1 //===-- SPUISelLowering.h - Cell SPU DAG Lowering Interface -----*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the interfaces that Cell SPU uses to lower LLVM code into 11 // a selection DAG. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef SPU_ISELLOWERING_H 16 #define SPU_ISELLOWERING_H 17 18 #include "SPU.h" 19 #include "llvm/Target/TargetLowering.h" 20 #include "llvm/CodeGen/SelectionDAG.h" 21 22 namespace llvm { 23 namespace SPUISD { 24 enum NodeType { 25 // Start the numbering where the builting ops and target ops leave off. 26 FIRST_NUMBER = ISD::BUILTIN_OP_END, 27 28 // Pseudo instructions: 29 RET_FLAG, ///< Return with flag, matched by bi instruction 30 31 Hi, ///< High address component (upper 16) 32 Lo, ///< Low address component (lower 16) 33 PCRelAddr, ///< Program counter relative address 34 AFormAddr, ///< A-form address (local store) 35 IndirectAddr, ///< D-Form "imm($r)" and X-form "$r($r)" 36 37 LDRESULT, ///< Load result (value, chain) 38 CALL, ///< CALL instruction 39 SHUFB, ///< Vector shuffle (permute) 40 SHUFFLE_MASK, ///< Shuffle mask 41 CNTB, ///< Count leading ones in bytes 42 PREFSLOT2VEC, ///< Promote scalar->vector 43 VEC2PREFSLOT, ///< Extract element 0 44 SHL_BITS, ///< Shift quad left, by bits 45 SHL_BYTES, ///< Shift quad left, by bytes 46 SRL_BYTES, ///< Shift quad right, by bytes. Insert zeros. 47 VEC_ROTL, ///< Vector rotate left 48 VEC_ROTR, ///< Vector rotate right 49 ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI) 50 ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count 51 SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI) 52 SELB, ///< Select bits -> (b & mask) | (a & ~mask) 53 // Markers: These aren't used to generate target-dependent nodes, but 54 // are used during instruction selection. 55 ADD64_MARKER, ///< i64 addition marker 56 SUB64_MARKER, ///< i64 subtraction marker 57 MUL64_MARKER, ///< i64 multiply marker 58 LAST_SPUISD ///< Last user-defined instruction 59 }; 60 } 61 62 //! Utility functions specific to CellSPU: 63 namespace SPU { 64 SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG, 65 EVT ValueType); 66 SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG, 67 EVT ValueType); 68 SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG, 69 EVT ValueType); 70 SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG, 71 EVT ValueType); 72 SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG, 73 EVT ValueType); 74 SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG); 75 SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG); 76 77 SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG, 78 const SPUTargetMachine &TM); 79 //! Simplify a EVT::v2i64 constant splat to CellSPU-ready form 80 SDValue LowerV2I64Splat(EVT OpVT, SelectionDAG &DAG, uint64_t splat, 81 DebugLoc dl); 82 } 83 84 class SPUTargetMachine; // forward dec'l. 85 86 class SPUTargetLowering : 87 public TargetLowering 88 { 89 int VarArgsFrameIndex; // FrameIndex for start of varargs area. 90 SPUTargetMachine &SPUTM; 91 92 public: 93 //! The venerable constructor 94 /*! 95 This is where the CellSPU backend sets operation handling (i.e., legal, 96 custom, expand or promote.) 97 */ 98 SPUTargetLowering(SPUTargetMachine &TM); 99 100 //! Get the target machine 101 SPUTargetMachine &getSPUTargetMachine() { 102 return SPUTM; 103 } 104 105 /// getTargetNodeName() - This method returns the name of a target specific 106 /// DAG node. 107 virtual const char *getTargetNodeName(unsigned Opcode) const; 108 109 /// getSetCCResultType - Return the ValueType for ISD::SETCC 110 virtual EVT getSetCCResultType(EVT VT) const; 111 112 virtual MVT getShiftAmountTy(EVT LHSTy) const { return MVT::i32; } 113 114 //! Custom lowering hooks 115 virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const; 116 117 //! Custom lowering hook for nodes with illegal result types. 118 virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, 119 SelectionDAG &DAG) const; 120 121 virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; 122 123 virtual void computeMaskedBitsForTargetNode(const SDValue Op, 124 APInt &KnownZero, 125 APInt &KnownOne, 126 const SelectionDAG &DAG, 127 unsigned Depth = 0) const; 128 129 virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, 130 unsigned Depth = 0) const; 131 132 ConstraintType getConstraintType(const std::string &ConstraintLetter) const; 133 134 /// Examine constraint string and operand type and determine a weight value. 135 /// The operand object must already have been set up with the operand type. 136 ConstraintWeight getSingleConstraintMatchWeight( 137 AsmOperandInfo &info, const char *constraint) const; 138 139 std::pair<unsigned, const TargetRegisterClass*> 140 getRegForInlineAsmConstraint(const std::string &Constraint, 141 EVT VT) const; 142 143 void LowerAsmOperandForConstraint(SDValue Op, std::string &Constraint, 144 std::vector<SDValue> &Ops, 145 SelectionDAG &DAG) const; 146 147 /// isLegalAddressImmediate - Return true if the integer value can be used 148 /// as the offset of the target addressing mode. 149 virtual bool isLegalAddressImmediate(int64_t V, Type *Ty) const; 150 virtual bool isLegalAddressImmediate(GlobalValue *) const; 151 152 virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; 153 154 virtual SDValue 155 LowerFormalArguments(SDValue Chain, 156 CallingConv::ID CallConv, bool isVarArg, 157 const SmallVectorImpl<ISD::InputArg> &Ins, 158 DebugLoc dl, SelectionDAG &DAG, 159 SmallVectorImpl<SDValue> &InVals) const; 160 161 virtual SDValue 162 LowerCall(SDValue Chain, SDValue Callee, 163 CallingConv::ID CallConv, bool isVarArg, 164 bool doesNotRet, bool &isTailCall, 165 const SmallVectorImpl<ISD::OutputArg> &Outs, 166 const SmallVectorImpl<SDValue> &OutVals, 167 const SmallVectorImpl<ISD::InputArg> &Ins, 168 DebugLoc dl, SelectionDAG &DAG, 169 SmallVectorImpl<SDValue> &InVals) const; 170 171 virtual SDValue 172 LowerReturn(SDValue Chain, 173 CallingConv::ID CallConv, bool isVarArg, 174 const SmallVectorImpl<ISD::OutputArg> &Outs, 175 const SmallVectorImpl<SDValue> &OutVals, 176 DebugLoc dl, SelectionDAG &DAG) const; 177 178 virtual bool isLegalICmpImmediate(int64_t Imm) const; 179 180 virtual bool isLegalAddressingMode(const AddrMode &AM, 181 Type *Ty) const; 182 }; 183 } 184 185 #endif 186