[LLVMdev] Iterating thru CF edges in a CFG
sabre at nondot.org
Thu Dec 23 11:34:10 PST 2004
On Wed, 22 Dec 2004, Sriraman Tallam wrote:
> I want to instrument every control-flow edge in a CFG. What is the
> best way to do this ? I was thinking of getting a reference to the CFG
> using GraphTraits<Function *>. Is there a simple way to get the CFG
The CFG is implicit and always up to date in LLVM. You should be able to
do something like this (I haven't verified this):
BasicBlock *BB = ...
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
BasicBlock *PredBlock = *PI;
Likewise s/pred/succ/ for successor blocks.
You can treat the CFG as a graph, using standard LLVM graph algorithms,
but for most things it's easier to use pred/succ edges directly.
More information about the llvm-dev