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