[cfe-dev] basic block traversal for conditions and loops

Anna Zaks ganna at apple.com
Wed Feb 6 10:26:29 PST 2013


CFG is a graph and llvm GraphTraits for it exist. This should allow you to use llvm graph traversal algorithms.

You could also traverse it directly by relying on the iterators of CFG and CFGBlock. For example, UninitializedValues.cpp uses such iterators:
    for (CFG::const_iterator BI = cfg.begin(), BE = cfg.end(); BI != BE; ++BI) {
      unsigned BlockID = Block->getBlockID();
      ...
        for (CFGBlock::const_succ_iterator I = Block->succ_begin(),
             E = Block->succ_end(); I != E; ++I) {

Unlike LLVM, we do not have any direct representation of loops in clang. However, we do have support for dominators, see Dominators.h.

You can visualize the CFG with DebugChecker, which should be mentioned in clang/docs/analyzer/DebugChecks.txt.

Anna. 
On Feb 5, 2013, at 8:10 PM, Rajendra <rks at cse.iitb.ac.in> wrote:

> Any pointers on how to traverse CFG for loops? or How to find entry and exit
> point of loop? 
> Any clang source code where it does so?
> 
> 
> 
> --
> View this message in context: http://clang-developers.42468.n3.nabble.com/basic-block-traversal-for-conditions-and-loops-tp4030231p4030308.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list