[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / lib / Target / SPIRV / SPIRVBuiltins.td
blob8acd4691787e4c6fb49b958f4d81ea4863c70000
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>;
30 // Define various builtin groups
31 def BuiltinGroup : GenericEnum {
32   let FilterClass = "BuiltinGroup";
35 class BuiltinGroup;
37 def Extended : BuiltinGroup;
38 def Relational : BuiltinGroup;
39 def Group : BuiltinGroup;
40 def Variable : BuiltinGroup;
41 def Atomic : BuiltinGroup;
42 def Barrier : BuiltinGroup;
43 def Dot : BuiltinGroup;
44 def GetQuery : BuiltinGroup;
45 def ImageSizeQuery : BuiltinGroup;
46 def ImageMiscQuery : BuiltinGroup;
47 def Convert : BuiltinGroup;
48 def ReadImage : BuiltinGroup;
49 def WriteImage : BuiltinGroup;
50 def SampleImage : BuiltinGroup;
51 def Select : BuiltinGroup;
52 def SpecConstant : BuiltinGroup;
53 def Enqueue : BuiltinGroup;
54 def AsyncCopy : BuiltinGroup;
55 def VectorLoadStore : BuiltinGroup;
56 def LoadStore : BuiltinGroup;
58 //===----------------------------------------------------------------------===//
59 // Class defining a demangled builtin record. The information in the record
60 // should be used to expand the builtin into either native SPIR-V instructions
61 // or an external call (in case of builtins without a direct mapping).
63 // name is the demangled name of the given builtin.
64 // set specifies which external instruction set the builtin belongs to.
65 // group specifies to which implementation group given record belongs.
66 // minNumArgs is the minimum required number of arguments for lowering.
67 // maxNumArgs specifies the maximum used number of arguments for lowering.
68 //===----------------------------------------------------------------------===//
69 class DemangledBuiltin<string name, InstructionSet set, BuiltinGroup group, bits<8> minNumArgs, bits<8> maxNumArgs> {
70   string Name = name;
71   InstructionSet Set = set;
72   BuiltinGroup Group = group;
73   bits<8> MinNumArgs = minNumArgs;
74   bits<8> MaxNumArgs = maxNumArgs;
77 // Table gathering all the builtins.
78 def DemangledBuiltins : GenericTable {
79   let FilterClass = "DemangledBuiltin";
80   let Fields = ["Name", "Set", "Group", "MinNumArgs", "MaxNumArgs"];
81   string TypeOf_Set = "InstructionSet";
82   string TypeOf_Group = "BuiltinGroup";
85 // Function to lookup builtins by their demangled name and set.
86 def lookupBuiltin : SearchIndex {
87   let Table = DemangledBuiltins;
88   let Key = ["Name", "Set"];
91 // Dot builtin record:
92 def : DemangledBuiltin<"dot", OpenCL_std, Dot, 2, 2>;
94 // Image builtin records:
95 def : DemangledBuiltin<"read_imagei", OpenCL_std, ReadImage, 2, 4>;
96 def : DemangledBuiltin<"read_imageui", OpenCL_std, ReadImage, 2, 4>;
97 def : DemangledBuiltin<"read_imagef", OpenCL_std, ReadImage, 2, 4>;
99 def : DemangledBuiltin<"write_imagef", OpenCL_std, WriteImage, 3, 4>;
100 def : DemangledBuiltin<"write_imagei", OpenCL_std, WriteImage, 3, 4>;
101 def : DemangledBuiltin<"write_imageui", OpenCL_std, WriteImage, 3, 4>;
102 def : DemangledBuiltin<"write_imageh", OpenCL_std, WriteImage, 3, 4>;
104 def : DemangledBuiltin<"__translate_sampler_initializer", OpenCL_std, SampleImage, 1, 1>;
105 def : DemangledBuiltin<"__spirv_SampledImage", OpenCL_std, SampleImage, 2, 2>;
106 def : DemangledBuiltin<"__spirv_ImageSampleExplicitLod", OpenCL_std, SampleImage, 3, 4>;
108 // Select builtin record:
109 def : DemangledBuiltin<"__spirv_Select", OpenCL_std, Select, 3, 3>;
111 //===----------------------------------------------------------------------===//
112 // Class defining an extended builtin record used for lowering into an
113 // OpExtInst instruction.
115 // name is the demangled name of the given builtin.
116 // set specifies which external instruction set the builtin belongs to.
117 // number specifies the number of the instruction in the external set.
118 //===----------------------------------------------------------------------===//
119 class ExtendedBuiltin<string name, InstructionSet set, int number> {
120   string Name = name;
121   InstructionSet Set = set;
122   bits<32> Number = number;
125 // Table gathering all the extended builtins.
126 def ExtendedBuiltins : GenericTable {
127   let FilterClass = "ExtendedBuiltin";
128   let Fields = ["Name", "Set", "Number"];
129   string TypeOf_Set = "InstructionSet";
132 // Function to lookup extended builtins by their name and set.
133 def lookupExtendedBuiltin : SearchIndex {
134   let Table = ExtendedBuiltins;
135   let Key = ["Name", "Set"];
138 // Function to lookup extended builtins by their set and number.
139 def lookupExtendedBuiltinBySetAndNumber : SearchIndex {
140   let Table = ExtendedBuiltins;
141   let Key = ["Set", "Number"];
144 // OpenCL extended instruction enums
145 def OpenCLExtInst : GenericEnum {
146   let FilterClass = "OpenCLExtInst";
147   let NameField = "Name";
148   let ValueField = "Value";
151 class OpenCLExtInst<string name, bits<32> value> {
152   string Name = name;
153   bits<32> Value = value;
156 // GLSL extended instruction enums
157 def GLSLExtInst : GenericEnum {
158   let FilterClass = "GLSLExtInst";
159   let NameField = "Name";
160   let ValueField = "Value";
163 class GLSLExtInst<string name, bits<32> value> {
164   string Name = name;
165   bits<32> Value = value;
168 // Multiclass used to define at the same time both a demangled builtin record
169 // and a corresponding extended builtin record.
170 multiclass DemangledExtendedBuiltin<string name, InstructionSet set, int number> {
171   def : DemangledBuiltin<name, set, Extended, 1, 3>;
172   def : ExtendedBuiltin<name, set, number>;
174   if !eq(set, OpenCL_std) then {
175     def : OpenCLExtInst<name, number>;
176   }
178   if !eq(set, GLSL_std_450) then {
179     def : GLSLExtInst<name, number>;
180   }
183 // Extended builtin records:
184 defm : DemangledExtendedBuiltin<"acos", OpenCL_std, 0>;
185 defm : DemangledExtendedBuiltin<"acosh", OpenCL_std, 1>;
186 defm : DemangledExtendedBuiltin<"acospi", OpenCL_std, 2>;
187 defm : DemangledExtendedBuiltin<"asin", OpenCL_std, 3>;
188 defm : DemangledExtendedBuiltin<"asinh", OpenCL_std, 4>;
189 defm : DemangledExtendedBuiltin<"asinpi", OpenCL_std, 5>;
190 defm : DemangledExtendedBuiltin<"atan", OpenCL_std, 6>;
191 defm : DemangledExtendedBuiltin<"atan2", OpenCL_std, 7>;
192 defm : DemangledExtendedBuiltin<"atanh", OpenCL_std, 8>;
193 defm : DemangledExtendedBuiltin<"atanpi", OpenCL_std, 9>;
194 defm : DemangledExtendedBuiltin<"atan2pi", OpenCL_std, 10>;
195 defm : DemangledExtendedBuiltin<"cbrt", OpenCL_std, 11>;
196 defm : DemangledExtendedBuiltin<"ceil", OpenCL_std, 12>;
197 defm : DemangledExtendedBuiltin<"copysign", OpenCL_std, 13>;
198 defm : DemangledExtendedBuiltin<"cos", OpenCL_std, 14>;
199 defm : DemangledExtendedBuiltin<"cosh", OpenCL_std, 15>;
200 defm : DemangledExtendedBuiltin<"cospi", OpenCL_std, 16>;
201 defm : DemangledExtendedBuiltin<"erfc", OpenCL_std, 17>;
202 defm : DemangledExtendedBuiltin<"erf", OpenCL_std, 18>;
203 defm : DemangledExtendedBuiltin<"exp", OpenCL_std, 19>;
204 defm : DemangledExtendedBuiltin<"exp2", OpenCL_std, 20>;
205 defm : DemangledExtendedBuiltin<"exp10", OpenCL_std, 21>;
206 defm : DemangledExtendedBuiltin<"expm1", OpenCL_std, 22>;
207 defm : DemangledExtendedBuiltin<"fabs", OpenCL_std, 23>;
208 defm : DemangledExtendedBuiltin<"fdim", OpenCL_std, 24>;
209 defm : DemangledExtendedBuiltin<"floor", OpenCL_std, 25>;
210 defm : DemangledExtendedBuiltin<"fma", OpenCL_std, 26>;
211 defm : DemangledExtendedBuiltin<"fmax", OpenCL_std, 27>;
212 defm : DemangledExtendedBuiltin<"fmin", OpenCL_std, 28>;
213 defm : DemangledExtendedBuiltin<"fmod", OpenCL_std, 29>;
214 defm : DemangledExtendedBuiltin<"fract", OpenCL_std, 30>;
215 defm : DemangledExtendedBuiltin<"frexp", OpenCL_std, 31>;
216 defm : DemangledExtendedBuiltin<"hypot", OpenCL_std, 32>;
217 defm : DemangledExtendedBuiltin<"ilogb", OpenCL_std, 33>;
218 defm : DemangledExtendedBuiltin<"ldexp", OpenCL_std, 34>;
219 defm : DemangledExtendedBuiltin<"lgamma", OpenCL_std, 35>;
220 defm : DemangledExtendedBuiltin<"lgamma_r", OpenCL_std, 36>;
221 defm : DemangledExtendedBuiltin<"log", OpenCL_std, 37>;
222 defm : DemangledExtendedBuiltin<"log2", OpenCL_std, 38>;
223 defm : DemangledExtendedBuiltin<"log10", OpenCL_std, 39>;
224 defm : DemangledExtendedBuiltin<"log1p", OpenCL_std, 40>;
225 defm : DemangledExtendedBuiltin<"logb", OpenCL_std, 41>;
226 defm : DemangledExtendedBuiltin<"mad", OpenCL_std, 42>;
227 defm : DemangledExtendedBuiltin<"maxmag", OpenCL_std, 43>;
228 defm : DemangledExtendedBuiltin<"minmag", OpenCL_std, 44>;
229 defm : DemangledExtendedBuiltin<"modf", OpenCL_std, 45>;
230 defm : DemangledExtendedBuiltin<"nan", OpenCL_std, 46>;
231 defm : DemangledExtendedBuiltin<"nextafter", OpenCL_std, 47>;
232 defm : DemangledExtendedBuiltin<"pow", OpenCL_std, 48>;
233 defm : DemangledExtendedBuiltin<"pown", OpenCL_std, 49>;
234 defm : DemangledExtendedBuiltin<"powr", OpenCL_std, 50>;
235 defm : DemangledExtendedBuiltin<"remainder", OpenCL_std, 51>;
236 defm : DemangledExtendedBuiltin<"remquo", OpenCL_std, 52>;
237 defm : DemangledExtendedBuiltin<"rint", OpenCL_std, 53>;
238 defm : DemangledExtendedBuiltin<"rootn", OpenCL_std, 54>;
239 defm : DemangledExtendedBuiltin<"round", OpenCL_std, 55>;
240 defm : DemangledExtendedBuiltin<"rsqrt", OpenCL_std, 56>;
241 defm : DemangledExtendedBuiltin<"sin", OpenCL_std, 57>;
242 defm : DemangledExtendedBuiltin<"sincos", OpenCL_std, 58>;
243 defm : DemangledExtendedBuiltin<"sinh", OpenCL_std, 59>;
244 defm : DemangledExtendedBuiltin<"sinpi", OpenCL_std, 60>;
245 defm : DemangledExtendedBuiltin<"sqrt", OpenCL_std, 61>;
246 defm : DemangledExtendedBuiltin<"tan", OpenCL_std, 62>;
247 defm : DemangledExtendedBuiltin<"tanh", OpenCL_std, 63>;
248 defm : DemangledExtendedBuiltin<"tanpi", OpenCL_std, 64>;
249 defm : DemangledExtendedBuiltin<"tgamma", OpenCL_std, 65>;
250 defm : DemangledExtendedBuiltin<"trunc", OpenCL_std, 66>;
251 defm : DemangledExtendedBuiltin<"half_cos", OpenCL_std, 67>;
252 defm : DemangledExtendedBuiltin<"half_divide", OpenCL_std, 68>;
253 defm : DemangledExtendedBuiltin<"half_exp", OpenCL_std, 69>;
254 defm : DemangledExtendedBuiltin<"half_exp2", OpenCL_std, 70>;
255 defm : DemangledExtendedBuiltin<"half_exp10", OpenCL_std, 71>;
256 defm : DemangledExtendedBuiltin<"half_log", OpenCL_std, 72>;
257 defm : DemangledExtendedBuiltin<"half_log2", OpenCL_std, 73>;
258 defm : DemangledExtendedBuiltin<"half_log10", OpenCL_std, 74>;
259 defm : DemangledExtendedBuiltin<"half_powr", OpenCL_std, 75>;
260 defm : DemangledExtendedBuiltin<"half_recip", OpenCL_std, 76>;
261 defm : DemangledExtendedBuiltin<"half_rsqrt", OpenCL_std, 77>;
262 defm : DemangledExtendedBuiltin<"half_sin", OpenCL_std, 78>;
263 defm : DemangledExtendedBuiltin<"half_sqrt", OpenCL_std, 79>;
264 defm : DemangledExtendedBuiltin<"half_tan", OpenCL_std, 80>;
265 defm : DemangledExtendedBuiltin<"native_cos", OpenCL_std, 81>;
266 defm : DemangledExtendedBuiltin<"native_divide", OpenCL_std, 82>;
267 defm : DemangledExtendedBuiltin<"native_exp", OpenCL_std, 83>;
268 defm : DemangledExtendedBuiltin<"native_exp2", OpenCL_std, 84>;
269 defm : DemangledExtendedBuiltin<"native_exp10", OpenCL_std, 85>;
270 defm : DemangledExtendedBuiltin<"native_log", OpenCL_std, 86>;
271 defm : DemangledExtendedBuiltin<"native_log2", OpenCL_std, 87>;
272 defm : DemangledExtendedBuiltin<"native_log10", OpenCL_std, 88>;
273 defm : DemangledExtendedBuiltin<"native_powr", OpenCL_std, 89>;
274 defm : DemangledExtendedBuiltin<"native_recip", OpenCL_std, 90>;
275 defm : DemangledExtendedBuiltin<"native_rsqrt", OpenCL_std, 91>;
276 defm : DemangledExtendedBuiltin<"native_sin", OpenCL_std, 92>;
277 defm : DemangledExtendedBuiltin<"native_sqrt", OpenCL_std, 93>;
278 defm : DemangledExtendedBuiltin<"native_tan", OpenCL_std, 94>;
279 defm : DemangledExtendedBuiltin<"s_abs", OpenCL_std, 141>;
280 defm : DemangledExtendedBuiltin<"s_abs_diff", OpenCL_std, 142>;
281 defm : DemangledExtendedBuiltin<"s_add_sat", OpenCL_std, 143>;
282 defm : DemangledExtendedBuiltin<"u_add_sat", OpenCL_std, 144>;
283 defm : DemangledExtendedBuiltin<"s_hadd", OpenCL_std, 145>;
284 defm : DemangledExtendedBuiltin<"u_hadd", OpenCL_std, 146>;
285 defm : DemangledExtendedBuiltin<"s_rhadd", OpenCL_std, 147>;
286 defm : DemangledExtendedBuiltin<"u_rhadd", OpenCL_std, 148>;
287 defm : DemangledExtendedBuiltin<"s_clamp", OpenCL_std, 149>;
288 defm : DemangledExtendedBuiltin<"u_clamp", OpenCL_std, 150>;
289 defm : DemangledExtendedBuiltin<"clz", OpenCL_std, 151>;
290 defm : DemangledExtendedBuiltin<"ctz", OpenCL_std, 152>;
291 defm : DemangledExtendedBuiltin<"s_mad_hi", OpenCL_std, 153>;
292 defm : DemangledExtendedBuiltin<"u_mad_sat", OpenCL_std, 154>;
293 defm : DemangledExtendedBuiltin<"s_mad_sat", OpenCL_std, 155>;
294 defm : DemangledExtendedBuiltin<"s_max", OpenCL_std, 156>;
295 defm : DemangledExtendedBuiltin<"u_max", OpenCL_std, 157>;
296 defm : DemangledExtendedBuiltin<"s_min", OpenCL_std, 158>;
297 defm : DemangledExtendedBuiltin<"u_min", OpenCL_std, 159>;
298 defm : DemangledExtendedBuiltin<"s_mul_hi", OpenCL_std, 160>;
299 defm : DemangledExtendedBuiltin<"rotate", OpenCL_std, 161>;
300 defm : DemangledExtendedBuiltin<"s_sub_sat", OpenCL_std, 162>;
301 defm : DemangledExtendedBuiltin<"u_sub_sat", OpenCL_std, 163>;
302 defm : DemangledExtendedBuiltin<"u_upsample", OpenCL_std, 164>;
303 defm : DemangledExtendedBuiltin<"s_upsample", OpenCL_std, 165>;
304 defm : DemangledExtendedBuiltin<"popcount", OpenCL_std, 166>;
305 defm : DemangledExtendedBuiltin<"s_mad24", OpenCL_std, 167>;
306 defm : DemangledExtendedBuiltin<"u_mad24", OpenCL_std, 168>;
307 defm : DemangledExtendedBuiltin<"s_mul24", OpenCL_std, 169>;
308 defm : DemangledExtendedBuiltin<"u_mul24", OpenCL_std, 170>;
309 defm : DemangledExtendedBuiltin<"u_abs", OpenCL_std, 201>;
310 defm : DemangledExtendedBuiltin<"u_abs_diff", OpenCL_std, 202>;
311 defm : DemangledExtendedBuiltin<"u_mul_hi", OpenCL_std, 203>;
312 defm : DemangledExtendedBuiltin<"u_mad_hi", OpenCL_std, 204>;
313 defm : DemangledExtendedBuiltin<"fclamp", OpenCL_std, 95>;
314 defm : DemangledExtendedBuiltin<"degrees", OpenCL_std, 96>;
315 defm : DemangledExtendedBuiltin<"fmax_common", OpenCL_std, 97>;
316 defm : DemangledExtendedBuiltin<"fmin_common", OpenCL_std, 98>;
317 defm : DemangledExtendedBuiltin<"mix", OpenCL_std, 99>;
318 defm : DemangledExtendedBuiltin<"radians", OpenCL_std, 100>;
319 defm : DemangledExtendedBuiltin<"step", OpenCL_std, 101>;
320 defm : DemangledExtendedBuiltin<"smoothstep", OpenCL_std, 102>;
321 defm : DemangledExtendedBuiltin<"sign", OpenCL_std, 103>;
322 defm : DemangledExtendedBuiltin<"cross", OpenCL_std, 104>;
323 defm : DemangledExtendedBuiltin<"distance", OpenCL_std, 105>;
324 defm : DemangledExtendedBuiltin<"length", OpenCL_std, 106>;
325 defm : DemangledExtendedBuiltin<"normalize", OpenCL_std, 107>;
326 defm : DemangledExtendedBuiltin<"fast_distance", OpenCL_std, 108>;
327 defm : DemangledExtendedBuiltin<"fast_length", OpenCL_std, 109>;
328 defm : DemangledExtendedBuiltin<"fast_normalize", OpenCL_std, 110>;
329 defm : DemangledExtendedBuiltin<"bitselect", OpenCL_std, 186>;
330 defm : DemangledExtendedBuiltin<"select", OpenCL_std, 187>;
331 defm : DemangledExtendedBuiltin<"vloadn", OpenCL_std, 171>;
332 defm : DemangledExtendedBuiltin<"vstoren", OpenCL_std, 172>;
333 defm : DemangledExtendedBuiltin<"vload_half", OpenCL_std, 173>;
334 defm : DemangledExtendedBuiltin<"vload_halfn", OpenCL_std, 174>;
335 defm : DemangledExtendedBuiltin<"vstore_half", OpenCL_std, 175>;
336 defm : DemangledExtendedBuiltin<"vstore_half_r", OpenCL_std, 176>;
337 defm : DemangledExtendedBuiltin<"vstore_halfn", OpenCL_std, 177>;
338 defm : DemangledExtendedBuiltin<"vstore_halfn_r", OpenCL_std, 178>;
339 defm : DemangledExtendedBuiltin<"vloada_halfn", OpenCL_std, 179>;
340 defm : DemangledExtendedBuiltin<"vstorea_halfn", OpenCL_std, 180>;
341 defm : DemangledExtendedBuiltin<"vstorea_halfn_r", OpenCL_std, 181>;
342 defm : DemangledExtendedBuiltin<"shuffle", OpenCL_std, 182>;
343 defm : DemangledExtendedBuiltin<"shuffle2", OpenCL_std, 183>;
344 defm : DemangledExtendedBuiltin<"printf", OpenCL_std, 184>;
345 defm : DemangledExtendedBuiltin<"prefetch", OpenCL_std, 185>;
347 defm : DemangledExtendedBuiltin<"Round", GLSL_std_450, 1>;
348 defm : DemangledExtendedBuiltin<"RoundEven", GLSL_std_450, 2>;
349 defm : DemangledExtendedBuiltin<"Trunc", GLSL_std_450, 3>;
350 defm : DemangledExtendedBuiltin<"FAbs", GLSL_std_450, 4>;
351 defm : DemangledExtendedBuiltin<"SAbs", GLSL_std_450, 5>;
352 defm : DemangledExtendedBuiltin<"FSign", GLSL_std_450, 6>;
353 defm : DemangledExtendedBuiltin<"SSign", GLSL_std_450, 7>;
354 defm : DemangledExtendedBuiltin<"Floor", GLSL_std_450, 8>;
355 defm : DemangledExtendedBuiltin<"Ceil", GLSL_std_450, 9>;
356 defm : DemangledExtendedBuiltin<"Fract", GLSL_std_450, 10>;
357 defm : DemangledExtendedBuiltin<"Radians", GLSL_std_450, 11>;
358 defm : DemangledExtendedBuiltin<"Degrees", GLSL_std_450, 12>;
359 defm : DemangledExtendedBuiltin<"Sin", GLSL_std_450, 13>;
360 defm : DemangledExtendedBuiltin<"Cos", GLSL_std_450, 14>;
361 defm : DemangledExtendedBuiltin<"Tan", GLSL_std_450, 15>;
362 defm : DemangledExtendedBuiltin<"Asin", GLSL_std_450, 16>;
363 defm : DemangledExtendedBuiltin<"Acos", GLSL_std_450, 17>;
364 defm : DemangledExtendedBuiltin<"Atan", GLSL_std_450, 18>;
365 defm : DemangledExtendedBuiltin<"Sinh", GLSL_std_450, 19>;
366 defm : DemangledExtendedBuiltin<"Cosh", GLSL_std_450, 20>;
367 defm : DemangledExtendedBuiltin<"Tanh", GLSL_std_450, 21>;
368 defm : DemangledExtendedBuiltin<"Asinh", GLSL_std_450, 22>;
369 defm : DemangledExtendedBuiltin<"Acosh", GLSL_std_450, 23>;
370 defm : DemangledExtendedBuiltin<"Atanh", GLSL_std_450, 24>;
371 defm : DemangledExtendedBuiltin<"Atan2", GLSL_std_450, 25>;
372 defm : DemangledExtendedBuiltin<"Pow", GLSL_std_450, 26>;
373 defm : DemangledExtendedBuiltin<"Exp", GLSL_std_450, 27>;
374 defm : DemangledExtendedBuiltin<"Log", GLSL_std_450, 28>;
375 defm : DemangledExtendedBuiltin<"Exp2", GLSL_std_450, 29>;
376 defm : DemangledExtendedBuiltin<"Log2", GLSL_std_450, 30>;
377 defm : DemangledExtendedBuiltin<"Sqrt", GLSL_std_450, 31>;
378 defm : DemangledExtendedBuiltin<"InverseSqrt", GLSL_std_450, 32>;
379 defm : DemangledExtendedBuiltin<"Determinant", GLSL_std_450, 33>;
380 defm : DemangledExtendedBuiltin<"MatrixInverse", GLSL_std_450, 34>;
381 defm : DemangledExtendedBuiltin<"Modf", GLSL_std_450, 35>;
382 defm : DemangledExtendedBuiltin<"ModfStruct", GLSL_std_450, 36>;
383 defm : DemangledExtendedBuiltin<"FMin", GLSL_std_450, 37>;
384 defm : DemangledExtendedBuiltin<"UMin", GLSL_std_450, 38>;
385 defm : DemangledExtendedBuiltin<"SMin", GLSL_std_450, 39>;
386 defm : DemangledExtendedBuiltin<"FMax", GLSL_std_450, 40>;
387 defm : DemangledExtendedBuiltin<"UMax", GLSL_std_450, 41>;
388 defm : DemangledExtendedBuiltin<"SMax", GLSL_std_450, 42>;
389 defm : DemangledExtendedBuiltin<"FClamp", GLSL_std_450, 43>;
390 defm : DemangledExtendedBuiltin<"UClamp", GLSL_std_450, 44>;
391 defm : DemangledExtendedBuiltin<"SClamp", GLSL_std_450, 45>;
392 defm : DemangledExtendedBuiltin<"FMix", GLSL_std_450, 46>;
393 defm : DemangledExtendedBuiltin<"Step", GLSL_std_450, 48>;
394 defm : DemangledExtendedBuiltin<"SmoothStep", GLSL_std_450, 49>;
395 defm : DemangledExtendedBuiltin<"Fma", GLSL_std_450, 50>;
396 defm : DemangledExtendedBuiltin<"Frexp", GLSL_std_450, 51>;
397 defm : DemangledExtendedBuiltin<"FrexpStruct", GLSL_std_450, 52>;
398 defm : DemangledExtendedBuiltin<"Ldexp", GLSL_std_450, 53>;
399 defm : DemangledExtendedBuiltin<"PackSnorm4x8", GLSL_std_450, 54>;
400 defm : DemangledExtendedBuiltin<"PackUnorm4x8", GLSL_std_450, 55>;
401 defm : DemangledExtendedBuiltin<"PackSnorm2x16", GLSL_std_450, 56>;
402 defm : DemangledExtendedBuiltin<"PackUnorm2x16", GLSL_std_450, 57>;
403 defm : DemangledExtendedBuiltin<"PackHalf2x16", GLSL_std_450, 58>;
404 defm : DemangledExtendedBuiltin<"PackDouble2x32", GLSL_std_450, 59>;
405 defm : DemangledExtendedBuiltin<"UnpackSnorm2x16", GLSL_std_450, 60>;
406 defm : DemangledExtendedBuiltin<"UnpackUnorm2x16", GLSL_std_450, 61>;
407 defm : DemangledExtendedBuiltin<"UnpackHalf2x16", GLSL_std_450, 62>;
408 defm : DemangledExtendedBuiltin<"UnpackSnorm4x8", GLSL_std_450, 63>;
409 defm : DemangledExtendedBuiltin<"UnpackUnorm4x8", GLSL_std_450, 64>;
410 defm : DemangledExtendedBuiltin<"UnpackDouble2x32", GLSL_std_450, 65>;
411 defm : DemangledExtendedBuiltin<"Length", GLSL_std_450, 66>;
412 defm : DemangledExtendedBuiltin<"Distance", GLSL_std_450, 67>;
413 defm : DemangledExtendedBuiltin<"Cross", GLSL_std_450, 68>;
414 defm : DemangledExtendedBuiltin<"Normalize", GLSL_std_450, 69>;
415 defm : DemangledExtendedBuiltin<"FaceForward", GLSL_std_450, 70>;
416 defm : DemangledExtendedBuiltin<"Reflect", GLSL_std_450, 71>;
417 defm : DemangledExtendedBuiltin<"Refract", GLSL_std_450, 72>;
418 defm : DemangledExtendedBuiltin<"FindILsb", GLSL_std_450, 73>;
419 defm : DemangledExtendedBuiltin<"FindSMsb", GLSL_std_450, 74>;
420 defm : DemangledExtendedBuiltin<"FindUMsb", GLSL_std_450, 75>;
421 defm : DemangledExtendedBuiltin<"InterpolateAtCentroid", GLSL_std_450, 76>;
422 defm : DemangledExtendedBuiltin<"InterpolateAtSample", GLSL_std_450, 77>;
423 defm : DemangledExtendedBuiltin<"InterpolateAtOffset", GLSL_std_450, 78>;
424 defm : DemangledExtendedBuiltin<"NMin", GLSL_std_450, 79>;
425 defm : DemangledExtendedBuiltin<"NMax", GLSL_std_450, 80>;
426 defm : DemangledExtendedBuiltin<"NClamp", GLSL_std_450, 81>;
428 //===----------------------------------------------------------------------===//
429 // Class defining an native builtin record used for direct translation into a
430 // SPIR-V instruction.
432 // name is the demangled name of the given builtin.
433 // set specifies which external instruction set the builtin belongs to.
434 // opcode specifies the SPIR-V operation code of the generated instruction.
435 //===----------------------------------------------------------------------===//
436 class NativeBuiltin<string name, InstructionSet set, Op operation> {
437   string Name = name;
438   InstructionSet Set = set;
439   Op Opcode = operation;
442 // Table gathering all the native builtins.
443 def NativeBuiltins : GenericTable {
444   let FilterClass = "NativeBuiltin";
445   let Fields = ["Name", "Set", "Opcode"];
446   string TypeOf_Set = "InstructionSet";
449 // Function to lookup native builtins by their name and set.
450 def lookupNativeBuiltin : SearchIndex {
451   let Table = NativeBuiltins;
452   let Key = ["Name", "Set"];
455 // Multiclass used to define at the same time both an incoming builtin record
456 // and a corresponding native builtin record.
457 multiclass DemangledNativeBuiltin<string name, InstructionSet set, BuiltinGroup group, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
458   def : DemangledBuiltin<name, set, group, minNumArgs, maxNumArgs>;
459   def : NativeBuiltin<name, set, operation>;
462 // Relational builtin records:
463 defm : DemangledNativeBuiltin<"isequal", OpenCL_std, Relational, 2, 2, OpFOrdEqual>;
464 defm : DemangledNativeBuiltin<"__spirv_FOrdEqual", OpenCL_std, Relational, 2, 2, OpFOrdEqual>;
465 defm : DemangledNativeBuiltin<"isnotequal", OpenCL_std, Relational, 2, 2, OpFUnordNotEqual>;
466 defm : DemangledNativeBuiltin<"__spirv_FUnordNotEqual", OpenCL_std, Relational, 2, 2, OpFUnordNotEqual>;
467 defm : DemangledNativeBuiltin<"isgreater", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThan>;
468 defm : DemangledNativeBuiltin<"__spirv_FOrdGreaterThan", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThan>;
469 defm : DemangledNativeBuiltin<"isgreaterequal", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThanEqual>;
470 defm : DemangledNativeBuiltin<"__spirv_FOrdGreaterThanEqual", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThanEqual>;
471 defm : DemangledNativeBuiltin<"isless", OpenCL_std, Relational, 2, 2, OpFOrdLessThan>;
472 defm : DemangledNativeBuiltin<"__spirv_FOrdLessThan", OpenCL_std, Relational, 2, 2, OpFOrdLessThan>;
473 defm : DemangledNativeBuiltin<"islessequal", OpenCL_std, Relational, 2, 2, OpFOrdLessThanEqual>;
474 defm : DemangledNativeBuiltin<"__spirv_FOrdLessThanEqual", OpenCL_std, Relational, 2, 2, OpFOrdLessThanEqual>;
475 defm : DemangledNativeBuiltin<"islessgreater", OpenCL_std, Relational, 2, 2, OpFOrdNotEqual>;
476 defm : DemangledNativeBuiltin<"__spirv_FOrdNotEqual", OpenCL_std, Relational, 2, 2, OpFOrdNotEqual>;
477 defm : DemangledNativeBuiltin<"isordered", OpenCL_std, Relational, 2, 2, OpOrdered>;
478 defm : DemangledNativeBuiltin<"__spirv_Ordered", OpenCL_std, Relational, 2, 2, OpOrdered>;
479 defm : DemangledNativeBuiltin<"isunordered", OpenCL_std, Relational, 2, 2, OpUnordered>;
480 defm : DemangledNativeBuiltin<"__spirv_Unordered", OpenCL_std, Relational, 2, 2, OpUnordered>;
481 defm : DemangledNativeBuiltin<"isfinite", OpenCL_std, Relational, 1, 1, OpIsFinite>;
482 defm : DemangledNativeBuiltin<"__spirv_IsFinite", OpenCL_std, Relational, 1, 1, OpIsFinite>;
483 defm : DemangledNativeBuiltin<"isinf", OpenCL_std, Relational, 1, 1, OpIsInf>;
484 defm : DemangledNativeBuiltin<"__spirv_IsInf", OpenCL_std, Relational, 1, 1, OpIsInf>;
485 defm : DemangledNativeBuiltin<"isnan", OpenCL_std, Relational, 1, 1, OpIsNan>;
486 defm : DemangledNativeBuiltin<"__spirv_IsNan", OpenCL_std, Relational, 1, 1, OpIsNan>;
487 defm : DemangledNativeBuiltin<"isnormal", OpenCL_std, Relational, 1, 1, OpIsNormal>;
488 defm : DemangledNativeBuiltin<"__spirv_IsNormal", OpenCL_std, Relational, 1, 1, OpIsNormal>;
489 defm : DemangledNativeBuiltin<"signbit", OpenCL_std, Relational, 1, 1, OpSignBitSet>;
490 defm : DemangledNativeBuiltin<"__spirv_SignBitSet", OpenCL_std, Relational, 1, 1, OpSignBitSet>;
491 defm : DemangledNativeBuiltin<"any", OpenCL_std, Relational, 1, 1, OpAny>;
492 defm : DemangledNativeBuiltin<"__spirv_Any", OpenCL_std, Relational, 1, 1, OpAny>;
493 defm : DemangledNativeBuiltin<"all", OpenCL_std, Relational, 1, 1, OpAll>;
494 defm : DemangledNativeBuiltin<"__spirv_All", OpenCL_std, Relational, 1, 1, OpAll>;
496 // Atomic builtin records:
497 defm : DemangledNativeBuiltin<"atomic_init", OpenCL_std, Atomic, 2, 2, OpStore>;
498 defm : DemangledNativeBuiltin<"atomic_load", OpenCL_std, Atomic, 1, 1, OpAtomicLoad>;
499 defm : DemangledNativeBuiltin<"atomic_load_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicLoad>;
500 defm : DemangledNativeBuiltin<"atomic_store", OpenCL_std, Atomic, 2, 2, OpAtomicStore>;
501 defm : DemangledNativeBuiltin<"atomic_store_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicStore>;
502 defm : DemangledNativeBuiltin<"atomic_compare_exchange_strong", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
503 defm : DemangledNativeBuiltin<"atomic_compare_exchange_strong_explicit", OpenCL_std, Atomic, 5, 6, OpAtomicCompareExchange>;
504 defm : DemangledNativeBuiltin<"atomic_compare_exchange_weak", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchangeWeak>;
505 defm : DemangledNativeBuiltin<"atomic_compare_exchange_weak_explicit", OpenCL_std, Atomic, 5, 6, OpAtomicCompareExchangeWeak>;
506 defm : DemangledNativeBuiltin<"atom_cmpxchg", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
507 defm : DemangledNativeBuiltin<"atomic_cmpxchg", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
508 defm : DemangledNativeBuiltin<"atom_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
509 defm : DemangledNativeBuiltin<"atomic_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
510 defm : DemangledNativeBuiltin<"atom_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
511 defm : DemangledNativeBuiltin<"atomic_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
512 defm : DemangledNativeBuiltin<"atom_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
513 defm : DemangledNativeBuiltin<"atomic_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
514 defm : DemangledNativeBuiltin<"atom_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
515 defm : DemangledNativeBuiltin<"atomic_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
516 defm : DemangledNativeBuiltin<"atom_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
517 defm : DemangledNativeBuiltin<"atomic_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
518 defm : DemangledNativeBuiltin<"atomic_exchange", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
519 defm : DemangledNativeBuiltin<"atomic_exchange_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
520 defm : DemangledNativeBuiltin<"atomic_work_item_fence", OpenCL_std, Atomic, 1, 3, OpMemoryBarrier>;
521 defm : DemangledNativeBuiltin<"atomic_fetch_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
522 defm : DemangledNativeBuiltin<"atomic_fetch_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
523 defm : DemangledNativeBuiltin<"atomic_fetch_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
524 defm : DemangledNativeBuiltin<"atomic_fetch_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
525 defm : DemangledNativeBuiltin<"atomic_fetch_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
526 defm : DemangledNativeBuiltin<"atomic_fetch_add_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicIAdd>;
527 defm : DemangledNativeBuiltin<"atomic_fetch_sub_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicISub>;
528 defm : DemangledNativeBuiltin<"atomic_fetch_or_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicOr>;
529 defm : DemangledNativeBuiltin<"atomic_fetch_xor_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicXor>;
530 defm : DemangledNativeBuiltin<"atomic_fetch_and_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicAnd>;
531 defm : DemangledNativeBuiltin<"atomic_flag_test_and_set", OpenCL_std, Atomic, 1, 1, OpAtomicFlagTestAndSet>;
532 defm : DemangledNativeBuiltin<"atomic_flag_test_and_set_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicFlagTestAndSet>;
533 defm : DemangledNativeBuiltin<"atomic_flag_clear", OpenCL_std, Atomic, 1, 1, OpAtomicFlagClear>;
534 defm : DemangledNativeBuiltin<"atomic_flag_clear_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicFlagClear>;
536 // Barrier builtin records:
537 defm : DemangledNativeBuiltin<"barrier", OpenCL_std, Barrier, 1, 3, OpControlBarrier>;
538 defm : DemangledNativeBuiltin<"work_group_barrier", OpenCL_std, Barrier, 1, 3, OpControlBarrier>;
540 // Kernel enqueue builtin records:
541 defm : DemangledNativeBuiltin<"__enqueue_kernel_basic", OpenCL_std, Enqueue, 5, 5, OpEnqueueKernel>;
542 defm : DemangledNativeBuiltin<"__enqueue_kernel_basic_events", OpenCL_std, Enqueue, 8, 8, OpEnqueueKernel>;
543 defm : DemangledNativeBuiltin<"__enqueue_kernel_varargs", OpenCL_std, Enqueue, 7, 7, OpEnqueueKernel>;
544 defm : DemangledNativeBuiltin<"__enqueue_kernel_events_varargs", OpenCL_std, Enqueue, 10, 10, OpEnqueueKernel>;
545 defm : DemangledNativeBuiltin<"retain_event", OpenCL_std, Enqueue, 1, 1, OpRetainEvent>;
546 defm : DemangledNativeBuiltin<"release_event", OpenCL_std, Enqueue, 1, 1, OpReleaseEvent>;
547 defm : DemangledNativeBuiltin<"create_user_event", OpenCL_std, Enqueue, 0, 0, OpCreateUserEvent>;
548 defm : DemangledNativeBuiltin<"is_valid_event", OpenCL_std, Enqueue, 1, 1, OpIsValidEvent>;
549 defm : DemangledNativeBuiltin<"set_user_event_status", OpenCL_std, Enqueue, 2, 2, OpSetUserEventStatus>;
550 defm : DemangledNativeBuiltin<"capture_event_profiling_info", OpenCL_std, Enqueue, 3, 3, OpCaptureEventProfilingInfo>;
551 defm : DemangledNativeBuiltin<"get_default_queue", OpenCL_std, Enqueue, 0, 0, OpGetDefaultQueue>;
552 defm : DemangledNativeBuiltin<"ndrange_1D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
553 defm : DemangledNativeBuiltin<"ndrange_2D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
554 defm : DemangledNativeBuiltin<"ndrange_3D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
556 // Spec constant builtin records:
557 defm : DemangledNativeBuiltin<"__spirv_SpecConstant", OpenCL_std, SpecConstant, 2, 2, OpSpecConstant>;
558 defm : DemangledNativeBuiltin<"__spirv_SpecConstantComposite", OpenCL_std, SpecConstant, 1, 0, OpSpecConstantComposite>;
560 // Async Copy and Prefetch builtin records:
561 defm : DemangledNativeBuiltin<"async_work_group_copy", OpenCL_std, AsyncCopy, 4, 4, OpGroupAsyncCopy>;
562 defm : DemangledNativeBuiltin<"wait_group_events", OpenCL_std, AsyncCopy, 2, 2, OpGroupWaitEvents>;
564 // Load and store builtin records:
565 defm : DemangledNativeBuiltin<"__spirv_Load", OpenCL_std, LoadStore, 1, 3, OpLoad>;
566 defm : DemangledNativeBuiltin<"__spirv_Store", OpenCL_std, LoadStore, 2, 4, OpStore>;
568 //===----------------------------------------------------------------------===//
569 // Class defining a work/sub group builtin that should be translated into a
570 // SPIR-V instruction using the defined properties.
572 // name is the demangled name of the given builtin.
573 // opcode specifies the SPIR-V operation code of the generated instruction.
574 //===----------------------------------------------------------------------===//
575 class GroupBuiltin<string name, Op operation> {
576   string Name = name;
577   Op Opcode = operation;
578   bits<32> GroupOperation = !cond(!not(!eq(!find(name, "group_reduce"), -1)) : Reduce.Value,
579                                   !not(!eq(!find(name, "group_scan_inclusive"), -1)) : InclusiveScan.Value,
580                                   !not(!eq(!find(name, "group_scan_exclusive"), -1)) : ExclusiveScan.Value,
581                                   !not(!eq(!find(name, "group_ballot_bit_count"), -1)) : Reduce.Value,
582                                   !not(!eq(!find(name, "group_ballot_inclusive_scan"), -1)) : InclusiveScan.Value,
583                                   !not(!eq(!find(name, "group_ballot_exclusive_scan"), -1)) : ExclusiveScan.Value,
584                                   !not(!eq(!find(name, "group_non_uniform_reduce"), -1)) : Reduce.Value,
585                                   !not(!eq(!find(name, "group_non_uniform_scan_inclusive"), -1)) : InclusiveScan.Value,
586                                   !not(!eq(!find(name, "group_non_uniform_scan_exclusive"), -1)) : ExclusiveScan.Value,
587                                   !not(!eq(!find(name, "group_non_uniform_reduce_logical"), -1)) : Reduce.Value,
588                                   !not(!eq(!find(name, "group_non_uniform_scan_inclusive_logical"), -1)) : InclusiveScan.Value,
589                                   !not(!eq(!find(name, "group_non_uniform_scan_exclusive_logical"), -1)) : ExclusiveScan.Value,
590                                   !not(!eq(!find(name, "group_clustered_reduce"), -1)) : ClusteredReduce.Value,
591                                   !not(!eq(!find(name, "group_clustered_reduce_logical"), -1)) : ClusteredReduce.Value,
592                                   true : 0);
593   bit IsElect = !eq(operation, OpGroupNonUniformElect);
594   bit IsAllOrAny = !or(!eq(operation, OpGroupAll),
595                        !eq(operation, OpGroupAny),
596                        !eq(operation, OpGroupNonUniformAll),
597                        !eq(operation, OpGroupNonUniformAny));
598   bit IsAllEqual = !eq(operation, OpGroupNonUniformAllEqual);
599   bit IsBallot = !eq(operation, OpGroupNonUniformBallot);
600   bit IsInverseBallot = !eq(operation, OpGroupNonUniformInverseBallot);
601   bit IsBallotBitExtract = !eq(operation, OpGroupNonUniformBallotBitExtract);
602   bit IsBallotFindBit = !or(!eq(operation, OpGroupNonUniformBallotFindLSB),
603                             !eq(operation, OpGroupNonUniformBallotFindMSB));
604   bit IsLogical = !or(!eq(operation, OpGroupNonUniformLogicalAnd),
605                       !eq(operation, OpGroupNonUniformLogicalOr),
606                       !eq(operation, OpGroupNonUniformLogicalXor));
607   bit NoGroupOperation = !or(IsElect, IsAllOrAny, IsAllEqual,
608                              IsBallot, IsInverseBallot,
609                              IsBallotBitExtract, IsBallotFindBit,
610                              !eq(operation, OpGroupNonUniformShuffle),
611                              !eq(operation, OpGroupNonUniformShuffleXor),
612                              !eq(operation, OpGroupNonUniformShuffleUp),
613                              !eq(operation, OpGroupNonUniformShuffleDown),
614                              !eq(operation, OpGroupBroadcast),
615                              !eq(operation, OpGroupNonUniformBroadcast),
616                              !eq(operation, OpGroupNonUniformBroadcastFirst));
617   bit HasBoolArg = !or(!and(IsAllOrAny, !eq(IsAllEqual, false)), IsBallot, IsLogical);
620 // Table gathering all the work/sub group builtins.
621 def GroupBuiltins : GenericTable {
622   let FilterClass = "GroupBuiltin";
623   let Fields = ["Name", "Opcode", "GroupOperation", "IsElect", "IsAllOrAny",
624                 "IsAllEqual", "IsBallot", "IsInverseBallot", "IsBallotBitExtract",
625                 "IsBallotFindBit", "IsLogical", "NoGroupOperation", "HasBoolArg"];
628 // Function to lookup native builtins by their name and set.
629 def lookupGroupBuiltin : SearchIndex {
630   let Table = GroupBuiltins;
631   let Key = ["Name"];
634 // Multiclass used to define at the same time both incoming builtin records
635 // and corresponding work/sub group builtin records.
636 defvar OnlyWork = 0; defvar OnlySub = 1; defvar WorkOrSub = 2;
637 multiclass DemangledGroupBuiltin<string name, int level /* OnlyWork/OnlySub/... */, Op operation> {
638   assert !and(!ge(level, 0), !le(level, 2)), "group level is invalid: " # level;
640   if !or(!eq(level, OnlyWork), !eq(level, WorkOrSub)) then {
641     def : DemangledBuiltin<!strconcat("work_", name), OpenCL_std, Group, 0, 4>;
642     def : GroupBuiltin<!strconcat("work_", name), operation>;
643   }
645   if !or(!eq(level, OnlySub), !eq(level, WorkOrSub)) then {
646     def : DemangledBuiltin<!strconcat("sub_", name), OpenCL_std, Group, 0, 4>;
647     def : GroupBuiltin<!strconcat("sub_", name), operation>;
648   }
651 defm : DemangledGroupBuiltin<"group_all", WorkOrSub, OpGroupAll>;
652 defm : DemangledGroupBuiltin<"group_any", WorkOrSub, OpGroupAny>;
653 defm : DemangledGroupBuiltin<"group_broadcast", WorkOrSub, OpGroupBroadcast>;
654 defm : DemangledGroupBuiltin<"group_non_uniform_broadcast", OnlySub, OpGroupNonUniformBroadcast>;
655 defm : DemangledGroupBuiltin<"group_broadcast_first", OnlySub, OpGroupNonUniformBroadcastFirst>;
657 // cl_khr_subgroup_non_uniform_vote
658 defm : DemangledGroupBuiltin<"group_elect", OnlySub, OpGroupNonUniformElect>;
659 defm : DemangledGroupBuiltin<"group_non_uniform_all", OnlySub, OpGroupNonUniformAll>;
660 defm : DemangledGroupBuiltin<"group_non_uniform_any", OnlySub, OpGroupNonUniformAny>;
661 defm : DemangledGroupBuiltin<"group_non_uniform_all_equal", OnlySub, OpGroupNonUniformAllEqual>;
663 // cl_khr_subgroup_ballot
664 defm : DemangledGroupBuiltin<"group_ballot", OnlySub, OpGroupNonUniformBallot>;
665 defm : DemangledGroupBuiltin<"group_inverse_ballot", OnlySub, OpGroupNonUniformInverseBallot>;
666 defm : DemangledGroupBuiltin<"group_ballot_bit_extract", OnlySub, OpGroupNonUniformBallotBitExtract>;
667 defm : DemangledGroupBuiltin<"group_ballot_bit_count", OnlySub, OpGroupNonUniformBallotBitCount>;
668 defm : DemangledGroupBuiltin<"group_ballot_inclusive_scan", OnlySub, OpGroupNonUniformBallotBitCount>;
669 defm : DemangledGroupBuiltin<"group_ballot_exclusive_scan", OnlySub, OpGroupNonUniformBallotBitCount>;
670 defm : DemangledGroupBuiltin<"group_ballot_find_lsb", OnlySub, OpGroupNonUniformBallotFindLSB>;
671 defm : DemangledGroupBuiltin<"group_ballot_find_msb", OnlySub, OpGroupNonUniformBallotFindMSB>;
673 // cl_khr_subgroup_shuffle
674 defm : DemangledGroupBuiltin<"group_shuffle", OnlySub, OpGroupNonUniformShuffle>;
675 defm : DemangledGroupBuiltin<"group_shuffle_xor", OnlySub, OpGroupNonUniformShuffleXor>;
677 // cl_khr_subgroup_shuffle_relative
678 defm : DemangledGroupBuiltin<"group_shuffle_up", OnlySub, OpGroupNonUniformShuffleUp>;
679 defm : DemangledGroupBuiltin<"group_shuffle_down", OnlySub, OpGroupNonUniformShuffleDown>;
681 defm : DemangledGroupBuiltin<"group_iadd", WorkOrSub, OpGroupIAdd>;
682 defm : DemangledGroupBuiltin<"group_reduce_adds", WorkOrSub, OpGroupIAdd>;
683 defm : DemangledGroupBuiltin<"group_scan_exclusive_adds", WorkOrSub, OpGroupIAdd>;
684 defm : DemangledGroupBuiltin<"group_scan_inclusive_adds", WorkOrSub, OpGroupIAdd>;
685 defm : DemangledGroupBuiltin<"group_reduce_addu", WorkOrSub, OpGroupIAdd>;
686 defm : DemangledGroupBuiltin<"group_scan_exclusive_addu", WorkOrSub, OpGroupIAdd>;
687 defm : DemangledGroupBuiltin<"group_scan_inclusive_addu", WorkOrSub, OpGroupIAdd>;
689 defm : DemangledGroupBuiltin<"group_fadd", WorkOrSub, OpGroupFAdd>;
690 defm : DemangledGroupBuiltin<"group_reduce_addf", WorkOrSub, OpGroupFAdd>;
691 defm : DemangledGroupBuiltin<"group_scan_exclusive_addf", WorkOrSub, OpGroupFAdd>;
692 defm : DemangledGroupBuiltin<"group_scan_inclusive_addf", WorkOrSub, OpGroupFAdd>;
694 defm : DemangledGroupBuiltin<"group_fmin", WorkOrSub, OpGroupFMin>;
695 defm : DemangledGroupBuiltin<"group_reduce_minf", WorkOrSub, OpGroupFMin>;
696 defm : DemangledGroupBuiltin<"group_scan_exclusive_minf", WorkOrSub, OpGroupFMin>;
697 defm : DemangledGroupBuiltin<"group_scan_inclusive_minf", WorkOrSub, OpGroupFMin>;
699 defm : DemangledGroupBuiltin<"group_umin", WorkOrSub, OpGroupUMin>;
700 defm : DemangledGroupBuiltin<"group_reduce_minu", WorkOrSub, OpGroupUMin>;
701 defm : DemangledGroupBuiltin<"group_scan_exclusive_minu", WorkOrSub, OpGroupUMin>;
702 defm : DemangledGroupBuiltin<"group_scan_inclusive_minu", WorkOrSub, OpGroupUMin>;
704 defm : DemangledGroupBuiltin<"group_smin", WorkOrSub, OpGroupSMin>;
705 defm : DemangledGroupBuiltin<"group_reduce_mins", WorkOrSub, OpGroupSMin>;
706 defm : DemangledGroupBuiltin<"group_scan_exclusive_mins", WorkOrSub, OpGroupSMin>;
707 defm : DemangledGroupBuiltin<"group_scan_inclusive_mins", WorkOrSub, OpGroupSMin>;
709 defm : DemangledGroupBuiltin<"group_fmax", WorkOrSub, OpGroupFMax>;
710 defm : DemangledGroupBuiltin<"group_reduce_maxf", WorkOrSub, OpGroupFMax>;
711 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxf", WorkOrSub, OpGroupFMax>;
712 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxf", WorkOrSub, OpGroupFMax>;
714 defm : DemangledGroupBuiltin<"group_umax", WorkOrSub, OpGroupUMax>;
715 defm : DemangledGroupBuiltin<"group_reduce_maxu", WorkOrSub, OpGroupUMax>;
716 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxu", WorkOrSub, OpGroupUMax>;
717 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxu", WorkOrSub, OpGroupUMax>;
719 defm : DemangledGroupBuiltin<"group_smax", WorkOrSub, OpGroupSMax>;
720 defm : DemangledGroupBuiltin<"group_reduce_maxs", WorkOrSub, OpGroupSMax>;
721 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxs", WorkOrSub, OpGroupSMax>;
722 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxs", WorkOrSub, OpGroupSMax>;
724 // cl_khr_subgroup_non_uniform_arithmetic
725 defm : DemangledGroupBuiltin<"group_non_uniform_iadd", WorkOrSub, OpGroupNonUniformIAdd>;
726 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addu", WorkOrSub, OpGroupNonUniformIAdd>;
727 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_adds", WorkOrSub, OpGroupNonUniformIAdd>;
728 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addu", WorkOrSub, OpGroupNonUniformIAdd>;
729 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_adds", WorkOrSub, OpGroupNonUniformIAdd>;
730 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addu", WorkOrSub, OpGroupNonUniformIAdd>;
731 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_adds", WorkOrSub, OpGroupNonUniformIAdd>;
732 defm : DemangledGroupBuiltin<"group_clustered_reduce_addu", WorkOrSub, OpGroupNonUniformIAdd>;
733 defm : DemangledGroupBuiltin<"group_clustered_reduce_adds", WorkOrSub, OpGroupNonUniformIAdd>;
735 defm : DemangledGroupBuiltin<"group_non_uniform_fadd", WorkOrSub, OpGroupNonUniformFAdd>;
736 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addf", WorkOrSub, OpGroupNonUniformFAdd>;
737 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addh", WorkOrSub, OpGroupNonUniformFAdd>;
738 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addd", WorkOrSub, OpGroupNonUniformFAdd>;
739 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addf", WorkOrSub, OpGroupNonUniformFAdd>;
740 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addh", WorkOrSub, OpGroupNonUniformFAdd>;
741 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addd", WorkOrSub, OpGroupNonUniformFAdd>;
742 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addf", WorkOrSub, OpGroupNonUniformFAdd>;
743 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addh", WorkOrSub, OpGroupNonUniformFAdd>;
744 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addd", WorkOrSub, OpGroupNonUniformFAdd>;
745 defm : DemangledGroupBuiltin<"group_clustered_reduce_addf", WorkOrSub, OpGroupNonUniformFAdd>;
746 defm : DemangledGroupBuiltin<"group_clustered_reduce_addh", WorkOrSub, OpGroupNonUniformFAdd>;
747 defm : DemangledGroupBuiltin<"group_clustered_reduce_addd", WorkOrSub, OpGroupNonUniformFAdd>;
749 defm : DemangledGroupBuiltin<"group_non_uniform_imul", WorkOrSub, OpGroupNonUniformIMul>;
750 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulu", WorkOrSub, OpGroupNonUniformIMul>;
751 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_muls", WorkOrSub, OpGroupNonUniformIMul>;
752 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulu", WorkOrSub, OpGroupNonUniformIMul>;
753 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_muls", WorkOrSub, OpGroupNonUniformIMul>;
754 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulu", WorkOrSub, OpGroupNonUniformIMul>;
755 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_muls", WorkOrSub, OpGroupNonUniformIMul>;
756 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulu", WorkOrSub, OpGroupNonUniformIMul>;
757 defm : DemangledGroupBuiltin<"group_clustered_reduce_muls", WorkOrSub, OpGroupNonUniformIMul>;
759 defm : DemangledGroupBuiltin<"group_non_uniform_fmul", WorkOrSub, OpGroupNonUniformFMul>;
760 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulf", WorkOrSub, OpGroupNonUniformFMul>;
761 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulh", WorkOrSub, OpGroupNonUniformFMul>;
762 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_muld", WorkOrSub, OpGroupNonUniformFMul>;
763 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulf", WorkOrSub, OpGroupNonUniformFMul>;
764 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulh", WorkOrSub, OpGroupNonUniformFMul>;
765 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_muld", WorkOrSub, OpGroupNonUniformFMul>;
766 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulf", WorkOrSub, OpGroupNonUniformFMul>;
767 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulh", WorkOrSub, OpGroupNonUniformFMul>;
768 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_muld", WorkOrSub, OpGroupNonUniformFMul>;
769 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulf", WorkOrSub, OpGroupNonUniformFMul>;
770 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulh", WorkOrSub, OpGroupNonUniformFMul>;
771 defm : DemangledGroupBuiltin<"group_clustered_reduce_muld", WorkOrSub, OpGroupNonUniformFMul>;
773 defm : DemangledGroupBuiltin<"group_non_uniform_smin", WorkOrSub, OpGroupNonUniformSMin>;
774 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mins", WorkOrSub, OpGroupNonUniformSMin>;
775 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mins", WorkOrSub, OpGroupNonUniformSMin>;
776 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mins", WorkOrSub, OpGroupNonUniformSMin>;
777 defm : DemangledGroupBuiltin<"group_clustered_reduce_mins", WorkOrSub, OpGroupNonUniformSMin>;
780 defm : DemangledGroupBuiltin<"group_non_uniform_umin", WorkOrSub, OpGroupNonUniformUMin>;
781 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minu", WorkOrSub, OpGroupNonUniformUMin>;
782 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minu", WorkOrSub, OpGroupNonUniformUMin>;
783 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minu", WorkOrSub, OpGroupNonUniformUMin>;
784 defm : DemangledGroupBuiltin<"group_clustered_reduce_minu", WorkOrSub, OpGroupNonUniformUMin>;
786 defm : DemangledGroupBuiltin<"group_non_uniform_fmin", WorkOrSub, OpGroupNonUniformFMin>;
787 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minf", WorkOrSub, OpGroupNonUniformFMin>;
788 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minh", WorkOrSub, OpGroupNonUniformFMin>;
789 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mind", WorkOrSub, OpGroupNonUniformFMin>;
790 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minf", WorkOrSub, OpGroupNonUniformFMin>;
791 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minh", WorkOrSub, OpGroupNonUniformFMin>;
792 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mind", WorkOrSub, OpGroupNonUniformFMin>;
793 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minf", WorkOrSub, OpGroupNonUniformFMin>;
794 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minh", WorkOrSub, OpGroupNonUniformFMin>;
795 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mind", WorkOrSub, OpGroupNonUniformFMin>;
796 defm : DemangledGroupBuiltin<"group_clustered_reduce_minf", WorkOrSub, OpGroupNonUniformFMin>;
797 defm : DemangledGroupBuiltin<"group_clustered_reduce_minh", WorkOrSub, OpGroupNonUniformFMin>;
798 defm : DemangledGroupBuiltin<"group_clustered_reduce_mind", WorkOrSub, OpGroupNonUniformFMin>;
800 defm : DemangledGroupBuiltin<"group_non_uniform_smax", WorkOrSub, OpGroupNonUniformSMax>;
801 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxs", WorkOrSub, OpGroupNonUniformSMax>;
802 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxs", WorkOrSub, OpGroupNonUniformSMax>;
803 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxs", WorkOrSub, OpGroupNonUniformSMax>;
804 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxs", WorkOrSub, OpGroupNonUniformSMax>;
806 defm : DemangledGroupBuiltin<"group_non_uniform_umax", WorkOrSub, OpGroupNonUniformUMax>;
807 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxu", WorkOrSub, OpGroupNonUniformUMax>;
808 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxu", WorkOrSub, OpGroupNonUniformUMax>;
809 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxu", WorkOrSub, OpGroupNonUniformUMax>;
810 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxu", WorkOrSub, OpGroupNonUniformUMax>;
812 defm : DemangledGroupBuiltin<"group_non_uniform_fmax", WorkOrSub, OpGroupNonUniformFMax>;
813 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxf", WorkOrSub, OpGroupNonUniformFMax>;
814 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxh", WorkOrSub, OpGroupNonUniformFMax>;
815 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxd", WorkOrSub, OpGroupNonUniformFMax>;
816 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxf", WorkOrSub, OpGroupNonUniformFMax>;
817 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxh", WorkOrSub, OpGroupNonUniformFMax>;
818 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxd", WorkOrSub, OpGroupNonUniformFMax>;
819 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxf", WorkOrSub, OpGroupNonUniformFMax>;
820 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxh", WorkOrSub, OpGroupNonUniformFMax>;
821 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxd", WorkOrSub, OpGroupNonUniformFMax>;
822 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxf", WorkOrSub, OpGroupNonUniformFMax>;
823 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxh", WorkOrSub, OpGroupNonUniformFMax>;
824 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxd", WorkOrSub, OpGroupNonUniformFMax>;
826 defm : DemangledGroupBuiltin<"group_non_uniform_iand", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
827 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
828 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
829 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
830 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
831 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
832 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
833 defm : DemangledGroupBuiltin<"group_clustered_reduce_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
834 defm : DemangledGroupBuiltin<"group_clustered_reduce_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
836 defm : DemangledGroupBuiltin<"group_non_uniform_ior", WorkOrSub, OpGroupNonUniformBitwiseOr>;
837 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
838 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
839 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
840 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
841 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
842 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
843 defm : DemangledGroupBuiltin<"group_clustered_reduce_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
844 defm : DemangledGroupBuiltin<"group_clustered_reduce_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
846 defm : DemangledGroupBuiltin<"group_non_uniform_ixor", WorkOrSub, OpGroupNonUniformBitwiseXor>;
847 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
848 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
849 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
850 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
851 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
852 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
853 defm : DemangledGroupBuiltin<"group_clustered_reduce_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
854 defm : DemangledGroupBuiltin<"group_clustered_reduce_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
856 defm : DemangledGroupBuiltin<"group_non_uniform_logical_iand", WorkOrSub, OpGroupNonUniformLogicalAnd>;
857 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
858 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
859 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
860 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_and", WorkOrSub, OpGroupNonUniformLogicalAnd>;
862 defm : DemangledGroupBuiltin<"group_non_uniform_logical_ior", WorkOrSub, OpGroupNonUniformLogicalOr>;
863 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
864 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
865 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
866 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_or", WorkOrSub, OpGroupNonUniformLogicalOr>;
868 defm : DemangledGroupBuiltin<"group_non_uniform_logical_ixor", WorkOrSub, OpGroupNonUniformLogicalXor>;
869 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
870 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
871 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
872 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_xor", WorkOrSub, OpGroupNonUniformLogicalXor>;
875 //===----------------------------------------------------------------------===//
876 // Class defining a get builtin record used for lowering builtin calls such as
877 // "get_sub_group_eq_mask" or "get_global_id" to SPIR-V instructions.
879 // name is the demangled name of the given builtin.
880 // set specifies which external instruction set the builtin belongs to.
881 // value specifies the value of the BuiltIn enum.
882 //===----------------------------------------------------------------------===//
883 class GetBuiltin<string name, InstructionSet set, BuiltIn value> {
884   string Name = name;
885   InstructionSet Set = set;
886   BuiltIn Value = value;
889 // Table gathering all the get builtin records.
890 def GetBuiltins : GenericTable {
891   let FilterClass = "GetBuiltin";
892   let Fields = ["Name", "Set", "Value"];
893   string TypeOf_Set = "InstructionSet";
894   string TypeOf_Value = "BuiltIn";
897 // Function to lookup get builtin records by their name and set.
898 def lookupGetBuiltin : SearchIndex {
899   let Table = GetBuiltins;
900   let Key = ["Name", "Set"];
903 // Multiclass used to define at the same time both a demangled builtin record
904 // and a corresponding get builtin record.
905 multiclass DemangledGetBuiltin<string name, InstructionSet set, BuiltinGroup group, BuiltIn value> {
906   def : DemangledBuiltin<name, set, group, 0, 1>;
907   def : GetBuiltin<name, set, value>;
910 // Builtin variable records:
911 defm : DemangledGetBuiltin<"get_sub_group_eq_mask", OpenCL_std, Variable, SubgroupEqMask>;
912 defm : DemangledGetBuiltin<"get_sub_group_ge_mask", OpenCL_std, Variable, SubgroupGeMask>;
913 defm : DemangledGetBuiltin<"get_sub_group_gt_mask", OpenCL_std, Variable, SubgroupGtMask>;
914 defm : DemangledGetBuiltin<"get_sub_group_le_mask", OpenCL_std, Variable, SubgroupLeMask>;
915 defm : DemangledGetBuiltin<"get_sub_group_lt_mask", OpenCL_std, Variable, SubgroupLtMask>;
916 defm : DemangledGetBuiltin<"__spirv_BuiltInGlobalLinearId", OpenCL_std, Variable, GlobalLinearId>;
917 defm : DemangledGetBuiltin<"__spirv_BuiltInGlobalInvocationId", OpenCL_std, Variable, GlobalInvocationId>;
919 // GetQuery builtin records:
920 defm : DemangledGetBuiltin<"get_local_id", OpenCL_std, GetQuery, LocalInvocationId>;
921 defm : DemangledGetBuiltin<"get_global_id", OpenCL_std, GetQuery, GlobalInvocationId>;
922 defm : DemangledGetBuiltin<"get_local_size", OpenCL_std, GetQuery, WorkgroupSize>;
923 defm : DemangledGetBuiltin<"get_global_size", OpenCL_std, GetQuery, GlobalSize>;
924 defm : DemangledGetBuiltin<"get_group_id", OpenCL_std, GetQuery, WorkgroupId>;
925 defm : DemangledGetBuiltin<"get_enqueued_local_size", OpenCL_std, GetQuery, EnqueuedWorkgroupSize>;
926 defm : DemangledGetBuiltin<"get_num_groups", OpenCL_std, GetQuery, NumWorkgroups>;
928 //===----------------------------------------------------------------------===//
929 // Class defining an image query builtin record used for lowering the OpenCL
930 // "get_image_*" calls into OpImageQuerySize/OpImageQuerySizeLod instructions.
932 // name is the demangled name of the given builtin.
933 // set specifies which external instruction set the builtin belongs to.
934 // component specifies the unsigned number of the query component.
935 //===----------------------------------------------------------------------===//
936 class ImageQueryBuiltin<string name, InstructionSet set, bits<32> component> {
937   string Name = name;
938   InstructionSet Set = set;
939   bits<32> Component = component;
942 // Table gathering all the image query builtins.
943 def ImageQueryBuiltins : GenericTable {
944   let FilterClass = "ImageQueryBuiltin";
945   let Fields = ["Name", "Set", "Component"];
946   string TypeOf_Set = "InstructionSet";
949 // Function to lookup image query builtins by their name and set.
950 def lookupImageQueryBuiltin : SearchIndex {
951   let Table = ImageQueryBuiltins;
952   let Key = ["Name", "Set"];
955 // Multiclass used to define at the same time both a demangled builtin record
956 // and a corresponding image query builtin record.
957 multiclass DemangledImageQueryBuiltin<string name, InstructionSet set, int component> {
958   def : DemangledBuiltin<name, set, ImageSizeQuery, 1, 1>;
959   def : ImageQueryBuiltin<name, set, component>;
962 // Image query builtin records:
963 defm : DemangledImageQueryBuiltin<"get_image_width", OpenCL_std, 0>;
964 defm : DemangledImageQueryBuiltin<"get_image_height", OpenCL_std, 1>;
965 defm : DemangledImageQueryBuiltin<"get_image_depth", OpenCL_std, 2>;
966 defm : DemangledImageQueryBuiltin<"get_image_dim", OpenCL_std, 0>;
967 defm : DemangledImageQueryBuiltin<"get_image_array_size", OpenCL_std, 3>;
969 defm : DemangledNativeBuiltin<"get_image_num_samples", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQuerySamples>;
970 defm : DemangledNativeBuiltin<"get_image_num_mip_levels", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQueryLevels>;
972 //===----------------------------------------------------------------------===//
973 // Class defining a "convert_destType<_sat><_roundingMode>" call record for
974 // lowering into OpConvert instructions.
976 // name is the demangled name of the given builtin.
977 // set specifies which external instruction set the builtin belongs to.
978 //===----------------------------------------------------------------------===//
979 class ConvertBuiltin<string name, InstructionSet set> {
980   string Name = name;
981   InstructionSet Set = set;
982   bit IsDestinationSigned = !eq(!find(name, "convert_u"), -1);
983   bit IsSaturated = !not(!eq(!find(name, "_sat"), -1));
984   bit IsRounded = !not(!eq(!find(name, "_rt"), -1));
985   FPRoundingMode RoundingMode = !cond(!not(!eq(!find(name, "_rte"), -1)) : RTE,
986                                   !not(!eq(!find(name, "_rtz"), -1)) : RTZ,
987                                   !not(!eq(!find(name, "_rtp"), -1)) : RTP,
988                                   !not(!eq(!find(name, "_rtn"), -1)) : RTN,
989                                   true : RTE);
992 // Table gathering all the convert builtins.
993 def ConvertBuiltins : GenericTable {
994   let FilterClass = "ConvertBuiltin";
995   let Fields = ["Name", "Set", "IsDestinationSigned", "IsSaturated", "IsRounded", "RoundingMode"];
996   string TypeOf_Set = "InstructionSet";
997   string TypeOf_RoundingMode = "FPRoundingMode";
1000 // Function to lookup convert builtins by their name and set.
1001 def lookupConvertBuiltin : SearchIndex {
1002   let Table = ConvertBuiltins;
1003   let Key = ["Name", "Set"];
1006 // Multiclass used to define at the same time both a demangled builtin records
1007 // and a corresponding convert builtin records.
1008 multiclass DemangledConvertBuiltin<string name, InstructionSet set> {
1009   // Create records for scalar and 2, 4, 8, and 16 element vector conversions.
1010   foreach i = ["", "2", "3", "4", "8", "16"] in {
1011     // Also create records for each rounding mode.
1012     foreach j = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
1013       def : DemangledBuiltin<!strconcat(name, i, j), set, Convert, 1, 1>;
1014       def : ConvertBuiltin<!strconcat(name, i, j), set>;
1016       // Create records with the "_sat" modifier for all conversions except
1017       // those targeting floating-point types.
1018       if !eq(!find(name, "float"), -1) then {
1019         def : DemangledBuiltin<!strconcat(name, i, "_sat", j), set, Convert, 1, 1>;
1020         def : ConvertBuiltin<!strconcat(name, i, "_sat", j), set>;
1021       }
1022     }
1023   }
1026 // Explicit conversion builtin records:
1027 defm : DemangledConvertBuiltin<"convert_char", OpenCL_std>;
1028 defm : DemangledConvertBuiltin<"convert_uchar", OpenCL_std>;
1029 defm : DemangledConvertBuiltin<"convert_short", OpenCL_std>;
1030 defm : DemangledConvertBuiltin<"convert_ushort", OpenCL_std>;
1031 defm : DemangledConvertBuiltin<"convert_int", OpenCL_std>;
1032 defm : DemangledConvertBuiltin<"convert_uint", OpenCL_std>;
1033 defm : DemangledConvertBuiltin<"convert_long", OpenCL_std>;
1034 defm : DemangledConvertBuiltin<"convert_ulong", OpenCL_std>;
1035 defm : DemangledConvertBuiltin<"convert_float", OpenCL_std>;
1037 //===----------------------------------------------------------------------===//
1038 // Class defining a vector data load/store builtin record used for lowering
1039 // into OpExtInst instruction.
1041 // name is the demangled name of the given builtin.
1042 // set specifies which external instruction set the builtin belongs to.
1043 // number specifies the number of the instruction in the external set.
1044 //===----------------------------------------------------------------------===//
1045 class VectorLoadStoreBuiltin<string name, InstructionSet set, int number> {
1046   string Name = name;
1047   InstructionSet Set = set;
1048   bits<32> Number = number;
1049   bit IsRounded = !not(!eq(!find(name, "_rt"), -1));
1050   FPRoundingMode RoundingMode = !cond(!not(!eq(!find(name, "_rte"), -1)) : RTE,
1051                                   !not(!eq(!find(name, "_rtz"), -1)) : RTZ,
1052                                   !not(!eq(!find(name, "_rtp"), -1)) : RTP,
1053                                   !not(!eq(!find(name, "_rtn"), -1)) : RTN,
1054                                   true : RTE);
1057 // Table gathering all the vector data load/store builtins.
1058 def VectorLoadStoreBuiltins : GenericTable {
1059   let FilterClass = "VectorLoadStoreBuiltin";
1060   let Fields = ["Name", "Set", "Number", "IsRounded", "RoundingMode"];
1061   string TypeOf_Set = "InstructionSet";
1062   string TypeOf_RoundingMode = "FPRoundingMode";
1065 // Function to lookup vector data load/store builtins by their name and set.
1066 def lookupVectorLoadStoreBuiltin : SearchIndex {
1067   let Table = VectorLoadStoreBuiltins;
1068   let Key = ["Name", "Set"];
1071 // Multiclass used to define at the same time both a demangled builtin record
1072 // and a corresponding vector data load/store builtin record.
1073 multiclass DemangledVectorLoadStoreBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, int number> {
1074   def : DemangledBuiltin<name, OpenCL_std, VectorLoadStore, minNumArgs, maxNumArgs>;
1075   def : VectorLoadStoreBuiltin<name, OpenCL_std, number>;
1078 // Create records for scalar and 2, 4, 8, and 16 vector element count.
1079 foreach i = ["", "2", "3", "4", "8", "16"] in {
1080   if !eq(i, "") then {
1081     defm : DemangledVectorLoadStoreBuiltin<"vload_half", 2, 2, 173>;
1082     defm : DemangledVectorLoadStoreBuiltin<"vstore_half", 3, 3, 175>;
1083   } else {
1084     defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload_half", i), 3, 3, 174>;
1085     defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i), 3, 3, 177>;
1086   }
1087   defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload", i), 2, 2, 171>;
1088   defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore", i), 3, 3, 172>;
1089   defm : DemangledVectorLoadStoreBuiltin<!strconcat("vloada_half", i), 2, 2, 174>;
1090   defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstorea_half", i), 3, 3, 180>;
1092   // Also create records for each rounding mode.
1093   foreach j = ["_rte", "_rtz", "_rtp", "_rtn"] in {
1094     if !eq(i, "") then {
1095       defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", j), 3, 3, 176>;
1096     } else {
1097       defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i, j), 3, 3, 178>;
1098     }
1099     defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstorea_half", i, j), 3, 3, 181>;
1100   }
1103 //===----------------------------------------------------------------------===//
1104 // Class defining implementation details of SPIR-V builtin types. The info
1105 // in the record is used for lowering into OpType.
1107 // name is the name of the given SPIR-V builtin type.
1108 // operation specifies the SPIR-V opcode the StructType should be lowered to.
1109 //===----------------------------------------------------------------------===//
1110 class BuiltinType<string name, Op operation> {
1111   string Name = name;
1112   Op Opcode = operation;
1115 // Table gathering all the builtin type records.
1116 def BuiltinTypes : GenericTable {
1117   let FilterClass = "BuiltinType";
1118   let Fields = ["Name", "Opcode"];
1121 // Function to lookup builtin types by their demangled name.
1122 def lookupBuiltinType : SearchIndex {
1123   let Table = BuiltinTypes;
1124   let Key = ["Name"];
1127 def : BuiltinType<"spirv.ReserveId", OpTypeReserveId>;
1128 def : BuiltinType<"spirv.PipeStorage", OpTypePipeStorage>;
1129 def : BuiltinType<"spirv.Queue", OpTypeQueue>;
1130 def : BuiltinType<"spirv.Event", OpTypeEvent>;
1131 def : BuiltinType<"spirv.Sampler", OpTypeSampler>;
1132 def : BuiltinType<"spirv.DeviceEvent", OpTypeDeviceEvent>;
1133 def : BuiltinType<"spirv.Image", OpTypeImage>;
1134 def : BuiltinType<"spirv.SampledImage", OpTypeSampledImage>;
1135 def : BuiltinType<"spirv.Pipe", OpTypePipe>;
1138 //===----------------------------------------------------------------------===//
1139 // Class matching an OpenCL builtin type name to an equivalent SPIR-V
1140 // builtin type literal.
1142 // name is the name of the given OpenCL builtin type.
1143 // spirvTypeLiteral is the literal of an equivalent SPIR-V builtin type.
1144 //===----------------------------------------------------------------------===//
1145 class OpenCLType<string name, string spirvTypeLiteral> {
1146   string Name = name;
1147   string SpirvTypeLiteral = spirvTypeLiteral;
1150 // Table gathering all the OpenCL type records.
1151 def OpenCLTypes : GenericTable {
1152   let FilterClass = "OpenCLType";
1153   let Fields = ["Name", "SpirvTypeLiteral"];
1156 // Function to lookup OpenCL types by their name.
1157 def lookupOpenCLType : SearchIndex {
1158   let Table = OpenCLTypes;
1159   let Key = ["Name"];
1162 def : OpenCLType<"opencl.reserve_id_t", "spirv.ReserveId">;
1163 def : OpenCLType<"opencl.event_t", "spirv.Event">;
1164 def : OpenCLType<"opencl.queue_t", "spirv.Queue">;
1165 def : OpenCLType<"opencl.sampler_t", "spirv.Sampler">;
1166 def : OpenCLType<"opencl.clk_event_t", "spirv.DeviceEvent">;
1168 foreach aq = ["_t", "_ro_t", "_wo_t", "_rw_t"] in {
1169   defvar p = !cond(!not(!eq(!find(aq, "_rw_t"), -1)) : "2",
1170                    !not(!eq(!find(aq, "_wo_t"), -1)) : "1",
1171                                                 true : "0");
1172   def : OpenCLType<!strconcat("opencl.pipe", aq), 
1173                    !strconcat("spirv.Pipe._", p)>;
1176 foreach aq = ["_t", "_ro_t", "_wo_t", "_rw_t"] in {
1177   defvar p7 = !cond(!not(!eq(!find(aq, "_rw_t"), -1)) : "2",
1178                     !not(!eq(!find(aq, "_wo_t"), -1)) : "1",
1179                                                  true : "0");
1181   def : OpenCLType<!strconcat("opencl.image1d", aq), 
1182                    !strconcat("spirv.Image._void_0_0_0_0_0_0_", p7)>;
1183   def : OpenCLType<!strconcat("opencl.image1d_array", aq), 
1184                    !strconcat("spirv.Image._void_0_0_1_0_0_0_", p7)>;
1185   def : OpenCLType<!strconcat("opencl.image1d_buffer", aq), 
1186                    !strconcat("spirv.Image._void_5_0_0_0_0_0_", p7)>;
1188   foreach a1 = ["", "_array"] in {
1189     foreach a2 = ["", "_msaa"] in {
1190       foreach a3 = ["", "_depth"] in {
1191         defvar p2 = !cond(!not(!eq(!find(a3, "_depth"), -1)) : "1", true : "0");
1192         defvar p3 = !cond(!not(!eq(!find(a1, "_array"), -1))  : "1", true : "0");
1193         defvar p4 = !cond(!not(!eq(!find(a2, "msaa"), -1))  : "1", true : "0");
1195         def : OpenCLType<!strconcat("opencl.image2d", a1, a2, a3, aq), 
1196                          !strconcat("spirv.Image._void_1_", p2 , "_", p3, "_", p4, "_0_0_", p7)>;
1197       }
1198     }
1199   }
1200   
1201   def : OpenCLType<!strconcat("opencl.image3d", aq), 
1202                    !strconcat("spirv.Image._void_2_0_0_0_0_0_", p7)>;
1205 //===----------------------------------------------------------------------===//
1206 // Classes definining various OpenCL enums.
1207 //===----------------------------------------------------------------------===//
1209 // OpenCL memory_scope enum
1210 def CLMemoryScope : GenericEnum {
1211   let FilterClass = "CLMemoryScope";
1212   let NameField = "Name";
1213   let ValueField = "Value";
1216 class CLMemoryScope<bits<32> value> {
1217   string Name = NAME;
1218   bits<32> Value = value;
1221 def memory_scope_work_item : CLMemoryScope<0>;
1222 def memory_scope_work_group : CLMemoryScope<1>;
1223 def memory_scope_device : CLMemoryScope<2>;
1224 def memory_scope_all_svm_devices : CLMemoryScope<3>;
1225 def memory_scope_sub_group : CLMemoryScope<4>;
1227 // OpenCL sampler addressing mode/bitmask enum
1228 def CLSamplerAddressingMode : GenericEnum {
1229   let FilterClass = "CLSamplerAddressingMode";
1230   let NameField = "Name";
1231   let ValueField = "Value";
1234 class CLSamplerAddressingMode<bits<32> value> {
1235   string Name = NAME;
1236   bits<32> Value = value;
1239 def CLK_ADDRESS_NONE : CLSamplerAddressingMode<0x0>;
1240 def CLK_ADDRESS_CLAMP : CLSamplerAddressingMode<0x4>;
1241 def CLK_ADDRESS_CLAMP_TO_EDGE : CLSamplerAddressingMode<0x2>;
1242 def CLK_ADDRESS_REPEAT : CLSamplerAddressingMode<0x6>;
1243 def CLK_ADDRESS_MIRRORED_REPEAT : CLSamplerAddressingMode<0x8>;
1244 def CLK_ADDRESS_MODE_MASK : CLSamplerAddressingMode<0xE>;
1245 def CLK_NORMALIZED_COORDS_FALSE : CLSamplerAddressingMode<0x0>;
1246 def CLK_NORMALIZED_COORDS_TRUE : CLSamplerAddressingMode<0x1>;
1247 def CLK_FILTER_NEAREST : CLSamplerAddressingMode<0x10>;
1248 def CLK_FILTER_LINEAR : CLSamplerAddressingMode<0x20>;
1250 // OpenCL memory fences
1251 def CLMemoryFenceFlags : GenericEnum {
1252   let FilterClass = "CLMemoryFenceFlags";
1253   let NameField = "Name";
1254   let ValueField = "Value";
1257 class CLMemoryFenceFlags<bits<32> value> {
1258   string Name = NAME;
1259   bits<32> Value = value;
1262 def CLK_LOCAL_MEM_FENCE : CLMemoryFenceFlags<0x1>;
1263 def CLK_GLOBAL_MEM_FENCE : CLMemoryFenceFlags<0x2>;
1264 def CLK_IMAGE_MEM_FENCE : CLMemoryFenceFlags<0x4>;