Author: Sven van Haastregt Date: 2020-02-26T14:08:23Z New Revision: 319ea2dd9e32cd10415e1f5060e84febf7c606c6
URL: https://github.com/llvm/llvm-project/commit/319ea2dd9e32cd10415e1f5060e84febf7c606c6 DIFF: https://github.com/llvm/llvm-project/commit/319ea2dd9e32cd10415e1f5060e84febf7c606c6.diff LOG: [OpenCL] Add atomic type builtins Add atomic types and builtins operating on those atomic types to `-fdeclare-opencl-builtins`. The _explicit variants are left out of this commit, as these take enum arguments that are not yet supported by the `-fdeclare-opencl-builtins` machinery. Added: Modified: clang/lib/Sema/OpenCLBuiltins.td Removed: ################################################################################ diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index f79bb54a8143..4ccb6b5fd49d 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -265,7 +265,7 @@ def Half : Type<"half", QualType<"HalfTy">>; def Size : Type<"size_t", QualType<"getSizeType()">>; def PtrDiff : Type<"ptr diff _t", QualType<"getPointerDiffType()">>; def IntPtr : Type<"intptr_t", QualType<"getIntPtrType()">>; -def UIntPtr : Type<"uintPtr_t", QualType<"getUIntPtrType()">>; +def UIntPtr : Type<"uintptr_t", QualType<"getUIntPtrType()">>; def Void : Type<"void", QualType<"VoidTy">>; // OpenCL v1.0/1.2/2.0 s6.1.2: Built-in Vector Data Types. @@ -290,6 +290,18 @@ def Image2dArrayMsaaDepth : Type<"image2d_array_msaa_depth_t", QualType<"OCLImag def Sampler : Type<"sampler_t", QualType<"OCLSamplerTy">>; def Event : Type<"event_t", QualType<"OCLEventTy">>; +// OpenCL v2.0 s6.13.11: Atomic integer and floating-point types. +def AtomicInt : Type<"atomic_int", QualType<"getAtomicType(Context.IntTy)">>; +def AtomicUInt : Type<"atomic_uint", QualType<"getAtomicType(Context.UnsignedIntTy)">>; +def AtomicLong : Type<"atomic_long", QualType<"getAtomicType(Context.LongTy)">>; +def AtomicULong : Type<"atomic_ulong", QualType<"getAtomicType(Context.UnsignedLongTy)">>; +def AtomicFloat : Type<"atomic_float", QualType<"getAtomicType(Context.FloatTy)">>; +def AtomicDouble : Type<"atomic_double", QualType<"getAtomicType(Context.DoubleTy)">>; +def AtomicIntPtr : Type<"atomic_intptr_t", QualType<"getAtomicType(Context.getIntPtrType())">>; +def AtomicUIntPtr : Type<"atomic_uintptr_t", QualType<"getAtomicType(Context.getUIntPtrType())">>; +def AtomicSize : Type<"atomic_size_t", QualType<"getAtomicType(Context.getSizeType())">>; +def AtomicPtrDiff : Type<"atomic_ptr diff _t", QualType<"getAtomicType(Context.getPointerDiffType())">>; + //===----------------------------------------------------------------------===// // Definitions of OpenCL gentype variants //===----------------------------------------------------------------------===// @@ -984,6 +996,45 @@ foreach AS = [GlobalAS, LocalAS] in { } } } +// OpenCL v2.0 s6.13.11 - Atomic Functions. +let MinVersion = CL20 in { + foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt], + [AtomicLong, Long], [AtomicULong, ULong], + [AtomicFloat, Float], [AtomicDouble, Double]] in { + def : Builtin<"atomic_init", + [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; + def : Builtin<"atomic_store", + [Void, PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; + def : Builtin<"atomic_load", + [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>]>; + def : Builtin<"atomic_exchange", + [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[1]]>; + foreach Variant = ["weak", "strong"] in { + def : Builtin<"atomic_compare_exchange_" # Variant, + [Bool, PointerType<VolatileType<TypePair[0]>, GenericAS>, + PointerType<TypePair[1], GenericAS>, TypePair[1]]>; + } + } + + foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], + [AtomicLong, Long, Long], [AtomicULong, ULong, ULong], + [AtomicIntPtr, IntPtr, PtrDiff], + [AtomicUIntPtr, UIntPtr, PtrDiff]] in { + foreach ModOp = ["add", "sub"] in { + def : Builtin<"atomic_fetch_" # ModOp, + [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>; + } + } + foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], + [AtomicLong, Long, Long], [AtomicULong, ULong, ULong], + [AtomicIntPtr, IntPtr, IntPtr], + [AtomicUIntPtr, UIntPtr, UIntPtr]] in { + foreach ModOp = ["or", "xor", "and", "min", "max"] in { + def : Builtin<"atomic_fetch_" # ModOp, + [TypePair[1], PointerType<VolatileType<TypePair[0]>, GenericAS>, TypePair[2]]>; + } + } +} //-------------------------------------------------------------------- // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits