#include <stdlib.h>
#include <isl_dim_private.h>
#include "isl_name.h"
+#include <isl_reordering.h>
isl_ctx *isl_dim_get_ctx(__isl_keep isl_dim *dim)
{
case isl_dim_out:
return isl_dim_extend(dim,
dim->nparam, dim->n_in, dim->n_out + n);
+ default:
+ isl_die(dim->ctx, isl_error_invalid,
+ "cannot add dimensions of specified type", goto error);
}
- return dim;
error:
isl_dim_free(dim);
return NULL;
}
+static int valid_dim_type(enum isl_dim_type type)
+{
+ switch (type) {
+ case isl_dim_param:
+ case isl_dim_in:
+ case isl_dim_out:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
__isl_give isl_dim *isl_dim_insert(__isl_take isl_dim *dim,
enum isl_dim_type type, unsigned pos, unsigned n)
{
if (n == 0)
return isl_dim_reset(dim, type);
+ if (!valid_dim_type(type))
+ isl_die(dim->ctx, isl_error_invalid,
+ "cannot insert dimensions of specified type",
+ goto error);
+
isl_assert(dim->ctx, pos <= isl_dim_size(dim, type), goto error);
dim = isl_dim_cow(dim);
case isl_dim_param: dim->nparam += n; break;
case isl_dim_in: dim->n_in += n; break;
case isl_dim_out: dim->n_out += n; break;
+ default: ;
}
dim = isl_dim_reset(dim, type);
case isl_dim_param: dim->nparam += n; break;
case isl_dim_in: dim->n_in += n; break;
case isl_dim_out: dim->n_out += n; break;
+ default: ;
}
switch (src_type) {
case isl_dim_param: dim->nparam -= n; break;
case isl_dim_in: dim->n_in -= n; break;
case isl_dim_out: dim->n_out -= n; break;
+ default: ;
}
if (dst_type != isl_dim_param && src_type != isl_dim_param)
if (!dim)
return NULL;
- if (n == 0)
+ if (num == 0)
return isl_dim_reset(dim, type);
+ if (!valid_dim_type(type))
+ isl_die(dim->ctx, isl_error_invalid,
+ "cannot drop dimensions of specified type", goto error);
+
isl_assert(dim->ctx, first + num <= n(dim, type), goto error);
dim = isl_dim_cow(dim);
if (!dim)
case isl_dim_in:
get_names(dim, isl_dim_out, 0, dim->n_out,
dim->names + offset(dim, isl_dim_out) - num);
- case isl_dim_out:
+ default:
;
}
dim->n_name -= num;
case isl_dim_param: dim->nparam -= num; break;
case isl_dim_in: dim->n_in -= num; break;
case isl_dim_out: dim->n_out -= num; break;
+ default: ;
}
dim = isl_dim_reset(dim, type);
if (type == isl_dim_param) {
return dim;
}
+__isl_give isl_dim *isl_dim_flatten_range(__isl_take isl_dim *dim)
+{
+ if (!dim)
+ return NULL;
+ if (!dim->nested[1])
+ return dim;
+
+ return isl_dim_reset(dim, isl_dim_out);
+}
+
/* Replace the dimensions of the given type of dst by those of src.
*/
__isl_give isl_dim *isl_dim_replace(__isl_take isl_dim *dst,
return 0;
return 1;
}
+
+/* Align the initial parameters of dim1 to match the order in dim2.
+ */
+__isl_give isl_dim *isl_dim_align_params(__isl_take isl_dim *dim1,
+ __isl_take isl_dim *dim2)
+{
+ isl_reordering *exp;
+
+ if (!isl_dim_has_named_params(dim1) || !isl_dim_has_named_params(dim2))
+ isl_die(isl_dim_get_ctx(dim1), isl_error_invalid,
+ "parameter alignment requires named parameters",
+ goto error);
+
+ exp = isl_parameter_alignment_reordering(dim1, dim2);
+ isl_dim_free(dim1);
+ isl_dim_free(dim2);
+ if (!exp)
+ return NULL;
+ dim1 = isl_dim_copy(exp->dim);
+ isl_reordering_free(exp);
+ return dim1;
+error:
+ isl_dim_free(dim1);
+ isl_dim_free(dim2);
+ return NULL;
+}