forked from OSchip/llvm-project
BranchRelaxation: Recompute live-ins when splitting a block
Factors out and reuses live-in computation code from BranchFolding. Differential Revision: https://reviews.llvm.org/D27558 llvm-svn: 290013
This commit is contained in:
parent
2dfb688214
commit
181983055f
|
@ -155,6 +155,13 @@ inline raw_ostream &operator<<(raw_ostream &OS, const LivePhysRegs& LR) {
|
||||||
return OS;
|
return OS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compute the live-in list for \p MBB assuming all of its successors live-in
|
||||||
|
/// lists are up-to-date. Uses the given LivePhysReg instance \p LiveRegs; This
|
||||||
|
/// is just here to avoid repeated heap allocations when calling this multiple
|
||||||
|
/// times in a pass.
|
||||||
|
void computeLiveIns(LivePhysRegs &LiveRegs, const TargetRegisterInfo &TRI,
|
||||||
|
MachineBasicBlock &MBB);
|
||||||
|
|
||||||
} // end namespace llvm
|
} // end namespace llvm
|
||||||
|
|
||||||
#endif // LLVM_CODEGEN_LIVEPHYSREGS_H
|
#endif // LLVM_CODEGEN_LIVEPHYSREGS_H
|
||||||
|
|
|
@ -289,6 +289,9 @@ public:
|
||||||
/// LiveIn insertion.
|
/// LiveIn insertion.
|
||||||
void sortUniqueLiveIns();
|
void sortUniqueLiveIns();
|
||||||
|
|
||||||
|
/// Clear live in list.
|
||||||
|
void clearLiveIns();
|
||||||
|
|
||||||
/// Add PhysReg as live in to this block, and ensure that there is a copy of
|
/// Add PhysReg as live in to this block, and ensure that there is a copy of
|
||||||
/// PhysReg to a virtual register of class RC. Return the virtual register
|
/// PhysReg to a virtual register of class RC. Return the virtual register
|
||||||
/// that is a copy of the live in PhysReg.
|
/// that is a copy of the live in PhysReg.
|
||||||
|
|
|
@ -349,37 +349,16 @@ static unsigned ComputeCommonTailLength(MachineBasicBlock *MBB1,
|
||||||
return TailLen;
|
return TailLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BranchFolder::computeLiveIns(MachineBasicBlock &MBB) {
|
|
||||||
if (!UpdateLiveIns)
|
|
||||||
return;
|
|
||||||
|
|
||||||
LiveRegs.init(*TRI);
|
|
||||||
LiveRegs.addLiveOutsNoPristines(MBB);
|
|
||||||
for (MachineInstr &MI : make_range(MBB.rbegin(), MBB.rend()))
|
|
||||||
LiveRegs.stepBackward(MI);
|
|
||||||
|
|
||||||
for (unsigned Reg : LiveRegs) {
|
|
||||||
// Skip the register if we are about to add one of its super registers.
|
|
||||||
bool ContainsSuperReg = false;
|
|
||||||
for (MCSuperRegIterator SReg(Reg, TRI); SReg.isValid(); ++SReg) {
|
|
||||||
if (LiveRegs.contains(*SReg)) {
|
|
||||||
ContainsSuperReg = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ContainsSuperReg)
|
|
||||||
continue;
|
|
||||||
MBB.addLiveIn(Reg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
|
/// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
|
||||||
/// after it, replacing it with an unconditional branch to NewDest.
|
/// after it, replacing it with an unconditional branch to NewDest.
|
||||||
void BranchFolder::ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
|
void BranchFolder::ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
|
||||||
MachineBasicBlock *NewDest) {
|
MachineBasicBlock *NewDest) {
|
||||||
TII->ReplaceTailWithBranchTo(OldInst, NewDest);
|
TII->ReplaceTailWithBranchTo(OldInst, NewDest);
|
||||||
|
|
||||||
computeLiveIns(*NewDest);
|
if (UpdateLiveIns) {
|
||||||
|
NewDest->clearLiveIns();
|
||||||
|
computeLiveIns(LiveRegs, *TRI, *NewDest);
|
||||||
|
}
|
||||||
|
|
||||||
++NumTailMerge;
|
++NumTailMerge;
|
||||||
}
|
}
|
||||||
|
@ -417,7 +396,8 @@ MachineBasicBlock *BranchFolder::SplitMBBAt(MachineBasicBlock &CurMBB,
|
||||||
// NewMBB inherits CurMBB's block frequency.
|
// NewMBB inherits CurMBB's block frequency.
|
||||||
MBBFreqInfo.setBlockFreq(NewMBB, MBBFreqInfo.getBlockFreq(&CurMBB));
|
MBBFreqInfo.setBlockFreq(NewMBB, MBBFreqInfo.getBlockFreq(&CurMBB));
|
||||||
|
|
||||||
computeLiveIns(*NewMBB);
|
if (UpdateLiveIns)
|
||||||
|
computeLiveIns(LiveRegs, *TRI, *NewMBB);
|
||||||
|
|
||||||
// Add the new block to the funclet.
|
// Add the new block to the funclet.
|
||||||
const auto &FuncletI = FuncletMembership.find(&CurMBB);
|
const auto &FuncletI = FuncletMembership.find(&CurMBB);
|
||||||
|
|
|
@ -137,7 +137,6 @@ namespace llvm {
|
||||||
MachineBasicBlock* PredBB,
|
MachineBasicBlock* PredBB,
|
||||||
unsigned MinCommonTailLength);
|
unsigned MinCommonTailLength);
|
||||||
void setCommonTailEdgeWeights(MachineBasicBlock &TailMBB);
|
void setCommonTailEdgeWeights(MachineBasicBlock &TailMBB);
|
||||||
void computeLiveIns(MachineBasicBlock &MBB);
|
|
||||||
void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
|
void ReplaceTailWithBranchTo(MachineBasicBlock::iterator OldInst,
|
||||||
MachineBasicBlock *NewDest);
|
MachineBasicBlock *NewDest);
|
||||||
MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
|
MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "llvm/CodeGen/Passes.h"
|
#include "llvm/CodeGen/Passes.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
|
#include "llvm/CodeGen/LivePhysRegs.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
#include "llvm/CodeGen/RegisterScavenging.h"
|
#include "llvm/CodeGen/RegisterScavenging.h"
|
||||||
#include "llvm/Target/TargetInstrInfo.h"
|
#include "llvm/Target/TargetInstrInfo.h"
|
||||||
|
@ -69,8 +70,10 @@ class BranchRelaxation : public MachineFunctionPass {
|
||||||
|
|
||||||
SmallVector<BasicBlockInfo, 16> BlockInfo;
|
SmallVector<BasicBlockInfo, 16> BlockInfo;
|
||||||
std::unique_ptr<RegScavenger> RS;
|
std::unique_ptr<RegScavenger> RS;
|
||||||
|
LivePhysRegs LiveRegs;
|
||||||
|
|
||||||
MachineFunction *MF;
|
MachineFunction *MF;
|
||||||
|
const TargetRegisterInfo *TRI;
|
||||||
const TargetInstrInfo *TII;
|
const TargetInstrInfo *TII;
|
||||||
|
|
||||||
bool relaxBranchInstructions();
|
bool relaxBranchInstructions();
|
||||||
|
@ -252,6 +255,10 @@ MachineBasicBlock *BranchRelaxation::splitBlockBeforeInstr(MachineInstr &MI,
|
||||||
// All BBOffsets following these blocks must be modified.
|
// All BBOffsets following these blocks must be modified.
|
||||||
adjustBlockOffsets(*OrigBB);
|
adjustBlockOffsets(*OrigBB);
|
||||||
|
|
||||||
|
// Need to fix live-in lists if we track liveness.
|
||||||
|
if (TRI->trackLivenessAfterRegAlloc(*MF))
|
||||||
|
computeLiveIns(LiveRegs, *TRI, *NewBB);
|
||||||
|
|
||||||
++NumSplit;
|
++NumSplit;
|
||||||
|
|
||||||
return NewBB;
|
return NewBB;
|
||||||
|
@ -411,8 +418,9 @@ bool BranchRelaxation::relaxBranchInstructions() {
|
||||||
for (MachineFunction::iterator I = MF->begin(); I != MF->end(); ++I) {
|
for (MachineFunction::iterator I = MF->begin(); I != MF->end(); ++I) {
|
||||||
MachineBasicBlock &MBB = *I;
|
MachineBasicBlock &MBB = *I;
|
||||||
|
|
||||||
auto Last = MBB.rbegin();
|
// Empty block?
|
||||||
if (Last == MBB.rend()) // Empty block.
|
MachineBasicBlock::iterator Last = MBB.getLastNonDebugInstr();
|
||||||
|
if (Last == MBB.end())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Expand the unconditional branch first if necessary. If there is a
|
// Expand the unconditional branch first if necessary. If there is a
|
||||||
|
@ -473,7 +481,7 @@ bool BranchRelaxation::runOnMachineFunction(MachineFunction &mf) {
|
||||||
const TargetSubtargetInfo &ST = MF->getSubtarget();
|
const TargetSubtargetInfo &ST = MF->getSubtarget();
|
||||||
TII = ST.getInstrInfo();
|
TII = ST.getInstrInfo();
|
||||||
|
|
||||||
const TargetRegisterInfo *TRI = ST.getRegisterInfo();
|
TRI = ST.getRegisterInfo();
|
||||||
if (TRI->trackLivenessAfterRegAlloc(*MF))
|
if (TRI->trackLivenessAfterRegAlloc(*MF))
|
||||||
RS.reset(new RegScavenger());
|
RS.reset(new RegScavenger());
|
||||||
|
|
||||||
|
|
|
@ -197,3 +197,26 @@ void LivePhysRegs::addLiveIns(const MachineBasicBlock &MBB) {
|
||||||
addPristines(*this, MF, MFI, *TRI);
|
addPristines(*this, MF, MFI, *TRI);
|
||||||
addBlockLiveIns(MBB);
|
addBlockLiveIns(MBB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void llvm::computeLiveIns(LivePhysRegs &LiveRegs, const TargetRegisterInfo &TRI,
|
||||||
|
MachineBasicBlock &MBB) {
|
||||||
|
assert(MBB.livein_empty());
|
||||||
|
LiveRegs.init(TRI);
|
||||||
|
LiveRegs.addLiveOutsNoPristines(MBB);
|
||||||
|
for (MachineInstr &MI : make_range(MBB.rbegin(), MBB.rend()))
|
||||||
|
LiveRegs.stepBackward(MI);
|
||||||
|
|
||||||
|
for (unsigned Reg : LiveRegs) {
|
||||||
|
// Skip the register if we are about to add one of its super registers.
|
||||||
|
bool ContainsSuperReg = false;
|
||||||
|
for (MCSuperRegIterator SReg(Reg, &TRI); SReg.isValid(); ++SReg) {
|
||||||
|
if (LiveRegs.contains(*SReg)) {
|
||||||
|
ContainsSuperReg = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ContainsSuperReg)
|
||||||
|
continue;
|
||||||
|
MBB.addLiveIn(Reg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1288,3 +1288,7 @@ MachineBasicBlock::getEndClobberMask(const TargetRegisterInfo *TRI) const {
|
||||||
// care what kind of return it is, putting a mask after it is a no-op.
|
// care what kind of return it is, putting a mask after it is a no-op.
|
||||||
return isReturnBlock() && !succ_empty() ? TRI->getNoPreservedMask() : nullptr;
|
return isReturnBlock() && !succ_empty() ? TRI->getNoPreservedMask() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MachineBasicBlock::clearLiveIns() {
|
||||||
|
LiveIns.clear();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue