[PATCH] D134589: [C++20][Modules] Elide unused guard variables in Itanium ABI module initializers.

Iain Sandoe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 24 08:20:31 PDT 2022


iains created this revision.
Herald added a project: All.
iains added a reviewer: urnathan.
iains added a subscriber: clang-modules.
iains published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

For the Itanium ABI, we emit an initializer for each module.  This is responsible
for handling initialization of global vars.  Relates to P1874R1.

The initializer has a known mangling and is automatically called from any TU that
imports a module. Since, at present, the importer has no way to determine that an
imported module does not require an initializer, we generate the initializer for
all cases (even when it is empty).

Initializers must be run once, with the ordering guaranteed by the import graph
and this is ensured in the current code by addition of a guard variable.

In the case that a module has no requirement for global initializers, we can
elide the guard variable - in this case an optimisation.

For some offload targets, this can also be a matter of correctness - since they
might not support a global variable of this nature (and have empty global inits).

In order to handle the second case better, we also eliminate the guard variable
when a current module imports other modules.  This means that we might call the
initializers for the sub-modules more than once - however, if they actually have
active content, that will be guarded locally.  If the entire tree is empty, then
there will be no guard variables - which is appropriate in the off-loading case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134589

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/module-initializer-guard-elision.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134589.462675.patch
Type: text/x-patch
Size: 4833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220924/3f13a0de/attachment-0001.bin>


More information about the cfe-commits mailing list