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