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_SHL, ///< Vector shift left |
| 47 | VEC_SRL, ///< Vector shift right (logical) |
| 48 | VEC_SRA, ///< Vector shift right (arithmetic) |
| 49 | VEC_ROTL, ///< Vector rotate left |
| 50 | VEC_ROTR, ///< Vector rotate right |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 51 | ROTBYTES_LEFT, ///< Rotate bytes (loads -> ROTQBYI) |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 52 | ROTBYTES_LEFT_BITS, ///< Rotate bytes left by bit shift count |
| 53 | SELECT_MASK, ///< Select Mask (FSM, FSMB, FSMH, FSMBI) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 54 | SELB, ///< Select bits -> (b & mask) | (a & ~mask) |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 55 | // Markers: These aren't used to generate target-dependent nodes, but |
| 56 | // are used during instruction selection. |
| 57 | ADD64_MARKER, ///< i64 addition marker |
| 58 | SUB64_MARKER, ///< i64 subtraction marker |
| 59 | MUL64_MARKER, ///< i64 multiply marker |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 60 | LAST_SPUISD ///< Last user-defined instruction |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 61 | }; |
| 62 | } |
| 63 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 64 | //! Utility functions specific to CellSPU: |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 65 | namespace SPU { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 66 | SDValue get_vec_u18imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 67 | MVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 68 | SDValue get_vec_i16imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 69 | MVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 70 | SDValue get_vec_i10imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 71 | MVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 72 | SDValue get_vec_i8imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 73 | MVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 74 | SDValue get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 75 | MVT ValueType); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 76 | SDValue get_v4i32_imm(SDNode *N, SelectionDAG &DAG); |
| 77 | SDValue get_v2i64_imm(SDNode *N, SelectionDAG &DAG); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 78 | |
| 79 | SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG, |
| 80 | const SPUTargetMachine &TM); |
Scott Michel | 7ea02ff | 2009-03-17 01:15:45 +0000 | [diff] [blame^] | 81 | //! Simplify a MVT::v2i64 constant splat to CellSPU-ready form |
| 82 | SDValue LowerV2I64Splat(MVT OpVT, SelectionDAG &DAG, uint64_t splat, |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 83 | DebugLoc dl); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | class SPUTargetMachine; // forward dec'l. |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 87 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 88 | class SPUTargetLowering : |
| 89 | public TargetLowering |
| 90 | { |
| 91 | int VarArgsFrameIndex; // FrameIndex for start of varargs area. |
| 92 | int ReturnAddrIndex; // FrameIndex for return slot. |
| 93 | SPUTargetMachine &SPUTM; |
| 94 | |
| 95 | public: |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 96 | //! The venerable constructor |
| 97 | /*! |
| 98 | This is where the CellSPU backend sets operation handling (i.e., legal, |
| 99 | custom, expand or promote.) |
| 100 | */ |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 101 | SPUTargetLowering(SPUTargetMachine &TM); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 102 | |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 103 | //! Get the target machine |
| 104 | SPUTargetMachine &getSPUTargetMachine() { |
| 105 | return SPUTM; |
| 106 | } |
| 107 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 108 | /// getTargetNodeName() - This method returns the name of a target specific |
| 109 | /// DAG node. |
| 110 | virtual const char *getTargetNodeName(unsigned Opcode) const; |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame] | 111 | |
| 112 | /// getSetCCResultType - Return the ValueType for ISD::SETCC |
Duncan Sands | 5480c04 | 2009-01-01 15:52:00 +0000 | [diff] [blame] | 113 | virtual MVT getSetCCResultType(MVT VT) const; |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 114 | |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 115 | //! Custom lowering hooks |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 116 | virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG); |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 117 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 118 | //! Custom lowering hook for nodes with illegal result types. |
| 119 | virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results, |
| 120 | SelectionDAG &DAG); |
| 121 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 122 | virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 123 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 124 | virtual void computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 125 | const APInt &Mask, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 126 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 127 | APInt &KnownOne, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 128 | const SelectionDAG &DAG, |
| 129 | unsigned Depth = 0) const; |
| 130 | |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 131 | virtual unsigned ComputeNumSignBitsForTargetNode(SDValue Op, |
| 132 | unsigned Depth = 0) const; |
| 133 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 134 | ConstraintType getConstraintType(const std::string &ConstraintLetter) const; |
| 135 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 136 | std::pair<unsigned, const TargetRegisterClass*> |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 137 | getRegForInlineAsmConstraint(const std::string &Constraint, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 138 | MVT VT) const; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 139 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 140 | void LowerAsmOperandForConstraint(SDValue Op, char ConstraintLetter, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 141 | bool hasMemory, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 142 | std::vector<SDValue> &Ops, |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 143 | SelectionDAG &DAG) const; |
| 144 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 145 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 146 | /// as the offset of the target addressing mode. |
| 147 | virtual bool isLegalAddressImmediate(int64_t V, const Type *Ty) const; |
| 148 | virtual bool isLegalAddressImmediate(GlobalValue *) const; |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 149 | |
| 150 | virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 151 | }; |
| 152 | } |
| 153 | |
| 154 | #endif |