comparison gcc/tree-cfg.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
1 /* Control flow functions for trees. 1 /* Control flow functions for trees.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
3 Free Software Foundation, Inc. 3 2010 Free Software Foundation, Inc.
4 Contributed by Diego Novillo <dnovillo@redhat.com> 4 Contributed by Diego Novillo <dnovillo@redhat.com>
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify 8 GCC is free software; you can redistribute it and/or modify
22 #include "config.h" 22 #include "config.h"
23 #include "system.h" 23 #include "system.h"
24 #include "coretypes.h" 24 #include "coretypes.h"
25 #include "tm.h" 25 #include "tm.h"
26 #include "tree.h" 26 #include "tree.h"
27 #include "rtl.h"
28 #include "tm_p.h" 27 #include "tm_p.h"
29 #include "hard-reg-set.h"
30 #include "basic-block.h" 28 #include "basic-block.h"
31 #include "output.h" 29 #include "output.h"
32 #include "flags.h" 30 #include "flags.h"
33 #include "function.h" 31 #include "function.h"
34 #include "expr.h" 32 #include "expr.h"
35 #include "ggc.h" 33 #include "ggc.h"
36 #include "langhooks.h" 34 #include "langhooks.h"
37 #include "diagnostic.h" 35 #include "diagnostic.h"
36 #include "tree-pretty-print.h"
37 #include "gimple-pretty-print.h"
38 #include "tree-flow.h" 38 #include "tree-flow.h"
39 #include "timevar.h" 39 #include "timevar.h"
40 #include "tree-dump.h" 40 #include "tree-dump.h"
41 #include "tree-pass.h" 41 #include "tree-pass.h"
42 #include "toplev.h" 42 #include "toplev.h"
69 more persistent. The key is getting notification of changes to 69 more persistent. The key is getting notification of changes to
70 the CFG (particularly edge removal, creation and redirection). */ 70 the CFG (particularly edge removal, creation and redirection). */
71 71
72 static struct pointer_map_t *edge_to_cases; 72 static struct pointer_map_t *edge_to_cases;
73 73
74 /* If we record edge_to_cases, this bitmap will hold indexes
75 of basic blocks that end in a GIMPLE_SWITCH which we touched
76 due to edge manipulations. */
77
78 static bitmap touched_switch_bbs;
79
74 /* CFG statistics. */ 80 /* CFG statistics. */
75 struct cfg_stats_d 81 struct cfg_stats_d
76 { 82 {
77 long num_merged_labels; 83 long num_merged_labels;
78 }; 84 };
120 static void remove_bb (basic_block); 126 static void remove_bb (basic_block);
121 static edge find_taken_edge_computed_goto (basic_block, tree); 127 static edge find_taken_edge_computed_goto (basic_block, tree);
122 static edge find_taken_edge_cond_expr (basic_block, tree); 128 static edge find_taken_edge_cond_expr (basic_block, tree);
123 static edge find_taken_edge_switch_expr (basic_block, tree); 129 static edge find_taken_edge_switch_expr (basic_block, tree);
124 static tree find_case_label_for_value (gimple, tree); 130 static tree find_case_label_for_value (gimple, tree);
131 static void group_case_labels_stmt (gimple);
125 132
126 void 133 void
127 init_empty_tree_cfg_for_function (struct function *fn) 134 init_empty_tree_cfg_for_function (struct function *fn)
128 { 135 {
129 /* Initialize the basic block array. */ 136 /* Initialize the basic block array. */
846 void 853 void
847 start_recording_case_labels (void) 854 start_recording_case_labels (void)
848 { 855 {
849 gcc_assert (edge_to_cases == NULL); 856 gcc_assert (edge_to_cases == NULL);
850 edge_to_cases = pointer_map_create (); 857 edge_to_cases = pointer_map_create ();
858 touched_switch_bbs = BITMAP_ALLOC (NULL);
851 } 859 }
852 860
853 /* Return nonzero if we are recording information for case labels. */ 861 /* Return nonzero if we are recording information for case labels. */
854 862
855 static bool 863 static bool
861 /* Stop recording information mapping edges to case labels and 869 /* Stop recording information mapping edges to case labels and
862 remove any information we have recorded. */ 870 remove any information we have recorded. */
863 void 871 void
864 end_recording_case_labels (void) 872 end_recording_case_labels (void)
865 { 873 {
874 bitmap_iterator bi;
875 unsigned i;
866 pointer_map_traverse (edge_to_cases, edge_to_cases_cleanup, NULL); 876 pointer_map_traverse (edge_to_cases, edge_to_cases_cleanup, NULL);
867 pointer_map_destroy (edge_to_cases); 877 pointer_map_destroy (edge_to_cases);
868 edge_to_cases = NULL; 878 edge_to_cases = NULL;
879 EXECUTE_IF_SET_IN_BITMAP (touched_switch_bbs, 0, i, bi)
880 {
881 basic_block bb = BASIC_BLOCK (i);
882 if (bb)
883 {
884 gimple stmt = last_stmt (bb);
885 if (stmt && gimple_code (stmt) == GIMPLE_SWITCH)
886 group_case_labels_stmt (stmt);
887 }
888 }
889 BITMAP_FREE (touched_switch_bbs);
869 } 890 }
870 891
871 /* If we are inside a {start,end}_recording_cases block, then return 892 /* If we are inside a {start,end}_recording_cases block, then return
872 a chain of CASE_LABEL_EXPRs from T which reference E. 893 a chain of CASE_LABEL_EXPRs from T which reference E.
873 894
1276 } 1297 }
1277 1298
1278 free (label_for_bb); 1299 free (label_for_bb);
1279 } 1300 }
1280 1301
1281 /* Look for blocks ending in a multiway branch (a SWITCH_EXPR in GIMPLE), 1302 /* Scan the sorted vector of cases in STMT (a GIMPLE_SWITCH) and combine
1303 the ones jumping to the same label.
1304 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
1305
1306 static void
1307 group_case_labels_stmt (gimple stmt)
1308 {
1309 int old_size = gimple_switch_num_labels (stmt);
1310 int i, j, new_size = old_size;
1311 tree default_case = NULL_TREE;
1312 tree default_label = NULL_TREE;
1313 bool has_default;
1314
1315 /* The default label is always the first case in a switch
1316 statement after gimplification if it was not optimized
1317 away */
1318 if (!CASE_LOW (gimple_switch_default_label (stmt))
1319 && !CASE_HIGH (gimple_switch_default_label (stmt)))
1320 {
1321 default_case = gimple_switch_default_label (stmt);
1322 default_label = CASE_LABEL (default_case);
1323 has_default = true;
1324 }
1325 else
1326 has_default = false;
1327
1328 /* Look for possible opportunities to merge cases. */
1329 if (has_default)
1330 i = 1;
1331 else
1332 i = 0;
1333 while (i < old_size)
1334 {
1335 tree base_case, base_label, base_high;
1336 base_case = gimple_switch_label (stmt, i);
1337
1338 gcc_assert (base_case);
1339 base_label = CASE_LABEL (base_case);
1340
1341 /* Discard cases that have the same destination as the
1342 default case. */
1343 if (base_label == default_label)
1344 {
1345 gimple_switch_set_label (stmt, i, NULL_TREE);
1346 i++;
1347 new_size--;
1348 continue;
1349 }
1350
1351 base_high = CASE_HIGH (base_case)
1352 ? CASE_HIGH (base_case)
1353 : CASE_LOW (base_case);
1354 i++;
1355
1356 /* Try to merge case labels. Break out when we reach the end
1357 of the label vector or when we cannot merge the next case
1358 label with the current one. */
1359 while (i < old_size)
1360 {
1361 tree merge_case = gimple_switch_label (stmt, i);
1362 tree merge_label = CASE_LABEL (merge_case);
1363 tree t = int_const_binop (PLUS_EXPR, base_high,
1364 integer_one_node, 1);
1365
1366 /* Merge the cases if they jump to the same place,
1367 and their ranges are consecutive. */
1368 if (merge_label == base_label
1369 && tree_int_cst_equal (CASE_LOW (merge_case), t))
1370 {
1371 base_high = CASE_HIGH (merge_case) ?
1372 CASE_HIGH (merge_case) : CASE_LOW (merge_case);
1373 CASE_HIGH (base_case) = base_high;
1374 gimple_switch_set_label (stmt, i, NULL_TREE);
1375 new_size--;
1376 i++;
1377 }
1378 else
1379 break;
1380 }
1381 }
1382
1383 /* Compress the case labels in the label vector, and adjust the
1384 length of the vector. */
1385 for (i = 0, j = 0; i < new_size; i++)
1386 {
1387 while (! gimple_switch_label (stmt, j))
1388 j++;
1389 gimple_switch_set_label (stmt, i,
1390 gimple_switch_label (stmt, j++));
1391 }
1392
1393 gcc_assert (new_size <= old_size);
1394 gimple_switch_set_num_labels (stmt, new_size);
1395 }
1396
1397 /* Look for blocks ending in a multiway branch (a GIMPLE_SWITCH),
1282 and scan the sorted vector of cases. Combine the ones jumping to the 1398 and scan the sorted vector of cases. Combine the ones jumping to the
1283 same label. 1399 same label. */
1284 Eg. three separate entries 1: 2: 3: become one entry 1..3: */
1285 1400
1286 void 1401 void
1287 group_case_labels (void) 1402 group_case_labels (void)
1288 { 1403 {
1289 basic_block bb; 1404 basic_block bb;
1290 1405
1291 FOR_EACH_BB (bb) 1406 FOR_EACH_BB (bb)
1292 { 1407 {
1293 gimple stmt = last_stmt (bb); 1408 gimple stmt = last_stmt (bb);
1294 if (stmt && gimple_code (stmt) == GIMPLE_SWITCH) 1409 if (stmt && gimple_code (stmt) == GIMPLE_SWITCH)
1295 { 1410 group_case_labels_stmt (stmt);
1296 int old_size = gimple_switch_num_labels (stmt);
1297 int i, j, new_size = old_size;
1298 tree default_case = NULL_TREE;
1299 tree default_label = NULL_TREE;
1300 bool has_default;
1301
1302 /* The default label is always the first case in a switch
1303 statement after gimplification if it was not optimized
1304 away */
1305 if (!CASE_LOW (gimple_switch_default_label (stmt))
1306 && !CASE_HIGH (gimple_switch_default_label (stmt)))
1307 {
1308 default_case = gimple_switch_default_label (stmt);
1309 default_label = CASE_LABEL (default_case);
1310 has_default = true;
1311 }
1312 else
1313 has_default = false;
1314
1315 /* Look for possible opportunities to merge cases. */
1316 if (has_default)
1317 i = 1;
1318 else
1319 i = 0;
1320 while (i < old_size)
1321 {
1322 tree base_case, base_label, base_high;
1323 base_case = gimple_switch_label (stmt, i);
1324
1325 gcc_assert (base_case);
1326 base_label = CASE_LABEL (base_case);
1327
1328 /* Discard cases that have the same destination as the
1329 default case. */
1330 if (base_label == default_label)
1331 {
1332 gimple_switch_set_label (stmt, i, NULL_TREE);
1333 i++;
1334 new_size--;
1335 continue;
1336 }
1337
1338 base_high = CASE_HIGH (base_case)
1339 ? CASE_HIGH (base_case)
1340 : CASE_LOW (base_case);
1341 i++;
1342
1343 /* Try to merge case labels. Break out when we reach the end
1344 of the label vector or when we cannot merge the next case
1345 label with the current one. */
1346 while (i < old_size)
1347 {
1348 tree merge_case = gimple_switch_label (stmt, i);
1349 tree merge_label = CASE_LABEL (merge_case);
1350 tree t = int_const_binop (PLUS_EXPR, base_high,
1351 integer_one_node, 1);
1352
1353 /* Merge the cases if they jump to the same place,
1354 and their ranges are consecutive. */
1355 if (merge_label == base_label
1356 && tree_int_cst_equal (CASE_LOW (merge_case), t))
1357 {
1358 base_high = CASE_HIGH (merge_case) ?
1359 CASE_HIGH (merge_case) : CASE_LOW (merge_case);
1360 CASE_HIGH (base_case) = base_high;
1361 gimple_switch_set_label (stmt, i, NULL_TREE);
1362 new_size--;
1363 i++;
1364 }
1365 else
1366 break;
1367 }
1368 }
1369
1370 /* Compress the case labels in the label vector, and adjust the
1371 length of the vector. */
1372 for (i = 0, j = 0; i < new_size; i++)
1373 {
1374 while (! gimple_switch_label (stmt, j))
1375 j++;
1376 gimple_switch_set_label (stmt, i,
1377 gimple_switch_label (stmt, j++));
1378 }
1379
1380 gcc_assert (new_size <= old_size);
1381 gimple_switch_set_num_labels (stmt, new_size);
1382 }
1383 } 1411 }
1384 } 1412 }
1385 1413
1386 /* Checks whether we can merge block B into block A. */ 1414 /* Checks whether we can merge block B into block A. */
1387 1415
1436 /* Protect the loop latches. */ 1464 /* Protect the loop latches. */
1437 if (current_loops && b->loop_father->latch == b) 1465 if (current_loops && b->loop_father->latch == b)
1438 return false; 1466 return false;
1439 1467
1440 /* It must be possible to eliminate all phi nodes in B. If ssa form 1468 /* It must be possible to eliminate all phi nodes in B. If ssa form
1441 is not up-to-date, we cannot eliminate any phis; however, if only 1469 is not up-to-date and a name-mapping is registered, we cannot eliminate
1442 some symbols as whole are marked for renaming, this is not a problem, 1470 any phis. Symbols marked for renaming are never a problem though. */
1443 as phi nodes for those symbols are irrelevant in updating anyway. */
1444 phis = phi_nodes (b); 1471 phis = phi_nodes (b);
1445 if (!gimple_seq_empty_p (phis)) 1472 if (!gimple_seq_empty_p (phis)
1446 { 1473 && name_mappings_registered_p ())
1447 gimple_stmt_iterator i; 1474 return false;
1448
1449 if (name_mappings_registered_p ())
1450 return false;
1451
1452 for (i = gsi_start (phis); !gsi_end_p (i); gsi_next (&i))
1453 {
1454 gimple phi = gsi_stmt (i);
1455
1456 if (!is_gimple_reg (gimple_phi_result (phi))
1457 && !may_propagate_copy (gimple_phi_result (phi),
1458 gimple_phi_arg_def (phi, 0)))
1459 return false;
1460 }
1461 }
1462 1475
1463 return true; 1476 return true;
1464 } 1477 }
1465 1478
1466 /* Return true if the var whose chain of uses starts at PTR has no 1479 /* Return true if the var whose chain of uses starts at PTR has no
1630 gimple stmt; 1643 gimple stmt;
1631 1644
1632 FOR_EACH_IMM_USE_STMT (stmt, iter, def) 1645 FOR_EACH_IMM_USE_STMT (stmt, iter, def)
1633 FOR_EACH_IMM_USE_ON_STMT (use_p, iter) 1646 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
1634 SET_USE (use_p, use); 1647 SET_USE (use_p, use);
1648
1649 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
1650 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (use) = 1;
1635 } 1651 }
1636 else 1652 else
1637 replace_uses_by (def, use); 1653 replace_uses_by (def, use);
1638 1654
1639 remove_phi_node (&psi, true); 1655 remove_phi_node (&psi, true);
1758 1774
1759 static void 1775 static void
1760 remove_bb (basic_block bb) 1776 remove_bb (basic_block bb)
1761 { 1777 {
1762 gimple_stmt_iterator i; 1778 gimple_stmt_iterator i;
1763 source_location loc = UNKNOWN_LOCATION;
1764 1779
1765 if (dump_file) 1780 if (dump_file)
1766 { 1781 {
1767 fprintf (dump_file, "Removing basic block %d\n", bb->index); 1782 fprintf (dump_file, "Removing basic block %d\n", bb->index);
1768 if (dump_flags & TDF_DETAILS) 1783 if (dump_flags & TDF_DETAILS)
1828 1843
1829 if (gsi_end_p (i)) 1844 if (gsi_end_p (i))
1830 i = gsi_last_bb (bb); 1845 i = gsi_last_bb (bb);
1831 else 1846 else
1832 gsi_prev (&i); 1847 gsi_prev (&i);
1833 1848 }
1834 /* Don't warn for removed gotos. Gotos are often removed due to 1849 }
1835 jump threading, thus resulting in bogus warnings. Not great,
1836 since this way we lose warnings for gotos in the original
1837 program that are indeed unreachable. */
1838 if (gimple_code (stmt) != GIMPLE_GOTO
1839 && gimple_has_location (stmt))
1840 loc = gimple_location (stmt);
1841 }
1842 }
1843
1844 /* If requested, give a warning that the first statement in the
1845 block is unreachable. We walk statements backwards in the
1846 loop above, so the last statement we process is the first statement
1847 in the block. */
1848 if (loc > BUILTINS_LOCATION && LOCATION_LINE (loc) > 0)
1849 warning_at (loc, OPT_Wunreachable_code, "will never be executed");
1850 1850
1851 remove_phi_nodes_and_edges_for_unreachable_block (bb); 1851 remove_phi_nodes_and_edges_for_unreachable_block (bb);
1852 bb->il.gimple = NULL; 1852 bb->il.gimple = NULL;
1853 } 1853 }
1854 1854
2244 function has nonlocal labels. */ 2244 function has nonlocal labels. */
2245 if (!(flags & (ECF_CONST | ECF_PURE)) && cfun->has_nonlocal_label) 2245 if (!(flags & (ECF_CONST | ECF_PURE)) && cfun->has_nonlocal_label)
2246 return true; 2246 return true;
2247 2247
2248 /* A call also alters control flow if it does not return. */ 2248 /* A call also alters control flow if it does not return. */
2249 if (gimple_call_flags (t) & ECF_NORETURN) 2249 if (flags & ECF_NORETURN)
2250 return true; 2250 return true;
2251 } 2251 }
2252 break; 2252 break;
2253 2253
2254 case GIMPLE_EH_DISPATCH: 2254 case GIMPLE_EH_DISPATCH:
2951 static bool 2951 static bool
2952 verify_gimple_call (gimple stmt) 2952 verify_gimple_call (gimple stmt)
2953 { 2953 {
2954 tree fn = gimple_call_fn (stmt); 2954 tree fn = gimple_call_fn (stmt);
2955 tree fntype; 2955 tree fntype;
2956 unsigned i;
2957
2958 if (TREE_CODE (fn) != OBJ_TYPE_REF
2959 && !is_gimple_val (fn))
2960 {
2961 error ("invalid function in gimple call");
2962 debug_generic_stmt (fn);
2963 return true;
2964 }
2956 2965
2957 if (!POINTER_TYPE_P (TREE_TYPE (fn)) 2966 if (!POINTER_TYPE_P (TREE_TYPE (fn))
2958 || (TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != FUNCTION_TYPE 2967 || (TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != FUNCTION_TYPE
2959 && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != METHOD_TYPE)) 2968 && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != METHOD_TYPE))
2960 { 2969 {
2965 if (gimple_call_lhs (stmt) 2974 if (gimple_call_lhs (stmt)
2966 && (!is_gimple_lvalue (gimple_call_lhs (stmt)) 2975 && (!is_gimple_lvalue (gimple_call_lhs (stmt))
2967 || verify_types_in_gimple_reference (gimple_call_lhs (stmt), true))) 2976 || verify_types_in_gimple_reference (gimple_call_lhs (stmt), true)))
2968 { 2977 {
2969 error ("invalid LHS in gimple call"); 2978 error ("invalid LHS in gimple call");
2979 return true;
2980 }
2981
2982 if (gimple_call_lhs (stmt) && gimple_call_noreturn_p (stmt))
2983 {
2984 error ("LHS in noreturn call");
2970 return true; 2985 return true;
2971 } 2986 }
2972 2987
2973 fntype = TREE_TYPE (TREE_TYPE (fn)); 2988 fntype = TREE_TYPE (TREE_TYPE (fn));
2974 if (gimple_call_lhs (stmt) 2989 if (gimple_call_lhs (stmt)
2986 debug_generic_stmt (TREE_TYPE (gimple_call_lhs (stmt))); 3001 debug_generic_stmt (TREE_TYPE (gimple_call_lhs (stmt)));
2987 debug_generic_stmt (TREE_TYPE (fntype)); 3002 debug_generic_stmt (TREE_TYPE (fntype));
2988 return true; 3003 return true;
2989 } 3004 }
2990 3005
3006 if (gimple_call_chain (stmt)
3007 && !is_gimple_val (gimple_call_chain (stmt)))
3008 {
3009 error ("invalid static chain in gimple call");
3010 debug_generic_stmt (gimple_call_chain (stmt));
3011 return true;
3012 }
3013
2991 /* If there is a static chain argument, this should not be an indirect 3014 /* If there is a static chain argument, this should not be an indirect
2992 call, and the decl should have DECL_STATIC_CHAIN set. */ 3015 call, and the decl should have DECL_STATIC_CHAIN set. */
2993 if (gimple_call_chain (stmt)) 3016 if (gimple_call_chain (stmt))
2994 { 3017 {
2995 if (TREE_CODE (fn) != ADDR_EXPR 3018 if (TREE_CODE (fn) != ADDR_EXPR
3007 } 3030 }
3008 } 3031 }
3009 3032
3010 /* ??? The C frontend passes unpromoted arguments in case it 3033 /* ??? The C frontend passes unpromoted arguments in case it
3011 didn't see a function declaration before the call. So for now 3034 didn't see a function declaration before the call. So for now
3012 leave the call arguments unverified. Once we gimplify 3035 leave the call arguments mostly unverified. Once we gimplify
3013 unit-at-a-time we have a chance to fix this. */ 3036 unit-at-a-time we have a chance to fix this. */
3037
3038 for (i = 0; i < gimple_call_num_args (stmt); ++i)
3039 {
3040 tree arg = gimple_call_arg (stmt, i);
3041 if (!is_gimple_operand (arg))
3042 {
3043 error ("invalid argument to gimple call");
3044 debug_generic_expr (arg);
3045 }
3046 }
3014 3047
3015 return false; 3048 return false;
3016 } 3049 }
3017 3050
3018 /* Verifies the gimple comparison with the result type TYPE and 3051 /* Verifies the gimple comparison with the result type TYPE and
3268 /* Shifts and rotates are ok on integral types, fixed point 3301 /* Shifts and rotates are ok on integral types, fixed point
3269 types and integer vector types. */ 3302 types and integer vector types. */
3270 if ((!INTEGRAL_TYPE_P (rhs1_type) 3303 if ((!INTEGRAL_TYPE_P (rhs1_type)
3271 && !FIXED_POINT_TYPE_P (rhs1_type) 3304 && !FIXED_POINT_TYPE_P (rhs1_type)
3272 && !(TREE_CODE (rhs1_type) == VECTOR_TYPE 3305 && !(TREE_CODE (rhs1_type) == VECTOR_TYPE
3273 && TREE_CODE (TREE_TYPE (rhs1_type)) == INTEGER_TYPE)) 3306 && INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))))
3274 || (!INTEGRAL_TYPE_P (rhs2_type) 3307 || (!INTEGRAL_TYPE_P (rhs2_type)
3275 /* Vector shifts of vectors are also ok. */ 3308 /* Vector shifts of vectors are also ok. */
3276 && !(TREE_CODE (rhs1_type) == VECTOR_TYPE 3309 && !(TREE_CODE (rhs1_type) == VECTOR_TYPE
3277 && TREE_CODE (TREE_TYPE (rhs1_type)) == INTEGER_TYPE 3310 && INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
3278 && TREE_CODE (rhs2_type) == VECTOR_TYPE 3311 && TREE_CODE (rhs2_type) == VECTOR_TYPE
3279 && TREE_CODE (TREE_TYPE (rhs2_type)) == INTEGER_TYPE)) 3312 && INTEGRAL_TYPE_P (TREE_TYPE (rhs2_type))))
3280 || !useless_type_conversion_p (lhs_type, rhs1_type)) 3313 || !useless_type_conversion_p (lhs_type, rhs1_type))
3281 { 3314 {
3282 error ("type mismatch in shift expression"); 3315 error ("type mismatch in shift expression");
3283 debug_generic_expr (lhs_type); 3316 debug_generic_expr (lhs_type);
3284 debug_generic_expr (rhs1_type); 3317 debug_generic_expr (rhs1_type);
3420 case LTGT_EXPR: 3453 case LTGT_EXPR:
3421 /* Comparisons are also binary, but the result type is not 3454 /* Comparisons are also binary, but the result type is not
3422 connected to the operand types. */ 3455 connected to the operand types. */
3423 return verify_gimple_comparison (lhs_type, rhs1, rhs2); 3456 return verify_gimple_comparison (lhs_type, rhs1, rhs2);
3424 3457
3458 case WIDEN_MULT_EXPR:
3459 if (TREE_CODE (lhs_type) != INTEGER_TYPE)
3460 return true;
3461 return ((2 * TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (lhs_type))
3462 || (TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type)));
3463
3425 case WIDEN_SUM_EXPR: 3464 case WIDEN_SUM_EXPR:
3426 case WIDEN_MULT_EXPR:
3427 case VEC_WIDEN_MULT_HI_EXPR: 3465 case VEC_WIDEN_MULT_HI_EXPR:
3428 case VEC_WIDEN_MULT_LO_EXPR: 3466 case VEC_WIDEN_MULT_LO_EXPR:
3429 case VEC_PACK_TRUNC_EXPR: 3467 case VEC_PACK_TRUNC_EXPR:
3430 case VEC_PACK_SAT_EXPR: 3468 case VEC_PACK_SAT_EXPR:
3431 case VEC_PACK_FIX_TRUNC_EXPR: 3469 case VEC_PACK_FIX_TRUNC_EXPR:
3758 3796
3759 case GIMPLE_CALL: 3797 case GIMPLE_CALL:
3760 return verify_gimple_call (stmt); 3798 return verify_gimple_call (stmt);
3761 3799
3762 case GIMPLE_COND: 3800 case GIMPLE_COND:
3801 if (TREE_CODE_CLASS (gimple_cond_code (stmt)) != tcc_comparison)
3802 {
3803 error ("invalid comparison code in gimple cond");
3804 return true;
3805 }
3806 if (!(!gimple_cond_true_label (stmt)
3807 || TREE_CODE (gimple_cond_true_label (stmt)) == LABEL_DECL)
3808 || !(!gimple_cond_false_label (stmt)
3809 || TREE_CODE (gimple_cond_false_label (stmt)) == LABEL_DECL))
3810 {
3811 error ("invalid labels in gimple cond");
3812 return true;
3813 }
3814
3763 return verify_gimple_comparison (boolean_type_node, 3815 return verify_gimple_comparison (boolean_type_node,
3764 gimple_cond_lhs (stmt), 3816 gimple_cond_lhs (stmt),
3765 gimple_cond_rhs (stmt)); 3817 gimple_cond_rhs (stmt));
3766 3818
3767 case GIMPLE_GOTO: 3819 case GIMPLE_GOTO:
4229 4281
4230 label = gimple_label_label (stmt); 4282 label = gimple_label_label (stmt);
4231 if (prev_stmt && DECL_NONLOCAL (label)) 4283 if (prev_stmt && DECL_NONLOCAL (label))
4232 { 4284 {
4233 error ("nonlocal label "); 4285 error ("nonlocal label ");
4286 print_generic_expr (stderr, label, 0);
4287 fprintf (stderr, " is not first in a sequence of labels in bb %d",
4288 bb->index);
4289 err = 1;
4290 }
4291
4292 if (prev_stmt && EH_LANDING_PAD_NR (label) != 0)
4293 {
4294 error ("EH landing pad label ");
4234 print_generic_expr (stderr, label, 0); 4295 print_generic_expr (stderr, label, 0);
4235 fprintf (stderr, " is not first in a sequence of labels in bb %d", 4296 fprintf (stderr, " is not first in a sequence of labels in bb %d",
4236 bb->index); 4297 bb->index);
4237 err = 1; 4298 err = 1;
4238 } 4299 }
4659 tree cases2 = get_cases_for_edge (e2, stmt); 4720 tree cases2 = get_cases_for_edge (e2, stmt);
4660 4721
4661 TREE_CHAIN (last) = TREE_CHAIN (cases2); 4722 TREE_CHAIN (last) = TREE_CHAIN (cases2);
4662 TREE_CHAIN (cases2) = first; 4723 TREE_CHAIN (cases2) = first;
4663 } 4724 }
4725 bitmap_set_bit (touched_switch_bbs, gimple_bb (stmt)->index);
4664 } 4726 }
4665 else 4727 else
4666 { 4728 {
4667 size_t i, n = gimple_switch_num_labels (stmt); 4729 size_t i, n = gimple_switch_num_labels (stmt);
4668 4730
4883 FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS) 4945 FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS)
4884 create_new_def_for (DEF_FROM_PTR (def_p), copy, def_p); 4946 create_new_def_for (DEF_FROM_PTR (def_p), copy, def_p);
4885 } 4947 }
4886 4948
4887 return new_bb; 4949 return new_bb;
4888 }
4889
4890 /* Add phi arguments to the phi nodes in E_COPY->dest according to
4891 the phi arguments coming from the equivalent edge at
4892 the phi nodes of DEST. */
4893
4894 static void
4895 add_phi_args_after_redirect (edge e_copy, edge orig_e)
4896 {
4897 gimple_stmt_iterator psi, psi_copy;
4898 gimple phi, phi_copy;
4899 tree def;
4900
4901 for (psi = gsi_start_phis (orig_e->dest),
4902 psi_copy = gsi_start_phis (e_copy->dest);
4903 !gsi_end_p (psi);
4904 gsi_next (&psi), gsi_next (&psi_copy))
4905 {
4906
4907 phi = gsi_stmt (psi);
4908 phi_copy = gsi_stmt (psi_copy);
4909 def = PHI_ARG_DEF_FROM_EDGE (phi, orig_e);
4910 add_phi_arg (phi_copy, def, e_copy,
4911 gimple_phi_arg_location_from_edge (phi, orig_e));
4912 }
4913 } 4950 }
4914 4951
4915 /* Adds phi node arguments for edge E_COPY after basic block duplication. */ 4952 /* Adds phi node arguments for edge E_COPY after basic block duplication. */
4916 4953
4917 static void 4954 static void
5193 int total_freq = 0, exit_freq = 0; 5230 int total_freq = 0, exit_freq = 0;
5194 gcov_type total_count = 0, exit_count = 0; 5231 gcov_type total_count = 0, exit_count = 0;
5195 edge exits[2], nexits[2], e; 5232 edge exits[2], nexits[2], e;
5196 gimple_stmt_iterator gsi,gsi1; 5233 gimple_stmt_iterator gsi,gsi1;
5197 gimple cond_stmt; 5234 gimple cond_stmt;
5198 edge sorig, snew, orig_e; 5235 edge sorig, snew;
5199 basic_block exit_bb; 5236 basic_block exit_bb;
5200 edge_iterator ei; 5237 basic_block iters_bb;
5201 VEC (edge, heap) *redirect_edges;
5202 basic_block iters_bb, orig_src;
5203 tree new_rhs; 5238 tree new_rhs;
5239 gimple_stmt_iterator psi;
5240 gimple phi;
5241 tree def;
5204 5242
5205 gcc_assert (EDGE_COUNT (exit->src->succs) == 2); 5243 gcc_assert (EDGE_COUNT (exit->src->succs) == 2);
5206 exits[0] = exit; 5244 exits[0] = exit;
5207 exits[1] = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit); 5245 exits[1] = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
5208 5246
5209 if (!can_copy_bbs_p (region, n_region)) 5247 if (!can_copy_bbs_p (region, n_region))
5210 return false; 5248 return false;
5211
5212 /* Some sanity checking. Note that we do not check for all possible
5213 missuses of the functions. I.e. if you ask to copy something weird
5214 (e.g., in the example, if there is a jump from inside to the middle
5215 of some_code, or come_code defines some of the values used in cond)
5216 it will work, but the resulting code will not be correct. */
5217 for (i = 0; i < n_region; i++)
5218 {
5219 if (region[i] == orig_loop->latch)
5220 return false;
5221 }
5222 5249
5223 initialize_original_copy_tables (); 5250 initialize_original_copy_tables ();
5224 set_loop_copy (orig_loop, loop); 5251 set_loop_copy (orig_loop, loop);
5225 duplicate_subloops (orig_loop, loop); 5252 duplicate_subloops (orig_loop, loop);
5226 5253
5335 exit_bb = exit->dest; 5362 exit_bb = exit->dest;
5336 5363
5337 e = redirect_edge_and_branch (exits[0], exits[1]->dest); 5364 e = redirect_edge_and_branch (exits[0], exits[1]->dest);
5338 PENDING_STMT (e) = NULL; 5365 PENDING_STMT (e) = NULL;
5339 5366
5340 /* If the block consisting of the exit condition has the latch as 5367 /* The latch of ORIG_LOOP was copied, and so was the backedge
5341 successor, then the body of the loop is executed before 5368 to the original header. We redirect this backedge to EXIT_BB. */
5342 the exit condition is tested. 5369 for (i = 0; i < n_region; i++)
5343 5370 if (get_bb_original (region_copy[i]) == orig_loop->latch)
5344 { body } 5371 {
5345 { cond } (exit[0]) -> { latch } 5372 gcc_assert (single_succ_edge (region_copy[i]));
5346 | 5373 e = redirect_edge_and_branch (single_succ_edge (region_copy[i]), exit_bb);
5347 V (exit[1]) 5374 PENDING_STMT (e) = NULL;
5348 5375 for (psi = gsi_start_phis (exit_bb);
5349 { exit_bb } 5376 !gsi_end_p (psi);
5350 5377 gsi_next (&psi))
5351 5378 {
5352 In such case, the equivalent copied edge nexits[1] 5379 phi = gsi_stmt (psi);
5353 (for the peeled iteration) needs to be redirected to exit_bb. 5380 def = PHI_ARG_DEF (phi, nexits[0]->dest_idx);
5354 5381 add_phi_arg (phi, def, e, gimple_phi_arg_location_from_edge (phi, e));
5355 Otherwise, 5382 }
5356 5383 }
5357 { cond } (exit[0]) -> { body } 5384 e = redirect_edge_and_branch (nexits[0], nexits[1]->dest);
5358 |
5359 V (exit[1])
5360
5361 { exit_bb }
5362
5363
5364 exit[0] is pointing to the body of the loop,
5365 and the equivalent nexits[0] needs to be redirected to
5366 the copied body (of the peeled iteration). */
5367
5368 if (exits[1]->dest == orig_loop->latch)
5369 e = redirect_edge_and_branch (nexits[1], nexits[0]->dest);
5370 else
5371 e = redirect_edge_and_branch (nexits[0], nexits[1]->dest);
5372 PENDING_STMT (e) = NULL; 5385 PENDING_STMT (e) = NULL;
5373 5386
5374 redirect_edges = VEC_alloc (edge, heap, 10);
5375
5376 for (i = 0; i < n_region; i++)
5377 region_copy[i]->flags |= BB_DUPLICATED;
5378
5379 /* Iterate all incoming edges to latch. All those coming from
5380 copied bbs will be redirected to exit_bb. */
5381 FOR_EACH_EDGE (e, ei, orig_loop->latch->preds)
5382 {
5383 if (e->src->flags & BB_DUPLICATED)
5384 VEC_safe_push (edge, heap, redirect_edges, e);
5385 }
5386
5387 for (i = 0; i < n_region; i++)
5388 region_copy[i]->flags &= ~BB_DUPLICATED;
5389
5390 for (i = 0; VEC_iterate (edge, redirect_edges, i, e); ++i)
5391 {
5392 e = redirect_edge_and_branch (e, exit_bb);
5393 PENDING_STMT (e) = NULL;
5394 orig_src = get_bb_original (e->src);
5395 orig_e = find_edge (orig_src, orig_loop->latch);
5396 add_phi_args_after_redirect (e, orig_e);
5397 }
5398
5399 VEC_free (edge, heap, redirect_edges);
5400
5401 /* Anything that is outside of the region, but was dominated by something 5387 /* Anything that is outside of the region, but was dominated by something
5402 inside needs to update dominance info. */ 5388 inside needs to update dominance info. */
5403 iterate_fix_dominators (CDI_DOMINATORS, doms, false); 5389 iterate_fix_dominators (CDI_DOMINATORS, doms, false);
5404 VEC_free (basic_block, heap, doms); 5390 VEC_free (basic_block, heap, doms);
5405
5406 /* Update the SSA web. */ 5391 /* Update the SSA web. */
5407 update_ssa (TODO_update_ssa); 5392 update_ssa (TODO_update_ssa);
5408 5393
5409 if (free_region_copy) 5394 if (free_region_copy)
5410 free (region_copy); 5395 free (region_copy);
6895 static void 6880 static void
6896 gimple_execute_on_growing_pred (edge e) 6881 gimple_execute_on_growing_pred (edge e)
6897 { 6882 {
6898 basic_block bb = e->dest; 6883 basic_block bb = e->dest;
6899 6884
6900 if (phi_nodes (bb)) 6885 if (!gimple_seq_empty_p (phi_nodes (bb)))
6901 reserve_phi_args_for_new_edge (bb); 6886 reserve_phi_args_for_new_edge (bb);
6902 } 6887 }
6903 6888
6904 /* This function is called immediately before edge E is removed from 6889 /* This function is called immediately before edge E is removed from
6905 the edge vector E->dest->preds. */ 6890 the edge vector E->dest->preds. */
6906 6891
6907 static void 6892 static void
6908 gimple_execute_on_shrinking_pred (edge e) 6893 gimple_execute_on_shrinking_pred (edge e)
6909 { 6894 {
6910 if (phi_nodes (e->dest)) 6895 if (!gimple_seq_empty_p (phi_nodes (e->dest)))
6911 remove_phi_args (e); 6896 remove_phi_args (e);
6912 } 6897 }
6913 6898
6914 /*--------------------------------------------------------------------------- 6899 /*---------------------------------------------------------------------------
6915 Helper functions for Loop versioning 6900 Helper functions for Loop versioning