summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp')
-rw-r--r--llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp137
1 files changed, 0 insertions, 137 deletions
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 32b6c4630382..34531dd7ab17 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -133,10 +133,6 @@ INITIALIZE_PASS(RegAllocScoring, "regallocscoringpass",
// Common ML Advisor declarations
// ===================================
namespace {
-// The model can only accept a specified number of opcodes and will error it if
-// fed an opcode it hasn't seen before. This constant sets the current cutoff.
-static const int OpcodeValueCutoff = 17716;
-
// Most features are as described above, so we'll reuse this vector in defining
// them.
static const std::vector<int64_t> PerLiveRangeShape{1, NumberOfInterferences};
@@ -948,139 +944,6 @@ void MLEvictAdvisor::extractFeatures(
#undef SET
}
-void llvm::extractInstructionFeatures(
- SmallVectorImpl<LRStartEndInfo> &LRPosInfo, MLModelRunner *RegallocRunner,
- function_ref<int(SlotIndex)> GetOpcode,
- function_ref<float(SlotIndex)> GetMBBFreq,
- function_ref<MachineBasicBlock *(SlotIndex)> GetMBBReference,
- const int InstructionsIndex, const int InstructionsMappingIndex,
- const int MBBFreqIndex, const int MBBMappingIndex,
- const SlotIndex LastIndex) {
- // This function extracts instruction based features relevant to the eviction
- // problem currently being solved. This function ends up extracting two
- // tensors.
- // 1 - A vector of size max instruction count. It contains the opcodes of the
- // instructions spanned by all the intervals in the current instance of the
- // eviction problem.
- // 2 - A binary mapping matrix of size (LR count * max
- // instruction count) which maps where the LRs are live to the actual opcodes
- // for which they are live.
- // 3 - A vector of size max supported MBB count storing MBB frequencies,
- // encompassing all of the MBBs covered by the eviction problem.
- // 4 - A vector of size max instruction count of indices to members of the MBB
- // frequency vector, mapping each instruction to its associated MBB.
-
- // Start off by sorting the segments based on the beginning slot index.
- std::sort(
- LRPosInfo.begin(), LRPosInfo.end(),
- [](LRStartEndInfo A, LRStartEndInfo B) { return A.Begin < B.Begin; });
- size_t InstructionIndex = 0;
- size_t CurrentSegmentIndex = 0;
- SlotIndex CurrentIndex = LRPosInfo[0].Begin;
- std::map<MachineBasicBlock *, size_t> VisitedMBBs;
- size_t CurrentMBBIndex = 0;
- // This loop processes all the segments sequentially by starting at the
- // beginning slot index of the first segment, iterating through all the slot
- // indices before the end slot index of that segment (while checking for
- // overlaps with segments that start at greater slot indices). After hitting
- // that end index, the current segment being processed gets bumped until they
- // are all processed or the max instruction count is hit, where everything is
- // just truncated.
- while (true) {
- // If the index that we are currently at is within the current segment and
- // we haven't hit the max instruction count, continue processing the current
- // segment.
- while (CurrentIndex <= LRPosInfo[CurrentSegmentIndex].End &&
- InstructionIndex < ModelMaxSupportedInstructionCount) {
- int CurrentOpcode = GetOpcode(CurrentIndex);
- // If the current machine instruction is null, skip it
- if (CurrentOpcode == -1) {
- // If we're currently at the last index in the SlotIndex analysis,
- // we can't go any further, so return from the function
- if (CurrentIndex >= LastIndex) {
- return;
- }
- CurrentIndex = CurrentIndex.getNextIndex();
- continue;
- }
- MachineBasicBlock *CurrentMBBReference = GetMBBReference(CurrentIndex);
- if (VisitedMBBs.count(CurrentMBBReference) == 0) {
- VisitedMBBs[CurrentMBBReference] = CurrentMBBIndex;
- ++CurrentMBBIndex;
- }
- extractMBBFrequency(CurrentIndex, InstructionIndex, VisitedMBBs,
- GetMBBFreq, CurrentMBBReference, RegallocRunner,
- MBBFreqIndex, MBBMappingIndex);
- // Current code assumes we're not going to get any disjointed segments
- assert(LRPosInfo[CurrentSegmentIndex].Begin <= CurrentIndex);
- RegallocRunner->getTensor<int64_t>(InstructionsIndex)[InstructionIndex] =
- CurrentOpcode < OpcodeValueCutoff ? CurrentOpcode : 0;
- // set value in the binary mapping matrix for the current instruction
- auto CurrentSegmentPosition = LRPosInfo[CurrentSegmentIndex].Pos;
- RegallocRunner->getTensor<int64_t>(
- InstructionsMappingIndex)[CurrentSegmentPosition *
- ModelMaxSupportedInstructionCount +
- InstructionIndex] = 1;
- // All of the segments are sorted based on the beginning slot index, but
- // this doesn't mean that the beginning slot index of the next segment is
- // after the end segment of the one being currently processed. This while
- // loop checks for overlapping segments and modifies the portion of the
- // column in the mapping matrix for the currently processed instruction
- // for the LR it is checking. Also make sure that the beginning of the
- // current segment we're checking for overlap in is less than the current
- // index, otherwise we're done checking overlaps.
- size_t OverlapCheckCurrentSegment = CurrentSegmentIndex + 1;
- while (OverlapCheckCurrentSegment < LRPosInfo.size() &&
- LRPosInfo[OverlapCheckCurrentSegment].Begin <= CurrentIndex) {
- auto OverlapCurrentSegmentPosition =
- LRPosInfo[OverlapCheckCurrentSegment].Pos;
- if (LRPosInfo[OverlapCheckCurrentSegment].End >= CurrentIndex) {
- RegallocRunner->getTensor<int64_t>(
- InstructionsMappingIndex)[OverlapCurrentSegmentPosition *
- ModelMaxSupportedInstructionCount +
- InstructionIndex] = 1;
- }
- ++OverlapCheckCurrentSegment;
- }
- ++InstructionIndex;
- if (CurrentIndex >= LastIndex) {
- return;
- }
- CurrentIndex = CurrentIndex.getNextIndex();
- }
- // if we've just finished processing through the last segment or if we've
- // hit the maximum number of instructions, break out of the loop.
- if (CurrentSegmentIndex == LRPosInfo.size() - 1 ||
- InstructionIndex >= ModelMaxSupportedInstructionCount) {
- break;
- }
- // If the segments are not overlapping, we need to move to the beginning
- // index of the next segment to avoid having instructions not attached to
- // any register.
- if (LRPosInfo[CurrentSegmentIndex + 1].Begin >
- LRPosInfo[CurrentSegmentIndex].End) {
- CurrentIndex = LRPosInfo[CurrentSegmentIndex + 1].Begin;
- }
- ++CurrentSegmentIndex;
- }
-}
-
-void llvm::extractMBBFrequency(
- const SlotIndex CurrentIndex, const size_t CurrentInstructionIndex,
- std::map<MachineBasicBlock *, size_t> &VisitedMBBs,
- function_ref<float(SlotIndex)> GetMBBFreq,
- MachineBasicBlock *CurrentMBBReference, MLModelRunner *RegallocRunner,
- const int MBBFreqIndex, const int MBBMappingIndex) {
- size_t CurrentMBBIndex = VisitedMBBs[CurrentMBBReference];
- float CurrentMBBFreq = GetMBBFreq(CurrentIndex);
- if (CurrentMBBIndex < ModelMaxSupportedMBBCount) {
- RegallocRunner->getTensor<float>(MBBFreqIndex)[CurrentMBBIndex] =
- CurrentMBBFreq;
- RegallocRunner->getTensor<int64_t>(
- MBBMappingIndex)[CurrentInstructionIndex] = CurrentMBBIndex;
- }
-}
-
// Development mode-specific implementations
#ifdef LLVM_HAVE_TFLITE