[llvm-commits] [PATCH] Added topological graph sort routine to llvm/ADT

Jakob Stoklund Olesen stoklund at 2pi.dk
Thu Aug 18 10:28:55 PDT 2011


On Aug 18, 2011, at 10:17 AM, Chandler Carruth wrote:

> On Thu, Aug 18, 2011 at 10:03 AM, Delesley Hutchins <delesley at google.com> wrote:
> AFAICT, the RPO iterator does not do what we need.  For example,
> assume we have the following graph (pardon the bad ASCII graphics):
> 
>   /---> (2) ----------\
> (1)                     --> (5)
>   \---> (3) ---> (4)--/
> 
> I believe the RPO iterator will traverse this graph as 5-2-4-3-1,
> which is a standard depth-first post-order traversal.
> 
> What we want is a topological traversal, which is 1-2-3-4-5; every
> predecessor of a node must be traversed before the node itself.
> 
> 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.

Right, the 'R' in RPO stands for 'reverse'. Sorry if that wasn't clear.

See the ReversePostOrderTraversal class in the PostOrderIterator.h header file.

Given a DAG, it is easy to see that A --> B implies A > B in the DFS post-order. Thus, A < B in the reverse post-order.

/jakob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110818/766cc6d4/attachment.html>


More information about the llvm-commits mailing list