Mercurial > hg > CbC > CbC_gcc
comparison gcc/graphite-sese-to-poly.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Conversion of SESE regions to Polyhedra. | 1 /* Conversion of SESE regions to Polyhedra. |
2 Copyright (C) 2009 Free Software Foundation, Inc. | 2 Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
3 Contributed by Sebastian Pop <sebastian.pop@amd.com>. | 3 Contributed by Sebastian Pop <sebastian.pop@amd.com>. |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
178 | 178 |
179 loop = loop_containing_stmt (phi); | 179 loop = loop_containing_stmt (phi); |
180 | 180 |
181 if (simple_copy_phi_p (phi)) | 181 if (simple_copy_phi_p (phi)) |
182 { | 182 { |
183 /* FIXME: PRE introduces phi nodes like these, for an example, | 183 /* PRE introduces phi nodes like these, for an example, |
184 see id-5.f in the fortran graphite testsuite: | 184 see id-5.f in the fortran graphite testsuite: |
185 | 185 |
186 # prephitmp.85_265 = PHI <prephitmp.85_258(33), prephitmp.85_265(18)> | 186 # prephitmp.85_265 = PHI <prephitmp.85_258(33), prephitmp.85_265(18)> |
187 */ | 187 */ |
188 remove_simple_copy_phi (psi); | 188 remove_simple_copy_phi (psi); |
278 bb->aux = gbb; | 278 bb->aux = gbb; |
279 GBB_BB (gbb) = bb; | 279 GBB_BB (gbb) = bb; |
280 GBB_DATA_REFS (gbb) = drs; | 280 GBB_DATA_REFS (gbb) = drs; |
281 GBB_CONDITIONS (gbb) = NULL; | 281 GBB_CONDITIONS (gbb) = NULL; |
282 GBB_CONDITION_CASES (gbb) = NULL; | 282 GBB_CONDITION_CASES (gbb) = NULL; |
283 GBB_CLOOG_IV_TYPES (gbb) = NULL; | |
284 | 283 |
285 return gbb; | 284 return gbb; |
286 } | 285 } |
287 | 286 |
288 static void | 287 static void |
306 /* Frees GBB. */ | 305 /* Frees GBB. */ |
307 | 306 |
308 static void | 307 static void |
309 free_gimple_bb (struct gimple_bb *gbb) | 308 free_gimple_bb (struct gimple_bb *gbb) |
310 { | 309 { |
311 if (GBB_CLOOG_IV_TYPES (gbb)) | |
312 htab_delete (GBB_CLOOG_IV_TYPES (gbb)); | |
313 | |
314 free_data_refs_aux (GBB_DATA_REFS (gbb)); | 310 free_data_refs_aux (GBB_DATA_REFS (gbb)); |
315 free_data_refs (GBB_DATA_REFS (gbb)); | 311 free_data_refs (GBB_DATA_REFS (gbb)); |
316 | 312 |
317 VEC_free (gimple, heap, GBB_CONDITIONS (gbb)); | 313 VEC_free (gimple, heap, GBB_CONDITIONS (gbb)); |
318 VEC_free (gimple, heap, GBB_CONDITION_CASES (gbb)); | 314 VEC_free (gimple, heap, GBB_CONDITION_CASES (gbb)); |
517 int nb_iterators = pbb_dim_iter_domain (pbb); | 513 int nb_iterators = pbb_dim_iter_domain (pbb); |
518 int used_scattering_dimensions = nb_iterators * 2 + 1; | 514 int used_scattering_dimensions = nb_iterators * 2 + 1; |
519 int nb_params = scop_nb_params (scop); | 515 int nb_params = scop_nb_params (scop); |
520 ppl_Coefficient_t c; | 516 ppl_Coefficient_t c; |
521 ppl_dimension_type dim = scattering_dimensions + nb_iterators + nb_params; | 517 ppl_dimension_type dim = scattering_dimensions + nb_iterators + nb_params; |
522 Value v; | 518 mpz_t v; |
523 | 519 |
524 gcc_assert (scattering_dimensions >= used_scattering_dimensions); | 520 gcc_assert (scattering_dimensions >= used_scattering_dimensions); |
525 | 521 |
526 value_init (v); | 522 mpz_init (v); |
527 ppl_new_Coefficient (&c); | 523 ppl_new_Coefficient (&c); |
528 PBB_TRANSFORMED (pbb) = poly_scattering_new (); | 524 PBB_TRANSFORMED (pbb) = poly_scattering_new (); |
529 ppl_new_C_Polyhedron_from_space_dimension | 525 ppl_new_C_Polyhedron_from_space_dimension |
530 (&PBB_TRANSFORMED_SCATTERING (pbb), dim, 0); | 526 (&PBB_TRANSFORMED_SCATTERING (pbb), dim, 0); |
531 | 527 |
535 { | 531 { |
536 ppl_Constraint_t cstr; | 532 ppl_Constraint_t cstr; |
537 ppl_Linear_Expression_t expr; | 533 ppl_Linear_Expression_t expr; |
538 | 534 |
539 ppl_new_Linear_Expression_with_dimension (&expr, dim); | 535 ppl_new_Linear_Expression_with_dimension (&expr, dim); |
540 value_set_si (v, 1); | 536 mpz_set_si (v, 1); |
541 ppl_assign_Coefficient_from_mpz_t (c, v); | 537 ppl_assign_Coefficient_from_mpz_t (c, v); |
542 ppl_Linear_Expression_add_to_coefficient (expr, i, c); | 538 ppl_Linear_Expression_add_to_coefficient (expr, i, c); |
543 | 539 |
544 /* Textual order inside this loop. */ | 540 /* Textual order inside this loop. */ |
545 if ((i % 2) == 0) | 541 if ((i % 2) == 0) |
546 { | 542 { |
547 ppl_Linear_Expression_coefficient (static_schedule, i / 2, c); | 543 ppl_Linear_Expression_coefficient (static_schedule, i / 2, c); |
548 ppl_Coefficient_to_mpz_t (c, v); | 544 ppl_Coefficient_to_mpz_t (c, v); |
549 value_oppose (v, v); | 545 mpz_neg (v, v); |
550 ppl_assign_Coefficient_from_mpz_t (c, v); | 546 ppl_assign_Coefficient_from_mpz_t (c, v); |
551 ppl_Linear_Expression_add_to_inhomogeneous (expr, c); | 547 ppl_Linear_Expression_add_to_inhomogeneous (expr, c); |
552 } | 548 } |
553 | 549 |
554 /* Iterations of this loop. */ | 550 /* Iterations of this loop. */ |
555 else /* if ((i % 2) == 1) */ | 551 else /* if ((i % 2) == 1) */ |
556 { | 552 { |
557 int loop = (i - 1) / 2; | 553 int loop = (i - 1) / 2; |
558 | 554 |
559 value_set_si (v, -1); | 555 mpz_set_si (v, -1); |
560 ppl_assign_Coefficient_from_mpz_t (c, v); | 556 ppl_assign_Coefficient_from_mpz_t (c, v); |
561 ppl_Linear_Expression_add_to_coefficient | 557 ppl_Linear_Expression_add_to_coefficient |
562 (expr, scattering_dimensions + loop, c); | 558 (expr, scattering_dimensions + loop, c); |
563 } | 559 } |
564 | 560 |
566 ppl_Polyhedron_add_constraint (PBB_TRANSFORMED_SCATTERING (pbb), cstr); | 562 ppl_Polyhedron_add_constraint (PBB_TRANSFORMED_SCATTERING (pbb), cstr); |
567 ppl_delete_Linear_Expression (expr); | 563 ppl_delete_Linear_Expression (expr); |
568 ppl_delete_Constraint (cstr); | 564 ppl_delete_Constraint (cstr); |
569 } | 565 } |
570 | 566 |
571 value_clear (v); | 567 mpz_clear (v); |
572 ppl_delete_Coefficient (c); | 568 ppl_delete_Coefficient (c); |
573 | 569 |
574 PBB_ORIGINAL (pbb) = poly_scattering_copy (PBB_TRANSFORMED (pbb)); | 570 PBB_ORIGINAL (pbb) = poly_scattering_copy (PBB_TRANSFORMED (pbb)); |
575 } | 571 } |
576 | 572 |
616 int i; | 612 int i; |
617 poly_bb_p pbb; | 613 poly_bb_p pbb; |
618 gimple_bb_p previous_gbb = NULL; | 614 gimple_bb_p previous_gbb = NULL; |
619 ppl_Linear_Expression_t static_schedule; | 615 ppl_Linear_Expression_t static_schedule; |
620 ppl_Coefficient_t c; | 616 ppl_Coefficient_t c; |
621 Value v; | 617 mpz_t v; |
622 | 618 |
623 value_init (v); | 619 mpz_init (v); |
624 ppl_new_Coefficient (&c); | 620 ppl_new_Coefficient (&c); |
625 ppl_new_Linear_Expression (&static_schedule); | 621 ppl_new_Linear_Expression (&static_schedule); |
626 | 622 |
627 /* We have to start schedules at 0 on the first component and | 623 /* We have to start schedules at 0 on the first component and |
628 because we cannot compare_prefix_loops against a previous loop, | 624 because we cannot compare_prefix_loops against a previous loop, |
629 prefix will be equal to zero, and that index will be | 625 prefix will be equal to zero, and that index will be |
630 incremented before copying. */ | 626 incremented before copying. */ |
631 value_set_si (v, -1); | 627 mpz_set_si (v, -1); |
632 ppl_assign_Coefficient_from_mpz_t (c, v); | 628 ppl_assign_Coefficient_from_mpz_t (c, v); |
633 ppl_Linear_Expression_add_to_coefficient (static_schedule, 0, c); | 629 ppl_Linear_Expression_add_to_coefficient (static_schedule, 0, c); |
634 | 630 |
635 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++) | 631 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++) |
636 { | 632 { |
647 previous_gbb = gbb; | 643 previous_gbb = gbb; |
648 ppl_new_Linear_Expression_with_dimension (&common, prefix + 1); | 644 ppl_new_Linear_Expression_with_dimension (&common, prefix + 1); |
649 ppl_assign_Linear_Expression_from_Linear_Expression (common, | 645 ppl_assign_Linear_Expression_from_Linear_Expression (common, |
650 static_schedule); | 646 static_schedule); |
651 | 647 |
652 value_set_si (v, 1); | 648 mpz_set_si (v, 1); |
653 ppl_assign_Coefficient_from_mpz_t (c, v); | 649 ppl_assign_Coefficient_from_mpz_t (c, v); |
654 ppl_Linear_Expression_add_to_coefficient (common, prefix, c); | 650 ppl_Linear_Expression_add_to_coefficient (common, prefix, c); |
655 ppl_assign_Linear_Expression_from_Linear_Expression (static_schedule, | 651 ppl_assign_Linear_Expression_from_Linear_Expression (static_schedule, |
656 common); | 652 common); |
657 | 653 |
658 build_pbb_scattering_polyhedrons (common, pbb, nb_scat_dims); | 654 build_pbb_scattering_polyhedrons (common, pbb, nb_scat_dims); |
659 | 655 |
660 ppl_delete_Linear_Expression (common); | 656 ppl_delete_Linear_Expression (common); |
661 } | 657 } |
662 | 658 |
663 value_clear (v); | 659 mpz_clear (v); |
664 ppl_delete_Coefficient (c); | 660 ppl_delete_Coefficient (c); |
665 ppl_delete_Linear_Expression (static_schedule); | 661 ppl_delete_Linear_Expression (static_schedule); |
666 } | 662 } |
667 | 663 |
668 /* Add the value K to the dimension D of the linear expression EXPR. */ | 664 /* Add the value K to the dimension D of the linear expression EXPR. */ |
669 | 665 |
670 static void | 666 static void |
671 add_value_to_dim (ppl_dimension_type d, ppl_Linear_Expression_t expr, | 667 add_value_to_dim (ppl_dimension_type d, ppl_Linear_Expression_t expr, |
672 Value k) | 668 mpz_t k) |
673 { | 669 { |
674 Value val; | 670 mpz_t val; |
675 ppl_Coefficient_t coef; | 671 ppl_Coefficient_t coef; |
676 | 672 |
677 ppl_new_Coefficient (&coef); | 673 ppl_new_Coefficient (&coef); |
678 ppl_Linear_Expression_coefficient (expr, d, coef); | 674 ppl_Linear_Expression_coefficient (expr, d, coef); |
679 value_init (val); | 675 mpz_init (val); |
680 ppl_Coefficient_to_mpz_t (coef, val); | 676 ppl_Coefficient_to_mpz_t (coef, val); |
681 | 677 |
682 value_addto (val, val, k); | 678 mpz_add (val, val, k); |
683 | 679 |
684 ppl_assign_Coefficient_from_mpz_t (coef, val); | 680 ppl_assign_Coefficient_from_mpz_t (coef, val); |
685 ppl_Linear_Expression_add_to_coefficient (expr, d, coef); | 681 ppl_Linear_Expression_add_to_coefficient (expr, d, coef); |
686 value_clear (val); | 682 mpz_clear (val); |
687 ppl_delete_Coefficient (coef); | 683 ppl_delete_Coefficient (coef); |
688 } | 684 } |
689 | 685 |
690 /* In the context of scop S, scan E, the right hand side of a scalar | 686 /* In the context of scop S, scan E, the right hand side of a scalar |
691 evolution function in loop VAR, and translate it to a linear | 687 evolution function in loop VAR, and translate it to a linear |
697 { | 693 { |
698 if (expr) | 694 if (expr) |
699 { | 695 { |
700 loop_p loop = get_loop (var); | 696 loop_p loop = get_loop (var); |
701 ppl_dimension_type l = sese_loop_depth (s, loop) - 1; | 697 ppl_dimension_type l = sese_loop_depth (s, loop) - 1; |
702 Value val; | 698 mpz_t val; |
703 | 699 |
704 /* Scalar evolutions should happen in the sese region. */ | 700 /* Scalar evolutions should happen in the sese region. */ |
705 gcc_assert (sese_loop_depth (s, loop) > 0); | 701 gcc_assert (sese_loop_depth (s, loop) > 0); |
706 | 702 |
707 /* We can not deal with parametric strides like: | 703 /* We can not deal with parametric strides like: |
710 | | 706 | |
711 | for i: | 707 | for i: |
712 | a [i * p] = ... */ | 708 | a [i * p] = ... */ |
713 gcc_assert (TREE_CODE (e) == INTEGER_CST); | 709 gcc_assert (TREE_CODE (e) == INTEGER_CST); |
714 | 710 |
715 value_init (val); | 711 mpz_init (val); |
716 value_set_si (val, int_cst_value (e)); | 712 mpz_set_si (val, int_cst_value (e)); |
717 add_value_to_dim (l, expr, val); | 713 add_value_to_dim (l, expr, val); |
718 value_clear (val); | 714 mpz_clear (val); |
719 } | 715 } |
720 } | 716 } |
721 | 717 |
722 /* Scan the integer constant CST, and add it to the inhomogeneous part of the | 718 /* Scan the integer constant CST, and add it to the inhomogeneous part of the |
723 linear expression EXPR. K is the multiplier of the constant. */ | 719 linear expression EXPR. K is the multiplier of the constant. */ |
724 | 720 |
725 static void | 721 static void |
726 scan_tree_for_params_int (tree cst, ppl_Linear_Expression_t expr, Value k) | 722 scan_tree_for_params_int (tree cst, ppl_Linear_Expression_t expr, mpz_t k) |
727 { | 723 { |
728 Value val; | 724 mpz_t val; |
729 ppl_Coefficient_t coef; | 725 ppl_Coefficient_t coef; |
730 int v = int_cst_value (cst); | 726 int v = int_cst_value (cst); |
731 | 727 |
732 value_init (val); | 728 mpz_init (val); |
733 value_set_si (val, 0); | 729 mpz_set_si (val, 0); |
734 | 730 |
735 /* Necessary to not get "-1 = 2^n - 1". */ | 731 /* Necessary to not get "-1 = 2^n - 1". */ |
736 if (v < 0) | 732 if (v < 0) |
737 value_sub_int (val, val, -v); | 733 mpz_sub_ui (val, val, -v); |
738 else | 734 else |
739 value_add_int (val, val, v); | 735 mpz_add_ui (val, val, v); |
740 | 736 |
741 value_multiply (val, val, k); | 737 mpz_mul (val, val, k); |
742 ppl_new_Coefficient (&coef); | 738 ppl_new_Coefficient (&coef); |
743 ppl_assign_Coefficient_from_mpz_t (coef, val); | 739 ppl_assign_Coefficient_from_mpz_t (coef, val); |
744 ppl_Linear_Expression_add_to_inhomogeneous (expr, coef); | 740 ppl_Linear_Expression_add_to_inhomogeneous (expr, coef); |
745 value_clear (val); | 741 mpz_clear (val); |
746 ppl_delete_Coefficient (coef); | 742 ppl_delete_Coefficient (coef); |
747 } | 743 } |
748 | 744 |
749 /* When parameter NAME is in REGION, returns its index in SESE_PARAMS. | 745 /* When parameter NAME is in REGION, returns its index in SESE_PARAMS. |
750 Otherwise returns -1. */ | 746 Otherwise returns -1. */ |
791 represents the constant multiplier of an expression containing | 787 represents the constant multiplier of an expression containing |
792 parameters. */ | 788 parameters. */ |
793 | 789 |
794 static void | 790 static void |
795 scan_tree_for_params (sese s, tree e, ppl_Linear_Expression_t c, | 791 scan_tree_for_params (sese s, tree e, ppl_Linear_Expression_t c, |
796 Value k) | 792 mpz_t k) |
797 { | 793 { |
798 if (e == chrec_dont_know) | 794 if (e == chrec_dont_know) |
799 return; | 795 return; |
800 | 796 |
801 switch (TREE_CODE (e)) | 797 switch (TREE_CODE (e)) |
809 case MULT_EXPR: | 805 case MULT_EXPR: |
810 if (chrec_contains_symbols (TREE_OPERAND (e, 0))) | 806 if (chrec_contains_symbols (TREE_OPERAND (e, 0))) |
811 { | 807 { |
812 if (c) | 808 if (c) |
813 { | 809 { |
814 Value val; | 810 mpz_t val; |
815 gcc_assert (host_integerp (TREE_OPERAND (e, 1), 0)); | 811 gcc_assert (host_integerp (TREE_OPERAND (e, 1), 0)); |
816 value_init (val); | 812 mpz_init (val); |
817 value_set_si (val, int_cst_value (TREE_OPERAND (e, 1))); | 813 mpz_set_si (val, int_cst_value (TREE_OPERAND (e, 1))); |
818 value_multiply (val, val, k); | 814 mpz_mul (val, val, k); |
819 scan_tree_for_params (s, TREE_OPERAND (e, 0), c, val); | 815 scan_tree_for_params (s, TREE_OPERAND (e, 0), c, val); |
820 value_clear (val); | 816 mpz_clear (val); |
821 } | 817 } |
822 else | 818 else |
823 scan_tree_for_params (s, TREE_OPERAND (e, 0), c, k); | 819 scan_tree_for_params (s, TREE_OPERAND (e, 0), c, k); |
824 } | 820 } |
825 else | 821 else |
826 { | 822 { |
827 if (c) | 823 if (c) |
828 { | 824 { |
829 Value val; | 825 mpz_t val; |
830 gcc_assert (host_integerp (TREE_OPERAND (e, 0), 0)); | 826 gcc_assert (host_integerp (TREE_OPERAND (e, 0), 0)); |
831 value_init (val); | 827 mpz_init (val); |
832 value_set_si (val, int_cst_value (TREE_OPERAND (e, 0))); | 828 mpz_set_si (val, int_cst_value (TREE_OPERAND (e, 0))); |
833 value_multiply (val, val, k); | 829 mpz_mul (val, val, k); |
834 scan_tree_for_params (s, TREE_OPERAND (e, 1), c, val); | 830 scan_tree_for_params (s, TREE_OPERAND (e, 1), c, val); |
835 value_clear (val); | 831 mpz_clear (val); |
836 } | 832 } |
837 else | 833 else |
838 scan_tree_for_params (s, TREE_OPERAND (e, 1), c, k); | 834 scan_tree_for_params (s, TREE_OPERAND (e, 1), c, k); |
839 } | 835 } |
840 break; | 836 break; |
906 scan_tree_for_params (s, TREE_OPERAND (e, 0), tmp_expr, k); | 902 scan_tree_for_params (s, TREE_OPERAND (e, 0), tmp_expr, k); |
907 | 903 |
908 if (c) | 904 if (c) |
909 { | 905 { |
910 ppl_Coefficient_t coef; | 906 ppl_Coefficient_t coef; |
911 Value minus_one; | 907 mpz_t minus_one; |
912 | 908 |
913 ppl_subtract_Linear_Expression_from_Linear_Expression (c, | 909 ppl_subtract_Linear_Expression_from_Linear_Expression (c, |
914 tmp_expr); | 910 tmp_expr); |
915 ppl_delete_Linear_Expression (tmp_expr); | 911 ppl_delete_Linear_Expression (tmp_expr); |
916 value_init (minus_one); | 912 mpz_init (minus_one); |
917 value_set_si (minus_one, -1); | 913 mpz_set_si (minus_one, -1); |
918 ppl_new_Coefficient_from_mpz_t (&coef, minus_one); | 914 ppl_new_Coefficient_from_mpz_t (&coef, minus_one); |
919 ppl_Linear_Expression_add_to_inhomogeneous (c, coef); | 915 ppl_Linear_Expression_add_to_inhomogeneous (c, coef); |
920 value_clear (minus_one); | 916 mpz_clear (minus_one); |
921 ppl_delete_Coefficient (coef); | 917 ppl_delete_Coefficient (coef); |
922 } | 918 } |
923 | 919 |
924 break; | 920 break; |
925 } | 921 } |
963 int i; | 959 int i; |
964 unsigned j; | 960 unsigned j; |
965 data_reference_p dr; | 961 data_reference_p dr; |
966 gimple stmt; | 962 gimple stmt; |
967 loop_p loop = GBB_BB (gbb)->loop_father; | 963 loop_p loop = GBB_BB (gbb)->loop_father; |
968 Value one; | 964 mpz_t one; |
969 | 965 |
970 value_init (one); | 966 mpz_init (one); |
971 value_set_si (one, 1); | 967 mpz_set_si (one, 1); |
972 | 968 |
973 /* Find parameters in the access functions of data references. */ | 969 /* Find parameters in the access functions of data references. */ |
974 for (i = 0; VEC_iterate (data_reference_p, GBB_DATA_REFS (gbb), i, dr); i++) | 970 for (i = 0; VEC_iterate (data_reference_p, GBB_DATA_REFS (gbb), i, dr); i++) |
975 for (j = 0; j < DR_NUM_DIMENSIONS (dr); j++) | 971 for (j = 0; j < DR_NUM_DIMENSIONS (dr); j++) |
976 scan_tree_for_params (region, DR_ACCESS_FN (dr, j), NULL, one); | 972 scan_tree_for_params (region, DR_ACCESS_FN (dr, j), NULL, one); |
985 | 981 |
986 scan_tree_for_params (region, lhs, NULL, one); | 982 scan_tree_for_params (region, lhs, NULL, one); |
987 scan_tree_for_params (region, rhs, NULL, one); | 983 scan_tree_for_params (region, rhs, NULL, one); |
988 } | 984 } |
989 | 985 |
990 value_clear (one); | 986 mpz_clear (one); |
991 } | 987 } |
992 | 988 |
993 /* Record the parameters used in the SCOP. A variable is a parameter | 989 /* Record the parameters used in the SCOP. A variable is a parameter |
994 in a scop if it does not vary during the execution of that scop. */ | 990 in a scop if it does not vary during the execution of that scop. */ |
995 | 991 |
998 { | 994 { |
999 poly_bb_p pbb; | 995 poly_bb_p pbb; |
1000 unsigned i; | 996 unsigned i; |
1001 sese region = SCOP_REGION (scop); | 997 sese region = SCOP_REGION (scop); |
1002 struct loop *loop; | 998 struct loop *loop; |
1003 Value one; | 999 mpz_t one; |
1004 | 1000 |
1005 value_init (one); | 1001 mpz_init (one); |
1006 value_set_si (one, 1); | 1002 mpz_set_si (one, 1); |
1007 | 1003 |
1008 /* Find the parameters used in the loop bounds. */ | 1004 /* Find the parameters used in the loop bounds. */ |
1009 for (i = 0; VEC_iterate (loop_p, SESE_LOOP_NEST (region), i, loop); i++) | 1005 for (i = 0; VEC_iterate (loop_p, SESE_LOOP_NEST (region), i, loop); i++) |
1010 { | 1006 { |
1011 tree nb_iters = number_of_latch_executions (loop); | 1007 tree nb_iters = number_of_latch_executions (loop); |
1015 | 1011 |
1016 nb_iters = scalar_evolution_in_region (region, loop, nb_iters); | 1012 nb_iters = scalar_evolution_in_region (region, loop, nb_iters); |
1017 scan_tree_for_params (region, nb_iters, NULL, one); | 1013 scan_tree_for_params (region, nb_iters, NULL, one); |
1018 } | 1014 } |
1019 | 1015 |
1020 value_clear (one); | 1016 mpz_clear (one); |
1021 | 1017 |
1022 /* Find the parameters used in data accesses. */ | 1018 /* Find the parameters used in data accesses. */ |
1023 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++) | 1019 for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++) |
1024 find_params_in_bb (region, PBB_BLACK_BOX (pbb)); | 1020 find_params_in_bb (region, PBB_BLACK_BOX (pbb)); |
1025 | 1021 |
1034 | 1030 |
1035 static inline gimple_bb_p | 1031 static inline gimple_bb_p |
1036 gbb_from_bb (basic_block bb) | 1032 gbb_from_bb (basic_block bb) |
1037 { | 1033 { |
1038 return (gimple_bb_p) bb->aux; | 1034 return (gimple_bb_p) bb->aux; |
1035 } | |
1036 | |
1037 /* Insert in the SCOP context constraints from the estimation of the | |
1038 number of iterations. UB_EXPR is a linear expression describing | |
1039 the number of iterations in a loop. This expression is bounded by | |
1040 the estimation NIT. */ | |
1041 | |
1042 static void | |
1043 add_upper_bounds_from_estimated_nit (scop_p scop, double_int nit, | |
1044 ppl_dimension_type dim, | |
1045 ppl_Linear_Expression_t ub_expr) | |
1046 { | |
1047 mpz_t val; | |
1048 ppl_Linear_Expression_t nb_iters_le; | |
1049 ppl_Polyhedron_t pol; | |
1050 ppl_Coefficient_t coef; | |
1051 ppl_Constraint_t ub; | |
1052 | |
1053 ppl_new_Linear_Expression_with_dimension (&ub_expr, dim); | |
1054 ppl_new_C_Polyhedron_from_space_dimension (&pol, dim, 0); | |
1055 ppl_new_Linear_Expression_from_Linear_Expression (&nb_iters_le, | |
1056 ub_expr); | |
1057 | |
1058 /* Construct the negated number of last iteration in VAL. */ | |
1059 mpz_init (val); | |
1060 mpz_set_double_int (val, nit, false); | |
1061 mpz_sub_ui (val, val, 1); | |
1062 mpz_neg (val, val); | |
1063 | |
1064 /* NB_ITERS_LE holds the number of last iteration in | |
1065 parametrical form. Subtract estimated number of last | |
1066 iteration and assert that result is not positive. */ | |
1067 ppl_new_Coefficient_from_mpz_t (&coef, val); | |
1068 ppl_Linear_Expression_add_to_inhomogeneous (nb_iters_le, coef); | |
1069 ppl_delete_Coefficient (coef); | |
1070 ppl_new_Constraint (&ub, nb_iters_le, | |
1071 PPL_CONSTRAINT_TYPE_LESS_OR_EQUAL); | |
1072 ppl_Polyhedron_add_constraint (pol, ub); | |
1073 | |
1074 /* Remove all but last GDIM dimensions from POL to obtain | |
1075 only the constraints on the parameters. */ | |
1076 { | |
1077 graphite_dim_t gdim = scop_nb_params (scop); | |
1078 ppl_dimension_type *dims = XNEWVEC (ppl_dimension_type, dim - gdim); | |
1079 graphite_dim_t i; | |
1080 | |
1081 for (i = 0; i < dim - gdim; i++) | |
1082 dims[i] = i; | |
1083 | |
1084 ppl_Polyhedron_remove_space_dimensions (pol, dims, dim - gdim); | |
1085 XDELETEVEC (dims); | |
1086 } | |
1087 | |
1088 /* Add the constraints on the parameters to the SCoP context. */ | |
1089 { | |
1090 ppl_Pointset_Powerset_C_Polyhedron_t constraints_ps; | |
1091 | |
1092 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron | |
1093 (&constraints_ps, pol); | |
1094 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign | |
1095 (SCOP_CONTEXT (scop), constraints_ps); | |
1096 ppl_delete_Pointset_Powerset_C_Polyhedron (constraints_ps); | |
1097 } | |
1098 | |
1099 ppl_delete_Polyhedron (pol); | |
1100 ppl_delete_Linear_Expression (nb_iters_le); | |
1101 ppl_delete_Constraint (ub); | |
1102 mpz_clear (val); | |
1039 } | 1103 } |
1040 | 1104 |
1041 /* Builds the constraint polyhedra for LOOP in SCOP. OUTER_PH gives | 1105 /* Builds the constraint polyhedra for LOOP in SCOP. OUTER_PH gives |
1042 the constraints for the surrounding loops. */ | 1106 the constraints for the surrounding loops. */ |
1043 | 1107 |
1099 ppl_delete_Linear_Expression (ub_expr); | 1163 ppl_delete_Linear_Expression (ub_expr); |
1100 ppl_delete_Constraint (ub); | 1164 ppl_delete_Constraint (ub); |
1101 } | 1165 } |
1102 else if (!chrec_contains_undetermined (nb_iters)) | 1166 else if (!chrec_contains_undetermined (nb_iters)) |
1103 { | 1167 { |
1104 Value one; | 1168 mpz_t one; |
1105 ppl_Constraint_t ub; | 1169 ppl_Constraint_t ub; |
1106 ppl_Linear_Expression_t ub_expr; | 1170 ppl_Linear_Expression_t ub_expr; |
1107 double_int nit; | 1171 double_int nit; |
1108 | 1172 |
1109 value_init (one); | 1173 mpz_init (one); |
1110 value_set_si (one, 1); | 1174 mpz_set_si (one, 1); |
1111 ppl_new_Linear_Expression_with_dimension (&ub_expr, dim); | 1175 ppl_new_Linear_Expression_with_dimension (&ub_expr, dim); |
1112 nb_iters = scalar_evolution_in_region (region, loop, nb_iters); | 1176 nb_iters = scalar_evolution_in_region (region, loop, nb_iters); |
1113 scan_tree_for_params (SCOP_REGION (scop), nb_iters, ub_expr, one); | 1177 scan_tree_for_params (SCOP_REGION (scop), nb_iters, ub_expr, one); |
1114 value_clear (one); | 1178 mpz_clear (one); |
1115 | 1179 |
1116 /* N <= estimated_nb_iters | |
1117 | |
1118 FIXME: This is a workaround that should go away once we will | |
1119 have the PIP algorithm. */ | |
1120 if (estimated_loop_iterations (loop, true, &nit)) | 1180 if (estimated_loop_iterations (loop, true, &nit)) |
1121 { | 1181 add_upper_bounds_from_estimated_nit (scop, nit, dim, ub_expr); |
1122 Value val; | |
1123 ppl_Linear_Expression_t nb_iters_le; | |
1124 ppl_Polyhedron_t pol; | |
1125 graphite_dim_t n = scop_nb_params (scop); | |
1126 ppl_Coefficient_t coef; | |
1127 | |
1128 ppl_new_C_Polyhedron_from_space_dimension (&pol, dim, 0); | |
1129 ppl_new_Linear_Expression_from_Linear_Expression (&nb_iters_le, | |
1130 ub_expr); | |
1131 | |
1132 /* Construct the negated number of last iteration in VAL. */ | |
1133 value_init (val); | |
1134 mpz_set_double_int (val, nit, false); | |
1135 value_sub_int (val, val, 1); | |
1136 value_oppose (val, val); | |
1137 | |
1138 /* NB_ITERS_LE holds number of last iteration in parametrical form. | |
1139 Subtract estimated number of last iteration and assert that result | |
1140 is not positive. */ | |
1141 ppl_new_Coefficient_from_mpz_t (&coef, val); | |
1142 ppl_Linear_Expression_add_to_inhomogeneous (nb_iters_le, coef); | |
1143 ppl_delete_Coefficient (coef); | |
1144 ppl_new_Constraint (&ub, nb_iters_le, | |
1145 PPL_CONSTRAINT_TYPE_LESS_OR_EQUAL); | |
1146 ppl_Polyhedron_add_constraint (pol, ub); | |
1147 | |
1148 /* Remove all but last N dimensions from POL to obtain constraints | |
1149 on parameters. */ | |
1150 { | |
1151 ppl_dimension_type *dims = XNEWVEC (ppl_dimension_type, dim - n); | |
1152 graphite_dim_t i; | |
1153 for (i = 0; i < dim - n; i++) | |
1154 dims[i] = i; | |
1155 ppl_Polyhedron_remove_space_dimensions (pol, dims, dim - n); | |
1156 XDELETEVEC (dims); | |
1157 } | |
1158 | |
1159 /* Add constraints on parameters to SCoP context. */ | |
1160 { | |
1161 ppl_Pointset_Powerset_C_Polyhedron_t constraints_ps; | |
1162 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron | |
1163 (&constraints_ps, pol); | |
1164 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign | |
1165 (SCOP_CONTEXT (scop), constraints_ps); | |
1166 ppl_delete_Pointset_Powerset_C_Polyhedron (constraints_ps); | |
1167 } | |
1168 | |
1169 ppl_delete_Polyhedron (pol); | |
1170 ppl_delete_Linear_Expression (nb_iters_le); | |
1171 ppl_delete_Constraint (ub); | |
1172 value_clear (val); | |
1173 } | |
1174 | 1182 |
1175 /* loop_i <= expr_nb_iters */ | 1183 /* loop_i <= expr_nb_iters */ |
1176 ppl_set_coef (ub_expr, nb, -1); | 1184 ppl_set_coef (ub_expr, nb, -1); |
1177 ppl_new_Constraint (&ub, ub_expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); | 1185 ppl_new_Constraint (&ub, ub_expr, PPL_CONSTRAINT_TYPE_GREATER_OR_EQUAL); |
1178 ppl_Polyhedron_add_constraint (ph, ub); | 1186 ppl_Polyhedron_add_constraint (ph, ub); |
1199 /* Returns a linear expression for tree T evaluated in PBB. */ | 1207 /* Returns a linear expression for tree T evaluated in PBB. */ |
1200 | 1208 |
1201 static ppl_Linear_Expression_t | 1209 static ppl_Linear_Expression_t |
1202 create_linear_expr_from_tree (poly_bb_p pbb, tree t) | 1210 create_linear_expr_from_tree (poly_bb_p pbb, tree t) |
1203 { | 1211 { |
1204 Value one; | 1212 mpz_t one; |
1205 ppl_Linear_Expression_t res; | 1213 ppl_Linear_Expression_t res; |
1206 ppl_dimension_type dim; | 1214 ppl_dimension_type dim; |
1207 sese region = SCOP_REGION (PBB_SCOP (pbb)); | 1215 sese region = SCOP_REGION (PBB_SCOP (pbb)); |
1208 loop_p loop = pbb_loop (pbb); | 1216 loop_p loop = pbb_loop (pbb); |
1209 | 1217 |
1211 ppl_new_Linear_Expression_with_dimension (&res, dim); | 1219 ppl_new_Linear_Expression_with_dimension (&res, dim); |
1212 | 1220 |
1213 t = scalar_evolution_in_region (region, loop, t); | 1221 t = scalar_evolution_in_region (region, loop, t); |
1214 gcc_assert (!automatically_generated_chrec_p (t)); | 1222 gcc_assert (!automatically_generated_chrec_p (t)); |
1215 | 1223 |
1216 value_init (one); | 1224 mpz_init (one); |
1217 value_set_si (one, 1); | 1225 mpz_set_si (one, 1); |
1218 scan_tree_for_params (region, t, res, one); | 1226 scan_tree_for_params (region, t, res, one); |
1219 value_clear (one); | 1227 mpz_clear (one); |
1220 | 1228 |
1221 return res; | 1229 return res; |
1222 } | 1230 } |
1223 | 1231 |
1224 /* Returns the ppl constraint type from the gimple tree code CODE. */ | 1232 /* Returns the ppl constraint type from the gimple tree code CODE. */ |
1255 | 1263 |
1256 static void | 1264 static void |
1257 add_condition_to_domain (ppl_Pointset_Powerset_C_Polyhedron_t ps, gimple stmt, | 1265 add_condition_to_domain (ppl_Pointset_Powerset_C_Polyhedron_t ps, gimple stmt, |
1258 poly_bb_p pbb, enum tree_code code) | 1266 poly_bb_p pbb, enum tree_code code) |
1259 { | 1267 { |
1260 Value v; | 1268 mpz_t v; |
1261 ppl_Coefficient_t c; | 1269 ppl_Coefficient_t c; |
1262 ppl_Linear_Expression_t left, right; | 1270 ppl_Linear_Expression_t left, right; |
1263 ppl_Constraint_t cstr; | 1271 ppl_Constraint_t cstr; |
1264 enum ppl_enum_Constraint_Type type; | 1272 enum ppl_enum_Constraint_Type type; |
1265 | 1273 |
1268 | 1276 |
1269 /* If we have < or > expressions convert them to <= or >= by adding 1 to | 1277 /* If we have < or > expressions convert them to <= or >= by adding 1 to |
1270 the left or the right side of the expression. */ | 1278 the left or the right side of the expression. */ |
1271 if (code == LT_EXPR) | 1279 if (code == LT_EXPR) |
1272 { | 1280 { |
1273 value_init (v); | 1281 mpz_init (v); |
1274 value_set_si (v, 1); | 1282 mpz_set_si (v, 1); |
1275 ppl_new_Coefficient (&c); | 1283 ppl_new_Coefficient (&c); |
1276 ppl_assign_Coefficient_from_mpz_t (c, v); | 1284 ppl_assign_Coefficient_from_mpz_t (c, v); |
1277 ppl_Linear_Expression_add_to_inhomogeneous (left, c); | 1285 ppl_Linear_Expression_add_to_inhomogeneous (left, c); |
1278 ppl_delete_Coefficient (c); | 1286 ppl_delete_Coefficient (c); |
1279 value_clear (v); | 1287 mpz_clear (v); |
1280 | 1288 |
1281 code = LE_EXPR; | 1289 code = LE_EXPR; |
1282 } | 1290 } |
1283 else if (code == GT_EXPR) | 1291 else if (code == GT_EXPR) |
1284 { | 1292 { |
1285 value_init (v); | 1293 mpz_init (v); |
1286 value_set_si (v, 1); | 1294 mpz_set_si (v, 1); |
1287 ppl_new_Coefficient (&c); | 1295 ppl_new_Coefficient (&c); |
1288 ppl_assign_Coefficient_from_mpz_t (c, v); | 1296 ppl_assign_Coefficient_from_mpz_t (c, v); |
1289 ppl_Linear_Expression_add_to_inhomogeneous (right, c); | 1297 ppl_Linear_Expression_add_to_inhomogeneous (right, c); |
1290 ppl_delete_Coefficient (c); | 1298 ppl_delete_Coefficient (c); |
1291 value_clear (v); | 1299 mpz_clear (v); |
1292 | 1300 |
1293 code = GE_EXPR; | 1301 code = GE_EXPR; |
1294 } | 1302 } |
1295 | 1303 |
1296 type = ppl_constraint_type_from_tree_code (code); | 1304 type = ppl_constraint_type_from_tree_code (code); |
1497 { | 1505 { |
1498 ppl_Constraint_t cstr; | 1506 ppl_Constraint_t cstr; |
1499 ppl_Linear_Expression_t le; | 1507 ppl_Linear_Expression_t le; |
1500 tree parameter = VEC_index (tree, SESE_PARAMS (SCOP_REGION (scop)), p); | 1508 tree parameter = VEC_index (tree, SESE_PARAMS (SCOP_REGION (scop)), p); |
1501 tree type = TREE_TYPE (parameter); | 1509 tree type = TREE_TYPE (parameter); |
1502 tree lb, ub; | 1510 tree lb = NULL_TREE; |
1503 | 1511 tree ub = NULL_TREE; |
1504 /* Disabled until we fix CPU2006. */ | 1512 |
1505 return; | 1513 if (POINTER_TYPE_P (type) || !TYPE_MIN_VALUE (type)) |
1506 | 1514 lb = lower_bound_in_type (type, type); |
1507 if (!INTEGRAL_TYPE_P (type)) | 1515 else |
1508 return; | 1516 lb = TYPE_MIN_VALUE (type); |
1509 | 1517 |
1510 lb = TYPE_MIN_VALUE (type); | 1518 if (POINTER_TYPE_P (type) || !TYPE_MAX_VALUE (type)) |
1511 ub = TYPE_MAX_VALUE (type); | 1519 ub = upper_bound_in_type (type, type); |
1520 else | |
1521 ub = TYPE_MAX_VALUE (type); | |
1512 | 1522 |
1513 if (lb) | 1523 if (lb) |
1514 { | 1524 { |
1515 ppl_new_Linear_Expression_with_dimension (&le, scop_nb_params (scop)); | 1525 ppl_new_Linear_Expression_with_dimension (&le, scop_nb_params (scop)); |
1516 ppl_set_coef (le, p, -1); | 1526 ppl_set_coef (le, p, -1); |
1639 ppl_dimension_type accessp_nb_dims, | 1649 ppl_dimension_type accessp_nb_dims, |
1640 ppl_dimension_type dom_nb_dims, | 1650 ppl_dimension_type dom_nb_dims, |
1641 poly_bb_p pbb) | 1651 poly_bb_p pbb) |
1642 { | 1652 { |
1643 int i, nb_subscripts = DR_NUM_DIMENSIONS (dr); | 1653 int i, nb_subscripts = DR_NUM_DIMENSIONS (dr); |
1644 Value v; | 1654 mpz_t v; |
1645 scop_p scop = PBB_SCOP (pbb); | 1655 scop_p scop = PBB_SCOP (pbb); |
1646 sese region = SCOP_REGION (scop); | 1656 sese region = SCOP_REGION (scop); |
1647 | 1657 |
1648 value_init (v); | 1658 mpz_init (v); |
1649 | 1659 |
1650 for (i = 0; i < nb_subscripts; i++) | 1660 for (i = 0; i < nb_subscripts; i++) |
1651 { | 1661 { |
1652 ppl_Linear_Expression_t fn, access; | 1662 ppl_Linear_Expression_t fn, access; |
1653 ppl_Constraint_t cstr; | 1663 ppl_Constraint_t cstr; |
1655 tree afn = DR_ACCESS_FN (dr, nb_subscripts - 1 - i); | 1665 tree afn = DR_ACCESS_FN (dr, nb_subscripts - 1 - i); |
1656 | 1666 |
1657 ppl_new_Linear_Expression_with_dimension (&fn, dom_nb_dims); | 1667 ppl_new_Linear_Expression_with_dimension (&fn, dom_nb_dims); |
1658 ppl_new_Linear_Expression_with_dimension (&access, accessp_nb_dims); | 1668 ppl_new_Linear_Expression_with_dimension (&access, accessp_nb_dims); |
1659 | 1669 |
1660 value_set_si (v, 1); | 1670 mpz_set_si (v, 1); |
1661 scan_tree_for_params (region, afn, fn, v); | 1671 scan_tree_for_params (region, afn, fn, v); |
1662 ppl_assign_Linear_Expression_from_Linear_Expression (access, fn); | 1672 ppl_assign_Linear_Expression_from_Linear_Expression (access, fn); |
1663 | 1673 |
1664 ppl_set_coef (access, subscript, -1); | 1674 ppl_set_coef (access, subscript, -1); |
1665 ppl_new_Constraint (&cstr, access, PPL_CONSTRAINT_TYPE_EQUAL); | 1675 ppl_new_Constraint (&cstr, access, PPL_CONSTRAINT_TYPE_EQUAL); |
1668 ppl_delete_Linear_Expression (fn); | 1678 ppl_delete_Linear_Expression (fn); |
1669 ppl_delete_Linear_Expression (access); | 1679 ppl_delete_Linear_Expression (access); |
1670 ppl_delete_Constraint (cstr); | 1680 ppl_delete_Constraint (cstr); |
1671 } | 1681 } |
1672 | 1682 |
1673 value_clear (v); | 1683 mpz_clear (v); |
1674 } | 1684 } |
1675 | 1685 |
1676 /* Add constrains representing the size of the accessed data to the | 1686 /* Add constrains representing the size of the accessed data to the |
1677 ACCESSES polyhedron. ACCESSP_NB_DIMS is the dimension of the | 1687 ACCESSES polyhedron. ACCESSP_NB_DIMS is the dimension of the |
1678 ACCESSES polyhedron, DOM_NB_DIMS is the dimension of the iteration | 1688 ACCESSES polyhedron, DOM_NB_DIMS is the dimension of the iteration |
2167 { | 2177 { |
2168 if (gimple_code (phi) != GIMPLE_PHI | 2178 if (gimple_code (phi) != GIMPLE_PHI |
2169 || !is_gimple_reg (gimple_phi_result (phi))) | 2179 || !is_gimple_reg (gimple_phi_result (phi))) |
2170 return false; | 2180 return false; |
2171 | 2181 |
2182 /* Note that loop close phi nodes should have a single argument | |
2183 because we translated the representation into a canonical form | |
2184 before Graphite: see canonicalize_loop_closed_ssa_form. */ | |
2172 return (gimple_phi_num_args (phi) == 1); | 2185 return (gimple_phi_num_args (phi) == 1); |
2173 } | 2186 } |
2174 | 2187 |
2175 /* Rewrite out of SSA the reduction phi node at PSI by creating a zero | 2188 /* Rewrite out of SSA the reduction phi node at PSI by creating a zero |
2176 dimension array for it. */ | 2189 dimension array for it. */ |
2184 tree zero_dim_array = create_zero_dim_array (var, "Close_Phi"); | 2197 tree zero_dim_array = create_zero_dim_array (var, "Close_Phi"); |
2185 gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (phi)); | 2198 gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (phi)); |
2186 gimple stmt = gimple_build_assign (res, zero_dim_array); | 2199 gimple stmt = gimple_build_assign (res, zero_dim_array); |
2187 tree arg = gimple_phi_arg_def (phi, 0); | 2200 tree arg = gimple_phi_arg_def (phi, 0); |
2188 | 2201 |
2189 if (TREE_CODE (arg) == SSA_NAME) | 2202 /* Note that loop close phi nodes should have a single argument |
2203 because we translated the representation into a canonical form | |
2204 before Graphite: see canonicalize_loop_closed_ssa_form. */ | |
2205 gcc_assert (gimple_phi_num_args (phi) == 1); | |
2206 | |
2207 if (TREE_CODE (arg) == SSA_NAME | |
2208 && !SSA_NAME_IS_DEFAULT_DEF (arg)) | |
2190 insert_out_of_ssa_copy (zero_dim_array, arg); | 2209 insert_out_of_ssa_copy (zero_dim_array, arg); |
2191 else | 2210 else |
2192 insert_out_of_ssa_copy_on_edge (single_pred_edge (gimple_bb (phi)), | 2211 insert_out_of_ssa_copy_on_edge (single_pred_edge (gimple_bb (phi)), |
2193 zero_dim_array, arg); | 2212 zero_dim_array, arg); |
2194 | 2213 |
2349 | 2368 |
2350 def_bb = gimple_bb (stmt); | 2369 def_bb = gimple_bb (stmt); |
2351 | 2370 |
2352 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def) | 2371 FOR_EACH_IMM_USE_STMT (use_stmt, imm_iter, def) |
2353 if (def_bb != gimple_bb (use_stmt) | 2372 if (def_bb != gimple_bb (use_stmt) |
2354 && gimple_code (use_stmt) != GIMPLE_PHI) | 2373 && gimple_code (use_stmt) != GIMPLE_PHI |
2374 && !is_gimple_debug (use_stmt)) | |
2355 { | 2375 { |
2356 if (!zero_dim_array) | 2376 if (!zero_dim_array) |
2357 { | 2377 { |
2358 zero_dim_array = create_zero_dim_array | 2378 zero_dim_array = create_zero_dim_array |
2359 (SSA_NAME_VAR (def), "Cross_BB_scalar_dependence"); | 2379 (SSA_NAME_VAR (def), "Cross_BB_scalar_dependence"); |
2384 rewrite_phi_out_of_ssa (&psi); | 2404 rewrite_phi_out_of_ssa (&psi); |
2385 } | 2405 } |
2386 | 2406 |
2387 update_ssa (TODO_update_ssa); | 2407 update_ssa (TODO_update_ssa); |
2388 #ifdef ENABLE_CHECKING | 2408 #ifdef ENABLE_CHECKING |
2389 verify_ssa (false); | 2409 verify_loop_closed_ssa (true); |
2390 verify_loop_closed_ssa (); | |
2391 #endif | 2410 #endif |
2392 | 2411 |
2393 FOR_EACH_BB (bb) | 2412 FOR_EACH_BB (bb) |
2394 if (bb_in_sese_p (bb, region)) | 2413 if (bb_in_sese_p (bb, region)) |
2395 for (psi = gsi_start_bb (bb); !gsi_end_p (psi); gsi_next (&psi)) | 2414 for (psi = gsi_start_bb (bb); !gsi_end_p (psi); gsi_next (&psi)) |
2396 rewrite_cross_bb_scalar_deps (region, &psi); | 2415 rewrite_cross_bb_scalar_deps (region, &psi); |
2397 | 2416 |
2398 update_ssa (TODO_update_ssa); | 2417 update_ssa (TODO_update_ssa); |
2399 #ifdef ENABLE_CHECKING | 2418 #ifdef ENABLE_CHECKING |
2400 verify_ssa (false); | 2419 verify_loop_closed_ssa (true); |
2401 verify_loop_closed_ssa (); | |
2402 #endif | 2420 #endif |
2403 } | 2421 } |
2404 | 2422 |
2405 /* Returns the number of pbbs that are in loops contained in SCOP. */ | 2423 /* Returns the number of pbbs that are in loops contained in SCOP. */ |
2406 | 2424 |
2448 if (nb_data_writes_in_bb (bb) == 0) | 2466 if (nb_data_writes_in_bb (bb) == 0) |
2449 return bb; | 2467 return bb; |
2450 | 2468 |
2451 split_block (bb, stmt); | 2469 split_block (bb, stmt); |
2452 | 2470 |
2453 if (gsi_one_before_end_p (gsi_start_bb (bb))) | 2471 if (gsi_one_before_end_p (gsi_start_nondebug_bb (bb))) |
2454 return bb; | 2472 return bb; |
2455 | 2473 |
2456 gsi = gsi_last_bb (bb); | 2474 gsi = gsi_last_bb (bb); |
2457 gsi_prev (&gsi); | 2475 gsi_prev (&gsi); |
2458 e = split_block (bb, gsi_stmt (gsi)); | 2476 e = split_block (bb, gsi_stmt (gsi)); |
2649 gimple def, loop_phi; | 2667 gimple def, loop_phi; |
2650 | 2668 |
2651 if (TREE_CODE (arg) != SSA_NAME) | 2669 if (TREE_CODE (arg) != SSA_NAME) |
2652 return NULL; | 2670 return NULL; |
2653 | 2671 |
2672 /* Note that loop close phi nodes should have a single argument | |
2673 because we translated the representation into a canonical form | |
2674 before Graphite: see canonicalize_loop_closed_ssa_form. */ | |
2675 gcc_assert (gimple_phi_num_args (stmt) == 1); | |
2676 | |
2654 def = SSA_NAME_DEF_STMT (arg); | 2677 def = SSA_NAME_DEF_STMT (arg); |
2655 loop_phi = detect_commutative_reduction (def, in, out); | 2678 loop_phi = detect_commutative_reduction (def, in, out); |
2656 | 2679 |
2657 if (loop_phi) | 2680 if (loop_phi) |
2658 { | 2681 { |
2717 | 2740 |
2718 force_gimple_operand (expr, &stmts, true, NULL); | 2741 force_gimple_operand (expr, &stmts, true, NULL); |
2719 gsi_insert_seq_on_edge (edge_initial_value_for_loop_phi (loop_phi), stmts); | 2742 gsi_insert_seq_on_edge (edge_initial_value_for_loop_phi (loop_phi), stmts); |
2720 } | 2743 } |
2721 | 2744 |
2745 /* Removes the PHI node and resets all the debug stmts that are using | |
2746 the PHI_RESULT. */ | |
2747 | |
2748 static void | |
2749 remove_phi (gimple phi) | |
2750 { | |
2751 imm_use_iterator imm_iter; | |
2752 tree def; | |
2753 use_operand_p use_p; | |
2754 gimple_stmt_iterator gsi; | |
2755 VEC (gimple, heap) *update = VEC_alloc (gimple, heap, 3); | |
2756 unsigned int i; | |
2757 gimple stmt; | |
2758 | |
2759 def = PHI_RESULT (phi); | |
2760 FOR_EACH_IMM_USE_FAST (use_p, imm_iter, def) | |
2761 { | |
2762 stmt = USE_STMT (use_p); | |
2763 | |
2764 if (is_gimple_debug (stmt)) | |
2765 { | |
2766 gimple_debug_bind_reset_value (stmt); | |
2767 VEC_safe_push (gimple, heap, update, stmt); | |
2768 } | |
2769 } | |
2770 | |
2771 for (i = 0; VEC_iterate (gimple, update, i, stmt); i++) | |
2772 update_stmt (stmt); | |
2773 | |
2774 VEC_free (gimple, heap, update); | |
2775 | |
2776 gsi = gsi_for_phi_node (phi); | |
2777 remove_phi_node (&gsi, false); | |
2778 } | |
2779 | |
2722 /* Rewrite out of SSA the reduction described by the loop phi nodes | 2780 /* Rewrite out of SSA the reduction described by the loop phi nodes |
2723 IN, and the close phi nodes OUT. IN and OUT are structured by loop | 2781 IN, and the close phi nodes OUT. IN and OUT are structured by loop |
2724 levels like this: | 2782 levels like this: |
2725 | 2783 |
2726 IN: stmt, loop_n, ..., loop_0 | 2784 IN: stmt, loop_n, ..., loop_0 |
2734 VEC (gimple, heap) *out, | 2792 VEC (gimple, heap) *out, |
2735 sbitmap reductions) | 2793 sbitmap reductions) |
2736 { | 2794 { |
2737 unsigned int i; | 2795 unsigned int i; |
2738 gimple loop_phi; | 2796 gimple loop_phi; |
2739 tree red; | 2797 tree red = NULL_TREE; |
2740 gimple_stmt_iterator gsi; | |
2741 | 2798 |
2742 for (i = 0; VEC_iterate (gimple, in, i, loop_phi); i++) | 2799 for (i = 0; VEC_iterate (gimple, in, i, loop_phi); i++) |
2743 { | 2800 { |
2744 gimple close_phi = VEC_index (gimple, out, i); | 2801 gimple close_phi = VEC_index (gimple, out, i); |
2745 | 2802 |
2762 { | 2819 { |
2763 insert_copyout (red, close_phi); | 2820 insert_copyout (red, close_phi); |
2764 insert_copyin (red, loop_phi); | 2821 insert_copyin (red, loop_phi); |
2765 } | 2822 } |
2766 | 2823 |
2767 gsi = gsi_for_phi_node (loop_phi); | 2824 remove_phi (loop_phi); |
2768 remove_phi_node (&gsi, false); | 2825 remove_phi (close_phi); |
2769 | |
2770 gsi = gsi_for_phi_node (close_phi); | |
2771 remove_phi_node (&gsi, false); | |
2772 } | 2826 } |
2773 } | 2827 } |
2774 | 2828 |
2775 /* Rewrites out of SSA a commutative reduction at CLOSE_PHI. */ | 2829 /* Rewrites out of SSA a commutative reduction at CLOSE_PHI. */ |
2776 | 2830 |
2819 rewrite_commutative_reductions_out_of_ssa_loop (loop, reductions); | 2873 rewrite_commutative_reductions_out_of_ssa_loop (loop, reductions); |
2820 | 2874 |
2821 gsi_commit_edge_inserts (); | 2875 gsi_commit_edge_inserts (); |
2822 update_ssa (TODO_update_ssa); | 2876 update_ssa (TODO_update_ssa); |
2823 #ifdef ENABLE_CHECKING | 2877 #ifdef ENABLE_CHECKING |
2824 verify_ssa (false); | 2878 verify_loop_closed_ssa (true); |
2825 verify_loop_closed_ssa (); | |
2826 #endif | 2879 #endif |
2827 } | 2880 } |
2828 | 2881 |
2829 /* A LOOP is in normal form for Graphite when it contains only one | 2882 /* A LOOP is in normal form for Graphite when it contains only one |
2830 scalar phi node that defines the main induction variable of the | 2883 scalar phi node that defines the main induction variable of the |
2838 gimple_seq stmts; | 2891 gimple_seq stmts; |
2839 edge exit = single_dom_exit (loop); | 2892 edge exit = single_dom_exit (loop); |
2840 | 2893 |
2841 bool known_niter = number_of_iterations_exit (loop, exit, &niter, false); | 2894 bool known_niter = number_of_iterations_exit (loop, exit, &niter, false); |
2842 | 2895 |
2843 /* At this point we should know the number of iterations, */ | 2896 /* At this point we should know the number of iterations. */ |
2844 gcc_assert (known_niter); | 2897 gcc_assert (known_niter); |
2845 | 2898 |
2846 nit = force_gimple_operand (unshare_expr (niter.niter), &stmts, true, | 2899 nit = force_gimple_operand (unshare_expr (niter.niter), &stmts, true, |
2847 NULL_TREE); | 2900 NULL_TREE); |
2848 if (stmts) | 2901 if (stmts) |
2849 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts); | 2902 gsi_insert_seq_on_edge_immediate (loop_preheader_edge (loop), stmts); |
2850 | 2903 |
2851 loop->single_iv = canonicalize_loop_ivs (loop, &nit); | 2904 loop->single_iv = canonicalize_loop_ivs (loop, &nit, false); |
2852 } | 2905 } |
2853 | 2906 |
2854 /* Rewrite all the loops of SCOP in normal form: one induction | 2907 /* Rewrite all the loops of SCOP in normal form: one induction |
2855 variable per loop. */ | 2908 variable per loop. */ |
2856 | 2909 |
2863 FOR_EACH_LOOP (li, loop, 0) | 2916 FOR_EACH_LOOP (li, loop, 0) |
2864 if (loop_in_sese_p (loop, SCOP_REGION (scop))) | 2917 if (loop_in_sese_p (loop, SCOP_REGION (scop))) |
2865 graphite_loop_normal_form (loop); | 2918 graphite_loop_normal_form (loop); |
2866 } | 2919 } |
2867 | 2920 |
2921 /* Java does not initialize long_long_integer_type_node. */ | |
2922 #define my_long_long (long_long_integer_type_node ? long_long_integer_type_node : ssizetype) | |
2923 | |
2924 /* Can all ivs be represented by a signed integer? | |
2925 As CLooG might generate negative values in its expressions, signed loop ivs | |
2926 are required in the backend. */ | |
2927 static bool | |
2928 scop_ivs_can_be_represented (scop_p scop) | |
2929 { | |
2930 loop_iterator li; | |
2931 loop_p loop; | |
2932 | |
2933 FOR_EACH_LOOP (li, loop, 0) | |
2934 { | |
2935 tree type; | |
2936 int precision; | |
2937 | |
2938 if (!loop_in_sese_p (loop, SCOP_REGION (scop))) | |
2939 continue; | |
2940 | |
2941 if (!loop->single_iv) | |
2942 continue; | |
2943 | |
2944 type = TREE_TYPE(loop->single_iv); | |
2945 precision = TYPE_PRECISION (type); | |
2946 | |
2947 if (TYPE_UNSIGNED (type) | |
2948 && precision >= TYPE_PRECISION (my_long_long)) | |
2949 return false; | |
2950 } | |
2951 | |
2952 return true; | |
2953 } | |
2954 | |
2955 #undef my_long_long | |
2956 | |
2868 /* Builds the polyhedral representation for a SESE region. */ | 2957 /* Builds the polyhedral representation for a SESE region. */ |
2869 | 2958 |
2870 bool | 2959 void |
2871 build_poly_scop (scop_p scop) | 2960 build_poly_scop (scop_p scop) |
2872 { | 2961 { |
2873 sese region = SCOP_REGION (scop); | 2962 sese region = SCOP_REGION (scop); |
2874 sbitmap reductions = sbitmap_alloc (last_basic_block * 2); | 2963 sbitmap reductions = sbitmap_alloc (last_basic_block * 2); |
2964 graphite_dim_t max_dim; | |
2875 | 2965 |
2876 sbitmap_zero (reductions); | 2966 sbitmap_zero (reductions); |
2877 rewrite_commutative_reductions_out_of_ssa (region, reductions); | 2967 rewrite_commutative_reductions_out_of_ssa (region, reductions); |
2878 rewrite_reductions_out_of_ssa (scop); | 2968 rewrite_reductions_out_of_ssa (scop); |
2879 build_scop_bbs (scop, reductions); | 2969 build_scop_bbs (scop, reductions); |
2882 /* FIXME: This restriction is needed to avoid a problem in CLooG. | 2972 /* FIXME: This restriction is needed to avoid a problem in CLooG. |
2883 Once CLooG is fixed, remove this guard. Anyways, it makes no | 2973 Once CLooG is fixed, remove this guard. Anyways, it makes no |
2884 sense to optimize a scop containing only PBBs that do not belong | 2974 sense to optimize a scop containing only PBBs that do not belong |
2885 to any loops. */ | 2975 to any loops. */ |
2886 if (nb_pbbs_in_loops (scop) == 0) | 2976 if (nb_pbbs_in_loops (scop) == 0) |
2887 return false; | 2977 return; |
2888 | 2978 |
2889 scop_canonicalize_loops (scop); | 2979 scop_canonicalize_loops (scop); |
2980 if (!scop_ivs_can_be_represented (scop)) | |
2981 return; | |
2982 | |
2890 build_sese_loop_nests (region); | 2983 build_sese_loop_nests (region); |
2891 build_sese_conditions (region); | 2984 build_sese_conditions (region); |
2892 find_scop_parameters (scop); | 2985 find_scop_parameters (scop); |
2986 | |
2987 max_dim = PARAM_VALUE (PARAM_GRAPHITE_MAX_NB_SCOP_PARAMS); | |
2988 if (scop_nb_params (scop) > max_dim) | |
2989 return; | |
2893 | 2990 |
2894 build_scop_iteration_domain (scop); | 2991 build_scop_iteration_domain (scop); |
2895 build_scop_context (scop); | 2992 build_scop_context (scop); |
2896 | 2993 |
2897 add_conditions_to_constraints (scop); | 2994 add_conditions_to_constraints (scop); |
2898 scop_to_lst (scop); | 2995 scop_to_lst (scop); |
2899 build_scop_scattering (scop); | 2996 build_scop_scattering (scop); |
2900 build_scop_drs (scop); | 2997 build_scop_drs (scop); |
2901 | 2998 |
2902 return true; | 2999 /* This SCoP has been translated to the polyhedral |
3000 representation. */ | |
3001 POLY_SCOP_P (scop) = true; | |
2903 } | 3002 } |
2904 | 3003 |
2905 /* Always return false. Exercise the scop_to_clast function. */ | 3004 /* Always return false. Exercise the scop_to_clast function. */ |
2906 | 3005 |
2907 void | 3006 void |