diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-01-27 00:01:05 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-01-27 00:01:05 +0000 |
commit | 277faca30c9f8f72b79f55695cbe3395ec246e7c (patch) | |
tree | 80ed507b156a6d73ba2cf5651e772dd55f7adee0 /include/clang | |
parent | 528473335419f072f6eff25a4af07925c1692121 (diff) |
PTH: Use Token::setLiteralData() to directly store a pointer to cached spelling data in the PTH file. This removes a ton of code for looking up spellings using sourcelocations in the PTH file. This simplifies both PTH-generation and reading.
Performance impact for -fsyntax-only on Cocoa.h (with Cocoa.h in the PTH file):
- PTH generation time improves by 5%
- PTH reading improves by 0.3%.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63072 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang')
-rw-r--r-- | include/clang/Lex/PTHLexer.h | 17 | ||||
-rw-r--r-- | include/clang/Lex/PTHManager.h | 48 | ||||
-rw-r--r-- | include/clang/Lex/Preprocessor.h | 6 |
3 files changed, 11 insertions, 60 deletions
diff --git a/include/clang/Lex/PTHLexer.h b/include/clang/Lex/PTHLexer.h index c6837d2a8b..369b818a1f 100644 --- a/include/clang/Lex/PTHLexer.h +++ b/include/clang/Lex/PTHLexer.h @@ -45,10 +45,6 @@ class PTHLexer : public PreprocessorLexer { /// to process when doing quick skipping of preprocessor blocks. const unsigned char* CurPPCondPtr; - /// MySpellingMgr - Reference to the spelling manager used to get spellings - /// for the source file indicated by \c FileID. - PTHSpellingSearch& MySpellingSrch; - PTHLexer(const PTHLexer&); // DO NOT IMPLEMENT void operator=(const PTHLexer&); // DO NOT IMPLEMENT @@ -65,8 +61,7 @@ protected: /// Create a PTHLexer for the specified token stream. PTHLexer(Preprocessor& pp, FileID FID, const unsigned char *D, - const unsigned char* ppcond, - PTHSpellingSearch& mySpellingSrch, PTHManager &PM); + const unsigned char* ppcond, PTHManager &PM); public: ~PTHLexer() {} @@ -95,16 +90,6 @@ public: /// IndirectLex - An indirect call to 'Lex' that can be invoked via /// the PreprocessorLexer interface. void IndirectLex(Token &Result) { Lex(Result); } - - /// Returns the cached spelling of a token. - /// \param[in] sloc The SourceLocation of the token. - /// \param[out] Buffer If a token's spelling is found in the PTH file then - /// upon exit from this method \c Buffer will be set to the address of - /// the character array representing that spelling. No characters - /// are copied. - /// \returns The number of characters for the spelling of the token. This - /// value is 0 if the spelling could not be found in the PTH file. - unsigned getSpelling(SourceLocation sloc, const char *&Buffer); /// getSourceLocation - Return a source location for the token in /// the current file. diff --git a/include/clang/Lex/PTHManager.h b/include/clang/Lex/PTHManager.h index 31cf78f036..b77cda1f0b 100644 --- a/include/clang/Lex/PTHManager.h +++ b/include/clang/Lex/PTHManager.h @@ -29,42 +29,13 @@ namespace clang { class FileEntry; class PTHLexer; -class PTHManager; - -class PTHSpellingSearch { - PTHManager& PTHMgr; - - const unsigned char* const TableBeg; - const unsigned char* const TableEnd; - - const unsigned NumSpellings; - const unsigned char* LinearItr; - -public: - enum { SpellingEntrySize = 4*2 }; - - unsigned getSpellingBinarySearch(unsigned fpos, const char *&Buffer); - unsigned getSpellingLinearSearch(unsigned fpos, const char *&Buffer); - - PTHSpellingSearch(PTHManager& pm, unsigned numSpellings, - const unsigned char* tableBeg) - : PTHMgr(pm), - TableBeg(tableBeg), - TableEnd(tableBeg + numSpellings*SpellingEntrySize), - NumSpellings(numSpellings), - LinearItr(tableBeg) {} -}; class PTHManager : public IdentifierInfoLookup { friend class PTHLexer; - friend class PTHSpellingSearch; /// The memory mapped PTH file. const llvm::MemoryBuffer* Buf; - - /// A map from FileIDs to SpellingSearch objects. - llvm::DenseMap<FileID, PTHSpellingSearch*> SpellingMap; - + /// Alloc - Allocator used for IdentifierInfo objects. llvm::BumpPtrAllocator Alloc; @@ -84,7 +55,7 @@ class PTHManager : public IdentifierInfoLookup { /// SortedIdTable - Array ordering persistent identifier IDs by the lexical /// order of their corresponding strings. This is used by get(). const unsigned char* const SortedIdTable; - + /// NumIds - The number of identifiers in the PTH file. const unsigned NumIds; @@ -92,11 +63,16 @@ class PTHManager : public IdentifierInfoLookup { /// PTHLexer objects. Preprocessor* PP; + /// SpellingBase - The base offset within the PTH memory buffer that + /// contains the cached spellings for literals. + const unsigned char* const SpellingBase; + /// This constructor is intended to only be called by the static 'Create' /// method. PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, const unsigned char* idDataTable, IdentifierInfo** perIDCache, - const unsigned char* sortedIdTable, unsigned numIds); + const unsigned char* sortedIdTable, unsigned numIds, + const unsigned char* spellingBase); // Do not implement. PTHManager(); @@ -119,7 +95,7 @@ class PTHManager : public IdentifierInfoLookup { public: // The current PTH version. - enum { Version = 0 }; + enum { Version = 1 }; ~PTHManager(); @@ -138,11 +114,7 @@ public: /// 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(FileID FID); - - unsigned getSpelling(SourceLocation Loc, const char *&Buffer); -private: - unsigned getSpelling(FileID FID, unsigned fpos, const char *& Buffer); + PTHLexer *CreateLexer(FileID FID); }; } // end namespace clang diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 095c1db1de..4e57069385 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -461,12 +461,6 @@ public: // If the token is carrying a literal data pointer, just use it. if (const char *D = Tok.getLiteralData()) return *D; - - if (PTH) { - const char *Data; - if (PTH->getSpelling(Tok.getLocation(), Data)) - return *Data; - } // Otherwise, fall back on getCharacterData, which is slower, but always // works. |