1 //===-- SPIRVBuiltins.td - Describe SPIRV Builtins ---------*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // TableGen records defining implementation details of demangled builtin
10 // functions and types.
12 //===----------------------------------------------------------------------===//
14 // Define SPIR-V external builtin/instruction sets
15 def InstructionSet : GenericEnum {
16 let FilterClass = "InstructionSet";
17 let NameField = "Name";
18 let ValueField = "Value";
21 class InstructionSet<bits<32> value> {
23 bits<32> Value = value;
26 def OpenCL_std : InstructionSet<0>;
27 def GLSL_std_450 : InstructionSet<1>;
28 def SPV_AMD_shader_trinary_minmax : InstructionSet<2>;
30 // Define various builtin groups
31 def BuiltinGroup : GenericEnum {
32 let FilterClass = "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 Wave : BuiltinGroup;
45 def GetQuery : BuiltinGroup;
46 def ImageSizeQuery : BuiltinGroup;
47 def ImageMiscQuery : BuiltinGroup;
48 def Convert : BuiltinGroup;
49 def ReadImage : BuiltinGroup;
50 def WriteImage : BuiltinGroup;
51 def SampleImage : BuiltinGroup;
52 def Select : BuiltinGroup;
53 def SpecConstant : BuiltinGroup;
54 def Enqueue : BuiltinGroup;
55 def AsyncCopy : BuiltinGroup;
56 def VectorLoadStore : BuiltinGroup;
57 def LoadStore : BuiltinGroup;
58 def IntelSubgroups : BuiltinGroup;
59 def AtomicFloating : BuiltinGroup;
60 def GroupUniform : BuiltinGroup;
62 //===----------------------------------------------------------------------===//
63 // Class defining a demangled builtin record. The information in the record
64 // should be used to expand the builtin into either native SPIR-V instructions
65 // or an external call (in case of builtins without a direct mapping).
67 // name is the demangled name of the given builtin.
68 // set specifies which external instruction set the builtin belongs to.
69 // group specifies to which implementation group given record belongs.
70 // minNumArgs is the minimum required number of arguments for lowering.
71 // maxNumArgs specifies the maximum used number of arguments for lowering.
72 //===----------------------------------------------------------------------===//
73 class DemangledBuiltin<string name, InstructionSet set, BuiltinGroup group, bits<8> minNumArgs, bits<8> maxNumArgs> {
75 InstructionSet Set = set;
76 BuiltinGroup Group = group;
77 bits<8> MinNumArgs = minNumArgs;
78 bits<8> MaxNumArgs = maxNumArgs;
81 // Table gathering all the builtins.
82 def DemangledBuiltins : GenericTable {
83 let FilterClass = "DemangledBuiltin";
84 let Fields = ["Name", "Set", "Group", "MinNumArgs", "MaxNumArgs"];
85 string TypeOf_Set = "InstructionSet";
86 string TypeOf_Group = "BuiltinGroup";
89 // Function to lookup builtins by their demangled name and set.
90 def lookupBuiltin : SearchIndex {
91 let Table = DemangledBuiltins;
92 let Key = ["Name", "Set"];
95 // Dot builtin record:
96 def : DemangledBuiltin<"dot", OpenCL_std, Dot, 2, 2>;
98 // Image builtin records:
99 def : DemangledBuiltin<"read_imagei", OpenCL_std, ReadImage, 2, 4>;
100 def : DemangledBuiltin<"read_imageui", OpenCL_std, ReadImage, 2, 4>;
101 def : DemangledBuiltin<"read_imagef", OpenCL_std, ReadImage, 2, 4>;
103 def : DemangledBuiltin<"write_imagef", OpenCL_std, WriteImage, 3, 4>;
104 def : DemangledBuiltin<"write_imagei", OpenCL_std, WriteImage, 3, 4>;
105 def : DemangledBuiltin<"write_imageui", OpenCL_std, WriteImage, 3, 4>;
106 def : DemangledBuiltin<"write_imageh", OpenCL_std, WriteImage, 3, 4>;
108 def : DemangledBuiltin<"__translate_sampler_initializer", OpenCL_std, SampleImage, 1, 1>;
109 def : DemangledBuiltin<"__spirv_SampledImage", OpenCL_std, SampleImage, 2, 2>;
110 def : DemangledBuiltin<"__spirv_ImageSampleExplicitLod", OpenCL_std, SampleImage, 3, 4>;
112 // Select builtin record:
113 def : DemangledBuiltin<"__spirv_Select", OpenCL_std, Select, 3, 3>;
115 //===----------------------------------------------------------------------===//
116 // Class defining an extended builtin record used for lowering into an
117 // OpExtInst instruction.
119 // name is the demangled name of the given builtin.
120 // set specifies which external instruction set the builtin belongs to.
121 // number specifies the number of the instruction in the external set.
122 //===----------------------------------------------------------------------===//
123 class ExtendedBuiltin<string name, InstructionSet set, int number> {
125 InstructionSet Set = set;
126 bits<32> Number = number;
129 // Table gathering all the extended builtins.
130 def ExtendedBuiltins : GenericTable {
131 let FilterClass = "ExtendedBuiltin";
132 let Fields = ["Name", "Set", "Number"];
133 string TypeOf_Set = "InstructionSet";
136 // Function to lookup extended builtins by their name and set.
137 def lookupExtendedBuiltin : SearchIndex {
138 let Table = ExtendedBuiltins;
139 let Key = ["Name", "Set"];
142 // Function to lookup extended builtins by their set and number.
143 def lookupExtendedBuiltinBySetAndNumber : SearchIndex {
144 let Table = ExtendedBuiltins;
145 let Key = ["Set", "Number"];
148 // OpenCL extended instruction enums
149 def OpenCLExtInst : GenericEnum {
150 let FilterClass = "OpenCLExtInst";
151 let NameField = "Name";
152 let ValueField = "Value";
155 class OpenCLExtInst<string name, bits<32> value> {
157 bits<32> Value = value;
160 // GLSL extended instruction enums
161 def GLSLExtInst : GenericEnum {
162 let FilterClass = "GLSLExtInst";
163 let NameField = "Name";
164 let ValueField = "Value";
167 class GLSLExtInst<string name, bits<32> value> {
169 bits<32> Value = value;
172 // Multiclass used to define at the same time both a demangled builtin record
173 // and a corresponding extended builtin record.
174 multiclass DemangledExtendedBuiltin<string name, InstructionSet set, int number> {
175 def : DemangledBuiltin<name, set, Extended, 1, 3>;
176 def : ExtendedBuiltin<name, set, number>;
178 if !eq(set, OpenCL_std) then {
179 def : OpenCLExtInst<name, number>;
182 if !eq(set, GLSL_std_450) then {
183 def : GLSLExtInst<name, number>;
187 // Extended builtin records:
188 defm : DemangledExtendedBuiltin<"acos", OpenCL_std, 0>;
189 defm : DemangledExtendedBuiltin<"acosh", OpenCL_std, 1>;
190 defm : DemangledExtendedBuiltin<"acospi", OpenCL_std, 2>;
191 defm : DemangledExtendedBuiltin<"asin", OpenCL_std, 3>;
192 defm : DemangledExtendedBuiltin<"asinh", OpenCL_std, 4>;
193 defm : DemangledExtendedBuiltin<"asinpi", OpenCL_std, 5>;
194 defm : DemangledExtendedBuiltin<"atan", OpenCL_std, 6>;
195 defm : DemangledExtendedBuiltin<"atan2", OpenCL_std, 7>;
196 defm : DemangledExtendedBuiltin<"atanh", OpenCL_std, 8>;
197 defm : DemangledExtendedBuiltin<"atanpi", OpenCL_std, 9>;
198 defm : DemangledExtendedBuiltin<"atan2pi", OpenCL_std, 10>;
199 defm : DemangledExtendedBuiltin<"cbrt", OpenCL_std, 11>;
200 defm : DemangledExtendedBuiltin<"ceil", OpenCL_std, 12>;
201 defm : DemangledExtendedBuiltin<"copysign", OpenCL_std, 13>;
202 defm : DemangledExtendedBuiltin<"cos", OpenCL_std, 14>;
203 defm : DemangledExtendedBuiltin<"cosh", OpenCL_std, 15>;
204 defm : DemangledExtendedBuiltin<"cospi", OpenCL_std, 16>;
205 defm : DemangledExtendedBuiltin<"erfc", OpenCL_std, 17>;
206 defm : DemangledExtendedBuiltin<"erf", OpenCL_std, 18>;
207 defm : DemangledExtendedBuiltin<"exp", OpenCL_std, 19>;
208 defm : DemangledExtendedBuiltin<"exp2", OpenCL_std, 20>;
209 defm : DemangledExtendedBuiltin<"exp10", OpenCL_std, 21>;
210 defm : DemangledExtendedBuiltin<"expm1", OpenCL_std, 22>;
211 defm : DemangledExtendedBuiltin<"fabs", OpenCL_std, 23>;
212 defm : DemangledExtendedBuiltin<"fdim", OpenCL_std, 24>;
213 defm : DemangledExtendedBuiltin<"floor", OpenCL_std, 25>;
214 defm : DemangledExtendedBuiltin<"fma", OpenCL_std, 26>;
215 defm : DemangledExtendedBuiltin<"fmax", OpenCL_std, 27>;
216 defm : DemangledExtendedBuiltin<"fmin", OpenCL_std, 28>;
217 defm : DemangledExtendedBuiltin<"fmod", OpenCL_std, 29>;
218 defm : DemangledExtendedBuiltin<"fract", OpenCL_std, 30>;
219 defm : DemangledExtendedBuiltin<"frexp", OpenCL_std, 31>;
220 defm : DemangledExtendedBuiltin<"hypot", OpenCL_std, 32>;
221 defm : DemangledExtendedBuiltin<"ilogb", OpenCL_std, 33>;
222 defm : DemangledExtendedBuiltin<"ldexp", OpenCL_std, 34>;
223 defm : DemangledExtendedBuiltin<"lgamma", OpenCL_std, 35>;
224 defm : DemangledExtendedBuiltin<"lgamma_r", OpenCL_std, 36>;
225 defm : DemangledExtendedBuiltin<"log", OpenCL_std, 37>;
226 defm : DemangledExtendedBuiltin<"log2", OpenCL_std, 38>;
227 defm : DemangledExtendedBuiltin<"log10", OpenCL_std, 39>;
228 defm : DemangledExtendedBuiltin<"log1p", OpenCL_std, 40>;
229 defm : DemangledExtendedBuiltin<"logb", OpenCL_std, 41>;
230 defm : DemangledExtendedBuiltin<"mad", OpenCL_std, 42>;
231 defm : DemangledExtendedBuiltin<"maxmag", OpenCL_std, 43>;
232 defm : DemangledExtendedBuiltin<"minmag", OpenCL_std, 44>;
233 defm : DemangledExtendedBuiltin<"modf", OpenCL_std, 45>;
234 defm : DemangledExtendedBuiltin<"nan", OpenCL_std, 46>;
235 defm : DemangledExtendedBuiltin<"nextafter", OpenCL_std, 47>;
236 defm : DemangledExtendedBuiltin<"pow", OpenCL_std, 48>;
237 defm : DemangledExtendedBuiltin<"pown", OpenCL_std, 49>;
238 defm : DemangledExtendedBuiltin<"powr", OpenCL_std, 50>;
239 defm : DemangledExtendedBuiltin<"remainder", OpenCL_std, 51>;
240 defm : DemangledExtendedBuiltin<"remquo", OpenCL_std, 52>;
241 defm : DemangledExtendedBuiltin<"rint", OpenCL_std, 53>;
242 defm : DemangledExtendedBuiltin<"rootn", OpenCL_std, 54>;
243 defm : DemangledExtendedBuiltin<"round", OpenCL_std, 55>;
244 defm : DemangledExtendedBuiltin<"rsqrt", OpenCL_std, 56>;
245 defm : DemangledExtendedBuiltin<"sin", OpenCL_std, 57>;
246 defm : DemangledExtendedBuiltin<"sincos", OpenCL_std, 58>;
247 defm : DemangledExtendedBuiltin<"sinh", OpenCL_std, 59>;
248 defm : DemangledExtendedBuiltin<"sinpi", OpenCL_std, 60>;
249 defm : DemangledExtendedBuiltin<"sqrt", OpenCL_std, 61>;
250 defm : DemangledExtendedBuiltin<"tan", OpenCL_std, 62>;
251 defm : DemangledExtendedBuiltin<"tanh", OpenCL_std, 63>;
252 defm : DemangledExtendedBuiltin<"tanpi", OpenCL_std, 64>;
253 defm : DemangledExtendedBuiltin<"tgamma", OpenCL_std, 65>;
254 defm : DemangledExtendedBuiltin<"trunc", OpenCL_std, 66>;
255 defm : DemangledExtendedBuiltin<"half_cos", OpenCL_std, 67>;
256 defm : DemangledExtendedBuiltin<"half_divide", OpenCL_std, 68>;
257 defm : DemangledExtendedBuiltin<"half_exp", OpenCL_std, 69>;
258 defm : DemangledExtendedBuiltin<"half_exp2", OpenCL_std, 70>;
259 defm : DemangledExtendedBuiltin<"half_exp10", OpenCL_std, 71>;
260 defm : DemangledExtendedBuiltin<"half_log", OpenCL_std, 72>;
261 defm : DemangledExtendedBuiltin<"half_log2", OpenCL_std, 73>;
262 defm : DemangledExtendedBuiltin<"half_log10", OpenCL_std, 74>;
263 defm : DemangledExtendedBuiltin<"half_powr", OpenCL_std, 75>;
264 defm : DemangledExtendedBuiltin<"half_recip", OpenCL_std, 76>;
265 defm : DemangledExtendedBuiltin<"half_rsqrt", OpenCL_std, 77>;
266 defm : DemangledExtendedBuiltin<"half_sin", OpenCL_std, 78>;
267 defm : DemangledExtendedBuiltin<"half_sqrt", OpenCL_std, 79>;
268 defm : DemangledExtendedBuiltin<"half_tan", OpenCL_std, 80>;
269 defm : DemangledExtendedBuiltin<"native_cos", OpenCL_std, 81>;
270 defm : DemangledExtendedBuiltin<"native_divide", OpenCL_std, 82>;
271 defm : DemangledExtendedBuiltin<"native_exp", OpenCL_std, 83>;
272 defm : DemangledExtendedBuiltin<"native_exp2", OpenCL_std, 84>;
273 defm : DemangledExtendedBuiltin<"native_exp10", OpenCL_std, 85>;
274 defm : DemangledExtendedBuiltin<"native_log", OpenCL_std, 86>;
275 defm : DemangledExtendedBuiltin<"native_log2", OpenCL_std, 87>;
276 defm : DemangledExtendedBuiltin<"native_log10", OpenCL_std, 88>;
277 defm : DemangledExtendedBuiltin<"native_powr", OpenCL_std, 89>;
278 defm : DemangledExtendedBuiltin<"native_recip", OpenCL_std, 90>;
279 defm : DemangledExtendedBuiltin<"native_rsqrt", OpenCL_std, 91>;
280 defm : DemangledExtendedBuiltin<"native_sin", OpenCL_std, 92>;
281 defm : DemangledExtendedBuiltin<"native_sqrt", OpenCL_std, 93>;
282 defm : DemangledExtendedBuiltin<"native_tan", OpenCL_std, 94>;
283 defm : DemangledExtendedBuiltin<"s_abs", OpenCL_std, 141>;
284 defm : DemangledExtendedBuiltin<"s_abs_diff", OpenCL_std, 142>;
285 defm : DemangledExtendedBuiltin<"s_add_sat", OpenCL_std, 143>;
286 defm : DemangledExtendedBuiltin<"u_add_sat", OpenCL_std, 144>;
287 defm : DemangledExtendedBuiltin<"s_hadd", OpenCL_std, 145>;
288 defm : DemangledExtendedBuiltin<"u_hadd", OpenCL_std, 146>;
289 defm : DemangledExtendedBuiltin<"s_rhadd", OpenCL_std, 147>;
290 defm : DemangledExtendedBuiltin<"u_rhadd", OpenCL_std, 148>;
291 defm : DemangledExtendedBuiltin<"s_clamp", OpenCL_std, 149>;
292 defm : DemangledExtendedBuiltin<"u_clamp", OpenCL_std, 150>;
293 defm : DemangledExtendedBuiltin<"clz", OpenCL_std, 151>;
294 defm : DemangledExtendedBuiltin<"ctz", OpenCL_std, 152>;
295 defm : DemangledExtendedBuiltin<"s_mad_hi", OpenCL_std, 153>;
296 defm : DemangledExtendedBuiltin<"u_mad_sat", OpenCL_std, 154>;
297 defm : DemangledExtendedBuiltin<"s_mad_sat", OpenCL_std, 155>;
298 defm : DemangledExtendedBuiltin<"s_max", OpenCL_std, 156>;
299 defm : DemangledExtendedBuiltin<"u_max", OpenCL_std, 157>;
300 defm : DemangledExtendedBuiltin<"s_min", OpenCL_std, 158>;
301 defm : DemangledExtendedBuiltin<"u_min", OpenCL_std, 159>;
302 defm : DemangledExtendedBuiltin<"s_mul_hi", OpenCL_std, 160>;
303 defm : DemangledExtendedBuiltin<"rotate", OpenCL_std, 161>;
304 defm : DemangledExtendedBuiltin<"s_sub_sat", OpenCL_std, 162>;
305 defm : DemangledExtendedBuiltin<"u_sub_sat", OpenCL_std, 163>;
306 defm : DemangledExtendedBuiltin<"u_upsample", OpenCL_std, 164>;
307 defm : DemangledExtendedBuiltin<"s_upsample", OpenCL_std, 165>;
308 defm : DemangledExtendedBuiltin<"popcount", OpenCL_std, 166>;
309 defm : DemangledExtendedBuiltin<"s_mad24", OpenCL_std, 167>;
310 defm : DemangledExtendedBuiltin<"u_mad24", OpenCL_std, 168>;
311 defm : DemangledExtendedBuiltin<"s_mul24", OpenCL_std, 169>;
312 defm : DemangledExtendedBuiltin<"u_mul24", OpenCL_std, 170>;
313 defm : DemangledExtendedBuiltin<"u_abs", OpenCL_std, 201>;
314 defm : DemangledExtendedBuiltin<"u_abs_diff", OpenCL_std, 202>;
315 defm : DemangledExtendedBuiltin<"u_mul_hi", OpenCL_std, 203>;
316 defm : DemangledExtendedBuiltin<"u_mad_hi", OpenCL_std, 204>;
317 defm : DemangledExtendedBuiltin<"fclamp", OpenCL_std, 95>;
318 defm : DemangledExtendedBuiltin<"degrees", OpenCL_std, 96>;
319 defm : DemangledExtendedBuiltin<"fmax_common", OpenCL_std, 97>;
320 defm : DemangledExtendedBuiltin<"fmin_common", OpenCL_std, 98>;
321 defm : DemangledExtendedBuiltin<"mix", OpenCL_std, 99>;
322 defm : DemangledExtendedBuiltin<"radians", OpenCL_std, 100>;
323 defm : DemangledExtendedBuiltin<"step", OpenCL_std, 101>;
324 defm : DemangledExtendedBuiltin<"smoothstep", OpenCL_std, 102>;
325 defm : DemangledExtendedBuiltin<"sign", OpenCL_std, 103>;
326 defm : DemangledExtendedBuiltin<"cross", OpenCL_std, 104>;
327 defm : DemangledExtendedBuiltin<"distance", OpenCL_std, 105>;
328 defm : DemangledExtendedBuiltin<"length", OpenCL_std, 106>;
329 defm : DemangledExtendedBuiltin<"normalize", OpenCL_std, 107>;
330 defm : DemangledExtendedBuiltin<"fast_distance", OpenCL_std, 108>;
331 defm : DemangledExtendedBuiltin<"fast_length", OpenCL_std, 109>;
332 defm : DemangledExtendedBuiltin<"fast_normalize", OpenCL_std, 110>;
333 defm : DemangledExtendedBuiltin<"bitselect", OpenCL_std, 186>;
334 defm : DemangledExtendedBuiltin<"select", OpenCL_std, 187>;
335 defm : DemangledExtendedBuiltin<"vloadn", OpenCL_std, 171>;
336 defm : DemangledExtendedBuiltin<"vstoren", OpenCL_std, 172>;
337 defm : DemangledExtendedBuiltin<"vload_half", OpenCL_std, 173>;
338 defm : DemangledExtendedBuiltin<"vload_halfn", OpenCL_std, 174>;
339 defm : DemangledExtendedBuiltin<"vstore_half", OpenCL_std, 175>;
340 defm : DemangledExtendedBuiltin<"vstore_half_r", OpenCL_std, 176>;
341 defm : DemangledExtendedBuiltin<"vstore_halfn", OpenCL_std, 177>;
342 defm : DemangledExtendedBuiltin<"vstore_halfn_r", OpenCL_std, 178>;
343 defm : DemangledExtendedBuiltin<"vloada_halfn", OpenCL_std, 179>;
344 defm : DemangledExtendedBuiltin<"vstorea_halfn", OpenCL_std, 180>;
345 defm : DemangledExtendedBuiltin<"vstorea_halfn_r", OpenCL_std, 181>;
346 defm : DemangledExtendedBuiltin<"shuffle", OpenCL_std, 182>;
347 defm : DemangledExtendedBuiltin<"shuffle2", OpenCL_std, 183>;
348 defm : DemangledExtendedBuiltin<"printf", OpenCL_std, 184>;
349 defm : DemangledExtendedBuiltin<"prefetch", OpenCL_std, 185>;
351 defm : DemangledExtendedBuiltin<"Round", GLSL_std_450, 1>;
352 defm : DemangledExtendedBuiltin<"RoundEven", GLSL_std_450, 2>;
353 defm : DemangledExtendedBuiltin<"Trunc", GLSL_std_450, 3>;
354 defm : DemangledExtendedBuiltin<"FAbs", GLSL_std_450, 4>;
355 defm : DemangledExtendedBuiltin<"SAbs", GLSL_std_450, 5>;
356 defm : DemangledExtendedBuiltin<"FSign", GLSL_std_450, 6>;
357 defm : DemangledExtendedBuiltin<"SSign", GLSL_std_450, 7>;
358 defm : DemangledExtendedBuiltin<"Floor", GLSL_std_450, 8>;
359 defm : DemangledExtendedBuiltin<"Ceil", GLSL_std_450, 9>;
360 defm : DemangledExtendedBuiltin<"Fract", GLSL_std_450, 10>;
361 defm : DemangledExtendedBuiltin<"Radians", GLSL_std_450, 11>;
362 defm : DemangledExtendedBuiltin<"Degrees", GLSL_std_450, 12>;
363 defm : DemangledExtendedBuiltin<"Sin", GLSL_std_450, 13>;
364 defm : DemangledExtendedBuiltin<"Cos", GLSL_std_450, 14>;
365 defm : DemangledExtendedBuiltin<"Tan", GLSL_std_450, 15>;
366 defm : DemangledExtendedBuiltin<"Asin", GLSL_std_450, 16>;
367 defm : DemangledExtendedBuiltin<"Acos", GLSL_std_450, 17>;
368 defm : DemangledExtendedBuiltin<"Atan", GLSL_std_450, 18>;
369 defm : DemangledExtendedBuiltin<"Sinh", GLSL_std_450, 19>;
370 defm : DemangledExtendedBuiltin<"Cosh", GLSL_std_450, 20>;
371 defm : DemangledExtendedBuiltin<"Tanh", GLSL_std_450, 21>;
372 defm : DemangledExtendedBuiltin<"Asinh", GLSL_std_450, 22>;
373 defm : DemangledExtendedBuiltin<"Acosh", GLSL_std_450, 23>;
374 defm : DemangledExtendedBuiltin<"Atanh", GLSL_std_450, 24>;
375 defm : DemangledExtendedBuiltin<"Atan2", GLSL_std_450, 25>;
376 defm : DemangledExtendedBuiltin<"Pow", GLSL_std_450, 26>;
377 defm : DemangledExtendedBuiltin<"Exp", GLSL_std_450, 27>;
378 defm : DemangledExtendedBuiltin<"Log", GLSL_std_450, 28>;
379 defm : DemangledExtendedBuiltin<"Exp2", GLSL_std_450, 29>;
380 defm : DemangledExtendedBuiltin<"Log2", GLSL_std_450, 30>;
381 defm : DemangledExtendedBuiltin<"Sqrt", GLSL_std_450, 31>;
382 defm : DemangledExtendedBuiltin<"InverseSqrt", GLSL_std_450, 32>;
383 defm : DemangledExtendedBuiltin<"Determinant", GLSL_std_450, 33>;
384 defm : DemangledExtendedBuiltin<"MatrixInverse", GLSL_std_450, 34>;
385 defm : DemangledExtendedBuiltin<"Modf", GLSL_std_450, 35>;
386 defm : DemangledExtendedBuiltin<"ModfStruct", GLSL_std_450, 36>;
387 defm : DemangledExtendedBuiltin<"FMin", GLSL_std_450, 37>;
388 defm : DemangledExtendedBuiltin<"UMin", GLSL_std_450, 38>;
389 defm : DemangledExtendedBuiltin<"SMin", GLSL_std_450, 39>;
390 defm : DemangledExtendedBuiltin<"FMax", GLSL_std_450, 40>;
391 defm : DemangledExtendedBuiltin<"UMax", GLSL_std_450, 41>;
392 defm : DemangledExtendedBuiltin<"SMax", GLSL_std_450, 42>;
393 defm : DemangledExtendedBuiltin<"FClamp", GLSL_std_450, 43>;
394 defm : DemangledExtendedBuiltin<"UClamp", GLSL_std_450, 44>;
395 defm : DemangledExtendedBuiltin<"SClamp", GLSL_std_450, 45>;
396 defm : DemangledExtendedBuiltin<"FMix", GLSL_std_450, 46>;
397 defm : DemangledExtendedBuiltin<"Step", GLSL_std_450, 48>;
398 defm : DemangledExtendedBuiltin<"SmoothStep", GLSL_std_450, 49>;
399 defm : DemangledExtendedBuiltin<"Fma", GLSL_std_450, 50>;
400 defm : DemangledExtendedBuiltin<"Frexp", GLSL_std_450, 51>;
401 defm : DemangledExtendedBuiltin<"FrexpStruct", GLSL_std_450, 52>;
402 defm : DemangledExtendedBuiltin<"Ldexp", GLSL_std_450, 53>;
403 defm : DemangledExtendedBuiltin<"PackSnorm4x8", GLSL_std_450, 54>;
404 defm : DemangledExtendedBuiltin<"PackUnorm4x8", GLSL_std_450, 55>;
405 defm : DemangledExtendedBuiltin<"PackSnorm2x16", GLSL_std_450, 56>;
406 defm : DemangledExtendedBuiltin<"PackUnorm2x16", GLSL_std_450, 57>;
407 defm : DemangledExtendedBuiltin<"PackHalf2x16", GLSL_std_450, 58>;
408 defm : DemangledExtendedBuiltin<"PackDouble2x32", GLSL_std_450, 59>;
409 defm : DemangledExtendedBuiltin<"UnpackSnorm2x16", GLSL_std_450, 60>;
410 defm : DemangledExtendedBuiltin<"UnpackUnorm2x16", GLSL_std_450, 61>;
411 defm : DemangledExtendedBuiltin<"UnpackHalf2x16", GLSL_std_450, 62>;
412 defm : DemangledExtendedBuiltin<"UnpackSnorm4x8", GLSL_std_450, 63>;
413 defm : DemangledExtendedBuiltin<"UnpackUnorm4x8", GLSL_std_450, 64>;
414 defm : DemangledExtendedBuiltin<"UnpackDouble2x32", GLSL_std_450, 65>;
415 defm : DemangledExtendedBuiltin<"Length", GLSL_std_450, 66>;
416 defm : DemangledExtendedBuiltin<"Distance", GLSL_std_450, 67>;
417 defm : DemangledExtendedBuiltin<"Cross", GLSL_std_450, 68>;
418 defm : DemangledExtendedBuiltin<"Normalize", GLSL_std_450, 69>;
419 defm : DemangledExtendedBuiltin<"FaceForward", GLSL_std_450, 70>;
420 defm : DemangledExtendedBuiltin<"Reflect", GLSL_std_450, 71>;
421 defm : DemangledExtendedBuiltin<"Refract", GLSL_std_450, 72>;
422 defm : DemangledExtendedBuiltin<"FindILsb", GLSL_std_450, 73>;
423 defm : DemangledExtendedBuiltin<"FindSMsb", GLSL_std_450, 74>;
424 defm : DemangledExtendedBuiltin<"FindUMsb", GLSL_std_450, 75>;
425 defm : DemangledExtendedBuiltin<"InterpolateAtCentroid", GLSL_std_450, 76>;
426 defm : DemangledExtendedBuiltin<"InterpolateAtSample", GLSL_std_450, 77>;
427 defm : DemangledExtendedBuiltin<"InterpolateAtOffset", GLSL_std_450, 78>;
428 defm : DemangledExtendedBuiltin<"NMin", GLSL_std_450, 79>;
429 defm : DemangledExtendedBuiltin<"NMax", GLSL_std_450, 80>;
430 defm : DemangledExtendedBuiltin<"NClamp", GLSL_std_450, 81>;
432 //===----------------------------------------------------------------------===//
433 // Class defining an native builtin record used for direct translation into a
434 // SPIR-V instruction.
436 // name is the demangled name of the given builtin.
437 // set specifies which external instruction set the builtin belongs to.
438 // opcode specifies the SPIR-V operation code of the generated instruction.
439 //===----------------------------------------------------------------------===//
440 class NativeBuiltin<string name, InstructionSet set, Op operation> {
442 InstructionSet Set = set;
443 Op Opcode = operation;
446 // Table gathering all the native builtins.
447 def NativeBuiltins : GenericTable {
448 let FilterClass = "NativeBuiltin";
449 let Fields = ["Name", "Set", "Opcode"];
450 string TypeOf_Set = "InstructionSet";
453 // Function to lookup native builtins by their name and set.
454 def lookupNativeBuiltin : SearchIndex {
455 let Table = NativeBuiltins;
456 let Key = ["Name", "Set"];
459 // Multiclass used to define at the same time both an incoming builtin record
460 // and a corresponding native builtin record.
461 multiclass DemangledNativeBuiltin<string name, InstructionSet set, BuiltinGroup group, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
462 def : DemangledBuiltin<name, set, group, minNumArgs, maxNumArgs>;
463 def : NativeBuiltin<name, set, operation>;
466 // Relational builtin records:
467 defm : DemangledNativeBuiltin<"isequal", OpenCL_std, Relational, 2, 2, OpFOrdEqual>;
468 defm : DemangledNativeBuiltin<"__spirv_FOrdEqual", OpenCL_std, Relational, 2, 2, OpFOrdEqual>;
469 defm : DemangledNativeBuiltin<"isnotequal", OpenCL_std, Relational, 2, 2, OpFUnordNotEqual>;
470 defm : DemangledNativeBuiltin<"__spirv_FUnordNotEqual", OpenCL_std, Relational, 2, 2, OpFUnordNotEqual>;
471 defm : DemangledNativeBuiltin<"isgreater", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThan>;
472 defm : DemangledNativeBuiltin<"__spirv_FOrdGreaterThan", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThan>;
473 defm : DemangledNativeBuiltin<"isgreaterequal", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThanEqual>;
474 defm : DemangledNativeBuiltin<"__spirv_FOrdGreaterThanEqual", OpenCL_std, Relational, 2, 2, OpFOrdGreaterThanEqual>;
475 defm : DemangledNativeBuiltin<"isless", OpenCL_std, Relational, 2, 2, OpFOrdLessThan>;
476 defm : DemangledNativeBuiltin<"__spirv_FOrdLessThan", OpenCL_std, Relational, 2, 2, OpFOrdLessThan>;
477 defm : DemangledNativeBuiltin<"islessequal", OpenCL_std, Relational, 2, 2, OpFOrdLessThanEqual>;
478 defm : DemangledNativeBuiltin<"__spirv_FOrdLessThanEqual", OpenCL_std, Relational, 2, 2, OpFOrdLessThanEqual>;
479 defm : DemangledNativeBuiltin<"islessgreater", OpenCL_std, Relational, 2, 2, OpFOrdNotEqual>;
480 defm : DemangledNativeBuiltin<"__spirv_FOrdNotEqual", OpenCL_std, Relational, 2, 2, OpFOrdNotEqual>;
481 defm : DemangledNativeBuiltin<"isordered", OpenCL_std, Relational, 2, 2, OpOrdered>;
482 defm : DemangledNativeBuiltin<"__spirv_Ordered", OpenCL_std, Relational, 2, 2, OpOrdered>;
483 defm : DemangledNativeBuiltin<"isunordered", OpenCL_std, Relational, 2, 2, OpUnordered>;
484 defm : DemangledNativeBuiltin<"__spirv_Unordered", OpenCL_std, Relational, 2, 2, OpUnordered>;
485 defm : DemangledNativeBuiltin<"isfinite", OpenCL_std, Relational, 1, 1, OpIsFinite>;
486 defm : DemangledNativeBuiltin<"__spirv_IsFinite", OpenCL_std, Relational, 1, 1, OpIsFinite>;
487 defm : DemangledNativeBuiltin<"isinf", OpenCL_std, Relational, 1, 1, OpIsInf>;
488 defm : DemangledNativeBuiltin<"__spirv_IsInf", OpenCL_std, Relational, 1, 1, OpIsInf>;
489 defm : DemangledNativeBuiltin<"isnan", OpenCL_std, Relational, 1, 1, OpIsNan>;
490 defm : DemangledNativeBuiltin<"__spirv_IsNan", OpenCL_std, Relational, 1, 1, OpIsNan>;
491 defm : DemangledNativeBuiltin<"isnormal", OpenCL_std, Relational, 1, 1, OpIsNormal>;
492 defm : DemangledNativeBuiltin<"__spirv_IsNormal", OpenCL_std, Relational, 1, 1, OpIsNormal>;
493 defm : DemangledNativeBuiltin<"signbit", OpenCL_std, Relational, 1, 1, OpSignBitSet>;
494 defm : DemangledNativeBuiltin<"__spirv_SignBitSet", OpenCL_std, Relational, 1, 1, OpSignBitSet>;
495 defm : DemangledNativeBuiltin<"any", OpenCL_std, Relational, 1, 1, OpAny>;
496 defm : DemangledNativeBuiltin<"__spirv_Any", OpenCL_std, Relational, 1, 1, OpAny>;
497 defm : DemangledNativeBuiltin<"all", OpenCL_std, Relational, 1, 1, OpAll>;
498 defm : DemangledNativeBuiltin<"__spirv_All", OpenCL_std, Relational, 1, 1, OpAll>;
500 // Atomic builtin records:
501 defm : DemangledNativeBuiltin<"atomic_init", OpenCL_std, Atomic, 2, 2, OpStore>;
502 defm : DemangledNativeBuiltin<"atomic_load", OpenCL_std, Atomic, 1, 1, OpAtomicLoad>;
503 defm : DemangledNativeBuiltin<"atomic_load_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicLoad>;
504 defm : DemangledNativeBuiltin<"__spirv_AtomicLoad", OpenCL_std, Atomic, 3, 3, OpAtomicLoad>;
505 defm : DemangledNativeBuiltin<"atomic_store", OpenCL_std, Atomic, 2, 2, OpAtomicStore>;
506 defm : DemangledNativeBuiltin<"atomic_store_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicStore>;
507 defm : DemangledNativeBuiltin<"__spirv_AtomicStore", OpenCL_std, Atomic, 4, 4, OpAtomicStore>;
508 defm : DemangledNativeBuiltin<"atomic_compare_exchange_strong", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
509 defm : DemangledNativeBuiltin<"__spirv_AtomicCompareExchange", OpenCL_std, Atomic, 6, 6, OpAtomicCompareExchange>;
510 defm : DemangledNativeBuiltin<"atomic_compare_exchange_strong_explicit", OpenCL_std, Atomic, 5, 6, OpAtomicCompareExchange>;
511 defm : DemangledNativeBuiltin<"atomic_compare_exchange_weak", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchangeWeak>;
512 defm : DemangledNativeBuiltin<"atomic_compare_exchange_weak_explicit", OpenCL_std, Atomic, 5, 6, OpAtomicCompareExchangeWeak>;
513 defm : DemangledNativeBuiltin<"__spirv_AtomicCompareExchangeWeak", OpenCL_std, Atomic, 6, 6, OpAtomicCompareExchangeWeak>;
514 defm : DemangledNativeBuiltin<"atom_cmpxchg", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
515 defm : DemangledNativeBuiltin<"atomic_cmpxchg", OpenCL_std, Atomic, 3, 6, OpAtomicCompareExchange>;
516 defm : DemangledNativeBuiltin<"atom_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
517 defm : DemangledNativeBuiltin<"atomic_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
518 defm : DemangledNativeBuiltin<"__spirv_AtomicIAdd", OpenCL_std, Atomic, 4, 4, OpAtomicIAdd>;
519 defm : DemangledNativeBuiltin<"atom_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
520 defm : DemangledNativeBuiltin<"atomic_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
521 defm : DemangledNativeBuiltin<"__spirv_AtomicISub", OpenCL_std, Atomic, 4, 4, OpAtomicISub>;
522 defm : DemangledNativeBuiltin<"atom_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
523 defm : DemangledNativeBuiltin<"atomic_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
524 defm : DemangledNativeBuiltin<"__spirv_AtomicOr", OpenCL_std, Atomic, 4, 4, OpAtomicOr>;
525 defm : DemangledNativeBuiltin<"atom_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
526 defm : DemangledNativeBuiltin<"atomic_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
527 defm : DemangledNativeBuiltin<"__spirv_AtomicXor", OpenCL_std, Atomic, 4, 4, OpAtomicXor>;
528 defm : DemangledNativeBuiltin<"atom_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
529 defm : DemangledNativeBuiltin<"atomic_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
530 defm : DemangledNativeBuiltin<"__spirv_AtomicAnd", OpenCL_std, Atomic, 4, 4, OpAtomicAnd>;
531 defm : DemangledNativeBuiltin<"atomic_exchange", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
532 defm : DemangledNativeBuiltin<"atomic_exchange_explicit", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
533 defm : DemangledNativeBuiltin<"AtomicEx__spirv_change", OpenCL_std, Atomic, 2, 4, OpAtomicExchange>;
534 defm : DemangledNativeBuiltin<"atomic_work_item_fence", OpenCL_std, Atomic, 1, 3, OpMemoryBarrier>;
535 defm : DemangledNativeBuiltin<"__spirv_MemoryBarrier", OpenCL_std, Atomic, 2, 2, OpMemoryBarrier>;
536 defm : DemangledNativeBuiltin<"atomic_fetch_add", OpenCL_std, Atomic, 2, 4, OpAtomicIAdd>;
537 defm : DemangledNativeBuiltin<"atomic_fetch_sub", OpenCL_std, Atomic, 2, 4, OpAtomicISub>;
538 defm : DemangledNativeBuiltin<"atomic_fetch_or", OpenCL_std, Atomic, 2, 4, OpAtomicOr>;
539 defm : DemangledNativeBuiltin<"atomic_fetch_xor", OpenCL_std, Atomic, 2, 4, OpAtomicXor>;
540 defm : DemangledNativeBuiltin<"atomic_fetch_and", OpenCL_std, Atomic, 2, 4, OpAtomicAnd>;
541 defm : DemangledNativeBuiltin<"atomic_fetch_add_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicIAdd>;
542 defm : DemangledNativeBuiltin<"atomic_fetch_sub_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicISub>;
543 defm : DemangledNativeBuiltin<"atomic_fetch_or_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicOr>;
544 defm : DemangledNativeBuiltin<"atomic_fetch_xor_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicXor>;
545 defm : DemangledNativeBuiltin<"atomic_fetch_and_explicit", OpenCL_std, Atomic, 4, 6, OpAtomicAnd>;
546 defm : DemangledNativeBuiltin<"atomic_flag_test_and_set", OpenCL_std, Atomic, 1, 1, OpAtomicFlagTestAndSet>;
547 defm : DemangledNativeBuiltin<"__spirv_AtomicFlagTestAndSet", OpenCL_std, Atomic, 3, 3, OpAtomicFlagTestAndSet>;
548 defm : DemangledNativeBuiltin<"atomic_flag_test_and_set_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicFlagTestAndSet>;
549 defm : DemangledNativeBuiltin<"atomic_flag_clear", OpenCL_std, Atomic, 1, 1, OpAtomicFlagClear>;
550 defm : DemangledNativeBuiltin<"__spirv_AtomicFlagClear", OpenCL_std, Atomic, 3, 3, OpAtomicFlagClear>;
551 defm : DemangledNativeBuiltin<"atomic_flag_clear_explicit", OpenCL_std, Atomic, 2, 3, OpAtomicFlagClear>;
553 // Barrier builtin records:
554 defm : DemangledNativeBuiltin<"barrier", OpenCL_std, Barrier, 1, 3, OpControlBarrier>;
555 defm : DemangledNativeBuiltin<"work_group_barrier", OpenCL_std, Barrier, 1, 3, OpControlBarrier>;
556 defm : DemangledNativeBuiltin<"__spirv_ControlBarrier", OpenCL_std, Barrier, 3, 3, OpControlBarrier>;
558 // Kernel enqueue builtin records:
559 defm : DemangledNativeBuiltin<"__enqueue_kernel_basic", OpenCL_std, Enqueue, 5, 5, OpEnqueueKernel>;
560 defm : DemangledNativeBuiltin<"__enqueue_kernel_basic_events", OpenCL_std, Enqueue, 8, 8, OpEnqueueKernel>;
561 defm : DemangledNativeBuiltin<"__enqueue_kernel_varargs", OpenCL_std, Enqueue, 7, 7, OpEnqueueKernel>;
562 defm : DemangledNativeBuiltin<"__enqueue_kernel_events_varargs", OpenCL_std, Enqueue, 10, 10, OpEnqueueKernel>;
563 defm : DemangledNativeBuiltin<"__spirv_EnqueueKernel", OpenCL_std, Enqueue, 10, 0, OpEnqueueKernel>;
564 defm : DemangledNativeBuiltin<"retain_event", OpenCL_std, Enqueue, 1, 1, OpRetainEvent>;
565 defm : DemangledNativeBuiltin<"__spirv_RetainEvent", OpenCL_std, Enqueue, 1, 1, OpRetainEvent>;
566 defm : DemangledNativeBuiltin<"release_event", OpenCL_std, Enqueue, 1, 1, OpReleaseEvent>;
567 defm : DemangledNativeBuiltin<"__spirv_ReleaseEvent", OpenCL_std, Enqueue, 1, 1, OpReleaseEvent>;
568 defm : DemangledNativeBuiltin<"create_user_event", OpenCL_std, Enqueue, 0, 0, OpCreateUserEvent>;
569 defm : DemangledNativeBuiltin<"__spirv_CreateUserEvent", OpenCL_std, Enqueue, 0, 0, OpCreateUserEvent>;
570 defm : DemangledNativeBuiltin<"is_valid_event", OpenCL_std, Enqueue, 1, 1, OpIsValidEvent>;
571 defm : DemangledNativeBuiltin<"__spirv_IsValidEvent", OpenCL_std, Enqueue, 1, 1, OpIsValidEvent>;
572 defm : DemangledNativeBuiltin<"set_user_event_status", OpenCL_std, Enqueue, 2, 2, OpSetUserEventStatus>;
573 defm : DemangledNativeBuiltin<"__spirv_SetUserEventStatus", OpenCL_std, Enqueue, 2, 2, OpSetUserEventStatus>;
574 defm : DemangledNativeBuiltin<"capture_event_profiling_info", OpenCL_std, Enqueue, 3, 3, OpCaptureEventProfilingInfo>;
575 defm : DemangledNativeBuiltin<"__spirv_CaptureEventProfilingInfo", OpenCL_std, Enqueue, 3, 3, OpCaptureEventProfilingInfo>;
576 defm : DemangledNativeBuiltin<"get_default_queue", OpenCL_std, Enqueue, 0, 0, OpGetDefaultQueue>;
577 defm : DemangledNativeBuiltin<"__spirv_GetDefaultQueue", OpenCL_std, Enqueue, 0, 0, OpGetDefaultQueue>;
578 defm : DemangledNativeBuiltin<"ndrange_1D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
579 defm : DemangledNativeBuiltin<"ndrange_2D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
580 defm : DemangledNativeBuiltin<"ndrange_3D", OpenCL_std, Enqueue, 1, 3, OpBuildNDRange>;
582 // Spec constant builtin records:
583 defm : DemangledNativeBuiltin<"__spirv_SpecConstant", OpenCL_std, SpecConstant, 2, 2, OpSpecConstant>;
584 defm : DemangledNativeBuiltin<"__spirv_SpecConstantComposite", OpenCL_std, SpecConstant, 1, 0, OpSpecConstantComposite>;
586 // Async Copy and Prefetch builtin records:
587 defm : DemangledNativeBuiltin<"async_work_group_copy", OpenCL_std, AsyncCopy, 4, 4, OpGroupAsyncCopy>;
588 defm : DemangledNativeBuiltin<"__spirv_GroupAsyncCopy", OpenCL_std, AsyncCopy, 6, 6, OpGroupAsyncCopy>;
589 defm : DemangledNativeBuiltin<"wait_group_events", OpenCL_std, AsyncCopy, 2, 2, OpGroupWaitEvents>;
590 defm : DemangledNativeBuiltin<"__spirv_GroupWaitEvents", OpenCL_std, AsyncCopy, 3, 3, OpGroupWaitEvents>;
592 // Load and store builtin records:
593 defm : DemangledNativeBuiltin<"__spirv_Load", OpenCL_std, LoadStore, 1, 3, OpLoad>;
594 defm : DemangledNativeBuiltin<"__spirv_Store", OpenCL_std, LoadStore, 2, 4, OpStore>;
596 //===----------------------------------------------------------------------===//
597 // Class defining a work/sub group builtin that should be translated into a
598 // SPIR-V instruction using the defined properties.
600 // name is the demangled name of the given builtin.
601 // opcode specifies the SPIR-V operation code of the generated instruction.
602 //===----------------------------------------------------------------------===//
603 class GroupBuiltin<string name, Op operation> {
605 Op Opcode = operation;
606 bits<32> GroupOperation = !cond(!not(!eq(!find(name, "group_reduce"), -1)) : Reduce.Value,
607 !not(!eq(!find(name, "group_scan_inclusive"), -1)) : InclusiveScan.Value,
608 !not(!eq(!find(name, "group_scan_exclusive"), -1)) : ExclusiveScan.Value,
609 !not(!eq(!find(name, "group_ballot_bit_count"), -1)) : Reduce.Value,
610 !not(!eq(!find(name, "group_ballot_inclusive_scan"), -1)) : InclusiveScan.Value,
611 !not(!eq(!find(name, "group_ballot_exclusive_scan"), -1)) : ExclusiveScan.Value,
612 !not(!eq(!find(name, "group_non_uniform_reduce"), -1)) : Reduce.Value,
613 !not(!eq(!find(name, "group_non_uniform_scan_inclusive"), -1)) : InclusiveScan.Value,
614 !not(!eq(!find(name, "group_non_uniform_scan_exclusive"), -1)) : ExclusiveScan.Value,
615 !not(!eq(!find(name, "group_non_uniform_reduce_logical"), -1)) : Reduce.Value,
616 !not(!eq(!find(name, "group_non_uniform_scan_inclusive_logical"), -1)) : InclusiveScan.Value,
617 !not(!eq(!find(name, "group_non_uniform_scan_exclusive_logical"), -1)) : ExclusiveScan.Value,
618 !not(!eq(!find(name, "group_clustered_reduce"), -1)) : ClusteredReduce.Value,
619 !not(!eq(!find(name, "group_clustered_reduce_logical"), -1)) : ClusteredReduce.Value,
621 bit IsElect = !eq(operation, OpGroupNonUniformElect);
622 bit IsAllOrAny = !or(!eq(operation, OpGroupAll),
623 !eq(operation, OpGroupAny),
624 !eq(operation, OpGroupNonUniformAll),
625 !eq(operation, OpGroupNonUniformAny));
626 bit IsAllEqual = !eq(operation, OpGroupNonUniformAllEqual);
627 bit IsBallot = !eq(operation, OpGroupNonUniformBallot);
628 bit IsInverseBallot = !eq(operation, OpGroupNonUniformInverseBallot);
629 bit IsBallotBitExtract = !eq(operation, OpGroupNonUniformBallotBitExtract);
630 bit IsBallotFindBit = !or(!eq(operation, OpGroupNonUniformBallotFindLSB),
631 !eq(operation, OpGroupNonUniformBallotFindMSB));
632 bit IsLogical = !or(!eq(operation, OpGroupNonUniformLogicalAnd),
633 !eq(operation, OpGroupNonUniformLogicalOr),
634 !eq(operation, OpGroupNonUniformLogicalXor),
635 !eq(operation, OpGroupLogicalAndKHR),
636 !eq(operation, OpGroupLogicalOrKHR),
637 !eq(operation, OpGroupLogicalXorKHR));
638 bit NoGroupOperation = !or(IsElect, IsAllOrAny, IsAllEqual,
639 IsBallot, IsInverseBallot,
640 IsBallotBitExtract, IsBallotFindBit,
641 !eq(operation, OpGroupNonUniformShuffle),
642 !eq(operation, OpGroupNonUniformShuffleXor),
643 !eq(operation, OpGroupNonUniformShuffleUp),
644 !eq(operation, OpGroupNonUniformShuffleDown),
645 !eq(operation, OpGroupBroadcast),
646 !eq(operation, OpGroupNonUniformBroadcast),
647 !eq(operation, OpGroupNonUniformBroadcastFirst),
648 !eq(operation, OpGroupNonUniformRotateKHR));
649 bit HasBoolArg = !or(!and(IsAllOrAny, !eq(IsAllEqual, false)), IsBallot, IsLogical);
652 // Table gathering all the work/sub group builtins.
653 def GroupBuiltins : GenericTable {
654 let FilterClass = "GroupBuiltin";
655 let Fields = ["Name", "Opcode", "GroupOperation", "IsElect", "IsAllOrAny",
656 "IsAllEqual", "IsBallot", "IsInverseBallot", "IsBallotBitExtract",
657 "IsBallotFindBit", "IsLogical", "NoGroupOperation", "HasBoolArg"];
660 // Function to lookup group builtins by their name and set.
661 def lookupGroupBuiltin : SearchIndex {
662 let Table = GroupBuiltins;
666 // Multiclass used to define at the same time both incoming builtin records
667 // and corresponding work/sub group builtin records.
668 defvar OnlyWork = 0; defvar OnlySub = 1; defvar WorkOrSub = 2;
669 multiclass DemangledGroupBuiltin<string name, int level /* OnlyWork/OnlySub/... */, Op operation> {
670 assert !and(!ge(level, 0), !le(level, 2)), "group level is invalid: " # level;
672 if !or(!eq(level, OnlyWork), !eq(level, WorkOrSub)) then {
673 def : DemangledBuiltin<!strconcat("work_", name), OpenCL_std, Group, 0, 4>;
674 def : GroupBuiltin<!strconcat("work_", name), operation>;
677 if !or(!eq(level, OnlySub), !eq(level, WorkOrSub)) then {
678 def : DemangledBuiltin<!strconcat("sub_", name), OpenCL_std, Group, 0, 4>;
679 def : GroupBuiltin<!strconcat("sub_", name), operation>;
683 defm : DemangledGroupBuiltin<"group_all", WorkOrSub, OpGroupAll>;
684 defm : DemangledGroupBuiltin<"group_any", WorkOrSub, OpGroupAny>;
685 defm : DemangledGroupBuiltin<"group_broadcast", WorkOrSub, OpGroupBroadcast>;
686 defm : DemangledGroupBuiltin<"group_non_uniform_broadcast", OnlySub, OpGroupNonUniformBroadcast>;
687 defm : DemangledGroupBuiltin<"group_broadcast_first", OnlySub, OpGroupNonUniformBroadcastFirst>;
689 // cl_khr_subgroup_non_uniform_vote
690 defm : DemangledGroupBuiltin<"group_elect", OnlySub, OpGroupNonUniformElect>;
691 defm : DemangledGroupBuiltin<"group_non_uniform_all", OnlySub, OpGroupNonUniformAll>;
692 defm : DemangledGroupBuiltin<"group_non_uniform_any", OnlySub, OpGroupNonUniformAny>;
693 defm : DemangledGroupBuiltin<"group_non_uniform_all_equal", OnlySub, OpGroupNonUniformAllEqual>;
695 // cl_khr_subgroup_ballot
696 defm : DemangledGroupBuiltin<"group_ballot", OnlySub, OpGroupNonUniformBallot>;
697 defm : DemangledGroupBuiltin<"group_inverse_ballot", OnlySub, OpGroupNonUniformInverseBallot>;
698 defm : DemangledGroupBuiltin<"group_ballot_bit_extract", OnlySub, OpGroupNonUniformBallotBitExtract>;
699 defm : DemangledGroupBuiltin<"group_ballot_bit_count", OnlySub, OpGroupNonUniformBallotBitCount>;
700 defm : DemangledGroupBuiltin<"group_ballot_inclusive_scan", OnlySub, OpGroupNonUniformBallotBitCount>;
701 defm : DemangledGroupBuiltin<"group_ballot_exclusive_scan", OnlySub, OpGroupNonUniformBallotBitCount>;
702 defm : DemangledGroupBuiltin<"group_ballot_find_lsb", OnlySub, OpGroupNonUniformBallotFindLSB>;
703 defm : DemangledGroupBuiltin<"group_ballot_find_msb", OnlySub, OpGroupNonUniformBallotFindMSB>;
705 // cl_khr_subgroup_shuffle
706 defm : DemangledGroupBuiltin<"group_shuffle", OnlySub, OpGroupNonUniformShuffle>;
707 defm : DemangledGroupBuiltin<"group_shuffle_xor", OnlySub, OpGroupNonUniformShuffleXor>;
709 // cl_khr_subgroup_shuffle_relative
710 defm : DemangledGroupBuiltin<"group_shuffle_up", OnlySub, OpGroupNonUniformShuffleUp>;
711 defm : DemangledGroupBuiltin<"group_shuffle_down", OnlySub, OpGroupNonUniformShuffleDown>;
713 defm : DemangledGroupBuiltin<"group_iadd", WorkOrSub, OpGroupIAdd>;
714 defm : DemangledGroupBuiltin<"group_reduce_adds", WorkOrSub, OpGroupIAdd>;
715 defm : DemangledGroupBuiltin<"group_scan_exclusive_adds", WorkOrSub, OpGroupIAdd>;
716 defm : DemangledGroupBuiltin<"group_scan_inclusive_adds", WorkOrSub, OpGroupIAdd>;
717 defm : DemangledGroupBuiltin<"group_reduce_addu", WorkOrSub, OpGroupIAdd>;
718 defm : DemangledGroupBuiltin<"group_scan_exclusive_addu", WorkOrSub, OpGroupIAdd>;
719 defm : DemangledGroupBuiltin<"group_scan_inclusive_addu", WorkOrSub, OpGroupIAdd>;
721 defm : DemangledGroupBuiltin<"group_fadd", WorkOrSub, OpGroupFAdd>;
722 defm : DemangledGroupBuiltin<"group_reduce_addf", WorkOrSub, OpGroupFAdd>;
723 defm : DemangledGroupBuiltin<"group_scan_exclusive_addf", WorkOrSub, OpGroupFAdd>;
724 defm : DemangledGroupBuiltin<"group_scan_inclusive_addf", WorkOrSub, OpGroupFAdd>;
726 defm : DemangledGroupBuiltin<"group_fmin", WorkOrSub, OpGroupFMin>;
727 defm : DemangledGroupBuiltin<"group_reduce_minf", WorkOrSub, OpGroupFMin>;
728 defm : DemangledGroupBuiltin<"group_scan_exclusive_minf", WorkOrSub, OpGroupFMin>;
729 defm : DemangledGroupBuiltin<"group_scan_inclusive_minf", WorkOrSub, OpGroupFMin>;
731 defm : DemangledGroupBuiltin<"group_umin", WorkOrSub, OpGroupUMin>;
732 defm : DemangledGroupBuiltin<"group_reduce_minu", WorkOrSub, OpGroupUMin>;
733 defm : DemangledGroupBuiltin<"group_scan_exclusive_minu", WorkOrSub, OpGroupUMin>;
734 defm : DemangledGroupBuiltin<"group_scan_inclusive_minu", WorkOrSub, OpGroupUMin>;
736 defm : DemangledGroupBuiltin<"group_smin", WorkOrSub, OpGroupSMin>;
737 defm : DemangledGroupBuiltin<"group_reduce_mins", WorkOrSub, OpGroupSMin>;
738 defm : DemangledGroupBuiltin<"group_scan_exclusive_mins", WorkOrSub, OpGroupSMin>;
739 defm : DemangledGroupBuiltin<"group_scan_inclusive_mins", WorkOrSub, OpGroupSMin>;
741 defm : DemangledGroupBuiltin<"group_fmax", WorkOrSub, OpGroupFMax>;
742 defm : DemangledGroupBuiltin<"group_reduce_maxf", WorkOrSub, OpGroupFMax>;
743 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxf", WorkOrSub, OpGroupFMax>;
744 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxf", WorkOrSub, OpGroupFMax>;
746 defm : DemangledGroupBuiltin<"group_umax", WorkOrSub, OpGroupUMax>;
747 defm : DemangledGroupBuiltin<"group_reduce_maxu", WorkOrSub, OpGroupUMax>;
748 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxu", WorkOrSub, OpGroupUMax>;
749 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxu", WorkOrSub, OpGroupUMax>;
751 defm : DemangledGroupBuiltin<"group_smax", WorkOrSub, OpGroupSMax>;
752 defm : DemangledGroupBuiltin<"group_reduce_maxs", WorkOrSub, OpGroupSMax>;
753 defm : DemangledGroupBuiltin<"group_scan_exclusive_maxs", WorkOrSub, OpGroupSMax>;
754 defm : DemangledGroupBuiltin<"group_scan_inclusive_maxs", WorkOrSub, OpGroupSMax>;
756 // cl_khr_subgroup_non_uniform_arithmetic
757 defm : DemangledGroupBuiltin<"group_non_uniform_iadd", WorkOrSub, OpGroupNonUniformIAdd>;
758 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addu", WorkOrSub, OpGroupNonUniformIAdd>;
759 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_adds", WorkOrSub, OpGroupNonUniformIAdd>;
760 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addu", WorkOrSub, OpGroupNonUniformIAdd>;
761 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_adds", WorkOrSub, OpGroupNonUniformIAdd>;
762 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addu", WorkOrSub, OpGroupNonUniformIAdd>;
763 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_adds", WorkOrSub, OpGroupNonUniformIAdd>;
764 defm : DemangledGroupBuiltin<"group_clustered_reduce_addu", WorkOrSub, OpGroupNonUniformIAdd>;
765 defm : DemangledGroupBuiltin<"group_clustered_reduce_adds", WorkOrSub, OpGroupNonUniformIAdd>;
767 defm : DemangledGroupBuiltin<"group_non_uniform_fadd", WorkOrSub, OpGroupNonUniformFAdd>;
768 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addf", WorkOrSub, OpGroupNonUniformFAdd>;
769 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addh", WorkOrSub, OpGroupNonUniformFAdd>;
770 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_addd", WorkOrSub, OpGroupNonUniformFAdd>;
771 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addf", WorkOrSub, OpGroupNonUniformFAdd>;
772 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addh", WorkOrSub, OpGroupNonUniformFAdd>;
773 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_addd", WorkOrSub, OpGroupNonUniformFAdd>;
774 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addf", WorkOrSub, OpGroupNonUniformFAdd>;
775 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addh", WorkOrSub, OpGroupNonUniformFAdd>;
776 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_addd", WorkOrSub, OpGroupNonUniformFAdd>;
777 defm : DemangledGroupBuiltin<"group_clustered_reduce_addf", WorkOrSub, OpGroupNonUniformFAdd>;
778 defm : DemangledGroupBuiltin<"group_clustered_reduce_addh", WorkOrSub, OpGroupNonUniformFAdd>;
779 defm : DemangledGroupBuiltin<"group_clustered_reduce_addd", WorkOrSub, OpGroupNonUniformFAdd>;
781 defm : DemangledGroupBuiltin<"group_non_uniform_imul", WorkOrSub, OpGroupNonUniformIMul>;
782 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulu", WorkOrSub, OpGroupNonUniformIMul>;
783 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_muls", WorkOrSub, OpGroupNonUniformIMul>;
784 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulu", WorkOrSub, OpGroupNonUniformIMul>;
785 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_muls", WorkOrSub, OpGroupNonUniformIMul>;
786 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulu", WorkOrSub, OpGroupNonUniformIMul>;
787 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_muls", WorkOrSub, OpGroupNonUniformIMul>;
788 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulu", WorkOrSub, OpGroupNonUniformIMul>;
789 defm : DemangledGroupBuiltin<"group_clustered_reduce_muls", WorkOrSub, OpGroupNonUniformIMul>;
791 defm : DemangledGroupBuiltin<"group_non_uniform_fmul", WorkOrSub, OpGroupNonUniformFMul>;
792 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulf", WorkOrSub, OpGroupNonUniformFMul>;
793 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mulh", WorkOrSub, OpGroupNonUniformFMul>;
794 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_muld", WorkOrSub, OpGroupNonUniformFMul>;
795 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulf", WorkOrSub, OpGroupNonUniformFMul>;
796 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mulh", WorkOrSub, OpGroupNonUniformFMul>;
797 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_muld", WorkOrSub, OpGroupNonUniformFMul>;
798 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulf", WorkOrSub, OpGroupNonUniformFMul>;
799 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mulh", WorkOrSub, OpGroupNonUniformFMul>;
800 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_muld", WorkOrSub, OpGroupNonUniformFMul>;
801 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulf", WorkOrSub, OpGroupNonUniformFMul>;
802 defm : DemangledGroupBuiltin<"group_clustered_reduce_mulh", WorkOrSub, OpGroupNonUniformFMul>;
803 defm : DemangledGroupBuiltin<"group_clustered_reduce_muld", WorkOrSub, OpGroupNonUniformFMul>;
805 defm : DemangledGroupBuiltin<"group_non_uniform_smin", WorkOrSub, OpGroupNonUniformSMin>;
806 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mins", WorkOrSub, OpGroupNonUniformSMin>;
807 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mins", WorkOrSub, OpGroupNonUniformSMin>;
808 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mins", WorkOrSub, OpGroupNonUniformSMin>;
809 defm : DemangledGroupBuiltin<"group_clustered_reduce_mins", WorkOrSub, OpGroupNonUniformSMin>;
812 defm : DemangledGroupBuiltin<"group_non_uniform_umin", WorkOrSub, OpGroupNonUniformUMin>;
813 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minu", WorkOrSub, OpGroupNonUniformUMin>;
814 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minu", WorkOrSub, OpGroupNonUniformUMin>;
815 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minu", WorkOrSub, OpGroupNonUniformUMin>;
816 defm : DemangledGroupBuiltin<"group_clustered_reduce_minu", WorkOrSub, OpGroupNonUniformUMin>;
818 defm : DemangledGroupBuiltin<"group_non_uniform_fmin", WorkOrSub, OpGroupNonUniformFMin>;
819 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minf", WorkOrSub, OpGroupNonUniformFMin>;
820 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_minh", WorkOrSub, OpGroupNonUniformFMin>;
821 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_mind", WorkOrSub, OpGroupNonUniformFMin>;
822 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minf", WorkOrSub, OpGroupNonUniformFMin>;
823 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_minh", WorkOrSub, OpGroupNonUniformFMin>;
824 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_mind", WorkOrSub, OpGroupNonUniformFMin>;
825 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minf", WorkOrSub, OpGroupNonUniformFMin>;
826 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_minh", WorkOrSub, OpGroupNonUniformFMin>;
827 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_mind", WorkOrSub, OpGroupNonUniformFMin>;
828 defm : DemangledGroupBuiltin<"group_clustered_reduce_minf", WorkOrSub, OpGroupNonUniformFMin>;
829 defm : DemangledGroupBuiltin<"group_clustered_reduce_minh", WorkOrSub, OpGroupNonUniformFMin>;
830 defm : DemangledGroupBuiltin<"group_clustered_reduce_mind", WorkOrSub, OpGroupNonUniformFMin>;
832 defm : DemangledGroupBuiltin<"group_non_uniform_smax", WorkOrSub, OpGroupNonUniformSMax>;
833 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxs", WorkOrSub, OpGroupNonUniformSMax>;
834 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxs", WorkOrSub, OpGroupNonUniformSMax>;
835 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxs", WorkOrSub, OpGroupNonUniformSMax>;
836 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxs", WorkOrSub, OpGroupNonUniformSMax>;
838 defm : DemangledGroupBuiltin<"group_non_uniform_umax", WorkOrSub, OpGroupNonUniformUMax>;
839 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxu", WorkOrSub, OpGroupNonUniformUMax>;
840 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxu", WorkOrSub, OpGroupNonUniformUMax>;
841 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxu", WorkOrSub, OpGroupNonUniformUMax>;
842 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxu", WorkOrSub, OpGroupNonUniformUMax>;
844 defm : DemangledGroupBuiltin<"group_non_uniform_fmax", WorkOrSub, OpGroupNonUniformFMax>;
845 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxf", WorkOrSub, OpGroupNonUniformFMax>;
846 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxh", WorkOrSub, OpGroupNonUniformFMax>;
847 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_maxd", WorkOrSub, OpGroupNonUniformFMax>;
848 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxf", WorkOrSub, OpGroupNonUniformFMax>;
849 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxh", WorkOrSub, OpGroupNonUniformFMax>;
850 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_maxd", WorkOrSub, OpGroupNonUniformFMax>;
851 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxf", WorkOrSub, OpGroupNonUniformFMax>;
852 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxh", WorkOrSub, OpGroupNonUniformFMax>;
853 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_maxd", WorkOrSub, OpGroupNonUniformFMax>;
854 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxf", WorkOrSub, OpGroupNonUniformFMax>;
855 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxh", WorkOrSub, OpGroupNonUniformFMax>;
856 defm : DemangledGroupBuiltin<"group_clustered_reduce_maxd", WorkOrSub, OpGroupNonUniformFMax>;
858 defm : DemangledGroupBuiltin<"group_non_uniform_iand", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
859 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
860 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
861 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
862 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
863 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
864 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
865 defm : DemangledGroupBuiltin<"group_clustered_reduce_andu", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
866 defm : DemangledGroupBuiltin<"group_clustered_reduce_ands", WorkOrSub, OpGroupNonUniformBitwiseAnd>;
868 defm : DemangledGroupBuiltin<"group_non_uniform_ior", WorkOrSub, OpGroupNonUniformBitwiseOr>;
869 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
870 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
871 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
872 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
873 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
874 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
875 defm : DemangledGroupBuiltin<"group_clustered_reduce_oru", WorkOrSub, OpGroupNonUniformBitwiseOr>;
876 defm : DemangledGroupBuiltin<"group_clustered_reduce_ors", WorkOrSub, OpGroupNonUniformBitwiseOr>;
878 defm : DemangledGroupBuiltin<"group_non_uniform_ixor", WorkOrSub, OpGroupNonUniformBitwiseXor>;
879 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
880 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
881 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
882 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
883 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
884 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
885 defm : DemangledGroupBuiltin<"group_clustered_reduce_xoru", WorkOrSub, OpGroupNonUniformBitwiseXor>;
886 defm : DemangledGroupBuiltin<"group_clustered_reduce_xors", WorkOrSub, OpGroupNonUniformBitwiseXor>;
888 defm : DemangledGroupBuiltin<"group_non_uniform_logical_iand", WorkOrSub, OpGroupNonUniformLogicalAnd>;
889 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
890 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
891 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_ands", WorkOrSub, OpGroupNonUniformLogicalAnd>;
892 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_and", WorkOrSub, OpGroupNonUniformLogicalAnd>;
894 defm : DemangledGroupBuiltin<"group_non_uniform_logical_ior", WorkOrSub, OpGroupNonUniformLogicalOr>;
895 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
896 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
897 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_ors", WorkOrSub, OpGroupNonUniformLogicalOr>;
898 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_or", WorkOrSub, OpGroupNonUniformLogicalOr>;
900 defm : DemangledGroupBuiltin<"group_non_uniform_logical_ixor", WorkOrSub, OpGroupNonUniformLogicalXor>;
901 defm : DemangledGroupBuiltin<"group_non_uniform_reduce_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
902 defm : DemangledGroupBuiltin<"group_non_uniform_scan_inclusive_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
903 defm : DemangledGroupBuiltin<"group_non_uniform_scan_exclusive_logical_xors", WorkOrSub, OpGroupNonUniformLogicalXor>;
904 defm : DemangledGroupBuiltin<"group_clustered_reduce_logical_xor", WorkOrSub, OpGroupNonUniformLogicalXor>;
906 // cl_khr_subgroup_rotate / SPV_KHR_subgroup_rotate
907 defm : DemangledGroupBuiltin<"group_rotate", OnlySub, OpGroupNonUniformRotateKHR>;
908 defm : DemangledGroupBuiltin<"group_clustered_rotate", OnlySub, OpGroupNonUniformRotateKHR>;
910 // cl_khr_work_group_uniform_arithmetic / SPV_KHR_uniform_group_instructions
911 defm : DemangledGroupBuiltin<"group_reduce_imul", OnlyWork, OpGroupIMulKHR>;
912 defm : DemangledGroupBuiltin<"group_reduce_mulu", OnlyWork, OpGroupIMulKHR>;
913 defm : DemangledGroupBuiltin<"group_reduce_muls", OnlyWork, OpGroupIMulKHR>;
914 defm : DemangledGroupBuiltin<"group_scan_inclusive_imul", OnlyWork, OpGroupIMulKHR>;
915 defm : DemangledGroupBuiltin<"group_scan_inclusive_mulu", OnlyWork, OpGroupIMulKHR>;
916 defm : DemangledGroupBuiltin<"group_scan_inclusive_muls", OnlyWork, OpGroupIMulKHR>;
917 defm : DemangledGroupBuiltin<"group_scan_exclusive_imul", OnlyWork, OpGroupIMulKHR>;
918 defm : DemangledGroupBuiltin<"group_scan_exclusive_mulu", OnlyWork, OpGroupIMulKHR>;
919 defm : DemangledGroupBuiltin<"group_scan_exclusive_muls", OnlyWork, OpGroupIMulKHR>;
921 defm : DemangledGroupBuiltin<"group_reduce_mulf", OnlyWork, OpGroupFMulKHR>;
922 defm : DemangledGroupBuiltin<"group_reduce_mulh", OnlyWork, OpGroupFMulKHR>;
923 defm : DemangledGroupBuiltin<"group_reduce_muld", OnlyWork, OpGroupFMulKHR>;
924 defm : DemangledGroupBuiltin<"group_scan_inclusive_mulf", OnlyWork, OpGroupFMulKHR>;
925 defm : DemangledGroupBuiltin<"group_scan_inclusive_mulh", OnlyWork, OpGroupFMulKHR>;
926 defm : DemangledGroupBuiltin<"group_scan_inclusive_muld", OnlyWork, OpGroupFMulKHR>;
927 defm : DemangledGroupBuiltin<"group_scan_exclusive_mulf", OnlyWork, OpGroupFMulKHR>;
928 defm : DemangledGroupBuiltin<"group_scan_exclusive_mulh", OnlyWork, OpGroupFMulKHR>;
929 defm : DemangledGroupBuiltin<"group_scan_exclusive_muld", OnlyWork, OpGroupFMulKHR>;
931 defm : DemangledGroupBuiltin<"group_scan_exclusive_and", OnlyWork, OpGroupBitwiseAndKHR>;
932 defm : DemangledGroupBuiltin<"group_scan_inclusive_and", OnlyWork, OpGroupBitwiseAndKHR>;
933 defm : DemangledGroupBuiltin<"group_reduce_and", OnlyWork, OpGroupBitwiseAndKHR>;
935 defm : DemangledGroupBuiltin<"group_scan_exclusive_or", OnlyWork, OpGroupBitwiseOrKHR>;
936 defm : DemangledGroupBuiltin<"group_scan_inclusive_or", OnlyWork, OpGroupBitwiseOrKHR>;
937 defm : DemangledGroupBuiltin<"group_reduce_or", OnlyWork, OpGroupBitwiseOrKHR>;
939 defm : DemangledGroupBuiltin<"group_scan_exclusive_xor", OnlyWork, OpGroupBitwiseXorKHR>;
940 defm : DemangledGroupBuiltin<"group_scan_inclusive_xor", OnlyWork, OpGroupBitwiseXorKHR>;
941 defm : DemangledGroupBuiltin<"group_reduce_xor", OnlyWork, OpGroupBitwiseXorKHR>;
943 defm : DemangledGroupBuiltin<"group_scan_exclusive_logical_and", OnlyWork, OpGroupLogicalAndKHR>;
944 defm : DemangledGroupBuiltin<"group_scan_inclusive_logical_and", OnlyWork, OpGroupLogicalAndKHR>;
945 defm : DemangledGroupBuiltin<"group_reduce_logical_and", OnlyWork, OpGroupLogicalAndKHR>;
947 defm : DemangledGroupBuiltin<"group_scan_exclusive_logical_or", OnlyWork, OpGroupLogicalOrKHR>;
948 defm : DemangledGroupBuiltin<"group_scan_inclusive_logical_or", OnlyWork, OpGroupLogicalOrKHR>;
949 defm : DemangledGroupBuiltin<"group_reduce_logical_or", OnlyWork, OpGroupLogicalOrKHR>;
951 defm : DemangledGroupBuiltin<"group_scan_exclusive_logical_xor", OnlyWork, OpGroupLogicalXorKHR>;
952 defm : DemangledGroupBuiltin<"group_scan_inclusive_logical_xor", OnlyWork, OpGroupLogicalXorKHR>;
953 defm : DemangledGroupBuiltin<"group_reduce_logical_xor", OnlyWork, OpGroupLogicalXorKHR>;
955 //===----------------------------------------------------------------------===//
956 // Class defining an atomic instruction on floating-point numbers.
958 // name is the demangled name of the given builtin.
959 // opcode specifies the SPIR-V operation code of the generated instruction.
960 //===----------------------------------------------------------------------===//
961 class AtomicFloatingBuiltin<string name, Op operation> {
963 Op Opcode = operation;
966 // Table gathering all builtins for atomic instructions on floating-point numbers
967 def AtomicFloatingBuiltins : GenericTable {
968 let FilterClass = "AtomicFloatingBuiltin";
969 let Fields = ["Name", "Opcode"];
972 // Function to lookup builtins by their name and set.
973 def lookupAtomicFloatingBuiltin : SearchIndex {
974 let Table = AtomicFloatingBuiltins;
978 // Multiclass used to define incoming demangled builtin records and
979 // corresponding builtin records for atomic instructions on floating-point numbers.
980 multiclass DemangledAtomicFloatingBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
981 def : DemangledBuiltin<!strconcat("__spirv_AtomicF", name), OpenCL_std, AtomicFloating, minNumArgs, maxNumArgs>;
982 def : AtomicFloatingBuiltin<!strconcat("__spirv_AtomicF", name), operation>;
985 // SPV_EXT_shader_atomic_float_add, SPV_EXT_shader_atomic_float_min_max, SPV_EXT_shader_atomic_float16_add
986 // Atomic add, min and max instruction on floating-point numbers:
987 defm : DemangledAtomicFloatingBuiltin<"AddEXT", 4, 4, OpAtomicFAddEXT>;
988 defm : DemangledAtomicFloatingBuiltin<"MinEXT", 4, 4, OpAtomicFMinEXT>;
989 defm : DemangledAtomicFloatingBuiltin<"MaxEXT", 4, 4, OpAtomicFMaxEXT>;
990 // TODO: add support for cl_ext_float_atomics to enable performing atomic operations
991 // on floating-point numbers in memory (float arguments for atomic_fetch_add, ...)
993 //===----------------------------------------------------------------------===//
994 // Class defining a sub group builtin that should be translated into a
995 // SPIR-V instruction using the SPV_INTEL_subgroups extension.
997 // name is the demangled name of the given builtin.
998 // opcode specifies the SPIR-V operation code of the generated instruction.
999 //===----------------------------------------------------------------------===//
1000 class IntelSubgroupsBuiltin<string name, Op operation> {
1002 Op Opcode = operation;
1003 bit IsBlock = !or(!eq(operation, OpSubgroupBlockReadINTEL),
1004 !eq(operation, OpSubgroupBlockWriteINTEL));
1005 bit IsWrite = !eq(operation, OpSubgroupBlockWriteINTEL);
1008 // Table gathering all the Intel sub group builtins.
1009 def IntelSubgroupsBuiltins : GenericTable {
1010 let FilterClass = "IntelSubgroupsBuiltin";
1011 let Fields = ["Name", "Opcode", "IsBlock", "IsWrite"];
1014 // Function to lookup group builtins by their name and set.
1015 def lookupIntelSubgroupsBuiltin : SearchIndex {
1016 let Table = IntelSubgroupsBuiltins;
1020 // Multiclass used to define incoming builtin records for the SPV_INTEL_subgroups extension
1021 // and corresponding work/sub group builtin records.
1022 multiclass DemangledIntelSubgroupsBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
1023 def : DemangledBuiltin<!strconcat("intel_sub_group_", name), OpenCL_std, IntelSubgroups, minNumArgs, maxNumArgs>;
1024 def : IntelSubgroupsBuiltin<!strconcat("intel_sub_group_", name), operation>;
1027 // cl_intel_subgroups
1028 defm : DemangledIntelSubgroupsBuiltin<"shuffle", 2, 2, OpSubgroupShuffleINTEL>;
1029 defm : DemangledIntelSubgroupsBuiltin<"shuffle_down", 3, 3, OpSubgroupShuffleDownINTEL>;
1030 defm : DemangledIntelSubgroupsBuiltin<"shuffle_up", 3, 3, OpSubgroupShuffleUpINTEL>;
1031 defm : DemangledIntelSubgroupsBuiltin<"shuffle_xor", 2, 2, OpSubgroupShuffleXorINTEL>;
1032 foreach i = ["", "2", "4", "8"] in {
1033 // cl_intel_subgroups
1034 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read", i), 1, 2, OpSubgroupBlockReadINTEL>;
1035 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write", i), 2, 3, OpSubgroupBlockWriteINTEL>;
1036 // cl_intel_subgroups_short
1037 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read_ui", i), 1, 2, OpSubgroupBlockReadINTEL>;
1038 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write_ui", i), 2, 3, OpSubgroupBlockWriteINTEL>;
1040 // cl_intel_subgroups_char, cl_intel_subgroups_short, cl_intel_subgroups_long
1041 foreach i = ["", "2", "4", "8", "16"] in {
1042 foreach j = ["c", "s", "l"] in {
1043 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_read_u", j, i), 1, 2, OpSubgroupBlockReadINTEL>;
1044 defm : DemangledIntelSubgroupsBuiltin<!strconcat("block_write_u", j, i), 2, 3, OpSubgroupBlockWriteINTEL>;
1047 // OpSubgroupImageBlockReadINTEL and OpSubgroupImageBlockWriteINTEL are to be resolved later on (in code)
1049 //===----------------------------------------------------------------------===//
1050 // Class defining a builtin for group operations within uniform control flow.
1051 // It should be translated into a SPIR-V instruction using
1052 // the SPV_KHR_uniform_group_instructions extension.
1054 // name is the demangled name of the given builtin.
1055 // opcode specifies the SPIR-V operation code of the generated instruction.
1056 //===----------------------------------------------------------------------===//
1057 class GroupUniformBuiltin<string name, Op operation> {
1059 Op Opcode = operation;
1060 bit IsLogical = !or(!eq(operation, OpGroupLogicalAndKHR),
1061 !eq(operation, OpGroupLogicalOrKHR),
1062 !eq(operation, OpGroupLogicalXorKHR));
1065 // Table gathering all the Intel sub group builtins.
1066 def GroupUniformBuiltins : GenericTable {
1067 let FilterClass = "GroupUniformBuiltin";
1068 let Fields = ["Name", "Opcode", "IsLogical"];
1071 // Function to lookup group builtins by their name and set.
1072 def lookupGroupUniformBuiltin : SearchIndex {
1073 let Table = GroupUniformBuiltins;
1077 // Multiclass used to define incoming builtin records for
1078 // the SPV_KHR_uniform_group_instructions extension
1079 // and corresponding work group builtin records.
1080 multiclass DemangledGroupUniformBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, Op operation> {
1081 def : DemangledBuiltin<!strconcat("__spirv_Group", name), OpenCL_std, GroupUniform, minNumArgs, maxNumArgs>;
1082 def : GroupUniformBuiltin<!strconcat("__spirv_Group", name), operation>;
1085 // cl_khr_work_group_uniform_arithmetic / SPV_KHR_uniform_group_instructions
1086 defm : DemangledGroupUniformBuiltin<"IMulKHR", 3, 3, OpGroupIMulKHR>;
1087 defm : DemangledGroupUniformBuiltin<"FMulKHR", 3, 3, OpGroupFMulKHR>;
1088 defm : DemangledGroupUniformBuiltin<"BitwiseAndKHR", 3, 3, OpGroupBitwiseAndKHR>;
1089 defm : DemangledGroupUniformBuiltin<"BitwiseOrKHR", 3, 3, OpGroupBitwiseOrKHR>;
1090 defm : DemangledGroupUniformBuiltin<"BitwiseXorKHR", 3, 3, OpGroupBitwiseXorKHR>;
1091 defm : DemangledGroupUniformBuiltin<"LogicalAndKHR", 3, 3, OpGroupLogicalAndKHR>;
1092 defm : DemangledGroupUniformBuiltin<"LogicalOrKHR", 3, 3, OpGroupLogicalOrKHR>;
1093 defm : DemangledGroupUniformBuiltin<"LogicalXorKHR", 3, 3, OpGroupLogicalXorKHR>;
1095 //===----------------------------------------------------------------------===//
1096 // Class defining a get builtin record used for lowering builtin calls such as
1097 // "get_sub_group_eq_mask" or "get_global_id" to SPIR-V instructions.
1099 // name is the demangled name of the given builtin.
1100 // set specifies which external instruction set the builtin belongs to.
1101 // value specifies the value of the BuiltIn enum.
1102 //===----------------------------------------------------------------------===//
1103 class GetBuiltin<string name, InstructionSet set, BuiltIn value> {
1105 InstructionSet Set = set;
1106 BuiltIn Value = value;
1109 // Table gathering all the get builtin records.
1110 def GetBuiltins : GenericTable {
1111 let FilterClass = "GetBuiltin";
1112 let Fields = ["Name", "Set", "Value"];
1113 string TypeOf_Set = "InstructionSet";
1114 string TypeOf_Value = "BuiltIn";
1117 // Function to lookup get builtin records by their name and set.
1118 def lookupGetBuiltin : SearchIndex {
1119 let Table = GetBuiltins;
1120 let Key = ["Name", "Set"];
1123 // Multiclass used to define at the same time both a demangled builtin record
1124 // and a corresponding get builtin record.
1125 multiclass DemangledGetBuiltin<string name, InstructionSet set, BuiltinGroup group, BuiltIn value> {
1126 def : DemangledBuiltin<name, set, group, 0, 1>;
1127 def : GetBuiltin<name, set, value>;
1130 // Builtin variable records:
1131 defm : DemangledGetBuiltin<"get_sub_group_eq_mask", OpenCL_std, Variable, SubgroupEqMask>;
1132 defm : DemangledGetBuiltin<"get_sub_group_ge_mask", OpenCL_std, Variable, SubgroupGeMask>;
1133 defm : DemangledGetBuiltin<"get_sub_group_gt_mask", OpenCL_std, Variable, SubgroupGtMask>;
1134 defm : DemangledGetBuiltin<"get_sub_group_le_mask", OpenCL_std, Variable, SubgroupLeMask>;
1135 defm : DemangledGetBuiltin<"get_sub_group_lt_mask", OpenCL_std, Variable, SubgroupLtMask>;
1136 defm : DemangledGetBuiltin<"__spirv_BuiltInGlobalLinearId", OpenCL_std, Variable, GlobalLinearId>;
1137 defm : DemangledGetBuiltin<"__spirv_BuiltInGlobalInvocationId", OpenCL_std, Variable, GlobalInvocationId>;
1139 // GetQuery builtin records:
1140 defm : DemangledGetBuiltin<"get_local_id", OpenCL_std, GetQuery, LocalInvocationId>;
1141 defm : DemangledGetBuiltin<"get_global_id", OpenCL_std, GetQuery, GlobalInvocationId>;
1142 defm : DemangledGetBuiltin<"get_local_size", OpenCL_std, GetQuery, WorkgroupSize>;
1143 defm : DemangledGetBuiltin<"get_global_size", OpenCL_std, GetQuery, GlobalSize>;
1144 defm : DemangledGetBuiltin<"get_group_id", OpenCL_std, GetQuery, WorkgroupId>;
1145 defm : DemangledGetBuiltin<"get_enqueued_local_size", OpenCL_std, GetQuery, EnqueuedWorkgroupSize>;
1146 defm : DemangledGetBuiltin<"get_num_groups", OpenCL_std, GetQuery, NumWorkgroups>;
1147 defm : DemangledGetBuiltin<"__hlsl_wave_get_lane_index", GLSL_std_450, Wave, SubgroupLocalInvocationId>;
1149 //===----------------------------------------------------------------------===//
1150 // Class defining an image query builtin record used for lowering the OpenCL
1151 // "get_image_*" calls into OpImageQuerySize/OpImageQuerySizeLod instructions.
1153 // name is the demangled name of the given builtin.
1154 // set specifies which external instruction set the builtin belongs to.
1155 // component specifies the unsigned number of the query component.
1156 //===----------------------------------------------------------------------===//
1157 class ImageQueryBuiltin<string name, InstructionSet set, bits<32> component> {
1159 InstructionSet Set = set;
1160 bits<32> Component = component;
1163 // Table gathering all the image query builtins.
1164 def ImageQueryBuiltins : GenericTable {
1165 let FilterClass = "ImageQueryBuiltin";
1166 let Fields = ["Name", "Set", "Component"];
1167 string TypeOf_Set = "InstructionSet";
1170 // Function to lookup image query builtins by their name and set.
1171 def lookupImageQueryBuiltin : SearchIndex {
1172 let Table = ImageQueryBuiltins;
1173 let Key = ["Name", "Set"];
1176 // Multiclass used to define at the same time both a demangled builtin record
1177 // and a corresponding image query builtin record.
1178 multiclass DemangledImageQueryBuiltin<string name, InstructionSet set, int component> {
1179 def : DemangledBuiltin<name, set, ImageSizeQuery, 1, 1>;
1180 def : ImageQueryBuiltin<name, set, component>;
1183 // Image query builtin records:
1184 defm : DemangledImageQueryBuiltin<"get_image_width", OpenCL_std, 0>;
1185 defm : DemangledImageQueryBuiltin<"get_image_height", OpenCL_std, 1>;
1186 defm : DemangledImageQueryBuiltin<"get_image_depth", OpenCL_std, 2>;
1187 defm : DemangledImageQueryBuiltin<"get_image_dim", OpenCL_std, 0>;
1188 defm : DemangledImageQueryBuiltin<"get_image_array_size", OpenCL_std, 3>;
1190 defm : DemangledNativeBuiltin<"get_image_num_samples", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQuerySamples>;
1191 defm : DemangledNativeBuiltin<"get_image_num_mip_levels", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQueryLevels>;
1193 //===----------------------------------------------------------------------===//
1194 // Class defining a "convert_destType<_sat><_roundingMode>" call record for
1195 // lowering into OpConvert instructions.
1197 // name is the demangled name of the given builtin.
1198 // set specifies which external instruction set the builtin belongs to.
1199 //===----------------------------------------------------------------------===//
1200 class ConvertBuiltin<string name, InstructionSet set> {
1202 InstructionSet Set = set;
1203 bit IsDestinationSigned = !eq(!find(name, "convert_u"), -1);
1204 bit IsSaturated = !not(!eq(!find(name, "_sat"), -1));
1205 bit IsRounded = !not(!eq(!find(name, "_rt"), -1));
1206 bit IsBfloat16 = !or(!not(!eq(!find(name, "BF16"), -1)),
1207 !not(!eq(!find(name, "bfloat16"), -1)));
1208 FPRoundingMode RoundingMode = !cond(!not(!eq(!find(name, "_rte"), -1)) : RTE,
1209 !not(!eq(!find(name, "_rtz"), -1)) : RTZ,
1210 !not(!eq(!find(name, "_rtp"), -1)) : RTP,
1211 !not(!eq(!find(name, "_rtn"), -1)) : RTN,
1215 // Table gathering all the convert builtins.
1216 def ConvertBuiltins : GenericTable {
1217 let FilterClass = "ConvertBuiltin";
1218 let Fields = ["Name", "Set", "IsDestinationSigned", "IsSaturated",
1219 "IsRounded", "IsBfloat16", "RoundingMode"];
1220 string TypeOf_Set = "InstructionSet";
1221 string TypeOf_RoundingMode = "FPRoundingMode";
1224 // Function to lookup convert builtins by their name and set.
1225 def lookupConvertBuiltin : SearchIndex {
1226 let Table = ConvertBuiltins;
1227 let Key = ["Name", "Set"];
1230 // Multiclass used to define at the same time both a demangled builtin records
1231 // and a corresponding convert builtin records.
1232 multiclass DemangledConvertBuiltin<string name, InstructionSet set> {
1233 // Create records for scalar and 2, 4, 8, and 16 element vector conversions.
1234 foreach i = ["", "2", "3", "4", "8", "16"] in {
1235 // Also create records for each rounding mode.
1236 foreach j = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
1237 def : DemangledBuiltin<!strconcat(name, i, j), set, Convert, 1, 1>;
1238 def : ConvertBuiltin<!strconcat(name, i, j), set>;
1240 // Create records with the "_sat" modifier for all conversions except
1241 // those targeting floating-point types.
1242 if !eq(!find(name, "float"), -1) then {
1243 def : DemangledBuiltin<!strconcat(name, i, "_sat", j), set, Convert, 1, 1>;
1244 def : ConvertBuiltin<!strconcat(name, i, "_sat", j), set>;
1250 // Explicit conversion builtin records:
1251 defm : DemangledConvertBuiltin<"convert_char", OpenCL_std>;
1252 defm : DemangledConvertBuiltin<"convert_uchar", OpenCL_std>;
1253 defm : DemangledConvertBuiltin<"convert_short", OpenCL_std>;
1254 defm : DemangledConvertBuiltin<"convert_ushort", OpenCL_std>;
1255 defm : DemangledConvertBuiltin<"convert_int", OpenCL_std>;
1256 defm : DemangledConvertBuiltin<"convert_uint", OpenCL_std>;
1257 defm : DemangledConvertBuiltin<"convert_long", OpenCL_std>;
1258 defm : DemangledConvertBuiltin<"convert_ulong", OpenCL_std>;
1259 defm : DemangledConvertBuiltin<"convert_float", OpenCL_std>;
1261 // cl_intel_bfloat16_conversions / SPV_INTEL_bfloat16_conversion
1262 // Multiclass used to define at the same time both a demangled builtin records
1263 // and a corresponding convert builtin records.
1264 multiclass DemangledBF16ConvertBuiltin<string name1, string name2> {
1265 // Create records for scalar and vector conversions.
1266 foreach i = ["", "2", "3", "4", "8", "16"] in {
1267 def : DemangledBuiltin<!strconcat("intel_convert_", name1, i, name2, i), OpenCL_std, Convert, 1, 1>;
1268 def : ConvertBuiltin<!strconcat("intel_convert_", name1, i, name2, i), OpenCL_std>;
1272 defm : DemangledBF16ConvertBuiltin<"bfloat16", "_as_ushort">;
1273 defm : DemangledBF16ConvertBuiltin<"as_bfloat16", "_float">;
1275 foreach conv = ["FToBF16INTEL", "BF16ToFINTEL"] in {
1276 def : DemangledBuiltin<!strconcat("__spirv_Convert", conv), OpenCL_std, Convert, 1, 1>;
1277 def : ConvertBuiltin<!strconcat("__spirv_Convert", conv), OpenCL_std>;
1280 //===----------------------------------------------------------------------===//
1281 // Class defining a vector data load/store builtin record used for lowering
1282 // into OpExtInst instruction.
1284 // name is the demangled name of the given builtin.
1285 // set specifies which external instruction set the builtin belongs to.
1286 // number specifies the number of the instruction in the external set.
1287 //===----------------------------------------------------------------------===//
1288 class VectorLoadStoreBuiltin<string name, InstructionSet set, int number> {
1290 InstructionSet Set = set;
1291 bits<32> Number = number;
1292 bits<32> ElementCount = !cond(!not(!eq(!find(name, "2"), -1)) : 2,
1293 !not(!eq(!find(name, "3"), -1)) : 3,
1294 !not(!eq(!find(name, "4"), -1)) : 4,
1295 !not(!eq(!find(name, "8"), -1)) : 8,
1296 !not(!eq(!find(name, "16"), -1)) : 16,
1298 bit IsRounded = !not(!eq(!find(name, "_rt"), -1));
1299 FPRoundingMode RoundingMode = !cond(!not(!eq(!find(name, "_rte"), -1)) : RTE,
1300 !not(!eq(!find(name, "_rtz"), -1)) : RTZ,
1301 !not(!eq(!find(name, "_rtp"), -1)) : RTP,
1302 !not(!eq(!find(name, "_rtn"), -1)) : RTN,
1306 // Table gathering all the vector data load/store builtins.
1307 def VectorLoadStoreBuiltins : GenericTable {
1308 let FilterClass = "VectorLoadStoreBuiltin";
1309 let Fields = ["Name", "Set", "Number", "ElementCount", "IsRounded", "RoundingMode"];
1310 string TypeOf_Set = "InstructionSet";
1311 string TypeOf_RoundingMode = "FPRoundingMode";
1314 // Function to lookup vector data load/store builtins by their name and set.
1315 def lookupVectorLoadStoreBuiltin : SearchIndex {
1316 let Table = VectorLoadStoreBuiltins;
1317 let Key = ["Name", "Set"];
1320 // Multiclass used to define at the same time both a demangled builtin record
1321 // and a corresponding vector data load/store builtin record.
1322 multiclass DemangledVectorLoadStoreBuiltin<string name, bits<8> minNumArgs, bits<8> maxNumArgs, int number> {
1323 def : DemangledBuiltin<name, OpenCL_std, VectorLoadStore, minNumArgs, maxNumArgs>;
1324 def : VectorLoadStoreBuiltin<name, OpenCL_std, number>;
1327 // Create records for scalar and 2, 4, 8, and 16 vector element count.
1328 foreach i = ["", "2", "3", "4", "8", "16"] in {
1329 if !eq(i, "") then {
1330 defm : DemangledVectorLoadStoreBuiltin<"vload_half", 2, 2, 173>;
1331 defm : DemangledVectorLoadStoreBuiltin<"vstore_half", 3, 3, 175>;
1333 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload_half", i), 3, 3, 174>;
1334 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i), 3, 3, 177>;
1336 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vload", i), 2, 2, 171>;
1337 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore", i), 3, 3, 172>;
1338 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vloada_half", i), 2, 2, 174>;
1339 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstorea_half", i), 3, 3, 180>;
1341 // Also create records for each rounding mode.
1342 foreach j = ["_rte", "_rtz", "_rtp", "_rtn"] in {
1343 if !eq(i, "") then {
1344 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", j), 3, 3, 176>;
1346 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstore_half", i, j), 3, 3, 178>;
1348 defm : DemangledVectorLoadStoreBuiltin<!strconcat("vstorea_half", i, j), 3, 3, 181>;
1352 //===----------------------------------------------------------------------===//
1353 // Class defining implementation details of SPIR-V builtin types. The info
1354 // in the record is used for lowering into OpType.
1356 // name is the name of the given SPIR-V builtin type.
1357 // operation specifies the SPIR-V opcode the StructType should be lowered to.
1358 //===----------------------------------------------------------------------===//
1359 class BuiltinType<string name, Op operation> {
1361 Op Opcode = operation;
1364 // Table gathering all the builtin type records.
1365 def BuiltinTypes : GenericTable {
1366 let FilterClass = "BuiltinType";
1367 let Fields = ["Name", "Opcode"];
1370 // Function to lookup builtin types by their demangled name.
1371 def lookupBuiltinType : SearchIndex {
1372 let Table = BuiltinTypes;
1376 def : BuiltinType<"spirv.ReserveId", OpTypeReserveId>;
1377 def : BuiltinType<"spirv.PipeStorage", OpTypePipeStorage>;
1378 def : BuiltinType<"spirv.Queue", OpTypeQueue>;
1379 def : BuiltinType<"spirv.Event", OpTypeEvent>;
1380 def : BuiltinType<"spirv.Sampler", OpTypeSampler>;
1381 def : BuiltinType<"spirv.DeviceEvent", OpTypeDeviceEvent>;
1382 def : BuiltinType<"spirv.Image", OpTypeImage>;
1383 def : BuiltinType<"spirv.SampledImage", OpTypeSampledImage>;
1384 def : BuiltinType<"spirv.Pipe", OpTypePipe>;
1387 //===----------------------------------------------------------------------===//
1388 // Class matching an OpenCL builtin type name to an equivalent SPIR-V
1389 // builtin type literal.
1391 // name is the name of the given OpenCL builtin type.
1392 // spirvTypeLiteral is the literal of an equivalent SPIR-V builtin type.
1393 //===----------------------------------------------------------------------===//
1394 class OpenCLType<string name, string spirvTypeLiteral> {
1396 string SpirvTypeLiteral = spirvTypeLiteral;
1399 // Table gathering all the OpenCL type records.
1400 def OpenCLTypes : GenericTable {
1401 let FilterClass = "OpenCLType";
1402 let Fields = ["Name", "SpirvTypeLiteral"];
1405 // Function to lookup OpenCL types by their name.
1406 def lookupOpenCLType : SearchIndex {
1407 let Table = OpenCLTypes;
1411 def : OpenCLType<"opencl.reserve_id_t", "spirv.ReserveId">;
1412 def : OpenCLType<"opencl.event_t", "spirv.Event">;
1413 def : OpenCLType<"opencl.queue_t", "spirv.Queue">;
1414 def : OpenCLType<"opencl.sampler_t", "spirv.Sampler">;
1415 def : OpenCLType<"opencl.clk_event_t", "spirv.DeviceEvent">;
1417 foreach aq = ["_t", "_ro_t", "_wo_t", "_rw_t"] in {
1418 defvar p = !cond(!not(!eq(!find(aq, "_rw_t"), -1)) : "2",
1419 !not(!eq(!find(aq, "_wo_t"), -1)) : "1",
1421 def : OpenCLType<!strconcat("opencl.pipe", aq),
1422 !strconcat("spirv.Pipe._", p)>;
1425 foreach aq = ["_t", "_ro_t", "_wo_t", "_rw_t"] in {
1426 defvar p7 = !cond(!not(!eq(!find(aq, "_rw_t"), -1)) : "2",
1427 !not(!eq(!find(aq, "_wo_t"), -1)) : "1",
1430 def : OpenCLType<!strconcat("opencl.image1d", aq),
1431 !strconcat("spirv.Image._void_0_0_0_0_0_0_", p7)>;
1432 def : OpenCLType<!strconcat("opencl.image1d_array", aq),
1433 !strconcat("spirv.Image._void_0_0_1_0_0_0_", p7)>;
1434 def : OpenCLType<!strconcat("opencl.image1d_buffer", aq),
1435 !strconcat("spirv.Image._void_5_0_0_0_0_0_", p7)>;
1437 foreach a1 = ["", "_array"] in {
1438 foreach a2 = ["", "_msaa"] in {
1439 foreach a3 = ["", "_depth"] in {
1440 defvar p2 = !cond(!not(!eq(!find(a3, "_depth"), -1)) : "1", true : "0");
1441 defvar p3 = !cond(!not(!eq(!find(a1, "_array"), -1)) : "1", true : "0");
1442 defvar p4 = !cond(!not(!eq(!find(a2, "msaa"), -1)) : "1", true : "0");
1444 def : OpenCLType<!strconcat("opencl.image2d", a1, a2, a3, aq),
1445 !strconcat("spirv.Image._void_1_", p2 , "_", p3, "_", p4, "_0_0_", p7)>;
1450 def : OpenCLType<!strconcat("opencl.image3d", aq),
1451 !strconcat("spirv.Image._void_2_0_0_0_0_0_", p7)>;
1454 //===----------------------------------------------------------------------===//
1455 // Classes definining various OpenCL enums.
1456 //===----------------------------------------------------------------------===//
1458 // OpenCL memory_scope enum
1459 def CLMemoryScope : GenericEnum {
1460 let FilterClass = "CLMemoryScope";
1461 let NameField = "Name";
1462 let ValueField = "Value";
1465 class CLMemoryScope<bits<32> value> {
1467 bits<32> Value = value;
1470 def memory_scope_work_item : CLMemoryScope<0>;
1471 def memory_scope_work_group : CLMemoryScope<1>;
1472 def memory_scope_device : CLMemoryScope<2>;
1473 def memory_scope_all_svm_devices : CLMemoryScope<3>;
1474 def memory_scope_sub_group : CLMemoryScope<4>;
1476 // OpenCL sampler addressing mode/bitmask enum
1477 def CLSamplerAddressingMode : GenericEnum {
1478 let FilterClass = "CLSamplerAddressingMode";
1479 let NameField = "Name";
1480 let ValueField = "Value";
1483 class CLSamplerAddressingMode<bits<32> value> {
1485 bits<32> Value = value;
1488 def CLK_ADDRESS_NONE : CLSamplerAddressingMode<0x0>;
1489 def CLK_ADDRESS_CLAMP : CLSamplerAddressingMode<0x4>;
1490 def CLK_ADDRESS_CLAMP_TO_EDGE : CLSamplerAddressingMode<0x2>;
1491 def CLK_ADDRESS_REPEAT : CLSamplerAddressingMode<0x6>;
1492 def CLK_ADDRESS_MIRRORED_REPEAT : CLSamplerAddressingMode<0x8>;
1493 def CLK_ADDRESS_MODE_MASK : CLSamplerAddressingMode<0xE>;
1494 def CLK_NORMALIZED_COORDS_FALSE : CLSamplerAddressingMode<0x0>;
1495 def CLK_NORMALIZED_COORDS_TRUE : CLSamplerAddressingMode<0x1>;
1496 def CLK_FILTER_NEAREST : CLSamplerAddressingMode<0x10>;
1497 def CLK_FILTER_LINEAR : CLSamplerAddressingMode<0x20>;
1499 // OpenCL memory fences
1500 def CLMemoryFenceFlags : GenericEnum {
1501 let FilterClass = "CLMemoryFenceFlags";
1502 let NameField = "Name";
1503 let ValueField = "Value";
1506 class CLMemoryFenceFlags<bits<32> value> {
1508 bits<32> Value = value;
1511 def CLK_LOCAL_MEM_FENCE : CLMemoryFenceFlags<0x1>;
1512 def CLK_GLOBAL_MEM_FENCE : CLMemoryFenceFlags<0x2>;
1513 def CLK_IMAGE_MEM_FENCE : CLMemoryFenceFlags<0x4>;