Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-ssa-ccp.c @ 47:3bfb6c00c1e0
update it from 4.4.2 to 4.4.3.
author | kent <kent@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 07 Feb 2010 17:44:34 +0900 |
parents | 58ad6c70ea60 |
children | 77e2b8dfacca |
comparison
equal
deleted
inserted
replaced
46:b85a337e5837 | 47:3bfb6c00c1e0 |
---|---|
1725 BASE is a record type. OFFSET is a byte displacement. ORIG_TYPE | 1725 BASE is a record type. OFFSET is a byte displacement. ORIG_TYPE |
1726 is the desired result type. */ | 1726 is the desired result type. */ |
1727 | 1727 |
1728 static tree | 1728 static tree |
1729 maybe_fold_offset_to_component_ref (tree record_type, tree base, tree offset, | 1729 maybe_fold_offset_to_component_ref (tree record_type, tree base, tree offset, |
1730 tree orig_type, bool base_is_ptr) | 1730 tree orig_type) |
1731 { | 1731 { |
1732 tree f, t, field_type, tail_array_field, field_offset; | 1732 tree f, t, field_type, tail_array_field, field_offset; |
1733 tree ret; | 1733 tree ret; |
1734 tree new_base; | 1734 tree new_base; |
1735 | 1735 |
1777 /* Here we exactly match the offset being checked. If the types match, | 1777 /* Here we exactly match the offset being checked. If the types match, |
1778 then we can return that field. */ | 1778 then we can return that field. */ |
1779 if (cmp == 0 | 1779 if (cmp == 0 |
1780 && useless_type_conversion_p (orig_type, field_type)) | 1780 && useless_type_conversion_p (orig_type, field_type)) |
1781 { | 1781 { |
1782 if (base_is_ptr) | |
1783 base = build1 (INDIRECT_REF, record_type, base); | |
1784 t = build3 (COMPONENT_REF, field_type, base, f, NULL_TREE); | 1782 t = build3 (COMPONENT_REF, field_type, base, f, NULL_TREE); |
1785 return t; | 1783 return t; |
1786 } | 1784 } |
1787 | 1785 |
1788 /* Don't care about offsets into the middle of scalars. */ | 1786 /* Don't care about offsets into the middle of scalars. */ |
1803 if (!tree_int_cst_lt (t, DECL_SIZE_UNIT (f))) | 1801 if (!tree_int_cst_lt (t, DECL_SIZE_UNIT (f))) |
1804 continue; | 1802 continue; |
1805 | 1803 |
1806 /* If we matched, then set offset to the displacement into | 1804 /* If we matched, then set offset to the displacement into |
1807 this field. */ | 1805 this field. */ |
1808 if (base_is_ptr) | 1806 new_base = build3 (COMPONENT_REF, field_type, base, f, NULL_TREE); |
1809 new_base = build1 (INDIRECT_REF, record_type, base); | |
1810 else | |
1811 new_base = base; | |
1812 new_base = build3 (COMPONENT_REF, field_type, new_base, f, NULL_TREE); | |
1813 | 1807 |
1814 /* Recurse to possibly find the match. */ | 1808 /* Recurse to possibly find the match. */ |
1815 ret = maybe_fold_offset_to_array_ref (new_base, t, orig_type, | 1809 ret = maybe_fold_offset_to_array_ref (new_base, t, orig_type, |
1816 f == TYPE_FIELDS (record_type)); | 1810 f == TYPE_FIELDS (record_type)); |
1817 if (ret) | 1811 if (ret) |
1818 return ret; | 1812 return ret; |
1819 ret = maybe_fold_offset_to_component_ref (field_type, new_base, t, | 1813 ret = maybe_fold_offset_to_component_ref (field_type, new_base, t, |
1820 orig_type, false); | 1814 orig_type); |
1821 if (ret) | 1815 if (ret) |
1822 return ret; | 1816 return ret; |
1823 } | 1817 } |
1824 | 1818 |
1825 if (!tail_array_field) | 1819 if (!tail_array_field) |
1829 field_type = TREE_TYPE (f); | 1823 field_type = TREE_TYPE (f); |
1830 offset = int_const_binop (MINUS_EXPR, offset, byte_position (f), 1); | 1824 offset = int_const_binop (MINUS_EXPR, offset, byte_position (f), 1); |
1831 | 1825 |
1832 /* If we get here, we've got an aggregate field, and a possibly | 1826 /* If we get here, we've got an aggregate field, and a possibly |
1833 nonzero offset into them. Recurse and hope for a valid match. */ | 1827 nonzero offset into them. Recurse and hope for a valid match. */ |
1834 if (base_is_ptr) | |
1835 base = build1 (INDIRECT_REF, record_type, base); | |
1836 base = build3 (COMPONENT_REF, field_type, base, f, NULL_TREE); | 1828 base = build3 (COMPONENT_REF, field_type, base, f, NULL_TREE); |
1837 | 1829 |
1838 t = maybe_fold_offset_to_array_ref (base, offset, orig_type, | 1830 t = maybe_fold_offset_to_array_ref (base, offset, orig_type, |
1839 f == TYPE_FIELDS (record_type)); | 1831 f == TYPE_FIELDS (record_type)); |
1840 if (t) | 1832 if (t) |
1841 return t; | 1833 return t; |
1842 return maybe_fold_offset_to_component_ref (field_type, base, offset, | 1834 return maybe_fold_offset_to_component_ref (field_type, base, offset, |
1843 orig_type, false); | 1835 orig_type); |
1844 } | 1836 } |
1845 | 1837 |
1846 /* Attempt to express (ORIG_TYPE)BASE+OFFSET as BASE->field_of_orig_type | 1838 /* Attempt to express (ORIG_TYPE)BASE+OFFSET as BASE->field_of_orig_type |
1847 or BASE[index] or by combination of those. | 1839 or BASE[index] or by combination of those. |
1848 | 1840 |
1852 tree | 1844 tree |
1853 maybe_fold_offset_to_reference (tree base, tree offset, tree orig_type) | 1845 maybe_fold_offset_to_reference (tree base, tree offset, tree orig_type) |
1854 { | 1846 { |
1855 tree ret; | 1847 tree ret; |
1856 tree type; | 1848 tree type; |
1857 bool base_is_ptr = true; | |
1858 | 1849 |
1859 STRIP_NOPS (base); | 1850 STRIP_NOPS (base); |
1860 if (TREE_CODE (base) == ADDR_EXPR) | 1851 if (TREE_CODE (base) != ADDR_EXPR) |
1861 { | 1852 return NULL_TREE; |
1862 base_is_ptr = false; | 1853 |
1863 | 1854 base = TREE_OPERAND (base, 0); |
1864 base = TREE_OPERAND (base, 0); | 1855 |
1865 | 1856 /* Handle case where existing COMPONENT_REF pick e.g. wrong field of union, |
1866 /* Handle case where existing COMPONENT_REF pick e.g. wrong field of union, | 1857 so it needs to be removed and new COMPONENT_REF constructed. |
1867 so it needs to be removed and new COMPONENT_REF constructed. | 1858 The wrong COMPONENT_REF are often constructed by folding the |
1868 The wrong COMPONENT_REF are often constructed by folding the | 1859 (type *)&object within the expression (type *)&object+offset */ |
1869 (type *)&object within the expression (type *)&object+offset */ | 1860 if (handled_component_p (base)) |
1870 if (handled_component_p (base)) | 1861 { |
1862 HOST_WIDE_INT sub_offset, size, maxsize; | |
1863 tree newbase; | |
1864 newbase = get_ref_base_and_extent (base, &sub_offset, | |
1865 &size, &maxsize); | |
1866 gcc_assert (newbase); | |
1867 if (size == maxsize | |
1868 && size != -1 | |
1869 && !(sub_offset & (BITS_PER_UNIT - 1))) | |
1871 { | 1870 { |
1872 HOST_WIDE_INT sub_offset, size, maxsize; | 1871 base = newbase; |
1873 tree newbase; | 1872 if (sub_offset) |
1874 newbase = get_ref_base_and_extent (base, &sub_offset, | 1873 offset = int_const_binop (PLUS_EXPR, offset, |
1875 &size, &maxsize); | 1874 build_int_cst (TREE_TYPE (offset), |
1876 gcc_assert (newbase); | 1875 sub_offset / BITS_PER_UNIT), 1); |
1877 if (size == maxsize | |
1878 && size != -1 | |
1879 && !(sub_offset & (BITS_PER_UNIT - 1))) | |
1880 { | |
1881 base = newbase; | |
1882 if (sub_offset) | |
1883 offset = int_const_binop (PLUS_EXPR, offset, | |
1884 build_int_cst (TREE_TYPE (offset), | |
1885 sub_offset / BITS_PER_UNIT), 1); | |
1886 } | |
1887 } | 1876 } |
1888 if (useless_type_conversion_p (orig_type, TREE_TYPE (base)) | 1877 } |
1889 && integer_zerop (offset)) | 1878 if (useless_type_conversion_p (orig_type, TREE_TYPE (base)) |
1890 return base; | 1879 && integer_zerop (offset)) |
1891 type = TREE_TYPE (base); | 1880 return base; |
1892 } | 1881 type = TREE_TYPE (base); |
1893 else | 1882 |
1894 { | 1883 ret = maybe_fold_offset_to_component_ref (type, base, offset, orig_type); |
1895 base_is_ptr = true; | |
1896 if (!POINTER_TYPE_P (TREE_TYPE (base))) | |
1897 return NULL_TREE; | |
1898 type = TREE_TYPE (TREE_TYPE (base)); | |
1899 } | |
1900 ret = maybe_fold_offset_to_component_ref (type, base, offset, | |
1901 orig_type, base_is_ptr); | |
1902 if (!ret) | 1884 if (!ret) |
1903 { | 1885 ret = maybe_fold_offset_to_array_ref (base, offset, orig_type, true); |
1904 if (base_is_ptr) | 1886 |
1905 base = build1 (INDIRECT_REF, type, base); | |
1906 ret = maybe_fold_offset_to_array_ref (base, offset, orig_type, true); | |
1907 } | |
1908 return ret; | 1887 return ret; |
1909 } | 1888 } |
1910 | 1889 |
1911 /* Attempt to express (ORIG_TYPE)&BASE+OFFSET as &BASE->field_of_orig_type | 1890 /* Attempt to express (ORIG_TYPE)&BASE+OFFSET as &BASE->field_of_orig_type |
1912 or &BASE[index] or by combination of those. | 1891 or &BASE[index] or by combination of those. |
2141 | 2120 |
2142 /* At which point we can try some of the same things as for indirects. */ | 2121 /* At which point we can try some of the same things as for indirects. */ |
2143 t = maybe_fold_offset_to_array_ref (op0, op1, ptd_type, true); | 2122 t = maybe_fold_offset_to_array_ref (op0, op1, ptd_type, true); |
2144 if (!t) | 2123 if (!t) |
2145 t = maybe_fold_offset_to_component_ref (TREE_TYPE (op0), op0, op1, | 2124 t = maybe_fold_offset_to_component_ref (TREE_TYPE (op0), op0, op1, |
2146 ptd_type, false); | 2125 ptd_type); |
2147 if (t) | 2126 if (t) |
2148 t = build1 (ADDR_EXPR, res_type, t); | 2127 t = build1 (ADDR_EXPR, res_type, t); |
2149 | 2128 |
2150 return t; | 2129 return t; |
2151 } | 2130 } |