Skip to content

Commit b1af01f

Browse files
committed
[NFC][MLGO] Simplify conditional compilation
Most of the code that's shared between 'release' and 'development' modes doesn't depend on anything special.
1 parent 4684857 commit b1af01f

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

llvm/lib/Analysis/MLInlineAdvisor.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@
3636

3737
using namespace llvm;
3838

39-
#ifdef LLVM_HAVE_TF_AOT_INLINERSIZEMODEL
40-
#define LLVM_HAVE_TF_AOT
41-
#endif
42-
43-
#if defined(LLVM_HAVE_TF_AOT)
39+
#if defined(LLVM_HAVE_TF_AOT_INLINERSIZEMODEL)
4440
// codegen-ed file
4541
#include "InlinerSizeModel.h" // NOLINT
4642

@@ -55,8 +51,6 @@ llvm::getReleaseModeAdvisor(Module &M, ModuleAnalysisManager &MAM) {
5551

5652
#define DEBUG_TYPE "inline-ml"
5753

58-
#if defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
59-
6054
static cl::opt<float> SizeIncreaseThreshold(
6155
"ml-advisor-size-increase-threshold", cl::Hidden,
6256
cl::desc("Maximum factor by which expected native size may increase before "
@@ -417,4 +411,3 @@ void MLInlineAdvice::recordUnattemptedInliningImpl() {
417411
return R;
418412
});
419413
}
420-
#endif // defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)

llvm/lib/CodeGen/MLRegallocEvictAdvisor.cpp

+9-13
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@
4242
using namespace llvm;
4343

4444
#define DEBUG_TYPE "ml-regalloc"
45-
#ifdef LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL
46-
#define LLVM_HAVE_TF_AOT
47-
#endif
45+
4846
// Generated header in release (AOT) mode
49-
#if defined LLVM_HAVE_TF_AOT
47+
#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
5048
#include "RegallocEvictModel.h"
5149
#endif
5250

@@ -104,7 +102,6 @@ INITIALIZE_PASS(RegAllocScoring, "regallocscoringpass",
104102
// ===================================
105103
// Common ML Advisor declarations
106104
// ===================================
107-
#if defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
108105
namespace {
109106
// This is the maximum number of interfererring ranges. That's the number of
110107
// distinct AllocationOrder values, which comes from MCRegisterClass::RegsSize.
@@ -193,7 +190,9 @@ static const std::vector<int64_t> PerLiveRangeShape{1, NumberOfInterferences};
193190
// of the output tensor.
194191
// The contract with the model is that the output will be guaranteed to be to a
195192
// mask == 1 position.
196-
const char *const DecisionName = "index_to_evict";
193+
// Using a macro here to avoid 'not used' warnings (and keep cond compilation to
194+
// a minimum)
195+
#define DecisionName "index_to_evict"
197196

198197
// Named features index.
199198
enum FeatureIDs {
@@ -296,13 +295,12 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
296295
// ===================================
297296
// Release (AOT) - specifics
298297
// ===================================
299-
#ifdef LLVM_HAVE_TF_AOT
298+
#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
300299
const std::array<std::string, FeatureIDs::FeatureCount> FeatureNames{
301300
#define _GETNAME(_, NAME, __, ___) #NAME,
302301
RA_EVICT_FEATURES_LIST(_GETNAME)
303302
#undef _GETNAME
304303
};
305-
306304
class ReleaseModeEvictionAdvisorAnalysis final
307305
: public RegAllocEvictionAdvisorAnalysis {
308306
public:
@@ -331,7 +329,7 @@ class ReleaseModeEvictionAdvisorAnalysis final
331329
}
332330
std::unique_ptr<ReleaseModeModelRunner<RegallocEvictModel>> Runner;
333331
};
334-
#endif // LLVM_HAVE_TF_AOT
332+
#endif
335333

336334
// ===================================
337335
// Development mode-specifics
@@ -852,13 +850,11 @@ bool RegAllocScoring::runOnMachineFunction(MachineFunction &MF) {
852850
}
853851
#endif // #ifdef LLVM_HAVE_TF_API
854852

855-
// Release mode specific implementations
856-
#if defined LLVM_HAVE_TF_AOT
853+
#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
857854
RegAllocEvictionAdvisorAnalysis *llvm::createReleaseModeAdvisor() {
858855
return new ReleaseModeEvictionAdvisorAnalysis();
859856
}
860-
#endif // defined(LLVM_HAVE_TF_AOT)
861-
#endif // defined(LLVM_HAVE_TF_AOT) || defined(LLVM_HAVE_TF_API)
857+
#endif
862858

863859
// In all cases except development mode, we don't need scoring.
864860
#if !defined(LLVM_HAVE_TF_API)

0 commit comments

Comments
 (0)