Exemple #1
0
/* Set the stride and offset of data->pos to the given
 * value and expression.
 *
 * If we had already found a stride before, then the two strides
 * are combined into a single stride.
 *
 * In particular, if the new stride information is of the form
 *
 *	i = f + s (...)
 *
 * and the old stride information is of the form
 *
 *	i = f2 + s2 (...)
 *
 * then we compute the extended gcd of s and s2
 *
 *	a s + b s2 = g,
 *
 * with g = gcd(s,s2), multiply the first equation with t1 = b s2/g
 * and the second with t2 = a s1/g.
 * This results in
 *
 *	i = (b s2 + a s1)/g i = t1 f + t2 f2 + (s s2)/g (...)
 *
 * so that t1 f + t2 f2 is the combined offset and (s s2)/g = lcm(s,s2)
 * is the combined stride.
 */
static isl_stat set_stride(struct isl_detect_stride_data *data,
	__isl_take isl_val *stride, __isl_take isl_aff *offset)
{
	int pos;

	if (!stride || !offset)
		goto error;

	pos = data->pos;

	if (data->found) {
		isl_val *stride2, *a, *b, *g;
		isl_aff *offset2;

		stride2 = data->stride;
		g = isl_val_gcdext(isl_val_copy(stride), isl_val_copy(stride2),
					&a, &b);
		a = isl_val_mul(a, isl_val_copy(stride));
		a = isl_val_div(a, isl_val_copy(g));
		stride2 = isl_val_div(stride2, g);
		b = isl_val_mul(b, isl_val_copy(stride2));
		stride = isl_val_mul(stride, stride2);

		if (!data->want_offset) {
			isl_val_free(a);
			isl_val_free(b);
		} else {
			offset2 = data->offset;
			offset2 = isl_aff_scale_val(offset2, a);
			offset = isl_aff_scale_val(offset, b);
			offset = isl_aff_add(offset, offset2);
		}
	}

	data->found = 1;
	data->stride = stride;
	if (data->want_offset)
		data->offset = offset;
	else
		isl_aff_free(offset);
	if (!data->stride || (data->want_offset && !data->offset))
		return isl_stat_error;

	return isl_stat_ok;
error:
	isl_val_free(stride);
	isl_aff_free(offset);
	return isl_stat_error;
}
Exemple #2
0
/* 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);
}
Exemple #3
0
static __isl_give isl_printer *print_kernel_var(__isl_take isl_printer *p,
	struct ppcg_kernel_var *var)
{
	int j;

	p = isl_printer_start_line(p);
	if (var->type == ppcg_access_shared)
		p = isl_printer_print_str(p, "__shared__ ");
	p = isl_printer_print_str(p, var->array->type);
	p = isl_printer_print_str(p, " ");
	p = isl_printer_print_str(p,  var->name);
	for (j = 0; j < var->array->n_index; ++j) {
		isl_val *v;

		p = isl_printer_print_str(p, "[");
		v = isl_vec_get_element_val(var->size, j);
		p = isl_printer_print_val(p, v);
		isl_val_free(v);
		p = isl_printer_print_str(p, "]");
	}
	p = isl_printer_print_str(p, ";");
	p = isl_printer_end_line(p);

	return p;
}
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;
}
Exemple #5
0
/* Check whether the polynomial "poly" has sign "sign" over "bset",
 * i.e., if sign == 1, check that the lower bound on the polynomial
 * is non-negative and if sign == -1, check that the upper bound on
 * the polynomial is non-positive.
 */
static int has_sign(__isl_keep isl_basic_set *bset,
	__isl_keep isl_qpolynomial *poly, int sign, int *signs)
{
	struct range_data data_m;
	unsigned nparam;
	isl_space *dim;
	isl_val *opt;
	int r;
	enum isl_fold type;

	nparam = isl_basic_set_dim(bset, isl_dim_param);

	bset = isl_basic_set_copy(bset);
	poly = isl_qpolynomial_copy(poly);

	bset = isl_basic_set_move_dims(bset, isl_dim_set, 0,
					isl_dim_param, 0, nparam);
	poly = isl_qpolynomial_move_dims(poly, isl_dim_in, 0,
					isl_dim_param, 0, nparam);

	dim = isl_qpolynomial_get_space(poly);
	dim = isl_space_params(dim);
	dim = isl_space_from_domain(dim);
	dim = isl_space_add_dims(dim, isl_dim_out, 1);

	data_m.test_monotonicity = 0;
	data_m.signs = signs;
	data_m.sign = -sign;
	type = data_m.sign < 0 ? isl_fold_min : isl_fold_max;
	data_m.pwf = isl_pw_qpolynomial_fold_zero(dim, type);
	data_m.tight = 0;
	data_m.pwf_tight = NULL;

	if (propagate_on_domain(bset, poly, &data_m) < 0)
		goto error;

	if (sign > 0)
		opt = isl_pw_qpolynomial_fold_min(data_m.pwf);
	else
		opt = isl_pw_qpolynomial_fold_max(data_m.pwf);

	if (!opt)
		r = -1;
	else if (isl_val_is_nan(opt) ||
		 isl_val_is_infty(opt) ||
		 isl_val_is_neginfty(opt))
		r = 0;
	else
		r = sign * isl_val_sgn(opt) >= 0;

	isl_val_free(opt);

	return r;
error:
	isl_pw_qpolynomial_fold_free(data_m.pwf);
	return -1;
}
Exemple #6
0
/* Free "si" and return NULL.
 */
__isl_null isl_stride_info *isl_stride_info_free(
	__isl_take isl_stride_info *si)
{
	if (!si)
		return NULL;
	isl_val_free(si->stride);
	isl_aff_free(si->offset);
	free(si);
	return NULL;
}
enum lp_result isl_constraints_opt(Matrix *C, Value *obj, Value denom,
				    enum lp_dir dir, Value *opt)
{
	int i;
	isl_ctx *ctx = isl_ctx_alloc();
	isl_space *dim;
	isl_local_space *ls;
	isl_mat *eq, *ineq;
	isl_basic_set *bset;
	isl_aff *aff;
	isl_val *v;
	enum isl_lp_result res;
	int max = dir == lp_max;

	eq = extract_equalities(ctx, C);
	ineq = extract_inequalities(ctx, C);
	dim = isl_space_set_alloc(ctx, 0, C->NbColumns - 2);
	ls = isl_local_space_from_space(isl_space_copy(dim));
	bset = isl_basic_set_from_constraint_matrices(dim, eq, ineq,
			isl_dim_set, isl_dim_div, isl_dim_param, isl_dim_cst);
	aff = isl_aff_zero_on_domain(ls);
	for (i = 0; i < C->NbColumns - 2; ++i) {
		v = isl_val_int_from_gmp(ctx, obj[i]);
		aff = isl_aff_set_coefficient_val(aff, isl_dim_in, i, v);
	}
	v = isl_val_int_from_gmp(ctx, obj[C->NbColumns - 2]);
	aff = isl_aff_set_constant_val(aff, v);
	v = isl_val_int_from_gmp(ctx, denom);
	aff = isl_aff_scale_down_val(aff, v);

	if (max)
		v = isl_val_floor(isl_basic_set_max_lp_val(bset, aff));
	else
		v = isl_val_ceil(isl_basic_set_min_lp_val(bset, aff));
	if (!v)
		res = isl_lp_error;
	else if (isl_val_is_nan(v))
		res = isl_lp_empty;
	else if (!isl_val_is_rat(v))
		res = isl_lp_unbounded;
	else {
		res = isl_lp_ok;
		isl_val_get_num_gmp(v, *opt);
	}

	isl_val_free(v);
	isl_aff_free(aff);
	isl_basic_set_free(bset);
	isl_ctx_free(ctx);

	return isl_lp_result2lp_result(res);
}
Exemple #8
0
/* Check if dimension "dim" belongs to a residue class
 *		i_dim \equiv r mod m
 * with m != 1 and if so return m in *modulo and r in *residue.
 * As a special case, when i_dim has a fixed value v, then
 * *modulo is set to 0 and *residue to v.
 *
 * If i_dim does not belong to such a residue class, then *modulo
 * is set to 1 and *residue is set to 0.
 */
isl_stat isl_set_dim_residue_class_val(__isl_keep isl_set *set,
	int pos, __isl_give isl_val **modulo, __isl_give isl_val **residue)
{
	*modulo = NULL;
	*residue = NULL;
	if (!set)
		return isl_stat_error;
	*modulo = isl_val_alloc(isl_set_get_ctx(set));
	*residue = isl_val_alloc(isl_set_get_ctx(set));
	if (!*modulo || !*residue)
		goto error;
	if (isl_set_dim_residue_class(set, pos,
					&(*modulo)->n, &(*residue)->n) < 0)
		goto error;
	isl_int_set_si((*modulo)->d, 1);
	isl_int_set_si((*residue)->d, 1);
	return isl_stat_ok;
error:
	isl_val_free(*modulo);
	isl_val_free(*residue);
	return isl_stat_error;
}
Exemple #9
0
/* If "pa" represents a constant value over a single domain,
 * then return this constant.
 * Otherwise return NaN.
 */
__isl_give isl_val *pet_extract_cst(__isl_keep isl_pw_aff *pa)
{
	isl_val *v;

	if (!pa)
		return NULL;
	v = isl_val_nan(isl_pw_aff_get_ctx(pa));
	if (isl_pw_aff_n_piece(pa) != 1)
		return v;
	if (isl_pw_aff_foreach_piece(pa, &extract_cst, &v) < 0)
		v = isl_val_free(v);
	return v;
}
Exemple #10
0
/* If the isl_pw_aff on which isl_pw_aff_foreach_piece is called
 * has a constant expression on its only domain, then replace
 * the isl_val in *user by this constant.
 * The caller is assumed to have checked that this function will
 * be called exactly once.
 */
static isl_stat extract_cst(__isl_take isl_set *set, __isl_take isl_aff *aff,
	void *user)
{
	isl_val **inc = (isl_val **)user;

	if (isl_aff_is_cst(aff)) {
		isl_val_free(*inc);
		*inc = isl_aff_get_constant_val(aff);
	}

	isl_set_free(set);
	isl_aff_free(aff);

	return isl_stat_ok;
}
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;
}
Exemple #12
0
/* Construct an isl_stride_info object with given offset and stride.
 */
__isl_give isl_stride_info *isl_stride_info_alloc(
	__isl_take isl_val *stride, __isl_take isl_aff *offset)
{
	struct isl_stride_info *si;

	if (!stride || !offset)
		goto error;
	si = isl_alloc_type(isl_val_get_ctx(stride), struct isl_stride_info);
	if (!si)
		goto error;
	si->stride = stride;
	si->offset = offset;
	return si;
error:
	isl_val_free(stride);
	isl_aff_free(offset);
	return NULL;
}
Exemple #13
0
/*
 * Construct a PlutoMatrix with the same content as the given isl_mat.
 */
PlutoMatrix *pluto_matrix_from_isl_mat(__isl_keep isl_mat *mat)
{
    int i, j;
    int rows, cols;
    PlutoMatrix *pluto;

    rows = isl_mat_rows(mat);
    cols = isl_mat_cols(mat);
    pluto = pluto_matrix_alloc(rows, cols);

    for (i = 0; i < rows; ++i)
        for (j = 0; j < cols; ++j) {
            isl_val *v = isl_mat_get_element_val(mat, i, j);
            pluto->val[i][j] = isl_val_get_num_si(v);
            isl_val_free(v);
        }

    return pluto;
}
expression_ptr cpp_from_isl::process_expr(isl_ast_expr * ast_expr)
{
    expression_ptr expr;

    auto type = isl_ast_expr_get_type(ast_expr);

    switch(type)
    {
    case isl_ast_expr_op:
    {
        expr = process_op(ast_expr);
        break;
    }
    case isl_ast_expr_id:
    {
        auto id = isl_ast_expr_get_id(ast_expr);
        string name(isl_id_get_name(id));
        isl_id_free(id);

        if (m_id_func)
            expr = m_id_func(name);
        if (!expr)
            expr = make_shared<id_expression>(name);
        break;
    }
    case isl_ast_expr_int:
    {
        auto val = isl_ast_expr_get_val(ast_expr);
        if (isl_val_is_int(val) != isl_bool_true)
            throw error("Value is not an integer.");
        int ival = isl_val_get_num_si(val);
        isl_val_free(val);
        expr = literal(ival);
        break;
    }
    default:
        throw error("Unexpected AST expression type.");
    }

    return expr;
}
Exemple #15
0
/* 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;
}
Exemple #16
0
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;
}
Exemple #17
0
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_val *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);
    islstride = isl_set_max_val (set, aff);
    isl_val_get_num_gmp (islstride, stride);
    isl_val_free (islstride);
    isl_aff_free (aff);
    isl_set_free (set);

    if (dump_file && (dump_flags & TDF_DETAILS))
    {
        gmp_fprintf (dump_file, "\nStride in BB_%d, DR_%d, depth %d:  %Zd ",
                     pbb_index (pbb), PDR_ID (pdr), (int) depth, stride);
    }
}
Exemple #18
0
static void isl_obj_val_free(void *v)
{
	isl_val_free((isl_val *)v);
}
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;
}
Exemple #20
0
			// Solution value
			long solution_val (int v) const {
				isl_val * val = isl_point_get_coordinate_val (solution, isl_dim_set, v);
				long val_int = isl_val_get_num_si (val);
				isl_val_free (val);
				return val_int;
			}
Exemple #21
0
/* Check if constraint "c" imposes any stride on dimension data->pos
 * and, if so, update the stride information in "data".
 *
 * In order to impose a stride on the dimension, "c" needs to be an equality
 * and it needs to involve the dimension.  Note that "c" may also be
 * a div constraint and thus an inequality that we cannot use.
 *
 * Let c be of the form
 *
 *	h(p) + g * v * i + g * stride * f(alpha) = 0
 *
 * with h(p) an expression in terms of the parameters and other dimensions
 * and f(alpha) an expression in terms of the existentially quantified
 * variables.
 *
 * If "stride" is not zero and not one, then it represents a non-trivial stride
 * on "i".  We compute a and b such that
 *
 *	a v + b stride = 1
 *
 * We have
 *
 *	g v i = -h(p) + g stride f(alpha)
 *
 *	a g v i = -a h(p) + g stride f(alpha)
 *
 *	a g v i + b g stride i = -a h(p) + g stride * (...)
 *
 *	g i = -a h(p) + g stride * (...)
 *
 *	i = -a h(p)/g + stride * (...)
 *
 * The expression "-a h(p)/g" can therefore be used as offset.
 */
static isl_stat detect_stride(__isl_take isl_constraint *c, void *user)
{
	struct isl_detect_stride_data *data = user;
	int i, n_div;
	isl_ctx *ctx;
	isl_stat r = isl_stat_ok;
	isl_val *v, *stride, *m;
	isl_bool is_eq, relevant, has_stride;

	is_eq = isl_constraint_is_equality(c);
	relevant = isl_constraint_involves_dims(c, isl_dim_set, data->pos, 1);
	if (is_eq < 0 || relevant < 0)
		goto error;
	if (!is_eq || !relevant) {
		isl_constraint_free(c);
		return isl_stat_ok;
	}

	ctx = isl_constraint_get_ctx(c);
	stride = isl_val_zero(ctx);
	n_div = isl_constraint_dim(c, isl_dim_div);
	for (i = 0; i < n_div; ++i) {
		v = isl_constraint_get_coefficient_val(c, isl_dim_div, i);
		stride = isl_val_gcd(stride, v);
	}

	v = isl_constraint_get_coefficient_val(c, isl_dim_set, data->pos);
	m = isl_val_gcd(isl_val_copy(stride), isl_val_copy(v));
	stride = isl_val_div(stride, isl_val_copy(m));
	v = isl_val_div(v, isl_val_copy(m));

	has_stride = isl_val_gt_si(stride, 1);
	if (has_stride >= 0 && has_stride) {
		isl_aff *aff;
		isl_val *gcd, *a, *b;

		gcd = isl_val_gcdext(v, isl_val_copy(stride), &a, &b);
		isl_val_free(gcd);
		isl_val_free(b);

		aff = isl_constraint_get_aff(c);
		for (i = 0; i < n_div; ++i)
			aff = isl_aff_set_coefficient_si(aff,
							 isl_dim_div, i, 0);
		aff = isl_aff_set_coefficient_si(aff, isl_dim_in, data->pos, 0);
		aff = isl_aff_remove_unused_divs(aff);
		a = isl_val_neg(a);
		aff = isl_aff_scale_val(aff, a);
		aff = isl_aff_scale_down_val(aff, m);
		r = set_stride(data, stride, aff);
	} else {
		isl_val_free(stride);
		isl_val_free(m);
		isl_val_free(v);
	}

	isl_constraint_free(c);
	if (has_stride < 0)
		return isl_stat_error;
	return r;
error:
	isl_constraint_free(c);
	return isl_stat_error;
}
enum order_sign isl_polyhedron_affine_sign(Polyhedron *D, Matrix *T,
					    struct barvinok_options *options)
{
	int i;
	isl_ctx *ctx = isl_ctx_alloc();
	isl_space *dim;
	isl_local_space *ls;
	isl_aff *aff;
	isl_basic_set *bset;
	isl_val *min, *max = NULL;
	isl_val *v;
	enum order_sign sign = order_undefined;

	assert(D->Dimension == T->NbColumns - 1);

	dim = isl_space_set_alloc(ctx, 0, D->Dimension);
	ls = isl_local_space_from_space(isl_space_copy(dim));
	bset = isl_basic_set_new_from_polylib(D, dim);
	aff = isl_aff_zero_on_domain(ls);
	for (i = 0; i < D->Dimension; ++i) {
		v = isl_val_int_from_gmp(ctx, T->p[0][i]);
		aff = isl_aff_set_coefficient_val(aff, isl_dim_in, i, v);
	}
	v = isl_val_int_from_gmp(ctx, T->p[0][D->Dimension]);
	aff = isl_aff_set_constant_val(aff, v);
	v = isl_val_int_from_gmp(ctx, T->p[1][D->Dimension]);
	aff = isl_aff_scale_down_val(aff, v);

	min = isl_basic_set_min_lp_val(bset, aff);
	min = isl_val_ceil(min);
	assert(min);

	if (isl_val_is_nan(min))
		sign = order_undefined;
	else if (isl_val_is_pos(min))
		sign = order_gt;
	else {
		max = isl_basic_set_max_lp_val(bset, aff);
		max = isl_val_floor(max);
		assert(max);

		if (isl_val_is_neg(max))
			sign = order_lt;
		else if (isl_val_is_zero(min) && isl_val_is_zero(max))
			sign = order_eq;
		else if (isl_val_is_zero(min))
			sign = order_ge;
		else if (isl_val_is_zero(max))
			sign = order_le;
		else
			sign = order_unknown;
	}

	isl_basic_set_free(bset);
	isl_aff_free(aff);
	isl_val_free(min);
	isl_val_free(max);
	isl_ctx_free(ctx);

	return sign;
}