blob: 73e9b7b2d57109fd551ff848b394bfc21d515a62 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- AlphaInstrInfo.cpp - Alpha Instruction Information -------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
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 Anderson1636de92007-09-07 04:06:50 +000017#include "llvm/ADT/STLExtras.h"
Dan Gohmanc24a3f82009-01-05 17:59:02 +000018#include "llvm/ADT/SmallVector.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000019#include "llvm/CodeGen/MachineInstrBuilder.h"
20using namespace llvm;
21
22AlphaInstrInfo::AlphaInstrInfo()
Chris Lattnerd2fd6db2008-01-01 01:03:04 +000023 : TargetInstrInfoImpl(AlphaInsts, array_lengthof(AlphaInsts)),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024 RI(*this) { }
25
26
27bool AlphaInstrInfo::isMoveInstr(const MachineInstr& MI,
Evan Chengf97496a2009-01-20 19:12:24 +000028 unsigned& sourceReg, unsigned& destReg,
29 unsigned& SrcSR, unsigned& DstSR) const {
Chris Lattner99aa3372008-01-07 02:48:55 +000030 unsigned oc = MI.getOpcode();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031 if (oc == Alpha::BISr ||
32 oc == Alpha::CPYSS ||
33 oc == Alpha::CPYST ||
34 oc == Alpha::CPYSSt ||
35 oc == Alpha::CPYSTs) {
36 // or r1, r2, r2
37 // cpys(s|t) r1 r2 r2
38 assert(MI.getNumOperands() >= 3 &&
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000039 MI.getOperand(0).isReg() &&
40 MI.getOperand(1).isReg() &&
41 MI.getOperand(2).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +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();
Evan Chengf97496a2009-01-20 19:12:24 +000046 SrcSR = DstSR = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 return true;
48 }
49 }
50 return false;
51}
52
53unsigned
Dan Gohman90feee22008-11-18 19:49:32 +000054AlphaInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
55 int &FrameIndex) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 switch (MI->getOpcode()) {
57 case Alpha::LDL:
58 case Alpha::LDQ:
59 case Alpha::LDBU:
60 case Alpha::LDWU:
61 case Alpha::LDS:
62 case Alpha::LDT:
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000063 if (MI->getOperand(1).isFI()) {
Chris Lattner6017d482007-12-30 23:10:15 +000064 FrameIndex = MI->getOperand(1).getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065 return MI->getOperand(0).getReg();
66 }
67 break;
68 }
69 return 0;
70}
71
72unsigned
Dan Gohman90feee22008-11-18 19:49:32 +000073AlphaInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
74 int &FrameIndex) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075 switch (MI->getOpcode()) {
76 case Alpha::STL:
77 case Alpha::STQ:
78 case Alpha::STB:
79 case Alpha::STW:
80 case Alpha::STS:
81 case Alpha::STT:
Dan Gohmanb9f4fa72008-10-03 15:45:36 +000082 if (MI->getOperand(1).isFI()) {
Chris Lattner6017d482007-12-30 23:10:15 +000083 FrameIndex = MI->getOperand(1).getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +000084 return MI->getOperand(0).getReg();
85 }
86 break;
87 }
88 return 0;
89}
90
91static bool isAlphaIntCondCode(unsigned Opcode) {
92 switch (Opcode) {
93 case Alpha::BEQ:
94 case Alpha::BNE:
95 case Alpha::BGE:
96 case Alpha::BGT:
97 case Alpha::BLE:
98 case Alpha::BLT:
99 case Alpha::BLBC:
100 case Alpha::BLBS:
101 return true;
102 default:
103 return false;
104 }
105}
106
Owen Andersond131b5b2008-08-14 22:49:33 +0000107unsigned AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000108 MachineBasicBlock *TBB,
109 MachineBasicBlock *FBB,
Owen Andersond131b5b2008-08-14 22:49:33 +0000110 const SmallVectorImpl<MachineOperand> &Cond) const {
Dale Johannesen238c69d2009-02-13 02:30:42 +0000111 // FIXME this should probably have a DebugLoc argument
112 DebugLoc dl = DebugLoc::getUnknownLoc();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000113 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
114 assert((Cond.size() == 2 || Cond.size() == 0) &&
115 "Alpha branch conditions have two components!");
116
117 // One-way branch.
118 if (FBB == 0) {
119 if (Cond.empty()) // Unconditional branch
Dale Johannesen238c69d2009-02-13 02:30:42 +0000120 BuildMI(&MBB, dl, get(Alpha::BR)).addMBB(TBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000121 else // Conditional branch
122 if (isAlphaIntCondCode(Cond[0].getImm()))
Dale Johannesen238c69d2009-02-13 02:30:42 +0000123 BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_I))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000124 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
125 else
Dale Johannesen238c69d2009-02-13 02:30:42 +0000126 BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_F))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
128 return 1;
129 }
130
131 // Two-way Conditional Branch.
132 if (isAlphaIntCondCode(Cond[0].getImm()))
Dale Johannesen238c69d2009-02-13 02:30:42 +0000133 BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_I))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000134 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
135 else
Dale Johannesen238c69d2009-02-13 02:30:42 +0000136 BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_F))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000137 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Dale Johannesen238c69d2009-02-13 02:30:42 +0000138 BuildMI(&MBB, dl, get(Alpha::BR)).addMBB(FBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000139 return 2;
140}
141
Owen Anderson9fa72d92008-08-26 18:03:31 +0000142bool AlphaInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000143 MachineBasicBlock::iterator MI,
144 unsigned DestReg, unsigned SrcReg,
145 const TargetRegisterClass *DestRC,
146 const TargetRegisterClass *SrcRC) const {
Owen Anderson8f2c8932007-12-31 06:32:00 +0000147 //cerr << "copyRegToReg " << DestReg << " <- " << SrcReg << "\n";
148 if (DestRC != SrcRC) {
Owen Anderson9fa72d92008-08-26 18:03:31 +0000149 // Not yet supported!
150 return false;
Owen Anderson8f2c8932007-12-31 06:32:00 +0000151 }
152
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000153 DebugLoc DL = DebugLoc::getUnknownLoc();
154 if (MI != MBB.end()) DL = MI->getDebugLoc();
155
Owen Anderson8f2c8932007-12-31 06:32:00 +0000156 if (DestRC == Alpha::GPRCRegisterClass) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000157 BuildMI(MBB, MI, DL, get(Alpha::BISr), DestReg)
158 .addReg(SrcReg)
159 .addReg(SrcReg);
Owen Anderson8f2c8932007-12-31 06:32:00 +0000160 } else if (DestRC == Alpha::F4RCRegisterClass) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000161 BuildMI(MBB, MI, DL, get(Alpha::CPYSS), DestReg)
162 .addReg(SrcReg)
163 .addReg(SrcReg);
Owen Anderson8f2c8932007-12-31 06:32:00 +0000164 } else if (DestRC == Alpha::F8RCRegisterClass) {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000165 BuildMI(MBB, MI, DL, get(Alpha::CPYST), DestReg)
166 .addReg(SrcReg)
167 .addReg(SrcReg);
Owen Anderson8f2c8932007-12-31 06:32:00 +0000168 } else {
Owen Anderson9fa72d92008-08-26 18:03:31 +0000169 // Attempt to copy register that is not GPR or FPR
170 return false;
Owen Anderson8f2c8932007-12-31 06:32:00 +0000171 }
Owen Anderson9fa72d92008-08-26 18:03:31 +0000172
173 return true;
Owen Anderson8f2c8932007-12-31 06:32:00 +0000174}
175
Owen Anderson81875432008-01-01 21:11:32 +0000176void
177AlphaInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000178 MachineBasicBlock::iterator MI,
179 unsigned SrcReg, bool isKill, int FrameIdx,
180 const TargetRegisterClass *RC) const {
Owen Anderson81875432008-01-01 21:11:32 +0000181 //cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
182 // << FrameIdx << "\n";
183 //BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000184
185 DebugLoc DL = DebugLoc::getUnknownLoc();
186 if (MI != MBB.end()) DL = MI->getDebugLoc();
187
Owen Anderson81875432008-01-01 21:11:32 +0000188 if (RC == Alpha::F4RCRegisterClass)
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000189 BuildMI(MBB, MI, DL, get(Alpha::STS))
Owen Anderson81875432008-01-01 21:11:32 +0000190 .addReg(SrcReg, false, false, isKill)
191 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
192 else if (RC == Alpha::F8RCRegisterClass)
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000193 BuildMI(MBB, MI, DL, get(Alpha::STT))
Owen Anderson81875432008-01-01 21:11:32 +0000194 .addReg(SrcReg, false, false, isKill)
195 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
196 else if (RC == Alpha::GPRCRegisterClass)
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000197 BuildMI(MBB, MI, DL, get(Alpha::STQ))
Owen Anderson81875432008-01-01 21:11:32 +0000198 .addReg(SrcReg, false, false, isKill)
199 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
200 else
201 abort();
202}
203
204void AlphaInstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
205 bool isKill,
206 SmallVectorImpl<MachineOperand> &Addr,
207 const TargetRegisterClass *RC,
208 SmallVectorImpl<MachineInstr*> &NewMIs) const {
209 unsigned Opc = 0;
210 if (RC == Alpha::F4RCRegisterClass)
211 Opc = Alpha::STS;
212 else if (RC == Alpha::F8RCRegisterClass)
213 Opc = Alpha::STT;
214 else if (RC == Alpha::GPRCRegisterClass)
215 Opc = Alpha::STQ;
216 else
217 abort();
Dale Johannesen9e3c78d2009-02-12 23:24:44 +0000218 DebugLoc DL = DebugLoc::getUnknownLoc();
Owen Anderson81875432008-01-01 21:11:32 +0000219 MachineInstrBuilder MIB =
Dale Johannesen9e3c78d2009-02-12 23:24:44 +0000220 BuildMI(MF, DL, get(Opc)).addReg(SrcReg, false, false, isKill);
Owen Anderson81875432008-01-01 21:11:32 +0000221 for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
222 MachineOperand &MO = Addr[i];
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000223 if (MO.isReg())
Owen Anderson81875432008-01-01 21:11:32 +0000224 MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit());
225 else
226 MIB.addImm(MO.getImm());
227 }
228 NewMIs.push_back(MIB);
229}
230
231void
232AlphaInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
233 MachineBasicBlock::iterator MI,
234 unsigned DestReg, int FrameIdx,
235 const TargetRegisterClass *RC) const {
236 //cerr << "Trying to load " << getPrettyName(DestReg) << " to "
237 // << FrameIdx << "\n";
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000238 DebugLoc DL = DebugLoc::getUnknownLoc();
239 if (MI != MBB.end()) DL = MI->getDebugLoc();
240
Owen Anderson81875432008-01-01 21:11:32 +0000241 if (RC == Alpha::F4RCRegisterClass)
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000242 BuildMI(MBB, MI, DL, get(Alpha::LDS), DestReg)
Owen Anderson81875432008-01-01 21:11:32 +0000243 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
244 else if (RC == Alpha::F8RCRegisterClass)
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000245 BuildMI(MBB, MI, DL, get(Alpha::LDT), DestReg)
Owen Anderson81875432008-01-01 21:11:32 +0000246 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
247 else if (RC == Alpha::GPRCRegisterClass)
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000248 BuildMI(MBB, MI, DL, get(Alpha::LDQ), DestReg)
Owen Anderson81875432008-01-01 21:11:32 +0000249 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
250 else
251 abort();
252}
253
254void AlphaInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
255 SmallVectorImpl<MachineOperand> &Addr,
256 const TargetRegisterClass *RC,
257 SmallVectorImpl<MachineInstr*> &NewMIs) const {
258 unsigned Opc = 0;
259 if (RC == Alpha::F4RCRegisterClass)
260 Opc = Alpha::LDS;
261 else if (RC == Alpha::F8RCRegisterClass)
262 Opc = Alpha::LDT;
263 else if (RC == Alpha::GPRCRegisterClass)
264 Opc = Alpha::LDQ;
265 else
266 abort();
Dale Johannesen9e3c78d2009-02-12 23:24:44 +0000267 DebugLoc DL = DebugLoc::getUnknownLoc();
Owen Anderson81875432008-01-01 21:11:32 +0000268 MachineInstrBuilder MIB =
Dale Johannesen9e3c78d2009-02-12 23:24:44 +0000269 BuildMI(MF, DL, get(Opc), DestReg);
Owen Anderson81875432008-01-01 21:11:32 +0000270 for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
271 MachineOperand &MO = Addr[i];
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000272 if (MO.isReg())
Owen Anderson81875432008-01-01 21:11:32 +0000273 MIB.addReg(MO.getReg(), MO.isDef(), MO.isImplicit());
274 else
275 MIB.addImm(MO.getImm());
276 }
277 NewMIs.push_back(MIB);
278}
279
Dan Gohmanedc83d62008-12-03 18:43:12 +0000280MachineInstr *AlphaInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
281 MachineInstr *MI,
Dan Gohman46b948e2008-10-16 01:49:15 +0000282 const SmallVectorImpl<unsigned> &Ops,
Dan Gohmanedc83d62008-12-03 18:43:12 +0000283 int FrameIndex) const {
Owen Anderson9a184ef2008-01-07 01:35:02 +0000284 if (Ops.size() != 1) return NULL;
285
286 // Make sure this is a reg-reg copy.
287 unsigned Opc = MI->getOpcode();
288
289 MachineInstr *NewMI = NULL;
290 switch(Opc) {
291 default:
292 break;
293 case Alpha::BISr:
294 case Alpha::CPYSS:
295 case Alpha::CPYST:
296 if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
297 if (Ops[0] == 0) { // move -> store
298 unsigned InReg = MI->getOperand(1).getReg();
Evan Chenge52c1912008-07-03 09:09:37 +0000299 bool isKill = MI->getOperand(1).isKill();
Owen Anderson9a184ef2008-01-07 01:35:02 +0000300 Opc = (Opc == Alpha::BISr) ? Alpha::STQ :
301 ((Opc == Alpha::CPYSS) ? Alpha::STS : Alpha::STT);
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000302 NewMI = BuildMI(MF, MI->getDebugLoc(), get(Opc))
303 .addReg(InReg, false, false, isKill)
Evan Chenge52c1912008-07-03 09:09:37 +0000304 .addFrameIndex(FrameIndex)
Owen Anderson9a184ef2008-01-07 01:35:02 +0000305 .addReg(Alpha::F31);
306 } else { // load -> move
307 unsigned OutReg = MI->getOperand(0).getReg();
Evan Chenge52c1912008-07-03 09:09:37 +0000308 bool isDead = MI->getOperand(0).isDead();
Owen Anderson9a184ef2008-01-07 01:35:02 +0000309 Opc = (Opc == Alpha::BISr) ? Alpha::LDQ :
310 ((Opc == Alpha::CPYSS) ? Alpha::LDS : Alpha::LDT);
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000311 NewMI = BuildMI(MF, MI->getDebugLoc(), get(Opc))
312 .addReg(OutReg, true, false, false, isDead)
Evan Chenge52c1912008-07-03 09:09:37 +0000313 .addFrameIndex(FrameIndex)
Owen Anderson9a184ef2008-01-07 01:35:02 +0000314 .addReg(Alpha::F31);
315 }
316 }
317 break;
318 }
Evan Chenge52c1912008-07-03 09:09:37 +0000319 return NewMI;
Owen Anderson9a184ef2008-01-07 01:35:02 +0000320}
321
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000322static unsigned AlphaRevCondCode(unsigned Opcode) {
323 switch (Opcode) {
324 case Alpha::BEQ: return Alpha::BNE;
325 case Alpha::BNE: return Alpha::BEQ;
326 case Alpha::BGE: return Alpha::BLT;
327 case Alpha::BGT: return Alpha::BLE;
328 case Alpha::BLE: return Alpha::BGT;
329 case Alpha::BLT: return Alpha::BGE;
330 case Alpha::BLBC: return Alpha::BLBS;
331 case Alpha::BLBS: return Alpha::BLBC;
332 case Alpha::FBEQ: return Alpha::FBNE;
333 case Alpha::FBNE: return Alpha::FBEQ;
334 case Alpha::FBGE: return Alpha::FBLT;
335 case Alpha::FBGT: return Alpha::FBLE;
336 case Alpha::FBLE: return Alpha::FBGT;
337 case Alpha::FBLT: return Alpha::FBGE;
338 default:
339 assert(0 && "Unknown opcode");
340 }
Chris Lattner2b06cd32008-03-30 18:22:13 +0000341 return 0; // Not reached
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342}
343
344// Branch analysis.
345bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
Evan Chengeac31642009-02-09 07:14:22 +0000346 MachineBasicBlock *&FBB,
347 SmallVectorImpl<MachineOperand> &Cond,
348 bool AllowModify) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000349 // If the block has no terminators, it just falls into the block after it.
350 MachineBasicBlock::iterator I = MBB.end();
351 if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
352 return false;
353
354 // Get the last instruction in the block.
355 MachineInstr *LastInst = I;
356
357 // If there is only one terminator instruction, process it.
358 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
359 if (LastInst->getOpcode() == Alpha::BR) {
Chris Lattner6017d482007-12-30 23:10:15 +0000360 TBB = LastInst->getOperand(0).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361 return false;
362 } else if (LastInst->getOpcode() == Alpha::COND_BRANCH_I ||
363 LastInst->getOpcode() == Alpha::COND_BRANCH_F) {
364 // Block ends with fall-through condbranch.
Chris Lattner6017d482007-12-30 23:10:15 +0000365 TBB = LastInst->getOperand(2).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 Cond.push_back(LastInst->getOperand(0));
367 Cond.push_back(LastInst->getOperand(1));
368 return false;
369 }
370 // Otherwise, don't know what this is.
371 return true;
372 }
373
374 // Get the instruction before it if it's a terminator.
375 MachineInstr *SecondLastInst = I;
376
377 // If there are three terminators, we don't know what sort of block this is.
378 if (SecondLastInst && I != MBB.begin() &&
379 isUnpredicatedTerminator(--I))
380 return true;
381
382 // If the block ends with Alpha::BR and Alpha::COND_BRANCH_*, handle it.
383 if ((SecondLastInst->getOpcode() == Alpha::COND_BRANCH_I ||
384 SecondLastInst->getOpcode() == Alpha::COND_BRANCH_F) &&
385 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner6017d482007-12-30 23:10:15 +0000386 TBB = SecondLastInst->getOperand(2).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000387 Cond.push_back(SecondLastInst->getOperand(0));
388 Cond.push_back(SecondLastInst->getOperand(1));
Chris Lattner6017d482007-12-30 23:10:15 +0000389 FBB = LastInst->getOperand(0).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390 return false;
391 }
392
393 // If the block ends with two Alpha::BRs, handle it. The second one is not
394 // executed, so remove it.
395 if (SecondLastInst->getOpcode() == Alpha::BR &&
396 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner6017d482007-12-30 23:10:15 +0000397 TBB = SecondLastInst->getOperand(0).getMBB();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398 I = LastInst;
Evan Chengeac31642009-02-09 07:14:22 +0000399 if (AllowModify)
400 I->eraseFromParent();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000401 return false;
402 }
403
404 // Otherwise, can't handle this.
405 return true;
406}
407
408unsigned AlphaInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
409 MachineBasicBlock::iterator I = MBB.end();
410 if (I == MBB.begin()) return 0;
411 --I;
412 if (I->getOpcode() != Alpha::BR &&
413 I->getOpcode() != Alpha::COND_BRANCH_I &&
414 I->getOpcode() != Alpha::COND_BRANCH_F)
415 return 0;
416
417 // Remove the branch.
418 I->eraseFromParent();
419
420 I = MBB.end();
421
422 if (I == MBB.begin()) return 1;
423 --I;
424 if (I->getOpcode() != Alpha::COND_BRANCH_I &&
425 I->getOpcode() != Alpha::COND_BRANCH_F)
426 return 1;
427
428 // Remove the branch.
429 I->eraseFromParent();
430 return 2;
431}
432
433void AlphaInstrInfo::insertNoop(MachineBasicBlock &MBB,
434 MachineBasicBlock::iterator MI) const {
Bill Wendling5b8a97b2009-02-12 00:02:55 +0000435 DebugLoc DL = DebugLoc::getUnknownLoc();
436 if (MI != MBB.end()) DL = MI->getDebugLoc();
437 BuildMI(MBB, MI, DL, get(Alpha::BISr), Alpha::R31)
438 .addReg(Alpha::R31)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 .addReg(Alpha::R31);
440}
441
Dan Gohman46b948e2008-10-16 01:49:15 +0000442bool AlphaInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000443 if (MBB.empty()) return false;
444
445 switch (MBB.back().getOpcode()) {
446 case Alpha::RETDAG: // Return.
447 case Alpha::RETDAGp:
448 case Alpha::BR: // Uncond branch.
449 case Alpha::JMP: // Indirect branch.
450 return true;
451 default: return false;
452 }
453}
454bool AlphaInstrInfo::
Owen Andersond131b5b2008-08-14 22:49:33 +0000455ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000456 assert(Cond.size() == 2 && "Invalid Alpha branch opcode!");
457 Cond[0].setImm(AlphaRevCondCode(Cond[0].getImm()));
458 return false;
459}
460