Skip to content

Commit 979bf95

Browse files
authored
[Driver][SYCL] Remove extra SPIR-V conversion when using -fsycl-device-obj=spirv (#5294)
The use of -fsycl-device-obj=spirv should only be relevant when creating objects. Clean up usage of llvm-spirv -r when processing objects, as this is already taken care of by the spirv-to-ir-wrapper call.
1 parent 8734a3d commit 979bf95

File tree

3 files changed

+9
-52
lines changed

3 files changed

+9
-52
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,6 @@ void SYCLInstallationDetector::print(llvm::raw_ostream &OS) const {
4747
}
4848
}
4949

50-
const char *SYCL::Linker::constructLLVMSpirvCommand(
51-
Compilation &C, const JobAction &JA, const InputInfo &Output,
52-
StringRef OutputFilePrefix, bool ToBc, const char *InputFileName) const {
53-
// Construct llvm-spirv command.
54-
// The output is a bc file or vice versa depending on the -r option usage
55-
// llvm-spirv -r -o a_kernel.bc a_kernel.spv
56-
// llvm-spirv -o a_kernel.spv a_kernel.bc
57-
ArgStringList CmdArgs;
58-
const char *OutputFileName = nullptr;
59-
if (ToBc) {
60-
std::string TmpName =
61-
C.getDriver().GetTemporaryPath(OutputFilePrefix.str() + "-spirv", "bc");
62-
OutputFileName = C.addTempFile(C.getArgs().MakeArgString(TmpName));
63-
CmdArgs.push_back("-r");
64-
CmdArgs.push_back("-o");
65-
CmdArgs.push_back(OutputFileName);
66-
} else {
67-
CmdArgs.push_back("-spirv-max-version=1.4");
68-
CmdArgs.push_back("-spirv-ext=+all");
69-
CmdArgs.push_back("-spirv-debug-info-version=ocl-100");
70-
CmdArgs.push_back("-spirv-allow-extra-diexpressions");
71-
CmdArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
72-
CmdArgs.push_back("-o");
73-
CmdArgs.push_back(Output.getFilename());
74-
}
75-
CmdArgs.push_back(InputFileName);
76-
77-
SmallString<128> LLVMSpirvPath(C.getDriver().Dir);
78-
llvm::sys::path::append(LLVMSpirvPath, "llvm-spirv");
79-
const char *LLVMSpirv = C.getArgs().MakeArgString(LLVMSpirvPath);
80-
C.addCommand(std::make_unique<Command>(
81-
JA, *this, ResponseFileSupport::AtFileUTF8(), LLVMSpirv, CmdArgs, None));
82-
return OutputFileName;
83-
}
84-
8550
static void addFPGATimingDiagnostic(std::unique_ptr<Command> &Cmd,
8651
Compilation &C) {
8752
const char *Msg = C.getArgs().MakeArgString(
@@ -343,22 +308,11 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
343308
return;
344309
}
345310

346-
// We want to use llvm-spirv linker to link spirv binaries before putting
347-
// them into the fat object.
348-
// Each command outputs different files.
349311
InputInfoList SpirvInputs;
350312
for (const auto &II : Inputs) {
351313
if (!II.isFilename())
352314
continue;
353-
if (!Args.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
354-
.equals_insensitive("spirv"))
355-
SpirvInputs.push_back(II);
356-
else {
357-
const char *LLVMSpirvOutputFile = constructLLVMSpirvCommand(
358-
C, JA, Output, Prefix, true, II.getFilename());
359-
SpirvInputs.push_back(InputInfo(types::TY_LLVM_BC, LLVMSpirvOutputFile,
360-
LLVMSpirvOutputFile));
361-
}
315+
SpirvInputs.push_back(II);
362316
}
363317

364318
constructLLVMLinkCommand(C, JA, Output, Args, SubArchName, Prefix,

clang/lib/Driver/ToolChains/SYCL.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
5454
const char *LinkingOutput) const override;
5555

5656
private:
57-
/// \return llvm-spirv output file name.
58-
const char *constructLLVMSpirvCommand(Compilation &C, const JobAction &JA,
59-
const InputInfo &Output,
60-
llvm::StringRef OutputFilePrefix,
61-
bool isBc, const char *InputFile) const;
6257
/// \return llvm-link output file name.
6358
const char *constructLLVMLinkCommand(Compilation &C, const JobAction &JA,
6459
const InputInfo &Output,

clang/test/Driver/sycl-spirv-obj.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@
3434
// SPIRV_DEVICE_OBJ_PHASES: 10: backend, {9}, assembler, (host-sycl)
3535
// SPIRV_DEVICE_OBJ_PHASES: 11: assembler, {10}, object, (host-sycl)
3636
// SPIRV_DEVICE_OBJ_PHASES: 12: clang-offload-bundler, {4, 11}, object, (host-sycl)
37+
38+
/// Use of -fsycl-device-obj=spirv should not be effective during linking
39+
// RUN: touch %t.o
40+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-obj=spirv -### %t.o 2>&1 | \
41+
// RUN: FileCheck %s -check-prefixes=OPT_WARNING,LLVM_SPIRV_R
42+
// OPT_WARNING: warning: argument unused during compilation: '-fsycl-device-obj=spirv'
43+
// LLVM_SPIRV_R: spirv-to-ir-wrapper{{.*}}
44+
// LLVM_SPIRV_R-NOT: llvm-spirv{{.*}} "-r"

0 commit comments

Comments
 (0)