jhuber6 updated this revision to Diff 425214. jhuber6 added a comment. Small change, returning an empty action type should let us stop without an extra check.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D124220/new/ https://reviews.llvm.org/D124220 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/Driver.cpp clang/test/Driver/openmp-offload-gpu-new.c
Index: clang/test/Driver/openmp-offload-gpu-new.c =================================================================== --- clang/test/Driver/openmp-offload-gpu-new.c +++ clang/test/Driver/openmp-offload-gpu-new.c @@ -3,7 +3,6 @@ /// // REQUIRES: x86-registered-target -// REQUIRES: powerpc-registered-target // REQUIRES: nvptx-registered-target // REQUIRES: amdgpu-registered-target @@ -50,3 +49,18 @@ // RUN: | FileCheck -check-prefix=DRIVER_EMBEDDING %s // DRIVER_EMBEDDING: -fembed-offload-object=[[CUBIN:.*\.cubin]],openmp,nvptx64-nvidia-cuda,sm_70 + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -foffload-host-only -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-HOST-ONLY +// CHECK-HOST-ONLY: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.*]]"], output: "[[OUTPUT:.*]]" +// CHECK-HOST-ONLY: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[OUTPUT]]"], output: "a.out" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -foffload-device-only -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-ONLY +// CHECK-DEVICE-ONLY: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.*]]"], output: "[[HOST_BC:.*]]" +// CHECK-DEVICE-ONLY: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[DEVICE_ASM:.*]]" +// CHECK-DEVICE-ONLY: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[DEVICE_ASM]]"], output: "{{.*}}-openmp-nvptx64-nvidia-cuda.o" + +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda \ +// RUN: -foffload-device-only -E -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-DEVICE-ONLY-PP +// CHECK-DEVICE-ONLY-PP: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.*]]"], output: "-" Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -4052,11 +4052,6 @@ break; } - // Try to build the offloading actions and add the result as a dependency - // to the host. - if (UseNewOffloadingDriver) - Current = BuildOffloadingActions(C, Args, I, Current); - // FIXME: Should we include any prior module file outputs as inputs of // later actions in the same command line? @@ -4080,6 +4075,11 @@ if (OffloadBuilder.addHostDependenceToDeviceActions(Current, InputArg)) break; + // Try to build the offloading actions and add the result as a dependency + // to the host. + if (UseNewOffloadingDriver) + Current = BuildOffloadingActions(C, Args, I, Current); + if (Current->getType() == types::TY_Nothing) break; } @@ -4212,14 +4212,19 @@ llvm::opt::DerivedArgList &Args, const InputTy &Input, Action *HostAction) const { - if (!isa<CompileJobAction>(HostAction)) + if (Args.hasArg(options::OPT_foffload_host_only)) return HostAction; - OffloadAction::DeviceDependences DDeps; - types::ID InputType = Input.first; const Arg *InputArg = Input.second; + auto PL = types::getCompilationPhases(*this, Args, InputType); + + if (!isa<CompileJobAction>(HostAction) && PL.back() != phases::Preprocess) + return HostAction; + + OffloadAction::DeviceDependences DDeps; + const Action::OffloadKind OffloadKinds[] = {Action::OFK_OpenMP}; for (Action::OffloadKind Kind : OffloadKinds) { @@ -4239,8 +4244,6 @@ if (DeviceActions.empty()) return HostAction; - 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."); @@ -4251,7 +4254,8 @@ for (Action *&A : DeviceActions) { A = ConstructPhaseAction(C, Args, Phase, A, Kind); - if (isa<CompileJobAction>(A) && Kind == Action::OFK_OpenMP) { + if (isa<CompileJobAction>(A) && isa<CompileJobAction>(HostAction) && + Kind == Action::OFK_OpenMP) { HostAction->setCannotBeCollapsedWithNextDependentAction(); OffloadAction::HostDependence HDep( *HostAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(), @@ -4271,6 +4275,9 @@ } } + if (Args.hasArg(options::OPT_foffload_device_only)) + return C.MakeAction<OffloadAction>(DDeps, types::TY_Nothing); + OffloadAction::HostDependence HDep( *HostAction, *C.getSingleOffloadToolChain<Action::OFK_Host>(), /*BoundArch=*/nullptr, DDeps); Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -2532,6 +2532,10 @@ PosFlag<SetTrue, [CC1Option]>, NegFlag<SetFalse>, BothFlags<[NoArgumentUnused, HelpHidden]>>; def static_openmp: Flag<["-"], "static-openmp">, HelpText<"Use the static host OpenMP runtime while linking.">; +def foffload_device_only : Flag<["-"], "foffload-device-only">, + HelpText<"Only compile for the offloading device.">; +def foffload_host_only : Flag<["-"], "foffload-host-only">, + HelpText<"Only compile for the offloading host.">; 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>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits