Skip to content

Commit b3fb5ad

Browse files
[Clang] Fix passing -offload-compress when compiling and linking device images separately (#15997)
When compiling and linking device images separately, compression related flags are not propagated correctly to `offload-wrapper`. This PR fixes that and updates the test accordingly.
1 parent 66867d4 commit b3fb5ad

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10353,33 +10353,48 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1035310353
assert(JA.getInputs().size() == Inputs.size() &&
1035410354
"Not have inputs for all dependence actions??");
1035510355

10356-
// For FPGA, we wrap the host objects before archiving them when using
10357-
// -fsycl-link. This allows for better extraction control from the
10358-
// archive when we need the host objects for subsequent compilations.
1035910356
if (OffloadingKind == Action::OFK_None &&
10360-
C.getArgs().hasArg(options::OPT_fintelfpga) &&
1036110357
C.getArgs().hasArg(options::OPT_fsycl_link_EQ)) {
1036210358

10363-
// Add offload targets and inputs.
10364-
CmdArgs.push_back(C.getArgs().MakeArgString(
10365-
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
10366-
CmdArgs.push_back(
10367-
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
10359+
// For FPGA, we wrap the host objects before archiving them when using
10360+
// -fsycl-link. This allows for better extraction control from the
10361+
// archive when we need the host objects for subsequent compilations.
10362+
if (C.getArgs().hasArg(options::OPT_fintelfpga)) {
1036810363

10369-
if (Inputs[0].getType() == types::TY_Tempfiletable ||
10370-
Inputs[0].getType() == types::TY_Tempfilelist)
10371-
// Input files are passed via the batch job file table.
10372-
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));
10364+
// Add offload targets and inputs.
10365+
CmdArgs.push_back(C.getArgs().MakeArgString(
10366+
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
10367+
CmdArgs.push_back(
10368+
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
1037310369

10374-
// Add input.
10375-
assert(Inputs[0].isFilename() && "Invalid input.");
10376-
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
10370+
if (Inputs[0].getType() == types::TY_Tempfiletable ||
10371+
Inputs[0].getType() == types::TY_Tempfilelist)
10372+
// Input files are passed via the batch job file table.
10373+
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));
1037710374

10378-
C.addCommand(std::make_unique<Command>(
10379-
JA, *this, ResponseFileSupport::None(),
10380-
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
10381-
CmdArgs, Inputs));
10382-
return;
10375+
// Add input.
10376+
assert(Inputs[0].isFilename() && "Invalid input.");
10377+
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
10378+
10379+
C.addCommand(std::make_unique<Command>(
10380+
JA, *this, ResponseFileSupport::None(),
10381+
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
10382+
CmdArgs, Inputs));
10383+
return;
10384+
} else {
10385+
// When compiling and linking separately, we need to propagate the
10386+
// compression related CLI options to offload-wrapper. Don't propagate
10387+
// these options when wrapping objects for FPGA.
10388+
if (C.getInputArgs().getLastArg(options::OPT_offload_compress)) {
10389+
CmdArgs.push_back(
10390+
C.getArgs().MakeArgString(Twine("-offload-compress")));
10391+
// -offload-compression-level=<>
10392+
if (Arg *A = C.getInputArgs().getLastArg(
10393+
options::OPT_offload_compression_level_EQ))
10394+
CmdArgs.push_back(C.getArgs().MakeArgString(
10395+
Twine("-offload-compression-level=") + A->getValue()));
10396+
}
10397+
}
1038310398
}
1038410399

1038510400
// Add offload targets and inputs.

sycl/test-e2e/Compression/compression_separate_compile.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
////////////////////// Link device images
1111
// RUN: %clangxx --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -v
1212

13+
// Make sure the clang-offload-wrapper is called with the --offload-compress
14+
// option.
15+
// RUN: %clangxx --offload-compress -fsycl -fsycl-link -fsycl-targets=spir64_x86_64 -fPIC %t_kernel1_aot.o %t_kernel2_aot.o -o %t_compressed_image.o -### &> %t_driver_opts.txt
16+
// RUN: FileCheck -input-file=%t_driver_opts.txt %s --check-prefix=CHECK-DRIVER-OPTS
17+
18+
// CHECK-DRIVER-OPTS: clang-offload-wrapper{{.*}} "-offload-compress"
19+
1320
////////////////////// Compile the host program
1421
// RUN: %clangxx -fsycl -std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -c %s -o %t_main.o
1522

0 commit comments

Comments
 (0)