[llvm-commits] [llvm] r56683 - in /llvm/trunk: include/llvm/CodeGen/ lib/CodeGen/SelectionDAG/ lib/Target/ARM/ lib/Target/Alpha/ lib/Target/CellSPU/ lib/Target/IA64/ lib/Target/Mips/ lib/Target/PowerPC/ lib/Target/X86/ test/CodeGen/X86/
Evan Cheng
evan.cheng at apple.com
Fri Sep 26 12:48:35 PDT 2008
Author: evancheng
Date: Fri Sep 26 14:48:35 2008
New Revision: 56683
URL: http://llvm.org/viewvc/llvm-project?rev=56683&view=rev
Log:
Fix @llvm.frameaddress codegen. FP elimination optimization should be disabled when frame address is desired. Also add support for depth > 0.
Added:
llvm/trunk/test/CodeGen/X86/x86-frameaddr.ll
llvm/trunk/test/CodeGen/X86/x86-frameaddr2.ll
Modified:
llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
llvm/trunk/lib/Target/ARM/ARMRegisterInfo.cpp
llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.cpp
llvm/trunk/lib/Target/CellSPU/SPURegisterInfo.cpp
llvm/trunk/lib/Target/IA64/IA64RegisterInfo.cpp
llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp
llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
llvm/trunk/test/CodeGen/X86/x86-64-frameaddr.ll
Modified: llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineFrameInfo.h Fri Sep 26 14:48:35 2008
@@ -118,6 +118,10 @@
///
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 @@
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 @@
///
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; }
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp Fri Sep 26 14:48:35 2008
@@ -3483,10 +3483,13 @@
setValue(&I, DAG.getNode(ISD::RETURNADDR, TLI.getPointerTy(),
getValue(I.getOperand(1))));
return 0;
- case Intrinsic::frameaddress:
+ case Intrinsic::frameaddress: {
+ MachineFrameInfo *MFI = CurMBB->getParent()->getFrameInfo();
+ MFI->setFrameAddressIsTaken(true);
setValue(&I, DAG.getNode(ISD::FRAMEADDR, TLI.getPointerTy(),
getValue(I.getOperand(1))));
return 0;
+ }
case Intrinsic::setjmp:
return "_setjmp"+!TLI.usesUnderscoreSetJmp();
break;
Modified: llvm/trunk/lib/Target/ARM/ARMRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/ARMRegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/ARMRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/ARM/ARMRegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -209,7 +209,9 @@
/// 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() ||
+ MFI->isFrameAddressTaken();
}
// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
Modified: llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/Alpha/AlphaRegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -104,7 +104,7 @@
//
bool AlphaRegisterInfo::hasFP(const MachineFunction &MF) const {
const MachineFrameInfo *MFI = MF.getFrameInfo();
- return MFI->hasVarSizedObjects();
+ return MFI->hasVarSizedObjects() || MFI->isFrameAddressTaken();
}
void AlphaRegisterInfo::
Modified: llvm/trunk/lib/Target/CellSPU/SPURegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CellSPU/SPURegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/CellSPU/SPURegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/CellSPU/SPURegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -294,7 +294,8 @@
//
static bool needsFP(const MachineFunction &MF) {
const MachineFrameInfo *MFI = MF.getFrameInfo();
- return NoFramePointerElim || MFI->hasVarSizedObjects();
+ return NoFramePointerElim || MFI->hasVarSizedObjects() ||
+ MFI->isFrameAddressTaken();
}
//--------------------------------------------------------------------------
Modified: llvm/trunk/lib/Target/IA64/IA64RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/IA64/IA64RegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/IA64/IA64RegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/IA64/IA64RegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -75,7 +75,9 @@
// 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() ||
+ MFI->isFrameAddressTaken();
}
void IA64RegisterInfo::
Modified: llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsRegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -324,7 +324,9 @@
// 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() ||
+ MFI->isFrameAddressTaken();
}
// This function eliminate ADJCALLSTACKDOWN,
Modified: llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCRegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -333,6 +333,7 @@
static bool needsFP(const MachineFunction &MF) {
const MachineFrameInfo *MFI = MF.getFrameInfo();
return NoFramePointerElim || MFI->hasVarSizedObjects() ||
+ MFI->isFrameAddressTaken() ||
(PerformTailCallOpt && MF.getInfo<PPCFunctionInfo>()->hasFastCall());
}
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Sep 26 14:48:35 2008
@@ -5645,13 +5645,13 @@
}
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()));
+ unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
+ unsigned FrameReg = Subtarget->is64Bit() ? X86::RBP : X86::EBP;
+ SDValue FrameAddr = DAG.getRegister(FrameReg, getPointerTy());
+ while (Depth--)
+ FrameAddr = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), FrameAddr,
+ NULL, 0);
+ return FrameAddr;
}
SDValue X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDValue Op,
Modified: llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86RegisterInfo.cpp Fri Sep 26 14:48:35 2008
@@ -299,6 +299,7 @@
return (NoFramePointerElim ||
needsStackRealignment(MF) ||
MFI->hasVarSizedObjects() ||
+ MFI->isFrameAddressTaken() ||
MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
(MMI && MMI->callsUnwindInit()));
}
Modified: llvm/trunk/test/CodeGen/X86/x86-64-frameaddr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-64-frameaddr.ll?rev=56683&r1=56682&r2=56683&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-64-frameaddr.ll (original)
+++ llvm/trunk/test/CodeGen/X86/x86-64-frameaddr.ll Fri Sep 26 14:48:35 2008
@@ -1,7 +1,6 @@
-; RUN: llvm-as < %s | llc -march=x86-64 | grep {leaq -8(%rsp), %rax}
- at 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*
Added: llvm/trunk/test/CodeGen/X86/x86-frameaddr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-frameaddr.ll?rev=56683&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-frameaddr.ll (added)
+++ llvm/trunk/test/CodeGen/X86/x86-frameaddr.ll Fri Sep 26 14:48:35 2008
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep mov | grep ebp
+
+define i8* @t() nounwind {
+entry:
+ %0 = tail call i8* @llvm.frameaddress(i32 0)
+ ret i8* %0
+}
+
+declare i8* @llvm.frameaddress(i32) nounwind readnone
Added: llvm/trunk/test/CodeGen/X86/x86-frameaddr2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-frameaddr2.ll?rev=56683&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-frameaddr2.ll (added)
+++ llvm/trunk/test/CodeGen/X86/x86-frameaddr2.ll Fri Sep 26 14:48:35 2008
@@ -0,0 +1,9 @@
+; RUN: llvm-as < %s | llc -march=x86 | grep mov | count 3
+
+define i8* @t() nounwind {
+entry:
+ %0 = tail call i8* @llvm.frameaddress(i32 2)
+ ret i8* %0
+}
+
+declare i8* @llvm.frameaddress(i32) nounwind readnone
More information about the llvm-commits
mailing list