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 22class Version<int _Version> { 23 int ID = _Version; 24} 25def CLAll : Version< 0>; 26def CL10 : Version<100>; 27def CL11 : Version<110>; 28def CL12 : Version<120>; 29def CL20 : Version<200>; 30 31// Address spaces 32// Pointer types need to be assigned an address space. 33class AddressSpace<string _AS> { 34 string Name = _AS; 35} 36def 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">; 42 43// OpenCL language extension. 44class AbstractExtension<string _Ext> { 45 // One or more OpenCL extensions, space separated. Each extension must be 46 // a valid extension name for the opencl extension pragma. 47 string ExtName = _Ext; 48} 49 50// Extension associated to a builtin function. 51class FunctionExtension<string _Ext> : AbstractExtension<_Ext>; 52 53// Extension associated to a type. This enables implicit conditionalization of 54// builtin function overloads containing a type that depends on an extension. 55// During overload resolution, when a builtin function overload contains a type 56// with a TypeExtension, those overloads are skipped when the extension is 57// disabled. 58class TypeExtension<string _Ext> : AbstractExtension<_Ext>; 59 60// TypeExtension definitions. 61def NoTypeExt : TypeExtension<"">; 62def Fp16TypeExt : TypeExtension<"cl_khr_fp16">; 63def Fp64TypeExt : TypeExtension<"cl_khr_fp64">; 64 65// FunctionExtension definitions. 66def FuncExtNone : FunctionExtension<"">; 67def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">; 68def FuncExtKhrSubgroupExtendedTypes : FunctionExtension<"cl_khr_subgroup_extended_types">; 69def FuncExtKhrSubgroupNonUniformVote : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">; 70def FuncExtKhrSubgroupBallot : FunctionExtension<"cl_khr_subgroup_ballot">; 71def FuncExtKhrSubgroupNonUniformArithmetic: FunctionExtension<"cl_khr_subgroup_non_uniform_arithmetic">; 72def FuncExtKhrSubgroupShuffle : FunctionExtension<"cl_khr_subgroup_shuffle">; 73def FuncExtKhrSubgroupShuffleRelative : FunctionExtension<"cl_khr_subgroup_shuffle_relative">; 74def FuncExtKhrSubgroupClusteredReduce : FunctionExtension<"cl_khr_subgroup_clustered_reduce">; 75def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">; 76def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">; 77def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">; 78def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">; 79def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">; 80def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">; 81def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">; 82def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">; 83def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">; 84 85// Not a real extension, but a workaround to add C++ for OpenCL specific builtins. 86def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">; 87 88// Multiple extensions 89def FuncExtKhrMipmapWritesAndWrite3d : FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">; 90 91// Arm extensions. 92def ArmIntegerDotProductInt8 : FunctionExtension<"cl_arm_integer_dot_product_int8">; 93def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">; 94def ArmIntegerDotProductAccumulateInt16 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">; 95def ArmIntegerDotProductAccumulateSaturateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_saturate_int8">; 96 97// Qualified Type. These map to ASTContext::QualType. 98class QualType<string _TypeExpr, bit _IsAbstract=0> { 99 // Expression to obtain the QualType inside OCL2Qual. 100 // E.g. TypeExpr="Context.IntTy" for the int type. 101 string TypeExpr = _TypeExpr; 102 // Some QualTypes in this file represent an abstract type for which there is 103 // no corresponding AST QualType, e.g. a GenType or an `image2d_t` type 104 // without access qualifiers. 105 bit IsAbstract = _IsAbstract; 106} 107 108// List of integers. 109class IntList<string _Name, list<int> _List> { 110 string Name = _Name; 111 list<int> List = _List; 112} 113 114//===----------------------------------------------------------------------===// 115// OpenCL C classes for types 116//===----------------------------------------------------------------------===// 117// OpenCL C basic data types (int, float, image2d_t, ...). 118// Its child classes can represent concrete types (e.g. VectorType) or 119// abstract types (e.g. GenType). 120class Type<string _Name, QualType _QTExpr> { 121 // Name of the Type. 122 string Name = _Name; 123 // QualType associated with this type. 124 QualType QTExpr = _QTExpr; 125 // Size of the vector (if applicable). 126 int VecWidth = 1; 127 // Is a pointer. 128 bit IsPointer = 0; 129 // "const" qualifier. 130 bit IsConst = 0; 131 // "volatile" qualifier. 132 bit IsVolatile = 0; 133 // Access qualifier. Must be one of ("RO", "WO", "RW"). 134 string AccessQualifier = ""; 135 // Address space. 136 string AddrSpace = DefaultAS.Name; 137 // Extension that needs to be enabled to expose a builtin that uses this type. 138 TypeExtension Extension = NoTypeExt; 139} 140 141// OpenCL vector types (e.g. int2, int3, int16, float8, ...). 142class VectorType<Type _Ty, int _VecWidth> : Type<_Ty.Name, _Ty.QTExpr> { 143 let VecWidth = _VecWidth; 144 let AccessQualifier = ""; 145 // Inherited fields 146 let IsPointer = _Ty.IsPointer; 147 let IsConst = _Ty.IsConst; 148 let IsVolatile = _Ty.IsVolatile; 149 let AddrSpace = _Ty.AddrSpace; 150 let Extension = _Ty.Extension; 151} 152 153// OpenCL pointer types (e.g. int*, float*, ...). 154class PointerType<Type _Ty, AddressSpace _AS = DefaultAS> : 155 Type<_Ty.Name, _Ty.QTExpr> { 156 let AddrSpace = _AS.Name; 157 // Inherited fields 158 let VecWidth = _Ty.VecWidth; 159 let IsPointer = 1; 160 let IsConst = _Ty.IsConst; 161 let IsVolatile = _Ty.IsVolatile; 162 let AccessQualifier = _Ty.AccessQualifier; 163 let Extension = _Ty.Extension; 164} 165 166// OpenCL const types (e.g. const int). 167class ConstType<Type _Ty> : Type<_Ty.Name, _Ty.QTExpr> { 168 let IsConst = 1; 169 // Inherited fields 170 let VecWidth = _Ty.VecWidth; 171 let IsPointer = _Ty.IsPointer; 172 let IsVolatile = _Ty.IsVolatile; 173 let AccessQualifier = _Ty.AccessQualifier; 174 let AddrSpace = _Ty.AddrSpace; 175 let Extension = _Ty.Extension; 176} 177 178// OpenCL volatile types (e.g. volatile int). 179class VolatileType<Type _Ty> : Type<_Ty.Name, _Ty.QTExpr> { 180 let IsVolatile = 1; 181 // Inherited fields 182 let VecWidth = _Ty.VecWidth; 183 let IsPointer = _Ty.IsPointer; 184 let IsConst = _Ty.IsConst; 185 let AccessQualifier = _Ty.AccessQualifier; 186 let AddrSpace = _Ty.AddrSpace; 187 let Extension = _Ty.Extension; 188} 189 190// OpenCL image types (e.g. image2d). 191class ImageType<Type _Ty, string _AccessQualifier> : 192 Type<_Ty.Name, QualType<_Ty.QTExpr.TypeExpr # _AccessQualifier # "Ty", 0>> { 193 let VecWidth = 0; 194 let AccessQualifier = _AccessQualifier; 195 // Inherited fields 196 let IsPointer = _Ty.IsPointer; 197 let IsConst = _Ty.IsConst; 198 let IsVolatile = _Ty.IsVolatile; 199 let AddrSpace = _Ty.AddrSpace; 200 let Extension = _Ty.Extension; 201} 202 203// OpenCL enum type (e.g. memory_scope). 204class EnumType<string _Name> : 205 Type<_Name, QualType<"getOpenCLEnumType(S, \"" # _Name # "\")", 0>> { 206} 207 208// OpenCL typedef type (e.g. cl_mem_fence_flags). 209class TypedefType<string _Name> : 210 Type<_Name, QualType<"getOpenCLTypedefType(S, \"" # _Name # "\")", 0>> { 211} 212 213// List of Types. 214class TypeList<list<Type> _Type> { 215 list<Type> List = _Type; 216} 217 218// A GenericType is an abstract type that defines a set of types as a 219// combination of Types and vector sizes. 220// 221// For example, if TypeList = <int, float> and VectorList = <1, 2, 4>, then it 222// represents <int, int2, int4, float, float2, float4>. 223// 224// Some rules apply when using multiple GenericType arguments in a declaration: 225// 1. The number of vector sizes must be equal or 1 for all gentypes in a 226// declaration. 227// 2. The number of Types must be equal or 1 for all gentypes in a 228// declaration. 229// 3. Generic types are combined by iterating over all generic types at once. 230// For example, for the following GenericTypes 231// GenT1 = GenericType<half, [1, 2]> and 232// GenT2 = GenericType<float, int, [1, 2]> 233// A declaration f(GenT1, GenT2) results in the combinations 234// f(half, float), f(half2, float2), f(half, int), f(half2, int2) . 235// 4. "sgentype" from the OpenCL specification is supported by specifying 236// a single vector size. 237// For example, for the following GenericTypes 238// GenT = GenericType<half, int, [1, 2]> and 239// SGenT = GenericType<half, int, [1]> 240// A declaration f(GenT, SGenT) results in the combinations 241// f(half, half), f(half2, half), f(int, int), f(int2, int) . 242class GenericType<string _Ty, TypeList _TypeList, IntList _VectorList> : 243 Type<_Ty, QualType<"null", 1>> { 244 // Possible element types of the generic type. 245 TypeList TypeList = _TypeList; 246 // Possible vector sizes of the types in the TypeList. 247 IntList VectorList = _VectorList; 248 // The VecWidth field is ignored for GenericTypes. Use VectorList instead. 249 let VecWidth = 0; 250} 251 252// Builtin function attributes. 253def Attr { 254 list<bit> None = [0, 0, 0]; 255 list<bit> Pure = [1, 0, 0]; 256 list<bit> Const = [0, 1, 0]; 257 list<bit> Convergent = [0, 0, 1]; 258} 259 260//===----------------------------------------------------------------------===// 261// OpenCL C class for builtin functions 262//===----------------------------------------------------------------------===// 263class Builtin<string _Name, list<Type> _Signature, list<bit> _Attributes = Attr.None> { 264 // Name of the builtin function 265 string Name = _Name; 266 // List of types used by the function. The first one is the return type and 267 // the following are the arguments. The list must have at least one element 268 // (the return type). 269 list<Type> Signature = _Signature; 270 // Function attribute __attribute__((pure)) 271 bit IsPure = _Attributes[0]; 272 // Function attribute __attribute__((const)) 273 bit IsConst = _Attributes[1]; 274 // Function attribute __attribute__((convergent)) 275 bit IsConv = _Attributes[2]; 276 // OpenCL extensions to which the function belongs. 277 FunctionExtension Extension = FuncExtNone; 278 // Version of OpenCL from which the function is available (e.g.: CL10). 279 // MinVersion is inclusive. 280 Version MinVersion = CL10; 281 // Version of OpenCL from which the function is not supported anymore. 282 // MaxVersion is exclusive. 283 // CLAll makes the function available for all versions. 284 Version MaxVersion = CLAll; 285} 286 287//===----------------------------------------------------------------------===// 288// Definitions of OpenCL C types 289//===----------------------------------------------------------------------===// 290 291// OpenCL v1.0/1.2/2.0 s6.1.1: Built-in Scalar Data Types. 292def Bool : Type<"bool", QualType<"Context.BoolTy">>; 293def Char : Type<"char", QualType<"Context.CharTy">>; 294def UChar : Type<"uchar", QualType<"Context.UnsignedCharTy">>; 295def Short : Type<"short", QualType<"Context.ShortTy">>; 296def UShort : Type<"ushort", QualType<"Context.UnsignedShortTy">>; 297def Int : Type<"int", QualType<"Context.IntTy">>; 298def UInt : Type<"uint", QualType<"Context.UnsignedIntTy">>; 299def Long : Type<"long", QualType<"Context.LongTy">>; 300def ULong : Type<"ulong", QualType<"Context.UnsignedLongTy">>; 301def Float : Type<"float", QualType<"Context.FloatTy">>; 302let Extension = Fp64TypeExt in { 303 def Double : Type<"double", QualType<"Context.DoubleTy">>; 304} 305let Extension = Fp16TypeExt in { 306 def Half : Type<"half", QualType<"Context.HalfTy">>; 307} 308def Size : Type<"size_t", QualType<"Context.getSizeType()">>; 309def PtrDiff : Type<"ptrdiff_t", QualType<"Context.getPointerDiffType()">>; 310def IntPtr : Type<"intptr_t", QualType<"Context.getIntPtrType()">>; 311def UIntPtr : Type<"uintptr_t", QualType<"Context.getUIntPtrType()">>; 312def Void : Type<"void", QualType<"Context.VoidTy">>; 313 314// OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types. 315// Built-in vector data types are created by TableGen's OpenCLBuiltinEmitter. 316 317// OpenCL v1.0/1.2/2.0 s6.1.3: Other Built-in Data Types. 318// The image definitions are "abstract". They should not be used without 319// specifying an access qualifier (RO/WO/RW). 320def Image1d : Type<"image1d_t", QualType<"Context.OCLImage1d", 1>>; 321def Image2d : Type<"image2d_t", QualType<"Context.OCLImage2d", 1>>; 322def Image3d : Type<"image3d_t", QualType<"Context.OCLImage3d", 1>>; 323def Image1dArray : Type<"image1d_array_t", QualType<"Context.OCLImage1dArray", 1>>; 324def Image1dBuffer : Type<"image1d_buffer_t", QualType<"Context.OCLImage1dBuffer", 1>>; 325def Image2dArray : Type<"image2d_array_t", QualType<"Context.OCLImage2dArray", 1>>; 326def Image2dDepth : Type<"image2d_depth_t", QualType<"Context.OCLImage2dDepth", 1>>; 327def Image2dArrayDepth : Type<"image2d_array_depth_t", QualType<"Context.OCLImage2dArrayDepth", 1>>; 328def Image2dMsaa : Type<"image2d_msaa_t", QualType<"Context.OCLImage2dMSAA", 1>>; 329def Image2dArrayMsaa : Type<"image2d_array_msaa_t", QualType<"Context.OCLImage2dArrayMSAA", 1>>; 330def Image2dMsaaDepth : Type<"image2d_msaa_depth_t", QualType<"Context.OCLImage2dMSAADepth", 1>>; 331def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"Context.OCLImage2dArrayMSAADepth", 1>>; 332 333def Sampler : Type<"sampler_t", QualType<"Context.OCLSamplerTy">>; 334def ClkEvent : Type<"clk_event_t", QualType<"Context.OCLClkEventTy">>; 335def Event : Type<"event_t", QualType<"Context.OCLEventTy">>; 336def Queue : Type<"queue_t", QualType<"Context.OCLQueueTy">>; 337def ReserveId : Type<"reserve_id_t", QualType<"Context.OCLReserveIDTy">>; 338def MemFenceFlags : TypedefType<"cl_mem_fence_flags">; 339def ClkProfilingInfo : TypedefType<"clk_profiling_info">; 340def NDRange : TypedefType<"ndrange_t">; 341 342// OpenCL v2.0 s6.13.11: Atomic integer and floating-point types. 343def AtomicInt : Type<"atomic_int", QualType<"Context.getAtomicType(Context.IntTy)">>; 344def AtomicUInt : Type<"atomic_uint", QualType<"Context.getAtomicType(Context.UnsignedIntTy)">>; 345def AtomicLong : Type<"atomic_long", QualType<"Context.getAtomicType(Context.LongTy)">>; 346def AtomicULong : Type<"atomic_ulong", QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>; 347def AtomicFloat : Type<"atomic_float", QualType<"Context.getAtomicType(Context.FloatTy)">>; 348def AtomicDouble : Type<"atomic_double", QualType<"Context.getAtomicType(Context.DoubleTy)">>; 349def AtomicIntPtr : Type<"atomic_intptr_t", QualType<"Context.getAtomicType(Context.getIntPtrType())">>; 350def AtomicUIntPtr : Type<"atomic_uintptr_t", QualType<"Context.getAtomicType(Context.getUIntPtrType())">>; 351def AtomicSize : Type<"atomic_size_t", QualType<"Context.getAtomicType(Context.getSizeType())">>; 352def AtomicPtrDiff : Type<"atomic_ptrdiff_t", QualType<"Context.getAtomicType(Context.getPointerDiffType())">>; 353 354def AtomicFlag : TypedefType<"atomic_flag">; 355def MemoryOrder : EnumType<"memory_order">; 356def MemoryScope : EnumType<"memory_scope">; 357 358//===----------------------------------------------------------------------===// 359// Definitions of OpenCL gentype variants 360//===----------------------------------------------------------------------===// 361// The OpenCL specification often uses "gentype" in builtin function 362// declarations to indicate that a builtin function is available with various 363// argument and return types. The types represented by "gentype" vary between 364// different parts of the specification. The following definitions capture 365// the different type lists for gentypes in different parts of the 366// specification. 367 368// Vector width lists. 369def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>; 370def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>; 371def Vec1 : IntList<"Vec1", [1]>; 372def Vec1234 : IntList<"Vec1234", [1, 2, 3, 4]>; 373 374// Type lists. 375def TLAll : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong, Float, Double, Half]>; 376def TLFloat : TypeList<[Float, Double, Half]>; 377def TLSignedInts : TypeList<[Char, Short, Int, Long]>; 378def TLUnsignedInts : TypeList<[UChar, UShort, UInt, ULong]>; 379 380def TLIntLongFloats : TypeList<[Int, UInt, Long, ULong, Float, Double, Half]>; 381 382// All unsigned integer types twice, to facilitate unsigned return types for e.g. 383// uchar abs(char) and 384// uchar abs(uchar). 385def TLAllUIntsTwice : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong]>; 386 387def TLAllInts : TypeList<[Char, UChar, Short, UShort, Int, UInt, Long, ULong]>; 388 389// GenType definitions for multiple base types (e.g. all floating point types, 390// or all integer types). 391// All types 392def AGenType1 : GenericType<"AGenType1", TLAll, Vec1>; 393def AGenTypeN : GenericType<"AGenTypeN", TLAll, VecAndScalar>; 394def AGenTypeNNoScalar : GenericType<"AGenTypeNNoScalar", TLAll, VecNoScalar>; 395// All integer 396def AIGenType1 : GenericType<"AIGenType1", TLAllInts, Vec1>; 397def AIGenTypeN : GenericType<"AIGenTypeN", TLAllInts, VecAndScalar>; 398def AIGenTypeNNoScalar : GenericType<"AIGenTypeNNoScalar", TLAllInts, VecNoScalar>; 399// All integer to unsigned 400def AI2UGenTypeN : GenericType<"AI2UGenTypeN", TLAllUIntsTwice, VecAndScalar>; 401// Signed integer 402def SGenTypeN : GenericType<"SGenTypeN", TLSignedInts, VecAndScalar>; 403// Unsigned integer 404def UGenTypeN : GenericType<"UGenTypeN", TLUnsignedInts, VecAndScalar>; 405// Float 406def FGenTypeN : GenericType<"FGenTypeN", TLFloat, VecAndScalar>; 407// (u)int, (u)long, and all floats 408def IntLongFloatGenType1 : GenericType<"IntLongFloatGenType1", TLIntLongFloats, Vec1>; 409// (u)char and (u)short 410def CharShortGenType1 : GenericType<"CharShortGenType1", 411 TypeList<[Char, UChar, Short, UShort]>, Vec1>; 412 413// GenType definitions for every single base type (e.g. fp32 only). 414// Names are like: GenTypeFloatVecAndScalar. 415foreach Type = [Char, UChar, Short, UShort, 416 Int, UInt, Long, ULong, 417 Float, Double, Half] in { 418 foreach VecSizes = [VecAndScalar, VecNoScalar] in { 419 def "GenType" # Type # VecSizes : 420 GenericType<"GenType" # Type # VecSizes, 421 TypeList<[Type]>, VecSizes>; 422 } 423} 424 425// GenType definitions for vec1234. 426foreach Type = [Float, Double, Half] in { 427 def "GenType" # Type # Vec1234 : 428 GenericType<"GenType" # Type # Vec1234, 429 TypeList<[Type]>, Vec1234>; 430} 431 432 433//===----------------------------------------------------------------------===// 434// Definitions of OpenCL builtin functions 435//===----------------------------------------------------------------------===// 436//-------------------------------------------------------------------- 437// OpenCL v1.1/1.2/2.0 s6.2.3 - Explicit conversions. 438// OpenCL v2.0 Extensions s5.1.1 and s6.1.1 - Conversions. 439 440// Generate the convert_* builtins functions. 441foreach RType = [Float, Double, Half, Char, UChar, Short, 442 UShort, Int, UInt, Long, ULong] in { 443 foreach IType = [Float, Double, Half, Char, UChar, Short, 444 UShort, Int, UInt, Long, ULong] in { 445 // Conversions to integer type have a sat and non-sat variant. 446 foreach sat = !cond(!eq(RType.Name, "float") : [""], 447 !eq(RType.Name, "double") : [""], 448 !eq(RType.Name, "half") : [""], 449 1 : ["", "_sat"]) in { 450 foreach rnd = ["", "_rte", "_rtn", "_rtp", "_rtz"] in { 451 def : Builtin<"convert_" # RType.Name # sat # rnd, [RType, IType], 452 Attr.Const>; 453 foreach v = [2, 3, 4, 8, 16] in { 454 def : Builtin<"convert_" # RType.Name # v # sat # rnd, 455 [VectorType<RType, v>, VectorType<IType, v>], 456 Attr.Const>; 457 } 458 } 459 } 460 } 461} 462 463//-------------------------------------------------------------------- 464// OpenCL v1.1 s6.11.1, v1.2 s6.12.1, v2.0 s6.13.1 - Work-item Functions 465// --- Table 7 --- 466def : Builtin<"get_work_dim", [UInt], Attr.Const>; 467foreach name = ["get_global_size", "get_global_id", "get_local_size", 468 "get_local_id", "get_num_groups", "get_group_id", 469 "get_global_offset"] in { 470 def : Builtin<name, [Size, UInt], Attr.Const>; 471} 472 473let MinVersion = CL20 in { 474 def : Builtin<"get_enqueued_local_size", [Size, UInt]>; 475 foreach name = ["get_global_linear_id", "get_local_linear_id"] in { 476 def : Builtin<name, [Size]>; 477 } 478} 479 480 481//-------------------------------------------------------------------- 482// OpenCL v1.1 s6.11.2, v1.2 s6.12.2, v2.0 s6.13.2 - Math functions 483// OpenCL Extension v2.0 s5.1.2 and s6.1.2 - Math Functions 484// --- Table 8 --- 485// --- 1 argument --- 486foreach name = ["acos", "acosh", "acospi", 487 "asin", "asinh", "asinpi", 488 "atan", "atanh", "atanpi", 489 "cbrt", "ceil", 490 "cos", "cosh", "cospi", 491 "erfc", "erf", 492 "exp", "exp2", "exp10", "expm1", 493 "fabs", "floor", 494 "log", "log2", "log10", "log1p", "logb", 495 "rint", "round", "rsqrt", 496 "sin", "sinh", "sinpi", 497 "sqrt", 498 "tan", "tanh", "tanpi", 499 "tgamma", "trunc", 500 "lgamma"] in { 501 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>; 502} 503foreach name = ["nan"] in { 504 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>; 505 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>; 506 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>; 507} 508 509// --- 2 arguments --- 510foreach name = ["atan2", "atan2pi", "copysign", "fdim", "fmod", "hypot", 511 "maxmag", "minmag", "nextafter", "pow", "powr", 512 "remainder"] in { 513 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 514} 515foreach name = ["fmax", "fmin"] in { 516 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 517 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>; 518 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>; 519 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>; 520} 521foreach name = ["ilogb"] in { 522 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>; 523 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeDoubleVecAndScalar], Attr.Const>; 524 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeHalfVecAndScalar], Attr.Const>; 525} 526foreach name = ["ldexp"] in { 527 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 528 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Int], Attr.Const>; 529 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 530 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Int], Attr.Const>; 531 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 532 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Int], Attr.Const>; 533} 534foreach name = ["pown", "rootn"] in { 535 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 536 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 537 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 538} 539 540// --- 3 arguments --- 541foreach name = ["fma", "mad"] in { 542 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 543} 544 545// --- Version dependent --- 546let MaxVersion = CL20 in { 547 foreach AS = [GlobalAS, LocalAS, PrivateAS] in { 548 foreach name = ["fract", "modf", "sincos"] in { 549 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>; 550 } 551 foreach name = ["frexp", "lgamma_r"] in { 552 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { 553 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>; 554 } 555 } 556 foreach name = ["remquo"] in { 557 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { 558 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>; 559 } 560 } 561 } 562} 563let MinVersion = CL20 in { 564 foreach name = ["fract", "modf", "sincos"] in { 565 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>; 566 } 567 foreach name = ["frexp", "lgamma_r"] in { 568 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { 569 def : Builtin<name, [Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>; 570 } } 571 foreach name = ["remquo"] in { 572 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { 573 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, GenericAS>]>; 574 } 575 } 576} 577 578// --- Table 9 --- 579foreach name = ["half_cos", 580 "half_exp", "half_exp2", "half_exp10", 581 "half_log", "half_log2", "half_log10", 582 "half_recip", "half_rsqrt", 583 "half_sin", "half_sqrt", "half_tan", 584 "native_cos", 585 "native_exp", "native_exp2", "native_exp10", 586 "native_log", "native_log2", "native_log10", 587 "native_recip", "native_rsqrt", 588 "native_sin", "native_sqrt", "native_tan"] in { 589 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>; 590} 591foreach name = ["half_divide", "half_powr", 592 "native_divide", "native_powr"] in { 593 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>; 594} 595 596//-------------------------------------------------------------------- 597// OpenCL v1.1 s6.11.3, v1.2 s6.12.3, v2.0 s6.13.3 - Integer Functions 598// --- Table 10 --- 599// --- 1 argument --- 600foreach name = ["abs"] in { 601 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN], Attr.Const>; 602} 603def : Builtin<"clz", [AIGenTypeN, AIGenTypeN], Attr.Const>; 604let MinVersion = CL12 in { 605 def : Builtin<"popcount", [AIGenTypeN, AIGenTypeN], Attr.Const>; 606} 607let MinVersion = CL20 in { 608 foreach name = ["ctz"] in { 609 def : Builtin<name, [AIGenTypeN, AIGenTypeN]>; 610 } 611} 612 613// --- 2 arguments --- 614foreach name = ["abs_diff"] in { 615 def : Builtin<name, [AI2UGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>; 616} 617foreach name = ["add_sat", "hadd", "rhadd", "mul_hi", "rotate", "sub_sat"] in { 618 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>; 619} 620foreach name = ["max", "min"] in { 621 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>; 622 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1], Attr.Const>; 623} 624foreach name = ["upsample"] in { 625 def : Builtin<name, [GenTypeShortVecAndScalar, GenTypeCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>; 626 def : Builtin<name, [GenTypeUShortVecAndScalar, GenTypeUCharVecAndScalar, GenTypeUCharVecAndScalar], Attr.Const>; 627 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>; 628 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUShortVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>; 629 def : Builtin<name, [GenTypeLongVecAndScalar, GenTypeIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>; 630 def : Builtin<name, [GenTypeULongVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>; 631} 632 633// --- 3 arguments --- 634foreach name = ["clamp"] in { 635 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>; 636 def : Builtin<name, [AIGenTypeNNoScalar, AIGenTypeNNoScalar, AIGenType1, AIGenType1], Attr.Const>; 637} 638foreach name = ["mad_hi", "mad_sat"] in { 639 def : Builtin<name, [AIGenTypeN, AIGenTypeN, AIGenTypeN, AIGenTypeN], Attr.Const>; 640} 641 642// --- Table 11 --- 643foreach name = ["mad24"] in { 644 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 645 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>; 646} 647foreach name = ["mul24"] in { 648 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeIntVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 649 def : Builtin<name, [GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>; 650} 651 652//-------------------------------------------------------------------- 653// OpenCL v1.1 s6.11.4, v1.2 s6.12.4, v2.0 s6.13.4 - Common Functions 654// OpenCL Extension v2.0 s5.1.3 and s6.1.3 - Common Functions 655// --- Table 12 --- 656// --- 1 argument --- 657foreach name = ["degrees", "radians", "sign"] in { 658 def : Builtin<name, [FGenTypeN, FGenTypeN], Attr.Const>; 659} 660 661// --- 2 arguments --- 662foreach name = ["max", "min"] in { 663 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 664 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>; 665 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>; 666 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>; 667} 668foreach name = ["step"] in { 669 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 670 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, GenTypeFloatVecNoScalar], Attr.Const>; 671 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, GenTypeDoubleVecNoScalar], Attr.Const>; 672 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, GenTypeHalfVecNoScalar], Attr.Const>; 673} 674 675// --- 3 arguments --- 676foreach name = ["clamp"] in { 677 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 678 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float, Float], Attr.Const>; 679 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double, Double], Attr.Const>; 680 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half, Half], Attr.Const>; 681} 682foreach name = ["mix"] in { 683 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 684 def : Builtin<name, [GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, GenTypeFloatVecNoScalar, Float], Attr.Const>; 685 def : Builtin<name, [GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar, Double], Attr.Const>; 686 def : Builtin<name, [GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar, Half], Attr.Const>; 687} 688foreach name = ["smoothstep"] in { 689 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 690 def : Builtin<name, [GenTypeFloatVecNoScalar, Float, Float, GenTypeFloatVecNoScalar], Attr.Const>; 691 def : Builtin<name, [GenTypeDoubleVecNoScalar, Double, Double, GenTypeDoubleVecNoScalar], Attr.Const>; 692 def : Builtin<name, [GenTypeHalfVecNoScalar, Half, Half, GenTypeHalfVecNoScalar], Attr.Const>; 693} 694 695 696//-------------------------------------------------------------------- 697// OpenCL v1.1 s6.11.5, v1.2 s6.12.5, v2.0 s6.13.5 - Geometric Functions 698// OpenCL Extension v2.0 s5.1.4 and s6.1.4 - Geometric Functions 699// --- Table 13 --- 700// --- 1 argument --- 701foreach name = ["length"] in { 702 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>; 703 def : Builtin<name, [Double, GenTypeDoubleVec1234], Attr.Const>; 704 def : Builtin<name, [Half, GenTypeHalfVec1234], Attr.Const>; 705} 706foreach name = ["normalize"] in { 707 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>; 708 def : Builtin<name, [GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>; 709 def : Builtin<name, [GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>; 710} 711foreach name = ["fast_length"] in { 712 def : Builtin<name, [Float, GenTypeFloatVec1234], Attr.Const>; 713} 714foreach name = ["fast_normalize"] in { 715 def : Builtin<name, [GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>; 716} 717 718// --- 2 arguments --- 719foreach name = ["cross"] in { 720 foreach VSize = [3, 4] in { 721 def : Builtin<name, [VectorType<Float, VSize>, VectorType<Float, VSize>, VectorType<Float, VSize>], Attr.Const>; 722 def : Builtin<name, [VectorType<Double, VSize>, VectorType<Double, VSize>, VectorType<Double, VSize>], Attr.Const>; 723 def : Builtin<name, [VectorType<Half, VSize>, VectorType<Half, VSize>, VectorType<Half, VSize>], Attr.Const>; 724 } 725} 726foreach name = ["dot", "distance"] in { 727 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>; 728 def : Builtin<name, [Double, GenTypeDoubleVec1234, GenTypeDoubleVec1234], Attr.Const>; 729 def : Builtin<name, [Half, GenTypeHalfVec1234, GenTypeHalfVec1234], Attr.Const>; 730} 731foreach name = ["fast_distance"] in { 732 def : Builtin<name, [Float, GenTypeFloatVec1234, GenTypeFloatVec1234], Attr.Const>; 733} 734 735 736//-------------------------------------------------------------------- 737// OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions 738// OpenCL Extension v2.0 s5.1.5 and s6.1.5 - Relational Functions 739// --- Table 14 --- 740// --- 1 argument --- 741foreach name = ["isfinite", "isinf", "isnan", "isnormal", "signbit"] in { 742 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>; 743 def : Builtin<name, [Int, Double], Attr.Const>; 744 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>; 745 def : Builtin<name, [Int, Half], Attr.Const>; 746 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>; 747} 748foreach name = ["any", "all"] in { 749 def : Builtin<name, [Int, SGenTypeN], Attr.Const>; 750} 751 752// --- 2 arguments --- 753foreach name = ["isequal", "isnotequal", "isgreater", "isgreaterequal", 754 "isless", "islessequal", "islessgreater", "isordered", 755 "isunordered"] in { 756 def : Builtin<name, [GenTypeIntVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar], Attr.Const>; 757 def : Builtin<name, [Int, Double, Double], Attr.Const>; 758 def : Builtin<name, [GenTypeLongVecNoScalar, GenTypeDoubleVecNoScalar, GenTypeDoubleVecNoScalar], Attr.Const>; 759 def : Builtin<name, [Int, Half, Half], Attr.Const>; 760 def : Builtin<name, [GenTypeShortVecNoScalar, GenTypeHalfVecNoScalar, GenTypeHalfVecNoScalar], Attr.Const>; 761} 762 763// --- 3 arguments --- 764foreach name = ["bitselect"] in { 765 def : Builtin<name, [AGenTypeN, AGenTypeN, AGenTypeN, AGenTypeN], Attr.Const>; 766} 767foreach name = ["select"] in { 768 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, SGenTypeN], Attr.Const>; 769 def : Builtin<name, [SGenTypeN, SGenTypeN, SGenTypeN, UGenTypeN], Attr.Const>; 770 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, UGenTypeN], Attr.Const>; 771 def : Builtin<name, [UGenTypeN, UGenTypeN, UGenTypeN, SGenTypeN], Attr.Const>; 772 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeIntVecAndScalar], Attr.Const>; 773 def : Builtin<name, [GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeFloatVecAndScalar, GenTypeUIntVecAndScalar], Attr.Const>; 774 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeLongVecAndScalar], Attr.Const>; 775 def : Builtin<name, [GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeULongVecAndScalar], Attr.Const>; 776 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeShortVecAndScalar], Attr.Const>; 777 def : Builtin<name, [GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeHalfVecAndScalar, GenTypeUShortVecAndScalar], Attr.Const>; 778} 779 780 781//-------------------------------------------------------------------- 782// OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions 783// OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s5.1.6 and s6.1.6 - Vector Data Load and Store Functions 784// --- Table 15 --- 785// Variants for OpenCL versions below 2.0, using pointers to the global, local 786// and private address spaces. 787let MaxVersion = CL20 in { 788 foreach AS = [GlobalAS, LocalAS, PrivateAS] in { 789 foreach VSize = [2, 3, 4, 8, 16] in { 790 foreach name = ["vload" # VSize] in { 791 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>; 792 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>; 793 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>; 794 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>; 795 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>; 796 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>; 797 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>; 798 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>; 799 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>; 800 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>; 801 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 802 } 803 foreach name = ["vstore" # VSize] in { 804 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>; 805 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>; 806 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>; 807 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>; 808 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>; 809 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>; 810 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>; 811 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>; 812 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>; 813 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>; 814 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>; 815 } 816 foreach name = ["vloada_half" # VSize] in { 817 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 818 } 819 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { 820 foreach name = ["vstorea_half" # VSize # rnd] in { 821 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>; 822 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>; 823 } 824 } 825 } 826 } 827} 828// Variants for OpenCL versions above 2.0, using pointers to the generic 829// address space. 830let MinVersion = CL20 in { 831 foreach VSize = [2, 3, 4, 8, 16] in { 832 foreach name = ["vload" # VSize] in { 833 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, GenericAS>]>; 834 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, GenericAS>]>; 835 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, GenericAS>]>; 836 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, GenericAS>]>; 837 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, GenericAS>]>; 838 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, GenericAS>]>; 839 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, GenericAS>]>; 840 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, GenericAS>]>; 841 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, GenericAS>]>; 842 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, GenericAS>]>; 843 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>; 844 } 845 foreach name = ["vstore" # VSize] in { 846 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, GenericAS>]>; 847 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, GenericAS>]>; 848 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, GenericAS>]>; 849 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, GenericAS>]>; 850 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, GenericAS>]>; 851 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, GenericAS>]>; 852 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, GenericAS>]>; 853 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, GenericAS>]>; 854 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, GenericAS>]>; 855 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, GenericAS>]>; 856 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, GenericAS>]>; 857 } 858 foreach name = ["vloada_half" # VSize] in { 859 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, GenericAS>]>; 860 } 861 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { 862 foreach name = ["vstorea_half" # VSize # rnd] in { 863 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, GenericAS>]>; 864 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, GenericAS>]>; 865 } 866 } 867 } 868} 869// Variants using pointers to the constant address space. 870foreach VSize = [2, 3, 4, 8, 16] in { 871 foreach name = ["vload" # VSize] in { 872 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, ConstantAS>]>; 873 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, ConstantAS>]>; 874 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, ConstantAS>]>; 875 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, ConstantAS>]>; 876 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, ConstantAS>]>; 877 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, ConstantAS>]>; 878 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, ConstantAS>]>; 879 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, ConstantAS>]>; 880 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, ConstantAS>]>; 881 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, ConstantAS>]>; 882 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>; 883 } 884 foreach name = ["vloada_half" # VSize] in { 885 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, ConstantAS>]>; 886 } 887} 888let MaxVersion = CL20 in { 889 foreach AS = [GlobalAS, LocalAS, PrivateAS] in { 890 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 891 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 892 foreach VSize = [2, 3, 4, 8, 16] in { 893 foreach name = ["vload_half" # VSize] in { 894 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 895 } 896 } 897 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { 898 foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in { 899 def : Builtin<name, [Void, Float, Size, PointerType<Half, AS>]>; 900 def : Builtin<name, [Void, Double, Size, PointerType<Half, AS>]>; 901 } 902 foreach VSize = [2, 3, 4, 8, 16] in { 903 foreach name = ["vstore_half" # VSize # rnd] in { 904 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>; 905 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>; 906 } 907 } 908 } 909 } 910} 911let MinVersion = CL20 in { 912 foreach AS = [GenericAS] in { 913 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 914 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 915 foreach VSize = [2, 3, 4, 8, 16] in { 916 foreach name = ["vload_half" # VSize] in { 917 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 918 } 919 } 920 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { 921 foreach name = ["vstore_half" # rnd, "vstorea_half" # rnd] in { 922 def : Builtin<name, [Void, Float, Size, PointerType<Half, AS>]>; 923 def : Builtin<name, [Void, Double, Size, PointerType<Half, AS>]>; 924 } 925 foreach VSize = [2, 3, 4, 8, 16] in { 926 foreach name = ["vstore_half" # VSize # rnd] in { 927 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>; 928 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>; 929 } 930 } 931 } 932 } 933} 934 935foreach AS = [ConstantAS] in { 936 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 937 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 938 foreach VSize = [2, 3, 4, 8, 16] in { 939 foreach name = ["vload_half" # VSize] in { 940 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 941 } 942 } 943} 944 945// OpenCL v3.0 s6.15.8 - Synchronization Functions. 946def : Builtin<"barrier", [Void, MemFenceFlags], Attr.Convergent>; 947let MinVersion = CL20 in { 948 def : Builtin<"work_group_barrier", [Void, MemFenceFlags], Attr.Convergent>; 949 def : Builtin<"work_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>; 950} 951 952// OpenCL v3.0 s6.15.9 - Legacy Explicit Memory Fence Functions. 953def : Builtin<"mem_fence", [Void, MemFenceFlags]>; 954def : Builtin<"read_mem_fence", [Void, MemFenceFlags]>; 955def : Builtin<"write_mem_fence", [Void, MemFenceFlags]>; 956 957// OpenCL v3.0 s6.15.10 - Address Space Qualifier Functions. 958// to_global, to_local, to_private are declared in Builtins.def. 959 960let MinVersion = CL20 in { 961 // The OpenCL 3.0 specification defines these with a "gentype" argument indicating any builtin 962 // type or user-defined type, which cannot be represented currently. Hence we slightly diverge 963 // by providing only the following overloads with a void pointer. 964 def : Builtin<"get_fence", [MemFenceFlags, PointerType<Void, GenericAS>]>; 965 def : Builtin<"get_fence", [MemFenceFlags, PointerType<ConstType<Void>, GenericAS>]>; 966} 967 968//-------------------------------------------------------------------- 969// 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 970// OpenCL Extension v2.0 s5.1.7 and s6.1.7: Async Copies from Global to Local Memory, Local to Global Memory, and Prefetch 971// --- Table 18 --- 972foreach name = ["async_work_group_copy"] in { 973 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Event]>; 974 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Event]>; 975} 976foreach name = ["async_work_group_strided_copy"] in { 977 def : Builtin<name, [Event, PointerType<AGenTypeN, LocalAS>, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size, Size, Event]>; 978 def : Builtin<name, [Event, PointerType<AGenTypeN, GlobalAS>, PointerType<ConstType<AGenTypeN>, LocalAS>, Size, Size, Event]>; 979} 980foreach name = ["wait_group_events"] in { 981 def : Builtin<name, [Void, Int, PointerType<Event, GenericAS>]>; 982} 983foreach name = ["prefetch"] in { 984 def : Builtin<name, [Void, PointerType<ConstType<AGenTypeN>, GlobalAS>, Size]>; 985} 986 987//-------------------------------------------------------------------- 988// OpenCL v2.0 s6.13.11 - Atomics Functions. 989// Functions that use memory_order and cl_mem_fence_flags enums are not 990// declared here as the TableGen backend does not handle enums. 991 992// OpenCL v1.0 s9.5, s9.6, s9.7 - Atomic Functions for 32-bit integers 993// --- Table 9.1 --- 994let Extension = FuncExtKhrGlobalInt32BaseAtomics in { 995 foreach Type = [Int, UInt] in { 996 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in { 997 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>; 998 } 999 foreach name = ["atom_inc", "atom_dec"] in { 1000 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>]>; 1001 } 1002 foreach name = ["atom_cmpxchg"] in { 1003 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type, Type]>; 1004 } 1005 } 1006} 1007// --- Table 9.3 --- 1008let Extension = FuncExtKhrLocalInt32BaseAtomics in { 1009 foreach Type = [Int, UInt] in { 1010 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in { 1011 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>; 1012 } 1013 foreach name = ["atom_inc", "atom_dec"] in { 1014 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>; 1015 } 1016 foreach name = ["atom_cmpxchg"] in { 1017 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>; 1018 } 1019 } 1020} 1021// --- Table 9.5 --- 1022let Extension = FuncExtKhrInt64BaseAtomics in { 1023 foreach AS = [GlobalAS, LocalAS] in { 1024 foreach Type = [Long, ULong] in { 1025 foreach name = ["atom_add", "atom_sub", "atom_xchg"] in { 1026 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>; 1027 } 1028 foreach name = ["atom_inc", "atom_dec"] in { 1029 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>; 1030 } 1031 foreach name = ["atom_cmpxchg"] in { 1032 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>; 1033 } 1034 } 1035 } 1036} 1037// --- Table 9.2 --- 1038let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in { 1039 foreach Type = [Int, UInt] in { 1040 foreach name = ["atom_min", "atom_max", "atom_and", 1041 "atom_or", "atom_xor"] in { 1042 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>; 1043 } 1044 } 1045} 1046// --- Table 9.4 --- 1047let Extension = FuncExtKhrLocalInt32ExtendedAtomics in { 1048 foreach Type = [Int, UInt] in { 1049 foreach name = ["atom_min", "atom_max", "atom_and", 1050 "atom_or", "atom_xor"] in { 1051 def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>; 1052 } 1053 } 1054} 1055// --- Table 9.6 --- 1056let Extension = FuncExtKhrInt64ExtendedAtomics in { 1057 foreach AS = [GlobalAS, LocalAS] in { 1058 foreach Type = [Long, ULong] in { 1059 foreach name = ["atom_min", "atom_max", "atom_and", 1060 "atom_or", "atom_xor"] in { 1061 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>; 1062 } 1063 } 1064 } 1065} 1066// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions 1067foreach AS = [GlobalAS, LocalAS] in { 1068 def : Builtin<"atomic_xchg", [Float, PointerType<VolatileType<Float>, AS>, Float]>; 1069 foreach Type = [Int, UInt] in { 1070 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg", 1071 "atomic_min", "atomic_max", "atomic_and", 1072 "atomic_or", "atomic_xor"] in { 1073 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>; 1074 } 1075 foreach name = ["atomic_inc", "atomic_dec"] in { 1076 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>; 1077 } 1078 foreach name = ["atomic_cmpxchg"] in { 1079 def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>; 1080 } 1081 } 1082} 1083 1084let Extension = FuncExtOpenCLCxx in { 1085 foreach Type = [Int, UInt] in { 1086 foreach name = ["atomic_add", "atomic_sub", "atomic_xchg", 1087 "atomic_min", "atomic_max", "atomic_and", 1088 "atomic_or", "atomic_xor"] in { 1089 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type]>; 1090 } 1091 foreach name = ["atomic_inc", "atomic_dec"] in { 1092 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>]>; 1093 } 1094 foreach name = ["atomic_cmpxchg"] in { 1095 def : Builtin<name, [Type, PointerType<VolatileType<Type>, GenericAS>, Type, Type]>; 1096 } 1097 } 1098} 1099 1100// OpenCL v2.0 s6.13.11 - Atomic Functions. 1101let MinVersion = CL20 in { 1102 def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>; 1103 1104 foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt], 1105 [AtomicLong, Long], [AtomicULong, ULong], 1106 [AtomicFloat, Float], [AtomicDouble, Double]] in { 1107 def : Builtin<"atomic_init", 1108 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; 1109 def : Builtin<"atomic_store", 1110 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; 1111 def : Builtin<"atomic_store_explicit", 1112 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1], MemoryOrder]>; 1113 def : Builtin<"atomic_store_explicit", 1114 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1], MemoryOrder, MemoryScope]>; 1115 def : Builtin<"atomic_load", 1116 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>]>; 1117 def : Builtin<"atomic_load_explicit", 1118 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, MemoryOrder]>; 1119 def : Builtin<"atomic_load_explicit", 1120 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, MemoryOrder, MemoryScope]>; 1121 def : Builtin<"atomic_exchange", 1122 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; 1123 def : Builtin<"atomic_exchange_explicit", 1124 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1], MemoryOrder]>; 1125 def : Builtin<"atomic_exchange_explicit", 1126 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1], MemoryOrder, MemoryScope]>; 1127 foreach Variant = ["weak", "strong"] in { 1128 def : Builtin<"atomic_compare_exchange_" # Variant, 1129 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, 1130 PointerType<TypePair[1], GenericAS>, TypePair[1]]>; 1131 def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit", 1132 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, 1133 PointerType<TypePair[1], GenericAS>, TypePair[1], MemoryOrder, MemoryOrder]>; 1134 def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit", 1135 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, 1136 PointerType<TypePair[1], GenericAS>, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>; 1137 } 1138 } 1139 1140 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], 1141 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong], 1142 [AtomicUIntPtr, UIntPtr, PtrDiff]] in { 1143 foreach ModOp = ["add", "sub"] in { 1144 def : Builtin<"atomic_fetch_" # ModOp, 1145 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>; 1146 def : Builtin<"atomic_fetch_" # ModOp # "_explicit", 1147 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2], MemoryOrder]>; 1148 def : Builtin<"atomic_fetch_" # ModOp # "_explicit", 1149 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2], MemoryOrder, MemoryScope]>; 1150 } 1151 } 1152 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], 1153 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] in { 1154 foreach ModOp = ["or", "xor", "and", "min", "max"] in { 1155 def : Builtin<"atomic_fetch_" # ModOp, 1156 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>; 1157 def : Builtin<"atomic_fetch_" # ModOp # "_explicit", 1158 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2], MemoryOrder]>; 1159 def : Builtin<"atomic_fetch_" # ModOp # "_explicit", 1160 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2], MemoryOrder, MemoryScope]>; 1161 } 1162 } 1163 1164 def : Builtin<"atomic_flag_clear", 1165 [Void, PointerType<VolatileType<AtomicFlag>, GenericAS>]>; 1166 def : Builtin<"atomic_flag_clear_explicit", 1167 [Void, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder]>; 1168 def : Builtin<"atomic_flag_clear_explicit", 1169 [Void, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder, MemoryScope]>; 1170 1171 def : Builtin<"atomic_flag_test_and_set", 1172 [Bool, PointerType<VolatileType<AtomicFlag>, GenericAS>]>; 1173 def : Builtin<"atomic_flag_test_and_set_explicit", 1174 [Bool, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder]>; 1175 def : Builtin<"atomic_flag_test_and_set_explicit", 1176 [Bool, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder, MemoryScope]>; 1177} 1178 1179//-------------------------------------------------------------------- 1180// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions 1181// --- Table 19 --- 1182foreach VSize1 = [2, 4, 8, 16] in { 1183 foreach VSize2 = [2, 4, 8, 16] in { 1184 foreach VecAndMaskType = [[Char, UChar], [UChar, UChar], 1185 [Short, UShort], [UShort, UShort], 1186 [Int, UInt], [UInt, UInt], 1187 [Long, ULong], [ULong, ULong], 1188 [Float, UInt], [Double, ULong], [Half, UShort]] in { 1189 def : Builtin<"shuffle", [VectorType<VecAndMaskType[0], VSize1>, 1190 VectorType<VecAndMaskType[0], VSize2>, 1191 VectorType<VecAndMaskType[1], VSize1>], 1192 Attr.Const>; 1193 } 1194 } 1195} 1196foreach VSize1 = [2, 4, 8, 16] in { 1197 foreach VSize2 = [2, 4, 8, 16] in { 1198 foreach VecAndMaskType = [[Char, UChar], [UChar, UChar], 1199 [Short, UShort], [UShort, UShort], 1200 [Int, UInt], [UInt, UInt], 1201 [Long, ULong], [ULong, ULong], 1202 [Float, UInt], [Double, ULong], [Half, UShort]] in { 1203 def : Builtin<"shuffle2", [VectorType<VecAndMaskType[0], VSize1>, 1204 VectorType<VecAndMaskType[0], VSize2>, 1205 VectorType<VecAndMaskType[0], VSize2>, 1206 VectorType<VecAndMaskType[1], VSize1>], 1207 Attr.Const>; 1208 } 1209 } 1210} 1211 1212//-------------------------------------------------------------------- 1213// OpenCL v1.1 s6.11.3, v1.2 s6.12.14, v2.0 s6.13.14: Image Read and Write Functions 1214// OpenCL Extension v2.0 s5.1.8 and s6.1.8: Image Read and Write Functions 1215// --- Table 22: Image Read Functions with Samplers --- 1216foreach imgTy = [Image1d] in { 1217 foreach coordTy = [Int, Float] in { 1218 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>; 1219 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>; 1220 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, coordTy], Attr.Pure>; 1221 } 1222} 1223foreach imgTy = [Image2d, Image1dArray] in { 1224 foreach coordTy = [Int, Float] in { 1225 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; 1226 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; 1227 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; 1228 } 1229} 1230foreach imgTy = [Image3d, Image2dArray] in { 1231 foreach coordTy = [Int, Float] in { 1232 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; 1233 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; 1234 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; 1235 } 1236} 1237foreach coordTy = [Int, Float] in { 1238 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; 1239 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>; 1240} 1241 1242// --- Table 23: Sampler-less Read Functions --- 1243let MinVersion = CL12 in { 1244 foreach aQual = ["RO", "RW"] in { 1245 foreach imgTy = [Image2d, Image1dArray] in { 1246 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; 1247 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; 1248 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; 1249 } 1250 foreach imgTy = [Image3d, Image2dArray] in { 1251 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; 1252 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; 1253 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; 1254 } 1255 foreach imgTy = [Image1d, Image1dBuffer] in { 1256 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; 1257 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; 1258 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; 1259 } 1260 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>; 1261 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>; 1262 } 1263} 1264 1265// --- Table 24: Image Write Functions --- 1266foreach aQual = ["WO", "RW"] in { 1267 foreach imgTy = [Image2d] in { 1268 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>; 1269 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>; 1270 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>; 1271 } 1272 foreach imgTy = [Image2dArray] in { 1273 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>; 1274 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>; 1275 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>; 1276 } 1277 foreach imgTy = [Image1d, Image1dBuffer] in { 1278 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, VectorType<Float, 4>]>; 1279 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, VectorType<Int, 4>]>; 1280 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, VectorType<UInt, 4>]>; 1281 } 1282 foreach imgTy = [Image1dArray] in { 1283 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>; 1284 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Int, 4>]>; 1285 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>; 1286 } 1287 foreach imgTy = [Image3d] in { 1288 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Float, 4>]>; 1289 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<Int, 4>]>; 1290 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, VectorType<UInt, 4>]>; 1291 } 1292 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>; 1293 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>; 1294} 1295 1296// --- Table 25: Image Query Functions --- 1297foreach aQual = ["RO", "WO", "RW"] in { 1298 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d, 1299 Image1dArray, Image2dArray, Image2dDepth, 1300 Image2dArrayDepth] in { 1301 foreach name = ["get_image_width", "get_image_channel_data_type", 1302 "get_image_channel_order"] in { 1303 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>; 1304 } 1305 } 1306 foreach imgTy = [Image2d, Image3d, Image2dArray, Image2dDepth, 1307 Image2dArrayDepth] in { 1308 def : Builtin<"get_image_height", [Int, ImageType<imgTy, aQual>], Attr.Const>; 1309 } 1310 def : Builtin<"get_image_depth", [Int, ImageType<Image3d, aQual>], Attr.Const>; 1311 foreach imgTy = [Image2d, Image2dArray, Image2dDepth, 1312 Image2dArrayDepth] in { 1313 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>; 1314 } 1315 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>], Attr.Const>; 1316 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in { 1317 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>; 1318 } 1319} 1320 1321// OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions 1322// --- Table 8 --- 1323foreach aQual = ["RO"] in { 1324 foreach name = ["read_imageh"] in { 1325 foreach coordTy = [Int, Float] in { 1326 foreach imgTy = [Image2d, Image1dArray] in { 1327 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 2>], Attr.Pure>; 1328 } 1329 foreach imgTy = [Image3d, Image2dArray] in { 1330 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<coordTy, 4>], Attr.Pure>; 1331 } 1332 foreach imgTy = [Image1d] in { 1333 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Sampler, coordTy], Attr.Pure>; 1334 } 1335 } 1336 } 1337} 1338// OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions 1339// --- Table 9 --- 1340let MinVersion = CL12 in { 1341 foreach aQual = ["RO", "RW"] in { 1342 foreach name = ["read_imageh"] in { 1343 foreach imgTy = [Image2d, Image1dArray] in { 1344 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; 1345 } 1346 foreach imgTy = [Image3d, Image2dArray] in { 1347 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>; 1348 } 1349 foreach imgTy = [Image1d, Image1dBuffer] in { 1350 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; 1351 } 1352 } 1353 } 1354} 1355// OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions 1356// --- Table 10 --- 1357foreach aQual = ["WO", "RW"] in { 1358 foreach name = ["write_imageh"] in { 1359 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>; 1360 def : Builtin<name, [Void, ImageType<Image2dArray, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>; 1361 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>; 1362 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>; 1363 def : Builtin<name, [Void, ImageType<Image1dArray, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>; 1364 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>; 1365 } 1366} 1367 1368 1369//-------------------------------------------------------------------- 1370// OpenCL v2.0 s6.13.15 - Work-group Functions 1371// --- Table 26 --- 1372let MinVersion = CL20 in { 1373 foreach name = ["work_group_all", "work_group_any"] in { 1374 def : Builtin<name, [Int, Int], Attr.Convergent>; 1375 } 1376 foreach name = ["work_group_broadcast"] in { 1377 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>; 1378 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size], Attr.Convergent>; 1379 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size, Size, Size], Attr.Convergent>; 1380 } 1381 foreach op = ["add", "min", "max"] in { 1382 foreach name = ["work_group_reduce_", "work_group_scan_exclusive_", 1383 "work_group_scan_inclusive_"] in { 1384 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>; 1385 } 1386 } 1387} 1388 1389 1390//-------------------------------------------------------------------- 1391// OpenCL2.0 : 6.13.16 : Pipe Functions 1392// --- Table 27 --- 1393// Defined in Builtins.def 1394 1395// --- Table 28 --- 1396// Builtins taking pipe arguments are defined in Builtins.def 1397def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>; 1398 1399// --- Table 29 --- 1400// Defined in Builtins.def 1401 1402 1403//-------------------------------------------------------------------- 1404// OpenCL2.0 : 6.13.17 : Enqueuing Kernels 1405// --- Table 30 --- 1406// Defined in Builtins.def 1407 1408// --- Table 32 --- 1409// Defined in Builtins.def 1410 1411// --- Table 33 --- 1412let MinVersion = CL20 in { 1413 def : Builtin<"enqueue_marker", 1414 [Int, Queue, UInt, PointerType<ConstType<ClkEvent>, GenericAS>, PointerType<ClkEvent, GenericAS>]>; 1415 1416 // --- Table 34 --- 1417 def : Builtin<"retain_event", [Void, ClkEvent]>; 1418 def : Builtin<"release_event", [Void, ClkEvent]>; 1419 def : Builtin<"create_user_event", [ClkEvent]>; 1420 def : Builtin<"is_valid_event", [Bool, ClkEvent]>; 1421 def : Builtin<"set_user_event_status", [Void, ClkEvent, Int]>; 1422 def : Builtin<"capture_event_profiling_info", 1423 [Void, ClkEvent, ClkProfilingInfo, PointerType<Void, GlobalAS>]>; 1424 1425 // --- Table 35 --- 1426 def : Builtin<"get_default_queue", [Queue]>; 1427 1428 def : Builtin<"ndrange_1D", [NDRange, Size]>; 1429 def : Builtin<"ndrange_1D", [NDRange, Size, Size]>; 1430 def : Builtin<"ndrange_1D", [NDRange, Size, Size, Size]>; 1431 def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>]>; 1432 def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>, 1433 PointerType<ConstType<Size>, PrivateAS>]>; 1434 def : Builtin<"ndrange_2D", [NDRange, PointerType<ConstType<Size>, PrivateAS>, 1435 PointerType<ConstType<Size>, PrivateAS>, 1436 PointerType<ConstType<Size>, PrivateAS>]>; 1437 def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>]>; 1438 def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>, 1439 PointerType<ConstType<Size>, PrivateAS>]>; 1440 def : Builtin<"ndrange_3D", [NDRange, PointerType<ConstType<Size>, PrivateAS>, 1441 PointerType<ConstType<Size>, PrivateAS>, 1442 PointerType<ConstType<Size>, PrivateAS>]>; 1443} 1444 1445 1446//-------------------------------------------------------------------- 1447// End of the builtin functions defined in the OpenCL C specification. 1448// Builtin functions defined in the OpenCL C Extension are below. 1449//-------------------------------------------------------------------- 1450 1451 1452// OpenCL Extension v2.0 s9.18 - Mipmaps 1453let Extension = FuncExtKhrMipmapImage in { 1454 // Added to section 6.13.14.2. 1455 foreach aQual = ["RO"] in { 1456 foreach imgTy = [Image2d] in { 1457 foreach name = ["read_imagef"] in { 1458 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1459 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1460 } 1461 foreach name = ["read_imagei"] in { 1462 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1463 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1464 } 1465 foreach name = ["read_imageui"] in { 1466 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1467 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1468 } 1469 } 1470 foreach imgTy = [Image2dDepth] in { 1471 foreach name = ["read_imagef"] in { 1472 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1473 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1474 } 1475 } 1476 foreach imgTy = [Image1d] in { 1477 foreach name = ["read_imagef"] in { 1478 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>; 1479 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>; 1480 } 1481 foreach name = ["read_imagei"] in { 1482 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>; 1483 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>; 1484 } 1485 foreach name = ["read_imageui"] in { 1486 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float], Attr.Pure>; 1487 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, Float, Float, Float], Attr.Pure>; 1488 } 1489 } 1490 foreach imgTy = [Image3d] in { 1491 foreach name = ["read_imagef"] in { 1492 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>; 1493 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1494 } 1495 foreach name = ["read_imagei"] in { 1496 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>; 1497 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1498 } 1499 foreach name = ["read_imageui"] in { 1500 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 4>, VectorType<Float, 4>], Attr.Pure>; 1501 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1502 } 1503 } 1504 foreach imgTy = [Image1dArray] in { 1505 foreach name = ["read_imagef"] in { 1506 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1507 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>; 1508 } 1509 foreach name = ["read_imagei"] in { 1510 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1511 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>; 1512 } 1513 foreach name = ["read_imageui"] in { 1514 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float], Attr.Pure>; 1515 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 2>, Float, Float], Attr.Pure>; 1516 } 1517 } 1518 foreach imgTy = [Image2dArray] in { 1519 foreach name = ["read_imagef"] in { 1520 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1521 def : Builtin<name, [VectorType<Float, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1522 } 1523 foreach name = ["read_imagei"] in { 1524 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1525 def : Builtin<name, [VectorType<Int, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1526 } 1527 foreach name = ["read_imageui"] in { 1528 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1529 def : Builtin<name, [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1530 } 1531 } 1532 foreach imgTy = [Image2dArrayDepth] in { 1533 foreach name = ["read_imagef"] in { 1534 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1535 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>; 1536 } 1537 } 1538 } 1539 // Added to section 6.13.14.5 1540 foreach aQual = ["RO", "WO", "RW"] in { 1541 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in { 1542 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>; 1543 } 1544 } 1545} 1546 1547// Write functions are enabled using a separate extension. 1548let Extension = FuncExtKhrMipmapImageWrites in { 1549 // Added to section 6.13.14.4. 1550 foreach aQual = ["WO"] in { 1551 foreach imgTy = [Image2d] in { 1552 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>; 1553 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>; 1554 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>; 1555 } 1556 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Int, Float]>; 1557 foreach imgTy = [Image1d] in { 1558 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Float, 4>]>; 1559 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<Int, 4>]>; 1560 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, Int, Int, VectorType<UInt, 4>]>; 1561 } 1562 foreach imgTy = [Image1dArray] in { 1563 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Float, 4>]>; 1564 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<Int, 4>]>; 1565 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int, VectorType<UInt, 4>]>; 1566 } 1567 foreach imgTy = [Image2dArray] in { 1568 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>; 1569 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>; 1570 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>; 1571 } 1572 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>; 1573 let Extension = FuncExtKhrMipmapWritesAndWrite3d in { 1574 foreach imgTy = [Image3d] in { 1575 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>; 1576 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>; 1577 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>; 1578 } 1579 } 1580 } 1581} 1582 1583//-------------------------------------------------------------------- 1584// OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures 1585let Extension = FuncExtKhrGlMsaaSharing in { 1586 // --- Table 6.13.14.3 --- 1587 foreach aQual = ["RO", "RW"] in { 1588 foreach imgTy = [Image2dMsaa] in { 1589 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>; 1590 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>; 1591 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>; 1592 } 1593 foreach imgTy = [Image2dArrayMsaa] in { 1594 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>; 1595 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>; 1596 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>; 1597 } 1598 foreach name = ["read_imagef"] in { 1599 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>; 1600 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>; 1601 } 1602 } 1603 1604 // --- Table 6.13.14.5 --- 1605 foreach aQual = ["RO", "WO", "RW"] in { 1606 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in { 1607 foreach name = ["get_image_width", "get_image_height", 1608 "get_image_channel_data_type", "get_image_channel_order", 1609 "get_image_num_samples"] in { 1610 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>; 1611 } 1612 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>; 1613 } 1614 foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in { 1615 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>; 1616 } 1617 } 1618} 1619 1620//-------------------------------------------------------------------- 1621// OpenCL Extension v2.0 s28 - Subgroups 1622// --- Table 28.2.1 --- 1623let Extension = FuncExtKhrSubgroups in { 1624 foreach name = ["get_sub_group_size", "get_max_sub_group_size", 1625 "get_num_sub_groups", "get_sub_group_id", 1626 "get_sub_group_local_id"] in { 1627 def : Builtin<name, [UInt]>; 1628 } 1629 let MinVersion = CL20 in { 1630 foreach name = ["get_enqueued_num_sub_groups"] in { 1631 def : Builtin<name, [UInt]>; 1632 } 1633 } 1634} 1635 1636// --- Table 28.2.2 --- 1637let Extension = FuncExtKhrSubgroups in { 1638 def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>; 1639 def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>; 1640} 1641 1642// --- Table 28.2.4 --- 1643let Extension = FuncExtKhrSubgroups in { 1644 foreach name = ["sub_group_all", "sub_group_any"] in { 1645 def : Builtin<name, [Int, Int], Attr.Convergent>; 1646 } 1647 foreach name = ["sub_group_broadcast"] in { 1648 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, UInt], Attr.Convergent>; 1649 } 1650 foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_", 1651 "sub_group_scan_inclusive_"] in { 1652 foreach op = ["add", "min", "max"] in { 1653 def : Builtin<name # op, [IntLongFloatGenType1, IntLongFloatGenType1], Attr.Convergent>; 1654 } 1655 } 1656} 1657 1658// OpenCL Extension v3.0 s38 - Extended Subgroup Functions 1659 1660// Section 38.4.1 - cl_khr_subgroup_extended_types 1661let Extension = FuncExtKhrSubgroupExtendedTypes in { 1662 // For sub_group_broadcast, add scalar char, uchar, short, and ushort support, 1663 def : Builtin<"sub_group_broadcast", [CharShortGenType1, CharShortGenType1, UInt], Attr.Convergent>; 1664 // gentype may additionally be one of the supported built-in vector data types. 1665 def : Builtin<"sub_group_broadcast", [AGenTypeNNoScalar, AGenTypeNNoScalar, UInt], Attr.Convergent>; 1666 1667 foreach name = ["sub_group_reduce_", "sub_group_scan_exclusive_", 1668 "sub_group_scan_inclusive_"] in { 1669 foreach op = ["add", "min", "max"] in { 1670 def : Builtin<name # op, [CharShortGenType1, CharShortGenType1], Attr.Convergent>; 1671 } 1672 } 1673} 1674 1675// Section 38.5.1 - cl_khr_subgroup_non_uniform_vote 1676let Extension = FuncExtKhrSubgroupNonUniformVote in { 1677 def : Builtin<"sub_group_elect", [Int]>; 1678 def : Builtin<"sub_group_non_uniform_all", [Int, Int]>; 1679 def : Builtin<"sub_group_non_uniform_any", [Int, Int]>; 1680 def : Builtin<"sub_group_non_uniform_all_equal", [Int, AGenType1]>; 1681} 1682 1683// Section 38.6.1 - cl_khr_subgroup_ballot 1684let Extension = FuncExtKhrSubgroupBallot in { 1685 def : Builtin<"sub_group_non_uniform_broadcast", [AGenTypeN, AGenTypeN, UInt]>; 1686 def : Builtin<"sub_group_broadcast_first", [AGenType1, AGenType1]>; 1687 def : Builtin<"sub_group_ballot", [VectorType<UInt, 4>, Int]>; 1688 def : Builtin<"sub_group_inverse_ballot", [Int, VectorType<UInt, 4>], Attr.Const>; 1689 def : Builtin<"sub_group_ballot_bit_extract", [Int, VectorType<UInt, 4>, UInt], Attr.Const>; 1690 def : Builtin<"sub_group_ballot_bit_count", [UInt, VectorType<UInt, 4>], Attr.Const>; 1691 def : Builtin<"sub_group_ballot_inclusive_scan", [UInt, VectorType<UInt, 4>]>; 1692 def : Builtin<"sub_group_ballot_exclusive_scan", [UInt, VectorType<UInt, 4>]>; 1693 def : Builtin<"sub_group_ballot_find_lsb", [UInt, VectorType<UInt, 4>]>; 1694 def : Builtin<"sub_group_ballot_find_msb", [UInt, VectorType<UInt, 4>]>; 1695 1696 foreach op = ["eq", "ge", "gt", "le", "lt"] in { 1697 def : Builtin<"get_sub_group_" # op # "_mask", [VectorType<UInt, 4>], Attr.Const>; 1698 } 1699} 1700 1701// Section 38.7.1 - cl_khr_subgroup_non_uniform_arithmetic 1702let Extension = FuncExtKhrSubgroupNonUniformArithmetic in { 1703 foreach name = ["reduce_", "scan_exclusive_", "scan_inclusive_"] in { 1704 foreach op = ["add", "min", "max", "mul"] in { 1705 def : Builtin<"sub_group_non_uniform_" # name # op, [AGenType1, AGenType1]>; 1706 } 1707 foreach op = ["and", "or", "xor"] in { 1708 def : Builtin<"sub_group_non_uniform_" # name # op, [AIGenType1, AIGenType1]>; 1709 } 1710 foreach op = ["and", "or", "xor"] in { 1711 def : Builtin<"sub_group_non_uniform_" # name # "logical_" # op, [Int, Int]>; 1712 } 1713 } 1714} 1715 1716// Section 38.8.1 - cl_khr_subgroup_shuffle 1717let Extension = FuncExtKhrSubgroupShuffle in { 1718 def : Builtin<"sub_group_shuffle", [AGenType1, AGenType1, UInt]>; 1719 def : Builtin<"sub_group_shuffle_xor", [AGenType1, AGenType1, UInt]>; 1720} 1721 1722// Section 38.9.1 - cl_khr_subgroup_shuffle_relative 1723let Extension = FuncExtKhrSubgroupShuffleRelative in { 1724 def : Builtin<"sub_group_shuffle_up", [AGenType1, AGenType1, UInt]>; 1725 def : Builtin<"sub_group_shuffle_down", [AGenType1, AGenType1, UInt]>; 1726} 1727 1728// Section 38.10.1 - cl_khr_subgroup_clustered_reduce 1729let Extension = FuncExtKhrSubgroupClusteredReduce in { 1730 foreach op = ["add", "min", "max", "mul"] in { 1731 def : Builtin<"sub_group_clustered_reduce_" # op, [AGenType1, AGenType1, UInt]>; 1732 } 1733 foreach op = ["and", "or", "xor"] in { 1734 def : Builtin<"sub_group_clustered_reduce_" # op, [AIGenType1, AIGenType1, UInt]>; 1735 } 1736 foreach op = ["and", "or", "xor"] in { 1737 def : Builtin<"sub_group_clustered_reduce_logical_" # op, [Int, Int, UInt]>; 1738 } 1739} 1740 1741//-------------------------------------------------------------------- 1742// Arm extensions. 1743let Extension = ArmIntegerDotProductInt8 in { 1744 foreach name = ["arm_dot"] in { 1745 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>; 1746 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>]>; 1747 } 1748} 1749let Extension = ArmIntegerDotProductAccumulateInt8 in { 1750 foreach name = ["arm_dot_acc"] in { 1751 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>; 1752 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>; 1753 } 1754} 1755let Extension = ArmIntegerDotProductAccumulateInt16 in { 1756 foreach name = ["arm_dot_acc"] in { 1757 def : Builtin<name, [UInt, VectorType<UShort, 2>, VectorType<UShort, 2>, UInt]>; 1758 def : Builtin<name, [Int, VectorType<Short, 2>, VectorType<Short, 2>, Int]>; 1759 } 1760} 1761let Extension = ArmIntegerDotProductAccumulateSaturateInt8 in { 1762 foreach name = ["arm_dot_acc_sat"] in { 1763 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt]>; 1764 def : Builtin<name, [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int]>; 1765 } 1766} 1767