Basic Block code sample

Hi LLVM Delveloper,
i’ve been working on LLVM and Clang to get basic block information. The CFG supports Visitors (CFG.h) but i might want to ask that is there any code sample available so that i can get the things easily…

Kulkarni Ashish A.
College of engineering, Pune


Example on how to iterate over CFG, take a look at DominanceFrontier.cpp.

You can further implement easily a traverse graph algorithm.

To get definitions before uses (apart from PHI nodes), use ReversePostOrderTraversal:

#include <llvm/ADT/PostOrderIterator.h>

ReversePostOrderTraversal<Function*> rpot((Function )&func);
for (ReversePostOrderTraversal<Function
>::rpo_iterator bi =
rpot.begin(), be = rpot.end(); bi != be; ++bi)