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:
Anton Korobeynikov 2009-12-07 02:28:10 +00:00
parent e662f7a8b2
commit 06ccca5f70
3 changed files with 65 additions and 1 deletions

View File

@ -15,6 +15,7 @@
#include "MSP430ISelLowering.h" #include "MSP430ISelLowering.h"
#include "MSP430.h" #include "MSP430.h"
#include "MSP430MachineFunctionInfo.h"
#include "MSP430TargetMachine.h" #include "MSP430TargetMachine.h"
#include "MSP430Subtarget.h" #include "MSP430Subtarget.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
@ -62,6 +63,8 @@ MSP430TargetLowering::MSP430TargetLowering(MSP430TargetMachine &tm) :
TargetLowering(tm, new TargetLoweringObjectFileELF()), TargetLowering(tm, new TargetLoweringObjectFileELF()),
Subtarget(*tm.getSubtargetImpl()), TM(tm) { Subtarget(*tm.getSubtargetImpl()), TM(tm) {
TD = getTargetData();
// Set up the register classes. // Set up the register classes.
addRegisterClass(MVT::i8, MSP430::GR8RegisterClass); addRegisterClass(MVT::i8, MSP430::GR8RegisterClass);
addRegisterClass(MVT::i16, MSP430::GR16RegisterClass); 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::BR_CC: return LowerBR_CC(Op, DAG);
case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
case ISD::SIGN_EXTEND: return LowerSIGN_EXTEND(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: default:
llvm_unreachable("unimplemented operand"); llvm_unreachable("unimplemented operand");
return SDValue(); return SDValue();
@ -730,6 +735,55 @@ SDValue MSP430TargetLowering::LowerSIGN_EXTEND(SDValue Op,
DAG.getValueType(Val.getValueType())); 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 /// getPostIndexedAddressParts - returns true by value, base pointer and
/// offset pointer and addressing mode by reference if this node can be /// offset pointer and addressing mode by reference if this node can be
/// combined with a load / store to form a post-indexed load / store. /// combined with a load / store to form a post-indexed load / store.

View File

@ -86,6 +86,9 @@ namespace llvm {
SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG); SDValue LowerBR_CC(SDValue Op, SelectionDAG &DAG);
SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG); SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG);
SDValue LowerSIGN_EXTEND(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 TargetLowering::ConstraintType
getConstraintType(const std::string &Constraint) const; getConstraintType(const std::string &Constraint) const;
@ -147,6 +150,7 @@ namespace llvm {
const MSP430Subtarget &Subtarget; const MSP430Subtarget &Subtarget;
const MSP430TargetMachine &TM; const MSP430TargetMachine &TM;
const TargetData *TD;
}; };
} // namespace llvm } // namespace llvm

View File

@ -25,14 +25,20 @@ class MSP430MachineFunctionInfo : public MachineFunctionInfo {
/// stack frame in bytes. /// stack frame in bytes.
unsigned CalleeSavedFrameSize; unsigned CalleeSavedFrameSize;
/// ReturnAddrIndex - FrameIndex for return slot.
int ReturnAddrIndex;
public: public:
MSP430MachineFunctionInfo() : CalleeSavedFrameSize(0) {} MSP430MachineFunctionInfo() : CalleeSavedFrameSize(0) {}
explicit MSP430MachineFunctionInfo(MachineFunction &MF) explicit MSP430MachineFunctionInfo(MachineFunction &MF)
: CalleeSavedFrameSize(0) {} : CalleeSavedFrameSize(0), ReturnAddrIndex(0) {}
unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; } unsigned getCalleeSavedFrameSize() const { return CalleeSavedFrameSize; }
void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; } void setCalleeSavedFrameSize(unsigned bytes) { CalleeSavedFrameSize = bytes; }
int getRAIndex() const { return ReturnAddrIndex; }
void setRAIndex(int Index) { ReturnAddrIndex = Index; }
}; };
} // End llvm namespace } // End llvm namespace