Replace DtoIsTemplateInstance() by Dsymbol::isInstantiated()

The semantics were almost identical, except for DtoIsTemplateInstance()
checking the specified Dsymbol and its parents, while isInstantiated()
starts from its parent and ignores the symbol itself.

After a quick glance, we seem to have fed it with {Aggregate,Func,Var}
Declarations only, so should be fine with the default front-end variant.
This commit is contained in:
Martin Kinkelin 2020-10-26 03:34:31 +01:00
parent ad9f9b51a2
commit ec9caae7fc
9 changed files with 24 additions and 33 deletions

View file

@ -578,18 +578,21 @@ void DtoDeclareFunction(FuncDeclaration *fdecl, const bool willDefine) {
bool defineAtEnd = false;
bool defineAsAvailableExternally = false;
if (willDefine) {
// will be defined anyway after declaration
} else if (defineOnDeclare(fdecl)) {
Logger::println("Function is inside a linkonce_odr template, will be "
"defined after declaration.");
if (fdecl->semanticRun < PASSsemantic3done) {
// this can e.g. happen for special __xtoHash member functions
Logger::println("Function hasn't had sema3 run yet, running it now.");
const bool semaSuccess = fdecl->functionSemantic3();
assert(semaSuccess);
Module::runDeferredSemantic3();
}
IF_LOG Logger::println("Function is inside a linkonce_odr template, will "
"be defined after declaration.");
defineAtEnd = true;
} else if (defineAsExternallyAvailable(*fdecl)) {
IF_LOG Logger::println("Function is an externally_available inline "
"candidate, will be defined after declaration.");
Logger::println("Function is an externally_available inline candidate, "
"will be defined after declaration.");
defineAtEnd = true;
defineAsAvailableExternally = true;
}

View file

@ -795,18 +795,8 @@ DValue *DtoPaintType(Loc &loc, DValue *val, Type *to) {
* TEMPLATE HELPERS
******************************************************************************/
TemplateInstance *DtoIsTemplateInstance(Dsymbol *s) {
for (; s; s = s->parent) {
if (auto ti = s->isTemplateInstance()) {
if (!ti->isTemplateMixin())
return ti;
}
}
return nullptr;
}
bool defineOnDeclare(Dsymbol* s) {
return global.params.linkonceTemplates && DtoIsTemplateInstance(s);
return global.params.linkonceTemplates && s->isInstantiated();
}
/******************************************************************************

View file

@ -101,8 +101,6 @@ DValue *DtoCast(Loc &loc, DValue *val, Type *to);
// otherwise returns a new DValue
DValue *DtoPaintType(Loc &loc, DValue *val, Type *to);
// is template instance check, returns module where instantiated
TemplateInstance *DtoIsTemplateInstance(Dsymbol *s);
/// Returns true if the specified symbol is to be defined on declaration, for
/// -linkonce-templates.
bool defineOnDeclare(Dsymbol *s);

View file

@ -170,7 +170,7 @@ void DtoDefineNakedFunction(FuncDeclaration *fd) {
asmstr << "\t.section\t__TEXT,__text,regular,pure_instructions"
<< std::endl;
asmstr << "\t.globl\t" << mangle << std::endl;
if (DtoIsTemplateInstance(fd)) {
if (fd->isInstantiated()) {
asmstr << "\t.weak_definition\t" << mangle << std::endl;
}
asmstr << "\t.p2align\t4, 0x90" << std::endl;
@ -198,7 +198,7 @@ void DtoDefineNakedFunction(FuncDeclaration *fd) {
asmstr << "\t.type\t32;" << std::endl;
asmstr << "\t.endef" << std::endl;
if (DtoIsTemplateInstance(fd)) {
if (fd->isInstantiated()) {
asmstr << "\t.section\t.text,\"xr\",discard," << mangle << std::endl;
} else {
asmstr << "\t.text" << std::endl;
@ -207,7 +207,7 @@ void DtoDefineNakedFunction(FuncDeclaration *fd) {
asmstr << "\t.p2align\t4, 0x90" << std::endl;
asmstr << mangle << ":" << std::endl;
} else {
if (DtoIsTemplateInstance(fd)) {
if (fd->isInstantiated()) {
asmstr << "\t.section\t.text." << mangle << ",\"axG\",@progbits,"
<< mangle << ",comdat" << std::endl;
asmstr << "\t.weak\t" << mangle << std::endl;

View file

@ -221,7 +221,7 @@ LinkageWithCOMDAT DtoLinkage(Dsymbol *sym) {
}
// Function (incl. delegate) literals are emitted into each referencing
// compilation unit; use template linkage to prevent conflicts.
else if (sym->isFuncLiteralDeclaration() || DtoIsTemplateInstance(sym)) {
else if (sym->isFuncLiteralDeclaration() || sym->isInstantiated()) {
linkage = templateLinkage;
} else {
linkage = LLGlobalValue::ExternalLinkage;

View file

@ -83,8 +83,8 @@ LLConstant *IrAggr::getInitSymbol(bool define) {
init = initGlobal;
if (!define && defineOnDeclare(aggrdecl))
define = true;
if (!define)
define = defineOnDeclare(aggrdecl);
}
if (define) {

View file

@ -72,8 +72,8 @@ LLGlobalVariable *IrClass::getVtblSymbol(bool define) {
vtbl = declareGlobal(aggrdecl->loc, gIR->module, vtblTy, irMangle,
/*isConstant=*/true);
if (!define && defineOnDeclare(aggrdecl))
define = true;
if (!define)
define = defineOnDeclare(aggrdecl);
}
if (define) {
@ -131,8 +131,8 @@ LLGlobalVariable *IrClass::getClassInfoSymbol(bool define) {
gIR->context(), llvm::makeArrayRef(mdVals, CD_NumFields)));
}
if (!define && defineOnDeclare(aggrdecl))
define = true;
if (!define)
define = defineOnDeclare(aggrdecl);
}
if (define) {
@ -473,8 +473,8 @@ llvm::GlobalVariable *IrClass::getInterfaceVtblSymbol(BaseClass *b,
// insert into the vtbl map
interfaceVtblMap.insert({{b->sym, interfaces_index}, gvar});
if (!define && defineOnDeclare(aggrdecl))
define = true;
if (!define)
define = defineOnDeclare(aggrdecl);
}
if (define && !gvar->hasInitializer()) {

View file

@ -54,8 +54,8 @@ LLGlobalVariable* IrStruct::getTypeInfoSymbol(bool define) {
emitTypeInfoMetadata(typeInfo, aggrdecl->type);
if (!define && defineOnDeclare(aggrdecl))
define = true;
if (!define)
define = defineOnDeclare(aggrdecl);
}
if (define) {

View file

@ -28,8 +28,8 @@ LLValue *IrGlobal::getValue(bool define) {
if (!value) {
declare();
if (!define && defineOnDeclare(V))
define = true;
if (!define)
define = defineOnDeclare(V);
}
if (define && !(V->storage_class & STCextern)) {