[compiler-rt] r236805 - builtins: Implement the functions from stdatomic.h

Justin Bogner mail at justinbogner.com
Thu May 7 22:39:06 PDT 2015


Author: bogner
Date: Fri May  8 00:39:05 2015
New Revision: 236805

URL: http://llvm.org/viewvc/llvm-project?rev=236805&view=rev
Log:
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.

Added:
    compiler-rt/trunk/lib/builtins/atomic_flag_clear.c
    compiler-rt/trunk/lib/builtins/atomic_flag_clear_explicit.c
    compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set.c
    compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set_explicit.c
    compiler-rt/trunk/lib/builtins/atomic_signal_fence.c
    compiler-rt/trunk/lib/builtins/atomic_thread_fence.c
Modified:
    compiler-rt/trunk/make/platform/clang_darwin.mk
    compiler-rt/trunk/make/platform/clang_macho_embedded.mk
    compiler-rt/trunk/make/platform/darwin_bni.mk

Added: compiler-rt/trunk/lib/builtins/atomic_flag_clear.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/atomic_flag_clear.c?rev=236805&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/atomic_flag_clear.c (added)
+++ compiler-rt/trunk/lib/builtins/atomic_flag_clear.c Fri May  8 00:39:05 2015
@@ -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);
+}

Added: compiler-rt/trunk/lib/builtins/atomic_flag_clear_explicit.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/atomic_flag_clear_explicit.c?rev=236805&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/atomic_flag_clear_explicit.c (added)
+++ compiler-rt/trunk/lib/builtins/atomic_flag_clear_explicit.c Fri May  8 00:39:05 2015
@@ -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);
+}

Added: compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set.c?rev=236805&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set.c (added)
+++ compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set.c Fri May  8 00:39:05 2015
@@ -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);
+}

Added: compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set_explicit.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set_explicit.c?rev=236805&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set_explicit.c (added)
+++ compiler-rt/trunk/lib/builtins/atomic_flag_test_and_set_explicit.c Fri May  8 00:39:05 2015
@@ -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);
+}

Added: compiler-rt/trunk/lib/builtins/atomic_signal_fence.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/atomic_signal_fence.c?rev=236805&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/atomic_signal_fence.c (added)
+++ compiler-rt/trunk/lib/builtins/atomic_signal_fence.c Fri May  8 00:39:05 2015
@@ -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);
+}

Added: compiler-rt/trunk/lib/builtins/atomic_thread_fence.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/atomic_thread_fence.c?rev=236805&view=auto
==============================================================================
--- compiler-rt/trunk/lib/builtins/atomic_thread_fence.c (added)
+++ compiler-rt/trunk/lib/builtins/atomic_thread_fence.c Fri May  8 00:39:05 2015
@@ -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);
+}

Modified: compiler-rt/trunk/make/platform/clang_darwin.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_darwin.mk?rev=236805&r1=236804&r2=236805&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
+++ compiler-rt/trunk/make/platform/clang_darwin.mk Fri May  8 00:39:05 2015
@@ -255,17 +255,26 @@ CFLAGS.ubsan_osx_dynamic += -isysroot $(
 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 \

Modified: compiler-rt/trunk/make/platform/clang_macho_embedded.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_macho_embedded.mk?rev=236805&r1=236804&r2=236805&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_macho_embedded.mk (original)
+++ compiler-rt/trunk/make/platform/clang_macho_embedded.mk Fri May  8 00:39:05 2015
@@ -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 \

Modified: compiler-rt/trunk/make/platform/darwin_bni.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/darwin_bni.mk?rev=236805&r1=236804&r2=236805&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/darwin_bni.mk (original)
+++ compiler-rt/trunk/make/platform/darwin_bni.mk Fri May  8 00:39:05 2015
@@ -47,7 +47,10 @@ FUNCTIONS := absvdi2 absvsi2 addvdi3 add
              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





More information about the llvm-commits mailing list