<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 19, 2017 at 10:23 AM, David Majnemer via Phabricator via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">majnemer added inline comments.<br>
<span class=""><br>
<br>
================<br>
Comment at: lib/Transforms/Scalar/LICM.<wbr>cpp:348<br>
+  SmallVector<BasicBlock *, 16> Worklist;<br>
+  DT->getDescendants(N-><wbr>getBlock(), Worklist);<br>
<br>
----------------<br>
</span><span class="">sanjoy wrote:<br>
> majnemer wrote:<br>
> > sanjoy wrote:<br>
> > > `getDescendants` seems to be doing a BFS.  Given that (and that DT is a tree), can you iterate `Worklist` in reverse to get a post order?  If you do this, we'd have to spec `getDescendants` as doing a BFS though (and not just have it be an implementation detail).<br>
> > ><br>
> > > OTOH if you write the BFS by hand (instead of relying on `getDescendents`), you can add an early exit for `CurLoop->contains(BB)`.<br>
> > Do you mean BFS or DFS?<br>
> I meant BFS; since DT is a tree you can do a (slightly) cheaper in-place BFS as:<br>
><br>
> ```<br>
> Order.push_back(N);<br>
> for (int i = 0; i < Order.size(); i++)<br>
>   Order.push_back(N->children())<wbr>;<br>
> ```<br>
><br>
</span>I don't believe reverse iterating a BFS gives you a post-order.<br></blockquote><div>Is your goal just to visit children first or an actual postorder postorder?<br><br></div><div><br></div><div>Reverse BFS on a tree will give a you a "children first" visitation order.  By definition, in fact.</div><div>BFS is all parents before all children.</div><div>reversing the order must give you all children before all parents.</div><div><br></div><div>Examples:<br><br></div><div> 1    2</div><div>3 4  5 6</div><div><br></div><div>BFS = 1 2 3 4 5 6</div><div><br></div><div>6 5 4 3 2 1 = children before parents.<br></div><div><br></div><div><br></div><div>    1 </div><div> 2    3 4</div><div>5 6  7 8</div><div><br></div><div>BFS = 1 2 3 4 5 6 7 8</div><div>reverse of that is still children before parents.</div><div><br></div><div><br></div><div>It is not a valid postorder in that the order of siblings is not related to the order of their children.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5"><br>
<br>
<a href="https://reviews.llvm.org/D35609" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D35609</a><br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div></div>