if (!dim)
return NULL;
dup = isl_space_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out);
+ if (!dup)
+ return NULL;
if (dim->tuple_id[0] &&
!(dup->tuple_id[0] = isl_id_copy(dim->tuple_id[0])))
goto error;
return dim;
}
-void isl_space_free(__isl_take isl_space *dim)
+void *isl_space_free(__isl_take isl_space *dim)
{
int i;
if (!dim)
- return;
+ return NULL;
if (--dim->ref > 0)
- return;
+ return NULL;
isl_id_free(dim->tuple_id[0]);
isl_id_free(dim->tuple_id[1]);
isl_ctx_deref(dim->ctx);
free(dim);
+
+ return NULL;
}
/* Check if "s" is a valid dimension or tuple name.
isl_assert(dim->ctx, dim->n_out <= n_out, goto error);
dim = isl_space_cow(dim);
+ if (!dim)
+ goto error;
if (dim->ids) {
ids = isl_calloc_array(dim->ctx, isl_id *,
if (!dim)
return hash;
- hash = isl_hash_builtin(hash, dim->nparam);
- hash = isl_hash_builtin(hash, dim->n_in);
- hash = isl_hash_builtin(hash, dim->n_out);
+ isl_hash_byte(hash, dim->nparam % 256);
+ isl_hash_byte(hash, dim->n_in % 256);
+ isl_hash_byte(hash, dim->n_out % 256);
for (i = 0; i < dim->nparam; ++i) {
id = get_id(dim, isl_dim_param, i);
return NULL;
}
+/* Can we apply isl_space_uncurry to "space"?
+ * That is, does it have a nested relation in its range?
+ */
+int isl_space_can_uncurry(__isl_keep isl_space *space)
+{
+ if (!space)
+ return -1;
+
+ return !!space->nested[1];
+}
+
+/* Given a space A -> (B -> C), return the corresponding space
+ * (A -> B) -> C.
+ */
+__isl_give isl_space *isl_space_uncurry(__isl_take isl_space *space)
+{
+ isl_space *dom, *ran;
+ isl_space *ran_dom, *ran_ran;
+
+ if (!space)
+ return NULL;
+
+ if (!isl_space_can_uncurry(space))
+ isl_die(space->ctx, isl_error_invalid,
+ "space cannot be uncurried",
+ return isl_space_free(space));
+
+ dom = isl_space_domain(isl_space_copy(space));
+ ran = isl_space_unwrap(isl_space_range(space));
+ ran_dom = isl_space_domain(isl_space_copy(ran));
+ ran_ran = isl_space_range(ran);
+ dom = isl_space_join(isl_space_from_domain(dom),
+ isl_space_from_range(ran_dom));
+ return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)),
+ isl_space_from_range(ran_ran));
+}
+
int isl_space_has_named_params(__isl_keep isl_space *dim)
{
int i;