================
@@ -1992,11 +2015,36 @@ void
LoweringPreparePass::buildCXXGlobalPriorityInitFuncs() {
void LoweringPreparePass::buildCXXGlobalInitFunc() {
buildCXXGlobalPriorityInitFuncs();
- if (dynamicInitializers.empty())
+ auto moduleInitFnName = mlirModule->getAttrOfType<mlir::StringAttr>(
+ cir::CIRDialect::getCXXModuleInitFnNameAttrName());
+ auto importedInits = mlirModule->getAttrOfType<mlir::ArrayAttr>(
+ cir::CIRDialect::getCXXModuleImportedInitsAttrName());
+
+ // As in classic CodeGen, a C++20 named-module interface unit gets its
+ // initializer function even with nothing to run, since importing
+ // translation units may call it; any other translation unit gets one only
+ // when there is something to call.
+ if (dynamicInitializers.empty() && !importedInits && !moduleInitFnName)
return;
+ CIRBaseBuilderTy builder(getContext());
+ builder.setInsertionPointToEnd(&mlirModule.getBodyRegion().back());
+ mlir::Location loc = mlirModule.getLoc();
+
+ // The initializers of the imported C++20 named modules, recorded by CIRGen
+ // as the mangled names of functions this translation unit declares and
+ // calls before its own initializers.
+ llvm::SmallVector<cir::FuncOp> initializers;
+ if (importedInits)
+ for (mlir::Attribute name : importedInits)
+ initializers.push_back(
+ buildRuntimeFunction(builder,
cast<mlir::StringAttr>(name).getValue(),
+ loc, builder.getVoidFnTy()));
+ initializers.append(dynamicInitializers.begin(), dynamicInitializers.end());
----------------
keryell wrote:
Interesting concept.
I am using the modules & CIR to speedup compilation for GPU and I did not hit
this...
https://github.com/llvm/llvm-project/pull/229648
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits