Mercurial > hg > CbC > CbC_gcc
comparison gcc/stmt.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 "insn-config.h" | 39 #include "insn-config.h" |
40 #include "expr.h" | 40 #include "expr.h" |
41 #include "libfuncs.h" | 41 #include "libfuncs.h" |
42 #include "recog.h" | 42 #include "recog.h" |
43 #include "machmode.h" | 43 #include "machmode.h" |
44 #include "toplev.h" | 44 #include "diagnostic-core.h" |
45 #include "output.h" | 45 #include "output.h" |
46 #include "ggc.h" | 46 #include "ggc.h" |
47 #include "langhooks.h" | 47 #include "langhooks.h" |
48 #include "predict.h" | 48 #include "predict.h" |
49 #include "optabs.h" | 49 #include "optabs.h" |
684 nclobbers = 0; | 684 nclobbers = 0; |
685 CLEAR_HARD_REG_SET (clobbered_regs); | 685 CLEAR_HARD_REG_SET (clobbered_regs); |
686 for (tail = clobbers; tail; tail = TREE_CHAIN (tail)) | 686 for (tail = clobbers; tail; tail = TREE_CHAIN (tail)) |
687 { | 687 { |
688 const char *regname; | 688 const char *regname; |
689 int nregs; | |
689 | 690 |
690 if (TREE_VALUE (tail) == error_mark_node) | 691 if (TREE_VALUE (tail) == error_mark_node) |
691 return; | 692 return; |
692 regname = TREE_STRING_POINTER (TREE_VALUE (tail)); | 693 regname = TREE_STRING_POINTER (TREE_VALUE (tail)); |
693 | 694 |
694 i = decode_reg_name (regname); | 695 i = decode_reg_name_and_count (regname, &nregs); |
695 if (i >= 0 || i == -4) | 696 if (i == -4) |
696 ++nclobbers; | 697 ++nclobbers; |
697 else if (i == -2) | 698 else if (i == -2) |
698 error ("unknown register name %qs in %<asm%>", regname); | 699 error ("unknown register name %qs in %<asm%>", regname); |
699 | 700 |
700 /* Mark clobbered registers. */ | 701 /* Mark clobbered registers. */ |
701 if (i >= 0) | 702 if (i >= 0) |
702 { | 703 { |
703 /* Clobbering the PIC register is an error. */ | 704 int reg; |
704 if (i == (int) PIC_OFFSET_TABLE_REGNUM) | 705 |
706 for (reg = i; reg < i + nregs; reg++) | |
705 { | 707 { |
706 error ("PIC register %qs clobbered in %<asm%>", regname); | 708 ++nclobbers; |
707 return; | 709 |
710 /* Clobbering the PIC register is an error. */ | |
711 if (reg == (int) PIC_OFFSET_TABLE_REGNUM) | |
712 { | |
713 error ("PIC register clobbered by %qs in %<asm%>", regname); | |
714 return; | |
715 } | |
716 | |
717 SET_HARD_REG_BIT (clobbered_regs, reg); | |
708 } | 718 } |
709 | |
710 SET_HARD_REG_BIT (clobbered_regs, i); | |
711 } | 719 } |
712 } | 720 } |
713 | 721 |
714 /* First pass over inputs and outputs checks validity and sets | 722 /* First pass over inputs and outputs checks validity and sets |
715 mark_addressable if needed. */ | 723 mark_addressable if needed. */ |
772 if (! allows_reg && allows_mem) | 780 if (! allows_reg && allows_mem) |
773 mark_addressable (TREE_VALUE (tail)); | 781 mark_addressable (TREE_VALUE (tail)); |
774 } | 782 } |
775 | 783 |
776 /* Second pass evaluates arguments. */ | 784 /* Second pass evaluates arguments. */ |
785 | |
786 /* Make sure stack is consistent for asm goto. */ | |
787 if (nlabels > 0) | |
788 do_pending_stack_adjust (); | |
777 | 789 |
778 ninout = 0; | 790 ninout = 0; |
779 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) | 791 for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++) |
780 { | 792 { |
781 tree val = TREE_VALUE (tail); | 793 tree val = TREE_VALUE (tail); |
1026 /* Store (clobber REG) for each clobbered register specified. */ | 1038 /* Store (clobber REG) for each clobbered register specified. */ |
1027 | 1039 |
1028 for (tail = clobbers; tail; tail = TREE_CHAIN (tail)) | 1040 for (tail = clobbers; tail; tail = TREE_CHAIN (tail)) |
1029 { | 1041 { |
1030 const char *regname = TREE_STRING_POINTER (TREE_VALUE (tail)); | 1042 const char *regname = TREE_STRING_POINTER (TREE_VALUE (tail)); |
1031 int j = decode_reg_name (regname); | 1043 int reg, nregs; |
1044 int j = decode_reg_name_and_count (regname, &nregs); | |
1032 rtx clobbered_reg; | 1045 rtx clobbered_reg; |
1033 | 1046 |
1034 if (j < 0) | 1047 if (j < 0) |
1035 { | 1048 { |
1036 if (j == -3) /* `cc', which is not a register */ | 1049 if (j == -3) /* `cc', which is not a register */ |
1048 | 1061 |
1049 /* Ignore unknown register, error already signaled. */ | 1062 /* Ignore unknown register, error already signaled. */ |
1050 continue; | 1063 continue; |
1051 } | 1064 } |
1052 | 1065 |
1053 /* Use QImode since that's guaranteed to clobber just one reg. */ | 1066 for (reg = j; reg < j + nregs; reg++) |
1054 clobbered_reg = gen_rtx_REG (QImode, j); | |
1055 | |
1056 /* Do sanity check for overlap between clobbers and respectively | |
1057 input and outputs that hasn't been handled. Such overlap | |
1058 should have been detected and reported above. */ | |
1059 if (!clobber_conflict_found) | |
1060 { | 1067 { |
1061 int opno; | 1068 /* Use QImode since that's guaranteed to clobber just |
1062 | 1069 * one reg. */ |
1063 /* We test the old body (obody) contents to avoid tripping | 1070 clobbered_reg = gen_rtx_REG (QImode, reg); |
1064 over the under-construction body. */ | 1071 |
1065 for (opno = 0; opno < noutputs; opno++) | 1072 /* Do sanity check for overlap between clobbers and |
1066 if (reg_overlap_mentioned_p (clobbered_reg, output_rtx[opno])) | 1073 respectively input and outputs that hasn't been |
1067 internal_error ("asm clobber conflict with output operand"); | 1074 handled. Such overlap should have been detected and |
1068 | 1075 reported above. */ |
1069 for (opno = 0; opno < ninputs - ninout; opno++) | 1076 if (!clobber_conflict_found) |
1070 if (reg_overlap_mentioned_p (clobbered_reg, | 1077 { |
1071 ASM_OPERANDS_INPUT (obody, opno))) | 1078 int opno; |
1072 internal_error ("asm clobber conflict with input operand"); | 1079 |
1080 /* We test the old body (obody) contents to avoid | |
1081 tripping over the under-construction body. */ | |
1082 for (opno = 0; opno < noutputs; opno++) | |
1083 if (reg_overlap_mentioned_p (clobbered_reg, | |
1084 output_rtx[opno])) | |
1085 internal_error | |
1086 ("asm clobber conflict with output operand"); | |
1087 | |
1088 for (opno = 0; opno < ninputs - ninout; opno++) | |
1089 if (reg_overlap_mentioned_p (clobbered_reg, | |
1090 ASM_OPERANDS_INPUT (obody, | |
1091 opno))) | |
1092 internal_error | |
1093 ("asm clobber conflict with input operand"); | |
1094 } | |
1095 | |
1096 XVECEXP (body, 0, i++) | |
1097 = gen_rtx_CLOBBER (VOIDmode, clobbered_reg); | |
1073 } | 1098 } |
1074 | |
1075 XVECEXP (body, 0, i++) | |
1076 = gen_rtx_CLOBBER (VOIDmode, clobbered_reg); | |
1077 } | 1099 } |
1078 | 1100 |
1079 if (nlabels > 0) | 1101 if (nlabels > 0) |
1080 emit_jump_insn (body); | 1102 emit_jump_insn (body); |
1081 else | 1103 else |
1317 break; | 1339 break; |
1318 else if (ISALPHA (c[1]) && c[2] == '[') | 1340 else if (ISALPHA (c[1]) && c[2] == '[') |
1319 break; | 1341 break; |
1320 else | 1342 else |
1321 { | 1343 { |
1322 c += 1; | 1344 c += 1 + (c[1] == '%'); |
1323 continue; | 1345 continue; |
1324 } | 1346 } |
1325 } | 1347 } |
1326 | 1348 |
1327 if (c) | 1349 if (c) |
1339 p += 1; | 1361 p += 1; |
1340 else if (ISALPHA (p[1]) && p[2] == '[') | 1362 else if (ISALPHA (p[1]) && p[2] == '[') |
1341 p += 2; | 1363 p += 2; |
1342 else | 1364 else |
1343 { | 1365 { |
1344 p += 1; | 1366 p += 1 + (p[1] == '%'); |
1345 continue; | 1367 continue; |
1346 } | 1368 } |
1347 | 1369 |
1348 p = resolve_operand_name_1 (p, outputs, inputs, labels); | 1370 p = resolve_operand_name_1 (p, outputs, inputs, labels); |
1349 } | 1371 } |
1592 { | 1614 { |
1593 tree funtype = TREE_TYPE (current_function_decl); | 1615 tree funtype = TREE_TYPE (current_function_decl); |
1594 tree type = TREE_TYPE (decl); | 1616 tree type = TREE_TYPE (decl); |
1595 int unsignedp = TYPE_UNSIGNED (type); | 1617 int unsignedp = TYPE_UNSIGNED (type); |
1596 enum machine_mode old_mode = DECL_MODE (decl); | 1618 enum machine_mode old_mode = DECL_MODE (decl); |
1597 enum machine_mode mode = promote_function_mode (type, old_mode, | 1619 enum machine_mode mode; |
1598 &unsignedp, funtype, 1); | 1620 if (DECL_BY_REFERENCE (decl)) |
1621 mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 2); | |
1622 else | |
1623 mode = promote_function_mode (type, old_mode, &unsignedp, funtype, 1); | |
1599 | 1624 |
1600 if (mode != old_mode) | 1625 if (mode != old_mode) |
1601 val = convert_modes (mode, old_mode, val, unsignedp); | 1626 val = convert_modes (mode, old_mode, val, unsignedp); |
1602 | 1627 |
1603 if (GET_CODE (return_reg) == PARALLEL) | 1628 if (GET_CODE (return_reg) == PARALLEL) |
1733 | 1758 |
1734 /* Use bitpos for the source extraction (left justified) and | 1759 /* Use bitpos for the source extraction (left justified) and |
1735 xbitpos for the destination store (right justified). */ | 1760 xbitpos for the destination store (right justified). */ |
1736 store_bit_field (dst, bitsize, xbitpos % BITS_PER_WORD, word_mode, | 1761 store_bit_field (dst, bitsize, xbitpos % BITS_PER_WORD, word_mode, |
1737 extract_bit_field (src, bitsize, | 1762 extract_bit_field (src, bitsize, |
1738 bitpos % BITS_PER_WORD, 1, | 1763 bitpos % BITS_PER_WORD, 1, false, |
1739 NULL_RTX, word_mode, word_mode)); | 1764 NULL_RTX, word_mode, word_mode)); |
1740 } | 1765 } |
1741 | 1766 |
1742 tmpmode = GET_MODE (result_rtl); | 1767 tmpmode = GET_MODE (result_rtl); |
1743 if (tmpmode == BLKmode) | 1768 if (tmpmode == BLKmode) |
1828 the original assignment true. | 1853 the original assignment true. |
1829 So the following insn will actually be | 1854 So the following insn will actually be |
1830 decrementing fp by STARTING_FRAME_OFFSET. */ | 1855 decrementing fp by STARTING_FRAME_OFFSET. */ |
1831 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx); | 1856 emit_move_insn (virtual_stack_vars_rtx, hard_frame_pointer_rtx); |
1832 | 1857 |
1833 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM | 1858 #if !HARD_FRAME_POINTER_IS_ARG_POINTER |
1834 if (fixed_regs[ARG_POINTER_REGNUM]) | 1859 if (fixed_regs[ARG_POINTER_REGNUM]) |
1835 { | 1860 { |
1836 #ifdef ELIMINABLE_REGS | 1861 #ifdef ELIMINABLE_REGS |
1837 /* If the argument pointer can be eliminated in favor of the | 1862 /* If the argument pointer can be eliminated in favor of the |
1838 frame pointer, we don't need to restore it. We assume here | 1863 frame pointer, we don't need to restore it. We assume here |
1979 expand_stack_save (void) | 2004 expand_stack_save (void) |
1980 { | 2005 { |
1981 rtx ret = NULL_RTX; | 2006 rtx ret = NULL_RTX; |
1982 | 2007 |
1983 do_pending_stack_adjust (); | 2008 do_pending_stack_adjust (); |
1984 emit_stack_save (SAVE_BLOCK, &ret, NULL_RTX); | 2009 emit_stack_save (SAVE_BLOCK, &ret); |
1985 return ret; | 2010 return ret; |
1986 } | 2011 } |
1987 | 2012 |
1988 /* Emit code to restore the current value of stack. */ | 2013 /* Emit code to restore the current value of stack. */ |
1989 void | 2014 void |
1990 expand_stack_restore (tree var) | 2015 expand_stack_restore (tree var) |
1991 { | 2016 { |
1992 rtx sa = expand_normal (var); | 2017 rtx sa = expand_normal (var); |
1993 | 2018 |
1994 sa = convert_memory_address (Pmode, sa); | 2019 sa = convert_memory_address (Pmode, sa); |
1995 emit_stack_restore (SAVE_BLOCK, sa, NULL_RTX); | 2020 emit_stack_restore (SAVE_BLOCK, sa); |
1996 } | 2021 } |
1997 | 2022 |
1998 /* Do the insertion of a case label into case_list. The labels are | 2023 /* Do the insertion of a case label into case_list. The labels are |
1999 fed to us in descending order from the sorted vector of case labels used | 2024 fed to us in descending order from the sorted vector of case labels used |
2000 in the tree part of the middle end. So the list we construct is | 2025 in the tree part of the middle end. So the list we construct is |
2069 /* Maximum number of case bit tests. */ | 2094 /* Maximum number of case bit tests. */ |
2070 #define MAX_CASE_BIT_TESTS 3 | 2095 #define MAX_CASE_BIT_TESTS 3 |
2071 | 2096 |
2072 /* By default, enable case bit tests on targets with ashlsi3. */ | 2097 /* By default, enable case bit tests on targets with ashlsi3. */ |
2073 #ifndef CASE_USE_BIT_TESTS | 2098 #ifndef CASE_USE_BIT_TESTS |
2074 #define CASE_USE_BIT_TESTS (optab_handler (ashl_optab, word_mode)->insn_code \ | 2099 #define CASE_USE_BIT_TESTS (optab_handler (ashl_optab, word_mode) \ |
2075 != CODE_FOR_nothing) | 2100 != CODE_FOR_nothing) |
2076 #endif | 2101 #endif |
2077 | 2102 |
2078 | 2103 |
2079 /* A case_bit_test represents a set of case nodes that may be | 2104 /* A case_bit_test represents a set of case nodes that may be |
2094 /* Determine whether "1 << x" is relatively cheap in word_mode. */ | 2119 /* Determine whether "1 << x" is relatively cheap in word_mode. */ |
2095 | 2120 |
2096 static | 2121 static |
2097 bool lshift_cheap_p (void) | 2122 bool lshift_cheap_p (void) |
2098 { | 2123 { |
2099 static bool init = false; | 2124 static bool init[2] = {false, false}; |
2100 static bool cheap = true; | 2125 static bool cheap[2] = {true, true}; |
2101 | 2126 |
2102 if (!init) | 2127 bool speed_p = optimize_insn_for_speed_p (); |
2128 | |
2129 if (!init[speed_p]) | |
2103 { | 2130 { |
2104 rtx reg = gen_rtx_REG (word_mode, 10000); | 2131 rtx reg = gen_rtx_REG (word_mode, 10000); |
2105 int cost = rtx_cost (gen_rtx_ASHIFT (word_mode, const1_rtx, reg), SET, | 2132 int cost = rtx_cost (gen_rtx_ASHIFT (word_mode, const1_rtx, reg), SET, |
2106 optimize_insn_for_speed_p ()); | 2133 speed_p); |
2107 cheap = cost < COSTS_N_INSNS (3); | 2134 cheap[speed_p] = cost < COSTS_N_INSNS (3); |
2108 init = true; | 2135 init[speed_p] = true; |
2109 } | 2136 } |
2110 | 2137 |
2111 return cheap; | 2138 return cheap[speed_p]; |
2112 } | 2139 } |
2113 | 2140 |
2114 /* Comparison function for qsort to order bit tests by decreasing | 2141 /* Comparison function for qsort to order bit tests by decreasing |
2115 number of case nodes, i.e. the node with the most cases gets | 2142 number of case nodes, i.e. the node with the most cases gets |
2116 tested first. */ | 2143 tested first. */ |
2221 #endif | 2248 #endif |
2222 | 2249 |
2223 #ifndef HAVE_tablejump | 2250 #ifndef HAVE_tablejump |
2224 #define HAVE_tablejump 0 | 2251 #define HAVE_tablejump 0 |
2225 #endif | 2252 #endif |
2253 | |
2254 /* Return true if a switch should be expanded as a bit test. | |
2255 INDEX_EXPR is the index expression, RANGE is the difference between | |
2256 highest and lowest case, UNIQ is number of unique case node targets | |
2257 not counting the default case and COUNT is the number of comparisons | |
2258 needed, not counting the default case. */ | |
2259 bool | |
2260 expand_switch_using_bit_tests_p (tree index_expr, tree range, | |
2261 unsigned int uniq, unsigned int count) | |
2262 { | |
2263 return (CASE_USE_BIT_TESTS | |
2264 && ! TREE_CONSTANT (index_expr) | |
2265 && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0 | |
2266 && compare_tree_int (range, 0) > 0 | |
2267 && lshift_cheap_p () | |
2268 && ((uniq == 1 && count >= 3) | |
2269 || (uniq == 2 && count >= 5) | |
2270 || (uniq == 3 && count >= 6))); | |
2271 } | |
2226 | 2272 |
2227 /* Terminate a case (Pascal/Ada) or switch (C) statement | 2273 /* Terminate a case (Pascal/Ada) or switch (C) statement |
2228 in which ORIG_INDEX is the expression to be tested. | 2274 in which ORIG_INDEX is the expression to be tested. |
2229 If ORIG_TYPE is not NULL, it is the original ORIG_INDEX | 2275 If ORIG_TYPE is not NULL, it is the original ORIG_INDEX |
2230 type as given in the source before any compiler conversions. | 2276 type as given in the source before any compiler conversions. |
2332 count++; | 2378 count++; |
2333 | 2379 |
2334 /* If we have not seen this label yet, then increase the | 2380 /* If we have not seen this label yet, then increase the |
2335 number of unique case node targets seen. */ | 2381 number of unique case node targets seen. */ |
2336 lab = label_rtx (n->code_label); | 2382 lab = label_rtx (n->code_label); |
2337 if (!bitmap_bit_p (label_bitmap, CODE_LABEL_NUMBER (lab))) | 2383 if (bitmap_set_bit (label_bitmap, CODE_LABEL_NUMBER (lab))) |
2338 { | 2384 uniq++; |
2339 bitmap_set_bit (label_bitmap, CODE_LABEL_NUMBER (lab)); | |
2340 uniq++; | |
2341 } | |
2342 } | 2385 } |
2343 | 2386 |
2344 BITMAP_FREE (label_bitmap); | 2387 BITMAP_FREE (label_bitmap); |
2345 | 2388 |
2346 /* cleanup_tree_cfg removes all SWITCH_EXPR with a single | 2389 /* cleanup_tree_cfg removes all SWITCH_EXPR with a single |
2359 range = fold_build2 (MINUS_EXPR, index_type, maxval, minval); | 2402 range = fold_build2 (MINUS_EXPR, index_type, maxval, minval); |
2360 | 2403 |
2361 /* Try implementing this switch statement by a short sequence of | 2404 /* Try implementing this switch statement by a short sequence of |
2362 bit-wise comparisons. However, we let the binary-tree case | 2405 bit-wise comparisons. However, we let the binary-tree case |
2363 below handle constant index expressions. */ | 2406 below handle constant index expressions. */ |
2364 if (CASE_USE_BIT_TESTS | 2407 if (expand_switch_using_bit_tests_p (index_expr, range, uniq, count)) |
2365 && ! TREE_CONSTANT (index_expr) | |
2366 && compare_tree_int (range, GET_MODE_BITSIZE (word_mode)) < 0 | |
2367 && compare_tree_int (range, 0) > 0 | |
2368 && lshift_cheap_p () | |
2369 && ((uniq == 1 && count >= 3) | |
2370 || (uniq == 2 && count >= 5) | |
2371 || (uniq == 3 && count >= 6))) | |
2372 { | 2408 { |
2373 /* Optimize the case where all the case values fit in a | 2409 /* Optimize the case where all the case values fit in a |
2374 word without having to subtract MINVAL. In this case, | 2410 word without having to subtract MINVAL. In this case, |
2375 we can optimize away the subtraction. */ | 2411 we can optimize away the subtraction. */ |
2376 if (compare_tree_int (minval, 0) > 0 | 2412 if (compare_tree_int (minval, 0) > 0 |