[cfe-dev] optimizations done on ASTs

John McCall rjmccall at apple.com
Fri Sep 9 10:07:29 PDT 2011


On Sep 9, 2011, at 9:09 AM, Douglas Gregor wrote:
> On Sep 9, 2011, at 8:44 AM, Bin Zeng wrote:
>> Just a quick question. What optimizations are done on ASTs in clang? By scanning the code, I did not find any optimizations done directly on ASTs. Shortly after preprocessed code is parsed in ParseAST.cpp, it is translated into bitcode which lots of optimizations manipulate. If any, please point me to the right direction.
> 
> Clang does not perform an optimization on ASTs. The ASTs describe the code as written in the source file, augmented with semantic information (types, implicit conversions, etc.) describing the actual behavior. The AST -> IR lowering performs some simple optimizations, but the real optimization work is performed on the IR.

Just to expand on this slightly:  we sometimes do record information that's useful for optimization in the ASTs.  For example, we mark that a local variable is a candidate for NRVO when processing that function.  But we still never do optimization on the ASTs:  they're intended to exactly represent the high-level syntax and semantics of the source file.

John.



More information about the cfe-dev mailing list