From: Chris Lattner Date: Sun, 7 Oct 2007 07:09:52 +0000 (+0000) Subject: First step to fixing a long lived layering violation: this X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4365a7e46822700357a272d839ee2656d9603d5a;p=clang First step to fixing a long lived layering violation: this moves the MacroInfo pointer to a side hash table (which currently lives in IdentifierTable.cpp). This removes a pointer from Identifier info, but doesn't shrink it, as it requires a new bit be added. This strange approach with the 'hasmacro' bit is needed to not lose preprocessor performance. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42722 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Lex/IdentifierTable.cpp b/Lex/IdentifierTable.cpp index fd64dec0ae..b1c2c63f23 100644 --- a/Lex/IdentifierTable.cpp +++ b/Lex/IdentifierTable.cpp @@ -19,6 +19,24 @@ #include "llvm/ADT/DenseMap.h" using namespace clang; +static llvm::DenseMap Macros; + +MacroInfo *IdentifierInfo::getMacroInfoInternal() const { + return Macros[this]; +} +void IdentifierInfo::setMacroInfo(MacroInfo *I) { + if (I == 0) { + if (HasMacro) { + Macros.erase(this); + HasMacro = false; + } + } else { + Macros[this] = I; + HasMacro = true; + } +} + + //===----------------------------------------------------------------------===// // Token Implementation //===----------------------------------------------------------------------===// @@ -40,11 +58,11 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const { //===----------------------------------------------------------------------===// IdentifierInfo::IdentifierInfo() { - Macro = 0; TokenID = tok::identifier; PPID = tok::pp_not_keyword; ObjCID = tok::objc_not_keyword; BuiltinID = 0; + HasMacro = false; IsExtension = false; IsPoisoned = false; IsOtherTargetMacro = false; @@ -54,7 +72,8 @@ IdentifierInfo::IdentifierInfo() { } IdentifierInfo::~IdentifierInfo() { - delete Macro; + if (MacroInfo *Macro = getMacroInfo()) + delete Macro; } //===----------------------------------------------------------------------===// diff --git a/include/clang/Lex/IdentifierTable.h b/include/clang/Lex/IdentifierTable.h index 132f71551a..ed9f971f45 100644 --- a/include/clang/Lex/IdentifierTable.h +++ b/include/clang/Lex/IdentifierTable.h @@ -37,11 +37,11 @@ namespace clang { /// variable or function name). The preprocessor keeps this information in a /// set, and all tok::identifier tokens have a pointer to one of these. class IdentifierInfo { - MacroInfo *Macro; // Set if this identifier is #define'd. tok::TokenKind TokenID : 8; // Front-end token ID or tok::identifier. + unsigned BuiltinID : 9; // ID if this is a builtin (__builtin_inf). tok::PPKeywordKind PPID : 5; // ID for preprocessor command like #'ifdef'. tok::ObjCKeywordKind ObjCID : 5; // ID for objc @ keyword like @'protocol'. - unsigned BuiltinID : 9; // ID if this is a builtin (__builtin_inf). + bool HasMacro : 1; // True if there is a #define for this. bool IsExtension : 1; // True if identifier is a lang extension. bool IsPoisoned : 1; // True if identifier is poisoned. bool IsOtherTargetMacro : 1; // True if ident is macro on another target. @@ -49,6 +49,7 @@ class IdentifierInfo { bool IsNonPortableBuiltin : 1; // True if builtin varies across targets. void *FETokenInfo; // Managed by the language front-end. IdentifierInfo(const IdentifierInfo&); // NONCOPYABLE. + void operator=(const IdentifierInfo&); // NONASSIGNABLE. public: IdentifierInfo(); ~IdentifierInfo(); @@ -72,8 +73,10 @@ public: /// getMacroInfo - Return macro information about this identifier, or null if /// it is not a macro. - MacroInfo *getMacroInfo() const { return Macro; } - void setMacroInfo(MacroInfo *I) { Macro = I; } + MacroInfo *getMacroInfo() const { + return HasMacro ? getMacroInfoInternal() : 0; + } + void setMacroInfo(MacroInfo *I); /// get/setTokenID - If this is a source-language token (e.g. 'for'), this API /// can be used to cause the lexer to map identifiers to source-language @@ -137,6 +140,8 @@ public: template T *getFETokenInfo() const { return static_cast(FETokenInfo); } void setFETokenInfo(void *T) { FETokenInfo = T; } +private: + MacroInfo *getMacroInfoInternal() const; }; /// IdentifierTable - This table implements an efficient mapping from strings to @@ -274,6 +279,9 @@ public: } // end namespace clang + +/// Define DenseMapInfo so that Selectors can be used as keys in DenseMap and +/// DenseSets. namespace llvm { template <> struct DenseMapInfo {