blob: 0cbdc05700e9f2d04fc1845d8343ab487f4ad4f7 [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
Sven van Haastregt308b8b72019-12-18 10:13:51 +000043// OpenCL language extension.
44class AbstractExtension<string _Ext> {
45 // One or more OpenCL extensions, space separated. Each extension must be
46 // a valid extension name for the opencl extension pragma.
47 string ExtName = _Ext;
48}
49
50// Extension associated to a builtin function.
51class FunctionExtension<string _Ext> : AbstractExtension<_Ext>;
52
53// FunctionExtension definitions.
54def FuncExtNone : FunctionExtension<"">;
55def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">;
56def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">;
57def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
Sven van Haastregtb7145832019-12-23 12:29:01 +000058def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">;
59def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
60def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">;
61def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +000062def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">;
Sven van Haastregt92451f02020-01-14 14:46:42 +000063def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +000064
65// Multiple extensions
66def FuncExtKhrMipmapAndWrite3d : FunctionExtension<"cl_khr_mipmap_image cl_khr_3d_image_writes">;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000067
Sven van Haastregtb21a3652019-08-19 11:56:03 +000068// Qualified Type. These map to ASTContext::QualType.
69class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000070 // Name of the field or function in a clang::ASTContext
71 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
72 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000073 // Some QualTypes in this file represent an abstract type for which there is
74 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
75 // without access qualifiers.
76 bit IsAbstract = _IsAbstract;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000077}
78
Sven van Haastregtb21a3652019-08-19 11:56:03 +000079// List of integers.
80class IntList<string _Name, list<int> _List> {
81 string Name = _Name;
82 list<int> List = _List;
83}
84
Sven van Haastregt79a222f2019-06-03 09:39:11 +000085//===----------------------------------------------------------------------===//
86// OpenCL C classes for types
87//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000088// OpenCL C basic data types (int, float, image2d_t, ...).
Sven van Haastregt47e95ff2019-09-17 13:32:56 +000089// Its child classes can represent concrete types (e.g. VectorType) or
90// abstract types (e.g. GenType).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000091class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000092 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000093 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000094 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000095 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000096 // Size of the vector (if applicable).
97 int VecWidth = 1;
98 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000099 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000100 // "const" qualifier.
101 bit IsConst = 0;
102 // "volatile" qualifier.
103 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000104 // Access qualifier. Must be one of ("RO", "WO", "RW").
105 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000106 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000107 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000108}
109
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000110// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000111class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000112 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000113 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000114 // Inherited fields
115 let IsPointer = _Ty.IsPointer;
116 let IsConst = _Ty.IsConst;
117 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000118 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000119}
120
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000121// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000122class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000123 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000124 let AddrSpace = _AS.Name;
125 // Inherited fields
126 let VecWidth = _Ty.VecWidth;
127 let IsPointer = 1;
128 let IsConst = _Ty.IsConst;
129 let IsVolatile = _Ty.IsVolatile;
130 let AccessQualifier = _Ty.AccessQualifier;
131}
132
133// OpenCL const types (e.g. const int).
134class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
135 let IsConst = 1;
136 // Inherited fields
137 let VecWidth = _Ty.VecWidth;
138 let IsPointer = _Ty.IsPointer;
139 let IsVolatile = _Ty.IsVolatile;
140 let AccessQualifier = _Ty.AccessQualifier;
141 let AddrSpace = _Ty.AddrSpace;
142}
143
144// OpenCL volatile types (e.g. volatile int).
145class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
146 let IsVolatile = 1;
147 // Inherited fields
148 let VecWidth = _Ty.VecWidth;
149 let IsPointer = _Ty.IsPointer;
150 let IsConst = _Ty.IsConst;
151 let AccessQualifier = _Ty.AccessQualifier;
152 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000153}
154
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000155// OpenCL image types (e.g. image2d).
156class ImageType<Type _Ty, string _AccessQualifier> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000157 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000158 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000159 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000160 // Inherited fields
161 let IsPointer = _Ty.IsPointer;
162 let IsConst = _Ty.IsConst;
163 let IsVolatile = _Ty.IsVolatile;
164 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000165}
166
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000167// List of Types.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000168class TypeList<list<Type> _Type> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000169 list<Type> List = _Type;
170}
171
172// A GenericType is an abstract type that defines a set of types as a
173// combination of Types and vector sizes.
174//
Sven van Haastregt47e95ff2019-09-17 13:32:56 +0000175// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
176// represents <int, int2, int4, float, float2, float4>.
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000177//
178// Some rules apply when using multiple GenericType arguments in a declaration:
179// 1. The number of vector sizes must be equal or 1 for all gentypes in a
180// declaration.
181// 2. The number of Types must be equal or 1 for all gentypes in a
182// declaration.
183// 3. Generic types are combined by iterating over all generic types at once.
184// For example, for the following GenericTypes
185// GenT1 = GenericType<half, [1, 2]> and
186// GenT2 = GenericType<float, int, [1, 2]>
187// A declaration f(GenT1, GenT2) results in the combinations
188// f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
189// 4. "sgentype" from the OpenCL specification is supported by specifying
190// a single vector size.
191// For example, for the following GenericTypes
192// GenT = GenericType<half, int, [1, 2]> and
193// SGenT = GenericType<half, int, [1]>
194// A declaration f(GenT, SGenT) results in the combinations
195// f(half, half), f(half2, half), f(int, int), f(int2, int) .
196class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000197 Type<_Ty, QualType<"null", 1>> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000198 // Possible element types of the generic type.
199 TypeList TypeList = _TypeList;
200 // Possible vector sizes of the types in the TypeList.
201 IntList VectorList = _VectorList;
202 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
203 let VecWidth = 0;
204}
205
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000206// Builtin function attributes.
207def Attr {
208 list<bit> None = [0, 0, 0];
209 list<bit> Pure = [1, 0, 0];
210 list<bit> Const = [0, 1, 0];
211 list<bit> Convergent = [0, 0, 1];
212}
213
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000214//===----------------------------------------------------------------------===//
215// OpenCL C class for builtin functions
216//===----------------------------------------------------------------------===//
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000217class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000218 // Name of the builtin function
219 string Name = _Name;
220 // List of types used by the function. The first one is the return type and
221 // the following are the arguments. The list must have at least one element
222 // (the return type).
223 list<Type> Signature = _Signature;
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000224 // Function attribute __attribute__((pure))
225 bit IsPure = _Attributes[0];
226 // Function attribute __attribute__((const))
227 bit IsConst = _Attributes[1];
228 // Function attribute __attribute__((convergent))
229 bit IsConv = _Attributes[2];
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000230 // OpenCL extensions to which the function belongs.
231 FunctionExtension Extension = FuncExtNone;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000232 // Version of OpenCL from which the function is available (e.g.: CL10).
233 // MinVersion is inclusive.
234 Version MinVersion = CL10;
235 // Version of OpenCL from which the function is not supported anymore.
236 // MaxVersion is exclusive.
237 // CLAll makes the function available for all versions.
238 Version MaxVersion = CLAll;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000239}
240
241//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000242// Definitions of OpenCL C types
243//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000244
245// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000246def Bool : Type<"bool", QualType<"BoolTy">>;
247def Char : Type<"char", QualType<"CharTy">>;
248def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
249def Short : Type<"short", QualType<"ShortTy">>;
250def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
251def Int : Type<"int", QualType<"IntTy">>;
252def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
253def Long : Type<"long", QualType<"LongTy">>;
254def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
255def Float : Type<"float", QualType<"FloatTy">>;
256def Double : Type<"double", QualType<"DoubleTy">>;
257def Half : Type<"half", QualType<"HalfTy">>;
258def Size : Type<"size_t", QualType<"getSizeType()">>;
259def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
260def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
261def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000262def Void : Type<"void", QualType<"VoidTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000263
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000264// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
265// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000266
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000267// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
268// The image definitions are "abstract". They should not be used without
269// specifying an access qualifier (RO/WO/RW).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000270def Image1d : Type<"image1d_t", QualType<"OCLImage1d", 1>>;
271def Image2d : Type<"image2d_t", QualType<"OCLImage2d", 1>>;
272def Image3d : Type<"image3d_t", QualType<"OCLImage3d", 1>>;
273def Image1dArray : Type<"image1d_array_t", QualType<"OCLImage1dArray", 1>>;
274def Image1dBuffer : Type<"image1d_buffer_t", QualType<"OCLImage1dBuffer", 1>>;
275def Image2dArray : Type<"image2d_array_t", QualType<"OCLImage2dArray", 1>>;
276def Image2dDepth : Type<"image2d_depth_t", QualType<"OCLImage2dDepth", 1>>;
277def Image2dArrayDepth : Type<"image2d_array_depth_t", QualType<"OCLImage2dArrayDepth", 1>>;
278def Image2dMsaa : Type<"image2d_msaa_t", QualType<"OCLImage2dMSAA", 1>>;
279def Image2dArrayMsaa : Type<"image2d_array_msaa_t", QualType<"OCLImage2dArrayMSAA", 1>>;
280def Image2dMsaaDepth : Type<"image2d_msaa_depth_t", QualType<"OCLImage2dMSAADepth", 1>>;
281def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"OCLImage2dArrayMSAADepth", 1>>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000282
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000283def Sampler : Type<"sampler_t", QualType<"OCLSamplerTy">>;
284def Event : Type<"event_t", QualType<"OCLEventTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000285
286//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000287// Definitions of OpenCL gentype variants
288//===----------------------------------------------------------------------===//
289// The OpenCL specification often uses "gentype" in builtin function
290// declarations to indicate that a builtin function is available with various
291// argument and return types. The types represented by "gentype" vary between
292// different parts of the specification. The following definitions capture
293// the different type lists for gentypes in different parts of the
294// specification.
295
296// Vector width lists.
297def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
298def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
299def Vec1 : IntList<"Vec1", [1]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000300def Vec2 : IntList<"Vec2", [2]>;
301def Vec4 : IntList<"Vec4", [4]>;
302def Vec8 : IntList<"Vec8", [8]>;
303def Vec16 : IntList<"Vec16", [16]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000304def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000305
306// Type lists.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000307def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
308def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
309def TLFloat : TypeList<[Float, Double, Half]>;
310def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
311def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000312
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000313def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000314
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000315// All unsigned integer types twice, to facilitate unsigned return types for e.g.
316// uchar abs(char) and
317// uchar abs(uchar).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000318def TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000319
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000320def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000321
322// GenType definitions for multiple base types (e.g. all floating point types,
323// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000324// All types
325def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
326def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000327// All integer
328def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
329def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
330def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000331// All integer to unsigned
332def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000333// Signed integer
334def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
335// Unsigned integer
336def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000337// Float
338def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000339// (u)int, (u)long, and all floats
340def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000341
342// GenType definitions for every single base type (e.g. fp32 only).
343// Names are like: GenTypeFloatVecAndScalar.
344foreach Type = [Char, UChar, Short, UShort,
345 Int, UInt, Long, ULong,
346 Float, Double, Half] in {
347 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
348 def "GenType" # Type # VecSizes :
349 GenericType<"GenType" # Type # VecSizes,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000350 TypeList<[Type]>, VecSizes>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000351 }
352}
353
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000354// GenType definitions for vec1234.
355foreach Type = [Float, Double, Half] in {
356 def "GenType" # Type # Vec1234 :
357 GenericType<"GenType" # Type # Vec1234,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000358 TypeList<[Type]>, Vec1234>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000359}
360
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000361
362//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000363// Definitions of OpenCL builtin functions
364//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000365//--------------------------------------------------------------------
366// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
367// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
368
369// Generate the convert_* builtins functions.
370foreach RType = [Float, Double, Half, Char, UChar, Short,
371 UShort, Int, UInt, Long, ULong] in {
372 foreach IType = [Float, Double, Half, Char, UChar, Short,
373 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000374 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000375 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000376 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
377 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000378 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000379 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000380 [VectorType<RType, v>, VectorType<IType, v>],
381 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000382 }
383 }
384 }
385 }
386}
387
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000388//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000389// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
390// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000391def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000392foreach name = ["get_global_size", "get_global_id", "get_local_size",
393 "get_local_id", "get_num_groups", "get_group_id",
394 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000395 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000396}
397
398let MinVersion = CL20 in {
399 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
400 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
401 def : Builtin<name, [Size]>;
402 }
403}
404
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000405
Sven van Haastregted69faa2019-09-19 13:41:51 +0000406//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000407// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
408// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
409// --- Table 8 ---
410// --- 1 argument ---
411foreach name = ["acos", "acosh", "acospi",
412 "asin", "asinh", "asinpi",
413 "atan", "atanh", "atanpi",
414 "cbrt", "ceil",
415 "cos", "cosh", "cospi",
416 "erfc", "erf",
417 "exp", "exp2", "exp10", "expm1",
418 "fabs", "floor",
419 "log", "log2", "log10", "log1p", "logb",
420 "rint", "round", "rsqrt",
421 "sin", "sinh", "sinpi",
422 "sqrt",
423 "tan", "tanh", "tanpi",
424 "tgamma", "trunc",
425 "lgamma"] in {
426 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
427}
428foreach name = ["nan"] in {
429 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
430 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
431 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
432}
433
434// --- 2 arguments ---
435foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
436 "maxmag", "minmag", "nextafter", "pow", "powr",
437 "remainder"] in {
438 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
439}
440foreach name = ["fmax", "fmin"] in {
441 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
442 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
443 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
444 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
445}
446foreach name = ["ilogb"] in {
447 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
448 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
449 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
450}
451foreach name = ["ldexp"] in {
452 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
453 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
454 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
455 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
456 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
457 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
458}
459foreach name = ["pown", "rootn"] in {
460 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
461 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
462 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
463}
464
465// --- 3 arguments ---
466foreach name = ["fma", "mad"] in {
467 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
468}
469
470// --- Version dependent ---
471let MaxVersion = CL20 in {
472 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
473 foreach name = ["fract", "modf", "sincos"] in {
474 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
475 }
476 foreach name = ["frexp", "lgamma_r"] in {
477 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
478 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
479 }
480 }
481 foreach name = ["remquo"] in {
482 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
483 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
484 }
485 }
486 }
487}
488let MinVersion = CL20 in {
489 foreach name = ["fract", "modf", "sincos"] in {
490 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
491 }
492 foreach name = ["frexp", "lgamma_r"] in {
493 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
494 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
495 } }
496 foreach name = ["remquo"] in {
497 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
498 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
499 }
500 }
501}
502
503// --- Table 9 ---
504foreach name = ["half_cos",
505 "half_exp", "half_exp2", "half_exp10",
506 "half_log", "half_log2", "half_log10",
507 "half_recip", "half_rsqrt",
508 "half_sin", "half_sqrt", "half_tan",
509 "native_cos",
510 "native_exp", "native_exp2", "native_exp10",
511 "native_log", "native_log2", "native_log10",
512 "native_recip", "native_rsqrt",
513 "native_sin", "native_sqrt", "native_tan"] in {
514 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
515}
516foreach name = ["half_divide", "half_powr",
517 "native_divide", "native_powr"] in {
518 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
519}
520
521//--------------------------------------------------------------------
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000522// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
523// --- Table 10 ---
524// --- 1 argument ---
525foreach name = ["abs"] in {
526 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
527}
528foreach name = ["clz", "popcount"] in {
529 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
530}
531let MinVersion = CL20 in {
532 foreach name = ["ctz"] in {
533 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
534 }
535}
536
537// --- 2 arguments ---
538foreach name = ["abs_diff"] in {
539 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
540}
541foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
542 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
543}
544foreach name = ["max", "min"] in {
545 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
546 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
547}
548foreach name = ["upsample"] in {
549 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
550 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
551 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
552 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
553 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
554 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
555}
556
557// --- 3 arguments ---
558foreach name = ["clamp"] in {
559 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
560 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
561}
562foreach name = ["mad_hi", "mad_sat"] in {
563 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
564}
565
566// --- Table 11 ---
567foreach name = ["mad24"] in {
568 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
569 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
570}
571foreach name = ["mul24"] in {
572 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
573 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
574}
575
576//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000577// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
578// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
579// --- Table 12 ---
580// --- 1 argument ---
581foreach name = ["degrees", "radians", "sign"] in {
582 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
583}
584
585// --- 2 arguments ---
586foreach name = ["max", "min"] in {
587 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
588 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
589 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
590 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
591}
592foreach name = ["step"] in {
593 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
594 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
595 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
596 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
597}
598
599// --- 3 arguments ---
600foreach name = ["clamp", "mix"] in {
601 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
602 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
603 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
604 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
605}
606foreach name = ["smoothstep"] in {
607 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
608 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
609 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
610 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
611}
612
613
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000614//--------------------------------------------------------------------
615// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
616// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
617// --- Table 13 ---
618// --- 1 argument ---
619foreach name = ["length"] in {
620 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
621 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
622 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
623}
624foreach name = ["normalize"] in {
625 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
626 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
627 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
628}
629foreach name = ["fast_length"] in {
630 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
631}
632foreach name = ["fast_normalize"] in {
633 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
634}
635
636// --- 2 arguments ---
637foreach name = ["cross"] in {
638 foreach VSize = [3, 4] in {
639 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
640 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
641 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
642 }
643}
644foreach name = ["dot", "distance"] in {
645 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
646 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
647 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
648}
649foreach name = ["fast_distance"] in {
650 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
651}
652
653
654//--------------------------------------------------------------------
655// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
656// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
657// --- Table 14 ---
658// --- 1 argument ---
659foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
660 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
661 def : Builtin<name, [Int, Double], Attr.Const>;
662 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
663 def : Builtin<name, [Int, Half], Attr.Const>;
664 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
665}
666foreach name = ["any", "all"] in {
667 def : Builtin<name, [Int, AIGenTypeN], Attr.Const>;
668}
669
670// --- 2 arguments ---
671foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
672 "isless", "islessequal", "islessgreater", "isordered",
673 "isunordered"] in {
674 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
675 def : Builtin<name, [Int, Double, Double], Attr.Const>;
676 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
677 def : Builtin<name, [Int, Half, Half], Attr.Const>;
678 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
679}
680
681// --- 3 arguments ---
682foreach name = ["bitselect"] in {
683 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
684}
685foreach name = ["select"] in {
686 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
687 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
688 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
689 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
690 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
691 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
692 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
693 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
694 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
695 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
696}
697
698
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000699//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000700// 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 +0000701// 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 +0000702// --- Table 15 ---
703// Variants for OpenCL versions below 2.0, using pointers to the global, local
704// and private address spaces.
705let MaxVersion = CL20 in {
706 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
707 foreach VSize = [2, 3, 4, 8, 16] in {
708 foreach name = ["vload" # VSize] in {
709 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
710 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
711 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
712 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
713 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
714 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
715 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
716 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
717 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
718 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
719 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
720 }
721 foreach name = ["vstore" # VSize] in {
722 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
723 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
724 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
725 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
726 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
727 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
728 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
729 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
730 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
731 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
732 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
733 }
734 foreach name = ["vloada_half" # VSize] in {
735 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
736 }
737 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
738 foreach name = ["vstorea_half" # VSize # rnd] in {
739 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
740 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
741 }
742 }
743 }
744 }
745}
746// Variants for OpenCL versions above 2.0, using pointers to the generic
747// address space.
748let MinVersion = CL20 in {
749 foreach VSize = [2, 3, 4, 8, 16] in {
750 foreach name = ["vload" # VSize] in {
751 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
752 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
753 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
754 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
755 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
756 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
757 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
758 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
759 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
760 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
761 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
762 }
763 foreach name = ["vstore" # VSize] in {
764 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
765 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
766 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
767 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
768 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
769 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
770 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
771 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
772 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
773 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
774 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
775 }
776 foreach name = ["vloada_half" # VSize] in {
777 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
778 }
779 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
780 foreach name = ["vstorea_half" # VSize # rnd] in {
781 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
782 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
783 }
784 }
785 }
786}
787// Variants using pointers to the constant address space.
788foreach VSize = [2, 3, 4, 8, 16] in {
789 foreach name = ["vload" # VSize] in {
790 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
791 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
792 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
793 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
794 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
795 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
796 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
797 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
798 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
799 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
800 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
801 }
802 foreach name = ["vloada_half" # VSize] in {
803 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
804 }
805 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
806 foreach name = ["vstorea_half" # VSize # rnd] in {
807 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
808 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
809 }
810 }
811}
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000812let MaxVersion = CL20 in {
813 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
814 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
815 foreach VSize = [2, 3, 4, 8, 16] in {
816 foreach name = ["vload_half" # VSize] in {
817 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
818 }
819 }
820 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
821 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
822 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
823 foreach VSize = [2, 3, 4, 8, 16] in {
824 foreach name = ["vstore_half" # VSize # rnd] in {
825 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
826 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
827 }
828 }
829 }
830 }
831}
832let MinVersion = CL20 in {
833 foreach AS = [GenericAS] in {
834 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
835 foreach VSize = [2, 3, 4, 8, 16] in {
836 foreach name = ["vload_half" # VSize] in {
837 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
838 }
839 }
840 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
841 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
842 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
843 foreach VSize = [2, 3, 4, 8, 16] in {
844 foreach name = ["vstore_half" # VSize # rnd] in {
845 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
846 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
847 }
848 }
849 }
850 }
851}
852
853foreach AS = [ConstantAS] in {
854 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
855 foreach VSize = [2, 3, 4, 8, 16] in {
856 foreach name = ["vload_half" # VSize] in {
857 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
858 }
859 }
860}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000861
862//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000863// 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
864// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
865// --- Table 18 ---
866foreach name = ["async_work_group_copy"] in {
867 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
868 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
869}
870foreach name = ["async_work_group_strided_copy"] in {
871 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
872 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
873}
874foreach name = ["wait_group_events"] in {
875 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
876}
877foreach name = ["prefetch"] in {
878 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
879}
880
881//--------------------------------------------------------------------
882// OpenCL v2.0 s6.13.11 - Atomics Functions.
883// Functions that use memory_order and cl_mem_fence_flags enums are not
884// declared here as the TableGen backend does not handle enums.
885
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000886// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000887// --- Table 9.1 ---
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000888let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
889 foreach Type = [Int, UInt] in {
890 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
891 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
892 }
893 foreach name = ["atom_inc", "atom_dec"] in {
894 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
895 }
896 foreach name = ["atom_cmpxchg"] in {
897 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
898 }
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000899 }
900}
Sven van Haastregtb7145832019-12-23 12:29:01 +0000901// --- Table 9.3 ---
902let Extension = FuncExtKhrLocalInt32BaseAtomics in {
903 foreach Type = [Int, UInt] in {
904 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
905 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
906 }
907 foreach name = ["atom_inc", "atom_dec"] in {
908 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
909 }
910 foreach name = ["atom_cmpxchg"] in {
911 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
912 }
913 }
914}
915// --- Table 9.5 ---
916let Extension = FuncExtKhrInt64BaseAtomics in {
917 foreach AS = [GlobalAS, LocalAS] in {
918 foreach Type = [Long, ULong] in {
919 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
920 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
921 }
922 foreach name = ["atom_inc", "atom_dec"] in {
923 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
924 }
925 foreach name = ["atom_cmpxchg"] in {
926 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
927 }
928 }
929 }
930}
931// --- Table 9.2 ---
932let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
933 foreach Type = [Int, UInt] in {
934 foreach name = ["atom_min", "atom_max", "atom_and",
935 "atom_or", "atom_xor"] in {
936 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
937 }
938 }
939}
940// --- Table 9.4 ---
941let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
942 foreach Type = [Int, UInt] in {
943 foreach name = ["atom_min", "atom_max", "atom_and",
944 "atom_or", "atom_xor"] in {
945 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
946 }
947 }
948}
949// --- Table 9.6 ---
950let Extension = FuncExtKhrInt64ExtendedAtomics in {
951 foreach AS = [GlobalAS, LocalAS] in {
952 foreach Type = [Long, ULong] in {
953 foreach name = ["atom_min", "atom_max", "atom_and",
954 "atom_or", "atom_xor"] in {
955 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
956 }
957 }
958 }
959}
960// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
961foreach AS = [GlobalAS, LocalAS] in {
962 foreach Type = [Int, UInt] in {
963 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
964 "atomic_min", "atomic_max", "atomic_and",
965 "atomic_or", "atomic_xor"] in {
966 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
967 }
968 foreach name = ["atomic_inc", "atomic_dec"] in {
969 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
970 }
971 foreach name = ["atomic_cmpxchg"] in {
972 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
973 }
974 }
975}
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000976
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000977//--------------------------------------------------------------------
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000978// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
979// --- Table 19 ---
Sven van Haastregtff429c52019-12-31 15:30:02 +0000980foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
981 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
982 def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
983 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
984 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
985 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000986 }
987}
Sven van Haastregtff429c52019-12-31 15:30:02 +0000988foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
989 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
990 def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
991 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
992 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
993 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
994 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000995 }
996}
997
998//--------------------------------------------------------------------
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000999// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1000// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1001// --- Table 22: Image Read Functions with Samplers ---
1002foreach imgTy = [Image1d] in {
1003 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001004 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1005 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1006 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001007 }
1008}
1009foreach imgTy = [Image2d, Image1dArray] in {
1010 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001011 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1012 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1013 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001014 }
1015}
1016foreach imgTy = [Image3d, Image2dArray] in {
1017 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001018 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1019 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1020 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001021 }
1022}
1023foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001024 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1025 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001026}
1027
1028// --- Table 23: Sampler-less Read Functions ---
1029foreach aQual = ["RO", "RW"] in {
1030 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001031 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1032 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1033 def : Builtin<"read_imageui", [VectorType<UInt, 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<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1037 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1038 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001039 }
1040 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001041 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1042 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1043 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001044 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001045 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1046 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001047}
1048
1049// --- Table 24: Image Write Functions ---
1050foreach aQual = ["WO", "RW"] in {
1051 foreach imgTy = [Image2d] in {
1052 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1053 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1054 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1055 }
1056 foreach imgTy = [Image2dArray] in {
1057 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1058 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1059 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1060 }
1061 foreach imgTy = [Image1d, Image1dBuffer] in {
1062 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1063 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1064 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1065 }
1066 foreach imgTy = [Image1dArray] in {
1067 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1068 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1069 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1070 }
1071 foreach imgTy = [Image3d] in {
1072 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1073 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1074 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1075 }
1076 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1077 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1078}
1079
Sven van Haastregt2a69ed02019-09-25 09:12:59 +00001080// --- Table 25: Image Query Functions ---
1081foreach aQual = ["RO", "WO", "RW"] in {
1082 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1083 Image1dArray, Image2dArray, Image2dDepth,
1084 Image2dArrayDepth] in {
1085 foreach name = ["get_image_width", "get_image_channel_data_type",
1086 "get_image_channel_order"] in {
1087 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1088 }
1089 }
1090 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1091 Image2dArrayDepth] in {
1092 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1093 }
1094 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1095 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1096 Image2dArrayDepth] in {
1097 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1098 }
1099 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1100 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1101 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1102 }
1103}
1104
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001105// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1106// --- Table 8 ---
1107foreach aQual = ["RO"] in {
1108 foreach name = ["read_imageh"] in {
1109 foreach coordTy = [Int, Float] in {
1110 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001111 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001112 }
1113 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001114 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001115 }
1116 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001117 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001118 }
1119 }
1120 }
1121}
1122// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1123// --- Table 9 ---
1124foreach aQual = ["RO", "RW"] in {
1125 foreach name = ["read_imageh"] in {
1126 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001127 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001128 }
1129 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001130 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001131 }
1132 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001133 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001134 }
1135 }
1136}
1137// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1138// --- Table 10 ---
1139foreach aQual = ["WO", "RW"] in {
1140 foreach name = ["write_imageh"] in {
1141 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1142 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1143 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1144 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1145 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1146 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1147 }
1148}
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001149
1150
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001151//--------------------------------------------------------------------
1152// OpenCL v2.0 s6.13.15 - Work-group Functions
1153// --- Table 26 ---
1154let MinVersion = CL20 in {
1155 foreach name = ["work_group_all", "work_group_any"] in {
1156 def : Builtin<name, [Int, Int], Attr.Convergent>;
1157 }
1158 foreach name = ["work_group_broadcast"] in {
1159 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1160 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1161 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1162 }
1163 foreach op = ["add", "min", "max"] in {
1164 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1165 "work_group_scan_inclusive_"] in {
1166 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1167 }
1168 }
1169}
1170
1171
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001172// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +00001173let MinVersion = CL20 in {
Sven van Haastregt308b8b72019-12-18 10:13:51 +00001174 let Extension = FuncExtKhrSubgroups in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +00001175 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1176 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1177 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001178 }
1179}
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001180
1181//--------------------------------------------------------------------
1182// End of the builtin functions defined in the OpenCL C specification.
1183// Builtin functions defined in the OpenCL C Extension are below.
1184//--------------------------------------------------------------------
1185
1186
1187// OpenCL Extension v2.0 s9.18 - Mipmaps
1188let Extension = FuncExtKhrMipmapImage in {
1189 // Added to section 6.13.14.2.
1190 foreach aQual = ["RO"] in {
1191 foreach imgTy = [Image2d] in {
1192 foreach name = ["read_imagef"] in {
1193 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1194 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1195 }
1196 foreach name = ["read_imagei"] in {
1197 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1198 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1199 }
1200 foreach name = ["read_imageui"] in {
1201 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1202 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1203 }
1204 }
1205 foreach imgTy = [Image2dDepth] in {
1206 foreach name = ["read_imagef"] in {
1207 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1208 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1209 }
1210 }
1211 foreach imgTy = [Image1d] in {
1212 foreach name = ["read_imagef"] in {
1213 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1214 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1215 }
1216 foreach name = ["read_imagei"] in {
1217 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1218 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1219 }
1220 foreach name = ["read_imageui"] in {
1221 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1222 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1223 }
1224 }
1225 foreach imgTy = [Image3d] in {
1226 foreach name = ["read_imagef"] in {
1227 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1228 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1229 }
1230 foreach name = ["read_imagei"] in {
1231 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1232 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1233 }
1234 foreach name = ["read_imageui"] in {
1235 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1236 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1237 }
1238 }
1239 foreach imgTy = [Image1dArray] in {
1240 foreach name = ["read_imagef"] in {
1241 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1242 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1243 }
1244 foreach name = ["read_imagei"] in {
1245 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1246 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1247 }
1248 foreach name = ["read_imageui"] in {
1249 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1250 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1251 }
1252 }
1253 foreach imgTy = [Image2dArray] in {
1254 foreach name = ["read_imagef"] in {
1255 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1256 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1257 }
1258 foreach name = ["read_imagei"] in {
1259 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1260 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1261 }
1262 foreach name = ["read_imageui"] in {
1263 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1264 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1265 }
1266 }
1267 foreach imgTy = [Image2dArrayDepth] in {
1268 foreach name = ["read_imagef"] in {
1269 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1270 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1271 }
1272 }
1273 }
1274 // Added to section 6.13.14.4.
1275 foreach aQual = ["WO"] in {
1276 foreach imgTy = [Image2d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001277 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1278 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1279 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001280 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001281 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001282 foreach imgTy = [Image1d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001283 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1284 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1285 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001286 }
1287 foreach imgTy = [Image1dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001288 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1289 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1290 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001291 }
1292 foreach imgTy = [Image2dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001293 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1294 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1295 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001296 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001297 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001298 let Extension = FuncExtKhrMipmapAndWrite3d in {
1299 foreach imgTy = [Image3d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001300 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1301 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1302 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001303 }
1304 }
1305 }
1306 // Added to section 6.13.14.5
1307 foreach aQual = ["RO", "WO", "RW"] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001308 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1309 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001310 }
1311 }
1312}
Sven van Haastregt92451f02020-01-14 14:46:42 +00001313
1314
1315//--------------------------------------------------------------------
1316// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1317let Extension = FuncExtKhrGlMsaaSharing in {
1318 // --- Table 6.13.14.3 ---
1319 foreach aQual = ["RO", "RW"] in {
1320 foreach imgTy = [Image2dMsaa] in {
1321 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1322 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1323 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1324 }
1325 foreach imgTy = [Image2dArrayMsaa] in {
1326 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1327 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1328 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1329 }
1330 foreach name = ["read_imagef"] in {
1331 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1332 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1333 }
1334 }
1335
1336 // --- Table 6.13.14.5 ---
1337 foreach aQual = ["RO", "WO", "RW"] in {
1338 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1339 foreach name = ["get_image_width", "get_image_height",
1340 "get_image_channel_data_type", "get_image_channel_order",
1341 "get_image_num_samples"] in {
1342 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1343 }
1344 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1345 }
1346 def : Builtin<"get_image_array_size", [Size, ImageType<Image2dArrayMsaaDepth, aQual>], Attr.Const>;
1347 }
1348}