[PATCH] D133229: [driver] Prune module-map related flags, if they are not going to be needed
Argyrios Kyrtzidis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 2 12:56:30 PDT 2022
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.
This is follow-up from https://reviews.llvm.org/D132801, but taking into account the conditions
where the module-map flags are still used even when `-fmodules` is disabled.
This useful for removing unnecessary input dependencies from the cc1 invocation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133229
Files:
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/modules.m
Index: clang/test/Driver/modules.m
===================================================================
--- clang/test/Driver/modules.m
+++ clang/test/Driver/modules.m
@@ -75,8 +75,13 @@
// RUN: %clang -fno-modules -fbuild-session-timestamp=123 -### %s 2>&1 | FileCheck -check-prefix=SESSION_FLAG %s
// SESSION_FLAG-NOT: -fbuild-session-timestamp
-// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_ONCE_FLAG %s
-// VALIDATE_ONCE_FLAG-NOT: -fmodules-validate-once-per-build-session
-
-// RUN: %clang -fno-modules -fmodules-validate-system-headers -### %s 2>&1 | FileCheck -check-prefix=VALIDATE_SYSTEM_FLAG %s
-// VALIDATE_SYSTEM_FLAG-NOT: -fmodules-validate-system-headers
+// RUN: %clang -fno-modules -fmodules-validate-once-per-build-session -fmodules-validate-system-headers -fmodule-map-file=module.modulemap \
+// RUN: -### %s 2>&1 | FileCheck -check-prefix=IGNORED_FLAGS %s
+// IGNORED_FLAGS-NOT: -fmodules-validate-once-per-build-session
+// IGNORED_FLAGS-NOT: -fmodules-validate-system-headers
+// IGNORED_FLAGS-NOT: -fmodule-map-file
+
+// RUN: %clang -fno-modules -fmodules-decluse -fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck -check-prefix=MMAPFILE %s
+// RUN: %clang -fno-modules -fmodules-strict-decluse -fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck -check-prefix=MMAPFILE %s
+// RUN: %clang -fno-modules -Xclang -fmodules-local-submodule-visibility -fmodule-map-file=module.modulemap -### %s 2>&1 | FileCheck -check-prefix=MMAPFILE %s
+// MMAPFILE: -fmodule-map-file
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3735,23 +3735,47 @@
CmdArgs.push_back("-fvalidate-ast-input-files-content");
}
- // -fmodule-name specifies the module that is currently being built (or
- // used for header checking by -fmodule-maps).
- Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
-
- // -fmodule-map-file can be used to specify files containing module
- // definitions.
- Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
-
- // -fbuiltin-module-map can be used to load the clang
- // builtin headers modulemap file.
- if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
- SmallString<128> BuiltinModuleMap(D.ResourceDir);
- llvm::sys::path::append(BuiltinModuleMap, "include");
- llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
- if (llvm::sys::fs::exists(BuiltinModuleMap))
- CmdArgs.push_back(
- Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+ // Check whether any "-fmodule-map-file=" flags are relevant or not. This is
+ // useful for pruning the cc1 arguments and removing unnecessary input
+ // dependencies.
+ bool ModuleMapsAreRelevant = [&]() -> bool {
+ if (HaveModules)
+ return true;
+ if (Args.hasFlag(options::OPT_fmodules_decluse,
+ options::OPT_fno_modules_decluse, false) ||
+ Args.hasFlag(options::OPT_fmodules_strict_decluse,
+ options::OPT_fno_modules_strict_decluse, false))
+ return true;
+ for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+ if (StringRef(Arg->getValue()) == "-fmodules-local-submodule-visibility")
+ return true;
+ }
+ return false;
+ }();
+
+ if (ModuleMapsAreRelevant) {
+ // -fmodule-name specifies the module that is currently being built (or
+ // used for header checking by -fmodule-maps).
+ Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
+
+ // -fmodule-map-file can be used to specify files containing module
+ // definitions.
+ Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
+
+ // -fbuiltin-module-map can be used to load the clang
+ // builtin headers modulemap file.
+ if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
+ SmallString<128> BuiltinModuleMap(D.ResourceDir);
+ llvm::sys::path::append(BuiltinModuleMap, "include");
+ llvm::sys::path::append(BuiltinModuleMap, "module.modulemap");
+ if (llvm::sys::fs::exists(BuiltinModuleMap))
+ CmdArgs.push_back(
+ Args.MakeArgString("-fmodule-map-file=" + BuiltinModuleMap));
+ }
+ } else {
+ Args.ClaimAllArgs(options::OPT_fmodule_name_EQ);
+ Args.ClaimAllArgs(options::OPT_fmodule_map_file);
+ Args.ClaimAllArgs(options::OPT_fbuiltin_module_map);
}
// The -fmodule-file=<name>=<file> form specifies the mapping of module
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133229.457682.patch
Type: text/x-patch
Size: 4577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220902/353140bf/attachment-0001.bin>
More information about the cfe-commits
mailing list