Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 1 | //===- SPUInstrInfo.cpp - Cell SPU Instruction Information ----------------===// |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the Cell SPU implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SPURegisterNames.h" |
| 15 | #include "SPUInstrInfo.h" |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 16 | #include "SPUInstrBuilder.h" |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 17 | #include "SPUTargetMachine.h" |
| 18 | #include "SPUGenInstrInfo.inc" |
| 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Bill Wendling | eecfa36 | 2008-05-29 21:46:33 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Streams.h" |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 21 | |
| 22 | using namespace llvm; |
| 23 | |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 24 | namespace { |
| 25 | //! Predicate for an unconditional branch instruction |
| 26 | inline bool isUncondBranch(const MachineInstr *I) { |
| 27 | unsigned opc = I->getOpcode(); |
| 28 | |
| 29 | return (opc == SPU::BR |
| 30 | || opc == SPU::BRA |
| 31 | || opc == SPU::BI); |
| 32 | } |
| 33 | |
| 34 | inline bool isCondBranch(const MachineInstr *I) { |
| 35 | unsigned opc = I->getOpcode(); |
| 36 | |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 37 | return (opc == SPU::BRNZr32 |
| 38 | || opc == SPU::BRNZv4i32 |
| 39 | || opc == SPU::BRZr32 |
| 40 | || opc == SPU::BRZv4i32 |
| 41 | || opc == SPU::BRHNZr16 |
| 42 | || opc == SPU::BRHNZv8i16 |
| 43 | || opc == SPU::BRHZr16 |
| 44 | || opc == SPU::BRHZv8i16); |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 48 | SPUInstrInfo::SPUInstrInfo(SPUTargetMachine &tm) |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 49 | : TargetInstrInfoImpl(SPUInsts, sizeof(SPUInsts)/sizeof(SPUInsts[0])), |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 50 | TM(tm), |
| 51 | RI(*TM.getSubtargetImpl(), *this) |
| 52 | { |
| 53 | /* NOP */ |
| 54 | } |
| 55 | |
| 56 | /// getPointerRegClass - Return the register class to use to hold pointers. |
| 57 | /// This is used for addressing modes. |
| 58 | const TargetRegisterClass * |
| 59 | SPUInstrInfo::getPointerRegClass() const |
| 60 | { |
| 61 | return &SPU::R32CRegClass; |
| 62 | } |
| 63 | |
| 64 | bool |
| 65 | SPUInstrInfo::isMoveInstr(const MachineInstr& MI, |
| 66 | unsigned& sourceReg, |
| 67 | unsigned& destReg) const { |
| 68 | // Primarily, ORI and OR are generated by copyRegToReg. But, there are other |
| 69 | // cases where we can safely say that what's being done is really a move |
| 70 | // (see how PowerPC does this -- it's the model for this code too.) |
| 71 | switch (MI.getOpcode()) { |
| 72 | default: |
| 73 | break; |
| 74 | case SPU::ORIv4i32: |
| 75 | case SPU::ORIr32: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 76 | case SPU::ORHIv8i16: |
| 77 | case SPU::ORHIr16: |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 78 | case SPU::ORHIi8i16: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 79 | case SPU::ORBIv16i8: |
Scott Michel | 504c369 | 2007-12-17 22:32:34 +0000 | [diff] [blame] | 80 | case SPU::ORBIr8: |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 81 | case SPU::ORIi16i32: |
| 82 | case SPU::ORIi8i32: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 83 | case SPU::AHIvec: |
| 84 | case SPU::AHIr16: |
| 85 | case SPU::AIvec: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 86 | assert(MI.getNumOperands() == 3 && |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 87 | MI.getOperand(0).isReg() && |
| 88 | MI.getOperand(1).isReg() && |
| 89 | MI.getOperand(2).isImm() && |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 90 | "invalid SPU ORI/ORHI/ORBI/AHI/AI/SFI/SFHI instruction!"); |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 91 | if (MI.getOperand(2).getImm() == 0) { |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 92 | sourceReg = MI.getOperand(1).getReg(); |
| 93 | destReg = MI.getOperand(0).getReg(); |
| 94 | return true; |
| 95 | } |
| 96 | break; |
Scott Michel | 9999e68 | 2007-12-19 07:35:06 +0000 | [diff] [blame] | 97 | case SPU::AIr32: |
| 98 | assert(MI.getNumOperands() == 3 && |
| 99 | "wrong number of operands to AIr32"); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 100 | if (MI.getOperand(0).isReg() && |
| 101 | (MI.getOperand(1).isReg() || |
| 102 | MI.getOperand(1).isFI()) && |
| 103 | (MI.getOperand(2).isImm() && |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 104 | MI.getOperand(2).getImm() == 0)) { |
Scott Michel | 9999e68 | 2007-12-19 07:35:06 +0000 | [diff] [blame] | 105 | sourceReg = MI.getOperand(1).getReg(); |
| 106 | destReg = MI.getOperand(0).getReg(); |
| 107 | return true; |
| 108 | } |
| 109 | break; |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 110 | case SPU::LRr8: |
| 111 | case SPU::LRr16: |
| 112 | case SPU::LRr32: |
| 113 | case SPU::LRf32: |
| 114 | case SPU::LRr64: |
| 115 | case SPU::LRf64: |
| 116 | case SPU::LRr128: |
| 117 | case SPU::LRv16i8: |
| 118 | case SPU::LRv8i16: |
| 119 | case SPU::LRv4i32: |
| 120 | case SPU::LRv4f32: |
| 121 | case SPU::LRv2i64: |
| 122 | case SPU::LRv2f64: |
Scott Michel | 170783a | 2007-12-19 20:15:47 +0000 | [diff] [blame] | 123 | case SPU::ORv16i8_i8: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 124 | case SPU::ORv8i16_i16: |
| 125 | case SPU::ORv4i32_i32: |
| 126 | case SPU::ORv2i64_i64: |
| 127 | case SPU::ORv4f32_f32: |
| 128 | case SPU::ORv2f64_f64: |
Scott Michel | 170783a | 2007-12-19 20:15:47 +0000 | [diff] [blame] | 129 | case SPU::ORi8_v16i8: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 130 | case SPU::ORi16_v8i16: |
| 131 | case SPU::ORi32_v4i32: |
| 132 | case SPU::ORi64_v2i64: |
| 133 | case SPU::ORf32_v4f32: |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 134 | case SPU::ORf64_v2f64: { |
| 135 | assert(MI.getNumOperands() == 2 && |
| 136 | MI.getOperand(0).isReg() && |
| 137 | MI.getOperand(1).isReg() && |
| 138 | "invalid SPU OR<type>_<vec> instruction!"); |
| 139 | if (MI.getOperand(0).getReg() == MI.getOperand(1).getReg()) { |
| 140 | sourceReg = MI.getOperand(0).getReg(); |
| 141 | destReg = MI.getOperand(0).getReg(); |
| 142 | return true; |
| 143 | } |
| 144 | break; |
| 145 | } |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 146 | case SPU::ORv16i8: |
| 147 | case SPU::ORv8i16: |
| 148 | case SPU::ORv4i32: |
| 149 | case SPU::ORr32: |
| 150 | case SPU::ORr64: |
Scott Michel | 86c041f | 2007-12-20 00:44:13 +0000 | [diff] [blame] | 151 | case SPU::ORf32: |
| 152 | case SPU::ORf64: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 153 | assert(MI.getNumOperands() == 3 && |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 154 | MI.getOperand(0).isReg() && |
| 155 | MI.getOperand(1).isReg() && |
| 156 | MI.getOperand(2).isReg() && |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 157 | "invalid SPU OR(vec|r32|r64|gprc) instruction!"); |
| 158 | if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) { |
| 159 | sourceReg = MI.getOperand(1).getReg(); |
| 160 | destReg = MI.getOperand(0).getReg(); |
| 161 | return true; |
| 162 | } |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | return false; |
| 167 | } |
| 168 | |
| 169 | unsigned |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 170 | SPUInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
| 171 | int &FrameIndex) const { |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 172 | switch (MI->getOpcode()) { |
| 173 | default: break; |
| 174 | case SPU::LQDv16i8: |
| 175 | case SPU::LQDv8i16: |
| 176 | case SPU::LQDv4i32: |
| 177 | case SPU::LQDv4f32: |
| 178 | case SPU::LQDv2f64: |
| 179 | case SPU::LQDr128: |
| 180 | case SPU::LQDr64: |
| 181 | case SPU::LQDr32: |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 182 | case SPU::LQDr16: { |
| 183 | const MachineOperand MOp1 = MI->getOperand(1); |
| 184 | const MachineOperand MOp2 = MI->getOperand(2); |
| 185 | if (MOp1.isImm() |
| 186 | && (MOp2.isFI() |
| 187 | || (MOp2.isReg() && MOp2.getReg() == SPU::R1))) { |
| 188 | if (MOp2.isFI()) |
| 189 | FrameIndex = MOp2.getIndex(); |
| 190 | else |
| 191 | FrameIndex = MOp1.getImm() / SPUFrameInfo::stackSlotSize(); |
| 192 | return MI->getOperand(0).getReg(); |
| 193 | } |
| 194 | break; |
| 195 | } |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 196 | case SPU::LQXv4i32: |
| 197 | case SPU::LQXr128: |
| 198 | case SPU::LQXr64: |
| 199 | case SPU::LQXr32: |
| 200 | case SPU::LQXr16: |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 201 | if (MI->getOperand(1).isReg() && MI->getOperand(2).isReg() |
| 202 | && (MI->getOperand(2).getReg() == SPU::R1 |
| 203 | || MI->getOperand(1).getReg() == SPU::R1)) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 204 | FrameIndex = MI->getOperand(2).getIndex(); |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 205 | return MI->getOperand(0).getReg(); |
| 206 | } |
| 207 | break; |
| 208 | } |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | unsigned |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 213 | SPUInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
| 214 | int &FrameIndex) const { |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 215 | switch (MI->getOpcode()) { |
| 216 | default: break; |
| 217 | case SPU::STQDv16i8: |
| 218 | case SPU::STQDv8i16: |
| 219 | case SPU::STQDv4i32: |
| 220 | case SPU::STQDv4f32: |
| 221 | case SPU::STQDv2f64: |
| 222 | case SPU::STQDr128: |
| 223 | case SPU::STQDr64: |
| 224 | case SPU::STQDr32: |
| 225 | case SPU::STQDr16: |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 226 | case SPU::STQDr8: { |
| 227 | const MachineOperand MOp1 = MI->getOperand(1); |
| 228 | const MachineOperand MOp2 = MI->getOperand(2); |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 229 | if (MOp1.isImm() && MOp2.isFI()) { |
| 230 | FrameIndex = MOp2.getIndex(); |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 231 | return MI->getOperand(0).getReg(); |
| 232 | } |
| 233 | break; |
| 234 | } |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 235 | #if 0 |
| 236 | case SPU::STQXv16i8: |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 237 | case SPU::STQXv8i16: |
| 238 | case SPU::STQXv4i32: |
| 239 | case SPU::STQXv4f32: |
| 240 | case SPU::STQXv2f64: |
| 241 | case SPU::STQXr128: |
| 242 | case SPU::STQXr64: |
| 243 | case SPU::STQXr32: |
| 244 | case SPU::STQXr16: |
Scott Michel | 9c0c6b2 | 2008-11-21 02:56:16 +0000 | [diff] [blame] | 245 | case SPU::STQXr8: |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 246 | if (MI->getOperand(1).isReg() && MI->getOperand(2).isReg() |
| 247 | && (MI->getOperand(2).getReg() == SPU::R1 |
| 248 | || MI->getOperand(1).getReg() == SPU::R1)) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 249 | FrameIndex = MI->getOperand(2).getIndex(); |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 250 | return MI->getOperand(0).getReg(); |
| 251 | } |
| 252 | break; |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 253 | #endif |
Scott Michel | 6637752 | 2007-12-04 22:35:58 +0000 | [diff] [blame] | 254 | } |
| 255 | return 0; |
| 256 | } |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 257 | |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 258 | bool SPUInstrInfo::copyRegToReg(MachineBasicBlock &MBB, |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 259 | MachineBasicBlock::iterator MI, |
| 260 | unsigned DestReg, unsigned SrcReg, |
| 261 | const TargetRegisterClass *DestRC, |
| 262 | const TargetRegisterClass *SrcRC) const |
| 263 | { |
Chris Lattner | 5e09da2 | 2008-03-09 20:31:11 +0000 | [diff] [blame] | 264 | // We support cross register class moves for our aliases, such as R3 in any |
| 265 | // reg class to any other reg class containing R3. This is required because |
| 266 | // we instruction select bitconvert i64 -> f64 as a noop for example, so our |
| 267 | // types have no specific meaning. |
| 268 | |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 269 | if (DestRC == SPU::R8CRegisterClass) { |
| 270 | BuildMI(MBB, MI, get(SPU::ORBIr8), DestReg).addReg(SrcReg).addImm(0); |
| 271 | } else if (DestRC == SPU::R16CRegisterClass) { |
| 272 | BuildMI(MBB, MI, get(SPU::ORHIr16), DestReg).addReg(SrcReg).addImm(0); |
| 273 | } else if (DestRC == SPU::R32CRegisterClass) { |
| 274 | BuildMI(MBB, MI, get(SPU::ORIr32), DestReg).addReg(SrcReg).addImm(0); |
| 275 | } else if (DestRC == SPU::R32FPRegisterClass) { |
| 276 | BuildMI(MBB, MI, get(SPU::ORf32), DestReg).addReg(SrcReg) |
| 277 | .addReg(SrcReg); |
| 278 | } else if (DestRC == SPU::R64CRegisterClass) { |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 279 | BuildMI(MBB, MI, get(SPU::ORr64), DestReg).addReg(SrcReg) |
| 280 | .addReg(SrcReg); |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 281 | } else if (DestRC == SPU::R64FPRegisterClass) { |
| 282 | BuildMI(MBB, MI, get(SPU::ORf64), DestReg).addReg(SrcReg) |
| 283 | .addReg(SrcReg); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 284 | } /* else if (DestRC == SPU::GPRCRegisterClass) { |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 285 | BuildMI(MBB, MI, get(SPU::ORgprc), DestReg).addReg(SrcReg) |
| 286 | .addReg(SrcReg); |
Scott Michel | a59d469 | 2008-02-23 18:41:37 +0000 | [diff] [blame] | 287 | } */ else if (DestRC == SPU::VECREGRegisterClass) { |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 288 | BuildMI(MBB, MI, get(SPU::ORv4i32), DestReg).addReg(SrcReg) |
| 289 | .addReg(SrcReg); |
| 290 | } else { |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 291 | // Attempt to copy unknown/unsupported register class! |
| 292 | return false; |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 293 | } |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 294 | |
| 295 | return true; |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 296 | } |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 297 | |
| 298 | void |
| 299 | SPUInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB, |
| 300 | MachineBasicBlock::iterator MI, |
| 301 | unsigned SrcReg, bool isKill, int FrameIdx, |
| 302 | const TargetRegisterClass *RC) const |
| 303 | { |
Chris Lattner | cc8cd0c | 2008-01-07 02:48:55 +0000 | [diff] [blame] | 304 | unsigned opc; |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 305 | bool isValidFrameIdx = (FrameIdx < SPUFrameInfo::maxFrameOffset()); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 306 | if (RC == SPU::GPRCRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 307 | opc = (isValidFrameIdx ? SPU::STQDr128 : SPU::STQXr128); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 308 | } else if (RC == SPU::R64CRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 309 | opc = (isValidFrameIdx ? SPU::STQDr64 : SPU::STQXr64); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 310 | } else if (RC == SPU::R64FPRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 311 | opc = (isValidFrameIdx ? SPU::STQDr64 : SPU::STQXr64); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 312 | } else if (RC == SPU::R32CRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 313 | opc = (isValidFrameIdx ? SPU::STQDr32 : SPU::STQXr32); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 314 | } else if (RC == SPU::R32FPRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 315 | opc = (isValidFrameIdx ? SPU::STQDr32 : SPU::STQXr32); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 316 | } else if (RC == SPU::R16CRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 317 | opc = (isValidFrameIdx ? SPU::STQDr16 : SPU::STQXr16); |
| 318 | } else if (RC == SPU::R8CRegisterClass) { |
| 319 | opc = (isValidFrameIdx ? SPU::STQDr8 : SPU::STQXr8); |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 320 | } else if (RC == SPU::VECREGRegisterClass) { |
| 321 | opc = (isValidFrameIdx) ? SPU::STQDv16i8 : SPU::STQXv16i8; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 322 | } else { |
| 323 | assert(0 && "Unknown regclass!"); |
| 324 | abort(); |
| 325 | } |
| 326 | |
| 327 | addFrameReference(BuildMI(MBB, MI, get(opc)) |
| 328 | .addReg(SrcReg, false, false, isKill), FrameIdx); |
| 329 | } |
| 330 | |
| 331 | void SPUInstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg, |
| 332 | bool isKill, |
| 333 | SmallVectorImpl<MachineOperand> &Addr, |
| 334 | const TargetRegisterClass *RC, |
| 335 | SmallVectorImpl<MachineInstr*> &NewMIs) const { |
| 336 | cerr << "storeRegToAddr() invoked!\n"; |
| 337 | abort(); |
| 338 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 339 | if (Addr[0].isFI()) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 340 | /* do what storeRegToStackSlot does here */ |
| 341 | } else { |
| 342 | unsigned Opc = 0; |
| 343 | if (RC == SPU::GPRCRegisterClass) { |
| 344 | /* Opc = PPC::STW; */ |
| 345 | } else if (RC == SPU::R16CRegisterClass) { |
| 346 | /* Opc = PPC::STD; */ |
| 347 | } else if (RC == SPU::R32CRegisterClass) { |
| 348 | /* Opc = PPC::STFD; */ |
| 349 | } else if (RC == SPU::R32FPRegisterClass) { |
| 350 | /* Opc = PPC::STFD; */ |
| 351 | } else if (RC == SPU::R64FPRegisterClass) { |
| 352 | /* Opc = PPC::STFS; */ |
| 353 | } else if (RC == SPU::VECREGRegisterClass) { |
| 354 | /* Opc = PPC::STVX; */ |
| 355 | } else { |
| 356 | assert(0 && "Unknown regclass!"); |
| 357 | abort(); |
| 358 | } |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 359 | MachineInstrBuilder MIB = BuildMI(MF, get(Opc)) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 360 | .addReg(SrcReg, false, false, isKill); |
| 361 | for (unsigned i = 0, e = Addr.size(); i != e; ++i) { |
| 362 | MachineOperand &MO = Addr[i]; |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 363 | if (MO.isReg()) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 364 | MIB.addReg(MO.getReg()); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 365 | else if (MO.isImm()) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 366 | MIB.addImm(MO.getImm()); |
| 367 | else |
| 368 | MIB.addFrameIndex(MO.getIndex()); |
| 369 | } |
| 370 | NewMIs.push_back(MIB); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | void |
| 375 | SPUInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 376 | MachineBasicBlock::iterator MI, |
| 377 | unsigned DestReg, int FrameIdx, |
| 378 | const TargetRegisterClass *RC) const |
| 379 | { |
Chris Lattner | cc8cd0c | 2008-01-07 02:48:55 +0000 | [diff] [blame] | 380 | unsigned opc; |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 381 | bool isValidFrameIdx = (FrameIdx < SPUFrameInfo::maxFrameOffset()); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 382 | if (RC == SPU::GPRCRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 383 | opc = (isValidFrameIdx ? SPU::LQDr128 : SPU::LQXr128); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 384 | } else if (RC == SPU::R64CRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 385 | opc = (isValidFrameIdx ? SPU::LQDr64 : SPU::LQXr64); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 386 | } else if (RC == SPU::R64FPRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 387 | opc = (isValidFrameIdx ? SPU::LQDr64 : SPU::LQXr64); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 388 | } else if (RC == SPU::R32CRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 389 | opc = (isValidFrameIdx ? SPU::LQDr32 : SPU::LQXr32); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 390 | } else if (RC == SPU::R32FPRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 391 | opc = (isValidFrameIdx ? SPU::LQDr32 : SPU::LQXr32); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 392 | } else if (RC == SPU::R16CRegisterClass) { |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 393 | opc = (isValidFrameIdx ? SPU::LQDr16 : SPU::LQXr16); |
| 394 | } else if (RC == SPU::R8CRegisterClass) { |
| 395 | opc = (isValidFrameIdx ? SPU::LQDr8 : SPU::LQXr8); |
Scott Michel | f0569be | 2008-12-27 04:51:36 +0000 | [diff] [blame] | 396 | } else if (RC == SPU::VECREGRegisterClass) { |
| 397 | opc = (isValidFrameIdx) ? SPU::LQDv16i8 : SPU::LQXv16i8; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 398 | } else { |
| 399 | assert(0 && "Unknown regclass in loadRegFromStackSlot!"); |
| 400 | abort(); |
| 401 | } |
| 402 | |
| 403 | addFrameReference(BuildMI(MBB, MI, get(opc)).addReg(DestReg), FrameIdx); |
| 404 | } |
| 405 | |
| 406 | /*! |
| 407 | \note We are really pessimistic here about what kind of a load we're doing. |
| 408 | */ |
| 409 | void SPUInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 410 | SmallVectorImpl<MachineOperand> &Addr, |
| 411 | const TargetRegisterClass *RC, |
| 412 | SmallVectorImpl<MachineInstr*> &NewMIs) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 413 | const { |
| 414 | cerr << "loadRegToAddr() invoked!\n"; |
| 415 | abort(); |
| 416 | |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 417 | if (Addr[0].isFI()) { |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 418 | /* do what loadRegFromStackSlot does here... */ |
| 419 | } else { |
| 420 | unsigned Opc = 0; |
| 421 | if (RC == SPU::R8CRegisterClass) { |
| 422 | /* do brilliance here */ |
| 423 | } else if (RC == SPU::R16CRegisterClass) { |
| 424 | /* Opc = PPC::LWZ; */ |
| 425 | } else if (RC == SPU::R32CRegisterClass) { |
| 426 | /* Opc = PPC::LD; */ |
| 427 | } else if (RC == SPU::R32FPRegisterClass) { |
| 428 | /* Opc = PPC::LFD; */ |
| 429 | } else if (RC == SPU::R64FPRegisterClass) { |
| 430 | /* Opc = PPC::LFS; */ |
| 431 | } else if (RC == SPU::VECREGRegisterClass) { |
| 432 | /* Opc = PPC::LVX; */ |
| 433 | } else if (RC == SPU::GPRCRegisterClass) { |
| 434 | /* Opc = something else! */ |
| 435 | } else { |
| 436 | assert(0 && "Unknown regclass!"); |
| 437 | abort(); |
| 438 | } |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 439 | MachineInstrBuilder MIB = BuildMI(MF, get(Opc), DestReg); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 440 | for (unsigned i = 0, e = Addr.size(); i != e; ++i) { |
| 441 | MachineOperand &MO = Addr[i]; |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 442 | if (MO.isReg()) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 443 | MIB.addReg(MO.getReg()); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 444 | else if (MO.isImm()) |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 445 | MIB.addImm(MO.getImm()); |
| 446 | else |
| 447 | MIB.addFrameIndex(MO.getIndex()); |
| 448 | } |
| 449 | NewMIs.push_back(MIB); |
| 450 | } |
| 451 | } |
| 452 | |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 453 | /// foldMemoryOperand - SPU, like PPC, can only fold spills into |
| 454 | /// copy instructions, turning them into load/store instructions. |
| 455 | MachineInstr * |
Dan Gohman | c54baa2 | 2008-12-03 18:43:12 +0000 | [diff] [blame] | 456 | SPUInstrInfo::foldMemoryOperandImpl(MachineFunction &MF, |
| 457 | MachineInstr *MI, |
| 458 | const SmallVectorImpl<unsigned> &Ops, |
| 459 | int FrameIndex) const |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 460 | { |
| 461 | #if SOMEDAY_SCOTT_LOOKS_AT_ME_AGAIN |
| 462 | if (Ops.size() != 1) return NULL; |
| 463 | |
| 464 | unsigned OpNum = Ops[0]; |
| 465 | unsigned Opc = MI->getOpcode(); |
| 466 | MachineInstr *NewMI = 0; |
| 467 | |
| 468 | if ((Opc == SPU::ORr32 |
| 469 | || Opc == SPU::ORv4i32) |
| 470 | && MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) { |
| 471 | if (OpNum == 0) { // move -> store |
| 472 | unsigned InReg = MI->getOperand(1).getReg(); |
Evan Cheng | 9f1c831 | 2008-07-03 09:09:37 +0000 | [diff] [blame] | 473 | bool isKill = MI->getOperand(1).isKill(); |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 474 | if (FrameIndex < SPUFrameInfo::maxFrameOffset()) { |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 475 | NewMI = addFrameReference(BuildMI(MF, TII.get(SPU::STQDr32)) |
Evan Cheng | 9f1c831 | 2008-07-03 09:09:37 +0000 | [diff] [blame] | 476 | .addReg(InReg, false, false, isKill), |
Scott Michel | 7f9ba9b | 2008-01-30 02:55:46 +0000 | [diff] [blame] | 477 | FrameIndex); |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 478 | } |
| 479 | } else { // move -> load |
| 480 | unsigned OutReg = MI->getOperand(0).getReg(); |
Evan Cheng | 9f1c831 | 2008-07-03 09:09:37 +0000 | [diff] [blame] | 481 | bool isDead = MI->getOperand(0).isDead(); |
| 482 | Opc = (FrameIndex < SPUFrameInfo::maxFrameOffset()) |
| 483 | ? SPU::STQDr32 : SPU::STQXr32; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 484 | NewMI = addFrameReference(BuildMI(MF, TII.get(Opc)) |
Evan Cheng | 9f1c831 | 2008-07-03 09:09:37 +0000 | [diff] [blame] | 485 | .addReg(OutReg, true, false, false, isDead), FrameIndex); |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 489 | return NewMI; |
| 490 | #else |
| 491 | return 0; |
| 492 | #endif |
| 493 | } |
| 494 | |
Scott Michel | aedc637 | 2008-12-10 00:15:19 +0000 | [diff] [blame] | 495 | //! Branch analysis |
| 496 | /* |
| 497 | \note This code was kiped from PPC. There may be more branch analysis for |
| 498 | CellSPU than what's currently done here. |
| 499 | */ |
| 500 | bool |
| 501 | SPUInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 502 | MachineBasicBlock *&FBB, |
| 503 | SmallVectorImpl<MachineOperand> &Cond) const { |
| 504 | // If the block has no terminators, it just falls into the block after it. |
| 505 | MachineBasicBlock::iterator I = MBB.end(); |
| 506 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) |
| 507 | return false; |
| 508 | |
| 509 | // Get the last instruction in the block. |
| 510 | MachineInstr *LastInst = I; |
| 511 | |
| 512 | // If there is only one terminator instruction, process it. |
| 513 | if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) { |
| 514 | if (isUncondBranch(LastInst)) { |
| 515 | TBB = LastInst->getOperand(0).getMBB(); |
| 516 | return false; |
| 517 | } else if (isCondBranch(LastInst)) { |
| 518 | // Block ends with fall-through condbranch. |
| 519 | TBB = LastInst->getOperand(1).getMBB(); |
| 520 | Cond.push_back(LastInst->getOperand(0)); |
| 521 | Cond.push_back(LastInst->getOperand(1)); |
| 522 | return false; |
| 523 | } |
| 524 | // Otherwise, don't know what this is. |
| 525 | return true; |
| 526 | } |
| 527 | |
| 528 | // Get the instruction before it if it's a terminator. |
| 529 | MachineInstr *SecondLastInst = I; |
| 530 | |
| 531 | // If there are three terminators, we don't know what sort of block this is. |
| 532 | if (SecondLastInst && I != MBB.begin() && |
| 533 | isUnpredicatedTerminator(--I)) |
| 534 | return true; |
| 535 | |
| 536 | // If the block ends with a conditional and unconditional branch, handle it. |
| 537 | if (isCondBranch(SecondLastInst) && isUncondBranch(LastInst)) { |
| 538 | TBB = SecondLastInst->getOperand(1).getMBB(); |
| 539 | Cond.push_back(SecondLastInst->getOperand(0)); |
| 540 | Cond.push_back(SecondLastInst->getOperand(1)); |
| 541 | FBB = LastInst->getOperand(0).getMBB(); |
| 542 | return false; |
| 543 | } |
| 544 | |
| 545 | // If the block ends with two unconditional branches, handle it. The second |
| 546 | // one is not executed, so remove it. |
| 547 | if (isUncondBranch(SecondLastInst) && isUncondBranch(LastInst)) { |
| 548 | TBB = SecondLastInst->getOperand(0).getMBB(); |
| 549 | I = LastInst; |
| 550 | I->eraseFromParent(); |
| 551 | return false; |
| 552 | } |
| 553 | |
| 554 | // Otherwise, can't handle this. |
| 555 | return true; |
| 556 | } |
| 557 | |
| 558 | unsigned |
| 559 | SPUInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const { |
| 560 | MachineBasicBlock::iterator I = MBB.end(); |
| 561 | if (I == MBB.begin()) |
| 562 | return 0; |
| 563 | --I; |
| 564 | if (!isCondBranch(I) && !isUncondBranch(I)) |
| 565 | return 0; |
| 566 | |
| 567 | // Remove the first branch. |
| 568 | I->eraseFromParent(); |
| 569 | I = MBB.end(); |
| 570 | if (I == MBB.begin()) |
| 571 | return 1; |
| 572 | |
| 573 | --I; |
| 574 | if (isCondBranch(I)) |
| 575 | return 1; |
| 576 | |
| 577 | // Remove the second branch. |
| 578 | I->eraseFromParent(); |
| 579 | return 2; |
| 580 | } |
| 581 | |
| 582 | unsigned |
| 583 | SPUInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 584 | MachineBasicBlock *FBB, |
| 585 | const SmallVectorImpl<MachineOperand> &Cond) const { |
| 586 | // Shouldn't be a fall through. |
| 587 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 588 | assert((Cond.size() == 2 || Cond.size() == 0) && |
| 589 | "SPU branch conditions have two components!"); |
| 590 | |
| 591 | // One-way branch. |
| 592 | if (FBB == 0) { |
| 593 | if (Cond.empty()) // Unconditional branch |
| 594 | BuildMI(&MBB, get(SPU::BR)).addMBB(TBB); |
| 595 | else { // Conditional branch |
| 596 | /* BuildMI(&MBB, get(SPU::BRNZ)) |
| 597 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB); */ |
| 598 | cerr << "SPUInstrInfo::InsertBranch conditional branch logic needed\n"; |
| 599 | abort(); |
| 600 | } |
| 601 | return 1; |
| 602 | } |
| 603 | |
| 604 | // Two-way Conditional Branch. |
| 605 | #if 0 |
| 606 | BuildMI(&MBB, get(SPU::BRNZ)) |
| 607 | .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB); |
| 608 | BuildMI(&MBB, get(SPU::BR)).addMBB(FBB); |
| 609 | #else |
| 610 | cerr << "SPUInstrInfo::InsertBranch conditional branch logic needed\n"; |
| 611 | abort(); |
| 612 | #endif |
| 613 | |
| 614 | return 2; |
| 615 | } |
| 616 | |
| 617 | |