LLVM API Documentation
00001 //===-- SPUISelLowering.h - Cell SPU 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 Cell SPU uses to lower LLVM code into 00011 // a selection DAG. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef SPU_ISELLOWERING_H 00016 #define SPU_ISELLOWERING_H 00017 00018 #include "llvm/Target/TargetLowering.h" 00019 #include "llvm/CodeGen/SelectionDAG.h" 00020 #include "SPU.h" 00021 00022 namespace llvm { 00023 namespace SPUISD { 00024 enum NodeType { 00025 // Start the numbering where the builting ops and target ops leave off. 00026 FIRST_NUMBER = ISD::BUILTIN_OP_END, 00027 00028 // Pseudo instructions: 00029 RET_FLAG, ///< Return with flag, matched by bi instruction 00030 00031 Hi, ///< High address component (upper 16) 00032 Lo, ///< Low address component (lower 16) 00033 PCRelAddr, ///< Program counter relative address 00034 AFormAddr, ///< A-form address (local store) 00035 IndirectAddr, ///< D-Form "imm($r)" and X-form "$r($r)" 00036 00037 LDRESULT, ///< Load result (value, chain) 00038 CALL, ///< CALL instruction 00039 SHUFB, ///< Vector shuffle (permute) 00040 SHUFFLE_MASK, ///< Shuffle mask 00041 CNTB, ///< Count leading ones in bytes 00042 PREFSLOT2VEC, ///< Promote scalar->vector 00043 VEC2PREFSLOT, ///< Extract element 0 00044 SHLQUAD_L_BITS, ///< Rotate quad left, by bits 00045 SHLQUAD_L_BYTES, ///< Rotate quad left, by bytes 00046 VEC_SHL, ///< Vector shift left 00047 VEC_SRL, ///< Vector shift right (logical) 00048 VEC_SRA, ///< Vector shift right (arithmetic) 00049 VEC_ROTL, ///< Vector rotate left 00050 VEC_ROTR, ///< Vector rotate right 00051 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI) 00052 ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count 00053 SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI) 00054 SELB, ///< Select bits -> (b & mask) | (a & ~mask) 00055 // Markers: These aren't used to generate target-dependent nodes, but 00056 // are used during instruction selection. 00057 ADD64_MARKER, ///< i64 addition marker 00058 SUB64_MARKER, ///< i64 subtraction marker 00059 MUL64_MARKER, ///< i64 multiply marker 00060 LAST_SPUISD ///< Last user-defined instruction 00061 }; 00062 } 00063 00064 //! Utility functions specific to CellSPU: 00065 namespace SPU { 00066 SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG, 00067 EVT ValueType); 00068 SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG, 00069 EVT ValueType); 00070 SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG, 00071 EVT ValueType); 00072 SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG, 00073 EVT ValueType); 00074 SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG, 00075 EVT ValueType); 00076 SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG); 00077 SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG); 00078 00079 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG, 00080 const SPUTargetMachine &TM); 00081 //! Simplify a EVT::v2i64 constant splat to CellSPU-ready form 00082 SDValue LowerV2I64Splat(EVT OpVT, SelectionDAG &DAG, uint64_t splat, 00083 DebugLoc dl); 00084 } 00085 00086 class SPUTargetMachine; // forward dec'l. 00087 00088 class SPUTargetLowering : 00089 public TargetLowering 00090 { 00091 int VarArgsFrameIndex; // FrameIndex for start of varargs area. 00092 SPUTargetMachine &SPUTM; 00093 00094 public: 00095 //! The venerable constructor 00096 /*! 00097 This is where the CellSPU backend sets operation handling (i.e., legal, 00098 custom, expand or promote.) 00099 */ 00100 SPUTargetLowering(SPUTargetMachine &TM); 00101 00102 //! Get the target machine 00103 SPUTargetMachine &getSPUTargetMachine() { 00104 return SPUTM; 00105 } 00106 00107 /// getTargetNodeName() - This method returns the name of a target specific 00108 /// DAG node. 00109 virtual const char *getTargetNodeName(unsigned Opcode) const; 00110 00111 /// getSetCCResultType - Return the ValueType for ISD::SETCC 00112 virtual MVT::SimpleValueType getSetCCResultType(EVT VT) const; 00113 00114 //! Custom lowering hooks 00115 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); 00116 00117 //! Custom lowering hook for nodes with illegal result types. 00118 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 00119 SelectionDAG &DAG); 00120 00121 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 00122 00123 virtual void computeMaskedBitsForTargetNode(const SDValue Op, 00124 const APInt &Mask, 00125 APInt &KnownZero, 00126 APInt &KnownOne, 00127 const SelectionDAG &DAG, 00128 unsigned Depth = 0) const; 00129 00130 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, 00131 unsigned Depth = 0) const; 00132 00133 ConstraintType getConstraintType(const std::string &ConstraintLetter) const; 00134 00135 std::pair<unsigned, const TargetRegisterClass*> 00136 getRegForInlineAsmConstraint(const std::string &Constraint, 00137 EVT VT) const; 00138 00139 void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter, 00140 bool hasMemory, 00141 std::vector<SDValue> &Ops, 00142 SelectionDAG &DAG) const; 00143 00144 /// isLegalAddressImmediate - Return true if the integer value can be used 00145 /// as the offset of the target addressing mode. 00146 virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const; 00147 virtual bool isLegalAddressImmediate(GlobalValue *) const; 00148 00149 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; 00150 00151 /// getFunctionAlignment - Return the Log2 alignment of this function. 00152 virtual unsigned getFunctionAlignment(const Function *F) const; 00153 00154 virtual SDValue 00155 LowerFormalArguments(SDValue Chain, 00156 unsigned CallConv, bool isVarArg, 00157 const SmallVectorImpl<ISD::InputArg> &Ins, 00158 DebugLoc dl, SelectionDAG &DAG, 00159 SmallVectorImpl<SDValue> &InVals); 00160 00161 virtual SDValue 00162 LowerCall(SDValue Chain, SDValue Callee, 00163 unsigned CallConv, bool isVarArg, 00164 bool isTailCall, 00165 const SmallVectorImpl<ISD::OutputArg> &Outs, 00166 const SmallVectorImpl<ISD::InputArg> &Ins, 00167 DebugLoc dl, SelectionDAG &DAG, 00168 SmallVectorImpl<SDValue> &InVals); 00169 00170 virtual SDValue 00171 LowerReturn(SDValue Chain, 00172 unsigned CallConv, bool isVarArg, 00173 const SmallVectorImpl<ISD::OutputArg> &Outs, 00174 DebugLoc dl, SelectionDAG &DAG); 00175 }; 00176 } 00177 00178 #endif