summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PCHReader.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-22 19:09:20 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-22 19:09:20 +0000
commitb985eebcdfaed7ba4ee07b411259b4a5a7549cba (patch)
tree7b2c0f88c8ca3885e4f58dd71dcb4cb7591a469f /clang/lib/Frontend/PCHReader.cpp
parent63660175f8474b215f5619e29cda7df9e7c5f68d (diff)
downloadbcm5719-llvm-b985eebcdfaed7ba4ee07b411259b4a5a7549cba.tar.gz
bcm5719-llvm-b985eebcdfaed7ba4ee07b411259b4a5a7549cba.zip
Minimize the number and kind of "external definitions" that the PCH
file needs to store. CodeGen needs to see these definitions (via HandleTopLevelDecl), otherwise it won't be able to generate code for them. This patch notifies the consumer (e.g., CodeGen) about function definitions and variable definitions when the corresponding declarations are deserialized. Hence, we don't eagerly deserialize the declarations for every variable or function that has a definition in the PCH file. This gives another 5% speedup for the Carbon-prefixed "Hello, World!", and brings our PCH statistics down to something far more reasonable: *** PCH Statistics: 13/20693 types read (0.062823%) 17/59230 declarations read (0.028702%) 54/44914 identifiers read (0.120230%) 0/32954 statements read (0.000000%) 5/6187 macros read (0.080815%) llvm-svn: 69820
Diffstat (limited to 'clang/lib/Frontend/PCHReader.cpp')
-rw-r--r--clang/lib/Frontend/PCHReader.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/clang/lib/Frontend/PCHReader.cpp b/clang/lib/Frontend/PCHReader.cpp
index 976b98dd11c..c6c34e9749f 100644
--- a/clang/lib/Frontend/PCHReader.cpp
+++ b/clang/lib/Frontend/PCHReader.cpp
@@ -377,9 +377,7 @@ void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
std::pair<uint64_t, uint64_t>
PCHDeclReader::VisitDeclContext(DeclContext *DC) {
uint64_t LexicalOffset = Record[Idx++];
- uint64_t VisibleOffset = 0;
- if (DC->getPrimaryContext() == DC)
- VisibleOffset = Record[Idx++];
+ uint64_t VisibleOffset = Record[Idx++];
return std::make_pair(LexicalOffset, VisibleOffset);
}
@@ -2317,6 +2315,23 @@ Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
}
assert(Idx == Record.size());
+ if (Consumer) {
+ // If we have deserialized a declaration that has a definition the
+ // AST consumer might need to know about, notify the consumer
+ // about that definition now.
+ if (VarDecl *Var = dyn_cast<VarDecl>(D)) {
+ if (Var->isFileVarDecl() && Var->getInit()) {
+ DeclGroupRef DG(Var);
+ Consumer->HandleTopLevelDecl(DG);
+ }
+ } else if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D)) {
+ if (Func->isThisDeclarationADefinition()) {
+ DeclGroupRef DG(Func);
+ Consumer->HandleTopLevelDecl(DG);
+ }
+ }
+ }
+
return D;
}
@@ -2458,6 +2473,8 @@ bool PCHReader::ReadDeclsVisibleInContext(DeclContext *DC,
}
void PCHReader::StartTranslationUnit(ASTConsumer *Consumer) {
+ this->Consumer = Consumer;
+
if (!Consumer)
return;
OpenPOWER on IntegriCloud