diff options
Diffstat (limited to 'contrib/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp')
-rw-r--r-- | contrib/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/contrib/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp b/contrib/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp index 48e23af2690a..90bc249bcb39 100644 --- a/contrib/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ b/contrib/llvm/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -13,6 +13,7 @@ #include "llvm/Analysis/BlockFrequencyInfoImpl.h" #include "llvm/ADT/SCCIterator.h" +#include "llvm/IR/Function.h" #include "llvm/Support/raw_ostream.h" #include <numeric> @@ -27,7 +28,7 @@ ScaledNumber<uint64_t> BlockMass::toScaled() const { return ScaledNumber<uint64_t>(getMass() + 1, -64); } -void BlockMass::dump() const { print(dbgs()); } +LLVM_DUMP_METHOD void BlockMass::dump() const { print(dbgs()); } static char getHexDigit(int N) { assert(N < 16); @@ -35,6 +36,7 @@ static char getHexDigit(int N) { return '0' + N; return 'a' + N - 10; } + raw_ostream &BlockMass::print(raw_ostream &OS) const { for (int Digits = 0; Digits < 16; ++Digits) OS << getHexDigit(Mass >> (60 - Digits * 4) & 0xf); @@ -78,7 +80,7 @@ struct DitheringDistributer { BlockMass takeMass(uint32_t Weight); }; -} // end namespace +} // end anonymous namespace DitheringDistributer::DitheringDistributer(Distribution &Dist, const BlockMass &Mass) { @@ -130,6 +132,7 @@ static void combineWeight(Weight &W, const Weight &OtherW) { else W.Amount += OtherW.Amount; } + static void combineWeightsBySorting(WeightList &Weights) { // Sort so edges to the same node are adjacent. std::sort(Weights.begin(), Weights.end(), @@ -149,8 +152,8 @@ static void combineWeightsBySorting(WeightList &Weights) { // Erase extra entries. Weights.erase(O, Weights.end()); - return; } + static void combineWeightsByHashing(WeightList &Weights) { // Collect weights into a DenseMap. typedef DenseMap<BlockNode::IndexType, Weight> HashTable; @@ -168,6 +171,7 @@ static void combineWeightsByHashing(WeightList &Weights) { for (const auto &I : Combined) Weights.push_back(I.second); } + static void combineWeights(WeightList &Weights) { // Use a hash table for many successors to keep this linear. if (Weights.size() > 128) { @@ -177,6 +181,7 @@ static void combineWeights(WeightList &Weights) { combineWeightsBySorting(Weights); } + static uint64_t shiftRightAndRound(uint64_t N, int Shift) { assert(Shift >= 0); assert(Shift < 64); @@ -184,6 +189,7 @@ static uint64_t shiftRightAndRound(uint64_t N, int Shift) { return N; return (N >> Shift) + (UINT64_C(1) & N >> (Shift - 1)); } + void Distribution::normalize() { // Early exit for termination nodes. if (Weights.empty()) @@ -345,7 +351,7 @@ void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) { // replaced to be the maximum of all computed scales plus 1. This would // appropriately describe the loop as having a large scale, without skewing // the final frequency computation. - const Scaled64 InifiniteLoopScale(1, 12); + const Scaled64 InfiniteLoopScale(1, 12); // LoopScale == 1 / ExitMass // ExitMass == HeadMass - BackedgeMass @@ -358,7 +364,7 @@ void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) { // its exit mass will be zero. In this case, use an arbitrary scale for the // loop scale. Loop.Scale = - ExitMass.isEmpty() ? InifiniteLoopScale : ExitMass.toScaled().inverse(); + ExitMass.isEmpty() ? InfiniteLoopScale : ExitMass.toScaled().inverse(); DEBUG(dbgs() << " - exit-mass = " << ExitMass << " (" << BlockMass::getFull() << " - " << TotalBackedgeMass << ")\n" @@ -523,6 +529,22 @@ BlockFrequencyInfoImplBase::getBlockFreq(const BlockNode &Node) const { return 0; return Freqs[Node.Index].Integer; } + +Optional<uint64_t> +BlockFrequencyInfoImplBase::getBlockProfileCount(const Function &F, + const BlockNode &Node) const { + auto EntryCount = F.getEntryCount(); + if (!EntryCount) + return None; + // Use 128 bit APInt to do the arithmetic to avoid overflow. + APInt BlockCount(128, EntryCount.getValue()); + APInt BlockFreq(128, getBlockFreq(Node).getFrequency()); + APInt EntryFreq(128, getEntryFreq()); + BlockCount *= BlockFreq; + BlockCount = BlockCount.udiv(EntryFreq); + return BlockCount.getLimitedValue(); +} + Scaled64 BlockFrequencyInfoImplBase::getFloatingBlockFreq(const BlockNode &Node) const { if (!Node.isValid()) @@ -541,6 +563,7 @@ std::string BlockFrequencyInfoImplBase::getBlockName(const BlockNode &Node) const { return std::string(); } + std::string BlockFrequencyInfoImplBase::getLoopName(const LoopData &Loop) const { return getBlockName(Loop.getHeader()) + (Loop.isIrreducible() ? "**" : "*"); @@ -568,6 +591,7 @@ void IrreducibleGraph::addNodesInLoop(const BFIBase::LoopData &OuterLoop) { addNode(N); indexNodes(); } + void IrreducibleGraph::addNodesInFunction() { Start = 0; for (uint32_t Index = 0; Index < BFI.Working.size(); ++Index) @@ -575,10 +599,12 @@ void IrreducibleGraph::addNodesInFunction() { addNode(Index); indexNodes(); } + void IrreducibleGraph::indexNodes() { for (auto &I : Nodes) Lookup[I.Node.Index] = &I; } + void IrreducibleGraph::addEdge(IrrNode &Irr, const BlockNode &Succ, const BFIBase::LoopData *OuterLoop) { if (OuterLoop && OuterLoop->isHeader(Succ)) @@ -605,7 +631,7 @@ template <> struct GraphTraits<IrreducibleGraph> { static ChildIteratorType child_begin(NodeType *N) { return N->succ_begin(); } static ChildIteratorType child_end(NodeType *N) { return N->succ_end(); } }; -} +} // end namespace llvm /// \brief Find extra irreducible headers. /// |