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