Move hasFP() and few related hooks to TargetFrameInfo.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119740 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/ARM/Thumb1FrameInfo.cpp b/lib/Target/ARM/Thumb1FrameInfo.cpp
index cc8d0ab..6a3c1e1 100644
--- a/lib/Target/ARM/Thumb1FrameInfo.cpp
+++ b/lib/Target/ARM/Thumb1FrameInfo.cpp
@@ -20,6 +20,19 @@
 
 using namespace llvm;
 
+bool Thumb1FrameInfo::hasReservedCallFrame(const MachineFunction &MF) const {
+  const MachineFrameInfo *FFI = MF.getFrameInfo();
+  unsigned CFSize = FFI->getMaxCallFrameSize();
+  // It's not always a good idea to include the call frame as part of the
+  // stack frame. ARM (especially Thumb) has small immediate offset to
+  // address the stack frame. So a large call frame can cause poor codegen
+  // and may even makes it impossible to scavenge a register.
+  if (CFSize >= ((1 << 8) - 1) * 4 / 2) // Half of imm8 * 4
+    return false;
+
+  return !MF.getFrameInfo()->hasVarSizedObjects();
+}
+
 static void emitSPUpdate(MachineBasicBlock &MBB,
                          MachineBasicBlock::iterator &MBBI,
                          const TargetInstrInfo &TII, DebugLoc dl,
@@ -105,7 +118,7 @@
   }
 
   // Adjust FP so it point to the stack slot that contains the previous FP.
-  if (RegInfo->hasFP(MF)) {
+  if (hasFP(MF)) {
     BuildMI(MBB, MBBI, dl, TII.get(ARM::tADDrSPi), FramePtr)
       .addFrameIndex(FramePtrSpillFI).addImm(0);
     AFI->setShouldRestoreSPFromFP(true);
@@ -126,7 +139,7 @@
     emitSPUpdate(MBB, MBBI, TII, dl, *RegInfo, -NumBytes);
   }
 
-  if (STI.isTargetELF() && RegInfo->hasFP(MF))
+  if (STI.isTargetELF() && hasFP(MF))
     MFI->setOffsetAdjustment(MFI->getOffsetAdjustment() -
                              AFI->getFramePtrSpillOffset());