1 //==--- OpenCLBuiltins.td - OpenCL builtin declarations -------------------===//
3 // The LLVM Compiler Infrastructure
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file contains TableGen definitions for OpenCL builtin function
12 // declarations. In case of an unresolved function name in OpenCL, Clang will
13 // check for a function described in this file when -fdeclare-opencl-builtins
16 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
19 // Definitions of miscellaneous basic entities.
20 //===----------------------------------------------------------------------===//
22 class Version<int _Version> {
25 def CLAll : Version< 0>;
26 def CL10 : Version<100>;
27 def CL11 : Version<110>;
28 def CL12 : Version<120>;
29 def CL20 : Version<200>;
32 // Pointer types need to be assigned an address space.
33 class AddressSpace<string _AS> {
36 def DefaultAS : AddressSpace<"clang::LangAS::Default">;
37 def PrivateAS : AddressSpace<"clang::LangAS::opencl_private">;
38 def GlobalAS : AddressSpace<"clang::LangAS::opencl_global">;
39 def ConstantAS : AddressSpace<"clang::LangAS::opencl_constant">;
40 def LocalAS : AddressSpace<"clang::LangAS::opencl_local">;
41 def GenericAS : AddressSpace<"clang::LangAS::opencl_generic">;
43 // OpenCL language extension.
44 class AbstractExtension<string _Ext> {
45 // One or more OpenCL extensions, space separated. Each extension must be
46 // a valid extension name for the opencl extension pragma.
47 string ExtName = _Ext;
50 // Extension associated to a builtin function.
51 class FunctionExtension<string _Ext> : AbstractExtension<_Ext>;
53 // FunctionExtension definitions.
54 def FuncExtNone : FunctionExtension<"">;
55 def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">;
56 def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">;
57 def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
58 def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">;
59 def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
60 def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">;
61 def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">;
62 def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">;
63 def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">;
65 // Multiple extensions
66 def FuncExtKhrMipmapAndWrite3d : FunctionExtension<"cl_khr_mipmap_image cl_khr_3d_image_writes">;
68 // Qualified Type. These map to ASTContext::QualType.
69 class QualType<string _Name, bit _IsAbstract=0> {
70 // Name of the field or function in a clang::ASTContext
71 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
73 // Some QualTypes in this file represent an abstract type for which there is
74 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
75 // without access qualifiers.
76 bit IsAbstract = _IsAbstract;
80 class IntList<string _Name, list<int> _List> {
82 list<int> List = _List;
85 //===----------------------------------------------------------------------===//
86 // OpenCL C classes for types
87 //===----------------------------------------------------------------------===//
88 // OpenCL C basic data types (int, float, image2d_t, ...).
89 // Its child classes can represent concrete types (e.g. VectorType) or
90 // abstract types (e.g. GenType).
91 class Type<string _Name, QualType _QTName> {
94 // QualType associated with this type.
95 QualType QTName = _QTName;
96 // Size of the vector (if applicable).
100 // "const" qualifier.
102 // "volatile" qualifier.
104 // Access qualifier. Must be one of ("RO", "WO", "RW").
105 string AccessQualifier = "";
107 string AddrSpace = DefaultAS.Name;
110 // OpenCL vector types (e.g. int2, int3, int16, float8, ...).
111 class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
112 let VecWidth = _VecWidth;
113 let AccessQualifier = "";
115 let IsPointer = _Ty.IsPointer;
116 let IsConst = _Ty.IsConst;
117 let IsVolatile = _Ty.IsVolatile;
118 let AddrSpace = _Ty.AddrSpace;
121 // OpenCL pointer types (e.g. int*, float*, ...).
122 class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
123 Type<_Ty.Name, _Ty.QTName> {
124 let AddrSpace = _AS.Name;
126 let VecWidth = _Ty.VecWidth;
128 let IsConst = _Ty.IsConst;
129 let IsVolatile = _Ty.IsVolatile;
130 let AccessQualifier = _Ty.AccessQualifier;
133 // OpenCL const types (e.g. const int).
134 class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
137 let VecWidth = _Ty.VecWidth;
138 let IsPointer = _Ty.IsPointer;
139 let IsVolatile = _Ty.IsVolatile;
140 let AccessQualifier = _Ty.AccessQualifier;
141 let AddrSpace = _Ty.AddrSpace;
144 // OpenCL volatile types (e.g. volatile int).
145 class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
148 let VecWidth = _Ty.VecWidth;
149 let IsPointer = _Ty.IsPointer;
150 let IsConst = _Ty.IsConst;
151 let AccessQualifier = _Ty.AccessQualifier;
152 let AddrSpace = _Ty.AddrSpace;
155 // OpenCL image types (e.g. image2d).
156 class ImageType<Type _Ty, string _AccessQualifier> :
157 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
159 let AccessQualifier = _AccessQualifier;
161 let IsPointer = _Ty.IsPointer;
162 let IsConst = _Ty.IsConst;
163 let IsVolatile = _Ty.IsVolatile;
164 let AddrSpace = _Ty.AddrSpace;
168 class TypeList<string _Name, list<Type> _Type> {
170 list<Type> List = _Type;
173 // A GenericType is an abstract type that defines a set of types as a
174 // combination of Types and vector sizes.
176 // For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
177 // represents <int, int2, int4, float, float2, float4>.
179 // Some rules apply when using multiple GenericType arguments in a declaration:
180 // 1. The number of vector sizes must be equal or 1 for all gentypes in a
182 // 2. The number of Types must be equal or 1 for all gentypes in a
184 // 3. Generic types are combined by iterating over all generic types at once.
185 // For example, for the following GenericTypes
186 // GenT1 = GenericType<half, [1, 2]> and
187 // GenT2 = GenericType<float, int, [1, 2]>
188 // A declaration f(GenT1, GenT2) results in the combinations
189 // f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
190 // 4. "sgentype" from the OpenCL specification is supported by specifying
191 // a single vector size.
192 // For example, for the following GenericTypes
193 // GenT = GenericType<half, int, [1, 2]> and
194 // SGenT = GenericType<half, int, [1]>
195 // A declaration f(GenT, SGenT) results in the combinations
196 // f(half, half), f(half2, half), f(int, int), f(int2, int) .
197 class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
198 Type<_Ty, QualType<"null", 1>> {
199 // Possible element types of the generic type.
200 TypeList TypeList = _TypeList;
201 // Possible vector sizes of the types in the TypeList.
202 IntList VectorList = _VectorList;
203 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
207 // Builtin function attributes.
209 list<bit> None = [0, 0, 0];
210 list<bit> Pure = [1, 0, 0];
211 list<bit> Const = [0, 1, 0];
212 list<bit> Convergent = [0, 0, 1];
215 //===----------------------------------------------------------------------===//
216 // OpenCL C class for builtin functions
217 //===----------------------------------------------------------------------===//
218 class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
219 // Name of the builtin function
221 // List of types used by the function. The first one is the return type and
222 // the following are the arguments. The list must have at least one element
223 // (the return type).
224 list<Type> Signature = _Signature;
225 // Function attribute __attribute__((pure))
226 bit IsPure = _Attributes[0];
227 // Function attribute __attribute__((const))
228 bit IsConst = _Attributes[1];
229 // Function attribute __attribute__((convergent))
230 bit IsConv = _Attributes[2];
231 // OpenCL extensions to which the function belongs.
232 FunctionExtension Extension = FuncExtNone;
233 // Version of OpenCL from which the function is available (e.g.: CL10).
234 // MinVersion is inclusive.
235 Version MinVersion = CL10;
236 // Version of OpenCL from which the function is not supported anymore.
237 // MaxVersion is exclusive.
238 // CLAll makes the function available for all versions.
239 Version MaxVersion = CLAll;
242 //===----------------------------------------------------------------------===//
243 // Definitions of OpenCL C types
244 //===----------------------------------------------------------------------===//
246 // OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
247 def Bool : Type<"bool", QualType<"BoolTy">>;
248 def Char : Type<"char", QualType<"CharTy">>;
249 def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
250 def Short : Type<"short", QualType<"ShortTy">>;
251 def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
252 def Int : Type<"int", QualType<"IntTy">>;
253 def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
254 def Long : Type<"long", QualType<"LongTy">>;
255 def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
256 def Float : Type<"float", QualType<"FloatTy">>;
257 def Double : Type<"double", QualType<"DoubleTy">>;
258 def Half : Type<"half", QualType<"HalfTy">>;
259 def Size : Type<"size_t", QualType<"getSizeType()">>;
260 def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
261 def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
262 def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
263 def Void : Type<"void_t", QualType<"VoidTy">>;
265 // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
266 // Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
268 // OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
269 // The image definitions are "abstract". They should not be used without
270 // specifying an access qualifier (RO/WO/RW).
271 def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>;
272 def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>;
273 def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>;
274 def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>;
275 def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>;
276 def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>;
277 def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>;
278 def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>;
279 def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>;
280 def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>;
281 def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>;
282 def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>;
284 def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>;
285 def Event : Type<"Event", QualType<"OCLEventTy">>;
287 //===----------------------------------------------------------------------===//
288 // Definitions of OpenCL gentype variants
289 //===----------------------------------------------------------------------===//
290 // The OpenCL specification often uses "gentype" in builtin function
291 // declarations to indicate that a builtin function is available with various
292 // argument and return types. The types represented by "gentype" vary between
293 // different parts of the specification. The following definitions capture
294 // the different type lists for gentypes in different parts of the
297 // Vector width lists.
298 def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
299 def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
300 def Vec1 : IntList<"Vec1", [1]>;
301 def Vec2 : IntList<"Vec2", [2]>;
302 def Vec4 : IntList<"Vec4", [4]>;
303 def Vec8 : IntList<"Vec8", [8]>;
304 def Vec16 : IntList<"Vec16", [16]>;
305 def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
308 def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
309 def TLAllUnsigned : TypeList<"TLAllUnsigned", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
310 def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
311 def TLSignedInts : TypeList<"TLSignedInts", [Char, Short, Int, Long]>;
312 def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>;
314 def TLIntLongFloats : TypeList<"TLIntLongFloats", [Int, UInt, Long, ULong, Float, Double, Half]>;
316 // All unsigned integer types twice, to facilitate unsigned return types for e.g.
317 // uchar abs(char) and
319 def TLAllUIntsTwice : TypeList<"TLAllUIntsTwice", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
321 def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
323 // GenType definitions for multiple base types (e.g. all floating point types,
324 // or all integer types).
326 def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
327 def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
329 def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
330 def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
331 def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
332 // All integer to unsigned
333 def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
335 def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
337 def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
339 def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
340 // (u)int, (u)long, and all floats
341 def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
343 // GenType definitions for every single base type (e.g. fp32 only).
344 // Names are like: GenTypeFloatVecAndScalar.
345 foreach Type = [Char, UChar, Short, UShort,
346 Int, UInt, Long, ULong,
347 Float, Double, Half] in {
348 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
349 def "GenType" # Type # VecSizes :
350 GenericType<"GenType" # Type # VecSizes,
351 TypeList<"GL" # Type.Name, [Type]>,
356 // GenType definitions for vec1234.
357 foreach Type = [Float, Double, Half] in {
358 def "GenType" # Type # Vec1234 :
359 GenericType<"GenType" # Type # Vec1234,
360 TypeList<"GL" # Type.Name, [Type]>,
365 //===----------------------------------------------------------------------===//
366 // Definitions of OpenCL builtin functions
367 //===----------------------------------------------------------------------===//
368 //--------------------------------------------------------------------
369 // OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
370 // OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
372 // Generate the convert_* builtins functions.
373 foreach RType = [Float, Double, Half, Char, UChar, Short,
374 UShort, Int, UInt, Long, ULong] in {
375 foreach IType = [Float, Double, Half, Char, UChar, Short,
376 UShort, Int, UInt, Long, ULong] in {
377 foreach sat = ["", "_sat"] in {
378 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
379 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
381 foreach v = [2, 3, 4, 8, 16] in {
382 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
383 [VectorType<RType, v>, VectorType<IType, v>],
391 //--------------------------------------------------------------------
392 // OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
394 def : Builtin<"get_work_dim", [UInt], Attr.Const>;
395 foreach name = ["get_global_size", "get_global_id", "get_local_size",
396 "get_local_id", "get_num_groups", "get_group_id",
397 "get_global_offset"] in {
398 def : Builtin<name, [Size, UInt], Attr.Const>;
401 let MinVersion = CL20 in {
402 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
403 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
404 def : Builtin<name, [Size]>;
409 //--------------------------------------------------------------------
410 // OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
411 // OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
413 // --- 1 argument ---
414 foreach name = ["acos", "acosh", "acospi",
415 "asin", "asinh", "asinpi",
416 "atan", "atanh", "atanpi",
418 "cos", "cosh", "cospi",
420 "exp", "exp2", "exp10", "expm1",
422 "log", "log2", "log10", "log1p", "logb",
423 "rint", "round", "rsqrt",
424 "sin", "sinh", "sinpi",
426 "tan", "tanh", "tanpi",
429 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
431 foreach name = ["nan"] in {
432 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
433 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
434 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
437 // --- 2 arguments ---
438 foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
439 "maxmag", "minmag", "nextafter", "pow", "powr",
441 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
443 foreach name = ["fmax", "fmin"] in {
444 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
445 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
446 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
447 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
449 foreach name = ["ilogb"] in {
450 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
451 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
452 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
454 foreach name = ["ldexp"] in {
455 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
456 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
457 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
458 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
459 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
460 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
462 foreach name = ["pown", "rootn"] in {
463 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
464 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
465 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
468 // --- 3 arguments ---
469 foreach name = ["fma", "mad"] in {
470 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
473 // --- Version dependent ---
474 let MaxVersion = CL20 in {
475 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
476 foreach name = ["fract", "modf", "sincos"] in {
477 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
479 foreach name = ["frexp", "lgamma_r"] in {
480 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
481 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
484 foreach name = ["remquo"] in {
485 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
486 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
491 let MinVersion = CL20 in {
492 foreach name = ["fract", "modf", "sincos"] in {
493 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
495 foreach name = ["frexp", "lgamma_r"] in {
496 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
497 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
499 foreach name = ["remquo"] in {
500 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
501 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
507 foreach name = ["half_cos",
508 "half_exp", "half_exp2", "half_exp10",
509 "half_log", "half_log2", "half_log10",
510 "half_recip", "half_rsqrt",
511 "half_sin", "half_sqrt", "half_tan",
513 "native_exp", "native_exp2", "native_exp10",
514 "native_log", "native_log2", "native_log10",
515 "native_recip", "native_rsqrt",
516 "native_sin", "native_sqrt", "native_tan"] in {
517 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
519 foreach name = ["half_divide", "half_powr",
520 "native_divide", "native_powr"] in {
521 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
524 //--------------------------------------------------------------------
525 // OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
527 // --- 1 argument ---
528 foreach name = ["abs"] in {
529 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
531 foreach name = ["clz", "popcount"] in {
532 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
534 let MinVersion = CL20 in {
535 foreach name = ["ctz"] in {
536 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
540 // --- 2 arguments ---
541 foreach name = ["abs_diff"] in {
542 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
544 foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
545 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
547 foreach name = ["max", "min"] in {
548 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
549 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
551 foreach name = ["upsample"] in {
552 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
553 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
554 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
555 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
556 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
557 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
560 // --- 3 arguments ---
561 foreach name = ["clamp"] in {
562 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
563 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
565 foreach name = ["mad_hi", "mad_sat"] in {
566 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
570 foreach name = ["mad24"] in {
571 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
572 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
574 foreach name = ["mul24"] in {
575 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
576 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
579 //--------------------------------------------------------------------
580 // OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
581 // OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
583 // --- 1 argument ---
584 foreach name = ["degrees", "radians", "sign"] in {
585 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
588 // --- 2 arguments ---
589 foreach name = ["max", "min"] in {
590 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
591 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
592 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
593 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
595 foreach name = ["step"] in {
596 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
597 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
598 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
599 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
602 // --- 3 arguments ---
603 foreach name = ["clamp", "mix"] in {
604 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
605 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
606 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
607 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
609 foreach name = ["smoothstep"] in {
610 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
611 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
612 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
613 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
617 //--------------------------------------------------------------------
618 // OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
619 // OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
621 // --- 1 argument ---
622 foreach name = ["length"] in {
623 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
624 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
625 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
627 foreach name = ["normalize"] in {
628 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
629 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
630 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
632 foreach name = ["fast_length"] in {
633 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
635 foreach name = ["fast_normalize"] in {
636 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
639 // --- 2 arguments ---
640 foreach name = ["cross"] in {
641 foreach VSize = [3, 4] in {
642 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
643 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
644 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
647 foreach name = ["dot", "distance"] in {
648 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
649 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
650 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
652 foreach name = ["fast_distance"] in {
653 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
657 //--------------------------------------------------------------------
658 // OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
659 // OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
661 // --- 1 argument ---
662 foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
663 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
664 def : Builtin<name, [Int, Double], Attr.Const>;
665 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
666 def : Builtin<name, [Int, Half], Attr.Const>;
667 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
669 foreach name = ["any", "all"] in {
670 def : Builtin<name, [Int, AIGenTypeN], Attr.Const>;
673 // --- 2 arguments ---
674 foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
675 "isless", "islessequal", "islessgreater", "isordered",
677 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
678 def : Builtin<name, [Int, Double, Double], Attr.Const>;
679 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
680 def : Builtin<name, [Int, Half, Half], Attr.Const>;
681 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
684 // --- 3 arguments ---
685 foreach name = ["bitselect"] in {
686 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
688 foreach name = ["select"] in {
689 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
690 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
691 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
692 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
693 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
694 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
695 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
696 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
697 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
698 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
702 //--------------------------------------------------------------------
703 // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
704 // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s5.1.6 and s6.1.6 - Vector Data Load and Store Functions
706 // Variants for OpenCL versions below 2.0, using pointers to the global, local
707 // and private address spaces.
708 let MaxVersion = CL20 in {
709 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
710 foreach VSize = [2, 3, 4, 8, 16] in {
711 foreach name = ["vload" # VSize] in {
712 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
713 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
714 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
715 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
716 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
717 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
718 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
719 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
720 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
721 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
722 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
724 foreach name = ["vstore" # VSize] in {
725 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
726 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
727 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
728 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
729 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
730 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
731 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
732 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
733 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
734 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
735 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
737 foreach name = ["vloada_half" # VSize] in {
738 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
740 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
741 foreach name = ["vstorea_half" # VSize # rnd] in {
742 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
743 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
749 // Variants for OpenCL versions above 2.0, using pointers to the generic
751 let MinVersion = CL20 in {
752 foreach VSize = [2, 3, 4, 8, 16] in {
753 foreach name = ["vload" # VSize] in {
754 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
755 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
756 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
757 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
758 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
759 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
760 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
761 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
762 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
763 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
764 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
766 foreach name = ["vstore" # VSize] in {
767 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
768 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
769 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
770 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
771 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
772 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
773 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
774 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
775 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
776 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
777 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
779 foreach name = ["vloada_half" # VSize] in {
780 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
782 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
783 foreach name = ["vstorea_half" # VSize # rnd] in {
784 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
785 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
790 // Variants using pointers to the constant address space.
791 foreach VSize = [2, 3, 4, 8, 16] in {
792 foreach name = ["vload" # VSize] in {
793 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
794 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
795 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
796 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
797 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
798 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
799 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
800 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
801 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
802 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
803 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
805 foreach name = ["vloada_half" # VSize] in {
806 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
808 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
809 foreach name = ["vstorea_half" # VSize # rnd] in {
810 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
811 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
815 let MaxVersion = CL20 in {
816 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
817 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
818 foreach VSize = [2, 3, 4, 8, 16] in {
819 foreach name = ["vload_half" # VSize] in {
820 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
823 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
824 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
825 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
826 foreach VSize = [2, 3, 4, 8, 16] in {
827 foreach name = ["vstore_half" # VSize # rnd] in {
828 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
829 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
835 let MinVersion = CL20 in {
836 foreach AS = [GenericAS] in {
837 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
838 foreach VSize = [2, 3, 4, 8, 16] in {
839 foreach name = ["vload_half" # VSize] in {
840 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
843 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
844 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
845 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
846 foreach VSize = [2, 3, 4, 8, 16] in {
847 foreach name = ["vstore_half" # VSize # rnd] in {
848 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
849 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
856 foreach AS = [ConstantAS] in {
857 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
858 foreach VSize = [2, 3, 4, 8, 16] in {
859 foreach name = ["vload_half" # VSize] in {
860 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
865 //--------------------------------------------------------------------
866 // OpenCL v1.1 s6.11.10, v1.2 s6.12.10, v2.0 s6.13.10: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
867 // OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
869 foreach name = ["async_work_group_copy"] in {
870 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
871 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
873 foreach name = ["async_work_group_strided_copy"] in {
874 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
875 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
877 foreach name = ["wait_group_events"] in {
878 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
880 foreach name = ["prefetch"] in {
881 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
884 //--------------------------------------------------------------------
885 // OpenCL v2.0 s6.13.11 - Atomics Functions.
886 // Functions that use memory_order and cl_mem_fence_flags enums are not
887 // declared here as the TableGen backend does not handle enums.
889 // OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
891 let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
892 foreach Type = [Int, UInt] in {
893 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
894 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
896 foreach name = ["atom_inc", "atom_dec"] in {
897 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
899 foreach name = ["atom_cmpxchg"] in {
900 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
905 let Extension = FuncExtKhrLocalInt32BaseAtomics in {
906 foreach Type = [Int, UInt] in {
907 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
908 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
910 foreach name = ["atom_inc", "atom_dec"] in {
911 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
913 foreach name = ["atom_cmpxchg"] in {
914 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
919 let Extension = FuncExtKhrInt64BaseAtomics in {
920 foreach AS = [GlobalAS, LocalAS] in {
921 foreach Type = [Long, ULong] in {
922 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
923 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
925 foreach name = ["atom_inc", "atom_dec"] in {
926 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
928 foreach name = ["atom_cmpxchg"] in {
929 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
935 let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
936 foreach Type = [Int, UInt] in {
937 foreach name = ["atom_min", "atom_max", "atom_and",
938 "atom_or", "atom_xor"] in {
939 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
944 let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
945 foreach Type = [Int, UInt] in {
946 foreach name = ["atom_min", "atom_max", "atom_and",
947 "atom_or", "atom_xor"] in {
948 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
953 let Extension = FuncExtKhrInt64ExtendedAtomics in {
954 foreach AS = [GlobalAS, LocalAS] in {
955 foreach Type = [Long, ULong] in {
956 foreach name = ["atom_min", "atom_max", "atom_and",
957 "atom_or", "atom_xor"] in {
958 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
963 // OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
964 foreach AS = [GlobalAS, LocalAS] in {
965 foreach Type = [Int, UInt] in {
966 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
967 "atomic_min", "atomic_max", "atomic_and",
968 "atomic_or", "atomic_xor"] in {
969 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
971 foreach name = ["atomic_inc", "atomic_dec"] in {
972 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
974 foreach name = ["atomic_cmpxchg"] in {
975 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
980 //--------------------------------------------------------------------
981 // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
983 foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
984 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
985 def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
986 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
987 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
991 foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
992 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
993 def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
994 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
995 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
996 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
1001 //--------------------------------------------------------------------
1002 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1003 // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1004 // --- Table 22: Image Read Functions with Samplers ---
1005 foreach imgTy = [Image1d] in {
1006 foreach coordTy = [Int, Float] in {
1007 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1008 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1009 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1012 foreach imgTy = [Image2d, Image1dArray] in {
1013 foreach coordTy = [Int, Float] in {
1014 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1015 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1016 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1019 foreach imgTy = [Image3d, Image2dArray] in {
1020 foreach coordTy = [Int, Float] in {
1021 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1022 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1023 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1026 foreach coordTy = [Int, Float] in {
1027 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1028 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1031 // --- Table 23: Sampler-less Read Functions ---
1032 foreach aQual = ["RO", "RW"] in {
1033 foreach imgTy = [Image2d, Image1dArray] in {
1034 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1035 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1036 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1038 foreach imgTy = [Image3d, Image2dArray] in {
1039 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1040 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1041 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1043 foreach imgTy = [Image1d, Image1dBuffer] in {
1044 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1045 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1046 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1048 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1049 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
1052 // --- Table 24: Image Write Functions ---
1053 foreach aQual = ["WO", "RW"] in {
1054 foreach imgTy = [Image2d] in {
1055 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1056 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1057 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1059 foreach imgTy = [Image2dArray] in {
1060 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1061 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1062 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1064 foreach imgTy = [Image1d, Image1dBuffer] in {
1065 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1066 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1067 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1069 foreach imgTy = [Image1dArray] in {
1070 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1071 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1072 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1074 foreach imgTy = [Image3d] in {
1075 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1076 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1077 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1079 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1080 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1083 // --- Table 25: Image Query Functions ---
1084 foreach aQual = ["RO", "WO", "RW"] in {
1085 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1086 Image1dArray, Image2dArray, Image2dDepth,
1087 Image2dArrayDepth] in {
1088 foreach name = ["get_image_width", "get_image_channel_data_type",
1089 "get_image_channel_order"] in {
1090 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1093 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1094 Image2dArrayDepth] in {
1095 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1097 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1098 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1099 Image2dArrayDepth] in {
1100 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1102 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1103 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1104 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1108 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1110 foreach aQual = ["RO"] in {
1111 foreach name = ["read_imageh"] in {
1112 foreach coordTy = [Int, Float] in {
1113 foreach imgTy = [Image2d, Image1dArray] in {
1114 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1116 foreach imgTy = [Image3d, Image2dArray] in {
1117 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1119 foreach imgTy = [Image1d] in {
1120 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
1125 // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1127 foreach aQual = ["RO", "RW"] in {
1128 foreach name = ["read_imageh"] in {
1129 foreach imgTy = [Image2d, Image1dArray] in {
1130 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1132 foreach imgTy = [Image3d, Image2dArray] in {
1133 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1135 foreach imgTy = [Image1d, Image1dBuffer] in {
1136 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1140 // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1142 foreach aQual = ["WO", "RW"] in {
1143 foreach name = ["write_imageh"] in {
1144 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1145 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1146 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1147 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1148 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1149 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1154 //--------------------------------------------------------------------
1155 // OpenCL v2.0 s6.13.15 - Work-group Functions
1157 let MinVersion = CL20 in {
1158 foreach name = ["work_group_all", "work_group_any"] in {
1159 def : Builtin<name, [Int, Int], Attr.Convergent>;
1161 foreach name = ["work_group_broadcast"] in {
1162 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1163 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1164 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1166 foreach op = ["add", "min", "max"] in {
1167 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1168 "work_group_scan_inclusive_"] in {
1169 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1175 // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
1176 let MinVersion = CL20 in {
1177 let Extension = FuncExtKhrSubgroups in {
1178 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1179 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1180 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
1184 //--------------------------------------------------------------------
1185 // End of the builtin functions defined in the OpenCL C specification.
1186 // Builtin functions defined in the OpenCL C Extension are below.
1187 //--------------------------------------------------------------------
1190 // OpenCL Extension v2.0 s9.18 - Mipmaps
1191 let Extension = FuncExtKhrMipmapImage in {
1192 // Added to section 6.13.14.2.
1193 foreach aQual = ["RO"] in {
1194 foreach imgTy = [Image2d] in {
1195 foreach name = ["read_imagef"] in {
1196 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1197 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1199 foreach name = ["read_imagei"] in {
1200 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1201 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1203 foreach name = ["read_imageui"] in {
1204 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1205 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1208 foreach imgTy = [Image2dDepth] in {
1209 foreach name = ["read_imagef"] in {
1210 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1211 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1214 foreach imgTy = [Image1d] in {
1215 foreach name = ["read_imagef"] in {
1216 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1217 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1219 foreach name = ["read_imagei"] in {
1220 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1221 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1223 foreach name = ["read_imageui"] in {
1224 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1225 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1228 foreach imgTy = [Image3d] in {
1229 foreach name = ["read_imagef"] in {
1230 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1231 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1233 foreach name = ["read_imagei"] in {
1234 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1235 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1237 foreach name = ["read_imageui"] in {
1238 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1239 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1242 foreach imgTy = [Image1dArray] in {
1243 foreach name = ["read_imagef"] in {
1244 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1245 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1247 foreach name = ["read_imagei"] in {
1248 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1249 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1251 foreach name = ["read_imageui"] in {
1252 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1253 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1256 foreach imgTy = [Image2dArray] in {
1257 foreach name = ["read_imagef"] in {
1258 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1259 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1261 foreach name = ["read_imagei"] in {
1262 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1263 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1265 foreach name = ["read_imageui"] in {
1266 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1267 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1270 foreach imgTy = [Image2dArrayDepth] in {
1271 foreach name = ["read_imagef"] in {
1272 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1273 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1277 // Added to section 6.13.14.4.
1278 foreach aQual = ["WO"] in {
1279 foreach imgTy = [Image2d] in {
1280 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1281 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1282 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
1284 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
1285 foreach imgTy = [Image1d] in {
1286 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1287 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1288 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
1290 foreach imgTy = [Image1dArray] in {
1291 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1292 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1293 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
1295 foreach imgTy = [Image2dArray] in {
1296 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1297 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1298 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1300 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
1301 let Extension = FuncExtKhrMipmapAndWrite3d in {
1302 foreach imgTy = [Image3d] in {
1303 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1304 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1305 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1309 // Added to section 6.13.14.5
1310 foreach aQual = ["RO", "WO", "RW"] in {
1311 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1312 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
1318 //--------------------------------------------------------------------
1319 // OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1320 let Extension = FuncExtKhrGlMsaaSharing in {
1321 // --- Table 6.13.14.3 ---
1322 foreach aQual = ["RO", "RW"] in {
1323 foreach imgTy = [Image2dMsaa] in {
1324 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1325 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1326 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1328 foreach imgTy = [Image2dArrayMsaa] in {
1329 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1330 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1331 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1333 foreach name = ["read_imagef"] in {
1334 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1335 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1339 // --- Table 6.13.14.5 ---
1340 foreach aQual = ["RO", "WO", "RW"] in {
1341 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1342 foreach name = ["get_image_width", "get_image_height",
1343 "get_image_channel_data_type", "get_image_channel_order",
1344 "get_image_num_samples"] in {
1345 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1347 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1349 def : Builtin<"get_image_array_size", [Size, ImageType<Image2dArrayMsaaDepth, aQual>], Attr.Const>;