GMP is only required for CLooG
llvm-svn: 201925
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);