Skip to content

Commit

Permalink
Suggestions and remove createProvider methods
Browse files Browse the repository at this point in the history
  • Loading branch information
optimisan committed Jan 1, 2025
1 parent 9dd5454 commit 94f3240
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
7 changes: 2 additions & 5 deletions llvm/include/llvm/CodeGen/RegAllocPriorityAdvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ class RegAllocPriorityAdvisorProvider {
const AdvisorMode Mode;
};

RegAllocPriorityAdvisorProvider *createReleaseModePriorityAdvisorProvider();

RegAllocPriorityAdvisorProvider *
createDevelopmentModePriorityAdvisorProvider(LLVMContext &Ctx);

class RegAllocPriorityAdvisorAnalysis
: public AnalysisInfoMixin<RegAllocPriorityAdvisorAnalysis> {
static AnalysisKey Key;
Expand All @@ -116,6 +111,8 @@ class RegAllocPriorityAdvisorAnalysis

private:
void initializeProvider(LLVMContext &Ctx);
void initializeMLProvider(RegAllocPriorityAdvisorProvider::AdvisorMode Mode,
LLVMContext &Ctx);
std::unique_ptr<RegAllocPriorityAdvisorProvider> Provider;
};

Expand Down
29 changes: 18 additions & 11 deletions llvm/lib/CodeGen/MLRegAllocPriorityAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,6 @@ class ReleaseModePriorityAdvisorProvider final
std::unique_ptr<MLModelRunner> Runner;
};

RegAllocPriorityAdvisorProvider *createReleaseModePriorityAdvisorProvider() {
return new ReleaseModePriorityAdvisorProvider();
}

class ReleaseModePriorityAdvisorAnalysisLegacy final
: public RegAllocPriorityAdvisorAnalysisLegacy {
public:
Expand All @@ -176,8 +172,6 @@ class ReleaseModePriorityAdvisorAnalysisLegacy final
Provider = std::make_unique<ReleaseModePriorityAdvisorProvider>();
return false;
}

// std::unique_ptr<ReleaseModePriorityAdvisorProvider> Provider;
};

// ===================================
Expand Down Expand Up @@ -283,11 +277,6 @@ class DevelopmentModePriorityAdvisorProvider final
std::unique_ptr<Logger> Log;
};

RegAllocPriorityAdvisorProvider *
createDevelopmentModePriorityAdvisorProvider(LLVMContext &Ctx) {
return new DevelopmentModePriorityAdvisorProvider(Ctx);
}

class DevelopmentModePriorityAdvisorAnalysisLegacy final
: public RegAllocPriorityAdvisorAnalysisLegacy {
public:
Expand Down Expand Up @@ -410,3 +399,21 @@ DevelopmentModePriorityAdvisor::getPriority(const LiveInterval &LI) const {
}

#endif // #ifdef LLVM_HAVE_TFLITE

void RegAllocPriorityAdvisorAnalysis::initializeMLProvider(
RegAllocPriorityAdvisorProvider::AdvisorMode Mode, LLVMContext &Ctx) {
if (Provider)
return;
switch (Mode) {
case RegAllocPriorityAdvisorProvider::AdvisorMode::Development:
#if defined(LLVM_HAVE_TFLITE)
Provider.reset(new DevelopmentModePriorityAdvisorProvider(Ctx));
#endif
break;
case RegAllocPriorityAdvisorProvider::AdvisorMode::Release:
Provider.reset(new ReleaseModePriorityAdvisorProvider());
break;
default:
break;
}
}
20 changes: 5 additions & 15 deletions llvm/lib/CodeGen/RegAllocPriorityAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,14 @@ class DefaultPriorityAdvisorAnalysisLegacy final
void RegAllocPriorityAdvisorAnalysis::initializeProvider(LLVMContext &Ctx) {
if (Provider)
return;

switch (Mode) {
case RegAllocPriorityAdvisorProvider::AdvisorMode::Default:
if (Mode == RegAllocPriorityAdvisorProvider::AdvisorMode::Default)
Provider.reset(
new DefaultPriorityAdvisorProvider(/*NotAsRequested*/ false, Ctx));
break;
case RegAllocPriorityAdvisorProvider::AdvisorMode::Development:
#if defined(LLVM_HAVE_TFLITE)
Provider.reset(createDevelopmentModePriorityAdvisorProvider(Ctx));
#endif
break;
case RegAllocPriorityAdvisorProvider::AdvisorMode::Release:
Provider.reset(createReleaseModePriorityAdvisorProvider());
break;
}
new DefaultPriorityAdvisorProvider(/*NotAsRequested=*/false, Ctx));
else
initializeMLProvider(Mode, Ctx);
if (!Provider)
Provider.reset(
new DefaultPriorityAdvisorProvider(/*NotAsRequested*/ true, Ctx));
new DefaultPriorityAdvisorProvider(/*NotAsRequested=*/true, Ctx));
}

AnalysisKey RegAllocPriorityAdvisorAnalysis::Key;
Expand Down

0 comments on commit 94f3240

Please sign in to comment.