[llvm] 5a50ab4 - [nfc][mlgo][regalloc] Stop warnings about unused function

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 8 08:36:34 PST 2022


Author: Mircea Trofin
Date: 2022-02-08T08:35:33-08:00
New Revision: 5a50ab4d5c2c50ccf2df3b3dffa7519c92b0b01a

URL: https://github.com/llvm/llvm-project/commit/5a50ab4d5c2c50ccf2df3b3dffa7519c92b0b01a
DIFF: https://github.com/llvm/llvm-project/commit/5a50ab4d5c2c50ccf2df3b3dffa7519c92b0b01a.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
    llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h b/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
index 1bf2e853980c..152d3e5fa313 100644
--- a/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
+++ b/llvm/include/llvm/Analysis/ReleaseModeModelRunner.h
@@ -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 @@ class ReleaseModeModelRunner final : public MLModelRunner {
   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

diff  --git a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
index f0893a43e4d0..89be511fc4f9 100644
--- a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
@@ -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 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
 // ===================================
 // 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 @@ class ReleaseModeEvictionAdvisorAnalysis final
   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)


        


More information about the llvm-commits mailing list