31 cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default),
32 cl::desc(
"Enable regalloc advisor mode"),
34 clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default,
35 "default",
"Default"),
36 clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release,
37 "release",
"precompiled"),
38 clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development,
39 "development",
"for training")));
43 cl::desc(
"Local reassignment can yield better allocation decisions, but "
44 "may be compile time intensive"),
49 "regalloc-eviction-max-interference-cutoff",
cl::Hidden,
50 cl::desc(
"Number of interferences after which we declare "
51 "an interference unevictable and bail out. This "
52 "is a compilation cost-saving consideration. To "
53 "disable, pass a very large number."),
57#define DEBUG_TYPE "regalloc"
58#ifdef LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL
59#define LLVM_HAVE_TF_AOT
64 "Regalloc eviction policy",
false,
true)
67class DefaultEvictionAdvisorAnalysis final
70 DefaultEvictionAdvisorAnalysis(
bool NotAsRequested)
72 NotAsRequested(NotAsRequested) {}
80 std::unique_ptr<RegAllocEvictionAdvisor>
82 return std::make_unique<DefaultEvictionAdvisor>(MF,
RA);
86 M.getContext().emitError(
"Requested regalloc eviction advisor analysis "
87 "could not be created. Using default");
90 const bool NotAsRequested;
97 case RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default:
98 Ret =
new DefaultEvictionAdvisorAnalysis(
false);
100 case RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development:
101#if defined(LLVM_HAVE_TFLITE)
105 case RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release:
111 return new DefaultEvictionAdvisorAnalysis(
true);
114StringRef RegAllocEvictionAdvisorAnalysis::getPassName()
const {
117 return "Default Regalloc Eviction Advisor";
119 return "Release mode Regalloc Eviction Advisor";
121 return "Development mode Regalloc Eviction Advisor";
129 LIS(
RA.getLiveIntervals()), VRM(
RA.getVirtRegMap()),
130 MRI(&VRM->getRegInfo()),
TRI(MF.getSubtarget().getRegisterInfo()),
131 RegClassInfo(
RA.getRegClassInfo()), RegCosts(
TRI->getRegisterCosts(MF)),
133 MF.getSubtarget().enableRALocalReassignment(
134 MF.getTarget().getOptLevel())) {}
149bool DefaultEvictionAdvisor::shouldEvict(
const LiveInterval &
A,
bool IsHint,
151 bool BreaksHint)
const {
156 if (CanSplit && IsHint && !BreaksHint)
159 if (
A.weight() >
B.weight()) {
160 LLVM_DEBUG(
dbgs() <<
"should evict: " <<
B <<
" w= " <<
B.weight() <<
'\n');
168bool DefaultEvictionAdvisor::canEvictHintInterference(
173 return canEvictInterferenceBasedOnCost(VirtReg, PhysReg,
true, MaxCost,
186bool DefaultEvictionAdvisor::canEvictInterferenceBasedOnCost(
214 assert(Intf->reg().isVirtual() &&
215 "Only expecting virtual register interference from query");
220 if (FixedRegisters.
count(Intf->reg()))
234 (Intf->isSpillable() ||
240 if (Cascade == IntfCascade)
243 if (Cascade < IntfCascade) {
248 Cost.BrokenHints += 10;
253 Cost.BrokenHints += BreaksHint;
254 Cost.MaxWeight = std::max(
Cost.MaxWeight, Intf->weight());
256 if (!(
Cost < MaxCost))
261 if (!shouldEvict(VirtReg, IsHint, *Intf, BreaksHint))
276MCRegister DefaultEvictionAdvisor::tryFindEvictionCandidate(
278 uint8_t CostPerUseLimit,
const SmallVirtRegSet &FixedRegisters)
const {
283 auto MaybeOrderLimit =
getOrderLimit(VirtReg, Order, CostPerUseLimit);
284 if (!MaybeOrderLimit)
286 unsigned OrderLimit = *MaybeOrderLimit;
290 if (CostPerUseLimit < uint8_t(~0u)) {
300 !canEvictInterferenceBasedOnCost(VirtReg, PhysReg,
false, BestCost,
unsigned const MachineRegisterInfo * MRI
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
unsigned const TargetRegisterInfo * TRI
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static cl::opt< bool > EnableLocalReassignment("enable-local-reassign", cl::Hidden, cl::desc("Local reassignment can yield better allocation decisions, but " "may be compile time intensive"), cl::init(false))
static cl::opt< RegAllocEvictionAdvisorAnalysis::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysis::AdvisorMode::Development, "development", "for training")))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SI optimize exec mask operations pre RA
Iterator getOrderLimitEnd(unsigned OrderLimit) const
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?
MachineBasicBlock * intervalIsInOneMBB(const LiveInterval &LI) const
If LI is confined to a single basic block, return a pointer to that block.
LiveIntervalUnion::Query & query(const LiveRange &LR, MCRegister RegUnit)
Query a line of the assigned virtual register matrix directly.
@ IK_VirtReg
Virtual register interference.
InterferenceKind checkInterference(const LiveInterval &VirtReg, MCRegister PhysReg)
Check for interference before assigning VirtReg to PhysReg.
iterator_range< MCRegUnitIterator > regunits(MCRegister Reg) const
Returns an iterator range over all regunits for Reg.
Wrapper class representing physical registers. Should be passed by value.
static constexpr unsigned NoRegister
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
A Module instance is used to store all the information related to an LLVM module.
Pass interface - Implemented by all 'passes'.
virtual bool doInitialization(Module &)
doInitialization - Virtual method overridden by subclasses to do any necessary initialization before ...
const ExtraRegInfo & getExtraInfo() const
ImmutableAnalysis abstraction for fetching the Eviction Advisor.
AdvisorMode getAdvisorMode() const
virtual std::unique_ptr< RegAllocEvictionAdvisor > getAdvisor(const MachineFunction &MF, const RAGreedy &RA)=0
Get an advisor for the given context (i.e. machine function, etc)
const TargetRegisterInfo *const TRI
std::optional< unsigned > getOrderLimit(const LiveInterval &VirtReg, const AllocationOrder &Order, unsigned CostPerUseLimit) const
MachineRegisterInfo *const MRI
const RegisterClassInfo & RegClassInfo
RegAllocEvictionAdvisor(const RegAllocEvictionAdvisor &)=delete
bool canReassign(const LiveInterval &VirtReg, MCRegister FromReg) const
const bool EnableLocalReassign
Run or not the local reassignment heuristic.
bool canAllocatePhysReg(unsigned CostPerUseLimit, MCRegister PhysReg) const
LiveRegMatrix *const Matrix
unsigned getNumAllocatableRegs(const TargetRegisterClass *RC) const
getNumAllocatableRegs - Returns the number of actually allocatable registers in RC in the current fun...
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
StringRef - Represent a constant reference to a string, i.e.
bool hasPreferredPhys(Register VirtReg) const
returns true if VirtReg is assigned to its preferred physreg.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
auto reverse(ContainerTy &&C)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ RS_Spill
Live range will be spilled. No more splitting will be attempted.
@ RS_Done
There is nothing more we can do to this live range.
Pass * callDefaultCtor< RegAllocEvictionAdvisorAnalysis >()
Specialization for the API used by the analysis infrastructure to create an instance of the eviction ...
RegAllocEvictionAdvisorAnalysis * createReleaseModeAdvisor()
RegAllocEvictionAdvisorAnalysis * createDevelopmentModeAdvisor()
cl::opt< unsigned > EvictInterferenceCutoff
Cost of evicting interference - used by default advisor, and the eviction chain heuristic in RegAlloc...
unsigned BrokenHints
Total number of broken hints.
float MaxWeight
Maximum spill weight evicted.
void setBrokenHints(unsigned NHints)