[cfe-commits] r99912 - in /cfe/trunk: include/clang/AST/DeclBase.h include/clang/AST/DeclCXX.h include/clang/AST/DeclFriend.h include/clang/AST/DeclObjC.h include/clang/AST/DeclTemplate.h include/clang/AST/Expr.h include/clang/AST/ExprCXX.h include/clang/AST/ExprObjC.h include/clang/AST/Statistics.h include/clang/AST/Stmt.h include/clang/AST/StmtCXX.h include/clang/AST/StmtObjC.h include/clang/AST/Type.h lib/AST/DeclBase.cpp lib/AST/Expr.cpp lib/AST/Stmt.cpp lib/AST/Type.cpp

Douglas Gregor dgregor at apple.com
Tue Mar 30 13:41:37 PDT 2010


On Mar 30, 2010, at 1:22 PM, Chris Lattner wrote:

> 
> On Mar 30, 2010, at 11:56 AM, Douglas Gregor wrote:
> 
>> Author: dgregor
>> Date: Tue Mar 30 13:56:13 2010
>> New Revision: 99912
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=99912&view=rev
>> Log:
>> Introduce new AST statistics that keep track of the number of isa (or
>> dyn_cast) invocations for C++ and Objective-C types, declarations,
>> expressions, and statements. The statistics will be printed when
>> -print-stats is provided to Clang -cc1, with results such as:
>> 
>> 277073 clang - Number of checks for C++ declaration nodes
>> 13311 clang - Number of checks for C++ expression nodes
>>   18 clang - Number of checks for C++ statement nodes
>> 174182 clang - Number of checks for C++ type nodes
>> 92300 clang - Number of checks for Objective-C declaration nodes
>> 9800 clang - Number of checks for Objective-C expression nodes
>>    7 clang - Number of checks for Objective-C statement nodes
>> 65733 clang - Number of checks for Objective-C type nodes
>> 
>> The statistics are only gathered when NDEBUG is not defined, since
>> they introduce potentially-expensive operations into very low-level
>> routines (isa).
> 
> Interesting, are these checks (without the instrumentation) expensive and worth optimizing?  What do these metrics tell us?

Not as much as I'd hoped. Turning all of these checks into a constant "false" (in effect, partly specializing Clang for C code) only yielded a 2.8% performance improvement in -fsyntax-only on some sample C code, so these checks aren't all that expensive.

> Instead of NDEBUG, how about only enabling it with expensive checks?


As I understand it, expensive checks is for the *really* expensive checks, like iterator validity via the C++ standard library's debug mode. I don't think we're in that league, but if you're worried about the cost of incrementing a counter per C++/ObjC isa<> in a debug build I can look into it. 

	- Doug



More information about the cfe-commits mailing list