diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-12-23 02:30:15 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-12-23 02:30:15 +0000 |
commit | 866bdf74547efe32c320554837ffce00fcc084fe (patch) | |
tree | 6808fb06c128558647af51f0268131b3d98aece5 /lib/Lex/PTHLexer.cpp | |
parent | e5680f3cd678014cf0872d34726dc804b0cbbdd4 (diff) |
PTH:
- In PTHLexer::Lex read all of the token data from PTH file before
constructing the token. The idea is to enhance locality.
- Do not use Read8/Read32 in PTHLexer::Lex. Inline these operations manually.
- Change PTHManager::ReadIdentifierInfo() to PTHManager::GetIdentifierInfo().
They are functionally the same except that PTHLexer::Lex() reads the
persistent id.
These changes result in a 3.3% speedup for PTH on Cocoa.h (-Eonly).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61363 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PTHLexer.cpp')
-rw-r--r-- | lib/Lex/PTHLexer.cpp | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp index 2c19fcd0d9..1038e3b70c 100644 --- a/lib/Lex/PTHLexer.cpp +++ b/lib/Lex/PTHLexer.cpp @@ -55,32 +55,51 @@ PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D, void PTHLexer::Lex(Token& Tok) { LexNextToken: + + //===--------------------------------------==// + // Read the raw token data. + //===--------------------------------------==// - // Read the token. - // FIXME: Setting the flags directly should obviate this step. - Tok.startToken(); + // Shadow CurPtr into an automatic variable. + const unsigned char *CurPtrShadow = (const unsigned char*) CurPtr; + + // Read in the data for the token. 14 bytes in total. + tok::TokenKind k = (tok::TokenKind) CurPtrShadow[0]; + Token::TokenFlags flags = (Token::TokenFlags) CurPtrShadow[1]; + + uint32_t persistentID = ((uint32_t) CurPtrShadow[2]) + | (((uint32_t) CurPtrShadow[3]) << 8) + | (((uint32_t) CurPtrShadow[4]) << 16) + | (((uint32_t) CurPtrShadow[5]) << 24); - // Shadow CurPtr into an automatic variable so that Read8 doesn't load and - // store back into the instance variable. - const char *CurPtrShadow = CurPtr; - // Read the type of the token. - Tok.setKind((tok::TokenKind) Read8(CurPtrShadow)); + uint32_t FileOffset = ((uint32_t) CurPtrShadow[6]) + | (((uint32_t) CurPtrShadow[7]) << 8) + | (((uint32_t) CurPtrShadow[8]) << 16) + | (((uint32_t) CurPtrShadow[9]) << 24); - // Set flags. This is gross, since we are really setting multiple flags. - Tok.setFlag((Token::TokenFlags) Read8(CurPtrShadow)); + uint32_t Len = ((uint32_t) CurPtrShadow[10]) + | (((uint32_t) CurPtrShadow[11]) << 8) + | (((uint32_t) CurPtrShadow[12]) << 16) + | (((uint32_t) CurPtrShadow[13]) << 24); - // Set the IdentifierInfo* (if any). - Tok.setIdentifierInfo(PTHMgr.ReadIdentifierInfo(CurPtrShadow)); + CurPtr = (const char*) (CurPtrShadow + DISK_TOKEN_SIZE); - // Set the SourceLocation. Since all tokens are constructed using a - // raw lexer, they will all be offseted from the same FileID. - Tok.setLocation(SourceLocation::getFileLoc(FileID, Read32(CurPtrShadow))); + //===--------------------------------------==// + // Construct the token itself. + //===--------------------------------------==// - // Finally, read and set the length of the token. - Tok.setLength(Read32(CurPtrShadow)); + Tok.startToken(); + Tok.setKind(k); + Tok.setFlag(flags); + Tok.setIdentifierInfo(persistentID ? PTHMgr.GetIdentifierInfo(persistentID-1) + : 0); + Tok.setLocation(SourceLocation::getFileLoc(FileID, FileOffset)); + Tok.setLength(Len); - CurPtr = CurPtrShadow; + //===--------------------------------------==// + // Process the token. + //===--------------------------------------==// if (Tok.is(tok::eof)) { // Save the end-of-file token. @@ -437,18 +456,8 @@ PTHManager* PTHManager::Create(const std::string& file, Preprocessor& PP) { return new PTHManager(File.take(), FL.take(), IData, PerIDCache, PP); } -IdentifierInfo* PTHManager::ReadIdentifierInfo(const char*& D) { - // Read the persistent ID from the PTH file. - uint32_t persistentID = Read32(D); - - // A persistent ID of '0' always maps to NULL. - if (!persistentID) - return 0; - - // Adjust the persistent ID by subtracting '1' so that it can be used - // as an index within a table in the PTH file. - --persistentID; - +IdentifierInfo* PTHManager::GetIdentifierInfo(unsigned persistentID) { + // Check if the IdentifierInfo has already been resolved. IdentifierInfo*& II = PerIDCache[persistentID]; if (II) return II; |