Skip to content

Commit 0a5b903

Browse files
committed
Use the provider as analysis result
1 parent d6cdb24 commit 0a5b903

File tree

4 files changed

+53
-54
lines changed

4 files changed

+53
-54
lines changed

llvm/include/llvm/CodeGen/RegAllocEvictionAdvisor.h

+41-40
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

+8-8
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,12 @@ class ReleaseModeEvictionAdvisorAnalysisLegacy final
414414
ReleaseModeEvictionAdvisorAnalysisLegacy()
415415
: RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Release) {}
416416

417-
std::unique_ptr<RegAllocEvictionAdvisor>
418-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
417+
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
418+
getProvider() override {
419419
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
420420
auto *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
421421
Provider->setAnalyses(MBFI, Loops);
422-
return Provider->getAdvisor(MF, RA);
422+
return Provider;
423423
}
424424

425425
void logRewardIfNeeded(const MachineFunction &MF,
@@ -444,7 +444,7 @@ class ReleaseModeEvictionAdvisorAnalysisLegacy final
444444
}
445445

446446
private:
447-
std::unique_ptr<ReleaseModeEvictionAdvisorProvider> Provider;
447+
// std::unique_ptr<ReleaseModeEvictionAdvisorProvider> Provider;
448448
};
449449

450450
// ===================================
@@ -596,12 +596,12 @@ class DevelopmentModeEvictionAdvisorAnalysisLegacy final
596596
Provider->logRewardIfNeeded(MF, GetReward);
597597
}
598598

599-
std::unique_ptr<RegAllocEvictionAdvisor>
600-
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
599+
std::unique_ptr<RegAllocEvictionAdvisorProvider>&
600+
getProvider() override {
601601
auto *MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
602602
auto *Loops = &getAnalysis<MachineLoopInfoWrapperPass>().getLI();
603603
Provider->setAnalyses(MBFI, Loops);
604-
return Provider->getAdvisor(MF, RA);
604+
return Provider;
605605
}
606606

607607
// support for isa<> and dyn_cast.
@@ -616,7 +616,7 @@ class DevelopmentModeEvictionAdvisorAnalysisLegacy final
616616
}
617617

618618
private:
619-
std::unique_ptr<DevelopmentModeEvictionAdvisorProvider> Provider;
619+
// std::unique_ptr<DevelopmentModeEvictionAdvisorProvider> Provider;
620620
};
621621

622622
#endif //#ifdef LLVM_HAVE_TFLITE

llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp

+3-4
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

+1-2
Original file line numberDiff line numberDiff line change
@@ -2748,8 +2748,7 @@ bool RAGreedy::runOnMachineFunction(MachineFunction &mf) {
27482748

27492749
ExtraInfo.emplace();
27502750
EvictAdvisor =
2751-
getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().getAdvisor(*MF,
2752-
*this);
2751+
getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().getProvider()->getAdvisor(*MF, *this);
27532752
PriorityAdvisor =
27542753
getAnalysis<RegAllocPriorityAdvisorAnalysis>().getAdvisor(*MF, *this);
27552754

0 commit comments

Comments
 (0)