Depth First Sort of Machine Basic Blocks just before emitting code

For nefarious reasons I won't go into (this is for a quick hack that will be thrown away in a week or two), I'd like my Asm printer to get MBBs in a depth first order.

Is there an existing pass or function that will let me do this easily?

Thanks,

Dan

Dan,
I was not able to find a simple way to do this outside of writing my
own DFS traversal using the succ nodes.

Micah

Check out "llvm/ADT/DepthFirstIterator.h", it lets you iterate over arbitrary graphs (including CFGs) in depth first order. grep the source base for df_begin etc to see examples of use.

-Chris

That looks like it does a preorder depth first traversal (I think). I'm looking for postorder. Is there a trivial transform between the two? (I don't know one.)

Am I wrong about the preorder/postorder? If not, anything lurking for postorder traversal?

Thanks,

Dan

po_iterator (ADT/PostOrderIterator.h) ?

Too obvious!

Thanks

Dan

I have used df_iterator (also idf_iterator, which I had to patch up a bit), and po_iterator. They have saved much coding, so many thanks to Chris and everyone for these.

John