Add the private linkage.
[oota-llvm.git] / lib / Target / PowerPC / PPCRegisterInfo.cpp
index 014925e1a6dc89b3bc3fa37404b02c04b0ea7c3f..b7e3ac2824049b295abb3adb48179da294ce4598 100644 (file)
@@ -347,6 +347,7 @@ BitVector PPCRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
   Reserved.set(PPC::R1);
   Reserved.set(PPC::LR);
   Reserved.set(PPC::LR8);
+  Reserved.set(PPC::RM);
 
   // In Linux, r2 is reserved for the OS.
   if (!Subtarget.isDarwin())
@@ -389,15 +390,15 @@ bool PPCRegisterInfo::hasFP(const MachineFunction &MF) const {
 /// 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 +407,7 @@ void PPCRegisterInfo::
 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;
@@ -629,7 +630,7 @@ void PPCRegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
 
   // Find out which operand is the frame index.
   unsigned FIOperandNo = 0;
-  while (!MI.getOperand(FIOperandNo).isFrameIndex()) {
+  while (!MI.getOperand(FIOperandNo).isFI()) {
     ++FIOperandNo;
     assert(FIOperandNo != MI.getNumOperands() &&
            "Instr doesn't have FrameIndex operand!");
@@ -934,7 +935,7 @@ PPCRegisterInfo::processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
   //  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 +1016,9 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
   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 +1026,7 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
   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 +1035,13 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
         .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 +1050,7 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
         .addImm(FPOffset)
         .addReg(PPC::R1);
 
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::STW))
         .addReg(PPC::R0)
         .addImm(LROffset)
@@ -1162,7 +1164,7 @@ PPCRegisterInfo::emitPrologue(MachineFunction &MF) const {
     for (unsigned I = 0, E = CSI.size(); I != E; ++I) {
       int Offset = MFI->getObjectOffset(CSI[I].getFrameIdx());
       unsigned Reg = CSI[I].getReg();
-      if (Reg == PPC::LR || Reg == PPC::LR8) continue;
+      if (Reg == PPC::LR || Reg == PPC::LR8 || Reg == PPC::RM) continue;
       MachineLocation CSDst(MachineLocation::VirtualFP, Offset);
       MachineLocation CSSrc(Reg);
       Moves.push_back(MachineMove(FrameLabelId, CSDst, CSSrc));
@@ -1222,8 +1224,9 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
   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,12 +1240,10 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
     RetOpcode == PPC::TCRETURNdi8 ||
     RetOpcode == PPC::TCRETURNai8;
 
-  PPCFunctionInfo *FI = MF.getInfo<PPCFunctionInfo>();
-
   if (UsesTCRet) {
     int MaxTCRetDelta = FI->getTailCallSPDelta();
     MachineOperand &StackAdjust = MBBI->getOperand(1);
-    assert( StackAdjust.isImmediate() && "Expecting immediate value.");
+    assert(StackAdjust.isImm() && "Expecting immediate value.");
     // Adjust stack pointer.
     int StackAdj = StackAdjust.getImm();
     int Delta = StackAdj - MaxTCRetDelta;
@@ -1309,7 +1310,7 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
   }
 
   if (IsPPC64) {
-    if (UsesLR)
+    if (MustSaveLR)
       BuildMI(MBB, MBBI, TII.get(PPC::LD), PPC::X0)
         .addImm(LROffset/4).addReg(PPC::X1);
         
@@ -1317,10 +1318,10 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
       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 +1329,7 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
       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);
   }
 
@@ -1368,7 +1369,7 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
   } else if (RetOpcode == PPC::TCRETURNri) {
     MBBI = prior(MBB.end());
     MachineOperand &JumpTarget = MBBI->getOperand(0);
-    assert(JumpTarget.isRegister() && "Expecting register operand.");
+    assert(JumpTarget.isReg() && "Expecting register operand.");
     BuildMI(MBB, MBBI, TII.get(PPC::TAILBCTR));
   } else if (RetOpcode == PPC::TCRETURNai) {
     MBBI = prior(MBB.end());
@@ -1382,7 +1383,7 @@ void PPCRegisterInfo::emitEpilogue(MachineFunction &MF,
   } else if (RetOpcode == PPC::TCRETURNri8) {
     MBBI = prior(MBB.end());
     MachineOperand &JumpTarget = MBBI->getOperand(0);
-    assert(JumpTarget.isRegister() && "Expecting register operand.");
+    assert(JumpTarget.isReg() && "Expecting register operand.");
     BuildMI(MBB, MBBI, TII.get(PPC::TAILBCTR8));
   } else if (RetOpcode == PPC::TCRETURNai8) {
     MBBI = prior(MBB.end());