<div class="gmail_quote">On Thu, Aug 18, 2011 at 10:03 AM, Delesley Hutchins <span dir="ltr"><<a href="mailto:delesley@google.com">delesley@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
AFAICT, the RPO iterator does not do what we need.  For example,<br>
assume we have the following graph (pardon the bad ASCII graphics):<br>
<br>
   /---> (2) ----------\<br>
(1)                     --> (5)<br>
   \---> (3) ---> (4)--/<br>
<br>
I believe the RPO iterator will traverse this graph as 5-2-4-3-1,<br>
which is a standard depth-first post-order traversal.<br>
<br>
What we want is a topological traversal, which is 1-2-3-4-5; every<br>
predecessor of a node must be traversed before the node itself.<br></blockquote><div><br></div><div>What about the reverse of the RPO violates this constraint? 1-3-4-2-5 looks like it satisfies your constraint. I think Jakub is aware that we would have to reverse the order, and was just claiming that such a reversed order satisfied the constraints of a topological ordering.</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Notice that a topological traversal is neither depth-first (that would<br>
be 1-2-5-3-4), nor breadth-first (1-2-3-5-4); we want to ensure that 2<br>
and 4 are traversed before 5.<br>
<br>
This patch does three things to achieve the topological traversal:<br>
(1) Depth-first traversal to identify back-edges and assign depths.<br>
(2) Sort nodes according to depth.<br>
(3) Traversal of the sorted list of nodes.<br>
<span class="HOEnZb"><font color="#888888"><br>
  -DeLesley<br>
</font></span><div class="HOEnZb"><div></div><div class="h5"><br>
On Wed, Aug 17, 2011 at 10:00 PM, Jakob Stoklund Olesen <<a href="mailto:stoklund@2pi.dk">stoklund@2pi.dk</a>> wrote:<br>
><br>
> On Aug 17, 2011, at 9:17 PM, Chandler Carruth wrote:<br>
><br>
> On Wed, Aug 17, 2011 at 8:56 PM, Jakob Stoklund Olesen <<a href="mailto:stoklund@2pi.dk">stoklund@2pi.dk</a>><br>
> wrote:<br>
>><br>
>> On Aug 17, 2011, at 3:52 PM, Delesley Hutchins wrote:<br>
>><br>
>> > This patch adds a topological sort routine for indexed graphs to<br>
>> > llvm/ADT.  This sort routine is currently used to traverse CFGs in<br>
>> > Clang when doing thread safety analysis (patch to be released<br>
>> > shortly).<br>
>><br>
>> Could you explain why we need this in addition to<br>
>> include/llvm/ADT/PostOrderIterator.h?<br>
><br>
> FYI, I'm not terribly familiar w/ PostOrderIterator (so maybe it would<br>
> actually serve here), but JSYK, the motivating use case is in a Clang<br>
> patch: <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110815/045262.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110815/045262.html</a><br>
><br>
> I see.<br>
> AFAICT, the existing RPO iterator will give you the exact same ordering of<br>
> blocks, at least it will give you a topo-sort of the graph after removing<br>
> back-edges.<br>
> You can detect back-edges by keeping track of visited blocks in a BitVector<br>
> as you iterate through the RPO.<br>
> /jakob<br>
><br>
<br>
<br>
<br>
</div></div><div class="HOEnZb"><div></div><div class="h5">--<br>
DeLesley Hutchins | Software Engineer | <a href="mailto:delesley@google.com">delesley@google.com</a> | <a href="tel:505-206-0315" value="+15052060315">505-206-0315</a><br>
</div></div></blockquote></div><br>