12#ifndef LLVM_CODEGEN_REGALLOCGREEDY_H_
13#define LLVM_CODEGEN_REGALLOCGREEDY_H_
45class LiveDebugVariables;
48class MachineBasicBlock;
49class MachineBlockFrequencyInfo;
50class MachineDominatorTree;
53class MachineOptimizationRemarkEmitter;
54class MachineOptimizationRemarkMissed;
78 unsigned NextCascade = 1;
87 return getStage(VirtReg.
reg());
96 setStage(VirtReg.
reg(), Stage);
103 return getStage(
Reg);
114 unsigned Cascade = getCascade(
Reg);
116 Cascade = NextCascade++;
117 setCascade(
Reg, Cascade);
123 unsigned Cascade = getCascade(
Reg);
125 Cascade = NextCascade;
129 template <
typename Iterator>
131 for (; Begin !=
End; ++Begin) {
151 return RegClassPriorityTrumpsGlobalness;
158 using PQueue = std::priority_queue<std::pair<unsigned, unsigned>>;
163 using RecoloringStack =
183 std::unique_ptr<Spiller> SpillerInstance;
185 std::unique_ptr<VirtRegAuxInfo> VRAI;
186 std::optional<ExtraRegInfo> ExtraInfo;
187 std::unique_ptr<RegAllocEvictionAdvisor> EvictAdvisor;
189 std::unique_ptr<RegAllocPriorityAdvisor> PriorityAdvisor;
205 uint8_t CutOffInfo = CutOffStage::CO_None;
208 static const char *
const StageName[];
212 std::unique_ptr<SplitAnalysis> SA;
213 std::unique_ptr<SplitEditor> SE;
216 InterferenceCache IntfCache;
219 SmallVector<SpillPlacement::BlockConstraint, 8> SplitConstraints;
222 struct GlobalSplitCandidate {
230 InterferenceCache::Cursor Intf;
233 BitVector LiveBundles;
234 SmallVector<unsigned, 8> ActiveBlocks;
236 void reset(InterferenceCache &Cache, MCRegister
Reg) {
239 Intf.setPhysReg(Cache,
Reg);
241 ActiveBlocks.clear();
245 unsigned getBundles(SmallVectorImpl<unsigned> &
B,
unsigned C) {
247 for (
unsigned I : LiveBundles.set_bits())
248 if (
B[
I] == NoCand) {
259 SmallVector<GlobalSplitCandidate, 32> GlobalCand;
261 enum :
unsigned {
NoCand = ~0
u };
265 SmallVector<unsigned, 32> BundleCand;
268 BlockFrequency CSRCost;
271 SmallSetVector<const LiveInterval *, 8> SetOfBrokenHints;
275 ArrayRef<uint8_t> RegCosts;
279 bool RegClassPriorityTrumpsGlobalness =
false;
281 bool ReverseLocalAssignment =
false;
284 RAGreedy(
const RegAllocFilterFunc
F =
nullptr);
291 void releaseMemory()
override;
297 void aboutToRemoveInterval(
const LiveInterval &)
override;
304 MachineFunctionProperties::Property::NoPHIs);
309 MachineFunctionProperties::Property::IsSSA);
319 bool LRE_CanEraseVirtReg(
Register)
override;
320 void LRE_WillShrinkVirtReg(
Register)
override;
325 bool hasVirtRegAlloc();
329 bool growRegion(GlobalSplitCandidate &Cand);
332 bool calcCompactRegion(GlobalSplitCandidate &);
337 bool mayRecolorAllInterferences(
MCRegister PhysReg,
350 unsigned calculateRegionSplitCostAroundReg(
MCPhysReg PhysReg,
356 unsigned calculateRegionSplitCost(
const LiveInterval &VirtReg,
359 unsigned &NumCands,
bool IgnoreCSR);
361 unsigned doRegionSplit(
const LiveInterval &VirtReg,
unsigned BestCand,
371 uint8_t &CostPerUseLimit,
373 void initializeCSRCost();
389 void tryHintsRecoloring();
402 : Freq(Freq),
Reg(
Reg), PhysReg(PhysReg) {}
404 using HintsInfo = SmallVector<HintInfo, 4>;
406 BlockFrequency getBrokenHintFreq(
const HintsInfo &, MCRegister);
407 void collectHintInfo(
Register, HintsInfo &);
410 struct RAGreedyStats {
411 unsigned Reloads = 0;
412 unsigned FoldedReloads = 0;
413 unsigned ZeroCostFoldedReloads = 0;
415 unsigned FoldedSpills = 0;
417 float ReloadsCost = 0.0f;
418 float FoldedReloadsCost = 0.0f;
419 float SpillsCost = 0.0f;
420 float FoldedSpillsCost = 0.0f;
421 float CopiesCost = 0.0f;
424 return !(Reloads || FoldedReloads || Spills || FoldedSpills ||
425 ZeroCostFoldedReloads ||
Copies);
428 void add(
const RAGreedyStats &other) {
429 Reloads += other.Reloads;
430 FoldedReloads += other.FoldedReloads;
431 ZeroCostFoldedReloads += other.ZeroCostFoldedReloads;
432 Spills += other.Spills;
433 FoldedSpills += other.FoldedSpills;
435 ReloadsCost += other.ReloadsCost;
436 FoldedReloadsCost += other.FoldedReloadsCost;
437 SpillsCost += other.SpillsCost;
438 FoldedSpillsCost += other.FoldedSpillsCost;
439 CopiesCost += other.CopiesCost;
442 void report(MachineOptimizationRemarkMissed &R);
446 RAGreedyStats computeStats(MachineBasicBlock &
MBB);
449 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.