Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-phiopt.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 |
---|---|
205 outer ones, and also that we do not try to visit a removed | 205 outer ones, and also that we do not try to visit a removed |
206 block. */ | 206 block. */ |
207 bb_order = blocks_in_phiopt_order (); | 207 bb_order = blocks_in_phiopt_order (); |
208 n = n_basic_blocks - NUM_FIXED_BLOCKS; | 208 n = n_basic_blocks - NUM_FIXED_BLOCKS; |
209 | 209 |
210 for (i = 0; i < n; i++) | 210 for (i = 0; i < n; i++) |
211 { | 211 { |
212 gimple cond_stmt, phi; | 212 gimple cond_stmt, phi; |
213 basic_block bb1, bb2; | 213 basic_block bb1, bb2; |
214 edge e1, e2; | 214 edge e1, e2; |
215 tree arg0, arg1; | 215 tree arg0, arg1; |
305 cfgchanged = true; | 305 cfgchanged = true; |
306 } | 306 } |
307 } | 307 } |
308 | 308 |
309 free (bb_order); | 309 free (bb_order); |
310 | 310 |
311 if (do_store_elim) | 311 if (do_store_elim) |
312 pointer_set_destroy (nontrap); | 312 pointer_set_destroy (nontrap); |
313 /* If the CFG has changed, we should cleanup the CFG. */ | 313 /* If the CFG has changed, we should cleanup the CFG. */ |
314 if (cfgchanged && do_store_elim) | 314 if (cfgchanged && do_store_elim) |
315 { | 315 { |
330 basic_block * | 330 basic_block * |
331 blocks_in_phiopt_order (void) | 331 blocks_in_phiopt_order (void) |
332 { | 332 { |
333 basic_block x, y; | 333 basic_block x, y; |
334 basic_block *order = XNEWVEC (basic_block, n_basic_blocks); | 334 basic_block *order = XNEWVEC (basic_block, n_basic_blocks); |
335 unsigned n = n_basic_blocks - NUM_FIXED_BLOCKS; | 335 unsigned n = n_basic_blocks - NUM_FIXED_BLOCKS; |
336 unsigned np, i; | 336 unsigned np, i; |
337 sbitmap visited = sbitmap_alloc (last_basic_block); | 337 sbitmap visited = sbitmap_alloc (last_basic_block); |
338 | 338 |
339 #define MARK_VISITED(BB) (SET_BIT (visited, (BB)->index)) | 339 #define MARK_VISITED(BB) (SET_BIT (visited, (BB)->index)) |
340 #define VISITED_P(BB) (TEST_BIT (visited, (BB)->index)) | 340 #define VISITED_P(BB) (TEST_BIT (visited, (BB)->index)) |
341 | 341 |
342 sbitmap_zero (visited); | 342 sbitmap_zero (visited); |
343 | 343 |
344 MARK_VISITED (ENTRY_BLOCK_PTR); | 344 MARK_VISITED (ENTRY_BLOCK_PTR); |
345 FOR_EACH_BB (x) | 345 FOR_EACH_BB (x) |
382 | 382 |
383 bool | 383 bool |
384 empty_block_p (basic_block bb) | 384 empty_block_p (basic_block bb) |
385 { | 385 { |
386 /* BB must have no executable statements. */ | 386 /* BB must have no executable statements. */ |
387 return gsi_end_p (gsi_after_labels (bb)); | 387 gimple_stmt_iterator gsi = gsi_after_labels (bb); |
388 if (gsi_end_p (gsi)) | |
389 return true; | |
390 if (is_gimple_debug (gsi_stmt (gsi))) | |
391 gsi_next_nondebug (&gsi); | |
392 return gsi_end_p (gsi); | |
388 } | 393 } |
389 | 394 |
390 /* Replace PHI node element whose edge is E in block BB with variable NEW. | 395 /* Replace PHI node element whose edge is E in block BB with variable NEW. |
391 Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK | 396 Remove the edge from COND_BLOCK which does not lead to BB (COND_BLOCK |
392 is known to have two edges, one of which must reach BB). */ | 397 is known to have two edges, one of which must reach BB). */ |
511 new_var = force_gimple_operand_gsi (&gsi, cond, true, NULL, true, | 516 new_var = force_gimple_operand_gsi (&gsi, cond, true, NULL, true, |
512 GSI_SAME_STMT); | 517 GSI_SAME_STMT); |
513 | 518 |
514 if (!useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (new_var))) | 519 if (!useless_type_conversion_p (TREE_TYPE (result), TREE_TYPE (new_var))) |
515 { | 520 { |
521 source_location locus_0, locus_1; | |
522 | |
516 new_var2 = create_tmp_var (TREE_TYPE (result), NULL); | 523 new_var2 = create_tmp_var (TREE_TYPE (result), NULL); |
517 add_referenced_var (new_var2); | 524 add_referenced_var (new_var2); |
518 new_stmt = gimple_build_assign_with_ops (CONVERT_EXPR, new_var2, | 525 new_stmt = gimple_build_assign_with_ops (CONVERT_EXPR, new_var2, |
519 new_var, NULL); | 526 new_var, NULL); |
520 new_var2 = make_ssa_name (new_var2, new_stmt); | 527 new_var2 = make_ssa_name (new_var2, new_stmt); |
521 gimple_assign_set_lhs (new_stmt, new_var2); | 528 gimple_assign_set_lhs (new_stmt, new_var2); |
522 gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT); | 529 gsi_insert_before (&gsi, new_stmt, GSI_SAME_STMT); |
523 new_var = new_var2; | 530 new_var = new_var2; |
531 | |
532 /* Set the locus to the first argument, unless is doesn't have one. */ | |
533 locus_0 = gimple_phi_arg_location (phi, 0); | |
534 locus_1 = gimple_phi_arg_location (phi, 1); | |
535 if (locus_0 == UNKNOWN_LOCATION) | |
536 locus_0 = locus_1; | |
537 gimple_set_location (new_stmt, locus_0); | |
524 } | 538 } |
525 | 539 |
526 replace_phi_edge_with_variable (cond_bb, e1, phi, new_var); | 540 replace_phi_edge_with_variable (cond_bb, e1, phi, new_var); |
527 | 541 |
528 /* Note that we optimized this PHI. */ | 542 /* Note that we optimized this PHI. */ |
680 { | 694 { |
681 if (operand_equal_for_phi_arg_p (arg_true, smaller) | 695 if (operand_equal_for_phi_arg_p (arg_true, smaller) |
682 && operand_equal_for_phi_arg_p (arg_false, larger)) | 696 && operand_equal_for_phi_arg_p (arg_false, larger)) |
683 { | 697 { |
684 /* Case | 698 /* Case |
685 | 699 |
686 if (smaller < larger) | 700 if (smaller < larger) |
687 rslt = smaller; | 701 rslt = smaller; |
688 else | 702 else |
689 rslt = larger; */ | 703 rslt = larger; */ |
690 minmax = MIN_EXPR; | 704 minmax = MIN_EXPR; |
841 return false; | 855 return false; |
842 } | 856 } |
843 | 857 |
844 /* Move the statement from the middle block. */ | 858 /* Move the statement from the middle block. */ |
845 gsi = gsi_last_bb (cond_bb); | 859 gsi = gsi_last_bb (cond_bb); |
846 gsi_from = gsi_last_bb (middle_bb); | 860 gsi_from = gsi_last_nondebug_bb (middle_bb); |
847 gsi_move_before (&gsi_from, &gsi); | 861 gsi_move_before (&gsi_from, &gsi); |
848 } | 862 } |
849 | 863 |
850 /* Emit the statement to compute min/max. */ | 864 /* Emit the statement to compute min/max. */ |
851 result = duplicate_ssa_name (PHI_RESULT (phi), NULL); | 865 result = duplicate_ssa_name (PHI_RESULT (phi), NULL); |
889 assign = last_and_only_stmt (middle_bb); | 903 assign = last_and_only_stmt (middle_bb); |
890 /* If we did not find the proper negation assignment, then we can not | 904 /* If we did not find the proper negation assignment, then we can not |
891 optimize. */ | 905 optimize. */ |
892 if (assign == NULL) | 906 if (assign == NULL) |
893 return false; | 907 return false; |
894 | 908 |
895 /* If we got here, then we have found the only executable statement | 909 /* If we got here, then we have found the only executable statement |
896 in OTHER_BLOCK. If it is anything other than arg = -arg1 or | 910 in OTHER_BLOCK. If it is anything other than arg = -arg1 or |
897 arg1 = -arg0, then we can not optimize. */ | 911 arg1 = -arg0, then we can not optimize. */ |
898 if (gimple_code (assign) != GIMPLE_ASSIGN) | 912 if (gimple_code (assign) != GIMPLE_ASSIGN) |
899 return false; | 913 return false; |
902 | 916 |
903 if (gimple_assign_rhs_code (assign) != NEGATE_EXPR) | 917 if (gimple_assign_rhs_code (assign) != NEGATE_EXPR) |
904 return false; | 918 return false; |
905 | 919 |
906 rhs = gimple_assign_rhs1 (assign); | 920 rhs = gimple_assign_rhs1 (assign); |
907 | 921 |
908 /* The assignment has to be arg0 = -arg1 or arg1 = -arg0. */ | 922 /* The assignment has to be arg0 = -arg1 or arg1 = -arg0. */ |
909 if (!(lhs == arg0 && rhs == arg1) | 923 if (!(lhs == arg0 && rhs == arg1) |
910 && !(lhs == arg1 && rhs == arg0)) | 924 && !(lhs == arg1 && rhs == arg0)) |
911 return false; | 925 return false; |
912 | 926 |
1137 dominance information. */ | 1151 dominance information. */ |
1138 calculate_dominance_info (CDI_DOMINATORS); | 1152 calculate_dominance_info (CDI_DOMINATORS); |
1139 | 1153 |
1140 /* Setup callbacks for the generic dominator tree walker. */ | 1154 /* Setup callbacks for the generic dominator tree walker. */ |
1141 nontrap_set = nontrap; | 1155 nontrap_set = nontrap; |
1142 walk_data.walk_stmts_backward = false; | |
1143 walk_data.dom_direction = CDI_DOMINATORS; | 1156 walk_data.dom_direction = CDI_DOMINATORS; |
1144 walk_data.initialize_block_local_data = NULL; | 1157 walk_data.initialize_block_local_data = NULL; |
1145 walk_data.before_dom_children_before_stmts = nt_init_block; | 1158 walk_data.before_dom_children = nt_init_block; |
1146 walk_data.before_dom_children_walk_stmts = NULL; | 1159 walk_data.after_dom_children = nt_fini_block; |
1147 walk_data.before_dom_children_after_stmts = NULL; | |
1148 walk_data.after_dom_children_before_stmts = NULL; | |
1149 walk_data.after_dom_children_walk_stmts = NULL; | |
1150 walk_data.after_dom_children_after_stmts = nt_fini_block; | |
1151 walk_data.global_data = NULL; | 1160 walk_data.global_data = NULL; |
1152 walk_data.block_local_data_size = 0; | 1161 walk_data.block_local_data_size = 0; |
1153 walk_data.interesting_blocks = NULL; | |
1154 | 1162 |
1155 init_walk_dominator_tree (&walk_data); | 1163 init_walk_dominator_tree (&walk_data); |
1156 walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR); | 1164 walk_dominator_tree (&walk_data, ENTRY_BLOCK_PTR); |
1157 fini_walk_dominator_tree (&walk_data); | 1165 fini_walk_dominator_tree (&walk_data); |
1158 htab_delete (seen_ssa_names); | 1166 htab_delete (seen_ssa_names); |
1181 { | 1189 { |
1182 gimple assign = last_and_only_stmt (middle_bb); | 1190 gimple assign = last_and_only_stmt (middle_bb); |
1183 tree lhs, rhs, name; | 1191 tree lhs, rhs, name; |
1184 gimple newphi, new_stmt; | 1192 gimple newphi, new_stmt; |
1185 gimple_stmt_iterator gsi; | 1193 gimple_stmt_iterator gsi; |
1194 source_location locus; | |
1186 enum tree_code code; | 1195 enum tree_code code; |
1187 | 1196 |
1188 /* Check if middle_bb contains of only one store. */ | 1197 /* Check if middle_bb contains of only one store. */ |
1189 if (!assign | 1198 if (!assign |
1190 || gimple_code (assign) != GIMPLE_ASSIGN) | 1199 || gimple_code (assign) != GIMPLE_ASSIGN) |
1191 return false; | 1200 return false; |
1192 | 1201 |
1202 locus = gimple_location (assign); | |
1193 lhs = gimple_assign_lhs (assign); | 1203 lhs = gimple_assign_lhs (assign); |
1194 rhs = gimple_assign_rhs1 (assign); | 1204 rhs = gimple_assign_rhs1 (assign); |
1195 if (!INDIRECT_REF_P (lhs)) | 1205 if (!INDIRECT_REF_P (lhs)) |
1196 return false; | 1206 return false; |
1197 | 1207 |
1228 on the edge which did not contain the store. */ | 1238 on the edge which did not contain the store. */ |
1229 lhs = unshare_expr (lhs); | 1239 lhs = unshare_expr (lhs); |
1230 new_stmt = gimple_build_assign (condstoretemp, lhs); | 1240 new_stmt = gimple_build_assign (condstoretemp, lhs); |
1231 name = make_ssa_name (condstoretemp, new_stmt); | 1241 name = make_ssa_name (condstoretemp, new_stmt); |
1232 gimple_assign_set_lhs (new_stmt, name); | 1242 gimple_assign_set_lhs (new_stmt, name); |
1243 gimple_set_location (new_stmt, locus); | |
1233 mark_symbols_for_renaming (new_stmt); | 1244 mark_symbols_for_renaming (new_stmt); |
1234 gsi_insert_on_edge (e1, new_stmt); | 1245 gsi_insert_on_edge (e1, new_stmt); |
1235 | 1246 |
1236 /* 4) Create a PHI node at the join block, with one argument | 1247 /* 4) Create a PHI node at the join block, with one argument |
1237 holding the old RHS, and the other holding the temporary | 1248 holding the old RHS, and the other holding the temporary |
1238 where we stored the old memory contents. */ | 1249 where we stored the old memory contents. */ |
1239 newphi = create_phi_node (condstoretemp, join_bb); | 1250 newphi = create_phi_node (condstoretemp, join_bb); |
1240 add_phi_arg (newphi, rhs, e0); | 1251 add_phi_arg (newphi, rhs, e0, locus); |
1241 add_phi_arg (newphi, name, e1); | 1252 add_phi_arg (newphi, name, e1, locus); |
1242 | 1253 |
1243 lhs = unshare_expr (lhs); | 1254 lhs = unshare_expr (lhs); |
1244 new_stmt = gimple_build_assign (lhs, PHI_RESULT (newphi)); | 1255 new_stmt = gimple_build_assign (lhs, PHI_RESULT (newphi)); |
1245 mark_symbols_for_renaming (new_stmt); | 1256 mark_symbols_for_renaming (new_stmt); |
1246 | 1257 |
1274 tree_ssa_phiopt, /* execute */ | 1285 tree_ssa_phiopt, /* execute */ |
1275 NULL, /* sub */ | 1286 NULL, /* sub */ |
1276 NULL, /* next */ | 1287 NULL, /* next */ |
1277 0, /* static_pass_number */ | 1288 0, /* static_pass_number */ |
1278 TV_TREE_PHIOPT, /* tv_id */ | 1289 TV_TREE_PHIOPT, /* tv_id */ |
1279 PROP_cfg | PROP_ssa | PROP_alias, /* properties_required */ | 1290 PROP_cfg | PROP_ssa, /* properties_required */ |
1280 0, /* properties_provided */ | 1291 0, /* properties_provided */ |
1281 0, /* properties_destroyed */ | 1292 0, /* properties_destroyed */ |
1282 0, /* todo_flags_start */ | 1293 0, /* todo_flags_start */ |
1283 TODO_dump_func | 1294 TODO_dump_func |
1284 | TODO_ggc_collect | 1295 | TODO_ggc_collect |
1303 tree_ssa_cs_elim, /* execute */ | 1314 tree_ssa_cs_elim, /* execute */ |
1304 NULL, /* sub */ | 1315 NULL, /* sub */ |
1305 NULL, /* next */ | 1316 NULL, /* next */ |
1306 0, /* static_pass_number */ | 1317 0, /* static_pass_number */ |
1307 TV_TREE_PHIOPT, /* tv_id */ | 1318 TV_TREE_PHIOPT, /* tv_id */ |
1308 PROP_cfg | PROP_ssa | PROP_alias, /* properties_required */ | 1319 PROP_cfg | PROP_ssa, /* properties_required */ |
1309 0, /* properties_provided */ | 1320 0, /* properties_provided */ |
1310 0, /* properties_destroyed */ | 1321 0, /* properties_destroyed */ |
1311 0, /* todo_flags_start */ | 1322 0, /* todo_flags_start */ |
1312 TODO_dump_func | 1323 TODO_dump_func |
1313 | TODO_ggc_collect | 1324 | TODO_ggc_collect |