Skip to content

Commit

Permalink
Remove initializeMLProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
optimisan committed Jan 9, 2025
1 parent 5ea6947 commit 72eff55
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
9 changes: 6 additions & 3 deletions llvm/include/llvm/CodeGen/RegAllocEvictionAdvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@ class RegAllocEvictionAdvisorAnalysis
void
initializeProvider(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode,
LLVMContext &Ctx);
void
initializeMLProvider(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode,
LLVMContext &Ctx);

std::unique_ptr<RegAllocEvictionAdvisorProvider> Provider;
};
Expand All @@ -282,6 +279,12 @@ RegAllocEvictionAdvisorAnalysisLegacy *createReleaseModeAdvisorAnalysisLegacy();
RegAllocEvictionAdvisorAnalysisLegacy *
createDevelopmentModeAdvisorAnalysisLegacy();

RegAllocEvictionAdvisorProvider *
createReleaseModeAdvisorProvider(LLVMContext &Ctx);

RegAllocEvictionAdvisorProvider *
createDevelopmentModeAdvisorProvider(LLVMContext &Ctx);

// TODO: move to RegAllocEvictionAdvisor.cpp when we move implementation
// out of RegAllocGreedy.cpp
class DefaultEvictionAdvisor : public RegAllocEvictionAdvisor {
Expand Down
23 changes: 9 additions & 14 deletions llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1218,22 +1218,17 @@ bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
}
#endif // #ifdef LLVM_HAVE_TFLITE

void RegAllocEvictionAdvisorAnalysis::initializeMLProvider(
RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) {
if (Provider)
return;
switch (Mode) {
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development:
RegAllocEvictionAdvisorProvider *
llvm::createReleaseModeAdvisorProvider(LLVMContext &Ctx) {
return new ReleaseModeEvictionAdvisorProvider(Ctx);
}

RegAllocEvictionAdvisorProvider *
llvm::createDevelopmentModeAdvisorProvider(LLVMContext &Ctx) {
#if defined(LLVM_HAVE_TFLITE)
Provider.reset(new DevelopmentModeEvictionAdvisorProvider(Ctx));
return new DevelopmentModeEvictionAdvisorProvider(Ctx);
#endif
break;
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release:
Provider.reset(new ReleaseModeEvictionAdvisorProvider(Ctx));
break;
default:
break;
}
return nullptr;
}

RegAllocEvictionAdvisorAnalysisLegacy *
Expand Down
16 changes: 13 additions & 3 deletions llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,21 @@ void RegAllocEvictionAdvisorAnalysis::initializeProvider(
RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) {
if (Provider)
return;
if (Mode == RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default)
switch (Mode) {
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default:
Provider.reset(
new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/false, Ctx));
else
initializeMLProvider(Mode, Ctx);
break;
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development:
#if defined(LLVM_HAVE_TFLITE)
Provider.reset(createDevelopmentModeAdvisorProvider(Ctx));
#endif
break;
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release:
Provider.reset(createReleaseModeAdvisorProvider(Ctx));
break;
}

if (!Provider)
Provider.reset(
new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/true, Ctx));
Expand Down

0 comments on commit 72eff55

Please sign in to comment.