19#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL) || defined(LLVM_HAVE_TFLITE)
48#define DEBUG_TYPE "ml-regalloc"
51#if defined(LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL)
52#include "RegAllocEvictModel.h"
59 "regalloc-evict-interactive-channel-base",
cl::Hidden,
61 "Base file path for the interactive mode. The incoming filename should "
62 "have the name <regalloc-evict-interactive-channel-base>.in, while the "
63 "outgoing name should be "
64 "<regalloc-evict-interactive-channel-base>.out"));
68 cl::desc(
"The maximum number of times a live range can be "
69 "evicted before preventing it from being evicted"),
73#ifdef LLVM_HAVE_TFLITE
79 cl::desc(
"Training log for the register allocator eviction model"));
83 cl::desc(
"The model being trained for register allocation eviction"));
99 RegAllocScoring() : MachineFunctionPass(ID) {}
101 ~RegAllocScoring()
override =
default;
103 StringRef getPassName()
const override {
104 return "Register Allocation Pass Scoring";
108 void getAnalysisUsage(AnalysisUsage &AU)
const override {
110 AU.
addRequired<RegAllocEvictionAdvisorAnalysisLegacy>();
111 AU.
addRequired<RegAllocPriorityAdvisorAnalysisLegacy>();
112 AU.
addRequired<MachineBlockFrequencyInfoWrapperPass>();
117 bool runOnMachineFunction(MachineFunction &)
override;
121char RegAllocScoring::ID = 0;
123 return new RegAllocScoring();
127 "Register Allocation Scoring Pass",
false,
false)
155#define RA_EVICT_FEATURES_LIST(M) \
156 M(int64_t, mask, PerLiveRangeShape, \
157 "boolean values, 0 for unavailable candidates (i.e. if a position is 0, " \
159 "can't be evicted)") \
160 M(int64_t, is_free, PerLiveRangeShape, \
161 "boolean values, 1 if this phys reg is actually free (no interferences)") \
162 M(float, nr_urgent, PerLiveRangeShape, \
163 "number of 'urgent' intervals, normalized. Urgent are those that are OK " \
164 "to break cascades") \
165 M(float, nr_broken_hints, PerLiveRangeShape, \
166 "if this position were evicted, how many broken hints would there be") \
167 M(int64_t, is_hint, PerLiveRangeShape, \
168 "is this a preferred phys reg for the candidate") \
169 M(int64_t, is_local, PerLiveRangeShape, \
170 "is this live range local to a basic block") \
171 M(float, nr_rematerializable, PerLiveRangeShape, \
172 "nr rematerializable ranges") \
173 M(float, nr_defs_and_uses, PerLiveRangeShape, \
174 "bb freq - weighed nr defs and uses") \
175 M(float, weighed_reads_by_max, PerLiveRangeShape, \
176 "bb freq - weighed nr of reads, normalized") \
177 M(float, weighed_writes_by_max, PerLiveRangeShape, \
178 "bb feq - weighed nr of writes, normalized") \
179 M(float, weighed_read_writes_by_max, PerLiveRangeShape, \
180 "bb freq - weighed nr of uses that are both read and writes, normalized") \
181 M(float, weighed_indvars_by_max, PerLiveRangeShape, \
182 "bb freq - weighed nr of uses that are indvars, normalized") \
183 M(float, hint_weights_by_max, PerLiveRangeShape, \
184 "bb freq - weighed nr of uses that are hints, normalized") \
185 M(float, start_bb_freq_by_max, PerLiveRangeShape, \
186 "the freq in the start block, normalized") \
187 M(float, end_bb_freq_by_max, PerLiveRangeShape, \
188 "freq of end block, normalized") \
189 M(float, hottest_bb_freq_by_max, PerLiveRangeShape, \
190 "hottest BB freq, normalized") \
191 M(float, liverange_size, PerLiveRangeShape, \
192 "size (instr index diff) of the LR") \
193 M(float, use_def_density, PerLiveRangeShape, \
194 "the max weight, as computed by the manual heuristic") \
195 M(int64_t, max_stage, PerLiveRangeShape, \
196 "largest stage of an interval in this LR") \
197 M(int64_t, min_stage, PerLiveRangeShape, \
198 "lowest stage of an interval in this LR") \
199 M(float, progress, {1}, "ratio of current queue size to initial size")
205#define DecisionName "index_to_evict"
211#define _FEATURE_IDX_SIMPLE(_, name, __, ___) name
212#define _FEATURE_IDX(A, B, C, D) _FEATURE_IDX_SIMPLE(A, B, C, D),
215#undef _FEATURE_IDX_SIMPLE
222template <
typename T>
size_t getTotalSize(
const std::vector<int64_t> &Shape) {
223 size_t Ret =
sizeof(
T);
224 for (
const auto V : Shape)
230#define _RESET(TYPE, NAME, SHAPE, __) \
231 std::memset(Runner.getTensorUntyped(FeatureIDs::NAME), 0, \
232 getTotalSize<TYPE>(SHAPE));
239struct LIFeatureComponents {
243 double IndVarUpdates = 0;
244 double HintWeights = 0.0;
245 int64_t NumDefsAndUses = 0;
246 float HottestBlockFreq = 0.0;
247 bool IsRemat =
false;
250using CandidateRegList =
252using FeaturesListNormalizer =
276 tryFindEvictionCandidatePosition(
const LiveInterval &VirtReg,
278 unsigned OrderLimit,
uint8_t CostPerUseLimit,
299 int64_t IsHint, int64_t LocalIntfsCount,
float NumUrgent,
307 return getDefaultAdvisor().canEvictHintInterference(VirtReg, PhysReg,
311 const LIFeatureComponents &
325 std::bitset<FeatureIDs::FeatureCount> DoNotNormalize;
326 const float InitialQSize;
333 void onEviction(
Register RegBeingEvicted)
const {
337 ++VirtRegEvictionCounts[RegBeingEvicted.
id()];
341 auto EvictionCountIt = VirtRegEvictionCounts.
find(
Reg.id());
342 if (EvictionCountIt != VirtRegEvictionCounts.
end())
343 return EvictionCountIt->second;
348#define _DECL_FEATURES(type, name, shape, _) \
349 TensorSpec::createSpec<type>(#name, shape),
355class ReleaseModeEvictionAdvisorProvider final
358 ReleaseModeEvictionAdvisorProvider(
LLVMContext &Ctx)
364 return R->getAdvisorMode() == AdvisorMode::Release;
367 std::unique_ptr<RegAllocEvictionAdvisor>
372 Runner = std::make_unique<ReleaseModeModelRunner<CompiledModelType>>(
375 Runner = std::make_unique<InteractiveModelRunner>(
381 "Invalid provider state: must have analysis available");
382 return std::make_unique<MLEvictAdvisor>(MF,
RA, Runner.get(), *MBFI,
388 std::unique_ptr<MLModelRunner> Runner;
391class ReleaseModeEvictionAdvisorAnalysisLegacy final
394 ReleaseModeEvictionAdvisorAnalysisLegacy()
404 std::make_unique<ReleaseModeEvictionAdvisorProvider>(M.getContext());
409 return R->getAdvisorMode() == AdvisorMode::Release;
424#ifdef LLVM_HAVE_TFLITE
431#define _DECL_TRAIN_FEATURES(type, name, shape, _) \
432 TensorSpec::createSpec<type>(std::string("action_") + #name, shape),
434class DevelopmentModeEvictAdvisor :
public MLEvictAdvisor {
440 : MLEvictAdvisor(MF,
RA, Runner, MBFI,
Loops), Log(Log) {}
443 int64_t tryFindEvictionCandidatePosition(
445 unsigned OrderLimit,
uint8_t CostPerUseLimit,
451class DevelopmentModeEvictionAdvisorProvider final
454 DevelopmentModeEvictionAdvisorProvider(
LLVMContext &Ctx)
457 TrainingInputFeatures = {
462 if (ModelUnderTraining.empty() && TrainingLog.empty()) {
463 Ctx.emitError(
"Regalloc development mode should be requested with at "
464 "least logging enabled and/or a training model");
467 if (ModelUnderTraining.empty())
468 Runner = std::make_unique<NoInferenceModelRunner>(Ctx,
InputFeatures);
470 Runner = ModelUnderTrainingRunner::createAndEnsureValid(
471 Ctx, ModelUnderTraining,
DecisionName, TrainingInputFeatures);
473 Ctx.emitError(
"Regalloc: could not set up the model runner");
476 if (TrainingLog.empty())
479 auto OS = std::make_unique<raw_fd_ostream>(TrainingLog, EC);
481 Ctx.emitError(EC.message() +
":" + TrainingLog);
492 Log = std::make_unique<Logger>(std::move(OS), LFS, Reward,
499 return R->getAdvisorMode() == AdvisorMode::Development;
504 if (!Log || !Log->hasAnyObservationForContext(MF.
getName()))
510 if (Log->currentContext() != MF.
getName()) {
512 "The training log context shouldn't have had changed.");
514 if (Log->hasObservationInProgress())
515 Log->logReward<
float>(GetReward());
518 std::unique_ptr<RegAllocEvictionAdvisor>
524 Log->switchContext(MF.
getName());
526 "Invalid provider state: must have analysis available");
527 return std::make_unique<DevelopmentModeEvictAdvisor>(
528 MF,
RA, Runner.get(), *MBFI, *
Loops, Log.get());
533 std::vector<TensorSpec> TrainingInputFeatures;
535 std::unique_ptr<MLModelRunner> Runner;
536 std::unique_ptr<Logger> Log;
539class DevelopmentModeEvictionAdvisorAnalysisLegacy final
542 DevelopmentModeEvictionAdvisorAnalysisLegacy()
546 Provider = std::make_unique<DevelopmentModeEvictionAdvisorProvider>(
553 Provider->logRewardIfNeeded(MF, GetReward);
558 return R->getAdvisorMode() == AdvisorMode::Development;
573 unsigned NumUsedRegs = 0;
574 for (
unsigned I = 0,
E = MRI.getNumVirtRegs();
I !=
E; ++
I) {
576 if (!MRI.reg_nodbg_empty(
Reg))
579 return static_cast<float>(NumUsedRegs);
588 InitialQSize(MLEvictAdvisor::getInitialQueueSize(MF)) {
591 DoNotNormalize.set(FeatureIDs::mask);
592 DoNotNormalize.set(FeatureIDs::is_free);
593 DoNotNormalize.set(FeatureIDs::is_hint);
594 DoNotNormalize.set(FeatureIDs::is_local);
595 DoNotNormalize.set(FeatureIDs::min_stage);
596 DoNotNormalize.set(FeatureIDs::max_stage);
597 DoNotNormalize.set(FeatureIDs::progress);
600int64_t MLEvictAdvisor::tryFindEvictionCandidatePosition(
603 int64_t Ret = Runner->
evaluate<int64_t>();
609bool MLEvictAdvisor::loadInterferenceFeatures(
620 const bool IsLocal = LIS->intervalIsInOneMBB(VirtReg);
621 int64_t LocalIntfs = 0;
622 float NumUrgent = 0.0f;
625 unsigned Cascade =
RA.getExtraInfo().getCascadeOrCurrentNext(VirtReg.
reg());
628 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
633 if (IFIntervals.empty() && InterferingIntervals.
empty())
637 InterferingIntervals.
append(IFIntervals.begin(), IFIntervals.end());
639 assert(Intf->reg().isVirtual() &&
640 "Only expecting virtual register interference from query");
647 if (FixedRegisters.
count(Intf->reg()))
649 if (
RA.getExtraInfo().getStage(*Intf) ==
RS_Done)
653 (Intf->isSpillable() ||
654 RegClassInfo.getNumAllocatableRegs(MRI->getRegClass(VirtReg.
reg())) <
655 RegClassInfo.getNumAllocatableRegs(
656 MRI->getRegClass(Intf->reg())));
658 unsigned IntfCascade =
RA.getExtraInfo().getCascade(Intf->reg());
669 if (Cascade <= IntfCascade) {
675 LocalIntfs += (IsLocal && LIS->intervalIsInOneMBB(*Intf) &&
676 (!EnableLocalReassign || !canReassign(*Intf, PhysReg)));
681 extractFeatures(InterferingIntervals, Largest, Pos, IsHint, LocalIntfs,
682 NumUrgent, LRPosInfo);
686MCRegister MLEvictAdvisor::tryFindEvictionCandidate(
689 auto MaybeOrderLimit = getOrderLimit(VirtReg, Order, CostPerUseLimit);
690 if (!MaybeOrderLimit)
692 unsigned OrderLimit = *MaybeOrderLimit;
700 const bool MustFindEviction =
706 resetInputs(*Runner);
711 CandidateRegList Regs;
712 Regs.fill({0,
false});
730 assert(!Regs[Pos].second);
732 if (!canAllocatePhysReg(CostPerUseLimit, PhysReg)) {
735 if (loadInterferenceFeatures(VirtReg, PhysReg,
I.isHint(), FixedRegisters,
736 Largest, Pos, LRPosInfo)) {
738 Regs[Pos] = std::make_pair(PhysReg,
true);
743 assert(!MustFindEviction);
746 const size_t ValidPosLimit = Pos;
750 if (!MustFindEviction)
755 assert(InitialQSize > 0.0 &&
"We couldn't have gotten here if we had "
756 "nothing to allocate initially.");
758 for (
auto &V : Largest)
768 *Runner->
getTensor<
float>(FeatureIDs::progress) =
769 static_cast<float>(
RA.getQueueSize()) / InitialQSize;
772 size_t CandidatePos = tryFindEvictionCandidatePosition(
773 VirtReg, Order, OrderLimit, CostPerUseLimit, FixedRegisters);
776 assert(Regs[CandidatePos].second);
778 onEviction(VirtReg.
reg());
779 assert(!MustFindEviction);
782 assert(CandidatePos < ValidPosLimit);
788 for (MCRegUnit Unit :
TRI->regunits(Regs[CandidatePos].first)) {
792 onEviction(Intf->reg());
796 return Regs[CandidatePos].first;
799const LIFeatureComponents &
800MLEvictAdvisor::getLIFeatureComponents(
const LiveInterval &LI)
const {
802 LIFeatureComponents
Empty;
803 auto I = CachedFeatures.insert(std::make_pair(
ID,
Empty));
804 LIFeatureComponents &Ret =
I.first->getSecond();
812 I = MRI->reg_instr_nodbg_begin(LI.
reg()),
813 E = MRI->reg_instr_nodbg_end();
817 ++Ret.NumDefsAndUses;
821 if (
MI->isIdentityCopy() ||
MI->isImplicitDef())
825 std::tie(Reads, Writes) =
MI->readsWritesVirtualRegister(LI.
reg());
828 Ret.HottestBlockFreq = std::max(Freq, Ret.HottestBlockFreq);
830 Ret.R += (Reads && !Writes) * Freq;
831 Ret.W += (!Reads && Writes) * Freq;
832 Ret.RW += (Reads && Writes) * Freq;
834 auto *
MBB =
MI->getParent();
838 if (Writes && IsExiting && LIS->isLiveOutOfMBB(LI,
MBB))
839 Ret.IndVarUpdates += Freq;
842 Ret.HintWeights += Freq;
851void MLEvictAdvisor::extractFeatures(
854 int64_t LocalIntfsCount,
float NumUrgent,
856 int64_t NumDefsAndUses = 0;
857 int64_t NumBrokenHints = 0;
861 double IndVarUpdates = 0.0;
862 double HintWeights = 0.0;
863 float StartBBFreq = 0.0;
864 float EndBBFreq = 0.0;
865 float HottestBlockFreq = 0.0;
866 int32_t NumRematerializable = 0;
867 float TotalWeight = 0.0;
869 SlotIndex EndSI = LIS->getSlotIndexes()->getZeroIndex();
870 SlotIndex StartSI = LIS->getSlotIndexes()->getLastIndex();
871 int64_t MaxStage = 0;
873 Intervals.
empty() ? 0 : std::numeric_limits<int64_t>::max();
875 for (
const auto *L : Intervals) {
877 MaxStage = std::max<int64_t>(
878 MaxStage,
static_cast<int64_t
>(
RA.getExtraInfo().getStage(LI)));
879 MinStage = std::min<int64_t>(
880 MinStage,
static_cast<int64_t
>(
RA.getExtraInfo().getStage(LI)));
882 TotalWeight = std::max(TotalWeight, LI.
weight());
889 const LIFeatureComponents &LIFC = getLIFeatureComponents(LI);
890 NumBrokenHints += VRM->hasPreferredPhys(LI.
reg());
892 NumDefsAndUses += LIFC.NumDefsAndUses;
893 HottestBlockFreq = std::max(HottestBlockFreq, LIFC.HottestBlockFreq);
898 IndVarUpdates += LIFC.IndVarUpdates;
900 HintWeights += LIFC.HintWeights;
901 NumRematerializable += LIFC.IsRemat;
904 if (!Intervals.empty()) {
907 if (EndSI >= LIS->getSlotIndexes()->getLastIndex())
908 EndSI = LIS->getSlotIndexes()->getLastIndex().
getPrevIndex();
914#define SET(ID, TYPE, VAL) \
916 Runner->getTensor<TYPE>(FeatureIDs::ID)[Pos] = static_cast<TYPE>(VAL); \
917 if (!DoNotNormalize.test(FeatureIDs::ID)) \
918 Largest[FeatureIDs::ID] = \
919 std::max(Largest[FeatureIDs::ID], static_cast<float>(VAL)); \
922 SET(is_free, int64_t, Intervals.empty());
923 SET(nr_urgent,
float, NumUrgent);
924 SET(nr_broken_hints,
float, NumBrokenHints);
925 SET(is_hint, int64_t, IsHint);
926 SET(is_local, int64_t, LocalIntfsCount);
927 SET(nr_rematerializable,
float, NumRematerializable);
928 SET(nr_defs_and_uses,
float, NumDefsAndUses);
929 SET(weighed_reads_by_max,
float, R);
930 SET(weighed_writes_by_max,
float, W);
931 SET(weighed_read_writes_by_max,
float, RW);
932 SET(weighed_indvars_by_max,
float, IndVarUpdates);
933 SET(hint_weights_by_max,
float, HintWeights);
934 SET(start_bb_freq_by_max,
float, StartBBFreq);
935 SET(end_bb_freq_by_max,
float, EndBBFreq);
936 SET(hottest_bb_freq_by_max,
float, HottestBlockFreq);
937 SET(liverange_size,
float,
Size);
938 SET(use_def_density,
float, TotalWeight);
939 SET(max_stage, int64_t, MaxStage);
940 SET(min_stage, int64_t, MinStage);
945#ifdef LLVM_HAVE_TFLITE
949 return new DevelopmentModeEvictionAdvisorAnalysisLegacy();
952int64_t DevelopmentModeEvictAdvisor::tryFindEvictionCandidatePosition(
954 unsigned OrderLimit,
uint8_t CostPerUseLimit,
958 Ret = MLEvictAdvisor::tryFindEvictionCandidatePosition(
959 VirtReg, Order, OrderLimit, CostPerUseLimit, FixedRegisters);
961 MCRegister PhysReg = getDefaultAdvisor().tryFindEvictionCandidate(
962 VirtReg, Order, CostPerUseLimit, FixedRegisters);
974 if (TrainingLog.empty())
979 if (
Log->hasObservationInProgress())
980 Log->logReward<
float>(0.0);
982 Log->startObservation();
983 size_t CurrentFeature = 0;
985 for (; CurrentFeature <
FeatureCount; ++CurrentFeature) {
986 Log->logTensorValue(CurrentFeature,
987 reinterpret_cast<const char *
>(
988 getRunner().getTensorUntyped(CurrentFeature)));
991 for (
size_t I = 0;
I < MUTR->extraOutputsForLoggingSpecs().
size();
992 ++
I, ++CurrentFeature)
995 reinterpret_cast<const char *
>(MUTR->getUntypedExtraOutputValue(
I)));
997 Log->logTensorValue(CurrentFeature,
reinterpret_cast<const char *
>(&Ret));
998 Log->endObservation();
1003 std::optional<float> CachedReward;
1004 auto GetReward = [&]() {
1006 CachedReward =
static_cast<float>(
1008 MF, getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI())
1010 return *CachedReward;
1013 getAnalysis<RegAllocEvictionAdvisorAnalysisLegacy>().logRewardIfNeeded(
1015 getAnalysis<RegAllocPriorityAdvisorAnalysisLegacy>().logRewardIfNeeded(
1021RegAllocEvictionAdvisorProvider *
1023 return new ReleaseModeEvictionAdvisorProvider(Ctx);
1028#if defined(LLVM_HAVE_TFLITE)
1029 return new DevelopmentModeEvictionAdvisorProvider(Ctx);
1038 ?
new ReleaseModeEvictionAdvisorAnalysisLegacy()
1043#if !defined(LLVM_HAVE_TFLITE)
1044bool RegAllocScoring::runOnMachineFunction(
MachineFunction &) {
return false; }
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static constexpr unsigned long long mask(BlockVerifier::State S)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
@ Available
We know the block is fully available. This is a fixpoint.
Module.h This file contains the declarations for the Module class.
NoopSavedModelImpl CompiledModelType
static cl::opt< std::string > InteractiveChannelBaseName("inliner-interactive-channel-base", cl::Hidden, cl::desc("Base file path for the interactive mode. The incoming filename should " "have the name <inliner-interactive-channel-base>.in, while the " "outgoing name should be <inliner-interactive-channel-base>.out"))
static cl::opt< unsigned > MaxEvictionCount("mlregalloc-max-eviction-count", cl::Hidden, cl::desc("The maximum number of times a live range can be " "evicted before preventing it from being evicted"), cl::init(100))
#define RA_EVICT_FEATURES_LIST(M)
#define SET(ID, TYPE, VAL)
#define _RESET(TYPE, NAME, SHAPE, __)
static cl::opt< std::string > InteractiveChannelBaseName("regalloc-evict-interactive-channel-base", cl::Hidden, cl::desc("Base file path for the interactive mode. The incoming filename should " "have the name <regalloc-evict-interactive-channel-base>.in, while the " "outgoing name should be " "<regalloc-evict-interactive-channel-base>.out"))
#define _FEATURE_IDX(A, B, C, D)
#define _DECL_FEATURES(type, name, shape, _)
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
SI optimize exec mask operations pre RA
LocallyHashedType DenseMapInfo< LocallyHashedType >::Empty
Iterator getOrderLimitEnd(unsigned OrderLimit) const
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator find(const_arg_type_t< KeyT > Val)
FunctionPass class - This class is used to implement most global optimizations.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
This is an important class for using LLVM in a threaded context.
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
Query interferences between a single live virtual register and a live interval union.
const SmallVectorImpl< const LiveInterval * > & interferingVRegs(unsigned MaxInterferingRegs=std::numeric_limits< unsigned >::max())
LiveInterval - This class represents the liveness of a register, or stack slot.
bool isSpillable() const
isSpillable - Can this interval be spilled?
SlotIndex beginIndex() const
beginIndex - Return the lowest numbered slot covered.
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
@ IK_VirtReg
Virtual register interference.
Logging utility - given an ordered specification of features, and assuming a scalar reward,...
bool isLoopExiting(const BlockT *BB) const
True if terminator in the block can branch to another block that is outside of the current loop.
Represents a single loop in the control flow graph.
Wrapper class representing physical registers. Should be passed by value.
static constexpr unsigned NoRegister
MLModelRunner interface: abstraction of a mechanism for evaluating a ML model.
virtual void switchContext(StringRef Name)
T * getTensor(I FeatureID)
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
double getBlockFreqRelativeToEntryBlock(const MachineBasicBlock *MBB) const
Compute the frequency of the block, relative to the entry block.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
defusechain_instr_iterator< true, true, true, true > reg_instr_nodbg_iterator
reg_instr_nodbg_iterator/reg_instr_nodbg_begin/reg_instr_nodbg_end - Walk all defs and uses of the sp...
A Module instance is used to store all the information related to an LLVM module.
A mock class satisfying the interface expected by ReleaseModeModelRunner for its TGen parameter.
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
ImmutableAnalysis abstraction for fetching the Eviction Advisor.
virtual void logRewardIfNeeded(const MachineFunction &MF, function_ref< float()> GetReward)
RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode Mode)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Common provider for legacy and new pass managers.
virtual std::unique_ptr< RegAllocEvictionAdvisor > getAdvisor(const MachineFunction &MF, const RAGreedy &RA, MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *Loops)=0
virtual void logRewardIfNeeded(const MachineFunction &MF, llvm::function_ref< float()> GetReward)
RegAllocEvictionAdvisorProvider(AdvisorMode Mode, LLVMContext &Ctx)
virtual bool canEvictHintInterference(const LiveInterval &VirtReg, MCRegister PhysReg, const SmallVirtRegSet &FixedRegisters) const =0
Find out if we can evict the live ranges occupying the given PhysReg, which is a hint (preferred regi...
virtual MCRegister tryFindEvictionCandidate(const LiveInterval &VirtReg, const AllocationOrder &Order, uint8_t CostPerUseLimit, const SmallVirtRegSet &FixedRegisters) const =0
Find a physical register that can be freed by evicting the FixedRegisters, or return NoRegister.
LLVM_ABI_FOR_TEST double getScore() const
Wrapper class representing virtual and physical registers.
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
constexpr unsigned id() const
SlotIndex - An opaque wrapper around machine indexes.
int distance(SlotIndex other) const
Return the distance from this index to the given one.
SlotIndex getPrevIndex() const
Returns the previous index.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
static TensorSpec createSpec(const std::string &Name, const std::vector< int64_t > &Shape, int Port=0)
static LLVM_ABI bool isRematerializable(const LiveInterval &LI, const LiveIntervals &LIS, const VirtRegMap &VRM, const MachineRegisterInfo &MRI, const TargetInstrInfo &TII)
Determine if all values in LI are rematerializable.
static LLVM_ABI Register copyHint(const MachineInstr *MI, Register Reg, const TargetRegisterInfo &TRI, const MachineRegisterInfo &MRI)
Return the preferred allocation register for reg, given a COPY instruction.
An efficient, type-erasing, non-owning reference to a callable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool isEmbeddedModelEvaluatorValid()
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
SmallSet< Register, 16 > SmallVirtRegSet
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI RegAllocEvictionAdvisorAnalysisLegacy * createReleaseModeAdvisorAnalysisLegacy()
LLVM_ABI RegAllocEvictionAdvisorProvider * createDevelopmentModeAdvisorProvider(LLVMContext &Ctx)
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
static const TensorSpec DecisionSpec
RegAllocScore calculateRegAllocScore(const MachineFunction &MF, const MachineBlockFrequencyInfo &MBFI)
Calculate a score.
LLVM_ABI RegAllocEvictionAdvisorAnalysisLegacy * createDevelopmentModeAdvisorAnalysisLegacy()
auto reverse(ContainerTy &&C)
static const std::vector< TensorSpec > InputFeatures
@ RS_Done
There is nothing more we can do to this live range.
LLVM_ABI FunctionPass * createRegAllocScoringPass()
When learning an eviction policy, extract score(reward) information, otherwise this does nothing.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
cl::opt< unsigned > EvictInterferenceCutoff
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ABI RegAllocEvictionAdvisorProvider * createReleaseModeAdvisorProvider(LLVMContext &Ctx)
static const int64_t NumberOfInterferences
static const std::vector< int64_t > PerLiveRangeShape
static const int64_t CandidateVirtRegPos
Implement std::hash so that hash_code can be used in STL containers.