1212#ifndef LLVM_CODEGEN_REGALLOCGREEDY_H_
1313#define LLVM_CODEGEN_REGALLOCGREEDY_H_
1414
15- #include " InterferenceCache.h"
16- #include " RegAllocBase.h"
17- #include " SplitKit.h"
1815#include " llvm/ADT/ArrayRef.h"
1916#include " llvm/ADT/BitVector.h"
2017#include " llvm/ADT/IndexedMap.h"
2118#include " llvm/ADT/SetVector.h"
2219#include " llvm/ADT/SmallVector.h"
2320#include " llvm/ADT/StringRef.h"
2421#include " llvm/CodeGen/CalcSpillWeights.h"
22+ #include " llvm/CodeGen/InterferenceCache.h"
2523#include " llvm/CodeGen/LiveDebugVariables.h"
2624#include " llvm/CodeGen/LiveInterval.h"
2725#include " llvm/CodeGen/LiveRangeEdit.h"
26+ #include " llvm/CodeGen/LiveStacks.h"
2827#include " llvm/CodeGen/MachineFunction.h"
2928#include " llvm/CodeGen/MachineFunctionPass.h"
29+ #include " llvm/CodeGen/RegAllocBase.h"
30+ #include " llvm/CodeGen/RegAllocEvictionAdvisor.h"
3031#include " llvm/CodeGen/RegAllocPriorityAdvisor.h"
3132#include " llvm/CodeGen/RegisterClassInfo.h"
3233#include " llvm/CodeGen/SpillPlacement.h"
3334#include " llvm/CodeGen/Spiller.h"
35+ #include " llvm/CodeGen/SplitKit.h"
3436#include " llvm/CodeGen/TargetRegisterInfo.h"
37+ #include " llvm/IR/PassManager.h"
3538#include < algorithm>
3639#include < cstdint>
3740#include < memory>
@@ -56,11 +59,30 @@ class SlotIndexes;
5659class TargetInstrInfo ;
5760class VirtRegMap ;
5861
59- class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
60- public RegAllocBase,
62+ class LLVM_LIBRARY_VISIBILITY RAGreedy : public RegAllocBase,
6163 private LiveRangeEdit::Delegate {
62- // Interface to eviction advisers
6364public:
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
6486 // / Track allocation stage and eviction loop prevention during allocation.
6587 class ExtraRegInfo final {
6688 // RegInfo - Keep additional information about each live range.
@@ -178,6 +200,10 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
178200 EdgeBundles *Bundles = nullptr ;
179201 SpillPlacement *SpillPlacer = nullptr ;
180202 LiveDebugVariables *DebugVars = nullptr ;
203+ LiveStacks *LSS = nullptr ; // Used by InlineSpiller
204+ // Proxy for the advisors
205+ RegAllocEvictionAdvisorProvider *EvictProvider = nullptr ;
206+ RegAllocPriorityAdvisorProvider *PriorityProvider = nullptr ;
181207
182208 // state
183209 std::unique_ptr<Spiller> SpillerInstance;
@@ -282,13 +308,11 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
282308
283309public:
284310 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);
285315
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 ;
292316 Spiller &spiller () override { return *SpillerInstance; }
293317 void enqueueImpl (const LiveInterval *LI) override ;
294318 const LiveInterval *dequeue () override ;
@@ -297,19 +321,9 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
297321 void aboutToRemoveInterval (const LiveInterval &) override ;
298322
299323 // / 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);
311325
312- static char ID ;
326+ void releaseMemory () ;
313327
314328private:
315329 MCRegister selectOrSplitImpl (const LiveInterval &,
@@ -451,5 +465,23 @@ class LLVM_LIBRARY_VISIBILITY RAGreedy : public MachineFunctionPass,
451465 // / Report the statistic for each loop.
452466 void reportStats ();
453467};
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+ };
454486} // namespace llvm
455487#endif // #ifndef LLVM_CODEGEN_REGALLOCGREEDY_H_
0 commit comments