#define IMPURE 0
#define PURE_PARAM 1
#define PURE_VAR 2
+#define MIXED 3
/* Return PURE_PARAM if only the coefficients of the parameters are non-zero.
* Return PURE_VAR if only the coefficients of the set variables are non-zero.
+ * Return MIXED if only the coefficients of the parameters and the set
+ * variables are non-zero and if moreover the parametric constant
+ * can never attain positive values.
* Return IMPURE otherwise.
*/
-static int purity(__isl_keep isl_basic_set *bset, isl_int *c)
+static int purity(__isl_keep isl_basic_set *bset, isl_int *c, int eq)
{
unsigned d;
unsigned n_div;
unsigned nparam;
+ int k;
+ int empty;
n_div = isl_basic_set_dim(bset, isl_dim_div);
d = isl_basic_set_dim(bset, isl_dim_set);
return PURE_VAR;
if (isl_seq_first_non_zero(c + 1 + nparam, d) == -1)
return PURE_PARAM;
- return IMPURE;
+ if (eq)
+ return IMPURE;
+
+ bset = isl_basic_set_copy(bset);
+ bset = isl_basic_set_cow(bset);
+ bset = isl_basic_set_extend_constraints(bset, 0, 1);
+ k = isl_basic_set_alloc_inequality(bset);
+ if (k < 0)
+ goto error;
+ isl_seq_clr(bset->ineq[k], 1 + isl_basic_set_total_dim(bset));
+ isl_seq_cpy(bset->ineq[k], c, 1 + nparam);
+ isl_int_sub_ui(bset->ineq[k][0], bset->ineq[k][0], 1);
+ empty = isl_basic_set_is_empty(bset);
+ isl_basic_set_free(bset);
+
+ return empty < 0 ? -1 : empty ? MIXED : IMPURE;
+error:
+ isl_basic_set_free(bset);
+ return -1;
}
/* Given a set of offsets "delta", construct a relation of the
* In particular, let delta be defined as
*
* \delta = [p] -> { [x] : A x + a >= and B p + b >= 0 and
- * C x + C'p + c >= 0 }
+ * C x + C'p + c >= 0 and
+ * D x + D'p + d >= 0 }
*
- * then the relation is constructed as
+ * where the constraints C x + C'p + c >= 0 are such that the parametric
+ * constant term of each constraint j, "C_j x + C'_j p + c_j",
+ * can never attain positive values, then the relation is constructed as
*
* { [x] -> [y] : exists [f, k] \in Z^{n+1} : y = x + f and
- * A f + k a >= 0 and B p + b >= 0 and k >= 1 }
+ * A f + k a >= 0 and B p + b >= 0 and
+ * C f + C'p + c >= 0 and k >= 1 }
* union { [x] -> [x] }
*
* Existentially quantified variables in \delta are currently ignored.
}
for (i = 0; i < delta->n_eq; ++i) {
- int p = purity(delta, delta->eq[i]);
+ int p = purity(delta, delta->eq[i], 1);
+ if (p < 0)
+ goto error;
if (p == IMPURE)
continue;
k = isl_basic_map_alloc_equality(path);
}
for (i = 0; i < delta->n_ineq; ++i) {
- int p = purity(delta, delta->ineq[i]);
+ int p = purity(delta, delta->ineq[i], 0);
+ if (p < 0)
+ goto error;
if (p == IMPURE)
continue;
k = isl_basic_map_alloc_inequality(path);
isl_seq_cpy(path->ineq[k] + off,
delta->ineq[i] + 1 + nparam, d);
isl_int_set(path->ineq[k][off + d], delta->ineq[i][0]);
- } else
+ } else if (p == PURE_PARAM) {
+ isl_seq_cpy(path->ineq[k], delta->ineq[i], 1 + nparam);
+ } else {
+ isl_seq_cpy(path->ineq[k] + off,
+ delta->ineq[i] + 1 + nparam, d);
isl_seq_cpy(path->ineq[k], delta->ineq[i], 1 + nparam);
+ }
}
k = isl_basic_map_alloc_inequality(path);
if (j < d) {
path = isl_map_apply_range(path,
path_along_delta(isl_dim_copy(dim), delta));
+ path = isl_map_coalesce(path);
} else {
isl_basic_set_free(delta);
++n;
* { (x) -> (x) }
*/
static __isl_give isl_map *construct_component(__isl_take isl_dim *dim,
- __isl_keep isl_map *map, int *project)
+ __isl_keep isl_map *map, int *exact, int project)
{
struct isl_set *domain = NULL;
struct isl_set *range = NULL;
+ struct isl_set *overlap;
struct isl_map *app = NULL;
struct isl_map *path = NULL;
domain = isl_set_coalesce(domain);
range = isl_map_range(isl_map_copy(map));
range = isl_set_coalesce(range);
+ overlap = isl_set_intersect(isl_set_copy(domain), isl_set_copy(range));
+ if (isl_set_is_empty(overlap) == 1) {
+ isl_set_free(domain);
+ isl_set_free(range);
+ isl_set_free(overlap);
+ isl_dim_free(dim);
+
+ map = isl_map_copy(map);
+ map = isl_map_add(map, isl_dim_in, 1);
+ map = isl_map_add(map, isl_dim_out, 1);
+ map = set_path_length(map, 1, 1);
+ return map;
+ }
+ isl_set_free(overlap);
app = isl_map_from_domain_and_range(domain, range);
app = isl_map_add(app, isl_dim_in, 1);
app = isl_map_add(app, isl_dim_out, 1);
- path = construct_extended_path(isl_dim_copy(dim), map, project);
+ path = construct_extended_path(isl_dim_copy(dim), map,
+ exact && *exact ? &project : NULL);
app = isl_map_intersect(app, path);
+ if (exact && *exact &&
+ (*exact = check_exactness(isl_map_copy(map), isl_map_copy(app),
+ project)) < 0)
+ goto error;
+
return isl_map_union(app, isl_map_identity(isl_dim_domain(dim)));
+error:
+ isl_dim_free(dim);
+ isl_map_free(app);
+ return NULL;
}
/* Structure for representing the nodes in the graph being traversed
*
* R_1 \circ R_2
*
- * is non-empty and that moreover, it is non-empty on the set
- * of elements that do not get mapped to the same set of elements
- * by both "R_1 \circ R_2" and "R_2 \circ R_1".
- * For elements that do get mapped to the same elements by these
- * two compositions, R_1 and R_2 are commutative, so if these
- * elements are the only ones for which R_1 \circ R_2 is non-empty,
- * then you may just as well apply R_1 first.
+ * is a subset of
+ *
+ * R_2 \circ R_1
+ *
+ * If so, then there is no reason for R_1 to immediately follow R_2
+ * in any path.
*/
static int basic_map_follows(__isl_keep isl_basic_map *bmap1,
__isl_keep isl_basic_map *bmap2)
{
struct isl_map *map12 = NULL;
struct isl_map *map21 = NULL;
- struct isl_map *d = NULL;
- struct isl_set *dom = NULL;
- int empty;
+ int subset;
map21 = isl_map_from_basic_map(
isl_basic_map_apply_range(
isl_basic_map_copy(bmap2),
isl_basic_map_copy(bmap1)));
- empty = isl_map_is_empty(map21);
- if (empty < 0)
+ subset = isl_map_is_empty(map21);
+ if (subset < 0)
goto error;
- if (empty) {
+ if (subset) {
isl_map_free(map21);
return 0;
}
isl_basic_map_apply_range(
isl_basic_map_copy(bmap1),
isl_basic_map_copy(bmap2)));
- d = isl_map_subtract(isl_map_copy(map12), isl_map_copy(map21));
- d = isl_map_union(d,
- isl_map_subtract(isl_map_copy(map21), isl_map_copy(map12)));
- dom = isl_map_domain(d);
- map21 = isl_map_intersect_domain(map21, dom);
- empty = isl_map_is_empty(map21);
+ subset = isl_map_is_subset(map21, map12);
isl_map_free(map12);
isl_map_free(map21);
- return empty < 0 ? -1 : !empty;
+ return subset < 0 ? -1 : !subset;
error:
isl_map_free(map21);
return -1;
* to be strictly positive.
*/
static __isl_give isl_map *construct_power_components(__isl_take isl_dim *dim,
- __isl_keep isl_map *map, int *project)
+ __isl_keep isl_map *map, int *exact, int project)
{
int i, n;
struct isl_map *path = NULL;
if (!map)
goto error;
if (map->n <= 1)
- return construct_component(dim, map, project);
+ return construct_component(dim, map, exact, project);
s = basic_map_sort_alloc(map->ctx, map->n);
if (!s)
++i;
}
path = isl_map_apply_range(path,
- construct_component(isl_dim_copy(dim), comp, project));
+ construct_component(isl_dim_copy(dim), comp,
+ exact, project));
isl_map_free(comp);
++i;
}
dim = isl_dim_add(dim, isl_dim_out, 1);
app = construct_power_components(isl_dim_copy(dim), map,
- exact ? &project : NULL);
-
- if (exact &&
- (*exact = check_exactness(isl_map_copy(map), isl_map_copy(app),
- project)) < 0)
- goto error;
+ exact, project);
diff = equate_parameter_to_length(dim, param);
app = isl_map_intersect(app, diff);
app = isl_map_project_out(app, isl_dim_out, d, 1);
return app;
-error:
- isl_dim_free(dim);
- isl_map_free(app);
- return NULL;
}
/* Compute the positive powers of "map", or an overapproximation.