[clang] [clang][Driver][HIP] Change OffloadingActionBuilder to respect the --no-gpu-bundle-output flag (PR #163834)
alessandra simmons via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 4 08:35:58 PST 2025
https://github.com/MixedMatched updated https://github.com/llvm/llvm-project/pull/163834
>From 0125a69ee8e9ec206c72f64d30b8c13324b7a107 Mon Sep 17 00:00:00 2001
From: alessandra simmons <30960626+MixedMatched at users.noreply.github.com>
Date: Thu, 2 Oct 2025 18:34:34 -0400
Subject: [PATCH 1/2] [clang][Driver][HIP] Change OffloadingActionBuilder to
respect the --no-gpu-bundle-output flag
---
clang/lib/Driver/Driver.cpp | 16 +++++++++++-----
clang/test/Driver/no-gpu-bundle-respected.hip | 18 ++++++++++++++++++
2 files changed, 29 insertions(+), 5 deletions(-)
create mode 100644 clang/test/Driver/no-gpu-bundle-respected.hip
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 40ea513e85427..02cfc4314bbc4 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3844,6 +3844,9 @@ class OffloadingActionBuilder final {
/// Flag set to true if all valid builders allow file bundling/unbundling.
bool CanUseBundler;
+ /// Flag set to false if an argument turns off bundling.
+ bool ShouldUseBundler;
+
public:
OffloadingActionBuilder(Compilation &C, DerivedArgList &Args,
const Driver::InputList &Inputs)
@@ -3878,6 +3881,9 @@ class OffloadingActionBuilder final {
}
CanUseBundler =
ValidBuilders && ValidBuilders == ValidBuildersSupportingBundling;
+
+ ShouldUseBundler = Args.hasFlag(options::OPT_gpu_bundle_output,
+ options::OPT_no_gpu_bundle_output, true);
}
~OffloadingActionBuilder() {
@@ -4029,11 +4035,11 @@ class OffloadingActionBuilder final {
SB->appendTopLevelActions(OffloadAL);
}
- // If we can use the bundler, replace the host action by the bundling one in
- // the resulting list. Otherwise, just append the device actions. For
- // device only compilation, HostAction is a null pointer, therefore only do
- // this when HostAction is not a null pointer.
- if (CanUseBundler && HostAction &&
+ // If we can and should use the bundler, replace the host action by the
+ // bundling one in the resulting list. Otherwise, just append the device
+ // actions. For device only compilation, HostAction is a null pointer,
+ // therefore only do this when HostAction is not a null pointer.
+ if (CanUseBundler && ShouldUseBundler && HostAction &&
HostAction->getType() != types::TY_Nothing && !OffloadAL.empty()) {
// Add the host action to the list in order to create the bundling action.
OffloadAL.push_back(HostAction);
diff --git a/clang/test/Driver/no-gpu-bundle-respected.hip b/clang/test/Driver/no-gpu-bundle-respected.hip
new file mode 100644
index 0000000000000..1587551f0322d
--- /dev/null
+++ b/clang/test/Driver/no-gpu-bundle-respected.hip
@@ -0,0 +1,18 @@
+// RUN: %clang -ccc-print-phases -c -emit-llvm \
+// RUN: --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
+// RUN: 2>&1 | FileCheck %s --check-prefix=OFFLOAD
+
+// RUN: %clang -ccc-print-phases -c -emit-llvm \
+// RUN: --gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
+// RUN: 2>&1 | FileCheck %s --check-prefix=OFFLOAD
+
+// RUN: %clang -ccc-print-phases -c -emit-llvm \
+// RUN: --no-gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
+// RUN: 2>&1 | FileCheck %s --check-prefix=OFFLOAD2
+
+// OFFLOAD: clang-offload-bundler
+// OFFLOAD2-NOT: clang-offload-bundler
+
+int square(int num) {
+ return num * num;
+}
>From 655f0164fe2940e4806a035b288e625007de7f7c Mon Sep 17 00:00:00 2001
From: alessandra simmons <alessandra at adrs.pub>
Date: Tue, 4 Nov 2025 10:34:21 -0500
Subject: [PATCH 2/2] Improve bundling lit test with better action names and
sanity checks
---
clang/test/Driver/no-gpu-bundle-respected.hip | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/clang/test/Driver/no-gpu-bundle-respected.hip b/clang/test/Driver/no-gpu-bundle-respected.hip
index 1587551f0322d..fc93640dc4b90 100644
--- a/clang/test/Driver/no-gpu-bundle-respected.hip
+++ b/clang/test/Driver/no-gpu-bundle-respected.hip
@@ -1,17 +1,23 @@
// RUN: %clang -ccc-print-phases -c -emit-llvm \
// RUN: --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=OFFLOAD
+// RUN: 2>&1 | FileCheck %s --check-prefix=BUNDLE
// RUN: %clang -ccc-print-phases -c -emit-llvm \
// RUN: --gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=OFFLOAD
+// RUN: 2>&1 | FileCheck %s --check-prefix=BUNDLE
// RUN: %clang -ccc-print-phases -c -emit-llvm \
// RUN: --no-gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
-// RUN: 2>&1 | FileCheck %s --check-prefix=OFFLOAD2
+// RUN: 2>&1 | FileCheck %s --check-prefixes=COMPILER,GFX1030,GFX900,OFFLOAD,NOBUNDLE
-// OFFLOAD: clang-offload-bundler
-// OFFLOAD2-NOT: clang-offload-bundler
+// BUNDLE: clang-offload-bundler
+// NOBUNDLE-NOT: clang-offload-bundler
+
+// COM: sanity checks
+// COMPILER: compiler
+// GFX1030: (device-hip, gfx1030)
+// GFX900: (device-hip, gfx900)
+// OFFLOAD: offload
int square(int num) {
return num * num;
More information about the cfe-commits
mailing list