[llvm] r235026 - Add range iterators for post order and inverse post order. Use them
David Blaikie
dblaikie at gmail.com
Wed Apr 15 11:00:46 PDT 2015
On Wed, Apr 15, 2015 at 10:41 AM, Daniel Berlin <dberlin at dberlin.org> wrote:
> Author: dannyb
> Date: Wed Apr 15 12:41:42 2015
> New Revision: 235026
>
> URL: http://llvm.org/viewvc/llvm-project?rev=235026&view=rev
> Log:
> Add range iterators for post order and inverse post order. Use them
>
> Modified:
> llvm/trunk/include/llvm/ADT/PostOrderIterator.h
> llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h
> llvm/trunk/include/llvm/Analysis/RegionInfoImpl.h
> llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
> llvm/trunk/lib/CodeGen/EarlyIfConversion.cpp
> llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp
> llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
> llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
>
> Modified: llvm/trunk/include/llvm/ADT/PostOrderIterator.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/PostOrderIterator.h?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/ADT/PostOrderIterator.h (original)
> +++ llvm/trunk/include/llvm/ADT/PostOrderIterator.h Wed Apr 15 12:41:42
> 2015
> @@ -18,6 +18,7 @@
>
> #include "llvm/ADT/GraphTraits.h"
> #include "llvm/ADT/SmallPtrSet.h"
> +#include "llvm/ADT/iterator_range.h"
> #include <set>
> #include <vector>
>
> @@ -178,6 +179,10 @@ po_iterator<T> po_begin(T G) { return po
> template <class T>
> po_iterator<T> po_end (T G) { return po_iterator<T>::end(G); }
>
> +template <class T> iterator_range<po_iterator<T>> post_order(T G) {
> + return iterator_range<po_iterator<T>>(po_begin(G), po_end(G));
> +}
> +
> // Provide global definitions of external postorder iterators...
> template<class T, class SetType=std::set<typename
> GraphTraits<T>::NodeType*> >
> struct po_ext_iterator : public po_iterator<T, SetType, true> {
> @@ -195,6 +200,12 @@ po_ext_iterator<T, SetType> po_ext_end(T
> return po_ext_iterator<T, SetType>::end(G, S);
> }
>
> +template <class T, class SetType>
> +iterator_range<po_ext_iterator<T, SetType>> post_order_ext(T G, SetType
> &S) {
> + return iterator_range<po_ext_iterator<T, SetType>>(po_ext_begin(G, S),
> + po_ext_end(G, S));
>
You can probably use "make_range" here (& elsewhere in this patch)
& did you mean to pass 'G' by value? (I would've expected const ref, I
guess, but not sure what sort of thing it is - oh, I see, it's a pointer?
Perhaps "T *G" to enforce that if that's reasonable?)
> +}
> +
> // Provide global definitions of inverse post order iterators...
> template <class T,
> class SetType = std::set<typename GraphTraits<T>::NodeType*>,
> @@ -214,6 +225,11 @@ ipo_iterator<T> ipo_end(T G){
> return ipo_iterator<T>::end(G);
> }
>
> +template <class T>
> +iterator_range<ipo_iterator<T>> inverse_post_order(T G, bool Reverse =
> false) {
> + return iterator_range<ipo_iterator<T>>(ipo_begin(G, Reverse),
> ipo_end(G));
> +}
> +
> // Provide global definitions of external inverse postorder iterators...
> template <class T,
> class SetType = std::set<typename GraphTraits<T>::NodeType*> >
> @@ -234,6 +250,13 @@ ipo_ext_iterator<T, SetType> ipo_ext_end
> return ipo_ext_iterator<T, SetType>::end(G, S);
> }
>
> +template <class T, class SetType>
> +iterator_range<ipo_ext_iterator<T, SetType>>
> +inverse_post_order_ext(T G, SetType &S) {
> + return iterator_range<ipo_ext_iterator<T, SetType>>(ipo_ext_begin(G, S),
> + ipo_ext_end(G, S));
> +}
> +
>
> //===--------------------------------------------------------------------===//
> // Reverse Post Order CFG iterator code
>
> //===--------------------------------------------------------------------===//
>
> Modified: llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h (original)
> +++ llvm/trunk/include/llvm/Analysis/LoopInfoImpl.h Wed Apr 15 12:41:42
> 2015
> @@ -498,10 +498,9 @@ Analyze(DominatorTreeBase<BlockT> &DomTr
>
> // Postorder traversal of the dominator tree.
> DomTreeNodeBase<BlockT>* DomRoot = DomTree.getRootNode();
> - for (po_iterator<DomTreeNodeBase<BlockT>*> DomIter = po_begin(DomRoot),
> - DomEnd = po_end(DomRoot); DomIter != DomEnd; ++DomIter) {
> + for (auto DomNode : post_order(DomRoot)) {
>
> - BlockT *Header = DomIter->getBlock();
> + BlockT *Header = DomNode->getBlock();
> SmallVector<BlockT *, 4> Backedges;
>
> // Check each predecessor of the potential loop header.
>
> Modified: llvm/trunk/include/llvm/Analysis/RegionInfoImpl.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/RegionInfoImpl.h?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/RegionInfoImpl.h (original)
> +++ llvm/trunk/include/llvm/Analysis/RegionInfoImpl.h Wed Apr 15 12:41:42
> 2015
> @@ -714,10 +714,8 @@ void RegionInfoBase<Tr>::scanForRegions(
> // regions from the bottom of the dominance tree. If the small regions
> are
> // detected first, detection of bigger regions is faster, as we can jump
> // over the small regions.
> - for (po_iterator<DomTreeNodeT *> FI = po_begin(N), FE = po_end(N); FI
> != FE;
> - ++FI) {
> - findRegionsWithEntry(FI->getBlock(), ShortCut);
> - }
> + for (auto DomNode : post_order(N))
> + findRegionsWithEntry(DomNode->getBlock(), ShortCut);
> }
>
> template <class Tr>
>
> Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
> +++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Wed Apr 15 12:41:42
> 2015
> @@ -507,25 +507,23 @@ bool BranchProbabilityInfo::runOnFunctio
>
> // Walk the basic blocks in post-order so that we can build up state
> about
> // the successors of a block iteratively.
> - for (po_iterator<BasicBlock *> I = po_begin(&F.getEntryBlock()),
> - E = po_end(&F.getEntryBlock());
> - I != E; ++I) {
> - DEBUG(dbgs() << "Computing probabilities for " << I->getName() <<
> "\n");
> - if (calcUnreachableHeuristics(*I))
> + for (auto BB : post_order(&F.getEntryBlock())) {
> + DEBUG(dbgs() << "Computing probabilities for " << BB->getName() <<
> "\n");
> + if (calcUnreachableHeuristics(BB))
> continue;
> - if (calcMetadataWeights(*I))
> + if (calcMetadataWeights(BB))
> continue;
> - if (calcColdCallHeuristics(*I))
> + if (calcColdCallHeuristics(BB))
> continue;
> - if (calcLoopBranchHeuristics(*I))
> + if (calcLoopBranchHeuristics(BB))
> continue;
> - if (calcPointerHeuristics(*I))
> + if (calcPointerHeuristics(BB))
> continue;
> - if (calcZeroHeuristics(*I))
> + if (calcZeroHeuristics(BB))
> continue;
> - if (calcFloatingPointHeuristics(*I))
> + if (calcFloatingPointHeuristics(BB))
> continue;
> - calcInvokeHeuristics(*I);
> + calcInvokeHeuristics(BB);
> }
>
> PostDominatedByUnreachable.clear();
>
> Modified: llvm/trunk/lib/CodeGen/EarlyIfConversion.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/EarlyIfConversion.cpp?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/EarlyIfConversion.cpp (original)
> +++ llvm/trunk/lib/CodeGen/EarlyIfConversion.cpp Wed Apr 15 12:41:42 2015
> @@ -797,9 +797,8 @@ bool EarlyIfConverter::runOnMachineFunct
> // if-conversion in a single pass. The tryConvertIf() function may erase
> // blocks, but only blocks dominated by the head block. This makes it
> safe to
> // update the dominator tree while the post-order iterator is still
> active.
> - for (po_iterator<MachineDominatorTree*>
> - I = po_begin(DomTree), E = po_end(DomTree); I != E; ++I)
> - if (tryConvertIf(I->getBlock()))
> + for (auto DomNode : post_order(DomTree))
> + if (tryConvertIf(DomNode->getBlock()))
> Changed = true;
>
> return Changed;
>
> Modified: llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineTraceMetrics.cpp Wed Apr 15 12:41:42 2015
> @@ -463,13 +463,11 @@ void MachineTraceMetrics::Ensemble::comp
> // Run an upwards post-order search for the trace start.
> Bounds.Downward = false;
> Bounds.Visited.clear();
> - typedef ipo_ext_iterator<const MachineBasicBlock*, LoopBounds> UpwardPO;
> - for (UpwardPO I = ipo_ext_begin(MBB, Bounds), E = ipo_ext_end(MBB,
> Bounds);
> - I != E; ++I) {
> + for (auto I : inverse_post_order_ext(MBB, Bounds)) {
> DEBUG(dbgs() << " pred for BB#" << I->getNumber() << ": ");
> TraceBlockInfo &TBI = BlockInfo[I->getNumber()];
> // All the predecessors have been visited, pick the preferred one.
> - TBI.Pred = pickTracePred(*I);
> + TBI.Pred = pickTracePred(I);
> DEBUG({
> if (TBI.Pred)
> dbgs() << "BB#" << TBI.Pred->getNumber() << '\n';
> @@ -477,19 +475,17 @@ void MachineTraceMetrics::Ensemble::comp
> dbgs() << "null\n";
> });
> // The trace leading to I is now known, compute the depth resources.
> - computeDepthResources(*I);
> + computeDepthResources(I);
> }
>
> // Run a downwards post-order search for the trace end.
> Bounds.Downward = true;
> Bounds.Visited.clear();
> - typedef po_ext_iterator<const MachineBasicBlock*, LoopBounds>
> DownwardPO;
> - for (DownwardPO I = po_ext_begin(MBB, Bounds), E = po_ext_end(MBB,
> Bounds);
> - I != E; ++I) {
> + for (auto I : post_order_ext(MBB, Bounds)) {
> DEBUG(dbgs() << " succ for BB#" << I->getNumber() << ": ");
> TraceBlockInfo &TBI = BlockInfo[I->getNumber()];
> // All the successors have been visited, pick the preferred one.
> - TBI.Succ = pickTraceSucc(*I);
> + TBI.Succ = pickTraceSucc(I);
> DEBUG({
> if (TBI.Succ)
> dbgs() << "BB#" << TBI.Succ->getNumber() << '\n';
> @@ -497,7 +493,7 @@ void MachineTraceMetrics::Ensemble::comp
> dbgs() << "null\n";
> });
> // The trace leaving I is now known, compute the height resources.
> - computeHeightResources(*I);
> + computeHeightResources(I);
> }
> }
>
>
> Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp (original)
> +++ llvm/trunk/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp Wed Apr
> 15 12:41:42 2015
> @@ -652,8 +652,7 @@ void llvm::ComputeUsesVAFloatArgument(co
> if (FT->isVarArg() && !MMI->usesVAFloatArgument()) {
> for (unsigned i = 0, e = I.getNumArgOperands(); i != e; ++i) {
> Type* T = I.getArgOperand(i)->getType();
> - for (po_iterator<Type*> i = po_begin(T), e = po_end(T);
> - i != e; ++i) {
> + for (auto i : post_order(T)) {
> if (i->isFloatingPointTy()) {
> MMI->setUsesVAFloatArgument(true);
> return;
>
> Modified: llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp?rev=235026&r1=235025&r2=235026&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp (original)
> +++ llvm/trunk/lib/Transforms/Vectorize/SLPVectorizer.cpp Wed Apr 15
> 12:41:42 2015
> @@ -3101,9 +3101,7 @@ struct SLPVectorizer : public FunctionPa
> // delete instructions.
>
> // Scan the blocks in the function in post order.
> - for (po_iterator<BasicBlock*> it = po_begin(&F.getEntryBlock()),
> - e = po_end(&F.getEntryBlock()); it != e; ++it) {
> - BasicBlock *BB = *it;
> + for (auto BB : post_order(&F.getEntryBlock())) {
> // Vectorize trees that end at stores.
> if (unsigned count = collectStores(BB, R)) {
> (void)count;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150415/90b25186/attachment.html>
More information about the llvm-commits
mailing list