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
,
59 #if defined ENABLE_CHECKING
62 || TREE_CODE (poly
) != POLYNOMIAL_CHREC
63 || is_not_constant_evolution (cst
))
70 return build_polynomial_chrec
71 (CHREC_VARIABLE (poly
),
72 chrec_fold_plus (type
, CHREC_LEFT (poly
), cst
),
76 return build_polynomial_chrec
77 (CHREC_VARIABLE (poly
),
78 chrec_fold_minus (type
, CHREC_LEFT (poly
), cst
),
82 return build_polynomial_chrec
83 (CHREC_VARIABLE (poly
),
84 chrec_fold_multiply (type
, CHREC_LEFT (poly
), cst
),
85 chrec_fold_multiply (type
, CHREC_RIGHT (poly
), cst
));
88 return chrec_dont_know
;
92 /* Fold the addition of two polynomial functions. */
95 chrec_fold_plus_poly_poly (enum tree_code code
,
102 #if defined ENABLE_CHECKING
103 if (poly0
== NULL_TREE
104 || poly1
== NULL_TREE
105 || TREE_CODE (poly0
) != POLYNOMIAL_CHREC
106 || TREE_CODE (poly1
) != POLYNOMIAL_CHREC
)
111 {a, +, b}_1 + {c, +, d}_2 -> {{a, +, b}_1 + c, +, d}_2,
112 {a, +, b}_2 + {c, +, d}_1 -> {{c, +, d}_1 + a, +, b}_2,
113 {a, +, b}_x + {c, +, d}_x -> {a+c, +, b+d}_x. */
114 if (CHREC_VARIABLE (poly0
) < CHREC_VARIABLE (poly1
))
116 if (code
== PLUS_EXPR
)
117 return build_polynomial_chrec
118 (CHREC_VARIABLE (poly1
),
119 chrec_fold_plus (type
, poly0
, CHREC_LEFT (poly1
)),
120 CHREC_RIGHT (poly1
));
122 return build_polynomial_chrec
123 (CHREC_VARIABLE (poly1
),
124 chrec_fold_minus (type
, poly0
, CHREC_LEFT (poly1
)),
125 chrec_fold_multiply (type
, CHREC_RIGHT (poly1
),
126 convert (type
, integer_minus_one_node
)));
129 if (CHREC_VARIABLE (poly0
) > CHREC_VARIABLE (poly1
))
131 if (code
== PLUS_EXPR
)
132 return build_polynomial_chrec
133 (CHREC_VARIABLE (poly0
),
134 chrec_fold_plus (type
, CHREC_LEFT (poly0
), poly1
),
135 CHREC_RIGHT (poly0
));
137 return build_polynomial_chrec
138 (CHREC_VARIABLE (poly0
),
139 chrec_fold_minus (type
, CHREC_LEFT (poly0
), poly1
),
140 CHREC_RIGHT (poly0
));
143 if (code
== PLUS_EXPR
)
145 left
= chrec_fold_plus
146 (type
, CHREC_LEFT (poly0
), CHREC_LEFT (poly1
));
147 right
= chrec_fold_plus
148 (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
));
152 left
= chrec_fold_minus
153 (type
, CHREC_LEFT (poly0
), CHREC_LEFT (poly1
));
154 right
= chrec_fold_minus
155 (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
));
158 if (chrec_zerop (right
))
161 return build_polynomial_chrec
162 (CHREC_VARIABLE (poly0
), left
, right
);
167 /* Fold the multiplication of two polynomial functions. */
170 chrec_fold_multiply_poly_poly (tree type
,
174 #if defined ENABLE_CHECKING
175 if (poly0
== NULL_TREE
176 || poly1
== NULL_TREE
177 || TREE_CODE (poly0
) != POLYNOMIAL_CHREC
178 || TREE_CODE (poly1
) != POLYNOMIAL_CHREC
)
182 /* {a, +, b}_1 * {c, +, d}_2 -> {c*{a, +, b}_1, +, d}_2,
183 {a, +, b}_2 * {c, +, d}_1 -> {a*{c, +, d}_1, +, b}_2,
184 {a, +, b}_x * {c, +, d}_x -> {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x. */
185 if (CHREC_VARIABLE (poly0
) < CHREC_VARIABLE (poly1
))
186 /* poly0 is a constant wrt. poly1. */
187 return build_polynomial_chrec
188 (CHREC_VARIABLE (poly1
),
189 chrec_fold_multiply (type
, CHREC_LEFT (poly1
), poly0
),
190 CHREC_RIGHT (poly1
));
192 if (CHREC_VARIABLE (poly1
) < CHREC_VARIABLE (poly0
))
193 /* poly1 is a constant wrt. poly0. */
194 return build_polynomial_chrec
195 (CHREC_VARIABLE (poly0
),
196 chrec_fold_multiply (type
, CHREC_LEFT (poly0
), poly1
),
197 CHREC_RIGHT (poly0
));
199 /* poly0 and poly1 are two polynomials in the same variable,
200 {a, +, b}_x * {c, +, d}_x -> {a*c, +, a*d + b*c + b*d, +, 2*b*d}_x. */
202 build_polynomial_chrec
203 (CHREC_VARIABLE (poly0
),
204 build_polynomial_chrec
205 (CHREC_VARIABLE (poly0
),
208 chrec_fold_multiply (type
, CHREC_LEFT (poly0
), CHREC_LEFT (poly1
)),
210 /* "a*d + b*c + b*d". */
212 (type
, chrec_fold_multiply (type
, CHREC_LEFT (poly0
), CHREC_RIGHT (poly1
)),
216 chrec_fold_multiply (type
, CHREC_RIGHT (poly0
), CHREC_LEFT (poly1
)),
217 chrec_fold_multiply (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
))))),
221 (type
, build_int_cst (NULL_TREE
, 2, 0),
222 chrec_fold_multiply (type
, CHREC_RIGHT (poly0
), CHREC_RIGHT (poly1
))));
225 /* When the operands are automatically_generated_chrec_p, the fold has
226 to respect the semantics of the operands. */
229 chrec_fold_automatically_generated_operands (tree op0
,
232 if (op0
== chrec_dont_know
233 || op1
== chrec_dont_know
)
234 return chrec_dont_know
;
236 if (op0
== chrec_known
237 || op1
== chrec_known
)
240 if (op0
== chrec_not_analyzed_yet
241 || op1
== chrec_not_analyzed_yet
)
242 return chrec_not_analyzed_yet
;
244 /* The default case produces a safe result. */
245 return chrec_dont_know
;
248 /* Fold the addition of two chrecs. */
251 chrec_fold_plus_1 (enum tree_code code
,
256 if (automatically_generated_chrec_p (op0
)
257 || automatically_generated_chrec_p (op1
))
258 return chrec_fold_automatically_generated_operands (op0
, op1
);
260 switch (TREE_CODE (op0
))
262 case POLYNOMIAL_CHREC
:
263 switch (TREE_CODE (op1
))
265 case POLYNOMIAL_CHREC
:
266 return chrec_fold_plus_poly_poly (code
, type
, op0
, op1
);
269 if (code
== PLUS_EXPR
)
270 return build_polynomial_chrec
271 (CHREC_VARIABLE (op0
),
272 chrec_fold_plus (type
, CHREC_LEFT (op0
), op1
),
275 return build_polynomial_chrec
276 (CHREC_VARIABLE (op0
),
277 chrec_fold_minus (type
, CHREC_LEFT (op0
), op1
),
282 switch (TREE_CODE (op1
))
284 case POLYNOMIAL_CHREC
:
285 if (code
== PLUS_EXPR
)
286 return build_polynomial_chrec
287 (CHREC_VARIABLE (op1
),
288 chrec_fold_plus (type
, op0
, CHREC_LEFT (op1
)),
291 return build_polynomial_chrec
292 (CHREC_VARIABLE (op1
),
293 chrec_fold_minus (type
, op0
, CHREC_LEFT (op1
)),
294 chrec_fold_multiply (type
, CHREC_RIGHT (op1
),
296 integer_minus_one_node
)));
299 if (tree_contains_chrecs (op0
)
300 || tree_contains_chrecs (op1
))
301 return build (code
, type
, op0
, op1
);
303 return fold (build (code
, type
, op0
, op1
));
308 /* Fold the addition of two chrecs. */
311 chrec_fold_plus (tree type
,
315 if (integer_zerop (op0
))
317 if (integer_zerop (op1
))
320 return chrec_fold_plus_1 (PLUS_EXPR
, type
, op0
, op1
);
323 /* Fold the subtraction of two chrecs. */
326 chrec_fold_minus (tree type
,
330 if (integer_zerop (op1
))
333 return chrec_fold_plus_1 (MINUS_EXPR
, type
, op0
, op1
);
336 /* Fold the multiplication of two chrecs. */
339 chrec_fold_multiply (tree type
,
343 if (automatically_generated_chrec_p (op0
)
344 || automatically_generated_chrec_p (op1
))
345 return chrec_fold_automatically_generated_operands (op0
, op1
);
347 switch (TREE_CODE (op0
))
349 case POLYNOMIAL_CHREC
:
350 switch (TREE_CODE (op1
))
352 case POLYNOMIAL_CHREC
:
353 return chrec_fold_multiply_poly_poly (type
, op0
, op1
);
356 if (integer_onep (op1
))
358 if (integer_zerop (op1
))
359 return convert (type
, integer_zero_node
);
361 return build_polynomial_chrec
362 (CHREC_VARIABLE (op0
),
363 chrec_fold_multiply (type
, CHREC_LEFT (op0
), op1
),
364 chrec_fold_multiply (type
, CHREC_RIGHT (op0
), op1
));
368 if (integer_onep (op0
))
371 if (integer_zerop (op0
))
372 return convert (type
, integer_zero_node
);
374 switch (TREE_CODE (op1
))
376 case POLYNOMIAL_CHREC
:
377 return build_polynomial_chrec
378 (CHREC_VARIABLE (op1
),
379 chrec_fold_multiply (type
, CHREC_LEFT (op1
), op0
),
380 chrec_fold_multiply (type
, CHREC_RIGHT (op1
), op0
));
383 if (integer_onep (op1
))
385 if (integer_zerop (op1
))
386 return convert (type
, integer_zero_node
);
387 return fold (build (MULT_EXPR
, type
, op0
, op1
));
399 tree_fold_factorial (tree f
)
401 if (tree_int_cst_sgn (f
) <= 0)
402 return integer_one_node
;
405 (build (MULT_EXPR
, integer_type_node
, f
,
406 tree_fold_factorial (fold (build (MINUS_EXPR
, integer_type_node
,
407 f
, integer_one_node
)))));
410 /* The binomial coefficient. */
413 tree_fold_binomial (tree n
,
417 (build (EXACT_DIV_EXPR
, integer_type_node
, tree_fold_factorial (n
),
418 fold (build (MULT_EXPR
, integer_type_node
,
419 tree_fold_factorial (k
),
421 (fold (build (MINUS_EXPR
, integer_type_node
,
425 /* Helper function. Use the Newton's interpolating formula for
426 evaluating the value of the evolution function. */
429 chrec_evaluate (unsigned var
,
434 tree type
= chrec_type (chrec
);
435 tree binomial_n_k
= tree_fold_binomial (n
, k
);
437 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
439 if (CHREC_VARIABLE (chrec
) > var
)
440 return chrec_evaluate (var
, CHREC_LEFT (chrec
), n
, k
);
442 if (CHREC_VARIABLE (chrec
) == var
)
443 return chrec_fold_plus
445 fold (build (MULT_EXPR
, type
, binomial_n_k
, CHREC_LEFT (chrec
))),
446 chrec_evaluate (var
, CHREC_RIGHT (chrec
), n
,
447 fold (build (PLUS_EXPR
, type
, k
, integer_one_node
))));
449 return fold (build (MULT_EXPR
, type
, binomial_n_k
, chrec
));
452 return fold (build (MULT_EXPR
, type
, binomial_n_k
, chrec
));
455 /* Evaluates "CHREC (X)" when the varying variable is VAR.
456 Example: Given the following parameters,
462 The result is given by the Newton's interpolating formula:
463 3 * \binom{10}{0} + 4 * \binom{10}{1}.
467 chrec_apply (unsigned var
,
471 tree type
= chrec_type (chrec
);
472 tree res
= chrec_dont_know
;
474 if (automatically_generated_chrec_p (chrec
)
475 || automatically_generated_chrec_p (x
)
477 /* When the symbols are defined in an outer loop, it is possible
478 to symbolically compute the apply, since the symbols are
479 constants with respect to the varying loop. */
480 || chrec_contains_symbols_defined_in_loop (chrec
, var
)
481 || chrec_contains_symbols (x
))
482 return chrec_dont_know
;
484 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
485 fprintf (dump_file
, "(chrec_apply \n");
487 if (evolution_function_is_affine_p (chrec
))
489 /* "{a, +, b} (x)" -> "a + b*x". */
490 if (TREE_CODE (CHREC_LEFT (chrec
)) == INTEGER_CST
491 && integer_zerop (CHREC_LEFT (chrec
)))
492 res
= chrec_fold_multiply (type
, CHREC_RIGHT (chrec
), x
);
495 res
= chrec_fold_plus (type
, CHREC_LEFT (chrec
),
496 chrec_fold_multiply (type
,
497 CHREC_RIGHT (chrec
), x
));
500 else if (TREE_CODE (chrec
) != POLYNOMIAL_CHREC
)
503 else if (TREE_CODE (x
) == INTEGER_CST
504 && tree_int_cst_sgn (x
) == 1)
505 /* testsuite/.../ssa-chrec-38.c. */
506 res
= chrec_evaluate (var
, chrec
, x
, integer_zero_node
);
509 res
= chrec_dont_know
;
511 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
513 fprintf (dump_file
, " (varying_loop = %d\n", var
);
514 fprintf (dump_file
, ")\n (chrec = ");
515 print_generic_expr (dump_file
, chrec
, 0);
516 fprintf (dump_file
, ")\n (x = ");
517 print_generic_expr (dump_file
, x
, 0);
518 fprintf (dump_file
, ")\n (res = ");
519 print_generic_expr (dump_file
, res
, 0);
520 fprintf (dump_file
, "))\n");
526 /* Replaces the initial condition in CHREC with INIT_COND. */
529 chrec_replace_initial_condition (tree chrec
,
532 if (automatically_generated_chrec_p (chrec
))
535 switch (TREE_CODE (chrec
))
537 case POLYNOMIAL_CHREC
:
538 return build_polynomial_chrec
539 (CHREC_VARIABLE (chrec
),
540 chrec_replace_initial_condition (CHREC_LEFT (chrec
), init_cond
),
541 CHREC_RIGHT (chrec
));
548 /* Returns the initial condition of a given CHREC. */
551 initial_condition (tree chrec
)
553 if (automatically_generated_chrec_p (chrec
))
556 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
557 return initial_condition (CHREC_LEFT (chrec
));
562 /* Returns a univariate function that represents the evolution in
563 LOOP_NUM. Mask the evolution of any other loop. */
566 hide_evolution_in_other_loops_than_loop (tree chrec
,
569 if (automatically_generated_chrec_p (chrec
))
572 switch (TREE_CODE (chrec
))
574 case POLYNOMIAL_CHREC
:
575 if (CHREC_VARIABLE (chrec
) == loop_num
)
576 return build_polynomial_chrec
578 hide_evolution_in_other_loops_than_loop (CHREC_LEFT (chrec
),
580 CHREC_RIGHT (chrec
));
582 else if (CHREC_VARIABLE (chrec
) < loop_num
)
583 /* There is no evolution in this loop. */
584 return initial_condition (chrec
);
587 return hide_evolution_in_other_loops_than_loop (CHREC_LEFT (chrec
),
595 /* Returns the evolution part in LOOP_NUM. Example: the call
596 get_evolution_in_loop (1, {{0, +, 1}_1, +, 2}_1) returns
600 evolution_part_in_loop_num (tree chrec
,
603 if (automatically_generated_chrec_p (chrec
))
606 switch (TREE_CODE (chrec
))
608 case POLYNOMIAL_CHREC
:
609 if (CHREC_VARIABLE (chrec
) == loop_num
)
611 if (TREE_CODE (CHREC_LEFT (chrec
)) != POLYNOMIAL_CHREC
612 || CHREC_VARIABLE (CHREC_LEFT (chrec
)) != CHREC_VARIABLE (chrec
))
613 return CHREC_RIGHT (chrec
);
616 return build_polynomial_chrec
618 evolution_part_in_loop_num (CHREC_LEFT (chrec
), loop_num
),
619 CHREC_RIGHT (chrec
));
622 else if (CHREC_VARIABLE (chrec
) < loop_num
)
623 /* There is no evolution part in this loop. */
627 return evolution_part_in_loop_num (CHREC_LEFT (chrec
), loop_num
);
634 /* Set or reset the evolution of CHREC to NEW_EVOL in loop LOOP_NUM.
635 This function is essentially used for setting the evolution to
636 chrec_dont_know, for example after having determined that it is
637 impossible to say how many times a loop will execute. */
640 reset_evolution_in_loop (unsigned loop_num
,
644 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
645 && CHREC_VARIABLE (chrec
) > loop_num
)
648 build_int_cst (NULL_TREE
, CHREC_VARIABLE (chrec
), 0),
649 reset_evolution_in_loop (loop_num
, CHREC_LEFT (chrec
), new_evol
),
650 reset_evolution_in_loop (loop_num
, CHREC_RIGHT (chrec
), new_evol
));
652 while (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
653 && CHREC_VARIABLE (chrec
) == loop_num
)
654 chrec
= CHREC_LEFT (chrec
);
656 return build_polynomial_chrec (loop_num
, chrec
, new_evol
);
659 /* Merges two evolution functions that were found by following two
660 alternate paths of a conditional expression. */
663 chrec_merge (tree chrec1
,
666 if (chrec1
== chrec_dont_know
667 || chrec2
== chrec_dont_know
)
668 return chrec_dont_know
;
670 if (chrec1
== chrec_known
671 || chrec2
== chrec_known
)
674 if (chrec1
== chrec_not_analyzed_yet
)
676 if (chrec2
== chrec_not_analyzed_yet
)
679 if (operand_equal_p (chrec1
, chrec2
, 0))
682 return chrec_dont_know
;
689 /* Helper function for is_multivariate_chrec. */
692 is_multivariate_chrec_rec (tree chrec
, unsigned int rec_var
)
694 if (chrec
== NULL_TREE
)
697 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
699 if (CHREC_VARIABLE (chrec
) != rec_var
)
702 return (is_multivariate_chrec_rec (CHREC_LEFT (chrec
), rec_var
)
703 || is_multivariate_chrec_rec (CHREC_RIGHT (chrec
), rec_var
));
709 /* Determine whether the given chrec is multivariate or not. */
712 is_multivariate_chrec (tree chrec
)
714 if (chrec
== NULL_TREE
)
717 if (TREE_CODE (chrec
) == POLYNOMIAL_CHREC
)
718 return (is_multivariate_chrec_rec (CHREC_LEFT (chrec
),
719 CHREC_VARIABLE (chrec
))
720 || is_multivariate_chrec_rec (CHREC_RIGHT (chrec
),
721 CHREC_VARIABLE (chrec
)));
726 /* Determines whether the chrec contains symbolic names or not. */
729 chrec_contains_symbols (tree chrec
)
731 if (chrec
== NULL_TREE
)
734 if (TREE_CODE (chrec
) == SSA_NAME
735 || TREE_CODE (chrec
) == VAR_DECL
736 || TREE_CODE (chrec
) == PARM_DECL
737 || TREE_CODE (chrec
) == FUNCTION_DECL
738 || TREE_CODE (chrec
) == LABEL_DECL
739 || TREE_CODE (chrec
) == RESULT_DECL
740 || TREE_CODE (chrec
) == FIELD_DECL
)
743 switch (TREE_CODE_LENGTH (TREE_CODE (chrec
)))
746 if (chrec_contains_symbols (TREE_OPERAND (chrec
, 2)))
750 if (chrec_contains_symbols (TREE_OPERAND (chrec
, 1)))
754 if (chrec_contains_symbols (TREE_OPERAND (chrec
, 0)))
762 /* Determines whether the chrec contains undetermined coefficients. */
765 chrec_contains_undetermined (tree chrec
)
767 if (chrec
== chrec_dont_know
768 || chrec
== chrec_not_analyzed_yet
769 || chrec
== NULL_TREE
)
772 switch (TREE_CODE_LENGTH (TREE_CODE (chrec
)))
775 if (chrec_contains_undetermined (TREE_OPERAND (chrec
, 2)))
779 if (chrec_contains_undetermined (TREE_OPERAND (chrec
, 1)))
783 if (chrec_contains_undetermined (TREE_OPERAND (chrec
, 0)))
791 /* Determines whether the tree EXPR contains chrecs. */
794 tree_contains_chrecs (tree expr
)
796 if (expr
== NULL_TREE
)
799 if (tree_is_chrec (expr
))
802 switch (TREE_CODE_LENGTH (TREE_CODE (expr
)))
805 if (tree_contains_chrecs (TREE_OPERAND (expr
, 2)))
809 if (tree_contains_chrecs (TREE_OPERAND (expr
, 1)))
813 if (tree_contains_chrecs (TREE_OPERAND (expr
, 0)))
821 /* Determine whether the given tree is an affine multivariate
825 evolution_function_is_affine_multivariate_p (tree chrec
)
827 if (chrec
== NULL_TREE
)
830 switch (TREE_CODE (chrec
))
832 case POLYNOMIAL_CHREC
:
833 if (evolution_function_is_constant_p (CHREC_LEFT (chrec
)))
835 if (evolution_function_is_constant_p (CHREC_RIGHT (chrec
)))
839 if (TREE_CODE (CHREC_RIGHT (chrec
)) == POLYNOMIAL_CHREC
840 && CHREC_VARIABLE (CHREC_RIGHT (chrec
))
841 != CHREC_VARIABLE (chrec
)
842 && evolution_function_is_affine_multivariate_p
843 (CHREC_RIGHT (chrec
)))
851 if (evolution_function_is_constant_p (CHREC_RIGHT (chrec
))
852 && TREE_CODE (CHREC_LEFT (chrec
)) == POLYNOMIAL_CHREC
853 && CHREC_VARIABLE (CHREC_LEFT (chrec
)) != CHREC_VARIABLE (chrec
)
854 && evolution_function_is_affine_multivariate_p
855 (CHREC_LEFT (chrec
)))
866 /* Determine whether the given tree is a function in zero or one
870 evolution_function_is_univariate_p (tree chrec
)
872 if (chrec
== NULL_TREE
)
875 switch (TREE_CODE (chrec
))
877 case POLYNOMIAL_CHREC
:
878 switch (TREE_CODE (CHREC_LEFT (chrec
)))
880 case POLYNOMIAL_CHREC
:
881 if (CHREC_VARIABLE (chrec
) != CHREC_VARIABLE (CHREC_LEFT (chrec
)))
883 if (!evolution_function_is_univariate_p (CHREC_LEFT (chrec
)))
891 switch (TREE_CODE (CHREC_RIGHT (chrec
)))
893 case POLYNOMIAL_CHREC
:
894 if (CHREC_VARIABLE (chrec
) != CHREC_VARIABLE (CHREC_RIGHT (chrec
)))
896 if (!evolution_function_is_univariate_p (CHREC_RIGHT (chrec
)))
911 /* Convert the initial condition of chrec to type. */
914 chrec_convert (tree type
,
919 if (automatically_generated_chrec_p (chrec
))
922 ct
= chrec_type (chrec
);
926 if (TYPE_PRECISION (ct
) < TYPE_PRECISION (type
))
927 return count_ev_in_wider_type (type
, chrec
);
929 switch (TREE_CODE (chrec
))
931 case POLYNOMIAL_CHREC
:
932 return build_polynomial_chrec (CHREC_VARIABLE (chrec
),
936 CHREC_RIGHT (chrec
)));
940 tree res
= convert (type
, chrec
);
942 /* Don't propagate overflows. */
943 TREE_OVERFLOW (res
) = 0;
944 if (TREE_CODE_CLASS (TREE_CODE (res
)) == 'c')
945 TREE_CONSTANT_OVERFLOW (res
) = 0;
951 /* Returns the type of the chrec. */
954 chrec_type (tree chrec
)
956 if (automatically_generated_chrec_p (chrec
))
959 return TREE_TYPE (chrec
);
962 extern void initialize_scalar_evolutions_analyzer (void);
967 initialize_scalar_evolutions_analyzer (void)
969 /* The elements below are unique. */
970 if (chrec_dont_know
== NULL_TREE
)
972 chrec_not_analyzed_yet
= NULL_TREE
;
973 chrec_dont_know
= make_node (SCEV_NOT_KNOWN
);
974 chrec_known
= make_node (SCEV_KNOWN
);
975 TREE_TYPE (chrec_dont_know
) = NULL_TREE
;
976 TREE_TYPE (chrec_known
) = NULL_TREE
;