Optimize serialized representation of redeclarable declarations for
which there are no redeclarations. This reduced by size of the PCH
file for Cocoa.h by ~650k: ~536k of that was in the new
LOCAL_REDECLARATIONS table, which went from a ridiculous 540k down to
an acceptable 3.5k, while the rest was due to the more compact
abbreviated representation of redeclarable declaration kinds (which no
longer need to store the 'first' declaration ID).
llvm-svn: 146869
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp
index d538d6e..3e08d99 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -1410,9 +1410,18 @@
template <typename T>
void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
- enum RedeclKind { FirstInFile, PointsToPrevious };
+ enum RedeclKind { OnlyDeclaration = 0, FirstInFile, PointsToPrevious };
RedeclKind Kind = (RedeclKind)Record[Idx++];
+ // If this is the only known declaration of this entity, this module file
+ // has no additional redeclaration information. However, other module
+ // files might have redeclarations.
+ if (Kind == OnlyDeclaration) {
+ if (Reader.PendingDeclChainsKnown.insert(ThisDeclID))
+ Reader.PendingDeclChains.push_back(ThisDeclID);
+ return;
+ }
+
// Read the first declaration ID, and note that we need to reconstruct
// the redeclaration chain once we hit the top level.
DeclID FirstDeclID = ReadDeclID(Record, Idx);
@@ -1422,6 +1431,9 @@
T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
switch (Kind) {
+ case OnlyDeclaration:
+ llvm_unreachable("only declaration handled above");
+
case FirstInFile:
if (FirstDecl != D)
D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(FirstDecl);