blob: 353e0c1d8c8d245b3a7ef2acdbed4f2f0fd15036 [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]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000277def Vec2 : IntList<"Vec2", [2]>;
278def Vec4 : IntList<"Vec4", [4]>;
279def Vec8 : IntList<"Vec8", [8]>;
280def Vec16 : IntList<"Vec16", [16]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000281def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000282
283// Type lists.
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000284def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
285def TLAllUnsigned : TypeList<"TLAllUnsigned", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000286def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000287def TLSignedInts : TypeList<"TLSignedInts", [Char, Short, Int, Long]>;
288def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000289
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000290def TLIntLongFloats : TypeList<"TLIntLongFloats", [Int, UInt, Long, ULong, Float, Double, Half]>;
291
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000292// All unsigned integer types twice, to facilitate unsigned return types for e.g.
293// uchar abs(char) and
294// uchar abs(uchar).
295def TLAllUIntsTwice : TypeList<"TLAllUIntsTwice", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
296
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000297def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
298
299// GenType definitions for multiple base types (e.g. all floating point types,
300// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000301// All types
302def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
303def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000304// All integer
305def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
306def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
307def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000308// All integer to unsigned
309def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000310// Signed integer
311def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
312// Unsigned integer
313def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000314// Float
315def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000316// (u)int, (u)long, and all floats
317def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000318
319// GenType definitions for every single base type (e.g. fp32 only).
320// Names are like: GenTypeFloatVecAndScalar.
321foreach Type = [Char, UChar, Short, UShort,
322 Int, UInt, Long, ULong,
323 Float, Double, Half] in {
324 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
325 def "GenType" # Type # VecSizes :
326 GenericType<"GenType" # Type # VecSizes,
327 TypeList<"GL" # Type.Name, [Type]>,
328 VecSizes>;
329 }
330}
331
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000332// GenType definitions for vec1234.
333foreach Type = [Float, Double, Half] in {
334 def "GenType" # Type # Vec1234 :
335 GenericType<"GenType" # Type # Vec1234,
336 TypeList<"GL" # Type.Name, [Type]>,
337 Vec1234>;
338}
339
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000340
341//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000342// Definitions of OpenCL builtin functions
343//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000344//--------------------------------------------------------------------
345// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
346// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
347
348// Generate the convert_* builtins functions.
349foreach RType = [Float, Double, Half, Char, UChar, Short,
350 UShort, Int, UInt, Long, ULong] in {
351 foreach IType = [Float, Double, Half, Char, UChar, Short,
352 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000353 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000354 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000355 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
356 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000357 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000358 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000359 [VectorType<RType, v>, VectorType<IType, v>],
360 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000361 }
362 }
363 }
364 }
365}
366
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000367//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000368// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
369// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000370def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000371foreach name = ["get_global_size", "get_global_id", "get_local_size",
372 "get_local_id", "get_num_groups", "get_group_id",
373 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000374 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000375}
376
377let MinVersion = CL20 in {
378 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
379 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
380 def : Builtin<name, [Size]>;
381 }
382}
383
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000384
Sven van Haastregted69faa2019-09-19 13:41:51 +0000385//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000386// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
387// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
388// --- Table 8 ---
389// --- 1 argument ---
390foreach name = ["acos", "acosh", "acospi",
391 "asin", "asinh", "asinpi",
392 "atan", "atanh", "atanpi",
393 "cbrt", "ceil",
394 "cos", "cosh", "cospi",
395 "erfc", "erf",
396 "exp", "exp2", "exp10", "expm1",
397 "fabs", "floor",
398 "log", "log2", "log10", "log1p", "logb",
399 "rint", "round", "rsqrt",
400 "sin", "sinh", "sinpi",
401 "sqrt",
402 "tan", "tanh", "tanpi",
403 "tgamma", "trunc",
404 "lgamma"] in {
405 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
406}
407foreach name = ["nan"] in {
408 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
409 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
410 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
411}
412
413// --- 2 arguments ---
414foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
415 "maxmag", "minmag", "nextafter", "pow", "powr",
416 "remainder"] in {
417 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
418}
419foreach name = ["fmax", "fmin"] in {
420 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
421 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
422 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
423 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
424}
425foreach name = ["ilogb"] in {
426 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
427 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
428 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
429}
430foreach name = ["ldexp"] in {
431 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
432 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
433 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
434 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
435 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
436 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
437}
438foreach name = ["pown", "rootn"] in {
439 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
440 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
441 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
442}
443
444// --- 3 arguments ---
445foreach name = ["fma", "mad"] in {
446 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
447}
448
449// --- Version dependent ---
450let MaxVersion = CL20 in {
451 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
452 foreach name = ["fract", "modf", "sincos"] in {
453 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
454 }
455 foreach name = ["frexp", "lgamma_r"] in {
456 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
457 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
458 }
459 }
460 foreach name = ["remquo"] in {
461 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
462 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
463 }
464 }
465 }
466}
467let MinVersion = CL20 in {
468 foreach name = ["fract", "modf", "sincos"] in {
469 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
470 }
471 foreach name = ["frexp", "lgamma_r"] in {
472 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
473 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
474 } }
475 foreach name = ["remquo"] in {
476 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
477 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
478 }
479 }
480}
481
482// --- Table 9 ---
483foreach name = ["half_cos",
484 "half_exp", "half_exp2", "half_exp10",
485 "half_log", "half_log2", "half_log10",
486 "half_recip", "half_rsqrt",
487 "half_sin", "half_sqrt", "half_tan",
488 "native_cos",
489 "native_exp", "native_exp2", "native_exp10",
490 "native_log", "native_log2", "native_log10",
491 "native_recip", "native_rsqrt",
492 "native_sin", "native_sqrt", "native_tan"] in {
493 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
494}
495foreach name = ["half_divide", "half_powr",
496 "native_divide", "native_powr"] in {
497 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
498}
499
500//--------------------------------------------------------------------
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000501// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
502// --- Table 10 ---
503// --- 1 argument ---
504foreach name = ["abs"] in {
505 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
506}
507foreach name = ["clz", "popcount"] in {
508 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
509}
510let MinVersion = CL20 in {
511 foreach name = ["ctz"] in {
512 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
513 }
514}
515
516// --- 2 arguments ---
517foreach name = ["abs_diff"] in {
518 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
519}
520foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
521 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
522}
523foreach name = ["max", "min"] in {
524 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
525 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
526}
527foreach name = ["upsample"] in {
528 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
529 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
530 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
531 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
532 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
533 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
534}
535
536// --- 3 arguments ---
537foreach name = ["clamp"] in {
538 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
539 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
540}
541foreach name = ["mad_hi", "mad_sat"] in {
542 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
543}
544
545// --- Table 11 ---
546foreach name = ["mad24"] in {
547 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
548 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
549}
550foreach name = ["mul24"] in {
551 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
552 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
553}
554
555//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000556// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
557// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
558// --- Table 12 ---
559// --- 1 argument ---
560foreach name = ["degrees", "radians", "sign"] in {
561 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
562}
563
564// --- 2 arguments ---
565foreach name = ["max", "min"] in {
566 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
567 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
568 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
569 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
570}
571foreach name = ["step"] in {
572 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
573 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
574 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
575 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
576}
577
578// --- 3 arguments ---
579foreach name = ["clamp", "mix"] in {
580 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
581 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
582 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
583 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
584}
585foreach name = ["smoothstep"] in {
586 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
587 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
588 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
589 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
590}
591
592
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000593//--------------------------------------------------------------------
594// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
595// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
596// --- Table 13 ---
597// --- 1 argument ---
598foreach name = ["length"] in {
599 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
600 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
601 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
602}
603foreach name = ["normalize"] in {
604 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
605 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
606 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
607}
608foreach name = ["fast_length"] in {
609 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
610}
611foreach name = ["fast_normalize"] in {
612 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
613}
614
615// --- 2 arguments ---
616foreach name = ["cross"] in {
617 foreach VSize = [3, 4] in {
618 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
619 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
620 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
621 }
622}
623foreach name = ["dot", "distance"] in {
624 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
625 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
626 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
627}
628foreach name = ["fast_distance"] in {
629 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
630}
631
632
633//--------------------------------------------------------------------
634// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
635// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
636// --- Table 14 ---
637// --- 1 argument ---
638foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
639 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
640 def : Builtin<name, [Int, Double], Attr.Const>;
641 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
642 def : Builtin<name, [Int, Half], Attr.Const>;
643 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
644}
645foreach name = ["any", "all"] in {
646 def : Builtin<name, [Int, AIGenTypeN], Attr.Const>;
647}
648
649// --- 2 arguments ---
650foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
651 "isless", "islessequal", "islessgreater", "isordered",
652 "isunordered"] in {
653 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
654 def : Builtin<name, [Int, Double, Double], Attr.Const>;
655 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
656 def : Builtin<name, [Int, Half, Half], Attr.Const>;
657 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
658}
659
660// --- 3 arguments ---
661foreach name = ["bitselect"] in {
662 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
663}
664foreach name = ["select"] in {
665 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
666 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
667 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
668 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
669 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
670 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
671 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
672 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
673 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
674 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
675}
676
677
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000678//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000679// OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000680// 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
Sven van Haastregted69faa2019-09-19 13:41:51 +0000681// --- Table 15 ---
682// Variants for OpenCL versions below 2.0, using pointers to the global, local
683// and private address spaces.
684let MaxVersion = CL20 in {
685 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
686 foreach VSize = [2, 3, 4, 8, 16] in {
687 foreach name = ["vload" # VSize] in {
688 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
689 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
690 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
691 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
692 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
693 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
694 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
695 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
696 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
697 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
698 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
699 }
700 foreach name = ["vstore" # VSize] in {
701 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
702 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
703 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
704 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
705 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
706 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
707 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
708 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
709 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
710 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
711 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
712 }
713 foreach name = ["vloada_half" # VSize] in {
714 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
715 }
716 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
717 foreach name = ["vstorea_half" # VSize # rnd] in {
718 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
719 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
720 }
721 }
722 }
723 }
724}
725// Variants for OpenCL versions above 2.0, using pointers to the generic
726// address space.
727let MinVersion = CL20 in {
728 foreach VSize = [2, 3, 4, 8, 16] in {
729 foreach name = ["vload" # VSize] in {
730 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
731 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
732 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
733 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
734 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
735 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
736 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
737 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
738 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
739 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
740 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
741 }
742 foreach name = ["vstore" # VSize] in {
743 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
744 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
745 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
746 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
747 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
748 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
749 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
750 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
751 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
752 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
753 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
754 }
755 foreach name = ["vloada_half" # VSize] in {
756 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
757 }
758 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
759 foreach name = ["vstorea_half" # VSize # rnd] in {
760 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
761 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
762 }
763 }
764 }
765}
766// Variants using pointers to the constant address space.
767foreach VSize = [2, 3, 4, 8, 16] in {
768 foreach name = ["vload" # VSize] in {
769 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
770 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
771 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
772 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
773 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
774 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
775 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
776 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
777 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
778 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
779 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
780 }
781 foreach name = ["vloada_half" # VSize] in {
782 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
783 }
784 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
785 foreach name = ["vstorea_half" # VSize # rnd] in {
786 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
787 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
788 }
789 }
790}
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000791let MaxVersion = CL20 in {
792 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
793 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
794 foreach VSize = [2, 3, 4, 8, 16] in {
795 foreach name = ["vload_half" # VSize] in {
796 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
797 }
798 }
799 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
800 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
801 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
802 foreach VSize = [2, 3, 4, 8, 16] in {
803 foreach name = ["vstore_half" # VSize # rnd] in {
804 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
805 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
806 }
807 }
808 }
809 }
810}
811let MinVersion = CL20 in {
812 foreach AS = [GenericAS] in {
813 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
814 foreach VSize = [2, 3, 4, 8, 16] in {
815 foreach name = ["vload_half" # VSize] in {
816 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
817 }
818 }
819 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
820 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
821 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
822 foreach VSize = [2, 3, 4, 8, 16] in {
823 foreach name = ["vstore_half" # VSize # rnd] in {
824 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
825 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
826 }
827 }
828 }
829 }
830}
831
832foreach AS = [ConstantAS] in {
833 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
834 foreach VSize = [2, 3, 4, 8, 16] in {
835 foreach name = ["vload_half" # VSize] in {
836 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
837 }
838 }
839}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000840
841//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000842// 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
843// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
844// --- Table 18 ---
845foreach name = ["async_work_group_copy"] in {
846 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
847 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
848}
849foreach name = ["async_work_group_strided_copy"] in {
850 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
851 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
852}
853foreach name = ["wait_group_events"] in {
854 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
855}
856foreach name = ["prefetch"] in {
857 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
858}
859
860//--------------------------------------------------------------------
861// OpenCL v2.0 s6.13.11 - Atomics Functions.
862// Functions that use memory_order and cl_mem_fence_flags enums are not
863// declared here as the TableGen backend does not handle enums.
864
865// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers.
866// --- Table 9.1 ---
867foreach Type = [Int, UInt] in {
868 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
869 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
870 }
871 foreach name = ["atom_inc", "atom_dec"] in {
872 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
873 }
874 foreach name = ["atom_cmpxchg"] in {
875 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
876 }
877}
878
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000879//--------------------------------------------------------------------
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000880// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
881// --- Table 19 ---
882foreach name = ["shuffle"] in {
883 foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
884 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
885 def : Builtin<name, [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
886 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
887 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
888 Attr.Const>;
889 }
890 }
891}
892foreach name = ["shuffle2"] in {
893 foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
894 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
895 def : Builtin<name, [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
896 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
897 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
898 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
899 Attr.Const>;
900 }
901 }
902}
903
904//--------------------------------------------------------------------
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000905// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
906// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
907// --- Table 22: Image Read Functions with Samplers ---
908foreach imgTy = [Image1d] in {
909 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000910 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
911 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
912 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000913 }
914}
915foreach imgTy = [Image2d, Image1dArray] in {
916 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000917 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
918 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
919 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000920 }
921}
922foreach imgTy = [Image3d, Image2dArray] in {
923 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000924 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
925 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
926 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000927 }
928}
929foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000930 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
931 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000932}
933
934// --- Table 23: Sampler-less Read Functions ---
935foreach aQual = ["RO", "RW"] in {
936 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000937 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
938 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
939 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000940 }
941 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000942 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
943 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
944 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000945 }
946 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000947 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
948 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
949 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000950 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000951 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
952 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000953}
954
955// --- Table 24: Image Write Functions ---
956foreach aQual = ["WO", "RW"] in {
957 foreach imgTy = [Image2d] in {
958 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
959 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
960 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
961 }
962 foreach imgTy = [Image2dArray] in {
963 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
964 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
965 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
966 }
967 foreach imgTy = [Image1d, Image1dBuffer] in {
968 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
969 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
970 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
971 }
972 foreach imgTy = [Image1dArray] in {
973 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
974 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
975 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
976 }
977 foreach imgTy = [Image3d] in {
978 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
979 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
980 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
981 }
982 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
983 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
984}
985
Sven van Haastregt2a69ed02019-09-25 09:12:59 +0000986// --- Table 25: Image Query Functions ---
987foreach aQual = ["RO", "WO", "RW"] in {
988 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
989 Image1dArray, Image2dArray, Image2dDepth,
990 Image2dArrayDepth] in {
991 foreach name = ["get_image_width", "get_image_channel_data_type",
992 "get_image_channel_order"] in {
993 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
994 }
995 }
996 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
997 Image2dArrayDepth] in {
998 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
999 }
1000 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1001 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1002 Image2dArrayDepth] in {
1003 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1004 }
1005 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1006 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1007 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1008 }
1009}
1010
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001011// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1012// --- Table 8 ---
1013foreach aQual = ["RO"] in {
1014 foreach name = ["read_imageh"] in {
1015 foreach coordTy = [Int, Float] in {
1016 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001017 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001018 }
1019 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001020 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001021 }
1022 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001023 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001024 }
1025 }
1026 }
1027}
1028// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1029// --- Table 9 ---
1030foreach aQual = ["RO", "RW"] in {
1031 foreach name = ["read_imageh"] in {
1032 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001033 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001034 }
1035 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001036 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001037 }
1038 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001039 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001040 }
1041 }
1042}
1043// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1044// --- Table 10 ---
1045foreach aQual = ["WO", "RW"] in {
1046 foreach name = ["write_imageh"] in {
1047 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1048 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1049 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1050 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1051 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1052 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1053 }
1054}
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001055
1056
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001057//--------------------------------------------------------------------
1058// OpenCL v2.0 s6.13.15 - Work-group Functions
1059// --- Table 26 ---
1060let MinVersion = CL20 in {
1061 foreach name = ["work_group_all", "work_group_any"] in {
1062 def : Builtin<name, [Int, Int], Attr.Convergent>;
1063 }
1064 foreach name = ["work_group_broadcast"] in {
1065 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1066 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1067 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1068 }
1069 foreach op = ["add", "min", "max"] in {
1070 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1071 "work_group_scan_inclusive_"] in {
1072 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1073 }
1074 }
1075}
1076
1077
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001078// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +00001079let MinVersion = CL20 in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001080 let Extension = "cl_khr_subgroups" in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +00001081 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1082 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1083 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001084 }
1085}