static void lst_linearized_niter (lst_p lst, mpz_t res) { int i; lst_p l; mpz_t n; mpz_init (n); mpz_set_si (res, 0); FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l) if (LST_LOOP_P (l)) { lst_linearized_niter (l, n); mpz_add (res, res, n); } if (LST_LOOP_P (lst)) { lst_niter_for_loop (lst, n); if (mpz_cmp_si (res, 0) != 0) mpz_mul (res, res, n); else mpz_set (res, n); } mpz_clear (n); }
static bool lst_do_strip_mine (lst_p lst, int stride) { int i; lst_p l; bool res = false; int depth; if (!stride) stride = PARAM_VALUE (PARAM_LOOP_BLOCK_TILE_SIZE); if (!lst || !LST_LOOP_P (lst)) return false; FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l) res |= lst_do_strip_mine (l, stride); depth = lst_depth (lst); if (depth >= 0 && lst_strip_mine_profitable_p (lst, stride)) { res |= lst_do_strip_mine_loop (lst, lst_depth (lst), stride); lst_add_loop_under_loop (lst); } return res; }
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 memory_strides_in_loop_1 (lst_p loop, graphite_dim_t depth, mpz_t strides) { int i, j; lst_p l; poly_dr_p pdr; mpz_t s, n; mpz_init (s); mpz_init (n); FOR_EACH_VEC_ELT (LST_SEQ (loop), j, l) if (LST_LOOP_P (l)) memory_strides_in_loop_1 (l, depth, strides); else FOR_EACH_VEC_ELT (PBB_DRS (LST_PBB (l)), i, pdr) { pdr_stride_in_loop (s, depth, pdr); mpz_set_si (n, PDR_NB_REFS (pdr)); mpz_mul (s, s, n); mpz_add (strides, strides, s); }
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; }