(CHREC_VARIABLE (poly1),
chrec_fold_minus (type, poly0, CHREC_LEFT (poly1)),
chrec_fold_multiply (type, CHREC_RIGHT (poly1),
- convert (type, integer_minus_one_node)));
+ build_int_cst_type (type, -1)));
}
if (CHREC_VARIABLE (poly0) > CHREC_VARIABLE (poly1))
return build_polynomial_chrec
(CHREC_VARIABLE (op1),
chrec_fold_minus (type, op0, CHREC_LEFT (op1)),
- chrec_fold_multiply (type, CHREC_RIGHT (op1),
- convert (type,
- integer_minus_one_node)));
+ chrec_fold_multiply (type, CHREC_RIGHT (op1),
+ build_int_cst_type (type, -1)));
default:
if (tree_contains_chrecs (op0)
if (integer_onep (op1))
return op0;
if (integer_zerop (op1))
- return convert (type, integer_zero_node);
+ return build_int_cst_type (type, 0);
return build_polynomial_chrec
(CHREC_VARIABLE (op0),
return op1;
if (integer_zerop (op0))
- return convert (type, integer_zero_node);
+ return build_int_cst_type (type, 0);
switch (TREE_CODE (op1))
{
if (integer_onep (op1))
return op0;
if (integer_zerop (op1))
- return convert (type, integer_zero_node);
+ return build_int_cst_type (type, 0);
return fold (build (MULT_EXPR, type, op0, op1));
}
}
}
}
-/* Returns the evolution part in LOOP_NUM. Example: the call
- get_evolution_in_loop (1, {{0, +, 1}_1, +, 2}_1) returns
- {1, +, 2}_1 */
+/* Returns the evolution part of CHREC in LOOP_NUM when RIGHT is
+ true, otherwise returns the initial condition in LOOP_NUM. */
-tree
-evolution_part_in_loop_num (tree chrec,
- unsigned loop_num)
+static tree
+chrec_component_in_loop_num (tree chrec,
+ unsigned loop_num,
+ bool right)
{
+ tree component;
+
if (automatically_generated_chrec_p (chrec))
return chrec;
case POLYNOMIAL_CHREC:
if (CHREC_VARIABLE (chrec) == loop_num)
{
+ if (right)
+ component = CHREC_RIGHT (chrec);
+ else
+ component = CHREC_LEFT (chrec);
+
if (TREE_CODE (CHREC_LEFT (chrec)) != POLYNOMIAL_CHREC
|| CHREC_VARIABLE (CHREC_LEFT (chrec)) != CHREC_VARIABLE (chrec))
- return CHREC_RIGHT (chrec);
+ return component;
else
return build_polynomial_chrec
(loop_num,
- evolution_part_in_loop_num (CHREC_LEFT (chrec), loop_num),
- CHREC_RIGHT (chrec));
+ chrec_component_in_loop_num (CHREC_LEFT (chrec),
+ loop_num,
+ right),
+ component);
}
else if (CHREC_VARIABLE (chrec) < loop_num)
return NULL_TREE;
else
- return evolution_part_in_loop_num (CHREC_LEFT (chrec), loop_num);
+ return chrec_component_in_loop_num (CHREC_LEFT (chrec),
+ loop_num,
+ right);
- default:
- return NULL_TREE;
+ default:
+ if (right)
+ return NULL_TREE;
+ else
+ return chrec;
}
}
+/* Returns the evolution part in LOOP_NUM. Example: the call
+ evolution_part_in_loop_num ({{0, +, 1}_1, +, 2}_1, 1) returns
+ {1, +, 2}_1 */
+
+tree
+evolution_part_in_loop_num (tree chrec,
+ unsigned loop_num)
+{
+ return chrec_component_in_loop_num (chrec, loop_num, true);
+}
+
+/* Returns the initial condition in LOOP_NUM. Example: the call
+ initial_condition_in_loop_num ({{0, +, 1}_1, +, 2}_2, 2) returns
+ {0, +, 1}_1 */
+
+tree
+initial_condition_in_loop_num (tree chrec,
+ unsigned loop_num)
+{
+ return chrec_component_in_loop_num (chrec, loop_num, false);
+}
+
/* Set or reset the evolution of CHREC to NEW_EVOL in loop LOOP_NUM.
This function is essentially used for setting the evolution to
chrec_dont_know, for example after having determined that it is
}
}
+/* Returns the number of variables of CHREC. Example: the call
+ nb_vars_in_chrec ({{0, +, 1}_5, +, 2}_6) returns 2. */
+
+unsigned
+nb_vars_in_chrec (tree chrec)
+{
+ if (chrec == NULL_TREE)
+ return 0;
+
+ switch (TREE_CODE (chrec))
+ {
+ case POLYNOMIAL_CHREC:
+ return 1 + nb_vars_in_chrec
+ (initial_condition_in_loop_num (chrec, CHREC_VARIABLE (chrec)));
+
+ default:
+ return 0;
+ }
+}
+
\f
/* Convert the initial condition of chrec to type. */