From a86037084d8c2338c305533807b3213cfdc47a3e Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 19 May 2009 22:18:56 +0000 Subject: [PATCH] Split the ENABLE_THREADS #define in two. Now ENABLE_THREADS indicates the ability to run multiple threads at once in the JIT, and requires only mutex support. LLVM_MULTITHREADED indicates (or will indicate) the ability to run LLVM itself across multiple threads, and requires atomics support. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72140 91177308-0d34-0410-b5e6-96231b3b80d8 --- autoconf/configure.ac | 33 ++++++++--------- configure | 88 +++++++++++++++++++++++--------------------- include/llvm/System/Atomic.h | 12 ++---- 3 files changed, 66 insertions(+), 67 deletions(-) diff --git a/autoconf/configure.ac b/autoconf/configure.ac index 56853e96bf1..7f625d4bed1 100644 --- a/autoconf/configure.ac +++ b/autoconf/configure.ac @@ -372,6 +372,7 @@ case "$enableval" in default) AC_SUBST(ENABLE_THREADS,[1]) ;; *) AC_MSG_ERROR([Invalid setting for --enable-threads. Use "yes" or "no"]) ;; esac +AC_DEFINE_UNQUOTED([ENABLE_THREADS],$ENABLE_THREADS,[Define if threads enabled]) dnl Allow building without position independent code AC_ARG_ENABLE(pic, @@ -897,24 +898,22 @@ if test "$llvm_cv_platform_type" = "Unix" ; then fi dnl atomic builtins are required for threading support. -if test "$ENABLE_THREADS" -eq 1 ; then - AC_MSG_CHECKING(for GCC atomic builtins) - AC_LINK_IFELSE( - AC_LANG_SOURCE( - [[int main() { - volatile unsigned long val = 1; - __sync_synchronize(); - __sync_val_compare_and_swap(&val, 1, 0); - return 0; - } - ]]), - AC_MSG_RESULT(yes), - AC_MSG_RESULT(no) - AC_SUBST(ENABLE_THREADS, [0]) - AC_MSG_WARN([Threading support disabled because atomic builtins are missing])) -fi +AC_MSG_CHECKING(for GCC atomic builtins) +AC_LINK_IFELSE( + AC_LANG_SOURCE( + [[int main() { + volatile unsigned long val = 1; + __sync_synchronize(); + __sync_val_compare_and_swap(&val, 1, 0); + return 0; + } + ]]), + AC_MSG_RESULT(yes) + AC_DEFINE(LLVM_MULTITHREADED, 1, Build multithreading support into LLVM), + AC_MSG_RESULT(no) + AC_DEFINE(LLVM_MULTITHREADED, 0, Build multithreading support into LLVM) + AC_MSG_WARN([LLVM will be built thread-unsafe because atomic builtins are missing])) -AC_DEFINE_UNQUOTED([ENABLE_THREADS],$ENABLE_THREADS,[Define if threads enabled]) dnl===-----------------------------------------------------------------------=== dnl=== diff --git a/configure b/configure index 20e3b4fa303..1179524853f 100755 --- a/configure +++ b/configure @@ -4870,6 +4870,11 @@ echo "$as_me: error: Invalid setting for --enable-threads. Use \"yes\" or \"no\" { (exit 1); exit 1; }; } ;; esac +cat >>confdefs.h <<_ACEOF +#define ENABLE_THREADS $ENABLE_THREADS +_ACEOF + + # Check whether --enable-pic was given. if test "${enable_pic+set}" = set; then enableval=$enable_pic; @@ -10570,7 +10575,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext + echo '#line 12722 "configure"' > conftest.$ac_ext if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5 (eval $ac_compile) 2>&5 ac_status=$? @@ -14432,11 +14437,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14435: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14440: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:14439: \$? = $ac_status" >&5 + echo "$as_me:14444: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -14700,11 +14705,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14703: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14708: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:14707: \$? = $ac_status" >&5 + echo "$as_me:14712: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -14804,11 +14809,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:14807: $lt_compile\"" >&5) + (eval echo "\"\$as_me:14812: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:14811: \$? = $ac_status" >&5 + echo "$as_me:14816: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -17256,7 +17261,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext < conftest.$ac_ext <&5) + (eval echo "\"\$as_me:19732: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:19731: \$? = $ac_status" >&5 + echo "$as_me:19736: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -19828,11 +19833,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:19831: $lt_compile\"" >&5) + (eval echo "\"\$as_me:19836: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:19835: \$? = $ac_status" >&5 + echo "$as_me:19840: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -21398,11 +21403,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:21401: $lt_compile\"" >&5) + (eval echo "\"\$as_me:21406: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:21405: \$? = $ac_status" >&5 + echo "$as_me:21410: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -21502,11 +21507,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:21505: $lt_compile\"" >&5) + (eval echo "\"\$as_me:21510: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:21509: \$? = $ac_status" >&5 + echo "$as_me:21514: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -23737,11 +23742,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:23740: $lt_compile\"" >&5) + (eval echo "\"\$as_me:23745: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:23744: \$? = $ac_status" >&5 + echo "$as_me:23749: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -24005,11 +24010,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:24008: $lt_compile\"" >&5) + (eval echo "\"\$as_me:24013: $lt_compile\"" >&5) (eval "$lt_compile" 2>conftest.err) ac_status=$? cat conftest.err >&5 - echo "$as_me:24012: \$? = $ac_status" >&5 + echo "$as_me:24017: \$? = $ac_status" >&5 if (exit $ac_status) && test -s "$ac_outfile"; then # The compiler can only warn and ignore the option if not recognized # So say no if there are warnings other than the usual output. @@ -24109,11 +24114,11 @@ else -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \ -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \ -e 's:$: $lt_compiler_flag:'` - (eval echo "\"\$as_me:24112: $lt_compile\"" >&5) + (eval echo "\"\$as_me:24117: $lt_compile\"" >&5) (eval "$lt_compile" 2>out/conftest.err) ac_status=$? cat out/conftest.err >&5 - echo "$as_me:24116: \$? = $ac_status" >&5 + echo "$as_me:24121: \$? = $ac_status" >&5 if (exit $ac_status) && test -s out/conftest2.$ac_objext then # The compiler can only warn and ignore the option if not recognized @@ -33602,21 +33607,20 @@ echo "$as_me: WARNING: mmap() of files required but not found" >&2;} fi fi -if test "$ENABLE_THREADS" -eq 1 ; then - { echo "$as_me:$LINENO: checking for GCC atomic builtins" >&5 +{ echo "$as_me:$LINENO: checking for GCC atomic builtins" >&5 echo $ECHO_N "checking for GCC atomic builtins... $ECHO_C" >&6; } - cat >conftest.$ac_ext <<_ACEOF +cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ int main() { - volatile unsigned long val = 1; - __sync_synchronize(); - __sync_val_compare_and_swap(&val, 1, 0); - return 0; - } + volatile unsigned long val = 1; + __sync_synchronize(); + __sync_val_compare_and_swap(&val, 1, 0); + return 0; + } _ACEOF rm -f conftest.$ac_objext conftest$ac_exeext @@ -33655,26 +33659,28 @@ eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 (exit $ac_status); }; }; then { echo "$as_me:$LINENO: result: yes" >&5 echo "${ECHO_T}yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define LLVM_MULTITHREADED 1 +_ACEOF + else echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { echo "$as_me:$LINENO: result: no" >&5 echo "${ECHO_T}no" >&6; } - ENABLE_THREADS=0 - { echo "$as_me:$LINENO: WARNING: Threading support disabled because atomic builtins are missing" >&5 -echo "$as_me: WARNING: Threading support disabled because atomic builtins are missing" >&2;} +cat >>confdefs.h <<\_ACEOF +#define LLVM_MULTITHREADED 0 +_ACEOF + + { echo "$as_me:$LINENO: WARNING: LLVM will be built thread-unsafe because atomic builtins are missing" >&5 +echo "$as_me: WARNING: LLVM will be built thread-unsafe because atomic builtins are missing" >&2;} fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext -fi - - -cat >>confdefs.h <<_ACEOF -#define ENABLE_THREADS $ENABLE_THREADS -_ACEOF diff --git a/include/llvm/System/Atomic.h b/include/llvm/System/Atomic.h index 5830b37083b..38388a4b28a 100644 --- a/include/llvm/System/Atomic.h +++ b/include/llvm/System/Atomic.h @@ -23,14 +23,8 @@ namespace llvm { namespace sys { inline void MemoryFence() { -#if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0 -# if defined(__GNUC__) - __asm__ __volatile__("" : : : "memory"); -# elif defined(_MSC_VER) - __asm { }; -# else -# error No memory fence implementation for your platform! -# endif +#if LLVM_MULTITHREADED==0 + return; #else # if defined(__GNUC__) __sync_synchronize(); @@ -42,7 +36,7 @@ namespace llvm { #endif } -#if !defined(ENABLE_THREADS) || ENABLE_THREADS == 0 +#if LLVM_MULTITHREADED==0 typedef unsigned long cas_flag; template inline T CompareAndSwap(volatile T* dest, -- 2.11.0