33 cl::desc(
"Enable regalloc advisor mode"),
36 "default",
"Default"),
38 "release",
"precompiled"),
41 "development",
"for training")));
45 cl::desc(
"Local reassignment can yield better allocation decisions, but "
46 "may be compile time intensive"));
50 "regalloc-eviction-max-interference-cutoff",
cl::Hidden,
51 cl::desc(
"Number of interferences after which we declare "
52 "an interference unevictable and bail out. This "
53 "is a compilation cost-saving consideration. To "
54 "disable, pass a very large number."),
58#define DEBUG_TYPE "regalloc"
59#ifdef LLVM_HAVE_TF_AOT_REGALLOCEVICTMODEL
60#define LLVM_HAVE_TF_AOT
65 "Regalloc eviction policy",
false,
true)
68class DefaultEvictionAdvisorProvider final
71 DefaultEvictionAdvisorProvider(
bool NotAsRequested,
LLVMContext &Ctx)
74 Ctx.emitError(
"Requested regalloc eviction advisor analysis "
75 "could not be created. Using default");
80 return R->getAdvisorMode() == AdvisorMode::Default;
83 std::unique_ptr<RegAllocEvictionAdvisor>
86 return std::make_unique<DefaultEvictionAdvisor>(MF,
RA);
90class DefaultEvictionAdvisorAnalysisLegacy final
93 DefaultEvictionAdvisorAnalysisLegacy(
bool NotAsRequested)
95 NotAsRequested(NotAsRequested) {}
99 new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext()));
105 return R->getAdvisorMode() == AdvisorMode::Default;
109 const bool NotAsRequested;
115void RegAllocEvictionAdvisorAnalysis::initializeProvider(
122 new DefaultEvictionAdvisorProvider(
false, Ctx));
133 new DefaultEvictionAdvisorProvider(
true, Ctx));
141 return Result{Provider.get()};
148 return new DefaultEvictionAdvisorAnalysisLegacy(
false);
154 return new DefaultEvictionAdvisorAnalysisLegacy(
true);
157#if defined(LLVM_HAVE_TFLITE)
160 return new DefaultEvictionAdvisorAnalysisLegacy(
true);
169 return "Default Regalloc Eviction Advisor";
171 return "Release mode Regalloc Eviction Advisor";
173 return "Development mode Regalloc Eviction Advisor";
181 LIS(
RA.getLiveIntervals()),
VRM(
RA.getVirtRegMap()),
182 MRI(&
VRM->getRegInfo()),
TRI(
MF.getSubtarget().getRegisterInfo()),
187 MF.getSubtarget().enableRALocalReassignment(
188 MF.getTarget().getOptLevel()))) {}
218bool DefaultEvictionAdvisor::shouldEvict(
const LiveInterval &
A,
bool IsHint,
220 bool BreaksHint)
const {
221 bool CanSplit =
RA.getExtraInfo().getStage(
B) <
RS_Spill;
225 if (CanSplit && IsHint && !BreaksHint)
228 if (
A.weight() >
B.weight()) {
237bool DefaultEvictionAdvisor::canEvictHintInterference(
240 EvictionCost MaxCost;
242 return canEvictInterferenceBasedOnCost(VirtReg, PhysReg,
true, MaxCost,
255bool DefaultEvictionAdvisor::canEvictInterferenceBasedOnCost(
262 bool IsLocal = VirtReg.
empty() ||
LIS->intervalIsInOneMBB(VirtReg);
271 unsigned Cascade =
RA.getExtraInfo().getCascadeOrCurrentNext(VirtReg.
reg());
274 for (MCRegUnit Unit :
TRI->regunits(PhysReg)) {
275 LiveIntervalUnion::Query &Q =
Matrix->query(VirtReg, Unit);
282 for (
const LiveInterval *Intf :
reverse(Interferences)) {
283 assert(Intf->reg().isVirtual() &&
284 "Only expecting virtual register interference from query");
289 if (FixedRegisters.
count(Intf->reg()))
293 if (
RA.getExtraInfo().getStage(*Intf) ==
RS_Done)
298 unsigned IntfCascade =
RA.getExtraInfo().getCascade(Intf->reg());
299 if (Cascade == IntfCascade)
302 if (Cascade < IntfCascade) {
307 Cost.BrokenHints += 10 *
MRI->getRegClass(Intf->reg())->getCopyCost();
310 bool BreaksHint =
VRM->hasPreferredPhys(Intf->reg());
313 Cost.BrokenHints +=
MRI->getRegClass(Intf->reg())->getCopyCost();
315 Cost.MaxWeight = std::max(
Cost.MaxWeight, Intf->weight());
322 if (!shouldEvict(VirtReg, IsHint, *Intf, BreaksHint))
327 if (!MaxCost.
isMax() && IsLocal &&
LIS->intervalIsInOneMBB(*Intf) &&
337MCRegister DefaultEvictionAdvisor::tryFindEvictionCandidate(
339 uint8_t CostPerUseLimit,
const SmallVirtRegSet &FixedRegisters)
const {
341 EvictionCost BestCost;
344 auto MaybeOrderLimit =
getOrderLimit(VirtReg, Order, CostPerUseLimit);
345 if (!MaybeOrderLimit)
347 unsigned OrderLimit = *MaybeOrderLimit;
351 if (CostPerUseLimit < uint8_t(~0u)) {
358 MCRegister PhysReg = *
I;
361 !canEvictInterferenceBasedOnCost(VirtReg, PhysReg,
false, BestCost,
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static cl::opt< cl::boolOrDefault > EnableLocalReassignment("enable-local-reassign", cl::Hidden, cl::desc("Local reassignment can yield better allocation decisions, but " "may be compile time intensive"))
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")))
SI optimize exec mask operations pre RA
Iterator getOrderLimitEnd(unsigned OrderLimit) const
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.
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?
@ IK_VirtReg
Virtual register interference.
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.
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 ...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
ImmutableAnalysis abstraction for fetching the Eviction Advisor.
RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode Mode)
AdvisorMode getAdvisorMode() const
LLVM_ABI 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
RegAllocEvictionAdvisorProvider(AdvisorMode Mode, LLVMContext &Ctx)
const TargetRegisterInfo *const TRI
LLVM_ABI std::optional< unsigned > getOrderLimit(const LiveInterval &VirtReg, const AllocationOrder &Order, unsigned CostPerUseLimit) const
const ArrayRef< uint8_t > RegCosts
MachineRegisterInfo *const MRI
const RegisterClassInfo & RegClassInfo
const MachineFunction & MF
RegAllocEvictionAdvisor(const RegAllocEvictionAdvisor &)=delete
LLVM_ABI bool isUrgentEviction(const LiveInterval &VirtReg, const LiveInterval &Intf) const
Returns true if this is an urgent eviction.
LLVM_ABI bool canReassign(const LiveInterval &VirtReg, MCRegister FromReg) const
const bool EnableLocalReassign
Run or not the local reassignment heuristic.
LLVM_ABI bool canAllocatePhysReg(unsigned CostPerUseLimit, MCRegister PhysReg) const
LiveRegMatrix *const Matrix
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
Represent a constant reference to a string, i.e.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This namespace contains all of the command line option processing machinery.
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.
SmallSet< Register, 16 > SmallVirtRegSet
LLVM_ABI RegAllocEvictionAdvisorAnalysisLegacy * createReleaseModeAdvisorAnalysisLegacy()
LLVM_ABI RegAllocEvictionAdvisorProvider * createDevelopmentModeAdvisorProvider(LLVMContext &Ctx)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI RegAllocEvictionAdvisorAnalysisLegacy * createDevelopmentModeAdvisorAnalysisLegacy()
auto reverse(ContainerTy &&C)
LLVM_ABI 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_ABI RegAllocEvictionAdvisorProvider * createReleaseModeAdvisorProvider(LLVMContext &Ctx)
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)