First time!

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

First time!

aditya vishnubhotla
Hi!

I want to know

How to count the number of predecessors for each basic
block?

Thank You



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: First time!

Prabhat Kumar Saraswat
Hi aditya,
There are two ways to cound the number of predecessors for each basic block.
You can generate the control flow graph using the CallGraphScc pass with the granularity of basic block and can simply traverse the graph bottom up till the root. The number of nodes encountered would be the number of predecessors.

The second way would be to use the special ;preds marker in the llvm IR. Each basic block starts with this line which details the name of its predecessor blocks

for example

bb5:   ; preds bb2, bb3

thus bb5 is preceeded by bb2 and bb3.

but, one word of caution, even bb2 and bb3 can be preceeded by some other basic blocks, thus the count for bb5 (number of predecessors) won't be 2, but would be more (depends upon the predecessors of bb2 and bb3).

You can also try to utilize the branching info at the end of each basic block in llvmIR of the source.

I am working on something similar, do let me know if u need some specific information.

Regards
Prabhat



On Dec 20, 2007 11:36 AM, aditya vishnubhotla <[hidden email]> wrote:
Hi!

I want to know

How to count the number of predecessors for each basic
block?

Thank You



     ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: First time!

aditya vishnubhotla
hi prabhat,
how to extract the arguements(number of arguements
also) of the remarks statement(regarding
predecessors)?
 in your example i want to get my answer as 2!
thank you
aditya

--- Prabhat Kumar Saraswat
<[hidden email]> wrote:

> Hi aditya,
> There are two ways to cound the number of
> predecessors for each basic block.
>
> You can generate the control flow graph using the
> CallGraphScc pass with the
> granularity of basic block and can simply traverse
> the graph bottom up till
> the root. The number of nodes encountered would be
> the number of
> predecessors.
>
> The second way would be to use the special ;preds
> marker in the llvm IR.
> Each basic block starts with this line which details
> the name of its
> predecessor blocks
>
> for example
>
> bb5:   ; preds bb2, bb3
>
> thus bb5 is preceeded by bb2 and bb3.
>
> but, one word of caution, even bb2 and bb3 can be
> preceeded by some other
> basic blocks, thus the count for bb5 (number of
> predecessors) won't be 2,
> but would be more (depends upon the predecessors of
> bb2 and bb3).
>
> You can also try to utilize the branching info at
> the end of each basic
> block in llvmIR of the source.
>
> I am working on something similar, do let me know if
> u need some specific
> information.
>
> Regards
> Prabhat
>
>
>
> On Dec 20, 2007 11:36 AM, aditya vishnubhotla
> <[hidden email]> wrote:
>
> > Hi!
> >
> > I want to know
> >
> > How to count the number of predecessors for each
> basic
> > block?
> >
> > Thank You
> >
> >
> >
> >
> >
>
____________________________________________________________________________________

> > Never miss a thing.  Make Yahoo your home page.
> > http://www.yahoo.com/r/hs
> > _______________________________________________
> > LLVM Developers mailing list
> > [hidden email]        
> http://llvm.cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> >
> > _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page.
http://www.yahoo.com/r/hs
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: First time!

Devang Patel
In reply to this post by aditya vishnubhotla

On Dec 20, 2007, at 2:36 AM, aditya vishnubhotla wrote:

> Hi!
>
> I want to know
>
> How to count the number of predecessors for each basic
> block?

My obvious question is what are you trying to do ?

One way to count predecessor for a basic block BB is

        unsigned count = 0;
        for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; +
+PI)
          ++count;


pred_iteraor, pred_begin, pred_end etc.. are available through llvm/
Support/CFG.h

-
Devang
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: First time!

Chris Lattner
In reply to this post by aditya vishnubhotla
On Thu, 20 Dec 2007, aditya vishnubhotla wrote:
> I want to know
> How to count the number of predecessors for each basic
> block?

Use:

#include "llvm/Support/CFG.h"

   for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++I) {
     BasicBlock *PredBB = *PI;
     ..
   }

to walk basic block predecessors.  Similarly, use succ_* for successors.

You might find this section useful:
http://llvm.org/docs/ProgrammersManual.html#common

-Chris

--
http://nondot.org/sabre/
http://llvm.org/
_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev