blob: 2986140594675ccf10e9cda577f8c34e5c4ba18c [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
43
Sven van Haastregtb21a3652019-08-19 11:56:03 +000044// Qualified Type. These map to ASTContext::QualType.
45class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000046 // Name of the field or function in a clang::ASTContext
47 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
48 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000049 // Some QualTypes in this file represent an abstract type for which there is
50 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
51 // without access qualifiers.
52 bit IsAbstract = _IsAbstract;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000053}
54
Sven van Haastregtb21a3652019-08-19 11:56:03 +000055// List of integers.
56class IntList<string _Name, list<int> _List> {
57 string Name = _Name;
58 list<int> List = _List;
59}
60
Sven van Haastregt79a222f2019-06-03 09:39:11 +000061//===----------------------------------------------------------------------===//
62// OpenCL C classes for types
63//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000064// OpenCL C basic data types (int, float, image2d_t, ...).
Sven van Haastregt47e95ff2019-09-17 13:32:56 +000065// Its child classes can represent concrete types (e.g. VectorType) or
66// abstract types (e.g. GenType).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000067class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000068 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000069 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000070 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000071 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000072 // Size of the vector (if applicable).
73 int VecWidth = 1;
74 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000075 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000076 // "const" qualifier.
77 bit IsConst = 0;
78 // "volatile" qualifier.
79 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000080 // Access qualifier. Must be one of ("RO", "WO", "RW").
81 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +000082 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000083 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000084}
85
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000086// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000087class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000088 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +000089 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000090 // Inherited fields
91 let IsPointer = _Ty.IsPointer;
92 let IsConst = _Ty.IsConst;
93 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000094 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000095}
96
Sven van Haastregtb21a3652019-08-19 11:56:03 +000097// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000098class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt79a222f2019-06-03 09:39:11 +000099 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000100 let AddrSpace = _AS.Name;
101 // Inherited fields
102 let VecWidth = _Ty.VecWidth;
103 let IsPointer = 1;
104 let IsConst = _Ty.IsConst;
105 let IsVolatile = _Ty.IsVolatile;
106 let AccessQualifier = _Ty.AccessQualifier;
107}
108
109// OpenCL const types (e.g. const int).
110class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
111 let IsConst = 1;
112 // Inherited fields
113 let VecWidth = _Ty.VecWidth;
114 let IsPointer = _Ty.IsPointer;
115 let IsVolatile = _Ty.IsVolatile;
116 let AccessQualifier = _Ty.AccessQualifier;
117 let AddrSpace = _Ty.AddrSpace;
118}
119
120// OpenCL volatile types (e.g. volatile int).
121class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
122 let IsVolatile = 1;
123 // Inherited fields
124 let VecWidth = _Ty.VecWidth;
125 let IsPointer = _Ty.IsPointer;
126 let IsConst = _Ty.IsConst;
127 let AccessQualifier = _Ty.AccessQualifier;
128 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000129}
130
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000131// OpenCL image types (e.g. image2d).
132class ImageType<Type _Ty, string _AccessQualifier> :
133 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
134 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000135 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000136 // Inherited fields
137 let IsPointer = _Ty.IsPointer;
138 let IsConst = _Ty.IsConst;
139 let IsVolatile = _Ty.IsVolatile;
140 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000141}
142
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000143// List of Types.
144class TypeList<string _Name, list<Type> _Type> {
145 string Name = _Name;
146 list<Type> List = _Type;
147}
148
149// A GenericType is an abstract type that defines a set of types as a
150// combination of Types and vector sizes.
151//
Sven van Haastregt47e95ff2019-09-17 13:32:56 +0000152// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it
153// represents <int, int2, int4, float, float2, float4>.
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000154//
155// Some rules apply when using multiple GenericType arguments in a declaration:
156// 1. The number of vector sizes must be equal or 1 for all gentypes in a
157// declaration.
158// 2. The number of Types must be equal or 1 for all gentypes in a
159// declaration.
160// 3. Generic types are combined by iterating over all generic types at once.
161// For example, for the following GenericTypes
162// GenT1 = GenericType<half, [1, 2]> and
163// GenT2 = GenericType<float, int, [1, 2]>
164// A declaration f(GenT1, GenT2) results in the combinations
165// f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
166// 4. "sgentype" from the OpenCL specification is supported by specifying
167// a single vector size.
168// For example, for the following GenericTypes
169// GenT = GenericType<half, int, [1, 2]> and
170// SGenT = GenericType<half, int, [1]>
171// A declaration f(GenT, SGenT) results in the combinations
172// f(half, half), f(half2, half), f(int, int), f(int2, int) .
173class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
174 Type<_Ty, QualType<"null", 1>> {
175 // Possible element types of the generic type.
176 TypeList TypeList = _TypeList;
177 // Possible vector sizes of the types in the TypeList.
178 IntList VectorList = _VectorList;
179 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
180 let VecWidth = 0;
181}
182
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000183//===----------------------------------------------------------------------===//
184// OpenCL C class for builtin functions
185//===----------------------------------------------------------------------===//
186class Builtin<string _Name, list<Type> _Signature> {
187 // Name of the builtin function
188 string Name = _Name;
189 // List of types used by the function. The first one is the return type and
190 // the following are the arguments. The list must have at least one element
191 // (the return type).
192 list<Type> Signature = _Signature;
193 // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
194 string Extension = "";
Sven van Haastregted69faa2019-09-19 13:41:51 +0000195 // Version of OpenCL from which the function is available (e.g.: CL10).
196 // MinVersion is inclusive.
197 Version MinVersion = CL10;
198 // Version of OpenCL from which the function is not supported anymore.
199 // MaxVersion is exclusive.
200 // CLAll makes the function available for all versions.
201 Version MaxVersion = CLAll;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000202}
203
204//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000205// Definitions of OpenCL C types
206//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000207
208// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types.
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000209def Bool : Type<"bool", QualType<"BoolTy">>;
210def Char : Type<"char", QualType<"CharTy">>;
211def UChar : Type<"uchar", QualType<"UnsignedCharTy">>;
212def Short : Type<"short", QualType<"ShortTy">>;
213def UShort : Type<"ushort", QualType<"UnsignedShortTy">>;
214def Int : Type<"int", QualType<"IntTy">>;
215def UInt : Type<"uint", QualType<"UnsignedIntTy">>;
216def Long : Type<"long", QualType<"LongTy">>;
217def ULong : Type<"ulong", QualType<"UnsignedLongTy">>;
218def Float : Type<"float", QualType<"FloatTy">>;
219def Double : Type<"double", QualType<"DoubleTy">>;
220def Half : Type<"half", QualType<"HalfTy">>;
221def Size : Type<"size_t", QualType<"getSizeType()">>;
222def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>;
223def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>;
224def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>;
225def Void : Type<"void_t", QualType<"VoidTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000226
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000227// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types.
228// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter.
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000229
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000230// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types.
231// The image definitions are "abstract". They should not be used without
232// specifying an access qualifier (RO/WO/RW).
233def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>;
234def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>;
235def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>;
236def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>;
237def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>;
238def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>;
239def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>;
240def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>;
241def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>;
242def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>;
243def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>;
244def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000245
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000246def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>;
247def Event : Type<"Event", QualType<"OCLEventTy">>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000248
249//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000250// Definitions of OpenCL gentype variants
251//===----------------------------------------------------------------------===//
252// The OpenCL specification often uses "gentype" in builtin function
253// declarations to indicate that a builtin function is available with various
254// argument and return types. The types represented by "gentype" vary between
255// different parts of the specification. The following definitions capture
256// the different type lists for gentypes in different parts of the
257// specification.
258
259// Vector width lists.
260def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
261def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
262def Vec1 : IntList<"Vec1", [1]>;
263
264// Type lists.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000265def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000266def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>;
267
268def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>;
269
270// GenType definitions for multiple base types (e.g. all floating point types,
271// or all integer types).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000272// All types
273def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>;
274def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>;
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000275// All integer
276def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>;
277def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>;
278def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>;
279// Float
280def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>;
281
282// GenType definitions for every single base type (e.g. fp32 only).
283// Names are like: GenTypeFloatVecAndScalar.
284foreach Type = [Char, UChar, Short, UShort,
285 Int, UInt, Long, ULong,
286 Float, Double, Half] in {
287 foreach VecSizes = [VecAndScalar, VecNoScalar] in {
288 def "GenType" # Type # VecSizes :
289 GenericType<"GenType" # Type # VecSizes,
290 TypeList<"GL" # Type.Name, [Type]>,
291 VecSizes>;
292 }
293}
294
295
296//===----------------------------------------------------------------------===//
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000297// Definitions of OpenCL builtin functions
298//===----------------------------------------------------------------------===//
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000299//--------------------------------------------------------------------
300// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions.
301// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions.
302
303// Generate the convert_* builtins functions.
304foreach RType = [Float, Double, Half, Char, UChar, Short,
305 UShort, Int, UInt, Long, ULong] in {
306 foreach IType = [Float, Double, Half, Char, UChar, Short,
307 UShort, Int, UInt, Long, ULong] in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000308 foreach sat = ["", "_sat"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000309 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in {
310 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000311 foreach v = [2, 3, 4, 8, 16] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000312 def : Builtin<"convert_" # RType.Name # v # sat # rnd,
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000313 [VectorType<RType, v>,
314 VectorType<IType, v>]>;
315 }
316 }
317 }
318 }
319}
320
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000321//--------------------------------------------------------------------
Sven van Haastregted69faa2019-09-19 13:41:51 +0000322// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions
323// --- Table 7 ---
324def : Builtin<"get_work_dim", [UInt]>;
325foreach name = ["get_global_size", "get_global_id", "get_local_size",
326 "get_local_id", "get_num_groups", "get_group_id",
327 "get_global_offset"] in {
328 def : Builtin<name, [Size, UInt]>;
329}
330
331let MinVersion = CL20 in {
332 def : Builtin<"get_enqueued_local_size", [Size, UInt]>;
333 foreach name = ["get_global_linear_id", "get_local_linear_id"] in {
334 def : Builtin<name, [Size]>;
335 }
336}
337
338//--------------------------------------------------------------------
339// OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions
340// OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s9.4.6, v2.0 s5.1.6 and 6.1.6 - Vector Data Load and Store Functions
341// --- Table 15 ---
342// Variants for OpenCL versions below 2.0, using pointers to the global, local
343// and private address spaces.
344let MaxVersion = CL20 in {
345 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
346 foreach VSize = [2, 3, 4, 8, 16] in {
347 foreach name = ["vload" # VSize] in {
348 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
349 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
350 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
351 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
352 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
353 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
354 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
355 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
356 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
357 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
358 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
359 }
360 foreach name = ["vstore" # VSize] in {
361 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>;
362 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>;
363 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>;
364 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>;
365 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>;
366 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>;
367 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>;
368 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>;
369 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>;
370 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>;
371 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
372 }
373 foreach name = ["vloada_half" # VSize] in {
374 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>;
375 }
376 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
377 foreach name = ["vstorea_half" # VSize # rnd] in {
378 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>;
379 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>;
380 }
381 }
382 }
383 }
384}
385// Variants for OpenCL versions above 2.0, using pointers to the generic
386// address space.
387let MinVersion = CL20 in {
388 foreach VSize = [2, 3, 4, 8, 16] in {
389 foreach name = ["vload" # VSize] in {
390 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
391 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
392 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
393 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
394 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
395 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
396 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
397 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
398 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
399 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
400 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
401 }
402 foreach name = ["vstore" # VSize] in {
403 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>;
404 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>;
405 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>;
406 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>;
407 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>;
408 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>;
409 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>;
410 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>;
411 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>;
412 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>;
413 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
414 }
415 foreach name = ["vloada_half" # VSize] in {
416 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>;
417 }
418 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
419 foreach name = ["vstorea_half" # VSize # rnd] in {
420 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>;
421 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>;
422 }
423 }
424 }
425}
426// Variants using pointers to the constant address space.
427foreach VSize = [2, 3, 4, 8, 16] in {
428 foreach name = ["vload" # VSize] in {
429 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>;
430 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>;
431 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>;
432 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>;
433 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>;
434 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>;
435 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>;
436 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>;
437 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>;
438 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>;
439 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
440 }
441 foreach name = ["vloada_half" # VSize] in {
442 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>;
443 }
444 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
445 foreach name = ["vstorea_half" # VSize # rnd] in {
446 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>;
447 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>;
448 }
449 }
450}
451
452//--------------------------------------------------------------------
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000453// 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
454// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
455// --- Table 18 ---
456foreach name = ["async_work_group_copy"] in {
457 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
458 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
459}
460foreach name = ["async_work_group_strided_copy"] in {
461 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
462 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
463}
464foreach name = ["wait_group_events"] in {
465 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
466}
467foreach name = ["prefetch"] in {
468 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
469}
470
471//--------------------------------------------------------------------
472// OpenCL v2.0 s6.13.11 - Atomics Functions.
473// Functions that use memory_order and cl_mem_fence_flags enums are not
474// declared here as the TableGen backend does not handle enums.
475
476// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers.
477// --- Table 9.1 ---
478foreach Type = [Int, UInt] in {
479 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
480 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
481 }
482 foreach name = ["atom_inc", "atom_dec"] in {
483 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
484 }
485 foreach name = ["atom_cmpxchg"] in {
486 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
487 }
488}
489
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000490// OpenCL v1.2 s6.12.2: Math Functions
491foreach name = ["acos", "acosh", "acospi",
492 "asin", "asinh", "asinpi",
493 "atan", "atanh", "atanpi"] in {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000494 def : Builtin<name, [FGenTypeN, FGenTypeN]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000495}
496
497foreach name = ["atan2", "atan2pi"] in {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000498 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000499}
500
501foreach name = ["fmax", "fmin"] in {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000502 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
503 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float]>;
504 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double]>;
505 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half]>;
506}
507
508// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
509foreach name = ["max", "min"] in {
510 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN]>;
511 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000512}
513
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000514//--------------------------------------------------------------------
515// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
516// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
517// --- Table 22: Image Read Functions with Samplers ---
518foreach imgTy = [Image1d] in {
519 foreach coordTy = [Int, Float] in {
520 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
521 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
522 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
523 }
524}
525foreach imgTy = [Image2d, Image1dArray] in {
526 foreach coordTy = [Int, Float] in {
527 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
528 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
529 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
530 }
531}
532foreach imgTy = [Image3d, Image2dArray] in {
533 foreach coordTy = [Int, Float] in {
534 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
535 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
536 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
537 }
538}
539foreach coordTy = [Int, Float] in {
540 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>]>;
541 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>]>;
542}
543
544// --- Table 23: Sampler-less Read Functions ---
545foreach aQual = ["RO", "RW"] in {
546 foreach imgTy = [Image2d, Image1dArray] in {
547 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
548 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
549 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
550 }
551 foreach imgTy = [Image3d, Image2dArray] in {
552 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
553 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
554 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
555 }
556 foreach imgTy = [Image1d, Image1dBuffer] in {
557 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int]>;
558 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int]>;
559 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int]>;
560 }
561 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>]>;
562 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>]>;
563}
564
565// --- Table 24: Image Write Functions ---
566foreach aQual = ["WO", "RW"] in {
567 foreach imgTy = [Image2d] in {
568 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
569 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
570 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
571 }
572 foreach imgTy = [Image2dArray] in {
573 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
574 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
575 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
576 }
577 foreach imgTy = [Image1d, Image1dBuffer] in {
578 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
579 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
580 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
581 }
582 foreach imgTy = [Image1dArray] in {
583 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
584 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
585 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
586 }
587 foreach imgTy = [Image3d] in {
588 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
589 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
590 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
591 }
592 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
593 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
594}
595
Sven van Haastregt2a69ed02019-09-25 09:12:59 +0000596// --- Table 25: Image Query Functions ---
597foreach aQual = ["RO", "WO", "RW"] in {
598 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
599 Image1dArray, Image2dArray, Image2dDepth,
600 Image2dArrayDepth] in {
601 foreach name = ["get_image_width", "get_image_channel_data_type",
602 "get_image_channel_order"] in {
603 def : Builtin<name, [Int, ImageType<imgTy, aQual>]>;
604 }
605 }
606 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth,
607 Image2dArrayDepth] in {
608 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>;
609 }
610 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>;
611 foreach imgTy = [Image2d, Image2dArray, Image2dDepth,
612 Image2dArrayDepth] in {
613 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>;
614 }
615 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>;
616 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
617 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>;
618 }
619}
620
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000621// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
622// --- Table 8 ---
623foreach aQual = ["RO"] in {
624 foreach name = ["read_imageh"] in {
625 foreach coordTy = [Int, Float] in {
626 foreach imgTy = [Image2d, Image1dArray] in {
627 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>]>;
628 }
629 foreach imgTy = [Image3d, Image2dArray] in {
630 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>]>;
631 }
632 foreach imgTy = [Image1d] in {
633 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy]>;
634 }
635 }
636 }
637}
638// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
639// --- Table 9 ---
640foreach aQual = ["RO", "RW"] in {
641 foreach name = ["read_imageh"] in {
642 foreach imgTy = [Image2d, Image1dArray] in {
643 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
644 }
645 foreach imgTy = [Image3d, Image2dArray] in {
646 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
647 }
648 foreach imgTy = [Image1d, Image1dBuffer] in {
649 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int]>;
650 }
651 }
652}
653// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
654// --- Table 10 ---
655foreach aQual = ["WO", "RW"] in {
656 foreach name = ["write_imageh"] in {
657 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
658 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
659 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
660 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
661 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
662 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
663 }
664}
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000665
666
667// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
Sven van Haastregted69faa2019-09-19 13:41:51 +0000668let MinVersion = CL20 in {
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000669 let Extension = "cl_khr_subgroups" in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000670 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
671 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
672 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000673 }
674}