CFG Manipulation is LLVM

Hi,

Is there any API within llvm that provides methods to access the CFG and do some manipulations on the CFG.

Thanks,
Rohith.

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.

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.

Hi Duncan,

Does llvm have any specific methods to build dependenece graphs ?

Thanks,
Rohith.