Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 1 | //===-- SPUISelDAGToDAG.cpp - CellSPU pattern matching inst selector ------===// |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 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 a pattern matching instruction selector for the Cell SPU, |
| 11 | // converting from a legalized dag to a SPU-target dag. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "SPU.h" |
| 16 | #include "SPUTargetMachine.h" |
| 17 | #include "SPUISelLowering.h" |
| 18 | #include "SPUHazardRecognizers.h" |
| 19 | #include "SPUFrameInfo.h" |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 20 | #include "SPURegisterNames.h" |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 21 | #include "SPUTargetMachine.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/MachineConstantPool.h" |
| 23 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 24 | #include "llvm/CodeGen/MachineFunction.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/SelectionDAG.h" |
| 26 | #include "llvm/CodeGen/SelectionDAGISel.h" |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetOptions.h" |
| 29 | #include "llvm/ADT/Statistic.h" |
| 30 | #include "llvm/Constants.h" |
| 31 | #include "llvm/GlobalValue.h" |
| 32 | #include "llvm/Intrinsics.h" |
| 33 | #include "llvm/Support/Debug.h" |
| 34 | #include "llvm/Support/MathExtras.h" |
| 35 | #include "llvm/Support/Compiler.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 36 | |
| 37 | using namespace llvm; |
| 38 | |
| 39 | namespace { |
| 40 | //! ConstantSDNode predicate for i32 sign-extended, 10-bit immediates |
| 41 | bool |
| 42 | isI64IntS10Immediate(ConstantSDNode *CN) |
| 43 | { |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 44 | return isS10Constant(CN->getSExtValue()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | //! ConstantSDNode predicate for i32 sign-extended, 10-bit immediates |
| 48 | bool |
| 49 | isI32IntS10Immediate(ConstantSDNode *CN) |
| 50 | { |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 51 | return isS10Constant(CN->getSExtValue()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Scott Michel | 504c369 | 2007-12-17 22:32:34 +0000 | [diff] [blame] | 54 | //! ConstantSDNode predicate for i32 unsigned 10-bit immediate values |
| 55 | bool |
| 56 | isI32IntU10Immediate(ConstantSDNode *CN) |
| 57 | { |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 58 | return isU10Constant(CN->getSExtValue()); |
Scott Michel | 504c369 | 2007-12-17 22:32:34 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 61 | //! ConstantSDNode predicate for i16 sign-extended, 10-bit immediate values |
| 62 | bool |
| 63 | isI16IntS10Immediate(ConstantSDNode *CN) |
| 64 | { |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 65 | return isS10Constant(CN->getSExtValue()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | //! SDNode predicate for i16 sign-extended, 10-bit immediate values |
| 69 | bool |
| 70 | isI16IntS10Immediate(SDNode *N) |
| 71 | { |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 72 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N); |
| 73 | return (CN != 0 && isI16IntS10Immediate(CN)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Scott Michel | ec2a08f | 2007-12-15 00:38:50 +0000 | [diff] [blame] | 76 | //! ConstantSDNode predicate for i16 unsigned 10-bit immediate values |
| 77 | bool |
| 78 | isI16IntU10Immediate(ConstantSDNode *CN) |
| 79 | { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 80 | return isU10Constant((short) CN->getZExtValue()); |
Scott Michel | ec2a08f | 2007-12-15 00:38:50 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | //! SDNode predicate for i16 sign-extended, 10-bit immediate values |
| 84 | bool |
| 85 | isI16IntU10Immediate(SDNode *N) |
| 86 | { |
| 87 | return (N->getOpcode() == ISD::Constant |
| 88 | && isI16IntU10Immediate(cast<ConstantSDNode>(N))); |
| 89 | } |
| 90 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 91 | //! ConstantSDNode predicate for signed 16-bit values |
| 92 | /*! |
| 93 | \arg CN The constant SelectionDAG node holding the value |
| 94 | \arg Imm The returned 16-bit value, if returning true |
| 95 | |
| 96 | This predicate tests the value in \a CN to see whether it can be |
| 97 | represented as a 16-bit, sign-extended quantity. Returns true if |
| 98 | this is the case. |
| 99 | */ |
| 100 | bool |
| 101 | isIntS16Immediate(ConstantSDNode *CN, short &Imm) |
| 102 | { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 103 | MVT vt = CN->getValueType(0); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 104 | Imm = (short) CN->getZExtValue(); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 105 | if (vt.getSimpleVT() >= MVT::i1 && vt.getSimpleVT() <= MVT::i16) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 106 | return true; |
| 107 | } else if (vt == MVT::i32) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 108 | int32_t i_val = (int32_t) CN->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 109 | short s_val = (short) i_val; |
| 110 | return i_val == s_val; |
| 111 | } else { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 112 | int64_t i_val = (int64_t) CN->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 113 | short s_val = (short) i_val; |
| 114 | return i_val == s_val; |
| 115 | } |
| 116 | |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | //! SDNode predicate for signed 16-bit values. |
| 121 | bool |
| 122 | isIntS16Immediate(SDNode *N, short &Imm) |
| 123 | { |
| 124 | return (N->getOpcode() == ISD::Constant |
| 125 | && isIntS16Immediate(cast<ConstantSDNode>(N), Imm)); |
| 126 | } |
| 127 | |
| 128 | //! ConstantFPSDNode predicate for representing floats as 16-bit sign ext. |
| 129 | static bool |
| 130 | isFPS16Immediate(ConstantFPSDNode *FPN, short &Imm) |
| 131 | { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 132 | MVT vt = FPN->getValueType(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 133 | if (vt == MVT::f32) { |
Chris Lattner | d3ada75 | 2007-12-22 22:45:38 +0000 | [diff] [blame] | 134 | int val = FloatToBits(FPN->getValueAPF().convertToFloat()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 135 | int sval = (int) ((val << 16) >> 16); |
| 136 | Imm = (short) val; |
| 137 | return val == sval; |
| 138 | } |
| 139 | |
| 140 | return false; |
| 141 | } |
| 142 | |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 143 | bool |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 144 | isHighLow(const SDValue &Op) |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 145 | { |
| 146 | return (Op.getOpcode() == SPUISD::IndirectAddr |
| 147 | && ((Op.getOperand(0).getOpcode() == SPUISD::Hi |
| 148 | && Op.getOperand(1).getOpcode() == SPUISD::Lo) |
| 149 | || (Op.getOperand(0).getOpcode() == SPUISD::Lo |
| 150 | && Op.getOperand(1).getOpcode() == SPUISD::Hi))); |
| 151 | } |
| 152 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 153 | //===------------------------------------------------------------------===// |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 154 | //! MVT to "useful stuff" mapping structure: |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 155 | |
| 156 | struct valtype_map_s { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 157 | MVT VT; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 158 | unsigned ldresult_ins; /// LDRESULT instruction (0 = undefined) |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 159 | bool ldresult_imm; /// LDRESULT instruction requires immediate? |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 160 | unsigned lrinst; /// LR instruction |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | const valtype_map_s valtype_map[] = { |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 164 | { MVT::i8, SPU::ORBIr8, true, SPU::LRr8 }, |
| 165 | { MVT::i16, SPU::ORHIr16, true, SPU::LRr16 }, |
| 166 | { MVT::i32, SPU::ORIr32, true, SPU::LRr32 }, |
| 167 | { MVT::i64, SPU::ORr64, false, SPU::LRr64 }, |
| 168 | { MVT::f32, SPU::ORf32, false, SPU::LRf32 }, |
| 169 | { MVT::f64, SPU::ORf64, false, SPU::LRf64 }, |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 170 | // vector types... (sigh!) |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 171 | { MVT::v16i8, 0, false, SPU::LRv16i8 }, |
| 172 | { MVT::v8i16, 0, false, SPU::LRv8i16 }, |
| 173 | { MVT::v4i32, 0, false, SPU::LRv4i32 }, |
| 174 | { MVT::v2i64, 0, false, SPU::LRv2i64 }, |
| 175 | { MVT::v4f32, 0, false, SPU::LRv4f32 }, |
| 176 | { MVT::v2f64, 0, false, SPU::LRv2f64 } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | const size_t n_valtype_map = sizeof(valtype_map) / sizeof(valtype_map[0]); |
| 180 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 181 | const valtype_map_s *getValueTypeMapEntry(MVT VT) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 182 | { |
| 183 | const valtype_map_s *retval = 0; |
| 184 | for (size_t i = 0; i < n_valtype_map; ++i) { |
| 185 | if (valtype_map[i].VT == VT) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 186 | retval = valtype_map + i; |
| 187 | break; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
| 191 | |
| 192 | #ifndef NDEBUG |
| 193 | if (retval == 0) { |
| 194 | cerr << "SPUISelDAGToDAG.cpp: getValueTypeMapEntry returns NULL for " |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 195 | << VT.getMVTString() |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 196 | << "\n"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 197 | abort(); |
| 198 | } |
| 199 | #endif |
| 200 | |
| 201 | return retval; |
| 202 | } |
| 203 | } |
| 204 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 205 | namespace { |
| 206 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 207 | //===--------------------------------------------------------------------===// |
| 208 | /// SPUDAGToDAGISel - Cell SPU-specific code to select SPU machine |
| 209 | /// instructions for SelectionDAG operations. |
| 210 | /// |
| 211 | class SPUDAGToDAGISel : |
| 212 | public SelectionDAGISel |
| 213 | { |
| 214 | SPUTargetMachine &TM; |
| 215 | SPUTargetLowering &SPUtli; |
| 216 | unsigned GlobalBaseReg; |
| 217 | |
| 218 | public: |
Dan Gohman | 1002c02 | 2008-07-07 18:00:37 +0000 | [diff] [blame] | 219 | explicit SPUDAGToDAGISel(SPUTargetMachine &tm) : |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 220 | SelectionDAGISel(tm), |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 221 | TM(tm), |
| 222 | SPUtli(*tm.getTargetLowering()) |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 223 | { } |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 224 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 225 | virtual bool runOnFunction(Function &Fn) { |
| 226 | // Make sure we re-emit a set of the global base reg if necessary |
| 227 | GlobalBaseReg = 0; |
| 228 | SelectionDAGISel::runOnFunction(Fn); |
| 229 | return true; |
| 230 | } |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 231 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 232 | /// getI32Imm - Return a target constant with the specified value, of type |
| 233 | /// i32. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 234 | inline SDValue getI32Imm(uint32_t Imm) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 235 | return CurDAG->getTargetConstant(Imm, MVT::i32); |
| 236 | } |
| 237 | |
| 238 | /// getI64Imm - Return a target constant with the specified value, of type |
| 239 | /// i64. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 240 | inline SDValue getI64Imm(uint64_t Imm) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 241 | return CurDAG->getTargetConstant(Imm, MVT::i64); |
| 242 | } |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 243 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 244 | /// getSmallIPtrImm - Return a target constant of pointer type. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 245 | inline SDValue getSmallIPtrImm(unsigned Imm) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 246 | return CurDAG->getTargetConstant(Imm, SPUtli.getPointerTy()); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 247 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 248 | |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 249 | SDNode *emitBuildVector(SDValue build_vec) { |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 250 | MVT vecVT = build_vec.getValueType(); |
| 251 | SDNode *bvNode = build_vec.getNode(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 252 | DebugLoc dl = bvNode->getDebugLoc(); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 253 | |
| 254 | // Check to see if this vector can be represented as a CellSPU immediate |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 255 | // constant by invoking all of the instruction selection predicates: |
| 256 | if (((vecVT == MVT::v8i16) && |
| 257 | (SPU::get_vec_i16imm(bvNode, *CurDAG, MVT::i16).getNode() != 0)) || |
| 258 | ((vecVT == MVT::v4i32) && |
| 259 | ((SPU::get_vec_i16imm(bvNode, *CurDAG, MVT::i32).getNode() != 0) || |
| 260 | (SPU::get_ILHUvec_imm(bvNode, *CurDAG, MVT::i32).getNode() != 0) || |
| 261 | (SPU::get_vec_u18imm(bvNode, *CurDAG, MVT::i32).getNode() != 0) || |
| 262 | (SPU::get_v4i32_imm(bvNode, *CurDAG).getNode() != 0))) || |
| 263 | ((vecVT == MVT::v2i64) && |
| 264 | ((SPU::get_vec_i16imm(bvNode, *CurDAG, MVT::i64).getNode() != 0) || |
| 265 | (SPU::get_ILHUvec_imm(bvNode, *CurDAG, MVT::i64).getNode() != 0) || |
| 266 | (SPU::get_vec_u18imm(bvNode, *CurDAG, MVT::i64).getNode() != 0)))) |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 267 | return Select(build_vec); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 268 | |
| 269 | // No, need to emit a constant pool spill: |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 270 | std::vector<Constant*> CV; |
| 271 | |
| 272 | for (size_t i = 0; i < build_vec.getNumOperands(); ++i) { |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 273 | ConstantSDNode *V = dyn_cast<ConstantSDNode > (build_vec.getOperand(i)); |
| 274 | CV.push_back(const_cast<ConstantInt *> (V->getConstantIntValue())); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | Constant *CP = ConstantVector::get(CV); |
| 278 | SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy()); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 279 | unsigned Alignment = 1 << cast<ConstantPoolSDNode > (CPIdx)->getAlignment(); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 280 | SDValue CGPoolOffset = |
| 281 | SPU::LowerConstantPool(CPIdx, *CurDAG, |
| 282 | SPUtli.getSPUTargetMachine()); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 283 | return SelectCode(CurDAG->getLoad(build_vec.getValueType(), dl, |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 284 | CurDAG->getEntryNode(), CGPoolOffset, |
| 285 | PseudoSourceValue::getConstantPool(), 0, |
| 286 | false, Alignment)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 289 | /// Select - Convert the specified operand from a target-independent to a |
| 290 | /// target-specific node if it hasn't already been changed. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 291 | SDNode *Select(SDValue Op); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 292 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 293 | //! Emit the instruction sequence for i64 shl |
| 294 | SDNode *SelectSHLi64(SDValue &Op, MVT OpVT); |
| 295 | |
| 296 | //! Emit the instruction sequence for i64 srl |
| 297 | SDNode *SelectSRLi64(SDValue &Op, MVT OpVT); |
| 298 | |
| 299 | //! Emit the instruction sequence for i64 sra |
| 300 | SDNode *SelectSRAi64(SDValue &Op, MVT OpVT); |
| 301 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 302 | //! Emit the necessary sequence for loading i64 constants: |
| 303 | SDNode *SelectI64Constant(SDValue &Op, MVT OpVT); |
| 304 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 305 | //! Returns true if the address N is an A-form (local store) address |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 306 | bool SelectAFormAddr(SDValue Op, SDValue N, SDValue &Base, |
| 307 | SDValue &Index); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 308 | |
| 309 | //! D-form address predicate |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 310 | bool SelectDFormAddr(SDValue Op, SDValue N, SDValue &Base, |
| 311 | SDValue &Index); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 312 | |
| 313 | /// Alternate D-form address using i7 offset predicate |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 314 | bool SelectDForm2Addr(SDValue Op, SDValue N, SDValue &Disp, |
| 315 | SDValue &Base); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 316 | |
| 317 | /// D-form address selection workhorse |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 318 | bool DFormAddressPredicate(SDValue Op, SDValue N, SDValue &Disp, |
| 319 | SDValue &Base, int minOffset, int maxOffset); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 320 | |
| 321 | //! Address predicate if N can be expressed as an indexed [r+r] operation. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 322 | bool SelectXFormAddr(SDValue Op, SDValue N, SDValue &Base, |
| 323 | SDValue &Index); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 324 | |
| 325 | /// SelectInlineAsmMemoryOperand - Implement addressing mode selection for |
| 326 | /// inline asm expressions. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 327 | virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 328 | char ConstraintCode, |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 329 | std::vector<SDValue> &OutOps) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 330 | SDValue Op0, Op1; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 331 | switch (ConstraintCode) { |
| 332 | default: return true; |
| 333 | case 'm': // memory |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 334 | if (!SelectDFormAddr(Op, Op, Op0, Op1) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 335 | && !SelectAFormAddr(Op, Op, Op0, Op1)) |
| 336 | SelectXFormAddr(Op, Op, Op0, Op1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 337 | break; |
| 338 | case 'o': // offsetable |
| 339 | if (!SelectDFormAddr(Op, Op, Op0, Op1) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 340 | && !SelectAFormAddr(Op, Op, Op0, Op1)) { |
| 341 | Op0 = Op; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 342 | Op1 = getSmallIPtrImm(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 343 | } |
| 344 | break; |
| 345 | case 'v': // not offsetable |
| 346 | #if 1 |
| 347 | assert(0 && "InlineAsmMemoryOperand 'v' constraint not handled."); |
| 348 | #else |
| 349 | SelectAddrIdxOnly(Op, Op, Op0, Op1); |
| 350 | #endif |
| 351 | break; |
| 352 | } |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 353 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 354 | OutOps.push_back(Op0); |
| 355 | OutOps.push_back(Op1); |
| 356 | return false; |
| 357 | } |
| 358 | |
Evan Cheng | db8d56b | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 359 | /// InstructionSelect - This callback is invoked by |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 360 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 361 | virtual void InstructionSelect(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 362 | |
| 363 | virtual const char *getPassName() const { |
| 364 | return "Cell SPU DAG->DAG Pattern Instruction Selection"; |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 367 | /// CreateTargetHazardRecognizer - Return the hazard recognizer to use for |
| 368 | /// this target when scheduling the DAG. |
Dan Gohman | fc54c55 | 2009-01-15 22:18:12 +0000 | [diff] [blame] | 369 | virtual ScheduleHazardRecognizer *CreateTargetHazardRecognizer() { |
Dan Gohman | 6448d91 | 2008-09-04 15:39:15 +0000 | [diff] [blame] | 370 | const TargetInstrInfo *II = TM.getInstrInfo(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 371 | assert(II && "No InstrInfo?"); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 372 | return new SPUHazardRecognizer(*II); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | // Include the pieces autogenerated from the target description. |
| 376 | #include "SPUGenDAGISel.inc" |
| 377 | }; |
| 378 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Evan Cheng | db8d56b | 2008-06-30 20:45:06 +0000 | [diff] [blame] | 381 | /// InstructionSelect - This callback is invoked by |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 382 | /// SelectionDAGISel when it has created a SelectionDAG for us to codegen. |
| 383 | void |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 384 | SPUDAGToDAGISel::InstructionSelect() |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 385 | { |
| 386 | DEBUG(BB->dump()); |
| 387 | |
| 388 | // Select target instructions for the DAG. |
David Greene | 8ad4c00 | 2008-10-27 21:56:29 +0000 | [diff] [blame] | 389 | SelectRoot(*CurDAG); |
Dan Gohman | f350b27 | 2008-08-23 02:25:05 +0000 | [diff] [blame] | 390 | CurDAG->RemoveDeadNodes(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 393 | /*! |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 394 | \arg Op The ISD instruction operand |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 395 | \arg N The address to be tested |
| 396 | \arg Base The base address |
| 397 | \arg Index The base address index |
| 398 | */ |
| 399 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 400 | SPUDAGToDAGISel::SelectAFormAddr(SDValue Op, SDValue N, SDValue &Base, |
| 401 | SDValue &Index) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 402 | // These match the addr256k operand type: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 403 | MVT OffsVT = MVT::i16; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 404 | SDValue Zero = CurDAG->getTargetConstant(0, OffsVT); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 405 | |
| 406 | switch (N.getOpcode()) { |
| 407 | case ISD::Constant: |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 408 | case ISD::ConstantPool: |
| 409 | case ISD::GlobalAddress: |
| 410 | cerr << "SPU SelectAFormAddr: Constant/Pool/Global not lowered.\n"; |
| 411 | abort(); |
| 412 | /*NOTREACHED*/ |
| 413 | |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 414 | case ISD::TargetConstant: |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 415 | case ISD::TargetGlobalAddress: |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 416 | case ISD::TargetJumpTable: |
| 417 | cerr << "SPUSelectAFormAddr: Target Constant/Pool/Global not wrapped as " |
| 418 | << "A-form address.\n"; |
| 419 | abort(); |
| 420 | /*NOTREACHED*/ |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 421 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 422 | case SPUISD::AFormAddr: |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 423 | // Just load from memory if there's only a single use of the location, |
| 424 | // otherwise, this will get handled below with D-form offset addresses |
| 425 | if (N.hasOneUse()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 426 | SDValue Op0 = N.getOperand(0); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 427 | switch (Op0.getOpcode()) { |
| 428 | case ISD::TargetConstantPool: |
| 429 | case ISD::TargetJumpTable: |
| 430 | Base = Op0; |
| 431 | Index = Zero; |
| 432 | return true; |
| 433 | |
| 434 | case ISD::TargetGlobalAddress: { |
| 435 | GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op0); |
| 436 | GlobalValue *GV = GSDN->getGlobal(); |
| 437 | if (GV->getAlignment() == 16) { |
| 438 | Base = Op0; |
| 439 | Index = Zero; |
| 440 | return true; |
| 441 | } |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | break; |
| 447 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 448 | return false; |
| 449 | } |
| 450 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 451 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 452 | SPUDAGToDAGISel::SelectDForm2Addr(SDValue Op, SDValue N, SDValue &Disp, |
| 453 | SDValue &Base) { |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 454 | const int minDForm2Offset = -(1 << 7); |
| 455 | const int maxDForm2Offset = (1 << 7) - 1; |
| 456 | return DFormAddressPredicate(Op, N, Disp, Base, minDForm2Offset, |
| 457 | maxDForm2Offset); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 458 | } |
| 459 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 460 | /*! |
| 461 | \arg Op The ISD instruction (ignored) |
| 462 | \arg N The address to be tested |
| 463 | \arg Base Base address register/pointer |
| 464 | \arg Index Base address index |
| 465 | |
| 466 | Examine the input address by a base register plus a signed 10-bit |
| 467 | displacement, [r+I10] (D-form address). |
| 468 | |
| 469 | \return true if \a N is a D-form address with \a Base and \a Index set |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 470 | to non-empty SDValue instances. |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 471 | */ |
| 472 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 473 | SPUDAGToDAGISel::SelectDFormAddr(SDValue Op, SDValue N, SDValue &Base, |
| 474 | SDValue &Index) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 475 | return DFormAddressPredicate(Op, N, Base, Index, |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 476 | SPUFrameInfo::minFrameOffset(), |
| 477 | SPUFrameInfo::maxFrameOffset()); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 481 | SPUDAGToDAGISel::DFormAddressPredicate(SDValue Op, SDValue N, SDValue &Base, |
| 482 | SDValue &Index, int minOffset, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 483 | int maxOffset) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 484 | unsigned Opc = N.getOpcode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 485 | MVT PtrTy = SPUtli.getPointerTy(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 486 | |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 487 | if (Opc == ISD::FrameIndex) { |
| 488 | // Stack frame index must be less than 512 (divided by 16): |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 489 | FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(N); |
| 490 | int FI = int(FIN->getIndex()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 491 | DEBUG(cerr << "SelectDFormAddr: ISD::FrameIndex = " |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 492 | << FI << "\n"); |
| 493 | if (SPUFrameInfo::FItoStackOffset(FI) < maxOffset) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 494 | Base = CurDAG->getTargetConstant(0, PtrTy); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 495 | Index = CurDAG->getTargetFrameIndex(FI, PtrTy); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 496 | return true; |
| 497 | } |
| 498 | } else if (Opc == ISD::ADD) { |
| 499 | // Generated by getelementptr |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 500 | const SDValue Op0 = N.getOperand(0); |
| 501 | const SDValue Op1 = N.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 502 | |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 503 | if ((Op0.getOpcode() == SPUISD::Hi && Op1.getOpcode() == SPUISD::Lo) |
| 504 | || (Op1.getOpcode() == SPUISD::Hi && Op0.getOpcode() == SPUISD::Lo)) { |
| 505 | Base = CurDAG->getTargetConstant(0, PtrTy); |
| 506 | Index = N; |
| 507 | return true; |
| 508 | } else if (Op1.getOpcode() == ISD::Constant |
| 509 | || Op1.getOpcode() == ISD::TargetConstant) { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 510 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op1); |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 511 | int32_t offset = int32_t(CN->getSExtValue()); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 512 | |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 513 | if (Op0.getOpcode() == ISD::FrameIndex) { |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 514 | FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Op0); |
| 515 | int FI = int(FIN->getIndex()); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 516 | DEBUG(cerr << "SelectDFormAddr: ISD::ADD offset = " << offset |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 517 | << " frame index = " << FI << "\n"); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 518 | |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 519 | if (SPUFrameInfo::FItoStackOffset(FI) < maxOffset) { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 520 | Base = CurDAG->getTargetConstant(offset, PtrTy); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 521 | Index = CurDAG->getTargetFrameIndex(FI, PtrTy); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 522 | return true; |
| 523 | } |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 524 | } else if (offset > minOffset && offset < maxOffset) { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 525 | Base = CurDAG->getTargetConstant(offset, PtrTy); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 526 | Index = Op0; |
| 527 | return true; |
| 528 | } |
| 529 | } else if (Op0.getOpcode() == ISD::Constant |
| 530 | || Op0.getOpcode() == ISD::TargetConstant) { |
| 531 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op0); |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 532 | int32_t offset = int32_t(CN->getSExtValue()); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 533 | |
| 534 | if (Op1.getOpcode() == ISD::FrameIndex) { |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 535 | FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Op1); |
| 536 | int FI = int(FIN->getIndex()); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 537 | DEBUG(cerr << "SelectDFormAddr: ISD::ADD offset = " << offset |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 538 | << " frame index = " << FI << "\n"); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 539 | |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 540 | if (SPUFrameInfo::FItoStackOffset(FI) < maxOffset) { |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 541 | Base = CurDAG->getTargetConstant(offset, PtrTy); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 542 | Index = CurDAG->getTargetFrameIndex(FI, PtrTy); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 543 | return true; |
| 544 | } |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 545 | } else if (offset > minOffset && offset < maxOffset) { |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 546 | Base = CurDAG->getTargetConstant(offset, PtrTy); |
| 547 | Index = Op1; |
| 548 | return true; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 549 | } |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 550 | } |
| 551 | } else if (Opc == SPUISD::IndirectAddr) { |
| 552 | // Indirect with constant offset -> D-Form address |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 553 | const SDValue Op0 = N.getOperand(0); |
| 554 | const SDValue Op1 = N.getOperand(1); |
Scott Michel | 497e888 | 2008-01-11 21:01:19 +0000 | [diff] [blame] | 555 | |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 556 | if (Op0.getOpcode() == SPUISD::Hi |
| 557 | && Op1.getOpcode() == SPUISD::Lo) { |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 558 | // (SPUindirect (SPUhi <arg>, 0), (SPUlo <arg>, 0)) |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 559 | Base = CurDAG->getTargetConstant(0, PtrTy); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 560 | Index = N; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 561 | return true; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 562 | } else if (isa<ConstantSDNode>(Op0) || isa<ConstantSDNode>(Op1)) { |
| 563 | int32_t offset = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 564 | SDValue idxOp; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 565 | |
| 566 | if (isa<ConstantSDNode>(Op1)) { |
| 567 | ConstantSDNode *CN = cast<ConstantSDNode>(Op1); |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 568 | offset = int32_t(CN->getSExtValue()); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 569 | idxOp = Op0; |
| 570 | } else if (isa<ConstantSDNode>(Op0)) { |
| 571 | ConstantSDNode *CN = cast<ConstantSDNode>(Op0); |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 572 | offset = int32_t(CN->getSExtValue()); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 573 | idxOp = Op1; |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 574 | } |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 575 | |
| 576 | if (offset >= minOffset && offset <= maxOffset) { |
| 577 | Base = CurDAG->getTargetConstant(offset, PtrTy); |
| 578 | Index = idxOp; |
| 579 | return true; |
| 580 | } |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 581 | } |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 582 | } else if (Opc == SPUISD::AFormAddr) { |
| 583 | Base = CurDAG->getTargetConstant(0, N.getValueType()); |
| 584 | Index = N; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 585 | return true; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 586 | } else if (Opc == SPUISD::LDRESULT) { |
| 587 | Base = CurDAG->getTargetConstant(0, N.getValueType()); |
| 588 | Index = N; |
| 589 | return true; |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 590 | } else if (Opc == ISD::Register || Opc == ISD::CopyFromReg) { |
| 591 | unsigned OpOpc = Op.getOpcode(); |
| 592 | |
| 593 | if (OpOpc == ISD::STORE || OpOpc == ISD::LOAD) { |
| 594 | // Direct load/store without getelementptr |
| 595 | SDValue Addr, Offs; |
| 596 | |
| 597 | // Get the register from CopyFromReg |
| 598 | if (Opc == ISD::CopyFromReg) |
| 599 | Addr = N.getOperand(1); |
| 600 | else |
| 601 | Addr = N; // Register |
| 602 | |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 603 | Offs = ((OpOpc == ISD::STORE) ? Op.getOperand(3) : Op.getOperand(2)); |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 604 | |
| 605 | if (Offs.getOpcode() == ISD::Constant || Offs.getOpcode() == ISD::UNDEF) { |
| 606 | if (Offs.getOpcode() == ISD::UNDEF) |
| 607 | Offs = CurDAG->getTargetConstant(0, Offs.getValueType()); |
| 608 | |
| 609 | Base = Offs; |
| 610 | Index = Addr; |
| 611 | return true; |
| 612 | } |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 613 | } else { |
| 614 | /* If otherwise unadorned, default to D-form address with 0 offset: */ |
| 615 | if (Opc == ISD::CopyFromReg) { |
Scott Michel | 19c10e6 | 2009-01-26 03:37:41 +0000 | [diff] [blame] | 616 | Index = N.getOperand(1); |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 617 | } else { |
Scott Michel | 19c10e6 | 2009-01-26 03:37:41 +0000 | [diff] [blame] | 618 | Index = N; |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | Base = CurDAG->getTargetConstant(0, Index.getValueType()); |
| 622 | return true; |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 623 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 624 | } |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 625 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 626 | return false; |
| 627 | } |
| 628 | |
| 629 | /*! |
| 630 | \arg Op The ISD instruction operand |
| 631 | \arg N The address operand |
| 632 | \arg Base The base pointer operand |
| 633 | \arg Index The offset/index operand |
| 634 | |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 635 | If the address \a N can be expressed as an A-form or D-form address, returns |
| 636 | false. Otherwise, creates two operands, Base and Index that will become the |
| 637 | (r)(r) X-form address. |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 638 | */ |
| 639 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 640 | SPUDAGToDAGISel::SelectXFormAddr(SDValue Op, SDValue N, SDValue &Base, |
| 641 | SDValue &Index) { |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 642 | if (!SelectAFormAddr(Op, N, Base, Index) |
| 643 | && !SelectDFormAddr(Op, N, Base, Index)) { |
Scott Michel | 18fae69 | 2008-11-25 17:29:43 +0000 | [diff] [blame] | 644 | // If the address is neither A-form or D-form, punt and use an X-form |
| 645 | // address: |
Scott Michel | 1a6cdb6 | 2008-12-01 17:56:02 +0000 | [diff] [blame] | 646 | Base = N.getOperand(1); |
| 647 | Index = N.getOperand(0); |
Scott Michel | 50843c0 | 2008-11-25 04:03:47 +0000 | [diff] [blame] | 648 | return true; |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | return false; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 654 | //! Convert the operand from a target-independent to a target-specific node |
| 655 | /*! |
| 656 | */ |
| 657 | SDNode * |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 658 | SPUDAGToDAGISel::Select(SDValue Op) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 659 | SDNode *N = Op.getNode(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 660 | unsigned Opc = N->getOpcode(); |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 661 | int n_ops = -1; |
| 662 | unsigned NewOpc; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 663 | MVT OpVT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 664 | SDValue Ops[8]; |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 665 | DebugLoc dl = N->getDebugLoc(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 666 | |
Dan Gohman | e8be6c6 | 2008-07-17 19:10:17 +0000 | [diff] [blame] | 667 | if (N->isMachineOpcode()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 668 | return NULL; // Already selected. |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | if (Opc == ISD::FrameIndex) { |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 672 | int FI = cast<FrameIndexSDNode>(N)->getIndex(); |
| 673 | SDValue TFI = CurDAG->getTargetFrameIndex(FI, Op.getValueType()); |
| 674 | SDValue Imm0 = CurDAG->getTargetConstant(0, Op.getValueType()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 675 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 676 | if (FI < 128) { |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 677 | NewOpc = SPU::AIr32; |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 678 | Ops[0] = TFI; |
| 679 | Ops[1] = Imm0; |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 680 | n_ops = 2; |
| 681 | } else { |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 682 | NewOpc = SPU::Ar32; |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 683 | Ops[0] = CurDAG->getRegister(SPU::R1, Op.getValueType()); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 684 | Ops[1] = SDValue(CurDAG->getTargetNode(SPU::ILAr32, dl, Op.getValueType(), |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 685 | TFI, Imm0), 0); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 686 | n_ops = 2; |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 687 | } |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 688 | } else if (Opc == ISD::Constant && OpVT == MVT::i64) { |
| 689 | // Catch the i64 constants that end up here. Note: The backend doesn't |
| 690 | // attempt to legalize the constant (it's useless because DAGCombiner |
| 691 | // will insert 64-bit constants and we can't stop it). |
| 692 | return SelectI64Constant(Op, OpVT); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 693 | } else if ((Opc == ISD::ZERO_EXTEND || Opc == ISD::ANY_EXTEND) |
| 694 | && OpVT == MVT::i64) { |
| 695 | SDValue Op0 = Op.getOperand(0); |
| 696 | MVT Op0VT = Op0.getValueType(); |
| 697 | MVT Op0VecVT = MVT::getVectorVT(Op0VT, (128 / Op0VT.getSizeInBits())); |
| 698 | MVT OpVecVT = MVT::getVectorVT(OpVT, (128 / OpVT.getSizeInBits())); |
| 699 | SDValue shufMask; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 700 | |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 701 | switch (Op0VT.getSimpleVT()) { |
| 702 | default: |
| 703 | cerr << "CellSPU Select: Unhandled zero/any extend MVT\n"; |
| 704 | abort(); |
| 705 | /*NOTREACHED*/ |
| 706 | break; |
| 707 | case MVT::i32: |
Evan Cheng | a87008d | 2009-02-25 22:49:59 +0000 | [diff] [blame^] | 708 | shufMask = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 709 | CurDAG->getConstant(0x80808080, MVT::i32), |
| 710 | CurDAG->getConstant(0x00010203, MVT::i32), |
| 711 | CurDAG->getConstant(0x80808080, MVT::i32), |
| 712 | CurDAG->getConstant(0x08090a0b, MVT::i32)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 713 | break; |
| 714 | |
| 715 | case MVT::i16: |
Evan Cheng | a87008d | 2009-02-25 22:49:59 +0000 | [diff] [blame^] | 716 | shufMask = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 717 | CurDAG->getConstant(0x80808080, MVT::i32), |
| 718 | CurDAG->getConstant(0x80800203, MVT::i32), |
| 719 | CurDAG->getConstant(0x80808080, MVT::i32), |
| 720 | CurDAG->getConstant(0x80800a0b, MVT::i32)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 721 | break; |
| 722 | |
| 723 | case MVT::i8: |
Evan Cheng | a87008d | 2009-02-25 22:49:59 +0000 | [diff] [blame^] | 724 | shufMask = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 725 | CurDAG->getConstant(0x80808080, MVT::i32), |
| 726 | CurDAG->getConstant(0x80808003, MVT::i32), |
| 727 | CurDAG->getConstant(0x80808080, MVT::i32), |
| 728 | CurDAG->getConstant(0x8080800b, MVT::i32)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 729 | break; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 730 | } |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 731 | |
| 732 | SDNode *shufMaskLoad = emitBuildVector(shufMask); |
| 733 | SDNode *PromoteScalar = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 734 | SelectCode(CurDAG->getNode(SPUISD::PREFSLOT2VEC, dl, Op0VecVT, Op0)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 735 | |
| 736 | SDValue zextShuffle = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 737 | CurDAG->getNode(SPUISD::SHUFB, dl, OpVecVT, |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 738 | SDValue(PromoteScalar, 0), |
| 739 | SDValue(PromoteScalar, 0), |
| 740 | SDValue(shufMaskLoad, 0)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 741 | |
| 742 | // N.B.: BIT_CONVERT replaces and updates the zextShuffle node, so we |
| 743 | // re-use it in the VEC2PREFSLOT selection without needing to explicitly |
| 744 | // call SelectCode (it's already done for us.) |
Dale Johannesen | 0469280 | 2009-02-07 00:56:46 +0000 | [diff] [blame] | 745 | SelectCode(CurDAG->getNode(ISD::BIT_CONVERT, dl, OpVecVT, zextShuffle)); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 746 | return SelectCode(CurDAG->getNode(SPUISD::VEC2PREFSLOT, dl, OpVT, |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 747 | zextShuffle)); |
| 748 | } else if (Opc == ISD::ADD && (OpVT == MVT::i64 || OpVT == MVT::v2i64)) { |
| 749 | SDNode *CGLoad = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 750 | emitBuildVector(SPU::getCarryGenerateShufMask(*CurDAG, dl)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 751 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 752 | return SelectCode(CurDAG->getNode(SPUISD::ADD64_MARKER, dl, OpVT, |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 753 | Op.getOperand(0), Op.getOperand(1), |
| 754 | SDValue(CGLoad, 0))); |
| 755 | } else if (Opc == ISD::SUB && (OpVT == MVT::i64 || OpVT == MVT::v2i64)) { |
| 756 | SDNode *CGLoad = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 757 | emitBuildVector(SPU::getBorrowGenerateShufMask(*CurDAG, dl)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 758 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 759 | return SelectCode(CurDAG->getNode(SPUISD::SUB64_MARKER, dl, OpVT, |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 760 | Op.getOperand(0), Op.getOperand(1), |
| 761 | SDValue(CGLoad, 0))); |
| 762 | } else if (Opc == ISD::MUL && (OpVT == MVT::i64 || OpVT == MVT::v2i64)) { |
| 763 | SDNode *CGLoad = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 764 | emitBuildVector(SPU::getCarryGenerateShufMask(*CurDAG, dl)); |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 765 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 766 | return SelectCode(CurDAG->getNode(SPUISD::MUL64_MARKER, dl, OpVT, |
Scott Michel | 94bd57e | 2009-01-15 04:41:47 +0000 | [diff] [blame] | 767 | Op.getOperand(0), Op.getOperand(1), |
| 768 | SDValue(CGLoad, 0))); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 769 | } else if (Opc == ISD::TRUNCATE) { |
| 770 | SDValue Op0 = Op.getOperand(0); |
| 771 | if ((Op0.getOpcode() == ISD::SRA || Op0.getOpcode() == ISD::SRL) |
| 772 | && OpVT == MVT::i32 |
| 773 | && Op0.getValueType() == MVT::i64) { |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 774 | // Catch (truncate:i32 ([sra|srl]:i64 arg, c), where c >= 32 |
| 775 | // |
| 776 | // Take advantage of the fact that the upper 32 bits are in the |
| 777 | // i32 preferred slot and avoid shuffle gymnastics: |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 778 | ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op0.getOperand(1)); |
| 779 | if (CN != 0) { |
| 780 | unsigned shift_amt = unsigned(CN->getZExtValue()); |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 781 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 782 | if (shift_amt >= 32) { |
| 783 | SDNode *hi32 = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 784 | CurDAG->getTargetNode(SPU::ORr32_r64, dl, OpVT, |
| 785 | Op0.getOperand(0)); |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 786 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 787 | shift_amt -= 32; |
| 788 | if (shift_amt > 0) { |
| 789 | // Take care of the additional shift, if present: |
| 790 | SDValue shift = CurDAG->getTargetConstant(shift_amt, MVT::i32); |
| 791 | unsigned Opc = SPU::ROTMAIr32_i32; |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 792 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 793 | if (Op0.getOpcode() == ISD::SRL) |
| 794 | Opc = SPU::ROTMr32; |
Scott Michel | d1e8d9c | 2009-01-21 04:58:48 +0000 | [diff] [blame] | 795 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 796 | hi32 = CurDAG->getTargetNode(Opc, dl, OpVT, SDValue(hi32, 0), |
| 797 | shift); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | return hi32; |
| 801 | } |
| 802 | } |
| 803 | } |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 804 | } else if (Opc == ISD::SHL) { |
| 805 | if (OpVT == MVT::i64) { |
| 806 | return SelectSHLi64(Op, OpVT); |
| 807 | } |
| 808 | } else if (Opc == ISD::SRL) { |
| 809 | if (OpVT == MVT::i64) { |
| 810 | return SelectSRLi64(Op, OpVT); |
| 811 | } |
| 812 | } else if (Opc == ISD::SRA) { |
| 813 | if (OpVT == MVT::i64) { |
| 814 | return SelectSRAi64(Op, OpVT); |
| 815 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 816 | } else if (Opc == SPUISD::LDRESULT) { |
| 817 | // Custom select instructions for LDRESULT |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 818 | MVT VT = N->getValueType(0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 819 | SDValue Arg = N->getOperand(0); |
| 820 | SDValue Chain = N->getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 821 | SDNode *Result; |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 822 | const valtype_map_s *vtm = getValueTypeMapEntry(VT); |
| 823 | |
| 824 | if (vtm->ldresult_ins == 0) { |
| 825 | cerr << "LDRESULT for unsupported type: " |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 826 | << VT.getMVTString() |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 827 | << "\n"; |
| 828 | abort(); |
| 829 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 830 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 831 | Opc = vtm->ldresult_ins; |
| 832 | if (vtm->ldresult_imm) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 833 | SDValue Zero = CurDAG->getTargetConstant(0, VT); |
Scott Michel | 86c041f | 2007-12-20 00:44:13 +0000 | [diff] [blame] | 834 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 835 | Result = CurDAG->getTargetNode(Opc, dl, VT, MVT::Other, Arg, Zero, Chain); |
Scott Michel | 86c041f | 2007-12-20 00:44:13 +0000 | [diff] [blame] | 836 | } else { |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 837 | Result = CurDAG->getTargetNode(Opc, dl, VT, MVT::Other, Arg, Arg, Chain); |
Scott Michel | 86c041f | 2007-12-20 00:44:13 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 840 | return Result; |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 841 | } else if (Opc == SPUISD::IndirectAddr) { |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 842 | // Look at the operands: SelectCode() will catch the cases that aren't |
| 843 | // specifically handled here. |
| 844 | // |
| 845 | // SPUInstrInfo catches the following patterns: |
| 846 | // (SPUindirect (SPUhi ...), (SPUlo ...)) |
| 847 | // (SPUindirect $sp, imm) |
| 848 | MVT VT = Op.getValueType(); |
| 849 | SDValue Op0 = N->getOperand(0); |
| 850 | SDValue Op1 = N->getOperand(1); |
| 851 | RegisterSDNode *RN; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 852 | |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 853 | if ((Op0.getOpcode() != SPUISD::Hi && Op1.getOpcode() != SPUISD::Lo) |
| 854 | || (Op0.getOpcode() == ISD::Register |
| 855 | && ((RN = dyn_cast<RegisterSDNode>(Op0.getNode())) != 0 |
| 856 | && RN->getReg() != SPU::R1))) { |
| 857 | NewOpc = SPU::Ar32; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 858 | if (Op1.getOpcode() == ISD::Constant) { |
| 859 | ConstantSDNode *CN = cast<ConstantSDNode>(Op1); |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 860 | Op1 = CurDAG->getTargetConstant(CN->getSExtValue(), VT); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 861 | NewOpc = (isI32IntS10Immediate(CN) ? SPU::AIr32 : SPU::Ar32); |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 862 | } |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 863 | Ops[0] = Op0; |
| 864 | Ops[1] = Op1; |
| 865 | n_ops = 2; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 866 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 867 | } |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 868 | |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 869 | if (n_ops > 0) { |
| 870 | if (N->hasOneUse()) |
| 871 | return CurDAG->SelectNodeTo(N, NewOpc, OpVT, Ops, n_ops); |
| 872 | else |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 873 | return CurDAG->getTargetNode(NewOpc, dl, OpVT, Ops, n_ops); |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 874 | } else |
| 875 | return SelectCode(Op); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 876 | } |
| 877 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 878 | /*! |
| 879 | * Emit the instruction sequence for i64 left shifts. The basic algorithm |
| 880 | * is to fill the bottom two word slots with zeros so that zeros are shifted |
| 881 | * in as the entire quadword is shifted left. |
| 882 | * |
| 883 | * \note This code could also be used to implement v2i64 shl. |
| 884 | * |
| 885 | * @param Op The shl operand |
| 886 | * @param OpVT Op's machine value value type (doesn't need to be passed, but |
| 887 | * makes life easier.) |
| 888 | * @return The SDNode with the entire instruction sequence |
| 889 | */ |
| 890 | SDNode * |
| 891 | SPUDAGToDAGISel::SelectSHLi64(SDValue &Op, MVT OpVT) { |
| 892 | SDValue Op0 = Op.getOperand(0); |
| 893 | MVT VecVT = MVT::getVectorVT(OpVT, (128 / OpVT.getSizeInBits())); |
| 894 | SDValue ShiftAmt = Op.getOperand(1); |
| 895 | MVT ShiftAmtVT = ShiftAmt.getValueType(); |
| 896 | SDNode *VecOp0, *SelMask, *ZeroFill, *Shift = 0; |
| 897 | SDValue SelMaskVal; |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 898 | DebugLoc dl = Op.getDebugLoc(); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 899 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 900 | VecOp0 = CurDAG->getTargetNode(SPU::ORv2i64_i64, dl, VecVT, Op0); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 901 | SelMaskVal = CurDAG->getTargetConstant(0xff00ULL, MVT::i16); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 902 | SelMask = CurDAG->getTargetNode(SPU::FSMBIv2i64, dl, VecVT, SelMaskVal); |
| 903 | ZeroFill = CurDAG->getTargetNode(SPU::ILv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 904 | CurDAG->getTargetConstant(0, OpVT)); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 905 | VecOp0 = CurDAG->getTargetNode(SPU::SELBv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 906 | SDValue(ZeroFill, 0), |
| 907 | SDValue(VecOp0, 0), |
| 908 | SDValue(SelMask, 0)); |
| 909 | |
| 910 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 911 | unsigned bytes = unsigned(CN->getZExtValue()) >> 3; |
| 912 | unsigned bits = unsigned(CN->getZExtValue()) & 7; |
| 913 | |
| 914 | if (bytes > 0) { |
| 915 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 916 | CurDAG->getTargetNode(SPU::SHLQBYIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 917 | SDValue(VecOp0, 0), |
| 918 | CurDAG->getTargetConstant(bytes, ShiftAmtVT)); |
| 919 | } |
| 920 | |
| 921 | if (bits > 0) { |
| 922 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 923 | CurDAG->getTargetNode(SPU::SHLQBIIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 924 | SDValue((Shift != 0 ? Shift : VecOp0), 0), |
| 925 | CurDAG->getTargetConstant(bits, ShiftAmtVT)); |
| 926 | } |
| 927 | } else { |
| 928 | SDNode *Bytes = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 929 | CurDAG->getTargetNode(SPU::ROTMIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 930 | ShiftAmt, |
| 931 | CurDAG->getTargetConstant(3, ShiftAmtVT)); |
| 932 | SDNode *Bits = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 933 | CurDAG->getTargetNode(SPU::ANDIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 934 | ShiftAmt, |
| 935 | CurDAG->getTargetConstant(7, ShiftAmtVT)); |
| 936 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 937 | CurDAG->getTargetNode(SPU::SHLQBYv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 938 | SDValue(VecOp0, 0), SDValue(Bytes, 0)); |
| 939 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 940 | CurDAG->getTargetNode(SPU::SHLQBIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 941 | SDValue(Shift, 0), SDValue(Bits, 0)); |
| 942 | } |
| 943 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 944 | return CurDAG->getTargetNode(SPU::ORi64_v2i64, dl, OpVT, SDValue(Shift, 0)); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /*! |
| 948 | * Emit the instruction sequence for i64 logical right shifts. |
| 949 | * |
| 950 | * @param Op The shl operand |
| 951 | * @param OpVT Op's machine value value type (doesn't need to be passed, but |
| 952 | * makes life easier.) |
| 953 | * @return The SDNode with the entire instruction sequence |
| 954 | */ |
| 955 | SDNode * |
| 956 | SPUDAGToDAGISel::SelectSRLi64(SDValue &Op, MVT OpVT) { |
| 957 | SDValue Op0 = Op.getOperand(0); |
| 958 | MVT VecVT = MVT::getVectorVT(OpVT, (128 / OpVT.getSizeInBits())); |
| 959 | SDValue ShiftAmt = Op.getOperand(1); |
| 960 | MVT ShiftAmtVT = ShiftAmt.getValueType(); |
| 961 | SDNode *VecOp0, *Shift = 0; |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 962 | DebugLoc dl = Op.getDebugLoc(); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 963 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 964 | VecOp0 = CurDAG->getTargetNode(SPU::ORv2i64_i64, dl, VecVT, Op0); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 965 | |
| 966 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 967 | unsigned bytes = unsigned(CN->getZExtValue()) >> 3; |
| 968 | unsigned bits = unsigned(CN->getZExtValue()) & 7; |
| 969 | |
| 970 | if (bytes > 0) { |
| 971 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 972 | CurDAG->getTargetNode(SPU::ROTQMBYIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 973 | SDValue(VecOp0, 0), |
| 974 | CurDAG->getTargetConstant(bytes, ShiftAmtVT)); |
| 975 | } |
| 976 | |
| 977 | if (bits > 0) { |
| 978 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 979 | CurDAG->getTargetNode(SPU::ROTQMBIIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 980 | SDValue((Shift != 0 ? Shift : VecOp0), 0), |
| 981 | CurDAG->getTargetConstant(bits, ShiftAmtVT)); |
| 982 | } |
| 983 | } else { |
| 984 | SDNode *Bytes = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 985 | CurDAG->getTargetNode(SPU::ROTMIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 986 | ShiftAmt, |
| 987 | CurDAG->getTargetConstant(3, ShiftAmtVT)); |
| 988 | SDNode *Bits = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 989 | CurDAG->getTargetNode(SPU::ANDIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 990 | ShiftAmt, |
| 991 | CurDAG->getTargetConstant(7, ShiftAmtVT)); |
| 992 | |
| 993 | // Ensure that the shift amounts are negated! |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 994 | Bytes = CurDAG->getTargetNode(SPU::SFIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 995 | SDValue(Bytes, 0), |
| 996 | CurDAG->getTargetConstant(0, ShiftAmtVT)); |
| 997 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 998 | Bits = CurDAG->getTargetNode(SPU::SFIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 999 | SDValue(Bits, 0), |
| 1000 | CurDAG->getTargetConstant(0, ShiftAmtVT)); |
| 1001 | |
| 1002 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1003 | CurDAG->getTargetNode(SPU::ROTQMBYv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1004 | SDValue(VecOp0, 0), SDValue(Bytes, 0)); |
| 1005 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1006 | CurDAG->getTargetNode(SPU::ROTQMBIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1007 | SDValue(Shift, 0), SDValue(Bits, 0)); |
| 1008 | } |
| 1009 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1010 | return CurDAG->getTargetNode(SPU::ORi64_v2i64, dl, OpVT, SDValue(Shift, 0)); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | /*! |
| 1014 | * Emit the instruction sequence for i64 arithmetic right shifts. |
| 1015 | * |
| 1016 | * @param Op The shl operand |
| 1017 | * @param OpVT Op's machine value value type (doesn't need to be passed, but |
| 1018 | * makes life easier.) |
| 1019 | * @return The SDNode with the entire instruction sequence |
| 1020 | */ |
| 1021 | SDNode * |
| 1022 | SPUDAGToDAGISel::SelectSRAi64(SDValue &Op, MVT OpVT) { |
| 1023 | // Promote Op0 to vector |
| 1024 | MVT VecVT = MVT::getVectorVT(OpVT, (128 / OpVT.getSizeInBits())); |
| 1025 | SDValue ShiftAmt = Op.getOperand(1); |
| 1026 | MVT ShiftAmtVT = ShiftAmt.getValueType(); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1027 | DebugLoc dl = Op.getDebugLoc(); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1028 | |
| 1029 | SDNode *VecOp0 = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1030 | CurDAG->getTargetNode(SPU::ORv2i64_i64, dl, VecVT, Op.getOperand(0)); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1031 | |
| 1032 | SDValue SignRotAmt = CurDAG->getTargetConstant(31, ShiftAmtVT); |
| 1033 | SDNode *SignRot = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1034 | CurDAG->getTargetNode(SPU::ROTMAIv2i64_i32, dl, MVT::v2i64, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1035 | SDValue(VecOp0, 0), SignRotAmt); |
| 1036 | SDNode *UpperHalfSign = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1037 | CurDAG->getTargetNode(SPU::ORi32_v4i32, dl, MVT::i32, SDValue(SignRot, 0)); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1038 | |
| 1039 | SDNode *UpperHalfSignMask = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1040 | CurDAG->getTargetNode(SPU::FSM64r32, dl, VecVT, SDValue(UpperHalfSign, 0)); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1041 | SDNode *UpperLowerMask = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1042 | CurDAG->getTargetNode(SPU::FSMBIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1043 | CurDAG->getTargetConstant(0xff00ULL, MVT::i16)); |
| 1044 | SDNode *UpperLowerSelect = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1045 | CurDAG->getTargetNode(SPU::SELBv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1046 | SDValue(UpperHalfSignMask, 0), |
| 1047 | SDValue(VecOp0, 0), |
| 1048 | SDValue(UpperLowerMask, 0)); |
| 1049 | |
| 1050 | SDNode *Shift = 0; |
| 1051 | |
| 1052 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(ShiftAmt)) { |
| 1053 | unsigned bytes = unsigned(CN->getZExtValue()) >> 3; |
| 1054 | unsigned bits = unsigned(CN->getZExtValue()) & 7; |
| 1055 | |
| 1056 | if (bytes > 0) { |
| 1057 | bytes = 31 - bytes; |
| 1058 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1059 | CurDAG->getTargetNode(SPU::ROTQBYIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1060 | SDValue(UpperLowerSelect, 0), |
| 1061 | CurDAG->getTargetConstant(bytes, ShiftAmtVT)); |
| 1062 | } |
| 1063 | |
| 1064 | if (bits > 0) { |
| 1065 | bits = 8 - bits; |
| 1066 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1067 | CurDAG->getTargetNode(SPU::ROTQBIIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1068 | SDValue((Shift != 0 ? Shift : UpperLowerSelect), 0), |
| 1069 | CurDAG->getTargetConstant(bits, ShiftAmtVT)); |
| 1070 | } |
| 1071 | } else { |
| 1072 | SDNode *NegShift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1073 | CurDAG->getTargetNode(SPU::SFIr32, dl, ShiftAmtVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1074 | ShiftAmt, CurDAG->getTargetConstant(0, ShiftAmtVT)); |
| 1075 | |
| 1076 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1077 | CurDAG->getTargetNode(SPU::ROTQBYBIv2i64_r32, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1078 | SDValue(UpperLowerSelect, 0), SDValue(NegShift, 0)); |
| 1079 | Shift = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1080 | CurDAG->getTargetNode(SPU::ROTQBIv2i64, dl, VecVT, |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1081 | SDValue(Shift, 0), SDValue(NegShift, 0)); |
| 1082 | } |
| 1083 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1084 | return CurDAG->getTargetNode(SPU::ORi64_v2i64, dl, OpVT, SDValue(Shift, 0)); |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1087 | /*! |
| 1088 | Do the necessary magic necessary to load a i64 constant |
| 1089 | */ |
| 1090 | SDNode *SPUDAGToDAGISel::SelectI64Constant(SDValue& Op, MVT OpVT) { |
| 1091 | ConstantSDNode *CN = cast<ConstantSDNode>(Op.getNode()); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1092 | // Currently there's no DL on the input, but won't hurt to pretend. |
| 1093 | DebugLoc dl = Op.getDebugLoc(); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1094 | MVT OpVecVT = MVT::getVectorVT(OpVT, 2); |
| 1095 | SDValue i64vec = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1096 | SPU::LowerSplat_v2i64(OpVecVT, *CurDAG, CN->getZExtValue(), dl); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1097 | |
| 1098 | // Here's where it gets interesting, because we have to parse out the |
| 1099 | // subtree handed back in i64vec: |
| 1100 | |
| 1101 | if (i64vec.getOpcode() == ISD::BIT_CONVERT) { |
| 1102 | // The degenerate case where the upper and lower bits in the splat are |
| 1103 | // identical: |
| 1104 | SDValue Op0 = i64vec.getOperand(0); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1105 | |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 1106 | ReplaceUses(i64vec, Op0); |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1107 | return CurDAG->getTargetNode(SPU::ORi64_v2i64, dl, OpVT, |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1108 | SDValue(emitBuildVector(Op0), 0)); |
| 1109 | } else if (i64vec.getOpcode() == SPUISD::SHUFB) { |
| 1110 | SDValue lhs = i64vec.getOperand(0); |
| 1111 | SDValue rhs = i64vec.getOperand(1); |
| 1112 | SDValue shufmask = i64vec.getOperand(2); |
| 1113 | |
| 1114 | if (lhs.getOpcode() == ISD::BIT_CONVERT) { |
| 1115 | ReplaceUses(lhs, lhs.getOperand(0)); |
| 1116 | lhs = lhs.getOperand(0); |
| 1117 | } |
| 1118 | |
| 1119 | SDNode *lhsNode = (lhs.getNode()->isMachineOpcode() |
| 1120 | ? lhs.getNode() |
| 1121 | : emitBuildVector(lhs)); |
| 1122 | |
| 1123 | if (rhs.getOpcode() == ISD::BIT_CONVERT) { |
| 1124 | ReplaceUses(rhs, rhs.getOperand(0)); |
| 1125 | rhs = rhs.getOperand(0); |
| 1126 | } |
| 1127 | |
| 1128 | SDNode *rhsNode = (rhs.getNode()->isMachineOpcode() |
| 1129 | ? rhs.getNode() |
| 1130 | : emitBuildVector(rhs)); |
Scott Michel | 9de57a9 | 2009-01-26 22:33:37 +0000 | [diff] [blame] | 1131 | |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1132 | if (shufmask.getOpcode() == ISD::BIT_CONVERT) { |
| 1133 | ReplaceUses(shufmask, shufmask.getOperand(0)); |
| 1134 | shufmask = shufmask.getOperand(0); |
| 1135 | } |
| 1136 | |
| 1137 | SDNode *shufMaskNode = (shufmask.getNode()->isMachineOpcode() |
| 1138 | ? shufmask.getNode() |
| 1139 | : emitBuildVector(shufmask)); |
| 1140 | |
| 1141 | SDNode *shufNode = |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1142 | Select(CurDAG->getNode(SPUISD::SHUFB, dl, OpVecVT, |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1143 | SDValue(lhsNode, 0), SDValue(rhsNode, 0), |
| 1144 | SDValue(shufMaskNode, 0))); |
| 1145 | |
Dale Johannesen | ed2eee6 | 2009-02-06 01:31:28 +0000 | [diff] [blame] | 1146 | return CurDAG->getTargetNode(SPU::ORi64_v2i64, dl, OpVT, |
| 1147 | SDValue(shufNode, 0)); |
Scott Michel | c9c8b2a | 2009-01-26 03:31:40 +0000 | [diff] [blame] | 1148 | } else { |
| 1149 | cerr << "SPUDAGToDAGISel::SelectI64Constant: Unhandled i64vec condition\n"; |
| 1150 | abort(); |
| 1151 | } |
| 1152 | } |
| 1153 | |
Scott Michel | 02d711b | 2008-12-30 23:28:25 +0000 | [diff] [blame] | 1154 | /// createSPUISelDag - This pass converts a legalized DAG into a |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1155 | /// SPU-specific DAG, ready for instruction scheduling. |
| 1156 | /// |
| 1157 | FunctionPass *llvm::createSPUISelDag(SPUTargetMachine &TM) { |
| 1158 | return new SPUDAGToDAGISel(TM); |
| 1159 | } |