LLVM API Documentation
00001 //===-- XCoreISelLowering.h - XCore DAG Lowering Interface ------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the interfaces that XCore uses to lower LLVM code into a 00011 // selection DAG. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_LIB_TARGET_XCORE_XCOREISELLOWERING_H 00016 #define LLVM_LIB_TARGET_XCORE_XCOREISELLOWERING_H 00017 00018 #include "XCore.h" 00019 #include "llvm/CodeGen/SelectionDAG.h" 00020 #include "llvm/Target/TargetLowering.h" 00021 00022 namespace llvm { 00023 00024 // Forward delcarations 00025 class XCoreSubtarget; 00026 class XCoreTargetMachine; 00027 00028 namespace XCoreISD { 00029 enum NodeType { 00030 // Start the numbering where the builtin ops and target ops leave off. 00031 FIRST_NUMBER = ISD::BUILTIN_OP_END, 00032 00033 // Branch and link (call) 00034 BL, 00035 00036 // pc relative address 00037 PCRelativeWrapper, 00038 00039 // dp relative address 00040 DPRelativeWrapper, 00041 00042 // cp relative address 00043 CPRelativeWrapper, 00044 00045 // Load word from stack 00046 LDWSP, 00047 00048 // Store word to stack 00049 STWSP, 00050 00051 // Corresponds to retsp instruction 00052 RETSP, 00053 00054 // Corresponds to LADD instruction 00055 LADD, 00056 00057 // Corresponds to LSUB instruction 00058 LSUB, 00059 00060 // Corresponds to LMUL instruction 00061 LMUL, 00062 00063 // Corresponds to MACCU instruction 00064 MACCU, 00065 00066 // Corresponds to MACCS instruction 00067 MACCS, 00068 00069 // Corresponds to CRC8 instruction 00070 CRC8, 00071 00072 // Jumptable branch. 00073 BR_JT, 00074 00075 // Jumptable branch using long branches for each entry. 00076 BR_JT32, 00077 00078 // Offset from frame pointer to the first (possible) on-stack argument 00079 FRAME_TO_ARGS_OFFSET, 00080 00081 // Exception handler return. The stack is restored to the first 00082 // followed by a jump to the second argument. 00083 EH_RETURN, 00084 00085 // Memory barrier. 00086 MEMBARRIER 00087 }; 00088 } 00089 00090 //===--------------------------------------------------------------------===// 00091 // TargetLowering Implementation 00092 //===--------------------------------------------------------------------===// 00093 class XCoreTargetLowering : public TargetLowering 00094 { 00095 public: 00096 00097 explicit XCoreTargetLowering(const TargetMachine &TM); 00098 00099 using TargetLowering::isZExtFree; 00100 bool isZExtFree(SDValue Val, EVT VT2) const override; 00101 00102 00103 unsigned getJumpTableEncoding() const override; 00104 MVT getScalarShiftAmountTy(EVT LHSTy) const override { return MVT::i32; } 00105 00106 /// LowerOperation - Provide custom lowering hooks for some operations. 00107 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override; 00108 00109 /// ReplaceNodeResults - Replace the results of node with an illegal result 00110 /// type with new values built out of custom code. 00111 /// 00112 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 00113 SelectionDAG &DAG) const override; 00114 00115 /// getTargetNodeName - This method returns the name of a target specific 00116 // DAG node. 00117 const char *getTargetNodeName(unsigned Opcode) const override; 00118 00119 MachineBasicBlock * 00120 EmitInstrWithCustomInserter(MachineInstr *MI, 00121 MachineBasicBlock *MBB) const override; 00122 00123 bool isLegalAddressingMode(const AddrMode &AM, Type *Ty) const override; 00124 00125 private: 00126 const TargetMachine &TM; 00127 const XCoreSubtarget &Subtarget; 00128 00129 // Lower Operand helpers 00130 SDValue LowerCCCArguments(SDValue Chain, 00131 CallingConv::ID CallConv, 00132 bool isVarArg, 00133 const SmallVectorImpl<ISD::InputArg> &Ins, 00134 SDLoc dl, SelectionDAG &DAG, 00135 SmallVectorImpl<SDValue> &InVals) const; 00136 SDValue LowerCCCCallTo(SDValue Chain, SDValue Callee, 00137 CallingConv::ID CallConv, bool isVarArg, 00138 bool isTailCall, 00139 const SmallVectorImpl<ISD::OutputArg> &Outs, 00140 const SmallVectorImpl<SDValue> &OutVals, 00141 const SmallVectorImpl<ISD::InputArg> &Ins, 00142 SDLoc dl, SelectionDAG &DAG, 00143 SmallVectorImpl<SDValue> &InVals) const; 00144 SDValue getReturnAddressFrameIndex(SelectionDAG &DAG) const; 00145 SDValue getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV, 00146 SelectionDAG &DAG) const; 00147 SDValue lowerLoadWordFromAlignedBasePlusOffset(SDLoc DL, SDValue Chain, 00148 SDValue Base, int64_t Offset, 00149 SelectionDAG &DAG) const; 00150 00151 // Lower Operand specifics 00152 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const; 00153 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const; 00154 SDValue LowerEH_RETURN(SDValue Op, SelectionDAG &DAG) const; 00155 SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const; 00156 SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const; 00157 SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const; 00158 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const; 00159 SDValue LowerBR_JT(SDValue Op, SelectionDAG &DAG) const; 00160 SDValue LowerVAARG(SDValue Op, SelectionDAG &DAG) const; 00161 SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const; 00162 SDValue LowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const; 00163 SDValue LowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const; 00164 SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const; 00165 SDValue LowerFRAME_TO_ARGS_OFFSET(SDValue Op, SelectionDAG &DAG) const; 00166 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const; 00167 SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const; 00168 SDValue LowerADJUST_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const; 00169 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const; 00170 SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG) const; 00171 SDValue LowerATOMIC_LOAD(SDValue Op, SelectionDAG &DAG) const; 00172 SDValue LowerATOMIC_STORE(SDValue Op, SelectionDAG &DAG) const; 00173 00174 // Inline asm support 00175 std::pair<unsigned, const TargetRegisterClass*> 00176 getRegForInlineAsmConstraint(const std::string &Constraint, 00177 MVT VT) const override; 00178 00179 // Expand specifics 00180 SDValue TryExpandADDWithMul(SDNode *Op, SelectionDAG &DAG) const; 00181 SDValue ExpandADDSUB(SDNode *Op, SelectionDAG &DAG) const; 00182 00183 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override; 00184 00185 void computeKnownBitsForTargetNode(const SDValue Op, 00186 APInt &KnownZero, 00187 APInt &KnownOne, 00188 const SelectionDAG &DAG, 00189 unsigned Depth = 0) const override; 00190 00191 SDValue 00192 LowerFormalArguments(SDValue Chain, 00193 CallingConv::ID CallConv, 00194 bool isVarArg, 00195 const SmallVectorImpl<ISD::InputArg> &Ins, 00196 SDLoc dl, SelectionDAG &DAG, 00197 SmallVectorImpl<SDValue> &InVals) const override; 00198 00199 SDValue 00200 LowerCall(TargetLowering::CallLoweringInfo &CLI, 00201 SmallVectorImpl<SDValue> &InVals) const override; 00202 00203 SDValue 00204 LowerReturn(SDValue Chain, 00205 CallingConv::ID CallConv, bool isVarArg, 00206 const SmallVectorImpl<ISD::OutputArg> &Outs, 00207 const SmallVectorImpl<SDValue> &OutVals, 00208 SDLoc dl, SelectionDAG &DAG) const override; 00209 00210 bool 00211 CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, 00212 bool isVarArg, 00213 const SmallVectorImpl<ISD::OutputArg> &ArgsFlags, 00214 LLVMContext &Context) const override; 00215 }; 00216 } 00217 00218 #endif