Skip to content

Commit 3922171

Browse files
authored
[clang][Driver][HIP] Change OffloadingActionBuilder to respect the --no-gpu-bundle-output flag (#163834)
Currently, the command `clang -c -emit-llvm --no-gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip square.hip` will lead to a bundled output: ``` ❯ ../bin/clang -c -emit-llvm --no-gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip square.hip ❯ ls square.hip square.bc ``` This doesn't match my expectation of the behavior of `--no-gpu-bundle-output`, so this adds a check into OffloadingActionBuilder for the flag when replacing the host compile action for a bundling action.
1 parent 4ce5883 commit 3922171

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3857,6 +3857,9 @@ class OffloadingActionBuilder final {
38573857
/// Flag set to true if all valid builders allow file bundling/unbundling.
38583858
bool CanUseBundler;
38593859

3860+
/// Flag set to false if an argument turns off bundling.
3861+
bool ShouldUseBundler;
3862+
38603863
public:
38613864
OffloadingActionBuilder(Compilation &C, DerivedArgList &Args,
38623865
const Driver::InputList &Inputs)
@@ -3891,6 +3894,9 @@ class OffloadingActionBuilder final {
38913894
}
38923895
CanUseBundler =
38933896
ValidBuilders && ValidBuilders == ValidBuildersSupportingBundling;
3897+
3898+
ShouldUseBundler = Args.hasFlag(options::OPT_gpu_bundle_output,
3899+
options::OPT_no_gpu_bundle_output, true);
38943900
}
38953901

38963902
~OffloadingActionBuilder() {
@@ -4042,11 +4048,11 @@ class OffloadingActionBuilder final {
40424048
SB->appendTopLevelActions(OffloadAL);
40434049
}
40444050

4045-
// If we can use the bundler, replace the host action by the bundling one in
4046-
// the resulting list. Otherwise, just append the device actions. For
4047-
// device only compilation, HostAction is a null pointer, therefore only do
4048-
// this when HostAction is not a null pointer.
4049-
if (CanUseBundler && HostAction &&
4051+
// If we can and should use the bundler, replace the host action by the
4052+
// bundling one in the resulting list. Otherwise, just append the device
4053+
// actions. For device only compilation, HostAction is a null pointer,
4054+
// therefore only do this when HostAction is not a null pointer.
4055+
if (CanUseBundler && ShouldUseBundler && HostAction &&
40504056
HostAction->getType() != types::TY_Nothing && !OffloadAL.empty()) {
40514057
// Add the host action to the list in order to create the bundling action.
40524058
OffloadAL.push_back(HostAction);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %clang -ccc-print-phases -c -emit-llvm \
2+
// RUN: --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
3+
// RUN: 2>&1 | FileCheck %s --check-prefix=BUNDLE
4+
5+
// RUN: %clang -ccc-print-phases -c -emit-llvm \
6+
// RUN: --gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
7+
// RUN: 2>&1 | FileCheck %s --check-prefix=BUNDLE
8+
9+
// RUN: %clang -ccc-print-phases -c -emit-llvm \
10+
// RUN: --no-gpu-bundle-output --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
11+
// RUN: 2>&1 | FileCheck %s --check-prefixes=COMPILER,GFX1030,GFX900,OFFLOAD,NOBUNDLE
12+
13+
// BUNDLE: clang-offload-bundler
14+
// NOBUNDLE-NOT: clang-offload-bundler
15+
16+
// COM: sanity checks
17+
// COMPILER: compiler
18+
// GFX1030: (device-hip, gfx1030)
19+
// GFX900: (device-hip, gfx900)
20+
// OFFLOAD: offload
21+
22+
int square(int num) {
23+
return num * num;
24+
}

0 commit comments

Comments
 (0)