Skip to content

Commit 9c26f37

Browse files
authored
[libclc] Add generic implementation of some atomic functions in OpenCL spec section 6.15.12.7 (#146814)
Add corresponding clc functions, which are implemented with clang __scoped_atomic builtins. OpenCL functions are implemented as a wrapper over clc functions. Also change legacy atomic_inc and atomic_dec to re-use the newly added clc_atomic_inc/dec implementations. llvm-diff only no change to atomic_inc and atomic_dec in bitcode. Notes: * Generic OpenCL built-ins functions uses __ATOMIC_SEQ_CST and __MEMORY_SCOPE_DEVICE for memory order and memory scope parameters. * OpenCL atomic_*_explicit, atomic_flag* built-ins are not implemented yet. * OpenCL built-ins of atomic_intptr_t, atomic_uintptr_t, atomic_size_t and atomic_ptrdiff_t types are not implemented yet. * llvm-diff shows no change to nvptx64--nvidiacl.bc and amdgcn--amdhsa.bc since __opencl_c_atomic_order_seq_cst and __opencl_c_atomic_scope_device are not defined in these two targets.
1 parent 64205ad commit 9c26f37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1511
-43
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// MemoryOrder is memory order supported by Clang __scoped_atomic* builtins.
10+
// MemoryScope is memory scope supported by Clang __scoped_atomic* builtins.
11+
12+
#ifdef __CLC_SCALAR
13+
#if defined(__CLC_FPSIZE) || (__CLC_GENSIZE >= 32)
14+
15+
#ifdef __CLC_NO_VALUE_ARG
16+
#define __CLC_DECLARE_ATOMIC(ADDRSPACE) \
17+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION( \
18+
volatile ADDRSPACE __CLC_GENTYPE *Ptr, int MemoryOrder, \
19+
int MemoryScope);
20+
#elif defined(__CLC_RETURN_VOID)
21+
#define __CLC_DECLARE_ATOMIC(ADDRSPACE) \
22+
_CLC_OVERLOAD _CLC_DECL void FUNCTION(volatile ADDRSPACE __CLC_GENTYPE *Ptr, \
23+
__CLC_GENTYPE Value, int MemoryOrder, \
24+
int MemoryScope);
25+
#elif defined(__CLC_COMPARE_EXCHANGE)
26+
#define __CLC_DECLARE_ATOMIC(ADDRSPACE) \
27+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION( \
28+
volatile ADDRSPACE __CLC_GENTYPE *Ptr, __CLC_GENTYPE Comparator, \
29+
__CLC_GENTYPE Value, int MemoryOrderEqual, int MemoryOrderUnequal, \
30+
int MemoryScope);
31+
#else
32+
#define __CLC_DECLARE_ATOMIC(ADDRSPACE) \
33+
_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE FUNCTION( \
34+
volatile ADDRSPACE __CLC_GENTYPE *Ptr, __CLC_GENTYPE Value, \
35+
int MemoryOrder, int MemoryScope);
36+
#endif
37+
38+
__CLC_DECLARE_ATOMIC(global)
39+
__CLC_DECLARE_ATOMIC(local)
40+
#if _CLC_GENERIC_AS_SUPPORTED
41+
__CLC_DECLARE_ATOMIC()
42+
#endif
43+
44+
#undef __CLC_DECLARE_ATOMIC
45+
46+
#endif // defined(__CLC_FPSIZE) || (__CLC_GENSIZE >= 32)
47+
#endif // __CLC_SCALAR
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_COMPARE_EXCHANGE_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_COMPARE_EXCHANGE_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_compare_exchange
15+
#define __CLC_COMPARE_EXCHANGE
16+
17+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
18+
#include <clc/integer/gentype.inc>
19+
20+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
21+
#include <clc/math/gentype.inc>
22+
23+
#undef __CLC_COMPARE_EXCHANGE
24+
#undef FUNCTION
25+
26+
#endif // __CLC_ATOMIC_CLC_ATOMIC_COMPARE_EXCHANGE_H__
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_DEC_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_DEC_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_dec
15+
#define __CLC_NO_VALUE_ARG
16+
17+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
18+
#include <clc/integer/gentype.inc>
19+
20+
#undef __CLC_NO_VALUE_ARG
21+
#undef FUNCTION
22+
23+
#endif // __CLC_ATOMIC_CLC_ATOMIC_DEC_H__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_EXCHANGE_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_EXCHANGE_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_exchange
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef FUNCTION
23+
24+
#endif // __CLC_ATOMIC_CLC_ATOMIC_EXCHANGE_H__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_FETCH_ADD_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_FETCH_ADD_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_fetch_add
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef FUNCTION
23+
24+
#endif // __CLC_ATOMIC_CLC_ATOMIC_FETCH_ADD_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_FETCH_AND_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_FETCH_AND_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_fetch_and
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#undef FUNCTION
20+
21+
#endif // __CLC_ATOMIC_CLC_ATOMIC_FETCH_AND_H__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_FETCH_MAX_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_FETCH_MAX_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_fetch_max
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef FUNCTION
23+
24+
#endif // __CLC_ATOMIC_CLC_ATOMIC_FETCH_MAX_H__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_FETCH_MIN_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_FETCH_MIN_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_fetch_min
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef FUNCTION
23+
24+
#endif // __CLC_ATOMIC_CLC_ATOMIC_FETCH_MIN_H__
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_FETCH_OR_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_FETCH_OR_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_fetch_or
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#undef FUNCTION
20+
21+
#endif // __CLC_ATOMIC_CLC_ATOMIC_FETCH_OR_H__
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef __CLC_ATOMIC_CLC_ATOMIC_FETCH_SUB_H__
10+
#define __CLC_ATOMIC_CLC_ATOMIC_FETCH_SUB_H__
11+
12+
#include <clc/internal/clc.h>
13+
14+
#define FUNCTION __clc_atomic_fetch_sub
15+
16+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
17+
#include <clc/integer/gentype.inc>
18+
19+
#define __CLC_BODY <clc/atomic/atomic_decl.inc>
20+
#include <clc/math/gentype.inc>
21+
22+
#undef FUNCTION
23+
24+
#endif // __CLC_ATOMIC_CLC_ATOMIC_FETCH_SUB_H__

0 commit comments

Comments
 (0)