Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1 | //===-- SPUISelLowering.h - Cell SPU DAG Lowering Interface -----*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 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 "llvm/Target/TargetLowering.h" |
| 19 | #include "llvm/CodeGen/SelectionDAG.h" |
| 20 | #include "SPU.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | namespace SPUISD { |
| 24 | enum NodeType { |
| 25 | // Start the numbering where the builting ops and target ops leave off. |
Dan Gohman | 0ba2bcf | 2008-09-23 18:42:32 +0000 | [diff] [blame] | 26 | FIRST_NUMBER = ISD::BUILTIN_OP_END, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 27 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 28 | // Pseudo instructions: |
| 29 | RET_FLAG, ///< Return with flag, matched by bi instruction |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 30 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 31 | Hi, ///< High address component (upper 16) |
| 32 | Lo, ///< Low address component (lower 16) |
| 33 | PCRelAddr, ///< Program counter relative address |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 34 | AFormAddr, ///< A-form address (local store) |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 35 | IndirectAddr, ///< D-Form "imm($r)" and X-form "$r($r)" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 36 | |
| 37 | LDRESULT, ///< Load result (value, chain) |
| 38 | CALL, ///< CALL instruction |
| 39 | SHUFB, ///< Vector shuffle (permute) |
Scott Michel | 7a1c9e9 | 2008-11-22 23:50:42 +0000 | [diff] [blame] | 40 | SHUFFLE_MASK, ///< Shuffle mask |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 41 | CNTB, ///< Count leading ones in bytes |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 42 | PREFSLOT2VEC, ///< Promote scalar->vector |
Scott Michel | 104de43 | 2008-11-24 17:11:17 +0000 | [diff] [blame] | 43 | VEC2PREFSLOT, ///< Extract element 0 |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 44 | SHLQUAD_L_BITS, ///< Rotate quad left, by bits |
| 45 | SHLQUAD_L_BYTES, ///< Rotate quad left, by bytes |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 46 | VEC_ROTL, ///< Vector rotate left |
| 47 | VEC_ROTR, ///< Vector rotate right |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 48 | ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI) |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 49 | ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count |
| 50 | SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 51 | SELB, ///< Select bits -> (b & mask) | (a & ~mask) |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 52 | // Markers: These aren't used to generate target-dependent nodes, but |
| 53 | // are used during instruction selection. |
| 54 | ADD64_MARKER, ///< i64 addition marker |
| 55 | SUB64_MARKER, ///< i64 subtraction marker |
| 56 | MUL64_MARKER, ///< i64 multiply marker |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 57 | LAST_SPUISD ///< Last user-defined instruction |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 58 | }; |
| 59 | } |
| 60 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 61 | //! Utility functions specific to CellSPU: |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 62 | namespace SPU { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 63 | SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 64 | EVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 65 | SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 66 | EVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 67 | SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 68 | EVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 69 | SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 70 | EVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 71 | SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 72 | EVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 73 | SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG); |
| 74 | SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 75 | |
| 76 | SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG, |
| 77 | const SPUTargetMachine &TM); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 78 | //! Simplify a EVT::v2i64 constant splat to CellSPU-ready form |
| 79 | SDValue LowerV2I64Splat(EVT OpVT, SelectionDAG &DAG, uint64_t splat, |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 80 | DebugLoc dl); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | class SPUTargetMachine; // forward dec'l. |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 84 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 85 | class SPUTargetLowering : |
| 86 | public TargetLowering |
| 87 | { |
| 88 | int VarArgsFrameIndex; // FrameIndex for start of varargs area. |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 89 | SPUTargetMachine &SPUTM; |
| 90 | |
| 91 | public: |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 92 | //! The venerable constructor |
| 93 | /*! |
| 94 | This is where the CellSPU backend sets operation handling (i.e., legal, |
| 95 | custom, expand or promote.) |
| 96 | */ |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 97 | SPUTargetLowering(SPUTargetMachine &TM); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 98 | |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 99 | //! Get the target machine |
| 100 | SPUTargetMachine &getSPUTargetMachine() { |
| 101 | return SPUTM; |
| 102 | } |
| 103 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 104 | /// getTargetNodeName() - This method returns the name of a target specific |
| 105 | /// DAG node. |
| 106 | virtual const char *getTargetNodeName(unsigned Opcode) const; |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 107 | |
| 108 | /// getSetCCResultType - Return the ValueType for ISD::SETCC |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 109 | virtual MVT::SimpleValueType getSetCCResultType(EVT VT) const; |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 110 | |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 111 | //! Custom lowering hooks |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 112 | virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const; |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 113 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 114 | //! Custom lowering hook for nodes with illegal result types. |
| 115 | virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 116 | SelectionDAG &DAG) const; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 117 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 118 | virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 119 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 120 | virtual void computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 121 | const APInt &Mask, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 122 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 123 | APInt &KnownOne, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 124 | const SelectionDAG &DAG, |
| 125 | unsigned Depth = 0) const; |
| 126 | |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 127 | virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, |
| 128 | unsigned Depth = 0) const; |
| 129 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 130 | ConstraintType getConstraintType(const std::string &ConstraintLetter) const; |
| 131 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 132 | std::pair<unsigned, const TargetRegisterClass*> |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 133 | getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 134 | EVT VT) const; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 135 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 136 | void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 137 | bool hasMemory, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 138 | std::vector<SDValue> &Ops, |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 139 | SelectionDAG &DAG) const; |
| 140 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 141 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 142 | /// as the offset of the target addressing mode. |
| 143 | virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const; |
| 144 | virtual bool isLegalAddressImmediate(GlobalValue *) const; |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 145 | |
| 146 | virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 147 | |
Bill Wendling | b4202b8 | 2009-07-01 18:50:55 +0000 | [diff] [blame] | 148 | /// getFunctionAlignment - Return the Log2 alignment of this function. |
Bill Wendling | 20c568f | 2009-06-30 22:38:32 +0000 | [diff] [blame] | 149 | virtual unsigned getFunctionAlignment(const Function *F) const; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 150 | |
| 151 | virtual SDValue |
| 152 | LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 153 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 154 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 155 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 156 | SmallVectorImpl<SDValue> &InVals) const; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 157 | |
| 158 | virtual SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 159 | LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 160 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 161 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 162 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 163 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 164 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 165 | SmallVectorImpl<SDValue> &InVals) const; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 166 | |
| 167 | virtual SDValue |
| 168 | LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 169 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 170 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 171 | DebugLoc dl, SelectionDAG &DAG) const; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 172 | }; |
| 173 | } |
| 174 | |
| 175 | #endif |