https://github.com/YuriPlyakhin updated https://github.com/llvm/llvm-project/pull/216090
>From 4e9d6070d37570a42a5c9817ba668e4ad6af84ad Mon Sep 17 00:00:00 2001 From: "Plyakhin, Yury" <[email protected]> Date: Mon, 10 Aug 2026 17:09:10 +0200 Subject: [PATCH] [clang][NFC] Generalize -fcuda-include-gpubinary to -foffload-include-binary -fcuda-include-gpubinary names a finalized device binary to incorporate into the host object file at compile time, rather than deferring device code to a device link step. Despite the name it is already shared by CUDA and HIP, and the mechanism is not CUDA-specific: any offloading model that finalizes device code per translation unit (i.e. non-relocatable device code) needs it. Rename the cc1 option to -foffload-include-binary and the corresponding CodeGenOptions field from CudaGpuBinaryFileName to OffloadBinaryToEmbedFile. The offloading model in effect (-fcuda-is-device, -fsycl-is-host, ...) already determines how the binary is incorporated, so a single option suffices; the driver rejects mixing offloading kinds on one command line (err_drv_mix_offload), and the option is single-valued because a single finalized binary covers all requested device targets. -fcuda-include-gpubinary is kept as an alias so existing invocations continue to work. Co-Authored-By: Claude <[email protected]> --- clang/include/clang/Basic/CodeGenOptions.h | 7 ++++--- clang/include/clang/Options/Options.td | 7 +++++-- clang/lib/CIR/CodeGen/CIRGenModule.cpp | 2 +- clang/lib/CodeGen/CGCUDANV.cpp | 3 ++- clang/lib/Driver/ToolChains/Clang.cpp | 4 ++-- clang/lib/Interpreter/DeviceOffload.cpp | 2 +- clang/test/Driver/cuda-external-tools.cu | 2 +- clang/test/Driver/cuda-openmp-driver.cu | 4 ++-- clang/test/Driver/cuda-options.cu | 8 ++++---- clang/test/Driver/hip-save-temps.hip | 2 +- clang/test/Driver/hip-toolchain-no-rdc.hip | 8 ++++---- clang/test/Driver/hip-unbundle-preproc.hipi | 2 +- clang/test/Driver/hipspv-toolchain.hip | 2 +- 13 files changed, 29 insertions(+), 24 deletions(-) diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h index c12434135a198..2aabc9301da30 100644 --- a/clang/include/clang/Basic/CodeGenOptions.h +++ b/clang/include/clang/Basic/CodeGenOptions.h @@ -391,9 +391,10 @@ class CodeGenOptions : public CodeGenOptionsBase { /// Prefix to use for -save-temps output. std::string SaveTempsFilePrefix; - /// Name of file passed with -fcuda-include-gpubinary option to forward to - /// CUDA runtime back-end for incorporating them into host-side object file. - std::string CudaGpuBinaryFileName; + /// Name of file passed with -foffload-include-binary option to forward to + /// offloading runtime back-end for incorporating them into host-side object + /// file. + std::string OffloadBinaryToEmbedFile; /// List of filenames passed in using the -fembed-offload-object option. These /// are offloading binaries containing device images and metadata. diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index b354a475346df..18170fa4eac44 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -1819,6 +1819,10 @@ def fembed_offload_object_EQ : Joined<["-"], "fembed-offload-object=">, Visibility<[ClangOption, CC1Option, FC1Option]>, HelpText<"Embed Offloading device-side binary into host object file as a section.">, MarshallingInfoStringVector<CodeGenOpts<"OffloadObjects">>; +def foffload_include_binary : Separate<["-"], "foffload-include-binary">, + Visibility<[CC1Option]>, + HelpText<"Incorporate offloading device-side binary into host object file.">, + MarshallingInfoString<CodeGenOpts<"OffloadBinaryToEmbedFile">>; def fembed_bitcode_EQ : Joined<["-"], "fembed-bitcode=">, Group<f_Group>, Flags<[NoXarchOption]>, Visibility<[ClangOption, CC1Option, CC1AsOption]>, MetaVarName<"<option>">, @@ -9118,8 +9122,7 @@ def fcuda_is_device : Flag<["-"], "fcuda-is-device">, HelpText<"Generate code for CUDA device">, MarshallingInfoFlag<LangOpts<"CUDAIsDevice">>; def fcuda_include_gpubinary : Separate<["-"], "fcuda-include-gpubinary">, - HelpText<"Incorporate CUDA device-side binary into host object file.">, - MarshallingInfoString<CodeGenOpts<"CudaGpuBinaryFileName">>; + Alias<foffload_include_binary>; def fcuda_allow_variadic_functions : Flag<["-"], "fcuda-allow-variadic-functions">, HelpText<"Deprecated; Allow variadic functions in CUDA device code.">; def fno_cuda_host_device_constexpr : Flag<["-"], "fno-cuda-host-device-constexpr">, diff --git a/clang/lib/CIR/CodeGen/CIRGenModule.cpp b/clang/lib/CIR/CodeGen/CIRGenModule.cpp index 9ddd65e80f800..c68fc494d3e27 100644 --- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp @@ -176,7 +176,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &mlirContext, // Set CUDA GPU binary handle. if (langOpts.CUDA) { - llvm::StringRef cudaBinaryName = codeGenOpts.CudaGpuBinaryFileName; + llvm::StringRef cudaBinaryName = codeGenOpts.OffloadBinaryToEmbedFile; if (!cudaBinaryName.empty()) { theModule->setAttr(cir::CIRDialect::getCUDABinaryHandleAttrName(), cir::CUDABinaryHandleAttr::get( diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp index 1e688d29d15a5..9c67f33ae46b9 100644 --- a/clang/lib/CodeGen/CGCUDANV.cpp +++ b/clang/lib/CodeGen/CGCUDANV.cpp @@ -831,7 +831,8 @@ llvm::Function *CGNVCUDARuntime::makeModuleCtorFunction() { bool IsHIP = CGM.getLangOpts().HIP; bool IsCUDA = CGM.getLangOpts().CUDA; // No need to generate ctors/dtors if there is no GPU binary. - StringRef CudaGpuBinaryFileName = CGM.getCodeGenOpts().CudaGpuBinaryFileName; + StringRef CudaGpuBinaryFileName = + CGM.getCodeGenOpts().OffloadBinaryToEmbedFile; if (CudaGpuBinaryFileName.empty() && !IsHIP) return nullptr; if ((IsHIP || (IsCUDA && !RelocatableDeviceCode)) && EmittedKernels.empty() && diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 79127fa5e2db1..357a1c9a80a57 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8294,13 +8294,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // them in the host compilation depending on the target. If the host inputs // are not empty we use the new-driver scheme, otherwise use the old scheme. if ((IsCuda || IsHIP) && CudaDeviceInput) { - CmdArgs.push_back("-fcuda-include-gpubinary"); + CmdArgs.push_back("-foffload-include-binary"); CmdArgs.push_back(CudaDeviceInput->getFilename()); } else if (!HostOffloadingInputs.empty()) { if ((IsCuda || IsHIP) && (!IsRDCMode || Args.hasArg(options::OPT_cuda_emit_nvcc_abi))) { assert(HostOffloadingInputs.size() == 1 && "Only one input expected"); - CmdArgs.push_back("-fcuda-include-gpubinary"); + CmdArgs.push_back("-foffload-include-binary"); CmdArgs.push_back(HostOffloadingInputs.front().getFilename()); } else { for (const InputInfo Input : HostOffloadingInputs) diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp index 7c3404e02e328..38cecd142a8e6 100644 --- a/clang/lib/Interpreter/DeviceOffload.cpp +++ b/clang/lib/Interpreter/DeviceOffload.cpp @@ -152,7 +152,7 @@ llvm::Error IncrementalCUDADeviceParser::GenerateFatbinary() { llvm::StringRef(FatbinContent.data(), FatbinContent.size()), "", false)); - CodeGenOpts.CudaGpuBinaryFileName = std::move(FatbinFileName); + CodeGenOpts.OffloadBinaryToEmbedFile = std::move(FatbinFileName); FatbinContent.clear(); diff --git a/clang/test/Driver/cuda-external-tools.cu b/clang/test/Driver/cuda-external-tools.cu index 4f380ec5a3a08..059d0d4af378f 100644 --- a/clang/test/Driver/cuda-external-tools.cu +++ b/clang/test/Driver/cuda-external-tools.cu @@ -173,6 +173,6 @@ // CHECK: "-cc1" // ARCH64-SAME: "-triple" "x86_64- // ARCH32-SAME: "-triple" "i386- -// CHECK-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]" +// CHECK-SAME: "-foffload-include-binary" "[[FATBINARY]]" // CHK-PTXAS-VERBOSE: ptxas{{.*}}" "-v" diff --git a/clang/test/Driver/cuda-openmp-driver.cu b/clang/test/Driver/cuda-openmp-driver.cu index 47e83ec426181..546a489220068 100644 --- a/clang/test/Driver/cuda-openmp-driver.cu +++ b/clang/test/Driver/cuda-openmp-driver.cu @@ -37,7 +37,7 @@ // RUN: | FileCheck -check-prefix GPU-BINARY %s // GPU-BINARY: fatbinary{{.*}}"--create" "{{.*}}.fatbin" -// GPU-BINARY: -cc1{{.*}}-fcuda-include-gpubinary" "{{.*}}.fatbin" +// GPU-BINARY: -cc1{{.*}}-foffload-include-binary" "{{.*}}.fatbin" // RUN: %clang -### -target x86_64-linux-gnu -nocudalib -fgpu-rdc --cuda-emit-nvcc-abi \ // RUN: --offload-arch=sm_35 --offload-arch=sm_70 --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda %s 2>&1 \ @@ -46,4 +46,4 @@ // RUN: --implicit-check-not=fembed-offload-object %s // NVCC-ABI: fatbinary{{.*}}"--create" "{{.*}}.fatbin" -// NVCC-ABI: -cc1{{.*}}"-fcuda-include-gpubinary" "{{.*}}.fatbin"{{.*}}"--cuda-emit-nvcc-abi" +// NVCC-ABI: -cc1{{.*}}"-foffload-include-binary" "{{.*}}.fatbin"{{.*}}"--cuda-emit-nvcc-abi" diff --git a/clang/test/Driver/cuda-options.cu b/clang/test/Driver/cuda-options.cu index fc8e83a2bb279..253246de31ff0 100644 --- a/clang/test/Driver/cuda-options.cu +++ b/clang/test/Driver/cuda-options.cu @@ -260,10 +260,10 @@ // THINLTOWPD-SAME: "-flto=thin" // HOST-NOT: "-fcuda-is-device" // There is only one GPU binary after combining it with fatbinary! -// INCLUDES-DEVICE2-NOT: "-fcuda-include-gpubinary" -// INCLUDES-DEVICE-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]" +// INCLUDES-DEVICE2-NOT: "-foffload-include-binary" +// INCLUDES-DEVICE-SAME: "-foffload-include-binary" "[[FATBINARY]]" // There is only one GPU binary after combining it with fatbinary. -// INCLUDES-DEVICE2-NOT: "-fcuda-include-gpubinary" +// INCLUDES-DEVICE2-NOT: "-foffload-include-binary" // THINLTOWPD-SAME: "-fwhole-program-vtables" // HOST-SAME: "-o" "[[HOSTOUTPUT:[^"]*]]" // HOST-NOSAVE-SAME: "-x" "cuda" @@ -273,7 +273,7 @@ // HOST-AS: "-o" "{{.*}}.o" "[[HOSTOUTPUT]]" // Match no GPU code inclusion. -// NOINCLUDES-DEVICE-NOT: "-fcuda-include-gpubinary" +// NOINCLUDES-DEVICE-NOT: "-foffload-include-binary" // Match no host compilation. // NOHOST-NOT: "-cc1" "-triple" diff --git a/clang/test/Driver/hip-save-temps.hip b/clang/test/Driver/hip-save-temps.hip index 6ad0ef6dc4e77..a9af44062c0fd 100644 --- a/clang/test/Driver/hip-save-temps.hip +++ b/clang/test/Driver/hip-save-temps.hip @@ -56,7 +56,7 @@ // -fno-gpu-rdc host object path // NORDC: "{{.*clang.*}}" "-cc1" {{.*}} "-E" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.hipi" -// NORDC: "{{.*clang.*}}" "-cc1" {{.*}} "-emit-llvm-bc" {{.*}} "-fcuda-include-gpubinary" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.bc" +// NORDC: "{{.*clang.*}}" "-cc1" {{.*}} "-emit-llvm-bc" {{.*}} "-foffload-include-binary" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.bc" // NORDC: "{{.*clang.*}}" "-cc1" {{.*}} "-S" {{.*}} "-o" "hip-save-temps-host-x86_64-unknown-linux-gnu.s" // NORDC: "{{.*clang.*}}" "-cc1as" {{.*}} "-o" "hip-save-temps{{.*}}.o" diff --git a/clang/test/Driver/hip-toolchain-no-rdc.hip b/clang/test/Driver/hip-toolchain-no-rdc.hip index dde2dc867f011..f0e582b669558 100644 --- a/clang/test/Driver/hip-toolchain-no-rdc.hip +++ b/clang/test/Driver/hip-toolchain-no-rdc.hip @@ -116,8 +116,8 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "a.cu" -// OLD-SAME: {{.*}} "-fcuda-include-gpubinary" "[[BUNDLE_A]]" -// NEW-SAME: {{.*}} "-fcuda-include-gpubinary" "[[HIPFB_A]]" +// OLD-SAME: {{.*}} "-foffload-include-binary" "[[BUNDLE_A]]" +// NEW-SAME: {{.*}} "-foffload-include-binary" "[[HIPFB_A]]" // CHECK-SAME: {{.*}} "-o" [[A_OBJ_HOST:".*o"]] "-x" "hip" // CHECK-SAME: {{.*}} [[A_SRC]] @@ -189,8 +189,8 @@ // CHECK-SAME: "-aux-triple" "amdgcn-amd-amdhsa" // CHECK-SAME: "-emit-obj" // CHECK-SAME: {{.*}} "-main-file-name" "b.hip" -// OLD-SAME: {{.*}} "-fcuda-include-gpubinary" "[[BUNDLE_B]]" -// NEW-SAME: {{.*}} "-fcuda-include-gpubinary" "[[HIPFB_B]]" +// OLD-SAME: {{.*}} "-foffload-include-binary" "[[BUNDLE_B]]" +// NEW-SAME: {{.*}} "-foffload-include-binary" "[[HIPFB_B]]" // CHECK-SAME: {{.*}} "-o" [[B_OBJ_HOST:".*o"]] "-x" "hip" // CHECK-SAME: {{.*}} [[B_SRC]] diff --git a/clang/test/Driver/hip-unbundle-preproc.hipi b/clang/test/Driver/hip-unbundle-preproc.hipi index 2cbc0db59062a..839280972a611 100644 --- a/clang/test/Driver/hip-unbundle-preproc.hipi +++ b/clang/test/Driver/hip-unbundle-preproc.hipi @@ -10,7 +10,7 @@ // CHECK: {{".*clang.*"}} "-cc1" {{.*}}"-target-cpu" "gfx803" {{.*}}"-o" "[[DEV_O:[^"]*]]" {{.*}}"[[DEV_PP]]" // CHECK: {{".*lld.*"}} {{.*}}"-o" "[[DEV_ISA:.*]]" "[[DEV_O]]" // CHECK: {{".*clang-offload-bundler.*"}} {{.*}}"-input={{.*}}" "-input=[[DEV_ISA]]" "-output=[[FATBIN:.*]]" -// CHECK: {{".*clang.*"}} {{.*}}"-triple" "x86_64-unknown-linux-gnu"{{.*}} "-fcuda-include-gpubinary" "[[FATBIN]]" {{.*}}"-o" "[[HOST_O:.*o]]" {{.*}}"[[HOST_PP]]" +// CHECK: {{".*clang.*"}} {{.*}}"-triple" "x86_64-unknown-linux-gnu"{{.*}} "-foffload-include-binary" "[[FATBIN]]" {{.*}}"-o" "[[HOST_O:.*o]]" {{.*}}"[[HOST_PP]]" // CHECK: {{".*ld.*"}} {{.*}}"[[HOST_O]]" // RUN: %clang -### --target=x86_64-unknown-linux-gnu \ diff --git a/clang/test/Driver/hipspv-toolchain.hip b/clang/test/Driver/hipspv-toolchain.hip index 3a262a2ce6002..2a888fd9ecdd0 100644 --- a/clang/test/Driver/hipspv-toolchain.hip +++ b/clang/test/Driver/hipspv-toolchain.hip @@ -43,7 +43,7 @@ // CHECK: [[CLANG]] "-cc1" "-triple" {{".*"}} "-aux-triple" "[[TRIPLE]]" // CHECK-SAME: "-emit-obj" -// CHECK-SAME: "-fcuda-include-gpubinary" "[[BUNDLE]]" +// CHECK-SAME: "-foffload-include-binary" "[[BUNDLE]]" // CHECK-SAME: "-o" [[OBJ_HOST:".*o"]] "-x" "hip" // OLD: {{".*ld.*"}} {{.*}}[[OBJ_HOST]] _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
