blob: f31cb26e2c17a26a0715108209d5ac42b056c653 [file] [log] [blame]
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001//==--- OpenCLBuiltins.td - OpenCL builtin declarations -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
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
8//
9//===----------------------------------------------------------------------===//
10//
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
14// is specified.
15//
16//===----------------------------------------------------------------------===//
17
18//===----------------------------------------------------------------------===//
19// Definitions of miscellaneous basic entities.
20//===----------------------------------------------------------------------===//
21// Versions of OpenCL
22class Version<int _Version> {
Sven van Haastregted69faa2019-09-19 13:41:51 +000023 int ID = _Version;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000024}
Sven van Haastregted69faa2019-09-19 13:41:51 +000025def CLAll : Version< 0>;
26def CL10 : Version<100>;
27def CL11 : Version<110>;
28def CL12 : Version<120>;
29def CL20 : Version<200>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000030
31// Address spaces
32// Pointer types need to be assigned an address space.
33class AddressSpace<string _AS> {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +000034 string Name = _AS;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000035}
Sven van Haastregt89fb9e82019-07-29 14:55:29 +000036def DefaultAS : AddressSpace<"clang::LangAS::Default">;
37def PrivateAS : AddressSpace<"clang::LangAS::opencl_private">;
38def GlobalAS : AddressSpace<"clang::LangAS::opencl_global">;
39def ConstantAS : AddressSpace<"clang::LangAS::opencl_constant">;
40def LocalAS : AddressSpace<"clang::LangAS::opencl_local">;
41def GenericAS : AddressSpace<"clang::LangAS::opencl_generic">;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000042
43
Sven van Haastregtb21a3652019-08-19 11:56:03 +000044// Qualified Type. These map to ASTContext::QualType.
45class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000046 // 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
48 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000049 // 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;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000053}
54
Sven van Haastregtb21a3652019-08-19 11:56:03 +000055// List of integers.
56class IntList<string _Name, list<int> _List> {
57 string Name = _Name;
58 list<int> List = _List;
59}
60
Sven van Haastregt79a222f2019-06-03 09:39:11 +000061//===----------------------------------------------------------------------===//
62// OpenCL C classes for types
63//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000064// OpenCL C basic data types (int, float, image2d_t, ...).
Sven van Haastregt47e95ff2019-09-17 13:32:56 +000065// Its child classes can represent concrete types (e.g. VectorType) or
66// abstract types (e.g. GenType).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000067class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000068 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000069 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000070 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000071 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000072 // Size of the vector (if applicable).
73 int VecWidth = 1;
74 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000075 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000076 // "const" qualifier.
77 bit IsConst = 0;
78 // "volatile" qualifier.
79 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000080 // Access qualifier. Must be one of ("RO", "WO", "RW").
81 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +000082 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000083 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000084}
85
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000086// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000087class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000088 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +000089 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000090 // Inherited fields
91 let IsPointer = _Ty.IsPointer;
92 let IsConst = _Ty.IsConst;
93 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000094 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000095}
96
Sven van Haastregtb21a3652019-08-19 11:56:03 +000097// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000098class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt79a222f2019-06-03 09:39:11 +000099 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000100 let AddrSpace = _AS.Name;
101 // Inherited fields
102 let VecWidth = _Ty.VecWidth;
103 let IsPointer = 1;
104 let IsConst = _Ty.IsConst;
105 let IsVolatile = _Ty.IsVolatile;
106 let AccessQualifier = _Ty.AccessQualifier;
107}
108
109// OpenCL const types (e.g. const int).
110class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
111 let IsConst = 1;
112 // Inherited fields
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;
118}
119
120// OpenCL volatile types (e.g. volatile int).
121class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
122 let IsVolatile = 1;
123 // Inherited fields
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;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000129}
130
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000131// OpenCL image types (e.g. image2d).
132class ImageType<Type _Ty, string _AccessQualifier> :
133 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
134 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000135 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000136 // Inherited fields
137 let IsPointer = _Ty.IsPointer;
138 let IsConst = _Ty.IsConst;
139 let IsVolatile = _Ty.IsVolatile;
140 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000141}
142
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000143// List of Types.
144class TypeList<string _Name, list<Type> _Type> {
145 string Name = _Name;
146 list<Type> List = _Type;
147}
148
149// A GenericType is an abstract type that defines a set of types as a
150// combination of Types and vector sizes.
151//
Sven van Haastregt47e95ff2019-09-17 13:32:56 +0000152// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
153// represents <int, int2, int4, float, float2, float4>.
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000154//
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
157// declaration.
158// 2. The number of Types must be equal or 1 for all gentypes in a
159// declaration.
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) .
173class 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.
180 let VecWidth = 0;
181}
182
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000183// Builtin function attributes.
184def Attr {
185 list<bit> None = [0, 0, 0];
186 list<bit> Pure = [1, 0, 0];
187 list<bit> Const = [0, 1, 0];
188 list<bit> Convergent = [0, 0, 1];
189}
190
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000191//===----------------------------------------------------------------------===//
192// OpenCL C class for builtin functions
193//===----------------------------------------------------------------------===//
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000194class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000195 // Name of the builtin function
196 string Name = _Name;
197 // List of types used by the function. The first one is the return type and
198 // the following are the arguments. The list must have at least one element
199 // (the return type).
200 list<Type> Signature = _Signature;
201 // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
202 string Extension = "";
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000203 // Function attribute __attribute__((pure))
204 bit IsPure = _Attributes[0];
205 // Function attribute __attribute__((const))
206 bit IsConst = _Attributes[1];
207 // Function attribute __attribute__((convergent))
208 bit IsConv = _Attributes[2];
Sven van Haastregted69faa2019-09-19 13:41:51 +0000209 // Version of OpenCL from which the function is available (e.g.: CL10).
210 // MinVersion is inclusive.
211 Version MinVersion = CL10;
212 // Version of OpenCL from which the function is not supported anymore.
213 // MaxVersion is exclusive.
214 // CLAll makes the function available for all versions.
215 Version MaxVersion = CLAll;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000216}
217
218//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000219// Definitions of OpenCL C types
220//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000221
222// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000223def Bool : Type<"bool", QualType<"BoolTy">>;
224def Char : Type<"char", QualType<"CharTy">>;
225def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
226def Short : Type<"short", QualType<"ShortTy">>;
227def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
228def Int : Type<"int", QualType<"IntTy">>;
229def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
230def Long : Type<"long", QualType<"LongTy">>;
231def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
232def Float : Type<"float", QualType<"FloatTy">>;
233def Double : Type<"double", QualType<"DoubleTy">>;
234def Half : Type<"half", QualType<"HalfTy">>;
235def Size : Type<"size_t", QualType<"getSizeType()">>;
236def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
237def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
238def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
239def Void : Type<"void_t", QualType<"VoidTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000240
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000241// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
242// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000243
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000244// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
245// The image definitions are "abstract". They should not be used without
246// specifying an access qualifier (RO/WO/RW).
247def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>;
248def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>;
249def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>;
250def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>;
251def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>;
252def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>;
253def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>;
254def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>;
255def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>;
256def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>;
257def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>;
258def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000259
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000260def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>;
261def Event : Type<"Event", QualType<"OCLEventTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000262
263//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000264// Definitions of OpenCL gentype variants
265//===----------------------------------------------------------------------===//
266// The OpenCL specification often uses "gentype" in builtin function
267// declarations to indicate that a builtin function is available with various
268// argument and return types. The types represented by "gentype" vary between
269// different parts of the specification. The following definitions capture
270// the different type lists for gentypes in different parts of the
271// specification.
272
273// Vector width lists.
274def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
275def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
276def Vec1 : IntList<"Vec1", [1]>;
277
278// Type lists.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000279def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000280def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
281
282def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
283
284// GenType definitions for multiple base types (e.g. all floating point types,
285// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000286// All types
287def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
288def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000289// All integer
290def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
291def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
292def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
293// Float
294def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
295
296// GenType definitions for every single base type (e.g. fp32 only).
297// Names are like: GenTypeFloatVecAndScalar.
298foreach Type = [Char, UChar, Short, UShort,
299 Int, UInt, Long, ULong,
300 Float, Double, Half] in {
301 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
302 def "GenType" # Type # VecSizes :
303 GenericType<"GenType" # Type # VecSizes,
304 TypeList<"GL" # Type.Name, [Type]>,
305 VecSizes>;
306 }
307}
308
309
310//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000311// Definitions of OpenCL builtin functions
312//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000313//--------------------------------------------------------------------
314// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
315// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
316
317// Generate the convert_* builtins functions.
318foreach RType = [Float, Double, Half, Char, UChar, Short,
319 UShort, Int, UInt, Long, ULong] in {
320 foreach IType = [Float, Double, Half, Char, UChar, Short,
321 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000322 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000323 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000324 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
325 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000326 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000327 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000328 [VectorType<RType, v>, VectorType<IType, v>],
329 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000330 }
331 }
332 }
333 }
334}
335
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000336//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000337// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
338// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000339def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000340foreach name = ["get_global_size", "get_global_id", "get_local_size",
341 "get_local_id", "get_num_groups", "get_group_id",
342 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000343 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000344}
345
346let MinVersion = CL20 in {
347 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
348 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
349 def : Builtin<name, [Size]>;
350 }
351}
352
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000353
Sven van Haastregted69faa2019-09-19 13:41:51 +0000354//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000355// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
356// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
357// --- Table 8 ---
358// --- 1 argument ---
359foreach name = ["acos", "acosh", "acospi",
360 "asin", "asinh", "asinpi",
361 "atan", "atanh", "atanpi",
362 "cbrt", "ceil",
363 "cos", "cosh", "cospi",
364 "erfc", "erf",
365 "exp", "exp2", "exp10", "expm1",
366 "fabs", "floor",
367 "log", "log2", "log10", "log1p", "logb",
368 "rint", "round", "rsqrt",
369 "sin", "sinh", "sinpi",
370 "sqrt",
371 "tan", "tanh", "tanpi",
372 "tgamma", "trunc",
373 "lgamma"] in {
374 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
375}
376foreach name = ["nan"] in {
377 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
378 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
379 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
380}
381
382// --- 2 arguments ---
383foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
384 "maxmag", "minmag", "nextafter", "pow", "powr",
385 "remainder"] in {
386 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
387}
388foreach name = ["fmax", "fmin"] in {
389 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
390 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
391 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
392 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
393}
394foreach name = ["ilogb"] in {
395 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
396 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
397 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
398}
399foreach name = ["ldexp"] in {
400 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
401 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
402 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
403 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
404 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
405 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
406}
407foreach name = ["pown", "rootn"] in {
408 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
409 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
410 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
411}
412
413// --- 3 arguments ---
414foreach name = ["fma", "mad"] in {
415 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
416}
417
418// --- Version dependent ---
419let MaxVersion = CL20 in {
420 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
421 foreach name = ["fract", "modf", "sincos"] in {
422 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
423 }
424 foreach name = ["frexp", "lgamma_r"] in {
425 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
426 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
427 }
428 }
429 foreach name = ["remquo"] in {
430 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
431 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
432 }
433 }
434 }
435}
436let MinVersion = CL20 in {
437 foreach name = ["fract", "modf", "sincos"] in {
438 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
439 }
440 foreach name = ["frexp", "lgamma_r"] in {
441 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
442 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
443 } }
444 foreach name = ["remquo"] in {
445 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
446 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
447 }
448 }
449}
450
451// --- Table 9 ---
452foreach name = ["half_cos",
453 "half_exp", "half_exp2", "half_exp10",
454 "half_log", "half_log2", "half_log10",
455 "half_recip", "half_rsqrt",
456 "half_sin", "half_sqrt", "half_tan",
457 "native_cos",
458 "native_exp", "native_exp2", "native_exp10",
459 "native_log", "native_log2", "native_log10",
460 "native_recip", "native_rsqrt",
461 "native_sin", "native_sqrt", "native_tan"] in {
462 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
463}
464foreach name = ["half_divide", "half_powr",
465 "native_divide", "native_powr"] in {
466 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
467}
468
469//--------------------------------------------------------------------
470// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
471// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
472// --- Table 12 ---
473// --- 1 argument ---
474foreach name = ["degrees", "radians", "sign"] in {
475 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
476}
477
478// --- 2 arguments ---
479foreach name = ["max", "min"] in {
480 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
481 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
482 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
483 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
484}
485foreach name = ["step"] in {
486 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
487 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
488 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
489 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
490}
491
492// --- 3 arguments ---
493foreach name = ["clamp", "mix"] in {
494 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
495 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
496 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
497 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
498}
499foreach name = ["smoothstep"] in {
500 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
501 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
502 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
503 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
504}
505
506
Sven van Haastregted69faa2019-09-19 13:41:51 +0000507// OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
508// 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
509// --- Table 15 ---
510// Variants for OpenCL versions below 2.0, using pointers to the global, local
511// and private address spaces.
512let MaxVersion = CL20 in {
513 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
514 foreach VSize = [2, 3, 4, 8, 16] in {
515 foreach name = ["vload" # VSize] in {
516 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
517 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
518 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
519 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
520 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
521 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
522 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
523 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
524 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
525 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
526 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
527 }
528 foreach name = ["vstore" # VSize] in {
529 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
530 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
531 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
532 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
533 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
534 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
535 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
536 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
537 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
538 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
539 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
540 }
541 foreach name = ["vloada_half" # VSize] in {
542 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
543 }
544 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
545 foreach name = ["vstorea_half" # VSize # rnd] in {
546 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
547 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
548 }
549 }
550 }
551 }
552}
553// Variants for OpenCL versions above 2.0, using pointers to the generic
554// address space.
555let MinVersion = CL20 in {
556 foreach VSize = [2, 3, 4, 8, 16] in {
557 foreach name = ["vload" # VSize] in {
558 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
559 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
560 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
561 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
562 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
563 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
564 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
565 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
566 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
567 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
568 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
569 }
570 foreach name = ["vstore" # VSize] in {
571 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
572 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
573 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
574 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
575 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
576 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
577 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
578 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
579 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
580 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
581 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
582 }
583 foreach name = ["vloada_half" # VSize] in {
584 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
585 }
586 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
587 foreach name = ["vstorea_half" # VSize # rnd] in {
588 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
589 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
590 }
591 }
592 }
593}
594// Variants using pointers to the constant address space.
595foreach VSize = [2, 3, 4, 8, 16] in {
596 foreach name = ["vload" # VSize] in {
597 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
598 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
599 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
600 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
601 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
602 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
603 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
604 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
605 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
606 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
607 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
608 }
609 foreach name = ["vloada_half" # VSize] in {
610 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
611 }
612 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
613 foreach name = ["vstorea_half" # VSize # rnd] in {
614 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
615 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
616 }
617 }
618}
619
620//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000621// 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
622// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
623// --- Table 18 ---
624foreach name = ["async_work_group_copy"] in {
625 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
626 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
627}
628foreach name = ["async_work_group_strided_copy"] in {
629 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
630 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
631}
632foreach name = ["wait_group_events"] in {
633 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
634}
635foreach name = ["prefetch"] in {
636 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
637}
638
639//--------------------------------------------------------------------
640// OpenCL v2.0 s6.13.11 - Atomics Functions.
641// Functions that use memory_order and cl_mem_fence_flags enums are not
642// declared here as the TableGen backend does not handle enums.
643
644// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers.
645// --- Table 9.1 ---
646foreach Type = [Int, UInt] in {
647 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
648 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
649 }
650 foreach name = ["atom_inc", "atom_dec"] in {
651 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
652 }
653 foreach name = ["atom_cmpxchg"] in {
654 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
655 }
656}
657
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000658// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
659foreach name = ["max", "min"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000660 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
661 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000662}
663
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000664//--------------------------------------------------------------------
665// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
666// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
667// --- Table 22: Image Read Functions with Samplers ---
668foreach imgTy = [Image1d] in {
669 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000670 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
671 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
672 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000673 }
674}
675foreach imgTy = [Image2d, Image1dArray] in {
676 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000677 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
678 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
679 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000680 }
681}
682foreach imgTy = [Image3d, Image2dArray] in {
683 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000684 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
685 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
686 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000687 }
688}
689foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000690 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
691 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000692}
693
694// --- Table 23: Sampler-less Read Functions ---
695foreach aQual = ["RO", "RW"] in {
696 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000697 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
698 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
699 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000700 }
701 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000702 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
703 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
704 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000705 }
706 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000707 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
708 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
709 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000710 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000711 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
712 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000713}
714
715// --- Table 24: Image Write Functions ---
716foreach aQual = ["WO", "RW"] in {
717 foreach imgTy = [Image2d] in {
718 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
719 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
720 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
721 }
722 foreach imgTy = [Image2dArray] in {
723 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
724 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
725 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
726 }
727 foreach imgTy = [Image1d, Image1dBuffer] in {
728 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
729 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
730 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
731 }
732 foreach imgTy = [Image1dArray] in {
733 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
734 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
735 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
736 }
737 foreach imgTy = [Image3d] in {
738 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
739 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
740 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
741 }
742 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
743 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
744}
745
Sven van Haastregt2a69ed02019-09-25 09:12:59 +0000746// --- Table 25: Image Query Functions ---
747foreach aQual = ["RO", "WO", "RW"] in {
748 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
749 Image1dArray, Image2dArray, Image2dDepth,
750 Image2dArrayDepth] in {
751 foreach name = ["get_image_width", "get_image_channel_data_type",
752 "get_image_channel_order"] in {
753 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
754 }
755 }
756 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
757 Image2dArrayDepth] in {
758 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
759 }
760 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
761 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
762 Image2dArrayDepth] in {
763 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
764 }
765 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
766 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
767 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
768 }
769}
770
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000771// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
772// --- Table 8 ---
773foreach aQual = ["RO"] in {
774 foreach name = ["read_imageh"] in {
775 foreach coordTy = [Int, Float] in {
776 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000777 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000778 }
779 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000780 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000781 }
782 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000783 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000784 }
785 }
786 }
787}
788// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
789// --- Table 9 ---
790foreach aQual = ["RO", "RW"] in {
791 foreach name = ["read_imageh"] in {
792 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000793 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000794 }
795 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000796 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000797 }
798 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000799 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000800 }
801 }
802}
803// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
804// --- Table 10 ---
805foreach aQual = ["WO", "RW"] in {
806 foreach name = ["write_imageh"] in {
807 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
808 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
809 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
810 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
811 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
812 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
813 }
814}
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000815
816
817// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +0000818let MinVersion = CL20 in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000819 let Extension = "cl_khr_subgroups" in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000820 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
821 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
822 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000823 }
824}