[cfe-commits] r60452 - in /cfe/trunk: Driver/CacheTokens.cpp include/clang/Lex/PTHManager.h lib/Lex/PTHLexer.cpp
Ted Kremenek
kremenek at apple.com
Tue Dec 2 17:16:39 PST 2008
Author: kremenek
Date: Tue Dec 2 19:16:39 2008
New Revision: 60452
URL: http://llvm.org/viewvc/llvm-project?rev=60452&view=rev
Log:
PTH:
Use an array instead of a DenseMap to cache persistent IDs -> IdentifierInfo*. This leads to a 4% speedup at -fsyntax-only using PTH.
Modified:
cfe/trunk/Driver/CacheTokens.cpp
cfe/trunk/include/clang/Lex/PTHManager.h
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/Driver/CacheTokens.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/CacheTokens.cpp?rev=60452&r1=60451&r2=60452&view=diff
==============================================================================
--- cfe/trunk/Driver/CacheTokens.cpp (original)
+++ cfe/trunk/Driver/CacheTokens.cpp Tue Dec 2 19:16:39 2008
@@ -104,7 +104,7 @@
}
Offset DataOff = Out.tell();
-
+
for (InverseIDMap::iterator I=IIDMap.begin(), E=IIDMap.end(); I!=E; ++I) {
// Record the location for this data.
I->FileOffset = Out.tell();
@@ -118,6 +118,9 @@
// Now emit the table mapping from persistent IDs to PTH file offsets.
Offset IDOff = Out.tell();
+ // Emit the number of identifiers.
+ Emit32(Out, max);
+
for (InverseIDMap::iterator I=IIDMap.begin(), E=IIDMap.end(); I!=E; ++I)
Emit32(Out, I->FileOffset);
Modified: cfe/trunk/include/clang/Lex/PTHManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PTHManager.h?rev=60452&r1=60451&r2=60452&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PTHManager.h (original)
+++ cfe/trunk/include/clang/Lex/PTHManager.h Tue Dec 2 19:16:39 2008
@@ -38,7 +38,7 @@
/// IdMap - A lazily generated cache mapping from persistent identifiers to
/// IdentifierInfo*.
- void* PersistentIDCache;
+ void* PerIDCache;
/// FileLookup - Abstract data structure used for mapping between files
/// and token data in the PTH file.
@@ -59,7 +59,7 @@
/// This constructor is intended to only be called by the static 'Create'
/// method.
PTHManager(const llvm::MemoryBuffer* buf, void* fileLookup,
- const char* idDataTable, Preprocessor& pp);
+ const char* idDataTable, void* perIDCache, Preprocessor& pp);
// Do not implement.
PTHManager();
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=60452&r1=60451&r2=60452&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Tue Dec 2 19:16:39 2008
@@ -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 @@
// 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 @@
//===----------------------------------------------------------------------===//
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 @@
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 @@
--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.
More information about the cfe-commits
mailing list