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; }
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; }
static isl_constraint * build_linearized_memory_access (isl_map *map, poly_dr_p pdr) { isl_constraint *res; isl_local_space *ls = isl_local_space_from_space (isl_map_get_space (map)); unsigned offset, nsubs; int i; isl_ctx *ctx; isl_val *size, *subsize, *size1; res = isl_equality_alloc (ls); ctx = isl_local_space_get_ctx (ls); size = isl_val_int_from_ui (ctx, 1); nsubs = isl_set_dim (pdr->extent, isl_dim_set); /* -1 for the already included L dimension. */ offset = isl_map_dim (map, isl_dim_out) - 1 - nsubs; res = isl_constraint_set_coefficient_si (res, isl_dim_out, offset + nsubs, -1); /* Go through all subscripts from last to first. First dimension is the alias set, ignore it. */ for (i = nsubs - 1; i >= 1; i--) { isl_space *dc; isl_aff *aff; size1 = isl_val_copy (size); res = isl_constraint_set_coefficient_val (res, isl_dim_out, offset + i, size); dc = isl_set_get_space (pdr->extent); aff = isl_aff_zero_on_domain (isl_local_space_from_space (dc)); aff = isl_aff_set_coefficient_si (aff, isl_dim_in, i, 1); subsize = isl_set_max_val (pdr->extent, aff); isl_aff_free (aff); size = isl_val_mul (size1, subsize); } isl_val_free (size); return res; }
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; }