[PATCH] D29951: Load lazily the template specialization in multi-module setups.

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 14 11:02:02 PST 2017


v.g.vassilev created this revision.

Currently, we load all template specialization if we have more than one module attached and we touch anything around the template definition.

This patch registers the template specializations as a lazily-loadable entities. This reduces the amount of deserializations by 1%.


Repository:
  rL LLVM

https://reviews.llvm.org/D29951

Files:
  lib/Serialization/ASTReaderDecl.cpp


Index: lib/Serialization/ASTReaderDecl.cpp
===================================================================
--- lib/Serialization/ASTReaderDecl.cpp
+++ lib/Serialization/ASTReaderDecl.cpp
@@ -3788,9 +3788,31 @@
       break;
     }
 
-    case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
-      // It will be added to the template's specializations set when loaded.
-      (void)Record.readDecl();
+    case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: {
+      // It will be added to the template's lazy specialization set when loaded.
+      // FIXME: reduce the copy paste.
+      SmallVector<serialization::DeclID, 1> SpecID;
+      if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) {
+        SpecID.push_back(ReadDeclID());
+        auto *CommonPtr = CTD->getCommonPtr();
+        CommonPtr->LazySpecializations = newDeclIDList(
+            Reader.getContext(), CommonPtr->LazySpecializations, SpecID);
+
+      } else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) {
+        SpecID.push_back(ReadDeclID());
+        auto *CommonPtr = FTD->getCommonPtr();
+        CommonPtr->LazySpecializations = newDeclIDList(
+            Reader.getContext(), CommonPtr->LazySpecializations, SpecID);
+
+      } else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) {
+        SpecID.push_back(ReadDeclID());
+        auto *CommonPtr = VTD->getCommonPtr();
+        CommonPtr->LazySpecializations = newDeclIDList(
+            Reader.getContext(), CommonPtr->LazySpecializations, SpecID);
+
+      } else // TypeAliasTemplateDecl
+        assert(0 && "TypeAliasTemplateDecl doesn't have specs!");
+    }
       break;
 
     case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29951.88398.patch
Type: text/x-patch
Size: 1653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170214/52f7f416/attachment.bin>


More information about the cfe-commits mailing list