GMP is only required for CLooG

llvm-svn: 201925
diff --git a/polly/CMakeLists.txt b/polly/CMakeLists.txt
index 6f86772..5519219 100644
--- a/polly/CMakeLists.txt
+++ b/polly/CMakeLists.txt
@@ -80,13 +80,13 @@
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${POLLY_SOURCE_DIR}/cmake")
 
 FIND_PACKAGE(Isl REQUIRED)
-FIND_PACKAGE(Gmp REQUIRED)
 FIND_PACKAGE(Pluto)
 
 option(POLLY_USE_CLOOG "Build Polly with Cloog support" ON)
 if (POLLY_USE_CLOOG)
   # Build Cloog support in Polly (default is for cloog-isl).
   FIND_PACKAGE(Cloog)
+  FIND_PACKAGE(Gmp REQUIRED)
 endif(POLLY_USE_CLOOG)
 
 option(POLLY_ENABLE_GPGPU_CODEGEN "Enable GPGPU code generation feature" OFF)
@@ -114,7 +114,9 @@
   INCLUDE_DIRECTORIES( ${PLUTO_INCLUDE_DIR} )
 endif(PLUTO_FOUND)
 INCLUDE_DIRECTORIES( ${ISL_INCLUDE_DIR} )
-INCLUDE_DIRECTORIES( ${GMP_INCLUDE_DIR} )
+if (GMP_FOUND)
+  INCLUDE_DIRECTORIES( ${GMP_INCLUDE_DIR} )
+endif(GMP_FOUND)
 
 # Support GPGPU code generation if the library is available.
 if (CUDALIB_FOUND)
diff --git a/polly/autoconf/configure.ac b/polly/autoconf/configure.ac
index 193e4b0..be25dc6 100644
--- a/polly/autoconf/configure.ac
+++ b/polly/autoconf/configure.ac
@@ -75,11 +75,11 @@
 dnl * Set the location of various third-party software packages
 dnl **************************************************************************
 dnl Find Gmp
-find_lib_and_headers([gmp], [gmp.h], [gmp], [required])
+find_lib_and_headers([gmp], [gmp.h], [gmp])
 
 dnl Find Isl
 saved_CXXFLAGS=$CXXFLAGS
-CXXFLAGS="$CXXFLAGS $gmp_inc"
+CXXFLAGS="$CXXFLAGS"
 find_lib_and_headers([isl], [isl/val.h], [isl], [required])
 CXXFLAGS=$saved_CXXFLAGS
 
diff --git a/polly/cmake/polly_macros.cmake b/polly/cmake/polly_macros.cmake
index 399a716..b247927 100644
--- a/polly/cmake/polly_macros.cmake
+++ b/polly/cmake/polly_macros.cmake
@@ -27,10 +27,10 @@
     endforeach(lib)
   endif( LLVM_USED_LIBS )
 
-  target_link_libraries( ${name} ${ISL_LIBRARY} ${GMP_LIBRARY})
+  target_link_libraries( ${name} ${ISL_LIBRARY})
 
   if (CLOOG_FOUND)
-    target_link_libraries( ${name} ${CLOOG_LIBRARY})
+    target_link_libraries( ${name} ${CLOOG_LIBRARY} ${GMP_LIBRARY})
   endif(CLOOG_FOUND)
 
   if (OPENSCOP_FOUND)
diff --git a/polly/configure b/polly/configure
index 1d3148b..cb5dd54 100755
--- a/polly/configure
+++ b/polly/configure
@@ -2453,7 +2453,7 @@
 
 fi
 else
-  if test "xrequired" = "xrequired"; then :
+  if test "x" = "xrequired"; then :
   as_fn_error "gmp required but not found" "$LINENO" 5
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: not found" >&5
@@ -2477,7 +2477,7 @@
 
 
 saved_CXXFLAGS=$CXXFLAGS
-CXXFLAGS="$CXXFLAGS $gmp_inc"
+CXXFLAGS="$CXXFLAGS"
 
   ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
@@ -2504,8 +2504,8 @@
 fi
 
   # Check for library and headers works
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl: isl/val.in $given_inc_path, and libisl in $given_lib_path" >&5
-$as_echo_n "checking for isl: isl/val.in $given_inc_path, and libisl in $given_lib_path... " >&6; }
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for isl: isl/val.h in $given_inc_path, and libisl in $given_lib_path" >&5
+$as_echo_n "checking for isl: isl/val.h in $given_inc_path, and libisl in $given_lib_path... " >&6; }
 
   # try to compile a file that includes a header of the library
   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
diff --git a/polly/include/polly/Support/GICHelper.h b/polly/include/polly/Support/GICHelper.h
index 0d8b22b..4c4d5e2 100755
--- a/polly/include/polly/Support/GICHelper.h
+++ b/polly/include/polly/Support/GICHelper.h
@@ -1,4 +1,4 @@
-//===- Support/GICHelper.h -- Helper functions for GMP, ISL, and Cloog -----===/
+//===- Support/GICHelper.h -- Helper functions for ISL --------------------===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -7,7 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// Helper functions for gmp, isl and Cloog objects.
+// Helper functions for isl objects.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -15,10 +15,7 @@
 #define POLLY_SUPPORT_GIC_HELPER_H
 
 #include "llvm/ADT/APInt.h"
-#include <gmp.h>
-
 #include "isl/ctx.h"
-
 #include "llvm/Support/raw_ostream.h"
 
 struct isl_map;
@@ -33,18 +30,6 @@
 struct isl_val;
 
 namespace polly {
-
-/// @brief Convert APInt to mpz.
-///
-/// @param v      The mpz_t object your want to hold the result.
-/// @param apint  The APInt you want to convert.
-void MPZ_from_APInt(mpz_t v, const llvm::APInt apint, bool is_signed = true);
-
-/// @brief Convert mpz to APInt.
-///
-/// @param mpz    The mpz_t you want to convert.
-llvm::APInt APInt_from_MPZ(const mpz_t mpz);
-
 __isl_give isl_val *isl_valFromAPInt(isl_ctx *Ctx, const llvm::APInt Int,
                                      bool IsSigned);
 llvm::APInt APIntFromVal(__isl_take isl_val *Val);
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index d98e7cf3..2dc423c 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -115,6 +115,27 @@
   return Builder.CreateSExtOrBitCast(I->second, Ty);
 }
 
+static APInt APInt_from_MPZ(const mpz_t mpz) {
+  uint64_t *p = NULL;
+  size_t sz;
+
+  p = (uint64_t *)mpz_export(p, &sz, -1, sizeof(uint64_t), 0, 0, mpz);
+
+  if (p) {
+    APInt A((unsigned)mpz_sizeinbase(mpz, 2), (unsigned)sz, p);
+    A = A.zext(A.getBitWidth() + 1);
+    free(p);
+
+    if (mpz_sgn(mpz) == -1)
+      return -A;
+    else
+      return A;
+  } else {
+    uint64_t val = 0;
+    return APInt(1, 1, &val);
+  }
+}
+
 Value *ClastExpCodeGen::codegen(const clast_term *e, Type *Ty) {
   APInt a = APInt_from_MPZ(e->val);
 
diff --git a/polly/lib/Support/GICHelper.cpp b/polly/lib/Support/GICHelper.cpp
index cc293e8..530ce91 100644
--- a/polly/lib/Support/GICHelper.cpp
+++ b/polly/lib/Support/GICHelper.cpp
@@ -21,25 +21,6 @@
 
 using namespace llvm;
 
-void polly::MPZ_from_APInt(mpz_t v, const APInt apint, bool is_signed) {
-  // There is no sign taken from the data, rop will simply be a positive
-  // integer. An application can handle any sign itself, and apply it for
-  // instance with mpz_neg.
-  APInt abs;
-  if (is_signed)
-    abs = apint.abs();
-  else
-    abs = apint;
-
-  const uint64_t *rawdata = abs.getRawData();
-  unsigned numWords = abs.getNumWords();
-
-  mpz_import(v, numWords, -1, sizeof(uint64_t), 0, 0, rawdata);
-
-  if (is_signed && apint.isNegative())
-    mpz_neg(v, v);
-}
-
 __isl_give isl_val *polly::isl_valFromAPInt(isl_ctx *Ctx, const APInt Int,
                                             bool IsSigned) {
   APInt Abs;
@@ -61,27 +42,6 @@
   return v;
 }
 
-APInt polly::APInt_from_MPZ(const mpz_t mpz) {
-  uint64_t *p = NULL;
-  size_t sz;
-
-  p = (uint64_t *)mpz_export(p, &sz, -1, sizeof(uint64_t), 0, 0, mpz);
-
-  if (p) {
-    APInt A((unsigned)mpz_sizeinbase(mpz, 2), (unsigned)sz, p);
-    A = A.zext(A.getBitWidth() + 1);
-    free(p);
-
-    if (mpz_sgn(mpz) == -1)
-      return -A;
-    else
-      return A;
-  } else {
-    uint64_t val = 0;
-    return APInt(1, 1, &val);
-  }
-}
-
 APInt polly::APIntFromVal(__isl_take isl_val *Val) {
   uint64_t *Data;
   int NumChunks;