blob: 7b3053e5238bbafbd3f508d882894f313dc31a7f [file] [log] [blame]
Misha Brukman2a8350a2005-02-05 02:24:26 +00001//===- AlphaInstrInfo.cpp - Alpha Instruction Information -------*- C++ -*-===//
Misha Brukman4633f1c2005-04-21 23:13:11 +00002//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00003// 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.
Misha Brukman4633f1c2005-04-21 23:13:11 +00007//
Andrew Lenharth304d0f32005-01-22 23:41:55 +00008//===----------------------------------------------------------------------===//
9//
10// This file contains the Alpha implementation of the TargetInstrInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "Alpha.h"
15#include "AlphaInstrInfo.h"
16#include "AlphaGenInstrInfo.inc"
Owen Anderson718cb662007-09-07 04:06:50 +000017#include "llvm/ADT/STLExtras.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000018#include "llvm/CodeGen/MachineInstrBuilder.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000019using namespace llvm;
20
21AlphaInstrInfo::AlphaInstrInfo()
Chris Lattner64105522008-01-01 01:03:04 +000022 : TargetInstrInfoImpl(AlphaInsts, array_lengthof(AlphaInsts)),
Evan Cheng7ce45782006-11-13 23:36:35 +000023 RI(*this) { }
Andrew Lenharth304d0f32005-01-22 23:41:55 +000024
25
26bool AlphaInstrInfo::isMoveInstr(const MachineInstr& MI,
27 unsigned& sourceReg,
28 unsigned& destReg) const {
Chris Lattnercc8cd0c2008-01-07 02:48:55 +000029 unsigned oc = MI.getOpcode();
Andrew Lenharth6bbf6b02006-10-31 23:46:56 +000030 if (oc == Alpha::BISr ||
Andrew Lenharthddc877c2006-03-09 18:18:51 +000031 oc == Alpha::CPYSS ||
32 oc == Alpha::CPYST ||
33 oc == Alpha::CPYSSt ||
34 oc == Alpha::CPYSTs) {
Andrew Lenharth5cefc5e2005-11-09 19:17:08 +000035 // or r1, r2, r2
36 // cpys(s|t) r1 r2 r2
Evan Cheng1e3417292007-04-25 07:12:14 +000037 assert(MI.getNumOperands() >= 3 &&
Dan Gohmand735b802008-10-03 15:45:36 +000038 MI.getOperand(0).isReg() &&
39 MI.getOperand(1).isReg() &&
40 MI.getOperand(2).isReg() &&
Andrew Lenharth304d0f32005-01-22 23:41:55 +000041 "invalid Alpha BIS instruction!");
42 if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
43 sourceReg = MI.getOperand(1).getReg();
44 destReg = MI.getOperand(0).getReg();
45 return true;
46 }
47 }
48 return false;
49}
Chris Lattner40839602006-02-02 20:12:32 +000050
51unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000052AlphaInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
53 int &FrameIndex) const {
Chris Lattner40839602006-02-02 20:12:32 +000054 switch (MI->getOpcode()) {
55 case Alpha::LDL:
56 case Alpha::LDQ:
57 case Alpha::LDBU:
58 case Alpha::LDWU:
59 case Alpha::LDS:
60 case Alpha::LDT:
Dan Gohmand735b802008-10-03 15:45:36 +000061 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000062 FrameIndex = MI->getOperand(1).getIndex();
Chris Lattner40839602006-02-02 20:12:32 +000063 return MI->getOperand(0).getReg();
64 }
65 break;
66 }
67 return 0;
68}
69
Andrew Lenharth133d3102006-02-03 03:07:37 +000070unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000071AlphaInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
72 int &FrameIndex) const {
Andrew Lenharth133d3102006-02-03 03:07:37 +000073 switch (MI->getOpcode()) {
74 case Alpha::STL:
75 case Alpha::STQ:
76 case Alpha::STB:
77 case Alpha::STW:
78 case Alpha::STS:
79 case Alpha::STT:
Dan Gohmand735b802008-10-03 15:45:36 +000080 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000081 FrameIndex = MI->getOperand(1).getIndex();
Andrew Lenharth133d3102006-02-03 03:07:37 +000082 return MI->getOperand(0).getReg();
83 }
84 break;
85 }
86 return 0;
87}
88
Andrew Lenharthf81173f2006-10-31 16:49:55 +000089static bool isAlphaIntCondCode(unsigned Opcode) {
90 switch (Opcode) {
91 case Alpha::BEQ:
92 case Alpha::BNE:
93 case Alpha::BGE:
94 case Alpha::BGT:
95 case Alpha::BLE:
96 case Alpha::BLT:
97 case Alpha::BLBC:
98 case Alpha::BLBS:
99 return true;
100 default:
101 return false;
102 }
103}
104
Owen Anderson44eb65c2008-08-14 22:49:33 +0000105unsigned AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,
106 MachineBasicBlock *TBB,
107 MachineBasicBlock *FBB,
108 const SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000109 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
110 assert((Cond.size() == 2 || Cond.size() == 0) &&
111 "Alpha branch conditions have two components!");
112
113 // One-way branch.
114 if (FBB == 0) {
115 if (Cond.empty()) // Unconditional branch
Evan Chengc0f64ff2006-11-27 23:37:22 +0000116 BuildMI(&MBB, get(Alpha::BR)).addMBB(TBB);
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000117 else // Conditional branch
118 if (isAlphaIntCondCode(Cond[0].getImm()))
Evan Chengc0f64ff2006-11-27 23:37:22 +0000119 BuildMI(&MBB, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000120 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
121 else
Evan Chengc0f64ff2006-11-27 23:37:22 +0000122 BuildMI(&MBB, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000123 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000124 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000125 }
126
127 // Two-way Conditional Branch.
128 if (isAlphaIntCondCode(Cond[0].getImm()))
Evan Chengc0f64ff2006-11-27 23:37:22 +0000129 BuildMI(&MBB, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000130 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
131 else
Evan Chengc0f64ff2006-11-27 23:37:22 +0000132 BuildMI(&MBB, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000133 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Evan Chengc0f64ff2006-11-27 23:37:22 +0000134 BuildMI(&MBB, get(Alpha::BR)).addMBB(FBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000135 return 2;
Rafael Espindola3d7d39a2006-10-24 17:07:11 +0000136}
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000137
Owen Anderson940f83e2008-08-26 18:03:31 +0000138bool AlphaInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
Owen Andersond10fd972007-12-31 06:32:00 +0000139 MachineBasicBlock::iterator MI,
140 unsigned DestReg, unsigned SrcReg,
141 const TargetRegisterClass *DestRC,
142 const TargetRegisterClass *SrcRC) const {
143 //cerr << "copyRegToReg " << DestReg << " <- " << SrcReg << "\n";
144 if (DestRC != SrcRC) {
Owen Anderson940f83e2008-08-26 18:03:31 +0000145 // Not yet supported!
146 return false;
Owen Andersond10fd972007-12-31 06:32:00 +0000147 }
148
149 if (DestRC == Alpha::GPRCRegisterClass) {
150 BuildMI(MBB, MI, get(Alpha::BISr), DestReg).addReg(SrcReg).addReg(SrcReg);
151 } else if (DestRC == Alpha::F4RCRegisterClass) {
152 BuildMI(MBB, MI, get(Alpha::CPYSS), DestReg).addReg(SrcReg).addReg(SrcReg);
153 } else if (DestRC == Alpha::F8RCRegisterClass) {
154 BuildMI(MBB, MI, get(Alpha::CPYST), DestReg).addReg(SrcReg).addReg(SrcReg);
155 } else {
Owen Anderson940f83e2008-08-26 18:03:31 +0000156 // Attempt to copy register that is not GPR or FPR
157 return false;
Owen Andersond10fd972007-12-31 06:32:00 +0000158 }
Owen Anderson940f83e2008-08-26 18:03:31 +0000159
160 return true;
Owen Andersond10fd972007-12-31 06:32:00 +0000161}
162
Owen Andersonf6372aa2008-01-01 21:11:32 +0000163void
164AlphaInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
165 MachineBasicBlock::iterator MI,
166 unsigned SrcReg, bool isKill, int FrameIdx,
167 const TargetRegisterClass *RC) const {
168 //cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
169 // << FrameIdx << "\n";
170 //BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
171 if (RC == Alpha::F4RCRegisterClass)
172 BuildMI(MBB, MI, get(Alpha::STS))
173 .addReg(SrcReg, false, false, isKill)
174 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
175 else if (RC == Alpha::F8RCRegisterClass)
176 BuildMI(MBB, MI, get(Alpha::STT))
177 .addReg(SrcReg, false, false, isKill)
178 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
179 else if (RC == Alpha::GPRCRegisterClass)
180 BuildMI(MBB, MI, get(Alpha::STQ))
181 .addReg(SrcReg, false, false, isKill)
182 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
183 else
184 abort();
185}
186
187void AlphaInstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
188 bool isKill,
189 SmallVectorImpl<MachineOperand> &Addr,
190 const TargetRegisterClass *RC,
191 SmallVectorImpl<MachineInstr*> &NewMIs) const {
192 unsigned Opc = 0;
193 if (RC == Alpha::F4RCRegisterClass)
194 Opc = Alpha::STS;
195 else if (RC == Alpha::F8RCRegisterClass)
196 Opc = Alpha::STT;
197 else if (RC == Alpha::GPRCRegisterClass)
198 Opc = Alpha::STQ;
199 else
200 abort();
201 MachineInstrBuilder MIB =
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000202 BuildMI(MF, get(Opc)).addReg(SrcReg, false, false, isKill);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000203 for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
204 MachineOperand &MO = Addr[i];
Dan Gohmand735b802008-10-03 15:45:36 +0000205 if (MO.isReg())
Owen Andersonf6372aa2008-01-01 21:11:32 +0000206 MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit());
207 else
208 MIB.addImm(MO.getImm());
209 }
210 NewMIs.push_back(MIB);
211}
212
213void
214AlphaInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
215 MachineBasicBlock::iterator MI,
216 unsigned DestReg, int FrameIdx,
217 const TargetRegisterClass *RC) const {
218 //cerr << "Trying to load " << getPrettyName(DestReg) << " to "
219 // << FrameIdx << "\n";
220 if (RC == Alpha::F4RCRegisterClass)
221 BuildMI(MBB, MI, get(Alpha::LDS), DestReg)
222 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
223 else if (RC == Alpha::F8RCRegisterClass)
224 BuildMI(MBB, MI, get(Alpha::LDT), DestReg)
225 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
226 else if (RC == Alpha::GPRCRegisterClass)
227 BuildMI(MBB, MI, get(Alpha::LDQ), DestReg)
228 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
229 else
230 abort();
231}
232
233void AlphaInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
234 SmallVectorImpl<MachineOperand> &Addr,
235 const TargetRegisterClass *RC,
236 SmallVectorImpl<MachineInstr*> &NewMIs) const {
237 unsigned Opc = 0;
238 if (RC == Alpha::F4RCRegisterClass)
239 Opc = Alpha::LDS;
240 else if (RC == Alpha::F8RCRegisterClass)
241 Opc = Alpha::LDT;
242 else if (RC == Alpha::GPRCRegisterClass)
243 Opc = Alpha::LDQ;
244 else
245 abort();
246 MachineInstrBuilder MIB =
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000247 BuildMI(MF, get(Opc), DestReg);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000248 for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
249 MachineOperand &MO = Addr[i];
Dan Gohmand735b802008-10-03 15:45:36 +0000250 if (MO.isReg())
Owen Andersonf6372aa2008-01-01 21:11:32 +0000251 MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit());
252 else
253 MIB.addImm(MO.getImm());
254 }
255 NewMIs.push_back(MIB);
256}
257
Evan Cheng5fd79d02008-02-08 21:20:40 +0000258MachineInstr *AlphaInstrInfo::foldMemoryOperand(MachineFunction &MF,
259 MachineInstr *MI,
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000260 const SmallVectorImpl<unsigned> &Ops,
Evan Cheng5fd79d02008-02-08 21:20:40 +0000261 int FrameIndex) const {
Owen Anderson43dbe052008-01-07 01:35:02 +0000262 if (Ops.size() != 1) return NULL;
263
264 // Make sure this is a reg-reg copy.
265 unsigned Opc = MI->getOpcode();
266
267 MachineInstr *NewMI = NULL;
268 switch(Opc) {
269 default:
270 break;
271 case Alpha::BISr:
272 case Alpha::CPYSS:
273 case Alpha::CPYST:
274 if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
275 if (Ops[0] == 0) { // move -> store
276 unsigned InReg = MI->getOperand(1).getReg();
Evan Cheng9f1c8312008-07-03 09:09:37 +0000277 bool isKill = MI->getOperand(1).isKill();
Owen Anderson43dbe052008-01-07 01:35:02 +0000278 Opc = (Opc == Alpha::BISr) ? Alpha::STQ :
279 ((Opc == Alpha::CPYSS) ? Alpha::STS : Alpha::STT);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000280 NewMI = BuildMI(MF, get(Opc)).addReg(InReg, false, false, isKill)
Evan Cheng9f1c8312008-07-03 09:09:37 +0000281 .addFrameIndex(FrameIndex)
Owen Anderson43dbe052008-01-07 01:35:02 +0000282 .addReg(Alpha::F31);
283 } else { // load -> move
284 unsigned OutReg = MI->getOperand(0).getReg();
Evan Cheng9f1c8312008-07-03 09:09:37 +0000285 bool isDead = MI->getOperand(0).isDead();
Owen Anderson43dbe052008-01-07 01:35:02 +0000286 Opc = (Opc == Alpha::BISr) ? Alpha::LDQ :
287 ((Opc == Alpha::CPYSS) ? Alpha::LDS : Alpha::LDT);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000288 NewMI = BuildMI(MF, get(Opc)).addReg(OutReg, true, false, false, isDead)
Evan Cheng9f1c8312008-07-03 09:09:37 +0000289 .addFrameIndex(FrameIndex)
Owen Anderson43dbe052008-01-07 01:35:02 +0000290 .addReg(Alpha::F31);
291 }
292 }
293 break;
294 }
Evan Cheng9f1c8312008-07-03 09:09:37 +0000295 return NewMI;
Owen Anderson43dbe052008-01-07 01:35:02 +0000296}
297
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000298static unsigned AlphaRevCondCode(unsigned Opcode) {
299 switch (Opcode) {
300 case Alpha::BEQ: return Alpha::BNE;
301 case Alpha::BNE: return Alpha::BEQ;
302 case Alpha::BGE: return Alpha::BLT;
303 case Alpha::BGT: return Alpha::BLE;
304 case Alpha::BLE: return Alpha::BGT;
305 case Alpha::BLT: return Alpha::BGE;
306 case Alpha::BLBC: return Alpha::BLBS;
307 case Alpha::BLBS: return Alpha::BLBC;
308 case Alpha::FBEQ: return Alpha::FBNE;
309 case Alpha::FBNE: return Alpha::FBEQ;
310 case Alpha::FBGE: return Alpha::FBLT;
311 case Alpha::FBGT: return Alpha::FBLE;
312 case Alpha::FBLE: return Alpha::FBGT;
313 case Alpha::FBLT: return Alpha::FBGE;
314 default:
315 assert(0 && "Unknown opcode");
316 }
Chris Lattnerd27c9912008-03-30 18:22:13 +0000317 return 0; // Not reached
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000318}
319
320// Branch analysis.
321bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
322 MachineBasicBlock *&FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000323 SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000324 // If the block has no terminators, it just falls into the block after it.
325 MachineBasicBlock::iterator I = MBB.end();
Evan Chengbfd2ec42007-06-08 21:59:56 +0000326 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000327 return false;
328
329 // Get the last instruction in the block.
330 MachineInstr *LastInst = I;
331
332 // If there is only one terminator instruction, process it.
Evan Chengbfd2ec42007-06-08 21:59:56 +0000333 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000334 if (LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000335 TBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000336 return false;
337 } else if (LastInst->getOpcode() == Alpha::COND_BRANCH_I ||
338 LastInst->getOpcode() == Alpha::COND_BRANCH_F) {
339 // Block ends with fall-through condbranch.
Chris Lattner8aa797a2007-12-30 23:10:15 +0000340 TBB = LastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000341 Cond.push_back(LastInst->getOperand(0));
342 Cond.push_back(LastInst->getOperand(1));
343 return false;
344 }
345 // Otherwise, don't know what this is.
346 return true;
347 }
348
349 // Get the instruction before it if it's a terminator.
350 MachineInstr *SecondLastInst = I;
351
352 // If there are three terminators, we don't know what sort of block this is.
353 if (SecondLastInst && I != MBB.begin() &&
Evan Chengbfd2ec42007-06-08 21:59:56 +0000354 isUnpredicatedTerminator(--I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000355 return true;
356
357 // If the block ends with Alpha::BR and Alpha::COND_BRANCH_*, handle it.
358 if ((SecondLastInst->getOpcode() == Alpha::COND_BRANCH_I ||
359 SecondLastInst->getOpcode() == Alpha::COND_BRANCH_F) &&
360 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000361 TBB = SecondLastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000362 Cond.push_back(SecondLastInst->getOperand(0));
363 Cond.push_back(SecondLastInst->getOperand(1));
Chris Lattner8aa797a2007-12-30 23:10:15 +0000364 FBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000365 return false;
366 }
367
Dale Johannesen13e8b512007-06-13 17:59:52 +0000368 // If the block ends with two Alpha::BRs, handle it. The second one is not
369 // executed, so remove it.
370 if (SecondLastInst->getOpcode() == Alpha::BR &&
371 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000372 TBB = SecondLastInst->getOperand(0).getMBB();
Dale Johannesen13e8b512007-06-13 17:59:52 +0000373 I = LastInst;
374 I->eraseFromParent();
375 return false;
376 }
377
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000378 // Otherwise, can't handle this.
379 return true;
380}
381
Evan Chengb5cdaa22007-05-18 00:05:48 +0000382unsigned AlphaInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000383 MachineBasicBlock::iterator I = MBB.end();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000384 if (I == MBB.begin()) return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000385 --I;
386 if (I->getOpcode() != Alpha::BR &&
387 I->getOpcode() != Alpha::COND_BRANCH_I &&
388 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000389 return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000390
391 // Remove the branch.
392 I->eraseFromParent();
393
394 I = MBB.end();
395
Evan Chengb5cdaa22007-05-18 00:05:48 +0000396 if (I == MBB.begin()) return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000397 --I;
398 if (I->getOpcode() != Alpha::COND_BRANCH_I &&
399 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000400 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000401
402 // Remove the branch.
403 I->eraseFromParent();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000404 return 2;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000405}
406
407void AlphaInstrInfo::insertNoop(MachineBasicBlock &MBB,
408 MachineBasicBlock::iterator MI) const {
Evan Chengc0f64ff2006-11-27 23:37:22 +0000409 BuildMI(MBB, MI, get(Alpha::BISr), Alpha::R31).addReg(Alpha::R31)
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000410 .addReg(Alpha::R31);
411}
412
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000413bool AlphaInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000414 if (MBB.empty()) return false;
415
416 switch (MBB.back().getOpcode()) {
Evan Cheng126f17a2007-05-21 18:44:17 +0000417 case Alpha::RETDAG: // Return.
418 case Alpha::RETDAGp:
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000419 case Alpha::BR: // Uncond branch.
420 case Alpha::JMP: // Indirect branch.
421 return true;
422 default: return false;
423 }
424}
425bool AlphaInstrInfo::
Owen Anderson44eb65c2008-08-14 22:49:33 +0000426ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000427 assert(Cond.size() == 2 && "Invalid Alpha branch opcode!");
428 Cond[0].setImm(AlphaRevCondCode(Cond[0].getImm()));
429 return false;
430}
431