Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 1 | //===- SparcInstrInfo.cpp - Sparc Instruction Information -------*- C++ -*-===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 10 | // This file contains the Sparc implementation of the TargetInstrInfo class. |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 14 | #include "SparcInstrInfo.h" |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 15 | #include "SparcSubtarget.h" |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 16 | #include "Sparc.h" |
Owen Anderson | 718cb66 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Dan Gohman | d68a076 | 2009-01-05 17:59:02 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | db486a6 | 2009-09-15 17:46:24 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 22 | #include "SparcGenInstrInfo.inc" |
Chris Lattner | db486a6 | 2009-09-15 17:46:24 +0000 | [diff] [blame] | 23 | #include "SparcMachineFunctionInfo.h" |
Chris Lattner | 1ddf475 | 2004-02-29 05:59:33 +0000 | [diff] [blame] | 24 | using namespace llvm; |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 26 | SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST) |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 27 | : TargetInstrInfoImpl(SparcInsts, array_lengthof(SparcInsts)), |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 28 | RI(ST, *this), Subtarget(ST) { |
Brian Gaeke | e785e53 | 2004-02-25 19:28:19 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Chris Lattner | 5ccc722 | 2006-02-03 06:44:54 +0000 | [diff] [blame] | 31 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 32 | /// load from a stack slot, return the virtual or physical register number of |
| 33 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 34 | /// not, return 0. This predicate must return 0 if the instruction has |
| 35 | /// any side effects other than loading from the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 36 | unsigned SparcInstrInfo::isLoadFromStackSlot(const MachineInstr *MI, |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 37 | int &FrameIndex) const { |
| 38 | if (MI->getOpcode() == SP::LDri || |
| 39 | MI->getOpcode() == SP::LDFri || |
| 40 | MI->getOpcode() == SP::LDDFri) { |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 41 | if (MI->getOperand(1).isFI() && MI->getOperand(2).isImm() && |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 42 | MI->getOperand(2).getImm() == 0) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 43 | FrameIndex = MI->getOperand(1).getIndex(); |
Chris Lattner | 5ccc722 | 2006-02-03 06:44:54 +0000 | [diff] [blame] | 44 | return MI->getOperand(0).getReg(); |
| 45 | } |
| 46 | } |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 51 | /// store to a stack slot, return the virtual or physical register number of |
| 52 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 53 | /// not, return 0. This predicate must return 0 if the instruction has |
| 54 | /// any side effects other than storing to the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 55 | unsigned SparcInstrInfo::isStoreToStackSlot(const MachineInstr *MI, |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 56 | int &FrameIndex) const { |
| 57 | if (MI->getOpcode() == SP::STri || |
| 58 | MI->getOpcode() == SP::STFri || |
| 59 | MI->getOpcode() == SP::STDFri) { |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 60 | if (MI->getOperand(0).isFI() && MI->getOperand(1).isImm() && |
Chris Lattner | 9a1ceae | 2007-12-30 20:49:49 +0000 | [diff] [blame] | 61 | MI->getOperand(1).getImm() == 0) { |
Chris Lattner | 8aa797a | 2007-12-30 23:10:15 +0000 | [diff] [blame] | 62 | FrameIndex = MI->getOperand(0).getIndex(); |
Chris Lattner | 5ccc722 | 2006-02-03 06:44:54 +0000 | [diff] [blame] | 63 | return MI->getOperand(2).getReg(); |
| 64 | } |
| 65 | } |
| 66 | return 0; |
| 67 | } |
Chris Lattner | e87146a | 2006-10-24 16:39:19 +0000 | [diff] [blame] | 68 | |
Venkatraman Govindaraju | c1a6283 | 2011-01-16 03:15:11 +0000 | [diff] [blame] | 69 | static bool IsIntegerCC(unsigned CC) |
| 70 | { |
| 71 | return (CC <= SPCC::ICC_VC); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | static SPCC::CondCodes GetOppositeBranchCondition(SPCC::CondCodes CC) |
| 76 | { |
| 77 | switch(CC) { |
| 78 | default: llvm_unreachable("Unknown condition code"); |
| 79 | case SPCC::ICC_NE: return SPCC::ICC_E; |
| 80 | case SPCC::ICC_E: return SPCC::ICC_NE; |
| 81 | case SPCC::ICC_G: return SPCC::ICC_LE; |
| 82 | case SPCC::ICC_LE: return SPCC::ICC_G; |
| 83 | case SPCC::ICC_GE: return SPCC::ICC_L; |
| 84 | case SPCC::ICC_L: return SPCC::ICC_GE; |
| 85 | case SPCC::ICC_GU: return SPCC::ICC_LEU; |
| 86 | case SPCC::ICC_LEU: return SPCC::ICC_GU; |
| 87 | case SPCC::ICC_CC: return SPCC::ICC_CS; |
| 88 | case SPCC::ICC_CS: return SPCC::ICC_CC; |
| 89 | case SPCC::ICC_POS: return SPCC::ICC_NEG; |
| 90 | case SPCC::ICC_NEG: return SPCC::ICC_POS; |
| 91 | case SPCC::ICC_VC: return SPCC::ICC_VS; |
| 92 | case SPCC::ICC_VS: return SPCC::ICC_VC; |
| 93 | |
| 94 | case SPCC::FCC_U: return SPCC::FCC_O; |
| 95 | case SPCC::FCC_O: return SPCC::FCC_U; |
| 96 | case SPCC::FCC_G: return SPCC::FCC_LE; |
| 97 | case SPCC::FCC_LE: return SPCC::FCC_G; |
| 98 | case SPCC::FCC_UG: return SPCC::FCC_ULE; |
| 99 | case SPCC::FCC_ULE: return SPCC::FCC_UG; |
| 100 | case SPCC::FCC_L: return SPCC::FCC_GE; |
| 101 | case SPCC::FCC_GE: return SPCC::FCC_L; |
| 102 | case SPCC::FCC_UL: return SPCC::FCC_UGE; |
| 103 | case SPCC::FCC_UGE: return SPCC::FCC_UL; |
| 104 | case SPCC::FCC_LG: return SPCC::FCC_UE; |
| 105 | case SPCC::FCC_UE: return SPCC::FCC_LG; |
| 106 | case SPCC::FCC_NE: return SPCC::FCC_E; |
| 107 | case SPCC::FCC_E: return SPCC::FCC_NE; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | |
| 112 | bool SparcInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB, |
| 113 | MachineBasicBlock *&TBB, |
| 114 | MachineBasicBlock *&FBB, |
| 115 | SmallVectorImpl<MachineOperand> &Cond, |
| 116 | bool AllowModify) const |
| 117 | { |
| 118 | |
| 119 | MachineBasicBlock::iterator I = MBB.end(); |
| 120 | MachineBasicBlock::iterator UnCondBrIter = MBB.end(); |
| 121 | while (I != MBB.begin()) { |
| 122 | --I; |
| 123 | |
| 124 | if (I->isDebugValue()) |
| 125 | continue; |
| 126 | |
| 127 | //When we see a non-terminator, we are done |
| 128 | if (!isUnpredicatedTerminator(I)) |
| 129 | break; |
| 130 | |
| 131 | //Terminator is not a branch |
| 132 | if (!I->getDesc().isBranch()) |
| 133 | return true; |
| 134 | |
| 135 | //Handle Unconditional branches |
| 136 | if (I->getOpcode() == SP::BA) { |
| 137 | UnCondBrIter = I; |
| 138 | |
| 139 | if (!AllowModify) { |
| 140 | TBB = I->getOperand(0).getMBB(); |
| 141 | continue; |
| 142 | } |
| 143 | |
| 144 | while (llvm::next(I) != MBB.end()) |
| 145 | llvm::next(I)->eraseFromParent(); |
| 146 | |
| 147 | Cond.clear(); |
| 148 | FBB = 0; |
| 149 | |
| 150 | if (MBB.isLayoutSuccessor(I->getOperand(0).getMBB())) { |
| 151 | TBB = 0; |
| 152 | I->eraseFromParent(); |
| 153 | I = MBB.end(); |
| 154 | UnCondBrIter = MBB.end(); |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | TBB = I->getOperand(0).getMBB(); |
| 159 | continue; |
| 160 | } |
| 161 | |
| 162 | unsigned Opcode = I->getOpcode(); |
| 163 | if (Opcode != SP::BCOND && Opcode != SP::FBCOND) |
| 164 | return true; //Unknown Opcode |
| 165 | |
| 166 | SPCC::CondCodes BranchCode = (SPCC::CondCodes)I->getOperand(1).getImm(); |
| 167 | |
| 168 | if (Cond.empty()) { |
| 169 | MachineBasicBlock *TargetBB = I->getOperand(0).getMBB(); |
| 170 | if (AllowModify && UnCondBrIter != MBB.end() && |
| 171 | MBB.isLayoutSuccessor(TargetBB)) { |
| 172 | |
| 173 | //Transform the code |
| 174 | // |
| 175 | // brCC L1 |
| 176 | // ba L2 |
| 177 | // L1: |
| 178 | // .. |
| 179 | // L2: |
| 180 | // |
| 181 | // into |
| 182 | // |
| 183 | // brnCC L2 |
| 184 | // L1: |
| 185 | // ... |
| 186 | // L2: |
| 187 | // |
| 188 | BranchCode = GetOppositeBranchCondition(BranchCode); |
| 189 | MachineBasicBlock::iterator OldInst = I; |
| 190 | BuildMI(MBB, UnCondBrIter, MBB.findDebugLoc(I), get(Opcode)) |
| 191 | .addMBB(UnCondBrIter->getOperand(0).getMBB()).addImm(BranchCode); |
| 192 | BuildMI(MBB, UnCondBrIter, MBB.findDebugLoc(I), get(SP::BA)) |
| 193 | .addMBB(TargetBB); |
| 194 | MBB.addSuccessor(TargetBB); |
| 195 | OldInst->eraseFromParent(); |
| 196 | UnCondBrIter->eraseFromParent(); |
| 197 | |
| 198 | UnCondBrIter = MBB.end(); |
| 199 | I = MBB.end(); |
| 200 | continue; |
| 201 | } |
| 202 | FBB = TBB; |
| 203 | TBB = I->getOperand(0).getMBB(); |
| 204 | Cond.push_back(MachineOperand::CreateImm(BranchCode)); |
| 205 | continue; |
| 206 | } |
| 207 | //FIXME: Handle subsequent conditional branches |
| 208 | //For now, we can't handle multiple conditional branches |
| 209 | return true; |
| 210 | } |
| 211 | return false; |
| 212 | } |
| 213 | |
Evan Cheng | 6ae3626 | 2007-05-18 00:18:17 +0000 | [diff] [blame] | 214 | unsigned |
| 215 | SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB, |
| 216 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 217 | const SmallVectorImpl<MachineOperand> &Cond, |
Venkatraman Govindaraju | c1a6283 | 2011-01-16 03:15:11 +0000 | [diff] [blame] | 218 | DebugLoc DL) const { |
| 219 | assert(TBB && "InsertBranch must not be told to insert a fallthrough"); |
| 220 | assert((Cond.size() == 1 || Cond.size() == 0) && |
| 221 | "Sparc branch conditions should have one component!"); |
| 222 | |
| 223 | if (Cond.empty()) { |
| 224 | assert(!FBB && "Unconditional branch with multiple successors!"); |
| 225 | BuildMI(&MBB, DL, get(SP::BA)).addMBB(TBB); |
| 226 | return 1; |
| 227 | } |
| 228 | |
| 229 | //Conditional branch |
| 230 | unsigned CC = Cond[0].getImm(); |
| 231 | |
| 232 | if (IsIntegerCC(CC)) |
| 233 | BuildMI(&MBB, DL, get(SP::BCOND)).addMBB(TBB).addImm(CC); |
| 234 | else |
| 235 | BuildMI(&MBB, DL, get(SP::FBCOND)).addMBB(TBB).addImm(CC); |
| 236 | if (!FBB) |
| 237 | return 1; |
| 238 | |
| 239 | BuildMI(&MBB, DL, get(SP::BA)).addMBB(FBB); |
| 240 | return 2; |
| 241 | } |
| 242 | |
| 243 | unsigned SparcInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const |
| 244 | { |
| 245 | MachineBasicBlock::iterator I = MBB.end(); |
| 246 | unsigned Count = 0; |
| 247 | while (I != MBB.begin()) { |
| 248 | --I; |
| 249 | |
| 250 | if (I->isDebugValue()) |
| 251 | continue; |
| 252 | |
| 253 | if (I->getOpcode() != SP::BA |
| 254 | && I->getOpcode() != SP::BCOND |
| 255 | && I->getOpcode() != SP::FBCOND) |
| 256 | break; // Not a branch |
| 257 | |
| 258 | I->eraseFromParent(); |
| 259 | I = MBB.end(); |
| 260 | ++Count; |
| 261 | } |
| 262 | return Count; |
Rafael Espindola | 3d7d39a | 2006-10-24 17:07:11 +0000 | [diff] [blame] | 263 | } |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 264 | |
Jakob Stoklund Olesen | 8e18a1a | 2010-07-11 07:56:09 +0000 | [diff] [blame] | 265 | void SparcInstrInfo::copyPhysReg(MachineBasicBlock &MBB, |
| 266 | MachineBasicBlock::iterator I, DebugLoc DL, |
| 267 | unsigned DestReg, unsigned SrcReg, |
| 268 | bool KillSrc) const { |
| 269 | if (SP::IntRegsRegClass.contains(DestReg, SrcReg)) |
| 270 | BuildMI(MBB, I, DL, get(SP::ORrr), DestReg).addReg(SP::G0) |
| 271 | .addReg(SrcReg, getKillRegState(KillSrc)); |
| 272 | else if (SP::FPRegsRegClass.contains(DestReg, SrcReg)) |
| 273 | BuildMI(MBB, I, DL, get(SP::FMOVS), DestReg) |
| 274 | .addReg(SrcReg, getKillRegState(KillSrc)); |
| 275 | else if (SP::DFPRegsRegClass.contains(DestReg, SrcReg)) |
| 276 | BuildMI(MBB, I, DL, get(Subtarget.isV9() ? SP::FMOVD : SP::FpMOVD), DestReg) |
| 277 | .addReg(SrcReg, getKillRegState(KillSrc)); |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 278 | else |
Jakob Stoklund Olesen | 8e18a1a | 2010-07-11 07:56:09 +0000 | [diff] [blame] | 279 | llvm_unreachable("Impossible reg-to-reg copy"); |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 280 | } |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 281 | |
| 282 | void SparcInstrInfo:: |
| 283 | storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 284 | unsigned SrcReg, bool isKill, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 285 | const TargetRegisterClass *RC, |
| 286 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 287 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 288 | if (I != MBB.end()) DL = I->getDebugLoc(); |
| 289 | |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 290 | // On the order of operands here: think "[FrameIdx + 0] = SrcReg". |
| 291 | if (RC == SP::IntRegsRegisterClass) |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 292 | BuildMI(MBB, I, DL, get(SP::STri)).addFrameIndex(FI).addImm(0) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 293 | .addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 294 | else if (RC == SP::FPRegsRegisterClass) |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 295 | BuildMI(MBB, I, DL, get(SP::STFri)).addFrameIndex(FI).addImm(0) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 296 | .addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 297 | else if (RC == SP::DFPRegsRegisterClass) |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 298 | BuildMI(MBB, I, DL, get(SP::STDFri)).addFrameIndex(FI).addImm(0) |
Bill Wendling | 587daed | 2009-05-13 21:33:08 +0000 | [diff] [blame] | 299 | .addReg(SrcReg, getKillRegState(isKill)); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 300 | else |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 301 | llvm_unreachable("Can't store this register to stack slot"); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 304 | void SparcInstrInfo:: |
| 305 | loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 306 | unsigned DestReg, int FI, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 307 | const TargetRegisterClass *RC, |
| 308 | const TargetRegisterInfo *TRI) const { |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 309 | DebugLoc DL; |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 310 | if (I != MBB.end()) DL = I->getDebugLoc(); |
| 311 | |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 312 | if (RC == SP::IntRegsRegisterClass) |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 313 | BuildMI(MBB, I, DL, get(SP::LDri), DestReg).addFrameIndex(FI).addImm(0); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 314 | else if (RC == SP::FPRegsRegisterClass) |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 315 | BuildMI(MBB, I, DL, get(SP::LDFri), DestReg).addFrameIndex(FI).addImm(0); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 316 | else if (RC == SP::DFPRegsRegisterClass) |
Bill Wendling | d1c321a | 2009-02-12 00:02:55 +0000 | [diff] [blame] | 317 | BuildMI(MBB, I, DL, get(SP::LDDFri), DestReg).addFrameIndex(FI).addImm(0); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 318 | else |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 319 | llvm_unreachable("Can't load this register from stack slot"); |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Chris Lattner | db486a6 | 2009-09-15 17:46:24 +0000 | [diff] [blame] | 322 | unsigned SparcInstrInfo::getGlobalBaseReg(MachineFunction *MF) const |
| 323 | { |
| 324 | SparcMachineFunctionInfo *SparcFI = MF->getInfo<SparcMachineFunctionInfo>(); |
| 325 | unsigned GlobalBaseReg = SparcFI->getGlobalBaseReg(); |
| 326 | if (GlobalBaseReg != 0) |
| 327 | return GlobalBaseReg; |
| 328 | |
| 329 | // Insert the set of GlobalBaseReg into the first MBB of the function |
| 330 | MachineBasicBlock &FirstMBB = MF->front(); |
| 331 | MachineBasicBlock::iterator MBBI = FirstMBB.begin(); |
| 332 | MachineRegisterInfo &RegInfo = MF->getRegInfo(); |
| 333 | |
| 334 | GlobalBaseReg = RegInfo.createVirtualRegister(&SP::IntRegsRegClass); |
| 335 | |
| 336 | |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 337 | DebugLoc dl; |
Chris Lattner | db486a6 | 2009-09-15 17:46:24 +0000 | [diff] [blame] | 338 | |
| 339 | BuildMI(FirstMBB, MBBI, dl, get(SP::GETPCX), GlobalBaseReg); |
| 340 | SparcFI->setGlobalBaseReg(GlobalBaseReg); |
| 341 | return GlobalBaseReg; |
| 342 | } |