xref: /freebsd/contrib/llvm-project/clang/lib/Sema/OpenCLBuiltins.td (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
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
53fe6060f1SDimitry Andric// Extension associated to a type.  This enables implicit conditionalization of
54fe6060f1SDimitry Andric// builtin function overloads containing a type that depends on an extension.
55fe6060f1SDimitry Andric// During overload resolution, when a builtin function overload contains a type
56fe6060f1SDimitry Andric// with a TypeExtension, those overloads are skipped when the extension is
57fe6060f1SDimitry Andric// disabled.
58fe6060f1SDimitry Andricclass TypeExtension<string _Ext> : AbstractExtension<_Ext>;
59fe6060f1SDimitry Andric
60d56accc7SDimitry Andric// Concatenate zero or more space-separated extensions in NewExts to Base and
61d56accc7SDimitry Andric// return the resulting FunctionExtension in ret.
62d56accc7SDimitry Andricclass concatExtension<FunctionExtension Base, string NewExts> {
63d56accc7SDimitry Andric  FunctionExtension ret = FunctionExtension<
64d56accc7SDimitry Andric    !cond(
65d56accc7SDimitry Andric      // Return Base extension if NewExts is empty,
66d56accc7SDimitry Andric      !empty(NewExts) : Base.ExtName,
67d56accc7SDimitry Andric
68d56accc7SDimitry Andric      // otherwise, return NewExts if Base extension is empty,
69d56accc7SDimitry Andric      !empty(Base.ExtName) : NewExts,
70d56accc7SDimitry Andric
71d56accc7SDimitry Andric      // otherwise, concatenate NewExts to Base.
72d56accc7SDimitry Andric      true : Base.ExtName # " " # NewExts
73d56accc7SDimitry Andric    )
74d56accc7SDimitry Andric  >;
75d56accc7SDimitry Andric}
76d56accc7SDimitry Andric
77fe6060f1SDimitry Andric// TypeExtension definitions.
78fe6060f1SDimitry Andricdef NoTypeExt   : TypeExtension<"">;
79fe6060f1SDimitry Andricdef Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
80fe6060f1SDimitry Andricdef Fp64TypeExt : TypeExtension<"cl_khr_fp64">;
8181ad6265SDimitry Andricdef Atomic64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics">;
8281ad6265SDimitry Andricdef AtomicFp64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp64">;
83fe6060f1SDimitry Andric
84480093f4SDimitry Andric// FunctionExtension definitions.
85480093f4SDimitry Andricdef FuncExtNone                          : FunctionExtension<"">;
8681ad6265SDimitry Andricdef FuncExtKhrSubgroups                  : FunctionExtension<"__opencl_subgroup_builtins">;
87fe6060f1SDimitry Andricdef FuncExtKhrSubgroupExtendedTypes      : FunctionExtension<"cl_khr_subgroup_extended_types">;
88fe6060f1SDimitry Andricdef FuncExtKhrSubgroupNonUniformVote     : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
89fe6060f1SDimitry Andricdef FuncExtKhrSubgroupBallot             : FunctionExtension<"cl_khr_subgroup_ballot">;
90fe6060f1SDimitry Andricdef FuncExtKhrSubgroupNonUniformArithmetic: FunctionExtension<"cl_khr_subgroup_non_uniform_arithmetic">;
91fe6060f1SDimitry Andricdef FuncExtKhrSubgroupShuffle            : FunctionExtension<"cl_khr_subgroup_shuffle">;
92fe6060f1SDimitry Andricdef FuncExtKhrSubgroupShuffleRelative    : FunctionExtension<"cl_khr_subgroup_shuffle_relative">;
93fe6060f1SDimitry Andricdef FuncExtKhrSubgroupClusteredReduce    : FunctionExtension<"cl_khr_subgroup_clustered_reduce">;
94fe6060f1SDimitry Andricdef FuncExtKhrExtendedBitOps             : FunctionExtension<"cl_khr_extended_bit_ops">;
95480093f4SDimitry Andricdef FuncExtKhrGlobalInt32BaseAtomics     : FunctionExtension<"cl_khr_global_int32_base_atomics">;
96480093f4SDimitry Andricdef FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
97480093f4SDimitry Andricdef FuncExtKhrLocalInt32BaseAtomics      : FunctionExtension<"cl_khr_local_int32_base_atomics">;
98480093f4SDimitry Andricdef FuncExtKhrLocalInt32ExtendedAtomics  : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
99480093f4SDimitry Andricdef FuncExtKhrInt64BaseAtomics           : FunctionExtension<"cl_khr_int64_base_atomics">;
100480093f4SDimitry Andricdef FuncExtKhrInt64ExtendedAtomics       : FunctionExtension<"cl_khr_int64_extended_atomics">;
101480093f4SDimitry Andricdef FuncExtKhrMipmapImage                : FunctionExtension<"cl_khr_mipmap_image">;
1025ffd83dbSDimitry Andricdef FuncExtKhrMipmapImageWrites          : FunctionExtension<"cl_khr_mipmap_image_writes">;
103480093f4SDimitry Andricdef FuncExtKhrGlMsaaSharing              : FunctionExtension<"cl_khr_gl_msaa_sharing">;
104480093f4SDimitry Andric
10581ad6265SDimitry Andricdef FuncExtOpenCLCDeviceEnqueue          : FunctionExtension<"__opencl_c_device_enqueue">;
1061fd87a68SDimitry Andricdef FuncExtOpenCLCGenericAddressSpace    : FunctionExtension<"__opencl_c_generic_address_space">;
1071fd87a68SDimitry Andricdef FuncExtOpenCLCNamedAddressSpaceBuiltins : FunctionExtension<"__opencl_c_named_address_space_builtins">;
108349cc55cSDimitry Andricdef FuncExtOpenCLCPipes                  : FunctionExtension<"__opencl_c_pipes">;
109349cc55cSDimitry Andricdef FuncExtOpenCLCWGCollectiveFunctions  : FunctionExtension<"__opencl_c_work_group_collective_functions">;
11004eeddc0SDimitry Andricdef FuncExtOpenCLCReadWriteImages        : FunctionExtension<"__opencl_c_read_write_images">;
111d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16GlobalASLoadStore  : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store">;
112d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16LocalASLoadStore   : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_load_store">;
113d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16GenericASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store __opencl_c_ext_fp16_local_atomic_load_store">;
114d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16GlobalASAdd        : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_add">;
115d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp32GlobalASAdd        : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_add">;
116d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp64GlobalASAdd        : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_add">;
117d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16LocalASAdd         : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add">;
118d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp32LocalASAdd         : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add">;
119d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp64LocalASAdd         : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add">;
120d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16GenericASAdd       : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add __opencl_c_ext_fp16_global_atomic_add">;
121d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp32GenericASAdd       : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add __opencl_c_ext_fp32_global_atomic_add">;
122d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp64GenericASAdd       : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add __opencl_c_ext_fp64_global_atomic_add">;
123d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16GlobalASMinMax     : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_min_max">;
124d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp32GlobalASMinMax     : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_min_max">;
125d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp64GlobalASMinMax     : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_min_max">;
126d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16LocalASMinMax      : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_min_max">;
127d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp32LocalASMinMax      : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_min_max">;
128d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp64LocalASMinMax      : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_min_max">;
129d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp16GenericASMinMax    : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_min_max __opencl_c_ext_fp16_global_atomic_min_max">;
130d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp32GenericASMinMax    : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_min_max __opencl_c_ext_fp32_global_atomic_min_max">;
131d56accc7SDimitry Andricdef FuncExtFloatAtomicsFp64GenericASMinMax    : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_min_max __opencl_c_ext_fp64_global_atomic_min_max">;
132349cc55cSDimitry Andric
133fe6060f1SDimitry Andric// Not a real extension, but a workaround to add C++ for OpenCL specific builtins.
134fe6060f1SDimitry Andricdef FuncExtOpenCLCxx                     : FunctionExtension<"__cplusplus">;
135fe6060f1SDimitry Andric
1365ffd83dbSDimitry Andric// Arm extensions.
1375ffd83dbSDimitry Andricdef ArmIntegerDotProductInt8                   : FunctionExtension<"cl_arm_integer_dot_product_int8">;
1385ffd83dbSDimitry Andricdef ArmIntegerDotProductAccumulateInt8         : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
1395ffd83dbSDimitry Andricdef ArmIntegerDotProductAccumulateInt16        : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">;
1405ffd83dbSDimitry Andricdef ArmIntegerDotProductAccumulateSaturateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_saturate_int8">;
1410b57cec5SDimitry Andric
142a7dea167SDimitry Andric// Qualified Type.  These map to ASTContext::QualType.
143fe6060f1SDimitry Andricclass QualType<string _TypeExpr, bit _IsAbstract=0> {
144fe6060f1SDimitry Andric  // Expression to obtain the QualType inside OCL2Qual.
145fe6060f1SDimitry Andric  // E.g. TypeExpr="Context.IntTy" for the int type.
146fe6060f1SDimitry Andric  string TypeExpr = _TypeExpr;
147a7dea167SDimitry Andric  // Some QualTypes in this file represent an abstract type for which there is
148a7dea167SDimitry Andric  // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
149a7dea167SDimitry Andric  // without access qualifiers.
150a7dea167SDimitry Andric  bit IsAbstract = _IsAbstract;
1510b57cec5SDimitry Andric}
1520b57cec5SDimitry Andric
153a7dea167SDimitry Andric// List of integers.
154a7dea167SDimitry Andricclass IntList<string _Name, list<int> _List> {
155a7dea167SDimitry Andric  string Name = _Name;
156a7dea167SDimitry Andric  list<int> List = _List;
1570b57cec5SDimitry Andric}
1580b57cec5SDimitry Andric
1590b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
1600b57cec5SDimitry Andric//                      OpenCL C classes for types
1610b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
162a7dea167SDimitry Andric// OpenCL C basic data types (int, float, image2d_t, ...).
163a7dea167SDimitry Andric// Its child classes can represent concrete types (e.g. VectorType) or
164a7dea167SDimitry Andric// abstract types (e.g. GenType).
165fe6060f1SDimitry Andricclass Type<string _Name, QualType _QTExpr> {
166a7dea167SDimitry Andric  // Name of the Type.
1670b57cec5SDimitry Andric  string Name = _Name;
168a7dea167SDimitry Andric  // QualType associated with this type.
169fe6060f1SDimitry Andric  QualType QTExpr = _QTExpr;
170a7dea167SDimitry Andric  // Size of the vector (if applicable).
171a7dea167SDimitry Andric  int VecWidth = 1;
172a7dea167SDimitry Andric  // Is a pointer.
1730b57cec5SDimitry Andric  bit IsPointer = 0;
174a7dea167SDimitry Andric  // "const" qualifier.
175a7dea167SDimitry Andric  bit IsConst = 0;
176a7dea167SDimitry Andric  // "volatile" qualifier.
177a7dea167SDimitry Andric  bit IsVolatile = 0;
1780b57cec5SDimitry Andric  // Access qualifier. Must be one of ("RO", "WO", "RW").
1790b57cec5SDimitry Andric  string AccessQualifier = "";
180a7dea167SDimitry Andric  // Address space.
181a7dea167SDimitry Andric  string AddrSpace = DefaultAS.Name;
182fe6060f1SDimitry Andric  // Extension that needs to be enabled to expose a builtin that uses this type.
183fe6060f1SDimitry Andric  TypeExtension Extension = NoTypeExt;
1840b57cec5SDimitry Andric}
1850b57cec5SDimitry Andric
186a7dea167SDimitry Andric// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
187fe6060f1SDimitry Andricclass VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTExpr> {
188a7dea167SDimitry Andric  let VecWidth = _VecWidth;
189a7dea167SDimitry Andric  let AccessQualifier = "";
190a7dea167SDimitry Andric  // Inherited fields
191a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
192a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
193a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
194a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
195fe6060f1SDimitry Andric  let Extension = _Ty.Extension;
1960b57cec5SDimitry Andric}
1970b57cec5SDimitry Andric
198a7dea167SDimitry Andric// OpenCL pointer types (e.g. int*, float*, ...).
199a7dea167SDimitry Andricclass PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
200fe6060f1SDimitry Andric    Type<_Ty.Name, _Ty.QTExpr> {
201a7dea167SDimitry Andric  let AddrSpace = _AS.Name;
202a7dea167SDimitry Andric  // Inherited fields
203a7dea167SDimitry Andric  let VecWidth = _Ty.VecWidth;
204a7dea167SDimitry Andric  let IsPointer = 1;
205a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
206a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
207a7dea167SDimitry Andric  let AccessQualifier = _Ty.AccessQualifier;
208fe6060f1SDimitry Andric  let Extension = _Ty.Extension;
2090b57cec5SDimitry Andric}
2100b57cec5SDimitry Andric
211a7dea167SDimitry Andric// OpenCL const types (e.g. const int).
212fe6060f1SDimitry Andricclass ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTExpr> {
213a7dea167SDimitry Andric  let IsConst = 1;
214a7dea167SDimitry Andric  // Inherited fields
215a7dea167SDimitry Andric  let VecWidth = _Ty.VecWidth;
216a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
217a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
218a7dea167SDimitry Andric  let AccessQualifier = _Ty.AccessQualifier;
219a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
220fe6060f1SDimitry Andric  let Extension = _Ty.Extension;
221a7dea167SDimitry Andric}
222a7dea167SDimitry Andric
223a7dea167SDimitry Andric// OpenCL volatile types (e.g. volatile int).
224fe6060f1SDimitry Andricclass VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTExpr> {
225a7dea167SDimitry Andric  let IsVolatile = 1;
226a7dea167SDimitry Andric  // Inherited fields
227a7dea167SDimitry Andric  let VecWidth = _Ty.VecWidth;
228a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
229a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
230a7dea167SDimitry Andric  let AccessQualifier = _Ty.AccessQualifier;
231a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
232fe6060f1SDimitry Andric  let Extension = _Ty.Extension;
233a7dea167SDimitry Andric}
234a7dea167SDimitry Andric
235a7dea167SDimitry Andric// OpenCL image types (e.g. image2d).
236a7dea167SDimitry Andricclass ImageType<Type _Ty, string _AccessQualifier> :
237fe6060f1SDimitry Andric    Type<_Ty.Name, QualType<_Ty.QTExpr.TypeExpr # _AccessQualifier # "Ty", 0>> {
238a7dea167SDimitry Andric  let VecWidth = 0;
2390b57cec5SDimitry Andric  let AccessQualifier = _AccessQualifier;
240a7dea167SDimitry Andric  // Inherited fields
241a7dea167SDimitry Andric  let IsPointer = _Ty.IsPointer;
242a7dea167SDimitry Andric  let IsConst = _Ty.IsConst;
243a7dea167SDimitry Andric  let IsVolatile = _Ty.IsVolatile;
244a7dea167SDimitry Andric  let AddrSpace = _Ty.AddrSpace;
24581ad6265SDimitry Andric  // Add TypeExtensions for writable "image3d_t" and "read_write" image types.
24681ad6265SDimitry Andric  let Extension = !cond(
24781ad6265SDimitry Andric      !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : TypeExtension<"cl_khr_3d_image_writes">,
24881ad6265SDimitry Andric      !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "RW")) : TypeExtension<"cl_khr_3d_image_writes __opencl_c_read_write_images">,
249bdd1243dSDimitry Andric      !or(!eq(_Ty.Name, "image2d_depth_t"), !eq(_Ty.Name, "image2d_array_depth_t")) : TypeExtension<"cl_khr_depth_images">,
25081ad6265SDimitry Andric      !eq(_AccessQualifier, "RW") : TypeExtension<"__opencl_c_read_write_images">,
25181ad6265SDimitry Andric      true : _Ty.Extension);
252fe6060f1SDimitry Andric}
253fe6060f1SDimitry Andric
254fe6060f1SDimitry Andric// OpenCL enum type (e.g. memory_scope).
255fe6060f1SDimitry Andricclass EnumType<string _Name> :
256fe6060f1SDimitry Andric    Type<_Name, QualType<"getOpenCLEnumType(S, \"" # _Name # "\")", 0>> {
257fe6060f1SDimitry Andric}
258fe6060f1SDimitry Andric
259fe6060f1SDimitry Andric// OpenCL typedef type (e.g. cl_mem_fence_flags).
260fe6060f1SDimitry Andricclass TypedefType<string _Name> :
261fe6060f1SDimitry Andric    Type<_Name, QualType<"getOpenCLTypedefType(S, \"" # _Name # "\")", 0>> {
262a7dea167SDimitry Andric}
263a7dea167SDimitry Andric
264a7dea167SDimitry Andric// List of Types.
2655ffd83dbSDimitry Andricclass TypeList<list<Type> _Type> {
266a7dea167SDimitry Andric  list<Type> List = _Type;
267a7dea167SDimitry Andric}
268a7dea167SDimitry Andric
269a7dea167SDimitry Andric// A GenericType is an abstract type that defines a set of types as a
270a7dea167SDimitry Andric// combination of Types and vector sizes.
271a7dea167SDimitry Andric//
272a7dea167SDimitry Andric// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
273a7dea167SDimitry Andric// represents <int, int2, int4, float, float2, float4>.
274a7dea167SDimitry Andric//
275a7dea167SDimitry Andric// Some rules apply when using multiple GenericType arguments in a declaration:
276a7dea167SDimitry Andric//   1. The number of vector sizes must be equal or 1 for all gentypes in a
277a7dea167SDimitry Andric//      declaration.
278a7dea167SDimitry Andric//   2. The number of Types must be equal or 1 for all gentypes in a
279a7dea167SDimitry Andric//      declaration.
280a7dea167SDimitry Andric//   3. Generic types are combined by iterating over all generic types at once.
281a7dea167SDimitry Andric//      For example, for the following GenericTypes
282a7dea167SDimitry Andric//        GenT1 = GenericType<half, [1, 2]> and
283a7dea167SDimitry Andric//        GenT2 = GenericType<float, int, [1, 2]>
284a7dea167SDimitry Andric//      A declaration f(GenT1, GenT2) results in the combinations
285a7dea167SDimitry Andric//        f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
286a7dea167SDimitry Andric//   4. "sgentype" from the OpenCL specification is supported by specifying
287a7dea167SDimitry Andric//      a single vector size.
288a7dea167SDimitry Andric//      For example, for the following GenericTypes
289a7dea167SDimitry Andric//        GenT = GenericType<half, int, [1, 2]> and
290a7dea167SDimitry Andric//        SGenT = GenericType<half, int, [1]>
291a7dea167SDimitry Andric//      A declaration f(GenT, SGenT) results in the combinations
292a7dea167SDimitry Andric//        f(half, half), f(half2, half), f(int, int), f(int2, int) .
293a7dea167SDimitry Andricclass GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
294a7dea167SDimitry Andric    Type<_Ty, QualType<"null", 1>> {
295a7dea167SDimitry Andric  // Possible element types of the generic type.
296a7dea167SDimitry Andric  TypeList TypeList = _TypeList;
297a7dea167SDimitry Andric  // Possible vector sizes of the types in the TypeList.
298a7dea167SDimitry Andric  IntList VectorList = _VectorList;
299a7dea167SDimitry Andric  // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
300a7dea167SDimitry Andric  let VecWidth = 0;
3010b57cec5SDimitry Andric}
3020b57cec5SDimitry Andric
303480093f4SDimitry Andric// Builtin function attributes.
304480093f4SDimitry Andricdef Attr {
305480093f4SDimitry Andric  list<bit> None = [0, 0, 0];
306480093f4SDimitry Andric  list<bit> Pure = [1, 0, 0];
307480093f4SDimitry Andric  list<bit> Const = [0, 1, 0];
308480093f4SDimitry Andric  list<bit> Convergent = [0, 0, 1];
309480093f4SDimitry Andric}
310480093f4SDimitry Andric
3110b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
3120b57cec5SDimitry Andric//                      OpenCL C class for builtin functions
3130b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
314480093f4SDimitry Andricclass Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
3150b57cec5SDimitry Andric  // Name of the builtin function
3160b57cec5SDimitry Andric  string Name = _Name;
3170b57cec5SDimitry Andric  // List of types used by the function. The first one is the return type and
3180b57cec5SDimitry Andric  // the following are the arguments. The list must have at least one element
3190b57cec5SDimitry Andric  // (the return type).
3200b57cec5SDimitry Andric  list<Type> Signature = _Signature;
321480093f4SDimitry Andric  // Function attribute __attribute__((pure))
322480093f4SDimitry Andric  bit IsPure = _Attributes[0];
323480093f4SDimitry Andric  // Function attribute __attribute__((const))
324480093f4SDimitry Andric  bit IsConst = _Attributes[1];
325480093f4SDimitry Andric  // Function attribute __attribute__((convergent))
326480093f4SDimitry Andric  bit IsConv = _Attributes[2];
327480093f4SDimitry Andric  // OpenCL extensions to which the function belongs.
328480093f4SDimitry Andric  FunctionExtension Extension = FuncExtNone;
329a7dea167SDimitry Andric  // Version of OpenCL from which the function is available (e.g.: CL10).
330a7dea167SDimitry Andric  // MinVersion is inclusive.
331a7dea167SDimitry Andric  Version MinVersion = CL10;
332a7dea167SDimitry Andric  // Version of OpenCL from which the function is not supported anymore.
333a7dea167SDimitry Andric  // MaxVersion is exclusive.
334a7dea167SDimitry Andric  // CLAll makes the function available for all versions.
335a7dea167SDimitry Andric  Version MaxVersion = CLAll;
3360b57cec5SDimitry Andric}
3370b57cec5SDimitry Andric
3380b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
3390b57cec5SDimitry Andric//                 Definitions of OpenCL C types
3400b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
3410b57cec5SDimitry Andric
342a7dea167SDimitry Andric// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
343fe6060f1SDimitry Andricdef Bool      : Type<"bool",      QualType<"Context.BoolTy">>;
344fe6060f1SDimitry Andricdef Char      : Type<"char",      QualType<"Context.CharTy">>;
345fe6060f1SDimitry Andricdef UChar     : Type<"uchar",     QualType<"Context.UnsignedCharTy">>;
346fe6060f1SDimitry Andricdef Short     : Type<"short",     QualType<"Context.ShortTy">>;
347fe6060f1SDimitry Andricdef UShort    : Type<"ushort",    QualType<"Context.UnsignedShortTy">>;
348fe6060f1SDimitry Andricdef Int       : Type<"int",       QualType<"Context.IntTy">>;
349fe6060f1SDimitry Andricdef UInt      : Type<"uint",      QualType<"Context.UnsignedIntTy">>;
350fe6060f1SDimitry Andricdef Long      : Type<"long",      QualType<"Context.LongTy">>;
351fe6060f1SDimitry Andricdef ULong     : Type<"ulong",     QualType<"Context.UnsignedLongTy">>;
352fe6060f1SDimitry Andricdef Float     : Type<"float",     QualType<"Context.FloatTy">>;
353fe6060f1SDimitry Andriclet Extension = Fp64TypeExt in {
354fe6060f1SDimitry Andric  def Double    : Type<"double",    QualType<"Context.DoubleTy">>;
355fe6060f1SDimitry Andric}
35681ad6265SDimitry Andric
35781ad6265SDimitry Andric// The half type for builtins that require the cl_khr_fp16 extension.
358fe6060f1SDimitry Andriclet Extension = Fp16TypeExt in {
359fe6060f1SDimitry Andric  def Half      : Type<"half",      QualType<"Context.HalfTy">>;
360fe6060f1SDimitry Andric}
36181ad6265SDimitry Andric
36281ad6265SDimitry Andric// Without the cl_khr_fp16 extension, the half type can only be used to declare
36381ad6265SDimitry Andric// a pointer.  Define const and non-const pointer types in all address spaces.
36481ad6265SDimitry Andric// Use the "__half" alias to allow the TableGen emitter to distinguish the
36581ad6265SDimitry Andric// (extensionless) pointee type of these pointer-to-half types from the "half"
36681ad6265SDimitry Andric// type defined above that already carries the cl_khr_fp16 extension.
36781ad6265SDimitry Andricforeach AS = [PrivateAS, GlobalAS, ConstantAS, LocalAS, GenericAS] in {
36881ad6265SDimitry Andric  def "HalfPtr" # AS      : PointerType<Type<"__half", QualType<"Context.HalfTy">>, AS>;
36981ad6265SDimitry Andric  def "HalfPtrConst" # AS : PointerType<ConstType<Type<"__half", QualType<"Context.HalfTy">>>, AS>;
37081ad6265SDimitry Andric}
37181ad6265SDimitry Andric
372fe6060f1SDimitry Andricdef Size      : Type<"size_t",    QualType<"Context.getSizeType()">>;
373fe6060f1SDimitry Andricdef PtrDiff   : Type<"ptrdiff_t", QualType<"Context.getPointerDiffType()">>;
374fe6060f1SDimitry Andricdef IntPtr    : Type<"intptr_t",  QualType<"Context.getIntPtrType()">>;
375fe6060f1SDimitry Andricdef UIntPtr   : Type<"uintptr_t", QualType<"Context.getUIntPtrType()">>;
376fe6060f1SDimitry Andricdef Void      : Type<"void",      QualType<"Context.VoidTy">>;
377a7dea167SDimitry Andric
378a7dea167SDimitry Andric// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
379a7dea167SDimitry Andric// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
380a7dea167SDimitry Andric
381a7dea167SDimitry Andric// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
382a7dea167SDimitry Andric// The image definitions are "abstract".  They should not be used without
383a7dea167SDimitry Andric// specifying an access qualifier (RO/WO/RW).
384fe6060f1SDimitry Andricdef Image1d               : Type<"image1d_t", QualType<"Context.OCLImage1d", 1>>;
385fe6060f1SDimitry Andricdef Image2d               : Type<"image2d_t", QualType<"Context.OCLImage2d", 1>>;
386fe6060f1SDimitry Andricdef Image3d               : Type<"image3d_t", QualType<"Context.OCLImage3d", 1>>;
387fe6060f1SDimitry Andricdef Image1dArray          : Type<"image1d_array_t", QualType<"Context.OCLImage1dArray", 1>>;
388fe6060f1SDimitry Andricdef Image1dBuffer         : Type<"image1d_buffer_t", QualType<"Context.OCLImage1dBuffer", 1>>;
389fe6060f1SDimitry Andricdef Image2dArray          : Type<"image2d_array_t", QualType<"Context.OCLImage2dArray", 1>>;
390fe6060f1SDimitry Andricdef Image2dDepth          : Type<"image2d_depth_t", QualType<"Context.OCLImage2dDepth", 1>>;
391fe6060f1SDimitry Andricdef Image2dArrayDepth     : Type<"image2d_array_depth_t", QualType<"Context.OCLImage2dArrayDepth", 1>>;
392fe6060f1SDimitry Andricdef Image2dMsaa           : Type<"image2d_msaa_t", QualType<"Context.OCLImage2dMSAA", 1>>;
393fe6060f1SDimitry Andricdef Image2dArrayMsaa      : Type<"image2d_array_msaa_t", QualType<"Context.OCLImage2dArrayMSAA", 1>>;
394fe6060f1SDimitry Andricdef Image2dMsaaDepth      : Type<"image2d_msaa_depth_t", QualType<"Context.OCLImage2dMSAADepth", 1>>;
395fe6060f1SDimitry Andricdef Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"Context.OCLImage2dArrayMSAADepth", 1>>;
396a7dea167SDimitry Andric
397fe6060f1SDimitry Andricdef Sampler               : Type<"sampler_t", QualType<"Context.OCLSamplerTy">>;
398fe6060f1SDimitry Andricdef ClkEvent              : Type<"clk_event_t", QualType<"Context.OCLClkEventTy">>;
399fe6060f1SDimitry Andricdef Event                 : Type<"event_t", QualType<"Context.OCLEventTy">>;
400fe6060f1SDimitry Andricdef Queue                 : Type<"queue_t", QualType<"Context.OCLQueueTy">>;
401fe6060f1SDimitry Andricdef ReserveId             : Type<"reserve_id_t", QualType<"Context.OCLReserveIDTy">>;
402fe6060f1SDimitry Andricdef MemFenceFlags         : TypedefType<"cl_mem_fence_flags">;
403fe6060f1SDimitry Andricdef ClkProfilingInfo      : TypedefType<"clk_profiling_info">;
404fe6060f1SDimitry Andricdef NDRange               : TypedefType<"ndrange_t">;
4055ffd83dbSDimitry Andric
4065ffd83dbSDimitry Andric// OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
407fe6060f1SDimitry Andricdef AtomicInt             : Type<"atomic_int", QualType<"Context.getAtomicType(Context.IntTy)">>;
408fe6060f1SDimitry Andricdef AtomicUInt            : Type<"atomic_uint", QualType<"Context.getAtomicType(Context.UnsignedIntTy)">>;
40981ad6265SDimitry Andriclet Extension = Atomic64TypeExt in {
410fe6060f1SDimitry Andric  def AtomicLong            : Type<"atomic_long", QualType<"Context.getAtomicType(Context.LongTy)">>;
411fe6060f1SDimitry Andric  def AtomicULong           : Type<"atomic_ulong", QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>;
41281ad6265SDimitry Andric}
413fe6060f1SDimitry Andricdef AtomicFloat           : Type<"atomic_float", QualType<"Context.getAtomicType(Context.FloatTy)">>;
41481ad6265SDimitry Andriclet Extension = AtomicFp64TypeExt in {
415fe6060f1SDimitry Andric  def AtomicDouble          : Type<"atomic_double", QualType<"Context.getAtomicType(Context.DoubleTy)">>;
41681ad6265SDimitry Andric}
417349cc55cSDimitry Andricdef AtomicHalf            : Type<"atomic_half", QualType<"Context.getAtomicType(Context.HalfTy)">>;
418fe6060f1SDimitry Andricdef AtomicIntPtr          : Type<"atomic_intptr_t", QualType<"Context.getAtomicType(Context.getIntPtrType())">>;
419fe6060f1SDimitry Andricdef AtomicUIntPtr         : Type<"atomic_uintptr_t", QualType<"Context.getAtomicType(Context.getUIntPtrType())">>;
420fe6060f1SDimitry Andricdef AtomicSize            : Type<"atomic_size_t", QualType<"Context.getAtomicType(Context.getSizeType())">>;
421fe6060f1SDimitry Andricdef AtomicPtrDiff         : Type<"atomic_ptrdiff_t", QualType<"Context.getAtomicType(Context.getPointerDiffType())">>;
422fe6060f1SDimitry Andric
423fe6060f1SDimitry Andricdef AtomicFlag            : TypedefType<"atomic_flag">;
424fe6060f1SDimitry Andricdef MemoryOrder           : EnumType<"memory_order">;
425fe6060f1SDimitry Andricdef MemoryScope           : EnumType<"memory_scope">;
426a7dea167SDimitry Andric
427a7dea167SDimitry Andric//===----------------------------------------------------------------------===//
428a7dea167SDimitry Andric//                 Definitions of OpenCL gentype variants
429a7dea167SDimitry Andric//===----------------------------------------------------------------------===//
430a7dea167SDimitry Andric// The OpenCL specification often uses "gentype" in builtin function
431a7dea167SDimitry Andric// declarations to indicate that a builtin function is available with various
432a7dea167SDimitry Andric// argument and return types.  The types represented by "gentype" vary between
433a7dea167SDimitry Andric// different parts of the specification.  The following definitions capture
434a7dea167SDimitry Andric// the different type lists for gentypes in different parts of the
435a7dea167SDimitry Andric// specification.
436a7dea167SDimitry Andric
437a7dea167SDimitry Andric// Vector width lists.
438a7dea167SDimitry Andricdef VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
439a7dea167SDimitry Andricdef VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
440a7dea167SDimitry Andricdef Vec1        : IntList<"Vec1", [1]>;
441480093f4SDimitry Andricdef Vec1234     : IntList<"Vec1234", [1, 2, 3, 4]>;
442a7dea167SDimitry Andric
443a7dea167SDimitry Andric// Type lists.
4445ffd83dbSDimitry Andricdef TLAll           : TypeList<[Char,  UChar, Short,  UShort, Int,  UInt, Long,  ULong, Float, Double, Half]>;
4455ffd83dbSDimitry Andricdef TLFloat         : TypeList<[Float, Double, Half]>;
4465ffd83dbSDimitry Andricdef TLSignedInts    : TypeList<[Char, Short, Int, Long]>;
4475ffd83dbSDimitry Andricdef TLUnsignedInts  : TypeList<[UChar, UShort, UInt, ULong]>;
448480093f4SDimitry Andric
4495ffd83dbSDimitry Andricdef TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
450480093f4SDimitry Andric
451480093f4SDimitry Andric// All unsigned integer types twice, to facilitate unsigned return types for e.g.
452480093f4SDimitry Andric// uchar abs(char) and
453480093f4SDimitry Andric// uchar abs(uchar).
4545ffd83dbSDimitry Andricdef TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
455a7dea167SDimitry Andric
4565ffd83dbSDimitry Andricdef TLAllInts       : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
457a7dea167SDimitry Andric
458a7dea167SDimitry Andric// GenType definitions for multiple base types (e.g. all floating point types,
459a7dea167SDimitry Andric// or all integer types).
460a7dea167SDimitry Andric// All types
461fe6060f1SDimitry Andricdef AGenType1              : GenericType<"AGenType1", TLAll, Vec1>;
462a7dea167SDimitry Andricdef AGenTypeN              : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
463a7dea167SDimitry Andricdef AGenTypeNNoScalar      : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
464a7dea167SDimitry Andric// All integer
465a7dea167SDimitry Andricdef AIGenType1             : GenericType<"AIGenType1", TLAllInts, Vec1>;
466a7dea167SDimitry Andricdef AIGenTypeN             : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
467a7dea167SDimitry Andricdef AIGenTypeNNoScalar     : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
468480093f4SDimitry Andric// All integer to unsigned
469480093f4SDimitry Andricdef AI2UGenTypeN           : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
470480093f4SDimitry Andric// Signed integer
471480093f4SDimitry Andricdef SGenTypeN              : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
472480093f4SDimitry Andric// Unsigned integer
473480093f4SDimitry Andricdef UGenTypeN              : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
474a7dea167SDimitry Andric// Float
475a7dea167SDimitry Andricdef FGenTypeN              : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
476480093f4SDimitry Andric// (u)int, (u)long, and all floats
477480093f4SDimitry Andricdef IntLongFloatGenType1   : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
478fe6060f1SDimitry Andric// (u)char and (u)short
479fe6060f1SDimitry Andricdef CharShortGenType1      : GenericType<"CharShortGenType1",
480fe6060f1SDimitry Andric                                 TypeList<[Char, UChar, Short, UShort]>, Vec1>;
481a7dea167SDimitry Andric
482a7dea167SDimitry Andric// GenType definitions for every single base type (e.g. fp32 only).
483a7dea167SDimitry Andric// Names are like: GenTypeFloatVecAndScalar.
484a7dea167SDimitry Andricforeach Type = [Char, UChar, Short, UShort,
485a7dea167SDimitry Andric                Int, UInt, Long, ULong,
486a7dea167SDimitry Andric                Float, Double, Half] in {
487a7dea167SDimitry Andric  foreach VecSizes = [VecAndScalar, VecNoScalar] in {
488a7dea167SDimitry Andric    def "GenType" # Type # VecSizes :
489a7dea167SDimitry Andric              GenericType<"GenType" # Type # VecSizes,
4905ffd83dbSDimitry Andric                          TypeList<[Type]>, VecSizes>;
491a7dea167SDimitry Andric  }
4920b57cec5SDimitry Andric}
4930b57cec5SDimitry Andric
494480093f4SDimitry Andric// GenType definitions for vec1234.
495480093f4SDimitry Andricforeach Type = [Float, Double, Half] in {
496480093f4SDimitry Andric  def "GenType" # Type # Vec1234 :
497480093f4SDimitry Andric              GenericType<"GenType" # Type # Vec1234,
4985ffd83dbSDimitry Andric                          TypeList<[Type]>, Vec1234>;
499480093f4SDimitry Andric}
500480093f4SDimitry Andric
5010b57cec5SDimitry Andric
5020b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
5030b57cec5SDimitry Andric//                 Definitions of OpenCL builtin functions
5040b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
505a7dea167SDimitry Andric//--------------------------------------------------------------------
506a7dea167SDimitry Andric// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
507a7dea167SDimitry Andric// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
508a7dea167SDimitry Andric
509a7dea167SDimitry Andric// Generate the convert_* builtins functions.
510a7dea167SDimitry Andricforeach RType = [Float, Double, Half, Char, UChar, Short,
511a7dea167SDimitry Andric                 UShort, Int, UInt, Long, ULong] in {
512a7dea167SDimitry Andric  foreach IType = [Float, Double, Half, Char, UChar, Short,
513a7dea167SDimitry Andric                   UShort, Int, UInt, Long, ULong] in {
5145ffd83dbSDimitry Andric    // Conversions to integer type have a sat and non-sat variant.
5155ffd83dbSDimitry Andric    foreach sat = !cond(!eq(RType.Name, "float") : [""],
5165ffd83dbSDimitry Andric                        !eq(RType.Name, "double") : [""],
5175ffd83dbSDimitry Andric                        !eq(RType.Name, "half") : [""],
5185ffd83dbSDimitry Andric                        1 : ["", "_sat"]) in {
519a7dea167SDimitry Andric      foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
520480093f4SDimitry Andric        def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
521480093f4SDimitry Andric                      Attr.Const>;
5220b57cec5SDimitry Andric        foreach v = [2, 3, 4, 8, 16] in {
523a7dea167SDimitry Andric          def : Builtin<"convert_" # RType.Name # v # sat # rnd,
524480093f4SDimitry Andric                        [VectorType<RType, v>, VectorType<IType, v>],
525480093f4SDimitry Andric                        Attr.Const>;
5260b57cec5SDimitry Andric        }
5270b57cec5SDimitry Andric      }
5280b57cec5SDimitry Andric    }
5290b57cec5SDimitry Andric  }
5300b57cec5SDimitry Andric}
5310b57cec5SDimitry Andric
532a7dea167SDimitry Andric//--------------------------------------------------------------------
533a7dea167SDimitry Andric// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
534a7dea167SDimitry Andric// --- Table 7 ---
535480093f4SDimitry Andricdef : Builtin<"get_work_dim", [UInt], Attr.Const>;
5360b57cec5SDimitry Andricforeach name = ["get_global_size", "get_global_id", "get_local_size",
5370b57cec5SDimitry Andric                "get_local_id", "get_num_groups", "get_group_id",
5380b57cec5SDimitry Andric                "get_global_offset"] in {
539480093f4SDimitry Andric  def : Builtin<name, [Size, UInt], Attr.Const>;
540a7dea167SDimitry Andric}
541a7dea167SDimitry Andric
542a7dea167SDimitry Andriclet MinVersion = CL20 in {
543a7dea167SDimitry Andric  def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
544a7dea167SDimitry Andric  foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
545a7dea167SDimitry Andric    def : Builtin<name, [Size]>;
546a7dea167SDimitry Andric  }
547a7dea167SDimitry Andric}
548a7dea167SDimitry Andric
549480093f4SDimitry Andric
550480093f4SDimitry Andric//--------------------------------------------------------------------
551480093f4SDimitry Andric// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
552480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
553480093f4SDimitry Andric// --- Table 8 ---
554480093f4SDimitry Andric// --- 1 argument ---
555480093f4SDimitry Andricforeach name = ["acos", "acosh", "acospi",
556480093f4SDimitry Andric                "asin", "asinh", "asinpi",
557480093f4SDimitry Andric                "atan", "atanh", "atanpi",
558480093f4SDimitry Andric                "cbrt", "ceil",
559480093f4SDimitry Andric                "cos", "cosh", "cospi",
560480093f4SDimitry Andric                "erfc", "erf",
561480093f4SDimitry Andric                "exp", "exp2", "exp10", "expm1",
562480093f4SDimitry Andric                "fabs", "floor",
563480093f4SDimitry Andric                "log", "log2", "log10", "log1p", "logb",
564480093f4SDimitry Andric                "rint", "round", "rsqrt",
565480093f4SDimitry Andric                "sin", "sinh", "sinpi",
566480093f4SDimitry Andric                "sqrt",
567480093f4SDimitry Andric                "tan", "tanh", "tanpi",
568480093f4SDimitry Andric                "tgamma", "trunc",
569480093f4SDimitry Andric                "lgamma"] in {
570480093f4SDimitry Andric    def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
571480093f4SDimitry Andric}
572480093f4SDimitry Andricforeach name = ["nan"] in {
573480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
574480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
575480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
576480093f4SDimitry Andric}
577480093f4SDimitry Andric
578480093f4SDimitry Andric// --- 2 arguments ---
579480093f4SDimitry Andricforeach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
580480093f4SDimitry Andric                "maxmag", "minmag", "nextafter", "pow", "powr",
581480093f4SDimitry Andric                "remainder"] in {
582480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
583480093f4SDimitry Andric}
584480093f4SDimitry Andricforeach name = ["fmax", "fmin"] in {
585480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
586480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
587480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
588480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
589480093f4SDimitry Andric}
590480093f4SDimitry Andricforeach name = ["ilogb"] in {
591480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
592480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
593480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
594480093f4SDimitry Andric}
595480093f4SDimitry Andricforeach name = ["ldexp"] in {
596480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
597480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
598480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
599480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
600480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
601480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
602480093f4SDimitry Andric}
603480093f4SDimitry Andricforeach name = ["pown", "rootn"] in {
604480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
605480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
606480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
607480093f4SDimitry Andric}
608480093f4SDimitry Andric
609480093f4SDimitry Andric// --- 3 arguments ---
610480093f4SDimitry Andricforeach name = ["fma", "mad"] in {
611480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
612480093f4SDimitry Andric}
613480093f4SDimitry Andric
614349cc55cSDimitry Andric// The following math builtins take pointer arguments.  Which overloads are
615349cc55cSDimitry Andric// available depends on whether the generic address space feature is enabled.
616349cc55cSDimitry Andricmulticlass MathWithPointer<list<AddressSpace> addrspaces> {
617349cc55cSDimitry Andric  foreach AS = addrspaces in {
618480093f4SDimitry Andric    foreach name = ["fract", "modf", "sincos"] in {
619480093f4SDimitry Andric      def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
620480093f4SDimitry Andric    }
621480093f4SDimitry Andric    foreach name = ["frexp", "lgamma_r"] in {
622480093f4SDimitry Andric      foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
623480093f4SDimitry Andric        def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
624480093f4SDimitry Andric      }
625480093f4SDimitry Andric    }
626480093f4SDimitry Andric    foreach name = ["remquo"] in {
627480093f4SDimitry Andric      foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
628480093f4SDimitry Andric        def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
629480093f4SDimitry Andric      }
630480093f4SDimitry Andric    }
631480093f4SDimitry Andric  }
632480093f4SDimitry Andric}
633349cc55cSDimitry Andric
6341fd87a68SDimitry Andriclet Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
635349cc55cSDimitry Andric  defm : MathWithPointer<[GlobalAS, LocalAS, PrivateAS]>;
636349cc55cSDimitry Andric}
6371fd87a68SDimitry Andriclet Extension = FuncExtOpenCLCGenericAddressSpace in {
638349cc55cSDimitry Andric  defm : MathWithPointer<[GenericAS]>;
639480093f4SDimitry Andric}
640480093f4SDimitry Andric
641480093f4SDimitry Andric// --- Table 9 ---
642480093f4SDimitry Andricforeach name = ["half_cos",
643480093f4SDimitry Andric                "half_exp", "half_exp2", "half_exp10",
644480093f4SDimitry Andric                "half_log", "half_log2", "half_log10",
645480093f4SDimitry Andric                "half_recip", "half_rsqrt",
646480093f4SDimitry Andric                "half_sin", "half_sqrt", "half_tan",
647480093f4SDimitry Andric                "native_cos",
648480093f4SDimitry Andric                "native_exp", "native_exp2", "native_exp10",
649480093f4SDimitry Andric                "native_log", "native_log2", "native_log10",
650480093f4SDimitry Andric                "native_recip", "native_rsqrt",
651480093f4SDimitry Andric                "native_sin", "native_sqrt", "native_tan"] in {
652480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
653480093f4SDimitry Andric}
654480093f4SDimitry Andricforeach name = ["half_divide", "half_powr",
655480093f4SDimitry Andric                "native_divide", "native_powr"] in {
656480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
657480093f4SDimitry Andric}
658480093f4SDimitry Andric
659480093f4SDimitry Andric//--------------------------------------------------------------------
660480093f4SDimitry Andric// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
661480093f4SDimitry Andric// --- Table 10 ---
662480093f4SDimitry Andric// --- 1 argument ---
663480093f4SDimitry Andricforeach name = ["abs"] in {
664480093f4SDimitry Andric  def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
665480093f4SDimitry Andric}
666fe6060f1SDimitry Andricdef : Builtin<"clz", [AIGenTypeN, AIGenTypeN], Attr.Const>;
667fe6060f1SDimitry Andriclet MinVersion = CL12 in {
668fe6060f1SDimitry Andric  def : Builtin<"popcount", [AIGenTypeN, AIGenTypeN], Attr.Const>;
669480093f4SDimitry Andric}
670480093f4SDimitry Andriclet MinVersion = CL20 in {
671480093f4SDimitry Andric  foreach name = ["ctz"] in {
672fe6060f1SDimitry Andric    def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
673480093f4SDimitry Andric  }
674480093f4SDimitry Andric}
675480093f4SDimitry Andric
676480093f4SDimitry Andric// --- 2 arguments ---
677480093f4SDimitry Andricforeach name = ["abs_diff"] in {
678480093f4SDimitry Andric  def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
679480093f4SDimitry Andric}
680480093f4SDimitry Andricforeach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
681480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
682480093f4SDimitry Andric}
683480093f4SDimitry Andricforeach name = ["max", "min"] in {
684480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
685480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
686480093f4SDimitry Andric}
687480093f4SDimitry Andricforeach name = ["upsample"] in {
688480093f4SDimitry Andric  def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
689480093f4SDimitry Andric  def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
690480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
691480093f4SDimitry Andric  def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
692480093f4SDimitry Andric  def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
693480093f4SDimitry Andric  def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
694480093f4SDimitry Andric}
695480093f4SDimitry Andric
696480093f4SDimitry Andric// --- 3 arguments ---
697480093f4SDimitry Andricforeach name = ["clamp"] in {
698480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
699480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
700480093f4SDimitry Andric}
701480093f4SDimitry Andricforeach name = ["mad_hi", "mad_sat"] in {
702480093f4SDimitry Andric  def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
703480093f4SDimitry Andric}
704480093f4SDimitry Andric
705480093f4SDimitry Andric// --- Table 11 ---
706480093f4SDimitry Andricforeach name = ["mad24"] in {
707480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
708480093f4SDimitry Andric  def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
709480093f4SDimitry Andric}
710480093f4SDimitry Andricforeach name = ["mul24"] in {
711480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
712480093f4SDimitry Andric  def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
713480093f4SDimitry Andric}
714480093f4SDimitry Andric
715480093f4SDimitry Andric//--------------------------------------------------------------------
716480093f4SDimitry Andric// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
717480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
718480093f4SDimitry Andric// --- Table 12 ---
719480093f4SDimitry Andric// --- 1 argument ---
720480093f4SDimitry Andricforeach name = ["degrees", "radians", "sign"] in {
721480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
722480093f4SDimitry Andric}
723480093f4SDimitry Andric
724480093f4SDimitry Andric// --- 2 arguments ---
725480093f4SDimitry Andricforeach name = ["max", "min"] in {
726480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
727480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
728480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
729480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
730480093f4SDimitry Andric}
731480093f4SDimitry Andricforeach name = ["step"] in {
732480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
733480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
734480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
735480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
736480093f4SDimitry Andric}
737480093f4SDimitry Andric
738480093f4SDimitry Andric// --- 3 arguments ---
739fe6060f1SDimitry Andricforeach name = ["clamp"] in {
740480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
741480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
742480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
743480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
744480093f4SDimitry Andric}
745fe6060f1SDimitry Andricforeach name = ["mix"] in {
746fe6060f1SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
747fe6060f1SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
748fe6060f1SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
749fe6060f1SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
750fe6060f1SDimitry Andric}
751480093f4SDimitry Andricforeach name = ["smoothstep"] in {
752480093f4SDimitry Andric  def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
753480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
754480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
755480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
756480093f4SDimitry Andric}
757480093f4SDimitry Andric
758480093f4SDimitry Andric
759480093f4SDimitry Andric//--------------------------------------------------------------------
760480093f4SDimitry Andric// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
761480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
762480093f4SDimitry Andric// --- Table 13 ---
763480093f4SDimitry Andric// --- 1 argument ---
764480093f4SDimitry Andricforeach name = ["length"] in {
765480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
766480093f4SDimitry Andric  def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
767480093f4SDimitry Andric  def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
768480093f4SDimitry Andric}
769480093f4SDimitry Andricforeach name = ["normalize"] in {
770480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
771480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
772480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
773480093f4SDimitry Andric}
774480093f4SDimitry Andricforeach name = ["fast_length"] in {
775480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
776480093f4SDimitry Andric}
777480093f4SDimitry Andricforeach name = ["fast_normalize"] in {
778480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
779480093f4SDimitry Andric}
780480093f4SDimitry Andric
781480093f4SDimitry Andric// --- 2 arguments ---
782480093f4SDimitry Andricforeach name = ["cross"] in {
783480093f4SDimitry Andric  foreach VSize = [3, 4] in {
784480093f4SDimitry Andric    def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
785480093f4SDimitry Andric    def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
786480093f4SDimitry Andric    def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
787480093f4SDimitry Andric  }
788480093f4SDimitry Andric}
789480093f4SDimitry Andricforeach name = ["dot", "distance"] in {
790480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
791480093f4SDimitry Andric  def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
792480093f4SDimitry Andric  def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
793480093f4SDimitry Andric}
794480093f4SDimitry Andricforeach name = ["fast_distance"] in {
795480093f4SDimitry Andric  def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
796480093f4SDimitry Andric}
797480093f4SDimitry Andric
798480093f4SDimitry Andric
799480093f4SDimitry Andric//--------------------------------------------------------------------
800480093f4SDimitry Andric// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
801480093f4SDimitry Andric// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
802480093f4SDimitry Andric// --- Table 14 ---
803480093f4SDimitry Andric// --- 1 argument ---
804480093f4SDimitry Andricforeach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
805480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
806480093f4SDimitry Andric  def : Builtin<name, [Int, Double], Attr.Const>;
807480093f4SDimitry Andric  def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
808480093f4SDimitry Andric  def : Builtin<name, [Int, Half], Attr.Const>;
809480093f4SDimitry Andric  def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
810480093f4SDimitry Andric}
811480093f4SDimitry Andricforeach name = ["any", "all"] in {
8125ffd83dbSDimitry Andric  def : Builtin<name, [Int, SGenTypeN], Attr.Const>;
813480093f4SDimitry Andric}
814480093f4SDimitry Andric
815480093f4SDimitry Andric// --- 2 arguments ---
816480093f4SDimitry Andricforeach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
817480093f4SDimitry Andric                "isless", "islessequal", "islessgreater", "isordered",
818480093f4SDimitry Andric                "isunordered"] in {
819480093f4SDimitry Andric  def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
820480093f4SDimitry Andric  def : Builtin<name, [Int, Double, Double], Attr.Const>;
821480093f4SDimitry Andric  def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
822480093f4SDimitry Andric  def : Builtin<name, [Int, Half, Half], Attr.Const>;
823480093f4SDimitry Andric  def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
824480093f4SDimitry Andric}
825480093f4SDimitry Andric
826480093f4SDimitry Andric// --- 3 arguments ---
827480093f4SDimitry Andricforeach name = ["bitselect"] in {
828480093f4SDimitry Andric  def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
829480093f4SDimitry Andric}
830480093f4SDimitry Andricforeach name = ["select"] in {
831480093f4SDimitry Andric  def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
832480093f4SDimitry Andric  def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
833480093f4SDimitry Andric  def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
834480093f4SDimitry Andric  def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
835480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
836480093f4SDimitry Andric  def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
837480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
838480093f4SDimitry Andric  def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
839480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
840480093f4SDimitry Andric  def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
841480093f4SDimitry Andric}
842480093f4SDimitry Andric
843480093f4SDimitry Andric
844a7dea167SDimitry Andric//--------------------------------------------------------------------
845a7dea167SDimitry Andric// OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
846480093f4SDimitry 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
847a7dea167SDimitry Andric// --- Table 15 ---
848349cc55cSDimitry Andricmulticlass VloadVstore<list<AddressSpace> addrspaces, bit defStores> {
849349cc55cSDimitry Andric  foreach AS = addrspaces in {
850a7dea167SDimitry Andric    foreach VSize = [2, 3, 4, 8, 16] in {
851a7dea167SDimitry Andric      foreach name = ["vload" # VSize] in {
8520eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>], Attr.Pure>;
8530eae32dcSDimitry Andric        def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>], Attr.Pure>;
8540eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>], Attr.Pure>;
8550eae32dcSDimitry Andric        def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>], Attr.Pure>;
8560eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>], Attr.Pure>;
8570eae32dcSDimitry Andric        def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>], Attr.Pure>;
8580eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>], Attr.Pure>;
8590eae32dcSDimitry Andric        def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>], Attr.Pure>;
8600eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>], Attr.Pure>;
8610eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>], Attr.Pure>;
8620eae32dcSDimitry Andric        def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>], Attr.Pure>;
863a7dea167SDimitry Andric      }
864349cc55cSDimitry Andric      if defStores then {
865a7dea167SDimitry Andric        foreach name = ["vstore" # VSize] in {
8665ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>;
8675ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>;
8685ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>;
8695ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>;
8705ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>;
8715ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>;
8725ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>;
8735ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>;
8745ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>;
8755ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>;
8765ffd83dbSDimitry Andric          def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>;
877a7dea167SDimitry Andric        }
878a7dea167SDimitry Andric      }
879a7dea167SDimitry Andric    }
880a7dea167SDimitry Andric  }
881a7dea167SDimitry Andric}
882349cc55cSDimitry Andric
8831fd87a68SDimitry Andriclet Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
884349cc55cSDimitry Andric  defm : VloadVstore<[GlobalAS, LocalAS, PrivateAS], 1>;
885480093f4SDimitry Andric}
8861fd87a68SDimitry Andriclet Extension = FuncExtOpenCLCGenericAddressSpace in {
887349cc55cSDimitry Andric  defm : VloadVstore<[GenericAS], 1>;
888349cc55cSDimitry Andric}
889349cc55cSDimitry Andric// vload with constant address space is available regardless of version.
890349cc55cSDimitry Andricdefm : VloadVstore<[ConstantAS], 0>;
891349cc55cSDimitry Andric
892349cc55cSDimitry Andricmulticlass VloadVstoreHalf<list<AddressSpace> addrspaces, bit defStores> {
893349cc55cSDimitry Andric  foreach AS = addrspaces in {
89481ad6265SDimitry Andric    def : Builtin<"vload_half", [Float, Size, !cast<Type>("HalfPtrConst" # AS)], Attr.Pure>;
895480093f4SDimitry Andric    foreach VSize = [2, 3, 4, 8, 16] in {
896349cc55cSDimitry Andric      foreach name = ["vload_half" # VSize, "vloada_half" # VSize] in {
89781ad6265SDimitry Andric        def : Builtin<name, [VectorType<Float, VSize>, Size, !cast<Type>("HalfPtrConst" # AS)], Attr.Pure>;
898480093f4SDimitry Andric      }
899480093f4SDimitry Andric    }
900349cc55cSDimitry Andric    if defStores then {
901480093f4SDimitry Andric      foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
902349cc55cSDimitry Andric        foreach name = ["vstore_half" # rnd] in {
90381ad6265SDimitry Andric          def : Builtin<name, [Void, Float, Size, !cast<Type>("HalfPtr" # AS)]>;
90481ad6265SDimitry Andric          def : Builtin<name, [Void, Double, Size, !cast<Type>("HalfPtr" # AS)]>;
9055ffd83dbSDimitry Andric        }
906480093f4SDimitry Andric        foreach VSize = [2, 3, 4, 8, 16] in {
907349cc55cSDimitry Andric          foreach name = ["vstore_half" # VSize # rnd, "vstorea_half" # VSize # rnd] in {
90881ad6265SDimitry Andric            def : Builtin<name, [Void, VectorType<Float, VSize>, Size, !cast<Type>("HalfPtr" # AS)]>;
90981ad6265SDimitry Andric            def : Builtin<name, [Void, VectorType<Double, VSize>, Size, !cast<Type>("HalfPtr" # AS)]>;
910480093f4SDimitry Andric          }
911480093f4SDimitry Andric        }
912480093f4SDimitry Andric      }
913480093f4SDimitry Andric    }
914480093f4SDimitry Andric  }
915349cc55cSDimitry Andric}
916480093f4SDimitry Andric
9171fd87a68SDimitry Andriclet Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
918349cc55cSDimitry Andric  defm : VloadVstoreHalf<[GlobalAS, LocalAS, PrivateAS], 1>;
919480093f4SDimitry Andric}
9201fd87a68SDimitry Andriclet Extension = FuncExtOpenCLCGenericAddressSpace in {
921349cc55cSDimitry Andric  defm : VloadVstoreHalf<[GenericAS], 1>;
922480093f4SDimitry Andric}
9230eae32dcSDimitry Andric// vload_half and vloada_half with constant address space are available regardless of version.
924349cc55cSDimitry Andricdefm : VloadVstoreHalf<[ConstantAS], 0>;
925a7dea167SDimitry Andric
926fe6060f1SDimitry Andric// OpenCL v3.0 s6.15.8 - Synchronization Functions.
927fe6060f1SDimitry Andricdef : Builtin<"barrier", [Void, MemFenceFlags], Attr.Convergent>;
928fe6060f1SDimitry Andriclet MinVersion = CL20 in {
929fe6060f1SDimitry Andric  def : Builtin<"work_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
930fe6060f1SDimitry Andric  def : Builtin<"work_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
931fe6060f1SDimitry Andric}
932fe6060f1SDimitry Andric
933fe6060f1SDimitry Andric// OpenCL v3.0 s6.15.9 - Legacy Explicit Memory Fence Functions.
934fe6060f1SDimitry Andricdef : Builtin<"mem_fence", [Void, MemFenceFlags]>;
935fe6060f1SDimitry Andricdef : Builtin<"read_mem_fence", [Void, MemFenceFlags]>;
936fe6060f1SDimitry Andricdef : Builtin<"write_mem_fence", [Void, MemFenceFlags]>;
937fe6060f1SDimitry Andric
938fe6060f1SDimitry Andric// OpenCL v3.0 s6.15.10 - Address Space Qualifier Functions.
939*0fca6ea1SDimitry Andric// to_global, to_local, to_private are declared in Builtins.td.
940fe6060f1SDimitry Andric
94181ad6265SDimitry Andriclet Extension = FuncExtOpenCLCGenericAddressSpace in {
942fe6060f1SDimitry Andric  // The OpenCL 3.0 specification defines these with a "gentype" argument indicating any builtin
943fe6060f1SDimitry Andric  // type or user-defined type, which cannot be represented currently.  Hence we slightly diverge
944fe6060f1SDimitry Andric  // by providing only the following overloads with a void pointer.
945fe6060f1SDimitry Andric  def : Builtin<"get_fence", [MemFenceFlags, PointerType<Void, GenericAS>]>;
946fe6060f1SDimitry Andric  def : Builtin<"get_fence", [MemFenceFlags, PointerType<ConstType<Void>, GenericAS>]>;
947fe6060f1SDimitry Andric}
948fe6060f1SDimitry Andric
949a7dea167SDimitry Andric//--------------------------------------------------------------------
950a7dea167SDimitry 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
951a7dea167SDimitry 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
952a7dea167SDimitry Andric// --- Table 18 ---
953a7dea167SDimitry Andricforeach name = ["async_work_group_copy"] in {
954a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
955a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
956a7dea167SDimitry Andric}
957a7dea167SDimitry Andricforeach name = ["async_work_group_strided_copy"] in {
958a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
959a7dea167SDimitry Andric  def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
960a7dea167SDimitry Andric}
961a7dea167SDimitry Andricforeach name = ["wait_group_events"] in {
962a7dea167SDimitry Andric  def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
963a7dea167SDimitry Andric}
964a7dea167SDimitry Andricforeach name = ["prefetch"] in {
965a7dea167SDimitry Andric  def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
966a7dea167SDimitry Andric}
967a7dea167SDimitry Andric
968a7dea167SDimitry Andric//--------------------------------------------------------------------
969a7dea167SDimitry Andric// OpenCL v2.0 s6.13.11 - Atomics Functions.
970a7dea167SDimitry Andric// Functions that use memory_order and cl_mem_fence_flags enums are not
971a7dea167SDimitry Andric// declared here as the TableGen backend does not handle enums.
972a7dea167SDimitry Andric
973480093f4SDimitry Andric// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
974a7dea167SDimitry Andric// --- Table 9.1 ---
975480093f4SDimitry Andriclet Extension = FuncExtKhrGlobalInt32BaseAtomics in {
976a7dea167SDimitry Andric  foreach Type = [Int, UInt] in {
977a7dea167SDimitry Andric    foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
978a7dea167SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
979a7dea167SDimitry Andric    }
980a7dea167SDimitry Andric    foreach name = ["atom_inc", "atom_dec"] in {
981a7dea167SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
982a7dea167SDimitry Andric    }
983a7dea167SDimitry Andric    foreach name = ["atom_cmpxchg"] in {
984a7dea167SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
985a7dea167SDimitry Andric    }
9860b57cec5SDimitry Andric  }
987480093f4SDimitry Andric}
988480093f4SDimitry Andric// --- Table 9.3 ---
989480093f4SDimitry Andriclet Extension = FuncExtKhrLocalInt32BaseAtomics in {
990480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
991480093f4SDimitry Andric    foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
992480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
993480093f4SDimitry Andric    }
994480093f4SDimitry Andric    foreach name = ["atom_inc", "atom_dec"] in {
995480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
996480093f4SDimitry Andric    }
997480093f4SDimitry Andric    foreach name = ["atom_cmpxchg"] in {
998480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
999480093f4SDimitry Andric    }
1000480093f4SDimitry Andric  }
1001480093f4SDimitry Andric}
1002480093f4SDimitry Andric// --- Table 9.5 ---
1003480093f4SDimitry Andriclet Extension = FuncExtKhrInt64BaseAtomics in {
1004480093f4SDimitry Andric  foreach AS = [GlobalAS, LocalAS] in {
1005480093f4SDimitry Andric    foreach Type = [Long, ULong] in {
1006480093f4SDimitry Andric      foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
1007480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
1008480093f4SDimitry Andric      }
1009480093f4SDimitry Andric      foreach name = ["atom_inc", "atom_dec"] in {
1010480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
1011480093f4SDimitry Andric      }
1012480093f4SDimitry Andric      foreach name = ["atom_cmpxchg"] in {
1013480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
1014480093f4SDimitry Andric      }
1015480093f4SDimitry Andric    }
1016480093f4SDimitry Andric  }
1017480093f4SDimitry Andric}
1018480093f4SDimitry Andric// --- Table 9.2 ---
1019480093f4SDimitry Andriclet Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
1020480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
1021480093f4SDimitry Andric    foreach name = ["atom_min", "atom_max", "atom_and",
1022480093f4SDimitry Andric                    "atom_or", "atom_xor"] in {
1023480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
1024480093f4SDimitry Andric    }
1025480093f4SDimitry Andric  }
1026480093f4SDimitry Andric}
1027480093f4SDimitry Andric// --- Table 9.4 ---
1028480093f4SDimitry Andriclet Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
1029480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
1030480093f4SDimitry Andric    foreach name = ["atom_min", "atom_max", "atom_and",
1031480093f4SDimitry Andric                    "atom_or", "atom_xor"] in {
1032480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
1033480093f4SDimitry Andric    }
1034480093f4SDimitry Andric  }
1035480093f4SDimitry Andric}
1036480093f4SDimitry Andric// --- Table 9.6 ---
1037480093f4SDimitry Andriclet Extension = FuncExtKhrInt64ExtendedAtomics in {
1038480093f4SDimitry Andric  foreach AS = [GlobalAS, LocalAS] in {
1039480093f4SDimitry Andric    foreach Type = [Long, ULong] in {
1040480093f4SDimitry Andric      foreach name = ["atom_min", "atom_max", "atom_and",
1041480093f4SDimitry Andric                      "atom_or", "atom_xor"] in {
1042480093f4SDimitry Andric        def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
1043480093f4SDimitry Andric      }
1044480093f4SDimitry Andric    }
1045480093f4SDimitry Andric  }
1046480093f4SDimitry Andric}
1047480093f4SDimitry Andric// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
1048480093f4SDimitry Andricforeach AS = [GlobalAS, LocalAS] in {
1049fe6060f1SDimitry Andric  def : Builtin<"atomic_xchg", [Float, PointerType<VolatileType<Float>, AS>, Float]>;
1050480093f4SDimitry Andric  foreach Type = [Int, UInt] in {
1051480093f4SDimitry Andric    foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
1052480093f4SDimitry Andric                    "atomic_min", "atomic_max", "atomic_and",
1053480093f4SDimitry Andric                    "atomic_or", "atomic_xor"] in {
1054480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
1055480093f4SDimitry Andric    }
1056480093f4SDimitry Andric    foreach name = ["atomic_inc", "atomic_dec"] in {
1057480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
1058480093f4SDimitry Andric    }
1059480093f4SDimitry Andric    foreach name = ["atomic_cmpxchg"] in {
1060480093f4SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
1061480093f4SDimitry Andric    }
1062480093f4SDimitry Andric  }
10630b57cec5SDimitry Andric}
1064fe6060f1SDimitry Andric
1065fe6060f1SDimitry Andriclet Extension = FuncExtOpenCLCxx in {
1066fe6060f1SDimitry Andric  foreach Type = [Int, UInt] in {
1067fe6060f1SDimitry Andric    foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
1068fe6060f1SDimitry Andric                    "atomic_min", "atomic_max", "atomic_and",
1069fe6060f1SDimitry Andric                    "atomic_or", "atomic_xor"] in {
1070fe6060f1SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type]>;
1071fe6060f1SDimitry Andric    }
1072fe6060f1SDimitry Andric    foreach name = ["atomic_inc", "atomic_dec"] in {
1073fe6060f1SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>]>;
1074fe6060f1SDimitry Andric    }
1075fe6060f1SDimitry Andric    foreach name = ["atomic_cmpxchg"] in {
1076fe6060f1SDimitry Andric      def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type, Type]>;
1077fe6060f1SDimitry Andric    }
1078fe6060f1SDimitry Andric  }
1079fe6060f1SDimitry Andric}
1080fe6060f1SDimitry Andric
10815ffd83dbSDimitry Andric// OpenCL v2.0 s6.13.11 - Atomic Functions.
1082fe6060f1SDimitry Andric
1083d56accc7SDimitry Andric// An atomic builtin with 2 additional _explicit variants.
1084d56accc7SDimitry Andricmulticlass BuiltinAtomicExplicit<string Name, list<Type> Types, FunctionExtension BaseExt> {
1085d56accc7SDimitry Andric  // Without explicit MemoryOrder or MemoryScope.
1086d56accc7SDimitry Andric  let Extension = concatExtension<BaseExt, "__opencl_c_atomic_order_seq_cst __opencl_c_atomic_scope_device">.ret in {
1087d56accc7SDimitry Andric    def : Builtin<Name, Types>;
1088d56accc7SDimitry Andric  }
1089d56accc7SDimitry Andric
1090d56accc7SDimitry Andric  // With an explicit MemoryOrder argument.
1091d56accc7SDimitry Andric  let Extension = concatExtension<BaseExt, "__opencl_c_atomic_scope_device">.ret in {
1092d56accc7SDimitry Andric    def : Builtin<Name # "_explicit", !listconcat(Types, [MemoryOrder])>;
1093d56accc7SDimitry Andric  }
1094d56accc7SDimitry Andric
1095d56accc7SDimitry Andric  // With explicit MemoryOrder and MemoryScope arguments.
1096d56accc7SDimitry Andric  let Extension = BaseExt in {
1097d56accc7SDimitry Andric    def : Builtin<Name # "_explicit", !listconcat(Types, [MemoryOrder, MemoryScope])>;
1098d56accc7SDimitry Andric  }
1099d56accc7SDimitry Andric}
1100d56accc7SDimitry Andric
1101d56accc7SDimitry Andric// OpenCL 2.0 atomic functions that have a pointer argument in a given address space.
1102d56accc7SDimitry Andricmulticlass OpenCL2Atomics<AddressSpace addrspace, FunctionExtension BaseExt> {
11035ffd83dbSDimitry Andric  foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
11045ffd83dbSDimitry Andric                      [AtomicLong, Long], [AtomicULong, ULong],
11055ffd83dbSDimitry Andric                      [AtomicFloat, Float], [AtomicDouble, Double]] in {
110681ad6265SDimitry Andric    let Extension = BaseExt in {
11075ffd83dbSDimitry Andric      def : Builtin<"atomic_init",
1108d56accc7SDimitry Andric          [Void, PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]]>;
110981ad6265SDimitry Andric    }
1110d56accc7SDimitry Andric    defm : BuiltinAtomicExplicit<"atomic_store",
1111d56accc7SDimitry Andric        [Void, PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]], BaseExt>;
1112d56accc7SDimitry Andric    defm : BuiltinAtomicExplicit<"atomic_load",
1113d56accc7SDimitry Andric        [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>], BaseExt>;
1114d56accc7SDimitry Andric    defm : BuiltinAtomicExplicit<"atomic_exchange",
1115d56accc7SDimitry Andric        [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]], BaseExt>;
11165ffd83dbSDimitry Andric    foreach Variant = ["weak", "strong"] in {
1117d56accc7SDimitry Andric      foreach exp_ptr_addrspace = !cond(
1118d56accc7SDimitry Andric            !eq(BaseExt, FuncExtOpenCLCGenericAddressSpace): [GenericAS],
1119d56accc7SDimitry Andric            !eq(BaseExt, FuncExtOpenCLCNamedAddressSpaceBuiltins): [GlobalAS, LocalAS, PrivateAS])
1120d56accc7SDimitry Andric          in {
1121d56accc7SDimitry Andric        let Extension = concatExtension<BaseExt, "__opencl_c_atomic_order_seq_cst __opencl_c_atomic_scope_device">.ret in {
11225ffd83dbSDimitry Andric          def : Builtin<"atomic_compare_exchange_" # Variant,
1123d56accc7SDimitry Andric              [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
1124d56accc7SDimitry Andric               PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1]]>;
1125d56accc7SDimitry Andric        }
1126d56accc7SDimitry Andric        let Extension = concatExtension<BaseExt, "__opencl_c_atomic_scope_device">.ret in {
1127fe6060f1SDimitry Andric          def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
1128d56accc7SDimitry Andric              [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
1129d56accc7SDimitry Andric               PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1], MemoryOrder, MemoryOrder]>;
1130d56accc7SDimitry Andric        }
1131d56accc7SDimitry Andric        let Extension = BaseExt in {
1132fe6060f1SDimitry Andric          def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
1133d56accc7SDimitry Andric              [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
1134d56accc7SDimitry Andric               PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>;
1135d56accc7SDimitry Andric        }
1136d56accc7SDimitry Andric      }
11375ffd83dbSDimitry Andric    }
11385ffd83dbSDimitry Andric  }
11395ffd83dbSDimitry Andric
11405ffd83dbSDimitry Andric  foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
11415ffd83dbSDimitry Andric                      [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
11425ffd83dbSDimitry Andric                      [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
11435ffd83dbSDimitry Andric    foreach ModOp = ["add", "sub"] in {
1144d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1145d56accc7SDimitry Andric          [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[2]], BaseExt>;
11465ffd83dbSDimitry Andric    }
11475ffd83dbSDimitry Andric  }
11485ffd83dbSDimitry Andric  foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1149fe6060f1SDimitry Andric                      [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] in {
11505ffd83dbSDimitry Andric    foreach ModOp = ["or", "xor", "and", "min", "max"] in {
1151d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1152d56accc7SDimitry Andric          [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[2]], BaseExt>;
11535ffd83dbSDimitry Andric    }
11545ffd83dbSDimitry Andric  }
1155fe6060f1SDimitry Andric
1156d56accc7SDimitry Andric  defm : BuiltinAtomicExplicit<"atomic_flag_clear",
1157d56accc7SDimitry Andric      [Void, PointerType<VolatileType<AtomicFlag>, addrspace>], BaseExt>;
1158fe6060f1SDimitry Andric
1159d56accc7SDimitry Andric  defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set",
1160d56accc7SDimitry Andric      [Bool, PointerType<VolatileType<AtomicFlag>, addrspace>], BaseExt>;
1161d56accc7SDimitry Andric}
1162d56accc7SDimitry Andric
1163d56accc7SDimitry Andriclet MinVersion = CL20 in {
1164d56accc7SDimitry Andric  def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>;
1165d56accc7SDimitry Andric
1166d56accc7SDimitry Andric  defm : OpenCL2Atomics<GenericAS, FuncExtOpenCLCGenericAddressSpace>;
1167d56accc7SDimitry Andric  defm : OpenCL2Atomics<GlobalAS, FuncExtOpenCLCNamedAddressSpaceBuiltins>;
1168d56accc7SDimitry Andric  defm : OpenCL2Atomics<LocalAS, FuncExtOpenCLCNamedAddressSpaceBuiltins>;
11695ffd83dbSDimitry Andric}
11700b57cec5SDimitry Andric
1171349cc55cSDimitry Andric// The functionality added by cl_ext_float_atomics extension
1172349cc55cSDimitry Andriclet MinVersion = CL20 in {
1173d56accc7SDimitry Andric  foreach addrspace = [GlobalAS, LocalAS, GenericAS] in {
1174d56accc7SDimitry Andric    defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "LoadStore");
1175d56accc7SDimitry Andric
1176d56accc7SDimitry Andric    defm : BuiltinAtomicExplicit<"atomic_store",
1177d56accc7SDimitry Andric        [Void, PointerType<VolatileType<AtomicHalf>, addrspace>, AtomicHalf], extension_fp16>;
1178d56accc7SDimitry Andric    defm : BuiltinAtomicExplicit<"atomic_load",
1179d56accc7SDimitry Andric        [Half, PointerType<VolatileType<AtomicHalf>, addrspace>], extension_fp16>;
1180d56accc7SDimitry Andric    defm : BuiltinAtomicExplicit<"atomic_exchange",
1181d56accc7SDimitry Andric        [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
1182d56accc7SDimitry Andric
1183349cc55cSDimitry Andric    foreach ModOp = ["add", "sub"] in {
1184d56accc7SDimitry Andric      defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "Add");
1185d56accc7SDimitry Andric      defvar extension_fp32 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp32" # addrspace # "Add");
1186d56accc7SDimitry Andric      defvar extension_fp64 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp64" # addrspace # "Add");
1187d56accc7SDimitry Andric
1188d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
118981ad6265SDimitry Andric          [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
1190d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1191d56accc7SDimitry Andric          [Float, PointerType<VolatileType<AtomicFloat>, addrspace>, Float], extension_fp32>;
1192d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1193d56accc7SDimitry Andric          [Double, PointerType<VolatileType<AtomicDouble>, addrspace>, Double], extension_fp64>;
1194349cc55cSDimitry Andric    }
1195d56accc7SDimitry Andric
1196349cc55cSDimitry Andric    foreach ModOp = ["min", "max"] in {
1197d56accc7SDimitry Andric      defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "MinMax");
1198d56accc7SDimitry Andric      defvar extension_fp32 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp32" # addrspace # "MinMax");
1199d56accc7SDimitry Andric      defvar extension_fp64 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp64" # addrspace # "MinMax");
1200d56accc7SDimitry Andric
1201d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1202d56accc7SDimitry Andric          [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
1203d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1204d56accc7SDimitry Andric          [Float, PointerType<VolatileType<AtomicFloat>, addrspace>, Float], extension_fp32>;
1205d56accc7SDimitry Andric      defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1206d56accc7SDimitry Andric          [Double, PointerType<VolatileType<AtomicDouble>, addrspace>, Double], extension_fp64>;
1207349cc55cSDimitry Andric    }
1208349cc55cSDimitry Andric  }
1209349cc55cSDimitry Andric}
1210349cc55cSDimitry Andric
1211480093f4SDimitry Andric//--------------------------------------------------------------------
1212480093f4SDimitry Andric// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
1213480093f4SDimitry Andric// --- Table 19 ---
1214fe6060f1SDimitry Andricforeach VSize1 = [2, 4, 8, 16] in {
1215fe6060f1SDimitry Andric  foreach VSize2 = [2, 4, 8, 16] in {
1216fe6060f1SDimitry Andric    foreach VecAndMaskType = [[Char, UChar], [UChar, UChar],
1217fe6060f1SDimitry Andric                              [Short, UShort], [UShort, UShort],
1218fe6060f1SDimitry Andric                              [Int, UInt], [UInt, UInt],
1219fe6060f1SDimitry Andric                              [Long, ULong], [ULong, ULong],
1220fe6060f1SDimitry Andric                              [Float, UInt], [Double, ULong], [Half, UShort]] in {
1221fe6060f1SDimitry Andric      def : Builtin<"shuffle", [VectorType<VecAndMaskType[0], VSize1>,
1222fe6060f1SDimitry Andric                                VectorType<VecAndMaskType[0], VSize2>,
1223fe6060f1SDimitry Andric                                VectorType<VecAndMaskType[1], VSize1>],
1224480093f4SDimitry Andric                               Attr.Const>;
12250b57cec5SDimitry Andric    }
1226a7dea167SDimitry Andric  }
1227fe6060f1SDimitry Andric}
1228fe6060f1SDimitry Andricforeach VSize1 = [2, 4, 8, 16] in {
1229fe6060f1SDimitry Andric  foreach VSize2 = [2, 4, 8, 16] in {
1230fe6060f1SDimitry Andric    foreach VecAndMaskType = [[Char, UChar], [UChar, UChar],
1231fe6060f1SDimitry Andric                              [Short, UShort], [UShort, UShort],
1232fe6060f1SDimitry Andric                              [Int, UInt], [UInt, UInt],
1233fe6060f1SDimitry Andric                              [Long, ULong], [ULong, ULong],
1234fe6060f1SDimitry Andric                              [Float, UInt], [Double, ULong], [Half, UShort]] in {
1235fe6060f1SDimitry Andric      def : Builtin<"shuffle2", [VectorType<VecAndMaskType[0], VSize1>,
1236fe6060f1SDimitry Andric                                 VectorType<VecAndMaskType[0], VSize2>,
1237fe6060f1SDimitry Andric                                 VectorType<VecAndMaskType[0], VSize2>,
1238fe6060f1SDimitry Andric                                 VectorType<VecAndMaskType[1], VSize1>],
1239480093f4SDimitry Andric                                Attr.Const>;
1240480093f4SDimitry Andric    }
1241a7dea167SDimitry Andric  }
1242fe6060f1SDimitry Andric}
1243a7dea167SDimitry Andric
1244a7dea167SDimitry Andric//--------------------------------------------------------------------
1245a7dea167SDimitry Andric// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1246a7dea167SDimitry Andric// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1247a7dea167SDimitry Andric// --- Table 22: Image Read Functions with Samplers ---
1248a7dea167SDimitry Andricforeach imgTy = [Image1d] in {
1249a7dea167SDimitry Andric  foreach coordTy = [Int, Float] in {
1250480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1251480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1252480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1253a7dea167SDimitry Andric  }
1254a7dea167SDimitry Andric}
1255a7dea167SDimitry Andricforeach imgTy = [Image2d, Image1dArray] in {
1256a7dea167SDimitry Andric  foreach coordTy = [Int, Float] in {
1257480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1258480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1259480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1260a7dea167SDimitry Andric  }
1261a7dea167SDimitry Andric}
1262a7dea167SDimitry Andricforeach imgTy = [Image3d, Image2dArray] in {
1263a7dea167SDimitry Andric  foreach coordTy = [Int, Float] in {
1264480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1265480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1266480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1267a7dea167SDimitry Andric  }
1268a7dea167SDimitry Andric}
1269a7dea167SDimitry Andricforeach coordTy = [Int, Float] in {
1270480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1271480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1272a7dea167SDimitry Andric}
1273a7dea167SDimitry Andric
1274a7dea167SDimitry Andric// --- Table 23: Sampler-less Read Functions ---
127504eeddc0SDimitry Andricmulticlass ImageReadSamplerless<string aQual> {
1276a7dea167SDimitry Andric  foreach imgTy = [Image2d, Image1dArray] in {
1277480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1278480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1279480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1280a7dea167SDimitry Andric  }
1281a7dea167SDimitry Andric  foreach imgTy = [Image3d, Image2dArray] in {
1282480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1283480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1284480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1285a7dea167SDimitry Andric  }
1286a7dea167SDimitry Andric  foreach imgTy = [Image1d, Image1dBuffer] in {
1287480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1288480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1289480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1290a7dea167SDimitry Andric  }
1291480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1292480093f4SDimitry Andric  def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
1293a7dea167SDimitry Andric}
129404eeddc0SDimitry Andric
129504eeddc0SDimitry Andriclet MinVersion = CL12 in {
129604eeddc0SDimitry Andric  defm : ImageReadSamplerless<"RO">;
129704eeddc0SDimitry Andric  let Extension = FuncExtOpenCLCReadWriteImages in {
129804eeddc0SDimitry Andric    defm : ImageReadSamplerless<"RW">;
129904eeddc0SDimitry Andric  }
1300fe6060f1SDimitry Andric}
1301a7dea167SDimitry Andric
1302a7dea167SDimitry Andric// --- Table 24: Image Write Functions ---
130304eeddc0SDimitry Andricmulticlass ImageWrite<string aQual> {
1304a7dea167SDimitry Andric  foreach imgTy = [Image2d] in {
1305a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1306a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1307a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1308a7dea167SDimitry Andric  }
1309a7dea167SDimitry Andric  foreach imgTy = [Image2dArray] in {
1310a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1311a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1312a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1313a7dea167SDimitry Andric  }
1314a7dea167SDimitry Andric  foreach imgTy = [Image1d, Image1dBuffer] in {
1315a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1316a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1317a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1318a7dea167SDimitry Andric  }
1319a7dea167SDimitry Andric  foreach imgTy = [Image1dArray] in {
1320a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1321a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1322a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1323a7dea167SDimitry Andric  }
1324a7dea167SDimitry Andric  foreach imgTy = [Image3d] in {
1325a7dea167SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1326a7dea167SDimitry Andric    def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1327a7dea167SDimitry Andric    def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1328a7dea167SDimitry Andric  }
1329a7dea167SDimitry Andric  def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1330a7dea167SDimitry Andric  def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1331a7dea167SDimitry Andric}
1332a7dea167SDimitry Andric
133304eeddc0SDimitry Andricdefm : ImageWrite<"WO">;
133404eeddc0SDimitry Andriclet Extension = FuncExtOpenCLCReadWriteImages in {
133504eeddc0SDimitry Andric  defm : ImageWrite<"RW">;
133604eeddc0SDimitry Andric}
133704eeddc0SDimitry Andric
1338a7dea167SDimitry Andric// --- Table 25: Image Query Functions ---
133904eeddc0SDimitry Andricmulticlass ImageQuery<string aQual> {
1340a7dea167SDimitry Andric  foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1341a7dea167SDimitry Andric                   Image1dArray, Image2dArray, Image2dDepth,
1342a7dea167SDimitry Andric                   Image2dArrayDepth] in {
1343a7dea167SDimitry Andric    foreach name = ["get_image_width", "get_image_channel_data_type",
1344a7dea167SDimitry Andric                    "get_image_channel_order"] in {
1345fe6060f1SDimitry Andric      def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1346a7dea167SDimitry Andric    }
1347a7dea167SDimitry Andric  }
1348a7dea167SDimitry Andric  foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1349a7dea167SDimitry Andric                   Image2dArrayDepth] in {
1350fe6060f1SDimitry Andric    def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>], Attr.Const>;
1351a7dea167SDimitry Andric  }
1352fe6060f1SDimitry Andric  def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>], Attr.Const>;
1353a7dea167SDimitry Andric  foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1354a7dea167SDimitry Andric                   Image2dArrayDepth] in {
1355fe6060f1SDimitry Andric    def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1356a7dea167SDimitry Andric  }
1357fe6060f1SDimitry Andric  def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>], Attr.Const>;
1358a7dea167SDimitry Andric  foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1359fe6060f1SDimitry Andric    def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
13600b57cec5SDimitry Andric  }
13610b57cec5SDimitry Andric}
13620b57cec5SDimitry Andric
136304eeddc0SDimitry Andricdefm : ImageQuery<"RO">;
136404eeddc0SDimitry Andricdefm : ImageQuery<"WO">;
136504eeddc0SDimitry Andriclet Extension = FuncExtOpenCLCReadWriteImages in {
136604eeddc0SDimitry Andric  defm : ImageQuery<"RW">;
136704eeddc0SDimitry Andric}
136804eeddc0SDimitry Andric
1369a7dea167SDimitry Andric// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1370a7dea167SDimitry Andric// --- Table 8 ---
1371a7dea167SDimitry Andricforeach aQual = ["RO"] in {
1372a7dea167SDimitry Andric  foreach name = ["read_imageh"] in {
1373a7dea167SDimitry Andric    foreach coordTy = [Int, Float] in {
1374a7dea167SDimitry Andric      foreach imgTy = [Image2d, Image1dArray] in {
1375480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1376a7dea167SDimitry Andric      }
1377a7dea167SDimitry Andric      foreach imgTy = [Image3d, Image2dArray] in {
1378480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1379a7dea167SDimitry Andric      }
1380a7dea167SDimitry Andric      foreach imgTy = [Image1d] in {
1381480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
1382a7dea167SDimitry Andric      }
1383a7dea167SDimitry Andric    }
1384a7dea167SDimitry Andric  }
1385a7dea167SDimitry Andric}
1386a7dea167SDimitry Andric// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1387a7dea167SDimitry Andric// --- Table 9 ---
1388fe6060f1SDimitry Andriclet MinVersion = CL12 in {
138904eeddc0SDimitry Andric  multiclass ImageReadHalf<string aQual> {
1390a7dea167SDimitry Andric    foreach name = ["read_imageh"] in {
1391a7dea167SDimitry Andric      foreach imgTy = [Image2d, Image1dArray] in {
1392480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1393a7dea167SDimitry Andric      }
1394a7dea167SDimitry Andric      foreach imgTy = [Image3d, Image2dArray] in {
1395480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1396a7dea167SDimitry Andric      }
1397a7dea167SDimitry Andric      foreach imgTy = [Image1d, Image1dBuffer] in {
1398480093f4SDimitry Andric        def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1399a7dea167SDimitry Andric      }
1400a7dea167SDimitry Andric    }
1401a7dea167SDimitry Andric  }
140204eeddc0SDimitry Andric  defm : ImageReadHalf<"RO">;
140304eeddc0SDimitry Andric  let Extension = FuncExtOpenCLCReadWriteImages in {
140404eeddc0SDimitry Andric    defm : ImageReadHalf<"RW">;
140504eeddc0SDimitry Andric  }
1406fe6060f1SDimitry Andric}
1407a7dea167SDimitry Andric// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1408a7dea167SDimitry Andric// --- Table 10 ---
140904eeddc0SDimitry Andricmulticlass ImageWriteHalf<string aQual> {
1410a7dea167SDimitry Andric  foreach name = ["write_imageh"] in {
1411a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1412a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1413a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1414a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1415a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1416a7dea167SDimitry Andric    def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1417a7dea167SDimitry Andric  }
1418a7dea167SDimitry Andric}
14190b57cec5SDimitry Andric
142004eeddc0SDimitry Andricdefm : ImageWriteHalf<"WO">;
142104eeddc0SDimitry Andriclet Extension = FuncExtOpenCLCReadWriteImages in {
142204eeddc0SDimitry Andric  defm : ImageWriteHalf<"RW">;
142304eeddc0SDimitry Andric}
142404eeddc0SDimitry Andric
142504eeddc0SDimitry Andric
14260b57cec5SDimitry Andric
1427480093f4SDimitry Andric//--------------------------------------------------------------------
1428480093f4SDimitry Andric// OpenCL v2.0 s6.13.15 - Work-group Functions
1429480093f4SDimitry Andric// --- Table 26 ---
1430349cc55cSDimitry Andriclet Extension = FuncExtOpenCLCWGCollectiveFunctions in {
1431480093f4SDimitry Andric  foreach name = ["work_group_all", "work_group_any"] in {
1432480093f4SDimitry Andric    def : Builtin<name, [Int, Int], Attr.Convergent>;
1433480093f4SDimitry Andric  }
1434480093f4SDimitry Andric  foreach name = ["work_group_broadcast"] in {
1435480093f4SDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1436480093f4SDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1437480093f4SDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1438480093f4SDimitry Andric  }
1439480093f4SDimitry Andric  foreach op = ["add", "min", "max"] in {
1440480093f4SDimitry Andric    foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1441480093f4SDimitry Andric                    "work_group_scan_inclusive_"] in {
1442480093f4SDimitry Andric      def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1443480093f4SDimitry Andric    }
1444480093f4SDimitry Andric  }
1445480093f4SDimitry Andric}
1446480093f4SDimitry Andric
1447480093f4SDimitry Andric
14485ffd83dbSDimitry Andric//--------------------------------------------------------------------
14495ffd83dbSDimitry Andric// OpenCL2.0 : 6.13.16 : Pipe Functions
14505ffd83dbSDimitry Andric// --- Table 27 ---
1451*0fca6ea1SDimitry Andric// Defined in Builtins.td
14525ffd83dbSDimitry Andric
14535ffd83dbSDimitry Andric// --- Table 28 ---
1454*0fca6ea1SDimitry Andric// Builtins taking pipe arguments are defined in Builtins.td
1455349cc55cSDimitry Andriclet Extension = FuncExtOpenCLCPipes in {
14565ffd83dbSDimitry Andric  def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
1457349cc55cSDimitry Andric}
14585ffd83dbSDimitry Andric
14595ffd83dbSDimitry Andric// --- Table 29 ---
1460*0fca6ea1SDimitry Andric// Defined in Builtins.td
14615ffd83dbSDimitry Andric
14625ffd83dbSDimitry Andric
14635ffd83dbSDimitry Andric//--------------------------------------------------------------------
14645ffd83dbSDimitry Andric// OpenCL2.0 : 6.13.17 : Enqueuing Kernels
14655ffd83dbSDimitry Andric// --- Table 30 ---
1466*0fca6ea1SDimitry Andric// Defined in Builtins.td
14675ffd83dbSDimitry Andric
14685ffd83dbSDimitry Andric// --- Table 32 ---
1469*0fca6ea1SDimitry Andric// Defined in Builtins.td
14705ffd83dbSDimitry Andric
14715ffd83dbSDimitry Andric// --- Table 33 ---
147281ad6265SDimitry Andriclet Extension = FuncExtOpenCLCDeviceEnqueue in {
14735ffd83dbSDimitry Andric  def : Builtin<"enqueue_marker",
14745ffd83dbSDimitry Andric      [Int, Queue, UInt, PointerType<ConstType<ClkEvent>, GenericAS>, PointerType<ClkEvent, GenericAS>]>;
14755ffd83dbSDimitry Andric
14765ffd83dbSDimitry Andric  // --- Table 34 ---
14775ffd83dbSDimitry Andric  def : Builtin<"retain_event", [Void, ClkEvent]>;
14785ffd83dbSDimitry Andric  def : Builtin<"release_event", [Void, ClkEvent]>;
14795ffd83dbSDimitry Andric  def : Builtin<"create_user_event", [ClkEvent]>;
14805ffd83dbSDimitry Andric  def : Builtin<"is_valid_event", [Bool, ClkEvent]>;
14815ffd83dbSDimitry Andric  def : Builtin<"set_user_event_status", [Void, ClkEvent, Int]>;
1482fe6060f1SDimitry Andric  def : Builtin<"capture_event_profiling_info",
1483fe6060f1SDimitry Andric      [Void, ClkEvent, ClkProfilingInfo, PointerType<Void, GlobalAS>]>;
14845ffd83dbSDimitry Andric
14855ffd83dbSDimitry Andric  // --- Table 35 ---
14865ffd83dbSDimitry Andric  def : Builtin<"get_default_queue", [Queue]>;
1487fe6060f1SDimitry Andric
1488fe6060f1SDimitry Andric  def : Builtin<"ndrange_1D", [NDRange, Size]>;
1489fe6060f1SDimitry Andric  def : Builtin<"ndrange_1D", [NDRange, Size, Size]>;
1490fe6060f1SDimitry Andric  def : Builtin<"ndrange_1D", [NDRange, Size, Size, Size]>;
1491fe6060f1SDimitry Andric  def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>]>;
1492fe6060f1SDimitry Andric  def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
1493fe6060f1SDimitry Andric                                        PointerType<ConstType<Size>, PrivateAS>]>;
1494fe6060f1SDimitry Andric  def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
1495fe6060f1SDimitry Andric                                        PointerType<ConstType<Size>, PrivateAS>,
1496fe6060f1SDimitry Andric                                        PointerType<ConstType<Size>, PrivateAS>]>;
1497fe6060f1SDimitry Andric  def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>]>;
1498fe6060f1SDimitry Andric  def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
1499fe6060f1SDimitry Andric                                        PointerType<ConstType<Size>, PrivateAS>]>;
1500fe6060f1SDimitry Andric  def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>,
1501fe6060f1SDimitry Andric                                        PointerType<ConstType<Size>, PrivateAS>,
1502fe6060f1SDimitry Andric                                        PointerType<ConstType<Size>, PrivateAS>]>;
1503fe6060f1SDimitry Andric}
15045ffd83dbSDimitry Andric
1505480093f4SDimitry Andric
1506480093f4SDimitry Andric//--------------------------------------------------------------------
1507480093f4SDimitry Andric// End of the builtin functions defined in the OpenCL C specification.
1508480093f4SDimitry Andric// Builtin functions defined in the OpenCL C Extension are below.
1509480093f4SDimitry Andric//--------------------------------------------------------------------
1510480093f4SDimitry Andric
1511480093f4SDimitry Andric
1512480093f4SDimitry Andric// OpenCL Extension v2.0 s9.18 - Mipmaps
1513480093f4SDimitry Andriclet Extension = FuncExtKhrMipmapImage in {
1514480093f4SDimitry Andric  // Added to section 6.13.14.2.
1515480093f4SDimitry Andric  foreach aQual = ["RO"] in {
1516480093f4SDimitry Andric    foreach imgTy = [Image2d] in {
1517480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1518480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1519480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1520480093f4SDimitry Andric      }
1521480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1522480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1523480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1524480093f4SDimitry Andric      }
1525480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1526480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1527480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1528480093f4SDimitry Andric      }
1529480093f4SDimitry Andric    }
1530480093f4SDimitry Andric    foreach imgTy = [Image2dDepth] in {
1531480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1532480093f4SDimitry Andric        def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1533480093f4SDimitry Andric        def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1534480093f4SDimitry Andric      }
1535480093f4SDimitry Andric    }
1536480093f4SDimitry Andric    foreach imgTy = [Image1d] in {
1537480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1538480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1539480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1540480093f4SDimitry Andric      }
1541480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1542480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1543480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1544480093f4SDimitry Andric      }
1545480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1546480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1547480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1548480093f4SDimitry Andric      }
1549480093f4SDimitry Andric    }
1550480093f4SDimitry Andric    foreach imgTy = [Image3d] in {
1551480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1552480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1553480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1554480093f4SDimitry Andric      }
1555480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1556480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1557fe6060f1SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1558480093f4SDimitry Andric      }
1559480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1560480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1561fe6060f1SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1562480093f4SDimitry Andric      }
1563480093f4SDimitry Andric    }
1564480093f4SDimitry Andric    foreach imgTy = [Image1dArray] in {
1565480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1566480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1567480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1568480093f4SDimitry Andric      }
1569480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1570480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1571480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1572480093f4SDimitry Andric      }
1573480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1574480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1575480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1576480093f4SDimitry Andric      }
1577480093f4SDimitry Andric    }
1578480093f4SDimitry Andric    foreach imgTy = [Image2dArray] in {
1579480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1580480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1581480093f4SDimitry Andric        def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1582480093f4SDimitry Andric      }
1583480093f4SDimitry Andric      foreach name = ["read_imagei"] in {
1584480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1585480093f4SDimitry Andric        def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1586480093f4SDimitry Andric      }
1587480093f4SDimitry Andric      foreach name = ["read_imageui"] in {
1588480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1589480093f4SDimitry Andric        def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1590480093f4SDimitry Andric      }
1591480093f4SDimitry Andric    }
1592480093f4SDimitry Andric    foreach imgTy = [Image2dArrayDepth] in {
1593480093f4SDimitry Andric      foreach name = ["read_imagef"] in {
1594fe6060f1SDimitry Andric        def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1595fe6060f1SDimitry Andric        def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1596480093f4SDimitry Andric      }
1597480093f4SDimitry Andric    }
1598480093f4SDimitry Andric  }
159904eeddc0SDimitry Andric}
160004eeddc0SDimitry Andric
16015ffd83dbSDimitry Andric// Added to section 6.13.14.5
160204eeddc0SDimitry Andricmulticlass ImageQueryNumMipLevels<string aQual> {
16035ffd83dbSDimitry Andric  foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
16045ffd83dbSDimitry Andric    def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
16055ffd83dbSDimitry Andric  }
16065ffd83dbSDimitry Andric}
160704eeddc0SDimitry Andric
160804eeddc0SDimitry Andriclet Extension = FuncExtKhrMipmapImage in {
160904eeddc0SDimitry Andric  defm : ImageQueryNumMipLevels<"RO">;
161004eeddc0SDimitry Andric  defm : ImageQueryNumMipLevels<"WO">;
161104eeddc0SDimitry Andric  defm : ImageQueryNumMipLevels<"RW">;
16125ffd83dbSDimitry Andric}
16135ffd83dbSDimitry Andric
16145ffd83dbSDimitry Andric// Write functions are enabled using a separate extension.
16155ffd83dbSDimitry Andriclet Extension = FuncExtKhrMipmapImageWrites in {
1616480093f4SDimitry Andric  // Added to section 6.13.14.4.
1617480093f4SDimitry Andric  foreach aQual = ["WO"] in {
1618480093f4SDimitry Andric    foreach imgTy = [Image2d] in {
1619480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1620480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1621480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
1622480093f4SDimitry Andric    }
1623480093f4SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
1624480093f4SDimitry Andric    foreach imgTy = [Image1d] in {
1625480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1626480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1627480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
1628480093f4SDimitry Andric    }
1629480093f4SDimitry Andric    foreach imgTy = [Image1dArray] in {
1630480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1631480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1632480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
1633480093f4SDimitry Andric    }
1634480093f4SDimitry Andric    foreach imgTy = [Image2dArray] in {
1635480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1636480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1637480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1638480093f4SDimitry Andric    }
1639480093f4SDimitry Andric    def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
1640480093f4SDimitry Andric    foreach imgTy = [Image3d] in {
1641480093f4SDimitry Andric      def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1642480093f4SDimitry Andric      def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1643480093f4SDimitry Andric      def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1644480093f4SDimitry Andric    }
1645480093f4SDimitry Andric  }
1646480093f4SDimitry Andric}
1647480093f4SDimitry Andric
1648480093f4SDimitry Andric//--------------------------------------------------------------------
1649480093f4SDimitry Andric// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1650480093f4SDimitry Andric// --- Table 6.13.14.3 ---
165104eeddc0SDimitry Andricmulticlass ImageReadMsaa<string aQual> {
1652480093f4SDimitry Andric  foreach imgTy = [Image2dMsaa] in {
1653480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1654480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1655480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1656480093f4SDimitry Andric  }
1657480093f4SDimitry Andric  foreach imgTy = [Image2dArrayMsaa] in {
1658480093f4SDimitry Andric    def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1659480093f4SDimitry Andric    def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1660480093f4SDimitry Andric    def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1661480093f4SDimitry Andric  }
1662480093f4SDimitry Andric  foreach name = ["read_imagef"] in {
1663480093f4SDimitry Andric    def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1664480093f4SDimitry Andric    def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1665480093f4SDimitry Andric  }
1666480093f4SDimitry Andric}
1667480093f4SDimitry Andric
1668480093f4SDimitry Andric// --- Table 6.13.14.5 ---
166904eeddc0SDimitry Andricmulticlass ImageQueryMsaa<string aQual> {
1670480093f4SDimitry Andric  foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1671480093f4SDimitry Andric    foreach name = ["get_image_width", "get_image_height",
1672480093f4SDimitry Andric                    "get_image_channel_data_type", "get_image_channel_order",
1673480093f4SDimitry Andric                    "get_image_num_samples"] in {
1674480093f4SDimitry Andric      def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1675480093f4SDimitry Andric    }
1676480093f4SDimitry Andric    def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1677480093f4SDimitry Andric  }
16785ffd83dbSDimitry Andric  foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in {
16795ffd83dbSDimitry Andric    def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
16805ffd83dbSDimitry Andric  }
16815ffd83dbSDimitry Andric}
168204eeddc0SDimitry Andric
168304eeddc0SDimitry Andriclet Extension = FuncExtKhrGlMsaaSharing in {
168404eeddc0SDimitry Andric  defm : ImageReadMsaa<"RO">;
168504eeddc0SDimitry Andric  defm : ImageQueryMsaa<"RO">;
168604eeddc0SDimitry Andric  defm : ImageQueryMsaa<"WO">;
168704eeddc0SDimitry Andric  defm : ImageReadMsaa<"RW">;
168804eeddc0SDimitry Andric  defm : ImageQueryMsaa<"RW">;
16895ffd83dbSDimitry Andric}
16905ffd83dbSDimitry Andric
16915ffd83dbSDimitry Andric//--------------------------------------------------------------------
16925ffd83dbSDimitry Andric// OpenCL Extension v2.0 s28 - Subgroups
16935ffd83dbSDimitry Andric// --- Table 28.2.1 ---
16945ffd83dbSDimitry Andriclet Extension = FuncExtKhrSubgroups in {
16955ffd83dbSDimitry Andric  foreach name = ["get_sub_group_size", "get_max_sub_group_size",
16965ffd83dbSDimitry Andric                  "get_num_sub_groups", "get_sub_group_id",
16975ffd83dbSDimitry Andric                  "get_sub_group_local_id"] in {
16985ffd83dbSDimitry Andric    def : Builtin<name, [UInt]>;
16995ffd83dbSDimitry Andric  }
17005ffd83dbSDimitry Andric  let MinVersion = CL20 in {
17015ffd83dbSDimitry Andric    foreach name = ["get_enqueued_num_sub_groups"] in {
17025ffd83dbSDimitry Andric      def : Builtin<name, [UInt]>;
17035ffd83dbSDimitry Andric    }
17045ffd83dbSDimitry Andric  }
17055ffd83dbSDimitry Andric}
17065ffd83dbSDimitry Andric
17075ffd83dbSDimitry Andric// --- Table 28.2.2 ---
1708fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroups in {
1709fe6060f1SDimitry Andric  def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
171081ad6265SDimitry Andric  let MinVersion = CL20 in {
1711fe6060f1SDimitry Andric    def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
1712fe6060f1SDimitry Andric  }
171381ad6265SDimitry Andric}
17145ffd83dbSDimitry Andric
17155ffd83dbSDimitry Andric// --- Table 28.2.4 ---
17165ffd83dbSDimitry Andriclet Extension = FuncExtKhrSubgroups in {
17175ffd83dbSDimitry Andric  foreach name = ["sub_group_all", "sub_group_any"] in {
17185ffd83dbSDimitry Andric    def : Builtin<name, [Int, Int], Attr.Convergent>;
17195ffd83dbSDimitry Andric  }
17205ffd83dbSDimitry Andric  foreach name = ["sub_group_broadcast"] in {
17215ffd83dbSDimitry Andric    def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, UInt], Attr.Convergent>;
17225ffd83dbSDimitry Andric  }
17235ffd83dbSDimitry Andric  foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
17245ffd83dbSDimitry Andric                  "sub_group_scan_inclusive_"] in {
17255ffd83dbSDimitry Andric    foreach op = ["add", "min", "max"] in {
17265ffd83dbSDimitry Andric      def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
17275ffd83dbSDimitry Andric    }
17285ffd83dbSDimitry Andric  }
17295ffd83dbSDimitry Andric}
17305ffd83dbSDimitry Andric
1731fe6060f1SDimitry Andric// OpenCL Extension v3.0 s38 - Extended Subgroup Functions
1732fe6060f1SDimitry Andric
1733fe6060f1SDimitry Andric// Section 38.4.1 - cl_khr_subgroup_extended_types
1734fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupExtendedTypes in {
1735fe6060f1SDimitry Andric  // For sub_group_broadcast, add scalar char, uchar, short, and ushort support,
1736fe6060f1SDimitry Andric  def : Builtin<"sub_group_broadcast", [CharShortGenType1, CharShortGenType1, UInt], Attr.Convergent>;
1737fe6060f1SDimitry Andric  // gentype may additionally be one of the supported built-in vector data types.
1738fe6060f1SDimitry Andric  def : Builtin<"sub_group_broadcast", [AGenTypeNNoScalar, AGenTypeNNoScalar, UInt], Attr.Convergent>;
1739fe6060f1SDimitry Andric
1740fe6060f1SDimitry Andric  foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_",
1741fe6060f1SDimitry Andric                  "sub_group_scan_inclusive_"] in {
1742fe6060f1SDimitry Andric    foreach op = ["add", "min", "max"] in {
1743fe6060f1SDimitry Andric      def : Builtin<name # op, [CharShortGenType1, CharShortGenType1], Attr.Convergent>;
1744fe6060f1SDimitry Andric    }
1745fe6060f1SDimitry Andric  }
1746fe6060f1SDimitry Andric}
1747fe6060f1SDimitry Andric
1748fe6060f1SDimitry Andric// Section 38.5.1 - cl_khr_subgroup_non_uniform_vote
1749fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupNonUniformVote in {
1750fe6060f1SDimitry Andric  def : Builtin<"sub_group_elect", [Int]>;
1751fe6060f1SDimitry Andric  def : Builtin<"sub_group_non_uniform_all", [Int, Int]>;
1752fe6060f1SDimitry Andric  def : Builtin<"sub_group_non_uniform_any", [Int, Int]>;
1753fe6060f1SDimitry Andric  def : Builtin<"sub_group_non_uniform_all_equal", [Int, AGenType1]>;
1754fe6060f1SDimitry Andric}
1755fe6060f1SDimitry Andric
1756fe6060f1SDimitry Andric// Section 38.6.1 - cl_khr_subgroup_ballot
1757fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupBallot in {
1758fe6060f1SDimitry Andric  def : Builtin<"sub_group_non_uniform_broadcast", [AGenTypeN, AGenTypeN, UInt]>;
1759fe6060f1SDimitry Andric  def : Builtin<"sub_group_broadcast_first", [AGenType1, AGenType1]>;
1760fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot", [VectorType<UInt, 4>, Int]>;
1761fe6060f1SDimitry Andric  def : Builtin<"sub_group_inverse_ballot", [Int, VectorType<UInt, 4>], Attr.Const>;
1762fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot_bit_extract", [Int, VectorType<UInt, 4>, UInt], Attr.Const>;
1763fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot_bit_count", [UInt, VectorType<UInt, 4>], Attr.Const>;
1764fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot_inclusive_scan", [UInt, VectorType<UInt, 4>]>;
1765fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot_exclusive_scan", [UInt, VectorType<UInt, 4>]>;
1766fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot_find_lsb", [UInt, VectorType<UInt, 4>]>;
1767fe6060f1SDimitry Andric  def : Builtin<"sub_group_ballot_find_msb", [UInt, VectorType<UInt, 4>]>;
1768fe6060f1SDimitry Andric
1769fe6060f1SDimitry Andric  foreach op = ["eq", "ge", "gt", "le", "lt"] in {
1770fe6060f1SDimitry Andric    def : Builtin<"get_sub_group_" # op # "_mask", [VectorType<UInt, 4>], Attr.Const>;
1771fe6060f1SDimitry Andric  }
1772fe6060f1SDimitry Andric}
1773fe6060f1SDimitry Andric
1774fe6060f1SDimitry Andric// Section 38.7.1 - cl_khr_subgroup_non_uniform_arithmetic
1775fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupNonUniformArithmetic in {
1776fe6060f1SDimitry Andric  foreach name = ["reduce_", "scan_exclusive_", "scan_inclusive_"] in {
1777fe6060f1SDimitry Andric    foreach op = ["add", "min", "max", "mul"] in {
1778fe6060f1SDimitry Andric      def : Builtin<"sub_group_non_uniform_" # name # op, [AGenType1, AGenType1]>;
1779fe6060f1SDimitry Andric    }
1780fe6060f1SDimitry Andric    foreach op = ["and", "or", "xor"] in {
1781fe6060f1SDimitry Andric      def : Builtin<"sub_group_non_uniform_" # name # op, [AIGenType1, AIGenType1]>;
1782fe6060f1SDimitry Andric    }
1783fe6060f1SDimitry Andric    foreach op = ["and", "or", "xor"] in {
1784fe6060f1SDimitry Andric      def : Builtin<"sub_group_non_uniform_" # name # "logical_" # op, [Int, Int]>;
1785fe6060f1SDimitry Andric    }
1786fe6060f1SDimitry Andric  }
1787fe6060f1SDimitry Andric}
1788fe6060f1SDimitry Andric
1789fe6060f1SDimitry Andric// Section 38.8.1 - cl_khr_subgroup_shuffle
1790fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupShuffle in {
1791fe6060f1SDimitry Andric  def : Builtin<"sub_group_shuffle", [AGenType1, AGenType1, UInt]>;
1792fe6060f1SDimitry Andric  def : Builtin<"sub_group_shuffle_xor", [AGenType1, AGenType1, UInt]>;
1793fe6060f1SDimitry Andric}
1794fe6060f1SDimitry Andric
1795fe6060f1SDimitry Andric// Section 38.9.1 - cl_khr_subgroup_shuffle_relative
1796fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupShuffleRelative in {
1797fe6060f1SDimitry Andric  def : Builtin<"sub_group_shuffle_up", [AGenType1, AGenType1, UInt]>;
1798fe6060f1SDimitry Andric  def : Builtin<"sub_group_shuffle_down", [AGenType1, AGenType1, UInt]>;
1799fe6060f1SDimitry Andric}
1800fe6060f1SDimitry Andric
1801fe6060f1SDimitry Andric// Section 38.10.1 - cl_khr_subgroup_clustered_reduce
1802fe6060f1SDimitry Andriclet Extension = FuncExtKhrSubgroupClusteredReduce in {
1803fe6060f1SDimitry Andric  foreach op = ["add", "min", "max", "mul"] in {
1804fe6060f1SDimitry Andric    def : Builtin<"sub_group_clustered_reduce_" # op, [AGenType1, AGenType1, UInt]>;
1805fe6060f1SDimitry Andric  }
1806fe6060f1SDimitry Andric  foreach op = ["and", "or", "xor"] in {
1807fe6060f1SDimitry Andric    def : Builtin<"sub_group_clustered_reduce_" # op, [AIGenType1, AIGenType1, UInt]>;
1808fe6060f1SDimitry Andric  }
1809fe6060f1SDimitry Andric  foreach op = ["and", "or", "xor"] in {
1810fe6060f1SDimitry Andric    def : Builtin<"sub_group_clustered_reduce_logical_" # op, [Int, Int, UInt]>;
1811fe6060f1SDimitry Andric  }
1812fe6060f1SDimitry Andric}
1813fe6060f1SDimitry Andric
1814fe6060f1SDimitry Andric// Section 40.3.1 - cl_khr_extended_bit_ops
1815fe6060f1SDimitry Andriclet Extension = FuncExtKhrExtendedBitOps in {
1816fe6060f1SDimitry Andric  def : Builtin<"bitfield_insert", [AIGenTypeN, AIGenTypeN, AIGenTypeN, UInt, UInt], Attr.Const>;
1817fe6060f1SDimitry Andric  def : Builtin<"bitfield_extract_signed", [SGenTypeN, SGenTypeN, UInt, UInt], Attr.Const>;
1818fe6060f1SDimitry Andric  def : Builtin<"bitfield_extract_signed", [SGenTypeN, UGenTypeN, UInt, UInt], Attr.Const>;
1819fe6060f1SDimitry Andric  def : Builtin<"bitfield_extract_unsigned", [UGenTypeN, SGenTypeN, UInt, UInt], Attr.Const>;
1820fe6060f1SDimitry Andric  def : Builtin<"bitfield_extract_unsigned", [UGenTypeN, UGenTypeN, UInt, UInt], Attr.Const>;
1821fe6060f1SDimitry Andric  def : Builtin<"bit_reverse", [AIGenTypeN, AIGenTypeN], Attr.Const>;
1822fe6060f1SDimitry Andric}
1823fe6060f1SDimitry Andric
1824fe6060f1SDimitry Andric// Section 42.3 - cl_khr_integer_dot_product
1825fe6060f1SDimitry Andriclet Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
1826fe6060f1SDimitry Andric  def : Builtin<"dot", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>], Attr.Const>;
1827fe6060f1SDimitry Andric  def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<Char, 4>], Attr.Const>;
1828fe6060f1SDimitry Andric  def : Builtin<"dot", [Int, VectorType<UChar, 4>, VectorType<Char, 4>], Attr.Const>;
1829fe6060f1SDimitry Andric  def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<UChar, 4>], Attr.Const>;
1830fe6060f1SDimitry Andric
1831fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt], Attr.Const>;
1832fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int], Attr.Const>;
1833fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat", [Int, VectorType<UChar, 4>, VectorType<Char, 4>, Int], Attr.Const>;
1834fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<UChar, 4>, Int], Attr.Const>;
1835fe6060f1SDimitry Andric}
1836fe6060f1SDimitry Andric
1837fe6060f1SDimitry Andriclet Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
1838fe6060f1SDimitry Andric  def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
1839fe6060f1SDimitry Andric  def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
1840fe6060f1SDimitry Andric  def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
1841fe6060f1SDimitry Andric  def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
1842fe6060f1SDimitry Andric
1843fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], Attr.Const>;
1844fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], Attr.Const>;
1845fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], Attr.Const>;
1846fe6060f1SDimitry Andric  def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], Attr.Const>;
1847fe6060f1SDimitry Andric}
1848fe6060f1SDimitry Andric
184981ad6265SDimitry Andric// Section 48.3 - cl_khr_subgroup_rotate
185081ad6265SDimitry Andriclet Extension = FunctionExtension<"cl_khr_subgroup_rotate"> in {
185181ad6265SDimitry Andric  def : Builtin<"sub_group_rotate", [AGenType1, AGenType1, Int], Attr.Convergent>;
185281ad6265SDimitry Andric  def : Builtin<"sub_group_clustered_rotate", [AGenType1, AGenType1, Int, UInt], Attr.Convergent>;
185381ad6265SDimitry Andric}
185481ad6265SDimitry Andric
1855*0fca6ea1SDimitry Andric// cl_khr_kernel_clock
1856*0fca6ea1SDimitry Andriclet Extension = FunctionExtension<"cl_khr_kernel_clock __opencl_c_kernel_clock_scope_device"> in {
1857*0fca6ea1SDimitry Andric  def : Builtin<"clock_read_device", [ULong]>;
1858*0fca6ea1SDimitry Andric  def : Builtin<"clock_read_hilo_device", [VectorType<UInt, 2>]>;
1859*0fca6ea1SDimitry Andric}
1860*0fca6ea1SDimitry Andriclet Extension = FunctionExtension<"cl_khr_kernel_clock __opencl_c_kernel_clock_scope_work_group"> in {
1861*0fca6ea1SDimitry Andric  def : Builtin<"clock_read_work_group", [ULong]>;
1862*0fca6ea1SDimitry Andric  def : Builtin<"clock_read_hilo_work_group", [VectorType<UInt, 2>]>;
1863*0fca6ea1SDimitry Andric}
1864*0fca6ea1SDimitry Andriclet Extension = FunctionExtension<"cl_khr_kernel_clock __opencl_c_kernel_clock_scope_sub_group"> in {
1865*0fca6ea1SDimitry Andric  def : Builtin<"clock_read_sub_group", [ULong]>;
1866*0fca6ea1SDimitry Andric  def : Builtin<"clock_read_hilo_sub_group", [VectorType<UInt, 2>]>;
1867*0fca6ea1SDimitry Andric}
1868*0fca6ea1SDimitry Andric
18695ffd83dbSDimitry Andric//--------------------------------------------------------------------
18705ffd83dbSDimitry Andric// Arm extensions.
18715ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductInt8 in {
18725ffd83dbSDimitry Andric  foreach name = ["arm_dot"] in {
18735ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>;
18745ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>]>;
18755ffd83dbSDimitry Andric  }
18765ffd83dbSDimitry Andric}
18775ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductAccumulateInt8 in {
18785ffd83dbSDimitry Andric  foreach name = ["arm_dot_acc"] in {
18795ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
18805ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
18815ffd83dbSDimitry Andric  }
18825ffd83dbSDimitry Andric}
18835ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductAccumulateInt16 in {
18845ffd83dbSDimitry Andric  foreach name = ["arm_dot_acc"] in {
18855ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UShort, 2>, VectorType<UShort, 2>, UInt]>;
18865ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Short, 2>, VectorType<Short, 2>, Int]>;
18875ffd83dbSDimitry Andric  }
18885ffd83dbSDimitry Andric}
18895ffd83dbSDimitry Andriclet Extension = ArmIntegerDotProductAccumulateSaturateInt8 in {
18905ffd83dbSDimitry Andric  foreach name = ["arm_dot_acc_sat"] in {
18915ffd83dbSDimitry Andric    def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
18925ffd83dbSDimitry Andric    def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1893480093f4SDimitry Andric  }
1894480093f4SDimitry Andric}
1895