diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-15 18:47:46 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-15 18:47:46 +0000 |
commit | 72b1b15ee88aac0a63e2c1dc53fe22f5ab297b20 (patch) | |
tree | 525dfef2340cc9e228a1be10104d902ef7d9eaee /include/clang/Lex/PTHManager.h | |
parent | f185319f25efd6094870f287030270fad26085ba (diff) |
IdentifierInfo:
- IdentifierInfo can now (optionally) have its string data not be
co-located with itself. This is for use with PTH. This aspect is a
little gross, as getName() and getLength() now make assumptions
about a possible alternate representation of IdentifierInfo.
Perhaps we should make IdentifierInfo have virtual methods?
IdentifierTable:
- Added class "IdentifierInfoLookup" that can be used by
IdentifierTable to perform "string -> IdentifierInfo" lookups using
an auxilliary data structure. This is used by PTH.
- Perform tests show that IdentifierTable::get() does not slow down
because of the extra check for the IdentiferInfoLookup object (the
regular StringMap lookup does enough work to mitigate the impact of
an extra null pointer check).
- The upshot is that now that some IdentifierInfo objects might be
owned by the IdentiferInfoLookup object. This should be reviewed.
PTH:
- Modified PTHManager::GetIdentifierInfo to *not* insert entries in
IdentifierTable's string map, and instead create IdentifierInfo
objects on the fly when mapping from persistent IDs to
IdentifierInfos. This saves a ton of work with string copies,
hashing, and StringMap lookup and resizing. This change was
motivated because when processing source files in the PTH cache we
don't need to do any string -> IdentifierInfo lookups.
- PTHManager now subclasses IdentifierInfoLookup, allowing clients of
IdentifierTable to transparently use IdentifierInfo objects managed
by the PTH file. PTHManager resolves "string -> IdentifierInfo"
queries by doing a binary search over a sorted table of identifier
strings in the PTH file (the exact algorithm we use can be changed
as needed).
These changes lead to the following performance changes when using PTH on Cocoa.h:
- fsyntax-only: 10% performance improvement
- Eonly: 30% performance improvement
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62273 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex/PTHManager.h')
-rw-r--r-- | include/clang/Lex/PTHManager.h | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/include/clang/Lex/PTHManager.h b/include/clang/Lex/PTHManager.h index 60beee3645..634c088b8f 100644 --- a/include/clang/Lex/PTHManager.h +++ b/include/clang/Lex/PTHManager.h @@ -16,7 +16,9 @@ #include "clang/Lex/PTHLexer.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/IdentifierTable.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/Support/Allocator.h" #include <string> namespace llvm { @@ -26,8 +28,6 @@ namespace llvm { namespace clang { class FileEntry; -class IdentifierInfo; -class IdentifierTable; class PTHLexer; class PTHManager; @@ -54,7 +54,7 @@ public: LinearItr(tableBeg) {} }; -class PTHManager { +class PTHManager : public IdentifierInfoLookup { friend class PTHLexer; friend class PTHSpellingSearch; @@ -64,6 +64,9 @@ class PTHManager { /// A map from FileIDs to SpellingSearch objects. llvm::DenseMap<unsigned,PTHSpellingSearch*> SpellingMap; + /// Alloc - Allocator used for IdentifierInfo objects. + llvm::BumpPtrAllocator Alloc; + /// IdMap - A lazily generated cache mapping from persistent identifiers to /// IdentifierInfo*. IdentifierInfo** PerIDCache; @@ -75,47 +78,59 @@ class PTHManager { /// IdDataTable - Array representing the mapping from persistent IDs to the /// data offset within the PTH file containing the information to /// reconsitute an IdentifierInfo. - const char* IdDataTable; + const char* const IdDataTable; + + /// SortedIdTable - Array ordering persistent identifier IDs by the lexical + /// order of their corresponding strings. This is used by get(). + const char* const SortedIdTable; - /// ITable - The IdentifierTable used for the translation unit being lexed. - IdentifierTable& ITable; + /// NumIds - The number of identifiers in the PTH file. + const unsigned NumIds; /// PP - The Preprocessor object that will use this PTHManager to create /// PTHLexer objects. - Preprocessor& PP; + Preprocessor* PP; /// This constructor is intended to only be called by the static 'Create' /// method. PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, const char* idDataTable, IdentifierInfo** perIDCache, - Preprocessor& pp); + const char* sortedIdTable, unsigned numIds); // Do not implement. PTHManager(); void operator=(const PTHManager&); - /// GetIdentifierInfo - Used by PTHManager to reconstruct IdentifierInfo - /// objects from the PTH file. - IdentifierInfo* GetIdentifierInfo(unsigned); - /// getSpellingAtPTHOffset - Used by PTHLexer classes to get the cached /// spelling for a token. unsigned getSpellingAtPTHOffset(unsigned PTHOffset, const char*& Buffer); -public: + /// GetIdentifierInfo - Used to reconstruct IdentifierInfo objects from the + /// PTH file. + IdentifierInfo* GetIdentifierInfo(unsigned); + +public: ~PTHManager(); + /// get - Return the identifier token info for the specified named identifier. + /// Unlike the version in IdentifierTable, this returns a pointer instead + /// of a reference. If the pointer is NULL then the IdentifierInfo cannot + /// be found. + IdentifierInfo* get(const char *NameStart, const char *NameEnd); + /// Create - This method creates PTHManager objects. The 'file' argument /// is the name of the PTH file. This method returns NULL upon failure. - static PTHManager* Create(const std::string& file, Preprocessor& PP); + static PTHManager* Create(const std::string& file); + void setPreprocessor(Preprocessor* pp) { PP = pp; } + /// CreateLexer - Return a PTHLexer that "lexes" the cached tokens for the /// specified file. This method returns NULL if no cached tokens exist. /// It is the responsibility of the caller to 'delete' the returned object. PTHLexer* CreateLexer(unsigned FileID, const FileEntry* FE); - unsigned getSpelling(unsigned FileID, unsigned fpos, const char *& Buffer); + unsigned getSpelling(unsigned FileID, unsigned fpos, const char *& Buffer); }; } // end namespace clang |