Skip to content

Commit 20a22a4

Browse files
[MLGO] Remove Extra Dev Mode Features (#167273)
These essentially embedded the MIR into tensors that we could then process on the ML side. We have not used this for any experimentation in the past year or two and the work has largely been superseded by MIR2Vec, which is what we are going to experiment with going forward.
1 parent 7171a9c commit 20a22a4

File tree

2 files changed

+8
-146
lines changed

2 files changed

+8
-146
lines changed

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 8 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,6 @@ static cl::opt<std::string> ModelUnderTraining(
8383
"regalloc-model", cl::Hidden,
8484
cl::desc("The model being trained for register allocation eviction"));
8585

86-
static cl::opt<bool> EnableDevelopmentFeatures(
87-
"regalloc-enable-development-features", cl::Hidden,
88-
cl::desc("Whether or not to enable features under development for the ML "
89-
"regalloc advisor"));
90-
91-
#else
92-
static const bool EnableDevelopmentFeatures = false;
9386
#endif // #ifdef LLVM_HAVE_TFLITE
9487

9588
/// The score injection pass.
@@ -212,23 +205,6 @@ static const std::vector<int64_t> PerLiveRangeShape{1, NumberOfInterferences};
212205
"lowest stage of an interval in this LR") \
213206
M(float, progress, {1}, "ratio of current queue size to initial size")
214207

215-
#ifdef LLVM_HAVE_TFLITE
216-
#define RA_EVICT_FIRST_DEVELOPMENT_FEATURE(M) \
217-
M(int64_t, instructions, InstructionsShape, \
218-
"Opcodes of the instructions covered by the eviction problem")
219-
220-
#define RA_EVICT_REST_DEVELOPMENT_FEATURES(M) \
221-
M(int64_t, instructions_mapping, InstructionsMappingShape, \
222-
"A binary matrix mapping LRs to instruction opcodes") \
223-
M(float, mbb_frequencies, MBBFrequencyShape, \
224-
"A vector of machine basic block frequencies") \
225-
M(int64_t, mbb_mapping, InstructionsShape, \
226-
"A vector of indices mapping instructions to MBBs")
227-
#else
228-
#define RA_EVICT_FIRST_DEVELOPMENT_FEATURE(M)
229-
#define RA_EVICT_REST_DEVELOPMENT_FEATURES(M)
230-
#endif
231-
232208
// The model learns to pick one of the mask == 1 interferences. This is the
233209
// name of the output tensor. The contract with the model is that the output
234210
// will be guaranteed to be to a mask == 1 position. Using a macro here to
@@ -242,12 +218,6 @@ enum FeatureIDs {
242218
#define _FEATURE_IDX_SIMPLE(_, name, __, ___) name
243219
#define _FEATURE_IDX(A, B, C, D) _FEATURE_IDX_SIMPLE(A, B, C, D),
244220
RA_EVICT_FEATURES_LIST(_FEATURE_IDX) FeatureCount,
245-
#ifdef LLVM_HAVE_TFLITE
246-
RA_EVICT_FIRST_DEVELOPMENT_FEATURE(_FEATURE_IDX_SIMPLE) = FeatureCount,
247-
#else
248-
RA_EVICT_FIRST_DEVELOPMENT_FEATURE(_FEATURE_IDX)
249-
#endif // #ifdef LLVM_HAVE_TFLITE
250-
RA_EVICT_REST_DEVELOPMENT_FEATURES(_FEATURE_IDX) FeaturesWithDevelopmentCount
251221
#undef _FEATURE_IDX
252222
#undef _FEATURE_IDX_SIMPLE
253223
};
@@ -268,11 +238,7 @@ void resetInputs(MLModelRunner &Runner) {
268238
std::memset(Runner.getTensorUntyped(FeatureIDs::NAME), 0, \
269239
getTotalSize<TYPE>(SHAPE));
270240
RA_EVICT_FEATURES_LIST(_RESET)
271-
if (EnableDevelopmentFeatures) {
272-
RA_EVICT_FIRST_DEVELOPMENT_FEATURE(_RESET)
273-
RA_EVICT_REST_DEVELOPMENT_FEATURES(_RESET)
274241
#undef _RESET
275-
}
276242
}
277243

278244
// Per-live interval components that get aggregated into the feature values
@@ -398,13 +364,7 @@ class ReleaseModeEvictionAdvisorProvider final
398364
public:
399365
ReleaseModeEvictionAdvisorProvider(LLVMContext &Ctx)
400366
: RegAllocEvictionAdvisorProvider(AdvisorMode::Release, Ctx) {
401-
if (EnableDevelopmentFeatures) {
402-
InputFeatures = {RA_EVICT_FEATURES_LIST(
403-
_DECL_FEATURES) RA_EVICT_FIRST_DEVELOPMENT_FEATURE(_DECL_FEATURES)
404-
RA_EVICT_REST_DEVELOPMENT_FEATURES(_DECL_FEATURES)};
405-
} else {
406-
InputFeatures = {RA_EVICT_FEATURES_LIST(_DECL_FEATURES)};
407-
}
367+
InputFeatures = {RA_EVICT_FEATURES_LIST(_DECL_FEATURES)};
408368
}
409369
// support for isa<> and dyn_cast.
410370
static bool classof(const RegAllocEvictionAdvisorProvider *R) {
@@ -500,25 +460,12 @@ class DevelopmentModeEvictionAdvisorProvider final
500460
public:
501461
DevelopmentModeEvictionAdvisorProvider(LLVMContext &Ctx)
502462
: RegAllocEvictionAdvisorProvider(AdvisorMode::Development, Ctx) {
503-
if (EnableDevelopmentFeatures) {
504-
InputFeatures = {RA_EVICT_FEATURES_LIST(
505-
_DECL_FEATURES) RA_EVICT_FIRST_DEVELOPMENT_FEATURE(_DECL_FEATURES)
506-
RA_EVICT_REST_DEVELOPMENT_FEATURES(_DECL_FEATURES)};
507-
TrainingInputFeatures = {
508-
RA_EVICT_FEATURES_LIST(_DECL_TRAIN_FEATURES)
509-
RA_EVICT_FIRST_DEVELOPMENT_FEATURE(_DECL_TRAIN_FEATURES)
510-
RA_EVICT_REST_DEVELOPMENT_FEATURES(_DECL_TRAIN_FEATURES)
511-
TensorSpec::createSpec<float>("action_discount", {1}),
512-
TensorSpec::createSpec<int32_t>("action_step_type", {1}),
513-
TensorSpec::createSpec<float>("action_reward", {1})};
514-
} else {
515-
InputFeatures = {RA_EVICT_FEATURES_LIST(_DECL_FEATURES)};
516-
TrainingInputFeatures = {
517-
RA_EVICT_FEATURES_LIST(_DECL_TRAIN_FEATURES)
518-
TensorSpec::createSpec<float>("action_discount", {1}),
519-
TensorSpec::createSpec<int32_t>("action_step_type", {1}),
520-
TensorSpec::createSpec<float>("action_reward", {1})};
521-
}
463+
InputFeatures = {RA_EVICT_FEATURES_LIST(_DECL_FEATURES)};
464+
TrainingInputFeatures = {
465+
RA_EVICT_FEATURES_LIST(_DECL_TRAIN_FEATURES)
466+
TensorSpec::createSpec<float>("action_discount", {1}),
467+
TensorSpec::createSpec<int32_t>("action_step_type", {1}),
468+
TensorSpec::createSpec<float>("action_reward", {1})};
522469
if (ModelUnderTraining.empty() && TrainingLog.empty()) {
523470
Ctx.emitError("Regalloc development mode should be requested with at "
524471
"least logging enabled and/or a training model");
@@ -814,34 +761,6 @@ MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
814761
/*NumUrgent*/ 0.0, LRPosInfo);
815762
assert(InitialQSize > 0.0 && "We couldn't have gotten here if we had "
816763
"nothing to allocate initially.");
817-
#ifdef LLVM_HAVE_TFLITE
818-
if (EnableDevelopmentFeatures) {
819-
extractInstructionFeatures(
820-
LRPosInfo, Runner,
821-
[this](SlotIndex InputIndex) -> int {
822-
auto *CurrentMachineInstruction =
823-
LIS->getInstructionFromIndex(InputIndex);
824-
if (!CurrentMachineInstruction) {
825-
return -1;
826-
}
827-
return CurrentMachineInstruction->getOpcode();
828-
},
829-
[this](SlotIndex InputIndex) -> float {
830-
auto *CurrentMachineInstruction =
831-
LIS->getInstructionFromIndex(InputIndex);
832-
return MBFI.getBlockFreqRelativeToEntryBlock(
833-
CurrentMachineInstruction->getParent());
834-
},
835-
[this](SlotIndex InputIndex) -> MachineBasicBlock * {
836-
auto *CurrentMachineInstruction =
837-
LIS->getInstructionFromIndex(InputIndex);
838-
return CurrentMachineInstruction->getParent();
839-
},
840-
FeatureIDs::instructions, FeatureIDs::instructions_mapping,
841-
FeatureIDs::mbb_frequencies, FeatureIDs::mbb_mapping,
842-
LIS->getSlotIndexes()->getLastIndex());
843-
}
844-
#endif // #ifdef LLVM_HAVE_TFLITE
845764
// Normalize the features.
846765
for (auto &V : Largest)
847766
V = V ? V : 1.0;
@@ -987,13 +906,6 @@ void MLEvictAdvisor::extractFeatures(
987906

988907
HintWeights += LIFC.HintWeights;
989908
NumRematerializable += LIFC.IsRemat;
990-
991-
if (EnableDevelopmentFeatures) {
992-
for (auto CurrentSegment : LI) {
993-
LRPosInfo.push_back(
994-
LRStartEndInfo{CurrentSegment.start, CurrentSegment.end, Pos});
995-
}
996-
}
997909
}
998910
size_t Size = 0;
999911
if (!Intervals.empty()) {
@@ -1209,9 +1121,7 @@ int64_t DevelopmentModeEvictAdvisor::tryFindEvictionCandidatePosition(
12091121

12101122
Log->startObservation();
12111123
size_t CurrentFeature = 0;
1212-
size_t FeatureCount = EnableDevelopmentFeatures
1213-
? FeatureIDs::FeaturesWithDevelopmentCount
1214-
: FeatureIDs::FeatureCount;
1124+
size_t FeatureCount = FeatureIDs::FeatureCount;
12151125
for (; CurrentFeature < FeatureCount; ++CurrentFeature) {
12161126
Log->logTensorValue(CurrentFeature,
12171127
reinterpret_cast<const char *>(

llvm/test/CodeGen/MLRegAlloc/dev-mode-extra-features-logging.ll

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)