<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Dear Xiaohui,<br>
      <br>
      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.<br>
      <br>
      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.<br>
      <br>
      Regards,<br>
      <br>
      John Criswell<br>
      <br>
      On 2/17/16 5:02 PM, xiaohui chen wrote:<br>
    </div>
    <blockquote
cite="mid:CALpPt0-nEx=2_C3+0f3zDE+EfaAe9VLjZDjFo94SnJSTLh6c0A@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">Dear John,
        <div><br>
        </div>
        <div>Thanks for your reply! I understand. </div>
        <div><br>
        </div>
        <div>My question is more subtle. Could I obtain the LLVM IR for
          a specific stmt ?</div>
        <div><br>
        </div>
        <div>For example, </div>
        <div><br>
        </div>
        <div>void foo()</div>
        <div>{</div>
        <div>      ...  // some stmts</div>
        <div><br>
        </div>
        <div>     for(...) {</div>
        <div>       ...</div>
        <div>    }</div>
        <div><br>
        </div>
        <div>     ... //  some stmts</div>
        <div>} </div>
        <div><br>
        </div>
        <div>Once I built the Clang AST, there is a node to represent
          that for-loop, say nodeFor. </div>
        <div><br>
        </div>
        <div>Then  I could take nodeFor as parameter to call buildCFG()
          to generate the source code level  CFG of that for-loop.</div>
        <div><br>
        </div>
        <div>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.</div>
        <div>Hope my question is clear.</div>
        <div><br>
        </div>
        <div>Sincerely</div>
        <div>xiaohui </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Wed, Feb 17, 2016 at 12:27 PM, John
          Criswell <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:jtcriswel@gmail.com" target="_blank">jtcriswel@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote">
            <div><span class="">
                <div>On 2/15/16 8:57 PM, xiaohui chen via cfe-dev wrote:<br>
                </div>
                <blockquote type="cite">
                  <div dir="ltr">Dear All:
                    <div><br>
                    </div>
                    <div><span>I am working on Clang/LLVM and interested
                        to know if there is a programmatic way to
                        extract the CFG of a specific</span></div>
                    <div><span>node in AST like a for loop? </span></div>
                    <div><span><br>
                      </span></div>
                    <div><span> I am aware of </span><code>-emit-llvm</code><span>option,

                        but it will apply on the whole TU.</span><span><br>
                      </span></div>
                    <div><span><br>
                      </span></div>
                    <div><span>For example,</span></div>
                    <div><span>we could use  </span><span>CFG</span><span>::</span><span>buildCFG
                        to extract the source level CFG of a specific
                        node.</span></div>
                    <div><span>Is there a counterpart API to extract the
                        LLVM IR level CFG of a specific node?</span></div>
                  </div>
                </blockquote>
                <br>
              </span> 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.<br>
              <br>
              Regards,<br>
              <br>
              John Criswell<br>
              <br>
              <blockquote type="cite">
                <div dir="ltr">
                  <div><span><br>
                    </span></div>
                  <div><span>Sincerely</span></div>
                  <div><span>xiaohui</span></div>
                </div>
                <br>
                <fieldset></fieldset>
                <br>
                <pre>_______________________________________________
cfe-dev mailing list
<a moz-do-not-send="true" href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>
<a moz-do-not-send="true" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><span class="HOEnZb">
</span></pre>
                <span class="HOEnZb"> </span></blockquote>
              <span class="HOEnZb"> <br>
                <br>
                <pre cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a moz-do-not-send="true" href="http://www.cs.rochester.edu/u/criswell" target="_blank">http://www.cs.rochester.edu/u/criswell</a></pre>
              </span></div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>