From: Owen Anderson Date: Thu, 7 Feb 2013 00:21:34 +0000 (+0000) Subject: Conditionalize constant folding of math intrinsics on the availability of an implemen... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=132ae8b9550d5dda70c0e9dada6cb92d903cb4b7;p=platform%2Fupstream%2Fllvm.git Conditionalize constant folding of math intrinsics on the availability of an implementation on the host. This is a little bit unfortunate, but until someone decides to implement a full libm for APFloat, we don't have a better way to get this functionality. llvm-svn: 174561 --- diff --git a/llvm/autoconf/configure.ac b/llvm/autoconf/configure.ac index c1f2884..ae615df 100644 --- a/llvm/autoconf/configure.ac +++ b/llvm/autoconf/configure.ac @@ -1573,6 +1573,7 @@ dnl===-----------------------------------------------------------------------=== AC_CHECK_FUNCS([backtrace ceilf floorf roundf rintf nearbyintf getcwd ]) AC_CHECK_FUNCS([powf fmodf strtof round ]) +AC_CHECK_FUNCS([log log2 log10 exp exp2]) AC_CHECK_FUNCS([getpagesize getrusage getrlimit setrlimit gettimeofday ]) AC_CHECK_FUNCS([isatty mkdtemp mkstemp ]) AC_CHECK_FUNCS([mktemp posix_spawn pread realpath sbrk setrlimit strdup ]) diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake index b079a07..f077eca 100755 --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -119,6 +119,12 @@ check_symbol_exists(isnan math.h HAVE_ISNAN_IN_MATH_H) check_symbol_exists(ceilf math.h HAVE_CEILF) check_symbol_exists(floorf math.h HAVE_FLOORF) check_symbol_exists(fmodf math.h HAVE_FMODF) +check_symbol_exists(log "math.h cmath" HAVE_LOG) +check_symbol_exists(log2 "math.h cmath" HAVE_LOG2) +check_symbol_exists(log10 "math.h cmath" HAVE_LOG10) +check_symbol_exists(exp "math.h cmath" HAVE_EXP) +check_symbol_exists(exp2 "math.h cmath" HAVE_EXP2) +check_symbol_exists(exp10 "math.h cmath" HAVE_EXP10) if( HAVE_SETJMP_H ) check_symbol_exists(longjmp setjmp.h HAVE_LONGJMP) check_symbol_exists(setjmp setjmp.h HAVE_SETJMP) diff --git a/llvm/configure b/llvm/configure index fc59c4d..a0a33bd 100755 --- a/llvm/configure +++ b/llvm/configure @@ -17366,6 +17366,120 @@ done +for ac_func in log log2 log10 exp exp2 +do +as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` +{ echo "$as_me:$LINENO: checking for $ac_func" >&5 +echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; } +if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +/* Define $ac_func to an innocuous variant, in case declares $ac_func. + For example, HP-UX 11i declares gettimeofday. */ +#define $ac_func innocuous_$ac_func + +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func (); below. + Prefer to if __STDC__ is defined, since + exists even on freestanding compilers. */ + +#ifdef __STDC__ +# include +#else +# include +#endif + +#undef $ac_func + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char $ac_func (); +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined __stub_$ac_func || defined __stub___$ac_func +choke me +#endif + +int +main () +{ +return $ac_func (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && + { ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } && + { ac_try='test -s conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + eval "$as_ac_var=yes" +else + echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + eval "$as_ac_var=no" +fi + +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +ac_res=`eval echo '${'$as_ac_var'}'` + { echo "$as_me:$LINENO: result: $ac_res" >&5 +echo "${ECHO_T}$ac_res" >&6; } +if test `eval echo '${'$as_ac_var'}'` = yes; then + cat >>confdefs.h <<_ACEOF +#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1 +_ACEOF + +fi +done + + + + + + for ac_func in getpagesize getrusage getrlimit setrlimit gettimeofday do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` diff --git a/llvm/include/llvm/Config/config.h.in b/llvm/include/llvm/Config/config.h.in index 5fb4c81..2f9e6ff 100644 --- a/llvm/include/llvm/Config/config.h.in +++ b/llvm/include/llvm/Config/config.h.in @@ -122,6 +122,12 @@ /* Define to 1 if you have the header file. */ #undef HAVE_EXECINFO_H +/* Define to 1 if you have the `exp' function. */ +#undef HAVE_EXP + +/* Define to 1 if you have the `exp2' function. */ +#undef HAVE_EXP2 + /* Define to 1 if you have the header file. */ #undef HAVE_FCNTL_H @@ -225,6 +231,15 @@ the current directory to the dynamic linker search path. */ #undef HAVE_LINK_R +/* Define to 1 if you have the `log' function. */ +#undef HAVE_LOG + +/* Define to 1 if you have the `log10' function. */ +#undef HAVE_LOG10 + +/* Define to 1 if you have the `log2' function. */ +#undef HAVE_LOG2 + /* Define to 1 if you have the `longjmp' function. */ #undef HAVE_LONGJMP diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index e499c73..26e3888 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -1282,16 +1282,26 @@ llvm::ConstantFoldCall(Function *F, ArrayRef Operands, default: break; case Intrinsic::fabs: return ConstantFoldFP(fabs, V, Ty); +#if HAVE_LOG2 case Intrinsic::log2: return ConstantFoldFP(log2, V, Ty); +#endif +#if HAVE_LOG case Intrinsic::log: return ConstantFoldFP(log, V, Ty); +#endif +#if HAVE_LOG10 case Intrinsic::log10: return ConstantFoldFP(log10, V, Ty); +#endif +#if HAVE_EXP case Intrinsic::exp: return ConstantFoldFP(exp, V, Ty); +#endif +#if HAVE_EXP2 case Intrinsic::exp2: return ConstantFoldFP(exp2, V, Ty); +#endif case Intrinsic::floor: return ConstantFoldFP(floor, V, Ty); }