Mercurial > hg > CbC > CbC_gcc
comparison gcc/stor-layout.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* C-compiler utilities for types and variables storage layout | 1 /* C-compiler utilities for types and variables storage layout |
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. | 2 Copyright (C) 1987-2020 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
7 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
40 #include "tree-inline.h" | 40 #include "tree-inline.h" |
41 #include "dumpfile.h" | 41 #include "dumpfile.h" |
42 #include "gimplify.h" | 42 #include "gimplify.h" |
43 #include "attribs.h" | 43 #include "attribs.h" |
44 #include "debug.h" | 44 #include "debug.h" |
45 #include "calls.h" | |
45 | 46 |
46 /* Data type for the expressions representing sizes of data types. | 47 /* Data type for the expressions representing sizes of data types. |
47 It is the first integer type laid out. */ | 48 It is the first integer type laid out. */ |
48 tree sizetype_tab[(int) stk_type_kind_last]; | 49 tree sizetype_tab[(int) stk_type_kind_last]; |
49 | 50 |
512 } | 513 } |
513 | 514 |
514 return opt_machine_mode (); | 515 return opt_machine_mode (); |
515 } | 516 } |
516 | 517 |
517 /* Return the mode for a vector that has NUNITS integer elements of | 518 /* If a piece of code is using vector mode VECTOR_MODE and also wants |
518 INT_BITS bits each, if such a mode exists. The mode can be either | 519 to operate on elements of mode ELEMENT_MODE, return the vector mode |
519 an integer mode or a vector mode. */ | 520 it should use for those elements. If NUNITS is nonzero, ensure that |
521 the mode has exactly NUNITS elements, otherwise pick whichever vector | |
522 size pairs the most naturally with VECTOR_MODE; this may mean choosing | |
523 a mode with a different size and/or number of elements, depending on | |
524 what the target prefers. Return an empty opt_machine_mode if there | |
525 is no supported vector mode with the required properties. | |
526 | |
527 Unlike mode_for_vector. any returned mode is guaranteed to satisfy | |
528 both VECTOR_MODE_P and targetm.vector_mode_supported_p. */ | |
520 | 529 |
521 opt_machine_mode | 530 opt_machine_mode |
522 mode_for_int_vector (unsigned int int_bits, poly_uint64 nunits) | 531 related_vector_mode (machine_mode vector_mode, scalar_mode element_mode, |
523 { | 532 poly_uint64 nunits) |
533 { | |
534 gcc_assert (VECTOR_MODE_P (vector_mode)); | |
535 return targetm.vectorize.related_mode (vector_mode, element_mode, nunits); | |
536 } | |
537 | |
538 /* If a piece of code is using vector mode VECTOR_MODE and also wants | |
539 to operate on integer vectors with the same element size and number | |
540 of elements, return the vector mode it should use. Return an empty | |
541 opt_machine_mode if there is no supported vector mode with the | |
542 required properties. | |
543 | |
544 Unlike mode_for_vector. any returned mode is guaranteed to satisfy | |
545 both VECTOR_MODE_P and targetm.vector_mode_supported_p. */ | |
546 | |
547 opt_machine_mode | |
548 related_int_vector_mode (machine_mode vector_mode) | |
549 { | |
550 gcc_assert (VECTOR_MODE_P (vector_mode)); | |
524 scalar_int_mode int_mode; | 551 scalar_int_mode int_mode; |
525 machine_mode vec_mode; | 552 if (int_mode_for_mode (GET_MODE_INNER (vector_mode)).exists (&int_mode)) |
526 if (int_mode_for_size (int_bits, 0).exists (&int_mode) | 553 return related_vector_mode (vector_mode, int_mode, |
527 && mode_for_vector (int_mode, nunits).exists (&vec_mode)) | 554 GET_MODE_NUNITS (vector_mode)); |
528 return vec_mode; | |
529 return opt_machine_mode (); | 555 return opt_machine_mode (); |
530 } | 556 } |
531 | 557 |
532 /* Return the alignment of MODE. This will be bounded by 1 and | 558 /* Return the alignment of MODE. This will be bounded by 1 and |
533 BIGGEST_ALIGNMENT. */ | 559 BIGGEST_ALIGNMENT. */ |
1808 However, if possible, we use a mode that fits in a register | 1834 However, if possible, we use a mode that fits in a register |
1809 instead, in order to allow for better optimization down the | 1835 instead, in order to allow for better optimization down the |
1810 line. */ | 1836 line. */ |
1811 SET_TYPE_MODE (type, BLKmode); | 1837 SET_TYPE_MODE (type, BLKmode); |
1812 | 1838 |
1813 if (! tree_fits_uhwi_p (TYPE_SIZE (type))) | 1839 poly_uint64 type_size; |
1840 if (!poly_int_tree_p (TYPE_SIZE (type), &type_size)) | |
1814 return; | 1841 return; |
1815 | 1842 |
1816 /* A record which has any BLKmode members must itself be | 1843 /* A record which has any BLKmode members must itself be |
1817 BLKmode; it can't go in a register. Unless the member is | 1844 BLKmode; it can't go in a register. Unless the member is |
1818 BLKmode only because it isn't aligned. */ | 1845 BLKmode only because it isn't aligned. */ |
1819 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) | 1846 for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) |
1820 { | 1847 { |
1821 if (TREE_CODE (field) != FIELD_DECL) | 1848 if (TREE_CODE (field) != FIELD_DECL) |
1822 continue; | 1849 continue; |
1823 | 1850 |
1851 poly_uint64 field_size; | |
1824 if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK | 1852 if (TREE_CODE (TREE_TYPE (field)) == ERROR_MARK |
1825 || (TYPE_MODE (TREE_TYPE (field)) == BLKmode | 1853 || (TYPE_MODE (TREE_TYPE (field)) == BLKmode |
1826 && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)) | 1854 && ! TYPE_NO_FORCE_BLK (TREE_TYPE (field)) |
1827 && !(TYPE_SIZE (TREE_TYPE (field)) != 0 | 1855 && !(TYPE_SIZE (TREE_TYPE (field)) != 0 |
1828 && integer_zerop (TYPE_SIZE (TREE_TYPE (field))))) | 1856 && integer_zerop (TYPE_SIZE (TREE_TYPE (field))))) |
1829 || ! tree_fits_uhwi_p (bit_position (field)) | 1857 || !tree_fits_poly_uint64_p (bit_position (field)) |
1830 || DECL_SIZE (field) == 0 | 1858 || DECL_SIZE (field) == 0 |
1831 || ! tree_fits_uhwi_p (DECL_SIZE (field))) | 1859 || !poly_int_tree_p (DECL_SIZE (field), &field_size)) |
1832 return; | 1860 return; |
1833 | 1861 |
1834 /* If this field is the whole struct, remember its mode so | 1862 /* If this field is the whole struct, remember its mode so |
1835 that, say, we can put a double in a class into a DF | 1863 that, say, we can put a double in a class into a DF |
1836 register instead of forcing it to live in the stack. */ | 1864 register instead of forcing it to live in the stack. */ |
1837 if (simple_cst_equal (TYPE_SIZE (type), DECL_SIZE (field))) | 1865 if (known_eq (field_size, type_size) |
1866 /* Partial int types (e.g. __int20) may have TYPE_SIZE equal to | |
1867 wider types (e.g. int32), despite precision being less. Ensure | |
1868 that the TYPE_MODE of the struct does not get set to the partial | |
1869 int mode if there is a wider type also in the struct. */ | |
1870 && known_gt (GET_MODE_PRECISION (DECL_MODE (field)), | |
1871 GET_MODE_PRECISION (mode))) | |
1838 mode = DECL_MODE (field); | 1872 mode = DECL_MODE (field); |
1839 | 1873 |
1840 /* With some targets, it is sub-optimal to access an aligned | 1874 /* With some targets, it is sub-optimal to access an aligned |
1841 BLKmode structure as a scalar. */ | 1875 BLKmode structure as a scalar. */ |
1842 if (targetm.member_type_forces_blk (field, mode)) | 1876 if (targetm.member_type_forces_blk (field, mode)) |
1843 return; | 1877 return; |
1844 } | 1878 } |
1845 | 1879 |
1846 /* If we only have one real field; use its mode if that mode's size | 1880 /* If we only have one real field; use its mode if that mode's size |
1847 matches the type's size. This only applies to RECORD_TYPE. This | 1881 matches the type's size. This generally only applies to RECORD_TYPE. |
1848 does not apply to unions. */ | 1882 For UNION_TYPE, if the widest field is MODE_INT then use that mode. |
1849 poly_uint64 type_size; | 1883 If the widest field is MODE_PARTIAL_INT, and the union will be passed |
1850 if (TREE_CODE (type) == RECORD_TYPE | 1884 by reference, then use that mode. */ |
1885 if ((TREE_CODE (type) == RECORD_TYPE | |
1886 || (TREE_CODE (type) == UNION_TYPE | |
1887 && (GET_MODE_CLASS (mode) == MODE_INT | |
1888 || (GET_MODE_CLASS (mode) == MODE_PARTIAL_INT | |
1889 && (targetm.calls.pass_by_reference | |
1890 (pack_cumulative_args (0), | |
1891 function_arg_info (type, mode, /*named=*/false))))))) | |
1851 && mode != VOIDmode | 1892 && mode != VOIDmode |
1852 && poly_int_tree_p (TYPE_SIZE (type), &type_size) | |
1853 && known_eq (GET_MODE_BITSIZE (mode), type_size)) | 1893 && known_eq (GET_MODE_BITSIZE (mode), type_size)) |
1854 ; | 1894 ; |
1855 else | 1895 else |
1856 mode = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1).else_blk (); | 1896 mode = mode_for_size_tree (TYPE_SIZE (type), MODE_INT, 1).else_blk (); |
1857 | 1897 |
2701 | 2741 |
2702 precision = -1; | 2742 precision = -1; |
2703 for (i = 0; i < NUM_INT_N_ENTS; i++) | 2743 for (i = 0; i < NUM_INT_N_ENTS; i++) |
2704 if (int_n_enabled_p[i]) | 2744 if (int_n_enabled_p[i]) |
2705 { | 2745 { |
2706 char name[50]; | 2746 char name[50], altname[50]; |
2707 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize); | 2747 sprintf (name, "__int%d unsigned", int_n_data[i].bitsize); |
2708 | 2748 sprintf (altname, "__int%d__ unsigned", int_n_data[i].bitsize); |
2709 if (strcmp (name, SIZETYPE) == 0) | 2749 |
2750 if (strcmp (name, SIZETYPE) == 0 | |
2751 || strcmp (altname, SIZETYPE) == 0) | |
2710 { | 2752 { |
2711 precision = int_n_data[i].bitsize; | 2753 precision = int_n_data[i].bitsize; |
2712 } | 2754 } |
2713 } | 2755 } |
2714 if (precision == -1) | 2756 if (precision == -1) |