Add configure-time test for latest ISL

Query the isl_config.h macros recently added to ISL. One of it looks for
the ffs (find first set), whose functionality is available in Visual
Studio with _BitScanForward. Also add isl_ffs.c to the source files
which contains the implementation of ffs using _BitScanForward.

Reviewers: grosser
llvm-svn: 242770
This commit is contained in:
Michael Kruse 2015-07-21 12:01:14 +00:00
parent 8d60fac5ba
commit bf5a711e96
2 changed files with 116 additions and 20 deletions

View File

@ -32,6 +32,7 @@ elseif (EXISTS "${ISL_SOURCE_DIR}/gitversion.h")
string(REGEX REPLACE ".*\\\"([^\\\"]*)\\\".*" "\\1" GIT_HEAD_ID "${GITVERSION_H}")
elseif ()
# Unknown revision
# TODO: We could look for a .git and get the revision from HEAD
set(GIT_HEAD_ID "UNKNOWN")
endif ()
@ -45,6 +46,19 @@ set(USE_SMALL_INT_OPT ON)
# Determine compiler characteristics
include(CheckCSourceCompiles)
# Like check_c_source_compiles, but sets the result to either
# 0 (error while compiling) or 1 (compiled successfully)
# Required for compatibility with autotool's AC_CHECK_DECLS
function (check_c_source_compiles_numeric _prog _var)
check_c_source_compiles("${_prog}" "${_var}")
if ("${${_var}}")
set("${_var}" 1 PARENT_SCOPE)
else ()
set("${_var}" 0 PARENT_SCOPE)
endif ()
endfunction ()
check_c_source_compiles("
int func(void) __attribute__((__warn_unused_result__));
int main() { return 0; }
@ -54,30 +68,80 @@ if (HAS_ATTRIBUTE_WARN_UNUSED_RESULT)
set(GCC_WARN_UNUSED_RESULT "__attribute__((__warn_unused_result__))")
endif ()
check_c_source_compiles("
#include <strings.h>
int main() { ffs(0); return 0; }
" HAVE_DECL_FFS)
if (NOT HAVE_DECL_FFS)
set(HAVE_DECL_FFS 0)
endif ()
check_c_source_compiles("
int main() { __builtin_ffs(0); return 0; }
" HAVE_DECL___BUILTIN_FFS)
if (NOT HAVE_DECL___BUILTIN_FFS)
set(HAVE_DECL___BUILTIN_FFS 0)
endif ()
check_c_source_compiles("
static void foo(void) __attribute__ ((unused));
int main() { return 0; }
" HAVE___ATTRIBUTE__)
check_c_source_compiles_numeric("
#include <strings.h>
int main() { ffs(0); return 0; }
" HAVE_DECL_FFS)
check_c_source_compiles_numeric("
int main() { __builtin_ffs(0); return 0; }
" HAVE_DECL___BUILTIN_FFS)
check_c_source_compiles_numeric("
#include <intrin.h>
int main() { _BitScanForward(NULL, 0); return 0; }
" HAVE_DECL__BITSCANFORWARD)
if (NOT HAVE_DECL_FFS AND
NOT HAVE_DECL___BUILTIN_FFS AND
NOT HAVE_DECL__BITSCANFORWARD)
message(FATAL_ERROR "No ffs implementation found")
endif ()
check_c_source_compiles_numeric("
#include <strings.h>
int main() { strcasecmp(\"\", \"\"); return 0; }
" HAVE_DECL_STRCASECMP)
check_c_source_compiles_numeric("
#include <string.h>
int main() { _stricmp(\"\", \"\"); return 0; }
" HAVE_DECL__STRICMP)
if (NOT HAVE_DECL_STRCASECMP AND NOT HAVE_DECL__STRICMP)
message(FATAL_ERROR "No strcasecmp implementation found")
endif ()
check_c_source_compiles_numeric("
#include <strings.h>
int main() { strncasecmp(\"\", \"\", 0); return 0; }
" HAVE_DECL_STRNCASECMP)
check_c_source_compiles_numeric("
#include <string.h>
int main() { _strnicmp(\"\", \"\", 0); return 0; }
" HAVE_DECL__STRNICMP)
if (NOT HAVE_DECL_STRNCASECMP AND NOT HAVE_DECL__STRNICMP)
message(FATAL_ERROR "No strncasecmp implementation found")
endif ()
check_c_source_compiles_numeric("
#include <stdio.h>
int main() { snprintf((void*)0, 0, \"\"); return 0; }
" HAVE_DECL_SNPRINTF)
check_c_source_compiles_numeric("
#include <stdio.h>
int main() { _snprintf((void*)0, 0, \"\"); return 0; }
" HAVE_DECL__SNPRINTF)
if (NOT HAVE_DECL_SNPRINTF AND NOT HAVE_DECL__SNPRINTF)
message(FATAL_ERROR "No snprintf implementation found")
endif ()
# Write configure result
configure_file("External/gitversion.h.cmake" "${ISL_BINARY_DIR}/gitversion.h")
configure_file("External/isl_config.h.cmake" "${ISL_BINARY_DIR}/isl_config.h")
file(WRITE "${ISL_BINARY_DIR}/include/isl/stdint.h" "#include <stdint.h>")
# ISL files to compile
set (ISL_FILES
@ -103,6 +167,7 @@ set (ISL_FILES
External/isl/isl_equalities.c
External/isl/isl_factorization.c
External/isl/isl_farkas.c
External/isl/isl_ffs.c
External/isl/isl_flow.c
External/isl/isl_fold.c
External/isl/isl_hash.c

View File

@ -1,8 +1,10 @@
/* define if your compiler has __attribute__ */
#cmakedefine HAVE___ATTRIBUTE__ /**/
/* most gcc compilers know a function __attribute__((__warn_unused_result__))
*/
/* most gcc compilers know a function __attribute__((__warn_unused_result__)) */
#define GCC_WARN_UNUSED_RESULT @GCC_WARN_UNUSED_RESULT@
/* Define to 1 if you have the declaration of `ffs', and to 0 if you don't. */
#define HAVE_DECL_FFS @HAVE_DECL_FFS@
@ -10,8 +12,37 @@
don't. */
#define HAVE_DECL___BUILTIN_FFS @HAVE_DECL___BUILTIN_FFS@
/* define if your compiler has __attribute__ */
#cmakedefine HAVE___ATTRIBUTE__ /**/
/* Define to 1 if you have the declaration of `_BitScanForward', and to 0 if
you don't. */
#define HAVE_DECL__BITSCANFORWARD @HAVE_DECL__BITSCANFORWARD@
/* Define to 1 if you have the declaration of `strcasecmp', and to 0 if you
don't. */
#define HAVE_DECL_STRCASECMP @HAVE_DECL_STRCASECMP@
/* Define to 1 if you have the declaration of `_stricmp', and to 0 if you
don't. */
#define HAVE_DECL__STRICMP @HAVE_DECL__STRICMP@
/* Define to 1 if you have the declaration of `strncasecmp', and to 0 if you
don't. */
#define HAVE_DECL_STRNCASECMP @HAVE_DECL_STRNCASECMP@
/* Define to 1 if you have the declaration of `_strnicmp', and to 0 if you
don't. */
#define HAVE_DECL__STRNICMP @HAVE_DECL__STRNICMP@
/* Define to 1 if you have the declaration of `snprintf', and to 0 if you
don't. */
#define HAVE_DECL_SNPRINTF @HAVE_DECL_SNPRINTF@
/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you
don't. */
#define HAVE_DECL__SNPRINTF @HAVE_DECL__SNPRINTF@
/* use gmp to implement isl_int */
#cmakedefine USE_GMP_FOR_MP