comparison clang/lib/Sema/OpenCLBuiltins.td @ 236:c4bab56944e8 llvm-original

LLVM 16
author kono
date Wed, 09 Nov 2022 17:45:10 +0900
parents 79ff65ed7e25
children
comparison
equal deleted inserted replaced
232:70dce7da266c 236:c4bab56944e8
55 // During overload resolution, when a builtin function overload contains a type 55 // During overload resolution, when a builtin function overload contains a type
56 // with a TypeExtension, those overloads are skipped when the extension is 56 // with a TypeExtension, those overloads are skipped when the extension is
57 // disabled. 57 // disabled.
58 class TypeExtension<string _Ext> : AbstractExtension<_Ext>; 58 class TypeExtension<string _Ext> : AbstractExtension<_Ext>;
59 59
60 // Concatenate zero or more space-separated extensions in NewExts to Base and
61 // return the resulting FunctionExtension in ret.
62 class concatExtension<FunctionExtension Base, string NewExts> {
63 FunctionExtension ret = FunctionExtension<
64 !cond(
65 // Return Base extension if NewExts is empty,
66 !empty(NewExts) : Base.ExtName,
67
68 // otherwise, return NewExts if Base extension is empty,
69 !empty(Base.ExtName) : NewExts,
70
71 // otherwise, concatenate NewExts to Base.
72 true : Base.ExtName # " " # NewExts
73 )
74 >;
75 }
76
60 // TypeExtension definitions. 77 // TypeExtension definitions.
61 def NoTypeExt : TypeExtension<"">; 78 def NoTypeExt : TypeExtension<"">;
62 def Fp16TypeExt : TypeExtension<"cl_khr_fp16">; 79 def Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
63 def Fp64TypeExt : TypeExtension<"cl_khr_fp64">; 80 def Fp64TypeExt : TypeExtension<"cl_khr_fp64">;
81 def Atomic64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics">;
82 def AtomicFp64TypeExt : TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp64">;
64 83
65 // FunctionExtension definitions. 84 // FunctionExtension definitions.
66 def FuncExtNone : FunctionExtension<"">; 85 def FuncExtNone : FunctionExtension<"">;
67 def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">; 86 def FuncExtKhrSubgroups : FunctionExtension<"__opencl_subgroup_builtins">;
68 def FuncExtKhrSubgroupExtendedTypes : FunctionExtension<"cl_khr_subgroup_extended_types">; 87 def FuncExtKhrSubgroupExtendedTypes : FunctionExtension<"cl_khr_subgroup_extended_types">;
69 def FuncExtKhrSubgroupNonUniformVote : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">; 88 def FuncExtKhrSubgroupNonUniformVote : FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
70 def FuncExtKhrSubgroupBallot : FunctionExtension<"cl_khr_subgroup_ballot">; 89 def FuncExtKhrSubgroupBallot : FunctionExtension<"cl_khr_subgroup_ballot">;
71 def FuncExtKhrSubgroupNonUniformArithmetic: FunctionExtension<"cl_khr_subgroup_non_uniform_arithmetic">; 90 def FuncExtKhrSubgroupNonUniformArithmetic: FunctionExtension<"cl_khr_subgroup_non_uniform_arithmetic">;
72 def FuncExtKhrSubgroupShuffle : FunctionExtension<"cl_khr_subgroup_shuffle">; 91 def FuncExtKhrSubgroupShuffle : FunctionExtension<"cl_khr_subgroup_shuffle">;
73 def FuncExtKhrSubgroupShuffleRelative : FunctionExtension<"cl_khr_subgroup_shuffle_relative">; 92 def FuncExtKhrSubgroupShuffleRelative : FunctionExtension<"cl_khr_subgroup_shuffle_relative">;
74 def FuncExtKhrSubgroupClusteredReduce : FunctionExtension<"cl_khr_subgroup_clustered_reduce">; 93 def FuncExtKhrSubgroupClusteredReduce : FunctionExtension<"cl_khr_subgroup_clustered_reduce">;
94 def FuncExtKhrExtendedBitOps : FunctionExtension<"cl_khr_extended_bit_ops">;
75 def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">; 95 def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">;
76 def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">; 96 def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
77 def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">; 97 def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">;
78 def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">; 98 def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
79 def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">; 99 def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">;
80 def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">; 100 def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">;
81 def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">; 101 def FuncExtKhrMipmapImage : FunctionExtension<"cl_khr_mipmap_image">;
82 def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">; 102 def FuncExtKhrMipmapImageWrites : FunctionExtension<"cl_khr_mipmap_image_writes">;
83 def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">; 103 def FuncExtKhrGlMsaaSharing : FunctionExtension<"cl_khr_gl_msaa_sharing">;
84 104
105 def FuncExtOpenCLCDeviceEnqueue : FunctionExtension<"__opencl_c_device_enqueue">;
106 def FuncExtOpenCLCGenericAddressSpace : FunctionExtension<"__opencl_c_generic_address_space">;
107 def FuncExtOpenCLCNamedAddressSpaceBuiltins : FunctionExtension<"__opencl_c_named_address_space_builtins">;
108 def FuncExtOpenCLCPipes : FunctionExtension<"__opencl_c_pipes">;
109 def FuncExtOpenCLCWGCollectiveFunctions : FunctionExtension<"__opencl_c_work_group_collective_functions">;
110 def FuncExtOpenCLCReadWriteImages : FunctionExtension<"__opencl_c_read_write_images">;
111 def FuncExtFloatAtomicsFp16GlobalASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store">;
112 def FuncExtFloatAtomicsFp16LocalASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_load_store">;
113 def FuncExtFloatAtomicsFp16GenericASLoadStore : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_load_store __opencl_c_ext_fp16_local_atomic_load_store">;
114 def FuncExtFloatAtomicsFp16GlobalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_add">;
115 def FuncExtFloatAtomicsFp32GlobalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_add">;
116 def FuncExtFloatAtomicsFp64GlobalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_add">;
117 def FuncExtFloatAtomicsFp16LocalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add">;
118 def FuncExtFloatAtomicsFp32LocalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add">;
119 def FuncExtFloatAtomicsFp64LocalASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add">;
120 def FuncExtFloatAtomicsFp16GenericASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add __opencl_c_ext_fp16_global_atomic_add">;
121 def FuncExtFloatAtomicsFp32GenericASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add __opencl_c_ext_fp32_global_atomic_add">;
122 def FuncExtFloatAtomicsFp64GenericASAdd : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add __opencl_c_ext_fp64_global_atomic_add">;
123 def FuncExtFloatAtomicsFp16GlobalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_min_max">;
124 def FuncExtFloatAtomicsFp32GlobalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_min_max">;
125 def FuncExtFloatAtomicsFp64GlobalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_min_max">;
126 def FuncExtFloatAtomicsFp16LocalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_min_max">;
127 def FuncExtFloatAtomicsFp32LocalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_min_max">;
128 def FuncExtFloatAtomicsFp64LocalASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_min_max">;
129 def FuncExtFloatAtomicsFp16GenericASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_min_max __opencl_c_ext_fp16_global_atomic_min_max">;
130 def FuncExtFloatAtomicsFp32GenericASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_min_max __opencl_c_ext_fp32_global_atomic_min_max">;
131 def FuncExtFloatAtomicsFp64GenericASMinMax : FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_min_max __opencl_c_ext_fp64_global_atomic_min_max">;
132
85 // Not a real extension, but a workaround to add C++ for OpenCL specific builtins. 133 // Not a real extension, but a workaround to add C++ for OpenCL specific builtins.
86 def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">; 134 def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
87
88 // Multiple extensions
89 def FuncExtKhrMipmapWritesAndWrite3d : FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">;
90 135
91 // Arm extensions. 136 // Arm extensions.
92 def ArmIntegerDotProductInt8 : FunctionExtension<"cl_arm_integer_dot_product_int8">; 137 def ArmIntegerDotProductInt8 : FunctionExtension<"cl_arm_integer_dot_product_int8">;
93 def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">; 138 def ArmIntegerDotProductAccumulateInt8 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
94 def ArmIntegerDotProductAccumulateInt16 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">; 139 def ArmIntegerDotProductAccumulateInt16 : FunctionExtension<"cl_arm_integer_dot_product_accumulate_int16">;
195 // Inherited fields 240 // Inherited fields
196 let IsPointer = _Ty.IsPointer; 241 let IsPointer = _Ty.IsPointer;
197 let IsConst = _Ty.IsConst; 242 let IsConst = _Ty.IsConst;
198 let IsVolatile = _Ty.IsVolatile; 243 let IsVolatile = _Ty.IsVolatile;
199 let AddrSpace = _Ty.AddrSpace; 244 let AddrSpace = _Ty.AddrSpace;
200 let Extension = _Ty.Extension; 245 // Add TypeExtensions for writable "image3d_t" and "read_write" image types.
246 let Extension = !cond(
247 !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : TypeExtension<"cl_khr_3d_image_writes">,
248 !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "RW")) : TypeExtension<"cl_khr_3d_image_writes __opencl_c_read_write_images">,
249 !or(!eq(_Ty.Name, "image2d_depth_t"), !eq(_Ty.Name, "image2d_array_depth_t")) : TypeExtension<"cl_khr_depth_images">,
250 !eq(_AccessQualifier, "RW") : TypeExtension<"__opencl_c_read_write_images">,
251 true : _Ty.Extension);
201 } 252 }
202 253
203 // OpenCL enum type (e.g. memory_scope). 254 // OpenCL enum type (e.g. memory_scope).
204 class EnumType<string _Name> : 255 class EnumType<string _Name> :
205 Type<_Name, QualType<"getOpenCLEnumType(S, \"" # _Name # "\")", 0>> { 256 Type<_Name, QualType<"getOpenCLEnumType(S, \"" # _Name # "\")", 0>> {
300 def ULong : Type<"ulong", QualType<"Context.UnsignedLongTy">>; 351 def ULong : Type<"ulong", QualType<"Context.UnsignedLongTy">>;
301 def Float : Type<"float", QualType<"Context.FloatTy">>; 352 def Float : Type<"float", QualType<"Context.FloatTy">>;
302 let Extension = Fp64TypeExt in { 353 let Extension = Fp64TypeExt in {
303 def Double : Type<"double", QualType<"Context.DoubleTy">>; 354 def Double : Type<"double", QualType<"Context.DoubleTy">>;
304 } 355 }
356
357 // The half type for builtins that require the cl_khr_fp16 extension.
305 let Extension = Fp16TypeExt in { 358 let Extension = Fp16TypeExt in {
306 def Half : Type<"half", QualType<"Context.HalfTy">>; 359 def Half : Type<"half", QualType<"Context.HalfTy">>;
307 } 360 }
361
362 // Without the cl_khr_fp16 extension, the half type can only be used to declare
363 // a pointer. Define const and non-const pointer types in all address spaces.
364 // Use the "__half" alias to allow the TableGen emitter to distinguish the
365 // (extensionless) pointee type of these pointer-to-half types from the "half"
366 // type defined above that already carries the cl_khr_fp16 extension.
367 foreach AS = [PrivateAS, GlobalAS, ConstantAS, LocalAS, GenericAS] in {
368 def "HalfPtr" # AS : PointerType<Type<"__half", QualType<"Context.HalfTy">>, AS>;
369 def "HalfPtrConst" # AS : PointerType<ConstType<Type<"__half", QualType<"Context.HalfTy">>>, AS>;
370 }
371
308 def Size : Type<"size_t", QualType<"Context.getSizeType()">>; 372 def Size : Type<"size_t", QualType<"Context.getSizeType()">>;
309 def PtrDiff : Type<"ptrdiff_t", QualType<"Context.getPointerDiffType()">>; 373 def PtrDiff : Type<"ptrdiff_t", QualType<"Context.getPointerDiffType()">>;
310 def IntPtr : Type<"intptr_t", QualType<"Context.getIntPtrType()">>; 374 def IntPtr : Type<"intptr_t", QualType<"Context.getIntPtrType()">>;
311 def UIntPtr : Type<"uintptr_t", QualType<"Context.getUIntPtrType()">>; 375 def UIntPtr : Type<"uintptr_t", QualType<"Context.getUIntPtrType()">>;
312 def Void : Type<"void", QualType<"Context.VoidTy">>; 376 def Void : Type<"void", QualType<"Context.VoidTy">>;
340 def NDRange : TypedefType<"ndrange_t">; 404 def NDRange : TypedefType<"ndrange_t">;
341 405
342 // OpenCL v2.0 s6.13.11: Atomic integer and floating-point types. 406 // OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
343 def AtomicInt : Type<"atomic_int", QualType<"Context.getAtomicType(Context.IntTy)">>; 407 def AtomicInt : Type<"atomic_int", QualType<"Context.getAtomicType(Context.IntTy)">>;
344 def AtomicUInt : Type<"atomic_uint", QualType<"Context.getAtomicType(Context.UnsignedIntTy)">>; 408 def AtomicUInt : Type<"atomic_uint", QualType<"Context.getAtomicType(Context.UnsignedIntTy)">>;
345 def AtomicLong : Type<"atomic_long", QualType<"Context.getAtomicType(Context.LongTy)">>; 409 let Extension = Atomic64TypeExt in {
346 def AtomicULong : Type<"atomic_ulong", QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>; 410 def AtomicLong : Type<"atomic_long", QualType<"Context.getAtomicType(Context.LongTy)">>;
411 def AtomicULong : Type<"atomic_ulong", QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>;
412 }
347 def AtomicFloat : Type<"atomic_float", QualType<"Context.getAtomicType(Context.FloatTy)">>; 413 def AtomicFloat : Type<"atomic_float", QualType<"Context.getAtomicType(Context.FloatTy)">>;
348 def AtomicDouble : Type<"atomic_double", QualType<"Context.getAtomicType(Context.DoubleTy)">>; 414 let Extension = AtomicFp64TypeExt in {
415 def AtomicDouble : Type<"atomic_double", QualType<"Context.getAtomicType(Context.DoubleTy)">>;
416 }
417 def AtomicHalf : Type<"atomic_half", QualType<"Context.getAtomicType(Context.HalfTy)">>;
349 def AtomicIntPtr : Type<"atomic_intptr_t", QualType<"Context.getAtomicType(Context.getIntPtrType())">>; 418 def AtomicIntPtr : Type<"atomic_intptr_t", QualType<"Context.getAtomicType(Context.getIntPtrType())">>;
350 def AtomicUIntPtr : Type<"atomic_uintptr_t", QualType<"Context.getAtomicType(Context.getUIntPtrType())">>; 419 def AtomicUIntPtr : Type<"atomic_uintptr_t", QualType<"Context.getAtomicType(Context.getUIntPtrType())">>;
351 def AtomicSize : Type<"atomic_size_t", QualType<"Context.getAtomicType(Context.getSizeType())">>; 420 def AtomicSize : Type<"atomic_size_t", QualType<"Context.getAtomicType(Context.getSizeType())">>;
352 def AtomicPtrDiff : Type<"atomic_ptrdiff_t", QualType<"Context.getAtomicType(Context.getPointerDiffType())">>; 421 def AtomicPtrDiff : Type<"atomic_ptrdiff_t", QualType<"Context.getAtomicType(Context.getPointerDiffType())">>;
353 422
540 // --- 3 arguments --- 609 // --- 3 arguments ---
541 foreach name = ["fma", "mad"] in { 610 foreach name = ["fma", "mad"] in {
542 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>; 611 def : Builtin<name, [FGenTypeN, FGenTypeN, FGenTypeN, FGenTypeN], Attr.Const>;
543 } 612 }
544 613
545 // --- Version dependent --- 614 // The following math builtins take pointer arguments. Which overloads are
546 let MaxVersion = CL20 in { 615 // available depends on whether the generic address space feature is enabled.
547 foreach AS = [GlobalAS, LocalAS, PrivateAS] in { 616 multiclass MathWithPointer<list<AddressSpace> addrspaces> {
617 foreach AS = addrspaces in {
548 foreach name = ["fract", "modf", "sincos"] in { 618 foreach name = ["fract", "modf", "sincos"] in {
549 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>; 619 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, AS>]>;
550 } 620 }
551 foreach name = ["frexp", "lgamma_r"] in { 621 foreach name = ["frexp", "lgamma_r"] in {
552 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { 622 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in {
558 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>; 628 def : Builtin<name, [Type, Type, Type, PointerType<GenTypeIntVecAndScalar, AS>]>;
559 } 629 }
560 } 630 }
561 } 631 }
562 } 632 }
563 let MinVersion = CL20 in { 633
564 foreach name = ["fract", "modf", "sincos"] in { 634 let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
565 def : Builtin<name, [FGenTypeN, FGenTypeN, PointerType<FGenTypeN, GenericAS>]>; 635 defm : MathWithPointer<[GlobalAS, LocalAS, PrivateAS]>;
566 } 636 }
567 foreach name = ["frexp", "lgamma_r"] in { 637 let Extension = FuncExtOpenCLCGenericAddressSpace in {
568 foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, GenTypeHalfVecAndScalar] in { 638 defm : MathWithPointer<[GenericAS]>;
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 } 639 }
577 640
578 // --- Table 9 --- 641 // --- Table 9 ---
579 foreach name = ["half_cos", 642 foreach name = ["half_cos",
580 "half_exp", "half_exp2", "half_exp10", 643 "half_exp", "half_exp2", "half_exp10",
780 843
781 //-------------------------------------------------------------------- 844 //--------------------------------------------------------------------
782 // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and Store Functions 845 // 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 846 // 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 --- 847 // --- Table 15 ---
785 // Variants for OpenCL versions below 2.0, using pointers to the global, local 848 multiclass VloadVstore<list<AddressSpace> addrspaces, bit defStores> {
786 // and private address spaces. 849 foreach AS = addrspaces in {
787 let MaxVersion = CL20 in {
788 foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
789 foreach VSize = [2, 3, 4, 8, 16] in { 850 foreach VSize = [2, 3, 4, 8, 16] in {
790 foreach name = ["vload" # VSize] in { 851 foreach name = ["vload" # VSize] in {
791 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>]>; 852 def : Builtin<name, [VectorType<Char, VSize>, Size, PointerType<ConstType<Char>, AS>], Attr.Pure>;
792 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>]>; 853 def : Builtin<name, [VectorType<UChar, VSize>, Size, PointerType<ConstType<UChar>, AS>], Attr.Pure>;
793 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>]>; 854 def : Builtin<name, [VectorType<Short, VSize>, Size, PointerType<ConstType<Short>, AS>], Attr.Pure>;
794 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>]>; 855 def : Builtin<name, [VectorType<UShort, VSize>, Size, PointerType<ConstType<UShort>, AS>], Attr.Pure>;
795 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>]>; 856 def : Builtin<name, [VectorType<Int, VSize>, Size, PointerType<ConstType<Int>, AS>], Attr.Pure>;
796 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>]>; 857 def : Builtin<name, [VectorType<UInt, VSize>, Size, PointerType<ConstType<UInt>, AS>], Attr.Pure>;
797 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>]>; 858 def : Builtin<name, [VectorType<Long, VSize>, Size, PointerType<ConstType<Long>, AS>], Attr.Pure>;
798 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>]>; 859 def : Builtin<name, [VectorType<ULong, VSize>, Size, PointerType<ConstType<ULong>, AS>], Attr.Pure>;
799 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>]>; 860 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Float>, AS>], Attr.Pure>;
800 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>]>; 861 def : Builtin<name, [VectorType<Double, VSize>, Size, PointerType<ConstType<Double>, AS>], Attr.Pure>;
801 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 862 def : Builtin<name, [VectorType<Half, VSize>, Size, PointerType<ConstType<Half>, AS>], Attr.Pure>;
802 } 863 }
803 foreach name = ["vstore" # VSize] in { 864 if defStores then {
804 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>; 865 foreach name = ["vstore" # VSize] in {
805 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>; 866 def : Builtin<name, [Void, VectorType<Char, VSize>, Size, PointerType<Char, AS>]>;
806 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>; 867 def : Builtin<name, [Void, VectorType<UChar, VSize>, Size, PointerType<UChar, AS>]>;
807 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>; 868 def : Builtin<name, [Void, VectorType<Short, VSize>, Size, PointerType<Short, AS>]>;
808 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>; 869 def : Builtin<name, [Void, VectorType<UShort, VSize>, Size, PointerType<UShort, AS>]>;
809 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>; 870 def : Builtin<name, [Void, VectorType<Int, VSize>, Size, PointerType<Int, AS>]>;
810 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>; 871 def : Builtin<name, [Void, VectorType<UInt, VSize>, Size, PointerType<UInt, AS>]>;
811 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>; 872 def : Builtin<name, [Void, VectorType<Long, VSize>, Size, PointerType<Long, AS>]>;
812 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>; 873 def : Builtin<name, [Void, VectorType<ULong, VSize>, Size, PointerType<ULong, AS>]>;
813 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>; 874 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Float, AS>]>;
814 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>; 875 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Double, AS>]>;
815 } 876 def : Builtin<name, [Void, VectorType<Half, VSize>, Size, PointerType<Half, AS>]>;
816 foreach name = ["vloada_half" # VSize] in { 877 }
817 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 878 }
818 } 879 }
880 }
881 }
882
883 let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
884 defm : VloadVstore<[GlobalAS, LocalAS, PrivateAS], 1>;
885 }
886 let Extension = FuncExtOpenCLCGenericAddressSpace in {
887 defm : VloadVstore<[GenericAS], 1>;
888 }
889 // vload with constant address space is available regardless of version.
890 defm : VloadVstore<[ConstantAS], 0>;
891
892 multiclass VloadVstoreHalf<list<AddressSpace> addrspaces, bit defStores> {
893 foreach AS = addrspaces in {
894 def : Builtin<"vload_half", [Float, Size, !cast<Type>("HalfPtrConst" # AS)], Attr.Pure>;
895 foreach VSize = [2, 3, 4, 8, 16] in {
896 foreach name = ["vload_half" # VSize, "vloada_half" # VSize] in {
897 def : Builtin<name, [VectorType<Float, VSize>, Size, !cast<Type>("HalfPtrConst" # AS)], Attr.Pure>;
898 }
899 }
900 if defStores then {
819 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in { 901 foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
820 foreach name = ["vstorea_half" # VSize # rnd] in { 902 foreach name = ["vstore_half" # rnd] in {
821 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, PointerType<Half, AS>]>; 903 def : Builtin<name, [Void, Float, Size, !cast<Type>("HalfPtr" # AS)]>;
822 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, PointerType<Half, AS>]>; 904 def : Builtin<name, [Void, Double, Size, !cast<Type>("HalfPtr" # AS)]>;
823 } 905 }
824 } 906 foreach VSize = [2, 3, 4, 8, 16] in {
825 } 907 foreach name = ["vstore_half" # VSize # rnd, "vstorea_half" # VSize # rnd] in {
826 } 908 def : Builtin<name, [Void, VectorType<Float, VSize>, Size, !cast<Type>("HalfPtr" # AS)]>;
827 } 909 def : Builtin<name, [Void, VectorType<Double, VSize>, Size, !cast<Type>("HalfPtr" # AS)]>;
828 // Variants for OpenCL versions above 2.0, using pointers to the generic 910 }
829 // address space.
830 let 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.
870 foreach 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 }
888 let 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 } 911 }
907 } 912 }
908 } 913 }
909 } 914 }
910 } 915 }
911 let MinVersion = CL20 in { 916
912 foreach AS = [GenericAS] in { 917 let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
913 def : Builtin<"vload_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 918 defm : VloadVstoreHalf<[GlobalAS, LocalAS, PrivateAS], 1>;
914 def : Builtin<"vloada_half", [Float, Size, PointerType<ConstType<Half>, AS>]>; 919 }
915 foreach VSize = [2, 3, 4, 8, 16] in { 920 let Extension = FuncExtOpenCLCGenericAddressSpace in {
916 foreach name = ["vload_half" # VSize] in { 921 defm : VloadVstoreHalf<[GenericAS], 1>;
917 def : Builtin<name, [VectorType<Float, VSize>, Size, PointerType<ConstType<Half>, AS>]>; 922 }
918 } 923 // vload_half and vloada_half with constant address space are available regardless of version.
919 } 924 defm : VloadVstoreHalf<[ConstantAS], 0>;
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
935 foreach 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 925
945 // OpenCL v3.0 s6.15.8 - Synchronization Functions. 926 // OpenCL v3.0 s6.15.8 - Synchronization Functions.
946 def : Builtin<"barrier", [Void, MemFenceFlags], Attr.Convergent>; 927 def : Builtin<"barrier", [Void, MemFenceFlags], Attr.Convergent>;
947 let MinVersion = CL20 in { 928 let MinVersion = CL20 in {
948 def : Builtin<"work_group_barrier", [Void, MemFenceFlags], Attr.Convergent>; 929 def : Builtin<"work_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
955 def : Builtin<"write_mem_fence", [Void, MemFenceFlags]>; 936 def : Builtin<"write_mem_fence", [Void, MemFenceFlags]>;
956 937
957 // OpenCL v3.0 s6.15.10 - Address Space Qualifier Functions. 938 // OpenCL v3.0 s6.15.10 - Address Space Qualifier Functions.
958 // to_global, to_local, to_private are declared in Builtins.def. 939 // to_global, to_local, to_private are declared in Builtins.def.
959 940
960 let MinVersion = CL20 in { 941 let Extension = FuncExtOpenCLCGenericAddressSpace in {
961 // The OpenCL 3.0 specification defines these with a "gentype" argument indicating any builtin 942 // 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 943 // 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. 944 // by providing only the following overloads with a void pointer.
964 def : Builtin<"get_fence", [MemFenceFlags, PointerType<Void, GenericAS>]>; 945 def : Builtin<"get_fence", [MemFenceFlags, PointerType<Void, GenericAS>]>;
965 def : Builtin<"get_fence", [MemFenceFlags, PointerType<ConstType<Void>, GenericAS>]>; 946 def : Builtin<"get_fence", [MemFenceFlags, PointerType<ConstType<Void>, GenericAS>]>;
1096 } 1077 }
1097 } 1078 }
1098 } 1079 }
1099 1080
1100 // OpenCL v2.0 s6.13.11 - Atomic Functions. 1081 // OpenCL v2.0 s6.13.11 - Atomic Functions.
1101 let MinVersion = CL20 in { 1082
1102 def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>; 1083 // An atomic builtin with 2 additional _explicit variants.
1103 1084 multiclass BuiltinAtomicExplicit<string Name, list<Type> Types, FunctionExtension BaseExt> {
1085 // Without explicit MemoryOrder or MemoryScope.
1086 let Extension = concatExtension<BaseExt, "__opencl_c_atomic_order_seq_cst __opencl_c_atomic_scope_device">.ret in {
1087 def : Builtin<Name, Types>;
1088 }
1089
1090 // With an explicit MemoryOrder argument.
1091 let Extension = concatExtension<BaseExt, "__opencl_c_atomic_scope_device">.ret in {
1092 def : Builtin<Name # "_explicit", !listconcat(Types, [MemoryOrder])>;
1093 }
1094
1095 // With explicit MemoryOrder and MemoryScope arguments.
1096 let Extension = BaseExt in {
1097 def : Builtin<Name # "_explicit", !listconcat(Types, [MemoryOrder, MemoryScope])>;
1098 }
1099 }
1100
1101 // OpenCL 2.0 atomic functions that have a pointer argument in a given address space.
1102 multiclass OpenCL2Atomics<AddressSpace addrspace, FunctionExtension BaseExt> {
1104 foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt], 1103 foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
1105 [AtomicLong, Long], [AtomicULong, ULong], 1104 [AtomicLong, Long], [AtomicULong, ULong],
1106 [AtomicFloat, Float], [AtomicDouble, Double]] in { 1105 [AtomicFloat, Float], [AtomicDouble, Double]] in {
1107 def : Builtin<"atomic_init", 1106 let Extension = BaseExt in {
1108 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; 1107 def : Builtin<"atomic_init",
1109 def : Builtin<"atomic_store", 1108 [Void, PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]]>;
1110 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; 1109 }
1111 def : Builtin<"atomic_store_explicit", 1110 defm : BuiltinAtomicExplicit<"atomic_store",
1112 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1], MemoryOrder]>; 1111 [Void, PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]], BaseExt>;
1113 def : Builtin<"atomic_store_explicit", 1112 defm : BuiltinAtomicExplicit<"atomic_load",
1114 [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1], MemoryOrder, MemoryScope]>; 1113 [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>], BaseExt>;
1115 def : Builtin<"atomic_load", 1114 defm : BuiltinAtomicExplicit<"atomic_exchange",
1116 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>]>; 1115 [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[1]], BaseExt>;
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 { 1116 foreach Variant = ["weak", "strong"] in {
1128 def : Builtin<"atomic_compare_exchange_" # Variant, 1117 foreach exp_ptr_addrspace = !cond(
1129 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, 1118 !eq(BaseExt, FuncExtOpenCLCGenericAddressSpace): [GenericAS],
1130 PointerType<TypePair[1], GenericAS>, TypePair[1]]>; 1119 !eq(BaseExt, FuncExtOpenCLCNamedAddressSpaceBuiltins): [GlobalAS, LocalAS, PrivateAS])
1131 def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit", 1120 in {
1132 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, 1121 let Extension = concatExtension<BaseExt, "__opencl_c_atomic_order_seq_cst __opencl_c_atomic_scope_device">.ret in {
1133 PointerType<TypePair[1], GenericAS>, TypePair[1], MemoryOrder, MemoryOrder]>; 1122 def : Builtin<"atomic_compare_exchange_" # Variant,
1134 def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit", 1123 [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
1135 [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, 1124 PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1]]>;
1136 PointerType<TypePair[1], GenericAS>, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>; 1125 }
1126 let Extension = concatExtension<BaseExt, "__opencl_c_atomic_scope_device">.ret in {
1127 def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
1128 [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
1129 PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1], MemoryOrder, MemoryOrder]>;
1130 }
1131 let Extension = BaseExt in {
1132 def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
1133 [Bool, PointerType<VolatileType<TypePair[0]>, addrspace>,
1134 PointerType<TypePair[1], exp_ptr_addrspace>, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>;
1135 }
1136 }
1137 } 1137 }
1138 } 1138 }
1139 1139
1140 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], 1140 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1141 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong], 1141 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
1142 [AtomicUIntPtr, UIntPtr, PtrDiff]] in { 1142 [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
1143 foreach ModOp = ["add", "sub"] in { 1143 foreach ModOp = ["add", "sub"] in {
1144 def : Builtin<"atomic_fetch_" # ModOp, 1144 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1145 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>; 1145 [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[2]], BaseExt>;
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 } 1146 }
1151 } 1147 }
1152 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], 1148 foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
1153 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] in { 1149 [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] in {
1154 foreach ModOp = ["or", "xor", "and", "min", "max"] in { 1150 foreach ModOp = ["or", "xor", "and", "min", "max"] in {
1155 def : Builtin<"atomic_fetch_" # ModOp, 1151 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1156 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>; 1152 [TypePair[1], PointerType<VolatileType<TypePair[0]>, addrspace>, TypePair[2]], BaseExt>;
1157 def : Builtin<"atomic_fetch_" # ModOp # "_explicit", 1153 }
1158 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2], MemoryOrder]>; 1154 }
1159 def : Builtin<"atomic_fetch_" # ModOp # "_explicit", 1155
1160 [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2], MemoryOrder, MemoryScope]>; 1156 defm : BuiltinAtomicExplicit<"atomic_flag_clear",
1161 } 1157 [Void, PointerType<VolatileType<AtomicFlag>, addrspace>], BaseExt>;
1162 } 1158
1163 1159 defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set",
1164 def : Builtin<"atomic_flag_clear", 1160 [Bool, PointerType<VolatileType<AtomicFlag>, addrspace>], BaseExt>;
1165 [Void, PointerType<VolatileType<AtomicFlag>, GenericAS>]>; 1161 }
1166 def : Builtin<"atomic_flag_clear_explicit", 1162
1167 [Void, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder]>; 1163 let MinVersion = CL20 in {
1168 def : Builtin<"atomic_flag_clear_explicit", 1164 def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>;
1169 [Void, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder, MemoryScope]>; 1165
1170 1166 defm : OpenCL2Atomics<GenericAS, FuncExtOpenCLCGenericAddressSpace>;
1171 def : Builtin<"atomic_flag_test_and_set", 1167 defm : OpenCL2Atomics<GlobalAS, FuncExtOpenCLCNamedAddressSpaceBuiltins>;
1172 [Bool, PointerType<VolatileType<AtomicFlag>, GenericAS>]>; 1168 defm : OpenCL2Atomics<LocalAS, FuncExtOpenCLCNamedAddressSpaceBuiltins>;
1173 def : Builtin<"atomic_flag_test_and_set_explicit", 1169 }
1174 [Bool, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder]>; 1170
1175 def : Builtin<"atomic_flag_test_and_set_explicit", 1171 // The functionality added by cl_ext_float_atomics extension
1176 [Bool, PointerType<VolatileType<AtomicFlag>, GenericAS>, MemoryOrder, MemoryScope]>; 1172 let MinVersion = CL20 in {
1173 foreach addrspace = [GlobalAS, LocalAS, GenericAS] in {
1174 defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "LoadStore");
1175
1176 defm : BuiltinAtomicExplicit<"atomic_store",
1177 [Void, PointerType<VolatileType<AtomicHalf>, addrspace>, AtomicHalf], extension_fp16>;
1178 defm : BuiltinAtomicExplicit<"atomic_load",
1179 [Half, PointerType<VolatileType<AtomicHalf>, addrspace>], extension_fp16>;
1180 defm : BuiltinAtomicExplicit<"atomic_exchange",
1181 [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
1182
1183 foreach ModOp = ["add", "sub"] in {
1184 defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "Add");
1185 defvar extension_fp32 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp32" # addrspace # "Add");
1186 defvar extension_fp64 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp64" # addrspace # "Add");
1187
1188 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1189 [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
1190 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1191 [Float, PointerType<VolatileType<AtomicFloat>, addrspace>, Float], extension_fp32>;
1192 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1193 [Double, PointerType<VolatileType<AtomicDouble>, addrspace>, Double], extension_fp64>;
1194 }
1195
1196 foreach ModOp = ["min", "max"] in {
1197 defvar extension_fp16 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp16" # addrspace # "MinMax");
1198 defvar extension_fp32 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp32" # addrspace # "MinMax");
1199 defvar extension_fp64 = !cast<FunctionExtension>("FuncExtFloatAtomicsFp64" # addrspace # "MinMax");
1200
1201 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1202 [Half, PointerType<VolatileType<AtomicHalf>, addrspace>, Half], extension_fp16>;
1203 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1204 [Float, PointerType<VolatileType<AtomicFloat>, addrspace>, Float], extension_fp32>;
1205 defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
1206 [Double, PointerType<VolatileType<AtomicDouble>, addrspace>, Double], extension_fp64>;
1207 }
1208 }
1177 } 1209 }
1178 1210
1179 //-------------------------------------------------------------------- 1211 //--------------------------------------------------------------------
1180 // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions 1212 // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
1181 // --- Table 19 --- 1213 // --- Table 19 ---
1238 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, "RO">, Sampler, VectorType<coordTy, 2>], Attr.Pure>; 1270 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>; 1271 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, "RO">, Sampler, VectorType<coordTy, 4>], Attr.Pure>;
1240 } 1272 }
1241 1273
1242 // --- Table 23: Sampler-less Read Functions --- 1274 // --- Table 23: Sampler-less Read Functions ---
1275 multiclass ImageReadSamplerless<string aQual> {
1276 foreach imgTy = [Image2d, Image1dArray] in {
1277 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1278 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1279 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1280 }
1281 foreach imgTy = [Image3d, Image2dArray] in {
1282 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1283 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1284 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>], Attr.Pure>;
1285 }
1286 foreach imgTy = [Image1d, Image1dBuffer] in {
1287 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1288 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1289 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1290 }
1291 def : Builtin<"read_imagef", [Float, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>], Attr.Pure>;
1292 def : Builtin<"read_imagef", [Float, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>], Attr.Pure>;
1293 }
1294
1243 let MinVersion = CL12 in { 1295 let MinVersion = CL12 in {
1244 foreach aQual = ["RO", "RW"] in { 1296 defm : ImageReadSamplerless<"RO">;
1245 foreach imgTy = [Image2d, Image1dArray] in { 1297 let Extension = FuncExtOpenCLCReadWriteImages in {
1246 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; 1298 defm : ImageReadSamplerless<"RW">;
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 } 1299 }
1263 } 1300 }
1264 1301
1265 // --- Table 24: Image Write Functions --- 1302 // --- Table 24: Image Write Functions ---
1266 foreach aQual = ["WO", "RW"] in { 1303 multiclass ImageWrite<string aQual> {
1267 foreach imgTy = [Image2d] in { 1304 foreach imgTy = [Image2d] in {
1268 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<Float, 4>]>; 1305 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>]>; 1306 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>]>; 1307 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 2>, VectorType<UInt, 4>]>;
1271 } 1308 }
1291 } 1328 }
1292 def : Builtin<"write_imagef", [Void, ImageType<Image2dDepth, aQual>, VectorType<Int, 2>, Float]>; 1329 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]>; 1330 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Float]>;
1294 } 1331 }
1295 1332
1333 defm : ImageWrite<"WO">;
1334 let Extension = FuncExtOpenCLCReadWriteImages in {
1335 defm : ImageWrite<"RW">;
1336 }
1337
1296 // --- Table 25: Image Query Functions --- 1338 // --- Table 25: Image Query Functions ---
1297 foreach aQual = ["RO", "WO", "RW"] in { 1339 multiclass ImageQuery<string aQual> {
1298 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d, 1340 foreach imgTy = [Image1d, Image1dBuffer, Image2d, Image3d,
1299 Image1dArray, Image2dArray, Image2dDepth, 1341 Image1dArray, Image2dArray, Image2dDepth,
1300 Image2dArrayDepth] in { 1342 Image2dArrayDepth] in {
1301 foreach name = ["get_image_width", "get_image_channel_data_type", 1343 foreach name = ["get_image_width", "get_image_channel_data_type",
1302 "get_image_channel_order"] in { 1344 "get_image_channel_order"] in {
1314 } 1356 }
1315 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>], Attr.Const>; 1357 def : Builtin<"get_image_dim", [VectorType<Int, 4>, ImageType<Image3d, aQual>], Attr.Const>;
1316 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in { 1358 foreach imgTy = [Image1dArray, Image2dArray, Image2dArrayDepth] in {
1317 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>; 1359 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
1318 } 1360 }
1361 }
1362
1363 defm : ImageQuery<"RO">;
1364 defm : ImageQuery<"WO">;
1365 let Extension = FuncExtOpenCLCReadWriteImages in {
1366 defm : ImageQuery<"RW">;
1319 } 1367 }
1320 1368
1321 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions 1369 // OpenCL extension v2.0 s5.1.9: Built-in Image Read Functions
1322 // --- Table 8 --- 1370 // --- Table 8 ---
1323 foreach aQual = ["RO"] in { 1371 foreach aQual = ["RO"] in {
1336 } 1384 }
1337 } 1385 }
1338 // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions 1386 // OpenCL extension v2.0 s5.1.10: Built-in Image Sampler-less Read Functions
1339 // --- Table 9 --- 1387 // --- Table 9 ---
1340 let MinVersion = CL12 in { 1388 let MinVersion = CL12 in {
1341 foreach aQual = ["RO", "RW"] in { 1389 multiclass ImageReadHalf<string aQual> {
1342 foreach name = ["read_imageh"] in { 1390 foreach name = ["read_imageh"] in {
1343 foreach imgTy = [Image2d, Image1dArray] in { 1391 foreach imgTy = [Image2d, Image1dArray] in {
1344 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>; 1392 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>], Attr.Pure>;
1345 } 1393 }
1346 foreach imgTy = [Image3d, Image2dArray] in { 1394 foreach imgTy = [Image3d, Image2dArray] in {
1349 foreach imgTy = [Image1d, Image1dBuffer] in { 1397 foreach imgTy = [Image1d, Image1dBuffer] in {
1350 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>; 1398 def : Builtin<name, [VectorType<Half, 4>, ImageType<imgTy, aQual>, Int], Attr.Pure>;
1351 } 1399 }
1352 } 1400 }
1353 } 1401 }
1402 defm : ImageReadHalf<"RO">;
1403 let Extension = FuncExtOpenCLCReadWriteImages in {
1404 defm : ImageReadHalf<"RW">;
1405 }
1354 } 1406 }
1355 // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions 1407 // OpenCL extension v2.0 s5.1.11: Built-in Image Write Functions
1356 // --- Table 10 --- 1408 // --- Table 10 ---
1357 foreach aQual = ["WO", "RW"] in { 1409 multiclass ImageWriteHalf<string aQual> {
1358 foreach name = ["write_imageh"] in { 1410 foreach name = ["write_imageh"] in {
1359 def : Builtin<name, [Void, ImageType<Image2d, aQual>, VectorType<Int, 2>, VectorType<Half, 4>]>; 1411 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>]>; 1412 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>]>; 1413 def : Builtin<name, [Void, ImageType<Image1d, aQual>, Int, VectorType<Half, 4>]>;
1362 def : Builtin<name, [Void, ImageType<Image1dBuffer, aQual>, Int, VectorType<Half, 4>]>; 1414 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>]>; 1415 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>]>; 1416 def : Builtin<name, [Void, ImageType<Image3d, aQual>, VectorType<Int, 4>, VectorType<Half, 4>]>;
1365 } 1417 }
1366 } 1418 }
1367 1419
1420 defm : ImageWriteHalf<"WO">;
1421 let Extension = FuncExtOpenCLCReadWriteImages in {
1422 defm : ImageWriteHalf<"RW">;
1423 }
1424
1425
1368 1426
1369 //-------------------------------------------------------------------- 1427 //--------------------------------------------------------------------
1370 // OpenCL v2.0 s6.13.15 - Work-group Functions 1428 // OpenCL v2.0 s6.13.15 - Work-group Functions
1371 // --- Table 26 --- 1429 // --- Table 26 ---
1372 let MinVersion = CL20 in { 1430 let Extension = FuncExtOpenCLCWGCollectiveFunctions in {
1373 foreach name = ["work_group_all", "work_group_any"] in { 1431 foreach name = ["work_group_all", "work_group_any"] in {
1374 def : Builtin<name, [Int, Int], Attr.Convergent>; 1432 def : Builtin<name, [Int, Int], Attr.Convergent>;
1375 } 1433 }
1376 foreach name = ["work_group_broadcast"] in { 1434 foreach name = ["work_group_broadcast"] in {
1377 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>; 1435 def : Builtin<name, [IntLongFloatGenType1, IntLongFloatGenType1, Size], Attr.Convergent>;
1392 // --- Table 27 --- 1450 // --- Table 27 ---
1393 // Defined in Builtins.def 1451 // Defined in Builtins.def
1394 1452
1395 // --- Table 28 --- 1453 // --- Table 28 ---
1396 // Builtins taking pipe arguments are defined in Builtins.def 1454 // Builtins taking pipe arguments are defined in Builtins.def
1397 def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>; 1455 let Extension = FuncExtOpenCLCPipes in {
1456 def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
1457 }
1398 1458
1399 // --- Table 29 --- 1459 // --- Table 29 ---
1400 // Defined in Builtins.def 1460 // Defined in Builtins.def
1401 1461
1402 1462
1407 1467
1408 // --- Table 32 --- 1468 // --- Table 32 ---
1409 // Defined in Builtins.def 1469 // Defined in Builtins.def
1410 1470
1411 // --- Table 33 --- 1471 // --- Table 33 ---
1412 let MinVersion = CL20 in { 1472 let Extension = FuncExtOpenCLCDeviceEnqueue in {
1413 def : Builtin<"enqueue_marker", 1473 def : Builtin<"enqueue_marker",
1414 [Int, Queue, UInt, PointerType<ConstType<ClkEvent>, GenericAS>, PointerType<ClkEvent, GenericAS>]>; 1474 [Int, Queue, UInt, PointerType<ConstType<ClkEvent>, GenericAS>, PointerType<ClkEvent, GenericAS>]>;
1415 1475
1416 // --- Table 34 --- 1476 // --- Table 34 ---
1417 def : Builtin<"retain_event", [Void, ClkEvent]>; 1477 def : Builtin<"retain_event", [Void, ClkEvent]>;
1534 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, Float], Attr.Pure>; 1594 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>; 1595 def : Builtin<name, [Float, ImageType<imgTy, aQual>, Sampler, VectorType<Float, 4>, VectorType<Float, 2>, VectorType<Float, 2>], Attr.Pure>;
1536 } 1596 }
1537 } 1597 }
1538 } 1598 }
1539 // Added to section 6.13.14.5 1599 }
1540 foreach aQual = ["RO", "WO", "RW"] in { 1600
1541 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in { 1601 // Added to section 6.13.14.5
1542 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>; 1602 multiclass ImageQueryNumMipLevels<string aQual> {
1543 } 1603 foreach imgTy = [Image1d, Image2d, Image3d, Image1dArray, Image2dArray, Image2dDepth, Image2dArrayDepth] in {
1544 } 1604 def : Builtin<"get_image_num_mip_levels", [Int, ImageType<imgTy, aQual>]>;
1605 }
1606 }
1607
1608 let Extension = FuncExtKhrMipmapImage in {
1609 defm : ImageQueryNumMipLevels<"RO">;
1610 defm : ImageQueryNumMipLevels<"WO">;
1611 defm : ImageQueryNumMipLevels<"RW">;
1545 } 1612 }
1546 1613
1547 // Write functions are enabled using a separate extension. 1614 // Write functions are enabled using a separate extension.
1548 let Extension = FuncExtKhrMipmapImageWrites in { 1615 let Extension = FuncExtKhrMipmapImageWrites in {
1549 // Added to section 6.13.14.4. 1616 // Added to section 6.13.14.4.
1568 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>; 1635 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>]>; 1636 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>]>; 1637 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1571 } 1638 }
1572 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>; 1639 def : Builtin<"write_imagef", [Void, ImageType<Image2dArrayDepth, aQual>, VectorType<Int, 4>, Int, Float]>;
1573 let Extension = FuncExtKhrMipmapWritesAndWrite3d in { 1640 foreach imgTy = [Image3d] in {
1574 foreach imgTy = [Image3d] in { 1641 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>;
1575 def : Builtin<"write_imagef", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Float, 4>]>; 1642 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>;
1576 def : Builtin<"write_imagei", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<Int, 4>]>; 1643 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1577 def : Builtin<"write_imageui", [Void, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int, VectorType<UInt, 4>]>;
1578 }
1579 } 1644 }
1580 } 1645 }
1581 } 1646 }
1582 1647
1583 //-------------------------------------------------------------------- 1648 //--------------------------------------------------------------------
1584 // OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures 1649 // OpenCL Extension v2.0 s18.3 - Creating OpenCL Memory Objects from OpenGL MSAA Textures
1650 // --- Table 6.13.14.3 ---
1651 multiclass ImageReadMsaa<string aQual> {
1652 foreach imgTy = [Image2dMsaa] in {
1653 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1654 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1655 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1656 }
1657 foreach imgTy = [Image2dArrayMsaa] in {
1658 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1659 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1660 def : Builtin<"read_imageui", [VectorType<UInt, 4>, ImageType<imgTy, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1661 }
1662 foreach name = ["read_imagef"] in {
1663 def : Builtin<name, [Float, ImageType<Image2dMsaaDepth, aQual>, VectorType<Int, 2>, Int], Attr.Pure>;
1664 def : Builtin<name, [Float, ImageType<Image2dArrayMsaaDepth, aQual>, VectorType<Int, 4>, Int], Attr.Pure>;
1665 }
1666 }
1667
1668 // --- Table 6.13.14.5 ---
1669 multiclass ImageQueryMsaa<string aQual> {
1670 foreach imgTy = [Image2dMsaa, Image2dArrayMsaa, Image2dMsaaDepth, Image2dArrayMsaaDepth] in {
1671 foreach name = ["get_image_width", "get_image_height",
1672 "get_image_channel_data_type", "get_image_channel_order",
1673 "get_image_num_samples"] in {
1674 def : Builtin<name, [Int, ImageType<imgTy, aQual>], Attr.Const>;
1675 }
1676 def : Builtin<"get_image_dim", [VectorType<Int, 2>, ImageType<imgTy, aQual>], Attr.Const>;
1677 }
1678 foreach imgTy = [Image2dArrayMsaa, Image2dArrayMsaaDepth] in {
1679 def : Builtin<"get_image_array_size", [Size, ImageType<imgTy, aQual>], Attr.Const>;
1680 }
1681 }
1682
1585 let Extension = FuncExtKhrGlMsaaSharing in { 1683 let Extension = FuncExtKhrGlMsaaSharing in {
1586 // --- Table 6.13.14.3 --- 1684 defm : ImageReadMsaa<"RO">;
1587 foreach aQual = ["RO", "RW"] in { 1685 defm : ImageQueryMsaa<"RO">;
1588 foreach imgTy = [Image2dMsaa] in { 1686 defm : ImageQueryMsaa<"WO">;
1589 def : Builtin<"read_imagef", [VectorType<Float, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>; 1687 defm : ImageReadMsaa<"RW">;
1590 def : Builtin<"read_imagei", [VectorType<Int, 4>, ImageType<imgTy, aQual>, VectorType<Int, 2>, Int], Attr.Pure>; 1688 defm : ImageQueryMsaa<"RW">;
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 } 1689 }
1619 1690
1620 //-------------------------------------------------------------------- 1691 //--------------------------------------------------------------------
1621 // OpenCL Extension v2.0 s28 - Subgroups 1692 // OpenCL Extension v2.0 s28 - Subgroups
1622 // --- Table 28.2.1 --- 1693 // --- Table 28.2.1 ---
1634 } 1705 }
1635 1706
1636 // --- Table 28.2.2 --- 1707 // --- Table 28.2.2 ---
1637 let Extension = FuncExtKhrSubgroups in { 1708 let Extension = FuncExtKhrSubgroups in {
1638 def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>; 1709 def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
1639 def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>; 1710 let MinVersion = CL20 in {
1711 def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], Attr.Convergent>;
1712 }
1640 } 1713 }
1641 1714
1642 // --- Table 28.2.4 --- 1715 // --- Table 28.2.4 ---
1643 let Extension = FuncExtKhrSubgroups in { 1716 let Extension = FuncExtKhrSubgroups in {
1644 foreach name = ["sub_group_all", "sub_group_any"] in { 1717 foreach name = ["sub_group_all", "sub_group_any"] in {
1736 foreach op = ["and", "or", "xor"] in { 1809 foreach op = ["and", "or", "xor"] in {
1737 def : Builtin<"sub_group_clustered_reduce_logical_" # op, [Int, Int, UInt]>; 1810 def : Builtin<"sub_group_clustered_reduce_logical_" # op, [Int, Int, UInt]>;
1738 } 1811 }
1739 } 1812 }
1740 1813
1814 // Section 40.3.1 - cl_khr_extended_bit_ops
1815 let Extension = FuncExtKhrExtendedBitOps in {
1816 def : Builtin<"bitfield_insert", [AIGenTypeN, AIGenTypeN, AIGenTypeN, UInt, UInt], Attr.Const>;
1817 def : Builtin<"bitfield_extract_signed", [SGenTypeN, SGenTypeN, UInt, UInt], Attr.Const>;
1818 def : Builtin<"bitfield_extract_signed", [SGenTypeN, UGenTypeN, UInt, UInt], Attr.Const>;
1819 def : Builtin<"bitfield_extract_unsigned", [UGenTypeN, SGenTypeN, UInt, UInt], Attr.Const>;
1820 def : Builtin<"bitfield_extract_unsigned", [UGenTypeN, UGenTypeN, UInt, UInt], Attr.Const>;
1821 def : Builtin<"bit_reverse", [AIGenTypeN, AIGenTypeN], Attr.Const>;
1822 }
1823
1824 // Section 42.3 - cl_khr_integer_dot_product
1825 let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
1826 def : Builtin<"dot", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>], Attr.Const>;
1827 def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<Char, 4>], Attr.Const>;
1828 def : Builtin<"dot", [Int, VectorType<UChar, 4>, VectorType<Char, 4>], Attr.Const>;
1829 def : Builtin<"dot", [Int, VectorType<Char, 4>, VectorType<UChar, 4>], Attr.Const>;
1830
1831 def : Builtin<"dot_acc_sat", [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>, UInt], Attr.Const>;
1832 def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<Char, 4>, Int], Attr.Const>;
1833 def : Builtin<"dot_acc_sat", [Int, VectorType<UChar, 4>, VectorType<Char, 4>, Int], Attr.Const>;
1834 def : Builtin<"dot_acc_sat", [Int, VectorType<Char, 4>, VectorType<UChar, 4>, Int], Attr.Const>;
1835 }
1836
1837 let Extension = FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
1838 def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
1839 def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
1840 def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
1841 def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
1842
1843 def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], Attr.Const>;
1844 def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], Attr.Const>;
1845 def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], Attr.Const>;
1846 def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], Attr.Const>;
1847 }
1848
1849 // Section 48.3 - cl_khr_subgroup_rotate
1850 let Extension = FunctionExtension<"cl_khr_subgroup_rotate"> in {
1851 def : Builtin<"sub_group_rotate", [AGenType1, AGenType1, Int], Attr.Convergent>;
1852 def : Builtin<"sub_group_clustered_rotate", [AGenType1, AGenType1, Int, UInt], Attr.Convergent>;
1853 }
1854
1741 //-------------------------------------------------------------------- 1855 //--------------------------------------------------------------------
1742 // Arm extensions. 1856 // Arm extensions.
1743 let Extension = ArmIntegerDotProductInt8 in { 1857 let Extension = ArmIntegerDotProductInt8 in {
1744 foreach name = ["arm_dot"] in { 1858 foreach name = ["arm_dot"] in {
1745 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>; 1859 def : Builtin<name, [UInt, VectorType<UChar, 4>, VectorType<UChar, 4>]>;