Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1 | //===-- SPUISelLowering.cpp - Cell SPU DAG Lowering Implementation --------===// |
| 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 implements the SPUTargetLowering class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SPURegisterNames.h" |
| 15 | #include "SPUISelLowering.h" |
| 16 | #include "SPUTargetMachine.h" |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 17 | #include "SPUFrameInfo.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/VectorExtras.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/CallingConvLower.h" |
| 20 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/SelectionDAG.h" |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 25 | #include "llvm/Constants.h" |
| 26 | #include "llvm/Function.h" |
| 27 | #include "llvm/Intrinsics.h" |
| 28 | #include "llvm/Support/Debug.h" |
| 29 | #include "llvm/Support/MathExtras.h" |
| 30 | #include "llvm/Target/TargetOptions.h" |
| 31 | |
| 32 | #include <map> |
| 33 | |
| 34 | using namespace llvm; |
| 35 | |
| 36 | // Used in getTargetNodeName() below |
| 37 | namespace { |
| 38 | std::map<unsigned, const char *> node_names; |
| 39 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 40 | //! MVT mapping to useful data for Cell SPU |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 41 | struct valtype_map_s { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 42 | const MVT valtype; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 43 | const int prefslot_byte; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 44 | }; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 45 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 46 | const valtype_map_s valtype_map[] = { |
| 47 | { MVT::i1, 3 }, |
| 48 | { MVT::i8, 3 }, |
| 49 | { MVT::i16, 2 }, |
| 50 | { MVT::i32, 0 }, |
| 51 | { MVT::f32, 0 }, |
| 52 | { MVT::i64, 0 }, |
| 53 | { MVT::f64, 0 }, |
| 54 | { MVT::i128, 0 } |
| 55 | }; |
| 56 | |
| 57 | const size_t n_valtype_map = sizeof(valtype_map) / sizeof(valtype_map[0]); |
| 58 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 59 | const valtype_map_s *getValueTypeMapEntry(MVT VT) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 60 | const valtype_map_s *retval = 0; |
| 61 | |
| 62 | for (size_t i = 0; i < n_valtype_map; ++i) { |
| 63 | if (valtype_map[i].valtype == VT) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 64 | retval = valtype_map + i; |
| 65 | break; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | #ifndef NDEBUG |
| 70 | if (retval == 0) { |
| 71 | cerr << "getValueTypeMapEntry returns NULL for " |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 72 | << VT.getMVTString() |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 73 | << "\n"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 74 | abort(); |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | return retval; |
| 79 | } |
| 80 | |
| 81 | //! Predicate that returns true if operand is a memory target |
| 82 | /*! |
| 83 | \arg Op Operand to test |
| 84 | \return true if the operand is a memory target (i.e., global |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 85 | address, external symbol, constant pool) or an A-form |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 86 | address. |
| 87 | */ |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 88 | bool isMemoryOperand(const SDValue &Op) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 89 | { |
| 90 | const unsigned Opc = Op.getOpcode(); |
| 91 | return (Opc == ISD::GlobalAddress |
| 92 | || Opc == ISD::GlobalTLSAddress |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 93 | || Opc == ISD::JumpTable |
| 94 | || Opc == ISD::ConstantPool |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 95 | || Opc == ISD::ExternalSymbol |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 96 | || Opc == ISD::TargetGlobalAddress |
| 97 | || Opc == ISD::TargetGlobalTLSAddress |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 98 | || Opc == ISD::TargetJumpTable |
| 99 | || Opc == ISD::TargetConstantPool |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 100 | || Opc == ISD::TargetExternalSymbol |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 101 | || Opc == SPUISD::AFormAddr); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 102 | } |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 103 | |
| 104 | //! Predicate that returns true if the operand is an indirect target |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 105 | bool isIndirectOperand(const SDValue &Op) |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 106 | { |
| 107 | const unsigned Opc = Op.getOpcode(); |
| 108 | return (Opc == ISD::Register |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 109 | || Opc == SPUISD::LDRESULT); |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 110 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | SPUTargetLowering::SPUTargetLowering(SPUTargetMachine &TM) |
| 114 | : TargetLowering(TM), |
| 115 | SPUTM(TM) |
| 116 | { |
| 117 | // Fold away setcc operations if possible. |
| 118 | setPow2DivIsCheap(); |
| 119 | |
| 120 | // Use _setjmp/_longjmp instead of setjmp/longjmp. |
| 121 | setUseUnderscoreSetJmp(true); |
| 122 | setUseUnderscoreLongJmp(true); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 123 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 124 | // Set up the SPU's register classes: |
Scott Michel | 504c369 | 2007-12-17 22:32:34 +0000 | [diff] [blame] | 125 | addRegisterClass(MVT::i8, SPU::R8CRegisterClass); |
| 126 | addRegisterClass(MVT::i16, SPU::R16CRegisterClass); |
| 127 | addRegisterClass(MVT::i32, SPU::R32CRegisterClass); |
| 128 | addRegisterClass(MVT::i64, SPU::R64CRegisterClass); |
| 129 | addRegisterClass(MVT::f32, SPU::R32FPRegisterClass); |
| 130 | addRegisterClass(MVT::f64, SPU::R64FPRegisterClass); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 131 | addRegisterClass(MVT::i128, SPU::GPRCRegisterClass); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 132 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 133 | // SPU has no sign or zero extended loads for i1, i8, i16: |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 134 | setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote); |
| 135 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
| 136 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote); |
Scott Michel | 719b0e1 | 2008-11-19 17:45:08 +0000 | [diff] [blame] | 137 | setTruncStoreAction(MVT::i8, MVT::i1, Promote); |
Scott Michel | a0e5769 | 2008-11-20 04:26:21 +0000 | [diff] [blame^] | 138 | setTruncStoreAction(MVT::i16, MVT::i1, Custom); |
| 139 | setTruncStoreAction(MVT::i32, MVT::i1, Custom); |
| 140 | setTruncStoreAction(MVT::i64, MVT::i1, Custom); |
Scott Michel | 719b0e1 | 2008-11-19 17:45:08 +0000 | [diff] [blame] | 141 | setTruncStoreAction(MVT::i128, MVT::i1, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 142 | |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 143 | setLoadExtAction(ISD::EXTLOAD, MVT::i8, Custom); |
| 144 | setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Custom); |
| 145 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i8, Custom); |
Scott Michel | a0e5769 | 2008-11-20 04:26:21 +0000 | [diff] [blame^] | 146 | setTruncStoreAction(MVT::i8, MVT::i8, Custom); |
| 147 | setTruncStoreAction(MVT::i16, MVT::i8, Custom); |
| 148 | setTruncStoreAction(MVT::i32, MVT::i8, Custom); |
| 149 | setTruncStoreAction(MVT::i64, MVT::i8, Custom); |
| 150 | setTruncStoreAction(MVT::i128, MVT::i8, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 151 | |
Evan Cheng | 0329466 | 2008-10-14 21:26:46 +0000 | [diff] [blame] | 152 | setLoadExtAction(ISD::EXTLOAD, MVT::i16, Custom); |
| 153 | setLoadExtAction(ISD::SEXTLOAD, MVT::i16, Custom); |
| 154 | setLoadExtAction(ISD::ZEXTLOAD, MVT::i16, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 155 | |
| 156 | // SPU constant load actions are custom lowered: |
| 157 | setOperationAction(ISD::Constant, MVT::i64, Custom); |
Nate Begeman | ccef580 | 2008-02-14 18:43:04 +0000 | [diff] [blame] | 158 | setOperationAction(ISD::ConstantFP, MVT::f32, Legal); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 159 | setOperationAction(ISD::ConstantFP, MVT::f64, Custom); |
| 160 | |
| 161 | // SPU's loads and stores have to be custom lowered: |
Scott Michel | 719b0e1 | 2008-11-19 17:45:08 +0000 | [diff] [blame] | 162 | for (unsigned sctype = (unsigned) MVT::i8; sctype < (unsigned) MVT::f128; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 163 | ++sctype) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 164 | MVT VT = (MVT::SimpleValueType)sctype; |
| 165 | |
| 166 | setOperationAction(ISD::LOAD, VT, Custom); |
| 167 | setOperationAction(ISD::STORE, VT, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 170 | // Custom lower BRCOND for i1, i8 to "promote" the result to |
| 171 | // i32 and i16, respectively. |
| 172 | setOperationAction(ISD::BRCOND, MVT::Other, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 173 | |
| 174 | // Expand the jumptable branches |
| 175 | setOperationAction(ISD::BR_JT, MVT::Other, Expand); |
| 176 | setOperationAction(ISD::BR_CC, MVT::Other, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 177 | setOperationAction(ISD::SELECT_CC, MVT::Other, Expand); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 178 | |
| 179 | // SPU has no intrinsics for these particular operations: |
Andrew Lenharth | d497d9f | 2008-02-16 14:46:26 +0000 | [diff] [blame] | 180 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
| 181 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 182 | // PowerPC has no SREM/UREM instructions |
| 183 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 184 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 185 | setOperationAction(ISD::SREM, MVT::i64, Expand); |
| 186 | setOperationAction(ISD::UREM, MVT::i64, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 187 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 188 | // We don't support sin/cos/sqrt/fmod |
| 189 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 190 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
| 191 | setOperationAction(ISD::FREM , MVT::f64, Expand); |
| 192 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 193 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
| 194 | setOperationAction(ISD::FREM , MVT::f32, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 195 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 196 | // If we're enabling GP optimizations, use hardware square root |
| 197 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 198 | setOperationAction(ISD::FSQRT, MVT::f32, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 199 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 200 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 201 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
| 202 | |
| 203 | // SPU can do rotate right and left, so legalize it... but customize for i8 |
| 204 | // because instructions don't exist. |
Bill Wendling | 9440e35 | 2008-08-31 02:59:23 +0000 | [diff] [blame] | 205 | |
| 206 | // FIXME: Change from "expand" to appropriate type once ROTR is supported in |
| 207 | // .td files. |
| 208 | setOperationAction(ISD::ROTR, MVT::i32, Expand /*Legal*/); |
| 209 | setOperationAction(ISD::ROTR, MVT::i16, Expand /*Legal*/); |
| 210 | setOperationAction(ISD::ROTR, MVT::i8, Expand /*Custom*/); |
| 211 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 212 | setOperationAction(ISD::ROTL, MVT::i32, Legal); |
| 213 | setOperationAction(ISD::ROTL, MVT::i16, Legal); |
| 214 | setOperationAction(ISD::ROTL, MVT::i8, Custom); |
| 215 | // SPU has no native version of shift left/right for i8 |
| 216 | setOperationAction(ISD::SHL, MVT::i8, Custom); |
| 217 | setOperationAction(ISD::SRL, MVT::i8, Custom); |
| 218 | setOperationAction(ISD::SRA, MVT::i8, Custom); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 219 | // And SPU needs custom lowering for shift left/right for i64 |
| 220 | setOperationAction(ISD::SHL, MVT::i64, Custom); |
| 221 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 222 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 223 | |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 224 | // Custom lower i8, i32 and i64 multiplications |
| 225 | setOperationAction(ISD::MUL, MVT::i8, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 226 | setOperationAction(ISD::MUL, MVT::i32, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 227 | setOperationAction(ISD::MUL, MVT::i64, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 228 | |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 229 | // Need to custom handle (some) common i8, i64 math ops |
| 230 | setOperationAction(ISD::ADD, MVT::i64, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 231 | setOperationAction(ISD::SUB, MVT::i8, Custom); |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 232 | setOperationAction(ISD::SUB, MVT::i64, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 233 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 234 | // SPU does not have BSWAP. It does have i32 support CTLZ. |
| 235 | // CTPOP has to be custom lowered. |
| 236 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| 237 | setOperationAction(ISD::BSWAP, MVT::i64, Expand); |
| 238 | |
| 239 | setOperationAction(ISD::CTPOP, MVT::i8, Custom); |
| 240 | setOperationAction(ISD::CTPOP, MVT::i16, Custom); |
| 241 | setOperationAction(ISD::CTPOP, MVT::i32, Custom); |
| 242 | setOperationAction(ISD::CTPOP, MVT::i64, Custom); |
| 243 | |
| 244 | setOperationAction(ISD::CTTZ , MVT::i32, Expand); |
| 245 | setOperationAction(ISD::CTTZ , MVT::i64, Expand); |
| 246 | |
| 247 | setOperationAction(ISD::CTLZ , MVT::i32, Legal); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 248 | |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 249 | // SPU has a version of select that implements (a&~c)|(b&c), just like |
Scott Michel | 405fba1 | 2008-03-10 23:49:09 +0000 | [diff] [blame] | 250 | // select ought to work: |
Scott Michel | 78c47fa | 2008-03-10 16:58:52 +0000 | [diff] [blame] | 251 | setOperationAction(ISD::SELECT, MVT::i1, Promote); |
| 252 | setOperationAction(ISD::SELECT, MVT::i8, Legal); |
Scott Michel | ad2715e | 2008-03-05 23:02:02 +0000 | [diff] [blame] | 253 | setOperationAction(ISD::SELECT, MVT::i16, Legal); |
| 254 | setOperationAction(ISD::SELECT, MVT::i32, Legal); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 255 | setOperationAction(ISD::SELECT, MVT::i64, Expand); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 256 | |
Scott Michel | 78c47fa | 2008-03-10 16:58:52 +0000 | [diff] [blame] | 257 | setOperationAction(ISD::SETCC, MVT::i1, Promote); |
| 258 | setOperationAction(ISD::SETCC, MVT::i8, Legal); |
| 259 | setOperationAction(ISD::SETCC, MVT::i16, Legal); |
| 260 | setOperationAction(ISD::SETCC, MVT::i32, Legal); |
| 261 | setOperationAction(ISD::SETCC, MVT::i64, Expand); |
Scott Michel | ad2715e | 2008-03-05 23:02:02 +0000 | [diff] [blame] | 262 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 263 | // Zero extension and sign extension for i64 have to be |
| 264 | // custom legalized |
| 265 | setOperationAction(ISD::ZERO_EXTEND, MVT::i64, Custom); |
| 266 | setOperationAction(ISD::SIGN_EXTEND, MVT::i64, Custom); |
| 267 | setOperationAction(ISD::ANY_EXTEND, MVT::i64, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 268 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 269 | // SPU has a legal FP -> signed INT instruction |
| 270 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Legal); |
| 271 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); |
| 272 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Legal); |
| 273 | setOperationAction(ISD::FP_TO_UINT, MVT::i64, Custom); |
| 274 | |
| 275 | // FDIV on SPU requires custom lowering |
| 276 | setOperationAction(ISD::FDIV, MVT::f32, Custom); |
| 277 | //setOperationAction(ISD::FDIV, MVT::f64, Custom); |
| 278 | |
| 279 | // SPU has [U|S]INT_TO_FP |
| 280 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Legal); |
| 281 | setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote); |
| 282 | setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote); |
| 283 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Legal); |
| 284 | setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote); |
| 285 | setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote); |
| 286 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); |
| 287 | setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom); |
| 288 | |
Scott Michel | 86c041f | 2007-12-20 00:44:13 +0000 | [diff] [blame] | 289 | setOperationAction(ISD::BIT_CONVERT, MVT::i32, Legal); |
| 290 | setOperationAction(ISD::BIT_CONVERT, MVT::f32, Legal); |
| 291 | setOperationAction(ISD::BIT_CONVERT, MVT::i64, Legal); |
| 292 | setOperationAction(ISD::BIT_CONVERT, MVT::f64, Legal); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 293 | |
| 294 | // We cannot sextinreg(i1). Expand to shifts. |
| 295 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 296 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 297 | // Support label based line numbers. |
Dan Gohman | 7f46020 | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 298 | setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 299 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 300 | |
| 301 | // We want to legalize GlobalAddress and ConstantPool nodes into the |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 302 | // appropriate instructions to materialize the address. |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 303 | for (unsigned sctype = (unsigned) MVT::i1; sctype < (unsigned) MVT::f128; |
| 304 | ++sctype) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 305 | MVT VT = (MVT::SimpleValueType)sctype; |
| 306 | |
| 307 | setOperationAction(ISD::GlobalAddress, VT, Custom); |
| 308 | setOperationAction(ISD::ConstantPool, VT, Custom); |
| 309 | setOperationAction(ISD::JumpTable, VT, Custom); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 310 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 311 | |
| 312 | // RET must be custom lowered, to meet ABI requirements |
| 313 | setOperationAction(ISD::RET, MVT::Other, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 314 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 315 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex |
| 316 | setOperationAction(ISD::VASTART , MVT::Other, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 317 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 318 | // Use the default implementation. |
| 319 | setOperationAction(ISD::VAARG , MVT::Other, Expand); |
| 320 | setOperationAction(ISD::VACOPY , MVT::Other, Expand); |
| 321 | setOperationAction(ISD::VAEND , MVT::Other, Expand); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 322 | setOperationAction(ISD::STACKSAVE , MVT::Other, Expand); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 323 | setOperationAction(ISD::STACKRESTORE , MVT::Other, Expand); |
| 324 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand); |
| 325 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64 , Expand); |
| 326 | |
| 327 | // Cell SPU has instructions for converting between i64 and fp. |
| 328 | setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom); |
| 329 | setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 330 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 331 | // To take advantage of the above i64 FP_TO_SINT, promote i32 FP_TO_UINT |
| 332 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Promote); |
| 333 | |
| 334 | // BUILD_PAIR can't be handled natively, and should be expanded to shl/or |
| 335 | setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand); |
| 336 | |
| 337 | // First set operation action for all vector types to expand. Then we |
| 338 | // will selectively turn on ones that can be effectively codegen'd. |
| 339 | addRegisterClass(MVT::v16i8, SPU::VECREGRegisterClass); |
| 340 | addRegisterClass(MVT::v8i16, SPU::VECREGRegisterClass); |
| 341 | addRegisterClass(MVT::v4i32, SPU::VECREGRegisterClass); |
| 342 | addRegisterClass(MVT::v2i64, SPU::VECREGRegisterClass); |
| 343 | addRegisterClass(MVT::v4f32, SPU::VECREGRegisterClass); |
| 344 | addRegisterClass(MVT::v2f64, SPU::VECREGRegisterClass); |
| 345 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 346 | for (unsigned i = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 347 | i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) { |
| 348 | MVT VT = (MVT::SimpleValueType)i; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 349 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 350 | // add/sub are legal for all supported vector VT's. |
| 351 | setOperationAction(ISD::ADD , VT, Legal); |
| 352 | setOperationAction(ISD::SUB , VT, Legal); |
| 353 | // mul has to be custom lowered. |
| 354 | setOperationAction(ISD::MUL , VT, Custom); |
| 355 | |
| 356 | setOperationAction(ISD::AND , VT, Legal); |
| 357 | setOperationAction(ISD::OR , VT, Legal); |
| 358 | setOperationAction(ISD::XOR , VT, Legal); |
| 359 | setOperationAction(ISD::LOAD , VT, Legal); |
| 360 | setOperationAction(ISD::SELECT, VT, Legal); |
| 361 | setOperationAction(ISD::STORE, VT, Legal); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 362 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 363 | // These operations need to be expanded: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 364 | setOperationAction(ISD::SDIV, VT, Expand); |
| 365 | setOperationAction(ISD::SREM, VT, Expand); |
| 366 | setOperationAction(ISD::UDIV, VT, Expand); |
| 367 | setOperationAction(ISD::UREM, VT, Expand); |
| 368 | setOperationAction(ISD::FDIV, VT, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 369 | |
| 370 | // Custom lower build_vector, constant pool spills, insert and |
| 371 | // extract vector elements: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 372 | setOperationAction(ISD::BUILD_VECTOR, VT, Custom); |
| 373 | setOperationAction(ISD::ConstantPool, VT, Custom); |
| 374 | setOperationAction(ISD::SCALAR_TO_VECTOR, VT, Custom); |
| 375 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom); |
| 376 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom); |
| 377 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | setOperationAction(ISD::MUL, MVT::v16i8, Custom); |
| 381 | setOperationAction(ISD::AND, MVT::v16i8, Custom); |
| 382 | setOperationAction(ISD::OR, MVT::v16i8, Custom); |
| 383 | setOperationAction(ISD::XOR, MVT::v16i8, Custom); |
| 384 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Custom); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 385 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 386 | setShiftAmountType(MVT::i32); |
| 387 | setSetCCResultContents(ZeroOrOneSetCCResult); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 388 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 389 | setStackPointerRegisterToSaveRestore(SPU::R1); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 390 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 391 | // We have target-specific dag combine patterns for the following nodes: |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 392 | setTargetDAGCombine(ISD::ADD); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 393 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 394 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 395 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 396 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 397 | computeRegisterProperties(); |
| 398 | } |
| 399 | |
| 400 | const char * |
| 401 | SPUTargetLowering::getTargetNodeName(unsigned Opcode) const |
| 402 | { |
| 403 | if (node_names.empty()) { |
| 404 | node_names[(unsigned) SPUISD::RET_FLAG] = "SPUISD::RET_FLAG"; |
| 405 | node_names[(unsigned) SPUISD::Hi] = "SPUISD::Hi"; |
| 406 | node_names[(unsigned) SPUISD::Lo] = "SPUISD::Lo"; |
| 407 | node_names[(unsigned) SPUISD::PCRelAddr] = "SPUISD::PCRelAddr"; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 408 | node_names[(unsigned) SPUISD::AFormAddr] = "SPUISD::AFormAddr"; |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 409 | node_names[(unsigned) SPUISD::IndirectAddr] = "SPUISD::IndirectAddr"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 410 | node_names[(unsigned) SPUISD::LDRESULT] = "SPUISD::LDRESULT"; |
| 411 | node_names[(unsigned) SPUISD::CALL] = "SPUISD::CALL"; |
| 412 | node_names[(unsigned) SPUISD::SHUFB] = "SPUISD::SHUFB"; |
| 413 | node_names[(unsigned) SPUISD::INSERT_MASK] = "SPUISD::INSERT_MASK"; |
| 414 | node_names[(unsigned) SPUISD::CNTB] = "SPUISD::CNTB"; |
| 415 | node_names[(unsigned) SPUISD::PROMOTE_SCALAR] = "SPUISD::PROMOTE_SCALAR"; |
| 416 | node_names[(unsigned) SPUISD::EXTRACT_ELT0] = "SPUISD::EXTRACT_ELT0"; |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 417 | node_names[(unsigned) SPUISD::EXTRACT_ELT0_CHAINED] |
| 418 | = "SPUISD::EXTRACT_ELT0_CHAINED"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 419 | node_names[(unsigned) SPUISD::EXTRACT_I1_ZEXT] = "SPUISD::EXTRACT_I1_ZEXT"; |
| 420 | node_names[(unsigned) SPUISD::EXTRACT_I1_SEXT] = "SPUISD::EXTRACT_I1_SEXT"; |
| 421 | node_names[(unsigned) SPUISD::EXTRACT_I8_ZEXT] = "SPUISD::EXTRACT_I8_ZEXT"; |
| 422 | node_names[(unsigned) SPUISD::EXTRACT_I8_SEXT] = "SPUISD::EXTRACT_I8_SEXT"; |
| 423 | node_names[(unsigned) SPUISD::MPY] = "SPUISD::MPY"; |
| 424 | node_names[(unsigned) SPUISD::MPYU] = "SPUISD::MPYU"; |
| 425 | node_names[(unsigned) SPUISD::MPYH] = "SPUISD::MPYH"; |
| 426 | node_names[(unsigned) SPUISD::MPYHH] = "SPUISD::MPYHH"; |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 427 | node_names[(unsigned) SPUISD::SHLQUAD_L_BITS] = "SPUISD::SHLQUAD_L_BITS"; |
| 428 | node_names[(unsigned) SPUISD::SHLQUAD_L_BYTES] = "SPUISD::SHLQUAD_L_BYTES"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 429 | node_names[(unsigned) SPUISD::VEC_SHL] = "SPUISD::VEC_SHL"; |
| 430 | node_names[(unsigned) SPUISD::VEC_SRL] = "SPUISD::VEC_SRL"; |
| 431 | node_names[(unsigned) SPUISD::VEC_SRA] = "SPUISD::VEC_SRA"; |
| 432 | node_names[(unsigned) SPUISD::VEC_ROTL] = "SPUISD::VEC_ROTL"; |
| 433 | node_names[(unsigned) SPUISD::VEC_ROTR] = "SPUISD::VEC_ROTR"; |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 434 | node_names[(unsigned) SPUISD::ROTQUAD_RZ_BYTES] = |
| 435 | "SPUISD::ROTQUAD_RZ_BYTES"; |
| 436 | node_names[(unsigned) SPUISD::ROTQUAD_RZ_BITS] = |
| 437 | "SPUISD::ROTQUAD_RZ_BITS"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 438 | node_names[(unsigned) SPUISD::ROTBYTES_RIGHT_S] = |
| 439 | "SPUISD::ROTBYTES_RIGHT_S"; |
| 440 | node_names[(unsigned) SPUISD::ROTBYTES_LEFT] = "SPUISD::ROTBYTES_LEFT"; |
| 441 | node_names[(unsigned) SPUISD::ROTBYTES_LEFT_CHAINED] = |
| 442 | "SPUISD::ROTBYTES_LEFT_CHAINED"; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 443 | node_names[(unsigned) SPUISD::ROTBYTES_LEFT_BITS] = |
| 444 | "SPUISD::ROTBYTES_LEFT_BITS"; |
| 445 | node_names[(unsigned) SPUISD::SELECT_MASK] = "SPUISD::SELECT_MASK"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 446 | node_names[(unsigned) SPUISD::SELB] = "SPUISD::SELB"; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 447 | node_names[(unsigned) SPUISD::ADD_EXTENDED] = "SPUISD::ADD_EXTENDED"; |
| 448 | node_names[(unsigned) SPUISD::CARRY_GENERATE] = "SPUISD::CARRY_GENERATE"; |
| 449 | node_names[(unsigned) SPUISD::SUB_EXTENDED] = "SPUISD::SUB_EXTENDED"; |
| 450 | node_names[(unsigned) SPUISD::BORROW_GENERATE] = "SPUISD::BORROW_GENERATE"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 451 | node_names[(unsigned) SPUISD::FPInterp] = "SPUISD::FPInterp"; |
| 452 | node_names[(unsigned) SPUISD::FPRecipEst] = "SPUISD::FPRecipEst"; |
| 453 | node_names[(unsigned) SPUISD::SEXT32TO64] = "SPUISD::SEXT32TO64"; |
| 454 | } |
| 455 | |
| 456 | std::map<unsigned, const char *>::iterator i = node_names.find(Opcode); |
| 457 | |
| 458 | return ((i != node_names.end()) ? i->second : 0); |
| 459 | } |
| 460 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 461 | MVT SPUTargetLowering::getSetCCResultType(const SDValue &Op) const { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 462 | MVT VT = Op.getValueType(); |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 463 | return (VT.isInteger() ? VT : MVT(MVT::i32)); |
Scott Michel | 78c47fa | 2008-03-10 16:58:52 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 466 | //===----------------------------------------------------------------------===// |
| 467 | // Calling convention code: |
| 468 | //===----------------------------------------------------------------------===// |
| 469 | |
| 470 | #include "SPUGenCallingConv.inc" |
| 471 | |
| 472 | //===----------------------------------------------------------------------===// |
| 473 | // LowerOperation implementation |
| 474 | //===----------------------------------------------------------------------===// |
| 475 | |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 476 | /// Aligned load common code for CellSPU |
| 477 | /*! |
| 478 | \param[in] Op The SelectionDAG load or store operand |
| 479 | \param[in] DAG The selection DAG |
| 480 | \param[in] ST CellSPU subtarget information structure |
| 481 | \param[in,out] alignment Caller initializes this to the load or store node's |
| 482 | value from getAlignment(), may be updated while generating the aligned load |
| 483 | \param[in,out] alignOffs Aligned offset; set by AlignedLoad to the aligned |
| 484 | offset (divisible by 16, modulo 16 == 0) |
| 485 | \param[in,out] prefSlotOffs Preferred slot offset; set by AlignedLoad to the |
| 486 | offset of the preferred slot (modulo 16 != 0) |
| 487 | \param[in,out] VT Caller initializes this value type to the the load or store |
| 488 | node's loaded or stored value type; may be updated if an i1-extended load or |
| 489 | store. |
| 490 | \param[out] was16aligned true if the base pointer had 16-byte alignment, |
| 491 | otherwise false. Can help to determine if the chunk needs to be rotated. |
| 492 | |
| 493 | Both load and store lowering load a block of data aligned on a 16-byte |
| 494 | boundary. This is the common aligned load code shared between both. |
| 495 | */ |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 496 | static SDValue |
| 497 | AlignedLoad(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST, |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 498 | LSBaseSDNode *LSN, |
| 499 | unsigned &alignment, int &alignOffs, int &prefSlotOffs, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 500 | MVT &VT, bool &was16aligned) |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 501 | { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 502 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 503 | const valtype_map_s *vtm = getValueTypeMapEntry(VT); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 504 | SDValue basePtr = LSN->getBasePtr(); |
| 505 | SDValue chain = LSN->getChain(); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 506 | |
| 507 | if (basePtr.getOpcode() == ISD::ADD) { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 508 | SDValue Op1 = basePtr.getNode()->getOperand(1); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 509 | |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 510 | if (Op1.getOpcode() == ISD::Constant |
| 511 | || Op1.getOpcode() == ISD::TargetConstant) { |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 512 | const ConstantSDNode *CN = cast<ConstantSDNode>(basePtr.getOperand(1)); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 513 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 514 | alignOffs = (int) CN->getZExtValue(); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 515 | prefSlotOffs = (int) (alignOffs & 0xf); |
| 516 | |
| 517 | // Adjust the rotation amount to ensure that the final result ends up in |
| 518 | // the preferred slot: |
| 519 | prefSlotOffs -= vtm->prefslot_byte; |
| 520 | basePtr = basePtr.getOperand(0); |
| 521 | |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 522 | // Loading from memory, can we adjust alignment? |
| 523 | if (basePtr.getOpcode() == SPUISD::AFormAddr) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 524 | SDValue APtr = basePtr.getOperand(0); |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 525 | if (APtr.getOpcode() == ISD::TargetGlobalAddress) { |
| 526 | GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(APtr); |
| 527 | alignment = GSDN->getGlobal()->getAlignment(); |
| 528 | } |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 529 | } |
| 530 | } else { |
| 531 | alignOffs = 0; |
| 532 | prefSlotOffs = -vtm->prefslot_byte; |
| 533 | } |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 534 | } else if (basePtr.getOpcode() == ISD::FrameIndex) { |
| 535 | FrameIndexSDNode *FIN = cast<FrameIndexSDNode>(basePtr); |
| 536 | alignOffs = int(FIN->getIndex() * SPUFrameInfo::stackSlotSize()); |
| 537 | prefSlotOffs = (int) (alignOffs & 0xf); |
| 538 | prefSlotOffs -= vtm->prefslot_byte; |
| 539 | basePtr = DAG.getRegister(SPU::R1, VT); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 540 | } else { |
| 541 | alignOffs = 0; |
| 542 | prefSlotOffs = -vtm->prefslot_byte; |
| 543 | } |
| 544 | |
| 545 | if (alignment == 16) { |
| 546 | // Realign the base pointer as a D-Form address: |
| 547 | if (!isMemoryOperand(basePtr) || (alignOffs & ~0xf) != 0) { |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 548 | basePtr = DAG.getNode(ISD::ADD, PtrVT, |
| 549 | basePtr, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 550 | DAG.getConstant((alignOffs & ~0xf), PtrVT)); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | // Emit the vector load: |
| 554 | was16aligned = true; |
| 555 | return DAG.getLoad(MVT::v16i8, chain, basePtr, |
| 556 | LSN->getSrcValue(), LSN->getSrcValueOffset(), |
| 557 | LSN->isVolatile(), 16); |
| 558 | } |
| 559 | |
| 560 | // Unaligned load or we're using the "large memory" model, which means that |
| 561 | // we have to be very pessimistic: |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 562 | if (isMemoryOperand(basePtr) || isIndirectOperand(basePtr)) { |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 563 | basePtr = DAG.getNode(SPUISD::IndirectAddr, PtrVT, basePtr, |
| 564 | DAG.getConstant(0, PtrVT)); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | // Add the offset |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 568 | basePtr = DAG.getNode(ISD::ADD, PtrVT, basePtr, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 569 | DAG.getConstant((alignOffs & ~0xf), PtrVT)); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 570 | was16aligned = false; |
| 571 | return DAG.getLoad(MVT::v16i8, chain, basePtr, |
| 572 | LSN->getSrcValue(), LSN->getSrcValueOffset(), |
| 573 | LSN->isVolatile(), 16); |
| 574 | } |
| 575 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 576 | /// Custom lower loads for CellSPU |
| 577 | /*! |
| 578 | All CellSPU loads and stores are aligned to 16-byte boundaries, so for elements |
| 579 | within a 16-byte block, we have to rotate to extract the requested element. |
| 580 | */ |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 581 | static SDValue |
| 582 | LowerLOAD(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 583 | LoadSDNode *LN = cast<LoadSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 584 | SDValue the_chain = LN->getChain(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 585 | MVT VT = LN->getMemoryVT(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 586 | MVT OpVT = Op.getNode()->getValueType(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 587 | ISD::LoadExtType ExtType = LN->getExtensionType(); |
| 588 | unsigned alignment = LN->getAlignment(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 589 | SDValue Ops[8]; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 590 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 591 | switch (LN->getAddressingMode()) { |
| 592 | case ISD::UNINDEXED: { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 593 | int offset, rotamt; |
| 594 | bool was16aligned; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 595 | SDValue result = |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 596 | AlignedLoad(Op, DAG, ST, LN,alignment, offset, rotamt, VT, was16aligned); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 597 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 598 | if (result.getNode() == 0) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 599 | return result; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 600 | |
| 601 | the_chain = result.getValue(1); |
| 602 | // Rotate the chunk if necessary |
| 603 | if (rotamt < 0) |
| 604 | rotamt += 16; |
Scott Michel | 497e888 | 2008-01-11 21:01:19 +0000 | [diff] [blame] | 605 | if (rotamt != 0 || !was16aligned) { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 606 | SDVTList vecvts = DAG.getVTList(MVT::v16i8, MVT::Other); |
| 607 | |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 608 | Ops[0] = the_chain; |
| 609 | Ops[1] = result; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 610 | if (was16aligned) { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 611 | Ops[2] = DAG.getConstant(rotamt, MVT::i16); |
| 612 | } else { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 613 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 614 | LoadSDNode *LN1 = cast<LoadSDNode>(result); |
Scott Michel | 497e888 | 2008-01-11 21:01:19 +0000 | [diff] [blame] | 615 | Ops[2] = DAG.getNode(ISD::ADD, PtrVT, LN1->getBasePtr(), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 616 | DAG.getConstant(rotamt, PtrVT)); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | result = DAG.getNode(SPUISD::ROTBYTES_LEFT_CHAINED, vecvts, Ops, 3); |
| 620 | the_chain = result.getValue(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 621 | } |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 622 | |
| 623 | if (VT == OpVT || ExtType == ISD::EXTLOAD) { |
| 624 | SDVTList scalarvts; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 625 | MVT vecVT = MVT::v16i8; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 626 | |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 627 | // Convert the loaded v16i8 vector to the appropriate vector type |
| 628 | // specified by the operand: |
| 629 | if (OpVT == VT) { |
| 630 | if (VT != MVT::i1) |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 631 | vecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits())); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 632 | } else |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 633 | vecVT = MVT::getVectorVT(OpVT, (128 / OpVT.getSizeInBits())); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 634 | |
| 635 | Ops[0] = the_chain; |
| 636 | Ops[1] = DAG.getNode(ISD::BIT_CONVERT, vecVT, result); |
| 637 | scalarvts = DAG.getVTList((OpVT == VT ? VT : OpVT), MVT::Other); |
| 638 | result = DAG.getNode(SPUISD::EXTRACT_ELT0_CHAINED, scalarvts, Ops, 2); |
| 639 | the_chain = result.getValue(1); |
| 640 | } else { |
| 641 | // Handle the sign and zero-extending loads for i1 and i8: |
| 642 | unsigned NewOpC; |
| 643 | |
| 644 | if (ExtType == ISD::SEXTLOAD) { |
| 645 | NewOpC = (OpVT == MVT::i1 |
| 646 | ? SPUISD::EXTRACT_I1_SEXT |
| 647 | : SPUISD::EXTRACT_I8_SEXT); |
| 648 | } else { |
| 649 | assert(ExtType == ISD::ZEXTLOAD); |
| 650 | NewOpC = (OpVT == MVT::i1 |
| 651 | ? SPUISD::EXTRACT_I1_ZEXT |
| 652 | : SPUISD::EXTRACT_I8_ZEXT); |
| 653 | } |
| 654 | |
| 655 | result = DAG.getNode(NewOpC, OpVT, result); |
| 656 | } |
| 657 | |
| 658 | SDVTList retvts = DAG.getVTList(OpVT, MVT::Other); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 659 | SDValue retops[2] = { |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 660 | result, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 661 | the_chain |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 662 | }; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 663 | |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 664 | result = DAG.getNode(SPUISD::LDRESULT, retvts, |
| 665 | retops, sizeof(retops) / sizeof(retops[0])); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 666 | return result; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 667 | } |
| 668 | case ISD::PRE_INC: |
| 669 | case ISD::PRE_DEC: |
| 670 | case ISD::POST_INC: |
| 671 | case ISD::POST_DEC: |
| 672 | case ISD::LAST_INDEXED_MODE: |
| 673 | cerr << "LowerLOAD: Got a LoadSDNode with an addr mode other than " |
| 674 | "UNINDEXED\n"; |
| 675 | cerr << (unsigned) LN->getAddressingMode() << "\n"; |
| 676 | abort(); |
| 677 | /*NOTREACHED*/ |
| 678 | } |
| 679 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 680 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | /// Custom lower stores for CellSPU |
| 684 | /*! |
| 685 | All CellSPU stores are aligned to 16-byte boundaries, so for elements |
| 686 | within a 16-byte block, we have to generate a shuffle to insert the |
| 687 | requested element into its place, then store the resulting block. |
| 688 | */ |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 689 | static SDValue |
| 690 | LowerSTORE(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 691 | StoreSDNode *SN = cast<StoreSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 692 | SDValue Value = SN->getValue(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 693 | MVT VT = Value.getValueType(); |
| 694 | MVT StVT = (!SN->isTruncatingStore() ? VT : SN->getMemoryVT()); |
| 695 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 696 | unsigned alignment = SN->getAlignment(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 697 | |
| 698 | switch (SN->getAddressingMode()) { |
| 699 | case ISD::UNINDEXED: { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 700 | int chunk_offset, slot_offset; |
| 701 | bool was16aligned; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 702 | |
| 703 | // The vector type we really want to load from the 16-byte chunk, except |
| 704 | // in the case of MVT::i1, which has to be v16i8. |
Scott Michel | 719b0e1 | 2008-11-19 17:45:08 +0000 | [diff] [blame] | 705 | MVT vecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits())), |
| 706 | stVecVT = MVT::getVectorVT(StVT, (128 / StVT.getSizeInBits())); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 707 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 708 | SDValue alignLoadVec = |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 709 | AlignedLoad(Op, DAG, ST, SN, alignment, |
| 710 | chunk_offset, slot_offset, VT, was16aligned); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 711 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 712 | if (alignLoadVec.getNode() == 0) |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 713 | return alignLoadVec; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 714 | |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 715 | LoadSDNode *LN = cast<LoadSDNode>(alignLoadVec); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 716 | SDValue basePtr = LN->getBasePtr(); |
| 717 | SDValue the_chain = alignLoadVec.getValue(1); |
| 718 | SDValue theValue = SN->getValue(); |
| 719 | SDValue result; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 720 | |
| 721 | if (StVT != VT |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 722 | && (theValue.getOpcode() == ISD::AssertZext |
| 723 | || theValue.getOpcode() == ISD::AssertSext)) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 724 | // Drill down and get the value for zero- and sign-extended |
| 725 | // quantities |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 726 | theValue = theValue.getOperand(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 729 | chunk_offset &= 0xf; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 730 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 731 | SDValue insertEltOffs = DAG.getConstant(chunk_offset, PtrVT); |
| 732 | SDValue insertEltPtr; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 733 | |
| 734 | // If the base pointer is already a D-form address, then just create |
| 735 | // a new D-form address with a slot offset and the orignal base pointer. |
| 736 | // Otherwise generate a D-form address with the slot offset relative |
| 737 | // to the stack pointer, which is always aligned. |
Scott Michel | 497e888 | 2008-01-11 21:01:19 +0000 | [diff] [blame] | 738 | DEBUG(cerr << "CellSPU LowerSTORE: basePtr = "); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 739 | DEBUG(basePtr.getNode()->dump(&DAG)); |
Scott Michel | 497e888 | 2008-01-11 21:01:19 +0000 | [diff] [blame] | 740 | DEBUG(cerr << "\n"); |
| 741 | |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 742 | if (basePtr.getOpcode() == SPUISD::IndirectAddr || |
| 743 | (basePtr.getOpcode() == ISD::ADD |
| 744 | && basePtr.getOperand(0).getOpcode() == SPUISD::IndirectAddr)) { |
Scott Michel | 497e888 | 2008-01-11 21:01:19 +0000 | [diff] [blame] | 745 | insertEltPtr = basePtr; |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 746 | } else { |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 747 | insertEltPtr = DAG.getNode(ISD::ADD, PtrVT, basePtr, insertEltOffs); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Scott Michel | 430a555 | 2008-11-19 15:24:16 +0000 | [diff] [blame] | 750 | SDValue insertEltOp = |
| 751 | DAG.getNode(SPUISD::INSERT_MASK, stVecVT, insertEltPtr); |
Scott Michel | 719b0e1 | 2008-11-19 17:45:08 +0000 | [diff] [blame] | 752 | SDValue vectorizeOp = |
| 753 | DAG.getNode(ISD::SCALAR_TO_VECTOR, vecVT, theValue); |
Scott Michel | 430a555 | 2008-11-19 15:24:16 +0000 | [diff] [blame] | 754 | |
| 755 | result = DAG.getNode(SPUISD::SHUFB, vecVT, vectorizeOp, alignLoadVec, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 756 | DAG.getNode(ISD::BIT_CONVERT, vecVT, insertEltOp)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 757 | |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 758 | result = DAG.getStore(the_chain, result, basePtr, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 759 | LN->getSrcValue(), LN->getSrcValueOffset(), |
| 760 | LN->isVolatile(), LN->getAlignment()); |
| 761 | |
Scott Michel | 719b0e1 | 2008-11-19 17:45:08 +0000 | [diff] [blame] | 762 | #if 0 && defined(NDEBUG) |
Scott Michel | 430a555 | 2008-11-19 15:24:16 +0000 | [diff] [blame] | 763 | if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { |
| 764 | const SDValue ¤tRoot = DAG.getRoot(); |
| 765 | |
| 766 | DAG.setRoot(result); |
| 767 | cerr << "------- CellSPU:LowerStore result:\n"; |
| 768 | DAG.dump(); |
| 769 | cerr << "-------\n"; |
| 770 | DAG.setRoot(currentRoot); |
| 771 | } |
| 772 | #endif |
| 773 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 774 | return result; |
| 775 | /*UNREACHED*/ |
| 776 | } |
| 777 | case ISD::PRE_INC: |
| 778 | case ISD::PRE_DEC: |
| 779 | case ISD::POST_INC: |
| 780 | case ISD::POST_DEC: |
| 781 | case ISD::LAST_INDEXED_MODE: |
| 782 | cerr << "LowerLOAD: Got a LoadSDNode with an addr mode other than " |
| 783 | "UNINDEXED\n"; |
| 784 | cerr << (unsigned) SN->getAddressingMode() << "\n"; |
| 785 | abort(); |
| 786 | /*NOTREACHED*/ |
| 787 | } |
| 788 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 789 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | /// Generate the address of a constant pool entry. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 793 | static SDValue |
| 794 | LowerConstantPool(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 795 | MVT PtrVT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 796 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| 797 | Constant *C = CP->getConstVal(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 798 | SDValue CPI = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment()); |
| 799 | SDValue Zero = DAG.getConstant(0, PtrVT); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 800 | const TargetMachine &TM = DAG.getTarget(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 801 | |
| 802 | if (TM.getRelocationModel() == Reloc::Static) { |
| 803 | if (!ST->usingLargeMem()) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 804 | // Just return the SDValue with the constant pool address in it. |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 805 | return DAG.getNode(SPUISD::AFormAddr, PtrVT, CPI, Zero); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 806 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 807 | SDValue Hi = DAG.getNode(SPUISD::Hi, PtrVT, CPI, Zero); |
| 808 | SDValue Lo = DAG.getNode(SPUISD::Lo, PtrVT, CPI, Zero); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 809 | return DAG.getNode(SPUISD::IndirectAddr, PtrVT, Hi, Lo); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | |
| 813 | assert(0 && |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 814 | "LowerConstantPool: Relocation model other than static" |
| 815 | " not supported."); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 816 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 819 | static SDValue |
| 820 | LowerJumpTable(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 821 | MVT PtrVT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 822 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 823 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT); |
| 824 | SDValue Zero = DAG.getConstant(0, PtrVT); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 825 | const TargetMachine &TM = DAG.getTarget(); |
| 826 | |
| 827 | if (TM.getRelocationModel() == Reloc::Static) { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 828 | if (!ST->usingLargeMem()) { |
| 829 | return DAG.getNode(SPUISD::AFormAddr, PtrVT, JTI, Zero); |
| 830 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 831 | SDValue Hi = DAG.getNode(SPUISD::Hi, PtrVT, JTI, Zero); |
| 832 | SDValue Lo = DAG.getNode(SPUISD::Lo, PtrVT, JTI, Zero); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 833 | return DAG.getNode(SPUISD::IndirectAddr, PtrVT, Hi, Lo); |
| 834 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | assert(0 && |
| 838 | "LowerJumpTable: Relocation model other than static not supported."); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 839 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 842 | static SDValue |
| 843 | LowerGlobalAddress(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 844 | MVT PtrVT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 845 | GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); |
| 846 | GlobalValue *GV = GSDN->getGlobal(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 847 | SDValue GA = DAG.getTargetGlobalAddress(GV, PtrVT, GSDN->getOffset()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 848 | const TargetMachine &TM = DAG.getTarget(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 849 | SDValue Zero = DAG.getConstant(0, PtrVT); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 850 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 851 | if (TM.getRelocationModel() == Reloc::Static) { |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 852 | if (!ST->usingLargeMem()) { |
| 853 | return DAG.getNode(SPUISD::AFormAddr, PtrVT, GA, Zero); |
| 854 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 855 | SDValue Hi = DAG.getNode(SPUISD::Hi, PtrVT, GA, Zero); |
| 856 | SDValue Lo = DAG.getNode(SPUISD::Lo, PtrVT, GA, Zero); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 857 | return DAG.getNode(SPUISD::IndirectAddr, PtrVT, Hi, Lo); |
| 858 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 859 | } else { |
| 860 | cerr << "LowerGlobalAddress: Relocation model other than static not " |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 861 | << "supported.\n"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 862 | abort(); |
| 863 | /*NOTREACHED*/ |
| 864 | } |
| 865 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 866 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | //! Custom lower i64 integer constants |
| 870 | /*! |
| 871 | This code inserts all of the necessary juggling that needs to occur to load |
| 872 | a 64-bit constant into a register. |
| 873 | */ |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 874 | static SDValue |
| 875 | LowerConstant(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 876 | MVT VT = Op.getValueType(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 877 | ConstantSDNode *CN = cast<ConstantSDNode>(Op.getNode()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 878 | |
| 879 | if (VT == MVT::i64) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 880 | SDValue T = DAG.getConstant(CN->getZExtValue(), MVT::i64); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 881 | return DAG.getNode(SPUISD::EXTRACT_ELT0, VT, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 882 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v2i64, T, T)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 883 | } else { |
| 884 | cerr << "LowerConstant: unhandled constant type " |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 885 | << VT.getMVTString() |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 886 | << "\n"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 887 | abort(); |
| 888 | /*NOTREACHED*/ |
| 889 | } |
| 890 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 891 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Nate Begeman | ccef580 | 2008-02-14 18:43:04 +0000 | [diff] [blame] | 894 | //! Custom lower double precision floating point constants |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 895 | static SDValue |
| 896 | LowerConstantFP(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 897 | MVT VT = Op.getValueType(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 898 | ConstantFPSDNode *FP = cast<ConstantFPSDNode>(Op.getNode()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 899 | |
| 900 | assert((FP != 0) && |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 901 | "LowerConstantFP: Node is not ConstantFPSDNode"); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 902 | |
Nate Begeman | ccef580 | 2008-02-14 18:43:04 +0000 | [diff] [blame] | 903 | if (VT == MVT::f64) { |
Scott Michel | 170783a | 2007-12-19 20:15:47 +0000 | [diff] [blame] | 904 | uint64_t dbits = DoubleToBits(FP->getValueAPF().convertToDouble()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 905 | return DAG.getNode(ISD::BIT_CONVERT, VT, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 906 | LowerConstant(DAG.getConstant(dbits, MVT::i64), DAG)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 909 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 912 | //! Lower MVT::i1, MVT::i8 brcond to a promoted type (MVT::i32, MVT::i16) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 913 | static SDValue |
| 914 | LowerBRCOND(SDValue Op, SelectionDAG &DAG) |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 915 | { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 916 | SDValue Cond = Op.getOperand(1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 917 | MVT CondVT = Cond.getValueType(); |
| 918 | MVT CondNVT; |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 919 | |
| 920 | if (CondVT == MVT::i1 || CondVT == MVT::i8) { |
| 921 | CondNVT = (CondVT == MVT::i1 ? MVT::i32 : MVT::i16); |
| 922 | return DAG.getNode(ISD::BRCOND, Op.getValueType(), |
| 923 | Op.getOperand(0), |
| 924 | DAG.getNode(ISD::ZERO_EXTEND, CondNVT, Op.getOperand(1)), |
| 925 | Op.getOperand(2)); |
| 926 | } else |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 927 | return SDValue(); // Unchanged |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 930 | static SDValue |
| 931 | LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG, int &VarArgsFrameIndex) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 932 | { |
| 933 | MachineFunction &MF = DAG.getMachineFunction(); |
| 934 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 935 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 936 | SmallVector<SDValue, 48> ArgValues; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 937 | SDValue Root = Op.getOperand(0); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 938 | bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() != 0; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 939 | |
| 940 | const unsigned *ArgRegs = SPURegisterInfo::getArgRegs(); |
| 941 | const unsigned NumArgRegs = SPURegisterInfo::getNumArgRegs(); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 942 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 943 | unsigned ArgOffset = SPUFrameInfo::minStackSize(); |
| 944 | unsigned ArgRegIdx = 0; |
| 945 | unsigned StackSlotSize = SPUFrameInfo::stackSlotSize(); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 946 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 947 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 948 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 949 | // Add DAG nodes to load the arguments or copy them out of registers. |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 950 | for (unsigned ArgNo = 0, e = Op.getNode()->getNumValues() - 1; |
| 951 | ArgNo != e; ++ArgNo) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 952 | MVT ObjectVT = Op.getValue(ArgNo).getValueType(); |
| 953 | unsigned ObjSize = ObjectVT.getSizeInBits()/8; |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 954 | SDValue ArgVal; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 955 | |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 956 | if (ArgRegIdx < NumArgRegs) { |
| 957 | const TargetRegisterClass *ArgRegClass; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 958 | |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 959 | switch (ObjectVT.getSimpleVT()) { |
| 960 | default: { |
| 961 | cerr << "LowerFORMAL_ARGUMENTS Unhandled argument type: " |
| 962 | << ObjectVT.getMVTString() |
| 963 | << "\n"; |
| 964 | abort(); |
| 965 | } |
| 966 | case MVT::i8: |
| 967 | ArgRegClass = &SPU::R8CRegClass; |
| 968 | break; |
| 969 | case MVT::i16: |
| 970 | ArgRegClass = &SPU::R16CRegClass; |
| 971 | break; |
| 972 | case MVT::i32: |
| 973 | ArgRegClass = &SPU::R32CRegClass; |
| 974 | break; |
| 975 | case MVT::i64: |
| 976 | ArgRegClass = &SPU::R64CRegClass; |
| 977 | break; |
| 978 | case MVT::f32: |
| 979 | ArgRegClass = &SPU::R32FPRegClass; |
| 980 | break; |
| 981 | case MVT::f64: |
| 982 | ArgRegClass = &SPU::R64FPRegClass; |
| 983 | break; |
| 984 | case MVT::v2f64: |
| 985 | case MVT::v4f32: |
| 986 | case MVT::v2i64: |
| 987 | case MVT::v4i32: |
| 988 | case MVT::v8i16: |
| 989 | case MVT::v16i8: |
| 990 | ArgRegClass = &SPU::VECREGRegClass; |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 991 | break; |
| 992 | } |
| 993 | |
| 994 | unsigned VReg = RegInfo.createVirtualRegister(ArgRegClass); |
| 995 | RegInfo.addLiveIn(ArgRegs[ArgRegIdx], VReg); |
| 996 | ArgVal = DAG.getCopyFromReg(Root, VReg, ObjectVT); |
| 997 | ++ArgRegIdx; |
| 998 | } else { |
| 999 | // We need to load the argument to a virtual register if we determined |
| 1000 | // above that we ran out of physical registers of the appropriate type |
| 1001 | // or we're forced to do vararg |
Chris Lattner | 9f72d1a | 2008-02-13 07:35:30 +0000 | [diff] [blame] | 1002 | int FI = MFI->CreateFixedObject(ObjSize, ArgOffset); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1003 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); |
Chris Lattner | 9f72d1a | 2008-02-13 07:35:30 +0000 | [diff] [blame] | 1004 | ArgVal = DAG.getLoad(ObjectVT, Root, FIN, NULL, 0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1005 | ArgOffset += StackSlotSize; |
| 1006 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1007 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1008 | ArgValues.push_back(ArgVal); |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 1009 | // Update the chain |
| 1010 | Root = ArgVal.getOperand(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1011 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1012 | |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 1013 | // vararg handling: |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1014 | if (isVarArg) { |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 1015 | // unsigned int ptr_size = PtrVT.getSizeInBits() / 8; |
| 1016 | // We will spill (79-3)+1 registers to the stack |
| 1017 | SmallVector<SDValue, 79-3+1> MemOps; |
| 1018 | |
| 1019 | // Create the frame slot |
| 1020 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1021 | for (; ArgRegIdx != NumArgRegs; ++ArgRegIdx) { |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 1022 | VarArgsFrameIndex = MFI->CreateFixedObject(StackSlotSize, ArgOffset); |
| 1023 | SDValue FIN = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT); |
| 1024 | SDValue ArgVal = DAG.getRegister(ArgRegs[ArgRegIdx], MVT::v16i8); |
| 1025 | SDValue Store = DAG.getStore(Root, ArgVal, FIN, NULL, 0); |
| 1026 | Root = Store.getOperand(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1027 | MemOps.push_back(Store); |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 1028 | |
| 1029 | // Increment address by stack slot size for the next stored argument |
| 1030 | ArgOffset += StackSlotSize; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1031 | } |
| 1032 | if (!MemOps.empty()) |
Scott Michel | d976c21 | 2008-10-30 01:51:48 +0000 | [diff] [blame] | 1033 | Root = DAG.getNode(ISD::TokenFactor,MVT::Other,&MemOps[0],MemOps.size()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1034 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1035 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1036 | ArgValues.push_back(Root); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1037 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1038 | // Return the new list of results. |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1039 | return DAG.getMergeValues(Op.getNode()->getVTList(), &ArgValues[0], |
Duncan Sands | f951620 | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 1040 | ArgValues.size()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /// isLSAAddress - Return the immediate to use if the specified |
| 1044 | /// value is representable as a LSA address. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1045 | static SDNode *isLSAAddress(SDValue Op, SelectionDAG &DAG) { |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 1046 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1047 | if (!C) return 0; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1048 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1049 | int Addr = C->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1050 | if ((Addr & 3) != 0 || // Low 2 bits are implicitly zero. |
| 1051 | (Addr << 14 >> 14) != Addr) |
| 1052 | return 0; // Top 14 bits have to be sext of immediate. |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1053 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1054 | return DAG.getConstant((int)C->getZExtValue() >> 2, MVT::i32).getNode(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | static |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1058 | SDValue |
| 1059 | LowerCALL(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) { |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1060 | CallSDNode *TheCall = cast<CallSDNode>(Op.getNode()); |
| 1061 | SDValue Chain = TheCall->getChain(); |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1062 | SDValue Callee = TheCall->getCallee(); |
| 1063 | unsigned NumOps = TheCall->getNumArgs(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1064 | unsigned StackSlotSize = SPUFrameInfo::stackSlotSize(); |
| 1065 | const unsigned *ArgRegs = SPURegisterInfo::getArgRegs(); |
| 1066 | const unsigned NumArgRegs = SPURegisterInfo::getNumArgRegs(); |
| 1067 | |
| 1068 | // Handy pointer type |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1069 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1070 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1071 | // Accumulate how many bytes are to be pushed on the stack, including the |
| 1072 | // linkage area, and parameter passing area. According to the SPU ABI, |
| 1073 | // we minimally need space for [LR] and [SP] |
| 1074 | unsigned NumStackBytes = SPUFrameInfo::minStackSize(); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1075 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1076 | // Set up a copy of the stack pointer for use loading and storing any |
| 1077 | // arguments that may not fit in the registers available for argument |
| 1078 | // passing. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1079 | SDValue StackPtr = DAG.getRegister(SPU::R1, MVT::i32); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1080 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1081 | // Figure out which arguments are going to go in registers, and which in |
| 1082 | // memory. |
| 1083 | unsigned ArgOffset = SPUFrameInfo::minStackSize(); // Just below [LR] |
| 1084 | unsigned ArgRegIdx = 0; |
| 1085 | |
| 1086 | // Keep track of registers passing arguments |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1087 | std::vector<std::pair<unsigned, SDValue> > RegsToPass; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1088 | // And the arguments passed on the stack |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1089 | SmallVector<SDValue, 8> MemOpChains; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1090 | |
| 1091 | for (unsigned i = 0; i != NumOps; ++i) { |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1092 | SDValue Arg = TheCall->getArg(i); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1093 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1094 | // PtrOff will be used to store the current argument to the stack if a |
| 1095 | // register cannot be found for it. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1096 | SDValue PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1097 | PtrOff = DAG.getNode(ISD::ADD, PtrVT, StackPtr, PtrOff); |
| 1098 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1099 | switch (Arg.getValueType().getSimpleVT()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1100 | default: assert(0 && "Unexpected ValueType for argument!"); |
| 1101 | case MVT::i32: |
| 1102 | case MVT::i64: |
| 1103 | case MVT::i128: |
| 1104 | if (ArgRegIdx != NumArgRegs) { |
| 1105 | RegsToPass.push_back(std::make_pair(ArgRegs[ArgRegIdx++], Arg)); |
| 1106 | } else { |
| 1107 | MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0)); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1108 | ArgOffset += StackSlotSize; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1109 | } |
| 1110 | break; |
| 1111 | case MVT::f32: |
| 1112 | case MVT::f64: |
| 1113 | if (ArgRegIdx != NumArgRegs) { |
| 1114 | RegsToPass.push_back(std::make_pair(ArgRegs[ArgRegIdx++], Arg)); |
| 1115 | } else { |
| 1116 | MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0)); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1117 | ArgOffset += StackSlotSize; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1118 | } |
| 1119 | break; |
| 1120 | case MVT::v4f32: |
| 1121 | case MVT::v4i32: |
| 1122 | case MVT::v8i16: |
| 1123 | case MVT::v16i8: |
| 1124 | if (ArgRegIdx != NumArgRegs) { |
| 1125 | RegsToPass.push_back(std::make_pair(ArgRegs[ArgRegIdx++], Arg)); |
| 1126 | } else { |
| 1127 | MemOpChains.push_back(DAG.getStore(Chain, Arg, PtrOff, NULL, 0)); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1128 | ArgOffset += StackSlotSize; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1129 | } |
| 1130 | break; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | // Update number of stack bytes actually used, insert a call sequence start |
| 1135 | NumStackBytes = (ArgOffset - SPUFrameInfo::minStackSize()); |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1136 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumStackBytes, |
| 1137 | true)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1138 | |
| 1139 | if (!MemOpChains.empty()) { |
| 1140 | // Adjust the stack pointer for the stack arguments. |
| 1141 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, |
| 1142 | &MemOpChains[0], MemOpChains.size()); |
| 1143 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1144 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1145 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1146 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1147 | SDValue InFlag; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1148 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1149 | Chain = DAG.getCopyToReg(Chain, RegsToPass[i].first, RegsToPass[i].second, |
| 1150 | InFlag); |
| 1151 | InFlag = Chain.getValue(1); |
| 1152 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1153 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1154 | SmallVector<SDValue, 8> Ops; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1155 | unsigned CallOpc = SPUISD::CALL; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1156 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1157 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1158 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1159 | // node so that legalize doesn't hack it. |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 1160 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1161 | GlobalValue *GV = G->getGlobal(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1162 | MVT CalleeVT = Callee.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1163 | SDValue Zero = DAG.getConstant(0, PtrVT); |
| 1164 | SDValue GA = DAG.getTargetGlobalAddress(GV, CalleeVT); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1165 | |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 1166 | if (!ST->usingLargeMem()) { |
| 1167 | // Turn calls to targets that are defined (i.e., have bodies) into BRSL |
| 1168 | // style calls, otherwise, external symbols are BRASL calls. This assumes |
| 1169 | // that declared/defined symbols are in the same compilation unit and can |
| 1170 | // be reached through PC-relative jumps. |
| 1171 | // |
| 1172 | // NOTE: |
| 1173 | // This may be an unsafe assumption for JIT and really large compilation |
| 1174 | // units. |
| 1175 | if (GV->isDeclaration()) { |
| 1176 | Callee = DAG.getNode(SPUISD::AFormAddr, CalleeVT, GA, Zero); |
| 1177 | } else { |
| 1178 | Callee = DAG.getNode(SPUISD::PCRelAddr, CalleeVT, GA, Zero); |
| 1179 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1180 | } else { |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 1181 | // "Large memory" mode: Turn all calls into indirect calls with a X-form |
| 1182 | // address pairs: |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 1183 | Callee = DAG.getNode(SPUISD::IndirectAddr, PtrVT, GA, Zero); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1184 | } |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 1185 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1186 | Callee = DAG.getExternalSymbol(S->getSymbol(), Callee.getValueType()); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 1187 | else if (SDNode *Dest = isLSAAddress(Callee, DAG)) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1188 | // If this is an absolute destination address that appears to be a legal |
| 1189 | // local store address, use the munged value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1190 | Callee = SDValue(Dest, 0); |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 1191 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1192 | |
| 1193 | Ops.push_back(Chain); |
| 1194 | Ops.push_back(Callee); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1195 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1196 | // Add argument registers to the end of the list so that they are known live |
| 1197 | // into the call. |
| 1198 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1199 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1200 | RegsToPass[i].second.getValueType())); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1201 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1202 | if (InFlag.getNode()) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1203 | Ops.push_back(InFlag); |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1204 | // Returns a chain and a flag for retval copy to use. |
| 1205 | Chain = DAG.getNode(CallOpc, DAG.getVTList(MVT::Other, MVT::Flag), |
| 1206 | &Ops[0], Ops.size()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1207 | InFlag = Chain.getValue(1); |
| 1208 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1209 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumStackBytes, true), |
| 1210 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1211 | if (TheCall->getValueType(0) != MVT::Other) |
Evan Cheng | ebaaa91 | 2008-02-05 22:44:06 +0000 | [diff] [blame] | 1212 | InFlag = Chain.getValue(1); |
| 1213 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1214 | SDValue ResultVals[3]; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1215 | unsigned NumResults = 0; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1216 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1217 | // If the call has results, copy the values out of the ret val registers. |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1218 | switch (TheCall->getValueType(0).getSimpleVT()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1219 | default: assert(0 && "Unexpected ret value!"); |
| 1220 | case MVT::Other: break; |
| 1221 | case MVT::i32: |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1222 | if (TheCall->getValueType(1) == MVT::i32) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1223 | Chain = DAG.getCopyFromReg(Chain, SPU::R4, MVT::i32, InFlag).getValue(1); |
| 1224 | ResultVals[0] = Chain.getValue(0); |
| 1225 | Chain = DAG.getCopyFromReg(Chain, SPU::R3, MVT::i32, |
| 1226 | Chain.getValue(2)).getValue(1); |
| 1227 | ResultVals[1] = Chain.getValue(0); |
| 1228 | NumResults = 2; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1229 | } else { |
| 1230 | Chain = DAG.getCopyFromReg(Chain, SPU::R3, MVT::i32, InFlag).getValue(1); |
| 1231 | ResultVals[0] = Chain.getValue(0); |
| 1232 | NumResults = 1; |
| 1233 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1234 | break; |
| 1235 | case MVT::i64: |
| 1236 | Chain = DAG.getCopyFromReg(Chain, SPU::R3, MVT::i64, InFlag).getValue(1); |
| 1237 | ResultVals[0] = Chain.getValue(0); |
| 1238 | NumResults = 1; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1239 | break; |
| 1240 | case MVT::f32: |
| 1241 | case MVT::f64: |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1242 | Chain = DAG.getCopyFromReg(Chain, SPU::R3, TheCall->getValueType(0), |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1243 | InFlag).getValue(1); |
| 1244 | ResultVals[0] = Chain.getValue(0); |
| 1245 | NumResults = 1; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1246 | break; |
| 1247 | case MVT::v2f64: |
| 1248 | case MVT::v4f32: |
| 1249 | case MVT::v4i32: |
| 1250 | case MVT::v8i16: |
| 1251 | case MVT::v16i8: |
Dan Gohman | 095cc29 | 2008-09-13 01:54:27 +0000 | [diff] [blame] | 1252 | Chain = DAG.getCopyFromReg(Chain, SPU::R3, TheCall->getValueType(0), |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1253 | InFlag).getValue(1); |
| 1254 | ResultVals[0] = Chain.getValue(0); |
| 1255 | NumResults = 1; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1256 | break; |
| 1257 | } |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1258 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1259 | // If the function returns void, just return the chain. |
| 1260 | if (NumResults == 0) |
| 1261 | return Chain; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1262 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1263 | // Otherwise, merge everything together with a MERGE_VALUES node. |
| 1264 | ResultVals[NumResults++] = Chain; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1265 | SDValue Res = DAG.getMergeValues(ResultVals, NumResults); |
Gabor Greif | 99a6cb9 | 2008-08-26 22:36:50 +0000 | [diff] [blame] | 1266 | return Res.getValue(Op.getResNo()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1269 | static SDValue |
| 1270 | LowerRET(SDValue Op, SelectionDAG &DAG, TargetMachine &TM) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1271 | SmallVector<CCValAssign, 16> RVLocs; |
| 1272 | unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv(); |
| 1273 | bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg(); |
| 1274 | CCState CCInfo(CC, isVarArg, TM, RVLocs); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1275 | CCInfo.AnalyzeReturn(Op.getNode(), RetCC_SPU); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1276 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1277 | // If this is the first return lowered for this function, add the regs to the |
| 1278 | // liveout set for the function. |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1279 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1280 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1281 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1284 | SDValue Chain = Op.getOperand(0); |
| 1285 | SDValue Flag; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1286 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1287 | // Copy the result values into the output registers. |
| 1288 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1289 | CCValAssign &VA = RVLocs[i]; |
| 1290 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1291 | Chain = DAG.getCopyToReg(Chain, VA.getLocReg(), Op.getOperand(i*2+1), Flag); |
| 1292 | Flag = Chain.getValue(1); |
| 1293 | } |
| 1294 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1295 | if (Flag.getNode()) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1296 | return DAG.getNode(SPUISD::RET_FLAG, MVT::Other, Chain, Flag); |
| 1297 | else |
| 1298 | return DAG.getNode(SPUISD::RET_FLAG, MVT::Other, Chain); |
| 1299 | } |
| 1300 | |
| 1301 | |
| 1302 | //===----------------------------------------------------------------------===// |
| 1303 | // Vector related lowering: |
| 1304 | //===----------------------------------------------------------------------===// |
| 1305 | |
| 1306 | static ConstantSDNode * |
| 1307 | getVecImm(SDNode *N) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1308 | SDValue OpVal(0, 0); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1309 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1310 | // Check to see if this buildvec has a single non-undef value in its elements. |
| 1311 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 1312 | if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1313 | if (OpVal.getNode() == 0) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1314 | OpVal = N->getOperand(i); |
| 1315 | else if (OpVal != N->getOperand(i)) |
| 1316 | return 0; |
| 1317 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1318 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1319 | if (OpVal.getNode() != 0) { |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 1320 | if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1321 | return CN; |
| 1322 | } |
| 1323 | } |
| 1324 | |
| 1325 | return 0; // All UNDEF: use implicit def.; not Constant node |
| 1326 | } |
| 1327 | |
| 1328 | /// get_vec_i18imm - Test if this vector is a vector filled with the same value |
| 1329 | /// and the value fits into an unsigned 18-bit constant, and if so, return the |
| 1330 | /// constant |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1331 | SDValue SPU::get_vec_u18imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1332 | MVT ValueType) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1333 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1334 | uint64_t Value = CN->getZExtValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1335 | if (ValueType == MVT::i64) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1336 | uint64_t UValue = CN->getZExtValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1337 | uint32_t upper = uint32_t(UValue >> 32); |
| 1338 | uint32_t lower = uint32_t(UValue); |
| 1339 | if (upper != lower) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1340 | return SDValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1341 | Value = Value >> 32; |
| 1342 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1343 | if (Value <= 0x3ffff) |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1344 | return DAG.getTargetConstant(Value, ValueType); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1347 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | /// get_vec_i16imm - Test if this vector is a vector filled with the same value |
| 1351 | /// and the value fits into a signed 16-bit constant, and if so, return the |
| 1352 | /// constant |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1353 | SDValue SPU::get_vec_i16imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1354 | MVT ValueType) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1355 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 1356 | int64_t Value = CN->getSExtValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1357 | if (ValueType == MVT::i64) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1358 | uint64_t UValue = CN->getZExtValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1359 | uint32_t upper = uint32_t(UValue >> 32); |
| 1360 | uint32_t lower = uint32_t(UValue); |
| 1361 | if (upper != lower) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1362 | return SDValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1363 | Value = Value >> 32; |
| 1364 | } |
Scott Michel | ad2715e | 2008-03-05 23:02:02 +0000 | [diff] [blame] | 1365 | if (Value >= -(1 << 15) && Value <= ((1 << 15) - 1)) { |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1366 | return DAG.getTargetConstant(Value, ValueType); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1370 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /// get_vec_i10imm - Test if this vector is a vector filled with the same value |
| 1374 | /// and the value fits into a signed 10-bit constant, and if so, return the |
| 1375 | /// constant |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1376 | SDValue SPU::get_vec_i10imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1377 | MVT ValueType) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1378 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | 7810bfe | 2008-09-26 21:54:37 +0000 | [diff] [blame] | 1379 | int64_t Value = CN->getSExtValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1380 | if (ValueType == MVT::i64) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1381 | uint64_t UValue = CN->getZExtValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1382 | uint32_t upper = uint32_t(UValue >> 32); |
| 1383 | uint32_t lower = uint32_t(UValue); |
| 1384 | if (upper != lower) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1385 | return SDValue(); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1386 | Value = Value >> 32; |
| 1387 | } |
Scott Michel | ad2715e | 2008-03-05 23:02:02 +0000 | [diff] [blame] | 1388 | if (isS10Constant(Value)) |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1389 | return DAG.getTargetConstant(Value, ValueType); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1392 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | /// get_vec_i8imm - Test if this vector is a vector filled with the same value |
| 1396 | /// and the value fits into a signed 8-bit constant, and if so, return the |
| 1397 | /// constant. |
| 1398 | /// |
| 1399 | /// @note: The incoming vector is v16i8 because that's the only way we can load |
| 1400 | /// constant vectors. Thus, we test to see if the upper and lower bytes are the |
| 1401 | /// same value. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1402 | SDValue SPU::get_vec_i8imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1403 | MVT ValueType) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1404 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1405 | int Value = (int) CN->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1406 | if (ValueType == MVT::i16 |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1407 | && Value <= 0xffff /* truncated from uint64_t */ |
| 1408 | && ((short) Value >> 8) == ((short) Value & 0xff)) |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1409 | return DAG.getTargetConstant(Value & 0xff, ValueType); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1410 | else if (ValueType == MVT::i8 |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1411 | && (Value & 0xff) == Value) |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1412 | return DAG.getTargetConstant(Value, ValueType); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1415 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | /// get_ILHUvec_imm - Test if this vector is a vector filled with the same value |
| 1419 | /// and the value fits into a signed 16-bit constant, and if so, return the |
| 1420 | /// constant |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1421 | SDValue SPU::get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1422 | MVT ValueType) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1423 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1424 | uint64_t Value = CN->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1425 | if ((ValueType == MVT::i32 |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1426 | && ((unsigned) Value & 0xffff0000) == (unsigned) Value) |
| 1427 | || (ValueType == MVT::i64 && (Value & 0xffff0000) == Value)) |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1428 | return DAG.getTargetConstant(Value >> 16, ValueType); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1429 | } |
| 1430 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1431 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | /// get_v4i32_imm - Catch-all for general 32-bit constant vectors |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1435 | SDValue SPU::get_v4i32_imm(SDNode *N, SelectionDAG &DAG) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1436 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1437 | return DAG.getTargetConstant((unsigned) CN->getZExtValue(), MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1440 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | /// get_v4i32_imm - Catch-all for general 64-bit constant vectors |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1444 | SDValue SPU::get_v2i64_imm(SDNode *N, SelectionDAG &DAG) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1445 | if (ConstantSDNode *CN = getVecImm(N)) { |
Dan Gohman | fa210d8 | 2008-11-05 02:06:09 +0000 | [diff] [blame] | 1446 | return DAG.getTargetConstant((unsigned) CN->getZExtValue(), MVT::i64); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1447 | } |
| 1448 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1449 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | // If this is a vector of constants or undefs, get the bits. A bit in |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1453 | // UndefBits is set if the corresponding element of the vector is an |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1454 | // ISD::UNDEF value. For undefs, the corresponding VectorBits values are |
| 1455 | // zero. Return true if this is not an array of constants, false if it is. |
| 1456 | // |
| 1457 | static bool GetConstantBuildVectorBits(SDNode *BV, uint64_t VectorBits[2], |
| 1458 | uint64_t UndefBits[2]) { |
| 1459 | // Start with zero'd results. |
| 1460 | VectorBits[0] = VectorBits[1] = UndefBits[0] = UndefBits[1] = 0; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1461 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1462 | unsigned EltBitSize = BV->getOperand(0).getValueType().getSizeInBits(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1463 | for (unsigned i = 0, e = BV->getNumOperands(); i != e; ++i) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1464 | SDValue OpVal = BV->getOperand(i); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1465 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1466 | unsigned PartNo = i >= e/2; // In the upper 128 bits? |
| 1467 | unsigned SlotNo = e/2 - (i & (e/2-1))-1; // Which subpiece of the uint64_t. |
| 1468 | |
| 1469 | uint64_t EltBits = 0; |
| 1470 | if (OpVal.getOpcode() == ISD::UNDEF) { |
| 1471 | uint64_t EltUndefBits = ~0ULL >> (64-EltBitSize); |
| 1472 | UndefBits[PartNo] |= EltUndefBits << (SlotNo*EltBitSize); |
| 1473 | continue; |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 1474 | } else if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1475 | EltBits = CN->getZExtValue() & (~0ULL >> (64-EltBitSize)); |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 1476 | } else if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(OpVal)) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1477 | const APFloat &apf = CN->getValueAPF(); |
| 1478 | EltBits = (CN->getValueType(0) == MVT::f32 |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1479 | ? FloatToBits(apf.convertToFloat()) |
| 1480 | : DoubleToBits(apf.convertToDouble())); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1481 | } else { |
| 1482 | // Nonconstant element. |
| 1483 | return true; |
| 1484 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1485 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1486 | VectorBits[PartNo] |= EltBits << (SlotNo*EltBitSize); |
| 1487 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1488 | |
| 1489 | //printf("%llx %llx %llx %llx\n", |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1490 | // VectorBits[0], VectorBits[1], UndefBits[0], UndefBits[1]); |
| 1491 | return false; |
| 1492 | } |
| 1493 | |
| 1494 | /// If this is a splat (repetition) of a value across the whole vector, return |
| 1495 | /// the smallest size that splats it. For example, "0x01010101010101..." is a |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1496 | /// splat of 0x01, 0x0101, and 0x01010101. We return SplatBits = 0x01 and |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1497 | /// SplatSize = 1 byte. |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1498 | static bool isConstantSplat(const uint64_t Bits128[2], |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1499 | const uint64_t Undef128[2], |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1500 | int MinSplatBits, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1501 | uint64_t &SplatBits, uint64_t &SplatUndef, |
| 1502 | int &SplatSize) { |
| 1503 | // Don't let undefs prevent splats from matching. See if the top 64-bits are |
| 1504 | // the same as the lower 64-bits, ignoring undefs. |
| 1505 | uint64_t Bits64 = Bits128[0] | Bits128[1]; |
| 1506 | uint64_t Undef64 = Undef128[0] & Undef128[1]; |
| 1507 | uint32_t Bits32 = uint32_t(Bits64) | uint32_t(Bits64 >> 32); |
| 1508 | uint32_t Undef32 = uint32_t(Undef64) & uint32_t(Undef64 >> 32); |
| 1509 | uint16_t Bits16 = uint16_t(Bits32) | uint16_t(Bits32 >> 16); |
| 1510 | uint16_t Undef16 = uint16_t(Undef32) & uint16_t(Undef32 >> 16); |
| 1511 | |
| 1512 | if ((Bits128[0] & ~Undef128[1]) == (Bits128[1] & ~Undef128[0])) { |
| 1513 | if (MinSplatBits < 64) { |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1514 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1515 | // Check that the top 32-bits are the same as the lower 32-bits, ignoring |
| 1516 | // undefs. |
| 1517 | if ((Bits64 & (~Undef64 >> 32)) == ((Bits64 >> 32) & ~Undef64)) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1518 | if (MinSplatBits < 32) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1519 | |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1520 | // If the top 16-bits are different than the lower 16-bits, ignoring |
| 1521 | // undefs, we have an i32 splat. |
| 1522 | if ((Bits32 & (~Undef32 >> 16)) == ((Bits32 >> 16) & ~Undef32)) { |
| 1523 | if (MinSplatBits < 16) { |
| 1524 | // If the top 8-bits are different than the lower 8-bits, ignoring |
| 1525 | // undefs, we have an i16 splat. |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1526 | if ((Bits16 & (uint16_t(~Undef16) >> 8)) |
| 1527 | == ((Bits16 >> 8) & ~Undef16)) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1528 | // Otherwise, we have an 8-bit splat. |
| 1529 | SplatBits = uint8_t(Bits16) | uint8_t(Bits16 >> 8); |
| 1530 | SplatUndef = uint8_t(Undef16) & uint8_t(Undef16 >> 8); |
| 1531 | SplatSize = 1; |
| 1532 | return true; |
| 1533 | } |
| 1534 | } else { |
| 1535 | SplatBits = Bits16; |
| 1536 | SplatUndef = Undef16; |
| 1537 | SplatSize = 2; |
| 1538 | return true; |
| 1539 | } |
| 1540 | } |
| 1541 | } else { |
| 1542 | SplatBits = Bits32; |
| 1543 | SplatUndef = Undef32; |
| 1544 | SplatSize = 4; |
| 1545 | return true; |
| 1546 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } else { |
| 1549 | SplatBits = Bits128[0]; |
| 1550 | SplatUndef = Undef128[0]; |
| 1551 | SplatSize = 8; |
| 1552 | return true; |
| 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | return false; // Can't be a splat if two pieces don't match. |
| 1557 | } |
| 1558 | |
| 1559 | // If this is a case we can't handle, return null and let the default |
| 1560 | // expansion code take care of it. If we CAN select this case, and if it |
| 1561 | // selects to a single instruction, return Op. Otherwise, if we can codegen |
| 1562 | // this case more efficiently than a constant pool load, lower it to the |
| 1563 | // sequence of ops that should be used. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1564 | static SDValue LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1565 | MVT VT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1566 | // If this is a vector of constants or undefs, get the bits. A bit in |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1567 | // UndefBits is set if the corresponding element of the vector is an |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1568 | // ISD::UNDEF value. For undefs, the corresponding VectorBits values are |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1569 | // zero. |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1570 | uint64_t VectorBits[2]; |
| 1571 | uint64_t UndefBits[2]; |
| 1572 | uint64_t SplatBits, SplatUndef; |
| 1573 | int SplatSize; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1574 | if (GetConstantBuildVectorBits(Op.getNode(), VectorBits, UndefBits) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1575 | || !isConstantSplat(VectorBits, UndefBits, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1576 | VT.getVectorElementType().getSizeInBits(), |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1577 | SplatBits, SplatUndef, SplatSize)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1578 | return SDValue(); // Not a constant vector, not a splat. |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1579 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1580 | switch (VT.getSimpleVT()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1581 | default: |
| 1582 | case MVT::v4f32: { |
| 1583 | uint32_t Value32 = SplatBits; |
| 1584 | assert(SplatSize == 4 |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1585 | && "LowerBUILD_VECTOR: Unexpected floating point vector element."); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1586 | // NOTE: pretend the constant is an integer. LLVM won't load FP constants |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1587 | SDValue T = DAG.getConstant(Value32, MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1588 | return DAG.getNode(ISD::BIT_CONVERT, MVT::v4f32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1589 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, T, T, T, T)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1590 | break; |
| 1591 | } |
| 1592 | case MVT::v2f64: { |
| 1593 | uint64_t f64val = SplatBits; |
| 1594 | assert(SplatSize == 8 |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1595 | && "LowerBUILD_VECTOR: 64-bit float vector element: unexpected size."); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1596 | // NOTE: pretend the constant is an integer. LLVM won't load FP constants |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1597 | SDValue T = DAG.getConstant(f64val, MVT::i64); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1598 | return DAG.getNode(ISD::BIT_CONVERT, MVT::v2f64, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1599 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v2i64, T, T)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1600 | break; |
| 1601 | } |
| 1602 | case MVT::v16i8: { |
| 1603 | // 8-bit constants have to be expanded to 16-bits |
| 1604 | unsigned short Value16 = SplatBits | (SplatBits << 8); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1605 | SDValue Ops[8]; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1606 | for (int i = 0; i < 8; ++i) |
| 1607 | Ops[i] = DAG.getConstant(Value16, MVT::i16); |
| 1608 | return DAG.getNode(ISD::BIT_CONVERT, VT, |
| 1609 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v8i16, Ops, 8)); |
| 1610 | } |
| 1611 | case MVT::v8i16: { |
| 1612 | unsigned short Value16; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1613 | if (SplatSize == 2) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1614 | Value16 = (unsigned short) (SplatBits & 0xffff); |
| 1615 | else |
| 1616 | Value16 = (unsigned short) (SplatBits | (SplatBits << 8)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1617 | SDValue T = DAG.getConstant(Value16, VT.getVectorElementType()); |
| 1618 | SDValue Ops[8]; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1619 | for (int i = 0; i < 8; ++i) Ops[i] = T; |
| 1620 | return DAG.getNode(ISD::BUILD_VECTOR, VT, Ops, 8); |
| 1621 | } |
| 1622 | case MVT::v4i32: { |
| 1623 | unsigned int Value = SplatBits; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1624 | SDValue T = DAG.getConstant(Value, VT.getVectorElementType()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1625 | return DAG.getNode(ISD::BUILD_VECTOR, VT, T, T, T, T); |
| 1626 | } |
| 1627 | case MVT::v2i64: { |
| 1628 | uint64_t val = SplatBits; |
| 1629 | uint32_t upper = uint32_t(val >> 32); |
| 1630 | uint32_t lower = uint32_t(val); |
| 1631 | |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1632 | if (upper == lower) { |
| 1633 | // Magic constant that can be matched by IL, ILA, et. al. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1634 | SDValue Val = DAG.getTargetConstant(val, MVT::i64); |
Scott Michel | 4cb8bd8 | 2008-03-06 04:02:54 +0000 | [diff] [blame] | 1635 | return DAG.getNode(ISD::BUILD_VECTOR, VT, Val, Val); |
Scott Michel | ad2715e | 2008-03-05 23:02:02 +0000 | [diff] [blame] | 1636 | } else { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1637 | SDValue LO32; |
| 1638 | SDValue HI32; |
| 1639 | SmallVector<SDValue, 16> ShufBytes; |
| 1640 | SDValue Result; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1641 | bool upper_special, lower_special; |
| 1642 | |
| 1643 | // NOTE: This code creates common-case shuffle masks that can be easily |
| 1644 | // detected as common expressions. It is not attempting to create highly |
| 1645 | // specialized masks to replace any and all 0's, 0xff's and 0x80's. |
| 1646 | |
| 1647 | // Detect if the upper or lower half is a special shuffle mask pattern: |
| 1648 | upper_special = (upper == 0 || upper == 0xffffffff || upper == 0x80000000); |
| 1649 | lower_special = (lower == 0 || lower == 0xffffffff || lower == 0x80000000); |
| 1650 | |
| 1651 | // Create lower vector if not a special pattern |
| 1652 | if (!lower_special) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1653 | SDValue LO32C = DAG.getConstant(lower, MVT::i32); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1654 | LO32 = DAG.getNode(ISD::BIT_CONVERT, VT, |
| 1655 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, |
| 1656 | LO32C, LO32C, LO32C, LO32C)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | // Create upper vector if not a special pattern |
| 1660 | if (!upper_special) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1661 | SDValue HI32C = DAG.getConstant(upper, MVT::i32); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1662 | HI32 = DAG.getNode(ISD::BIT_CONVERT, VT, |
| 1663 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, |
| 1664 | HI32C, HI32C, HI32C, HI32C)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | // If either upper or lower are special, then the two input operands are |
| 1668 | // the same (basically, one of them is a "don't care") |
| 1669 | if (lower_special) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1670 | LO32 = HI32; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1671 | if (upper_special) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1672 | HI32 = LO32; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1673 | if (lower_special && upper_special) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1674 | // Unhappy situation... both upper and lower are special, so punt with |
| 1675 | // a target constant: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1676 | SDValue Zero = DAG.getConstant(0, MVT::i32); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1677 | HI32 = LO32 = DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, Zero, Zero, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1678 | Zero, Zero); |
| 1679 | } |
| 1680 | |
| 1681 | for (int i = 0; i < 4; ++i) { |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1682 | uint64_t val = 0; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1683 | for (int j = 0; j < 4; ++j) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1684 | SDValue V; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1685 | bool process_upper, process_lower; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1686 | val <<= 8; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1687 | process_upper = (upper_special && (i & 1) == 0); |
| 1688 | process_lower = (lower_special && (i & 1) == 1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1689 | |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1690 | if (process_upper || process_lower) { |
| 1691 | if ((process_upper && upper == 0) |
| 1692 | || (process_lower && lower == 0)) |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1693 | val |= 0x80; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1694 | else if ((process_upper && upper == 0xffffffff) |
| 1695 | || (process_lower && lower == 0xffffffff)) |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1696 | val |= 0xc0; |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1697 | else if ((process_upper && upper == 0x80000000) |
| 1698 | || (process_lower && lower == 0x80000000)) |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1699 | val |= (j == 0 ? 0xe0 : 0x80); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1700 | } else |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1701 | val |= i * 4 + j + ((i & 1) * 16); |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1702 | } |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1703 | |
| 1704 | ShufBytes.push_back(DAG.getConstant(val, MVT::i32)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | return DAG.getNode(SPUISD::SHUFB, VT, HI32, LO32, |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1708 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1709 | &ShufBytes[0], ShufBytes.size())); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1713 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1714 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | /// LowerVECTOR_SHUFFLE - Lower a vector shuffle (V1, V2, V3) to something on |
| 1718 | /// which the Cell can operate. The code inspects V3 to ascertain whether the |
| 1719 | /// permutation vector, V3, is monotonically increasing with one "exception" |
| 1720 | /// element, e.g., (0, 1, _, 3). If this is the case, then generate a |
| 1721 | /// INSERT_MASK synthetic instruction. Otherwise, spill V3 to the constant pool. |
| 1722 | /// In either case, the net result is going to eventually invoke SHUFB to |
| 1723 | /// permute/shuffle the bytes from V1 and V2. |
| 1724 | /// \note |
| 1725 | /// INSERT_MASK is eventually selected as one of the C*D instructions, generate |
| 1726 | /// control word for byte/halfword/word insertion. This takes care of a single |
| 1727 | /// element move from V2 into V1. |
| 1728 | /// \note |
| 1729 | /// SPUISD::SHUFB is eventually selected as Cell's <i>shufb</i> instructions. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1730 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
| 1731 | SDValue V1 = Op.getOperand(0); |
| 1732 | SDValue V2 = Op.getOperand(1); |
| 1733 | SDValue PermMask = Op.getOperand(2); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1734 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1735 | if (V2.getOpcode() == ISD::UNDEF) V2 = V1; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1736 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1737 | // If we have a single element being moved from V1 to V2, this can be handled |
| 1738 | // using the C*[DX] compute mask instructions, but the vector elements have |
| 1739 | // to be monotonically increasing with one exception element. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1740 | MVT EltVT = V1.getValueType().getVectorElementType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1741 | unsigned EltsFromV2 = 0; |
| 1742 | unsigned V2Elt = 0; |
| 1743 | unsigned V2EltIdx0 = 0; |
| 1744 | unsigned CurrElt = 0; |
| 1745 | bool monotonic = true; |
| 1746 | if (EltVT == MVT::i8) |
| 1747 | V2EltIdx0 = 16; |
| 1748 | else if (EltVT == MVT::i16) |
| 1749 | V2EltIdx0 = 8; |
| 1750 | else if (EltVT == MVT::i32) |
| 1751 | V2EltIdx0 = 4; |
| 1752 | else |
| 1753 | assert(0 && "Unhandled vector type in LowerVECTOR_SHUFFLE"); |
| 1754 | |
| 1755 | for (unsigned i = 0, e = PermMask.getNumOperands(); |
| 1756 | EltsFromV2 <= 1 && monotonic && i != e; |
| 1757 | ++i) { |
| 1758 | unsigned SrcElt; |
| 1759 | if (PermMask.getOperand(i).getOpcode() == ISD::UNDEF) |
| 1760 | SrcElt = 0; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1761 | else |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1762 | SrcElt = cast<ConstantSDNode>(PermMask.getOperand(i))->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1763 | |
| 1764 | if (SrcElt >= V2EltIdx0) { |
| 1765 | ++EltsFromV2; |
| 1766 | V2Elt = (V2EltIdx0 - SrcElt) << 2; |
| 1767 | } else if (CurrElt != SrcElt) { |
| 1768 | monotonic = false; |
| 1769 | } |
| 1770 | |
| 1771 | ++CurrElt; |
| 1772 | } |
| 1773 | |
| 1774 | if (EltsFromV2 == 1 && monotonic) { |
| 1775 | // Compute mask and shuffle |
| 1776 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1777 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
| 1778 | unsigned VReg = RegInfo.createVirtualRegister(&SPU::R32CRegClass); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1779 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1780 | // Initialize temporary register to 0 |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1781 | SDValue InitTempReg = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1782 | DAG.getCopyToReg(DAG.getEntryNode(), VReg, DAG.getConstant(0, PtrVT)); |
| 1783 | // Copy register's contents as index in INSERT_MASK: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1784 | SDValue ShufMaskOp = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1785 | DAG.getNode(SPUISD::INSERT_MASK, V1.getValueType(), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1786 | DAG.getTargetConstant(V2Elt, MVT::i32), |
| 1787 | DAG.getCopyFromReg(InitTempReg, VReg, PtrVT)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1788 | // Use shuffle mask in SHUFB synthetic instruction: |
| 1789 | return DAG.getNode(SPUISD::SHUFB, V1.getValueType(), V2, V1, ShufMaskOp); |
| 1790 | } else { |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1791 | // Convert the SHUFFLE_VECTOR mask's input element units to the |
| 1792 | // actual bytes. |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1793 | unsigned BytesPerElement = EltVT.getSizeInBits()/8; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1794 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1795 | SmallVector<SDValue, 16> ResultMask; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1796 | for (unsigned i = 0, e = PermMask.getNumOperands(); i != e; ++i) { |
| 1797 | unsigned SrcElt; |
| 1798 | if (PermMask.getOperand(i).getOpcode() == ISD::UNDEF) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1799 | SrcElt = 0; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1800 | else |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1801 | SrcElt = cast<ConstantSDNode>(PermMask.getOperand(i))->getZExtValue(); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1802 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 1803 | for (unsigned j = 0; j < BytesPerElement; ++j) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1804 | ResultMask.push_back(DAG.getConstant(SrcElt*BytesPerElement+j, |
| 1805 | MVT::i8)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1806 | } |
| 1807 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 1808 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1809 | SDValue VPermMask = DAG.getNode(ISD::BUILD_VECTOR, MVT::v16i8, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1810 | &ResultMask[0], ResultMask.size()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1811 | return DAG.getNode(SPUISD::SHUFB, V1.getValueType(), V1, V2, VPermMask); |
| 1812 | } |
| 1813 | } |
| 1814 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1815 | static SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) { |
| 1816 | SDValue Op0 = Op.getOperand(0); // Op0 = the scalar |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1817 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1818 | if (Op0.getNode()->getOpcode() == ISD::Constant) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1819 | // For a constant, build the appropriate constant vector, which will |
| 1820 | // eventually simplify to a vector register load. |
| 1821 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1822 | ConstantSDNode *CN = cast<ConstantSDNode>(Op0.getNode()); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1823 | SmallVector<SDValue, 16> ConstVecValues; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1824 | MVT VT; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1825 | size_t n_copies; |
| 1826 | |
| 1827 | // Create a constant vector: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1828 | switch (Op.getValueType().getSimpleVT()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1829 | default: assert(0 && "Unexpected constant value type in " |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1830 | "LowerSCALAR_TO_VECTOR"); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1831 | case MVT::v16i8: n_copies = 16; VT = MVT::i8; break; |
| 1832 | case MVT::v8i16: n_copies = 8; VT = MVT::i16; break; |
| 1833 | case MVT::v4i32: n_copies = 4; VT = MVT::i32; break; |
| 1834 | case MVT::v4f32: n_copies = 4; VT = MVT::f32; break; |
| 1835 | case MVT::v2i64: n_copies = 2; VT = MVT::i64; break; |
| 1836 | case MVT::v2f64: n_copies = 2; VT = MVT::f64; break; |
| 1837 | } |
| 1838 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 1839 | SDValue CValue = DAG.getConstant(CN->getZExtValue(), VT); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1840 | for (size_t j = 0; j < n_copies; ++j) |
| 1841 | ConstVecValues.push_back(CValue); |
| 1842 | |
| 1843 | return DAG.getNode(ISD::BUILD_VECTOR, Op.getValueType(), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1844 | &ConstVecValues[0], ConstVecValues.size()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1845 | } else { |
| 1846 | // Otherwise, copy the value from one register to another: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1847 | switch (Op0.getValueType().getSimpleVT()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1848 | default: assert(0 && "Unexpected value type in LowerSCALAR_TO_VECTOR"); |
| 1849 | case MVT::i8: |
| 1850 | case MVT::i16: |
| 1851 | case MVT::i32: |
| 1852 | case MVT::i64: |
| 1853 | case MVT::f32: |
| 1854 | case MVT::f64: |
| 1855 | return DAG.getNode(SPUISD::PROMOTE_SCALAR, Op.getValueType(), Op0, Op0); |
| 1856 | } |
| 1857 | } |
| 1858 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1859 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1862 | static SDValue LowerVectorMUL(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 1863 | switch (Op.getValueType().getSimpleVT()) { |
| 1864 | default: |
| 1865 | cerr << "CellSPU: Unknown vector multiplication, got " |
| 1866 | << Op.getValueType().getMVTString() |
| 1867 | << "\n"; |
| 1868 | abort(); |
| 1869 | /*NOTREACHED*/ |
| 1870 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1871 | case MVT::v4i32: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1872 | SDValue rA = Op.getOperand(0); |
| 1873 | SDValue rB = Op.getOperand(1); |
| 1874 | SDValue HiProd1 = DAG.getNode(SPUISD::MPYH, MVT::v4i32, rA, rB); |
| 1875 | SDValue HiProd2 = DAG.getNode(SPUISD::MPYH, MVT::v4i32, rB, rA); |
| 1876 | SDValue LoProd = DAG.getNode(SPUISD::MPYU, MVT::v4i32, rA, rB); |
| 1877 | SDValue Residual1 = DAG.getNode(ISD::ADD, MVT::v4i32, LoProd, HiProd1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1878 | |
| 1879 | return DAG.getNode(ISD::ADD, MVT::v4i32, Residual1, HiProd2); |
| 1880 | break; |
| 1881 | } |
| 1882 | |
| 1883 | // Multiply two v8i16 vectors (pipeline friendly version): |
| 1884 | // a) multiply lower halves, mask off upper 16-bit of 32-bit product |
| 1885 | // b) multiply upper halves, rotate left by 16 bits (inserts 16 lower zeroes) |
| 1886 | // c) Use SELB to select upper and lower halves from the intermediate results |
| 1887 | // |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1888 | // NOTE: We really want to move the SELECT_MASK to earlier to actually get the |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1889 | // dual-issue. This code does manage to do this, even if it's a little on |
| 1890 | // the wacky side |
| 1891 | case MVT::v8i16: { |
| 1892 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1893 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1894 | SDValue Chain = Op.getOperand(0); |
| 1895 | SDValue rA = Op.getOperand(0); |
| 1896 | SDValue rB = Op.getOperand(1); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 1897 | unsigned FSMBIreg = RegInfo.createVirtualRegister(&SPU::VECREGRegClass); |
| 1898 | unsigned HiProdReg = RegInfo.createVirtualRegister(&SPU::VECREGRegClass); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1899 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1900 | SDValue FSMBOp = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1901 | DAG.getCopyToReg(Chain, FSMBIreg, |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 1902 | DAG.getNode(SPUISD::SELECT_MASK, MVT::v8i16, |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 1903 | DAG.getConstant(0xcccc, MVT::i16))); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1904 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1905 | SDValue HHProd = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1906 | DAG.getCopyToReg(FSMBOp, HiProdReg, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1907 | DAG.getNode(SPUISD::MPYHH, MVT::v8i16, rA, rB)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1908 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1909 | SDValue HHProd_v4i32 = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1910 | DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1911 | DAG.getCopyFromReg(HHProd, HiProdReg, MVT::v4i32)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1912 | |
| 1913 | return DAG.getNode(SPUISD::SELB, MVT::v8i16, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1914 | DAG.getNode(SPUISD::MPY, MVT::v8i16, rA, rB), |
| 1915 | DAG.getNode(ISD::BIT_CONVERT, Op.getValueType(), |
| 1916 | DAG.getNode(SPUISD::VEC_SHL, MVT::v4i32, |
| 1917 | HHProd_v4i32, |
| 1918 | DAG.getConstant(16, MVT::i16))), |
| 1919 | DAG.getCopyFromReg(FSMBOp, FSMBIreg, MVT::v4i32)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | // This M00sE is N@stI! (apologies to Monty Python) |
| 1923 | // |
| 1924 | // SPU doesn't know how to do any 8-bit multiplication, so the solution |
| 1925 | // is to break it all apart, sign extend, and reassemble the various |
| 1926 | // intermediate products. |
| 1927 | case MVT::v16i8: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1928 | SDValue rA = Op.getOperand(0); |
| 1929 | SDValue rB = Op.getOperand(1); |
| 1930 | SDValue c8 = DAG.getConstant(8, MVT::i32); |
| 1931 | SDValue c16 = DAG.getConstant(16, MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1932 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1933 | SDValue LLProd = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1934 | DAG.getNode(SPUISD::MPY, MVT::v8i16, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1935 | DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, rA), |
| 1936 | DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, rB)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1937 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1938 | SDValue rALH = DAG.getNode(SPUISD::VEC_SRA, MVT::v8i16, rA, c8); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1939 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1940 | SDValue rBLH = DAG.getNode(SPUISD::VEC_SRA, MVT::v8i16, rB, c8); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1941 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1942 | SDValue LHProd = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1943 | DAG.getNode(SPUISD::VEC_SHL, MVT::v8i16, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1944 | DAG.getNode(SPUISD::MPY, MVT::v8i16, rALH, rBLH), c8); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1945 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1946 | SDValue FSMBmask = DAG.getNode(SPUISD::SELECT_MASK, MVT::v8i16, |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 1947 | DAG.getConstant(0x2222, MVT::i16)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1948 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1949 | SDValue LoProdParts = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 1950 | DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, |
| 1951 | DAG.getNode(SPUISD::SELB, MVT::v8i16, |
| 1952 | LLProd, LHProd, FSMBmask)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1953 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1954 | SDValue LoProdMask = DAG.getConstant(0xffff, MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1955 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1956 | SDValue LoProd = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1957 | DAG.getNode(ISD::AND, MVT::v4i32, |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 1958 | LoProdParts, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1959 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, |
| 1960 | LoProdMask, LoProdMask, |
| 1961 | LoProdMask, LoProdMask)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1962 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1963 | SDValue rAH = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1964 | DAG.getNode(SPUISD::VEC_SRA, MVT::v4i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1965 | DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, rA), c16); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1966 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1967 | SDValue rBH = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1968 | DAG.getNode(SPUISD::VEC_SRA, MVT::v4i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1969 | DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, rB), c16); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1970 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1971 | SDValue HLProd = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1972 | DAG.getNode(SPUISD::MPY, MVT::v8i16, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1973 | DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, rAH), |
| 1974 | DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, rBH)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1975 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1976 | SDValue HHProd_1 = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1977 | DAG.getNode(SPUISD::MPY, MVT::v8i16, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1978 | DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1979 | DAG.getNode(SPUISD::VEC_SRA, |
| 1980 | MVT::v4i32, rAH, c8)), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1981 | DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 1982 | DAG.getNode(SPUISD::VEC_SRA, |
| 1983 | MVT::v4i32, rBH, c8))); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1984 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1985 | SDValue HHProd = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 1986 | DAG.getNode(SPUISD::SELB, MVT::v8i16, |
| 1987 | HLProd, |
| 1988 | DAG.getNode(SPUISD::VEC_SHL, MVT::v8i16, HHProd_1, c8), |
| 1989 | FSMBmask); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1990 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1991 | SDValue HiProd = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 1992 | DAG.getNode(SPUISD::VEC_SHL, MVT::v4i32, HHProd, c16); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1993 | |
| 1994 | return DAG.getNode(ISD::BIT_CONVERT, MVT::v16i8, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 1995 | DAG.getNode(ISD::OR, MVT::v4i32, |
| 1996 | LoProd, HiProd)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1997 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 1998 | } |
| 1999 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2000 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2003 | static SDValue LowerFDIVf32(SDValue Op, SelectionDAG &DAG) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2004 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2005 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2006 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2007 | SDValue A = Op.getOperand(0); |
| 2008 | SDValue B = Op.getOperand(1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2009 | MVT VT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2010 | |
| 2011 | unsigned VRegBR, VRegC; |
| 2012 | |
| 2013 | if (VT == MVT::f32) { |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2014 | VRegBR = RegInfo.createVirtualRegister(&SPU::R32FPRegClass); |
| 2015 | VRegC = RegInfo.createVirtualRegister(&SPU::R32FPRegClass); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2016 | } else { |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2017 | VRegBR = RegInfo.createVirtualRegister(&SPU::VECREGRegClass); |
| 2018 | VRegC = RegInfo.createVirtualRegister(&SPU::VECREGRegClass); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2019 | } |
| 2020 | // TODO: make sure we're feeding FPInterp the right arguments |
| 2021 | // Right now: fi B, frest(B) |
| 2022 | |
| 2023 | // Computes BRcpl = |
| 2024 | // (Floating Interpolate (FP Reciprocal Estimate B)) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2025 | SDValue BRcpl = |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2026 | DAG.getCopyToReg(DAG.getEntryNode(), VRegBR, |
| 2027 | DAG.getNode(SPUISD::FPInterp, VT, B, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2028 | DAG.getNode(SPUISD::FPRecipEst, VT, B))); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2029 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2030 | // Computes A * BRcpl and stores in a temporary register |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2031 | SDValue AxBRcpl = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2032 | DAG.getCopyToReg(BRcpl, VRegC, |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2033 | DAG.getNode(ISD::FMUL, VT, A, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2034 | DAG.getCopyFromReg(BRcpl, VRegBR, VT))); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2035 | // What's the Chain variable do? It's magic! |
| 2036 | // TODO: set Chain = Op(0).getEntryNode() |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2037 | |
| 2038 | return DAG.getNode(ISD::FADD, VT, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2039 | DAG.getCopyFromReg(AxBRcpl, VRegC, VT), |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2040 | DAG.getNode(ISD::FMUL, VT, |
| 2041 | DAG.getCopyFromReg(AxBRcpl, VRegBR, VT), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2042 | DAG.getNode(ISD::FSUB, VT, A, |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2043 | DAG.getNode(ISD::FMUL, VT, B, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2044 | DAG.getCopyFromReg(AxBRcpl, VRegC, VT))))); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2047 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2048 | MVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2049 | SDValue N = Op.getOperand(0); |
| 2050 | SDValue Elt = Op.getOperand(1); |
| 2051 | SDValue ShufMask[16]; |
Scott Michel | 19fd42a | 2008-11-11 03:06:06 +0000 | [diff] [blame] | 2052 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2053 | |
| 2054 | assert(C != 0 && "LowerEXTRACT_VECTOR_ELT expecting constant SDNode"); |
| 2055 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2056 | int EltNo = (int) C->getZExtValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2057 | |
| 2058 | // sanity checks: |
| 2059 | if (VT == MVT::i8 && EltNo >= 16) |
| 2060 | assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i8 extraction slot > 15"); |
| 2061 | else if (VT == MVT::i16 && EltNo >= 8) |
| 2062 | assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i16 extraction slot > 7"); |
| 2063 | else if (VT == MVT::i32 && EltNo >= 4) |
| 2064 | assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i32 extraction slot > 4"); |
| 2065 | else if (VT == MVT::i64 && EltNo >= 2) |
| 2066 | assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i64 extraction slot > 2"); |
| 2067 | |
| 2068 | if (EltNo == 0 && (VT == MVT::i32 || VT == MVT::i64)) { |
| 2069 | // i32 and i64: Element 0 is the preferred slot |
| 2070 | return DAG.getNode(SPUISD::EXTRACT_ELT0, VT, N); |
| 2071 | } |
| 2072 | |
| 2073 | // Need to generate shuffle mask and extract: |
Scott Michel | 0e5665b | 2007-12-19 21:17:42 +0000 | [diff] [blame] | 2074 | int prefslot_begin = -1, prefslot_end = -1; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2075 | int elt_byte = EltNo * VT.getSizeInBits() / 8; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2076 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2077 | switch (VT.getSimpleVT()) { |
| 2078 | default: |
| 2079 | assert(false && "Invalid value type!"); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2080 | case MVT::i8: { |
| 2081 | prefslot_begin = prefslot_end = 3; |
| 2082 | break; |
| 2083 | } |
| 2084 | case MVT::i16: { |
| 2085 | prefslot_begin = 2; prefslot_end = 3; |
| 2086 | break; |
| 2087 | } |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 2088 | case MVT::i32: |
| 2089 | case MVT::f32: { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2090 | prefslot_begin = 0; prefslot_end = 3; |
| 2091 | break; |
| 2092 | } |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 2093 | case MVT::i64: |
| 2094 | case MVT::f64: { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2095 | prefslot_begin = 0; prefslot_end = 7; |
| 2096 | break; |
| 2097 | } |
| 2098 | } |
| 2099 | |
Scott Michel | 0e5665b | 2007-12-19 21:17:42 +0000 | [diff] [blame] | 2100 | assert(prefslot_begin != -1 && prefslot_end != -1 && |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2101 | "LowerEXTRACT_VECTOR_ELT: preferred slots uninitialized"); |
Scott Michel | 0e5665b | 2007-12-19 21:17:42 +0000 | [diff] [blame] | 2102 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2103 | for (int i = 0; i < 16; ++i) { |
| 2104 | // zero fill uppper part of preferred slot, don't care about the |
| 2105 | // other slots: |
| 2106 | unsigned int mask_val; |
| 2107 | |
| 2108 | if (i <= prefslot_end) { |
| 2109 | mask_val = |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2110 | ((i < prefslot_begin) |
| 2111 | ? 0x80 |
| 2112 | : elt_byte + (i - prefslot_begin)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2113 | |
Scott Michel | 0e5665b | 2007-12-19 21:17:42 +0000 | [diff] [blame] | 2114 | ShufMask[i] = DAG.getConstant(mask_val, MVT::i8); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2115 | } else |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2116 | ShufMask[i] = ShufMask[i % (prefslot_end + 1)]; |
| 2117 | } |
| 2118 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2119 | SDValue ShufMaskVec = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2120 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v16i8, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2121 | &ShufMask[0], |
| 2122 | sizeof(ShufMask) / sizeof(ShufMask[0])); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2123 | |
| 2124 | return DAG.getNode(SPUISD::EXTRACT_ELT0, VT, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2125 | DAG.getNode(SPUISD::SHUFB, N.getValueType(), |
| 2126 | N, N, ShufMaskVec)); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2127 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2128 | } |
| 2129 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2130 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 2131 | SDValue VecOp = Op.getOperand(0); |
| 2132 | SDValue ValOp = Op.getOperand(1); |
| 2133 | SDValue IdxOp = Op.getOperand(2); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2134 | MVT VT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2135 | |
| 2136 | ConstantSDNode *CN = cast<ConstantSDNode>(IdxOp); |
| 2137 | assert(CN != 0 && "LowerINSERT_VECTOR_ELT: Index is not constant!"); |
| 2138 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2139 | MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2140 | // Use $2 because it's always 16-byte aligned and it's available: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2141 | SDValue PtrBase = DAG.getRegister(SPU::R2, PtrVT); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2142 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2143 | SDValue result = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2144 | DAG.getNode(SPUISD::SHUFB, VT, |
| 2145 | DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, ValOp), |
| 2146 | VecOp, |
| 2147 | DAG.getNode(SPUISD::INSERT_MASK, VT, |
| 2148 | DAG.getNode(ISD::ADD, PtrVT, |
| 2149 | PtrBase, |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2150 | DAG.getConstant(CN->getZExtValue(), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2151 | PtrVT)))); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2152 | |
| 2153 | return result; |
| 2154 | } |
| 2155 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2156 | static SDValue LowerI8Math(SDValue Op, SelectionDAG &DAG, unsigned Opc) |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2157 | { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2158 | SDValue N0 = Op.getOperand(0); // Everything has at least one operand |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2159 | |
| 2160 | assert(Op.getValueType() == MVT::i8); |
| 2161 | switch (Opc) { |
| 2162 | default: |
| 2163 | assert(0 && "Unhandled i8 math operator"); |
| 2164 | /*NOTREACHED*/ |
| 2165 | break; |
| 2166 | case ISD::SUB: { |
| 2167 | // 8-bit subtraction: Promote the arguments up to 16-bits and truncate |
| 2168 | // the result: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2169 | SDValue N1 = Op.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2170 | N0 = (N0.getOpcode() != ISD::Constant |
| 2171 | ? DAG.getNode(ISD::SIGN_EXTEND, MVT::i16, N0) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2172 | : DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(), |
| 2173 | MVT::i16)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2174 | N1 = (N1.getOpcode() != ISD::Constant |
| 2175 | ? DAG.getNode(ISD::SIGN_EXTEND, MVT::i16, N1) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2176 | : DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(), |
| 2177 | MVT::i16)); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2178 | return DAG.getNode(ISD::TRUNCATE, MVT::i8, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2179 | DAG.getNode(Opc, MVT::i16, N0, N1)); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2180 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2181 | case ISD::ROTR: |
| 2182 | case ISD::ROTL: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2183 | SDValue N1 = Op.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2184 | unsigned N1Opc; |
| 2185 | N0 = (N0.getOpcode() != ISD::Constant |
| 2186 | ? DAG.getNode(ISD::ZERO_EXTEND, MVT::i16, N0) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2187 | : DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(), |
| 2188 | MVT::i16)); |
Duncan Sands | fa7935f | 2008-10-30 19:24:28 +0000 | [diff] [blame] | 2189 | N1Opc = N1.getValueType().bitsLT(MVT::i32) |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 2190 | ? ISD::ZERO_EXTEND |
| 2191 | : ISD::TRUNCATE; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2192 | N1 = (N1.getOpcode() != ISD::Constant |
Duncan Sands | fa7935f | 2008-10-30 19:24:28 +0000 | [diff] [blame] | 2193 | ? DAG.getNode(N1Opc, MVT::i32, N1) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2194 | : DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(), |
Duncan Sands | fa7935f | 2008-10-30 19:24:28 +0000 | [diff] [blame] | 2195 | MVT::i32)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2196 | SDValue ExpandArg = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2197 | DAG.getNode(ISD::OR, MVT::i16, N0, |
| 2198 | DAG.getNode(ISD::SHL, MVT::i16, |
Duncan Sands | fa7935f | 2008-10-30 19:24:28 +0000 | [diff] [blame] | 2199 | N0, DAG.getConstant(8, MVT::i32))); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2200 | return DAG.getNode(ISD::TRUNCATE, MVT::i8, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2201 | DAG.getNode(Opc, MVT::i16, ExpandArg, N1)); |
| 2202 | } |
| 2203 | case ISD::SRL: |
| 2204 | case ISD::SHL: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2205 | SDValue N1 = Op.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2206 | unsigned N1Opc; |
| 2207 | N0 = (N0.getOpcode() != ISD::Constant |
| 2208 | ? DAG.getNode(ISD::ZERO_EXTEND, MVT::i16, N0) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2209 | : DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(), |
| 2210 | MVT::i16)); |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 2211 | N1Opc = N1.getValueType().bitsLT(MVT::i16) |
| 2212 | ? ISD::ZERO_EXTEND |
| 2213 | : ISD::TRUNCATE; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2214 | N1 = (N1.getOpcode() != ISD::Constant |
| 2215 | ? DAG.getNode(N1Opc, MVT::i16, N1) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2216 | : DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(), |
| 2217 | MVT::i16)); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2218 | return DAG.getNode(ISD::TRUNCATE, MVT::i8, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2219 | DAG.getNode(Opc, MVT::i16, N0, N1)); |
| 2220 | } |
| 2221 | case ISD::SRA: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2222 | SDValue N1 = Op.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2223 | unsigned N1Opc; |
| 2224 | N0 = (N0.getOpcode() != ISD::Constant |
| 2225 | ? DAG.getNode(ISD::SIGN_EXTEND, MVT::i16, N0) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2226 | : DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(), |
| 2227 | MVT::i16)); |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 2228 | N1Opc = N1.getValueType().bitsLT(MVT::i16) |
| 2229 | ? ISD::SIGN_EXTEND |
| 2230 | : ISD::TRUNCATE; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2231 | N1 = (N1.getOpcode() != ISD::Constant |
| 2232 | ? DAG.getNode(N1Opc, MVT::i16, N1) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2233 | : DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(), |
| 2234 | MVT::i16)); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2235 | return DAG.getNode(ISD::TRUNCATE, MVT::i8, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2236 | DAG.getNode(Opc, MVT::i16, N0, N1)); |
| 2237 | } |
| 2238 | case ISD::MUL: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2239 | SDValue N1 = Op.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2240 | unsigned N1Opc; |
| 2241 | N0 = (N0.getOpcode() != ISD::Constant |
| 2242 | ? DAG.getNode(ISD::SIGN_EXTEND, MVT::i16, N0) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2243 | : DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(), |
| 2244 | MVT::i16)); |
Duncan Sands | 8e4eb09 | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 2245 | N1Opc = N1.getValueType().bitsLT(MVT::i16) ? ISD::SIGN_EXTEND : ISD::TRUNCATE; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2246 | N1 = (N1.getOpcode() != ISD::Constant |
| 2247 | ? DAG.getNode(N1Opc, MVT::i16, N1) |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2248 | : DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(), |
| 2249 | MVT::i16)); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2250 | return DAG.getNode(ISD::TRUNCATE, MVT::i8, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2251 | DAG.getNode(Opc, MVT::i16, N0, N1)); |
| 2252 | break; |
| 2253 | } |
| 2254 | } |
| 2255 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2256 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2259 | static SDValue LowerI64Math(SDValue Op, SelectionDAG &DAG, unsigned Opc) |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2260 | { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2261 | MVT VT = Op.getValueType(); |
| 2262 | MVT VecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits())); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2263 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2264 | SDValue Op0 = Op.getOperand(0); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2265 | |
| 2266 | switch (Opc) { |
| 2267 | case ISD::ZERO_EXTEND: |
| 2268 | case ISD::SIGN_EXTEND: |
| 2269 | case ISD::ANY_EXTEND: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2270 | MVT Op0VT = Op0.getValueType(); |
| 2271 | MVT Op0VecVT = MVT::getVectorVT(Op0VT, (128 / Op0VT.getSizeInBits())); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2272 | |
| 2273 | assert(Op0VT == MVT::i32 |
| 2274 | && "CellSPU: Zero/sign extending something other than i32"); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 2275 | DEBUG(cerr << "CellSPU: LowerI64Math custom lowering zero/sign/any extend\n"); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2276 | |
| 2277 | unsigned NewOpc = (Opc == ISD::SIGN_EXTEND |
| 2278 | ? SPUISD::ROTBYTES_RIGHT_S |
| 2279 | : SPUISD::ROTQUAD_RZ_BYTES); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2280 | SDValue PromoteScalar = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2281 | DAG.getNode(SPUISD::PROMOTE_SCALAR, Op0VecVT, Op0); |
| 2282 | |
| 2283 | return DAG.getNode(SPUISD::EXTRACT_ELT0, VT, |
| 2284 | DAG.getNode(ISD::BIT_CONVERT, VecVT, |
| 2285 | DAG.getNode(NewOpc, Op0VecVT, |
| 2286 | PromoteScalar, |
| 2287 | DAG.getConstant(4, MVT::i32)))); |
| 2288 | } |
| 2289 | |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2290 | case ISD::ADD: { |
| 2291 | // Turn operands into vectors to satisfy type checking (shufb works on |
| 2292 | // vectors) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2293 | SDValue Op0 = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2294 | DAG.getNode(SPUISD::PROMOTE_SCALAR, MVT::v2i64, Op.getOperand(0)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2295 | SDValue Op1 = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2296 | DAG.getNode(SPUISD::PROMOTE_SCALAR, MVT::v2i64, Op.getOperand(1)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2297 | SmallVector<SDValue, 16> ShufBytes; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2298 | |
| 2299 | // Create the shuffle mask for "rotating" the borrow up one register slot |
| 2300 | // once the borrow is generated. |
| 2301 | ShufBytes.push_back(DAG.getConstant(0x04050607, MVT::i32)); |
| 2302 | ShufBytes.push_back(DAG.getConstant(0x80808080, MVT::i32)); |
| 2303 | ShufBytes.push_back(DAG.getConstant(0x0c0d0e0f, MVT::i32)); |
| 2304 | ShufBytes.push_back(DAG.getConstant(0x80808080, MVT::i32)); |
| 2305 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2306 | SDValue CarryGen = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2307 | DAG.getNode(SPUISD::CARRY_GENERATE, MVT::v2i64, Op0, Op1); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2308 | SDValue ShiftedCarry = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2309 | DAG.getNode(SPUISD::SHUFB, MVT::v2i64, |
| 2310 | CarryGen, CarryGen, |
| 2311 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, |
| 2312 | &ShufBytes[0], ShufBytes.size())); |
| 2313 | |
| 2314 | return DAG.getNode(SPUISD::EXTRACT_ELT0, MVT::i64, |
| 2315 | DAG.getNode(SPUISD::ADD_EXTENDED, MVT::v2i64, |
| 2316 | Op0, Op1, ShiftedCarry)); |
| 2317 | } |
| 2318 | |
| 2319 | case ISD::SUB: { |
| 2320 | // Turn operands into vectors to satisfy type checking (shufb works on |
| 2321 | // vectors) |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2322 | SDValue Op0 = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2323 | DAG.getNode(SPUISD::PROMOTE_SCALAR, MVT::v2i64, Op.getOperand(0)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2324 | SDValue Op1 = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2325 | DAG.getNode(SPUISD::PROMOTE_SCALAR, MVT::v2i64, Op.getOperand(1)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2326 | SmallVector<SDValue, 16> ShufBytes; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2327 | |
| 2328 | // Create the shuffle mask for "rotating" the borrow up one register slot |
| 2329 | // once the borrow is generated. |
| 2330 | ShufBytes.push_back(DAG.getConstant(0x04050607, MVT::i32)); |
| 2331 | ShufBytes.push_back(DAG.getConstant(0xc0c0c0c0, MVT::i32)); |
| 2332 | ShufBytes.push_back(DAG.getConstant(0x0c0d0e0f, MVT::i32)); |
| 2333 | ShufBytes.push_back(DAG.getConstant(0xc0c0c0c0, MVT::i32)); |
| 2334 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2335 | SDValue BorrowGen = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2336 | DAG.getNode(SPUISD::BORROW_GENERATE, MVT::v2i64, Op0, Op1); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2337 | SDValue ShiftedBorrow = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2338 | DAG.getNode(SPUISD::SHUFB, MVT::v2i64, |
| 2339 | BorrowGen, BorrowGen, |
| 2340 | DAG.getNode(ISD::BUILD_VECTOR, MVT::v4i32, |
| 2341 | &ShufBytes[0], ShufBytes.size())); |
| 2342 | |
| 2343 | return DAG.getNode(SPUISD::EXTRACT_ELT0, MVT::i64, |
| 2344 | DAG.getNode(SPUISD::SUB_EXTENDED, MVT::v2i64, |
| 2345 | Op0, Op1, ShiftedBorrow)); |
| 2346 | } |
| 2347 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2348 | case ISD::SHL: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2349 | SDValue ShiftAmt = Op.getOperand(1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2350 | MVT ShiftAmtVT = ShiftAmt.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2351 | SDValue Op0Vec = DAG.getNode(SPUISD::PROMOTE_SCALAR, VecVT, Op0); |
| 2352 | SDValue MaskLower = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2353 | DAG.getNode(SPUISD::SELB, VecVT, |
| 2354 | Op0Vec, |
| 2355 | DAG.getConstant(0, VecVT), |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2356 | DAG.getNode(SPUISD::SELECT_MASK, VecVT, |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2357 | DAG.getConstant(0xff00ULL, MVT::i16))); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2358 | SDValue ShiftAmtBytes = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2359 | DAG.getNode(ISD::SRL, ShiftAmtVT, |
| 2360 | ShiftAmt, |
| 2361 | DAG.getConstant(3, ShiftAmtVT)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2362 | SDValue ShiftAmtBits = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2363 | DAG.getNode(ISD::AND, ShiftAmtVT, |
| 2364 | ShiftAmt, |
| 2365 | DAG.getConstant(7, ShiftAmtVT)); |
| 2366 | |
| 2367 | return DAG.getNode(SPUISD::EXTRACT_ELT0, VT, |
| 2368 | DAG.getNode(SPUISD::SHLQUAD_L_BITS, VecVT, |
| 2369 | DAG.getNode(SPUISD::SHLQUAD_L_BYTES, VecVT, |
| 2370 | MaskLower, ShiftAmtBytes), |
| 2371 | ShiftAmtBits)); |
| 2372 | } |
| 2373 | |
| 2374 | case ISD::SRL: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2375 | MVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2376 | SDValue ShiftAmt = Op.getOperand(1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2377 | MVT ShiftAmtVT = ShiftAmt.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2378 | SDValue ShiftAmtBytes = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2379 | DAG.getNode(ISD::SRL, ShiftAmtVT, |
| 2380 | ShiftAmt, |
| 2381 | DAG.getConstant(3, ShiftAmtVT)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2382 | SDValue ShiftAmtBits = |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2383 | DAG.getNode(ISD::AND, ShiftAmtVT, |
| 2384 | ShiftAmt, |
| 2385 | DAG.getConstant(7, ShiftAmtVT)); |
| 2386 | |
| 2387 | return DAG.getNode(SPUISD::ROTQUAD_RZ_BITS, VT, |
| 2388 | DAG.getNode(SPUISD::ROTQUAD_RZ_BYTES, VT, |
| 2389 | Op0, ShiftAmtBytes), |
| 2390 | ShiftAmtBits); |
| 2391 | } |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2392 | |
| 2393 | case ISD::SRA: { |
| 2394 | // Promote Op0 to vector |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2395 | SDValue Op0 = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2396 | DAG.getNode(SPUISD::PROMOTE_SCALAR, MVT::v2i64, Op.getOperand(0)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2397 | SDValue ShiftAmt = Op.getOperand(1); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2398 | MVT ShiftVT = ShiftAmt.getValueType(); |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2399 | |
| 2400 | // Negate variable shift amounts |
| 2401 | if (!isa<ConstantSDNode>(ShiftAmt)) { |
| 2402 | ShiftAmt = DAG.getNode(ISD::SUB, ShiftVT, |
| 2403 | DAG.getConstant(0, ShiftVT), ShiftAmt); |
| 2404 | } |
| 2405 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2406 | SDValue UpperHalfSign = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2407 | DAG.getNode(SPUISD::EXTRACT_ELT0, MVT::i32, |
| 2408 | DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, |
| 2409 | DAG.getNode(SPUISD::VEC_SRA, MVT::v2i64, |
| 2410 | Op0, DAG.getConstant(31, MVT::i32)))); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2411 | SDValue UpperHalfSignMask = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2412 | DAG.getNode(SPUISD::SELECT_MASK, MVT::v2i64, UpperHalfSign); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2413 | SDValue UpperLowerMask = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2414 | DAG.getNode(SPUISD::SELECT_MASK, MVT::v2i64, |
| 2415 | DAG.getConstant(0xff00, MVT::i16)); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2416 | SDValue UpperLowerSelect = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2417 | DAG.getNode(SPUISD::SELB, MVT::v2i64, |
| 2418 | UpperHalfSignMask, Op0, UpperLowerMask); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2419 | SDValue RotateLeftBytes = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2420 | DAG.getNode(SPUISD::ROTBYTES_LEFT_BITS, MVT::v2i64, |
| 2421 | UpperLowerSelect, ShiftAmt); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2422 | SDValue RotateLeftBits = |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2423 | DAG.getNode(SPUISD::ROTBYTES_LEFT, MVT::v2i64, |
| 2424 | RotateLeftBytes, ShiftAmt); |
| 2425 | |
| 2426 | return DAG.getNode(SPUISD::EXTRACT_ELT0, MVT::i64, |
| 2427 | RotateLeftBits); |
| 2428 | } |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2431 | return SDValue(); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2432 | } |
| 2433 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2434 | //! Lower byte immediate operations for v16i8 vectors: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2435 | static SDValue |
| 2436 | LowerByteImmed(SDValue Op, SelectionDAG &DAG) { |
| 2437 | SDValue ConstVec; |
| 2438 | SDValue Arg; |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2439 | MVT VT = Op.getValueType(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2440 | |
| 2441 | ConstVec = Op.getOperand(0); |
| 2442 | Arg = Op.getOperand(1); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2443 | if (ConstVec.getNode()->getOpcode() != ISD::BUILD_VECTOR) { |
| 2444 | if (ConstVec.getNode()->getOpcode() == ISD::BIT_CONVERT) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2445 | ConstVec = ConstVec.getOperand(0); |
| 2446 | } else { |
| 2447 | ConstVec = Op.getOperand(1); |
| 2448 | Arg = Op.getOperand(0); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2449 | if (ConstVec.getNode()->getOpcode() == ISD::BIT_CONVERT) { |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2450 | ConstVec = ConstVec.getOperand(0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | } |
| 2454 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2455 | if (ConstVec.getNode()->getOpcode() == ISD::BUILD_VECTOR) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2456 | uint64_t VectorBits[2]; |
| 2457 | uint64_t UndefBits[2]; |
| 2458 | uint64_t SplatBits, SplatUndef; |
| 2459 | int SplatSize; |
| 2460 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2461 | if (!GetConstantBuildVectorBits(ConstVec.getNode(), VectorBits, UndefBits) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2462 | && isConstantSplat(VectorBits, UndefBits, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2463 | VT.getVectorElementType().getSizeInBits(), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2464 | SplatBits, SplatUndef, SplatSize)) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2465 | SDValue tcVec[16]; |
| 2466 | SDValue tc = DAG.getTargetConstant(SplatBits & 0xff, MVT::i8); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2467 | const size_t tcVecSize = sizeof(tcVec) / sizeof(tcVec[0]); |
| 2468 | |
| 2469 | // Turn the BUILD_VECTOR into a set of target constants: |
| 2470 | for (size_t i = 0; i < tcVecSize; ++i) |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2471 | tcVec[i] = tc; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2472 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2473 | return DAG.getNode(Op.getNode()->getOpcode(), VT, Arg, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2474 | DAG.getNode(ISD::BUILD_VECTOR, VT, tcVec, tcVecSize)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2475 | } |
| 2476 | } |
Nate Begeman | 24dc346 | 2008-07-29 19:07:27 +0000 | [diff] [blame] | 2477 | // These operations (AND, OR, XOR) are legal, they just couldn't be custom |
| 2478 | // lowered. Return the operation, rather than a null SDValue. |
| 2479 | return Op; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | //! Lower i32 multiplication |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2483 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG, MVT VT, |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2484 | unsigned Opc) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2485 | switch (VT.getSimpleVT()) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2486 | default: |
| 2487 | cerr << "CellSPU: Unknown LowerMUL value type, got " |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2488 | << Op.getValueType().getMVTString() |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2489 | << "\n"; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2490 | abort(); |
| 2491 | /*NOTREACHED*/ |
| 2492 | |
| 2493 | case MVT::i32: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2494 | SDValue rA = Op.getOperand(0); |
| 2495 | SDValue rB = Op.getOperand(1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2496 | |
| 2497 | return DAG.getNode(ISD::ADD, MVT::i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2498 | DAG.getNode(ISD::ADD, MVT::i32, |
| 2499 | DAG.getNode(SPUISD::MPYH, MVT::i32, rA, rB), |
| 2500 | DAG.getNode(SPUISD::MPYH, MVT::i32, rB, rA)), |
| 2501 | DAG.getNode(SPUISD::MPYU, MVT::i32, rA, rB)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2502 | } |
| 2503 | } |
| 2504 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2505 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | //! Custom lowering for CTPOP (count population) |
| 2509 | /*! |
| 2510 | Custom lowering code that counts the number ones in the input |
| 2511 | operand. SPU has such an instruction, but it counts the number of |
| 2512 | ones per byte, which then have to be accumulated. |
| 2513 | */ |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2514 | static SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2515 | MVT VT = Op.getValueType(); |
| 2516 | MVT vecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits())); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2517 | |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2518 | switch (VT.getSimpleVT()) { |
| 2519 | default: |
| 2520 | assert(false && "Invalid value type!"); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2521 | case MVT::i8: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2522 | SDValue N = Op.getOperand(0); |
| 2523 | SDValue Elt0 = DAG.getConstant(0, MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2524 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2525 | SDValue Promote = DAG.getNode(SPUISD::PROMOTE_SCALAR, vecVT, N, N); |
| 2526 | SDValue CNTB = DAG.getNode(SPUISD::CNTB, vecVT, Promote); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2527 | |
| 2528 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, MVT::i8, CNTB, Elt0); |
| 2529 | } |
| 2530 | |
| 2531 | case MVT::i16: { |
| 2532 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2533 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2534 | |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2535 | unsigned CNTB_reg = RegInfo.createVirtualRegister(&SPU::R16CRegClass); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2536 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2537 | SDValue N = Op.getOperand(0); |
| 2538 | SDValue Elt0 = DAG.getConstant(0, MVT::i16); |
| 2539 | SDValue Mask0 = DAG.getConstant(0x0f, MVT::i16); |
Duncan Sands | fa7935f | 2008-10-30 19:24:28 +0000 | [diff] [blame] | 2540 | SDValue Shift1 = DAG.getConstant(8, MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2541 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2542 | SDValue Promote = DAG.getNode(SPUISD::PROMOTE_SCALAR, vecVT, N, N); |
| 2543 | SDValue CNTB = DAG.getNode(SPUISD::CNTB, vecVT, Promote); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2544 | |
| 2545 | // CNTB_result becomes the chain to which all of the virtual registers |
| 2546 | // CNTB_reg, SUM1_reg become associated: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2547 | SDValue CNTB_result = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2548 | DAG.getNode(ISD::EXTRACT_VECTOR_ELT, MVT::i16, CNTB, Elt0); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2549 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2550 | SDValue CNTB_rescopy = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2551 | DAG.getCopyToReg(CNTB_result, CNTB_reg, CNTB_result); |
| 2552 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2553 | SDValue Tmp1 = DAG.getCopyFromReg(CNTB_rescopy, CNTB_reg, MVT::i16); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2554 | |
| 2555 | return DAG.getNode(ISD::AND, MVT::i16, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2556 | DAG.getNode(ISD::ADD, MVT::i16, |
| 2557 | DAG.getNode(ISD::SRL, MVT::i16, |
| 2558 | Tmp1, Shift1), |
| 2559 | Tmp1), |
| 2560 | Mask0); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | case MVT::i32: { |
| 2564 | MachineFunction &MF = DAG.getMachineFunction(); |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2565 | MachineRegisterInfo &RegInfo = MF.getRegInfo(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2566 | |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 2567 | unsigned CNTB_reg = RegInfo.createVirtualRegister(&SPU::R32CRegClass); |
| 2568 | unsigned SUM1_reg = RegInfo.createVirtualRegister(&SPU::R32CRegClass); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2569 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2570 | SDValue N = Op.getOperand(0); |
| 2571 | SDValue Elt0 = DAG.getConstant(0, MVT::i32); |
| 2572 | SDValue Mask0 = DAG.getConstant(0xff, MVT::i32); |
| 2573 | SDValue Shift1 = DAG.getConstant(16, MVT::i32); |
| 2574 | SDValue Shift2 = DAG.getConstant(8, MVT::i32); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2575 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2576 | SDValue Promote = DAG.getNode(SPUISD::PROMOTE_SCALAR, vecVT, N, N); |
| 2577 | SDValue CNTB = DAG.getNode(SPUISD::CNTB, vecVT, Promote); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2578 | |
| 2579 | // CNTB_result becomes the chain to which all of the virtual registers |
| 2580 | // CNTB_reg, SUM1_reg become associated: |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2581 | SDValue CNTB_result = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2582 | DAG.getNode(ISD::EXTRACT_VECTOR_ELT, MVT::i32, CNTB, Elt0); |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2583 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2584 | SDValue CNTB_rescopy = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2585 | DAG.getCopyToReg(CNTB_result, CNTB_reg, CNTB_result); |
| 2586 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2587 | SDValue Comp1 = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2588 | DAG.getNode(ISD::SRL, MVT::i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2589 | DAG.getCopyFromReg(CNTB_rescopy, CNTB_reg, MVT::i32), Shift1); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2590 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2591 | SDValue Sum1 = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2592 | DAG.getNode(ISD::ADD, MVT::i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2593 | Comp1, DAG.getCopyFromReg(CNTB_rescopy, CNTB_reg, MVT::i32)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2594 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2595 | SDValue Sum1_rescopy = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2596 | DAG.getCopyToReg(CNTB_result, SUM1_reg, Sum1); |
| 2597 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2598 | SDValue Comp2 = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2599 | DAG.getNode(ISD::SRL, MVT::i32, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2600 | DAG.getCopyFromReg(Sum1_rescopy, SUM1_reg, MVT::i32), |
| 2601 | Shift2); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2602 | SDValue Sum2 = |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2603 | DAG.getNode(ISD::ADD, MVT::i32, Comp2, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2604 | DAG.getCopyFromReg(Sum1_rescopy, SUM1_reg, MVT::i32)); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2605 | |
| 2606 | return DAG.getNode(ISD::AND, MVT::i32, Sum2, Mask0); |
| 2607 | } |
| 2608 | |
| 2609 | case MVT::i64: |
| 2610 | break; |
| 2611 | } |
| 2612 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2613 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 2617 | /// |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2618 | SDValue |
| 2619 | SPUTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2620 | { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2621 | unsigned Opc = (unsigned) Op.getOpcode(); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2622 | MVT VT = Op.getValueType(); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2623 | |
| 2624 | switch (Opc) { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2625 | default: { |
| 2626 | cerr << "SPUTargetLowering::LowerOperation(): need to lower this!\n"; |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2627 | cerr << "Op.getOpcode() = " << Opc << "\n"; |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2628 | cerr << "*Op.getNode():\n"; |
| 2629 | Op.getNode()->dump(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2630 | abort(); |
| 2631 | } |
| 2632 | case ISD::LOAD: |
| 2633 | case ISD::SEXTLOAD: |
| 2634 | case ISD::ZEXTLOAD: |
| 2635 | return LowerLOAD(Op, DAG, SPUTM.getSubtargetImpl()); |
| 2636 | case ISD::STORE: |
| 2637 | return LowerSTORE(Op, DAG, SPUTM.getSubtargetImpl()); |
| 2638 | case ISD::ConstantPool: |
| 2639 | return LowerConstantPool(Op, DAG, SPUTM.getSubtargetImpl()); |
| 2640 | case ISD::GlobalAddress: |
| 2641 | return LowerGlobalAddress(Op, DAG, SPUTM.getSubtargetImpl()); |
| 2642 | case ISD::JumpTable: |
| 2643 | return LowerJumpTable(Op, DAG, SPUTM.getSubtargetImpl()); |
| 2644 | case ISD::Constant: |
| 2645 | return LowerConstant(Op, DAG); |
| 2646 | case ISD::ConstantFP: |
| 2647 | return LowerConstantFP(Op, DAG); |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 2648 | case ISD::BRCOND: |
| 2649 | return LowerBRCOND(Op, DAG); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2650 | case ISD::FORMAL_ARGUMENTS: |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 2651 | return LowerFORMAL_ARGUMENTS(Op, DAG, VarArgsFrameIndex); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2652 | case ISD::CALL: |
Scott Michel | 9de5d0d | 2008-01-11 02:53:15 +0000 | [diff] [blame] | 2653 | return LowerCALL(Op, DAG, SPUTM.getSubtargetImpl()); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2654 | case ISD::RET: |
| 2655 | return LowerRET(Op, DAG, getTargetMachine()); |
| 2656 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2657 | |
| 2658 | // i8, i64 math ops: |
| 2659 | case ISD::ZERO_EXTEND: |
| 2660 | case ISD::SIGN_EXTEND: |
| 2661 | case ISD::ANY_EXTEND: |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2662 | case ISD::ADD: |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2663 | case ISD::SUB: |
| 2664 | case ISD::ROTR: |
| 2665 | case ISD::ROTL: |
| 2666 | case ISD::SRL: |
| 2667 | case ISD::SHL: |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2668 | case ISD::SRA: { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2669 | if (VT == MVT::i8) |
| 2670 | return LowerI8Math(Op, DAG, Opc); |
| 2671 | else if (VT == MVT::i64) |
| 2672 | return LowerI64Math(Op, DAG, Opc); |
| 2673 | break; |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2674 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2675 | |
| 2676 | // Vector-related lowering. |
| 2677 | case ISD::BUILD_VECTOR: |
| 2678 | return LowerBUILD_VECTOR(Op, DAG); |
| 2679 | case ISD::SCALAR_TO_VECTOR: |
| 2680 | return LowerSCALAR_TO_VECTOR(Op, DAG); |
| 2681 | case ISD::VECTOR_SHUFFLE: |
| 2682 | return LowerVECTOR_SHUFFLE(Op, DAG); |
| 2683 | case ISD::EXTRACT_VECTOR_ELT: |
| 2684 | return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| 2685 | case ISD::INSERT_VECTOR_ELT: |
| 2686 | return LowerINSERT_VECTOR_ELT(Op, DAG); |
| 2687 | |
| 2688 | // Look for ANDBI, ORBI and XORBI opportunities and lower appropriately: |
| 2689 | case ISD::AND: |
| 2690 | case ISD::OR: |
| 2691 | case ISD::XOR: |
| 2692 | return LowerByteImmed(Op, DAG); |
| 2693 | |
| 2694 | // Vector and i8 multiply: |
| 2695 | case ISD::MUL: |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2696 | if (VT.isVector()) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2697 | return LowerVectorMUL(Op, DAG); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2698 | else if (VT == MVT::i8) |
| 2699 | return LowerI8Math(Op, DAG, Opc); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2700 | else |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2701 | return LowerMUL(Op, DAG, VT, Opc); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2702 | |
| 2703 | case ISD::FDIV: |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2704 | if (VT == MVT::f32 || VT == MVT::v4f32) |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2705 | return LowerFDIVf32(Op, DAG); |
| 2706 | // else if (Op.getValueType() == MVT::f64) |
| 2707 | // return LowerFDIVf64(Op, DAG); |
| 2708 | else |
| 2709 | assert(0 && "Calling FDIV on unsupported MVT"); |
| 2710 | |
| 2711 | case ISD::CTPOP: |
| 2712 | return LowerCTPOP(Op, DAG); |
| 2713 | } |
| 2714 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2715 | return SDValue(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2716 | } |
| 2717 | |
Scott Michel | 73ce1c5 | 2008-11-10 23:43:06 +0000 | [diff] [blame] | 2718 | SDNode *SPUTargetLowering::ReplaceNodeResults(SDNode *N, SelectionDAG &DAG) |
| 2719 | { |
| 2720 | #if 0 |
| 2721 | unsigned Opc = (unsigned) N->getOpcode(); |
| 2722 | MVT OpVT = N->getValueType(0); |
| 2723 | |
| 2724 | switch (Opc) { |
| 2725 | default: { |
| 2726 | cerr << "SPUTargetLowering::ReplaceNodeResults(): need to fix this!\n"; |
| 2727 | cerr << "Op.getOpcode() = " << Opc << "\n"; |
| 2728 | cerr << "*Op.getNode():\n"; |
| 2729 | N->dump(); |
| 2730 | abort(); |
| 2731 | /*NOTREACHED*/ |
| 2732 | } |
| 2733 | } |
| 2734 | #endif |
| 2735 | |
| 2736 | /* Otherwise, return unchanged */ |
| 2737 | return 0; |
| 2738 | } |
| 2739 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2740 | //===----------------------------------------------------------------------===// |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2741 | // Target Optimization Hooks |
| 2742 | //===----------------------------------------------------------------------===// |
| 2743 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2744 | SDValue |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2745 | SPUTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const |
| 2746 | { |
| 2747 | #if 0 |
| 2748 | TargetMachine &TM = getTargetMachine(); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2749 | #endif |
| 2750 | const SPUSubtarget *ST = SPUTM.getSubtargetImpl(); |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2751 | SelectionDAG &DAG = DCI.DAG; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2752 | SDValue Op0 = N->getOperand(0); // everything has at least one operand |
| 2753 | SDValue Result; // Initially, NULL result |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2754 | |
| 2755 | switch (N->getOpcode()) { |
| 2756 | default: break; |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2757 | case ISD::ADD: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2758 | SDValue Op1 = N->getOperand(1); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2759 | |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2760 | if (isa<ConstantSDNode>(Op1) && Op0.getOpcode() == SPUISD::IndirectAddr) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2761 | SDValue Op01 = Op0.getOperand(1); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2762 | if (Op01.getOpcode() == ISD::Constant |
| 2763 | || Op01.getOpcode() == ISD::TargetConstant) { |
| 2764 | // (add <const>, (SPUindirect <arg>, <const>)) -> |
| 2765 | // (SPUindirect <arg>, <const + const>) |
| 2766 | ConstantSDNode *CN0 = cast<ConstantSDNode>(Op1); |
| 2767 | ConstantSDNode *CN1 = cast<ConstantSDNode>(Op01); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2768 | SDValue combinedConst = |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2769 | DAG.getConstant(CN0->getZExtValue() + CN1->getZExtValue(), |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2770 | Op0.getValueType()); |
| 2771 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2772 | DEBUG(cerr << "Replace: (add " << CN0->getZExtValue() << ", " |
| 2773 | << "(SPUindirect <arg>, " << CN1->getZExtValue() << "))\n"); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2774 | DEBUG(cerr << "With: (SPUindirect <arg>, " |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2775 | << CN0->getZExtValue() + CN1->getZExtValue() << ")\n"); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2776 | return DAG.getNode(SPUISD::IndirectAddr, Op0.getValueType(), |
| 2777 | Op0.getOperand(0), combinedConst); |
| 2778 | } |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 2779 | } else if (isa<ConstantSDNode>(Op0) |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2780 | && Op1.getOpcode() == SPUISD::IndirectAddr) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2781 | SDValue Op11 = Op1.getOperand(1); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2782 | if (Op11.getOpcode() == ISD::Constant |
| 2783 | || Op11.getOpcode() == ISD::TargetConstant) { |
| 2784 | // (add (SPUindirect <arg>, <const>), <const>) -> |
| 2785 | // (SPUindirect <arg>, <const + const>) |
| 2786 | ConstantSDNode *CN0 = cast<ConstantSDNode>(Op0); |
| 2787 | ConstantSDNode *CN1 = cast<ConstantSDNode>(Op11); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2788 | SDValue combinedConst = |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2789 | DAG.getConstant(CN0->getZExtValue() + CN1->getZExtValue(), |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2790 | Op0.getValueType()); |
| 2791 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2792 | DEBUG(cerr << "Replace: (add " << CN0->getZExtValue() << ", " |
| 2793 | << "(SPUindirect <arg>, " << CN1->getZExtValue() << "))\n"); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2794 | DEBUG(cerr << "With: (SPUindirect <arg>, " |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2795 | << CN0->getZExtValue() + CN1->getZExtValue() << ")\n"); |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2796 | |
| 2797 | return DAG.getNode(SPUISD::IndirectAddr, Op1.getValueType(), |
| 2798 | Op1.getOperand(0), combinedConst); |
| 2799 | } |
| 2800 | } |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2801 | break; |
| 2802 | } |
| 2803 | case ISD::SIGN_EXTEND: |
| 2804 | case ISD::ZERO_EXTEND: |
| 2805 | case ISD::ANY_EXTEND: { |
| 2806 | if (Op0.getOpcode() == SPUISD::EXTRACT_ELT0 && |
| 2807 | N->getValueType(0) == Op0.getValueType()) { |
| 2808 | // (any_extend (SPUextract_elt0 <arg>)) -> |
| 2809 | // (SPUextract_elt0 <arg>) |
| 2810 | // Types must match, however... |
| 2811 | DEBUG(cerr << "Replace: "); |
| 2812 | DEBUG(N->dump(&DAG)); |
| 2813 | DEBUG(cerr << "\nWith: "); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2814 | DEBUG(Op0.getNode()->dump(&DAG)); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2815 | DEBUG(cerr << "\n"); |
| 2816 | |
| 2817 | return Op0; |
| 2818 | } |
| 2819 | break; |
| 2820 | } |
| 2821 | case SPUISD::IndirectAddr: { |
| 2822 | if (!ST->usingLargeMem() && Op0.getOpcode() == SPUISD::AFormAddr) { |
| 2823 | ConstantSDNode *CN = cast<ConstantSDNode>(N->getOperand(1)); |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2824 | if (CN->getZExtValue() == 0) { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2825 | // (SPUindirect (SPUaform <addr>, 0), 0) -> |
| 2826 | // (SPUaform <addr>, 0) |
| 2827 | |
| 2828 | DEBUG(cerr << "Replace: "); |
| 2829 | DEBUG(N->dump(&DAG)); |
| 2830 | DEBUG(cerr << "\nWith: "); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2831 | DEBUG(Op0.getNode()->dump(&DAG)); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2832 | DEBUG(cerr << "\n"); |
| 2833 | |
| 2834 | return Op0; |
| 2835 | } |
| 2836 | } |
| 2837 | break; |
| 2838 | } |
| 2839 | case SPUISD::SHLQUAD_L_BITS: |
| 2840 | case SPUISD::SHLQUAD_L_BYTES: |
| 2841 | case SPUISD::VEC_SHL: |
| 2842 | case SPUISD::VEC_SRL: |
| 2843 | case SPUISD::VEC_SRA: |
| 2844 | case SPUISD::ROTQUAD_RZ_BYTES: |
| 2845 | case SPUISD::ROTQUAD_RZ_BITS: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2846 | SDValue Op1 = N->getOperand(1); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2847 | |
| 2848 | if (isa<ConstantSDNode>(Op1)) { |
| 2849 | // Kill degenerate vector shifts: |
| 2850 | ConstantSDNode *CN = cast<ConstantSDNode>(Op1); |
| 2851 | |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2852 | if (CN->getZExtValue() == 0) { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2853 | Result = Op0; |
| 2854 | } |
| 2855 | } |
| 2856 | break; |
| 2857 | } |
| 2858 | case SPUISD::PROMOTE_SCALAR: { |
| 2859 | switch (Op0.getOpcode()) { |
| 2860 | default: |
| 2861 | break; |
| 2862 | case ISD::ANY_EXTEND: |
| 2863 | case ISD::ZERO_EXTEND: |
| 2864 | case ISD::SIGN_EXTEND: { |
| 2865 | // (SPUpromote_scalar (any|sign|zero_extend (SPUextract_elt0 <arg>))) -> |
| 2866 | // <arg> |
| 2867 | // but only if the SPUpromote_scalar and <arg> types match. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2868 | SDValue Op00 = Op0.getOperand(0); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2869 | if (Op00.getOpcode() == SPUISD::EXTRACT_ELT0) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2870 | SDValue Op000 = Op00.getOperand(0); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2871 | if (Op000.getValueType() == N->getValueType(0)) { |
| 2872 | Result = Op000; |
| 2873 | } |
| 2874 | } |
| 2875 | break; |
| 2876 | } |
| 2877 | case SPUISD::EXTRACT_ELT0: { |
| 2878 | // (SPUpromote_scalar (SPUextract_elt0 <arg>)) -> |
| 2879 | // <arg> |
| 2880 | Result = Op0.getOperand(0); |
| 2881 | break; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2882 | } |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2883 | } |
| 2884 | break; |
Scott Michel | 053c1da | 2008-01-29 02:16:57 +0000 | [diff] [blame] | 2885 | } |
| 2886 | } |
Scott Michel | 58c5818 | 2008-01-17 20:38:41 +0000 | [diff] [blame] | 2887 | // Otherwise, return unchanged. |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 2888 | #if 1 |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2889 | if (Result.getNode()) { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2890 | DEBUG(cerr << "\nReplace.SPU: "); |
| 2891 | DEBUG(N->dump(&DAG)); |
| 2892 | DEBUG(cerr << "\nWith: "); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2893 | DEBUG(Result.getNode()->dump(&DAG)); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2894 | DEBUG(cerr << "\n"); |
| 2895 | } |
| 2896 | #endif |
| 2897 | |
| 2898 | return Result; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | //===----------------------------------------------------------------------===// |
| 2902 | // Inline Assembly Support |
| 2903 | //===----------------------------------------------------------------------===// |
| 2904 | |
| 2905 | /// getConstraintType - Given a constraint letter, return the type of |
| 2906 | /// constraint it is for this target. |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2907 | SPUTargetLowering::ConstraintType |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2908 | SPUTargetLowering::getConstraintType(const std::string &ConstraintLetter) const { |
| 2909 | if (ConstraintLetter.size() == 1) { |
| 2910 | switch (ConstraintLetter[0]) { |
| 2911 | default: break; |
| 2912 | case 'b': |
| 2913 | case 'r': |
| 2914 | case 'f': |
| 2915 | case 'v': |
| 2916 | case 'y': |
| 2917 | return C_RegisterClass; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2918 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2919 | } |
| 2920 | return TargetLowering::getConstraintType(ConstraintLetter); |
| 2921 | } |
| 2922 | |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2923 | std::pair<unsigned, const TargetRegisterClass*> |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2924 | SPUTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2925 | MVT VT) const |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2926 | { |
| 2927 | if (Constraint.size() == 1) { |
| 2928 | // GCC RS6000 Constraint Letters |
| 2929 | switch (Constraint[0]) { |
| 2930 | case 'b': // R1-R31 |
| 2931 | case 'r': // R0-R31 |
| 2932 | if (VT == MVT::i64) |
| 2933 | return std::make_pair(0U, SPU::R64CRegisterClass); |
| 2934 | return std::make_pair(0U, SPU::R32CRegisterClass); |
| 2935 | case 'f': |
| 2936 | if (VT == MVT::f32) |
| 2937 | return std::make_pair(0U, SPU::R32FPRegisterClass); |
| 2938 | else if (VT == MVT::f64) |
| 2939 | return std::make_pair(0U, SPU::R64FPRegisterClass); |
| 2940 | break; |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2941 | case 'v': |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2942 | return std::make_pair(0U, SPU::GPRCRegisterClass); |
| 2943 | } |
| 2944 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2945 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2946 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 2947 | } |
| 2948 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2949 | //! Compute used/known bits for a SPU operand |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 2950 | void |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2951 | SPUTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 2952 | const APInt &Mask, |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2953 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 2954 | APInt &KnownOne, |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 2955 | const SelectionDAG &DAG, |
| 2956 | unsigned Depth ) const { |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 2957 | #if 0 |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2958 | const uint64_t uint64_sizebits = sizeof(uint64_t) * 8; |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 2959 | #endif |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2960 | |
| 2961 | switch (Op.getOpcode()) { |
| 2962 | default: |
| 2963 | // KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
| 2964 | break; |
| 2965 | |
| 2966 | #if 0 |
| 2967 | case CALL: |
| 2968 | case SHUFB: |
| 2969 | case INSERT_MASK: |
| 2970 | case CNTB: |
| 2971 | #endif |
| 2972 | |
| 2973 | case SPUISD::PROMOTE_SCALAR: { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2974 | SDValue Op0 = Op.getOperand(0); |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2975 | MVT Op0VT = Op0.getValueType(); |
| 2976 | unsigned Op0VTBits = Op0VT.getSizeInBits(); |
| 2977 | uint64_t InMask = Op0VT.getIntegerVTBitMask(); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 2978 | KnownZero |= APInt(Op0VTBits, ~InMask, false); |
| 2979 | KnownOne |= APInt(Op0VTBits, InMask, false); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2980 | break; |
| 2981 | } |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 2982 | |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2983 | case SPUISD::LDRESULT: |
| 2984 | case SPUISD::EXTRACT_ELT0: |
| 2985 | case SPUISD::EXTRACT_ELT0_CHAINED: { |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 2986 | MVT OpVT = Op.getValueType(); |
| 2987 | unsigned OpVTBits = OpVT.getSizeInBits(); |
| 2988 | uint64_t InMask = OpVT.getIntegerVTBitMask(); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 2989 | KnownZero |= APInt(OpVTBits, ~InMask, false); |
| 2990 | KnownOne |= APInt(OpVTBits, InMask, false); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 2991 | break; |
| 2992 | } |
| 2993 | |
| 2994 | #if 0 |
| 2995 | case EXTRACT_I1_ZEXT: |
| 2996 | case EXTRACT_I1_SEXT: |
| 2997 | case EXTRACT_I8_ZEXT: |
| 2998 | case EXTRACT_I8_SEXT: |
| 2999 | case MPY: |
| 3000 | case MPYU: |
| 3001 | case MPYH: |
| 3002 | case MPYHH: |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 3003 | case SPUISD::SHLQUAD_L_BITS: |
| 3004 | case SPUISD::SHLQUAD_L_BYTES: |
| 3005 | case SPUISD::VEC_SHL: |
| 3006 | case SPUISD::VEC_SRL: |
| 3007 | case SPUISD::VEC_SRA: |
| 3008 | case SPUISD::VEC_ROTL: |
| 3009 | case SPUISD::VEC_ROTR: |
| 3010 | case SPUISD::ROTQUAD_RZ_BYTES: |
| 3011 | case SPUISD::ROTQUAD_RZ_BITS: |
| 3012 | case SPUISD::ROTBYTES_RIGHT_S: |
| 3013 | case SPUISD::ROTBYTES_LEFT: |
| 3014 | case SPUISD::ROTBYTES_LEFT_CHAINED: |
Scott Michel | 8bf61e8 | 2008-06-02 22:18:03 +0000 | [diff] [blame] | 3015 | case SPUISD::SELECT_MASK: |
| 3016 | case SPUISD::SELB: |
| 3017 | case SPUISD::FPInterp: |
| 3018 | case SPUISD::FPRecipEst: |
| 3019 | case SPUISD::SEXT32TO64: |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 3020 | #endif |
| 3021 | } |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 3022 | } |
| 3023 | |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 3024 | // LowerAsmOperandForConstraint |
| 3025 | void |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3026 | SPUTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 3027 | char ConstraintLetter, |
Evan Cheng | da43bcf | 2008-09-24 00:05:32 +0000 | [diff] [blame] | 3028 | bool hasMemory, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3029 | std::vector<SDValue> &Ops, |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 3030 | SelectionDAG &DAG) const { |
| 3031 | // Default, for the time being, to the base class handler |
Evan Cheng | da43bcf | 2008-09-24 00:05:32 +0000 | [diff] [blame] | 3032 | TargetLowering::LowerAsmOperandForConstraint(Op, ConstraintLetter, hasMemory, |
| 3033 | Ops, DAG); |
Scott Michel | 203b2d6 | 2008-04-30 00:30:08 +0000 | [diff] [blame] | 3034 | } |
| 3035 | |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 3036 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 3037 | /// as the offset of the target addressing mode. |
Gabor Greif | 93c53e5 | 2008-08-31 15:37:04 +0000 | [diff] [blame] | 3038 | bool SPUTargetLowering::isLegalAddressImmediate(int64_t V, |
| 3039 | const Type *Ty) const { |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 3040 | // SPU's addresses are 256K: |
| 3041 | return (V > -(1 << 18) && V < (1 << 18) - 1); |
| 3042 | } |
| 3043 | |
| 3044 | bool SPUTargetLowering::isLegalAddressImmediate(llvm::GlobalValue* GV) const { |
Scott Michel | 5af8f0e | 2008-07-16 17:17:29 +0000 | [diff] [blame] | 3045 | return false; |
Scott Michel | 266bc8f | 2007-12-04 22:23:35 +0000 | [diff] [blame] | 3046 | } |
Dan Gohman | 6520e20 | 2008-10-18 02:06:02 +0000 | [diff] [blame] | 3047 | |
| 3048 | bool |
| 3049 | SPUTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 3050 | // The SPU target isn't yet aware of offsets. |
| 3051 | return false; |
| 3052 | } |