#include <isl_mat_private.h>
#include <isl/union_map.h>
#include <isl/constraint.h>
+#include <isl_local_space_private.h>
+#include <isl_aff_private.h>
static const char *s_to[2] = { " -> ", " \\to " };
static const char *s_and[2] = { " and ", " \\wedge " };
{
int i, n;
struct isl_aff_split *split;
+ isl_ctx *ctx;
- split = isl_calloc_array(map->isl, struct isl_aff_split, map->n);
+ ctx = isl_map_get_ctx(map);
+ split = isl_calloc_array(ctx, struct isl_aff_split, map->n);
if (!split)
return NULL;
-
+
for (i = 0; i < map->n; ++i) {
isl_basic_map *bmap;
split[i].aff = get_aff(isl_basic_map_copy(map->p[i]));
__isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
{
enum isl_dim_type type;
- unsigned nparam = isl_basic_set_dim(bset, isl_dim_param);
if (pos == 0)
return isl_printer_print_isl_int(p, c);
isl_printer_free(printer);
}
+
+__isl_give isl_printer *isl_printer_print_dim(__isl_take isl_printer *p,
+ __isl_keep isl_dim *dim)
+{
+ if (!dim)
+ goto error;
+
+ if (isl_dim_size(dim, isl_dim_param) > 0) {
+ p = print_tuple(dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+
+ p = isl_printer_print_str(p, "{ ");
+ p = print_tuple(dim, p, isl_dim_in, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ p = print_tuple(dim, p, isl_dim_out, 0, 0, NULL);
+ p = isl_printer_print_str(p, " }");
+
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_dim_dump(__isl_keep isl_dim *dim)
+{
+ isl_printer *printer;
+
+ if (!dim)
+ return;
+
+ printer = isl_printer_to_file(isl_dim_get_ctx(dim), stderr);
+ printer = isl_printer_print_dim(printer, dim);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+__isl_give isl_printer *isl_printer_print_local_space(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls)
+{
+ unsigned total;
+ unsigned n_div;
+
+ if (!ls)
+ goto error;
+
+ total = isl_local_space_dim(ls, isl_dim_all);
+ if (isl_local_space_dim(ls, isl_dim_param) > 0) {
+ p = print_tuple(ls->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ p = print_tuple(ls->dim, p, isl_dim_in, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ p = print_tuple(ls->dim, p, isl_dim_out, 0, 0, NULL);
+ n_div = isl_local_space_dim(ls, isl_dim_div);
+ if (n_div > 0) {
+ int i;
+ p = isl_printer_print_str(p, " : ");
+ p = isl_printer_print_str(p, s_open_exists[0]);
+ for (i = 0; i < n_div; ++i) {
+ if (i)
+ p = isl_printer_print_str(p, ", ");
+ p = print_name(ls->dim, p, isl_dim_div, i, 0, 0);
+ if (isl_int_is_zero(ls->div->row[i][0]))
+ continue;
+ p = isl_printer_print_str(p, " = [(");
+ p = print_affine_of_len(ls->dim, ls->div, p,
+ ls->div->row[i] + 1, 1 + total, 0);
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, ls->div->row[i][0]);
+ p = isl_printer_print_str(p, "]");
+ }
+ }
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_local_space_dump(__isl_keep isl_local_space *ls)
+{
+ isl_printer *printer;
+
+ if (!ls)
+ return;
+
+ printer = isl_printer_to_file(isl_local_space_get_ctx(ls), stderr);
+ printer = isl_printer_print_local_space(printer, ls);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+static __isl_give isl_printer *print_aff(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ unsigned total;
+
+ total = isl_local_space_dim(aff->ls, isl_dim_all);
+ p = print_tuple(aff->ls->dim, p, isl_dim_set, 1, 0, NULL);
+ p = isl_printer_print_str(p, " -> [");
+ p = isl_printer_print_str(p, "(");
+ p = print_affine_of_len(aff->ls->dim, aff->ls->div, p,
+ aff->v->el + 1, 1 + total, 1);
+ if (isl_int_is_one(aff->v->el[0]))
+ p = isl_printer_print_str(p, ")");
+ else {
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, aff->v->el[0]);
+ }
+ p = isl_printer_print_str(p, "]");
+
+ return p;
+}
+
+static __isl_give isl_printer *print_aff_isl(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ if (!aff)
+ goto error;
+
+ if (isl_local_space_dim(aff->ls, isl_dim_param) > 0) {
+ p = print_tuple(aff->ls->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ p = print_aff(p, aff);
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_aff_dump(__isl_keep isl_aff *aff)
+{
+ isl_printer *printer;
+
+ if (!aff)
+ return;
+
+ printer = isl_printer_to_file(isl_aff_get_ctx(aff), stderr);
+ printer = isl_printer_print_aff(printer, aff);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}
+
+static __isl_give isl_printer *print_pw_aff_isl(__isl_take isl_printer *p,
+ __isl_keep isl_pw_aff *pwaff)
+{
+ int i;
+
+ if (!pwaff)
+ goto error;
+
+ if (isl_dim_size(pwaff->dim, isl_dim_param) > 0) {
+ p = print_tuple(pwaff->dim, p, isl_dim_param, 0, 0, NULL);
+ p = isl_printer_print_str(p, " -> ");
+ }
+ p = isl_printer_print_str(p, "{ ");
+ for (i = 0; i < pwaff->n; ++i) {
+ if (i)
+ p = isl_printer_print_str(p, "; ");
+ p = print_aff(p, pwaff->p[i].aff);
+ p = print_disjuncts((isl_map *)pwaff->p[i].set, p, 1, 0);
+ }
+ p = isl_printer_print_str(p, " }");
+ return p;
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, isl_int *c);
+
+static __isl_give isl_printer *print_ls_name_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos)
+{
+ if (type == isl_dim_div) {
+ p = isl_printer_print_str(p, "floord(");
+ p = print_ls_affine_c(p, ls, ls->div->row[pos] + 1);
+ p = isl_printer_print_str(p, ", ");
+ p = isl_printer_print_isl_int(p, ls->div->row[pos][0]);
+ p = isl_printer_print_str(p, ")");
+ } else {
+ const char *name;
+
+ name = isl_dim_get_name(ls->dim, type, pos);
+ if (!name)
+ name = "UNNAMED";
+ p = isl_printer_print_str(p, name);
+ }
+ return p;
+}
+
+static __isl_give isl_printer *print_ls_term_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, isl_int c, unsigned pos)
+{
+ enum isl_dim_type type;
+
+ if (pos == 0)
+ return isl_printer_print_isl_int(p, c);
+
+ if (isl_int_is_one(c))
+ ;
+ else if (isl_int_is_negone(c))
+ p = isl_printer_print_str(p, "-");
+ else {
+ p = isl_printer_print_isl_int(p, c);
+ p = isl_printer_print_str(p, "*");
+ }
+ type = pos2type(ls->dim, &pos);
+ p = print_ls_name_c(p, ls, type, pos);
+ return p;
+}
+
+static __isl_give isl_printer *print_ls_partial_affine_c(
+ __isl_take isl_printer *p, __isl_keep isl_local_space *ls,
+ isl_int *c, unsigned len)
+{
+ int i;
+ int first;
+
+ for (i = 0, first = 1; i < len; ++i) {
+ int flip = 0;
+ if (isl_int_is_zero(c[i]))
+ continue;
+ if (!first) {
+ if (isl_int_is_neg(c[i])) {
+ flip = 1;
+ isl_int_neg(c[i], c[i]);
+ p = isl_printer_print_str(p, " - ");
+ } else
+ p = isl_printer_print_str(p, " + ");
+ }
+ first = 0;
+ p = print_ls_term_c(p, ls, c[i], i);
+ if (flip)
+ isl_int_neg(c[i], c[i]);
+ }
+ if (first)
+ p = isl_printer_print_str(p, "0");
+ return p;
+}
+
+static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p,
+ __isl_keep isl_local_space *ls, isl_int *c)
+{
+ unsigned len = 1 + isl_local_space_dim(ls, isl_dim_all);
+ return print_ls_partial_affine_c(p, ls, c, len);
+}
+
+static __isl_give isl_printer *print_aff_c(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ unsigned total;
+
+ total = isl_local_space_dim(aff->ls, isl_dim_all);
+ p = isl_printer_print_str(p, "(");
+ p = print_ls_partial_affine_c(p, aff->ls, aff->v->el + 1, 1 + total);
+ if (isl_int_is_one(aff->v->el[0]))
+ p = isl_printer_print_str(p, ")");
+ else {
+ p = isl_printer_print_str(p, ")/");
+ p = isl_printer_print_isl_int(p, aff->v->el[0]);
+ }
+ return p;
+}
+
+static __isl_give isl_printer *print_pw_aff_c(__isl_take isl_printer *p,
+ __isl_keep isl_pw_aff *pwaff)
+{
+ int i;
+
+ if (pwaff->n < 1)
+ isl_die(p->ctx, isl_error_unsupported,
+ "cannot print empty isl_pw_aff in C format", goto error);
+
+ for (i = 0; i < pwaff->n - 1; ++i) {
+ p = isl_printer_print_str(p, "(");
+ p = print_set_c(p, pwaff->dim, pwaff->p[i].set);
+ p = isl_printer_print_str(p, ") ? (");
+ p = print_aff_c(p, pwaff->p[i].aff);
+ p = isl_printer_print_str(p, ") : ");
+ }
+
+ return print_aff_c(p, pwaff->p[pwaff->n - 1].aff);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+__isl_give isl_printer *isl_printer_print_aff(__isl_take isl_printer *p,
+ __isl_keep isl_aff *aff)
+{
+ if (!p || !aff)
+ goto error;
+
+ if (p->output_format == ISL_FORMAT_ISL)
+ return print_aff_isl(p, aff);
+ else if (p->output_format == ISL_FORMAT_C)
+ return print_aff_c(p, aff);
+ isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
+ goto error);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+__isl_give isl_printer *isl_printer_print_pw_aff(__isl_take isl_printer *p,
+ __isl_keep isl_pw_aff *pwaff)
+{
+ if (!p || !pwaff)
+ goto error;
+
+ if (p->output_format == ISL_FORMAT_ISL)
+ return print_pw_aff_isl(p, pwaff);
+ else if (p->output_format == ISL_FORMAT_C)
+ return print_pw_aff_c(p, pwaff);
+ isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
+ goto error);
+error:
+ isl_printer_free(p);
+ return NULL;
+}
+
+void isl_pw_aff_dump(__isl_keep isl_pw_aff *pwaff)
+{
+ isl_printer *printer;
+
+ if (!pwaff)
+ return;
+
+ printer = isl_printer_to_file(isl_pw_aff_get_ctx(pwaff), stderr);
+ printer = isl_printer_print_pw_aff(printer, pwaff);
+ printer = isl_printer_end_line(printer);
+
+ isl_printer_free(printer);
+}