Propagate debug loc info through prologue/epilogue.
authorBill Wendling <isanbard@gmail.com>
Mon, 23 Feb 2009 00:42:30 +0000 (00:42 +0000)
committerBill Wendling <isanbard@gmail.com>
Mon, 23 Feb 2009 00:42:30 +0000 (00:42 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65298 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/ARMRegisterInfo.cpp
lib/Target/Alpha/AlphaRegisterInfo.cpp
lib/Target/CellSPU/SPURegisterInfo.cpp
lib/Target/IA64/IA64RegisterInfo.cpp
lib/Target/Mips/MipsRegisterInfo.cpp
lib/Target/Sparc/SparcRegisterInfo.cpp
lib/Target/XCore/XCoreRegisterInfo.cpp

index bd95a48d987e3636647f0d4206a7e78ba15ff106..8785c39a96fb51efbf179b187b4c856d12bdae20 100644 (file)
@@ -1222,7 +1222,8 @@ void ARMRegisterInfo::emitPrologue(MachineFunction &MF) const {
   unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
   unsigned NumBytes = MFI->getStackSize();
   const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
 
   if (isThumb) {
     // Check if R3 is live in. It might have to be used as a scratch register.
@@ -1292,8 +1293,11 @@ void ARMRegisterInfo::emitPrologue(MachineFunction &MF) const {
     // Build the new SUBri to adjust SP for integer callee-save spill area 1.
     emitSPUpdate(MBB, MBBI, -GPRCS1Size, ARMCC::AL, 0, isThumb, TII, *this, dl);
     movePastCSLoadStoreOps(MBB, MBBI, ARM::STR, 1, STI);
-  } else if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tPUSH)
+  } else if (MBBI != MBB.end() && MBBI->getOpcode() == ARM::tPUSH) {
     ++MBBI;
+    if (MBBI != MBB.end())
+      dl = MBBI->getDebugLoc();
+  }
 
   // Darwin ABI requires FP to point to the stack slot that contains the
   // previous FP.
@@ -1358,18 +1362,18 @@ static bool isCSRestore(MachineInstr *MI, const unsigned *CSRegs) {
 
 void ARMRegisterInfo::emitEpilogue(MachineFunction &MF,
                                    MachineBasicBlock &MBB) const {
-  DebugLoc dl = DebugLoc::getUnknownLoc();
   MachineBasicBlock::iterator MBBI = prior(MBB.end());
   assert((MBBI->getOpcode() == ARM::BX_RET ||
           MBBI->getOpcode() == ARM::tBX_RET ||
           MBBI->getOpcode() == ARM::tPOP_RET) &&
          "Can only insert epilog into returning blocks");
-
+  DebugLoc dl = MBBI->getDebugLoc();
   MachineFrameInfo *MFI = MF.getFrameInfo();
   ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
   bool isThumb = AFI->isThumbFunction();
   unsigned VARegSaveSize = AFI->getVarArgsRegSaveSize();
   int NumBytes = (int)MFI->getStackSize();
+
   if (!AFI->hasStackFrame()) {
     if (NumBytes != 0)
       emitSPUpdate(MBB, MBBI, NumBytes, ARMCC::AL, 0, isThumb, TII, *this, dl);
index 2ed8dac16a16bf26acb2afe579ca33a14648bce4..feee6e467f47fbd64c7a60792f56bb5cb87af2e7 100644 (file)
@@ -202,7 +202,8 @@ void AlphaRegisterInfo::emitPrologue(MachineFunction &MF) const {
   MachineBasicBlock &MBB = MF.front();   // Prolog goes in entry BB
   MachineBasicBlock::iterator MBBI = MBB.begin();
   MachineFrameInfo *MFI = MF.getFrameInfo();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
   bool FP = hasFP(MF);
 
   static int curgpdist = 0;
@@ -268,7 +269,7 @@ void AlphaRegisterInfo::emitEpilogue(MachineFunction &MF,
   assert((MBBI->getOpcode() == Alpha::RETDAG ||
           MBBI->getOpcode() == Alpha::RETDAGp)
          && "Can only insert epilog into returning blocks");
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = MBBI->getDebugLoc();
 
   bool FP = hasFP(MF);
 
index 64ed8287972ac5fdb544efa04bdef02902dbd8c2..e031048e7ccb362b924f48ffda4fa593973d7ce8 100644 (file)
@@ -428,7 +428,8 @@ void SPURegisterInfo::emitPrologue(MachineFunction &MF) const
   MachineBasicBlock::iterator MBBI = MBB.begin();
   MachineFrameInfo *MFI = MF.getFrameInfo();
   MachineModuleInfo *MMI = MFI->getMachineModuleInfo();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
 
   // Prepare for debug frame info.
   bool hasDebugInfo = MMI && MMI->hasDebugInfo();
@@ -521,6 +522,8 @@ void SPURegisterInfo::emitPrologue(MachineFunction &MF) const
     // this is just a best guess based on the basic block's size.
     if (MBB.size() >= (unsigned) SPUFrameInfo::branchHintPenalty()) {
       MachineBasicBlock::iterator MBBI = prior(MBB.end());
+      dl = MBBI->getDebugLoc();
+
       // Insert terminator label
       unsigned BranchLabelId = MMI->NextLabelID();
       BuildMI(MBB, MBBI, dl, TII.get(SPU::DBG_LABEL)).addImm(BranchLabelId);
@@ -535,7 +538,7 @@ SPURegisterInfo::emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const
   const MachineFrameInfo *MFI = MF.getFrameInfo();
   int FrameSize = MFI->getStackSize();
   int LinkSlotOffset = SPUFrameInfo::stackSlotSize();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = MBBI->getDebugLoc();
 
   assert(MBBI->getOpcode() == SPU::RET &&
          "Can only insert epilog into returning blocks");
index 19cfd08aec6fdfa68aee65c7e000ae1d158b3d39..7ad6f51a9b8bded96aee93d072df6f0a71f8b4b9 100644 (file)
@@ -165,7 +165,8 @@ void IA64RegisterInfo::emitPrologue(MachineFunction &MF) const {
   MachineBasicBlock::iterator MBBI = MBB.begin();
   MachineFrameInfo *MFI = MF.getFrameInfo();
   bool FP = hasFP(MF);
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
 
   // first, we handle the 'alloc' instruction, that should be right up the
   // top of any function
@@ -208,6 +209,8 @@ void IA64RegisterInfo::emitPrologue(MachineFunction &MF) const {
     }
   }
 
+  if (MBBI != MBB.end()) dl = MBBI->getDebugLoc();
+
   BuildMI(MBB, MBBI, dl, TII.get(IA64::ALLOC)).
      addReg(dstRegOfPseudoAlloc).addImm(0).
      addImm(numStackedGPRsUsed).addImm(numOutRegsUsed).addImm(0);
@@ -261,24 +264,21 @@ void IA64RegisterInfo::emitEpilogue(MachineFunction &MF,
   MachineBasicBlock::iterator MBBI = prior(MBB.end());
   assert(MBBI->getOpcode() == IA64::RET &&
          "Can only insert epilog into returning blocks");
-  DebugLoc dl = DebugLoc::getUnknownLoc();
-
+  DebugLoc dl = MBBI->getDebugLoc();
   bool FP = hasFP(MF);
 
   // Get the number of bytes allocated from the FrameInfo...
   unsigned NumBytes = MFI->getStackSize();
 
   //now if we need to, restore the old FP
-  if (FP)
-  {
+  if (FP) {
     //copy the FP into the SP (discards allocas)
     BuildMI(MBB, MBBI, dl, TII.get(IA64::MOV), IA64::r12).addReg(IA64::r5);
     //restore the FP
     BuildMI(MBB, MBBI, dl, TII.get(IA64::LD8), IA64::r5).addReg(IA64::r5);
   }
 
-  if (NumBytes != 0)
-  {
+  if (NumBytes != 0) {
     if (NumBytes <= 8191) {
       BuildMI(MBB, MBBI, dl, TII.get(IA64::ADDIMM22),IA64::r12).
         addReg(IA64::r12).addImm(NumBytes);
@@ -289,7 +289,6 @@ void IA64RegisterInfo::emitEpilogue(MachineFunction &MF,
         addReg(IA64::r22);
     }
   }
-
 }
 
 unsigned IA64RegisterInfo::getRARegister() const {
index 7146ff215549248f431eeb84078bf0bf500fd443..8a468d1db5c601057bf53e5cf9232e5641eb9e61 100644 (file)
@@ -391,7 +391,8 @@ emitPrologue(MachineFunction &MF) const
   MachineFrameInfo *MFI    = MF.getFrameInfo();
   MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
   MachineBasicBlock::iterator MBBI = MBB.begin();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
   bool isPIC = (MF.getTarget().getRelocationModel() == Reloc::PIC_);
 
   // Get the right frame order for Mips.
@@ -449,7 +450,7 @@ emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const
   MachineBasicBlock::iterator MBBI = prior(MBB.end());
   MachineFrameInfo *MFI            = MF.getFrameInfo();
   MipsFunctionInfo *MipsFI         = MF.getInfo<MipsFunctionInfo>();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = MBBI->getDebugLoc();
 
   // Get the number of bytes from FrameInfo
   int NumBytes = (int) MFI->getStackSize();
index d8964d90f6664085489939e5cfdd6d645c55395c..59efb19ab9c5a2ae7c42e86b39b814faaa1b0dc9 100644 (file)
@@ -120,7 +120,9 @@ processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
 void SparcRegisterInfo::emitPrologue(MachineFunction &MF) const {
   MachineBasicBlock &MBB = MF.front();
   MachineFrameInfo *MFI = MF.getFrameInfo();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  MachineBasicBlock::iterator MBBI = MBB.begin();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
 
   // Get the number of bytes to allocate from the FrameInfo
   int NumBytes = (int) MFI->getStackSize();
@@ -133,24 +135,24 @@ void SparcRegisterInfo::emitPrologue(MachineFunction &MF) const {
   // ----------
   //   23 words * 4 bytes per word = 92 bytes
   NumBytes += 92;
+
   // Round up to next doubleword boundary -- a double-word boundary
   // is required by the ABI.
   NumBytes = (NumBytes + 7) & ~7;
   NumBytes = -NumBytes;
   
   if (NumBytes >= -4096) {
-    BuildMI(MBB, MBB.begin(), dl, TII.get(SP::SAVEri),
-            SP::O6).addReg(SP::O6).addImm(NumBytes);
+    BuildMI(MBB, MBBI, dl, TII.get(SP::SAVEri), SP::O6)
+      .addReg(SP::O6).addImm(NumBytes);
   } else {
-    MachineBasicBlock::iterator InsertPt = MBB.begin();
     // Emit this the hard way.  This clobbers G1 which we always know is 
     // available here.
     unsigned OffHi = (unsigned)NumBytes >> 10U;
-    BuildMI(MBB, InsertPt, dl, TII.get(SP::SETHIi), SP::G1).addImm(OffHi);
+    BuildMI(MBB, MBBI, dl, TII.get(SP::SETHIi), SP::G1).addImm(OffHi);
     // Emit G1 = G1 + I6
-    BuildMI(MBB, InsertPt, dl, TII.get(SP::ORri), SP::G1)
+    BuildMI(MBB, MBBI, dl, TII.get(SP::ORri), SP::G1)
       .addReg(SP::G1).addImm(NumBytes & ((1 << 10)-1));
-    BuildMI(MBB, InsertPt, dl, TII.get(SP::SAVErr), SP::O6)
+    BuildMI(MBB, MBBI, dl, TII.get(SP::SAVErr), SP::O6)
       .addReg(SP::O6).addReg(SP::G1);
   }
 }
@@ -158,7 +160,7 @@ void SparcRegisterInfo::emitPrologue(MachineFunction &MF) const {
 void SparcRegisterInfo::emitEpilogue(MachineFunction &MF,
                                      MachineBasicBlock &MBB) const {
   MachineBasicBlock::iterator MBBI = prior(MBB.end());
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = MBBI->getDebugLoc();
   assert(MBBI->getOpcode() == SP::RETL &&
          "Can only put epilog before 'retl' instruction!");
   BuildMI(MBB, MBBI, dl, TII.get(SP::RESTORErr), SP::G0).addReg(SP::G0)
index 059a836c9e89e16444b8bfcd0a008c58e9bedac0..ef5f9f99acc99b08bf35a5a8d6b020ebe6e86421 100644 (file)
@@ -398,7 +398,8 @@ void XCoreRegisterInfo::emitPrologue(MachineFunction &MF) const {
   MachineFrameInfo *MFI = MF.getFrameInfo();
   MachineModuleInfo *MMI = MFI->getMachineModuleInfo();
   XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = (MBBI != MBB.end() ?
+                 MBBI->getDebugLoc() : DebugLoc::getUnknownLoc());
 
   bool FP = hasFP(MF);
 
@@ -515,7 +516,7 @@ void XCoreRegisterInfo::emitEpilogue(MachineFunction &MF,
                                      MachineBasicBlock &MBB) const {
   MachineFrameInfo *MFI            = MF.getFrameInfo();
   MachineBasicBlock::iterator MBBI = prior(MBB.end());
-  DebugLoc dl = DebugLoc::getUnknownLoc();
+  DebugLoc dl = MBBI->getDebugLoc();
   
   bool FP = hasFP(MF);