[LLVMdev] CFG Manipulation is LLVM

Duncan Sands baldrick at free.fr
Fri Mar 26 01:50:50 PDT 2010


Hi Rohith,

>      I'm actually working on building a dependence graph . I'm not able
> to find the methods which llvm uses to build the CFG. Is it possible to
> use the same functions do build a dependence graph ( i Know the CFG
> nodes are basicblocks where as dependence graph nodes will be variables)?.

LLVM does not have explicit methods to build the CFG because it is created
automatically when you build the IR.  For example, each basic block must
finish with a "terminator" instruction (branch, return, invoke, etc).  Each
terminator instruction specifies which other basic blocks control can reach.
Thus to find the successor nodes of a basic block, you look at the last
instruction of the basic block, and see where it says control flows to.
There are of course helper methods that do this for you.  Predecessors are
also automatically set up.

Similarly, the list of uses of "variables" (aka instructions) is maintained
automatically.

Ciao,

Duncan.

PS: Please reply to the list rather than me personally.  I've CC'd the list.

>
> Thanks,
> Rohith.
>
> On Thu, Mar 18, 2010 at 4:55 PM, Rohith Goparaju <rgoparaj at umail.iu.edu
> <mailto:rgoparaj at umail.iu.edu>> wrote:
>
>       Thanks Duncan...That was helpful.
>
>
>     On Thu, Mar 18, 2010 at 4:54 AM, Duncan Sands <baldrick at free.fr
>     <mailto:baldrick at free.fr>> wrote:
>
>         Hi Rohith,
>
>          >     Is there any API within llvm that provides methods to
>         access the CFG
>          > and do some manipulations on the CFG.
>
>         the CFG is built into the LLVM IR: given a basic block (i.e. a
>         node of the
>         CFG) you can iterate over its successors and predecessors using
>         the methods
>         in include/llvm/Support/CFG.h.  To modify the CFG you have to
>         modify the
>         basic blocks, usually by changing the basic block terminator.
>
>         Ciao,
>
>         Duncan.
>         _______________________________________________
>         LLVM Developers mailing list
>         LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu>
>         http://llvm.cs.uiuc.edu
>         http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>




More information about the llvm-dev mailing list