Mercurial > projects > ldc
comparison 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 |
comparison
equal
deleted
inserted
replaced
939:cac9895be400 | 940:39519a1ff603 |
---|---|
829 /****************************************************************************************/ | 829 /****************************************************************************************/ |
830 /*//////////////////////////////////////////////////////////////////////////////////////// | 830 /*//////////////////////////////////////////////////////////////////////////////////////// |
831 // TEMPLATE HELPERS | 831 // TEMPLATE HELPERS |
832 ////////////////////////////////////////////////////////////////////////////////////////*/ | 832 ////////////////////////////////////////////////////////////////////////////////////////*/ |
833 | 833 |
834 // FIXME: when is this the right one to use instead of Dsymbol::inTemplateInstance() ? | 834 Module* DtoIsTemplateInstance(Dsymbol* s) |
835 bool DtoIsTemplateInstance(Dsymbol* s) | 835 { |
836 { | 836 if (!s) return NULL; |
837 if (!s) return false; | |
838 if (s->isTemplateInstance() && !s->isTemplateMixin()) | 837 if (s->isTemplateInstance() && !s->isTemplateMixin()) |
839 return true; | 838 return s->isTemplateInstance()->tmodule; |
840 else if (s->parent) | 839 else if (s->parent) |
841 return DtoIsTemplateInstance(s->parent); | 840 return DtoIsTemplateInstance(s->parent); |
842 return false; | 841 return NULL; |
843 } | 842 } |
844 | 843 |
845 /****************************************************************************************/ | 844 /****************************************************************************************/ |
846 /*//////////////////////////////////////////////////////////////////////////////////////// | 845 /*//////////////////////////////////////////////////////////////////////////////////////// |
847 // PROCESSING QUEUE HELPERS | 846 // PROCESSING QUEUE HELPERS |
956 llvm::cast<LLOpaqueType>(glob->type.get())->refineAbstractTypeTo(initVal->getType()); | 955 llvm::cast<LLOpaqueType>(glob->type.get())->refineAbstractTypeTo(initVal->getType()); |
957 | 956 |
958 assert(!glob->constInit); | 957 assert(!glob->constInit); |
959 glob->constInit = initVal; | 958 glob->constInit = initVal; |
960 | 959 |
961 bool istempl = false; | |
962 if ((vd->storage_class & STCcomdat) || (vd->parent && DtoIsTemplateInstance(vd->parent))) { | |
963 istempl = true; | |
964 } | |
965 | |
966 // assign the initializer | 960 // assign the initializer |
967 llvm::GlobalVariable* globalvar = llvm::cast<llvm::GlobalVariable>(glob->value); | 961 llvm::GlobalVariable* globalvar = llvm::cast<llvm::GlobalVariable>(glob->value); |
968 | 962 |
969 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl)) | 963 if (!(vd->storage_class & STCextern) && mustDefineSymbol(vd)) |
970 { | 964 { |
971 if (Logger::enabled()) | 965 if (Logger::enabled()) |
972 { | 966 { |
973 Logger::println("setting initializer"); | 967 Logger::println("setting initializer"); |
974 Logger::cout() << "global: " << *gvar << '\n'; | 968 Logger::cout() << "global: " << *gvar << '\n'; |
1557 while(std::string::npos != (pos = name.find(needle))) | 1551 while(std::string::npos != (pos = name.find(needle))) |
1558 name.replace(pos, 1, tmp); | 1552 name.replace(pos, 1, tmp); |
1559 | 1553 |
1560 Logger::println("final intrinsic name: %s", name.c_str()); | 1554 Logger::println("final intrinsic name: %s", name.c_str()); |
1561 } | 1555 } |
1556 | |
1557 ////////////////////////////////////////////////////////////////////////////////////////// | |
1558 | |
1559 bool mustDefineSymbol(Dsymbol* s) | |
1560 { | |
1561 Module* M = DtoIsTemplateInstance(s); | |
1562 // if it's a template instance, check the instantiating module | |
1563 // not the module that defines the template | |
1564 if (M) | |
1565 return M == gIR->dmodule; | |
1566 return s->getModule() == gIR->dmodule; | |
1567 } | |
1568 | |
1569 ////////////////////////////////////////////////////////////////////////////////////////// | |
1570 | |
1571 bool needsTemplateLinkage(Dsymbol* s) | |
1572 { | |
1573 Module* M = DtoIsTemplateInstance(s); | |
1574 // only return true if the symbol is a template instances | |
1575 // and if this instance originated in the current module | |
1576 if (M) | |
1577 return M == gIR->dmodule; | |
1578 return false; | |
1579 } |