Skip to content

Commit b2d1e00

Browse files
committed
[PowerPC][NFC] Small cleanup to restore CR field code in PPCFrameLowering.
Skip the loop over the CalleSavedInfos in 'restoreCalleeSavedRegisters' when the register is a CR field and we are not targeting 32-bit ELF. This is safe because: 1) The helper function 'restoreCRs' returns if the target is not 32-bit ELF, making all the code in the loop related to CR fields dead for every other subtarget. This code is only called on ELF right now, but the patch to extend it for AIX also needs to skip 'restoreCRs'. 2) The loop will not otherwise modify the iterator, so the iterator manipulations at the bottom of the loop end up setting 'I' to its current value. This simplifciation allows us to remove one argument from 'restoreCRs'. Also add a helper function to determine if a register is one of the callee saved condition register fields.
1 parent a41550c commit b2d1e00

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,28 +2253,22 @@ bool PPCFrameLowering::spillCalleeSavedRegisters(
22532253
return true;
22542254
}
22552255

2256-
static void restoreCRs(bool isPPC64, bool is31, bool CR2Spilled,
2257-
bool CR3Spilled, bool CR4Spilled, MachineBasicBlock &MBB,
2256+
static void restoreCRs(bool is31, bool CR2Spilled, bool CR3Spilled,
2257+
bool CR4Spilled, MachineBasicBlock &MBB,
22582258
MachineBasicBlock::iterator MI,
22592259
ArrayRef<CalleeSavedInfo> CSI, unsigned CSIIndex) {
22602260

22612261
MachineFunction *MF = MBB.getParent();
22622262
const PPCInstrInfo &TII = *MF->getSubtarget<PPCSubtarget>().getInstrInfo();
22632263
DebugLoc DL;
2264-
unsigned RestoreOp, MoveReg;
2264+
unsigned MoveReg = PPC::R12;
22652265

2266-
if (isPPC64)
2267-
// This is handled during epilogue generation.
2268-
return;
2269-
else {
2270-
// 32-bit: FP-relative
2271-
MBB.insert(MI, addFrameReference(BuildMI(*MF, DL, TII.get(PPC::LWZ),
2272-
PPC::R12),
2273-
CSI[CSIIndex].getFrameIdx()));
2274-
RestoreOp = PPC::MTOCRF;
2275-
MoveReg = PPC::R12;
2276-
}
2266+
// 32-bit: FP-relative
2267+
MBB.insert(MI,
2268+
addFrameReference(BuildMI(*MF, DL, TII.get(PPC::LWZ), MoveReg),
2269+
CSI[CSIIndex].getFrameIdx()));
22772270

2271+
unsigned RestoreOp = PPC::MTOCRF;
22782272
if (CR2Spilled)
22792273
MBB.insert(MI, BuildMI(*MF, DL, TII.get(RestoreOp), PPC::CR2)
22802274
.addReg(MoveReg, getKillRegState(!CR3Spilled && !CR4Spilled)));
@@ -2327,6 +2321,10 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
23272321
return MBB.erase(I);
23282322
}
23292323

2324+
static bool isCalleeSavedCR(unsigned Reg) {
2325+
return PPC::CR2 == Reg || Reg == PPC::CR3 || Reg == PPC::CR4;
2326+
}
2327+
23302328
bool
23312329
PPCFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
23322330
MachineBasicBlock::iterator MI,
@@ -2365,6 +2363,11 @@ PPCFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
23652363
if ((Reg == PPC::X2 || Reg == PPC::R2) && MustSaveTOC)
23662364
continue;
23672365

2366+
// Restore of callee saved condition register field is handled during
2367+
// epilogue insertion.
2368+
if (isCalleeSavedCR(Reg) && !Subtarget.is32BitELFABI())
2369+
continue;
2370+
23682371
if (Reg == PPC::CR2) {
23692372
CR2Spilled = true;
23702373
// The spill slot is associated only with CR2, which is the
@@ -2380,12 +2383,10 @@ PPCFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
23802383
} else {
23812384
// When we first encounter a non-CR register after seeing at
23822385
// least one CR register, restore all spilled CRs together.
2383-
if ((CR2Spilled || CR3Spilled || CR4Spilled)
2384-
&& !(PPC::CR2 <= Reg && Reg <= PPC::CR4)) {
2386+
if (CR2Spilled || CR3Spilled || CR4Spilled) {
23852387
bool is31 = needsFP(*MF);
2386-
restoreCRs(Subtarget.isPPC64(), is31,
2387-
CR2Spilled, CR3Spilled, CR4Spilled,
2388-
MBB, I, CSI, CSIIndex);
2388+
restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled, MBB, I, CSI,
2389+
CSIIndex);
23892390
CR2Spilled = CR3Spilled = CR4Spilled = false;
23902391
}
23912392

@@ -2423,9 +2424,10 @@ PPCFrameLowering::restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
24232424

24242425
// If we haven't yet spilled the CRs, do so now.
24252426
if (CR2Spilled || CR3Spilled || CR4Spilled) {
2427+
assert(Subtarget.is32BitELFABI() &&
2428+
"Only set CR[2|3|4]Spilled on 32-bit SVR4.");
24262429
bool is31 = needsFP(*MF);
2427-
restoreCRs(Subtarget.isPPC64(), is31, CR2Spilled, CR3Spilled, CR4Spilled,
2428-
MBB, I, CSI, CSIIndex);
2430+
restoreCRs(is31, CR2Spilled, CR3Spilled, CR4Spilled, MBB, I, CSI, CSIIndex);
24292431
}
24302432

24312433
return true;

0 commit comments

Comments
 (0)