summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2015-05-08 05:39:05 +0000
committerJustin Bogner <mail@justinbogner.com>2015-05-08 05:39:05 +0000
commit0c904ece562d5c6f9df57e42b56dd5533db7d2bb (patch)
tree4bb926b34dba3234113d0dea992824309fcd7ea9
parent49afa2c4e79b8840de86ce633b12e3380c7c2801 (diff)
builtins: Implement the functions from stdatomic.h
Talking to John and Doug, we concluded that these functions from stdatomic really do belong here in compiler-rt rather than in libc, since the compiler owns stdatomic.h and these need to refer to clang-specific builtins. Nonetheless, I've only added these on darwin for now - other platforms should probably do the same unless their libc does implement these functions. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@236805 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/builtins/atomic_flag_clear.c19
-rw-r--r--lib/builtins/atomic_flag_clear_explicit.c20
-rw-r--r--lib/builtins/atomic_flag_test_and_set.c19
-rw-r--r--lib/builtins/atomic_flag_test_and_set_explicit.c20
-rw-r--r--lib/builtins/atomic_signal_fence.c19
-rw-r--r--lib/builtins/atomic_thread_fence.c19
-rw-r--r--make/platform/clang_darwin.mk15
-rw-r--r--make/platform/clang_macho_embedded.mk8
-rw-r--r--make/platform/darwin_bni.mk12
9 files changed, 144 insertions, 7 deletions
diff --git a/lib/builtins/atomic_flag_clear.c b/lib/builtins/atomic_flag_clear.c
new file mode 100644
index 000000000..15984cd52
--- /dev/null
+++ b/lib/builtins/atomic_flag_clear.c
@@ -0,0 +1,19 @@
+/*===-- atomic_flag_clear.c -------------------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ *===------------------------------------------------------------------------===
+ *
+ * This file implements atomic_flag_clear from C11's stdatomic.h.
+ *
+ *===------------------------------------------------------------------------===
+ */
+
+#include <stdatomic.h>
+#undef atomic_flag_clear
+void atomic_flag_clear(volatile atomic_flag *object) {
+ return __c11_atomic_store(&(object)->_Value, 0, __ATOMIC_SEQ_CST);
+}
diff --git a/lib/builtins/atomic_flag_clear_explicit.c b/lib/builtins/atomic_flag_clear_explicit.c
new file mode 100644
index 000000000..0f7859c2c
--- /dev/null
+++ b/lib/builtins/atomic_flag_clear_explicit.c
@@ -0,0 +1,20 @@
+/*===-- atomic_flag_clear_explicit.c ----------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ *===------------------------------------------------------------------------===
+ *
+ * This file implements atomic_flag_clear_explicit from C11's stdatomic.h.
+ *
+ *===------------------------------------------------------------------------===
+ */
+
+#include <stdatomic.h>
+#undef atomic_flag_clear_explicit
+void atomic_flag_clear_explicit(volatile atomic_flag *object,
+ memory_order order) {
+ return __c11_atomic_store(&(object)->_Value, 0, order);
+}
diff --git a/lib/builtins/atomic_flag_test_and_set.c b/lib/builtins/atomic_flag_test_and_set.c
new file mode 100644
index 000000000..07209fc02
--- /dev/null
+++ b/lib/builtins/atomic_flag_test_and_set.c
@@ -0,0 +1,19 @@
+/*===-- atomic_flag_test_and_set.c ------------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ *===------------------------------------------------------------------------===
+ *
+ * This file implements atomic_flag_test_and_set from C11's stdatomic.h.
+ *
+ *===------------------------------------------------------------------------===
+ */
+
+#include <stdatomic.h>
+#undef atomic_flag_test_and_set
+_Bool atomic_flag_test_and_set(volatile atomic_flag *object) {
+ return __c11_atomic_exchange(&(object)->_Value, 1, __ATOMIC_SEQ_CST);
+}
diff --git a/lib/builtins/atomic_flag_test_and_set_explicit.c b/lib/builtins/atomic_flag_test_and_set_explicit.c
new file mode 100644
index 000000000..eaa5be08d
--- /dev/null
+++ b/lib/builtins/atomic_flag_test_and_set_explicit.c
@@ -0,0 +1,20 @@
+/*===-- atomic_flag_test_and_set_explicit.c ---------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ *===------------------------------------------------------------------------===
+ *
+ * This file implements atomic_flag_test_and_set_explicit from C11's stdatomic.h
+ *
+ *===------------------------------------------------------------------------===
+ */
+
+#include <stdatomic.h>
+#undef atomic_flag_test_and_set_explicit
+_Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *object,
+ memory_order order) {
+ return __c11_atomic_exchange(&(object)->_Value, 1, order);
+}
diff --git a/lib/builtins/atomic_signal_fence.c b/lib/builtins/atomic_signal_fence.c
new file mode 100644
index 000000000..ad292d2f1
--- /dev/null
+++ b/lib/builtins/atomic_signal_fence.c
@@ -0,0 +1,19 @@
+/*===-- atomic_signal_fence.c -----------------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ *===------------------------------------------------------------------------===
+ *
+ * This file implements atomic_signal_fence from C11's stdatomic.h.
+ *
+ *===------------------------------------------------------------------------===
+ */
+
+#include <stdatomic.h>
+#undef atomic_signal_fence
+void atomic_signal_fence(memory_order order) {
+ __c11_atomic_signal_fence(order);
+}
diff --git a/lib/builtins/atomic_thread_fence.c b/lib/builtins/atomic_thread_fence.c
new file mode 100644
index 000000000..71f698c9d
--- /dev/null
+++ b/lib/builtins/atomic_thread_fence.c
@@ -0,0 +1,19 @@
+/*===-- atomic_thread_fence.c -----------------------------------------------===
+ *
+ * The LLVM Compiler Infrastructure
+ *
+ * This file is dual licensed under the MIT and the University of Illinois Open
+ * Source Licenses. See LICENSE.TXT for details.
+ *
+ *===------------------------------------------------------------------------===
+ *
+ * This file implements atomic_thread_fence from C11's stdatomic.h.
+ *
+ *===------------------------------------------------------------------------===
+ */
+
+#include <stdatomic.h>
+#undef atomic_thread_fence
+void atomic_thread_fence(memory_order order) {
+ __c11_atomic_thread_fence(order);
+}
diff --git a/make/platform/clang_darwin.mk b/make/platform/clang_darwin.mk
index 21d12a801..9295edea5 100644
--- a/make/platform/clang_darwin.mk
+++ b/make/platform/clang_darwin.mk
@@ -255,17 +255,26 @@ CFLAGS.ubsan_osx_dynamic += -isysroot $(OSX_SDK)
LDFLAGS.ubsan_osx_dynamic += -isysroot $(OSX_SDK)
endif
+ATOMIC_FUNCTIONS := \
+ atomic_flag_clear \
+ atomic_flag_clear_explicit \
+ atomic_flag_test_and_set \
+ atomic_flag_test_and_set_explicit \
+ atomic_signal_fence \
+ atomic_thread_fence
+
FUNCTIONS.eprintf := eprintf
FUNCTIONS.10.4 := eprintf floatundidf floatundisf floatundixf
-FUNCTIONS.ios := divmodsi4 udivmodsi4 mulosi4 mulodi4 muloti4
+FUNCTIONS.ios := divmodsi4 udivmodsi4 mulosi4 mulodi4 muloti4 \
+ $(ATOMIC_FUNCTIONS)
# On x86, the divmod functions reference divsi.
FUNCTIONS.ios.i386 := $(FUNCTIONS.ios) \
divsi3 udivsi3
FUNCTIONS.ios.x86_64 := $(FUNCTIONS.ios.i386)
-FUNCTIONS.ios.arm64 := mulsc3 muldc3 divsc3 divdc3
+FUNCTIONS.ios.arm64 := mulsc3 muldc3 divsc3 divdc3 $(ATOMIC_FUNCTIONS)
-FUNCTIONS.osx := mulosi4 mulodi4 muloti4
+FUNCTIONS.osx := mulosi4 mulodi4 muloti4 $(ATOMIC_FUNCTIONS)
FUNCTIONS.profile_osx := GCDAProfiling InstrProfiling InstrProfilingBuffer \
InstrProfilingFile InstrProfilingPlatformDarwin \
diff --git a/make/platform/clang_macho_embedded.mk b/make/platform/clang_macho_embedded.mk
index 76e43e66c..77885d574 100644
--- a/make/platform/clang_macho_embedded.mk
+++ b/make/platform/clang_macho_embedded.mk
@@ -176,7 +176,13 @@ COMMON_FUNCTIONS := \
udivsi3 \
umodsi3 \
unorddf2 \
- unordsf2
+ unordsf2 \
+ atomic_flag_clear \
+ atomic_flag_clear_explicit \
+ atomic_flag_test_and_set \
+ atomic_flag_test_and_set_explicit \
+ atomic_signal_fence \
+ atomic_thread_fence
ARM_FUNCTIONS := \
aeabi_cdcmpeq \
diff --git a/make/platform/darwin_bni.mk b/make/platform/darwin_bni.mk
index 2fd5089ba..b4c57d4cc 100644
--- a/make/platform/darwin_bni.mk
+++ b/make/platform/darwin_bni.mk
@@ -47,7 +47,10 @@ FUNCTIONS := absvdi2 absvsi2 addvdi3 addvsi3 ashldi3 ashrdi3 \
mulodi4 muloti4 mulsc3 mulvdi3 mulvsi3 negdi2 negvdi2 negvsi2 \
paritydi2 paritysi2 popcountdi2 popcountsi2 powidf2 \
powisf2 subvdi3 subvsi3 ucmpdi2 udivdi3 \
- udivmoddi4 umoddi3 apple_versioning eprintf atomic
+ udivmoddi4 umoddi3 apple_versioning eprintf atomic \
+ atomic_flag_clear atomic_flag_clear_explicit \
+ atomic_flag_test_and_set atomic_flag_test_and_set_explicit \
+ atomic_signal_fence atomic_thread_fence
FUNCTIONS.i386 := $(FUNCTIONS) \
divxc3 fixunsxfdi fixunsxfsi fixxfdi floatdixf \
@@ -124,5 +127,8 @@ FUNCTIONS.arm64 := divti3 modti3 \
fixdfti fixsfti \
fixunsdfti fixunssfti fixunssfti \
floattidf floattisf floatuntidf floatuntisf \
- gcc_personality_v0 atomic
-
+ gcc_personality_v0 atomic \
+ atomic_flag_clear atomic_flag_clear_explicit \
+ atomic_flag_test_and_set \
+ atomic_flag_test_and_set_explicit \
+ atomic_signal_fence atomic_thread_fence