aboutsummaryrefslogtreecommitdiff
path: root/lib/Serialization/ASTWriter.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-02-11 00:26:14 +0000
committerDouglas Gregor <dgregor@apple.com>2011-02-11 00:26:14 +0000
commit040a804f852c45c8b8c371ce1d421fd4cd84b6fb (patch)
tree55e028ebf0f4e88db129f1834c8ba7edb279c959 /lib/Serialization/ASTWriter.cpp
parentc4850c2aa4c281a352e228aafc51fb1e30dcad02 (diff)
Implement AST/PCH chaining support for macro definitions. Previously,
we would deserialize all of the macro definitions we knew about while serializing the macro definitions at the end of the AST/PCH file. Even though we skipped most of them (since they were unchanged), it's still a performance problem. Now, we do the standard AST/PCH chaining trick: watch what identifiers are deserialized as macro names, and consider only those identifiers (along with macro definitions that have been deserialized/written in the source) when serializing the preprocessor state. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125324 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Serialization/ASTWriter.cpp')
-rw-r--r--lib/Serialization/ASTWriter.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index b6789687d7..ce68649142 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -1536,7 +1536,8 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
llvm::SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2>
MacrosToEmit;
llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen;
- for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
+ for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0),
+ E = PP.macro_end(Chain == 0);
I != E; ++I) {
MacroDefinitionsSeen.insert(I->first);
MacrosToEmit.push_back(std::make_pair(I->first, I->second));
@@ -1547,10 +1548,21 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(),
&compareMacroDefinitions);
+ // Resolve any identifiers that defined macros at the time they were
+ // deserialized, adding them to the list of macros to emit (if appropriate).
+ for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) {
+ IdentifierInfo *Name
+ = const_cast<IdentifierInfo *>(DeserializedMacroNames[I]);
+ if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name))
+ MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name)));
+ }
+
for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) {
const IdentifierInfo *Name = MacrosToEmit[I].first;
MacroInfo *MI = MacrosToEmit[I].second;
-
+ if (!MI)
+ continue;
+
// Don't emit builtin macros like __LINE__ to the AST file unless they have
// been redefined by the header (in which case they are not isBuiltinMacro).
// Also skip macros from a AST file if we're chaining.
@@ -1603,7 +1615,6 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
// FIXME: When reading literal tokens, reconstruct the literal pointer if
// it is needed.
AddIdentifierRef(Tok.getIdentifierInfo(), Record);
-
// FIXME: Should translate token kind to a stable encoding.
Record.push_back(Tok.getKind());
// FIXME: Should translate token flags to a stable encoding.
@@ -3681,6 +3692,8 @@ void ASTWriter::ReaderInitialized(ASTReader *Reader) {
void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) {
IdentifierIDs[II] = ID;
+ if (II->hasMacroDefinition())
+ DeserializedMacroNames.push_back(II);
}
void ASTWriter::TypeRead(TypeIdx Idx, QualType T) {