mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-22 10:29:35 +00:00
Add lowering of returnaddr and frameaddr intrinsics. Shamelessly stolen from x86 :)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90740 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
e662f7a8b2
commit
06ccca5f70
@ -15,6 +15,7 @@
|
||||
|
||||
#include "MSP430ISelLowering.h"
|
||||
#include "MSP430.h"
|
||||
#include "MSP430MachineFunctionInfo.h"
|
||||
#include "MSP430TargetMachine.h"
|
||||
#include "MSP430Subtarget.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
@ -62,6 +63,8 @@ MSP430TargetLowering::MSP430TargetLowering(MSP430TargetMachine &tm) :
|
||||
TargetLowering(tm, new TargetLoweringObjectFileELF()),
|
||||
Subtarget(*tm.getSubtargetImpl()), TM(tm) {
|
||||
|
||||
TD = getTargetData();
|
||||
|
||||
// Set up the register classes.
|
||||
addRegisterClass(MVT::i8, MSP430::GR8RegisterClass);
|
||||
addRegisterClass(MVT::i16, MSP430::GR16RegisterClass);
|
||||
@ -183,6 +186,8 @@ SDValue MSP430TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) {
|
||||
case ISD::BR_CC: return LowerBR_CC(Op, DAG);
|
||||
case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
|
||||
case ISD::SIGN_EXTEND: return LowerSIGN_EXTEND(Op, DAG);
|
||||
case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG);
|
||||
case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
|
||||
default:
|
||||
llvm_unreachable("unimplemented operand");
|
||||
return SDValue();
|
||||
@ -730,6 +735,55 @@ SDValue MSP430TargetLowering::LowerSIGN_EXTEND(SDValue Op,
|
||||
DAG.getValueType(Val.getValueType()));
|
||||
}
|
||||
|
||||
SDValue MSP430TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) {
|
||||
MachineFunction &MF = DAG.getMachineFunction();
|
||||
MSP430MachineFunctionInfo *FuncInfo = MF.getInfo<MSP430MachineFunctionInfo>();
|
||||
int ReturnAddrIndex = FuncInfo->getRAIndex();
|
||||
|
||||
if (ReturnAddrIndex == 0) {
|
||||
// Set up a frame object for the return address.
|
||||
uint64_t SlotSize = TD->getPointerSize();
|
||||
ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(SlotSize, -SlotSize,
|
||||
true, false);
|
||||
FuncInfo->setRAIndex(ReturnAddrIndex);
|
||||
}
|
||||
|
||||
return DAG.getFrameIndex(ReturnAddrIndex, getPointerTy());
|
||||
}
|
||||
|
||||
SDValue MSP430TargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) {
|
||||
unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
|
||||
DebugLoc dl = Op.getDebugLoc();
|
||||
|
||||
if (Depth > 0) {
|
||||
SDValue FrameAddr = LowerFRAMEADDR(Op, DAG);
|
||||
SDValue Offset =
|
||||
DAG.getConstant(TD->getPointerSize(), MVT::i16);
|
||||
return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
|
||||
DAG.getNode(ISD::ADD, dl, getPointerTy(),
|
||||
FrameAddr, Offset),
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
// Just load the return address.
|
||||
SDValue RetAddrFI = getReturnAddressFrameIndex(DAG);
|
||||
return DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(),
|
||||
RetAddrFI, NULL, 0);
|
||||
}
|
||||
|
||||
SDValue MSP430TargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) {
|
||||
MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo();
|
||||
MFI->setFrameAddressIsTaken(true);
|
||||
EVT VT = Op.getValueType();
|
||||
DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful
|
||||
unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
|
||||
SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl,
|
||||
MSP430::FPW, VT);
|
||||
while (Depth--)
|
||||
FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, NULL, 0);
|
||||
return FrameAddr;
|
||||
}
|
||||
|
||||
/// getPostIndexedAddressParts - returns true by value, base pointer and
|
||||
/// offset pointer and addressing mode by reference if this node can be
|
||||
/// combined with a load / store to form a post-indexed load / store.
|
||||
|
@ -86,6 +86,9 @@ namespace llvm {
|
||||
SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
|
||||
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
|
||||
SDValue LowerSIGN_EXTEND(SDValue Op, SelectionDAG &DAG);
|
||||
SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG);
|
||||
SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG);
|
||||
SDValue getReturnAddressFrameIndex(SelectionDAG &DAG);
|
||||
|
||||
TargetLowering::ConstraintType
|
||||
getConstraintType(const std::string &Constraint) const;
|
||||
@ -147,6 +150,7 @@ namespace llvm {
|
||||
|
||||
const MSP430Subtarget &Subtarget;
|
||||
const MSP430TargetMachine &TM;
|
||||
const TargetData *TD;
|
||||
};
|
||||
} // namespace llvm
|
||||
|
||||
|
@ -25,14 +25,20 @@ class MSP430MachineFunctionInfo : public MachineFunctionInfo {
|
||||
/// stack frame in bytes.
|
||||
unsigned CalleeSavedFrameSize;
|
||||
|
||||
/// ReturnAddrIndex - FrameIndex for return slot.
|
||||
int ReturnAddrIndex;
|
||||
|
||||
public:
|
||||
MSP430MachineFunctionInfo() : CalleeSavedFrameSize(0) {}
|
||||
|
||||
explicit MSP430MachineFunctionInfo(MachineFunction &MF)
|
||||
: CalleeSavedFrameSize(0) {}
|
||||
: CalleeSavedFrameSize(0), ReturnAddrIndex(0) {}
|
||||
|
||||
unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
|
||||
void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
|
||||
|
||||
int getRAIndex() const { return ReturnAddrIndex; }
|
||||
void setRAIndex(int Index) { ReturnAddrIndex = Index; }
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
|
Loading…
Reference in New Issue
Block a user