[cfe-commits] r59862 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Lex/Preprocessor.cpp

Chris Lattner sabre at nondot.org
Fri Nov 21 23:03:47 PST 2008


Author: lattner
Date: Sat Nov 22 01:03:46 2008
New Revision: 59862

URL: http://llvm.org/viewvc/llvm-project?rev=59862&view=rev
Log:
Move the Preprocessor::Diag methods inline.  This has the interesting
(and carefully calculated) effect of allowing the compiler to reason
about the aliasing properties of DiagnosticBuilder object better,
allowing the whole thing to be promoted to registers instead of
resulting in a ton of stack traffic.

While I'm not very concerned about the performance of the Diag() method
invocations, I *am* more concerned about their code size and impact on the
non-diagnostic code.  This patch shrinks the clang executable (in 
release-asserts mode with gcc-4.2) from 14523980 to 14519816 bytes.  This
isn't much, but it shrinks the lexer from 38192 to 37776, PPDirectives.o
from 31116 to 28868 bytes, etc.


Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=59862&r1=59861&r2=59862&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Sat Nov 22 01:03:46 2008
@@ -18,6 +18,7 @@
 #include "clang/Lex/PTHLexer.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/TokenLexer.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/IdentifierTable.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/DenseMap.h"
@@ -404,8 +405,14 @@
   /// Diag - Forwarding function for diagnostics.  This emits a diagnostic at
   /// the specified Token's location, translating the token's start
   /// position in the current buffer into a SourcePosition object for rendering.
-  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);  
-  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID);
+  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) {
+    return Diags.Report(FullSourceLoc(Loc, getSourceManager()), DiagID);
+  }
+  
+  DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) {
+    return Diags.Report(FullSourceLoc(Tok.getLocation(), getSourceManager()),
+                        DiagID);
+  }
   
   /// getSpelling() - Return the 'spelling' of the Tok token.  The spelling of a
   /// token is the characters used to represent the token in the source file

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

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Sat Nov 22 01:03:46 2008
@@ -114,18 +114,6 @@
   delete Callbacks;
 }
 
-/// Diag - Forwarding function for diagnostics.  This emits a diagnostic at
-/// the specified Token's location, translating the token's start
-/// position in the current buffer into a SourcePosition object for rendering.
-DiagnosticBuilder Preprocessor::Diag(SourceLocation Loc, unsigned DiagID) {
-  return Diags.Report(FullSourceLoc(Loc, getSourceManager()), DiagID);
-}
-
-DiagnosticBuilder Preprocessor::Diag(const Token &Tok, unsigned DiagID) {
-  return Diags.Report(FullSourceLoc(Tok.getLocation(), getSourceManager()),
-                      DiagID);
-}
-
 void Preprocessor::DumpToken(const Token &Tok, bool DumpFlags) const {
   llvm::cerr << tok::getTokenName(Tok.getKind()) << " '"
              << getSpelling(Tok) << "'";





More information about the cfe-commits mailing list