diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 10:51:19 +0000 |
commit | eb11fae6d08f479c0799db45860a98af528fa6e7 (patch) | |
tree | 44d492a50c8c1a7eb8e2d17ea3360ec4d066f042 /lib/Analysis/BlockFrequencyInfoImpl.cpp | |
parent | b8a2042aa938069e862750553db0e4d82d25822c (diff) |
Notes
Diffstat (limited to 'lib/Analysis/BlockFrequencyInfoImpl.cpp')
-rw-r--r-- | lib/Analysis/BlockFrequencyInfoImpl.cpp | 107 |
1 files changed, 56 insertions, 51 deletions
diff --git a/lib/Analysis/BlockFrequencyInfoImpl.cpp b/lib/Analysis/BlockFrequencyInfoImpl.cpp index 7e323022d9ce..3d095068e7ff 100644 --- a/lib/Analysis/BlockFrequencyInfoImpl.cpp +++ b/lib/Analysis/BlockFrequencyInfoImpl.cpp @@ -17,6 +17,7 @@ #include "llvm/ADT/GraphTraits.h" #include "llvm/ADT/None.h" #include "llvm/ADT/SCCIterator.h" +#include "llvm/Config/llvm-config.h" #include "llvm/IR/Function.h" #include "llvm/Support/BlockFrequency.h" #include "llvm/Support/BranchProbability.h" @@ -73,7 +74,7 @@ using LoopData = BlockFrequencyInfoImplBase::LoopData; using Weight = BlockFrequencyInfoImplBase::Weight; using FrequencyData = BlockFrequencyInfoImplBase::FrequencyData; -/// \brief Dithering mass distributer. +/// Dithering mass distributer. /// /// This class splits up a single mass into portions by weight, dithering to /// spread out error. No mass is lost. The dithering precision depends on the @@ -155,9 +156,9 @@ static void combineWeight(Weight &W, const Weight &OtherW) { static void combineWeightsBySorting(WeightList &Weights) { // Sort so edges to the same node are adjacent. - std::sort(Weights.begin(), Weights.end(), - [](const Weight &L, - const Weight &R) { return L.TargetNode < R.TargetNode; }); + llvm::sort(Weights.begin(), Weights.end(), + [](const Weight &L, + const Weight &R) { return L.TargetNode < R.TargetNode; }); // Combine adjacent edges. WeightList::iterator O = Weights.begin(); @@ -276,7 +277,7 @@ void BlockFrequencyInfoImplBase::clear() { Loops.clear(); } -/// \brief Clear all memory not needed downstream. +/// Clear all memory not needed downstream. /// /// Releases all memory not used downstream. In particular, saves Freqs. static void cleanup(BlockFrequencyInfoImplBase &BFI) { @@ -315,13 +316,13 @@ bool BlockFrequencyInfoImplBase::addToDist(Distribution &Dist, #endif if (isLoopHeader(Resolved)) { - DEBUG(debugSuccessor("backedge")); + LLVM_DEBUG(debugSuccessor("backedge")); Dist.addBackedge(Resolved, Weight); return true; } if (Working[Resolved.Index].getContainingLoop() != OuterLoop) { - DEBUG(debugSuccessor(" exit ")); + LLVM_DEBUG(debugSuccessor(" exit ")); Dist.addExit(Resolved, Weight); return true; } @@ -333,7 +334,7 @@ bool BlockFrequencyInfoImplBase::addToDist(Distribution &Dist, "unhandled irreducible control flow"); // Irreducible backedge. Abort. - DEBUG(debugSuccessor("abort!!!")); + LLVM_DEBUG(debugSuccessor("abort!!!")); return false; } @@ -344,7 +345,7 @@ bool BlockFrequencyInfoImplBase::addToDist(Distribution &Dist, "unhandled irreducible control flow"); } - DEBUG(debugSuccessor(" local ")); + LLVM_DEBUG(debugSuccessor(" local ")); Dist.addLocal(Resolved, Weight); return true; } @@ -361,10 +362,10 @@ bool BlockFrequencyInfoImplBase::addLoopSuccessorsToDist( return true; } -/// \brief Compute the loop scale for a loop. +/// Compute the loop scale for a loop. void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) { // Compute loop scale. - DEBUG(dbgs() << "compute-loop-scale: " << getLoopName(Loop) << "\n"); + LLVM_DEBUG(dbgs() << "compute-loop-scale: " << getLoopName(Loop) << "\n"); // Infinite loops need special handling. If we give the back edge an infinite // mass, they may saturate all the other scales in the function down to 1, @@ -390,20 +391,21 @@ void BlockFrequencyInfoImplBase::computeLoopScale(LoopData &Loop) { Loop.Scale = ExitMass.isEmpty() ? InfiniteLoopScale : ExitMass.toScaled().inverse(); - DEBUG(dbgs() << " - exit-mass = " << ExitMass << " (" << BlockMass::getFull() - << " - " << TotalBackedgeMass << ")\n" - << " - scale = " << Loop.Scale << "\n"); + LLVM_DEBUG(dbgs() << " - exit-mass = " << ExitMass << " (" + << BlockMass::getFull() << " - " << TotalBackedgeMass + << ")\n" + << " - scale = " << Loop.Scale << "\n"); } -/// \brief Package up a loop. +/// Package up a loop. void BlockFrequencyInfoImplBase::packageLoop(LoopData &Loop) { - DEBUG(dbgs() << "packaging-loop: " << getLoopName(Loop) << "\n"); + LLVM_DEBUG(dbgs() << "packaging-loop: " << getLoopName(Loop) << "\n"); // Clear the subloop exits to prevent quadratic memory usage. for (const BlockNode &M : Loop.Nodes) { if (auto *Loop = Working[M.Index].getPackagedLoop()) Loop->Exits.clear(); - DEBUG(dbgs() << " - node: " << getBlockName(M.Index) << "\n"); + LLVM_DEBUG(dbgs() << " - node: " << getBlockName(M.Index) << "\n"); } Loop.IsPackaged = true; } @@ -425,7 +427,7 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source, LoopData *OuterLoop, Distribution &Dist) { BlockMass Mass = Working[Source.Index].getMass(); - DEBUG(dbgs() << " => mass: " << Mass << "\n"); + LLVM_DEBUG(dbgs() << " => mass: " << Mass << "\n"); // Distribute mass to successors as laid out in Dist. DitheringDistributer D(Dist, Mass); @@ -435,7 +437,7 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source, BlockMass Taken = D.takeMass(W.Amount); if (W.Type == Weight::Local) { Working[W.TargetNode.Index].getMass() += Taken; - DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr)); + LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr)); continue; } @@ -445,14 +447,14 @@ void BlockFrequencyInfoImplBase::distributeMass(const BlockNode &Source, // Check for a backedge. if (W.Type == Weight::Backedge) { OuterLoop->BackedgeMass[OuterLoop->getHeaderIndex(W.TargetNode)] += Taken; - DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "back")); + LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "back")); continue; } // This must be an exit. assert(W.Type == Weight::Exit); OuterLoop->Exits.push_back(std::make_pair(W.TargetNode, Taken)); - DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "exit")); + LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, "exit")); } } @@ -480,28 +482,28 @@ static void convertFloatingToInteger(BlockFrequencyInfoImplBase &BFI, } // Translate the floats to integers. - DEBUG(dbgs() << "float-to-int: min = " << Min << ", max = " << Max - << ", factor = " << ScalingFactor << "\n"); + LLVM_DEBUG(dbgs() << "float-to-int: min = " << Min << ", max = " << Max + << ", factor = " << ScalingFactor << "\n"); for (size_t Index = 0; Index < BFI.Freqs.size(); ++Index) { Scaled64 Scaled = BFI.Freqs[Index].Scaled * ScalingFactor; BFI.Freqs[Index].Integer = std::max(UINT64_C(1), Scaled.toInt<uint64_t>()); - DEBUG(dbgs() << " - " << BFI.getBlockName(Index) << ": float = " - << BFI.Freqs[Index].Scaled << ", scaled = " << Scaled - << ", int = " << BFI.Freqs[Index].Integer << "\n"); + LLVM_DEBUG(dbgs() << " - " << BFI.getBlockName(Index) << ": float = " + << BFI.Freqs[Index].Scaled << ", scaled = " << Scaled + << ", int = " << BFI.Freqs[Index].Integer << "\n"); } } -/// \brief Unwrap a loop package. +/// Unwrap a loop package. /// /// Visits all the members of a loop, adjusting their BlockData according to /// the loop's pseudo-node. static void unwrapLoop(BlockFrequencyInfoImplBase &BFI, LoopData &Loop) { - DEBUG(dbgs() << "unwrap-loop-package: " << BFI.getLoopName(Loop) - << ": mass = " << Loop.Mass << ", scale = " << Loop.Scale - << "\n"); + LLVM_DEBUG(dbgs() << "unwrap-loop-package: " << BFI.getLoopName(Loop) + << ": mass = " << Loop.Mass << ", scale = " << Loop.Scale + << "\n"); Loop.Scale *= Loop.Mass.toScaled(); Loop.IsPackaged = false; - DEBUG(dbgs() << " => combined-scale = " << Loop.Scale << "\n"); + LLVM_DEBUG(dbgs() << " => combined-scale = " << Loop.Scale << "\n"); // Propagate the head scale through the loop. Since members are visited in // RPO, the head scale will be updated by the loop scale first, and then the @@ -511,8 +513,8 @@ static void unwrapLoop(BlockFrequencyInfoImplBase &BFI, LoopData &Loop) { Scaled64 &F = Working.isAPackage() ? Working.getPackagedLoop()->Scale : BFI.Freqs[N.Index].Scaled; Scaled64 New = Loop.Scale * F; - DEBUG(dbgs() << " - " << BFI.getBlockName(N) << ": " << F << " => " << New - << "\n"); + LLVM_DEBUG(dbgs() << " - " << BFI.getBlockName(N) << ": " << F << " => " + << New << "\n"); F = New; } } @@ -544,7 +546,7 @@ void BlockFrequencyInfoImplBase::finalizeMetrics() { cleanup(*this); // Print out the final stats. - DEBUG(dump()); + LLVM_DEBUG(dump()); } BlockFrequency @@ -567,7 +569,7 @@ BlockFrequencyInfoImplBase::getProfileCountFromFreq(const Function &F, if (!EntryCount) return None; // Use 128 bit APInt to do the arithmetic to avoid overflow. - APInt BlockCount(128, EntryCount.getValue()); + APInt BlockCount(128, EntryCount.getCount()); APInt BlockFreq(128, Freq); APInt EntryFreq(128, getEntryFreq()); BlockCount *= BlockFreq; @@ -669,7 +671,7 @@ template <> struct GraphTraits<IrreducibleGraph> { } // end namespace llvm -/// \brief Find extra irreducible headers. +/// Find extra irreducible headers. /// /// Find entry blocks and other blocks with backedges, which exist when \c G /// contains irreducible sub-SCCs. @@ -694,7 +696,8 @@ static void findIrreducibleHeaders( // This is an entry block. I->second = true; Headers.push_back(Irr.Node); - DEBUG(dbgs() << " => entry = " << BFI.getBlockName(Irr.Node) << "\n"); + LLVM_DEBUG(dbgs() << " => entry = " << BFI.getBlockName(Irr.Node) + << "\n"); break; } } @@ -702,7 +705,7 @@ static void findIrreducibleHeaders( "Expected irreducible CFG; -loop-info is likely invalid"); if (Headers.size() == InSCC.size()) { // Every block is a header. - std::sort(Headers.begin(), Headers.end()); + llvm::sort(Headers.begin(), Headers.end()); return; } @@ -725,7 +728,8 @@ static void findIrreducibleHeaders( // Store the extra header. Headers.push_back(Irr.Node); - DEBUG(dbgs() << " => extra = " << BFI.getBlockName(Irr.Node) << "\n"); + LLVM_DEBUG(dbgs() << " => extra = " << BFI.getBlockName(Irr.Node) + << "\n"); break; } if (Headers.back() == Irr.Node) @@ -734,10 +738,10 @@ static void findIrreducibleHeaders( // This is not a header. Others.push_back(Irr.Node); - DEBUG(dbgs() << " => other = " << BFI.getBlockName(Irr.Node) << "\n"); + LLVM_DEBUG(dbgs() << " => other = " << BFI.getBlockName(Irr.Node) << "\n"); } - std::sort(Headers.begin(), Headers.end()); - std::sort(Others.begin(), Others.end()); + llvm::sort(Headers.begin(), Headers.end()); + llvm::sort(Others.begin(), Others.end()); } static void createIrreducibleLoop( @@ -745,7 +749,7 @@ static void createIrreducibleLoop( LoopData *OuterLoop, std::list<LoopData>::iterator Insert, const std::vector<const IrreducibleGraph::IrrNode *> &SCC) { // Translate the SCC into RPO. - DEBUG(dbgs() << " - found-scc\n"); + LLVM_DEBUG(dbgs() << " - found-scc\n"); LoopData::NodeList Headers; LoopData::NodeList Others; @@ -806,27 +810,28 @@ void BlockFrequencyInfoImplBase::adjustLoopHeaderMass(LoopData &Loop) { BlockMass LoopMass = BlockMass::getFull(); Distribution Dist; - DEBUG(dbgs() << "adjust-loop-header-mass:\n"); + LLVM_DEBUG(dbgs() << "adjust-loop-header-mass:\n"); for (uint32_t H = 0; H < Loop.NumHeaders; ++H) { auto &HeaderNode = Loop.Nodes[H]; auto &BackedgeMass = Loop.BackedgeMass[Loop.getHeaderIndex(HeaderNode)]; - DEBUG(dbgs() << " - Add back edge mass for node " - << getBlockName(HeaderNode) << ": " << BackedgeMass << "\n"); + LLVM_DEBUG(dbgs() << " - Add back edge mass for node " + << getBlockName(HeaderNode) << ": " << BackedgeMass + << "\n"); if (BackedgeMass.getMass() > 0) Dist.addLocal(HeaderNode, BackedgeMass.getMass()); else - DEBUG(dbgs() << " Nothing added. Back edge mass is zero\n"); + LLVM_DEBUG(dbgs() << " Nothing added. Back edge mass is zero\n"); } DitheringDistributer D(Dist, LoopMass); - DEBUG(dbgs() << " Distribute loop mass " << LoopMass - << " to headers using above weights\n"); + LLVM_DEBUG(dbgs() << " Distribute loop mass " << LoopMass + << " to headers using above weights\n"); for (const Weight &W : Dist.Weights) { BlockMass Taken = D.takeMass(W.Amount); assert(W.Type == Weight::Local && "all weights should be local"); Working[W.TargetNode.Index].getMass() = Taken; - DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr)); + LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr)); } } @@ -837,6 +842,6 @@ void BlockFrequencyInfoImplBase::distributeIrrLoopHeaderMass(Distribution &Dist) BlockMass Taken = D.takeMass(W.Amount); assert(W.Type == Weight::Local && "all weights should be local"); Working[W.TargetNode.Index].getMass() = Taken; - DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr)); + LLVM_DEBUG(debugAssign(*this, D, W.TargetNode, Taken, nullptr)); } } |