comparison gcc/dominance.c @ 67:f6334be47118

update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
author nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
date Tue, 22 Mar 2011 17:18:12 +0900
parents b7f97abdc517
children 04ced10e8804
comparison
equal deleted inserted replaced
65:65488c3d617d 67:f6334be47118
39 #include "tm.h" 39 #include "tm.h"
40 #include "rtl.h" 40 #include "rtl.h"
41 #include "hard-reg-set.h" 41 #include "hard-reg-set.h"
42 #include "obstack.h" 42 #include "obstack.h"
43 #include "basic-block.h" 43 #include "basic-block.h"
44 #include "toplev.h" 44 #include "diagnostic-core.h"
45 #include "et-forest.h" 45 #include "et-forest.h"
46 #include "timevar.h" 46 #include "timevar.h"
47 #include "vecprim.h" 47 #include "vecprim.h"
48 #include "pointer-set.h" 48 #include "pointer-set.h"
49 #include "graphds.h" 49 #include "graphds.h"
781 781
782 return doms; 782 return doms;
783 } 783 }
784 784
785 /* Returns the list of basic blocks including BB dominated by BB, in the 785 /* Returns the list of basic blocks including BB dominated by BB, in the
786 direction DIR. The vector will be sorted in preorder. */ 786 direction DIR up to DEPTH in the dominator tree. The DEPTH of zero will
787 produce a vector containing all dominated blocks. The vector will be sorted
788 in preorder. */
787 789
788 VEC (basic_block, heap) * 790 VEC (basic_block, heap) *
789 get_all_dominated_blocks (enum cdi_direction dir, basic_block bb) 791 get_dominated_to_depth (enum cdi_direction dir, basic_block bb, int depth)
790 { 792 {
791 VEC(basic_block, heap) *bbs = NULL; 793 VEC(basic_block, heap) *bbs = NULL;
792 unsigned i; 794 unsigned i;
795 unsigned next_level_start;
793 796
794 i = 0; 797 i = 0;
795 VEC_safe_push (basic_block, heap, bbs, bb); 798 VEC_safe_push (basic_block, heap, bbs, bb);
799 next_level_start = 1; /* = VEC_length (basic_block, bbs); */
796 800
797 do 801 do
798 { 802 {
799 basic_block son; 803 basic_block son;
800 804
801 bb = VEC_index (basic_block, bbs, i++); 805 bb = VEC_index (basic_block, bbs, i++);
802 for (son = first_dom_son (dir, bb); 806 for (son = first_dom_son (dir, bb);
803 son; 807 son;
804 son = next_dom_son (dir, son)) 808 son = next_dom_son (dir, son))
805 VEC_safe_push (basic_block, heap, bbs, son); 809 VEC_safe_push (basic_block, heap, bbs, son);
806 } 810
807 while (i < VEC_length (basic_block, bbs)); 811 if (i == next_level_start && --depth)
812 next_level_start = VEC_length (basic_block, bbs);
813 }
814 while (i < next_level_start);
808 815
809 return bbs; 816 return bbs;
817 }
818
819 /* Returns the list of basic blocks including BB dominated by BB, in the
820 direction DIR. The vector will be sorted in preorder. */
821
822 VEC (basic_block, heap) *
823 get_all_dominated_blocks (enum cdi_direction dir, basic_block bb)
824 {
825 return get_dominated_to_depth (dir, bb, 0);
810 } 826 }
811 827
812 /* Redirect all edges pointing to BB to TO. */ 828 /* Redirect all edges pointing to BB to TO. */
813 void 829 void
814 redirect_immediate_dominators (enum cdi_direction dir, basic_block bb, 830 redirect_immediate_dominators (enum cdi_direction dir, basic_block bb,
987 gcc_assert (dom_computed[dir_index] == DOM_OK); 1003 gcc_assert (dom_computed[dir_index] == DOM_OK);
988 return n->dfs_num_out; 1004 return n->dfs_num_out;
989 } 1005 }
990 1006
991 /* Verify invariants of dominator structure. */ 1007 /* Verify invariants of dominator structure. */
992 void 1008 DEBUG_FUNCTION void
993 verify_dominators (enum cdi_direction dir) 1009 verify_dominators (enum cdi_direction dir)
994 { 1010 {
995 int err = 0; 1011 int err = 0;
996 basic_block bb, imm_bb, imm_bb_correct; 1012 basic_block bb, imm_bb, imm_bb_correct;
997 struct dom_info di; 1013 struct dom_info di;
1179 VEC_safe_push (int, heap, sccs[g->vertices[a].component], a); 1195 VEC_safe_push (int, heap, sccs[g->vertices[a].component], a);
1180 1196
1181 for (i = nc - 1; i >= 0; i--) 1197 for (i = nc - 1; i >= 0; i--)
1182 { 1198 {
1183 dom = NULL; 1199 dom = NULL;
1184 for (si = 0; VEC_iterate (int, sccs[i], si, a); si++) 1200 FOR_EACH_VEC_ELT (int, sccs[i], si, a)
1185 { 1201 {
1186 bb = VEC_index (basic_block, bbs, a); 1202 bb = VEC_index (basic_block, bbs, a);
1187 FOR_EACH_EDGE (e, ei, bb->preds) 1203 FOR_EACH_EDGE (e, ei, bb->preds)
1188 { 1204 {
1189 if (root_of_dom_tree (CDI_DOMINATORS, e->src) != ybb) 1205 if (root_of_dom_tree (CDI_DOMINATORS, e->src) != ybb)
1192 dom = nearest_common_dominator (CDI_DOMINATORS, dom, e->src); 1208 dom = nearest_common_dominator (CDI_DOMINATORS, dom, e->src);
1193 } 1209 }
1194 } 1210 }
1195 1211
1196 gcc_assert (dom != NULL); 1212 gcc_assert (dom != NULL);
1197 for (si = 0; VEC_iterate (int, sccs[i], si, a); si++) 1213 FOR_EACH_VEC_ELT (int, sccs[i], si, a)
1198 { 1214 {
1199 bb = VEC_index (basic_block, bbs, a); 1215 bb = VEC_index (basic_block, bbs, a);
1200 set_immediate_dominator (CDI_DOMINATORS, bb, dom); 1216 set_immediate_dominator (CDI_DOMINATORS, bb, dom);
1201 } 1217 }
1202 } 1218 }
1295 { 1311 {
1296 /* Split the tree now. If the idoms of blocks in BBS are not 1312 /* Split the tree now. If the idoms of blocks in BBS are not
1297 conservatively correct, setting the dominators using the 1313 conservatively correct, setting the dominators using the
1298 heuristics in prune_bbs_to_update_dominators could 1314 heuristics in prune_bbs_to_update_dominators could
1299 create cycles in the dominance "tree", and cause ICE. */ 1315 create cycles in the dominance "tree", and cause ICE. */
1300 for (i = 0; VEC_iterate (basic_block, bbs, i, bb); i++) 1316 FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
1301 set_immediate_dominator (CDI_DOMINATORS, bb, NULL); 1317 set_immediate_dominator (CDI_DOMINATORS, bb, NULL);
1302 } 1318 }
1303 1319
1304 prune_bbs_to_update_dominators (bbs, conservative); 1320 prune_bbs_to_update_dominators (bbs, conservative);
1305 n = VEC_length (basic_block, bbs); 1321 n = VEC_length (basic_block, bbs);
1315 return; 1331 return;
1316 } 1332 }
1317 1333
1318 /* Construct the graph G. */ 1334 /* Construct the graph G. */
1319 map = pointer_map_create (); 1335 map = pointer_map_create ();
1320 for (i = 0; VEC_iterate (basic_block, bbs, i, bb); i++) 1336 FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
1321 { 1337 {
1322 /* If the dominance tree is conservatively correct, split it now. */ 1338 /* If the dominance tree is conservatively correct, split it now. */
1323 if (conservative) 1339 if (conservative)
1324 set_immediate_dominator (CDI_DOMINATORS, bb, NULL); 1340 set_immediate_dominator (CDI_DOMINATORS, bb, NULL);
1325 *pointer_map_insert (map, bb) = (void *) (size_t) i; 1341 *pointer_map_insert (map, bb) = (void *) (size_t) i;
1327 *pointer_map_insert (map, ENTRY_BLOCK_PTR) = (void *) (size_t) n; 1343 *pointer_map_insert (map, ENTRY_BLOCK_PTR) = (void *) (size_t) n;
1328 1344
1329 g = new_graph (n + 1); 1345 g = new_graph (n + 1);
1330 for (y = 0; y < g->n_vertices; y++) 1346 for (y = 0; y < g->n_vertices; y++)
1331 g->vertices[y].data = BITMAP_ALLOC (NULL); 1347 g->vertices[y].data = BITMAP_ALLOC (NULL);
1332 for (i = 0; VEC_iterate (basic_block, bbs, i, bb); i++) 1348 FOR_EACH_VEC_ELT (basic_block, bbs, i, bb)
1333 { 1349 {
1334 FOR_EACH_EDGE (e, ei, bb->preds) 1350 FOR_EACH_EDGE (e, ei, bb->preds)
1335 { 1351 {
1336 dom = root_of_dom_tree (CDI_DOMINATORS, e->src); 1352 dom = root_of_dom_tree (CDI_DOMINATORS, e->src);
1337 if (dom == bb) 1353 if (dom == bb)
1338 continue; 1354 continue;
1339 1355
1340 dom_i = (size_t) *pointer_map_contains (map, dom); 1356 dom_i = (size_t) *pointer_map_contains (map, dom);
1341 1357
1342 /* Do not include parallel edges to G. */ 1358 /* Do not include parallel edges to G. */
1343 if (bitmap_bit_p ((bitmap) g->vertices[dom_i].data, i)) 1359 if (!bitmap_set_bit ((bitmap) g->vertices[dom_i].data, i))
1344 continue; 1360 continue;
1345 1361
1346 bitmap_set_bit ((bitmap) g->vertices[dom_i].data, i);
1347 add_edge (g, dom_i, i); 1362 add_edge (g, dom_i, i);
1348 } 1363 }
1349 } 1364 }
1350 for (y = 0; y < g->n_vertices; y++) 1365 for (y = 0; y < g->n_vertices; y++)
1351 BITMAP_FREE (g->vertices[y].data); 1366 BITMAP_FREE (g->vertices[y].data);
1464 unsigned int dir_index = dom_convert_dir_to_idx (dir); 1479 unsigned int dir_index = dom_convert_dir_to_idx (dir);
1465 1480
1466 return dom_computed[dir_index] != DOM_NONE; 1481 return dom_computed[dir_index] != DOM_NONE;
1467 } 1482 }
1468 1483
1469 void 1484 DEBUG_FUNCTION void
1470 debug_dominance_info (enum cdi_direction dir) 1485 debug_dominance_info (enum cdi_direction dir)
1471 { 1486 {
1472 basic_block bb, bb2; 1487 basic_block bb, bb2;
1473 FOR_EACH_BB (bb) 1488 FOR_EACH_BB (bb)
1474 if ((bb2 = get_immediate_dominator (dir, bb))) 1489 if ((bb2 = get_immediate_dominator (dir, bb)))
1505 } 1520 }
1506 1521
1507 /* Prints to stderr representation of the dominance tree (for direction DIR) 1522 /* Prints to stderr representation of the dominance tree (for direction DIR)
1508 rooted in ROOT. */ 1523 rooted in ROOT. */
1509 1524
1510 void 1525 DEBUG_FUNCTION void
1511 debug_dominance_tree (enum cdi_direction dir, basic_block root) 1526 debug_dominance_tree (enum cdi_direction dir, basic_block root)
1512 { 1527 {
1513 debug_dominance_tree_1 (dir, root, 0, false); 1528 debug_dominance_tree_1 (dir, root, 0, false);
1514 } 1529 }