[cfe-dev] Extracting llvm IR CFG from Clang

xiaohui chen via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 17 14:02:29 PST 2016


Dear John,

Thanks for your reply! I understand.

My question is more subtle. Could I obtain the LLVM IR for a specific stmt ?

For example,

void foo()
{
      ...  // some stmts

     for(...) {
       ...
    }

     ... //  some stmts
}

Once I built the Clang AST, there is a node to represent that for-loop, say
nodeFor.

Then  I could take nodeFor as parameter to call buildCFG() to generate the
source code level  CFG of that for-loop.

Could I use a similar method to get the LLVM IR for that for-loop? Again I
do not want to generate LLVM IR for other stmts other than that for-loop.
Hope my question is clear.

Sincerely
xiaohui





On Wed, Feb 17, 2016 at 12:27 PM, John Criswell <jtcriswel at gmail.com> wrote:

> On 2/15/16 8:57 PM, xiaohui chen via cfe-dev wrote:
>
> Dear All:
>
> I am working on Clang/LLVM and interested to know if there is a
> programmatic way to extract the CFG of a specific
> node in AST like a for loop?
>
>  I am aware of -emit-llvmoption, but it will apply on the whole TU.
>
> For example,
> we could use  CFG::buildCFG to extract the source level CFG of a specific
> node.
> Is there a counterpart API to extract the LLVM IR level CFG of a specific
> node?
>
>
> The LLVM IR expresses each function as a set of basic blocks with an
> explicit CFG.  In other words, the LLVM IR encodes the CFG of each function
> explicitly.  If you have the LLVM IR of a function, you already have the
> CFG.
>
> Regards,
>
> John Criswell
>
>
> Sincerely
> xiaohui
>
>
> _______________________________________________
> cfe-dev mailing listcfe-dev at lists.llvm.orghttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
>
> --
> John Criswell
> Assistant Professor
> Department of Computer Science, University of Rochesterhttp://www.cs.rochester.edu/u/criswell
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160217/b6746509/attachment.html>


More information about the cfe-dev mailing list