[llvm] [CodeGen][NewPM] Port RegAllocEvictionAdvisor analysis to NPM (PR #117309)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 22 23:36:40 PST 2024
================
@@ -59,59 +62,110 @@ cl::opt<unsigned> EvictInterferenceCutoff(
#define LLVM_HAVE_TF_AOT
#endif
-char RegAllocEvictionAdvisorAnalysis::ID = 0;
-INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysis, "regalloc-evict",
+char RegAllocEvictionAdvisorAnalysisLegacy::ID = 0;
+INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysisLegacy, "regalloc-evict",
"Regalloc eviction policy", false, true)
namespace {
-class DefaultEvictionAdvisorAnalysis final
- : public RegAllocEvictionAdvisorAnalysis {
+class DefaultEvictionAdvisorProvider final
+ : public RegAllocEvictionAdvisorProvider {
public:
- DefaultEvictionAdvisorAnalysis(bool NotAsRequested)
- : RegAllocEvictionAdvisorAnalysis(AdvisorMode::Default),
- NotAsRequested(NotAsRequested) {}
+ DefaultEvictionAdvisorProvider(bool NotAsRequested, LLVMContext &Ctx)
+ : RegAllocEvictionAdvisorProvider(AdvisorMode::Default, Ctx) {
+ if (NotAsRequested)
+ Ctx.emitError("Requested regalloc eviction advisor analysis "
+ "could not be created. Using default");
+ }
// support for isa<> and dyn_cast.
- static bool classof(const RegAllocEvictionAdvisorAnalysis *R) {
+ static bool classof(const RegAllocEvictionAdvisorProvider *R) {
return R->getAdvisorMode() == AdvisorMode::Default;
}
-private:
std::unique_ptr<RegAllocEvictionAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
return std::make_unique<DefaultEvictionAdvisor>(MF, RA);
}
+};
+
+class DefaultEvictionAdvisorAnalysisLegacy final
+ : public RegAllocEvictionAdvisorAnalysisLegacy {
+public:
+ DefaultEvictionAdvisorAnalysisLegacy(bool NotAsRequested)
+ : RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Default),
+ NotAsRequested(NotAsRequested) {}
+
+ std::unique_ptr<RegAllocEvictionAdvisorProvider>&
+ getProvider() override {
+ // MBFI and Loops not required here.
+ return Provider;
+ }
+
bool doInitialization(Module &M) override {
- if (NotAsRequested)
- M.getContext().emitError("Requested regalloc eviction advisor analysis "
- "could not be created. Using default");
- return RegAllocEvictionAdvisorAnalysis::doInitialization(M);
+ Provider.reset(
+ new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext()));
+ return false;
+ }
+
+ // support for isa<> and dyn_cast.
+ static bool classof(const RegAllocEvictionAdvisorAnalysisLegacy *R) {
+ return R->getAdvisorMode() == AdvisorMode::Default;
}
+
+private:
const bool NotAsRequested;
};
} // namespace
-template <> Pass *llvm::callDefaultCtor<RegAllocEvictionAdvisorAnalysis>() {
+AnalysisKey RegAllocEvictionAdvisorAnalysis::Key;
+
+void RegAllocEvictionAdvisorAnalysis::initializeProvider(
+ RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) {
+ if (Provider)
+ return;
+ if (Mode == RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default)
+ Provider.reset(
+ new DefaultEvictionAdvisorProvider(/*NotAsRequested*/ false, Ctx));
+ else
+ initializeMLProvider(Mode, Ctx);
+ if (!Provider)
+ Provider.reset(
+ new DefaultEvictionAdvisorProvider(/*NotAsRequested*/ true, Ctx));
----------------
arsenm wrote:
```suggestion
Provider.reset(
new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/ false, Ctx));
else
initializeMLProvider(Mode, Ctx);
if (!Provider)
Provider.reset(
new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/ true, Ctx));
```
https://github.com/llvm/llvm-project/pull/117309
More information about the llvm-commits
mailing list