blob: f0790dd325275fed92be3236fb6cb9d73677ae65 [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 Haastregt8b65f792020-02-18 10:02:06 +000069// Arm extensions.
70def ArmIntegerDotProductInt8 : FunctionExtension<"cl_arm_integer_dot_product_int8">;
71def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
72def ArmIntegerDotProductAccumulateInt16 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">;
73def ArmIntegerDotProductAccumulateSaturateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_saturate_int8">;
74
Sven van Haastregtb21a3652019-08-19 11:56:03 +000075// Qualified Type. These map to ASTContext::QualType.
76class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000077 // Name of the field or function in a clang::ASTContext
78 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
79 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000080 // Some QualTypes in this file represent an abstract type for which there is
81 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
82 // without access qualifiers.
83 bit IsAbstract = _IsAbstract;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000084}
85
Sven van Haastregtb21a3652019-08-19 11:56:03 +000086// List of integers.
87class IntList<string _Name, list<int> _List> {
88 string Name = _Name;
89 list<int> List = _List;
90}
91
Sven van Haastregt79a222f2019-06-03 09:39:11 +000092//===----------------------------------------------------------------------===//
93// OpenCL C classes for types
94//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000095// OpenCL C basic data types (int, float, image2d_t, ...).
Sven van Haastregt47e95ff2019-09-17 13:32:56 +000096// Its child classes can represent concrete types (e.g. VectorType) or
97// abstract types (e.g. GenType).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000098class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000099 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000100 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000101 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000102 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000103 // Size of the vector (if applicable).
104 int VecWidth = 1;
105 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000106 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000107 // "const" qualifier.
108 bit IsConst = 0;
109 // "volatile" qualifier.
110 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000111 // Access qualifier. Must be one of ("RO", "WO", "RW").
112 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000113 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000114 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000115}
116
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000117// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000118class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000119 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000120 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000121 // Inherited fields
122 let IsPointer = _Ty.IsPointer;
123 let IsConst = _Ty.IsConst;
124 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000125 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000126}
127
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000128// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000129class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000130 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000131 let AddrSpace = _AS.Name;
132 // Inherited fields
133 let VecWidth = _Ty.VecWidth;
134 let IsPointer = 1;
135 let IsConst = _Ty.IsConst;
136 let IsVolatile = _Ty.IsVolatile;
137 let AccessQualifier = _Ty.AccessQualifier;
138}
139
140// OpenCL const types (e.g. const int).
141class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
142 let IsConst = 1;
143 // Inherited fields
144 let VecWidth = _Ty.VecWidth;
145 let IsPointer = _Ty.IsPointer;
146 let IsVolatile = _Ty.IsVolatile;
147 let AccessQualifier = _Ty.AccessQualifier;
148 let AddrSpace = _Ty.AddrSpace;
149}
150
151// OpenCL volatile types (e.g. volatile int).
152class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
153 let IsVolatile = 1;
154 // Inherited fields
155 let VecWidth = _Ty.VecWidth;
156 let IsPointer = _Ty.IsPointer;
157 let IsConst = _Ty.IsConst;
158 let AccessQualifier = _Ty.AccessQualifier;
159 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000160}
161
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000162// OpenCL image types (e.g. image2d).
163class ImageType<Type _Ty, string _AccessQualifier> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000164 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000165 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000166 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000167 // Inherited fields
168 let IsPointer = _Ty.IsPointer;
169 let IsConst = _Ty.IsConst;
170 let IsVolatile = _Ty.IsVolatile;
171 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000172}
173
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000174// List of Types.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000175class TypeList<list<Type> _Type> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000176 list<Type> List = _Type;
177}
178
179// A GenericType is an abstract type that defines a set of types as a
180// combination of Types and vector sizes.
181//
Sven van Haastregt47e95ff2019-09-17 13:32:56 +0000182// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
183// represents <int, int2, int4, float, float2, float4>.
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000184//
185// Some rules apply when using multiple GenericType arguments in a declaration:
186// 1. The number of vector sizes must be equal or 1 for all gentypes in a
187// declaration.
188// 2. The number of Types must be equal or 1 for all gentypes in a
189// declaration.
190// 3. Generic types are combined by iterating over all generic types at once.
191// For example, for the following GenericTypes
192// GenT1 = GenericType<half, [1, 2]> and
193// GenT2 = GenericType<float, int, [1, 2]>
194// A declaration f(GenT1, GenT2) results in the combinations
195// f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
196// 4. "sgentype" from the OpenCL specification is supported by specifying
197// a single vector size.
198// For example, for the following GenericTypes
199// GenT = GenericType<half, int, [1, 2]> and
200// SGenT = GenericType<half, int, [1]>
201// A declaration f(GenT, SGenT) results in the combinations
202// f(half, half), f(half2, half), f(int, int), f(int2, int) .
203class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000204 Type<_Ty, QualType<"null", 1>> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000205 // Possible element types of the generic type.
206 TypeList TypeList = _TypeList;
207 // Possible vector sizes of the types in the TypeList.
208 IntList VectorList = _VectorList;
209 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
210 let VecWidth = 0;
211}
212
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000213// Builtin function attributes.
214def Attr {
215 list<bit> None = [0, 0, 0];
216 list<bit> Pure = [1, 0, 0];
217 list<bit> Const = [0, 1, 0];
218 list<bit> Convergent = [0, 0, 1];
219}
220
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000221//===----------------------------------------------------------------------===//
222// OpenCL C class for builtin functions
223//===----------------------------------------------------------------------===//
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000224class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000225 // Name of the builtin function
226 string Name = _Name;
227 // List of types used by the function. The first one is the return type and
228 // the following are the arguments. The list must have at least one element
229 // (the return type).
230 list<Type> Signature = _Signature;
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000231 // Function attribute __attribute__((pure))
232 bit IsPure = _Attributes[0];
233 // Function attribute __attribute__((const))
234 bit IsConst = _Attributes[1];
235 // Function attribute __attribute__((convergent))
236 bit IsConv = _Attributes[2];
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000237 // OpenCL extensions to which the function belongs.
238 FunctionExtension Extension = FuncExtNone;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000239 // Version of OpenCL from which the function is available (e.g.: CL10).
240 // MinVersion is inclusive.
241 Version MinVersion = CL10;
242 // Version of OpenCL from which the function is not supported anymore.
243 // MaxVersion is exclusive.
244 // CLAll makes the function available for all versions.
245 Version MaxVersion = CLAll;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000246}
247
248//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000249// Definitions of OpenCL C types
250//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000251
252// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000253def Bool : Type<"bool", QualType<"BoolTy">>;
254def Char : Type<"char", QualType<"CharTy">>;
255def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
256def Short : Type<"short", QualType<"ShortTy">>;
257def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
258def Int : Type<"int", QualType<"IntTy">>;
259def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
260def Long : Type<"long", QualType<"LongTy">>;
261def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
262def Float : Type<"float", QualType<"FloatTy">>;
263def Double : Type<"double", QualType<"DoubleTy">>;
264def Half : Type<"half", QualType<"HalfTy">>;
265def Size : Type<"size_t", QualType<"getSizeType()">>;
266def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
267def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
268def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000269def Void : Type<"void", QualType<"VoidTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000270
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000271// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
272// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000273
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000274// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
275// The image definitions are "abstract". They should not be used without
276// specifying an access qualifier (RO/WO/RW).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000277def Image1d : Type<"image1d_t", QualType<"OCLImage1d", 1>>;
278def Image2d : Type<"image2d_t", QualType<"OCLImage2d", 1>>;
279def Image3d : Type<"image3d_t", QualType<"OCLImage3d", 1>>;
280def Image1dArray : Type<"image1d_array_t", QualType<"OCLImage1dArray", 1>>;
281def Image1dBuffer : Type<"image1d_buffer_t", QualType<"OCLImage1dBuffer", 1>>;
282def Image2dArray : Type<"image2d_array_t", QualType<"OCLImage2dArray", 1>>;
283def Image2dDepth : Type<"image2d_depth_t", QualType<"OCLImage2dDepth", 1>>;
284def Image2dArrayDepth : Type<"image2d_array_depth_t", QualType<"OCLImage2dArrayDepth", 1>>;
285def Image2dMsaa : Type<"image2d_msaa_t", QualType<"OCLImage2dMSAA", 1>>;
286def Image2dArrayMsaa : Type<"image2d_array_msaa_t", QualType<"OCLImage2dArrayMSAA", 1>>;
287def Image2dMsaaDepth : Type<"image2d_msaa_depth_t", QualType<"OCLImage2dMSAADepth", 1>>;
288def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"OCLImage2dArrayMSAADepth", 1>>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000289
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000290def Sampler : Type<"sampler_t", QualType<"OCLSamplerTy">>;
291def Event : Type<"event_t", QualType<"OCLEventTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000292
293//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000294// Definitions of OpenCL gentype variants
295//===----------------------------------------------------------------------===//
296// The OpenCL specification often uses "gentype" in builtin function
297// declarations to indicate that a builtin function is available with various
298// argument and return types. The types represented by "gentype" vary between
299// different parts of the specification. The following definitions capture
300// the different type lists for gentypes in different parts of the
301// specification.
302
303// Vector width lists.
304def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
305def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
306def Vec1 : IntList<"Vec1", [1]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000307def Vec2 : IntList<"Vec2", [2]>;
308def Vec4 : IntList<"Vec4", [4]>;
309def Vec8 : IntList<"Vec8", [8]>;
310def Vec16 : IntList<"Vec16", [16]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000311def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000312
313// Type lists.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000314def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
315def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
316def TLFloat : TypeList<[Float, Double, Half]>;
317def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
318def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000319
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000320def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000321
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000322// All unsigned integer types twice, to facilitate unsigned return types for e.g.
323// uchar abs(char) and
324// uchar abs(uchar).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000325def TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000326
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000327def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000328
329// GenType definitions for multiple base types (e.g. all floating point types,
330// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000331// All types
332def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
333def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000334// All integer
335def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
336def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
337def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000338// All integer to unsigned
339def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000340// Signed integer
341def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
342// Unsigned integer
343def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000344// Float
345def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000346// (u)int, (u)long, and all floats
347def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000348
349// GenType definitions for every single base type (e.g. fp32 only).
350// Names are like: GenTypeFloatVecAndScalar.
351foreach Type = [Char, UChar, Short, UShort,
352 Int, UInt, Long, ULong,
353 Float, Double, Half] in {
354 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
355 def "GenType" # Type # VecSizes :
356 GenericType<"GenType" # Type # VecSizes,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000357 TypeList<[Type]>, VecSizes>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000358 }
359}
360
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000361// GenType definitions for vec1234.
362foreach Type = [Float, Double, Half] in {
363 def "GenType" # Type # Vec1234 :
364 GenericType<"GenType" # Type # Vec1234,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000365 TypeList<[Type]>, Vec1234>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000366}
367
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000368
369//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000370// Definitions of OpenCL builtin functions
371//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000372//--------------------------------------------------------------------
373// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
374// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
375
376// Generate the convert_* builtins functions.
377foreach RType = [Float, Double, Half, Char, UChar, Short,
378 UShort, Int, UInt, Long, ULong] in {
379 foreach IType = [Float, Double, Half, Char, UChar, Short,
380 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000381 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000382 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000383 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
384 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000385 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000386 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000387 [VectorType<RType, v>, VectorType<IType, v>],
388 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000389 }
390 }
391 }
392 }
393}
394
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000395//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000396// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
397// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000398def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000399foreach name = ["get_global_size", "get_global_id", "get_local_size",
400 "get_local_id", "get_num_groups", "get_group_id",
401 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000402 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000403}
404
405let MinVersion = CL20 in {
406 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
407 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
408 def : Builtin<name, [Size]>;
409 }
410}
411
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000412
Sven van Haastregted69faa2019-09-19 13:41:51 +0000413//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000414// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
415// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
416// --- Table 8 ---
417// --- 1 argument ---
418foreach name = ["acos", "acosh", "acospi",
419 "asin", "asinh", "asinpi",
420 "atan", "atanh", "atanpi",
421 "cbrt", "ceil",
422 "cos", "cosh", "cospi",
423 "erfc", "erf",
424 "exp", "exp2", "exp10", "expm1",
425 "fabs", "floor",
426 "log", "log2", "log10", "log1p", "logb",
427 "rint", "round", "rsqrt",
428 "sin", "sinh", "sinpi",
429 "sqrt",
430 "tan", "tanh", "tanpi",
431 "tgamma", "trunc",
432 "lgamma"] in {
433 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
434}
435foreach name = ["nan"] in {
436 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
437 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
438 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
439}
440
441// --- 2 arguments ---
442foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
443 "maxmag", "minmag", "nextafter", "pow", "powr",
444 "remainder"] in {
445 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
446}
447foreach name = ["fmax", "fmin"] in {
448 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
449 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
450 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
451 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
452}
453foreach name = ["ilogb"] in {
454 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
455 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
456 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
457}
458foreach name = ["ldexp"] in {
459 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
460 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
461 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
462 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
463 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
464 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
465}
466foreach name = ["pown", "rootn"] in {
467 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
468 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
469 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
470}
471
472// --- 3 arguments ---
473foreach name = ["fma", "mad"] in {
474 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
475}
476
477// --- Version dependent ---
478let MaxVersion = CL20 in {
479 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
480 foreach name = ["fract", "modf", "sincos"] in {
481 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
482 }
483 foreach name = ["frexp", "lgamma_r"] in {
484 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
485 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
486 }
487 }
488 foreach name = ["remquo"] in {
489 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
490 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
491 }
492 }
493 }
494}
495let MinVersion = CL20 in {
496 foreach name = ["fract", "modf", "sincos"] in {
497 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
498 }
499 foreach name = ["frexp", "lgamma_r"] in {
500 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
501 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
502 } }
503 foreach name = ["remquo"] in {
504 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
505 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
506 }
507 }
508}
509
510// --- Table 9 ---
511foreach name = ["half_cos",
512 "half_exp", "half_exp2", "half_exp10",
513 "half_log", "half_log2", "half_log10",
514 "half_recip", "half_rsqrt",
515 "half_sin", "half_sqrt", "half_tan",
516 "native_cos",
517 "native_exp", "native_exp2", "native_exp10",
518 "native_log", "native_log2", "native_log10",
519 "native_recip", "native_rsqrt",
520 "native_sin", "native_sqrt", "native_tan"] in {
521 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
522}
523foreach name = ["half_divide", "half_powr",
524 "native_divide", "native_powr"] in {
525 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
526}
527
528//--------------------------------------------------------------------
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000529// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
530// --- Table 10 ---
531// --- 1 argument ---
532foreach name = ["abs"] in {
533 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
534}
535foreach name = ["clz", "popcount"] in {
536 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
537}
538let MinVersion = CL20 in {
539 foreach name = ["ctz"] in {
540 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
541 }
542}
543
544// --- 2 arguments ---
545foreach name = ["abs_diff"] in {
546 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
547}
548foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
549 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
550}
551foreach name = ["max", "min"] in {
552 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
553 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
554}
555foreach name = ["upsample"] in {
556 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
557 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
558 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
559 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
560 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
561 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
562}
563
564// --- 3 arguments ---
565foreach name = ["clamp"] in {
566 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
567 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
568}
569foreach name = ["mad_hi", "mad_sat"] in {
570 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
571}
572
573// --- Table 11 ---
574foreach name = ["mad24"] in {
575 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
576 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
577}
578foreach name = ["mul24"] in {
579 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
580 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
581}
582
583//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000584// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
585// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
586// --- Table 12 ---
587// --- 1 argument ---
588foreach name = ["degrees", "radians", "sign"] in {
589 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
590}
591
592// --- 2 arguments ---
593foreach name = ["max", "min"] in {
594 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
595 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
596 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
597 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
598}
599foreach name = ["step"] in {
600 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
601 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
602 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
603 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
604}
605
606// --- 3 arguments ---
607foreach name = ["clamp", "mix"] in {
608 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
609 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
610 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
611 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
612}
613foreach name = ["smoothstep"] in {
614 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
615 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
616 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
617 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
618}
619
620
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000621//--------------------------------------------------------------------
622// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
623// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
624// --- Table 13 ---
625// --- 1 argument ---
626foreach name = ["length"] in {
627 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
628 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
629 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
630}
631foreach name = ["normalize"] in {
632 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
633 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
634 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
635}
636foreach name = ["fast_length"] in {
637 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
638}
639foreach name = ["fast_normalize"] in {
640 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
641}
642
643// --- 2 arguments ---
644foreach name = ["cross"] in {
645 foreach VSize = [3, 4] in {
646 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
647 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
648 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
649 }
650}
651foreach name = ["dot", "distance"] in {
652 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
653 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
654 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
655}
656foreach name = ["fast_distance"] in {
657 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
658}
659
660
661//--------------------------------------------------------------------
662// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
663// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
664// --- Table 14 ---
665// --- 1 argument ---
666foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
667 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
668 def : Builtin<name, [Int, Double], Attr.Const>;
669 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
670 def : Builtin<name, [Int, Half], Attr.Const>;
671 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
672}
673foreach name = ["any", "all"] in {
674 def : Builtin<name, [Int, AIGenTypeN], Attr.Const>;
675}
676
677// --- 2 arguments ---
678foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
679 "isless", "islessequal", "islessgreater", "isordered",
680 "isunordered"] in {
681 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
682 def : Builtin<name, [Int, Double, Double], Attr.Const>;
683 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
684 def : Builtin<name, [Int, Half, Half], Attr.Const>;
685 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
686}
687
688// --- 3 arguments ---
689foreach name = ["bitselect"] in {
690 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
691}
692foreach name = ["select"] in {
693 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
694 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
695 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
696 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
697 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
698 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
699 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
700 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
701 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
702 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
703}
704
705
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000706//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000707// 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 +0000708// 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 +0000709// --- Table 15 ---
710// Variants for OpenCL versions below 2.0, using pointers to the global, local
711// and private address spaces.
712let MaxVersion = CL20 in {
713 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
714 foreach VSize = [2, 3, 4, 8, 16] in {
715 foreach name = ["vload" # VSize] in {
716 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
717 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
718 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
719 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
720 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
721 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
722 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
723 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
724 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
725 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
726 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
727 }
728 foreach name = ["vstore" # VSize] in {
729 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
730 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
731 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
732 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
733 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
734 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
735 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
736 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
737 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
738 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
739 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
740 }
741 foreach name = ["vloada_half" # VSize] in {
742 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
743 }
744 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
745 foreach name = ["vstorea_half" # VSize # rnd] in {
746 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
747 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
748 }
749 }
750 }
751 }
752}
753// Variants for OpenCL versions above 2.0, using pointers to the generic
754// address space.
755let MinVersion = CL20 in {
756 foreach VSize = [2, 3, 4, 8, 16] in {
757 foreach name = ["vload" # VSize] in {
758 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
759 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
760 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
761 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
762 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
763 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
764 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
765 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
766 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
767 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
768 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
769 }
770 foreach name = ["vstore" # VSize] in {
771 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
772 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
773 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
774 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
775 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
776 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
777 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
778 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
779 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
780 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
781 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
782 }
783 foreach name = ["vloada_half" # VSize] in {
784 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
785 }
786 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
787 foreach name = ["vstorea_half" # VSize # rnd] in {
788 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
789 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
790 }
791 }
792 }
793}
794// Variants using pointers to the constant address space.
795foreach VSize = [2, 3, 4, 8, 16] in {
796 foreach name = ["vload" # VSize] in {
797 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
798 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
799 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
800 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
801 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
802 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
803 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
804 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
805 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
806 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
807 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
808 }
809 foreach name = ["vloada_half" # VSize] in {
810 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
811 }
812 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
813 foreach name = ["vstorea_half" # VSize # rnd] in {
814 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
815 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
816 }
817 }
818}
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000819let MaxVersion = CL20 in {
820 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
821 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
822 foreach VSize = [2, 3, 4, 8, 16] in {
823 foreach name = ["vload_half" # VSize] in {
824 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
825 }
826 }
827 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
828 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
829 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
830 foreach VSize = [2, 3, 4, 8, 16] in {
831 foreach name = ["vstore_half" # VSize # rnd] in {
832 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
833 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
834 }
835 }
836 }
837 }
838}
839let MinVersion = CL20 in {
840 foreach AS = [GenericAS] in {
841 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
842 foreach VSize = [2, 3, 4, 8, 16] in {
843 foreach name = ["vload_half" # VSize] in {
844 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
845 }
846 }
847 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
848 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
849 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
850 foreach VSize = [2, 3, 4, 8, 16] in {
851 foreach name = ["vstore_half" # VSize # rnd] in {
852 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
853 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
854 }
855 }
856 }
857 }
858}
859
860foreach AS = [ConstantAS] in {
861 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
862 foreach VSize = [2, 3, 4, 8, 16] in {
863 foreach name = ["vload_half" # VSize] in {
864 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
865 }
866 }
867}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000868
869//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000870// 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
871// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
872// --- Table 18 ---
873foreach name = ["async_work_group_copy"] in {
874 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
875 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
876}
877foreach name = ["async_work_group_strided_copy"] in {
878 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
879 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
880}
881foreach name = ["wait_group_events"] in {
882 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
883}
884foreach name = ["prefetch"] in {
885 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
886}
887
888//--------------------------------------------------------------------
889// OpenCL v2.0 s6.13.11 - Atomics Functions.
890// Functions that use memory_order and cl_mem_fence_flags enums are not
891// declared here as the TableGen backend does not handle enums.
892
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000893// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000894// --- Table 9.1 ---
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000895let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
896 foreach Type = [Int, UInt] in {
897 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
898 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
899 }
900 foreach name = ["atom_inc", "atom_dec"] in {
901 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
902 }
903 foreach name = ["atom_cmpxchg"] in {
904 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
905 }
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000906 }
907}
Sven van Haastregtb7145832019-12-23 12:29:01 +0000908// --- Table 9.3 ---
909let Extension = FuncExtKhrLocalInt32BaseAtomics in {
910 foreach Type = [Int, UInt] in {
911 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
912 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
913 }
914 foreach name = ["atom_inc", "atom_dec"] in {
915 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
916 }
917 foreach name = ["atom_cmpxchg"] in {
918 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
919 }
920 }
921}
922// --- Table 9.5 ---
923let Extension = FuncExtKhrInt64BaseAtomics in {
924 foreach AS = [GlobalAS, LocalAS] in {
925 foreach Type = [Long, ULong] in {
926 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
927 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
928 }
929 foreach name = ["atom_inc", "atom_dec"] in {
930 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
931 }
932 foreach name = ["atom_cmpxchg"] in {
933 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
934 }
935 }
936 }
937}
938// --- Table 9.2 ---
939let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
940 foreach Type = [Int, UInt] in {
941 foreach name = ["atom_min", "atom_max", "atom_and",
942 "atom_or", "atom_xor"] in {
943 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
944 }
945 }
946}
947// --- Table 9.4 ---
948let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
949 foreach Type = [Int, UInt] in {
950 foreach name = ["atom_min", "atom_max", "atom_and",
951 "atom_or", "atom_xor"] in {
952 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
953 }
954 }
955}
956// --- Table 9.6 ---
957let Extension = FuncExtKhrInt64ExtendedAtomics in {
958 foreach AS = [GlobalAS, LocalAS] in {
959 foreach Type = [Long, ULong] in {
960 foreach name = ["atom_min", "atom_max", "atom_and",
961 "atom_or", "atom_xor"] in {
962 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
963 }
964 }
965 }
966}
967// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
968foreach AS = [GlobalAS, LocalAS] in {
969 foreach Type = [Int, UInt] in {
970 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
971 "atomic_min", "atomic_max", "atomic_and",
972 "atomic_or", "atomic_xor"] in {
973 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
974 }
975 foreach name = ["atomic_inc", "atomic_dec"] in {
976 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
977 }
978 foreach name = ["atomic_cmpxchg"] in {
979 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
980 }
981 }
982}
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000983
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000984//--------------------------------------------------------------------
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000985// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
986// --- Table 19 ---
Sven van Haastregtff429c52019-12-31 15:30:02 +0000987foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
988 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
989 def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
990 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
991 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
992 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000993 }
994}
Sven van Haastregtff429c52019-12-31 15:30:02 +0000995foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
996 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
997 def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
998 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
999 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1000 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
1001 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001002 }
1003}
1004
1005//--------------------------------------------------------------------
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001006// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1007// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1008// --- Table 22: Image Read Functions with Samplers ---
1009foreach imgTy = [Image1d] 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, coordTy], Attr.Pure>;
1012 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1013 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001014 }
1015}
1016foreach imgTy = [Image2d, Image1dArray] 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, 2>], Attr.Pure>;
1019 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1020 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001021 }
1022}
1023foreach imgTy = [Image3d, Image2dArray] in {
1024 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001025 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1026 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1027 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001028 }
1029}
1030foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001031 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1032 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001033}
1034
1035// --- Table 23: Sampler-less Read Functions ---
1036foreach aQual = ["RO", "RW"] in {
1037 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001038 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1039 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1040 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001041 }
1042 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001043 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1044 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1045 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001046 }
1047 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001048 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1049 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1050 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001051 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001052 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1053 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001054}
1055
1056// --- Table 24: Image Write Functions ---
1057foreach aQual = ["WO", "RW"] in {
1058 foreach imgTy = [Image2d] in {
1059 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1060 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1061 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1062 }
1063 foreach imgTy = [Image2dArray] in {
1064 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1065 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1066 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1067 }
1068 foreach imgTy = [Image1d, Image1dBuffer] in {
1069 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1070 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1071 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1072 }
1073 foreach imgTy = [Image1dArray] in {
1074 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1075 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1076 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1077 }
1078 foreach imgTy = [Image3d] in {
1079 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1080 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1081 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1082 }
1083 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1084 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1085}
1086
Sven van Haastregt2a69ed02019-09-25 09:12:59 +00001087// --- Table 25: Image Query Functions ---
1088foreach aQual = ["RO", "WO", "RW"] in {
1089 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1090 Image1dArray, Image2dArray, Image2dDepth,
1091 Image2dArrayDepth] in {
1092 foreach name = ["get_image_width", "get_image_channel_data_type",
1093 "get_image_channel_order"] in {
1094 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1095 }
1096 }
1097 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1098 Image2dArrayDepth] in {
1099 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1100 }
1101 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1102 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1103 Image2dArrayDepth] in {
1104 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1105 }
1106 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1107 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1108 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1109 }
1110}
1111
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001112// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1113// --- Table 8 ---
1114foreach aQual = ["RO"] in {
1115 foreach name = ["read_imageh"] in {
1116 foreach coordTy = [Int, Float] in {
1117 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001118 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001119 }
1120 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001121 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001122 }
1123 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001124 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001125 }
1126 }
1127 }
1128}
1129// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1130// --- Table 9 ---
1131foreach aQual = ["RO", "RW"] in {
1132 foreach name = ["read_imageh"] in {
1133 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001134 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001135 }
1136 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001137 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001138 }
1139 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001140 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001141 }
1142 }
1143}
1144// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1145// --- Table 10 ---
1146foreach aQual = ["WO", "RW"] in {
1147 foreach name = ["write_imageh"] in {
1148 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1149 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1150 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1151 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1152 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1153 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1154 }
1155}
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001156
1157
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001158//--------------------------------------------------------------------
1159// OpenCL v2.0 s6.13.15 - Work-group Functions
1160// --- Table 26 ---
1161let MinVersion = CL20 in {
1162 foreach name = ["work_group_all", "work_group_any"] in {
1163 def : Builtin<name, [Int, Int], Attr.Convergent>;
1164 }
1165 foreach name = ["work_group_broadcast"] in {
1166 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1167 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1168 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1169 }
1170 foreach op = ["add", "min", "max"] in {
1171 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1172 "work_group_scan_inclusive_"] in {
1173 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1174 }
1175 }
1176}
1177
1178
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001179// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +00001180let MinVersion = CL20 in {
Sven van Haastregt308b8b72019-12-18 10:13:51 +00001181 let Extension = FuncExtKhrSubgroups in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +00001182 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1183 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1184 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001185 }
1186}
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001187
1188//--------------------------------------------------------------------
1189// End of the builtin functions defined in the OpenCL C specification.
1190// Builtin functions defined in the OpenCL C Extension are below.
1191//--------------------------------------------------------------------
1192
1193
1194// OpenCL Extension v2.0 s9.18 - Mipmaps
1195let Extension = FuncExtKhrMipmapImage in {
1196 // Added to section 6.13.14.2.
1197 foreach aQual = ["RO"] in {
1198 foreach imgTy = [Image2d] in {
1199 foreach name = ["read_imagef"] in {
1200 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1201 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1202 }
1203 foreach name = ["read_imagei"] in {
1204 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1205 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1206 }
1207 foreach name = ["read_imageui"] in {
1208 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1209 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1210 }
1211 }
1212 foreach imgTy = [Image2dDepth] in {
1213 foreach name = ["read_imagef"] in {
1214 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1215 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1216 }
1217 }
1218 foreach imgTy = [Image1d] in {
1219 foreach name = ["read_imagef"] in {
1220 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1221 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1222 }
1223 foreach name = ["read_imagei"] in {
1224 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1225 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1226 }
1227 foreach name = ["read_imageui"] in {
1228 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1229 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1230 }
1231 }
1232 foreach imgTy = [Image3d] in {
1233 foreach name = ["read_imagef"] in {
1234 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1235 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1236 }
1237 foreach name = ["read_imagei"] in {
1238 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1239 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1240 }
1241 foreach name = ["read_imageui"] in {
1242 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1243 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1244 }
1245 }
1246 foreach imgTy = [Image1dArray] in {
1247 foreach name = ["read_imagef"] in {
1248 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1249 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1250 }
1251 foreach name = ["read_imagei"] in {
1252 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1253 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1254 }
1255 foreach name = ["read_imageui"] in {
1256 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1257 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1258 }
1259 }
1260 foreach imgTy = [Image2dArray] in {
1261 foreach name = ["read_imagef"] in {
1262 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1263 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1264 }
1265 foreach name = ["read_imagei"] in {
1266 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1267 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1268 }
1269 foreach name = ["read_imageui"] 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 foreach imgTy = [Image2dArrayDepth] in {
1275 foreach name = ["read_imagef"] in {
1276 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1277 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1278 }
1279 }
1280 }
Sven van Haastregt91b30832020-02-05 16:05:20 +00001281 // Added to section 6.13.14.5
1282 foreach aQual = ["RO", "WO", "RW"] in {
1283 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1284 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
1285 }
1286 }
1287}
1288
1289// Write functions are enabled using a separate extension.
1290let Extension = FuncExtKhrMipmapImageWrites in {
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001291 // Added to section 6.13.14.4.
1292 foreach aQual = ["WO"] in {
1293 foreach imgTy = [Image2d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001294 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1295 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1296 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001297 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001298 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001299 foreach imgTy = [Image1d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001300 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1301 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1302 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001303 }
1304 foreach imgTy = [Image1dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001305 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1306 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1307 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001308 }
1309 foreach imgTy = [Image2dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001310 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1311 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1312 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001313 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001314 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
Sven van Haastregt91b30832020-02-05 16:05:20 +00001315 let Extension = FuncExtKhrMipmapWritesAndWrite3d in {
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001316 foreach imgTy = [Image3d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001317 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1318 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1319 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001320 }
1321 }
1322 }
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001323}
Sven van Haastregt92451f02020-01-14 14:46:42 +00001324
Sven van Haastregt92451f02020-01-14 14:46:42 +00001325//--------------------------------------------------------------------
1326// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1327let Extension = FuncExtKhrGlMsaaSharing in {
1328 // --- Table 6.13.14.3 ---
1329 foreach aQual = ["RO", "RW"] in {
1330 foreach imgTy = [Image2dMsaa] in {
1331 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1332 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1333 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1334 }
1335 foreach imgTy = [Image2dArrayMsaa] in {
1336 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1337 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1338 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1339 }
1340 foreach name = ["read_imagef"] in {
1341 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1342 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1343 }
1344 }
1345
1346 // --- Table 6.13.14.5 ---
1347 foreach aQual = ["RO", "WO", "RW"] in {
1348 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1349 foreach name = ["get_image_width", "get_image_height",
1350 "get_image_channel_data_type", "get_image_channel_order",
1351 "get_image_num_samples"] in {
1352 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1353 }
1354 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1355 }
1356 def : Builtin<"get_image_array_size", [Size, ImageType<Image2dArrayMsaaDepth, aQual>], Attr.Const>;
1357 }
1358}
Sven van Haastregt8b65f792020-02-18 10:02:06 +00001359
1360//--------------------------------------------------------------------
1361// Arm extensions.
1362let Extension = ArmIntegerDotProductInt8 in {
1363 foreach name = ["arm_dot"] in {
1364 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>;
1365 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>]>;
1366 }
1367}
1368let Extension = ArmIntegerDotProductAccumulateInt8 in {
1369 foreach name = ["arm_dot_acc"] in {
1370 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
1371 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1372 }
1373}
1374let Extension = ArmIntegerDotProductAccumulateInt16 in {
1375 foreach name = ["arm_dot_acc"] in {
1376 def : Builtin<name, [UInt, VectorType<UShort, 2>, VectorType<UShort, 2>, UInt]>;
1377 def : Builtin<name, [Int, VectorType<Short, 2>, VectorType<Short, 2>, Int]>;
1378 }
1379}
1380let Extension = ArmIntegerDotProductAccumulateSaturateInt8 in {
1381 foreach name = ["arm_dot_acc_sat"] in {
1382 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
1383 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1384 }
1385}