@@ -153,6 +153,44 @@ class RegAllocEvictionAdvisor {
153153 const bool EnableLocalReassign;
154154};
155155
156+ // / Common provider for legacy and new pass managers.
157+ // / This keeps the state for logging, and sets up and holds the provider.
158+ // / The legacy pass itself used to keep the logging state and provider,
159+ // / so this extraction helps the NPM analysis to reuse the logic.
160+ // / TODO: Coalesce this with the NPM analysis when legacy PM is removed.
161+ class RegAllocEvictionAdvisorProvider {
162+ public:
163+ enum class AdvisorMode : int { Default, Release, Development };
164+ RegAllocEvictionAdvisorProvider (AdvisorMode Mode, LLVMContext &Ctx)
165+ : Ctx(Ctx), Mode(Mode) {}
166+
167+ virtual ~RegAllocEvictionAdvisorProvider () = default ;
168+
169+ virtual void logRewardIfNeeded (const MachineFunction &MF,
170+ llvm::function_ref<float ()> GetReward) {}
171+
172+ virtual std::unique_ptr<RegAllocEvictionAdvisor>
173+ getAdvisor (const MachineFunction &MF, const RAGreedy &RA) = 0 ;
174+
175+ // / We create this provider in doInitialization which doesn't have these
176+ // / analyses. For NPM, we do have them in run(MachineFunction&)
177+ virtual void setAnalyses (MachineBlockFrequencyInfo *MBFI,
178+ MachineLoopInfo *Loops) {
179+ this ->MBFI = MBFI;
180+ this ->Loops = Loops;
181+ }
182+
183+ AdvisorMode getAdvisorMode () const { return Mode; }
184+
185+ protected:
186+ LLVMContext &Ctx;
187+ MachineBlockFrequencyInfo *MBFI;
188+ MachineLoopInfo *Loops;
189+
190+ private:
191+ const AdvisorMode Mode;
192+ };
193+
156194// / ImmutableAnalysis abstraction for fetching the Eviction Advisor. We model it
157195// / as an analysis to decouple the user from the implementation insofar as
158196// / dependencies on other analyses goes. The motivation for it being an
@@ -177,8 +215,8 @@ class RegAllocEvictionAdvisorAnalysisLegacy : public ImmutablePass {
177215 static char ID;
178216
179217 // / Get an advisor for the given context (i.e. machine function, etc)
180- virtual std::unique_ptr<RegAllocEvictionAdvisor>
181- getAdvisor ( const MachineFunction &MF, const RAGreedy &RA ) = 0 ;
218+ virtual std::unique_ptr<RegAllocEvictionAdvisorProvider>&
219+ getProvider ( ) = 0 ;
182220 AdvisorMode getAdvisorMode () const { return Mode; }
183221 virtual void logRewardIfNeeded (const MachineFunction &MF,
184222 llvm::function_ref<float ()> GetReward) {};
@@ -189,50 +227,13 @@ class RegAllocEvictionAdvisorAnalysisLegacy : public ImmutablePass {
189227 void getAnalysisUsage (AnalysisUsage &AU) const override {
190228 AU.setPreservesAll ();
191229 }
230+ std::unique_ptr<RegAllocEvictionAdvisorProvider> Provider;
192231
193232private:
194233 StringRef getPassName () const override ;
195234 const AdvisorMode Mode;
196235};
197236
198- // / Common provider for legacy and new pass managers.
199- // / This keeps the state for logging, and sets up and holds the provider.
200- // / The legacy pass itself used to keep the logging state and provider,
201- // / so this extraction helps the NPM analysis to reuse the logic.
202- // / TODO: Coalesce this with the NPM analysis when legacy PM is removed.
203- class RegAllocEvictionAdvisorProvider {
204- public:
205- enum class AdvisorMode : int { Default, Release, Development };
206- RegAllocEvictionAdvisorProvider (AdvisorMode Mode, LLVMContext &Ctx)
207- : Ctx(Ctx), Mode(Mode) {}
208-
209- virtual ~RegAllocEvictionAdvisorProvider () = default ;
210-
211- virtual void logRewardIfNeeded (const MachineFunction &MF,
212- llvm::function_ref<float ()> GetReward) {}
213-
214- virtual std::unique_ptr<RegAllocEvictionAdvisor>
215- getAdvisor (const MachineFunction &MF, const RAGreedy &RA) = 0 ;
216-
217- // / We create this provider in doInitialization which doesn't have these
218- // / analyses. For NPM, we do have them in run(MachineFunction&)
219- virtual void setAnalyses (MachineBlockFrequencyInfo *MBFI,
220- MachineLoopInfo *Loops) {
221- this ->MBFI = MBFI;
222- this ->Loops = Loops;
223- }
224-
225- AdvisorMode getAdvisorMode () const { return Mode; }
226-
227- protected:
228- LLVMContext &Ctx;
229- MachineBlockFrequencyInfo *MBFI;
230- MachineLoopInfo *Loops;
231-
232- private:
233- const AdvisorMode Mode;
234- };
235-
236237// / A MachineFunction analysis for fetching the Eviction Advisor.
237238// / This sets up the Provider lazily and caches it.
238239// / - in the ML implementation case, the evaluator is stateless but (especially
0 commit comments