@@ -389,15 +389,15 @@ bool PPCRegisterInfo::hasFP(const MachineFunction &MF) const {
389
389
// / MustSaveLR - Return true if this function requires that we save the LR
390
390
// / register onto the stack in the prolog and restore it in the epilog of the
391
391
// / function.
392
- static bool MustSaveLR (const MachineFunction &MF) {
392
+ static bool MustSaveLR (const MachineFunction &MF, unsigned LR ) {
393
393
const PPCFunctionInfo *MFI = MF.getInfo <PPCFunctionInfo>();
394
394
395
- // We need an save/restore of LR if there is any use/ def of LR explicitly, or
396
- // if there is some use of the LR stack slot (e.g. for builtin_return_address.
397
- return MFI-> usesLR () || MFI-> isLRStoreRequired () ||
398
- // FIXME: Anything that has a call should clobber the LR register,
399
- // isn't this redundant??
400
- MF.getFrameInfo ()-> hasCalls ();
395
+ // We need a save/restore of LR if there is any def of LR (which is
396
+ // defined by calls, including the PIC setup sequence), or if there is
397
+ // some use of the LR stack slot (e.g. for builtin_return_address).
398
+ // (LR comes in 32 and 64 bit versions.)
399
+ MachineRegisterInfo::def_iterator RI = MF. getRegInfo (). def_begin (LR);
400
+ return RI != MF.getRegInfo (). def_end () || MFI-> isLRStoreRequired ();
401
401
}
402
402
403
403
@@ -406,7 +406,7 @@ void PPCRegisterInfo::
406
406
eliminateCallFramePseudoInstr (MachineFunction &MF, MachineBasicBlock &MBB,
407
407
MachineBasicBlock::iterator I) const {
408
408
if (PerformTailCallOpt && I->getOpcode () == PPC::ADJCALLSTACKUP) {
409
- // Add (actually substract ) back the amount the callee popped on return.
409
+ // Add (actually subtract ) back the amount the callee popped on return.
410
410
if (int CalleeAmt = I->getOperand (1 ).getImm ()) {
411
411
bool is64Bit = Subtarget.isPPC64 ();
412
412
CalleeAmt *= -1 ;
@@ -934,7 +934,7 @@ PPCRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
934
934
// Save and clear the LR state.
935
935
PPCFunctionInfo *FI = MF.getInfo <PPCFunctionInfo>();
936
936
unsigned LR = getRARegister ();
937
- FI->setUsesLR (MF. getRegInfo (). isPhysRegUsed ( LR));
937
+ FI->setMustSaveLR ( MustSaveLR (MF, LR));
938
938
MF.getRegInfo ().setPhysRegUnused (LR);
939
939
940
940
// Save R31 if necessary
@@ -1015,16 +1015,17 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
1015
1015
bool IsPPC64 = Subtarget.isPPC64 ();
1016
1016
// Get operating system
1017
1017
bool IsMachoABI = Subtarget.isMachoABI ();
1018
- // Check if the link register (LR) has been used.
1019
- bool UsesLR = MustSaveLR (MF);
1018
+ // Check if the link register (LR) must be saved.
1019
+ PPCFunctionInfo *FI = MF.getInfo <PPCFunctionInfo>();
1020
+ bool MustSaveLR = FI->mustSaveLR ();
1020
1021
// Do we have a frame pointer for this function?
1021
1022
bool HasFP = hasFP (MF) && FrameSize;
1022
1023
1023
1024
int LROffset = PPCFrameInfo::getReturnSaveOffset (IsPPC64, IsMachoABI);
1024
1025
int FPOffset = PPCFrameInfo::getFramePointerSaveOffset (IsPPC64, IsMachoABI);
1025
1026
1026
1027
if (IsPPC64) {
1027
- if (UsesLR )
1028
+ if (MustSaveLR )
1028
1029
BuildMI (MBB, MBBI, TII.get (PPC::MFLR8), PPC::X0);
1029
1030
1030
1031
if (HasFP)
@@ -1033,13 +1034,13 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
1033
1034
.addImm (FPOffset/4 )
1034
1035
.addReg (PPC::X1);
1035
1036
1036
- if (UsesLR )
1037
+ if (MustSaveLR )
1037
1038
BuildMI (MBB, MBBI, TII.get (PPC::STD))
1038
1039
.addReg (PPC::X0)
1039
1040
.addImm (LROffset / 4 )
1040
1041
.addReg (PPC::X1);
1041
1042
} else {
1042
- if (UsesLR )
1043
+ if (MustSaveLR )
1043
1044
BuildMI (MBB, MBBI, TII.get (PPC::MFLR), PPC::R0);
1044
1045
1045
1046
if (HasFP)
@@ -1048,7 +1049,7 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
1048
1049
.addImm (FPOffset)
1049
1050
.addReg (PPC::R1);
1050
1051
1051
- if (UsesLR )
1052
+ if (MustSaveLR )
1052
1053
BuildMI (MBB, MBBI, TII.get (PPC::STW))
1053
1054
.addReg (PPC::R0)
1054
1055
.addImm (LROffset)
@@ -1222,8 +1223,9 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
1222
1223
bool IsPPC64 = Subtarget.isPPC64 ();
1223
1224
// Get operating system
1224
1225
bool IsMachoABI = Subtarget.isMachoABI ();
1225
- // Check if the link register (LR) has been used.
1226
- bool UsesLR = MustSaveLR (MF);
1226
+ // Check if the link register (LR) has been saved.
1227
+ PPCFunctionInfo *FI = MF.getInfo <PPCFunctionInfo>();
1228
+ bool MustSaveLR = FI->mustSaveLR ();
1227
1229
// Do we have a frame pointer for this function?
1228
1230
bool HasFP = hasFP (MF) && FrameSize;
1229
1231
@@ -1237,8 +1239,6 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
1237
1239
RetOpcode == PPC::TCRETURNdi8 ||
1238
1240
RetOpcode == PPC::TCRETURNai8;
1239
1241
1240
- PPCFunctionInfo *FI = MF.getInfo <PPCFunctionInfo>();
1241
-
1242
1242
if (UsesTCRet) {
1243
1243
int MaxTCRetDelta = FI->getTailCallSPDelta ();
1244
1244
MachineOperand &StackAdjust = MBBI->getOperand (1 );
@@ -1309,26 +1309,26 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
1309
1309
}
1310
1310
1311
1311
if (IsPPC64) {
1312
- if (UsesLR )
1312
+ if (MustSaveLR )
1313
1313
BuildMI (MBB, MBBI, TII.get (PPC::LD), PPC::X0)
1314
1314
.addImm (LROffset/4 ).addReg (PPC::X1);
1315
1315
1316
1316
if (HasFP)
1317
1317
BuildMI (MBB, MBBI, TII.get (PPC::LD), PPC::X31)
1318
1318
.addImm (FPOffset/4 ).addReg (PPC::X1);
1319
1319
1320
- if (UsesLR )
1320
+ if (MustSaveLR )
1321
1321
BuildMI (MBB, MBBI, TII.get (PPC::MTLR8)).addReg (PPC::X0);
1322
1322
} else {
1323
- if (UsesLR )
1323
+ if (MustSaveLR )
1324
1324
BuildMI (MBB, MBBI, TII.get (PPC::LWZ), PPC::R0)
1325
1325
.addImm (LROffset).addReg (PPC::R1);
1326
1326
1327
1327
if (HasFP)
1328
1328
BuildMI (MBB, MBBI, TII.get (PPC::LWZ), PPC::R31)
1329
1329
.addImm (FPOffset).addReg (PPC::R1);
1330
1330
1331
- if (UsesLR )
1331
+ if (MustSaveLR )
1332
1332
BuildMI (MBB, MBBI, TII.get (PPC::MTLR)).addReg (PPC::R0);
1333
1333
}
1334
1334
0 commit comments