5
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
6
//
7
7
// ===----------------------------------------------------------------------===//
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
+ // /
12
13
// ===----------------------------------------------------------------------===//
13
14
15
+ #include " RegAllocBasic.h"
14
16
#include " AllocationOrder.h"
15
- #include " RegAllocBase.h"
16
17
#include " llvm/Analysis/AliasAnalysis.h"
17
18
#include " llvm/Analysis/ProfileSummaryInfo.h"
18
19
#include " llvm/CodeGen/CalcSpillWeights.h"
19
20
#include " llvm/CodeGen/LiveDebugVariables.h"
20
21
#include " llvm/CodeGen/LiveIntervals.h"
21
- #include " llvm/CodeGen/LiveRangeEdit.h"
22
22
#include " llvm/CodeGen/LiveRegMatrix.h"
23
23
#include " llvm/CodeGen/LiveStacks.h"
24
24
#include " llvm/CodeGen/MachineBlockFrequencyInfo.h"
25
25
#include " llvm/CodeGen/MachineDominators.h"
26
- #include " llvm/CodeGen/MachineFunctionPass.h"
27
26
#include " llvm/CodeGen/MachineLoopInfo.h"
28
27
#include " llvm/CodeGen/Passes.h"
29
28
#include " llvm/CodeGen/RegAllocRegistry.h"
30
- #include " llvm/CodeGen/Spiller.h"
31
- #include " llvm/CodeGen/TargetRegisterInfo.h"
32
29
#include " llvm/CodeGen/VirtRegMap.h"
33
30
#include " llvm/Pass.h"
34
31
#include " llvm/Support/Debug.h"
35
32
#include " llvm/Support/raw_ostream.h"
36
- #include < queue>
37
33
38
34
using namespace llvm ;
39
35
@@ -42,89 +38,8 @@ using namespace llvm;
42
38
static RegisterRegAlloc basicRegAlloc (" basic" , " basic register allocator" ,
43
39
createBasicRegisterAllocator);
44
40
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
-
124
41
char RABasic::ID = 0 ;
125
42
126
- } // end anonymous namespace
127
-
128
43
char &llvm::RABasicID = RABasic::ID;
129
44
130
45
INITIALIZE_PASS_BEGIN (RABasic, " regallocbasic" , " Basic Register Allocator" ,
0 commit comments