44 #define DEBUG_TYPE "spillplacement"
48 "Spill Code Placement Analysis",
true,
true)
56 void SpillPlacement::getAnalysisUsage(
AnalysisUsage &AU)
const {
122 if (
I->second == b) {
154 if (nodes[
I->second].
Value == -1)
156 else if (nodes[
I->second].
Value == 1)
169 if (SumN >= SumP + Threshold)
171 else if (SumP >= SumN + Threshold)
181 bundles = &getAnalysis<EdgeBundles>();
182 loops = &getAnalysis<MachineLoopInfo>();
184 assert(!nodes &&
"Leaking node array");
189 MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
192 unsigned Num =
I->getNumber();
200 void SpillPlacement::releaseMemory() {
206 void SpillPlacement::activate(
unsigned n) {
207 if (ActiveNodes->
test(n))
210 nodes[n].
clear(Threshold);
236 uint64_t Scaled = (Freq >> 13) +
bool(Freq & (1 << 12));
237 Threshold = std::max(UINT64_C(1), Scaled);
244 E = LiveBlocks.
end();
I != E; ++
I) {
256 unsigned ob = bundles->
getBundle(
I->Number, 1);
282 unsigned Number = *
I;
284 unsigned ob = bundles->
getBundle(Number, 1);
303 RecentPositive.
clear();
305 nodes[n].
update(nodes, Threshold);
308 if (nodes[n].mustSpill())
310 if (!nodes[n].Links.empty())
312 if (nodes[n].preferReg())
315 return !RecentPositive.
empty();
324 while (!RecentPositive.
empty())
336 for (
unsigned iteration = 0; iteration != 10; ++iteration) {
339 bool Changed =
false;
341 iteration == 0 ? Linked.
rbegin() : std::next(Linked.
rbegin()),
342 E = Linked.
rend();
I != E; ++
I) {
344 if (nodes[n].update(nodes, Threshold)) {
346 if (nodes[n].preferReg())
350 if (!Changed || !RecentPositive.
empty())
356 std::next(Linked.
begin()), E = Linked.
end();
I != E; ++
I) {
358 if (nodes[n].update(nodes, Threshold)) {
360 if (nodes[n].preferReg())
364 if (!Changed || !RecentPositive.
empty())
371 RecentPositive.
clear();
373 ActiveNodes = &RegBundles;
374 ActiveNodes->
clear();
380 assert(ActiveNodes &&
"Call prepare() first");
385 if (!nodes[n].preferReg()) {
386 ActiveNodes->
reset(n);
389 ActiveNodes =
nullptr;
void resize(unsigned N, bool t=false)
resize - Grow or shrink the bitvector.
int Value
Value - Output value of this node computed from the Bias and links.
void push_back(const T &Elt)
spill code Spill Code Placement true
int find_first() const
find_first - Returns the index of the first set bit, -1 if none of the bits are set.
INITIALIZE_PASS_BEGIN(SpillPlacement,"spill-code-placement","Spill Code Placement Analysis", true, true) INITIALIZE_PASS_END(SpillPlacement
A register is impossible, variable must be spilled.
int find_next(unsigned Prev) const
find_next - Returns the index of the next set bit following the "Prev" bit.
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
BlockFrequency BiasP
BiasP - Sum of blocks that prefer a register.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
#define INITIALIZE_PASS_DEPENDENCY(depName)
uint64_t getEntryFreq() const
void clear()
clear - Clear all bits.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
void addPrefSpill(ArrayRef< unsigned > Blocks, bool Strong)
addPrefSpill - Add PrefSpill constraints to all blocks listed.
bool scanActiveBundles()
scanActiveBundles - Perform an initial scan of all bundles activated by addConstraints and addLinks...
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
LinkVector Links
Links - (Weight, BundleNo) for all transparent blocks connecting to other bundles.
void iterate()
iterate - Update the network iteratively until convergence, or new bundles are found.
unsigned getNumBundles() const
getNumBundles - Return the total number of bundles in the CFG.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
size_t size() const
size - Get the array size.
BlockFrequency SumLinkWeights
SumLinkWeights - Cached sum of the weights of all links + ThresHold.
void addBias(BlockFrequency freq, BorderConstraint direction)
addBias - Bias this node.
void addLinks(ArrayRef< unsigned > Links)
addLinks - Add transparent blocks with the given numbers.
Block doesn't care / variable not live.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
spill code Spill Code Placement Analysis
void clear(const BlockFrequency &Threshold)
clear - Reset per-query data, but preserve frequencies that only depend on
Represent the analysis usage information of a pass.
bool empty() const
empty - Check if the array is empty.
bool update(const Node nodes[], const BlockFrequency &Threshold)
update - Recompute Value from Bias and Links.
bool finish()
finish - Compute the optimal spill code placement given the constraints.
Block entry/exit prefers a register.
void addConstraints(ArrayRef< BlockConstraint > LiveBlocks)
addConstraints - Add constraints and biases.
block Branch Probability Basic Block Placement
Block entry/exit prefers a stack slot.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool test(unsigned Idx) const
void prepare(BitVector &RegBundles)
prepare - Reset state and prepare for a new spill placement computation.
ArrayRef< unsigned > getBlocks(unsigned Bundle) const
getBlocks - Return an array of blocks that are connected to Bundle.
void addLink(unsigned b, BlockFrequency w)
addLink - Add a link to bundle b with weight w.
Node - Each edge bundle corresponds to a Hopfield node.
static uint64_t getMaxFrequency()
Returns the maximum possible frequency, the saturation value.
BorderConstraint
BorderConstraint - A basic block has separate constraints for entry and exit.
char & SpillPlacementID
SpillPlacement analysis.
SmallVector< std::pair< BlockFrequency, unsigned >, 4 > LinkVector
unsigned getBundle(unsigned N, bool Out) const
getBundle - Return the ingoing (Out = false) or outgoing (Out = true) bundle number for basic block N...
reverse_iterator rbegin()
LLVM Value Representation.
BasicBlockListType::iterator iterator
bool mustSpill() const
mustSpill - Return True if this node is so biased that it must spill.
BlockFrequency BiasN
BiasN - Sum of blocks that prefer a spill.
bool preferReg() const
preferReg - Return true when this node prefers to be in a register.