blob: e5048e6d4ea4308c417ea12a6803685e178bc5ee [file] [log] [blame]
Chris Lattner4ee451d2007-12-29 20:36:04 +00001//===- SPUInstrInfo.cpp - Cell SPU Instruction Information ----------------===//
Scott Michel66377522007-12-04 22:35:58 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michel66377522007-12-04 22:35:58 +00007//
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 Andersonf6372aa2008-01-01 21:11:32 +000016#include "SPUInstrBuilder.h"
Scott Michel66377522007-12-04 22:35:58 +000017#include "SPUTargetMachine.h"
18#include "SPUGenInstrInfo.inc"
Andrew Trick2da8bc82010-12-24 05:03:26 +000019#include "SPUHazardRecognizers.h"
Scott Michel66377522007-12-04 22:35:58 +000020#include "llvm/CodeGen/MachineInstrBuilder.h"
Scott Michel9bd7a372009-01-02 20:52:08 +000021#include "llvm/Support/Debug.h"
Torok Edwindac237e2009-07-08 20:53:28 +000022#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer072a56e2009-08-23 11:52:17 +000023#include "llvm/Support/raw_ostream.h"
Scott Michel66377522007-12-04 22:35:58 +000024
25using namespace llvm;
26
Scott Michelaedc6372008-12-10 00:15:19 +000027namespace {
28 //! Predicate for an unconditional branch instruction
29 inline bool isUncondBranch(const MachineInstr *I) {
30 unsigned opc = I->getOpcode();
31
32 return (opc == SPU::BR
Scott Michel19c10e62009-01-26 03:37:41 +000033 || opc == SPU::BRA
34 || opc == SPU::BI);
Scott Michelaedc6372008-12-10 00:15:19 +000035 }
36
Scott Michel52d00012009-01-03 00:27:53 +000037 //! Predicate for a conditional branch instruction
Scott Michelaedc6372008-12-10 00:15:19 +000038 inline bool isCondBranch(const MachineInstr *I) {
39 unsigned opc = I->getOpcode();
40
Scott Michelf0569be2008-12-27 04:51:36 +000041 return (opc == SPU::BRNZr32
42 || opc == SPU::BRNZv4i32
Scott Michel19c10e62009-01-26 03:37:41 +000043 || opc == SPU::BRZr32
44 || opc == SPU::BRZv4i32
45 || opc == SPU::BRHNZr16
46 || opc == SPU::BRHNZv8i16
47 || opc == SPU::BRHZr16
48 || opc == SPU::BRHZv8i16);
Scott Michelaedc6372008-12-10 00:15:19 +000049 }
50}
51
Scott Michel66377522007-12-04 22:35:58 +000052SPUInstrInfo::SPUInstrInfo(SPUTargetMachine &tm)
Chris Lattner64105522008-01-01 01:03:04 +000053 : TargetInstrInfoImpl(SPUInsts, sizeof(SPUInsts)/sizeof(SPUInsts[0])),
Scott Michel66377522007-12-04 22:35:58 +000054 TM(tm),
55 RI(*TM.getSubtargetImpl(), *this)
Scott Michel52d00012009-01-03 00:27:53 +000056{ /* NOP */ }
Scott Michel66377522007-12-04 22:35:58 +000057
Andrew Trick2da8bc82010-12-24 05:03:26 +000058/// CreateTargetHazardRecognizer - Return the hazard recognizer to use for
59/// this target when scheduling the DAG.
60ScheduleHazardRecognizer *SPUInstrInfo::CreateTargetHazardRecognizer(
61 const TargetMachine *TM,
62 const ScheduleDAG *DAG) const {
63 const TargetInstrInfo *TII = TM->getInstrInfo();
64 assert(TII && "No InstrInfo?");
65 return new SPUHazardRecognizer(*TII);
66}
67
Scott Michel66377522007-12-04 22:35:58 +000068unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000069SPUInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
70 int &FrameIndex) const {
Scott Michel66377522007-12-04 22:35:58 +000071 switch (MI->getOpcode()) {
72 default: break;
73 case SPU::LQDv16i8:
74 case SPU::LQDv8i16:
75 case SPU::LQDv4i32:
76 case SPU::LQDv4f32:
77 case SPU::LQDv2f64:
78 case SPU::LQDr128:
79 case SPU::LQDr64:
80 case SPU::LQDr32:
Scott Michelaedc6372008-12-10 00:15:19 +000081 case SPU::LQDr16: {
82 const MachineOperand MOp1 = MI->getOperand(1);
83 const MachineOperand MOp2 = MI->getOperand(2);
Scott Michel52d00012009-01-03 00:27:53 +000084 if (MOp1.isImm() && MOp2.isFI()) {
85 FrameIndex = MOp2.getIndex();
Scott Michelaedc6372008-12-10 00:15:19 +000086 return MI->getOperand(0).getReg();
87 }
88 break;
89 }
Scott Michel66377522007-12-04 22:35:58 +000090 }
91 return 0;
92}
93
94unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000095SPUInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
96 int &FrameIndex) const {
Scott Michel66377522007-12-04 22:35:58 +000097 switch (MI->getOpcode()) {
98 default: break;
99 case SPU::STQDv16i8:
100 case SPU::STQDv8i16:
101 case SPU::STQDv4i32:
102 case SPU::STQDv4f32:
103 case SPU::STQDv2f64:
104 case SPU::STQDr128:
105 case SPU::STQDr64:
106 case SPU::STQDr32:
107 case SPU::STQDr16:
Scott Michelaedc6372008-12-10 00:15:19 +0000108 case SPU::STQDr8: {
109 const MachineOperand MOp1 = MI->getOperand(1);
110 const MachineOperand MOp2 = MI->getOperand(2);
Scott Michelf0569be2008-12-27 04:51:36 +0000111 if (MOp1.isImm() && MOp2.isFI()) {
112 FrameIndex = MOp2.getIndex();
Scott Michelaedc6372008-12-10 00:15:19 +0000113 return MI->getOperand(0).getReg();
114 }
115 break;
116 }
Scott Michel66377522007-12-04 22:35:58 +0000117 }
118 return 0;
119}
Owen Andersond10fd972007-12-31 06:32:00 +0000120
Jakob Stoklund Olesen377b7b72010-07-11 07:31:03 +0000121void SPUInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
122 MachineBasicBlock::iterator I, DebugLoc DL,
123 unsigned DestReg, unsigned SrcReg,
124 bool KillSrc) const
Owen Andersond10fd972007-12-31 06:32:00 +0000125{
Chris Lattner5e09da22008-03-09 20:31:11 +0000126 // We support cross register class moves for our aliases, such as R3 in any
127 // reg class to any other reg class containing R3. This is required because
128 // we instruction select bitconvert i64 -> f64 as a noop for example, so our
129 // types have no specific meaning.
Scott Michel02d711b2008-12-30 23:28:25 +0000130
Jakob Stoklund Olesen377b7b72010-07-11 07:31:03 +0000131 BuildMI(MBB, I, DL, get(SPU::LRr128), DestReg)
132 .addReg(SrcReg, getKillRegState(KillSrc));
Owen Andersond10fd972007-12-31 06:32:00 +0000133}
Owen Andersonf6372aa2008-01-01 21:11:32 +0000134
135void
136SPUInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
Evan Cheng746ad692010-05-06 19:06:44 +0000137 MachineBasicBlock::iterator MI,
138 unsigned SrcReg, bool isKill, int FrameIdx,
139 const TargetRegisterClass *RC,
140 const TargetRegisterInfo *TRI) const
Owen Andersonf6372aa2008-01-01 21:11:32 +0000141{
Chris Lattnercc8cd0c2008-01-07 02:48:55 +0000142 unsigned opc;
Scott Michelaedc6372008-12-10 00:15:19 +0000143 bool isValidFrameIdx = (FrameIdx < SPUFrameInfo::maxFrameOffset());
Owen Andersonf6372aa2008-01-01 21:11:32 +0000144 if (RC == SPU::GPRCRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000145 opc = (isValidFrameIdx ? SPU::STQDr128 : SPU::STQXr128);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000146 } else if (RC == SPU::R64CRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000147 opc = (isValidFrameIdx ? SPU::STQDr64 : SPU::STQXr64);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000148 } else if (RC == SPU::R64FPRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000149 opc = (isValidFrameIdx ? SPU::STQDr64 : SPU::STQXr64);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000150 } else if (RC == SPU::R32CRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000151 opc = (isValidFrameIdx ? SPU::STQDr32 : SPU::STQXr32);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000152 } else if (RC == SPU::R32FPRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000153 opc = (isValidFrameIdx ? SPU::STQDr32 : SPU::STQXr32);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000154 } else if (RC == SPU::R16CRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000155 opc = (isValidFrameIdx ? SPU::STQDr16 : SPU::STQXr16);
156 } else if (RC == SPU::R8CRegisterClass) {
157 opc = (isValidFrameIdx ? SPU::STQDr8 : SPU::STQXr8);
Scott Michelf0569be2008-12-27 04:51:36 +0000158 } else if (RC == SPU::VECREGRegisterClass) {
159 opc = (isValidFrameIdx) ? SPU::STQDv16i8 : SPU::STQXv16i8;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000160 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +0000161 llvm_unreachable("Unknown regclass!");
Owen Andersonf6372aa2008-01-01 21:11:32 +0000162 }
163
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000164 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000165 if (MI != MBB.end()) DL = MI->getDebugLoc();
166 addFrameReference(BuildMI(MBB, MI, DL, get(opc))
Bill Wendling587daed2009-05-13 21:33:08 +0000167 .addReg(SrcReg, getKillRegState(isKill)), FrameIdx);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000168}
169
Owen Andersonf6372aa2008-01-01 21:11:32 +0000170void
171SPUInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
Evan Cheng746ad692010-05-06 19:06:44 +0000172 MachineBasicBlock::iterator MI,
173 unsigned DestReg, int FrameIdx,
174 const TargetRegisterClass *RC,
175 const TargetRegisterInfo *TRI) const
Owen Andersonf6372aa2008-01-01 21:11:32 +0000176{
Chris Lattnercc8cd0c2008-01-07 02:48:55 +0000177 unsigned opc;
Scott Michelaedc6372008-12-10 00:15:19 +0000178 bool isValidFrameIdx = (FrameIdx < SPUFrameInfo::maxFrameOffset());
Owen Andersonf6372aa2008-01-01 21:11:32 +0000179 if (RC == SPU::GPRCRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000180 opc = (isValidFrameIdx ? SPU::LQDr128 : SPU::LQXr128);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000181 } else if (RC == SPU::R64CRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000182 opc = (isValidFrameIdx ? SPU::LQDr64 : SPU::LQXr64);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000183 } else if (RC == SPU::R64FPRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000184 opc = (isValidFrameIdx ? SPU::LQDr64 : SPU::LQXr64);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000185 } else if (RC == SPU::R32CRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000186 opc = (isValidFrameIdx ? SPU::LQDr32 : SPU::LQXr32);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000187 } else if (RC == SPU::R32FPRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000188 opc = (isValidFrameIdx ? SPU::LQDr32 : SPU::LQXr32);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000189 } else if (RC == SPU::R16CRegisterClass) {
Scott Michelaedc6372008-12-10 00:15:19 +0000190 opc = (isValidFrameIdx ? SPU::LQDr16 : SPU::LQXr16);
191 } else if (RC == SPU::R8CRegisterClass) {
192 opc = (isValidFrameIdx ? SPU::LQDr8 : SPU::LQXr8);
Scott Michelf0569be2008-12-27 04:51:36 +0000193 } else if (RC == SPU::VECREGRegisterClass) {
194 opc = (isValidFrameIdx) ? SPU::LQDv16i8 : SPU::LQXv16i8;
Owen Andersonf6372aa2008-01-01 21:11:32 +0000195 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +0000196 llvm_unreachable("Unknown regclass in loadRegFromStackSlot!");
Owen Andersonf6372aa2008-01-01 21:11:32 +0000197 }
198
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000199 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000200 if (MI != MBB.end()) DL = MI->getDebugLoc();
Jakob Stoklund Olesenf2c3f6a2009-05-16 07:25:44 +0000201 addFrameReference(BuildMI(MBB, MI, DL, get(opc), DestReg), FrameIdx);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000202}
203
Scott Michelaedc6372008-12-10 00:15:19 +0000204//! Branch analysis
Scott Michel9bd7a372009-01-02 20:52:08 +0000205/*!
Scott Michelaedc6372008-12-10 00:15:19 +0000206 \note This code was kiped from PPC. There may be more branch analysis for
207 CellSPU than what's currently done here.
208 */
209bool
210SPUInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
Scott Michel19c10e62009-01-26 03:37:41 +0000211 MachineBasicBlock *&FBB,
Evan Chengdc54d312009-02-09 07:14:22 +0000212 SmallVectorImpl<MachineOperand> &Cond,
213 bool AllowModify) const {
Scott Michelaedc6372008-12-10 00:15:19 +0000214 // If the block has no terminators, it just falls into the block after it.
215 MachineBasicBlock::iterator I = MBB.end();
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000216 if (I == MBB.begin())
217 return false;
218 --I;
219 while (I->isDebugValue()) {
220 if (I == MBB.begin())
221 return false;
222 --I;
223 }
224 if (!isUnpredicatedTerminator(I))
Scott Michelaedc6372008-12-10 00:15:19 +0000225 return false;
226
227 // Get the last instruction in the block.
228 MachineInstr *LastInst = I;
Scott Michel02d711b2008-12-30 23:28:25 +0000229
Scott Michelaedc6372008-12-10 00:15:19 +0000230 // If there is only one terminator instruction, process it.
231 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
232 if (isUncondBranch(LastInst)) {
Kalle Raiskila2320a442010-05-11 11:00:02 +0000233 // Check for jump tables
234 if (!LastInst->getOperand(0).isMBB())
235 return true;
Scott Michelaedc6372008-12-10 00:15:19 +0000236 TBB = LastInst->getOperand(0).getMBB();
237 return false;
238 } else if (isCondBranch(LastInst)) {
239 // Block ends with fall-through condbranch.
240 TBB = LastInst->getOperand(1).getMBB();
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000241 DEBUG(errs() << "Pushing LastInst: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000242 DEBUG(LastInst->dump());
243 Cond.push_back(MachineOperand::CreateImm(LastInst->getOpcode()));
Scott Michelaedc6372008-12-10 00:15:19 +0000244 Cond.push_back(LastInst->getOperand(0));
Scott Michelaedc6372008-12-10 00:15:19 +0000245 return false;
246 }
247 // Otherwise, don't know what this is.
248 return true;
249 }
Scott Michel02d711b2008-12-30 23:28:25 +0000250
Scott Michelaedc6372008-12-10 00:15:19 +0000251 // Get the instruction before it if it's a terminator.
252 MachineInstr *SecondLastInst = I;
253
254 // If there are three terminators, we don't know what sort of block this is.
255 if (SecondLastInst && I != MBB.begin() &&
256 isUnpredicatedTerminator(--I))
257 return true;
Scott Michel02d711b2008-12-30 23:28:25 +0000258
Scott Michelaedc6372008-12-10 00:15:19 +0000259 // If the block ends with a conditional and unconditional branch, handle it.
260 if (isCondBranch(SecondLastInst) && isUncondBranch(LastInst)) {
261 TBB = SecondLastInst->getOperand(1).getMBB();
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000262 DEBUG(errs() << "Pushing SecondLastInst: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000263 DEBUG(SecondLastInst->dump());
264 Cond.push_back(MachineOperand::CreateImm(SecondLastInst->getOpcode()));
Scott Michelaedc6372008-12-10 00:15:19 +0000265 Cond.push_back(SecondLastInst->getOperand(0));
Scott Michelaedc6372008-12-10 00:15:19 +0000266 FBB = LastInst->getOperand(0).getMBB();
267 return false;
268 }
Scott Michel02d711b2008-12-30 23:28:25 +0000269
Scott Michelaedc6372008-12-10 00:15:19 +0000270 // If the block ends with two unconditional branches, handle it. The second
271 // one is not executed, so remove it.
272 if (isUncondBranch(SecondLastInst) && isUncondBranch(LastInst)) {
273 TBB = SecondLastInst->getOperand(0).getMBB();
274 I = LastInst;
Evan Chengdc54d312009-02-09 07:14:22 +0000275 if (AllowModify)
276 I->eraseFromParent();
Scott Michelaedc6372008-12-10 00:15:19 +0000277 return false;
278 }
279
280 // Otherwise, can't handle this.
281 return true;
282}
Scott Michel02d711b2008-12-30 23:28:25 +0000283
Scott Michelaedc6372008-12-10 00:15:19 +0000284unsigned
285SPUInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
286 MachineBasicBlock::iterator I = MBB.end();
287 if (I == MBB.begin())
288 return 0;
289 --I;
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000290 while (I->isDebugValue()) {
291 if (I == MBB.begin())
292 return 0;
293 --I;
294 }
Scott Michelaedc6372008-12-10 00:15:19 +0000295 if (!isCondBranch(I) && !isUncondBranch(I))
296 return 0;
297
298 // Remove the first branch.
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000299 DEBUG(errs() << "Removing branch: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000300 DEBUG(I->dump());
Scott Michelaedc6372008-12-10 00:15:19 +0000301 I->eraseFromParent();
302 I = MBB.end();
303 if (I == MBB.begin())
304 return 1;
305
306 --I;
Scott Michel9bd7a372009-01-02 20:52:08 +0000307 if (!(isCondBranch(I) || isUncondBranch(I)))
Scott Michelaedc6372008-12-10 00:15:19 +0000308 return 1;
309
310 // Remove the second branch.
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000311 DEBUG(errs() << "Removing second branch: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000312 DEBUG(I->dump());
Scott Michelaedc6372008-12-10 00:15:19 +0000313 I->eraseFromParent();
314 return 2;
315}
Scott Michel02d711b2008-12-30 23:28:25 +0000316
Scott Michelaedc6372008-12-10 00:15:19 +0000317unsigned
318SPUInstrInfo::InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
Scott Michel19c10e62009-01-26 03:37:41 +0000319 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +0000320 const SmallVectorImpl<MachineOperand> &Cond,
321 DebugLoc DL) const {
Scott Michelaedc6372008-12-10 00:15:19 +0000322 // Shouldn't be a fall through.
323 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
Scott Michel02d711b2008-12-30 23:28:25 +0000324 assert((Cond.size() == 2 || Cond.size() == 0) &&
Scott Michelaedc6372008-12-10 00:15:19 +0000325 "SPU branch conditions have two components!");
Scott Michel02d711b2008-12-30 23:28:25 +0000326
Scott Michelaedc6372008-12-10 00:15:19 +0000327 // One-way branch.
328 if (FBB == 0) {
Scott Michel9bd7a372009-01-02 20:52:08 +0000329 if (Cond.empty()) {
330 // Unconditional branch
Stuart Hastings3bf91252010-06-17 22:43:56 +0000331 MachineInstrBuilder MIB = BuildMI(&MBB, DL, get(SPU::BR));
Scott Michel9bd7a372009-01-02 20:52:08 +0000332 MIB.addMBB(TBB);
333
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000334 DEBUG(errs() << "Inserted one-way uncond branch: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000335 DEBUG((*MIB).dump());
336 } else {
337 // Conditional branch
Stuart Hastings3bf91252010-06-17 22:43:56 +0000338 MachineInstrBuilder MIB = BuildMI(&MBB, DL, get(Cond[0].getImm()));
Scott Michel9bd7a372009-01-02 20:52:08 +0000339 MIB.addReg(Cond[1].getReg()).addMBB(TBB);
340
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000341 DEBUG(errs() << "Inserted one-way cond branch: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000342 DEBUG((*MIB).dump());
Scott Michelaedc6372008-12-10 00:15:19 +0000343 }
344 return 1;
Scott Michel9bd7a372009-01-02 20:52:08 +0000345 } else {
Stuart Hastings3bf91252010-06-17 22:43:56 +0000346 MachineInstrBuilder MIB = BuildMI(&MBB, DL, get(Cond[0].getImm()));
347 MachineInstrBuilder MIB2 = BuildMI(&MBB, DL, get(SPU::BR));
Scott Michel9bd7a372009-01-02 20:52:08 +0000348
349 // Two-way Conditional Branch.
350 MIB.addReg(Cond[1].getReg()).addMBB(TBB);
351 MIB2.addMBB(FBB);
352
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000353 DEBUG(errs() << "Inserted conditional branch: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000354 DEBUG((*MIB).dump());
Benjamin Kramer072a56e2009-08-23 11:52:17 +0000355 DEBUG(errs() << "part 2: ");
Scott Michel9bd7a372009-01-02 20:52:08 +0000356 DEBUG((*MIB2).dump());
357 return 2;
Scott Michelaedc6372008-12-10 00:15:19 +0000358 }
Scott Michelaedc6372008-12-10 00:15:19 +0000359}
360
Scott Michel52d00012009-01-03 00:27:53 +0000361//! Reverses a branch's condition, returning false on success.
362bool
363SPUInstrInfo::ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond)
364 const {
365 // Pretty brainless way of inverting the condition, but it works, considering
366 // there are only two conditions...
367 static struct {
368 unsigned Opc; //! The incoming opcode
369 unsigned RevCondOpc; //! The reversed condition opcode
370 } revconds[] = {
371 { SPU::BRNZr32, SPU::BRZr32 },
372 { SPU::BRNZv4i32, SPU::BRZv4i32 },
373 { SPU::BRZr32, SPU::BRNZr32 },
374 { SPU::BRZv4i32, SPU::BRNZv4i32 },
375 { SPU::BRHNZr16, SPU::BRHZr16 },
376 { SPU::BRHNZv8i16, SPU::BRHZv8i16 },
377 { SPU::BRHZr16, SPU::BRHNZr16 },
378 { SPU::BRHZv8i16, SPU::BRHNZv8i16 }
379 };
Scott Michelaedc6372008-12-10 00:15:19 +0000380
Scott Michel52d00012009-01-03 00:27:53 +0000381 unsigned Opc = unsigned(Cond[0].getImm());
382 // Pretty dull mapping between the two conditions that SPU can generate:
Misha Brukman93c65c82009-01-07 23:07:29 +0000383 for (int i = sizeof(revconds)/sizeof(revconds[0]) - 1; i >= 0; --i) {
Scott Michel52d00012009-01-03 00:27:53 +0000384 if (revconds[i].Opc == Opc) {
385 Cond[0].setImm(revconds[i].RevCondOpc);
386 return false;
387 }
388 }
389
390 return true;
391}