static isl_map* build_access_function (scoplib_scop_p scop, scoplib_statement_p s, scoplib_matrix_p m, isl_space* space, isl_ctx* ctxt, int* row_pos, int array_id) { isl_map* ret = NULL; int i; isl_val* tmp = isl_val_int_from_si (ctxt, 0); for (i = *row_pos; i < m->NbRows; ++i) { if (SCOPVAL_get_si(m->p[i][0]) == array_id) { ret = isl_map_universe (isl_space_copy (space)); int pos = 0; do { isl_local_space* ls = isl_local_space_from_space (isl_space_copy (space)); isl_constraint* cst = isl_equality_alloc (isl_local_space_copy (ls)); // Set input dimensions. int k; for (k = 0; k < s->nb_iterators; ++k) { tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][k+1])); cst = isl_constraint_set_coefficient_val (cst, isl_dim_in, k, isl_val_copy(tmp)); } for (k = 0; k < scop->nb_parameters; ++k) { tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][k+1+s->nb_iterators])); cst = isl_constraint_set_coefficient_val (cst, isl_dim_param, k, isl_val_copy (tmp)); } tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][m->NbColumns - 1])); cst = isl_constraint_set_constant_val (cst, isl_val_copy(tmp)); // Set output dimension. tmp = isl_val_set_si (tmp, -1); isl_constraint_set_coefficient_val (cst, isl_dim_out, pos++, isl_val_copy (tmp)); // Insert constraint. ret = isl_map_add_constraint (ret, cst); ++i; } while (i < m->NbRows && SCOPVAL_get_si(m->p[i][0]) == 0); *row_pos = i; break; } } isl_val_free (tmp); return ret; }
/* Construct an affine expression pet_expr that evaluates * to the constant "val" on "space". */ static __isl_give pet_expr *universally(__isl_take isl_space *space, int val) { isl_ctx *ctx; isl_local_space *ls; isl_aff *aff; isl_multi_pw_aff *mpa; ctx = isl_space_get_ctx(space); ls = isl_local_space_from_space(space); aff = isl_aff_val_on_domain(ls, isl_val_int_from_si(ctx, val)); mpa = isl_multi_pw_aff_from_pw_aff(isl_pw_aff_from_aff(aff)); return pet_expr_from_index(mpa); }
static isl_set* build_iteration_domain (scoplib_scop_p scop, scoplib_statement_p s, isl_space* space, isl_ctx* ctxt) { isl_set* ret = isl_set_universe (isl_space_domain (isl_space_copy (space))); int i; isl_val* tmp = isl_val_int_from_si (ctxt, 0); scoplib_matrix_p m = s->domain->elt; for (i = 0; i < m->NbRows; ++i) { isl_local_space* ls = isl_local_space_from_space (isl_set_get_space (ret)); isl_constraint* cst; if (SCOPVAL_get_si(m->p[i][0]) == 0) cst = isl_equality_alloc (isl_local_space_copy (ls)); else cst = isl_inequality_alloc (isl_local_space_copy (ls)); // Set input dimensions. int k; for (k = 0; k < s->nb_iterators; ++k) { tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][k+1])); cst = isl_constraint_set_coefficient_val (cst, isl_dim_set, k, isl_val_copy (tmp)); } for (k = 0; k < scop->nb_parameters; ++k) { tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][k+1+s->nb_iterators])); cst = isl_constraint_set_coefficient_val (cst, isl_dim_param, k, isl_val_copy (tmp)); } tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][m->NbColumns - 1])); cst = isl_constraint_set_constant_val (cst, isl_val_copy (tmp)); // Insert constraint. ret = isl_set_add_constraint (ret, cst); } isl_val_free (tmp); return ret; }
/* Construct an isl_multi_val living in "space" with all values equal to "val". */ __isl_give isl_multi_val *ppcg_multi_val_from_int(__isl_take isl_space *space, int val) { int i, n; isl_ctx *ctx; isl_val *v; isl_multi_val *mv; if (!space) return NULL; ctx = isl_space_get_ctx(space); n = isl_space_dim(space, isl_dim_set); mv = isl_multi_val_zero(space); v = isl_val_int_from_si(ctx, val); for (i = 0; i < n; ++i) mv = isl_multi_val_set_val(mv, i, isl_val_copy(v)); isl_val_free(v); return mv; }
/* Construct an isl_multi_val living in "space" with values specified * by "list". "list" is assumed to have at least as many entries * as the set dimension of "space". */ __isl_give isl_multi_val *ppcg_multi_val_from_int_list( __isl_take isl_space *space, int *list) { int i, n; isl_ctx *ctx; isl_multi_val *mv; if (!space) return NULL; ctx = isl_space_get_ctx(space); n = isl_space_dim(space, isl_dim_set); mv = isl_multi_val_zero(space); for (i = 0; i < n; ++i) { isl_val *v; v = isl_val_int_from_si(ctx, list[i]); mv = isl_multi_val_set_val(mv, i, v); } return mv; }
static isl_map* build_schedule (scoplib_scop_p scop, scoplib_statement_p s, isl_space* sp, isl_ctx* ctxt) { // Set up the space. isl_space* space_in = isl_space_domain (isl_space_copy (sp)); int dout = s->schedule->NbRows; isl_space* space_out = isl_space_set_alloc(ctxt, scop->nb_parameters, dout); int i; char buffer[32]; char* name; for (i = 0; i < dout; ++i) { sprintf (buffer, "t%d", i); name = strdup (buffer); space_out = isl_space_set_dim_name (space_out, isl_dim_set, i, name); } for (i = 0; i < scop->nb_parameters; ++i) { name = strdup (((SgVariableSymbol*)(scop->parameters[i]))->get_name().str()); space_out = isl_space_set_dim_name (space_out, isl_dim_param, i, name); } isl_space* space = isl_space_map_from_domain_and_range (isl_space_copy (space_in), isl_space_copy (space_out)); isl_map* ret = isl_map_universe (isl_space_copy (space)); isl_val* tmp = isl_val_int_from_si (ctxt, 0); scoplib_matrix_p m = s->schedule; for (i = 0; i < m->NbRows; ++i) { isl_local_space* ls = isl_local_space_from_space (isl_space_copy (space)); isl_constraint* cst; if (SCOPVAL_get_si(m->p[i][0]) == 0) cst = isl_equality_alloc (isl_local_space_copy (ls)); else cst = isl_inequality_alloc (isl_local_space_copy (ls)); // Set input dimensions. int k; for (k = 0; k < s->nb_iterators; ++k) { tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][k+1])); cst = isl_constraint_set_coefficient_val (cst, isl_dim_in, k, isl_val_copy (tmp)); } for (k = 0; k < scop->nb_parameters; ++k) { tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][k+1+s->nb_iterators])); cst = isl_constraint_set_coefficient_val (cst, isl_dim_param, k, isl_val_copy (tmp)); } tmp = isl_val_set_si (tmp, SCOPVAL_get_si(m->p[i][m->NbColumns - 1])); cst = isl_constraint_set_constant_val (cst, isl_val_copy (tmp)); // Set output dimension. tmp = isl_val_set_si (tmp, -1); isl_constraint_set_coefficient_val (cst, isl_dim_out, i, isl_val_copy (tmp)); // Insert constraint. ret = isl_map_add_constraint (ret, cst); } isl_val_free (tmp); return ret; }