12#ifndef LLVM_CODEGEN_REGALLOCGREEDY_H_
13#define LLVM_CODEGEN_REGALLOCGREEDY_H_
46class LiveDebugVariablesWrapperLegacy;
49class MachineBasicBlock;
50class MachineBlockFrequencyInfo;
51class MachineDominatorTree;
54class MachineOptimizationRemarkEmitter;
55class MachineOptimizationRemarkMissed;
79 unsigned NextCascade = 1;
88 return getStage(VirtReg.
reg());
97 setStage(VirtReg.
reg(), Stage);
104 return getStage(
Reg);
115 unsigned Cascade = getCascade(
Reg);
117 Cascade = NextCascade++;
118 setCascade(
Reg, Cascade);
124 unsigned Cascade = getCascade(
Reg);
126 Cascade = NextCascade;
130 template <
typename Iterator>
132 for (; Begin !=
End; ++Begin) {
152 return RegClassPriorityTrumpsGlobalness;
159 using PQueue = std::priority_queue<std::pair<unsigned, unsigned>>;
164 using RecoloringStack =
184 std::unique_ptr<Spiller> SpillerInstance;
186 std::unique_ptr<VirtRegAuxInfo> VRAI;
187 std::optional<ExtraRegInfo> ExtraInfo;
188 std::unique_ptr<RegAllocEvictionAdvisor> EvictAdvisor;
190 std::unique_ptr<RegAllocPriorityAdvisor> PriorityAdvisor;
206 uint8_t CutOffInfo = CutOffStage::CO_None;
209 static const char *
const StageName[];
213 std::unique_ptr<SplitAnalysis> SA;
214 std::unique_ptr<SplitEditor> SE;
217 InterferenceCache IntfCache;
220 SmallVector<SpillPlacement::BlockConstraint, 8> SplitConstraints;
223 struct GlobalSplitCandidate {
231 InterferenceCache::Cursor Intf;
234 BitVector LiveBundles;
235 SmallVector<unsigned, 8> ActiveBlocks;
237 void reset(InterferenceCache &Cache, MCRegister
Reg) {
240 Intf.setPhysReg(Cache,
Reg);
242 ActiveBlocks.clear();
246 unsigned getBundles(SmallVectorImpl<unsigned> &
B,
unsigned C) {
248 for (
unsigned I : LiveBundles.set_bits())
249 if (
B[
I] == NoCand) {
260 SmallVector<GlobalSplitCandidate, 32> GlobalCand;
262 enum :
unsigned {
NoCand = ~0
u };
266 SmallVector<unsigned, 32> BundleCand;
269 BlockFrequency CSRCost;
272 SmallSetVector<const LiveInterval *, 8> SetOfBrokenHints;
276 ArrayRef<uint8_t> RegCosts;
280 bool RegClassPriorityTrumpsGlobalness =
false;
282 bool ReverseLocalAssignment =
false;
285 RAGreedy(
const RegAllocFilterFunc
F =
nullptr);
292 void releaseMemory()
override;
298 void aboutToRemoveInterval(
const LiveInterval &)
override;
305 MachineFunctionProperties::Property::NoPHIs);
310 MachineFunctionProperties::Property::IsSSA);
320 bool LRE_CanEraseVirtReg(
Register)
override;
321 void LRE_WillShrinkVirtReg(
Register)
override;
326 bool hasVirtRegAlloc();
330 bool growRegion(GlobalSplitCandidate &Cand);
333 bool calcCompactRegion(GlobalSplitCandidate &);
338 bool mayRecolorAllInterferences(
MCRegister PhysReg,
351 unsigned calculateRegionSplitCostAroundReg(
MCPhysReg PhysReg,
357 unsigned calculateRegionSplitCost(
const LiveInterval &VirtReg,
360 unsigned &NumCands,
bool IgnoreCSR);
362 unsigned doRegionSplit(
const LiveInterval &VirtReg,
unsigned BestCand,
374 void initializeCSRCost();
390 void tryHintsRecoloring();
403 : Freq(Freq),
Reg(
Reg), PhysReg(PhysReg) {}
405 using HintsInfo = SmallVector<HintInfo, 4>;
407 BlockFrequency getBrokenHintFreq(
const HintsInfo &, MCRegister);
408 void collectHintInfo(
Register, HintsInfo &);
411 struct RAGreedyStats {
412 unsigned Reloads = 0;
413 unsigned FoldedReloads = 0;
414 unsigned ZeroCostFoldedReloads = 0;
416 unsigned FoldedSpills = 0;
418 float ReloadsCost = 0.0f;
419 float FoldedReloadsCost = 0.0f;
420 float SpillsCost = 0.0f;
421 float FoldedSpillsCost = 0.0f;
422 float CopiesCost = 0.0f;
425 return !(Reloads || FoldedReloads || Spills || FoldedSpills ||
426 ZeroCostFoldedReloads ||
Copies);
429 void add(
const RAGreedyStats &other) {
430 Reloads += other.Reloads;
431 FoldedReloads += other.FoldedReloads;
432 ZeroCostFoldedReloads += other.ZeroCostFoldedReloads;
433 Spills += other.Spills;
434 FoldedSpills += other.FoldedSpills;
436 ReloadsCost += other.ReloadsCost;
437 FoldedReloadsCost += other.FoldedReloadsCost;
438 SpillsCost += other.SpillsCost;
439 FoldedSpillsCost += other.FoldedSpillsCost;
440 CopiesCost += other.CopiesCost;
443 void report(MachineOptimizationRemarkMissed &R);
447 RAGreedyStats computeStats(MachineBasicBlock &
MBB);
450 RAGreedyStats reportStats(MachineLoop *L);
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Analysis containing CSE Info
#define LLVM_LIBRARY_VISIBILITY
const HexagonInstrInfo * TII
This file implements an indexed map.
Promote Memory to Register
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
Represent the analysis usage information of a pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Cursor - The primary query interface for the block interference cache.
LiveInterval - This class represents the liveness of a register, or stack slot.
Callback methods for LiveRangeEdit owners.
Wrapper class representing physical registers. Should be passed by value.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Properties which a MachineFunction may have at a given point in time.
MachineFunctionProperties & set(Property P)
StringRef getPassName() const override
Return the pass name.
MachineFunctionProperties getClearedProperties() const override
const ExtraRegInfo & getExtraInfo() const
Spiller & spiller() override
MachineFunctionProperties getRequiredProperties() const override
VirtRegMap * getVirtRegMap() const
LiveIntervals * getLiveIntervals() const
const RegisterClassInfo & getRegClassInfo() const
bool getReverseLocalAssignment() const
size_t getQueueSize() const
LiveRegMatrix * getInterferenceMatrix() const
bool getRegClassPriorityTrumpsGlobalness() const
RegAllocBase provides the register allocation driver and interface that can be extended to add intere...
Wrapper class representing virtual and physical registers.
A SetVector that performs no allocations if smaller than a certain size.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
TargetInstrInfo - Interface to description of machine instruction set.
This is an optimization pass for GlobalISel generic memory operations.
@ RS_New
Newly created live range that has never been queued.