https://github.com/ChuanqiXu9 updated https://github.com/llvm/llvm-project/pull/85050
>From 79706501a7a3f0f2e0e9c9411bdd5e00e34ae175 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu <yedeng...@linux.alibaba.com> Date: Tue, 12 Mar 2024 17:26:49 +0800 Subject: [PATCH 1/3] [C++20] [Modules] Introduce -fgen-reduced-bmi --- clang/include/clang/CodeGen/CodeGenAction.h | 2 + clang/include/clang/Driver/Options.td | 6 +++ .../include/clang/Frontend/FrontendOptions.h | 9 +++- clang/include/clang/Serialization/ASTWriter.h | 7 +-- clang/lib/CodeGen/CodeGenAction.cpp | 19 +++++++ clang/lib/Driver/Driver.cpp | 12 ++++- clang/lib/Driver/ToolChains/Clang.cpp | 23 ++++++-- clang/lib/Frontend/FrontendActions.cpp | 7 +++ clang/lib/Frontend/PrecompiledPreamble.cpp | 3 +- clang/lib/Serialization/GeneratePCH.cpp | 23 ++++++-- .../test/Driver/module-fgen-reduced-bmi.cppm | 53 +++++++++++++++++++ clang/test/Modules/gen-reduced-bmi.cppm | 36 +++++++++++++ 12 files changed, 186 insertions(+), 14 deletions(-) create mode 100644 clang/test/Driver/module-fgen-reduced-bmi.cppm create mode 100644 clang/test/Modules/gen-reduced-bmi.cppm diff --git a/clang/include/clang/CodeGen/CodeGenAction.h b/clang/include/clang/CodeGen/CodeGenAction.h index 7ad2988e589eb2..186dbb43f01ef7 100644 --- a/clang/include/clang/CodeGen/CodeGenAction.h +++ b/clang/include/clang/CodeGen/CodeGenAction.h @@ -57,6 +57,8 @@ class CodeGenAction : public ASTFrontendAction { bool loadLinkModules(CompilerInstance &CI); protected: + bool BeginSourceFileAction(CompilerInstance &CI) override; + /// Create a new code generation action. If the optional \p _VMContext /// parameter is supplied, the action uses it without taking ownership, /// otherwise it creates a fresh LLVM context and takes ownership. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index f5289fb00c895e..3b920db56586f2 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3017,6 +3017,7 @@ defm prebuilt_implicit_modules : BoolFOption<"prebuilt-implicit-modules", def fmodule_output_EQ : Joined<["-"], "fmodule-output=">, Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>, + MarshallingInfoString<FrontendOpts<"ModuleOutputPath">>, HelpText<"Save intermediate module file results when compiling a standard C++ module unit.">; def fmodule_output : Flag<["-"], "fmodule-output">, Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option]>, @@ -3030,6 +3031,11 @@ 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 gen_reduced_bmi : Flag<["-"], "fgen-reduced-bmi">, + Group<i_Group>, Visibility<[ClangOption, CC1Option]>, + HelpText<"Generate the reduced BMI">, + MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>; + def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group<i_Group>, Visibility<[ClangOption, CC1Option]>, MetaVarName<"<seconds>">, HelpText<"Specify the interval (in seconds) between attempts to prune the module cache">, diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 8085dbcbf671a6..ddfd4f30d1b773 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -387,6 +387,10 @@ class FrontendOptions { LLVM_PREFERRED_TYPE(bool) unsigned ModulesShareFileManager : 1; + /// Whether to generate reduced BMI for C++20 named modules. + LLVM_PREFERRED_TYPE(bool) + unsigned GenReducedBMI : 1; + CodeCompleteOptions CodeCompleteOpts; /// Specifies the output format of the AST. @@ -553,6 +557,9 @@ class FrontendOptions { /// Path which stores the output files for -ftime-trace std::string TimeTracePath; + /// Output Path for module output file. + std::string ModuleOutputPath; + public: FrontendOptions() : DisableFree(false), RelocatablePCH(false), ShowHelp(false), @@ -565,7 +572,7 @@ class FrontendOptions { BuildingImplicitModuleUsesLock(true), ModulesEmbedAllFiles(false), IncludeTimestamps(true), UseTemporary(true), AllowPCMWithCompilerErrors(false), ModulesShareFileManager(true), - TimeTraceGranularity(500) {} + GenReducedBMI(false), TimeTraceGranularity(500) {} /// getInputKindForExtension - Return the appropriate input kind for a file /// extension. For example, "c" would return Language::C. diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 3ed9803fa3745b..bd310b6c7a5cdd 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -846,7 +846,7 @@ class ASTWriter : public ASTDeserializationListener, /// AST and semantic-analysis consumer that generates a /// precompiled header from the parsed source code. class PCHGenerator : public SemaConsumer { - const Preprocessor &PP; + Preprocessor &PP; std::string OutputFile; std::string isysroot; Sema *SemaPtr; @@ -867,11 +867,12 @@ class PCHGenerator : public SemaConsumer { DiagnosticsEngine &getDiagnostics() const { return SemaPtr->getDiagnostics(); } + Preprocessor &getPreprocessor() { return PP; } virtual Module *getEmittingModule(ASTContext &Ctx); public: - PCHGenerator(const Preprocessor &PP, InMemoryModuleCache &ModuleCache, + PCHGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile, StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, @@ -893,7 +894,7 @@ class ReducedBMIGenerator : public PCHGenerator { virtual Module *getEmittingModule(ASTContext &Ctx) override; public: - ReducedBMIGenerator(const Preprocessor &PP, InMemoryModuleCache &ModuleCache, + ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile); void HandleTranslationUnit(ASTContext &Ctx) override; diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index bb9aaba025fa59..cd0d011e8c72b0 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -25,8 +25,11 @@ #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Driver/DriverDiagnostic.h" #include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendActions.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Frontend/MultiplexConsumer.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Serialization/ASTWriter.h" #include "llvm/ADT/Hashing.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h" @@ -1003,6 +1006,12 @@ CodeGenerator *CodeGenAction::getCodeGenerator() const { return BEConsumer->getCodeGenerator(); } +bool CodeGenAction::BeginSourceFileAction(CompilerInstance &CI) { + if (CI.getFrontendOpts().GenReducedBMI) + CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface); + return true; +} + static std::unique_ptr<raw_pwrite_stream> GetOutputStream(CompilerInstance &CI, StringRef InFile, BackendAction Action) { switch (Action) { @@ -1061,6 +1070,16 @@ CodeGenAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { CI.getPreprocessor().addPPCallbacks(std::move(Callbacks)); } + if (CI.getFrontendOpts().GenReducedBMI && + !CI.getFrontendOpts().ModuleOutputPath.empty()) { + std::vector<std::unique_ptr<ASTConsumer>> Consumers{2}; + Consumers[0] = std::make_unique<ReducedBMIGenerator>( + CI.getPreprocessor(), CI.getModuleCache(), + CI.getFrontendOpts().ModuleOutputPath); + Consumers[1] = std::move(Result); + return std::make_unique<MultiplexConsumer>(std::move(Consumers)); + } + return std::move(Result); } diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 1a0f5f27eda2fc..a4a5b6aae07ead 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4749,6 +4749,14 @@ Action *Driver::ConstructPhaseAction( if (Args.hasArg(options::OPT_extract_api)) return C.MakeAction<ExtractAPIJobAction>(Input, types::TY_API_INFO); + // With '-fgen-reduced-bmi', we don't want to run the precompile phase + // unless the user specified '--precompile'. In the case the '--precompile' + // flag is enabled, we will try to emit the reduced BMI as a by product + // in GenerateModuleInterfaceAction. + if (Args.hasArg(options::OPT_gen_reduced_bmi) && + !Args.getLastArg(options::OPT__precompile)) + return Input; + types::ID OutputTy = getPrecompiledType(Input->getType()); assert(OutputTy != types::TY_INVALID && "Cannot precompile this input type!"); @@ -5903,8 +5911,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, // If we're emitting a module output with the specified option // `-fmodule-output`. if (!AtTopLevel && isa<PrecompileJobAction>(JA) && - JA.getType() == types::TY_ModuleFile && SpecifiedModuleOutput) + JA.getType() == types::TY_ModuleFile && SpecifiedModuleOutput) { + assert(!C.getArgs().hasArg(options::OPT_gen_reduced_bmi)); return GetModuleOutputPath(C, JA, BaseInput); + } // Output to a temporary file? if ((!AtTopLevel && !isSaveTempsEnabled() && diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b03ac6018d2b80..a36a7d470d7527 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4045,9 +4045,26 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D, // module fragment. CmdArgs.push_back("-fskip-odr-check-in-gmf"); - // Claim `-fmodule-output` and `-fmodule-output=` to avoid unused warnings. - Args.ClaimAllArgs(options::OPT_fmodule_output); - Args.ClaimAllArgs(options::OPT_fmodule_output_EQ); + // Noop if we see '-fgen-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. + if (Args.hasArg(options::OPT_gen_reduced_bmi) && + (Input.getType() == driver::types::TY_CXXModule || + Input.getType() == driver::types::TY_PP_CXXModule)) { + CmdArgs.push_back("-fgen-reduced-bmi"); + + if (Args.hasArg(options::OPT_fmodule_output_EQ)) + Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ); + else + CmdArgs.push_back(Args.MakeArgString( + "-fmodule-output=" + + getCXX20NamedModuleOutputPath(Args, Input.getBaseInput()))); + } else { + // To avoid unused warnings. + Args.ClaimAllArgs(options::OPT_gen_reduced_bmi); + Args.ClaimAllArgs(options::OPT_fmodule_output); + Args.ClaimAllArgs(options::OPT_fmodule_output_EQ); + } return HaveModules; } diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 0bc26b694cfc8d..2f077c972d6ed8 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -284,6 +284,13 @@ GenerateModuleInterfaceAction::CreateASTConsumer(CompilerInstance &CI, if (Consumers.empty()) return nullptr; + if (CI.getFrontendOpts().GenReducedBMI && + !CI.getFrontendOpts().ModuleOutputPath.empty()) { + Consumers.push_back(std::make_unique<ReducedBMIGenerator>( + CI.getPreprocessor(), CI.getModuleCache(), + CI.getFrontendOpts().ModuleOutputPath)); + } + return std::make_unique<MultiplexConsumer>(std::move(Consumers)); } diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index 9b0ef30a14121b..fdf05c3613c956 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -290,8 +290,7 @@ class PrecompilePreambleAction : public ASTFrontendAction { class PrecompilePreambleConsumer : public PCHGenerator { public: - PrecompilePreambleConsumer(PrecompilePreambleAction &Action, - const Preprocessor &PP, + PrecompilePreambleConsumer(PrecompilePreambleAction &Action, Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer) diff --git a/clang/lib/Serialization/GeneratePCH.cpp b/clang/lib/Serialization/GeneratePCH.cpp index f54db36d4a0199..4260ba867ad28b 100644 --- a/clang/lib/Serialization/GeneratePCH.cpp +++ b/clang/lib/Serialization/GeneratePCH.cpp @@ -14,6 +14,7 @@ #include "clang/AST/ASTContext.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Lex/HeaderSearch.h" +#include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/SemaConsumer.h" #include "clang/Serialization/ASTReader.h" @@ -23,8 +24,8 @@ using namespace clang; PCHGenerator::PCHGenerator( - const Preprocessor &PP, InMemoryModuleCache &ModuleCache, - StringRef OutputFile, StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, + Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile, + StringRef isysroot, std::shared_ptr<PCHBuffer> Buffer, ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, bool AllowASTWithErrors, bool IncludeTimestamps, bool BuildingImplicitModule, bool ShouldCacheASTInMemory, @@ -88,7 +89,7 @@ ASTDeserializationListener *PCHGenerator::GetASTDeserializationListener() { return &Writer; } -ReducedBMIGenerator::ReducedBMIGenerator(const Preprocessor &PP, +ReducedBMIGenerator::ReducedBMIGenerator(Preprocessor &PP, InMemoryModuleCache &ModuleCache, StringRef OutputFile) : PCHGenerator( @@ -101,12 +102,26 @@ ReducedBMIGenerator::ReducedBMIGenerator(const Preprocessor &PP, Module *ReducedBMIGenerator::getEmittingModule(ASTContext &Ctx) { Module *M = Ctx.getCurrentNamedModule(); - assert(M->isNamedModuleUnit() && + assert(M && M->isNamedModuleUnit() && "ReducedBMIGenerator should only be used with C++20 Named modules."); return M; } void ReducedBMIGenerator::HandleTranslationUnit(ASTContext &Ctx) { + // FIMXE: We'd better to wrap such options to a new class ASTWriterOptions. + getPreprocessor() + .getHeaderSearchInfo() + .getHeaderSearchOpts() + .ModulesSkipDiagnosticOptions = true; + getPreprocessor() + .getHeaderSearchInfo() + .getHeaderSearchOpts() + .ModulesSkipHeaderSearchPaths = true; + getPreprocessor() + .getHeaderSearchInfo() + .getHeaderSearchOpts() + .ModulesSkipPragmaDiagnosticMappings = true; + PCHGenerator::HandleTranslationUnit(Ctx); if (!isComplete()) diff --git a/clang/test/Driver/module-fgen-reduced-bmi.cppm b/clang/test/Driver/module-fgen-reduced-bmi.cppm new file mode 100644 index 00000000000000..77afdf3e74e505 --- /dev/null +++ b/clang/test/Driver/module-fgen-reduced-bmi.cppm @@ -0,0 +1,53 @@ +// 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. +// REQUIRES: !system-aix +// +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: split-file %s %t +// +// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm \ +// RUN: -fgen-reduced-bmi -c -o %t/Hello.o -### 2>&1 | FileCheck %t/Hello.cppm +// +// RUN: %clang -std=c++20 %t/Hello.cppm \ +// RUN: -fgen-reduced-bmi -c -o %t/Hello.o -### 2>&1 | \ +// RUN: FileCheck %t/Hello.cppm --check-prefix=CHECK-UNSPECIFIED +// +// RUN: %clang -std=c++20 %t/Hello.cppm \ +// RUN: -fgen-reduced-bmi -c -### 2>&1 | \ +// RUN: FileCheck %t/Hello.cppm --check-prefix=CHECK-NO-O +// +// RUN: %clang -std=c++20 %t/Hello.cppm \ +// RUN: -fgen-reduced-bmi -c -o %t/AnotherName.o -### 2>&1 | \ +// RUN: FileCheck %t/Hello.cppm --check-prefix=CHECK-ANOTHER-NAME +// +// RUN: %clang -std=c++20 %t/Hello.cppm --precompile -fgen-reduced-bmi \ +// RUN: -o %t/Hello.full.pcm -### 2>&1 | FileCheck %t/Hello.cppm \ +// RUN: --check-prefix=CHECK-EMIT-MODULE-INTERFACE +// +// RUN: %clang -std=c++20 %t/Hello.cc -fgen-reduced-bmi -Wall -Werror \ +// RUN: -c -o %t/Hello.o -### 2>&1 | FileCheck %t/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: "-fgen-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: "-fgen-reduced-bmi" diff --git a/clang/test/Modules/gen-reduced-bmi.cppm b/clang/test/Modules/gen-reduced-bmi.cppm new file mode 100644 index 00000000000000..8c08795ce4e453 --- /dev/null +++ b/clang/test/Modules/gen-reduced-bmi.cppm @@ -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 -fgen-reduced-bmi -fmodule-output=%t/a.pcm \ +// RUN: -S -emit-llvm -o %t/a.ll +// +// Test that the generated BMI from `-fgen-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 -fgen-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(); } >From 7cfb3ee3041349b1b088e2f2c208e47a383a1b28 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu <yedeng...@linux.alibaba.com> Date: Tue, 26 Mar 2024 10:44:22 +0800 Subject: [PATCH 2/3] Use -fmodules-reduced-bmi --- clang/include/clang/Driver/Options.td | 4 +- clang/lib/Driver/Driver.cpp | 6 +-- clang/lib/Driver/ToolChains/Clang.cpp | 8 ++-- .../test/Driver/module-fgen-reduced-bmi.cppm | 46 +++++++++---------- ...uced-bmi.cppm => modules-reduced-bmi.cppm} | 6 +-- 5 files changed, 34 insertions(+), 36 deletions(-) rename clang/test/Modules/{gen-reduced-bmi.cppm => modules-reduced-bmi.cppm} (78%) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 3b920db56586f2..f1a928f747b240 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3031,8 +3031,8 @@ 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 gen_reduced_bmi : Flag<["-"], "fgen-reduced-bmi">, - Group<i_Group>, Visibility<[ClangOption, CC1Option]>, +def modules_reduced_bmi : Flag<["-"], "fmodules-reduced-bmi">, + Group<f_Group>, Visibility<[ClangOption, CC1Option]>, HelpText<"Generate the reduced BMI">, MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index a4a5b6aae07ead..db1ef52e1ca684 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4749,11 +4749,11 @@ Action *Driver::ConstructPhaseAction( if (Args.hasArg(options::OPT_extract_api)) return C.MakeAction<ExtractAPIJobAction>(Input, types::TY_API_INFO); - // With '-fgen-reduced-bmi', we don't want to run the precompile phase + // With '-fmodules-reduced-bmi', we don't want to run the precompile phase // unless the user specified '--precompile'. In the case the '--precompile' // flag is enabled, we will try to emit the reduced BMI as a by product // in GenerateModuleInterfaceAction. - if (Args.hasArg(options::OPT_gen_reduced_bmi) && + if (Args.hasArg(options::OPT_modules_reduced_bmi) && !Args.getLastArg(options::OPT__precompile)) return Input; @@ -5912,7 +5912,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA, // `-fmodule-output`. if (!AtTopLevel && isa<PrecompileJobAction>(JA) && JA.getType() == types::TY_ModuleFile && SpecifiedModuleOutput) { - assert(!C.getArgs().hasArg(options::OPT_gen_reduced_bmi)); + assert(!C.getArgs().hasArg(options::OPT_modules_reduced_bmi)); return GetModuleOutputPath(C, JA, BaseInput); } diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a36a7d470d7527..b0676924b38e08 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4045,13 +4045,13 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D, // module fragment. CmdArgs.push_back("-fskip-odr-check-in-gmf"); - // Noop if we see '-fgen-reduced-bmi' with other translation units than module + // 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. - if (Args.hasArg(options::OPT_gen_reduced_bmi) && + if (Args.hasArg(options::OPT_modules_reduced_bmi) && (Input.getType() == driver::types::TY_CXXModule || Input.getType() == driver::types::TY_PP_CXXModule)) { - CmdArgs.push_back("-fgen-reduced-bmi"); + CmdArgs.push_back("-fmodules-reduced-bmi"); if (Args.hasArg(options::OPT_fmodule_output_EQ)) Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ); @@ -4061,7 +4061,7 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D, getCXX20NamedModuleOutputPath(Args, Input.getBaseInput()))); } else { // To avoid unused warnings. - Args.ClaimAllArgs(options::OPT_gen_reduced_bmi); + Args.ClaimAllArgs(options::OPT_modules_reduced_bmi); Args.ClaimAllArgs(options::OPT_fmodule_output); Args.ClaimAllArgs(options::OPT_fmodule_output_EQ); } diff --git a/clang/test/Driver/module-fgen-reduced-bmi.cppm b/clang/test/Driver/module-fgen-reduced-bmi.cppm index 77afdf3e74e505..a7a6c91f16156d 100644 --- a/clang/test/Driver/module-fgen-reduced-bmi.cppm +++ b/clang/test/Driver/module-fgen-reduced-bmi.cppm @@ -4,45 +4,43 @@ // 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. -// REQUIRES: !system-aix +// UNSUPPORTED: system-aix // -// RUN: rm -rf %t -// RUN: mkdir %t -// RUN: split-file %s %t +// RUN: rm -rf %t && split-file %s %t && cd %t // -// RUN: %clang -std=c++20 %t/Hello.cppm -fmodule-output=%t/Hello.pcm \ -// RUN: -fgen-reduced-bmi -c -o %t/Hello.o -### 2>&1 | FileCheck %t/Hello.cppm +// 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 %t/Hello.cppm \ -// RUN: -fgen-reduced-bmi -c -o %t/Hello.o -### 2>&1 | \ -// RUN: FileCheck %t/Hello.cppm --check-prefix=CHECK-UNSPECIFIED +// 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 %t/Hello.cppm \ -// RUN: -fgen-reduced-bmi -c -### 2>&1 | \ -// RUN: FileCheck %t/Hello.cppm --check-prefix=CHECK-NO-O +// 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 %t/Hello.cppm \ -// RUN: -fgen-reduced-bmi -c -o %t/AnotherName.o -### 2>&1 | \ -// RUN: FileCheck %t/Hello.cppm --check-prefix=CHECK-ANOTHER-NAME +// 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 %t/Hello.cppm --precompile -fgen-reduced-bmi \ -// RUN: -o %t/Hello.full.pcm -### 2>&1 | FileCheck %t/Hello.cppm \ +// 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 %t/Hello.cc -fgen-reduced-bmi -Wall -Werror \ -// RUN: -c -o %t/Hello.o -### 2>&1 | FileCheck %t/Hello.cc +// RUN: %clang -std=c++20 Hello.cc -fmodules-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: "-fgen-reduced-bmi" +// CHECK: "-fmodules-reduced-bmi" -// CHECK-UNSPECIFIED: -fmodule-output={{.*}}/Hello.pcm +// CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm -// CHECK-NO-O: -fmodule-output={{.*}}/Hello.pcm -// CHECK-ANOTHER-NAME: -fmodule-output={{.*}}/AnotherName.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. @@ -50,4 +48,4 @@ export module Hello; //--- Hello.cc -// CHECK-NOT: "-fgen-reduced-bmi" +// CHECK-NOT: "-fmodules-reduced-bmi" diff --git a/clang/test/Modules/gen-reduced-bmi.cppm b/clang/test/Modules/modules-reduced-bmi.cppm similarity index 78% rename from clang/test/Modules/gen-reduced-bmi.cppm rename to clang/test/Modules/modules-reduced-bmi.cppm index 8c08795ce4e453..84adcf14a335f8 100644 --- a/clang/test/Modules/gen-reduced-bmi.cppm +++ b/clang/test/Modules/modules-reduced-bmi.cppm @@ -3,10 +3,10 @@ // 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 -fgen-reduced-bmi -fmodule-output=%t/a.pcm \ +// RUN: %clang_cc1 -std=c++20 %t/a.cppm -fmodules-reduced-bmi -fmodule-output=%t/a.pcm \ // RUN: -S -emit-llvm -o %t/a.ll // -// Test that the generated BMI from `-fgen-reduced-bmi -fmodule-output=` is same with +// Test that the generated BMI from `-fmodules-reduced-bmi -fmodule-output=` is same with // `-emit-reduced-module-interface`. // RUN: diff %t/a.reduced.pcm %t/a.pcm // @@ -14,7 +14,7 @@ // 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 -fgen-reduced-bmi -fmodule-output=%t/a.pcm \ +// RUN: %clang_cc1 -std=c++20 %t/a.cppm -fmodules-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 >From dc0856aecc103d6fc0961262547c6fa38e5b90d5 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu <yedeng...@linux.alibaba.com> Date: Fri, 29 Mar 2024 10:07:46 +0800 Subject: [PATCH 3/3] Rename to `-fexperimental-modules-reduced-bmi` --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/Driver.cpp | 8 ++++---- clang/lib/Driver/ToolChains/Clang.cpp | 8 ++++---- clang/test/Driver/module-fgen-reduced-bmi.cppm | 16 ++++++++-------- clang/test/Modules/modules-reduced-bmi.cppm | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index f1a928f747b240..b4faae42a9ce5c 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -3031,7 +3031,7 @@ 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<["-"], "fmodules-reduced-bmi">, +def modules_reduced_bmi : Flag<["-"], "fexperimental-modules-reduced-bmi">, Group<f_Group>, Visibility<[ClangOption, CC1Option]>, HelpText<"Generate the reduced BMI">, MarshallingInfoFlag<FrontendOpts<"GenReducedBMI">>; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index db1ef52e1ca684..b2be4f6cc74024 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4749,10 +4749,10 @@ Action *Driver::ConstructPhaseAction( if (Args.hasArg(options::OPT_extract_api)) return C.MakeAction<ExtractAPIJobAction>(Input, types::TY_API_INFO); - // With '-fmodules-reduced-bmi', we don't want to run the precompile phase - // unless the user specified '--precompile'. In the case the '--precompile' - // flag is enabled, we will try to emit the reduced BMI as a by product - // in GenerateModuleInterfaceAction. + // With 'fexperimental-modules-reduced-bmi', we don't want to run the + // precompile phase unless the user specified '--precompile'. In the case + // the '--precompile' flag is enabled, we will try to emit the reduced BMI + // as a by product in GenerateModuleInterfaceAction. if (Args.hasArg(options::OPT_modules_reduced_bmi) && !Args.getLastArg(options::OPT__precompile)) return Input; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index b0676924b38e08..b85378d7dbe9d6 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -4045,13 +4045,13 @@ static bool RenderModulesOptions(Compilation &C, const Driver &D, // module fragment. CmdArgs.push_back("-fskip-odr-check-in-gmf"); - // 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. + // Noop if we see '-modules-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. if (Args.hasArg(options::OPT_modules_reduced_bmi) && (Input.getType() == driver::types::TY_CXXModule || Input.getType() == driver::types::TY_PP_CXXModule)) { - CmdArgs.push_back("-fmodules-reduced-bmi"); + CmdArgs.push_back("-fexperimental-modules-reduced-bmi"); if (Args.hasArg(options::OPT_fmodule_output_EQ)) Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ); diff --git a/clang/test/Driver/module-fgen-reduced-bmi.cppm b/clang/test/Driver/module-fgen-reduced-bmi.cppm index a7a6c91f16156d..1223189fb49b72 100644 --- a/clang/test/Driver/module-fgen-reduced-bmi.cppm +++ b/clang/test/Driver/module-fgen-reduced-bmi.cppm @@ -9,25 +9,25 @@ // RUN: rm -rf %t && split-file %s %t && cd %t // // 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: -fexperimental-modules-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: -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: -fmodules-reduced-bmi -c -### 2>&1 | \ +// 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: -fmodules-reduced-bmi -c -o AnotherName.o -### 2>&1 | \ +// 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 -fmodules-reduced-bmi \ +// 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 -fmodules-reduced-bmi -Wall -Werror \ +// 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 @@ -35,7 +35,7 @@ export module Hello; // Test that we won't generate the emit-module-interface as 2 phase compilation model. // CHECK-NOT: -emit-module-interface -// CHECK: "-fmodules-reduced-bmi" +// CHECK: "-fexperimental-modules-reduced-bmi" // CHECK-UNSPECIFIED: -fmodule-output=Hello.pcm @@ -48,4 +48,4 @@ export module Hello; //--- Hello.cc -// CHECK-NOT: "-fmodules-reduced-bmi" +// CHECK-NOT: "-fexperimental-modules-reduced-bmi" diff --git a/clang/test/Modules/modules-reduced-bmi.cppm b/clang/test/Modules/modules-reduced-bmi.cppm index 84adcf14a335f8..9b84220ae03032 100644 --- a/clang/test/Modules/modules-reduced-bmi.cppm +++ b/clang/test/Modules/modules-reduced-bmi.cppm @@ -3,10 +3,10 @@ // 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 -fmodules-reduced-bmi -fmodule-output=%t/a.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 `-fmodules-reduced-bmi -fmodule-output=` is same with +// 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 // @@ -14,7 +14,7 @@ // 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 -fmodules-reduced-bmi -fmodule-output=%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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits