struct UNION {
int ref;
+#ifdef HAS_TYPE
+ enum isl_fold type;
+#endif
isl_dim *dim;
struct isl_hash_table table;
return isl_dim_copy(u->dim);
}
+#ifdef HAS_TYPE
+static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim,
+ enum isl_fold type, int size)
+#else
static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_dim *dim, int size)
+#endif
{
UNION *u;
+ if (!dim)
+ return NULL;
+
u = isl_calloc_type(ctx, UNION);
if (!u)
return NULL;
u->ref = 1;
+#ifdef HAS_TYPE
+ u->type = type;
+#endif
u->dim = dim;
if (isl_hash_table_init(dim->ctx, &u->table, size) < 0)
goto error;
return NULL;
}
+#ifdef HAS_TYPE
+__isl_give UNION *FN(UNION,zero)(__isl_take isl_dim *dim, enum isl_fold type)
+{
+ return FN(UNION,alloc)(dim, type, 16);
+}
+#else
__isl_give UNION *FN(UNION,zero)(__isl_take isl_dim *dim)
{
return FN(UNION,alloc)(dim, 16);
}
+#endif
__isl_give UNION *FN(UNION,copy)(__isl_keep UNION *u)
{
return isl_dim_equal(part->dim, dim);
}
+__isl_give PART *FN(FN(UNION,extract),PARTS)(__isl_keep UNION *u,
+ __isl_take isl_dim *dim)
+{
+ uint32_t hash;
+ struct isl_hash_table_entry *entry;
+
+ if (!u || !dim)
+ goto error;
+
+ hash = isl_dim_get_hash(dim);
+ entry = isl_hash_table_find(u->dim->ctx, &u->table, hash,
+ &has_dim, dim, 0);
+ if (!entry)
+#ifdef HAS_TYPE
+ return FN(PART,zero)(dim, u->type);
+#else
+ return FN(PART,zero)(dim);
+#endif
+ isl_dim_free(dim);
+ return FN(PART,copy)(entry->data);
+error:
+ isl_dim_free(dim);
+ return NULL;
+}
+
__isl_give UNION *FN(FN(UNION,add),PARTS)(__isl_take UNION *u,
__isl_take PART *part)
{
if (!u)
return NULL;
+#ifdef HAS_TYPE
+ dup = FN(UNION,zero)(isl_dim_copy(u->dim), u->type);
+#else
dup = FN(UNION,zero)(isl_dim_copy(u->dim));
+#endif
if (FN(FN(UNION,foreach),PARTS)(u, &add_part, &dup) < 0)
goto error;
return dup;
free(u);
}
+S(UNION,align) {
+ isl_reordering *exp;
+ UNION *res;
+};
+
+static int align_entry(__isl_take PART *part, void *user)
+{
+ isl_reordering *exp;
+ S(UNION,align) *data = user;
+
+ exp = isl_reordering_extend_dim(isl_reordering_copy(data->exp),
+ FN(PART,get_dim)(part));
+
+ data->res = FN(FN(UNION,add),PARTS)(data->res,
+ FN(PART,realign)(part, exp));
+
+ return 0;
+}
+
+__isl_give UNION *FN(UNION,align_params)(__isl_take UNION *u,
+ __isl_take isl_dim *model)
+{
+ int i, j;
+ S(UNION,align) data = { NULL, NULL };
+
+ if (!u || !model)
+ goto error;
+
+ if (isl_dim_match(u->dim, isl_dim_param, model, isl_dim_param)) {
+ isl_dim_free(model);
+ return u;
+ }
+
+ data.exp = isl_parameter_alignment_reordering(u->dim, model);
+ if (!data.exp)
+ goto error;
+
+#ifdef HAS_TYPE
+ data.res = FN(UNION,alloc)(isl_dim_copy(data.exp->dim),
+ u->type, u->table.n);
+#else
+ data.res = FN(UNION,alloc)(isl_dim_copy(data.exp->dim), u->table.n);
+#endif
+ if (FN(FN(UNION,foreach),PARTS)(u, &align_entry, &data) < 0)
+ goto error;
+
+ isl_reordering_free(data.exp);
+ FN(UNION,free)(u);
+ isl_dim_free(model);
+ return data.res;
+error:
+ isl_reordering_free(data.exp);
+ FN(UNION,free)(u);
+ FN(UNION,free)(data.res);
+ isl_dim_free(model);
+ return NULL;
+}
+
__isl_give UNION *FN(UNION,add)(__isl_take UNION *u1, __isl_take UNION *u2)
{
+ u1 = FN(UNION,align_params)(u1, FN(UNION,get_dim)(u2));
+ u2 = FN(UNION,align_params)(u2, FN(UNION,get_dim)(u1));
+
u1 = FN(UNION,cow)(u1);
if (!u1 || !u2)
dim = FN(PART,get_dim)(part);
dim = isl_dim_drop(dim, isl_dim_in, 0, isl_dim_size(dim, isl_dim_in));
dim = isl_dim_drop(dim, isl_dim_out, 0, isl_dim_size(dim, isl_dim_out));
+#ifdef HAS_TYPE
+ u = FN(UNION,zero)(dim, part->type);
+#else
u = FN(UNION,zero)(dim);
+#endif
u = FN(FN(UNION,add),PARTS)(u, part);
return u;
}
S(UNION,match_bin_data) {
- UNION *upwqp2;
+ UNION *u2;
UNION *res;
};
static __isl_give UNION *match_bin_op(__isl_take UNION *u1,
__isl_take UNION *u2, int (*fn)(void **, void *))
{
- S(UNION,match_bin_data) data = { u2, NULL };
+ S(UNION,match_bin_data) data = { NULL, NULL };
+
+ u1 = FN(UNION,align_params)(u1, FN(UNION,get_dim)(u2));
+ u2 = FN(UNION,align_params)(u2, FN(UNION,get_dim)(u1));
if (!u1 || !u2)
goto error;
+ data.u2 = u2;
+#ifdef HAS_TYPE
+ data.res = FN(UNION,alloc)(isl_dim_copy(u1->dim), u1->type, u1->table.n);
+#else
data.res = FN(UNION,alloc)(isl_dim_copy(u1->dim), u1->table.n);
+#endif
if (isl_hash_table_foreach(u1->dim->ctx, &u1->table, fn, &data) < 0)
goto error;
__isl_take isl_union_set *uset,
__isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*))
{
- S(UNION,match_set_data) data = { uset, NULL, fn };
+ S(UNION,match_set_data) data = { NULL, NULL, fn };
+
+ u = FN(UNION,align_params)(u, isl_union_set_get_dim(uset));
+ uset = isl_union_set_align_params(uset, FN(UNION,get_dim)(u));
if (!u || !uset)
goto error;
+ data.uset = uset;
+#ifdef HAS_TYPE
+ data.res = FN(UNION,alloc)(isl_dim_copy(u->dim), u->type, u->table.n);
+#else
data.res = FN(UNION,alloc)(isl_dim_copy(u->dim), u->table.n);
+#endif
if (isl_hash_table_foreach(u->dim->ctx, &u->table,
&match_set_entry, &data) < 0)
goto error;