1 /* Chains of recurrences.
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <s.pop@laposte.net>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* This file implements operations on chains of recurrences. Chains
23 of recurrences are used for modeling evolution functions of scalar
29 #include "coretypes.h"
34 #include "diagnostic.h"
36 #include "tree-chrec.h"
37 #include "tree-pass.h"
41 /* Extended folder for chrecs. */
43 /* Determines whether CST is not a constant evolution. */
46 is_not_constant_evolution (tree cst
)
48 return (TREE_CODE (cst
) == POLYNOMIAL_CHREC
);
51 /* Fold CODE for a polynomial function and a constant. */
54 chrec_fold_poly_cst (enum tree_code code
,
61 gcc_assert (TREE_CODE (poly
) == POLYNOMIAL_CHREC
);
62 gcc_assert (!is_not_constant_evolution (cst
));
67 return build_polynomial_chrec
68 (CHREC_VARIABLE (poly
),
69 chrec_fold_plus (type
, CHREC_LEFT (poly
), cst
),
73 return build_polynomial_chrec
74 (CHREC_VARIABLE (poly
),
75 chrec_fold_minus (type
, CHREC_LEFT (poly
), cst
),
79 return build_polynomial_chrec
80 (CHREC_VARIABLE (poly
),
81 chrec_fold_multiply (type
, CHREC_LEFT (poly
), cst
),
82 chrec_fold_multiply (type
, CHREC_RIGHT (poly
), cst
));
85 return chrec_dont_know
;
89 /* Fold the addition of two polynomial functions. */
92 chrec_fold_plus_poly_poly (enum tree_code code
,
101 gcc_assert (TREE_CODE (poly0
) == POLYNOMIAL_CHREC
);
102 gcc_assert (TREE_CODE (poly1
) == POLYNOMIAL_CHREC
);
105 {a, +, b}_1 + {c, +, d}_2 -> {{a, +, b}_1 + c, +, d}_2,
106 {a, +, b}_2 + {c, +, d}_1 -> {{c, +, d}_1 + a, +, b}_2,
107 {a, +, b}_x + {c, +, d}_x -> {a+c, +, b+d}_x. */
108 if (CHREC_VARIABLE (poly0
) < CHREC_VARIABLE (poly1
))
110 if (code
== PLUS_EXPR
)
111 return build_polynomial_chrec
112 (CHREC_VARIABLE (poly1
),
113 chrec_fold_plus (type
, poly0
, CHREC_LEFT (poly1
)),
114 CHREC_RIGHT (poly1
));
116 return build_polynomial_chrec
117 (CHREC_VARIABLE (poly1
),
118 chrec_fold_minus (type
, poly0
, CHREC_LEFT (poly1
)),
119 chrec_fold_multiply (type
, CHREC_RIGHT (poly1
),
120 convert (type
, integer_minus_one_node
)));
123 if (CHREC_VARIABLE (poly0
) > CHREC_VARIABLE (poly1
))
125 if (code
== PLUS_EXPR
)
126 return build_polynomial_chrec
127 (CHREC_VARIABLE (poly0
),
128 chrec_fold_plus (type
, CHREC_LEFT (poly0
), poly1
),
129 CHREC_RIGHT (poly0
));
131 return build_polynomial_chrec
132 (CHREC_VARIABLE (poly0
),
133 chrec_fold_minus (type
, CHREC_LEFT (poly0
), poly1
),
134 CHREC_RIGHT (poly0
));
137 if (code
== PLUS_EXPR
)
139 left
= chrec_fold_plus
140 (type
, CHREC_LEFT (poly0
), CHREC_LEFT (poly1
));
141 right
= chrec_fold_plus
142 (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
));
146 left
= chrec_fold_minus
147 (type
, CHREC_LEFT (poly0
), CHREC_LEFT (poly1
));
148 right
= chrec_fold_minus
149 (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
));
152 if (chrec_zerop (right
))
155 return build_polynomial_chrec
156 (CHREC_VARIABLE (poly0
), left
, right
);
161 /* Fold the multiplication of two polynomial functions. */
164 chrec_fold_multiply_poly_poly (tree type
,
170 gcc_assert (TREE_CODE (poly0
) == POLYNOMIAL_CHREC
);
171 gcc_assert (TREE_CODE (poly1
) == POLYNOMIAL_CHREC
);
173 /* {a, +, b}_1 * {c, +, d}_2 -> {c*{a, +, b}_1, +, d}_2,
174 {a, +, b}_2 * {c, +, d}_1 -> {a*{c, +, d}_1, +, b}_2,
175 {a, +, b}_x * {c, +, d}_x -> {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x. */
176 if (CHREC_VARIABLE (poly0
) < CHREC_VARIABLE (poly1
))
177 /* poly0 is a constant wrt. poly1. */
178 return build_polynomial_chrec
179 (CHREC_VARIABLE (poly1
),
180 chrec_fold_multiply (type
, CHREC_LEFT (poly1
), poly0
),
181 CHREC_RIGHT (poly1
));
183 if (CHREC_VARIABLE (poly1
) < CHREC_VARIABLE (poly0
))
184 /* poly1 is a constant wrt. poly0. */
185 return build_polynomial_chrec
186 (CHREC_VARIABLE (poly0
),
187 chrec_fold_multiply (type
, CHREC_LEFT (poly0
), poly1
),
188 CHREC_RIGHT (poly0
));
190 /* poly0 and poly1 are two polynomials in the same variable,
191 {a, +, b}_x * {c, +, d}_x -> {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x. */
193 build_polynomial_chrec
194 (CHREC_VARIABLE (poly0
),
195 build_polynomial_chrec
196 (CHREC_VARIABLE (poly0
),
199 chrec_fold_multiply (type
, CHREC_LEFT (poly0
), CHREC_LEFT (poly1
)),
201 /* "a*d + b*c + b*d". */
203 (type
, chrec_fold_multiply (type
, CHREC_LEFT (poly0
), CHREC_RIGHT (poly1
)),
207 chrec_fold_multiply (type
, CHREC_RIGHT (poly0
), CHREC_LEFT (poly1
)),
208 chrec_fold_multiply (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
))))),
212 (type
, build_int_cst (NULL_TREE
, 2),
213 chrec_fold_multiply (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
))));
216 /* When the operands are automatically_generated_chrec_p, the fold has
217 to respect the semantics of the operands. */
220 chrec_fold_automatically_generated_operands (tree op0
,
223 if (op0
== chrec_dont_know
224 || op1
== chrec_dont_know
)
225 return chrec_dont_know
;
227 if (op0
== chrec_known
228 || op1
== chrec_known
)
231 if (op0
== chrec_not_analyzed_yet
232 || op1
== chrec_not_analyzed_yet
)
233 return chrec_not_analyzed_yet
;
235 /* The default case produces a safe result. */
236 return chrec_dont_know
;
239 /* Fold the addition of two chrecs. */
242 chrec_fold_plus_1 (enum tree_code code
,
247 if (automatically_generated_chrec_p (op0
)
248 || automatically_generated_chrec_p (op1
))
249 return chrec_fold_automatically_generated_operands (op0
, op1
);
251 switch (TREE_CODE (op0
))
253 case POLYNOMIAL_CHREC
:
254 switch (TREE_CODE (op1
))
256 case POLYNOMIAL_CHREC
:
257 return chrec_fold_plus_poly_poly (code
, type
, op0
, op1
);
260 if (code
== PLUS_EXPR
)
261 return build_polynomial_chrec
262 (CHREC_VARIABLE (op0
),
263 chrec_fold_plus (type
, CHREC_LEFT (op0
), op1
),
266 return build_polynomial_chrec
267 (CHREC_VARIABLE (op0
),
268 chrec_fold_minus (type
, CHREC_LEFT (op0
), op1
),
273 switch (TREE_CODE (op1
))
275 case POLYNOMIAL_CHREC
:
276 if (code
== PLUS_EXPR
)
277 return build_polynomial_chrec
278 (CHREC_VARIABLE (op1
),
279 chrec_fold_plus (type
, op0
, CHREC_LEFT (op1
)),
282 return build_polynomial_chrec
283 (CHREC_VARIABLE (op1
),
284 chrec_fold_minus (type
, op0
, CHREC_LEFT (op1
)),
285 chrec_fold_multiply (type
, CHREC_RIGHT (op1
),
287 integer_minus_one_node
)));
290 if (tree_contains_chrecs (op0
)
291 || tree_contains_chrecs (op1
))
292 return build (code
, type
, op0
, op1
);
294 return fold (build (code
, type
, op0
, op1
));
299 /* Fold the addition of two chrecs. */
302 chrec_fold_plus (tree type
,
306 if (integer_zerop (op0
))
308 if (integer_zerop (op1
))
311 return chrec_fold_plus_1 (PLUS_EXPR
, type
, op0
, op1
);
314 /* Fold the subtraction of two chrecs. */
317 chrec_fold_minus (tree type
,
321 if (integer_zerop (op1
))
324 return chrec_fold_plus_1 (MINUS_EXPR
, type
, op0
, op1
);
327 /* Fold the multiplication of two chrecs. */
330 chrec_fold_multiply (tree type
,
334 if (automatically_generated_chrec_p (op0
)
335 || automatically_generated_chrec_p (op1
))
336 return chrec_fold_automatically_generated_operands (op0
, op1
);
338 switch (TREE_CODE (op0
))
340 case POLYNOMIAL_CHREC
:
341 switch (TREE_CODE (op1
))
343 case POLYNOMIAL_CHREC
:
344 return chrec_fold_multiply_poly_poly (type
, op0
, op1
);
347 if (integer_onep (op1
))
349 if (integer_zerop (op1
))
350 return convert (type
, integer_zero_node
);
352 return build_polynomial_chrec
353 (CHREC_VARIABLE (op0
),
354 chrec_fold_multiply (type
, CHREC_LEFT (op0
), op1
),
355 chrec_fold_multiply (type
, CHREC_RIGHT (op0
), op1
));
359 if (integer_onep (op0
))
362 if (integer_zerop (op0
))
363 return convert (type
, integer_zero_node
);
365 switch (TREE_CODE (op1
))
367 case POLYNOMIAL_CHREC
:
368 return build_polynomial_chrec
369 (CHREC_VARIABLE (op1
),
370 chrec_fold_multiply (type
, CHREC_LEFT (op1
), op0
),
371 chrec_fold_multiply (type
, CHREC_RIGHT (op1
), op0
));
374 if (integer_onep (op1
))
376 if (integer_zerop (op1
))
377 return convert (type
, integer_zero_node
);
378 return fold (build (MULT_EXPR
, type
, op0
, op1
));
390 tree_fold_factorial (tree f
)
392 if (tree_int_cst_sgn (f
) <= 0)
393 return integer_one_node
;
396 (build (MULT_EXPR
, integer_type_node
, f
,
397 tree_fold_factorial (fold (build (MINUS_EXPR
, integer_type_node
,
398 f
, integer_one_node
)))));
401 /* The binomial coefficient. */
404 tree_fold_binomial (tree n
,
408 (build (EXACT_DIV_EXPR
, integer_type_node
, tree_fold_factorial (n
),
409 fold (build (MULT_EXPR
, integer_type_node
,
410 tree_fold_factorial (k
),
412 (fold (build (MINUS_EXPR
, integer_type_node
,
416 /* Helper function. Use the Newton's interpolating formula for
417 evaluating the value of the evolution function. */
420 chrec_evaluate (unsigned var
,
425 tree type
= chrec_type (chrec
);
426 tree binomial_n_k
= tree_fold_binomial (n
, k
);
428 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
430 if (CHREC_VARIABLE (chrec
) > var
)
431 return chrec_evaluate (var
, CHREC_LEFT (chrec
), n
, k
);
433 if (CHREC_VARIABLE (chrec
) == var
)
434 return chrec_fold_plus
436 fold (build (MULT_EXPR
, type
, binomial_n_k
, CHREC_LEFT (chrec
))),
437 chrec_evaluate (var
, CHREC_RIGHT (chrec
), n
,
438 fold (build (PLUS_EXPR
, type
, k
, integer_one_node
))));
440 return fold (build (MULT_EXPR
, type
, binomial_n_k
, chrec
));
443 return fold (build (MULT_EXPR
, type
, binomial_n_k
, chrec
));
446 /* Evaluates "CHREC (X)" when the varying variable is VAR.
447 Example: Given the following parameters,
453 The result is given by the Newton's interpolating formula:
454 3 * \binom{10}{0} + 4 * \binom{10}{1}.
458 chrec_apply (unsigned var
,
462 tree type
= chrec_type (chrec
);
463 tree res
= chrec_dont_know
;
465 if (automatically_generated_chrec_p (chrec
)
466 || automatically_generated_chrec_p (x
)
468 /* When the symbols are defined in an outer loop, it is possible
469 to symbolically compute the apply, since the symbols are
470 constants with respect to the varying loop. */
471 || chrec_contains_symbols_defined_in_loop (chrec
, var
)
472 || chrec_contains_symbols (x
))
473 return chrec_dont_know
;
475 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
476 fprintf (dump_file
, "(chrec_apply \n");
478 if (evolution_function_is_affine_p (chrec
))
480 /* "{a, +, b} (x)" -> "a + b*x". */
481 if (TREE_CODE (CHREC_LEFT (chrec
)) == INTEGER_CST
482 && integer_zerop (CHREC_LEFT (chrec
)))
483 res
= chrec_fold_multiply (type
, CHREC_RIGHT (chrec
), x
);
486 res
= chrec_fold_plus (type
, CHREC_LEFT (chrec
),
487 chrec_fold_multiply (type
,
488 CHREC_RIGHT (chrec
), x
));
491 else if (TREE_CODE (chrec
) != POLYNOMIAL_CHREC
)
494 else if (TREE_CODE (x
) == INTEGER_CST
495 && tree_int_cst_sgn (x
) == 1)
496 /* testsuite/.../ssa-chrec-38.c. */
497 res
= chrec_evaluate (var
, chrec
, x
, integer_zero_node
);
500 res
= chrec_dont_know
;
502 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
504 fprintf (dump_file
, " (varying_loop = %d\n", var
);
505 fprintf (dump_file
, ")\n (chrec = ");
506 print_generic_expr (dump_file
, chrec
, 0);
507 fprintf (dump_file
, ")\n (x = ");
508 print_generic_expr (dump_file
, x
, 0);
509 fprintf (dump_file
, ")\n (res = ");
510 print_generic_expr (dump_file
, res
, 0);
511 fprintf (dump_file
, "))\n");
517 /* Replaces the initial condition in CHREC with INIT_COND. */
520 chrec_replace_initial_condition (tree chrec
,
523 if (automatically_generated_chrec_p (chrec
))
526 switch (TREE_CODE (chrec
))
528 case POLYNOMIAL_CHREC
:
529 return build_polynomial_chrec
530 (CHREC_VARIABLE (chrec
),
531 chrec_replace_initial_condition (CHREC_LEFT (chrec
), init_cond
),
532 CHREC_RIGHT (chrec
));
539 /* Returns the initial condition of a given CHREC. */
542 initial_condition (tree chrec
)
544 if (automatically_generated_chrec_p (chrec
))
547 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
548 return initial_condition (CHREC_LEFT (chrec
));
553 /* Returns a univariate function that represents the evolution in
554 LOOP_NUM. Mask the evolution of any other loop. */
557 hide_evolution_in_other_loops_than_loop (tree chrec
,
560 if (automatically_generated_chrec_p (chrec
))
563 switch (TREE_CODE (chrec
))
565 case POLYNOMIAL_CHREC
:
566 if (CHREC_VARIABLE (chrec
) == loop_num
)
567 return build_polynomial_chrec
569 hide_evolution_in_other_loops_than_loop (CHREC_LEFT (chrec
),
571 CHREC_RIGHT (chrec
));
573 else if (CHREC_VARIABLE (chrec
) < loop_num
)
574 /* There is no evolution in this loop. */
575 return initial_condition (chrec
);
578 return hide_evolution_in_other_loops_than_loop (CHREC_LEFT (chrec
),
586 /* Returns the evolution part of CHREC in LOOP_NUM when RIGHT is
587 true, otherwise returns the initial condition in LOOP_NUM. */
590 chrec_component_in_loop_num (tree chrec
,
596 if (automatically_generated_chrec_p (chrec
))
599 switch (TREE_CODE (chrec
))
601 case POLYNOMIAL_CHREC
:
602 if (CHREC_VARIABLE (chrec
) == loop_num
)
605 component
= CHREC_RIGHT (chrec
);
607 component
= CHREC_LEFT (chrec
);
609 if (TREE_CODE (CHREC_LEFT (chrec
)) != POLYNOMIAL_CHREC
610 || CHREC_VARIABLE (CHREC_LEFT (chrec
)) != CHREC_VARIABLE (chrec
))
614 return build_polynomial_chrec
616 chrec_component_in_loop_num (CHREC_LEFT (chrec
),
622 else if (CHREC_VARIABLE (chrec
) < loop_num
)
623 /* There is no evolution part in this loop. */
627 return chrec_component_in_loop_num (CHREC_LEFT (chrec
),
639 /* Returns the evolution part in LOOP_NUM. Example: the call
640 evolution_part_in_loop_num (1, {{0, +, 1}_1, +, 2}_1) returns
644 evolution_part_in_loop_num (tree chrec
,
647 return chrec_component_in_loop_num (chrec
, loop_num
, true);
650 /* Returns the initial condition in LOOP_NUM. Example: the call
651 initial_condition_in_loop_num ({{0, +, 1}_1, +, 2}_2, 1) returns
655 initial_condition_in_loop_num (tree chrec
,
658 return chrec_component_in_loop_num (chrec
, loop_num
, false);
661 /* Set or reset the evolution of CHREC to NEW_EVOL in loop LOOP_NUM.
662 This function is essentially used for setting the evolution to
663 chrec_dont_know, for example after having determined that it is
664 impossible to say how many times a loop will execute. */
667 reset_evolution_in_loop (unsigned loop_num
,
671 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
672 && CHREC_VARIABLE (chrec
) > loop_num
)
675 build_int_cst (NULL_TREE
, CHREC_VARIABLE (chrec
)),
676 reset_evolution_in_loop (loop_num
, CHREC_LEFT (chrec
), new_evol
),
677 reset_evolution_in_loop (loop_num
, CHREC_RIGHT (chrec
), new_evol
));
679 while (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
680 && CHREC_VARIABLE (chrec
) == loop_num
)
681 chrec
= CHREC_LEFT (chrec
);
683 return build_polynomial_chrec (loop_num
, chrec
, new_evol
);
686 /* Merges two evolution functions that were found by following two
687 alternate paths of a conditional expression. */
690 chrec_merge (tree chrec1
,
693 if (chrec1
== chrec_dont_know
694 || chrec2
== chrec_dont_know
)
695 return chrec_dont_know
;
697 if (chrec1
== chrec_known
698 || chrec2
== chrec_known
)
701 if (chrec1
== chrec_not_analyzed_yet
)
703 if (chrec2
== chrec_not_analyzed_yet
)
706 if (operand_equal_p (chrec1
, chrec2
, 0))
709 return chrec_dont_know
;
716 /* Helper function for is_multivariate_chrec. */
719 is_multivariate_chrec_rec (tree chrec
, unsigned int rec_var
)
721 if (chrec
== NULL_TREE
)
724 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
726 if (CHREC_VARIABLE (chrec
) != rec_var
)
729 return (is_multivariate_chrec_rec (CHREC_LEFT (chrec
), rec_var
)
730 || is_multivariate_chrec_rec (CHREC_RIGHT (chrec
), rec_var
));
736 /* Determine whether the given chrec is multivariate or not. */
739 is_multivariate_chrec (tree chrec
)
741 if (chrec
== NULL_TREE
)
744 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
745 return (is_multivariate_chrec_rec (CHREC_LEFT (chrec
),
746 CHREC_VARIABLE (chrec
))
747 || is_multivariate_chrec_rec (CHREC_RIGHT (chrec
),
748 CHREC_VARIABLE (chrec
)));
753 /* Determines whether the chrec contains symbolic names or not. */
756 chrec_contains_symbols (tree chrec
)
758 if (chrec
== NULL_TREE
)
761 if (TREE_CODE (chrec
) == SSA_NAME
762 || TREE_CODE (chrec
) == VAR_DECL
763 || TREE_CODE (chrec
) == PARM_DECL
764 || TREE_CODE (chrec
) == FUNCTION_DECL
765 || TREE_CODE (chrec
) == LABEL_DECL
766 || TREE_CODE (chrec
) == RESULT_DECL
767 || TREE_CODE (chrec
) == FIELD_DECL
)
770 switch (TREE_CODE_LENGTH (TREE_CODE (chrec
)))
773 if (chrec_contains_symbols (TREE_OPERAND (chrec
, 2)))
777 if (chrec_contains_symbols (TREE_OPERAND (chrec
, 1)))
781 if (chrec_contains_symbols (TREE_OPERAND (chrec
, 0)))
789 /* Determines whether the chrec contains undetermined coefficients. */
792 chrec_contains_undetermined (tree chrec
)
794 if (chrec
== chrec_dont_know
795 || chrec
== chrec_not_analyzed_yet
796 || chrec
== NULL_TREE
)
799 switch (TREE_CODE_LENGTH (TREE_CODE (chrec
)))
802 if (chrec_contains_undetermined (TREE_OPERAND (chrec
, 2)))
806 if (chrec_contains_undetermined (TREE_OPERAND (chrec
, 1)))
810 if (chrec_contains_undetermined (TREE_OPERAND (chrec
, 0)))
818 /* Determines whether the tree EXPR contains chrecs. */
821 tree_contains_chrecs (tree expr
)
823 if (expr
== NULL_TREE
)
826 if (tree_is_chrec (expr
))
829 switch (TREE_CODE_LENGTH (TREE_CODE (expr
)))
832 if (tree_contains_chrecs (TREE_OPERAND (expr
, 2)))
836 if (tree_contains_chrecs (TREE_OPERAND (expr
, 1)))
840 if (tree_contains_chrecs (TREE_OPERAND (expr
, 0)))
848 /* Determine whether the given tree is an affine multivariate
852 evolution_function_is_affine_multivariate_p (tree chrec
)
854 if (chrec
== NULL_TREE
)
857 switch (TREE_CODE (chrec
))
859 case POLYNOMIAL_CHREC
:
860 if (evolution_function_is_constant_p (CHREC_LEFT (chrec
)))
862 if (evolution_function_is_constant_p (CHREC_RIGHT (chrec
)))
866 if (TREE_CODE (CHREC_RIGHT (chrec
)) == POLYNOMIAL_CHREC
867 && CHREC_VARIABLE (CHREC_RIGHT (chrec
))
868 != CHREC_VARIABLE (chrec
)
869 && evolution_function_is_affine_multivariate_p
870 (CHREC_RIGHT (chrec
)))
878 if (evolution_function_is_constant_p (CHREC_RIGHT (chrec
))
879 && TREE_CODE (CHREC_LEFT (chrec
)) == POLYNOMIAL_CHREC
880 && CHREC_VARIABLE (CHREC_LEFT (chrec
)) != CHREC_VARIABLE (chrec
)
881 && evolution_function_is_affine_multivariate_p
882 (CHREC_LEFT (chrec
)))
893 /* Determine whether the given tree is a function in zero or one
897 evolution_function_is_univariate_p (tree chrec
)
899 if (chrec
== NULL_TREE
)
902 switch (TREE_CODE (chrec
))
904 case POLYNOMIAL_CHREC
:
905 switch (TREE_CODE (CHREC_LEFT (chrec
)))
907 case POLYNOMIAL_CHREC
:
908 if (CHREC_VARIABLE (chrec
) != CHREC_VARIABLE (CHREC_LEFT (chrec
)))
910 if (!evolution_function_is_univariate_p (CHREC_LEFT (chrec
)))
918 switch (TREE_CODE (CHREC_RIGHT (chrec
)))
920 case POLYNOMIAL_CHREC
:
921 if (CHREC_VARIABLE (chrec
) != CHREC_VARIABLE (CHREC_RIGHT (chrec
)))
923 if (!evolution_function_is_univariate_p (CHREC_RIGHT (chrec
)))
938 /* Convert the initial condition of chrec to type. */
941 chrec_convert (tree type
,
946 if (automatically_generated_chrec_p (chrec
))
949 ct
= chrec_type (chrec
);
953 if (TYPE_PRECISION (ct
) < TYPE_PRECISION (type
))
954 return count_ev_in_wider_type (type
, chrec
);
956 switch (TREE_CODE (chrec
))
958 case POLYNOMIAL_CHREC
:
959 return build_polynomial_chrec (CHREC_VARIABLE (chrec
),
963 CHREC_RIGHT (chrec
)));
967 tree res
= convert (type
, chrec
);
969 /* Don't propagate overflows. */
970 TREE_OVERFLOW (res
) = 0;
971 if (CONSTANT_CLASS_P (res
))
972 TREE_CONSTANT_OVERFLOW (res
) = 0;
978 /* Returns the type of the chrec. */
981 chrec_type (tree chrec
)
983 if (automatically_generated_chrec_p (chrec
))
986 return TREE_TYPE (chrec
);