comparison gcc/dominance.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
709 return (basic_block) node->father->data; 709 return (basic_block) node->father->data;
710 } 710 }
711 711
712 /* Set the immediate dominator of the block possibly removing 712 /* Set the immediate dominator of the block possibly removing
713 existing edge. NULL can be used to remove any edge. */ 713 existing edge. NULL can be used to remove any edge. */
714 inline void 714 void
715 set_immediate_dominator (enum cdi_direction dir, basic_block bb, 715 set_immediate_dominator (enum cdi_direction dir, basic_block bb,
716 basic_block dominated_by) 716 basic_block dominated_by)
717 { 717 {
718 unsigned int dir_index = dom_convert_dir_to_idx (dir); 718 unsigned int dir_index = dom_convert_dir_to_idx (dir);
719 struct et_node *node = bb->dom[dir_index]; 719 struct et_node *node = bb->dom[dir_index];
720 720
721 gcc_assert (dom_computed[dir_index]); 721 gcc_assert (dom_computed[dir_index]);
722 722
723 if (node->father) 723 if (node->father)
724 { 724 {
725 if (node->father->data == dominated_by) 725 if (node->father->data == dominated_by)
737 /* Returns the list of basic blocks immediately dominated by BB, in the 737 /* Returns the list of basic blocks immediately dominated by BB, in the
738 direction DIR. */ 738 direction DIR. */
739 VEC (basic_block, heap) * 739 VEC (basic_block, heap) *
740 get_dominated_by (enum cdi_direction dir, basic_block bb) 740 get_dominated_by (enum cdi_direction dir, basic_block bb)
741 { 741 {
742 int n;
743 unsigned int dir_index = dom_convert_dir_to_idx (dir); 742 unsigned int dir_index = dom_convert_dir_to_idx (dir);
744 struct et_node *node = bb->dom[dir_index], *son = node->son, *ason; 743 struct et_node *node = bb->dom[dir_index], *son = node->son, *ason;
745 VEC (basic_block, heap) *bbs = NULL; 744 VEC (basic_block, heap) *bbs = NULL;
746 745
747 gcc_assert (dom_computed[dir_index]); 746 gcc_assert (dom_computed[dir_index]);
748 747
749 if (!son) 748 if (!son)
750 return NULL; 749 return NULL;
751 750
752 VEC_safe_push (basic_block, heap, bbs, (basic_block) son->data); 751 VEC_safe_push (basic_block, heap, bbs, (basic_block) son->data);
753 for (ason = son->right, n = 1; ason != son; ason = ason->right) 752 for (ason = son->right; ason != son; ason = ason->right)
754 VEC_safe_push (basic_block, heap, bbs, (basic_block) ason->data); 753 VEC_safe_push (basic_block, heap, bbs, (basic_block) ason->data);
755 754
756 return bbs; 755 return bbs;
757 } 756 }
758 757
759 /* Returns the list of basic blocks that are immediately dominated (in 758 /* Returns the list of basic blocks that are immediately dominated (in
760 direction DIR) by some block between N_REGION ones stored in REGION, 759 direction DIR) by some block between N_REGION ones stored in REGION,
761 except for blocks in the REGION itself. */ 760 except for blocks in the REGION itself. */
762 761
763 VEC (basic_block, heap) * 762 VEC (basic_block, heap) *
764 get_dominated_by_region (enum cdi_direction dir, basic_block *region, 763 get_dominated_by_region (enum cdi_direction dir, basic_block *region,
765 unsigned n_region) 764 unsigned n_region)
766 { 765 {
767 unsigned i; 766 unsigned i;
780 region[i]->flags &= ~BB_DUPLICATED; 779 region[i]->flags &= ~BB_DUPLICATED;
781 780
782 return doms; 781 return doms;
783 } 782 }
784 783
784 /* Returns the list of basic blocks including BB dominated by BB, in the
785 direction DIR. The vector will be sorted in preorder. */
786
787 VEC (basic_block, heap) *
788 get_all_dominated_blocks (enum cdi_direction dir, basic_block bb)
789 {
790 VEC(basic_block, heap) *bbs = NULL;
791 unsigned i;
792
793 i = 0;
794 VEC_safe_push (basic_block, heap, bbs, bb);
795
796 do
797 {
798 basic_block son;
799
800 bb = VEC_index (basic_block, bbs, i++);
801 for (son = first_dom_son (dir, bb);
802 son;
803 son = next_dom_son (dir, son))
804 VEC_safe_push (basic_block, heap, bbs, son);
805 }
806 while (i < VEC_length (basic_block, bbs));
807
808 return bbs;
809 }
810
785 /* Redirect all edges pointing to BB to TO. */ 811 /* Redirect all edges pointing to BB to TO. */
786 void 812 void
787 redirect_immediate_dominators (enum cdi_direction dir, basic_block bb, 813 redirect_immediate_dominators (enum cdi_direction dir, basic_block bb,
788 basic_block to) 814 basic_block to)
789 { 815 {
790 unsigned int dir_index = dom_convert_dir_to_idx (dir); 816 unsigned int dir_index = dom_convert_dir_to_idx (dir);
791 struct et_node *bb_node, *to_node, *son; 817 struct et_node *bb_node, *to_node, *son;
792 818
793 bb_node = bb->dom[dir_index]; 819 bb_node = bb->dom[dir_index];
794 to_node = to->dom[dir_index]; 820 to_node = to->dom[dir_index];
795 821
796 gcc_assert (dom_computed[dir_index]); 822 gcc_assert (dom_computed[dir_index]);
797 823
834 nearest_common_dominator_for_set (enum cdi_direction dir, bitmap blocks) 860 nearest_common_dominator_for_set (enum cdi_direction dir, bitmap blocks)
835 { 861 {
836 unsigned i, first; 862 unsigned i, first;
837 bitmap_iterator bi; 863 bitmap_iterator bi;
838 basic_block dom; 864 basic_block dom;
839 865
840 first = bitmap_first_set_bit (blocks); 866 first = bitmap_first_set_bit (blocks);
841 dom = BASIC_BLOCK (first); 867 dom = BASIC_BLOCK (first);
842 EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi) 868 EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
843 if (dom != BASIC_BLOCK (i)) 869 if (dom != BASIC_BLOCK (i))
844 dom = nearest_common_dominator (dir, dom, BASIC_BLOCK (i)); 870 dom = nearest_common_dominator (dir, dom, BASIC_BLOCK (i));
853 2. The number for when we visit a node on the way back up the tree 879 2. The number for when we visit a node on the way back up the tree
854 880
855 You can view these as bounds for the range of dfs numbers the 881 You can view these as bounds for the range of dfs numbers the
856 nodes in the subtree of the dominator tree rooted at that node 882 nodes in the subtree of the dominator tree rooted at that node
857 will contain. 883 will contain.
858 884
859 The dominator tree is always a simple acyclic tree, so there are 885 The dominator tree is always a simple acyclic tree, so there are
860 only three possible relations two nodes in the dominator tree have 886 only three possible relations two nodes in the dominator tree have
861 to each other: 887 to each other:
862 888
863 1. Node A is above Node B (and thus, Node A dominates node B) 889 1. Node A is above Node B (and thus, Node A dominates node B)
864 890
865 A 891 A
866 | 892 |
867 C 893 C
871 897
872 In the above case, DFS_Number_In of A will be <= DFS_Number_In of 898 In the above case, DFS_Number_In of A will be <= DFS_Number_In of
873 B, and DFS_Number_Out of A will be >= DFS_Number_Out of B. This is 899 B, and DFS_Number_Out of A will be >= DFS_Number_Out of B. This is
874 because we must hit A in the dominator tree *before* B on the walk 900 because we must hit A in the dominator tree *before* B on the walk
875 down, and we will hit A *after* B on the walk back up 901 down, and we will hit A *after* B on the walk back up
876 902
877 2. Node A is below node B (and thus, node B dominates node A) 903 2. Node A is below node B (and thus, node B dominates node A)
878 904
879 905
880 B 906 B
881 | 907 |
882 A 908 A
883 / \ 909 / \
884 C D 910 C D
885 911
886 In the above case, DFS_Number_In of A will be >= DFS_Number_In of 912 In the above case, DFS_Number_In of A will be >= DFS_Number_In of
887 B, and DFS_Number_Out of A will be <= DFS_Number_Out of B. 913 B, and DFS_Number_Out of A will be <= DFS_Number_Out of B.
888 914
889 This is because we must hit A in the dominator tree *after* B on 915 This is because we must hit A in the dominator tree *after* B on
890 the walk down, and we will hit A *before* B on the walk back up 916 the walk down, and we will hit A *before* B on the walk back up
891 917
892 3. Node A and B are siblings (and thus, neither dominates the other) 918 3. Node A and B are siblings (and thus, neither dominates the other)
893 919
894 C 920 C
895 | 921 |
896 D 922 D
909 935
910 Thus, it is sufficient to write 936 Thus, it is sufficient to write
911 937
912 A_Dominates_B (node A, node B) 938 A_Dominates_B (node A, node B)
913 { 939 {
914 return DFS_Number_In(A) <= DFS_Number_In(B) 940 return DFS_Number_In(A) <= DFS_Number_In(B)
915 && DFS_Number_Out (A) >= DFS_Number_Out(B); 941 && DFS_Number_Out (A) >= DFS_Number_Out(B);
916 } 942 }
917 943
918 A_Dominated_by_B (node A, node B) 944 A_Dominated_by_B (node A, node B)
919 { 945 {
922 } */ 948 } */
923 949
924 /* Return TRUE in case BB1 is dominated by BB2. */ 950 /* Return TRUE in case BB1 is dominated by BB2. */
925 bool 951 bool
926 dominated_by_p (enum cdi_direction dir, const_basic_block bb1, const_basic_block bb2) 952 dominated_by_p (enum cdi_direction dir, const_basic_block bb1, const_basic_block bb2)
927 { 953 {
928 unsigned int dir_index = dom_convert_dir_to_idx (dir); 954 unsigned int dir_index = dom_convert_dir_to_idx (dir);
929 struct et_node *n1 = bb1->dom[dir_index], *n2 = bb2->dom[dir_index]; 955 struct et_node *n1 = bb1->dom[dir_index], *n2 = bb2->dom[dir_index];
930 956
931 gcc_assert (dom_computed[dir_index]); 957 gcc_assert (dom_computed[dir_index]);
932 958
933 if (dom_computed[dir_index] == DOM_OK) 959 if (dom_computed[dir_index] == DOM_OK)
934 return (n1->dfs_num_in >= n2->dfs_num_in 960 return (n1->dfs_num_in >= n2->dfs_num_in
935 && n1->dfs_num_out <= n2->dfs_num_out); 961 && n1->dfs_num_out <= n2->dfs_num_out);
1361 1387
1362 gcc_assert (dom_computed[dir_index]); 1388 gcc_assert (dom_computed[dir_index]);
1363 gcc_assert (!bb->dom[dir_index]); 1389 gcc_assert (!bb->dom[dir_index]);
1364 1390
1365 n_bbs_in_dom_tree[dir_index]++; 1391 n_bbs_in_dom_tree[dir_index]++;
1366 1392
1367 bb->dom[dir_index] = et_new_tree (bb); 1393 bb->dom[dir_index] = et_new_tree (bb);
1368 1394
1369 if (dom_computed[dir_index] == DOM_OK) 1395 if (dom_computed[dir_index] == DOM_OK)
1370 dom_computed[dir_index] = DOM_NO_FAST_QUERY; 1396 dom_computed[dir_index] = DOM_NO_FAST_QUERY;
1371 } 1397 }