# HG changeset patch # User Christian Kamm # Date 1236531105 -3600 # Node ID 39e2f5e4af3d221dd3261503b6ac3ce6238ab537 # Parent dc576c7e4b1ea6667c672119e387567c6d9638db# Parent 8038b106c458ace7a123f817b0d2d942dd357baf Automated merge with http://hg.dsource.org/projects/ldc diff -r dc576c7e4b1e -r 39e2f5e4af3d dmd/template.c --- a/dmd/template.c Sun Mar 08 16:37:55 2009 +0100 +++ b/dmd/template.c Sun Mar 08 17:51:45 2009 +0100 @@ -2875,6 +2875,7 @@ this->errors = 0; // LDC + this->emittedInModule = NULL; this->tinst = NULL; this->tmodule = NULL; } diff -r dc576c7e4b1e -r 39e2f5e4af3d dmd/template.h --- a/dmd/template.h Sun Mar 08 16:37:55 2009 +0100 +++ b/dmd/template.h Sun Mar 08 17:51:45 2009 +0100 @@ -327,6 +327,7 @@ // LDC TemplateInstance *tinst; // enclosing template instance Module* tmodule; // module from outermost enclosing template instantiation + Module* emittedInModule; // which module this template instance has been emitted in void printInstantiationTrace(); }; diff -r dc576c7e4b1e -r 39e2f5e4af3d gen/cl_options.cpp --- a/gen/cl_options.cpp Sun Mar 08 16:37:55 2009 +0100 +++ b/gen/cl_options.cpp Sun Mar 08 17:51:45 2009 +0100 @@ -326,6 +326,11 @@ cl::ValueDisallowed); +cl::opt singleObj("singleobj", + cl::desc("Create only a single output object file"), + cl::ZeroOrMore); + + static cl::extrahelp footer("\n" "-d-debug can also be specified without options, in which case it enables all\n" "debug checks (i.e. (asserts, boundchecks, contracts and invariants) as well\n" diff -r dc576c7e4b1e -r 39e2f5e4af3d gen/cl_options.h --- a/gen/cl_options.h Sun Mar 08 16:37:55 2009 +0100 +++ b/gen/cl_options.h Sun Mar 08 17:51:45 2009 +0100 @@ -43,6 +43,7 @@ extern cl::opt mCPU; extern cl::list mAttrs; extern cl::opt mTargetTriple; + extern cl::opt singleObj; // Arguments to -d-debug extern std::vector debugArgs; diff -r dc576c7e4b1e -r 39e2f5e4af3d gen/llvmhelpers.cpp --- a/gen/llvmhelpers.cpp Sun Mar 08 16:37:55 2009 +0100 +++ b/gen/llvmhelpers.cpp Sun Mar 08 17:51:45 2009 +0100 @@ -20,6 +20,7 @@ #include "gen/functions.h" #include "gen/typeinf.h" #include "gen/todebug.h" +#include "gen/cl_options.h" #include "ir/irmodule.h" #include @@ -833,11 +834,11 @@ // TEMPLATE HELPERS ////////////////////////////////////////////////////////////////////////////////////////*/ -Module* DtoIsTemplateInstance(Dsymbol* s) +TemplateInstance* DtoIsTemplateInstance(Dsymbol* s) { if (!s) return NULL; if (s->isTemplateInstance() && !s->isTemplateMixin()) - return s->isTemplateInstance()->tmodule; + return s->isTemplateInstance(); else if (s->parent) return DtoIsTemplateInstance(s->parent); return NULL; @@ -1536,34 +1537,25 @@ bool mustDefineSymbol(Dsymbol* s) { -#if 1 - return s->getModule() == gIR->dmodule || DtoIsTemplateInstance(s) != NULL; -#else - Module* M = DtoIsTemplateInstance(s); - // if it's a template instance, check the instantiating module - // not the module that defines the template - if (M) { - //Logger::println("TINST %s from %s cur %s", s->toPrettyChars(), M->toChars(), gIR->dmodule->toChars()); - return M == gIR->dmodule; + TemplateInstance* tinst = DtoIsTemplateInstance(s); + if (tinst) + { + if (!opts::singleObj) + return true; + + if (!tinst->emittedInModule) + tinst->emittedInModule = gIR->dmodule; + return tinst->emittedInModule == gIR->dmodule; } - return s->getCompilationModule() == gIR->dmodule; -#endif + + return s->getModule() == gIR->dmodule; } ////////////////////////////////////////////////////////////////////////////////////////// bool needsTemplateLinkage(Dsymbol* s) { -#if 1 - return DtoIsTemplateInstance(s) != NULL; -#else - 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; -#endif + return DtoIsTemplateInstance(s) && mustDefineSymbol(s); } ////////////////////////////////////////////////////////////////////////////////////////// diff -r dc576c7e4b1e -r 39e2f5e4af3d gen/llvmhelpers.h --- a/gen/llvmhelpers.h Sun Mar 08 16:37:55 2009 +0100 +++ b/gen/llvmhelpers.h Sun Mar 08 17:51:45 2009 +0100 @@ -62,7 +62,7 @@ DValue* DtoPaintType(Loc& loc, DValue* val, Type* to); // is template instance check, returns module where instantiated -Module* DtoIsTemplateInstance(Dsymbol* s); +TemplateInstance* DtoIsTemplateInstance(Dsymbol* s); // these are all basically drivers for the codegeneration called by the main loop void DtoResolveDsymbol(Dsymbol* dsym); diff -r dc576c7e4b1e -r 39e2f5e4af3d gen/main.cpp --- a/gen/main.cpp Sun Mar 08 16:37:55 2009 +0100 +++ b/gen/main.cpp Sun Mar 08 17:51:45 2009 +0100 @@ -43,10 +43,6 @@ extern void backend_init(); extern void backend_term(); -static cl::opt singleObj("singleobj", - cl::desc("Create only a single output object file"), - cl::ZeroOrMore); - static cl::opt noDefaultLib("nodefaultlib", cl::desc("Don't add a default library for linking implicitly"), cl::ZeroOrMore); diff -r dc576c7e4b1e -r 39e2f5e4af3d gen/todebug.cpp --- a/gen/todebug.cpp Sun Mar 08 16:37:55 2009 +0100 +++ b/gen/todebug.cpp Sun Mar 08 17:51:45 2009 +0100 @@ -503,6 +503,12 @@ false, // isMain, false // isOptimized ); + + // if the linkage stays internal, we can't llvm-link the generated modules together: + // llvm's DwarfWriter uses path and filename to determine the symbol name and we'd + // end up with duplicate symbols + m->ir.irModule->diCompileUnit.getGV()->setLinkage(DEBUGINFO_LINKONCE_LINKAGE_TYPE); + m->ir.irModule->diCompileUnit.getGV()->setName(std::string("llvm.dbg.compile_unit_") + srcpath + m->srcfile->name->toChars()); return m->ir.irModule->diCompileUnit; }