32 cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default),
33 cl::desc(
"Enable regalloc advisor mode"),
35 clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default,
36 "default",
"Default"),
37 clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release,
38 "release",
"precompiled"),
40 RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development,
41 "development",
"for training")));
45 cl::desc(
"Local reassignment can yield better allocation decisions, but "
46 "may be compile time intensive"),
51 "regalloc-eviction-max-interference-cutoff",
cl::Hidden,
52 cl::desc(
"Number of interferences after which we declare "
53 "an interference unevictable and bail out. This "
54 "is a compilation cost-saving consideration. To "
55 "disable, pass a very large number."),
59#define DEBUG_TYPE "regalloc"
60#ifdef LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL
61#define LLVM_HAVE_TF_AOT
66 "Regalloc eviction policy",
false,
true)
69class DefaultEvictionAdvisorProvider final
72 DefaultEvictionAdvisorProvider(
bool NotAsRequested,
LLVMContext &Ctx)
75 Ctx.
emitError(
"Requested regalloc eviction advisor analysis "
76 "could not be created. Using default");
84 std::unique_ptr<RegAllocEvictionAdvisor>
87 return std::make_unique<DefaultEvictionAdvisor>(MF,
RA);
91class DefaultEvictionAdvisorAnalysisLegacy final
94 DefaultEvictionAdvisorAnalysisLegacy(
bool NotAsRequested)
96 NotAsRequested(NotAsRequested) {}
100 new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext()));
110 const bool NotAsRequested;
116void RegAllocEvictionAdvisorAnalysis::initializeProvider(
123 new DefaultEvictionAdvisorProvider(
false, Ctx));
126#if defined(LLVM_HAVE_TFLITE)
130 new DefaultEvictionAdvisorProvider(
true, Ctx));
144 return Result{Provider.get()};
151 return new DefaultEvictionAdvisorAnalysisLegacy(
false);
157 return new DefaultEvictionAdvisorAnalysisLegacy(
true);
160#if defined(LLVM_HAVE_TFLITE)
163 return new DefaultEvictionAdvisorAnalysisLegacy(
true);
169StringRef RegAllocEvictionAdvisorAnalysisLegacy::getPassName()
const {
172 return "Default Regalloc Eviction Advisor";
174 return "Release mode Regalloc Eviction Advisor";
176 return "Development mode Regalloc Eviction Advisor";
184 LIS(
RA.getLiveIntervals()), VRM(
RA.getVirtRegMap()),
185 MRI(&VRM->getRegInfo()),
TRI(MF.getSubtarget().getRegisterInfo()),
186 RegClassInfo(
RA.getRegClassInfo()), RegCosts(
TRI->getRegisterCosts(MF)),
188 MF.getSubtarget().enableRALocalReassignment(
189 MF.getTarget().getOptLevel())) {}
204bool DefaultEvictionAdvisor::shouldEvict(
const LiveInterval &
A,
bool IsHint,
206 bool BreaksHint)
const {
211 if (CanSplit && IsHint && !BreaksHint)
214 if (
A.weight() >
B.weight()) {
223bool DefaultEvictionAdvisor::canEvictHintInterference(
228 return canEvictInterferenceBasedOnCost(VirtReg, PhysReg,
true, MaxCost,
241bool DefaultEvictionAdvisor::canEvictInterferenceBasedOnCost(
269 assert(Intf->reg().isVirtual() &&
270 "Only expecting virtual register interference from query");
275 if (FixedRegisters.
count(Intf->reg()))
289 (Intf->isSpillable() ||
295 if (Cascade == IntfCascade)
298 if (Cascade < IntfCascade) {
303 Cost.BrokenHints += 10;
308 Cost.BrokenHints += BreaksHint;
309 Cost.MaxWeight = std::max(
Cost.MaxWeight, Intf->weight());
311 if (!(
Cost < MaxCost))
316 if (!shouldEvict(VirtReg, IsHint, *Intf, BreaksHint))
331MCRegister DefaultEvictionAdvisor::tryFindEvictionCandidate(
338 auto MaybeOrderLimit =
getOrderLimit(VirtReg, Order, CostPerUseLimit);
339 if (!MaybeOrderLimit)
341 unsigned OrderLimit = *MaybeOrderLimit;
345 if (CostPerUseLimit <
uint8_t(~0u)) {
355 !canEvictInterferenceBasedOnCost(VirtReg, PhysReg,
false, BestCost,
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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)
Module.h This file contains the declarations for the Module class.
Register const TargetRegisterInfo * TRI
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
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))
SI optimize exec mask operations pre RA
Iterator getOrderLimitEnd(unsigned OrderLimit) const
A container for analyses that lazily runs them and caches their results.
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?
LLVM_ABI 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, MCRegUnit 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
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
Function & getFunction()
Return the LLVM function that this machine code represents.
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
Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MAM)
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
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.
LLVM_ABI 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.
RegAllocEvictionAdvisorAnalysisLegacy * createReleaseModeAdvisorAnalysisLegacy()
RegAllocEvictionAdvisorProvider * createDevelopmentModeAdvisorProvider(LLVMContext &Ctx)
auto reverse(ContainerTy &&C)
Pass * callDefaultCtor< RegAllocEvictionAdvisorAnalysisLegacy >()
Specialization for the API used by the analysis infrastructure to create an instance of the eviction ...
LLVM_ABI 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.
cl::opt< unsigned > EvictInterferenceCutoff
LLVM_ATTRIBUTE_RETURNS_NONNULL RegAllocEvictionAdvisorProvider * createReleaseModeAdvisorProvider(LLVMContext &Ctx)
RegAllocEvictionAdvisorAnalysisLegacy * createDevelopmentModeAdvisorAnalysisLegacy()
A special type used by analysis passes to provide an address that identifies that particular analysis...
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)