[llvm-commits] [llvm] r58116 - in /llvm/trunk/lib/Target/PowerPC: PPCMachineFunctionInfo.h PPCRegisterInfo.cpp

Dale Johannesen dalej at apple.com
Fri Oct 24 14:24:24 PDT 2008


Author: johannes
Date: Fri Oct 24 16:24:23 2008
New Revision: 58116

URL: http://llvm.org/viewvc/llvm-project?rev=58116&view=rev
Log:
Rewrite logic to figure out whether LR needs to
be saved/restored in the prolog/epilog.  We need
to do this iff something in the function stores
into it.


Modified:
    llvm/trunk/lib/Target/PowerPC/PPCMachineFunctionInfo.h
    llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCMachineFunctionInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMachineFunctionInfo.h?rev=58116&r1=58115&r2=58116&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMachineFunctionInfo.h (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMachineFunctionInfo.h Fri Oct 24 16:24:23 2008
@@ -31,9 +31,10 @@
   ///
   int ReturnAddrSaveIndex;
 
-  /// UsesLR - Indicates whether LR is used in the current function.  This is
-  /// only valid after the initial scan of the function by PEI.
-  bool UsesLR;
+  /// MustSaveLR - Indicates whether LR is defined (or clobbered) in the current
+  /// function.  This is only valid after the initial scan of the function by
+  /// PEI.
+  bool MustSaveLR;
 
   /// SpillsCR - Indicates whether CR is spilled in the current function.
   bool SpillsCR;
@@ -79,12 +80,13 @@
   int getTailCallSPDelta() const { return TailCallSPDelta; }
   void setTailCallSPDelta(int size) { TailCallSPDelta = size; }
 
-  /// UsesLR - This is set when the prolog/epilog inserter does its initial scan
-  /// of the function, it is true if the LR/LR8 register is ever explicitly
-  /// accessed/clobbered in the machine function (e.g. by calls and movpctolr,
-  /// which is used in PIC generation).
-  void setUsesLR(bool U) { UsesLR = U; }
-  bool usesLR() const    { return UsesLR; }
+  /// MustSaveLR - This is set when the prolog/epilog inserter does its initial
+  /// scan of the function. It is true if the LR/LR8 register is ever explicitly
+  /// defined/clobbered in the machine function (e.g. by calls and movpctolr,
+  /// which is used in PIC generation), or if the LR stack slot is explicitly
+  /// referenced by builtin_return_address.
+  void setMustSaveLR(bool U) { MustSaveLR = U; }
+  bool mustSaveLR() const    { return MustSaveLR; }
 
   void setSpillsCR()       { SpillsCR = true; }
   bool isCRSpilled() const { return SpillsCR; }

Modified: llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp?rev=58116&r1=58115&r2=58116&view=diff

==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp Fri Oct 24 16:24:23 2008
@@ -389,15 +389,15 @@
 /// MustSaveLR - Return true if this function requires that we save the LR
 /// register onto the stack in the prolog and restore it in the epilog of the
 /// function.
-static bool MustSaveLR(const MachineFunction &MF) {
+static bool MustSaveLR(const MachineFunction &MF, unsigned LR) {
   const PPCFunctionInfo *MFI = MF.getInfo<PPCFunctionInfo>();
   
-  // We need an save/restore of LR if there is any use/def of LR explicitly, or
-  // if there is some use of the LR stack slot (e.g. for builtin_return_address.
-  return MFI->usesLR() || MFI->isLRStoreRequired() ||
-         // FIXME: Anything that has a call should clobber the LR register,
-         // isn't this redundant??
-         MF.getFrameInfo()->hasCalls();
+  // We need a save/restore of LR if there is any def of LR (which is
+  // defined by calls, including the PIC setup sequence), or if there is
+  // some use of the LR stack slot (e.g. for builtin_return_address).
+  // (LR comes in 32 and 64 bit versions.)
+  MachineRegisterInfo::def_iterator RI = MF.getRegInfo().def_begin(LR);
+  return RI !=MF.getRegInfo().def_end() || MFI->isLRStoreRequired();
 }
 
 
@@ -406,7 +406,7 @@
 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
                               MachineBasicBlock::iterator I) const {
   if (PerformTailCallOpt && I->getOpcode() == PPC::ADJCALLSTACKUP) {
-    // Add (actually substract) back the amount the callee popped on return.
+    // Add (actually subtract) back the amount the callee popped on return.
     if (int CalleeAmt =  I->getOperand(1).getImm()) {
       bool is64Bit = Subtarget.isPPC64();
       CalleeAmt *= -1;
@@ -934,7 +934,7 @@
   //  Save and clear the LR state.
   PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
   unsigned LR = getRARegister();
-  FI->setUsesLR(MF.getRegInfo().isPhysRegUsed(LR));
+  FI->setMustSaveLR(MustSaveLR(MF, LR));
   MF.getRegInfo().setPhysRegUnused(LR);
 
   //  Save R31 if necessary
@@ -1015,8 +1015,9 @@
   bool IsPPC64 = Subtarget.isPPC64();
   // Get operating system
   bool IsMachoABI = Subtarget.isMachoABI();
-  // Check if the link register (LR) has been used.
-  bool UsesLR = MustSaveLR(MF);
+  // Check if the link register (LR) must be saved.
+  PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
+  bool MustSaveLR = FI->mustSaveLR();
   // Do we have a frame pointer for this function?
   bool HasFP = hasFP(MF) && FrameSize;
   
@@ -1024,7 +1025,7 @@
   int FPOffset = PPCFrameInfo::getFramePointerSaveOffset(IsPPC64, IsMachoABI);
 
   if (IsPPC64) {
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::MFLR8), PPC::X0);
       
     if (HasFP)
@@ -1033,13 +1034,13 @@
         .addImm(FPOffset/4)
         .addReg(PPC::X1);
     
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::STD))
         .addReg(PPC::X0)
         .addImm(LROffset / 4)
         .addReg(PPC::X1);
   } else {
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::MFLR), PPC::R0);
       
     if (HasFP)
@@ -1048,7 +1049,7 @@
         .addImm(FPOffset)
         .addReg(PPC::R1);
 
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::STW))
         .addReg(PPC::R0)
         .addImm(LROffset)
@@ -1222,8 +1223,9 @@
   bool IsPPC64 = Subtarget.isPPC64();
   // Get operating system
   bool IsMachoABI = Subtarget.isMachoABI();
-  // Check if the link register (LR) has been used.
-  bool UsesLR = MustSaveLR(MF);
+  // Check if the link register (LR) has been saved.
+  PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
+  bool MustSaveLR = FI->mustSaveLR();
   // Do we have a frame pointer for this function?
   bool HasFP = hasFP(MF) && FrameSize;
   
@@ -1237,8 +1239,6 @@
     RetOpcode == PPC::TCRETURNdi8 ||
     RetOpcode == PPC::TCRETURNai8;
 
-  PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
-
   if (UsesTCRet) {
     int MaxTCRetDelta = FI->getTailCallSPDelta();
     MachineOperand &StackAdjust = MBBI->getOperand(1);
@@ -1309,7 +1309,7 @@
   }
 
   if (IsPPC64) {
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X0)
         .addImm(LROffset/4).addReg(PPC::X1);
         
@@ -1317,10 +1317,10 @@
       BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X31)
         .addImm(FPOffset/4).addReg(PPC::X1);
         
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::MTLR8)).addReg(PPC::X0);
   } else {
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::LWZ), PPC::R0)
           .addImm(LROffset).addReg(PPC::R1);
         
@@ -1328,7 +1328,7 @@
       BuildMI(MBB, MBBI, TII.get(PPC::LWZ), PPC::R31)
           .addImm(FPOffset).addReg(PPC::R1);
           
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::MTLR)).addReg(PPC::R0);
   }
 





More information about the llvm-commits mailing list