comparison gcc/varasm.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 /* Output variables, constants and external declarations, for GNU compiler. 1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 Free Software Foundation, Inc. 4 2010 Free Software Foundation, Inc.
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 it under 8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free 9 the terms of the GNU General Public License as published by the Free
36 #include "flags.h" 36 #include "flags.h"
37 #include "function.h" 37 #include "function.h"
38 #include "expr.h" 38 #include "expr.h"
39 #include "hard-reg-set.h" 39 #include "hard-reg-set.h"
40 #include "regs.h" 40 #include "regs.h"
41 #include "real.h"
42 #include "output.h" 41 #include "output.h"
43 #include "toplev.h" 42 #include "toplev.h"
44 #include "hashtab.h" 43 #include "hashtab.h"
45 #include "ggc.h" 44 #include "ggc.h"
46 #include "langhooks.h" 45 #include "langhooks.h"
168 167
169 /* A linked list of all the unnamed sections. */ 168 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections; 169 static GTY(()) section *unnamed_sections;
171 170
172 /* Return a nonzero value if DECL has a section attribute. */ 171 /* Return a nonzero value if DECL has a section attribute. */
173 #ifndef IN_NAMED_SECTION
174 #define IN_NAMED_SECTION(DECL) \ 172 #define IN_NAMED_SECTION(DECL) \
175 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \ 173 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
176 && DECL_SECTION_NAME (DECL) != NULL_TREE) 174 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 #endif
178 175
179 /* Hash table of named sections. */ 176 /* Hash table of named sections. */
180 static GTY((param_is (section))) htab_t section_htab; 177 static GTY((param_is (section))) htab_t section_htab;
181 178
182 /* A table of object_blocks, indexed by section. */ 179 /* A table of object_blocks, indexed by section. */
365 name = DECL_ASSEMBLER_NAME (decl); 362 name = DECL_ASSEMBLER_NAME (decl);
366 363
367 /* Note that we use the hash of the decl's name, rather than a hash 364 /* Note that we use the hash of the decl's name, rather than a hash
368 of the decl's pointer. In emutls_finish we iterate through the 365 of the decl's pointer. In emutls_finish we iterate through the
369 hash table, and we want this traversal to be predictable. */ 366 hash table, and we want this traversal to be predictable. */
370 in.hash = htab_hash_string (IDENTIFIER_POINTER (name)); 367 in.hash = IDENTIFIER_HASH_VALUE (name);
371 in.base.from = decl; 368 in.base.from = decl;
372 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT); 369 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
373 h = (struct tree_map *) *loc; 370 h = (struct tree_map *) *loc;
374 if (h != NULL) 371 if (h != NULL)
375 to = h->to; 372 to = h->to;
403 the original decl. Consider: 400 the original decl. Consider:
404 extern __thread int i; 401 extern __thread int i;
405 int foo() { return i; } 402 int foo() { return i; }
406 __thread int i = 1; 403 __thread int i = 1;
407 in which I goes from external to locally defined and initialized. */ 404 in which I goes from external to locally defined and initialized. */
405 DECL_DLLIMPORT_P (to) = DECL_DLLIMPORT_P (decl);
406 DECL_ATTRIBUTES (to) = targetm.merge_decl_attributes (decl, to);
408 407
409 TREE_STATIC (to) = TREE_STATIC (decl); 408 TREE_STATIC (to) = TREE_STATIC (decl);
410 TREE_USED (to) = TREE_USED (decl); 409 TREE_USED (to) = TREE_USED (decl);
411 TREE_PUBLIC (to) = TREE_PUBLIC (decl); 410 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
412 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl); 411 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
1172 int reloc; 1171 int reloc;
1173 1172
1174 if (TREE_TYPE (decl) != error_mark_node) 1173 if (TREE_TYPE (decl) != error_mark_node)
1175 as = TYPE_ADDR_SPACE (TREE_TYPE (decl)); 1174 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1176 1175
1177 /* If the decl has been given an explicit section name, or it resides 1176 if (DECL_COMMON (decl))
1178 in a non-generic address space, then it isn't common, and shouldn't 1177 {
1179 be handled as such. */ 1178 /* If the decl has been given an explicit section name, or it resides
1180 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL 1179 in a non-generic address space, then it isn't common, and shouldn't
1181 && ADDR_SPACE_GENERIC_P (as)) 1180 be handled as such. */
1182 { 1181 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1182 && ADDR_SPACE_GENERIC_P (as));
1183 if (DECL_THREAD_LOCAL_P (decl)) 1183 if (DECL_THREAD_LOCAL_P (decl))
1184 return tls_comm_section; 1184 return tls_comm_section;
1185 /* This cannot be common bss for an emulated TLS object without 1185 /* This cannot be common bss for an emulated TLS object without
1186 a register_common hook. */ 1186 a register_common hook. */
1187 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED 1187 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1350 1350
1351 /* Make this function static known to the mudflap runtime. */ 1351 /* Make this function static known to the mudflap runtime. */
1352 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL) 1352 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1353 mudflap_enqueue_decl (decl); 1353 mudflap_enqueue_decl (decl);
1354 1354
1355 return;
1356 }
1357
1358 /* If this variable belongs to the global constant pool, retrieve the
1359 pre-computed RTL or recompute it in LTO mode. */
1360 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1361 {
1362 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1355 return; 1363 return;
1356 } 1364 }
1357 1365
1358 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 1366 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1359 1367
1432 #endif 1440 #endif
1433 } 1441 }
1434 1442
1435 /* Specifying a section attribute on a variable forces it into a 1443 /* Specifying a section attribute on a variable forces it into a
1436 non-.bss section, and thus it cannot be common. */ 1444 non-.bss section, and thus it cannot be common. */
1445 /* FIXME: In general this code should not be necessary because
1446 visibility pass is doing the same work. But notice_global_symbol
1447 is called early and it needs to make DECL_RTL to get the name.
1448 we take care of recomputing the DECL_RTL after visibility is changed. */
1437 if (TREE_CODE (decl) == VAR_DECL 1449 if (TREE_CODE (decl) == VAR_DECL
1438 && DECL_SECTION_NAME (decl) != NULL_TREE 1450 && DECL_SECTION_NAME (decl) != NULL_TREE
1439 && DECL_INITIAL (decl) == NULL_TREE 1451 && DECL_INITIAL (decl) == NULL_TREE
1440 && DECL_COMMON (decl)) 1452 && DECL_COMMON (decl))
1441 DECL_COMMON (decl) = 0; 1453 DECL_COMMON (decl) = 0;
1471 targetm.encode_section_info (decl, DECL_RTL (decl), true); 1483 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1472 1484
1473 /* Make this function static known to the mudflap runtime. */ 1485 /* Make this function static known to the mudflap runtime. */
1474 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL) 1486 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1475 mudflap_enqueue_decl (decl); 1487 mudflap_enqueue_decl (decl);
1488 }
1489
1490 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1491 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1492 rtl. */
1493
1494 rtx
1495 make_decl_rtl_for_debug (tree decl)
1496 {
1497 unsigned int save_aliasing_flag, save_mudflap_flag;
1498 rtx rtl;
1499
1500 if (DECL_RTL_SET_P (decl))
1501 return DECL_RTL (decl);
1502
1503 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1504 call new_alias_set. If running with -fcompare-debug, sometimes
1505 we do not want to create alias sets that will throw the alias
1506 numbers off in the comparison dumps. So... clearing
1507 flag_strict_aliasing will keep new_alias_set() from creating a
1508 new set. It is undesirable to register decl with mudflap
1509 in this case as well. */
1510 save_aliasing_flag = flag_strict_aliasing;
1511 flag_strict_aliasing = 0;
1512 save_mudflap_flag = flag_mudflap;
1513 flag_mudflap = 0;
1514
1515 rtl = DECL_RTL (decl);
1516 /* Reset DECL_RTL back, as various parts of the compiler expects
1517 DECL_RTL set meaning it is actually going to be output. */
1518 SET_DECL_RTL (decl, NULL);
1519
1520 flag_strict_aliasing = save_aliasing_flag;
1521 flag_mudflap = save_mudflap_flag;
1522
1523 return rtl;
1476 } 1524 }
1477 1525
1478 /* Output a string of literal assembler code 1526 /* Output a string of literal assembler code
1479 for an `asm' keyword used between functions. */ 1527 for an `asm' keyword used between functions. */
1480 1528
2157 2205
2158 /* Do no output if -fsyntax-only. */ 2206 /* Do no output if -fsyntax-only. */
2159 if (flag_syntax_only) 2207 if (flag_syntax_only)
2160 return; 2208 return;
2161 2209
2162 app_disable ();
2163
2164 if (! dont_output_data 2210 if (! dont_output_data
2165 && ! host_integerp (DECL_SIZE_UNIT (decl), 1)) 2211 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2166 { 2212 {
2167 error ("size of variable %q+D is too large", decl); 2213 error ("size of variable %q+D is too large", decl);
2168 return; 2214 return;
2169 } 2215 }
2170 2216
2171 gcc_assert (MEM_P (decl_rtl)); 2217 gcc_assert (MEM_P (decl_rtl));
2172 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF); 2218 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2173 symbol = XEXP (decl_rtl, 0); 2219 symbol = XEXP (decl_rtl, 0);
2220
2221 /* If this symbol belongs to the tree constant pool, output the constant
2222 if it hasn't already been written. */
2223 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2224 {
2225 tree decl = SYMBOL_REF_DECL (symbol);
2226 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2227 output_constant_def_contents (symbol);
2228 return;
2229 }
2230
2231 app_disable ();
2232
2174 name = XSTR (symbol, 0); 2233 name = XSTR (symbol, 0);
2175 if (TREE_PUBLIC (decl) && DECL_NAME (decl)) 2234 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2176 notice_global_symbol (decl); 2235 notice_global_symbol (decl);
2177 2236
2178 /* Compute the alignment of this data. */ 2237 /* Compute the alignment of this data. */
2335 return; 2394 return;
2336 2395
2337 /* We want to output annotation for weak and external symbols at 2396 /* We want to output annotation for weak and external symbols at
2338 very last to check if they are references or not. */ 2397 very last to check if they are references or not. */
2339 2398
2340 if (SUPPORTS_WEAK && DECL_WEAK (decl) 2399 if (SUPPORTS_WEAK
2400 && DECL_WEAK (decl)
2341 /* TREE_STATIC is a weird and abused creature which is not 2401 /* TREE_STATIC is a weird and abused creature which is not
2342 generally the right test for whether an entity has been 2402 generally the right test for whether an entity has been
2343 locally emitted, inlined or otherwise not-really-extern, but 2403 locally emitted, inlined or otherwise not-really-extern, but
2344 for declarations that can be weak, it happens to be 2404 for declarations that can be weak, it happens to be
2345 match. */ 2405 match. */
2346 && !TREE_STATIC (decl) 2406 && !TREE_STATIC (decl)
2407 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2347 && value_member (decl, weak_decls) == NULL_TREE) 2408 && value_member (decl, weak_decls) == NULL_TREE)
2348 weak_decls = tree_cons (NULL, decl, weak_decls); 2409 weak_decls = tree_cons (NULL, decl, weak_decls);
2349 2410
2350 #ifdef ASM_OUTPUT_EXTERNAL 2411 #ifdef ASM_OUTPUT_EXTERNAL
2351 if (value_member (decl, pending_assemble_externals) == NULL_TREE) 2412 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2747 2808
2748 while (1) 2809 while (1)
2749 { 2810 {
2750 if (TREE_CODE (target) == COMPONENT_REF 2811 if (TREE_CODE (target) == COMPONENT_REF
2751 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0)) 2812 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2752
2753 { 2813 {
2754 offset += int_byte_position (TREE_OPERAND (target, 1)); 2814 offset += int_byte_position (TREE_OPERAND (target, 1));
2755 target = TREE_OPERAND (target, 0); 2815 target = TREE_OPERAND (target, 0);
2756 } 2816 }
2757 else if (TREE_CODE (target) == ARRAY_REF 2817 else if (TREE_CODE (target) == ARRAY_REF
2759 { 2819 {
2760 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1) 2820 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2761 * tree_low_cst (TREE_OPERAND (target, 1), 0)); 2821 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2762 target = TREE_OPERAND (target, 0); 2822 target = TREE_OPERAND (target, 0);
2763 } 2823 }
2824 else if (TREE_CODE (target) == INDIRECT_REF
2825 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2826 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2827 == ADDR_EXPR)
2828 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2764 else 2829 else
2765 break; 2830 break;
2766 } 2831 }
2767 2832
2768 switch (TREE_CODE (target)) 2833 switch (TREE_CODE (target))
2799 2864
2800 2865
2801 static GTY((param_is (struct constant_descriptor_tree))) 2866 static GTY((param_is (struct constant_descriptor_tree)))
2802 htab_t const_desc_htab; 2867 htab_t const_desc_htab;
2803 2868
2804 static struct constant_descriptor_tree * build_constant_desc (tree);
2805 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int); 2869 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2806 2870
2807 /* Constant pool accessor function. */ 2871 /* Constant pool accessor function. */
2808 2872
2809 htab_t 2873 htab_t
2850 break; 2914 break;
2851 2915
2852 case COMPLEX_CST: 2916 case COMPLEX_CST:
2853 return (const_hash_1 (TREE_REALPART (exp)) * 5 2917 return (const_hash_1 (TREE_REALPART (exp)) * 5
2854 + const_hash_1 (TREE_IMAGPART (exp))); 2918 + const_hash_1 (TREE_IMAGPART (exp)));
2919
2920 case VECTOR_CST:
2921 {
2922 tree link;
2923
2924 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2925
2926 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2927 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2928
2929 return hi;
2930 }
2855 2931
2856 case CONSTRUCTOR: 2932 case CONSTRUCTOR:
2857 { 2933 {
2858 unsigned HOST_WIDE_INT idx; 2934 unsigned HOST_WIDE_INT idx;
2859 tree value; 2935 tree value;
2978 TREE_STRING_LENGTH (t1))); 3054 TREE_STRING_LENGTH (t1)));
2979 3055
2980 case COMPLEX_CST: 3056 case COMPLEX_CST:
2981 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2)) 3057 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2982 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2))); 3058 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3059
3060 case VECTOR_CST:
3061 {
3062 tree link1, link2;
3063
3064 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3065 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3066 return 0;
3067
3068 link2 = TREE_VECTOR_CST_ELTS (t2);
3069 for (link1 = TREE_VECTOR_CST_ELTS (t1);
3070 link1;
3071 link1 = TREE_CHAIN (link1))
3072 {
3073 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3074 return 0;
3075 link2 = TREE_CHAIN (link2);
3076 }
3077
3078 return 1;
3079 }
2983 3080
2984 case CONSTRUCTOR: 3081 case CONSTRUCTOR:
2985 { 3082 {
2986 VEC(constructor_elt, gc) *v1, *v2; 3083 VEC(constructor_elt, gc) *v1, *v2;
2987 unsigned HOST_WIDE_INT idx; 3084 unsigned HOST_WIDE_INT idx;
3039 3136
3040 case ADDR_EXPR: 3137 case ADDR_EXPR:
3041 case FDESC_EXPR: 3138 case FDESC_EXPR:
3042 { 3139 {
3043 struct addr_const value1, value2; 3140 struct addr_const value1, value2;
3141 enum rtx_code code;
3142 int ret;
3044 3143
3045 decode_addr_const (t1, &value1); 3144 decode_addr_const (t1, &value1);
3046 decode_addr_const (t2, &value2); 3145 decode_addr_const (t2, &value2);
3047 return (value1.offset == value2.offset 3146
3048 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0); 3147 if (value1.offset != value2.offset)
3148 return 0;
3149
3150 code = GET_CODE (value1.base);
3151 if (code != GET_CODE (value2.base))
3152 return 0;
3153
3154 switch (code)
3155 {
3156 case SYMBOL_REF:
3157 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3158 break;
3159
3160 case LABEL_REF:
3161 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3162 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3163 break;
3164
3165 default:
3166 gcc_unreachable ();
3167 }
3168 return ret;
3049 } 3169 }
3050 3170
3051 case PLUS_EXPR: 3171 case PLUS_EXPR:
3052 case POINTER_PLUS_EXPR: 3172 case POINTER_PLUS_EXPR:
3053 case MINUS_EXPR: 3173 case MINUS_EXPR:
3103 3223
3104 CASE_CONVERT: 3224 CASE_CONVERT:
3105 case VIEW_CONVERT_EXPR: 3225 case VIEW_CONVERT_EXPR:
3106 return build1 (TREE_CODE (exp), TREE_TYPE (exp), 3226 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3107 copy_constant (TREE_OPERAND (exp, 0))); 3227 copy_constant (TREE_OPERAND (exp, 0)));
3228
3229 case VECTOR_CST:
3230 return build_vector (TREE_TYPE (exp),
3231 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3108 3232
3109 case CONSTRUCTOR: 3233 case CONSTRUCTOR:
3110 { 3234 {
3111 tree copy = copy_node (exp); 3235 tree copy = copy_node (exp);
3112 VEC(constructor_elt, gc) *v; 3236 VEC(constructor_elt, gc) *v;
3128 default: 3252 default:
3129 gcc_unreachable (); 3253 gcc_unreachable ();
3130 } 3254 }
3131 } 3255 }
3132 3256
3133 /* Return the alignment of constant EXP in bits. */
3134
3135 static unsigned int
3136 get_constant_alignment (tree exp)
3137 {
3138 unsigned int align;
3139
3140 align = TYPE_ALIGN (TREE_TYPE (exp));
3141 #ifdef CONSTANT_ALIGNMENT
3142 align = CONSTANT_ALIGNMENT (exp, align);
3143 #endif
3144 return align;
3145 }
3146
3147 /* Return the section into which constant EXP should be placed. */ 3257 /* Return the section into which constant EXP should be placed. */
3148 3258
3149 static section * 3259 static section *
3150 get_constant_section (tree exp) 3260 get_constant_section (tree exp, unsigned int align)
3151 { 3261 {
3152 if (IN_NAMED_SECTION (exp)) 3262 return targetm.asm_out.select_section (exp,
3153 return get_named_section (exp, NULL, compute_reloc_for_constant (exp)); 3263 compute_reloc_for_constant (exp),
3154 else 3264 align);
3155 return targetm.asm_out.select_section (exp,
3156 compute_reloc_for_constant (exp),
3157 get_constant_alignment (exp));
3158 } 3265 }
3159 3266
3160 /* Return the size of constant EXP in bytes. */ 3267 /* Return the size of constant EXP in bytes. */
3161 3268
3162 static HOST_WIDE_INT 3269 static HOST_WIDE_INT
3178 Caller is responsible for updating the hash table. */ 3285 Caller is responsible for updating the hash table. */
3179 3286
3180 static struct constant_descriptor_tree * 3287 static struct constant_descriptor_tree *
3181 build_constant_desc (tree exp) 3288 build_constant_desc (tree exp)
3182 { 3289 {
3183 rtx symbol; 3290 struct constant_descriptor_tree *desc;
3184 rtx rtl; 3291 rtx symbol, rtl;
3185 char label[256]; 3292 char label[256];
3186 int labelno; 3293 int labelno;
3187 struct constant_descriptor_tree *desc; 3294 tree decl;
3188 3295
3189 desc = GGC_NEW (struct constant_descriptor_tree); 3296 desc = GGC_NEW (struct constant_descriptor_tree);
3190 desc->value = copy_constant (exp); 3297 desc->value = copy_constant (exp);
3191 3298
3192 /* Propagate marked-ness to copied constant. */ 3299 /* Propagate marked-ness to copied constant. */
3195 3302
3196 /* Create a string containing the label name, in LABEL. */ 3303 /* Create a string containing the label name, in LABEL. */
3197 labelno = const_labelno++; 3304 labelno = const_labelno++;
3198 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno); 3305 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3199 3306
3200 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */ 3307 /* Construct the VAR_DECL associated with the constant. */
3308 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3309 TREE_TYPE (exp));
3310 DECL_ARTIFICIAL (decl) = 1;
3311 DECL_IGNORED_P (decl) = 1;
3312 TREE_READONLY (decl) = 1;
3313 TREE_STATIC (decl) = 1;
3314 TREE_ADDRESSABLE (decl) = 1;
3315 /* We don't set the RTL yet as this would cause varpool to assume that the
3316 variable is referenced. Moreover, it would just be dropped in LTO mode.
3317 Instead we set the flag that will be recognized in make_decl_rtl. */
3318 DECL_IN_CONSTANT_POOL (decl) = 1;
3319 DECL_INITIAL (decl) = desc->value;
3320 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3321 architectures so use DATA_ALIGNMENT as well, except for strings. */
3322 if (TREE_CODE (exp) == STRING_CST)
3323 {
3324 #ifdef CONSTANT_ALIGNMENT
3325 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3326 #endif
3327 }
3328 else
3329 align_variable (decl, 0);
3330
3331 /* Now construct the SYMBOL_REF and the MEM. */
3201 if (use_object_blocks_p ()) 3332 if (use_object_blocks_p ())
3202 { 3333 {
3203 section *sect = get_constant_section (exp); 3334 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3204 symbol = create_block_symbol (ggc_strdup (label), 3335 symbol = create_block_symbol (ggc_strdup (label),
3205 get_block_for_section (sect), -1); 3336 get_block_for_section (sect), -1);
3206 } 3337 }
3207 else 3338 else
3208 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)); 3339 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3209 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL; 3340 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3210 SET_SYMBOL_REF_DECL (symbol, desc->value); 3341 SET_SYMBOL_REF_DECL (symbol, decl);
3211 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1; 3342 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3212 3343
3213 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol); 3344 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3214 set_mem_attributes (rtl, exp, 1); 3345 set_mem_attributes (rtl, exp, 1);
3215 set_mem_alias_set (rtl, 0); 3346 set_mem_alias_set (rtl, 0);
3222 /* Set flags or add text to the name to record information, such as 3353 /* Set flags or add text to the name to record information, such as
3223 that it is a local symbol. If the name is changed, the macro 3354 that it is a local symbol. If the name is changed, the macro
3224 ASM_OUTPUT_LABELREF will have to know how to strip this 3355 ASM_OUTPUT_LABELREF will have to know how to strip this
3225 information. This call might invalidate our local variable 3356 information. This call might invalidate our local variable
3226 SYMBOL; we can't use it afterward. */ 3357 SYMBOL; we can't use it afterward. */
3227
3228 targetm.encode_section_info (exp, rtl, true); 3358 targetm.encode_section_info (exp, rtl, true);
3229 3359
3230 desc->rtl = rtl; 3360 desc->rtl = rtl;
3231 3361
3232 return desc; 3362 return desc;
3329 /* We must output the constant data referred to by SYMBOL; do so. */ 3459 /* We must output the constant data referred to by SYMBOL; do so. */
3330 3460
3331 static void 3461 static void
3332 output_constant_def_contents (rtx symbol) 3462 output_constant_def_contents (rtx symbol)
3333 { 3463 {
3334 tree exp = SYMBOL_REF_DECL (symbol); 3464 tree decl = SYMBOL_REF_DECL (symbol);
3465 tree exp = DECL_INITIAL (decl);
3335 unsigned int align; 3466 unsigned int align;
3336 3467
3337 /* Make sure any other constants whose addresses appear in EXP 3468 /* Make sure any other constants whose addresses appear in EXP
3338 are assigned label numbers. */ 3469 are assigned label numbers. */
3339 output_addressed_constants (exp); 3470 output_addressed_constants (exp);
3346 its definition yet. output_object_blocks will do that later. */ 3477 its definition yet. output_object_blocks will do that later. */
3347 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol)) 3478 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3348 place_block_symbol (symbol); 3479 place_block_symbol (symbol);
3349 else 3480 else
3350 { 3481 {
3351 switch_to_section (get_constant_section (exp)); 3482 align = DECL_ALIGN (decl);
3352 align = get_constant_alignment (exp); 3483 switch_to_section (get_constant_section (exp, align));
3353 if (align > BITS_PER_UNIT) 3484 if (align > BITS_PER_UNIT)
3354 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); 3485 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3355 assemble_constant_contents (exp, XSTR (symbol, 0), align); 3486 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3356 } 3487 }
3357 if (flag_mudflap) 3488 if (flag_mudflap)
3371 key.hash = const_hash_1 (exp); 3502 key.hash = const_hash_1 (exp);
3372 desc = (struct constant_descriptor_tree *) 3503 desc = (struct constant_descriptor_tree *)
3373 htab_find_with_hash (const_desc_htab, &key, key.hash); 3504 htab_find_with_hash (const_desc_htab, &key, key.hash);
3374 3505
3375 return (desc ? desc->rtl : NULL_RTX); 3506 return (desc ? desc->rtl : NULL_RTX);
3507 }
3508
3509 /* Return a tree representing a reference to constant data in memory
3510 for the constant expression EXP.
3511
3512 This is the counterpart of output_constant_def at the Tree level. */
3513
3514 tree
3515 tree_output_constant_def (tree exp)
3516 {
3517 struct constant_descriptor_tree *desc, key;
3518 void **loc;
3519 tree decl;
3520
3521 /* Look up EXP in the table of constant descriptors. If we didn't find
3522 it, create a new one. */
3523 key.value = exp;
3524 key.hash = const_hash_1 (exp);
3525 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3526
3527 desc = (struct constant_descriptor_tree *) *loc;
3528 if (desc == 0)
3529 {
3530 desc = build_constant_desc (exp);
3531 desc->hash = key.hash;
3532 *loc = desc;
3533 }
3534
3535 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3536 varpool_finalize_decl (decl);
3537 return decl;
3376 } 3538 }
3377 3539
3378 /* Used in the hash tables to avoid outputting the same constant 3540 /* Used in the hash tables to avoid outputting the same constant
3379 twice. Unlike 'struct constant_descriptor_tree', RTX constants 3541 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3380 are output once per function, not once per file. */ 3542 are output once per function, not once per file. */
3841 for_each_rtx (&desc->constant, mark_constant, NULL); 4003 for_each_rtx (&desc->constant, mark_constant, NULL);
3842 } 4004 }
3843 } 4005 }
3844 else if (TREE_CONSTANT_POOL_ADDRESS_P (x)) 4006 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3845 { 4007 {
3846 tree exp = SYMBOL_REF_DECL (x); 4008 tree decl = SYMBOL_REF_DECL (x);
3847 if (!TREE_ASM_WRITTEN (exp)) 4009 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
3848 { 4010 {
3849 n_deferred_constants--; 4011 n_deferred_constants--;
3850 output_constant_def_contents (x); 4012 output_constant_def_contents (x);
3851 } 4013 }
3852 } 4014 }
4089 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE 4251 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4090 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE) 4252 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4091 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor))); 4253 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4092 } 4254 }
4093 4255
4256 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4257 tree *cache);
4258
4094 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR, 4259 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4095 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE 4260 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4096 which are valid when ENDTYPE is an integer of any size; in 4261 which are valid when ENDTYPE is an integer of any size; in
4097 particular, this does not accept a pointer minus a constant. This 4262 particular, this does not accept a pointer minus a constant. This
4098 returns null_pointer_node if the VALUE is an absolute constant 4263 returns null_pointer_node if the VALUE is an absolute constant
4099 which can be used to initialize a static variable. Otherwise it 4264 which can be used to initialize a static variable. Otherwise it
4100 returns NULL. */ 4265 returns NULL. */
4101 4266
4102 static tree 4267 static tree
4103 narrowing_initializer_constant_valid_p (tree value, tree endtype) 4268 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4104 { 4269 {
4105 tree op0, op1; 4270 tree op0, op1;
4106 4271
4107 if (!INTEGRAL_TYPE_P (endtype)) 4272 if (!INTEGRAL_TYPE_P (endtype))
4108 return NULL_TREE; 4273 return NULL_TREE;
4137 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) 4302 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4138 break; 4303 break;
4139 op1 = inner; 4304 op1 = inner;
4140 } 4305 }
4141 4306
4142 op0 = initializer_constant_valid_p (op0, endtype); 4307 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4143 op1 = initializer_constant_valid_p (op1, endtype); 4308 if (!op0)
4144 4309 return NULL_TREE;
4310
4311 op1 = initializer_constant_valid_p_1 (op1, endtype,
4312 cache ? cache + 2 : NULL);
4145 /* Both initializers must be known. */ 4313 /* Both initializers must be known. */
4146 if (op0 && op1) 4314 if (op1)
4147 { 4315 {
4148 if (op0 == op1 4316 if (op0 == op1
4149 && (op0 == null_pointer_node 4317 && (op0 == null_pointer_node
4150 || TREE_CODE (value) == MINUS_EXPR)) 4318 || TREE_CODE (value) == MINUS_EXPR))
4151 return null_pointer_node; 4319 return null_pointer_node;
4162 } 4330 }
4163 4331
4164 return NULL_TREE; 4332 return NULL_TREE;
4165 } 4333 }
4166 4334
4167 /* Return nonzero if VALUE is a valid constant-valued expression 4335 /* Helper function of initializer_constant_valid_p.
4336 Return nonzero if VALUE is a valid constant-valued expression
4168 for use in initializing a static variable; one that can be an 4337 for use in initializing a static variable; one that can be an
4169 element of a "constant" initializer. 4338 element of a "constant" initializer.
4170 4339
4171 Return null_pointer_node if the value is absolute; 4340 Return null_pointer_node if the value is absolute;
4172 if it is relocatable, return the variable that determines the relocation. 4341 if it is relocatable, return the variable that determines the relocation.
4173 We assume that VALUE has been folded as much as possible; 4342 We assume that VALUE has been folded as much as possible;
4174 therefore, we do not need to check for such things as 4343 therefore, we do not need to check for such things as
4175 arithmetic-combinations of integers. */ 4344 arithmetic-combinations of integers.
4176 4345
4177 tree 4346 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4178 initializer_constant_valid_p (tree value, tree endtype) 4347
4348 static tree
4349 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4179 { 4350 {
4180 tree ret; 4351 tree ret;
4181 4352
4182 switch (TREE_CODE (value)) 4353 switch (TREE_CODE (value))
4183 { 4354 {
4186 { 4357 {
4187 unsigned HOST_WIDE_INT idx; 4358 unsigned HOST_WIDE_INT idx;
4188 tree elt; 4359 tree elt;
4189 bool absolute = true; 4360 bool absolute = true;
4190 4361
4362 if (cache && cache[0] == value)
4363 return cache[1];
4191 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt) 4364 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4192 { 4365 {
4193 tree reloc; 4366 tree reloc;
4194 reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt)); 4367 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4368 NULL);
4195 if (!reloc) 4369 if (!reloc)
4196 return NULL_TREE; 4370 {
4371 if (cache)
4372 {
4373 cache[0] = value;
4374 cache[1] = NULL_TREE;
4375 }
4376 return NULL_TREE;
4377 }
4197 if (reloc != null_pointer_node) 4378 if (reloc != null_pointer_node)
4198 absolute = false; 4379 absolute = false;
4199 } 4380 }
4200 /* For a non-absolute relocation, there is no single 4381 /* For a non-absolute relocation, there is no single
4201 variable that can be "the variable that determines the 4382 variable that can be "the variable that determines the
4202 relocation." */ 4383 relocation." */
4384 if (cache)
4385 {
4386 cache[0] = value;
4387 cache[1] = absolute ? null_pointer_node : error_mark_node;
4388 }
4203 return absolute ? null_pointer_node : error_mark_node; 4389 return absolute ? null_pointer_node : error_mark_node;
4204 } 4390 }
4205 4391
4206 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE; 4392 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4207 4393
4237 } 4423 }
4238 return op0; 4424 return op0;
4239 } 4425 }
4240 4426
4241 case NON_LVALUE_EXPR: 4427 case NON_LVALUE_EXPR:
4242 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); 4428 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4429 endtype, cache);
4243 4430
4244 case VIEW_CONVERT_EXPR: 4431 case VIEW_CONVERT_EXPR:
4245 { 4432 {
4246 tree src = TREE_OPERAND (value, 0); 4433 tree src = TREE_OPERAND (value, 0);
4247 tree src_type = TREE_TYPE (src); 4434 tree src_type = TREE_TYPE (src);
4252 RTL expander won't be able to apply a subsequent transformation 4439 RTL expander won't be able to apply a subsequent transformation
4253 to the underlying constructor. */ 4440 to the underlying constructor. */
4254 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type)) 4441 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4255 { 4442 {
4256 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type)) 4443 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4257 return initializer_constant_valid_p (src, endtype); 4444 return initializer_constant_valid_p_1 (src, endtype, cache);
4258 else 4445 else
4259 return NULL_TREE; 4446 return NULL_TREE;
4260 } 4447 }
4261 4448
4262 /* Allow all other kinds of view-conversion. */ 4449 /* Allow all other kinds of view-conversion. */
4263 return initializer_constant_valid_p (src, endtype); 4450 return initializer_constant_valid_p_1 (src, endtype, cache);
4264 } 4451 }
4265 4452
4266 CASE_CONVERT: 4453 CASE_CONVERT:
4267 { 4454 {
4268 tree src = TREE_OPERAND (value, 0); 4455 tree src = TREE_OPERAND (value, 0);
4273 types, and offset types. */ 4460 types, and offset types. */
4274 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)) 4461 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4275 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type)) 4462 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4276 || (TREE_CODE (dest_type) == OFFSET_TYPE 4463 || (TREE_CODE (dest_type) == OFFSET_TYPE
4277 && TREE_CODE (src_type) == OFFSET_TYPE)) 4464 && TREE_CODE (src_type) == OFFSET_TYPE))
4278 return initializer_constant_valid_p (src, endtype); 4465 return initializer_constant_valid_p_1 (src, endtype, cache);
4279 4466
4280 /* Allow length-preserving conversions between integer types. */ 4467 /* Allow length-preserving conversions between integer types. */
4281 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type) 4468 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4282 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type))) 4469 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4283 return initializer_constant_valid_p (src, endtype); 4470 return initializer_constant_valid_p_1 (src, endtype, cache);
4284 4471
4285 /* Allow conversions between other integer types only if 4472 /* Allow conversions between other integer types only if
4286 explicit value. */ 4473 explicit value. */
4287 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)) 4474 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4288 { 4475 {
4289 tree inner = initializer_constant_valid_p (src, endtype); 4476 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4290 if (inner == null_pointer_node) 4477 if (inner == null_pointer_node)
4291 return null_pointer_node; 4478 return null_pointer_node;
4292 break; 4479 break;
4293 } 4480 }
4294 4481
4295 /* Allow (int) &foo provided int is as wide as a pointer. */ 4482 /* Allow (int) &foo provided int is as wide as a pointer. */
4296 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type) 4483 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4297 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))) 4484 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4298 return initializer_constant_valid_p (src, endtype); 4485 return initializer_constant_valid_p_1 (src, endtype, cache);
4299 4486
4300 /* Likewise conversions from int to pointers, but also allow 4487 /* Likewise conversions from int to pointers, but also allow
4301 conversions from 0. */ 4488 conversions from 0. */
4302 if ((POINTER_TYPE_P (dest_type) 4489 if ((POINTER_TYPE_P (dest_type)
4303 || TREE_CODE (dest_type) == OFFSET_TYPE) 4490 || TREE_CODE (dest_type) == OFFSET_TYPE)
4307 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)) 4494 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4308 return null_pointer_node; 4495 return null_pointer_node;
4309 if (integer_zerop (src)) 4496 if (integer_zerop (src))
4310 return null_pointer_node; 4497 return null_pointer_node;
4311 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)) 4498 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4312 return initializer_constant_valid_p (src, endtype); 4499 return initializer_constant_valid_p_1 (src, endtype, cache);
4313 } 4500 }
4314 4501
4315 /* Allow conversions to struct or union types if the value 4502 /* Allow conversions to struct or union types if the value
4316 inside is okay. */ 4503 inside is okay. */
4317 if (TREE_CODE (dest_type) == RECORD_TYPE 4504 if (TREE_CODE (dest_type) == RECORD_TYPE
4318 || TREE_CODE (dest_type) == UNION_TYPE) 4505 || TREE_CODE (dest_type) == UNION_TYPE)
4319 return initializer_constant_valid_p (src, endtype); 4506 return initializer_constant_valid_p_1 (src, endtype, cache);
4320 } 4507 }
4321 break; 4508 break;
4322 4509
4323 case POINTER_PLUS_EXPR: 4510 case POINTER_PLUS_EXPR:
4324 case PLUS_EXPR: 4511 case PLUS_EXPR:
4325 /* Any valid floating-point constants will have been folded by now; 4512 /* Any valid floating-point constants will have been folded by now;
4326 with -frounding-math we hit this with addition of two constants. */ 4513 with -frounding-math we hit this with addition of two constants. */
4327 if (TREE_CODE (endtype) == REAL_TYPE) 4514 if (TREE_CODE (endtype) == REAL_TYPE)
4328 return NULL_TREE; 4515 return NULL_TREE;
4516 if (cache && cache[0] == value)
4517 return cache[1];
4329 if (! INTEGRAL_TYPE_P (endtype) 4518 if (! INTEGRAL_TYPE_P (endtype)
4330 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value))) 4519 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4331 { 4520 {
4332 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), 4521 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4333 endtype); 4522 tree valid0
4334 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), 4523 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4335 endtype); 4524 endtype, ncache);
4525 tree valid1
4526 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4527 endtype, ncache + 2);
4336 /* If either term is absolute, use the other term's relocation. */ 4528 /* If either term is absolute, use the other term's relocation. */
4337 if (valid0 == null_pointer_node) 4529 if (valid0 == null_pointer_node)
4338 return valid1; 4530 ret = valid1;
4339 if (valid1 == null_pointer_node) 4531 else if (valid1 == null_pointer_node)
4340 return valid0; 4532 ret = valid0;
4533 /* Support narrowing pointer differences. */
4534 else
4535 ret = narrowing_initializer_constant_valid_p (value, endtype,
4536 ncache);
4341 } 4537 }
4342 4538 else
4343 /* Support narrowing pointer differences. */ 4539 /* Support narrowing pointer differences. */
4344 ret = narrowing_initializer_constant_valid_p (value, endtype); 4540 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4345 if (ret != NULL_TREE) 4541 if (cache)
4346 return ret; 4542 {
4347 4543 cache[0] = value;
4348 break; 4544 cache[1] = ret;
4545 }
4546 return ret;
4349 4547
4350 case MINUS_EXPR: 4548 case MINUS_EXPR:
4351 if (TREE_CODE (endtype) == REAL_TYPE) 4549 if (TREE_CODE (endtype) == REAL_TYPE)
4352 return NULL_TREE; 4550 return NULL_TREE;
4551 if (cache && cache[0] == value)
4552 return cache[1];
4353 if (! INTEGRAL_TYPE_P (endtype) 4553 if (! INTEGRAL_TYPE_P (endtype)
4354 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value))) 4554 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4355 { 4555 {
4356 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), 4556 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4357 endtype); 4557 tree valid0
4358 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), 4558 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4359 endtype); 4559 endtype, ncache);
4560 tree valid1
4561 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4562 endtype, ncache + 2);
4360 /* Win if second argument is absolute. */ 4563 /* Win if second argument is absolute. */
4361 if (valid1 == null_pointer_node) 4564 if (valid1 == null_pointer_node)
4362 return valid0; 4565 ret = valid0;
4363 /* Win if both arguments have the same relocation. 4566 /* Win if both arguments have the same relocation.
4364 Then the value is absolute. */ 4567 Then the value is absolute. */
4365 if (valid0 == valid1 && valid0 != 0) 4568 else if (valid0 == valid1 && valid0 != 0)
4366 return null_pointer_node; 4569 ret = null_pointer_node;
4367
4368 /* Since GCC guarantees that string constants are unique in the 4570 /* Since GCC guarantees that string constants are unique in the
4369 generated code, a subtraction between two copies of the same 4571 generated code, a subtraction between two copies of the same
4370 constant string is absolute. */ 4572 constant string is absolute. */
4371 if (valid0 && TREE_CODE (valid0) == STRING_CST 4573 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4372 && valid1 && TREE_CODE (valid1) == STRING_CST 4574 && valid1 && TREE_CODE (valid1) == STRING_CST
4373 && operand_equal_p (valid0, valid1, 1)) 4575 && operand_equal_p (valid0, valid1, 1))
4374 return null_pointer_node; 4576 ret = null_pointer_node;
4577 /* Support narrowing differences. */
4578 else
4579 ret = narrowing_initializer_constant_valid_p (value, endtype,
4580 ncache);
4375 } 4581 }
4376 4582 else
4377 /* Support narrowing differences. */ 4583 /* Support narrowing differences. */
4378 ret = narrowing_initializer_constant_valid_p (value, endtype); 4584 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4379 if (ret != NULL_TREE) 4585 if (cache)
4380 return ret; 4586 {
4381 4587 cache[0] = value;
4382 break; 4588 cache[1] = ret;
4589 }
4590 return ret;
4383 4591
4384 default: 4592 default:
4385 break; 4593 break;
4386 } 4594 }
4387 4595
4388 return 0; 4596 return NULL_TREE;
4597 }
4598
4599 /* Return nonzero if VALUE is a valid constant-valued expression
4600 for use in initializing a static variable; one that can be an
4601 element of a "constant" initializer.
4602
4603 Return null_pointer_node if the value is absolute;
4604 if it is relocatable, return the variable that determines the relocation.
4605 We assume that VALUE has been folded as much as possible;
4606 therefore, we do not need to check for such things as
4607 arithmetic-combinations of integers. */
4608 tree
4609 initializer_constant_valid_p (tree value, tree endtype)
4610 {
4611 return initializer_constant_valid_p_1 (value, endtype, NULL);
4389 } 4612 }
4390 4613
4391 /* Return true if VALUE is a valid constant-valued expression 4614 /* Return true if VALUE is a valid constant-valued expression
4392 for use in initializing a static bit-field; one that can be 4615 for use in initializing a static bit-field; one that can be
4393 an element of a "constant" initializer. */ 4616 an element of a "constant" initializer. */
5225 error ("weak declaration of %q+D must precede definition", decl); 5448 error ("weak declaration of %q+D must precede definition", decl);
5226 else if (!SUPPORTS_WEAK) 5449 else if (!SUPPORTS_WEAK)
5227 warning (0, "weak declaration of %q+D not supported", decl); 5450 warning (0, "weak declaration of %q+D not supported", decl);
5228 5451
5229 mark_weak (decl); 5452 mark_weak (decl);
5453 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
5454 DECL_ATTRIBUTES (decl)
5455 = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
5230 } 5456 }
5231 5457
5232 static void 5458 static void
5233 weak_finish_1 (tree decl) 5459 weak_finish_1 (tree decl)
5234 { 5460 {
5423 return fnode->decl; 5649 return fnode->decl;
5424 } 5650 }
5425 else if (vnode) 5651 else if (vnode)
5426 { 5652 {
5427 varpool_mark_needed_node (vnode); 5653 varpool_mark_needed_node (vnode);
5654 vnode->force_output = 1;
5428 return vnode->decl; 5655 return vnode->decl;
5429 } 5656 }
5430 else 5657 else
5431 return NULL_TREE; 5658 return NULL_TREE;
5432 } 5659 }
5438 static void 5665 static void
5439 do_assemble_alias (tree decl, tree target) 5666 do_assemble_alias (tree decl, tree target)
5440 { 5667 {
5441 if (TREE_ASM_WRITTEN (decl)) 5668 if (TREE_ASM_WRITTEN (decl))
5442 return; 5669 return;
5670
5671 /* We must force creation of DECL_RTL for debug info generation, even though
5672 we don't use it here. */
5673 make_decl_rtl (decl);
5443 5674
5444 TREE_ASM_WRITTEN (decl) = 1; 5675 TREE_ASM_WRITTEN (decl) = 1;
5445 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1; 5676 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5446 5677
5447 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))) 5678 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
5656 return; 5887 return;
5657 } 5888 }
5658 # endif 5889 # endif
5659 #endif 5890 #endif
5660 } 5891 }
5661
5662 /* We must force creation of DECL_RTL for debug info generation, even though
5663 we don't use it here. */
5664 make_decl_rtl (decl);
5665 TREE_USED (decl) = 1; 5892 TREE_USED (decl) = 1;
5666 5893
5667 /* A quirk of the initial implementation of aliases required that the user 5894 /* A quirk of the initial implementation of aliases required that the user
5668 add "extern" to all of them. Which is silly, but now historical. Do 5895 add "extern" to all of them. Which is silly, but now historical. Do
5669 note that the symbol is in fact locally defined. */ 5896 note that the symbol is in fact locally defined. */
5694 5921
5695 /* Emit an assembler directive to set symbol for DECL visibility to 5922 /* Emit an assembler directive to set symbol for DECL visibility to
5696 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */ 5923 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5697 5924
5698 void 5925 void
5699 default_assemble_visibility (tree decl, int vis) 5926 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
5700 { 5927 int vis ATTRIBUTE_UNUSED)
5928 {
5929 #ifdef HAVE_GAS_HIDDEN
5701 static const char * const visibility_types[] = { 5930 static const char * const visibility_types[] = {
5702 NULL, "protected", "hidden", "internal" 5931 NULL, "protected", "hidden", "internal"
5703 }; 5932 };
5704 5933
5705 const char *name, *type; 5934 const char *name, *type;
5706 5935
5707 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); 5936 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5708 type = visibility_types[vis]; 5937 type = visibility_types[vis];
5709 5938
5710 #ifdef HAVE_GAS_HIDDEN
5711 fprintf (asm_out_file, "\t.%s\t", type); 5939 fprintf (asm_out_file, "\t.%s\t", type);
5712 assemble_name (asm_out_file, name); 5940 assemble_name (asm_out_file, name);
5713 fprintf (asm_out_file, "\n"); 5941 fprintf (asm_out_file, "\n");
5714 #else 5942 #else
5715 warning (OPT_Wattributes, "visibility attribute not supported " 5943 warning (OPT_Wattributes, "visibility attribute not supported "
5961 /* Some object formats don't support named sections at all. The 6189 /* Some object formats don't support named sections at all. The
5962 front-end should already have flagged this as an error. */ 6190 front-end should already have flagged this as an error. */
5963 gcc_unreachable (); 6191 gcc_unreachable ();
5964 } 6192 }
5965 6193
6194 #ifndef TLS_SECTION_ASM_FLAG
6195 #define TLS_SECTION_ASM_FLAG 'T'
6196 #endif
6197
5966 void 6198 void
5967 default_elf_asm_named_section (const char *name, unsigned int flags, 6199 default_elf_asm_named_section (const char *name, unsigned int flags,
5968 tree decl ATTRIBUTE_UNUSED) 6200 tree decl ATTRIBUTE_UNUSED)
5969 { 6201 {
5970 char flagchars[10], *f = flagchars; 6202 char flagchars[10], *f = flagchars;
5991 if (flags & SECTION_MERGE) 6223 if (flags & SECTION_MERGE)
5992 *f++ = 'M'; 6224 *f++ = 'M';
5993 if (flags & SECTION_STRINGS) 6225 if (flags & SECTION_STRINGS)
5994 *f++ = 'S'; 6226 *f++ = 'S';
5995 if (flags & SECTION_TLS) 6227 if (flags & SECTION_TLS)
5996 *f++ = 'T'; 6228 *f++ = TLS_SECTION_ASM_FLAG;
5997 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) 6229 if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
5998 *f++ = 'G'; 6230 *f++ = 'G';
5999 *f = '\0'; 6231 *f = '\0';
6000 6232
6001 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); 6233 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
6735 size = GET_MODE_SIZE (desc->mode); 6967 size = GET_MODE_SIZE (desc->mode);
6736 } 6968 }
6737 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol)) 6969 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6738 { 6970 {
6739 decl = SYMBOL_REF_DECL (symbol); 6971 decl = SYMBOL_REF_DECL (symbol);
6740 alignment = get_constant_alignment (decl); 6972 alignment = DECL_ALIGN (decl);
6741 size = get_constant_size (decl); 6973 size = get_constant_size (DECL_INITIAL (decl));
6742 } 6974 }
6743 else 6975 else
6744 { 6976 {
6745 decl = SYMBOL_REF_DECL (symbol); 6977 decl = SYMBOL_REF_DECL (symbol);
6746 alignment = DECL_ALIGN (decl); 6978 alignment = DECL_ALIGN (decl);
6882 offset += GET_MODE_SIZE (desc->mode); 7114 offset += GET_MODE_SIZE (desc->mode);
6883 } 7115 }
6884 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol)) 7116 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
6885 { 7117 {
6886 decl = SYMBOL_REF_DECL (symbol); 7118 decl = SYMBOL_REF_DECL (symbol);
6887 assemble_constant_contents (decl, XSTR (symbol, 0), 7119 assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
6888 get_constant_alignment (decl)); 7120 DECL_ALIGN (decl));
6889 offset += get_constant_size (decl); 7121 offset += get_constant_size (DECL_INITIAL (decl));
6890 } 7122 }
6891 else 7123 else
6892 { 7124 {
6893 decl = SYMBOL_REF_DECL (symbol); 7125 decl = SYMBOL_REF_DECL (symbol);
6894 assemble_variable_contents (decl, XSTR (symbol, 0), false); 7126 assemble_variable_contents (decl, XSTR (symbol, 0), false);
7029 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) 7261 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
7030 && targetm.binds_local_p (decl)) 7262 && targetm.binds_local_p (decl))
7031 maybe_assemble_visibility (decl); 7263 maybe_assemble_visibility (decl);
7032 } 7264 }
7033 7265
7266 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7267 EXP. */
7268 rtx
7269 make_debug_expr_from_rtl (const_rtx exp)
7270 {
7271 tree ddecl = make_node (DEBUG_EXPR_DECL), type;
7272 enum machine_mode mode = GET_MODE (exp);
7273 rtx dval;
7274
7275 DECL_ARTIFICIAL (ddecl) = 1;
7276 if (REG_P (exp) && REG_EXPR (exp))
7277 type = TREE_TYPE (REG_EXPR (exp));
7278 else if (MEM_P (exp) && MEM_EXPR (exp))
7279 type = TREE_TYPE (MEM_EXPR (exp));
7280 else
7281 type = NULL_TREE;
7282 if (type && TYPE_MODE (type) == mode)
7283 TREE_TYPE (ddecl) = type;
7284 else
7285 TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
7286 DECL_MODE (ddecl) = mode;
7287 dval = gen_rtx_DEBUG_EXPR (mode);
7288 DEBUG_EXPR_TREE_DECL (dval) = ddecl;
7289 SET_DECL_RTL (ddecl, dval);
7290 return dval;
7291 }
7292
7034 #include "gt-varasm.h" 7293 #include "gt-varasm.h"