blob: 6be75a1ea1a4660b76bfaed82756a277d9ffad64 [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"
Dan Gohman99114052009-06-03 20:30:14 +000016#include "AlphaMachineFunctionInfo.h"
Evan Cheng59ee62d2011-07-11 03:57:24 +000017#include "llvm/CodeGen/MachineInstrBuilder.h"
Dan Gohman99114052009-06-03 20:30:14 +000018#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng59ee62d2011-07-11 03:57:24 +000019#include "llvm/Target/TargetRegistry.h"
Owen Anderson718cb662007-09-07 04:06:50 +000020#include "llvm/ADT/STLExtras.h"
Dan Gohmand68a0762009-01-05 17:59:02 +000021#include "llvm/ADT/SmallVector.h"
Torok Edwin804e0fe2009-07-08 19:04:27 +000022#include "llvm/Support/ErrorHandling.h"
Evan Cheng22fee2d2011-06-28 20:07:07 +000023
24#define GET_INSTRINFO_MC_DESC
Evan Cheng4db3cff2011-07-01 17:57:27 +000025#define GET_INSTRINFO_CTOR
Evan Cheng22fee2d2011-06-28 20:07:07 +000026#include "AlphaGenInstrInfo.inc"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000027using namespace llvm;
28
29AlphaInstrInfo::AlphaInstrInfo()
Evan Cheng4db3cff2011-07-01 17:57:27 +000030 : AlphaGenInstrInfo(Alpha::ADJUSTSTACKDOWN, Alpha::ADJUSTSTACKUP),
31 RI(*this) {
32}
Andrew Lenharth304d0f32005-01-22 23:41:55 +000033
34
Chris Lattner40839602006-02-02 20:12:32 +000035unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000036AlphaInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
37 int &FrameIndex) const {
Chris Lattner40839602006-02-02 20:12:32 +000038 switch (MI->getOpcode()) {
39 case Alpha::LDL:
40 case Alpha::LDQ:
41 case Alpha::LDBU:
42 case Alpha::LDWU:
43 case Alpha::LDS:
44 case Alpha::LDT:
Dan Gohmand735b802008-10-03 15:45:36 +000045 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000046 FrameIndex = MI->getOperand(1).getIndex();
Chris Lattner40839602006-02-02 20:12:32 +000047 return MI->getOperand(0).getReg();
48 }
49 break;
50 }
51 return 0;
52}
53
Andrew Lenharth133d3102006-02-03 03:07:37 +000054unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000055AlphaInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
56 int &FrameIndex) const {
Andrew Lenharth133d3102006-02-03 03:07:37 +000057 switch (MI->getOpcode()) {
58 case Alpha::STL:
59 case Alpha::STQ:
60 case Alpha::STB:
61 case Alpha::STW:
62 case Alpha::STS:
63 case Alpha::STT:
Dan Gohmand735b802008-10-03 15:45:36 +000064 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000065 FrameIndex = MI->getOperand(1).getIndex();
Andrew Lenharth133d3102006-02-03 03:07:37 +000066 return MI->getOperand(0).getReg();
67 }
68 break;
69 }
70 return 0;
71}
72
Andrew Lenharthf81173f2006-10-31 16:49:55 +000073static bool isAlphaIntCondCode(unsigned Opcode) {
74 switch (Opcode) {
75 case Alpha::BEQ:
76 case Alpha::BNE:
77 case Alpha::BGE:
78 case Alpha::BGT:
79 case Alpha::BLE:
80 case Alpha::BLT:
81 case Alpha::BLBC:
82 case Alpha::BLBS:
83 return true;
84 default:
85 return false;
86 }
87}
88
Owen Anderson44eb65c2008-08-14 22:49:33 +000089unsigned AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,
Bill Wendlingd1c321a2009-02-12 00:02:55 +000090 MachineBasicBlock *TBB,
91 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +000092 const SmallVectorImpl<MachineOperand> &Cond,
93 DebugLoc DL) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +000094 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
95 assert((Cond.size() == 2 || Cond.size() == 0) &&
96 "Alpha branch conditions have two components!");
97
98 // One-way branch.
99 if (FBB == 0) {
100 if (Cond.empty()) // Unconditional branch
Stuart Hastings3bf91252010-06-17 22:43:56 +0000101 BuildMI(&MBB, DL, get(Alpha::BR)).addMBB(TBB);
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000102 else // Conditional branch
103 if (isAlphaIntCondCode(Cond[0].getImm()))
Stuart Hastings3bf91252010-06-17 22:43:56 +0000104 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000105 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
106 else
Stuart Hastings3bf91252010-06-17 22:43:56 +0000107 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000108 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000109 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000110 }
111
112 // Two-way Conditional Branch.
113 if (isAlphaIntCondCode(Cond[0].getImm()))
Stuart Hastings3bf91252010-06-17 22:43:56 +0000114 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000115 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
116 else
Stuart Hastings3bf91252010-06-17 22:43:56 +0000117 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000118 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Stuart Hastings3bf91252010-06-17 22:43:56 +0000119 BuildMI(&MBB, DL, get(Alpha::BR)).addMBB(FBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000120 return 2;
Rafael Espindola3d7d39a2006-10-24 17:07:11 +0000121}
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000122
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000123void AlphaInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
124 MachineBasicBlock::iterator MI, DebugLoc DL,
125 unsigned DestReg, unsigned SrcReg,
126 bool KillSrc) const {
127 if (Alpha::GPRCRegClass.contains(DestReg, SrcReg)) {
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000128 BuildMI(MBB, MI, DL, get(Alpha::BISr), DestReg)
129 .addReg(SrcReg)
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000130 .addReg(SrcReg, getKillRegState(KillSrc));
131 } else if (Alpha::F4RCRegClass.contains(DestReg, SrcReg)) {
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000132 BuildMI(MBB, MI, DL, get(Alpha::CPYSS), DestReg)
133 .addReg(SrcReg)
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000134 .addReg(SrcReg, getKillRegState(KillSrc));
135 } else if (Alpha::F8RCRegClass.contains(DestReg, SrcReg)) {
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000136 BuildMI(MBB, MI, DL, get(Alpha::CPYST), DestReg)
137 .addReg(SrcReg)
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000138 .addReg(SrcReg, getKillRegState(KillSrc));
Owen Andersond10fd972007-12-31 06:32:00 +0000139 } else {
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000140 llvm_unreachable("Attempt to copy register that is not GPR or FPR");
Owen Andersond10fd972007-12-31 06:32:00 +0000141 }
142}
143
Owen Andersonf6372aa2008-01-01 21:11:32 +0000144void
145AlphaInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000146 MachineBasicBlock::iterator MI,
147 unsigned SrcReg, bool isKill, int FrameIdx,
Evan Cheng746ad692010-05-06 19:06:44 +0000148 const TargetRegisterClass *RC,
149 const TargetRegisterInfo *TRI) const {
Owen Andersonf6372aa2008-01-01 21:11:32 +0000150 //cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
151 // << FrameIdx << "\n";
152 //BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000153
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000154 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000155 if (MI != MBB.end()) DL = MI->getDebugLoc();
156
Owen Andersonf6372aa2008-01-01 21:11:32 +0000157 if (RC == Alpha::F4RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000158 BuildMI(MBB, MI, DL, get(Alpha::STS))
Bill Wendling587daed2009-05-13 21:33:08 +0000159 .addReg(SrcReg, getKillRegState(isKill))
Owen Andersonf6372aa2008-01-01 21:11:32 +0000160 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
161 else if (RC == Alpha::F8RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000162 BuildMI(MBB, MI, DL, get(Alpha::STT))
Bill Wendling587daed2009-05-13 21:33:08 +0000163 .addReg(SrcReg, getKillRegState(isKill))
Owen Andersonf6372aa2008-01-01 21:11:32 +0000164 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
165 else if (RC == Alpha::GPRCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000166 BuildMI(MBB, MI, DL, get(Alpha::STQ))
Bill Wendling587daed2009-05-13 21:33:08 +0000167 .addReg(SrcReg, getKillRegState(isKill))
Owen Andersonf6372aa2008-01-01 21:11:32 +0000168 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
169 else
Torok Edwinc23197a2009-07-14 16:55:14 +0000170 llvm_unreachable("Unhandled register class");
Owen Andersonf6372aa2008-01-01 21:11:32 +0000171}
172
Owen Andersonf6372aa2008-01-01 21:11:32 +0000173void
174AlphaInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
175 MachineBasicBlock::iterator MI,
176 unsigned DestReg, int FrameIdx,
Evan Cheng746ad692010-05-06 19:06:44 +0000177 const TargetRegisterClass *RC,
178 const TargetRegisterInfo *TRI) const {
Owen Andersonf6372aa2008-01-01 21:11:32 +0000179 //cerr << "Trying to load " << getPrettyName(DestReg) << " to "
180 // << FrameIdx << "\n";
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000181 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000182 if (MI != MBB.end()) DL = MI->getDebugLoc();
183
Owen Andersonf6372aa2008-01-01 21:11:32 +0000184 if (RC == Alpha::F4RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000185 BuildMI(MBB, MI, DL, get(Alpha::LDS), DestReg)
Owen Andersonf6372aa2008-01-01 21:11:32 +0000186 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
187 else if (RC == Alpha::F8RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000188 BuildMI(MBB, MI, DL, get(Alpha::LDT), DestReg)
Owen Andersonf6372aa2008-01-01 21:11:32 +0000189 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
190 else if (RC == Alpha::GPRCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000191 BuildMI(MBB, MI, DL, get(Alpha::LDQ), DestReg)
Owen Andersonf6372aa2008-01-01 21:11:32 +0000192 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
193 else
Torok Edwinc23197a2009-07-14 16:55:14 +0000194 llvm_unreachable("Unhandled register class");
Owen Andersonf6372aa2008-01-01 21:11:32 +0000195}
196
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000197static unsigned AlphaRevCondCode(unsigned Opcode) {
198 switch (Opcode) {
199 case Alpha::BEQ: return Alpha::BNE;
200 case Alpha::BNE: return Alpha::BEQ;
201 case Alpha::BGE: return Alpha::BLT;
202 case Alpha::BGT: return Alpha::BLE;
203 case Alpha::BLE: return Alpha::BGT;
204 case Alpha::BLT: return Alpha::BGE;
205 case Alpha::BLBC: return Alpha::BLBS;
206 case Alpha::BLBS: return Alpha::BLBC;
207 case Alpha::FBEQ: return Alpha::FBNE;
208 case Alpha::FBNE: return Alpha::FBEQ;
209 case Alpha::FBGE: return Alpha::FBLT;
210 case Alpha::FBGT: return Alpha::FBLE;
211 case Alpha::FBLE: return Alpha::FBGT;
212 case Alpha::FBLT: return Alpha::FBGE;
213 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000214 llvm_unreachable("Unknown opcode");
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000215 }
Chris Lattnerd27c9912008-03-30 18:22:13 +0000216 return 0; // Not reached
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000217}
218
219// Branch analysis.
220bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
Evan Chengdc54d312009-02-09 07:14:22 +0000221 MachineBasicBlock *&FBB,
222 SmallVectorImpl<MachineOperand> &Cond,
223 bool AllowModify) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000224 // If the block has no terminators, it just falls into the block after it.
225 MachineBasicBlock::iterator I = MBB.end();
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000226 if (I == MBB.begin())
227 return false;
228 --I;
229 while (I->isDebugValue()) {
230 if (I == MBB.begin())
231 return false;
232 --I;
233 }
234 if (!isUnpredicatedTerminator(I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000235 return false;
236
237 // Get the last instruction in the block.
238 MachineInstr *LastInst = I;
239
240 // If there is only one terminator instruction, process it.
Evan Chengbfd2ec42007-06-08 21:59:56 +0000241 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000242 if (LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000243 TBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000244 return false;
245 } else if (LastInst->getOpcode() == Alpha::COND_BRANCH_I ||
246 LastInst->getOpcode() == Alpha::COND_BRANCH_F) {
247 // Block ends with fall-through condbranch.
Chris Lattner8aa797a2007-12-30 23:10:15 +0000248 TBB = LastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000249 Cond.push_back(LastInst->getOperand(0));
250 Cond.push_back(LastInst->getOperand(1));
251 return false;
252 }
253 // Otherwise, don't know what this is.
254 return true;
255 }
256
257 // Get the instruction before it if it's a terminator.
258 MachineInstr *SecondLastInst = I;
259
260 // If there are three terminators, we don't know what sort of block this is.
261 if (SecondLastInst && I != MBB.begin() &&
Evan Chengbfd2ec42007-06-08 21:59:56 +0000262 isUnpredicatedTerminator(--I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000263 return true;
264
265 // If the block ends with Alpha::BR and Alpha::COND_BRANCH_*, handle it.
266 if ((SecondLastInst->getOpcode() == Alpha::COND_BRANCH_I ||
267 SecondLastInst->getOpcode() == Alpha::COND_BRANCH_F) &&
268 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000269 TBB = SecondLastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000270 Cond.push_back(SecondLastInst->getOperand(0));
271 Cond.push_back(SecondLastInst->getOperand(1));
Chris Lattner8aa797a2007-12-30 23:10:15 +0000272 FBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000273 return false;
274 }
275
Dale Johannesen13e8b512007-06-13 17:59:52 +0000276 // If the block ends with two Alpha::BRs, handle it. The second one is not
277 // executed, so remove it.
278 if (SecondLastInst->getOpcode() == Alpha::BR &&
279 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000280 TBB = SecondLastInst->getOperand(0).getMBB();
Dale Johannesen13e8b512007-06-13 17:59:52 +0000281 I = LastInst;
Evan Chengdc54d312009-02-09 07:14:22 +0000282 if (AllowModify)
283 I->eraseFromParent();
Dale Johannesen13e8b512007-06-13 17:59:52 +0000284 return false;
285 }
286
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000287 // Otherwise, can't handle this.
288 return true;
289}
290
Evan Chengb5cdaa22007-05-18 00:05:48 +0000291unsigned AlphaInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000292 MachineBasicBlock::iterator I = MBB.end();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000293 if (I == MBB.begin()) return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000294 --I;
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000295 while (I->isDebugValue()) {
296 if (I == MBB.begin())
297 return 0;
298 --I;
299 }
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000300 if (I->getOpcode() != Alpha::BR &&
301 I->getOpcode() != Alpha::COND_BRANCH_I &&
302 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000303 return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000304
305 // Remove the branch.
306 I->eraseFromParent();
307
308 I = MBB.end();
309
Evan Chengb5cdaa22007-05-18 00:05:48 +0000310 if (I == MBB.begin()) return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000311 --I;
312 if (I->getOpcode() != Alpha::COND_BRANCH_I &&
313 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000314 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000315
316 // Remove the branch.
317 I->eraseFromParent();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000318 return 2;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000319}
320
321void AlphaInstrInfo::insertNoop(MachineBasicBlock &MBB,
322 MachineBasicBlock::iterator MI) const {
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000323 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000324 BuildMI(MBB, MI, DL, get(Alpha::BISr), Alpha::R31)
325 .addReg(Alpha::R31)
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000326 .addReg(Alpha::R31);
327}
328
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000329bool AlphaInstrInfo::
Owen Anderson44eb65c2008-08-14 22:49:33 +0000330ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000331 assert(Cond.size() == 2 && "Invalid Alpha branch opcode!");
332 Cond[0].setImm(AlphaRevCondCode(Cond[0].getImm()));
333 return false;
334}
335
Dan Gohman99114052009-06-03 20:30:14 +0000336/// getGlobalBaseReg - Return a virtual register initialized with the
337/// the global base register value. Output instructions required to
338/// initialize the register in the function entry block, if necessary.
339///
340unsigned AlphaInstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
341 AlphaMachineFunctionInfo *AlphaFI = MF->getInfo<AlphaMachineFunctionInfo>();
342 unsigned GlobalBaseReg = AlphaFI->getGlobalBaseReg();
343 if (GlobalBaseReg != 0)
344 return GlobalBaseReg;
345
346 // Insert the set of GlobalBaseReg into the first MBB of the function
347 MachineBasicBlock &FirstMBB = MF->front();
348 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
349 MachineRegisterInfo &RegInfo = MF->getRegInfo();
350 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
351
352 GlobalBaseReg = RegInfo.createVirtualRegister(&Alpha::GPRCRegClass);
Jakob Stoklund Olesen3ecf1f02010-07-10 22:43:03 +0000353 BuildMI(FirstMBB, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY),
354 GlobalBaseReg).addReg(Alpha::R29);
Dan Gohman99114052009-06-03 20:30:14 +0000355 RegInfo.addLiveIn(Alpha::R29);
356
357 AlphaFI->setGlobalBaseReg(GlobalBaseReg);
358 return GlobalBaseReg;
359}
360
361/// getGlobalRetAddr - Return a virtual register initialized with the
362/// the global base register value. Output instructions required to
363/// initialize the register in the function entry block, if necessary.
364///
365unsigned AlphaInstrInfo::getGlobalRetAddr(MachineFunction *MF) const {
366 AlphaMachineFunctionInfo *AlphaFI = MF->getInfo<AlphaMachineFunctionInfo>();
367 unsigned GlobalRetAddr = AlphaFI->getGlobalRetAddr();
368 if (GlobalRetAddr != 0)
369 return GlobalRetAddr;
370
371 // Insert the set of GlobalRetAddr into the first MBB of the function
372 MachineBasicBlock &FirstMBB = MF->front();
373 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
374 MachineRegisterInfo &RegInfo = MF->getRegInfo();
375 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
376
377 GlobalRetAddr = RegInfo.createVirtualRegister(&Alpha::GPRCRegClass);
Jakob Stoklund Olesen3ecf1f02010-07-10 22:43:03 +0000378 BuildMI(FirstMBB, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY),
379 GlobalRetAddr).addReg(Alpha::R26);
Dan Gohman99114052009-06-03 20:30:14 +0000380 RegInfo.addLiveIn(Alpha::R26);
381
382 AlphaFI->setGlobalRetAddr(GlobalRetAddr);
383 return GlobalRetAddr;
384}
Evan Cheng59ee62d2011-07-11 03:57:24 +0000385
386MCInstrInfo *createAlphaMCInstrInfo() {
387 MCInstrInfo *X = new MCInstrInfo();
388 InitAlphaMCInstrInfo(X);
389 return X;
390}
391
392extern "C" void LLVMInitializeAlphaMCInstrInfo() {
393 TargetRegistry::RegisterMCInstrInfo(TheAlphaTarget, createAlphaMCInstrInfo);
394}