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