<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Guoping,<div><br><div>Yes, you should include a test with your patch. The test should be a part of the clang regression tests - it should be automatically tested when we run $make test. As for how to approach testing here, see the suggestion made by Ted in one of the previous emails to use testing approach similar to how we test LiveVariables analysis. This is not going to be trivial but it is absolutely necessary.</div><div><br></div><div>As for the format of the patch, please see "Making a Patch" in<br><div><a href="http://llvm.org/docs/DeveloperPolicy.html">http://llvm.org/docs/DeveloperPolicy.html</a></div><div><br></div><div>Thanks!</div><div>Anna.<br><div><div><br></div><div>On Oct 13, 2011, at 9:03 PM, Guoping Long wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello<div><br></div><div>   I re-engineered the dominance algorithm. Attached are the cpp/h files and a test input file. There are still several things:</div><div>A. This implementation is done based on various comments pointed out by Ted, Anna, Arjun, et al. While I tried my best to provide a much better version this time, it still may not meet the quality to be a part of Clang. Please let me know if there are any issues on the code. I shall continue to improve it until it's good enough.</div>
<div><br></div><div>B. The dominance algorithm need two basic things. One is the post order iterator of a general graph. As Anna pointed out, Clang already has this facility. So I use it directly to traverse the CFG nodes in reverse post order. The other one is the LLVM's implementation of DominatorTree. This implementation is different from the one in VMCore on two aspects: 1 The dominator implementation in LLVM VMCore is closely coupled with the LLVM IR infrastructure (basic blocks, instructions, etc). The attached implementation mainly suits the CFG graph of Clang. 2. The LLVM implementation used the classical Lengauer-Tarjan algorithm, published in 1979. The attached implementation is based on an improved 2001 paper. For more details please refer to the comments of the code.<br>
<br>C. Shall I also provide the test code for the algorithm? While I know I need to test code, but I am not sure the standard procedures. Please let me know.<br>Thanks.</div><div><br></div><div>--------</div><div>Guoping</div>
<div><br><div class="gmail_quote">2011/10/12 Anna Zaks <span dir="ltr"><<a href="mailto:ganna@apple.com">ganna@apple.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="word-wrap:break-word"><br><div><div class="im"><div>On Oct 12, 2011, at 3:05 PM, Guoping Long wrote:</div><br><blockquote type="cite">Hi, Anna<div><br></div><div>   You are right. Since LLVM already has dominatorTree implementation, it's not very interesting to build the wheel again.</div>
<div><br></div></blockquote></div>LLVM CFG and Clang front end CFG are different. I am not sure if the LLVM dominator tree can be integrated to work with Clang CFG (most likely not). Though, it could be worthwhile to check how it is implemented, both from algorithmic as well as API design points of view.</div>
<div><br></div><div>I think bringing those algorithms into Clang would be useful.</div><div><br></div><div>Cheers,</div><div>Anna.</div><div><div></div><div class="h5"><div><blockquote type="cite"><div>------</div><div>Guoping<br>
<br><div class="gmail_quote">
2011/10/6 Anna Zaks <span dir="ltr"><<a href="mailto:ganna@apple.com" target="_blank">ganna@apple.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">
Hi Guoping,<div><br></div><div>Here are some comments mostly based on review of buildDominanceTree().</div><div><br></div><div><div>This should be extensively tested. I think unit tests(clang/test/unittests) could be a good fit in this case. Please, make tests a part of your next patch.</div>

</div><div><br></div><div>It would be nice if you could provide more expressive API for users of the algorithms. For example, provide reverse post order iterator which can be used by multiple clients instead of using the RPOQueue local variable to store the results.  Similarly for the dominator info, it would be nice to add some API which allows querying if one block dominates another one.. LLVM already has these algorithms implemented. I am not sure if some reuse is possible or not:</div>

<div><a href="http://llvm.org/docs/doxygen/html/PostOrderIterator_8h_source.html" target="_blank">http://llvm.org/docs/doxygen/html/PostOrderIterator_8h_source.html</a></div><div><a href="http://llvm.org/docs/doxygen/html/classllvm_1_1DominatorTree.html" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1DominatorTree.html</a></div>

<div><br></div><div>Other comments:</div><div><div>- A single patch file would be easier to review.</div><div><br></div><div> - If the following if statement needed? (Can a block have null successors?)<br><div>+      if(CFGBlock *B = *I) {</div>

<div><br></div><div> - Is VisitVector needed? Maybe you could use the BlockRPO of the successors instead.</div></div><div><br></div> - Shouldn't Dominator fields be initialized to 0?<div><br></div><div> - 2 components/functions should be pulled out of buildDominanceTree(): buildReversePostorder(), intersect().</div>

<div><div><br></div><div> - I think it would be cleaner to include the paper references as part of method comments/not fields comments.</div></div><div><div><br></div><div> - "That is, dead code CFG blocks are ignored by this algorithm" - I'd remove this comment. The first sentence is clear enough. (I think you are talking about unreachable code here, and dominance analysis are not powerful enough to find all unreachable code.)</div>

</div><div><br></div><div><div>Microscopic style issues:</div><div>   - Comments should use proper punctuation.</div><div><br></div><div>   - You need to insert a space after a comma and before {. For example:  </div><div>

        RPOQueue.push_back(item,BlkBVC); ->  RPOQueue.push_back(item, BlkBVC);</div><div>        if(!VisitVector[BlockID]){ -> if (!VisitVector[BlockID]) {</div><div><br></div><div>   - CFGBlock * getSCCRoot() -> CFGBlock *getSCCRoot()</div>

</div><div><br></div><div>Cheers,</div><div>Anna.</div><div><br></div><div><div><div></div><div><div>On Oct 5, 2011, at 3:44 PM, Guoping Long wrote:</div><br></div></div><blockquote type="cite"><div><div></div>
<div>Thanks Arjun for your feedback. I updated these files (attached).<div>Ted, I am looking forward to your comments.</div><div><br></div><div>------</div><div>Guoping<br><div><br><div class="gmail_quote">2011/10/5 Arjun Singri <span dir="ltr"><<a href="mailto:arjunsingri@gmail.com" target="_blank">arjunsingri@gmail.com</a>></span><br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>1. Use "unsigned int" instead of just "unsigned"</div><div>2. Shouldnt       "CFGStack.pop_back_val(); " on line 45 be outside the "if (AllVisited)" statement?</div>




<div>3. The check on line 76 is unnecessary. If you are at line 76 then the check at line 71 was false which means that the check at 76 is true. So I guess replace "else if" with "else".</div><div>4. typo on line 52</div>




<div><br></div><font color="#888888"><div>Arjun</div></font><div><div></div><div><div><br>

<div class="gmail_quote">On Tue, Oct 4, 2011 at 8:34 PM, Guoping Long <span dir="ltr"><<a href="mailto:longguoping@gmail.com" target="_blank">longguoping@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear Ted<div><br></div><div>   I added two control flow analysis algorithms: One builds the dominance tree for CFG. The other one finds all SCC components within the CFG. Attached is the patch. I integrated these algorithms within the CFG and CFGBlock classes. This is the first time I submit something, so I have some questions:</div>









<div><br></div><div>1 While I would really love to contribute, I am not sure if the code quality is enough. Please let me know any problems with the code so I shall fix them.</div><div>2 These algorithms shall work on any CFG. I am not sure what kind of special test cases should be added. I do wrote an example (in tools/clang/examples) to illustrate how to use these two algorithms. Is it necessary to submit the example into the examples/ directory?</div>









<div>3 I tried my best to follow the code standards and comments. Also, in the comments, I listed the key reference papers which described thorough details of these algorithms. They are the state of the art algorithms as far as I know, and very efficient, although I am not sure my implementation is good or not.</div>









<div><br></div><div>I am looking forward to feedback. I shall fix problems until it meets the quality for actual commit.</div><div>Thanks.</div><div><br></div><div>------------</div><div>Guoping<div><div></div><div>
<br><br><div class="gmail_quote">
2011/10/3 Ted Kremenek <span dir="ltr"><<a href="mailto:kremenek@apple.com" target="_blank">kremenek@apple.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">








Hi Guoping,<br>

<br>
Additions to libAnalysis have largely been demand-driven.  I think we are fine with general contributions to this library that meeting the following criteria:<br>
<br>
(1) Meet the Clang coding conventions and quality expectations.<br>
<br>
(2) Are testable ("make test"), and tests are included in clang/test.<br>
<br>
(3) Performance is acceptable and measurable, or at least documented when algorithms are known to be expensive.<br>
<br>
(4) APIs are well-documented, which can come in the form of good doxygen comments.<br>
<br>
Source-to-source transformations are welcome, and the Clang codebase does contains tools that are source-to-source rewriters.  For example, libRewrite provides low-level functionality for doing textual rewrites of source files using Clang SourceLocations.  Other analysis algorithms are useful as well; we just prefer that they can be regression tested, and the APIs are well-documented (especially if they don't have any real clients in the codebase at present).<br>










<br>
Cheers,<br>
<font color="#888888">Ted<br>
</font><div><div></div><div><br>
On Oct 3, 2011, at 2:40 PM, Guoping Long wrote:<br>
<br>
> Hi,<br>
><br>
>    There are some program analysis algorithms in clang/lib/Analysis directory. I am wandering if there are more algorithms to come or not. Are there some people working on this? What kind of algorithms are welcome to be part of Clang?<br>










><br>
>    I am asking this because I want to help on this part. But I am not sure if source-to-source transformation algorithms are welcome in this community, since many optimization work is done in the LLVM backend. Currently I have implemented to CFG analysis algorithms (building the dominance tree and finding the strong connected components in CFG). I plan to implement more data flow analysis or even pointer analysis algorithms. If these algorithms are useful to people in this community, I would love to submit a patch.<br>










><br>
>   I am new to Clang and this community. Hopefully these questions are not naive to you.<br>
><br>
>   Thanks.<br>
> --------<br>
> Guoping<br>
</div></div><div><div></div><div>> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br>
</div></div></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>
</div></div><span><CFG.cpp.patch></span><span><CFG.h.patch></span>_______________________________________________<div><br>cfe-dev mailing list<br><a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>

<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>
<span><Dominators.cpp></span><span><Dominators.h></span><span><domtest.c></span></blockquote></div><br></div></div></div></body></html>