139 changes: 110 additions & 29 deletions polly/lib/External/isl/isl_local_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,44 @@ isl_size isl_local_space_dim(__isl_keep isl_local_space *ls,
#define TYPE isl_local_space
#include "check_type_range_templ.c"

unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
/* Return the position of the variables of the given type
* within the sequence of variables of "ls".
*/
isl_size isl_local_space_var_offset(__isl_keep isl_local_space *ls,
enum isl_dim_type type)
{
isl_space *space;

space = isl_local_space_peek_space(ls);
if (space < 0)
return isl_size_error;
switch (type) {
case isl_dim_param:
case isl_dim_in:
case isl_dim_out: return isl_space_offset(space, type);
case isl_dim_div: return isl_space_dim(space, isl_dim_all);
case isl_dim_cst:
default:
isl_die(isl_local_space_get_ctx(ls), isl_error_invalid,
"invalid dimension type", return isl_size_error);
}
}

/* Return the position of the coefficients of the variables of the given type
* within the sequence of coefficients of "ls".
*/
unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
enum isl_dim_type type)
{
if (!ls)
return 0;

space = ls->dim;
switch (type) {
case isl_dim_cst: return 0;
case isl_dim_param: return 1;
case isl_dim_in: return 1 + space->nparam;
case isl_dim_out: return 1 + space->nparam + space->n_in;
case isl_dim_div:
return 1 + space->nparam + space->n_in + space->n_out;
case isl_dim_param:
case isl_dim_in:
case isl_dim_out:
case isl_dim_div: return 1 + isl_local_space_var_offset(ls, type);
default: return 0;
}
}
Expand Down Expand Up @@ -464,6 +486,66 @@ __isl_keep isl_local *isl_local_space_peek_local(__isl_keep isl_local_space *ls)
return ls ? ls->div : NULL;
}

/* Return a copy of the local variables of "ls".
*/
__isl_keep isl_local *isl_local_space_get_local(__isl_keep isl_local_space *ls)
{
return isl_local_copy(isl_local_space_peek_local(ls));
}

/* Return the local variables of "ls".
* This may be either a copy or the local variables itself
* if there is only one reference to "ls".
* This allows the local variables to be modified inplace
* if both the local space and its local variables have only a single reference.
* The caller is not allowed to modify "ls" between this call and
* the subsequent call to isl_local_space_restore_local.
* The only exception is that isl_local_space_free can be called instead.
*/
static __isl_give isl_local *isl_local_space_take_local(
__isl_keep isl_local_space *ls)
{
isl_local *local;

if (!ls)
return NULL;
if (ls->ref != 1)
return isl_local_space_get_local(ls);
local = ls->div;
ls->div = NULL;
return local;
}

/* Set the local variables of "ls" to "local",
* where the local variables of "ls" may be missing
* due to a preceding call to isl_local_space_take_local.
* However, in this case, "ls" only has a single reference and
* then the call to isl_local_space_cow has no effect.
*/
static __isl_give isl_local_space *isl_local_space_restore_local(
__isl_take isl_local_space *ls, __isl_take isl_local *local)
{
if (!ls || !local)
goto error;

if (ls->div == local) {
isl_local_free(local);
return ls;
}

ls = isl_local_space_cow(ls);
if (!ls)
goto error;
isl_local_free(ls->div);
ls->div = local;

return ls;
error:
isl_local_space_free(ls);
isl_local_free(local);
return NULL;
}

/* Replace the identifier of the tuple of type "type" by "id".
*/
__isl_give isl_local_space *isl_local_space_set_tuple_id(
Expand Down Expand Up @@ -551,22 +633,16 @@ __isl_give isl_local_space *isl_local_space_reset_space(
__isl_give isl_local_space *isl_local_space_realign(
__isl_take isl_local_space *ls, __isl_take isl_reordering *r)
{
ls = isl_local_space_cow(ls);
if (!ls || !r)
goto error;
isl_local *local;

ls->div = isl_local_reorder(ls->div, isl_reordering_copy(r));
if (!ls->div)
goto error;
local = isl_local_space_take_local(ls);
local = isl_local_reorder(local, isl_reordering_copy(r));
ls = isl_local_space_restore_local(ls, local);

ls = isl_local_space_reset_space(ls, isl_reordering_get_space(r));

isl_reordering_free(r);
return ls;
error:
isl_local_space_free(ls);
isl_reordering_free(r);
return NULL;
}

__isl_give isl_local_space *isl_local_space_add_div(
Expand Down Expand Up @@ -1557,6 +1633,9 @@ __isl_give isl_local_space *isl_local_space_move_dims(
enum isl_dim_type dst_type, unsigned dst_pos,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
isl_space *space;
isl_local *local;
isl_size v_src, v_dst;
unsigned g_dst_pos;
unsigned g_src_pos;

Expand Down Expand Up @@ -1584,21 +1663,23 @@ __isl_give isl_local_space *isl_local_space_move_dims(
"moving dims within the same type not supported",
return isl_local_space_free(ls));

ls = isl_local_space_cow(ls);
if (!ls)
return NULL;

g_src_pos = 1 + isl_local_space_offset(ls, src_type) + src_pos;
g_dst_pos = 1 + isl_local_space_offset(ls, dst_type) + dst_pos;
v_src = isl_local_space_var_offset(ls, src_type);
v_dst = isl_local_space_var_offset(ls, dst_type);
if (v_src < 0 || v_dst < 0)
return isl_local_space_free(ls);
g_src_pos = v_src + src_pos;
g_dst_pos = v_dst + dst_pos;
if (dst_type > src_type)
g_dst_pos -= n;
ls->div = isl_mat_move_cols(ls->div, g_dst_pos, g_src_pos, n);
if (!ls->div)
return isl_local_space_free(ls);
ls->dim = isl_space_move_dims(ls->dim, dst_type, dst_pos,

local = isl_local_space_take_local(ls);
local = isl_local_move_vars(local, g_dst_pos, g_src_pos, n);
ls = isl_local_space_restore_local(ls, local);

space = isl_local_space_take_space(ls);
space = isl_space_move_dims(space, dst_type, dst_pos,
src_type, src_pos, n);
if (!ls->dim)
return isl_local_space_free(ls);
ls = isl_local_space_restore_space(ls, space);

return ls;
}
Expand Down
2 changes: 2 additions & 0 deletions polly/lib/External/isl/isl_local_space_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ int isl_mat_cmp_div(__isl_keep isl_mat *div, int i, int j);
__isl_give isl_mat *isl_merge_divs(__isl_keep isl_mat *div1,
__isl_keep isl_mat *div2, int *exp1, int *exp2);

isl_size isl_local_space_var_offset(__isl_keep isl_local_space *ls,
enum isl_dim_type type);
unsigned isl_local_space_offset(__isl_keep isl_local_space *ls,
enum isl_dim_type type);

Expand Down
2 changes: 1 addition & 1 deletion polly/lib/External/isl/isl_lp.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <bset_to_bmap.c>
#include <set_to_map.c>

enum isl_lp_result isl_tab_solve_lp(__isl_keep isl_basic_map *bmap,
static enum isl_lp_result isl_tab_solve_lp(__isl_keep isl_basic_map *bmap,
int maximize, isl_int *f, isl_int denom, isl_int *opt,
isl_int *opt_denom, __isl_give isl_vec **sol)
{
Expand Down
111 changes: 66 additions & 45 deletions polly/lib/External/isl/isl_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -1464,14 +1464,7 @@ __isl_give isl_basic_set *isl_basic_set_dup(__isl_keep isl_basic_set *bset)

__isl_give isl_basic_set *isl_basic_set_copy(__isl_keep isl_basic_set *bset)
{
if (!bset)
return NULL;

if (ISL_F_ISSET(bset, ISL_BASIC_SET_FINAL)) {
bset->ref++;
return bset;
}
return isl_basic_set_dup(bset);
return bset_from_bmap(isl_basic_map_copy(bset_to_bmap(bset)));
}

__isl_give isl_set *isl_set_copy(__isl_keep isl_set *set)
Expand Down Expand Up @@ -4622,6 +4615,7 @@ __isl_give isl_map *isl_map_project_out(__isl_take isl_map *map,
#undef TYPE
#define TYPE isl_map
#include "isl_project_out_all_params_templ.c"
#include "isl_project_out_param_templ.c"

/* Turn all the dimensions of type "type", except the "n" starting at "first"
* into existentially quantified variables.
Expand Down Expand Up @@ -4655,19 +4649,7 @@ __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set,
__isl_give isl_set *isl_set_project_out_param_id(__isl_take isl_set *set,
__isl_take isl_id *id)
{
int pos;

if (!set || !id)
goto error;
pos = isl_set_find_dim_by_id(set, isl_dim_param, id);
isl_id_free(id);
if (pos < 0)
return set;
return isl_set_project_out(set, isl_dim_param, pos, 1);
error:
isl_set_free(set);
isl_id_free(id);
return NULL;
return set_from_map(isl_map_project_out_param_id(set_to_map(set), id));
}

/* If "set" involves any of the parameters with identifiers in "list",
Expand All @@ -4676,25 +4658,11 @@ __isl_give isl_set *isl_set_project_out_param_id(__isl_take isl_set *set,
__isl_give isl_set *isl_set_project_out_param_id_list(__isl_take isl_set *set,
__isl_take isl_id_list *list)
{
int i;
isl_size n;

n = isl_id_list_size(list);
if (n < 0)
goto error;
for (i = 0; i < n; ++i) {
isl_id *id;

id = isl_id_list_get_at(list, i);
set = isl_set_project_out_param_id(set, id);
}
isl_map *map;

isl_id_list_free(list);
return set;
error:
isl_id_list_free(list);
isl_set_free(set);
return NULL;
map = set_to_map(set);
map = isl_map_project_out_param_id_list(map, list);
return set_from_map(map);
}

/* Project out all parameters from "set" by existentially quantifying
Expand Down Expand Up @@ -8587,6 +8555,46 @@ __isl_give isl_set *isl_set_intersect_factor_range(__isl_take isl_set *set,
set_to_map(range), &control));
}

/* Given a map "map" in a space [A -> B] -> C and a set "domain"
* in the space A, return the intersection.
*
* The set "domain" is extended to a set living in the space [A -> B] and
* the domain of "map" is intersected with this set.
*/
__isl_give isl_map *isl_map_intersect_domain_wrapped_domain(
__isl_take isl_map *map, __isl_take isl_set *domain)
{
isl_space *space;
isl_set *factor;

isl_map_align_params_set(&map, &domain);
space = isl_map_get_space(map);
space = isl_space_domain_wrapped_range(space);
factor = isl_set_universe(space);
domain = isl_set_product(domain, factor);
return isl_map_intersect_domain(map, domain);
}

/* Given a map "map" in a space A -> [B -> C] and a set "domain"
* in the space B, return the intersection.
*
* The set "domain" is extended to a set living in the space [B -> C] and
* the range of "map" is intersected with this set.
*/
__isl_give isl_map *isl_map_intersect_range_wrapped_domain(
__isl_take isl_map *map, __isl_take isl_set *domain)
{
isl_space *space;
isl_set *factor;

isl_map_align_params_set(&map, &domain);
space = isl_map_get_space(map);
space = isl_space_range_wrapped_range(space);
factor = isl_set_universe(space);
domain = isl_set_product(domain, factor);
return isl_map_intersect_range(map, domain);
}

__isl_give isl_map *isl_map_apply_domain(__isl_take isl_map *map1,
__isl_take isl_map *map2)
{
Expand Down Expand Up @@ -10361,6 +10369,18 @@ int isl_basic_map_plain_cmp(__isl_keep isl_basic_map *bmap1,
return cmp;
}
for (i = 0; i < bmap1->n_div; ++i) {
isl_bool unknown1, unknown2;

unknown1 = isl_basic_map_div_is_marked_unknown(bmap1, i);
unknown2 = isl_basic_map_div_is_marked_unknown(bmap2, i);
if (unknown1 < 0 || unknown2 < 0)
return -1;
if (unknown1 && unknown2)
continue;
if (unknown1)
return 1;
if (unknown2)
return -1;
cmp = isl_seq_cmp(bmap1->div[i], bmap2->div[i], 1+1+total);
if (cmp)
return cmp;
Expand Down Expand Up @@ -12469,10 +12489,11 @@ __isl_give isl_map *isl_map_align_params(__isl_take isl_map *map,
if (aligned < 0)
goto error;
if (!aligned) {
isl_space *space;
isl_reordering *exp;

exp = isl_parameter_alignment_reordering(map->dim, model);
exp = isl_reordering_extend_space(exp, isl_map_get_space(map));
space = isl_map_peek_space(map);
exp = isl_parameter_alignment_reordering(space, model);
map = isl_map_realign(map, exp);
}

Expand All @@ -12498,6 +12519,7 @@ __isl_give isl_basic_map *isl_basic_map_align_params(
{
isl_ctx *ctx;
isl_bool equal_params;
isl_space *bmap_space;

if (!bmap || !model)
goto error;
Expand All @@ -12508,16 +12530,15 @@ __isl_give isl_basic_map *isl_basic_map_align_params(
"model has unnamed parameters", goto error);
if (isl_basic_map_check_named_params(bmap) < 0)
goto error;
equal_params = isl_space_has_equal_params(bmap->dim, model);
bmap_space = isl_basic_map_peek_space(bmap);
equal_params = isl_space_has_equal_params(bmap_space, model);
if (equal_params < 0)
goto error;
if (!equal_params) {
isl_reordering *exp;
struct isl_dim_map *dim_map;

exp = isl_parameter_alignment_reordering(bmap->dim, model);
exp = isl_reordering_extend_space(exp,
isl_basic_map_get_space(bmap));
exp = isl_parameter_alignment_reordering(bmap_space, model);
dim_map = isl_dim_map_from_reordering(exp);
bmap = isl_basic_map_realign(bmap,
isl_reordering_get_space(exp),
Expand Down
2 changes: 1 addition & 1 deletion polly/lib/External/isl/isl_map_simplify.c
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,7 @@ static isl_bool better_div_constraint(__isl_keep isl_basic_map *bmap,
* a "better" expression for a div for which we already have an expression.
* "sum" is the sum of the constant terms of the constraints.
* If this sum is strictly smaller than the coefficient of one
* of the divs, then this pair can be used define the div.
* of the divs, then this pair can be used to define the div.
* To avoid the introduction of circular definitions of divs, we
* do not use the pair if the resulting expression would refer to
* any other undefined divs or if any known div is defined in
Expand Down
4 changes: 2 additions & 2 deletions polly/lib/External/isl/isl_map_subtract.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ static int tab_freeze_constraints(struct isl_tab *tab)
}

/* Check for redundant constraints starting at offset.
* Put the indices of the redundant constraints in index
* and return the number of redundant constraints.
* Put the indices of the non-redundant constraints in index
* and return the number of non-redundant constraints.
*/
static int n_non_redundant(isl_ctx *ctx, struct isl_tab *tab,
int offset, int **index)
Expand Down
4 changes: 4 additions & 0 deletions polly/lib/External/isl/isl_map_to_basic_set.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
#define ISL_VAL isl_basic_set
#define ISL_HMAP_SUFFIX map_to_basic_set
#define ISL_HMAP isl_map_to_basic_set
#define ISL_HMAP_IS_EQUAL isl_map_to_basic_set_plain_is_equal
#define ISL_KEY_IS_EQUAL isl_map_plain_is_equal
#define ISL_VAL_IS_EQUAL isl_basic_set_plain_is_equal
#define ISL_KEY_PRINT isl_printer_print_map
#define ISL_VAL_PRINT isl_printer_print_basic_set
#define ISL_HMAP_HAVE_READ_FROM_STR
#define ISL_KEY_READ isl_stream_read_map
#define ISL_VAL_READ isl_stream_read_basic_set

#include <isl/hmap_templ.c>
52 changes: 8 additions & 44 deletions polly/lib/External/isl/isl_multi_add_constant_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,16 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_val *v)
{
isl_bool zero;
isl_size n;
int i;

zero = isl_val_is_zero(v);
n = FN(MULTI(BASE),size)(multi);
if (zero < 0 || n < 0)
if (zero < 0)
goto error;
if (zero || n == 0) {
if (zero) {
isl_val_free(v);
return multi;
}

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;

for (i = 0; i < n; ++i) {
multi->u.p[i] = FN(EL,add_constant_val)(multi->u.p[i],
isl_val_copy(v));
if (!multi->u.p[i])
goto error;
}

isl_val_free(v);
return multi;
return FN(MULTI(BASE),fn_val)(multi, &FN(EL,add_constant_val), v);
error:
FN(MULTI(BASE),free)(multi);
isl_val_free(v);
Expand All @@ -52,40 +37,19 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_val)(
__isl_give MULTI(BASE) *FN(MULTI(BASE),add_constant_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
isl_space *multi_space, *mv_space;
isl_bool zero, equal;
isl_size n;
int i;
isl_bool zero;

zero = isl_multi_val_is_zero(mv);
n = FN(MULTI(BASE),size)(multi);
multi_space = FN(MULTI(BASE),peek_space)(multi);
mv_space = isl_multi_val_peek_space(mv);
equal = isl_space_tuple_is_equal(multi_space, isl_dim_out,
mv_space, isl_dim_out);
if (zero < 0 || n < 0 || equal < 0)
if (zero < 0)
goto error;
if (!equal)
isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
"spaces don't match", goto error);
if (zero || n == 0) {
if (zero) {
isl_multi_val_free(mv);
return multi;
}

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;
return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,add_constant_val),
mv);

for (i = 0; i < n; ++i) {
isl_val *v = isl_multi_val_get_at(mv, i);
multi->u.p[i] = FN(EL,add_constant_val)(multi->u.p[i], v);
if (!multi->u.p[i])
goto error;
}

isl_multi_val_free(mv);
return multi;
error:
FN(MULTI(BASE),free)(multi);
isl_multi_val_free(mv);
Expand Down
21 changes: 8 additions & 13 deletions polly/lib/External/isl/isl_multi_apply_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,19 @@ __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply_aligned),APPLY_DOMBASE)(
__isl_take MULTI(BASE) *multi, __isl_take APPLY_DOM *set,
__isl_give EL *(*fn)(EL *el, __isl_take APPLY_DOM *set))
{
isl_size n;
int i;

if (!multi || !set)
n = FN(MULTI(BASE),size)(multi);
if (n < 0 || !set)
goto error;

if (multi->n == 0) {
FN(APPLY_DOM,free)(set);
return multi;
}

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;
for (i = 0; i < n; ++i) {
EL *el;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = fn(multi->u.p[i], FN(APPLY_DOM,copy)(set));
if (!multi->u.p[i])
goto error;
el = FN(MULTI(BASE),take_at)(multi, i);
el = fn(el, FN(APPLY_DOM,copy)(set));
multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

FN(APPLY_DOM,free)(set);
Expand Down
161 changes: 20 additions & 141 deletions polly/lib/External/isl/isl_multi_arith_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),sub)(__isl_take MULTI(BASE) *multi1,
return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,sub));
}

/* Multiply the elements of "multi" by "v" and return the result.
/* Depending on "fn", multiply or divide the elements of "multi" by "v" and
* return the result.
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
__isl_take isl_val *v)
static __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val_fn)(
__isl_take MULTI(BASE) *multi, __isl_take isl_val *v,
__isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v))
{
int i;

if (!multi || !v)
goto error;

Expand All @@ -48,59 +48,31 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
isl_die(isl_val_get_ctx(v), isl_error_invalid,
"expecting rational factor", goto error);

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,scale_val)(multi->u.p[i],
isl_val_copy(v));
if (!multi->u.p[i])
goto error;
}

isl_val_free(v);
return multi;
return FN(MULTI(BASE),fn_val)(multi, fn, v);
error:
isl_val_free(v);
return FN(MULTI(BASE),free)(multi);
}

/* Multiply the elements of "multi" by "v" and return the result.
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi,
__isl_take isl_val *v)
{
return FN(MULTI(BASE),scale_val_fn)(multi, v, &FN(EL,scale_val));
}

/* Divide the elements of "multi" by "v" and return the result.
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_val *v)
{
int i;

if (!multi || !v)
if (!v)
goto error;

if (isl_val_is_one(v)) {
isl_val_free(v);
return multi;
}

if (!isl_val_is_rat(v))
isl_die(isl_val_get_ctx(v), isl_error_invalid,
"expecting rational factor", goto error);
if (isl_val_is_zero(v))
isl_die(isl_val_get_ctx(v), isl_error_invalid,
"cannot scale down by zero", goto error);

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,scale_down_val)(multi->u.p[i],
isl_val_copy(v));
if (!multi->u.p[i])
goto error;
}

isl_val_free(v);
return multi;
return FN(MULTI(BASE),scale_val_fn)(multi, v, &FN(EL,scale_down_val));
error:
isl_val_free(v);
return FN(MULTI(BASE),free)(multi);
Expand All @@ -112,34 +84,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_val)(
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
int i;

if (!multi || !mv)
goto error;

if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
mv->space, isl_dim_set))
isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
"spaces don't match", goto error);

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;

for (i = 0; i < multi->n; ++i) {
isl_val *v;

v = isl_multi_val_get_val(mv, i);
multi->u.p[i] = FN(EL,scale_val)(multi->u.p[i], v);
if (!multi->u.p[i])
goto error;
}

isl_multi_val_free(mv);
return multi;
error:
isl_multi_val_free(mv);
return FN(MULTI(BASE),free)(multi);
return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,scale_val), mv);
}

/* Divide the elements of "multi" by the corresponding element of "mv"
Expand All @@ -148,34 +93,7 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)(
__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
int i;

if (!multi || !mv)
goto error;

if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
mv->space, isl_dim_set))
isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
"spaces don't match", goto error);

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
isl_val *v;

v = isl_multi_val_get_val(mv, i);
multi->u.p[i] = FN(EL,scale_down_val)(multi->u.p[i], v);
if (!multi->u.p[i])
goto error;
}

isl_multi_val_free(mv);
return multi;
error:
isl_multi_val_free(mv);
return FN(MULTI(BASE),free)(multi);
return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,scale_down_val), mv);
}

/* Compute the residues of the elements of "multi" modulo
Expand All @@ -184,51 +102,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)(
__isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)(
__isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv)
{
int i;

if (!multi || !mv)
goto error;

if (!isl_space_tuple_is_equal(multi->space, isl_dim_out,
mv->space, isl_dim_set))
isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid,
"spaces don't match", goto error);

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
goto error;

for (i = 0; i < multi->n; ++i) {
isl_val *v;

v = isl_multi_val_get_val(mv, i);
multi->u.p[i] = FN(EL,mod_val)(multi->u.p[i], v);
if (!multi->u.p[i])
goto error;
}

isl_multi_val_free(mv);
return multi;
error:
isl_multi_val_free(mv);
return FN(MULTI(BASE),free)(multi);
return FN(MULTI(BASE),fn_multi_val)(multi, &FN(EL,mod_val), mv);
}

/* Return the opposite of "multi".
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),neg)(__isl_take MULTI(BASE) *multi)
{
int i;

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,neg)(multi->u.p[i]);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
}

return multi;
return FN(MULTI(BASE),un_op)(multi, &FN(EL,neg));
}
73 changes: 73 additions & 0 deletions polly/lib/External/isl/isl_multi_bin_val_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2013 Ecole Normale Superieure
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
*/

/* Apply "fn" to each of the elements of "multi" with as second argument "v".
*/
static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_val)(
__isl_take MULTI(BASE) *multi,
__isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v),
__isl_take isl_val *v)
{
isl_size n;
int i;

n = FN(MULTI(BASE),size)(multi);
if (n < 0 || !v)
goto error;

for (i = 0; i < n; ++i) {
EL *el;

el = FN(MULTI(BASE),take_at)(multi, i);
el = fn(el, isl_val_copy(v));
multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

isl_val_free(v);
return multi;
error:
isl_val_free(v);
FN(MULTI(BASE),free)(multi);
return NULL;
}

#undef TYPE
#define TYPE MULTI(BASE)
#include "isl_type_check_match_range_multi_val.c"

/* Elementwise apply "fn" to "multi" and "mv".
*/
static __isl_give MULTI(BASE) *FN(MULTI(BASE),fn_multi_val)(
__isl_take MULTI(BASE) *multi,
__isl_give EL *(*fn)(__isl_take EL *el, __isl_take isl_val *v),
__isl_take isl_multi_val *mv)
{
isl_size n;
int i;

n = FN(MULTI(BASE),size)(multi);
if (n < 0 || FN(MULTI(BASE),check_match_range_multi_val)(multi, mv) < 0)
goto error;

for (i = 0; i < n; ++i) {
isl_val *v;
EL *el;

v = isl_multi_val_get_val(mv, i);
el = FN(MULTI(BASE),take_at)(multi, i);
el = fn(el, v);
multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

isl_multi_val_free(mv);
return multi;
error:
isl_multi_val_free(mv);
return FN(MULTI(BASE),free)(multi);
}
30 changes: 4 additions & 26 deletions polly/lib/External/isl/isl_multi_dim_id_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,12 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned pos, const char *s)
{
int i;

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

multi->space = isl_space_set_dim_name(multi->space, type, pos, s);
if (!multi->space)
return FN(MULTI(BASE),free)(multi);
isl_space *space;

if (type == isl_dim_out)
return multi;
for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,set_dim_name)(multi->u.p[i],
type, pos, s);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
}
space = FN(MULTI(BASE),get_space)(multi);
space = isl_space_set_dim_name(space, type, pos, s);

return multi;
return FN(MULTI(BASE),reset_space)(multi, space);
}

/* Set the id of the given dimension of "multi" to "id".
Expand All @@ -77,16 +63,8 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_id)(
{
isl_space *space;

multi = FN(MULTI(BASE),cow)(multi);
if (!multi || !id)
goto error;

space = FN(MULTI(BASE),get_space)(multi);
space = isl_space_set_dim_id(space, type, pos, id);

return FN(MULTI(BASE),reset_space)(multi, space);
error:
isl_id_free(id);
FN(MULTI(BASE),free)(multi);
return NULL;
}
29 changes: 14 additions & 15 deletions polly/lib/External/isl/isl_multi_dims.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,34 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),insert_dims)(
__isl_take MULTI(BASE) *multi,
enum isl_dim_type type, unsigned first, unsigned n)
{
isl_space *space;
isl_size size;
int i;

if (!multi)
return NULL;
size = FN(MULTI(BASE),size)(multi);
if (size < 0)
return FN(MULTI(BASE),free)(multi);
if (type == isl_dim_out)
isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid,
"cannot insert output/set dimensions",
return FN(MULTI(BASE),free)(multi));
if (n == 0 && !isl_space_is_named_or_nested(multi->space, type))
return multi;

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;
space = FN(MULTI(BASE),take_space)(multi);
space = isl_space_insert_dims(space, type, first, n);
multi = FN(MULTI(BASE),restore_space)(multi, space);

multi->space = isl_space_insert_dims(multi->space, type, first, n);
if (!multi->space)
return FN(MULTI(BASE),free)(multi);
if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),insert_explicit_domain_dims)(multi,
type, first, n);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,insert_dims)(multi->u.p[i],
type, first, n);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
for (i = 0; i < size; ++i) {
EL *el;

el = FN(MULTI(BASE),take_at)(multi, i);
el = FN(EL,insert_dims)(el, type, first, n);
multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
Expand Down
14 changes: 1 addition & 13 deletions polly/lib/External/isl/isl_multi_floor.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,5 @@
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),floor)(__isl_take MULTI(BASE) *multi)
{
int i;

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,floor)(multi->u.p[i]);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
}

return multi;
return FN(MULTI(BASE),un_op)(multi, &FN(EL,floor));
}
46 changes: 46 additions & 0 deletions polly/lib/External/isl/isl_multi_from_tuple_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2011 Sven Verdoolaege
* Copyright 2012 Ecole Normale Superieure
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
*/

#include <isl_multi_macro.h>

/* Extract a multi expression with domain space "dom_space"
* from a tuple "tuple" that was read by read_tuple.
*
* Check that none of the expressions depend on any other output/set dimensions.
*/
static MULTI(BASE) *FN(MULTI(BASE),from_tuple)(
__isl_take isl_space *dom_space, __isl_take isl_multi_pw_aff *tuple)
{
int i;
isl_size dim, n;
isl_space *space;
MULTI(BASE) *multi;

n = isl_multi_pw_aff_dim(tuple, isl_dim_out);
dim = isl_space_dim(dom_space, isl_dim_all);
if (n < 0 || dim < 0)
dom_space = isl_space_free(dom_space);
space = isl_space_range(isl_multi_pw_aff_get_space(tuple));
space = isl_space_align_params(space, isl_space_copy(dom_space));
if (!isl_space_is_params(dom_space))
space = isl_space_map_from_domain_and_range(
isl_space_copy(dom_space), space);
isl_space_free(dom_space);
multi = FN(MULTI(BASE),alloc)(space);

for (i = 0; i < n; ++i) {
isl_pw_aff *pa;
pa = isl_multi_pw_aff_get_pw_aff(tuple, i);
multi = FN(MULTI(BASE),set_tuple_entry)(multi, pa, i, dim, n);
}

isl_multi_pw_aff_free(tuple);
return multi;
}
31 changes: 15 additions & 16 deletions polly/lib/External/isl/isl_multi_move_dims_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
enum isl_dim_type dst_type, unsigned dst_pos,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
isl_space *space;
isl_size size;
int i;

if (!multi)
return NULL;
size = FN(MULTI(BASE),size)(multi);
if (size < 0)
return FN(MULTI(BASE),free)(multi);

if (n == 0 &&
!isl_space_is_named_or_nested(multi->space, src_type) &&
Expand All @@ -45,26 +48,22 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi,
"moving dims within the same type not supported",
return FN(MULTI(BASE),free)(multi));

multi = FN(MULTI(BASE),cow)(multi);
if (!multi)
return NULL;

multi->space = isl_space_move_dims(multi->space, dst_type, dst_pos,
space = FN(MULTI(BASE),take_space)(multi);
space = isl_space_move_dims(space, dst_type, dst_pos,
src_type, src_pos, n);
if (!multi->space)
return FN(MULTI(BASE),free)(multi);
multi = FN(MULTI(BASE),restore_space)(multi, space);

if (FN(MULTI(BASE),has_explicit_domain)(multi))
multi = FN(MULTI(BASE),move_explicit_domain_dims)(multi,
dst_type, dst_pos, src_type, src_pos, n);
if (!multi)
return NULL;

for (i = 0; i < multi->n; ++i) {
multi->u.p[i] = FN(EL,move_dims)(multi->u.p[i],
dst_type, dst_pos,
for (i = 0; i < size; ++i) {
EL *el;

el = FN(MULTI(BASE),take_at)(multi, i);
el = FN(EL,move_dims)(el, dst_type, dst_pos,
src_type, src_pos, n);
if (!multi->u.p[i])
return FN(MULTI(BASE),free)(multi);
multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
Expand Down
73 changes: 73 additions & 0 deletions polly/lib/External/isl/isl_multi_pw_aff_pullback_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2013 Ecole Normale Superieure
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
*/

#define xCAT(A,B) A ## B
#define CAT(A,B) xCAT(A,B)
#undef TYPE
#define TYPE CAT(isl_,BASE)
#define xFN(TYPE,NAME) TYPE ## _ ## NAME
#define FN(TYPE,NAME) xFN(TYPE,NAME)

#undef SUFFIX
#define SUFFIX BASE
#undef ARG1
#define ARG1 isl_multi_pw_aff
#undef ARG2
#define ARG2 TYPE

static
#include "isl_align_params_templ.c"

/* Compute the pullback of "mpa" by the function represented by "fn".
* In other words, plug in "fn" in "mpa".
*
* If "mpa" has an explicit domain, then it is this domain
* that needs to undergo a pullback, i.e., a preimage.
*/
__isl_give isl_multi_pw_aff *FN(isl_multi_pw_aff_pullback,BASE)(
__isl_take isl_multi_pw_aff *mpa, __isl_take TYPE *fn)
{
int i;
isl_size n;
isl_space *space = NULL;

FN(isl_multi_pw_aff_align_params,BASE)(&mpa, &fn);
mpa = isl_multi_pw_aff_cow(mpa);
n = isl_multi_pw_aff_size(mpa);
if (n < 0 || !fn)
goto error;

space = isl_space_join(FN(TYPE,get_space)(fn),
isl_multi_pw_aff_get_space(mpa));

for (i = 0; i < n; ++i) {
isl_pw_aff *pa;

pa = isl_multi_pw_aff_take_at(mpa, i);
pa = FN(isl_pw_aff_pullback,BASE)(pa, FN(TYPE,copy)(fn));
mpa = isl_multi_pw_aff_restore_at(mpa, i, pa);
if (!mpa)
goto error;
}
if (isl_multi_pw_aff_has_explicit_domain(mpa)) {
mpa->u.dom = FN(isl_set_preimage,BASE)(mpa->u.dom,
FN(TYPE,copy)(fn));
if (!mpa->u.dom)
goto error;
}

FN(TYPE,free)(fn);
isl_multi_pw_aff_restore_space(mpa, space);
return mpa;
error:
isl_space_free(space);
isl_multi_pw_aff_free(mpa);
FN(TYPE,free)(fn);
return NULL;
}
16 changes: 3 additions & 13 deletions polly/lib/External/isl/isl_multi_read_no_explicit_domain_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ __isl_give MULTI(BASE) *FN(isl_stream_read_multi,BASE)(
return NULL;
}

/* Read a multi expression from "str".
*/
__isl_give MULTI(BASE) *FN(MULTI(BASE),read_from_str)(isl_ctx *ctx,
const char *str)
{
MULTI(BASE) *multi;
isl_stream *s = isl_stream_new_str(ctx, str);
if (!s)
return NULL;
multi = FN(isl_stream_read_multi,BASE)(s);
isl_stream_free(s);
return multi;
}
#undef TYPE_BASE
#define TYPE_BASE CAT(multi_,BASE)
#include "isl_read_from_str_templ.c"
278 changes: 181 additions & 97 deletions polly/lib/External/isl/isl_multi_templ.c

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions polly/lib/External/isl/isl_multi_un_op_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2014 Ecole Normale Superieure
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
*/

#include <isl_multi_macro.h>

/* Apply "fn" to each of the base expressions of "multi".
*/
static __isl_give MULTI(BASE) *FN(MULTI(BASE),un_op)(
__isl_take MULTI(BASE) *multi, __isl_give EL *(*fn)(__isl_take EL *el))
{
int i;
isl_size n;

n = FN(MULTI(BASE),size)(multi);
if (n < 0)
return FN(MULTI(BASE),free)(multi);

for (i = 0; i < n; ++i) {
EL *el;

el = FN(MULTI(BASE),take_at)(multi, i);
el = fn(el);
multi = FN(MULTI(BASE),restore_at)(multi, i, el);
}

return multi;
}
345 changes: 36 additions & 309 deletions polly/lib/External/isl/isl_output.c

Large diffs are not rendered by default.

62 changes: 61 additions & 1 deletion polly/lib/External/isl/isl_point.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright 2010 INRIA Saclay
* Copyright 2013 Ecole Normale Superieure
* Copyright 2015 Sven Verdoolaege
* Copyright 2019 Cerebras Systems
* Copyright 2019,2022 Cerebras Systems
*
* Use of this software is governed by the MIT license
*
Expand All @@ -11,6 +11,7 @@
* 91893 Orsay, France
* and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
* and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
* and Cerebras Systems, 1237 E Arques Ave, Sunnyvale, CA, USA
*/

#include <isl_map_private.h>
Expand Down Expand Up @@ -57,6 +58,11 @@ static
static
#include "isl_type_check_equal_space_templ.c"

#undef TYPE
#define TYPE isl_point

#include "isl_check_named_params_templ.c"

__isl_give isl_point *isl_point_alloc(__isl_take isl_space *space,
__isl_take isl_vec *vec)
{
Expand Down Expand Up @@ -304,6 +310,60 @@ static isl_size isl_point_var_offset(__isl_keep isl_point *pnt,
return pnt ? isl_space_offset(pnt->dim, type) : isl_size_error;
}

/* Reorder the coordinates of "pnt" based on the given reordering.
*/
static __isl_give isl_point *isl_point_reorder(__isl_take isl_point *pnt,
__isl_take isl_reordering *r)
{
isl_vec *vec;

isl_space_free(isl_point_take_space(pnt));
pnt = isl_point_restore_space(pnt, isl_reordering_get_space(r));

vec = isl_point_take_vec(pnt);
vec = isl_vec_reorder(vec, 1, isl_reordering_copy(r));
pnt = isl_point_restore_vec(pnt, vec);

return pnt;
}

/* Align the parameters of "pnt" along those of "model".
*
* Note that "model" is not allowed to have any parameters
* that do not already appear in "pnt" since "pnt" does not specify
* any value for such parameters.
*/
__isl_give isl_point *isl_point_align_params(__isl_take isl_point *pnt,
__isl_take isl_space *model)
{
isl_space *space;
isl_bool equal_params;

space = isl_point_peek_space(pnt);
equal_params = isl_space_has_equal_params(space, model);
if (equal_params < 0)
goto error;
if (!equal_params) {
isl_reordering *r;

r = isl_parameter_alignment_reordering(space, model);
if (!r)
goto error;
if (r->src_len != r->dst_len)
isl_die(isl_point_get_ctx(pnt), isl_error_invalid,
"no value specified for some parameters",
r = isl_reordering_free(r));
pnt = isl_point_reorder(pnt, r);
}

isl_space_free(model);
return pnt;
error:
isl_space_free(model);
isl_point_free(pnt);
return NULL;
}

#undef TYPE
#define TYPE isl_point
static
Expand Down
4 changes: 4 additions & 0 deletions polly/lib/External/isl/isl_point_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ __isl_give isl_vec *isl_point_take_vec(__isl_keep isl_point *pnt);
__isl_give isl_point *isl_point_restore_vec(__isl_take isl_point *pnt,
__isl_take isl_vec *vec);

isl_stat isl_point_check_named_params(__isl_keep isl_point *pnt);
__isl_give isl_point *isl_point_align_params(__isl_take isl_point *pnt,
__isl_take isl_space *model);

#endif
17 changes: 10 additions & 7 deletions polly/lib/External/isl/isl_polynomial.c
Original file line number Diff line number Diff line change
Expand Up @@ -3108,13 +3108,18 @@ static __isl_give isl_qpolynomial *isl_qpolynomial_zero_in_space(
#define DEFAULT_IS_ZERO 1

#include <isl_pw_templ.c>
#include <isl_pw_un_op_templ.c>
#include <isl_pw_add_disjoint_templ.c>
#include <isl_pw_eval.c>
#include <isl_pw_fix_templ.c>
#include <isl_pw_from_range_templ.c>
#include <isl_pw_insert_dims_templ.c>
#include <isl_pw_lift_templ.c>
#include <isl_pw_morph_templ.c>
#include <isl_pw_move_dims_templ.c>
#include <isl_pw_neg_templ.c>
#include <isl_pw_opt_templ.c>
#include <isl_pw_split_dims_templ.c>
#include <isl_pw_sub_templ.c>

#undef BASE
Expand All @@ -3123,6 +3128,7 @@ static __isl_give isl_qpolynomial *isl_qpolynomial_zero_in_space(
#include <isl_union_single.c>
#include <isl_union_eval.c>
#include <isl_union_neg.c>
#include <isl_union_sub_templ.c>

int isl_pw_qpolynomial_is_one(__isl_keep isl_pw_qpolynomial *pwqp)
{
Expand Down Expand Up @@ -4486,20 +4492,17 @@ __isl_give isl_qpolynomial *isl_qpolynomial_realign_domain(
__isl_give isl_qpolynomial *isl_qpolynomial_align_params(
__isl_take isl_qpolynomial *qp, __isl_take isl_space *model)
{
isl_space *domain_space;
isl_bool equal_params;

if (!qp || !model)
goto error;

equal_params = isl_space_has_equal_params(qp->dim, model);
domain_space = isl_qpolynomial_peek_domain_space(qp);
equal_params = isl_space_has_equal_params(domain_space, model);
if (equal_params < 0)
goto error;
if (!equal_params) {
isl_reordering *exp;

exp = isl_parameter_alignment_reordering(qp->dim, model);
exp = isl_reordering_extend_space(exp,
isl_qpolynomial_get_domain_space(qp));
exp = isl_parameter_alignment_reordering(domain_space, model);
qp = isl_qpolynomial_realign_domain(qp, exp);
}

Expand Down
19 changes: 6 additions & 13 deletions polly/lib/External/isl/isl_polynomial_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ __isl_give isl_qpolynomial *isl_qpolynomial_from_affine(
__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_cow(
__isl_take isl_pw_qpolynomial *pwqp);

__isl_keep isl_qpolynomial *isl_pw_qpolynomial_peek_base_at(
__isl_keep isl_pw_qpolynomial *pwqp, int pos);

__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add_piece(
__isl_take isl_pw_qpolynomial *pwqp,
__isl_take isl_set *set, __isl_take isl_qpolynomial *qp);
Expand All @@ -211,6 +214,9 @@ __isl_keep isl_qpolynomial_list *isl_qpolynomial_fold_peek_list(
__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_cow(
__isl_take isl_pw_qpolynomial_fold *pwf);

__isl_keep isl_qpolynomial_fold *isl_pw_qpolynomial_fold_peek_base_at(
__isl_keep isl_pw_qpolynomial_fold *pwf, int pos);

__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_add_on_domain(
__isl_keep isl_set *set,
__isl_take isl_qpolynomial_fold *fold1,
Expand Down Expand Up @@ -255,10 +261,6 @@ __isl_give isl_qpolynomial *isl_qpolynomial_realign_domain(
__isl_take isl_qpolynomial *qp, __isl_take isl_reordering *r);
__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_realign_domain(
__isl_take isl_qpolynomial_fold *fold, __isl_take isl_reordering *r);
__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_realign_domain(
__isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_reordering *r);
__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_realign_domain(
__isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_reordering *r);

__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_reset_space(
__isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_space *space);
Expand All @@ -280,20 +282,11 @@ __isl_give isl_qpolynomial *isl_qpolynomial_add_isl_int(
__isl_take isl_qpolynomial *qp, isl_int v);
__isl_give isl_qpolynomial *isl_qpolynomial_mul_isl_int(
__isl_take isl_qpolynomial *qp, isl_int v);
__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul_isl_int(
__isl_take isl_pw_qpolynomial *pwqp, isl_int v);

__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_scale(
__isl_take isl_qpolynomial_fold *fold, isl_int v);

__isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_mul_isl_int(
__isl_take isl_qpolynomial_fold *fold, isl_int v);
__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_mul_isl_int(
__isl_take isl_pw_qpolynomial_fold *pwf, isl_int v);
__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_mul_isl_int(
__isl_take isl_union_pw_qpolynomial *upwqp, isl_int v);
__isl_give isl_union_pw_qpolynomial_fold *
isl_union_pw_qpolynomial_fold_mul_isl_int(
__isl_take isl_union_pw_qpolynomial_fold *upwf, isl_int v);

ISL_DECLARE_LIST_FN_PRIVATE(qpolynomial)
31 changes: 24 additions & 7 deletions polly/lib/External/isl/isl_power_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
#define xFN(TYPE,NAME) TYPE ## _ ## NAME
#define FN(TYPE,NAME) xFN(TYPE,NAME)

/* Helper function for isl_*_fixed_power that applies (a copy of) "map2"
* to the range of "map1" and returns the result.
*
* The result is coalesced in an attempt to reduce the number of disjuncts
* that result from repeated applications.
* Similarly, look for implicit equality constraints in an attempt
* to reduce the number of local variables that get introduced
* during the repeated applications.
*/
static __isl_give TYPE *FN(TYPE,fixed_power_apply)(__isl_take TYPE *map1,
__isl_keep TYPE *map2)
{
TYPE *res;

res = FN(TYPE,apply_range)(map1, FN(TYPE,copy)(map2));
res = FN(TYPE,detect_equalities)(res);
res = FN(TYPE,coalesce)(res);

return res;
}

/* Compute the given non-zero power of "map" and return the result.
* If the exponent "exp" is negative, then the -exp th power of the inverse
* relation is computed.
Expand Down Expand Up @@ -34,11 +55,8 @@ __isl_give TYPE *FN(TYPE,fixed_power)(__isl_take TYPE *map, isl_int exp)
if (!isl_int_is_zero(r)) {
if (!res)
res = FN(TYPE,copy)(map);
else {
res = FN(TYPE,apply_range)(res,
FN(TYPE,copy)(map));
res = FN(TYPE,coalesce)(res);
}
else
res = FN(TYPE,fixed_power_apply)(res, map);
if (!res)
break;
}
Expand All @@ -47,8 +65,7 @@ __isl_give TYPE *FN(TYPE,fixed_power)(__isl_take TYPE *map, isl_int exp)
if (isl_int_is_zero(exp))
break;

map = FN(TYPE,apply_range)(map, FN(TYPE,copy)(map));
map = FN(TYPE,coalesce)(map);
map = FN(TYPE,fixed_power_apply)(map, map);
}
isl_int_clear(r);

Expand Down
59 changes: 59 additions & 0 deletions polly/lib/External/isl/isl_project_out_param_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2019 Cerebras Systems
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA
*/

#define xFN(TYPE,NAME) TYPE ## _ ## NAME
#define FN(TYPE,NAME) xFN(TYPE,NAME)

/* If "obj" involves a parameter with identifier "id",
* then turn it into an existentially quantified variable.
*/
__isl_give TYPE *FN(TYPE,project_out_param_id)(__isl_take TYPE *obj,
__isl_take isl_id *id)
{
int pos;

if (!obj || !id)
goto error;
pos = FN(TYPE,find_dim_by_id)(obj, isl_dim_param, id);
isl_id_free(id);
if (pos < 0)
return obj;
return FN(TYPE,project_out)(obj, isl_dim_param, pos, 1);
error:
FN(TYPE,free)(obj);
isl_id_free(id);
return NULL;
}

/* If "obj" involves any of the parameters with identifiers in "list",
* then turn them into existentially quantified variables.
*/
__isl_give TYPE *FN(TYPE,project_out_param_id_list)(__isl_take TYPE *obj,
__isl_take isl_id_list *list)
{
int i;
isl_size n;

n = isl_id_list_size(list);
if (n < 0)
goto error;
for (i = 0; i < n; ++i) {
isl_id *id;

id = isl_id_list_get_at(list, i);
obj = FN(TYPE,project_out_param_id)(obj, id);
}

isl_id_list_free(list);
return obj;
error:
isl_id_list_free(list);
FN(TYPE,free)(obj);
return NULL;
}
93 changes: 93 additions & 0 deletions polly/lib/External/isl/isl_pw_add_disjoint_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright 2010 INRIA Saclay
* Copyright 2011 Sven Verdoolaege
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
* Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
* 91893 Orsay, France
*/

#include <isl_pw_macro.h>

/* Make sure "pw" has room for at least "n" more pieces.
*
* If there is only one reference to pw, we extend it in place.
* Otherwise, we create a new PW and copy the pieces.
*/
static __isl_give PW *FN(PW,grow)(__isl_take PW *pw, int n)
{
int i;
isl_ctx *ctx;
PW *res;

if (!pw)
return NULL;
if (pw->n + n <= pw->size)
return pw;
ctx = FN(PW,get_ctx)(pw);
n += pw->n;
if (pw->ref == 1) {
res = isl_realloc(ctx, pw, struct PW,
sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece)));
if (!res)
return FN(PW,free)(pw);
res->size = n;
return res;
}
res = FN(PW,alloc_size)(isl_space_copy(pw->dim) OPT_TYPE_ARG(pw->), n);
if (!res)
return FN(PW,free)(pw);
for (i = 0; i < pw->n; ++i)
res = FN(PW,add_piece)(res, isl_set_copy(pw->p[i].set),
FN(EL,copy)(pw->p[i].FIELD));
FN(PW,free)(pw);
return res;
}

__isl_give PW *FN(PW,add_disjoint)(__isl_take PW *pw1, __isl_take PW *pw2)
{
int i;
isl_ctx *ctx;

if (FN(PW,align_params_bin)(&pw1, &pw2) < 0)
goto error;

if (pw1->size < pw1->n + pw2->n && pw1->n < pw2->n)
return FN(PW,add_disjoint)(pw2, pw1);

ctx = isl_space_get_ctx(pw1->dim);
if (!OPT_EQUAL_TYPES(pw1->, pw2->))
isl_die(ctx, isl_error_invalid,
"fold types don't match", goto error);
if (FN(PW,check_equal_space)(pw1, pw2) < 0)
goto error;

if (FN(PW,IS_ZERO)(pw1)) {
FN(PW,free)(pw1);
return pw2;
}

if (FN(PW,IS_ZERO)(pw2)) {
FN(PW,free)(pw2);
return pw1;
}

pw1 = FN(PW,grow)(pw1, pw2->n);
if (!pw1)
goto error;

for (i = 0; i < pw2->n; ++i)
pw1 = FN(PW,add_piece)(pw1,
isl_set_copy(pw2->p[i].set),
FN(EL,copy)(pw2->p[i].FIELD));

FN(PW,free)(pw2);

return pw1;
error:
FN(PW,free)(pw1);
FN(PW,free)(pw2);
return NULL;
}
15 changes: 15 additions & 0 deletions polly/lib/External/isl/isl_pw_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@

#include <isl_pw_macro.h>

#undef SUFFIX
#define SUFFIX point
#undef ARG1
#define ARG1 PW
#undef ARG2
#define ARG2 isl_point

static
#include "isl_align_params_templ.c"

/* Evaluate "pw" in the void point "pnt".
* In particular, return the value NaN.
*/
Expand All @@ -34,6 +44,9 @@ static __isl_give isl_val *FN(PW,eval_void)(__isl_take PW *pw,
* If the point is void, then return NaN.
* If the point lies outside the domain of "pw", then return 0 or NaN
* depending on whether 0 is the default value for this type of function.
*
* Align the parameters if needed, but "pnt" should specify a value
* for all parameters in "pw".
*/
__isl_give isl_val *FN(PW,eval)(__isl_take PW *pw, __isl_take isl_point *pnt)
{
Expand All @@ -45,6 +58,8 @@ __isl_give isl_val *FN(PW,eval)(__isl_take PW *pw, __isl_take isl_point *pnt)
isl_space *pnt_space, *pw_space;
isl_val *v;

FN(PW,align_params_point)(&pw, &pnt);

pnt_space = isl_point_peek_space(pnt);
pw_space = FN(PW,peek_space)(pw);
ok = isl_space_is_domain_internal(pnt_space, pw_space);
Expand Down
71 changes: 71 additions & 0 deletions polly/lib/External/isl/isl_pw_fix_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <isl_pw_macro.h>

/* Fix the value of the given parameter or domain dimension of "pw"
* to be equal to "value".
*/
__isl_give PW *FN(PW,fix_si)(__isl_take PW *pw, enum isl_dim_type type,
unsigned pos, int value)
{
int i;
isl_size n;

n = FN(PW,n_piece)(pw);
if (n < 0)
return FN(PW,free)(pw);

if (type == isl_dim_out)
isl_die(FN(PW,get_ctx)(pw), isl_error_invalid,
"cannot fix output dimension", return FN(PW,free)(pw));

if (type == isl_dim_in)
type = isl_dim_set;

for (i = n - 1; i >= 0; --i) {
isl_set *domain;

domain = FN(PW,take_domain_at)(pw, i);
domain = isl_set_fix_si(domain, type, pos, value);
pw = FN(PW,restore_domain_at)(pw, i, domain);
pw = FN(PW,exploit_equalities_and_remove_if_empty)(pw, i);
}

return pw;
}

/* Fix the value of the variable at position "pos" of type "type" of "pw"
* to be equal to "v".
*/
__isl_give PW *FN(PW,fix_val)(__isl_take PW *pw,
enum isl_dim_type type, unsigned pos, __isl_take isl_val *v)
{
int i;
isl_size n;

if (!v)
return FN(PW,free)(pw);
if (!isl_val_is_int(v))
isl_die(FN(PW,get_ctx)(pw), isl_error_invalid,
"expecting integer value", goto error);

n = FN(PW,n_piece)(pw);
if (n < 0)
goto error;

if (type == isl_dim_in)
type = isl_dim_set;

for (i = 0; i < n; ++i) {
isl_set *domain;

domain = FN(PW,take_domain_at)(pw, i);
domain = isl_set_fix(domain, type, pos, v->n);
pw = FN(PW,restore_domain_at)(pw, i, domain);
pw = FN(PW,exploit_equalities_and_remove_if_empty)(pw, i);
}

isl_val_free(v);
return pw;
error:
isl_val_free(v);
return FN(PW,free)(pw);
}
14 changes: 14 additions & 0 deletions polly/lib/External/isl/isl_pw_from_range_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2013 Ecole Normale Superieure
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege,
* Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
*/

#include <isl_pw_macro.h>

#undef TYPE
#define TYPE PW
#include "isl_from_range_templ.c"
41 changes: 19 additions & 22 deletions polly/lib/External/isl/isl_pw_insert_dims_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,35 @@ __isl_give PW *FN(PW,insert_dims)(__isl_take PW *pw, enum isl_dim_type type,
unsigned first, unsigned n)
{
int i;
isl_size n_piece;
enum isl_dim_type set_type;
isl_space *space;

if (!pw)
return NULL;
n_piece = FN(PW,n_piece)(pw);
if (n_piece < 0)
return FN(PW,free)(pw);
if (n == 0 && !isl_space_is_named_or_nested(pw->dim, type))
return pw;

set_type = type == isl_dim_in ? isl_dim_set : type;

pw = FN(PW,cow)(pw);
if (!pw)
return NULL;

pw->dim = isl_space_insert_dims(pw->dim, type, first, n);
if (!pw->dim)
goto error;

for (i = 0; i < pw->n; ++i) {
pw->p[i].set = isl_set_insert_dims(pw->p[i].set,
set_type, first, n);
if (!pw->p[i].set)
goto error;
pw->p[i].FIELD = FN(EL,insert_dims)(pw->p[i].FIELD,
type, first, n);
if (!pw->p[i].FIELD)
goto error;
space = FN(PW,take_space)(pw);
space = isl_space_insert_dims(space, type, first, n);
pw = FN(PW,restore_space)(pw, space);

for (i = 0; i < n_piece; ++i) {
isl_set *domain;
EL *el;

domain = FN(PW,take_domain_at)(pw, i);
domain = isl_set_insert_dims(domain, set_type, first, n);
pw = FN(PW,restore_domain_at)(pw, i, domain);
el = FN(PW,take_base_at)(pw, i);
el = FN(EL,insert_dims)(el, type, first, n);
pw = FN(PW,restore_base_at)(pw, i, el);
}

return pw;
error:
FN(PW,free)(pw);
return NULL;
}

__isl_give PW *FN(PW,add_dims)(__isl_take PW *pw, enum isl_dim_type type,
Expand Down
34 changes: 18 additions & 16 deletions polly/lib/External/isl/isl_pw_morph_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,33 @@ __isl_give PW *FN(PW,morph_domain)(__isl_take PW *pw,
__isl_take isl_morph *morph)
{
int i;
isl_size n;
isl_ctx *ctx;
isl_space *space;

if (!pw || !morph)
n = FN(PW,n_piece)(pw);
if (n < 0 || !morph)
goto error;

ctx = isl_space_get_ctx(pw->dim);
isl_assert(ctx, isl_space_is_domain_internal(morph->dom->dim, pw->dim),
goto error);

pw = FN(PW,cow)(pw);
if (!pw)
goto error;
pw->dim = isl_space_extend_domain_with_range(
isl_space_copy(morph->ran->dim), pw->dim);
if (!pw->dim)
goto error;
space = FN(PW,take_space)(pw);
space = isl_space_extend_domain_with_range(
isl_space_copy(morph->ran->dim), space);
pw = FN(PW,restore_space)(pw, space);

for (i = 0; i < n; ++i) {
isl_set *domain;
EL *el;

for (i = 0; i < pw->n; ++i) {
pw->p[i].set = isl_morph_set(isl_morph_copy(morph), pw->p[i].set);
if (!pw->p[i].set)
goto error;
pw->p[i].FIELD = FN(EL,morph_domain)(pw->p[i].FIELD,
isl_morph_copy(morph));
if (!pw->p[i].FIELD)
goto error;
domain = FN(PW,take_domain_at)(pw, i);
domain = isl_morph_set(isl_morph_copy(morph), domain);
pw = FN(PW,restore_domain_at)(pw, i, domain);
el = FN(PW,take_base_at)(pw, i);
el = FN(EL,morph_domain)(el, isl_morph_copy(morph));
pw = FN(PW,restore_base_at)(pw, i, el);
}

isl_morph_free(morph);
Expand Down
39 changes: 21 additions & 18 deletions polly/lib/External/isl/isl_pw_move_dims_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,40 @@ __isl_give PW *FN(PW,move_dims)(__isl_take PW *pw,
enum isl_dim_type src_type, unsigned src_pos, unsigned n)
{
int i;
isl_size n_piece;
isl_space *space;

pw = FN(PW,cow)(pw);
if (!pw)
return NULL;
space = FN(PW,take_space)(pw);
space = isl_space_move_dims(space, dst_type, dst_pos,
src_type, src_pos, n);
pw = FN(PW,restore_space)(pw, space);

pw->dim = isl_space_move_dims(pw->dim, dst_type, dst_pos, src_type, src_pos, n);
if (!pw->dim)
goto error;
n_piece = FN(PW,n_piece)(pw);
if (n_piece < 0)
return FN(PW,free)(pw);

for (i = 0; i < pw->n; ++i) {
pw->p[i].FIELD = FN(EL,move_dims)(pw->p[i].FIELD,
for (i = 0; i < n_piece; ++i) {
EL *el;

el = FN(PW,take_base_at)(pw, i);
el = FN(EL,move_dims)(el,
dst_type, dst_pos, src_type, src_pos, n);
if (!pw->p[i].FIELD)
goto error;
pw = FN(PW,restore_base_at)(pw, i, el);
}

if (dst_type == isl_dim_in)
dst_type = isl_dim_set;
if (src_type == isl_dim_in)
src_type = isl_dim_set;

for (i = 0; i < pw->n; ++i) {
pw->p[i].set = isl_set_move_dims(pw->p[i].set,
dst_type, dst_pos,
for (i = 0; i < n_piece; ++i) {
isl_set *domain;

domain = FN(PW,take_domain_at)(pw, i);
domain = isl_set_move_dims(domain, dst_type, dst_pos,
src_type, src_pos, n);
if (!pw->p[i].set)
goto error;
pw = FN(PW,restore_domain_at)(pw, i, domain);
}

return pw;
error:
FN(PW,free)(pw);
return NULL;
}
20 changes: 1 addition & 19 deletions polly/lib/External/isl/isl_pw_neg_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,5 @@

__isl_give PW *FN(PW,neg)(__isl_take PW *pw)
{
int i;

if (!pw)
return NULL;

if (FN(PW,IS_ZERO)(pw))
return pw;

pw = FN(PW,cow)(pw);
if (!pw)
return NULL;

for (i = 0; i < pw->n; ++i) {
pw->p[i].FIELD = FN(EL,neg)(pw->p[i].FIELD);
if (!pw->p[i].FIELD)
return FN(PW,free)(pw);
}

return pw;
return FN(PW,un_op)(pw, &FN(EL,neg));
}
55 changes: 55 additions & 0 deletions polly/lib/External/isl/isl_pw_print_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2011 Sven Verdoolaege
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege.
*/

#undef EL
#define EL CAT(isl_,BASE)
#undef PW
#define PW CAT(isl_pw_,BASE)

/* Print the body of a piecewise expression, i.e., a semicolon delimited
* sequence of expressions, each followed by constraints.
*/
static __isl_give isl_printer *FN(print_body_pw,BASE)(
__isl_take isl_printer *p, __isl_keep PW *pw)
{
int i;

if (!pw)
return isl_printer_free(p);

for (i = 0; i < pw->n; ++i) {
EL *el;
isl_space *space;

if (i)
p = isl_printer_print_str(p, "; ");
el = FN(PW,peek_base_at)(pw, i);
p = FN(print_body,BASE)(p, el);
space = FN(EL,get_domain_space)(el);
p = print_disjuncts(set_to_map(pw->p[i].set), space, p, 0);
isl_space_free(space);
}
return p;
}

/* Print a piecewise expression in isl format.
*/
static __isl_give isl_printer *FN(FN(print_pw,BASE),isl)(
__isl_take isl_printer *p, __isl_keep PW *pw)
{
struct isl_print_space_data data = { 0 };

if (!pw)
return isl_printer_free(p);

p = print_param_tuple(p, pw->dim, &data);
p = isl_printer_print_str(p, "{ ");
p = FN(print_body_pw,BASE)(p, pw);
p = isl_printer_print_str(p, " }");
return p;
}
23 changes: 13 additions & 10 deletions polly/lib/External/isl/isl_pw_pullback_templ.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,29 @@ __isl_give PW *FN(PW,pullback_multi_aff)(__isl_take PW *pw,
__isl_take isl_multi_aff *ma)
{
int i;
isl_size n;
isl_space *space = NULL;

FN(PW,align_params_multi_aff)(&pw, &ma);
ma = isl_multi_aff_align_divs(ma);
pw = FN(PW,cow)(pw);
if (!pw || !ma)
n = FN(PW,n_piece)(pw);
if (n < 0 || !ma)
goto error;

space = isl_space_join(isl_multi_aff_get_space(ma),
FN(PW,get_space)(pw));

for (i = 0; i < pw->n; ++i) {
pw->p[i].set = isl_set_preimage_multi_aff(pw->p[i].set,
isl_multi_aff_copy(ma));
if (!pw->p[i].set)
goto error;
pw->p[i].FIELD = FN(EL,pullback_multi_aff)(pw->p[i].FIELD,
for (i = 0; i < n; ++i) {
isl_set *domain;
EL *el;

domain = FN(PW,take_domain_at)(pw, i);
domain = isl_set_preimage_multi_aff(domain,
isl_multi_aff_copy(ma));
if (!pw->p[i].FIELD)
goto error;
pw = FN(PW,restore_domain_at)(pw, i, domain);
el = FN(PW,take_base_at)(pw, i);
el = FN(EL,pullback_multi_aff)(el, isl_multi_aff_copy(ma));
pw = FN(PW,restore_base_at)(pw, i, el);
}

pw = FN(PW,reset_space)(pw, space);
Expand Down
42 changes: 42 additions & 0 deletions polly/lib/External/isl/isl_pw_scale_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2010 INRIA Saclay
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
* Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
* 91893 Orsay, France
*/

#include <isl_pw_macro.h>

__isl_give PW *FN(PW,scale)(__isl_take PW *pw, isl_int v)
{
int i;
isl_size n;

if (isl_int_is_one(v))
return pw;
if (pw && DEFAULT_IS_ZERO && isl_int_is_zero(v)) {
PW *zero;
isl_space *space = FN(PW,get_space)(pw);
zero = FN(PW,ZERO)(space OPT_TYPE_ARG(pw->));
FN(PW,free)(pw);
return zero;
}
if (isl_int_is_neg(v))
pw = FN(PW,negate_type)(pw);

n = FN(PW,n_piece)(pw);
if (n < 0)
return FN(PW,free)(pw);
for (i = 0; i < n; ++i) {
EL *el;

el = FN(PW,take_base_at)(pw, i);
el = FN(EL,scale)(el, v);
pw = FN(PW,restore_base_at)(pw, i, el);
}

return pw;
}
37 changes: 37 additions & 0 deletions polly/lib/External/isl/isl_pw_split_dims_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2010 INRIA Saclay
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
* Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
* 91893 Orsay, France
*/

#include <isl_pw_macro.h>

__isl_give PW *FN(PW,split_dims)(__isl_take PW *pw,
enum isl_dim_type type, unsigned first, unsigned n)
{
int i;
isl_size n_piece;

n_piece = FN(PW,n_piece)(pw);
if (n_piece < 0)
return FN(PW,free)(pw);
if (n == 0)
return pw;

if (type == isl_dim_in)
type = isl_dim_set;

for (i = 0; i < n; ++i) {
isl_set *domain;

domain = FN(PW,take_domain_at)(pw, i);
domain = isl_set_split_dims(domain, type, first, n);
pw = FN(PW,restore_domain_at)(pw, i, domain);
}

return pw;
}
1,379 changes: 607 additions & 772 deletions polly/lib/External/isl/isl_pw_templ.c

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions polly/lib/External/isl/isl_pw_un_op_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2010 INRIA Saclay
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
* Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
* 91893 Orsay, France
*/

#include <isl_pw_macro.h>

/* Apply "fn" to each of the base expressions of "pw".
* The function is assumed to have no effect on the default value
* (i.e., zero for those objects with a default value).
*/
static __isl_give PW *FN(PW,un_op)(__isl_take PW *pw,
__isl_give EL *(*fn)(__isl_take EL *el))
{
isl_size n;
int i;

n = FN(PW,n_piece)(pw);
if (n < 0)
return FN(PW,free)(pw);

for (i = 0; i < n; ++i) {
EL *el;

el = FN(PW,take_base_at)(pw, i);
el = fn(el);
pw = FN(PW,restore_base_at)(pw, i, el);
}

return pw;
}
2 changes: 1 addition & 1 deletion polly/lib/External/isl/isl_pw_union_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static __isl_give PW *FN(PW,union_opt_cmp)(
}

for (i = 0; i < 2; ++i) {
data[i].pw = FN(PW,sort)(data[i].pw);
data[i].pw = FN(PW,sort_unique)(data[i].pw);
data[i].cell = FN(PW,extract_domains)(data[i].pw);
}

Expand Down
27 changes: 27 additions & 0 deletions polly/lib/External/isl/isl_read_from_str_templ.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2008 Katholieke Universiteit Leuven
*
* Use of this software is governed by the MIT license
*
* Written by Sven Verdoolaege, K.U.Leuven, Departement
* Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
*/

#define xCAT(A,B) A ## B
#define CAT(A,B) xCAT(A,B)
#undef TYPE
#define TYPE CAT(isl_,TYPE_BASE)

/* Read an object of type TYPE from "str" (using an isl_stream).
*/
__isl_give TYPE *FN(isl,FN(TYPE_BASE,read_from_str))(isl_ctx *ctx,
const char *str)
{
TYPE *obj;
isl_stream *s = isl_stream_new_str(ctx, str);
if (!s)
return NULL;
obj = FN(isl_stream_read,TYPE_BASE)(s);
isl_stream_free(s);
return obj;
}
104 changes: 72 additions & 32 deletions polly/lib/External/isl/isl_reordering.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,49 @@
#include <isl_space_private.h>
#include <isl_reordering.h>

__isl_give isl_reordering *isl_reordering_alloc(isl_ctx *ctx, int len)
/* Create a new reordering description based on
* the number of source dimensions "src_len" and
* (an initial value for) the number of target dimensions "dst_len".
*
* The caller still needs to fill in the space field and
* possibly adjust the target dimensionality if this is not known yet
* when this function is called.
*/
__isl_give isl_reordering *isl_reordering_alloc(isl_ctx *ctx, int src_len,
int dst_len)
{
isl_reordering *exp;

exp = isl_alloc(ctx, struct isl_reordering,
sizeof(struct isl_reordering) + (len - 1) * sizeof(int));
sizeof(struct isl_reordering) + (src_len - 1) * sizeof(int));
if (!exp)
return NULL;

exp->ref = 1;
exp->len = len;
exp->src_len = src_len;
exp->dst_len = dst_len;
exp->space = NULL;

return exp;
}

/* Set r->dst_len to the total dimensionality of r->space.
*/
static __isl_give isl_reordering *isl_reordering_set_dst_len_from_space(
__isl_take isl_reordering *r)
{
isl_size n;

if (!r)
return NULL;

n = isl_space_dim(r->space, isl_dim_all);
if (n < 0)
return isl_reordering_free(r);
r->dst_len = n;
return r;
}

__isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp)
{
if (!exp)
Expand All @@ -46,14 +73,15 @@ __isl_give isl_reordering *isl_reordering_dup(__isl_keep isl_reordering *r)
if (!r)
return NULL;

dup = isl_reordering_alloc(isl_reordering_get_ctx(r), r->len);
dup = isl_reordering_alloc(isl_reordering_get_ctx(r),
r->src_len, r->dst_len);
if (!dup)
return NULL;

dup->space = isl_reordering_get_space(r);
if (!dup->space)
return isl_reordering_free(dup);
for (i = 0; i < dup->len; ++i)
for (i = 0; i < dup->src_len; ++i)
dup->pos[i] = r->pos[i];

return dup;
Expand Down Expand Up @@ -110,36 +138,44 @@ __isl_give isl_space *isl_reordering_get_space(__isl_keep isl_reordering *r)
* to the corresponding parameters in a new dimension specification
* that has the parameters of "aligner" first, followed by
* any remaining parameters of "alignee" that do not occur in "aligner".
* The other dimensions of "alignee" are mapped to subsequent positions
* in order.
*/
__isl_give isl_reordering *isl_parameter_alignment_reordering(
__isl_keep isl_space *alignee, __isl_keep isl_space *aligner)
{
int i, j;
int i, j, offset;
isl_ctx *ctx;
isl_reordering *exp;
isl_size dim, n_alignee, n_aligner;

if (!alignee || !aligner)
dim = isl_space_dim(alignee, isl_dim_all);
n_alignee = isl_space_dim(alignee, isl_dim_param);
n_aligner = isl_space_dim(aligner, isl_dim_param);
if (dim < 0 || n_alignee < 0 || n_aligner < 0)
return NULL;

exp = isl_reordering_alloc(alignee->ctx, alignee->nparam);
ctx = isl_space_get_ctx(alignee);
exp = isl_reordering_alloc(ctx, dim, dim);
if (!exp)
return NULL;

exp->space = isl_space_params(isl_space_copy(aligner));
exp->space = isl_space_replace_params(isl_space_copy(alignee), aligner);

for (i = 0; i < alignee->nparam; ++i) {
for (i = 0; i < n_alignee; ++i) {
isl_id *id_i;
id_i = isl_space_get_dim_id(alignee, isl_dim_param, i);
if (!id_i)
isl_die(alignee->ctx, isl_error_invalid,
isl_die(ctx, isl_error_invalid,
"cannot align unnamed parameters", goto error);
for (j = 0; j < aligner->nparam; ++j) {
for (j = 0; j < n_aligner; ++j) {
isl_id *id_j;
id_j = isl_space_get_dim_id(aligner, isl_dim_param, j);
isl_id_free(id_j);
if (id_i == id_j)
break;
}
if (j < aligner->nparam) {
if (j < n_aligner) {
exp->pos[i] = j;
isl_id_free(id_i);
} else {
Expand All @@ -155,8 +191,14 @@ __isl_give isl_reordering *isl_parameter_alignment_reordering(
}
}

if (!exp->space)
return isl_reordering_free(exp);
exp = isl_reordering_set_dst_len_from_space(exp);
if (!exp)
return NULL;

offset = exp->dst_len - exp->src_len;
for (i = n_alignee; i < dim; ++i)
exp->pos[i] = offset + i;

return exp;
error:
isl_reordering_free(exp);
Expand All @@ -179,14 +221,16 @@ __isl_give isl_reordering *isl_reordering_unbind_params_insert_domain(
{
int i, n;
int offset, first;
isl_size dim;
isl_ctx *ctx;
isl_reordering *r;

if (!space || !tuple)
dim = isl_space_dim(space, isl_dim_all);
if (dim < 0 || !tuple)
return NULL;

ctx = isl_space_get_ctx(space);
r = isl_reordering_alloc(ctx, isl_space_dim(space, isl_dim_all));
r = isl_reordering_alloc(ctx, dim, dim);
if (!r)
return NULL;

Expand Down Expand Up @@ -224,43 +268,38 @@ __isl_give isl_reordering *isl_reordering_unbind_params_insert_domain(
r->pos[pos] = offset + i;
}

offset = isl_space_dim(r->space, isl_dim_all) - r->len;
offset = isl_space_dim(r->space, isl_dim_all) - dim;
first = isl_space_dim(space, isl_dim_param);
n = r->len - first;
n = dim - first;
for (i = 0; i < n; ++i)
r->pos[first + i] = first + offset + i;

return r;
return isl_reordering_set_dst_len_from_space(r);
}

__isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp,
unsigned extra)
{
int i;
isl_ctx *ctx;
isl_space *space;
isl_reordering *res;
int offset;
isl_size dim;

if (!exp)
return NULL;
if (extra == 0)
return exp;

ctx = isl_reordering_get_ctx(exp);
space = isl_reordering_peek_space(exp);
dim = isl_space_dim(space, isl_dim_all);
if (dim < 0)
return isl_reordering_free(exp);
offset = dim - exp->len;
res = isl_reordering_alloc(ctx, exp->len + extra);
offset = exp->dst_len - exp->src_len;
res = isl_reordering_alloc(ctx, exp->src_len + extra,
exp->dst_len + extra);
if (!res)
goto error;
res->space = isl_reordering_get_space(exp);
for (i = 0; i < exp->len; ++i)
for (i = 0; i < exp->src_len; ++i)
res->pos[i] = exp->pos[i];
for (i = exp->len; i < res->len; ++i)
for (i = exp->src_len; i < res->src_len; ++i)
res->pos[i] = offset + i;

isl_reordering_free(exp);
Expand All @@ -282,7 +321,8 @@ __isl_give isl_reordering *isl_reordering_extend_space(
if (!exp || dim < 0)
goto error;

res = isl_reordering_extend(isl_reordering_copy(exp), dim - exp->len);
res = isl_reordering_extend(isl_reordering_copy(exp),
dim - exp->src_len);
res = isl_reordering_cow(res);
if (!res)
goto error;
Expand All @@ -307,7 +347,7 @@ void isl_reordering_dump(__isl_keep isl_reordering *exp)
int i;

isl_space_dump(exp->space);
for (i = 0; i < exp->len; ++i)
for (i = 0; i < exp->src_len; ++i)
fprintf(stderr, "%d -> %d; ", i, exp->pos[i]);
fprintf(stderr, "\n");
}
11 changes: 6 additions & 5 deletions polly/lib/External/isl/isl_reordering.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@

#include <isl/space.h>

/* pos maps original dimensions to new dimensions.
/* "pos" has "src_len" entries and maps original dimensions to new dimensions.
* The final space is given by "space".
* The number of dimensions (i.e., the range of values) in the result
* may be larger than the number of dimensions in the input.
* In particular, the possible values of the entries in pos ranges from 0 to
* the total dimension of dim - 1, unless isl_reordering_extend
* has been called.
* In particular, the possible values of the entries in "pos" ranges from 0 to
* to "dst_len" - 1, where "dst_len" is equal to the total dimension of "space",
* unless isl_reordering_extend has been called.
*/
struct isl_reordering {
int ref;
isl_space *space;
unsigned len;
unsigned src_len;
unsigned dst_len;
int pos[1];
};
typedef struct isl_reordering isl_reordering;
Expand Down
5 changes: 3 additions & 2 deletions polly/lib/External/isl/isl_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <bset_from_bmap.c>
#include <set_to_map.c>

static __isl_give isl_vec *isl_basic_set_sample_bounded(
__isl_take isl_basic_set *bset);

static __isl_give isl_vec *empty_sample(__isl_take isl_basic_set *bset)
{
struct isl_vec *vec;
Expand Down Expand Up @@ -1150,12 +1153,10 @@ static __isl_give isl_vec *gbr_sample(__isl_take isl_basic_set *bset)
static __isl_give isl_vec *basic_set_sample(__isl_take isl_basic_set *bset,
int bounded)
{
struct isl_ctx *ctx;
isl_size dim;
if (!bset)
return NULL;

ctx = bset->ctx;
if (isl_basic_set_plain_is_empty(bset))
return empty_sample(bset);

Expand Down
2 changes: 0 additions & 2 deletions polly/lib/External/isl/isl_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ extern "C" {
#endif

__isl_give isl_vec *isl_basic_set_sample_vec(__isl_take isl_basic_set *bset);
__isl_give isl_vec *isl_basic_set_sample_bounded(
__isl_take isl_basic_set *bset);
__isl_give isl_vec *isl_basic_set_sample_with_cone(
__isl_take isl_basic_set *bset, __isl_take isl_basic_set *cone);

Expand Down
40 changes: 17 additions & 23 deletions polly/lib/External/isl/isl_schedule_constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ __isl_give isl_printer *isl_printer_print_schedule_constraints(
#define KEY_ERROR isl_sc_key_error
#undef KEY_END
#define KEY_END isl_sc_key_end
#undef KEY_STR
#define KEY_STR key_str
#undef KEY_EXTRACT
#define KEY_EXTRACT extract_key
#undef KEY_GET
#define KEY_GET get_key
#include "extract_key.c"

#undef BASE
Expand Down Expand Up @@ -588,16 +594,17 @@ __isl_give isl_schedule_constraints *isl_stream_read_schedule_constraints(
{
isl_ctx *ctx;
isl_schedule_constraints *sc;
int more;
isl_bool more;
int domain_set = 0;

if (isl_stream_yaml_read_start_mapping(s))
if (isl_stream_yaml_read_start_mapping(s) < 0)
return NULL;

ctx = isl_stream_get_ctx(s);
sc = isl_schedule_constraints_alloc(ctx);
while ((more = isl_stream_yaml_next(s)) > 0) {
while ((more = isl_stream_yaml_next(s)) == isl_bool_true) {
enum isl_sc_key key;
enum isl_edge_type type;
isl_set *context;
isl_union_set *domain;
isl_union_map *constraints;
Expand Down Expand Up @@ -627,8 +634,10 @@ __isl_give isl_schedule_constraints *isl_stream_read_schedule_constraints(
case isl_sc_key_condition:
case isl_sc_key_conditional_validity:
case isl_sc_key_proximity:
type = (enum isl_edge_type) key;
constraints = read_union_map(s);
sc = isl_schedule_constraints_set(sc, key, constraints);
sc = isl_schedule_constraints_set(sc, type,
constraints);
if (!sc)
return NULL;
break;
Expand All @@ -637,10 +646,8 @@ __isl_give isl_schedule_constraints *isl_stream_read_schedule_constraints(
if (more < 0)
return isl_schedule_constraints_free(sc);

if (isl_stream_yaml_read_end_mapping(s) < 0) {
isl_stream_error(s, NULL, "unexpected extra elements");
if (isl_stream_yaml_read_end_mapping(s) < 0)
return isl_schedule_constraints_free(sc);
}

if (!domain_set) {
isl_stream_error(s, NULL, "no domain specified");
Expand All @@ -667,22 +674,9 @@ __isl_give isl_schedule_constraints *isl_schedule_constraints_read_from_file(
return sc;
}

/* Read an isl_schedule_constraints object from the string "str".
*/
__isl_give isl_schedule_constraints *isl_schedule_constraints_read_from_str(
isl_ctx *ctx, const char *str)
{
struct isl_stream *s;
isl_schedule_constraints *sc;

s = isl_stream_new_str(ctx, str);
if (!s)
return NULL;
sc = isl_stream_read_schedule_constraints(s);
isl_stream_free(s);

return sc;
}
#undef TYPE_BASE
#define TYPE_BASE schedule_constraints
#include "isl_read_from_str_templ.c"

/* Align the parameters of the fields of "sc".
*/
Expand Down
116 changes: 87 additions & 29 deletions polly/lib/External/isl/isl_schedule_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ __isl_give isl_schedule *isl_schedule_node_get_schedule(

/* Return a fresh copy of "node".
*/
__isl_take isl_schedule_node *isl_schedule_node_dup(
__isl_give isl_schedule_node *isl_schedule_node_dup(
__isl_keep isl_schedule_node *node)
{
if (!node)
Expand Down Expand Up @@ -1141,6 +1141,14 @@ __isl_give isl_schedule_node *isl_schedule_node_parent(
return isl_schedule_node_ancestor(node, 1);
}

/* Move the "node" pointer to the parent of its parent.
*/
__isl_give isl_schedule_node *isl_schedule_node_grandparent(
__isl_take isl_schedule_node *node)
{
return isl_schedule_node_ancestor(node, 2);
}

/* Move the "node" pointer to the root of its schedule tree.
*/
__isl_give isl_schedule_node *isl_schedule_node_root(
Expand Down Expand Up @@ -1201,6 +1209,17 @@ __isl_give isl_schedule_node *isl_schedule_node_child(
return node;
}

/* Move the "node" pointer to the child at position "pos2" of the child
* at position "pos1".
*/
__isl_give isl_schedule_node *isl_schedule_node_grandchild(
__isl_take isl_schedule_node *node, int pos1, int pos2)
{
node = isl_schedule_node_child(node, pos1);
node = isl_schedule_node_child(node, pos2);
return node;
}

/* Move the "node" pointer to the first child of the node
* it currently points to.
*/
Expand Down Expand Up @@ -2273,6 +2292,20 @@ __isl_give isl_id *isl_schedule_node_mark_get_id(
return isl_schedule_tree_mark_get_id(node->tree);
}

/* Check that "node" is a sequence node.
*/
static isl_stat check_is_sequence(__isl_keep isl_schedule_node *node)
{
if (!node)
return isl_stat_error;

if (isl_schedule_node_get_type(node) != isl_schedule_node_sequence)
isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
"not a sequence node", return isl_stat_error);

return isl_stat_ok;
}

/* Replace the child at position "pos" of the sequence node "node"
* by the children of sequence root node of "tree".
*/
Expand All @@ -2282,11 +2315,8 @@ __isl_give isl_schedule_node *isl_schedule_node_sequence_splice(
{
isl_schedule_tree *node_tree;

if (!node || !tree)
if (check_is_sequence(node) < 0 || !tree)
goto error;
if (isl_schedule_node_get_type(node) != isl_schedule_node_sequence)
isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
"not a sequence node", goto error);
if (isl_schedule_tree_get_type(tree) != isl_schedule_node_sequence)
isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
"not a sequence node", goto error);
Expand Down Expand Up @@ -2317,18 +2347,11 @@ __isl_give isl_schedule_node *isl_schedule_node_sequence_splice_child(
isl_schedule_node *child;
isl_schedule_tree *tree;

if (!node)
return NULL;
if (isl_schedule_node_get_type(node) != isl_schedule_node_sequence)
isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
"not a sequence node",
return isl_schedule_node_free(node));
node = isl_schedule_node_child(node, pos);
node = isl_schedule_node_child(node, 0);
if (isl_schedule_node_get_type(node) != isl_schedule_node_sequence)
isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid,
"not a sequence node",
return isl_schedule_node_free(node));
if (check_is_sequence(node) < 0)
return isl_schedule_node_free(node);
node = isl_schedule_node_grandchild(node, pos, 0);
if (check_is_sequence(node) < 0)
return isl_schedule_node_free(node);
n = isl_schedule_node_n_children(node);
if (n < 0)
return isl_schedule_node_free(node);
Expand All @@ -2350,6 +2373,46 @@ __isl_give isl_schedule_node *isl_schedule_node_sequence_splice_child(
return node;
}

/* Given a sequence node "node", for each child that is also
* (the parent of) a sequence node, attach the children of that node directly
* as children of "node" at the position of the child,
* replacing this original child.
*
* Since splicing in a child may change the positions of later children,
* iterate through the children from last to first.
*/
__isl_give isl_schedule_node *isl_schedule_node_sequence_splice_children(
__isl_take isl_schedule_node *node)
{
int i;
isl_size n;

if (check_is_sequence(node) < 0)
return isl_schedule_node_free(node);
n = isl_schedule_node_n_children(node);
if (n < 0)
return isl_schedule_node_free(node);

for (i = n - 1; i >= 0; --i) {
enum isl_schedule_node_type type;
int is_seq;

node = isl_schedule_node_grandchild(node, i, 0);
type = isl_schedule_node_get_type(node);
if (type < 0)
return isl_schedule_node_free(node);
is_seq = type == isl_schedule_node_sequence;
node = isl_schedule_node_grandparent(node);

if (!is_seq)
continue;

node = isl_schedule_node_sequence_splice_child(node, i);
}

return node;
}

/* Update the ancestors of "node" to point to the tree that "node"
* now points to.
* That is, replace the child in the original parent that corresponds
Expand Down Expand Up @@ -4151,17 +4214,15 @@ static isl_bool has_ancestors(__isl_keep isl_schedule_node *node,
* of both the original extension and the domain elements that reach
* that original extension?
*/
static int is_disjoint_extension(__isl_keep isl_schedule_node *node,
static isl_bool is_disjoint_extension(__isl_keep isl_schedule_node *node,
__isl_keep isl_union_map *extension)
{
isl_union_map *old;
isl_union_set *domain;
int empty;
isl_bool empty;

node = isl_schedule_node_copy(node);
node = isl_schedule_node_parent(node);
node = isl_schedule_node_parent(node);
node = isl_schedule_node_parent(node);
node = isl_schedule_node_ancestor(node, 3);
old = isl_schedule_node_extension_get_extension(node);
domain = isl_schedule_node_get_universe_domain(node);
isl_schedule_node_free(node);
Expand Down Expand Up @@ -4195,14 +4256,12 @@ static __isl_give isl_schedule_node *extend_extension(
pos = isl_schedule_node_get_child_position(node);
if (pos < 0)
node = isl_schedule_node_free(node);
node = isl_schedule_node_parent(node);
node = isl_schedule_node_parent(node);
node = isl_schedule_node_grandparent(node);
node_extension = isl_schedule_node_extension_get_extension(node);
disjoint = isl_union_map_is_disjoint(extension, node_extension);
extension = isl_union_map_union(extension, node_extension);
node = isl_schedule_node_extension_set_extension(node, extension);
node = isl_schedule_node_child(node, 0);
node = isl_schedule_node_child(node, pos);
node = isl_schedule_node_grandchild(node, 0, pos);

if (disjoint < 0)
return isl_schedule_node_free(node);
Expand Down Expand Up @@ -4279,7 +4338,7 @@ static __isl_give isl_schedule_node *insert_extension(
if (in_ext < 0)
goto error;
if (in_ext) {
int disjoint;
isl_bool disjoint;

disjoint = is_disjoint_extension(node, extension);
if (disjoint < 0)
Expand Down Expand Up @@ -4327,8 +4386,7 @@ static __isl_give isl_schedule_node *graft_or_splice(
pos = 0;
node = isl_schedule_node_graft_tree(node, tree);
}
node = isl_schedule_node_child(node, pos + tree_pos);
node = isl_schedule_node_child(node, 0);
node = isl_schedule_node_grandchild(node, pos + tree_pos, 0);

return node;
}
Expand Down
103 changes: 34 additions & 69 deletions polly/lib/External/isl/isl_schedule_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ static char *key_str[] = {
#define KEY_ERROR isl_schedule_key_error
#undef KEY_END
#define KEY_END isl_schedule_key_end
#undef KEY_STR
#define KEY_STR key_str
#undef KEY_EXTRACT
#define KEY_EXTRACT extract_key
#undef KEY_GET
#define KEY_GET get_key
#include "extract_key.c"

static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
Expand All @@ -71,7 +77,7 @@ static __isl_give isl_schedule_tree *read_context(__isl_keep isl_stream *s)
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -122,7 +128,7 @@ static __isl_give isl_schedule_tree *read_domain(__isl_keep isl_stream *s)
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -171,7 +177,7 @@ static __isl_give isl_schedule_tree *read_expansion(isl_stream *s)
isl_union_pw_multi_aff *contraction = NULL;
isl_union_map *expansion = NULL;
isl_schedule_tree *tree = NULL;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -216,7 +222,7 @@ static __isl_give isl_schedule_tree *read_expansion(isl_stream *s)
isl_die(ctx, isl_error_invalid, "unexpected key",
goto error);
}
} while ((more = isl_stream_yaml_next(s)) > 0);
} while ((more = isl_stream_yaml_next(s)) == isl_bool_true);

if (more < 0)
goto error;
Expand Down Expand Up @@ -248,7 +254,7 @@ static __isl_give isl_schedule_tree *read_extension(isl_stream *s)
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -299,7 +305,7 @@ static __isl_give isl_schedule_tree *read_filter(__isl_keep isl_stream *s)
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -350,7 +356,7 @@ static __isl_give isl_schedule_tree *read_guard(isl_stream *s)
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -401,7 +407,7 @@ static __isl_give isl_schedule_tree *read_mark(isl_stream *s)
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -443,32 +449,17 @@ static __isl_give isl_schedule_tree *read_mark(isl_stream *s)
return NULL;
}

#undef EL_BASE
#define EL_BASE val

#include <isl_list_read_yaml_templ.c>

/* Read a sequence of integers from "s" (representing the coincident
* property of a band node).
*/
static __isl_give isl_val_list *read_coincident(__isl_keep isl_stream *s)
{
isl_ctx *ctx;
isl_val_list *list;
int more;

ctx = isl_stream_get_ctx(s);

if (isl_stream_yaml_read_start_sequence(s) < 0)
return NULL;

list = isl_val_list_alloc(ctx, 0);
while ((more = isl_stream_yaml_next(s)) > 0) {
isl_val *val;

val = isl_stream_read_val(s);
list = isl_val_list_add(list, val);
}

if (more < 0 || isl_stream_yaml_read_end_sequence(s))
list = isl_val_list_free(list);

return list;
return isl_stream_yaml_read_val_list(s);
}

/* Set the (initial) coincident properties of "band" according to
Expand Down Expand Up @@ -510,7 +501,7 @@ static __isl_give isl_schedule_tree *read_band(isl_stream *s)
isl_ctx *ctx;
isl_schedule_band *band;
int permutable = 0;
int more;
isl_bool more;

ctx = isl_stream_get_ctx(s);

Expand Down Expand Up @@ -570,7 +561,7 @@ static __isl_give isl_schedule_tree *read_band(isl_stream *s)
isl_die(ctx, isl_error_invalid, "unexpected key",
goto error);
}
} while ((more = isl_stream_yaml_next(s)) > 0);
} while ((more = isl_stream_yaml_next(s)) == isl_bool_true);

if (more < 0)
goto error;
Expand Down Expand Up @@ -598,36 +589,25 @@ static __isl_give isl_schedule_tree *read_band(isl_stream *s)
return NULL;
}

#undef EL_BASE
#define EL_BASE schedule_tree

#include <isl_list_read_yaml_templ.c>

/* Read a subtree with root node of type "type" from "s".
* The node is represented by a sequence of children.
*/
static __isl_give isl_schedule_tree *read_children(isl_stream *s,
enum isl_schedule_node_type type)
{
isl_ctx *ctx;
isl_schedule_tree_list *list;
int more;

ctx = isl_stream_get_ctx(s);

isl_token_free(isl_stream_next_token(s));

if (isl_stream_yaml_next(s) < 0)
return NULL;

if (isl_stream_yaml_read_start_sequence(s))
return NULL;

list = isl_schedule_tree_list_alloc(ctx, 0);
while ((more = isl_stream_yaml_next(s)) > 0) {
isl_schedule_tree *tree;

tree = isl_stream_read_schedule_tree(s);
list = isl_schedule_tree_list_add(list, tree);
}

if (more < 0 || isl_stream_yaml_read_end_sequence(s))
list = isl_schedule_tree_list_free(list);
list = isl_stream_yaml_read_schedule_tree_list(s);

return isl_schedule_tree_from_children(type, list);
}
Expand Down Expand Up @@ -658,9 +638,9 @@ static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
enum isl_schedule_key key;
struct isl_token *tok;
isl_schedule_tree *tree = NULL;
int more;
isl_bool more;

if (isl_stream_yaml_read_start_mapping(s))
if (isl_stream_yaml_read_start_mapping(s) < 0)
return NULL;
more = isl_stream_yaml_next(s);
if (more < 0)
Expand Down Expand Up @@ -722,10 +702,8 @@ static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
return NULL;
}

if (isl_stream_yaml_read_end_mapping(s) < 0) {
isl_stream_error(s, NULL, "unexpected extra elements");
if (isl_stream_yaml_read_end_mapping(s) < 0)
return isl_schedule_tree_free(tree);
}

return tree;
}
Expand Down Expand Up @@ -761,19 +739,6 @@ __isl_give isl_schedule *isl_schedule_read_from_file(isl_ctx *ctx, FILE *input)
return schedule;
}

/* Read an isl_schedule from "str".
*/
__isl_give isl_schedule *isl_schedule_read_from_str(isl_ctx *ctx,
const char *str)
{
struct isl_stream *s;
isl_schedule *schedule;

s = isl_stream_new_str(ctx, str);
if (!s)
return NULL;
schedule = isl_stream_read_schedule(s);
isl_stream_free(s);

return schedule;
}
#undef TYPE_BASE
#define TYPE_BASE schedule
#include "isl_read_from_str_templ.c"
2 changes: 1 addition & 1 deletion polly/lib/External/isl/isl_schedule_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static __isl_give isl_schedule_tree *isl_schedule_tree_alloc(isl_ctx *ctx,

/* Return a fresh copy of "tree".
*/
__isl_take isl_schedule_tree *isl_schedule_tree_dup(
__isl_give isl_schedule_tree *isl_schedule_tree_dup(
__isl_keep isl_schedule_tree *tree)
{
isl_ctx *ctx;
Expand Down
Loading