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