Don't enforce (normal) emission for pragma(inline, true) function templates, and don't cull lambdas (#3570)

With the new available_externally emission into each referencing CU, the
enforced regular emission from the module members tree shouldn't be
required anymore.

After adapting the codegen/inlining_templates.d lit-test accordingly (no
IR definitions anymore in .ll file, because available_externally doesn't
make it there), I've noticed that a lambda in imported and inlined
call_enforce_with_default_template_params() wasn't emitted - it got
culled by alreadyOrWillBeDefined().
Function/delegate literals aren't culled anymore.
This commit is contained in:
Martin Kinkelin 2020-09-30 21:26:26 +02:00 committed by GitHub
parent d33f6f9bbd
commit b1bd6fb2ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 27 deletions

View file

@ -371,28 +371,19 @@ public:
return; return;
} }
// Force codegen if this is a templated function with pragma(inline, true). // FIXME: This is #673 all over again.
if ((decl->members->length == 1) && if (!decl->needsCodegen()) {
((*decl->members)[0]->isFuncDeclaration()) && Logger::println("Does not need codegen, skipping.");
((*decl->members)[0]->isFuncDeclaration()->inlining == PINLINEalways)) { return;
Logger::println("needsCodegen() == false, but function is marked with " }
"pragma(inline, true), so it really does need "
"codegen.");
} else {
// FIXME: This is #673 all over again.
if (!decl->needsCodegen()) {
Logger::println("Does not need codegen, skipping.");
return;
}
if (irs->dcomputetarget && (decl->tempdecl == Type::rtinfo || if (irs->dcomputetarget && (decl->tempdecl == Type::rtinfo ||
decl->tempdecl == Type::rtinfoImpl)) { decl->tempdecl == Type::rtinfoImpl)) {
// Emitting object.RTInfo(Impl) template instantiations in dcompute // Emitting object.RTInfo(Impl) template instantiations in dcompute
// modules would require dcompute support for global variables. // modules would require dcompute support for global variables.
Logger::println("Skipping object.RTInfo(Impl) template instantiations " Logger::println("Skipping object.RTInfo(Impl) template instantiations "
"in dcompute modules."); "in dcompute modules.");
return; return;
}
} }
for (auto &m : *decl->members) { for (auto &m : *decl->members) {

View file

@ -73,6 +73,9 @@ bool isInlineCandidate(FuncDeclaration &fdecl) {
} // end anonymous namespace } // end anonymous namespace
bool alreadyOrWillBeDefined(FuncDeclaration &fdecl) { bool alreadyOrWillBeDefined(FuncDeclaration &fdecl) {
if (fdecl.isFuncLiteralDeclaration()) // emitted into each referencing CU
return true;
for (FuncDeclaration *f = &fdecl; f;) { for (FuncDeclaration *f = &fdecl; f;) {
if (!f->isInstantiated() && f->inNonRoot()) { if (!f->isInstantiated() && f->inNonRoot()) {
return false; return false;

View file

@ -31,10 +31,8 @@ void main()
{ {
} }
// CHECK-NOT: declare{{.*}}_D6inputs10inlinables__T12template_fooTiZQrUNaNbNiNfiZi // CHECK-NOT: declare {{.*}}template_foo
// CHECK-NOT: declare{{.*}}_D3std9exception__T7enforce
// CHECK-DAG: define{{.*}}_D6inputs10inlinables__T12template_fooTiZQrUNaNbNiNfiZi{{.*}}) #[[ATTR:[0-9]+]] // CHECK-NOT: declare {{.*}}call_enforce_with_default_template_params
// CHECK-DAG: define{{.*}}_D3std9exception__T7enforce{{.*}}) #[[ATTR]] // CHECK-NOT: declare {{.*}}__lambda
// CHECK-NOT: declare {{.*}}_D3std9exception__T7enforce
// CHECK-DAG: attributes #[[ATTR]] ={{.*}} alwaysinline