Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3853,6 +3853,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)
Expand Down Expand Up @@ -3887,6 +3890,9 @@ class OffloadingActionBuilder final {
}
CanUseBundler =
ValidBuilders && ValidBuilders == ValidBuildersSupportingBundling;

ShouldUseBundler = Args.hasFlag(options::OPT_gpu_bundle_output,
options::OPT_no_gpu_bundle_output, true);
}

~OffloadingActionBuilder() {
Expand Down Expand Up @@ -4038,11 +4044,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);
Expand Down
24 changes: 24 additions & 0 deletions clang/test/Driver/no-gpu-bundle-respected.hip
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %clang -ccc-print-phases -c -emit-llvm \
// RUN: --offload-arch=gfx900,gfx1030 -O3 -x hip %s \
// 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=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-prefixes=COMPILER,GFX1030,GFX900,OFFLOAD,NOBUNDLE

// 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;
}
Loading