From b1bd6fb2ac03ce6cc43855bef9bd45cf9b8fec1a Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Wed, 30 Sep 2020 21:26:26 +0200 Subject: [PATCH] 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. --- gen/declarations.cpp | 33 +++++++++++------------------- gen/function-inlining.cpp | 3 +++ tests/codegen/inlining_templates.d | 10 ++++----- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/gen/declarations.cpp b/gen/declarations.cpp index e29a385cbe..e648f109de 100644 --- a/gen/declarations.cpp +++ b/gen/declarations.cpp @@ -371,28 +371,19 @@ public: return; } - // Force codegen if this is a templated function with pragma(inline, true). - if ((decl->members->length == 1) && - ((*decl->members)[0]->isFuncDeclaration()) && - ((*decl->members)[0]->isFuncDeclaration()->inlining == PINLINEalways)) { - 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; - } + // 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 || - decl->tempdecl == Type::rtinfoImpl)) { - // Emitting object.RTInfo(Impl) template instantiations in dcompute - // modules would require dcompute support for global variables. - Logger::println("Skipping object.RTInfo(Impl) template instantiations " - "in dcompute modules."); - return; - } + if (irs->dcomputetarget && (decl->tempdecl == Type::rtinfo || + decl->tempdecl == Type::rtinfoImpl)) { + // Emitting object.RTInfo(Impl) template instantiations in dcompute + // modules would require dcompute support for global variables. + Logger::println("Skipping object.RTInfo(Impl) template instantiations " + "in dcompute modules."); + return; } for (auto &m : *decl->members) { diff --git a/gen/function-inlining.cpp b/gen/function-inlining.cpp index fc84fe1524..8d23f32bca 100644 --- a/gen/function-inlining.cpp +++ b/gen/function-inlining.cpp @@ -73,6 +73,9 @@ bool isInlineCandidate(FuncDeclaration &fdecl) { } // end anonymous namespace bool alreadyOrWillBeDefined(FuncDeclaration &fdecl) { + if (fdecl.isFuncLiteralDeclaration()) // emitted into each referencing CU + return true; + for (FuncDeclaration *f = &fdecl; f;) { if (!f->isInstantiated() && f->inNonRoot()) { return false; diff --git a/tests/codegen/inlining_templates.d b/tests/codegen/inlining_templates.d index 1112e99518..510929d790 100644 --- a/tests/codegen/inlining_templates.d +++ b/tests/codegen/inlining_templates.d @@ -31,10 +31,8 @@ void main() { } -// CHECK-NOT: declare{{.*}}_D6inputs10inlinables__T12template_fooTiZQrUNaNbNiNfiZi -// CHECK-NOT: declare{{.*}}_D3std9exception__T7enforce +// CHECK-NOT: declare {{.*}}template_foo -// CHECK-DAG: define{{.*}}_D6inputs10inlinables__T12template_fooTiZQrUNaNbNiNfiZi{{.*}}) #[[ATTR:[0-9]+]] -// CHECK-DAG: define{{.*}}_D3std9exception__T7enforce{{.*}}) #[[ATTR]] - -// CHECK-DAG: attributes #[[ATTR]] ={{.*}} alwaysinline +// CHECK-NOT: declare {{.*}}call_enforce_with_default_template_params +// CHECK-NOT: declare {{.*}}__lambda +// CHECK-NOT: declare {{.*}}_D3std9exception__T7enforce