1 //===-- SPIRVBuiltins.td - Describe SPIRV Builtins ---------*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // TableGen records defining implementation details of demangled builtin
10 // functions and types.
12 //===----------------------------------------------------------------------===//
14 // Define SPIR-V external builtin/instruction sets
15 def InstructionSet : GenericEnum {
16 let FilterClass = "InstructionSet";
17 let NameField = "Name";
18 let ValueField = "Value";
21 class InstructionSet<bits<32> value> {
23 bits<32> Value = value;
26 def OpenCL_std : InstructionSet<0>;
27 def GLSL_std_450 : InstructionSet<1>;
28 def SPV_AMD_shader_trinary_minmax : InstructionSet<2>;
29 def NonSemantic_Shader_DebugInfo_100 : InstructionSet<3>;
31 // Define various builtin groups
32 def BuiltinGroup : GenericEnum {
33 let FilterClass = "BuiltinGroup";
38 def Extended : BuiltinGroup;
39 def Relational : BuiltinGroup;
40 def Group : BuiltinGroup;
41 def Variable : BuiltinGroup;
42 def Atomic : BuiltinGroup;
43 def Barrier : BuiltinGroup;
44 def Dot : BuiltinGroup;
45 def Wave : BuiltinGroup;
46 def GetQuery : BuiltinGroup;
47 def ImageSizeQuery : BuiltinGroup;
48 def ImageMiscQuery : BuiltinGroup;
49 def Convert : BuiltinGroup;
50 def ReadImage : BuiltinGroup;
51 def WriteImage : BuiltinGroup;
52 def SampleImage : BuiltinGroup;
53 def Select : BuiltinGroup;
54 def SpecConstant : BuiltinGroup;
55 def Enqueue : BuiltinGroup;
56 def AsyncCopy : BuiltinGroup;
57 def VectorLoadStore : BuiltinGroup;
58 def LoadStore : BuiltinGroup;
59 def IntelSubgroups : BuiltinGroup;
60 def AtomicFloating : BuiltinGroup;
61 def GroupUniform : BuiltinGroup;
62 def KernelClock : BuiltinGroup;
63 def CastToPtr : BuiltinGroup;
64 def Construct : BuiltinGroup;
65 def CoopMatr : BuiltinGroup;
67 //===----------------------------------------------------------------------===//
68 // Class defining a demangled builtin record. The information in the record
69 // should be used to expand the builtin into either native SPIR-V instructions
70 // or an external call (in case of builtins without a direct mapping).
72 // name is the demangled name of the given builtin.
73 // set specifies which external instruction set the builtin belongs to.
74 // group specifies to which implementation group given record belongs.
75 // minNumArgs is the minimum required number of arguments for lowering.
76 // maxNumArgs specifies the maximum used number of arguments for lowering.
77 //===----------------------------------------------------------------------===//
78 class DemangledBuiltin<string name, InstructionSet set, BuiltinGroup group, bits<8> minNumArgs, bits<8> maxNumArgs> {
80 InstructionSet Set = set;
81 BuiltinGroup Group = group;
82 bits<8> MinNumArgs = minNumArgs;
83 bits<8> MaxNumArgs = maxNumArgs;
86 // Table gathering all the builtins.
87 def DemangledBuiltins : GenericTable {
88 let FilterClass = "DemangledBuiltin";
89 let Fields = ["Name", "Set", "Group", "MinNumArgs", "MaxNumArgs"];
90 string TypeOf_Set = "InstructionSet";
91 string TypeOf_Group = "BuiltinGroup";
94 // Function to lookup builtins by their demangled name and set.
95 def lookupBuiltin : SearchIndex {
96 let Table = DemangledBuiltins;
97 let Key = ["Name", "Set"];
100 // Dot builtin record:
101 def : DemangledBuiltin<"dot", OpenCL_std, Dot, 2, 2>;
102 def : DemangledBuiltin<"__spirv_Dot", OpenCL_std, Dot, 2, 2>;
104 // Image builtin records:
105 def : DemangledBuiltin<"read_imagei", OpenCL_std, ReadImage, 2, 4>;
106 def : DemangledBuiltin<"read_imageui", OpenCL_std, ReadImage, 2, 4>;
107 def : DemangledBuiltin<"read_imagef", OpenCL_std, ReadImage, 2, 4>;
109 def : DemangledBuiltin<"write_imagef", OpenCL_std, WriteImage, 3, 4>;
110 def : DemangledBuiltin<"write_imagei", OpenCL_std, WriteImage, 3, 4>;
111 def : DemangledBuiltin<"write_imageui", OpenCL_std, WriteImage, 3, 4>;
112 def : DemangledBuiltin<"write_imageh", OpenCL_std, WriteImage, 3, 4>;
114 def : DemangledBuiltin<"__translate_sampler_initializer", OpenCL_std, SampleImage, 1, 1>;
115 def : DemangledBuiltin<"__spirv_SampledImage", OpenCL_std, SampleImage, 2, 2>;
116 def : DemangledBuiltin<"__spirv_ImageSampleExplicitLod", OpenCL_std, SampleImage, 3, 4>;
118 // Select builtin record:
119 def : DemangledBuiltin<"__spirv_Select", OpenCL_std, Select, 3, 3>;
121 // Composite Construct builtin record:
122 def : DemangledBuiltin<"__spirv_CompositeConstruct", OpenCL_std, Construct, 1, 0>;
124 //===----------------------------------------------------------------------===//
125 // Class defining an extended builtin record used for lowering into an
126 // OpExtInst instruction.
128 // name is the demangled name of the given builtin.
129 // set specifies which external instruction set the builtin belongs to.
130 // number specifies the number of the instruction in the external set.
131 //===----------------------------------------------------------------------===//
132 class ExtendedBuiltin<string name, InstructionSet set, int number> {
134 InstructionSet Set = set;
135 bits<32> Number = number;
138 // Table gathering all the extended builtins.
139 def ExtendedBuiltins : GenericTable {
140 let FilterClass = "ExtendedBuiltin";
141 let Fields = ["Name", "Set", "Number"];
142 string TypeOf_Set = "InstructionSet";
145 // Function to lookup extended builtins by their name and set.
146 def lookupExtendedBuiltin : SearchIndex {
147 let Table = ExtendedBuiltins;
148 let Key = ["Name", "Set"];
151 // Function to lookup extended builtins by their set and number.
152 def lookupExtendedBuiltinBySetAndNumber : SearchIndex {
153 let Table = ExtendedBuiltins;
154 let Key = ["Set", "Number"];
157 // OpenCL extended instruction enums
158 def OpenCLExtInst : GenericEnum {
159 let FilterClass = "OpenCLExtInst";
160 let NameField = "Name";
161 let ValueField = "Value";
164 class OpenCLExtInst<string name, bits<32> value> {
166 bits<32> Value = value;
169 // GLSL extended instruction enums
170 def GLSLExtInst : GenericEnum {
171 let FilterClass = "GLSLExtInst";
172 let NameField = "Name";
173 let ValueField = "Value";
176 class GLSLExtInst<string name, bits<32> value> {
178 bits<32> Value = value;
181 def NonSemanticExtInst : GenericEnum {
182 let FilterClass = "NonSemanticExtInst";
183 let NameField = "Name";
184 let ValueField = "Value";
187 class NonSemanticExtInst<string name, bits<32> value> {
189 bits<32> Value = value;
192 // Multiclass used to define at the same time both a demangled builtin record
193 // and a corresponding extended builtin record.
194 multiclass DemangledExtendedBuiltin<string name, InstructionSet set, int number> {
195 def : DemangledBuiltin<name, set, Extended, 1, 3>;
196 def : ExtendedBuiltin<name, set, number>;
198 if !eq(set, OpenCL_std) then {
199 def : OpenCLExtInst<name, number>;
202 if !eq(set, GLSL_std_450) then {
203 def : GLSLExtInst<name, number>;
206 if !eq(set, NonSemantic_Shader_DebugInfo_100) then {
207 def : NonSemanticExtInst<name, number>;
211 // Extended builtin records:
212 defm : DemangledExtendedBuiltin<"acos", OpenCL_std, 0>;
213 defm : DemangledExtendedBuiltin<"acosh", OpenCL_std, 1>;
214 defm : DemangledExtendedBuiltin<"acospi", OpenCL_std, 2>;
215 defm : DemangledExtendedBuiltin<"asin", OpenCL_std, 3>;
216 defm : DemangledExtendedBuiltin<"asinh", OpenCL_std, 4>;
217 defm : DemangledExtendedBuiltin<"asinpi", OpenCL_std, 5>;
218 defm : DemangledExtendedBuiltin<"atan", OpenCL_std, 6>;
219 defm : DemangledExtendedBuiltin<"atan2", OpenCL_std, 7>;
220 defm : DemangledExtendedBuiltin<"atanh", OpenCL_std, 8>;
221 defm : DemangledExtendedBuiltin<"atanpi", OpenCL_std, 9>;
222 defm : DemangledExtendedBuiltin<"atan2pi", OpenCL_std, 10>;
223 defm : DemangledExtendedBuiltin<"cbrt", OpenCL_std, 11>;
224 defm : DemangledExtendedBuiltin<"ceil", OpenCL_std, 12>;
225 defm : DemangledExtendedBuiltin<"copysign", OpenCL_std, 13>;
226 defm : DemangledExtendedBuiltin<"cos", OpenCL_std, 14>;
227 defm : DemangledExtendedBuiltin<"cosh", OpenCL_std, 15>;
228 defm : DemangledExtendedBuiltin<"cospi", OpenCL_std, 16>;
229 defm : DemangledExtendedBuiltin<"erfc", OpenCL_std, 17>;
230 defm : DemangledExtendedBuiltin<"erf", OpenCL_std, 18>;
231 defm : DemangledExtendedBuiltin<"exp", OpenCL_std, 19>;
232 defm : DemangledExtendedBuiltin<"exp2", OpenCL_std, 20>;
233 defm : DemangledExtendedBuiltin<"exp10", OpenCL_std, 21>;
234 defm : DemangledExtendedBuiltin<"expm1", OpenCL_std, 22>;
235 defm : DemangledExtendedBuiltin<"fabs", OpenCL_std, 23>;
236 defm : DemangledExtendedBuiltin<"fdim", OpenCL_std, 24>;
237 defm : DemangledExtendedBuiltin<"floor", OpenCL_std, 25>;
238 defm : DemangledExtendedBuiltin<"fma", OpenCL_std, 26>;
239 defm : DemangledExtendedBuiltin<"fmax", OpenCL_std, 27>;
240 defm : DemangledExtendedBuiltin<"fmin", OpenCL_std, 28>;
241 defm : DemangledExtendedBuiltin<"fmod", OpenCL_std, 29>;
242 defm : DemangledExtendedBuiltin<"fract", OpenCL_std, 30>;
243 defm : DemangledExtendedBuiltin<"frexp", OpenCL_std, 31>;
244 defm : DemangledExtendedBuiltin<"hypot", OpenCL_std, 32>;
245 defm : DemangledExtendedBuiltin<"ilogb", OpenCL_std, 33>;
246 defm : DemangledExtendedBuiltin<"ldexp", OpenCL_std, 34>;
247 defm : DemangledExtendedBuiltin<"lgamma", OpenCL_std, 35>;
248 defm : DemangledExtendedBuiltin<"lgamma_r", OpenCL_std, 36>;
249 defm : DemangledExtendedBuiltin<"log", OpenCL_std, 37>;
250 defm : DemangledExtendedBuiltin<"log2", OpenCL_std, 38>;
251 defm : DemangledExtendedBuiltin<"log10", OpenCL_std, 39>;
252 defm : DemangledExtendedBuiltin<"log1p", OpenCL_std, 40>;
253 defm : DemangledExtendedBuiltin<"logb", OpenCL_std, 41>;
254 defm : DemangledExtendedBuiltin<"mad", OpenCL_std, 42>;
255 defm : DemangledExtendedBuiltin<"maxmag", OpenCL_std, 43>;
256 defm : DemangledExtendedBuiltin<"minmag", OpenCL_std, 44>;
257 defm : DemangledExtendedBuiltin<"modf", OpenCL_std, 45>;
258 defm : DemangledExtendedBuiltin<"nan", OpenCL_std, 46>;
259 defm : DemangledExtendedBuiltin<"nextafter", OpenCL_std, 47>;
260 defm : DemangledExtendedBuiltin<"pow", OpenCL_std, 48>;
261 defm : DemangledExtendedBuiltin<"pown", OpenCL_std, 49>;
262 defm : DemangledExtendedBuiltin<"powr", OpenCL_std, 50>;
263 defm : DemangledExtendedBuiltin<"remainder", OpenCL_std, 51>;
264 defm : DemangledExtendedBuiltin<"remquo", OpenCL_std, 52>;
265 defm : DemangledExtendedBuiltin<"rint", OpenCL_std, 53>;
266 defm : DemangledExtendedBuiltin<"rootn", OpenCL_std, 54>;
267 defm : DemangledExtendedBuiltin<"round", OpenCL_std, 55>;
268 defm : DemangledExtendedBuiltin<"rsqrt", OpenCL_std, 56>;
269 defm : DemangledExtendedBuiltin<"sin", OpenCL_std, 57>;
270 defm : DemangledExtendedBuiltin<"sincos", OpenCL_std, 58>;
271 defm : DemangledExtendedBuiltin<"sinh", OpenCL_std, 59>;
272 defm : DemangledExtendedBuiltin<"sinpi", OpenCL_std, 60>;
273 defm : DemangledExtendedBuiltin<"sqrt", OpenCL_std, 61>;
274 defm : DemangledExtendedBuiltin<"tan", OpenCL_std, 62>;
275 defm : DemangledExtendedBuiltin<"tanh", OpenCL_std, 63>;
276 defm : DemangledExtendedBuiltin<"tanpi", OpenCL_std, 64>;
277 defm : DemangledExtendedBuiltin<"tgamma", OpenCL_std, 65>;
278 defm : DemangledExtendedBuiltin<"trunc", OpenCL_std, 66>;
279 defm : DemangledExtendedBuiltin<"half_cos", OpenCL_std, 67>;
280 defm : DemangledExtendedBuiltin<"half_divide", OpenCL_std, 68>;
281 defm : DemangledExtendedBuiltin<"half_exp", OpenCL_std, 69>;
282 defm : DemangledExtendedBuiltin<"half_exp2", OpenCL_std, 70>;
283 defm : DemangledExtendedBuiltin<"half_exp10", OpenCL_std, 71>;
284 defm : DemangledExtendedBuiltin<"half_log", OpenCL_std, 72>;
285 defm : DemangledExtendedBuiltin<"half_log2", OpenCL_std, 73>;
286 defm : DemangledExtendedBuiltin<"half_log10", OpenCL_std, 74>;
287 defm : DemangledExtendedBuiltin<"half_powr", OpenCL_std, 75>;
288 defm : DemangledExtendedBuiltin<"half_recip", OpenCL_std, 76>;
289 defm : DemangledExtendedBuiltin<"half_rsqrt", OpenCL_std, 77>;
290 defm : DemangledExtendedBuiltin<"half_sin", OpenCL_std, 78>;
291 defm : DemangledExtendedBuiltin<"half_sqrt", OpenCL_std, 79>;
292 defm : DemangledExtendedBuiltin<"half_tan", OpenCL_std, 80>;
293 defm : DemangledExtendedBuiltin<"native_cos", OpenCL_std, 81>;
294 defm : DemangledExtendedBuiltin<"native_divide", OpenCL_std, 82>;
295 defm : DemangledExtendedBuiltin<"native_exp", OpenCL_std, 83>;
296 defm : DemangledExtendedBuiltin<"native_exp2", OpenCL_std, 84>;
297 defm : DemangledExtendedBuiltin<"native_exp10", OpenCL_std, 85>;
298 defm : DemangledExtendedBuiltin<"native_log", OpenCL_std, 86>;
299 defm : DemangledExtendedBuiltin<"native_log2", OpenCL_std, 87>;
300 defm : DemangledExtendedBuiltin<"native_log10", OpenCL_std, 88>;
301 defm : DemangledExtendedBuiltin<"native_powr", OpenCL_std, 89>;
302 defm : DemangledExtendedBuiltin<"native_recip", OpenCL_std, 90>;
303 defm : DemangledExtendedBuiltin<"native_rsqrt", OpenCL_std, 91>;
304 defm : DemangledExtendedBuiltin<"native_sin", OpenCL_std, 92>;
305 defm : DemangledExtendedBuiltin<"native_sqrt", OpenCL_std, 93>;
306 defm : DemangledExtendedBuiltin<"native_tan", OpenCL_std, 94>;
307 defm : DemangledExtendedBuiltin<"s_abs", OpenCL_std, 141>;
308 defm : DemangledExtendedBuiltin<"s_abs_diff", OpenCL_std, 142>;
309 defm : DemangledExtendedBuiltin<"s_add_sat", OpenCL_std, 143>;
310 defm : DemangledExtendedBuiltin<"u_add_sat", OpenCL_std, 144>;
311 defm : DemangledExtendedBuiltin<"s_hadd", OpenCL_std, 145>;
312 defm : DemangledExtendedBuiltin<"u_hadd", OpenCL_std, 146>;
313 defm : DemangledExtendedBuiltin<"s_rhadd", OpenCL_std, 147>;
314 defm : DemangledExtendedBuiltin<"u_rhadd", OpenCL_std, 148>;
315 defm : DemangledExtendedBuiltin<"s_clamp", OpenCL_std, 149>;
316 defm : DemangledExtendedBuiltin<"u_clamp", OpenCL_std, 150>;
317 defm : DemangledExtendedBuiltin<"clz", OpenCL_std, 151>;
318 defm : DemangledExtendedBuiltin<"ctz", OpenCL_std, 152>;
319 defm : DemangledExtendedBuiltin<"s_mad_hi", OpenCL_std, 153>;
320 defm : DemangledExtendedBuiltin<"u_mad_sat", OpenCL_std, 154>;
321 defm : DemangledExtendedBuiltin<"s_mad_sat", OpenCL_std, 155>;
322 defm : DemangledExtendedBuiltin<"s_max", OpenCL_std, 156>;
323 defm : DemangledExtendedBuiltin<"u_max", OpenCL_std, 157>;
324 defm : DemangledExtendedBuiltin<"s_min", OpenCL_std, 158>;
325 defm : DemangledExtendedBuiltin<"u_min", OpenCL_std, 159>;
326 defm : DemangledExtendedBuiltin<"s_mul_hi", OpenCL_std, 160>;
327 defm : DemangledExtendedBuiltin<"rotate", OpenCL_std, 161>;
328 defm : DemangledExtendedBuiltin<"s_sub_sat", OpenCL_std, 162>;
329 defm : DemangledExtendedBuiltin<"u_sub_sat", OpenCL_std, 163>;
330 defm : DemangledExtendedBuiltin<"u_upsample", OpenCL_std, 164>;
331 defm : DemangledExtendedBuiltin<"s_upsample", OpenCL_std, 165>;
332 defm : DemangledExtendedBuiltin<"popcount", OpenCL_std, 166>;
333 defm : DemangledExtendedBuiltin<"s_mad24", OpenCL_std, 167>;
334 defm : DemangledExtendedBuiltin<"u_mad24", OpenCL_std, 168>;
335 defm : DemangledExtendedBuiltin<"s_mul24", OpenCL_std, 169>;
336 defm : DemangledExtendedBuiltin<"u_mul24", OpenCL_std, 170>;
337 defm : DemangledExtendedBuiltin<"u_abs", OpenCL_std, 201>;
338 defm : DemangledExtendedBuiltin<"u_abs_diff", OpenCL_std, 202>;
339 defm : DemangledExtendedBuiltin<"u_mul_hi", OpenCL_std, 203>;
340 defm : DemangledExtendedBuiltin<"u_mad_hi", OpenCL_std, 204>;
341 defm : DemangledExtendedBuiltin<"fclamp", OpenCL_std, 95>;
342 defm : DemangledExtendedBuiltin<"degrees", OpenCL_std, 96>;
343 defm : DemangledExtendedBuiltin<"fmax_common", OpenCL_std, 97>;
344 defm : DemangledExtendedBuiltin<"fmin_common", OpenCL_std, 98>;
345 defm : DemangledExtendedBuiltin<"mix", OpenCL_std, 99>;
346 defm : DemangledExtendedBuiltin<"radians", OpenCL_std, 100>;
347 defm : DemangledExtendedBuiltin<"step", OpenCL_std, 101>;
348 defm : DemangledExtendedBuiltin<"smoothstep", OpenCL_std, 102>;
349 defm : DemangledExtendedBuiltin<"sign", OpenCL_std, 103>;
350 defm : DemangledExtendedBuiltin<"cross", OpenCL_std, 104>;
351 defm : DemangledExtendedBuiltin<"distance", OpenCL_std, 105>;
352 defm : DemangledExtendedBuiltin<"length", OpenCL_std, 106>;
353 defm : DemangledExtendedBuiltin<"normalize", OpenCL_std, 107>;
354 defm : DemangledExtendedBuiltin<"fast_distance", OpenCL_std, 108>;
355 defm : DemangledExtendedBuiltin<"fast_length", OpenCL_std, 109>;
356 defm : DemangledExtendedBuiltin<"fast_normalize", OpenCL_std, 110>;
357 defm : DemangledExtendedBuiltin<"bitselect", OpenCL_std, 186>;
358 defm : DemangledExtendedBuiltin<"select", OpenCL_std, 187>;
359 defm : DemangledExtendedBuiltin<"vloadn", OpenCL_std, 171>;
360 defm : DemangledExtendedBuiltin<"vstoren", OpenCL_std, 172>;
361 defm : DemangledExtendedBuiltin<"vload_half", OpenCL_std, 173>;
362 defm : DemangledExtendedBuiltin<"vload_halfn", OpenCL_std, 174>;
363 defm : DemangledExtendedBuiltin<"vstore_half", OpenCL_std, 175>;
364 defm : DemangledExtendedBuiltin<"vstore_half_r", OpenCL_std, 176>;
365 defm : DemangledExtendedBuiltin<"vstore_halfn", OpenCL_std, 177>;
366 defm : DemangledExtendedBuiltin<"vstore_halfn_r", OpenCL_std, 178>;
367 defm : DemangledExtendedBuiltin<"vloada_halfn", OpenCL_std, 179>;
368 defm : DemangledExtendedBuiltin<"vstorea_halfn", OpenCL_std, 180>;
369 defm : DemangledExtendedBuiltin<"vstorea_halfn_r", OpenCL_std, 181>;
370 defm : DemangledExtendedBuiltin<"shuffle", OpenCL_std, 182>;
371 defm : DemangledExtendedBuiltin<"shuffle2", OpenCL_std, 183>;
372 defm : DemangledExtendedBuiltin<"printf", OpenCL_std, 184>;
373 defm : DemangledExtendedBuiltin<"prefetch", OpenCL_std, 185>;
375 defm : DemangledExtendedBuiltin<"Round", GLSL_std_450, 1>;
376 defm : DemangledExtendedBuiltin<"RoundEven", GLSL_std_450, 2>;
377 defm : DemangledExtendedBuiltin<"Trunc", GLSL_std_450, 3>;
378 defm : DemangledExtendedBuiltin<"FAbs", GLSL_std_450, 4>;
379 defm : DemangledExtendedBuiltin<"SAbs", GLSL_std_450, 5>;
380 defm : DemangledExtendedBuiltin<"FSign", GLSL_std_450, 6>;
381 defm : DemangledExtendedBuiltin<"SSign", GLSL_std_450, 7>;
382 defm : DemangledExtendedBuiltin<"Floor", GLSL_std_450, 8>;
383 defm : DemangledExtendedBuiltin<"Ceil", GLSL_std_450, 9>;
384 defm : DemangledExtendedBuiltin<"Fract", GLSL_std_450, 10>;
385 defm : DemangledExtendedBuiltin<"Radians", GLSL_std_450, 11>;
386 defm : DemangledExtendedBuiltin<"Degrees", GLSL_std_450, 12>;
387 defm : DemangledExtendedBuiltin<"Sin", GLSL_std_450, 13>;
388 defm : DemangledExtendedBuiltin<"Cos", GLSL_std_450, 14>;
389 defm : DemangledExtendedBuiltin<"Tan", GLSL_std_450, 15>;
390 defm : DemangledExtendedBuiltin<"Asin", GLSL_std_450, 16>;
391 defm : DemangledExtendedBuiltin<"Acos", GLSL_std_450, 17>;
392 defm : DemangledExtendedBuiltin<"Atan", GLSL_std_450, 18>;
393 defm : DemangledExtendedBuiltin<"Sinh", GLSL_std_450, 19>;
394 defm : DemangledExtendedBuiltin<"Cosh", GLSL_std_450, 20>;
395 defm : DemangledExtendedBuiltin<"Tanh", GLSL_std_450, 21>;
396 defm : DemangledExtendedBuiltin<"Asinh", GLSL_std_450, 22>;
397 defm : DemangledExtendedBuiltin<"Acosh", GLSL_std_450, 23>;
398 defm : DemangledExtendedBuiltin<"Atanh", GLSL_std_450, 24>;
399 defm : DemangledExtendedBuiltin<"Atan2", GLSL_std_450, 25>;
400 defm : DemangledExtendedBuiltin<"Pow", GLSL_std_450, 26>;
401 defm : DemangledExtendedBuiltin<"Exp", GLSL_std_450, 27>;
402 defm : DemangledExtendedBuiltin<"Log", GLSL_std_450, 28>;
403 defm : DemangledExtendedBuiltin<"Exp2", GLSL_std_450, 29>;
404 defm : DemangledExtendedBuiltin<"Log2", GLSL_std_450, 30>;
405 defm : DemangledExtendedBuiltin<"Sqrt", GLSL_std_450, 31>;
406 defm : DemangledExtendedBuiltin<"InverseSqrt", GLSL_std_450, 32>;
407 defm : DemangledExtendedBuiltin<"Determinant", GLSL_std_450, 33>;
408 defm : DemangledExtendedBuiltin<"MatrixInverse", GLSL_std_450, 34>;
409 defm : DemangledExtendedBuiltin<"Modf", GLSL_std_450, 35>;
410 defm : DemangledExtendedBuiltin<"ModfStruct", GLSL_std_450, 36>;
411 defm : DemangledExtendedBuiltin<"FMin", GLSL_std_450, 37>;
412 defm : DemangledExtendedBuiltin<"UMin", GLSL_std_450, 38>;
413 defm : DemangledExtendedBuiltin<"SMin", GLSL_std_450, 39>;
414 defm : DemangledExtendedBuiltin<"FMax", GLSL_std_450, 40>;
415 defm : DemangledExtendedBuiltin<"UMax", GLSL_std_450, 41>;
416 defm : DemangledExtendedBuiltin<"SMax", GLSL_std_450, 42>;
417 defm : DemangledExtendedBuiltin<"FClamp", GLSL_std_450, 43>;
418 defm : DemangledExtendedBuiltin<"UClamp", GLSL_std_450, 44>;
419 defm : DemangledExtendedBuiltin<"SClamp", GLSL_std_450, 45>;
420 defm : DemangledExtendedBuiltin<"FMix", GLSL_std_450, 46>;
421 defm : DemangledExtendedBuiltin<"Step", GLSL_std_450, 48>;
422 defm : DemangledExtendedBuiltin<"SmoothStep", GLSL_std_450, 49>;
423 defm : DemangledExtendedBuiltin<"Fma", GLSL_std_450, 50>;
424 defm : DemangledExtendedBuiltin<"Frexp", GLSL_std_450, 51>;
425 defm : DemangledExtendedBuiltin<"FrexpStruct", GLSL_std_450, 52>;
426 defm : DemangledExtendedBuiltin<"Ldexp", GLSL_std_450, 53>;
427 defm : DemangledExtendedBuiltin<"PackSnorm4x8", GLSL_std_450, 54>;
428 defm : DemangledExtendedBuiltin<"PackUnorm4x8", GLSL_std_450, 55>;
429 defm : DemangledExtendedBuiltin<"PackSnorm2x16", GLSL_std_450, 56>;
430 defm : DemangledExtendedBuiltin<"PackUnorm2x16", GLSL_std_450, 57>;
431 defm : DemangledExtendedBuiltin<"PackHalf2x16", GLSL_std_450, 58>;
432 defm : DemangledExtendedBuiltin<"PackDouble2x32", GLSL_std_450, 59>;
433 defm : DemangledExtendedBuiltin<"UnpackSnorm2x16", GLSL_std_450, 60>;
434 defm : DemangledExtendedBuiltin<"UnpackUnorm2x16", GLSL_std_450, 61>;
435 defm : DemangledExtendedBuiltin<"UnpackHalf2x16", GLSL_std_450, 62>;
436 defm : DemangledExtendedBuiltin<"UnpackSnorm4x8", GLSL_std_450, 63>;
437 defm : DemangledExtendedBuiltin<"UnpackUnorm4x8", GLSL_std_450, 64>;
438 defm : DemangledExtendedBuiltin<"UnpackDouble2x32", GLSL_std_450, 65>;
439 defm : DemangledExtendedBuiltin<"Length", GLSL_std_450, 66>;
440 defm : DemangledExtendedBuiltin<"Distance", GLSL_std_450, 67>;
441 defm : DemangledExtendedBuiltin<"Cross", GLSL_std_450, 68>;
442 defm : DemangledExtendedBuiltin<"Normalize", GLSL_std_450, 69>;
443 defm : DemangledExtendedBuiltin<"FaceForward", GLSL_std_450, 70>;
444 defm : DemangledExtendedBuiltin<"Reflect", GLSL_std_450, 71>;
445 defm : DemangledExtendedBuiltin<"Refract", GLSL_std_450, 72>;
446 defm : DemangledExtendedBuiltin<"FindILsb", GLSL_std_450, 73>;
447 defm : DemangledExtendedBuiltin<"FindSMsb", GLSL_std_450, 74>;
448 defm : DemangledExtendedBuiltin<"FindUMsb", GLSL_std_450, 75>;
449 defm : DemangledExtendedBuiltin<"InterpolateAtCentroid", GLSL_std_450, 76>;
450 defm : DemangledExtendedBuiltin<"InterpolateAtSample", GLSL_std_450, 77>;
451 defm : DemangledExtendedBuiltin<"InterpolateAtOffset", GLSL_std_450, 78>;
452 defm : DemangledExtendedBuiltin<"NMin", GLSL_std_450, 79>;
453 defm : DemangledExtendedBuiltin<"NMax", GLSL_std_450, 80>;
454 defm : DemangledExtendedBuiltin<"NClamp", GLSL_std_450, 81>;
456 defm : DemangledExtendedBuiltin<"DebugInfoNone", NonSemantic_Shader_DebugInfo_100, 0>;
457 defm : DemangledExtendedBuiltin<"DebugCompilationUnit", NonSemantic_Shader_DebugInfo_100, 1>;
458 defm : DemangledExtendedBuiltin<"DebugTypeBasic", NonSemantic_Shader_DebugInfo_100, 2>;
459 defm : DemangledExtendedBuiltin<"DebugTypePointer", NonSemantic_Shader_DebugInfo_100, 3>;
460 defm : DemangledExtendedBuiltin<"DebugTypeQualifier", NonSemantic_Shader_DebugInfo_100, 4>;
461 defm : DemangledExtendedBuiltin<"DebugTypeArray", NonSemantic_Shader_DebugInfo_100, 5>;
462 defm : DemangledExtendedBuiltin<"DebugTypeVector", NonSemantic_Shader_DebugInfo_100, 6>;
463 defm : DemangledExtendedBuiltin<"DebugTypedef", NonSemantic_Shader_DebugInfo_100, 7>;
464 defm : DemangledExtendedBuiltin<"DebugTypeFunction", NonSemantic_Shader_DebugInfo_100, 8>;
465 defm : DemangledExtendedBuiltin<"DebugTypeEnum", NonSemantic_Shader_DebugInfo_100, 9>;
466 defm : DemangledExtendedBuiltin<"DebugTypeComposite", NonSemantic_Shader_DebugInfo_100, 10>;
467 defm : DemangledExtendedBuiltin<"DebugTypeMember", NonSemantic_Shader_DebugInfo_100, 11>;
468 defm : DemangledExtendedBuiltin<"DebugTypeInheritance", NonSemantic_Shader_DebugInfo_100, 12>;
469 defm : DemangledExtendedBuiltin<"DebugTypePtrToMember", NonSemantic_Shader_DebugInfo_100, 13>;
470 defm : DemangledExtendedBuiltin<"DebugTypeTemplate", NonSemantic_Shader_DebugInfo_100, 14>;
471 defm : DemangledExtendedBuiltin<"DebugTypeTemplateParameter", NonSemantic_Shader_DebugInfo_100, 15>;
472 defm : DemangledExtendedBuiltin<"DebugTypeTemplateTemplateParameter", NonSemantic_Shader_DebugInfo_100, 16>;
473 defm : DemangledExtendedBuiltin<"DebugTypeTemplateParameterPack", NonSemantic_Shader_DebugInfo_100, 17>;
474 defm : DemangledExtendedBuiltin<"DebugGlobalVariable", NonSemantic_Shader_DebugInfo_100, 18>;
475 defm : DemangledExtendedBuiltin<"DebugFunctionDeclaration", NonSemantic_Shader_DebugInfo_100, 19>;
476 defm : DemangledExtendedBuiltin<"DebugFunction", NonSemantic_Shader_DebugInfo_100, 20>;
477 defm : DemangledExtendedBuiltin<"DebugLexicalBlock", NonSemantic_Shader_DebugInfo_100, 21>;
478 defm : DemangledExtendedBuiltin<"DebugLexicalBlockDiscriminator", NonSemantic_Shader_DebugInfo_100, 22>;
479 defm : DemangledExtendedBuiltin<"DebugScope", NonSemantic_Shader_DebugInfo_100, 23>;
480 defm : DemangledExtendedBuiltin<"DebugNoScope", NonSemantic_Shader_DebugInfo_100, 24>;
481 defm : DemangledExtendedBuiltin<"DebugInlinedAt", NonSemantic_Shader_DebugInfo_100, 25>;
482 defm : DemangledExtendedBuiltin<"DebugLocalVariable", NonSemantic_Shader_DebugInfo_100, 26>;
483 defm : DemangledExtendedBuiltin<"DebugInlinedVariable", NonSemantic_Shader_DebugInfo_100, 27>;
484 defm : DemangledExtendedBuiltin<"DebugDeclare", NonSemantic_Shader_DebugInfo_100, 28>;
485 defm : DemangledExtendedBuiltin<"DebugValue", NonSemantic_Shader_DebugInfo_100, 29>;
486 defm : DemangledExtendedBuiltin<"DebugOperation", NonSemantic_Shader_DebugInfo_100, 30>;
487 defm : DemangledExtendedBuiltin<"DebugExpression", NonSemantic_Shader_DebugInfo_100, 31>;
488 defm : DemangledExtendedBuiltin<"DebugMacroDef", NonSemantic_Shader_DebugInfo_100, 32>;
489 defm : DemangledExtendedBuiltin<"DebugMacroUndef", NonSemantic_Shader_DebugInfo_100, 33>;
490 defm : DemangledExtendedBuiltin<"DebugImportedEntity", NonSemantic_Shader_DebugInfo_100, 34>;
491 defm : DemangledExtendedBuiltin<"DebugSource", NonSemantic_Shader_DebugInfo_100, 35>;
492 defm : DemangledExtendedBuiltin<"DebugFunctionDefinition", NonSemantic_Shader_DebugInfo_100, 101>;
493 defm : DemangledExtendedBuiltin<"DebugSourceContinued", NonSemantic_Shader_DebugInfo_100, 102>;
494 defm : DemangledExtendedBuiltin<"DebugLine", NonSemantic_Shader_DebugInfo_100, 103>;
495 defm : DemangledExtendedBuiltin<"DebugNoLine", NonSemantic_Shader_DebugInfo_100, 104>;
496 defm : DemangledExtendedBuiltin<"DebugBuildIdentifier", NonSemantic_Shader_DebugInfo_100, 105>;
497 defm : DemangledExtendedBuiltin<"DebugStoragePath", NonSemantic_Shader_DebugInfo_100, 106>;
498 defm : DemangledExtendedBuiltin<"DebugEntryPoint", NonSemantic_Shader_DebugInfo_100, 107>;
499 defm : DemangledExtendedBuiltin<"DebugTypeMatrix", NonSemantic_Shader_DebugInfo_100, 108>;
500 //===----------------------------------------------------------------------===//
501 // Class defining an native builtin record used for direct translation into a
502 // SPIR-V instruction.
504 // name is the demangled name of the given builtin.
505 // set specifies which external instruction set the builtin belongs to.
506 // opcode specifies the SPIR-V operation code of the generated instruction.
507 //===----------------------------------------------------------------------===//
508 class NativeBuiltin<string name, InstructionSet set, Op operation> {
510 InstructionSet Set = set;
511 Op Opcode = operation;
514 // Table gathering all the native builtins.
515 def NativeBuiltins : GenericTable {
516 let FilterClass = "NativeBuiltin";
517 let Fields = ["Name", "Set", "Opcode"];
518 string TypeOf_Set = "InstructionSet";
521 // Function to lookup native builtins by their name and set.
522 def lookupNativeBuiltin : SearchIndex {
523 let Table = NativeBuiltins;
524 let Key = ["Name", "Set"];
527 // Multiclass used to define at the same time both an incoming builtin record
528 // and a corresponding native builtin record.
529 multiclass DemangledNativeBuiltin<string name, InstructionSet set, BuiltinGroup group, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
530 def : DemangledBuiltin<name, set, group, minNumArgs, maxNumArgs>;
531 def : NativeBuiltin<name, set, operation>;
534 // Relational builtin records:
535 defm : DemangledNativeBuiltin<"isequal", OpenCL_std, Relational, 2, 2, OpFOrdEqual>;
536 defm : DemangledNativeBuiltin<"__spirv_FOrdEqual", OpenCL_std, Relational, 2, 2, OpFOrdEqual>;
537 defm : DemangledNativeBuiltin<"isnotequal", OpenCL_std, Relational, 2, 2, OpFUnordNotEqual>;
538 defm : DemangledNativeBuiltin<"__spirv_FUnordNotEqual", OpenCL_std, Relational, 2, 2, OpFUnordNotEqual>;
539 defm : DemangledNativeBuiltin<"isgreater", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThan>;
540 defm : DemangledNativeBuiltin<"__spirv_FOrdGreaterThan", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThan>;
541 defm : DemangledNativeBuiltin<"isgreaterequal", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThanEqual>;
542 defm : DemangledNativeBuiltin<"__spirv_FOrdGreaterThanEqual", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThanEqual>;
543 defm : DemangledNativeBuiltin<"isless", OpenCL_std, Relational, 2, 2, OpFOrdLessThan>;
544 defm : DemangledNativeBuiltin<"__spirv_FOrdLessThan", OpenCL_std, Relational, 2, 2, OpFOrdLessThan>;
545 defm : DemangledNativeBuiltin<"islessequal", OpenCL_std, Relational, 2, 2, OpFOrdLessThanEqual>;
546 defm : DemangledNativeBuiltin<"__spirv_FOrdLessThanEqual", OpenCL_std, Relational, 2, 2, OpFOrdLessThanEqual>;
547 defm : DemangledNativeBuiltin<"islessgreater", OpenCL_std, Relational, 2, 2, OpFOrdNotEqual>;
548 defm : DemangledNativeBuiltin<"__spirv_FOrdNotEqual", OpenCL_std, Relational, 2, 2, OpFOrdNotEqual>;
549 defm : DemangledNativeBuiltin<"isordered", OpenCL_std, Relational, 2, 2, OpOrdered>;
550 defm : DemangledNativeBuiltin<"__spirv_Ordered", OpenCL_std, Relational, 2, 2, OpOrdered>;
551 defm : DemangledNativeBuiltin<"isunordered", OpenCL_std, Relational, 2, 2, OpUnordered>;
552 defm : DemangledNativeBuiltin<"__spirv_Unordered", OpenCL_std, Relational, 2, 2, OpUnordered>;
553 defm : DemangledNativeBuiltin<"isfinite", OpenCL_std, Relational, 1, 1, OpIsFinite>;
554 defm : DemangledNativeBuiltin<"__spirv_IsFinite", OpenCL_std, Relational, 1, 1, OpIsFinite>;
555 defm : DemangledNativeBuiltin<"isinf", OpenCL_std, Relational, 1, 1, OpIsInf>;
556 defm : DemangledNativeBuiltin<"__spirv_IsInf", OpenCL_std, Relational, 1, 1, OpIsInf>;
557 defm : DemangledNativeBuiltin<"isnan", OpenCL_std, Relational, 1, 1, OpIsNan>;
558 defm : DemangledNativeBuiltin<"__spirv_IsNan", OpenCL_std, Relational, 1, 1, OpIsNan>;
559 defm : DemangledNativeBuiltin<"isnormal", OpenCL_std, Relational, 1, 1, OpIsNormal>;
560 defm : DemangledNativeBuiltin<"__spirv_IsNormal", OpenCL_std, Relational, 1, 1, OpIsNormal>;
561 defm : DemangledNativeBuiltin<"signbit", OpenCL_std, Relational, 1, 1, OpSignBitSet>;
562 defm : DemangledNativeBuiltin<"__spirv_SignBitSet", OpenCL_std, Relational, 1, 1, OpSignBitSet>;
563 defm : DemangledNativeBuiltin<"any", OpenCL_std, Relational, 1, 1, OpAny>;
564 defm : DemangledNativeBuiltin<"__spirv_Any", OpenCL_std, Relational, 1, 1, OpAny>;
565 defm : DemangledNativeBuiltin<"all", OpenCL_std, Relational, 1, 1, OpAll>;
566 defm : DemangledNativeBuiltin<"__spirv_All", OpenCL_std, Relational, 1, 1, OpAll>;
568 // Atomic builtin records:
569 defm : DemangledNativeBuiltin<"atomic_init", OpenCL_std, Atomic, 2, 2, OpStore>;
570 defm : DemangledNativeBuiltin<"atomic_load", OpenCL_std, Atomic, 1, 1, OpAtomicLoad>;
571 defm : DemangledNativeBuiltin<"atomic_load_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicLoad>;
572 defm : DemangledNativeBuiltin<"__spirv_AtomicLoad", OpenCL_std, Atomic, 3, 3, OpAtomicLoad>;
573 defm : DemangledNativeBuiltin<"atomic_store", OpenCL_std, Atomic, 2, 2, OpAtomicStore>;
574 defm : DemangledNativeBuiltin<"atomic_store_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicStore>;
575 defm : DemangledNativeBuiltin<"__spirv_AtomicStore", OpenCL_std, Atomic, 4, 4, OpAtomicStore>;
576 defm : DemangledNativeBuiltin<"atomic_compare_exchange_strong", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
577 defm : DemangledNativeBuiltin<"__spirv_AtomicCompareExchange", OpenCL_std, Atomic, 6, 6, OpAtomicCompareExchange>;
578 defm : DemangledNativeBuiltin<"atomic_compare_exchange_strong_explicit", OpenCL_std, Atomic, 5, 6, OpAtomicCompareExchange>;
579 defm : DemangledNativeBuiltin<"atomic_compare_exchange_weak", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchangeWeak>;
580 defm : DemangledNativeBuiltin<"atomic_compare_exchange_weak_explicit", OpenCL_std, Atomic, 5, 6, OpAtomicCompareExchangeWeak>;
581 defm : DemangledNativeBuiltin<"__spirv_AtomicCompareExchangeWeak", OpenCL_std, Atomic, 6, 6, OpAtomicCompareExchangeWeak>;
582 defm : DemangledNativeBuiltin<"atom_cmpxchg", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
583 defm : DemangledNativeBuiltin<"atomic_cmpxchg", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
584 defm : DemangledNativeBuiltin<"atom_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
585 defm : DemangledNativeBuiltin<"atomic_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
586 defm : DemangledNativeBuiltin<"__spirv_AtomicIAdd", OpenCL_std, Atomic, 4, 4, OpAtomicIAdd>;
587 defm : DemangledNativeBuiltin<"atom_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
588 defm : DemangledNativeBuiltin<"atomic_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
589 defm : DemangledNativeBuiltin<"__spirv_AtomicISub", OpenCL_std, Atomic, 4, 4, OpAtomicISub>;
590 defm : DemangledNativeBuiltin<"atom_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
591 defm : DemangledNativeBuiltin<"atomic_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
592 defm : DemangledNativeBuiltin<"__spirv_AtomicOr", OpenCL_std, Atomic, 4, 4, OpAtomicOr>;
593 defm : DemangledNativeBuiltin<"atom_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
594 defm : DemangledNativeBuiltin<"atomic_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
595 defm : DemangledNativeBuiltin<"__spirv_AtomicXor", OpenCL_std, Atomic, 4, 4, OpAtomicXor>;
596 defm : DemangledNativeBuiltin<"atom_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
597 defm : DemangledNativeBuiltin<"atomic_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
598 defm : DemangledNativeBuiltin<"__spirv_AtomicAnd", OpenCL_std, Atomic, 4, 4, OpAtomicAnd>;
599 defm : DemangledNativeBuiltin<"atomic_exchange", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
600 defm : DemangledNativeBuiltin<"atomic_exchange_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
601 defm : DemangledNativeBuiltin<"AtomicEx__spirv_change", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
602 defm : DemangledNativeBuiltin<"__spirv_AtomicExchange", OpenCL_std, Atomic, 4, 4, OpAtomicExchange>;
603 defm : DemangledNativeBuiltin<"atomic_work_item_fence", OpenCL_std, Atomic, 1, 3, OpMemoryBarrier>;
604 defm : DemangledNativeBuiltin<"__spirv_MemoryBarrier", OpenCL_std, Atomic, 2, 2, OpMemoryBarrier>;
605 defm : DemangledNativeBuiltin<"atomic_fetch_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
606 defm : DemangledNativeBuiltin<"atomic_fetch_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
607 defm : DemangledNativeBuiltin<"atomic_fetch_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
608 defm : DemangledNativeBuiltin<"atomic_fetch_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
609 defm : DemangledNativeBuiltin<"atomic_fetch_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
610 defm : DemangledNativeBuiltin<"atomic_fetch_add_explicit", OpenCL_std, Atomic, 3, 4, OpAtomicIAdd>;
611 defm : DemangledNativeBuiltin<"atomic_fetch_sub_explicit", OpenCL_std, Atomic, 3, 4, OpAtomicISub>;
612 defm : DemangledNativeBuiltin<"atomic_fetch_or_explicit", OpenCL_std, Atomic, 3, 4, OpAtomicOr>;
613 defm : DemangledNativeBuiltin<"atomic_fetch_xor_explicit", OpenCL_std, Atomic, 3, 4, OpAtomicXor>;
614 defm : DemangledNativeBuiltin<"atomic_fetch_and_explicit", OpenCL_std, Atomic, 3, 4, OpAtomicAnd>;
615 defm : DemangledNativeBuiltin<"atomic_flag_test_and_set", OpenCL_std, Atomic, 1, 1, OpAtomicFlagTestAndSet>;
616 defm : DemangledNativeBuiltin<"__spirv_AtomicFlagTestAndSet", OpenCL_std, Atomic, 3, 3, OpAtomicFlagTestAndSet>;
617 defm : DemangledNativeBuiltin<"atomic_flag_test_and_set_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicFlagTestAndSet>;
618 defm : DemangledNativeBuiltin<"atomic_flag_clear", OpenCL_std, Atomic, 1, 1, OpAtomicFlagClear>;
619 defm : DemangledNativeBuiltin<"__spirv_AtomicFlagClear", OpenCL_std, Atomic, 3, 3, OpAtomicFlagClear>;
620 defm : DemangledNativeBuiltin<"atomic_flag_clear_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicFlagClear>;
621 defm : DemangledNativeBuiltin<"__spirv_AtomicSMin", OpenCL_std, Atomic, 4, 4, OpAtomicSMin>;
622 defm : DemangledNativeBuiltin<"__spirv_AtomicSMax", OpenCL_std, Atomic, 4, 4, OpAtomicSMax>;
623 defm : DemangledNativeBuiltin<"__spirv_AtomicUMin", OpenCL_std, Atomic, 4, 4, OpAtomicUMin>;
624 defm : DemangledNativeBuiltin<"__spirv_AtomicUMax", OpenCL_std, Atomic, 4, 4, OpAtomicUMax>;
626 // Barrier builtin records:
627 defm : DemangledNativeBuiltin<"barrier", OpenCL_std, Barrier, 1, 3, OpControlBarrier>;
628 defm : DemangledNativeBuiltin<"work_group_barrier", OpenCL_std, Barrier, 1, 3, OpControlBarrier>;
629 defm : DemangledNativeBuiltin<"__spirv_ControlBarrier", OpenCL_std, Barrier, 3, 3, OpControlBarrier>;
631 // Kernel enqueue builtin records:
632 defm : DemangledNativeBuiltin<"__enqueue_kernel_basic", OpenCL_std, Enqueue, 5, 5, OpEnqueueKernel>;
633 defm : DemangledNativeBuiltin<"__enqueue_kernel_basic_events", OpenCL_std, Enqueue, 8, 8, OpEnqueueKernel>;
634 defm : DemangledNativeBuiltin<"__enqueue_kernel_varargs", OpenCL_std, Enqueue, 7, 7, OpEnqueueKernel>;
635 defm : DemangledNativeBuiltin<"__enqueue_kernel_events_varargs", OpenCL_std, Enqueue, 10, 10, OpEnqueueKernel>;
636 defm : DemangledNativeBuiltin<"__spirv_EnqueueKernel", OpenCL_std, Enqueue, 10, 0, OpEnqueueKernel>;
637 defm : DemangledNativeBuiltin<"retain_event", OpenCL_std, Enqueue, 1, 1, OpRetainEvent>;
638 defm : DemangledNativeBuiltin<"__spirv_RetainEvent", OpenCL_std, Enqueue, 1, 1, OpRetainEvent>;
639 defm : DemangledNativeBuiltin<"release_event", OpenCL_std, Enqueue, 1, 1, OpReleaseEvent>;
640 defm : DemangledNativeBuiltin<"__spirv_ReleaseEvent", OpenCL_std, Enqueue, 1, 1, OpReleaseEvent>;
641 defm : DemangledNativeBuiltin<"create_user_event", OpenCL_std, Enqueue, 0, 0, OpCreateUserEvent>;
642 defm : DemangledNativeBuiltin<"__spirv_CreateUserEvent", OpenCL_std, Enqueue, 0, 0, OpCreateUserEvent>;
643 defm : DemangledNativeBuiltin<"is_valid_event", OpenCL_std, Enqueue, 1, 1, OpIsValidEvent>;
644 defm : DemangledNativeBuiltin<"__spirv_IsValidEvent", OpenCL_std, Enqueue, 1, 1, OpIsValidEvent>;
645 defm : DemangledNativeBuiltin<"set_user_event_status", OpenCL_std, Enqueue, 2, 2, OpSetUserEventStatus>;
646 defm : DemangledNativeBuiltin<"__spirv_SetUserEventStatus", OpenCL_std, Enqueue, 2, 2, OpSetUserEventStatus>;
647 defm : DemangledNativeBuiltin<"capture_event_profiling_info", OpenCL_std, Enqueue, 3, 3, OpCaptureEventProfilingInfo>;
648 defm : DemangledNativeBuiltin<"__spirv_CaptureEventProfilingInfo", OpenCL_std, Enqueue, 3, 3, OpCaptureEventProfilingInfo>;
649 defm : DemangledNativeBuiltin<"get_default_queue", OpenCL_std, Enqueue, 0, 0, OpGetDefaultQueue>;
650 defm : DemangledNativeBuiltin<"__spirv_GetDefaultQueue", OpenCL_std, Enqueue, 0, 0, OpGetDefaultQueue>;
651 defm : DemangledNativeBuiltin<"ndrange_1D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
652 defm : DemangledNativeBuiltin<"ndrange_2D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
653 defm : DemangledNativeBuiltin<"ndrange_3D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
655 // Spec constant builtin records:
656 defm : DemangledNativeBuiltin<"__spirv_SpecConstant", OpenCL_std, SpecConstant, 2, 2, OpSpecConstant>;
657 defm : DemangledNativeBuiltin<"__spirv_SpecConstantComposite", OpenCL_std, SpecConstant, 1, 0, OpSpecConstantComposite>;
659 // Async Copy and Prefetch builtin records:
660 defm : DemangledNativeBuiltin<"async_work_group_copy", OpenCL_std, AsyncCopy, 4, 4, OpGroupAsyncCopy>;
661 defm : DemangledNativeBuiltin<"async_work_group_strided_copy", OpenCL_std, AsyncCopy, 5, 5, OpGroupAsyncCopy>;
662 defm : DemangledNativeBuiltin<"__spirv_GroupAsyncCopy", OpenCL_std, AsyncCopy, 6, 6, OpGroupAsyncCopy>;
663 defm : DemangledNativeBuiltin<"wait_group_events", OpenCL_std, AsyncCopy, 2, 2, OpGroupWaitEvents>;
664 defm : DemangledNativeBuiltin<"__spirv_GroupWaitEvents", OpenCL_std, AsyncCopy, 3, 3, OpGroupWaitEvents>;
666 // Load and store builtin records:
667 defm : DemangledNativeBuiltin<"__spirv_Load", OpenCL_std, LoadStore, 1, 3, OpLoad>;
668 defm : DemangledNativeBuiltin<"__spirv_Store", OpenCL_std, LoadStore, 2, 4, OpStore>;
670 // Address Space Qualifier Functions/Pointers Conversion Instructions:
671 defm : DemangledNativeBuiltin<"to_global", OpenCL_std, CastToPtr, 1, 1, OpGenericCastToPtr>;
672 defm : DemangledNativeBuiltin<"to_local", OpenCL_std, CastToPtr, 1, 1, OpGenericCastToPtr>;
673 defm : DemangledNativeBuiltin<"to_private", OpenCL_std, CastToPtr, 1, 1, OpGenericCastToPtr>;
674 defm : DemangledNativeBuiltin<"__spirv_GenericCastToPtr_ToGlobal", OpenCL_std, CastToPtr, 2, 2, OpGenericCastToPtr>;
675 defm : DemangledNativeBuiltin<"__spirv_GenericCastToPtr_ToLocal", OpenCL_std, CastToPtr, 2, 2, OpGenericCastToPtr>;
676 defm : DemangledNativeBuiltin<"__spirv_GenericCastToPtr_ToPrivate", OpenCL_std, CastToPtr, 2, 2, OpGenericCastToPtr>;
677 defm : DemangledNativeBuiltin<"__spirv_GenericCastToPtrExplicit_ToGlobal", OpenCL_std, CastToPtr, 2, 2, OpGenericCastToPtr>;
678 defm : DemangledNativeBuiltin<"__spirv_GenericCastToPtrExplicit_ToLocal", OpenCL_std, CastToPtr, 2, 2, OpGenericCastToPtr>;
679 defm : DemangledNativeBuiltin<"__spirv_GenericCastToPtrExplicit_ToPrivate", OpenCL_std, CastToPtr, 2, 2, OpGenericCastToPtr>;
681 // Cooperative Matrix builtin records:
682 defm : DemangledNativeBuiltin<"__spirv_CooperativeMatrixLoadKHR", OpenCL_std, CoopMatr, 2, 0, OpCooperativeMatrixLoadKHR>;
683 defm : DemangledNativeBuiltin<"__spirv_CooperativeMatrixStoreKHR", OpenCL_std, CoopMatr, 3, 0, OpCooperativeMatrixStoreKHR>;
684 defm : DemangledNativeBuiltin<"__spirv_CooperativeMatrixMulAddKHR", OpenCL_std, CoopMatr, 3, 0, OpCooperativeMatrixMulAddKHR>;
685 defm : DemangledNativeBuiltin<"__spirv_CooperativeMatrixLengthKHR", OpenCL_std, CoopMatr, 1, 1, OpCooperativeMatrixLengthKHR>;
687 //===----------------------------------------------------------------------===//
688 // Class defining a work/sub group builtin that should be translated into a
689 // SPIR-V instruction using the defined properties.
691 // name is the demangled name of the given builtin.
692 // opcode specifies the SPIR-V operation code of the generated instruction.
693 //===----------------------------------------------------------------------===//
694 class GroupBuiltin<string name, Op operation> {
696 Op Opcode = operation;
697 bits<32> GroupOperation = !cond(!not(!eq(!find(name, "group_reduce"), -1)) : Reduce.Value,
698 !not(!eq(!find(name, "group_scan_inclusive"), -1)) : InclusiveScan.Value,
699 !not(!eq(!find(name, "group_scan_exclusive"), -1)) : ExclusiveScan.Value,
700 !not(!eq(!find(name, "group_ballot_bit_count"), -1)) : Reduce.Value,
701 !not(!eq(!find(name, "group_ballot_inclusive_scan"), -1)) : InclusiveScan.Value,
702 !not(!eq(!find(name, "group_ballot_exclusive_scan"), -1)) : ExclusiveScan.Value,
703 !not(!eq(!find(name, "group_non_uniform_reduce"), -1)) : Reduce.Value,
704 !not(!eq(!find(name, "group_non_uniform_scan_inclusive"), -1)) : InclusiveScan.Value,
705 !not(!eq(!find(name, "group_non_uniform_scan_exclusive"), -1)) : ExclusiveScan.Value,
706 !not(!eq(!find(name, "group_non_uniform_reduce_logical"), -1)) : Reduce.Value,
707 !not(!eq(!find(name, "group_non_uniform_scan_inclusive_logical"), -1)) : InclusiveScan.Value,
708 !not(!eq(!find(name, "group_non_uniform_scan_exclusive_logical"), -1)) : ExclusiveScan.Value,
709 !not(!eq(!find(name, "group_clustered_reduce"), -1)) : ClusteredReduce.Value,
710 !not(!eq(!find(name, "group_clustered_reduce_logical"), -1)) : ClusteredReduce.Value,
712 bit IsElect = !eq(operation, OpGroupNonUniformElect);
713 bit IsAllOrAny = !or(!eq(operation, OpGroupAll),
714 !eq(operation, OpGroupAny),
715 !eq(operation, OpGroupNonUniformAll),
716 !eq(operation, OpGroupNonUniformAny));
717 bit IsAllEqual = !eq(operation, OpGroupNonUniformAllEqual);
718 bit IsBallot = !eq(operation, OpGroupNonUniformBallot);
719 bit IsInverseBallot = !eq(operation, OpGroupNonUniformInverseBallot);
720 bit IsBallotBitExtract = !eq(operation, OpGroupNonUniformBallotBitExtract);
721 bit IsBallotFindBit = !or(!eq(operation, OpGroupNonUniformBallotFindLSB),
722 !eq(operation, OpGroupNonUniformBallotFindMSB));
723 bit IsLogical = !or(!eq(operation, OpGroupNonUniformLogicalAnd),
724 !eq(operation, OpGroupNonUniformLogicalOr),
725 !eq(operation, OpGroupNonUniformLogicalXor),
726 !eq(operation, OpGroupLogicalAndKHR),
727 !eq(operation, OpGroupLogicalOrKHR),
728 !eq(operation, OpGroupLogicalXorKHR));
729 bit NoGroupOperation = !or(IsElect, IsAllOrAny, IsAllEqual,
730 IsBallot, IsInverseBallot,
731 IsBallotBitExtract, IsBallotFindBit,
732 !eq(operation, OpGroupNonUniformShuffle),
733 !eq(operation, OpGroupNonUniformShuffleXor),
734 !eq(operation, OpGroupNonUniformShuffleUp),
735 !eq(operation, OpGroupNonUniformShuffleDown),
736 !eq(operation, OpGroupBroadcast),
737 !eq(operation, OpGroupNonUniformBroadcast),
738 !eq(operation, OpGroupNonUniformBroadcastFirst),
739 !eq(operation, OpGroupNonUniformRotateKHR));
740 bit HasBoolArg = !or(!and(IsAllOrAny, !eq(IsAllEqual, false)), IsBallot, IsLogical);
743 // Table gathering all the work/sub group builtins.
744 def GroupBuiltins : GenericTable {
745 let FilterClass = "GroupBuiltin";
746 let Fields = ["Name", "Opcode", "GroupOperation", "IsElect", "IsAllOrAny",
747 "IsAllEqual", "IsBallot", "IsInverseBallot", "IsBallotBitExtract",
748 "IsBallotFindBit", "IsLogical", "NoGroupOperation", "HasBoolArg"];
751 // Function to lookup group builtins by their name and set.
752 def lookupGroupBuiltin : SearchIndex {
753 let Table = GroupBuiltins;
757 // Multiclass used to define at the same time both incoming builtin records
758 // and corresponding work/sub group builtin records.
759 defvar OnlyWork = 0; defvar OnlySub = 1; defvar WorkOrSub = 2;
760 multiclass DemangledGroupBuiltin<string name, int level /* OnlyWork/OnlySub/... */, Op operation> {
761 assert !and(!ge(level, 0), !le(level, 2)), "group level is invalid: " # level;
763 if !or(!eq(level, OnlyWork), !eq(level, WorkOrSub)) then {
764 def : DemangledBuiltin<!strconcat("work_", name), OpenCL_std, Group, 0, 4>;
765 def : GroupBuiltin<!strconcat("work_", name), operation>;
768 if !or(!eq(level, OnlySub), !eq(level, WorkOrSub)) then {
769 def : DemangledBuiltin<!strconcat("sub_", name), OpenCL_std, Group, 0, 4>;
770 def : GroupBuiltin<!strconcat("sub_", name), operation>;
774 multiclass DemangledGroupBuiltinWrapper<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
775 def : DemangledBuiltin<name, OpenCL_std, Group, minNumArgs, maxNumArgs>;
776 def : GroupBuiltin<name, operation>;
779 defm : DemangledGroupBuiltin<"group_all", WorkOrSub, OpGroupAll>;
780 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupAll", 2, 2, OpGroupAll>;
781 defm : DemangledGroupBuiltin<"group_any", WorkOrSub, OpGroupAny>;
782 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupAny", 2, 2, OpGroupAny>;
783 defm : DemangledGroupBuiltin<"group_broadcast", WorkOrSub, OpGroupBroadcast>;
784 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupBroadcast", 3, 3, OpGroupBroadcast>;
785 defm : DemangledGroupBuiltin<"group_non_uniform_broadcast", OnlySub, OpGroupNonUniformBroadcast>;
786 defm : DemangledGroupBuiltin<"group_broadcast_first", OnlySub, OpGroupNonUniformBroadcastFirst>;
788 // cl_khr_subgroup_non_uniform_vote
789 defm : DemangledGroupBuiltin<"group_elect", OnlySub, OpGroupNonUniformElect>;
790 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformElect", 1, 1, OpGroupNonUniformElect>;
791 defm : DemangledGroupBuiltin<"group_non_uniform_all", OnlySub, OpGroupNonUniformAll>;
792 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformAll", 2, 2, OpGroupNonUniformAll>;
793 defm : DemangledGroupBuiltin<"group_non_uniform_any", OnlySub, OpGroupNonUniformAny>;
794 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformAny", 2, 2, OpGroupNonUniformAny>;
795 defm : DemangledGroupBuiltin<"group_non_uniform_all_equal", OnlySub, OpGroupNonUniformAllEqual>;
796 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformAllEqual", 2, 2, OpGroupNonUniformAllEqual>;
798 // cl_khr_subgroup_ballot
799 defm : DemangledGroupBuiltin<"group_ballot", OnlySub, OpGroupNonUniformBallot>;
800 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBallot", 2, 2, OpGroupNonUniformBallot>;
801 defm : DemangledGroupBuiltin<"group_inverse_ballot", OnlySub, OpGroupNonUniformInverseBallot>;
802 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformInverseBallot", 2, 2, OpGroupNonUniformInverseBallot>;
803 defm : DemangledGroupBuiltin<"group_ballot_bit_extract", OnlySub, OpGroupNonUniformBallotBitExtract>;
804 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBallotBitExtract", 3, 3, OpGroupNonUniformBallotBitExtract>;
805 defm : DemangledGroupBuiltin<"group_ballot_bit_count", OnlySub, OpGroupNonUniformBallotBitCount>;
806 defm : DemangledGroupBuiltin<"group_ballot_inclusive_scan", OnlySub, OpGroupNonUniformBallotBitCount>;
807 defm : DemangledGroupBuiltin<"group_ballot_exclusive_scan", OnlySub, OpGroupNonUniformBallotBitCount>;
808 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBallotBitCount", 3, 3, OpGroupNonUniformBallotBitCount>;
809 defm : DemangledGroupBuiltin<"group_ballot_find_lsb", OnlySub, OpGroupNonUniformBallotFindLSB>;
810 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBallotFindLSB", 2, 2, OpGroupNonUniformBallotFindLSB>;
811 defm : DemangledGroupBuiltin<"group_ballot_find_msb", OnlySub, OpGroupNonUniformBallotFindMSB>;
812 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBallotFindMSB", 2, 2, OpGroupNonUniformBallotFindMSB>;
814 // cl_khr_subgroup_shuffle
815 defm : DemangledGroupBuiltin<"group_shuffle", OnlySub, OpGroupNonUniformShuffle>;
816 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformShuffle", 3, 3, OpGroupNonUniformShuffle>;
817 defm : DemangledGroupBuiltin<"group_shuffle_xor", OnlySub, OpGroupNonUniformShuffleXor>;
818 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformShuffleXor", 3, 3, OpGroupNonUniformShuffleXor>;
820 // cl_khr_subgroup_shuffle_relative
821 defm : DemangledGroupBuiltin<"group_shuffle_up", OnlySub, OpGroupNonUniformShuffleUp>;
822 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformShuffleUp", 3, 3, OpGroupNonUniformShuffleUp>;
823 defm : DemangledGroupBuiltin<"group_shuffle_down", OnlySub, OpGroupNonUniformShuffleDown>;
824 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformShuffleDown", 3, 3, OpGroupNonUniformShuffleDown>;
826 defm : DemangledGroupBuiltin<"group_iadd", WorkOrSub, OpGroupIAdd>;
827 defm : DemangledGroupBuiltin<"group_reduce_adds", WorkOrSub, OpGroupIAdd>;
828 defm : DemangledGroupBuiltin<"group_scan_exclusive_adds", WorkOrSub, OpGroupIAdd>;
829 defm : DemangledGroupBuiltin<"group_scan_inclusive_adds", WorkOrSub, OpGroupIAdd>;
830 defm : DemangledGroupBuiltin<"group_reduce_addu", WorkOrSub, OpGroupIAdd>;
831 defm : DemangledGroupBuiltin<"group_scan_exclusive_addu", WorkOrSub, OpGroupIAdd>;
832 defm : DemangledGroupBuiltin<"group_scan_inclusive_addu", WorkOrSub, OpGroupIAdd>;
833 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupIAdd", 3, 3, OpGroupIAdd>;
835 defm : DemangledGroupBuiltin<"group_fadd", WorkOrSub, OpGroupFAdd>;
836 defm : DemangledGroupBuiltin<"group_reduce_addf", WorkOrSub, OpGroupFAdd>;
837 defm : DemangledGroupBuiltin<"group_scan_exclusive_addf", WorkOrSub, OpGroupFAdd>;
838 defm : DemangledGroupBuiltin<"group_scan_inclusive_addf", WorkOrSub, OpGroupFAdd>;
839 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupFAdd", 3, 3, OpGroupFAdd>;
841 defm : DemangledGroupBuiltin<"group_fmin", WorkOrSub, OpGroupFMin>;
842 defm : DemangledGroupBuiltin<"group_reduce_minf", WorkOrSub, OpGroupFMin>;
843 defm : DemangledGroupBuiltin<"group_scan_exclusive_minf", WorkOrSub, OpGroupFMin>;
844 defm : DemangledGroupBuiltin<"group_scan_inclusive_minf", WorkOrSub, OpGroupFMin>;
845 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupFMin", 3, 3, OpGroupFMin>;
847 defm : DemangledGroupBuiltin<"group_umin", WorkOrSub, OpGroupUMin>;
848 defm : DemangledGroupBuiltin<"group_reduce_minu", WorkOrSub, OpGroupUMin>;
849 defm : DemangledGroupBuiltin<"group_scan_exclusive_minu", WorkOrSub, OpGroupUMin>;
850 defm : DemangledGroupBuiltin<"group_scan_inclusive_minu", WorkOrSub, OpGroupUMin>;
851 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupUMin", 3, 3, OpGroupUMin>;
853 defm : DemangledGroupBuiltin<"group_smin", WorkOrSub, OpGroupSMin>;
854 defm : DemangledGroupBuiltin<"group_reduce_mins", WorkOrSub, OpGroupSMin>;
855 defm : DemangledGroupBuiltin<"group_scan_exclusive_mins", WorkOrSub, OpGroupSMin>;
856 defm : DemangledGroupBuiltin<"group_scan_inclusive_mins", WorkOrSub, OpGroupSMin>;
857 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupSMin", 3, 3, OpGroupSMin>;
859 defm : DemangledGroupBuiltin<"group_fmax", WorkOrSub, OpGroupFMax>;
860 defm : DemangledGroupBuiltin<"group_reduce_maxf", WorkOrSub, OpGroupFMax>;
861 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxf", WorkOrSub, OpGroupFMax>;
862 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxf", WorkOrSub, OpGroupFMax>;
863 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupFMax", 3, 3, OpGroupFMax>;
865 defm : DemangledGroupBuiltin<"group_umax", WorkOrSub, OpGroupUMax>;
866 defm : DemangledGroupBuiltin<"group_reduce_maxu", WorkOrSub, OpGroupUMax>;
867 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxu", WorkOrSub, OpGroupUMax>;
868 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxu", WorkOrSub, OpGroupUMax>;
869 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupUMax", 3, 3, OpGroupUMax>;
871 defm : DemangledGroupBuiltin<"group_smax", WorkOrSub, OpGroupSMax>;
872 defm : DemangledGroupBuiltin<"group_reduce_maxs", WorkOrSub, OpGroupSMax>;
873 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxs", WorkOrSub, OpGroupSMax>;
874 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxs", WorkOrSub, OpGroupSMax>;
875 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupSMax", 3, 3, OpGroupSMax>;
877 // cl_khr_subgroup_non_uniform_arithmetic
878 defm : DemangledGroupBuiltin<"group_non_uniform_iadd", WorkOrSub, OpGroupNonUniformIAdd>;
879 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addu", WorkOrSub, OpGroupNonUniformIAdd>;
880 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_adds", WorkOrSub, OpGroupNonUniformIAdd>;
881 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addu", WorkOrSub, OpGroupNonUniformIAdd>;
882 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_adds", WorkOrSub, OpGroupNonUniformIAdd>;
883 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addu", WorkOrSub, OpGroupNonUniformIAdd>;
884 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_adds", WorkOrSub, OpGroupNonUniformIAdd>;
885 defm : DemangledGroupBuiltin<"group_clustered_reduce_addu", WorkOrSub, OpGroupNonUniformIAdd>;
886 defm : DemangledGroupBuiltin<"group_clustered_reduce_adds", WorkOrSub, OpGroupNonUniformIAdd>;
887 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformIAdd", 3, 4, OpGroupNonUniformIAdd>;
889 defm : DemangledGroupBuiltin<"group_non_uniform_fadd", WorkOrSub, OpGroupNonUniformFAdd>;
890 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addf", WorkOrSub, OpGroupNonUniformFAdd>;
891 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addh", WorkOrSub, OpGroupNonUniformFAdd>;
892 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addd", WorkOrSub, OpGroupNonUniformFAdd>;
893 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addf", WorkOrSub, OpGroupNonUniformFAdd>;
894 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addh", WorkOrSub, OpGroupNonUniformFAdd>;
895 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addd", WorkOrSub, OpGroupNonUniformFAdd>;
896 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addf", WorkOrSub, OpGroupNonUniformFAdd>;
897 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addh", WorkOrSub, OpGroupNonUniformFAdd>;
898 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addd", WorkOrSub, OpGroupNonUniformFAdd>;
899 defm : DemangledGroupBuiltin<"group_clustered_reduce_addf", WorkOrSub, OpGroupNonUniformFAdd>;
900 defm : DemangledGroupBuiltin<"group_clustered_reduce_addh", WorkOrSub, OpGroupNonUniformFAdd>;
901 defm : DemangledGroupBuiltin<"group_clustered_reduce_addd", WorkOrSub, OpGroupNonUniformFAdd>;
902 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformFAdd", 3, 4, OpGroupNonUniformFAdd>;
904 defm : DemangledGroupBuiltin<"group_non_uniform_imul", WorkOrSub, OpGroupNonUniformIMul>;
905 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulu", WorkOrSub, OpGroupNonUniformIMul>;
906 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_muls", WorkOrSub, OpGroupNonUniformIMul>;
907 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulu", WorkOrSub, OpGroupNonUniformIMul>;
908 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_muls", WorkOrSub, OpGroupNonUniformIMul>;
909 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulu", WorkOrSub, OpGroupNonUniformIMul>;
910 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_muls", WorkOrSub, OpGroupNonUniformIMul>;
911 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulu", WorkOrSub, OpGroupNonUniformIMul>;
912 defm : DemangledGroupBuiltin<"group_clustered_reduce_muls", WorkOrSub, OpGroupNonUniformIMul>;
913 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformIMul", 3, 4, OpGroupNonUniformIMul>;
915 defm : DemangledGroupBuiltin<"group_non_uniform_fmul", WorkOrSub, OpGroupNonUniformFMul>;
916 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulf", WorkOrSub, OpGroupNonUniformFMul>;
917 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulh", WorkOrSub, OpGroupNonUniformFMul>;
918 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_muld", WorkOrSub, OpGroupNonUniformFMul>;
919 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulf", WorkOrSub, OpGroupNonUniformFMul>;
920 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulh", WorkOrSub, OpGroupNonUniformFMul>;
921 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_muld", WorkOrSub, OpGroupNonUniformFMul>;
922 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulf", WorkOrSub, OpGroupNonUniformFMul>;
923 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulh", WorkOrSub, OpGroupNonUniformFMul>;
924 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_muld", WorkOrSub, OpGroupNonUniformFMul>;
925 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulf", WorkOrSub, OpGroupNonUniformFMul>;
926 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulh", WorkOrSub, OpGroupNonUniformFMul>;
927 defm : DemangledGroupBuiltin<"group_clustered_reduce_muld", WorkOrSub, OpGroupNonUniformFMul>;
928 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformFMul", 3, 4, OpGroupNonUniformFMul>;
930 defm : DemangledGroupBuiltin<"group_non_uniform_smin", WorkOrSub, OpGroupNonUniformSMin>;
931 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mins", WorkOrSub, OpGroupNonUniformSMin>;
932 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mins", WorkOrSub, OpGroupNonUniformSMin>;
933 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mins", WorkOrSub, OpGroupNonUniformSMin>;
934 defm : DemangledGroupBuiltin<"group_clustered_reduce_mins", WorkOrSub, OpGroupNonUniformSMin>;
935 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformSMin", 3, 4, OpGroupNonUniformSMin>;
937 defm : DemangledGroupBuiltin<"group_non_uniform_umin", WorkOrSub, OpGroupNonUniformUMin>;
938 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minu", WorkOrSub, OpGroupNonUniformUMin>;
939 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minu", WorkOrSub, OpGroupNonUniformUMin>;
940 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minu", WorkOrSub, OpGroupNonUniformUMin>;
941 defm : DemangledGroupBuiltin<"group_clustered_reduce_minu", WorkOrSub, OpGroupNonUniformUMin>;
942 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformUMin", 3, 4, OpGroupNonUniformUMin>;
944 defm : DemangledGroupBuiltin<"group_non_uniform_fmin", WorkOrSub, OpGroupNonUniformFMin>;
945 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minf", WorkOrSub, OpGroupNonUniformFMin>;
946 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minh", WorkOrSub, OpGroupNonUniformFMin>;
947 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mind", WorkOrSub, OpGroupNonUniformFMin>;
948 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minf", WorkOrSub, OpGroupNonUniformFMin>;
949 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minh", WorkOrSub, OpGroupNonUniformFMin>;
950 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mind", WorkOrSub, OpGroupNonUniformFMin>;
951 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minf", WorkOrSub, OpGroupNonUniformFMin>;
952 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minh", WorkOrSub, OpGroupNonUniformFMin>;
953 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mind", WorkOrSub, OpGroupNonUniformFMin>;
954 defm : DemangledGroupBuiltin<"group_clustered_reduce_minf", WorkOrSub, OpGroupNonUniformFMin>;
955 defm : DemangledGroupBuiltin<"group_clustered_reduce_minh", WorkOrSub, OpGroupNonUniformFMin>;
956 defm : DemangledGroupBuiltin<"group_clustered_reduce_mind", WorkOrSub, OpGroupNonUniformFMin>;
957 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformFMin", 3, 4, OpGroupNonUniformFMin>;
959 defm : DemangledGroupBuiltin<"group_non_uniform_smax", WorkOrSub, OpGroupNonUniformSMax>;
960 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxs", WorkOrSub, OpGroupNonUniformSMax>;
961 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxs", WorkOrSub, OpGroupNonUniformSMax>;
962 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxs", WorkOrSub, OpGroupNonUniformSMax>;
963 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxs", WorkOrSub, OpGroupNonUniformSMax>;
964 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformSMax", 3, 4, OpGroupNonUniformSMax>;
966 defm : DemangledGroupBuiltin<"group_non_uniform_umax", WorkOrSub, OpGroupNonUniformUMax>;
967 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxu", WorkOrSub, OpGroupNonUniformUMax>;
968 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxu", WorkOrSub, OpGroupNonUniformUMax>;
969 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxu", WorkOrSub, OpGroupNonUniformUMax>;
970 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxu", WorkOrSub, OpGroupNonUniformUMax>;
971 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformUMax", 3, 4, OpGroupNonUniformUMax>;
973 defm : DemangledGroupBuiltin<"group_non_uniform_fmax", WorkOrSub, OpGroupNonUniformFMax>;
974 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxf", WorkOrSub, OpGroupNonUniformFMax>;
975 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxh", WorkOrSub, OpGroupNonUniformFMax>;
976 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxd", WorkOrSub, OpGroupNonUniformFMax>;
977 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxf", WorkOrSub, OpGroupNonUniformFMax>;
978 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxh", WorkOrSub, OpGroupNonUniformFMax>;
979 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxd", WorkOrSub, OpGroupNonUniformFMax>;
980 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxf", WorkOrSub, OpGroupNonUniformFMax>;
981 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxh", WorkOrSub, OpGroupNonUniformFMax>;
982 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxd", WorkOrSub, OpGroupNonUniformFMax>;
983 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxf", WorkOrSub, OpGroupNonUniformFMax>;
984 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxh", WorkOrSub, OpGroupNonUniformFMax>;
985 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxd", WorkOrSub, OpGroupNonUniformFMax>;
986 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformFMax", 3, 4, OpGroupNonUniformFMax>;
988 defm : DemangledGroupBuiltin<"group_non_uniform_iand", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
989 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
990 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
991 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
992 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
993 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
994 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
995 defm : DemangledGroupBuiltin<"group_clustered_reduce_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
996 defm : DemangledGroupBuiltin<"group_clustered_reduce_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
997 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBitwiseAnd", 3, 4, OpGroupNonUniformBitwiseAnd>;
999 defm : DemangledGroupBuiltin<"group_non_uniform_ior", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1000 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1001 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1002 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1003 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1004 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1005 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1006 defm : DemangledGroupBuiltin<"group_clustered_reduce_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1007 defm : DemangledGroupBuiltin<"group_clustered_reduce_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
1008 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBitwiseOr", 3, 4, OpGroupNonUniformBitwiseOr>;
1010 defm : DemangledGroupBuiltin<"group_non_uniform_ixor", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1011 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1012 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1013 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1014 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1015 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1016 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1017 defm : DemangledGroupBuiltin<"group_clustered_reduce_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1018 defm : DemangledGroupBuiltin<"group_clustered_reduce_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
1019 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformBitwiseXor", 3, 4, OpGroupNonUniformBitwiseXor>;
1021 defm : DemangledGroupBuiltin<"group_non_uniform_logical_iand", WorkOrSub, OpGroupNonUniformLogicalAnd>;
1022 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
1023 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
1024 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
1025 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_and", WorkOrSub, OpGroupNonUniformLogicalAnd>;
1026 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformLogicalAnd", 3, 4, OpGroupNonUniformLogicalAnd>;
1028 defm : DemangledGroupBuiltin<"group_non_uniform_logical_ior", WorkOrSub, OpGroupNonUniformLogicalOr>;
1029 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
1030 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
1031 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
1032 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_or", WorkOrSub, OpGroupNonUniformLogicalOr>;
1033 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformLogicalOr", 3, 4, OpGroupNonUniformLogicalOr>;
1035 defm : DemangledGroupBuiltin<"group_non_uniform_logical_ixor", WorkOrSub, OpGroupNonUniformLogicalXor>;
1036 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
1037 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
1038 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
1039 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_xor", WorkOrSub, OpGroupNonUniformLogicalXor>;
1040 defm : DemangledGroupBuiltinWrapper<"__spirv_GroupNonUniformLogicalXor", 3, 4, OpGroupNonUniformLogicalXor>;
1042 // cl_khr_subgroup_rotate / SPV_KHR_subgroup_rotate
1043 defm : DemangledGroupBuiltin<"group_rotate", OnlySub, OpGroupNonUniformRotateKHR>;
1044 defm : DemangledGroupBuiltin<"group_clustered_rotate", OnlySub, OpGroupNonUniformRotateKHR>;
1046 // cl_khr_work_group_uniform_arithmetic / SPV_KHR_uniform_group_instructions
1047 defm : DemangledGroupBuiltin<"group_reduce_imul", OnlyWork, OpGroupIMulKHR>;
1048 defm : DemangledGroupBuiltin<"group_reduce_mulu", OnlyWork, OpGroupIMulKHR>;
1049 defm : DemangledGroupBuiltin<"group_reduce_muls", OnlyWork, OpGroupIMulKHR>;
1050 defm : DemangledGroupBuiltin<"group_scan_inclusive_imul", OnlyWork, OpGroupIMulKHR>;
1051 defm : DemangledGroupBuiltin<"group_scan_inclusive_mulu", OnlyWork, OpGroupIMulKHR>;
1052 defm : DemangledGroupBuiltin<"group_scan_inclusive_muls", OnlyWork, OpGroupIMulKHR>;
1053 defm : DemangledGroupBuiltin<"group_scan_exclusive_imul", OnlyWork, OpGroupIMulKHR>;
1054 defm : DemangledGroupBuiltin<"group_scan_exclusive_mulu", OnlyWork, OpGroupIMulKHR>;
1055 defm : DemangledGroupBuiltin<"group_scan_exclusive_muls", OnlyWork, OpGroupIMulKHR>;
1057 defm : DemangledGroupBuiltin<"group_reduce_mulf", OnlyWork, OpGroupFMulKHR>;
1058 defm : DemangledGroupBuiltin<"group_reduce_mulh", OnlyWork, OpGroupFMulKHR>;
1059 defm : DemangledGroupBuiltin<"group_reduce_muld", OnlyWork, OpGroupFMulKHR>;
1060 defm : DemangledGroupBuiltin<"group_scan_inclusive_mulf", OnlyWork, OpGroupFMulKHR>;
1061 defm : DemangledGroupBuiltin<"group_scan_inclusive_mulh", OnlyWork, OpGroupFMulKHR>;
1062 defm : DemangledGroupBuiltin<"group_scan_inclusive_muld", OnlyWork, OpGroupFMulKHR>;
1063 defm : DemangledGroupBuiltin<"group_scan_exclusive_mulf", OnlyWork, OpGroupFMulKHR>;
1064 defm : DemangledGroupBuiltin<"group_scan_exclusive_mulh", OnlyWork, OpGroupFMulKHR>;
1065 defm : DemangledGroupBuiltin<"group_scan_exclusive_muld", OnlyWork, OpGroupFMulKHR>;
1067 defm : DemangledGroupBuiltin<"group_scan_exclusive_and", OnlyWork, OpGroupBitwiseAndKHR>;
1068 defm : DemangledGroupBuiltin<"group_scan_inclusive_and", OnlyWork, OpGroupBitwiseAndKHR>;
1069 defm : DemangledGroupBuiltin<"group_reduce_and", OnlyWork, OpGroupBitwiseAndKHR>;
1071 defm : DemangledGroupBuiltin<"group_scan_exclusive_or", OnlyWork, OpGroupBitwiseOrKHR>;
1072 defm : DemangledGroupBuiltin<"group_scan_inclusive_or", OnlyWork, OpGroupBitwiseOrKHR>;
1073 defm : DemangledGroupBuiltin<"group_reduce_or", OnlyWork, OpGroupBitwiseOrKHR>;
1075 defm : DemangledGroupBuiltin<"group_scan_exclusive_xor", OnlyWork, OpGroupBitwiseXorKHR>;
1076 defm : DemangledGroupBuiltin<"group_scan_inclusive_xor", OnlyWork, OpGroupBitwiseXorKHR>;
1077 defm : DemangledGroupBuiltin<"group_reduce_xor", OnlyWork, OpGroupBitwiseXorKHR>;
1079 defm : DemangledGroupBuiltin<"group_scan_exclusive_logical_and", OnlyWork, OpGroupLogicalAndKHR>;
1080 defm : DemangledGroupBuiltin<"group_scan_inclusive_logical_and", OnlyWork, OpGroupLogicalAndKHR>;
1081 defm : DemangledGroupBuiltin<"group_reduce_logical_and", OnlyWork, OpGroupLogicalAndKHR>;
1083 defm : DemangledGroupBuiltin<"group_scan_exclusive_logical_or", OnlyWork, OpGroupLogicalOrKHR>;
1084 defm : DemangledGroupBuiltin<"group_scan_inclusive_logical_or", OnlyWork, OpGroupLogicalOrKHR>;
1085 defm : DemangledGroupBuiltin<"group_reduce_logical_or", OnlyWork, OpGroupLogicalOrKHR>;
1087 defm : DemangledGroupBuiltin<"group_scan_exclusive_logical_xor", OnlyWork, OpGroupLogicalXorKHR>;
1088 defm : DemangledGroupBuiltin<"group_scan_inclusive_logical_xor", OnlyWork, OpGroupLogicalXorKHR>;
1089 defm : DemangledGroupBuiltin<"group_reduce_logical_xor", OnlyWork, OpGroupLogicalXorKHR>;
1091 // cl_khr_kernel_clock / SPV_KHR_shader_clock
1092 defm : DemangledNativeBuiltin<"clock_read_device", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
1093 defm : DemangledNativeBuiltin<"clock_read_work_group", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
1094 defm : DemangledNativeBuiltin<"clock_read_sub_group", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
1095 defm : DemangledNativeBuiltin<"clock_read_hilo_device", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
1096 defm : DemangledNativeBuiltin<"clock_read_hilo_work_group", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
1097 defm : DemangledNativeBuiltin<"clock_read_hilo_sub_group", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
1099 //===----------------------------------------------------------------------===//
1100 // Class defining an atomic instruction on floating-point numbers.
1102 // name is the demangled name of the given builtin.
1103 // opcode specifies the SPIR-V operation code of the generated instruction.
1104 //===----------------------------------------------------------------------===//
1105 class AtomicFloatingBuiltin<string name, Op operation> {
1107 Op Opcode = operation;
1110 // Table gathering all builtins for atomic instructions on floating-point numbers
1111 def AtomicFloatingBuiltins : GenericTable {
1112 let FilterClass = "AtomicFloatingBuiltin";
1113 let Fields = ["Name", "Opcode"];
1116 // Function to lookup builtins by their name and set.
1117 def lookupAtomicFloatingBuiltin : SearchIndex {
1118 let Table = AtomicFloatingBuiltins;
1122 // Multiclass used to define incoming demangled builtin records and
1123 // corresponding builtin records for atomic instructions on floating-point numbers.
1124 multiclass DemangledAtomicFloatingBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
1125 def : DemangledBuiltin<!strconcat("__spirv_AtomicF", name), OpenCL_std, AtomicFloating, minNumArgs, maxNumArgs>;
1126 def : AtomicFloatingBuiltin<!strconcat("__spirv_AtomicF", name), operation>;
1129 // SPV_EXT_shader_atomic_float_add, SPV_EXT_shader_atomic_float_min_max, SPV_EXT_shader_atomic_float16_add
1130 // Atomic add, min and max instruction on floating-point numbers:
1131 defm : DemangledAtomicFloatingBuiltin<"AddEXT", 4, 4, OpAtomicFAddEXT>;
1132 defm : DemangledAtomicFloatingBuiltin<"MinEXT", 4, 4, OpAtomicFMinEXT>;
1133 defm : DemangledAtomicFloatingBuiltin<"MaxEXT", 4, 4, OpAtomicFMaxEXT>;
1135 //===----------------------------------------------------------------------===//
1136 // Class defining a sub group builtin that should be translated into a
1137 // SPIR-V instruction using the SPV_INTEL_subgroups extension.
1139 // name is the demangled name of the given builtin.
1140 // opcode specifies the SPIR-V operation code of the generated instruction.
1141 //===----------------------------------------------------------------------===//
1142 class IntelSubgroupsBuiltin<string name, Op operation> {
1144 Op Opcode = operation;
1145 bit IsBlock = !or(!eq(operation, OpSubgroupBlockReadINTEL),
1146 !eq(operation, OpSubgroupBlockWriteINTEL));
1147 bit IsWrite = !eq(operation, OpSubgroupBlockWriteINTEL);
1150 // Table gathering all the Intel sub group builtins.
1151 def IntelSubgroupsBuiltins : GenericTable {
1152 let FilterClass = "IntelSubgroupsBuiltin";
1153 let Fields = ["Name", "Opcode", "IsBlock", "IsWrite"];
1156 // Function to lookup group builtins by their name and set.
1157 def lookupIntelSubgroupsBuiltin : SearchIndex {
1158 let Table = IntelSubgroupsBuiltins;
1162 // Multiclass used to define incoming builtin records for the SPV_INTEL_subgroups extension
1163 // and corresponding work/sub group builtin records.
1164 multiclass DemangledIntelSubgroupsBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
1165 def : DemangledBuiltin<!strconcat("intel_sub_group_", name), OpenCL_std, IntelSubgroups, minNumArgs, maxNumArgs>;
1166 def : IntelSubgroupsBuiltin<!strconcat("intel_sub_group_", name), operation>;
1169 // cl_intel_subgroups
1170 defm : DemangledIntelSubgroupsBuiltin<"shuffle", 2, 2, OpSubgroupShuffleINTEL>;
1171 defm : DemangledIntelSubgroupsBuiltin<"shuffle_down", 3, 3, OpSubgroupShuffleDownINTEL>;
1172 defm : DemangledIntelSubgroupsBuiltin<"shuffle_up", 3, 3, OpSubgroupShuffleUpINTEL>;
1173 defm : DemangledIntelSubgroupsBuiltin<"shuffle_xor", 2, 2, OpSubgroupShuffleXorINTEL>;
1174 foreach i = ["", "2", "4", "8"] in {
1175 // cl_intel_subgroups
1176 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read", i), 1, 2, OpSubgroupBlockReadINTEL>;
1177 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write", i), 2, 3, OpSubgroupBlockWriteINTEL>;
1178 // cl_intel_subgroups_short
1179 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read_ui", i), 1, 2, OpSubgroupBlockReadINTEL>;
1180 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write_ui", i), 2, 3, OpSubgroupBlockWriteINTEL>;
1182 // cl_intel_subgroups_char, cl_intel_subgroups_short, cl_intel_subgroups_long
1183 foreach i = ["", "2", "4", "8", "16"] in {
1184 foreach j = ["c", "s", "l"] in {
1185 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read_u", j, i), 1, 2, OpSubgroupBlockReadINTEL>;
1186 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write_u", j, i), 2, 3, OpSubgroupBlockWriteINTEL>;
1189 // OpSubgroupImageBlockReadINTEL and OpSubgroupImageBlockWriteINTEL are to be resolved later on (in code)
1191 // Multiclass used to define builtin wrappers for the SPV_INTEL_subgroups extension.
1192 multiclass DemangledIntelSubgroupsBuiltinWrapper<string name, bits<8> numArgs, Op operation> {
1193 def : DemangledBuiltin<!strconcat("__spirv_", name), OpenCL_std, IntelSubgroups, numArgs, numArgs>;
1194 def : IntelSubgroupsBuiltin<!strconcat("__spirv_", name), operation>;
1197 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupShuffleINTEL", 2, OpSubgroupShuffleINTEL>;
1198 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupShuffleDownINTEL", 3, OpSubgroupShuffleDownINTEL>;
1199 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupShuffleUpINTEL", 3, OpSubgroupShuffleUpINTEL>;
1200 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupShuffleXorINTEL", 2, OpSubgroupShuffleXorINTEL>;
1201 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupBlockReadINTEL", 1, OpSubgroupBlockReadINTEL>;
1202 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupBlockWriteINTEL", 2, OpSubgroupBlockWriteINTEL>;
1203 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupImageBlockReadINTEL", 2, OpSubgroupImageBlockReadINTEL>;
1204 defm : DemangledIntelSubgroupsBuiltinWrapper<"SubgroupImageBlockWriteINTEL", 3, OpSubgroupImageBlockWriteINTEL>;
1206 //===----------------------------------------------------------------------===//
1207 // Class defining a builtin for group operations within uniform control flow.
1208 // It should be translated into a SPIR-V instruction using
1209 // the SPV_KHR_uniform_group_instructions extension.
1211 // name is the demangled name of the given builtin.
1212 // opcode specifies the SPIR-V operation code of the generated instruction.
1213 //===----------------------------------------------------------------------===//
1214 class GroupUniformBuiltin<string name, Op operation> {
1216 Op Opcode = operation;
1217 bit IsLogical = !or(!eq(operation, OpGroupLogicalAndKHR),
1218 !eq(operation, OpGroupLogicalOrKHR),
1219 !eq(operation, OpGroupLogicalXorKHR));
1222 // Table gathering all the Intel sub group builtins.
1223 def GroupUniformBuiltins : GenericTable {
1224 let FilterClass = "GroupUniformBuiltin";
1225 let Fields = ["Name", "Opcode", "IsLogical"];
1228 // Function to lookup group builtins by their name and set.
1229 def lookupGroupUniformBuiltin : SearchIndex {
1230 let Table = GroupUniformBuiltins;
1234 // Multiclass used to define incoming builtin records for
1235 // the SPV_KHR_uniform_group_instructions extension
1236 // and corresponding work group builtin records.
1237 multiclass DemangledGroupUniformBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
1238 def : DemangledBuiltin<!strconcat("__spirv_Group", name), OpenCL_std, GroupUniform, minNumArgs, maxNumArgs>;
1239 def : GroupUniformBuiltin<!strconcat("__spirv_Group", name), operation>;
1242 // cl_khr_work_group_uniform_arithmetic / SPV_KHR_uniform_group_instructions
1243 defm : DemangledGroupUniformBuiltin<"IMulKHR", 3, 3, OpGroupIMulKHR>;
1244 defm : DemangledGroupUniformBuiltin<"FMulKHR", 3, 3, OpGroupFMulKHR>;
1245 defm : DemangledGroupUniformBuiltin<"BitwiseAndKHR", 3, 3, OpGroupBitwiseAndKHR>;
1246 defm : DemangledGroupUniformBuiltin<"BitwiseOrKHR", 3, 3, OpGroupBitwiseOrKHR>;
1247 defm : DemangledGroupUniformBuiltin<"BitwiseXorKHR", 3, 3, OpGroupBitwiseXorKHR>;
1248 defm : DemangledGroupUniformBuiltin<"LogicalAndKHR", 3, 3, OpGroupLogicalAndKHR>;
1249 defm : DemangledGroupUniformBuiltin<"LogicalOrKHR", 3, 3, OpGroupLogicalOrKHR>;
1250 defm : DemangledGroupUniformBuiltin<"LogicalXorKHR", 3, 3, OpGroupLogicalXorKHR>;
1252 //===----------------------------------------------------------------------===//
1253 // Class defining a get builtin record used for lowering builtin calls such as
1254 // "get_sub_group_eq_mask" or "get_global_id" to SPIR-V instructions.
1256 // name is the demangled name of the given builtin.
1257 // set specifies which external instruction set the builtin belongs to.
1258 // value specifies the value of the BuiltIn enum.
1259 //===----------------------------------------------------------------------===//
1260 class GetBuiltin<string name, InstructionSet set, BuiltIn value> {
1262 InstructionSet Set = set;
1263 BuiltIn Value = value;
1266 // Table gathering all the get builtin records.
1267 def GetBuiltins : GenericTable {
1268 let FilterClass = "GetBuiltin";
1269 let Fields = ["Name", "Set", "Value"];
1270 string TypeOf_Set = "InstructionSet";
1271 string TypeOf_Value = "BuiltIn";
1274 // Function to lookup get builtin records by their name and set.
1275 def lookupGetBuiltin : SearchIndex {
1276 let Table = GetBuiltins;
1277 let Key = ["Name", "Set"];
1280 // Multiclass used to define at the same time both a demangled builtin record
1281 // and a corresponding get builtin record.
1282 multiclass DemangledGetBuiltin<string name, InstructionSet set, BuiltinGroup group, BuiltIn value> {
1283 def : DemangledBuiltin<name, set, group, 0, 1>;
1284 def : GetBuiltin<name, set, value>;
1287 // Builtin variable records:
1288 defm : DemangledGetBuiltin<"get_sub_group_eq_mask", OpenCL_std, Variable, SubgroupEqMask>;
1289 defm : DemangledGetBuiltin<"get_sub_group_ge_mask", OpenCL_std, Variable, SubgroupGeMask>;
1290 defm : DemangledGetBuiltin<"get_sub_group_gt_mask", OpenCL_std, Variable, SubgroupGtMask>;
1291 defm : DemangledGetBuiltin<"get_sub_group_le_mask", OpenCL_std, Variable, SubgroupLeMask>;
1292 defm : DemangledGetBuiltin<"get_sub_group_lt_mask", OpenCL_std, Variable, SubgroupLtMask>;
1293 defm : DemangledGetBuiltin<"__spirv_BuiltInGlobalLinearId", OpenCL_std, Variable, GlobalLinearId>;
1294 defm : DemangledGetBuiltin<"__spirv_BuiltInGlobalInvocationId", OpenCL_std, Variable, GlobalInvocationId>;
1296 // GetQuery builtin records:
1297 defm : DemangledGetBuiltin<"get_local_id", OpenCL_std, GetQuery, LocalInvocationId>;
1298 defm : DemangledGetBuiltin<"get_global_id", OpenCL_std, GetQuery, GlobalInvocationId>;
1299 defm : DemangledGetBuiltin<"get_local_size", OpenCL_std, GetQuery, WorkgroupSize>;
1300 defm : DemangledGetBuiltin<"get_global_size", OpenCL_std, GetQuery, GlobalSize>;
1301 defm : DemangledGetBuiltin<"get_group_id", OpenCL_std, GetQuery, WorkgroupId>;
1302 defm : DemangledGetBuiltin<"get_enqueued_local_size", OpenCL_std, GetQuery, EnqueuedWorkgroupSize>;
1303 defm : DemangledGetBuiltin<"get_num_groups", OpenCL_std, GetQuery, NumWorkgroups>;
1304 defm : DemangledGetBuiltin<"__hlsl_wave_get_lane_index", GLSL_std_450, Wave, SubgroupLocalInvocationId>;
1306 //===----------------------------------------------------------------------===//
1307 // Class defining an image query builtin record used for lowering the OpenCL
1308 // "get_image_*" calls into OpImageQuerySize/OpImageQuerySizeLod instructions.
1310 // name is the demangled name of the given builtin.
1311 // set specifies which external instruction set the builtin belongs to.
1312 // component specifies the unsigned number of the query component.
1313 //===----------------------------------------------------------------------===//
1314 class ImageQueryBuiltin<string name, InstructionSet set, bits<32> component> {
1316 InstructionSet Set = set;
1317 bits<32> Component = component;
1320 // Table gathering all the image query builtins.
1321 def ImageQueryBuiltins : GenericTable {
1322 let FilterClass = "ImageQueryBuiltin";
1323 let Fields = ["Name", "Set", "Component"];
1324 string TypeOf_Set = "InstructionSet";
1327 // Function to lookup image query builtins by their name and set.
1328 def lookupImageQueryBuiltin : SearchIndex {
1329 let Table = ImageQueryBuiltins;
1330 let Key = ["Name", "Set"];
1333 // Multiclass used to define at the same time both a demangled builtin record
1334 // and a corresponding image query builtin record.
1335 multiclass DemangledImageQueryBuiltin<string name, InstructionSet set, int component> {
1336 def : DemangledBuiltin<name, set, ImageSizeQuery, 1, 1>;
1337 def : ImageQueryBuiltin<name, set, component>;
1340 // Image query builtin records:
1341 defm : DemangledImageQueryBuiltin<"get_image_width", OpenCL_std, 0>;
1342 defm : DemangledImageQueryBuiltin<"get_image_height", OpenCL_std, 1>;
1343 defm : DemangledImageQueryBuiltin<"get_image_depth", OpenCL_std, 2>;
1344 defm : DemangledImageQueryBuiltin<"get_image_dim", OpenCL_std, 0>;
1345 defm : DemangledImageQueryBuiltin<"get_image_array_size", OpenCL_std, 3>;
1347 defm : DemangledNativeBuiltin<"get_image_num_samples", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQuerySamples>;
1348 defm : DemangledNativeBuiltin<"get_image_num_mip_levels", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQueryLevels>;
1350 //===----------------------------------------------------------------------===//
1351 // Class defining a "convert_destType<_sat><_roundingMode>" call record for
1352 // lowering into OpConvert instructions.
1354 // name is the demangled name of the given builtin.
1355 // set specifies which external instruction set the builtin belongs to.
1356 //===----------------------------------------------------------------------===//
1357 class ConvertBuiltin<string name, InstructionSet set> {
1359 InstructionSet Set = set;
1360 bit IsDestinationSigned = !eq(!find(name, "convert_u"), -1);
1361 bit IsSaturated = !not(!eq(!find(name, "_sat"), -1));
1362 bit IsRounded = !not(!eq(!find(name, "_rt"), -1));
1363 bit IsBfloat16 = !or(!not(!eq(!find(name, "BF16"), -1)),
1364 !not(!eq(!find(name, "bfloat16"), -1)));
1365 FPRoundingMode RoundingMode = !cond(!not(!eq(!find(name, "_rte"), -1)) : RTE,
1366 !not(!eq(!find(name, "_rtz"), -1)) : RTZ,
1367 !not(!eq(!find(name, "_rtp"), -1)) : RTP,
1368 !not(!eq(!find(name, "_rtn"), -1)) : RTN,
1372 // Table gathering all the convert builtins.
1373 def ConvertBuiltins : GenericTable {
1374 let FilterClass = "ConvertBuiltin";
1375 let Fields = ["Name", "Set", "IsDestinationSigned", "IsSaturated",
1376 "IsRounded", "IsBfloat16", "RoundingMode"];
1377 string TypeOf_Set = "InstructionSet";
1378 string TypeOf_RoundingMode = "FPRoundingMode";
1381 // Function to lookup convert builtins by their name and set.
1382 def lookupConvertBuiltin : SearchIndex {
1383 let Table = ConvertBuiltins;
1384 let Key = ["Name", "Set"];
1387 // Multiclass used to define at the same time both a demangled builtin records
1388 // and a corresponding convert builtin records.
1389 multiclass DemangledConvertBuiltin<string name, InstructionSet set> {
1390 // Create records for scalar and 2, 4, 8, and 16 element vector conversions.
1391 foreach i = ["", "2", "3", "4", "8", "16"] in {
1392 // Also create records for each rounding mode.
1393 foreach j = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
1394 def : DemangledBuiltin<!strconcat(name, i, j), set, Convert, 1, 1>;
1395 def : ConvertBuiltin<!strconcat(name, i, j), set>;
1397 // Create records with the "_sat" modifier for all conversions except
1398 // those targeting floating-point types.
1399 if !eq(!find(name, "float"), -1) then {
1400 def : DemangledBuiltin<!strconcat(name, i, "_sat", j), set, Convert, 1, 1>;
1401 def : ConvertBuiltin<!strconcat(name, i, "_sat", j), set>;
1407 // Explicit conversion builtin records:
1408 defm : DemangledConvertBuiltin<"convert_char", OpenCL_std>;
1409 defm : DemangledConvertBuiltin<"convert_uchar", OpenCL_std>;
1410 defm : DemangledConvertBuiltin<"convert_short", OpenCL_std>;
1411 defm : DemangledConvertBuiltin<"convert_ushort", OpenCL_std>;
1412 defm : DemangledConvertBuiltin<"convert_int", OpenCL_std>;
1413 defm : DemangledConvertBuiltin<"convert_uint", OpenCL_std>;
1414 defm : DemangledConvertBuiltin<"convert_long", OpenCL_std>;
1415 defm : DemangledConvertBuiltin<"convert_ulong", OpenCL_std>;
1416 defm : DemangledConvertBuiltin<"convert_float", OpenCL_std>;
1418 defm : DemangledNativeBuiltin<"__spirv_ConvertFToU", OpenCL_std, Convert, 1, 1, OpConvertFToU>;
1419 defm : DemangledNativeBuiltin<"__spirv_ConvertFToS", OpenCL_std, Convert, 1, 1, OpConvertFToS>;
1420 defm : DemangledNativeBuiltin<"__spirv_ConvertSToF", OpenCL_std, Convert, 1, 1, OpConvertSToF>;
1421 defm : DemangledNativeBuiltin<"__spirv_ConvertUToF", OpenCL_std, Convert, 1, 1, OpConvertUToF>;
1422 defm : DemangledNativeBuiltin<"__spirv_UConvert", OpenCL_std, Convert, 1, 1, OpUConvert>;
1423 defm : DemangledNativeBuiltin<"__spirv_SConvert", OpenCL_std, Convert, 1, 1, OpSConvert>;
1424 defm : DemangledNativeBuiltin<"__spirv_FConvert", OpenCL_std, Convert, 1, 1, OpFConvert>;
1425 defm : DemangledNativeBuiltin<"__spirv_QuantizeToF16", OpenCL_std, Convert, 1, 1, OpQuantizeToF16>;
1426 defm : DemangledNativeBuiltin<"__spirv_ConvertPtrToU", OpenCL_std, Convert, 1, 1, OpConvertPtrToU>;
1427 defm : DemangledNativeBuiltin<"__spirv_SatConvertSToU", OpenCL_std, Convert, 1, 1, OpSatConvertSToU>;
1428 defm : DemangledNativeBuiltin<"__spirv_SatConvertUToS", OpenCL_std, Convert, 1, 1, OpSatConvertUToS>;
1429 defm : DemangledNativeBuiltin<"__spirv_ConvertUToPtr", OpenCL_std, Convert, 1, 1, OpConvertUToPtr>;
1431 // cl_intel_bfloat16_conversions / SPV_INTEL_bfloat16_conversion
1432 // Multiclass used to define at the same time both a demangled builtin records
1433 // and a corresponding convert builtin records.
1434 multiclass DemangledBF16ConvertBuiltin<string name1, string name2> {
1435 // Create records for scalar and vector conversions.
1436 foreach i = ["", "2", "3", "4", "8", "16"] in {
1437 def : DemangledBuiltin<!strconcat("intel_convert_", name1, i, name2, i), OpenCL_std, Convert, 1, 1>;
1438 def : ConvertBuiltin<!strconcat("intel_convert_", name1, i, name2, i), OpenCL_std>;
1442 defm : DemangledBF16ConvertBuiltin<"bfloat16", "_as_ushort">;
1443 defm : DemangledBF16ConvertBuiltin<"as_bfloat16", "_float">;
1445 foreach conv = ["FToBF16INTEL", "BF16ToFINTEL"] in {
1446 def : DemangledBuiltin<!strconcat("__spirv_Convert", conv), OpenCL_std, Convert, 1, 1>;
1447 def : ConvertBuiltin<!strconcat("__spirv_Convert", conv), OpenCL_std>;
1450 //===----------------------------------------------------------------------===//
1451 // Class defining a vector data load/store builtin record used for lowering
1452 // into OpExtInst instruction.
1454 // name is the demangled name of the given builtin.
1455 // set specifies which external instruction set the builtin belongs to.
1456 // number specifies the number of the instruction in the external set.
1457 //===----------------------------------------------------------------------===//
1458 class VectorLoadStoreBuiltin<string name, InstructionSet set, int number> {
1460 InstructionSet Set = set;
1461 bits<32> Number = number;
1462 bits<32> ElementCount = !cond(!not(!eq(!find(name, "2"), -1)) : 2,
1463 !not(!eq(!find(name, "3"), -1)) : 3,
1464 !not(!eq(!find(name, "4"), -1)) : 4,
1465 !not(!eq(!find(name, "8"), -1)) : 8,
1466 !not(!eq(!find(name, "16"), -1)) : 16,
1468 bit IsRounded = !not(!eq(!find(name, "_rt"), -1));
1469 FPRoundingMode RoundingMode = !cond(!not(!eq(!find(name, "_rte"), -1)) : RTE,
1470 !not(!eq(!find(name, "_rtz"), -1)) : RTZ,
1471 !not(!eq(!find(name, "_rtp"), -1)) : RTP,
1472 !not(!eq(!find(name, "_rtn"), -1)) : RTN,
1476 // Table gathering all the vector data load/store builtins.
1477 def VectorLoadStoreBuiltins : GenericTable {
1478 let FilterClass = "VectorLoadStoreBuiltin";
1479 let Fields = ["Name", "Set", "Number", "ElementCount", "IsRounded", "RoundingMode"];
1480 string TypeOf_Set = "InstructionSet";
1481 string TypeOf_RoundingMode = "FPRoundingMode";
1484 // Function to lookup vector data load/store builtins by their name and set.
1485 def lookupVectorLoadStoreBuiltin : SearchIndex {
1486 let Table = VectorLoadStoreBuiltins;
1487 let Key = ["Name", "Set"];
1490 // Multiclass used to define at the same time both a demangled builtin record
1491 // and a corresponding vector data load/store builtin record.
1492 multiclass DemangledVectorLoadStoreBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, int number> {
1493 def : DemangledBuiltin<name, OpenCL_std, VectorLoadStore, minNumArgs, maxNumArgs>;
1494 def : VectorLoadStoreBuiltin<name, OpenCL_std, number>;
1497 // Create records for scalar and 2, 4, 8, and 16 vector element count.
1498 foreach i = ["", "2", "3", "4", "8", "16"] in {
1499 if !eq(i, "") then {
1500 defm : DemangledVectorLoadStoreBuiltin<"vload_half", 2, 2, 173>;
1501 defm : DemangledVectorLoadStoreBuiltin<"vstore_half", 3, 3, 175>;
1503 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload_half", i), 3, 3, 174>;
1504 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i), 3, 3, 177>;
1506 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload", i), 2, 2, 171>;
1507 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore", i), 3, 3, 172>;
1508 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vloada_half", i), 2, 2, 174>;
1509 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstorea_half", i), 3, 3, 180>;
1511 // Also create records for each rounding mode.
1512 foreach j = ["_rte", "_rtz", "_rtp", "_rtn"] in {
1513 if !eq(i, "") then {
1514 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", j), 3, 3, 176>;
1516 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i, j), 3, 3, 178>;
1518 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstorea_half", i, j), 3, 3, 181>;
1522 //===----------------------------------------------------------------------===//
1523 // Class defining implementation details of SPIR-V builtin types. The info
1524 // in the record is used for lowering into OpType.
1526 // name is the name of the given SPIR-V builtin type.
1527 // operation specifies the SPIR-V opcode the StructType should be lowered to.
1528 //===----------------------------------------------------------------------===//
1529 class BuiltinType<string name, Op operation> {
1531 Op Opcode = operation;
1534 // Table gathering all the builtin type records.
1535 def BuiltinTypes : GenericTable {
1536 let FilterClass = "BuiltinType";
1537 let Fields = ["Name", "Opcode"];
1540 // Function to lookup builtin types by their demangled name.
1541 def lookupBuiltinType : SearchIndex {
1542 let Table = BuiltinTypes;
1546 def : BuiltinType<"spirv.ReserveId", OpTypeReserveId>;
1547 def : BuiltinType<"spirv.PipeStorage", OpTypePipeStorage>;
1548 def : BuiltinType<"spirv.Queue", OpTypeQueue>;
1549 def : BuiltinType<"spirv.Event", OpTypeEvent>;
1550 def : BuiltinType<"spirv.Sampler", OpTypeSampler>;
1551 def : BuiltinType<"spirv.DeviceEvent", OpTypeDeviceEvent>;
1552 def : BuiltinType<"spirv.Image", OpTypeImage>;
1553 def : BuiltinType<"spirv.SampledImage", OpTypeSampledImage>;
1554 def : BuiltinType<"spirv.Pipe", OpTypePipe>;
1555 def : BuiltinType<"spirv.CooperativeMatrixKHR", OpTypeCooperativeMatrixKHR>;
1557 //===----------------------------------------------------------------------===//
1558 // Class matching an OpenCL builtin type name to an equivalent SPIR-V
1559 // builtin type literal.
1561 // name is the name of the given OpenCL builtin type.
1562 // spirvTypeLiteral is the literal of an equivalent SPIR-V builtin type.
1563 //===----------------------------------------------------------------------===//
1564 class OpenCLType<string name, string spirvTypeLiteral> {
1566 string SpirvTypeLiteral = spirvTypeLiteral;
1569 // Table gathering all the OpenCL type records.
1570 def OpenCLTypes : GenericTable {
1571 let FilterClass = "OpenCLType";
1572 let Fields = ["Name", "SpirvTypeLiteral"];
1575 // Function to lookup OpenCL types by their name.
1576 def lookupOpenCLType : SearchIndex {
1577 let Table = OpenCLTypes;
1581 def : OpenCLType<"opencl.reserve_id_t", "spirv.ReserveId">;
1582 def : OpenCLType<"opencl.event_t", "spirv.Event">;
1583 def : OpenCLType<"opencl.queue_t", "spirv.Queue">;
1584 def : OpenCLType<"opencl.sampler_t", "spirv.Sampler">;
1585 def : OpenCLType<"opencl.clk_event_t", "spirv.DeviceEvent">;
1587 foreach aq = ["_t", "_ro_t", "_wo_t", "_rw_t"] in {
1588 defvar p = !cond(!not(!eq(!find(aq, "_rw_t"), -1)) : "2",
1589 !not(!eq(!find(aq, "_wo_t"), -1)) : "1",
1591 def : OpenCLType<!strconcat("opencl.pipe", aq),
1592 !strconcat("spirv.Pipe._", p)>;
1595 foreach aq = ["_t", "_ro_t", "_wo_t", "_rw_t"] in {
1596 defvar p7 = !cond(!not(!eq(!find(aq, "_rw_t"), -1)) : "2",
1597 !not(!eq(!find(aq, "_wo_t"), -1)) : "1",
1600 def : OpenCLType<!strconcat("opencl.image1d", aq),
1601 !strconcat("spirv.Image._void_0_0_0_0_0_0_", p7)>;
1602 def : OpenCLType<!strconcat("opencl.image1d_array", aq),
1603 !strconcat("spirv.Image._void_0_0_1_0_0_0_", p7)>;
1604 def : OpenCLType<!strconcat("opencl.image1d_buffer", aq),
1605 !strconcat("spirv.Image._void_5_0_0_0_0_0_", p7)>;
1607 foreach a1 = ["", "_array"] in {
1608 foreach a2 = ["", "_msaa"] in {
1609 foreach a3 = ["", "_depth"] in {
1610 defvar p2 = !cond(!not(!eq(!find(a3, "_depth"), -1)) : "1", true : "0");
1611 defvar p3 = !cond(!not(!eq(!find(a1, "_array"), -1)) : "1", true : "0");
1612 defvar p4 = !cond(!not(!eq(!find(a2, "msaa"), -1)) : "1", true : "0");
1614 def : OpenCLType<!strconcat("opencl.image2d", a1, a2, a3, aq),
1615 !strconcat("spirv.Image._void_1_", p2 , "_", p3, "_", p4, "_0_0_", p7)>;
1620 def : OpenCLType<!strconcat("opencl.image3d", aq),
1621 !strconcat("spirv.Image._void_2_0_0_0_0_0_", p7)>;
1624 //===----------------------------------------------------------------------===//
1625 // Classes definining various OpenCL enums.
1626 //===----------------------------------------------------------------------===//
1628 // OpenCL memory_scope enum
1629 def CLMemoryScope : GenericEnum {
1630 let FilterClass = "CLMemoryScope";
1631 let NameField = "Name";
1632 let ValueField = "Value";
1635 class CLMemoryScope<bits<32> value> {
1637 bits<32> Value = value;
1640 def memory_scope_work_item : CLMemoryScope<0>;
1641 def memory_scope_work_group : CLMemoryScope<1>;
1642 def memory_scope_device : CLMemoryScope<2>;
1643 def memory_scope_all_svm_devices : CLMemoryScope<3>;
1644 def memory_scope_sub_group : CLMemoryScope<4>;
1646 // OpenCL sampler addressing mode/bitmask enum
1647 def CLSamplerAddressingMode : GenericEnum {
1648 let FilterClass = "CLSamplerAddressingMode";
1649 let NameField = "Name";
1650 let ValueField = "Value";
1653 class CLSamplerAddressingMode<bits<32> value> {
1655 bits<32> Value = value;
1658 def CLK_ADDRESS_NONE : CLSamplerAddressingMode<0x0>;
1659 def CLK_ADDRESS_CLAMP : CLSamplerAddressingMode<0x4>;
1660 def CLK_ADDRESS_CLAMP_TO_EDGE : CLSamplerAddressingMode<0x2>;
1661 def CLK_ADDRESS_REPEAT : CLSamplerAddressingMode<0x6>;
1662 def CLK_ADDRESS_MIRRORED_REPEAT : CLSamplerAddressingMode<0x8>;
1663 def CLK_ADDRESS_MODE_MASK : CLSamplerAddressingMode<0xE>;
1664 def CLK_NORMALIZED_COORDS_FALSE : CLSamplerAddressingMode<0x0>;
1665 def CLK_NORMALIZED_COORDS_TRUE : CLSamplerAddressingMode<0x1>;
1666 def CLK_FILTER_NEAREST : CLSamplerAddressingMode<0x10>;
1667 def CLK_FILTER_LINEAR : CLSamplerAddressingMode<0x20>;
1669 // OpenCL memory fences
1670 def CLMemoryFenceFlags : GenericEnum {
1671 let FilterClass = "CLMemoryFenceFlags";
1672 let NameField = "Name";
1673 let ValueField = "Value";
1676 class CLMemoryFenceFlags<bits<32> value> {
1678 bits<32> Value = value;
1681 def CLK_LOCAL_MEM_FENCE : CLMemoryFenceFlags<0x1>;
1682 def CLK_GLOBAL_MEM_FENCE : CLMemoryFenceFlags<0x2>;
1683 def CLK_IMAGE_MEM_FENCE : CLMemoryFenceFlags<0x4>;