| 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 constructTranslateCommand(Compilation &C, const Tool &T, |
| 21 | const JobAction &JA, const InputInfo &Output, |
| 22 | const InputInfo &Input, |
| 23 | const llvm::opt::ArgStringList &Args); |
| 24 | |
| 25 | void constructAssembleCommand(Compilation &C, const Tool &T, |
| 26 | const JobAction &JA, const InputInfo &Output, |
| 27 | const InputInfo &Input, |
| 28 | const llvm::opt::ArgStringList &Args); |
| 29 | |
| 30 | void constructLLVMLinkCommand(Compilation &C, const Tool &T, |
| 31 | const JobAction &JA, const InputInfo &Output, |
| 32 | const InputInfoList &Inputs, |
| 33 | const llvm::opt::ArgList &Args); |
| 34 | |
| 35 | class LLVM_LIBRARY_VISIBILITY Translator : public Tool { |
| 36 | public: |
| 37 | Translator(const ToolChain &TC) |
| 38 | : Tool("SPIR-V::Translator" , "llvm-spirv" , TC) {} |
| 39 | |
| 40 | bool hasIntegratedCPP() const override { return false; } |
| 41 | bool hasIntegratedAssembler() const override { return true; } |
| 42 | |
| 43 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 44 | const InputInfo &Output, const InputInfoList &Inputs, |
| 45 | const llvm::opt::ArgList &TCArgs, |
| 46 | const char *LinkingOutput) const override; |
| 47 | }; |
| 48 | |
| 49 | class LLVM_LIBRARY_VISIBILITY Linker final : public Tool { |
| 50 | public: |
| 51 | Linker(const ToolChain &TC) : Tool("SPIR-V::Linker" , "spirv-link" , TC) {} |
| 52 | bool hasIntegratedCPP() const override { return false; } |
| 53 | bool isLinkJob() const override { return true; } |
| 54 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 55 | const InputInfo &Output, const InputInfoList &Inputs, |
| 56 | const llvm::opt::ArgList &TCArgs, |
| 57 | const char *LinkingOutput) const override; |
| 58 | }; |
| 59 | |
| 60 | class LLVM_LIBRARY_VISIBILITY Assembler final : public Tool { |
| 61 | public: |
| 62 | Assembler(const ToolChain &TC) : Tool("SPIR-V::Assembler" , "spirv-as" , TC) {} |
| 63 | bool hasIntegratedAssembler() const override { return false; } |
| 64 | bool hasIntegratedCPP() const override { return false; } |
| 65 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 66 | const InputInfo &Output, const InputInfoList &Inputs, |
| 67 | const llvm::opt::ArgList &TCArgs, |
| 68 | const char *AssembleOutput) const override; |
| 69 | }; |
| 70 | |
| 71 | } // namespace SPIRV |
| 72 | } // namespace tools |
| 73 | |
| 74 | namespace toolchains { |
| 75 | |
| 76 | class LLVM_LIBRARY_VISIBILITY SPIRVToolChain : public ToolChain { |
| 77 | mutable std::unique_ptr<Tool> Assembler; |
| 78 | |
| 79 | public: |
| 80 | SPIRVToolChain(const Driver &D, const llvm::Triple &Triple, |
| 81 | const llvm::opt::ArgList &Args); |
| 82 | |
| 83 | bool useIntegratedAs() const override { return true; } |
| 84 | |
| 85 | bool IsIntegratedBackendDefault() const override { return true; } |
| 86 | bool IsNonIntegratedBackendSupported() const override { return true; } |
| 87 | bool IsMathErrnoDefault() const override { return false; } |
| 88 | bool isCrossCompiling() const override { return true; } |
| 89 | bool isPICDefault() const override { return false; } |
| 90 | bool isPIEDefault(const llvm::opt::ArgList &Args) const override { |
| 91 | return false; |
| 92 | } |
| 93 | bool isPICDefaultForced() const override { return false; } |
| 94 | bool SupportsProfiling() const override { return false; } |
| 95 | bool HasNativeLLVMSupport() const override; |
| 96 | |
| 97 | clang::driver::Tool *SelectTool(const JobAction &JA) const override; |
| 98 | |
| 99 | protected: |
| 100 | clang::driver::Tool *getTool(Action::ActionClass AC) const override; |
| 101 | Tool *buildLinker() const override; |
| 102 | |
| 103 | private: |
| 104 | clang::driver::Tool *getAssembler() const; |
| 105 | |
| 106 | bool NativeLLVMSupport; |
| 107 | }; |
| 108 | |
| 109 | } // namespace toolchains |
| 110 | } // namespace driver |
| 111 | } // namespace clang |
| 112 | #endif |
| 113 | |