ScopInfo: Add parameter bounds to context

Derive the maximal and minimal values of a parameter from the type it has. Add
this information to the scop context. This information is needed, to derive
optimal types during code generation.

llvm-svn: 157245
diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp
index b1b95c0..2c9486c 100644
--- a/polly/lib/Analysis/ScopInfo.cpp
+++ b/polly/lib/Analysis/ScopInfo.cpp
@@ -37,6 +37,7 @@
 #define DEBUG_TYPE "polly-scops"
 #include "llvm/Support/Debug.h"
 
+#include "isl/int.h"
 #include "isl/constraint.h"
 #include "isl/set.h"
 #include "isl/map.h"
@@ -755,6 +756,38 @@
   Context = isl_set_universe (Space);
 }
 
+void Scop::addParameterBounds() {
+  for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
+    isl_int V;
+    isl_id *Id;
+    const SCEV *Scev;
+    const IntegerType *T;
+
+    Id = isl_set_get_dim_id(Context, isl_dim_param, i);
+    Scev = (const SCEV*) isl_id_get_user(Id);
+    T = dyn_cast<IntegerType>(Scev->getType());
+    isl_id_free(Id);
+
+    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);
+  }
+}
+
+
 void Scop::realignParams() {
   // Add all parameters into a common model.
   isl_space *Space = isl_space_params_alloc(IslCtx, ParameterIds.size());
@@ -790,6 +823,7 @@
   buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
 
   realignParams();
+  addParameterBounds();
 
   assert(NestLoops.empty() && "NestLoops not empty at top level!");
 }