Skip to content

Commit 8ae03ed

Browse files
authored
[Driver] Fix preview breaking changes option passing to offload-wrapper (#20708)
When passing options to the clang-offload-wrapper, the -fpreview-breaking-changes option needs to be passed accordingly to the tool when -fpreview-breaking-changes is used on the command line. This was happening for typical SYCL enabled compilations, but when using -fsycl-link, the usage of clang-offload-wrapper modifies the offloading kind encountered, causing the option to not be passed. Fixup the ability to pass -fpreview-breaking-changes for all needed uses as well as factoring in the offload-compress options which are in the same bucket of behaviors. This is done by creating a common function that adds the options via CLI enabling that is used for both `-fsycl-link` and non `-fsycl-link` usage paths.
1 parent 7e8159c commit 8ae03ed

File tree

3 files changed

+34
-31
lines changed

3 files changed

+34
-31
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10023,6 +10023,26 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1002310023
// object that is fed to the linker from the wrapper generated bc file
1002410024
assert(isa<OffloadWrapperJobAction>(JA) && "Expecting wrapping job!");
1002510025

10026+
// Validate and propogate CLI options related to device image compression
10027+
// and enabling preview breaking changes.
10028+
auto addCLIOptions = [&](ArgStringList &Args) -> void {
10029+
// -offload-compress
10030+
if (C.getInputArgs().hasFlag(options::OPT_offload_compress,
10031+
options::OPT_no_offload_compress, false)) {
10032+
Args.push_back(C.getArgs().MakeArgString(Twine("-offload-compress")));
10033+
// -offload-compression-level=<>
10034+
if (Arg *A = C.getInputArgs().getLastArg(
10035+
options::OPT_offload_compression_level_EQ))
10036+
Args.push_back(C.getArgs().MakeArgString(
10037+
Twine("-offload-compression-level=") + A->getValue()));
10038+
}
10039+
// Enable preview breaking changes in clang-offload-wrapper,
10040+
// in case it needs to introduce any ABI breaking changes.
10041+
// For example, changes in offload binary descriptor format.
10042+
if (C.getArgs().hasArg(options::OPT_fpreview_breaking_changes))
10043+
Args.push_back("-fpreview-breaking-changes");
10044+
};
10045+
1002610046
Action::OffloadKind OffloadingKind = JA.getOffloadingDeviceKind();
1002710047
if (OffloadingKind == Action::OFK_SYCL) {
1002810048
// The wrapper command looks like this:
@@ -10054,18 +10074,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1005410074
llvm::Triple TT = getToolChain().getTriple();
1005510075
SmallString<128> TargetTripleOpt = TT.getArchName();
1005610076

10057-
// Validate and propogate CLI options related to device image compression.
10058-
// -offload-compress
10059-
if (C.getInputArgs().getLastArg(options::OPT_offload_compress)) {
10060-
WrapperArgs.push_back(
10061-
C.getArgs().MakeArgString(Twine("-offload-compress")));
10062-
// -offload-compression-level=<>
10063-
if (Arg *A = C.getInputArgs().getLastArg(
10064-
options::OPT_offload_compression_level_EQ))
10065-
WrapperArgs.push_back(C.getArgs().MakeArgString(
10066-
Twine("-offload-compression-level=") + A->getValue()));
10067-
}
10068-
10077+
addCLIOptions(WrapperArgs);
1006910078
addRunTimeWrapperOpts(C, OffloadingKind, TCArgs, WrapperArgs,
1007010079
getToolChain(), JA);
1007110080

@@ -10095,12 +10104,6 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1009510104
WrapperArgs.push_back(
1009610105
C.getArgs().MakeArgString(Twine("-kind=") + Twine(Kind)));
1009710106

10098-
// Enable preview breaking changes in clang-offload-wrapper,
10099-
// in case it needs to introduce any ABI breaking changes.
10100-
// For example, changes in offload binary descriptor format.
10101-
if (C.getArgs().hasArg(options::OPT_fpreview_breaking_changes))
10102-
WrapperArgs.push_back("-fpreview-breaking-changes");
10103-
1010410107
assert((Inputs.size() > 0) && "no inputs for clang-offload-wrapper");
1010510108
assert(((Inputs[0].getType() != types::TY_Tempfiletable) ||
1010610109
(Inputs.size() == 1)) &&
@@ -10168,19 +10171,8 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1016810171
"Not have inputs for all dependence actions??");
1016910172

1017010173
if (OffloadingKind == Action::OFK_None &&
10171-
C.getArgs().hasArg(options::OPT_fsycl_link_EQ)) {
10172-
10173-
// When compiling and linking separately, we need to propagate the
10174-
// compression related CLI options to offload-wrapper.
10175-
if (C.getInputArgs().getLastArg(options::OPT_offload_compress)) {
10176-
CmdArgs.push_back(C.getArgs().MakeArgString(Twine("-offload-compress")));
10177-
// -offload-compression-level=<>
10178-
if (Arg *A = C.getInputArgs().getLastArg(
10179-
options::OPT_offload_compression_level_EQ))
10180-
CmdArgs.push_back(C.getArgs().MakeArgString(
10181-
Twine("-offload-compression-level=") + A->getValue()));
10182-
}
10183-
}
10174+
C.getArgs().hasArg(options::OPT_fsycl_link_EQ))
10175+
addCLIOptions(CmdArgs);
1018410176

1018510177
// Add offload targets and inputs.
1018610178
for (unsigned I = 0; I < Inputs.size(); ++I) {

clang/test/Driver/sycl-offload-old-model.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,16 @@
898898
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}.lib
899899
// FSYCL-PREVIEW-BREAKING-CHANGES-DEBUG-CHECK-NOT: -defaultlib:sycl{{[0-9]*}}-preview.lib
900900

901+
/// Check for -fpreview-breaking-changes output during the clang-offload-wrapper
902+
/// step of the offload compilation.
903+
// RUN: %clang -### -fsycl --no-offload-new-driver -fpreview-breaking-changes \
904+
// RUN: %s 2>&1 \
905+
// RUN: | FileCheck -check-prefix PREVIEW-WRAPPER %s
906+
// RUN: %clang -### -fsycl --no-offload-new-driver -fpreview-breaking-changes \
907+
// RUN: -fsycl-link %s 2>&1 \
908+
// RUN: | FileCheck -check-prefix PREVIEW-WRAPPER %s
909+
// PREVIEW-WRAPPER: clang-offload-wrapper{{.*}} "-fpreview-breaking-changes"
910+
901911
// Check if fsycl-targets correctly processes multiple NVidia
902912
// and AMD GPU targets.
903913
// RUN: %clang -### -fsycl -fsycl-targets=nvidia_gpu_sm_60,nvidia_gpu_sm_70 -fno-sycl-libspirv -nocudalib --no-offload-new-driver %s 2>&1 \

clang/test/Driver/sycl-offload-wrapper-compression.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
///
55

66
// RUN: %clangxx -### -fsycl --offload-compress --offload-compression-level=3 %s 2>&1 | FileCheck %s --check-prefix=CHECK-COMPRESS
7+
// RUN: %clangxx -### -fsycl -fsycl-link --offload-compress --offload-compression-level=3 %s 2>&1 | FileCheck %s --check-prefix=CHECK-COMPRESS
78
// CHECK-COMPRESS: {{.*}}clang-offload-wrapper{{.*}}"-offload-compress"{{.*}}"-offload-compression-level=3"{{.*}}
89

910
// Make sure that the compression options are not passed when --offload-compress is not set.

0 commit comments

Comments
 (0)