forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[C++20] [Modules] Introduce -fexperimental-modules-reduced-bmi (llvm#…
…85050) This is the driver part of llvm#75894. This patch introduces '-fexperimental-modules-reduced-bmi' to enable generating the reduced BMI. This patch did: - When `-fexperimental-modules-reduced-bmi` is specified but `--precompile` is not specified for a module unit, we'll skip the precompile phase to avoid unnecessary two-phase compilation phases. Then if `-c` is specified, we will generate the reduced BMI in CodeGenAction as a by-product. - When `-fexperimental-modules-reduced-bmi` is specified and `--precompile` is specified, we will generate the reduced BMI in GenerateModuleInterfaceAction as a by-product. - When `-fexperimental-modules-reduced-bmi` is specified for a non-module unit. We don't do anything nor try to give a warn. This is more user friendly so that the end users can try to test and experiment with the feature without asking help from the build systems. The core design idea is that users should be able to enable this easily with the existing cmake mechanisms. The future plan for the flag is: - Add this to clang19 and make it opt-in for 1~2 releases. It depends on the testing feedback to decide how long we like to make it opt-in. - Then we can announce the existing BMI generating may be deprecated and suggesting people (end users or build systems) to enable this for 1~2 releases. - Finally we will enable this by default. When that time comes, the term `BMI` will refer to the reduced BMI today and the existing BMI will only be meaningful to build systems which loves to support two phase compilations. I'll send release notes and document in seperate commits after this get landed.
- Loading branch information
1 parent
7e0b154
commit fe6a0af
Showing
9 changed files
with
159 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// It is annoying to handle different slash direction | ||
// in Windows and Linux. So we disable the test on Windows | ||
// here. | ||
// REQUIRES: !system-windows | ||
// On AIX, the default output for `-c` may be `.s` instead of `.o`, | ||
// which makes the test fail. So disable the test on AIX. | ||
// UNSUPPORTED: system-aix | ||
// | ||
// RUN: rm -rf %t && split-file %s %t && cd %t | ||
// | ||
// RUN: %clang -std=c++20 Hello.cppm -fmodule-output=Hello.pcm \ | ||
// RUN: -fexperimental-modules-reduced-bmi -c -o Hello.o -### 2>&1 | FileCheck Hello.cppm | ||
// | ||
// RUN: %clang -std=c++20 Hello.cppm \ | ||
// RUN: -fexperimental-modules-reduced-bmi -c -o Hello.o -### 2>&1 | \ | ||
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-UNSPECIFIED | ||
// | ||
// RUN: %clang -std=c++20 Hello.cppm \ | ||
// RUN: -fexperimental-modules-reduced-bmi -c -### 2>&1 | \ | ||
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-NO-O | ||
// | ||
// RUN: %clang -std=c++20 Hello.cppm \ | ||
// RUN: -fexperimental-modules-reduced-bmi -c -o AnotherName.o -### 2>&1 | \ | ||
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-ANOTHER-NAME | ||
// | ||
// RUN: %clang -std=c++20 Hello.cppm --precompile -fexperimental-modules-reduced-bmi \ | ||
// RUN: -o Hello.full.pcm -### 2>&1 | FileCheck Hello.cppm \ | ||
// RUN: --check-prefix=CHECK-EMIT-MODULE-INTERFACE | ||
// | ||
// RUN: %clang -std=c++20 Hello.cc -fexperimental-modules-reduced-bmi -Wall -Werror \ | ||
// RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc | ||
|
||
//--- Hello.cppm | ||
export module Hello; | ||
|
||
// Test that we won't generate the emit-module-interface as 2 phase compilation model. | ||
// CHECK-NOT: -emit-module-interface | ||
// CHECK: "-fexperimental-modules-reduced-bmi" | ||
|
||
// CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm | ||
|
||
// CHECK-NO-O: -fmodule-output=Hello.pcm | ||
// CHECK-ANOTHER-NAME: -fmodule-output=AnotherName.pcm | ||
|
||
// With `-emit-module-interface` specified, we should still see the `-emit-module-interface` | ||
// flag. | ||
// CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface | ||
|
||
//--- Hello.cc | ||
|
||
// CHECK-NOT: "-fexperimental-modules-reduced-bmi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir -p %t | ||
// RUN: split-file %s %t | ||
// | ||
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.reduced.pcm | ||
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -fexperimental-modules-reduced-bmi -fmodule-output=%t/a.pcm \ | ||
// RUN: -S -emit-llvm -o %t/a.ll | ||
// | ||
// Test that the generated BMI from `-fexperimental-modules-reduced-bmi -fmodule-output=` is same with | ||
// `-emit-reduced-module-interface`. | ||
// RUN: diff %t/a.reduced.pcm %t/a.pcm | ||
// | ||
// Test that we can consume the produced BMI correctly. | ||
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify | ||
// | ||
// RUN: rm -f %t/a.pcm | ||
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -fexperimental-modules-reduced-bmi -fmodule-output=%t/a.pcm \ | ||
// RUN: -emit-module-interface -o %t/a.full.pcm | ||
// RUN: diff %t/a.reduced.pcm %t/a.pcm | ||
// RUN: not diff %t/a.pcm %t/a.full.pcm | ||
// | ||
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -fmodule-file=a=%t/a.pcm -fsyntax-only -verify | ||
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -fmodule-file=a=%t/a.full.pcm -fsyntax-only -verify | ||
|
||
//--- a.cppm | ||
export module a; | ||
export int a() { | ||
return 43; | ||
} | ||
|
||
//--- b.cppm | ||
// Test that we can consume the produced BMI correctly as a smocking test. | ||
// expected-no-diagnostics | ||
export module b; | ||
import a; | ||
export int b() { return a(); } |