diff gen/llvmhelpers.cpp @ 940:39519a1ff603

Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 04 Feb 2009 18:48:03 +0100
parents 2ebac4750adb
children 95d09451cb59
line wrap: on
line diff
--- a/gen/llvmhelpers.cpp	Wed Feb 04 18:39:39 2009 +0100
+++ b/gen/llvmhelpers.cpp	Wed Feb 04 18:48:03 2009 +0100
@@ -831,15 +831,14 @@
 //      TEMPLATE HELPERS
 ////////////////////////////////////////////////////////////////////////////////////////*/
 
-// FIXME: when is this the right one to use instead of Dsymbol::inTemplateInstance() ?
-bool DtoIsTemplateInstance(Dsymbol* s)
+Module* DtoIsTemplateInstance(Dsymbol* s)
 {
-    if (!s) return false;
+    if (!s) return NULL;
     if (s->isTemplateInstance() && !s->isTemplateMixin())
-        return true;
+        return s->isTemplateInstance()->tmodule;
     else if (s->parent)
         return DtoIsTemplateInstance(s->parent);
-    return false;
+    return NULL;
 }
 
 /****************************************************************************************/
@@ -958,15 +957,10 @@
     assert(!glob->constInit);
     glob->constInit = initVal;
 
-    bool istempl = false;
-    if ((vd->storage_class & STCcomdat) || (vd->parent && DtoIsTemplateInstance(vd->parent))) {
-        istempl = true;
-    }
-
     // assign the initializer
     llvm::GlobalVariable* globalvar = llvm::cast<llvm::GlobalVariable>(glob->value);
 
-    if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl))
+    if (!(vd->storage_class & STCextern) && mustDefineSymbol(vd))
     {
         if (Logger::enabled())
         {
@@ -1559,3 +1553,27 @@
     
     Logger::println("final intrinsic name: %s", name.c_str());
 }
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+bool mustDefineSymbol(Dsymbol* s)
+{
+    Module* M = DtoIsTemplateInstance(s);
+    // if it's a template instance, check the instantiating module
+    // not the module that defines the template
+    if (M)
+        return M == gIR->dmodule;
+    return s->getModule() == gIR->dmodule;
+}
+
+//////////////////////////////////////////////////////////////////////////////////////////
+
+bool needsTemplateLinkage(Dsymbol* s)
+{
+    Module* M = DtoIsTemplateInstance(s);
+    // only return true if the symbol is a template instances
+    // and if this instance originated in the current module
+    if (M)
+        return M == gIR->dmodule;
+    return false;
+}