1 //==--- OpenCLBuiltins.td - OpenCL builtin declarations -------------------===//
3 // The LLVM Compiler Infrastructure
5 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6 // See https://llvm.org/LICENSE.txt for license information.
7 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9 //===----------------------------------------------------------------------===//
11 // This file contains TableGen definitions for OpenCL builtin function
12 // declarations. In case of an unresolved function name in OpenCL, Clang will
13 // check for a function described in this file when -fdeclare-opencl-builtins
16 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
19 // Definitions of miscellaneous basic entities.
20 //===----------------------------------------------------------------------===//
22 class Version<int _Version> {
25 def CLAll : Version< 0>;
26 def CL10 : Version<100>;
27 def CL11 : Version<110>;
28 def CL12 : Version<120>;
29 def CL20 : Version<200>;
32 // Pointer types need to be assigned an address space.
33 class AddressSpace<string _AS> {
36 def DefaultAS : AddressSpace<"clang::LangAS::Default">;
37 def PrivateAS : AddressSpace<"clang::LangAS::opencl_private">;
38 def GlobalAS : AddressSpace<"clang::LangAS::opencl_global">;
39 def ConstantAS : AddressSpace<"clang::LangAS::opencl_constant">;
40 def LocalAS : AddressSpace<"clang::LangAS::opencl_local">;
41 def GenericAS : AddressSpace<"clang::LangAS::opencl_generic">;
44 // Qualified Type. These map to ASTContext::QualType.
45 class QualType<string _Name, bit _IsAbstract=0> {
46 // Name of the field or function in a clang::ASTContext
47 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
49 // Some QualTypes in this file represent an abstract type for which there is
50 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
51 // without access qualifiers.
52 bit IsAbstract = _IsAbstract;
56 class IntList<string _Name, list<int> _List> {
58 list<int> List = _List;
61 //===----------------------------------------------------------------------===//
62 // OpenCL C classes for types
63 //===----------------------------------------------------------------------===//
64 // OpenCL C basic data types (int, float, image2d_t, ...).
65 // Its child classes can represent concrete types (e.g. VectorType) or
66 // abstract types (e.g. GenType).
67 class Type<string _Name, QualType _QTName> {
70 // QualType associated with this type.
71 QualType QTName = _QTName;
72 // Size of the vector (if applicable).
78 // "volatile" qualifier.
80 // Access qualifier. Must be one of ("RO", "WO", "RW").
81 string AccessQualifier = "";
83 string AddrSpace = DefaultAS.Name;
86 // OpenCL vector types (e.g. int2, int3, int16, float8, ...).
87 class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
88 let VecWidth = _VecWidth;
89 let AccessQualifier = "";
91 let IsPointer = _Ty.IsPointer;
92 let IsConst = _Ty.IsConst;
93 let IsVolatile = _Ty.IsVolatile;
94 let AddrSpace = _Ty.AddrSpace;
97 // OpenCL pointer types (e.g. int*, float*, ...).
98 class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
99 Type<_Ty.Name, _Ty.QTName> {
100 let AddrSpace = _AS.Name;
102 let VecWidth = _Ty.VecWidth;
104 let IsConst = _Ty.IsConst;
105 let IsVolatile = _Ty.IsVolatile;
106 let AccessQualifier = _Ty.AccessQualifier;
109 // OpenCL const types (e.g. const int).
110 class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
113 let VecWidth = _Ty.VecWidth;
114 let IsPointer = _Ty.IsPointer;
115 let IsVolatile = _Ty.IsVolatile;
116 let AccessQualifier = _Ty.AccessQualifier;
117 let AddrSpace = _Ty.AddrSpace;
120 // OpenCL volatile types (e.g. volatile int).
121 class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
124 let VecWidth = _Ty.VecWidth;
125 let IsPointer = _Ty.IsPointer;
126 let IsConst = _Ty.IsConst;
127 let AccessQualifier = _Ty.AccessQualifier;
128 let AddrSpace = _Ty.AddrSpace;
131 // OpenCL image types (e.g. image2d).
132 class ImageType<Type _Ty, string _AccessQualifier> :
133 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
135 let AccessQualifier = _AccessQualifier;
137 let IsPointer = _Ty.IsPointer;
138 let IsConst = _Ty.IsConst;
139 let IsVolatile = _Ty.IsVolatile;
140 let AddrSpace = _Ty.AddrSpace;
144 class TypeList<string _Name, list<Type> _Type> {
146 list<Type> List = _Type;
149 // A GenericType is an abstract type that defines a set of types as a
150 // combination of Types and vector sizes.
152 // For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
153 // represents <int, int2, int4, float, float2, float4>.
155 // Some rules apply when using multiple GenericType arguments in a declaration:
156 // 1. The number of vector sizes must be equal or 1 for all gentypes in a
158 // 2. The number of Types must be equal or 1 for all gentypes in a
160 // 3. Generic types are combined by iterating over all generic types at once.
161 // For example, for the following GenericTypes
162 // GenT1 = GenericType<half, [1, 2]> and
163 // GenT2 = GenericType<float, int, [1, 2]>
164 // A declaration f(GenT1, GenT2) results in the combinations
165 // f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
166 // 4. "sgentype" from the OpenCL specification is supported by specifying
167 // a single vector size.
168 // For example, for the following GenericTypes
169 // GenT = GenericType<half, int, [1, 2]> and
170 // SGenT = GenericType<half, int, [1]>
171 // A declaration f(GenT, SGenT) results in the combinations
172 // f(half, half), f(half2, half), f(int, int), f(int2, int) .
173 class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
174 Type<_Ty, QualType<"null", 1>> {
175 // Possible element types of the generic type.
176 TypeList TypeList = _TypeList;
177 // Possible vector sizes of the types in the TypeList.
178 IntList VectorList = _VectorList;
179 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
183 //===----------------------------------------------------------------------===//
184 // OpenCL C class for builtin functions
185 //===----------------------------------------------------------------------===//
186 class Builtin<string _Name, list<Type> _Signature> {
187 // Name of the builtin function
189 // List of types used by the function. The first one is the return type and
190 // the following are the arguments. The list must have at least one element
191 // (the return type).
192 list<Type> Signature = _Signature;
193 // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
194 string Extension = "";
195 // Version of OpenCL from which the function is available (e.g.: CL10).
196 // MinVersion is inclusive.
197 Version MinVersion = CL10;
198 // Version of OpenCL from which the function is not supported anymore.
199 // MaxVersion is exclusive.
200 // CLAll makes the function available for all versions.
201 Version MaxVersion = CLAll;
204 //===----------------------------------------------------------------------===//
205 // Definitions of OpenCL C types
206 //===----------------------------------------------------------------------===//
208 // OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
209 def Bool : Type<"bool", QualType<"BoolTy">>;
210 def Char : Type<"char", QualType<"CharTy">>;
211 def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
212 def Short : Type<"short", QualType<"ShortTy">>;
213 def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
214 def Int : Type<"int", QualType<"IntTy">>;
215 def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
216 def Long : Type<"long", QualType<"LongTy">>;
217 def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
218 def Float : Type<"float", QualType<"FloatTy">>;
219 def Double : Type<"double", QualType<"DoubleTy">>;
220 def Half : Type<"half", QualType<"HalfTy">>;
221 def Size : Type<"size_t", QualType<"getSizeType()">>;
222 def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
223 def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
224 def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
225 def Void : Type<"void_t", QualType<"VoidTy">>;
227 // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
228 // Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
230 // OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
231 // The image definitions are "abstract". They should not be used without
232 // specifying an access qualifier (RO/WO/RW).
233 def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>;
234 def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>;
235 def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>;
236 def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>;
237 def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>;
238 def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>;
239 def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>;
240 def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>;
241 def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>;
242 def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>;
243 def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>;
244 def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>;
246 def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>;
247 def Event : Type<"Event", QualType<"OCLEventTy">>;
249 //===----------------------------------------------------------------------===//
250 // Definitions of OpenCL gentype variants
251 //===----------------------------------------------------------------------===//
252 // The OpenCL specification often uses "gentype" in builtin function
253 // declarations to indicate that a builtin function is available with various
254 // argument and return types. The types represented by "gentype" vary between
255 // different parts of the specification. The following definitions capture
256 // the different type lists for gentypes in different parts of the
259 // Vector width lists.
260 def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
261 def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
262 def Vec1 : IntList<"Vec1", [1]>;
265 def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
266 def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
268 def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
270 // GenType definitions for multiple base types (e.g. all floating point types,
271 // or all integer types).
273 def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
274 def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
276 def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
277 def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
278 def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
280 def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
282 // GenType definitions for every single base type (e.g. fp32 only).
283 // Names are like: GenTypeFloatVecAndScalar.
284 foreach Type = [Char, UChar, Short, UShort,
285 Int, UInt, Long, ULong,
286 Float, Double, Half] in {
287 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
288 def "GenType" # Type # VecSizes :
289 GenericType<"GenType" # Type # VecSizes,
290 TypeList<"GL" # Type.Name, [Type]>,
296 //===----------------------------------------------------------------------===//
297 // Definitions of OpenCL builtin functions
298 //===----------------------------------------------------------------------===//
299 //--------------------------------------------------------------------
300 // OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
301 // OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
303 // Generate the convert_* builtins functions.
304 foreach RType = [Float, Double, Half, Char, UChar, Short,
305 UShort, Int, UInt, Long, ULong] in {
306 foreach IType = [Float, Double, Half, Char, UChar, Short,
307 UShort, Int, UInt, Long, ULong] in {
308 foreach sat = ["", "_sat"] in {
309 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
310 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType]>;
311 foreach v = [2, 3, 4, 8, 16] in {
312 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
313 [VectorType<RType, v>,
314 VectorType<IType, v>]>;
321 //--------------------------------------------------------------------
322 // OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
324 def : Builtin<"get_work_dim", [UInt]>;
325 foreach name = ["get_global_size", "get_global_id", "get_local_size",
326 "get_local_id", "get_num_groups", "get_group_id",
327 "get_global_offset"] in {
328 def : Builtin<name, [Size, UInt]>;
331 let MinVersion = CL20 in {
332 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
333 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
334 def : Builtin<name, [Size]>;
338 //--------------------------------------------------------------------
339 // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
340 // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s9.4.6, v2.0 s5.1.6 and 6.1.6 - Vector Data Load and Store Functions
342 // Variants for OpenCL versions below 2.0, using pointers to the global, local
343 // and private address spaces.
344 let MaxVersion = CL20 in {
345 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
346 foreach VSize = [2, 3, 4, 8, 16] in {
347 foreach name = ["vload" # VSize] in {
348 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
349 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
350 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
351 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
352 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
353 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
354 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
355 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
356 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
357 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
358 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
360 foreach name = ["vstore" # VSize] in {
361 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
362 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
363 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
364 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
365 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
366 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
367 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
368 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
369 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
370 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
371 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
373 foreach name = ["vloada_half" # VSize] in {
374 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
376 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
377 foreach name = ["vstorea_half" # VSize # rnd] in {
378 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
379 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
385 // Variants for OpenCL versions above 2.0, using pointers to the generic
387 let MinVersion = CL20 in {
388 foreach VSize = [2, 3, 4, 8, 16] in {
389 foreach name = ["vload" # VSize] in {
390 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
391 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
392 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
393 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
394 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
395 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
396 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
397 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
398 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
399 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
400 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
402 foreach name = ["vstore" # VSize] in {
403 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
404 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
405 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
406 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
407 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
408 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
409 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
410 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
411 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
412 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
413 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
415 foreach name = ["vloada_half" # VSize] in {
416 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
418 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
419 foreach name = ["vstorea_half" # VSize # rnd] in {
420 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
421 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
426 // Variants using pointers to the constant address space.
427 foreach VSize = [2, 3, 4, 8, 16] in {
428 foreach name = ["vload" # VSize] in {
429 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
430 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
431 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
432 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
433 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
434 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
435 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
436 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
437 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
438 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
439 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
441 foreach name = ["vloada_half" # VSize] in {
442 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
444 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
445 foreach name = ["vstorea_half" # VSize # rnd] in {
446 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
447 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
452 //--------------------------------------------------------------------
453 // 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
454 // OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
456 foreach name = ["async_work_group_copy"] in {
457 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
458 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
460 foreach name = ["async_work_group_strided_copy"] in {
461 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
462 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
464 foreach name = ["wait_group_events"] in {
465 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
467 foreach name = ["prefetch"] in {
468 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
471 //--------------------------------------------------------------------
472 // OpenCL v2.0 s6.13.11 - Atomics Functions.
473 // Functions that use memory_order and cl_mem_fence_flags enums are not
474 // declared here as the TableGen backend does not handle enums.
476 // OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers.
478 foreach Type = [Int, UInt] in {
479 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
480 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
482 foreach name = ["atom_inc", "atom_dec"] in {
483 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
485 foreach name = ["atom_cmpxchg"] in {
486 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
490 // OpenCL v1.2 s6.12.2: Math Functions
491 foreach name = ["acos", "acosh", "acospi",
492 "asin", "asinh", "asinpi",
493 "atan", "atanh", "atanpi"] in {
494 def : Builtin<name, [FGenTypeN, FGenTypeN]>;
497 foreach name = ["atan2", "atan2pi"] in {
498 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
501 foreach name = ["fmax", "fmin"] in {
502 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
503 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float]>;
504 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double]>;
505 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half]>;
508 // OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
509 foreach name = ["max", "min"] in {
510 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN]>;
511 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1]>;
514 //--------------------------------------------------------------------
515 // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
516 // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
517 // --- Table 22: Image Read Functions with Samplers ---
518 foreach imgTy = [Image1d] in {
519 foreach coordTy = [Int, Float] in {
520 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
521 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
522 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
525 foreach imgTy = [Image2d, Image1dArray] in {
526 foreach coordTy = [Int, Float] in {
527 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
528 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
529 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
532 foreach imgTy = [Image3d, Image2dArray] in {
533 foreach coordTy = [Int, Float] in {
534 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
535 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
536 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
539 foreach coordTy = [Int, Float] in {
540 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>]>;
541 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>]>;
544 // --- Table 23: Sampler-less Read Functions ---
545 foreach aQual = ["RO", "RW"] in {
546 foreach imgTy = [Image2d, Image1dArray] in {
547 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
548 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
549 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
551 foreach imgTy = [Image3d, Image2dArray] in {
552 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
553 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
554 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
556 foreach imgTy = [Image1d, Image1dBuffer] in {
557 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int]>;
558 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int]>;
559 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int]>;
561 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>]>;
562 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>]>;
565 // --- Table 24: Image Write Functions ---
566 foreach aQual = ["WO", "RW"] in {
567 foreach imgTy = [Image2d] in {
568 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
569 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
570 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
572 foreach imgTy = [Image2dArray] in {
573 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
574 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
575 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
577 foreach imgTy = [Image1d, Image1dBuffer] in {
578 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
579 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
580 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
582 foreach imgTy = [Image1dArray] in {
583 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
584 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
585 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
587 foreach imgTy = [Image3d] in {
588 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
589 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
590 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
592 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
593 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
596 // --- Table 25: Image Query Functions ---
597 foreach aQual = ["RO", "WO", "RW"] in {
598 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
599 Image1dArray, Image2dArray, Image2dDepth,
600 Image2dArrayDepth] in {
601 foreach name = ["get_image_width", "get_image_channel_data_type",
602 "get_image_channel_order"] in {
603 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
606 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
607 Image2dArrayDepth] in {
608 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
610 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
611 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
612 Image2dArrayDepth] in {
613 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
615 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
616 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
617 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
621 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
623 foreach aQual = ["RO"] in {
624 foreach name = ["read_imageh"] in {
625 foreach coordTy = [Int, Float] in {
626 foreach imgTy = [Image2d, Image1dArray] in {
627 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>]>;
629 foreach imgTy = [Image3d, Image2dArray] in {
630 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>]>;
632 foreach imgTy = [Image1d] in {
633 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy]>;
638 // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
640 foreach aQual = ["RO", "RW"] in {
641 foreach name = ["read_imageh"] in {
642 foreach imgTy = [Image2d, Image1dArray] in {
643 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
645 foreach imgTy = [Image3d, Image2dArray] in {
646 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
648 foreach imgTy = [Image1d, Image1dBuffer] in {
649 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int]>;
653 // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
655 foreach aQual = ["WO", "RW"] in {
656 foreach name = ["write_imageh"] in {
657 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
658 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
659 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
660 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
661 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
662 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
667 // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
668 let MinVersion = CL20 in {
669 let Extension = "cl_khr_subgroups" in {
670 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
671 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
672 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;