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