/home/runner/work/DirectXShaderCompiler/DirectXShaderCompiler/include/dxc/HLSL/HLOperationLowerExtension.h
Line | Count | Source |
1 | | /////////////////////////////////////////////////////////////////////////////// |
2 | | // // |
3 | | // HLOperationLowerExtension.h // |
4 | | // Copyright (C) Microsoft Corporation. All rights reserved. // |
5 | | // This file is distributed under the University of Illinois Open Source // |
6 | | // License. See LICENSE.TXT for details. // |
7 | | // // |
8 | | // Functions to lower HL operations coming from HLSL extensions to DXIL // |
9 | | // operations. // |
10 | | // // |
11 | | /////////////////////////////////////////////////////////////////////////////// |
12 | | #pragma once |
13 | | |
14 | | #include "dxc/HLSL/HLSLExtensionsCodegenHelper.h" |
15 | | #include "llvm/ADT/StringRef.h" |
16 | | #include <string> |
17 | | #include <unordered_map> |
18 | | |
19 | | namespace llvm { |
20 | | class Value; |
21 | | class CallInst; |
22 | | class Function; |
23 | | class StringRef; |
24 | | class Instruction; |
25 | | } // namespace llvm |
26 | | |
27 | | namespace hlsl { |
28 | | class OP; |
29 | | |
30 | | struct HLResourceLookup { |
31 | | // Lookup resource kind based on handle. Return true on success. |
32 | | virtual bool GetResourceKindName(llvm::Value *HLHandle, |
33 | | const char **ppName) = 0; |
34 | 68 | virtual ~HLResourceLookup() {} |
35 | | }; |
36 | | |
37 | | // Lowers HLSL extensions from HL operation to DXIL operation. |
38 | | class ExtensionLowering { |
39 | | public: |
40 | | // Strategy used for lowering extensions. |
41 | | enum class Strategy { |
42 | | Unknown, // Do not know how to lower. This is an error condition. |
43 | | NoTranslation, // Propagate the call arguments as is down to dxil. |
44 | | Replicate, // Scalarize the vector arguments and replicate the call. |
45 | | Pack, // Convert the vector arguments into structs. |
46 | | Resource, // Convert return value to resource return and explode vectors. |
47 | | Dxil, // Convert call to a dxil intrinsic. |
48 | | Custom, // Custom lowering based on flexible json string. |
49 | | }; |
50 | | |
51 | | // Create the lowering using the given strategy and custom codegen helper. |
52 | | ExtensionLowering(llvm::StringRef strategy, |
53 | | HLSLExtensionsCodegenHelper *helper, OP &hlslOp, |
54 | | HLResourceLookup &resourceHelper); |
55 | | ExtensionLowering(Strategy strategy, HLSLExtensionsCodegenHelper *helper, |
56 | | OP &hlslOp, HLResourceLookup &resourceHelper); |
57 | | |
58 | | // Translate the HL op call to a DXIL op call. |
59 | | // Returns a new value if translation was successful. |
60 | | // Returns nullptr if translation failed or made no changes. |
61 | | llvm::Value *Translate(llvm::CallInst *CI); |
62 | | |
63 | | // Translate the strategy string to an enum. The strategy string is |
64 | | // added as a custom attribute on the high level extension function. |
65 | | // It is translated as follows: |
66 | | // "r" -> Replicate |
67 | | // "n" -> NoTranslation |
68 | | // "c" -> Custom |
69 | | static Strategy GetStrategy(llvm::StringRef strategy); |
70 | | |
71 | | // Translate the strategy enum into a name. This is the inverse of the |
72 | | // GetStrategy() function. |
73 | | static llvm::StringRef GetStrategyName(Strategy strategy); |
74 | | |
75 | | // Get the name that will be used for the extension function call after |
76 | | // lowering. |
77 | | std::string GetExtensionName(llvm::CallInst *CI); |
78 | | |
79 | | private: |
80 | | Strategy m_strategy; |
81 | | HLSLExtensionsCodegenHelper *m_helper; |
82 | | OP &m_hlslOp; |
83 | | HLResourceLookup &m_hlResourceLookup; |
84 | | std::string m_extraStrategyInfo; |
85 | | |
86 | | llvm::Value *Unknown(llvm::CallInst *CI); |
87 | | llvm::Value *NoTranslation(llvm::CallInst *CI); |
88 | | llvm::Value *Replicate(llvm::CallInst *CI); |
89 | | llvm::Value *Pack(llvm::CallInst *CI); |
90 | | llvm::Value *Resource(llvm::CallInst *CI); |
91 | | llvm::Value *Dxil(llvm::CallInst *CI); |
92 | | llvm::Value *CustomResource(llvm::CallInst *CI); |
93 | | llvm::Value *Custom(llvm::CallInst *CI); |
94 | | }; |
95 | | } // namespace hlsl |