Improved template emission control for singleobj building.

This commit is contained in:
Christian Kamm 2009-03-08 16:21:56 +01:00
parent 520bc229ea
commit 13e83bf1c1
7 changed files with 24 additions and 28 deletions

View file

@ -2875,6 +2875,7 @@ TemplateInstance::TemplateInstance(Loc loc, Identifier *ident)
this->errors = 0; this->errors = 0;
// LDC // LDC
this->emittedInModule = NULL;
this->tinst = NULL; this->tinst = NULL;
this->tmodule = NULL; this->tmodule = NULL;
} }

View file

@ -327,6 +327,7 @@ struct TemplateInstance : ScopeDsymbol
// LDC // LDC
TemplateInstance *tinst; // enclosing template instance TemplateInstance *tinst; // enclosing template instance
Module* tmodule; // module from outermost enclosing template instantiation Module* tmodule; // module from outermost enclosing template instantiation
Module* emittedInModule; // which module this template instance has been emitted in
void printInstantiationTrace(); void printInstantiationTrace();
}; };

View file

@ -326,6 +326,11 @@ static cl::opt<MultiSetter, true, cl::parser<bool> > release("release",
cl::ValueDisallowed); cl::ValueDisallowed);
cl::opt<bool> singleObj("singleobj",
cl::desc("Create only a single output object file"),
cl::ZeroOrMore);
static cl::extrahelp footer("\n" static cl::extrahelp footer("\n"
"-d-debug can also be specified without options, in which case it enables all\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" "debug checks (i.e. (asserts, boundchecks, contracts and invariants) as well\n"

View file

@ -43,6 +43,7 @@ namespace opts {
extern cl::opt<std::string> mCPU; extern cl::opt<std::string> mCPU;
extern cl::list<std::string> mAttrs; extern cl::list<std::string> mAttrs;
extern cl::opt<std::string> mTargetTriple; extern cl::opt<std::string> mTargetTriple;
extern cl::opt<bool> singleObj;
// Arguments to -d-debug // Arguments to -d-debug
extern std::vector<std::string> debugArgs; extern std::vector<std::string> debugArgs;

View file

@ -20,6 +20,7 @@
#include "gen/functions.h" #include "gen/functions.h"
#include "gen/typeinf.h" #include "gen/typeinf.h"
#include "gen/todebug.h" #include "gen/todebug.h"
#include "gen/cl_options.h"
#include "ir/irmodule.h" #include "ir/irmodule.h"
#include <stack> #include <stack>
@ -833,11 +834,11 @@ DValue* DtoPaintType(Loc& loc, DValue* val, Type* to)
// TEMPLATE HELPERS // TEMPLATE HELPERS
////////////////////////////////////////////////////////////////////////////////////////*/ ////////////////////////////////////////////////////////////////////////////////////////*/
Module* DtoIsTemplateInstance(Dsymbol* s) TemplateInstance* DtoIsTemplateInstance(Dsymbol* s)
{ {
if (!s) return NULL; if (!s) return NULL;
if (s->isTemplateInstance() && !s->isTemplateMixin()) if (s->isTemplateInstance() && !s->isTemplateMixin())
return s->isTemplateInstance()->tmodule; return s->isTemplateInstance();
else if (s->parent) else if (s->parent)
return DtoIsTemplateInstance(s->parent); return DtoIsTemplateInstance(s->parent);
return NULL; return NULL;
@ -1536,34 +1537,25 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s
bool mustDefineSymbol(Dsymbol* s) bool mustDefineSymbol(Dsymbol* s)
{ {
#if 1 TemplateInstance* tinst = DtoIsTemplateInstance(s);
return s->getModule() == gIR->dmodule || DtoIsTemplateInstance(s) != NULL; if (tinst)
#else {
Module* M = DtoIsTemplateInstance(s); if (!opts::singleObj)
// if it's a template instance, check the instantiating module return true;
// not the module that defines the template
if (M) { if (!tinst->emittedInModule)
//Logger::println("TINST %s from %s cur %s", s->toPrettyChars(), M->toChars(), gIR->dmodule->toChars()); tinst->emittedInModule = gIR->dmodule;
return M == gIR->dmodule; return tinst->emittedInModule == gIR->dmodule;
} }
return s->getCompilationModule() == gIR->dmodule;
#endif return s->getModule() == gIR->dmodule;
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
bool needsTemplateLinkage(Dsymbol* s) bool needsTemplateLinkage(Dsymbol* s)
{ {
#if 1 return DtoIsTemplateInstance(s) && mustDefineSymbol(s);
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
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////

View file

@ -62,7 +62,7 @@ DValue* DtoCast(Loc& loc, DValue* val, Type* to);
DValue* DtoPaintType(Loc& loc, DValue* val, Type* to); DValue* DtoPaintType(Loc& loc, DValue* val, Type* to);
// is template instance check, returns module where instantiated // 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 // these are all basically drivers for the codegeneration called by the main loop
void DtoResolveDsymbol(Dsymbol* dsym); void DtoResolveDsymbol(Dsymbol* dsym);

View file

@ -43,10 +43,6 @@ extern void getenv_setargv(const char *envvar, int *pargc, char** *pargv);
extern void backend_init(); extern void backend_init();
extern void backend_term(); extern void backend_term();
static cl::opt<bool> singleObj("singleobj",
cl::desc("Create only a single output object file"),
cl::ZeroOrMore);
static cl::opt<bool> noDefaultLib("nodefaultlib", static cl::opt<bool> noDefaultLib("nodefaultlib",
cl::desc("Don't add a default library for linking implicitly"), cl::desc("Don't add a default library for linking implicitly"),
cl::ZeroOrMore); cl::ZeroOrMore);