[LLVMdev] Fwd: Order of Basic Blocks

Ryan Taylor ryta1203 at gmail.com
Mon Nov 21 10:30:57 PST 2011


---------- Forwarded message ----------
From: Ryan Taylor <ryta1203 at gmail.com>
Date: Mon, Nov 21, 2011 at 10:30 AM
Subject: Re: [LLVMdev] Order of Basic Blocks
To: Benjamin Kramer <benny.kra at googlemail.com>


This worked, though the RPO_iterator apparently wasn't what I was looking
for anyways, it seems it doesn't rreally go top->down.

I have a simple example code, where the block follow this path:

BB0->BB1 (T), BB8 (F)
BB1-> BB2 (T), BB3 (F)
BB2-> BB4
BB3-> BB5
BB4-> BB6
BB5-> BB8 (T), BB5 (F)
BB6-> BB7 (T), BB4 (F)
BB7-> BB8 (T), BB4 (F)
BB8 (end)

So, this is the basic block flow graph. When I iterate using the
ReversePostOrderTraversal iterator, the basic blocks vistied are in this
order:

BB0, BB1, BB3, BB2, BB7, BB6, BB4, BB5, BB8

Can someone explain why this is and how the BBs are stored so that I can
either go top->down or more prefably, depth first search (from the given
graph above)?

Thanks.



On Mon, Nov 21, 2011 at 10:14 AM, Benjamin Kramer
<benny.kra at googlemail.com>wrote:

>
> On 21.11.2011, at 19:07, Ryan Taylor wrote:
>
> > Is there a way to cast the rpo_iterator to a basic block pointer? I need
> to use the functions of the class Basic Block.
>
> Dereference it.
>
> - Ben
>
>
> >
> > On Sun, Nov 20, 2011 at 3:15 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:
> > Sorry, forgot to add group to CC.
> >
> > On Sun, Nov 20, 2011 at 6:14 PM, Ryan Taylor <ryta1203 at gmail.com> wrote:
> > Cameron,
> >
> >   To make it less vague, I would ideally like to traverse top down. I
> believe what you suggested is what I want, I will have a look at it.
> >
> >   Currently, I am iterating over the BBs in a Function, so
> Function::iterator BBitr=F->begin(), BBitrE=F->end();
> BBitr!=BBitrE;++BBitr, does that help clarify what I'm looking for? With
> this current iteration method, I seem to sometimes get top down but other
> times get bottom up and sometimes it starts top down then jumps to the
> bottom and goes bottom up. Is there a reason for this randomness?
> >
> > On Sun, Nov 20, 2011 at 6:10 PM, Cameron Zwarich <zwarich at apple.com>
> wrote:
> > Your question is a bit vague, but you probably want
> ReversePostOrderTraversal from include/llvm/ADT/PostOrderIterator.h.
> >
> > Cameron
> >
> > On Nov 20, 2011, at 3:00 PM, Ryan Taylor wrote:
> >
> > > LLVMers,
> > >
> > >   Is there any way to guarantee iteration of the basic blocks from top
> down or path to path? Currently it looks sort of semi-random, sometimes
> visiting loop heads first and other times loop tails, is there a way I can
> visit the BBs top down or path to path?
> > >
> > > Thank you.
> > > _______________________________________________
> > > LLVM Developers mailing list
> > > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
> >
> >
> >
> > _______________________________________________
> > LLVM Developers mailing list
> > LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111121/13ae3476/attachment.html>


More information about the llvm-dev mailing list