Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -375,11 +375,15 @@ def c : Flag<["-"], "c">, Flags<[DriverOption]>, HelpText<"Only run preprocess, compile, and assemble steps">; def cuda_device_only : Flag<["--"], "cuda-device-only">, - HelpText<"Do device-side CUDA compilation only">; + HelpText<"Compile CUDA code for host only. Has no effect on non-CUDA " + "compilations.">; +def cuda_host_only : Flag<["--"], "cuda-host-only">, + HelpText<"Compile CUDA code for device only">; +def cuda_compile_host_device : Flag<["--"], "cuda-compile-host-device">, + HelpText<"Compile CUDA code for both host and device (default). Has no " + "effect on non-CUDA compilations.">; def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[DriverOption]>, HelpText<"CUDA GPU architecture (e.g. sm_35). May be specified more than once.">; -def cuda_host_only : Flag<["--"], "cuda-host-only">, - HelpText<"Do host-side CUDA compilation only">; def cuda_noopt_device_debug : Flag<["--"], "cuda-noopt-device-debug">, HelpText<"Enable device-side debug info generation. Disables ptxas optimizations.">; def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group, Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -1316,11 +1316,17 @@ static Action *buildCudaActions(Compilation &C, DerivedArgList &Args, const Arg *InputArg, Action *HostAction, ActionList &Actions) { - Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only, - options::OPT_cuda_device_only); - // Host-only compilation case. - if (PartialCompilationArg && - PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only)) + Arg *PartialCompilationArg = Args.getLastArg( + options::OPT_cuda_host_only, options::OPT_cuda_device_only, + options::OPT_cuda_compile_host_device); + bool CompileHostOnly = + PartialCompilationArg && + PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only); + bool CompileDeviceOnly = + PartialCompilationArg && + PartialCompilationArg->getOption().matches(options::OPT_cuda_device_only); + + if (CompileHostOnly) return C.MakeAction(HostAction, ActionList()); // Collect all cuda_gpu_arch parameters, removing duplicates. @@ -1364,15 +1370,14 @@ // Figure out what to do with device actions -- pass them as inputs to the // host action or run each of them independently. - bool DeviceOnlyCompilation = PartialCompilationArg != nullptr; - if (PartialCompilation || DeviceOnlyCompilation) { + if (PartialCompilation || CompileDeviceOnly) { // In case of partial or device-only compilation results of device actions // are not consumed by the host action device actions have to be added to // top-level actions list with AtTopLevel=true and run independently. // -o is ambiguous if we have more than one top-level action. if (Args.hasArg(options::OPT_o) && - (!DeviceOnlyCompilation || GpuArchList.size() > 1)) { + (!CompileDeviceOnly || GpuArchList.size() > 1)) { C.getDriver().Diag( clang::diag::err_drv_output_argument_with_multiple_files); return nullptr; @@ -1383,7 +1388,7 @@ GpuArchList[I], /* AtTopLevel */ true)); // Kill host action in case of device-only compilation. - if (DeviceOnlyCompilation) + if (CompileDeviceOnly) return nullptr; return HostAction; } @@ -1647,9 +1652,10 @@ // Claim ignored clang-cl options. Args.ClaimAllArgs(options::OPT_cl_ignored_Group); - // Claim --cuda-host-only arg which may be passed to non-CUDA - // compilations and should not trigger warnings there. + // Claim --cuda-host-only and --cuda-compile-host-device, which may be passed + // to non-CUDA compilations and should not trigger warnings there. Args.ClaimAllArgs(options::OPT_cuda_host_only); + Args.ClaimAllArgs(options::OPT_cuda_compile_host_device); } Action *Driver::ConstructPhaseAction(Compilation &C, const ArgList &Args, Index: test/Driver/cuda-options.cu =================================================================== --- test/Driver/cuda-options.cu +++ test/Driver/cuda-options.cu @@ -22,23 +22,46 @@ // RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \ // RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s -// Same test as above, but with preceeding --cuda-device-only to make sure only -// the last option has an effect. -// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only --cuda-host-only %s 2>&1 \ -// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \ -// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s - // Verify that --cuda-device-only disables host-side compilation and linking. // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \ // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \ // RUN: -check-prefix NOHOST -check-prefix NOLINK %s -// Same test as above, but with preceeding --cuda-host-only to make sure only -// the last option has an effect. -// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only --cuda-device-only %s 2>&1 \ +// Check that the last of --cuda-compile-host-device, --cuda-host-only, and +// --cuda-device-only wins. + +// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \ +// RUN: --cuda-host-only %s 2>&1 \ +// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \ +// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s + +// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device \ +// RUN: --cuda-host-only %s 2>&1 \ +// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \ +// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s + +// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only \ +// RUN: --cuda-device-only %s 2>&1 \ // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \ // RUN: -check-prefix NOHOST -check-prefix NOLINK %s +// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device \ +// RUN: --cuda-device-only %s 2>&1 \ +// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \ +// RUN: -check-prefix NOHOST -check-prefix NOLINK %s + +// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only \ +// RUN: --cuda-compile-host-device %s 2>&1 \ +// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \ +// RUN: -check-prefix HOST -check-prefix INCLUDES-DEVICE \ +// RUN: -check-prefix LINK %s + +// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \ +// RUN: --cuda-compile-host-device %s 2>&1 \ +// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \ +// RUN: -check-prefix HOST -check-prefix INCLUDES-DEVICE \ +// RUN: -check-prefix LINK %s + // Verify that --cuda-gpu-arch option passes the correct GPU archtecture to // device compilation. // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_35 -c %s 2>&1 \ Index: test/Driver/cuda-unused-arg-warning.cu =================================================================== --- test/Driver/cuda-unused-arg-warning.cu +++ test/Driver/cuda-unused-arg-warning.cu @@ -4,11 +4,16 @@ // REQUIRES: x86-registered-target // REQUIRES: nvptx-registered-target -// --cuda-host-only should never trigger unused arg warning. +// --cuda-host-only and --cuda-compile-host-device should never trigger an +// unused arg warning. // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -c %s 2>&1 | \ // RUN: FileCheck %s // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -x c -c %s 2>&1 | \ // RUN: FileCheck %s +// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device -c %s 2>&1 | \ +// RUN: FileCheck %s +// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device -x c -c %s 2>&1 | \ +// RUN: FileCheck %s // --cuda-device-only should warn during non-CUDA compilation. // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only -x c -c %s 2>&1 | \ @@ -19,5 +24,6 @@ // RUN: FileCheck -check-prefix NO-UNUSED-WARNING %s // CHECK-NOT: warning: argument unused during compilation: '--cuda-host-only' +// CHECK-NOT: warning: argument unused during compilation: '--cuda-compile-host-device' // UNUSED-WARNING: warning: argument unused during compilation: '--cuda-device-only' // NO-UNUSED-WARNING-NOT: warning: argument unused during compilation: '--cuda-device-only'