comparison gcc/df-core.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* Allocation for dataflow support routines. 1 /* Allocation for dataflow support routines.
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2 Copyright (C) 1999-2017 Free Software Foundation, Inc.
3 2008, 2009, 2010 Free Software Foundation, Inc.
4 Originally contributed by Michael P. Hayes 3 Originally contributed by Michael P. Hayes
5 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com) 4 (m.hayes@elec.canterbury.ac.nz, mhayes@redhat.com)
6 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org) 5 Major rewrite contributed by Danny Berlin (dberlin@dberlin.org)
7 and Kenneth Zadeck (zadeck@naturalbridge.com). 6 and Kenneth Zadeck (zadeck@naturalbridge.com).
8 7
180 in the pass. In the case of 1a or 1b, a call to df_finish_pass 179 in the pass. In the case of 1a or 1b, a call to df_finish_pass
181 (either manually or via TODO_df_finish) should be made before the 180 (either manually or via TODO_df_finish) should be made before the
182 next call to df_analyze or df_process_deferred_rescans. 181 next call to df_analyze or df_process_deferred_rescans.
183 182
184 This mode is also used by a few passes that still rely on note_uses, 183 This mode is also used by a few passes that still rely on note_uses,
185 note_stores and for_each_rtx instead of using the DF data. This 184 note_stores and rtx iterators instead of using the DF data. This
186 can be said to fall under case 1c. 185 can be said to fall under case 1c.
187 186
188 To enable this mode, call df_set_flags (DF_DEFER_INSN_RESCAN). 187 To enable this mode, call df_set_flags (DF_DEFER_INSN_RESCAN).
189 (This mode can be cleared by calling df_clear_flags 188 (This mode can be cleared by calling df_clear_flags
190 (DF_DEFER_INSN_RESCAN) but this does not cause the deferred insns to 189 (DF_DEFER_INSN_RESCAN) but this does not cause the deferred insns to
376 375
377 376
378 #include "config.h" 377 #include "config.h"
379 #include "system.h" 378 #include "system.h"
380 #include "coretypes.h" 379 #include "coretypes.h"
381 #include "tm.h" 380 #include "backend.h"
382 #include "rtl.h" 381 #include "rtl.h"
383 #include "tm_p.h"
384 #include "insn-config.h"
385 #include "recog.h"
386 #include "function.h"
387 #include "regs.h"
388 #include "output.h"
389 #include "alloc-pool.h"
390 #include "flags.h"
391 #include "hard-reg-set.h"
392 #include "basic-block.h"
393 #include "sbitmap.h"
394 #include "bitmap.h"
395 #include "timevar.h"
396 #include "df.h" 382 #include "df.h"
383 #include "memmodel.h"
384 #include "emit-rtl.h"
385 #include "cfganal.h"
397 #include "tree-pass.h" 386 #include "tree-pass.h"
398 #include "params.h" 387 #include "cfgloop.h"
399 388
400 static void *df_get_bb_info (struct dataflow *, unsigned int); 389 static void *df_get_bb_info (struct dataflow *, unsigned int);
401 static void df_set_bb_info (struct dataflow *, unsigned int, void *); 390 static void df_set_bb_info (struct dataflow *, unsigned int, void *);
402 static void df_clear_bb_info (struct dataflow *, unsigned int); 391 static void df_clear_bb_info (struct dataflow *, unsigned int);
403 #ifdef DF_DEBUG_CFG 392 #ifdef DF_DEBUG_CFG
404 static void df_set_clean_cfg (void); 393 static void df_set_clean_cfg (void);
405 #endif 394 #endif
406 395
396 /* The obstack on which regsets are allocated. */
397 struct bitmap_obstack reg_obstack;
398
407 /* An obstack for bitmap not related to specific dataflow problems. 399 /* An obstack for bitmap not related to specific dataflow problems.
408 This obstack should e.g. be used for bitmaps with a short life time 400 This obstack should e.g. be used for bitmaps with a short life time
409 such as temporary bitmaps. */ 401 such as temporary bitmaps. */
410 402
411 bitmap_obstack df_bitmap_obstack; 403 bitmap_obstack df_bitmap_obstack;
418 struct df_d *df; 410 struct df_d *df;
419 411
420 /* Add PROBLEM (and any dependent problems) to the DF instance. */ 412 /* Add PROBLEM (and any dependent problems) to the DF instance. */
421 413
422 void 414 void
423 df_add_problem (struct df_problem *problem) 415 df_add_problem (const struct df_problem *problem)
424 { 416 {
425 struct dataflow *dflow; 417 struct dataflow *dflow;
426 int i; 418 int i;
427 419
428 /* First try to add the dependent problem. */ 420 /* First try to add the dependent problem. */
503 if (df->blocks_to_analyze) 495 if (df->blocks_to_analyze)
504 { 496 {
505 /* This block is called to change the focus from one subset 497 /* This block is called to change the focus from one subset
506 to another. */ 498 to another. */
507 int p; 499 int p;
508 bitmap_head diff; 500 auto_bitmap diff (&df_bitmap_obstack);
509 bitmap_initialize (&diff, &df_bitmap_obstack); 501 bitmap_and_compl (diff, df->blocks_to_analyze, blocks);
510 bitmap_and_compl (&diff, df->blocks_to_analyze, blocks);
511 for (p = 0; p < df->num_problems_defined; p++) 502 for (p = 0; p < df->num_problems_defined; p++)
512 { 503 {
513 struct dataflow *dflow = df->problems_in_order[p]; 504 struct dataflow *dflow = df->problems_in_order[p];
514 if (dflow->optional_p && dflow->problem->reset_fun) 505 if (dflow->optional_p && dflow->problem->reset_fun)
515 dflow->problem->reset_fun (df->blocks_to_analyze); 506 dflow->problem->reset_fun (df->blocks_to_analyze);
516 else if (dflow->problem->free_blocks_on_set_blocks) 507 else if (dflow->problem->free_blocks_on_set_blocks)
517 { 508 {
518 bitmap_iterator bi; 509 bitmap_iterator bi;
519 unsigned int bb_index; 510 unsigned int bb_index;
520 511
521 EXECUTE_IF_SET_IN_BITMAP (&diff, 0, bb_index, bi) 512 EXECUTE_IF_SET_IN_BITMAP (diff, 0, bb_index, bi)
522 { 513 {
523 basic_block bb = BASIC_BLOCK (bb_index); 514 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
524 if (bb) 515 if (bb)
525 { 516 {
526 void *bb_info = df_get_bb_info (dflow, bb_index); 517 void *bb_info = df_get_bb_info (dflow, bb_index);
527 dflow->problem->free_bb_fun (bb, bb_info); 518 dflow->problem->free_bb_fun (bb, bb_info);
528 df_clear_bb_info (dflow, bb_index); 519 df_clear_bb_info (dflow, bb_index);
529 } 520 }
530 } 521 }
531 } 522 }
532 } 523 }
533
534 bitmap_clear (&diff);
535 } 524 }
536 else 525 else
537 { 526 {
538 /* This block of code is executed to change the focus from 527 /* This block of code is executed to change the focus from
539 the entire function to a subset. */ 528 the entire function to a subset. */
547 { 536 {
548 if (!initialized) 537 if (!initialized)
549 { 538 {
550 basic_block bb; 539 basic_block bb;
551 bitmap_initialize (&blocks_to_reset, &df_bitmap_obstack); 540 bitmap_initialize (&blocks_to_reset, &df_bitmap_obstack);
552 FOR_ALL_BB(bb) 541 FOR_ALL_BB_FN (bb, cfun)
553 { 542 {
554 bitmap_set_bit (&blocks_to_reset, bb->index); 543 bitmap_set_bit (&blocks_to_reset, bb->index);
555 } 544 }
556 } 545 }
557 dflow->problem->reset_fun (&blocks_to_reset); 546 dflow->problem->reset_fun (&blocks_to_reset);
591 problem). */ 580 problem). */
592 581
593 void 582 void
594 df_remove_problem (struct dataflow *dflow) 583 df_remove_problem (struct dataflow *dflow)
595 { 584 {
596 struct df_problem *problem; 585 const struct df_problem *problem;
597 int i; 586 int i;
598 587
599 if (!dflow) 588 if (!dflow)
600 return; 589 return;
601 590
630 619
631 void 620 void
632 df_finish_pass (bool verify ATTRIBUTE_UNUSED) 621 df_finish_pass (bool verify ATTRIBUTE_UNUSED)
633 { 622 {
634 int i; 623 int i;
635 int removed = 0;
636 624
637 #ifdef ENABLE_DF_CHECKING 625 #ifdef ENABLE_DF_CHECKING
638 int saved_flags; 626 int saved_flags;
639 #endif 627 #endif
640 628
646 634
647 #ifdef ENABLE_DF_CHECKING 635 #ifdef ENABLE_DF_CHECKING
648 saved_flags = df->changeable_flags; 636 saved_flags = df->changeable_flags;
649 #endif 637 #endif
650 638
651 for (i = 0; i < df->num_problems_defined; i++) 639 /* We iterate over problems by index as each problem removed will
652 { 640 lead to problems_in_order to be reordered. */
653 struct dataflow *dflow = df->problems_in_order[i]; 641 for (i = 0; i < DF_LAST_PROBLEM_PLUS1; i++)
654 struct df_problem *problem = dflow->problem; 642 {
655 643 struct dataflow *dflow = df->problems_by_index[i];
656 if (dflow->optional_p) 644
657 { 645 if (dflow && dflow->optional_p)
658 gcc_assert (problem->remove_problem_fun); 646 df_remove_problem (dflow);
659 (problem->remove_problem_fun) (); 647 }
660 df->problems_in_order[i] = NULL;
661 df->problems_by_index[problem->id] = NULL;
662 removed++;
663 }
664 }
665 df->num_problems_defined -= removed;
666 648
667 /* Clear all of the flags. */ 649 /* Clear all of the flags. */
668 df->changeable_flags = 0; 650 df->changeable_flags = 0;
669 df_process_deferred_rescans (); 651 df_process_deferred_rescans ();
670 652
689 #ifdef DF_DEBUG_CFG 671 #ifdef DF_DEBUG_CFG
690 df_set_clean_cfg (); 672 df_set_clean_cfg ();
691 #endif 673 #endif
692 #endif 674 #endif
693 675
694 #ifdef ENABLE_CHECKING 676 if (flag_checking && verify)
695 if (verify)
696 df->changeable_flags |= DF_VERIFY_SCHEDULED; 677 df->changeable_flags |= DF_VERIFY_SCHEDULED;
697 #endif
698 } 678 }
699 679
700 680
701 /* Set up the dataflow instance for the entire back end. */ 681 /* Set up the dataflow instance for the entire back end. */
702 682
709 689
710 bitmap_obstack_initialize (&df_bitmap_obstack); 690 bitmap_obstack_initialize (&df_bitmap_obstack);
711 691
712 /* Set this to a conservative value. Stack_ptr_mod will compute it 692 /* Set this to a conservative value. Stack_ptr_mod will compute it
713 correctly later. */ 693 correctly later. */
714 current_function_sp_is_unchanging = 0; 694 crtl->sp_is_unchanging = 0;
715 695
716 df_scan_add_problem (); 696 df_scan_add_problem ();
717 df_scan_alloc (NULL); 697 df_scan_alloc (NULL);
718 698
719 /* These three problems are permanent. */ 699 /* These three problems are permanent. */
720 df_lr_add_problem (); 700 df_lr_add_problem ();
721 if (optimize > 1) 701 if (optimize > 1)
722 df_live_add_problem (); 702 df_live_add_problem ();
723 703
724 df->postorder = XNEWVEC (int, last_basic_block); 704 df->postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
725 df->postorder_inverted = XNEWVEC (int, last_basic_block);
726 df->n_blocks = post_order_compute (df->postorder, true, true); 705 df->n_blocks = post_order_compute (df->postorder, true, true);
727 df->n_blocks_inverted = inverted_post_order_compute (df->postorder_inverted); 706 inverted_post_order_compute (&df->postorder_inverted);
728 gcc_assert (df->n_blocks == df->n_blocks_inverted); 707 gcc_assert ((unsigned) df->n_blocks == df->postorder_inverted.length ());
729 708
730 df->hard_regs_live_count = XNEWVEC (unsigned int, FIRST_PSEUDO_REGISTER); 709 df->hard_regs_live_count = XCNEWVEC (unsigned int, FIRST_PSEUDO_REGISTER);
731 memset (df->hard_regs_live_count, 0,
732 sizeof (unsigned int) * FIRST_PSEUDO_REGISTER);
733 710
734 df_hard_reg_init (); 711 df_hard_reg_init ();
735 /* After reload, some ports add certain bits to regs_ever_live so 712 /* After reload, some ports add certain bits to regs_ever_live so
736 this cannot be reset. */ 713 this cannot be reset. */
737 df_compute_regs_ever_live (true); 714 df_compute_regs_ever_live (true);
739 df_compute_regs_ever_live (false); 716 df_compute_regs_ever_live (false);
740 return 0; 717 return 0;
741 } 718 }
742 719
743 720
744 static bool 721 namespace {
745 gate_opt (void) 722
746 { 723 const pass_data pass_data_df_initialize_opt =
747 return optimize > 0; 724 {
748 } 725 RTL_PASS, /* type */
749 726 "dfinit", /* name */
750 727 OPTGROUP_NONE, /* optinfo_flags */
751 struct rtl_opt_pass pass_df_initialize_opt = 728 TV_DF_SCAN, /* tv_id */
752 { 729 0, /* properties_required */
753 { 730 0, /* properties_provided */
754 RTL_PASS, 731 0, /* properties_destroyed */
755 "dfinit", /* name */ 732 0, /* todo_flags_start */
756 gate_opt, /* gate */ 733 0, /* todo_flags_finish */
757 rest_of_handle_df_initialize, /* execute */
758 NULL, /* sub */
759 NULL, /* next */
760 0, /* static_pass_number */
761 TV_DF_SCAN, /* tv_id */
762 0, /* properties_required */
763 0, /* properties_provided */
764 0, /* properties_destroyed */
765 0, /* todo_flags_start */
766 0 /* todo_flags_finish */
767 }
768 }; 734 };
769 735
770 736 class pass_df_initialize_opt : public rtl_opt_pass
771 static bool 737 {
772 gate_no_opt (void) 738 public:
773 { 739 pass_df_initialize_opt (gcc::context *ctxt)
774 return optimize == 0; 740 : rtl_opt_pass (pass_data_df_initialize_opt, ctxt)
775 } 741 {}
776 742
777 743 /* opt_pass methods: */
778 struct rtl_opt_pass pass_df_initialize_no_opt = 744 virtual bool gate (function *) { return optimize > 0; }
779 { 745 virtual unsigned int execute (function *)
780 { 746 {
781 RTL_PASS, 747 return rest_of_handle_df_initialize ();
782 "no-opt dfinit", /* name */ 748 }
783 gate_no_opt, /* gate */ 749
784 rest_of_handle_df_initialize, /* execute */ 750 }; // class pass_df_initialize_opt
785 NULL, /* sub */ 751
786 NULL, /* next */ 752 } // anon namespace
787 0, /* static_pass_number */ 753
788 TV_DF_SCAN, /* tv_id */ 754 rtl_opt_pass *
789 0, /* properties_required */ 755 make_pass_df_initialize_opt (gcc::context *ctxt)
790 0, /* properties_provided */ 756 {
791 0, /* properties_destroyed */ 757 return new pass_df_initialize_opt (ctxt);
792 0, /* todo_flags_start */ 758 }
793 0 /* todo_flags_finish */ 759
794 } 760
761 namespace {
762
763 const pass_data pass_data_df_initialize_no_opt =
764 {
765 RTL_PASS, /* type */
766 "no-opt dfinit", /* name */
767 OPTGROUP_NONE, /* optinfo_flags */
768 TV_DF_SCAN, /* tv_id */
769 0, /* properties_required */
770 0, /* properties_provided */
771 0, /* properties_destroyed */
772 0, /* todo_flags_start */
773 0, /* todo_flags_finish */
795 }; 774 };
775
776 class pass_df_initialize_no_opt : public rtl_opt_pass
777 {
778 public:
779 pass_df_initialize_no_opt (gcc::context *ctxt)
780 : rtl_opt_pass (pass_data_df_initialize_no_opt, ctxt)
781 {}
782
783 /* opt_pass methods: */
784 virtual bool gate (function *) { return optimize == 0; }
785 virtual unsigned int execute (function *)
786 {
787 return rest_of_handle_df_initialize ();
788 }
789
790 }; // class pass_df_initialize_no_opt
791
792 } // anon namespace
793
794 rtl_opt_pass *
795 make_pass_df_initialize_no_opt (gcc::context *ctxt)
796 {
797 return new pass_df_initialize_no_opt (ctxt);
798 }
796 799
797 800
798 /* Free all the dataflow info and the DF structure. This should be 801 /* Free all the dataflow info and the DF structure. This should be
799 called from the df_finish macro which also NULLs the parm. */ 802 called from the df_finish macro which also NULLs the parm. */
800 803
809 { 812 {
810 struct dataflow *dflow = df->problems_in_order[i]; 813 struct dataflow *dflow = df->problems_in_order[i];
811 dflow->problem->free_fun (); 814 dflow->problem->free_fun ();
812 } 815 }
813 816
814 if (df->postorder) 817 free (df->postorder);
815 free (df->postorder); 818 df->postorder_inverted.release ();
816 if (df->postorder_inverted)
817 free (df->postorder_inverted);
818 free (df->hard_regs_live_count); 819 free (df->hard_regs_live_count);
819 free (df); 820 free (df);
820 df = NULL; 821 df = NULL;
821 822
822 bitmap_obstack_release (&df_bitmap_obstack); 823 bitmap_obstack_release (&df_bitmap_obstack);
823 return 0; 824 return 0;
824 } 825 }
825 826
826 827
827 struct rtl_opt_pass pass_df_finish = 828 namespace {
828 { 829
829 { 830 const pass_data pass_data_df_finish =
830 RTL_PASS, 831 {
831 "dfinish", /* name */ 832 RTL_PASS, /* type */
832 NULL, /* gate */ 833 "dfinish", /* name */
833 rest_of_handle_df_finish, /* execute */ 834 OPTGROUP_NONE, /* optinfo_flags */
834 NULL, /* sub */ 835 TV_NONE, /* tv_id */
835 NULL, /* next */ 836 0, /* properties_required */
836 0, /* static_pass_number */ 837 0, /* properties_provided */
837 TV_NONE, /* tv_id */ 838 0, /* properties_destroyed */
838 0, /* properties_required */ 839 0, /* todo_flags_start */
839 0, /* properties_provided */ 840 0, /* todo_flags_finish */
840 0, /* properties_destroyed */
841 0, /* todo_flags_start */
842 0 /* todo_flags_finish */
843 }
844 }; 841 };
842
843 class pass_df_finish : public rtl_opt_pass
844 {
845 public:
846 pass_df_finish (gcc::context *ctxt)
847 : rtl_opt_pass (pass_data_df_finish, ctxt)
848 {}
849
850 /* opt_pass methods: */
851 virtual unsigned int execute (function *)
852 {
853 return rest_of_handle_df_finish ();
854 }
855
856 }; // class pass_df_finish
857
858 } // anon namespace
859
860 rtl_opt_pass *
861 make_pass_df_finish (gcc::context *ctxt)
862 {
863 return new pass_df_finish (ctxt);
864 }
845 865
846 866
847 867
848 868
849 869
879 sbitmap considered, 899 sbitmap considered,
880 ptrdiff_t age) 900 ptrdiff_t age)
881 { 901 {
882 edge e; 902 edge e;
883 edge_iterator ei; 903 edge_iterator ei;
884 basic_block bb = BASIC_BLOCK (bb_index); 904 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
885 bool changed = !age; 905 bool changed = !age;
886 906
887 /* Calculate <conf_op> of incoming edges. */ 907 /* Calculate <conf_op> of incoming edges. */
888 if (EDGE_COUNT (bb->preds) > 0) 908 if (EDGE_COUNT (bb->preds) > 0)
889 FOR_EACH_EDGE (e, ei, bb->preds) 909 FOR_EACH_EDGE (e, ei, bb->preds)
890 { 910 {
891 if (age <= BB_LAST_CHANGE_AGE (e->src) 911 if (age <= BB_LAST_CHANGE_AGE (e->src)
892 && TEST_BIT (considered, e->src->index)) 912 && bitmap_bit_p (considered, e->src->index))
893 changed |= dataflow->problem->con_fun_n (e); 913 changed |= dataflow->problem->con_fun_n (e);
894 } 914 }
895 else if (dataflow->problem->con_fun_0) 915 else if (dataflow->problem->con_fun_0)
896 dataflow->problem->con_fun_0 (bb); 916 dataflow->problem->con_fun_0 (bb);
897 917
902 Propagate to the outgoing blocks. */ 922 Propagate to the outgoing blocks. */
903 FOR_EACH_EDGE (e, ei, bb->succs) 923 FOR_EACH_EDGE (e, ei, bb->succs)
904 { 924 {
905 unsigned ob_index = e->dest->index; 925 unsigned ob_index = e->dest->index;
906 926
907 if (TEST_BIT (considered, ob_index)) 927 if (bitmap_bit_p (considered, ob_index))
908 bitmap_set_bit (pending, bbindex_to_postorder[ob_index]); 928 bitmap_set_bit (pending, bbindex_to_postorder[ob_index]);
909 } 929 }
910 return true; 930 return true;
911 } 931 }
912 return false; 932 return false;
924 sbitmap considered, 944 sbitmap considered,
925 ptrdiff_t age) 945 ptrdiff_t age)
926 { 946 {
927 edge e; 947 edge e;
928 edge_iterator ei; 948 edge_iterator ei;
929 basic_block bb = BASIC_BLOCK (bb_index); 949 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
930 bool changed = !age; 950 bool changed = !age;
931 951
932 /* Calculate <conf_op> of incoming edges. */ 952 /* Calculate <conf_op> of incoming edges. */
933 if (EDGE_COUNT (bb->succs) > 0) 953 if (EDGE_COUNT (bb->succs) > 0)
934 FOR_EACH_EDGE (e, ei, bb->succs) 954 FOR_EACH_EDGE (e, ei, bb->succs)
935 { 955 {
936 if (age <= BB_LAST_CHANGE_AGE (e->dest) 956 if (age <= BB_LAST_CHANGE_AGE (e->dest)
937 && TEST_BIT (considered, e->dest->index)) 957 && bitmap_bit_p (considered, e->dest->index))
938 changed |= dataflow->problem->con_fun_n (e); 958 changed |= dataflow->problem->con_fun_n (e);
939 } 959 }
940 else if (dataflow->problem->con_fun_0) 960 else if (dataflow->problem->con_fun_0)
941 dataflow->problem->con_fun_0 (bb); 961 dataflow->problem->con_fun_0 (bb);
942 962
947 Propagate to the outgoing blocks. */ 967 Propagate to the outgoing blocks. */
948 FOR_EACH_EDGE (e, ei, bb->preds) 968 FOR_EACH_EDGE (e, ei, bb->preds)
949 { 969 {
950 unsigned ob_index = e->src->index; 970 unsigned ob_index = e->src->index;
951 971
952 if (TEST_BIT (considered, ob_index)) 972 if (bitmap_bit_p (considered, ob_index))
953 bitmap_set_bit (pending, bbindex_to_postorder[ob_index]); 973 bitmap_set_bit (pending, bbindex_to_postorder[ob_index]);
954 } 974 }
955 return true; 975 return true;
956 } 976 }
957 return false; 977 return false;
960 /* Main dataflow solver loop. 980 /* Main dataflow solver loop.
961 981
962 DATAFLOW is problem we are solving, PENDING is worklist of basic blocks we 982 DATAFLOW is problem we are solving, PENDING is worklist of basic blocks we
963 need to visit. 983 need to visit.
964 BLOCK_IN_POSTORDER is array of size N_BLOCKS specifying postorder in BBs and 984 BLOCK_IN_POSTORDER is array of size N_BLOCKS specifying postorder in BBs and
965 BBINDEX_TO_POSTORDER is array mapping back BB->index to postorder possition. 985 BBINDEX_TO_POSTORDER is array mapping back BB->index to postorder position.
966 PENDING will be freed. 986 PENDING will be freed.
967 987
968 The worklists are bitmaps indexed by postorder positions. 988 The worklists are bitmaps indexed by postorder positions.
969 989
970 The function implements standard algorithm for dataflow solving with two 990 The function implements standard algorithm for dataflow solving with two
987 enum df_flow_dir dir = dataflow->problem->dir; 1007 enum df_flow_dir dir = dataflow->problem->dir;
988 int dcount = 0; 1008 int dcount = 0;
989 bitmap worklist = BITMAP_ALLOC (&df_bitmap_obstack); 1009 bitmap worklist = BITMAP_ALLOC (&df_bitmap_obstack);
990 int age = 0; 1010 int age = 0;
991 bool changed; 1011 bool changed;
992 VEC(int, heap) *last_visit_age = NULL; 1012 vec<int> last_visit_age = vNULL;
993 int prev_age; 1013 int prev_age;
994 basic_block bb; 1014 basic_block bb;
995 int i; 1015 int i;
996 1016
997 VEC_safe_grow_cleared (int, heap, last_visit_age, n_blocks); 1017 last_visit_age.safe_grow_cleared (n_blocks);
998 1018
999 /* Double-queueing. Worklist is for the current iteration, 1019 /* Double-queueing. Worklist is for the current iteration,
1000 and pending is for the next. */ 1020 and pending is for the next. */
1001 while (!bitmap_empty_p (pending)) 1021 while (!bitmap_empty_p (pending))
1002 { 1022 {
1003 bitmap_iterator bi; 1023 bitmap_iterator bi;
1004 unsigned int index; 1024 unsigned int index;
1005 1025
1006 /* Swap pending and worklist. */ 1026 std::swap (pending, worklist);
1007 bitmap temp = worklist;
1008 worklist = pending;
1009 pending = temp;
1010 1027
1011 EXECUTE_IF_SET_IN_BITMAP (worklist, 0, index, bi) 1028 EXECUTE_IF_SET_IN_BITMAP (worklist, 0, index, bi)
1012 { 1029 {
1013 unsigned bb_index; 1030 unsigned bb_index;
1014 dcount++; 1031 dcount++;
1015 1032
1016 bitmap_clear_bit (pending, index); 1033 bitmap_clear_bit (pending, index);
1017 bb_index = blocks_in_postorder[index]; 1034 bb_index = blocks_in_postorder[index];
1018 bb = BASIC_BLOCK (bb_index); 1035 bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1019 prev_age = VEC_index (int, last_visit_age, index); 1036 prev_age = last_visit_age[index];
1020 if (dir == DF_FORWARD) 1037 if (dir == DF_FORWARD)
1021 changed = df_worklist_propagate_forward (dataflow, bb_index, 1038 changed = df_worklist_propagate_forward (dataflow, bb_index,
1022 bbindex_to_postorder, 1039 bbindex_to_postorder,
1023 pending, considered, 1040 pending, considered,
1024 prev_age); 1041 prev_age);
1025 else 1042 else
1026 changed = df_worklist_propagate_backward (dataflow, bb_index, 1043 changed = df_worklist_propagate_backward (dataflow, bb_index,
1027 bbindex_to_postorder, 1044 bbindex_to_postorder,
1028 pending, considered, 1045 pending, considered,
1029 prev_age); 1046 prev_age);
1030 VEC_replace (int, last_visit_age, index, ++age); 1047 last_visit_age[index] = ++age;
1031 if (changed) 1048 if (changed)
1032 bb->aux = (void *)(ptrdiff_t)age; 1049 bb->aux = (void *)(ptrdiff_t)age;
1033 } 1050 }
1034 bitmap_clear (worklist); 1051 bitmap_clear (worklist);
1035 } 1052 }
1036 for (i = 0; i < n_blocks; i++) 1053 for (i = 0; i < n_blocks; i++)
1037 BASIC_BLOCK (blocks_in_postorder[i])->aux = NULL; 1054 BASIC_BLOCK_FOR_FN (cfun, blocks_in_postorder[i])->aux = NULL;
1038 1055
1039 BITMAP_FREE (worklist); 1056 BITMAP_FREE (worklist);
1040 BITMAP_FREE (pending); 1057 BITMAP_FREE (pending);
1041 VEC_free (int, heap, last_visit_age); 1058 last_visit_age.release ();
1042 1059
1043 /* Dump statistics. */ 1060 /* Dump statistics. */
1044 if (dump_file) 1061 if (dump_file)
1045 fprintf (dump_file, "df_worklist_dataflow_doublequeue:" 1062 fprintf (dump_file, "df_worklist_dataflow_doublequeue:"
1046 "n_basic_blocks %d n_edges %d" 1063 " n_basic_blocks %d n_edges %d"
1047 " count %d (%5.2g)\n", 1064 " count %d (%5.2g)\n",
1048 n_basic_blocks, n_edges, 1065 n_basic_blocks_for_fn (cfun), n_edges_for_fn (cfun),
1049 dcount, dcount / (float)n_basic_blocks); 1066 dcount, dcount / (float)n_basic_blocks_for_fn (cfun));
1050 } 1067 }
1051 1068
1052 /* Worklist-based dataflow solver. It uses sbitmap as a worklist, 1069 /* Worklist-based dataflow solver. It uses sbitmap as a worklist,
1053 with "n"-th bit representing the n-th block in the reverse-postorder order. 1070 with "n"-th bit representing the n-th block in the reverse-postorder order.
1054 The solver is a double-queue algorithm similar to the "double stack" solver 1071 The solver is a double-queue algorithm similar to the "double stack" solver
1061 bitmap blocks_to_consider, 1078 bitmap blocks_to_consider,
1062 int *blocks_in_postorder, 1079 int *blocks_in_postorder,
1063 int n_blocks) 1080 int n_blocks)
1064 { 1081 {
1065 bitmap pending = BITMAP_ALLOC (&df_bitmap_obstack); 1082 bitmap pending = BITMAP_ALLOC (&df_bitmap_obstack);
1066 sbitmap considered = sbitmap_alloc (last_basic_block);
1067 bitmap_iterator bi; 1083 bitmap_iterator bi;
1068 unsigned int *bbindex_to_postorder; 1084 unsigned int *bbindex_to_postorder;
1069 int i; 1085 int i;
1070 unsigned int index; 1086 unsigned int index;
1071 enum df_flow_dir dir = dataflow->problem->dir; 1087 enum df_flow_dir dir = dataflow->problem->dir;
1072 1088
1073 gcc_assert (dir != DF_NONE); 1089 gcc_assert (dir != DF_NONE);
1074 1090
1075 /* BBINDEX_TO_POSTORDER maps the bb->index to the reverse postorder. */ 1091 /* BBINDEX_TO_POSTORDER maps the bb->index to the reverse postorder. */
1076 bbindex_to_postorder = 1092 bbindex_to_postorder = XNEWVEC (unsigned int,
1077 (unsigned int *)xmalloc (last_basic_block * sizeof (unsigned int)); 1093 last_basic_block_for_fn (cfun));
1078 1094
1079 /* Initialize the array to an out-of-bound value. */ 1095 /* Initialize the array to an out-of-bound value. */
1080 for (i = 0; i < last_basic_block; i++) 1096 for (i = 0; i < last_basic_block_for_fn (cfun); i++)
1081 bbindex_to_postorder[i] = last_basic_block; 1097 bbindex_to_postorder[i] = last_basic_block_for_fn (cfun);
1082 1098
1083 /* Initialize the considered map. */ 1099 /* Initialize the considered map. */
1084 sbitmap_zero (considered); 1100 auto_sbitmap considered (last_basic_block_for_fn (cfun));
1101 bitmap_clear (considered);
1085 EXECUTE_IF_SET_IN_BITMAP (blocks_to_consider, 0, index, bi) 1102 EXECUTE_IF_SET_IN_BITMAP (blocks_to_consider, 0, index, bi)
1086 { 1103 {
1087 SET_BIT (considered, index); 1104 bitmap_set_bit (considered, index);
1088 } 1105 }
1089 1106
1090 /* Initialize the mapping of block index to postorder. */ 1107 /* Initialize the mapping of block index to postorder. */
1091 for (i = 0; i < n_blocks; i++) 1108 for (i = 0; i < n_blocks; i++)
1092 { 1109 {
1102 /* Solve it. */ 1119 /* Solve it. */
1103 df_worklist_dataflow_doublequeue (dataflow, pending, considered, 1120 df_worklist_dataflow_doublequeue (dataflow, pending, considered,
1104 blocks_in_postorder, 1121 blocks_in_postorder,
1105 bbindex_to_postorder, 1122 bbindex_to_postorder,
1106 n_blocks); 1123 n_blocks);
1107 sbitmap_free (considered);
1108 free (bbindex_to_postorder); 1124 free (bbindex_to_postorder);
1109 } 1125 }
1110 1126
1111 1127
1112 /* Remove the entries not in BLOCKS from the LIST of length LEN, preserving 1128 /* Remove the entries not in BLOCKS from the LIST of length LEN, preserving
1171 1187
1172 dflow->computed = true; 1188 dflow->computed = true;
1173 } 1189 }
1174 1190
1175 1191
1176 /* Analyze dataflow info for the basic blocks specified by the bitmap 1192 /* Analyze dataflow info. */
1177 BLOCKS, or for the whole CFG if BLOCKS is zero. */ 1193
1178 1194 static void
1179 void 1195 df_analyze_1 (void)
1180 df_analyze (void) 1196 {
1181 {
1182 bitmap current_all_blocks = BITMAP_ALLOC (&df_bitmap_obstack);
1183 bool everything;
1184 int i; 1197 int i;
1185 1198
1186 if (df->postorder)
1187 free (df->postorder);
1188 if (df->postorder_inverted)
1189 free (df->postorder_inverted);
1190 df->postorder = XNEWVEC (int, last_basic_block);
1191 df->postorder_inverted = XNEWVEC (int, last_basic_block);
1192 df->n_blocks = post_order_compute (df->postorder, true, true);
1193 df->n_blocks_inverted = inverted_post_order_compute (df->postorder_inverted);
1194
1195 /* These should be the same. */ 1199 /* These should be the same. */
1196 gcc_assert (df->n_blocks == df->n_blocks_inverted); 1200 gcc_assert ((unsigned) df->n_blocks == df->postorder_inverted.length ());
1197 1201
1198 /* We need to do this before the df_verify_all because this is 1202 /* We need to do this before the df_verify_all because this is
1199 not kept incrementally up to date. */ 1203 not kept incrementally up to date. */
1200 df_compute_regs_ever_live (false); 1204 df_compute_regs_ever_live (false);
1201 df_process_deferred_rescans (); 1205 df_process_deferred_rescans ();
1205 1209
1206 #ifndef ENABLE_DF_CHECKING 1210 #ifndef ENABLE_DF_CHECKING
1207 if (df->changeable_flags & DF_VERIFY_SCHEDULED) 1211 if (df->changeable_flags & DF_VERIFY_SCHEDULED)
1208 #endif 1212 #endif
1209 df_verify (); 1213 df_verify ();
1210
1211 for (i = 0; i < df->n_blocks; i++)
1212 bitmap_set_bit (current_all_blocks, df->postorder[i]);
1213
1214 #ifdef ENABLE_CHECKING
1215 /* Verify that POSTORDER_INVERTED only contains blocks reachable from
1216 the ENTRY block. */
1217 for (i = 0; i < df->n_blocks_inverted; i++)
1218 gcc_assert (bitmap_bit_p (current_all_blocks, df->postorder_inverted[i]));
1219 #endif
1220
1221 /* Make sure that we have pruned any unreachable blocks from these
1222 sets. */
1223 if (df->analyze_subset)
1224 {
1225 everything = false;
1226 bitmap_and_into (df->blocks_to_analyze, current_all_blocks);
1227 df->n_blocks = df_prune_to_subcfg (df->postorder,
1228 df->n_blocks, df->blocks_to_analyze);
1229 df->n_blocks_inverted = df_prune_to_subcfg (df->postorder_inverted,
1230 df->n_blocks_inverted,
1231 df->blocks_to_analyze);
1232 BITMAP_FREE (current_all_blocks);
1233 }
1234 else
1235 {
1236 everything = true;
1237 df->blocks_to_analyze = current_all_blocks;
1238 current_all_blocks = NULL;
1239 }
1240 1214
1241 /* Skip over the DF_SCAN problem. */ 1215 /* Skip over the DF_SCAN problem. */
1242 for (i = 1; i < df->num_problems_defined; i++) 1216 for (i = 1; i < df->num_problems_defined; i++)
1243 { 1217 {
1244 struct dataflow *dflow = df->problems_in_order[i]; 1218 struct dataflow *dflow = df->problems_in_order[i];
1245 if (dflow->solutions_dirty) 1219 if (dflow->solutions_dirty)
1246 { 1220 {
1247 if (dflow->problem->dir == DF_FORWARD) 1221 if (dflow->problem->dir == DF_FORWARD)
1248 df_analyze_problem (dflow, 1222 df_analyze_problem (dflow,
1249 df->blocks_to_analyze, 1223 df->blocks_to_analyze,
1250 df->postorder_inverted, 1224 df->postorder_inverted.address (),
1251 df->n_blocks_inverted); 1225 df->postorder_inverted.length ());
1252 else 1226 else
1253 df_analyze_problem (dflow, 1227 df_analyze_problem (dflow,
1254 df->blocks_to_analyze, 1228 df->blocks_to_analyze,
1255 df->postorder, 1229 df->postorder,
1256 df->n_blocks); 1230 df->n_blocks);
1257 } 1231 }
1258 } 1232 }
1259 1233
1260 if (everything) 1234 if (!df->analyze_subset)
1261 { 1235 {
1262 BITMAP_FREE (df->blocks_to_analyze); 1236 BITMAP_FREE (df->blocks_to_analyze);
1263 df->blocks_to_analyze = NULL; 1237 df->blocks_to_analyze = NULL;
1264 } 1238 }
1265 1239
1266 #ifdef DF_DEBUG_CFG 1240 #ifdef DF_DEBUG_CFG
1267 df_set_clean_cfg (); 1241 df_set_clean_cfg ();
1268 #endif 1242 #endif
1269 } 1243 }
1270 1244
1245 /* Analyze dataflow info. */
1246
1247 void
1248 df_analyze (void)
1249 {
1250 bitmap current_all_blocks = BITMAP_ALLOC (&df_bitmap_obstack);
1251
1252 free (df->postorder);
1253 df->postorder = XNEWVEC (int, last_basic_block_for_fn (cfun));
1254 df->n_blocks = post_order_compute (df->postorder, true, true);
1255 df->postorder_inverted.truncate (0);
1256 inverted_post_order_compute (&df->postorder_inverted);
1257
1258 for (int i = 0; i < df->n_blocks; i++)
1259 bitmap_set_bit (current_all_blocks, df->postorder[i]);
1260
1261 if (flag_checking)
1262 {
1263 /* Verify that POSTORDER_INVERTED only contains blocks reachable from
1264 the ENTRY block. */
1265 for (unsigned int i = 0; i < df->postorder_inverted.length (); i++)
1266 gcc_assert (bitmap_bit_p (current_all_blocks,
1267 df->postorder_inverted[i]));
1268 }
1269
1270 /* Make sure that we have pruned any unreachable blocks from these
1271 sets. */
1272 if (df->analyze_subset)
1273 {
1274 bitmap_and_into (df->blocks_to_analyze, current_all_blocks);
1275 df->n_blocks = df_prune_to_subcfg (df->postorder,
1276 df->n_blocks, df->blocks_to_analyze);
1277 unsigned int newlen = df_prune_to_subcfg (df->postorder_inverted.address (),
1278 df->postorder_inverted.length (),
1279 df->blocks_to_analyze);
1280 df->postorder_inverted.truncate (newlen);
1281 BITMAP_FREE (current_all_blocks);
1282 }
1283 else
1284 {
1285 df->blocks_to_analyze = current_all_blocks;
1286 current_all_blocks = NULL;
1287 }
1288
1289 df_analyze_1 ();
1290 }
1291
1292 /* Compute the reverse top sort order of the sub-CFG specified by LOOP.
1293 Returns the number of blocks which is always loop->num_nodes. */
1294
1295 static int
1296 loop_post_order_compute (int *post_order, struct loop *loop)
1297 {
1298 edge_iterator *stack;
1299 int sp;
1300 int post_order_num = 0;
1301
1302 /* Allocate stack for back-tracking up CFG. */
1303 stack = XNEWVEC (edge_iterator, loop->num_nodes + 1);
1304 sp = 0;
1305
1306 /* Allocate bitmap to track nodes that have been visited. */
1307 auto_bitmap visited;
1308
1309 /* Push the first edge on to the stack. */
1310 stack[sp++] = ei_start (loop_preheader_edge (loop)->src->succs);
1311
1312 while (sp)
1313 {
1314 edge_iterator ei;
1315 basic_block src;
1316 basic_block dest;
1317
1318 /* Look at the edge on the top of the stack. */
1319 ei = stack[sp - 1];
1320 src = ei_edge (ei)->src;
1321 dest = ei_edge (ei)->dest;
1322
1323 /* Check if the edge destination has been visited yet and mark it
1324 if not so. */
1325 if (flow_bb_inside_loop_p (loop, dest)
1326 && bitmap_set_bit (visited, dest->index))
1327 {
1328 if (EDGE_COUNT (dest->succs) > 0)
1329 /* Since the DEST node has been visited for the first
1330 time, check its successors. */
1331 stack[sp++] = ei_start (dest->succs);
1332 else
1333 post_order[post_order_num++] = dest->index;
1334 }
1335 else
1336 {
1337 if (ei_one_before_end_p (ei)
1338 && src != loop_preheader_edge (loop)->src)
1339 post_order[post_order_num++] = src->index;
1340
1341 if (!ei_one_before_end_p (ei))
1342 ei_next (&stack[sp - 1]);
1343 else
1344 sp--;
1345 }
1346 }
1347
1348 free (stack);
1349
1350 return post_order_num;
1351 }
1352
1353 /* Compute the reverse top sort order of the inverted sub-CFG specified
1354 by LOOP. Returns the number of blocks which is always loop->num_nodes. */
1355
1356 static void
1357 loop_inverted_post_order_compute (vec<int> *post_order, struct loop *loop)
1358 {
1359 basic_block bb;
1360 edge_iterator *stack;
1361 int sp;
1362
1363 post_order->reserve_exact (loop->num_nodes);
1364
1365 /* Allocate stack for back-tracking up CFG. */
1366 stack = XNEWVEC (edge_iterator, loop->num_nodes + 1);
1367 sp = 0;
1368
1369 /* Allocate bitmap to track nodes that have been visited. */
1370 auto_bitmap visited;
1371
1372 /* Put all latches into the initial work list. In theory we'd want
1373 to start from loop exits but then we'd have the special case of
1374 endless loops. It doesn't really matter for DF iteration order and
1375 handling latches last is probably even better. */
1376 stack[sp++] = ei_start (loop->header->preds);
1377 bitmap_set_bit (visited, loop->header->index);
1378
1379 /* The inverted traversal loop. */
1380 while (sp)
1381 {
1382 edge_iterator ei;
1383 basic_block pred;
1384
1385 /* Look at the edge on the top of the stack. */
1386 ei = stack[sp - 1];
1387 bb = ei_edge (ei)->dest;
1388 pred = ei_edge (ei)->src;
1389
1390 /* Check if the predecessor has been visited yet and mark it
1391 if not so. */
1392 if (flow_bb_inside_loop_p (loop, pred)
1393 && bitmap_set_bit (visited, pred->index))
1394 {
1395 if (EDGE_COUNT (pred->preds) > 0)
1396 /* Since the predecessor node has been visited for the first
1397 time, check its predecessors. */
1398 stack[sp++] = ei_start (pred->preds);
1399 else
1400 post_order->quick_push (pred->index);
1401 }
1402 else
1403 {
1404 if (flow_bb_inside_loop_p (loop, bb)
1405 && ei_one_before_end_p (ei))
1406 post_order->quick_push (bb->index);
1407
1408 if (!ei_one_before_end_p (ei))
1409 ei_next (&stack[sp - 1]);
1410 else
1411 sp--;
1412 }
1413 }
1414
1415 free (stack);
1416 }
1417
1418
1419 /* Analyze dataflow info for the basic blocks contained in LOOP. */
1420
1421 void
1422 df_analyze_loop (struct loop *loop)
1423 {
1424 free (df->postorder);
1425
1426 df->postorder = XNEWVEC (int, loop->num_nodes);
1427 df->postorder_inverted.truncate (0);
1428 df->n_blocks = loop_post_order_compute (df->postorder, loop);
1429 loop_inverted_post_order_compute (&df->postorder_inverted, loop);
1430 gcc_assert ((unsigned) df->n_blocks == loop->num_nodes);
1431 gcc_assert (df->postorder_inverted.length () == loop->num_nodes);
1432
1433 bitmap blocks = BITMAP_ALLOC (&df_bitmap_obstack);
1434 for (int i = 0; i < df->n_blocks; ++i)
1435 bitmap_set_bit (blocks, df->postorder[i]);
1436 df_set_blocks (blocks);
1437 BITMAP_FREE (blocks);
1438
1439 df_analyze_1 ();
1440 }
1441
1271 1442
1272 /* Return the number of basic blocks from the last call to df_analyze. */ 1443 /* Return the number of basic blocks from the last call to df_analyze. */
1273 1444
1274 int 1445 int
1275 df_get_n_blocks (enum df_flow_dir dir) 1446 df_get_n_blocks (enum df_flow_dir dir)
1276 { 1447 {
1277 gcc_assert (dir != DF_NONE); 1448 gcc_assert (dir != DF_NONE);
1278 1449
1279 if (dir == DF_FORWARD) 1450 if (dir == DF_FORWARD)
1280 { 1451 {
1281 gcc_assert (df->postorder_inverted); 1452 gcc_assert (df->postorder_inverted.length ());
1282 return df->n_blocks_inverted; 1453 return df->postorder_inverted.length ();
1283 } 1454 }
1284 1455
1285 gcc_assert (df->postorder); 1456 gcc_assert (df->postorder);
1286 return df->n_blocks; 1457 return df->n_blocks;
1287 } 1458 }
1296 { 1467 {
1297 gcc_assert (dir != DF_NONE); 1468 gcc_assert (dir != DF_NONE);
1298 1469
1299 if (dir == DF_FORWARD) 1470 if (dir == DF_FORWARD)
1300 { 1471 {
1301 gcc_assert (df->postorder_inverted); 1472 gcc_assert (df->postorder_inverted.length ());
1302 return df->postorder_inverted; 1473 return df->postorder_inverted.address ();
1303 } 1474 }
1304 gcc_assert (df->postorder); 1475 gcc_assert (df->postorder);
1305 return df->postorder; 1476 return df->postorder;
1306 } 1477 }
1307 1478
1398 /* Return true if BB needs it's transfer functions recomputed. */ 1569 /* Return true if BB needs it's transfer functions recomputed. */
1399 1570
1400 bool 1571 bool
1401 df_get_bb_dirty (basic_block bb) 1572 df_get_bb_dirty (basic_block bb)
1402 { 1573 {
1403 if (df && df_live) 1574 return bitmap_bit_p ((df_live
1404 return bitmap_bit_p (df_live->out_of_date_transfer_functions, bb->index); 1575 ? df_live : df_lr)->out_of_date_transfer_functions,
1405 else 1576 bb->index);
1406 return false;
1407 } 1577 }
1408 1578
1409 1579
1410 /* Mark BB as needing it's transfer functions as being out of 1580 /* Mark BB as needing it's transfer functions as being out of
1411 date. */ 1581 date. */
1431 /* Grow the bb_info array. */ 1601 /* Grow the bb_info array. */
1432 1602
1433 void 1603 void
1434 df_grow_bb_info (struct dataflow *dflow) 1604 df_grow_bb_info (struct dataflow *dflow)
1435 { 1605 {
1436 unsigned int new_size = last_basic_block + 1; 1606 unsigned int new_size = last_basic_block_for_fn (cfun) + 1;
1437 if (dflow->block_info_size < new_size) 1607 if (dflow->block_info_size < new_size)
1438 { 1608 {
1439 new_size += new_size / 4; 1609 new_size += new_size / 4;
1440 dflow->block_info 1610 dflow->block_info
1441 = (void *)XRESIZEVEC (char, (char *)dflow->block_info, 1611 = (void *)XRESIZEVEC (char, (char *)dflow->block_info,
1473 df_compact_blocks (void) 1643 df_compact_blocks (void)
1474 { 1644 {
1475 int i, p; 1645 int i, p;
1476 basic_block bb; 1646 basic_block bb;
1477 void *problem_temps; 1647 void *problem_temps;
1478 bitmap_head tmp; 1648
1479 1649 auto_bitmap tmp (&df_bitmap_obstack);
1480 bitmap_initialize (&tmp, &df_bitmap_obstack);
1481 for (p = 0; p < df->num_problems_defined; p++) 1650 for (p = 0; p < df->num_problems_defined; p++)
1482 { 1651 {
1483 struct dataflow *dflow = df->problems_in_order[p]; 1652 struct dataflow *dflow = df->problems_in_order[p];
1484 1653
1485 /* Need to reorganize the out_of_date_transfer_functions for the 1654 /* Need to reorganize the out_of_date_transfer_functions for the
1486 dflow problem. */ 1655 dflow problem. */
1487 if (dflow->out_of_date_transfer_functions) 1656 if (dflow->out_of_date_transfer_functions)
1488 { 1657 {
1489 bitmap_copy (&tmp, dflow->out_of_date_transfer_functions); 1658 bitmap_copy (tmp, dflow->out_of_date_transfer_functions);
1490 bitmap_clear (dflow->out_of_date_transfer_functions); 1659 bitmap_clear (dflow->out_of_date_transfer_functions);
1491 if (bitmap_bit_p (&tmp, ENTRY_BLOCK)) 1660 if (bitmap_bit_p (tmp, ENTRY_BLOCK))
1492 bitmap_set_bit (dflow->out_of_date_transfer_functions, ENTRY_BLOCK); 1661 bitmap_set_bit (dflow->out_of_date_transfer_functions, ENTRY_BLOCK);
1493 if (bitmap_bit_p (&tmp, EXIT_BLOCK)) 1662 if (bitmap_bit_p (tmp, EXIT_BLOCK))
1494 bitmap_set_bit (dflow->out_of_date_transfer_functions, EXIT_BLOCK); 1663 bitmap_set_bit (dflow->out_of_date_transfer_functions, EXIT_BLOCK);
1495 1664
1496 i = NUM_FIXED_BLOCKS; 1665 i = NUM_FIXED_BLOCKS;
1497 FOR_EACH_BB (bb) 1666 FOR_EACH_BB_FN (bb, cfun)
1498 { 1667 {
1499 if (bitmap_bit_p (&tmp, bb->index)) 1668 if (bitmap_bit_p (tmp, bb->index))
1500 bitmap_set_bit (dflow->out_of_date_transfer_functions, i); 1669 bitmap_set_bit (dflow->out_of_date_transfer_functions, i);
1501 i++; 1670 i++;
1502 } 1671 }
1503 } 1672 }
1504 1673
1505 /* Now shuffle the block info for the problem. */ 1674 /* Now shuffle the block info for the problem. */
1506 if (dflow->problem->free_bb_fun) 1675 if (dflow->problem->free_bb_fun)
1507 { 1676 {
1508 int size = last_basic_block * dflow->problem->block_info_elt_size; 1677 int size = (last_basic_block_for_fn (cfun)
1678 * dflow->problem->block_info_elt_size);
1509 problem_temps = XNEWVAR (char, size); 1679 problem_temps = XNEWVAR (char, size);
1510 df_grow_bb_info (dflow); 1680 df_grow_bb_info (dflow);
1511 memcpy (problem_temps, dflow->block_info, size); 1681 memcpy (problem_temps, dflow->block_info, size);
1512 1682
1513 /* Copy the bb info from the problem tmps to the proper 1683 /* Copy the bb info from the problem tmps to the proper
1514 place in the block_info vector. Null out the copied 1684 place in the block_info vector. Null out the copied
1515 item. The entry and exit blocks never move. */ 1685 item. The entry and exit blocks never move. */
1516 i = NUM_FIXED_BLOCKS; 1686 i = NUM_FIXED_BLOCKS;
1517 FOR_EACH_BB (bb) 1687 FOR_EACH_BB_FN (bb, cfun)
1518 { 1688 {
1519 df_set_bb_info (dflow, i, 1689 df_set_bb_info (dflow, i,
1520 (char *)problem_temps 1690 (char *)problem_temps
1521 + bb->index * dflow->problem->block_info_elt_size); 1691 + bb->index * dflow->problem->block_info_elt_size);
1522 i++; 1692 i++;
1523 } 1693 }
1524 memset ((char *)dflow->block_info 1694 memset ((char *)dflow->block_info
1525 + i * dflow->problem->block_info_elt_size, 0, 1695 + i * dflow->problem->block_info_elt_size, 0,
1526 (last_basic_block - i) 1696 (last_basic_block_for_fn (cfun) - i)
1527 * dflow->problem->block_info_elt_size); 1697 * dflow->problem->block_info_elt_size);
1528 free (problem_temps); 1698 free (problem_temps);
1529 } 1699 }
1530 } 1700 }
1531 1701
1532 /* Shuffle the bits in the basic_block indexed arrays. */ 1702 /* Shuffle the bits in the basic_block indexed arrays. */
1533 1703
1534 if (df->blocks_to_analyze) 1704 if (df->blocks_to_analyze)
1535 { 1705 {
1536 if (bitmap_bit_p (&tmp, ENTRY_BLOCK)) 1706 if (bitmap_bit_p (tmp, ENTRY_BLOCK))
1537 bitmap_set_bit (df->blocks_to_analyze, ENTRY_BLOCK); 1707 bitmap_set_bit (df->blocks_to_analyze, ENTRY_BLOCK);
1538 if (bitmap_bit_p (&tmp, EXIT_BLOCK)) 1708 if (bitmap_bit_p (tmp, EXIT_BLOCK))
1539 bitmap_set_bit (df->blocks_to_analyze, EXIT_BLOCK); 1709 bitmap_set_bit (df->blocks_to_analyze, EXIT_BLOCK);
1540 bitmap_copy (&tmp, df->blocks_to_analyze); 1710 bitmap_copy (tmp, df->blocks_to_analyze);
1541 bitmap_clear (df->blocks_to_analyze); 1711 bitmap_clear (df->blocks_to_analyze);
1542 i = NUM_FIXED_BLOCKS; 1712 i = NUM_FIXED_BLOCKS;
1543 FOR_EACH_BB (bb) 1713 FOR_EACH_BB_FN (bb, cfun)
1544 { 1714 {
1545 if (bitmap_bit_p (&tmp, bb->index)) 1715 if (bitmap_bit_p (tmp, bb->index))
1546 bitmap_set_bit (df->blocks_to_analyze, i); 1716 bitmap_set_bit (df->blocks_to_analyze, i);
1547 i++; 1717 i++;
1548 } 1718 }
1549 } 1719 }
1550 1720
1551 bitmap_clear (&tmp);
1552
1553 i = NUM_FIXED_BLOCKS; 1721 i = NUM_FIXED_BLOCKS;
1554 FOR_EACH_BB (bb) 1722 FOR_EACH_BB_FN (bb, cfun)
1555 { 1723 {
1556 SET_BASIC_BLOCK (i, bb); 1724 SET_BASIC_BLOCK_FOR_FN (cfun, i, bb);
1557 bb->index = i; 1725 bb->index = i;
1558 i++; 1726 i++;
1559 } 1727 }
1560 1728
1561 gcc_assert (i == n_basic_blocks); 1729 gcc_assert (i == n_basic_blocks_for_fn (cfun));
1562 1730
1563 for (; i < last_basic_block; i++) 1731 for (; i < last_basic_block_for_fn (cfun); i++)
1564 SET_BASIC_BLOCK (i, NULL); 1732 SET_BASIC_BLOCK_FOR_FN (cfun, i, NULL);
1565 1733
1566 #ifdef DF_DEBUG_CFG 1734 #ifdef DF_DEBUG_CFG
1567 if (!df_lr->solutions_dirty) 1735 if (!df_lr->solutions_dirty)
1568 df_set_clean_cfg (); 1736 df_set_clean_cfg ();
1569 #endif 1737 #endif
1581 1749
1582 if (dump_file) 1750 if (dump_file)
1583 fprintf (dump_file, "shoving block %d into %d\n", new_block_index, old_index); 1751 fprintf (dump_file, "shoving block %d into %d\n", new_block_index, old_index);
1584 1752
1585 gcc_assert (df); 1753 gcc_assert (df);
1586 gcc_assert (BASIC_BLOCK (old_index) == NULL); 1754 gcc_assert (BASIC_BLOCK_FOR_FN (cfun, old_index) == NULL);
1587 1755
1588 for (p = 0; p < df->num_problems_defined; p++) 1756 for (p = 0; p < df->num_problems_defined; p++)
1589 { 1757 {
1590 struct dataflow *dflow = df->problems_in_order[p]; 1758 struct dataflow *dflow = df->problems_in_order[p];
1591 if (dflow->block_info) 1759 if (dflow->block_info)
1595 df_get_bb_info (dflow, new_block_index)); 1763 df_get_bb_info (dflow, new_block_index));
1596 } 1764 }
1597 } 1765 }
1598 1766
1599 df_clear_bb_dirty (new_block); 1767 df_clear_bb_dirty (new_block);
1600 SET_BASIC_BLOCK (old_index, new_block); 1768 SET_BASIC_BLOCK_FOR_FN (cfun, old_index, new_block);
1601 new_block->index = old_index; 1769 new_block->index = old_index;
1602 df_set_bb_dirty (BASIC_BLOCK (old_index)); 1770 df_set_bb_dirty (BASIC_BLOCK_FOR_FN (cfun, old_index));
1603 SET_BASIC_BLOCK (new_block_index, NULL); 1771 SET_BASIC_BLOCK_FOR_FN (cfun, new_block_index, NULL);
1604 } 1772 }
1605 1773
1606 1774
1607 /* Free all of the per basic block dataflow from all of the problems. 1775 /* Free all of the per basic block dataflow from all of the problems.
1608 This is typically called before a basic block is deleted and the 1776 This is typically called before a basic block is deleted and the
1609 problem will be reanalyzed. */ 1777 problem will be reanalyzed. */
1610 1778
1611 void 1779 void
1612 df_bb_delete (int bb_index) 1780 df_bb_delete (int bb_index)
1613 { 1781 {
1614 basic_block bb = BASIC_BLOCK (bb_index); 1782 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1615 int i; 1783 int i;
1616 1784
1617 if (!df) 1785 if (!df)
1618 return; 1786 return;
1619 1787
1650 #ifdef ENABLE_DF_CHECKING 1818 #ifdef ENABLE_DF_CHECKING
1651 df_lr_verify_transfer_functions (); 1819 df_lr_verify_transfer_functions ();
1652 if (df_live) 1820 if (df_live)
1653 df_live_verify_transfer_functions (); 1821 df_live_verify_transfer_functions ();
1654 #endif 1822 #endif
1823 df->changeable_flags &= ~DF_VERIFY_SCHEDULED;
1655 } 1824 }
1656 1825
1657 #ifdef DF_DEBUG_CFG 1826 #ifdef DF_DEBUG_CFG
1658 1827
1659 /* Compute an array of ints that describes the cfg. This can be used 1828 /* Compute an array of ints that describes the cfg. This can be used
1664 1833
1665 static int * 1834 static int *
1666 df_compute_cfg_image (void) 1835 df_compute_cfg_image (void)
1667 { 1836 {
1668 basic_block bb; 1837 basic_block bb;
1669 int size = 2 + (2 * n_basic_blocks); 1838 int size = 2 + (2 * n_basic_blocks_for_fn (cfun));
1670 int i; 1839 int i;
1671 int * map; 1840 int * map;
1672 1841
1673 FOR_ALL_BB (bb) 1842 FOR_ALL_BB_FN (bb, cfun)
1674 { 1843 {
1675 size += EDGE_COUNT (bb->succs); 1844 size += EDGE_COUNT (bb->succs);
1676 } 1845 }
1677 1846
1678 map = XNEWVEC (int, size); 1847 map = XNEWVEC (int, size);
1679 map[0] = size; 1848 map[0] = size;
1680 i = 1; 1849 i = 1;
1681 FOR_ALL_BB (bb) 1850 FOR_ALL_BB_FN (bb, cfun)
1682 { 1851 {
1683 edge_iterator ei; 1852 edge_iterator ei;
1684 edge e; 1853 edge e;
1685 1854
1686 map[i++] = bb->index; 1855 map[i++] = bb->index;
1724 saved_cfg. */ 1893 saved_cfg. */
1725 1894
1726 static void 1895 static void
1727 df_set_clean_cfg (void) 1896 df_set_clean_cfg (void)
1728 { 1897 {
1729 if (saved_cfg) 1898 free (saved_cfg);
1730 free (saved_cfg);
1731 saved_cfg = df_compute_cfg_image (); 1899 saved_cfg = df_compute_cfg_image ();
1732 } 1900 }
1733 1901
1734 #endif /* DF_DEBUG_CFG */ 1902 #endif /* DF_DEBUG_CFG */
1735 /*---------------------------------------------------------------------------- 1903 /*----------------------------------------------------------------------------
1740 /* Return first def of REGNO within BB. */ 1908 /* Return first def of REGNO within BB. */
1741 1909
1742 df_ref 1910 df_ref
1743 df_bb_regno_first_def_find (basic_block bb, unsigned int regno) 1911 df_bb_regno_first_def_find (basic_block bb, unsigned int regno)
1744 { 1912 {
1745 rtx insn; 1913 rtx_insn *insn;
1746 df_ref *def_rec; 1914 df_ref def;
1747 unsigned int uid;
1748 1915
1749 FOR_BB_INSNS (bb, insn) 1916 FOR_BB_INSNS (bb, insn)
1750 { 1917 {
1751 if (!INSN_P (insn)) 1918 if (!INSN_P (insn))
1752 continue; 1919 continue;
1753 1920
1754 uid = INSN_UID (insn); 1921 FOR_EACH_INSN_DEF (def, insn)
1755 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++) 1922 if (DF_REF_REGNO (def) == regno)
1756 { 1923 return def;
1757 df_ref def = *def_rec;
1758 if (DF_REF_REGNO (def) == regno)
1759 return def;
1760 }
1761 } 1924 }
1762 return NULL; 1925 return NULL;
1763 } 1926 }
1764 1927
1765 1928
1766 /* Return last def of REGNO within BB. */ 1929 /* Return last def of REGNO within BB. */
1767 1930
1768 df_ref 1931 df_ref
1769 df_bb_regno_last_def_find (basic_block bb, unsigned int regno) 1932 df_bb_regno_last_def_find (basic_block bb, unsigned int regno)
1770 { 1933 {
1771 rtx insn; 1934 rtx_insn *insn;
1772 df_ref *def_rec; 1935 df_ref def;
1773 unsigned int uid;
1774 1936
1775 FOR_BB_INSNS_REVERSE (bb, insn) 1937 FOR_BB_INSNS_REVERSE (bb, insn)
1776 { 1938 {
1777 if (!INSN_P (insn)) 1939 if (!INSN_P (insn))
1778 continue; 1940 continue;
1779 1941
1780 uid = INSN_UID (insn); 1942 FOR_EACH_INSN_DEF (def, insn)
1781 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++) 1943 if (DF_REF_REGNO (def) == regno)
1782 { 1944 return def;
1783 df_ref def = *def_rec;
1784 if (DF_REF_REGNO (def) == regno)
1785 return def;
1786 }
1787 } 1945 }
1788 1946
1789 return NULL; 1947 return NULL;
1790 } 1948 }
1791 1949
1792 /* Finds the reference corresponding to the definition of REG in INSN. 1950 /* Finds the reference corresponding to the definition of REG in INSN.
1793 DF is the dataflow object. */ 1951 DF is the dataflow object. */
1794 1952
1795 df_ref 1953 df_ref
1796 df_find_def (rtx insn, rtx reg) 1954 df_find_def (rtx_insn *insn, rtx reg)
1797 { 1955 {
1798 unsigned int uid; 1956 df_ref def;
1799 df_ref *def_rec;
1800 1957
1801 if (GET_CODE (reg) == SUBREG) 1958 if (GET_CODE (reg) == SUBREG)
1802 reg = SUBREG_REG (reg); 1959 reg = SUBREG_REG (reg);
1803 gcc_assert (REG_P (reg)); 1960 gcc_assert (REG_P (reg));
1804 1961
1805 uid = INSN_UID (insn); 1962 FOR_EACH_INSN_DEF (def, insn)
1806 for (def_rec = DF_INSN_UID_DEFS (uid); *def_rec; def_rec++) 1963 if (DF_REF_REGNO (def) == REGNO (reg))
1807 { 1964 return def;
1808 df_ref def = *def_rec;
1809 if (rtx_equal_p (DF_REF_REAL_REG (def), reg))
1810 return def;
1811 }
1812 1965
1813 return NULL; 1966 return NULL;
1814 } 1967 }
1815 1968
1816 1969
1817 /* Return true if REG is defined in INSN, zero otherwise. */ 1970 /* Return true if REG is defined in INSN, zero otherwise. */
1818 1971
1819 bool 1972 bool
1820 df_reg_defined (rtx insn, rtx reg) 1973 df_reg_defined (rtx_insn *insn, rtx reg)
1821 { 1974 {
1822 return df_find_def (insn, reg) != NULL; 1975 return df_find_def (insn, reg) != NULL;
1823 } 1976 }
1824 1977
1825 1978
1826 /* Finds the reference corresponding to the use of REG in INSN. 1979 /* Finds the reference corresponding to the use of REG in INSN.
1827 DF is the dataflow object. */ 1980 DF is the dataflow object. */
1828 1981
1829 df_ref 1982 df_ref
1830 df_find_use (rtx insn, rtx reg) 1983 df_find_use (rtx_insn *insn, rtx reg)
1831 { 1984 {
1832 unsigned int uid; 1985 df_ref use;
1833 df_ref *use_rec;
1834 1986
1835 if (GET_CODE (reg) == SUBREG) 1987 if (GET_CODE (reg) == SUBREG)
1836 reg = SUBREG_REG (reg); 1988 reg = SUBREG_REG (reg);
1837 gcc_assert (REG_P (reg)); 1989 gcc_assert (REG_P (reg));
1838 1990
1839 uid = INSN_UID (insn); 1991 df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
1840 for (use_rec = DF_INSN_UID_USES (uid); *use_rec; use_rec++) 1992 FOR_EACH_INSN_INFO_USE (use, insn_info)
1841 { 1993 if (DF_REF_REGNO (use) == REGNO (reg))
1842 df_ref use = *use_rec; 1994 return use;
1843 if (rtx_equal_p (DF_REF_REAL_REG (use), reg)) 1995 if (df->changeable_flags & DF_EQ_NOTES)
1996 FOR_EACH_INSN_INFO_EQ_USE (use, insn_info)
1997 if (DF_REF_REGNO (use) == REGNO (reg))
1844 return use; 1998 return use;
1845 }
1846 if (df->changeable_flags & DF_EQ_NOTES)
1847 for (use_rec = DF_INSN_UID_EQ_USES (uid); *use_rec; use_rec++)
1848 {
1849 df_ref use = *use_rec;
1850 if (rtx_equal_p (DF_REF_REAL_REG (use), reg))
1851 return use;
1852 }
1853 return NULL; 1999 return NULL;
1854 } 2000 }
1855 2001
1856 2002
1857 /* Return true if REG is referenced in INSN, zero otherwise. */ 2003 /* Return true if REG is referenced in INSN, zero otherwise. */
1858 2004
1859 bool 2005 bool
1860 df_reg_used (rtx insn, rtx reg) 2006 df_reg_used (rtx_insn *insn, rtx reg)
1861 { 2007 {
1862 return df_find_use (insn, reg) != NULL; 2008 return df_find_use (insn, reg) != NULL;
1863 } 2009 }
1864 2010
1865 2011
1866 /*---------------------------------------------------------------------------- 2012 /*----------------------------------------------------------------------------
1867 Debugging and printing functions. 2013 Debugging and printing functions.
1868 ----------------------------------------------------------------------------*/ 2014 ----------------------------------------------------------------------------*/
1869 2015
2016 /* Write information about registers and basic blocks into FILE.
2017 This is part of making a debugging dump. */
2018
2019 void
2020 dump_regset (regset r, FILE *outf)
2021 {
2022 unsigned i;
2023 reg_set_iterator rsi;
2024
2025 if (r == NULL)
2026 {
2027 fputs (" (nil)", outf);
2028 return;
2029 }
2030
2031 EXECUTE_IF_SET_IN_REG_SET (r, 0, i, rsi)
2032 {
2033 fprintf (outf, " %d", i);
2034 if (i < FIRST_PSEUDO_REGISTER)
2035 fprintf (outf, " [%s]",
2036 reg_names[i]);
2037 }
2038 }
2039
2040 /* Print a human-readable representation of R on the standard error
2041 stream. This function is designed to be used from within the
2042 debugger. */
2043 extern void debug_regset (regset);
2044 DEBUG_FUNCTION void
2045 debug_regset (regset r)
2046 {
2047 dump_regset (r, stderr);
2048 putc ('\n', stderr);
2049 }
1870 2050
1871 /* Write information about registers and basic blocks into FILE. 2051 /* Write information about registers and basic blocks into FILE.
1872 This is part of making a debugging dump. */ 2052 This is part of making a debugging dump. */
1873 2053
1874 void 2054 void
1936 df_dump (FILE *file) 2116 df_dump (FILE *file)
1937 { 2117 {
1938 basic_block bb; 2118 basic_block bb;
1939 df_dump_start (file); 2119 df_dump_start (file);
1940 2120
1941 FOR_ALL_BB (bb) 2121 FOR_ALL_BB_FN (bb, cfun)
1942 { 2122 {
1943 df_print_bb_index (bb, file); 2123 df_print_bb_index (bb, file);
1944 df_dump_top (bb, file); 2124 df_dump_top (bb, file);
1945 df_dump_bottom (bb, file); 2125 df_dump_bottom (bb, file);
1946 } 2126 }
1962 fprintf (file, "\n\nstarting region dump\n"); 2142 fprintf (file, "\n\nstarting region dump\n");
1963 df_dump_start (file); 2143 df_dump_start (file);
1964 2144
1965 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi) 2145 EXECUTE_IF_SET_IN_BITMAP (df->blocks_to_analyze, 0, bb_index, bi)
1966 { 2146 {
1967 basic_block bb = BASIC_BLOCK (bb_index); 2147 basic_block bb = BASIC_BLOCK_FOR_FN (cfun, bb_index);
1968 2148 dump_bb (file, bb, 0, TDF_DETAILS);
1969 df_print_bb_index (bb, file);
1970 df_dump_top (bb, file);
1971 df_dump_bottom (bb, file);
1972 } 2149 }
1973 fprintf (file, "\n"); 2150 fprintf (file, "\n");
1974 } 2151 }
1975 else 2152 else
1976 df_dump (file); 2153 df_dump (file);
1998 struct dataflow *dflow = df->problems_in_order[i]; 2175 struct dataflow *dflow = df->problems_in_order[i];
1999 if (dflow->computed) 2176 if (dflow->computed)
2000 { 2177 {
2001 df_dump_problem_function fun = dflow->problem->dump_start_fun; 2178 df_dump_problem_function fun = dflow->problem->dump_start_fun;
2002 if (fun) 2179 if (fun)
2003 fun(file); 2180 fun (file);
2004 } 2181 }
2005 } 2182 }
2006 } 2183 }
2007 2184
2008 2185
2009 /* Dump the top of the block information for BB. */ 2186 /* Dump the top or bottom of the block information for BB. */
2010 2187 static void
2011 void 2188 df_dump_bb_problem_data (basic_block bb, FILE *file, bool top)
2012 df_dump_top (basic_block bb, FILE *file)
2013 { 2189 {
2014 int i; 2190 int i;
2015 2191
2016 if (!df || !file) 2192 if (!df || !file)
2017 return; 2193 return;
2019 for (i = 0; i < df->num_problems_defined; i++) 2195 for (i = 0; i < df->num_problems_defined; i++)
2020 { 2196 {
2021 struct dataflow *dflow = df->problems_in_order[i]; 2197 struct dataflow *dflow = df->problems_in_order[i];
2022 if (dflow->computed) 2198 if (dflow->computed)
2023 { 2199 {
2024 df_dump_bb_problem_function bbfun = dflow->problem->dump_top_fun; 2200 df_dump_bb_problem_function bbfun;
2201
2202 if (top)
2203 bbfun = dflow->problem->dump_top_fun;
2204 else
2205 bbfun = dflow->problem->dump_bottom_fun;
2206
2025 if (bbfun) 2207 if (bbfun)
2026 bbfun (bb, file); 2208 bbfun (bb, file);
2027 } 2209 }
2028 } 2210 }
2029 } 2211 }
2030 2212
2213 /* Dump the top of the block information for BB. */
2214
2215 void
2216 df_dump_top (basic_block bb, FILE *file)
2217 {
2218 df_dump_bb_problem_data (bb, file, /*top=*/true);
2219 }
2031 2220
2032 /* Dump the bottom of the block information for BB. */ 2221 /* Dump the bottom of the block information for BB. */
2033 2222
2034 void 2223 void
2035 df_dump_bottom (basic_block bb, FILE *file) 2224 df_dump_bottom (basic_block bb, FILE *file)
2225 {
2226 df_dump_bb_problem_data (bb, file, /*top=*/false);
2227 }
2228
2229
2230 /* Dump information about INSN just before or after dumping INSN itself. */
2231 static void
2232 df_dump_insn_problem_data (const rtx_insn *insn, FILE *file, bool top)
2036 { 2233 {
2037 int i; 2234 int i;
2038 2235
2039 if (!df || !file) 2236 if (!df || !file)
2040 return; 2237 return;
2042 for (i = 0; i < df->num_problems_defined; i++) 2239 for (i = 0; i < df->num_problems_defined; i++)
2043 { 2240 {
2044 struct dataflow *dflow = df->problems_in_order[i]; 2241 struct dataflow *dflow = df->problems_in_order[i];
2045 if (dflow->computed) 2242 if (dflow->computed)
2046 { 2243 {
2047 df_dump_bb_problem_function bbfun = dflow->problem->dump_bottom_fun; 2244 df_dump_insn_problem_function insnfun;
2048 if (bbfun) 2245
2049 bbfun (bb, file); 2246 if (top)
2247 insnfun = dflow->problem->dump_insn_top_fun;
2248 else
2249 insnfun = dflow->problem->dump_insn_bottom_fun;
2250
2251 if (insnfun)
2252 insnfun (insn, file);
2050 } 2253 }
2051 } 2254 }
2255 }
2256
2257 /* Dump information about INSN before dumping INSN itself. */
2258
2259 void
2260 df_dump_insn_top (const rtx_insn *insn, FILE *file)
2261 {
2262 df_dump_insn_problem_data (insn, file, /*top=*/true);
2263 }
2264
2265 /* Dump information about INSN after dumping INSN itself. */
2266
2267 void
2268 df_dump_insn_bottom (const rtx_insn *insn, FILE *file)
2269 {
2270 df_dump_insn_problem_data (insn, file, /*top=*/false);
2052 } 2271 }
2053 2272
2054 2273
2055 static void 2274 static void
2056 df_ref_dump (df_ref ref, FILE *file) 2275 df_ref_dump (df_ref ref, FILE *file)
2062 DF_REF_ID (ref), 2281 DF_REF_ID (ref),
2063 DF_REF_REGNO (ref)); 2282 DF_REF_REGNO (ref));
2064 } 2283 }
2065 2284
2066 void 2285 void
2067 df_refs_chain_dump (df_ref *ref_rec, bool follow_chain, FILE *file) 2286 df_refs_chain_dump (df_ref ref, bool follow_chain, FILE *file)
2068 { 2287 {
2069 fprintf (file, "{ "); 2288 fprintf (file, "{ ");
2070 while (*ref_rec) 2289 for (; ref; ref = DF_REF_NEXT_LOC (ref))
2071 { 2290 {
2072 df_ref ref = *ref_rec;
2073 df_ref_dump (ref, file); 2291 df_ref_dump (ref, file);
2074 if (follow_chain) 2292 if (follow_chain)
2075 df_chain_dump (DF_REF_CHAIN (ref), file); 2293 df_chain_dump (DF_REF_CHAIN (ref), file);
2076 ref_rec++;
2077 } 2294 }
2078 fprintf (file, "}"); 2295 fprintf (file, "}");
2079 } 2296 }
2080 2297
2081 2298
2093 fprintf (file, "}"); 2310 fprintf (file, "}");
2094 } 2311 }
2095 2312
2096 2313
2097 static void 2314 static void
2098 df_mws_dump (struct df_mw_hardreg **mws, FILE *file) 2315 df_mws_dump (struct df_mw_hardreg *mws, FILE *file)
2099 { 2316 {
2100 while (*mws) 2317 for (; mws; mws = DF_MWS_NEXT (mws))
2101 { 2318 fprintf (file, "mw %c r[%d..%d]\n",
2102 fprintf (file, "mw %c r[%d..%d]\n", 2319 DF_MWS_REG_DEF_P (mws) ? 'd' : 'u',
2103 (DF_MWS_REG_DEF_P (*mws)) ? 'd' : 'u', 2320 mws->start_regno, mws->end_regno);
2104 (*mws)->start_regno, (*mws)->end_regno);
2105 mws++;
2106 }
2107 } 2321 }
2108 2322
2109 2323
2110 static void 2324 static void
2111 df_insn_uid_debug (unsigned int uid, 2325 df_insn_uid_debug (unsigned int uid,
2140 fprintf (file, "\n"); 2354 fprintf (file, "\n");
2141 } 2355 }
2142 2356
2143 2357
2144 DEBUG_FUNCTION void 2358 DEBUG_FUNCTION void
2145 df_insn_debug (rtx insn, bool follow_chain, FILE *file) 2359 df_insn_debug (rtx_insn *insn, bool follow_chain, FILE *file)
2146 { 2360 {
2147 df_insn_uid_debug (INSN_UID (insn), follow_chain, file); 2361 df_insn_uid_debug (INSN_UID (insn), follow_chain, file);
2148 } 2362 }
2149 2363
2150 DEBUG_FUNCTION void 2364 DEBUG_FUNCTION void
2151 df_insn_debug_regno (rtx insn, FILE *file) 2365 df_insn_debug_regno (rtx_insn *insn, FILE *file)
2152 { 2366 {
2153 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn); 2367 struct df_insn_info *insn_info = DF_INSN_INFO_GET (insn);
2154 2368
2155 fprintf (file, "insn %d bb %d luid %d defs ", 2369 fprintf (file, "insn %d bb %d luid %d defs ",
2156 INSN_UID (insn), BLOCK_FOR_INSN (insn)->index, 2370 INSN_UID (insn), BLOCK_FOR_INSN (insn)->index,
2205 } 2419 }
2206 2420
2207 /* Functions for debugging from GDB. */ 2421 /* Functions for debugging from GDB. */
2208 2422
2209 DEBUG_FUNCTION void 2423 DEBUG_FUNCTION void
2210 debug_df_insn (rtx insn) 2424 debug_df_insn (rtx_insn *insn)
2211 { 2425 {
2212 df_insn_debug (insn, true, stderr); 2426 df_insn_debug (insn, true, stderr);
2213 debug_rtx (insn); 2427 debug_rtx (insn);
2214 } 2428 }
2215 2429