Skip to content

Commit 2783683

Browse files
committed
Remove setAnalyses(); pass analysis in getAdvisor
1 parent ef2ab43 commit 2783683

File tree

4 files changed

+19
-48
lines changed

4 files changed

+19
-48
lines changed

llvm/include/llvm/CodeGen/RegAllocEvictionAdvisor.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -170,22 +170,13 @@ class RegAllocEvictionAdvisorProvider {
170170
llvm::function_ref<float()> GetReward) {}
171171

172172
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-
}
173+
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
174+
MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *Loops) = 0;
182175

183176
AdvisorMode getAdvisorMode() const { return Mode; }
184177

185178
protected:
186179
LLVMContext &Ctx;
187-
MachineBlockFrequencyInfo *MBFI;
188-
MachineLoopInfo *Loops;
189180

190181
private:
191182
const AdvisorMode Mode;
@@ -215,8 +206,10 @@ class RegAllocEvictionAdvisorAnalysisLegacy : public ImmutablePass {
215206
static char ID;
216207

217208
/// Get an advisor for the given context (i.e. machine function, etc)
218-
virtual std::unique_ptr<RegAllocEvictionAdvisorProvider>&
219-
getProvider() = 0;
209+
std::unique_ptr<RegAllocEvictionAdvisorProvider> &getProvider() {
210+
return Provider;
211+
}
212+
220213
AdvisorMode getAdvisorMode() const { return Mode; }
221214
virtual void logRewardIfNeeded(const MachineFunction &MF,
222215
llvm::function_ref<float()> GetReward) {};

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ class ReleaseModeEvictionAdvisorProvider final
409409
}
410410

411411
std::unique_ptr<RegAllocEvictionAdvisor>
412-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
412+
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
413+
MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *Loops) override {
413414
if (!Runner) {
414415
if (InteractiveChannelBaseName.empty())
415416
Runner = std::make_unique<ReleaseModeModelRunner<CompiledModelType>>(
@@ -437,14 +438,6 @@ class ReleaseModeEvictionAdvisorAnalysisLegacy final
437438
ReleaseModeEvictionAdvisorAnalysisLegacy()
438439
: RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Release) {}
439440

440-
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
441-
getProvider() override {
442-
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
443-
auto *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
444-
Provider->setAnalyses(MBFI, Loops);
445-
return Provider;
446-
}
447-
448441
void logRewardIfNeeded(const MachineFunction &MF,
449442
llvm::function_ref<float()> GetReward) override {
450443
// No-op in release mode
@@ -465,9 +458,6 @@ class ReleaseModeEvictionAdvisorAnalysisLegacy final
465458
AU.addRequired<MachineLoopInfoWrapperPass>();
466459
RegAllocEvictionAdvisorAnalysisLegacy::getAnalysisUsage(AU);
467460
}
468-
469-
private:
470-
// std::unique_ptr<ReleaseModeEvictionAdvisorProvider> Provider;
471461
};
472462

473463
// ===================================
@@ -583,7 +573,8 @@ class DevelopmentModeEvictionAdvisorProvider final
583573
}
584574

585575
std::unique_ptr<RegAllocEvictionAdvisor>
586-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
576+
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
577+
MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *Loops) override {
587578
if (!Runner)
588579
return nullptr;
589580
if (Log)
@@ -619,14 +610,6 @@ class DevelopmentModeEvictionAdvisorAnalysisLegacy final
619610
Provider->logRewardIfNeeded(MF, GetReward);
620611
}
621612

622-
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
623-
getProvider() override {
624-
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
625-
auto *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
626-
Provider->setAnalyses(MBFI, Loops);
627-
return Provider;
628-
}
629-
630613
// support for isa<> and dyn_cast.
631614
static bool classof(const RegAllocEvictionAdvisorAnalysisLegacy *R) {
632615
return R->getAdvisorMode() == AdvisorMode::Development;

llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ class DefaultEvictionAdvisorProvider final
8383
}
8484

8585
std::unique_ptr<RegAllocEvictionAdvisor>
86-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
86+
getAdvisor(const MachineFunction &MF, const RAGreedy &RA,
87+
MachineBlockFrequencyInfo *, MachineLoopInfo *) override {
8788
return std::make_unique<DefaultEvictionAdvisor>(MF, RA);
8889
}
8990
};
@@ -95,12 +96,6 @@ class DefaultEvictionAdvisorAnalysisLegacy final
9596
: RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Default),
9697
NotAsRequested(NotAsRequested) {}
9798

98-
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
99-
getProvider() override {
100-
// MBFI and Loops not required here.
101-
return Provider;
102-
}
103-
10499
bool doInitialization(Module &M) override {
105100
Provider.reset(
106101
new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext()));
@@ -125,22 +120,19 @@ void RegAllocEvictionAdvisorAnalysis::initializeProvider(
125120
return;
126121
if (Mode == RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default)
127122
Provider.reset(
128-
new DefaultEvictionAdvisorProvider(/*NotAsRequested*/ false, Ctx));
123+
new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/false, Ctx));
129124
else
130125
initializeMLProvider(Mode, Ctx);
131126
if (!Provider)
132127
Provider.reset(
133-
new DefaultEvictionAdvisorProvider(/*NotAsRequested*/ true, Ctx));
128+
new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/true, Ctx));
134129
}
135130

136131
RegAllocEvictionAdvisorAnalysis::Result
137132
RegAllocEvictionAdvisorAnalysis::run(MachineFunction &MF,
138133
MachineFunctionAnalysisManager &MFAM) {
139134
// Lazy initialization of the provider.
140135
initializeProvider(::Mode, MF.getFunction().getContext());
141-
auto *MBFI = &MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
142-
auto *Loops = &MFAM.getResult<MachineLoopAnalysis>(MF);
143-
Provider->setAnalyses(MBFI, Loops);
144136
return Result{Provider.get()};
145137
}
146138

llvm/lib/CodeGen/RegAllocGreedy.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2765,8 +2765,11 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27652765
: TRI->reverseLocalAssignment();
27662766

27672767
ExtraInfo.emplace();
2768-
EvictAdvisor =
2769-
getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().getProvider()->getAdvisor(*MF, *this);
2768+
2769+
auto &EvictAdvisorProvider =
2770+
getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().getProvider();
2771+
EvictAdvisor = EvictAdvisorProvider->getAdvisor(*MF, *this, MBFI, Loops);
2772+
27702773
PriorityAdvisor =
27712774
getAnalysis<RegAllocPriorityAdvisorAnalysis>().getAdvisor(*MF, *this);
27722775

0 commit comments

Comments
 (0)