Skip to content

[C++20] [Modules] Convert '-fexperimental-modules-reduced-bmi' to '-fmodules-reduced-bmi' #114382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ Modified Compiler Flags
``memset`` and similar functions for which it is a documented undefined
behavior.

- Added ``-fmodules-reduced-bmi`` flag corresponding to
``-fexperimental-modules-reduced-bmi`` flag. The ``-fmodules-reduced-bmi`` flag
is intended to be enabled by default in the future.

Removed Compiler Flags
-------------------------

Expand Down
23 changes: 11 additions & 12 deletions clang/docs/StandardCPlusPlusModules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -602,16 +602,16 @@ unnecessary dependencies for the BMI. To mitigate the problem, Clang has a
compiler option to reduce the information contained in the BMI. These two
formats are known as Full BMI and Reduced BMI, respectively.

Users can use the ``-fexperimental-modules-reduced-bmi`` option to produce a
Users can use the ``-fmodules-reduced-bmi`` option to produce a
Reduced BMI.

For the one-phase compilation model (CMake implements this model), with
``-fexperimental-modules-reduced-bmi``, the generated BMI will be a Reduced
``-fmodules-reduced-bmi``, the generated BMI will be a Reduced
BMI automatically. (The output path of the BMI is specified by
``-fmodule-output=`` as usual with the one-phase compilation model).

It is also possible to produce a Reduced BMI with the two-phase compilation
model. When ``-fexperimental-modules-reduced-bmi``, ``--precompile``, and
model. When ``-fmodules-reduced-bmi``, ``--precompile``, and
``-fmodule-output=`` are specified, the generated BMI specified by ``-o`` will
be a full BMI and the BMI specified by ``-fmodule-output=`` will be a Reduced
BMI. The dependency graph in this case would look like:
Expand All @@ -625,7 +625,7 @@ BMI. The dependency graph in this case would look like:
-> ...
-> consumer_n.cpp

Clang does not emit diagnostics when ``-fexperimental-modules-reduced-bmi`` is
Clang does not emit diagnostics when ``-fmodules-reduced-bmi`` is
used with a non-module unit. This design permits users of the one-phase
compilation model to try using reduced BMIs without needing to modify the build
system. The two-phase compilation module requires build system support.
Expand Down Expand Up @@ -691,11 +691,10 @@ ensure it is reachable, e.g. ``using N::g;``.
Support for Reduced BMIs is still experimental, but it may become the default
in the future. The expected roadmap for Reduced BMIs as of Clang 19.x is:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
in the future. The expected roadmap for Reduced BMIs as of Clang 19.x is:
in the future. The expected roadmap for Reduced BMIs as of Clang 20.x is:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked up the dictionary and it says "as of" means "from". So I feel the wording is good since it was added in 19.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's confusing to update/clarify the plan during the 20.x cycle and then not update the "as of 19.x" (even though the overall shape of the plan didn't change). If you want to keep the "as of 19.x", then we should specify which steps have been done already (see below), though IMO any updates here should also update the "as of".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as suggested.


1. ``-fexperimental-modules-reduced-bmi`` is opt-in for 1~2 releases. The period depends
1. ``-fexperimental-modules-reduced-bmi`` was introduced in v19.x
2. For v20.x, ``-fmodules-reduced-bmi`` is introduced as an equivalent non-experimental
option. It is expected to stay opt-in for 1~2 releases, though the period depends
on user feedback and may be extended.
2. Announce that Reduced BMIs are no longer experimental and introduce
``-fmodules-reduced-bmi`` as a new option, and recommend use of the new
option. This transition is expected to take 1~2 additional releases as well.
3. Finally, ``-fmodules-reduced-bmi`` will be the default. When that time
comes, the term BMI will refer to the Reduced BMI and the Full BMI will only
be meaningful to build systems which elect to support two-phase compilation.
Expand Down Expand Up @@ -814,8 +813,8 @@ With reduced BMI, non-cascading changes can be more powerful. For example,

.. code-block:: console

$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fexperimental-modules-reduced-bmi -o A.o
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fmodules-reduced-bmi -o A.o
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fmodules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
$ md5sum B.pcm
6c2bd452ca32ab418bf35cd141b060b9 B.pcm

Expand All @@ -831,8 +830,8 @@ and recompile the example:

.. code-block:: console

$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fexperimental-modules-reduced-bmi -o A.o
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fexperimental-modules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
$ clang++ -std=c++20 A.cppm -c -fmodule-output=A.pcm -fmodules-reduced-bmi -o A.o
$ clang++ -std=c++20 B.cppm -c -fmodule-output=B.pcm -fmodules-reduced-bmi -o B.o -fmodule-file=A=A.pcm
$ md5sum B.pcm
6c2bd452ca32ab418bf35cd141b060b9 B.pcm

Expand Down
5 changes: 4 additions & 1 deletion clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -3194,11 +3194,14 @@ defm skip_odr_check_in_gmf : BoolOption<"f", "skip-odr-check-in-gmf",
"Perform ODR checks for decls in the global module fragment.">>,
Group<f_Group>;

def modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
def modules_reduced_bmi : Flag<["-"], "fmodules-reduced-bmi">,
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
HelpText<"Generate the reduced BMI">,
MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>;

def experimental_modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">,
Group<f_Group>, Visibility<[ClangOption, CC1Option]>, Alias<modules_reduced_bmi>;

def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
Visibility<[ClangOption, CC1Option, CLOption]>,
HelpText<"Embed the contents of all files read by this compilation into "
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4257,7 +4257,7 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
(Input.getType() == driver::types::TY_CXXModule ||
Input.getType() == driver::types::TY_PP_CXXModule)) {
CmdArgs.push_back("-fexperimental-modules-reduced-bmi");
CmdArgs.push_back("-fmodules-reduced-bmi");

if (Args.hasArg(options::OPT_fmodule_output_EQ))
Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
Expand All @@ -4267,7 +4267,7 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D,
getCXX20NamedModuleOutputPath(Args, Input.getBaseInput())));
}

// Noop if we see '-fexperimental-modules-reduced-bmi' with other translation
// Noop if we see '-fmodules-reduced-bmi' with other translation
// units than module units. This is more user friendly to allow end uers to
// enable this feature without asking for help from build systems.
Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);
Expand Down
34 changes: 32 additions & 2 deletions clang/test/Driver/module-fgen-reduced-bmi.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,41 @@
//
// RUN: %clang -std=c++20 Hello.cc -fexperimental-modules-reduced-bmi -Wall -Werror \
// RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc
//
// RUN: %clang -std=c++20 Hello.cppm -fmodule-output=Hello.pcm \
// RUN: -fmodules-reduced-bmi -c -o Hello.o -### 2>&1 | FileCheck Hello.cppm
//
// RUN: %clang -std=c++20 Hello.cppm \
// RUN: -fmodules-reduced-bmi -c -o Hello.o -### 2>&1 | \
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-UNSPECIFIED
//
// RUN: %clang -std=c++20 Hello.cppm \
// RUN: -fmodules-reduced-bmi -c -### 2>&1 | \
// RUN: FileCheck Hello.cppm --check-prefix=CHECK-NO-O
//
// RUN: %clang -std=c++20 Hello.cppm \
// RUN: -fmodules-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 -fmodules-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 -fmodules-reduced-bmi -Wall -Werror \
// RUN: -c -o Hello.o -### 2>&1 | FileCheck Hello.cc
//
// RUN: %clang -std=c++20 Hello.cppm -fmodule-output=Hello.pcm -c -o Hello.o \
// RUN: -Wno-missing-reduced-bmi -### 2>&1 | FileCheck Hello.cppm -check-prefix=NO_WARN
//
// RUN: %clang -std=c++20 Hello.cppm --precompile -o Hello.pcm \
// RUN: -Wno-missing-reduced-bmi -### 2>&1 | FileCheck Hello.cppm -check-prefix=NO_WARN

//--- 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: "-fmodules-reduced-bmi"

// CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm

Expand All @@ -46,6 +74,8 @@ export module Hello;
// flag.
// CHECK-EMIT-MODULE-INTERFACE: -emit-module-interface

// NO_WARN-NOT: warning

//--- Hello.cc

// CHECK-NOT: "-fexperimental-modules-reduced-bmi"
// CHECK-NOT: "-fmodules-reduced-bmi"
Loading