hanchenye-llvm-project/clang
Alexander Kornienko 8b3f623582 Keep history of macro definitions and #undefs
Summary:
Summary: Keep history of macro definitions and #undefs with corresponding source locations, so that we can later find out all macros active in a specified source location. We don't save the history in PCH (no need currently). Memory overhead is about sizeof(void*)*3*<number of macro definitions and #undefs>+<in-memory size of all #undef'd macros>

I've run a test on a file composed of 109 .h files from boost 1.49 on x86-64 linux.
Stats before this patch:
*** Preprocessor Stats:
73222 directives found:
  19171 #define.
  4345 #undef.
  #include/#include_next/#import:
    5233 source files entered.
    27 max include stack depth
  19210 #if/#ifndef/#ifdef.
  2384 #else/#elif.
  6891 #endif.
  408 #pragma.
14466 #if/#ifndef#ifdef regions skipped
80023/451669/1270 obj/fn/builtin macros expanded, 85724 on the fast path.
127145 token paste (##) operations performed, 11008 on the fast path.

Preprocessor Memory: 5874615B total
  BumpPtr: 4399104
  Macro Expanded Tokens: 417768
  Predefines Buffer: 8135
  Macros: 1048576
  #pragma push_macro Info: 0
  Poison Reasons: 1024
  Comment Handlers: 8

Stats with this patch:
...
Preprocessor Memory: 7541687B total
  BumpPtr: 6066176
  Macro Expanded Tokens: 417768
  Predefines Buffer: 8135
  Macros: 1048576
  #pragma push_macro Info: 0
  Poison Reasons: 1024
  Comment Handlers: 8

In my test increase in memory usage is about 1.7Mb, which is ~28% of initial preprocessor's memory usage and about 0.8% of clang's total VMM allocation.

As for CPU overhead, it should only be noticeable when iterating over all macros, and should mostly consist of couple extra dereferences and one comparison per macro + skipping of #undef'd macros. It's less trivial to measure, though, as the preprocessor consumes a very small fraction of compilation time.


Reviewers: doug.gregor, klimek, rsmith, djasper

Reviewed By: doug.gregor

CC: cfe-commits, chandlerc

Differential Revision: http://llvm-reviews.chandlerc.com/D28

llvm-svn: 162810
2012-08-29 00:20:03 +00:00
..
INPUTS all-std-headers.cpp: Include the C++11 headers when building with clang 2012-04-13 03:39:16 +00:00
bindings [cindex.py] Cache the number of chunks in CompletionString 2012-08-20 10:38:16 +00:00
docs This is a temporary solution until we have a better way to 2012-08-27 18:49:12 +00:00
examples libclang, examples: [CMake] Add dependencies to tblgen'd headers. 2012-07-27 06:17:56 +00:00
include Keep history of macro definitions and #undefs 2012-08-29 00:20:03 +00:00
lib Keep history of macro definitions and #undefs 2012-08-29 00:20:03 +00:00
runtime build/compiler-rt: Companion commit to r159172. 2012-06-25 23:02:25 +00:00
test objective-C arc: ns_returns_retained is a type attribute in ARC, 2012-08-28 22:26:21 +00:00
tools Fix passing of -analyzer-max-loop from scan-build to clang. 2012-08-28 16:48:48 +00:00
unittests ASTTests: Suppress TestCXXConstructorDecl11 on msvc for now. It seems incompatible. 2012-08-25 00:05:56 +00:00
utils Automatically use more cores when the test build uses 'make'. 2012-08-28 20:40:04 +00:00
www Small change to avoid confusion on what "used by" means for a compiler. 2012-08-14 21:58:29 +00:00
.gitignore Teach Git to ignore the tools/extra directory. 2012-08-13 17:45:30 +00:00
CMakeLists.txt Fix capitalization of LibXml2 for CMake on case-sensitive file systems 2012-08-07 20:42:31 +00:00
INSTALL.txt
LICENSE.TXT
Makefile
ModuleInfo.txt
NOTES.txt Add a note about a missing optimization in the case of virtual 2012-03-30 04:25:03 +00:00
README.txt commit access verified, revert change 2012-03-06 22:55:51 +00:00

README.txt

//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//

Welcome to Clang.  This is a compiler front-end for the C family of languages
(C, C++, Objective-C, and Objective-C++) which is built as part of the LLVM
compiler infrastructure project.

Unlike many other compiler frontends, Clang is useful for a number of things
beyond just compiling code: we intend for Clang to be host to a number of
different source level tools.  One example of this is the Clang Static Analyzer.

If you're interested in more (including how to build Clang) it is best to read
the relevant web sites.  Here are some pointers:

Information on Clang:              http://clang.llvm.org/
Building and using Clang:          http://clang.llvm.org/get_started.html
Clang Static Analyzer:             http://clang-analyzer.llvm.org/
Information on the LLVM project:   http://llvm.org/

If you have questions or comments about Clang, a great place to discuss them is
on the Clang development mailing list:
  http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev

If you find a bug in Clang, please file it in the LLVM bug tracker:
  http://llvm.org/bugs/