| 1 | //===- MLRegAllocEvictAdvisor.cpp - ML eviction advisor -------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // Function declarations of utilities related to feature extraction for unit |
| 10 | // testing. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_MLREGALLOCEVICTIONADVISOR_H |
| 15 | #define LLVM_CODEGEN_MLREGALLOCEVICTIONADVISOR_H |
| 16 | |
| 17 | #include "llvm/Analysis/MLModelRunner.h" |
| 18 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 19 | #include "llvm/CodeGen/SlotIndexes.h" |
| 20 | #include "llvm/Support/Compiler.h" |
| 21 | #include <map> |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | // LRStartEndInfo contains the start and end of a specific live range as |
| 26 | // slot indices as well as storing the index of the physical register it |
| 27 | // is assigned to (or 1 above the phys reg count if its the candidate). |
| 28 | // Used when extracting per-instruction features in the context of a |
| 29 | // specific eviction problem. |
| 30 | struct LRStartEndInfo { |
| 31 | SlotIndex Begin; |
| 32 | SlotIndex End; |
| 33 | size_t Pos = 0; |
| 34 | }; |
| 35 | |
| 36 | // The number of instructions that a specific live range might have is variable, |
| 37 | // but we're passing in a single matrix of instructions and tensorflow saved |
| 38 | // models only support a fixed input size, so we have to cap the number of |
| 39 | // instructions that can be passed along. The specific value was derived from |
| 40 | // experimentation such that the majority of eviction problems would be |
| 41 | // completely covered. |
| 42 | static const int ModelMaxSupportedInstructionCount = 300; |
| 43 | |
| 44 | // When extracting per-instruction features, the advisor will currently create |
| 45 | // a vector of size ModelMaxSupportedInstructionCount to hold the opcodes of the |
| 46 | // instructions relevant to the eviction problem. |
| 47 | static const std::vector<int64_t> InstructionsShape{ |
| 48 | 1, ModelMaxSupportedInstructionCount}; |
| 49 | |
| 50 | // When extracting mappings between MBBs and individual instructions, we create |
| 51 | // a vector of MBB frequencies, currently of size 100, which was a value |
| 52 | // determined through experimentation to encompass the vast majority of eviction |
| 53 | // problems. The actual mapping is the same shape as the instruction opcodes |
| 54 | // vector. |
| 55 | static const int64_t ModelMaxSupportedMBBCount = 100; |
| 56 | static const std::vector<int64_t> MBBFrequencyShape{1, |
| 57 | ModelMaxSupportedMBBCount}; |
| 58 | |
| 59 | } // namespace llvm |
| 60 | |
| 61 | #endif // LLVM_CODEGEN_MLREGALLOCEVICTIONADVISOR_H |
| 62 | |