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() {
235 this->bundles = Bundles;
247 unsigned Num =
I.getNumber();
253void SpillPlacement::activate(
unsigned n) {
255 if (ActiveNodes->test(n))
258 nodes[n].clear(Threshold);
269 if (bundles->getBlocks(n).size() > 100) {
270 nodes[n].BiasP = BlockFrequency(0);
271 BlockFrequency BiasN = MBFI->getEntryFreq();
273 nodes[n].BiasN = BiasN;
285 uint64_t Freq =
Entry.getFrequency();
286 uint64_t
Scaled = (Freq >> 13) +
bool(Freq & (1 << 12));
287 Threshold = BlockFrequency(std::max(UINT64_C(1),
Scaled));
298 unsigned ib = bundles->getBundle(LB.Number,
false);
300 nodes[ib].addBias(Freq, LB.Entry);
305 unsigned ob = bundles->getBundle(LB.Number,
true);
307 nodes[ob].addBias(Freq, LB.Exit);
314 for (
unsigned B : Blocks) {
318 unsigned ib = bundles->getBundle(
B,
false);
319 unsigned ob = bundles->getBundle(
B,
true);
328 for (
unsigned Number : Links) {
329 unsigned ib = bundles->getBundle(
Number,
false);
330 unsigned ob = bundles->getBundle(
Number,
true);
338 nodes[ib].addLink(ob, Freq);
339 nodes[ob].addLink(ib, Freq);
344 RecentPositive.clear();
345 for (
unsigned n : ActiveNodes->set_bits()) {
349 if (nodes[n].mustSpill())
351 if (nodes[n].preferReg())
352 RecentPositive.push_back(n);
354 return !RecentPositive.empty();
357bool SpillPlacement::update(
unsigned n) {
360 nodes[n].getDissentingNeighbors(TodoList,
nodes.get());
369 RecentPositive.clear();
375 unsigned Limit = bundles->getNumBundles() * 10;
376 while(Limit-- > 0 && !TodoList.empty()) {
377 unsigned n = TodoList.pop_back_val();
380 if (nodes[n].preferReg())
381 RecentPositive.push_back(n);
386 RecentPositive.clear();
389 ActiveNodes = &RegBundles;
390 ActiveNodes->
clear();
391 ActiveNodes->resize(bundles->getNumBundles());
396 assert(ActiveNodes &&
"Call prepare() first");
400 for (
unsigned n : ActiveNodes->set_bits())
401 if (!nodes[n].preferReg()) {
402 ActiveNodes->reset(n);
405 ActiveNodes =
nullptr;
413 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< 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.
SpillPlacement run(MachineFunction &, MachineFunctionAnalysisManager &)
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,...
bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, MachineFunctionAnalysisManager::Invalidator &Inv)
friend class SpillPlacementAnalysis
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.
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.
@ C
The default llvm calling convention, compatible with C.
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.
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()).