]> granicus.if.org Git - clang/commitdiff
Move the functionality to mark all vtables of key functions as used within
authorChandler Carruth <chandlerc@gmail.com>
Sun, 12 Dec 2010 21:36:11 +0000 (21:36 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sun, 12 Dec 2010 21:36:11 +0000 (21:36 +0000)
a translation unit to the ActOnEndOfTranslationUnit function instead of doing
it at the start of DefineUsedVTables. The latter is now called *recursively*
during template instantiation, which causes an absolutely insane number of
walks of every record decl in the translation unit.

After this patch, an extremely template instantiation heavy test case's compile
time drops by 10x, and we see between 15% and 20% improvement in average
compile times across a project. This is just recovering a regression, it
doesn't make anything faster than it was several weeks ago.

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

lib/Sema/Sema.cpp
lib/Sema/SemaDeclCXX.cpp

index e9791a0e644a74c2baea2ffded59ffde46ddf5b3..fcc5370ed9e500508b1ccef53df56bee087e8b39 100644 (file)
@@ -285,6 +285,18 @@ void Sema::ActOnEndOfTranslationUnit() {
   // At PCH writing, implicit instantiations and VTable handling info are
   // stored and performed when the PCH is included.
   if (CompleteTranslationUnit) {
+    // If any dynamic classes have their key function defined within
+    // this translation unit, then those vtables are considered "used" and must
+    // be emitted.
+    for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) {
+      if (const CXXMethodDecl *KeyFunction
+          = Context.getKeyFunction(DynamicClasses[I])) {
+        const FunctionDecl *Definition = 0;
+        if (KeyFunction->hasBody(Definition))
+          MarkVTableUsed(Definition->getLocation(), DynamicClasses[I], true);
+      }
+    }
+
     // If DefinedUsedVTables ends up marking any virtual member functions it
     // might lead to more pending template instantiations, which we then need
     // to instantiate.
index be1979e26ed428254aebb18f7025fdf4284d4989..4fc770eecfb95f925eb1e10b5ccf2ab2262e13db 100644 (file)
@@ -6895,21 +6895,9 @@ void Sema::MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class,
 }
 
 bool Sema::DefineUsedVTables() {
-  // If any dynamic classes have their key function defined within
-  // this translation unit, then those vtables are considered "used" and must
-  // be emitted.
-  for (unsigned I = 0, N = DynamicClasses.size(); I != N; ++I) {
-    if (const CXXMethodDecl *KeyFunction
-                             = Context.getKeyFunction(DynamicClasses[I])) {
-      const FunctionDecl *Definition = 0;
-      if (KeyFunction->hasBody(Definition))
-        MarkVTableUsed(Definition->getLocation(), DynamicClasses[I], true);
-    }
-  }
-
   if (VTableUses.empty())
     return false;
-  
+
   // Note: The VTableUses vector could grow as a result of marking
   // the members of a class as "used", so we check the size each
   // time through the loop and prefer indices (with are stable) to