summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2008-09-27 01:56:22 +0000
committerEvan Cheng <evan.cheng@apple.com>2008-09-27 01:56:22 +0000
commit184793fc8a9cf6ecc9147468bbcc068f472b8517 (patch)
tree8a3fb921e6c50ca0cd6c77e2ce1c1ce7d6171514
parent85263907681d21094cab75547cf4a5f538703fcc (diff)
downloadllvm-184793fc8a9cf6ecc9147468bbcc068f472b8517.tar.gz
llvm-184793fc8a9cf6ecc9147468bbcc068f472b8517.tar.bz2
llvm-184793fc8a9cf6ecc9147468bbcc068f472b8517.tar.xz
Re-apply 56683 with fixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56748 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/MachineFrameInfo.h11
-rw-r--r--lib/Target/ARM/ARMRegisterInfo.cpp3
-rw-r--r--lib/Target/IA64/IA64RegisterInfo.cpp3
-rw-r--r--lib/Target/Mips/MipsRegisterInfo.cpp3
-rw-r--r--lib/Target/X86/X86ISelLowering.cpp16
-rw-r--r--lib/Target/X86/X86RegisterInfo.cpp1
-rw-r--r--test/CodeGen/X86/2008-09-26-FrameAddrBug.ll16
-rw-r--r--test/CodeGen/X86/x86-64-frameaddr.ll5
-rw-r--r--test/CodeGen/X86/x86-frameaddr.ll1
-rw-r--r--test/CodeGen/X86/x86-frameaddr2.ll1
10 files changed, 45 insertions, 15 deletions
diff --git a/include/llvm/CodeGen/MachineFrameInfo.h b/include/llvm/CodeGen/MachineFrameInfo.h
index 6c49eaf88e..363f206348 100644
--- a/include/llvm/CodeGen/MachineFrameInfo.h
+++ b/include/llvm/CodeGen/MachineFrameInfo.h
@@ -118,6 +118,10 @@ class MachineFrameInfo {
///
bool HasVarSizedObjects;
+ /// FrameAddressTaken - This boolean keeps track of whether there is a call
+ /// to builtin @llvm.frameaddress.
+ bool FrameAddressTaken;
+
/// StackSize - The prolog/epilog code inserter calculates the final stack
/// offsets for all of the fixed size objects, updating the Objects list
/// above. It then updates StackSize to contain the number of bytes that need
@@ -174,6 +178,7 @@ public:
MachineFrameInfo(const TargetFrameInfo &tfi) : TFI(tfi) {
StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
HasVarSizedObjects = false;
+ FrameAddressTaken = false;
HasCalls = false;
MaxCallFrameSize = 0;
MMI = 0;
@@ -190,6 +195,12 @@ public:
///
bool hasVarSizedObjects() const { return HasVarSizedObjects; }
+ /// isFrameAddressTaken - This method may be called any time after instruction
+ /// selection is complete to determine if there is a call to
+ /// @llvm.frameaddress in this function.
+ bool isFrameAddressTaken() const { return FrameAddressTaken; }
+ void setFrameAddressIsTaken(bool T) { FrameAddressTaken = T; }
+
/// getObjectIndexBegin - Return the minimum frame object index...
///
int getObjectIndexBegin() const { return -NumFixedObjects; }
diff --git a/lib/Target/ARM/ARMRegisterInfo.cpp b/lib/Target/ARM/ARMRegisterInfo.cpp
index 7787f43ff6..3a0a57d92d 100644
--- a/lib/Target/ARM/ARMRegisterInfo.cpp
+++ b/lib/Target/ARM/ARMRegisterInfo.cpp
@@ -209,7 +209,8 @@ ARMRegisterInfo::requiresRegisterScavenging(const MachineFunction &MF) const {
/// or if frame pointer elimination is disabled.
///
bool ARMRegisterInfo::hasFP(const MachineFunction &MF) const {
- return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
+ const MachineFrameInfo *MFI = MF.getFrameInfo();
+ return NoFramePointerElim || MFI->hasVarSizedObjects();
}
// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
diff --git a/lib/Target/IA64/IA64RegisterInfo.cpp b/lib/Target/IA64/IA64RegisterInfo.cpp
index 848eab8ed9..a0bc9f860d 100644
--- a/lib/Target/IA64/IA64RegisterInfo.cpp
+++ b/lib/Target/IA64/IA64RegisterInfo.cpp
@@ -75,7 +75,8 @@ BitVector IA64RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
// if frame pointer elimination is disabled.
//
bool IA64RegisterInfo::hasFP(const MachineFunction &MF) const {
- return NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects();
+ const MachineFrameInfo *MFI = MF.getFrameInfo();
+ return NoFramePointerElim || MFI->hasVarSizedObjects();
}
void IA64RegisterInfo::
diff --git a/lib/Target/Mips/MipsRegisterInfo.cpp b/lib/Target/Mips/MipsRegisterInfo.cpp
index 6d75f460d3..de0cb52240 100644
--- a/lib/Target/Mips/MipsRegisterInfo.cpp
+++ b/lib/Target/Mips/MipsRegisterInfo.cpp
@@ -324,7 +324,8 @@ void MipsRegisterInfo::adjustMipsStackFrame(MachineFunction &MF) const
// if frame pointer elimination is disabled.
bool MipsRegisterInfo::
hasFP(const MachineFunction &MF) const {
- return (NoFramePointerElim || MF.getFrameInfo()->hasVarSizedObjects());
+ const MachineFrameInfo *MFI = MF.getFrameInfo();
+ return NoFramePointerElim || MFI->hasVarSizedObjects();
}
// This function eliminate ADJCALLSTACKDOWN,
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 8e8a51a920..9135432153 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -5645,13 +5645,15 @@ SDValue X86TargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) {
}
SDValue X86TargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) {
- // Depths > 0 not supported yet!
- if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() > 0)
- return SDValue();
-
- SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
- return DAG.getNode(ISD::SUB, getPointerTy(), RetAddrFI,
- DAG.getIntPtrConstant(TD->getPointerSize()));
+ MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
+ MFI->setFrameAddressIsTaken(true);
+ MVT VT = Op.getValueType();
+ unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
+ unsigned FrameReg = Subtarget->is64Bit() ? X86::RBP : X86::EBP;
+ SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), FrameReg, VT);
+ while (Depth--)
+ FrameAddr = DAG.getLoad(VT, DAG.getEntryNode(), FrameAddr, NULL, 0);
+ return FrameAddr;
}
SDValue X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDValue Op,
diff --git a/lib/Target/X86/X86RegisterInfo.cpp b/lib/Target/X86/X86RegisterInfo.cpp
index 49766a8fc7..d618ffdeb7 100644
--- a/lib/Target/X86/X86RegisterInfo.cpp
+++ b/lib/Target/X86/X86RegisterInfo.cpp
@@ -299,6 +299,7 @@ bool X86RegisterInfo::hasFP(const MachineFunction &MF) const {
return (NoFramePointerElim ||
needsStackRealignment(MF) ||
MFI->hasVarSizedObjects() ||
+ MFI->isFrameAddressTaken() ||
MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
(MMI && MMI->callsUnwindInit()));
}
diff --git a/test/CodeGen/X86/2008-09-26-FrameAddrBug.ll b/test/CodeGen/X86/2008-09-26-FrameAddrBug.ll
new file mode 100644
index 0000000000..b1f5ab5907
--- /dev/null
+++ b/test/CodeGen/X86/2008-09-26-FrameAddrBug.ll
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin9
+
+ %struct._Unwind_Context = type { [18 x i8*], i8*, i8*, i8*, %struct.dwarf_eh_bases, i32, i32, i32, [18 x i8] }
+ %struct._Unwind_Exception = type { i64, void (i32, %struct._Unwind_Exception*)*, i32, i32, [3 x i32] }
+ %struct.dwarf_eh_bases = type { i8*, i8*, i8* }
+
+declare fastcc void @uw_init_context_1(%struct._Unwind_Context*, i8*, i8*)
+
+declare i8* @llvm.eh.dwarf.cfa(i32) nounwind
+
+define hidden void @_Unwind_Resume(%struct._Unwind_Exception* %exc) noreturn noreturn {
+entry:
+ %0 = call i8* @llvm.eh.dwarf.cfa(i32 0) ; <i8*> [#uses=1]
+ call fastcc void @uw_init_context_1(%struct._Unwind_Context* null, i8* %0, i8* null)
+ unreachable
+}
diff --git a/test/CodeGen/X86/x86-64-frameaddr.ll b/test/CodeGen/X86/x86-64-frameaddr.ll
index 86a238f6ab..80060996f3 100644
--- a/test/CodeGen/X86/x86-64-frameaddr.ll
+++ b/test/CodeGen/X86/x86-64-frameaddr.ll
@@ -1,7 +1,6 @@
-; RUN: llvm-as < %s | llc -march=x86-64 | grep {leaq -8(%rsp), %rax}
-@llvm.noinline = appending global [1 x i8*] [ i8* bitcast (i64* ()* @stack_end_address to i8*) ], section "llvm.metadata"
+; RUN: llvm-as < %s | llc -march=x86-64 | grep movq | grep rbp
-define internal i64* @stack_end_address() nounwind {
+define i64* @stack_end_address() nounwind {
entry:
tail call i8* @llvm.frameaddress( i32 0 )
bitcast i8* %0 to i64*
diff --git a/test/CodeGen/X86/x86-frameaddr.ll b/test/CodeGen/X86/x86-frameaddr.ll
index 0707d92d09..b9d6d13880 100644
--- a/test/CodeGen/X86/x86-frameaddr.ll
+++ b/test/CodeGen/X86/x86-frameaddr.ll
@@ -1,5 +1,4 @@
; RUN: llvm-as < %s | llc -march=x86 | grep mov | grep ebp
-; XFAIL: *
define i8* @t() nounwind {
entry:
diff --git a/test/CodeGen/X86/x86-frameaddr2.ll b/test/CodeGen/X86/x86-frameaddr2.ll
index bcb87c549b..f50ab072c3 100644
--- a/test/CodeGen/X86/x86-frameaddr2.ll
+++ b/test/CodeGen/X86/x86-frameaddr2.ll
@@ -1,5 +1,4 @@
; RUN: llvm-as < %s | llc -march=x86 | grep mov | count 3
-; XFAIL: *
define i8* @t() nounwind {
entry: