[llvm-commits] CVS: llvm/lib/CodeGen/PrologEpilogInserter.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Jan 15 16:53:01 PST 2003


Changes in directory llvm/lib/CodeGen:

PrologEpilogInserter.cpp updated: 1.5 -> 1.6

---
Log message:

* Insert prolog/epilog code before rewriting indexes
* Fix calculation of frame offsets when there is an offset.



---
Diffs of the changes:

Index: llvm/lib/CodeGen/PrologEpilogInserter.cpp
diff -u llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.5 llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.6
--- llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.5	Tue Jan 14 15:58:41 2003
+++ llvm/lib/CodeGen/PrologEpilogInserter.cpp	Wed Jan 15 16:52:34 2003
@@ -41,13 +41,13 @@
       // Calculate actual frame offsets for all of the abstract stack objects...
       calculateFrameObjectOffsets(Fn);
 
+      // Add prolog and epilog code to the function.
+      insertPrologEpilogCode(Fn);
+
       // Replace all MO_FrameIndex operands with physical register references
       // and actual offsets.
       //
       replaceFrameIndices(Fn);
-
-      // Add prolog and epilog code to the function.
-      insertPrologEpilogCode(Fn);
       return true;
     }
 
@@ -187,7 +187,7 @@
   MachineFrameInfo *FFI = Fn.getFrameInfo();
 
   // Start at the beginning of the local area...
-  int Offset = -TFI.getOffsetOfLocalArea();
+  int Offset = TFI.getOffsetOfLocalArea();
   for (unsigned i = 0, e = FFI->getObjectIndexEnd(); i != e; ++i) {
     Offset += FFI->getObjectSize(i);         // Allocate Size bytes...
 
@@ -202,7 +202,25 @@
   Offset = (Offset+StackAlign-1)/StackAlign*StackAlign;
 
   // Set the final value of the stack pointer...
-  FFI->setStackSize(Offset);
+  FFI->setStackSize(Offset-TFI.getOffsetOfLocalArea());
+}
+
+
+/// insertPrologEpilogCode - Scan the function for modified caller saved
+/// registers, insert spill code for these caller saved registers, then add
+/// prolog and epilog code to the function.
+///
+void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
+  // Add prologue to the function...
+  Fn.getTarget().getRegisterInfo()->emitPrologue(Fn);
+
+  // Add epilogue to restore the callee-save registers in each exiting block
+  const TargetInstrInfo &TII = Fn.getTarget().getInstrInfo();
+  for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
+    // If last instruction is a return instruction, add an epilogue
+    if (TII.isReturn(I->back()->getOpcode()))
+      Fn.getTarget().getRegisterInfo()->emitEpilogue(Fn, *I);
+  }
 }
 
 
@@ -225,22 +243,4 @@
 	  MRI.eliminateFrameIndex(Fn, I);
 	  break;
 	}
-}
-
-
-/// insertPrologEpilogCode - Scan the function for modified caller saved
-/// registers, insert spill code for these caller saved registers, then add
-/// prolog and epilog code to the function.
-///
-void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
-  // Add prologue to the function...
-  Fn.getTarget().getRegisterInfo()->emitPrologue(Fn);
-
-  // Add epilogue to restore the callee-save registers in each exiting block
-  const TargetInstrInfo &TII = Fn.getTarget().getInstrInfo();
-  for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
-    // If last instruction is a return instruction, add an epilogue
-    if (TII.isReturn(I->back()->getOpcode()))
-      Fn.getTarget().getRegisterInfo()->emitEpilogue(Fn, *I);
-  }
 }





More information about the llvm-commits mailing list