Skip to content

Commit d796915

Browse files
committed
Use the provider as analysis result
1 parent 8e5a3b3 commit d796915

File tree

4 files changed

+53
-54
lines changed

4 files changed

+53
-54
lines changed

llvm/include/llvm/CodeGen/RegAllocEvictionAdvisor.h

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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

193232
private:
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

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,12 @@ class ReleaseModeEvictionAdvisorAnalysisLegacy final
437437
ReleaseModeEvictionAdvisorAnalysisLegacy()
438438
: RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Release) {}
439439

440-
std::unique_ptr<RegAllocEvictionAdvisor>
441-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
440+
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
441+
getProvider() override {
442442
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
443443
auto *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
444444
Provider->setAnalyses(MBFI, Loops);
445-
return Provider->getAdvisor(MF, RA);
445+
return Provider;
446446
}
447447

448448
void logRewardIfNeeded(const MachineFunction &MF,
@@ -467,7 +467,7 @@ class ReleaseModeEvictionAdvisorAnalysisLegacy final
467467
}
468468

469469
private:
470-
std::unique_ptr<ReleaseModeEvictionAdvisorProvider> Provider;
470+
// std::unique_ptr<ReleaseModeEvictionAdvisorProvider> Provider;
471471
};
472472

473473
// ===================================
@@ -619,12 +619,12 @@ class DevelopmentModeEvictionAdvisorAnalysisLegacy final
619619
Provider->logRewardIfNeeded(MF, GetReward);
620620
}
621621

622-
std::unique_ptr<RegAllocEvictionAdvisor>
623-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
622+
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
623+
getProvider() override {
624624
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
625625
auto *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
626626
Provider->setAnalyses(MBFI, Loops);
627-
return Provider->getAdvisor(MF, RA);
627+
return Provider;
628628
}
629629

630630
// support for isa<> and dyn_cast.
@@ -639,7 +639,7 @@ class DevelopmentModeEvictionAdvisorAnalysisLegacy final
639639
}
640640

641641
private:
642-
std::unique_ptr<DevelopmentModeEvictionAdvisorProvider> Provider;
642+
// std::unique_ptr<DevelopmentModeEvictionAdvisorProvider> Provider;
643643
};
644644

645645
#endif // #ifdef LLVM_HAVE_TFLITE

llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ class DefaultEvictionAdvisorAnalysisLegacy final
9595
: RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Default),
9696
NotAsRequested(NotAsRequested) {}
9797

98-
std::unique_ptr<RegAllocEvictionAdvisor>
99-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
98+
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
99+
getProvider() override {
100100
// MBFI and Loops not required here.
101-
return Provider->getAdvisor(MF, RA);
101+
return Provider;
102102
}
103103

104104
bool doInitialization(Module &M) override {
@@ -113,7 +113,6 @@ class DefaultEvictionAdvisorAnalysisLegacy final
113113
}
114114

115115
private:
116-
std::unique_ptr<DefaultEvictionAdvisorProvider> Provider;
117116
const bool NotAsRequested;
118117
};
119118
} // namespace

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,8 +2766,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27662766

27672767
ExtraInfo.emplace();
27682768
EvictAdvisor =
2769-
getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().getAdvisor(*MF,
2770-
*this);
2769+
getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().getProvider()->getAdvisor(*MF, *this);
27712770
PriorityAdvisor =
27722771
getAnalysis<RegAllocPriorityAdvisorAnalysis>().getAdvisor(*MF, *this);
27732772

0 commit comments

Comments
 (0)