[polly] r287098 - Update to isl-0.17.1-267-gbf9723d

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 16 03:06:48 PST 2016


Author: grosser
Date: Wed Nov 16 05:06:47 2016
New Revision: 287098

URL: http://llvm.org/viewvc/llvm-project?rev=287098&view=rev
Log:
Update to isl-0.17.1-267-gbf9723d

This update corrects an incorrect generation of min/max expressions in the isl
AST generator and a problematic nullptr dereference.

Added:
    polly/trunk/lib/External/isl/bset_from_bmap.c
    polly/trunk/lib/External/isl/bset_to_bmap.c
    polly/trunk/lib/External/isl/set_from_map.c
    polly/trunk/lib/External/isl/set_to_map.c
    polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.c
    polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.st
Modified:
    polly/trunk/lib/External/isl/GIT_HEAD_ID
    polly/trunk/lib/External/isl/Makefile.am
    polly/trunk/lib/External/isl/Makefile.in
    polly/trunk/lib/External/isl/doc/manual.pdf
    polly/trunk/lib/External/isl/doc/user.pod
    polly/trunk/lib/External/isl/include/isl/constraint.h
    polly/trunk/lib/External/isl/isl_aff.c
    polly/trunk/lib/External/isl/isl_affine_hull.c
    polly/trunk/lib/External/isl/isl_ast_build_expr.c
    polly/trunk/lib/External/isl/isl_coalesce.c
    polly/trunk/lib/External/isl/isl_constraint.c
    polly/trunk/lib/External/isl/isl_convex_hull.c
    polly/trunk/lib/External/isl/isl_dim_map.h
    polly/trunk/lib/External/isl/isl_equalities.c
    polly/trunk/lib/External/isl/isl_lp.c
    polly/trunk/lib/External/isl/isl_map.c
    polly/trunk/lib/External/isl/isl_map_private.h
    polly/trunk/lib/External/isl/isl_map_simplify.c
    polly/trunk/lib/External/isl/isl_map_subtract.c
    polly/trunk/lib/External/isl/isl_output.c
    polly/trunk/lib/External/isl/isl_point.c
    polly/trunk/lib/External/isl/isl_sample.c
    polly/trunk/lib/External/isl/isl_tab.c
    polly/trunk/lib/External/isl/isl_tab_pip.c
    polly/trunk/lib/External/isl/isl_test.c
    polly/trunk/lib/External/isl/isl_transitive_closure.c
    polly/trunk/lib/External/isl/isl_union_map.c
    polly/trunk/lib/External/isl/isl_vertices.c

Modified: polly/trunk/lib/External/isl/GIT_HEAD_ID
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/GIT_HEAD_ID?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/GIT_HEAD_ID (original)
+++ polly/trunk/lib/External/isl/GIT_HEAD_ID Wed Nov 16 05:06:47 2016
@@ -1 +1 @@
-isl-0.17.1-243-g24c0339
+isl-0.17.1-267-gbf9723d

Modified: polly/trunk/lib/External/isl/Makefile.am
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/Makefile.am?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/Makefile.am (original)
+++ polly/trunk/lib/External/isl/Makefile.am Wed Nov 16 05:06:47 2016
@@ -339,6 +339,8 @@ EXTRA_DIST = \
 	LICENSE \
 	isl_config_post.h \
 	basis_reduction_templ.c \
+	bset_to_bmap.c \
+	bset_from_bmap.c \
 	isl_list_templ.c \
 	isl_list_templ.h \
 	isl_map_lexopt_templ.c \
@@ -362,6 +364,8 @@ EXTRA_DIST = \
 	isl_pw_hash.c \
 	isl_pw_union_opt.c \
 	read_in_string_templ.c \
+	set_to_map.c \
+	set_from_map.c \
 	isl_tab_lexopt_templ.c \
 	isl_union_macro.h \
 	isl_union_templ.c \

Modified: polly/trunk/lib/External/isl/Makefile.in
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/Makefile.in?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/Makefile.in (original)
+++ polly/trunk/lib/External/isl/Makefile.in Wed Nov 16 05:06:47 2016
@@ -1107,6 +1107,8 @@ EXTRA_DIST = \
 	LICENSE \
 	isl_config_post.h \
 	basis_reduction_templ.c \
+	bset_to_bmap.c \
+	bset_from_bmap.c \
 	isl_list_templ.c \
 	isl_list_templ.h \
 	isl_map_lexopt_templ.c \
@@ -1130,6 +1132,8 @@ EXTRA_DIST = \
 	isl_pw_hash.c \
 	isl_pw_union_opt.c \
 	read_in_string_templ.c \
+	set_to_map.c \
+	set_from_map.c \
 	isl_tab_lexopt_templ.c \
 	isl_union_macro.h \
 	isl_union_templ.c \

Added: polly/trunk/lib/External/isl/bset_from_bmap.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/bset_from_bmap.c?rev=287098&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/bset_from_bmap.c (added)
+++ polly/trunk/lib/External/isl/bset_from_bmap.c Wed Nov 16 05:06:47 2016
@@ -0,0 +1,8 @@
+#include <isl/map_type.h>
+
+/* Return the basic set that was treated as the basic map "bmap".
+ */
+static __isl_give isl_basic_set *bset_from_bmap(__isl_take isl_basic_map *bmap)
+{
+	return (isl_basic_set *) bmap;
+}

Added: polly/trunk/lib/External/isl/bset_to_bmap.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/bset_to_bmap.c?rev=287098&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/bset_to_bmap.c (added)
+++ polly/trunk/lib/External/isl/bset_to_bmap.c Wed Nov 16 05:06:47 2016
@@ -0,0 +1,10 @@
+#include <isl/map_type.h>
+
+/* Treat "bset" as a basic map.
+ * Internally, isl_basic_set is defined to isl_basic_map, so in practice,
+ * this function performs a redundant cast.
+ */
+static __isl_give isl_basic_map *bset_to_bmap(__isl_take isl_basic_set *bset)
+{
+	return (isl_basic_map *) bset;
+}

Modified: polly/trunk/lib/External/isl/doc/manual.pdf
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/manual.pdf?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
Binary files polly/trunk/lib/External/isl/doc/manual.pdf (original) and polly/trunk/lib/External/isl/doc/manual.pdf Wed Nov 16 05:06:47 2016 differ

Modified: polly/trunk/lib/External/isl/doc/user.pod
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/doc/user.pod?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/doc/user.pod (original)
+++ polly/trunk/lib/External/isl/doc/user.pod Wed Nov 16 05:06:47 2016
@@ -263,6 +263,11 @@ of the printer needs to have been explic
 As a result, the function C<isl_ast_expr_to_str> no longer prints
 the expression in C format.  Use C<isl_ast_expr_to_C_str> instead.
 
+=item * The functions C<isl_set_align_divs> and C<isl_map_align_divs>
+have been deprecated.  The function C<isl_set_lift> has an effect
+that is similar to C<isl_set_align_divs> and could in some cases
+be used as an alternative.
+
 =back
 
 =head1 License
@@ -2101,15 +2106,6 @@ variables as integer divisions of the ot
 including earlier existentially quantified variables.
 An explicitly represented existentially quantified variable therefore
 has a unique value when the values of the other variables are known.
-If, furthermore, the same existentials, i.e., existentials
-with the same explicit representations, should appear in the
-same order in each of the disjuncts of a set or map, then the user should call
-either of the following functions.
-
-	__isl_give isl_set *isl_set_align_divs(
-		__isl_take isl_set *set);
-	__isl_give isl_map *isl_map_align_divs(
-		__isl_take isl_map *map);
 
 Alternatively, the existentially quantified variables can be removed
 using the following functions, which compute an overapproximation.
@@ -7618,7 +7614,7 @@ library.
 
 The function C<isl_basic_set_compute_vertices> performs the
 actual computation of the parametric vertices and the chamber
-decomposition and store the result in an C<isl_vertices> object.
+decomposition and stores the result in an C<isl_vertices> object.
 This information can be queried by either iterating over all
 the vertices or iterating over all the chambers or cells
 and then iterating over all vertices that are active on the chamber.

Modified: polly/trunk/lib/External/isl/include/isl/constraint.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/include/isl/constraint.h?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/include/isl/constraint.h (original)
+++ polly/trunk/lib/External/isl/include/isl/constraint.h Wed Nov 16 05:06:47 2016
@@ -131,6 +131,7 @@ __isl_give isl_aff *isl_constraint_get_a
 __isl_give isl_constraint *isl_equality_from_aff(__isl_take isl_aff *aff);
 __isl_give isl_constraint *isl_inequality_from_aff(__isl_take isl_aff *aff);
 
+ISL_DEPRECATED
 __isl_give isl_basic_set *isl_basic_set_drop_constraint(
 	__isl_take isl_basic_set *bset, __isl_take isl_constraint *constraint);
 

Modified: polly/trunk/lib/External/isl/isl_aff.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_aff.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_aff.c (original)
+++ polly/trunk/lib/External/isl/isl_aff.c Wed Nov 16 05:06:47 2016
@@ -416,6 +416,8 @@ static __isl_give isl_vec *vec_reorder(_
 
 	res = isl_vec_alloc(vec->ctx,
 			    2 + isl_space_dim(r->dim, isl_dim_all) + n_div);
+	if (!res)
+		goto error;
 	isl_seq_cpy(res->el, vec->el, 2);
 	isl_seq_clr(res->el + 2, res->size - 2);
 	for (i = 0; i < r->len; ++i)

Modified: polly/trunk/lib/External/isl/isl_affine_hull.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_affine_hull.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_affine_hull.c (original)
+++ polly/trunk/lib/External/isl/isl_affine_hull.c Wed Nov 16 05:06:47 2016
@@ -24,6 +24,11 @@
 #include <isl_mat_private.h>
 #include <isl_vec_private.h>
 
+#include <bset_to_bmap.c>
+#include <bset_from_bmap.c>
+#include <set_to_map.c>
+#include <set_from_map.c>
+
 struct isl_basic_map *isl_basic_map_implicit_equalities(
 						struct isl_basic_map *bmap)
 {
@@ -57,8 +62,8 @@ error:
 struct isl_basic_set *isl_basic_set_implicit_equalities(
 						struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_implicit_equalities((struct isl_basic_map*)bset);
+	return bset_from_bmap(
+		isl_basic_map_implicit_equalities(bset_to_bmap(bset)));
 }
 
 struct isl_map *isl_map_implicit_equalities(struct isl_map *map)
@@ -1171,8 +1176,8 @@ error:
 __isl_give isl_basic_set *isl_basic_set_detect_equalities(
 						__isl_take isl_basic_set *bset)
 {
-	return (isl_basic_set *)
-		isl_basic_map_detect_equalities((isl_basic_map *)bset);
+	return bset_from_bmap(
+		isl_basic_map_detect_equalities(bset_to_bmap(bset)));
 }
 
 __isl_give isl_map *isl_map_detect_equalities(__isl_take isl_map *map)
@@ -1183,7 +1188,7 @@ __isl_give isl_map *isl_map_detect_equal
 
 __isl_give isl_set *isl_set_detect_equalities(__isl_take isl_set *set)
 {
-	return (isl_set *)isl_map_detect_equalities((isl_map *)set);
+	return set_from_map(isl_map_detect_equalities(set_to_map(set)));
 }
 
 /* Return the superset of "bmap" described by the equalities
@@ -1221,8 +1226,7 @@ struct isl_basic_map *isl_basic_map_affi
 
 struct isl_basic_set *isl_basic_set_affine_hull(struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_affine_hull((struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_affine_hull(bset_to_bmap(bset)));
 }
 
 /* Given a rational affine matrix "M", add stride constraints to "bmap"
@@ -1467,6 +1471,5 @@ error:
 
 struct isl_basic_set *isl_set_affine_hull(struct isl_set *set)
 {
-	return (struct isl_basic_set *)
-		isl_map_affine_hull((struct isl_map *)set);
+	return bset_from_bmap(isl_map_affine_hull(set_to_map(set)));
 }

Modified: polly/trunk/lib/External/isl/isl_ast_build_expr.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_ast_build_expr.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_ast_build_expr.c (original)
+++ polly/trunk/lib/External/isl/isl_ast_build_expr.c Wed Nov 16 05:06:47 2016
@@ -1961,6 +1961,37 @@ static isl_bool single_is_subset(struct
 	return subset;
 }
 
+/* Is "aff" a rational expression, i.e., does it have a denominator
+ * different from one?
+ */
+static isl_bool aff_is_rational(__isl_keep isl_aff *aff)
+{
+	isl_bool rational;
+	isl_val *den;
+
+	den = isl_aff_get_denominator_val(aff);
+	rational = isl_bool_not(isl_val_is_one(den));
+	isl_val_free(den);
+
+	return rational;
+}
+
+/* Does "list" consist of a single rational affine expression?
+ */
+static isl_bool is_single_rational_aff(__isl_keep isl_aff_list *list)
+{
+	isl_bool rational;
+	isl_aff *aff;
+
+	if (isl_aff_list_n_aff(list) != 1)
+		return isl_bool_false;
+	aff = isl_aff_list_get_aff(list, 0);
+	rational = aff_is_rational(aff);
+	isl_aff_free(aff);
+
+	return rational;
+}
+
 /* Can the list of subpieces in the last piece of "data" be extended with
  * "set" and "aff" based on "test"?
  * In particular, is it the case for each entry (set_i, aff_i) that
@@ -1974,6 +2005,11 @@ static isl_bool single_is_subset(struct
  * This function is used to detect min/max expressions.
  * If the ast_build_detect_min_max option is turned off, then
  * do not even try and perform any detection and return false instead.
+ *
+ * Rational affine expressions are not considered for min/max expressions
+ * since the combined expression will be defined on the union of the domains,
+ * while a rational expression may only yield integer values
+ * on its own definition domain.
  */
 static isl_bool extends(struct isl_from_pw_aff_data *data,
 	__isl_keep isl_set *set, __isl_keep isl_aff *aff,
@@ -1981,9 +2017,16 @@ static isl_bool extends(struct isl_from_
 		__isl_take isl_aff *aff2))
 {
 	int i, n;
+	isl_bool is_rational;
 	isl_ctx *ctx;
 	isl_set *dom;
 
+	is_rational = aff_is_rational(aff);
+	if (is_rational >= 0 && !is_rational)
+		is_rational = is_single_rational_aff(data->p[data->n].aff_list);
+	if (is_rational < 0 || is_rational)
+		return isl_bool_not(is_rational);
+
 	ctx = isl_ast_build_get_ctx(data->build);
 	if (!isl_options_get_ast_build_detect_min_max(ctx))
 		return isl_bool_false;

Modified: polly/trunk/lib/External/isl/isl_coalesce.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_coalesce.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_coalesce.c (original)
+++ polly/trunk/lib/External/isl/isl_coalesce.c Wed Nov 16 05:06:47 2016
@@ -27,6 +27,9 @@
 #include <isl_aff_private.h>
 #include <isl_equalities.h>
 
+#include <set_to_map.c>
+#include <set_from_map.c>
+
 #define STATUS_ERROR		-1
 #define STATUS_REDUNDANT	 1
 #define STATUS_VALID	 	 2
@@ -3214,5 +3217,5 @@ error:
  */
 struct isl_set *isl_set_coalesce(struct isl_set *set)
 {
-	return (struct isl_set *)isl_map_coalesce((struct isl_map *)set);
+	return set_from_map(isl_map_coalesce(set_to_map(set)));
 }

Modified: polly/trunk/lib/External/isl/isl_constraint.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_constraint.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_constraint.c (original)
+++ polly/trunk/lib/External/isl/isl_constraint.c Wed Nov 16 05:06:47 2016
@@ -20,6 +20,9 @@
 #include <isl_vec_private.h>
 #include <isl/deprecated/constraint_int.h>
 
+#include <bset_to_bmap.c>
+#include <bset_from_bmap.c>
+
 #undef BASE
 #define BASE constraint
 
@@ -132,7 +135,7 @@ error:
 struct isl_constraint *isl_basic_set_constraint(struct isl_basic_set *bset,
 	isl_int **line)
 {
-	return isl_basic_map_constraint((struct isl_basic_map *)bset, line);
+	return isl_basic_map_constraint(bset_to_bmap(bset), line);
 }
 
 __isl_give isl_constraint *isl_constraint_alloc_equality(
@@ -248,7 +251,7 @@ isl_stat isl_basic_map_foreach_constrain
 isl_stat isl_basic_set_foreach_constraint(__isl_keep isl_basic_set *bset,
 	isl_stat (*fn)(__isl_take isl_constraint *c, void *user), void *user)
 {
-	return isl_basic_map_foreach_constraint((isl_basic_map *)bset, fn, user);
+	return isl_basic_map_foreach_constraint(bset_to_bmap(bset), fn, user);
 }
 
 /* Add the constraint to the list that "user" points to, if it is not
@@ -350,9 +353,8 @@ error:
 struct isl_basic_set *isl_basic_set_add_constraint(
 	struct isl_basic_set *bset, struct isl_constraint *constraint)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_add_constraint((struct isl_basic_map *)bset,
-						constraint);
+	return bset_from_bmap(isl_basic_map_add_constraint(bset_to_bmap(bset),
+							    constraint));
 }
 
 __isl_give isl_map *isl_map_add_constraint(__isl_take isl_map *map,
@@ -831,7 +833,7 @@ struct isl_basic_set *isl_basic_set_from
 	if (isl_constraint_dim(constraint, isl_dim_in) != 0)
 		isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid,
 			"not a set constraint", goto error);
-	return (isl_basic_set *)isl_basic_map_from_constraint(constraint);
+	return bset_from_bmap(isl_basic_map_from_constraint(constraint));
 error:
 	isl_constraint_free(constraint);
 	return NULL;
@@ -877,7 +879,7 @@ int isl_basic_set_has_defining_equality(
 	__isl_keep isl_basic_set *bset, enum isl_dim_type type, int pos,
 	__isl_give isl_constraint **c)
 {
-	return isl_basic_map_has_defining_equality((isl_basic_map *)bset,
+	return isl_basic_map_has_defining_equality(bset_to_bmap(bset),
 						    type, pos, c);
 }
 

Modified: polly/trunk/lib/External/isl/isl_convex_hull.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_convex_hull.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_convex_hull.c (original)
+++ polly/trunk/lib/External/isl/isl_convex_hull.c Wed Nov 16 05:06:47 2016
@@ -23,6 +23,10 @@
 #include "isl_tab.h"
 #include <isl_sort.h>
 
+#include <bset_to_bmap.c>
+#include <bset_from_bmap.c>
+#include <set_to_map.c>
+
 static struct isl_basic_set *uset_convex_hull_wrap_bounded(struct isl_set *set);
 
 /* Return 1 if constraint c is redundant with respect to the constraints
@@ -126,8 +130,8 @@ error:
 __isl_give isl_basic_set *isl_basic_set_remove_redundancies(
 	__isl_take isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_remove_redundancies((struct isl_basic_map *)bset);
+	return bset_from_bmap(
+		isl_basic_map_remove_redundancies(bset_to_bmap(bset)));
 }
 
 /* Remove redundant constraints in each of the basic maps.
@@ -192,7 +196,7 @@ error:
 }
 
 __isl_give isl_basic_map *isl_basic_map_set_rational(
-	__isl_take isl_basic_set *bmap)
+	__isl_take isl_basic_map *bmap)
 {
 	if (!bmap)
 		return NULL;
@@ -936,7 +940,7 @@ int isl_basic_map_image_is_bounded(__isl
 	bmap = isl_basic_map_cow(bmap);
 	bmap = isl_basic_map_move_dims(bmap, isl_dim_param, nparam,
 					isl_dim_in, 0, n_in);
-	bounded = isl_basic_set_is_bounded((isl_basic_set *)bmap);
+	bounded = isl_basic_set_is_bounded(bset_from_bmap(bmap));
 	isl_basic_map_free(bmap);
 
 	return bounded;
@@ -1987,8 +1991,7 @@ error:
 
 struct isl_basic_set *isl_set_convex_hull(struct isl_set *set)
 {
-	return (struct isl_basic_set *)
-		isl_map_convex_hull((struct isl_map *)set);
+	return bset_from_bmap(isl_map_convex_hull(set_to_map(set)));
 }
 
 __isl_give isl_basic_map *isl_map_polyhedral_hull(__isl_take isl_map *map)
@@ -2001,7 +2004,7 @@ __isl_give isl_basic_map *isl_map_polyhe
 
 __isl_give isl_basic_set *isl_set_polyhedral_hull(__isl_take isl_set *set)
 {
-	return (isl_basic_set *)isl_map_polyhedral_hull((isl_map *)set);
+	return bset_from_bmap(isl_map_polyhedral_hull(set_to_map(set)));
 }
 
 struct sh_data_entry {
@@ -2477,8 +2480,7 @@ __isl_give isl_basic_map *isl_map_simple
 
 struct isl_basic_set *isl_set_simple_hull(struct isl_set *set)
 {
-	return (struct isl_basic_set *)
-		isl_map_simple_hull((struct isl_map *)set);
+	return bset_from_bmap(isl_map_simple_hull(set_to_map(set)));
 }
 
 /* Compute a superset of the convex hull of map that is described
@@ -2977,7 +2979,7 @@ error:
 
 /* Return a sequence of the basic maps that make up the maps in "list".
  */
-static __isl_give isl_basic_set_list *collect_basic_maps(
+static __isl_give isl_basic_map_list *collect_basic_maps(
 	__isl_take isl_map_list *list)
 {
 	int i, n;

Modified: polly/trunk/lib/External/isl/isl_dim_map.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_dim_map.h?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_dim_map.h (original)
+++ polly/trunk/lib/External/isl/isl_dim_map.h Wed Nov 16 05:06:47 2016
@@ -4,6 +4,7 @@
 #include <isl/ctx.h>
 #include <isl/space.h>
 #include <isl/map.h>
+#include <isl_reordering.h>
 
 struct isl_dim_map;
 typedef struct isl_dim_map isl_dim_map;

Modified: polly/trunk/lib/External/isl/isl_equalities.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_equalities.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_equalities.c (original)
+++ polly/trunk/lib/External/isl/isl_equalities.c Wed Nov 16 05:06:47 2016
@@ -493,7 +493,7 @@ static __isl_give isl_mat *insert_parame
  * The number of equality constraints in B is assumed to be smaller than
  * or equal to the number of variables x.
  * "first" is the position of the first x variable.
- * The preceding variables are considered to by y-variables.
+ * The preceding variables are considered to be y-variables.
  * If T2 is not NULL, then *T2 is set to a matrix mapping [1 x] to [1 x'].
  *
  * First compute the (left) Hermite normal form of M,

Modified: polly/trunk/lib/External/isl/isl_lp.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_lp.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_lp.c (original)
+++ polly/trunk/lib/External/isl/isl_lp.c Wed Nov 16 05:06:47 2016
@@ -19,6 +19,9 @@
 #include <isl_val_private.h>
 #include <isl_vec_private.h>
 
+#include <bset_to_bmap.c>
+#include <set_to_map.c>
+
 enum isl_lp_result isl_tab_solve_lp(struct isl_basic_map *bmap, int maximize,
 				      isl_int *f, isl_int denom, isl_int *opt,
 				      isl_int *opt_denom,
@@ -78,7 +81,7 @@ enum isl_lp_result isl_basic_set_solve_l
 				      isl_int *opt_denom,
 				      struct isl_vec **sol)
 {
-	return isl_basic_map_solve_lp((struct isl_basic_map *)bset, max,
+	return isl_basic_map_solve_lp(bset_to_bmap(bset), max,
 					f, d, opt, opt_denom, sol);
 }
 
@@ -196,7 +199,7 @@ enum isl_lp_result isl_set_solve_lp(__is
 				      isl_int *opt_denom,
 				      struct isl_vec **sol)
 {
-	return isl_map_solve_lp((struct isl_map *)set, max,
+	return isl_map_solve_lp(set_to_map(set), max,
 					f, d, opt, opt_denom, sol);
 }
 

Modified: polly/trunk/lib/External/isl/isl_map.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_map.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_map.c (original)
+++ polly/trunk/lib/External/isl/isl_map.c Wed Nov 16 05:06:47 2016
@@ -43,6 +43,11 @@
 #include <isl/deprecated/map_int.h>
 #include <isl/deprecated/set_int.h>
 
+#include <bset_to_bmap.c>
+#include <bset_from_bmap.c>
+#include <set_to_map.c>
+#include <set_from_map.c>
+
 static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type)
 {
 	switch (type) {
@@ -507,7 +512,8 @@ const char *isl_map_get_tuple_name(__isl
 __isl_give isl_set *isl_set_set_tuple_name(__isl_take isl_set *set,
 	const char *s)
 {
-	return (isl_set *)isl_map_set_tuple_name((isl_map *)set, isl_dim_set, s);
+	return set_from_map(isl_map_set_tuple_name(set_to_map(set),
+						isl_dim_set, s));
 }
 
 __isl_give isl_map *isl_map_set_tuple_id(__isl_take isl_map *map,
@@ -678,14 +684,15 @@ __isl_give isl_basic_set *isl_basic_set_
 	__isl_take isl_basic_set *bset,
 	enum isl_dim_type type, unsigned pos, const char *s)
 {
-	return (isl_basic_set *)isl_basic_map_set_dim_name(
-		(isl_basic_map *)bset, type, pos, s);
+	return bset_from_bmap(isl_basic_map_set_dim_name(bset_to_bmap(bset),
+							type, pos, s));
 }
 
 __isl_give isl_set *isl_set_set_dim_name(__isl_take isl_set *set,
 	enum isl_dim_type type, unsigned pos, const char *s)
 {
-	return (isl_set *)isl_map_set_dim_name((isl_map *)set, type, pos, s);
+	return set_from_map(isl_map_set_dim_name(set_to_map(set),
+							type, pos, s));
 }
 
 isl_bool isl_basic_map_has_dim_id(__isl_keep isl_basic_map *bmap,
@@ -1029,7 +1036,7 @@ struct isl_basic_set *isl_basic_set_allo
 		return NULL;
 
 	bmap = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq);
-	return (struct isl_basic_set *)bmap;
+	return bset_from_bmap(bmap);
 }
 
 struct isl_basic_set *isl_basic_set_alloc_space(__isl_take isl_space *dim,
@@ -1040,7 +1047,7 @@ struct isl_basic_set *isl_basic_set_allo
 		return NULL;
 	isl_assert(dim->ctx, dim->n_in == 0, goto error);
 	bmap = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq);
-	return (struct isl_basic_set *)bmap;
+	return bset_from_bmap(bmap);
 error:
 	isl_space_free(dim);
 	return NULL;
@@ -1122,8 +1129,8 @@ struct isl_basic_set *isl_basic_set_dup(
 {
 	struct isl_basic_map *dup;
 
-	dup = isl_basic_map_dup((struct isl_basic_map *)bset);
-	return (struct isl_basic_set *)dup;
+	dup = isl_basic_map_dup(bset_to_bmap(bset));
+	return bset_from_bmap(dup);
 }
 
 struct isl_basic_set *isl_basic_set_copy(struct isl_basic_set *bset)
@@ -1193,7 +1200,7 @@ __isl_null isl_basic_map *isl_basic_map_
 
 __isl_null isl_basic_set *isl_basic_set_free(__isl_take isl_basic_set *bset)
 {
-	return isl_basic_map_free((struct isl_basic_map *)bset);
+	return isl_basic_map_free(bset_to_bmap(bset));
 }
 
 static int room_for_con(struct isl_basic_map *bmap, unsigned n)
@@ -1282,7 +1289,7 @@ int isl_basic_map_alloc_equality(struct
 
 int isl_basic_set_alloc_equality(struct isl_basic_set *bset)
 {
-	return isl_basic_map_alloc_equality((struct isl_basic_map *)bset);
+	return isl_basic_map_alloc_equality(bset_to_bmap(bset));
 }
 
 int isl_basic_map_free_equality(struct isl_basic_map *bmap, unsigned n)
@@ -1296,7 +1303,7 @@ int isl_basic_map_free_equality(struct i
 
 int isl_basic_set_free_equality(struct isl_basic_set *bset, unsigned n)
 {
-	return isl_basic_map_free_equality((struct isl_basic_map *)bset, n);
+	return isl_basic_map_free_equality(bset_to_bmap(bset), n);
 }
 
 int isl_basic_map_drop_equality(struct isl_basic_map *bmap, unsigned pos)
@@ -1317,7 +1324,7 @@ int isl_basic_map_drop_equality(struct i
 
 int isl_basic_set_drop_equality(struct isl_basic_set *bset, unsigned pos)
 {
-	return isl_basic_map_drop_equality((struct isl_basic_map *)bset, pos);
+	return isl_basic_map_drop_equality(bset_to_bmap(bset), pos);
 }
 
 /* Turn inequality "pos" of "bmap" into an equality.
@@ -1369,7 +1376,7 @@ int isl_basic_map_alloc_inequality(struc
 
 int isl_basic_set_alloc_inequality(struct isl_basic_set *bset)
 {
-	return isl_basic_map_alloc_inequality((struct isl_basic_map *)bset);
+	return isl_basic_map_alloc_inequality(bset_to_bmap(bset));
 }
 
 int isl_basic_map_free_inequality(struct isl_basic_map *bmap, unsigned n)
@@ -1383,7 +1390,7 @@ int isl_basic_map_free_inequality(struct
 
 int isl_basic_set_free_inequality(struct isl_basic_set *bset, unsigned n)
 {
-	return isl_basic_map_free_inequality((struct isl_basic_map *)bset, n);
+	return isl_basic_map_free_inequality(bset_to_bmap(bset), n);
 }
 
 int isl_basic_map_drop_inequality(struct isl_basic_map *bmap, unsigned pos)
@@ -1405,7 +1412,7 @@ int isl_basic_map_drop_inequality(struct
 
 int isl_basic_set_drop_inequality(struct isl_basic_set *bset, unsigned pos)
 {
-	return isl_basic_map_drop_inequality((struct isl_basic_map *)bset, pos);
+	return isl_basic_map_drop_inequality(bset_to_bmap(bset), pos);
 }
 
 __isl_give isl_basic_map *isl_basic_map_add_eq(__isl_take isl_basic_map *bmap,
@@ -1429,8 +1436,7 @@ error:
 __isl_give isl_basic_set *isl_basic_set_add_eq(__isl_take isl_basic_set *bset,
 	isl_int *eq)
 {
-	return (isl_basic_set *)
-		isl_basic_map_add_eq((isl_basic_map *)bset, eq);
+	return bset_from_bmap(isl_basic_map_add_eq(bset_to_bmap(bset), eq));
 }
 
 __isl_give isl_basic_map *isl_basic_map_add_ineq(__isl_take isl_basic_map *bmap,
@@ -1454,8 +1460,7 @@ error:
 __isl_give isl_basic_set *isl_basic_set_add_ineq(__isl_take isl_basic_set *bset,
 	isl_int *ineq)
 {
-	return (isl_basic_set *)
-		isl_basic_map_add_ineq((isl_basic_map *)bset, ineq);
+	return bset_from_bmap(isl_basic_map_add_ineq(bset_to_bmap(bset), ineq));
 }
 
 int isl_basic_map_alloc_div(struct isl_basic_map *bmap)
@@ -1472,7 +1477,7 @@ int isl_basic_map_alloc_div(struct isl_b
 
 int isl_basic_set_alloc_div(struct isl_basic_set *bset)
 {
-	return isl_basic_map_alloc_div((struct isl_basic_map *)bset);
+	return isl_basic_map_alloc_div(bset_to_bmap(bset));
 }
 
 /* Insert an extra integer division, prescribed by "div", to "bmap"
@@ -1523,7 +1528,7 @@ int isl_basic_map_free_div(struct isl_ba
 
 int isl_basic_set_free_div(struct isl_basic_set *bset, unsigned n)
 {
-	return isl_basic_map_free_div((struct isl_basic_map *)bset, n);
+	return isl_basic_map_free_div(bset_to_bmap(bset), n);
 }
 
 /* Copy constraint from src to dst, putting the vars of src at offset
@@ -1626,9 +1631,8 @@ error:
 struct isl_basic_set *isl_basic_set_add_constraints(struct isl_basic_set *bset1,
 		struct isl_basic_set *bset2, unsigned pos)
 {
-	return (struct isl_basic_set *)
-		add_constraints((struct isl_basic_map *)bset1,
-				(struct isl_basic_map *)bset2, 0, pos);
+	return bset_from_bmap(add_constraints(bset_to_bmap(bset1),
+						bset_to_bmap(bset2), 0, pos));
 }
 
 struct isl_basic_map *isl_basic_map_extend_space(struct isl_basic_map *base,
@@ -1687,9 +1691,8 @@ struct isl_basic_set *isl_basic_set_exte
 		__isl_take isl_space *dim, unsigned extra,
 		unsigned n_eq, unsigned n_ineq)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_extend_space((struct isl_basic_map *)base, dim,
-							extra, n_eq, n_ineq);
+	return bset_from_bmap(isl_basic_map_extend_space(bset_to_bmap(base),
+						    dim, extra, n_eq, n_ineq));
 }
 
 struct isl_basic_map *isl_basic_map_extend_constraints(
@@ -1725,23 +1728,21 @@ struct isl_basic_set *isl_basic_set_exte
 		unsigned nparam, unsigned dim, unsigned extra,
 		unsigned n_eq, unsigned n_ineq)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_extend((struct isl_basic_map *)base,
-					nparam, 0, dim, extra, n_eq, n_ineq);
+	return bset_from_bmap(isl_basic_map_extend(bset_to_bmap(base),
+					nparam, 0, dim, extra, n_eq, n_ineq));
 }
 
 struct isl_basic_set *isl_basic_set_extend_constraints(
 		struct isl_basic_set *base, unsigned n_eq, unsigned n_ineq)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_extend_constraints((struct isl_basic_map *)base,
-						    n_eq, n_ineq);
+	isl_basic_map *bmap = bset_to_bmap(base);
+	bmap = isl_basic_map_extend_constraints(bmap, n_eq, n_ineq);
+	return bset_from_bmap(bmap);
 }
 
 struct isl_basic_set *isl_basic_set_cow(struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_cow((struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_cow(bset_to_bmap(bset)));
 }
 
 struct isl_basic_map *isl_basic_map_cow(struct isl_basic_map *bmap)
@@ -1882,8 +1883,7 @@ error:
 
 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((struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_set_to_empty(bset_to_bmap(bset)));
 }
 
 /* Swap divs "a" and "b" in "bmap" (without modifying any of the constraints
@@ -1965,7 +1965,7 @@ error:
 __isl_give isl_set *isl_set_eliminate(__isl_take isl_set *set,
 	enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_set *)isl_map_eliminate((isl_map *)set, type, first, n);
+	return set_from_map(isl_map_eliminate(set_to_map(set), type, first, n));
 }
 
 /* Eliminate the specified n dimensions starting at first from the
@@ -1994,8 +1994,7 @@ __isl_give isl_basic_map *isl_basic_map_
 __isl_give isl_basic_set *isl_basic_set_remove_divs(
 	__isl_take isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)isl_basic_map_remove_divs(
-			(struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_remove_divs(bset_to_bmap(bset)));
 }
 
 __isl_give isl_map *isl_map_remove_divs(__isl_take isl_map *map)
@@ -2332,11 +2331,11 @@ error:
 __isl_give isl_set *isl_set_remove_divs_involving_dims(__isl_take isl_set *set,
 	enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_set *)isl_map_remove_divs_involving_dims((isl_map *)set,
-							      type, first, n);
+	return set_from_map(isl_map_remove_divs_involving_dims(set_to_map(set),
+							      type, first, n));
 }
 
-/* Does the desciption of "bmap" depend on the specified dimensions?
+/* Does the description of "bmap" depend on the specified dimensions?
  * We also check whether the dimensions appear in any of the div definitions.
  * In principle there is no need for this check.  If the dimensions appear
  * in a div definition, they also appear in the defining constraints of that
@@ -2497,15 +2496,16 @@ error:
 
 __isl_give isl_set *isl_set_remove_unknown_divs(__isl_take isl_set *set)
 {
-	return (isl_set *)isl_map_remove_unknown_divs((isl_map *)set);
+	return set_from_map(isl_map_remove_unknown_divs(set_to_map(set)));
 }
 
 __isl_give isl_basic_set *isl_basic_set_remove_dims(
 	__isl_take isl_basic_set *bset,
 	enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_basic_set *)
-	    isl_basic_map_remove_dims((isl_basic_map *)bset, type, first, n);
+	isl_basic_map *bmap = bset_to_bmap(bset);
+	bmap = isl_basic_map_remove_dims(bmap, type, first, n);
+	return bset_from_bmap(bmap);
 }
 
 struct isl_map *isl_map_remove_dims(struct isl_map *map,
@@ -2537,7 +2537,8 @@ error:
 __isl_give isl_set *isl_set_remove_dims(__isl_take isl_set *bset,
 	enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_set *)isl_map_remove_dims((isl_map *)bset, type, first, n);
+	return set_from_map(isl_map_remove_dims(set_to_map(bset),
+						type, first, n));
 }
 
 /* Project out n inputs starting at first using Fourier-Motzkin */
@@ -2675,7 +2676,7 @@ void isl_basic_set_print_internal(struct
 	fprintf(out, "ref: %d, nparam: %d, dim: %d, extra: %d, flags: %x\n",
 			bset->ref, bset->dim->nparam, bset->dim->n_out,
 			bset->extra, bset->flags);
-	dump((struct isl_basic_map *)bset, out, indent);
+	dump(bset_to_bmap(bset), out, indent);
 }
 
 void isl_basic_map_print_internal(struct isl_basic_map *bmap,
@@ -2769,7 +2770,7 @@ error:
  */
 struct isl_set *isl_set_grow(struct isl_set *set, int n)
 {
-	return (struct isl_set *)isl_map_grow((struct isl_map *)set, n);
+	return set_from_map(isl_map_grow(set_to_map(set), n));
 }
 
 struct isl_set *isl_set_dup(struct isl_set *set)
@@ -2807,8 +2808,8 @@ struct isl_map *isl_map_from_basic_map(s
 __isl_give isl_set *isl_set_add_basic_set(__isl_take isl_set *set,
 						__isl_take isl_basic_set *bset)
 {
-	return (struct isl_set *)isl_map_add_basic_map((struct isl_map *)set,
-						(struct isl_basic_map *)bset);
+	return set_from_map(isl_map_add_basic_map(set_to_map(set),
+						bset_to_bmap(bset)));
 }
 
 __isl_null isl_set *isl_set_free(__isl_take isl_set *set)
@@ -2964,7 +2965,7 @@ isl_bool isl_basic_map_contains(__isl_ke
 isl_bool isl_basic_set_contains(__isl_keep isl_basic_set *bset,
 	__isl_keep isl_vec *vec)
 {
-	return isl_basic_map_contains((struct isl_basic_map *)bset, vec);
+	return isl_basic_map_contains(bset_to_bmap(bset), vec);
 }
 
 struct isl_basic_map *isl_basic_map_intersect(
@@ -3033,10 +3034,8 @@ error:
 struct isl_basic_set *isl_basic_set_intersect(
 		struct isl_basic_set *bset1, struct isl_basic_set *bset2)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_intersect(
-			(struct isl_basic_map *)bset1,
-			(struct isl_basic_map *)bset2);
+	return bset_from_bmap(isl_basic_map_intersect(bset_to_bmap(bset1),
+							bset_to_bmap(bset2)));
 }
 
 __isl_give isl_basic_set *isl_basic_set_intersect_params(
@@ -3187,9 +3186,8 @@ __isl_give isl_map *isl_map_intersect(__
 
 struct isl_set *isl_set_intersect(struct isl_set *set1, struct isl_set *set2)
 {
-	return (struct isl_set *)
-		isl_map_intersect((struct isl_map *)set1,
-				  (struct isl_map *)set2);
+	return set_from_map(isl_map_intersect(set_to_map(set1),
+					      set_to_map(set2)));
 }
 
 /* map_intersect_internal accepts intersections
@@ -3385,7 +3383,7 @@ __isl_give isl_set *isl_set_add_dims(__i
 	if (!set)
 		return NULL;
 	isl_assert(set->ctx, type != isl_dim_in, goto error);
-	return (isl_set *)isl_map_add_dims((isl_map *)set, type, n);
+	return set_from_map(isl_map_add_dims(set_to_map(set), type, n));
 error:
 	isl_set_free(set);
 	return NULL;
@@ -3486,8 +3484,10 @@ __isl_give isl_basic_set *isl_basic_set_
 	enum isl_dim_type dst_type, unsigned dst_pos,
 	enum isl_dim_type src_type, unsigned src_pos, unsigned n)
 {
-	return (isl_basic_set *)isl_basic_map_move_dims(
-		(isl_basic_map *)bset, dst_type, dst_pos, src_type, src_pos, n);
+	isl_basic_map *bmap = bset_to_bmap(bset);
+	bmap = isl_basic_map_move_dims(bmap, dst_type, dst_pos,
+					src_type, src_pos, n);
+	return bset_from_bmap(bmap);
 }
 
 __isl_give isl_set *isl_set_move_dims(__isl_take isl_set *set,
@@ -3497,8 +3497,8 @@ __isl_give isl_set *isl_set_move_dims(__
 	if (!set)
 		return NULL;
 	isl_assert(set->ctx, dst_type != isl_dim_in, goto error);
-	return (isl_set *)isl_map_move_dims((isl_map *)set, dst_type, dst_pos,
-					src_type, src_pos, n);
+	return set_from_map(isl_map_move_dims(set_to_map(set),
+				    dst_type, dst_pos, src_type, src_pos, n));
 error:
 	isl_set_free(set);
 	return NULL;
@@ -3724,8 +3724,8 @@ error:
 struct isl_basic_set *isl_basic_set_project_out(struct isl_basic_set *bset,
 		enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_basic_set *)isl_basic_map_project_out(
-			(isl_basic_map *)bset, type, first, n);
+	return bset_from_bmap(isl_basic_map_project_out(bset_to_bmap(bset),
+							type, first, n));
 }
 
 /* Turn the n dimensions of type type, starting at first
@@ -3770,7 +3770,8 @@ error:
 __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set,
 		enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_set *)isl_map_project_out((isl_map *)set, type, first, n);
+	return set_from_map(isl_map_project_out(set_to_map(set),
+						type, first, n));
 }
 
 /* Return a map that projects the elements in "set" onto their
@@ -3885,8 +3886,8 @@ struct isl_basic_set *isl_basic_set_appl
 	isl_assert(bset->ctx, isl_basic_map_compatible_domain(bmap, bset),
 		    goto error);
 
-	return (struct isl_basic_set *)
-		isl_basic_map_apply_range((struct isl_basic_map *)bset, bmap);
+	return bset_from_bmap(isl_basic_map_apply_range(bset_to_bmap(bset),
+							bmap));
 error:
 	isl_basic_set_free(bset);
 	isl_basic_map_free(bmap);
@@ -4015,7 +4016,7 @@ error:
 __isl_give isl_set *isl_set_sum(__isl_take isl_set *set1,
 	__isl_take isl_set *set2)
 {
-	return (isl_set *)isl_map_sum((isl_map *)set1, (isl_map *)set2);
+	return set_from_map(isl_map_sum(set_to_map(set1), set_to_map(set2)));
 }
 
 /* Given a basic map A -> f(A), construct A -> -f(A).
@@ -4073,7 +4074,7 @@ error:
 
 __isl_give isl_set *isl_set_neg(__isl_take isl_set *set)
 {
-	return (isl_set *)isl_map_neg((isl_map *)set);
+	return set_from_map(isl_map_neg(set_to_map(set)));
 }
 
 /* Given a basic map A -> f(A) and an integer d, construct a basic map
@@ -4195,7 +4196,7 @@ error:
 	return NULL;
 }
 
-/* Add a constraints to "bmap" expressing i_pos < o_pos
+/* Add a constraint to "bmap" expressing i_pos < o_pos
  */
 static struct isl_basic_map *var_less(struct isl_basic_map *bmap, unsigned pos)
 {
@@ -4241,7 +4242,7 @@ error:
 	return NULL;
 }
 
-/* Add a constraints to "bmap" expressing i_pos > o_pos
+/* Add a constraint to "bmap" expressing i_pos > o_pos
  */
 static struct isl_basic_map *var_more(struct isl_basic_map *bmap, unsigned pos)
 {
@@ -4317,7 +4318,7 @@ __isl_give isl_basic_map *isl_basic_map_
 	return isl_basic_map_finalize(bmap);
 }
 
-/* Return a relation on of dimension "dim" expressing i_[0..pos] <<= o_[0..pos]
+/* Return a relation on "dim" expressing i_[0..pos] <<= o_[0..pos]
  */
 __isl_give isl_basic_map *isl_basic_map_less_or_equal_at(
 	__isl_take isl_space *dim, unsigned pos)
@@ -4332,7 +4333,7 @@ __isl_give isl_basic_map *isl_basic_map_
 	return isl_basic_map_finalize(bmap);
 }
 
-/* Return a relation on pairs of sets of dimension "dim" expressing i_pos > o_pos
+/* Return a relation on "dim" expressing i_pos > o_pos
  */
 __isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *dim,
 	unsigned pos)
@@ -4349,7 +4350,7 @@ __isl_give isl_basic_map *isl_basic_map_
 	return isl_basic_map_finalize(bmap);
 }
 
-/* Return a relation on of dimension "dim" expressing i_[0..pos] >>= o_[0..pos]
+/* Return a relation on "dim" expressing i_[0..pos] >>= o_[0..pos]
  */
 __isl_give isl_basic_map *isl_basic_map_more_or_equal_at(
 	__isl_take isl_space *dim, unsigned pos)
@@ -4563,7 +4564,7 @@ __isl_give isl_basic_map *isl_basic_map_
 
 	isl_assert(bset->ctx, isl_space_compatible(bset->dim, dim), goto error);
 	isl_space_free(bset->dim);
-	bmap = (struct isl_basic_map *) bset;
+	bmap = bset_to_bmap(bset);
 	bmap->dim = dim;
 	return isl_basic_map_finalize(bmap);
 error:
@@ -4634,7 +4635,7 @@ int isl_basic_map_add_div_constraints_va
 int isl_basic_set_add_div_constraints_var(__isl_keep isl_basic_set *bset,
 	unsigned pos, isl_int *div)
 {
-	return isl_basic_map_add_div_constraints_var((isl_basic_map *)bset,
+	return isl_basic_map_add_div_constraints_var(bset_to_bmap(bset),
 							pos, div);
 }
 
@@ -4717,7 +4718,7 @@ struct isl_basic_set *isl_basic_map_unde
 	    bmap->n_div == 0 &&
 	    !isl_space_is_named_or_nested(bmap->dim, isl_dim_in) &&
 	    !isl_space_is_named_or_nested(bmap->dim, isl_dim_out))
-		return (struct isl_basic_set *)bmap;
+		return bset_from_bmap(bmap);
 	bmap = isl_basic_map_cow(bmap);
 	if (!bmap)
 		goto error;
@@ -4727,7 +4728,7 @@ struct isl_basic_set *isl_basic_map_unde
 	bmap->extra -= bmap->n_div;
 	bmap->n_div = 0;
 	bmap = isl_basic_map_finalize(bmap);
-	return (struct isl_basic_set *)bmap;
+	return bset_from_bmap(bmap);
 error:
 	isl_basic_map_free(bmap);
 	return NULL;
@@ -4736,7 +4737,7 @@ error:
 __isl_give isl_basic_set *isl_basic_set_underlying_set(
 		__isl_take isl_basic_set *bset)
 {
-	return isl_basic_map_underlying_set((isl_basic_map *)bset);
+	return isl_basic_map_underlying_set(bset_to_bmap(bset));
 }
 
 /* Replace each element in "list" by the result of applying
@@ -4787,7 +4788,7 @@ struct isl_basic_map *isl_basic_map_over
 	if (!bset)
 		goto error;
 	total = bset->dim->n_out + bset->extra;
-	bmap = (struct isl_basic_map *)bset;
+	bmap = bset_to_bmap(bset);
 	isl_space_free(bmap->dim);
 	bmap->dim = isl_space_copy(like->dim);
 	if (!bmap->dim)
@@ -4829,8 +4830,8 @@ error:
 struct isl_basic_set *isl_basic_set_from_underlying_set(
 	struct isl_basic_set *bset, struct isl_basic_set *like)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_overlying_set(bset, (struct isl_basic_map *)like);
+	return bset_from_bmap(isl_basic_map_overlying_set(bset,
+							bset_to_bmap(like)));
 }
 
 struct isl_set *isl_set_from_underlying_set(
@@ -4882,8 +4883,8 @@ struct isl_set *isl_map_underlying_set(s
 		isl_assert(map->ctx, map->p[0]->n_div == map->p[i]->n_div,
 				goto error);
 	for (i = 0; i < map->n; ++i) {
-		map->p[i] = (struct isl_basic_map *)
-				isl_basic_map_underlying_set(map->p[i]);
+		map->p[i] = bset_to_bmap(
+				isl_basic_map_underlying_set(map->p[i]));
 		if (!map->p[i])
 			goto error;
 	}
@@ -4895,7 +4896,7 @@ struct isl_set *isl_map_underlying_set(s
 	}
 	if (!map->dim)
 		goto error;
-	return (struct isl_set *)map;
+	return set_from_map(map);
 error:
 	isl_map_free(map);
 	return NULL;
@@ -4903,7 +4904,7 @@ error:
 
 struct isl_set *isl_set_to_underlying_set(struct isl_set *set)
 {
-	return (struct isl_set *)isl_map_underlying_set((struct isl_map *)set);
+	return set_from_map(isl_map_underlying_set(set_to_map(set)));
 }
 
 /* Replace the space of "bmap" by "space".
@@ -4950,8 +4951,8 @@ error:
 __isl_give isl_basic_set *isl_basic_set_reset_space(
 	__isl_take isl_basic_set *bset, __isl_take isl_space *dim)
 {
-	return (isl_basic_set *)isl_basic_map_reset_space((isl_basic_map *)bset,
-							dim);
+	return bset_from_bmap(isl_basic_map_reset_space(bset_to_bmap(bset),
+							dim));
 }
 
 __isl_give isl_map *isl_map_reset_space(__isl_take isl_map *map,
@@ -4982,7 +4983,7 @@ error:
 __isl_give isl_set *isl_set_reset_space(__isl_take isl_set *set,
 	__isl_take isl_space *dim)
 {
-	return (struct isl_set *) isl_map_reset_space((struct isl_map *)set, dim);
+	return set_from_map(isl_map_reset_space(set_to_map(set), dim));
 }
 
 /* Compute the parameter domain of the given basic set.
@@ -5205,13 +5206,13 @@ struct isl_set *isl_map_range(struct isl
 	if (!map)
 		goto error;
 	if (isl_map_is_set(map))
-		return (isl_set *)map;
+		return set_from_map(map);
 
 	map = isl_map_cow(map);
 	if (!map)
 		goto error;
 
-	set = (struct isl_set *) map;
+	set = set_from_map(map);
 	set->dim = isl_space_range(set->dim);
 	if (!set->dim)
 		goto error;
@@ -5310,7 +5311,7 @@ __isl_give isl_map *isl_map_from_set(__i
 	if (!set || !dim)
 		goto error;
 	isl_assert(set->ctx, isl_space_compatible(set->dim, dim), goto error);
-	map = (struct isl_map *)set;
+	map = set_to_map(set);
 	for (i = 0; i < set->n; ++i) {
 		map->p[i] = isl_basic_map_from_basic_set(
 				set->p[i], isl_space_copy(dim));
@@ -5339,7 +5340,7 @@ __isl_give isl_basic_map *isl_basic_map_
 	space = isl_basic_set_get_space(bset);
 	space = isl_space_from_range(space);
 	bset = isl_basic_set_reset_space(bset, space);
-	return (isl_basic_map *)bset;
+	return bset_to_bmap(bset);
 }
 
 /* Create a relation with the given set as range.
@@ -5352,7 +5353,7 @@ __isl_give isl_map *isl_map_from_range(_
 	space = isl_set_get_space(set);
 	space = isl_space_from_range(space);
 	set = isl_set_reset_space(set, space);
-	return (struct isl_map *)set;
+	return set_to_map(set);
 }
 
 /* Create a relation with the given set as domain.
@@ -5679,17 +5680,15 @@ __isl_give isl_basic_set *isl_basic_set_
 struct isl_basic_set *isl_basic_set_fix_si(struct isl_basic_set *bset,
 		enum isl_dim_type type, unsigned pos, int value)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_fix_si((struct isl_basic_map *)bset,
-					type, pos, value);
+	return bset_from_bmap(isl_basic_map_fix_si(bset_to_bmap(bset),
+						    type, pos, value));
 }
 
 __isl_give isl_basic_set *isl_basic_set_fix(__isl_take isl_basic_set *bset,
 		enum isl_dim_type type, unsigned pos, isl_int value)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_fix((struct isl_basic_map *)bset,
-					type, pos, value);
+	return bset_from_bmap(isl_basic_map_fix(bset_to_bmap(bset),
+						    type, pos, value));
 }
 
 struct isl_basic_map *isl_basic_map_fix_input_si(struct isl_basic_map *bmap,
@@ -5701,9 +5700,8 @@ struct isl_basic_map *isl_basic_map_fix_
 struct isl_basic_set *isl_basic_set_fix_dim_si(struct isl_basic_set *bset,
 		unsigned dim, int value)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_fix_si((struct isl_basic_map *)bset,
-					isl_dim_set, dim, value);
+	return bset_from_bmap(isl_basic_map_fix_si(bset_to_bmap(bset),
+					isl_dim_set, dim, value));
 }
 
 static int remove_if_empty(__isl_keep isl_map *map, int i)
@@ -5783,8 +5781,7 @@ error:
 __isl_give isl_set *isl_set_fix_si(__isl_take isl_set *set,
 		enum isl_dim_type type, unsigned pos, int value)
 {
-	return (struct isl_set *)
-		isl_map_fix_si((struct isl_map *)set, type, pos, value);
+	return set_from_map(isl_map_fix_si(set_to_map(set), type, pos, value));
 }
 
 __isl_give isl_map *isl_map_fix(__isl_take isl_map *map,
@@ -5812,7 +5809,7 @@ error:
 __isl_give isl_set *isl_set_fix(__isl_take isl_set *set,
 		enum isl_dim_type type, unsigned pos, isl_int value)
 {
-	return (struct isl_set *)isl_map_fix((isl_map *)set, type, pos, value);
+	return set_from_map(isl_map_fix(set_to_map(set), type, pos, value));
 }
 
 /* Fix the value of the variable at position "pos" of type "type" of "map"
@@ -5865,8 +5862,8 @@ struct isl_map *isl_map_fix_input_si(str
 
 struct isl_set *isl_set_fix_dim_si(struct isl_set *set, unsigned dim, int value)
 {
-	return (struct isl_set *)
-		isl_map_fix_si((struct isl_map *)set, isl_dim_set, dim, value);
+	return set_from_map(isl_map_fix_si(set_to_map(set),
+						isl_dim_set, dim, value));
 }
 
 static __isl_give isl_basic_map *basic_map_bound_si(
@@ -5973,8 +5970,8 @@ __isl_give isl_map *isl_map_upper_bound_
 __isl_give isl_set *isl_set_lower_bound_si(__isl_take isl_set *set,
 		enum isl_dim_type type, unsigned pos, int value)
 {
-	return (struct isl_set *)
-		isl_map_lower_bound_si((struct isl_map *)set, type, pos, value);
+	return set_from_map(isl_map_lower_bound_si(set_to_map(set),
+							type, pos, value));
 }
 
 __isl_give isl_set *isl_set_upper_bound_si(__isl_take isl_set *set,
@@ -6327,18 +6324,16 @@ __isl_give isl_set *isl_set_partial_lexm
 		__isl_take isl_set *set, __isl_take isl_set *dom,
 		__isl_give isl_set **empty)
 {
-	return (struct isl_set *)
-		isl_map_partial_lexmin((struct isl_map *)set,
-			dom, empty);
+	return set_from_map(isl_map_partial_lexmin(set_to_map(set),
+						    dom, empty));
 }
 
 __isl_give isl_set *isl_set_partial_lexmax(
 		__isl_take isl_set *set, __isl_take isl_set *dom,
 		__isl_give isl_set **empty)
 {
-	return (struct isl_set *)
-		isl_map_partial_lexmax((struct isl_map *)set,
-			dom, empty);
+	return set_from_map(isl_map_partial_lexmax(set_to_map(set),
+						    dom, empty));
 }
 
 /* Compute the lexicographic minimum (or maximum if "flags" includes
@@ -6357,12 +6352,12 @@ __isl_give isl_map *isl_basic_map_lexmax
 
 __isl_give isl_set *isl_basic_set_lexmin(__isl_take isl_basic_set *bset)
 {
-	return (isl_set *)isl_basic_map_lexmin((isl_basic_map *)bset);
+	return set_from_map(isl_basic_map_lexmin(bset_to_bmap(bset)));
 }
 
 __isl_give isl_set *isl_basic_set_lexmax(__isl_take isl_basic_set *bset)
 {
-	return (isl_set *)isl_basic_map_lexmax((isl_basic_map *)bset);
+	return set_from_map(isl_basic_map_lexmax(bset_to_bmap(bset)));
 }
 
 /* Compute the lexicographic minimum of "bset" over its parametric domain
@@ -6934,10 +6929,10 @@ static struct isl_map *compute_divs(stru
 		bmap->extra -= n_known;
 	}
 	bmap = isl_basic_map_reset_space(bmap, dim);
-	bset = (struct isl_basic_set *)bmap;
+	bset = bset_from_bmap(bmap);
 
 	set = parameter_compute_divs(bset);
-	map = (struct isl_map *)set;
+	map = set_to_map(set);
 	map = replace_space_by_local_space(map, ls);
 
 	return map;
@@ -7114,14 +7109,12 @@ struct isl_map *isl_map_compute_divs(str
 
 struct isl_set *isl_basic_set_compute_divs(struct isl_basic_set *bset)
 {
-	return (struct isl_set *)
-		isl_basic_map_compute_divs((struct isl_basic_map *)bset);
+	return set_from_map(isl_basic_map_compute_divs(bset_to_bmap(bset)));
 }
 
 struct isl_set *isl_set_compute_divs(struct isl_set *set)
 {
-	return (struct isl_set *)
-		isl_map_compute_divs((struct isl_map *)set);
+	return set_from_map(isl_map_compute_divs(set_to_map(set)));
 }
 
 struct isl_set *isl_map_domain(struct isl_map *map)
@@ -7136,7 +7129,7 @@ struct isl_set *isl_map_domain(struct is
 	if (!map)
 		return NULL;
 
-	set = (struct isl_set *)map;
+	set = set_from_map(map);
 	set->dim = isl_space_domain(set->dim);
 	if (!set->dim)
 		goto error;
@@ -7298,15 +7291,13 @@ __isl_give isl_map *isl_map_union(__isl_
 struct isl_set *isl_set_union_disjoint(
 			struct isl_set *set1, struct isl_set *set2)
 {
-	return (struct isl_set *)
-		isl_map_union_disjoint(
-			(struct isl_map *)set1, (struct isl_map *)set2);
+	return set_from_map(isl_map_union_disjoint(set_to_map(set1),
+						    set_to_map(set2)));
 }
 
 struct isl_set *isl_set_union(struct isl_set *set1, struct isl_set *set2)
 {
-	return (struct isl_set *)
-		isl_map_union((struct isl_map *)set1, (struct isl_map *)set2);
+	return set_from_map(isl_map_union(set_to_map(set1), set_to_map(set2)));
 }
 
 /* Apply "fn" to pairs of elements from "map" and "set" and collect
@@ -7837,7 +7828,7 @@ int isl_set_foreach_orthant(__isl_keep i
 
 isl_bool isl_set_is_equal(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
 {
-	return isl_map_is_equal((struct isl_map *)set1, (struct isl_map *)set2);
+	return isl_map_is_equal(set_to_map(set1), set_to_map(set2));
 }
 
 isl_bool isl_basic_map_is_subset(__isl_keep isl_basic_map *bmap1,
@@ -7885,7 +7876,7 @@ isl_bool isl_basic_set_is_equal(__isl_ke
 	__isl_keep isl_basic_set *bset2)
 {
 	return isl_basic_map_is_equal(
-		(struct isl_basic_map *)bset1, (struct isl_basic_map *)bset2);
+		bset_to_bmap(bset1), bset_to_bmap(bset2));
 }
 
 isl_bool isl_map_is_empty(__isl_keep isl_map *map)
@@ -7917,7 +7908,7 @@ isl_bool isl_set_plain_is_empty(__isl_ke
 
 isl_bool isl_set_is_empty(__isl_keep isl_set *set)
 {
-	return isl_map_is_empty((struct isl_map *)set);
+	return isl_map_is_empty(set_to_map(set));
 }
 
 int isl_map_has_equal_space(__isl_keep isl_map *map1, __isl_keep isl_map *map2)
@@ -7999,7 +7990,7 @@ isl_bool isl_map_is_strict_subset(__isl_
 isl_bool isl_set_is_strict_subset(__isl_keep isl_set *set1,
 	__isl_keep isl_set *set2)
 {
-	return isl_map_is_strict_subset((isl_map *)set1, (isl_map *)set2);
+	return isl_map_is_strict_subset(set_to_map(set1), set_to_map(set2));
 }
 
 /* Is "bmap" obviously equal to the universe with the same space?
@@ -8091,7 +8082,7 @@ isl_bool isl_map_plain_is_universe(__isl
 
 isl_bool isl_set_plain_is_universe(__isl_keep isl_set *set)
 {
-	return isl_map_plain_is_universe((isl_map *) set);
+	return isl_map_plain_is_universe(set_to_map(set));
 }
 
 isl_bool isl_basic_map_is_empty(__isl_keep isl_basic_map *bmap)
@@ -8173,7 +8164,7 @@ isl_bool isl_basic_map_plain_is_non_empt
 
 isl_bool isl_basic_set_is_empty(__isl_keep isl_basic_set *bset)
 {
-	return isl_basic_map_is_empty((struct isl_basic_map *)bset);
+	return isl_basic_map_is_empty(bset_to_bmap(bset));
 }
 
 struct isl_map *isl_basic_map_union(
@@ -8200,9 +8191,8 @@ error:
 struct isl_set *isl_basic_set_union(
 		struct isl_basic_set *bset1, struct isl_basic_set *bset2)
 {
-	return (struct isl_set *)isl_basic_map_union(
-					    (struct isl_basic_map *)bset1,
-					    (struct isl_basic_map *)bset2);
+	return set_from_map(isl_basic_map_union(bset_to_bmap(bset1),
+						bset_to_bmap(bset2)));
 }
 
 /* Order divs such that any div only depends on previous divs */
@@ -8236,8 +8226,7 @@ struct isl_basic_map *isl_basic_map_orde
 
 struct isl_basic_set *isl_basic_set_order_divs(struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_order_divs((struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_order_divs(bset_to_bmap(bset)));
 }
 
 __isl_give isl_map *isl_map_order_divs(__isl_take isl_map *map)
@@ -8259,6 +8248,14 @@ error:
 	return NULL;
 }
 
+/* Sort the local variables of "bset".
+ */
+__isl_give isl_basic_set *isl_basic_set_sort_divs(
+	__isl_take isl_basic_set *bset)
+{
+	return bset_from_bmap(isl_basic_map_sort_divs(bset_to_bmap(bset)));
+}
+
 /* Apply the expansion computed by isl_merge_divs.
  * The expansion itself is given by "exp" while the resulting
  * list of divs is given by "div".
@@ -8270,7 +8267,7 @@ error:
  * in the definitions of the extra integer divisions.
  */
 __isl_give isl_basic_map *isl_basic_map_expand_divs(
-	__isl_take isl_basic_set *bmap, __isl_take isl_mat *div, int *exp)
+	__isl_take isl_basic_map *bmap, __isl_take isl_mat *div, int *exp)
 {
 	int i, j;
 	int n_div;
@@ -8412,8 +8409,8 @@ __isl_give isl_basic_map *isl_basic_map_
 struct isl_basic_set *isl_basic_set_align_divs(
 		struct isl_basic_set *dst, struct isl_basic_set *src)
 {
-	return (struct isl_basic_set *)isl_basic_map_align_divs(
-		(struct isl_basic_map *)dst, (struct isl_basic_map *)src);
+	return bset_from_bmap(isl_basic_map_align_divs(bset_to_bmap(dst),
+							bset_to_bmap(src)));
 }
 
 struct isl_map *isl_map_align_divs(struct isl_map *map)
@@ -8443,7 +8440,7 @@ struct isl_map *isl_map_align_divs(struc
 
 struct isl_set *isl_set_align_divs(struct isl_set *set)
 {
-	return (struct isl_set *)isl_map_align_divs((struct isl_map *)set);
+	return set_from_map(isl_map_align_divs(set_to_map(set)));
 }
 
 /* Align the divs of the basic maps in "map" to those
@@ -8538,8 +8535,7 @@ struct isl_map *isl_map_remove_empty_par
 
 struct isl_set *isl_set_remove_empty_parts(struct isl_set *set)
 {
-	return (struct isl_set *)
-		isl_map_remove_empty_parts((struct isl_map *)set);
+	return set_from_map(isl_map_remove_empty_parts(set_to_map(set)));
 }
 
 struct isl_basic_map *isl_map_copy_basic_map(struct isl_map *map)
@@ -8554,8 +8550,7 @@ struct isl_basic_map *isl_map_copy_basic
 
 struct isl_basic_set *isl_set_copy_basic_set(struct isl_set *set)
 {
-	return (struct isl_basic_set *)
-		isl_map_copy_basic_map((struct isl_map *)set);
+	return bset_from_bmap(isl_map_copy_basic_map(set_to_map(set)));
 }
 
 __isl_give isl_map *isl_map_drop_basic_map(__isl_take isl_map *map,
@@ -8588,8 +8583,8 @@ error:
 struct isl_set *isl_set_drop_basic_set(struct isl_set *set,
 						struct isl_basic_set *bset)
 {
-	return (struct isl_set *)isl_map_drop_basic_map((struct isl_map *)set,
-						(struct isl_basic_map *)bset);
+	return set_from_map(isl_map_drop_basic_map(set_to_map(set),
+						bset_to_bmap(bset)));
 }
 
 /* Given two basic sets bset1 and bset2, compute the maximal difference
@@ -8817,14 +8812,14 @@ static int isl_map_plain_has_fixed_var(_
 static int isl_basic_set_plain_has_fixed_var(__isl_keep isl_basic_set *bset,
 	unsigned pos, isl_int *val)
 {
-	return isl_basic_map_plain_has_fixed_var((struct isl_basic_map *)bset,
+	return isl_basic_map_plain_has_fixed_var(bset_to_bmap(bset),
 						pos, val);
 }
 
 static int isl_set_plain_has_fixed_var(__isl_keep isl_set *set, unsigned pos,
 	isl_int *val)
 {
-	return isl_map_plain_has_fixed_var((struct isl_map *)set, pos, val);
+	return isl_map_plain_has_fixed_var(set_to_map(set), pos, val);
 }
 
 int isl_basic_map_plain_is_fixed(__isl_keep isl_basic_map *bmap,
@@ -9101,8 +9096,8 @@ __isl_give isl_basic_map *isl_basic_map_
 __isl_give isl_basic_set *isl_basic_set_sort_constraints(
 	__isl_take isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)isl_basic_map_sort_constraints(
-						(struct isl_basic_map *)bset);
+	isl_basic_map *bmap = bset_to_bmap(bset);
+	return bset_from_bmap(isl_basic_map_sort_constraints(bmap));
 }
 
 struct isl_basic_map *isl_basic_map_normalize(struct isl_basic_map *bmap)
@@ -9120,8 +9115,7 @@ struct isl_basic_map *isl_basic_map_norm
 
 struct isl_basic_set *isl_basic_set_normalize(struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)isl_basic_map_normalize(
-						(struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_normalize(bset_to_bmap(bset)));
 }
 
 int isl_basic_map_plain_cmp(const __isl_keep isl_basic_map *bmap1,
@@ -9211,8 +9205,8 @@ isl_bool isl_basic_map_plain_is_equal(__
 isl_bool isl_basic_set_plain_is_equal(__isl_keep isl_basic_set *bset1,
 	__isl_keep isl_basic_set *bset2)
 {
-	return isl_basic_map_plain_is_equal((isl_basic_map *)bset1,
-					    (isl_basic_map *)bset2);
+	return isl_basic_map_plain_is_equal(bset_to_bmap(bset1),
+					    bset_to_bmap(bset2));
 }
 
 static int qsort_bmap_cmp(const void *p1, const void *p2)
@@ -9315,7 +9309,7 @@ error:
 
 struct isl_set *isl_set_normalize(struct isl_set *set)
 {
-	return (struct isl_set *)isl_map_normalize((struct isl_map *)set);
+	return set_from_map(isl_map_normalize(set_to_map(set)));
 }
 
 isl_bool isl_map_plain_is_equal(__isl_keep isl_map *map1,
@@ -9356,8 +9350,7 @@ error:
 isl_bool isl_set_plain_is_equal(__isl_keep isl_set *set1,
 	__isl_keep isl_set *set2)
 {
-	return isl_map_plain_is_equal((struct isl_map *)set1,
-						(struct isl_map *)set2);
+	return isl_map_plain_is_equal(set_to_map(set1), set_to_map(set2));
 }
 
 /* Return an interval that ranges from min to max (inclusive)
@@ -10049,7 +10042,7 @@ uint32_t isl_basic_map_get_hash(__isl_ke
 
 uint32_t isl_basic_set_get_hash(__isl_keep isl_basic_set *bset)
 {
-	return isl_basic_map_get_hash((isl_basic_map *)bset);
+	return isl_basic_map_get_hash(bset_to_bmap(bset));
 }
 
 uint32_t isl_map_get_hash(__isl_keep isl_map *map)
@@ -10078,7 +10071,7 @@ uint32_t isl_map_get_hash(__isl_keep isl
 
 uint32_t isl_set_get_hash(__isl_keep isl_set *set)
 {
-	return isl_map_get_hash((isl_map *)set);
+	return isl_map_get_hash(set_to_map(set));
 }
 
 /* Check if the value for dimension dim is completely determined
@@ -10417,7 +10410,7 @@ int isl_map_dim_is_bounded(__isl_keep is
 int isl_set_dim_is_bounded(__isl_keep isl_set *set,
 	enum isl_dim_type type, unsigned pos)
 {
-	return isl_map_dim_is_bounded((isl_map *)set, type, pos);
+	return isl_map_dim_is_bounded(set_to_map(set), type, pos);
 }
 
 /* Does "map" have a bound (according to "fn") for any of its basic maps?
@@ -10924,7 +10917,7 @@ isl_bool isl_map_is_bijective(__isl_keep
 
 isl_bool isl_set_is_singleton(__isl_keep isl_set *set)
 {
-	return isl_map_is_single_valued((isl_map *)set);
+	return isl_map_is_single_valued(set_to_map(set));
 }
 
 /* Does "map" only map elements to themselves?
@@ -11103,7 +11096,7 @@ __isl_give isl_basic_set *isl_basic_map_
 
 	bmap = isl_basic_map_finalize(bmap);
 
-	return (isl_basic_set *)bmap;
+	return bset_from_bmap(bmap);
 error:
 	isl_basic_map_free(bmap);
 	return NULL;
@@ -11128,7 +11121,7 @@ __isl_give isl_basic_map *isl_basic_set_
 
 	bset = isl_basic_set_finalize(bset);
 
-	return (isl_basic_map *)bset;
+	return bset_to_bmap(bset);
 error:
 	isl_basic_set_free(bset);
 	return NULL;
@@ -11224,7 +11217,7 @@ error:
 
 __isl_give isl_basic_set *isl_basic_set_flatten(__isl_take isl_basic_set *bset)
 {
-	return (isl_basic_set *)isl_basic_map_flatten((isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_flatten(bset_to_bmap(bset)));
 }
 
 __isl_give isl_basic_map *isl_basic_map_flatten_domain(
@@ -11292,7 +11285,7 @@ __isl_give isl_map *isl_map_flatten(__is
 
 __isl_give isl_set *isl_set_flatten(__isl_take isl_set *set)
 {
-	return (isl_set *)isl_map_flatten((isl_map *)set);
+	return set_from_map(isl_map_flatten(set_to_map(set)));
 }
 
 __isl_give isl_map *isl_set_flatten_map(__isl_take isl_set *set)
@@ -11407,7 +11400,7 @@ error:
 __isl_give isl_set *isl_set_realign(__isl_take isl_set *set,
 	__isl_take isl_reordering *r)
 {
-	return (isl_set *)isl_map_realign((isl_map *)set, r);
+	return set_from_map(isl_map_realign(set_to_map(set), r));
 }
 
 __isl_give isl_map *isl_map_align_params(__isl_take isl_map *map,
@@ -11646,7 +11639,7 @@ __isl_give isl_mat *isl_basic_set_equali
 	__isl_keep isl_basic_set *bset, enum isl_dim_type c1,
 	enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
 {
-	return isl_basic_map_equalities_matrix((isl_basic_map *)bset,
+	return isl_basic_map_equalities_matrix(bset_to_bmap(bset),
 						c1, c2, c3, c4, isl_dim_in);
 }
 
@@ -11654,7 +11647,7 @@ __isl_give isl_mat *isl_basic_set_inequa
 	__isl_keep isl_basic_set *bset, enum isl_dim_type c1,
 	enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
 {
-	return isl_basic_map_inequalities_matrix((isl_basic_map *)bset,
+	return isl_basic_map_inequalities_matrix(bset_to_bmap(bset),
 						 c1, c2, c3, c4, isl_dim_in);
 }
 
@@ -11663,9 +11656,10 @@ __isl_give isl_basic_set *isl_basic_set_
 	__isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1,
 	enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4)
 {
-	return (isl_basic_set*)
-	    isl_basic_map_from_constraint_matrices(dim, eq, ineq,
+	isl_basic_map *bmap;
+	bmap = isl_basic_map_from_constraint_matrices(dim, eq, ineq,
 						   c1, c2, c3, c4, isl_dim_in);
+	return bset_from_bmap(bmap);
 }
 
 isl_bool isl_basic_map_can_zip(__isl_keep isl_basic_map *bmap)

Modified: polly/trunk/lib/External/isl/isl_map_private.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_map_private.h?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_map_private.h (original)
+++ polly/trunk/lib/External/isl/isl_map_private.h Wed Nov 16 05:06:47 2016
@@ -277,6 +277,8 @@ __isl_give isl_map *isl_map_align_divs_t
 	__isl_take isl_map *map, __isl_keep isl_basic_map_list *list);
 __isl_give isl_basic_map_list *isl_basic_map_list_align_divs_to_basic_map(
 	__isl_take isl_basic_map_list *list, __isl_keep isl_basic_map *bmap);
+__isl_give isl_basic_set *isl_basic_set_sort_divs(
+	__isl_take isl_basic_set *bset);
 __isl_give isl_basic_map *isl_basic_map_sort_divs(
 	__isl_take isl_basic_map *bmap);
 __isl_give isl_map *isl_map_sort_divs(__isl_take isl_map *map);

Modified: polly/trunk/lib/External/isl/isl_map_simplify.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_map_simplify.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_map_simplify.c (original)
+++ polly/trunk/lib/External/isl/isl_map_simplify.c Wed Nov 16 05:06:47 2016
@@ -23,6 +23,11 @@
 #include <isl_mat_private.h>
 #include <isl_vec_private.h>
 
+#include <bset_to_bmap.c>
+#include <bset_from_bmap.c>
+#include <set_to_map.c>
+#include <set_from_map.c>
+
 static void swap_equality(struct isl_basic_map *bmap, int a, int b)
 {
 	isl_int *t = bmap->eq[a];
@@ -212,8 +217,8 @@ error:
 __isl_give isl_basic_set *isl_basic_set_drop(__isl_take isl_basic_set *bset,
 	enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_basic_set *)isl_basic_map_drop((isl_basic_map *)bset,
-							type, first, n);
+	return bset_from_bmap(isl_basic_map_drop(bset_to_bmap(bset),
+							type, first, n));
 }
 
 struct isl_basic_map *isl_basic_map_drop_inputs(
@@ -257,7 +262,7 @@ error:
 struct isl_set *isl_set_drop(struct isl_set *set,
 	enum isl_dim_type type, unsigned first, unsigned n)
 {
-	return (isl_set *)isl_map_drop((isl_map *)set, type, first, n);
+	return set_from_map(isl_map_drop(set_to_map(set), type, first, n));
 }
 
 struct isl_map *isl_map_drop_inputs(
@@ -372,8 +377,8 @@ struct isl_basic_map *isl_basic_map_norm
 struct isl_basic_set *isl_basic_set_normalize_constraints(
 	struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)isl_basic_map_normalize_constraints(
-		(struct isl_basic_map *)bset);
+	isl_basic_map *bmap = bset_to_bmap(bset);
+	return bset_from_bmap(isl_basic_map_normalize_constraints(bmap));
 }
 
 /* Assuming the variable at position "pos" has an integer coefficient
@@ -745,8 +750,8 @@ struct isl_basic_map *isl_basic_map_gaus
 struct isl_basic_set *isl_basic_set_gauss(
 	struct isl_basic_set *bset, int *progress)
 {
-	return (struct isl_basic_set*)isl_basic_map_gauss(
-			(struct isl_basic_map *)bset, progress);
+	return bset_from_bmap(isl_basic_map_gauss(bset_to_bmap(bset),
+							progress));
 }
 
 
@@ -1419,7 +1424,7 @@ __isl_give isl_basic_map *isl_basic_map_
  * We skip integral divs, i.e., those with denominator 1, as we would
  * risk eliminating the div from the div constraints.  We do not need
  * to handle those divs here anyway since the div constraints will turn
- * out to form an equality and this equality can then be use to eliminate
+ * out to form an equality and this equality can then be used to eliminate
  * the div from all constraints.
  */
 static __isl_give isl_basic_map *eliminate_unit_divs(
@@ -1508,8 +1513,7 @@ struct isl_basic_map *isl_basic_map_simp
 
 struct isl_basic_set *isl_basic_set_simplify(struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_simplify((struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_simplify(bset_to_bmap(bset)));
 }
 
 
@@ -1635,8 +1639,7 @@ struct isl_basic_map *isl_basic_map_fina
 
 struct isl_basic_set *isl_basic_set_finalize(struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-		isl_basic_map_finalize((struct isl_basic_map *)bset);
+	return bset_from_bmap(isl_basic_map_finalize(bset_to_bmap(bset)));
 }
 
 struct isl_set *isl_set_finalize(struct isl_set *set)
@@ -1799,8 +1802,8 @@ error:
 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(
-			(struct isl_basic_map *)bset, pos, n);
+	return bset_from_bmap(isl_basic_map_eliminate_vars(bset_to_bmap(bset),
+								pos, n));
 }
 
 /* Eliminate the specified n dimensions starting at first from the
@@ -1949,7 +1952,7 @@ static void compute_elimination_index(st
 
 static void set_compute_elimination_index(struct isl_basic_set *bset, int *elim)
 {
-	compute_elimination_index((struct isl_basic_map *)bset, elim);
+	compute_elimination_index(bset_to_bmap(bset), elim);
 }
 
 static int reduced_using_equalities(isl_int *dst, isl_int *src,
@@ -1978,7 +1981,7 @@ static int set_reduced_using_equalities(
 	struct isl_basic_set *bset, int *elim)
 {
 	return reduced_using_equalities(dst, src,
-					(struct isl_basic_map *)bset, elim);
+					bset_to_bmap(bset), elim);
 }
 
 static struct isl_basic_set *isl_basic_set_reduce_using_equalities(
@@ -3644,15 +3647,15 @@ __isl_give isl_map *isl_map_gist(__isl_t
 struct isl_basic_set *isl_basic_set_gist(struct isl_basic_set *bset,
 						struct isl_basic_set *context)
 {
-	return (struct isl_basic_set *)isl_basic_map_gist(
-		(struct isl_basic_map *)bset, (struct isl_basic_map *)context);
+	return bset_from_bmap(isl_basic_map_gist(bset_to_bmap(bset),
+						bset_to_bmap(context)));
 }
 
 __isl_give isl_set *isl_set_gist_basic_set(__isl_take isl_set *set,
 	__isl_take isl_basic_set *context)
 {
-	return (struct isl_set *)isl_map_gist_basic_map((struct isl_map *)set,
-					(struct isl_basic_map *)context);
+	return set_from_map(isl_map_gist_basic_map(set_to_map(set),
+					bset_to_bmap(context)));
 }
 
 __isl_give isl_set *isl_set_gist_params_basic_set(__isl_take isl_set *set,
@@ -3667,8 +3670,7 @@ __isl_give isl_set *isl_set_gist_params_
 __isl_give isl_set *isl_set_gist(__isl_take isl_set *set,
 	__isl_take isl_set *context)
 {
-	return (struct isl_set *)isl_map_gist((struct isl_map *)set,
-					(struct isl_map *)context);
+	return set_from_map(isl_map_gist(set_to_map(set), set_to_map(context)));
 }
 
 /* Compute the gist of "bmap" with respect to the constraints "context"
@@ -3787,8 +3789,8 @@ error:
 int isl_basic_set_plain_is_disjoint(__isl_keep isl_basic_set *bset1,
 	__isl_keep isl_basic_set *bset2)
 {
-	return isl_basic_map_plain_is_disjoint((struct isl_basic_map *)bset1,
-					      (struct isl_basic_map *)bset2);
+	return isl_basic_map_plain_is_disjoint(bset_to_bmap(bset1),
+					      bset_to_bmap(bset2));
 }
 
 /* Does "test" hold for all pairs of basic maps in "map1" and "map2"?
@@ -3980,8 +3982,7 @@ isl_bool isl_basic_set_is_disjoint(__isl
 isl_bool isl_set_plain_is_disjoint(__isl_keep isl_set *set1,
 	__isl_keep isl_set *set2)
 {
-	return isl_map_plain_is_disjoint((struct isl_map *)set1,
-					(struct isl_map *)set2);
+	return isl_map_plain_is_disjoint(set_to_map(set1), set_to_map(set2));
 }
 
 /* Are "set1" and "set2" disjoint?
@@ -5099,8 +5100,8 @@ __isl_give isl_basic_map *isl_basic_map_
 struct isl_basic_set *isl_basic_set_drop_redundant_divs(
 	struct isl_basic_set *bset)
 {
-	return (struct isl_basic_set *)
-	    isl_basic_map_drop_redundant_divs((struct isl_basic_map *)bset);
+	isl_basic_map *bmap = bset_to_bmap(bset);
+	return bset_from_bmap(isl_basic_map_drop_redundant_divs(bmap));
 }
 
 struct isl_map *isl_map_drop_redundant_divs(struct isl_map *map)
@@ -5123,8 +5124,7 @@ error:
 
 struct isl_set *isl_set_drop_redundant_divs(struct isl_set *set)
 {
-	return (struct isl_set *)
-	    isl_map_drop_redundant_divs((struct isl_map *)set);
+	return set_from_map(isl_map_drop_redundant_divs(set_to_map(set)));
 }
 
 /* Does "bmap" satisfy any equality that involves more than 2 variables

Modified: polly/trunk/lib/External/isl/isl_map_subtract.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_map_subtract.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_map_subtract.c (original)
+++ polly/trunk/lib/External/isl/isl_map_subtract.c Wed Nov 16 05:06:47 2016
@@ -15,6 +15,9 @@
 #include <isl_point_private.h>
 #include <isl_vec_private.h>
 
+#include <set_to_map.c>
+#include <set_from_map.c>
+
 /* Expand the constraint "c" into "v".  The initial "dim" dimensions
  * are the same, but "v" may have more divs than "c" and the divs of "c"
  * may appear in different positions in "v".
@@ -579,9 +582,8 @@ __isl_give isl_map *isl_map_subtract( __
 
 struct isl_set *isl_set_subtract(struct isl_set *set1, struct isl_set *set2)
 {
-	return (struct isl_set *)
-		isl_map_subtract(
-			(struct isl_map *)set1, (struct isl_map *)set2);
+	return set_from_map(isl_map_subtract(set_to_map(set1),
+					    set_to_map(set2)));
 }
 
 /* Remove the elements of "dom" from the domain of "map".
@@ -868,8 +870,7 @@ isl_bool isl_map_is_subset(__isl_keep is
 
 isl_bool isl_set_is_subset(__isl_keep isl_set *set1, __isl_keep isl_set *set2)
 {
-	return isl_map_is_subset(
-			(struct isl_map *)set1, (struct isl_map *)set2);
+	return isl_map_is_subset(set_to_map(set1), set_to_map(set2));
 }
 
 __isl_give isl_map *isl_map_make_disjoint(__isl_take isl_map *map)
@@ -910,7 +911,7 @@ __isl_give isl_map *isl_map_make_disjoin
 
 __isl_give isl_set *isl_set_make_disjoint(__isl_take isl_set *set)
 {
-	return (struct isl_set *)isl_map_make_disjoint((struct isl_map *)set);
+	return set_from_map(isl_map_make_disjoint(set_to_map(set)));
 }
 
 __isl_give isl_map *isl_map_complement(__isl_take isl_map *map)

Modified: polly/trunk/lib/External/isl/isl_output.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_output.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_output.c (original)
+++ polly/trunk/lib/External/isl/isl_output.c Wed Nov 16 05:06:47 2016
@@ -32,6 +32,9 @@
 #include <isl_sort.h>
 #include <isl_output_private.h>
 
+#include <bset_to_bmap.c>
+#include <set_to_map.c>
+
 static const char *s_to[2] = { " -> ", " \\to " };
 static const char *s_and[2] = { " and ", " \\wedge " };
 static const char *s_or[2] = { " or ", " \\vee " };
@@ -100,7 +103,7 @@ static __isl_give isl_printer *print_con
 static __isl_give isl_printer *bset_print_constraints_polylib(
 	struct isl_basic_set *bset, __isl_take isl_printer *p)
 {
-	return print_constraints_polylib((struct isl_basic_map *)bset, p);
+	return print_constraints_polylib(bset_to_bmap(bset), p);
 }
 
 static __isl_give isl_printer *isl_basic_map_print_polylib(
@@ -132,7 +135,7 @@ static __isl_give isl_printer *isl_basic
 static __isl_give isl_printer *isl_basic_set_print_polylib(
 	__isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int ext)
 {
-	return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p, ext);
+	return isl_basic_map_print_polylib(bset_to_bmap(bset), p, ext);
 }
 
 static __isl_give isl_printer *isl_map_print_polylib(__isl_keep isl_map *map,
@@ -154,7 +157,7 @@ static __isl_give isl_printer *isl_map_p
 static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
 	__isl_take isl_printer *p, int ext)
 {
-	return isl_map_print_polylib((struct isl_map *)set, p, ext);
+	return isl_map_print_polylib(set_to_map(set), p, ext);
 }
 
 static int count_same_name(__isl_keep isl_space *dim,
@@ -1318,7 +1321,7 @@ __isl_give isl_printer *isl_printer_prin
 	if (!p || !set)
 		goto error;
 	if (p->output_format == ISL_FORMAT_ISL)
-		return isl_map_print_isl((isl_map *)set, p);
+		return isl_map_print_isl(set_to_map(set), p);
 	else if (p->output_format == ISL_FORMAT_POLYLIB)
 		return isl_set_print_polylib(set, p, 0);
 	else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
@@ -1326,7 +1329,7 @@ __isl_give isl_printer *isl_printer_prin
 	else if (p->output_format == ISL_FORMAT_OMEGA)
 		return isl_set_print_omega(set, p);
 	else if (p->output_format == ISL_FORMAT_LATEX)
-		return isl_map_print_latex((isl_map *)set, p);
+		return isl_map_print_latex(set_to_map(set), p);
 	isl_assert(set->ctx, 0, goto error);
 error:
 	isl_printer_free(p);
@@ -1739,7 +1742,7 @@ static __isl_give isl_printer *isl_pwqp_
 			p = isl_printer_print_str(p, " -> ");
 		}
 		p = print_qpolynomial(p, pwqp->p[i].qp);
-		p = print_disjuncts((isl_map *)pwqp->p[i].set, space, p, 0);
+		p = print_disjuncts(set_to_map(pwqp->p[i].set), space, p, 0);
 		isl_space_free(space);
 	}
 
@@ -1806,7 +1809,7 @@ static __isl_give isl_printer *isl_pwf_p
 			p = isl_printer_print_str(p, " -> ");
 		}
 		p = qpolynomial_fold_print(pwf->p[i].fold, p);
-		p = print_disjuncts((isl_map *)pwf->p[i].set, space, p, 0);
+		p = print_disjuncts(set_to_map(pwf->p[i].set), space, p, 0);
 		isl_space_free(space);
 	}
 
@@ -2407,7 +2410,7 @@ static __isl_give isl_printer *print_pw_
 			p = isl_printer_print_str(p, "; ");
 		p = print_aff(p, pa->p[i].aff);
 		space = isl_aff_get_domain_space(pa->p[i].aff);
-		p = print_disjuncts((isl_map *)pa->p[i].set, space, p, 0);
+		p = print_disjuncts(set_to_map(pa->p[i].set), space, p, 0);
 		isl_space_free(space);
 	}
 
@@ -2751,7 +2754,7 @@ static __isl_give isl_printer *print_pw_
 			p = isl_printer_print_str(p, "; ");
 		p = print_multi_aff(p, pma->p[i].maff);
 		space = isl_multi_aff_get_domain_space(pma->p[i].maff);
-		p = print_disjuncts((isl_map *)pma->p[i].set, space, p, 0);
+		p = print_disjuncts(set_to_map(pma->p[i].set), space, p, 0);
 		isl_space_free(space);
 	}
 	return p;

Modified: polly/trunk/lib/External/isl/isl_point.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_point.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_point.c (original)
+++ polly/trunk/lib/External/isl/isl_point.c Wed Nov 16 05:06:47 2016
@@ -11,6 +11,8 @@
 #include <isl_output_private.h>
 #include <isl/deprecated/point_int.h>
 
+#include <set_to_map.c>
+
 isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt)
 {
 	return pnt ? isl_space_get_ctx(pnt->dim) : NULL;
@@ -421,7 +423,7 @@ error:
 isl_bool isl_set_contains_point(__isl_keep isl_set *set,
 	__isl_keep isl_point *point)
 {
-	return isl_map_contains_point((isl_map *)set, point);
+	return isl_map_contains_point(set_to_map(set), point);
 }
 
 __isl_give isl_basic_set *isl_basic_set_from_point(__isl_take isl_point *pnt)

Modified: polly/trunk/lib/External/isl/isl_sample.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_sample.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_sample.c (original)
+++ polly/trunk/lib/External/isl/isl_sample.c Wed Nov 16 05:06:47 2016
@@ -21,6 +21,9 @@
 #include <isl_options_private.h>
 #include <isl_vec_private.h>
 
+#include <bset_from_bmap.c>
+#include <set_to_map.c>
+
 static struct isl_vec *empty_sample(struct isl_basic_set *bset)
 {
 	struct isl_vec *vec;
@@ -1261,7 +1264,7 @@ error:
 
 __isl_give isl_basic_set *isl_set_sample(__isl_take isl_set *set)
 {
-	return (isl_basic_set *) isl_map_sample((isl_map *)set);
+	return bset_from_bmap(isl_map_sample(set_to_map(set)));
 }
 
 __isl_give isl_point *isl_basic_set_sample_point(__isl_take isl_basic_set *bset)

Modified: polly/trunk/lib/External/isl/isl_tab.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_tab.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_tab.c (original)
+++ polly/trunk/lib/External/isl/isl_tab.c Wed Nov 16 05:06:47 2016
@@ -20,6 +20,9 @@
 #include <isl_seq.h>
 #include <isl_config.h>
 
+#include <bset_to_bmap.c>
+#include <bset_from_bmap.c>
+
 /*
  * The implementation of tableaus in this file was inspired by Section 8
  * of David Detlefs, Greg Nelson and James B. Saxe, "Simplify: a theorem
@@ -2613,8 +2616,8 @@ struct isl_basic_map *isl_basic_map_upda
 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
 	struct isl_tab *tab)
 {
-	return (struct isl_basic_set *)isl_basic_map_update_from_tab(
-		(struct isl_basic_map *)bset, tab);
+	return bset_from_bmap(isl_basic_map_update_from_tab(bset_to_bmap(bset),
+								tab));
 }
 
 /* Drop the last constraint added to "tab" in position "r".
@@ -3722,7 +3725,7 @@ error:
 
 int isl_tab_track_bset(struct isl_tab *tab, __isl_take isl_basic_set *bset)
 {
-	return isl_tab_track_bmap(tab, (isl_basic_map *)bset);
+	return isl_tab_track_bmap(tab, bset_to_bmap(bset));
 }
 
 __isl_keep isl_basic_set *isl_tab_peek_bset(struct isl_tab *tab)
@@ -3730,7 +3733,7 @@ __isl_keep isl_basic_set *isl_tab_peek_b
 	if (!tab)
 		return NULL;
 
-	return (isl_basic_set *)tab->bmap;
+	return bset_from_bmap(tab->bmap);
 }
 
 static void isl_tab_print_internal(__isl_keep struct isl_tab *tab,

Modified: polly/trunk/lib/External/isl/isl_tab_pip.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_tab_pip.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_tab_pip.c (original)
+++ polly/trunk/lib/External/isl/isl_tab_pip.c Wed Nov 16 05:06:47 2016
@@ -23,6 +23,8 @@
 #include <isl_options_private.h>
 #include <isl_config.h>
 
+#include <bset_to_bmap.c>
+
 /*
  * The implementation of parametric integer linear programming in this file
  * was inspired by the paper "Parametric Integer Programming" and the
@@ -603,7 +605,7 @@ static void sol_map_add_empty_wrap(struc
 	sol_map_add_empty((struct isl_sol_map *)sol, bset);
 }
 
-/* Given a basic map "dom" that represents the context and an affine
+/* Given a basic set "dom" that represents the context and an affine
  * matrix "M" that maps the dimensions of the context to the
  * output variables, construct a basic map with the same parameters
  * and divs as the context, the dimensions of the context as input
@@ -2634,7 +2636,7 @@ static struct isl_tab *context_tab_for_l
 
 	if (!bset)
 		return NULL;
-	tab = tab_for_lexmin((struct isl_basic_map *)bset, NULL, 1, 0);
+	tab = tab_for_lexmin(bset_to_bmap(bset), NULL, 1, 0);
 	if (!tab)
 		goto error;
 	if (isl_tab_track_bset(tab, bset) < 0)
@@ -4171,6 +4173,11 @@ error:
  * We make sure the divs in the domain are properly ordered,
  * because they will be added one by one in the given order
  * during the construction of the solution map.
+ * Furthermore, make sure that the known integer divisions
+ * appear before any unknown integer division because the solution
+ * may depend on the known integer divisions, while anything that
+ * depends on any variable starting from the first unknown integer
+ * division is ignored in sol_pma_add.
  */
 static struct isl_sol *basic_map_partial_lexopt_base_sol(
 	__isl_take isl_basic_map *bmap, __isl_take isl_basic_set *dom,
@@ -4183,7 +4190,7 @@ static struct isl_sol *basic_map_partial
 	struct isl_context *context;
 
 	if (dom->n_div) {
-		dom = isl_basic_set_order_divs(dom);
+		dom = isl_basic_set_sort_divs(dom);
 		bmap = align_context_divs(bmap, dom);
 	}
 	sol = init(bmap, dom, !!empty, max);
@@ -4546,7 +4553,7 @@ static int need_split_basic_map(__isl_ke
 static int need_split_basic_set(__isl_keep isl_basic_set *bset,
 	__isl_keep isl_mat *cst)
 {
-	return need_split_basic_map((isl_basic_map *)bset, cst);
+	return need_split_basic_map(bset_to_bmap(bset), cst);
 }
 
 /* Given that the last set variable of "set" represents the minimum
@@ -5356,6 +5363,27 @@ error:
 	sol->sol.error = 1;
 }
 
+/* Check that the final columns of "M", starting at "first", are zero.
+ */
+static isl_stat check_final_columns_are_zero(__isl_keep isl_mat *M,
+	unsigned first)
+{
+	int i;
+	unsigned rows, cols, n;
+
+	if (!M)
+		return isl_stat_error;
+	rows = isl_mat_rows(M);
+	cols = isl_mat_cols(M);
+	n = cols - first;
+	for (i = 0; i < rows; ++i)
+		if (isl_seq_first_non_zero(M->row[i] + first, n) != -1)
+			isl_die(isl_mat_get_ctx(M), isl_error_internal,
+				"final columns should be zero",
+				return isl_stat_error);
+	return isl_stat_ok;
+}
+
 /* Set the affine expressions in "ma" according to the rows in "M", which
  * are defined over the local space "ls".
  * The matrix "M" may have extra (zero) columns beyond the number
@@ -5372,6 +5400,8 @@ static __isl_give isl_multi_aff *set_fro
 		goto error;
 
 	dim = isl_local_space_dim(ls, isl_dim_all);
+	if (check_final_columns_are_zero(M, 1 + dim) < 0)
+		goto error;
 	for (i = 1; i < M->n_row; ++i) {
 		aff = isl_aff_alloc(isl_local_space_copy(ls));
 		if (aff) {
@@ -5392,7 +5422,7 @@ error:
 	return NULL;
 }
 
-/* Given a basic map "dom" that represents the context and an affine
+/* Given a basic set "dom" that represents the context and an affine
  * matrix "M" that maps the dimensions of the context to the
  * output variables, construct an isl_pw_multi_aff with a single
  * cell corresponding to "dom" and affine expressions copied from "M".
@@ -5401,9 +5431,10 @@ error:
  * existentially quantified variables, in which case they also appear
  * in "dom".  These need to be removed before creating the affine
  * expression because an affine expression cannot be defined in terms
+ * of existentially quantified variables without a known representation.
  * Since newly added integer divisions are inserted before these
  * existentially quantified variables, they are still in the final
- * positions and the corresponding final columns "M" are zero
+ * positions and the corresponding final columns of "M" are zero
  * because align_context_divs adds the existentially quantified
  * variables of the context to the main tableau without any constraints and
  * any equality constraints that are added later on can only serve

Modified: polly/trunk/lib/External/isl/isl_test.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_test.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_test.c (original)
+++ polly/trunk/lib/External/isl/isl_test.c Wed Nov 16 05:06:47 2016
@@ -6034,6 +6034,49 @@ static int test_ast_gen5(isl_ctx *ctx)
 	return 0;
 }
 
+/* Check that the expression
+ *
+ *	[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }
+ *
+ * is not combined into
+ *
+ *	min(n/2, 0)
+ *
+ * as this would result in n/2 being evaluated in parts of
+ * the definition domain where n is not a multiple of 2.
+ */
+static int test_ast_expr(isl_ctx *ctx)
+{
+	const char *str;
+	isl_pw_aff *pa;
+	isl_ast_build *build;
+	isl_ast_expr *expr;
+	int min_max;
+	int is_min;
+
+	min_max = isl_options_get_ast_build_detect_min_max(ctx);
+	isl_options_set_ast_build_detect_min_max(ctx, 1);
+
+	str = "[n] -> { [n/2] : n <= 0 and n % 2 = 0; [0] : n > 0 }";
+	pa = isl_pw_aff_read_from_str(ctx, str);
+	build = isl_ast_build_alloc(ctx);
+	expr = isl_ast_build_expr_from_pw_aff(build, pa);
+	is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op &&
+		 isl_ast_expr_get_op_type(expr) == isl_ast_op_min;
+	isl_ast_build_free(build);
+	isl_ast_expr_free(expr);
+
+	isl_options_set_ast_build_detect_min_max(ctx, min_max);
+
+	if (!expr)
+		return -1;
+	if (is_min)
+		isl_die(ctx, isl_error_unknown,
+			"expressions should not be combined", return -1);
+
+	return 0;
+}
+
 static int test_ast_gen(isl_ctx *ctx)
 {
 	if (test_ast_gen1(ctx) < 0)
@@ -6046,6 +6089,8 @@ static int test_ast_gen(isl_ctx *ctx)
 		return -1;
 	if (test_ast_gen5(ctx) < 0)
 		return -1;
+	if (test_ast_expr(ctx) < 0)
+		return -1;
 	return 0;
 }
 

Modified: polly/trunk/lib/External/isl/isl_transitive_closure.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_transitive_closure.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_transitive_closure.c (original)
+++ polly/trunk/lib/External/isl/isl_transitive_closure.c Wed Nov 16 05:06:47 2016
@@ -2116,7 +2116,7 @@ __isl_give isl_map *isl_map_reaching_pat
 }
 
 /* Check whether equality i of bset is a pure stride constraint
- * on a single dimensions, i.e., of the form
+ * on a single dimension, i.e., of the form
  *
  *	v = k e
  *

Modified: polly/trunk/lib/External/isl/isl_union_map.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_union_map.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_union_map.c (original)
+++ polly/trunk/lib/External/isl/isl_union_map.c Wed Nov 16 05:06:47 2016
@@ -25,6 +25,10 @@
 #include <isl/union_set.h>
 #include <isl/deprecated/union_map_int.h>
 
+#include <bset_from_bmap.c>
+#include <set_to_map.c>
+#include <set_from_map.c>
+
 /* Return the number of parameters of "umap", where "type"
  * is required to be set to isl_dim_param.
  */
@@ -381,7 +385,7 @@ error:
 __isl_give isl_union_set *isl_union_set_add_set(__isl_take isl_union_set *uset,
 	__isl_take isl_set *set)
 {
-	return isl_union_map_add_map(uset, (isl_map *)set);
+	return isl_union_map_add_map(uset, set_to_map(set));
 }
 
 __isl_give isl_union_map *isl_union_map_from_map(__isl_take isl_map *map)
@@ -402,7 +406,7 @@ __isl_give isl_union_map *isl_union_map_
 
 __isl_give isl_union_set *isl_union_set_from_set(__isl_take isl_set *set)
 {
-	return isl_union_map_from_map((isl_map *)set);
+	return isl_union_map_from_map(set_to_map(set));
 }
 
 __isl_give isl_union_map *isl_union_map_from_basic_map(
@@ -522,7 +526,7 @@ error:
 __isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset,
 	__isl_take isl_space *dim)
 {
-	return (isl_set *)isl_union_map_extract_map(uset, dim);
+	return set_from_map(isl_union_map_extract_map(uset, dim));
 }
 
 /* Check if umap contains a map in the given space.
@@ -896,13 +900,13 @@ __isl_give isl_union_set *isl_union_set_
 static __isl_give isl_map *lex_le_set(__isl_take isl_map *set1,
 	__isl_take isl_map *set2)
 {
-	return isl_set_lex_le_set((isl_set *)set1, (isl_set *)set2);
+	return isl_set_lex_le_set(set_from_map(set1), set_from_map(set2));
 }
 
 static __isl_give isl_map *lex_lt_set(__isl_take isl_map *set1,
 	__isl_take isl_map *set2)
 {
-	return isl_set_lex_lt_set((isl_set *)set1, (isl_set *)set2);
+	return isl_set_lex_lt_set(set_from_map(set1), set_from_map(set2));
 }
 
 __isl_give isl_union_map *isl_union_set_lex_lt_union_set(
@@ -2442,7 +2446,7 @@ error:
 
 __isl_give isl_basic_set *isl_union_set_sample(__isl_take isl_union_set *uset)
 {
-	return (isl_basic_set *)isl_union_map_sample(uset);
+	return bset_from_bmap(isl_union_map_sample(uset));
 }
 
 /* Return an element in "uset" in the form of an isl_point.

Modified: polly/trunk/lib/External/isl/isl_vertices.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/isl_vertices.c?rev=287098&r1=287097&r2=287098&view=diff
==============================================================================
--- polly/trunk/lib/External/isl/isl_vertices.c (original)
+++ polly/trunk/lib/External/isl/isl_vertices.c Wed Nov 16 05:06:47 2016
@@ -272,7 +272,7 @@ static int is_independent(__isl_keep isl
  *
  * If the constraint is (strictly) redundant in the tableau, selecting it would
  * result in an empty tableau, so it can't be selected.
- * If the set variable part of the constraint is not linearly indepedent
+ * If the set variable part of the constraint is not linearly independent
  * of the set variable parts of the already selected constraints,
  * the constraint cannot be selected.
  * If selecting the constraint results in an empty tableau, the constraint
@@ -859,7 +859,7 @@ static int update_todo(struct isl_facet_
  * set.  As a minor optimization, we only consider those activity domains
  * that contain some arbitrary point.
  *
- * For each of interior facets of the chamber, we construct a todo item,
+ * For each of the interior facets of the chamber, we construct a todo item,
  * containing the facet and a constraint containing the other side of the facet,
  * for constructing the chamber on the other side.
  * While their are any todo items left, we pick a todo item and

Added: polly/trunk/lib/External/isl/set_from_map.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/set_from_map.c?rev=287098&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/set_from_map.c (added)
+++ polly/trunk/lib/External/isl/set_from_map.c Wed Nov 16 05:06:47 2016
@@ -0,0 +1,8 @@
+#include <isl/map_type.h>
+
+/* Return the set that was treated as the map "map".
+ */
+static __isl_give isl_set *set_from_map(__isl_take isl_map *map)
+{
+	return (isl_set *) map;
+}

Added: polly/trunk/lib/External/isl/set_to_map.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/set_to_map.c?rev=287098&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/set_to_map.c (added)
+++ polly/trunk/lib/External/isl/set_to_map.c Wed Nov 16 05:06:47 2016
@@ -0,0 +1,10 @@
+#include <isl/map_type.h>
+
+/* Treat "set" as a map.
+ * Internally, isl_set is defined to isl_map, so in practice,
+ * this function performs a redundant cast.
+ */
+static __isl_give isl_map *set_to_map(__isl_take isl_set *set)
+{
+	return (isl_map *) set;
+}

Added: polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.c?rev=287098&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.c (added)
+++ polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.c Wed Nov 16 05:06:47 2016
@@ -0,0 +1,3 @@
+for (int c0 = 1; c0 < max((6 * M + 3 * N + 188) / 200 - 2, (N + 93) / 100 + 3 * ((2 * M + N + 196) / 200) - 4); c0 += 1)
+  for (int c1 = max(0, floord(-N + 100 * c0 + 106, 300)); c1 <= min((2 * M + N - 4) / 200 - 1, (c0 - 1) / 3); c1 += 1)
+    S2(c0 - c1, c1);

Added: polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.st
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.st?rev=287098&view=auto
==============================================================================
--- polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.st (added)
+++ polly/trunk/lib/External/isl/test_inputs/codegen/sor1d-part.st Wed Nov 16 05:06:47 2016
@@ -0,0 +1,10 @@
+# Check that a proper upper bound is generated for the outer loop.
+# Earlier versions of isl would generate an incorrect bound.
+domain: "[M, N] -> { S2[i0, i1] : i1 >= 0 and  200i1 >= -193 - N + 100i0 and i0 >= 0 and 200i1 <= -204 + 2M + N and 2i1 <= -1 + i0 and 100i1 >= -94 - N + 50i0 and 100i1 >= -94 - N }"
+child:
+  context: "[M, N] -> { [] : M >= 0 and N >= 4 }"
+  child:
+    schedule: "[M, N] -> [{ S2[i0, i1] -> [(i0 + i1)]}]"
+    options: "[M, N] -> { separate[i0] }"
+    child:
+          schedule: "[M, N] -> [{ S2[i0, i1] -> [(i1)]}]"




More information about the llvm-commits mailing list