blob: 888978dfdbd3e73587d8bc2cacfc35b6d7e209ac [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 Haastregt91b30832020-02-05 16:05:20 +000063def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">;
Sven van Haastregt92451f02020-01-14 14:46:42 +000064def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +000065
66// Multiple extensions
Sven van Haastregt91b30832020-02-05 16:05:20 +000067def FuncExtKhrMipmapWritesAndWrite3d : FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000068
Sven van Haastregtb21a3652019-08-19 11:56:03 +000069// Qualified Type. These map to ASTContext::QualType.
70class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000071 // Name of the field or function in a clang::ASTContext
72 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
73 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000074 // Some QualTypes in this file represent an abstract type for which there is
75 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
76 // without access qualifiers.
77 bit IsAbstract = _IsAbstract;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000078}
79
Sven van Haastregtb21a3652019-08-19 11:56:03 +000080// List of integers.
81class IntList<string _Name, list<int> _List> {
82 string Name = _Name;
83 list<int> List = _List;
84}
85
Sven van Haastregt79a222f2019-06-03 09:39:11 +000086//===----------------------------------------------------------------------===//
87// OpenCL C classes for types
88//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000089// OpenCL C basic data types (int, float, image2d_t, ...).
Sven van Haastregt47e95ff2019-09-17 13:32:56 +000090// Its child classes can represent concrete types (e.g. VectorType) or
91// abstract types (e.g. GenType).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000092class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000093 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000094 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000095 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000096 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000097 // Size of the vector (if applicable).
98 int VecWidth = 1;
99 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000100 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000101 // "const" qualifier.
102 bit IsConst = 0;
103 // "volatile" qualifier.
104 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000105 // Access qualifier. Must be one of ("RO", "WO", "RW").
106 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000107 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000108 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000109}
110
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000111// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000112class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000113 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000114 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000115 // Inherited fields
116 let IsPointer = _Ty.IsPointer;
117 let IsConst = _Ty.IsConst;
118 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000119 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000120}
121
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000122// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000123class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000124 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000125 let AddrSpace = _AS.Name;
126 // Inherited fields
127 let VecWidth = _Ty.VecWidth;
128 let IsPointer = 1;
129 let IsConst = _Ty.IsConst;
130 let IsVolatile = _Ty.IsVolatile;
131 let AccessQualifier = _Ty.AccessQualifier;
132}
133
134// OpenCL const types (e.g. const int).
135class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
136 let IsConst = 1;
137 // Inherited fields
138 let VecWidth = _Ty.VecWidth;
139 let IsPointer = _Ty.IsPointer;
140 let IsVolatile = _Ty.IsVolatile;
141 let AccessQualifier = _Ty.AccessQualifier;
142 let AddrSpace = _Ty.AddrSpace;
143}
144
145// OpenCL volatile types (e.g. volatile int).
146class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
147 let IsVolatile = 1;
148 // Inherited fields
149 let VecWidth = _Ty.VecWidth;
150 let IsPointer = _Ty.IsPointer;
151 let IsConst = _Ty.IsConst;
152 let AccessQualifier = _Ty.AccessQualifier;
153 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000154}
155
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000156// OpenCL image types (e.g. image2d).
157class ImageType<Type _Ty, string _AccessQualifier> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000158 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000159 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000160 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000161 // Inherited fields
162 let IsPointer = _Ty.IsPointer;
163 let IsConst = _Ty.IsConst;
164 let IsVolatile = _Ty.IsVolatile;
165 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000166}
167
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000168// List of Types.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000169class TypeList<list<Type> _Type> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000170 list<Type> List = _Type;
171}
172
173// A GenericType is an abstract type that defines a set of types as a
174// combination of Types and vector sizes.
175//
Sven van Haastregt47e95ff2019-09-17 13:32:56 +0000176// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
177// represents <int, int2, int4, float, float2, float4>.
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000178//
179// Some rules apply when using multiple GenericType arguments in a declaration:
180// 1. The number of vector sizes must be equal or 1 for all gentypes in a
181// declaration.
182// 2. The number of Types must be equal or 1 for all gentypes in a
183// declaration.
184// 3. Generic types are combined by iterating over all generic types at once.
185// For example, for the following GenericTypes
186// GenT1 = GenericType<half, [1, 2]> and
187// GenT2 = GenericType<float, int, [1, 2]>
188// A declaration f(GenT1, GenT2) results in the combinations
189// f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
190// 4. "sgentype" from the OpenCL specification is supported by specifying
191// a single vector size.
192// For example, for the following GenericTypes
193// GenT = GenericType<half, int, [1, 2]> and
194// SGenT = GenericType<half, int, [1]>
195// A declaration f(GenT, SGenT) results in the combinations
196// f(half, half), f(half2, half), f(int, int), f(int2, int) .
197class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000198 Type<_Ty, QualType<"null", 1>> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000199 // Possible element types of the generic type.
200 TypeList TypeList = _TypeList;
201 // Possible vector sizes of the types in the TypeList.
202 IntList VectorList = _VectorList;
203 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
204 let VecWidth = 0;
205}
206
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000207// Builtin function attributes.
208def Attr {
209 list<bit> None = [0, 0, 0];
210 list<bit> Pure = [1, 0, 0];
211 list<bit> Const = [0, 1, 0];
212 list<bit> Convergent = [0, 0, 1];
213}
214
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000215//===----------------------------------------------------------------------===//
216// OpenCL C class for builtin functions
217//===----------------------------------------------------------------------===//
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000218class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000219 // Name of the builtin function
220 string Name = _Name;
221 // List of types used by the function. The first one is the return type and
222 // the following are the arguments. The list must have at least one element
223 // (the return type).
224 list<Type> Signature = _Signature;
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000225 // Function attribute __attribute__((pure))
226 bit IsPure = _Attributes[0];
227 // Function attribute __attribute__((const))
228 bit IsConst = _Attributes[1];
229 // Function attribute __attribute__((convergent))
230 bit IsConv = _Attributes[2];
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000231 // OpenCL extensions to which the function belongs.
232 FunctionExtension Extension = FuncExtNone;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000233 // Version of OpenCL from which the function is available (e.g.: CL10).
234 // MinVersion is inclusive.
235 Version MinVersion = CL10;
236 // Version of OpenCL from which the function is not supported anymore.
237 // MaxVersion is exclusive.
238 // CLAll makes the function available for all versions.
239 Version MaxVersion = CLAll;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000240}
241
242//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000243// Definitions of OpenCL C types
244//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000245
246// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000247def Bool : Type<"bool", QualType<"BoolTy">>;
248def Char : Type<"char", QualType<"CharTy">>;
249def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
250def Short : Type<"short", QualType<"ShortTy">>;
251def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
252def Int : Type<"int", QualType<"IntTy">>;
253def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
254def Long : Type<"long", QualType<"LongTy">>;
255def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
256def Float : Type<"float", QualType<"FloatTy">>;
257def Double : Type<"double", QualType<"DoubleTy">>;
258def Half : Type<"half", QualType<"HalfTy">>;
259def Size : Type<"size_t", QualType<"getSizeType()">>;
260def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
261def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
262def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000263def Void : Type<"void", QualType<"VoidTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000264
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000265// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
266// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000267
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000268// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
269// The image definitions are "abstract". They should not be used without
270// specifying an access qualifier (RO/WO/RW).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000271def Image1d : Type<"image1d_t", QualType<"OCLImage1d", 1>>;
272def Image2d : Type<"image2d_t", QualType<"OCLImage2d", 1>>;
273def Image3d : Type<"image3d_t", QualType<"OCLImage3d", 1>>;
274def Image1dArray : Type<"image1d_array_t", QualType<"OCLImage1dArray", 1>>;
275def Image1dBuffer : Type<"image1d_buffer_t", QualType<"OCLImage1dBuffer", 1>>;
276def Image2dArray : Type<"image2d_array_t", QualType<"OCLImage2dArray", 1>>;
277def Image2dDepth : Type<"image2d_depth_t", QualType<"OCLImage2dDepth", 1>>;
278def Image2dArrayDepth : Type<"image2d_array_depth_t", QualType<"OCLImage2dArrayDepth", 1>>;
279def Image2dMsaa : Type<"image2d_msaa_t", QualType<"OCLImage2dMSAA", 1>>;
280def Image2dArrayMsaa : Type<"image2d_array_msaa_t", QualType<"OCLImage2dArrayMSAA", 1>>;
281def Image2dMsaaDepth : Type<"image2d_msaa_depth_t", QualType<"OCLImage2dMSAADepth", 1>>;
282def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"OCLImage2dArrayMSAADepth", 1>>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000283
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000284def Sampler : Type<"sampler_t", QualType<"OCLSamplerTy">>;
285def Event : Type<"event_t", QualType<"OCLEventTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000286
287//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000288// Definitions of OpenCL gentype variants
289//===----------------------------------------------------------------------===//
290// The OpenCL specification often uses "gentype" in builtin function
291// declarations to indicate that a builtin function is available with various
292// argument and return types. The types represented by "gentype" vary between
293// different parts of the specification. The following definitions capture
294// the different type lists for gentypes in different parts of the
295// specification.
296
297// Vector width lists.
298def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
299def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
300def Vec1 : IntList<"Vec1", [1]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000301def Vec2 : IntList<"Vec2", [2]>;
302def Vec4 : IntList<"Vec4", [4]>;
303def Vec8 : IntList<"Vec8", [8]>;
304def Vec16 : IntList<"Vec16", [16]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000305def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000306
307// Type lists.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000308def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
309def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
310def TLFloat : TypeList<[Float, Double, Half]>;
311def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
312def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000313
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000314def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000315
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000316// All unsigned integer types twice, to facilitate unsigned return types for e.g.
317// uchar abs(char) and
318// uchar abs(uchar).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000319def TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000320
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000321def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000322
323// GenType definitions for multiple base types (e.g. all floating point types,
324// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000325// All types
326def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
327def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000328// All integer
329def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
330def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
331def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000332// All integer to unsigned
333def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000334// Signed integer
335def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
336// Unsigned integer
337def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000338// Float
339def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000340// (u)int, (u)long, and all floats
341def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000342
343// GenType definitions for every single base type (e.g. fp32 only).
344// Names are like: GenTypeFloatVecAndScalar.
345foreach Type = [Char, UChar, Short, UShort,
346 Int, UInt, Long, ULong,
347 Float, Double, Half] in {
348 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
349 def "GenType" # Type # VecSizes :
350 GenericType<"GenType" # Type # VecSizes,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000351 TypeList<[Type]>, VecSizes>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000352 }
353}
354
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000355// GenType definitions for vec1234.
356foreach Type = [Float, Double, Half] in {
357 def "GenType" # Type # Vec1234 :
358 GenericType<"GenType" # Type # Vec1234,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000359 TypeList<[Type]>, Vec1234>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000360}
361
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000362
363//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000364// Definitions of OpenCL builtin functions
365//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000366//--------------------------------------------------------------------
367// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
368// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
369
370// Generate the convert_* builtins functions.
371foreach RType = [Float, Double, Half, Char, UChar, Short,
372 UShort, Int, UInt, Long, ULong] in {
373 foreach IType = [Float, Double, Half, Char, UChar, Short,
374 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000375 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000376 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000377 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
378 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000379 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000380 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000381 [VectorType<RType, v>, VectorType<IType, v>],
382 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000383 }
384 }
385 }
386 }
387}
388
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000389//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000390// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
391// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000392def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000393foreach name = ["get_global_size", "get_global_id", "get_local_size",
394 "get_local_id", "get_num_groups", "get_group_id",
395 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000396 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000397}
398
399let MinVersion = CL20 in {
400 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
401 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
402 def : Builtin<name, [Size]>;
403 }
404}
405
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000406
Sven van Haastregted69faa2019-09-19 13:41:51 +0000407//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000408// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
409// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
410// --- Table 8 ---
411// --- 1 argument ---
412foreach name = ["acos", "acosh", "acospi",
413 "asin", "asinh", "asinpi",
414 "atan", "atanh", "atanpi",
415 "cbrt", "ceil",
416 "cos", "cosh", "cospi",
417 "erfc", "erf",
418 "exp", "exp2", "exp10", "expm1",
419 "fabs", "floor",
420 "log", "log2", "log10", "log1p", "logb",
421 "rint", "round", "rsqrt",
422 "sin", "sinh", "sinpi",
423 "sqrt",
424 "tan", "tanh", "tanpi",
425 "tgamma", "trunc",
426 "lgamma"] in {
427 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
428}
429foreach name = ["nan"] in {
430 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
431 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
432 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
433}
434
435// --- 2 arguments ---
436foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
437 "maxmag", "minmag", "nextafter", "pow", "powr",
438 "remainder"] in {
439 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
440}
441foreach name = ["fmax", "fmin"] in {
442 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
443 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
444 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
445 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
446}
447foreach name = ["ilogb"] in {
448 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
449 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
450 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
451}
452foreach name = ["ldexp"] in {
453 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
454 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
455 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
456 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
457 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
458 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
459}
460foreach name = ["pown", "rootn"] in {
461 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
462 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
463 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
464}
465
466// --- 3 arguments ---
467foreach name = ["fma", "mad"] in {
468 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
469}
470
471// --- Version dependent ---
472let MaxVersion = CL20 in {
473 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
474 foreach name = ["fract", "modf", "sincos"] in {
475 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
476 }
477 foreach name = ["frexp", "lgamma_r"] in {
478 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
479 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
480 }
481 }
482 foreach name = ["remquo"] in {
483 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
484 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
485 }
486 }
487 }
488}
489let MinVersion = CL20 in {
490 foreach name = ["fract", "modf", "sincos"] in {
491 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
492 }
493 foreach name = ["frexp", "lgamma_r"] in {
494 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
495 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
496 } }
497 foreach name = ["remquo"] in {
498 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
499 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
500 }
501 }
502}
503
504// --- Table 9 ---
505foreach name = ["half_cos",
506 "half_exp", "half_exp2", "half_exp10",
507 "half_log", "half_log2", "half_log10",
508 "half_recip", "half_rsqrt",
509 "half_sin", "half_sqrt", "half_tan",
510 "native_cos",
511 "native_exp", "native_exp2", "native_exp10",
512 "native_log", "native_log2", "native_log10",
513 "native_recip", "native_rsqrt",
514 "native_sin", "native_sqrt", "native_tan"] in {
515 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
516}
517foreach name = ["half_divide", "half_powr",
518 "native_divide", "native_powr"] in {
519 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
520}
521
522//--------------------------------------------------------------------
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000523// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
524// --- Table 10 ---
525// --- 1 argument ---
526foreach name = ["abs"] in {
527 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
528}
529foreach name = ["clz", "popcount"] in {
530 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
531}
532let MinVersion = CL20 in {
533 foreach name = ["ctz"] in {
534 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
535 }
536}
537
538// --- 2 arguments ---
539foreach name = ["abs_diff"] in {
540 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
541}
542foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
543 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
544}
545foreach name = ["max", "min"] in {
546 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
547 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
548}
549foreach name = ["upsample"] in {
550 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
551 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
552 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
553 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
554 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
555 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
556}
557
558// --- 3 arguments ---
559foreach name = ["clamp"] in {
560 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
561 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
562}
563foreach name = ["mad_hi", "mad_sat"] in {
564 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
565}
566
567// --- Table 11 ---
568foreach name = ["mad24"] in {
569 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
570 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
571}
572foreach name = ["mul24"] in {
573 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
574 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
575}
576
577//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000578// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
579// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
580// --- Table 12 ---
581// --- 1 argument ---
582foreach name = ["degrees", "radians", "sign"] in {
583 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
584}
585
586// --- 2 arguments ---
587foreach name = ["max", "min"] in {
588 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
589 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
590 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
591 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
592}
593foreach name = ["step"] in {
594 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
595 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
596 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
597 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
598}
599
600// --- 3 arguments ---
601foreach name = ["clamp", "mix"] in {
602 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
603 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
604 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
605 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
606}
607foreach name = ["smoothstep"] in {
608 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
609 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
610 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
611 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
612}
613
614
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000615//--------------------------------------------------------------------
616// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
617// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
618// --- Table 13 ---
619// --- 1 argument ---
620foreach name = ["length"] in {
621 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
622 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
623 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
624}
625foreach name = ["normalize"] in {
626 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
627 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
628 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
629}
630foreach name = ["fast_length"] in {
631 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
632}
633foreach name = ["fast_normalize"] in {
634 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
635}
636
637// --- 2 arguments ---
638foreach name = ["cross"] in {
639 foreach VSize = [3, 4] in {
640 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
641 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
642 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
643 }
644}
645foreach name = ["dot", "distance"] in {
646 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
647 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
648 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
649}
650foreach name = ["fast_distance"] in {
651 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
652}
653
654
655//--------------------------------------------------------------------
656// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
657// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
658// --- Table 14 ---
659// --- 1 argument ---
660foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
661 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
662 def : Builtin<name, [Int, Double], Attr.Const>;
663 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
664 def : Builtin<name, [Int, Half], Attr.Const>;
665 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
666}
667foreach name = ["any", "all"] in {
668 def : Builtin<name, [Int, AIGenTypeN], Attr.Const>;
669}
670
671// --- 2 arguments ---
672foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
673 "isless", "islessequal", "islessgreater", "isordered",
674 "isunordered"] in {
675 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
676 def : Builtin<name, [Int, Double, Double], Attr.Const>;
677 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
678 def : Builtin<name, [Int, Half, Half], Attr.Const>;
679 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
680}
681
682// --- 3 arguments ---
683foreach name = ["bitselect"] in {
684 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
685}
686foreach name = ["select"] in {
687 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
688 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
689 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
690 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
691 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
692 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
693 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
694 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
695 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
696 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
697}
698
699
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000700//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000701// 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 +0000702// 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 +0000703// --- Table 15 ---
704// Variants for OpenCL versions below 2.0, using pointers to the global, local
705// and private address spaces.
706let MaxVersion = CL20 in {
707 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
708 foreach VSize = [2, 3, 4, 8, 16] in {
709 foreach name = ["vload" # VSize] in {
710 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
711 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
712 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
713 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
714 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
715 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
716 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
717 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
718 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
719 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
720 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
721 }
722 foreach name = ["vstore" # VSize] in {
723 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
724 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
725 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
726 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
727 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
728 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
729 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
730 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
731 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
732 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
733 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
734 }
735 foreach name = ["vloada_half" # VSize] in {
736 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
737 }
738 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
739 foreach name = ["vstorea_half" # VSize # rnd] in {
740 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
741 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
742 }
743 }
744 }
745 }
746}
747// Variants for OpenCL versions above 2.0, using pointers to the generic
748// address space.
749let MinVersion = CL20 in {
750 foreach VSize = [2, 3, 4, 8, 16] in {
751 foreach name = ["vload" # VSize] in {
752 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
753 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
754 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
755 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
756 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
757 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
758 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
759 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
760 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
761 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
762 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
763 }
764 foreach name = ["vstore" # VSize] in {
765 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
766 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
767 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
768 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
769 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
770 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
771 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
772 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
773 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
774 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
775 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
776 }
777 foreach name = ["vloada_half" # VSize] in {
778 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
779 }
780 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
781 foreach name = ["vstorea_half" # VSize # rnd] in {
782 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
783 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
784 }
785 }
786 }
787}
788// Variants using pointers to the constant address space.
789foreach VSize = [2, 3, 4, 8, 16] in {
790 foreach name = ["vload" # VSize] in {
791 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
792 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
793 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
794 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
795 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
796 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
797 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
798 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
799 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
800 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
801 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
802 }
803 foreach name = ["vloada_half" # VSize] in {
804 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
805 }
806 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
807 foreach name = ["vstorea_half" # VSize # rnd] in {
808 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
809 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
810 }
811 }
812}
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000813let MaxVersion = CL20 in {
814 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
815 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
816 foreach VSize = [2, 3, 4, 8, 16] in {
817 foreach name = ["vload_half" # VSize] in {
818 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
819 }
820 }
821 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
822 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
823 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
824 foreach VSize = [2, 3, 4, 8, 16] in {
825 foreach name = ["vstore_half" # VSize # rnd] in {
826 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
827 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
828 }
829 }
830 }
831 }
832}
833let MinVersion = CL20 in {
834 foreach AS = [GenericAS] in {
835 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
836 foreach VSize = [2, 3, 4, 8, 16] in {
837 foreach name = ["vload_half" # VSize] in {
838 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
839 }
840 }
841 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
842 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
843 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
844 foreach VSize = [2, 3, 4, 8, 16] in {
845 foreach name = ["vstore_half" # VSize # rnd] in {
846 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
847 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
848 }
849 }
850 }
851 }
852}
853
854foreach AS = [ConstantAS] in {
855 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
856 foreach VSize = [2, 3, 4, 8, 16] in {
857 foreach name = ["vload_half" # VSize] in {
858 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
859 }
860 }
861}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000862
863//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000864// 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
865// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
866// --- Table 18 ---
867foreach name = ["async_work_group_copy"] in {
868 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
869 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
870}
871foreach name = ["async_work_group_strided_copy"] in {
872 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
873 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
874}
875foreach name = ["wait_group_events"] in {
876 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
877}
878foreach name = ["prefetch"] in {
879 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
880}
881
882//--------------------------------------------------------------------
883// OpenCL v2.0 s6.13.11 - Atomics Functions.
884// Functions that use memory_order and cl_mem_fence_flags enums are not
885// declared here as the TableGen backend does not handle enums.
886
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000887// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000888// --- Table 9.1 ---
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000889let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
890 foreach Type = [Int, UInt] in {
891 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
892 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
893 }
894 foreach name = ["atom_inc", "atom_dec"] in {
895 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
896 }
897 foreach name = ["atom_cmpxchg"] in {
898 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
899 }
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000900 }
901}
Sven van Haastregtb7145832019-12-23 12:29:01 +0000902// --- Table 9.3 ---
903let Extension = FuncExtKhrLocalInt32BaseAtomics in {
904 foreach Type = [Int, UInt] in {
905 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
906 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
907 }
908 foreach name = ["atom_inc", "atom_dec"] in {
909 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
910 }
911 foreach name = ["atom_cmpxchg"] in {
912 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
913 }
914 }
915}
916// --- Table 9.5 ---
917let Extension = FuncExtKhrInt64BaseAtomics in {
918 foreach AS = [GlobalAS, LocalAS] in {
919 foreach Type = [Long, ULong] in {
920 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
921 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
922 }
923 foreach name = ["atom_inc", "atom_dec"] in {
924 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
925 }
926 foreach name = ["atom_cmpxchg"] in {
927 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
928 }
929 }
930 }
931}
932// --- Table 9.2 ---
933let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
934 foreach Type = [Int, UInt] in {
935 foreach name = ["atom_min", "atom_max", "atom_and",
936 "atom_or", "atom_xor"] in {
937 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
938 }
939 }
940}
941// --- Table 9.4 ---
942let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
943 foreach Type = [Int, UInt] in {
944 foreach name = ["atom_min", "atom_max", "atom_and",
945 "atom_or", "atom_xor"] in {
946 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
947 }
948 }
949}
950// --- Table 9.6 ---
951let Extension = FuncExtKhrInt64ExtendedAtomics in {
952 foreach AS = [GlobalAS, LocalAS] in {
953 foreach Type = [Long, ULong] in {
954 foreach name = ["atom_min", "atom_max", "atom_and",
955 "atom_or", "atom_xor"] in {
956 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
957 }
958 }
959 }
960}
961// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
962foreach AS = [GlobalAS, LocalAS] in {
963 foreach Type = [Int, UInt] in {
964 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
965 "atomic_min", "atomic_max", "atomic_and",
966 "atomic_or", "atomic_xor"] in {
967 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
968 }
969 foreach name = ["atomic_inc", "atomic_dec"] in {
970 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
971 }
972 foreach name = ["atomic_cmpxchg"] in {
973 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
974 }
975 }
976}
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000977
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000978//--------------------------------------------------------------------
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000979// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
980// --- Table 19 ---
Sven van Haastregtff429c52019-12-31 15:30:02 +0000981foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
982 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
983 def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
984 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
985 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
986 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000987 }
988}
Sven van Haastregtff429c52019-12-31 15:30:02 +0000989foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
990 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
991 def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
992 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
993 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
994 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
995 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000996 }
997}
998
999//--------------------------------------------------------------------
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001000// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1001// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1002// --- Table 22: Image Read Functions with Samplers ---
1003foreach imgTy = [Image1d] in {
1004 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001005 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1006 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1007 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001008 }
1009}
1010foreach imgTy = [Image2d, Image1dArray] in {
1011 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001012 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1013 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1014 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001015 }
1016}
1017foreach imgTy = [Image3d, Image2dArray] in {
1018 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001019 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1020 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1021 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001022 }
1023}
1024foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001025 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1026 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001027}
1028
1029// --- Table 23: Sampler-less Read Functions ---
1030foreach aQual = ["RO", "RW"] in {
1031 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001032 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1033 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1034 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001035 }
1036 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001037 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1038 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1039 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001040 }
1041 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001042 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1043 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1044 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001045 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001046 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1047 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001048}
1049
1050// --- Table 24: Image Write Functions ---
1051foreach aQual = ["WO", "RW"] in {
1052 foreach imgTy = [Image2d] in {
1053 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1054 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1055 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1056 }
1057 foreach imgTy = [Image2dArray] in {
1058 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1059 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1060 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1061 }
1062 foreach imgTy = [Image1d, Image1dBuffer] in {
1063 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1064 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1065 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1066 }
1067 foreach imgTy = [Image1dArray] in {
1068 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1069 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1070 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1071 }
1072 foreach imgTy = [Image3d] in {
1073 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1074 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1075 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1076 }
1077 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1078 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1079}
1080
Sven van Haastregt2a69ed02019-09-25 09:12:59 +00001081// --- Table 25: Image Query Functions ---
1082foreach aQual = ["RO", "WO", "RW"] in {
1083 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1084 Image1dArray, Image2dArray, Image2dDepth,
1085 Image2dArrayDepth] in {
1086 foreach name = ["get_image_width", "get_image_channel_data_type",
1087 "get_image_channel_order"] in {
1088 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1089 }
1090 }
1091 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1092 Image2dArrayDepth] in {
1093 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1094 }
1095 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1096 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1097 Image2dArrayDepth] in {
1098 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1099 }
1100 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1101 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1102 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1103 }
1104}
1105
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001106// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1107// --- Table 8 ---
1108foreach aQual = ["RO"] in {
1109 foreach name = ["read_imageh"] in {
1110 foreach coordTy = [Int, Float] in {
1111 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001112 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001113 }
1114 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001115 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001116 }
1117 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001118 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001119 }
1120 }
1121 }
1122}
1123// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1124// --- Table 9 ---
1125foreach aQual = ["RO", "RW"] in {
1126 foreach name = ["read_imageh"] in {
1127 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001128 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001129 }
1130 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001131 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001132 }
1133 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001134 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001135 }
1136 }
1137}
1138// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1139// --- Table 10 ---
1140foreach aQual = ["WO", "RW"] in {
1141 foreach name = ["write_imageh"] in {
1142 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1143 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1144 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1145 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1146 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1147 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1148 }
1149}
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001150
1151
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001152//--------------------------------------------------------------------
1153// OpenCL v2.0 s6.13.15 - Work-group Functions
1154// --- Table 26 ---
1155let MinVersion = CL20 in {
1156 foreach name = ["work_group_all", "work_group_any"] in {
1157 def : Builtin<name, [Int, Int], Attr.Convergent>;
1158 }
1159 foreach name = ["work_group_broadcast"] in {
1160 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1161 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1162 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1163 }
1164 foreach op = ["add", "min", "max"] in {
1165 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1166 "work_group_scan_inclusive_"] in {
1167 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1168 }
1169 }
1170}
1171
1172
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001173// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +00001174let MinVersion = CL20 in {
Sven van Haastregt308b8b72019-12-18 10:13:51 +00001175 let Extension = FuncExtKhrSubgroups in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +00001176 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1177 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1178 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001179 }
1180}
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001181
1182//--------------------------------------------------------------------
1183// End of the builtin functions defined in the OpenCL C specification.
1184// Builtin functions defined in the OpenCL C Extension are below.
1185//--------------------------------------------------------------------
1186
1187
1188// OpenCL Extension v2.0 s9.18 - Mipmaps
1189let Extension = FuncExtKhrMipmapImage in {
1190 // Added to section 6.13.14.2.
1191 foreach aQual = ["RO"] in {
1192 foreach imgTy = [Image2d] in {
1193 foreach name = ["read_imagef"] in {
1194 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1195 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1196 }
1197 foreach name = ["read_imagei"] in {
1198 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1199 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1200 }
1201 foreach name = ["read_imageui"] in {
1202 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1203 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1204 }
1205 }
1206 foreach imgTy = [Image2dDepth] in {
1207 foreach name = ["read_imagef"] in {
1208 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1209 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1210 }
1211 }
1212 foreach imgTy = [Image1d] in {
1213 foreach name = ["read_imagef"] in {
1214 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1215 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1216 }
1217 foreach name = ["read_imagei"] in {
1218 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1219 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1220 }
1221 foreach name = ["read_imageui"] in {
1222 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1223 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1224 }
1225 }
1226 foreach imgTy = [Image3d] in {
1227 foreach name = ["read_imagef"] in {
1228 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1229 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1230 }
1231 foreach name = ["read_imagei"] in {
1232 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1233 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1234 }
1235 foreach name = ["read_imageui"] in {
1236 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1237 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1238 }
1239 }
1240 foreach imgTy = [Image1dArray] in {
1241 foreach name = ["read_imagef"] in {
1242 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1243 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1244 }
1245 foreach name = ["read_imagei"] in {
1246 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1247 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1248 }
1249 foreach name = ["read_imageui"] in {
1250 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1251 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1252 }
1253 }
1254 foreach imgTy = [Image2dArray] in {
1255 foreach name = ["read_imagef"] in {
1256 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1257 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1258 }
1259 foreach name = ["read_imagei"] in {
1260 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1261 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1262 }
1263 foreach name = ["read_imageui"] in {
1264 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1265 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1266 }
1267 }
1268 foreach imgTy = [Image2dArrayDepth] in {
1269 foreach name = ["read_imagef"] in {
1270 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1271 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1272 }
1273 }
1274 }
Sven van Haastregt91b30832020-02-05 16:05:20 +00001275 // Added to section 6.13.14.5
1276 foreach aQual = ["RO", "WO", "RW"] in {
1277 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1278 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
1279 }
1280 }
1281}
1282
1283// Write functions are enabled using a separate extension.
1284let Extension = FuncExtKhrMipmapImageWrites in {
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001285 // Added to section 6.13.14.4.
1286 foreach aQual = ["WO"] in {
1287 foreach imgTy = [Image2d] 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 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001292 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001293 foreach imgTy = [Image1d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001294 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1295 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1296 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001297 }
1298 foreach imgTy = [Image1dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001299 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1300 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1301 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001302 }
1303 foreach imgTy = [Image2dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001304 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1305 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1306 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001307 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001308 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
Sven van Haastregt91b30832020-02-05 16:05:20 +00001309 let Extension = FuncExtKhrMipmapWritesAndWrite3d in {
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001310 foreach imgTy = [Image3d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001311 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1312 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1313 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001314 }
1315 }
1316 }
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001317}
Sven van Haastregt92451f02020-01-14 14:46:42 +00001318
Sven van Haastregt92451f02020-01-14 14:46:42 +00001319//--------------------------------------------------------------------
1320// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1321let Extension = FuncExtKhrGlMsaaSharing in {
1322 // --- Table 6.13.14.3 ---
1323 foreach aQual = ["RO", "RW"] in {
1324 foreach imgTy = [Image2dMsaa] in {
1325 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1326 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1327 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1328 }
1329 foreach imgTy = [Image2dArrayMsaa] in {
1330 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1331 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1332 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1333 }
1334 foreach name = ["read_imagef"] in {
1335 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1336 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1337 }
1338 }
1339
1340 // --- Table 6.13.14.5 ---
1341 foreach aQual = ["RO", "WO", "RW"] in {
1342 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1343 foreach name = ["get_image_width", "get_image_height",
1344 "get_image_channel_data_type", "get_image_channel_order",
1345 "get_image_num_samples"] in {
1346 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1347 }
1348 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1349 }
1350 def : Builtin<"get_image_array_size", [Size, ImageType<Image2dArrayMsaaDepth, aQual>], Attr.Const>;
1351 }
1352}