xref: /aosp_15_r20/external/llvm/lib/CodeGen/RegAllocBasic.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- RegAllocBasic.cpp - Basic Register Allocator ----------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file defines the RABasic function pass, which provides a minimal
11*9880d681SAndroid Build Coastguard Worker // implementation of the basic register allocator.
12*9880d681SAndroid Build Coastguard Worker //
13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/Passes.h"
16*9880d681SAndroid Build Coastguard Worker #include "AllocationOrder.h"
17*9880d681SAndroid Build Coastguard Worker #include "LiveDebugVariables.h"
18*9880d681SAndroid Build Coastguard Worker #include "RegAllocBase.h"
19*9880d681SAndroid Build Coastguard Worker #include "Spiller.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/AliasAnalysis.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/CalcSpillWeights.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/LiveIntervalAnalysis.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/LiveRangeEdit.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/LiveRegMatrix.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/LiveStackAnalysis.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunctionPass.h"
28*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineInstr.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineLoopInfo.h"
30*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineRegisterInfo.h"
31*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/RegAllocRegistry.h"
32*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/VirtRegMap.h"
33*9880d681SAndroid Build Coastguard Worker #include "llvm/PassAnalysisSupport.h"
34*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Debug.h"
35*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/raw_ostream.h"
36*9880d681SAndroid Build Coastguard Worker #include "llvm/Target/TargetRegisterInfo.h"
37*9880d681SAndroid Build Coastguard Worker #include <cstdlib>
38*9880d681SAndroid Build Coastguard Worker #include <queue>
39*9880d681SAndroid Build Coastguard Worker 
40*9880d681SAndroid Build Coastguard Worker using namespace llvm;
41*9880d681SAndroid Build Coastguard Worker 
42*9880d681SAndroid Build Coastguard Worker #define DEBUG_TYPE "regalloc"
43*9880d681SAndroid Build Coastguard Worker 
44*9880d681SAndroid Build Coastguard Worker static RegisterRegAlloc basicRegAlloc("basic", "basic register allocator",
45*9880d681SAndroid Build Coastguard Worker                                       createBasicRegisterAllocator);
46*9880d681SAndroid Build Coastguard Worker 
47*9880d681SAndroid Build Coastguard Worker namespace {
48*9880d681SAndroid Build Coastguard Worker   struct CompSpillWeight {
operator ()__anon90e31fb70111::CompSpillWeight49*9880d681SAndroid Build Coastguard Worker     bool operator()(LiveInterval *A, LiveInterval *B) const {
50*9880d681SAndroid Build Coastguard Worker       return A->weight < B->weight;
51*9880d681SAndroid Build Coastguard Worker     }
52*9880d681SAndroid Build Coastguard Worker   };
53*9880d681SAndroid Build Coastguard Worker }
54*9880d681SAndroid Build Coastguard Worker 
55*9880d681SAndroid Build Coastguard Worker namespace {
56*9880d681SAndroid Build Coastguard Worker /// RABasic provides a minimal implementation of the basic register allocation
57*9880d681SAndroid Build Coastguard Worker /// algorithm. It prioritizes live virtual registers by spill weight and spills
58*9880d681SAndroid Build Coastguard Worker /// whenever a register is unavailable. This is not practical in production but
59*9880d681SAndroid Build Coastguard Worker /// provides a useful baseline both for measuring other allocators and comparing
60*9880d681SAndroid Build Coastguard Worker /// the speed of the basic algorithm against other styles of allocators.
61*9880d681SAndroid Build Coastguard Worker class RABasic : public MachineFunctionPass, public RegAllocBase
62*9880d681SAndroid Build Coastguard Worker {
63*9880d681SAndroid Build Coastguard Worker   // context
64*9880d681SAndroid Build Coastguard Worker   MachineFunction *MF;
65*9880d681SAndroid Build Coastguard Worker 
66*9880d681SAndroid Build Coastguard Worker   // state
67*9880d681SAndroid Build Coastguard Worker   std::unique_ptr<Spiller> SpillerInstance;
68*9880d681SAndroid Build Coastguard Worker   std::priority_queue<LiveInterval*, std::vector<LiveInterval*>,
69*9880d681SAndroid Build Coastguard Worker                       CompSpillWeight> Queue;
70*9880d681SAndroid Build Coastguard Worker 
71*9880d681SAndroid Build Coastguard Worker   // Scratch space.  Allocated here to avoid repeated malloc calls in
72*9880d681SAndroid Build Coastguard Worker   // selectOrSplit().
73*9880d681SAndroid Build Coastguard Worker   BitVector UsableRegs;
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker public:
76*9880d681SAndroid Build Coastguard Worker   RABasic();
77*9880d681SAndroid Build Coastguard Worker 
78*9880d681SAndroid Build Coastguard Worker   /// Return the pass name.
getPassName() const79*9880d681SAndroid Build Coastguard Worker   const char* getPassName() const override {
80*9880d681SAndroid Build Coastguard Worker     return "Basic Register Allocator";
81*9880d681SAndroid Build Coastguard Worker   }
82*9880d681SAndroid Build Coastguard Worker 
83*9880d681SAndroid Build Coastguard Worker   /// RABasic analysis usage.
84*9880d681SAndroid Build Coastguard Worker   void getAnalysisUsage(AnalysisUsage &AU) const override;
85*9880d681SAndroid Build Coastguard Worker 
86*9880d681SAndroid Build Coastguard Worker   void releaseMemory() override;
87*9880d681SAndroid Build Coastguard Worker 
spiller()88*9880d681SAndroid Build Coastguard Worker   Spiller &spiller() override { return *SpillerInstance; }
89*9880d681SAndroid Build Coastguard Worker 
enqueue(LiveInterval * LI)90*9880d681SAndroid Build Coastguard Worker   void enqueue(LiveInterval *LI) override {
91*9880d681SAndroid Build Coastguard Worker     Queue.push(LI);
92*9880d681SAndroid Build Coastguard Worker   }
93*9880d681SAndroid Build Coastguard Worker 
dequeue()94*9880d681SAndroid Build Coastguard Worker   LiveInterval *dequeue() override {
95*9880d681SAndroid Build Coastguard Worker     if (Queue.empty())
96*9880d681SAndroid Build Coastguard Worker       return nullptr;
97*9880d681SAndroid Build Coastguard Worker     LiveInterval *LI = Queue.top();
98*9880d681SAndroid Build Coastguard Worker     Queue.pop();
99*9880d681SAndroid Build Coastguard Worker     return LI;
100*9880d681SAndroid Build Coastguard Worker   }
101*9880d681SAndroid Build Coastguard Worker 
102*9880d681SAndroid Build Coastguard Worker   unsigned selectOrSplit(LiveInterval &VirtReg,
103*9880d681SAndroid Build Coastguard Worker                          SmallVectorImpl<unsigned> &SplitVRegs) override;
104*9880d681SAndroid Build Coastguard Worker 
105*9880d681SAndroid Build Coastguard Worker   /// Perform register allocation.
106*9880d681SAndroid Build Coastguard Worker   bool runOnMachineFunction(MachineFunction &mf) override;
107*9880d681SAndroid Build Coastguard Worker 
108*9880d681SAndroid Build Coastguard Worker   // Helper for spilling all live virtual registers currently unified under preg
109*9880d681SAndroid Build Coastguard Worker   // that interfere with the most recently queried lvr.  Return true if spilling
110*9880d681SAndroid Build Coastguard Worker   // was successful, and append any new spilled/split intervals to splitLVRs.
111*9880d681SAndroid Build Coastguard Worker   bool spillInterferences(LiveInterval &VirtReg, unsigned PhysReg,
112*9880d681SAndroid Build Coastguard Worker                           SmallVectorImpl<unsigned> &SplitVRegs);
113*9880d681SAndroid Build Coastguard Worker 
114*9880d681SAndroid Build Coastguard Worker   static char ID;
115*9880d681SAndroid Build Coastguard Worker };
116*9880d681SAndroid Build Coastguard Worker 
117*9880d681SAndroid Build Coastguard Worker char RABasic::ID = 0;
118*9880d681SAndroid Build Coastguard Worker 
119*9880d681SAndroid Build Coastguard Worker } // end anonymous namespace
120*9880d681SAndroid Build Coastguard Worker 
RABasic()121*9880d681SAndroid Build Coastguard Worker RABasic::RABasic(): MachineFunctionPass(ID) {
122*9880d681SAndroid Build Coastguard Worker   initializeLiveDebugVariablesPass(*PassRegistry::getPassRegistry());
123*9880d681SAndroid Build Coastguard Worker   initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
124*9880d681SAndroid Build Coastguard Worker   initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
125*9880d681SAndroid Build Coastguard Worker   initializeRegisterCoalescerPass(*PassRegistry::getPassRegistry());
126*9880d681SAndroid Build Coastguard Worker   initializeMachineSchedulerPass(*PassRegistry::getPassRegistry());
127*9880d681SAndroid Build Coastguard Worker   initializeLiveStacksPass(*PassRegistry::getPassRegistry());
128*9880d681SAndroid Build Coastguard Worker   initializeMachineDominatorTreePass(*PassRegistry::getPassRegistry());
129*9880d681SAndroid Build Coastguard Worker   initializeMachineLoopInfoPass(*PassRegistry::getPassRegistry());
130*9880d681SAndroid Build Coastguard Worker   initializeVirtRegMapPass(*PassRegistry::getPassRegistry());
131*9880d681SAndroid Build Coastguard Worker   initializeLiveRegMatrixPass(*PassRegistry::getPassRegistry());
132*9880d681SAndroid Build Coastguard Worker }
133*9880d681SAndroid Build Coastguard Worker 
getAnalysisUsage(AnalysisUsage & AU) const134*9880d681SAndroid Build Coastguard Worker void RABasic::getAnalysisUsage(AnalysisUsage &AU) const {
135*9880d681SAndroid Build Coastguard Worker   AU.setPreservesCFG();
136*9880d681SAndroid Build Coastguard Worker   AU.addRequired<AAResultsWrapperPass>();
137*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<AAResultsWrapperPass>();
138*9880d681SAndroid Build Coastguard Worker   AU.addRequired<LiveIntervals>();
139*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<LiveIntervals>();
140*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<SlotIndexes>();
141*9880d681SAndroid Build Coastguard Worker   AU.addRequired<LiveDebugVariables>();
142*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<LiveDebugVariables>();
143*9880d681SAndroid Build Coastguard Worker   AU.addRequired<LiveStacks>();
144*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<LiveStacks>();
145*9880d681SAndroid Build Coastguard Worker   AU.addRequired<MachineBlockFrequencyInfo>();
146*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<MachineBlockFrequencyInfo>();
147*9880d681SAndroid Build Coastguard Worker   AU.addRequiredID(MachineDominatorsID);
148*9880d681SAndroid Build Coastguard Worker   AU.addPreservedID(MachineDominatorsID);
149*9880d681SAndroid Build Coastguard Worker   AU.addRequired<MachineLoopInfo>();
150*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<MachineLoopInfo>();
151*9880d681SAndroid Build Coastguard Worker   AU.addRequired<VirtRegMap>();
152*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<VirtRegMap>();
153*9880d681SAndroid Build Coastguard Worker   AU.addRequired<LiveRegMatrix>();
154*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<LiveRegMatrix>();
155*9880d681SAndroid Build Coastguard Worker   MachineFunctionPass::getAnalysisUsage(AU);
156*9880d681SAndroid Build Coastguard Worker }
157*9880d681SAndroid Build Coastguard Worker 
releaseMemory()158*9880d681SAndroid Build Coastguard Worker void RABasic::releaseMemory() {
159*9880d681SAndroid Build Coastguard Worker   SpillerInstance.reset();
160*9880d681SAndroid Build Coastguard Worker }
161*9880d681SAndroid Build Coastguard Worker 
162*9880d681SAndroid Build Coastguard Worker 
163*9880d681SAndroid Build Coastguard Worker // Spill or split all live virtual registers currently unified under PhysReg
164*9880d681SAndroid Build Coastguard Worker // that interfere with VirtReg. The newly spilled or split live intervals are
165*9880d681SAndroid Build Coastguard Worker // returned by appending them to SplitVRegs.
spillInterferences(LiveInterval & VirtReg,unsigned PhysReg,SmallVectorImpl<unsigned> & SplitVRegs)166*9880d681SAndroid Build Coastguard Worker bool RABasic::spillInterferences(LiveInterval &VirtReg, unsigned PhysReg,
167*9880d681SAndroid Build Coastguard Worker                                  SmallVectorImpl<unsigned> &SplitVRegs) {
168*9880d681SAndroid Build Coastguard Worker   // Record each interference and determine if all are spillable before mutating
169*9880d681SAndroid Build Coastguard Worker   // either the union or live intervals.
170*9880d681SAndroid Build Coastguard Worker   SmallVector<LiveInterval*, 8> Intfs;
171*9880d681SAndroid Build Coastguard Worker 
172*9880d681SAndroid Build Coastguard Worker   // Collect interferences assigned to any alias of the physical register.
173*9880d681SAndroid Build Coastguard Worker   for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) {
174*9880d681SAndroid Build Coastguard Worker     LiveIntervalUnion::Query &Q = Matrix->query(VirtReg, *Units);
175*9880d681SAndroid Build Coastguard Worker     Q.collectInterferingVRegs();
176*9880d681SAndroid Build Coastguard Worker     if (Q.seenUnspillableVReg())
177*9880d681SAndroid Build Coastguard Worker       return false;
178*9880d681SAndroid Build Coastguard Worker     for (unsigned i = Q.interferingVRegs().size(); i; --i) {
179*9880d681SAndroid Build Coastguard Worker       LiveInterval *Intf = Q.interferingVRegs()[i - 1];
180*9880d681SAndroid Build Coastguard Worker       if (!Intf->isSpillable() || Intf->weight > VirtReg.weight)
181*9880d681SAndroid Build Coastguard Worker         return false;
182*9880d681SAndroid Build Coastguard Worker       Intfs.push_back(Intf);
183*9880d681SAndroid Build Coastguard Worker     }
184*9880d681SAndroid Build Coastguard Worker   }
185*9880d681SAndroid Build Coastguard Worker   DEBUG(dbgs() << "spilling " << TRI->getName(PhysReg) <<
186*9880d681SAndroid Build Coastguard Worker         " interferences with " << VirtReg << "\n");
187*9880d681SAndroid Build Coastguard Worker   assert(!Intfs.empty() && "expected interference");
188*9880d681SAndroid Build Coastguard Worker 
189*9880d681SAndroid Build Coastguard Worker   // Spill each interfering vreg allocated to PhysReg or an alias.
190*9880d681SAndroid Build Coastguard Worker   for (unsigned i = 0, e = Intfs.size(); i != e; ++i) {
191*9880d681SAndroid Build Coastguard Worker     LiveInterval &Spill = *Intfs[i];
192*9880d681SAndroid Build Coastguard Worker 
193*9880d681SAndroid Build Coastguard Worker     // Skip duplicates.
194*9880d681SAndroid Build Coastguard Worker     if (!VRM->hasPhys(Spill.reg))
195*9880d681SAndroid Build Coastguard Worker       continue;
196*9880d681SAndroid Build Coastguard Worker 
197*9880d681SAndroid Build Coastguard Worker     // Deallocate the interfering vreg by removing it from the union.
198*9880d681SAndroid Build Coastguard Worker     // A LiveInterval instance may not be in a union during modification!
199*9880d681SAndroid Build Coastguard Worker     Matrix->unassign(Spill);
200*9880d681SAndroid Build Coastguard Worker 
201*9880d681SAndroid Build Coastguard Worker     // Spill the extracted interval.
202*9880d681SAndroid Build Coastguard Worker     LiveRangeEdit LRE(&Spill, SplitVRegs, *MF, *LIS, VRM, nullptr, &DeadRemats);
203*9880d681SAndroid Build Coastguard Worker     spiller().spill(LRE);
204*9880d681SAndroid Build Coastguard Worker   }
205*9880d681SAndroid Build Coastguard Worker   return true;
206*9880d681SAndroid Build Coastguard Worker }
207*9880d681SAndroid Build Coastguard Worker 
208*9880d681SAndroid Build Coastguard Worker // Driver for the register assignment and splitting heuristics.
209*9880d681SAndroid Build Coastguard Worker // Manages iteration over the LiveIntervalUnions.
210*9880d681SAndroid Build Coastguard Worker //
211*9880d681SAndroid Build Coastguard Worker // This is a minimal implementation of register assignment and splitting that
212*9880d681SAndroid Build Coastguard Worker // spills whenever we run out of registers.
213*9880d681SAndroid Build Coastguard Worker //
214*9880d681SAndroid Build Coastguard Worker // selectOrSplit can only be called once per live virtual register. We then do a
215*9880d681SAndroid Build Coastguard Worker // single interference test for each register the correct class until we find an
216*9880d681SAndroid Build Coastguard Worker // available register. So, the number of interference tests in the worst case is
217*9880d681SAndroid Build Coastguard Worker // |vregs| * |machineregs|. And since the number of interference tests is
218*9880d681SAndroid Build Coastguard Worker // minimal, there is no value in caching them outside the scope of
219*9880d681SAndroid Build Coastguard Worker // selectOrSplit().
selectOrSplit(LiveInterval & VirtReg,SmallVectorImpl<unsigned> & SplitVRegs)220*9880d681SAndroid Build Coastguard Worker unsigned RABasic::selectOrSplit(LiveInterval &VirtReg,
221*9880d681SAndroid Build Coastguard Worker                                 SmallVectorImpl<unsigned> &SplitVRegs) {
222*9880d681SAndroid Build Coastguard Worker   // Populate a list of physical register spill candidates.
223*9880d681SAndroid Build Coastguard Worker   SmallVector<unsigned, 8> PhysRegSpillCands;
224*9880d681SAndroid Build Coastguard Worker 
225*9880d681SAndroid Build Coastguard Worker   // Check for an available register in this class.
226*9880d681SAndroid Build Coastguard Worker   AllocationOrder Order(VirtReg.reg, *VRM, RegClassInfo, Matrix);
227*9880d681SAndroid Build Coastguard Worker   while (unsigned PhysReg = Order.next()) {
228*9880d681SAndroid Build Coastguard Worker     // Check for interference in PhysReg
229*9880d681SAndroid Build Coastguard Worker     switch (Matrix->checkInterference(VirtReg, PhysReg)) {
230*9880d681SAndroid Build Coastguard Worker     case LiveRegMatrix::IK_Free:
231*9880d681SAndroid Build Coastguard Worker       // PhysReg is available, allocate it.
232*9880d681SAndroid Build Coastguard Worker       return PhysReg;
233*9880d681SAndroid Build Coastguard Worker 
234*9880d681SAndroid Build Coastguard Worker     case LiveRegMatrix::IK_VirtReg:
235*9880d681SAndroid Build Coastguard Worker       // Only virtual registers in the way, we may be able to spill them.
236*9880d681SAndroid Build Coastguard Worker       PhysRegSpillCands.push_back(PhysReg);
237*9880d681SAndroid Build Coastguard Worker       continue;
238*9880d681SAndroid Build Coastguard Worker 
239*9880d681SAndroid Build Coastguard Worker     default:
240*9880d681SAndroid Build Coastguard Worker       // RegMask or RegUnit interference.
241*9880d681SAndroid Build Coastguard Worker       continue;
242*9880d681SAndroid Build Coastguard Worker     }
243*9880d681SAndroid Build Coastguard Worker   }
244*9880d681SAndroid Build Coastguard Worker 
245*9880d681SAndroid Build Coastguard Worker   // Try to spill another interfering reg with less spill weight.
246*9880d681SAndroid Build Coastguard Worker   for (SmallVectorImpl<unsigned>::iterator PhysRegI = PhysRegSpillCands.begin(),
247*9880d681SAndroid Build Coastguard Worker        PhysRegE = PhysRegSpillCands.end(); PhysRegI != PhysRegE; ++PhysRegI) {
248*9880d681SAndroid Build Coastguard Worker     if (!spillInterferences(VirtReg, *PhysRegI, SplitVRegs))
249*9880d681SAndroid Build Coastguard Worker       continue;
250*9880d681SAndroid Build Coastguard Worker 
251*9880d681SAndroid Build Coastguard Worker     assert(!Matrix->checkInterference(VirtReg, *PhysRegI) &&
252*9880d681SAndroid Build Coastguard Worker            "Interference after spill.");
253*9880d681SAndroid Build Coastguard Worker     // Tell the caller to allocate to this newly freed physical register.
254*9880d681SAndroid Build Coastguard Worker     return *PhysRegI;
255*9880d681SAndroid Build Coastguard Worker   }
256*9880d681SAndroid Build Coastguard Worker 
257*9880d681SAndroid Build Coastguard Worker   // No other spill candidates were found, so spill the current VirtReg.
258*9880d681SAndroid Build Coastguard Worker   DEBUG(dbgs() << "spilling: " << VirtReg << '\n');
259*9880d681SAndroid Build Coastguard Worker   if (!VirtReg.isSpillable())
260*9880d681SAndroid Build Coastguard Worker     return ~0u;
261*9880d681SAndroid Build Coastguard Worker   LiveRangeEdit LRE(&VirtReg, SplitVRegs, *MF, *LIS, VRM, nullptr, &DeadRemats);
262*9880d681SAndroid Build Coastguard Worker   spiller().spill(LRE);
263*9880d681SAndroid Build Coastguard Worker 
264*9880d681SAndroid Build Coastguard Worker   // The live virtual register requesting allocation was spilled, so tell
265*9880d681SAndroid Build Coastguard Worker   // the caller not to allocate anything during this round.
266*9880d681SAndroid Build Coastguard Worker   return 0;
267*9880d681SAndroid Build Coastguard Worker }
268*9880d681SAndroid Build Coastguard Worker 
runOnMachineFunction(MachineFunction & mf)269*9880d681SAndroid Build Coastguard Worker bool RABasic::runOnMachineFunction(MachineFunction &mf) {
270*9880d681SAndroid Build Coastguard Worker   DEBUG(dbgs() << "********** BASIC REGISTER ALLOCATION **********\n"
271*9880d681SAndroid Build Coastguard Worker                << "********** Function: "
272*9880d681SAndroid Build Coastguard Worker                << mf.getName() << '\n');
273*9880d681SAndroid Build Coastguard Worker 
274*9880d681SAndroid Build Coastguard Worker   MF = &mf;
275*9880d681SAndroid Build Coastguard Worker   RegAllocBase::init(getAnalysis<VirtRegMap>(),
276*9880d681SAndroid Build Coastguard Worker                      getAnalysis<LiveIntervals>(),
277*9880d681SAndroid Build Coastguard Worker                      getAnalysis<LiveRegMatrix>());
278*9880d681SAndroid Build Coastguard Worker 
279*9880d681SAndroid Build Coastguard Worker   calculateSpillWeightsAndHints(*LIS, *MF, VRM,
280*9880d681SAndroid Build Coastguard Worker                                 getAnalysis<MachineLoopInfo>(),
281*9880d681SAndroid Build Coastguard Worker                                 getAnalysis<MachineBlockFrequencyInfo>());
282*9880d681SAndroid Build Coastguard Worker 
283*9880d681SAndroid Build Coastguard Worker   SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM));
284*9880d681SAndroid Build Coastguard Worker 
285*9880d681SAndroid Build Coastguard Worker   allocatePhysRegs();
286*9880d681SAndroid Build Coastguard Worker   postOptimization();
287*9880d681SAndroid Build Coastguard Worker 
288*9880d681SAndroid Build Coastguard Worker   // Diagnostic output before rewriting
289*9880d681SAndroid Build Coastguard Worker   DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *VRM << "\n");
290*9880d681SAndroid Build Coastguard Worker 
291*9880d681SAndroid Build Coastguard Worker   releaseMemory();
292*9880d681SAndroid Build Coastguard Worker   return true;
293*9880d681SAndroid Build Coastguard Worker }
294*9880d681SAndroid Build Coastguard Worker 
createBasicRegisterAllocator()295*9880d681SAndroid Build Coastguard Worker FunctionPass* llvm::createBasicRegisterAllocator()
296*9880d681SAndroid Build Coastguard Worker {
297*9880d681SAndroid Build Coastguard Worker   return new RABasic();
298*9880d681SAndroid Build Coastguard Worker }
299