mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-13 17:00:01 +00:00
Implement builtin_return_address(x) and builtin_frame_address(x)
on PPC for x!=0. 7624113. llvm-svn: 102972
This commit is contained in:
parent
b8016872b6
commit
b10ca6bf4c
@ -4298,7 +4298,7 @@ SDValue PPCTargetLowering::LowerSCALAR_TO_VECTOR(SDValue Op,
|
|||||||
// Create a stack slot that is 16-byte aligned.
|
// Create a stack slot that is 16-byte aligned.
|
||||||
MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo();
|
MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo();
|
||||||
int FrameIdx = FrameInfo->CreateStackObject(16, 16, false);
|
int FrameIdx = FrameInfo->CreateStackObject(16, 16, false);
|
||||||
EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
EVT PtrVT = getPointerTy();
|
||||||
SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT);
|
SDValue FIdx = DAG.getFrameIndex(FrameIdx, PtrVT);
|
||||||
|
|
||||||
// Store the input value into Value#0 of the stack slot.
|
// Store the input value into Value#0 of the stack slot.
|
||||||
@ -5497,45 +5497,56 @@ bool PPCTargetLowering::isLegalAddressImmediate(llvm::GlobalValue* GV) const {
|
|||||||
SDValue PPCTargetLowering::LowerRETURNADDR(SDValue Op,
|
SDValue PPCTargetLowering::LowerRETURNADDR(SDValue Op,
|
||||||
SelectionDAG &DAG) const {
|
SelectionDAG &DAG) const {
|
||||||
DebugLoc dl = Op.getDebugLoc();
|
DebugLoc dl = Op.getDebugLoc();
|
||||||
// Depths > 0 not supported yet!
|
unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
|
||||||
if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() > 0)
|
|
||||||
return SDValue();
|
|
||||||
|
|
||||||
|
// Make sure the function does not optimize away the store of the RA to
|
||||||
|
// the stack.
|
||||||
MachineFunction &MF = DAG.getMachineFunction();
|
MachineFunction &MF = DAG.getMachineFunction();
|
||||||
PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
|
PPCFunctionInfo *FuncInfo = MF.getInfo<PPCFunctionInfo>();
|
||||||
|
FuncInfo->setLRStoreRequired();
|
||||||
|
bool isPPC64 = PPCSubTarget.isPPC64();
|
||||||
|
bool isDarwinABI = PPCSubTarget.isDarwinABI();
|
||||||
|
|
||||||
|
if (Depth > 0) {
|
||||||
|
SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
|
||||||
|
SDValue Offset =
|
||||||
|
|
||||||
|
DAG.getConstant(PPCFrameInfo::getReturnSaveOffset(isPPC64, isDarwinABI),
|
||||||
|
isPPC64? MVT::i64 : MVT::i32);
|
||||||
|
return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
|
||||||
|
DAG.getNode(ISD::ADD, dl, getPointerTy(),
|
||||||
|
FrameAddr, Offset),
|
||||||
|
NULL, 0, false, false, 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Just load the return address off the stack.
|
// Just load the return address off the stack.
|
||||||
SDValue RetAddrFI = getReturnAddrFrameIndex(DAG);
|
SDValue RetAddrFI = getReturnAddrFrameIndex(DAG);
|
||||||
|
return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
|
||||||
// Make sure the function really does not optimize away the store of the RA
|
RetAddrFI, NULL, 0, false, false, 0);
|
||||||
// to the stack.
|
|
||||||
FuncInfo->setLRStoreRequired();
|
|
||||||
return DAG.getLoad(getPointerTy(), dl,
|
|
||||||
DAG.getEntryNode(), RetAddrFI, NULL, 0,
|
|
||||||
false, false, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue PPCTargetLowering::LowerFRAMEADDR(SDValue Op,
|
SDValue PPCTargetLowering::LowerFRAMEADDR(SDValue Op,
|
||||||
SelectionDAG &DAG) const {
|
SelectionDAG &DAG) const {
|
||||||
DebugLoc dl = Op.getDebugLoc();
|
DebugLoc dl = Op.getDebugLoc();
|
||||||
// Depths > 0 not supported yet!
|
unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
|
||||||
if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() > 0)
|
|
||||||
return SDValue();
|
|
||||||
|
|
||||||
EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
||||||
bool isPPC64 = PtrVT == MVT::i64;
|
bool isPPC64 = PtrVT == MVT::i64;
|
||||||
|
|
||||||
MachineFunction &MF = DAG.getMachineFunction();
|
MachineFunction &MF = DAG.getMachineFunction();
|
||||||
MachineFrameInfo *MFI = MF.getFrameInfo();
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
||||||
bool is31 = (DisableFramePointerElim(MF) || MFI->hasVarSizedObjects())
|
MFI->setFrameAddressIsTaken(true);
|
||||||
&& MFI->getStackSize();
|
bool is31 = (DisableFramePointerElim(MF) || MFI->hasVarSizedObjects()) &&
|
||||||
|
MFI->getStackSize() &&
|
||||||
if (isPPC64)
|
!MF.getFunction()->hasFnAttr(Attribute::Naked);
|
||||||
return DAG.getCopyFromReg(DAG.getEntryNode(), dl, is31 ? PPC::X31 : PPC::X1,
|
unsigned FrameReg = isPPC64 ? (is31 ? PPC::X31 : PPC::X1) :
|
||||||
MVT::i64);
|
(is31 ? PPC::R31 : PPC::R1);
|
||||||
else
|
SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg,
|
||||||
return DAG.getCopyFromReg(DAG.getEntryNode(), dl, is31 ? PPC::R31 : PPC::R1,
|
PtrVT);
|
||||||
MVT::i32);
|
while (Depth--)
|
||||||
|
FrameAddr = DAG.getLoad(Op.getValueType(), dl, DAG.getEntryNode(),
|
||||||
|
FrameAddr, NULL, 0, false, false, 0);
|
||||||
|
return FrameAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
24
test/CodeGen/PowerPC/2010-05-03-retaddr1.ll
Normal file
24
test/CodeGen/PowerPC/2010-05-03-retaddr1.ll
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
; RUN: llc < %s -march=ppc32 -mtriple=powerpc-apple-darwin -mcpu=g5 | FileCheck %s
|
||||||
|
|
||||||
|
declare i8* @llvm.frameaddress(i32) nounwind readnone
|
||||||
|
|
||||||
|
define i8* @g2() nounwind readnone {
|
||||||
|
entry:
|
||||||
|
; CHECK: _g2:
|
||||||
|
; CHECK: lwz r3, 0(r1)
|
||||||
|
%0 = tail call i8* @llvm.frameaddress(i32 1) ; <i8*> [#uses=1]
|
||||||
|
ret i8* %0
|
||||||
|
}
|
||||||
|
|
||||||
|
declare i8* @llvm.returnaddress(i32) nounwind readnone
|
||||||
|
|
||||||
|
define i8* @g() nounwind readnone {
|
||||||
|
entry:
|
||||||
|
; CHECK: _g:
|
||||||
|
; CHECK: mflr r0
|
||||||
|
; CHECK: stw r0, 8(r1)
|
||||||
|
; CHECK: lwz r3, 0(r1)
|
||||||
|
; CHECK: lwz r3, 8(r3)
|
||||||
|
%0 = tail call i8* @llvm.returnaddress(i32 1) ; <i8*> [#uses=1]
|
||||||
|
ret i8* %0
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user