10b57cec5SDimitry Andric //===-- RegAllocBasic.cpp - Basic Register Allocator ----------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file defines the RABasic function pass, which provides a minimal
100b57cec5SDimitry Andric // implementation of the basic register allocator.
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #include "AllocationOrder.h"
150b57cec5SDimitry Andric #include "LiveDebugVariables.h"
160b57cec5SDimitry Andric #include "RegAllocBase.h"
170b57cec5SDimitry Andric #include "llvm/Analysis/AliasAnalysis.h"
180b57cec5SDimitry Andric #include "llvm/CodeGen/CalcSpillWeights.h"
190b57cec5SDimitry Andric #include "llvm/CodeGen/LiveIntervals.h"
200b57cec5SDimitry Andric #include "llvm/CodeGen/LiveRangeEdit.h"
210b57cec5SDimitry Andric #include "llvm/CodeGen/LiveRegMatrix.h"
220b57cec5SDimitry Andric #include "llvm/CodeGen/LiveStacks.h"
230b57cec5SDimitry Andric #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
240b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunctionPass.h"
250b57cec5SDimitry Andric #include "llvm/CodeGen/MachineInstr.h"
260b57cec5SDimitry Andric #include "llvm/CodeGen/MachineLoopInfo.h"
270b57cec5SDimitry Andric #include "llvm/CodeGen/MachineRegisterInfo.h"
280b57cec5SDimitry Andric #include "llvm/CodeGen/Passes.h"
290b57cec5SDimitry Andric #include "llvm/CodeGen/RegAllocRegistry.h"
305ffd83dbSDimitry Andric #include "llvm/CodeGen/Spiller.h"
310b57cec5SDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h"
320b57cec5SDimitry Andric #include "llvm/CodeGen/VirtRegMap.h"
335ffd83dbSDimitry Andric #include "llvm/Pass.h"
340b57cec5SDimitry Andric #include "llvm/Support/Debug.h"
350b57cec5SDimitry Andric #include "llvm/Support/raw_ostream.h"
360b57cec5SDimitry Andric #include <cstdlib>
370b57cec5SDimitry Andric #include <queue>
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric using namespace llvm;
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric #define DEBUG_TYPE "regalloc"
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric static RegisterRegAlloc basicRegAlloc("basic", "basic register allocator",
440b57cec5SDimitry Andric                                       createBasicRegisterAllocator);
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric namespace {
470b57cec5SDimitry Andric   struct CompSpillWeight {
operator ()__anon7c0ba8530111::CompSpillWeight480b57cec5SDimitry Andric     bool operator()(LiveInterval *A, LiveInterval *B) const {
49af732203SDimitry Andric       return A->weight() < B->weight();
500b57cec5SDimitry Andric     }
510b57cec5SDimitry Andric   };
520b57cec5SDimitry Andric }
530b57cec5SDimitry Andric 
540b57cec5SDimitry Andric namespace {
550b57cec5SDimitry Andric /// RABasic provides a minimal implementation of the basic register allocation
560b57cec5SDimitry Andric /// algorithm. It prioritizes live virtual registers by spill weight and spills
570b57cec5SDimitry Andric /// whenever a register is unavailable. This is not practical in production but
580b57cec5SDimitry Andric /// provides a useful baseline both for measuring other allocators and comparing
590b57cec5SDimitry Andric /// the speed of the basic algorithm against other styles of allocators.
600b57cec5SDimitry Andric class RABasic : public MachineFunctionPass,
610b57cec5SDimitry Andric                 public RegAllocBase,
620b57cec5SDimitry Andric                 private LiveRangeEdit::Delegate {
630b57cec5SDimitry Andric   // context
640b57cec5SDimitry Andric   MachineFunction *MF;
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   // state
670b57cec5SDimitry Andric   std::unique_ptr<Spiller> SpillerInstance;
680b57cec5SDimitry Andric   std::priority_queue<LiveInterval*, std::vector<LiveInterval*>,
690b57cec5SDimitry Andric                       CompSpillWeight> Queue;
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   // Scratch space.  Allocated here to avoid repeated malloc calls in
720b57cec5SDimitry Andric   // selectOrSplit().
730b57cec5SDimitry Andric   BitVector UsableRegs;
740b57cec5SDimitry Andric 
75af732203SDimitry Andric   bool LRE_CanEraseVirtReg(Register) override;
76af732203SDimitry Andric   void LRE_WillShrinkVirtReg(Register) override;
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric public:
79*5f7ddb14SDimitry Andric   RABasic(const RegClassFilterFunc F = allocateAllRegClasses);
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   /// Return the pass name.
getPassName() const820b57cec5SDimitry Andric   StringRef getPassName() const override { return "Basic Register Allocator"; }
830b57cec5SDimitry Andric 
840b57cec5SDimitry Andric   /// RABasic analysis usage.
850b57cec5SDimitry Andric   void getAnalysisUsage(AnalysisUsage &AU) const override;
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric   void releaseMemory() override;
880b57cec5SDimitry Andric 
spiller()890b57cec5SDimitry Andric   Spiller &spiller() override { return *SpillerInstance; }
900b57cec5SDimitry Andric 
enqueueImpl(LiveInterval * LI)91*5f7ddb14SDimitry Andric   void enqueueImpl(LiveInterval *LI) override {
920b57cec5SDimitry Andric     Queue.push(LI);
930b57cec5SDimitry Andric   }
940b57cec5SDimitry Andric 
dequeue()950b57cec5SDimitry Andric   LiveInterval *dequeue() override {
960b57cec5SDimitry Andric     if (Queue.empty())
970b57cec5SDimitry Andric       return nullptr;
980b57cec5SDimitry Andric     LiveInterval *LI = Queue.top();
990b57cec5SDimitry Andric     Queue.pop();
1000b57cec5SDimitry Andric     return LI;
1010b57cec5SDimitry Andric   }
1020b57cec5SDimitry Andric 
103af732203SDimitry Andric   MCRegister selectOrSplit(LiveInterval &VirtReg,
1045ffd83dbSDimitry Andric                            SmallVectorImpl<Register> &SplitVRegs) override;
1050b57cec5SDimitry Andric 
1060b57cec5SDimitry Andric   /// Perform register allocation.
1070b57cec5SDimitry Andric   bool runOnMachineFunction(MachineFunction &mf) override;
1080b57cec5SDimitry Andric 
getRequiredProperties() const1090b57cec5SDimitry Andric   MachineFunctionProperties getRequiredProperties() const override {
1100b57cec5SDimitry Andric     return MachineFunctionProperties().set(
1110b57cec5SDimitry Andric         MachineFunctionProperties::Property::NoPHIs);
1120b57cec5SDimitry Andric   }
1130b57cec5SDimitry Andric 
getClearedProperties() const114af732203SDimitry Andric   MachineFunctionProperties getClearedProperties() const override {
115af732203SDimitry Andric     return MachineFunctionProperties().set(
116af732203SDimitry Andric       MachineFunctionProperties::Property::IsSSA);
117af732203SDimitry Andric   }
118af732203SDimitry Andric 
1190b57cec5SDimitry Andric   // Helper for spilling all live virtual registers currently unified under preg
1200b57cec5SDimitry Andric   // that interfere with the most recently queried lvr.  Return true if spilling
1210b57cec5SDimitry Andric   // was successful, and append any new spilled/split intervals to splitLVRs.
122af732203SDimitry Andric   bool spillInterferences(LiveInterval &VirtReg, MCRegister PhysReg,
1235ffd83dbSDimitry Andric                           SmallVectorImpl<Register> &SplitVRegs);
1240b57cec5SDimitry Andric 
1250b57cec5SDimitry Andric   static char ID;
1260b57cec5SDimitry Andric };
1270b57cec5SDimitry Andric 
1280b57cec5SDimitry Andric char RABasic::ID = 0;
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric } // end anonymous namespace
1310b57cec5SDimitry Andric 
1320b57cec5SDimitry Andric char &llvm::RABasicID = RABasic::ID;
1330b57cec5SDimitry Andric 
1340b57cec5SDimitry Andric INITIALIZE_PASS_BEGIN(RABasic, "regallocbasic", "Basic Register Allocator",
1350b57cec5SDimitry Andric                       false, false)
INITIALIZE_PASS_DEPENDENCY(LiveDebugVariables)1360b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(LiveDebugVariables)
1370b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
1380b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
1390b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(RegisterCoalescer)
1400b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(MachineScheduler)
1410b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(LiveStacks)
1420b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree)
1430b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
1440b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(VirtRegMap)
1450b57cec5SDimitry Andric INITIALIZE_PASS_DEPENDENCY(LiveRegMatrix)
1460b57cec5SDimitry Andric INITIALIZE_PASS_END(RABasic, "regallocbasic", "Basic Register Allocator", false,
1470b57cec5SDimitry Andric                     false)
1480b57cec5SDimitry Andric 
149af732203SDimitry Andric bool RABasic::LRE_CanEraseVirtReg(Register VirtReg) {
1500b57cec5SDimitry Andric   LiveInterval &LI = LIS->getInterval(VirtReg);
1510b57cec5SDimitry Andric   if (VRM->hasPhys(VirtReg)) {
1520b57cec5SDimitry Andric     Matrix->unassign(LI);
1530b57cec5SDimitry Andric     aboutToRemoveInterval(LI);
1540b57cec5SDimitry Andric     return true;
1550b57cec5SDimitry Andric   }
1560b57cec5SDimitry Andric   // Unassigned virtreg is probably in the priority queue.
1570b57cec5SDimitry Andric   // RegAllocBase will erase it after dequeueing.
1580b57cec5SDimitry Andric   // Nonetheless, clear the live-range so that the debug
1590b57cec5SDimitry Andric   // dump will show the right state for that VirtReg.
1600b57cec5SDimitry Andric   LI.clear();
1610b57cec5SDimitry Andric   return false;
1620b57cec5SDimitry Andric }
1630b57cec5SDimitry Andric 
LRE_WillShrinkVirtReg(Register VirtReg)164af732203SDimitry Andric void RABasic::LRE_WillShrinkVirtReg(Register VirtReg) {
1650b57cec5SDimitry Andric   if (!VRM->hasPhys(VirtReg))
1660b57cec5SDimitry Andric     return;
1670b57cec5SDimitry Andric 
1680b57cec5SDimitry Andric   // Register is assigned, put it back on the queue for reassignment.
1690b57cec5SDimitry Andric   LiveInterval &LI = LIS->getInterval(VirtReg);
1700b57cec5SDimitry Andric   Matrix->unassign(LI);
1710b57cec5SDimitry Andric   enqueue(&LI);
1720b57cec5SDimitry Andric }
1730b57cec5SDimitry Andric 
RABasic(RegClassFilterFunc F)174*5f7ddb14SDimitry Andric RABasic::RABasic(RegClassFilterFunc F):
175*5f7ddb14SDimitry Andric   MachineFunctionPass(ID),
176*5f7ddb14SDimitry Andric   RegAllocBase(F) {
1770b57cec5SDimitry Andric }
1780b57cec5SDimitry Andric 
getAnalysisUsage(AnalysisUsage & AU) const1790b57cec5SDimitry Andric void RABasic::getAnalysisUsage(AnalysisUsage &AU) const {
1800b57cec5SDimitry Andric   AU.setPreservesCFG();
1810b57cec5SDimitry Andric   AU.addRequired<AAResultsWrapperPass>();
1820b57cec5SDimitry Andric   AU.addPreserved<AAResultsWrapperPass>();
1830b57cec5SDimitry Andric   AU.addRequired<LiveIntervals>();
1840b57cec5SDimitry Andric   AU.addPreserved<LiveIntervals>();
1850b57cec5SDimitry Andric   AU.addPreserved<SlotIndexes>();
1860b57cec5SDimitry Andric   AU.addRequired<LiveDebugVariables>();
1870b57cec5SDimitry Andric   AU.addPreserved<LiveDebugVariables>();
1880b57cec5SDimitry Andric   AU.addRequired<LiveStacks>();
1890b57cec5SDimitry Andric   AU.addPreserved<LiveStacks>();
1900b57cec5SDimitry Andric   AU.addRequired<MachineBlockFrequencyInfo>();
1910b57cec5SDimitry Andric   AU.addPreserved<MachineBlockFrequencyInfo>();
1920b57cec5SDimitry Andric   AU.addRequiredID(MachineDominatorsID);
1930b57cec5SDimitry Andric   AU.addPreservedID(MachineDominatorsID);
1940b57cec5SDimitry Andric   AU.addRequired<MachineLoopInfo>();
1950b57cec5SDimitry Andric   AU.addPreserved<MachineLoopInfo>();
1960b57cec5SDimitry Andric   AU.addRequired<VirtRegMap>();
1970b57cec5SDimitry Andric   AU.addPreserved<VirtRegMap>();
1980b57cec5SDimitry Andric   AU.addRequired<LiveRegMatrix>();
1990b57cec5SDimitry Andric   AU.addPreserved<LiveRegMatrix>();
2000b57cec5SDimitry Andric   MachineFunctionPass::getAnalysisUsage(AU);
2010b57cec5SDimitry Andric }
2020b57cec5SDimitry Andric 
releaseMemory()2030b57cec5SDimitry Andric void RABasic::releaseMemory() {
2040b57cec5SDimitry Andric   SpillerInstance.reset();
2050b57cec5SDimitry Andric }
2060b57cec5SDimitry Andric 
2070b57cec5SDimitry Andric 
2080b57cec5SDimitry Andric // Spill or split all live virtual registers currently unified under PhysReg
2090b57cec5SDimitry Andric // that interfere with VirtReg. The newly spilled or split live intervals are
2100b57cec5SDimitry Andric // returned by appending them to SplitVRegs.
spillInterferences(LiveInterval & VirtReg,MCRegister PhysReg,SmallVectorImpl<Register> & SplitVRegs)211af732203SDimitry Andric bool RABasic::spillInterferences(LiveInterval &VirtReg, MCRegister PhysReg,
2125ffd83dbSDimitry Andric                                  SmallVectorImpl<Register> &SplitVRegs) {
2130b57cec5SDimitry Andric   // Record each interference and determine if all are spillable before mutating
2140b57cec5SDimitry Andric   // either the union or live intervals.
2150b57cec5SDimitry Andric   SmallVector<LiveInterval*, 8> Intfs;
2160b57cec5SDimitry Andric 
2170b57cec5SDimitry Andric   // Collect interferences assigned to any alias of the physical register.
2180b57cec5SDimitry Andric   for (MCRegUnitIterator Units(PhysReg, TRI); Units.isValid(); ++Units) {
2190b57cec5SDimitry Andric     LiveIntervalUnion::Query &Q = Matrix->query(VirtReg, *Units);
2200b57cec5SDimitry Andric     Q.collectInterferingVRegs();
2210b57cec5SDimitry Andric     for (unsigned i = Q.interferingVRegs().size(); i; --i) {
2220b57cec5SDimitry Andric       LiveInterval *Intf = Q.interferingVRegs()[i - 1];
223af732203SDimitry Andric       if (!Intf->isSpillable() || Intf->weight() > VirtReg.weight())
2240b57cec5SDimitry Andric         return false;
2250b57cec5SDimitry Andric       Intfs.push_back(Intf);
2260b57cec5SDimitry Andric     }
2270b57cec5SDimitry Andric   }
2280b57cec5SDimitry Andric   LLVM_DEBUG(dbgs() << "spilling " << printReg(PhysReg, TRI)
2290b57cec5SDimitry Andric                     << " interferences with " << VirtReg << "\n");
2300b57cec5SDimitry Andric   assert(!Intfs.empty() && "expected interference");
2310b57cec5SDimitry Andric 
2320b57cec5SDimitry Andric   // Spill each interfering vreg allocated to PhysReg or an alias.
2330b57cec5SDimitry Andric   for (unsigned i = 0, e = Intfs.size(); i != e; ++i) {
2340b57cec5SDimitry Andric     LiveInterval &Spill = *Intfs[i];
2350b57cec5SDimitry Andric 
2360b57cec5SDimitry Andric     // Skip duplicates.
237af732203SDimitry Andric     if (!VRM->hasPhys(Spill.reg()))
2380b57cec5SDimitry Andric       continue;
2390b57cec5SDimitry Andric 
2400b57cec5SDimitry Andric     // Deallocate the interfering vreg by removing it from the union.
2410b57cec5SDimitry Andric     // A LiveInterval instance may not be in a union during modification!
2420b57cec5SDimitry Andric     Matrix->unassign(Spill);
2430b57cec5SDimitry Andric 
2440b57cec5SDimitry Andric     // Spill the extracted interval.
2450b57cec5SDimitry Andric     LiveRangeEdit LRE(&Spill, SplitVRegs, *MF, *LIS, VRM, this, &DeadRemats);
2460b57cec5SDimitry Andric     spiller().spill(LRE);
2470b57cec5SDimitry Andric   }
2480b57cec5SDimitry Andric   return true;
2490b57cec5SDimitry Andric }
2500b57cec5SDimitry Andric 
2510b57cec5SDimitry Andric // Driver for the register assignment and splitting heuristics.
2520b57cec5SDimitry Andric // Manages iteration over the LiveIntervalUnions.
2530b57cec5SDimitry Andric //
2540b57cec5SDimitry Andric // This is a minimal implementation of register assignment and splitting that
2550b57cec5SDimitry Andric // spills whenever we run out of registers.
2560b57cec5SDimitry Andric //
2570b57cec5SDimitry Andric // selectOrSplit can only be called once per live virtual register. We then do a
2580b57cec5SDimitry Andric // single interference test for each register the correct class until we find an
2590b57cec5SDimitry Andric // available register. So, the number of interference tests in the worst case is
2600b57cec5SDimitry Andric // |vregs| * |machineregs|. And since the number of interference tests is
2610b57cec5SDimitry Andric // minimal, there is no value in caching them outside the scope of
2620b57cec5SDimitry Andric // selectOrSplit().
selectOrSplit(LiveInterval & VirtReg,SmallVectorImpl<Register> & SplitVRegs)263af732203SDimitry Andric MCRegister RABasic::selectOrSplit(LiveInterval &VirtReg,
2645ffd83dbSDimitry Andric                                   SmallVectorImpl<Register> &SplitVRegs) {
2650b57cec5SDimitry Andric   // Populate a list of physical register spill candidates.
266af732203SDimitry Andric   SmallVector<MCRegister, 8> PhysRegSpillCands;
2670b57cec5SDimitry Andric 
2680b57cec5SDimitry Andric   // Check for an available register in this class.
269af732203SDimitry Andric   auto Order =
270af732203SDimitry Andric       AllocationOrder::create(VirtReg.reg(), *VRM, RegClassInfo, Matrix);
271af732203SDimitry Andric   for (MCRegister PhysReg : Order) {
272af732203SDimitry Andric     assert(PhysReg.isValid());
2730b57cec5SDimitry Andric     // Check for interference in PhysReg
2740b57cec5SDimitry Andric     switch (Matrix->checkInterference(VirtReg, PhysReg)) {
2750b57cec5SDimitry Andric     case LiveRegMatrix::IK_Free:
2760b57cec5SDimitry Andric       // PhysReg is available, allocate it.
2770b57cec5SDimitry Andric       return PhysReg;
2780b57cec5SDimitry Andric 
2790b57cec5SDimitry Andric     case LiveRegMatrix::IK_VirtReg:
2800b57cec5SDimitry Andric       // Only virtual registers in the way, we may be able to spill them.
2810b57cec5SDimitry Andric       PhysRegSpillCands.push_back(PhysReg);
2820b57cec5SDimitry Andric       continue;
2830b57cec5SDimitry Andric 
2840b57cec5SDimitry Andric     default:
2850b57cec5SDimitry Andric       // RegMask or RegUnit interference.
2860b57cec5SDimitry Andric       continue;
2870b57cec5SDimitry Andric     }
2880b57cec5SDimitry Andric   }
2890b57cec5SDimitry Andric 
2900b57cec5SDimitry Andric   // Try to spill another interfering reg with less spill weight.
291*5f7ddb14SDimitry Andric   for (MCRegister &PhysReg : PhysRegSpillCands) {
292*5f7ddb14SDimitry Andric     if (!spillInterferences(VirtReg, PhysReg, SplitVRegs))
2930b57cec5SDimitry Andric       continue;
2940b57cec5SDimitry Andric 
295*5f7ddb14SDimitry Andric     assert(!Matrix->checkInterference(VirtReg, PhysReg) &&
2960b57cec5SDimitry Andric            "Interference after spill.");
2970b57cec5SDimitry Andric     // Tell the caller to allocate to this newly freed physical register.
298*5f7ddb14SDimitry Andric     return PhysReg;
2990b57cec5SDimitry Andric   }
3000b57cec5SDimitry Andric 
3010b57cec5SDimitry Andric   // No other spill candidates were found, so spill the current VirtReg.
3020b57cec5SDimitry Andric   LLVM_DEBUG(dbgs() << "spilling: " << VirtReg << '\n');
3030b57cec5SDimitry Andric   if (!VirtReg.isSpillable())
3040b57cec5SDimitry Andric     return ~0u;
3050b57cec5SDimitry Andric   LiveRangeEdit LRE(&VirtReg, SplitVRegs, *MF, *LIS, VRM, this, &DeadRemats);
3060b57cec5SDimitry Andric   spiller().spill(LRE);
3070b57cec5SDimitry Andric 
3080b57cec5SDimitry Andric   // The live virtual register requesting allocation was spilled, so tell
3090b57cec5SDimitry Andric   // the caller not to allocate anything during this round.
3100b57cec5SDimitry Andric   return 0;
3110b57cec5SDimitry Andric }
3120b57cec5SDimitry Andric 
runOnMachineFunction(MachineFunction & mf)3130b57cec5SDimitry Andric bool RABasic::runOnMachineFunction(MachineFunction &mf) {
3140b57cec5SDimitry Andric   LLVM_DEBUG(dbgs() << "********** BASIC REGISTER ALLOCATION **********\n"
3150b57cec5SDimitry Andric                     << "********** Function: " << mf.getName() << '\n');
3160b57cec5SDimitry Andric 
3170b57cec5SDimitry Andric   MF = &mf;
3180b57cec5SDimitry Andric   RegAllocBase::init(getAnalysis<VirtRegMap>(),
3190b57cec5SDimitry Andric                      getAnalysis<LiveIntervals>(),
3200b57cec5SDimitry Andric                      getAnalysis<LiveRegMatrix>());
321af732203SDimitry Andric   VirtRegAuxInfo VRAI(*MF, *LIS, *VRM, getAnalysis<MachineLoopInfo>(),
3220b57cec5SDimitry Andric                       getAnalysis<MachineBlockFrequencyInfo>());
323af732203SDimitry Andric   VRAI.calculateSpillWeightsAndHints();
3240b57cec5SDimitry Andric 
325*5f7ddb14SDimitry Andric   SpillerInstance.reset(createInlineSpiller(*this, *MF, *VRM, VRAI));
3260b57cec5SDimitry Andric 
3270b57cec5SDimitry Andric   allocatePhysRegs();
3280b57cec5SDimitry Andric   postOptimization();
3290b57cec5SDimitry Andric 
3300b57cec5SDimitry Andric   // Diagnostic output before rewriting
3310b57cec5SDimitry Andric   LLVM_DEBUG(dbgs() << "Post alloc VirtRegMap:\n" << *VRM << "\n");
3320b57cec5SDimitry Andric 
3330b57cec5SDimitry Andric   releaseMemory();
3340b57cec5SDimitry Andric   return true;
3350b57cec5SDimitry Andric }
3360b57cec5SDimitry Andric 
createBasicRegisterAllocator()337*5f7ddb14SDimitry Andric FunctionPass* llvm::createBasicRegisterAllocator() {
3380b57cec5SDimitry Andric   return new RABasic();
3390b57cec5SDimitry Andric }
340*5f7ddb14SDimitry Andric 
createBasicRegisterAllocator(RegClassFilterFunc F)341*5f7ddb14SDimitry Andric FunctionPass* llvm::createBasicRegisterAllocator(RegClassFilterFunc F) {
342*5f7ddb14SDimitry Andric   return new RABasic(F);
343*5f7ddb14SDimitry Andric }
344