[cfe-dev] Extracting llvm IR CFG from Clang

John Criswell via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 17 14:06:06 PST 2016


Dear Xiaohui,

I'm not very familiar with the Clang AST, but I suspect the answer is 
no: you probably can't generate LLVM IR for just an arbitrary subset of 
the Clang AST.

That said, if you have the LLVM IR, you can use existing analysis passes 
to loops, control-dependences, and that sort of thing. However, if you 
want to find a CFG for a subset of a Clang AST, then I do not know if 
there is existing code to do that.

Regards,

John Criswell

On 2/17/16 5:02 PM, xiaohui chen wrote:
> 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 
> <mailto: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-llvm|option, 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 list
>>     cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>     http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
>     -- 
>     John Criswell
>     Assistant Professor
>     Department of Computer Science, University of Rochester
>     http://www.cs.rochester.edu/u/criswell
>
>


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160217/87b3b73b/attachment.html>


More information about the cfe-dev mailing list