aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Basic/OnDiskHashTable.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-21 22:25:48 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-21 22:25:48 +0000
commit668c1a4fdcc56bdd050256b1688e116fe84b72db (patch)
treebd72a7861c9d2ba6b5f1b37cd41aa12910c20a8b /include/clang/Basic/OnDiskHashTable.h
parent5b54b88c4082bb81b8b341b622fda9a85cbd5fad (diff)
Lazy deserialization of the declaration chains associated with
identifiers from a precompiled header. This patch changes the primary name lookup method for entities within a precompiled header. Previously, we would load all of the names of declarations at translation unit scope into a large DenseMap (inside the TranslationUnitDecl's DeclContext), and then perform a special "last resort" lookup into this DeclContext when we knew there was a PCH file (see Sema::LookupName). Now, when we see an identifier named for the first time, we load all of the declarations with that name that are visible from the translation unit into the IdentifierInfo's chain of declarations. Thus, the explicit "look into the translation unit's DeclContext" code is gone, and Sema effectively uses the same IdentifierInfo-based name lookup mechanism whether we are using a PCH file or not. This approach should help PCH scale with the size of the input program rather than the size of the PCH file. The "Hello, World!" application with Carbon.h as a PCH file now loads 20% of the identifiers in the PCH file rather than 85% of the identifiers. 90% of the 20% of identifiers loaded are actually loaded when we deserialize the preprocessor state. The next step is to make the preprocessor load macros lazily, which should drastically reduce the number of types, declarations, and identifiers loaded for "Hello, World". git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69737 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/OnDiskHashTable.h')
-rw-r--r--include/clang/Basic/OnDiskHashTable.h29
1 files changed, 19 insertions, 10 deletions
diff --git a/include/clang/Basic/OnDiskHashTable.h b/include/clang/Basic/OnDiskHashTable.h
index 631d497f1a..3caeb9ffd8 100644
--- a/include/clang/Basic/OnDiskHashTable.h
+++ b/include/clang/Basic/OnDiskHashTable.h
@@ -242,6 +242,8 @@ class OnDiskChainedHashTable {
const unsigned NumEntries;
const unsigned char* const Buckets;
const unsigned char* const Base;
+ Info InfoObj;
+
public:
typedef typename Info::internal_key_type internal_key_type;
typedef typename Info::external_key_type external_key_type;
@@ -249,9 +251,10 @@ public:
OnDiskChainedHashTable(unsigned numBuckets, unsigned numEntries,
const unsigned char* buckets,
- const unsigned char* base)
+ const unsigned char* base,
+ const Info &InfoObj = Info())
: NumBuckets(numBuckets), NumEntries(numEntries),
- Buckets(buckets), Base(base) {
+ Buckets(buckets), Base(base), InfoObj(InfoObj) {
assert((reinterpret_cast<uintptr_t>(buckets) & 0x3) == 0 &&
"'buckets' must have a 4-byte alignment");
}
@@ -267,22 +270,27 @@ public:
internal_key_type key;
const unsigned char* const data;
const unsigned len;
+ Info *InfoObj;
public:
iterator() : data(0), len(0) {}
- iterator(const internal_key_type k, const unsigned char* d, unsigned l)
- : key(k), data(d), len(l) {}
+ iterator(const internal_key_type k, const unsigned char* d, unsigned l,
+ Info *InfoObj)
+ : key(k), data(d), len(l), InfoObj(InfoObj) {}
- data_type operator*() const { return Info::ReadData(key, data, len); }
+ data_type operator*() const { return InfoObj->ReadData(key, data, len); }
bool operator==(const iterator& X) const { return X.data == data; }
bool operator!=(const iterator& X) const { return X.data != data; }
};
- iterator find(const external_key_type& eKey) {
+ iterator find(const external_key_type& eKey, Info *InfoPtr = 0) {
+ if (!InfoPtr)
+ InfoPtr = &InfoObj;
+
using namespace io;
const internal_key_type& iKey = Info::GetInternalKey(eKey);
unsigned key_hash = Info::ComputeHash(iKey);
- // Each bucket is just a 32-bit offset into the PTH file.
+ // Each bucket is just a 32-bit offset into the hash table file.
unsigned idx = key_hash & (NumBuckets - 1);
const unsigned char* Bucket = Buckets + sizeof(uint32_t)*idx;
@@ -319,7 +327,7 @@ public:
}
// The key matches!
- return iterator(X, Items + L.first, L.second);
+ return iterator(X, Items + L.first, L.second, InfoPtr);
}
return iterator();
@@ -329,7 +337,8 @@ public:
static OnDiskChainedHashTable* Create(const unsigned char* buckets,
- const unsigned char* const base) {
+ const unsigned char* const base,
+ const Info &InfoObj = Info()) {
using namespace io;
assert(buckets > base);
assert((reinterpret_cast<uintptr_t>(buckets) & 0x3) == 0 &&
@@ -338,7 +347,7 @@ public:
unsigned numBuckets = ReadLE32(buckets);
unsigned numEntries = ReadLE32(buckets);
return new OnDiskChainedHashTable<Info>(numBuckets, numEntries, buckets,
- base);
+ base, InfoObj);
}
};