Iterating thru CF edges in a CFG

Hi,

  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
handle?

Thanks.

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):

#include "llvm/Support/CFG.h"

   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.

-Chris