Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 1 | //==--- 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 |
| 22 | class Version<int _Version> { |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 23 | int ID = _Version; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 24 | } |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 25 | def CLAll : Version< 0>; |
| 26 | def CL10 : Version<100>; |
| 27 | def CL11 : Version<110>; |
| 28 | def CL12 : Version<120>; |
| 29 | def CL20 : Version<200>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 30 | |
| 31 | // Address spaces |
| 32 | // Pointer types need to be assigned an address space. |
| 33 | class AddressSpace<string _AS> { |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 34 | string Name = _AS; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 35 | } |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 36 | def DefaultAS : AddressSpace<"clang::LangAS::Default">; |
| 37 | def PrivateAS : AddressSpace<"clang::LangAS::opencl_private">; |
| 38 | def GlobalAS : AddressSpace<"clang::LangAS::opencl_global">; |
| 39 | def ConstantAS : AddressSpace<"clang::LangAS::opencl_constant">; |
| 40 | def LocalAS : AddressSpace<"clang::LangAS::opencl_local">; |
| 41 | def GenericAS : AddressSpace<"clang::LangAS::opencl_generic">; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 42 | |
| 43 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 44 | // Qualified Type. These map to ASTContext::QualType. |
| 45 | class QualType<string _Name, bit _IsAbstract=0> { |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 46 | // 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 Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 49 | // 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 55 | // List of integers. |
| 56 | class IntList<string _Name, list<int> _List> { |
| 57 | string Name = _Name; |
| 58 | list<int> List = _List; |
| 59 | } |
| 60 | |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 61 | //===----------------------------------------------------------------------===// |
| 62 | // OpenCL C classes for types |
| 63 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 64 | // OpenCL C basic data types (int, float, image2d_t, ...). |
Sven van Haastregt | 47e95ff | 2019-09-17 13:32:56 +0000 | [diff] [blame] | 65 | // Its child classes can represent concrete types (e.g. VectorType) or |
| 66 | // abstract types (e.g. GenType). |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 67 | class Type<string _Name, QualType _QTName> { |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 68 | // Name of the Type. |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 69 | string Name = _Name; |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 70 | // QualType associated with this type. |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 71 | QualType QTName = _QTName; |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 72 | // Size of the vector (if applicable). |
| 73 | int VecWidth = 1; |
| 74 | // Is a pointer. |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 75 | bit IsPointer = 0; |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 76 | // "const" qualifier. |
| 77 | bit IsConst = 0; |
| 78 | // "volatile" qualifier. |
| 79 | bit IsVolatile = 0; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 80 | // Access qualifier. Must be one of ("RO", "WO", "RW"). |
| 81 | string AccessQualifier = ""; |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 82 | // Address space. |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 83 | string AddrSpace = DefaultAS.Name; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 86 | // OpenCL vector types (e.g. int2, int3, int16, float8, ...). |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 87 | class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTName> { |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 88 | let VecWidth = _VecWidth; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 89 | let AccessQualifier = ""; |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 90 | // Inherited fields |
| 91 | let IsPointer = _Ty.IsPointer; |
| 92 | let IsConst = _Ty.IsConst; |
| 93 | let IsVolatile = _Ty.IsVolatile; |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 94 | let AddrSpace = _Ty.AddrSpace; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 97 | // OpenCL pointer types (e.g. int*, float*, ...). |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 98 | class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> : |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 99 | Type<_Ty.Name, _Ty.QTName> { |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 100 | 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). |
| 110 | class 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). |
| 121 | class 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 Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 131 | // OpenCL image types (e.g. image2d). |
| 132 | class ImageType<Type _Ty, string _AccessQualifier> : |
| 133 | Type<_Ty.Name, QualType<_Ty.QTName.Name#_AccessQualifier#"Ty", 0>> { |
| 134 | let VecWidth = 0; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 135 | let AccessQualifier = _AccessQualifier; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 136 | // Inherited fields |
| 137 | let IsPointer = _Ty.IsPointer; |
| 138 | let IsConst = _Ty.IsConst; |
| 139 | let IsVolatile = _Ty.IsVolatile; |
| 140 | let AddrSpace = _Ty.AddrSpace; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 143 | // List of Types. |
| 144 | class 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 Haastregt | 47e95ff | 2019-09-17 13:32:56 +0000 | [diff] [blame] | 152 | // For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it |
| 153 | // represents <int, int2, int4, float, float2, float4>. |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 154 | // |
| 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) . |
| 173 | class 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 Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 183 | // Builtin function attributes. |
| 184 | def Attr { |
| 185 | list<bit> None = [0, 0, 0]; |
| 186 | list<bit> Pure = [1, 0, 0]; |
| 187 | list<bit> Const = [0, 1, 0]; |
| 188 | list<bit> Convergent = [0, 0, 1]; |
| 189 | } |
| 190 | |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 191 | //===----------------------------------------------------------------------===// |
| 192 | // OpenCL C class for builtin functions |
| 193 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 194 | class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> { |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 195 | // Name of the builtin function |
| 196 | string Name = _Name; |
| 197 | // List of types used by the function. The first one is the return type and |
| 198 | // the following are the arguments. The list must have at least one element |
| 199 | // (the return type). |
| 200 | list<Type> Signature = _Signature; |
| 201 | // OpenCL Extension to which the function belongs (cl_khr_subgroups, ...) |
| 202 | string Extension = ""; |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 203 | // Function attribute __attribute__((pure)) |
| 204 | bit IsPure = _Attributes[0]; |
| 205 | // Function attribute __attribute__((const)) |
| 206 | bit IsConst = _Attributes[1]; |
| 207 | // Function attribute __attribute__((convergent)) |
| 208 | bit IsConv = _Attributes[2]; |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 209 | // Version of OpenCL from which the function is available (e.g.: CL10). |
| 210 | // MinVersion is inclusive. |
| 211 | Version MinVersion = CL10; |
| 212 | // Version of OpenCL from which the function is not supported anymore. |
| 213 | // MaxVersion is exclusive. |
| 214 | // CLAll makes the function available for all versions. |
| 215 | Version MaxVersion = CLAll; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 219 | // Definitions of OpenCL C types |
| 220 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 221 | |
| 222 | // OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types. |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 223 | def Bool : Type<"bool", QualType<"BoolTy">>; |
| 224 | def Char : Type<"char", QualType<"CharTy">>; |
| 225 | def UChar : Type<"uchar", QualType<"UnsignedCharTy">>; |
| 226 | def Short : Type<"short", QualType<"ShortTy">>; |
| 227 | def UShort : Type<"ushort", QualType<"UnsignedShortTy">>; |
| 228 | def Int : Type<"int", QualType<"IntTy">>; |
| 229 | def UInt : Type<"uint", QualType<"UnsignedIntTy">>; |
| 230 | def Long : Type<"long", QualType<"LongTy">>; |
| 231 | def ULong : Type<"ulong", QualType<"UnsignedLongTy">>; |
| 232 | def Float : Type<"float", QualType<"FloatTy">>; |
| 233 | def Double : Type<"double", QualType<"DoubleTy">>; |
| 234 | def Half : Type<"half", QualType<"HalfTy">>; |
| 235 | def Size : Type<"size_t", QualType<"getSizeType()">>; |
| 236 | def PtrDiff : Type<"ptrdiff_t", QualType<"getPointerDiffType()">>; |
| 237 | def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>; |
| 238 | def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>; |
| 239 | def Void : Type<"void_t", QualType<"VoidTy">>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 240 | |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 241 | // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types. |
| 242 | // Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter. |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 243 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 244 | // OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types. |
| 245 | // The image definitions are "abstract". They should not be used without |
| 246 | // specifying an access qualifier (RO/WO/RW). |
| 247 | def Image1d : Type<"Image1d", QualType<"OCLImage1d", 1>>; |
| 248 | def Image2d : Type<"Image2d", QualType<"OCLImage2d", 1>>; |
| 249 | def Image3d : Type<"Image3d", QualType<"OCLImage3d", 1>>; |
| 250 | def Image1dArray : Type<"Image1dArray", QualType<"OCLImage1dArray", 1>>; |
| 251 | def Image1dBuffer : Type<"Image1dBuffer", QualType<"OCLImage1dBuffer", 1>>; |
| 252 | def Image2dArray : Type<"Image2dArray", QualType<"OCLImage2dArray", 1>>; |
| 253 | def Image2dDepth : Type<"Image2dDepth", QualType<"OCLImage2dDepth", 1>>; |
| 254 | def Image2dArrayDepth : Type<"Image2dArrayDepth", QualType<"OCLImage2dArrayDepth", 1>>; |
| 255 | def Image2dMsaa : Type<"Image2dMsaa", QualType<"OCLImage2dMSAA", 1>>; |
| 256 | def Image2dArrayMsaa : Type<"Image2dArrayMsaa", QualType<"OCLImage2dArrayMSAA", 1>>; |
| 257 | def Image2dMsaaDepth : Type<"Image2dMsaaDepth", QualType<"OCLImage2dMSAADepth", 1>>; |
| 258 | def Image2dArrayMsaaDepth : Type<"Image2dArrayMsaaDepth", QualType<"OCLImage2dArrayMSAADepth", 1>>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 259 | |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 260 | def Sampler : Type<"Sampler", QualType<"OCLSamplerTy">>; |
| 261 | def Event : Type<"Event", QualType<"OCLEventTy">>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 262 | |
| 263 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 264 | // Definitions of OpenCL gentype variants |
| 265 | //===----------------------------------------------------------------------===// |
| 266 | // The OpenCL specification often uses "gentype" in builtin function |
| 267 | // declarations to indicate that a builtin function is available with various |
| 268 | // argument and return types. The types represented by "gentype" vary between |
| 269 | // different parts of the specification. The following definitions capture |
| 270 | // the different type lists for gentypes in different parts of the |
| 271 | // specification. |
| 272 | |
| 273 | // Vector width lists. |
| 274 | def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>; |
| 275 | def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>; |
| 276 | def Vec1 : IntList<"Vec1", [1]>; |
| 277 | |
| 278 | // Type lists. |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 279 | def TLAll : TypeList<"TLAll", [Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 280 | def TLFloat : TypeList<"TLFloat", [Float, Double, Half]>; |
| 281 | |
| 282 | def TLAllInts : TypeList<"TLAllInts", [Char, UChar, Short, UShort, Int, UInt, Long, ULong]>; |
| 283 | |
| 284 | // GenType definitions for multiple base types (e.g. all floating point types, |
| 285 | // or all integer types). |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 286 | // All types |
| 287 | def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>; |
| 288 | def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>; |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 289 | // All integer |
| 290 | def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>; |
| 291 | def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>; |
| 292 | def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>; |
| 293 | // Float |
| 294 | def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>; |
| 295 | |
| 296 | // GenType definitions for every single base type (e.g. fp32 only). |
| 297 | // Names are like: GenTypeFloatVecAndScalar. |
| 298 | foreach Type = [Char, UChar, Short, UShort, |
| 299 | Int, UInt, Long, ULong, |
| 300 | Float, Double, Half] in { |
| 301 | foreach VecSizes = [VecAndScalar, VecNoScalar] in { |
| 302 | def "GenType" # Type # VecSizes : |
| 303 | GenericType<"GenType" # Type # VecSizes, |
| 304 | TypeList<"GL" # Type.Name, [Type]>, |
| 305 | VecSizes>; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | |
| 310 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 311 | // Definitions of OpenCL builtin functions |
| 312 | //===----------------------------------------------------------------------===// |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 313 | //-------------------------------------------------------------------- |
| 314 | // OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions. |
| 315 | // OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions. |
| 316 | |
| 317 | // Generate the convert_* builtins functions. |
| 318 | foreach RType = [Float, Double, Half, Char, UChar, Short, |
| 319 | UShort, Int, UInt, Long, ULong] in { |
| 320 | foreach IType = [Float, Double, Half, Char, UChar, Short, |
| 321 | UShort, Int, UInt, Long, ULong] in { |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 322 | foreach sat = ["", "_sat"] in { |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 323 | foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 324 | def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType], |
| 325 | Attr.Const>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 326 | foreach v = [2, 3, 4, 8, 16] in { |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 327 | def : Builtin<"convert_" # RType.Name # v # sat # rnd, |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 328 | [VectorType<RType, v>, VectorType<IType, v>], |
| 329 | Attr.Const>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 336 | //-------------------------------------------------------------------- |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 337 | // OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions |
| 338 | // --- Table 7 --- |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 339 | def : Builtin<"get_work_dim", [UInt], Attr.Const>; |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 340 | foreach name = ["get_global_size", "get_global_id", "get_local_size", |
| 341 | "get_local_id", "get_num_groups", "get_group_id", |
| 342 | "get_global_offset"] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 343 | def : Builtin<name, [Size, UInt], Attr.Const>; |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | let MinVersion = CL20 in { |
| 347 | def : Builtin<"get_enqueued_local_size", [Size, UInt]>; |
| 348 | foreach name = ["get_global_linear_id", "get_local_linear_id"] in { |
| 349 | def : Builtin<name, [Size]>; |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | //-------------------------------------------------------------------- |
| 354 | // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions |
| 355 | // 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 |
| 356 | // --- Table 15 --- |
| 357 | // Variants for OpenCL versions below 2.0, using pointers to the global, local |
| 358 | // and private address spaces. |
| 359 | let MaxVersion = CL20 in { |
| 360 | foreach AS = [GlobalAS, LocalAS, PrivateAS] in { |
| 361 | foreach VSize = [2, 3, 4, 8, 16] in { |
| 362 | foreach name = ["vload" # VSize] in { |
| 363 | def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>; |
| 364 | def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>; |
| 365 | def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>; |
| 366 | def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>; |
| 367 | def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>; |
| 368 | def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>; |
| 369 | def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>; |
| 370 | def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>; |
| 371 | def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>; |
| 372 | def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>; |
| 373 | def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>; |
| 374 | } |
| 375 | foreach name = ["vstore" # VSize] in { |
| 376 | def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>; |
| 377 | def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>; |
| 378 | def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>; |
| 379 | def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>; |
| 380 | def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>; |
| 381 | def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>; |
| 382 | def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>; |
| 383 | def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>; |
| 384 | def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>; |
| 385 | def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>; |
| 386 | def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>; |
| 387 | } |
| 388 | foreach name = ["vloada_half" # VSize] in { |
| 389 | def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; |
| 390 | } |
| 391 | foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { |
| 392 | foreach name = ["vstorea_half" # VSize # rnd] in { |
| 393 | def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>; |
| 394 | def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>; |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | // Variants for OpenCL versions above 2.0, using pointers to the generic |
| 401 | // address space. |
| 402 | let MinVersion = CL20 in { |
| 403 | foreach VSize = [2, 3, 4, 8, 16] in { |
| 404 | foreach name = ["vload" # VSize] in { |
| 405 | def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>; |
| 406 | def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>; |
| 407 | def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>; |
| 408 | def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>; |
| 409 | def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>; |
| 410 | def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>; |
| 411 | def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>; |
| 412 | def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>; |
| 413 | def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>; |
| 414 | def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>; |
| 415 | def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>; |
| 416 | } |
| 417 | foreach name = ["vstore" # VSize] in { |
| 418 | def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>; |
| 419 | def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>; |
| 420 | def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>; |
| 421 | def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>; |
| 422 | def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>; |
| 423 | def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>; |
| 424 | def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>; |
| 425 | def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>; |
| 426 | def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>; |
| 427 | def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>; |
| 428 | def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>; |
| 429 | } |
| 430 | foreach name = ["vloada_half" # VSize] in { |
| 431 | def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>; |
| 432 | } |
| 433 | foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { |
| 434 | foreach name = ["vstorea_half" # VSize # rnd] in { |
| 435 | def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>; |
| 436 | def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>; |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | // Variants using pointers to the constant address space. |
| 442 | foreach VSize = [2, 3, 4, 8, 16] in { |
| 443 | foreach name = ["vload" # VSize] in { |
| 444 | def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>; |
| 445 | def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>; |
| 446 | def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>; |
| 447 | def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>; |
| 448 | def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>; |
| 449 | def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>; |
| 450 | def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>; |
| 451 | def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>; |
| 452 | def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>; |
| 453 | def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>; |
| 454 | def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>; |
| 455 | } |
| 456 | foreach name = ["vloada_half" # VSize] in { |
| 457 | def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>; |
| 458 | } |
| 459 | foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { |
| 460 | foreach name = ["vstorea_half" # VSize # rnd] in { |
| 461 | def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, ConstantAS>]>; |
| 462 | def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, ConstantAS>]>; |
| 463 | } |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | //-------------------------------------------------------------------- |
Sven van Haastregt | cc0ba28 | 2019-08-20 12:21:03 +0000 | [diff] [blame] | 468 | // 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 |
| 469 | // OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch |
| 470 | // --- Table 18 --- |
| 471 | foreach name = ["async_work_group_copy"] in { |
| 472 | def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>; |
| 473 | def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>; |
| 474 | } |
| 475 | foreach name = ["async_work_group_strided_copy"] in { |
| 476 | def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>; |
| 477 | def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>; |
| 478 | } |
| 479 | foreach name = ["wait_group_events"] in { |
| 480 | def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>; |
| 481 | } |
| 482 | foreach name = ["prefetch"] in { |
| 483 | def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>; |
| 484 | } |
| 485 | |
| 486 | //-------------------------------------------------------------------- |
| 487 | // OpenCL v2.0 s6.13.11 - Atomics Functions. |
| 488 | // Functions that use memory_order and cl_mem_fence_flags enums are not |
| 489 | // declared here as the TableGen backend does not handle enums. |
| 490 | |
| 491 | // OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers. |
| 492 | // --- Table 9.1 --- |
| 493 | foreach Type = [Int, UInt] in { |
| 494 | foreach name = ["atom_add", "atom_sub", "atom_xchg"] in { |
| 495 | def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>; |
| 496 | } |
| 497 | foreach name = ["atom_inc", "atom_dec"] in { |
| 498 | def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>; |
| 499 | } |
| 500 | foreach name = ["atom_cmpxchg"] in { |
| 501 | def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>; |
| 502 | } |
| 503 | } |
| 504 | |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 505 | // OpenCL v1.2 s6.12.2: Math Functions |
| 506 | foreach name = ["acos", "acosh", "acospi", |
| 507 | "asin", "asinh", "asinpi", |
| 508 | "atan", "atanh", "atanpi"] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 509 | def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | foreach name = ["atan2", "atan2pi"] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 513 | def : Builtin<name, [FGenTypeN, FGenTypeN,FGenTypeN], Attr.Const>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | foreach name = ["fmax", "fmin"] in { |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 517 | def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN]>; |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 518 | def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>; |
| 519 | def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>; |
| 520 | def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>; |
Sven van Haastregt | b21a365 | 2019-08-19 11:56:03 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | // OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions |
| 524 | foreach name = ["max", "min"] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 525 | def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>; |
| 526 | def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 529 | //-------------------------------------------------------------------- |
| 530 | // OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions |
| 531 | // OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions |
| 532 | // --- Table 22: Image Read Functions with Samplers --- |
| 533 | foreach imgTy = [Image1d] in { |
| 534 | foreach coordTy = [Int, Float] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 535 | def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>; |
| 536 | def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>; |
| 537 | def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | foreach imgTy = [Image2d, Image1dArray] in { |
| 541 | foreach coordTy = [Int, Float] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 542 | def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; |
| 543 | def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; |
| 544 | def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | foreach imgTy = [Image3d, Image2dArray] in { |
| 548 | foreach coordTy = [Int, Float] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 549 | def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; |
| 550 | def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; |
| 551 | def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | foreach coordTy = [Int, Float] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 555 | def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; |
| 556 | def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | // --- Table 23: Sampler-less Read Functions --- |
| 560 | foreach aQual = ["RO", "RW"] in { |
| 561 | foreach imgTy = [Image2d, Image1dArray] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 562 | def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; |
| 563 | def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; |
| 564 | def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 565 | } |
| 566 | foreach imgTy = [Image3d, Image2dArray] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 567 | def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; |
| 568 | def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; |
| 569 | def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 570 | } |
| 571 | foreach imgTy = [Image1d, Image1dBuffer] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 572 | def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; |
| 573 | def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; |
| 574 | def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 575 | } |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 576 | def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>; |
| 577 | def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | // --- Table 24: Image Write Functions --- |
| 581 | foreach aQual = ["WO", "RW"] in { |
| 582 | foreach imgTy = [Image2d] 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 = [Image2dArray] 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 | foreach imgTy = [Image1d, Image1dBuffer] in { |
| 593 | def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>; |
| 594 | def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>; |
| 595 | def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>; |
| 596 | } |
| 597 | foreach imgTy = [Image1dArray] in { |
| 598 | def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>; |
| 599 | def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>; |
| 600 | def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>; |
| 601 | } |
| 602 | foreach imgTy = [Image3d] in { |
| 603 | def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>; |
| 604 | def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>; |
| 605 | def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>; |
| 606 | } |
| 607 | def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>; |
| 608 | def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>; |
| 609 | } |
| 610 | |
Sven van Haastregt | 2a69ed0 | 2019-09-25 09:12:59 +0000 | [diff] [blame] | 611 | // --- Table 25: Image Query Functions --- |
| 612 | foreach aQual = ["RO", "WO", "RW"] in { |
| 613 | foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d, |
| 614 | Image1dArray, Image2dArray, Image2dDepth, |
| 615 | Image2dArrayDepth] in { |
| 616 | foreach name = ["get_image_width", "get_image_channel_data_type", |
| 617 | "get_image_channel_order"] in { |
| 618 | def : Builtin<name, [Int, ImageType<imgTy, aQual>]>; |
| 619 | } |
| 620 | } |
| 621 | foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth, |
| 622 | Image2dArrayDepth] in { |
| 623 | def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>]>; |
| 624 | } |
| 625 | def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>]>; |
| 626 | foreach imgTy = [Image2d, Image2dArray, Image2dDepth, |
| 627 | Image2dArrayDepth] in { |
| 628 | def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>]>; |
| 629 | } |
| 630 | def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>]>; |
| 631 | foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in { |
| 632 | def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>]>; |
| 633 | } |
| 634 | } |
| 635 | |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 636 | // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions |
| 637 | // --- Table 8 --- |
| 638 | foreach aQual = ["RO"] in { |
| 639 | foreach name = ["read_imageh"] in { |
| 640 | foreach coordTy = [Int, Float] in { |
| 641 | foreach imgTy = [Image2d, Image1dArray] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 642 | def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 643 | } |
| 644 | foreach imgTy = [Image3d, Image2dArray] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 645 | def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 646 | } |
| 647 | foreach imgTy = [Image1d] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 648 | def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions |
| 654 | // --- Table 9 --- |
| 655 | foreach aQual = ["RO", "RW"] in { |
| 656 | foreach name = ["read_imageh"] in { |
| 657 | foreach imgTy = [Image2d, Image1dArray] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 658 | def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 659 | } |
| 660 | foreach imgTy = [Image3d, Image2dArray] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 661 | def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 662 | } |
| 663 | foreach imgTy = [Image1d, Image1dBuffer] in { |
Sven van Haastregt | 9a8d477 | 2019-11-05 10:07:43 +0000 | [diff] [blame^] | 664 | def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; |
Sven van Haastregt | 988f1e3 | 2019-09-05 10:01:24 +0000 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | } |
| 668 | // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions |
| 669 | // --- Table 10 --- |
| 670 | foreach aQual = ["WO", "RW"] in { |
| 671 | foreach name = ["write_imageh"] in { |
| 672 | def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>; |
| 673 | def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>; |
| 674 | def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>; |
| 675 | def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>; |
| 676 | def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>; |
| 677 | def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>; |
| 678 | } |
| 679 | } |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 680 | |
| 681 | |
| 682 | // OpenCL v2.0 s9.17.3: Additions to section 6.13.1: Work-Item Functions |
Sven van Haastregt | ed69faa | 2019-09-19 13:41:51 +0000 | [diff] [blame] | 683 | let MinVersion = CL20 in { |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 684 | let Extension = "cl_khr_subgroups" in { |
Sven van Haastregt | 89fb9e8 | 2019-07-29 14:55:29 +0000 | [diff] [blame] | 685 | def get_sub_group_size : Builtin<"get_sub_group_size", [UInt]>; |
| 686 | def get_max_sub_group_size : Builtin<"get_max_sub_group_size", [UInt]>; |
| 687 | def get_num_sub_groups : Builtin<"get_num_sub_groups", [UInt]>; |
Sven van Haastregt | 79a222f | 2019-06-03 09:39:11 +0000 | [diff] [blame] | 688 | } |
| 689 | } |