[C++20][Modules] Elide unused guard variables in Itanium ABI module initializers.
authorIain Sandoe <iain@sandoe.co.uk>
Sat, 24 Sep 2022 15:01:44 +0000 (16:01 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sun, 18 Dec 2022 09:16:27 +0000 (09:16 +0000)
commitbd7f4c561f5e2385ebe5500a044efe0de30cccaa
tree6057783eb5b3010ccea2b3bd4015cd61d95e70c6
parent541ef3d61e9341cd38420c0dbca9250c4d0ea04c
[C++20][Modules] Elide unused guard variables in Itanium ABI module initializers.

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, and also does
not import any other modules, we can elide the guard variable.

Differential Revision: https://reviews.llvm.org/D134589
clang/lib/CodeGen/CGDeclCXX.cpp
clang/test/CodeGenCXX/module-initializer-guard-elision.cpp [new file with mode: 0644]