clang 23.0.0git
HLSL.h
Go to the documentation of this file.
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"
14
15namespace clang {
16namespace driver {
17
18namespace tools {
19
20namespace hlsl {
21class LLVM_LIBRARY_VISIBILITY Validator : public Tool {
22public:
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
35class LLVM_LIBRARY_VISIBILITY MetalConverter : public Tool {
36public:
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
48class LLVM_LIBRARY_VISIBILITY LLVMObjcopy : public Tool {
49public:
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
64namespace toolchains {
65
66class LLVM_LIBRARY_VISIBILITY HLSLToolChain : public ToolChain {
67public:
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, StringRef BoundArch,
80 Action::OffloadKind DeviceOffloadKind) const override;
81 static std::optional<std::string> parseTargetProfile(StringRef TargetProfile);
82
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
112private:
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
static StringRef getTriple(const Command &Job)
Compilation - A set of tasks to perform for a single driver invocation.
Definition Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:99
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:91
Tool - Information on a specific compilation tool.
Definition Tool.h:32
Tool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition Tool.cpp:14
bool requiresBinaryTranslation(llvm::opt::DerivedArgList &Args) const
Definition HLSL.cpp:634
bool isLastOutputProducingJob(llvm::opt::DerivedArgList &Args, Action::ActionClass AC) const
Determines whether the given action class is the last job that produces an output file.
Definition HLSL.cpp:644
Tool * getTool(Action::ActionClass AC) const override
Definition HLSL.cpp:407
HLSLToolChain(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
DirectX Toolchain.
Definition HLSL.cpp:396
unsigned GetDefaultDwarfVersion() const override
Definition HLSL.h:108
bool requiresObjcopy(llvm::opt::DerivedArgList &Args) const
Definition HLSL.cpp:638
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition HLSL.h:72
ValidationInfo getValidationInfo(llvm::opt::DerivedArgList &Args, bool Diagnose=true) const
Returns information about whether validation is required and whether the validator produces output.
Definition HLSL.cpp:596
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition HLSL.h:73
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition HLSL.h:76
LLVMObjcopy(const ToolChain &TC)
Definition HLSL.h:50
bool hasIntegratedCPP() const override
Definition HLSL.h:53
MetalConverter(const ToolChain &TC)
Definition HLSL.h:37
bool hasIntegratedCPP() const override
Definition HLSL.h:40
bool hasIntegratedCPP() const override
Definition HLSL.h:27
Validator(const ToolChain &TC)
Definition HLSL.h:23
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:50
The JSON file list parser is used to communicate input to InstallAPI.