static void lst_project_loop (lst_p outer, lst_p inner, mpz_t stride) { int i; lst_p stmt; mpz_t x; ppl_Coefficient_t one; int outer_depth = lst_depth (outer); int inner_depth = lst_depth (inner); mpz_init (x); mpz_set_si (x, 1); ppl_new_Coefficient (&one); ppl_assign_Coefficient_from_mpz_t (one, x); FOR_EACH_VEC_ELT (lst_p, LST_SEQ (inner), i, stmt) { poly_bb_p pbb = LST_PBB (stmt); ppl_Polyhedron_t poly = PBB_TRANSFORMED_SCATTERING (pbb); ppl_dimension_type outer_dim = psct_dynamic_dim (pbb, outer_depth); ppl_dimension_type inner_dim = psct_dynamic_dim (pbb, inner_depth); ppl_Linear_Expression_t expr; ppl_dimension_type dim; ppl_dimension_type *ds; /* There should be no loops under INNER. */ gcc_assert (!LST_LOOP_P (stmt)); ppl_Polyhedron_space_dimension (poly, &dim); ppl_new_Linear_Expression_with_dimension (&expr, dim); /* outer_dim = outer_dim * stride + inner_dim. */ ppl_set_coef (expr, inner_dim, 1); ppl_set_coef_gmp (expr, outer_dim, stride); ppl_Polyhedron_affine_image (poly, outer_dim, expr, one); ppl_delete_Linear_Expression (expr); /* Project on inner_dim. */ ppl_new_Linear_Expression_with_dimension (&expr, dim - 1); ppl_Polyhedron_affine_image (poly, inner_dim, expr, one); ppl_delete_Linear_Expression (expr); /* Remove inner loop and the static schedule of its body. */ ds = XNEWVEC (ppl_dimension_type, 2); ds[0] = inner_dim; ds[1] = inner_dim + 1; ppl_Polyhedron_remove_space_dimensions (poly, ds, 2); PBB_NB_SCATTERING_TRANSFORM (pbb) -= 2; free (ds); }
static void lst_scale (lst_p lst, lst_p stmt, mpz_t factor) { mpz_t x; ppl_Coefficient_t one; int outer_depth = lst_depth (lst); poly_bb_p pbb = LST_PBB (stmt); ppl_Polyhedron_t poly = PBB_TRANSFORMED_SCATTERING (pbb); ppl_dimension_type outer_dim = psct_dynamic_dim (pbb, outer_depth); ppl_Linear_Expression_t expr; ppl_dimension_type dim; mpz_init (x); mpz_set_si (x, 1); ppl_new_Coefficient (&one); ppl_assign_Coefficient_from_mpz_t (one, x); ppl_Polyhedron_space_dimension (poly, &dim); ppl_new_Linear_Expression_with_dimension (&expr, dim); /* outer_dim = factor * outer_dim. */ ppl_set_coef_gmp (expr, outer_dim, factor); ppl_Polyhedron_affine_image (poly, outer_dim, expr, one); ppl_delete_Linear_Expression (expr); mpz_clear (x); ppl_delete_Coefficient (one); }
static void lst_offset (lst_p stmt, mpz_t offset) { lst_p inner = LST_LOOP_FATHER (stmt); poly_bb_p pbb = LST_PBB (stmt); ppl_Polyhedron_t poly = PBB_TRANSFORMED_SCATTERING (pbb); int inner_depth = lst_depth (inner); ppl_dimension_type inner_dim = psct_dynamic_dim (pbb, inner_depth); ppl_Linear_Expression_t expr; ppl_dimension_type dim; ppl_Coefficient_t one; mpz_t x; mpz_init (x); mpz_set_si (x, 1); ppl_new_Coefficient (&one); ppl_assign_Coefficient_from_mpz_t (one, x); ppl_Polyhedron_space_dimension (poly, &dim); ppl_new_Linear_Expression_with_dimension (&expr, dim); ppl_set_coef (expr, inner_dim, 1); ppl_set_inhomogeneous_gmp (expr, offset); ppl_Polyhedron_affine_image (poly, inner_dim, expr, one); ppl_delete_Linear_Expression (expr); ppl_delete_Coefficient (one); }
static bool lst_do_strip_mine_loop (lst_p lst, int depth, int stride) { int i; lst_p l; poly_bb_p pbb; if (!lst) return false; if (LST_LOOP_P (lst)) { bool res = false; FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l) res |= lst_do_strip_mine_loop (l, depth, stride); return res; } pbb = LST_PBB (lst); return pbb_strip_mine_time_depth (pbb, psct_dynamic_dim (pbb, depth), stride); }
static int lst_do_strip_mine_loop (lst_p lst, int depth, int stride) { int i; lst_p l; poly_bb_p pbb; if (!lst) return 0; if (LST_LOOP_P (lst)) { int res = 0; FOR_EACH_VEC_ELT (LST_SEQ (lst), i, l) res += lst_do_strip_mine_loop (l, depth, stride); return res; } pbb = LST_PBB (lst); pbb_strip_mine_time_depth (pbb, psct_dynamic_dim (pbb, depth), stride); return 1; }
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); } }