[cfe-commits] r38747 - in /cfe/cfe/trunk: Lex/MacroExpander.cpp Lex/Preprocessor.cpp include/clang/Lex/Preprocessor.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:24:18 PDT 2007
Author: sabre
Date: Wed Jul 11 11:24:17 2007
New Revision: 38747
URL: http://llvm.org/viewvc/llvm-project?rev=38747&view=rev
Log:
Add optimization for identifier##identifier -> identifier, the most common case of token pasting.
Modified:
cfe/cfe/trunk/Lex/MacroExpander.cpp
cfe/cfe/trunk/Lex/Preprocessor.cpp
cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/cfe/trunk/Lex/MacroExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/MacroExpander.cpp?rev=38747&r1=38746&r2=38747&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/MacroExpander.cpp (original)
+++ cfe/cfe/trunk/Lex/MacroExpander.cpp Wed Jul 11 11:24:17 2007
@@ -455,9 +455,18 @@
// and emit an error that it is unterminated.
if (Tok.getKind() == tok::slash && RHS.getKind() == tok::star) {
isInvalid = true;
+ } else if (Tok.getKind() == tok::identifier &&
+ Tok.getKind() == tok::identifier) {
+ // Common paste case: identifier+identifier = identifier. Avoid creating
+ // a lexer and other overhead.
+ PP.IncrementPasteCounter(true);
+ Result.StartToken();
+ Result.SetKind(tok::identifier);
+ Result.SetLocation(ResultTokLoc);
+ Result.SetLength(LHSLen+RHSLen);
} else {
- // FIXME: Handle common cases: ident+ident, ident+simplenumber here.
-
+ PP.IncrementPasteCounter(false);
+
// Make a lexer to lex this string from.
SourceManager &SourceMgr = PP.getSourceManager();
const char *ResultStrData = SourceMgr.getCharacterData(ResultTokLoc);
Modified: cfe/cfe/trunk/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Lex/Preprocessor.cpp?rev=38747&r1=38746&r2=38747&view=diff
==============================================================================
--- cfe/cfe/trunk/Lex/Preprocessor.cpp (original)
+++ cfe/cfe/trunk/Lex/Preprocessor.cpp Wed Jul 11 11:24:17 2007
@@ -51,7 +51,7 @@
NumIf = NumElse = NumEndif = 0;
NumEnteredSourceFiles = 0;
NumMacroExpanded = NumFnMacroExpanded = NumBuiltinMacroExpanded = 0;
- NumFastMacroExpanded = 0;
+ NumFastMacroExpanded = NumTokenPaste = NumFastTokenPaste = 0;
MaxIncludeStackDepth = 0; NumMultiIncludeFileOptzn = 0;
NumSkipped = 0;
@@ -193,6 +193,9 @@
std::cerr << NumMacroExpanded << "/" << NumFnMacroExpanded << "/"
<< NumBuiltinMacroExpanded << " obj/fn/builtin macros expanded, "
<< NumFastMacroExpanded << " on the fast path.\n";
+ std::cerr << (NumFastTokenPaste+NumTokenPaste)
+ << " token paste (##) operations performed, "
+ << NumFastTokenPaste << " on the fast path.\n";
}
//===----------------------------------------------------------------------===//
Modified: cfe/cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=38747&r1=38746&r2=38747&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/cfe/trunk/include/clang/Lex/Preprocessor.h Wed Jul 11 11:24:17 2007
@@ -200,7 +200,7 @@
unsigned NumIf, NumElse, NumEndif;
unsigned NumEnteredSourceFiles, MaxIncludeStackDepth,NumMultiIncludeFileOptzn;
unsigned NumMacroExpanded, NumFnMacroExpanded, NumBuiltinMacroExpanded;
- unsigned NumFastMacroExpanded;
+ unsigned NumFastMacroExpanded, NumTokenPaste, NumFastTokenPaste;
unsigned NumSkipped;
public:
Preprocessor(Diagnostic &diags, const LangOptions &opts, FileManager &FM,
@@ -392,6 +392,17 @@
void DumpToken(const LexerToken &Tok, bool DumpFlags = false) const;
void DumpMacro(const MacroInfo &MI) const;
+ /// IncrementPasteCounter - Increment the counters for the number of token
+ /// paste operations performed. If fast was specified, this is a 'fast paste'
+ /// case we handled.
+ ///
+ void IncrementPasteCounter(bool isFast) {
+ if (isFast)
+ ++NumFastTokenPaste;
+ else
+ ++NumTokenPaste;
+ }
+
void PrintStats();
//===--------------------------------------------------------------------===//
More information about the cfe-commits
mailing list