mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-17 20:29:31 +00:00
Fix @llvm.frameaddress codegen. FP elimination optimization should be disabled when frame address is desired. Also add support for depth > 0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56683 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dbc2e856fc
commit
36a55023c1
@ -118,6 +118,10 @@ class MachineFrameInfo {
|
|||||||
///
|
///
|
||||||
bool HasVarSizedObjects;
|
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
|
/// StackSize - The prolog/epilog code inserter calculates the final stack
|
||||||
/// offsets for all of the fixed size objects, updating the Objects list
|
/// 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
|
/// above. It then updates StackSize to contain the number of bytes that need
|
||||||
@ -174,6 +178,7 @@ public:
|
|||||||
MachineFrameInfo(const TargetFrameInfo &tfi) : TFI(tfi) {
|
MachineFrameInfo(const TargetFrameInfo &tfi) : TFI(tfi) {
|
||||||
StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
|
StackSize = NumFixedObjects = OffsetAdjustment = MaxAlignment = 0;
|
||||||
HasVarSizedObjects = false;
|
HasVarSizedObjects = false;
|
||||||
|
FrameAddressTaken = false;
|
||||||
HasCalls = false;
|
HasCalls = false;
|
||||||
MaxCallFrameSize = 0;
|
MaxCallFrameSize = 0;
|
||||||
MMI = 0;
|
MMI = 0;
|
||||||
@ -190,6 +195,12 @@ public:
|
|||||||
///
|
///
|
||||||
bool hasVarSizedObjects() const { return HasVarSizedObjects; }
|
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...
|
/// getObjectIndexBegin - Return the minimum frame object index...
|
||||||
///
|
///
|
||||||
int getObjectIndexBegin() const { return -NumFixedObjects; }
|
int getObjectIndexBegin() const { return -NumFixedObjects; }
|
||||||
|
@ -3483,10 +3483,13 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
|
|||||||
setValue(&I, DAG.getNode(ISD::RETURNADDR, TLI.getPointerTy(),
|
setValue(&I, DAG.getNode(ISD::RETURNADDR, TLI.getPointerTy(),
|
||||||
getValue(I.getOperand(1))));
|
getValue(I.getOperand(1))));
|
||||||
return 0;
|
return 0;
|
||||||
case Intrinsic::frameaddress:
|
case Intrinsic::frameaddress: {
|
||||||
|
MachineFrameInfo *MFI = CurMBB->getParent()->getFrameInfo();
|
||||||
|
MFI->setFrameAddressIsTaken(true);
|
||||||
setValue(&I, DAG.getNode(ISD::FRAMEADDR, TLI.getPointerTy(),
|
setValue(&I, DAG.getNode(ISD::FRAMEADDR, TLI.getPointerTy(),
|
||||||
getValue(I.getOperand(1))));
|
getValue(I.getOperand(1))));
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
case Intrinsic::setjmp:
|
case Intrinsic::setjmp:
|
||||||
return "_setjmp"+!TLI.usesUnderscoreSetJmp();
|
return "_setjmp"+!TLI.usesUnderscoreSetJmp();
|
||||||
break;
|
break;
|
||||||
|
@ -209,7 +209,9 @@ ARMRegisterInfo::requiresRegisterScavenging(const MachineFunction &MF) const {
|
|||||||
/// or if frame pointer elimination is disabled.
|
/// or if frame pointer elimination is disabled.
|
||||||
///
|
///
|
||||||
bool ARMRegisterInfo::hasFP(const MachineFunction &MF) const {
|
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
|
// hasReservedCallFrame - Under normal circumstances, when a frame pointer is
|
||||||
|
@ -104,7 +104,7 @@ BitVector AlphaRegisterInfo::getReservedRegs(const MachineFunction &MF) const {
|
|||||||
//
|
//
|
||||||
bool AlphaRegisterInfo::hasFP(const MachineFunction &MF) const {
|
bool AlphaRegisterInfo::hasFP(const MachineFunction &MF) const {
|
||||||
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
return MFI->hasVarSizedObjects();
|
return MFI->hasVarSizedObjects() || MFI->isFrameAddressTaken();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlphaRegisterInfo::
|
void AlphaRegisterInfo::
|
||||||
|
@ -294,7 +294,8 @@ BitVector SPURegisterInfo::getReservedRegs(const MachineFunction &MF) const {
|
|||||||
//
|
//
|
||||||
static bool needsFP(const MachineFunction &MF) {
|
static bool needsFP(const MachineFunction &MF) {
|
||||||
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
return NoFramePointerElim || MFI->hasVarSizedObjects();
|
return NoFramePointerElim || MFI->hasVarSizedObjects() ||
|
||||||
|
MFI->isFrameAddressTaken();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
|
@ -75,7 +75,9 @@ BitVector IA64RegisterInfo::getReservedRegs(const MachineFunction &MF) const {
|
|||||||
// if frame pointer elimination is disabled.
|
// if frame pointer elimination is disabled.
|
||||||
//
|
//
|
||||||
bool IA64RegisterInfo::hasFP(const MachineFunction &MF) const {
|
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::
|
void IA64RegisterInfo::
|
||||||
|
@ -324,7 +324,9 @@ void MipsRegisterInfo::adjustMipsStackFrame(MachineFunction &MF) const
|
|||||||
// if frame pointer elimination is disabled.
|
// if frame pointer elimination is disabled.
|
||||||
bool MipsRegisterInfo::
|
bool MipsRegisterInfo::
|
||||||
hasFP(const MachineFunction &MF) const {
|
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,
|
// This function eliminate ADJCALLSTACKDOWN,
|
||||||
|
@ -333,6 +333,7 @@ PPCRegisterInfo::getCalleeSavedRegClasses(const MachineFunction *MF) const {
|
|||||||
static bool needsFP(const MachineFunction &MF) {
|
static bool needsFP(const MachineFunction &MF) {
|
||||||
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
const MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
return NoFramePointerElim || MFI->hasVarSizedObjects() ||
|
return NoFramePointerElim || MFI->hasVarSizedObjects() ||
|
||||||
|
MFI->isFrameAddressTaken() ||
|
||||||
(PerformTailCallOpt && MF.getInfo<PPCFunctionInfo>()->hasFastCall());
|
(PerformTailCallOpt && MF.getInfo<PPCFunctionInfo>()->hasFastCall());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5645,13 +5645,13 @@ SDValue X86TargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDValue X86TargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) {
|
SDValue X86TargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) {
|
||||||
// Depths > 0 not supported yet!
|
unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
|
||||||
if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() > 0)
|
unsigned FrameReg = Subtarget->is64Bit() ? X86::RBP : X86::EBP;
|
||||||
return SDValue();
|
SDValue FrameAddr = DAG.getRegister(FrameReg, getPointerTy());
|
||||||
|
while (Depth--)
|
||||||
SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
|
FrameAddr = DAG.getLoad(getPointerTy(), DAG.getEntryNode(), FrameAddr,
|
||||||
return DAG.getNode(ISD::SUB, getPointerTy(), RetAddrFI,
|
NULL, 0);
|
||||||
DAG.getIntPtrConstant(TD->getPointerSize()));
|
return FrameAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDValue Op,
|
SDValue X86TargetLowering::LowerFRAME_TO_ARGS_OFFSET(SDValue Op,
|
||||||
|
@ -299,6 +299,7 @@ bool X86RegisterInfo::hasFP(const MachineFunction &MF) const {
|
|||||||
return (NoFramePointerElim ||
|
return (NoFramePointerElim ||
|
||||||
needsStackRealignment(MF) ||
|
needsStackRealignment(MF) ||
|
||||||
MFI->hasVarSizedObjects() ||
|
MFI->hasVarSizedObjects() ||
|
||||||
|
MFI->isFrameAddressTaken() ||
|
||||||
MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
|
MF.getInfo<X86MachineFunctionInfo>()->getForceFramePointer() ||
|
||||||
(MMI && MMI->callsUnwindInit()));
|
(MMI && MMI->callsUnwindInit()));
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
; RUN: llvm-as < %s | llc -march=x86-64 | grep {leaq -8(%rsp), %rax}
|
; RUN: llvm-as < %s | llc -march=x86-64 | grep movq | grep rbp
|
||||||
@llvm.noinline = appending global [1 x i8*] [ i8* bitcast (i64* ()* @stack_end_address to i8*) ], section "llvm.metadata"
|
|
||||||
|
|
||||||
define internal i64* @stack_end_address() nounwind {
|
define i64* @stack_end_address() nounwind {
|
||||||
entry:
|
entry:
|
||||||
tail call i8* @llvm.frameaddress( i32 0 )
|
tail call i8* @llvm.frameaddress( i32 0 )
|
||||||
bitcast i8* %0 to i64*
|
bitcast i8* %0 to i64*
|
||||||
|
9
test/CodeGen/X86/x86-frameaddr.ll
Normal file
9
test/CodeGen/X86/x86-frameaddr.ll
Normal file
@ -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
|
9
test/CodeGen/X86/x86-frameaddr2.ll
Normal file
9
test/CodeGen/X86/x86-frameaddr2.ll
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user