Skip to content

Commit 472e4ab

Browse files
[MLGO] Fully Remove MLRegalloc Experimental Features (#168252)
20a22a4 was supposed to fully remove these, but left around the functionality to actually compute them and a unittest that ensured they worked. These are not development features in the sense of features used in development mode, but experimental features that have been superseded by MIR2Vec.
1 parent 1425d75 commit 472e4ab

File tree

3 files changed

+0
-431
lines changed

3 files changed

+0
-431
lines changed

llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,6 @@ INITIALIZE_PASS(RegAllocScoring, "regallocscoringpass",
133133
// Common ML Advisor declarations
134134
// ===================================
135135
namespace {
136-
// The model can only accept a specified number of opcodes and will error it if
137-
// fed an opcode it hasn't seen before. This constant sets the current cutoff.
138-
static const int OpcodeValueCutoff = 17716;
139-
140136
// Most features are as described above, so we'll reuse this vector in defining
141137
// them.
142138
static const std::vector<int64_t> PerLiveRangeShape{1, NumberOfInterferences};
@@ -948,139 +944,6 @@ void MLEvictAdvisor::extractFeatures(
948944
#undef SET
949945
}
950946

951-
void llvm::extractInstructionFeatures(
952-
SmallVectorImpl<LRStartEndInfo> &LRPosInfo, MLModelRunner *RegallocRunner,
953-
function_ref<int(SlotIndex)> GetOpcode,
954-
function_ref<float(SlotIndex)> GetMBBFreq,
955-
function_ref<MachineBasicBlock *(SlotIndex)> GetMBBReference,
956-
const int InstructionsIndex, const int InstructionsMappingIndex,
957-
const int MBBFreqIndex, const int MBBMappingIndex,
958-
const SlotIndex LastIndex) {
959-
// This function extracts instruction based features relevant to the eviction
960-
// problem currently being solved. This function ends up extracting two
961-
// tensors.
962-
// 1 - A vector of size max instruction count. It contains the opcodes of the
963-
// instructions spanned by all the intervals in the current instance of the
964-
// eviction problem.
965-
// 2 - A binary mapping matrix of size (LR count * max
966-
// instruction count) which maps where the LRs are live to the actual opcodes
967-
// for which they are live.
968-
// 3 - A vector of size max supported MBB count storing MBB frequencies,
969-
// encompassing all of the MBBs covered by the eviction problem.
970-
// 4 - A vector of size max instruction count of indices to members of the MBB
971-
// frequency vector, mapping each instruction to its associated MBB.
972-
973-
// Start off by sorting the segments based on the beginning slot index.
974-
std::sort(
975-
LRPosInfo.begin(), LRPosInfo.end(),
976-
[](LRStartEndInfo A, LRStartEndInfo B) { return A.Begin < B.Begin; });
977-
size_t InstructionIndex = 0;
978-
size_t CurrentSegmentIndex = 0;
979-
SlotIndex CurrentIndex = LRPosInfo[0].Begin;
980-
std::map<MachineBasicBlock *, size_t> VisitedMBBs;
981-
size_t CurrentMBBIndex = 0;
982-
// This loop processes all the segments sequentially by starting at the
983-
// beginning slot index of the first segment, iterating through all the slot
984-
// indices before the end slot index of that segment (while checking for
985-
// overlaps with segments that start at greater slot indices). After hitting
986-
// that end index, the current segment being processed gets bumped until they
987-
// are all processed or the max instruction count is hit, where everything is
988-
// just truncated.
989-
while (true) {
990-
// If the index that we are currently at is within the current segment and
991-
// we haven't hit the max instruction count, continue processing the current
992-
// segment.
993-
while (CurrentIndex <= LRPosInfo[CurrentSegmentIndex].End &&
994-
InstructionIndex < ModelMaxSupportedInstructionCount) {
995-
int CurrentOpcode = GetOpcode(CurrentIndex);
996-
// If the current machine instruction is null, skip it
997-
if (CurrentOpcode == -1) {
998-
// If we're currently at the last index in the SlotIndex analysis,
999-
// we can't go any further, so return from the function
1000-
if (CurrentIndex >= LastIndex) {
1001-
return;
1002-
}
1003-
CurrentIndex = CurrentIndex.getNextIndex();
1004-
continue;
1005-
}
1006-
MachineBasicBlock *CurrentMBBReference = GetMBBReference(CurrentIndex);
1007-
if (VisitedMBBs.count(CurrentMBBReference) == 0) {
1008-
VisitedMBBs[CurrentMBBReference] = CurrentMBBIndex;
1009-
++CurrentMBBIndex;
1010-
}
1011-
extractMBBFrequency(CurrentIndex, InstructionIndex, VisitedMBBs,
1012-
GetMBBFreq, CurrentMBBReference, RegallocRunner,
1013-
MBBFreqIndex, MBBMappingIndex);
1014-
// Current code assumes we're not going to get any disjointed segments
1015-
assert(LRPosInfo[CurrentSegmentIndex].Begin <= CurrentIndex);
1016-
RegallocRunner->getTensor<int64_t>(InstructionsIndex)[InstructionIndex] =
1017-
CurrentOpcode < OpcodeValueCutoff ? CurrentOpcode : 0;
1018-
// set value in the binary mapping matrix for the current instruction
1019-
auto CurrentSegmentPosition = LRPosInfo[CurrentSegmentIndex].Pos;
1020-
RegallocRunner->getTensor<int64_t>(
1021-
InstructionsMappingIndex)[CurrentSegmentPosition *
1022-
ModelMaxSupportedInstructionCount +
1023-
InstructionIndex] = 1;
1024-
// All of the segments are sorted based on the beginning slot index, but
1025-
// this doesn't mean that the beginning slot index of the next segment is
1026-
// after the end segment of the one being currently processed. This while
1027-
// loop checks for overlapping segments and modifies the portion of the
1028-
// column in the mapping matrix for the currently processed instruction
1029-
// for the LR it is checking. Also make sure that the beginning of the
1030-
// current segment we're checking for overlap in is less than the current
1031-
// index, otherwise we're done checking overlaps.
1032-
size_t OverlapCheckCurrentSegment = CurrentSegmentIndex + 1;
1033-
while (OverlapCheckCurrentSegment < LRPosInfo.size() &&
1034-
LRPosInfo[OverlapCheckCurrentSegment].Begin <= CurrentIndex) {
1035-
auto OverlapCurrentSegmentPosition =
1036-
LRPosInfo[OverlapCheckCurrentSegment].Pos;
1037-
if (LRPosInfo[OverlapCheckCurrentSegment].End >= CurrentIndex) {
1038-
RegallocRunner->getTensor<int64_t>(
1039-
InstructionsMappingIndex)[OverlapCurrentSegmentPosition *
1040-
ModelMaxSupportedInstructionCount +
1041-
InstructionIndex] = 1;
1042-
}
1043-
++OverlapCheckCurrentSegment;
1044-
}
1045-
++InstructionIndex;
1046-
if (CurrentIndex >= LastIndex) {
1047-
return;
1048-
}
1049-
CurrentIndex = CurrentIndex.getNextIndex();
1050-
}
1051-
// if we've just finished processing through the last segment or if we've
1052-
// hit the maximum number of instructions, break out of the loop.
1053-
if (CurrentSegmentIndex == LRPosInfo.size() - 1 ||
1054-
InstructionIndex >= ModelMaxSupportedInstructionCount) {
1055-
break;
1056-
}
1057-
// If the segments are not overlapping, we need to move to the beginning
1058-
// index of the next segment to avoid having instructions not attached to
1059-
// any register.
1060-
if (LRPosInfo[CurrentSegmentIndex + 1].Begin >
1061-
LRPosInfo[CurrentSegmentIndex].End) {
1062-
CurrentIndex = LRPosInfo[CurrentSegmentIndex + 1].Begin;
1063-
}
1064-
++CurrentSegmentIndex;
1065-
}
1066-
}
1067-
1068-
void llvm::extractMBBFrequency(
1069-
const SlotIndex CurrentIndex, const size_t CurrentInstructionIndex,
1070-
std::map<MachineBasicBlock *, size_t> &VisitedMBBs,
1071-
function_ref<float(SlotIndex)> GetMBBFreq,
1072-
MachineBasicBlock *CurrentMBBReference, MLModelRunner *RegallocRunner,
1073-
const int MBBFreqIndex, const int MBBMappingIndex) {
1074-
size_t CurrentMBBIndex = VisitedMBBs[CurrentMBBReference];
1075-
float CurrentMBBFreq = GetMBBFreq(CurrentIndex);
1076-
if (CurrentMBBIndex < ModelMaxSupportedMBBCount) {
1077-
RegallocRunner->getTensor<float>(MBBFreqIndex)[CurrentMBBIndex] =
1078-
CurrentMBBFreq;
1079-
RegallocRunner->getTensor<int64_t>(
1080-
MBBMappingIndex)[CurrentInstructionIndex] = CurrentMBBIndex;
1081-
}
1082-
}
1083-
1084947
// Development mode-specific implementations
1085948
#ifdef LLVM_HAVE_TFLITE
1086949

llvm/unittests/CodeGen/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ add_llvm_unittest(CodeGenTests
4949
TypeTraitsTest.cpp
5050
TargetOptionsTest.cpp
5151
TestAsmPrinter.cpp
52-
MLRegAllocDevelopmentFeatures.cpp
5352
X86MCInstLowerTest.cpp
5453
)
5554

0 commit comments

Comments
 (0)