diff options
author | Sven Verdoolaege <skimo@kotnet.org> | 2008-09-09 10:09:34 +0200 |
---|---|---|
committer | Sven Verdoolaege <skimo@kotnet.org> | 2008-10-11 23:37:28 +0200 |
commit | 7cd47d61a34916dd23e658e3b8bac9b2abfe8b1d (patch) | |
tree | 67402ef7f2793bc83f7169699891f0a92277898d | |
parent | 608fe1dc7d7df7c60b18af546ec719e3a4c7ee81 (diff) | |
download | isl-7cd47d61a34916dd23e658e3b8bac9b2abfe8b1d.tar.gz isl-7cd47d61a34916dd23e658e3b8bac9b2abfe8b1d.tar.bz2 isl-7cd47d61a34916dd23e658e3b8bac9b2abfe8b1d.zip |
add struct_ctx field to isl_set and isl_map
Since isl_sets and isl_maps now know which isl_ctx they belong
to, the isl_ctx argument of many functions can be dropped.
-rw-r--r-- | include/isl_ctx.h.in | 4 | ||||
-rw-r--r-- | include/isl_map.h | 127 | ||||
-rw-r--r-- | include/isl_map_piplib.h | 7 | ||||
-rw-r--r-- | include/isl_map_polylib.h | 5 | ||||
-rw-r--r-- | include/isl_set.h | 92 | ||||
-rw-r--r-- | include/isl_set_polylib.h | 5 | ||||
-rw-r--r-- | isl_affine_hull.c | 125 | ||||
-rw-r--r-- | isl_convex_hull.c | 197 | ||||
-rw-r--r-- | isl_ctx.c | 14 | ||||
-rw-r--r-- | isl_equalities.c | 16 | ||||
-rw-r--r-- | isl_equalities.h | 2 | ||||
-rw-r--r-- | isl_input.c | 12 | ||||
-rw-r--r-- | isl_input_omega.c | 21 | ||||
-rw-r--r-- | isl_map.c | 1344 | ||||
-rw-r--r-- | isl_map_no_piplib.c | 17 | ||||
-rw-r--r-- | isl_map_piplib.c | 94 | ||||
-rw-r--r-- | isl_map_polylib.c | 39 | ||||
-rw-r--r-- | isl_map_private.h | 87 | ||||
-rw-r--r-- | isl_mat.c | 23 | ||||
-rw-r--r-- | isl_sample.c | 27 | ||||
-rw-r--r-- | isl_sample.h | 3 | ||||
-rw-r--r-- | isl_sample_no_piplib.c | 5 | ||||
-rw-r--r-- | isl_sample_piplib.c | 18 | ||||
-rw-r--r-- | isl_sample_piplib.h | 3 | ||||
-rw-r--r-- | isl_test.c | 26 |
25 files changed, 1103 insertions, 1210 deletions
diff --git a/include/isl_ctx.h.in b/include/isl_ctx.h.in index d1d5b7a3..070cd53a 100644 --- a/include/isl_ctx.h.in +++ b/include/isl_ctx.h.in @@ -40,6 +40,8 @@ extern "C" { */ struct isl_vec; struct isl_ctx { + int ref; + isl_int one; int n_cached; @@ -76,6 +78,8 @@ struct isl_ctx { /* struct isl_ctx functions */ struct isl_ctx *isl_ctx_alloc(); +void isl_ctx_ref(struct isl_ctx *ctx); +void isl_ctx_deref(struct isl_ctx *ctx); void isl_ctx_free(struct isl_ctx *ctx); #if defined(__cplusplus) diff --git a/include/isl_map.h b/include/isl_map.h index 395334bc..ad667a6b 100644 --- a/include/isl_map.h +++ b/include/isl_map.h @@ -43,6 +43,8 @@ struct isl_basic_map { #define ISL_BASIC_MAP_RATIONAL (1 << 4) unsigned flags; + struct isl_ctx *ctx; + unsigned nparam; unsigned n_in; unsigned n_out; @@ -77,6 +79,8 @@ struct isl_map { #define ISL_MAP_DISJOINT (1 << 0) unsigned flags; + struct isl_ctx *ctx; + unsigned nparam; unsigned n_in; unsigned n_out; @@ -93,13 +97,10 @@ struct isl_basic_map *isl_basic_map_alloc(struct isl_ctx *ctx, unsigned n_eq, unsigned n_ineq); struct isl_basic_map *isl_basic_map_identity(struct isl_ctx *ctx, unsigned nparam, unsigned dim); -struct isl_basic_map *isl_basic_map_finalize(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -void isl_basic_map_free(struct isl_ctx *ctx, struct isl_basic_map *bmap); -struct isl_basic_map *isl_basic_map_copy(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_basic_map *isl_basic_map_extend(struct isl_ctx *ctx, - struct isl_basic_map *base, +struct isl_basic_map *isl_basic_map_finalize(struct isl_basic_map *bmap); +void isl_basic_map_free(struct isl_basic_map *bmap); +struct isl_basic_map *isl_basic_map_copy(struct isl_basic_map *bmap); +struct isl_basic_map *isl_basic_map_extend(struct isl_basic_map *base, unsigned nparam, unsigned n_in, unsigned n_out, unsigned extra, unsigned n_eq, unsigned n_ineq); struct isl_basic_map *isl_basic_map_equal(struct isl_ctx *ctx, @@ -114,57 +115,46 @@ struct isl_basic_map *isl_basic_map_universe(struct isl_ctx *ctx, unsigned nparam, unsigned in, unsigned out); struct isl_basic_map *isl_basic_map_intersect_domain( - struct isl_ctx *ctx, struct isl_basic_map *bmap, + struct isl_basic_map *bmap, struct isl_basic_set *bset); struct isl_basic_map *isl_basic_map_intersect( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2); struct isl_map *isl_basic_map_union( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2); struct isl_basic_map *isl_basic_map_apply_domain( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2); struct isl_basic_map *isl_basic_map_apply_range( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2); -struct isl_basic_map *isl_basic_map_reverse(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_basic_set *isl_basic_map_domain(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_basic_set *isl_basic_map_range(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_basic_map *isl_basic_map_from_basic_set( - struct isl_ctx *ctx, struct isl_basic_set *bset, +struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap); +struct isl_basic_set *isl_basic_map_domain(struct isl_basic_map *bmap); +struct isl_basic_set *isl_basic_map_range(struct isl_basic_map *bmap); +struct isl_basic_map *isl_basic_map_from_basic_set(struct isl_basic_set *bset, unsigned n_in, unsigned n_out); -struct isl_basic_set *isl_basic_set_from_basic_map( - struct isl_ctx *ctx, struct isl_basic_map *bmap); -struct isl_basic_map *isl_basic_map_simplify( - struct isl_ctx *ctx, struct isl_basic_map *bmap); +struct isl_basic_set *isl_basic_set_from_basic_map(struct isl_basic_map *bmap); +struct isl_basic_map *isl_basic_map_simplify(struct isl_basic_map *bmap); #define ISL_FORMAT_POLYLIB 1 #define ISL_FORMAT_OMEGA 2 struct isl_basic_map *isl_basic_map_read_from_file(struct isl_ctx *ctx, FILE *input, unsigned nparam, unsigned input_format); -struct isl_map *isl_basic_map_lexmax(struct isl_ctx *ctx, +struct isl_map *isl_basic_map_lexmax( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty); -struct isl_map *isl_basic_map_lexmin(struct isl_ctx *ctx, +struct isl_map *isl_basic_map_lexmin( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty); -void isl_basic_map_dump(struct isl_ctx *ctx, struct isl_basic_map *bmap, - FILE *out, int indent); +void isl_basic_map_dump(struct isl_basic_map *bmap, FILE *out, int indent); -int isl_basic_map_is_universe(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -int isl_basic_map_is_empty(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -int isl_basic_map_is_subset(struct isl_ctx *ctx, - struct isl_basic_map *bmap1, +int isl_basic_map_is_universe(struct isl_basic_map *bmap); +int isl_basic_map_is_empty(struct isl_basic_map *bmap); +int isl_basic_map_is_subset(struct isl_basic_map *bmap1, struct isl_basic_map *bmap2); -int isl_basic_map_is_strict_subset(struct isl_ctx *ctx, - struct isl_basic_map *bmap1, +int isl_basic_map_is_strict_subset(struct isl_basic_map *bmap1, struct isl_basic_map *bmap2); struct isl_map *isl_map_alloc(struct isl_ctx *ctx, @@ -172,60 +162,49 @@ struct isl_map *isl_map_alloc(struct isl_ctx *ctx, unsigned flags); struct isl_map *isl_map_empty(struct isl_ctx *ctx, unsigned nparam, unsigned in, unsigned out); -struct isl_map *isl_map_dup(struct isl_ctx *ctx, struct isl_map *map); -struct isl_map *isl_map_add(struct isl_ctx *ctx, struct isl_map *map, - struct isl_basic_map *bmap); +struct isl_map *isl_map_dup(struct isl_map *map); +struct isl_map *isl_map_add(struct isl_map *map, struct isl_basic_map *bmap); struct isl_map *isl_map_identity(struct isl_ctx *ctx, unsigned nparam, unsigned dim); -struct isl_map *isl_map_finalize(struct isl_ctx *ctx, struct isl_map *map); -void isl_map_free(struct isl_ctx *ctx, struct isl_map *map); -struct isl_map *isl_map_copy(struct isl_ctx *ctx, struct isl_map *map); -struct isl_map *isl_map_extend(struct isl_ctx *ctx, struct isl_map *base, +struct isl_map *isl_map_finalize(struct isl_map *map); +void isl_map_free(struct isl_map *map); +struct isl_map *isl_map_copy(struct isl_map *map); +struct isl_map *isl_map_extend(struct isl_map *base, unsigned nparam, unsigned n_in, unsigned n_out); -struct isl_map *isl_map_reverse(struct isl_ctx *ctx, struct isl_map *map); -struct isl_map *isl_map_union(struct isl_ctx *ctx, - struct isl_map *map1, struct isl_map *map2); -struct isl_map *isl_map_union_disjoint(struct isl_ctx *ctx, +struct isl_map *isl_map_reverse(struct isl_map *map); +struct isl_map *isl_map_union(struct isl_map *map1, struct isl_map *map2); +struct isl_map *isl_map_union_disjoint( struct isl_map *map1, struct isl_map *map2); struct isl_map *isl_map_intersect_domain( - struct isl_ctx *ctx, struct isl_map *map, + struct isl_map *map, struct isl_set *set); struct isl_map *isl_map_intersect_range( - struct isl_ctx *ctx, struct isl_map *map, + struct isl_map *map, struct isl_set *set); struct isl_map *isl_map_apply_domain( - struct isl_ctx *ctx, struct isl_map *map1, + struct isl_map *map1, struct isl_map *map2); struct isl_map *isl_map_apply_range( - struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2); -struct isl_map *isl_map_intersect(struct isl_ctx *ctx, struct isl_map *map1, + struct isl_map *map1, struct isl_map *map2); -struct isl_map *isl_map_subtract(struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2); -struct isl_map *isl_map_fix_input_si(struct isl_ctx *ctx, struct isl_map *map, +struct isl_map *isl_map_intersect(struct isl_map *map1, struct isl_map *map2); +struct isl_map *isl_map_subtract(struct isl_map *map1, struct isl_map *map2); +struct isl_map *isl_map_fix_input_si(struct isl_map *map, unsigned input, int value); -struct isl_basic_set *isl_basic_map_deltas(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_set *isl_map_range(struct isl_ctx *ctx, struct isl_map *map); -struct isl_basic_map *isl_map_affine_hull(struct isl_ctx *ctx, - struct isl_map *map); - -struct isl_set *isl_map_domain(struct isl_ctx *ctx, struct isl_map *bmap); -struct isl_map *isl_map_from_basic_map(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_map *isl_map_from_set( - struct isl_ctx *ctx, struct isl_set *set, +struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap); +struct isl_set *isl_map_range(struct isl_map *map); +struct isl_basic_map *isl_map_affine_hull(struct isl_map *map); + +struct isl_set *isl_map_domain(struct isl_map *bmap); +struct isl_map *isl_map_from_basic_map(struct isl_basic_map *bmap); +struct isl_map *isl_map_from_set(struct isl_set *set, unsigned n_in, unsigned n_out); -int isl_map_is_empty(struct isl_ctx *ctx, struct isl_map *map); -int isl_map_is_subset(struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2); -int isl_map_is_equal(struct isl_ctx *ctx, - struct isl_map *map1, struct isl_map *map2); +int isl_map_is_empty(struct isl_map *map); +int isl_map_is_subset(struct isl_map *map1, struct isl_map *map2); +int isl_map_is_equal(struct isl_map *map1, struct isl_map *map2); -void isl_map_dump(struct isl_ctx *ctx, struct isl_map *map, FILE *out, - int indent); +void isl_map_dump(struct isl_map *map, FILE *out, int indent); #if defined(__cplusplus) } diff --git a/include/isl_map_piplib.h b/include/isl_map_piplib.h index 193f7e94..70533fc9 100644 --- a/include/isl_map_piplib.h +++ b/include/isl_map_piplib.h @@ -7,14 +7,13 @@ extern "C" { #endif -struct isl_map *isl_pip_basic_map_lexmax(struct isl_ctx *ctx, +struct isl_map *isl_pip_basic_map_lexmax( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty); -struct isl_map *isl_pip_basic_map_lexmin(struct isl_ctx *ctx, +struct isl_map *isl_pip_basic_map_lexmin( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty); -struct isl_map *isl_pip_basic_map_compute_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap); +struct isl_map *isl_pip_basic_map_compute_divs(struct isl_basic_map *bmap); #if defined(__cplusplus) } diff --git a/include/isl_map_polylib.h b/include/isl_map_polylib.h index 411d52ee..0028fa41 100644 --- a/include/isl_map_polylib.h +++ b/include/isl_map_polylib.h @@ -14,9 +14,8 @@ struct isl_basic_map *isl_basic_map_new_from_polylib( struct isl_map *isl_map_new_from_polylib(struct isl_ctx *ctx, Polyhedron *D, unsigned nparam, unsigned in, unsigned out); -Polyhedron *isl_basic_map_to_polylib(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -Polyhedron *isl_map_to_polylib(struct isl_ctx *ctx, struct isl_map *map); +Polyhedron *isl_basic_map_to_polylib(struct isl_basic_map *bmap); +Polyhedron *isl_map_to_polylib(struct isl_map *map); #if defined(__cplusplus) } diff --git a/include/isl_set.h b/include/isl_set.h index 6300c139..c597e571 100644 --- a/include/isl_set.h +++ b/include/isl_set.h @@ -16,6 +16,8 @@ struct isl_basic_set { #define ISL_BASIC_SET_EMPTY (1 << 1) unsigned flags; + struct isl_ctx *ctx; + unsigned nparam; unsigned zero; unsigned dim; @@ -47,6 +49,8 @@ struct isl_set { #define ISL_SET_DISJOINT (1 << 0) unsigned flags; + struct isl_ctx *ctx; + unsigned nparam; unsigned zero; unsigned dim; @@ -60,35 +64,30 @@ struct isl_set { struct isl_basic_set *isl_basic_set_alloc(struct isl_ctx *ctx, unsigned nparam, unsigned dim, unsigned extra, unsigned n_eq, unsigned n_ineq); -struct isl_basic_set *isl_basic_set_extend(struct isl_ctx *ctx, - struct isl_basic_set *base, +struct isl_basic_set *isl_basic_set_extend(struct isl_basic_set *base, unsigned nparam, unsigned dim, unsigned extra, unsigned n_eq, unsigned n_ineq); -struct isl_basic_set *isl_basic_set_finalize(struct isl_ctx *ctx, - struct isl_basic_set *bset); -void isl_basic_set_free(struct isl_ctx *ctx, struct isl_basic_set *bset); -struct isl_basic_set *isl_basic_set_copy(struct isl_ctx *ctx, - struct isl_basic_set *bset); +struct isl_basic_set *isl_basic_set_finalize(struct isl_basic_set *bset); +void isl_basic_set_free(struct isl_basic_set *bset); +struct isl_basic_set *isl_basic_set_copy(struct isl_basic_set *bset); struct isl_basic_set *isl_basic_set_empty(struct isl_ctx *ctx, unsigned nparam, unsigned dim); struct isl_basic_set *isl_basic_set_universe(struct isl_ctx *ctx, unsigned nparam, unsigned dim); -void isl_basic_set_dump(struct isl_ctx *ctx, struct isl_basic_set *bset, +void isl_basic_set_dump(struct isl_basic_set *bset, FILE *out, int indent); -struct isl_basic_set *isl_basic_set_swap_vars(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_swap_vars( struct isl_basic_set *bset, unsigned n); -struct isl_basic_set *isl_basic_set_drop_vars(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_drop_vars( struct isl_basic_set *bset, unsigned first, unsigned n); struct isl_basic_set *isl_basic_set_intersect( - struct isl_ctx *ctx, struct isl_basic_set *bset1, + struct isl_basic_set *bset1, struct isl_basic_set *bset2); struct isl_basic_set *isl_basic_set_apply( - struct isl_ctx *ctx, struct isl_basic_set *bset, + struct isl_basic_set *bset, struct isl_basic_map *bmap); -struct isl_basic_set *isl_basic_set_affine_hull(struct isl_ctx *ctx, - struct isl_basic_set *bset); -struct isl_basic_set *isl_basic_set_simplify( - struct isl_ctx *ctx, struct isl_basic_set *bset); +struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset); +struct isl_basic_set *isl_basic_set_simplify(struct isl_basic_set *bset); #define ISL_FORMAT_POLYLIB 1 #define ISL_FORMAT_OMEGA 2 struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx, @@ -96,55 +95,42 @@ struct isl_basic_set *isl_basic_set_read_from_file(struct isl_ctx *ctx, struct isl_set *isl_set_read_from_file(struct isl_ctx *ctx, FILE *input, unsigned nparam, unsigned input_format); -int isl_basic_set_is_equal(struct isl_ctx *ctx, +int isl_basic_set_is_equal( struct isl_basic_set *bset1, struct isl_basic_set *bset2); -struct isl_set *isl_basic_set_lexmin(struct isl_ctx *ctx, - struct isl_basic_set *bset); +struct isl_set *isl_basic_set_lexmin(struct isl_basic_set *bset); struct isl_set *isl_basic_set_union( - struct isl_ctx *ctx, struct isl_basic_set *bset1, + struct isl_basic_set *bset1, struct isl_basic_set *bset2); struct isl_set *isl_set_alloc(struct isl_ctx *ctx, unsigned nparam, unsigned dim, int n, unsigned flags); struct isl_set *isl_set_empty(struct isl_ctx *ctx, unsigned nparam, unsigned dim); -struct isl_set *isl_set_add(struct isl_ctx *ctx, struct isl_set *set, - struct isl_basic_set *bset); -struct isl_set *isl_set_finalize(struct isl_ctx *ctx, struct isl_set *set); -struct isl_set *isl_set_copy(struct isl_ctx *ctx, struct isl_set *set); -void isl_set_free(struct isl_ctx *ctx, struct isl_set *set); -struct isl_set *isl_set_dup(struct isl_ctx *ctx, struct isl_set *set); -struct isl_set *isl_set_from_basic_set(struct isl_ctx *ctx, - struct isl_basic_set *bset); -struct isl_basic_set *isl_set_affine_hull(struct isl_ctx *ctx, - struct isl_set *set); -struct isl_basic_set *isl_set_convex_hull(struct isl_ctx *ctx, - struct isl_set *set); - -struct isl_set *isl_set_union_disjoint(struct isl_ctx *ctx, +struct isl_set *isl_set_add(struct isl_set *set, struct isl_basic_set *bset); +struct isl_set *isl_set_finalize(struct isl_set *set); +struct isl_set *isl_set_copy(struct isl_set *set); +void isl_set_free(struct isl_set *set); +struct isl_set *isl_set_dup(struct isl_set *set); +struct isl_set *isl_set_from_basic_set(struct isl_basic_set *bset); +struct isl_basic_set *isl_set_affine_hull(struct isl_set *set); +struct isl_basic_set *isl_set_convex_hull(struct isl_set *set); + +struct isl_set *isl_set_union_disjoint( struct isl_set *set1, struct isl_set *set2); -struct isl_set *isl_set_union(struct isl_ctx *ctx, - struct isl_set *set1, struct isl_set *set2); -struct isl_set *isl_set_subtract(struct isl_ctx *ctx, struct isl_set *set1, - struct isl_set *set2); -struct isl_set *isl_set_apply(struct isl_ctx *ctx, struct isl_set *set, - struct isl_map *map); -struct isl_set *isl_set_fix_dim_si(struct isl_ctx *ctx, struct isl_set *set, +struct isl_set *isl_set_union(struct isl_set *set1, struct isl_set *set2); +struct isl_set *isl_set_subtract(struct isl_set *set1, struct isl_set *set2); +struct isl_set *isl_set_apply(struct isl_set *set, struct isl_map *map); +struct isl_set *isl_set_fix_dim_si(struct isl_set *set, unsigned dim, int value); -void isl_set_dump(struct isl_ctx *ctx, struct isl_set *set, FILE *out, - int indent); -struct isl_set *isl_set_swap_vars(struct isl_ctx *ctx, - struct isl_set *set, unsigned n); -int isl_set_is_empty(struct isl_ctx *ctx, struct isl_set *set); -int isl_set_is_subset(struct isl_ctx *ctx, - struct isl_set *set1, struct isl_set *set2); -int isl_set_is_equal(struct isl_ctx *ctx, - struct isl_set *set1, struct isl_set *set2); - -struct isl_set *isl_basic_set_compute_divs(struct isl_ctx *ctx, - struct isl_basic_set *bset); +void isl_set_dump(struct isl_set *set, FILE *out, int indent); +struct isl_set *isl_set_swap_vars(struct isl_set *set, unsigned n); +int isl_set_is_empty(struct isl_set *set); +int isl_set_is_subset(struct isl_set *set1, struct isl_set *set2); +int isl_set_is_equal(struct isl_set *set1, struct isl_set *set2); + +struct isl_set *isl_basic_set_compute_divs(struct isl_basic_set *bset); #if defined(__cplusplus) } diff --git a/include/isl_set_polylib.h b/include/isl_set_polylib.h index 7e01ae46..b6963ba3 100644 --- a/include/isl_set_polylib.h +++ b/include/isl_set_polylib.h @@ -11,12 +11,11 @@ extern "C" { struct isl_basic_set *isl_basic_set_new_from_polylib( struct isl_ctx *ctx, Polyhedron *P, unsigned nparam, unsigned dim); -Polyhedron *isl_basic_set_to_polylib(struct isl_ctx *ctx, - struct isl_basic_set *bset); +Polyhedron *isl_basic_set_to_polylib(struct isl_basic_set *bset); struct isl_set *isl_set_new_from_polylib(struct isl_ctx *ctx, Polyhedron *D, unsigned nparam, unsigned dim); -Polyhedron *isl_set_to_polylib(struct isl_ctx *ctx, struct isl_set *set); +Polyhedron *isl_set_to_polylib(struct isl_set *set); #if defined(__cplusplus) } diff --git a/isl_affine_hull.c b/isl_affine_hull.c index 43e71c41..038f4cc5 100644 --- a/isl_affine_hull.c +++ b/isl_affine_hull.c @@ -7,11 +7,12 @@ #include "isl_equalities.h" #include "isl_sample.h" -struct isl_basic_map *isl_basic_map_implicit_equalities(struct isl_ctx *ctx, +struct isl_basic_map *isl_basic_map_implicit_equalities( struct isl_basic_map *bmap) { int i; isl_int opt; + struct isl_ctx *ctx; if (!bmap) return bmap; @@ -21,6 +22,7 @@ struct isl_basic_map *isl_basic_map_implicit_equalities(struct isl_ctx *ctx, if (F_ISSET(bmap, ISL_BASIC_MAP_NO_IMPLICIT)) return bmap; + ctx = bmap->ctx; isl_int_init(opt); for (i = 0; i < bmap->n_ineq; ++i) { enum isl_lp_result res; @@ -30,12 +32,12 @@ struct isl_basic_map *isl_basic_map_implicit_equalities(struct isl_ctx *ctx, if (res == isl_lp_error) goto error; if (res == isl_lp_empty) { - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); break; } isl_int_add(opt, opt, bmap->ineq[i][0]); if (isl_int_is_zero(opt)) { - isl_basic_map_inequality_to_equality(ctx, bmap, i); + isl_basic_map_inequality_to_equality(bmap, i); --i; } } @@ -45,7 +47,7 @@ struct isl_basic_map *isl_basic_map_implicit_equalities(struct isl_ctx *ctx, return bmap; error: isl_int_clear(opt); - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -175,7 +177,7 @@ static int transform_column( * except that the echelon form we use starts from the last column * and that we are dealing with integer coefficients. */ -static struct isl_basic_set *affine_hull(struct isl_ctx *ctx, +static struct isl_basic_set *affine_hull( struct isl_basic_set *bset1, struct isl_basic_set *bset2) { unsigned total; @@ -202,11 +204,11 @@ static struct isl_basic_set *affine_hull(struct isl_ctx *ctx, --row; } } - isl_basic_set_free(ctx, bset2); + isl_basic_set_free(bset2); isl_assert(ctx, row == bset1->n_eq, goto error); return bset1; error: - isl_basic_set_free(ctx, bset1); + isl_basic_set_free(bset1); return NULL; } @@ -223,7 +225,7 @@ static struct isl_basic_set *isl_basic_set_from_vec(struct isl_ctx *ctx, bset = isl_basic_set_alloc(ctx, 0, vec->size - 1, 0, vec->size - 1, 0); for (i = bset->dim - 1; i >= 0; --i) { - k = isl_basic_set_alloc_equality(ctx, bset); + k = isl_basic_set_alloc_equality(bset); if (k < 0) goto error; isl_seq_clr(bset->eq[k], 1 + bset->dim); @@ -234,7 +236,7 @@ static struct isl_basic_set *isl_basic_set_from_vec(struct isl_ctx *ctx, return bset; error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); isl_vec_free(ctx, vec); return NULL; } @@ -247,11 +249,11 @@ static struct isl_basic_set *outside_point(struct isl_ctx *ctx, struct isl_basic_set *point; int k; - slice = isl_basic_set_copy(ctx, bset); + slice = isl_basic_set_copy(bset); if (!slice) goto error; - slice = isl_basic_set_extend(ctx, slice, 0, slice->dim, 0, 1, 0); - k = isl_basic_set_alloc_equality(ctx, slice); + slice = isl_basic_set_extend(slice, 0, slice->dim, 0, 1, 0); + k = isl_basic_set_alloc_equality(slice); if (k < 0) goto error; isl_seq_cpy(slice->eq[k], eq, 1 + slice->dim); @@ -260,7 +262,7 @@ static struct isl_basic_set *outside_point(struct isl_ctx *ctx, else isl_int_sub_ui(slice->eq[k][0], slice->eq[k][0], 1); - sample = isl_basic_set_sample(ctx, slice); + sample = isl_basic_set_sample(slice); if (!sample) goto error; if (sample->size == 0) { @@ -271,7 +273,7 @@ static struct isl_basic_set *outside_point(struct isl_ctx *ctx, return point; error: - isl_basic_set_free(ctx, slice); + isl_basic_set_free(slice); return NULL; } @@ -286,25 +288,26 @@ error: * we check if there is any point on the corresponding hyperplane * shifted by one (in either direction). */ -struct isl_basic_map *isl_basic_map_affine_hull(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_affine_hull(struct isl_basic_map *bmap) { int i, j; struct isl_mat *T2 = NULL; struct isl_basic_set *bset = NULL; struct isl_basic_set *hull = NULL; struct isl_vec *sample; + struct isl_ctx *ctx; - bmap = isl_basic_map_implicit_equalities(ctx, bmap); + bmap = isl_basic_map_implicit_equalities(bmap); if (!bmap) return NULL; + ctx = bmap->ctx; if (bmap->n_ineq == 0) return bmap; - bset = isl_basic_map_underlying_set(ctx, isl_basic_map_copy(ctx, bmap)); - bset = isl_basic_set_remove_equalities(ctx, bset, NULL, &T2); + bset = isl_basic_map_underlying_set(isl_basic_map_copy(bmap)); + bset = isl_basic_set_remove_equalities(bset, NULL, &T2); - sample = isl_basic_set_sample(ctx, isl_basic_set_copy(ctx, bset)); + sample = isl_basic_set_sample(isl_basic_set_copy(bset)); hull = isl_basic_set_from_vec(ctx, sample); for (i = 0; i < bset->dim; ++i) { @@ -315,49 +318,47 @@ struct isl_basic_map *isl_basic_map_affine_hull(struct isl_ctx *ctx, goto error; if (!F_ISSET(point, ISL_BASIC_SET_EMPTY)) break; - isl_basic_set_free(ctx, point); + isl_basic_set_free(point); point = outside_point(ctx, bset, hull->eq[j], 0); if (!point) goto error; if (!F_ISSET(point, ISL_BASIC_SET_EMPTY)) break; - isl_basic_set_free(ctx, point); + isl_basic_set_free(point); } if (j == hull->n_eq) break; - hull = affine_hull(ctx, hull, point); + hull = affine_hull(hull, point); } - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); bset = NULL; - bmap = isl_basic_map_cow(ctx, bmap); + bmap = isl_basic_map_cow(bmap); if (!bmap) goto error; - isl_basic_map_free_inequality(ctx, bmap, bmap->n_ineq); + isl_basic_map_free_inequality(bmap, bmap->n_ineq); if (T2) hull = isl_basic_set_preimage(ctx, hull, T2); - bmap = isl_basic_map_intersect(ctx, bmap, - isl_basic_map_overlying_set(ctx, hull, - isl_basic_map_copy(ctx, bmap))); + bmap = isl_basic_map_intersect(bmap, + isl_basic_map_overlying_set(hull, + isl_basic_map_copy(bmap))); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: isl_mat_free(ctx, T2); - isl_basic_set_free(ctx, bset); - isl_basic_set_free(ctx, hull); - isl_basic_map_free(ctx, bmap); + isl_basic_set_free(bset); + isl_basic_set_free(hull); + isl_basic_map_free(bmap); return NULL; } -struct isl_basic_set *isl_basic_set_affine_hull(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset) { return (struct isl_basic_set *) - isl_basic_map_affine_hull(ctx, (struct isl_basic_map *)bset); + isl_basic_map_affine_hull((struct isl_basic_map *)bset); } -struct isl_basic_map *isl_map_affine_hull(struct isl_ctx *ctx, - struct isl_map *map) +struct isl_basic_map *isl_map_affine_hull(struct isl_map *map) { int i; struct isl_basic_map *model = NULL; @@ -368,54 +369,52 @@ struct isl_basic_map *isl_map_affine_hull(struct isl_ctx *ctx, return NULL; if (map->n == 0) { - hull = isl_basic_map_empty(ctx, - map->nparam, map->n_in, map->n_out); - isl_map_free(ctx, map); + hull = isl_basic_map_empty(map->ctx, + map->nparam, map->n_in, map->n_out); + isl_map_free(map); return hull; } - map = isl_map_align_divs(ctx, map); - model = isl_basic_map_copy(ctx, map->p[0]); - set = isl_map_underlying_set(ctx, map); - set = isl_set_cow(ctx, set); + map = isl_map_align_divs(map); + model = isl_basic_map_copy(map->p[0]); + set = isl_map_underlying_set(map); + set = isl_set_cow(set); if (!set) goto error; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_cow(ctx, set->p[i]); - set->p[i] = isl_basic_set_affine_hull(ctx, set->p[i]); - set->p[i] = isl_basic_set_gauss(ctx, set->p[i], NULL); + set->p[i] = isl_basic_set_cow(set->p[i]); + set->p[i] = isl_basic_set_affine_hull(set->p[i]); + set->p[i] = isl_basic_set_gauss(set->p[i], NULL); if (!set->p[i]) goto error; } - set = isl_set_remove_empty_parts(ctx, set); + set = isl_set_remove_empty_parts(set); if (set->n == 0) { - hull = isl_basic_map_empty(ctx, + hull = isl_basic_map_empty(set->ctx, model->nparam, model->n_in, model->n_out); - isl_basic_map_free(ctx, model); + isl_basic_map_free(model); } else { struct isl_basic_set *bset; while (set->n > 1) { - set->p[0] = affine_hull(ctx, set->p[0], - set->p[--set->n]); + set->p[0] = affine_hull(set->p[0], set->p[--set->n]); if (!set->p[0]) goto error; } - bset = isl_basic_set_copy(ctx, set->p[0]); - hull = isl_basic_map_overlying_set(ctx, bset, model); + bset = isl_basic_set_copy(set->p[0]); + hull = isl_basic_map_overlying_set(bset, model); } - isl_set_free(ctx, set); - hull = isl_basic_map_simplify(ctx, hull); - return isl_basic_map_finalize(ctx, hull); + isl_set_free(set); + hull = isl_basic_map_simplify(hull); + return isl_basic_map_finalize(hull); error: - isl_basic_map_free(ctx, model); - isl_set_free(ctx, set); + isl_basic_map_free(model); + isl_set_free(set); return NULL; } -struct isl_basic_set *isl_set_affine_hull(struct isl_ctx *ctx, - struct isl_set *set) +struct isl_basic_set *isl_set_affine_hull(struct isl_set *set) { return (struct isl_basic_set *) - isl_map_affine_hull(ctx, (struct isl_map *)set); + isl_map_affine_hull((struct isl_map *)set); } diff --git a/isl_convex_hull.c b/isl_convex_hull.c index 8c7ea3f8..cf064341 100644 --- a/isl_convex_hull.c +++ b/isl_convex_hull.c @@ -6,8 +6,7 @@ #include "isl_seq.h" #include "isl_equalities.h" -static struct isl_basic_set *uset_convex_hull(struct isl_ctx *ctx, - struct isl_set *set); +static struct isl_basic_set *uset_convex_hull(struct isl_set *set); static swap_ineq(struct isl_basic_map *bmap, unsigned i, unsigned j) { @@ -28,14 +27,14 @@ static swap_ineq(struct isl_basic_map *bmap, unsigned i, unsigned j) * corresponding equality and the checked if the dimension was that * of a facet. */ -struct isl_basic_map *isl_basic_map_convex_hull(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_convex_hull(struct isl_basic_map *bmap) { int i; isl_int opt_n; isl_int opt_d; + struct isl_ctx *ctx; - bmap = isl_basic_map_implicit_equalities(ctx, bmap); + bmap = isl_basic_map_implicit_equalities(bmap); if (!bmap) return NULL; @@ -44,6 +43,7 @@ struct isl_basic_map *isl_basic_map_convex_hull(struct isl_ctx *ctx, if (F_ISSET(bmap, ISL_BASIC_MAP_NO_REDUNDANT)) return bmap; + ctx = bmap->ctx; isl_int_init(opt_n); isl_int_init(opt_d); for (i = bmap->n_ineq-1; i >= 0; --i) { @@ -59,12 +59,12 @@ struct isl_basic_map *isl_basic_map_convex_hull(struct isl_ctx *ctx, if (res == isl_lp_error) goto error; if (res == isl_lp_empty) { - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); break; } isl_int_addmul(opt_n, opt_d, bmap->ineq[i][0]); if (!isl_int_is_neg(opt_n)) - isl_basic_map_drop_inequality(ctx, bmap, i); + isl_basic_map_drop_inequality(bmap, i); } isl_int_clear(opt_n); isl_int_clear(opt_d); @@ -74,15 +74,14 @@ struct isl_basic_map *isl_basic_map_convex_hull(struct isl_ctx *ctx, error: isl_int_clear(opt_n); isl_int_clear(opt_d); - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -struct isl_basic_set *isl_basic_set_convex_hull(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_convex_hull(struct isl_basic_set *bset) { - return (struct isl_basic_set *)isl_basic_map_convex_hull(ctx, - (struct isl_basic_map *)bset); + return (struct isl_basic_set *) + isl_basic_map_convex_hull((struct isl_basic_map *)bset); } /* Check if "c" is a direction with a lower bound in "set" that is independent @@ -136,7 +135,7 @@ static int is_independent_bound(struct isl_ctx *ctx, if (res == isl_lp_error) goto error; if (res == isl_lp_empty) { - set->p[j] = isl_basic_set_set_to_empty(ctx, set->p[j]); + set->p[j] = isl_basic_set_set_to_empty(set->p[j]); if (!set->p[j]) goto error; continue; @@ -220,7 +219,7 @@ error: return NULL; } -static struct isl_basic_set *isl_basic_set_set_rational(struct isl_ctx *ctx, +static struct isl_basic_set *isl_basic_set_set_rational( struct isl_basic_set *bset) { if (!bset) @@ -229,7 +228,7 @@ static struct isl_basic_set *isl_basic_set_set_rational(struct isl_ctx *ctx, if (F_ISSET(bset, ISL_BASIC_MAP_RATIONAL)) return bset; - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); if (!bset) return NULL; @@ -238,22 +237,21 @@ static struct isl_basic_set *isl_basic_set_set_rational(struct isl_ctx *ctx, return bset; } -static struct isl_set *isl_set_set_rational(struct isl_ctx *ctx, - struct isl_set *set) +static struct isl_set *isl_set_set_rational(struct isl_set *set) { int i; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) return NULL; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_set_rational(ctx, set->p[i]); + set->p[i] = isl_basic_set_set_rational(set->p[i]); if (!set->p[i]) goto error; } return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -265,14 +263,14 @@ static struct isl_basic_set *isl_basic_set_add_equality(struct isl_ctx *ctx, isl_assert(ctx, bset->nparam == 0, goto error); isl_assert(ctx, bset->n_div == 0, goto error); - bset = isl_basic_set_extend(ctx, bset, 0, bset->dim, 0, 1, 0); - i = isl_basic_set_alloc_equality(ctx, bset); + bset = isl_basic_set_extend(bset, 0, bset->dim, 0, 1, 0); + i = isl_basic_set_alloc_equality(bset); if (i < 0) goto error; isl_seq_cpy(bset->eq[i], c, 1 + bset->dim); return bset; error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } @@ -281,7 +279,7 @@ static struct isl_set *isl_set_add_equality(struct isl_ctx *ctx, { int i; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) return NULL; for (i = 0; i < set->n; ++i) { @@ -291,7 +289,7 @@ static struct isl_set *isl_set_add_equality(struct isl_ctx *ctx, } return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -334,7 +332,7 @@ static struct isl_basic_set *wrap_constraints(struct isl_ctx *ctx, lp = isl_basic_set_alloc(ctx, 0, dim * set->n, 0, n_eq, n_ineq); if (!lp) return NULL; - k = isl_basic_set_alloc_equality(ctx, lp); + k = isl_basic_set_alloc_equality(lp); isl_int_set_si(lp->eq[k][0], -1); for (i = 0; i < set->n; ++i) { isl_int_set_si(lp->eq[k][1+dim*i], 0); @@ -342,19 +340,19 @@ static struct isl_basic_set *wrap_constraints(struct isl_ctx *ctx, isl_seq_clr(lp->eq[k]+1+dim*i+2, dim-2); } for (i = 0; i < set->n; ++i) { - k = isl_basic_set_alloc_inequality(ctx, lp); + k = isl_basic_set_alloc_inequality(lp); isl_seq_clr(lp->ineq[k], 1+lp->dim); isl_int_set_si(lp->ineq[k][1+dim*i], 1); for (j = 0; j < set->p[i]->n_eq; ++j) { - k = isl_basic_set_alloc_equality(ctx, lp); + k = isl_basic_set_alloc_equality(lp); isl_seq_clr(lp->eq[k], 1+dim*i); isl_seq_cpy(lp->eq[k]+1+dim*i, set->p[i]->eq[j], dim); isl_seq_clr(lp->eq[k]+1+dim*(i+1), dim*(set->n-i-1)); } for (j = 0; j < set->p[i]->n_ineq; ++j) { - k = isl_basic_set_alloc_inequality(ctx, lp); + k = isl_basic_set_alloc_inequality(lp); isl_seq_clr(lp->ineq[k], 1+dim*i); isl_seq_cpy(lp->ineq[k]+1+dim*i, set->p[i]->ineq[j], dim); isl_seq_clr(lp->ineq[k]+1+dim*(i+1), dim*(set->n-i-1)); @@ -427,7 +425,7 @@ static isl_int *wrap_facet(struct isl_ctx *ctx, struct isl_set *set, isl_int num, den; unsigned dim; - set = isl_set_copy(ctx, set); + set = isl_set_copy(set); dim = 1 + set->dim; T = isl_mat_alloc(ctx, 3, 1 + set->dim); @@ -460,13 +458,13 @@ static isl_int *wrap_facet(struct isl_ctx *ctx, struct isl_set *set, isl_int_clear(num); isl_int_clear(den); isl_vec_free(ctx, obj); - isl_basic_set_free(ctx, lp); - isl_set_free(ctx, set); + isl_basic_set_free(lp); + isl_set_free(set); return (res == isl_lp_ok) ? facet : NULL; error: - isl_basic_set_free(ctx, lp); + isl_basic_set_free(lp); isl_mat_free(ctx, T); - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -498,7 +496,7 @@ static int compute_bound_on_face(struct isl_ctx *ctx, if (res == isl_lp_error) goto error; if (res == isl_lp_empty) { - set->p[j] = isl_basic_set_set_to_empty(ctx, set->p[j]); + set->p[j] = isl_basic_set_set_to_empty(set->p[j]); if (!set->p[j]) goto error; continue; @@ -540,7 +538,7 @@ static struct isl_mat *initial_facet_constraint(struct isl_ctx *ctx, isl_assert(ctx, set->n > 0, goto error); isl_assert(ctx, bounds->n_row == set->dim, goto error); - face = isl_set_copy(ctx, set); + face = isl_set_copy(set); if (!face) goto error; for (i = 1; i < set->dim; ++i) { @@ -550,10 +548,10 @@ static struct isl_mat *initial_facet_constraint(struct isl_ctx *ctx, if (!wrap_facet(ctx, set, bounds->row[0], bounds->row[i])) goto error; } - isl_set_free(ctx, face); + isl_set_free(face); return bounds; error: - isl_set_free(ctx, face); + isl_set_free(face); isl_mat_free(ctx, bounds); return NULL; } @@ -603,7 +601,7 @@ static struct isl_basic_set *compute_facet(struct isl_ctx *ctx, struct isl_mat *m, *U, *Q; struct isl_basic_set *facet; - set = isl_set_copy(ctx, set); + set = isl_set_copy(set); m = isl_mat_alloc(ctx, 2, 1 + set->dim); if (!m) goto error; @@ -616,12 +614,12 @@ static struct isl_basic_set *compute_facet(struct isl_ctx *ctx, U = isl_mat_drop_cols(ctx, U, 1, 1); Q = isl_mat_drop_rows(ctx, Q, 1, 1); set = isl_set_preimage(ctx, set, U); - facet = uset_convex_hull(ctx, set); + facet = uset_convex_hull(set); facet = isl_basic_set_preimage(ctx, facet, Q); isl_mat_free(ctx, m); return facet; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -660,7 +658,7 @@ static struct isl_basic_set *extend(struct isl_ctx *ctx, struct isl_set *set, 0, n_ineq + 2 * set->p[0]->n_div); if (!hull) goto error; - k = isl_basic_set_alloc_inequality(ctx, hull); + k = isl_basic_set_alloc_inequality(hull); if (k < 0) goto error; isl_seq_cpy(hull->ineq[k], initial->row[0], initial->n_col); @@ -669,7 +667,7 @@ static struct isl_basic_set *extend(struct isl_ctx *ctx, struct isl_set *set, if (!facet) goto error; for (j = 0; j < facet->n_ineq; ++j) { - k = isl_basic_set_alloc_inequality(ctx, hull); + k = isl_basic_set_alloc_inequality(hull); if (k < 0) goto error; isl_seq_cpy(hull->ineq[k], hull->ineq[i], 1+hull->dim); @@ -680,15 +678,15 @@ static struct isl_basic_set *extend(struct isl_ctx *ctx, struct isl_set *set, 1+hull->dim)) break; if (f < k) - isl_basic_set_free_inequality(ctx, hull, 1); + isl_basic_set_free_inequality(hull, 1); } - isl_basic_set_free(ctx, facet); + isl_basic_set_free(facet); } - hull = isl_basic_set_simplify(ctx, hull); - hull = isl_basic_set_finalize(ctx, hull); + hull = isl_basic_set_simplify(hull); + hull = isl_basic_set_finalize(hull); return hull; error: - isl_basic_set_free(ctx, hull); + isl_basic_set_free(hull); return NULL; } @@ -707,11 +705,11 @@ static struct isl_basic_set *convex_hull_1d(struct isl_ctx *ctx, struct isl_basic_set *hull; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_simplify(ctx, set->p[i]); + set->p[i] = isl_basic_set_simplify(set->p[i]); if (!set->p[i]) goto error; } - set = isl_set_remove_empty_parts(ctx, set); + set = isl_set_remove_empty_parts(set); if (!set) goto error; isl_assert(ctx, set->n > 0, goto error); @@ -799,19 +797,19 @@ static struct isl_basic_set *convex_hull_1d(struct isl_ctx *ctx, if (!hull) goto error; if (lower) { - k = isl_basic_set_alloc_inequality(ctx, hull); + k = isl_basic_set_alloc_inequality(hull); isl_seq_cpy(hull->ineq[k], lower, 2); } if (upper) { - k = isl_basic_set_alloc_inequality(ctx, hull); + k = isl_basic_set_alloc_inequality(hull); isl_seq_cpy(hull->ineq[k], upper, 2); } - hull = isl_basic_set_finalize(ctx, hull); - isl_set_free(ctx, set); + hull = isl_basic_set_finalize(hull); + isl_set_free(set); isl_mat_free(ctx, c); return hull; error: - isl_set_free(ctx, set); + isl_set_free(set); isl_mat_free(ctx, c); return NULL; } @@ -822,20 +820,20 @@ static struct isl_set *set_project_out(struct isl_ctx *ctx, { int i; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) return NULL; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_eliminate_vars(ctx, set->p[i], + set->p[i] = isl_basic_set_eliminate_vars(set->p[i], set->dim - n, n); if (!set->p[i]) goto error; } - set = isl_set_drop_vars(ctx, set, set->dim - n, n); + set = isl_set_drop_vars(set, set->dim - n, n); return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -866,14 +864,14 @@ static struct isl_basic_set *modulo_lineality(struct isl_ctx *ctx, isl_mat_free(ctx, H); set = isl_set_preimage(ctx, set, U); set = set_project_out(ctx, set, old_dim - new_dim); - hull = uset_convex_hull(ctx, set); + hull = uset_convex_hull(set); hull = isl_basic_set_preimage(ctx, hull, Q); isl_mat_free(ctx, bounds); return hull; error: isl_mat_free(ctx, bounds); isl_mat_free(ctx, Q); - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -881,54 +879,53 @@ error: * without parameters or divs and where the convex hull of set is * known to be full-dimensional. */ -static struct isl_basic_set *uset_convex_hull(struct isl_ctx *ctx, - struct isl_set *set) +static struct isl_basic_set *uset_convex_hull(struct isl_set *set) { int i; struct isl_basic_set *convex_hull = NULL; struct isl_mat *bounds; if (set->dim == 0) { - convex_hull = isl_basic_set_universe(ctx, 0, 0); - isl_set_free(ctx, set); + convex_hull = isl_basic_set_universe(set->ctx, 0, 0); + isl_set_free(set); return convex_hull; } - set = isl_set_set_rational(ctx, set); + set = isl_set_set_rational(set); if (!set) goto error; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_convex_hull(ctx, set->p[i]); + set->p[i] = isl_basic_set_convex_hull(set->p[i]); if (!set->p[i]) goto error; } - set = isl_set_remove_empty_parts(ctx, set); + set = isl_set_remove_empty_parts(set); if (!set) goto error; if (set->n == 1) { - convex_hull = isl_basic_set_copy(ctx, set->p[0]); - isl_set_free(ctx, set); + convex_hull = isl_basic_set_copy(set->p[0]); + isl_set_free(set); return convex_hull; } if (set->dim == 1) - return convex_hull_1d(ctx, set); + return convex_hull_1d(set->ctx, set); - bounds = independent_bounds(ctx, set); + bounds = independent_bounds(set->ctx, set); if (!bounds) goto error; if (bounds->n_row < set->dim) - return modulo_lineality(ctx, set, bounds); - bounds = initial_facet_constraint(ctx, set, bounds); + return modulo_lineality(set->ctx, set, bounds); + bounds = initial_facet_constraint(set->ctx, set, bounds); if (!bounds) goto error; - convex_hull = extend(ctx, set, bounds); - isl_mat_free(ctx, bounds); - isl_set_free(ctx, set); + convex_hull = extend(set->ctx, set, bounds); + isl_mat_free(set->ctx, bounds); + isl_set_free(set); return convex_hull; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -945,19 +942,19 @@ static struct isl_basic_set *modulo_affine_hull(struct isl_ctx *ctx, struct isl_basic_set *dummy; struct isl_basic_set *convex_hull; - dummy = isl_basic_set_remove_equalities(ctx, - isl_basic_set_copy(ctx, affine_hull), &T, &T2); + dummy = isl_basic_set_remove_equalities( + isl_basic_set_copy(affine_hull), &T, &T2); if (!dummy) goto error; - isl_basic_set_free(ctx, dummy); + isl_basic_set_free(dummy); set = isl_set_preimage(ctx, set, T); - convex_hull = uset_convex_hull(ctx, set); + convex_hull = uset_convex_hull(set); convex_hull = isl_basic_set_preimage(ctx, convex_hull, T2); - convex_hull = isl_basic_set_intersect(ctx, convex_hull, affine_hull); + convex_hull = isl_basic_set_intersect(convex_hull, affine_hull); return convex_hull; error: - isl_basic_set_free(ctx, affine_hull); - isl_set_free(ctx, set); + isl_basic_set_free(affine_hull); + isl_set_free(set); return NULL; } @@ -966,52 +963,52 @@ error: * The implementation was inspired by "Extended Convex Hull" by Fukuda et al., * specifically, the wrapping of facets to obtain new facets. */ -struct isl_basic_map *isl_map_convex_hull(struct isl_ctx *ctx, - struct isl_map *map) +struct isl_basic_map *isl_map_convex_hull(struct isl_map *map) { struct isl_basic_set *bset; struct isl_basic_set *affine_hull = NULL; struct isl_basic_map *convex_hull = NULL; struct isl_set *set = NULL; + struct isl_ctx *ctx; if (!map) goto error; + ctx = map->ctx; if (map->n == 0) { convex_hull = isl_basic_map_empty(ctx, map->nparam, map->n_in, map->n_out); - isl_map_free(ctx, map); + isl_map_free(map); return convex_hull; } - set = isl_map_underlying_set(ctx, isl_map_copy(ctx, map)); + set = isl_map_underlying_set(isl_map_copy(map)); if (!set) goto error; - affine_hull = isl_set_affine_hull(ctx, isl_set_copy(ctx, set)); + affine_hull = isl_set_affine_hull(isl_set_copy(set)); if (!affine_hull) goto error; if (affine_hull->n_eq != 0) bset = modulo_affine_hull(ctx, set, affine_hull); else { - isl_basic_set_free(ctx, affine_hull); - bset = uset_convex_hull(ctx, set); + isl_basic_set_free(affine_hull); + bset = uset_convex_hull(set); } - convex_hull = isl_basic_map_overlying_set(ctx, bset, - isl_basic_map_copy(ctx, map->p[0])); + convex_hull = isl_basic_map_overlying_set(bset, + isl_basic_map_copy(map->p[0])); - isl_map_free(ctx, map); + isl_map_free(map); return convex_hull; error: - isl_set_free(ctx, set); - isl_map_free(ctx, map); + isl_set_free(set); + isl_map_free(map); return NULL; } -struct isl_basic_set *isl_set_convex_hull(struct isl_ctx *ctx, - struct isl_set *set) +struct isl_basic_set *isl_set_convex_hull(struct isl_set *set) { return (struct isl_basic_set *) - isl_map_convex_hull(ctx, (struct isl_map *)set); + isl_map_convex_hull((struct isl_map *)set); } @@ -12,6 +12,8 @@ struct isl_ctx *isl_ctx_alloc() if (!ctx) goto error; + ctx->ref = 0; + isl_int_init(ctx->one); isl_int_set_si(ctx->one, 1); @@ -27,10 +29,22 @@ error: return NULL; } +void isl_ctx_ref(struct isl_ctx *ctx) +{ + ctx->ref++; +} + +void isl_ctx_deref(struct isl_ctx *ctx) +{ + isl_assert(ctx, ctx->ref > 0, return); + ctx->ref--; +} + void isl_ctx_free(struct isl_ctx *ctx) { if (!ctx) return; + isl_assert(ctx, ctx->ref == 0, return); isl_blk_clear_cache(ctx); isl_int_clear(ctx->one); free(ctx); diff --git a/isl_equalities.c b/isl_equalities.c index a4aeac45..895ed8f1 100644 --- a/isl_equalities.c +++ b/isl_equalities.c @@ -89,7 +89,7 @@ static struct isl_basic_set *compress_variables(struct isl_ctx *ctx, isl_mat_free(ctx, *T2); *T2 = NULL; } - return isl_basic_set_set_to_empty(ctx, bset); + return isl_basic_set_set_to_empty(bset); } isl_seq_scale_down(TC->row[1+i], TC->row[1+i], TC->row[0][0], 1); } @@ -112,7 +112,7 @@ error: isl_mat_free(ctx, U); if (T2) isl_mat_free(ctx, *T2); - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); if (T) *T = NULL; if (T2) @@ -120,21 +120,23 @@ error: return NULL; } -struct isl_basic_set *isl_basic_set_remove_equalities(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_remove_equalities( struct isl_basic_set *bset, struct isl_mat **T, struct isl_mat **T2) { - isl_assert(ctx, bset->nparam == 0, goto error); if (T) *T = NULL; if (T2) *T2 = NULL; - bset = isl_basic_set_gauss(ctx, bset, NULL); + if (!bset) + return NULL; + isl_assert(bset->ctx, bset->nparam == 0, goto error); + bset = isl_basic_set_gauss(bset, NULL); if (F_ISSET(bset, ISL_BASIC_SET_EMPTY)) return bset; - bset = compress_variables(ctx, bset, T, T2); + bset = compress_variables(bset->ctx, bset, T, T2); return bset; error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); *T = NULL; return NULL; } diff --git a/isl_equalities.h b/isl_equalities.h index e579fbee..47fa6da5 100644 --- a/isl_equalities.h +++ b/isl_equalities.h @@ -8,7 +8,7 @@ extern "C" { #endif -struct isl_basic_set *isl_basic_set_remove_equalities(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_remove_equalities( struct isl_basic_set *bset, struct isl_mat **T, struct isl_mat **T2); #if defined(__cplusplus) diff --git a/isl_input.c b/isl_input.c index 53fffc28..1606dcdb 100644 --- a/isl_input.c +++ b/isl_input.c @@ -50,10 +50,10 @@ static struct isl_basic_set *isl_basic_set_read_from_file_polylib( p += offset; isl_assert(ctx, type == 0 || type == 1, goto error); if (type == 0) { - k = isl_basic_set_alloc_equality(ctx, bset); + k = isl_basic_set_alloc_equality(bset); c = bset->eq[k]; } else { - k = isl_basic_set_alloc_inequality(ctx, bset); + k = isl_basic_set_alloc_inequality(bset); c = bset->ineq[k]; } isl_assert(ctx, k >= 0, goto error); @@ -73,11 +73,11 @@ static struct isl_basic_set *isl_basic_set_read_from_file_polylib( isl_assert(ctx, n != 0, goto error); isl_int_read(c[0], val); } - bset = isl_basic_set_simplify(ctx, bset); - bset = isl_basic_set_finalize(ctx, bset); + bset = isl_basic_set_simplify(bset); + bset = isl_basic_set_finalize(bset); return bset; error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } @@ -109,7 +109,7 @@ static struct isl_set *isl_set_read_from_file_polylib( isl_assert(ctx, set->dim == set->p[i]->dim, goto error); return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } diff --git a/isl_input_omega.c b/isl_input_omega.c index 9cd75f5f..089fc346 100644 --- a/isl_input_omega.c +++ b/isl_input_omega.c @@ -1,6 +1,7 @@ #include <ctype.h> #include <string.h> #include <strings.h> +#include "isl_map_private.h" #include "isl_input_omega.h" enum token_type { TOKEN_UNKNOWN = 256, TOKEN_VALUE, TOKEN_IDENT, TOKEN_GE, @@ -495,12 +496,12 @@ static struct isl_basic_map *add_exists(struct stream *s, if (!*v) goto error; extra = (*v)->n - n; - bmap = isl_basic_map_extend(s->ctx, bmap, bmap->nparam, + bmap = isl_basic_map_extend(bmap, bmap->nparam, bmap->n_in, bmap->n_out, extra, 0, 0); total = bmap->nparam+bmap->n_in+bmap->n_out+bmap->extra; for (i = 0; i < extra; ++i) { int k; - if ((k = isl_basic_map_alloc_div(s->ctx, bmap)) < 0) + if ((k = isl_basic_map_alloc_div(bmap)) < 0) goto error; isl_seq_clr(bmap->div[k], 1+1+total); } @@ -513,7 +514,7 @@ static struct isl_basic_map *add_exists(struct stream *s, goto error; return bmap; error: - isl_basic_map_free(s->ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -536,9 +537,9 @@ static struct isl_basic_map *add_constraint(struct stream *s, } stream_push_token(s, tok); - bmap = isl_basic_map_extend(s->ctx, bmap, bmap->nparam, + bmap = isl_basic_map_extend(bmap, bmap->nparam, bmap->n_in, bmap->n_out, 0, 0, 1); - k = isl_basic_map_alloc_inequality(s->ctx, bmap); + k = isl_basic_map_alloc_inequality(bmap); if (k < 0) goto error; isl_seq_clr(bmap->ineq[k], 1+total); @@ -612,12 +613,12 @@ static struct isl_basic_map *add_constraint(struct stream *s, goto error; } if (equality) - isl_basic_map_inequality_to_equality(s->ctx, bmap, k); + isl_basic_map_inequality_to_equality(bmap, k); return bmap; error: if (tok) token_free(tok); - isl_basic_map_free(s->ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -645,7 +646,7 @@ static struct isl_basic_map *add_constraints(struct stream *s, error: if (tok) token_free(tok); - isl_basic_map_free(s->ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -704,7 +705,7 @@ static struct isl_basic_map *basic_map_read(struct stream *s) return bmap; error: - isl_basic_map_free(s->ctx, bmap); + isl_basic_map_free(bmap); if (v) vars_free(v); return NULL; @@ -732,6 +733,6 @@ struct isl_basic_set *isl_basic_set_read_from_file_omega( isl_assert(ctx, bmap->n_in == 0, goto error); return (struct isl_basic_set *)bmap; error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -59,6 +59,8 @@ static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx, for (i = 0; i < extra; ++i) bmap->div[i] = bmap->block2.data + i * (1 + row_size); + bmap->ctx = ctx; + isl_ctx_ref(ctx); bmap->ref = 1; bmap->flags = 0; bmap->c_size = n_eq + n_ineq; @@ -98,56 +100,55 @@ struct isl_basic_map *isl_basic_map_alloc(struct isl_ctx *ctx, nparam, in, out, extra, n_eq, n_ineq); } -static void dup_constraints(struct isl_ctx *ctx, +static void dup_constraints( struct isl_basic_map *dst, struct isl_basic_map *src) { int i; unsigned total = src->nparam + src->n_in + src->n_out + src->n_div; for (i = 0; i < src->n_eq; ++i) { - int j = isl_basic_map_alloc_equality(ctx, dst); + int j = isl_basic_map_alloc_equality(dst); isl_seq_cpy(dst->eq[j], src->eq[i], 1+total); } for (i = 0; i < src->n_ineq; ++i) { - int j = isl_basic_map_alloc_inequality(ctx, dst); + int j = isl_basic_map_alloc_inequality(dst); isl_seq_cpy(dst->ineq[j], src->ineq[i], 1+total); } for (i = 0; i < src->n_div; ++i) { - int j = isl_basic_map_alloc_div(ctx, dst); + int j = isl_basic_map_alloc_div(dst); isl_seq_cpy(dst->div[j], src->div[i], 1+1+total); } F_SET(dst, ISL_BASIC_SET_FINAL); } -struct isl_basic_map *isl_basic_map_dup(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_dup(struct isl_basic_map *bmap) { struct isl_basic_map *dup; - dup = isl_basic_map_alloc(ctx, bmap->nparam, + if (!bmap) + return NULL; + dup = isl_basic_map_alloc(bmap->ctx, bmap->nparam, bmap->n_in, bmap->n_out, bmap->n_div, bmap->n_eq, bmap->n_ineq); if (!dup) return NULL; dup->flags = bmap->flags; - dup_constraints(ctx, dup, bmap); - dup->sample = isl_vec_copy(ctx, bmap->sample); + dup_constraints(dup, bmap); + dup->sample = isl_vec_copy(bmap->ctx, bmap->sample); return dup; } -struct isl_basic_set *isl_basic_set_dup(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_dup(struct isl_basic_set *bset) { struct isl_basic_map *dup; - dup = isl_basic_map_dup(ctx, (struct isl_basic_map *)bset); + dup = isl_basic_map_dup((struct isl_basic_map *)bset); return (struct isl_basic_set *)dup; } -struct isl_basic_set *isl_basic_set_copy(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_copy(struct isl_basic_set *bset) { if (!bset) return NULL; @@ -156,10 +157,10 @@ struct isl_basic_set *isl_basic_set_copy(struct isl_ctx *ctx, bset->ref++; return bset; } - return isl_basic_set_dup(ctx, bset); + return isl_basic_set_dup(bset); } -struct isl_set *isl_set_copy(struct isl_ctx *ctx, struct isl_set *set) +struct isl_set *isl_set_copy(struct isl_set *set) { if (!set) return NULL; @@ -168,8 +169,7 @@ struct isl_set *isl_set_copy(struct isl_ctx *ctx, struct isl_set *set) return set; } -struct isl_basic_map *isl_basic_map_copy(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_copy(struct isl_basic_map *bmap) { if (!bmap) return NULL; @@ -178,10 +178,10 @@ struct isl_basic_map *isl_basic_map_copy(struct isl_ctx *ctx, bmap->ref++; return bmap; } - return isl_basic_map_dup(ctx, bmap); + return isl_basic_map_dup(bmap); } -struct isl_map *isl_map_copy(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_copy(struct isl_map *map) { if (!map) return NULL; @@ -190,7 +190,7 @@ struct isl_map *isl_map_copy(struct isl_ctx *ctx, struct isl_map *map) return map; } -void isl_basic_map_free(struct isl_ctx *ctx, struct isl_basic_map *bmap) +void isl_basic_map_free(struct isl_basic_map *bmap) { if (!bmap) return; @@ -198,29 +198,31 @@ void isl_basic_map_free(struct isl_ctx *ctx, struct isl_basic_map *bmap) if (--bmap->ref > 0) return; + isl_ctx_deref(bmap->ctx); free(bmap->div); - isl_blk_free(ctx, bmap->block2); + isl_blk_free(bmap->ctx, bmap->block2); free(bmap->eq); - isl_blk_free(ctx, bmap->block); - isl_vec_free(ctx, bmap->sample); + isl_blk_free(bmap->ctx, bmap->block); + isl_vec_free(bmap->ctx, bmap->sample); free(bmap); } -void isl_basic_set_free(struct isl_ctx *ctx, struct isl_basic_set *bset) +void isl_basic_set_free(struct isl_basic_set *bset) { - isl_basic_map_free(ctx, (struct isl_basic_map *)bset); + isl_basic_map_free((struct isl_basic_map *)bset); } -int isl_basic_map_alloc_equality(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +int isl_basic_map_alloc_equality(struct isl_basic_map *bmap) { + struct isl_ctx *ctx; if (!bmap) return -1; + ctx = bmap->ctx; isl_assert(ctx, bmap->n_eq + bmap->n_ineq < bmap->c_size, return -1); isl_assert(ctx, bmap->eq + bmap->n_eq <= bmap->ineq, return -1); if (bmap->eq + bmap->n_eq == bmap->ineq) { isl_int *t; - int j = isl_basic_map_alloc_inequality(ctx, bmap); + int j = isl_basic_map_alloc_inequality(bmap); if (j < 0) return -1; t = bmap->ineq[0]; @@ -232,25 +234,26 @@ int isl_basic_map_alloc_equality(struct isl_ctx *ctx, return bmap->n_eq++; } -int isl_basic_set_alloc_equality(struct isl_ctx *ctx, - struct isl_basic_set *bset) +int isl_basic_set_alloc_equality(struct isl_basic_set *bset) { - return isl_basic_map_alloc_equality(ctx, (struct isl_basic_map *)bset); + return isl_basic_map_alloc_equality((struct isl_basic_map *)bset); } -int isl_basic_map_free_equality(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned n) +int isl_basic_map_free_equality(struct isl_basic_map *bmap, unsigned n) { - isl_assert(ctx, n <= bmap->n_eq, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, n <= bmap->n_eq, return -1); bmap->n_eq -= n; return 0; } -int isl_basic_map_drop_equality(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned pos) +int isl_basic_map_drop_equality(struct isl_basic_map *bmap, unsigned pos) { isl_int *t; - isl_assert(ctx, pos < bmap->n_eq, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, pos < bmap->n_eq, return -1); if (pos != bmap->n_eq - 1) { t = bmap->eq[pos]; @@ -261,14 +264,12 @@ int isl_basic_map_drop_equality(struct isl_ctx *ctx, return 0; } -int isl_basic_set_drop_equality(struct isl_ctx *ctx, - struct isl_basic_set *bset, unsigned pos) +int isl_basic_set_drop_equality(struct isl_basic_set *bset, unsigned pos) { - return isl_basic_map_drop_equality(ctx, - (struct isl_basic_map *)bset, pos); + return isl_basic_map_drop_equality((struct isl_basic_map *)bset, pos); } -void isl_basic_map_inequality_to_equality(struct isl_ctx *ctx, +void isl_basic_map_inequality_to_equality( struct isl_basic_map *bmap, unsigned pos) { isl_int *t; @@ -282,9 +283,12 @@ void isl_basic_map_inequality_to_equality(struct isl_ctx *ctx, bmap->ineq++; } -int isl_basic_map_alloc_inequality(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +int isl_basic_map_alloc_inequality(struct isl_basic_map *bmap) { + struct isl_ctx *ctx; + if (!bmap) + return -1; + ctx = bmap->ctx; isl_assert(ctx, (bmap->ineq - bmap->eq) + bmap->n_ineq < bmap->c_size, return -1); F_CLR(bmap, ISL_BASIC_MAP_NO_IMPLICIT); @@ -292,32 +296,31 @@ int isl_basic_map_alloc_inequality(struct isl_ctx *ctx, return bmap->n_ineq++; } -int isl_basic_set_alloc_inequality(struct isl_ctx *ctx, - struct isl_basic_set *bset) +int isl_basic_set_alloc_inequality(struct isl_basic_set *bset) { - return isl_basic_map_alloc_inequality(ctx, (struct isl_basic_map *)bset); + return isl_basic_map_alloc_inequality((struct isl_basic_map *)bset); } -int isl_basic_map_free_inequality(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned n) +int isl_basic_map_free_inequality(struct isl_basic_map *bmap, unsigned n) { - isl_assert(ctx, n <= bmap->n_ineq, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, n <= bmap->n_ineq, return -1); bmap->n_ineq -= n; return 0; } -int isl_basic_set_free_inequality(struct isl_ctx *ctx, - struct isl_basic_set *bset, unsigned n) +int isl_basic_set_free_inequality(struct isl_basic_set *bset, unsigned n) { - return isl_basic_map_free_inequality(ctx, - (struct isl_basic_map *)bset, n); + return isl_basic_map_free_inequality((struct isl_basic_map *)bset, n); } -int isl_basic_map_drop_inequality(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned pos) +int isl_basic_map_drop_inequality(struct isl_basic_map *bmap, unsigned pos) { isl_int *t; - isl_assert(ctx, pos < bmap->n_ineq, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, pos < bmap->n_ineq, return -1); if (pos != bmap->n_ineq - 1) { t = bmap->ineq[pos]; @@ -328,24 +331,24 @@ int isl_basic_map_drop_inequality(struct isl_ctx *ctx, return 0; } -int isl_basic_set_drop_inequality(struct isl_ctx *ctx, - struct isl_basic_set *bset, unsigned pos) +int isl_basic_set_drop_inequality(struct isl_basic_set *bset, unsigned pos) { - return isl_basic_map_drop_inequality(ctx, - (struct isl_basic_map *)bset, pos); + return isl_basic_map_drop_inequality((struct isl_basic_map *)bset, pos); } -int isl_basic_map_alloc_div(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +int isl_basic_map_alloc_div(struct isl_basic_map *bmap) { - isl_assert(ctx, bmap->n_div < bmap->extra, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, bmap->n_div < bmap->extra, return -1); return bmap->n_div++; } -int isl_basic_map_free_div(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned n) +int isl_basic_map_free_div(struct isl_basic_map *bmap, unsigned n) { - isl_assert(ctx, n <= bmap->n_div, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, n <= bmap->n_div, return -1); bmap->n_div -= n; return 0; } @@ -396,15 +399,14 @@ static void copy_div(struct isl_basic_map *dst_map, isl_int *dst, copy_constraint(dst_map, dst+1, src_map, src+1, in_off, out_off, div_off); } -static struct isl_basic_map *add_constraints(struct isl_ctx *ctx, - struct isl_basic_map *bmap1, +static struct isl_basic_map *add_constraints(struct isl_basic_map *bmap1, struct isl_basic_map *bmap2, unsigned i_pos, unsigned o_pos) { int i; unsigned div_off = bmap1->n_div; for (i = 0; i < bmap2->n_eq; ++i) { - int i1 = isl_basic_map_alloc_equality(ctx, bmap1); + int i1 = isl_basic_map_alloc_equality(bmap1); if (i1 < 0) goto error; copy_constraint(bmap1, bmap1->eq[i1], bmap2, bmap2->eq[i], @@ -412,7 +414,7 @@ static struct isl_basic_map *add_constraints(struct isl_ctx *ctx, } for (i = 0; i < bmap2->n_ineq; ++i) { - int i1 = isl_basic_map_alloc_inequality(ctx, bmap1); + int i1 = isl_basic_map_alloc_inequality(bmap1); if (i1 < 0) goto error; copy_constraint(bmap1, bmap1->ineq[i1], bmap2, bmap2->ineq[i], @@ -420,25 +422,24 @@ static struct isl_basic_map *add_constraints(struct isl_ctx *ctx, } for (i = 0; i < bmap2->n_div; ++i) { - int i1 = isl_basic_map_alloc_div(ctx, bmap1); + int i1 = isl_basic_map_alloc_div(bmap1); if (i1 < 0) goto error; copy_div(bmap1, bmap1->div[i1], bmap2, bmap2->div[i], i_pos, o_pos, div_off); } - isl_basic_map_free(ctx, bmap2); + isl_basic_map_free(bmap2); return bmap1; error: - isl_basic_map_free(ctx, bmap1); - isl_basic_map_free(ctx, bmap2); + isl_basic_map_free(bmap1); + isl_basic_map_free(bmap2); return NULL; } -struct isl_basic_map *isl_basic_map_extend(struct isl_ctx *ctx, - struct isl_basic_map *base, +struct isl_basic_map *isl_basic_map_extend(struct isl_basic_map *base, unsigned nparam, unsigned n_in, unsigned n_out, unsigned extra, unsigned n_eq, unsigned n_ineq) { @@ -446,7 +447,7 @@ struct isl_basic_map *isl_basic_map_extend(struct isl_ctx *ctx, unsigned flags; int dims_ok; - base = isl_basic_map_cow(ctx, base); + base = isl_basic_map_cow(base); if (!base) goto error; @@ -457,16 +458,14 @@ struct isl_basic_map *isl_basic_map_extend(struct isl_ctx *ctx, if (dims_ok && n_eq == 0 && n_ineq == 0) return base; - if (base) { - isl_assert(ctx, base->nparam <= nparam, goto error); - isl_assert(ctx, base->n_in <= n_in, goto error); - isl_assert(ctx, base->n_out <= n_out, goto error); - extra += base->extra; - n_eq += base->n_eq; - n_ineq += base->n_ineq; - } + isl_assert(base->ctx, base->nparam <= nparam, goto error); + isl_assert(base->ctx, base->n_in <= n_in, goto error); + isl_assert(base->ctx, base->n_out <= n_out, goto error); + extra += base->extra; + n_eq += base->n_eq; + n_ineq += base->n_ineq; - ext = isl_basic_map_alloc(ctx, nparam, n_in, n_out, + ext = isl_basic_map_alloc(base->ctx, nparam, n_in, n_out, extra, n_eq, n_ineq); if (!base) return ext; @@ -474,7 +473,7 @@ struct isl_basic_map *isl_basic_map_extend(struct isl_ctx *ctx, goto error; flags = base->flags; - ext = add_constraints(ctx, ext, base, 0, 0); + ext = add_constraints(ext, base, 0, 0); if (ext) { ext->flags = flags; F_CLR(ext, ISL_BASIC_SET_FINAL); @@ -483,42 +482,39 @@ struct isl_basic_map *isl_basic_map_extend(struct isl_ctx *ctx, return ext; error: - isl_basic_map_free(ctx, base); + isl_basic_map_free(base); return NULL; } -struct isl_basic_set *isl_basic_set_extend(struct isl_ctx *ctx, - struct isl_basic_set *base, +struct isl_basic_set *isl_basic_set_extend(struct isl_basic_set *base, unsigned nparam, unsigned dim, unsigned extra, unsigned n_eq, unsigned n_ineq) { return (struct isl_basic_set *) - isl_basic_map_extend(ctx, (struct isl_basic_map *)base, + isl_basic_map_extend((struct isl_basic_map *)base, nparam, 0, dim, extra, n_eq, n_ineq); } -struct isl_basic_set *isl_basic_set_cow(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_cow(struct isl_basic_set *bset) { return (struct isl_basic_set *) - isl_basic_map_cow(ctx, (struct isl_basic_map *)bset); + isl_basic_map_cow((struct isl_basic_map *)bset); } -struct isl_basic_map *isl_basic_map_cow(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_cow(struct isl_basic_map *bmap) { if (!bmap) return NULL; if (bmap->ref > 1) { bmap->ref--; - bmap = isl_basic_map_dup(ctx, bmap); + bmap = isl_basic_map_dup(bmap); } F_CLR(bmap, ISL_BASIC_SET_FINAL); return bmap; } -struct isl_set *isl_set_cow(struct isl_ctx *ctx, struct isl_set *set) +struct isl_set *isl_set_cow(struct isl_set *set) { if (!set) return NULL; @@ -526,10 +522,10 @@ struct isl_set *isl_set_cow(struct isl_ctx *ctx, struct isl_set *set) if (set->ref == 1) return set; set->ref--; - return isl_set_dup(ctx, set); + return isl_set_dup(set); } -struct isl_map *isl_map_cow(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_cow(struct isl_map *map) { if (!map) return NULL; @@ -537,7 +533,7 @@ struct isl_map *isl_map_cow(struct isl_ctx *ctx, struct isl_map *map) if (map->ref == 1) return map; map->ref--; - return isl_map_dup(ctx, map); + return isl_map_dup(map); } static void swap_vars(struct isl_blk blk, isl_int *a, @@ -548,7 +544,7 @@ static void swap_vars(struct isl_blk blk, isl_int *a, isl_seq_cpy(a, blk.data, b_len+a_len); } -struct isl_basic_set *isl_basic_set_swap_vars(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_swap_vars( struct isl_basic_set *bset, unsigned n) { int i; @@ -557,16 +553,16 @@ struct isl_basic_set *isl_basic_set_swap_vars(struct isl_ctx *ctx, if (!bset) goto error; - isl_assert(ctx, n <= bset->dim, goto error); + isl_assert(bset->ctx, n <= bset->dim, goto error); if (n == bset->dim) return bset; - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); if (!bset) return NULL; - blk = isl_blk_alloc(ctx, bset->dim); + blk = isl_blk_alloc(bset->ctx, bset->dim); if (isl_blk_is_error(blk)) goto error; @@ -582,27 +578,26 @@ struct isl_basic_set *isl_basic_set_swap_vars(struct isl_ctx *ctx, swap_vars(blk, bset->div[i]+1+1+bset->nparam, n, bset->dim - n); - isl_blk_free(ctx, blk); + isl_blk_free(bset->ctx, blk); return bset; error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -struct isl_set *isl_set_swap_vars(struct isl_ctx *ctx, - struct isl_set *set, unsigned n) +struct isl_set *isl_set_swap_vars(struct isl_set *set, unsigned n) { int i; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) return NULL; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_swap_vars(ctx, set->p[i], n); + set->p[i] = isl_basic_set_swap_vars(set->p[i], n); if (!set->p[i]) { - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } } @@ -615,7 +610,7 @@ static void constraint_drop_vars(isl_int *c, unsigned n, unsigned rem) isl_seq_clr(c + rem, n); } -struct isl_basic_set *isl_basic_set_drop_vars(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_drop_vars( struct isl_basic_set *bset, unsigned first, unsigned n) { int i; @@ -623,12 +618,12 @@ struct isl_basic_set *isl_basic_set_drop_vars(struct isl_ctx *ctx, if (!bset) goto error; - isl_assert(ctx, first + n <= bset->dim, goto error); + isl_assert(bset->ctx, first + n <= bset->dim, goto error); if (n == 0) return bset; - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); if (!bset) return NULL; @@ -647,13 +642,13 @@ struct isl_basic_set *isl_basic_set_drop_vars(struct isl_ctx *ctx, bset->dim -= n; bset->extra += n; - return isl_basic_set_finalize(ctx, bset); + return isl_basic_set_finalize(bset); error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -struct isl_set *isl_set_drop_vars(struct isl_ctx *ctx, +struct isl_set *isl_set_drop_vars( struct isl_set *set, unsigned first, unsigned n) { int i; @@ -661,16 +656,16 @@ struct isl_set *isl_set_drop_vars(struct isl_ctx *ctx, if (!set) goto error; - isl_assert(ctx, first + n <= set->dim, goto error); + isl_assert(set->ctx, first + n <= set->dim, goto error); if (n == 0) return set; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) goto error; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_drop_vars(ctx, set->p[i], first, n); + set->p[i] = isl_basic_set_drop_vars(set->p[i], first, n); if (!set->p[i]) goto error; } @@ -678,14 +673,14 @@ struct isl_set *isl_set_drop_vars(struct isl_ctx *ctx, return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } /* * We don't cow, as the div is assumed to be redundant. */ -static struct isl_basic_map *isl_basic_map_drop_div(struct isl_ctx *ctx, +static struct isl_basic_map *isl_basic_map_drop_div( struct isl_basic_map *bmap, unsigned div) { int i; @@ -696,14 +691,14 @@ static struct isl_basic_map *isl_basic_map_drop_div(struct isl_ctx *ctx, pos = 1 + bmap->nparam + bmap->n_in + bmap->n_out + div; - isl_assert(ctx, div < bmap->n_div, goto error); + isl_assert(bmap->ctx, div < bmap->n_div, goto error); for (i = 0; i < bmap->n_eq; ++i) constraint_drop_vars(bmap->eq[i]+pos, 1, bmap->extra-div-1); for (i = 0; i < bmap->n_ineq; ++i) { if (!isl_int_is_zero(bmap->ineq[i][pos])) { - isl_basic_map_drop_inequality(ctx, bmap, i); + isl_basic_map_drop_inequality(bmap, i); --i; continue; } @@ -722,16 +717,15 @@ static struct isl_basic_map *isl_basic_map_drop_div(struct isl_ctx *ctx, bmap->div[bmap->n_div - 1] = t; } - isl_basic_map_free_div(ctx, bmap, 1); + isl_basic_map_free_div(bmap, 1); return bmap; error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -static void eliminate_div(struct isl_ctx *ctx, struct isl_basic_map *bmap, - isl_int *eq, unsigned div) +static void eliminate_div(struct isl_basic_map *bmap, isl_int *eq, unsigned div) { int i; unsigned pos = 1 + bmap->nparam + bmap->n_in + bmap->n_out + div; @@ -754,40 +748,38 @@ static void eliminate_div(struct isl_ctx *ctx, struct isl_basic_map *bmap, !isl_int_is_zero(bmap->div[i][1 + pos])) isl_seq_clr(bmap->div[i], 1 + len); - isl_basic_map_drop_div(ctx, bmap, div); + isl_basic_map_drop_div(bmap, div); } -struct isl_basic_map *isl_basic_map_set_to_empty( - struct isl_ctx *ctx, struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_set_to_empty(struct isl_basic_map *bmap) { int i = 0; unsigned total; if (!bmap) goto error; total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->extra; - isl_basic_map_free_div(ctx, bmap, bmap->n_div); - isl_basic_map_free_inequality(ctx, bmap, bmap->n_ineq); + isl_basic_map_free_div(bmap, bmap->n_div); + isl_basic_map_free_inequality(bmap, bmap->n_ineq); if (bmap->n_eq > 0) - isl_basic_map_free_equality(ctx, bmap, bmap->n_eq-1); + isl_basic_map_free_equality(bmap, bmap->n_eq-1); else { - isl_basic_map_alloc_equality(ctx, bmap); + isl_basic_map_alloc_equality(bmap); if (i < 0) goto error; } isl_int_set_si(bmap->eq[i][0], 1); isl_seq_clr(bmap->eq[i]+1, total); F_SET(bmap, ISL_BASIC_MAP_EMPTY); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -struct isl_basic_set *isl_basic_set_set_to_empty( - struct isl_ctx *ctx, struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_set_to_empty(struct isl_basic_set *bset) { return (struct isl_basic_set *) - isl_basic_map_set_to_empty(ctx, (struct isl_basic_map *)bset); + isl_basic_map_set_to_empty((struct isl_basic_map *)bset); } static void swap_equality(struct isl_basic_map *bmap, int a, int b) @@ -822,7 +814,7 @@ static void swap_div(struct isl_basic_map *bmap, int a, int b) isl_int_swap(bmap->div[i][1+1+off+a], bmap->div[i][1+1+off+b]); } -struct isl_basic_map *isl_basic_map_gauss(struct isl_ctx *ctx, +struct isl_basic_map *isl_basic_map_gauss( struct isl_basic_map *bmap, int *progress) { int k; @@ -898,16 +890,16 @@ struct isl_basic_map *isl_basic_map_gauss(struct isl_ctx *ctx, for (k = done; k < bmap->n_eq; ++k) { if (isl_int_is_zero(bmap->eq[k][0])) continue; - return isl_basic_map_set_to_empty(ctx, bmap); + return isl_basic_map_set_to_empty(bmap); } - isl_basic_map_free_equality(ctx, bmap, bmap->n_eq-done); + isl_basic_map_free_equality(bmap, bmap->n_eq-done); return bmap; } -struct isl_basic_set *isl_basic_set_gauss(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_gauss( struct isl_basic_set *bset, int *progress) { - return (struct isl_basic_set*)isl_basic_map_gauss(ctx, + return (struct isl_basic_set*)isl_basic_map_gauss( (struct isl_basic_map *)bset, progress); } @@ -937,7 +929,6 @@ static int hash_index(int *index, unsigned int size, int bits, } static struct isl_basic_map *remove_duplicate_constraints( - struct isl_ctx *ctx, struct isl_basic_map *bmap, int *progress) { unsigned int size; @@ -968,7 +959,7 @@ static struct isl_basic_map *remove_duplicate_constraints( l = index[h] - 1; if (isl_int_lt(bmap->ineq[k][0], bmap->ineq[l][0])) swap_inequality(bmap, k, l); - isl_basic_map_drop_inequality(ctx, bmap, k); + isl_basic_map_drop_inequality(bmap, k); --k; } isl_int_init(sum); @@ -988,10 +979,10 @@ static struct isl_basic_map *remove_duplicate_constraints( * will no longer be valid. * Plus, we probably we want to regauss first. */ - isl_basic_map_drop_inequality(ctx, bmap, l); - isl_basic_map_inequality_to_equality(ctx, bmap, k); + isl_basic_map_drop_inequality(bmap, l); + isl_basic_map_inequality_to_equality(bmap, k); } else - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); break; } isl_int_clear(sum); @@ -1000,7 +991,7 @@ static struct isl_basic_map *remove_duplicate_constraints( return bmap; } -static struct isl_basic_map *remove_duplicate_divs(struct isl_ctx *ctx, +static struct isl_basic_map *remove_duplicate_divs( struct isl_basic_map *bmap, int *progress) { unsigned int size; @@ -1010,10 +1001,12 @@ static struct isl_basic_map *remove_duplicate_divs(struct isl_ctx *ctx, struct isl_blk eq; unsigned total_var = bmap->nparam + bmap->n_in + bmap->n_out; unsigned total = total_var + bmap->n_div; + struct isl_ctx *ctx; if (bmap->n_div <= 1) return bmap; + ctx = bmap->ctx; for (k = bmap->n_div - 1; k >= 0; --k) if (!isl_int_is_zero(bmap->div[k][0])) break; @@ -1048,7 +1041,7 @@ static struct isl_basic_map *remove_duplicate_divs(struct isl_ctx *ctx, l = index[h] - 1; isl_int_set_si(eq.data[1+total_var+k], -1); isl_int_set_si(eq.data[1+total_var+l], 1); - eliminate_div(ctx, bmap, eq.data, l); + eliminate_div(bmap, eq.data, l); isl_int_set_si(eq.data[1+total_var+k], 0); isl_int_set_si(eq.data[1+total_var+l], 0); } @@ -1064,8 +1057,7 @@ out: /* Elimininate divs based on equalities */ static struct isl_basic_map *eliminate_divs_eq( - struct isl_ctx *ctx, struct isl_basic_map *bmap, - int *progress) + struct isl_basic_map *bmap, int *progress) { int d; int i; @@ -1084,18 +1076,17 @@ static struct isl_basic_map *eliminate_divs_eq( continue; modified = 1; *progress = 1; - eliminate_div(ctx, bmap, bmap->eq[i], d); - isl_basic_map_drop_equality(ctx, bmap, i); + eliminate_div(bmap, bmap->eq[i], d); + isl_basic_map_drop_equality(bmap, i); break; } } if (modified) - return eliminate_divs_eq(ctx, bmap, progress); + return eliminate_divs_eq(bmap, progress); return bmap; } -static struct isl_basic_map *normalize_constraints( - struct isl_ctx *ctx, struct isl_basic_map *bmap) +static struct isl_basic_map *normalize_constraints(struct isl_basic_map *bmap) { int i; isl_int gcd; @@ -1106,10 +1097,10 @@ static struct isl_basic_map *normalize_constraints( isl_seq_gcd(bmap->eq[i]+1, total, &gcd); if (isl_int_is_zero(gcd)) { if (!isl_int_is_zero(bmap->eq[i][0])) { - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); break; } - isl_basic_map_drop_equality(ctx, bmap, i); + isl_basic_map_drop_equality(bmap, i); continue; } if (F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) @@ -1117,7 +1108,7 @@ static struct isl_basic_map *normalize_constraints( if (isl_int_is_one(gcd)) continue; if (!isl_int_is_divisible_by(bmap->eq[i][0], gcd)) { - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); break; } isl_seq_scale_down(bmap->eq[i], bmap->eq[i], gcd, 1+total); @@ -1127,10 +1118,10 @@ static struct isl_basic_map *normalize_constraints( isl_seq_gcd(bmap->ineq[i]+1, total, &gcd); if (isl_int_is_zero(gcd)) { if (isl_int_is_neg(bmap->ineq[i][0])) { - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); break; } - isl_basic_map_drop_inequality(ctx, bmap, i); + isl_basic_map_drop_inequality(bmap, i); continue; } if (F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) @@ -1149,7 +1140,7 @@ static struct isl_basic_map *normalize_constraints( /* Eliminate the specified variables from the constraints using * Fourier-Motzkin. The variables themselves are not removed. */ -struct isl_basic_map *isl_basic_map_eliminate_vars(struct isl_ctx *ctx, +struct isl_basic_map *isl_basic_map_eliminate_vars( struct isl_basic_map *bmap, int pos, unsigned n) { int d; @@ -1162,8 +1153,8 @@ struct isl_basic_map *isl_basic_map_eliminate_vars(struct isl_ctx *ctx, total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div; extra = bmap->extra - bmap->n_div; - bmap = isl_basic_map_cow(ctx, bmap); - bmap = isl_basic_map_gauss(ctx, bmap, NULL); + bmap = isl_basic_map_cow(bmap); + bmap = isl_basic_map_gauss(bmap, NULL); for (d = pos + n - 1; d >= pos; --d) { int n_lower, n_upper; if (!bmap) @@ -1171,7 +1162,7 @@ struct isl_basic_map *isl_basic_map_eliminate_vars(struct isl_ctx *ctx, for (i = 0; i < bmap->n_eq; ++i) { if (isl_int_is_zero(bmap->eq[i][1+d])) continue; - isl_basic_map_drop_equality(ctx, bmap, i); + isl_basic_map_drop_equality(bmap, i); break; } if (i < bmap->n_eq) @@ -1184,7 +1175,7 @@ struct isl_basic_map *isl_basic_map_eliminate_vars(struct isl_ctx *ctx, else if (isl_int_is_neg(bmap->ineq[i][1+d])) n_upper++; } - bmap = isl_basic_map_extend(ctx, bmap, + bmap = isl_basic_map_extend(bmap, bmap->nparam, bmap->n_in, bmap->n_out, 0, 0, n_lower * n_upper); for (i = bmap->n_ineq - 1; i >= 0; --i) { @@ -1199,7 +1190,7 @@ struct isl_basic_map *isl_basic_map_eliminate_vars(struct isl_ctx *ctx, if (isl_int_sgn(bmap->ineq[i][1+d]) == isl_int_sgn(bmap->ineq[j][1+d])) continue; - k = isl_basic_map_alloc_inequality(ctx, bmap); + k = isl_basic_map_alloc_inequality(bmap); if (k < 0) goto error; isl_seq_cpy(bmap->ineq[k], bmap->ineq[i], @@ -1208,42 +1199,43 @@ struct isl_basic_map *isl_basic_map_eliminate_vars(struct isl_ctx *ctx, isl_seq_elim(bmap->ineq[k], bmap->ineq[j], 1+d, 1+total, NULL); } - isl_basic_map_drop_inequality(ctx, bmap, i); + isl_basic_map_drop_inequality(bmap, i); i = last + 1; } if (n_lower > 0 && n_upper > 0) { - bmap = normalize_constraints(ctx, bmap); - bmap = isl_basic_map_gauss(ctx, bmap, NULL); + bmap = normalize_constraints(bmap); + bmap = isl_basic_map_gauss(bmap, NULL); if (F_ISSET(bmap, ISL_BASIC_MAP_EMPTY)) break; } } return bmap; error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -struct isl_basic_set *isl_basic_set_eliminate_vars(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_eliminate_vars( struct isl_basic_set *bset, unsigned pos, unsigned n) { - return (struct isl_basic_set *)isl_basic_map_eliminate_vars(ctx, + return (struct isl_basic_set *)isl_basic_map_eliminate_vars( (struct isl_basic_map *)bset, pos, n); } /* Elimininate divs based on inequalities */ static struct isl_basic_map *eliminate_divs_ineq( - struct isl_ctx *ctx, struct isl_basic_map *bmap, - int *progress) + struct isl_basic_map *bmap, int *progress) { int d; int i; unsigned off; + struct isl_ctx *ctx; if (!bmap) return NULL; + ctx = bmap->ctx; off = 1 + bmap->nparam + bmap->n_in + bmap->n_out; for (d = bmap->n_div - 1; d >= 0 ; --d) { @@ -1258,40 +1250,37 @@ static struct isl_basic_map *eliminate_divs_ineq( if (i < bmap->n_ineq) continue; *progress = 1; - bmap = isl_basic_map_eliminate_vars(ctx, bmap, (off-1)+d, 1); + bmap = isl_basic_map_eliminate_vars(bmap, (off-1)+d, 1); if (F_ISSET(bmap, ISL_BASIC_MAP_EMPTY)) break; - bmap = isl_basic_map_drop_div(ctx, bmap, d); + bmap = isl_basic_map_drop_div(bmap, d); if (!bmap) break; } return bmap; } -struct isl_basic_map *isl_basic_map_simplify( - struct isl_ctx *ctx, struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_simplify(struct isl_basic_map *bmap) { int progress = 1; if (!bmap) return NULL; while (progress) { progress = 0; - bmap = normalize_constraints(ctx, bmap); - bmap = eliminate_divs_eq(ctx, bmap, &progress); - bmap = eliminate_divs_ineq(ctx, bmap, &progress); - bmap = isl_basic_map_gauss(ctx, bmap, &progress); - bmap = remove_duplicate_divs(ctx, bmap, &progress); - bmap = remove_duplicate_constraints(ctx, bmap, &progress); + bmap = normalize_constraints(bmap); + bmap = eliminate_divs_eq(bmap, &progress); + bmap = eliminate_divs_ineq(bmap, &progress); + bmap = isl_basic_map_gauss(bmap, &progress); + bmap = remove_duplicate_divs(bmap, &progress); + bmap = remove_duplicate_constraints(bmap, &progress); } return bmap; } -struct isl_basic_set *isl_basic_set_simplify( - struct isl_ctx *ctx, struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_simplify(struct isl_basic_set *bset) { return (struct isl_basic_set *) - isl_basic_map_simplify(ctx, - (struct isl_basic_map *)bset); + isl_basic_map_simplify((struct isl_basic_map *)bset); } static void dump_term(struct isl_basic_map *bmap, @@ -1402,8 +1391,7 @@ static void dump(struct isl_basic_map *bmap, FILE *out, int indent) } } -void isl_basic_set_dump(struct isl_ctx *ctx, struct isl_basic_set *bset, - FILE *out, int indent) +void isl_basic_set_dump(struct isl_basic_set *bset, FILE *out, int indent) { if (!bset) { fprintf(out, "null basic set\n"); @@ -1416,8 +1404,7 @@ void isl_basic_set_dump(struct isl_ctx *ctx, struct isl_basic_set *bset, dump((struct isl_basic_map *)bset, out, indent); } -void isl_basic_map_dump(struct isl_ctx *ctx, struct isl_basic_map *bmap, - FILE *out, int indent) +void isl_basic_map_dump(struct isl_basic_map *bmap, FILE *out, int indent) { if (!bmap) { fprintf(out, "null basic map\n"); @@ -1431,11 +1418,12 @@ void isl_basic_map_dump(struct isl_ctx *ctx, struct isl_basic_map *bmap, dump(bmap, out, indent); } -int isl_inequality_negate(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned pos) +int isl_inequality_negate(struct isl_basic_map *bmap, unsigned pos) { unsigned total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div; - isl_assert(ctx, pos < bmap->n_ineq, return -1); + if (!bmap) + return -1; + isl_assert(bmap->ctx, pos < bmap->n_ineq, return -1); isl_seq_neg(bmap->ineq[pos], bmap->ineq[pos], 1 + total); isl_int_sub_ui(bmap->ineq[pos][0], bmap->ineq[pos][0], 1); return 0; @@ -1452,6 +1440,8 @@ struct isl_set *isl_set_alloc(struct isl_ctx *ctx, if (!set) return NULL; + set->ctx = ctx; + isl_ctx_ref(ctx); set->ref = 1; set->size = n; set->n = 0; @@ -1462,67 +1452,73 @@ struct isl_set *isl_set_alloc(struct isl_ctx *ctx, return set; } -struct isl_set *isl_set_dup(struct isl_ctx *ctx, struct isl_set *set) +struct isl_set *isl_set_dup(struct isl_set *set) { int i; struct isl_set *dup; - dup = isl_set_alloc(ctx, set->nparam, set->dim, set->n, set->flags); + if (!set) + return NULL; + + dup = isl_set_alloc(set->ctx, set->nparam, set->dim, set->n, set->flags); if (!dup) return NULL; for (i = 0; i < set->n; ++i) - dup = isl_set_add(ctx, dup, - isl_basic_set_dup(ctx, set->p[i])); + dup = isl_set_add(dup, + isl_basic_set_dup(set->p[i])); return dup; } -struct isl_set *isl_set_from_basic_set(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_set *isl_set_from_basic_set(struct isl_basic_set *bset) { struct isl_set *set; - set = isl_set_alloc(ctx, bset->nparam, bset->dim, 1, ISL_MAP_DISJOINT); + if (!bset) + return NULL; + + set = isl_set_alloc(bset->ctx, bset->nparam, bset->dim, 1, ISL_MAP_DISJOINT); if (!set) { - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } - return isl_set_add(ctx, set, bset); + return isl_set_add(set, bset); } -struct isl_map *isl_map_from_basic_map(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_map *isl_map_from_basic_map(struct isl_basic_map *bmap) { struct isl_map *map; - map = isl_map_alloc(ctx, bmap->nparam, bmap->n_in, bmap->n_out, 1, + if (!bmap) + return NULL; + + map = isl_map_alloc(bmap->ctx, bmap->nparam, bmap->n_in, bmap->n_out, 1, ISL_MAP_DISJOINT); if (!map) { - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } - return isl_map_add(ctx, map, bmap); + return isl_map_add(map, bmap); } -struct isl_set *isl_set_add(struct isl_ctx *ctx, struct isl_set *set, - struct isl_basic_set *bset) +struct isl_set *isl_set_add(struct isl_set *set, struct isl_basic_set *bset) { if (!bset || !set) goto error; - isl_assert(ctx, set->nparam == bset->nparam, goto error); - isl_assert(ctx, set->dim == bset->dim, goto error); - isl_assert(ctx, set->n < set->size, goto error); + isl_assert(set->ctx, set->nparam == bset->nparam, goto error); + isl_assert(set->ctx, set->dim == bset->dim, goto error); + isl_assert(set->ctx, set->n < set->size, goto error); set->p[set->n] = bset; set->n++; return set; error: if (set) - isl_set_free(ctx, set); + isl_set_free(set); if (bset) - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -void isl_set_free(struct isl_ctx *ctx, struct isl_set *set) +void isl_set_free(struct isl_set *set) { int i; @@ -1532,13 +1528,13 @@ void isl_set_free(struct isl_ctx *ctx, struct isl_set *set) if (--set->ref > 0) return; + isl_ctx_deref(set->ctx); for (i = 0; i < set->n; ++i) - isl_basic_set_free(ctx, set->p[i]); + isl_basic_set_free(set->p[i]); free(set); } -void isl_set_dump(struct isl_ctx *ctx, struct isl_set *set, FILE *out, - int indent) +void isl_set_dump(struct isl_set *set, FILE *out, int indent) { int i; @@ -1552,12 +1548,11 @@ void isl_set_dump(struct isl_ctx *ctx, struct isl_set *set, FILE *out, for (i = 0; i < set->n; ++i) { fprintf(out, "%*s", indent, ""); fprintf(out, "basic set %d:\n", i); - isl_basic_set_dump(ctx, set->p[i], out, indent+4); + isl_basic_set_dump(set->p[i], out, indent+4); } } -void isl_map_dump(struct isl_ctx *ctx, struct isl_map *map, FILE *out, - int indent) +void isl_map_dump(struct isl_map *map, FILE *out, int indent) { int i; @@ -1573,106 +1568,101 @@ void isl_map_dump(struct isl_ctx *ctx, struct isl_map *map, FILE *out, for (i = 0; i < map->n; ++i) { fprintf(out, "%*s", indent, ""); fprintf(out, "basic map %d:\n", i); - isl_basic_map_dump(ctx, map->p[i], out, indent+4); + isl_basic_map_dump(map->p[i], out, indent+4); } } struct isl_basic_map *isl_basic_map_intersect_domain( - struct isl_ctx *ctx, struct isl_basic_map *bmap, - struct isl_basic_set *bset) + struct isl_basic_map *bmap, struct isl_basic_set *bset) { struct isl_basic_map *bmap_domain; if (!bmap || !bset) goto error; - isl_assert(ctx, bset->dim == bmap->n_in, goto error); - isl_assert(ctx, bset->nparam == bmap->nparam, goto error); + isl_assert(bset->ctx, bset->dim == bmap->n_in, goto error); + isl_assert(bset->ctx, bset->nparam == bmap->nparam, goto error); - bmap = isl_basic_map_extend(ctx, bmap, + bmap = isl_basic_map_extend(bmap, bset->nparam, bmap->n_in, bmap->n_out, bset->n_div, bset->n_eq, bset->n_ineq); if (!bmap) goto error; - bmap_domain = isl_basic_map_from_basic_set(ctx, bset, + bmap_domain = isl_basic_map_from_basic_set(bset, bset->dim, 0); - bmap = add_constraints(ctx, bmap, bmap_domain, 0, 0); + bmap = add_constraints(bmap, bmap_domain, 0, 0); - bmap = isl_basic_map_simplify(ctx, bmap); - return isl_basic_map_finalize(ctx, bmap); + bmap = isl_basic_map_simplify(bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); - isl_basic_set_free(ctx, bset); + isl_basic_map_free(bmap); + isl_basic_set_free(bset); return NULL; } struct isl_basic_map *isl_basic_map_intersect_range( - struct isl_ctx *ctx, struct isl_basic_map *bmap, - struct isl_basic_set *bset) + struct isl_basic_map *bmap, struct isl_basic_set *bset) { struct isl_basic_map *bmap_range; if (!bmap || !bset) goto error; - isl_assert(ctx, bset->dim == bmap->n_out, goto error); - isl_assert(ctx, bset->nparam == bmap->nparam, goto error); + isl_assert(bset->ctx, bset->dim == bmap->n_out, goto error); + isl_assert(bset->ctx, bset->nparam == bmap->nparam, goto error); - bmap = isl_basic_map_extend(ctx, bmap, + bmap = isl_basic_map_extend(bmap, bset->nparam, bmap->n_in, bmap->n_out, bset->n_div, bset->n_eq, bset->n_ineq); if (!bmap) goto error; - bmap_range = isl_basic_map_from_basic_set(ctx, bset, + bmap_range = isl_basic_map_from_basic_set(bset, 0, bset->dim); - bmap = add_constraints(ctx, bmap, bmap_range, 0, 0); + bmap = add_constraints(bmap, bmap_range, 0, 0); - bmap = isl_basic_map_simplify(ctx, bmap); - return isl_basic_map_finalize(ctx, bmap); + bmap = isl_basic_map_simplify(bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); - isl_basic_set_free(ctx, bset); + isl_basic_map_free(bmap); + isl_basic_set_free(bset); return NULL; } struct isl_basic_map *isl_basic_map_intersect( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { if (!bmap1 || !bmap2) goto error; - isl_assert(ctx, bmap1->nparam == bmap2->nparam, goto error); - isl_assert(ctx, bmap1->n_in == bmap2->n_in, goto error); - isl_assert(ctx, bmap1->n_out == bmap2->n_out, goto error); + isl_assert(bmap1->ctx, bmap1->nparam == bmap2->nparam, goto error); + isl_assert(bmap1->ctx, bmap1->n_in == bmap2->n_in, goto error); + isl_assert(bmap1->ctx, bmap1->n_out == bmap2->n_out, goto error); - bmap1 = isl_basic_map_extend(ctx, bmap1, + bmap1 = isl_basic_map_extend(bmap1, bmap1->nparam, bmap1->n_in, bmap1->n_out, bmap2->n_div, bmap2->n_eq, bmap2->n_ineq); if (!bmap1) goto error; - bmap1 = add_constraints(ctx, bmap1, bmap2, 0, 0); + bmap1 = add_constraints(bmap1, bmap2, 0, 0); - bmap1 = isl_basic_map_simplify(ctx, bmap1); - return isl_basic_map_finalize(ctx, bmap1); + bmap1 = isl_basic_map_simplify(bmap1); + return isl_basic_map_finalize(bmap1); error: - isl_basic_map_free(ctx, bmap1); - isl_basic_map_free(ctx, bmap2); + isl_basic_map_free(bmap1); + isl_basic_map_free(bmap2); return NULL; } struct isl_basic_set *isl_basic_set_intersect( - struct isl_ctx *ctx, struct isl_basic_set *bset1, - struct isl_basic_set *bset2) + struct isl_basic_set *bset1, struct isl_basic_set *bset2) { return (struct isl_basic_set *) - isl_basic_map_intersect(ctx, + isl_basic_map_intersect( (struct isl_basic_map *)bset1, (struct isl_basic_map *)bset2); } -struct isl_map *isl_map_intersect(struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2) +struct isl_map *isl_map_intersect(struct isl_map *map1, struct isl_map *map2) { unsigned flags = 0; struct isl_map *result; @@ -1685,54 +1675,52 @@ struct isl_map *isl_map_intersect(struct isl_ctx *ctx, struct isl_map *map1, F_ISSET(map2, ISL_MAP_DISJOINT)) FL_SET(flags, ISL_MAP_DISJOINT); - result = isl_map_alloc(ctx, map1->nparam, map1->n_in, map1->n_out, + result = isl_map_alloc(map1->ctx, map1->nparam, map1->n_in, map1->n_out, map1->n * map2->n, flags); if (!result) goto error; for (i = 0; i < map1->n; ++i) for (j = 0; j < map2->n; ++j) { struct isl_basic_map *part; - part = isl_basic_map_intersect(ctx, - isl_basic_map_copy(ctx, map1->p[i]), - isl_basic_map_copy(ctx, map2->p[j])); - if (isl_basic_map_is_empty(ctx, part)) - isl_basic_map_free(ctx, part); + part = isl_basic_map_intersect( + isl_basic_map_copy(map1->p[i]), + isl_basic_map_copy(map2->p[j])); + if (isl_basic_map_is_empty(part)) + isl_basic_map_free(part); else - result = isl_map_add(ctx, result, part); + result = isl_map_add(result, part); if (!result) goto error; } - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return result; error: - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return NULL; } -struct isl_basic_map *isl_basic_map_reverse(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_reverse(struct isl_basic_map *bmap) { struct isl_basic_set *bset; unsigned in; if (!bmap) return NULL; - bmap = isl_basic_map_cow(ctx, bmap); + bmap = isl_basic_map_cow(bmap); if (!bmap) return NULL; in = bmap->n_in; - bset = isl_basic_set_from_basic_map(ctx, bmap); - bset = isl_basic_set_swap_vars(ctx, bset, in); - return isl_basic_map_from_basic_set(ctx, bset, bset->dim-in, in); + bset = isl_basic_set_from_basic_map(bmap); + bset = isl_basic_set_swap_vars(bset, in); + return isl_basic_map_from_basic_set(bset, bset->dim-in, in); } /* Turn final n dimensions into existentially quantified variables. */ struct isl_basic_set *isl_basic_set_project_out( - struct isl_ctx *ctx, struct isl_basic_set *bset, - unsigned n, unsigned flags) + struct isl_basic_set *bset, unsigned n, unsigned flags) { int i; size_t row_size; @@ -1742,16 +1730,16 @@ struct isl_basic_set *isl_basic_set_project_out( if (!bset) return NULL; - isl_assert(ctx, n <= bset->dim, goto error); + isl_assert(bset->ctx, n <= bset->dim, goto error); if (n == 0) return bset; - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); row_size = 1 + bset->nparam + bset->dim + bset->extra; old = bset->block2.data; - bset->block2 = isl_blk_extend(ctx, bset->block2, + bset->block2 = isl_blk_extend(bset->ctx, bset->block2, (bset->extra + n) * (1 + row_size)); if (!bset->block2.data) goto error; @@ -1770,16 +1758,15 @@ struct isl_basic_set *isl_basic_set_project_out( bset->n_div += n; bset->extra += n; bset->dim -= n; - bset = isl_basic_set_simplify(ctx, bset); - return isl_basic_set_finalize(ctx, bset); + bset = isl_basic_set_simplify(bset); + return isl_basic_set_finalize(bset); error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } struct isl_basic_map *isl_basic_map_apply_range( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { struct isl_basic_set *bset; unsigned n_in, n_out; @@ -1787,53 +1774,50 @@ struct isl_basic_map *isl_basic_map_apply_range( if (!bmap1 || !bmap2) goto error; - isl_assert(ctx, bmap1->n_out == bmap2->n_in, goto error); - isl_assert(ctx, bmap1->nparam == bmap2->nparam, goto error); + isl_assert(bmap->ctx, bmap1->n_out == bmap2->n_in, goto error); + isl_assert(bmap->ctx, bmap1->nparam == bmap2->nparam, goto error); n_in = bmap1->n_in; n_out = bmap2->n_out; - bmap2 = isl_basic_map_reverse(ctx, bmap2); + bmap2 = isl_basic_map_reverse(bmap2); if (!bmap2) goto error; - bmap1 = isl_basic_map_extend(ctx, bmap1, bmap1->nparam, + bmap1 = isl_basic_map_extend(bmap1, bmap1->nparam, bmap1->n_in + bmap2->n_in, bmap1->n_out, bmap2->extra, bmap2->n_eq, bmap2->n_ineq); if (!bmap1) goto error; - bmap1 = add_constraints(ctx, bmap1, bmap2, bmap1->n_in - bmap2->n_in, 0); - bmap1 = isl_basic_map_simplify(ctx, bmap1); - bset = isl_basic_set_from_basic_map(ctx, bmap1); - bset = isl_basic_set_project_out(ctx, bset, + bmap1 = add_constraints(bmap1, bmap2, bmap1->n_in - bmap2->n_in, 0); + bmap1 = isl_basic_map_simplify(bmap1); + bset = isl_basic_set_from_basic_map(bmap1); + bset = isl_basic_set_project_out(bset, bset->dim - (n_in + n_out), 0); - return isl_basic_map_from_basic_set(ctx, bset, n_in, n_out); + return isl_basic_map_from_basic_set(bset, n_in, n_out); error: - isl_basic_map_free(ctx, bmap1); - isl_basic_map_free(ctx, bmap2); + isl_basic_map_free(bmap1); + isl_basic_map_free(bmap2); return NULL; } struct isl_basic_set *isl_basic_set_apply( - struct isl_ctx *ctx, struct isl_basic_set *bset, - struct isl_basic_map *bmap) + struct isl_basic_set *bset, struct isl_basic_map *bmap) { if (!bset || !bmap) goto error; - isl_assert(ctx, bset->dim == bmap->n_in, goto error); + isl_assert(bset->ctx, bset->dim == bmap->n_in, goto error); return (struct isl_basic_set *) - isl_basic_map_apply_range(ctx, - (struct isl_basic_map *)bset, bmap); + isl_basic_map_apply_range((struct isl_basic_map *)bset, bmap); error: - isl_basic_set_free(ctx, bset); - isl_basic_map_free(ctx, bmap); + isl_basic_set_free(bset); + isl_basic_map_free(bmap); return NULL; } struct isl_basic_map *isl_basic_map_apply_domain( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { if (!bmap1 || !bmap2) goto error; @@ -1841,12 +1825,12 @@ struct isl_basic_map *isl_basic_map_apply_domain( isl_assert(ctx, bmap1->n_in == bmap2->n_in, goto error); isl_assert(ctx, bmap1->nparam == bmap2->nparam, goto error); - bmap1 = isl_basic_map_reverse(ctx, bmap1); - bmap1 = isl_basic_map_apply_range(ctx, bmap1, bmap2); - return isl_basic_map_reverse(ctx, bmap1); + bmap1 = isl_basic_map_reverse(bmap1); + bmap1 = isl_basic_map_apply_range(bmap1, bmap2); + return isl_basic_map_reverse(bmap1); error: - isl_basic_map_free(ctx, bmap1); - isl_basic_map_free(ctx, bmap2); + isl_basic_map_free(bmap1); + isl_basic_map_free(bmap2); return NULL; } @@ -1854,16 +1838,16 @@ static struct isl_basic_map *var_equal(struct isl_ctx *ctx, struct isl_basic_map *bmap, unsigned pos) { int i; - i = isl_basic_map_alloc_equality(ctx, bmap); + i = isl_basic_map_alloc_equality(bmap); if (i < 0) goto error; isl_seq_clr(bmap->eq[i], 1 + bmap->nparam + bmap->n_in + bmap->n_out + bmap->extra); isl_int_set_si(bmap->eq[i][1+bmap->nparam+pos], -1); isl_int_set_si(bmap->eq[i][1+bmap->nparam+bmap->n_in+pos], 1); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -1871,7 +1855,7 @@ static struct isl_basic_map *var_more(struct isl_ctx *ctx, struct isl_basic_map *bmap, unsigned pos) { int i; - i = isl_basic_map_alloc_inequality(ctx, bmap); + i = isl_basic_map_alloc_inequality(bmap); if (i < 0) goto error; isl_seq_clr(bmap->ineq[i], @@ -1879,9 +1863,9 @@ static struct isl_basic_map *var_more(struct isl_ctx *ctx, isl_int_set_si(bmap->ineq[i][0], -1); isl_int_set_si(bmap->ineq[i][1+bmap->nparam+pos], -1); isl_int_set_si(bmap->ineq[i][1+bmap->nparam+bmap->n_in+pos], 1); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -1889,7 +1873,7 @@ static struct isl_basic_map *var_less(struct isl_ctx *ctx, struct isl_basic_map *bmap, unsigned pos) { int i; - i = isl_basic_map_alloc_inequality(ctx, bmap); + i = isl_basic_map_alloc_inequality(bmap); if (i < 0) goto error; isl_seq_clr(bmap->ineq[i], @@ -1897,9 +1881,9 @@ static struct isl_basic_map *var_less(struct isl_ctx *ctx, isl_int_set_si(bmap->ineq[i][0], -1); isl_int_set_si(bmap->ineq[i][1+bmap->nparam+pos], 1); isl_int_set_si(bmap->ineq[i][1+bmap->nparam+bmap->n_in+pos], -1); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -1913,7 +1897,7 @@ struct isl_basic_map *isl_basic_map_equal(struct isl_ctx *ctx, return NULL; for (i = 0; i < n_equal && bmap; ++i) bmap = var_equal(ctx, bmap, i); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); } struct isl_basic_map *isl_basic_map_less_at(struct isl_ctx *ctx, @@ -1928,7 +1912,7 @@ struct isl_basic_map *isl_basic_map_less_at(struct isl_ctx *ctx, bmap = var_equal(ctx, bmap, i); if (bmap) bmap = var_less(ctx, bmap, pos); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); } struct isl_basic_map *isl_basic_map_more_at(struct isl_ctx *ctx, @@ -1943,16 +1927,15 @@ struct isl_basic_map *isl_basic_map_more_at(struct isl_ctx *ctx, bmap = var_equal(ctx, bmap, i); if (bmap) bmap = var_more(ctx, bmap, pos); - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); } struct isl_basic_map *isl_basic_map_from_basic_set( - struct isl_ctx *ctx, struct isl_basic_set *bset, - unsigned n_in, unsigned n_out) + struct isl_basic_set *bset, unsigned n_in, unsigned n_out) { struct isl_basic_map *bmap; - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); if (!bset) return NULL; @@ -1960,25 +1943,24 @@ struct isl_basic_map *isl_basic_map_from_basic_set( bmap = (struct isl_basic_map *) bset; bmap->n_in = n_in; bmap->n_out = n_out; - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -struct isl_basic_set *isl_basic_set_from_basic_map( - struct isl_ctx *ctx, struct isl_basic_map *bmap) +struct isl_basic_set *isl_basic_set_from_basic_map(struct isl_basic_map *bmap) { if (!bmap) goto error; if (bmap->n_in == 0) return (struct isl_basic_set *)bmap; - bmap = isl_basic_map_cow(ctx, bmap); + bmap = isl_basic_map_cow(bmap); if (!bmap) goto error; bmap->n_out += bmap->n_in; bmap->n_in = 0; - bmap = isl_basic_map_finalize(ctx, bmap); + bmap = isl_basic_map_finalize(bmap); return (struct isl_basic_set *)bmap; error: return NULL; @@ -1993,20 +1975,19 @@ error: * * f - m d >= n */ -static int add_div_constraints(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned div) +static int add_div_constraints(struct isl_basic_map *bmap, unsigned div) { int i, j; unsigned div_pos = 1 + bmap->nparam + bmap->n_in + bmap->n_out + div; unsigned total = bmap->nparam + bmap->n_in + bmap->n_out + bmap->extra; - i = isl_basic_map_alloc_inequality(ctx, bmap); + i = isl_basic_map_alloc_inequality(bmap); if (i < 0) return -1; isl_seq_cpy(bmap->ineq[i], bmap->div[div]+1, 1+total); isl_int_neg(bmap->ineq[i][div_pos], bmap->div[div][0]); - j = isl_basic_map_alloc_inequality(ctx, bmap); + j = isl_basic_map_alloc_inequality(bmap); if (j < 0) return -1; isl_seq_neg(bmap->ineq[j], bmap->ineq[i], 1 + total); @@ -2016,13 +1997,13 @@ static int add_div_constraints(struct isl_ctx *ctx, } struct isl_basic_set *isl_basic_map_underlying_set( - struct isl_ctx *ctx, struct isl_basic_map *bmap) + struct isl_basic_map *bmap) { if (!bmap) goto error; if (bmap->nparam == 0 && bmap->n_in == 0 && bmap->n_div == 0) return (struct isl_basic_set *)bmap; - bmap = isl_basic_map_cow(ctx, bmap); + bmap = isl_basic_map_cow(bmap); if (!bmap) goto error; bmap->n_out += bmap->nparam + bmap->n_in + bmap->n_div; @@ -2030,30 +2011,31 @@ struct isl_basic_set *isl_basic_map_underlying_set( bmap->n_in = 0; bmap->extra -= bmap->n_div; bmap->n_div = 0; - bmap = isl_basic_map_finalize(ctx, bmap); + bmap = isl_basic_map_finalize(bmap); return (struct isl_basic_set *)bmap; error: return NULL; } struct isl_basic_map *isl_basic_map_overlying_set( - struct isl_ctx *ctx, struct isl_basic_set *bset, - struct isl_basic_map *like) + struct isl_basic_set *bset, struct isl_basic_map *like) { struct isl_basic_map *bmap; + struct isl_ctx *ctx; unsigned total; int i, k; if (!bset || !like) goto error; + ctx = bset->ctx; isl_assert(ctx, bset->dim == like->nparam + like->n_in + like->n_out + like->n_div, goto error); if (like->nparam == 0 && like->n_in == 0 && like->n_div == 0) { - isl_basic_map_free(ctx, like); + isl_basic_map_free(like); return (struct isl_basic_map *)bset; } - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); total = bset->dim + bset->extra; if (!bset) goto error; @@ -2075,39 +2057,39 @@ struct isl_basic_map *isl_basic_map_overlying_set( bmap->extra); if (!bmap->div) goto error; - bmap = isl_basic_map_extend(ctx, bmap, bmap->nparam, + bmap = isl_basic_map_extend(bmap, bmap->nparam, bmap->n_in, bmap->n_out, 0, 0, 2 * like->n_div); for (i = 0; i < like->n_div; ++i) { - k = isl_basic_map_alloc_div(ctx, bmap); + k = isl_basic_map_alloc_div(bmap); if (k < 0) goto error; isl_seq_cpy(bmap->div[k], like->div[i], 1 + 1 + ltotal); isl_seq_clr(bmap->div[k]+1+1+ltotal, total - ltotal); - if (add_div_constraints(ctx, bmap, k) < 0) + if (add_div_constraints(bmap, k) < 0) goto error; } } - isl_basic_map_free(ctx, like); - bmap = isl_basic_map_finalize(ctx, bmap); + isl_basic_map_free(like); + bmap = isl_basic_map_finalize(bmap); return bmap; error: - isl_basic_map_free(ctx, like); - isl_basic_set_free(ctx, bset); + isl_basic_map_free(like); + isl_basic_set_free(bset); return NULL; } -struct isl_set *isl_map_underlying_set(struct isl_ctx *ctx, struct isl_map *map) +struct isl_set *isl_map_underlying_set(struct isl_map *map) { int i; - map = isl_map_align_divs(ctx, map); - map = isl_map_cow(ctx, map); + map = isl_map_align_divs(map); + map = isl_map_cow(map); if (!map) return NULL; for (i = 0; i < map->n; ++i) { map->p[i] = (struct isl_basic_map *) - isl_basic_map_underlying_set(ctx, map->p[i]); + isl_basic_map_underlying_set(map->p[i]); if (!map->p[i]) goto error; } @@ -2119,56 +2101,52 @@ struct isl_set *isl_map_underlying_set(struct isl_ctx *ctx, struct isl_map *map) map->n_in = 0; return (struct isl_set *)map; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } -struct isl_basic_set *isl_basic_map_domain(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_set *isl_basic_map_domain(struct isl_basic_map *bmap) { struct isl_basic_set *domain; unsigned n_out; if (!bmap) return NULL; n_out = bmap->n_out; - domain = isl_basic_set_from_basic_map(ctx, bmap); - return isl_basic_set_project_out(ctx, domain, n_out, 0); + domain = isl_basic_set_from_basic_map(bmap); + return isl_basic_set_project_out(domain, n_out, 0); } -struct isl_basic_set *isl_basic_map_range(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_set *isl_basic_map_range(struct isl_basic_map *bmap) { - return isl_basic_map_domain(ctx, - isl_basic_map_reverse(ctx, bmap)); + return isl_basic_map_domain(isl_basic_map_reverse(bmap)); } -struct isl_set *isl_map_range(struct isl_ctx *ctx, struct isl_map *map) +struct isl_set *isl_map_range(struct isl_map *map) { int i; struct isl_set *set; if (!map) goto error; - map = isl_map_cow(ctx, map); + map = isl_map_cow(map); if (!map) goto error; set = (struct isl_set *) map; set->zero = 0; for (i = 0; i < map->n; ++i) { - set->p[i] = isl_basic_map_range(ctx, map->p[i]); + set->p[i] = isl_basic_map_range(map->p[i]); if (!set->p[i]) goto error; } F_CLR(set, ISL_MAP_DISJOINT); return set; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } -struct isl_map *isl_map_from_set( - struct isl_ctx *ctx, struct isl_set *set, +struct isl_map *isl_map_from_set(struct isl_set *set, unsigned n_in, unsigned n_out) { int i; @@ -2176,13 +2154,13 @@ struct isl_map *isl_map_from_set( if (!set) return NULL; - isl_assert(ctx, set->dim == n_in + n_out, goto error); - set = isl_set_cow(ctx, set); + isl_assert(set->ctx, set->dim == n_in + n_out, goto error); + set = isl_set_cow(set); if (!set) return NULL; map = (struct isl_map *)set; for (i = 0; i < set->n; ++i) { - map->p[i] = isl_basic_map_from_basic_set(ctx, + map->p[i] = isl_basic_map_from_basic_set( set->p[i], n_in, n_out); if (!map->p[i]) goto error; @@ -2191,7 +2169,7 @@ struct isl_map *isl_map_from_set( map->n_out = n_out; return map; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } @@ -2207,6 +2185,8 @@ struct isl_map *isl_map_alloc(struct isl_ctx *ctx, if (!map) return NULL; + map->ctx = ctx; + isl_ctx_ref(ctx); map->ref = 1; map->size = n; map->n = 0; @@ -2222,7 +2202,7 @@ struct isl_basic_map *isl_basic_map_empty(struct isl_ctx *ctx, { struct isl_basic_map *bmap; bmap = isl_basic_map_alloc(ctx, nparam, in, out, 0, 1, 0); - bmap = isl_basic_map_set_to_empty(ctx, bmap); + bmap = isl_basic_map_set_to_empty(bmap); return bmap; } @@ -2231,7 +2211,7 @@ struct isl_basic_set *isl_basic_set_empty(struct isl_ctx *ctx, { struct isl_basic_set *bset; bset = isl_basic_set_alloc(ctx, nparam, dim, 0, 1, 0); - bset = isl_basic_set_set_to_empty(ctx, bset); + bset = isl_basic_set_set_to_empty(bset); return bset; } @@ -2263,40 +2243,41 @@ struct isl_set *isl_set_empty(struct isl_ctx *ctx, return isl_set_alloc(ctx, nparam, dim, 0, ISL_MAP_DISJOINT); } -struct isl_map *isl_map_dup(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_dup(struct isl_map *map) { int i; struct isl_map *dup; - dup = isl_map_alloc(ctx, map->nparam, map->n_in, map->n_out, map->n, + if (!map) + return NULL; + dup = isl_map_alloc(map->ctx, map->nparam, map->n_in, map->n_out, map->n, map->flags); for (i = 0; i < map->n; ++i) - dup = isl_map_add(ctx, dup, - isl_basic_map_dup(ctx, map->p[i])); + dup = isl_map_add(dup, + isl_basic_map_dup(map->p[i])); return dup; } -struct isl_map *isl_map_add(struct isl_ctx *ctx, struct isl_map *map, - struct isl_basic_map *bmap) +struct isl_map *isl_map_add(struct isl_map *map, struct isl_basic_map *bmap) { if (!bmap || !map) goto error; - isl_assert(ctx, map->nparam == bmap->nparam, goto error); - isl_assert(ctx, map->n_in == bmap->n_in, goto error); - isl_assert(ctx, map->n_out == bmap->n_out, goto error); - isl_assert(ctx, map->n < map->size, goto error); + isl_assert(map->ctx, map->nparam == bmap->nparam, goto error); + isl_assert(map->ctx, map->n_in == bmap->n_in, goto error); + isl_assert(map->ctx, map->n_out == bmap->n_out, goto error); + isl_assert(map->ctx, map->n < map->size, goto error); map->p[map->n] = bmap; map->n++; return map; error: if (map) - isl_map_free(ctx, map); + isl_map_free(map); if (bmap) - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -void isl_map_free(struct isl_ctx *ctx, struct isl_map *map) +void isl_map_free(struct isl_map *map) { int i; @@ -2306,139 +2287,134 @@ void isl_map_free(struct isl_ctx *ctx, struct isl_map *map) if (--map->ref > 0) return; + isl_ctx_deref(map->ctx); for (i = 0; i < map->n; ++i) - isl_basic_map_free(ctx, map->p[i]); + isl_basic_map_free(map->p[i]); free(map); } -struct isl_map *isl_map_extend(struct isl_ctx *ctx, struct isl_map *base, +struct isl_map *isl_map_extend(struct isl_map *base, unsigned nparam, unsigned n_in, unsigned n_out) { int i; - base = isl_map_cow(ctx, base); + base = isl_map_cow(base); if (!base) return NULL; - isl_assert(ctx, base->nparam <= nparam, goto error); - isl_assert(ctx, base->n_in <= n_in, goto error); - isl_assert(ctx, base->n_out <= n_out, goto error); + isl_assert(base->ctx, base->nparam <= nparam, goto error); + isl_assert(base->ctx, base->n_in <= n_in, goto error); + isl_assert(base->ctx, base->n_out <= n_out, goto error); base->nparam = nparam; base->n_in = n_in; base->n_out = n_out; for (i = 0; i < base->n; ++i) { - base->p[i] = isl_basic_map_extend(ctx, base->p[i], + base->p[i] = isl_basic_map_extend(base->p[i], nparam, n_in, n_out, 0, 0, 0); if (!base->p[i]) goto error; } return base; error: - isl_map_free(ctx, base); + isl_map_free(base); return NULL; } -static struct isl_basic_map *isl_basic_map_fix_var(struct isl_ctx *ctx, - struct isl_basic_map *bmap, +static struct isl_basic_map *isl_basic_map_fix_var(struct isl_basic_map *bmap, unsigned var, int value) { int j; - bmap = isl_basic_map_cow(ctx, bmap); - bmap = isl_basic_map_extend(ctx, bmap, + bmap = isl_basic_map_cow(bmap); + bmap = isl_basic_map_extend(bmap, bmap->nparam, bmap->n_in, bmap->n_out, 0, 1, 0); - j = isl_basic_map_alloc_equality(ctx, bmap); + j = isl_basic_map_alloc_equality(bmap); if (j < 0) goto error; isl_seq_clr(bmap->eq[j], 1 + bmap->nparam + bmap->n_in + bmap->n_out + bmap->extra); isl_int_set_si(bmap->eq[j][1 + var], -1); isl_int_set_si(bmap->eq[j][0], value); - bmap = isl_basic_map_simplify(ctx, bmap); - return isl_basic_map_finalize(ctx, bmap); + bmap = isl_basic_map_simplify(bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -struct isl_basic_map *isl_basic_map_fix_input_si(struct isl_ctx *ctx, - struct isl_basic_map *bmap, +struct isl_basic_map *isl_basic_map_fix_input_si(struct isl_basic_map *bmap, unsigned input, int value) { if (!bmap) return NULL; - isl_assert(ctx, input < bmap->n_in, goto error); - return isl_basic_map_fix_var(ctx, bmap, bmap->nparam + input, value); + isl_assert(bmap->ctx, input < bmap->n_in, goto error); + return isl_basic_map_fix_var(bmap, bmap->nparam + input, value); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -struct isl_basic_set *isl_basic_set_fix_dim_si(struct isl_ctx *ctx, - struct isl_basic_set *bset, +struct isl_basic_set *isl_basic_set_fix_dim_si(struct isl_basic_set *bset, unsigned dim, int value) { if (!bset) return NULL; - isl_assert(ctx, dim < bset->dim, goto error); + isl_assert(bset->ctx, dim < bset->dim, goto error); return (struct isl_basic_set *) - isl_basic_map_fix_var(ctx, (struct isl_basic_map *)bset, + isl_basic_map_fix_var((struct isl_basic_map *)bset, bset->nparam + dim, value); error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -struct isl_map *isl_map_fix_input_si(struct isl_ctx *ctx, struct isl_map *map, +struct isl_map *isl_map_fix_input_si(struct isl_map *map, unsigned input, int value) { int i; - map = isl_map_cow(ctx, map); + map = isl_map_cow(map); if (!map) return NULL; isl_assert(ctx, input < map->n_in, goto error); for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_fix_input_si(ctx, map->p[i], - input, value); + map->p[i] = isl_basic_map_fix_input_si(map->p[i], input, value); if (!map->p[i]) goto error; } return map; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } -struct isl_set *isl_set_fix_dim_si(struct isl_ctx *ctx, struct isl_set *set, - unsigned dim, int value) +struct isl_set *isl_set_fix_dim_si(struct isl_set *set, unsigned dim, int value) { int i; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) return NULL; - isl_assert(ctx, dim < set->dim, goto error); + isl_assert(set->ctx, dim < set->dim, goto error); for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_fix_dim_si(ctx, set->p[i], - dim, value); + set->p[i] = isl_basic_set_fix_dim_si(set->p[i], dim, value); if (!set->p[i]) goto error; } return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } -struct isl_map *isl_map_reverse(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_reverse(struct isl_map *map) { int i; unsigned t; - map = isl_map_cow(ctx, map); + map = isl_map_cow(map); if (!map) return NULL; @@ -2446,32 +2422,31 @@ struct isl_map *isl_map_reverse(struct isl_ctx *ctx, struct isl_map *map) map->n_in = map->n_out; map->n_out = t; for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_reverse(ctx, map->p[i]); + map->p[i] = isl_basic_map_reverse(map->p[i]); if (!map->p[i]) goto error; } return map; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } -struct isl_map *isl_basic_map_lexmax(struct isl_ctx *ctx, +struct isl_map *isl_basic_map_lexmax( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty) { - return isl_pip_basic_map_lexmax(ctx, bmap, dom, empty); + return isl_pip_basic_map_lexmax(bmap, dom, empty); } -struct isl_map *isl_basic_map_lexmin(struct isl_ctx *ctx, +struct isl_map *isl_basic_map_lexmin( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty) { - return isl_pip_basic_map_lexmin(ctx, bmap, dom, empty); + return isl_pip_basic_map_lexmin(bmap, dom, empty); } -struct isl_set *isl_basic_set_lexmin(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_set *isl_basic_set_lexmin(struct isl_basic_set *bset) { struct isl_basic_map *bmap = NULL; struct isl_basic_set *dom = NULL; @@ -2479,30 +2454,29 @@ struct isl_set *isl_basic_set_lexmin(struct isl_ctx *ctx, if (!bset) goto error; - bmap = isl_basic_map_from_basic_set(ctx, bset, 0, bset->dim); + bmap = isl_basic_map_from_basic_set(bset, 0, bset->dim); if (!bmap) goto error; - dom = isl_basic_set_alloc(ctx, bmap->nparam, 0, 0, 0, 0); + dom = isl_basic_set_alloc(bmap->ctx, bmap->nparam, 0, 0, 0, 0); if (!dom) goto error; - min = isl_basic_map_lexmin(ctx, bmap, dom, NULL); - return isl_map_range(ctx, min); + min = isl_basic_map_lexmin(bmap, dom, NULL); + return isl_map_range(min); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } -struct isl_map *isl_basic_map_compute_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_map *isl_basic_map_compute_divs(struct isl_basic_map *bmap) { if (!bmap) return NULL; if (bmap->n_div == 0) - return isl_map_from_basic_map(ctx, bmap); - return isl_pip_basic_map_compute_divs(ctx, bmap); + return isl_map_from_basic_map(bmap); + return isl_pip_basic_map_compute_divs(bmap); } -struct isl_map *isl_map_compute_divs(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_compute_divs(struct isl_map *map) { int i; struct isl_map *res; @@ -2511,38 +2485,33 @@ struct isl_map *isl_map_compute_divs(struct isl_ctx *ctx, struct isl_map *map) return NULL; if (map->n == 0) return map; - res = isl_basic_map_compute_divs(ctx, - isl_basic_map_copy(ctx, map->p[0])); + res = isl_basic_map_compute_divs(isl_basic_map_copy(map->p[0])); for (i = 1 ; i < map->n; ++i) { struct isl_map *r2; - r2 = isl_basic_map_compute_divs(ctx, - isl_basic_map_copy(ctx, map->p[i])); + r2 = isl_basic_map_compute_divs(isl_basic_map_copy(map->p[i])); if (F_ISSET(map, ISL_MAP_DISJOINT)) - res = isl_map_union_disjoint(ctx, res, r2); + res = isl_map_union_disjoint(res, r2); else - res = isl_map_union(ctx, res, r2); + res = isl_map_union(res, r2); } - isl_map_free(ctx, map); + isl_map_free(map); return res; } -struct isl_set *isl_basic_set_compute_divs(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_set *isl_basic_set_compute_divs(struct isl_basic_set *bset) { return (struct isl_set *) - isl_basic_map_compute_divs(ctx, - (struct isl_basic_map *)bset); + isl_basic_map_compute_divs((struct isl_basic_map *)bset); } -struct isl_set *isl_set_compute_divs(struct isl_ctx *ctx, - struct isl_set *set) +struct isl_set *isl_set_compute_divs(struct isl_set *set) { return (struct isl_set *) - isl_map_compute_divs(ctx, (struct isl_map *)set); + isl_map_compute_divs((struct isl_map *)set); } -struct isl_set *isl_map_domain(struct isl_ctx *ctx, struct isl_map *map) +struct isl_set *isl_map_domain(struct isl_map *map) { int i; struct isl_set *set; @@ -2550,7 +2519,7 @@ struct isl_set *isl_map_domain(struct isl_ctx *ctx, struct isl_map *map) if (!map) goto error; - map = isl_map_cow(ctx, map); + map = isl_map_cow(map); if (!map) return NULL; @@ -2558,18 +2527,18 @@ struct isl_set *isl_map_domain(struct isl_ctx *ctx, struct isl_map *map) set->dim = map->n_in; set->zero = 0; for (i = 0; i < map->n; ++i) { - set->p[i] = isl_basic_map_domain(ctx, map->p[i]); + set->p[i] = isl_basic_map_domain(map->p[i]); if (!set->p[i]) goto error; } F_CLR(set, ISL_MAP_DISJOINT); return set; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } -struct isl_map *isl_map_union_disjoint(struct isl_ctx *ctx, +struct isl_map *isl_map_union_disjoint( struct isl_map *map1, struct isl_map *map2) { int i; @@ -2580,52 +2549,51 @@ struct isl_map *isl_map_union_disjoint(struct isl_ctx *ctx, goto error; if (map1->n == 0) { - isl_map_free(ctx, map1); + isl_map_free(map1); return map2; } if (map2->n == 0) { - isl_map_free(ctx, map2); + isl_map_free(map2); return map1; } - isl_assert(ctx, map1->nparam == map2->nparam, goto error); - isl_assert(ctx, map1->n_in == map2->n_in, goto error); - isl_assert(ctx, map1->n_out == map2->n_out, goto error); + isl_assert(map1->ctx, map1->nparam == map2->nparam, goto error); + isl_assert(map1->ctx, map1->n_in == map2->n_in, goto error); + isl_assert(map1->ctx, map1->n_out == map2->n_out, goto error); if (F_ISSET(map1, ISL_MAP_DISJOINT) && F_ISSET(map2, ISL_MAP_DISJOINT)) FL_SET(flags, ISL_MAP_DISJOINT); - map = isl_map_alloc(ctx, map1->nparam, map1->n_in, map1->n_out, + map = isl_map_alloc(map1->ctx, map1->nparam, map1->n_in, map1->n_out, map1->n + map2->n, flags); if (!map) goto error; for (i = 0; i < map1->n; ++i) { - map = isl_map_add(ctx, map, - isl_basic_map_copy(ctx, map1->p[i])); + map = isl_map_add(map, + isl_basic_map_copy(map1->p[i])); if (!map) goto error; } for (i = 0; i < map2->n; ++i) { - map = isl_map_add(ctx, map, - isl_basic_map_copy(ctx, map2->p[i])); + map = isl_map_add(map, + isl_basic_map_copy(map2->p[i])); if (!map) goto error; } - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return map; error: - isl_map_free(ctx, map); - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map); + isl_map_free(map1); + isl_map_free(map2); return NULL; } -struct isl_map *isl_map_union(struct isl_ctx *ctx, - struct isl_map *map1, struct isl_map *map2) +struct isl_map *isl_map_union(struct isl_map *map1, struct isl_map *map2) { - map1 = isl_map_union_disjoint(ctx, map1, map2); + map1 = isl_map_union_disjoint(map1, map2); if (!map1) return NULL; if (map1->n > 1) @@ -2633,25 +2601,22 @@ struct isl_map *isl_map_union(struct isl_ctx *ctx, return map1; } -struct isl_set *isl_set_union_disjoint(struct isl_ctx *ctx, +struct isl_set *isl_set_union_disjoint( struct isl_set *set1, struct isl_set *set2) { return (struct isl_set *) - isl_map_union_disjoint(ctx, + isl_map_union_disjoint( (struct isl_map *)set1, (struct isl_map *)set2); } -struct isl_set *isl_set_union(struct isl_ctx *ctx, - struct isl_set *set1, struct isl_set *set2) +struct isl_set *isl_set_union(struct isl_set *set1, struct isl_set *set2) { return (struct isl_set *) - isl_map_union(ctx, - (struct isl_map *)set1, (struct isl_map *)set2); + isl_map_union((struct isl_map *)set1, (struct isl_map *)set2); } struct isl_map *isl_map_intersect_range( - struct isl_ctx *ctx, struct isl_map *map, - struct isl_set *set) + struct isl_map *map, struct isl_set *set) { unsigned flags = 0; struct isl_map *result; @@ -2664,54 +2629,51 @@ struct isl_map *isl_map_intersect_range( F_ISSET(set, ISL_MAP_DISJOINT)) FL_SET(flags, ISL_MAP_DISJOINT); - result = isl_map_alloc(ctx, map->nparam, map->n_in, map->n_out, + result = isl_map_alloc(map->ctx, map->nparam, map->n_in, map->n_out, map->n * set->n, flags); if (!result) goto error; for (i = 0; i < map->n; ++i) for (j = 0; j < set->n; ++j) { - result = isl_map_add(ctx, result, - isl_basic_map_intersect_range(ctx, - isl_basic_map_copy(ctx, map->p[i]), - isl_basic_set_copy(ctx, set->p[j]))); + result = isl_map_add(result, + isl_basic_map_intersect_range( + isl_basic_map_copy(map->p[i]), + isl_basic_set_copy(set->p[j]))); if (!result) goto error; } - isl_map_free(ctx, map); - isl_set_free(ctx, set); + isl_map_free(map); + isl_set_free(set); return result; error: - isl_map_free(ctx, map); - isl_set_free(ctx, set); + isl_map_free(map); + isl_set_free(set); return NULL; } struct isl_map *isl_map_intersect_domain( - struct isl_ctx *ctx, struct isl_map *map, - struct isl_set *set) + struct isl_map *map, struct isl_set *set) { - return isl_map_reverse(ctx, - isl_map_intersect_range(ctx, isl_map_reverse(ctx, map), set)); + return isl_map_reverse( + isl_map_intersect_range(isl_map_reverse(map), set)); } struct isl_map *isl_map_apply_domain( - struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2) + struct isl_map *map1, struct isl_map *map2) { if (!map1 || !map2) goto error; - map1 = isl_map_reverse(ctx, map1); - map1 = isl_map_apply_range(ctx, map1, map2); - return isl_map_reverse(ctx, map1); + map1 = isl_map_reverse(map1); + map1 = isl_map_apply_range(map1, map2); + return isl_map_reverse(map1); error: - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return NULL; } struct isl_map *isl_map_apply_range( - struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2) + struct isl_map *map1, struct isl_map *map2) { struct isl_map *result; int i, j; @@ -2719,38 +2681,37 @@ struct isl_map *isl_map_apply_range( if (!map1 || !map2) goto error; - isl_assert(ctx, map1->nparam == map2->nparam, goto error); - isl_assert(ctx, map1->n_out == map2->n_in, goto error); + isl_assert(map1->ctx, map1->nparam == map2->nparam, goto error); + isl_assert(map1->ctx, map1->n_out == map2->n_in, goto error); - result = isl_map_alloc(ctx, map1->nparam, map1->n_in, map2->n_out, + result = isl_map_alloc(map1->ctx, map1->nparam, map1->n_in, map2->n_out, map1->n * map2->n, 0); if (!result) goto error; for (i = 0; i < map1->n; ++i) for (j = 0; j < map2->n; ++j) { - result = isl_map_add(ctx, result, - isl_basic_map_apply_range(ctx, - isl_basic_map_copy(ctx, map1->p[i]), - isl_basic_map_copy(ctx, map2->p[j]))); + result = isl_map_add(result, + isl_basic_map_apply_range( + isl_basic_map_copy(map1->p[i]), + isl_basic_map_copy(map2->p[j]))); if (!result) goto error; } - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); if (result && result->n <= 1) F_SET(result, ISL_MAP_DISJOINT); return result; error: - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return NULL; } /* * returns range - domain */ -struct isl_basic_set *isl_basic_map_deltas(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_set *isl_basic_map_deltas(struct isl_basic_map *bmap) { struct isl_basic_set *bset; unsigned dim; @@ -2758,14 +2719,14 @@ struct isl_basic_set *isl_basic_map_deltas(struct isl_ctx *ctx, if (!bmap) goto error; - isl_assert(ctx, bmap->n_in == bmap->n_out, goto error); + isl_assert(bmap->ctx, bmap->n_in == bmap->n_out, goto error); dim = bmap->n_in; - bset = isl_basic_set_from_basic_map(ctx, bmap); - bset = isl_basic_set_extend(ctx, bset, bset->nparam, 3*dim, 0, + bset = isl_basic_set_from_basic_map(bmap); + bset = isl_basic_set_extend(bset, bset->nparam, 3*dim, 0, dim, 0); - bset = isl_basic_set_swap_vars(ctx, bset, 2*dim); + bset = isl_basic_set_swap_vars(bset, 2*dim); for (i = 0; i < dim; ++i) { - int j = isl_basic_map_alloc_equality(ctx, + int j = isl_basic_map_alloc_equality( (struct isl_basic_map *)bset); if (j < 0) goto error; @@ -2775,9 +2736,9 @@ struct isl_basic_set *isl_basic_map_deltas(struct isl_ctx *ctx, isl_int_set_si(bset->eq[j][1+bset->nparam+dim+i], 1); isl_int_set_si(bset->eq[j][1+bset->nparam+2*dim+i], -1); } - return isl_basic_set_project_out(ctx, bset, 2*dim, 0); + return isl_basic_set_project_out(bset, 2*dim, 0); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -2789,8 +2750,7 @@ error: * * then it can safely be removed. */ -static int div_is_redundant(struct isl_ctx *ctx, struct isl_basic_map *bmap, - int div) +static int div_is_redundant(struct isl_basic_map *bmap, int div) { int i; unsigned pos = 1 + bmap->nparam + bmap->n_in + bmap->n_out + div; @@ -2838,8 +2798,7 @@ static int div_is_redundant(struct isl_ctx *ctx, struct isl_basic_map *bmap, * These can arise when dropping some of the variables in a quast * returned by piplib. */ -static struct isl_basic_map *remove_redundant_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +static struct isl_basic_map *remove_redundant_divs(struct isl_basic_map *bmap) { int i; @@ -2847,62 +2806,59 @@ static struct isl_basic_map *remove_redundant_divs(struct isl_ctx *ctx, return NULL; for (i = bmap->n_div-1; i >= 0; --i) { - if (!div_is_redundant(ctx, bmap, i)) + if (!div_is_redundant(bmap, i)) continue; - bmap = isl_basic_map_drop_div(ctx, bmap, i); + bmap = isl_basic_map_drop_div(bmap, i); } return bmap; } -struct isl_basic_map *isl_basic_map_finalize(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_basic_map *isl_basic_map_finalize(struct isl_basic_map *bmap) { - bmap = remove_redundant_divs(ctx, bmap); + bmap = remove_redundant_divs(bmap); if (!bmap) return NULL; F_SET(bmap, ISL_BASIC_SET_FINAL); return bmap; } -struct isl_basic_set *isl_basic_set_finalize(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_basic_set *isl_basic_set_finalize(struct isl_basic_set *bset) { return (struct isl_basic_set *) - isl_basic_map_finalize(ctx, - (struct isl_basic_map *)bset); + isl_basic_map_finalize((struct isl_basic_map *)bset); } -struct isl_set *isl_set_finalize(struct isl_ctx *ctx, struct isl_set *set) +struct isl_set *isl_set_finalize(struct isl_set *set) { int i; if (!set) return NULL; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_finalize(ctx, set->p[i]); + set->p[i] = isl_basic_set_finalize(set->p[i]); if (!set->p[i]) goto error; } return set; error: - isl_set_free(ctx, set); + isl_set_free(set); return NULL; } -struct isl_map *isl_map_finalize(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_finalize(struct isl_map *map) { int i; if (!map) return NULL; for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_finalize(ctx, map->p[i]); + map->p[i] = isl_basic_map_finalize(map->p[i]); if (!map->p[i]) goto error; } return map; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } @@ -2917,7 +2873,7 @@ struct isl_basic_map *isl_basic_map_identity(struct isl_ctx *ctx, goto error; for (i = 0; i < dim; ++i) { - int j = isl_basic_map_alloc_equality(ctx, bmap); + int j = isl_basic_map_alloc_equality(bmap); if (j < 0) goto error; isl_seq_clr(bmap->eq[j], @@ -2925,9 +2881,9 @@ struct isl_basic_map *isl_basic_map_identity(struct isl_ctx *ctx, isl_int_set_si(bmap->eq[j][1+nparam+i], 1); isl_int_set_si(bmap->eq[j][1+nparam+dim+i], -1); } - return isl_basic_map_finalize(ctx, bmap); + return isl_basic_map_finalize(bmap); error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -2938,31 +2894,27 @@ struct isl_map *isl_map_identity(struct isl_ctx *ctx, ISL_MAP_DISJOINT); if (!map) goto error; - map = isl_map_add(ctx, map, + map = isl_map_add(map, isl_basic_map_identity(ctx, nparam, dim)); return map; error: - isl_map_free(ctx, map); + isl_map_free(map); return NULL; } -int isl_set_is_equal(struct isl_ctx *ctx, - struct isl_set *set1, struct isl_set *set2) +int isl_set_is_equal(struct isl_set *set1, struct isl_set *set2) { - return isl_map_is_equal(ctx, - (struct isl_map *)set1, (struct isl_map *)set2); + return isl_map_is_equal((struct isl_map *)set1, (struct isl_map *)set2); } -int isl_set_is_subset(struct isl_ctx *ctx, - struct isl_set *set1, struct isl_set *set2) +int isl_set_is_subset(struct isl_set *set1, struct isl_set *set2) { - return isl_map_is_subset(ctx, + return isl_map_is_subset( (struct isl_map *)set1, (struct isl_map *)set2); } -int isl_basic_map_is_subset(struct isl_ctx *ctx, - struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) +int isl_basic_map_is_subset( + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { int is_subset; struct isl_map *map1; @@ -2971,41 +2923,39 @@ int isl_basic_map_is_subset(struct isl_ctx *ctx, if (!bmap1 || !bmap2) return -1; - map1 = isl_map_from_basic_map(ctx, - isl_basic_map_copy(ctx, bmap1)); - map2 = isl_map_from_basic_map(ctx, - isl_basic_map_copy(ctx, bmap2)); + map1 = isl_map_from_basic_map(isl_basic_map_copy(bmap1)); + map2 = isl_map_from_basic_map(isl_basic_map_copy(bmap2)); - is_subset = isl_map_is_subset(ctx, map1, map2); + is_subset = isl_map_is_subset(map1, map2); - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return is_subset; } -int isl_basic_map_is_equal(struct isl_ctx *ctx, +int isl_basic_map_is_equal( struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { int is_subset; if (!bmap1 || !bmap2) return -1; - is_subset = isl_basic_map_is_subset(ctx, bmap1, bmap2); + is_subset = isl_basic_map_is_subset(bmap1, bmap2); if (is_subset != 1) return is_subset; - is_subset = isl_basic_map_is_subset(ctx, bmap2, bmap1); + is_subset = isl_basic_map_is_subset(bmap2, bmap1); return is_subset; } -int isl_basic_set_is_equal(struct isl_ctx *ctx, +int isl_basic_set_is_equal( struct isl_basic_set *bset1, struct isl_basic_set *bset2) { - return isl_basic_map_is_equal(ctx, + return isl_basic_map_is_equal( (struct isl_basic_map *)bset1, (struct isl_basic_map *)bset2); } -int isl_map_is_empty(struct isl_ctx *ctx, struct isl_map *map) +int isl_map_is_empty(struct isl_map *map) { int i; int is_empty; @@ -3013,7 +2963,7 @@ int isl_map_is_empty(struct isl_ctx *ctx, struct isl_map *map) if (!map) return -1; for (i = 0; i < map->n; ++i) { - is_empty = isl_basic_map_is_empty(ctx, map->p[i]); + is_empty = isl_basic_map_is_empty(map->p[i]); if (is_empty < 0) return -1; if (!is_empty) @@ -3022,13 +2972,12 @@ int isl_map_is_empty(struct isl_ctx *ctx, struct isl_map *map) return 1; } -int isl_set_is_empty(struct isl_ctx *ctx, struct isl_set *set) +int isl_set_is_empty(struct isl_set *set) { - return isl_map_is_empty(ctx, (struct isl_map *)set); + return isl_map_is_empty((struct isl_map *)set); } -int isl_map_is_subset(struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2) +int isl_map_is_subset(struct isl_map *map1, struct isl_map *map2) { int i; int is_subset = 0; @@ -3037,56 +2986,52 @@ int isl_map_is_subset(struct isl_ctx *ctx, struct isl_map *map1, if (!map1 || !map2) return -1; - if (isl_map_is_empty(ctx, map1)) + if (isl_map_is_empty(map1)) return 1; - if (isl_map_is_empty(ctx, map2)) + if (isl_map_is_empty(map2)) return 0; - diff = isl_map_subtract(ctx, isl_map_copy(ctx, map1), - isl_map_copy(ctx, map2)); + diff = isl_map_subtract(isl_map_copy(map1), isl_map_copy(map2)); if (!diff) return -1; - is_subset = isl_map_is_empty(ctx, diff); - isl_map_free(ctx, diff); + is_subset = isl_map_is_empty(diff); + isl_map_free(diff); return is_subset; } -int isl_map_is_equal(struct isl_ctx *ctx, - struct isl_map *map1, struct isl_map *map2) +int isl_map_is_equal(struct isl_map *map1, struct isl_map *map2) { int is_subset; if (!map1 || !map2) return -1; - is_subset = isl_map_is_subset(ctx, map1, map2); + is_subset = isl_map_is_subset(map1, map2); if (is_subset != 1) return is_subset; - is_subset = isl_map_is_subset(ctx, map2, map1); + is_subset = isl_map_is_subset(map2, map1); return is_subset; } -int isl_basic_map_is_strict_subset(struct isl_ctx *ctx, - struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) +int isl_basic_map_is_strict_subset( + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { int is_subset; if (!bmap1 || !bmap2) return -1; - is_subset = isl_basic_map_is_subset(ctx, bmap1, bmap2); + is_subset = isl_basic_map_is_subset(bmap1, bmap2); if (is_subset != 1) return is_subset; - is_subset = isl_basic_map_is_subset(ctx, bmap2, bmap1); + is_subset = isl_basic_map_is_subset(bmap2, bmap1); if (is_subset == -1) return is_subset; return !is_subset; } -static int basic_map_contains(struct isl_ctx *ctx, struct isl_basic_map *bmap, - struct isl_vec *vec) +static int basic_map_contains(struct isl_basic_map *bmap, struct isl_vec *vec) { int i; unsigned total; @@ -3119,16 +3064,14 @@ static int basic_map_contains(struct isl_ctx *ctx, struct isl_basic_map *bmap, return 1; } -int isl_basic_map_is_universe(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +int isl_basic_map_is_universe(struct isl_basic_map *bmap) { if (!bmap) return -1; return bmap->n_eq == 0 && bmap->n_ineq == 0; } -int isl_basic_map_is_empty(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +int isl_basic_map_is_empty(struct isl_basic_map *bmap) { struct isl_basic_set *bset = NULL; struct isl_vec *sample = NULL; @@ -3143,64 +3086,60 @@ int isl_basic_map_is_empty(struct isl_ctx *ctx, total = 1 + bmap->nparam + bmap->n_in + bmap->n_out + bmap->n_div; if (bmap->sample && bmap->sample->size == total) { - int contains = basic_map_contains(ctx, bmap, bmap->sample); + int contains = basic_map_contains(bmap, bmap->sample); if (contains < 0) return -1; if (contains) return 0; } - bset = isl_basic_map_underlying_set(ctx, - isl_basic_map_copy(ctx, bmap)); + bset = isl_basic_map_underlying_set(isl_basic_map_copy(bmap)); if (!bset) return -1; - sample = isl_basic_set_sample(ctx, bset); + sample = isl_basic_set_sample(bset); if (!sample) return -1; empty = sample->size == 0; if (bmap->sample) - isl_vec_free(ctx, bmap->sample); + isl_vec_free(bmap->ctx, bmap->sample); bmap->sample = sample; return empty; } struct isl_map *isl_basic_map_union( - struct isl_ctx *ctx, struct isl_basic_map *bmap1, - struct isl_basic_map *bmap2) + struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { struct isl_map *map; if (!bmap1 || !bmap2) return NULL; - isl_assert(ctx, bmap1->nparam == bmap2->nparam, goto error); - isl_assert(ctx, bmap1->n_in == bmap2->n_in, goto error); - isl_assert(ctx, bmap1->n_out == bmap2->n_out, goto error); + isl_assert(bmap1->ctx, bmap1->nparam == bmap2->nparam, goto error); + isl_assert(bmap1->ctx, bmap1->n_in == bmap2->n_in, goto error); + isl_assert(bmap1->ctx, bmap1->n_out == bmap2->n_out, goto error); - map = isl_map_alloc(ctx, bmap1->nparam, + map = isl_map_alloc(bmap1->ctx, bmap1->nparam, bmap1->n_in, bmap1->n_out, 2, 0); if (!map) goto error; - map = isl_map_add(ctx, map, bmap1); - map = isl_map_add(ctx, map, bmap2); + map = isl_map_add(map, bmap1); + map = isl_map_add(map, bmap2); return map; error: - isl_basic_map_free(ctx, bmap1); - isl_basic_map_free(ctx, bmap2); + isl_basic_map_free(bmap1); + isl_basic_map_free(bmap2); return NULL; } struct isl_set *isl_basic_set_union( - struct isl_ctx *ctx, struct isl_basic_set *bset1, - struct isl_basic_set *bset2) + struct isl_basic_set *bset1, struct isl_basic_set *bset2) { - return (struct isl_set *)isl_basic_map_union(ctx, + return (struct isl_set *)isl_basic_map_union( (struct isl_basic_map *)bset1, (struct isl_basic_map *)bset2); } /* Order divs such that any div only depends on previous divs */ -static struct isl_basic_map *order_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +static struct isl_basic_map *order_divs(struct isl_basic_map *bmap) { int i; unsigned off = bmap->nparam + bmap->n_in + bmap->n_out; @@ -3232,7 +3171,7 @@ static int find_div(struct isl_basic_map *dst, return -1; } -struct isl_basic_map *isl_basic_map_align_divs(struct isl_ctx *ctx, +struct isl_basic_map *isl_basic_map_align_divs( struct isl_basic_map *dst, struct isl_basic_map *src) { int i; @@ -3241,21 +3180,21 @@ struct isl_basic_map *isl_basic_map_align_divs(struct isl_ctx *ctx, if (src->n_div == 0) return dst; - src = order_divs(ctx, src); - dst = isl_basic_map_extend(ctx, dst, dst->nparam, dst->n_in, + src = order_divs(src); + dst = isl_basic_map_extend(dst, dst->nparam, dst->n_in, dst->n_out, src->n_div, 0, 2 * src->n_div); if (!dst) return NULL; for (i = 0; i < src->n_div; ++i) { int j = find_div(dst, src, i); if (j < 0) { - j = isl_basic_map_alloc_div(ctx, dst); + j = isl_basic_map_alloc_div(dst); if (j < 0) goto error; isl_seq_cpy(dst->div[j], src->div[i], 1+1+total); isl_seq_clr(dst->div[j]+1+1+total, dst->extra - src->n_div); - if (add_div_constraints(ctx, dst, j) < 0) + if (add_div_constraints(dst, j) < 0) goto error; } if (j != i) @@ -3263,29 +3202,28 @@ struct isl_basic_map *isl_basic_map_align_divs(struct isl_ctx *ctx, } return dst; error: - isl_basic_map_free(ctx, dst); + isl_basic_map_free(dst); return NULL; } -struct isl_map *isl_map_align_divs(struct isl_ctx *ctx, struct isl_map *map) +struct isl_map *isl_map_align_divs(struct isl_map *map) { int i; - map = isl_map_compute_divs(ctx, map); - map = isl_map_cow(ctx, map); + map = isl_map_compute_divs(map); + map = isl_map_cow(map); if (!map) return NULL; for (i = 1; i < map->n; ++i) - map->p[0] = isl_basic_map_align_divs(ctx, map->p[0], map->p[i]); + map->p[0] = isl_basic_map_align_divs(map->p[0], map->p[i]); for (i = 1; i < map->n; ++i) - map->p[i] = isl_basic_map_align_divs(ctx, map->p[i], map->p[0]); + map->p[i] = isl_basic_map_align_divs(map->p[i], map->p[0]); return map; } -static struct isl_map *add_cut_constraint(struct isl_ctx *ctx, - struct isl_map *dst, +static struct isl_map *add_cut_constraint(struct isl_map *dst, struct isl_basic_map *src, isl_int *c, unsigned len, int oppose) { @@ -3294,13 +3232,13 @@ static struct isl_map *add_cut_constraint(struct isl_ctx *ctx, int k; unsigned total; - copy = isl_basic_map_copy(ctx, src); - copy = isl_basic_map_cow(ctx, copy); + copy = isl_basic_map_copy(src); + copy = isl_basic_map_cow(copy); if (!copy) goto error; - copy = isl_basic_map_extend(ctx, copy, + copy = isl_basic_map_extend(copy, copy->nparam, copy->n_in, copy->n_out, 0, 0, 1); - k = isl_basic_map_alloc_inequality(ctx, copy); + k = isl_basic_map_alloc_inequality(copy); if (k < 0) goto error; if (oppose) @@ -3309,25 +3247,24 @@ static struct isl_map *add_cut_constraint(struct isl_ctx *ctx, isl_seq_cpy(copy->ineq[k], c, len); total = 1 + copy->nparam + copy->n_in + copy->n_out + copy->extra; isl_seq_clr(copy->ineq[k]+len, total - len); - isl_inequality_negate(ctx, copy, k); - copy = isl_basic_map_simplify(ctx, copy); - copy = isl_basic_map_finalize(ctx, copy); - is_empty = isl_basic_map_is_empty(ctx, copy); + isl_inequality_negate(copy, k); + copy = isl_basic_map_simplify(copy); + copy = isl_basic_map_finalize(copy); + is_empty = isl_basic_map_is_empty(copy); if (is_empty < 0) goto error; if (!is_empty) - dst = isl_map_add(ctx, dst, copy); + dst = isl_map_add(dst, copy); else - isl_basic_map_free(ctx, copy); + isl_basic_map_free(copy); return dst; error: - isl_basic_map_free(ctx, copy); - isl_map_free(ctx, dst); + isl_basic_map_free(copy); + isl_map_free(dst); return NULL; } -static struct isl_map *subtract(struct isl_ctx *ctx, struct isl_map *map, - struct isl_basic_map *bmap) +static struct isl_map *subtract(struct isl_map *map, struct isl_basic_map *bmap) { int i, j, k; unsigned flags = 0; @@ -3344,38 +3281,38 @@ static struct isl_map *subtract(struct isl_ctx *ctx, struct isl_map *map, FL_SET(flags, ISL_MAP_DISJOINT); max = map->n * (2 * bmap->n_eq + bmap->n_ineq); - rest = isl_map_alloc(ctx, map->nparam, map->n_in, map->n_out, + rest = isl_map_alloc(map->ctx, map->nparam, map->n_in, map->n_out, max, flags); if (!rest) goto error; for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_align_divs(ctx, map->p[i], bmap); + map->p[i] = isl_basic_map_align_divs(map->p[i], bmap); if (!map->p[i]) goto error; } for (j = 0; j < map->n; ++j) - map->p[j] = isl_basic_map_cow(ctx, map->p[j]); + map->p[j] = isl_basic_map_cow(map->p[j]); for (i = 0; i < bmap->n_eq; ++i) { for (j = 0; j < map->n; ++j) { - rest = add_cut_constraint(ctx, rest, + rest = add_cut_constraint(rest, map->p[j], bmap->eq[i], 1+total, 0); if (!rest) goto error; - rest = add_cut_constraint(ctx, rest, + rest = add_cut_constraint(rest, map->p[j], bmap->eq[i], 1+total, 1); if (!rest) goto error; - map->p[j] = isl_basic_map_extend(ctx, map->p[j], + map->p[j] = isl_basic_map_extend(map->p[j], map->p[j]->nparam, map->p[j]->n_in, map->p[j]->n_out, 0, 1, 0); if (!map->p[j]) goto error; - k = isl_basic_map_alloc_equality(ctx, map->p[j]); + k = isl_basic_map_alloc_equality(map->p[j]); if (k < 0) goto error; isl_seq_cpy(map->p[j]->eq[k], bmap->eq[i], 1+total); @@ -3386,17 +3323,17 @@ static struct isl_map *subtract(struct isl_ctx *ctx, struct isl_map *map, for (i = 0; i < bmap->n_ineq; ++i) { for (j = 0; j < map->n; ++j) { - rest = add_cut_constraint(ctx, rest, + rest = add_cut_constraint(rest, map->p[j], bmap->ineq[i], 1+total, 0); if (!rest) goto error; - map->p[j] = isl_basic_map_extend(ctx, map->p[j], + map->p[j] = isl_basic_map_extend(map->p[j], map->p[j]->nparam, map->p[j]->n_in, map->p[j]->n_out, 0, 0, 1); if (!map->p[j]) goto error; - k = isl_basic_map_alloc_inequality(ctx, map->p[j]); + k = isl_basic_map_alloc_inequality(map->p[j]); if (k < 0) goto error; isl_seq_cpy(map->p[j]->ineq[k], bmap->ineq[i], 1+total); @@ -3405,72 +3342,70 @@ static struct isl_map *subtract(struct isl_ctx *ctx, struct isl_map *map, } } - isl_map_free(ctx, map); + isl_map_free(map); return rest; error: - isl_map_free(ctx, map); - isl_map_free(ctx, rest); + isl_map_free(map); + isl_map_free(rest); return NULL; } -struct isl_map *isl_map_subtract(struct isl_ctx *ctx, struct isl_map *map1, - struct isl_map *map2) +struct isl_map *isl_map_subtract(struct isl_map *map1, struct isl_map *map2) { int i; if (!map1 || !map2) goto error; - isl_assert(ctx, map1->nparam == map2->nparam, goto error); - isl_assert(ctx, map1->n_in == map2->n_in, goto error); - isl_assert(ctx, map1->n_out == map2->n_out, goto error); + isl_assert(map1->ctx, map1->nparam == map2->nparam, goto error); + isl_assert(map1->ctx, map1->n_in == map2->n_in, goto error); + isl_assert(map1->ctx, map1->n_out == map2->n_out, goto error); - if (isl_map_is_empty(ctx, map2)) { - isl_map_free(ctx, map2); + if (isl_map_is_empty(map2)) { + isl_map_free(map2); return map1; } - map1 = isl_map_compute_divs(ctx, map1); - map2 = isl_map_compute_divs(ctx, map2); + map1 = isl_map_compute_divs(map1); + map2 = isl_map_compute_divs(map2); if (!map1 || !map2) goto error; for (i = 0; map1 && i < map2->n; ++i) - map1 = subtract(ctx, map1, map2->p[i]); + map1 = subtract(map1, map2->p[i]); - isl_map_free(ctx, map2); + isl_map_free(map2); return map1; error: - isl_map_free(ctx, map1); - isl_map_free(ctx, map2); + isl_map_free(map1); + isl_map_free(map2); return NULL; } -struct isl_set *isl_set_subtract(struct isl_ctx *ctx, struct isl_set *set1, - struct isl_set *set2) +struct isl_set *isl_set_subtract(struct isl_set *set1, struct isl_set *set2) { return (struct isl_set *) - isl_map_subtract(ctx, + isl_map_subtract( (struct isl_map *)set1, (struct isl_map *)set2); } -struct isl_set *isl_set_apply(struct isl_ctx *ctx, struct isl_set *set, - struct isl_map *map) +struct isl_set *isl_set_apply(struct isl_set *set, struct isl_map *map) { - isl_assert(ctx, set->dim == map->n_in, goto error); - map = isl_map_intersect_domain(ctx, map, set); - set = isl_map_range(ctx, map); + if (!set || !map) + goto error; + isl_assert(set->ctx, set->dim == map->n_in, goto error); + map = isl_map_intersect_domain(map, set); + set = isl_map_range(map); return set; error: - isl_set_free(ctx, set); - isl_map_free(ctx, map); + isl_set_free(set); + isl_map_free(map); return NULL; } /* There is no need to cow as removing empty parts doesn't change * the meaning of the set. */ -struct isl_map *isl_map_remove_empty_parts(struct isl_ctx *ctx, - struct isl_map *map) +struct isl_map *isl_map_remove_empty_parts(struct isl_map *map) { int i; @@ -3480,7 +3415,7 @@ struct isl_map *isl_map_remove_empty_parts(struct isl_ctx *ctx, for (i = map->n-1; i >= 0; --i) { if (!F_ISSET(map->p[i], ISL_BASIC_MAP_EMPTY)) continue; - isl_basic_map_free(ctx, map->p[i]); + isl_basic_map_free(map->p[i]); if (i != map->n-1) map->p[i] = map->p[map->n-1]; map->n--; @@ -3489,9 +3424,8 @@ struct isl_map *isl_map_remove_empty_parts(struct isl_ctx *ctx, return map; } -struct isl_set *isl_set_remove_empty_parts(struct isl_ctx *ctx, - struct isl_set *set) +struct isl_set *isl_set_remove_empty_parts(struct isl_set *set) { return (struct isl_set *) - isl_map_remove_empty_parts(ctx, (struct isl_map *)set); + isl_map_remove_empty_parts((struct isl_map *)set); } diff --git a/isl_map_no_piplib.c b/isl_map_no_piplib.c index 469f62c3..b5cd4913 100644 --- a/isl_map_no_piplib.c +++ b/isl_map_no_piplib.c @@ -1,26 +1,25 @@ #include "isl_map_piplib.h" -struct isl_map *isl_pip_basic_map_lexmax(struct isl_ctx *ctx, +struct isl_map *isl_pip_basic_map_lexmax( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty) { - isl_basic_map_free(ctx, bmap); - isl_basic_set_free(ctx, dom); + isl_basic_map_free(bmap); + isl_basic_set_free(dom); return NULL; } -struct isl_map *isl_pip_basic_map_lexmin(struct isl_ctx *ctx, +struct isl_map *isl_pip_basic_map_lexmin( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty) { - isl_basic_map_free(ctx, bmap); - isl_basic_set_free(ctx, dom); + isl_basic_map_free(bmap); + isl_basic_set_free(dom); return NULL; } -struct isl_map *isl_pip_basic_map_compute_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_map *isl_pip_basic_map_compute_divs(struct isl_basic_map *bmap) { - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } diff --git a/isl_map_piplib.c b/isl_map_piplib.c index 8d21c992..2260d748 100644 --- a/isl_map_piplib.c +++ b/isl_map_piplib.c @@ -2,6 +2,7 @@ #include "isl_map.h" #include "isl_piplib.h" #include "isl_map_piplib.h" +#include "isl_map_private.h" static void copy_values_from(isl_int *dst, Entier *src, unsigned n) { @@ -36,7 +37,7 @@ static void copy_constraint_from(isl_int *dst, PipVector *src, static int add_inequality(struct isl_ctx *ctx, struct isl_basic_map *bmap, int *pos, PipVector *vec) { - int i = isl_basic_map_alloc_inequality(ctx, bmap); + int i = isl_basic_map_alloc_inequality(bmap); if (i < 0) return -1; copy_constraint_from(bmap->ineq[i], vec, @@ -67,7 +68,7 @@ static int add_div_constraints(struct isl_ctx *ctx, copy_values_from(&bmap->ineq[i][div_pos], &p->deno, 1); isl_int_neg(bmap->ineq[i][div_pos], bmap->ineq[i][div_pos]); - j = isl_basic_map_alloc_inequality(ctx, bmap); + j = isl_basic_map_alloc_inequality(bmap); if (j < 0) return -1; isl_seq_neg(bmap->ineq[j], bmap->ineq[i], 1 + total); @@ -84,7 +85,7 @@ static int add_equality(struct isl_ctx *ctx, isl_assert(ctx, var < bmap->n_out, return -1); - i = isl_basic_map_alloc_equality(ctx, bmap); + i = isl_basic_map_alloc_equality(bmap); if (i < 0) return -1; copy_constraint_from(bmap->eq[i], vec, @@ -99,7 +100,7 @@ static int find_div(struct isl_ctx *ctx, { int i, j; - i = isl_basic_map_alloc_div(ctx, bmap); + i = isl_basic_map_alloc_div(bmap); if (i < 0) return -1; @@ -110,7 +111,7 @@ static int find_div(struct isl_ctx *ctx, for (j = 0; j < i; ++j) if (isl_seq_eq(bmap->div[i], bmap->div[j], 1+1+bmap->nparam+bmap->n_in+bmap->n_out+j)) { - isl_basic_map_free_div(ctx, bmap, 1); + isl_basic_map_free_div(bmap, 1); return j; } @@ -192,11 +193,11 @@ static struct isl_map *scan_quast_r(struct scan_data *data, PipQuast *q, goto error; map = scan_quast_r(data, q->next_then, map); - if (isl_inequality_negate(data->ctx, bmap, pos)) + if (isl_inequality_negate(bmap, pos)) goto error; map = scan_quast_r(data, q->next_else, map); - if (isl_basic_map_free_inequality(data->ctx, bmap, 1)) + if (isl_basic_map_free_inequality(bmap, 1)) goto error; } else if (q->list) { PipList *l; @@ -208,32 +209,26 @@ static struct isl_map *scan_quast_r(struct scan_data *data, PipQuast *q, if (add_equality(data->ctx, bmap, data->pos, j, l->vector) < 0) goto error; - map = isl_map_add(data->ctx, map, - isl_basic_map_copy(data->ctx, bmap)); - if (isl_basic_map_free_equality(data->ctx, bmap, - bmap->n_out)) + map = isl_map_add(map, isl_basic_map_copy(bmap)); + if (isl_basic_map_free_equality(bmap, bmap->n_out)) goto error; } else if (map->n && data->rest) { /* not interested in rest if no sol */ struct isl_basic_set *bset; - bset = isl_basic_set_from_basic_map(data->ctx, - isl_basic_map_copy(data->ctx, bmap)); - bset = isl_basic_set_drop_vars(data->ctx, bset, - bmap->n_in, bmap->n_out); + bset = isl_basic_set_from_basic_map(isl_basic_map_copy(bmap)); + bset = isl_basic_set_drop_vars(bset, bmap->n_in, bmap->n_out); if (!bset) goto error; - *data->rest = isl_set_add(data->ctx, *data->rest, bset); + *data->rest = isl_set_add(*data->rest, bset); } - if (isl_basic_map_free_inequality(data->ctx, bmap, - 2*(bmap->n_div - old_n_div))) + if (isl_basic_map_free_inequality(bmap, 2*(bmap->n_div - old_n_div))) goto error; - if (isl_basic_map_free_div(data->ctx, bmap, - bmap->n_div - old_n_div)) + if (isl_basic_map_free_div(bmap, bmap->n_div - old_n_div)) goto error; return map; error: - isl_map_free(data->ctx, map); + isl_map_free(map); return NULL; } @@ -283,9 +278,9 @@ static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q, if (!map) goto error; - data.bmap = isl_basic_map_from_basic_set(ctx, context, + data.bmap = isl_basic_map_from_basic_set(context, context->dim, 0); - data.bmap = isl_basic_map_extend(data.ctx, data.bmap, + data.bmap = isl_basic_map_extend(data.bmap, nparam, data.bmap->n_in, keep, nexist, keep, max_depth+2*nexist); if (!data.bmap) goto error; @@ -300,25 +295,25 @@ static struct isl_map *isl_map_from_quast(struct isl_ctx *ctx, PipQuast *q, } map = scan_quast_r(&data, q, map); - map = isl_map_finalize(ctx, map); + map = isl_map_finalize(map); if (!map) goto error; if (rest) { - *rest = isl_set_finalize(ctx, *rest); + *rest = isl_set_finalize(*rest); if (!*rest) goto error; } - isl_basic_map_free(data.ctx, data.bmap); + isl_basic_map_free(data.bmap); if (data.pos) free(data.pos); return map; error: if (data.pos) free(data.pos); - isl_basic_map_free(data.ctx, data.bmap); - isl_map_free(ctx, map); + isl_basic_map_free(data.bmap); + isl_map_free(map); if (rest) { - isl_set_free(ctx, *rest); + isl_set_free(*rest); *rest = NULL; } return NULL; @@ -374,18 +369,20 @@ PipMatrix *isl_basic_map_to_pip(struct isl_basic_map *bmap, unsigned pip_param, return M; } -static struct isl_map *extremum_on(struct isl_ctx *ctx, +static struct isl_map *extremum_on( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty, int max) { PipOptions *options; PipQuast *sol; struct isl_map *map; + struct isl_ctx *ctx; PipMatrix *domain = NULL, *context = NULL; if (!bmap || !dom) goto error; + ctx = bmap->ctx; isl_assert(ctx, bmap->nparam == dom->nparam, goto error); isl_assert(ctx, bmap->n_in == dom->dim, goto error); @@ -406,7 +403,7 @@ static struct isl_map *extremum_on(struct isl_ctx *ctx, if (sol) { struct isl_basic_set *copy; - copy = isl_basic_set_copy(ctx, dom); + copy = isl_basic_set_copy(dom); map = isl_map_from_quast(ctx, sol, bmap->n_out, copy, empty); } else { map = isl_map_empty(ctx, bmap->nparam, bmap->n_in, bmap->n_out); @@ -416,11 +413,11 @@ static struct isl_map *extremum_on(struct isl_ctx *ctx, if (!map) goto error; if (map->n == 0 && empty) { - isl_set_free(ctx, *empty); - *empty = isl_set_from_basic_set(ctx, dom); + isl_set_free(*empty); + *empty = isl_set_from_basic_set(dom); } else - isl_basic_set_free(ctx, dom); - isl_basic_map_free(ctx, bmap); + isl_basic_set_free(dom); + isl_basic_map_free(bmap); pip_quast_free(sol); pip_options_free(options); @@ -433,31 +430,31 @@ error: pip_matrix_free(domain); if (context) pip_matrix_free(context); - isl_basic_map_free(ctx, bmap); - isl_basic_set_free(ctx, dom); + isl_basic_map_free(bmap); + isl_basic_set_free(dom); return NULL; } -struct isl_map *isl_pip_basic_map_lexmax(struct isl_ctx *ctx, +struct isl_map *isl_pip_basic_map_lexmax( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty) { - return extremum_on(ctx, bmap, dom, empty, 1); + return extremum_on(bmap, dom, empty, 1); } -struct isl_map *isl_pip_basic_map_lexmin(struct isl_ctx *ctx, +struct isl_map *isl_pip_basic_map_lexmin( struct isl_basic_map *bmap, struct isl_basic_set *dom, struct isl_set **empty) { - return extremum_on(ctx, bmap, dom, empty, 0); + return extremum_on(bmap, dom, empty, 0); } -struct isl_map *isl_pip_basic_map_compute_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +struct isl_map *isl_pip_basic_map_compute_divs(struct isl_basic_map *bmap) { PipMatrix *domain = NULL, *context = NULL; PipOptions *options; PipQuast *sol; + struct isl_ctx *ctx; struct isl_map *map; struct isl_set *set; struct isl_basic_set *dom; @@ -467,6 +464,7 @@ struct isl_map *isl_pip_basic_map_compute_divs(struct isl_ctx *ctx, if (!bmap) goto error; + ctx = bmap->ctx; n_in = bmap->n_in; n_out = bmap->n_out; @@ -491,17 +489,17 @@ struct isl_map *isl_pip_basic_map_compute_divs(struct isl_ctx *ctx, pip_matrix_free(domain); pip_matrix_free(context); - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); - set = isl_map_domain(ctx, map); + set = isl_map_domain(map); - return isl_map_from_set(ctx, set, n_in, n_out); + return isl_map_from_set(set, n_in, n_out); error: if (domain) pip_matrix_free(domain); if (context) pip_matrix_free(context); - isl_basic_set_free(ctx, dom); - isl_basic_map_free(ctx, bmap); + isl_basic_set_free(dom); + isl_basic_map_free(bmap); return NULL; } diff --git a/isl_map_polylib.c b/isl_map_polylib.c index 3502f82f..802276b9 100644 --- a/isl_map_polylib.c +++ b/isl_map_polylib.c @@ -1,6 +1,7 @@ #include "isl_set.h" #include "isl_map.h" #include "isl_map_polylib.h" +#include "isl_map_private.h" static void copy_values_from(isl_int *dst, Value *src, unsigned n) { @@ -39,7 +40,7 @@ static void copy_constraint_to(Value *dst, isl_int *src, static int add_equality(struct isl_ctx *ctx, struct isl_basic_map *bmap, Value *constraint) { - int i = isl_basic_map_alloc_equality(ctx, bmap); + int i = isl_basic_map_alloc_equality(bmap); if (i < 0) return -1; copy_constraint_from(bmap->eq[i], constraint, bmap->nparam, @@ -50,7 +51,7 @@ static int add_equality(struct isl_ctx *ctx, struct isl_basic_map *bmap, static int add_inequality(struct isl_ctx *ctx, struct isl_basic_map *bmap, Value *constraint) { - int i = isl_basic_map_alloc_inequality(ctx, bmap); + int i = isl_basic_map_alloc_inequality(bmap); if (i < 0) return -1; copy_constraint_from(bmap->ineq[i], constraint, bmap->nparam, @@ -75,14 +76,14 @@ static struct isl_basic_map *copy_constraints( } } for (i = 0; i < bmap->extra; ++i) { - int j = isl_basic_map_alloc_div(ctx, bmap); + int j = isl_basic_map_alloc_div(bmap); if (j == -1) goto error; isl_seq_clr(bmap->div[j], 1+1+total); } return bmap; error: - isl_basic_map_free(ctx, bmap); + isl_basic_map_free(bmap); return NULL; } @@ -128,7 +129,7 @@ struct isl_set *isl_set_new_from_polylib(struct isl_ctx *ctx, return NULL; for (P = D; P; P = P->next) - isl_set_add(ctx, set, + isl_set_add(set, isl_basic_set_new_from_polylib(ctx, P, nparam, dim)); return set; } @@ -149,20 +150,21 @@ struct isl_map *isl_map_new_from_polylib(struct isl_ctx *ctx, return NULL; for (P = D; P; P = P->next) - isl_map_add(ctx, map, - isl_basic_map_new_from_polylib(ctx, P, + isl_map_add(map, isl_basic_map_new_from_polylib(ctx, P, nparam, in, out)); return map; } -Polyhedron *isl_basic_map_to_polylib(struct isl_ctx *ctx, - struct isl_basic_map *bmap) +Polyhedron *isl_basic_map_to_polylib(struct isl_basic_map *bmap) { int i; Matrix *M; Polyhedron *P; unsigned off; + if (!bmap) + return NULL; + M = Matrix_Alloc(bmap->n_eq + bmap->n_ineq, 1 + bmap->n_in + bmap->n_out + bmap->n_div + bmap->nparam + 1); for (i = 0; i < bmap->n_eq; ++i) { @@ -176,34 +178,35 @@ Polyhedron *isl_basic_map_to_polylib(struct isl_ctx *ctx, copy_constraint_to(M->p[off+i], bmap->ineq[i], bmap->nparam, bmap->n_in + bmap->n_out, bmap->n_div); } - P = Constraints2Polyhedron(M, ctx->MaxRays); + P = Constraints2Polyhedron(M, bmap->ctx->MaxRays); Matrix_Free(M); return P; } -Polyhedron *isl_map_to_polylib(struct isl_ctx *ctx, struct isl_map *map) +Polyhedron *isl_map_to_polylib(struct isl_map *map) { int i; Polyhedron *R = NULL; Polyhedron **next = &R; + if (!map) + return NULL; + for (i = 0; i < map->n; ++i) { - *next = isl_basic_map_to_polylib(ctx, map->p[i]); + *next = isl_basic_map_to_polylib(map->p[i]); next = &(*next)->next; } return R; } -Polyhedron *isl_basic_set_to_polylib(struct isl_ctx *ctx, - struct isl_basic_set *bset) +Polyhedron *isl_basic_set_to_polylib(struct isl_basic_set *bset) { - return isl_basic_map_to_polylib(ctx, - (struct isl_basic_map *)bset); + return isl_basic_map_to_polylib((struct isl_basic_map *)bset); } -Polyhedron *isl_set_to_polylib(struct isl_ctx *ctx, struct isl_set *set) +Polyhedron *isl_set_to_polylib(struct isl_set *set) { - return isl_map_to_polylib(ctx, (struct isl_map *)set); + return isl_map_to_polylib((struct isl_map *)set); } diff --git a/isl_map_private.h b/isl_map_private.h index ba73e143..44e31bb5 100644 --- a/isl_map_private.h +++ b/isl_map_private.h @@ -1,71 +1,50 @@ #include "isl_set.h" #include "isl_map.h" -int isl_basic_map_alloc_equality(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -int isl_basic_set_alloc_equality(struct isl_ctx *ctx, - struct isl_basic_set *bset); -int isl_basic_set_free_inequality(struct isl_ctx *ctx, - struct isl_basic_set *bset, unsigned n); -int isl_basic_map_free_equality(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned n); -int isl_basic_set_alloc_inequality(struct isl_ctx *ctx, - struct isl_basic_set *bset); -int isl_basic_map_alloc_inequality(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -int isl_basic_map_free_inequality(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned n); -int isl_basic_map_alloc_div(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -int isl_basic_map_free_div(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned n); -void isl_basic_map_inequality_to_equality(struct isl_ctx *ctx, +int isl_basic_map_alloc_equality(struct isl_basic_map *bmap); +int isl_basic_set_alloc_equality(struct isl_basic_set *bset); +int isl_basic_set_free_inequality(struct isl_basic_set *bset, unsigned n); +int isl_basic_map_free_equality(struct isl_basic_map *bmap, unsigned n); +int isl_basic_set_alloc_inequality(struct isl_basic_set *bset); +int isl_basic_map_alloc_inequality(struct isl_basic_map *bmap); +int isl_basic_map_free_inequality(struct isl_basic_map *bmap, unsigned n); +int isl_basic_map_alloc_div(struct isl_basic_map *bmap); +int isl_basic_map_free_div(struct isl_basic_map *bmap, unsigned n); +void isl_basic_map_inequality_to_equality( struct isl_basic_map *bmap, unsigned pos); -int isl_basic_set_drop_equality(struct isl_ctx *ctx, - struct isl_basic_set *bset, unsigned pos); -int isl_basic_set_drop_inequality(struct isl_ctx *ctx, - struct isl_basic_set *bset, unsigned pos); +int isl_basic_set_drop_equality(struct isl_basic_set *bset, unsigned pos); +int isl_basic_set_drop_inequality(struct isl_basic_set *bset, unsigned pos); -int isl_inequality_negate(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned pos); +int isl_inequality_negate(struct isl_basic_map *bmap, unsigned pos); -struct isl_basic_set *isl_basic_set_cow(struct isl_ctx *ctx, - struct isl_basic_set *bset); -struct isl_basic_map *isl_basic_map_cow(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_set *isl_set_cow(struct isl_ctx *ctx, struct isl_set *set); -struct isl_map *isl_map_cow(struct isl_ctx *ctx, struct isl_map *map); +struct isl_basic_set *isl_basic_set_cow(struct isl_basic_set *bset); +struct isl_basic_map *isl_basic_map_cow(struct isl_basic_map *bmap); +struct isl_set *isl_set_cow(struct isl_set *set); +struct isl_map *isl_map_cow(struct isl_map *map); -struct isl_basic_map *isl_basic_map_set_to_empty( - struct isl_ctx *ctx, struct isl_basic_map *bmap); -struct isl_basic_set *isl_basic_set_set_to_empty( - struct isl_ctx *ctx, struct isl_basic_set *bset); -struct isl_map *isl_basic_map_compute_divs(struct isl_ctx *ctx, - struct isl_basic_map *bmap); -struct isl_map *isl_map_compute_divs(struct isl_ctx *ctx, struct isl_map *map); -struct isl_basic_map *isl_basic_map_align_divs(struct isl_ctx *ctx, +struct isl_basic_map *isl_basic_map_set_to_empty(struct isl_basic_map *bmap); +struct isl_basic_set *isl_basic_set_set_to_empty(struct isl_basic_set *bset); +struct isl_map *isl_basic_map_compute_divs(struct isl_basic_map *bmap); +struct isl_map *isl_map_compute_divs(struct isl_map *map); +struct isl_basic_map *isl_basic_map_align_divs( struct isl_basic_map *dst, struct isl_basic_map *src); -struct isl_map *isl_map_align_divs(struct isl_ctx *ctx, struct isl_map *map); -struct isl_basic_map *isl_basic_map_gauss(struct isl_ctx *ctx, +struct isl_map *isl_map_align_divs(struct isl_map *map); +struct isl_basic_map *isl_basic_map_gauss( struct isl_basic_map *bmap, int *progress); -struct isl_basic_set *isl_basic_set_gauss(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_gauss( struct isl_basic_set *bset, int *progress); -struct isl_basic_map *isl_basic_map_implicit_equalities(struct isl_ctx *ctx, +struct isl_basic_map *isl_basic_map_implicit_equalities( struct isl_basic_map *bmap); -struct isl_basic_set *isl_basic_map_underlying_set( - struct isl_ctx *ctx, struct isl_basic_map *bmap); -struct isl_set *isl_map_underlying_set(struct isl_ctx *ctx, struct isl_map *map); -struct isl_basic_map *isl_basic_map_overlying_set( - struct isl_ctx *ctx, struct isl_basic_set *bset, +struct isl_basic_set *isl_basic_map_underlying_set(struct isl_basic_map *bmap); +struct isl_set *isl_map_underlying_set(struct isl_map *map); +struct isl_basic_map *isl_basic_map_overlying_set(struct isl_basic_set *bset, struct isl_basic_map *like); -struct isl_map *isl_map_remove_empty_parts(struct isl_ctx *ctx, - struct isl_map *map); -struct isl_set *isl_set_remove_empty_parts(struct isl_ctx *ctx, - struct isl_set *set); +struct isl_map *isl_map_remove_empty_parts(struct isl_map *map); +struct isl_set *isl_set_remove_empty_parts(struct isl_set *set); -struct isl_set *isl_set_drop_vars(struct isl_ctx *ctx, +struct isl_set *isl_set_drop_vars( struct isl_set *set, unsigned first, unsigned n); -struct isl_basic_set *isl_basic_set_eliminate_vars(struct isl_ctx *ctx, +struct isl_basic_set *isl_basic_set_eliminate_vars( struct isl_basic_set *bset, unsigned pos, unsigned n); @@ -238,7 +238,7 @@ static void exchange(struct isl_ctx *ctx, struct isl_mat *M, struct isl_mat **U, isl_mat_swap_rows(ctx, *Q, i, j); } -static void subtract(struct isl_ctx *ctx, struct isl_mat *M, struct isl_mat **U, +static void subtract(struct isl_mat *M, struct isl_mat **U, struct isl_mat **Q, unsigned row, unsigned i, unsigned j, isl_int m) { int r, c; @@ -323,7 +323,7 @@ struct isl_mat *isl_mat_left_hermite(struct isl_ctx *ctx, M->n_col-first)) != -1) { first += off; isl_int_fdiv_q(c, M->row[row][first], M->row[row][col]); - subtract(ctx, M, U, Q, row, col, first, c); + subtract(M, U, Q, row, col, first, c); if (!isl_int_is_zero(M->row[row][first])) exchange(ctx, M, U, Q, row, first, col); else @@ -338,7 +338,7 @@ struct isl_mat *isl_mat_left_hermite(struct isl_ctx *ctx, isl_int_fdiv_q(c, M->row[row][i], M->row[row][col]); if (isl_int_is_zero(c)) continue; - subtract(ctx, M, U, Q, row, col, i, c); + subtract(M, U, Q, row, col, i, c); } ++col; } @@ -581,7 +581,7 @@ struct isl_mat *isl_mat_right_inverse(struct isl_ctx *ctx, first += off; isl_int_fdiv_q(a, mat->row[row][first], mat->row[row][row]); - subtract(ctx, mat, &inv, NULL, row, row, first, a); + subtract(mat, &inv, NULL, row, row, first, a); if (!isl_int_is_zero(mat->row[row][first])) exchange(ctx, mat, &inv, NULL, row, row, first); else @@ -683,7 +683,7 @@ struct isl_basic_set *isl_basic_set_preimage(struct isl_ctx *ctx, if (!bset || !mat) goto error; - bset = isl_basic_set_cow(ctx, bset); + bset = isl_basic_set_cow(bset); if (!bset) goto error; @@ -692,7 +692,7 @@ struct isl_basic_set *isl_basic_set_preimage(struct isl_ctx *ctx, isl_assert(ctx, 1+bset->dim == mat->n_row, goto error); if (mat->n_col > mat->n_row) - bset = isl_basic_set_extend(ctx, bset, 0, mat->n_col-1, 0, + bset = isl_basic_set_extend(bset, 0, mat->n_col-1, 0, 0, 0); else { bset->dim -= mat->n_row - mat->n_col; @@ -719,14 +719,14 @@ struct isl_basic_set *isl_basic_set_preimage(struct isl_ctx *ctx, } isl_mat_free(ctx, t); - bset = isl_basic_set_simplify(ctx, bset); - bset = isl_basic_set_finalize(ctx, bset); + bset = isl_basic_set_simplify(bset); + bset = isl_basic_set_finalize(bset); return bset; error: isl_mat_free(ctx, mat); error2: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } @@ -735,10 +735,11 @@ struct isl_set *isl_set_preimage(struct isl_ctx *ctx, { int i; - set = isl_set_cow(ctx, set); + set = isl_set_cow(set); if (!set) return NULL; + ctx = set->ctx; for (i = 0; i < set->n; ++i) { set->p[i] = isl_basic_set_preimage(ctx, set->p[i], isl_mat_copy(ctx, mat)); @@ -750,7 +751,7 @@ struct isl_set *isl_set_preimage(struct isl_ctx *ctx, isl_mat_free(ctx, mat); return set; error: - isl_set_free(ctx, set); + isl_set_free(set); isl_mat_free(ctx, mat); return NULL; } diff --git a/isl_sample.c b/isl_sample.c index 35f08f64..4ad8aebf 100644 --- a/isl_sample.c +++ b/isl_sample.c @@ -9,7 +9,7 @@ static struct isl_vec *point_sample(struct isl_ctx *ctx, struct isl_basic_set *bset) { struct isl_vec *sample; - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); sample = isl_vec_alloc(ctx, 1); if (!sample) return NULL; @@ -22,11 +22,11 @@ static struct isl_vec *interval_sample(struct isl_ctx *ctx, { struct isl_vec *sample; - bset = isl_basic_set_simplify(ctx, bset); + bset = isl_basic_set_simplify(bset); if (!bset) return NULL; if (bset->n_eq > 0) - return isl_basic_set_sample(ctx, bset); + return isl_basic_set_sample(bset); sample = isl_vec_alloc(ctx, 2); isl_int_set_si(sample->block.data[0], 1); if (bset->n_ineq == 0) @@ -51,7 +51,7 @@ static struct isl_vec *interval_sample(struct isl_ctx *ctx, sample = isl_vec_alloc(ctx, 0); } } - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return sample; } @@ -130,19 +130,20 @@ static struct isl_basic_set *remove_lineality(struct isl_ctx *ctx, error: isl_mat_free(ctx, bounds); isl_mat_free(ctx, U); - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -struct isl_vec *isl_basic_set_sample(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_vec *isl_basic_set_sample(struct isl_basic_set *bset) { + struct isl_ctx *ctx; struct isl_mat *bounds; if (!bset) return NULL; + ctx = bset->ctx; if (F_ISSET(bset, ISL_BASIC_SET_EMPTY)) { - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return isl_vec_alloc(ctx, 0); } @@ -153,8 +154,8 @@ struct isl_vec *isl_basic_set_sample(struct isl_ctx *ctx, struct isl_mat *T; struct isl_vec *sample; - bset = isl_basic_set_remove_equalities(ctx, bset, &T, NULL); - sample = isl_basic_set_sample(ctx, bset); + bset = isl_basic_set_remove_equalities(bset, &T, NULL); + sample = isl_basic_set_sample(bset); if (sample && sample->size != 0) sample = isl_mat_vec_product(ctx, T, sample); else @@ -175,15 +176,15 @@ struct isl_vec *isl_basic_set_sample(struct isl_ctx *ctx, struct isl_vec *sample; bset = remove_lineality(ctx, bset, bounds, &T); - sample = isl_basic_set_sample(ctx, bset); + sample = isl_basic_set_sample(bset); if (sample && sample->size != 0) sample = isl_mat_vec_product(ctx, T, sample); else isl_mat_free(ctx, T); return sample; } - return isl_pip_basic_set_sample(ctx, bset); + return isl_pip_basic_set_sample(bset); error: - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } diff --git a/isl_sample.h b/isl_sample.h index 26c8fe39..5a3aaeae 100644 --- a/isl_sample.h +++ b/isl_sample.h @@ -7,8 +7,7 @@ extern "C" { #endif -struct isl_vec *isl_basic_set_sample(struct isl_ctx *ctx, - struct isl_basic_set *bset); +struct isl_vec *isl_basic_set_sample(struct isl_basic_set *bset); #if defined(__cplusplus) } diff --git a/isl_sample_no_piplib.c b/isl_sample_no_piplib.c index 2f4c1a89..27cc6044 100644 --- a/isl_sample_no_piplib.c +++ b/isl_sample_no_piplib.c @@ -1,8 +1,7 @@ #include "isl_sample_piplib.h" -struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_vec *isl_pip_basic_set_sample(struct isl_basic_set *bset) { - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } diff --git a/isl_sample_piplib.c b/isl_sample_piplib.c index b0bf2cfc..9b3dc52f 100644 --- a/isl_sample_piplib.c +++ b/isl_sample_piplib.c @@ -78,18 +78,19 @@ static struct isl_mat *independent_bounds(struct isl_ctx *ctx, /* Skew into positive orthant and project out lineality space */ static struct isl_basic_set *isl_basic_set_skew_to_positive_orthant( - struct isl_ctx *ctx, struct isl_basic_set *bset, - struct isl_mat **T) + struct isl_basic_set *bset, struct isl_mat **T) { struct isl_mat *U = NULL; struct isl_mat *bounds = NULL; int i, j; unsigned old_dim, new_dim; + struct isl_ctx *ctx; *T = NULL; if (!bset) return NULL; + ctx = bset->ctx; isl_assert(ctx, bset->nparam == 0, goto error); isl_assert(ctx, bset->n_div == 0, goto error); isl_assert(ctx, bset->n_eq == 0, goto error); @@ -125,12 +126,11 @@ static struct isl_basic_set *isl_basic_set_skew_to_positive_orthant( error: isl_mat_free(ctx, bounds); isl_mat_free(ctx, U); - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return NULL; } -struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx, - struct isl_basic_set *bset) +struct isl_vec *isl_pip_basic_set_sample(struct isl_basic_set *bset) { PipOptions *options = NULL; PipMatrix *domain = NULL; @@ -138,12 +138,14 @@ struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx, struct isl_vec *vec = NULL; unsigned dim; struct isl_mat *T; + struct isl_ctx *ctx; if (!bset) goto error; + ctx = bset->ctx; isl_assert(ctx, bset->nparam == 0, goto error); isl_assert(ctx, bset->n_div == 0, goto error); - bset = isl_basic_set_skew_to_positive_orthant(ctx, bset, &T); + bset = isl_basic_set_skew_to_positive_orthant(bset, &T); if (!bset) goto error; dim = bset->dim; @@ -181,11 +183,11 @@ struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx, pip_options_free(options); pip_matrix_free(domain); - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); return vec; error: isl_vec_free(ctx, vec); - isl_basic_set_free(ctx, bset); + isl_basic_set_free(bset); if (sol) pip_quast_free(sol); if (domain) diff --git a/isl_sample_piplib.h b/isl_sample_piplib.h index 8f686202..25f23788 100644 --- a/isl_sample_piplib.h +++ b/isl_sample_piplib.h @@ -7,8 +7,7 @@ extern "C" { #endif -struct isl_vec *isl_pip_basic_set_sample(struct isl_ctx *ctx, - struct isl_basic_set *bset); +struct isl_vec *isl_pip_basic_set_sample(struct isl_basic_set *bset); #if defined(__cplusplus) } @@ -23,14 +23,14 @@ void test_application_case(struct isl_ctx *ctx, const char *name) bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA); bmap = isl_basic_map_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA); - bset1 = isl_basic_set_apply(ctx, bset1, bmap); + bset1 = isl_basic_set_apply(bset1, bmap); bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_OMEGA); - assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1); + assert(isl_basic_set_is_equal(bset1, bset2) == 1); - isl_basic_set_free(ctx, bset1); - isl_basic_set_free(ctx, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); fclose(input); } @@ -57,12 +57,12 @@ void test_affine_hull_case(struct isl_ctx *ctx, const char *name) bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB); bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB); - bset1 = isl_basic_set_affine_hull(ctx, bset1); + bset1 = isl_basic_set_affine_hull(bset1); - assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1); + assert(isl_basic_set_is_equal(bset1, bset2) == 1); - isl_basic_set_free(ctx, bset1); - isl_basic_set_free(ctx, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); fclose(input); } @@ -90,15 +90,15 @@ void test_convex_hull_case(struct isl_ctx *ctx, const char *name) bset1 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB); bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB); - set = isl_basic_set_union(ctx, bset1, bset2); - bset1 = isl_set_convex_hull(ctx, set); + set = isl_basic_set_union(bset1, bset2); + bset1 = isl_set_convex_hull(set); bset2 = isl_basic_set_read_from_file(ctx, input, 0, ISL_FORMAT_POLYLIB); - assert(isl_basic_set_is_equal(ctx, bset1, bset2) == 1); + assert(isl_basic_set_is_equal(bset1, bset2) == 1); - isl_basic_set_free(ctx, bset1); - isl_basic_set_free(ctx, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); fclose(input); } |