Skip to content

Commit d6cdb24

Browse files
committed
Remove createProvider*(), add new method in ML.cpp
1 parent 9027a0e commit d6cdb24

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
@@ -1143,11 +1143,6 @@ void llvm::extractMBBFrequency(
11431143
// Development mode-specific implementations
11441144
#ifdef LLVM_HAVE_TFLITE
11451145

1146-
RegAllocEvictionAdvisorProvider *
1147-
llvm::createDevelopmentModeAdvisorProvider(LLVMContext &Ctx) {
1148-
return new DevelopmentModeEvictionAdvisorProvider(Ctx);
1149-
}
1150-
11511146
RegAllocEvictionAdvisorAnalysisLegacy *
11521147
llvm::createDevelopmentModeAdvisorAnalysisLegacy() {
11531148
return new DevelopmentModeEvictionAdvisorAnalysisLegacy();
@@ -1224,9 +1219,22 @@ bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
12241219
}
12251220
#endif // #ifdef LLVM_HAVE_TFLITE
12261221

1227-
RegAllocEvictionAdvisorProvider *
1228-
llvm::createReleaseModeAdvisorProvider(LLVMContext &Ctx) {
1229-
return new ReleaseModeEvictionAdvisorProvider(Ctx);
1222+
void RegAllocEvictionAdvisorAnalysis::initializeMLProvider(
1223+
RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) {
1224+
if (Provider)
1225+
return;
1226+
switch (Mode) {
1227+
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development:
1228+
#if defined(LLVM_HAVE_TFLITE)
1229+
Provider.reset(new DevelopmentModeEvictionAdvisorProvider(Ctx));
1230+
#endif
1231+
break;
1232+
case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release:
1233+
Provider.reset(new ReleaseModeEvictionAdvisorProvider(Ctx));
1234+
break;
1235+
default:
1236+
break;
1237+
}
12301238
}
12311239

12321240
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)