[llvm] b1af01f - [NFC][MLGO] Simplify conditional compilation

Mircea Trofin via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 24 11:23:47 PST 2022


Author: Mircea Trofin
Date: 2022-01-24T11:19:04-08:00
New Revision: b1af01fe6aa7cb733461b2d475add77b947b79fb

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

LOG: [NFC][MLGO] Simplify conditional compilation

Most of the code that's shared between 'release' and 'development'
modes doesn't depend on anything special.

Added: 
    

Modified: 
    llvm/lib/Analysis/MLInlineAdvisor.cpp
    llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp
index 203e0b025e6c6..0480c1cd28428 100644
--- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
@@ -36,11 +36,7 @@
 
 using namespace llvm;
 
-#ifdef LLVM_HAVE_TF_AOT_INLINERSIZEMODEL
-#define LLVM_HAVE_TF_AOT
-#endif
-
-#if defined(LLVM_HAVE_TF_AOT)
+#if defined(LLVM_HAVE_TF_AOT_INLINERSIZEMODEL)
 // codegen-ed file
 #include "InlinerSizeModel.h" // NOLINT
 
@@ -55,8 +51,6 @@ llvm::getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM) {
 
 #define DEBUG_TYPE "inline-ml"
 
-#if defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
-
 static cl::opt<float> SizeIncreaseThreshold(
     "ml-advisor-size-increase-threshold", cl::Hidden,
     cl::desc("Maximum factor by which expected native size may increase before "
@@ -417,4 +411,3 @@ void MLInlineAdvice::recordUnattemptedInliningImpl() {
     return R;
   });
 }
-#endif // defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)

diff  --git a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
index 848f63da288de..a74c57690640c 100644
--- a/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp
@@ -42,11 +42,9 @@
 using namespace llvm;
 
 #define DEBUG_TYPE "ml-regalloc"
-#ifdef LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL
-#define LLVM_HAVE_TF_AOT
-#endif
+
 // Generated header in release (AOT) mode
-#if defined LLVM_HAVE_TF_AOT
+#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
 #include "RegallocEvictModel.h"
 #endif
 
@@ -104,7 +102,6 @@ INITIALIZE_PASS(RegAllocScoring, "regallocscoringpass",
 // ===================================
 // Common ML Advisor declarations
 // ===================================
-#if defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
 namespace {
 // This is the maximum number of interfererring ranges. That's the number of
 // distinct AllocationOrder values, which comes from MCRegisterClass::RegsSize.
@@ -193,7 +190,9 @@ static const std::vector<int64_t> PerLiveRangeShape{1, NumberOfInterferences};
 // of the output tensor.
 // The contract with the model is that the output will be guaranteed to be to a
 // mask == 1 position.
-const char *const DecisionName = "index_to_evict";
+// Using a macro here to avoid 'not used' warnings (and keep cond compilation to
+// a minimum)
+#define DecisionName "index_to_evict"
 
 // Named features index.
 enum FeatureIDs {
@@ -296,13 +295,12 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
 // ===================================
 // Release (AOT) - specifics
 // ===================================
-#ifdef LLVM_HAVE_TF_AOT
+#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
 const std::array<std::string, FeatureIDs::FeatureCount> FeatureNames{
 #define _GETNAME(_, NAME, __, ___) #NAME,
     RA_EVICT_FEATURES_LIST(_GETNAME)
 #undef _GETNAME
 };
-
 class ReleaseModeEvictionAdvisorAnalysis final
     : public RegAllocEvictionAdvisorAnalysis {
 public:
@@ -331,7 +329,7 @@ class ReleaseModeEvictionAdvisorAnalysis final
   }
   std::unique_ptr<ReleaseModeModelRunner<RegallocEvictModel>> Runner;
 };
-#endif // LLVM_HAVE_TF_AOT
+#endif
 
 // ===================================
 // Development mode-specifics
@@ -852,13 +850,11 @@ bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
 }
 #endif // #ifdef LLVM_HAVE_TF_API
 
-// Release mode specific implementations
-#if defined LLVM_HAVE_TF_AOT
+#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
 RegAllocEvictionAdvisorAnalysis *llvm::createReleaseModeAdvisor() {
   return new ReleaseModeEvictionAdvisorAnalysis();
 }
-#endif // defined(LLVM_HAVE_TF_AOT)
-#endif // defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
+#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