[clang] 7ee421d - [C++20] [Modules] Skip calls to module initializer to modules if we know the module doesn't init anything

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 22:59:31 PDT 2024


Author: Chuanqi Xu
Date: 2024-07-02T13:55:30+08:00
New Revision: 7ee421d29612ae919edfe7250b87e3c738d66a26

URL: https://github.com/llvm/llvm-project/commit/7ee421d29612ae919edfe7250b87e3c738d66a26
DIFF: https://github.com/llvm/llvm-project/commit/7ee421d29612ae919edfe7250b87e3c738d66a26.diff

LOG: [C++20] [Modules] Skip calls to module initializer to modules if we know the module doesn't init anything

Close https://github.com/llvm/llvm-project/issues/97244

This is an optimization allowed by the modules's ABI to skip calls to
imported modules for which we know nothing will be initialized.

Added: 
    clang/test/Modules/pr97244.cppm

Modified: 
    clang/lib/CodeGen/CGDeclCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index e18b339b31d24..05dd7ddb86fa6 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -840,6 +840,10 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
       // No Itanium initializer in header like modules.
       if (M->isHeaderLikeModule())
         continue;
+      // We're allowed to skip the initialization if we are sure it doesn't
+      // do any thing.
+      if (!M->isNamedModuleInterfaceHasInit())
+        continue;
       llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
       SmallString<256> FnName;
       {

diff  --git a/clang/test/Modules/pr97244.cppm b/clang/test/Modules/pr97244.cppm
new file mode 100644
index 0000000000000..ad8b466290cf0
--- /dev/null
+++ b/clang/test/Modules/pr97244.cppm
@@ -0,0 +1,30 @@
+// REQUIRES: !system-windows
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Empty.cppm \
+// RUN:     -emit-module-interface -o %t/Empty.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Empty2.cppm \
+// RUN:     -fprebuilt-module-path=%t -emit-module-interface -o %t/Empty2.pcm
+// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/main.cpp \
+// RUN:     -fprebuilt-module-path=%t -emit-llvm -o - | FileCheck %t/main.cpp
+// RUN: %clang_cc1 -std=c++20  -triple %itanium_abi_triple %t/Empty2.pcm \
+// RUN:     -fprebuilt-module-path=%t -emit-llvm -o - | FileCheck %t/Empty2.cppm
+
+//--- Empty.cppm
+export module Empty;
+
+//--- Empty2.cppm
+export module Empty2;
+import Empty;
+
+// CHECK-NOT: _ZGIW5Empty
+
+//--- main.cpp
+import Empty;
+import Empty2;
+
+// CHECK-NOT: _ZGIW5Empty
+// CHECK-NOT: _ZGIW6Empty2


        


More information about the cfe-commits mailing list