improve EH global handling, patch by Duncan Sands.
[oota-llvm.git] / lib / CodeGen / PrologEpilogInserter.cpp
index b76fa3f4eb4b2d6d630da9ed1e6097e4804eb81a..478f3d3a5f2b6f578f419ad5a3e5f77e9671851d 100644 (file)
@@ -156,19 +156,18 @@ void PEI::calculateCalleeSavedRegisters(MachineFunction &Fn) {
   // Now figure out which *callee saved* registers are modified by the current
   // function, thus needing to be saved and restored in the prolog/epilog.
   //
-  const bool *PhysRegsUsed = Fn.getUsedPhysregs();
   const TargetRegisterClass* const *CSRegClasses =
     RegInfo->getCalleeSavedRegClasses();
   std::vector<CalleeSavedInfo> CSI;
   for (unsigned i = 0; CSRegs[i]; ++i) {
     unsigned Reg = CSRegs[i];
-    if (PhysRegsUsed[Reg]) {
+    if (Fn.isPhysRegUsed(Reg)) {
         // If the reg is modified, save it!
       CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
     } else {
       for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
            *AliasSet; ++AliasSet) {  // Check alias registers too.
-        if (PhysRegsUsed[*AliasSet]) {
+        if (Fn.isPhysRegUsed(*AliasSet)) {
           CSI.push_back(CalleeSavedInfo(Reg, CSRegClasses[i]));
           break;
         }
@@ -305,7 +304,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
   // Start at the beginning of the local area.
   // The Offset is the distance from the stack top in the direction
   // of stack growth -- so it's always positive.
-  int Offset = TFI.getOffsetOfLocalArea();
+  int64_t Offset = TFI.getOffsetOfLocalArea();
   if (StackGrowsDown)
     Offset = -Offset;
   assert(Offset >= 0
@@ -317,7 +316,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
   // so we adjust 'Offset' to point to the end of last fixed sized
   // preallocated object.
   for (int i = FFI->getObjectIndexBegin(); i != 0; ++i) {
-    int FixedOff;
+    int64_t FixedOff;
     if (StackGrowsDown) {
       // The maximum distance from the stack pointer is at lower address of
       // the object -- which is given by offset. For down growing stack
@@ -455,7 +454,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &Fn) {
       Offset += FFI->getMaxCallFrameSize();
 
     unsigned AlignMask = TFI.getStackAlignment() - 1;
-    Offset = (Offset + AlignMask) & ~AlignMask;
+    Offset = (Offset + AlignMask) & ~uint64_t(AlignMask);
   }
 
   // Update frame info to pretend that this is part of the stack...
@@ -498,20 +497,22 @@ void PEI::replaceFrameIndices(MachineFunction &Fn) {
 
   for (MachineFunction::iterator BB = Fn.begin(), E = Fn.end(); BB != E; ++BB) {
     if (RS) RS->enterBasicBlock(BB);
-    for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
-      for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
-        if (I->getOperand(i).isFrameIndex()) {
+    for (MachineBasicBlock::iterator I = BB->begin(); I != BB->end(); ) {
+      MachineInstr *MI = I++;
+      for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
+        if (MI->getOperand(i).isFrameIndex()) {
           // If this instruction has a FrameIndex operand, we need to use that
           // target machine register info object to eliminate it.
-          MRI.eliminateFrameIndex(I, RS);
+          MRI.eliminateFrameIndex(MI, RS);
 
           // Revisit the instruction in full.  Some instructions (e.g. inline
           // asm instructions) can have multiple frame indices.
-          e = I->getNumOperands();
-          i = -1U;
+          --I;
+          MI = 0;
+          break;
         }
       // Update register states.
-      if (RS) RS->forward(I);
+      if (RS && MI) RS->forward(MI);
     }
   }
 }