[clang] 81ac5c7 - [clang][NFC] Generalize -fcuda-include-gpubinary to -foffload-include-binary (#216090)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 14 07:30:59 PDT 2026
Author: Yury Plyakhin
Date: 2026-08-14T07:30:54-07:00
New Revision: 81ac5c7c26efb70ffaffb91b26053437093ee085
URL: https://github.com/llvm/llvm-project/commit/81ac5c7c26efb70ffaffb91b26053437093ee085
DIFF: https://github.com/llvm/llvm-project/commit/81ac5c7c26efb70ffaffb91b26053437093ee085.diff
LOG: [clang][NFC] Generalize -fcuda-include-gpubinary to -foffload-include-binary (#216090)
`-fcuda-include-gpubinary` names a finalized device binary to
incorporate into the host object file at compile time. 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 already determines how the binary is
incorporated, so a single option suffices.
`-fcuda-include-gpubinary` is kept as an alias so existing invocations
continue to work.
Co-authored-by: Claude
Added:
Modified:
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Options/Options.td
clang/lib/CIR/CodeGen/CIRGenModule.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Interpreter/DeviceOffload.cpp
clang/test/Driver/cuda-external-tools.cu
clang/test/Driver/cuda-openmp-driver.cu
clang/test/Driver/cuda-options.cu
clang/test/Driver/hip-save-temps.hip
clang/test/Driver/hip-toolchain-no-rdc.hip
clang/test/Driver/hip-unbundle-preproc.hipi
clang/test/Driver/hipspv-toolchain.hip
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 6e9bde32e0655..4eec3522b1255 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -397,9 +397,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 6af0f578b6d63..3abb04a5f36c7 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>">,
@@ -9126,8 +9130,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 50ee0cfe48d26..e4650b775bc3c 100644
--- a/clang/lib/CIR/CodeGen/CIRGenModule.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenModule.cpp
@@ -180,7 +180,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 88a8a9df73581..2c6965ce894d9 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -843,7 +843,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 19d37b2ed7017..91ad5be238f5d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -8319,14 +8319,14 @@ 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) && !UsesLLVMOffloading && 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)) &&
!UsesLLVMOffloading) {
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]]
More information about the cfe-commits
mailing list