45#define DEBUG_TYPE "spill-code-placement"
52 "Spill Code Placement Analysis",
true,
true)
123 for (std::pair<BlockFrequency, unsigned> &L :
Links)
155 for (std::pair<BlockFrequency, unsigned> &L :
Links) {
156 if (
nodes[L.second].Value == -1)
158 else if (
nodes[L.second].Value == 1)
171 if (SumN >= SumP + Threshold)
173 else if (SumP >= SumN + Threshold)
181 const Node nodes[])
const {
182 for (
const auto &Elt :
Links) {
183 unsigned n = Elt.second;
194 bundles = &getAnalysis<EdgeBundles>();
196 assert(!nodes &&
"Leaking node array");
203 MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
206 unsigned Num =
I.getNumber();
214void SpillPlacement::releaseMemory() {
221void SpillPlacement::activate(
unsigned n) {
223 if (ActiveNodes->
test(n))
226 nodes[n].
clear(Threshold);
241 nodes[n].
BiasN = BiasN;
266 unsigned ib = bundles->
getBundle(LB.Number,
false);
268 nodes[ib].
addBias(Freq, LB.Entry);
273 unsigned ob = bundles->
getBundle(LB.Number,
true);
275 nodes[ob].
addBias(Freq, LB.Exit);
296 for (
unsigned Number : Links) {
312 RecentPositive.
clear();
313 for (
unsigned n : ActiveNodes->
set_bits()) {
317 if (nodes[n].mustSpill())
319 if (nodes[n].preferReg())
322 return !RecentPositive.
empty();
325bool SpillPlacement::update(
unsigned n) {
326 if (!nodes[n].update(nodes, Threshold))
337 RecentPositive.
clear();
344 while(Limit-- > 0 && !TodoList.
empty()) {
348 if (nodes[n].preferReg())
354 RecentPositive.
clear();
357 ActiveNodes = &RegBundles;
358 ActiveNodes->
clear();
364 assert(ActiveNodes &&
"Call prepare() first");
368 for (
unsigned n : ActiveNodes->
set_bits())
369 if (!nodes[n].preferReg()) {
370 ActiveNodes->
reset(n);
373 ActiveNodes =
nullptr;
381 case PrefReg:
return "PrefReg";
Unify divergent function exit nodes
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
DenseMap< Block *, BlockRelaxAux > Blocks
Branch Probability Basic Block Placement
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Spill Code Placement true
Spill Code Placement Analysis
Represent the analysis usage information of a pass.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool test(unsigned Idx) const
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
void clear()
clear - Removes all bits from the bitvector.
iterator_range< const_set_bits_iterator > set_bits() const
static BlockFrequency max()
Returns the maximum possible frequency, the saturation value.
ArrayRef< unsigned > getBlocks(unsigned Bundle) const
getBlocks - Return an array of blocks that are connected to Bundle.
unsigned getBundle(unsigned N, bool Out) const
getBundle - Return the ingoing (Out = false) or outgoing (Out = true) bundle number for basic block N
unsigned getNumBundles() const
getNumBundles - Return the total number of bundles in the CFG.
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
BlockFrequency getEntryFreq() const
Divide a block's BlockFrequency::getFrequency() value by this value to obtain the entry block - relat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void push_back(const T &Elt)
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
bool empty() const
empty - Returns true if the set is empty.
void clear()
clear - Clears the set.
std::pair< iterator, bool > insert(const ValueT &Val)
insert - Attempts to insert a new element.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
void addConstraints(ArrayRef< BlockConstraint > LiveBlocks)
addConstraints - Add constraints and biases.
bool finish()
finish - Compute the optimal spill code placement given the constraints.
void addPrefSpill(ArrayRef< unsigned > Blocks, bool Strong)
addPrefSpill - Add PrefSpill constraints to all blocks listed.
void prepare(BitVector &RegBundles)
prepare - Reset state and prepare for a new spill placement computation.
bool scanActiveBundles()
scanActiveBundles - Perform an initial scan of all bundles activated by addConstraints and addLinks,...
void addLinks(ArrayRef< unsigned > Links)
addLinks - Add transparent blocks with the given numbers.
void iterate()
iterate - Update the network iteratively until convergence, or new bundles are found.
BorderConstraint
BorderConstraint - A basic block has separate constraints for entry and exit.
@ MustSpill
A register is impossible, variable must be spilled.
@ DontCare
Block doesn't care / variable not live.
@ PrefBoth
Block entry prefers both register and stack.
@ PrefReg
Block entry/exit prefers a register.
@ PrefSpill
Block entry/exit prefers a stack slot.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr)
char & SpillPlacementID
SpillPlacement analysis.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Node - Each edge bundle corresponds to a Hopfield node.
void addBias(BlockFrequency freq, BorderConstraint direction)
addBias - Bias this node.
bool preferReg() const
preferReg - Return true when this node prefers to be in a register.
bool update(const Node nodes[], BlockFrequency Threshold)
update - Recompute Value from Bias and Links.
BlockFrequency SumLinkWeights
SumLinkWeights - Cached sum of the weights of all links + ThresHold.
BlockFrequency BiasN
BiasN - Sum of blocks that prefer a spill.
void addLink(unsigned b, BlockFrequency w)
addLink - Add a link to bundle b with weight w.
LinkVector Links
Links - (Weight, BundleNo) for all transparent blocks connecting to other bundles.
int Value
Value - Output value of this node computed from the Bias and links.
BlockFrequency BiasP
BiasP - Sum of blocks that prefer a register.
void clear(BlockFrequency Threshold)
clear - Reset per-query data, but preserve frequencies that only depend on the CFG.
bool mustSpill() const
mustSpill - Return True if this node is so biased that it must spill.
void getDissentingNeighbors(SparseSet< unsigned > &List, const Node nodes[]) const
BlockConstraint - Entry and exit constraints for a basic block.
BorderConstraint Exit
Constraint on block exit.
void print(raw_ostream &OS) const
bool ChangesValue
True when this block changes the value of the live range.
BorderConstraint Entry
Constraint on block entry.
unsigned Number
Basic block number (from MBB::getNumber()).