xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/SPIRV.h (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1 //===--- SPIRV.h - 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 
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_SPIRV_H
11 
12 #include "clang/Driver/Tool.h"
13 #include "clang/Driver/ToolChain.h"
14 
15 namespace clang {
16 namespace driver {
17 namespace tools {
18 namespace SPIRV {
19 
20 void addTranslatorArgs(const llvm::opt::ArgList &InArgs,
21                        llvm::opt::ArgStringList &OutArgs);
22 
23 void constructTranslateCommand(Compilation &C, const Tool &T,
24                                const JobAction &JA, const InputInfo &Output,
25                                const InputInfo &Input,
26                                const llvm::opt::ArgStringList &Args);
27 
28 class LLVM_LIBRARY_VISIBILITY Translator : public Tool {
29 public:
30   Translator(const ToolChain &TC)
31       : Tool("SPIR-V::Translator", "llvm-spirv", TC) {}
32 
33   bool hasIntegratedCPP() const override { return false; }
34   bool hasIntegratedAssembler() const override { return true; }
35 
36   void ConstructJob(Compilation &C, const JobAction &JA,
37                     const InputInfo &Output, const InputInfoList &Inputs,
38                     const llvm::opt::ArgList &TCArgs,
39                     const char *LinkingOutput) const override;
40 };
41 
42 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
43 public:
44   Linker(const ToolChain &TC) : Tool("SPIRV::Linker", "spirv-link", TC) {}
45   bool hasIntegratedCPP() const override { return false; }
46   bool isLinkJob() const override { return true; }
47   void ConstructJob(Compilation &C, const JobAction &JA,
48                     const InputInfo &Output, const InputInfoList &Inputs,
49                     const llvm::opt::ArgList &TCArgs,
50                     const char *LinkingOutput) const override;
51 };
52 
53 } // namespace SPIRV
54 } // namespace tools
55 
56 namespace toolchains {
57 
58 class LLVM_LIBRARY_VISIBILITY SPIRVToolChain final : public ToolChain {
59   mutable std::unique_ptr<Tool> Translator;
60 
61 public:
62   SPIRVToolChain(const Driver &D, const llvm::Triple &Triple,
63                  const llvm::opt::ArgList &Args)
64       : ToolChain(D, Triple, Args) {}
65 
66   bool useIntegratedAs() const override { return true; }
67 
68   bool IsIntegratedBackendDefault() const override { return false; }
69   bool IsNonIntegratedBackendSupported() const override { return true; }
70   bool IsMathErrnoDefault() const override { return false; }
71   bool isCrossCompiling() const override { return true; }
72   bool isPICDefault() const override { return false; }
73   bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
74     return false;
75   }
76   bool isPICDefaultForced() const override { return false; }
77   bool SupportsProfiling() const override { return false; }
78 
79   clang::driver::Tool *SelectTool(const JobAction &JA) const override;
80 
81 protected:
82   clang::driver::Tool *getTool(Action::ActionClass AC) const override;
83   Tool *buildLinker() const override;
84 
85 private:
86   clang::driver::Tool *getTranslator() const;
87 };
88 
89 } // namespace toolchains
90 } // namespace driver
91 } // namespace clang
92 #endif
93