return dim;
}
+/* Mark the space as being that of a set, by setting the domain tuple
+ * to isl_id_none.
+ */
+static __isl_give isl_space *mark_as_set(__isl_take isl_space *space)
+{
+ space = isl_space_cow(space);
+ if (!space)
+ return NULL;
+ space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none);
+ return space;
+}
+
+/* Is the space that of a set?
+ */
+int isl_space_is_set(__isl_keep isl_space *space)
+{
+ if (!space)
+ return -1;
+ if (space->n_in != 0 || space->nested[0])
+ return 0;
+ if (space->tuple_id[0] != &isl_id_none)
+ return 0;
+ return 1;
+}
+
__isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx,
unsigned nparam, unsigned dim)
{
- return isl_space_alloc(ctx, nparam, 0, dim);
+ isl_space *space;
+ space = isl_space_alloc(ctx, nparam, 0, dim);
+ space = mark_as_set(space);
+ return space;
+}
+
+/* Mark the space as being that of a parameter domain, by setting
+ * both tuples to isl_id_none.
+ */
+static __isl_give isl_space *mark_as_params(isl_space *space)
+{
+ if (!space)
+ return NULL;
+ space = isl_space_set_tuple_id(space, isl_dim_in, &isl_id_none);
+ space = isl_space_set_tuple_id(space, isl_dim_out, &isl_id_none);
+ return space;
+}
+
+/* Is the space that of a parameter domain?
+ */
+int isl_space_is_params(__isl_keep isl_space *space)
+{
+ if (!space)
+ return -1;
+ if (space->n_in != 0 || space->nested[0] ||
+ space->n_out != 0 || space->nested[1])
+ return 0;
+ if (space->tuple_id[0] != &isl_id_none)
+ return 0;
+ if (space->tuple_id[1] != &isl_id_none)
+ return 0;
+ return 1;
+}
+
+/* Create a space for a parameter domain.
+ */
+__isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx, unsigned nparam)
+{
+ isl_space *space;
+ space = isl_space_alloc(ctx, nparam, 0, 0);
+ space = mark_as_params(space);
+ return space;
}
static unsigned global_pos(__isl_keep isl_space *dim,
{
if (!dim)
return -1;
+ if (isl_space_is_params(dim))
+ isl_die(dim->ctx, isl_error_invalid,
+ "parameter spaces don't have tuple ids", return -1);
+ if (isl_space_is_set(dim) && type != isl_dim_set)
+ isl_die(dim->ctx, isl_error_invalid,
+ "set spaces can only have a set id", return -1);
if (type != isl_dim_in && type != isl_dim_out)
isl_die(dim->ctx, isl_error_invalid,
"only input, output and set tuples can have ids",
__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim,
enum isl_dim_type type)
{
+ int has_id;
+
if (!dim)
return NULL;
- if (type != isl_dim_in && type != isl_dim_out)
- isl_die(dim->ctx, isl_error_invalid,
- "only input, output and set tuples can have ids",
- return NULL);
- if (!dim->tuple_id[type - isl_dim_in])
+ has_id = isl_space_has_tuple_id(dim, type);
+ if (has_id < 0)
+ return NULL;
+ if (!has_id)
isl_die(dim->ctx, isl_error_invalid,
"tuple has no id", return NULL);
return isl_id_copy(dim->tuple_id[type - isl_dim_in]);
return NULL;
}
-__isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *dim,
+/* Set the id of the given dimension of "space" to "id".
+ * If the dimension already has an id, then it is replaced.
+ * If the dimension is a parameter, then we need to change it
+ * in the nested spaces (if any) as well.
+ */
+__isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *space,
enum isl_dim_type type, unsigned pos, __isl_take isl_id *id)
{
- dim = isl_space_cow(dim);
- if (!dim || !id)
+ space = isl_space_cow(space);
+ if (!space || !id)
goto error;
- isl_id_free(get_id(dim, type, pos));
- return set_id(dim, type, pos, id);
+
+ if (type == isl_dim_param) {
+ int i;
+
+ for (i = 0; i < 2; ++i) {
+ if (!space->nested[i])
+ continue;
+ space->nested[i] =
+ isl_space_set_dim_id(space->nested[i],
+ type, pos, isl_id_copy(id));
+ if (!space->nested[i])
+ goto error;
+ }
+ }
+
+ isl_id_free(get_id(space, type, pos));
+ return set_id(space, type, pos, id);
error:
isl_id_free(id);
- isl_space_free(dim);
+ isl_space_free(space);
+ return NULL;
+}
+
+/* Reset the id of the given dimension of "space".
+ * If the dimension already has an id, then it is removed.
+ * If the dimension is a parameter, then we need to reset it
+ * in the nested spaces (if any) as well.
+ */
+__isl_give isl_space *isl_space_reset_dim_id(__isl_take isl_space *space,
+ enum isl_dim_type type, unsigned pos)
+{
+ space = isl_space_cow(space);
+ if (!space)
+ goto error;
+
+ if (type == isl_dim_param) {
+ int i;
+
+ for (i = 0; i < 2; ++i) {
+ if (!space->nested[i])
+ continue;
+ space->nested[i] =
+ isl_space_reset_dim_id(space->nested[i],
+ type, pos);
+ if (!space->nested[i])
+ goto error;
+ }
+ }
+
+ isl_id_free(get_id(space, type, pos));
+ return set_id(space, type, pos, NULL);
+error:
+ isl_space_free(space);
return NULL;
}
if (!dim)
return NULL;
+ if (!s)
+ return isl_space_reset_dim_id(dim, type, pos);
if (!name_ok(dim->ctx, s))
goto error;
id = isl_id_alloc(dim->ctx, s, NULL);
return -1;
}
+int isl_space_find_dim_by_name(__isl_keep isl_space *space,
+ enum isl_dim_type type, const char *name)
+{
+ int i;
+ int offset;
+ int n;
+
+ if (!space || !name)
+ return -1;
+
+ offset = isl_space_offset(space, type);
+ n = isl_space_dim(space, type);
+ for (i = 0; i < n && offset + i < space->n_id; ++i)
+ if (space->ids[offset + i]->name &&
+ !strcmp(space->ids[offset + i]->name, name))
+ return i;
+
+ return -1;
+}
+
static __isl_keep isl_id *tuple_id(__isl_keep isl_space *dim,
enum isl_dim_type type)
{
if (!dim1 || !dim2)
return -1;
+ if (dim1 == dim2 && dim1_type == dim2_type)
+ return 1;
+
if (n(dim1, dim1_type) != n(dim2, dim2_type))
return 0;
id1 = tuple_id(dim1, dim1_type);
{
int i;
+ if (dim1 == dim2 && dim1_type == dim2_type)
+ return 1;
+
if (!isl_space_tuple_match(dim1, dim1_type, dim2, dim2_type))
return 0;
int isl_space_match(__isl_keep isl_space *dim1, enum isl_dim_type dim1_type,
__isl_keep isl_space *dim2, enum isl_dim_type dim2_type)
{
+ if (!dim1 || !dim2)
+ return -1;
+
return match(dim1, dim1_type, dim2, dim2_type);
}
__isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *dim)
{
+ isl_ctx *ctx;
isl_id **ids = NULL;
if (!dim)
return NULL;
- isl_assert(dim->ctx, dim->n_in == 0, goto error);
- if (dim->n_out == 0 && !isl_space_is_named_or_nested(dim, isl_dim_out))
- return dim;
+ ctx = isl_space_get_ctx(dim);
+ if (!isl_space_is_set(dim))
+ isl_die(ctx, isl_error_invalid, "not a set space", goto error);
dim = isl_space_cow(dim);
if (!dim)
return NULL;
return NULL;
}
+__isl_give isl_space *isl_space_map_from_domain_and_range(
+ __isl_take isl_space *domain, __isl_take isl_space *range)
+{
+ if (!domain || !range)
+ goto error;
+ if (!isl_space_is_set(domain))
+ isl_die(isl_space_get_ctx(domain), isl_error_invalid,
+ "domain is not a set space", goto error);
+ if (!isl_space_is_set(range))
+ isl_die(isl_space_get_ctx(range), isl_error_invalid,
+ "range is not a set space", goto error);
+ return isl_space_join(isl_space_reverse(domain), range);
+error:
+ isl_space_free(domain);
+ isl_space_free(range);
+ return NULL;
+}
+
static __isl_give isl_space *set_ids(__isl_take isl_space *dim,
enum isl_dim_type type,
unsigned first, unsigned n, __isl_take isl_id **ids)
if (!dim)
return NULL;
dim = isl_space_drop_outputs(dim, 0, dim->n_out);
- return isl_space_reverse(dim);
+ dim = isl_space_reverse(dim);
+ dim = mark_as_set(dim);
+ return dim;
}
__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim)
{
- return isl_space_reverse(dim);
+ if (!dim)
+ return NULL;
+ if (!isl_space_is_set(dim))
+ isl_die(isl_space_get_ctx(dim), isl_error_invalid,
+ "not a set space", goto error);
+ dim = isl_space_reverse(dim);
+ dim = isl_space_reset(dim, isl_dim_out);
+ return dim;
+error:
+ isl_space_free(dim);
+ return NULL;
}
__isl_give isl_space *isl_space_range(__isl_take isl_space *dim)
{
if (!dim)
return NULL;
- return isl_space_drop_inputs(dim, 0, dim->n_in);
+ dim = isl_space_drop_inputs(dim, 0, dim->n_in);
+ dim = mark_as_set(dim);
+ return dim;
}
__isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim)
{
- return dim;
+ if (!dim)
+ return NULL;
+ if (!isl_space_is_set(dim))
+ isl_die(isl_space_get_ctx(dim), isl_error_invalid,
+ "not a set space", goto error);
+ return isl_space_reset(dim, isl_dim_in);
+error:
+ isl_space_free(dim);
+ return NULL;
}
__isl_give isl_space *isl_space_params(__isl_take isl_space *space)
{
+ if (isl_space_is_params(space))
+ return space;
space = isl_space_drop_dims(space,
isl_dim_in, 0, isl_space_dim(space, isl_dim_in));
space = isl_space_drop_dims(space,
isl_dim_out, 0, isl_space_dim(space, isl_dim_out));
+ space = mark_as_params(space);
return space;
}
+__isl_give isl_space *isl_space_set_from_params(__isl_take isl_space *space)
+{
+ if (!space)
+ return NULL;
+ if (!isl_space_is_params(space))
+ isl_die(isl_space_get_ctx(space), isl_error_invalid,
+ "not a parameter space", goto error);
+ return isl_space_reset(space, isl_dim_set);
+error:
+ isl_space_free(space);
+ return NULL;
+}
+
__isl_give isl_space *isl_space_as_set_space(__isl_take isl_space *dim)
{
dim = isl_space_cow(dim);
{
if (!dim1 || !dim2)
return -1;
+ if (dim1 == dim2)
+ return 1;
return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
isl_space_tuple_match(dim1, isl_dim_in, dim2, isl_dim_in) &&
isl_space_tuple_match(dim1, isl_dim_out, dim2, isl_dim_out);
}
+/* Is space1 equal to the domain of space2?
+ */
+int isl_space_is_domain(__isl_keep isl_space *space1,
+ __isl_keep isl_space *space2)
+{
+ if (!space1 || !space2)
+ return -1;
+ if (!isl_space_is_set(space1))
+ return 0;
+ return match(space1, isl_dim_param, space2, isl_dim_param) &&
+ isl_space_tuple_match(space1, isl_dim_set, space2, isl_dim_in);
+}
+
int isl_space_compatible(__isl_keep isl_space *dim1,
__isl_keep isl_space *dim2)
{
if (!dim)
return -1;
- if (dim->n_in != 0 || dim->tuple_id[0] || dim->nested[0])
+ if (!isl_space_is_set(dim))
return 0;
return dim->nested[1] != NULL;
if (!dim)
return NULL;
- wrap = isl_space_alloc(dim->ctx, dim->nparam, 0, dim->n_in + dim->n_out);
+ wrap = isl_space_set_alloc(dim->ctx,
+ dim->nparam, dim->n_in + dim->n_out);
wrap = copy_ids(wrap, isl_dim_param, 0, dim, isl_dim_param);
wrap = copy_ids(wrap, isl_dim_set, 0, dim, isl_dim_in);
{
if (!dim)
return -1;
+ if (isl_space_is_set(dim))
+ return 1;
if (isl_space_dim(dim, isl_dim_in) != 0)
return 0;
if (isl_space_is_named_or_nested(dim, isl_dim_in))
isl_space_free(dim2);
return NULL;
}
+
+/* Given the space of set (domain), construct a space for a map
+ * with as domain the given space and as range the range of "model".
+ */
+__isl_give isl_space *isl_space_extend_domain_with_range(
+ __isl_take isl_space *domain, __isl_take isl_space *model)
+{
+ isl_space *space;
+
+ space = isl_space_from_domain(domain);
+ space = isl_space_add_dims(space, isl_dim_out,
+ isl_space_dim(model, isl_dim_out));
+ if (isl_space_has_tuple_id(model, isl_dim_out))
+ space = isl_space_set_tuple_id(space, isl_dim_out,
+ isl_space_get_tuple_id(model, isl_dim_out));
+ isl_space_free(model);
+ return space;
+}