aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/PCHWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-04-22 18:49:13 +0000
committerDouglas Gregor <dgregor@apple.com>2009-04-22 18:49:13 +0000
commit2deaea37a637dd01221d0cced343702a39d8132c (patch)
treeece1730c3fad98b022a242caf6f2e2b6933836e2 /lib/Frontend/PCHWriter.cpp
parent404dd7afe15c9d8b614da031bbfae6a28ffaea72 (diff)
Lazy loading of builtins for precompiled headers.
PCH files now contain complete information about builtins, including any declarations that have been synthesized as part of building the PCH file. When using a PCH file, we do not initialize builtins at all; when needed, they'll be found in the PCH file. This optimization translations into a 9% speedup for "Hello, World!" with Carbon.h as a prefix header and roughly a 5% speedup for 403.gcc with its prefix header. We're also reading less of the PCH file for "Hello, World!": *** PCH Statistics: 286/20693 types read (1.382110%) 1630/59230 declarations read (2.751984%) 764/44914 identifiers read (1.701029%) 1/32954 statements read (0.003035%) 5/6187 macros read (0.080815%) down from *** PCH Statistics: 411/20693 types read (1.986179%) 2553/59230 declarations read (4.310316%) 1093/44646 identifiers read (2.448148%) 1/32954 statements read (0.003035%) 21/6187 macros read (0.339421%) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69815 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/PCHWriter.cpp')
-rw-r--r--lib/Frontend/PCHWriter.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index f34323c160..15ee2369dd 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -1800,8 +1800,8 @@ public:
II->hasMacroDefinition() &&
!PP.getMacroInfo(const_cast<IdentifierInfo *>(II))->isBuiltinMacro();
Bits = Bits | (uint32_t)II->getTokenID();
- Bits = (Bits << 8) | (uint32_t)II->getObjCOrBuiltinID();
- Bits = (Bits << 10) | hasMacroDefinition;
+ Bits = (Bits << 10) | (uint32_t)II->getObjCOrBuiltinID();
+ Bits = (Bits << 1) | hasMacroDefinition;
Bits = (Bits << 1) | II->isExtensionToken();
Bits = (Bits << 1) | II->isPoisoned();
Bits = (Bits << 1) | II->isCPlusPlusOperatorKeyword();
@@ -2028,6 +2028,17 @@ void PCHWriter::WritePCH(Sema &SemaRef) {
DeclIDs[Context.getTranslationUnitDecl()] = 1;
DeclsToEmit.push(Context.getTranslationUnitDecl());
+ // Make sure that we emit IdentifierInfos (and any attached
+ // declarations) for builtins.
+ {
+ IdentifierTable &Table = PP.getIdentifierTable();
+ llvm::SmallVector<const char *, 32> BuiltinNames;
+ Context.BuiltinInfo.GetBuiltinNames(BuiltinNames,
+ Context.getLangOptions().NoBuiltin);
+ for (unsigned I = 0, N = BuiltinNames.size(); I != N; ++I)
+ getIdentifierRef(&Table.get(BuiltinNames[I]));
+ }
+
// Write the remaining PCH contents.
RecordData Record;
Stream.EnterSubblock(pch::PCH_BLOCK_ID, 3);
@@ -2079,16 +2090,17 @@ void PCHWriter::AddAPFloat(const llvm::APFloat &Value, RecordData &Record) {
}
void PCHWriter::AddIdentifierRef(const IdentifierInfo *II, RecordData &Record) {
- if (II == 0) {
- Record.push_back(0);
- return;
- }
+ Record.push_back(getIdentifierRef(II));
+}
+
+pch::IdentID PCHWriter::getIdentifierRef(const IdentifierInfo *II) {
+ if (II == 0)
+ return 0;
pch::IdentID &ID = IdentifierIDs[II];
if (ID == 0)
ID = IdentifierIDs.size();
-
- Record.push_back(ID);
+ return ID;
}
void PCHWriter::AddTypeRef(QualType T, RecordData &Record) {