diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-12-03 01:16:39 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-12-03 01:16:39 +0000 |
commit | 73a4d28758acae423f05aa1eaa99665ee5a21c3c (patch) | |
tree | 8ff38949685f8ac17c6fb6b15c2c24c4b956ee04 /clang/lib/Lex/PTHLexer.cpp | |
parent | 971c88f3b2e45331d2ecd660f8e0dbfc1e240d40 (diff) | |
download | bcm5719-llvm-73a4d28758acae423f05aa1eaa99665ee5a21c3c.tar.gz bcm5719-llvm-73a4d28758acae423f05aa1eaa99665ee5a21c3c.zip |
PTH:
Use an array instead of a DenseMap to cache persistent IDs -> IdentifierInfo*. This leads to a 4% speedup at -fsyntax-only using PTH.
llvm-svn: 60452
Diffstat (limited to 'clang/lib/Lex/PTHLexer.cpp')
-rw-r--r-- | clang/lib/Lex/PTHLexer.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index 846a17e8daf..63f2722e99b 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -23,13 +23,12 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/OwningPtr.h" -#include "llvm/ADT/DenseMap.h" using namespace clang; PTHLexer::PTHLexer(Preprocessor& pp, SourceLocation fileloc, const char* D, PTHManager& PM) - : TokBuf(D), PreprocessorLexer(&pp, fileloc), CurTokenIdx(0), PTHMgr(PM), + : PreprocessorLexer(&pp, fileloc), TokBuf(D), CurTokenIdx(0), PTHMgr(PM), NeedsFetching(true) { // Make sure the EofToken is completely clean. EofToken.startToken(); @@ -184,7 +183,6 @@ void PTHLexer::ReadToken(Token& T) { // Internal Data Structures for PTH file lookup and resolving identifiers. //===----------------------------------------------------------------------===// -typedef llvm::DenseMap<uint32_t, IdentifierInfo*> IDCache; /// PTHFileLookup - This internal data structure is used by the PTHManager /// to map from FileEntry objects managed by FileManager to offsets within @@ -238,14 +236,15 @@ public: //===----------------------------------------------------------------------===// PTHManager::PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup, - const char* idDataTable, Preprocessor& pp) -: Buf(buf), PersistentIDCache(0), FileLookup(fileLookup), -IdDataTable(idDataTable), ITable(pp.getIdentifierTable()), PP(pp) {} + const char* idDataTable, void* perIDCache, + Preprocessor& pp) +: Buf(buf), PerIDCache(perIDCache), FileLookup(fileLookup), + IdDataTable(idDataTable), ITable(pp.getIdentifierTable()), PP(pp) {} PTHManager::~PTHManager() { delete Buf; delete (PTHFileLookup*) FileLookup; - delete (IDCache*) PersistentIDCache; + delete [] (IdentifierInfo**) PerIDCache; } PTHManager* PTHManager::Create(const std::string& file, Preprocessor& PP) { @@ -294,7 +293,22 @@ PTHManager* PTHManager::Create(const std::string& file, Preprocessor& PP) { return 0; // FIXME: Proper error diagnostic? } - return new PTHManager(File.take(), FL.take(), IData, PP); + // Get the number of IdentifierInfos and pre-allocate the identifier cache. + uint32_t NumIds = Read32(IData); + + // Pre-allocate the peristent ID -> IdentifierInfo* cache. We use calloc() + // so that we in the best case only zero out memory once when the OS returns + // us new pages. + IdentifierInfo** PerIDCache = + (IdentifierInfo**) calloc(NumIds, sizeof(*PerIDCache)); + + if (!PerIDCache) { + assert(false && "Could not allocate Persistent ID cache."); + return 0; + } + + // Create the new lexer. + return new PTHManager(File.take(), FL.take(), IData, PerIDCache, PP); } IdentifierInfo* PTHManager::ReadIdentifierInfo(const char*& D) { @@ -310,11 +324,7 @@ IdentifierInfo* PTHManager::ReadIdentifierInfo(const char*& D) { --persistentID; // Check if the IdentifierInfo has already been resolved. - if (!PersistentIDCache) - PersistentIDCache = new IDCache(); - - // FIXME: We can make this an array, but what is the performance tradeoff? - IdentifierInfo*& II = (*((IDCache*) PersistentIDCache))[persistentID]; + IdentifierInfo*& II = ((IdentifierInfo**) PerIDCache)[persistentID]; if (II) return II; // Look in the PTH file for the string data for the IdentifierInfo object. |