12
12
#ifndef LLVM_CODEGEN_REGALLOCGREEDY_H_
13
13
#define LLVM_CODEGEN_REGALLOCGREEDY_H_
14
14
15
- #include " InterferenceCache.h"
16
- #include " RegAllocBase.h"
17
- #include " SplitKit.h"
18
15
#include " llvm/ADT/ArrayRef.h"
19
16
#include " llvm/ADT/BitVector.h"
20
17
#include " llvm/ADT/IndexedMap.h"
21
18
#include " llvm/ADT/SetVector.h"
22
19
#include " llvm/ADT/SmallVector.h"
23
20
#include " llvm/ADT/StringRef.h"
24
21
#include " llvm/CodeGen/CalcSpillWeights.h"
22
+ #include " llvm/CodeGen/InterferenceCache.h"
25
23
#include " llvm/CodeGen/LiveDebugVariables.h"
26
24
#include " llvm/CodeGen/LiveInterval.h"
27
25
#include " llvm/CodeGen/LiveRangeEdit.h"
26
+ #include " llvm/CodeGen/LiveStacks.h"
28
27
#include " llvm/CodeGen/MachineFunction.h"
29
28
#include " llvm/CodeGen/MachineFunctionPass.h"
29
+ #include " llvm/CodeGen/RegAllocBase.h"
30
+ #include " llvm/CodeGen/RegAllocEvictionAdvisor.h"
30
31
#include " llvm/CodeGen/RegAllocPriorityAdvisor.h"
31
32
#include " llvm/CodeGen/RegisterClassInfo.h"
32
33
#include " llvm/CodeGen/SpillPlacement.h"
33
34
#include " llvm/CodeGen/Spiller.h"
35
+ #include " llvm/CodeGen/SplitKit.h"
34
36
#include " llvm/CodeGen/TargetRegisterInfo.h"
37
+ #include " llvm/IR/PassManager.h"
35
38
#include < algorithm>
36
39
#include < cstdint>
37
40
#include < memory>
@@ -56,11 +59,30 @@ class SlotIndexes;
56
59
class TargetInstrInfo ;
57
60
class VirtRegMap ;
58
61
59
- class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
60
- public RegAllocBase,
62
+ class LLVM_LIBRARY_VISIBILITY RAGreedy : public RegAllocBase,
61
63
private LiveRangeEdit::Delegate {
62
- // Interface to eviction advisers
63
64
public:
65
+ struct RequiredAnalyses {
66
+ VirtRegMap *VRM = nullptr ;
67
+ LiveIntervals *LIS = nullptr ;
68
+ LiveRegMatrix *LRM = nullptr ;
69
+ SlotIndexes *Indexes = nullptr ;
70
+ MachineBlockFrequencyInfo *MBFI = nullptr ;
71
+ MachineDominatorTree *DomTree = nullptr ;
72
+ MachineLoopInfo *Loops = nullptr ;
73
+ MachineOptimizationRemarkEmitter *ORE = nullptr ;
74
+ EdgeBundles *Bundles = nullptr ;
75
+ SpillPlacement *SpillPlacer = nullptr ;
76
+ LiveDebugVariables *DebugVars = nullptr ;
77
+
78
+ // Used by InlineSpiller
79
+ LiveStacks *LSS;
80
+ // Proxies for eviction and priority advisors
81
+ RegAllocEvictionAdvisorProvider *EvictProvider;
82
+ RegAllocPriorityAdvisorProvider *PriorityProvider;
83
+ };
84
+
85
+ // Interface to eviction advisers
64
86
// / Track allocation stage and eviction loop prevention during allocation.
65
87
class ExtraRegInfo final {
66
88
// RegInfo - Keep additional information about each live range.
@@ -178,6 +200,10 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
178
200
EdgeBundles *Bundles = nullptr ;
179
201
SpillPlacement *SpillPlacer = nullptr ;
180
202
LiveDebugVariables *DebugVars = nullptr ;
203
+ LiveStacks *LSS = nullptr ; // Used by InlineSpiller
204
+ // Proxy for the advisors
205
+ RegAllocEvictionAdvisorProvider *EvictProvider = nullptr ;
206
+ RegAllocPriorityAdvisorProvider *PriorityProvider = nullptr ;
181
207
182
208
// state
183
209
std::unique_ptr<Spiller> SpillerInstance;
@@ -282,13 +308,11 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
282
308
283
309
public:
284
310
RAGreedy (const RegAllocFilterFunc F = nullptr );
311
+ // Evict and priority advisors use this object, so we can construct those
312
+ // first and pass them here.
313
+ // Not required once legacy PM is removed.
314
+ void setAnalyses (RequiredAnalyses &Analyses);
285
315
286
- // / Return the pass name.
287
- StringRef getPassName () const override { return " Greedy Register Allocator" ; }
288
-
289
- // / RAGreedy analysis usage.
290
- void getAnalysisUsage (AnalysisUsage &AU) const override ;
291
- void releaseMemory () override ;
292
316
Spiller &spiller () override { return *SpillerInstance; }
293
317
void enqueueImpl (const LiveInterval *LI) override ;
294
318
const LiveInterval *dequeue () override ;
@@ -297,19 +321,9 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
297
321
void aboutToRemoveInterval (const LiveInterval &) override ;
298
322
299
323
// / Perform register allocation.
300
- bool runOnMachineFunction (MachineFunction &mf) override ;
301
-
302
- MachineFunctionProperties getRequiredProperties () const override {
303
- return MachineFunctionProperties ().set (
304
- MachineFunctionProperties::Property::NoPHIs);
305
- }
306
-
307
- MachineFunctionProperties getClearedProperties () const override {
308
- return MachineFunctionProperties ().set (
309
- MachineFunctionProperties::Property::IsSSA);
310
- }
324
+ bool run (MachineFunction &mf);
311
325
312
- static char ID ;
326
+ void releaseMemory () ;
313
327
314
328
private:
315
329
MCRegister selectOrSplitImpl (const LiveInterval &,
@@ -451,5 +465,23 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
451
465
// / Report the statistic for each loop.
452
466
void reportStats ();
453
467
};
468
+
469
+ class RAGreedyPass : public PassInfoMixin <RAGreedyPass> {
470
+ RegAllocFilterFunc Filter;
471
+
472
+ public:
473
+ RAGreedyPass (RegAllocFilterFunc F = nullptr ) : Filter(F) {}
474
+ PreservedAnalyses run (MachineFunction &F, MachineFunctionAnalysisManager &AM);
475
+
476
+ MachineFunctionProperties getRequiredProperties () const {
477
+ return MachineFunctionProperties ().set (
478
+ MachineFunctionProperties::Property::NoPHIs);
479
+ }
480
+
481
+ MachineFunctionProperties getClearedProperties () const {
482
+ return MachineFunctionProperties ().set (
483
+ MachineFunctionProperties::Property::IsSSA);
484
+ }
485
+ };
454
486
} // namespace llvm
455
487
#endif // #ifndef LLVM_CODEGEN_REGALLOCGREEDY_H_
0 commit comments