[nfc][mlgo][regalloc] Stop warnings about unused function

Added a `NoopSavedModelImpl` type which can be used as a mock AOT-ed
saved model, and further minimize conditional compilation cases. This
also removes unused function warnings on gcc.
This commit is contained in:
Mircea Trofin 2022-02-08 07:27:11 -08:00
parent 24a1869d00
commit 5a50ab4d5c
2 changed files with 22 additions and 6 deletions

View File

@ -15,6 +15,7 @@
#define LLVM_ANALYSIS_RELEASEMODEMODELRUNNER_H
#include "llvm/Analysis/MLModelRunner.h"
#include "llvm/Support/ErrorHandling.h"
#include <memory>
#include <vector>
@ -73,6 +74,22 @@ private:
int32_t ResultIndex = -1;
std::unique_ptr<TGen> CompiledModel;
};
/// A mock class satisfying the interface expected by ReleaseModeModelRunner for
/// its `TGen` parameter. Useful to avoid conditional compilation complexity, as
/// a compile-time replacement for a real AOT-ed model.
class NoopSavedModelImpl final {
const char *ErrMsg = "The mock AOT-ed saved model is a compile-time stub and "
"should not be called.";
public:
NoopSavedModelImpl() = default;
int LookupArgIndex(const std::string &) { llvm_unreachable(ErrMsg); }
int LookupResultIndex(const std::string &) { llvm_unreachable(ErrMsg); }
void Run() { llvm_unreachable(ErrMsg); }
void *result_data(int) { llvm_unreachable(ErrMsg); }
void *arg_data(int) { llvm_unreachable(ErrMsg); }
};
} // namespace llvm
#endif // LLVM_ANALYSIS_RELEASEMODEMODELRUNNER_H

View File

@ -46,6 +46,9 @@ using namespace llvm;
// Generated header in release (AOT) mode
#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
#include "RegallocEvictModel.h"
using CompiledModelType = RegallocEvictModel;
#else
using CompiledModelType = NoopSavedModelImpl;
#endif
// Options that only make sense in development mode
@ -318,7 +321,6 @@ private:
// ===================================
// Release (AOT) - specifics
// ===================================
#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
const std::array<std::string, FeatureIDs::FeatureCount> FeatureNames{
#define _GETNAME(_, NAME, __, ___) #NAME,
RA_EVICT_FEATURES_LIST(_GETNAME)
@ -344,15 +346,14 @@ private:
std::unique_ptr<RegAllocEvictionAdvisor>
getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override {
if (!Runner)
Runner = std::make_unique<ReleaseModeModelRunner<RegallocEvictModel>>(
Runner = std::make_unique<ReleaseModeModelRunner<CompiledModelType>>(
MF.getFunction().getContext(), FeatureNames, DecisionName);
return std::make_unique<MLEvictAdvisor>(
MF, RA, Runner.get(), getAnalysis<MachineBlockFrequencyInfo>(),
getAnalysis<MachineLoopInfo>());
}
std::unique_ptr<ReleaseModeModelRunner<RegallocEvictModel>> Runner;
std::unique_ptr<ReleaseModeModelRunner<CompiledModelType>> Runner;
};
#endif
// ===================================
// Development mode-specifics
@ -901,11 +902,9 @@ bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
}
#endif // #ifdef LLVM_HAVE_TF_API
#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
RegAllocEvictionAdvisorAnalysis *llvm::createReleaseModeAdvisor() {
return new ReleaseModeEvictionAdvisorAnalysis();
}
#endif
// In all cases except development mode, we don't need scoring.
#if !defined(LLVM_HAVE_TF_API)