+/* 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}. */
+
+static void
+build_partial_difference (ppl_Pointset_Powerset_C_Polyhedron_t *p,
+ ppl_dimension_type time_depth,
+ ppl_dimension_type offset,
+ ppl_dimension_type dim_sctr)
+{
+ ppl_Constraint_t new_cstr;
+ ppl_Linear_Expression_t le;
+ ppl_dimension_type i;
+ ppl_dimension_type dim;
+ ppl_Pointset_Powerset_C_Polyhedron_t temp;
+
+ /* 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. */
+
+ ppl_Pointset_Powerset_C_Polyhedron_space_dimension (*p, &dim);
+ ppl_new_Linear_Expression_with_dimension (&le, dim);
+ ppl_set_coef (le, time_depth, 1);
+ ppl_set_coef (le, time_depth + offset, -1);
+ ppl_set_inhomogeneous (le, 1);
+ ppl_new_Constraint (&new_cstr, le, PPL_CONSTRAINT_TYPE_EQUAL);
+ ppl_Pointset_Powerset_C_Polyhedron_add_constraint (*p, new_cstr);
+ ppl_delete_Linear_Expression (le);
+ ppl_delete_Constraint (new_cstr);
+
+ /* 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 carefull 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. */
+
+ ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron (&temp, *p);
+
+ for (i = 0; i < dim_sctr; i++)
+ if (i != time_depth)
+ {
+ ppl_new_Linear_Expression_with_dimension (&le, dim);
+ ppl_set_coef (le, i, 1);
+ ppl_set_coef (le, i + offset, -1);
+ ppl_new_Constraint (&new_cstr, le, PPL_CONSTRAINT_TYPE_EQUAL);
+ ppl_Pointset_Powerset_C_Polyhedron_add_constraint (temp, new_cstr);
+
+ if (ppl_Pointset_Powerset_C_Polyhedron_is_empty (temp))
+ {
+ ppl_delete_Pointset_Powerset_C_Polyhedron (temp);
+ ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron (&temp, *p);
+ }
+ else
+ ppl_Pointset_Powerset_C_Polyhedron_add_constraint (*p, new_cstr);
+ ppl_delete_Linear_Expression (le);
+ ppl_delete_Constraint (new_cstr);
+ }
+
+ ppl_delete_Pointset_Powerset_C_Polyhedron (temp);
+}
+
+