xref: /freebsd/contrib/llvm-project/clang/lib/Sema/OpenCLBuiltins.td (revision 5ffd83dbcc34f10e07f6d3e968ae6365869615f4)
10b57cec5SDimitry Andric//==--- OpenCLBuiltins.td - OpenCL builtin declarations -------------------===//
20b57cec5SDimitry Andric//
30b57cec5SDimitry Andric//                     The LLVM Compiler Infrastructure
40b57cec5SDimitry Andric//
50b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
60b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
70b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
80b57cec5SDimitry Andric//
90b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
100b57cec5SDimitry Andric//
110b57cec5SDimitry Andric// This file contains TableGen definitions for OpenCL builtin function
120b57cec5SDimitry Andric// declarations.  In case of an unresolved function name in OpenCL, Clang will
130b57cec5SDimitry Andric// check for a function described in this file when -fdeclare-opencl-builtins
140b57cec5SDimitry Andric// is specified.
150b57cec5SDimitry Andric//
160b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
170b57cec5SDimitry Andric
180b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
190b57cec5SDimitry Andric//              Definitions of miscellaneous basic entities.
200b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
210b57cec5SDimitry Andric// Versions of OpenCL
220b57cec5SDimitry Andricclass Version<int _Version> {
23a7dea167SDimitry Andric  int ID = _Version;
240b57cec5SDimitry Andric}
25a7dea167SDimitry Andricdef CLAll : Version<  0>;
260b57cec5SDimitry Andricdef CL10  : Version<100>;
270b57cec5SDimitry Andricdef CL11  : Version<110>;
280b57cec5SDimitry Andricdef CL12  : Version<120>;
290b57cec5SDimitry Andricdef CL20  : Version<200>;
300b57cec5SDimitry Andric
310b57cec5SDimitry Andric// Address spaces
320b57cec5SDimitry Andric// Pointer types need to be assigned an address space.
330b57cec5SDimitry Andricclass AddressSpace<string _AS> {
34a7dea167SDimitry Andric  string Name = _AS;
350b57cec5SDimitry Andric}
36a7dea167SDimitry Andricdef DefaultAS    : AddressSpace<"clang::LangAS::Default">;
37a7dea167SDimitry Andricdef PrivateAS    : AddressSpace<"clang::LangAS::opencl_private">;
38a7dea167SDimitry Andricdef GlobalAS     : AddressSpace<"clang::LangAS::opencl_global">;
39a7dea167SDimitry Andricdef ConstantAS   : AddressSpace<"clang::LangAS::opencl_constant">;
40a7dea167SDimitry Andricdef LocalAS      : AddressSpace<"clang::LangAS::opencl_local">;
41a7dea167SDimitry Andricdef GenericAS    : AddressSpace<"clang::LangAS::opencl_generic">;
420b57cec5SDimitry Andric
43480093f4SDimitry Andric// OpenCL language extension.
44480093f4SDimitry Andricclass AbstractExtension<string _Ext> {
45480093f4SDimitry Andric  // One or more OpenCL extensions, space separated.  Each extension must be
46480093f4SDimitry Andric  // a valid extension name for the opencl extension pragma.
47480093f4SDimitry Andric  string ExtName = _Ext;
48480093f4SDimitry Andric}
49480093f4SDimitry Andric
50480093f4SDimitry Andric// Extension associated to a builtin function.
51480093f4SDimitry Andricclass FunctionExtension<string _Ext> : AbstractExtension<_Ext>;
52480093f4SDimitry Andric
53480093f4SDimitry Andric// FunctionExtension definitions.
54480093f4SDimitry Andricdef FuncExtNone                          : FunctionExtension<"">;
55480093f4SDimitry Andricdef FuncExtKhrSubgroups                  : FunctionExtension<"cl_khr_subgroups">;
56480093f4SDimitry Andricdef FuncExtKhrGlobalInt32BaseAtomics     : FunctionExtension<"cl_khr_global_int32_base_atomics">;
57480093f4SDimitry Andricdef FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
58480093f4SDimitry Andricdef FuncExtKhrLocalInt32BaseAtomics      : FunctionExtension<"cl_khr_local_int32_base_atomics">;
59480093f4SDimitry Andricdef FuncExtKhrLocalInt32ExtendedAtomics  : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
60480093f4SDimitry Andricdef FuncExtKhrInt64BaseAtomics           : FunctionExtension<"cl_khr_int64_base_atomics">;
61480093f4SDimitry Andricdef FuncExtKhrInt64ExtendedAtomics       : FunctionExtension<"cl_khr_int64_extended_atomics">;
62480093f4SDimitry Andricdef FuncExtKhrMipmapImage                : FunctionExtension<"cl_khr_mipmap_image">;
63*5ffd83dbSDimitry Andricdef FuncExtKhrMipmapImageWrites          : FunctionExtension<"cl_khr_mipmap_image_writes">;
64480093f4SDimitry Andricdef FuncExtKhrGlMsaaSharing              : FunctionExtension<"cl_khr_gl_msaa_sharing">;
65480093f4SDimitry Andric
66480093f4SDimitry Andric// Multiple extensions
67*5ffd83dbSDimitry Andricdef FuncExtKhrMipmapWritesAndWrite3d     : FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">;
68*5ffd83dbSDimitry Andric
69*5ffd83dbSDimitry Andric// Arm extensions.
70*5ffd83dbSDimitry Andricdef ArmIntegerDotProductInt8                   : FunctionExtension<"cl_arm_integer_dot_product_int8">;
71*5ffd83dbSDimitry Andricdef ArmIntegerDotProductAccumulateInt8         : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
72*5ffd83dbSDimitry Andricdef ArmIntegerDotProductAccumulateInt16        : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">;
73*5ffd83dbSDimitry Andricdef ArmIntegerDotProductAccumulateSaturateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_saturate_int8">;
740b57cec5SDimitry Andric
75a7dea167SDimitry Andric// Qualified Type.  These map to ASTContext::QualType.
76a7dea167SDimitry Andricclass QualType<string _Name, bit _IsAbstract=0> {
770b57cec5SDimitry Andric  // Name of the field or function in a clang::ASTContext
780b57cec5SDimitry Andric  // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
790b57cec5SDimitry Andric  string Name = _Name;
80a7dea167SDimitry Andric  // Some QualTypes in this file represent an abstract type for which there is
81a7dea167SDimitry Andric  // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
82a7dea167SDimitry Andric  // without access qualifiers.
83a7dea167SDimitry Andric  bit IsAbstract = _IsAbstract;
840b57cec5SDimitry Andric}
850b57cec5SDimitry Andric
86a7dea167SDimitry Andric// List of integers.
87a7dea167SDimitry Andricclass IntList<string _Name, list<int> _List> {
88a7dea167SDimitry Andric  string Name = _Name;
89a7dea167SDimitry Andric  list<int> List = _List;
900b57cec5SDimitry Andric}
910b57cec5SDimitry Andric
920b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
930b57cec5SDimitry Andric//                      OpenCL C classes for types
940b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
95a7dea167SDimitry Andric// OpenCL C basic data types (int, float, image2d_t, ...).
96a7dea167SDimitry Andric// Its child classes can represent concrete types (e.g. VectorType) or
97a7dea167SDimitry Andric// abstract types (e.g. GenType).
980b57cec5SDimitry Andricclass Type<string _Name, QualType _QTName> {
99a7dea167SDimitry Andric  // Name of the Type.
1000b57cec5SDimitry Andric  string Name = _Name;
101a7dea167SDimitry Andric  // QualType associated with this type.
1020b57cec5SDimitry Andric  QualType QTName = _QTName;
103a7dea167SDimitry Andric  // Size of the vector (if applicable).
104a7dea167SDimitry Andric  int VecWidth = 1;
105a7dea167SDimitry Andric  // Is a pointer.
1060b57cec5SDimitry Andric  bit IsPointer = 0;
107a7dea167SDimitry Andric  // "const" qualifier.
108a7dea167SDimitry Andric  bit IsConst = 0;
109a7dea167SDimitry Andric  // "volatile" qualifier.
110a7dea167SDimitry Andric  bit IsVolatile = 0;
1110b57cec5SDimitry Andric  // Access qualifier. Must be one of ("RO", "WO", "RW").
1120b57cec5SDimitry Andric  string AccessQualifier = "";
113a7dea167SDimitry Andric  // Address space.
114a7dea167SDimitry Andric  string AddrSpace = DefaultAS.Name;
1150b57cec5SDimitry Andric}
1160b57cec5SDimitry Andric
117a7dea167SDimitry Andric// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
1180b57cec5SDimitry Andricclass VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
119a7dea167SDimitry Andric  let VecWidth = _VecWidth;
120a7dea167SDimitry Andric  let AccessQualifier = "";
121a7dea167SDimitry Andric  // Inherited fields
122a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
123a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
124a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
125a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
1260b57cec5SDimitry Andric}
1270b57cec5SDimitry Andric
128a7dea167SDimitry Andric// OpenCL pointer types (e.g. int*, float*, ...).
129a7dea167SDimitry Andricclass PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
1300b57cec5SDimitry Andric    Type<_Ty.Name, _Ty.QTName> {
131a7dea167SDimitry Andric  let AddrSpace = _AS.Name;
132a7dea167SDimitry Andric  // Inherited fields
133a7dea167SDimitry Andric  let VecWidth = _Ty.VecWidth;
134a7dea167SDimitry Andric  let IsPointer = 1;
135a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
136a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
137a7dea167SDimitry Andric  let AccessQualifier = _Ty.AccessQualifier;
1380b57cec5SDimitry Andric}
1390b57cec5SDimitry Andric
140a7dea167SDimitry Andric// OpenCL const types (e.g. const int).
141a7dea167SDimitry Andricclass ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
142a7dea167SDimitry Andric  let IsConst = 1;
143a7dea167SDimitry Andric  // Inherited fields
144a7dea167SDimitry Andric  let VecWidth = _Ty.VecWidth;
145a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
146a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
147a7dea167SDimitry Andric  let AccessQualifier = _Ty.AccessQualifier;
148a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
149a7dea167SDimitry Andric}
150a7dea167SDimitry Andric
151a7dea167SDimitry Andric// OpenCL volatile types (e.g. volatile int).
152a7dea167SDimitry Andricclass VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
153a7dea167SDimitry Andric  let IsVolatile = 1;
154a7dea167SDimitry Andric  // Inherited fields
155a7dea167SDimitry Andric  let VecWidth = _Ty.VecWidth;
156a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
157a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
158a7dea167SDimitry Andric  let AccessQualifier = _Ty.AccessQualifier;
159a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
160a7dea167SDimitry Andric}
161a7dea167SDimitry Andric
162a7dea167SDimitry Andric// OpenCL image types (e.g. image2d).
163a7dea167SDimitry Andricclass ImageType<Type _Ty, string _AccessQualifier> :
164a7dea167SDimitry Andric    Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
165a7dea167SDimitry Andric  let VecWidth = 0;
1660b57cec5SDimitry Andric  let AccessQualifier = _AccessQualifier;
167a7dea167SDimitry Andric  // Inherited fields
168a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
169a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
170a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
171a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
172a7dea167SDimitry Andric}
173a7dea167SDimitry Andric
174a7dea167SDimitry Andric// List of Types.
175*5ffd83dbSDimitry Andricclass TypeList<list<Type> _Type> {
176a7dea167SDimitry Andric  list<Type> List = _Type;
177a7dea167SDimitry Andric}
178a7dea167SDimitry Andric
179a7dea167SDimitry Andric// A GenericType is an abstract type that defines a set of types as a
180a7dea167SDimitry Andric// combination of Types and vector sizes.
181a7dea167SDimitry Andric//
182a7dea167SDimitry Andric// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
183a7dea167SDimitry Andric// represents <int, int2, int4, float, float2, float4>.
184a7dea167SDimitry Andric//
185a7dea167SDimitry Andric// Some rules apply when using multiple GenericType arguments in a declaration:
186a7dea167SDimitry Andric//   1. The number of vector sizes must be equal or 1 for all gentypes in a
187a7dea167SDimitry Andric//      declaration.
188a7dea167SDimitry Andric//   2. The number of Types must be equal or 1 for all gentypes in a
189a7dea167SDimitry Andric//      declaration.
190a7dea167SDimitry Andric//   3. Generic types are combined by iterating over all generic types at once.
191a7dea167SDimitry Andric//      For example, for the following GenericTypes
192a7dea167SDimitry Andric//        GenT1 = GenericType<half, [1, 2]> and
193a7dea167SDimitry Andric//        GenT2 = GenericType<float, int, [1, 2]>
194a7dea167SDimitry Andric//      A declaration f(GenT1, GenT2) results in the combinations
195a7dea167SDimitry Andric//        f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
196a7dea167SDimitry Andric//   4. "sgentype" from the OpenCL specification is supported by specifying
197a7dea167SDimitry Andric//      a single vector size.
198a7dea167SDimitry Andric//      For example, for the following GenericTypes
199a7dea167SDimitry Andric//        GenT = GenericType<half, int, [1, 2]> and
200a7dea167SDimitry Andric//        SGenT = GenericType<half, int, [1]>
201a7dea167SDimitry Andric//      A declaration f(GenT, SGenT) results in the combinations
202a7dea167SDimitry Andric//        f(half, half), f(half2, half), f(int, int), f(int2, int) .
203a7dea167SDimitry Andricclass GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
204a7dea167SDimitry Andric    Type<_Ty, QualType<"null", 1>> {
205a7dea167SDimitry Andric  // Possible element types of the generic type.
206a7dea167SDimitry Andric  TypeList TypeList = _TypeList;
207a7dea167SDimitry Andric  // Possible vector sizes of the types in the TypeList.
208a7dea167SDimitry Andric  IntList VectorList = _VectorList;
209a7dea167SDimitry Andric  // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
210a7dea167SDimitry Andric  let VecWidth = 0;
2110b57cec5SDimitry Andric}
2120b57cec5SDimitry Andric
213480093f4SDimitry Andric// Builtin function attributes.
214480093f4SDimitry Andricdef Attr {
215480093f4SDimitry Andric  list<bit> None = [0, 0, 0];
216480093f4SDimitry Andric  list<bit> Pure = [1, 0, 0];
217480093f4SDimitry Andric  list<bit> Const = [0, 1, 0];
218480093f4SDimitry Andric  list<bit> Convergent = [0, 0, 1];
219480093f4SDimitry Andric}
220480093f4SDimitry Andric
2210b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2220b57cec5SDimitry Andric//                      OpenCL C class for builtin functions
2230b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
224480093f4SDimitry Andricclass Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
2250b57cec5SDimitry Andric  // Name of the builtin function
2260b57cec5SDimitry Andric  string Name = _Name;
2270b57cec5SDimitry Andric  // List of types used by the function. The first one is the return type and
2280b57cec5SDimitry Andric  // the following are the arguments. The list must have at least one element
2290b57cec5SDimitry Andric  // (the return type).
2300b57cec5SDimitry Andric  list<Type> Signature = _Signature;
231480093f4SDimitry Andric  // Function attribute __attribute__((pure))
232480093f4SDimitry Andric  bit IsPure = _Attributes[0];
233480093f4SDimitry Andric  // Function attribute __attribute__((const))
234480093f4SDimitry Andric  bit IsConst = _Attributes[1];
235480093f4SDimitry Andric  // Function attribute __attribute__((convergent))
236480093f4SDimitry Andric  bit IsConv = _Attributes[2];
237480093f4SDimitry Andric  // OpenCL extensions to which the function belongs.
238480093f4SDimitry Andric  FunctionExtension Extension = FuncExtNone;
239a7dea167SDimitry Andric  // Version of OpenCL from which the function is available (e.g.: CL10).
240a7dea167SDimitry Andric  // MinVersion is inclusive.
241a7dea167SDimitry Andric  Version MinVersion = CL10;
242a7dea167SDimitry Andric  // Version of OpenCL from which the function is not supported anymore.
243a7dea167SDimitry Andric  // MaxVersion is exclusive.
244a7dea167SDimitry Andric  // CLAll makes the function available for all versions.
245a7dea167SDimitry Andric  Version MaxVersion = CLAll;
2460b57cec5SDimitry Andric}
2470b57cec5SDimitry Andric
2480b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2490b57cec5SDimitry Andric//                 Definitions of OpenCL C types
2500b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
2510b57cec5SDimitry Andric
252a7dea167SDimitry Andric// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
253a7dea167SDimitry Andricdef Bool      : Type<"bool",      QualType<"BoolTy">>;
254a7dea167SDimitry Andricdef Char      : Type<"char",      QualType<"CharTy">>;
255a7dea167SDimitry Andricdef UChar     : Type<"uchar",     QualType<"UnsignedCharTy">>;
256a7dea167SDimitry Andricdef Short     : Type<"short",     QualType<"ShortTy">>;
257a7dea167SDimitry Andricdef UShort    : Type<"ushort",    QualType<"UnsignedShortTy">>;
258a7dea167SDimitry Andricdef Int       : Type<"int",       QualType<"IntTy">>;
259a7dea167SDimitry Andricdef UInt      : Type<"uint",      QualType<"UnsignedIntTy">>;
260a7dea167SDimitry Andricdef Long      : Type<"long",      QualType<"LongTy">>;
261a7dea167SDimitry Andricdef ULong     : Type<"ulong",     QualType<"UnsignedLongTy">>;
262a7dea167SDimitry Andricdef Float     : Type<"float",     QualType<"FloatTy">>;
263a7dea167SDimitry Andricdef Double    : Type<"double",    QualType<"DoubleTy">>;
264a7dea167SDimitry Andricdef Half      : Type<"half",      QualType<"HalfTy">>;
265a7dea167SDimitry Andricdef Size      : Type<"size_t",    QualType<"getSizeType()">>;
266a7dea167SDimitry Andricdef PtrDiff   : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
267a7dea167SDimitry Andricdef IntPtr    : Type<"intptr_t",  QualType<"getIntPtrType()">>;
268*5ffd83dbSDimitry Andricdef UIntPtr   : Type<"uintptr_t", QualType<"getUIntPtrType()">>;
269*5ffd83dbSDimitry Andricdef Void      : Type<"void",      QualType<"VoidTy">>;
270a7dea167SDimitry Andric
271a7dea167SDimitry Andric// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
272a7dea167SDimitry Andric// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
273a7dea167SDimitry Andric
274a7dea167SDimitry Andric// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
275a7dea167SDimitry Andric// The image definitions are "abstract".  They should not be used without
276a7dea167SDimitry Andric// specifying an access qualifier (RO/WO/RW).
277*5ffd83dbSDimitry Andricdef Image1d               : Type<"image1d_t", QualType<"OCLImage1d", 1>>;
278*5ffd83dbSDimitry Andricdef Image2d               : Type<"image2d_t", QualType<"OCLImage2d", 1>>;
279*5ffd83dbSDimitry Andricdef Image3d               : Type<"image3d_t", QualType<"OCLImage3d", 1>>;
280*5ffd83dbSDimitry Andricdef Image1dArray          : Type<"image1d_array_t", QualType<"OCLImage1dArray", 1>>;
281*5ffd83dbSDimitry Andricdef Image1dBuffer         : Type<"image1d_buffer_t", QualType<"OCLImage1dBuffer", 1>>;
282*5ffd83dbSDimitry Andricdef Image2dArray          : Type<"image2d_array_t", QualType<"OCLImage2dArray", 1>>;
283*5ffd83dbSDimitry Andricdef Image2dDepth          : Type<"image2d_depth_t", QualType<"OCLImage2dDepth", 1>>;
284*5ffd83dbSDimitry Andricdef Image2dArrayDepth     : Type<"image2d_array_depth_t", QualType<"OCLImage2dArrayDepth", 1>>;
285*5ffd83dbSDimitry Andricdef Image2dMsaa           : Type<"image2d_msaa_t", QualType<"OCLImage2dMSAA", 1>>;
286*5ffd83dbSDimitry Andricdef Image2dArrayMsaa      : Type<"image2d_array_msaa_t", QualType<"OCLImage2dArrayMSAA", 1>>;
287*5ffd83dbSDimitry Andricdef Image2dMsaaDepth      : Type<"image2d_msaa_depth_t", QualType<"OCLImage2dMSAADepth", 1>>;
288*5ffd83dbSDimitry Andricdef Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"OCLImage2dArrayMSAADepth", 1>>;
289a7dea167SDimitry Andric
290*5ffd83dbSDimitry Andricdef Sampler               : Type<"sampler_t", QualType<"OCLSamplerTy">>;
291*5ffd83dbSDimitry Andricdef ClkEvent              : Type<"clk_event_t", QualType<"OCLClkEventTy">>;
292*5ffd83dbSDimitry Andricdef Event                 : Type<"event_t", QualType<"OCLEventTy">>;
293*5ffd83dbSDimitry Andricdef Queue                 : Type<"queue_t", QualType<"OCLQueueTy">>;
294*5ffd83dbSDimitry Andricdef ReserveId             : Type<"reserve_id_t", QualType<"OCLReserveIDTy">>;
295*5ffd83dbSDimitry Andric
296*5ffd83dbSDimitry Andric// OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
297*5ffd83dbSDimitry Andricdef AtomicInt             : Type<"atomic_int", QualType<"getAtomicType(Context.IntTy)">>;
298*5ffd83dbSDimitry Andricdef AtomicUInt            : Type<"atomic_uint", QualType<"getAtomicType(Context.UnsignedIntTy)">>;
299*5ffd83dbSDimitry Andricdef AtomicLong            : Type<"atomic_long", QualType<"getAtomicType(Context.LongTy)">>;
300*5ffd83dbSDimitry Andricdef AtomicULong           : Type<"atomic_ulong", QualType<"getAtomicType(Context.UnsignedLongTy)">>;
301*5ffd83dbSDimitry Andricdef AtomicFloat           : Type<"atomic_float", QualType<"getAtomicType(Context.FloatTy)">>;
302*5ffd83dbSDimitry Andricdef AtomicDouble          : Type<"atomic_double", QualType<"getAtomicType(Context.DoubleTy)">>;
303*5ffd83dbSDimitry Andricdef AtomicIntPtr          : Type<"atomic_intptr_t", QualType<"getAtomicType(Context.getIntPtrType())">>;
304*5ffd83dbSDimitry Andricdef AtomicUIntPtr         : Type<"atomic_uintptr_t", QualType<"getAtomicType(Context.getUIntPtrType())">>;
305*5ffd83dbSDimitry Andricdef AtomicSize            : Type<"atomic_size_t", QualType<"getAtomicType(Context.getSizeType())">>;
306*5ffd83dbSDimitry Andricdef AtomicPtrDiff         : Type<"atomic_ptrdiff_t", QualType<"getAtomicType(Context.getPointerDiffType())">>;
307a7dea167SDimitry Andric
308a7dea167SDimitry Andric//===----------------------------------------------------------------------===//
309a7dea167SDimitry Andric//                 Definitions of OpenCL gentype variants
310a7dea167SDimitry Andric//===----------------------------------------------------------------------===//
311a7dea167SDimitry Andric// The OpenCL specification often uses "gentype" in builtin function
312a7dea167SDimitry Andric// declarations to indicate that a builtin function is available with various
313a7dea167SDimitry Andric// argument and return types.  The types represented by "gentype" vary between
314a7dea167SDimitry Andric// different parts of the specification.  The following definitions capture
315a7dea167SDimitry Andric// the different type lists for gentypes in different parts of the
316a7dea167SDimitry Andric// specification.
317a7dea167SDimitry Andric
318a7dea167SDimitry Andric// Vector width lists.
319a7dea167SDimitry Andricdef VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
320a7dea167SDimitry Andricdef VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
321a7dea167SDimitry Andricdef Vec1        : IntList<"Vec1", [1]>;
322480093f4SDimitry Andricdef Vec2        : IntList<"Vec2", [2]>;
323480093f4SDimitry Andricdef Vec4        : IntList<"Vec4", [4]>;
324480093f4SDimitry Andricdef Vec8        : IntList<"Vec8", [8]>;
325480093f4SDimitry Andricdef Vec16       : IntList<"Vec16", [16]>;
326480093f4SDimitry Andricdef Vec1234     : IntList<"Vec1234", [1, 2, 3, 4]>;
327a7dea167SDimitry Andric
328a7dea167SDimitry Andric// Type lists.
329*5ffd83dbSDimitry Andricdef TLAll           : TypeList<[Char,  UChar, Short,  UShort, Int,  UInt, Long,  ULong, Float, Double, Half]>;
330*5ffd83dbSDimitry Andricdef TLAllUnsigned   : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt,  ULong,  UShort]>;
331*5ffd83dbSDimitry Andricdef TLFloat         : TypeList<[Float, Double, Half]>;
332*5ffd83dbSDimitry Andricdef TLSignedInts    : TypeList<[Char, Short, Int, Long]>;
333*5ffd83dbSDimitry Andricdef TLUnsignedInts  : TypeList<[UChar, UShort, UInt, ULong]>;
334480093f4SDimitry Andric
335*5ffd83dbSDimitry Andricdef TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
336480093f4SDimitry Andric
337480093f4SDimitry Andric// All unsigned integer types twice, to facilitate unsigned return types for e.g.
338480093f4SDimitry Andric// uchar abs(char) and
339480093f4SDimitry Andric// uchar abs(uchar).
340*5ffd83dbSDimitry Andricdef TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
341a7dea167SDimitry Andric
342*5ffd83dbSDimitry Andricdef TLAllInts       : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
343a7dea167SDimitry Andric
344a7dea167SDimitry Andric// GenType definitions for multiple base types (e.g. all floating point types,
345a7dea167SDimitry Andric// or all integer types).
346a7dea167SDimitry Andric// All types
347a7dea167SDimitry Andricdef AGenTypeN              : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
348a7dea167SDimitry Andricdef AGenTypeNNoScalar      : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
349a7dea167SDimitry Andric// All integer
350a7dea167SDimitry Andricdef AIGenType1             : GenericType<"AIGenType1", TLAllInts, Vec1>;
351a7dea167SDimitry Andricdef AIGenTypeN             : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
352a7dea167SDimitry Andricdef AIGenTypeNNoScalar     : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
353480093f4SDimitry Andric// All integer to unsigned
354480093f4SDimitry Andricdef AI2UGenTypeN           : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
355480093f4SDimitry Andric// Signed integer
356480093f4SDimitry Andricdef SGenTypeN              : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
357480093f4SDimitry Andric// Unsigned integer
358480093f4SDimitry Andricdef UGenTypeN              : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
359a7dea167SDimitry Andric// Float
360a7dea167SDimitry Andricdef FGenTypeN              : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
361480093f4SDimitry Andric// (u)int, (u)long, and all floats
362480093f4SDimitry Andricdef IntLongFloatGenType1   : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
363a7dea167SDimitry Andric
364a7dea167SDimitry Andric// GenType definitions for every single base type (e.g. fp32 only).
365a7dea167SDimitry Andric// Names are like: GenTypeFloatVecAndScalar.
366a7dea167SDimitry Andricforeach Type = [Char, UChar, Short, UShort,
367a7dea167SDimitry Andric                Int, UInt, Long, ULong,
368a7dea167SDimitry Andric                Float, Double, Half] in {
369a7dea167SDimitry Andric  foreach VecSizes = [VecAndScalar, VecNoScalar] in {
370a7dea167SDimitry Andric    def "GenType" # Type # VecSizes :
371a7dea167SDimitry Andric              GenericType<"GenType" # Type # VecSizes,
372*5ffd83dbSDimitry Andric                          TypeList<[Type]>, VecSizes>;
373a7dea167SDimitry Andric  }
3740b57cec5SDimitry Andric}
3750b57cec5SDimitry Andric
376480093f4SDimitry Andric// GenType definitions for vec1234.
377480093f4SDimitry Andricforeach Type = [Float, Double, Half] in {
378480093f4SDimitry Andric  def "GenType" # Type # Vec1234 :
379480093f4SDimitry Andric              GenericType<"GenType" # Type # Vec1234,
380*5ffd83dbSDimitry Andric                          TypeList<[Type]>, Vec1234>;
381480093f4SDimitry Andric}
382480093f4SDimitry Andric
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
3850b57cec5SDimitry Andric//                 Definitions of OpenCL builtin functions
3860b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
387a7dea167SDimitry Andric//--------------------------------------------------------------------
388a7dea167SDimitry Andric// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
389a7dea167SDimitry Andric// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
390a7dea167SDimitry Andric
391a7dea167SDimitry Andric// Generate the convert_* builtins functions.
392a7dea167SDimitry Andricforeach RType = [Float, Double, Half, Char, UChar, Short,
393a7dea167SDimitry Andric                 UShort, Int, UInt, Long, ULong] in {
394a7dea167SDimitry Andric  foreach IType = [Float, Double, Half, Char, UChar, Short,
395a7dea167SDimitry Andric                   UShort, Int, UInt, Long, ULong] in {
396*5ffd83dbSDimitry Andric    // Conversions to integer type have a sat and non-sat variant.
397*5ffd83dbSDimitry Andric    foreach sat = !cond(!eq(RType.Name, "float") : [""],
398*5ffd83dbSDimitry Andric                        !eq(RType.Name, "double") : [""],
399*5ffd83dbSDimitry Andric                        !eq(RType.Name, "half") : [""],
400*5ffd83dbSDimitry Andric                        1 : ["", "_sat"]) in {
401a7dea167SDimitry Andric      foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
402480093f4SDimitry Andric        def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
403480093f4SDimitry Andric                      Attr.Const>;
4040b57cec5SDimitry Andric        foreach v = [2, 3, 4, 8, 16] in {
405a7dea167SDimitry Andric          def : Builtin<"convert_" # RType.Name # v # sat # rnd,
406480093f4SDimitry Andric                        [VectorType<RType, v>, VectorType<IType, v>],
407480093f4SDimitry Andric                        Attr.Const>;
4080b57cec5SDimitry Andric        }
4090b57cec5SDimitry Andric      }
4100b57cec5SDimitry Andric    }
4110b57cec5SDimitry Andric  }
4120b57cec5SDimitry Andric}
4130b57cec5SDimitry Andric
414a7dea167SDimitry Andric//--------------------------------------------------------------------
415a7dea167SDimitry Andric// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
416a7dea167SDimitry Andric// --- Table 7 ---
417480093f4SDimitry Andricdef : Builtin<"get_work_dim", [UInt], Attr.Const>;
4180b57cec5SDimitry Andricforeach name = ["get_global_size", "get_global_id", "get_local_size",
4190b57cec5SDimitry Andric                "get_local_id", "get_num_groups", "get_group_id",
4200b57cec5SDimitry Andric                "get_global_offset"] in {
421480093f4SDimitry Andric  def : Builtin<name, [Size, UInt], Attr.Const>;
422a7dea167SDimitry Andric}
423a7dea167SDimitry Andric
424a7dea167SDimitry Andriclet MinVersion = CL20 in {
425a7dea167SDimitry Andric  def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
426a7dea167SDimitry Andric  foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
427a7dea167SDimitry Andric    def : Builtin<name, [Size]>;
428a7dea167SDimitry Andric  }
429a7dea167SDimitry Andric}
430a7dea167SDimitry Andric
431480093f4SDimitry Andric
432480093f4SDimitry Andric//--------------------------------------------------------------------
433480093f4SDimitry Andric// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
434480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
435480093f4SDimitry Andric// --- Table 8 ---
436480093f4SDimitry Andric// --- 1 argument ---
437480093f4SDimitry Andricforeach name = ["acos", "acosh", "acospi",
438480093f4SDimitry Andric                "asin", "asinh", "asinpi",
439480093f4SDimitry Andric                "atan", "atanh", "atanpi",
440480093f4SDimitry Andric                "cbrt", "ceil",
441480093f4SDimitry Andric                "cos", "cosh", "cospi",
442480093f4SDimitry Andric                "erfc", "erf",
443480093f4SDimitry Andric                "exp", "exp2", "exp10", "expm1",
444480093f4SDimitry Andric                "fabs", "floor",
445480093f4SDimitry Andric                "log", "log2", "log10", "log1p", "logb",
446480093f4SDimitry Andric                "rint", "round", "rsqrt",
447480093f4SDimitry Andric                "sin", "sinh", "sinpi",
448480093f4SDimitry Andric                "sqrt",
449480093f4SDimitry Andric                "tan", "tanh", "tanpi",
450480093f4SDimitry Andric                "tgamma", "trunc",
451480093f4SDimitry Andric                "lgamma"] in {
452480093f4SDimitry Andric    def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
453480093f4SDimitry Andric}
454480093f4SDimitry Andricforeach name = ["nan"] in {
455480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
456480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
457480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
458480093f4SDimitry Andric}
459480093f4SDimitry Andric
460480093f4SDimitry Andric// --- 2 arguments ---
461480093f4SDimitry Andricforeach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
462480093f4SDimitry Andric                "maxmag", "minmag", "nextafter", "pow", "powr",
463480093f4SDimitry Andric                "remainder"] in {
464480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
465480093f4SDimitry Andric}
466480093f4SDimitry Andricforeach name = ["fmax", "fmin"] in {
467480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
468480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
469480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
470480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
471480093f4SDimitry Andric}
472480093f4SDimitry Andricforeach name = ["ilogb"] in {
473480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
474480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
475480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
476480093f4SDimitry Andric}
477480093f4SDimitry Andricforeach name = ["ldexp"] in {
478480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
479480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
480480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
481480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
482480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
483480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
484480093f4SDimitry Andric}
485480093f4SDimitry Andricforeach name = ["pown", "rootn"] in {
486480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
487480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
488480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
489480093f4SDimitry Andric}
490480093f4SDimitry Andric
491480093f4SDimitry Andric// --- 3 arguments ---
492480093f4SDimitry Andricforeach name = ["fma", "mad"] in {
493480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
494480093f4SDimitry Andric}
495480093f4SDimitry Andric
496480093f4SDimitry Andric// --- Version dependent ---
497480093f4SDimitry Andriclet MaxVersion = CL20 in {
498480093f4SDimitry Andric  foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
499480093f4SDimitry Andric    foreach name = ["fract", "modf", "sincos"] in {
500480093f4SDimitry Andric      def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
501480093f4SDimitry Andric    }
502480093f4SDimitry Andric    foreach name = ["frexp", "lgamma_r"] in {
503480093f4SDimitry Andric      foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
504480093f4SDimitry Andric        def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
505480093f4SDimitry Andric      }
506480093f4SDimitry Andric    }
507480093f4SDimitry Andric    foreach name = ["remquo"] in {
508480093f4SDimitry Andric      foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
509480093f4SDimitry Andric        def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
510480093f4SDimitry Andric      }
511480093f4SDimitry Andric    }
512480093f4SDimitry Andric  }
513480093f4SDimitry Andric}
514480093f4SDimitry Andriclet MinVersion = CL20 in {
515480093f4SDimitry Andric  foreach name = ["fract", "modf", "sincos"] in {
516480093f4SDimitry Andric    def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
517480093f4SDimitry Andric  }
518480093f4SDimitry Andric  foreach name = ["frexp", "lgamma_r"] in {
519480093f4SDimitry Andric    foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
520480093f4SDimitry Andric      def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
521480093f4SDimitry Andric    }  }
522480093f4SDimitry Andric  foreach name = ["remquo"] in {
523480093f4SDimitry Andric    foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
524480093f4SDimitry Andric      def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
525480093f4SDimitry Andric    }
526480093f4SDimitry Andric  }
527480093f4SDimitry Andric}
528480093f4SDimitry Andric
529480093f4SDimitry Andric// --- Table 9 ---
530480093f4SDimitry Andricforeach name = ["half_cos",
531480093f4SDimitry Andric                "half_exp", "half_exp2", "half_exp10",
532480093f4SDimitry Andric                "half_log", "half_log2", "half_log10",
533480093f4SDimitry Andric                "half_recip", "half_rsqrt",
534480093f4SDimitry Andric                "half_sin", "half_sqrt", "half_tan",
535480093f4SDimitry Andric                "native_cos",
536480093f4SDimitry Andric                "native_exp", "native_exp2", "native_exp10",
537480093f4SDimitry Andric                "native_log", "native_log2", "native_log10",
538480093f4SDimitry Andric                "native_recip", "native_rsqrt",
539480093f4SDimitry Andric                "native_sin", "native_sqrt", "native_tan"] in {
540480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
541480093f4SDimitry Andric}
542480093f4SDimitry Andricforeach name = ["half_divide", "half_powr",
543480093f4SDimitry Andric                "native_divide", "native_powr"] in {
544480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
545480093f4SDimitry Andric}
546480093f4SDimitry Andric
547480093f4SDimitry Andric//--------------------------------------------------------------------
548480093f4SDimitry Andric// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
549480093f4SDimitry Andric// --- Table 10 ---
550480093f4SDimitry Andric// --- 1 argument ---
551480093f4SDimitry Andricforeach name = ["abs"] in {
552480093f4SDimitry Andric  def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
553480093f4SDimitry Andric}
554480093f4SDimitry Andricforeach name = ["clz", "popcount"] in {
555480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
556480093f4SDimitry Andric}
557480093f4SDimitry Andriclet MinVersion = CL20 in {
558480093f4SDimitry Andric  foreach name = ["ctz"] in {
559480093f4SDimitry Andric    def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
560480093f4SDimitry Andric  }
561480093f4SDimitry Andric}
562480093f4SDimitry Andric
563480093f4SDimitry Andric// --- 2 arguments ---
564480093f4SDimitry Andricforeach name = ["abs_diff"] in {
565480093f4SDimitry Andric  def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
566480093f4SDimitry Andric}
567480093f4SDimitry Andricforeach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
568480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
569480093f4SDimitry Andric}
570480093f4SDimitry Andricforeach name = ["max", "min"] in {
571480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
572480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
573480093f4SDimitry Andric}
574480093f4SDimitry Andricforeach name = ["upsample"] in {
575480093f4SDimitry Andric  def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
576480093f4SDimitry Andric  def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
577480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
578480093f4SDimitry Andric  def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
579480093f4SDimitry Andric  def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
580480093f4SDimitry Andric  def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
581480093f4SDimitry Andric}
582480093f4SDimitry Andric
583480093f4SDimitry Andric// --- 3 arguments ---
584480093f4SDimitry Andricforeach name = ["clamp"] in {
585480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
586480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
587480093f4SDimitry Andric}
588480093f4SDimitry Andricforeach name = ["mad_hi", "mad_sat"] in {
589480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
590480093f4SDimitry Andric}
591480093f4SDimitry Andric
592480093f4SDimitry Andric// --- Table 11 ---
593480093f4SDimitry Andricforeach name = ["mad24"] in {
594480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
595480093f4SDimitry Andric  def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
596480093f4SDimitry Andric}
597480093f4SDimitry Andricforeach name = ["mul24"] in {
598480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
599480093f4SDimitry Andric  def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
600480093f4SDimitry Andric}
601480093f4SDimitry Andric
602480093f4SDimitry Andric//--------------------------------------------------------------------
603480093f4SDimitry Andric// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
604480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
605480093f4SDimitry Andric// --- Table 12 ---
606480093f4SDimitry Andric// --- 1 argument ---
607480093f4SDimitry Andricforeach name = ["degrees", "radians", "sign"] in {
608480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
609480093f4SDimitry Andric}
610480093f4SDimitry Andric
611480093f4SDimitry Andric// --- 2 arguments ---
612480093f4SDimitry Andricforeach name = ["max", "min"] in {
613480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
614480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
615480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
616480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
617480093f4SDimitry Andric}
618480093f4SDimitry Andricforeach name = ["step"] in {
619480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
620480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
621480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
622480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
623480093f4SDimitry Andric}
624480093f4SDimitry Andric
625480093f4SDimitry Andric// --- 3 arguments ---
626480093f4SDimitry Andricforeach name = ["clamp", "mix"] in {
627480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
628480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
629480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
630480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
631480093f4SDimitry Andric}
632480093f4SDimitry Andricforeach name = ["smoothstep"] in {
633480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
634480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
635480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
636480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
637480093f4SDimitry Andric}
638480093f4SDimitry Andric
639480093f4SDimitry Andric
640480093f4SDimitry Andric//--------------------------------------------------------------------
641480093f4SDimitry Andric// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
642480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
643480093f4SDimitry Andric// --- Table 13 ---
644480093f4SDimitry Andric// --- 1 argument ---
645480093f4SDimitry Andricforeach name = ["length"] in {
646480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
647480093f4SDimitry Andric  def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
648480093f4SDimitry Andric  def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
649480093f4SDimitry Andric}
650480093f4SDimitry Andricforeach name = ["normalize"] in {
651480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
652480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
653480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
654480093f4SDimitry Andric}
655480093f4SDimitry Andricforeach name = ["fast_length"] in {
656480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
657480093f4SDimitry Andric}
658480093f4SDimitry Andricforeach name = ["fast_normalize"] in {
659480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
660480093f4SDimitry Andric}
661480093f4SDimitry Andric
662480093f4SDimitry Andric// --- 2 arguments ---
663480093f4SDimitry Andricforeach name = ["cross"] in {
664480093f4SDimitry Andric  foreach VSize = [3, 4] in {
665480093f4SDimitry Andric    def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
666480093f4SDimitry Andric    def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
667480093f4SDimitry Andric    def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
668480093f4SDimitry Andric  }
669480093f4SDimitry Andric}
670480093f4SDimitry Andricforeach name = ["dot", "distance"] in {
671480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
672480093f4SDimitry Andric  def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
673480093f4SDimitry Andric  def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
674480093f4SDimitry Andric}
675480093f4SDimitry Andricforeach name = ["fast_distance"] in {
676480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
677480093f4SDimitry Andric}
678480093f4SDimitry Andric
679480093f4SDimitry Andric
680480093f4SDimitry Andric//--------------------------------------------------------------------
681480093f4SDimitry Andric// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
682480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
683480093f4SDimitry Andric// --- Table 14 ---
684480093f4SDimitry Andric// --- 1 argument ---
685480093f4SDimitry Andricforeach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
686480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
687480093f4SDimitry Andric  def : Builtin<name, [Int, Double], Attr.Const>;
688480093f4SDimitry Andric  def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
689480093f4SDimitry Andric  def : Builtin<name, [Int, Half], Attr.Const>;
690480093f4SDimitry Andric  def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
691480093f4SDimitry Andric}
692480093f4SDimitry Andricforeach name = ["any", "all"] in {
693*5ffd83dbSDimitry Andric  def : Builtin<name, [Int, SGenTypeN], Attr.Const>;
694480093f4SDimitry Andric}
695480093f4SDimitry Andric
696480093f4SDimitry Andric// --- 2 arguments ---
697480093f4SDimitry Andricforeach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
698480093f4SDimitry Andric                "isless", "islessequal", "islessgreater", "isordered",
699480093f4SDimitry Andric                "isunordered"] in {
700480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
701480093f4SDimitry Andric  def : Builtin<name, [Int, Double, Double], Attr.Const>;
702480093f4SDimitry Andric  def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
703480093f4SDimitry Andric  def : Builtin<name, [Int, Half, Half], Attr.Const>;
704480093f4SDimitry Andric  def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
705480093f4SDimitry Andric}
706480093f4SDimitry Andric
707480093f4SDimitry Andric// --- 3 arguments ---
708480093f4SDimitry Andricforeach name = ["bitselect"] in {
709480093f4SDimitry Andric  def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
710480093f4SDimitry Andric}
711480093f4SDimitry Andricforeach name = ["select"] in {
712480093f4SDimitry Andric  def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
713480093f4SDimitry Andric  def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
714480093f4SDimitry Andric  def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
715480093f4SDimitry Andric  def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
716480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
717480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
718480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
719480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
720480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
721480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
722480093f4SDimitry Andric}
723480093f4SDimitry Andric
724480093f4SDimitry Andric
725a7dea167SDimitry Andric//--------------------------------------------------------------------
726a7dea167SDimitry Andric// OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
727480093f4SDimitry Andric// 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
728a7dea167SDimitry Andric// --- Table 15 ---
729a7dea167SDimitry Andric// Variants for OpenCL versions below 2.0, using pointers to the global, local
730a7dea167SDimitry Andric// and private address spaces.
731a7dea167SDimitry Andriclet MaxVersion = CL20 in {
732a7dea167SDimitry Andric  foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
733a7dea167SDimitry Andric    foreach VSize = [2, 3, 4, 8, 16] in {
734a7dea167SDimitry Andric      foreach name = ["vload" # VSize] in {
735a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
736a7dea167SDimitry Andric        def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
737a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
738a7dea167SDimitry Andric        def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
739a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
740a7dea167SDimitry Andric        def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
741a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
742a7dea167SDimitry Andric        def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
743a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
744a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
745a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
746a7dea167SDimitry Andric      }
747a7dea167SDimitry Andric      foreach name = ["vstore" # VSize] in {
748*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>;
749*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>;
750*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>;
751*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>;
752*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>;
753*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>;
754*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>;
755*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>;
756*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>;
757*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>;
758*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>;
759a7dea167SDimitry Andric      }
760a7dea167SDimitry Andric      foreach name = ["vloada_half" # VSize] in {
761a7dea167SDimitry Andric        def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
762a7dea167SDimitry Andric      }
763a7dea167SDimitry Andric      foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
764a7dea167SDimitry Andric        foreach name = ["vstorea_half" # VSize # rnd] in {
765a7dea167SDimitry Andric          def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
766a7dea167SDimitry Andric          def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
767a7dea167SDimitry Andric        }
768a7dea167SDimitry Andric      }
769a7dea167SDimitry Andric    }
770a7dea167SDimitry Andric  }
771a7dea167SDimitry Andric}
772a7dea167SDimitry Andric// Variants for OpenCL versions above 2.0, using pointers to the generic
773a7dea167SDimitry Andric// address space.
774a7dea167SDimitry Andriclet MinVersion = CL20 in {
775a7dea167SDimitry Andric  foreach VSize = [2, 3, 4, 8, 16] in {
776a7dea167SDimitry Andric    foreach name = ["vload" # VSize] in {
777a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
778a7dea167SDimitry Andric      def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
779a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
780a7dea167SDimitry Andric      def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
781a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
782a7dea167SDimitry Andric      def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
783a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
784a7dea167SDimitry Andric      def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
785a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
786a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
787a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
788a7dea167SDimitry Andric    }
789a7dea167SDimitry Andric    foreach name = ["vstore" # VSize] in {
790*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, GenericAS>]>;
791*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, GenericAS>]>;
792*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, GenericAS>]>;
793*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, GenericAS>]>;
794*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, GenericAS>]>;
795*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, GenericAS>]>;
796*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, GenericAS>]>;
797*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, GenericAS>]>;
798*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, GenericAS>]>;
799*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, GenericAS>]>;
800*5ffd83dbSDimitry Andric      def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, GenericAS>]>;
801a7dea167SDimitry Andric    }
802a7dea167SDimitry Andric    foreach name = ["vloada_half" # VSize] in {
803a7dea167SDimitry Andric      def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
804a7dea167SDimitry Andric    }
805a7dea167SDimitry Andric    foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
806a7dea167SDimitry Andric      foreach name = ["vstorea_half" # VSize # rnd] in {
807a7dea167SDimitry Andric        def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
808a7dea167SDimitry Andric        def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
809a7dea167SDimitry Andric      }
810a7dea167SDimitry Andric    }
811a7dea167SDimitry Andric  }
812a7dea167SDimitry Andric}
813a7dea167SDimitry Andric// Variants using pointers to the constant address space.
814a7dea167SDimitry Andricforeach VSize = [2, 3, 4, 8, 16] in {
815a7dea167SDimitry Andric  foreach name = ["vload" # VSize] in {
816a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
817a7dea167SDimitry Andric    def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
818a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
819a7dea167SDimitry Andric    def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
820a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
821a7dea167SDimitry Andric    def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
822a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
823a7dea167SDimitry Andric    def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
824a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
825a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
826a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
827a7dea167SDimitry Andric  }
828a7dea167SDimitry Andric  foreach name = ["vloada_half" # VSize] in {
829a7dea167SDimitry Andric    def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
830a7dea167SDimitry Andric  }
831a7dea167SDimitry Andric}
832480093f4SDimitry Andriclet MaxVersion = CL20 in {
833480093f4SDimitry Andric  foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
834480093f4SDimitry Andric    def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
835*5ffd83dbSDimitry Andric    def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
836480093f4SDimitry Andric    foreach VSize = [2, 3, 4, 8, 16] in {
837480093f4SDimitry Andric      foreach name = ["vload_half" # VSize] in {
838480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
839480093f4SDimitry Andric      }
840480093f4SDimitry Andric    }
841480093f4SDimitry Andric    foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
842*5ffd83dbSDimitry Andric      foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in {
843*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, Float, Size, PointerType<Half, AS>]>;
844*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, Double, Size, PointerType<Half, AS>]>;
845*5ffd83dbSDimitry Andric      }
846480093f4SDimitry Andric      foreach VSize = [2, 3, 4, 8, 16] in {
847480093f4SDimitry Andric        foreach name = ["vstore_half" # VSize # rnd] in {
848480093f4SDimitry Andric          def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
849480093f4SDimitry Andric          def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
850480093f4SDimitry Andric        }
851480093f4SDimitry Andric      }
852480093f4SDimitry Andric    }
853480093f4SDimitry Andric  }
854480093f4SDimitry Andric}
855480093f4SDimitry Andriclet MinVersion = CL20 in {
856480093f4SDimitry Andric  foreach AS = [GenericAS] in {
857480093f4SDimitry Andric    def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
858*5ffd83dbSDimitry Andric    def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
859480093f4SDimitry Andric    foreach VSize = [2, 3, 4, 8, 16] in {
860480093f4SDimitry Andric      foreach name = ["vload_half" # VSize] in {
861480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
862480093f4SDimitry Andric      }
863480093f4SDimitry Andric    }
864480093f4SDimitry Andric    foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
865*5ffd83dbSDimitry Andric      foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in {
866*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, Float, Size, PointerType<Half, AS>]>;
867*5ffd83dbSDimitry Andric        def : Builtin<name, [Void, Double, Size, PointerType<Half, AS>]>;
868*5ffd83dbSDimitry Andric      }
869480093f4SDimitry Andric      foreach VSize = [2, 3, 4, 8, 16] in {
870480093f4SDimitry Andric        foreach name = ["vstore_half" # VSize # rnd] in {
871480093f4SDimitry Andric          def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
872480093f4SDimitry Andric          def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
873480093f4SDimitry Andric        }
874480093f4SDimitry Andric      }
875480093f4SDimitry Andric    }
876480093f4SDimitry Andric  }
877480093f4SDimitry Andric}
878480093f4SDimitry Andric
879480093f4SDimitry Andricforeach AS = [ConstantAS] in {
880480093f4SDimitry Andric  def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
881*5ffd83dbSDimitry Andric  def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
882480093f4SDimitry Andric  foreach VSize = [2, 3, 4, 8, 16] in {
883480093f4SDimitry Andric    foreach name = ["vload_half" # VSize] in {
884480093f4SDimitry Andric      def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
885480093f4SDimitry Andric    }
886480093f4SDimitry Andric  }
887480093f4SDimitry Andric}
888a7dea167SDimitry Andric
889a7dea167SDimitry Andric//--------------------------------------------------------------------
890a7dea167SDimitry Andric// 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
891a7dea167SDimitry Andric// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
892a7dea167SDimitry Andric// --- Table 18 ---
893a7dea167SDimitry Andricforeach name = ["async_work_group_copy"] in {
894a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
895a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
896a7dea167SDimitry Andric}
897a7dea167SDimitry Andricforeach name = ["async_work_group_strided_copy"] in {
898a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
899a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
900a7dea167SDimitry Andric}
901a7dea167SDimitry Andricforeach name = ["wait_group_events"] in {
902a7dea167SDimitry Andric  def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
903a7dea167SDimitry Andric}
904a7dea167SDimitry Andricforeach name = ["prefetch"] in {
905a7dea167SDimitry Andric  def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
906a7dea167SDimitry Andric}
907a7dea167SDimitry Andric
908a7dea167SDimitry Andric//--------------------------------------------------------------------
909a7dea167SDimitry Andric// OpenCL v2.0 s6.13.11 - Atomics Functions.
910a7dea167SDimitry Andric// Functions that use memory_order and cl_mem_fence_flags enums are not
911a7dea167SDimitry Andric// declared here as the TableGen backend does not handle enums.
912a7dea167SDimitry Andric
913480093f4SDimitry Andric// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
914a7dea167SDimitry Andric// --- Table 9.1 ---
915480093f4SDimitry Andriclet Extension = FuncExtKhrGlobalInt32BaseAtomics in {
916a7dea167SDimitry Andric  foreach Type = [Int, UInt] in {
917a7dea167SDimitry Andric    foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
918a7dea167SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
919a7dea167SDimitry Andric    }
920a7dea167SDimitry Andric    foreach name = ["atom_inc", "atom_dec"] in {
921a7dea167SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
922a7dea167SDimitry Andric    }
923a7dea167SDimitry Andric    foreach name = ["atom_cmpxchg"] in {
924a7dea167SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
925a7dea167SDimitry Andric    }
9260b57cec5SDimitry Andric  }
927480093f4SDimitry Andric}
928480093f4SDimitry Andric// --- Table 9.3 ---
929480093f4SDimitry Andriclet Extension = FuncExtKhrLocalInt32BaseAtomics in {
930480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
931480093f4SDimitry Andric    foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
932480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
933480093f4SDimitry Andric    }
934480093f4SDimitry Andric    foreach name = ["atom_inc", "atom_dec"] in {
935480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
936480093f4SDimitry Andric    }
937480093f4SDimitry Andric    foreach name = ["atom_cmpxchg"] in {
938480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
939480093f4SDimitry Andric    }
940480093f4SDimitry Andric  }
941480093f4SDimitry Andric}
942480093f4SDimitry Andric// --- Table 9.5 ---
943480093f4SDimitry Andriclet Extension = FuncExtKhrInt64BaseAtomics in {
944480093f4SDimitry Andric  foreach AS = [GlobalAS, LocalAS] in {
945480093f4SDimitry Andric    foreach Type = [Long, ULong] in {
946480093f4SDimitry Andric      foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
947480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
948480093f4SDimitry Andric      }
949480093f4SDimitry Andric      foreach name = ["atom_inc", "atom_dec"] in {
950480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
951480093f4SDimitry Andric      }
952480093f4SDimitry Andric      foreach name = ["atom_cmpxchg"] in {
953480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
954480093f4SDimitry Andric      }
955480093f4SDimitry Andric    }
956480093f4SDimitry Andric  }
957480093f4SDimitry Andric}
958480093f4SDimitry Andric// --- Table 9.2 ---
959480093f4SDimitry Andriclet Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
960480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
961480093f4SDimitry Andric    foreach name = ["atom_min", "atom_max", "atom_and",
962480093f4SDimitry Andric                    "atom_or", "atom_xor"] in {
963480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
964480093f4SDimitry Andric    }
965480093f4SDimitry Andric  }
966480093f4SDimitry Andric}
967480093f4SDimitry Andric// --- Table 9.4 ---
968480093f4SDimitry Andriclet Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
969480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
970480093f4SDimitry Andric    foreach name = ["atom_min", "atom_max", "atom_and",
971480093f4SDimitry Andric                    "atom_or", "atom_xor"] in {
972480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
973480093f4SDimitry Andric    }
974480093f4SDimitry Andric  }
975480093f4SDimitry Andric}
976480093f4SDimitry Andric// --- Table 9.6 ---
977480093f4SDimitry Andriclet Extension = FuncExtKhrInt64ExtendedAtomics in {
978480093f4SDimitry Andric  foreach AS = [GlobalAS, LocalAS] in {
979480093f4SDimitry Andric    foreach Type = [Long, ULong] in {
980480093f4SDimitry Andric      foreach name = ["atom_min", "atom_max", "atom_and",
981480093f4SDimitry Andric                      "atom_or", "atom_xor"] in {
982480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
983480093f4SDimitry Andric      }
984480093f4SDimitry Andric    }
985480093f4SDimitry Andric  }
986480093f4SDimitry Andric}
987480093f4SDimitry Andric// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
988480093f4SDimitry Andricforeach AS = [GlobalAS, LocalAS] in {
989480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
990480093f4SDimitry Andric    foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
991480093f4SDimitry Andric                    "atomic_min", "atomic_max", "atomic_and",
992480093f4SDimitry Andric                    "atomic_or", "atomic_xor"] in {
993480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
994480093f4SDimitry Andric    }
995480093f4SDimitry Andric    foreach name = ["atomic_inc", "atomic_dec"] in {
996480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
997480093f4SDimitry Andric    }
998480093f4SDimitry Andric    foreach name = ["atomic_cmpxchg"] in {
999480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
1000480093f4SDimitry Andric    }
1001480093f4SDimitry Andric  }
10020b57cec5SDimitry Andric}
1003*5ffd83dbSDimitry Andric// OpenCL v2.0 s6.13.11 - Atomic Functions.
1004*5ffd83dbSDimitry Andriclet MinVersion = CL20 in {
1005*5ffd83dbSDimitry Andric  foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
1006*5ffd83dbSDimitry Andric                      [AtomicLong, Long], [AtomicULong, ULong],
1007*5ffd83dbSDimitry Andric                      [AtomicFloat, Float], [AtomicDouble, Double]] in {
1008*5ffd83dbSDimitry Andric    def : Builtin<"atomic_init",
1009*5ffd83dbSDimitry Andric        [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>;
1010*5ffd83dbSDimitry Andric    def : Builtin<"atomic_store",
1011*5ffd83dbSDimitry Andric        [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>;
1012*5ffd83dbSDimitry Andric    def : Builtin<"atomic_load",
1013*5ffd83dbSDimitry Andric        [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>]>;
1014*5ffd83dbSDimitry Andric    def : Builtin<"atomic_exchange",
1015*5ffd83dbSDimitry Andric        [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>;
1016*5ffd83dbSDimitry Andric    foreach Variant = ["weak", "strong"] in {
1017*5ffd83dbSDimitry Andric      def : Builtin<"atomic_compare_exchange_" # Variant,
1018*5ffd83dbSDimitry Andric          [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>,
1019*5ffd83dbSDimitry Andric           PointerType<TypePair[1], GenericAS>, TypePair[1]]>;
1020*5ffd83dbSDimitry Andric    }
1021*5ffd83dbSDimitry Andric  }
1022*5ffd83dbSDimitry Andric
1023*5ffd83dbSDimitry Andric  foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1024*5ffd83dbSDimitry Andric                      [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
1025*5ffd83dbSDimitry Andric                      [AtomicIntPtr, IntPtr, PtrDiff],
1026*5ffd83dbSDimitry Andric                      [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
1027*5ffd83dbSDimitry Andric    foreach ModOp = ["add", "sub"] in {
1028*5ffd83dbSDimitry Andric      def : Builtin<"atomic_fetch_" # ModOp,
1029*5ffd83dbSDimitry Andric          [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>;
1030*5ffd83dbSDimitry Andric    }
1031*5ffd83dbSDimitry Andric  }
1032*5ffd83dbSDimitry Andric  foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1033*5ffd83dbSDimitry Andric                      [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
1034*5ffd83dbSDimitry Andric                      [AtomicIntPtr, IntPtr, IntPtr],
1035*5ffd83dbSDimitry Andric                      [AtomicUIntPtr, UIntPtr, UIntPtr]] in {
1036*5ffd83dbSDimitry Andric    foreach ModOp = ["or", "xor", "and", "min", "max"] in {
1037*5ffd83dbSDimitry Andric      def : Builtin<"atomic_fetch_" # ModOp,
1038*5ffd83dbSDimitry Andric          [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>;
1039*5ffd83dbSDimitry Andric    }
1040*5ffd83dbSDimitry Andric  }
1041*5ffd83dbSDimitry Andric}
10420b57cec5SDimitry Andric
1043480093f4SDimitry Andric//--------------------------------------------------------------------
1044480093f4SDimitry Andric// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
1045480093f4SDimitry Andric// --- Table 19 ---
1046480093f4SDimitry Andricforeach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
1047480093f4SDimitry Andric  foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
1048480093f4SDimitry Andric    def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
1049480093f4SDimitry Andric                              GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1050480093f4SDimitry Andric                              GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
1051480093f4SDimitry Andric                  Attr.Const>;
10520b57cec5SDimitry Andric  }
1053a7dea167SDimitry Andric}
1054480093f4SDimitry Andricforeach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
1055480093f4SDimitry Andric  foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
1056480093f4SDimitry Andric    def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
1057480093f4SDimitry Andric                               GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1058480093f4SDimitry Andric                               GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1059480093f4SDimitry Andric                               GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
1060480093f4SDimitry Andric                  Attr.Const>;
1061480093f4SDimitry Andric  }
1062a7dea167SDimitry Andric}
1063a7dea167SDimitry Andric
1064a7dea167SDimitry Andric//--------------------------------------------------------------------
1065a7dea167SDimitry Andric// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1066a7dea167SDimitry Andric// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1067a7dea167SDimitry Andric// --- Table 22: Image Read Functions with Samplers ---
1068a7dea167SDimitry Andricforeach imgTy = [Image1d] in {
1069a7dea167SDimitry Andric  foreach coordTy = [Int, Float] in {
1070480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1071480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1072480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1073a7dea167SDimitry Andric  }
1074a7dea167SDimitry Andric}
1075a7dea167SDimitry Andricforeach imgTy = [Image2d, Image1dArray] in {
1076a7dea167SDimitry Andric  foreach coordTy = [Int, Float] in {
1077480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1078480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1079480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1080a7dea167SDimitry Andric  }
1081a7dea167SDimitry Andric}
1082a7dea167SDimitry Andricforeach imgTy = [Image3d, Image2dArray] in {
1083a7dea167SDimitry Andric  foreach coordTy = [Int, Float] in {
1084480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1085480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1086480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1087a7dea167SDimitry Andric  }
1088a7dea167SDimitry Andric}
1089a7dea167SDimitry Andricforeach coordTy = [Int, Float] in {
1090480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1091480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1092a7dea167SDimitry Andric}
1093a7dea167SDimitry Andric
1094a7dea167SDimitry Andric// --- Table 23: Sampler-less Read Functions ---
1095a7dea167SDimitry Andricforeach aQual = ["RO", "RW"] in {
1096a7dea167SDimitry Andric  foreach imgTy = [Image2d, Image1dArray] in {
1097480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1098480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1099480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1100a7dea167SDimitry Andric  }
1101a7dea167SDimitry Andric  foreach imgTy = [Image3d, Image2dArray] in {
1102480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1103480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1104480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1105a7dea167SDimitry Andric  }
1106a7dea167SDimitry Andric  foreach imgTy = [Image1d, Image1dBuffer] in {
1107480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1108480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1109480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1110a7dea167SDimitry Andric  }
1111480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1112480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
1113a7dea167SDimitry Andric}
1114a7dea167SDimitry Andric
1115a7dea167SDimitry Andric// --- Table 24: Image Write Functions ---
1116a7dea167SDimitry Andricforeach aQual = ["WO", "RW"] in {
1117a7dea167SDimitry Andric  foreach imgTy = [Image2d] in {
1118a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1119a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1120a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1121a7dea167SDimitry Andric  }
1122a7dea167SDimitry Andric  foreach imgTy = [Image2dArray] in {
1123a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1124a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1125a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1126a7dea167SDimitry Andric  }
1127a7dea167SDimitry Andric  foreach imgTy = [Image1d, Image1dBuffer] in {
1128a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1129a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1130a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1131a7dea167SDimitry Andric  }
1132a7dea167SDimitry Andric  foreach imgTy = [Image1dArray] in {
1133a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1134a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1135a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1136a7dea167SDimitry Andric  }
1137a7dea167SDimitry Andric  foreach imgTy = [Image3d] in {
1138a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1139a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1140a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1141a7dea167SDimitry Andric  }
1142a7dea167SDimitry Andric  def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1143a7dea167SDimitry Andric  def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1144a7dea167SDimitry Andric}
1145a7dea167SDimitry Andric
1146a7dea167SDimitry Andric// --- Table 25: Image Query Functions ---
1147a7dea167SDimitry Andricforeach aQual = ["RO", "WO", "RW"] in {
1148a7dea167SDimitry Andric  foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1149a7dea167SDimitry Andric                   Image1dArray, Image2dArray, Image2dDepth,
1150a7dea167SDimitry Andric                   Image2dArrayDepth] in {
1151a7dea167SDimitry Andric    foreach name = ["get_image_width", "get_image_channel_data_type",
1152a7dea167SDimitry Andric                    "get_image_channel_order"] in {
1153a7dea167SDimitry Andric      def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1154a7dea167SDimitry Andric    }
1155a7dea167SDimitry Andric  }
1156a7dea167SDimitry Andric  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1157a7dea167SDimitry Andric                   Image2dArrayDepth] in {
1158a7dea167SDimitry Andric    def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1159a7dea167SDimitry Andric  }
1160a7dea167SDimitry Andric  def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1161a7dea167SDimitry Andric  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1162a7dea167SDimitry Andric                   Image2dArrayDepth] in {
1163a7dea167SDimitry Andric    def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1164a7dea167SDimitry Andric  }
1165a7dea167SDimitry Andric  def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1166a7dea167SDimitry Andric  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1167a7dea167SDimitry Andric    def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
11680b57cec5SDimitry Andric  }
11690b57cec5SDimitry Andric}
11700b57cec5SDimitry Andric
1171a7dea167SDimitry Andric// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1172a7dea167SDimitry Andric// --- Table 8 ---
1173a7dea167SDimitry Andricforeach aQual = ["RO"] in {
1174a7dea167SDimitry Andric  foreach name = ["read_imageh"] in {
1175a7dea167SDimitry Andric    foreach coordTy = [Int, Float] in {
1176a7dea167SDimitry Andric      foreach imgTy = [Image2d, Image1dArray] in {
1177480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1178a7dea167SDimitry Andric      }
1179a7dea167SDimitry Andric      foreach imgTy = [Image3d, Image2dArray] in {
1180480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1181a7dea167SDimitry Andric      }
1182a7dea167SDimitry Andric      foreach imgTy = [Image1d] in {
1183480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
1184a7dea167SDimitry Andric      }
1185a7dea167SDimitry Andric    }
1186a7dea167SDimitry Andric  }
1187a7dea167SDimitry Andric}
1188a7dea167SDimitry Andric// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1189a7dea167SDimitry Andric// --- Table 9 ---
1190a7dea167SDimitry Andricforeach aQual = ["RO", "RW"] in {
1191a7dea167SDimitry Andric  foreach name = ["read_imageh"] in {
1192a7dea167SDimitry Andric    foreach imgTy = [Image2d, Image1dArray] in {
1193480093f4SDimitry Andric      def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1194a7dea167SDimitry Andric    }
1195a7dea167SDimitry Andric    foreach imgTy = [Image3d, Image2dArray] in {
1196480093f4SDimitry Andric      def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1197a7dea167SDimitry Andric    }
1198a7dea167SDimitry Andric    foreach imgTy = [Image1d, Image1dBuffer] in {
1199480093f4SDimitry Andric      def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1200a7dea167SDimitry Andric    }
1201a7dea167SDimitry Andric  }
1202a7dea167SDimitry Andric}
1203a7dea167SDimitry Andric// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1204a7dea167SDimitry Andric// --- Table 10 ---
1205a7dea167SDimitry Andricforeach aQual = ["WO", "RW"] in {
1206a7dea167SDimitry Andric  foreach name = ["write_imageh"] in {
1207a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1208a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1209a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1210a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1211a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1212a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1213a7dea167SDimitry Andric  }
1214a7dea167SDimitry Andric}
12150b57cec5SDimitry Andric
12160b57cec5SDimitry Andric
1217480093f4SDimitry Andric//--------------------------------------------------------------------
1218480093f4SDimitry Andric// OpenCL v2.0 s6.13.15 - Work-group Functions
1219480093f4SDimitry Andric// --- Table 26 ---
1220480093f4SDimitry Andriclet MinVersion = CL20 in {
1221480093f4SDimitry Andric  foreach name = ["work_group_all", "work_group_any"] in {
1222480093f4SDimitry Andric    def : Builtin<name, [Int, Int], Attr.Convergent>;
1223480093f4SDimitry Andric  }
1224480093f4SDimitry Andric  foreach name = ["work_group_broadcast"] in {
1225480093f4SDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1226480093f4SDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1227480093f4SDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1228480093f4SDimitry Andric  }
1229480093f4SDimitry Andric  foreach op = ["add", "min", "max"] in {
1230480093f4SDimitry Andric    foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1231480093f4SDimitry Andric                    "work_group_scan_inclusive_"] in {
1232480093f4SDimitry Andric      def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1233480093f4SDimitry Andric    }
1234480093f4SDimitry Andric  }
1235480093f4SDimitry Andric}
1236480093f4SDimitry Andric
1237480093f4SDimitry Andric
1238*5ffd83dbSDimitry Andric//--------------------------------------------------------------------
1239*5ffd83dbSDimitry Andric// OpenCL2.0 : 6.13.16 : Pipe Functions
1240*5ffd83dbSDimitry Andric// --- Table 27 ---
1241*5ffd83dbSDimitry Andric// Defined in Builtins.def
1242*5ffd83dbSDimitry Andric
1243*5ffd83dbSDimitry Andric// --- Table 28 ---
1244*5ffd83dbSDimitry Andric// Builtins taking pipe arguments are defined in Builtins.def
1245*5ffd83dbSDimitry Andricdef : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
1246*5ffd83dbSDimitry Andric
1247*5ffd83dbSDimitry Andric// --- Table 29 ---
1248*5ffd83dbSDimitry Andric// Defined in Builtins.def
1249*5ffd83dbSDimitry Andric
1250*5ffd83dbSDimitry Andric
1251*5ffd83dbSDimitry Andric//--------------------------------------------------------------------
1252*5ffd83dbSDimitry Andric// OpenCL2.0 : 6.13.17 : Enqueuing Kernels
1253*5ffd83dbSDimitry Andric// --- Table 30 ---
1254*5ffd83dbSDimitry Andric// Defined in Builtins.def
1255*5ffd83dbSDimitry Andric
1256*5ffd83dbSDimitry Andric// --- Table 32 ---
1257*5ffd83dbSDimitry Andric// Defined in Builtins.def
1258*5ffd83dbSDimitry Andric
1259*5ffd83dbSDimitry Andric// --- Table 33 ---
1260*5ffd83dbSDimitry Andricdef : Builtin<"enqueue_marker",
1261*5ffd83dbSDimitry Andric    [Int, Queue, UInt, PointerType<ConstType<ClkEvent>, GenericAS>, PointerType<ClkEvent, GenericAS>]>;
1262*5ffd83dbSDimitry Andric
1263*5ffd83dbSDimitry Andric// --- Table 34 ---
1264*5ffd83dbSDimitry Andricdef : Builtin<"retain_event", [Void, ClkEvent]>;
1265*5ffd83dbSDimitry Andricdef : Builtin<"release_event", [Void, ClkEvent]>;
1266*5ffd83dbSDimitry Andricdef : Builtin<"create_user_event", [ClkEvent]>;
1267*5ffd83dbSDimitry Andricdef : Builtin<"is_valid_event", [Bool, ClkEvent]>;
1268*5ffd83dbSDimitry Andricdef : Builtin<"set_user_event_status", [Void, ClkEvent, Int]>;
1269*5ffd83dbSDimitry Andric// TODO: capture_event_profiling_info
1270*5ffd83dbSDimitry Andric
1271*5ffd83dbSDimitry Andric// --- Table 35 ---
1272*5ffd83dbSDimitry Andricdef : Builtin<"get_default_queue", [Queue]>;
1273*5ffd83dbSDimitry Andric// TODO: ndrange functions
1274*5ffd83dbSDimitry Andric
1275480093f4SDimitry Andric
1276480093f4SDimitry Andric//--------------------------------------------------------------------
1277480093f4SDimitry Andric// End of the builtin functions defined in the OpenCL C specification.
1278480093f4SDimitry Andric// Builtin functions defined in the OpenCL C Extension are below.
1279480093f4SDimitry Andric//--------------------------------------------------------------------
1280480093f4SDimitry Andric
1281480093f4SDimitry Andric
1282480093f4SDimitry Andric// OpenCL Extension v2.0 s9.18 - Mipmaps
1283480093f4SDimitry Andriclet Extension = FuncExtKhrMipmapImage in {
1284480093f4SDimitry Andric  // Added to section 6.13.14.2.
1285480093f4SDimitry Andric  foreach aQual = ["RO"] in {
1286480093f4SDimitry Andric    foreach imgTy = [Image2d] in {
1287480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1288480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1289480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1290480093f4SDimitry Andric      }
1291480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1292480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1293480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1294480093f4SDimitry Andric      }
1295480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1296480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1297480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1298480093f4SDimitry Andric      }
1299480093f4SDimitry Andric    }
1300480093f4SDimitry Andric    foreach imgTy = [Image2dDepth] in {
1301480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1302480093f4SDimitry Andric        def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1303480093f4SDimitry Andric        def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1304480093f4SDimitry Andric      }
1305480093f4SDimitry Andric    }
1306480093f4SDimitry Andric    foreach imgTy = [Image1d] in {
1307480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1308480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1309480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1310480093f4SDimitry Andric      }
1311480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1312480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1313480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1314480093f4SDimitry Andric      }
1315480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1316480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1317480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1318480093f4SDimitry Andric      }
1319480093f4SDimitry Andric    }
1320480093f4SDimitry Andric    foreach imgTy = [Image3d] in {
1321480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1322480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1323480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1324480093f4SDimitry Andric      }
1325480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1326480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1327480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1328480093f4SDimitry Andric      }
1329480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1330480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1331480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1332480093f4SDimitry Andric      }
1333480093f4SDimitry Andric    }
1334480093f4SDimitry Andric    foreach imgTy = [Image1dArray] in {
1335480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1336480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1337480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1338480093f4SDimitry Andric      }
1339480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1340480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1341480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1342480093f4SDimitry Andric      }
1343480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1344480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1345480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1346480093f4SDimitry Andric      }
1347480093f4SDimitry Andric    }
1348480093f4SDimitry Andric    foreach imgTy = [Image2dArray] in {
1349480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1350480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1351480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1352480093f4SDimitry Andric      }
1353480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1354480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1355480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1356480093f4SDimitry Andric      }
1357480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1358480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1359480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1360480093f4SDimitry Andric      }
1361480093f4SDimitry Andric    }
1362480093f4SDimitry Andric    foreach imgTy = [Image2dArrayDepth] in {
1363480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1364480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1365480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1366480093f4SDimitry Andric      }
1367480093f4SDimitry Andric    }
1368480093f4SDimitry Andric  }
1369*5ffd83dbSDimitry Andric  // Added to section 6.13.14.5
1370*5ffd83dbSDimitry Andric  foreach aQual = ["RO", "WO", "RW"] in {
1371*5ffd83dbSDimitry Andric    foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1372*5ffd83dbSDimitry Andric      def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
1373*5ffd83dbSDimitry Andric    }
1374*5ffd83dbSDimitry Andric  }
1375*5ffd83dbSDimitry Andric}
1376*5ffd83dbSDimitry Andric
1377*5ffd83dbSDimitry Andric// Write functions are enabled using a separate extension.
1378*5ffd83dbSDimitry Andriclet Extension = FuncExtKhrMipmapImageWrites in {
1379480093f4SDimitry Andric  // Added to section 6.13.14.4.
1380480093f4SDimitry Andric  foreach aQual = ["WO"] in {
1381480093f4SDimitry Andric    foreach imgTy = [Image2d] in {
1382480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1383480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1384480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
1385480093f4SDimitry Andric    }
1386480093f4SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
1387480093f4SDimitry Andric    foreach imgTy = [Image1d] in {
1388480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1389480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1390480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
1391480093f4SDimitry Andric    }
1392480093f4SDimitry Andric    foreach imgTy = [Image1dArray] in {
1393480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1394480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1395480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
1396480093f4SDimitry Andric    }
1397480093f4SDimitry Andric    foreach imgTy = [Image2dArray] in {
1398480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1399480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1400480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1401480093f4SDimitry Andric    }
1402480093f4SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
1403*5ffd83dbSDimitry Andric    let Extension = FuncExtKhrMipmapWritesAndWrite3d in {
1404480093f4SDimitry Andric      foreach imgTy = [Image3d] in {
1405480093f4SDimitry Andric        def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1406480093f4SDimitry Andric        def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1407480093f4SDimitry Andric        def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1408480093f4SDimitry Andric      }
1409480093f4SDimitry Andric    }
1410480093f4SDimitry Andric  }
1411480093f4SDimitry Andric}
1412480093f4SDimitry Andric
1413480093f4SDimitry Andric//--------------------------------------------------------------------
1414480093f4SDimitry Andric// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1415480093f4SDimitry Andriclet Extension = FuncExtKhrGlMsaaSharing in {
1416480093f4SDimitry Andric  // --- Table 6.13.14.3 ---
1417480093f4SDimitry Andric  foreach aQual = ["RO", "RW"] in {
1418480093f4SDimitry Andric    foreach imgTy = [Image2dMsaa] in {
1419480093f4SDimitry Andric      def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1420480093f4SDimitry Andric      def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1421480093f4SDimitry Andric      def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1422480093f4SDimitry Andric    }
1423480093f4SDimitry Andric    foreach imgTy = [Image2dArrayMsaa] in {
1424480093f4SDimitry Andric      def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1425480093f4SDimitry Andric      def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1426480093f4SDimitry Andric      def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1427480093f4SDimitry Andric    }
1428480093f4SDimitry Andric    foreach name = ["read_imagef"] in {
1429480093f4SDimitry Andric      def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1430480093f4SDimitry Andric      def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1431480093f4SDimitry Andric    }
1432480093f4SDimitry Andric  }
1433480093f4SDimitry Andric
1434480093f4SDimitry Andric  // --- Table 6.13.14.5 ---
1435480093f4SDimitry Andric  foreach aQual = ["RO", "WO", "RW"] in {
1436480093f4SDimitry Andric    foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1437480093f4SDimitry Andric      foreach name = ["get_image_width", "get_image_height",
1438480093f4SDimitry Andric                      "get_image_channel_data_type", "get_image_channel_order",
1439480093f4SDimitry Andric                      "get_image_num_samples"] in {
1440480093f4SDimitry Andric        def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1441480093f4SDimitry Andric      }
1442480093f4SDimitry Andric      def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1443480093f4SDimitry Andric    }
1444*5ffd83dbSDimitry Andric    foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in {
1445*5ffd83dbSDimitry Andric      def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
1446*5ffd83dbSDimitry Andric    }
1447*5ffd83dbSDimitry Andric  }
1448*5ffd83dbSDimitry Andric}
1449*5ffd83dbSDimitry Andric
1450*5ffd83dbSDimitry Andric//--------------------------------------------------------------------
1451*5ffd83dbSDimitry Andric// OpenCL Extension v2.0 s28 - Subgroups
1452*5ffd83dbSDimitry Andric// --- Table 28.2.1 ---
1453*5ffd83dbSDimitry Andriclet Extension = FuncExtKhrSubgroups in {
1454*5ffd83dbSDimitry Andric  foreach name = ["get_sub_group_size", "get_max_sub_group_size",
1455*5ffd83dbSDimitry Andric                  "get_num_sub_groups", "get_sub_group_id",
1456*5ffd83dbSDimitry Andric                  "get_sub_group_local_id"] in {
1457*5ffd83dbSDimitry Andric    def : Builtin<name, [UInt]>;
1458*5ffd83dbSDimitry Andric  }
1459*5ffd83dbSDimitry Andric  let MinVersion = CL20 in {
1460*5ffd83dbSDimitry Andric    foreach name = ["get_enqueued_num_sub_groups"] in {
1461*5ffd83dbSDimitry Andric      def : Builtin<name, [UInt]>;
1462*5ffd83dbSDimitry Andric    }
1463*5ffd83dbSDimitry Andric  }
1464*5ffd83dbSDimitry Andric}
1465*5ffd83dbSDimitry Andric
1466*5ffd83dbSDimitry Andric// --- Table 28.2.2 ---
1467*5ffd83dbSDimitry Andric// TODO: sub_group_barrier
1468*5ffd83dbSDimitry Andric
1469*5ffd83dbSDimitry Andric// --- Table 28.2.4 ---
1470*5ffd83dbSDimitry Andriclet Extension = FuncExtKhrSubgroups in {
1471*5ffd83dbSDimitry Andric  foreach name = ["sub_group_all", "sub_group_any"] in {
1472*5ffd83dbSDimitry Andric    def : Builtin<name, [Int, Int], Attr.Convergent>;
1473*5ffd83dbSDimitry Andric  }
1474*5ffd83dbSDimitry Andric  foreach name = ["sub_group_broadcast"] in {
1475*5ffd83dbSDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, UInt], Attr.Convergent>;
1476*5ffd83dbSDimitry Andric  }
1477*5ffd83dbSDimitry Andric  foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
1478*5ffd83dbSDimitry Andric                  "sub_group_scan_inclusive_"] in {
1479*5ffd83dbSDimitry Andric    foreach op = ["add", "min", "max"] in {
1480*5ffd83dbSDimitry Andric      def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1481*5ffd83dbSDimitry Andric    }
1482*5ffd83dbSDimitry Andric  }
1483*5ffd83dbSDimitry Andric}
1484*5ffd83dbSDimitry Andric
1485*5ffd83dbSDimitry Andric//--------------------------------------------------------------------
1486*5ffd83dbSDimitry Andric// Arm extensions.
1487*5ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductInt8 in {
1488*5ffd83dbSDimitry Andric  foreach name = ["arm_dot"] in {
1489*5ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>;
1490*5ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>]>;
1491*5ffd83dbSDimitry Andric  }
1492*5ffd83dbSDimitry Andric}
1493*5ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductAccumulateInt8 in {
1494*5ffd83dbSDimitry Andric  foreach name = ["arm_dot_acc"] in {
1495*5ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
1496*5ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1497*5ffd83dbSDimitry Andric  }
1498*5ffd83dbSDimitry Andric}
1499*5ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductAccumulateInt16 in {
1500*5ffd83dbSDimitry Andric  foreach name = ["arm_dot_acc"] in {
1501*5ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UShort, 2>, VectorType<UShort, 2>, UInt]>;
1502*5ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Short, 2>, VectorType<Short, 2>, Int]>;
1503*5ffd83dbSDimitry Andric  }
1504*5ffd83dbSDimitry Andric}
1505*5ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductAccumulateSaturateInt8 in {
1506*5ffd83dbSDimitry Andric  foreach name = ["arm_dot_acc_sat"] in {
1507*5ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
1508*5ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1509480093f4SDimitry Andric  }
1510480093f4SDimitry Andric}
1511