blob: e5109dfbb0482010d5404acea9d5fc24c545df8b [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()">>;
Sven van Haastregt319ea2d2020-02-26 14:08:23 +0000268def 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
Sven van Haastregt319ea2d2020-02-26 14:08:23 +0000293// OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
294def AtomicInt : Type<"atomic_int", QualType<"getAtomicType(Context.IntTy)">>;
295def AtomicUInt : Type<"atomic_uint", QualType<"getAtomicType(Context.UnsignedIntTy)">>;
296def AtomicLong : Type<"atomic_long", QualType<"getAtomicType(Context.LongTy)">>;
297def AtomicULong : Type<"atomic_ulong", QualType<"getAtomicType(Context.UnsignedLongTy)">>;
298def AtomicFloat : Type<"atomic_float", QualType<"getAtomicType(Context.FloatTy)">>;
299def AtomicDouble : Type<"atomic_double", QualType<"getAtomicType(Context.DoubleTy)">>;
300def AtomicIntPtr : Type<"atomic_intptr_t", QualType<"getAtomicType(Context.getIntPtrType())">>;
301def AtomicUIntPtr : Type<"atomic_uintptr_t", QualType<"getAtomicType(Context.getUIntPtrType())">>;
302def AtomicSize : Type<"atomic_size_t", QualType<"getAtomicType(Context.getSizeType())">>;
303def AtomicPtrDiff : Type<"atomic_ptrdiff_t", QualType<"getAtomicType(Context.getPointerDiffType())">>;
304
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000305//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000306// Definitions of OpenCL gentype variants
307//===----------------------------------------------------------------------===//
308// The OpenCL specification often uses "gentype" in builtin function
309// declarations to indicate that a builtin function is available with various
310// argument and return types. The types represented by "gentype" vary between
311// different parts of the specification. The following definitions capture
312// the different type lists for gentypes in different parts of the
313// specification.
314
315// Vector width lists.
316def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
317def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
318def Vec1 : IntList<"Vec1", [1]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000319def Vec2 : IntList<"Vec2", [2]>;
320def Vec4 : IntList<"Vec4", [4]>;
321def Vec8 : IntList<"Vec8", [8]>;
322def Vec16 : IntList<"Vec16", [16]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000323def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000324
325// Type lists.
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000326def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
327def TLAllUnsigned : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
328def TLFloat : TypeList<[Float, Double, Half]>;
329def TLSignedInts : TypeList<[Char, Short, Int, Long]>;
330def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000331
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000332def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000333
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000334// All unsigned integer types twice, to facilitate unsigned return types for e.g.
335// uchar abs(char) and
336// uchar abs(uchar).
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000337def TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000338
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000339def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000340
341// GenType definitions for multiple base types (e.g. all floating point types,
342// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000343// All types
344def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
345def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000346// All integer
347def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
348def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
349def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000350// All integer to unsigned
351def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000352// Signed integer
353def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
354// Unsigned integer
355def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000356// Float
357def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000358// (u)int, (u)long, and all floats
359def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000360
361// GenType definitions for every single base type (e.g. fp32 only).
362// Names are like: GenTypeFloatVecAndScalar.
363foreach Type = [Char, UChar, Short, UShort,
364 Int, UInt, Long, ULong,
365 Float, Double, Half] in {
366 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
367 def "GenType" # Type # VecSizes :
368 GenericType<"GenType" # Type # VecSizes,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000369 TypeList<[Type]>, VecSizes>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000370 }
371}
372
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000373// GenType definitions for vec1234.
374foreach Type = [Float, Double, Half] in {
375 def "GenType" # Type # Vec1234 :
376 GenericType<"GenType" # Type # Vec1234,
Sven van Haastregt89b8b422020-02-04 10:56:53 +0000377 TypeList<[Type]>, Vec1234>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000378}
379
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000380
381//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000382// Definitions of OpenCL builtin functions
383//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000384//--------------------------------------------------------------------
385// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
386// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
387
388// Generate the convert_* builtins functions.
389foreach RType = [Float, Double, Half, Char, UChar, Short,
390 UShort, Int, UInt, Long, ULong] in {
391 foreach IType = [Float, Double, Half, Char, UChar, Short,
392 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt81e8b602020-02-19 13:52:58 +0000393 // Conversions to integer type have a sat and non-sat variant.
394 foreach sat = !cond(!eq(RType.Name, "float") : [""],
395 !eq(RType.Name, "double") : [""],
396 !eq(RType.Name, "half") : [""],
397 1 : ["", "_sat"]) in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000398 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000399 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
400 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000401 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000402 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000403 [VectorType<RType, v>, VectorType<IType, v>],
404 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000405 }
406 }
407 }
408 }
409}
410
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000411//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000412// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
413// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000414def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000415foreach name = ["get_global_size", "get_global_id", "get_local_size",
416 "get_local_id", "get_num_groups", "get_group_id",
417 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000418 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000419}
420
421let MinVersion = CL20 in {
422 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
423 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
424 def : Builtin<name, [Size]>;
425 }
426}
427
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000428
Sven van Haastregted69faa2019-09-19 13:41:51 +0000429//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000430// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
431// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
432// --- Table 8 ---
433// --- 1 argument ---
434foreach name = ["acos", "acosh", "acospi",
435 "asin", "asinh", "asinpi",
436 "atan", "atanh", "atanpi",
437 "cbrt", "ceil",
438 "cos", "cosh", "cospi",
439 "erfc", "erf",
440 "exp", "exp2", "exp10", "expm1",
441 "fabs", "floor",
442 "log", "log2", "log10", "log1p", "logb",
443 "rint", "round", "rsqrt",
444 "sin", "sinh", "sinpi",
445 "sqrt",
446 "tan", "tanh", "tanpi",
447 "tgamma", "trunc",
448 "lgamma"] in {
449 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
450}
451foreach name = ["nan"] in {
452 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
453 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
454 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
455}
456
457// --- 2 arguments ---
458foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
459 "maxmag", "minmag", "nextafter", "pow", "powr",
460 "remainder"] in {
461 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
462}
463foreach name = ["fmax", "fmin"] in {
464 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
465 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
466 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
467 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
468}
469foreach name = ["ilogb"] in {
470 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
471 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
472 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
473}
474foreach name = ["ldexp"] in {
475 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
476 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
477 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
478 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
479 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
480 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
481}
482foreach name = ["pown", "rootn"] in {
483 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
484 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
485 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
486}
487
488// --- 3 arguments ---
489foreach name = ["fma", "mad"] in {
490 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
491}
492
493// --- Version dependent ---
494let MaxVersion = CL20 in {
495 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
496 foreach name = ["fract", "modf", "sincos"] in {
497 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
498 }
499 foreach name = ["frexp", "lgamma_r"] in {
500 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
501 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
502 }
503 }
504 foreach name = ["remquo"] in {
505 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
506 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
507 }
508 }
509 }
510}
511let MinVersion = CL20 in {
512 foreach name = ["fract", "modf", "sincos"] in {
513 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
514 }
515 foreach name = ["frexp", "lgamma_r"] in {
516 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
517 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
518 } }
519 foreach name = ["remquo"] in {
520 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
521 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
522 }
523 }
524}
525
526// --- Table 9 ---
527foreach name = ["half_cos",
528 "half_exp", "half_exp2", "half_exp10",
529 "half_log", "half_log2", "half_log10",
530 "half_recip", "half_rsqrt",
531 "half_sin", "half_sqrt", "half_tan",
532 "native_cos",
533 "native_exp", "native_exp2", "native_exp10",
534 "native_log", "native_log2", "native_log10",
535 "native_recip", "native_rsqrt",
536 "native_sin", "native_sqrt", "native_tan"] in {
537 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
538}
539foreach name = ["half_divide", "half_powr",
540 "native_divide", "native_powr"] in {
541 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
542}
543
544//--------------------------------------------------------------------
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000545// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
546// --- Table 10 ---
547// --- 1 argument ---
548foreach name = ["abs"] in {
549 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
550}
551foreach name = ["clz", "popcount"] in {
552 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
553}
554let MinVersion = CL20 in {
555 foreach name = ["ctz"] in {
556 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
557 }
558}
559
560// --- 2 arguments ---
561foreach name = ["abs_diff"] in {
562 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
563}
564foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
565 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
566}
567foreach name = ["max", "min"] in {
568 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
569 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
570}
571foreach name = ["upsample"] in {
572 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
573 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
574 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
575 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
576 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
577 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
578}
579
580// --- 3 arguments ---
581foreach name = ["clamp"] in {
582 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
583 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
584}
585foreach name = ["mad_hi", "mad_sat"] in {
586 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
587}
588
589// --- Table 11 ---
590foreach name = ["mad24"] in {
591 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
592 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
593}
594foreach name = ["mul24"] in {
595 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
596 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
597}
598
599//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000600// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
601// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
602// --- Table 12 ---
603// --- 1 argument ---
604foreach name = ["degrees", "radians", "sign"] in {
605 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
606}
607
608// --- 2 arguments ---
609foreach name = ["max", "min"] in {
610 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
611 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
612 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
613 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
614}
615foreach name = ["step"] in {
616 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
617 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
618 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
619 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
620}
621
622// --- 3 arguments ---
623foreach name = ["clamp", "mix"] in {
624 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
625 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
626 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
627 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
628}
629foreach name = ["smoothstep"] in {
630 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
631 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
632 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
633 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
634}
635
636
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000637//--------------------------------------------------------------------
638// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
639// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
640// --- Table 13 ---
641// --- 1 argument ---
642foreach name = ["length"] in {
643 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
644 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
645 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
646}
647foreach name = ["normalize"] in {
648 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
649 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
650 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
651}
652foreach name = ["fast_length"] in {
653 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
654}
655foreach name = ["fast_normalize"] in {
656 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
657}
658
659// --- 2 arguments ---
660foreach name = ["cross"] in {
661 foreach VSize = [3, 4] in {
662 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
663 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
664 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
665 }
666}
667foreach name = ["dot", "distance"] in {
668 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
669 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
670 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
671}
672foreach name = ["fast_distance"] in {
673 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
674}
675
676
677//--------------------------------------------------------------------
678// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
679// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
680// --- Table 14 ---
681// --- 1 argument ---
682foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
683 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
684 def : Builtin<name, [Int, Double], Attr.Const>;
685 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
686 def : Builtin<name, [Int, Half], Attr.Const>;
687 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
688}
689foreach name = ["any", "all"] in {
Sven van Haastregt25f26392020-03-09 10:26:11 +0000690 def : Builtin<name, [Int, SGenTypeN], Attr.Const>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000691}
692
693// --- 2 arguments ---
694foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
695 "isless", "islessequal", "islessgreater", "isordered",
696 "isunordered"] in {
697 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
698 def : Builtin<name, [Int, Double, Double], Attr.Const>;
699 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
700 def : Builtin<name, [Int, Half, Half], Attr.Const>;
701 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
702}
703
704// --- 3 arguments ---
705foreach name = ["bitselect"] in {
706 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
707}
708foreach name = ["select"] in {
709 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
710 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
711 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
712 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
713 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
714 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
715 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
716 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
717 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
718 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
719}
720
721
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000722//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000723// 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 +0000724// 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 +0000725// --- Table 15 ---
726// Variants for OpenCL versions below 2.0, using pointers to the global, local
727// and private address spaces.
728let MaxVersion = CL20 in {
729 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
730 foreach VSize = [2, 3, 4, 8, 16] in {
731 foreach name = ["vload" # VSize] in {
732 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
733 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
734 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
735 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
736 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
737 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
738 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
739 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
740 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
741 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
742 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
743 }
744 foreach name = ["vstore" # VSize] in {
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000745 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>;
746 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>;
747 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>;
748 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>;
749 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>;
750 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>;
751 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>;
752 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>;
753 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>;
754 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>;
755 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000756 }
757 foreach name = ["vloada_half" # VSize] in {
758 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
759 }
760 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
761 foreach name = ["vstorea_half" # VSize # rnd] in {
762 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
763 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
764 }
765 }
766 }
767 }
768}
769// Variants for OpenCL versions above 2.0, using pointers to the generic
770// address space.
771let MinVersion = CL20 in {
772 foreach VSize = [2, 3, 4, 8, 16] in {
773 foreach name = ["vload" # VSize] in {
774 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
775 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
776 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
777 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
778 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
779 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
780 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
781 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
782 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
783 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
784 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
785 }
786 foreach name = ["vstore" # VSize] in {
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000787 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, GenericAS>]>;
788 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, GenericAS>]>;
789 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, GenericAS>]>;
790 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, GenericAS>]>;
791 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, GenericAS>]>;
792 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, GenericAS>]>;
793 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, GenericAS>]>;
794 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, GenericAS>]>;
795 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, GenericAS>]>;
796 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, GenericAS>]>;
797 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, GenericAS>]>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000798 }
799 foreach name = ["vloada_half" # VSize] in {
800 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
801 }
802 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
803 foreach name = ["vstorea_half" # VSize # rnd] in {
804 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
805 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
806 }
807 }
808 }
809}
810// Variants using pointers to the constant address space.
811foreach VSize = [2, 3, 4, 8, 16] in {
812 foreach name = ["vload" # VSize] in {
813 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
814 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
815 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
816 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
817 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
818 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
819 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
820 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
821 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
822 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
823 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
824 }
825 foreach name = ["vloada_half" # VSize] in {
826 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
827 }
Sven van Haastregted69faa2019-09-19 13:41:51 +0000828}
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000829let MaxVersion = CL20 in {
830 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
831 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000832 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000833 foreach VSize = [2, 3, 4, 8, 16] in {
834 foreach name = ["vload_half" # VSize] in {
835 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
836 }
837 }
838 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000839 foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in {
840 def : Builtin<name, [Void, Float, Size, PointerType<Half, AS>]>;
841 def : Builtin<name, [Void, Double, Size, PointerType<Half, AS>]>;
842 }
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000843 foreach VSize = [2, 3, 4, 8, 16] in {
844 foreach name = ["vstore_half" # VSize # rnd] in {
845 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
846 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
847 }
848 }
849 }
850 }
851}
852let MinVersion = CL20 in {
853 foreach AS = [GenericAS] in {
854 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000855 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000856 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 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000862 foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in {
863 def : Builtin<name, [Void, Float, Size, PointerType<Half, AS>]>;
864 def : Builtin<name, [Void, Double, Size, PointerType<Half, AS>]>;
865 }
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000866 foreach VSize = [2, 3, 4, 8, 16] in {
867 foreach name = ["vstore_half" # VSize # rnd] in {
868 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
869 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
870 }
871 }
872 }
873 }
874}
875
876foreach AS = [ConstantAS] in {
877 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
Sven van Haastregt6ef953c2020-03-06 12:45:28 +0000878 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000879 foreach VSize = [2, 3, 4, 8, 16] in {
880 foreach name = ["vload_half" # VSize] in {
881 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
882 }
883 }
884}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000885
886//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000887// 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
888// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
889// --- Table 18 ---
890foreach name = ["async_work_group_copy"] in {
891 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
892 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
893}
894foreach name = ["async_work_group_strided_copy"] in {
895 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
896 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
897}
898foreach name = ["wait_group_events"] in {
899 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
900}
901foreach name = ["prefetch"] in {
902 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
903}
904
905//--------------------------------------------------------------------
906// OpenCL v2.0 s6.13.11 - Atomics Functions.
907// Functions that use memory_order and cl_mem_fence_flags enums are not
908// declared here as the TableGen backend does not handle enums.
909
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000910// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000911// --- Table 9.1 ---
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000912let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
913 foreach Type = [Int, UInt] in {
914 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
915 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
916 }
917 foreach name = ["atom_inc", "atom_dec"] in {
918 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
919 }
920 foreach name = ["atom_cmpxchg"] in {
921 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
922 }
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000923 }
924}
Sven van Haastregtb7145832019-12-23 12:29:01 +0000925// --- Table 9.3 ---
926let Extension = FuncExtKhrLocalInt32BaseAtomics in {
927 foreach Type = [Int, UInt] in {
928 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
929 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
930 }
931 foreach name = ["atom_inc", "atom_dec"] in {
932 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
933 }
934 foreach name = ["atom_cmpxchg"] in {
935 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
936 }
937 }
938}
939// --- Table 9.5 ---
940let Extension = FuncExtKhrInt64BaseAtomics in {
941 foreach AS = [GlobalAS, LocalAS] in {
942 foreach Type = [Long, ULong] in {
943 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
944 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
945 }
946 foreach name = ["atom_inc", "atom_dec"] in {
947 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
948 }
949 foreach name = ["atom_cmpxchg"] in {
950 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
951 }
952 }
953 }
954}
955// --- Table 9.2 ---
956let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
957 foreach Type = [Int, UInt] in {
958 foreach name = ["atom_min", "atom_max", "atom_and",
959 "atom_or", "atom_xor"] in {
960 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
961 }
962 }
963}
964// --- Table 9.4 ---
965let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
966 foreach Type = [Int, UInt] in {
967 foreach name = ["atom_min", "atom_max", "atom_and",
968 "atom_or", "atom_xor"] in {
969 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
970 }
971 }
972}
973// --- Table 9.6 ---
974let Extension = FuncExtKhrInt64ExtendedAtomics in {
975 foreach AS = [GlobalAS, LocalAS] in {
976 foreach Type = [Long, ULong] in {
977 foreach name = ["atom_min", "atom_max", "atom_and",
978 "atom_or", "atom_xor"] in {
979 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
980 }
981 }
982 }
983}
984// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
985foreach AS = [GlobalAS, LocalAS] in {
986 foreach Type = [Int, UInt] in {
987 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
988 "atomic_min", "atomic_max", "atomic_and",
989 "atomic_or", "atomic_xor"] in {
990 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
991 }
992 foreach name = ["atomic_inc", "atomic_dec"] in {
993 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
994 }
995 foreach name = ["atomic_cmpxchg"] in {
996 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
997 }
998 }
999}
Sven van Haastregt319ea2d2020-02-26 14:08:23 +00001000// OpenCL v2.0 s6.13.11 - Atomic Functions.
1001let MinVersion = CL20 in {
1002 foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
1003 [AtomicLong, Long], [AtomicULong, ULong],
1004 [AtomicFloat, Float], [AtomicDouble, Double]] in {
1005 def : Builtin<"atomic_init",
1006 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>;
1007 def : Builtin<"atomic_store",
1008 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>;
1009 def : Builtin<"atomic_load",
1010 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>]>;
1011 def : Builtin<"atomic_exchange",
1012 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>;
1013 foreach Variant = ["weak", "strong"] in {
1014 def : Builtin<"atomic_compare_exchange_" # Variant,
1015 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>,
1016 PointerType<TypePair[1], GenericAS>, TypePair[1]]>;
1017 }
1018 }
1019
1020 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1021 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
1022 [AtomicIntPtr, IntPtr, PtrDiff],
1023 [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
1024 foreach ModOp = ["add", "sub"] in {
1025 def : Builtin<"atomic_fetch_" # ModOp,
1026 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>;
1027 }
1028 }
1029 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1030 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
1031 [AtomicIntPtr, IntPtr, IntPtr],
1032 [AtomicUIntPtr, UIntPtr, UIntPtr]] in {
1033 foreach ModOp = ["or", "xor", "and", "min", "max"] in {
1034 def : Builtin<"atomic_fetch_" # ModOp,
1035 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>;
1036 }
1037 }
1038}
Sven van Haastregtcc0ba282019-08-20 12:21:03 +00001039
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001040//--------------------------------------------------------------------
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001041// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
1042// --- Table 19 ---
Sven van Haastregtff429c52019-12-31 15:30:02 +00001043foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
1044 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
1045 def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
1046 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1047 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
1048 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001049 }
1050}
Sven van Haastregtff429c52019-12-31 15:30:02 +00001051foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
1052 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
1053 def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
1054 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1055 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
1056 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
1057 Attr.Const>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001058 }
1059}
1060
1061//--------------------------------------------------------------------
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001062// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
1063// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
1064// --- Table 22: Image Read Functions with Samplers ---
1065foreach imgTy = [Image1d] in {
1066 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001067 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1068 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
1069 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001070 }
1071}
1072foreach imgTy = [Image2d, Image1dArray] in {
1073 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001074 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1075 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1076 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001077 }
1078}
1079foreach imgTy = [Image3d, Image2dArray] in {
1080 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001081 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1082 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1083 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001084 }
1085}
1086foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001087 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
1088 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001089}
1090
1091// --- Table 23: Sampler-less Read Functions ---
1092foreach aQual = ["RO", "RW"] in {
1093 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001094 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1095 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1096 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001097 }
1098 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001099 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1100 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1101 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001102 }
1103 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001104 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1105 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1106 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001107 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001108 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1109 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001110}
1111
1112// --- Table 24: Image Write Functions ---
1113foreach aQual = ["WO", "RW"] in {
1114 foreach imgTy = [Image2d] in {
1115 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1116 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1117 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1118 }
1119 foreach imgTy = [Image2dArray] in {
1120 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1121 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1122 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1123 }
1124 foreach imgTy = [Image1d, Image1dBuffer] in {
1125 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
1126 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
1127 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
1128 }
1129 foreach imgTy = [Image1dArray] in {
1130 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
1131 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
1132 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1133 }
1134 foreach imgTy = [Image3d] in {
1135 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
1136 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
1137 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
1138 }
1139 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1140 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1141}
1142
Sven van Haastregt2a69ed02019-09-25 09:12:59 +00001143// --- Table 25: Image Query Functions ---
1144foreach aQual = ["RO", "WO", "RW"] in {
1145 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1146 Image1dArray, Image2dArray, Image2dDepth,
1147 Image2dArrayDepth] in {
1148 foreach name = ["get_image_width", "get_image_channel_data_type",
1149 "get_image_channel_order"] in {
1150 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1151 }
1152 }
1153 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1154 Image2dArrayDepth] in {
1155 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1156 }
1157 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1158 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1159 Image2dArrayDepth] in {
1160 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1161 }
1162 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1163 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1164 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1165 }
1166}
1167
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001168// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1169// --- Table 8 ---
1170foreach aQual = ["RO"] in {
1171 foreach name = ["read_imageh"] in {
1172 foreach coordTy = [Int, Float] in {
1173 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001174 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001175 }
1176 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001177 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001178 }
1179 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001180 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001181 }
1182 }
1183 }
1184}
1185// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1186// --- Table 9 ---
1187foreach aQual = ["RO", "RW"] in {
1188 foreach name = ["read_imageh"] in {
1189 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001190 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001191 }
1192 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001193 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001194 }
1195 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001196 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001197 }
1198 }
1199}
1200// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1201// --- Table 10 ---
1202foreach aQual = ["WO", "RW"] in {
1203 foreach name = ["write_imageh"] in {
1204 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1205 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1206 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1207 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1208 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1209 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1210 }
1211}
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001212
1213
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001214//--------------------------------------------------------------------
1215// OpenCL v2.0 s6.13.15 - Work-group Functions
1216// --- Table 26 ---
1217let MinVersion = CL20 in {
1218 foreach name = ["work_group_all", "work_group_any"] in {
1219 def : Builtin<name, [Int, Int], Attr.Convergent>;
1220 }
1221 foreach name = ["work_group_broadcast"] in {
1222 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1223 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1224 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1225 }
1226 foreach op = ["add", "min", "max"] in {
1227 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1228 "work_group_scan_inclusive_"] in {
1229 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1230 }
1231 }
1232}
1233
1234
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001235// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +00001236let MinVersion = CL20 in {
Sven van Haastregt308b8b72019-12-18 10:13:51 +00001237 let Extension = FuncExtKhrSubgroups in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +00001238 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1239 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1240 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001241 }
1242}
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001243
1244//--------------------------------------------------------------------
1245// End of the builtin functions defined in the OpenCL C specification.
1246// Builtin functions defined in the OpenCL C Extension are below.
1247//--------------------------------------------------------------------
1248
1249
1250// OpenCL Extension v2.0 s9.18 - Mipmaps
1251let Extension = FuncExtKhrMipmapImage in {
1252 // Added to section 6.13.14.2.
1253 foreach aQual = ["RO"] in {
1254 foreach imgTy = [Image2d] in {
1255 foreach name = ["read_imagef"] in {
1256 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1257 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, 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, 2>, Float], Attr.Pure>;
1261 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, 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, 2>, Float], Attr.Pure>;
1265 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1266 }
1267 }
1268 foreach imgTy = [Image2dDepth] in {
1269 foreach name = ["read_imagef"] in {
1270 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1271 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1272 }
1273 }
1274 foreach imgTy = [Image1d] in {
1275 foreach name = ["read_imagef"] in {
1276 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1277 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1278 }
1279 foreach name = ["read_imagei"] in {
1280 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1281 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1282 }
1283 foreach name = ["read_imageui"] in {
1284 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>;
1285 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>;
1286 }
1287 }
1288 foreach imgTy = [Image3d] in {
1289 foreach name = ["read_imagef"] in {
1290 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1291 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1292 }
1293 foreach name = ["read_imagei"] in {
1294 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1295 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1296 }
1297 foreach name = ["read_imageui"] in {
1298 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>;
1299 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1300 }
1301 }
1302 foreach imgTy = [Image1dArray] in {
1303 foreach name = ["read_imagef"] in {
1304 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1305 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1306 }
1307 foreach name = ["read_imagei"] in {
1308 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1309 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1310 }
1311 foreach name = ["read_imageui"] in {
1312 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>;
1313 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>;
1314 }
1315 }
1316 foreach imgTy = [Image2dArray] in {
1317 foreach name = ["read_imagef"] in {
1318 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1319 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1320 }
1321 foreach name = ["read_imagei"] in {
1322 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1323 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1324 }
1325 foreach name = ["read_imageui"] in {
1326 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1327 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1328 }
1329 }
1330 foreach imgTy = [Image2dArrayDepth] in {
1331 foreach name = ["read_imagef"] in {
1332 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>;
1333 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1334 }
1335 }
1336 }
Sven van Haastregt91b30832020-02-05 16:05:20 +00001337 // Added to section 6.13.14.5
1338 foreach aQual = ["RO", "WO", "RW"] in {
1339 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1340 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
1341 }
1342 }
1343}
1344
1345// Write functions are enabled using a separate extension.
1346let Extension = FuncExtKhrMipmapImageWrites in {
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001347 // Added to section 6.13.14.4.
1348 foreach aQual = ["WO"] in {
1349 foreach imgTy = [Image2d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001350 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1351 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1352 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001353 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001354 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001355 foreach imgTy = [Image1d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001356 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>;
1357 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>;
1358 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001359 }
1360 foreach imgTy = [Image1dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001361 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>;
1362 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>;
1363 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001364 }
1365 foreach imgTy = [Image2dArray] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001366 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1367 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1368 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001369 }
Sven van Haastregtff429c52019-12-31 15:30:02 +00001370 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
Sven van Haastregt91b30832020-02-05 16:05:20 +00001371 let Extension = FuncExtKhrMipmapWritesAndWrite3d in {
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001372 foreach imgTy = [Image3d] in {
Sven van Haastregtff429c52019-12-31 15:30:02 +00001373 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1374 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1375 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001376 }
1377 }
1378 }
Sven van Haastregt4a188fd2019-12-30 10:47:58 +00001379}
Sven van Haastregt92451f02020-01-14 14:46:42 +00001380
Sven van Haastregt92451f02020-01-14 14:46:42 +00001381//--------------------------------------------------------------------
1382// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1383let Extension = FuncExtKhrGlMsaaSharing in {
1384 // --- Table 6.13.14.3 ---
1385 foreach aQual = ["RO", "RW"] in {
1386 foreach imgTy = [Image2dMsaa] in {
1387 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1388 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1389 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1390 }
1391 foreach imgTy = [Image2dArrayMsaa] in {
1392 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1393 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1394 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1395 }
1396 foreach name = ["read_imagef"] in {
1397 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1398 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1399 }
1400 }
1401
1402 // --- Table 6.13.14.5 ---
1403 foreach aQual = ["RO", "WO", "RW"] in {
1404 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1405 foreach name = ["get_image_width", "get_image_height",
1406 "get_image_channel_data_type", "get_image_channel_order",
1407 "get_image_num_samples"] in {
1408 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1409 }
1410 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1411 }
1412 def : Builtin<"get_image_array_size", [Size, ImageType<Image2dArrayMsaaDepth, aQual>], Attr.Const>;
1413 }
1414}
Sven van Haastregt8b65f792020-02-18 10:02:06 +00001415
1416//--------------------------------------------------------------------
1417// Arm extensions.
1418let Extension = ArmIntegerDotProductInt8 in {
1419 foreach name = ["arm_dot"] in {
1420 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>;
1421 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>]>;
1422 }
1423}
1424let Extension = ArmIntegerDotProductAccumulateInt8 in {
1425 foreach name = ["arm_dot_acc"] in {
1426 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
1427 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1428 }
1429}
1430let Extension = ArmIntegerDotProductAccumulateInt16 in {
1431 foreach name = ["arm_dot_acc"] in {
1432 def : Builtin<name, [UInt, VectorType<UShort, 2>, VectorType<UShort, 2>, UInt]>;
1433 def : Builtin<name, [Int, VectorType<Short, 2>, VectorType<Short, 2>, Int]>;
1434 }
1435}
1436let Extension = ArmIntegerDotProductAccumulateSaturateInt8 in {
1437 foreach name = ["arm_dot_acc_sat"] in {
1438 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>;
1439 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>;
1440 }
1441}