[LLVMdev] Help : CFG in LLVM ( Implementation)
Misha Brukman
brukman at uiuc.edu
Wed Nov 10 09:11:58 PST 2004
On Wed, Nov 10, 2004 at 06:39:12AM -0800, Tanu Sharma wrote:
> I am a new user of LLVM and have been trying to find how Control Flow
> Graphs are implemented in it.I wish to get access to the internal
> structures of CFG and learn how LLVM makes them.
LLVM does not need to construct a CFG, because the CFG is an explicit
integral part of the program representation. Every BasicBlock ends with
a terminator instruction, which is one of these:
http://llvm.cs.uiuc.edu/docs/LangRef.html#terminators
Each terminator has explicit target BasicBlocks (if any), which means
you can navigate the CFG directly using the terminators or you can use
the API pred_begin/end() and succ_begin/end() found in
llvm/include/llvm/Support/CFG.h
If you are not sure how to use them, search the code base for one of
them to find example usage.
> Is there any existing tool that LLVM provides that makes CFG out of
> bytecode ?
Above I described how to navigate the CFG within your compiler pass. If
you mean "how can I visualize the CFG", then the answer is:
$ analyze -print-cfg file.bc
or
$ analyze -print-cfg-only file.bc
which will produce a 'dot' file. You will need to get 'dot' (search for
graphviz package) which can convert .dot files into postscript.
--
Misha Brukman :: http://misha.brukman.net :: http://llvm.cs.uiuc.edu
More information about the llvm-dev
mailing list