clang  15.0.0git
SPIRV.cpp
Go to the documentation of this file.
1 //===--- SPIRV.cpp - SPIR-V Tool Implementations ----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #include "SPIRV.h"
9 #include "CommonArgs.h"
11 #include "clang/Driver/Driver.h"
12 #include "clang/Driver/InputInfo.h"
13 #include "clang/Driver/Options.h"
14 
15 using namespace clang::driver;
16 using namespace clang::driver::toolchains;
17 using namespace clang::driver::tools;
18 using namespace llvm::opt;
19 
21  const JobAction &JA,
22  const InputInfo &Output,
23  const InputInfo &Input,
24  const llvm::opt::ArgStringList &Args) {
25  llvm::opt::ArgStringList CmdArgs(Args);
26  CmdArgs.push_back(Input.getFilename());
27 
28  if (Input.getType() == types::TY_PP_Asm)
29  CmdArgs.push_back("-to-binary");
30  if (Output.getType() == types::TY_PP_Asm)
31  CmdArgs.push_back("--spirv-tools-dis");
32 
33  CmdArgs.append({"-o", Output.getFilename()});
34 
35  const char *Exec =
36  C.getArgs().MakeArgString(T.getToolChain().GetProgramPath("llvm-spirv"));
37  C.addCommand(std::make_unique<Command>(JA, T, ResponseFileSupport::None(),
38  Exec, CmdArgs, Input, Output));
39 }
40 
41 void SPIRV::Translator::ConstructJob(Compilation &C, const JobAction &JA,
42  const InputInfo &Output,
43  const InputInfoList &Inputs,
44  const ArgList &Args,
45  const char *LinkingOutput) const {
46  claimNoWarnArgs(Args);
47  if (Inputs.size() != 1)
48  llvm_unreachable("Invalid number of input files.");
49  constructTranslateCommand(C, *this, JA, Output, Inputs[0], {});
50 }
51 
52 clang::driver::Tool *SPIRVToolChain::getTranslator() const {
53  if (!Translator)
54  Translator = std::make_unique<SPIRV::Translator>(*this);
55  return Translator.get();
56 }
57 
59  Action::ActionClass AC = JA.getKind();
60  return SPIRVToolChain::getTool(AC);
61 }
62 
64  switch (AC) {
65  default:
66  break;
69  return SPIRVToolChain::getTranslator();
70  }
71  return ToolChain::getTool(AC);
72 }
74  return new tools::SPIRV::Linker(*this);
75 }
76 
77 void SPIRV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
78  const InputInfo &Output,
79  const InputInfoList &Inputs,
80  const ArgList &Args,
81  const char *LinkingOutput) const {
82  const ToolChain &ToolChain = getToolChain();
83  std::string Linker = ToolChain.GetProgramPath(getShortName());
84  ArgStringList CmdArgs;
85  AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
86 
87  CmdArgs.push_back("-o");
88  CmdArgs.push_back(Output.getFilename());
89 
90  C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
91  Args.MakeArgString(Linker), CmdArgs,
92  Inputs, Output));
93 }
clang::driver::toolchains
Definition: AIX.h:55
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::Action::ActionClass
ActionClass
Definition: Action.h:55
clang::driver::Action::getKind
ActionClass getKind() const
Definition: Action.h:148
clang::driver::ToolChain::GetProgramPath
std::string GetProgramPath(const char *Name) const
Definition: ToolChain.cpp:581
clang::driver::tools
Definition: AIX.h:17
clang::driver::toolchains::SPIRVToolChain::buildLinker
Tool * buildLinker() const override
Definition: SPIRV.cpp:73
clang::driver::Action::AssembleJobClass
@ AssembleJobClass
Definition: Action.h:67
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::tools::SPIRV::constructTranslateCommand
void constructTranslateCommand(Compilation &C, const Tool &T, const JobAction &JA, const InputInfo &Output, const InputInfo &Input, const llvm::opt::ArgStringList &Args)
Definition: SPIRV.cpp:20
InputInfo.h
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::toolchains::SPIRVToolChain::SelectTool
clang::driver::Tool * SelectTool(const JobAction &JA) const override
Choose a tool to use to handle the action JA.
Definition: SPIRV.cpp:58
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::tools::claimNoWarnArgs
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
Options.h
llvm::opt
Definition: DiagnosticOptions.h:19
SPIRV.h
clang::driver::ToolChain::getTool
virtual Tool * getTool(Action::ActionClass AC) const
Definition: ToolChain.cpp:344
clang::driver::Action::BackendJobClass
@ BackendJobClass
Definition: Action.h:66
Compilation.h
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver::Tool::getToolChain
const ToolChain & getToolChain() const
Definition: Tool.h:52
clang::driver::toolchains::SPIRVToolChain::getTool
clang::driver::Tool * getTool(Action::ActionClass AC) const override
Definition: SPIRV.cpp:63
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
CommonArgs.h
clang::driver::InputInfo::getType
types::ID getType() const
Definition: InputInfo.h:77
clang::driver::tools::SPIRV::Translator
Definition: SPIRV.h:28
clang::driver::tools::SPIRV::Linker
Definition: SPIRV.h:42
clang::driver
Definition: Action.h:31
clang::driver::ResponseFileSupport::None
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.
Definition: Job.h:78
clang::driver::JobAction
Definition: Action.h:395