blob: 5a2f5610fdb49b6e1416d058da3094cc59fdc141 [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"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000017#include "AlphaGenInstrInfo.inc"
Dan Gohman99114052009-06-03 20:30:14 +000018#include "llvm/CodeGen/MachineRegisterInfo.h"
Owen Anderson718cb662007-09-07 04:06:50 +000019#include "llvm/ADT/STLExtras.h"
Dan Gohmand68a0762009-01-05 17:59:02 +000020#include "llvm/ADT/SmallVector.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000021#include "llvm/CodeGen/MachineInstrBuilder.h"
Torok Edwin804e0fe2009-07-08 19:04:27 +000022#include "llvm/Support/ErrorHandling.h"
Andrew Lenharth304d0f32005-01-22 23:41:55 +000023using namespace llvm;
24
25AlphaInstrInfo::AlphaInstrInfo()
Chris Lattner64105522008-01-01 01:03:04 +000026 : TargetInstrInfoImpl(AlphaInsts, array_lengthof(AlphaInsts)),
Evan Cheng7ce45782006-11-13 23:36:35 +000027 RI(*this) { }
Andrew Lenharth304d0f32005-01-22 23:41:55 +000028
29
Chris Lattner40839602006-02-02 20:12:32 +000030unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000031AlphaInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
32 int &FrameIndex) const {
Chris Lattner40839602006-02-02 20:12:32 +000033 switch (MI->getOpcode()) {
34 case Alpha::LDL:
35 case Alpha::LDQ:
36 case Alpha::LDBU:
37 case Alpha::LDWU:
38 case Alpha::LDS:
39 case Alpha::LDT:
Dan Gohmand735b802008-10-03 15:45:36 +000040 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000041 FrameIndex = MI->getOperand(1).getIndex();
Chris Lattner40839602006-02-02 20:12:32 +000042 return MI->getOperand(0).getReg();
43 }
44 break;
45 }
46 return 0;
47}
48
Andrew Lenharth133d3102006-02-03 03:07:37 +000049unsigned
Dan Gohmancbad42c2008-11-18 19:49:32 +000050AlphaInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
51 int &FrameIndex) const {
Andrew Lenharth133d3102006-02-03 03:07:37 +000052 switch (MI->getOpcode()) {
53 case Alpha::STL:
54 case Alpha::STQ:
55 case Alpha::STB:
56 case Alpha::STW:
57 case Alpha::STS:
58 case Alpha::STT:
Dan Gohmand735b802008-10-03 15:45:36 +000059 if (MI->getOperand(1).isFI()) {
Chris Lattner8aa797a2007-12-30 23:10:15 +000060 FrameIndex = MI->getOperand(1).getIndex();
Andrew Lenharth133d3102006-02-03 03:07:37 +000061 return MI->getOperand(0).getReg();
62 }
63 break;
64 }
65 return 0;
66}
67
Andrew Lenharthf81173f2006-10-31 16:49:55 +000068static bool isAlphaIntCondCode(unsigned Opcode) {
69 switch (Opcode) {
70 case Alpha::BEQ:
71 case Alpha::BNE:
72 case Alpha::BGE:
73 case Alpha::BGT:
74 case Alpha::BLE:
75 case Alpha::BLT:
76 case Alpha::BLBC:
77 case Alpha::BLBS:
78 return true;
79 default:
80 return false;
81 }
82}
83
Owen Anderson44eb65c2008-08-14 22:49:33 +000084unsigned AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,
Bill Wendlingd1c321a2009-02-12 00:02:55 +000085 MachineBasicBlock *TBB,
86 MachineBasicBlock *FBB,
Stuart Hastings3bf91252010-06-17 22:43:56 +000087 const SmallVectorImpl<MachineOperand> &Cond,
88 DebugLoc DL) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +000089 assert(TBB && "InsertBranch must not be told to insert a fallthrough");
90 assert((Cond.size() == 2 || Cond.size() == 0) &&
91 "Alpha branch conditions have two components!");
92
93 // One-way branch.
94 if (FBB == 0) {
95 if (Cond.empty()) // Unconditional branch
Stuart Hastings3bf91252010-06-17 22:43:56 +000096 BuildMI(&MBB, DL, get(Alpha::BR)).addMBB(TBB);
Andrew Lenharthf81173f2006-10-31 16:49:55 +000097 else // Conditional branch
98 if (isAlphaIntCondCode(Cond[0].getImm()))
Stuart Hastings3bf91252010-06-17 22:43:56 +000099 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000100 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
101 else
Stuart Hastings3bf91252010-06-17 22:43:56 +0000102 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000103 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000104 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000105 }
106
107 // Two-way Conditional Branch.
108 if (isAlphaIntCondCode(Cond[0].getImm()))
Stuart Hastings3bf91252010-06-17 22:43:56 +0000109 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000110 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
111 else
Stuart Hastings3bf91252010-06-17 22:43:56 +0000112 BuildMI(&MBB, DL, get(Alpha::COND_BRANCH_F))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000113 .addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
Stuart Hastings3bf91252010-06-17 22:43:56 +0000114 BuildMI(&MBB, DL, get(Alpha::BR)).addMBB(FBB);
Evan Chengb5cdaa22007-05-18 00:05:48 +0000115 return 2;
Rafael Espindola3d7d39a2006-10-24 17:07:11 +0000116}
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000117
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000118void AlphaInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
119 MachineBasicBlock::iterator MI, DebugLoc DL,
120 unsigned DestReg, unsigned SrcReg,
121 bool KillSrc) const {
122 if (Alpha::GPRCRegClass.contains(DestReg, SrcReg)) {
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000123 BuildMI(MBB, MI, DL, get(Alpha::BISr), DestReg)
124 .addReg(SrcReg)
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000125 .addReg(SrcReg, getKillRegState(KillSrc));
126 } else if (Alpha::F4RCRegClass.contains(DestReg, SrcReg)) {
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000127 BuildMI(MBB, MI, DL, get(Alpha::CPYSS), DestReg)
128 .addReg(SrcReg)
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000129 .addReg(SrcReg, getKillRegState(KillSrc));
130 } else if (Alpha::F8RCRegClass.contains(DestReg, SrcReg)) {
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000131 BuildMI(MBB, MI, DL, get(Alpha::CPYST), DestReg)
132 .addReg(SrcReg)
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000133 .addReg(SrcReg, getKillRegState(KillSrc));
Owen Andersond10fd972007-12-31 06:32:00 +0000134 } else {
Jakob Stoklund Olesen99666a32010-07-11 01:08:23 +0000135 llvm_unreachable("Attempt to copy register that is not GPR or FPR");
Owen Andersond10fd972007-12-31 06:32:00 +0000136 }
137}
138
Owen Andersonf6372aa2008-01-01 21:11:32 +0000139void
140AlphaInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000141 MachineBasicBlock::iterator MI,
142 unsigned SrcReg, bool isKill, int FrameIdx,
Evan Cheng746ad692010-05-06 19:06:44 +0000143 const TargetRegisterClass *RC,
144 const TargetRegisterInfo *TRI) const {
Owen Andersonf6372aa2008-01-01 21:11:32 +0000145 //cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
146 // << FrameIdx << "\n";
147 //BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000148
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000149 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000150 if (MI != MBB.end()) DL = MI->getDebugLoc();
151
Owen Andersonf6372aa2008-01-01 21:11:32 +0000152 if (RC == Alpha::F4RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000153 BuildMI(MBB, MI, DL, get(Alpha::STS))
Bill Wendling587daed2009-05-13 21:33:08 +0000154 .addReg(SrcReg, getKillRegState(isKill))
Owen Andersonf6372aa2008-01-01 21:11:32 +0000155 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
156 else if (RC == Alpha::F8RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000157 BuildMI(MBB, MI, DL, get(Alpha::STT))
Bill Wendling587daed2009-05-13 21:33:08 +0000158 .addReg(SrcReg, getKillRegState(isKill))
Owen Andersonf6372aa2008-01-01 21:11:32 +0000159 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
160 else if (RC == Alpha::GPRCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000161 BuildMI(MBB, MI, DL, get(Alpha::STQ))
Bill Wendling587daed2009-05-13 21:33:08 +0000162 .addReg(SrcReg, getKillRegState(isKill))
Owen Andersonf6372aa2008-01-01 21:11:32 +0000163 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
164 else
Torok Edwinc23197a2009-07-14 16:55:14 +0000165 llvm_unreachable("Unhandled register class");
Owen Andersonf6372aa2008-01-01 21:11:32 +0000166}
167
Owen Andersonf6372aa2008-01-01 21:11:32 +0000168void
169AlphaInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
170 MachineBasicBlock::iterator MI,
171 unsigned DestReg, int FrameIdx,
Evan Cheng746ad692010-05-06 19:06:44 +0000172 const TargetRegisterClass *RC,
173 const TargetRegisterInfo *TRI) const {
Owen Andersonf6372aa2008-01-01 21:11:32 +0000174 //cerr << "Trying to load " << getPrettyName(DestReg) << " to "
175 // << FrameIdx << "\n";
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000176 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000177 if (MI != MBB.end()) DL = MI->getDebugLoc();
178
Owen Andersonf6372aa2008-01-01 21:11:32 +0000179 if (RC == Alpha::F4RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000180 BuildMI(MBB, MI, DL, get(Alpha::LDS), DestReg)
Owen Andersonf6372aa2008-01-01 21:11:32 +0000181 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
182 else if (RC == Alpha::F8RCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000183 BuildMI(MBB, MI, DL, get(Alpha::LDT), DestReg)
Owen Andersonf6372aa2008-01-01 21:11:32 +0000184 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
185 else if (RC == Alpha::GPRCRegisterClass)
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000186 BuildMI(MBB, MI, DL, get(Alpha::LDQ), DestReg)
Owen Andersonf6372aa2008-01-01 21:11:32 +0000187 .addFrameIndex(FrameIdx).addReg(Alpha::F31);
188 else
Torok Edwinc23197a2009-07-14 16:55:14 +0000189 llvm_unreachable("Unhandled register class");
Owen Andersonf6372aa2008-01-01 21:11:32 +0000190}
191
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000192static unsigned AlphaRevCondCode(unsigned Opcode) {
193 switch (Opcode) {
194 case Alpha::BEQ: return Alpha::BNE;
195 case Alpha::BNE: return Alpha::BEQ;
196 case Alpha::BGE: return Alpha::BLT;
197 case Alpha::BGT: return Alpha::BLE;
198 case Alpha::BLE: return Alpha::BGT;
199 case Alpha::BLT: return Alpha::BGE;
200 case Alpha::BLBC: return Alpha::BLBS;
201 case Alpha::BLBS: return Alpha::BLBC;
202 case Alpha::FBEQ: return Alpha::FBNE;
203 case Alpha::FBNE: return Alpha::FBEQ;
204 case Alpha::FBGE: return Alpha::FBLT;
205 case Alpha::FBGT: return Alpha::FBLE;
206 case Alpha::FBLE: return Alpha::FBGT;
207 case Alpha::FBLT: return Alpha::FBGE;
208 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000209 llvm_unreachable("Unknown opcode");
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000210 }
Chris Lattnerd27c9912008-03-30 18:22:13 +0000211 return 0; // Not reached
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000212}
213
214// Branch analysis.
215bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
Evan Chengdc54d312009-02-09 07:14:22 +0000216 MachineBasicBlock *&FBB,
217 SmallVectorImpl<MachineOperand> &Cond,
218 bool AllowModify) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000219 // If the block has no terminators, it just falls into the block after it.
220 MachineBasicBlock::iterator I = MBB.end();
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000221 if (I == MBB.begin())
222 return false;
223 --I;
224 while (I->isDebugValue()) {
225 if (I == MBB.begin())
226 return false;
227 --I;
228 }
229 if (!isUnpredicatedTerminator(I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000230 return false;
231
232 // Get the last instruction in the block.
233 MachineInstr *LastInst = I;
234
235 // If there is only one terminator instruction, process it.
Evan Chengbfd2ec42007-06-08 21:59:56 +0000236 if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000237 if (LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000238 TBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000239 return false;
240 } else if (LastInst->getOpcode() == Alpha::COND_BRANCH_I ||
241 LastInst->getOpcode() == Alpha::COND_BRANCH_F) {
242 // Block ends with fall-through condbranch.
Chris Lattner8aa797a2007-12-30 23:10:15 +0000243 TBB = LastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000244 Cond.push_back(LastInst->getOperand(0));
245 Cond.push_back(LastInst->getOperand(1));
246 return false;
247 }
248 // Otherwise, don't know what this is.
249 return true;
250 }
251
252 // Get the instruction before it if it's a terminator.
253 MachineInstr *SecondLastInst = I;
254
255 // If there are three terminators, we don't know what sort of block this is.
256 if (SecondLastInst && I != MBB.begin() &&
Evan Chengbfd2ec42007-06-08 21:59:56 +0000257 isUnpredicatedTerminator(--I))
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000258 return true;
259
260 // If the block ends with Alpha::BR and Alpha::COND_BRANCH_*, handle it.
261 if ((SecondLastInst->getOpcode() == Alpha::COND_BRANCH_I ||
262 SecondLastInst->getOpcode() == Alpha::COND_BRANCH_F) &&
263 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000264 TBB = SecondLastInst->getOperand(2).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000265 Cond.push_back(SecondLastInst->getOperand(0));
266 Cond.push_back(SecondLastInst->getOperand(1));
Chris Lattner8aa797a2007-12-30 23:10:15 +0000267 FBB = LastInst->getOperand(0).getMBB();
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000268 return false;
269 }
270
Dale Johannesen13e8b512007-06-13 17:59:52 +0000271 // If the block ends with two Alpha::BRs, handle it. The second one is not
272 // executed, so remove it.
273 if (SecondLastInst->getOpcode() == Alpha::BR &&
274 LastInst->getOpcode() == Alpha::BR) {
Chris Lattner8aa797a2007-12-30 23:10:15 +0000275 TBB = SecondLastInst->getOperand(0).getMBB();
Dale Johannesen13e8b512007-06-13 17:59:52 +0000276 I = LastInst;
Evan Chengdc54d312009-02-09 07:14:22 +0000277 if (AllowModify)
278 I->eraseFromParent();
Dale Johannesen13e8b512007-06-13 17:59:52 +0000279 return false;
280 }
281
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000282 // Otherwise, can't handle this.
283 return true;
284}
285
Evan Chengb5cdaa22007-05-18 00:05:48 +0000286unsigned AlphaInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000287 MachineBasicBlock::iterator I = MBB.end();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000288 if (I == MBB.begin()) return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000289 --I;
Dale Johannesen93d6a7e2010-04-02 01:38:09 +0000290 while (I->isDebugValue()) {
291 if (I == MBB.begin())
292 return 0;
293 --I;
294 }
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000295 if (I->getOpcode() != Alpha::BR &&
296 I->getOpcode() != Alpha::COND_BRANCH_I &&
297 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000298 return 0;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000299
300 // Remove the branch.
301 I->eraseFromParent();
302
303 I = MBB.end();
304
Evan Chengb5cdaa22007-05-18 00:05:48 +0000305 if (I == MBB.begin()) return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000306 --I;
307 if (I->getOpcode() != Alpha::COND_BRANCH_I &&
308 I->getOpcode() != Alpha::COND_BRANCH_F)
Evan Chengb5cdaa22007-05-18 00:05:48 +0000309 return 1;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000310
311 // Remove the branch.
312 I->eraseFromParent();
Evan Chengb5cdaa22007-05-18 00:05:48 +0000313 return 2;
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000314}
315
316void AlphaInstrInfo::insertNoop(MachineBasicBlock &MBB,
317 MachineBasicBlock::iterator MI) const {
Chris Lattnerc7f3ace2010-04-02 20:16:16 +0000318 DebugLoc DL;
Bill Wendlingd1c321a2009-02-12 00:02:55 +0000319 BuildMI(MBB, MI, DL, get(Alpha::BISr), Alpha::R31)
320 .addReg(Alpha::R31)
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000321 .addReg(Alpha::R31);
322}
323
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000324bool AlphaInstrInfo::
Owen Anderson44eb65c2008-08-14 22:49:33 +0000325ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
Andrew Lenharthf81173f2006-10-31 16:49:55 +0000326 assert(Cond.size() == 2 && "Invalid Alpha branch opcode!");
327 Cond[0].setImm(AlphaRevCondCode(Cond[0].getImm()));
328 return false;
329}
330
Dan Gohman99114052009-06-03 20:30:14 +0000331/// getGlobalBaseReg - Return a virtual register initialized with the
332/// the global base register value. Output instructions required to
333/// initialize the register in the function entry block, if necessary.
334///
335unsigned AlphaInstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
336 AlphaMachineFunctionInfo *AlphaFI = MF->getInfo<AlphaMachineFunctionInfo>();
337 unsigned GlobalBaseReg = AlphaFI->getGlobalBaseReg();
338 if (GlobalBaseReg != 0)
339 return GlobalBaseReg;
340
341 // Insert the set of GlobalBaseReg into the first MBB of the function
342 MachineBasicBlock &FirstMBB = MF->front();
343 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
344 MachineRegisterInfo &RegInfo = MF->getRegInfo();
345 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
346
347 GlobalBaseReg = RegInfo.createVirtualRegister(&Alpha::GPRCRegClass);
Jakob Stoklund Olesen3ecf1f02010-07-10 22:43:03 +0000348 BuildMI(FirstMBB, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY),
349 GlobalBaseReg).addReg(Alpha::R29);
Dan Gohman99114052009-06-03 20:30:14 +0000350 RegInfo.addLiveIn(Alpha::R29);
351
352 AlphaFI->setGlobalBaseReg(GlobalBaseReg);
353 return GlobalBaseReg;
354}
355
356/// getGlobalRetAddr - Return a virtual register initialized with the
357/// the global base register value. Output instructions required to
358/// initialize the register in the function entry block, if necessary.
359///
360unsigned AlphaInstrInfo::getGlobalRetAddr(MachineFunction *MF) const {
361 AlphaMachineFunctionInfo *AlphaFI = MF->getInfo<AlphaMachineFunctionInfo>();
362 unsigned GlobalRetAddr = AlphaFI->getGlobalRetAddr();
363 if (GlobalRetAddr != 0)
364 return GlobalRetAddr;
365
366 // Insert the set of GlobalRetAddr into the first MBB of the function
367 MachineBasicBlock &FirstMBB = MF->front();
368 MachineBasicBlock::iterator MBBI = FirstMBB.begin();
369 MachineRegisterInfo &RegInfo = MF->getRegInfo();
370 const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
371
372 GlobalRetAddr = RegInfo.createVirtualRegister(&Alpha::GPRCRegClass);
Jakob Stoklund Olesen3ecf1f02010-07-10 22:43:03 +0000373 BuildMI(FirstMBB, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY),
374 GlobalRetAddr).addReg(Alpha::R26);
Dan Gohman99114052009-06-03 20:30:14 +0000375 RegInfo.addLiveIn(Alpha::R26);
376
377 AlphaFI->setGlobalRetAddr(GlobalRetAddr);
378 return GlobalRetAddr;
379}