[polly] r184529 - Use isl_val instead of isl_int in the core of Polly

Tobias Grosser grosser at fim.uni-passau.de
Thu Jun 20 23:41:32 PDT 2013


Author: grosser
Date: Fri Jun 21 01:41:31 2013
New Revision: 184529

URL: http://llvm.org/viewvc/llvm-project?rev=184529&view=rev
Log:
Use isl_val instead of isl_int in the core of Polly

isl recently introduced isl_val as an abstract interface to represent arbitrary
precision numbers. This interface superseeds the old isl_int interface. In
contrast to the old interface which implemented arbitrary precision arithmetic
using macros that forward to the gmp library, the new library hides the math
library implementation in isl. This allows us to switch the math library used by
isl without affecting users such as Polly.

Modified:
    polly/trunk/include/polly/CodeGen/CodeGeneration.h
    polly/trunk/include/polly/Support/GICHelper.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/CodeGen/BlockGenerators.cpp
    polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
    polly/trunk/lib/ScheduleOptimizer.cpp
    polly/trunk/lib/Support/GICHelper.cpp
    polly/trunk/utils/checkout_cloog.sh

Modified: polly/trunk/include/polly/CodeGen/CodeGeneration.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/CodeGeneration.h?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/CodeGeneration.h (original)
+++ polly/trunk/include/polly/CodeGen/CodeGeneration.h Fri Jun 21 01:41:31 2013
@@ -58,11 +58,10 @@ static inline int getNumberOfIterations(
 
   isl_point *P = isl_set_sample_point(Elements);
 
-  isl_int V;
-  isl_int_init(V);
-  isl_point_get_coordinate(P, isl_dim_set, Dim - 1, &V);
-  int NumberIterations = isl_int_get_si(V);
-  isl_int_clear(V);
+  isl_val *V;
+  V = isl_point_get_coordinate_val(P, isl_dim_set, Dim - 1);
+  int NumberIterations = isl_val_get_num_si(V);
+  isl_val_free(V);
   isl_point_free(P);
 
   return NumberIterations;

Modified: polly/trunk/include/polly/Support/GICHelper.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Support/GICHelper.h?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/include/polly/Support/GICHelper.h (original)
+++ polly/trunk/include/polly/Support/GICHelper.h Fri Jun 21 01:41:31 2013
@@ -17,6 +17,8 @@
 #include "llvm/ADT/APInt.h"
 #include <gmp.h>
 
+#include "isl/ctx.h"
+
 struct isl_map;
 struct isl_union_map;
 struct isl_set;
@@ -26,6 +28,7 @@ struct isl_multi_aff;
 struct isl_pw_multi_aff;
 struct isl_aff;
 struct isl_pw_aff;
+struct isl_val;
 
 namespace polly {
 
@@ -40,6 +43,11 @@ void MPZ_from_APInt(mpz_t v, const llvm:
 /// @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);
+
 /// @brief Get c++ string from Isl objects.
 //@{
 std::string stringFromIslObj(/*__isl_keep*/ isl_map *map);

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Fri Jun 21 01:41:31 2013
@@ -44,6 +44,7 @@
 #include "isl/printer.h"
 #include "isl/local_space.h"
 #include "isl/options.h"
+#include "isl/val.h"
 #include <sstream>
 #include <string>
 #include <vector>
@@ -98,8 +99,7 @@ public:
 
   __isl_give isl_pw_aff *visitConstant(const SCEVConstant *Constant) {
     ConstantInt *Value = Constant->getValue();
-    isl_int v;
-    isl_int_init(v);
+    isl_val *v;
 
     // LLVM does not define if an integer value is interpreted as a signed or
     // unsigned value. Hence, without further information, it is unknown how
@@ -111,15 +111,14 @@ public:
     //    demand.
     // 2. We pass down the signedness of the calculation and use it to interpret
     //    this constant correctly.
-    MPZ_from_APInt(v, Value->getValue(), /* isSigned */ true);
+    v = isl_valFromAPInt(Ctx, Value->getValue(), /* isSigned */ true);
 
     isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
     isl_local_space *ls = isl_local_space_from_space(isl_space_copy(Space));
     isl_aff *Affine = isl_aff_zero_on_domain(ls);
     isl_set *Domain = isl_set_universe(Space);
 
-    Affine = isl_aff_add_constant(Affine, v);
-    isl_int_clear(v);
+    Affine = isl_aff_add_constant_val(Affine, v);
 
     return isl_pw_aff_alloc(Domain, Affine);
   }
@@ -299,11 +298,10 @@ MemoryAccess::MemoryAccess(const IRAcces
   // subsequent values of 'i' index two values that are stored next to each
   // other in memory. By this division we make this characteristic obvious
   // again.
-  isl_int v;
-  isl_int_init(v);
-  isl_int_set_si(v, Access.getElemSizeInBytes());
-  Affine = isl_pw_aff_scale_down(Affine, v);
-  isl_int_clear(v);
+  isl_val *v;
+  v = isl_val_int_from_si(isl_pw_aff_get_ctx(Affine),
+                          Access.getElemSizeInBytes());
+  Affine = isl_pw_aff_scale_down_val(Affine, v);
 
   AccessRelation = isl_map_from_pw_aff(Affine);
   isl_space *Space = Statement->getDomainSpace();
@@ -368,16 +366,15 @@ static isl_map *getEqualAndLarger(isl_sp
   //   input[?,?,?,...,iX] -> output[?,?,?,...,oX] : iX < oX
   //
   unsigned lastDimension = isl_map_dim(Map, isl_dim_in) - 1;
-  isl_int v;
-  isl_int_init(v);
+  isl_val *v;
+  isl_ctx *Ctx = isl_map_get_ctx(Map);
   isl_constraint *c = isl_inequality_alloc(isl_local_space_copy(MapLocalSpace));
-  isl_int_set_si(v, -1);
-  isl_constraint_set_coefficient(c, isl_dim_in, lastDimension, v);
-  isl_int_set_si(v, 1);
-  isl_constraint_set_coefficient(c, isl_dim_out, lastDimension, v);
-  isl_int_set_si(v, -1);
-  isl_constraint_set_constant(c, v);
-  isl_int_clear(v);
+  v = isl_val_int_from_si(Ctx, -1);
+  c = isl_constraint_set_coefficient_val(c, isl_dim_in, lastDimension, v);
+  v = isl_val_int_from_si(Ctx, 1);
+  c = isl_constraint_set_coefficient_val(c, isl_dim_out, lastDimension, v);
+  v = isl_val_int_from_si(Ctx, -1);
+  c = isl_constraint_set_constant_val(c, v);
 
   Map = isl_map_add_constraint(Map, c);
 
@@ -736,7 +733,7 @@ void Scop::buildContext() {
 
 void Scop::addParameterBounds() {
   for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
-    isl_int V;
+    isl_val *V;
     isl_id *Id;
     const SCEV *Scev;
     const IntegerType *T;
@@ -749,19 +746,15 @@ void Scop::addParameterBounds() {
     assert(T && "Not an integer type");
     int Width = T->getBitWidth();
 
-    isl_int_init(V);
-
-    isl_int_set_si(V, 1);
-    isl_int_mul_2exp(V, V, Width - 1);
-    isl_int_neg(V, V);
-    isl_set_lower_bound(Context, isl_dim_param, i, V);
-
-    isl_int_set_si(V, 1);
-    isl_int_mul_2exp(V, V, Width - 1);
-    isl_int_sub_ui(V, V, 1);
-    isl_set_upper_bound(Context, isl_dim_param, i, V);
-
-    isl_int_clear(V);
+    V = isl_val_int_from_si(IslCtx, Width - 1);
+    V = isl_val_2exp(V);
+    V = isl_val_neg(V);
+    Context = isl_set_lower_bound_val(Context, isl_dim_param, i, V);
+
+    V = isl_val_int_from_si(IslCtx, Width - 1);
+    V = isl_val_2exp(V);
+    V = isl_val_sub_ui(V, 1);
+    Context = isl_set_upper_bound_val(Context, isl_dim_param, i, V);
   }
 }
 

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Fri Jun 21 01:41:31 2013
@@ -66,7 +66,7 @@ class IslGenerator {
 public:
   IslGenerator(IRBuilder<> &Builder, std::vector<Value *> &IVS)
       : Builder(Builder), IVS(IVS) {}
-  Value *generateIslInt(__isl_take isl_int Int);
+  Value *generateIslVal(__isl_take isl_val *Val);
   Value *generateIslAff(__isl_take isl_aff *Aff);
   Value *generateIslPwAff(__isl_take isl_pw_aff *PwAff);
 
@@ -83,23 +83,18 @@ private:
 };
 }
 
-Value *IslGenerator::generateIslInt(isl_int Int) {
-  mpz_t IntMPZ;
-  mpz_init(IntMPZ);
-  isl_int_get_gmp(Int, IntMPZ);
-  Value *IntValue = Builder.getInt(APInt_from_MPZ(IntMPZ));
-  mpz_clear(IntMPZ);
+Value *IslGenerator::generateIslVal(__isl_take isl_val *Val) {
+  Value *IntValue = Builder.getInt(APIntFromVal(Val));
   return IntValue;
 }
 
 Value *IslGenerator::generateIslAff(__isl_take isl_aff *Aff) {
   Value *Result;
   Value *ConstValue;
-  isl_int ConstIsl;
+  isl_val *Val;
 
-  isl_int_init(ConstIsl);
-  isl_aff_get_constant(Aff, &ConstIsl);
-  ConstValue = generateIslInt(ConstIsl);
+  Val = isl_aff_get_constant_val(Aff);
+  ConstValue = generateIslVal(Val);
   Type *Ty = Builder.getInt64Ty();
 
   // FIXME: We should give the constant and coefficients the right type. Here
@@ -112,25 +107,22 @@ Value *IslGenerator::generateIslAff(__is
          "The Dimension of Induction Variables must match the dimension of the "
          "affine space.");
 
-  isl_int CoefficientIsl;
-  isl_int_init(CoefficientIsl);
-
   for (unsigned int i = 0; i < NbInputDims; ++i) {
     Value *CoefficientValue;
-    isl_aff_get_coefficient(Aff, isl_dim_in, i, &CoefficientIsl);
+    Val = isl_aff_get_coefficient_val(Aff, isl_dim_in, i);
 
-    if (isl_int_is_zero(CoefficientIsl))
+    if (isl_val_is_zero(Val)) {
+      isl_val_free(Val);
       continue;
+    }
 
-    CoefficientValue = generateIslInt(CoefficientIsl);
+    CoefficientValue = generateIslVal(Val);
     CoefficientValue = Builder.CreateIntCast(CoefficientValue, Ty, true);
     Value *IV = Builder.CreateIntCast(IVS[i], Ty, true);
     Value *PAdd = Builder.CreateMul(CoefficientValue, IV, "p_mul_coeff");
     Result = Builder.CreateAdd(Result, PAdd, "p_sum_coeff");
   }
 
-  isl_int_clear(CoefficientIsl);
-  isl_int_clear(ConstIsl);
   isl_aff_free(Aff);
 
   return Result;

Modified: polly/trunk/lib/CodeGen/IslCodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslCodeGeneration.cpp?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslCodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGen/IslCodeGeneration.cpp Fri Jun 21 01:41:31 2013
@@ -505,20 +505,18 @@ IntegerType *IslExprBuilder::getType(__i
 Value *IslExprBuilder::createInt(__isl_take isl_ast_expr *Expr) {
   assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_int &&
          "Expression not of type isl_ast_expr_int");
-  isl_int Int;
+  isl_val *Val;
   Value *V;
   APInt APValue;
   IntegerType *T;
 
-  isl_int_init(Int);
-  isl_ast_expr_get_int(Expr, &Int);
-  APValue = APInt_from_MPZ(Int);
+  Val = isl_ast_expr_get_val(Expr);
+  APValue = APIntFromVal(Val);
   T = getType(Expr);
   APValue = APValue.sextOrSelf(T->getBitWidth());
   V = ConstantInt::get(T, APValue);
 
   isl_ast_expr_free(Expr);
-  isl_int_clear(Int);
   return V;
 }
 

Modified: polly/trunk/lib/ScheduleOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/ScheduleOptimizer.cpp?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/lib/ScheduleOptimizer.cpp (original)
+++ polly/trunk/lib/ScheduleOptimizer.cpp Fri Jun 21 01:41:31 2013
@@ -314,7 +314,7 @@ isl_map *IslScheduleOptimizer::getPrevec
   isl_aff *Aff;
   int PointDimension; /* ip */
   int TileDimension;  /* it */
-  isl_int VectorWidthMP;
+  isl_val *VectorWidthMP;
 
   assert(0 <= DimToVectorize && DimToVectorize < ScheduleDimensions);
 
@@ -343,10 +343,8 @@ isl_map *IslScheduleOptimizer::getPrevec
   Aff = isl_aff_zero_on_domain(LocalSpaceRange);
   Aff = isl_aff_set_constant_si(Aff, VectorWidth);
   Aff = isl_aff_set_coefficient_si(Aff, isl_dim_in, TileDimension, 1);
-  isl_int_init(VectorWidthMP);
-  isl_int_set_si(VectorWidthMP, VectorWidth);
-  Aff = isl_aff_mod(Aff, VectorWidthMP);
-  isl_int_clear(VectorWidthMP);
+  VectorWidthMP = isl_val_int_from_si(ctx, VectorWidth);
+  Aff = isl_aff_mod_val(Aff, VectorWidthMP);
   Modulo = isl_pw_aff_zero_set(isl_pw_aff_from_aff(Aff));
   TilingMap = isl_map_intersect_range(TilingMap, Modulo);
 

Modified: polly/trunk/lib/Support/GICHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/GICHelper.cpp?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/lib/Support/GICHelper.cpp (original)
+++ polly/trunk/lib/Support/GICHelper.cpp Fri Jun 21 01:41:31 2013
@@ -17,6 +17,9 @@
 #include "isl/set.h"
 #include "isl/union_map.h"
 #include "isl/union_set.h"
+#include "isl/val.h"
+
+#include "llvm/Support/raw_ostream.h"
 
 using namespace llvm;
 
@@ -39,6 +42,27 @@ void polly::MPZ_from_APInt(mpz_t v, cons
     mpz_neg(v, v);
 }
 
+__isl_give isl_val *polly::isl_valFromAPInt(isl_ctx *Ctx, const APInt Int,
+                                            bool IsSigned) {
+  APInt Abs;
+  isl_val *v;
+
+  if (IsSigned)
+    Abs = Int.abs();
+  else
+    Abs = Int;
+
+  const uint64_t *Data = Abs.getRawData();
+  unsigned Words = Abs.getNumWords();
+
+  v = isl_val_int_from_chunks(Ctx, Words, sizeof(uint64_t), Data);
+
+  if (IsSigned && Int.isNegative())
+    v = isl_val_neg(v);
+
+  return v;
+}
+
 APInt polly::APInt_from_MPZ(const mpz_t mpz) {
   uint64_t *p = NULL;
   size_t sz;
@@ -60,6 +84,29 @@ APInt polly::APInt_from_MPZ(const mpz_t
   }
 }
 
+APInt polly::APIntFromVal(__isl_take isl_val *Val) {
+  uint64_t *Data;
+  int NumChunks;
+
+  NumChunks = isl_val_n_abs_num_chunks(Val, sizeof(uint64_t));
+
+  Data = (uint64_t*) malloc(NumChunks * sizeof(uint64_t));
+  isl_val_get_abs_num_chunks(Val, sizeof(uint64_t), Data);
+  APInt A(8 * sizeof(uint64_t) * NumChunks, NumChunks, Data);
+
+  if (isl_val_is_neg(Val)) {
+    A = A.zext(A.getBitWidth() + 1);
+    A = -A;
+  }
+
+  if (A.getMinSignedBits() < A.getBitWidth())
+    A = A.trunc(A.getMinSignedBits());
+
+  free(Data);
+  isl_val_free(Val);
+  return A;
+}
+
 template <typename ISLTy, typename ISL_CTX_GETTER, typename ISL_PRINTER>
 static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
                                                    ISL_CTX_GETTER ctx_getter_fn,

Modified: polly/trunk/utils/checkout_cloog.sh
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/utils/checkout_cloog.sh?rev=184529&r1=184528&r2=184529&view=diff
==============================================================================
--- polly/trunk/utils/checkout_cloog.sh (original)
+++ polly/trunk/utils/checkout_cloog.sh Fri Jun 21 01:41:31 2013
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 CLOOG_HASH="f861f854b6cc85b67e39794e38e7104fcd59af90"
-ISL_HASH="1df91d8515ec88dc7f7f597168ad0f34f26de5a7"
+ISL_HASH="0a83197c479109b0f7c327484b80a878f291b296"
 
 PWD=`pwd`
 





More information about the llvm-commits mailing list