blob: 37f31782393339435f0f9083aff642a8ac25dc41 [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 Haastregt79a222f2019-06-03 09:39:11 +000058
Sven van Haastregtb21a3652019-08-19 11:56:03 +000059// Qualified Type. These map to ASTContext::QualType.
60class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000061 // Name of the field or function in a clang::ASTContext
62 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
63 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000064 // Some QualTypes in this file represent an abstract type for which there is
65 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
66 // without access qualifiers.
67 bit IsAbstract = _IsAbstract;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000068}
69
Sven van Haastregtb21a3652019-08-19 11:56:03 +000070// List of integers.
71class IntList<string _Name, list<int> _List> {
72 string Name = _Name;
73 list<int> List = _List;
74}
75
Sven van Haastregt79a222f2019-06-03 09:39:11 +000076//===----------------------------------------------------------------------===//
77// OpenCL C classes for types
78//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000079// OpenCL C basic data types (int, float, image2d_t, ...).
Sven van Haastregt47e95ff2019-09-17 13:32:56 +000080// Its child classes can represent concrete types (e.g. VectorType) or
81// abstract types (e.g. GenType).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000082class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000083 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000084 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000085 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000086 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000087 // Size of the vector (if applicable).
88 int VecWidth = 1;
89 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000090 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000091 // "const" qualifier.
92 bit IsConst = 0;
93 // "volatile" qualifier.
94 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000095 // Access qualifier. Must be one of ("RO", "WO", "RW").
96 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +000097 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000098 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000099}
100
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000101// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000102class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000103 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000104 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000105 // Inherited fields
106 let IsPointer = _Ty.IsPointer;
107 let IsConst = _Ty.IsConst;
108 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000109 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000110}
111
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000112// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000113class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000114 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000115 let AddrSpace = _AS.Name;
116 // Inherited fields
117 let VecWidth = _Ty.VecWidth;
118 let IsPointer = 1;
119 let IsConst = _Ty.IsConst;
120 let IsVolatile = _Ty.IsVolatile;
121 let AccessQualifier = _Ty.AccessQualifier;
122}
123
124// OpenCL const types (e.g. const int).
125class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
126 let IsConst = 1;
127 // Inherited fields
128 let VecWidth = _Ty.VecWidth;
129 let IsPointer = _Ty.IsPointer;
130 let IsVolatile = _Ty.IsVolatile;
131 let AccessQualifier = _Ty.AccessQualifier;
132 let AddrSpace = _Ty.AddrSpace;
133}
134
135// OpenCL volatile types (e.g. volatile int).
136class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
137 let IsVolatile = 1;
138 // Inherited fields
139 let VecWidth = _Ty.VecWidth;
140 let IsPointer = _Ty.IsPointer;
141 let IsConst = _Ty.IsConst;
142 let AccessQualifier = _Ty.AccessQualifier;
143 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000144}
145
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000146// OpenCL image types (e.g. image2d).
147class ImageType<Type _Ty, string _AccessQualifier> :
148 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
149 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000150 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000151 // Inherited fields
152 let IsPointer = _Ty.IsPointer;
153 let IsConst = _Ty.IsConst;
154 let IsVolatile = _Ty.IsVolatile;
155 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000156}
157
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000158// List of Types.
159class TypeList<string _Name, list<Type> _Type> {
160 string Name = _Name;
161 list<Type> List = _Type;
162}
163
164// A GenericType is an abstract type that defines a set of types as a
165// combination of Types and vector sizes.
166//
Sven van Haastregt47e95ff2019-09-17 13:32:56 +0000167// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
168// represents <int, int2, int4, float, float2, float4>.
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000169//
170// Some rules apply when using multiple GenericType arguments in a declaration:
171// 1. The number of vector sizes must be equal or 1 for all gentypes in a
172// declaration.
173// 2. The number of Types must be equal or 1 for all gentypes in a
174// declaration.
175// 3. Generic types are combined by iterating over all generic types at once.
176// For example, for the following GenericTypes
177// GenT1 = GenericType<half, [1, 2]> and
178// GenT2 = GenericType<float, int, [1, 2]>
179// A declaration f(GenT1, GenT2) results in the combinations
180// f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
181// 4. "sgentype" from the OpenCL specification is supported by specifying
182// a single vector size.
183// For example, for the following GenericTypes
184// GenT = GenericType<half, int, [1, 2]> and
185// SGenT = GenericType<half, int, [1]>
186// A declaration f(GenT, SGenT) results in the combinations
187// f(half, half), f(half2, half), f(int, int), f(int2, int) .
188class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
189 Type<_Ty, QualType<"null", 1>> {
190 // Possible element types of the generic type.
191 TypeList TypeList = _TypeList;
192 // Possible vector sizes of the types in the TypeList.
193 IntList VectorList = _VectorList;
194 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
195 let VecWidth = 0;
196}
197
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000198// Builtin function attributes.
199def Attr {
200 list<bit> None = [0, 0, 0];
201 list<bit> Pure = [1, 0, 0];
202 list<bit> Const = [0, 1, 0];
203 list<bit> Convergent = [0, 0, 1];
204}
205
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000206//===----------------------------------------------------------------------===//
207// OpenCL C class for builtin functions
208//===----------------------------------------------------------------------===//
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000209class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000210 // Name of the builtin function
211 string Name = _Name;
212 // List of types used by the function. The first one is the return type and
213 // the following are the arguments. The list must have at least one element
214 // (the return type).
215 list<Type> Signature = _Signature;
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000216 // Function attribute __attribute__((pure))
217 bit IsPure = _Attributes[0];
218 // Function attribute __attribute__((const))
219 bit IsConst = _Attributes[1];
220 // Function attribute __attribute__((convergent))
221 bit IsConv = _Attributes[2];
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000222 // OpenCL extensions to which the function belongs.
223 FunctionExtension Extension = FuncExtNone;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000224 // Version of OpenCL from which the function is available (e.g.: CL10).
225 // MinVersion is inclusive.
226 Version MinVersion = CL10;
227 // Version of OpenCL from which the function is not supported anymore.
228 // MaxVersion is exclusive.
229 // CLAll makes the function available for all versions.
230 Version MaxVersion = CLAll;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000231}
232
233//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000234// Definitions of OpenCL C types
235//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000236
237// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000238def Bool : Type<"bool", QualType<"BoolTy">>;
239def Char : Type<"char", QualType<"CharTy">>;
240def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
241def Short : Type<"short", QualType<"ShortTy">>;
242def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
243def Int : Type<"int", QualType<"IntTy">>;
244def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
245def Long : Type<"long", QualType<"LongTy">>;
246def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
247def Float : Type<"float", QualType<"FloatTy">>;
248def Double : Type<"double", QualType<"DoubleTy">>;
249def Half : Type<"half", QualType<"HalfTy">>;
250def Size : Type<"size_t", QualType<"getSizeType()">>;
251def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
252def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
253def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
254def Void : Type<"void_t", QualType<"VoidTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000255
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000256// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
257// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000258
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000259// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
260// The image definitions are "abstract". They should not be used without
261// specifying an access qualifier (RO/WO/RW).
262def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>;
263def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>;
264def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>;
265def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>;
266def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>;
267def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>;
268def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>;
269def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>;
270def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>;
271def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>;
272def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>;
273def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000274
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000275def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>;
276def Event : Type<"Event", QualType<"OCLEventTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000277
278//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000279// Definitions of OpenCL gentype variants
280//===----------------------------------------------------------------------===//
281// The OpenCL specification often uses "gentype" in builtin function
282// declarations to indicate that a builtin function is available with various
283// argument and return types. The types represented by "gentype" vary between
284// different parts of the specification. The following definitions capture
285// the different type lists for gentypes in different parts of the
286// specification.
287
288// Vector width lists.
289def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
290def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
291def Vec1 : IntList<"Vec1", [1]>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000292def Vec2 : IntList<"Vec2", [2]>;
293def Vec4 : IntList<"Vec4", [4]>;
294def Vec8 : IntList<"Vec8", [8]>;
295def Vec16 : IntList<"Vec16", [16]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000296def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000297
298// Type lists.
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000299def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
300def TLAllUnsigned : TypeList<"TLAllUnsigned", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt, ULong, UShort]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000301def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000302def TLSignedInts : TypeList<"TLSignedInts", [Char, Short, Int, Long]>;
303def TLUnsignedInts : TypeList<"TLUnsignedInts", [UChar, UShort, UInt, ULong]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000304
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000305def TLIntLongFloats : TypeList<"TLIntLongFloats", [Int, UInt, Long, ULong, Float, Double, Half]>;
306
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000307// All unsigned integer types twice, to facilitate unsigned return types for e.g.
308// uchar abs(char) and
309// uchar abs(uchar).
310def TLAllUIntsTwice : TypeList<"TLAllUIntsTwice", [UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>;
311
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000312def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
313
314// GenType definitions for multiple base types (e.g. all floating point types,
315// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000316// All types
317def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
318def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000319// All integer
320def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
321def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
322def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000323// All integer to unsigned
324def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>;
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000325// Signed integer
326def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>;
327// Unsigned integer
328def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000329// Float
330def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000331// (u)int, (u)long, and all floats
332def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000333
334// GenType definitions for every single base type (e.g. fp32 only).
335// Names are like: GenTypeFloatVecAndScalar.
336foreach Type = [Char, UChar, Short, UShort,
337 Int, UInt, Long, ULong,
338 Float, Double, Half] in {
339 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
340 def "GenType" # Type # VecSizes :
341 GenericType<"GenType" # Type # VecSizes,
342 TypeList<"GL" # Type.Name, [Type]>,
343 VecSizes>;
344 }
345}
346
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000347// GenType definitions for vec1234.
348foreach Type = [Float, Double, Half] in {
349 def "GenType" # Type # Vec1234 :
350 GenericType<"GenType" # Type # Vec1234,
351 TypeList<"GL" # Type.Name, [Type]>,
352 Vec1234>;
353}
354
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000355
356//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000357// Definitions of OpenCL builtin functions
358//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000359//--------------------------------------------------------------------
360// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
361// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
362
363// Generate the convert_* builtins functions.
364foreach RType = [Float, Double, Half, Char, UChar, Short,
365 UShort, Int, UInt, Long, ULong] in {
366 foreach IType = [Float, Double, Half, Char, UChar, Short,
367 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000368 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000369 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000370 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType],
371 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000372 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000373 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000374 [VectorType<RType, v>, VectorType<IType, v>],
375 Attr.Const>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000376 }
377 }
378 }
379 }
380}
381
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000382//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000383// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
384// --- Table 7 ---
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000385def : Builtin<"get_work_dim", [UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000386foreach name = ["get_global_size", "get_global_id", "get_local_size",
387 "get_local_id", "get_num_groups", "get_group_id",
388 "get_global_offset"] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000389 def : Builtin<name, [Size, UInt], Attr.Const>;
Sven van Haastregted69faa2019-09-19 13:41:51 +0000390}
391
392let MinVersion = CL20 in {
393 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
394 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
395 def : Builtin<name, [Size]>;
396 }
397}
398
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000399
Sven van Haastregted69faa2019-09-19 13:41:51 +0000400//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000401// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions
402// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions
403// --- Table 8 ---
404// --- 1 argument ---
405foreach name = ["acos", "acosh", "acospi",
406 "asin", "asinh", "asinpi",
407 "atan", "atanh", "atanpi",
408 "cbrt", "ceil",
409 "cos", "cosh", "cospi",
410 "erfc", "erf",
411 "exp", "exp2", "exp10", "expm1",
412 "fabs", "floor",
413 "log", "log2", "log10", "log1p", "logb",
414 "rint", "round", "rsqrt",
415 "sin", "sinh", "sinpi",
416 "sqrt",
417 "tan", "tanh", "tanpi",
418 "tgamma", "trunc",
419 "lgamma"] in {
420 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
421}
422foreach name = ["nan"] in {
423 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
424 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
425 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
426}
427
428// --- 2 arguments ---
429foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot",
430 "maxmag", "minmag", "nextafter", "pow", "powr",
431 "remainder"] in {
432 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
433}
434foreach name = ["fmax", "fmin"] in {
435 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
436 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
437 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
438 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
439}
440foreach name = ["ilogb"] in {
441 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
442 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>;
443 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>;
444}
445foreach name = ["ldexp"] in {
446 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
447 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>;
448 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
449 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>;
450 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
451 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>;
452}
453foreach name = ["pown", "rootn"] in {
454 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
455 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
456 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
457}
458
459// --- 3 arguments ---
460foreach name = ["fma", "mad"] in {
461 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
462}
463
464// --- Version dependent ---
465let MaxVersion = CL20 in {
466 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
467 foreach name = ["fract", "modf", "sincos"] in {
468 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
469 }
470 foreach name = ["frexp", "lgamma_r"] in {
471 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
472 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
473 }
474 }
475 foreach name = ["remquo"] in {
476 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
477 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
478 }
479 }
480 }
481}
482let MinVersion = CL20 in {
483 foreach name = ["fract", "modf", "sincos"] in {
484 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>;
485 }
486 foreach name = ["frexp", "lgamma_r"] in {
487 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
488 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
489 } }
490 foreach name = ["remquo"] in {
491 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
492 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>;
493 }
494 }
495}
496
497// --- Table 9 ---
498foreach name = ["half_cos",
499 "half_exp", "half_exp2", "half_exp10",
500 "half_log", "half_log2", "half_log10",
501 "half_recip", "half_rsqrt",
502 "half_sin", "half_sqrt", "half_tan",
503 "native_cos",
504 "native_exp", "native_exp2", "native_exp10",
505 "native_log", "native_log2", "native_log10",
506 "native_recip", "native_rsqrt",
507 "native_sin", "native_sqrt", "native_tan"] in {
508 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
509}
510foreach name = ["half_divide", "half_powr",
511 "native_divide", "native_powr"] in {
512 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
513}
514
515//--------------------------------------------------------------------
Sven van Haastregt0e70c352019-11-06 11:53:19 +0000516// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
517// --- Table 10 ---
518// --- 1 argument ---
519foreach name = ["abs"] in {
520 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>;
521}
522foreach name = ["clz", "popcount"] in {
523 def : Builtin<name, [AIGenTypeN, AIGenTypeN], Attr.Const>;
524}
525let MinVersion = CL20 in {
526 foreach name = ["ctz"] in {
527 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>;
528 }
529}
530
531// --- 2 arguments ---
532foreach name = ["abs_diff"] in {
533 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
534}
535foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in {
536 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
537}
538foreach name = ["max", "min"] in {
539 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
540 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>;
541}
542foreach name = ["upsample"] in {
543 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
544 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>;
545 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
546 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
547 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
548 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
549}
550
551// --- 3 arguments ---
552foreach name = ["clamp"] in {
553 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
554 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>;
555}
556foreach name = ["mad_hi", "mad_sat"] in {
557 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>;
558}
559
560// --- Table 11 ---
561foreach name = ["mad24"] in {
562 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
563 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
564}
565foreach name = ["mul24"] in {
566 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
567 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
568}
569
570//--------------------------------------------------------------------
Sven van Haastregt6fc73f62019-11-05 19:47:21 +0000571// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions
572// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions
573// --- Table 12 ---
574// --- 1 argument ---
575foreach name = ["degrees", "radians", "sign"] in {
576 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>;
577}
578
579// --- 2 arguments ---
580foreach name = ["max", "min"] in {
581 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
582 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>;
583 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>;
584 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>;
585}
586foreach name = ["step"] in {
587 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
588 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>;
589 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
590 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>;
591}
592
593// --- 3 arguments ---
594foreach name = ["clamp", "mix"] in {
595 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
596 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>;
597 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>;
598 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>;
599}
600foreach name = ["smoothstep"] in {
601 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
602 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>;
603 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>;
604 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>;
605}
606
607
Sven van Haastregt3d30f2c2019-11-07 15:00:19 +0000608//--------------------------------------------------------------------
609// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions
610// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions
611// --- Table 13 ---
612// --- 1 argument ---
613foreach name = ["length"] in {
614 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
615 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>;
616 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>;
617}
618foreach name = ["normalize"] in {
619 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
620 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
621 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
622}
623foreach name = ["fast_length"] in {
624 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>;
625}
626foreach name = ["fast_normalize"] in {
627 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
628}
629
630// --- 2 arguments ---
631foreach name = ["cross"] in {
632 foreach VSize = [3, 4] in {
633 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>;
634 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>;
635 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>;
636 }
637}
638foreach name = ["dot", "distance"] in {
639 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
640 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>;
641 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>;
642}
643foreach name = ["fast_distance"] in {
644 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>;
645}
646
647
648//--------------------------------------------------------------------
649// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
650// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions
651// --- Table 14 ---
652// --- 1 argument ---
653foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in {
654 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
655 def : Builtin<name, [Int, Double], Attr.Const>;
656 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
657 def : Builtin<name, [Int, Half], Attr.Const>;
658 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
659}
660foreach name = ["any", "all"] in {
661 def : Builtin<name, [Int, AIGenTypeN], Attr.Const>;
662}
663
664// --- 2 arguments ---
665foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal",
666 "isless", "islessequal", "islessgreater", "isordered",
667 "isunordered"] in {
668 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>;
669 def : Builtin<name, [Int, Double, Double], Attr.Const>;
670 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>;
671 def : Builtin<name, [Int, Half, Half], Attr.Const>;
672 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>;
673}
674
675// --- 3 arguments ---
676foreach name = ["bitselect"] in {
677 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>;
678}
679foreach name = ["select"] in {
680 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>;
681 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>;
682 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>;
683 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>;
684 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>;
685 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>;
686 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>;
687 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>;
688 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>;
689 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>;
690}
691
692
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000693//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000694// 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 +0000695// 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 +0000696// --- Table 15 ---
697// Variants for OpenCL versions below 2.0, using pointers to the global, local
698// and private address spaces.
699let MaxVersion = CL20 in {
700 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
701 foreach VSize = [2, 3, 4, 8, 16] in {
702 foreach name = ["vload" # VSize] in {
703 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
704 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
705 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
706 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
707 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
708 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
709 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
710 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
711 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
712 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
713 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
714 }
715 foreach name = ["vstore" # VSize] in {
716 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
717 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
718 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
719 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
720 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
721 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
722 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
723 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
724 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
725 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
726 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
727 }
728 foreach name = ["vloada_half" # VSize] in {
729 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
730 }
731 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
732 foreach name = ["vstorea_half" # VSize # rnd] in {
733 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
734 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
735 }
736 }
737 }
738 }
739}
740// Variants for OpenCL versions above 2.0, using pointers to the generic
741// address space.
742let MinVersion = CL20 in {
743 foreach VSize = [2, 3, 4, 8, 16] in {
744 foreach name = ["vload" # VSize] in {
745 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
746 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
747 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
748 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
749 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
750 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
751 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
752 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
753 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
754 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
755 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
756 }
757 foreach name = ["vstore" # VSize] in {
758 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
759 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
760 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
761 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
762 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
763 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
764 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
765 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
766 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
767 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
768 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
769 }
770 foreach name = ["vloada_half" # VSize] in {
771 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
772 }
773 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
774 foreach name = ["vstorea_half" # VSize # rnd] in {
775 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
776 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
777 }
778 }
779 }
780}
781// Variants using pointers to the constant address space.
782foreach VSize = [2, 3, 4, 8, 16] in {
783 foreach name = ["vload" # VSize] in {
784 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
785 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
786 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
787 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
788 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
789 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
790 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
791 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
792 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
793 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
794 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
795 }
796 foreach name = ["vloada_half" # VSize] in {
797 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
798 }
799 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
800 foreach name = ["vstorea_half" # VSize # rnd] in {
801 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
802 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
803 }
804 }
805}
Sven van Haastregt2fe674b2019-11-13 10:16:33 +0000806let MaxVersion = CL20 in {
807 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
808 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
809 foreach VSize = [2, 3, 4, 8, 16] in {
810 foreach name = ["vload_half" # VSize] in {
811 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
812 }
813 }
814 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
815 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
816 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
817 foreach VSize = [2, 3, 4, 8, 16] in {
818 foreach name = ["vstore_half" # VSize # rnd] in {
819 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
820 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
821 }
822 }
823 }
824 }
825}
826let MinVersion = CL20 in {
827 foreach AS = [GenericAS] in {
828 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
829 foreach VSize = [2, 3, 4, 8, 16] in {
830 foreach name = ["vload_half" # VSize] in {
831 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
832 }
833 }
834 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
835 def : Builtin<"vstore_half" # rnd, [Void, Float, Size, PointerType<Half, AS>]>;
836 def : Builtin<"vstore_half" # rnd, [Void, Double, Size, PointerType<Half, AS>]>;
837 foreach VSize = [2, 3, 4, 8, 16] in {
838 foreach name = ["vstore_half" # VSize # rnd] in {
839 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
840 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
841 }
842 }
843 }
844 }
845}
846
847foreach AS = [ConstantAS] in {
848 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>;
849 foreach VSize = [2, 3, 4, 8, 16] in {
850 foreach name = ["vload_half" # VSize] in {
851 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
852 }
853 }
854}
Sven van Haastregted69faa2019-09-19 13:41:51 +0000855
856//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000857// 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
858// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
859// --- Table 18 ---
860foreach name = ["async_work_group_copy"] in {
861 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
862 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
863}
864foreach name = ["async_work_group_strided_copy"] in {
865 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
866 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
867}
868foreach name = ["wait_group_events"] in {
869 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
870}
871foreach name = ["prefetch"] in {
872 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
873}
874
875//--------------------------------------------------------------------
876// OpenCL v2.0 s6.13.11 - Atomics Functions.
877// Functions that use memory_order and cl_mem_fence_flags enums are not
878// declared here as the TableGen backend does not handle enums.
879
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000880// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000881// --- Table 9.1 ---
Sven van Haastregt308b8b72019-12-18 10:13:51 +0000882let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
883 foreach Type = [Int, UInt] in {
884 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
885 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
886 }
887 foreach name = ["atom_inc", "atom_dec"] in {
888 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
889 }
890 foreach name = ["atom_cmpxchg"] in {
891 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
892 }
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000893 }
894}
895
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000896//--------------------------------------------------------------------
Sven van Haastregte54c83e2019-11-26 10:44:49 +0000897// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
898// --- Table 19 ---
899foreach name = ["shuffle"] in {
900 foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
901 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
902 def : Builtin<name, [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
903 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
904 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
905 Attr.Const>;
906 }
907 }
908}
909foreach name = ["shuffle2"] in {
910 foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
911 foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
912 def : Builtin<name, [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
913 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
914 GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
915 GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
916 Attr.Const>;
917 }
918 }
919}
920
921//--------------------------------------------------------------------
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000922// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
923// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
924// --- Table 22: Image Read Functions with Samplers ---
925foreach imgTy = [Image1d] in {
926 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000927 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
928 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
929 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000930 }
931}
932foreach imgTy = [Image2d, Image1dArray] in {
933 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000934 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
935 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
936 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000937 }
938}
939foreach imgTy = [Image3d, Image2dArray] in {
940 foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000941 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
942 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
943 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000944 }
945}
946foreach coordTy = [Int, Float] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000947 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
948 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000949}
950
951// --- Table 23: Sampler-less Read Functions ---
952foreach aQual = ["RO", "RW"] in {
953 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000954 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
955 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
956 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000957 }
958 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000959 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
960 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
961 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000962 }
963 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000964 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
965 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
966 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000967 }
Sven van Haastregt9a8d4772019-11-05 10:07:43 +0000968 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
969 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000970}
971
972// --- Table 24: Image Write Functions ---
973foreach aQual = ["WO", "RW"] in {
974 foreach imgTy = [Image2d] in {
975 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
976 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
977 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
978 }
979 foreach imgTy = [Image2dArray] in {
980 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
981 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
982 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
983 }
984 foreach imgTy = [Image1d, Image1dBuffer] in {
985 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
986 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
987 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
988 }
989 foreach imgTy = [Image1dArray] in {
990 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
991 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
992 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
993 }
994 foreach imgTy = [Image3d] in {
995 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
996 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
997 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
998 }
999 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
1000 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1001}
1002
Sven van Haastregt2a69ed02019-09-25 09:12:59 +00001003// --- Table 25: Image Query Functions ---
1004foreach aQual = ["RO", "WO", "RW"] in {
1005 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1006 Image1dArray, Image2dArray, Image2dDepth,
1007 Image2dArrayDepth] in {
1008 foreach name = ["get_image_width", "get_image_channel_data_type",
1009 "get_image_channel_order"] in {
1010 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
1011 }
1012 }
1013 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
1014 Image2dArrayDepth] in {
1015 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
1016 }
1017 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
1018 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
1019 Image2dArrayDepth] in {
1020 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
1021 }
1022 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
1023 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1024 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
1025 }
1026}
1027
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001028// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1029// --- Table 8 ---
1030foreach aQual = ["RO"] in {
1031 foreach name = ["read_imageh"] in {
1032 foreach coordTy = [Int, Float] in {
1033 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001034 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001035 }
1036 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001037 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001038 }
1039 foreach imgTy = [Image1d] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001040 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001041 }
1042 }
1043 }
1044}
1045// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1046// --- Table 9 ---
1047foreach aQual = ["RO", "RW"] in {
1048 foreach name = ["read_imageh"] in {
1049 foreach imgTy = [Image2d, Image1dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001050 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001051 }
1052 foreach imgTy = [Image3d, Image2dArray] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001053 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001054 }
1055 foreach imgTy = [Image1d, Image1dBuffer] in {
Sven van Haastregt9a8d4772019-11-05 10:07:43 +00001056 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
Sven van Haastregt988f1e32019-09-05 10:01:24 +00001057 }
1058 }
1059}
1060// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1061// --- Table 10 ---
1062foreach aQual = ["WO", "RW"] in {
1063 foreach name = ["write_imageh"] in {
1064 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1065 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1066 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1067 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
1068 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
1069 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1070 }
1071}
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001072
1073
Sven van Haastregte54c83e2019-11-26 10:44:49 +00001074//--------------------------------------------------------------------
1075// OpenCL v2.0 s6.13.15 - Work-group Functions
1076// --- Table 26 ---
1077let MinVersion = CL20 in {
1078 foreach name = ["work_group_all", "work_group_any"] in {
1079 def : Builtin<name, [Int, Int], Attr.Convergent>;
1080 }
1081 foreach name = ["work_group_broadcast"] in {
1082 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1083 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>;
1084 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>;
1085 }
1086 foreach op = ["add", "min", "max"] in {
1087 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_",
1088 "work_group_scan_inclusive_"] in {
1089 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>;
1090 }
1091 }
1092}
1093
1094
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001095// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +00001096let MinVersion = CL20 in {
Sven van Haastregt308b8b72019-12-18 10:13:51 +00001097 let Extension = FuncExtKhrSubgroups in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +00001098 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
1099 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
1100 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +00001101 }
1102}