Skip to content

Commit c788cb7

Browse files
committed
Remove createProvider*(), add new method in ML.cpp
1 parent 8bb678d commit c788cb7

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

llvm/include/llvm/CodeGen/RegAllocEvictionAdvisor.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ class RegAllocEvictionAdvisorProvider {
233233
const AdvisorMode Mode;
234234
};
235235

236-
RegAllocEvictionAdvisorProvider *
237-
createReleaseModeAdvisorProvider(LLVMContext &Ctx);
238-
RegAllocEvictionAdvisorProvider *
239-
createDevelopmentModeAdvisorProvider(LLVMContext &Ctx);
240-
241236
/// A MachineFunction analysis for fetching the Eviction Advisor.
242237
/// This sets up the Provider lazily and caches it.
243238
/// - in the ML implementation case, the evaluator is stateless but (especially
@@ -276,7 +271,13 @@ class RegAllocEvictionAdvisorAnalysis
276271
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MAM);
277272

278273
private:
279-
void initializeProvider(LLVMContext &Ctx);
274+
void
275+
initializeProvider(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode,
276+
LLVMContext &Ctx);
277+
void
278+
initializeMLProvider(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode,
279+
LLVMContext &Ctx);
280+
280281
std::unique_ptr<RegAllocEvictionAdvisorProvider> Provider;
281282
};
282283

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,11 +1159,6 @@ void llvm::extractMBBFrequency(
11591159
// Development mode-specific implementations
11601160
#ifdef LLVM_HAVE_TFLITE
11611161

1162-
RegAllocEvictionAdvisorProvider *
1163-
llvm::createDevelopmentModeAdvisorProvider(LLVMContext &Ctx) {
1164-
return new DevelopmentModeEvictionAdvisorProvider(Ctx);
1165-
}
1166-
11671162
RegAllocEvictionAdvisorAnalysisLegacy *
11681163
llvm::createDevelopmentModeAdvisorAnalysisLegacy() {
11691164
return new DevelopmentModeEvictionAdvisorAnalysisLegacy();
@@ -1240,9 +1235,22 @@ bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
12401235
}
12411236
#endif // #ifdef LLVM_HAVE_TFLITE
12421237

1243-
RegAllocEvictionAdvisorProvider *
1244-
llvm::createReleaseModeAdvisorProvider(LLVMContext &Ctx) {
1245-
return new ReleaseModeEvictionAdvisorProvider(Ctx);
1238+
void RegAllocEvictionAdvisorAnalysis::initializeMLProvider(
1239+
RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) {
1240+
if (Provider)
1241+
return;
1242+
switch (Mode) {
1243+
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development:
1244+
#if defined(LLVM_HAVE_TFLITE)
1245+
Provider.reset(new DevelopmentModeEvictionAdvisorProvider(Ctx));
1246+
#endif
1247+
break;
1248+
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release:
1249+
Provider.reset(new ReleaseModeEvictionAdvisorProvider(Ctx));
1250+
break;
1251+
default:
1252+
break;
1253+
}
12461254
}
12471255

12481256
RegAllocEvictionAdvisorAnalysisLegacy *

llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,15 @@ class DefaultEvictionAdvisorAnalysisLegacy final
120120

121121
AnalysisKey RegAllocEvictionAdvisorAnalysis::Key;
122122

123-
void RegAllocEvictionAdvisorAnalysis::initializeProvider(LLVMContext &Ctx) {
123+
void RegAllocEvictionAdvisorAnalysis::initializeProvider(
124+
RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) {
124125
if (Provider)
125126
return;
126-
switch (Mode) {
127-
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default:
127+
if (Mode == RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default)
128128
Provider.reset(
129129
new DefaultEvictionAdvisorProvider(/*NotAsRequested*/ false, Ctx));
130-
break;
131-
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development:
132-
#if defined(LLVM_HAVE_TFLITE)
133-
Provider.reset(createDevelopmentModeAdvisorProvider(Ctx));
134-
#endif
135-
break;
136-
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release:
137-
Provider.reset(createReleaseModeAdvisorProvider(Ctx));
138-
break;
139-
}
130+
else
131+
initializeMLProvider(Mode, Ctx);
140132
if (!Provider)
141133
Provider.reset(
142134
new DefaultEvictionAdvisorProvider(/*NotAsRequested*/ true, Ctx));
@@ -146,7 +138,7 @@ RegAllocEvictionAdvisorAnalysis::Result
146138
RegAllocEvictionAdvisorAnalysis::run(MachineFunction &MF,
147139
MachineFunctionAnalysisManager &MFAM) {
148140
// Lazy initialization of the provider.
149-
initializeProvider(MF.getFunction().getContext());
141+
initializeProvider(::Mode, MF.getFunction().getContext());
150142
auto *MBFI = &MFAM.getResult<MachineBlockFrequencyAnalysis>(MF);
151143
auto *Loops = &MFAM.getResult<MachineLoopAnalysis>(MF);
152144
Provider->setAnalyses(MBFI, Loops);

0 commit comments

Comments
 (0)