Avoid unnecessarily casting away const.
[oota-llvm.git] / lib / CodeGen / PrologEpilogInserter.cpp
index 0f2da0bc38759ef1db776956121922887efd110e..c990ba4776fda0073bc6b1b218435afffe413041 100644 (file)
@@ -243,11 +243,19 @@ void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) {
     return;
 
   const TargetInstrInfo &TII = *Fn.getTarget().getInstrInfo();
-  
+
   // Now that we have a stack slot for each register to be saved, insert spill
   // code into the entry block.
   MachineBasicBlock *MBB = Fn.begin();
   MachineBasicBlock::iterator I = MBB->begin();
+
+  // Do not insert prologue code before debug LABELs at the start of the
+  // entry block.
+  MachineModuleInfo *MMI = FFI->getMachineModuleInfo();
+  if (MMI && MMI->hasDebugInfo())
+    while (I != MBB->end() && I->getOpcode() == TargetInstrInfo::LABEL)
+      ++I;
+
   if (!TII.spillCalleeSavedRegisters(*MBB, I, CSI)) {
     for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
       // Add the callee-saved register as live-in. It's killed at the spill.
@@ -262,14 +270,14 @@ void PEI::saveCalleeSavedRegisters(MachineFunction &Fn) {
   // Add code to restore the callee-save registers in each exiting block.
   for (MachineFunction::iterator FI = Fn.begin(), E = Fn.end(); FI != E; ++FI)
     // If last instruction is a return instruction, add an epilogue.
-    if (!FI->empty() && FI->back().getDesc()->isReturn()) {
+    if (!FI->empty() && FI->back().getDesc().isReturn()) {
       MBB = FI;
       I = MBB->end(); --I;
 
       // Skip over all terminator instructions, which are part of the return
       // sequence.
       MachineBasicBlock::iterator I2 = I;
-      while (I2 != MBB->begin() && (--I2)->getDesc()->isTerminator())
+      while (I2 != MBB->begin() && (--I2)->getDesc().isTerminator())
         I = I2;
 
       bool AtStart = I == MBB->begin();
@@ -485,7 +493,7 @@ void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
   // Add epilogue to restore the callee-save registers in each exiting block
   for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
     // If last instruction is a return instruction, add an epilogue
-    if (!I->empty() && I->back().getDesc()->isReturn())
+    if (!I->empty() && I->back().getDesc().isReturn())
       Fn.getTarget().getRegisterInfo()->emitEpilogue(Fn, *I);
   }
 }