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