blob: fa8224f113ffe39f780363bb84020b6b1b2807c9 [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"
Dan Gohmand68a0762009-01-05 17:59:02 +000018#include "llvm/ADT/SmallVector.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000019#include "llvm/CodeGen/MachineInstrBuilder.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000020using namespace llvm;
21
22AlphaInstrInfo::AlphaInstrInfo()
Chris Lattner64105522008-01-01 01:03:04 +000023 : TargetInstrInfoImpl(AlphaInsts, array_lengthof(AlphaInsts)),
Evan Cheng7ce45782006-11-13 23:36:35 +000024 RI(*this) { }
Andrew Lenharth304d0f32005-01-22 23:41:55 +000025
26
27bool AlphaInstrInfo::isMoveInstr(const MachineInstr& MI,
28 unsigned& sourceReg,
29 unsigned& destReg) const {
Chris Lattnercc8cd0c2008-01-07 02:48:55 +000030 unsigned oc = MI.getOpcode();
Andrew Lenharth6bbf6b02006-10-31 23:46:56 +000031 if (oc == Alpha::BISr ||
Andrew Lenharthddc877c2006-03-09 18:18:51 +000032 oc == Alpha::CPYSS ||
33 oc == Alpha::CPYST ||
34 oc == Alpha::CPYSSt ||
35 oc == Alpha::CPYSTs) {
Andrew Lenharth5cefc5e2005-11-09 19:17:08 +000036 // or r1, r2, r2
37 // cpys(s|t) r1 r2 r2
Evan Cheng1e3417292007-04-25 07:12:14 +000038 assert(MI.getNumOperands() >= 3 &&
Dan Gohmand735b802008-10-03 15:45:36 +000039 MI.getOperand(0).isReg() &&
40 MI.getOperand(1).isReg() &&
41 MI.getOperand(2).isReg() &&
Andrew Lenharth304d0f32005-01-22 23:41:55 +000042 "invalid Alpha BIS instruction!");
43 if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
44 sourceReg = MI.getOperand(1).getReg();
45 destReg = MI.getOperand(0).getReg();
46 return true;
47 }
48 }
49 return false;
50}
Chris Lattner40839602006-02-02 20:12:32 +000051
52unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000053AlphaInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
54 int &FrameIndex) const {
Chris Lattner40839602006-02-02 20:12:32 +000055 switch (MI->getOpcode()) {
56 case Alpha::LDL:
57 case Alpha::LDQ:
58 case Alpha::LDBU:
59 case Alpha::LDWU:
60 case Alpha::LDS:
61 case Alpha::LDT:
Dan Gohmand735b802008-10-03 15:45:36 +000062 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000063 FrameIndex = MI->getOperand(1).getIndex();
Chris Lattner40839602006-02-02 20:12:32 +000064 return MI->getOperand(0).getReg();
65 }
66 break;
67 }
68 return 0;
69}
70
Andrew Lenharth133d3102006-02-03 03:07:37 +000071unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000072AlphaInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
73 int &FrameIndex) const {
Andrew Lenharth133d3102006-02-03 03:07:37 +000074 switch (MI->getOpcode()) {
75 case Alpha::STL:
76 case Alpha::STQ:
77 case Alpha::STB:
78 case Alpha::STW:
79 case Alpha::STS:
80 case Alpha::STT:
Dan Gohmand735b802008-10-03 15:45:36 +000081 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000082 FrameIndex = MI->getOperand(1).getIndex();
Andrew Lenharth133d3102006-02-03 03:07:37 +000083 return MI->getOperand(0).getReg();
84 }
85 break;
86 }
87 return 0;
88}
89
Andrew Lenharthf81173f2006-10-31 16:49:55 +000090static bool isAlphaIntCondCode(unsigned Opcode) {
91 switch (Opcode) {
92 case Alpha::BEQ:
93 case Alpha::BNE:
94 case Alpha::BGE:
95 case Alpha::BGT:
96 case Alpha::BLE:
97 case Alpha::BLT:
98 case Alpha::BLBC:
99 case Alpha::BLBS:
100 return true;
101 default:
102 return false;
103 }
104}
105
Owen Anderson44eb65c2008-08-14 22:49:33 +0000106unsigned AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,
107 MachineBasicBlock *TBB,
108 MachineBasicBlock *FBB,
109 const SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000110 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
111 assert((Cond.size() == 2 || Cond.size() == 0) &&
112 "Alpha branch conditions have two components!");
113
114 // One-way branch.
115 if (FBB == 0) {
116 if (Cond.empty()) // Unconditional branch
Evan Chengc0f64ff2006-11-27 23:37:22 +0000117 BuildMI(&MBB, get(Alpha::BR)).addMBB(TBB);
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000118 else // Conditional branch
119 if (isAlphaIntCondCode(Cond[0].getImm()))
Evan Chengc0f64ff2006-11-27 23:37:22 +0000120 BuildMI(&MBB, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000121 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
122 else
Evan Chengc0f64ff2006-11-27 23:37:22 +0000123 BuildMI(&MBB, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000124 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000125 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000126 }
127
128 // Two-way Conditional Branch.
129 if (isAlphaIntCondCode(Cond[0].getImm()))
Evan Chengc0f64ff2006-11-27 23:37:22 +0000130 BuildMI(&MBB, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000131 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
132 else
Evan Chengc0f64ff2006-11-27 23:37:22 +0000133 BuildMI(&MBB, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000134 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Evan Chengc0f64ff2006-11-27 23:37:22 +0000135 BuildMI(&MBB, get(Alpha::BR)).addMBB(FBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000136 return 2;
Rafael Espindola3d7d39a2006-10-24 17:07:11 +0000137}
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000138
Owen Anderson940f83e2008-08-26 18:03:31 +0000139bool AlphaInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
Owen Andersond10fd972007-12-31 06:32:00 +0000140 MachineBasicBlock::iterator MI,
141 unsigned DestReg, unsigned SrcReg,
142 const TargetRegisterClass *DestRC,
143 const TargetRegisterClass *SrcRC) const {
144 //cerr << "copyRegToReg " << DestReg << " <- " << SrcReg << "\n";
145 if (DestRC != SrcRC) {
Owen Anderson940f83e2008-08-26 18:03:31 +0000146 // Not yet supported!
147 return false;
Owen Andersond10fd972007-12-31 06:32:00 +0000148 }
149
150 if (DestRC == Alpha::GPRCRegisterClass) {
151 BuildMI(MBB, MI, get(Alpha::BISr), DestReg).addReg(SrcReg).addReg(SrcReg);
152 } else if (DestRC == Alpha::F4RCRegisterClass) {
153 BuildMI(MBB, MI, get(Alpha::CPYSS), DestReg).addReg(SrcReg).addReg(SrcReg);
154 } else if (DestRC == Alpha::F8RCRegisterClass) {
155 BuildMI(MBB, MI, get(Alpha::CPYST), DestReg).addReg(SrcReg).addReg(SrcReg);
156 } else {
Owen Anderson940f83e2008-08-26 18:03:31 +0000157 // Attempt to copy register that is not GPR or FPR
158 return false;
Owen Andersond10fd972007-12-31 06:32:00 +0000159 }
Owen Anderson940f83e2008-08-26 18:03:31 +0000160
161 return true;
Owen Andersond10fd972007-12-31 06:32:00 +0000162}
163
Owen Andersonf6372aa2008-01-01 21:11:32 +0000164void
165AlphaInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
166 MachineBasicBlock::iterator MI,
167 unsigned SrcReg, bool isKill, int FrameIdx,
168 const TargetRegisterClass *RC) const {
169 //cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
170 // << FrameIdx << "\n";
171 //BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
172 if (RC == Alpha::F4RCRegisterClass)
173 BuildMI(MBB, MI, get(Alpha::STS))
174 .addReg(SrcReg, false, false, isKill)
175 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
176 else if (RC == Alpha::F8RCRegisterClass)
177 BuildMI(MBB, MI, get(Alpha::STT))
178 .addReg(SrcReg, false, false, isKill)
179 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
180 else if (RC == Alpha::GPRCRegisterClass)
181 BuildMI(MBB, MI, get(Alpha::STQ))
182 .addReg(SrcReg, false, false, isKill)
183 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
184 else
185 abort();
186}
187
188void AlphaInstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
189 bool isKill,
190 SmallVectorImpl<MachineOperand> &Addr,
191 const TargetRegisterClass *RC,
192 SmallVectorImpl<MachineInstr*> &NewMIs) const {
193 unsigned Opc = 0;
194 if (RC == Alpha::F4RCRegisterClass)
195 Opc = Alpha::STS;
196 else if (RC == Alpha::F8RCRegisterClass)
197 Opc = Alpha::STT;
198 else if (RC == Alpha::GPRCRegisterClass)
199 Opc = Alpha::STQ;
200 else
201 abort();
202 MachineInstrBuilder MIB =
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000203 BuildMI(MF, get(Opc)).addReg(SrcReg, false, false, isKill);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000204 for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
205 MachineOperand &MO = Addr[i];
Dan Gohmand735b802008-10-03 15:45:36 +0000206 if (MO.isReg())
Owen Andersonf6372aa2008-01-01 21:11:32 +0000207 MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit());
208 else
209 MIB.addImm(MO.getImm());
210 }
211 NewMIs.push_back(MIB);
212}
213
214void
215AlphaInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
216 MachineBasicBlock::iterator MI,
217 unsigned DestReg, int FrameIdx,
218 const TargetRegisterClass *RC) const {
219 //cerr << "Trying to load " << getPrettyName(DestReg) << " to "
220 // << FrameIdx << "\n";
221 if (RC == Alpha::F4RCRegisterClass)
222 BuildMI(MBB, MI, get(Alpha::LDS), DestReg)
223 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
224 else if (RC == Alpha::F8RCRegisterClass)
225 BuildMI(MBB, MI, get(Alpha::LDT), DestReg)
226 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
227 else if (RC == Alpha::GPRCRegisterClass)
228 BuildMI(MBB, MI, get(Alpha::LDQ), DestReg)
229 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
230 else
231 abort();
232}
233
234void AlphaInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
235 SmallVectorImpl<MachineOperand> &Addr,
236 const TargetRegisterClass *RC,
237 SmallVectorImpl<MachineInstr*> &NewMIs) const {
238 unsigned Opc = 0;
239 if (RC == Alpha::F4RCRegisterClass)
240 Opc = Alpha::LDS;
241 else if (RC == Alpha::F8RCRegisterClass)
242 Opc = Alpha::LDT;
243 else if (RC == Alpha::GPRCRegisterClass)
244 Opc = Alpha::LDQ;
245 else
246 abort();
247 MachineInstrBuilder MIB =
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000248 BuildMI(MF, get(Opc), DestReg);
Owen Andersonf6372aa2008-01-01 21:11:32 +0000249 for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
250 MachineOperand &MO = Addr[i];
Dan Gohmand735b802008-10-03 15:45:36 +0000251 if (MO.isReg())
Owen Andersonf6372aa2008-01-01 21:11:32 +0000252 MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit());
253 else
254 MIB.addImm(MO.getImm());
255 }
256 NewMIs.push_back(MIB);
257}
258
Dan Gohmanc54baa22008-12-03 18:43:12 +0000259MachineInstr *AlphaInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
260 MachineInstr *MI,
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000261 const SmallVectorImpl<unsigned> &Ops,
Dan Gohmanc54baa22008-12-03 18:43:12 +0000262 int FrameIndex) const {
Owen Anderson43dbe052008-01-07 01:35:02 +0000263 if (Ops.size() != 1) return NULL;
264
265 // Make sure this is a reg-reg copy.
266 unsigned Opc = MI->getOpcode();
267
268 MachineInstr *NewMI = NULL;
269 switch(Opc) {
270 default:
271 break;
272 case Alpha::BISr:
273 case Alpha::CPYSS:
274 case Alpha::CPYST:
275 if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
276 if (Ops[0] == 0) { // move -> store
277 unsigned InReg = MI->getOperand(1).getReg();
Evan Cheng9f1c8312008-07-03 09:09:37 +0000278 bool isKill = MI->getOperand(1).isKill();
Owen Anderson43dbe052008-01-07 01:35:02 +0000279 Opc = (Opc == Alpha::BISr) ? Alpha::STQ :
280 ((Opc == Alpha::CPYSS) ? Alpha::STS : Alpha::STT);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000281 NewMI = BuildMI(MF, get(Opc)).addReg(InReg, false, false, isKill)
Evan Cheng9f1c8312008-07-03 09:09:37 +0000282 .addFrameIndex(FrameIndex)
Owen Anderson43dbe052008-01-07 01:35:02 +0000283 .addReg(Alpha::F31);
284 } else { // load -> move
285 unsigned OutReg = MI->getOperand(0).getReg();
Evan Cheng9f1c8312008-07-03 09:09:37 +0000286 bool isDead = MI->getOperand(0).isDead();
Owen Anderson43dbe052008-01-07 01:35:02 +0000287 Opc = (Opc == Alpha::BISr) ? Alpha::LDQ :
288 ((Opc == Alpha::CPYSS) ? Alpha::LDS : Alpha::LDT);
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000289 NewMI = BuildMI(MF, get(Opc)).addReg(OutReg, true, false, false, isDead)
Evan Cheng9f1c8312008-07-03 09:09:37 +0000290 .addFrameIndex(FrameIndex)
Owen Anderson43dbe052008-01-07 01:35:02 +0000291 .addReg(Alpha::F31);
292 }
293 }
294 break;
295 }
Evan Cheng9f1c8312008-07-03 09:09:37 +0000296 return NewMI;
Owen Anderson43dbe052008-01-07 01:35:02 +0000297}
298
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000299static unsigned AlphaRevCondCode(unsigned Opcode) {
300 switch (Opcode) {
301 case Alpha::BEQ: return Alpha::BNE;
302 case Alpha::BNE: return Alpha::BEQ;
303 case Alpha::BGE: return Alpha::BLT;
304 case Alpha::BGT: return Alpha::BLE;
305 case Alpha::BLE: return Alpha::BGT;
306 case Alpha::BLT: return Alpha::BGE;
307 case Alpha::BLBC: return Alpha::BLBS;
308 case Alpha::BLBS: return Alpha::BLBC;
309 case Alpha::FBEQ: return Alpha::FBNE;
310 case Alpha::FBNE: return Alpha::FBEQ;
311 case Alpha::FBGE: return Alpha::FBLT;
312 case Alpha::FBGT: return Alpha::FBLE;
313 case Alpha::FBLE: return Alpha::FBGT;
314 case Alpha::FBLT: return Alpha::FBGE;
315 default:
316 assert(0 && "Unknown opcode");
317 }
Chris Lattnerd27c9912008-03-30 18:22:13 +0000318 return 0; // Not reached
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000319}
320
321// Branch analysis.
322bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
323 MachineBasicBlock *&FBB,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000324 SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000325 // If the block has no terminators, it just falls into the block after it.
326 MachineBasicBlock::iterator I = MBB.end();
Evan Chengbfd2ec42007-06-08 21:59:56 +0000327 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000328 return false;
329
330 // Get the last instruction in the block.
331 MachineInstr *LastInst = I;
332
333 // If there is only one terminator instruction, process it.
Evan Chengbfd2ec42007-06-08 21:59:56 +0000334 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000335 if (LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000336 TBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000337 return false;
338 } else if (LastInst->getOpcode() == Alpha::COND_BRANCH_I ||
339 LastInst->getOpcode() == Alpha::COND_BRANCH_F) {
340 // Block ends with fall-through condbranch.
Chris Lattner8aa797a2007-12-30 23:10:15 +0000341 TBB = LastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000342 Cond.push_back(LastInst->getOperand(0));
343 Cond.push_back(LastInst->getOperand(1));
344 return false;
345 }
346 // Otherwise, don't know what this is.
347 return true;
348 }
349
350 // Get the instruction before it if it's a terminator.
351 MachineInstr *SecondLastInst = I;
352
353 // If there are three terminators, we don't know what sort of block this is.
354 if (SecondLastInst && I != MBB.begin() &&
Evan Chengbfd2ec42007-06-08 21:59:56 +0000355 isUnpredicatedTerminator(--I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000356 return true;
357
358 // If the block ends with Alpha::BR and Alpha::COND_BRANCH_*, handle it.
359 if ((SecondLastInst->getOpcode() == Alpha::COND_BRANCH_I ||
360 SecondLastInst->getOpcode() == Alpha::COND_BRANCH_F) &&
361 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000362 TBB = SecondLastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000363 Cond.push_back(SecondLastInst->getOperand(0));
364 Cond.push_back(SecondLastInst->getOperand(1));
Chris Lattner8aa797a2007-12-30 23:10:15 +0000365 FBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000366 return false;
367 }
368
Dale Johannesen13e8b512007-06-13 17:59:52 +0000369 // If the block ends with two Alpha::BRs, handle it. The second one is not
370 // executed, so remove it.
371 if (SecondLastInst->getOpcode() == Alpha::BR &&
372 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000373 TBB = SecondLastInst->getOperand(0).getMBB();
Dale Johannesen13e8b512007-06-13 17:59:52 +0000374 I = LastInst;
375 I->eraseFromParent();
376 return false;
377 }
378
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000379 // Otherwise, can't handle this.
380 return true;
381}
382
Evan Chengb5cdaa22007-05-18 00:05:48 +0000383unsigned AlphaInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000384 MachineBasicBlock::iterator I = MBB.end();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000385 if (I == MBB.begin()) return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000386 --I;
387 if (I->getOpcode() != Alpha::BR &&
388 I->getOpcode() != Alpha::COND_BRANCH_I &&
389 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000390 return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000391
392 // Remove the branch.
393 I->eraseFromParent();
394
395 I = MBB.end();
396
Evan Chengb5cdaa22007-05-18 00:05:48 +0000397 if (I == MBB.begin()) return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000398 --I;
399 if (I->getOpcode() != Alpha::COND_BRANCH_I &&
400 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000401 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000402
403 // Remove the branch.
404 I->eraseFromParent();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000405 return 2;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000406}
407
408void AlphaInstrInfo::insertNoop(MachineBasicBlock &MBB,
409 MachineBasicBlock::iterator MI) const {
Evan Chengc0f64ff2006-11-27 23:37:22 +0000410 BuildMI(MBB, MI, get(Alpha::BISr), Alpha::R31).addReg(Alpha::R31)
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000411 .addReg(Alpha::R31);
412}
413
Dan Gohman8e8b8a22008-10-16 01:49:15 +0000414bool AlphaInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000415 if (MBB.empty()) return false;
416
417 switch (MBB.back().getOpcode()) {
Evan Cheng126f17a2007-05-21 18:44:17 +0000418 case Alpha::RETDAG: // Return.
419 case Alpha::RETDAGp:
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000420 case Alpha::BR: // Uncond branch.
421 case Alpha::JMP: // Indirect branch.
422 return true;
423 default: return false;
424 }
425}
426bool AlphaInstrInfo::
Owen Anderson44eb65c2008-08-14 22:49:33 +0000427ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000428 assert(Cond.size() == 2 && "Invalid Alpha branch opcode!");
429 Cond[0].setImm(AlphaRevCondCode(Cond[0].getImm()));
430 return false;
431}
432