summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven van Haastregt <sven.vanhaastregt@arm.com>2019-12-23 12:29:01 +0000
committerSven van Haastregt <sven.vanhaastregt@arm.com>2019-12-23 12:29:01 +0000
commitb714583fd09683458be9eb03a9faef656a8ccf49 (patch)
tree712f05e9c6aa40bdc6a83033bfb86cd565ba8231
parent40bd809b6d5cfe69ffcb567245bc521b971a80eb (diff)
downloadbcm5719-llvm-b714583fd09683458be9eb03a9faef656a8ccf49.tar.gz
bcm5719-llvm-b714583fd09683458be9eb03a9faef656a8ccf49.zip
[OpenCL] Add atomic builtin functions
Add atomic builtin functions from the OpenCL C specification. Patch by Pierre Gondois and Sven van Haastregt.
-rw-r--r--clang/lib/Sema/OpenCLBuiltins.td79
-rw-r--r--clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl10
2 files changed, 87 insertions, 2 deletions
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 37f31782393..38e07b21cb8 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -55,6 +55,10 @@ def FuncExtNone : FunctionExtension<"">;
def FuncExtKhrSubgroups : FunctionExtension<"cl_khr_subgroups">;
def FuncExtKhrGlobalInt32BaseAtomics : FunctionExtension<"cl_khr_global_int32_base_atomics">;
def FuncExtKhrGlobalInt32ExtendedAtomics : FunctionExtension<"cl_khr_global_int32_extended_atomics">;
+def FuncExtKhrLocalInt32BaseAtomics : FunctionExtension<"cl_khr_local_int32_base_atomics">;
+def FuncExtKhrLocalInt32ExtendedAtomics : FunctionExtension<"cl_khr_local_int32_extended_atomics">;
+def FuncExtKhrInt64BaseAtomics : FunctionExtension<"cl_khr_int64_base_atomics">;
+def FuncExtKhrInt64ExtendedAtomics : FunctionExtension<"cl_khr_int64_extended_atomics">;
// Qualified Type. These map to ASTContext::QualType.
class QualType<string _Name, bit _IsAbstract=0> {
@@ -892,6 +896,81 @@ let Extension = FuncExtKhrGlobalInt32BaseAtomics in {
}
}
}
+// --- Table 9.3 ---
+let Extension = FuncExtKhrLocalInt32BaseAtomics in {
+ foreach Type = [Int, UInt] in {
+ foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
+ }
+ foreach name = ["atom_inc", "atom_dec"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>]>;
+ }
+ foreach name = ["atom_cmpxchg"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type, Type]>;
+ }
+ }
+}
+// --- Table 9.5 ---
+let Extension = FuncExtKhrInt64BaseAtomics in {
+ foreach AS = [GlobalAS, LocalAS] in {
+ foreach Type = [Long, ULong] in {
+ foreach name = ["atom_add", "atom_sub", "atom_xchg"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
+ }
+ foreach name = ["atom_inc", "atom_dec"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
+ }
+ foreach name = ["atom_cmpxchg"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
+ }
+ }
+ }
+}
+// --- Table 9.2 ---
+let Extension = FuncExtKhrGlobalInt32ExtendedAtomics in {
+ foreach Type = [Int, UInt] in {
+ foreach name = ["atom_min", "atom_max", "atom_and",
+ "atom_or", "atom_xor"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, GlobalAS>, Type]>;
+ }
+ }
+}
+// --- Table 9.4 ---
+let Extension = FuncExtKhrLocalInt32ExtendedAtomics in {
+ foreach Type = [Int, UInt] in {
+ foreach name = ["atom_min", "atom_max", "atom_and",
+ "atom_or", "atom_xor"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, LocalAS>, Type]>;
+ }
+ }
+}
+// --- Table 9.6 ---
+let Extension = FuncExtKhrInt64ExtendedAtomics in {
+ foreach AS = [GlobalAS, LocalAS] in {
+ foreach Type = [Long, ULong] in {
+ foreach name = ["atom_min", "atom_max", "atom_and",
+ "atom_or", "atom_xor"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
+ }
+ }
+ }
+}
+// OpenCL v1.1 s6.11.1, v1.2 s6.12.11 - Atomic Functions
+foreach AS = [GlobalAS, LocalAS] in {
+ foreach Type = [Int, UInt] in {
+ foreach name = ["atomic_add", "atomic_sub", "atomic_xchg",
+ "atomic_min", "atomic_max", "atomic_and",
+ "atomic_or", "atomic_xor"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type]>;
+ }
+ foreach name = ["atomic_inc", "atomic_dec"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>]>;
+ }
+ foreach name = ["atomic_cmpxchg"] in {
+ def : Builtin<name, [Type, PointerType<VolatileType<Type>, AS>, Type, Type]>;
+ }
+ }
+}
//--------------------------------------------------------------------
// OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
diff --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 000f96278fa..dd89f40761c 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -44,8 +44,14 @@ kernel void test_pointers(volatile global void *global_p, global const int4 *a)
// There are two potential definitions of the function "atom_add", both are
// currently disabled because the associated extension is disabled.
-// expected-note@-6{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
-// expected-note@-7{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
+// expected-note@-6{{candidate function not viable: cannot pass pointer to address space '__global' as a pointer to address space '__local' in 1st argument}}
+// expected-note@-7{{candidate function not viable: no known conversion}}
+// expected-note@-8{{candidate function not viable: no known conversion}}
+// expected-note@-9{{candidate function not viable: no known conversion}}
+// expected-note@-10{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
+// expected-note@-11{{candidate unavailable as it requires OpenCL extension 'cl_khr_global_int32_base_atomics' to be enabled}}
+// expected-note@-12{{candidate unavailable as it requires OpenCL extension 'cl_khr_int64_base_atomics' to be enabled}}
+// expected-note@-13{{candidate unavailable as it requires OpenCL extension 'cl_khr_int64_base_atomics' to be enabled}}
#endif
#if __OPENCL_C_VERSION__ < CL_VERSION_1_1
OpenPOWER on IntegriCloud