forked from OSchip/llvm-project
[SPIR-V] Add translator tool
Add a tool for constructing commands for translating LLVM IR to SPIR-V. Used by HIPSPV tool chain (D110618). Reviewed By: bader Differential Revision: https://reviews.llvm.org/D112404
This commit is contained in:
parent
74115602e8
commit
49682f14bf
|
@ -69,6 +69,7 @@ add_clang_library(clangDriver
|
||||||
ToolChains/PS4CPU.cpp
|
ToolChains/PS4CPU.cpp
|
||||||
ToolChains/RISCVToolchain.cpp
|
ToolChains/RISCVToolchain.cpp
|
||||||
ToolChains/Solaris.cpp
|
ToolChains/Solaris.cpp
|
||||||
|
ToolChains/SPIRV.cpp
|
||||||
ToolChains/TCE.cpp
|
ToolChains/TCE.cpp
|
||||||
ToolChains/VEToolchain.cpp
|
ToolChains/VEToolchain.cpp
|
||||||
ToolChains/WebAssembly.cpp
|
ToolChains/WebAssembly.cpp
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
//===--- SPIRV.cpp - SPIR-V Tool Implementations ----------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
#include "SPIRV.h"
|
||||||
|
#include "CommonArgs.h"
|
||||||
|
#include "clang/Driver/Compilation.h"
|
||||||
|
#include "clang/Driver/Driver.h"
|
||||||
|
#include "clang/Driver/InputInfo.h"
|
||||||
|
#include "clang/Driver/Options.h"
|
||||||
|
|
||||||
|
using namespace clang::driver::tools;
|
||||||
|
using namespace llvm::opt;
|
||||||
|
|
||||||
|
void SPIRV::constructTranslateCommand(Compilation &C, const Tool &T,
|
||||||
|
const JobAction &JA,
|
||||||
|
const InputInfo &Output,
|
||||||
|
const InputInfo &Input,
|
||||||
|
const llvm::opt::ArgStringList &Args) {
|
||||||
|
llvm::opt::ArgStringList CmdArgs(Args);
|
||||||
|
CmdArgs.push_back(Input.getFilename());
|
||||||
|
|
||||||
|
if (Input.getType() == types::TY_PP_Asm)
|
||||||
|
CmdArgs.push_back("-to-binary");
|
||||||
|
if (Output.getType() == types::TY_PP_Asm)
|
||||||
|
CmdArgs.push_back("-spirv-text");
|
||||||
|
|
||||||
|
CmdArgs.append({"-o", Output.getFilename()});
|
||||||
|
|
||||||
|
const char *Exec =
|
||||||
|
C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
|
||||||
|
C.addCommand(std::make_unique<Command>(JA, T, ResponseFileSupport::None(),
|
||||||
|
Exec, CmdArgs, Input, Output));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SPIRV::Translator::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
|
const InputInfo &Output,
|
||||||
|
const InputInfoList &Inputs,
|
||||||
|
const ArgList &Args,
|
||||||
|
const char *LinkingOutput) const {
|
||||||
|
claimNoWarnArgs(Args);
|
||||||
|
if (Inputs.size() != 1)
|
||||||
|
llvm_unreachable("Invalid number of input files.");
|
||||||
|
constructTranslateCommand(C, *this, JA, Output, Inputs[0], {});
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
//===--- SPIRV.h - SPIR-V Tool Implementations ------------------*- C++ -*-===//
|
||||||
|
//
|
||||||
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||||
|
// See https://llvm.org/LICENSE.txt for license information.
|
||||||
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
|
||||||
|
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
|
||||||
|
|
||||||
|
#include "clang/Driver/Tool.h"
|
||||||
|
#include "clang/Driver/ToolChain.h"
|
||||||
|
|
||||||
|
namespace clang {
|
||||||
|
namespace driver {
|
||||||
|
namespace tools {
|
||||||
|
namespace SPIRV {
|
||||||
|
|
||||||
|
void addTranslatorArgs(const llvm::opt::ArgList &InArgs,
|
||||||
|
llvm::opt::ArgStringList &OutArgs);
|
||||||
|
|
||||||
|
void constructTranslateCommand(Compilation &C, const Tool &T,
|
||||||
|
const JobAction &JA, const InputInfo &Output,
|
||||||
|
const InputInfo &Input,
|
||||||
|
const llvm::opt::ArgStringList &Args);
|
||||||
|
|
||||||
|
class LLVM_LIBRARY_VISIBILITY Translator : public Tool {
|
||||||
|
public:
|
||||||
|
Translator(const ToolChain &TC)
|
||||||
|
: Tool("SPIR-V::Translator", "llvm-spirv", TC) {}
|
||||||
|
|
||||||
|
bool hasIntegratedCPP() const override { return false; }
|
||||||
|
bool hasIntegratedAssembler() const override { return true; }
|
||||||
|
|
||||||
|
void ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
|
const InputInfo &Output, const InputInfoList &Inputs,
|
||||||
|
const llvm::opt::ArgList &TCArgs,
|
||||||
|
const char *LinkingOutput) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace SPIRV
|
||||||
|
} // namespace tools
|
||||||
|
} // namespace driver
|
||||||
|
} // namespace clang
|
||||||
|
#endif
|
Loading…
Reference in New Issue