blob: 5da67e339da46bb9076639a944d3f31f40a75665 [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> {
23 int Version = _Version;
24}
25def CL10: Version<100>;
26def CL11: Version<110>;
27def CL12: Version<120>;
28def CL20: Version<200>;
29
30// Address spaces
31// Pointer types need to be assigned an address space.
32class AddressSpace<string _AS> {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +000033 string Name = _AS;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000034}
Sven van Haastregt89fb9e82019-07-29 14:55:29 +000035def DefaultAS : AddressSpace<"clang::LangAS::Default">;
36def PrivateAS : AddressSpace<"clang::LangAS::opencl_private">;
37def GlobalAS : AddressSpace<"clang::LangAS::opencl_global">;
38def ConstantAS : AddressSpace<"clang::LangAS::opencl_constant">;
39def LocalAS : AddressSpace<"clang::LangAS::opencl_local">;
40def GenericAS : AddressSpace<"clang::LangAS::opencl_generic">;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000041
42
Sven van Haastregtb21a3652019-08-19 11:56:03 +000043// Qualified Type. These map to ASTContext::QualType.
44class QualType<string _Name, bit _IsAbstract=0> {
Sven van Haastregt79a222f2019-06-03 09:39:11 +000045 // Name of the field or function in a clang::ASTContext
46 // E.g. Name="IntTy" for the int type, and "getIntPtrType()" for an intptr_t
47 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000048 // Some QualTypes in this file represent an abstract type for which there is
49 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type
50 // without access qualifiers.
51 bit IsAbstract = _IsAbstract;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000052}
53
Sven van Haastregtb21a3652019-08-19 11:56:03 +000054// List of integers.
55class IntList<string _Name, list<int> _List> {
56 string Name = _Name;
57 list<int> List = _List;
58}
59
Sven van Haastregt79a222f2019-06-03 09:39:11 +000060//===----------------------------------------------------------------------===//
61// OpenCL C classes for types
62//===----------------------------------------------------------------------===//
Sven van Haastregtb21a3652019-08-19 11:56:03 +000063// OpenCL C basic data types (int, float, image2d_t, ...).
64// Its Child classes can represent concrete types (e.g.: VectorType) or
65// custom types (e.g.: GenType).
66// Instances of these child classes should be used in Builtin function
67// arguments. See the definition of the "read_imagef" function as example.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000068class Type<string _Name, QualType _QTName> {
Sven van Haastregtb21a3652019-08-19 11:56:03 +000069 // Name of the Type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000070 string Name = _Name;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000071 // QualType associated with this type.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000072 QualType QTName = _QTName;
Sven van Haastregtb21a3652019-08-19 11:56:03 +000073 // Size of the vector (if applicable).
74 int VecWidth = 1;
75 // Is a pointer.
Sven van Haastregt79a222f2019-06-03 09:39:11 +000076 bit IsPointer = 0;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000077 // "const" qualifier.
78 bit IsConst = 0;
79 // "volatile" qualifier.
80 bit IsVolatile = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000081 // Access qualifier. Must be one of ("RO", "WO", "RW").
82 string AccessQualifier = "";
Sven van Haastregtb21a3652019-08-19 11:56:03 +000083 // Address space.
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000084 string AddrSpace = DefaultAS.Name;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000085}
86
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000087// OpenCL vector types (e.g. int2, int3, int16, float8, ...).
Sven van Haastregt79a222f2019-06-03 09:39:11 +000088class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000089 let VecWidth = _VecWidth;
Sven van Haastregt988f1e32019-09-05 10:01:24 +000090 let AccessQualifier = "";
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000091 // Inherited fields
92 let IsPointer = _Ty.IsPointer;
93 let IsConst = _Ty.IsConst;
94 let IsVolatile = _Ty.IsVolatile;
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000095 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +000096}
97
Sven van Haastregtb21a3652019-08-19 11:56:03 +000098// OpenCL pointer types (e.g. int*, float*, ...).
Sven van Haastregtcc0ba282019-08-20 12:21:03 +000099class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> :
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000100 Type<_Ty.Name, _Ty.QTName> {
Sven van Haastregtcc0ba282019-08-20 12:21:03 +0000101 let AddrSpace = _AS.Name;
102 // Inherited fields
103 let VecWidth = _Ty.VecWidth;
104 let IsPointer = 1;
105 let IsConst = _Ty.IsConst;
106 let IsVolatile = _Ty.IsVolatile;
107 let AccessQualifier = _Ty.AccessQualifier;
108}
109
110// OpenCL const types (e.g. const int).
111class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
112 let IsConst = 1;
113 // Inherited fields
114 let VecWidth = _Ty.VecWidth;
115 let IsPointer = _Ty.IsPointer;
116 let IsVolatile = _Ty.IsVolatile;
117 let AccessQualifier = _Ty.AccessQualifier;
118 let AddrSpace = _Ty.AddrSpace;
119}
120
121// OpenCL volatile types (e.g. volatile int).
122class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTName> {
123 let IsVolatile = 1;
124 // Inherited fields
125 let VecWidth = _Ty.VecWidth;
126 let IsPointer = _Ty.IsPointer;
127 let IsConst = _Ty.IsConst;
128 let AccessQualifier = _Ty.AccessQualifier;
129 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000130}
131
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000132// OpenCL image types (e.g. image2d).
133class ImageType<Type _Ty, string _AccessQualifier> :
134 Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> {
135 let VecWidth = 0;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000136 let AccessQualifier = _AccessQualifier;
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000137 // Inherited fields
138 let IsPointer = _Ty.IsPointer;
139 let IsConst = _Ty.IsConst;
140 let IsVolatile = _Ty.IsVolatile;
141 let AddrSpace = _Ty.AddrSpace;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000142}
143
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000144// List of Types.
145class TypeList<string _Name, list<Type> _Type> {
146 string Name = _Name;
147 list<Type> List = _Type;
148}
149
150// A GenericType is an abstract type that defines a set of types as a
151// combination of Types and vector sizes.
152//
153// E.g.: If TypeList = <int, float> and VectorList = <1, 2, 4>, then it
154// represents <int, int2, int4, float, float2, float4>.
155// _Ty : Name of the GenType.
156// _TypeList : List of basic data Types.
157// _VectorList : Sizes of the vector for each type of the _TypeList, 1 being a
158// scalar.
159//
160// Some rules apply when using multiple GenericType arguments in a declaration:
161// 1. The number of vector sizes must be equal or 1 for all gentypes in a
162// declaration.
163// 2. The number of Types must be equal or 1 for all gentypes in a
164// declaration.
165// 3. Generic types are combined by iterating over all generic types at once.
166// For example, for the following GenericTypes
167// GenT1 = GenericType<half, [1, 2]> and
168// GenT2 = GenericType<float, int, [1, 2]>
169// A declaration f(GenT1, GenT2) results in the combinations
170// f(half, float), f(half2, float2), f(half, int), f(half2, int2) .
171// 4. "sgentype" from the OpenCL specification is supported by specifying
172// a single vector size.
173// For example, for the following GenericTypes
174// GenT = GenericType<half, int, [1, 2]> and
175// SGenT = GenericType<half, int, [1]>
176// A declaration f(GenT, SGenT) results in the combinations
177// f(half, half), f(half2, half), f(int, int), f(int2, int) .
178class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> :
179 Type<_Ty, QualType<"null", 1>> {
180 // Possible element types of the generic type.
181 TypeList TypeList = _TypeList;
182 // Possible vector sizes of the types in the TypeList.
183 IntList VectorList = _VectorList;
184 // The VecWidth field is ignored for GenericTypes. Use VectorList instead.
185 let VecWidth = 0;
186}
187
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000188//===----------------------------------------------------------------------===//
189// OpenCL C class for builtin functions
190//===----------------------------------------------------------------------===//
191class Builtin<string _Name, list<Type> _Signature> {
192 // Name of the builtin function
193 string Name = _Name;
194 // List of types used by the function. The first one is the return type and
195 // the following are the arguments. The list must have at least one element
196 // (the return type).
197 list<Type> Signature = _Signature;
198 // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...)
199 string Extension = "";
200 // OpenCL Version to which the function belongs (CL10, ...)
201 Version Version = CL10;
202}
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//--------------------------------------------------------------------
322// 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
323// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch
324// --- Table 18 ---
325foreach name = ["async_work_group_copy"] in {
326 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>;
327 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>;
328}
329foreach name = ["async_work_group_strided_copy"] in {
330 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>;
331 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>;
332}
333foreach name = ["wait_group_events"] in {
334 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>;
335}
336foreach name = ["prefetch"] in {
337 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>;
338}
339
340//--------------------------------------------------------------------
341// OpenCL v2.0 s6.13.11 - Atomics Functions.
342// Functions that use memory_order and cl_mem_fence_flags enums are not
343// declared here as the TableGen backend does not handle enums.
344
345// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers.
346// --- Table 9.1 ---
347foreach Type = [Int, UInt] in {
348 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
349 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
350 }
351 foreach name = ["atom_inc", "atom_dec"] in {
352 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>;
353 }
354 foreach name = ["atom_cmpxchg"] in {
355 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>;
356 }
357}
358
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000359// OpenCL v1.2 s6.12.1: Work-Item Functions
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000360def get_work_dim : Builtin<"get_work_dim", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000361foreach name = ["get_global_size", "get_global_id", "get_local_size",
362 "get_local_id", "get_num_groups", "get_group_id",
363 "get_global_offset"] in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000364 def : Builtin<name, [Size, UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000365}
366
367// OpenCL v1.2 s6.12.2: Math Functions
368foreach name = ["acos", "acosh", "acospi",
369 "asin", "asinh", "asinpi",
370 "atan", "atanh", "atanpi"] in {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000371 def : Builtin<name, [FGenTypeN, FGenTypeN]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000372}
373
374foreach name = ["atan2", "atan2pi"] in {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000375 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000376}
377
378foreach name = ["fmax", "fmin"] in {
Sven van Haastregtb21a3652019-08-19 11:56:03 +0000379 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>;
380 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float]>;
381 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double]>;
382 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half]>;
383}
384
385// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions
386foreach name = ["max", "min"] in {
387 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN]>;
388 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000389}
390
Sven van Haastregt988f1e32019-09-05 10:01:24 +0000391//--------------------------------------------------------------------
392// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions
393// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions
394// --- Table 22: Image Read Functions with Samplers ---
395foreach imgTy = [Image1d] in {
396 foreach coordTy = [Int, Float] in {
397 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
398 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
399 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy]>;
400 }
401}
402foreach imgTy = [Image2d, Image1dArray] in {
403 foreach coordTy = [Int, Float] in {
404 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
405 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
406 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>]>;
407 }
408}
409foreach imgTy = [Image3d, Image2dArray] in {
410 foreach coordTy = [Int, Float] in {
411 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
412 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
413 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>]>;
414 }
415}
416foreach coordTy = [Int, Float] in {
417 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>]>;
418 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>]>;
419}
420
421// --- Table 23: Sampler-less Read Functions ---
422foreach aQual = ["RO", "RW"] in {
423 foreach imgTy = [Image2d, Image1dArray] in {
424 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
425 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
426 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
427 }
428 foreach imgTy = [Image3d, Image2dArray] in {
429 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
430 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
431 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
432 }
433 foreach imgTy = [Image1d, Image1dBuffer] in {
434 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int]>;
435 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int]>;
436 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int]>;
437 }
438 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>]>;
439 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>]>;
440}
441
442// --- Table 24: Image Write Functions ---
443foreach aQual = ["WO", "RW"] in {
444 foreach imgTy = [Image2d] in {
445 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
446 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
447 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
448 }
449 foreach imgTy = [Image2dArray] in {
450 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
451 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
452 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
453 }
454 foreach imgTy = [Image1d, Image1dBuffer] in {
455 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>;
456 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>;
457 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>;
458 }
459 foreach imgTy = [Image1dArray] in {
460 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>;
461 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>;
462 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
463 }
464 foreach imgTy = [Image3d] in {
465 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>;
466 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>;
467 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>;
468 }
469 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>;
470 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
471}
472
473// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
474// --- Table 8 ---
475foreach aQual = ["RO"] in {
476 foreach name = ["read_imageh"] in {
477 foreach coordTy = [Int, Float] in {
478 foreach imgTy = [Image2d, Image1dArray] in {
479 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>]>;
480 }
481 foreach imgTy = [Image3d, Image2dArray] in {
482 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>]>;
483 }
484 foreach imgTy = [Image1d] in {
485 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy]>;
486 }
487 }
488 }
489}
490// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
491// --- Table 9 ---
492foreach aQual = ["RO", "RW"] in {
493 foreach name = ["read_imageh"] in {
494 foreach imgTy = [Image2d, Image1dArray] in {
495 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>]>;
496 }
497 foreach imgTy = [Image3d, Image2dArray] in {
498 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>]>;
499 }
500 foreach imgTy = [Image1d, Image1dBuffer] in {
501 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int]>;
502 }
503 }
504}
505// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
506// --- Table 10 ---
507foreach aQual = ["WO", "RW"] in {
508 foreach name = ["write_imageh"] in {
509 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
510 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
511 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
512 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>;
513 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>;
514 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
515 }
516}
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000517
518
519// OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions
520let Version = CL20 in {
521 let Extension = "cl_khr_subgroups" in {
Sven van Haastregt89fb9e82019-07-29 14:55:29 +0000522 def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>;
523 def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>;
524 def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>;
Sven van Haastregt79a222f2019-06-03 09:39:11 +0000525 }
526}