| 1 | //===--- HLSL.h - HLSL ToolChain 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_HLSL_H |
| 10 | #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HLSL_H |
| 11 | |
| 12 | #include "clang/Driver/Tool.h" |
| 13 | #include "clang/Driver/ToolChain.h" |
| 14 | |
| 15 | namespace clang { |
| 16 | namespace driver { |
| 17 | |
| 18 | namespace tools { |
| 19 | |
| 20 | namespace hlsl { |
| 21 | class LLVM_LIBRARY_VISIBILITY Validator : public Tool { |
| 22 | public: |
| 23 | Validator(const ToolChain &TC) |
| 24 | : Tool("hlsl::Validator" , TC.getTriple().isSPIRV() ? "spirv-val" : "dxv" , |
| 25 | TC) {} |
| 26 | |
| 27 | bool hasIntegratedCPP() const override { return false; } |
| 28 | |
| 29 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 30 | const InputInfo &Output, const InputInfoList &Inputs, |
| 31 | const llvm::opt::ArgList &TCArgs, |
| 32 | const char *LinkingOutput) const override; |
| 33 | }; |
| 34 | |
| 35 | class LLVM_LIBRARY_VISIBILITY MetalConverter : public Tool { |
| 36 | public: |
| 37 | MetalConverter(const ToolChain &TC) |
| 38 | : Tool("hlsl::MetalConverter" , "metal-shaderconverter" , TC) {} |
| 39 | |
| 40 | bool hasIntegratedCPP() const override { return false; } |
| 41 | |
| 42 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 43 | const InputInfo &Output, const InputInfoList &Inputs, |
| 44 | const llvm::opt::ArgList &TCArgs, |
| 45 | const char *LinkingOutput) const override; |
| 46 | }; |
| 47 | |
| 48 | class LLVM_LIBRARY_VISIBILITY LLVMObjcopy : public Tool { |
| 49 | public: |
| 50 | LLVMObjcopy(const ToolChain &TC) |
| 51 | : Tool("hlsl::LLVMObjcopy" , "llvm-objcopy" , TC) {} |
| 52 | |
| 53 | bool hasIntegratedCPP() const override { return false; } |
| 54 | |
| 55 | void ConstructJob(Compilation &C, const JobAction &JA, |
| 56 | const InputInfo &Output, const InputInfoList &Inputs, |
| 57 | const llvm::opt::ArgList &TCArgs, |
| 58 | const char *LinkingOutput) const override; |
| 59 | }; |
| 60 | |
| 61 | } // namespace hlsl |
| 62 | } // namespace tools |
| 63 | |
| 64 | namespace toolchains { |
| 65 | |
| 66 | class LLVM_LIBRARY_VISIBILITY HLSLToolChain : public ToolChain { |
| 67 | public: |
| 68 | HLSLToolChain(const Driver &D, const llvm::Triple &Triple, |
| 69 | const llvm::opt::ArgList &Args); |
| 70 | Tool *getTool(Action::ActionClass AC) const override; |
| 71 | |
| 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 | |
| 78 | llvm::opt::DerivedArgList * |
| 79 | TranslateArgs(const llvm::opt::DerivedArgList &Args, BoundArch BA, |
| 80 | Action::OffloadKind DeviceOffloadKind) const override; |
| 81 | static std::optional<std::string> parseTargetProfile(StringRef TargetProfile); |
| 82 | |
| 83 | struct ValidationInfo { |
| 84 | bool NeedsValidation = false; |
| 85 | bool ProducesOutput = false; |
| 86 | }; |
| 87 | |
| 88 | /// Returns information about whether validation is required and whether the |
| 89 | /// validator produces output. When Diagnose is true, emits a warning if the |
| 90 | /// required validator executable cannot be found. |
| 91 | ValidationInfo getValidationInfo(llvm::opt::DerivedArgList &Args, |
| 92 | bool Diagnose = true) const; |
| 93 | bool requiresBinaryTranslation(llvm::opt::DerivedArgList &Args) const; |
| 94 | bool requiresObjcopy(llvm::opt::DerivedArgList &Args) const; |
| 95 | |
| 96 | /// Determines whether the given action class is the last job that produces |
| 97 | /// an output file. This is used to decide whether to write to the -Fo |
| 98 | /// output path or to a temporary file. |
| 99 | /// |
| 100 | /// For example, spirv-val is a pure validator that runs after the compile |
| 101 | /// step but doesn't produce output, so the compile step is the last |
| 102 | /// output-producing job. For DXIL, dxv validates and signs, producing the |
| 103 | /// final output. |
| 104 | bool isLastOutputProducingJob(llvm::opt::DerivedArgList &Args, |
| 105 | Action::ActionClass AC) const; |
| 106 | |
| 107 | // Set default DWARF version to 4 for DXIL uses version 4. |
| 108 | unsigned GetDefaultDwarfVersion() const override { return 4; } |
| 109 | |
| 110 | void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override; |
| 111 | |
| 112 | private: |
| 113 | mutable std::unique_ptr<tools::hlsl::Validator> Validator; |
| 114 | mutable std::unique_ptr<tools::hlsl::MetalConverter> MetalConverter; |
| 115 | mutable std::unique_ptr<tools::hlsl::LLVMObjcopy> LLVMObjcopy; |
| 116 | }; |
| 117 | |
| 118 | } // end namespace toolchains |
| 119 | } // end namespace driver |
| 120 | } // end namespace clang |
| 121 | |
| 122 | #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_HLSL_H |
| 123 | |