Skip to content

Commit 24f26e6

Browse files
committed
LivePhysRegs: Automatically determine presence of pristine regs.
Remove the AddPristinesAndCSRs parameters from addLiveIns()/addLiveOuts(). We need to respect pristine registers after prologue epilogue insertion, Seeing that we got this wrong in at least two commits already, we should rather pay the small price to query MachineFrameInfo for it. There are three cases that did not set AddPristineAndCSRs to true even after register allocation: - ExecutionDepsFix: live-out registers are used as a hint that the register is used soon. This is not true for pristine registers so use the new addLiveOutsNoPristines() to maintain this behaviour. - SystemZShortenInst: Not setting AddPristineAndCSRs to true looks like a bug, should do the right thing automatically now. - StackMapLivenessAnalysis: Not adding pristine registers looks like a bug to me. Added a FIXME comment but maintain the current behaviour as a change may need to get coordinated with GC runtimes. llvm-svn: 268336
1 parent 1a55a99 commit 24f26e6

File tree

10 files changed

+43
-35
lines changed

10 files changed

+43
-35
lines changed

llvm/include/llvm/CodeGen/LivePhysRegs.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,20 @@ class LivePhysRegs {
112112
void stepForward(const MachineInstr &MI,
113113
SmallVectorImpl<std::pair<unsigned, const MachineOperand*>> &Clobbers);
114114

115-
/// \brief Adds all live-in registers of basic block @p MBB; After prologue/
116-
/// epilogue insertion \p AddPristines should be set to true to insert the
115+
/// Adds all live-in registers of basic block @p MBB.
116+
/// Live in registers are the registers in the blocks live-in list and the
117117
/// pristine registers.
118-
void addLiveIns(const MachineBasicBlock *MBB, bool AddPristines = false);
118+
void addLiveIns(const MachineBasicBlock *MBB);
119119

120-
/// \brief Adds all live-out registers of basic block @p MBB; After prologue/
121-
/// epilogue insertion \p AddPristinesAndCSRs should be set to true.
122-
void addLiveOuts(const MachineBasicBlock *MBB,
123-
bool AddPristinesAndCSRs = false);
120+
/// Adds all live-out registers of basic block @p MBB.
121+
/// Live out registers are the union of the live-in registers of the successor
122+
/// blocks and pristine registers. Live out registers of the end block are the
123+
/// callee saved registers.
124+
void addLiveOuts(const MachineBasicBlock *MBB);
125+
126+
/// Like addLiveOuts() but does not add pristine registers/callee saved
127+
/// registers.
128+
void addLiveOutsNoPristines(const MachineBasicBlock *MBB);
124129

125130
typedef SparseSet<unsigned>::const_iterator const_iterator;
126131
const_iterator begin() const { return LiveRegs.begin(); }

llvm/lib/CodeGen/ExecutionDepsFix.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ void ExeDepsFix::processUndefReads(MachineBasicBlock *MBB) {
558558

559559
// Collect this block's live out register units.
560560
LiveRegSet.init(TRI);
561-
LiveRegSet.addLiveOuts(MBB);
561+
// We do not need to care about pristine registers as they are just preserved
562+
// but not actually used in the function.
563+
LiveRegSet.addLiveOutsNoPristines(MBB);
562564

563565
MachineInstr *UndefMI = UndefReads.back().first;
564566
unsigned OpIdx = UndefReads.back().second;

llvm/lib/CodeGen/LivePhysRegs.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,25 @@ static void addLiveIns(LivePhysRegs &LiveRegs, const MachineBasicBlock &MBB) {
135135
/// Add pristine registers to the given \p LiveRegs. This function removes
136136
/// actually saved callee save registers when \p InPrologueEpilogue is false.
137137
static void addPristines(LivePhysRegs &LiveRegs, const MachineFunction &MF,
138+
const MachineFrameInfo &MFI,
138139
const TargetRegisterInfo &TRI) {
139-
const MachineFrameInfo &MFI = *MF.getFrameInfo();
140-
if (!MFI.isCalleeSavedInfoValid())
141-
return;
142-
143140
for (const MCPhysReg *CSR = TRI.getCalleeSavedRegs(&MF); CSR && *CSR; ++CSR)
144141
LiveRegs.addReg(*CSR);
145142
for (const CalleeSavedInfo &Info : MFI.getCalleeSavedInfo())
146143
LiveRegs.removeReg(Info.getReg());
147144
}
148145

149-
void LivePhysRegs::addLiveOuts(const MachineBasicBlock *MBB,
150-
bool AddPristinesAndCSRs) {
151-
if (AddPristinesAndCSRs) {
152-
const MachineFunction &MF = *MBB->getParent();
153-
addPristines(*this, MF, *TRI);
146+
void LivePhysRegs::addLiveOutsNoPristines(const MachineBasicBlock *MBB) {
147+
// To get the live-outs we simply merge the live-ins of all successors.
148+
for (const MachineBasicBlock *Succ : MBB->successors())
149+
::addLiveIns(*this, *Succ);
150+
}
151+
152+
void LivePhysRegs::addLiveOuts(const MachineBasicBlock *MBB) {
153+
const MachineFunction &MF = *MBB->getParent();
154+
const MachineFrameInfo &MFI = *MF.getFrameInfo();
155+
if (MFI.isCalleeSavedInfoValid()) {
156+
addPristines(*this, MF, MFI, *TRI);
154157
if (MBB->isReturnBlock()) {
155158
// The return block has no successors whose live-ins we could merge
156159
// below. So instead we add the callee saved registers manually.
@@ -159,16 +162,13 @@ void LivePhysRegs::addLiveOuts(const MachineBasicBlock *MBB,
159162
}
160163
}
161164

162-
// To get the live-outs we simply merge the live-ins of all successors.
163-
for (const MachineBasicBlock *Succ : MBB->successors())
164-
::addLiveIns(*this, *Succ);
165+
addLiveOutsNoPristines(MBB);
165166
}
166167

167-
void LivePhysRegs::addLiveIns(const MachineBasicBlock *MBB,
168-
bool AddPristines) {
169-
if (AddPristines) {
170-
const MachineFunction &MF = *MBB->getParent();
171-
addPristines(*this, MF, *TRI);
172-
}
168+
void LivePhysRegs::addLiveIns(const MachineBasicBlock *MBB) {
169+
const MachineFunction &MF = *MBB->getParent();
170+
const MachineFrameInfo &MFI = *MF.getFrameInfo();
171+
if (MFI.isCalleeSavedInfoValid())
172+
addPristines(*this, MF, MFI, *TRI);
173173
::addLiveIns(*this, *MBB);
174174
}

llvm/lib/CodeGen/StackMapLivenessAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ bool StackMapLiveness::calculateLiveness(MachineFunction &MF) {
127127
for (auto &MBB : MF) {
128128
DEBUG(dbgs() << "****** BB " << MBB.getName() << " ******\n");
129129
LiveRegs.init(TRI);
130-
LiveRegs.addLiveOuts(&MBB);
130+
// FIXME: This should probably be addLiveOuts().
131+
LiveRegs.addLiveOutsNoPristines(&MBB);
131132
bool HasStackMap = false;
132133
// Reverse iterate over all instructions and add the current live register
133134
// set to an instruction if we encounter a patchpoint instruction.

llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ bool AArch64ExpandPseudo::expandCMP_SWAP(
607607
MachineOperand &New = MI.getOperand(4);
608608

609609
LivePhysRegs LiveRegs(&TII->getRegisterInfo());
610-
LiveRegs.addLiveOuts(&MBB, /*AddPristinesAndCSRs=*/true);
610+
LiveRegs.addLiveOuts(&MBB);
611611
for (auto I = std::prev(MBB.end()); I != MBBI; --I)
612612
LiveRegs.stepBackward(*I);
613613

@@ -685,7 +685,7 @@ bool AArch64ExpandPseudo::expandCMP_SWAP_128(
685685
MachineOperand &NewHi = MI.getOperand(7);
686686

687687
LivePhysRegs LiveRegs(&TII->getRegisterInfo());
688-
LiveRegs.addLiveOuts(&MBB, /*AddPristinesAndCSRs=*/true);
688+
LiveRegs.addLiveOuts(&MBB);
689689
for (auto I = std::prev(MBB.end()); I != MBBI; --I)
690690
LiveRegs.stepBackward(*I);
691691

llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ bool ARMExpandPseudo::ExpandCMP_SWAP(MachineBasicBlock &MBB,
775775
MachineOperand &New = MI.getOperand(4);
776776

777777
LivePhysRegs LiveRegs(&TII->getRegisterInfo());
778-
LiveRegs.addLiveOuts(&MBB, /*AddPristinesAndCSRs=*/true);
778+
LiveRegs.addLiveOuts(&MBB);
779779
for (auto I = std::prev(MBB.end()); I != MBBI; --I)
780780
LiveRegs.stepBackward(*I);
781781

@@ -897,7 +897,7 @@ bool ARMExpandPseudo::ExpandCMP_SWAP_64(MachineBasicBlock &MBB,
897897
unsigned DesiredHi = TRI->getSubReg(Desired.getReg(), ARM::gsub_1);
898898

899899
LivePhysRegs LiveRegs(&TII->getRegisterInfo());
900-
LiveRegs.addLiveOuts(&MBB, /*AddPristinesAndCSRs=*/true);
900+
LiveRegs.addLiveOuts(&MBB);
901901
for (auto I = std::prev(MBB.end()); I != MBBI; --I)
902902
LiveRegs.stepBackward(*I);
903903

llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ void ARMLoadStoreOpt::moveLiveRegsBefore(const MachineBasicBlock &MBB,
566566
// Initialize if we never queried in this block.
567567
if (!LiveRegsValid) {
568568
LiveRegs.init(TRI);
569-
LiveRegs.addLiveOuts(&MBB, true);
569+
LiveRegs.addLiveOuts(&MBB);
570570
LiveRegPos = MBB.end();
571571
LiveRegsValid = true;
572572
}

llvm/lib/Target/ARM/Thumb1FrameLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ bool Thumb1FrameLowering::emitPopSpecialFixUp(MachineBasicBlock &MBB,
467467
// Look for a temporary register to use.
468468
// First, compute the liveness information.
469469
LivePhysRegs UsedRegs(STI.getRegisterInfo());
470-
UsedRegs.addLiveOuts(&MBB, /*AddPristines*/ true);
470+
UsedRegs.addLiveOuts(&MBB);
471471
// The semantic of pristines changed recently and now,
472472
// the callee-saved registers that are touched in the function
473473
// are not part of the pristines set anymore.

llvm/lib/Target/X86/X86FixupBWInsts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ void FixupBWInstPass::processBasicBlock(MachineFunction &MF,
245245
// to update this for each instruction.
246246
LiveRegs.clear();
247247
// We run after PEI, so we need to AddPristinesAndCSRs.
248-
LiveRegs.addLiveOuts(&MBB, /*AddPristinesAndCSRs=*/true);
248+
LiveRegs.addLiveOuts(&MBB);
249249

250250
for (auto I = MBB.rbegin(); I != MBB.rend(); ++I) {
251251
MachineInstr *NewMI = nullptr;

llvm/lib/Target/X86/X86InstrInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4537,7 +4537,7 @@ void X86InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
45374537
// as this is usually wrong to read an undef value.
45384538
if (MachineBasicBlock::LQR_Unknown == LQR) {
45394539
LivePhysRegs LPR(&getRegisterInfo());
4540-
LPR.addLiveOuts(&MBB, /*AddPristinesAndCSRs*/ true);
4540+
LPR.addLiveOuts(&MBB);
45414541
MachineBasicBlock::iterator I = MBB.end();
45424542
while (I != MI) {
45434543
--I;

0 commit comments

Comments
 (0)