-linkonce-templates: Cull 'discardable' template instances (#3899)

Such instances are guaranteed not to need codegen (e.g., CTFE only).
This commit is contained in:
Martin Kinkelin 2022-01-29 14:07:43 +01:00 committed by GitHub
parent c100c15ae0
commit 423a1d8270
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View file

@ -318,8 +318,13 @@ public:
return;
}
// FIXME: This is #673 all over again.
if (!global.params.linkonceTemplates && !decl->needsCodegen()) {
// With -linkonce-templates, only non-speculative instances make it to
// module members (see `TemplateInstance.appendToModuleMember()`), and we
// don't need full needsCodegen() culling in that case; isDiscardable() is
// sufficient. Speculative ones are lazily emitted if actually referenced
// during codegen - per IR module.
if ((global.params.linkonceTemplates && decl->isDiscardable()) ||
(!global.params.linkonceTemplates && !decl->needsCodegen())) {
Logger::println("Does not need codegen, skipping.");
return;
}