From 31fa3a4d44316fd36e11f92729ea9596ee3bf3f8 Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Fri, 4 Feb 2022 10:17:48 +0000 Subject: [PATCH] [OpenCL] Move OpenCL 2.0 atomics into multiclass; NFC This is in preparation for adding the OpenCL 3.0 builtins with named address space arguments. --- clang/lib/Sema/OpenCLBuiltins.td | 42 +++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td index 5166536..08f8630 100644 --- a/clang/lib/Sema/OpenCLBuiltins.td +++ b/clang/lib/Sema/OpenCLBuiltins.td @@ -1040,6 +1040,8 @@ let Extension = FuncExtOpenCLCxx in { } } +// OpenCL v2.0 s6.13.11 - Atomic Functions. + // An atomic builtin with 2 additional _explicit variants. multiclass BuiltinAtomicExplicit Types> { // Without explicit MemoryOrder or MemoryScope. @@ -1052,31 +1054,29 @@ multiclass BuiltinAtomicExplicit Types> { def : Builtin; } -// OpenCL v2.0 s6.13.11 - Atomic Functions. -let MinVersion = CL20 in { - def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>; - +// OpenCL 2.0 atomic functions that have a pointer argument in a given address space. +multiclass OpenCL2Atomics { foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt], [AtomicLong, Long], [AtomicULong, ULong], [AtomicFloat, Float], [AtomicDouble, Double]] in { def : Builtin<"atomic_init", - [Void, PointerType, GenericAS>, TypePair[1]]>; + [Void, PointerType, addrspace>, TypePair[1]]>; defm : BuiltinAtomicExplicit<"atomic_store", - [Void, PointerType, GenericAS>, TypePair[1]]>; + [Void, PointerType, addrspace>, TypePair[1]]>; defm : BuiltinAtomicExplicit<"atomic_load", - [TypePair[1], PointerType, GenericAS>]>; + [TypePair[1], PointerType, addrspace>]>; defm : BuiltinAtomicExplicit<"atomic_exchange", - [TypePair[1], PointerType, GenericAS>, TypePair[1]]>; + [TypePair[1], PointerType, addrspace>, TypePair[1]]>; foreach Variant = ["weak", "strong"] in { def : Builtin<"atomic_compare_exchange_" # Variant, - [Bool, PointerType, GenericAS>, - PointerType, TypePair[1]]>; + [Bool, PointerType, addrspace>, + PointerType, TypePair[1]]>; def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit", - [Bool, PointerType, GenericAS>, - PointerType, TypePair[1], MemoryOrder, MemoryOrder]>; + [Bool, PointerType, addrspace>, + PointerType, TypePair[1], MemoryOrder, MemoryOrder]>; def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit", - [Bool, PointerType, GenericAS>, - PointerType, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>; + [Bool, PointerType, addrspace>, + PointerType, TypePair[1], MemoryOrder, MemoryOrder, MemoryScope]>; } } @@ -1085,22 +1085,28 @@ let MinVersion = CL20 in { [AtomicUIntPtr, UIntPtr, PtrDiff]] in { foreach ModOp = ["add", "sub"] in { defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp, - [TypePair[1], PointerType, GenericAS>, TypePair[2]]>; + [TypePair[1], PointerType, addrspace>, TypePair[2]]>; } } foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt], [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] in { foreach ModOp = ["or", "xor", "and", "min", "max"] in { defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp, - [TypePair[1], PointerType, GenericAS>, TypePair[2]]>; + [TypePair[1], PointerType, addrspace>, TypePair[2]]>; } } defm : BuiltinAtomicExplicit<"atomic_flag_clear", - [Void, PointerType, GenericAS>]>; + [Void, PointerType, addrspace>]>; defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set", - [Bool, PointerType, GenericAS>]>; + [Bool, PointerType, addrspace>]>; +} + +let MinVersion = CL20 in { + def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, MemoryScope]>; + + defm : OpenCL2Atomics; } // The functionality added by cl_ext_float_atomics extension -- 2.7.4