[clang] 4e2b5a6 - [Clang] Make enabling the new driver more generic
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 29 06:14:59 PDT 2022
Author: Joseph Huber
Date: 2022-04-29T09:14:39-04:00
New Revision: 4e2b5a6693e299fcb8671d4dbb69c993d181b29f
URL: https://github.com/llvm/llvm-project/commit/4e2b5a6693e299fcb8671d4dbb69c993d181b29f
DIFF: https://github.com/llvm/llvm-project/commit/4e2b5a6693e299fcb8671d4dbb69c993d181b29f.diff
LOG: [Clang] Make enabling the new driver more generic
In preparation for allowing other offloading kinds to use the new driver
a new opt-in flag `-foffload-new-driver` is added. This is distinct from
the existing `-fopenmp-new-driver` because OpenMP will soon use the new
driver by default while the others should not.
Reviewed By: yaxunl, tra
Differential Revision: https://reviews.llvm.org/D123325
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/Clang.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index d2097427ed71..6f70e28a211e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2534,10 +2534,14 @@ defm openmp_optimistic_collapse : BoolFOption<"openmp-optimistic-collapse",
PosFlag<SetTrue, [CC1Option]>, NegFlag<SetFalse>, BothFlags<[NoArgumentUnused, HelpHidden]>>;
def static_openmp: Flag<["-"], "static-openmp">,
HelpText<"Use the static host OpenMP runtime while linking.">;
+def offload_new_driver : Flag<["--"], "offload-new-driver">, Flags<[CC1Option]>, Group<Action_Group>,
+ HelpText<"Use the new driver for offloading compilation.">;
+def no_offload_new_driver : Flag<["--"], "no-offload-new-driver">, Flags<[CC1Option]>, Group<Action_Group>,
+ HelpText<"Don't Use the new driver for offloading compilation.">;
def fopenmp_new_driver : Flag<["-"], "fopenmp-new-driver">, Flags<[CC1Option]>, Group<Action_Group>,
HelpText<"Use the new driver for OpenMP offloading.">;
def fno_openmp_new_driver : Flag<["-"], "fno-openmp-new-driver">, Flags<[CC1Option]>, Group<Action_Group>,
- HelpText<"Don't use the new driver for OpenMP offloading.">;
+ Alias<no_offload_new_driver>, HelpText<"Don't use the new driver for OpenMP offloading.">;
def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Disable tail call optimization, keeping the call stack accurate">,
MarshallingInfoFlag<CodeGenOpts<"DisableTailCalls">>;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 487e2e1e0b3f..d0c5c3b6b49d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3976,17 +3976,19 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
// Builder to be used to build offloading actions.
OffloadingActionBuilder OffloadBuilder(C, Args, Inputs);
+ bool UseNewOffloadingDriver =
+ (C.isOffloadingHostKind(Action::OFK_OpenMP) &&
+ Args.hasFlag(options::OPT_fopenmp_new_driver,
+ options::OPT_no_offload_new_driver, true)) ||
+ Args.hasFlag(options::OPT_offload_new_driver,
+ options::OPT_no_offload_new_driver, false);
+
// Construct the actions to perform.
HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
ExtractAPIJobAction *ExtractAPIAction = nullptr;
ActionList LinkerInputs;
ActionList MergerInputs;
- bool UseNewOffloadingDriver =
- C.isOffloadingHostKind(Action::OFK_OpenMP) &&
- Args.hasFlag(options::OPT_fopenmp_new_driver,
- options::OPT_fno_openmp_new_driver, true);
-
for (auto &I : Inputs) {
types::ID InputType = I.first;
const Arg *InputArg = I.second;
@@ -4114,8 +4116,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
// Check if this Linker Job should emit a static library.
if (ShouldEmitStaticLibrary(Args)) {
LA = C.MakeAction<StaticLibJobAction>(LinkerInputs, types::TY_Image);
- } else if (UseNewOffloadingDriver &&
- C.getActiveOffloadKinds() != Action::OFK_None) {
+ } else if (UseNewOffloadingDriver) {
LA = C.MakeAction<LinkerWrapperJobAction>(LinkerInputs, types::TY_Image);
LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
/*BoundArch=*/nullptr);
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 3fc8dd0ecf24..450fc1abc4ce 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4389,8 +4389,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
bool IsDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
JA.isDeviceOffloading(Action::OFK_Host));
bool IsHostOffloadingAction =
- JA.isHostOffloading(Action::OFK_OpenMP) &&
- !Args.hasArg(options::OPT_fno_openmp_new_driver);
+ (JA.isHostOffloading(Action::OFK_OpenMP) &&
+ Args.hasFlag(options::OPT_fopenmp_new_driver,
+ options::OPT_no_offload_new_driver, true)) ||
+ Args.hasFlag(options::OPT_offload_new_driver,
+ options::OPT_no_offload_new_driver, false);
bool IsUsingLTO = D.isUsingLTO(IsDeviceOffloadAction);
auto LTOMode = D.getLTOMode(IsDeviceOffloadAction);
@@ -4686,7 +4689,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Only AMDGPU supports device-side LTO.
if (IsDeviceOffloadAction &&
!Args.hasFlag(options::OPT_fopenmp_new_driver,
- options::OPT_fno_openmp_new_driver, true) &&
+ options::OPT_no_offload_new_driver, true) &&
+ !Args.hasFlag(options::OPT_offload_new_driver,
+ options::OPT_no_offload_new_driver, false) &&
!Triple.isAMDGPU()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Args.getLastArg(options::OPT_foffload_lto,
More information about the cfe-commits
mailing list