diff --git a/clang/include/clang/Driver/Compilation.h b/clang/include/clang/Driver/Compilation.h --- a/clang/include/clang/Driver/Compilation.h +++ b/clang/include/clang/Driver/Compilation.h @@ -143,6 +143,8 @@ return ActiveOffloadMask & Kind; } + unsigned getActiveOffloadKinds() const { return ActiveOffloadMask; } + /// Iterator that visits device toolchains of a given kind. using const_offload_toolchains_iterator = const std::multimap bool hasOffloadToolChain() const { return OrderedOffloadingToolchains.find(Kind) != diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -3830,11 +3830,6 @@ // Builder to be used to build offloading actions. OffloadingActionBuilder OffloadBuilder(C, Args, Inputs); - // Offload kinds active for this compilation. - unsigned OffloadKinds = Action::OFK_None; - if (C.hasOffloadToolChain()) - OffloadKinds |= Action::OFK_OpenMP; - // Construct the actions to perform. HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr; ActionList LinkerInputs; @@ -3935,7 +3930,7 @@ if (!Args.hasArg(options::OPT_fopenmp_new_driver)) OffloadBuilder.appendTopLevelActions(Actions, Current, InputArg); else if (Current) - Current->propagateHostOffloadInfo(OffloadKinds, + Current->propagateHostOffloadInfo(C.getActiveOffloadKinds(), /*BoundArch=*/nullptr); } @@ -3956,9 +3951,9 @@ if (ShouldEmitStaticLibrary(Args)) { LA = C.MakeAction(LinkerInputs, types::TY_Image); } else if (Args.hasArg(options::OPT_fopenmp_new_driver) && - OffloadKinds != Action::OFK_None) { + C.getActiveOffloadKinds() != Action::OFK_None) { LA = C.MakeAction(LinkerInputs, types::TY_Image); - LA->propagateHostOffloadInfo(OffloadKinds, + LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(), /*BoundArch=*/nullptr); } else { LA = C.MakeAction(LinkerInputs, types::TY_Image); @@ -4057,53 +4052,60 @@ if (!isa(HostAction)) return HostAction; - SmallVector ToolChains; - ActionList DeviceActions; + OffloadAction::DeviceDependences DDeps; types::ID InputType = Input.first; const Arg *InputArg = Input.second; - auto OpenMPTCRange = C.getOffloadToolChains(); - for (auto TI = OpenMPTCRange.first, TE = OpenMPTCRange.second; TI != TE; ++TI) - ToolChains.push_back(TI->second); + const Action::OffloadKind OffloadKinds[] = {Action::OFK_OpenMP}; - for (unsigned I = 0; I < ToolChains.size(); ++I) - DeviceActions.push_back(C.MakeAction(*InputArg, InputType)); + for (Action::OffloadKind Kind : OffloadKinds) { + SmallVector ToolChains; + ActionList DeviceActions; - if (DeviceActions.empty()) - return HostAction; + auto TCRange = C.getOffloadToolChains(Kind); + for (auto TI = TCRange.first, TE = TCRange.second; TI != TE; ++TI) + ToolChains.push_back(TI->second); - auto PL = types::getCompilationPhases(*this, Args, InputType); + if (ToolChains.empty()) + continue; - for (phases::ID Phase : PL) { - if (Phase == phases::Link) { - assert(Phase == PL.back() && "linking must be final compilation step."); - break; - } + for (unsigned I = 0; I < ToolChains.size(); ++I) + DeviceActions.push_back(C.MakeAction(*InputArg, InputType)); - auto TC = ToolChains.begin(); - for (Action *&A : DeviceActions) { - A = ConstructPhaseAction(C, Args, Phase, A, Action::OFK_OpenMP); + if (DeviceActions.empty()) + return HostAction; - if (isa(A)) { - HostAction->setCannotBeCollapsedWithNextDependentAction(); - OffloadAction::HostDependence HDep( - *HostAction, *C.getSingleOffloadToolChain(), - /*BourdArch=*/nullptr, Action::OFK_OpenMP); - OffloadAction::DeviceDependences DDep; - DDep.add(*A, **TC, /*BoundArch=*/nullptr, Action::OFK_OpenMP); - A = C.MakeAction(HDep, DDep); + auto PL = types::getCompilationPhases(*this, Args, InputType); + + for (phases::ID Phase : PL) { + if (Phase == phases::Link) { + assert(Phase == PL.back() && "linking must be final compilation step."); + break; } - ++TC; - } - } - OffloadAction::DeviceDependences DDeps; + auto TC = ToolChains.begin(); + for (Action *&A : DeviceActions) { + A = ConstructPhaseAction(C, Args, Phase, A, Kind); + + if (isa(A) && Kind == Action::OFK_OpenMP) { + HostAction->setCannotBeCollapsedWithNextDependentAction(); + OffloadAction::HostDependence HDep( + *HostAction, *C.getSingleOffloadToolChain(), + /*BourdArch=*/nullptr, Action::OFK_OpenMP); + OffloadAction::DeviceDependences DDep; + DDep.add(*A, **TC, /*BoundArch=*/nullptr, Kind); + A = C.MakeAction(HDep, DDep); + } + ++TC; + } + } - auto TC = ToolChains.begin(); - for (Action *A : DeviceActions) { - DDeps.add(*A, **TC, /*BoundArch=*/nullptr, Action::OFK_OpenMP); - TC++; + auto TC = ToolChains.begin(); + for (Action *A : DeviceActions) { + DDeps.add(*A, **TC, /*BoundArch=*/nullptr, Kind); + TC++; + } } OffloadAction::HostDependence HDep(