Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa.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 /* Miscellaneous SSA utility functions. | 1 /* Miscellaneous SSA utility functions. |
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 | 2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
22 #include "system.h" | 22 #include "system.h" |
23 #include "coretypes.h" | 23 #include "coretypes.h" |
24 #include "tm.h" | 24 #include "tm.h" |
25 #include "tree.h" | 25 #include "tree.h" |
26 #include "flags.h" | 26 #include "flags.h" |
27 #include "rtl.h" | |
28 #include "tm_p.h" | 27 #include "tm_p.h" |
29 #include "target.h" | 28 #include "target.h" |
30 #include "ggc.h" | 29 #include "ggc.h" |
31 #include "langhooks.h" | 30 #include "langhooks.h" |
32 #include "hard-reg-set.h" | |
33 #include "basic-block.h" | 31 #include "basic-block.h" |
34 #include "output.h" | 32 #include "output.h" |
35 #include "expr.h" | 33 #include "expr.h" |
36 #include "function.h" | 34 #include "function.h" |
37 #include "diagnostic.h" | 35 #include "diagnostic.h" |
36 #include "tree-pretty-print.h" | |
37 #include "gimple-pretty-print.h" | |
38 #include "bitmap.h" | 38 #include "bitmap.h" |
39 #include "pointer-set.h" | 39 #include "pointer-set.h" |
40 #include "tree-flow.h" | 40 #include "tree-flow.h" |
41 #include "gimple.h" | 41 #include "gimple.h" |
42 #include "tree-inline.h" | 42 #include "tree-inline.h" |
43 #include "varray.h" | |
44 #include "timevar.h" | 43 #include "timevar.h" |
45 #include "hashtab.h" | 44 #include "hashtab.h" |
46 #include "tree-dump.h" | 45 #include "tree-dump.h" |
47 #include "tree-pass.h" | 46 #include "tree-pass.h" |
48 #include "toplev.h" | 47 #include "toplev.h" |
1121 fn->gimple_df->referenced_vars = htab_create_ggc (20, uid_decl_map_hash, | 1120 fn->gimple_df->referenced_vars = htab_create_ggc (20, uid_decl_map_hash, |
1122 uid_decl_map_eq, NULL); | 1121 uid_decl_map_eq, NULL); |
1123 fn->gimple_df->default_defs = htab_create_ggc (20, uid_ssaname_map_hash, | 1122 fn->gimple_df->default_defs = htab_create_ggc (20, uid_ssaname_map_hash, |
1124 uid_ssaname_map_eq, NULL); | 1123 uid_ssaname_map_eq, NULL); |
1125 pt_solution_reset (&fn->gimple_df->escaped); | 1124 pt_solution_reset (&fn->gimple_df->escaped); |
1126 pt_solution_reset (&fn->gimple_df->callused); | |
1127 init_ssanames (fn, 0); | 1125 init_ssanames (fn, 0); |
1128 init_phinodes (); | 1126 init_phinodes (); |
1129 } | 1127 } |
1130 | 1128 |
1131 | 1129 |
1161 delete_alias_heapvars (); | 1159 delete_alias_heapvars (); |
1162 | 1160 |
1163 htab_delete (cfun->gimple_df->default_defs); | 1161 htab_delete (cfun->gimple_df->default_defs); |
1164 cfun->gimple_df->default_defs = NULL; | 1162 cfun->gimple_df->default_defs = NULL; |
1165 pt_solution_reset (&cfun->gimple_df->escaped); | 1163 pt_solution_reset (&cfun->gimple_df->escaped); |
1166 pt_solution_reset (&cfun->gimple_df->callused); | |
1167 if (cfun->gimple_df->decls_to_pointers != NULL) | 1164 if (cfun->gimple_df->decls_to_pointers != NULL) |
1168 pointer_map_destroy (cfun->gimple_df->decls_to_pointers); | 1165 pointer_map_destroy (cfun->gimple_df->decls_to_pointers); |
1169 cfun->gimple_df->decls_to_pointers = NULL; | 1166 cfun->gimple_df->decls_to_pointers = NULL; |
1170 cfun->gimple_df->modified_noreturn_calls = NULL; | 1167 cfun->gimple_df->modified_noreturn_calls = NULL; |
1171 cfun->gimple_df = NULL; | 1168 cfun->gimple_df = NULL; |
1603 pointer_set_destroy (visited); | 1600 pointer_set_destroy (visited); |
1604 } | 1601 } |
1605 } | 1602 } |
1606 | 1603 |
1607 | 1604 |
1608 /* Return true if T, an SSA_NAME, has an undefined value. */ | |
1609 | |
1610 bool | |
1611 ssa_undefined_value_p (tree t) | |
1612 { | |
1613 tree var = SSA_NAME_VAR (t); | |
1614 | |
1615 /* Parameters get their initial value from the function entry. */ | |
1616 if (TREE_CODE (var) == PARM_DECL) | |
1617 return false; | |
1618 | |
1619 /* Hard register variables get their initial value from the ether. */ | |
1620 if (TREE_CODE (var) == VAR_DECL && DECL_HARD_REGISTER (var)) | |
1621 return false; | |
1622 | |
1623 /* The value is undefined iff its definition statement is empty. */ | |
1624 return gimple_nop_p (SSA_NAME_DEF_STMT (t)); | |
1625 } | |
1626 | |
1627 /* Emit warnings for uninitialized variables. This is done in two passes. | 1605 /* Emit warnings for uninitialized variables. This is done in two passes. |
1628 | 1606 |
1629 The first pass notices real uses of SSA names with undefined values. | 1607 The first pass notices real uses of SSA names with undefined values. |
1630 Such uses are unconditionally uninitialized, and we can be certain that | 1608 Such uses are unconditionally uninitialized, and we can be certain that |
1631 such a use is a mistake. This pass is run before most optimizations, | 1609 such a use is a mistake. This pass is run before most optimizations, |
1640 changed conditionally uninitialized to unconditionally uninitialized. */ | 1618 changed conditionally uninitialized to unconditionally uninitialized. */ |
1641 | 1619 |
1642 /* Emit a warning for T, an SSA_NAME, being uninitialized. The exact | 1620 /* Emit a warning for T, an SSA_NAME, being uninitialized. The exact |
1643 warning text is in MSGID and LOCUS may contain a location or be null. */ | 1621 warning text is in MSGID and LOCUS may contain a location or be null. */ |
1644 | 1622 |
1645 static void | 1623 void |
1646 warn_uninit (tree t, const char *gmsgid, void *data) | 1624 warn_uninit (tree t, const char *gmsgid, void *data) |
1647 { | 1625 { |
1648 tree var = SSA_NAME_VAR (t); | 1626 tree var = SSA_NAME_VAR (t); |
1649 gimple context = (gimple) data; | 1627 gimple context = (gimple) data; |
1650 location_t location; | 1628 location_t location; |
1770 } | 1748 } |
1771 | 1749 |
1772 return NULL_TREE; | 1750 return NULL_TREE; |
1773 } | 1751 } |
1774 | 1752 |
1775 /* Look for inputs to PHI that are SSA_NAMEs that have empty definitions | 1753 unsigned int |
1776 and warn about them. */ | |
1777 | |
1778 static void | |
1779 warn_uninitialized_phi (gimple phi) | |
1780 { | |
1781 size_t i, n = gimple_phi_num_args (phi); | |
1782 | |
1783 /* Don't look at memory tags. */ | |
1784 if (!is_gimple_reg (gimple_phi_result (phi))) | |
1785 return; | |
1786 | |
1787 for (i = 0; i < n; ++i) | |
1788 { | |
1789 tree op = gimple_phi_arg_def (phi, i); | |
1790 if (TREE_CODE (op) == SSA_NAME) | |
1791 warn_uninit (op, "%qD may be used uninitialized in this function", | |
1792 NULL); | |
1793 } | |
1794 } | |
1795 | |
1796 static unsigned int | |
1797 warn_uninitialized_vars (bool warn_possibly_uninitialized) | 1754 warn_uninitialized_vars (bool warn_possibly_uninitialized) |
1798 { | 1755 { |
1799 gimple_stmt_iterator gsi; | 1756 gimple_stmt_iterator gsi; |
1800 basic_block bb; | 1757 basic_block bb; |
1801 struct walk_data data; | 1758 struct walk_data data; |
1802 | 1759 |
1803 data.warn_possibly_uninitialized = warn_possibly_uninitialized; | 1760 data.warn_possibly_uninitialized = warn_possibly_uninitialized; |
1804 | 1761 |
1805 calculate_dominance_info (CDI_POST_DOMINATORS); | |
1806 | 1762 |
1807 FOR_EACH_BB (bb) | 1763 FOR_EACH_BB (bb) |
1808 { | 1764 { |
1809 data.always_executed = dominated_by_p (CDI_POST_DOMINATORS, | 1765 data.always_executed = dominated_by_p (CDI_POST_DOMINATORS, |
1810 single_succ (ENTRY_BLOCK_PTR), bb); | 1766 single_succ (ENTRY_BLOCK_PTR), bb); |
1818 wi.info = &data; | 1774 wi.info = &data; |
1819 walk_gimple_op (gsi_stmt (gsi), warn_uninitialized_var, &wi); | 1775 walk_gimple_op (gsi_stmt (gsi), warn_uninitialized_var, &wi); |
1820 } | 1776 } |
1821 } | 1777 } |
1822 | 1778 |
1823 /* Post-dominator information can not be reliably updated. Free it | |
1824 after the use. */ | |
1825 | |
1826 free_dominance_info (CDI_POST_DOMINATORS); | |
1827 return 0; | 1779 return 0; |
1828 } | 1780 } |
1829 | 1781 |
1830 static unsigned int | 1782 static unsigned int |
1831 execute_early_warn_uninitialized (void) | 1783 execute_early_warn_uninitialized (void) |
1834 execute_late_warn_uninitialized only runs with optimization. With | 1786 execute_late_warn_uninitialized only runs with optimization. With |
1835 optimization we want to warn about possible uninitialized as late | 1787 optimization we want to warn about possible uninitialized as late |
1836 as possible, thus don't do it here. However, without | 1788 as possible, thus don't do it here. However, without |
1837 optimization we need to warn here about "may be uninitialized". | 1789 optimization we need to warn here about "may be uninitialized". |
1838 */ | 1790 */ |
1791 calculate_dominance_info (CDI_POST_DOMINATORS); | |
1792 | |
1839 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize); | 1793 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/!optimize); |
1840 return 0; | 1794 |
1841 } | 1795 /* Post-dominator information can not be reliably updated. Free it |
1842 | 1796 after the use. */ |
1843 static unsigned int | 1797 |
1844 execute_late_warn_uninitialized (void) | 1798 free_dominance_info (CDI_POST_DOMINATORS); |
1845 { | |
1846 basic_block bb; | |
1847 gimple_stmt_iterator gsi; | |
1848 | |
1849 /* Re-do the plain uninitialized variable check, as optimization may have | |
1850 straightened control flow. Do this first so that we don't accidentally | |
1851 get a "may be" warning when we'd have seen an "is" warning later. */ | |
1852 warn_uninitialized_vars (/*warn_possibly_uninitialized=*/1); | |
1853 | |
1854 FOR_EACH_BB (bb) | |
1855 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi)) | |
1856 warn_uninitialized_phi (gsi_stmt (gsi)); | |
1857 | |
1858 return 0; | 1799 return 0; |
1859 } | 1800 } |
1860 | 1801 |
1861 static bool | 1802 static bool |
1862 gate_warn_uninitialized (void) | 1803 gate_warn_uninitialized (void) |
1869 { | 1810 { |
1870 GIMPLE_PASS, | 1811 GIMPLE_PASS, |
1871 "*early_warn_uninitialized", /* name */ | 1812 "*early_warn_uninitialized", /* name */ |
1872 gate_warn_uninitialized, /* gate */ | 1813 gate_warn_uninitialized, /* gate */ |
1873 execute_early_warn_uninitialized, /* execute */ | 1814 execute_early_warn_uninitialized, /* execute */ |
1874 NULL, /* sub */ | |
1875 NULL, /* next */ | |
1876 0, /* static_pass_number */ | |
1877 TV_NONE, /* tv_id */ | |
1878 PROP_ssa, /* properties_required */ | |
1879 0, /* properties_provided */ | |
1880 0, /* properties_destroyed */ | |
1881 0, /* todo_flags_start */ | |
1882 0 /* todo_flags_finish */ | |
1883 } | |
1884 }; | |
1885 | |
1886 struct gimple_opt_pass pass_late_warn_uninitialized = | |
1887 { | |
1888 { | |
1889 GIMPLE_PASS, | |
1890 "*late_warn_uninitialized", /* name */ | |
1891 gate_warn_uninitialized, /* gate */ | |
1892 execute_late_warn_uninitialized, /* execute */ | |
1893 NULL, /* sub */ | 1815 NULL, /* sub */ |
1894 NULL, /* next */ | 1816 NULL, /* next */ |
1895 0, /* static_pass_number */ | 1817 0, /* static_pass_number */ |
1896 TV_NONE, /* tv_id */ | 1818 TV_NONE, /* tv_id */ |
1897 PROP_ssa, /* properties_required */ | 1819 PROP_ssa, /* properties_required */ |