diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-04-25 23:30:02 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-04-25 23:30:02 +0000 |
commit | 8c5a760b82e73ed90b560090772db97e2ae27b09 (patch) | |
tree | ef93a4503bf57c6f71ad8a6b8fe55a9532afefd8 /include | |
parent | 71238f67c5df13eef19450d66b7a7ab28377192a (diff) |
Lazily load the controlling macros for all of the headers known in the
PCH file. In the Cocoa-prefixed "Hello, World" benchmark, this takes
us from reading 503 identifiers down to 37 and from 470 macros down to
4. It also results in an 8% performance improvement.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70094 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/clang/Basic/IdentifierTable.h | 15 | ||||
-rw-r--r-- | include/clang/Frontend/PCHReader.h | 9 | ||||
-rw-r--r-- | include/clang/Lex/HeaderSearch.h | 35 |
3 files changed, 53 insertions, 6 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 235c19081c..083196a2c1 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -234,7 +234,20 @@ public: /// be found. virtual IdentifierInfo* get(const char *NameStart, const char *NameEnd) = 0; }; - + +/// \brief An abstract class used to resolve numerical identifier +/// references (meaningful only to some external source) into +/// IdentifierInfo pointers. +class ExternalIdentifierLookup { +public: + virtual ~ExternalIdentifierLookup(); + + /// \brief Return the identifier associated with the given ID number. + /// + /// The ID 0 is associated with the NULL identifier. + virtual IdentifierInfo *GetIdentifier(unsigned ID) = 0; +}; + /// IdentifierTable - This table implements an efficient mapping from strings to /// IdentifierInfo nodes. It has no other purpose, but this is an /// extremely performance-critical piece of the code, as each occurrance of diff --git a/include/clang/Frontend/PCHReader.h b/include/clang/Frontend/PCHReader.h index 0c8520ceb4..98e32fcf0e 100644 --- a/include/clang/Frontend/PCHReader.h +++ b/include/clang/Frontend/PCHReader.h @@ -64,7 +64,10 @@ class SwitchCase; /// The PCH reader provides lazy de-serialization of declarations, as /// required when traversing the AST. Only those AST nodes that are /// actually required will be de-serialized. -class PCHReader : public ExternalSemaSource, public IdentifierInfoLookup { +class PCHReader + : public ExternalSemaSource, + public IdentifierInfoLookup, + public ExternalIdentifierLookup { public: enum PCHReadResult { Success, Failure, IgnorePCH }; @@ -371,6 +374,10 @@ public: return DecodeIdentifierInfo(Record[Idx++]); } + virtual IdentifierInfo *GetIdentifier(unsigned ID) { + return DecodeIdentifierInfo(ID); + } + Selector DecodeSelector(unsigned Idx); Selector GetSelector(const RecordData &Record, unsigned &Idx) { diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index fe7e7aef3b..f21aab1b40 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -19,6 +19,8 @@ #include <vector> namespace clang { + +class ExternalIdentifierLookup; class FileEntry; class FileManager; class IdentifierInfo; @@ -42,10 +44,27 @@ struct HeaderFileInfo { /// ControllingMacro - If this file has a #ifndef XXX (or equivalent) guard /// that protects the entire contents of the file, this is the identifier /// for the macro that controls whether or not it has any effect. + /// + /// Note: Most clients should use getControllingMacro() to access + /// the controlling macro of this header, since + /// getControllingMacro() is able to load a controlling macro from + /// external storage. const IdentifierInfo *ControllingMacro; - - HeaderFileInfo() : isImport(false), DirInfo(SrcMgr::C_User), - NumIncludes(0), ControllingMacro(0) {} + + /// \brief The ID number of the controlling macro. + /// + /// This ID number will be non-zero when there is a controlling + /// macro whose IdentifierInfo may not yet have been loaded from + /// external storage. + unsigned ControllingMacroID; + + HeaderFileInfo() + : isImport(false), DirInfo(SrcMgr::C_User), + NumIncludes(0), ControllingMacro(0), ControllingMacroID(0) {} + + /// \brief Retrieve the controlling macro for this header file, if + /// any. + const IdentifierInfo *getControllingMacro(ExternalIdentifierLookup *External); }; /// HeaderSearch - This class encapsulates the information needed to find the @@ -84,7 +103,11 @@ class HeaderSearch { /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing /// headermaps. This vector owns the headermap. std::vector<std::pair<const FileEntry*, const HeaderMap*> > HeaderMaps; - + + /// \brief Entity used to resolve the identifier IDs of controlling + /// macros into IdentifierInfo pointers, as needed. + ExternalIdentifierLookup *ExternalLookup; + // Various statistics we track for performance analysis. unsigned NumIncluded; unsigned NumMultiIncludeFileOptzn; @@ -115,6 +138,10 @@ public: FileInfo.clear(); } + void SetExternalLookup(ExternalIdentifierLookup *EIL) { + ExternalLookup = EIL; + } + /// LookupFile - Given a "foo" or <foo> reference, look up the indicated file, /// return null on failure. isAngled indicates whether the file reference is /// a <> reference. If successful, this returns 'UsedDir', the |