-#include "isl_dim.h"
+/*
+ * Copyright 2008-2009 Katholieke Universiteit Leuven
+ *
+ * Use of this software is governed by the GNU LGPLv2.1 license
+ *
+ * Written by Sven Verdoolaege, K.U.Leuven, Departement
+ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
+ */
+
+#include <isl_dim_private.h>
#include "isl_name.h"
struct isl_dim *isl_dim_alloc(struct isl_ctx *ctx,
return isl_dim_total(dim);
}
+/* Extend length of names array to the total number of dimensions.
+ */
+static __isl_give isl_dim *extend_names(__isl_take isl_dim *dim)
+{
+ struct isl_name **names;
+ int i;
+
+ if (isl_dim_total(dim) <= dim->n_name)
+ return dim;
+
+ if (!dim->names) {
+ dim->names = isl_calloc_array(dim->ctx,
+ struct isl_name *, isl_dim_total(dim));
+ if (!dim->names)
+ goto error;
+ } else {
+ names = isl_realloc_array(dim->ctx, dim->names,
+ struct isl_name *, isl_dim_total(dim));
+ if (!names)
+ goto error;
+ dim->names = names;
+ for (i = dim->n_name; i < isl_dim_total(dim); ++i)
+ dim->names[i] = NULL;
+ }
+
+ dim->n_name = isl_dim_total(dim);
+
+ return dim;
+error:
+ isl_dim_free(dim);
+ return NULL;
+}
+
static struct isl_dim *set_name(struct isl_dim *dim,
enum isl_dim_type type, unsigned pos,
struct isl_name *name)
if (pos >= dim->n_name) {
if (!name)
return dim;
- if (!dim->names) {
- dim->names = isl_calloc_array(dim->ctx,
- struct isl_name *, isl_dim_total(dim));
- if (!dim->names)
- goto error;
- } else {
- int i;
- dim->names = isl_realloc_array(dim->ctx, dim->names,
- struct isl_name *, isl_dim_total(dim));
- if (!dim->names)
- goto error;
- for (i = dim->n_name; i < isl_dim_total(dim); ++i)
- dim->names[i] = NULL;
- }
- dim->n_name = isl_dim_total(dim);
+ dim = extend_names(dim);
+ if (!dim)
+ goto error;
}
dim->names[pos] = name;
return dim;
}
+__isl_give isl_dim *isl_dim_move(__isl_take isl_dim *dim,
+ enum isl_dim_type dst_type, unsigned dst_pos,
+ enum isl_dim_type src_type, unsigned src_pos, unsigned n)
+{
+ if (!dim)
+ return NULL;
+ if (n == 0)
+ return dim;
+
+ isl_assert(dim->ctx, src_pos + n <= isl_dim_size(dim, src_type),
+ goto error);
+
+ /* just the simple case for now */
+ isl_assert(dim->ctx,
+ offset(dim, dst_type) + dst_pos ==
+ offset(dim, src_type) + src_pos + ((src_type < dst_type) ? n : 0),
+ goto error);
+
+ if (dst_type == src_type)
+ return dim;
+
+ dim = isl_dim_cow(dim);
+ if (!dim)
+ return NULL;
+
+ switch (dst_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;
+ }
+
+ 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;
+ }
+
+ return dim;
+error:
+ isl_dim_free(dim);
+ return NULL;
+}
+
struct isl_dim *isl_dim_join(struct isl_dim *left, struct isl_dim *right)
{
struct isl_dim *dim;
isl_assert(left->ctx, match(left, isl_dim_param, right, isl_dim_param),
goto error);
- isl_assert(left->ctx, match(left, isl_dim_out, right, isl_dim_in),
+ isl_assert(left->ctx, n(left, isl_dim_out) == n(right, isl_dim_in),
goto error);
dim = isl_dim_alloc(left->ctx, left->nparam, left->n_in, right->n_out);
}
dim->n_in = dim->n_out;
if (names) {
- copy_names(dim, isl_dim_out, 0, dim, isl_dim_in);
free(dim->names);
dim->names = names;
dim->n_name = dim->nparam + dim->n_out + dim->n_out;
+ dim = copy_names(dim, isl_dim_out, 0, dim, isl_dim_in);
}
return dim;
error:
if (!dim)
goto error;
if (dim->names) {
+ dim = extend_names(dim);
+ if (!dim)
+ goto error;
for (i = 0; i < num; ++i)
isl_name_free(dim->ctx, get_name(dim, type, first+i));
for (i = first+num; i < n(dim, type); ++i)
case isl_dim_out:
;
}
+ dim->n_name -= num;
}
switch (type) {
case isl_dim_param: dim->nparam -= num; break;
int isl_dim_equal(struct isl_dim *dim1, struct isl_dim *dim2)
{
return match(dim1, isl_dim_param, dim2, isl_dim_param) &&
- match(dim1, isl_dim_in, dim2, isl_dim_in) &&
- match(dim1, isl_dim_out, dim2, isl_dim_out);
+ n(dim1, isl_dim_in) == n(dim2, isl_dim_in) &&
+ n(dim1, isl_dim_out) == n(dim2, isl_dim_out);
}
int isl_dim_compatible(struct isl_dim *dim1, struct isl_dim *dim2)