Skip to content

[Driver][SYCL] Remove extra SPIR-V conversion when using -fsycl-devic… #5294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2022
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
48 changes: 1 addition & 47 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,41 +47,6 @@ void SYCLInstallationDetector::print(llvm::raw_ostream &OS) const {
}
}

const char *SYCL::Linker::constructLLVMSpirvCommand(
Compilation &C, const JobAction &JA, const InputInfo &Output,
StringRef OutputFilePrefix, bool ToBc, const char *InputFileName) const {
// Construct llvm-spirv command.
// The output is a bc file or vice versa depending on the -r option usage
// llvm-spirv -r -o a_kernel.bc a_kernel.spv
// llvm-spirv -o a_kernel.spv a_kernel.bc
ArgStringList CmdArgs;
const char *OutputFileName = nullptr;
if (ToBc) {
std::string TmpName =
C.getDriver().GetTemporaryPath(OutputFilePrefix.str() + "-spirv", "bc");
OutputFileName = C.addTempFile(C.getArgs().MakeArgString(TmpName));
CmdArgs.push_back("-r");
CmdArgs.push_back("-o");
CmdArgs.push_back(OutputFileName);
} else {
CmdArgs.push_back("-spirv-max-version=1.4");
CmdArgs.push_back("-spirv-ext=+all");
CmdArgs.push_back("-spirv-debug-info-version=ocl-100");
CmdArgs.push_back("-spirv-allow-extra-diexpressions");
CmdArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
CmdArgs.push_back("-o");
CmdArgs.push_back(Output.getFilename());
}
CmdArgs.push_back(InputFileName);

SmallString<128> LLVMSpirvPath(C.getDriver().Dir);
llvm::sys::path::append(LLVMSpirvPath, "llvm-spirv");
const char *LLVMSpirv = C.getArgs().MakeArgString(LLVMSpirvPath);
C.addCommand(std::make_unique<Command>(
JA, *this, ResponseFileSupport::AtFileUTF8(), LLVMSpirv, CmdArgs, None));
return OutputFileName;
}

static void addFPGATimingDiagnostic(std::unique_ptr<Command> &Cmd,
Compilation &C) {
const char *Msg = C.getArgs().MakeArgString(
Expand Down Expand Up @@ -343,22 +308,11 @@ void SYCL::Linker::ConstructJob(Compilation &C, const JobAction &JA,
return;
}

// We want to use llvm-spirv linker to link spirv binaries before putting
// them into the fat object.
// Each command outputs different files.
InputInfoList SpirvInputs;
for (const auto &II : Inputs) {
if (!II.isFilename())
continue;
if (!Args.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
.equals_insensitive("spirv"))
SpirvInputs.push_back(II);
else {
const char *LLVMSpirvOutputFile = constructLLVMSpirvCommand(
C, JA, Output, Prefix, true, II.getFilename());
SpirvInputs.push_back(InputInfo(types::TY_LLVM_BC, LLVMSpirvOutputFile,
LLVMSpirvOutputFile));
}
SpirvInputs.push_back(II);
}

constructLLVMLinkCommand(C, JA, Output, Args, SubArchName, Prefix,
Expand Down
5 changes: 0 additions & 5 deletions clang/lib/Driver/ToolChains/SYCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
const char *LinkingOutput) const override;

private:
/// \return llvm-spirv output file name.
const char *constructLLVMSpirvCommand(Compilation &C, const JobAction &JA,
const InputInfo &Output,
llvm::StringRef OutputFilePrefix,
bool isBc, const char *InputFile) const;
/// \return llvm-link output file name.
const char *constructLLVMLinkCommand(Compilation &C, const JobAction &JA,
const InputInfo &Output,
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Driver/sycl-spirv-obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,11 @@
// SPIRV_DEVICE_OBJ_PHASES: 10: backend, {9}, assembler, (host-sycl)
// SPIRV_DEVICE_OBJ_PHASES: 11: assembler, {10}, object, (host-sycl)
// SPIRV_DEVICE_OBJ_PHASES: 12: clang-offload-bundler, {4, 11}, object, (host-sycl)

/// Use of -fsycl-device-obj=spirv should not be effective during linking
// RUN: touch %t.o
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-obj=spirv -### %t.o 2>&1 | \
// RUN: FileCheck %s -check-prefixes=OPT_WARNING,LLVM_SPIRV_R
// OPT_WARNING: warning: argument unused during compilation: '-fsycl-device-obj=spirv'
// LLVM_SPIRV_R: spirv-to-ir-wrapper{{.*}}
// LLVM_SPIRV_R-NOT: llvm-spirv{{.*}} "-r"