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