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