55// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66//
77// ===----------------------------------------------------------------------===//
8- //
9- // This file defines the RABasic function pass, which provides a minimal
10- // implementation of the basic register allocator.
11- //
8+ // /
9+ // / \file
10+ // / This file defines the RABasic function pass, which provides a minimal
11+ // / implementation of the basic register allocator.
12+ // /
1213// ===----------------------------------------------------------------------===//
1314
15+ #include " RegAllocBasic.h"
1416#include " AllocationOrder.h"
15- #include " RegAllocBase.h"
1617#include " llvm/Analysis/AliasAnalysis.h"
1718#include " llvm/Analysis/ProfileSummaryInfo.h"
1819#include " llvm/CodeGen/CalcSpillWeights.h"
1920#include " llvm/CodeGen/LiveDebugVariables.h"
2021#include " llvm/CodeGen/LiveIntervals.h"
21- #include " llvm/CodeGen/LiveRangeEdit.h"
2222#include " llvm/CodeGen/LiveRegMatrix.h"
2323#include " llvm/CodeGen/LiveStacks.h"
2424#include " llvm/CodeGen/MachineBlockFrequencyInfo.h"
2525#include " llvm/CodeGen/MachineDominators.h"
26- #include " llvm/CodeGen/MachineFunctionPass.h"
2726#include " llvm/CodeGen/MachineLoopInfo.h"
2827#include " llvm/CodeGen/Passes.h"
2928#include " llvm/CodeGen/RegAllocRegistry.h"
30- #include " llvm/CodeGen/Spiller.h"
31- #include " llvm/CodeGen/TargetRegisterInfo.h"
3229#include " llvm/CodeGen/VirtRegMap.h"
3330#include " llvm/Pass.h"
3431#include " llvm/Support/Debug.h"
3532#include " llvm/Support/raw_ostream.h"
36- #include < queue>
3733
3834using namespace llvm ;
3935
@@ -42,89 +38,8 @@ using namespace llvm;
4238static RegisterRegAlloc basicRegAlloc (" basic" , " basic register allocator" ,
4339 createBasicRegisterAllocator);
4440
45- namespace {
46- struct CompSpillWeight {
47- bool operator ()(const LiveInterval *A, const LiveInterval *B) const {
48- return A->weight () < B->weight ();
49- }
50- };
51- }
52-
53- namespace {
54- // / RABasic provides a minimal implementation of the basic register allocation
55- // / algorithm. It prioritizes live virtual registers by spill weight and spills
56- // / whenever a register is unavailable. This is not practical in production but
57- // / provides a useful baseline both for measuring other allocators and comparing
58- // / the speed of the basic algorithm against other styles of allocators.
59- class RABasic : public MachineFunctionPass ,
60- public RegAllocBase,
61- private LiveRangeEdit::Delegate {
62- // context
63- MachineFunction *MF = nullptr ;
64-
65- // state
66- std::unique_ptr<Spiller> SpillerInstance;
67- std::priority_queue<const LiveInterval *, std::vector<const LiveInterval *>,
68- CompSpillWeight>
69- Queue;
70-
71- // Scratch space. Allocated here to avoid repeated malloc calls in
72- // selectOrSplit().
73- BitVector UsableRegs;
74-
75- bool LRE_CanEraseVirtReg (Register) override ;
76- void LRE_WillShrinkVirtReg (Register) override ;
77-
78- public:
79- RABasic (const RegAllocFilterFunc F = nullptr );
80-
81- // / Return the pass name.
82- StringRef getPassName () const override { return " Basic Register Allocator" ; }
83-
84- // / RABasic analysis usage.
85- void getAnalysisUsage (AnalysisUsage &AU) const override ;
86-
87- void releaseMemory () override ;
88-
89- Spiller &spiller () override { return *SpillerInstance; }
90-
91- void enqueueImpl (const LiveInterval *LI) override { Queue.push (LI); }
92-
93- const LiveInterval *dequeue () override {
94- if (Queue.empty ())
95- return nullptr ;
96- const LiveInterval *LI = Queue.top ();
97- Queue.pop ();
98- return LI;
99- }
100-
101- MCRegister selectOrSplit (const LiveInterval &VirtReg,
102- SmallVectorImpl<Register> &SplitVRegs) override ;
103-
104- // / Perform register allocation.
105- bool runOnMachineFunction (MachineFunction &mf) override ;
106-
107- MachineFunctionProperties getRequiredProperties () const override {
108- return MachineFunctionProperties ().setNoPHIs ();
109- }
110-
111- MachineFunctionProperties getClearedProperties () const override {
112- return MachineFunctionProperties ().setIsSSA ();
113- }
114-
115- // Helper for spilling all live virtual registers currently unified under preg
116- // that interfere with the most recently queried lvr. Return true if spilling
117- // was successful, and append any new spilled/split intervals to splitLVRs.
118- bool spillInterferences (const LiveInterval &VirtReg, MCRegister PhysReg,
119- SmallVectorImpl<Register> &SplitVRegs);
120-
121- static char ID;
122- };
123-
12441char RABasic::ID = 0 ;
12542
126- } // end anonymous namespace
127-
12843char &llvm::RABasicID = RABasic::ID;
12944
13045INITIALIZE_PASS_BEGIN (RABasic, " regallocbasic" , " Basic Register Allocator" ,
0 commit comments