45#define DEBUG_TYPE "spill-code-placement"
52 "Spill Code Placement Analysis",
true,
true)
123 for (std::pair<BlockFrequency, unsigned> &L :
Links)
129 Links.push_back(std::make_pair(w, b));
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;
192bool SpillPlacementWrapperLegacy::runOnMachineFunction(
MachineFunction &MF) {
196 Impl.run(MF, Bundles, MBFI);
208 Impl.run(MF, Bundles, MBFI);
214 MachineFunctionAnalysisManager::Invalidator &Inv) {
227void SpillPlacement::releaseMemory() {
234 this->bundles = Bundles;
246 unsigned Num =
I.getNumber();
252void SpillPlacement::activate(
unsigned n) {
254 if (ActiveNodes->test(n))
257 nodes[n].clear(Threshold);
268 if (bundles->getBlocks(n).size() > 100) {
269 nodes[n].BiasP = BlockFrequency(0);
270 BlockFrequency BiasN = MBFI->getEntryFreq();
272 nodes[n].BiasN = BiasN;
286 Threshold = BlockFrequency(std::max(UINT64_C(1),
Scaled));
297 unsigned ib = bundles->getBundle(LB.Number,
false);
299 nodes[ib].addBias(Freq, LB.Entry);
304 unsigned ob = bundles->getBundle(LB.Number,
true);
306 nodes[ob].addBias(Freq, LB.Exit);
313 for (
unsigned B : Blocks) {
317 unsigned ib = bundles->getBundle(
B,
false);
318 unsigned ob = bundles->getBundle(
B,
true);
327 for (
unsigned Number : Links) {
328 unsigned ib = bundles->getBundle(
Number,
false);
329 unsigned ob = bundles->getBundle(
Number,
true);
337 nodes[ib].addLink(ob, Freq);
338 nodes[ob].addLink(ib, Freq);
343 RecentPositive.clear();
344 for (
unsigned n : ActiveNodes->set_bits()) {
348 if (nodes[n].mustSpill())
350 if (nodes[n].preferReg())
351 RecentPositive.push_back(n);
353 return !RecentPositive.empty();
356bool SpillPlacement::update(
unsigned n) {
359 nodes[n].getDissentingNeighbors(TodoList,
nodes.get());
368 RecentPositive.clear();
374 unsigned Limit = bundles->getNumBundles() * 10;
375 while(Limit-- > 0 && !TodoList.empty()) {
376 unsigned n = TodoList.pop_back_val();
379 if (nodes[n].preferReg())
380 RecentPositive.push_back(n);
385 RecentPositive.clear();
388 ActiveNodes = &RegBundles;
389 ActiveNodes->
clear();
390 ActiveNodes->resize(bundles->getNumBundles());
395 assert(ActiveNodes &&
"Call prepare() first");
399 for (
unsigned n : ActiveNodes->set_bits())
400 if (!nodes[n].preferReg()) {
401 ActiveNodes->reset(n);
404 ActiveNodes =
nullptr;
412 case PrefReg:
return "PrefReg";
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Unify divergent function exit nodes
This file implements the BitVector class.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
void clear()
Removes all bits from the bitvector.
static BlockFrequency max()
Returns the maximum possible frequency, the saturation value.
unsigned getNumBundles() const
getNumBundles - Return the total number of bundles in the CFG.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
LLVM_ABI BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
LLVM_ABI 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.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
SparseSet - Fast set implementation for objects that can be identified by small unsigned keys.
void clear()
clear - Clears the set.
void setUniverse(unsigned U)
setUniverse - Set the universe size which determines the largest key the set can hold.
LLVM_ABI SpillPlacement run(MachineFunction &, MachineFunctionAnalysisManager &)
LLVM_ABI void addConstraints(ArrayRef< BlockConstraint > LiveBlocks)
addConstraints - Add constraints and biases.
LLVM_ABI bool finish()
finish - Compute the optimal spill code placement given the constraints.
LLVM_ABI void addPrefSpill(ArrayRef< unsigned > Blocks, bool Strong)
addPrefSpill - Add PrefSpill constraints to all blocks listed.
LLVM_ABI void prepare(BitVector &RegBundles)
prepare - Reset state and prepare for a new spill placement computation.
LLVM_ABI bool scanActiveBundles()
scanActiveBundles - Perform an initial scan of all bundles activated by addConstraints and addLinks,...
LLVM_ABI bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)
friend class SpillPlacementAnalysis
LLVM_ABI void addLinks(ArrayRef< unsigned > Links)
addLinks - Add transparent blocks with the given numbers.
LLVM_ABI 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.
LLVM_ABI ~SpillPlacement()
LLVM_ABI SpillPlacement(SpillPlacement &&)
Represent a constant reference to a string, i.e.
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.
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
iterator_range< typename GraphTraits< GraphType >::nodes_iterator > nodes(const GraphType &G)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI char & SpillPlacementID
SpillPlacement analysis.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
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.
SmallVector< std::pair< BlockFrequency, unsigned >, 4 > LinkVector
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
A special type used by analysis passes to provide an address that identifies that particular analysis...
BlockConstraint - Entry and exit constraints for a basic block.
BorderConstraint Exit
Constraint on block exit.
LLVM_ABI void dump() const
LLVM_ABI 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()).