@@ -51,6 +51,41 @@ class GlobalVariable;
51
51
class Function ;
52
52
class StructType ;
53
53
class Value ;
54
+
55
+ template <> struct DenseMapInfo <clang::Builtin::ID> {
56
+ static clang::Builtin::ID getEmptyKey () { return clang::Builtin::NotBuiltin; }
57
+
58
+ static clang::Builtin::ID getTombstoneKey () {
59
+ return clang::Builtin::FirstTSBuiltin;
60
+ }
61
+
62
+ static unsigned getHashValue (clang::Builtin::ID Val) {
63
+ return static_cast <unsigned >(Val);
64
+ }
65
+
66
+ static bool isEqual (clang::Builtin::ID LHS, clang::Builtin::ID RHS) {
67
+ return LHS == RHS;
68
+ }
69
+ };
70
+
71
+ template <> struct DenseMapInfo <llvm::Triple::ArchType> {
72
+ static llvm::Triple::ArchType getEmptyKey () {
73
+ return llvm::Triple::ArchType::UnknownArch;
74
+ }
75
+
76
+ static llvm::Triple::ArchType getTombstoneKey () {
77
+ return llvm::Triple::ArchType::LastArchType;
78
+ }
79
+
80
+ static unsigned getHashValue (llvm::Triple::ArchType Val) {
81
+ return static_cast <unsigned >(Val);
82
+ }
83
+
84
+ static bool isEqual (llvm::Triple::ArchType LHS, llvm::Triple::ArchType RHS) {
85
+ return LHS == RHS;
86
+ }
87
+ };
88
+
54
89
} // namespace llvm
55
90
56
91
namespace clang {
@@ -67,6 +102,15 @@ namespace CodeGen {
67
102
68
103
class CodeGenModule ;
69
104
105
+ struct CGHLSLIntrinsic {
106
+ llvm::DenseMap<llvm::Triple::ArchType, llvm::function_ref<llvm::Value *()>>
107
+ targetImplementations;
108
+ llvm::function_ref<llvm::Value *()> genericImplementation =
109
+ []() -> llvm::Value * {
110
+ llvm_unreachable (" Intrinsic not supported by target architecture." );
111
+ };
112
+ };
113
+
70
114
class CGHLSLRuntime {
71
115
public:
72
116
// ===----------------------------------------------------------------------===//
@@ -80,13 +124,11 @@ class CGHLSLRuntime {
80
124
// ===----------------------------------------------------------------------===//
81
125
// End of reserved area for HLSL intrinsic getters.
82
126
// ===----------------------------------------------------------------------===//
83
- llvm::Value *emitHLSLIntrinsic (
84
- llvm::function_ref<llvm::Value *()> DxilEmitter,
85
- llvm::function_ref<llvm::Value *()> SPIRVEmitter,
86
- llvm::function_ref<llvm::Value *()> GenericEmitter =
87
- []() -> llvm::Value * {
88
- llvm_unreachable (" Intrinsic not supported by target architecture." );
89
- });
127
+ void registerHLSLTargetIntrinsic (Builtin::ID, llvm::Triple::ArchType,
128
+ llvm::function_ref<llvm::Value *()>);
129
+ void registerHLSLGenericIntrinsic (Builtin::ID,
130
+ llvm::function_ref<llvm::Value *()>);
131
+ llvm::Value *emitHLSLIntrinsic (Builtin::ID);
90
132
struct BufferResBinding {
91
133
// The ID like 2 in register(b2, space1).
92
134
std::optional<unsigned > Reg;
@@ -137,6 +179,7 @@ class CGHLSLRuntime {
137
179
void addBufferDecls (const DeclContext *DC, Buffer &CB);
138
180
llvm::Triple::ArchType getArch ();
139
181
llvm::SmallVector<Buffer> Buffers;
182
+ llvm::DenseMap<clang::Builtin::ID, CGHLSLIntrinsic> IntrinsicCodeGen;
140
183
};
141
184
142
185
} // namespace CodeGen
0 commit comments