comparison gen/llvmhelpers.cpp @ 1067:7ce8355fbcc6

Improved template emission control for singleobj building.
author Christian Kamm <kamm incasoftware de>
date Sun, 08 Mar 2009 16:21:56 +0100
parents 39f12f5aa515
children 4e388d9d0e25
comparison
equal deleted inserted replaced
1066:186d44690036 1067:7ce8355fbcc6
18 #include "gen/complex.h" 18 #include "gen/complex.h"
19 #include "gen/classes.h" 19 #include "gen/classes.h"
20 #include "gen/functions.h" 20 #include "gen/functions.h"
21 #include "gen/typeinf.h" 21 #include "gen/typeinf.h"
22 #include "gen/todebug.h" 22 #include "gen/todebug.h"
23 #include "gen/cl_options.h"
23 #include "ir/irmodule.h" 24 #include "ir/irmodule.h"
24 25
25 #include <stack> 26 #include <stack>
26 27
27 /****************************************************************************************/ 28 /****************************************************************************************/
831 /****************************************************************************************/ 832 /****************************************************************************************/
832 /*//////////////////////////////////////////////////////////////////////////////////////// 833 /*////////////////////////////////////////////////////////////////////////////////////////
833 // TEMPLATE HELPERS 834 // TEMPLATE HELPERS
834 ////////////////////////////////////////////////////////////////////////////////////////*/ 835 ////////////////////////////////////////////////////////////////////////////////////////*/
835 836
836 Module* DtoIsTemplateInstance(Dsymbol* s) 837 TemplateInstance* DtoIsTemplateInstance(Dsymbol* s)
837 { 838 {
838 if (!s) return NULL; 839 if (!s) return NULL;
839 if (s->isTemplateInstance() && !s->isTemplateMixin()) 840 if (s->isTemplateInstance() && !s->isTemplateMixin())
840 return s->isTemplateInstance()->tmodule; 841 return s->isTemplateInstance();
841 else if (s->parent) 842 else if (s->parent)
842 return DtoIsTemplateInstance(s->parent); 843 return DtoIsTemplateInstance(s->parent);
843 return NULL; 844 return NULL;
844 } 845 }
845 846
1534 1535
1535 ////////////////////////////////////////////////////////////////////////////////////////// 1536 //////////////////////////////////////////////////////////////////////////////////////////
1536 1537
1537 bool mustDefineSymbol(Dsymbol* s) 1538 bool mustDefineSymbol(Dsymbol* s)
1538 { 1539 {
1539 #if 1 1540 TemplateInstance* tinst = DtoIsTemplateInstance(s);
1540 return s->getModule() == gIR->dmodule || DtoIsTemplateInstance(s) != NULL; 1541 if (tinst)
1541 #else 1542 {
1542 Module* M = DtoIsTemplateInstance(s); 1543 if (!opts::singleObj)
1543 // if it's a template instance, check the instantiating module 1544 return true;
1544 // not the module that defines the template 1545
1545 if (M) { 1546 if (!tinst->emittedInModule)
1546 //Logger::println("TINST %s from %s cur %s", s->toPrettyChars(), M->toChars(), gIR->dmodule->toChars()); 1547 tinst->emittedInModule = gIR->dmodule;
1547 return M == gIR->dmodule; 1548 return tinst->emittedInModule == gIR->dmodule;
1548 } 1549 }
1549 return s->getCompilationModule() == gIR->dmodule; 1550
1550 #endif 1551 return s->getModule() == gIR->dmodule;
1551 } 1552 }
1552 1553
1553 ////////////////////////////////////////////////////////////////////////////////////////// 1554 //////////////////////////////////////////////////////////////////////////////////////////
1554 1555
1555 bool needsTemplateLinkage(Dsymbol* s) 1556 bool needsTemplateLinkage(Dsymbol* s)
1556 { 1557 {
1557 #if 1 1558 return DtoIsTemplateInstance(s) && mustDefineSymbol(s);
1558 return DtoIsTemplateInstance(s) != NULL;
1559 #else
1560 Module* M = DtoIsTemplateInstance(s);
1561 // only return true if the symbol is a template instances
1562 // and if this instance originated in the current module
1563 if (M)
1564 return M == gIR->dmodule;
1565 return false;
1566 #endif
1567 } 1559 }
1568 1560
1569 ////////////////////////////////////////////////////////////////////////////////////////// 1561 //////////////////////////////////////////////////////////////////////////////////////////
1570 1562
1571 bool hasUnalignedFields(Type* t) 1563 bool hasUnalignedFields(Type* t)