dcastagna created this revision. Herald added subscribers: dang, yaxunl. dcastagna requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This CL adds a flag "cuda-device-triple" to clang driver that can be used to override the triple passed to the device compilation phase. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D117137 Files: clang/include/clang/Driver/Options.td clang/lib/Driver/Driver.cpp clang/test/Driver/cuda-device-triple.cu Index: clang/test/Driver/cuda-device-triple.cu =================================================================== --- /dev/null +++ clang/test/Driver/cuda-device-triple.cu @@ -0,0 +1,8 @@ +// REQUIRES: clang-driver + +// RUN: %clang -### -emit-llvm --cuda-device-only \ +// RUN: -nocudalib -nocudainc --cuda-device-triple=spirv32-unknown-unknown -c %s 2>&1 | FileCheck %s + +// CHECK: clang{{.*}}" "-cc1" "-triple" "spirv32-unknown-unknown" {{.*}} "-fcuda-is-device" {{.*}} + + Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -706,8 +706,13 @@ const llvm::Triple &HostTriple = HostTC->getTriple(); StringRef DeviceTripleStr; auto OFK = Action::OFK_Cuda; - DeviceTripleStr = - HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda"; + if (auto *CudaOverrideDeviceTriple = + C.getInputArgs().getLastArg(options::OPT_cuda_device_triple)) { + DeviceTripleStr = CudaOverrideDeviceTriple->getValue(); + } else { + DeviceTripleStr = + HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda"; + } llvm::Triple CudaTriple(DeviceTripleStr); // Use the CUDA and host triples as the key into the ToolChains map, // because the device toolchain we create depends on both. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -921,6 +921,8 @@ "specified more than once.">; def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[NoXarchOption]>, Alias<offload_arch_EQ>; +def cuda_device_triple: Joined<["--"], "cuda-device-triple=">, + HelpText<"Override the triple passed to CUDA device compilation phase">; def hip_link : Flag<["--"], "hip-link">, HelpText<"Link clang-offload-bundler bundles for HIP">; def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, Flags<[NoXarchOption]>,
Index: clang/test/Driver/cuda-device-triple.cu =================================================================== --- /dev/null +++ clang/test/Driver/cuda-device-triple.cu @@ -0,0 +1,8 @@ +// REQUIRES: clang-driver + +// RUN: %clang -### -emit-llvm --cuda-device-only \ +// RUN: -nocudalib -nocudainc --cuda-device-triple=spirv32-unknown-unknown -c %s 2>&1 | FileCheck %s + +// CHECK: clang{{.*}}" "-cc1" "-triple" "spirv32-unknown-unknown" {{.*}} "-fcuda-is-device" {{.*}} + + Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -706,8 +706,13 @@ const llvm::Triple &HostTriple = HostTC->getTriple(); StringRef DeviceTripleStr; auto OFK = Action::OFK_Cuda; - DeviceTripleStr = - HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda"; + if (auto *CudaOverrideDeviceTriple = + C.getInputArgs().getLastArg(options::OPT_cuda_device_triple)) { + DeviceTripleStr = CudaOverrideDeviceTriple->getValue(); + } else { + DeviceTripleStr = + HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda" : "nvptx-nvidia-cuda"; + } llvm::Triple CudaTriple(DeviceTripleStr); // Use the CUDA and host triples as the key into the ToolChains map, // because the device toolchain we create depends on both. Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -921,6 +921,8 @@ "specified more than once.">; def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[NoXarchOption]>, Alias<offload_arch_EQ>; +def cuda_device_triple: Joined<["--"], "cuda-device-triple=">, + HelpText<"Override the triple passed to CUDA device compilation phase">; def hip_link : Flag<["--"], "hip-link">, HelpText<"Link clang-offload-bundler bundles for HIP">; def no_offload_arch_EQ : Joined<["--"], "no-offload-arch=">, Flags<[NoXarchOption]>,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits