Skip to content

Commit f91de92

Browse files
committed
[Clang] Fix passing --offload-compress when compiling and linking device images separately.
1 parent 4d00087 commit f91de92

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10350,33 +10350,45 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
1035010350
assert(JA.getInputs().size() == Inputs.size() &&
1035110351
"Not have inputs for all dependence actions??");
1035210352

10353-
// For FPGA, we wrap the host objects before archiving them when using
10354-
// -fsycl-link. This allows for better extraction control from the
10355-
// archive when we need the host objects for subsequent compilations.
1035610353
if (OffloadingKind == Action::OFK_None &&
10357-
C.getArgs().hasArg(options::OPT_fintelfpga) &&
1035810354
C.getArgs().hasArg(options::OPT_fsycl_link_EQ)) {
1035910355

10360-
// Add offload targets and inputs.
10361-
CmdArgs.push_back(C.getArgs().MakeArgString(
10362-
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
10363-
CmdArgs.push_back(
10364-
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
10356+
// When compiling and linking separately, we need to propagate the
10357+
// compression related CLI options to offload-wrapper.
10358+
if (C.getInputArgs().getLastArg(options::OPT_offload_compress)) {
10359+
CmdArgs.push_back(C.getArgs().MakeArgString(Twine("-offload-compress")));
10360+
// -offload-compression-level=<>
10361+
if (Arg *A = C.getInputArgs().getLastArg(
10362+
options::OPT_offload_compression_level_EQ))
10363+
CmdArgs.push_back(C.getArgs().MakeArgString(
10364+
Twine("-offload-compression-level=") + A->getValue()));
10365+
}
1036510366

10366-
if (Inputs[0].getType() == types::TY_Tempfiletable ||
10367-
Inputs[0].getType() == types::TY_Tempfilelist)
10368-
// Input files are passed via the batch job file table.
10369-
CmdArgs.push_back(C.getArgs().MakeArgString("-batch"));
10367+
// For FPGA, we wrap the host objects before archiving them when using
10368+
// -fsycl-link. This allows for better extraction control from the
10369+
// archive when we need the host objects for subsequent compilations.
10370+
if (C.getArgs().hasArg(options::OPT_fintelfpga)) {
10371+
// Add offload targets and inputs.
10372+
CmdArgs.push_back(C.getArgs().MakeArgString(
10373+
Twine("-kind=") + Action::GetOffloadKindName(OffloadingKind)));
10374+
CmdArgs.push_back(
10375+
TCArgs.MakeArgString(Twine("-target=") + Triple.getTriple()));
1037010376

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

10375-
C.addCommand(std::make_unique<Command>(
10376-
JA, *this, ResponseFileSupport::None(),
10377-
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
10378-
CmdArgs, Inputs));
10379-
return;
10382+
// Add input.
10383+
assert(Inputs[0].isFilename() && "Invalid input.");
10384+
CmdArgs.push_back(TCArgs.MakeArgString(Inputs[0].getFilename()));
10385+
10386+
C.addCommand(std::make_unique<Command>(
10387+
JA, *this, ResponseFileSupport::None(),
10388+
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),
10389+
CmdArgs, Inputs));
10390+
return;
10391+
}
1038010392
}
1038110393

1038210394
// Add offload targets and inputs.

sycl/test-e2e/Compression/compression_separate_compile.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88
// RUN: %clangxx -fsycl -fsycl-targets=spir64_x86_64 -fsycl-host-compiler=clang++ -fsycl-host-compiler-options='-std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -DENABLE_KERNEL2' -DENABLE_KERNEL2 -c %s -o %t_kernel2_aot.o
99

1010
////////////////////// Link device images
11-
// 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
11+
// 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
12+
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"
1219

1320
////////////////////// Compile the host program
1421
// RUN: %clangxx -fsycl -std=c++17 -Wno-attributes -Wno-deprecated-declarations -fPIC -c %s -o %t_main.o

0 commit comments

Comments
 (0)