/* Compute the size of a bounding box around the origin and "set", * where "set" is assumed to contain only non-negative elements. * In particular, compute the maximal value of "set" in each direction * and add one. */ __isl_give isl_multi_pw_aff *ppcg_size_from_extent(__isl_take isl_set *set) { int i, n; isl_multi_pw_aff *mpa; n = isl_set_dim(set, isl_dim_set); mpa = isl_multi_pw_aff_zero(isl_set_get_space(set)); for (i = 0; i < n; ++i) { isl_space *space; isl_aff *one; isl_pw_aff *bound; if (!isl_set_dim_has_upper_bound(set, isl_dim_set, i)) { const char *name; name = isl_set_get_tuple_name(set); if (!name) name = ""; fprintf(stderr, "unable to determine extent of '%s' " "in dimension %d\n", name, i); set = isl_set_free(set); } bound = isl_set_dim_max(isl_set_copy(set), i); space = isl_pw_aff_get_domain_space(bound); one = isl_aff_zero_on_domain(isl_local_space_from_space(space)); one = isl_aff_add_constant_si(one, 1); bound = isl_pw_aff_add(bound, isl_pw_aff_from_aff(one)); mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, bound); } isl_set_free(set); return mpa; }
/* Check if the constraints in "set" imply any stride on set dimension "pos" and * store the results in data->stride and data->offset. * * In particular, compute the affine hull and then check if * any of the constraints in the hull impose any stride on the dimension. * If no such constraint can be found, then the offset is taken * to be the zero expression and the stride is taken to be one. */ static void set_detect_stride(__isl_keep isl_set *set, int pos, struct isl_detect_stride_data *data) { isl_basic_set *hull; hull = isl_set_affine_hull(isl_set_copy(set)); data->pos = pos; data->found = 0; data->stride = NULL; data->offset = NULL; if (isl_basic_set_foreach_constraint(hull, &detect_stride, data) < 0) goto error; if (!data->found) { data->stride = isl_val_one(isl_set_get_ctx(set)); if (data->want_offset) { isl_space *space; isl_local_space *ls; space = isl_set_get_space(set); ls = isl_local_space_from_space(space); data->offset = isl_aff_zero_on_domain(ls); } } isl_basic_set_free(hull); return; error: isl_basic_set_free(hull); data->stride = isl_val_free(data->stride); data->offset = isl_aff_free(data->offset); }
/* Extend "set" with unconstrained coordinates to a total length of "dst_len". */ __isl_give isl_set *extend(__isl_take isl_set *set, int dst_len) { int n_set; isl_space *dim; isl_map *map; dim = isl_set_get_space(set); n_set = isl_space_dim(dim, isl_dim_set); dim = isl_space_drop_dims(dim, isl_dim_set, 0, n_set); map = projection(dim, dst_len, n_set); map = isl_map_reverse(map); return isl_set_apply(set, map); }
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_int size, subsize; res = isl_equality_alloc (ls); isl_int_init (size); isl_int_set_ui (size, 1); isl_int_init (subsize); isl_int_set_ui (subsize, 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; res = isl_constraint_set_coefficient (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); isl_set_max (pdr->extent, aff, &subsize); isl_aff_free (aff); isl_int_mul (size, size, subsize); } isl_int_clear (subsize); isl_int_clear (size); return res; }
static void pdr_stride_in_loop (mpz_t stride, graphite_dim_t depth, poly_dr_p pdr) { poly_bb_p pbb = PDR_PBB (pdr); isl_map *map; isl_set *set; isl_aff *aff; isl_space *dc; isl_constraint *lma, *c; isl_int islstride; graphite_dim_t time_depth; unsigned offset, nt; unsigned i; /* XXX isl rewrite following comments. */ /* Builds a partial difference equations and inserts them into pointset powerset polyhedron P. Polyhedron is assumed to have the format: T|I|T'|I'|G|S|S'|l1|l2. TIME_DEPTH is the time dimension w.r.t. which we are differentiating. OFFSET represents the number of dimensions between columns t_{time_depth} and t'_{time_depth}. DIM_SCTR is the number of scattering dimensions. It is essentially the dimensionality of the T vector. The following equations are inserted into the polyhedron P: | t_1 = t_1' | ... | t_{time_depth-1} = t'_{time_depth-1} | t_{time_depth} = t'_{time_depth} + 1 | t_{time_depth+1} = t'_{time_depth + 1} | ... | t_{dim_sctr} = t'_{dim_sctr}. */ /* Add the equality: t_{time_depth} = t'_{time_depth} + 1. This is the core part of this alogrithm, since this constraint asks for the memory access stride (difference) between two consecutive points in time dimensions. */ /* Add equalities: | t1 = t1' | ... | t_{time_depth-1} = t'_{time_depth-1} | t_{time_depth+1} = t'_{time_depth+1} | ... | t_{dim_sctr} = t'_{dim_sctr} This means that all the time dimensions are equal except for time_depth, where the constraint is t_{depth} = t'_{depth} + 1 step. More to this: we should be careful not to add equalities to the 'coupled' dimensions, which happens when the one dimension is stripmined dimension, and the other dimension corresponds to the point loop inside stripmined dimension. */ /* pdr->accesses: [P1..nb_param,I1..nb_domain]->[a,S1..nb_subscript] ??? [P] not used for PDRs? pdr->extent: [a,S1..nb_subscript] pbb->domain: [P1..nb_param,I1..nb_domain] pbb->transformed: [P1..nb_param,I1..nb_domain]->[T1..Tnb_sctr] [T] includes local vars (currently unused) First we create [P,I] -> [T,a,S]. */ map = isl_map_flat_range_product (isl_map_copy (pbb->transformed), isl_map_copy (pdr->accesses)); /* Add a dimension for L: [P,I] -> [T,a,S,L].*/ map = isl_map_add_dims (map, isl_dim_out, 1); /* Build a constraint for "lma[S] - L == 0", effectively calculating L in terms of subscripts. */ lma = build_linearized_memory_access (map, pdr); /* And add it to the map, so we now have: [P,I] -> [T,a,S,L] : lma([S]) == L. */ map = isl_map_add_constraint (map, lma); /* Then we create [P,I,P',I'] -> [T,a,S,L,T',a',S',L']. */ map = isl_map_flat_product (map, isl_map_copy (map)); /* Now add the equality T[time_depth] == T'[time_depth]+1. This will force L' to be the linear address at T[time_depth] + 1. */ time_depth = psct_dynamic_dim (pbb, depth); /* Length of [a,S] plus [L] ... */ offset = 1 + isl_map_dim (pdr->accesses, isl_dim_out); /* ... plus [T]. */ offset += isl_map_dim (pbb->transformed, isl_dim_out); c = isl_equality_alloc (isl_local_space_from_space (isl_map_get_space (map))); c = isl_constraint_set_coefficient_si (c, isl_dim_out, time_depth, 1); c = isl_constraint_set_coefficient_si (c, isl_dim_out, offset + time_depth, -1); c = isl_constraint_set_constant_si (c, 1); map = isl_map_add_constraint (map, c); /* Now we equate most of the T/T' elements (making PITaSL nearly the same is (PITaSL)', except for one dimension, namely for 'depth' (an index into [I]), after translating to index into [T]. Take care to not produce an empty map, which indicates we wanted to equate two dimensions that are already coupled via the above time_depth dimension. Happens with strip mining where several scatter dimension are interdependend. */ /* Length of [T]. */ nt = pbb_nb_scattering_transform (pbb) + pbb_nb_local_vars (pbb); for (i = 0; i < nt; i++) if (i != time_depth) { isl_map *temp = isl_map_equate (isl_map_copy (map), isl_dim_out, i, isl_dim_out, offset + i); if (isl_map_is_empty (temp)) isl_map_free (temp); else { isl_map_free (map); map = temp; } } /* Now maximize the expression L' - L. */ set = isl_map_range (map); dc = isl_set_get_space (set); aff = isl_aff_zero_on_domain (isl_local_space_from_space (dc)); aff = isl_aff_set_coefficient_si (aff, isl_dim_in, offset - 1, -1); aff = isl_aff_set_coefficient_si (aff, isl_dim_in, offset + offset - 1, 1); isl_int_init (islstride); isl_set_max (set, aff, &islstride); isl_int_get_gmp (islstride, stride); isl_int_clear (islstride); isl_aff_free (aff); isl_set_free (set); if (dump_file && (dump_flags & TDF_DETAILS)) { char *str; void (*gmp_free) (void *, size_t); fprintf (dump_file, "\nStride in BB_%d, DR_%d, depth %d:", pbb_index (pbb), PDR_ID (pdr), (int) depth); str = mpz_get_str (0, 10, stride); fprintf (dump_file, " %s ", str); mp_get_memory_functions (NULL, NULL, &gmp_free); (*gmp_free) (str, strlen (str) + 1); } }