blob: 7d7ee64305e6de57e76ae1d76ae65e14bbfb50c3 [file] [log] [blame]
Chris Lattnerb74e83c2002-12-16 16:15:28 +00001//===-- RegAllocLocal.cpp - A BasicBlock generic register allocator -------===//
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerb74e83c2002-12-16 16:15:28 +00009//
10// This register allocator allocates registers to a basic block at a time,
11// attempting to keep values in registers and reusing registers as appropriate.
12//
13//===----------------------------------------------------------------------===//
14
Chris Lattner4cc662b2003-08-03 21:47:31 +000015#define DEBUG_TYPE "regalloc"
Chris Lattner91a452b2003-01-13 00:25:40 +000016#include "llvm/CodeGen/Passes.h"
Chris Lattner580f9be2002-12-28 20:40:43 +000017#include "llvm/CodeGen/MachineFunctionPass.h"
Chris Lattnerb74e83c2002-12-16 16:15:28 +000018#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnerff863ba2002-12-25 05:05:46 +000019#include "llvm/CodeGen/SSARegMap.h"
Chris Lattnereb24db92002-12-28 21:08:26 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner91a452b2003-01-13 00:25:40 +000021#include "llvm/CodeGen/LiveVariables.h"
Chris Lattner3501fea2003-01-14 22:00:31 +000022#include "llvm/Target/TargetInstrInfo.h"
Chris Lattnerb74e83c2002-12-16 16:15:28 +000023#include "llvm/Target/TargetMachine.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000024#include "llvm/Support/CommandLine.h"
25#include "llvm/Support/Debug.h"
26#include "llvm/ADT/DenseMap.h"
27#include "llvm/ADT/Statistic.h"
Chris Lattner27f29162004-10-26 15:35:58 +000028#include <algorithm>
Chris Lattneref09c632004-01-31 21:27:19 +000029using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000030
Chris Lattnerb74e83c2002-12-16 16:15:28 +000031namespace {
Alkis Evlogimenos2acef2d2004-02-19 06:19:09 +000032 Statistic<> NumStores("ra-local", "Number of stores added");
33 Statistic<> NumLoads ("ra-local", "Number of loads added");
Alkis Evlogimenosd6f6d1a2004-02-21 18:07:33 +000034 Statistic<> NumFolded("ra-local", "Number of loads/stores folded into "
35 "instructions");
Chris Lattner580f9be2002-12-28 20:40:43 +000036 class RA : public MachineFunctionPass {
37 const TargetMachine *TM;
Chris Lattnerb74e83c2002-12-16 16:15:28 +000038 MachineFunction *MF;
Chris Lattner580f9be2002-12-28 20:40:43 +000039 const MRegisterInfo *RegInfo;
Chris Lattner91a452b2003-01-13 00:25:40 +000040 LiveVariables *LV;
Chris Lattnerff863ba2002-12-25 05:05:46 +000041
Chris Lattnerb8822ad2003-08-04 23:36:39 +000042 // StackSlotForVirtReg - Maps virtual regs to the frame index where these
43 // values are spilled.
Chris Lattner580f9be2002-12-28 20:40:43 +000044 std::map<unsigned, int> StackSlotForVirtReg;
Chris Lattnerb74e83c2002-12-16 16:15:28 +000045
46 // Virt2PhysRegMap - This map contains entries for each virtual register
Alkis Evlogimenos4d0d8642004-02-25 21:55:45 +000047 // that is currently available in a physical register.
48 DenseMap<unsigned, VirtReg2IndexFunctor> Virt2PhysRegMap;
Chris Lattnerecea5632004-02-09 02:12:04 +000049
50 unsigned &getVirt2PhysRegMapSlot(unsigned VirtReg) {
Alkis Evlogimenos4d0d8642004-02-25 21:55:45 +000051 return Virt2PhysRegMap[VirtReg];
Chris Lattnerecea5632004-02-09 02:12:04 +000052 }
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +000053
Chris Lattner64667b62004-02-09 01:26:13 +000054 // PhysRegsUsed - This array is effectively a map, containing entries for
55 // each physical register that currently has a value (ie, it is in
56 // Virt2PhysRegMap). The value mapped to is the virtual register
57 // corresponding to the physical register (the inverse of the
58 // Virt2PhysRegMap), or 0. The value is set to 0 if this register is pinned
59 // because it is used by a future instruction. If the entry for a physical
60 // register is -1, then the physical register is "not in the map".
Chris Lattnerb74e83c2002-12-16 16:15:28 +000061 //
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +000062 std::vector<int> PhysRegsUsed;
Chris Lattnerb74e83c2002-12-16 16:15:28 +000063
64 // PhysRegsUseOrder - This contains a list of the physical registers that
65 // currently have a virtual register value in them. This list provides an
66 // ordering of registers, imposing a reallocation order. This list is only
67 // used if all registers are allocated and we have to spill one, in which
68 // case we spill the least recently used register. Entries at the front of
69 // the list are the least recently used registers, entries at the back are
70 // the most recently used.
71 //
72 std::vector<unsigned> PhysRegsUseOrder;
73
Chris Lattner91a452b2003-01-13 00:25:40 +000074 // VirtRegModified - This bitset contains information about which virtual
75 // registers need to be spilled back to memory when their registers are
76 // scavenged. If a virtual register has simply been rematerialized, there
77 // is no reason to spill it to memory when we need the register back.
Chris Lattner82bee0f2002-12-18 08:14:26 +000078 //
Chris Lattner91a452b2003-01-13 00:25:40 +000079 std::vector<bool> VirtRegModified;
80
81 void markVirtRegModified(unsigned Reg, bool Val = true) {
Chris Lattneref09c632004-01-31 21:27:19 +000082 assert(MRegisterInfo::isVirtualRegister(Reg) && "Illegal VirtReg!");
Chris Lattner91a452b2003-01-13 00:25:40 +000083 Reg -= MRegisterInfo::FirstVirtualRegister;
84 if (VirtRegModified.size() <= Reg) VirtRegModified.resize(Reg+1);
85 VirtRegModified[Reg] = Val;
86 }
87
88 bool isVirtRegModified(unsigned Reg) const {
Chris Lattneref09c632004-01-31 21:27:19 +000089 assert(MRegisterInfo::isVirtualRegister(Reg) && "Illegal VirtReg!");
Chris Lattner91a452b2003-01-13 00:25:40 +000090 assert(Reg - MRegisterInfo::FirstVirtualRegister < VirtRegModified.size()
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +000091 && "Illegal virtual register!");
Chris Lattner91a452b2003-01-13 00:25:40 +000092 return VirtRegModified[Reg - MRegisterInfo::FirstVirtualRegister];
93 }
Chris Lattner82bee0f2002-12-18 08:14:26 +000094
Chris Lattnerb74e83c2002-12-16 16:15:28 +000095 void MarkPhysRegRecentlyUsed(unsigned Reg) {
Chris Lattneraebcce82004-06-16 06:57:29 +000096 if(PhysRegsUseOrder.empty() ||
97 PhysRegsUseOrder.back() == Reg) return; // Already most recently used
Chris Lattner0eb172c2002-12-24 00:04:55 +000098
99 for (unsigned i = PhysRegsUseOrder.size(); i != 0; --i)
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000100 if (areRegsEqual(Reg, PhysRegsUseOrder[i-1])) {
101 unsigned RegMatch = PhysRegsUseOrder[i-1]; // remove from middle
102 PhysRegsUseOrder.erase(PhysRegsUseOrder.begin()+i-1);
103 // Add it to the end of the list
104 PhysRegsUseOrder.push_back(RegMatch);
105 if (RegMatch == Reg)
106 return; // Found an exact match, exit early
107 }
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000108 }
109
110 public:
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000111 virtual const char *getPassName() const {
112 return "Local Register Allocator";
113 }
114
Chris Lattner91a452b2003-01-13 00:25:40 +0000115 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattner56ddada2004-02-17 17:49:10 +0000116 AU.addRequired<LiveVariables>();
Chris Lattner91a452b2003-01-13 00:25:40 +0000117 AU.addRequiredID(PHIEliminationID);
Alkis Evlogimenos4c080862003-12-18 22:40:24 +0000118 AU.addRequiredID(TwoAddressInstructionPassID);
Chris Lattner91a452b2003-01-13 00:25:40 +0000119 MachineFunctionPass::getAnalysisUsage(AU);
120 }
121
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000122 private:
123 /// runOnMachineFunction - Register allocate the whole function
124 bool runOnMachineFunction(MachineFunction &Fn);
125
126 /// AllocateBasicBlock - Register allocate the specified basic block.
127 void AllocateBasicBlock(MachineBasicBlock &MBB);
128
Chris Lattner82bee0f2002-12-18 08:14:26 +0000129
Chris Lattner82bee0f2002-12-18 08:14:26 +0000130 /// areRegsEqual - This method returns true if the specified registers are
131 /// related to each other. To do this, it checks to see if they are equal
132 /// or if the first register is in the alias set of the second register.
133 ///
134 bool areRegsEqual(unsigned R1, unsigned R2) const {
135 if (R1 == R2) return true;
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000136 for (const unsigned *AliasSet = RegInfo->getAliasSet(R2);
137 *AliasSet; ++AliasSet) {
138 if (*AliasSet == R1) return true;
139 }
Chris Lattner82bee0f2002-12-18 08:14:26 +0000140 return false;
141 }
142
Chris Lattner580f9be2002-12-28 20:40:43 +0000143 /// getStackSpaceFor - This returns the frame index of the specified virtual
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000144 /// register on the stack, allocating space if necessary.
Chris Lattner580f9be2002-12-28 20:40:43 +0000145 int getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000146
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000147 /// removePhysReg - This method marks the specified physical register as no
148 /// longer being in use.
149 ///
Chris Lattner82bee0f2002-12-18 08:14:26 +0000150 void removePhysReg(unsigned PhysReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000151
152 /// spillVirtReg - This method spills the value specified by PhysReg into
153 /// the virtual register slot specified by VirtReg. It then updates the RA
154 /// data structures to indicate the fact that PhysReg is now available.
155 ///
Chris Lattner688c8252004-02-22 19:08:15 +0000156 void spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000157 unsigned VirtReg, unsigned PhysReg);
158
Chris Lattnerc21be922002-12-16 17:44:42 +0000159 /// spillPhysReg - This method spills the specified physical register into
Chris Lattner128c2aa2003-08-17 18:01:15 +0000160 /// the virtual register slot associated with it. If OnlyVirtRegs is set to
161 /// true, then the request is ignored if the physical register does not
162 /// contain a virtual register.
Chris Lattner91a452b2003-01-13 00:25:40 +0000163 ///
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000164 void spillPhysReg(MachineBasicBlock &MBB, MachineInstr *I,
Chris Lattner128c2aa2003-08-17 18:01:15 +0000165 unsigned PhysReg, bool OnlyVirtRegs = false);
Chris Lattnerc21be922002-12-16 17:44:42 +0000166
Chris Lattner91a452b2003-01-13 00:25:40 +0000167 /// assignVirtToPhysReg - This method updates local state so that we know
168 /// that PhysReg is the proper container for VirtReg now. The physical
169 /// register must not be used for anything else when this is called.
170 ///
171 void assignVirtToPhysReg(unsigned VirtReg, unsigned PhysReg);
172
173 /// liberatePhysReg - Make sure the specified physical register is available
174 /// for use. If there is currently a value in it, it is either moved out of
175 /// the way or spilled to memory.
176 ///
177 void liberatePhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000178 unsigned PhysReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000179
Chris Lattnerae640432002-12-17 02:50:10 +0000180 /// isPhysRegAvailable - Return true if the specified physical register is
181 /// free and available for use. This also includes checking to see if
182 /// aliased registers are all free...
183 ///
Chris Lattner82bee0f2002-12-18 08:14:26 +0000184 bool isPhysRegAvailable(unsigned PhysReg) const;
Chris Lattner91a452b2003-01-13 00:25:40 +0000185
186 /// getFreeReg - Look to see if there is a free register available in the
187 /// specified register class. If not, return 0.
188 ///
189 unsigned getFreeReg(const TargetRegisterClass *RC);
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000190
Chris Lattner91a452b2003-01-13 00:25:40 +0000191 /// getReg - Find a physical register to hold the specified virtual
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000192 /// register. If all compatible physical registers are used, this method
193 /// spills the last used virtual register to the stack, and uses that
194 /// register.
195 ///
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000196 unsigned getReg(MachineBasicBlock &MBB, MachineInstr *MI,
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000197 unsigned VirtReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000198
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000199 /// reloadVirtReg - This method transforms the specified specified virtual
200 /// register use to refer to a physical register. This method may do this
201 /// in one of several ways: if the register is available in a physical
202 /// register already, it uses that physical register. If the value is not
203 /// in a physical register, and if there are physical registers available,
204 /// it loads it into a register. If register pressure is high, and it is
205 /// possible, it tries to fold the load of the virtual register into the
206 /// instruction itself. It avoids doing this if register pressure is low to
207 /// improve the chance that subsequent instructions can use the reloaded
208 /// value. This method returns the modified instruction.
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000209 ///
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000210 MachineInstr *reloadVirtReg(MachineBasicBlock &MBB, MachineInstr *MI,
211 unsigned OpNum);
212
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000213
214 void reloadPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
215 unsigned PhysReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000216 };
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000217}
218
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000219/// getStackSpaceFor - This allocates space for the specified virtual register
220/// to be held on the stack.
221int RA::getStackSpaceFor(unsigned VirtReg, const TargetRegisterClass *RC) {
222 // Find the location Reg would belong...
223 std::map<unsigned, int>::iterator I =StackSlotForVirtReg.lower_bound(VirtReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000224
Chris Lattner580f9be2002-12-28 20:40:43 +0000225 if (I != StackSlotForVirtReg.end() && I->first == VirtReg)
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000226 return I->second; // Already has space allocated?
227
Chris Lattner580f9be2002-12-28 20:40:43 +0000228 // Allocate a new stack object for this spill location...
Chris Lattner26eb14b2004-08-15 22:02:22 +0000229 int FrameIdx = MF->getFrameInfo()->CreateStackObject(RC->getSize(),
230 RC->getAlignment());
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000231
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000232 // Assign the slot...
Chris Lattner580f9be2002-12-28 20:40:43 +0000233 StackSlotForVirtReg.insert(I, std::make_pair(VirtReg, FrameIdx));
234 return FrameIdx;
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000235}
236
Chris Lattnerae640432002-12-17 02:50:10 +0000237
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000238/// removePhysReg - This method marks the specified physical register as no
Chris Lattner82bee0f2002-12-18 08:14:26 +0000239/// longer being in use.
240///
241void RA::removePhysReg(unsigned PhysReg) {
Chris Lattner64667b62004-02-09 01:26:13 +0000242 PhysRegsUsed[PhysReg] = -1; // PhyReg no longer used
Chris Lattner82bee0f2002-12-18 08:14:26 +0000243
244 std::vector<unsigned>::iterator It =
245 std::find(PhysRegsUseOrder.begin(), PhysRegsUseOrder.end(), PhysReg);
Alkis Evlogimenos19b64862004-01-13 06:24:30 +0000246 if (It != PhysRegsUseOrder.end())
247 PhysRegsUseOrder.erase(It);
Chris Lattner82bee0f2002-12-18 08:14:26 +0000248}
249
Chris Lattner91a452b2003-01-13 00:25:40 +0000250
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000251/// spillVirtReg - This method spills the value specified by PhysReg into the
252/// virtual register slot specified by VirtReg. It then updates the RA data
253/// structures to indicate the fact that PhysReg is now available.
254///
Chris Lattner688c8252004-02-22 19:08:15 +0000255void RA::spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000256 unsigned VirtReg, unsigned PhysReg) {
Chris Lattner8c819452003-08-05 04:13:58 +0000257 assert(VirtReg && "Spilling a physical register is illegal!"
Chris Lattnerd9ac6a72003-08-05 00:49:09 +0000258 " Must not have appropriate kill for the register or use exists beyond"
259 " the intended one.");
260 DEBUG(std::cerr << " Spilling register " << RegInfo->getName(PhysReg);
261 std::cerr << " containing %reg" << VirtReg;
262 if (!isVirtRegModified(VirtReg))
263 std::cerr << " which has not been modified, so no store necessary!");
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000264
Chris Lattnerd9ac6a72003-08-05 00:49:09 +0000265 // Otherwise, there is a virtual register corresponding to this physical
266 // register. We only need to spill it into its stack slot if it has been
267 // modified.
268 if (isVirtRegModified(VirtReg)) {
269 const TargetRegisterClass *RC = MF->getSSARegMap()->getRegClass(VirtReg);
270 int FrameIndex = getStackSpaceFor(VirtReg, RC);
271 DEBUG(std::cerr << " to stack slot #" << FrameIndex);
Chris Lattner57f1b672004-08-15 21:56:44 +0000272 RegInfo->storeRegToStackSlot(MBB, I, PhysReg, FrameIndex);
Alkis Evlogimenos2acef2d2004-02-19 06:19:09 +0000273 ++NumStores; // Update statistics
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000274 }
Chris Lattnerecea5632004-02-09 02:12:04 +0000275
276 getVirt2PhysRegMapSlot(VirtReg) = 0; // VirtReg no longer available
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000277
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000278 DEBUG(std::cerr << "\n");
Chris Lattner82bee0f2002-12-18 08:14:26 +0000279 removePhysReg(PhysReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000280}
281
Chris Lattnerae640432002-12-17 02:50:10 +0000282
Chris Lattner91a452b2003-01-13 00:25:40 +0000283/// spillPhysReg - This method spills the specified physical register into the
Chris Lattner128c2aa2003-08-17 18:01:15 +0000284/// virtual register slot associated with it. If OnlyVirtRegs is set to true,
285/// then the request is ignored if the physical register does not contain a
286/// virtual register.
Chris Lattner91a452b2003-01-13 00:25:40 +0000287///
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000288void RA::spillPhysReg(MachineBasicBlock &MBB, MachineInstr *I,
Chris Lattner128c2aa2003-08-17 18:01:15 +0000289 unsigned PhysReg, bool OnlyVirtRegs) {
Chris Lattner64667b62004-02-09 01:26:13 +0000290 if (PhysRegsUsed[PhysReg] != -1) { // Only spill it if it's used!
291 if (PhysRegsUsed[PhysReg] || !OnlyVirtRegs)
292 spillVirtReg(MBB, I, PhysRegsUsed[PhysReg], PhysReg);
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000293 } else {
Chris Lattner91a452b2003-01-13 00:25:40 +0000294 // If the selected register aliases any other registers, we must make
295 // sure that one of the aliases isn't alive...
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000296 for (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg);
Chris Lattner64667b62004-02-09 01:26:13 +0000297 *AliasSet; ++AliasSet)
298 if (PhysRegsUsed[*AliasSet] != -1) // Spill aliased register...
299 if (PhysRegsUsed[*AliasSet] || !OnlyVirtRegs)
300 spillVirtReg(MBB, I, PhysRegsUsed[*AliasSet], *AliasSet);
Chris Lattner91a452b2003-01-13 00:25:40 +0000301 }
302}
303
304
305/// assignVirtToPhysReg - This method updates local state so that we know
306/// that PhysReg is the proper container for VirtReg now. The physical
307/// register must not be used for anything else when this is called.
308///
309void RA::assignVirtToPhysReg(unsigned VirtReg, unsigned PhysReg) {
Chris Lattner64667b62004-02-09 01:26:13 +0000310 assert(PhysRegsUsed[PhysReg] == -1 && "Phys reg already assigned!");
Chris Lattner91a452b2003-01-13 00:25:40 +0000311 // Update information to note the fact that this register was just used, and
312 // it holds VirtReg.
313 PhysRegsUsed[PhysReg] = VirtReg;
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000314 getVirt2PhysRegMapSlot(VirtReg) = PhysReg;
Chris Lattner91a452b2003-01-13 00:25:40 +0000315 PhysRegsUseOrder.push_back(PhysReg); // New use of PhysReg
316}
317
318
Chris Lattnerae640432002-12-17 02:50:10 +0000319/// isPhysRegAvailable - Return true if the specified physical register is free
320/// and available for use. This also includes checking to see if aliased
321/// registers are all free...
322///
323bool RA::isPhysRegAvailable(unsigned PhysReg) const {
Chris Lattner64667b62004-02-09 01:26:13 +0000324 if (PhysRegsUsed[PhysReg] != -1) return false;
Chris Lattnerae640432002-12-17 02:50:10 +0000325
326 // If the selected register aliases any other allocated registers, it is
327 // not free!
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000328 for (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg);
329 *AliasSet; ++AliasSet)
Chris Lattner64667b62004-02-09 01:26:13 +0000330 if (PhysRegsUsed[*AliasSet] != -1) // Aliased register in use?
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000331 return false; // Can't use this reg then.
Chris Lattnerae640432002-12-17 02:50:10 +0000332 return true;
333}
334
335
Chris Lattner91a452b2003-01-13 00:25:40 +0000336/// getFreeReg - Look to see if there is a free register available in the
337/// specified register class. If not, return 0.
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000338///
Chris Lattner91a452b2003-01-13 00:25:40 +0000339unsigned RA::getFreeReg(const TargetRegisterClass *RC) {
Chris Lattner580f9be2002-12-28 20:40:43 +0000340 // Get iterators defining the range of registers that are valid to allocate in
341 // this class, which also specifies the preferred allocation order.
342 TargetRegisterClass::iterator RI = RC->allocation_order_begin(*MF);
343 TargetRegisterClass::iterator RE = RC->allocation_order_end(*MF);
Chris Lattnerae640432002-12-17 02:50:10 +0000344
Chris Lattner91a452b2003-01-13 00:25:40 +0000345 for (; RI != RE; ++RI)
346 if (isPhysRegAvailable(*RI)) { // Is reg unused?
347 assert(*RI != 0 && "Cannot use register!");
348 return *RI; // Found an unused register!
349 }
350 return 0;
351}
352
353
354/// liberatePhysReg - Make sure the specified physical register is available for
355/// use. If there is currently a value in it, it is either moved out of the way
356/// or spilled to memory.
357///
358void RA::liberatePhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000359 unsigned PhysReg) {
Chris Lattner91a452b2003-01-13 00:25:40 +0000360 spillPhysReg(MBB, I, PhysReg);
361}
362
363
364/// getReg - Find a physical register to hold the specified virtual
365/// register. If all compatible physical registers are used, this method spills
366/// the last used virtual register to the stack, and uses that register.
367///
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000368unsigned RA::getReg(MachineBasicBlock &MBB, MachineInstr *I,
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000369 unsigned VirtReg) {
Chris Lattner91a452b2003-01-13 00:25:40 +0000370 const TargetRegisterClass *RC = MF->getSSARegMap()->getRegClass(VirtReg);
371
372 // First check to see if we have a free register of the requested type...
373 unsigned PhysReg = getFreeReg(RC);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000374
Chris Lattnerae640432002-12-17 02:50:10 +0000375 // If we didn't find an unused register, scavenge one now!
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000376 if (PhysReg == 0) {
Chris Lattnerc21be922002-12-16 17:44:42 +0000377 assert(!PhysRegsUseOrder.empty() && "No allocated registers??");
Chris Lattnerae640432002-12-17 02:50:10 +0000378
379 // Loop over all of the preallocated registers from the least recently used
380 // to the most recently used. When we find one that is capable of holding
381 // our register, use it.
382 for (unsigned i = 0; PhysReg == 0; ++i) {
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000383 assert(i != PhysRegsUseOrder.size() &&
384 "Couldn't find a register of the appropriate class!");
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000385
Chris Lattnerae640432002-12-17 02:50:10 +0000386 unsigned R = PhysRegsUseOrder[i];
Chris Lattner41822c72003-08-23 23:49:42 +0000387
388 // We can only use this register if it holds a virtual register (ie, it
389 // can be spilled). Do not use it if it is an explicitly allocated
390 // physical register!
Chris Lattner64667b62004-02-09 01:26:13 +0000391 assert(PhysRegsUsed[R] != -1 &&
Chris Lattner41822c72003-08-23 23:49:42 +0000392 "PhysReg in PhysRegsUseOrder, but is not allocated?");
393 if (PhysRegsUsed[R]) {
394 // If the current register is compatible, use it.
Chris Lattner3bba0262004-08-15 22:23:09 +0000395 if (RC->contains(R)) {
Chris Lattner41822c72003-08-23 23:49:42 +0000396 PhysReg = R;
397 break;
398 } else {
399 // If one of the registers aliased to the current register is
400 // compatible, use it.
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000401 for (const unsigned *AliasSet = RegInfo->getAliasSet(R);
402 *AliasSet; ++AliasSet) {
Chris Lattner3bba0262004-08-15 22:23:09 +0000403 if (RC->contains(*AliasSet)) {
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000404 PhysReg = *AliasSet; // Take an aliased register
405 break;
406 }
407 }
Chris Lattner41822c72003-08-23 23:49:42 +0000408 }
Chris Lattnerae640432002-12-17 02:50:10 +0000409 }
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000410 }
411
Chris Lattnerae640432002-12-17 02:50:10 +0000412 assert(PhysReg && "Physical register not assigned!?!?");
413
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000414 // At this point PhysRegsUseOrder[i] is the least recently used register of
415 // compatible register class. Spill it to memory and reap its remains.
Chris Lattnerc21be922002-12-16 17:44:42 +0000416 spillPhysReg(MBB, I, PhysReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000417 }
418
419 // Now that we know which register we need to assign this to, do it now!
Chris Lattner91a452b2003-01-13 00:25:40 +0000420 assignVirtToPhysReg(VirtReg, PhysReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000421 return PhysReg;
422}
423
Chris Lattnerae640432002-12-17 02:50:10 +0000424
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000425/// reloadVirtReg - This method transforms the specified specified virtual
426/// register use to refer to a physical register. This method may do this in
427/// one of several ways: if the register is available in a physical register
428/// already, it uses that physical register. If the value is not in a physical
429/// register, and if there are physical registers available, it loads it into a
430/// register. If register pressure is high, and it is possible, it tries to
431/// fold the load of the virtual register into the instruction itself. It
432/// avoids doing this if register pressure is low to improve the chance that
433/// subsequent instructions can use the reloaded value. This method returns the
434/// modified instruction.
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000435///
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000436MachineInstr *RA::reloadVirtReg(MachineBasicBlock &MBB, MachineInstr *MI,
437 unsigned OpNum) {
438 unsigned VirtReg = MI->getOperand(OpNum).getReg();
439
440 // If the virtual register is already available, just update the instruction
441 // and return.
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000442 if (unsigned PR = getVirt2PhysRegMapSlot(VirtReg)) {
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000443 MarkPhysRegRecentlyUsed(PR); // Already have this value available!
444 MI->SetMachineOperandReg(OpNum, PR); // Assign the input register
445 return MI;
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000446 }
447
Chris Lattner1e3812c2004-02-17 04:08:37 +0000448 // Otherwise, we need to fold it into the current instruction, or reload it.
449 // If we have registers available to hold the value, use them.
Chris Lattnerff863ba2002-12-25 05:05:46 +0000450 const TargetRegisterClass *RC = MF->getSSARegMap()->getRegClass(VirtReg);
Chris Lattner1e3812c2004-02-17 04:08:37 +0000451 unsigned PhysReg = getFreeReg(RC);
Chris Lattner11390e72004-02-17 08:09:40 +0000452 int FrameIndex = getStackSpaceFor(VirtReg, RC);
Chris Lattner1e3812c2004-02-17 04:08:37 +0000453
Chris Lattner11390e72004-02-17 08:09:40 +0000454 if (PhysReg) { // Register is available, allocate it!
455 assignVirtToPhysReg(VirtReg, PhysReg);
456 } else { // No registers available.
457 // If we can fold this spill into this instruction, do so now.
Alkis Evlogimenos39354c92004-03-14 07:19:51 +0000458 if (MachineInstr* FMI = RegInfo->foldMemoryOperand(MI, OpNum, FrameIndex)){
Alkis Evlogimenosd6f6d1a2004-02-21 18:07:33 +0000459 ++NumFolded;
Chris Lattnerd368c612004-02-19 18:34:02 +0000460 // Since we changed the address of MI, make sure to update live variables
461 // to know that the new instruction has the properties of the old one.
Alkis Evlogimenos39354c92004-03-14 07:19:51 +0000462 LV->instructionChanged(MI, FMI);
463 return MBB.insert(MBB.erase(MI), FMI);
Chris Lattner1e3812c2004-02-17 04:08:37 +0000464 }
465
466 // It looks like we can't fold this virtual register load into this
467 // instruction. Force some poor hapless value out of the register file to
468 // make room for the new register, and reload it.
469 PhysReg = getReg(MBB, MI, VirtReg);
470 }
471
Chris Lattner91a452b2003-01-13 00:25:40 +0000472 markVirtRegModified(VirtReg, false); // Note that this reg was just reloaded
473
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000474 DEBUG(std::cerr << " Reloading %reg" << VirtReg << " into "
475 << RegInfo->getName(PhysReg) << "\n");
476
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000477 // Add move instruction(s)
Chris Lattner57f1b672004-08-15 21:56:44 +0000478 RegInfo->loadRegFromStackSlot(MBB, MI, PhysReg, FrameIndex);
Alkis Evlogimenos2acef2d2004-02-19 06:19:09 +0000479 ++NumLoads; // Update statistics
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000480
481 MI->SetMachineOperandReg(OpNum, PhysReg); // Assign the input register
482 return MI;
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000483}
484
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000485
486
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000487void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
488 // loop over each instruction
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000489 MachineBasicBlock::iterator MI = MBB.begin();
490 for (; MI != MBB.end(); ++MI) {
Chris Lattner9bcdcd12004-06-02 05:57:12 +0000491 const TargetInstrDescriptor &TID = TM->getInstrInfo()->get(MI->getOpcode());
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000492 DEBUG(std::cerr << "\nStarting RegAlloc of: " << *MI;
493 std::cerr << " Regs have values: ";
Chris Lattner64667b62004-02-09 01:26:13 +0000494 for (unsigned i = 0; i != RegInfo->getNumRegs(); ++i)
495 if (PhysRegsUsed[i] != -1)
496 std::cerr << "[" << RegInfo->getName(i)
497 << ",%reg" << PhysRegsUsed[i] << "] ";
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000498 std::cerr << "\n");
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000499
Chris Lattnerae640432002-12-17 02:50:10 +0000500 // Loop over the implicit uses, making sure that they are at the head of the
501 // use order list, so they don't get reallocated.
Alkis Evlogimenos73ff5122003-10-08 05:20:08 +0000502 for (const unsigned *ImplicitUses = TID.ImplicitUses;
503 *ImplicitUses; ++ImplicitUses)
Chris Lattnerecea5632004-02-09 02:12:04 +0000504 MarkPhysRegRecentlyUsed(*ImplicitUses);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000505
Brian Gaeke53b99a02003-08-15 21:19:25 +0000506 // Get the used operands into registers. This has the potential to spill
Chris Lattnerb8822ad2003-08-04 23:36:39 +0000507 // incoming values if we are out of registers. Note that we completely
508 // ignore physical register uses here. We assume that if an explicit
509 // physical register is referenced by the instruction, that it is guaranteed
510 // to be live-in, or the input is badly hosed.
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000511 //
Alkis Evlogimenos71e353e2004-02-26 22:00:20 +0000512 for (unsigned i = 0; i != MI->getNumOperands(); ++i) {
513 MachineOperand& MO = MI->getOperand(i);
514 // here we are looking for only used operands (never def&use)
515 if (!MO.isDef() && MO.isRegister() && MO.getReg() &&
516 MRegisterInfo::isVirtualRegister(MO.getReg()))
Chris Lattner42e0a8f2004-02-17 03:57:19 +0000517 MI = reloadVirtReg(MBB, MI, i);
Alkis Evlogimenos71e353e2004-02-26 22:00:20 +0000518 }
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000519
Chris Lattner56ddada2004-02-17 17:49:10 +0000520 // If this instruction is the last user of anything in registers, kill the
521 // value, freeing the register being used, so it doesn't need to be
522 // spilled to memory.
523 //
524 for (LiveVariables::killed_iterator KI = LV->killed_begin(MI),
525 KE = LV->killed_end(MI); KI != KE; ++KI) {
526 unsigned VirtReg = KI->second;
527 unsigned PhysReg = VirtReg;
528 if (MRegisterInfo::isVirtualRegister(VirtReg)) {
529 // If the virtual register was never materialized into a register, it
530 // might not be in the map, but it won't hurt to zero it out anyway.
531 unsigned &PhysRegSlot = getVirt2PhysRegMapSlot(VirtReg);
532 PhysReg = PhysRegSlot;
533 PhysRegSlot = 0;
534 }
Chris Lattner91a452b2003-01-13 00:25:40 +0000535
Chris Lattner56ddada2004-02-17 17:49:10 +0000536 if (PhysReg) {
537 DEBUG(std::cerr << " Last use of " << RegInfo->getName(PhysReg)
538 << "[%reg" << VirtReg <<"], removing it from live set\n");
539 removePhysReg(PhysReg);
Chris Lattner91a452b2003-01-13 00:25:40 +0000540 }
541 }
542
543 // Loop over all of the operands of the instruction, spilling registers that
544 // are defined, and marking explicit destinations in the PhysRegsUsed map.
Alkis Evlogimenos71e353e2004-02-26 22:00:20 +0000545 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
546 MachineOperand& MO = MI->getOperand(i);
547 if (MO.isDef() && MO.isRegister() && MO.getReg() &&
548 MRegisterInfo::isPhysicalRegister(MO.getReg())) {
549 unsigned Reg = MO.getReg();
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000550 spillPhysReg(MBB, MI, Reg, true); // Spill any existing value in the reg
Chris Lattner91a452b2003-01-13 00:25:40 +0000551 PhysRegsUsed[Reg] = 0; // It is free and reserved now
552 PhysRegsUseOrder.push_back(Reg);
Alkis Evlogimenos19b64862004-01-13 06:24:30 +0000553 for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
554 *AliasSet; ++AliasSet) {
Chris Lattnerecea5632004-02-09 02:12:04 +0000555 PhysRegsUseOrder.push_back(*AliasSet);
556 PhysRegsUsed[*AliasSet] = 0; // It is free and reserved now
Alkis Evlogimenos19b64862004-01-13 06:24:30 +0000557 }
Chris Lattner91a452b2003-01-13 00:25:40 +0000558 }
Alkis Evlogimenos71e353e2004-02-26 22:00:20 +0000559 }
Chris Lattner91a452b2003-01-13 00:25:40 +0000560
561 // Loop over the implicit defs, spilling them as well.
Alkis Evlogimenosefe995a2003-12-13 01:20:58 +0000562 for (const unsigned *ImplicitDefs = TID.ImplicitDefs;
563 *ImplicitDefs; ++ImplicitDefs) {
564 unsigned Reg = *ImplicitDefs;
Chris Lattner11390e72004-02-17 08:09:40 +0000565 spillPhysReg(MBB, MI, Reg, true);
Alkis Evlogimenosefe995a2003-12-13 01:20:58 +0000566 PhysRegsUseOrder.push_back(Reg);
567 PhysRegsUsed[Reg] = 0; // It is free and reserved now
Alkis Evlogimenos19b64862004-01-13 06:24:30 +0000568 for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
569 *AliasSet; ++AliasSet) {
Chris Lattnerecea5632004-02-09 02:12:04 +0000570 PhysRegsUseOrder.push_back(*AliasSet);
571 PhysRegsUsed[*AliasSet] = 0; // It is free and reserved now
Alkis Evlogimenos19b64862004-01-13 06:24:30 +0000572 }
Alkis Evlogimenosefe995a2003-12-13 01:20:58 +0000573 }
Chris Lattner91a452b2003-01-13 00:25:40 +0000574
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000575 // Okay, we have allocated all of the source operands and spilled any values
576 // that would be destroyed by defs of this instruction. Loop over the
Chris Lattner91a452b2003-01-13 00:25:40 +0000577 // implicit defs and assign them to a register, spilling incoming values if
578 // we need to scavenge a register.
Chris Lattner82bee0f2002-12-18 08:14:26 +0000579 //
Alkis Evlogimenos71e353e2004-02-26 22:00:20 +0000580 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
581 MachineOperand& MO = MI->getOperand(i);
582 if (MO.isDef() && MO.isRegister() && MO.getReg() &&
583 MRegisterInfo::isVirtualRegister(MO.getReg())) {
584 unsigned DestVirtReg = MO.getReg();
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000585 unsigned DestPhysReg;
586
Alkis Evlogimenos9af9dbd2003-12-18 13:08:52 +0000587 // If DestVirtReg already has a value, use it.
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000588 if (!(DestPhysReg = getVirt2PhysRegMapSlot(DestVirtReg)))
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000589 DestPhysReg = getReg(MBB, MI, DestVirtReg);
Chris Lattnerd5725632003-05-12 03:54:14 +0000590 markVirtRegModified(DestVirtReg);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000591 MI->SetMachineOperandReg(i, DestPhysReg); // Assign the output register
592 }
Alkis Evlogimenos71e353e2004-02-26 22:00:20 +0000593 }
Chris Lattner82bee0f2002-12-18 08:14:26 +0000594
Chris Lattner56ddada2004-02-17 17:49:10 +0000595 // If this instruction defines any registers that are immediately dead,
596 // kill them now.
597 //
598 for (LiveVariables::killed_iterator KI = LV->dead_begin(MI),
599 KE = LV->dead_end(MI); KI != KE; ++KI) {
600 unsigned VirtReg = KI->second;
601 unsigned PhysReg = VirtReg;
602 if (MRegisterInfo::isVirtualRegister(VirtReg)) {
603 unsigned &PhysRegSlot = getVirt2PhysRegMapSlot(VirtReg);
604 PhysReg = PhysRegSlot;
605 assert(PhysReg != 0);
606 PhysRegSlot = 0;
607 }
Chris Lattner91a452b2003-01-13 00:25:40 +0000608
Chris Lattner56ddada2004-02-17 17:49:10 +0000609 if (PhysReg) {
610 DEBUG(std::cerr << " Register " << RegInfo->getName(PhysReg)
611 << " [%reg" << VirtReg
612 << "] is never used, removing it frame live list\n");
613 removePhysReg(PhysReg);
Chris Lattner82bee0f2002-12-18 08:14:26 +0000614 }
615 }
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000616 }
617
Alkis Evlogimenos743d0a12004-02-23 18:14:48 +0000618 MI = MBB.getFirstTerminator();
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000619
620 // Spill all physical registers holding virtual registers now.
Chris Lattner64667b62004-02-09 01:26:13 +0000621 for (unsigned i = 0, e = RegInfo->getNumRegs(); i != e; ++i)
622 if (PhysRegsUsed[i] != -1)
623 if (unsigned VirtReg = PhysRegsUsed[i])
Alkis Evlogimenosc0b9dc52004-02-12 02:27:10 +0000624 spillVirtReg(MBB, MI, VirtReg, i);
Chris Lattner64667b62004-02-09 01:26:13 +0000625 else
626 removePhysReg(i);
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000627
Chris Lattnerecea5632004-02-09 02:12:04 +0000628#ifndef NDEBUG
629 bool AllOk = true;
Alkis Evlogimenos4d0d8642004-02-25 21:55:45 +0000630 for (unsigned i = MRegisterInfo::FirstVirtualRegister,
631 e = MF->getSSARegMap()->getLastVirtReg(); i <= e; ++i)
Chris Lattnerecea5632004-02-09 02:12:04 +0000632 if (unsigned PR = Virt2PhysRegMap[i]) {
633 std::cerr << "Register still mapped: " << i << " -> " << PR << "\n";
634 AllOk = false;
635 }
636 assert(AllOk && "Virtual registers still in phys regs?");
637#endif
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000638
Chris Lattner128c2aa2003-08-17 18:01:15 +0000639 // Clear any physical register which appear live at the end of the basic
640 // block, but which do not hold any virtual registers. e.g., the stack
641 // pointer.
642 PhysRegsUseOrder.clear();
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000643}
644
Chris Lattner86c69a62002-12-17 03:16:10 +0000645
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000646/// runOnMachineFunction - Register allocate the whole function
647///
648bool RA::runOnMachineFunction(MachineFunction &Fn) {
649 DEBUG(std::cerr << "Machine Function " << "\n");
650 MF = &Fn;
Chris Lattner580f9be2002-12-28 20:40:43 +0000651 TM = &Fn.getTarget();
652 RegInfo = TM->getRegisterInfo();
Chris Lattner56ddada2004-02-17 17:49:10 +0000653 LV = &getAnalysis<LiveVariables>();
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000654
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000655 PhysRegsUsed.assign(RegInfo->getNumRegs(), -1);
Chris Lattner64667b62004-02-09 01:26:13 +0000656
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000657 // initialize the virtual->physical register map to have a 'null'
658 // mapping for all virtual registers
Alkis Evlogimenos4d0d8642004-02-25 21:55:45 +0000659 Virt2PhysRegMap.grow(MF->getSSARegMap()->getLastVirtReg());
Chris Lattnerecea5632004-02-09 02:12:04 +0000660
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000661 // Loop over all of the basic blocks, eliminating virtual register references
662 for (MachineFunction::iterator MBB = Fn.begin(), MBBe = Fn.end();
663 MBB != MBBe; ++MBB)
664 AllocateBasicBlock(*MBB);
665
Chris Lattner580f9be2002-12-28 20:40:43 +0000666 StackSlotForVirtReg.clear();
Alkis Evlogimenos4de473b2004-02-13 18:20:47 +0000667 PhysRegsUsed.clear();
Chris Lattner91a452b2003-01-13 00:25:40 +0000668 VirtRegModified.clear();
Chris Lattnerecea5632004-02-09 02:12:04 +0000669 Virt2PhysRegMap.clear();
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000670 return true;
671}
672
Chris Lattneref09c632004-01-31 21:27:19 +0000673FunctionPass *llvm::createLocalRegisterAllocator() {
Chris Lattner580f9be2002-12-28 20:40:43 +0000674 return new RA();
Chris Lattnerb74e83c2002-12-16 16:15:28 +0000675}