]> granicus.if.org Git - clang/commitdiff
When loading an identifier from an AST file solely for the purpose of
authorDouglas Gregor <dgregor@apple.com>
Mon, 21 Jan 2013 16:47:11 +0000 (16:47 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 21 Jan 2013 16:47:11 +0000 (16:47 +0000)
forming the identifier, e.g., as part of a selector or a declaration
name, don't actually deserialize any information about the
identifier. Instead, simply mark it "out-of-date" and we'll load the
the information on demand. 2% speedup on the modules testcase I'm
looking at; should also help PCH.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173056 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp

index 994008de44bd822f068e6f32edb6b654f6e5ea99..d6d6148ffdbfdc5560da50721162f8d78767d7af 100644 (file)
@@ -1515,11 +1515,22 @@ public:
   /// \brief Report a diagnostic.
   DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
 
-  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
+  /// \brief Given the global ID for an identifier, retrieve the
+  /// corresponding identifier information.
+  ///
+  /// \param ID The global ID.
+  ///
+  /// \param StartOutOfDate If true, don't actually read the identifier
+  /// contents (macro definition, etc.). Instead, put the identifier in the
+  /// "out-of-date" state to its contents to be loaded later.
+  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID,
+                                       bool StartOutOfDate = false);
 
   IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
-                                    unsigned &Idx) {
-    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
+                                    unsigned &Idx,
+                                    bool StartOutOfDate = false) {
+    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]),
+                                StartOutOfDate);
   }
 
   virtual IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) {
@@ -1529,7 +1540,8 @@ public:
     return DecodeIdentifierInfo(ID);
   }
 
-  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
+  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID,
+                                     bool StartOutOfDate = false);
 
   serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
                                                     unsigned LocalID);
index db850f3f83fe75eba6c6378457af2801c47291ef..e360d8dde2eb7fd28bf3c7436be9c03293387f36 100644 (file)
@@ -398,7 +398,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
   SelectorTable &SelTable = Reader.getContext().Selectors;
   unsigned N = ReadUnalignedLE16(d);
   IdentifierInfo *FirstII
-    = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
+    = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d), true);
   if (N == 0)
     return SelTable.getNullarySelector(FirstII);
   else if (N == 1)
@@ -407,7 +407,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
   SmallVector<IdentifierInfo *, 16> Args;
   Args.push_back(FirstII);
   for (unsigned I = 1; I != N; ++I)
-    Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)));
+    Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d), true));
 
   return SelTable.getSelector(N, Args.data());
 }
@@ -6038,7 +6038,8 @@ ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II,
   }
 }
 
-IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
+IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID,
+                                                bool StartOutOfDate) {
   if (ID == 0)
     return 0;
 
@@ -6063,8 +6064,15 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
     const unsigned char *StrLenPtr = (const unsigned char*) Str - 2;
     unsigned StrLen = (((unsigned) StrLenPtr[0])
                        | (((unsigned) StrLenPtr[1]) << 8)) - 1;
-    IdentifiersLoaded[ID]
-      = &PP.getIdentifierTable().get(StringRef(Str, StrLen));
+
+    StringRef Name(Str, StrLen);
+    if (StartOutOfDate) {
+      IdentifiersLoaded[ID] = &PP.getIdentifierTable().getOwn(Name);
+      IdentifiersLoaded[ID]->setOutOfDate(true);
+    } else {
+      IdentifiersLoaded[ID]
+        = &PP.getIdentifierTable().get(Name);
+    }
     if (DeserializationListener)
       DeserializationListener->IdentifierRead(ID + 1, IdentifiersLoaded[ID]);
   }
@@ -6072,8 +6080,10 @@ IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) {
   return IdentifiersLoaded[ID];
 }
 
-IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) {
-  return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID));
+IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID,
+                                              bool StartOutOfDate) {
+  return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID),
+                              StartOutOfDate);
 }
 
 IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) {
@@ -6209,7 +6219,7 @@ ASTReader::ReadDeclarationName(ModuleFile &F,
   DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++];
   switch (Kind) {
   case DeclarationName::Identifier:
-    return DeclarationName(GetIdentifierInfo(F, Record, Idx));
+    return DeclarationName(GetIdentifierInfo(F, Record, Idx, true));
 
   case DeclarationName::ObjCZeroArgSelector:
   case DeclarationName::ObjCOneArgSelector: