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