[cfe-commits] r62993 - in /cfe/trunk/lib/Lex: PPDirectives.cpp PPMacroExpansion.cpp

Chris Lattner sabre at nondot.org
Sun Jan 25 20:06:50 PST 2009


Author: lattner
Date: Sun Jan 25 22:06:48 2009
New Revision: 62993

URL: http://llvm.org/viewvc/llvm-project?rev=62993&view=rev
Log:
Eagerly resolve the spelling location of the tokens in a definition
of a macro.  Since these tokens may themselves be from macro 
expansions, we need to resolve down to the spelling loc when the
macro ends up being instantiated.  Instead of resolving this for
each token expanded from the macro definition, just do it once when
the macro is defined.  This speeds up clang on c99-intconst-1.c from
2.66s to 2.43s (9.5%), reducing the FileID lookups from 407244 linear and
114175649 binary to 2529040 linear and 64771121 binary.


Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=62993&r1=62992&r2=62993&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Sun Jan 25 22:06:48 2009
@@ -991,6 +991,12 @@
   if (MI->isObjectLike()) {
     // Object-like macros are very simple, just read their body.
     while (Tok.isNot(tok::eom)) {
+      // If this token has a virtual location, resolve it down to its spelling
+      // location.  This is not strictly needed, but avoids extra resolutions
+      // for macros that are expanded frequently.
+      if (!Tok.getLocation().isFileID())
+        Tok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
+      
       MI->AddTokenToBody(Tok);
       // Get the next token of the macro.
       LexUnexpandedToken(Tok);
@@ -1000,6 +1006,12 @@
     // Otherwise, read the body of a function-like macro.  This has to validate
     // the # (stringize) operator.
     while (Tok.isNot(tok::eom)) {
+      // If this token has a virtual location, resolve it down to its spelling
+      // location.  This is not strictly needed, but avoids extra resolutions
+      // for macros that are expanded frequently.
+      if (!Tok.getLocation().isFileID())
+        Tok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
+      
       MI->AddTokenToBody(Tok);
 
       // Check C99 6.10.3.2p1: ensure that # operators are followed by macro

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=62993&r1=62992&r2=62993&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Sun Jan 25 22:06:48 2009
@@ -340,6 +340,12 @@
           if (!MI->isEnabled())
             Tok.setFlag(Token::DisableExpand);
       }
+      
+      // If this token has instantiation location, resolve it down to its
+      // spelling location.  This is not strictly needed, but avoids extra
+      // resolutions for macros that are expanded frequently.
+      if (!Tok.getLocation().isFileID())
+        Tok.setLocation(SourceMgr.getSpellingLoc(Tok.getLocation()));
   
       ArgTokens.push_back(Tok);
     }





More information about the cfe-commits mailing list