[X86] Refactor the prologue emission to prepare for shrink-wrapping.
[oota-llvm.git] / lib / Target / X86 / X86RegisterInfo.cpp
index 6d031830b423e9652b319cf70ba93736ce698f54..1f361631a0b7dc86cb32d23471721b49d02306a8 100644 (file)
@@ -14,6 +14,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "X86RegisterInfo.h"
+#include "X86FrameLowering.h"
 #include "X86InstrBuilder.h"
 #include "X86MachineFunctionInfo.h"
 #include "X86Subtarget.h"
@@ -491,7 +492,8 @@ X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
   unsigned BasePtr;
 
   unsigned Opc = MI.getOpcode();
-  bool AfterFPPop = Opc == X86::TAILJMPm64 || Opc == X86::TAILJMPm;
+  bool AfterFPPop = Opc == X86::TAILJMPm64 || Opc == X86::TAILJMPm ||
+                    Opc == X86::TCRETURNmi || Opc == X86::TCRETURNmi64;
   if (hasBasePointer(MF))
     BasePtr = (FrameIndex < 0 ? FramePtr : getBaseRegister());
   else if (needsStackRealignment(MF))
@@ -507,15 +509,14 @@ X86RegisterInfo::eliminateFrameIndex(MachineBasicBlock::iterator II,
   // offset is from the SP at the end of the prologue, not the FP location. This
   // matches the behavior of llvm.frameaddress.
   if (Opc == TargetOpcode::FRAME_ALLOC) {
-    assert(TFI->hasFP(MF) && "frame alloc requires FP");
     MachineOperand &FI = MI.getOperand(FIOperandNum);
-    const MachineFrameInfo *MFI = MF.getFrameInfo();
-    int Offset = MFI->getObjectOffset(FrameIndex) - TFI->getOffsetOfLocalArea();
     bool IsWinEH = MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
+    int Offset;
     if (IsWinEH)
-      Offset += MFI->getStackSize();
+      Offset = static_cast<const X86FrameLowering *>(TFI)
+                     ->getFrameIndexOffsetFromSP(MF, FrameIndex);
     else
-      Offset += SlotSize;
+      Offset = TFI->getFrameIndexOffset(MF, FrameIndex);
     FI.ChangeToImmediate(Offset);
     return;
   }