/* Gimple Represented as Polyhedra.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 Free Software Foundation, Inc.
Contributed by Sebastian Pop <sebastian.pop@amd.com>
and Tobias Grosser <grosser@fim.uni-passau.de>
#include "ggc.h"
#ifdef HAVE_cloog
+
#include "ppl_c.h"
#include "cloog/cloog.h"
#include "graphite-ppl.h"
ppl_Linear_Expression_add_to_inhomogeneous (expr, coef);
ppl_delete_Coefficient (coef);
- if (value_zero_p (matrix->p[row][0]))
+ if (mpz_sgn (matrix->p[row][0]))
ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_EQUAL);
else
ppl_new_Constraint (&cstr, expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL);
/* Do not oppose the first column: it is the eq/ineq one. */
for (k = 1; k < m->NbColumns; k++)
- value_oppose (m->p[row][k], m->p[row][k]);
+ mpz_neg (m->p[row][k], m->p[row][k]);
}
/* Inserts constraint CSTR at row ROW of matrix M. */
}
for (i = dim; i < nb_cols - 1; i++)
- value_set_si (m->p[row][i + 1], 0);
+ mpz_set_si (m->p[row][i + 1], 0);
ppl_Constraint_inhomogeneous_term (cstr, c);
ppl_Coefficient_to_mpz_t (c, m->p[row][nb_cols - 1]);
- value_set_si (m->p[row][0], 1);
+ mpz_set_si (m->p[row][0], 1);
switch (ppl_Constraint_type (cstr))
{
case PPL_CONSTRAINT_TYPE_LESS_THAN:
oppose_constraint (m, row);
case PPL_CONSTRAINT_TYPE_GREATER_THAN:
- value_sub_int (m->p[row][nb_cols - 1],
+ mpz_sub_ui (m->p[row][nb_cols - 1],
m->p[row][nb_cols - 1], 1);
break;
break;
case PPL_CONSTRAINT_TYPE_EQUAL:
- value_set_si (m->p[row][0], 0);
+ mpz_set_si (m->p[row][0], 0);
break;
default:
/* Set the inhomogeneous term of E to X. */
void
-ppl_set_inhomogeneous_gmp (ppl_Linear_Expression_t e, Value x)
+ppl_set_inhomogeneous_gmp (ppl_Linear_Expression_t e, mpz_t x)
{
- Value v0, v1;
+ mpz_t v0, v1;
ppl_Coefficient_t c;
- value_init (v0);
- value_init (v1);
+ mpz_init (v0);
+ mpz_init (v1);
ppl_new_Coefficient (&c);
ppl_Linear_Expression_inhomogeneous_term (e, c);
ppl_Coefficient_to_mpz_t (c, v1);
- value_oppose (v1, v1);
- value_assign (v0, x);
- value_addto (v0, v0, v1);
+ mpz_neg (v1, v1);
+ mpz_set (v0, x);
+ mpz_add (v0, v0, v1);
ppl_assign_Coefficient_from_mpz_t (c, v0);
ppl_Linear_Expression_add_to_inhomogeneous (e, c);
- value_clear (v0);
- value_clear (v1);
+ mpz_clear (v0);
+ mpz_clear (v1);
ppl_delete_Coefficient (c);
}
/* Set E[I] to X. */
void
-ppl_set_coef_gmp (ppl_Linear_Expression_t e, ppl_dimension_type i, Value x)
+ppl_set_coef_gmp (ppl_Linear_Expression_t e, ppl_dimension_type i, mpz_t x)
{
- Value v0, v1;
+ mpz_t v0, v1;
ppl_Coefficient_t c;
- value_init (v0);
- value_init (v1);
+ mpz_init (v0);
+ mpz_init (v1);
ppl_new_Coefficient (&c);
ppl_Linear_Expression_coefficient (e, i, c);
ppl_Coefficient_to_mpz_t (c, v1);
- value_oppose (v1, v1);
- value_assign (v0, x);
- value_addto (v0, v0, v1);
+ mpz_neg (v1, v1);
+ mpz_set (v0, x);
+ mpz_add (v0, v0, v1);
ppl_assign_Coefficient_from_mpz_t (c, v0);
ppl_Linear_Expression_add_to_coefficient (e, i, c);
- value_clear (v0);
- value_clear (v1);
+ mpz_clear (v0);
+ mpz_clear (v1);
ppl_delete_Coefficient (c);
}
ppl_dimension_type dim;
ppl_Polyhedron_t res;
ppl_Coefficient_t c;
- Value val;
+ mpz_t val;
- value_init (val);
+ mpz_init (val);
ppl_new_Coefficient (&c);
ppl_Polyhedron_space_dimension (ph, &dim);
ppl_Linear_Expression_coefficient (expr, loop, c);
ppl_delete_Linear_Expression (expr);
ppl_Coefficient_to_mpz_t (c, val);
- v = value_get_si (val);
+ v = mpz_get_si (val);
if (0 < v || v < 0)
ppl_Polyhedron_add_constraint (tmp, cstr);
ppl_delete_Constraint (new_cstr);
}
- value_clear (val);
+ mpz_clear (val);
ppl_delete_Coefficient (c);
return res;
}
ppl_dimension_type i;
ppl_Coefficient_t c;
int res;
- Value va, vb;
+ mpz_t va, vb;
ppl_Linear_Expression_space_dimension (a, &length1);
ppl_Linear_Expression_space_dimension (b, &length2);
ppl_new_Coefficient (&c);
- value_init (va);
- value_init (vb);
+ mpz_init (va);
+ mpz_init (vb);
if (length1 < length2)
min_length = length1;
ppl_Coefficient_to_mpz_t (c, va);
ppl_Linear_Expression_coefficient (b, i, c);
ppl_Coefficient_to_mpz_t (c, vb);
- res = value_compare (va, vb);
+ res = mpz_cmp (va, vb);
if (res == 0)
continue;
- value_clear (va);
- value_clear (vb);
+ mpz_clear (va);
+ mpz_clear (vb);
ppl_delete_Coefficient (c);
return res;
}
- value_clear (va);
- value_clear (vb);
+ mpz_clear (va);
+ mpz_clear (vb);
ppl_delete_Coefficient (c);
return length1 - length2;
}
/* Print to STDERR the linear expression LE. */
-void
+DEBUG_FUNCTION void
debug_ppl_linear_expr (ppl_Linear_Expression_t le)
{
ppl_print_linear_expr (stderr, le);
ppl_print_powerset_matrix (FILE *file,
ppl_Pointset_Powerset_C_Polyhedron_t ps)
{
+ size_t nb_disjuncts;
ppl_Pointset_Powerset_C_Polyhedron_iterator_t it, end;
ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&it);
ppl_new_Pointset_Powerset_C_Polyhedron_iterator (&end);
+ ppl_Pointset_Powerset_C_Polyhedron_size (ps, &nb_disjuncts);
+ fprintf (file, "%d\n", (int) nb_disjuncts);
+
for (ppl_Pointset_Powerset_C_Polyhedron_iterator_begin (ps, it),
ppl_Pointset_Powerset_C_Polyhedron_iterator_end (ps, end);
!ppl_Pointset_Powerset_C_Polyhedron_iterator_equal_test (it, end);
/* Print to STDERR the polyhedron PH under its PolyLib matrix form. */
-void
+DEBUG_FUNCTION void
debug_ppl_polyhedron_matrix (ppl_Polyhedron_t ph)
{
ppl_print_polyhedron_matrix (stderr, ph);
/* Print to STDERR the powerset PS in its PolyLib matrix form. */
-void
+DEBUG_FUNCTION void
debug_ppl_powerset_matrix (ppl_Pointset_Powerset_C_Polyhedron_t ps)
{
ppl_print_powerset_matrix (stderr, ps);
void
ppl_max_for_le_pointset (ppl_Pointset_Powerset_C_Polyhedron_t ps,
- ppl_Linear_Expression_t le, Value res)
+ ppl_Linear_Expression_t le, mpz_t res)
{
ppl_Coefficient_t num, denom;
- Value dv, nv;
+ mpz_t dv, nv;
int maximum, err;
- value_init (nv);
- value_init (dv);
+ mpz_init (nv);
+ mpz_init (dv);
ppl_new_Coefficient (&num);
ppl_new_Coefficient (&denom);
err = ppl_Pointset_Powerset_C_Polyhedron_maximize (ps, le, num, denom, &maximum);
ppl_Coefficient_to_mpz_t (num, nv);
ppl_Coefficient_to_mpz_t (denom, dv);
gcc_assert (value_notzero_p (dv));
- value_division (res, nv, dv);
+ mpz_tdiv_q (res, nv, dv);
}
- value_clear (nv);
- value_clear (dv);
+ mpz_clear (nv);
+ mpz_clear (dv);
ppl_delete_Coefficient (num);
ppl_delete_Coefficient (denom);
}
polyhedron POL. */
void
-ppl_min_for_le_polyhedron (ppl_Polyhedron_t pol,
- ppl_Linear_Expression_t le, Value res)
+ppl_min_for_le_pointset (ppl_Pointset_Powerset_C_Polyhedron_t ps,
+ ppl_Linear_Expression_t le, mpz_t res)
{
ppl_Coefficient_t num, denom;
- Value dv, nv;
- int maximum, err;
+ mpz_t dv, nv;
+ int minimum, err;
- value_init (nv);
- value_init (dv);
+ mpz_init (nv);
+ mpz_init (dv);
ppl_new_Coefficient (&num);
ppl_new_Coefficient (&denom);
- err = ppl_Polyhedron_minimize (pol, le, num, denom, &maximum);
+ err = ppl_Pointset_Powerset_C_Polyhedron_minimize (ps, le, num, denom, &minimum);
if (err > 0)
{
ppl_Coefficient_to_mpz_t (num, nv);
ppl_Coefficient_to_mpz_t (denom, dv);
gcc_assert (value_notzero_p (dv));
- value_division (res, nv, dv);
+ mpz_tdiv_q (res, nv, dv);
}
- value_clear (nv);
- value_clear (dv);
+ mpz_clear (nv);
+ mpz_clear (dv);
ppl_delete_Coefficient (num);
ppl_delete_Coefficient (denom);
}
+/* Builds a constraint in dimension DIM relating dimensions POS1 to
+ POS2 as "POS1 - POS2 + C CSTR_TYPE 0" */
+
+ppl_Constraint_t
+ppl_build_relation (int dim, int pos1, int pos2, int c,
+ enum ppl_enum_Constraint_Type cstr_type)
+{
+ ppl_Linear_Expression_t expr;
+ ppl_Constraint_t cstr;
+ ppl_Coefficient_t coef;
+ mpz_t v, v_op, v_c;
+
+ mpz_init (v);
+ mpz_init (v_op);
+ mpz_init (v_c);
+
+ mpz_set_si (v, 1);
+ mpz_set_si (v_op, -1);
+ mpz_set_si (v_c, c);
+
+ ppl_new_Coefficient (&coef);
+ ppl_new_Linear_Expression_with_dimension (&expr, dim);
+
+ ppl_assign_Coefficient_from_mpz_t (coef, v);
+ ppl_Linear_Expression_add_to_coefficient (expr, pos1, coef);
+ ppl_assign_Coefficient_from_mpz_t (coef, v_op);
+ ppl_Linear_Expression_add_to_coefficient (expr, pos2, coef);
+ ppl_assign_Coefficient_from_mpz_t (coef, v_c);
+ ppl_Linear_Expression_add_to_inhomogeneous (expr, coef);
+
+ ppl_new_Constraint (&cstr, expr, cstr_type);
+
+ ppl_delete_Linear_Expression (expr);
+ ppl_delete_Coefficient (coef);
+ mpz_clear (v);
+ mpz_clear (v_op);
+ mpz_clear (v_c);
+
+ return cstr;
+}
#endif