[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Dec 3 06:43:26 PST 2024
================
@@ -20,76 +20,138 @@
using namespace llvm;
-static cl::opt<RegAllocPriorityAdvisorAnalysis::AdvisorMode> Mode(
+static cl::opt<RegAllocPriorityAdvisorProvider::AdvisorMode> Mode(
"regalloc-enable-priority-advisor", cl::Hidden,
- cl::init(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default),
+ cl::init(RegAllocPriorityAdvisorProvider::AdvisorMode::Default),
cl::desc("Enable regalloc advisor mode"),
cl::values(
- clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Default,
+ clEnumValN(RegAllocPriorityAdvisorProvider::AdvisorMode::Default,
"default", "Default"),
- clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Release,
+ clEnumValN(RegAllocPriorityAdvisorProvider::AdvisorMode::Release,
"release", "precompiled"),
- clEnumValN(RegAllocPriorityAdvisorAnalysis::AdvisorMode::Development,
+ clEnumValN(RegAllocPriorityAdvisorProvider::AdvisorMode::Development,
"development", "for training")));
-char RegAllocPriorityAdvisorAnalysis::ID = 0;
-INITIALIZE_PASS(RegAllocPriorityAdvisorAnalysis, "regalloc-priority",
+char RegAllocPriorityAdvisorAnalysisLegacy::ID = 0;
+INITIALIZE_PASS(RegAllocPriorityAdvisorAnalysisLegacy, "regalloc-priority",
"Regalloc priority policy", false, true)
namespace {
-class DefaultPriorityAdvisorAnalysis final
- : public RegAllocPriorityAdvisorAnalysis {
+
+class DefaultPriorityAdvisorProvider final
+ : public RegAllocPriorityAdvisorProvider {
public:
- DefaultPriorityAdvisorAnalysis(bool NotAsRequested)
- : RegAllocPriorityAdvisorAnalysis(AdvisorMode::Default),
+ DefaultPriorityAdvisorProvider(bool NotAsRequested, LLVMContext &Ctx)
+ : RegAllocPriorityAdvisorProvider(AdvisorMode::Default) {
+ if (NotAsRequested)
+ Ctx.emitError("Requested regalloc priority advisor analysis "
+ "could be created. Using default");
+ }
+
+ // support for isa<> and dyn_cast.
+ static bool classof(const RegAllocPriorityAdvisorProvider *R) {
+ return R->getAdvisorMode() == AdvisorMode::Default;
+ }
+
+ std::unique_ptr<RegAllocPriorityAdvisor>
+ getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
+ assert(SI && "SlotIndexes result must be set");
+ return std::make_unique<DefaultPriorityAdvisor>(MF, RA, SI);
+ }
+};
+
+class DefaultPriorityAdvisorAnalysisLegacy final
+ : public RegAllocPriorityAdvisorAnalysisLegacy {
+public:
+ DefaultPriorityAdvisorAnalysisLegacy(bool NotAsRequested)
+ : RegAllocPriorityAdvisorAnalysisLegacy(AdvisorMode::Default),
NotAsRequested(NotAsRequested) {}
// support for isa<> and dyn_cast.
- static bool classof(const RegAllocPriorityAdvisorAnalysis *R) {
+ static bool classof(const RegAllocPriorityAdvisorAnalysisLegacy *R) {
return R->getAdvisorMode() == AdvisorMode::Default;
}
private:
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<SlotIndexesWrapperPass>();
- RegAllocPriorityAdvisorAnalysis::getAnalysisUsage(AU);
+ RegAllocPriorityAdvisorAnalysisLegacy::getAnalysisUsage(AU);
}
+
std::unique_ptr<RegAllocPriorityAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
- return std::make_unique<DefaultPriorityAdvisor>(
- MF, RA, &getAnalysis<SlotIndexesWrapperPass>().getSI());
+ Provider->setAnalyses(&getAnalysis<SlotIndexesWrapperPass>().getSI());
+ return Provider->getAdvisor(MF, RA);
}
bool doInitialization(Module &M) override {
- if (NotAsRequested)
- M.getContext().emitError("Requested regalloc priority advisor analysis "
- "could be created. Using default");
- return RegAllocPriorityAdvisorAnalysis::doInitialization(M);
+ Provider.reset(
+ new DefaultPriorityAdvisorProvider(NotAsRequested, M.getContext()));
+ return false;
}
+
const bool NotAsRequested;
+ std::unique_ptr<DefaultPriorityAdvisorProvider> Provider;
};
} // namespace
-template <> Pass *llvm::callDefaultCtor<RegAllocPriorityAdvisorAnalysis>() {
+void RegAllocPriorityAdvisorAnalysis::initializeProvider(LLVMContext &Ctx) {
+ if (Provider)
+ return;
+
+ switch (Mode) {
+ case RegAllocPriorityAdvisorProvider::AdvisorMode::Default:
+ Provider.reset(
+ new DefaultPriorityAdvisorProvider(/*NotAsRequested*/ false, Ctx));
----------------
arsenm wrote:
```suggestion
new DefaultPriorityAdvisorProvider(/*NotAsRequested=*/ false, Ctx));
```
https://github.com/llvm/llvm-project/pull/118462
More information about the llvm-branch-commits
mailing list