1 /* Output variables, constants and external declarations, for GNU compiler.
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,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
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
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
45 #include "langhooks.h"
49 #include "targhooks.h"
50 #include "tree-mudflap.h"
52 #include "cfglayout.h"
53 #include "basic-block.h"
54 #include "tree-iterator.h"
56 #ifdef XCOFF_DEBUGGING_INFO
57 #include "xcoffout.h" /* Needed for external data
58 declarations for e.g. AIX 4.x. */
61 /* The (assembler) name of the first globally-visible object output. */
62 extern GTY(()) const char *first_global_object_name
;
63 extern GTY(()) const char *weak_global_object_name
;
65 const char *first_global_object_name
;
66 const char *weak_global_object_name
;
69 struct constant_descriptor_rtx
;
70 struct rtx_constant_pool
;
72 #define n_deferred_constants (crtl->varasm.deferred_constants)
74 /* Number for making the label on the next
75 constant that is stored in memory. */
77 static GTY(()) int const_labelno
;
79 /* Carry information from ASM_DECLARE_OBJECT_NAME
80 to ASM_FINISH_DECLARE_OBJECT. */
82 int size_directive_output
;
84 /* The last decl for which assemble_variable was called,
85 if it did ASM_DECLARE_OBJECT_NAME.
86 If the last call to assemble_variable didn't do that,
89 tree last_assemble_variable_decl
;
91 /* The following global variable indicates if the first basic block
92 in a function belongs to the cold partition or not. */
94 bool first_function_block_is_cold
;
96 /* We give all constants their own alias set. Perhaps redundant with
97 MEM_READONLY_P, but pre-dates it. */
99 static alias_set_type const_alias_set
;
101 static const char *strip_reg_name (const char *);
102 static int contains_pointers_p (tree
);
103 #ifdef ASM_OUTPUT_EXTERNAL
104 static bool incorporeal_function_p (tree
);
106 static void decode_addr_const (tree
, struct addr_const
*);
107 static hashval_t
const_desc_hash (const void *);
108 static int const_desc_eq (const void *, const void *);
109 static hashval_t
const_hash_1 (const tree
);
110 static int compare_constant (const tree
, const tree
);
111 static tree
copy_constant (tree
);
112 static void output_constant_def_contents (rtx
);
113 static void output_addressed_constants (tree
);
114 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
115 static unsigned min_align (unsigned, unsigned);
116 static void globalize_decl (tree
);
117 #ifdef BSS_SECTION_ASM_OP
118 #ifdef ASM_OUTPUT_BSS
119 static void asm_output_bss (FILE *, tree
, const char *,
120 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
122 #ifdef ASM_OUTPUT_ALIGNED_BSS
123 static void asm_output_aligned_bss (FILE *, tree
, const char *,
124 unsigned HOST_WIDE_INT
, int)
127 #endif /* BSS_SECTION_ASM_OP */
128 static void mark_weak (tree
);
129 static void output_constant_pool (const char *, tree
);
131 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
132 section
*text_section
;
133 section
*data_section
;
134 section
*readonly_data_section
;
135 section
*sdata_section
;
136 section
*ctors_section
;
137 section
*dtors_section
;
138 section
*bss_section
;
139 section
*sbss_section
;
141 /* Various forms of common section. All are guaranteed to be nonnull. */
142 section
*tls_comm_section
;
143 section
*comm_section
;
144 section
*lcomm_section
;
146 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148 section
*bss_noswitch_section
;
150 /* The section that holds the main exception table, when known. The section
151 is set either by the target's init_sections hook or by the first call to
152 switch_to_exception_section. */
153 section
*exception_section
;
155 /* The section that holds the DWARF2 frame unwind information, when known.
156 The section is set either by the target's init_sections hook or by the
157 first call to switch_to_eh_frame_section. */
158 section
*eh_frame_section
;
160 /* asm_out_file's current section. This is NULL if no section has yet
161 been selected or if we lose track of what the current section is. */
164 /* True if code for the current function is currently being directed
165 at the cold section. */
166 bool in_cold_section_p
;
168 /* A linked list of all the unnamed sections. */
169 static GTY(()) section
*unnamed_sections
;
171 /* Return a nonzero value if DECL has a section attribute. */
172 #define IN_NAMED_SECTION(DECL) \
173 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
174 && DECL_SECTION_NAME (DECL) != NULL_TREE)
176 /* Hash table of named sections. */
177 static GTY((param_is (section
))) htab_t section_htab
;
179 /* A table of object_blocks, indexed by section. */
180 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
182 /* The next number to use for internal anchor labels. */
183 static GTY(()) int anchor_labelno
;
185 /* A pool of constants that can be shared between functions. */
186 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
190 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
192 static GTY (()) tree emutls_object_type
;
193 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
194 macro can be used on them to distinguish the control variable from
195 the initialization template. */
196 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
198 #if !defined (NO_DOT_IN_LABEL)
199 # define EMUTLS_SEPARATOR "."
200 #elif !defined (NO_DOLLAR_IN_LABEL)
201 # define EMUTLS_SEPARATOR "$"
203 # define EMUTLS_SEPARATOR "_"
206 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
207 IDENTIFIER_NODE NAME's name. */
210 prefix_name (const char *prefix
, tree name
)
212 unsigned plen
= strlen (prefix
);
213 unsigned nlen
= strlen (IDENTIFIER_POINTER (name
));
214 char *toname
= (char *) alloca (plen
+ nlen
+ 1);
216 memcpy (toname
, prefix
, plen
);
217 memcpy (toname
+ plen
, IDENTIFIER_POINTER (name
), nlen
+ 1);
219 return get_identifier (toname
);
222 /* Create an identifier for the struct __emutls_object, given an identifier
223 of the DECL_ASSEMBLY_NAME of the original object. */
226 get_emutls_object_name (tree name
)
228 const char *prefix
= (targetm
.emutls
.var_prefix
229 ? targetm
.emutls
.var_prefix
230 : "__emutls_v" EMUTLS_SEPARATOR
);
231 return prefix_name (prefix
, name
);
235 default_emutls_var_fields (tree type
, tree
*name ATTRIBUTE_UNUSED
)
237 tree word_type_node
, field
, next_field
;
239 field
= build_decl (UNKNOWN_LOCATION
,
240 FIELD_DECL
, get_identifier ("__templ"), ptr_type_node
);
241 DECL_CONTEXT (field
) = type
;
244 field
= build_decl (UNKNOWN_LOCATION
,
245 FIELD_DECL
, get_identifier ("__offset"),
247 DECL_CONTEXT (field
) = type
;
248 TREE_CHAIN (field
) = next_field
;
251 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
252 field
= build_decl (UNKNOWN_LOCATION
,
253 FIELD_DECL
, get_identifier ("__align"),
255 DECL_CONTEXT (field
) = type
;
256 TREE_CHAIN (field
) = next_field
;
259 field
= build_decl (UNKNOWN_LOCATION
,
260 FIELD_DECL
, get_identifier ("__size"), word_type_node
);
261 DECL_CONTEXT (field
) = type
;
262 TREE_CHAIN (field
) = next_field
;
267 /* Create the structure for struct __emutls_object. This should match the
268 structure at the top of emutls.c, modulo the union there. */
271 get_emutls_object_type (void)
273 tree type
, type_name
, field
;
275 type
= emutls_object_type
;
279 emutls_object_type
= type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
281 field
= targetm
.emutls
.var_fields (type
, &type_name
);
283 type_name
= get_identifier ("__emutls_object");
284 type_name
= build_decl (UNKNOWN_LOCATION
,
285 TYPE_DECL
, type_name
, type
);
286 TYPE_NAME (type
) = type_name
;
287 TYPE_FIELDS (type
) = field
;
293 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
294 This will be used for initializing the emulated tls data area. */
297 get_emutls_init_templ_addr (tree decl
)
301 if (targetm
.emutls
.register_common
&& !DECL_INITIAL (decl
)
302 && !DECL_SECTION_NAME (decl
))
303 return null_pointer_node
;
305 name
= DECL_ASSEMBLER_NAME (decl
);
306 if (!targetm
.emutls
.tmpl_prefix
|| targetm
.emutls
.tmpl_prefix
[0])
308 const char *prefix
= (targetm
.emutls
.tmpl_prefix
309 ? targetm
.emutls
.tmpl_prefix
310 : "__emutls_t" EMUTLS_SEPARATOR
);
311 name
= prefix_name (prefix
, name
);
314 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
315 VAR_DECL
, name
, TREE_TYPE (decl
));
316 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
317 DECL_TLS_MODEL (to
) = TLS_MODEL_EMULATED
;
318 DECL_ARTIFICIAL (to
) = 1;
319 TREE_USED (to
) = TREE_USED (decl
);
320 TREE_READONLY (to
) = 1;
321 DECL_IGNORED_P (to
) = 1;
322 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
323 DECL_SECTION_NAME (to
) = DECL_SECTION_NAME (decl
);
325 DECL_WEAK (to
) = DECL_WEAK (decl
);
326 if (DECL_ONE_ONLY (decl
))
328 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
329 TREE_STATIC (to
) = TREE_STATIC (decl
);
330 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
331 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
334 TREE_STATIC (to
) = 1;
336 DECL_INITIAL (to
) = DECL_INITIAL (decl
);
337 DECL_INITIAL (decl
) = NULL
;
339 varpool_finalize_decl (to
);
340 return build_fold_addr_expr (to
);
343 /* When emulating tls, we use a control structure for use by the runtime.
344 Create and return this structure. */
347 emutls_decl (tree decl
)
350 struct tree_map
*h
, in
;
353 if (targetm
.have_tls
|| decl
== NULL
|| decl
== error_mark_node
354 || TREE_CODE (decl
) != VAR_DECL
|| ! DECL_THREAD_LOCAL_P (decl
))
357 /* Look up the object in the hash; return the control structure if
358 it has already been created. */
360 emutls_htab
= htab_create_ggc (512, tree_map_hash
, tree_map_eq
, 0);
362 name
= DECL_ASSEMBLER_NAME (decl
);
364 /* Note that we use the hash of the decl's name, rather than a hash
365 of the decl's pointer. In emutls_finish we iterate through the
366 hash table, and we want this traversal to be predictable. */
367 in
.hash
= IDENTIFIER_HASH_VALUE (name
);
369 loc
= htab_find_slot_with_hash (emutls_htab
, &in
, in
.hash
, INSERT
);
370 h
= (struct tree_map
*) *loc
;
375 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
376 VAR_DECL
, get_emutls_object_name (name
),
377 get_emutls_object_type ());
379 h
= GGC_NEW (struct tree_map
);
383 *(struct tree_map
**) loc
= h
;
385 DECL_TLS_MODEL (to
) = TLS_MODEL_EMULATED
;
386 DECL_ARTIFICIAL (to
) = 1;
387 DECL_IGNORED_P (to
) = 1;
388 TREE_READONLY (to
) = 0;
389 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
390 if (DECL_ONE_ONLY (decl
))
391 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
392 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
393 if (targetm
.emutls
.var_align_fixed
)
394 /* If we're not allowed to change the proxy object's
395 alignment, pretend it's been set by the user. */
396 DECL_USER_ALIGN (to
) = 1;
399 /* Note that these fields may need to be updated from time to time from
400 the original decl. Consider:
401 extern __thread int i;
402 int foo() { return i; }
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 TREE_STATIC (to
) = TREE_STATIC (decl
);
409 TREE_USED (to
) = TREE_USED (decl
);
410 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
411 DECL_EXTERNAL (to
) = DECL_EXTERNAL (decl
);
412 DECL_COMMON (to
) = DECL_COMMON (decl
);
413 DECL_WEAK (to
) = DECL_WEAK (decl
);
414 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
420 emutls_common_1 (void **loc
, void *xstmts
)
422 struct tree_map
*h
= *(struct tree_map
**) loc
;
423 tree args
, x
, *pstmts
= (tree
*) xstmts
;
426 if (! DECL_COMMON (h
->base
.from
)
427 || (DECL_INITIAL (h
->base
.from
)
428 && DECL_INITIAL (h
->base
.from
) != error_mark_node
))
431 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
433 /* The idea was to call get_emutls_init_templ_addr here, but if we
434 do this and there is an initializer, -fanchor_section loses,
435 because it would be too late to ensure the template is
437 x
= null_pointer_node
;
438 args
= tree_cons (NULL
, x
, NULL
);
439 x
= build_int_cst (word_type_node
, DECL_ALIGN_UNIT (h
->base
.from
));
440 args
= tree_cons (NULL
, x
, args
);
441 x
= fold_convert (word_type_node
, DECL_SIZE_UNIT (h
->base
.from
));
442 args
= tree_cons (NULL
, x
, args
);
443 x
= build_fold_addr_expr (h
->to
);
444 args
= tree_cons (NULL
, x
, args
);
446 x
= built_in_decls
[BUILT_IN_EMUTLS_REGISTER_COMMON
];
447 x
= build_function_call_expr (UNKNOWN_LOCATION
, x
, args
);
449 append_to_statement_list (x
, pstmts
);
456 if (targetm
.emutls
.register_common
)
458 tree body
= NULL_TREE
;
460 if (emutls_htab
== NULL
)
463 htab_traverse_noresize (emutls_htab
, emutls_common_1
, &body
);
464 if (body
== NULL_TREE
)
467 cgraph_build_static_cdtor ('I', body
, DEFAULT_INIT_PRIORITY
);
471 /* Helper routines for maintaining section_htab. */
474 section_entry_eq (const void *p1
, const void *p2
)
476 const section
*old
= (const section
*) p1
;
477 const char *new_name
= (const char *) p2
;
479 return strcmp (old
->named
.name
, new_name
) == 0;
483 section_entry_hash (const void *p
)
485 const section
*old
= (const section
*) p
;
486 return htab_hash_string (old
->named
.name
);
489 /* Return a hash value for section SECT. */
492 hash_section (section
*sect
)
494 if (sect
->common
.flags
& SECTION_NAMED
)
495 return htab_hash_string (sect
->named
.name
);
496 return sect
->common
.flags
;
499 /* Helper routines for maintaining object_block_htab. */
502 object_block_entry_eq (const void *p1
, const void *p2
)
504 const struct object_block
*old
= (const struct object_block
*) p1
;
505 const section
*new_section
= (const section
*) p2
;
507 return old
->sect
== new_section
;
511 object_block_entry_hash (const void *p
)
513 const struct object_block
*old
= (const struct object_block
*) p
;
514 return hash_section (old
->sect
);
517 /* Return a new unnamed section with the given fields. */
520 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
525 sect
= GGC_NEW (section
);
526 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
527 sect
->unnamed
.callback
= callback
;
528 sect
->unnamed
.data
= data
;
529 sect
->unnamed
.next
= unnamed_sections
;
531 unnamed_sections
= sect
;
535 /* Return a SECTION_NOSWITCH section with the given fields. */
538 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
542 sect
= GGC_NEW (section
);
543 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
544 sect
->noswitch
.callback
= callback
;
549 /* Return the named section structure associated with NAME. Create
550 a new section with the given fields if no such structure exists. */
553 get_section (const char *name
, unsigned int flags
, tree decl
)
555 section
*sect
, **slot
;
558 htab_find_slot_with_hash (section_htab
, name
,
559 htab_hash_string (name
), INSERT
);
560 flags
|= SECTION_NAMED
;
563 sect
= GGC_NEW (section
);
564 sect
->named
.common
.flags
= flags
;
565 sect
->named
.name
= ggc_strdup (name
);
566 sect
->named
.decl
= decl
;
572 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
573 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
575 /* Sanity check user variables for flag changes. */
577 decl
= sect
->named
.decl
;
579 error ("%+D causes a section type conflict", decl
);
585 /* Return true if the current compilation mode benefits from having
586 objects grouped into blocks. */
589 use_object_blocks_p (void)
591 return flag_section_anchors
;
594 /* Return the object_block structure for section SECT. Create a new
595 structure if we haven't created one already. Return null if SECT
598 static struct object_block
*
599 get_block_for_section (section
*sect
)
601 struct object_block
*block
;
607 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
608 hash_section (sect
), INSERT
);
609 block
= (struct object_block
*) *slot
;
612 block
= (struct object_block
*)
613 ggc_alloc_cleared (sizeof (struct object_block
));
620 /* Create a symbol with label LABEL and place it at byte offset
621 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
622 is not yet known. LABEL must be a garbage-collected string. */
625 create_block_symbol (const char *label
, struct object_block
*block
,
626 HOST_WIDE_INT offset
)
631 /* Create the extended SYMBOL_REF. */
632 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
633 symbol
= (rtx
) ggc_alloc_zone (size
, &rtl_zone
);
635 /* Initialize the normal SYMBOL_REF fields. */
636 memset (symbol
, 0, size
);
637 PUT_CODE (symbol
, SYMBOL_REF
);
638 PUT_MODE (symbol
, Pmode
);
639 XSTR (symbol
, 0) = label
;
640 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
642 /* Initialize the block_symbol stuff. */
643 SYMBOL_REF_BLOCK (symbol
) = block
;
644 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
650 initialize_cold_section_name (void)
652 const char *stripped_name
;
656 gcc_assert (cfun
&& current_function_decl
);
657 if (crtl
->subsections
.unlikely_text_section_name
)
660 dsn
= DECL_SECTION_NAME (current_function_decl
);
661 if (flag_function_sections
&& dsn
)
663 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
664 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
666 stripped_name
= targetm
.strip_name_encoding (name
);
668 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
669 crtl
->subsections
.unlikely_text_section_name
= ggc_strdup (buffer
);
672 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
675 /* Tell assembler to switch to unlikely-to-be-executed text section. */
678 unlikely_text_section (void)
682 if (!crtl
->subsections
.unlikely_text_section_name
)
683 initialize_cold_section_name ();
685 return get_named_section (NULL
, crtl
->subsections
.unlikely_text_section_name
, 0);
688 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
691 /* When called within a function context, return true if the function
692 has been assigned a cold text section and if SECT is that section.
693 When called outside a function context, return true if SECT is the
694 default cold section. */
697 unlikely_text_section_p (section
*sect
)
702 name
= crtl
->subsections
.unlikely_text_section_name
;
704 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
708 && SECTION_STYLE (sect
) == SECTION_NAMED
709 && strcmp (name
, sect
->named
.name
) == 0);
712 /* Return a section with a particular name and with whatever SECTION_*
713 flags section_type_flags deems appropriate. The name of the section
714 is taken from NAME if nonnull, otherwise it is taken from DECL's
715 DECL_SECTION_NAME. DECL is the decl associated with the section
716 (see the section comment for details) and RELOC is as for
717 section_type_flags. */
720 get_named_section (tree decl
, const char *name
, int reloc
)
724 gcc_assert (!decl
|| DECL_P (decl
));
726 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
728 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
730 return get_section (name
, flags
, decl
);
733 /* If required, set DECL_SECTION_NAME to a unique name. */
736 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
737 int flag_function_or_data_sections
)
739 if (DECL_SECTION_NAME (decl
) == NULL_TREE
740 && targetm
.have_named_sections
741 && (flag_function_or_data_sections
742 || DECL_ONE_ONLY (decl
)))
743 targetm
.asm_out
.unique_section (decl
, reloc
);
746 #ifdef BSS_SECTION_ASM_OP
748 #ifdef ASM_OUTPUT_BSS
750 /* Utility function for ASM_OUTPUT_BSS for targets to use if
751 they don't support alignments in .bss.
752 ??? It is believed that this function will work in most cases so such
753 support is localized here. */
756 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
758 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
759 unsigned HOST_WIDE_INT rounded
)
761 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl
), 0), 0), name
) == 0);
762 targetm
.asm_out
.globalize_decl_name (file
, decl
);
763 switch_to_section (bss_section
);
764 #ifdef ASM_DECLARE_OBJECT_NAME
765 last_assemble_variable_decl
= decl
;
766 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
768 /* Standard thing is just output label for the object. */
769 ASM_OUTPUT_LABEL (file
, name
);
770 #endif /* ASM_DECLARE_OBJECT_NAME */
771 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
776 #ifdef ASM_OUTPUT_ALIGNED_BSS
778 /* Utility function for targets to use in implementing
779 ASM_OUTPUT_ALIGNED_BSS.
780 ??? It is believed that this function will work in most cases so such
781 support is localized here. */
784 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
785 const char *name
, unsigned HOST_WIDE_INT size
,
788 switch_to_section (bss_section
);
789 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
790 #ifdef ASM_DECLARE_OBJECT_NAME
791 last_assemble_variable_decl
= decl
;
792 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
794 /* Standard thing is just output label for the object. */
795 ASM_OUTPUT_LABEL (file
, name
);
796 #endif /* ASM_DECLARE_OBJECT_NAME */
797 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
802 #endif /* BSS_SECTION_ASM_OP */
804 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
805 /* Return the hot section for function DECL. Return text_section for
809 hot_function_section (tree decl
)
811 if (decl
!= NULL_TREE
812 && DECL_SECTION_NAME (decl
) != NULL_TREE
813 && targetm
.have_named_sections
)
814 return get_named_section (decl
, NULL
, 0);
820 /* Return the section for function DECL.
822 If DECL is NULL_TREE, return the text section. We can be passed
823 NULL_TREE under some circumstances by dbxout.c at least. */
826 function_section (tree decl
)
830 if (first_function_block_is_cold
)
833 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
834 if (decl
!= NULL_TREE
835 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
836 return reloc
? unlikely_text_section ()
837 : get_named_section (decl
, NULL
, 0);
839 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
841 return reloc
? unlikely_text_section () : hot_function_section (decl
);
846 current_function_section (void)
848 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
849 if (current_function_decl
!= NULL_TREE
850 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
851 return in_cold_section_p
? unlikely_text_section ()
852 : get_named_section (current_function_decl
,
855 return targetm
.asm_out
.select_section (current_function_decl
,
857 DECL_ALIGN (current_function_decl
));
859 return (in_cold_section_p
860 ? unlikely_text_section ()
861 : hot_function_section (current_function_decl
));
865 /* Return the read-only data section associated with function DECL. */
868 default_function_rodata_section (tree decl
)
870 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
872 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
874 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
880 dot
= strchr (name
+ 1, '.');
883 len
= strlen (dot
) + 8;
884 rname
= (char *) alloca (len
);
886 strcpy (rname
, ".rodata");
888 return get_section (rname
, SECTION_LINKONCE
, decl
);
890 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
891 else if (DECL_ONE_ONLY (decl
)
892 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
894 size_t len
= strlen (name
) + 1;
895 char *rname
= (char *) alloca (len
);
897 memcpy (rname
, name
, len
);
899 return get_section (rname
, SECTION_LINKONCE
, decl
);
901 /* For .text.foo we want to use .rodata.foo. */
902 else if (flag_function_sections
&& flag_data_sections
903 && strncmp (name
, ".text.", 6) == 0)
905 size_t len
= strlen (name
) + 1;
906 char *rname
= (char *) alloca (len
+ 2);
908 memcpy (rname
, ".rodata", 7);
909 memcpy (rname
+ 7, name
+ 5, len
- 5);
910 return get_section (rname
, 0, decl
);
914 return readonly_data_section
;
917 /* Return the read-only data section associated with function DECL
918 for targets where that section should be always the single
919 readonly data section. */
922 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
924 return readonly_data_section
;
927 /* Return the section to use for string merging. */
930 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
931 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
932 unsigned int flags ATTRIBUTE_UNUSED
)
936 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
937 && TREE_CODE (decl
) == STRING_CST
938 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
940 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
941 && TREE_STRING_LENGTH (decl
) >= len
)
943 enum machine_mode mode
;
944 unsigned int modesize
;
950 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
951 modesize
= GET_MODE_BITSIZE (mode
);
952 if (modesize
>= 8 && modesize
<= 256
953 && (modesize
& (modesize
- 1)) == 0)
955 if (align
< modesize
)
958 str
= TREE_STRING_POINTER (decl
);
959 unit
= GET_MODE_SIZE (mode
);
961 /* Check for embedded NUL characters. */
962 for (i
= 0; i
< len
; i
+= unit
)
964 for (j
= 0; j
< unit
; j
++)
965 if (str
[i
+ j
] != '\0')
972 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
974 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
975 return get_section (name
, flags
, NULL
);
980 return readonly_data_section
;
983 /* Return the section to use for constant merging. */
986 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
987 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
988 unsigned int flags ATTRIBUTE_UNUSED
)
990 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
992 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
998 && (align
& (align
- 1)) == 0)
1002 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
1003 flags
|= (align
/ 8) | SECTION_MERGE
;
1004 return get_section (name
, flags
, NULL
);
1006 return readonly_data_section
;
1009 /* Given NAME, a putative register name, discard any customary prefixes. */
1012 strip_reg_name (const char *name
)
1014 #ifdef REGISTER_PREFIX
1015 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
1016 name
+= strlen (REGISTER_PREFIX
);
1018 if (name
[0] == '%' || name
[0] == '#')
1023 /* The user has asked for a DECL to have a particular name. Set (or
1024 change) it in such a way that we don't prefix an underscore to
1027 set_user_assembler_name (tree decl
, const char *name
)
1029 char *starred
= (char *) alloca (strlen (name
) + 2);
1031 strcpy (starred
+ 1, name
);
1032 change_decl_assembler_name (decl
, get_identifier (starred
));
1033 SET_DECL_RTL (decl
, NULL_RTX
);
1036 /* Decode an `asm' spec for a declaration as a register name.
1037 Return the register number, or -1 if nothing specified,
1038 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1039 or -3 if ASMSPEC is `cc' and is not recognized,
1040 or -4 if ASMSPEC is `memory' and is not recognized.
1041 Accept an exact spelling or a decimal number.
1042 Prefixes such as % are optional. */
1045 decode_reg_name (const char *asmspec
)
1051 /* Get rid of confusing prefixes. */
1052 asmspec
= strip_reg_name (asmspec
);
1054 /* Allow a decimal number as a "register name". */
1055 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
1056 if (! ISDIGIT (asmspec
[i
]))
1058 if (asmspec
[0] != 0 && i
< 0)
1061 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
1067 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1069 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
1072 #ifdef ADDITIONAL_REGISTER_NAMES
1074 static const struct { const char *const name
; const int number
; } table
[]
1075 = ADDITIONAL_REGISTER_NAMES
;
1077 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1078 if (table
[i
].name
[0]
1079 && ! strcmp (asmspec
, table
[i
].name
))
1080 return table
[i
].number
;
1082 #endif /* ADDITIONAL_REGISTER_NAMES */
1084 if (!strcmp (asmspec
, "memory"))
1087 if (!strcmp (asmspec
, "cc"))
1096 /* Return true if DECL's initializer is suitable for a BSS section. */
1099 bss_initializer_p (const_tree decl
)
1101 return (DECL_INITIAL (decl
) == NULL
1102 || DECL_INITIAL (decl
) == error_mark_node
1103 || (flag_zero_initialized_in_bss
1104 /* Leave constant zeroes in .rodata so they
1106 && !TREE_READONLY (decl
)
1107 && initializer_zerop (DECL_INITIAL (decl
))));
1110 /* Compute the alignment of variable specified by DECL.
1111 DONT_OUTPUT_DATA is from assemble_variable. */
1114 align_variable (tree decl
, bool dont_output_data
)
1116 unsigned int align
= DECL_ALIGN (decl
);
1118 /* In the case for initialing an array whose length isn't specified,
1119 where we have not yet been able to do the layout,
1120 figure out the proper alignment now. */
1121 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1122 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1123 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1125 /* Some object file formats have a maximum alignment which they support.
1126 In particular, a.out format supports a maximum alignment of 4. */
1127 if (align
> MAX_OFILE_ALIGNMENT
)
1129 warning (0, "alignment of %q+D is greater than maximum object "
1130 "file alignment. Using %d", decl
,
1131 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1132 align
= MAX_OFILE_ALIGNMENT
;
1135 /* On some machines, it is good to increase alignment sometimes. */
1136 if (! DECL_USER_ALIGN (decl
))
1138 #ifdef DATA_ALIGNMENT
1139 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1140 /* Don't increase alignment too much for TLS variables - TLS space
1142 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1145 #ifdef CONSTANT_ALIGNMENT
1146 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1148 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1150 /* Don't increase alignment too much for TLS variables - TLS space
1152 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1153 align
= const_align
;
1158 /* Reset the alignment in case we have made it tighter, so we can benefit
1159 from it in get_pointer_alignment. */
1160 DECL_ALIGN (decl
) = align
;
1163 /* Return the section into which the given VAR_DECL or CONST_DECL
1164 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1165 section should be used wherever possible. */
1168 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1170 addr_space_t as
= ADDR_SPACE_GENERIC
;
1173 if (TREE_TYPE (decl
) != error_mark_node
)
1174 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1176 if (DECL_COMMON (decl
))
1178 /* If the decl has been given an explicit section name, or it resides
1179 in a non-generic address space, then it isn't common, and shouldn't
1180 be handled as such. */
1181 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1182 && ADDR_SPACE_GENERIC_P (as
));
1183 if (DECL_THREAD_LOCAL_P (decl
))
1184 return tls_comm_section
;
1185 /* This cannot be common bss for an emulated TLS object without
1186 a register_common hook. */
1187 else if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
1188 && !targetm
.emutls
.register_common
)
1190 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1191 return comm_section
;
1194 if (DECL_INITIAL (decl
) == error_mark_node
)
1195 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1196 else if (DECL_INITIAL (decl
))
1197 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1201 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1202 if (IN_NAMED_SECTION (decl
))
1203 return get_named_section (decl
, NULL
, reloc
);
1205 if (ADDR_SPACE_GENERIC_P (as
)
1206 && !DECL_THREAD_LOCAL_P (decl
)
1207 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1208 && bss_initializer_p (decl
))
1210 if (!TREE_PUBLIC (decl
))
1211 return lcomm_section
;
1212 if (bss_noswitch_section
)
1213 return bss_noswitch_section
;
1216 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
1219 /* Return the block into which object_block DECL should be placed. */
1221 static struct object_block
*
1222 get_block_for_decl (tree decl
)
1226 if (TREE_CODE (decl
) == VAR_DECL
)
1228 /* The object must be defined in this translation unit. */
1229 if (DECL_EXTERNAL (decl
))
1232 /* There's no point using object blocks for something that is
1233 isolated by definition. */
1234 if (DECL_ONE_ONLY (decl
))
1238 /* We can only calculate block offsets if the decl has a known
1240 if (DECL_SIZE_UNIT (decl
) == NULL
)
1242 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
1245 /* Find out which section should contain DECL. We cannot put it into
1246 an object block if it requires a standalone definition. */
1247 if (TREE_CODE (decl
) == VAR_DECL
)
1248 align_variable (decl
, 0);
1249 sect
= get_variable_section (decl
, true);
1250 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1253 return get_block_for_section (sect
);
1256 /* Make sure block symbol SYMBOL is in block BLOCK. */
1259 change_symbol_block (rtx symbol
, struct object_block
*block
)
1261 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1263 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1264 SYMBOL_REF_BLOCK (symbol
) = block
;
1268 /* Return true if it is possible to put DECL in an object_block. */
1271 use_blocks_for_decl_p (tree decl
)
1273 /* Only data DECLs can be placed into object blocks. */
1274 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1277 /* Detect decls created by dw2_force_const_mem. Such decls are
1278 special because DECL_INITIAL doesn't specify the decl's true value.
1279 dw2_output_indirect_constants will instead call assemble_variable
1280 with dont_output_data set to 1 and then print the contents itself. */
1281 if (DECL_INITIAL (decl
) == decl
)
1284 /* If this decl is an alias, then we don't want to emit a definition. */
1285 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1291 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1292 have static storage duration. In other words, it should not be an
1293 automatic variable, including PARM_DECLs.
1295 There is, however, one exception: this function handles variables
1296 explicitly placed in a particular register by the user.
1298 This is never called for PARM_DECL nodes. */
1301 make_decl_rtl (tree decl
)
1303 const char *name
= 0;
1307 /* Check that we are not being given an automatic variable. */
1308 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1309 && TREE_CODE (decl
) != RESULT_DECL
);
1311 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1312 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1313 || TREE_STATIC (decl
)
1314 || TREE_PUBLIC (decl
)
1315 || DECL_EXTERNAL (decl
)
1316 || DECL_REGISTER (decl
));
1318 /* And that we were not given a type or a label. */
1319 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1320 && TREE_CODE (decl
) != LABEL_DECL
);
1322 /* For a duplicate declaration, we can be called twice on the
1323 same DECL node. Don't discard the RTL already made. */
1324 if (DECL_RTL_SET_P (decl
))
1326 /* If the old RTL had the wrong mode, fix the mode. */
1327 x
= DECL_RTL (decl
);
1328 if (GET_MODE (x
) != DECL_MODE (decl
))
1329 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1331 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1334 /* ??? Another way to do this would be to maintain a hashed
1335 table of such critters. Instead of adding stuff to a DECL
1336 to give certain attributes to it, we could use an external
1337 hash map from DECL to set of attributes. */
1339 /* Let the target reassign the RTL if it wants.
1340 This is necessary, for example, when one machine specific
1341 decl attribute overrides another. */
1342 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1344 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1345 on the new decl information. */
1347 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1348 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1349 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1351 /* Make this function static known to the mudflap runtime. */
1352 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1353 mudflap_enqueue_decl (decl
);
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
))
1362 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1366 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1368 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1369 && DECL_REGISTER (decl
))
1371 error ("register name not specified for %q+D", decl
);
1373 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1375 const char *asmspec
= name
+1;
1376 reg_number
= decode_reg_name (asmspec
);
1377 /* First detect errors in declaring global registers. */
1378 if (reg_number
== -1)
1379 error ("register name not specified for %q+D", decl
);
1380 else if (reg_number
< 0)
1381 error ("invalid register name for %q+D", decl
);
1382 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1383 error ("data type of %q+D isn%'t suitable for a register",
1385 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1386 error ("register specified for %q+D isn%'t suitable for data type",
1388 /* Now handle properly declared static register variables. */
1393 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1395 DECL_INITIAL (decl
) = 0;
1396 error ("global register variable has initial value");
1398 if (TREE_THIS_VOLATILE (decl
))
1399 warning (OPT_Wvolatile_register_var
,
1400 "optimization may eliminate reads and/or "
1401 "writes to register variables");
1403 /* If the user specified one of the eliminables registers here,
1404 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1405 confused with that register and be eliminated. This usage is
1406 somewhat suspect... */
1408 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1409 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1410 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1412 if (TREE_STATIC (decl
))
1414 /* Make this register global, so not usable for anything
1416 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1417 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1418 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1420 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1422 globalize_reg (reg_number
+ --nregs
);
1425 /* As a register variable, it has no section. */
1429 /* Now handle ordinary static variables and functions (in memory).
1430 Also handle vars declared register invalidly. */
1431 else if (name
[0] == '*')
1433 #ifdef REGISTER_PREFIX
1434 if (strlen (REGISTER_PREFIX
) != 0)
1436 reg_number
= decode_reg_name (name
);
1437 if (reg_number
>= 0 || reg_number
== -3)
1438 error ("register name given for non-register variable %q+D", decl
);
1443 /* Specifying a section attribute on a variable forces it into a
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. */
1449 if (TREE_CODE (decl
) == VAR_DECL
1450 && DECL_SECTION_NAME (decl
) != NULL_TREE
1451 && DECL_INITIAL (decl
) == NULL_TREE
1452 && DECL_COMMON (decl
))
1453 DECL_COMMON (decl
) = 0;
1455 /* Variables can't be both common and weak. */
1456 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1457 DECL_COMMON (decl
) = 0;
1459 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1460 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1463 enum machine_mode address_mode
= Pmode
;
1464 if (TREE_TYPE (decl
) != error_mark_node
)
1466 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1467 address_mode
= targetm
.addr_space
.address_mode (as
);
1469 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1471 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1472 SET_SYMBOL_REF_DECL (x
, decl
);
1474 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1475 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1476 set_mem_attributes (x
, decl
, 1);
1477 SET_DECL_RTL (decl
, x
);
1479 /* Optionally set flags or add text to the name to record information
1480 such as that it is a function name.
1481 If the name is changed, the macro ASM_OUTPUT_LABELREF
1482 will have to know how to strip this information. */
1483 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1485 /* Make this function static known to the mudflap runtime. */
1486 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1487 mudflap_enqueue_decl (decl
);
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
1495 make_decl_rtl_for_debug (tree decl
)
1497 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1500 if (DECL_RTL_SET_P (decl
))
1501 return DECL_RTL (decl
);
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
;
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
);
1520 flag_strict_aliasing
= save_aliasing_flag
;
1521 flag_mudflap
= save_mudflap_flag
;
1526 /* Output a string of literal assembler code
1527 for an `asm' keyword used between functions. */
1530 assemble_asm (tree string
)
1534 if (TREE_CODE (string
) == ADDR_EXPR
)
1535 string
= TREE_OPERAND (string
, 0);
1537 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1540 /* Record an element in the table of global destructors. SYMBOL is
1541 a SYMBOL_REF of the function to be called; PRIORITY is a number
1542 between 0 and MAX_INIT_PRIORITY. */
1545 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1546 int priority ATTRIBUTE_UNUSED
)
1548 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1549 /* Tell GNU LD that this is part of the static destructor set.
1550 This will work for any system that uses stabs, most usefully
1552 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1553 dbxout_stab_value_label (XSTR (symbol
, 0));
1555 sorry ("global destructors not supported on this target");
1559 /* Write the address of the entity given by SYMBOL to SEC. */
1561 assemble_addr_to_section (rtx symbol
, section
*sec
)
1563 switch_to_section (sec
);
1564 assemble_align (POINTER_SIZE
);
1565 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1568 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1569 not) section for PRIORITY. */
1571 get_cdtor_priority_section (int priority
, bool constructor_p
)
1575 /* ??? This only works reliably with the GNU linker. */
1576 sprintf (buf
, "%s.%.5u",
1577 constructor_p
? ".ctors" : ".dtors",
1578 /* Invert the numbering so the linker puts us in the proper
1579 order; constructors are run from right to left, and the
1580 linker sorts in increasing order. */
1581 MAX_INIT_PRIORITY
- priority
);
1582 return get_section (buf
, SECTION_WRITE
, NULL
);
1586 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1590 if (priority
!= DEFAULT_INIT_PRIORITY
)
1591 sec
= get_cdtor_priority_section (priority
,
1592 /*constructor_p=*/false);
1594 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1596 assemble_addr_to_section (symbol
, sec
);
1599 #ifdef DTORS_SECTION_ASM_OP
1601 default_dtor_section_asm_out_destructor (rtx symbol
,
1602 int priority ATTRIBUTE_UNUSED
)
1604 assemble_addr_to_section (symbol
, dtors_section
);
1608 /* Likewise for global constructors. */
1611 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1612 int priority ATTRIBUTE_UNUSED
)
1614 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1615 /* Tell GNU LD that this is part of the static destructor set.
1616 This will work for any system that uses stabs, most usefully
1618 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1619 dbxout_stab_value_label (XSTR (symbol
, 0));
1621 sorry ("global constructors not supported on this target");
1626 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1630 if (priority
!= DEFAULT_INIT_PRIORITY
)
1631 sec
= get_cdtor_priority_section (priority
,
1632 /*constructor_p=*/true);
1634 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1636 assemble_addr_to_section (symbol
, sec
);
1639 #ifdef CTORS_SECTION_ASM_OP
1641 default_ctor_section_asm_out_constructor (rtx symbol
,
1642 int priority ATTRIBUTE_UNUSED
)
1644 assemble_addr_to_section (symbol
, ctors_section
);
1648 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1649 a nonzero value if the constant pool should be output before the
1650 start of the function, or a zero value if the pool should output
1651 after the end of the function. The default is to put it before the
1654 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1655 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1658 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1659 to be output to assembler.
1660 Set first_global_object_name and weak_global_object_name as appropriate. */
1663 notice_global_symbol (tree decl
)
1665 const char **type
= &first_global_object_name
;
1667 if (first_global_object_name
1668 || !TREE_PUBLIC (decl
)
1669 || DECL_EXTERNAL (decl
)
1670 || !DECL_NAME (decl
)
1671 || (TREE_CODE (decl
) != FUNCTION_DECL
1672 && (TREE_CODE (decl
) != VAR_DECL
1673 || (DECL_COMMON (decl
)
1674 && (DECL_INITIAL (decl
) == 0
1675 || DECL_INITIAL (decl
) == error_mark_node
))))
1676 || !MEM_P (DECL_RTL (decl
)))
1679 /* We win when global object is found, but it is useful to know about weak
1680 symbol as well so we can produce nicer unique names. */
1681 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1682 type
= &weak_global_object_name
;
1688 rtx decl_rtl
= DECL_RTL (decl
);
1690 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1691 name
= ggc_strdup (p
);
1697 /* Output assembler code for the constant pool of a function and associated
1698 with defining the name of the function. DECL describes the function.
1699 NAME is the function's name. For the constant pool, we use the current
1700 constant pool data. */
1703 assemble_start_function (tree decl
, const char *fnname
)
1706 char tmp_label
[100];
1707 bool hot_label_written
= false;
1709 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1711 first_function_block_is_cold
= false;
1712 if (flag_reorder_blocks_and_partition
)
1714 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1715 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1716 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1717 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1718 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1719 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1720 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1721 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1726 crtl
->subsections
.hot_section_label
= NULL
;
1727 crtl
->subsections
.cold_section_label
= NULL
;
1728 crtl
->subsections
.hot_section_end_label
= NULL
;
1729 crtl
->subsections
.cold_section_end_label
= NULL
;
1732 /* The following code does not need preprocessing in the assembler. */
1736 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1737 output_constant_pool (fnname
, decl
);
1739 resolve_unique_section (decl
, 0, flag_function_sections
);
1741 /* Make sure the not and cold text (code) sections are properly
1742 aligned. This is necessary here in the case where the function
1743 has both hot and cold sections, because we don't want to re-set
1744 the alignment when the section switch happens mid-function. */
1746 if (flag_reorder_blocks_and_partition
)
1748 switch_to_section (unlikely_text_section ());
1749 assemble_align (DECL_ALIGN (decl
));
1750 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1752 /* When the function starts with a cold section, we need to explicitly
1753 align the hot section and write out the hot section label.
1754 But if the current function is a thunk, we do not have a CFG. */
1756 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1758 switch_to_section (text_section
);
1759 assemble_align (DECL_ALIGN (decl
));
1760 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1761 hot_label_written
= true;
1762 first_function_block_is_cold
= true;
1765 else if (DECL_SECTION_NAME (decl
))
1767 /* Calls to function_section rely on first_function_block_is_cold
1768 being accurate. The first block may be cold even if we aren't
1769 doing partitioning, if the entire function was decided by
1770 choose_function_section (predict.c) to be cold. */
1772 initialize_cold_section_name ();
1774 if (crtl
->subsections
.unlikely_text_section_name
1775 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1776 crtl
->subsections
.unlikely_text_section_name
) == 0)
1777 first_function_block_is_cold
= true;
1780 in_cold_section_p
= first_function_block_is_cold
;
1782 /* Switch to the correct text section for the start of the function. */
1784 switch_to_section (function_section (decl
));
1785 if (flag_reorder_blocks_and_partition
1786 && !hot_label_written
)
1787 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1789 /* Tell assembler to move to target machine's alignment for functions. */
1790 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1793 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1796 /* Handle a user-specified function alignment.
1797 Note that we still need to align to DECL_ALIGN, as above,
1798 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1799 if (! DECL_USER_ALIGN (decl
)
1800 && align_functions_log
> align
1801 && optimize_function_for_speed_p (cfun
))
1803 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1804 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1805 align_functions_log
, align_functions
- 1);
1807 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1811 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1812 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1815 if (!DECL_IGNORED_P (decl
))
1816 (*debug_hooks
->begin_function
) (decl
);
1818 /* Make function name accessible from other files, if appropriate. */
1820 if (TREE_PUBLIC (decl
))
1822 notice_global_symbol (decl
);
1824 globalize_decl (decl
);
1826 maybe_assemble_visibility (decl
);
1829 if (DECL_PRESERVE_P (decl
))
1830 targetm
.asm_out
.mark_decl_preserved (fnname
);
1832 /* Do any machine/system dependent processing of the function name. */
1833 #ifdef ASM_DECLARE_FUNCTION_NAME
1834 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1836 /* Standard thing is just output label for the function. */
1837 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1838 #endif /* ASM_DECLARE_FUNCTION_NAME */
1841 /* Output assembler code associated with defining the size of the
1842 function. DECL describes the function. NAME is the function's name. */
1845 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1847 #ifdef ASM_DECLARE_FUNCTION_SIZE
1848 /* We could have switched section in the middle of the function. */
1849 if (flag_reorder_blocks_and_partition
)
1850 switch_to_section (function_section (decl
));
1851 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1853 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1855 output_constant_pool (fnname
, decl
);
1856 switch_to_section (function_section (decl
)); /* need to switch back */
1858 /* Output labels for end of hot/cold text sections (to be used by
1860 if (flag_reorder_blocks_and_partition
)
1862 section
*save_text_section
;
1864 save_text_section
= in_section
;
1865 switch_to_section (unlikely_text_section ());
1866 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1867 if (first_function_block_is_cold
)
1868 switch_to_section (text_section
);
1870 switch_to_section (function_section (decl
));
1871 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1872 switch_to_section (save_text_section
);
1876 /* Assemble code to leave SIZE bytes of zeros. */
1879 assemble_zeros (unsigned HOST_WIDE_INT size
)
1881 /* Do no output if -fsyntax-only. */
1882 if (flag_syntax_only
)
1885 #ifdef ASM_NO_SKIP_IN_TEXT
1886 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1887 so we must output 0s explicitly in the text section. */
1888 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1890 unsigned HOST_WIDE_INT i
;
1891 for (i
= 0; i
< size
; i
++)
1892 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1897 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1900 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1903 assemble_align (int align
)
1905 if (align
> BITS_PER_UNIT
)
1907 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1911 /* Assemble a string constant with the specified C string as contents. */
1914 assemble_string (const char *p
, int size
)
1919 /* If the string is very long, split it up. */
1923 int thissize
= size
- pos
;
1924 if (thissize
> maximum
)
1927 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1935 /* A noswitch_section_callback for lcomm_section. */
1938 emit_local (tree decl ATTRIBUTE_UNUSED
,
1939 const char *name ATTRIBUTE_UNUSED
,
1940 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1941 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1943 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1944 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1945 size
, DECL_ALIGN (decl
));
1947 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1948 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1951 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1956 /* A noswitch_section_callback for bss_noswitch_section. */
1958 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1960 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1961 const char *name ATTRIBUTE_UNUSED
,
1962 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1963 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1965 #if defined ASM_OUTPUT_ALIGNED_BSS
1966 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1969 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1975 /* A noswitch_section_callback for comm_section. */
1978 emit_common (tree decl ATTRIBUTE_UNUSED
,
1979 const char *name ATTRIBUTE_UNUSED
,
1980 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1981 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1983 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1984 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
1985 size
, DECL_ALIGN (decl
));
1987 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1988 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1991 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
1996 /* A noswitch_section_callback for tls_comm_section. */
1999 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
2000 const char *name ATTRIBUTE_UNUSED
,
2001 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2002 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2004 #ifdef ASM_OUTPUT_TLS_COMMON
2005 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2008 sorry ("thread-local COMMON data not implemented");
2013 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2014 NAME is the name of DECL's SYMBOL_REF. */
2017 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
2019 unsigned HOST_WIDE_INT size
, rounded
;
2021 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
2024 /* Don't allocate zero bytes of common,
2025 since that means "undefined external" in the linker. */
2029 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2030 so that each uninitialized object starts on such a boundary. */
2031 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2032 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2033 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2035 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2036 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
2037 warning (0, "requested alignment for %q+D is greater than "
2038 "implemented alignment of %wu", decl
, rounded
);
2041 /* A subroutine of assemble_variable. Output the label and contents of
2042 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2043 is as for assemble_variable. */
2046 assemble_variable_contents (tree decl
, const char *name
,
2047 bool dont_output_data
)
2049 /* Do any machine/system dependent processing of the object. */
2050 #ifdef ASM_DECLARE_OBJECT_NAME
2051 last_assemble_variable_decl
= decl
;
2052 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2054 /* Standard thing is just output label for the object. */
2055 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2056 #endif /* ASM_DECLARE_OBJECT_NAME */
2058 if (!dont_output_data
)
2060 if (DECL_INITIAL (decl
)
2061 && DECL_INITIAL (decl
) != error_mark_node
2062 && !initializer_zerop (DECL_INITIAL (decl
)))
2063 /* Output the actual data. */
2064 output_constant (DECL_INITIAL (decl
),
2065 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
2068 /* Leave space for it. */
2069 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
2073 /* Initialize emulated tls object TO, which refers to TLS variable
2074 DECL and is initialized by PROXY. */
2077 default_emutls_var_init (tree to
, tree decl
, tree proxy
)
2079 VEC(constructor_elt
,gc
) *v
= VEC_alloc (constructor_elt
, gc
, 4);
2080 constructor_elt
*elt
;
2081 tree type
= TREE_TYPE (to
);
2082 tree field
= TYPE_FIELDS (type
);
2084 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2086 elt
->value
= fold_convert (TREE_TYPE (field
), DECL_SIZE_UNIT (decl
));
2088 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2089 field
= TREE_CHAIN (field
);
2091 elt
->value
= build_int_cst (TREE_TYPE (field
),
2092 DECL_ALIGN_UNIT (decl
));
2094 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2095 field
= TREE_CHAIN (field
);
2097 elt
->value
= null_pointer_node
;
2099 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2100 field
= TREE_CHAIN (field
);
2104 return build_constructor (type
, v
);
2107 /* Assemble everything that is needed for a variable or function declaration.
2108 Not used for automatic variables, and not used for function definitions.
2109 Should not be called for variables of incomplete structure type.
2111 TOP_LEVEL is nonzero if this variable has file scope.
2112 AT_END is nonzero if this is the special handling, at end of compilation,
2113 to define things that have had only tentative definitions.
2114 DONT_OUTPUT_DATA if nonzero means don't actually output the
2115 initial value (that will be done by the caller). */
2118 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2119 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2122 rtx decl_rtl
, symbol
;
2125 if (! targetm
.have_tls
2126 && TREE_CODE (decl
) == VAR_DECL
2127 && DECL_THREAD_LOCAL_P (decl
))
2129 tree to
= emutls_decl (decl
);
2131 /* If this variable is defined locally, then we need to initialize the
2132 control structure with size and alignment information. We do this
2133 at the last moment because tentative definitions can take a locally
2134 defined but uninitialized variable and initialize it later, which
2135 would result in incorrect contents. */
2136 if (! DECL_EXTERNAL (to
)
2137 && (! DECL_COMMON (to
)
2138 || (DECL_INITIAL (decl
)
2139 && DECL_INITIAL (decl
) != error_mark_node
)))
2141 DECL_INITIAL (to
) = targetm
.emutls
.var_init
2142 (to
, decl
, get_emutls_init_templ_addr (decl
));
2144 /* Make sure the template is marked as needed early enough.
2145 Without this, if the variable is placed in a
2146 section-anchored block, the template will only be marked
2147 when it's too late. */
2148 record_references_in_initializer (to
, false);
2154 last_assemble_variable_decl
= 0;
2156 /* Normally no need to say anything here for external references,
2157 since assemble_external is called by the language-specific code
2158 when a declaration is first seen. */
2160 if (DECL_EXTERNAL (decl
))
2163 /* Output no assembler code for a function declaration.
2164 Only definitions of functions output anything. */
2166 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2169 /* Do nothing for global register variables. */
2170 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2172 TREE_ASM_WRITTEN (decl
) = 1;
2176 /* If type was incomplete when the variable was declared,
2177 see if it is complete now. */
2179 if (DECL_SIZE (decl
) == 0)
2180 layout_decl (decl
, 0);
2182 /* Still incomplete => don't allocate it; treat the tentative defn
2183 (which is what it must have been) as an `extern' reference. */
2185 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2187 error ("storage size of %q+D isn%'t known", decl
);
2188 TREE_ASM_WRITTEN (decl
) = 1;
2192 /* The first declaration of a variable that comes through this function
2193 decides whether it is global (in C, has external linkage)
2194 or local (in C, has internal linkage). So do nothing more
2195 if this function has already run. */
2197 if (TREE_ASM_WRITTEN (decl
))
2200 /* Make sure targetm.encode_section_info is invoked before we set
2202 decl_rtl
= DECL_RTL (decl
);
2204 TREE_ASM_WRITTEN (decl
) = 1;
2206 /* Do no output if -fsyntax-only. */
2207 if (flag_syntax_only
)
2210 if (! dont_output_data
2211 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
2213 error ("size of variable %q+D is too large", decl
);
2217 gcc_assert (MEM_P (decl_rtl
));
2218 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2219 symbol
= XEXP (decl_rtl
, 0);
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
))
2225 tree decl
= SYMBOL_REF_DECL (symbol
);
2226 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2227 output_constant_def_contents (symbol
);
2233 name
= XSTR (symbol
, 0);
2234 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2235 notice_global_symbol (decl
);
2237 /* Compute the alignment of this data. */
2239 align_variable (decl
, dont_output_data
);
2240 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2242 if (TREE_PUBLIC (decl
))
2243 maybe_assemble_visibility (decl
);
2245 if (DECL_PRESERVE_P (decl
))
2246 targetm
.asm_out
.mark_decl_preserved (name
);
2248 /* First make the assembler name(s) global if appropriate. */
2249 sect
= get_variable_section (decl
, false);
2250 if (TREE_PUBLIC (decl
)
2251 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2252 globalize_decl (decl
);
2254 /* Output any data that we will need to use the address of. */
2255 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2256 output_addressed_constants (DECL_INITIAL (decl
));
2258 /* dbxout.c needs to know this. */
2259 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2260 DECL_IN_TEXT_SECTION (decl
) = 1;
2262 /* If the decl is part of an object_block, make sure that the decl
2263 has been positioned within its block, but do not write out its
2264 definition yet. output_object_blocks will do that later. */
2265 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2267 gcc_assert (!dont_output_data
);
2268 place_block_symbol (symbol
);
2270 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2271 assemble_noswitch_variable (decl
, name
, sect
);
2274 switch_to_section (sect
);
2275 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2276 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2277 assemble_variable_contents (decl
, name
, dont_output_data
);
2281 /* Return 1 if type TYPE contains any pointers. */
2284 contains_pointers_p (tree type
)
2286 switch (TREE_CODE (type
))
2289 case REFERENCE_TYPE
:
2290 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2291 so I'll play safe and return 1. */
2297 case QUAL_UNION_TYPE
:
2300 /* For a type that has fields, see if the fields have pointers. */
2301 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2302 if (TREE_CODE (fields
) == FIELD_DECL
2303 && contains_pointers_p (TREE_TYPE (fields
)))
2309 /* An array type contains pointers if its element type does. */
2310 return contains_pointers_p (TREE_TYPE (type
));
2317 /* We delay assemble_external processing until
2318 the compilation unit is finalized. This is the best we can do for
2319 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2320 it all the way to final. See PR 17982 for further discussion. */
2321 static GTY(()) tree pending_assemble_externals
;
2323 #ifdef ASM_OUTPUT_EXTERNAL
2324 /* True if DECL is a function decl for which no out-of-line copy exists.
2325 It is assumed that DECL's assembler name has been set. */
2328 incorporeal_function_p (tree decl
)
2330 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2334 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2335 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
2338 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2339 if (is_builtin_name (name
))
2345 /* Actually do the tests to determine if this is necessary, and invoke
2346 ASM_OUTPUT_EXTERNAL. */
2348 assemble_external_real (tree decl
)
2350 rtx rtl
= DECL_RTL (decl
);
2352 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2353 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2354 && !incorporeal_function_p (decl
))
2356 /* Some systems do require some output. */
2357 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2358 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2364 process_pending_assemble_externals (void)
2366 #ifdef ASM_OUTPUT_EXTERNAL
2368 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2369 assemble_external_real (TREE_VALUE (list
));
2371 pending_assemble_externals
= 0;
2375 /* This TREE_LIST contains any weak symbol declarations waiting
2377 static GTY(()) tree weak_decls
;
2379 /* Output something to declare an external symbol to the assembler,
2380 and qualifiers such as weakness. (Most assemblers don't need
2381 extern declaration, so we normally output nothing.) Do nothing if
2382 DECL is not external. */
2385 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2387 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2388 main body of this code is only rarely exercised. To provide some
2389 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2390 open. If it's not, we should not be calling this function. */
2391 gcc_assert (asm_out_file
);
2393 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2396 /* We want to output annotation for weak and external symbols at
2397 very last to check if they are references or not. */
2401 /* TREE_STATIC is a weird and abused creature which is not
2402 generally the right test for whether an entity has been
2403 locally emitted, inlined or otherwise not-really-extern, but
2404 for declarations that can be weak, it happens to be
2406 && !TREE_STATIC (decl
)
2407 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2408 && value_member (decl
, weak_decls
) == NULL_TREE
)
2409 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2411 #ifdef ASM_OUTPUT_EXTERNAL
2412 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2413 pending_assemble_externals
= tree_cons (NULL
, decl
,
2414 pending_assemble_externals
);
2418 /* Similar, for calling a library function FUN. */
2421 assemble_external_libcall (rtx fun
)
2423 /* Declare library function name external when first used, if nec. */
2424 if (! SYMBOL_REF_USED (fun
))
2426 SYMBOL_REF_USED (fun
) = 1;
2427 targetm
.asm_out
.external_libcall (fun
);
2431 /* Assemble a label named NAME. */
2434 assemble_label (const char *name
)
2436 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2439 /* Set the symbol_referenced flag for ID. */
2441 mark_referenced (tree id
)
2443 TREE_SYMBOL_REFERENCED (id
) = 1;
2446 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2448 mark_decl_referenced (tree decl
)
2450 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2452 /* Extern inline functions don't become needed when referenced.
2453 If we know a method will be emitted in other TU and no new
2454 functions can be marked reachable, just use the external
2456 struct cgraph_node
*node
= cgraph_node (decl
);
2457 if (!DECL_EXTERNAL (decl
)
2458 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2459 || !node
->local
.finalized
))
2460 cgraph_mark_needed_node (node
);
2462 else if (TREE_CODE (decl
) == VAR_DECL
)
2464 struct varpool_node
*node
= varpool_node (decl
);
2465 varpool_mark_needed_node (node
);
2466 /* C++ frontend use mark_decl_references to force COMDAT variables
2467 to be output that might appear dead otherwise. */
2468 node
->force_output
= true;
2470 /* else do nothing - we can get various sorts of CST nodes here,
2471 which do not need to be marked. */
2475 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2476 until we find an identifier that is not itself a transparent alias.
2477 Modify the alias passed to it by reference (and all aliases on the
2478 way to the ultimate target), such that they do not have to be
2479 followed again, and return the ultimate target of the alias
2483 ultimate_transparent_alias_target (tree
*alias
)
2485 tree target
= *alias
;
2487 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2489 gcc_assert (TREE_CHAIN (target
));
2490 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2491 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2492 && ! TREE_CHAIN (target
));
2499 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2500 starts with a *, the rest of NAME is output verbatim. Otherwise
2501 NAME is transformed in a target-specific way (usually by the
2502 addition of an underscore). */
2505 assemble_name_raw (FILE *file
, const char *name
)
2508 fputs (&name
[1], file
);
2510 ASM_OUTPUT_LABELREF (file
, name
);
2513 /* Like assemble_name_raw, but should be used when NAME might refer to
2514 an entity that is also represented as a tree (like a function or
2515 variable). If NAME does refer to such an entity, that entity will
2516 be marked as referenced. */
2519 assemble_name (FILE *file
, const char *name
)
2521 const char *real_name
;
2524 real_name
= targetm
.strip_name_encoding (name
);
2526 id
= maybe_get_identifier (real_name
);
2531 mark_referenced (id
);
2532 ultimate_transparent_alias_target (&id
);
2534 name
= IDENTIFIER_POINTER (id
);
2535 gcc_assert (! TREE_CHAIN (id
));
2538 assemble_name_raw (file
, name
);
2541 /* Allocate SIZE bytes writable static space with a gensym name
2542 and return an RTX to refer to its address. */
2545 assemble_static_space (unsigned HOST_WIDE_INT size
)
2548 const char *namestring
;
2551 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2553 namestring
= ggc_strdup (name
);
2555 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2556 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2558 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2559 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2562 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2563 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2566 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2567 so that each uninitialized object starts on such a boundary. */
2568 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2569 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2570 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2571 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2572 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2573 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2580 /* Assemble the static constant template for function entry trampolines.
2581 This is done at most once per compilation.
2582 Returns an RTX for the address of the template. */
2584 static GTY(()) rtx initial_trampoline
;
2587 assemble_trampoline_template (void)
2594 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2596 if (initial_trampoline
)
2597 return initial_trampoline
;
2599 /* By default, put trampoline templates in read-only data section. */
2601 #ifdef TRAMPOLINE_SECTION
2602 switch_to_section (TRAMPOLINE_SECTION
);
2604 switch_to_section (readonly_data_section
);
2607 /* Write the assembler code to define one. */
2608 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2610 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2612 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2613 targetm
.asm_out
.trampoline_template (asm_out_file
);
2615 /* Record the rtl to refer to it. */
2616 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2617 name
= ggc_strdup (label
);
2618 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2619 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2621 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2622 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2623 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2625 return initial_trampoline
;
2628 /* A and B are either alignments or offsets. Return the minimum alignment
2629 that may be assumed after adding the two together. */
2631 static inline unsigned
2632 min_align (unsigned int a
, unsigned int b
)
2634 return (a
| b
) & -(a
| b
);
2637 /* Return the assembler directive for creating a given kind of integer
2638 object. SIZE is the number of bytes in the object and ALIGNED_P
2639 indicates whether it is known to be aligned. Return NULL if the
2640 assembly dialect has no such directive.
2642 The returned string should be printed at the start of a new line and
2643 be followed immediately by the object's initial value. */
2646 integer_asm_op (int size
, int aligned_p
)
2648 struct asm_int_op
*ops
;
2651 ops
= &targetm
.asm_out
.aligned_op
;
2653 ops
= &targetm
.asm_out
.unaligned_op
;
2658 return targetm
.asm_out
.byte_op
;
2672 /* Use directive OP to assemble an integer object X. Print OP at the
2673 start of the line, followed immediately by the value of X. */
2676 assemble_integer_with_op (const char *op
, rtx x
)
2678 fputs (op
, asm_out_file
);
2679 output_addr_const (asm_out_file
, x
);
2680 fputc ('\n', asm_out_file
);
2683 /* The default implementation of the asm_out.integer target hook. */
2686 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2687 unsigned int size ATTRIBUTE_UNUSED
,
2688 int aligned_p ATTRIBUTE_UNUSED
)
2690 const char *op
= integer_asm_op (size
, aligned_p
);
2691 /* Avoid GAS bugs for large values. Specifically negative values whose
2692 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2693 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2695 return op
&& (assemble_integer_with_op (op
, x
), true);
2698 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2699 the alignment of the integer in bits. Return 1 if we were able to output
2700 the constant, otherwise 0. We must be able to output the constant,
2701 if FORCE is nonzero. */
2704 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2708 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2710 /* See if the target hook can handle this kind of object. */
2711 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2714 /* If the object is a multi-byte one, try splitting it up. Split
2715 it into words it if is multi-word, otherwise split it into bytes. */
2718 enum machine_mode omode
, imode
;
2719 unsigned int subalign
;
2720 unsigned int subsize
, i
;
2721 enum mode_class mclass
;
2723 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2724 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2725 if (GET_CODE (x
) == CONST_FIXED
)
2726 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2730 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2731 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2733 for (i
= 0; i
< size
; i
+= subsize
)
2735 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2736 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2742 /* If we've printed some of it, but not all of it, there's no going
2747 gcc_assert (!force
);
2753 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2755 long data
[4] = {0, 0, 0, 0};
2757 int bitsize
, nelts
, nunits
, units_per
;
2759 /* This is hairy. We have a quantity of known size. real_to_target
2760 will put it into an array of *host* longs, 32 bits per element
2761 (even if long is more than 32 bits). We need to determine the
2762 number of array elements that are occupied (nelts) and the number
2763 of *target* min-addressable units that will be occupied in the
2764 object file (nunits). We cannot assume that 32 divides the
2765 mode's bitsize (size * BITS_PER_UNIT) evenly.
2767 size * BITS_PER_UNIT is used here to make sure that padding bits
2768 (which might appear at either end of the value; real_to_target
2769 will include the padding bits in its output array) are included. */
2771 nunits
= GET_MODE_SIZE (mode
);
2772 bitsize
= nunits
* BITS_PER_UNIT
;
2773 nelts
= CEIL (bitsize
, 32);
2774 units_per
= 32 / BITS_PER_UNIT
;
2776 real_to_target (data
, &d
, mode
);
2778 /* Put out the first word with the specified alignment. */
2779 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2780 nunits
-= units_per
;
2782 /* Subsequent words need only 32-bit alignment. */
2783 align
= min_align (align
, 32);
2785 for (i
= 1; i
< nelts
; i
++)
2787 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2788 nunits
-= units_per
;
2792 /* Given an expression EXP with a constant value,
2793 reduce it to the sum of an assembler symbol and an integer.
2794 Store them both in the structure *VALUE.
2795 EXP must be reducible. */
2797 struct GTY(()) addr_const
{
2799 HOST_WIDE_INT offset
;
2803 decode_addr_const (tree exp
, struct addr_const
*value
)
2805 tree target
= TREE_OPERAND (exp
, 0);
2811 if (TREE_CODE (target
) == COMPONENT_REF
2812 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2814 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2815 target
= TREE_OPERAND (target
, 0);
2817 else if (TREE_CODE (target
) == ARRAY_REF
2818 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2820 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2821 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2822 target
= TREE_OPERAND (target
, 0);
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))
2828 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2833 switch (TREE_CODE (target
))
2837 x
= DECL_RTL (target
);
2841 x
= gen_rtx_MEM (FUNCTION_MODE
,
2842 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2851 x
= output_constant_def (target
, 1);
2858 gcc_assert (MEM_P (x
));
2862 value
->offset
= offset
;
2866 static GTY((param_is (struct constant_descriptor_tree
)))
2867 htab_t const_desc_htab
;
2869 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2871 /* Constant pool accessor function. */
2874 constant_pool_htab (void)
2876 return const_desc_htab
;
2879 /* Compute a hash code for a constant expression. */
2882 const_desc_hash (const void *ptr
)
2884 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2888 const_hash_1 (const tree exp
)
2893 enum tree_code code
= TREE_CODE (exp
);
2895 /* Either set P and LEN to the address and len of something to hash and
2896 exit the switch or return a value. */
2901 p
= (char *) &TREE_INT_CST (exp
);
2902 len
= sizeof TREE_INT_CST (exp
);
2906 return real_hash (TREE_REAL_CST_PTR (exp
));
2909 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2912 p
= TREE_STRING_POINTER (exp
);
2913 len
= TREE_STRING_LENGTH (exp
);
2917 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2918 + const_hash_1 (TREE_IMAGPART (exp
)));
2924 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2926 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2927 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2934 unsigned HOST_WIDE_INT idx
;
2937 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2939 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2941 hi
= hi
* 603 + const_hash_1 (value
);
2949 struct addr_const value
;
2951 decode_addr_const (exp
, &value
);
2952 switch (GET_CODE (value
.base
))
2955 /* Don't hash the address of the SYMBOL_REF;
2956 only use the offset and the symbol name. */
2958 p
= XSTR (value
.base
, 0);
2959 for (i
= 0; p
[i
] != 0; i
++)
2960 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2964 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2974 case POINTER_PLUS_EXPR
:
2976 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2977 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2980 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2983 /* A language specific constant. Just hash the code. */
2987 /* Compute hashing function. */
2989 for (i
= 0; i
< len
; i
++)
2990 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2995 /* Wrapper of compare_constant, for the htab interface. */
2997 const_desc_eq (const void *p1
, const void *p2
)
2999 const struct constant_descriptor_tree
*const c1
3000 = (const struct constant_descriptor_tree
*) p1
;
3001 const struct constant_descriptor_tree
*const c2
3002 = (const struct constant_descriptor_tree
*) p2
;
3003 if (c1
->hash
!= c2
->hash
)
3005 return compare_constant (c1
->value
, c2
->value
);
3008 /* Compare t1 and t2, and return 1 only if they are known to result in
3009 the same bit pattern on output. */
3012 compare_constant (const tree t1
, const tree t2
)
3014 enum tree_code typecode
;
3016 if (t1
== NULL_TREE
)
3017 return t2
== NULL_TREE
;
3018 if (t2
== NULL_TREE
)
3021 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3024 switch (TREE_CODE (t1
))
3027 /* Integer constants are the same only if the same width of type. */
3028 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3030 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3032 return tree_int_cst_equal (t1
, t2
);
3035 /* Real constants are the same only if the same width of type. */
3036 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3039 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3042 /* Fixed constants are the same only if the same width of type. */
3043 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3046 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3049 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3052 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3053 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3054 TREE_STRING_LENGTH (t1
)));
3057 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3058 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3064 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
3065 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
3068 link2
= TREE_VECTOR_CST_ELTS (t2
);
3069 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
3071 link1
= TREE_CHAIN (link1
))
3073 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
3075 link2
= TREE_CHAIN (link2
);
3083 VEC(constructor_elt
, gc
) *v1
, *v2
;
3084 unsigned HOST_WIDE_INT idx
;
3086 typecode
= TREE_CODE (TREE_TYPE (t1
));
3087 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3090 if (typecode
== ARRAY_TYPE
)
3092 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3093 /* For arrays, check that the sizes all match. */
3094 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3096 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3101 /* For record and union constructors, require exact type
3103 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3107 v1
= CONSTRUCTOR_ELTS (t1
);
3108 v2
= CONSTRUCTOR_ELTS (t2
);
3109 if (VEC_length (constructor_elt
, v1
)
3110 != VEC_length (constructor_elt
, v2
))
3113 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
3115 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
3116 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
3118 /* Check that each value is the same... */
3119 if (!compare_constant (c1
->value
, c2
->value
))
3121 /* ... and that they apply to the same fields! */
3122 if (typecode
== ARRAY_TYPE
)
3124 if (!compare_constant (c1
->index
, c2
->index
))
3129 if (c1
->index
!= c2
->index
)
3140 struct addr_const value1
, value2
;
3144 decode_addr_const (t1
, &value1
);
3145 decode_addr_const (t2
, &value2
);
3147 if (value1
.offset
!= value2
.offset
)
3150 code
= GET_CODE (value1
.base
);
3151 if (code
!= GET_CODE (value2
.base
))
3157 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3161 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
3162 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
3172 case POINTER_PLUS_EXPR
:
3175 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3176 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3179 case VIEW_CONVERT_EXPR
:
3180 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3189 /* Make a copy of the whole tree structure for a constant. This
3190 handles the same types of nodes that compare_constant handles. */
3193 copy_constant (tree exp
)
3195 switch (TREE_CODE (exp
))
3198 /* For ADDR_EXPR, we do not want to copy the decl whose address
3199 is requested. We do want to copy constants though. */
3200 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3201 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3202 copy_constant (TREE_OPERAND (exp
, 0)));
3204 return copy_node (exp
);
3210 return copy_node (exp
);
3213 return build_complex (TREE_TYPE (exp
),
3214 copy_constant (TREE_REALPART (exp
)),
3215 copy_constant (TREE_IMAGPART (exp
)));
3218 case POINTER_PLUS_EXPR
:
3220 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
3221 copy_constant (TREE_OPERAND (exp
, 0)),
3222 copy_constant (TREE_OPERAND (exp
, 1)));
3225 case VIEW_CONVERT_EXPR
:
3226 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3227 copy_constant (TREE_OPERAND (exp
, 0)));
3230 return build_vector (TREE_TYPE (exp
),
3231 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
3235 tree copy
= copy_node (exp
);
3236 VEC(constructor_elt
, gc
) *v
;
3237 unsigned HOST_WIDE_INT idx
;
3238 tree purpose
, value
;
3240 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
3241 CONSTRUCTOR_ELTS (exp
)));
3242 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3244 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
3245 ce
->index
= purpose
;
3246 ce
->value
= copy_constant (value
);
3248 CONSTRUCTOR_ELTS (copy
) = v
;
3257 /* Return the section into which constant EXP should be placed. */
3260 get_constant_section (tree exp
, unsigned int align
)
3262 return targetm
.asm_out
.select_section (exp
,
3263 compute_reloc_for_constant (exp
),
3267 /* Return the size of constant EXP in bytes. */
3269 static HOST_WIDE_INT
3270 get_constant_size (tree exp
)
3274 size
= int_size_in_bytes (TREE_TYPE (exp
));
3275 if (TREE_CODE (exp
) == STRING_CST
)
3276 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3280 /* Subroutine of output_constant_def:
3281 No constant equal to EXP is known to have been output.
3282 Make a constant descriptor to enter EXP in the hash table.
3283 Assign the label number and construct RTL to refer to the
3284 constant's location in memory.
3285 Caller is responsible for updating the hash table. */
3287 static struct constant_descriptor_tree
*
3288 build_constant_desc (tree exp
)
3290 struct constant_descriptor_tree
*desc
;
3296 desc
= GGC_NEW (struct constant_descriptor_tree
);
3297 desc
->value
= copy_constant (exp
);
3299 /* Propagate marked-ness to copied constant. */
3300 if (flag_mudflap
&& mf_marked_p (exp
))
3301 mf_mark (desc
->value
);
3303 /* Create a string containing the label name, in LABEL. */
3304 labelno
= const_labelno
++;
3305 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3307 /* Construct the VAR_DECL associated with the constant. */
3308 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
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
)
3324 #ifdef CONSTANT_ALIGNMENT
3325 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3329 align_variable (decl
, 0);
3331 /* Now construct the SYMBOL_REF and the MEM. */
3332 if (use_object_blocks_p ())
3334 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3335 symbol
= create_block_symbol (ggc_strdup (label
),
3336 get_block_for_section (sect
), -1);
3339 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3340 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3341 SET_SYMBOL_REF_DECL (symbol
, decl
);
3342 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3344 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3345 set_mem_attributes (rtl
, exp
, 1);
3346 set_mem_alias_set (rtl
, 0);
3347 set_mem_alias_set (rtl
, const_alias_set
);
3349 /* We cannot share RTX'es in pool entries.
3350 Mark this piece of RTL as required for unsharing. */
3351 RTX_FLAG (rtl
, used
) = 1;
3353 /* Set flags or add text to the name to record information, such as
3354 that it is a local symbol. If the name is changed, the macro
3355 ASM_OUTPUT_LABELREF will have to know how to strip this
3356 information. This call might invalidate our local variable
3357 SYMBOL; we can't use it afterward. */
3358 targetm
.encode_section_info (exp
, rtl
, true);
3365 /* Return an rtx representing a reference to constant data in memory
3366 for the constant expression EXP.
3368 If assembler code for such a constant has already been output,
3369 return an rtx to refer to it.
3370 Otherwise, output such a constant in memory
3371 and generate an rtx for it.
3373 If DEFER is nonzero, this constant can be deferred and output only
3374 if referenced in the function after all optimizations.
3376 `const_desc_table' records which constants already have label strings. */
3379 output_constant_def (tree exp
, int defer
)
3381 struct constant_descriptor_tree
*desc
;
3382 struct constant_descriptor_tree key
;
3385 /* Look up EXP in the table of constant descriptors. If we didn't find
3386 it, create a new one. */
3388 key
.hash
= const_hash_1 (exp
);
3389 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3391 desc
= (struct constant_descriptor_tree
*) *loc
;
3394 desc
= build_constant_desc (exp
);
3395 desc
->hash
= key
.hash
;
3399 maybe_output_constant_def_contents (desc
, defer
);
3403 /* Subroutine of output_constant_def: Decide whether or not we need to
3404 output the constant DESC now, and if so, do it. */
3406 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3409 rtx symbol
= XEXP (desc
->rtl
, 0);
3410 tree exp
= desc
->value
;
3412 if (flag_syntax_only
)
3415 if (TREE_ASM_WRITTEN (exp
))
3416 /* Already output; don't do it again. */
3419 /* We can always defer constants as long as the context allows
3423 /* Increment n_deferred_constants if it exists. It needs to be at
3424 least as large as the number of constants actually referred to
3425 by the function. If it's too small we'll stop looking too early
3426 and fail to emit constants; if it's too large we'll only look
3427 through the entire function when we could have stopped earlier. */
3429 n_deferred_constants
++;
3433 output_constant_def_contents (symbol
);
3436 /* Subroutine of output_constant_def_contents. Output the definition
3437 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3438 constant's alignment in bits. */
3441 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3445 size
= get_constant_size (exp
);
3447 /* Do any machine/system dependent processing of the constant. */
3448 #ifdef ASM_DECLARE_CONSTANT_NAME
3449 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
3451 /* Standard thing is just output label for the constant. */
3452 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3453 #endif /* ASM_DECLARE_CONSTANT_NAME */
3455 /* Output the value of EXP. */
3456 output_constant (exp
, size
, align
);
3459 /* We must output the constant data referred to by SYMBOL; do so. */
3462 output_constant_def_contents (rtx symbol
)
3464 tree decl
= SYMBOL_REF_DECL (symbol
);
3465 tree exp
= DECL_INITIAL (decl
);
3468 /* Make sure any other constants whose addresses appear in EXP
3469 are assigned label numbers. */
3470 output_addressed_constants (exp
);
3472 /* We are no longer deferring this constant. */
3473 TREE_ASM_WRITTEN (exp
) = 1;
3475 /* If the constant is part of an object block, make sure that the
3476 decl has been positioned within its block, but do not write out
3477 its definition yet. output_object_blocks will do that later. */
3478 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3479 place_block_symbol (symbol
);
3482 align
= DECL_ALIGN (decl
);
3483 switch_to_section (get_constant_section (exp
, align
));
3484 if (align
> BITS_PER_UNIT
)
3485 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3486 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3489 mudflap_enqueue_constant (exp
);
3492 /* Look up EXP in the table of constant descriptors. Return the rtl
3493 if it has been emitted, else null. */
3496 lookup_constant_def (tree exp
)
3498 struct constant_descriptor_tree
*desc
;
3499 struct constant_descriptor_tree key
;
3502 key
.hash
= const_hash_1 (exp
);
3503 desc
= (struct constant_descriptor_tree
*)
3504 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3506 return (desc
? desc
->rtl
: NULL_RTX
);
3509 /* Return a tree representing a reference to constant data in memory
3510 for the constant expression EXP.
3512 This is the counterpart of output_constant_def at the Tree level. */
3515 tree_output_constant_def (tree exp
)
3517 struct constant_descriptor_tree
*desc
, key
;
3521 /* Look up EXP in the table of constant descriptors. If we didn't find
3522 it, create a new one. */
3524 key
.hash
= const_hash_1 (exp
);
3525 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3527 desc
= (struct constant_descriptor_tree
*) *loc
;
3530 desc
= build_constant_desc (exp
);
3531 desc
->hash
= key
.hash
;
3535 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3536 varpool_finalize_decl (decl
);
3540 /* Used in the hash tables to avoid outputting the same constant
3541 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3542 are output once per function, not once per file. */
3543 /* ??? Only a few targets need per-function constant pools. Most
3544 can use one per-file pool. Should add a targetm bit to tell the
3547 struct GTY(()) rtx_constant_pool
{
3548 /* Pointers to first and last constant in pool, as ordered by offset. */
3549 struct constant_descriptor_rtx
*first
;
3550 struct constant_descriptor_rtx
*last
;
3552 /* Hash facility for making memory-constants from constant rtl-expressions.
3553 It is used on RISC machines where immediate integer arguments and
3554 constant addresses are restricted so that such constants must be stored
3556 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3558 /* Current offset in constant pool (does not include any
3559 machine-specific header). */
3560 HOST_WIDE_INT offset
;
3563 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3564 struct constant_descriptor_rtx
*next
;
3568 HOST_WIDE_INT offset
;
3570 enum machine_mode mode
;
3576 /* Hash and compare functions for const_rtx_htab. */
3579 const_desc_rtx_hash (const void *ptr
)
3581 const struct constant_descriptor_rtx
*const desc
3582 = (const struct constant_descriptor_rtx
*) ptr
;
3587 const_desc_rtx_eq (const void *a
, const void *b
)
3589 const struct constant_descriptor_rtx
*const x
3590 = (const struct constant_descriptor_rtx
*) a
;
3591 const struct constant_descriptor_rtx
*const y
3592 = (const struct constant_descriptor_rtx
*) b
;
3594 if (x
->mode
!= y
->mode
)
3596 return rtx_equal_p (x
->constant
, y
->constant
);
3599 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3602 const_rtx_hash_1 (rtx
*xp
, void *data
)
3604 unsigned HOST_WIDE_INT hwi
;
3605 enum machine_mode mode
;
3611 code
= GET_CODE (x
);
3612 mode
= GET_MODE (x
);
3613 h
= (hashval_t
) code
* 1048573 + mode
;
3621 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3622 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3625 h
^= (hashval_t
) hwi
;
3626 for (i
= 1; i
< n
; ++i
)
3629 h
^= (hashval_t
) hwi
;
3635 if (mode
== VOIDmode
)
3637 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3641 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3645 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3651 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3652 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3657 h
^= htab_hash_string (XSTR (x
, 0));
3661 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3665 case UNSPEC_VOLATILE
:
3666 h
= h
* 251 + XINT (x
, 1);
3673 hp
= (hashval_t
*) data
;
3674 *hp
= *hp
* 509 + h
;
3678 /* Compute a hash value for X, which should be a constant. */
3681 const_rtx_hash (rtx x
)
3684 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3689 /* Create and return a new rtx constant pool. */
3691 static struct rtx_constant_pool
*
3692 create_constant_pool (void)
3694 struct rtx_constant_pool
*pool
;
3696 pool
= GGC_NEW (struct rtx_constant_pool
);
3697 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3698 const_desc_rtx_eq
, NULL
);
3705 /* Initialize constant pool hashing for a new function. */
3708 init_varasm_status (void)
3710 crtl
->varasm
.pool
= create_constant_pool ();
3711 crtl
->varasm
.deferred_constants
= 0;
3714 /* Given a MINUS expression, simplify it if both sides
3715 include the same symbol. */
3718 simplify_subtraction (rtx x
)
3720 rtx r
= simplify_rtx (x
);
3724 /* Given a constant rtx X, make (or find) a memory constant for its value
3725 and return a MEM rtx to refer to it in memory. */
3728 force_const_mem (enum machine_mode mode
, rtx x
)
3730 struct constant_descriptor_rtx
*desc
, tmp
;
3731 struct rtx_constant_pool
*pool
;
3738 /* If we're not allowed to drop X into the constant pool, don't. */
3739 if (targetm
.cannot_force_const_mem (x
))
3742 /* Record that this function has used a constant pool entry. */
3743 crtl
->uses_const_pool
= 1;
3745 /* Decide which pool to use. */
3746 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3747 ? shared_constant_pool
3748 : crtl
->varasm
.pool
);
3750 /* Lookup the value in the hashtable. */
3753 hash
= const_rtx_hash (x
);
3754 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3755 desc
= (struct constant_descriptor_rtx
*) *slot
;
3757 /* If the constant was already present, return its memory. */
3759 return copy_rtx (desc
->mem
);
3761 /* Otherwise, create a new descriptor. */
3762 desc
= GGC_NEW (struct constant_descriptor_rtx
);
3765 /* Align the location counter as required by EXP's data type. */
3766 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3767 #ifdef CONSTANT_ALIGNMENT
3769 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3770 if (type
!= NULL_TREE
)
3771 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3775 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3776 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3779 desc
->constant
= tmp
.constant
;
3780 desc
->offset
= pool
->offset
;
3783 desc
->align
= align
;
3784 desc
->labelno
= const_labelno
;
3787 pool
->offset
+= GET_MODE_SIZE (mode
);
3789 pool
->last
->next
= desc
;
3791 pool
->first
= pool
->last
= desc
;
3794 /* Create a string containing the label name, in LABEL. */
3795 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3798 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3799 the constants pool. */
3800 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3802 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3803 symbol
= create_block_symbol (ggc_strdup (label
),
3804 get_block_for_section (sect
), -1);
3807 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3809 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3810 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3811 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3813 /* Construct the MEM. */
3814 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3815 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3816 set_mem_align (def
, align
);
3818 /* If we're dropping a label to the constant pool, make sure we
3820 if (GET_CODE (x
) == LABEL_REF
)
3821 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3823 return copy_rtx (def
);
3826 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3829 get_pool_constant (rtx addr
)
3831 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3834 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3835 and whether it has been output or not. */
3838 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3840 struct constant_descriptor_rtx
*desc
;
3842 desc
= SYMBOL_REF_CONSTANT (addr
);
3843 *pmarked
= (desc
->mark
!= 0);
3844 return desc
->constant
;
3847 /* Similar, return the mode. */
3850 get_pool_mode (const_rtx addr
)
3852 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3855 /* Return the size of the constant pool. */
3858 get_pool_size (void)
3860 return crtl
->varasm
.pool
->offset
;
3863 /* Worker function for output_constant_pool_1. Emit assembly for X
3864 in MODE with known alignment ALIGN. */
3867 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3869 switch (GET_MODE_CLASS (mode
))
3872 case MODE_DECIMAL_FLOAT
:
3876 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3877 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3878 assemble_real (r
, mode
, align
);
3883 case MODE_PARTIAL_INT
:
3888 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3891 case MODE_VECTOR_FLOAT
:
3892 case MODE_VECTOR_INT
:
3893 case MODE_VECTOR_FRACT
:
3894 case MODE_VECTOR_UFRACT
:
3895 case MODE_VECTOR_ACCUM
:
3896 case MODE_VECTOR_UACCUM
:
3899 enum machine_mode submode
= GET_MODE_INNER (mode
);
3900 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3902 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3903 units
= CONST_VECTOR_NUNITS (x
);
3905 for (i
= 0; i
< units
; i
++)
3907 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3908 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3918 /* Worker function for output_constant_pool. Emit constant DESC,
3919 giving it ALIGN bits of alignment. */
3922 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3929 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3930 whose CODE_LABEL has been deleted. This can occur if a jump table
3931 is eliminated by optimization. If so, write a constant of zero
3932 instead. Note that this can also happen by turning the
3933 CODE_LABEL into a NOTE. */
3934 /* ??? This seems completely and utterly wrong. Certainly it's
3935 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3936 functioning even with INSN_DELETED_P and friends. */
3939 switch (GET_CODE (tmp
))
3942 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3943 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3945 tmp
= XEXP (XEXP (tmp
, 0), 0);
3949 tmp
= XEXP (tmp
, 0);
3950 gcc_assert (!INSN_DELETED_P (tmp
));
3951 gcc_assert (!NOTE_P (tmp
)
3952 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3959 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3960 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3961 align
, desc
->labelno
, done
);
3964 assemble_align (align
);
3966 /* Output the label. */
3967 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3969 /* Output the data. */
3970 output_constant_pool_2 (desc
->mode
, x
, align
);
3972 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3973 sections have proper size. */
3974 if (align
> GET_MODE_BITSIZE (desc
->mode
)
3976 && (in_section
->common
.flags
& SECTION_MERGE
))
3977 assemble_align (align
);
3979 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3985 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3986 to as used. Emit referenced deferred strings. This function can
3987 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3990 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
3992 rtx x
= *current_rtx
;
3994 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
3997 if (CONSTANT_POOL_ADDRESS_P (x
))
3999 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
4000 if (desc
->mark
== 0)
4003 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
4006 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4008 tree decl
= SYMBOL_REF_DECL (x
);
4009 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4011 n_deferred_constants
--;
4012 output_constant_def_contents (x
);
4019 /* Look through appropriate parts of INSN, marking all entries in the
4020 constant pool which are actually being used. Entries that are only
4021 referenced by other constants are also marked as used. Emit
4022 deferred strings that are used. */
4025 mark_constants (rtx insn
)
4030 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4031 insns, not any notes that may be attached. We don't want to mark
4032 a constant just because it happens to appear in a REG_EQUIV note. */
4033 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
4035 rtx seq
= PATTERN (insn
);
4036 int i
, n
= XVECLEN (seq
, 0);
4037 for (i
= 0; i
< n
; ++i
)
4039 rtx subinsn
= XVECEXP (seq
, 0, i
);
4040 if (INSN_P (subinsn
))
4041 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
4045 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
4048 /* Look through the instructions for this function, and mark all the
4049 entries in POOL which are actually being used. Emit deferred constants
4050 which have indeed been used. */
4053 mark_constant_pool (void)
4057 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4060 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4061 mark_constants (insn
);
4063 for (link
= crtl
->epilogue_delay_list
;
4065 link
= XEXP (link
, 1))
4066 mark_constants (XEXP (link
, 0));
4069 /* Write all the constants in POOL. */
4072 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4074 struct constant_descriptor_rtx
*desc
;
4076 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4079 /* If the constant is part of an object_block, make sure that
4080 the constant has been positioned within its block, but do not
4081 write out its definition yet. output_object_blocks will do
4083 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4084 && SYMBOL_REF_BLOCK (desc
->sym
))
4085 place_block_symbol (desc
->sym
);
4088 switch_to_section (targetm
.asm_out
.select_rtx_section
4089 (desc
->mode
, desc
->constant
, desc
->align
));
4090 output_constant_pool_1 (desc
, desc
->align
);
4095 /* Mark all constants that are used in the current function, then write
4096 out the function's private constant pool. */
4099 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4100 tree fndecl ATTRIBUTE_UNUSED
)
4102 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4104 /* It is possible for gcc to call force_const_mem and then to later
4105 discard the instructions which refer to the constant. In such a
4106 case we do not need to output the constant. */
4107 mark_constant_pool ();
4109 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4110 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4113 output_constant_pool_contents (pool
);
4115 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4116 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4120 /* Write the contents of the shared constant pool. */
4123 output_shared_constant_pool (void)
4125 output_constant_pool_contents (shared_constant_pool
);
4128 /* Determine what kind of relocations EXP may need. */
4131 compute_reloc_for_constant (tree exp
)
4133 int reloc
= 0, reloc2
;
4136 switch (TREE_CODE (exp
))
4140 /* Go inside any operations that get_inner_reference can handle and see
4141 if what's inside is a constant: no need to do anything here for
4142 addresses of variables or functions. */
4143 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4144 tem
= TREE_OPERAND (tem
, 0))
4147 if (TREE_PUBLIC (tem
))
4154 case POINTER_PLUS_EXPR
:
4155 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4156 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4160 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4161 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4162 /* The difference of two local labels is computable at link time. */
4163 if (reloc
== 1 && reloc2
== 1)
4170 case VIEW_CONVERT_EXPR
:
4171 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4176 unsigned HOST_WIDE_INT idx
;
4177 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4179 reloc
|= compute_reloc_for_constant (tem
);
4189 /* Find all the constants whose addresses are referenced inside of EXP,
4190 and make sure assembler code with a label has been output for each one.
4191 Indicate whether an ADDR_EXPR has been encountered. */
4194 output_addressed_constants (tree exp
)
4198 switch (TREE_CODE (exp
))
4202 /* Go inside any operations that get_inner_reference can handle and see
4203 if what's inside is a constant: no need to do anything here for
4204 addresses of variables or functions. */
4205 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4206 tem
= TREE_OPERAND (tem
, 0))
4209 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4210 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4211 tem
= DECL_INITIAL (tem
);
4213 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4214 output_constant_def (tem
, 0);
4218 case POINTER_PLUS_EXPR
:
4220 output_addressed_constants (TREE_OPERAND (exp
, 1));
4224 case VIEW_CONVERT_EXPR
:
4225 output_addressed_constants (TREE_OPERAND (exp
, 0));
4230 unsigned HOST_WIDE_INT idx
;
4231 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4233 output_addressed_constants (tem
);
4242 /* Whether a constructor CTOR is a valid static constant initializer if all
4243 its elements are. This used to be internal to initializer_constant_valid_p
4244 and has been exposed to let other functions like categorize_ctor_elements
4245 evaluate the property while walking a constructor for other purposes. */
4248 constructor_static_from_elts_p (const_tree ctor
)
4250 return (TREE_CONSTANT (ctor
)
4251 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4252 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
)
4253 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)));
4256 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4259 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4260 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4261 which are valid when ENDTYPE is an integer of any size; in
4262 particular, this does not accept a pointer minus a constant. This
4263 returns null_pointer_node if the VALUE is an absolute constant
4264 which can be used to initialize a static variable. Otherwise it
4268 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4272 if (!INTEGRAL_TYPE_P (endtype
))
4275 op0
= TREE_OPERAND (value
, 0);
4276 op1
= TREE_OPERAND (value
, 1);
4278 /* Like STRIP_NOPS except allow the operand mode to widen. This
4279 works around a feature of fold that simplifies (int)(p1 - p2) to
4280 ((int)p1 - (int)p2) under the theory that the narrower operation
4283 while (CONVERT_EXPR_P (op0
)
4284 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4286 tree inner
= TREE_OPERAND (op0
, 0);
4287 if (inner
== error_mark_node
4288 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4289 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4290 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4295 while (CONVERT_EXPR_P (op1
)
4296 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4298 tree inner
= TREE_OPERAND (op1
, 0);
4299 if (inner
== error_mark_node
4300 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4301 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4302 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4307 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4311 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4312 cache
? cache
+ 2 : NULL
);
4313 /* Both initializers must be known. */
4317 && (op0
== null_pointer_node
4318 || TREE_CODE (value
) == MINUS_EXPR
))
4319 return null_pointer_node
;
4321 /* Support differences between labels. */
4322 if (TREE_CODE (op0
) == LABEL_DECL
4323 && TREE_CODE (op1
) == LABEL_DECL
)
4324 return null_pointer_node
;
4326 if (TREE_CODE (op0
) == STRING_CST
4327 && TREE_CODE (op1
) == STRING_CST
4328 && operand_equal_p (op0
, op1
, 1))
4329 return null_pointer_node
;
4335 /* Helper function of initializer_constant_valid_p.
4336 Return nonzero if VALUE is a valid constant-valued expression
4337 for use in initializing a static variable; one that can be an
4338 element of a "constant" initializer.
4340 Return null_pointer_node if the value is absolute;
4341 if it is relocatable, return the variable that determines the relocation.
4342 We assume that VALUE has been folded as much as possible;
4343 therefore, we do not need to check for such things as
4344 arithmetic-combinations of integers.
4346 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4349 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4353 switch (TREE_CODE (value
))
4356 if (constructor_static_from_elts_p (value
))
4358 unsigned HOST_WIDE_INT idx
;
4360 bool absolute
= true;
4362 if (cache
&& cache
[0] == value
)
4364 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4367 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4374 cache
[1] = NULL_TREE
;
4378 if (reloc
!= null_pointer_node
)
4381 /* For a non-absolute relocation, there is no single
4382 variable that can be "the variable that determines the
4387 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4389 return absolute
? null_pointer_node
: error_mark_node
;
4392 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4400 return null_pointer_node
;
4405 tree op0
= staticp (TREE_OPERAND (value
, 0));
4408 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4409 to be a constant, this is old-skool offsetof-like nonsense. */
4410 if (TREE_CODE (op0
) == INDIRECT_REF
4411 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4412 return null_pointer_node
;
4413 /* Taking the address of a nested function involves a trampoline,
4414 unless we don't need or want one. */
4415 if (TREE_CODE (op0
) == FUNCTION_DECL
4416 && DECL_STATIC_CHAIN (op0
)
4417 && !TREE_NO_TRAMPOLINE (value
))
4419 /* "&{...}" requires a temporary to hold the constructed
4421 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4427 case NON_LVALUE_EXPR
:
4428 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4431 case VIEW_CONVERT_EXPR
:
4433 tree src
= TREE_OPERAND (value
, 0);
4434 tree src_type
= TREE_TYPE (src
);
4435 tree dest_type
= TREE_TYPE (value
);
4437 /* Allow view-conversions from aggregate to non-aggregate type only
4438 if the bit pattern is fully preserved afterwards; otherwise, the
4439 RTL expander won't be able to apply a subsequent transformation
4440 to the underlying constructor. */
4441 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4443 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4444 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4449 /* Allow all other kinds of view-conversion. */
4450 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4455 tree src
= TREE_OPERAND (value
, 0);
4456 tree src_type
= TREE_TYPE (src
);
4457 tree dest_type
= TREE_TYPE (value
);
4459 /* Allow conversions between pointer types, floating-point
4460 types, and offset types. */
4461 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4462 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4463 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4464 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4465 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4467 /* Allow length-preserving conversions between integer types. */
4468 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4469 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4470 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4472 /* Allow conversions between other integer types only if
4474 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4476 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4477 if (inner
== null_pointer_node
)
4478 return null_pointer_node
;
4482 /* Allow (int) &foo provided int is as wide as a pointer. */
4483 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4484 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4485 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4487 /* Likewise conversions from int to pointers, but also allow
4488 conversions from 0. */
4489 if ((POINTER_TYPE_P (dest_type
)
4490 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4491 && INTEGRAL_TYPE_P (src_type
))
4493 if (TREE_CODE (src
) == INTEGER_CST
4494 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4495 return null_pointer_node
;
4496 if (integer_zerop (src
))
4497 return null_pointer_node
;
4498 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4499 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4502 /* Allow conversions to struct or union types if the value
4504 if (TREE_CODE (dest_type
) == RECORD_TYPE
4505 || TREE_CODE (dest_type
) == UNION_TYPE
)
4506 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4510 case POINTER_PLUS_EXPR
:
4512 /* Any valid floating-point constants will have been folded by now;
4513 with -frounding-math we hit this with addition of two constants. */
4514 if (TREE_CODE (endtype
) == REAL_TYPE
)
4516 if (cache
&& cache
[0] == value
)
4518 if (! INTEGRAL_TYPE_P (endtype
)
4519 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4521 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4523 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4526 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4527 endtype
, ncache
+ 2);
4528 /* If either term is absolute, use the other term's relocation. */
4529 if (valid0
== null_pointer_node
)
4531 else if (valid1
== null_pointer_node
)
4533 /* Support narrowing pointer differences. */
4535 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4539 /* Support narrowing pointer differences. */
4540 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4549 if (TREE_CODE (endtype
) == REAL_TYPE
)
4551 if (cache
&& cache
[0] == value
)
4553 if (! INTEGRAL_TYPE_P (endtype
)
4554 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4556 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4558 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4561 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4562 endtype
, ncache
+ 2);
4563 /* Win if second argument is absolute. */
4564 if (valid1
== null_pointer_node
)
4566 /* Win if both arguments have the same relocation.
4567 Then the value is absolute. */
4568 else if (valid0
== valid1
&& valid0
!= 0)
4569 ret
= null_pointer_node
;
4570 /* Since GCC guarantees that string constants are unique in the
4571 generated code, a subtraction between two copies of the same
4572 constant string is absolute. */
4573 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4574 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4575 && operand_equal_p (valid0
, valid1
, 1))
4576 ret
= null_pointer_node
;
4577 /* Support narrowing differences. */
4579 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4583 /* Support narrowing differences. */
4584 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
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.
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. */
4609 initializer_constant_valid_p (tree value
, tree endtype
)
4611 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4614 /* Return true if VALUE is a valid constant-valued expression
4615 for use in initializing a static bit-field; one that can be
4616 an element of a "constant" initializer. */
4619 initializer_constant_valid_for_bitfield_p (tree value
)
4621 /* For bitfields we support integer constants or possibly nested aggregates
4623 switch (TREE_CODE (value
))
4627 unsigned HOST_WIDE_INT idx
;
4630 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4631 if (!initializer_constant_valid_for_bitfield_p (elt
))
4639 case VIEW_CONVERT_EXPR
:
4640 case NON_LVALUE_EXPR
:
4642 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4651 /* output_constructor outer state of relevance in recursive calls, typically
4652 for nested aggregate bitfields. */
4655 unsigned int bit_offset
; /* current position in ... */
4656 int byte
; /* ... the outer byte buffer. */
4659 static unsigned HOST_WIDE_INT
4660 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4663 /* Output assembler code for constant EXP to FILE, with no label.
4664 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4665 Assumes output_addressed_constants has been done on EXP already.
4667 Generate exactly SIZE bytes of assembler data, padding at the end
4668 with zeros if necessary. SIZE must always be specified.
4670 SIZE is important for structure constructors,
4671 since trailing members may have been omitted from the constructor.
4672 It is also important for initialization of arrays from string constants
4673 since the full length of the string constant might not be wanted.
4674 It is also needed for initialization of unions, where the initializer's
4675 type is just one member, and that may not be as long as the union.
4677 There a case in which we would fail to output exactly SIZE bytes:
4678 for a structure constructor that wants to produce more than SIZE bytes.
4679 But such constructors will never be generated for any possible input.
4681 ALIGN is the alignment of the data in bits. */
4684 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4686 enum tree_code code
;
4687 unsigned HOST_WIDE_INT thissize
;
4689 if (size
== 0 || flag_syntax_only
)
4692 /* See if we're trying to initialize a pointer in a non-default mode
4693 to the address of some declaration somewhere. If the target says
4694 the mode is valid for pointers, assume the target has a way of
4696 if (TREE_CODE (exp
) == NOP_EXPR
4697 && POINTER_TYPE_P (TREE_TYPE (exp
))
4698 && targetm
.addr_space
.valid_pointer_mode
4699 (TYPE_MODE (TREE_TYPE (exp
)),
4700 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4702 tree saved_type
= TREE_TYPE (exp
);
4704 /* Peel off any intermediate conversions-to-pointer for valid
4706 while (TREE_CODE (exp
) == NOP_EXPR
4707 && POINTER_TYPE_P (TREE_TYPE (exp
))
4708 && targetm
.addr_space
.valid_pointer_mode
4709 (TYPE_MODE (TREE_TYPE (exp
)),
4710 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4711 exp
= TREE_OPERAND (exp
, 0);
4713 /* If what we're left with is the address of something, we can
4714 convert the address to the final type and output it that
4716 if (TREE_CODE (exp
) == ADDR_EXPR
)
4717 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4718 /* Likewise for constant ints. */
4719 else if (TREE_CODE (exp
) == INTEGER_CST
)
4720 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4721 TREE_INT_CST_HIGH (exp
));
4725 /* Eliminate any conversions since we'll be outputting the underlying
4727 while (CONVERT_EXPR_P (exp
)
4728 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4729 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4731 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4732 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4734 /* Make sure eliminating the conversion is really a no-op, except with
4735 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4736 union types to allow for Ada unchecked unions. */
4737 if (type_size
> op_size
4738 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4739 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4740 /* Keep the conversion. */
4743 exp
= TREE_OPERAND (exp
, 0);
4746 code
= TREE_CODE (TREE_TYPE (exp
));
4747 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4749 /* Allow a constructor with no elements for any data type.
4750 This means to fill the space with zeros. */
4751 if (TREE_CODE (exp
) == CONSTRUCTOR
4752 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4754 assemble_zeros (size
);
4758 if (TREE_CODE (exp
) == FDESC_EXPR
)
4760 #ifdef ASM_OUTPUT_FDESC
4761 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4762 tree decl
= TREE_OPERAND (exp
, 0);
4763 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4770 /* Now output the underlying data. If we've handling the padding, return.
4771 Otherwise, break and ensure SIZE is the size written. */
4778 case REFERENCE_TYPE
:
4780 case FIXED_POINT_TYPE
:
4781 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4782 EXPAND_INITIALIZER
),
4783 MIN (size
, thissize
), align
, 0))
4784 error ("initializer for integer/fixed-point value is too complicated");
4788 if (TREE_CODE (exp
) != REAL_CST
)
4789 error ("initializer for floating value is not a floating constant");
4791 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4795 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4796 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4797 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4802 switch (TREE_CODE (exp
))
4805 output_constructor (exp
, size
, align
, NULL
);
4808 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4810 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4817 unsigned int nalign
;
4818 enum machine_mode inner
;
4820 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4821 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4823 elt_size
= GET_MODE_SIZE (inner
);
4825 link
= TREE_VECTOR_CST_ELTS (exp
);
4826 output_constant (TREE_VALUE (link
), elt_size
, align
);
4827 thissize
= elt_size
;
4828 while ((link
= TREE_CHAIN (link
)) != NULL
)
4830 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4831 thissize
+= elt_size
;
4842 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4843 output_constructor (exp
, size
, align
, NULL
);
4853 if (size
> thissize
)
4854 assemble_zeros (size
- thissize
);
4858 /* Subroutine of output_constructor, used for computing the size of
4859 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4860 type with an unspecified upper bound. */
4862 static unsigned HOST_WIDE_INT
4863 array_size_for_constructor (tree val
)
4866 unsigned HOST_WIDE_INT cnt
;
4867 tree index
, value
, tmp
;
4869 /* This code used to attempt to handle string constants that are not
4870 arrays of single-bytes, but nothing else does, so there's no point in
4872 if (TREE_CODE (val
) == STRING_CST
)
4873 return TREE_STRING_LENGTH (val
);
4875 max_index
= NULL_TREE
;
4876 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4878 if (TREE_CODE (index
) == RANGE_EXPR
)
4879 index
= TREE_OPERAND (index
, 1);
4880 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4884 if (max_index
== NULL_TREE
)
4887 /* Compute the total number of array elements. */
4888 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4889 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4890 fold_convert (sizetype
, tmp
));
4891 i
= size_binop (PLUS_EXPR
, i
, build_int_cst (sizetype
, 1));
4893 /* Multiply by the array element unit size to find number of bytes. */
4894 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4896 return tree_low_cst (i
, 1);
4899 /* Other datastructures + helpers for output_constructor. */
4901 /* output_constructor local state to support interaction with helpers. */
4905 /* Received arguments. */
4906 tree exp
; /* Constructor expression. */
4907 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4908 unsigned int align
; /* Known initial alignment. */
4910 /* Constructor expression data. */
4911 tree type
; /* Expression type. */
4912 tree field
; /* Current field decl in a record. */
4913 tree min_index
; /* Lower bound if specified for an array. */
4915 /* Output processing state. */
4916 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4917 bool byte_buffer_in_use
; /* Whether byte ... */
4918 int byte
; /* ... contains part of a bitfield byte yet to
4921 int last_relative_index
; /* Implicit or explicit index of the last
4922 array element output within a bitfield. */
4923 /* Current element. */
4924 tree val
; /* Current element value. */
4925 tree index
; /* Current element index. */
4929 /* Helper for output_constructor. From the current LOCAL state, output a
4930 RANGE_EXPR element. */
4933 output_constructor_array_range (oc_local_state
*local
)
4935 unsigned HOST_WIDE_INT fieldsize
4936 = int_size_in_bytes (TREE_TYPE (local
->type
));
4938 HOST_WIDE_INT lo_index
4939 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4940 HOST_WIDE_INT hi_index
4941 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4942 HOST_WIDE_INT index
;
4945 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4947 for (index
= lo_index
; index
<= hi_index
; index
++)
4949 /* Output the element's initial value. */
4950 if (local
->val
== NULL_TREE
)
4951 assemble_zeros (fieldsize
);
4953 output_constant (local
->val
, fieldsize
, align2
);
4955 /* Count its size. */
4956 local
->total_bytes
+= fieldsize
;
4960 /* Helper for output_constructor. From the current LOCAL state, output a
4961 field element that is not true bitfield or part of an outer one. */
4964 output_constructor_regular_field (oc_local_state
*local
)
4966 /* Field size and position. Since this structure is static, we know the
4967 positions are constant. */
4968 unsigned HOST_WIDE_INT fieldsize
;
4969 HOST_WIDE_INT fieldpos
;
4971 unsigned int align2
;
4973 if (local
->index
!= NULL_TREE
)
4974 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
4975 * ((tree_low_cst (local
->index
, 0)
4976 - tree_low_cst (local
->min_index
, 0))));
4977 else if (local
->field
!= NULL_TREE
)
4978 fieldpos
= int_byte_position (local
->field
);
4982 /* Output any buffered-up bit-fields preceding this element. */
4983 if (local
->byte_buffer_in_use
)
4985 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
4986 local
->total_bytes
++;
4987 local
->byte_buffer_in_use
= false;
4990 /* Advance to offset of this element.
4991 Note no alignment needed in an array, since that is guaranteed
4992 if each element has the proper size. */
4993 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
4994 && fieldpos
!= local
->total_bytes
)
4996 gcc_assert (fieldpos
>= local
->total_bytes
);
4997 assemble_zeros (fieldpos
- local
->total_bytes
);
4998 local
->total_bytes
= fieldpos
;
5001 /* Find the alignment of this element. */
5002 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5004 /* Determine size this element should occupy. */
5009 /* If this is an array with an unspecified upper bound,
5010 the initializer determines the size. */
5011 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5012 but we cannot do this until the deprecated support for
5013 initializing zero-length array members is removed. */
5014 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5015 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
5016 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
5018 fieldsize
= array_size_for_constructor (local
->val
);
5019 /* Given a non-empty initialization, this field had
5021 gcc_assert (!fieldsize
|| !TREE_CHAIN (local
->field
));
5023 else if (DECL_SIZE_UNIT (local
->field
))
5025 /* ??? This can't be right. If the decl size overflows
5026 a host integer we will silently emit no data. */
5027 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
5028 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
5032 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5034 /* Output the element's initial value. */
5035 if (local
->val
== NULL_TREE
)
5036 assemble_zeros (fieldsize
);
5038 output_constant (local
->val
, fieldsize
, align2
);
5040 /* Count its size. */
5041 local
->total_bytes
+= fieldsize
;
5044 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5045 output an element that is a true bitfield or part of an outer one. */
5048 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
5050 /* Bit size of this element. */
5051 HOST_WIDE_INT ebitsize
5053 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
5054 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
5056 /* Relative index of this element if this is an array component. */
5057 HOST_WIDE_INT relative_index
5060 ? (tree_low_cst (local
->index
, 0)
5061 - tree_low_cst (local
->min_index
, 0))
5062 : local
->last_relative_index
+ 1)
5065 /* Bit position of this element from the start of the containing
5067 HOST_WIDE_INT constructor_relative_ebitpos
5069 ? int_bit_position (local
->field
)
5070 : ebitsize
* relative_index
);
5072 /* Bit position of this element from the start of a possibly ongoing
5073 outer byte buffer. */
5074 HOST_WIDE_INT byte_relative_ebitpos
5075 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
5077 /* From the start of a possibly ongoing outer byte buffer, offsets to
5078 the first bit of this element and to the first bit past the end of
5080 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5081 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5083 local
->last_relative_index
= relative_index
;
5085 if (local
->val
== NULL_TREE
)
5086 local
->val
= integer_zero_node
;
5088 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5089 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5090 local
->val
= TREE_OPERAND (local
->val
, 0);
5092 if (TREE_CODE (local
->val
) != INTEGER_CST
5093 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5095 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5099 /* If this field does not start in this (or, next) byte,
5101 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5103 /* Output remnant of any bit field in previous bytes. */
5104 if (local
->byte_buffer_in_use
)
5106 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5107 local
->total_bytes
++;
5108 local
->byte_buffer_in_use
= false;
5111 /* If still not at proper byte, advance to there. */
5112 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5114 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5115 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5116 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5120 /* Set up the buffer if necessary. */
5121 if (!local
->byte_buffer_in_use
)
5125 local
->byte_buffer_in_use
= true;
5128 /* If this is nested constructor, recurse passing the bit offset and the
5129 pending data, then retrieve the new pending data afterwards. */
5130 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5132 oc_outer_state output_state
;
5134 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5135 output_state
.byte
= local
->byte
;
5137 += output_constructor (local
->val
, 0, 0, &output_state
);
5138 local
->byte
= output_state
.byte
;
5142 /* Otherwise, we must split the element into pieces that fall within
5143 separate bytes, and combine each byte with previous or following
5145 while (next_offset
< end_offset
)
5149 HOST_WIDE_INT value
;
5150 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5151 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5153 /* Advance from byte to byte
5154 within this element when necessary. */
5155 while (next_byte
!= local
->total_bytes
)
5157 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5158 local
->total_bytes
++;
5162 /* Number of bits we can process at once
5163 (all part of the same byte). */
5164 this_time
= MIN (end_offset
- next_offset
,
5165 BITS_PER_UNIT
- next_bit
);
5166 if (BYTES_BIG_ENDIAN
)
5168 /* On big-endian machine, take the most significant bits
5169 first (of the bits that are significant)
5170 and put them into bytes from the most significant end. */
5171 shift
= end_offset
- next_offset
- this_time
;
5173 /* Don't try to take a bunch of bits that cross
5174 the word boundary in the INTEGER_CST. We can
5175 only select bits from the LOW or HIGH part
5177 if (shift
< HOST_BITS_PER_WIDE_INT
5178 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5180 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
5181 shift
= HOST_BITS_PER_WIDE_INT
;
5184 /* Now get the bits from the appropriate constant word. */
5185 if (shift
< HOST_BITS_PER_WIDE_INT
)
5186 value
= TREE_INT_CST_LOW (local
->val
);
5189 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5190 value
= TREE_INT_CST_HIGH (local
->val
);
5191 shift
-= HOST_BITS_PER_WIDE_INT
;
5194 /* Get the result. This works only when:
5195 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5196 local
->byte
|= (((value
>> shift
)
5197 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5198 << (BITS_PER_UNIT
- this_time
- next_bit
));
5202 /* On little-endian machines,
5203 take first the least significant bits of the value
5204 and pack them starting at the least significant
5205 bits of the bytes. */
5206 shift
= next_offset
- byte_relative_ebitpos
;
5208 /* Don't try to take a bunch of bits that cross
5209 the word boundary in the INTEGER_CST. We can
5210 only select bits from the LOW or HIGH part
5212 if (shift
< HOST_BITS_PER_WIDE_INT
5213 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5214 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
5216 /* Now get the bits from the appropriate constant word. */
5217 if (shift
< HOST_BITS_PER_WIDE_INT
)
5218 value
= TREE_INT_CST_LOW (local
->val
);
5221 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5222 value
= TREE_INT_CST_HIGH (local
->val
);
5223 shift
-= HOST_BITS_PER_WIDE_INT
;
5226 /* Get the result. This works only when:
5227 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5228 local
->byte
|= (((value
>> shift
)
5229 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5233 next_offset
+= this_time
;
5234 local
->byte_buffer_in_use
= true;
5238 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5239 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5240 caller output state of relevance in recursive invocations. */
5242 static unsigned HOST_WIDE_INT
5243 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5244 unsigned int align
, oc_outer_state
* outer
)
5246 unsigned HOST_WIDE_INT cnt
;
5247 constructor_elt
*ce
;
5249 oc_local_state local
;
5251 /* Setup our local state to communicate with helpers. */
5254 local
.align
= align
;
5256 local
.total_bytes
= 0;
5257 local
.byte_buffer_in_use
= outer
!= NULL
;
5258 local
.byte
= outer
? outer
->byte
: 0;
5260 local
.type
= TREE_TYPE (exp
);
5262 local
.last_relative_index
= -1;
5264 local
.min_index
= NULL_TREE
;
5265 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5266 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5267 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5269 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5271 /* As CE goes through the elements of the constant, FIELD goes through the
5272 structure fields if the constant is a structure. If the constant is a
5273 union, we override this by getting the field from the TREE_LIST element.
5274 But the constant could also be an array. Then FIELD is zero.
5276 There is always a maximum of one element in the chain LINK for unions
5277 (even if the initializer in a source program incorrectly contains
5280 local
.field
= NULL_TREE
;
5281 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5282 local
.field
= TYPE_FIELDS (local
.type
);
5285 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5286 cnt
++, local
.field
= local
.field
? TREE_CHAIN (local
.field
) : 0)
5288 local
.val
= ce
->value
;
5289 local
.index
= NULL_TREE
;
5291 /* The element in a union constructor specifies the proper field
5293 if ((TREE_CODE (local
.type
) == RECORD_TYPE
5294 || TREE_CODE (local
.type
) == UNION_TYPE
5295 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
5296 && ce
->index
!= NULL_TREE
)
5297 local
.field
= ce
->index
;
5299 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5300 local
.index
= ce
->index
;
5302 #ifdef ASM_COMMENT_START
5303 if (local
.field
&& flag_verbose_asm
)
5304 fprintf (asm_out_file
, "%s %s:\n",
5306 DECL_NAME (local
.field
)
5307 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5311 /* Eliminate the marker that makes a cast not be an lvalue. */
5312 if (local
.val
!= NULL_TREE
)
5313 STRIP_NOPS (local
.val
);
5315 /* Output the current element, using the appropriate helper ... */
5317 /* For an array slice not part of an outer bitfield. */
5319 && local
.index
!= NULL_TREE
5320 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5321 output_constructor_array_range (&local
);
5323 /* For a field that is neither a true bitfield nor part of an outer one,
5324 known to be at least byte aligned and multiple-of-bytes long. */
5326 && (local
.field
== NULL_TREE
5327 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5328 output_constructor_regular_field (&local
);
5330 /* For a true bitfield or part of an outer one. */
5332 output_constructor_bitfield (&local
, outer
);
5335 /* If we are not at toplevel, save the pending data for our caller.
5336 Otherwise output the pending data and padding zeros as needed. */
5338 outer
->byte
= local
.byte
;
5341 if (local
.byte_buffer_in_use
)
5343 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5344 local
.total_bytes
++;
5347 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5349 assemble_zeros (local
.size
- local
.total_bytes
);
5350 local
.total_bytes
= local
.size
;
5354 return local
.total_bytes
;
5357 /* Mark DECL as weak. */
5360 mark_weak (tree decl
)
5362 DECL_WEAK (decl
) = 1;
5364 if (DECL_RTL_SET_P (decl
)
5365 && MEM_P (DECL_RTL (decl
))
5366 && XEXP (DECL_RTL (decl
), 0)
5367 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5368 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5371 /* Merge weak status between NEWDECL and OLDDECL. */
5374 merge_weak (tree newdecl
, tree olddecl
)
5376 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5378 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
5381 /* We put the NEWDECL on the weak_decls list at some point
5382 and OLDDECL as well. Keep just OLDDECL on the list. */
5383 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5384 if (TREE_VALUE (*pwd
) == newdecl
)
5386 *pwd
= TREE_CHAIN (*pwd
);
5393 if (DECL_WEAK (newdecl
))
5397 /* NEWDECL is weak, but OLDDECL is not. */
5399 /* If we already output the OLDDECL, we're in trouble; we can't
5400 go back and make it weak. This error cannot be caught in
5401 declare_weak because the NEWDECL and OLDDECL was not yet
5402 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5403 if (TREE_ASM_WRITTEN (olddecl
))
5404 error ("weak declaration of %q+D must precede definition",
5407 /* If we've already generated rtl referencing OLDDECL, we may
5408 have done so in a way that will not function properly with
5410 else if (TREE_USED (olddecl
)
5411 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5412 warning (0, "weak declaration of %q+D after first use results "
5413 "in unspecified behavior", newdecl
);
5417 /* We put the NEWDECL on the weak_decls list at some point.
5418 Replace it with the OLDDECL. */
5419 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5420 if (TREE_VALUE (wd
) == newdecl
)
5422 TREE_VALUE (wd
) = olddecl
;
5425 /* We may not find the entry on the list. If NEWDECL is a
5426 weak alias, then we will have already called
5427 globalize_decl to remove the entry; in that case, we do
5428 not need to do anything. */
5431 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5432 mark_weak (olddecl
);
5435 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5436 weak. Just update NEWDECL to indicate that it's weak too. */
5437 mark_weak (newdecl
);
5440 /* Declare DECL to be a weak symbol. */
5443 declare_weak (tree decl
)
5445 if (! TREE_PUBLIC (decl
))
5446 error ("weak declaration of %q+D must be public", decl
);
5447 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5448 error ("weak declaration of %q+D must precede definition", decl
);
5449 else if (!SUPPORTS_WEAK
)
5450 warning (0, "weak declaration of %q+D not supported", decl
);
5453 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5454 DECL_ATTRIBUTES (decl
)
5455 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5459 weak_finish_1 (tree decl
)
5461 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5462 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5465 if (! TREE_USED (decl
))
5468 #ifdef ASM_WEAKEN_DECL
5469 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5471 #ifdef ASM_WEAKEN_LABEL
5472 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5474 #ifdef ASM_OUTPUT_WEAK_ALIAS
5476 static bool warn_once
= 0;
5479 warning (0, "only weak aliases are supported in this configuration");
5489 /* This TREE_LIST contains weakref targets. */
5491 static GTY(()) tree weakref_targets
;
5493 /* Forward declaration. */
5494 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5496 /* Emit any pending weak declarations. */
5503 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5505 tree alias_decl
= TREE_PURPOSE (t
);
5506 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5508 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5509 /* Remove alias_decl from the weak list, but leave entries for
5510 the target alone. */
5512 #ifndef ASM_OUTPUT_WEAKREF
5513 else if (! TREE_SYMBOL_REFERENCED (target
))
5515 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5516 defined, otherwise we and weak_finish_1 would use
5517 different macros. */
5518 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5519 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5521 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5525 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5526 TREE_CODE (alias_decl
), target
,
5527 TREE_TYPE (alias_decl
));
5529 DECL_EXTERNAL (decl
) = 1;
5530 TREE_PUBLIC (decl
) = 1;
5531 DECL_ARTIFICIAL (decl
) = 1;
5532 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5533 TREE_USED (decl
) = 1;
5536 weak_finish_1 (decl
);
5545 /* Remove the alias and the target from the pending weak list
5546 so that we do not emit any .weak directives for the former,
5547 nor multiple .weak directives for the latter. */
5548 for (p
= &weak_decls
; (t2
= *p
) ; )
5550 if (TREE_VALUE (t2
) == alias_decl
5551 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5552 *p
= TREE_CHAIN (t2
);
5554 p
= &TREE_CHAIN (t2
);
5557 /* Remove other weakrefs to the same target, to speed things up. */
5558 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5560 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5561 *p
= TREE_CHAIN (t2
);
5563 p
= &TREE_CHAIN (t2
);
5568 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5570 tree decl
= TREE_VALUE (t
);
5572 weak_finish_1 (decl
);
5576 /* Emit the assembly bits to indicate that DECL is globally visible. */
5579 globalize_decl (tree decl
)
5582 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5583 if (DECL_WEAK (decl
))
5585 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5588 #ifdef ASM_WEAKEN_DECL
5589 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5591 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5594 /* Remove this function from the pending weak list so that
5595 we do not emit multiple .weak directives for it. */
5596 for (p
= &weak_decls
; (t
= *p
) ; )
5598 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5599 *p
= TREE_CHAIN (t
);
5601 p
= &TREE_CHAIN (t
);
5604 /* Remove weakrefs to the same target from the pending weakref
5605 list, for the same reason. */
5606 for (p
= &weakref_targets
; (t
= *p
) ; )
5608 if (DECL_ASSEMBLER_NAME (decl
)
5609 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5610 *p
= TREE_CHAIN (t
);
5612 p
= &TREE_CHAIN (t
);
5619 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5622 VEC(alias_pair
,gc
) *alias_pairs
;
5624 /* Given an assembly name, find the decl it is associated with. At the
5625 same time, mark it needed for cgraph. */
5628 find_decl_and_mark_needed (tree decl
, tree target
)
5630 struct cgraph_node
*fnode
= NULL
;
5631 struct varpool_node
*vnode
= NULL
;
5633 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5635 fnode
= cgraph_node_for_asm (target
);
5637 vnode
= varpool_node_for_asm (target
);
5641 vnode
= varpool_node_for_asm (target
);
5643 fnode
= cgraph_node_for_asm (target
);
5648 cgraph_mark_needed_node (fnode
);
5653 varpool_mark_needed_node (vnode
);
5654 vnode
->force_output
= 1;
5661 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5662 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5663 tree node is DECL to have the value of the tree node TARGET. */
5666 do_assemble_alias (tree decl
, tree target
)
5668 if (TREE_ASM_WRITTEN (decl
))
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
);
5675 TREE_ASM_WRITTEN (decl
) = 1;
5676 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5678 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5680 ultimate_transparent_alias_target (&target
);
5682 if (!targetm
.have_tls
5683 && TREE_CODE (decl
) == VAR_DECL
5684 && DECL_THREAD_LOCAL_P (decl
))
5686 decl
= emutls_decl (decl
);
5687 target
= get_emutls_object_name (target
);
5690 if (!TREE_SYMBOL_REFERENCED (target
))
5691 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5693 #ifdef ASM_OUTPUT_WEAKREF
5694 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5695 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5696 IDENTIFIER_POINTER (target
));
5700 error_at (DECL_SOURCE_LOCATION (decl
),
5701 "weakref is not supported in this configuration");
5708 if (!targetm
.have_tls
5709 && TREE_CODE (decl
) == VAR_DECL
5710 && DECL_THREAD_LOCAL_P (decl
))
5712 decl
= emutls_decl (decl
);
5713 target
= get_emutls_object_name (target
);
5716 #ifdef ASM_OUTPUT_DEF
5717 /* Make name accessible from other files, if appropriate. */
5719 if (TREE_PUBLIC (decl
))
5721 globalize_decl (decl
);
5722 maybe_assemble_visibility (decl
);
5725 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5726 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5728 ASM_OUTPUT_DEF (asm_out_file
,
5729 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5730 IDENTIFIER_POINTER (target
));
5732 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5737 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5738 # ifdef ASM_WEAKEN_DECL
5739 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5741 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5743 /* Remove this function from the pending weak list so that
5744 we do not emit multiple .weak directives for it. */
5745 for (p
= &weak_decls
; (t
= *p
) ; )
5746 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5747 *p
= TREE_CHAIN (t
);
5749 p
= &TREE_CHAIN (t
);
5751 /* Remove weakrefs to the same target from the pending weakref
5752 list, for the same reason. */
5753 for (p
= &weakref_targets
; (t
= *p
) ; )
5755 if (DECL_ASSEMBLER_NAME (decl
)
5756 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5757 *p
= TREE_CHAIN (t
);
5759 p
= &TREE_CHAIN (t
);
5766 /* Remove the alias pairing for functions that are no longer in the call
5770 remove_unreachable_alias_pairs (void)
5775 if (alias_pairs
== NULL
)
5778 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5780 if (!DECL_EXTERNAL (p
->decl
))
5782 struct cgraph_node
*fnode
= NULL
;
5783 struct varpool_node
*vnode
= NULL
;
5784 fnode
= cgraph_node_for_asm (p
->target
);
5785 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5786 if (fnode
== NULL
&& vnode
== NULL
)
5788 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5798 /* First pass of completing pending aliases. Make sure that cgraph knows
5799 which symbols will be required. */
5802 finish_aliases_1 (void)
5807 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5811 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5812 if (target_decl
== NULL
)
5814 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5815 error ("%q+D aliased to undefined symbol %qE",
5816 p
->decl
, p
->target
);
5818 else if (DECL_EXTERNAL (target_decl
)
5819 /* We use local aliases for C++ thunks to force the tailcall
5820 to bind locally. Of course this is a hack - to keep it
5821 working do the following (which is not strictly correct). */
5822 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5823 || ! DECL_VIRTUAL_P (target_decl
))
5824 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5825 error ("%q+D aliased to external symbol %qE",
5826 p
->decl
, p
->target
);
5830 /* Second pass of completing pending aliases. Emit the actual assembly.
5831 This happens at the end of compilation and thus it is assured that the
5832 target symbol has been emitted. */
5835 finish_aliases_2 (void)
5840 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5841 do_assemble_alias (p
->decl
, p
->target
);
5843 VEC_truncate (alias_pair
, alias_pairs
, 0);
5846 /* Emit an assembler directive to make the symbol for DECL an alias to
5847 the symbol for TARGET. */
5850 assemble_alias (tree decl
, tree target
)
5853 bool is_weakref
= false;
5855 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5857 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5861 ultimate_transparent_alias_target (&target
);
5863 if (alias
== target
)
5864 error ("weakref %q+D ultimately targets itself", decl
);
5867 #ifndef ASM_OUTPUT_WEAKREF
5868 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5869 TREE_CHAIN (alias
) = target
;
5872 if (TREE_PUBLIC (decl
))
5873 error ("weakref %q+D must have static linkage", decl
);
5877 #if !defined (ASM_OUTPUT_DEF)
5878 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5879 error_at (DECL_SOURCE_LOCATION (decl
),
5880 "alias definitions not supported in this configuration");
5883 if (!DECL_WEAK (decl
))
5885 error_at (DECL_SOURCE_LOCATION (decl
),
5886 "only weak aliases are supported in this configuration");
5892 TREE_USED (decl
) = 1;
5894 /* A quirk of the initial implementation of aliases required that the user
5895 add "extern" to all of them. Which is silly, but now historical. Do
5896 note that the symbol is in fact locally defined. */
5898 DECL_EXTERNAL (decl
) = 0;
5900 /* Allow aliases to aliases. */
5901 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5902 cgraph_node (decl
)->alias
= true;
5904 varpool_node (decl
)->alias
= true;
5906 /* If the target has already been emitted, we don't have to queue the
5907 alias. This saves a tad of memory. */
5908 if (cgraph_global_info_ready
)
5909 target_decl
= find_decl_and_mark_needed (decl
, target
);
5912 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5913 do_assemble_alias (decl
, target
);
5916 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5922 /* Emit an assembler directive to set symbol for DECL visibility to
5923 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5926 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5927 int vis ATTRIBUTE_UNUSED
)
5929 #ifdef HAVE_GAS_HIDDEN
5930 static const char * const visibility_types
[] = {
5931 NULL
, "protected", "hidden", "internal"
5934 const char *name
, *type
;
5936 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5937 type
= visibility_types
[vis
];
5939 fprintf (asm_out_file
, "\t.%s\t", type
);
5940 assemble_name (asm_out_file
, name
);
5941 fprintf (asm_out_file
, "\n");
5943 warning (OPT_Wattributes
, "visibility attribute not supported "
5944 "in this configuration; ignored");
5948 /* A helper function to call assemble_visibility when needed for a decl. */
5951 maybe_assemble_visibility (tree decl
)
5953 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5955 if (vis
!= VISIBILITY_DEFAULT
)
5957 targetm
.asm_out
.visibility (decl
, vis
);
5964 /* Returns 1 if the target configuration supports defining public symbols
5965 so that one of them will be chosen at link time instead of generating a
5966 multiply-defined symbol error, whether through the use of weak symbols or
5967 a target-specific mechanism for having duplicates discarded. */
5970 supports_one_only (void)
5972 if (SUPPORTS_ONE_ONLY
)
5974 return SUPPORTS_WEAK
;
5977 /* Set up DECL as a public symbol that can be defined in multiple
5978 translation units without generating a linker error. */
5981 make_decl_one_only (tree decl
, tree comdat_group
)
5983 gcc_assert (TREE_CODE (decl
) == VAR_DECL
5984 || TREE_CODE (decl
) == FUNCTION_DECL
);
5986 TREE_PUBLIC (decl
) = 1;
5988 if (SUPPORTS_ONE_ONLY
)
5990 #ifdef MAKE_DECL_ONE_ONLY
5991 MAKE_DECL_ONE_ONLY (decl
);
5993 DECL_COMDAT_GROUP (decl
) = comdat_group
;
5995 else if (TREE_CODE (decl
) == VAR_DECL
5996 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5997 DECL_COMMON (decl
) = 1;
6000 gcc_assert (SUPPORTS_WEAK
);
6001 DECL_WEAK (decl
) = 1;
6006 init_varasm_once (void)
6008 section_htab
= htab_create_ggc (31, section_entry_hash
,
6009 section_entry_eq
, NULL
);
6010 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
6011 object_block_entry_eq
, NULL
);
6012 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
6013 const_desc_eq
, NULL
);
6015 const_alias_set
= new_alias_set ();
6016 shared_constant_pool
= create_constant_pool ();
6018 #ifdef TEXT_SECTION_ASM_OP
6019 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6020 TEXT_SECTION_ASM_OP
);
6023 #ifdef DATA_SECTION_ASM_OP
6024 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6025 DATA_SECTION_ASM_OP
);
6028 #ifdef SDATA_SECTION_ASM_OP
6029 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6030 SDATA_SECTION_ASM_OP
);
6033 #ifdef READONLY_DATA_SECTION_ASM_OP
6034 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6035 READONLY_DATA_SECTION_ASM_OP
);
6038 #ifdef CTORS_SECTION_ASM_OP
6039 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6040 CTORS_SECTION_ASM_OP
);
6043 #ifdef DTORS_SECTION_ASM_OP
6044 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6045 DTORS_SECTION_ASM_OP
);
6048 #ifdef BSS_SECTION_ASM_OP
6049 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6050 output_section_asm_op
,
6051 BSS_SECTION_ASM_OP
);
6054 #ifdef SBSS_SECTION_ASM_OP
6055 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6056 output_section_asm_op
,
6057 SBSS_SECTION_ASM_OP
);
6060 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6061 | SECTION_COMMON
, emit_tls_common
);
6062 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6063 | SECTION_COMMON
, emit_local
);
6064 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6065 | SECTION_COMMON
, emit_common
);
6067 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6068 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6072 targetm
.asm_out
.init_sections ();
6074 if (readonly_data_section
== NULL
)
6075 readonly_data_section
= text_section
;
6079 decl_default_tls_model (const_tree decl
)
6081 enum tls_model kind
;
6084 is_local
= targetm
.binds_local_p (decl
);
6088 kind
= TLS_MODEL_LOCAL_EXEC
;
6090 kind
= TLS_MODEL_INITIAL_EXEC
;
6093 /* Local dynamic is inefficient when we're not combining the
6094 parts of the address. */
6095 else if (optimize
&& is_local
)
6096 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6098 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6099 if (kind
< flag_tls_default
)
6100 kind
= flag_tls_default
;
6105 /* Select a set of attributes for section NAME based on the properties
6106 of DECL and whether or not RELOC indicates that DECL's initializer
6107 might contain runtime relocations.
6109 We make the section read-only and executable for a function decl,
6110 read-only for a const data decl, and writable for a non-const data decl. */
6113 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6117 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6118 flags
= SECTION_CODE
;
6119 else if (decl
&& decl_readonly_section (decl
, reloc
))
6121 else if (current_function_decl
6123 && crtl
->subsections
.unlikely_text_section_name
6124 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
6125 flags
= SECTION_CODE
;
6127 && (!current_function_decl
|| !cfun
)
6128 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6129 flags
= SECTION_CODE
;
6131 flags
= SECTION_WRITE
;
6133 if (decl
&& DECL_ONE_ONLY (decl
))
6134 flags
|= SECTION_LINKONCE
;
6136 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6137 flags
|= SECTION_TLS
| SECTION_WRITE
;
6139 if (strcmp (name
, ".bss") == 0
6140 || strncmp (name
, ".bss.", 5) == 0
6141 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6142 || strcmp (name
, ".sbss") == 0
6143 || strncmp (name
, ".sbss.", 6) == 0
6144 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6145 flags
|= SECTION_BSS
;
6147 if (strcmp (name
, ".tdata") == 0
6148 || strncmp (name
, ".tdata.", 7) == 0
6149 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6150 flags
|= SECTION_TLS
;
6152 if (strcmp (name
, ".tbss") == 0
6153 || strncmp (name
, ".tbss.", 6) == 0
6154 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6155 flags
|= SECTION_TLS
| SECTION_BSS
;
6157 /* These three sections have special ELF types. They are neither
6158 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6159 want to print a section type (@progbits or @nobits). If someone
6160 is silly enough to emit code or TLS variables to one of these
6161 sections, then don't handle them specially. */
6162 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6163 && (strcmp (name
, ".init_array") == 0
6164 || strcmp (name
, ".fini_array") == 0
6165 || strcmp (name
, ".preinit_array") == 0))
6166 flags
|= SECTION_NOTYPE
;
6171 /* Return true if the target supports some form of global BSS,
6172 either through bss_noswitch_section, or by selecting a BSS
6173 section in TARGET_ASM_SELECT_SECTION. */
6176 have_global_bss_p (void)
6178 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6181 /* Output assembly to switch to section NAME with attribute FLAGS.
6182 Four variants for common object file formats. */
6185 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6186 unsigned int flags ATTRIBUTE_UNUSED
,
6187 tree decl ATTRIBUTE_UNUSED
)
6189 /* Some object formats don't support named sections at all. The
6190 front-end should already have flagged this as an error. */
6194 #ifndef TLS_SECTION_ASM_FLAG
6195 #define TLS_SECTION_ASM_FLAG 'T'
6199 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6200 tree decl ATTRIBUTE_UNUSED
)
6202 char flagchars
[10], *f
= flagchars
;
6204 /* If we have already declared this section, we can use an
6205 abbreviated form to switch back to it -- unless this section is
6206 part of a COMDAT groups, in which case GAS requires the full
6207 declaration every time. */
6208 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6209 && (flags
& SECTION_DECLARED
))
6211 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6215 if (!(flags
& SECTION_DEBUG
))
6217 if (flags
& SECTION_WRITE
)
6219 if (flags
& SECTION_CODE
)
6221 if (flags
& SECTION_SMALL
)
6223 if (flags
& SECTION_MERGE
)
6225 if (flags
& SECTION_STRINGS
)
6227 if (flags
& SECTION_TLS
)
6228 *f
++ = TLS_SECTION_ASM_FLAG
;
6229 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6233 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6235 if (!(flags
& SECTION_NOTYPE
))
6240 if (flags
& SECTION_BSS
)
6246 #ifdef ASM_COMMENT_START
6247 /* On platforms that use "@" as the assembly comment character,
6249 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6252 fprintf (asm_out_file
, format
, type
);
6254 if (flags
& SECTION_ENTSIZE
)
6255 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6256 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6258 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6259 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6261 fprintf (asm_out_file
, ",%s,comdat",
6262 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6266 putc ('\n', asm_out_file
);
6270 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6271 tree decl ATTRIBUTE_UNUSED
)
6273 char flagchars
[8], *f
= flagchars
;
6275 if (flags
& SECTION_WRITE
)
6277 if (flags
& SECTION_CODE
)
6281 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6285 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6288 default_coff_asm_named_section (name
, flags
, decl
);
6290 if (flags
& SECTION_LINKONCE
)
6292 /* Functions may have been compiled at various levels of
6293 optimization so we can't use `same_size' here.
6294 Instead, have the linker pick one. */
6295 fprintf (asm_out_file
, "\t.linkonce %s\n",
6296 (flags
& SECTION_CODE
? "discard" : "same_size"));
6300 /* The lame default section selector. */
6303 default_select_section (tree decl
, int reloc
,
6304 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6308 if (decl_readonly_section (decl
, reloc
))
6309 return readonly_data_section
;
6311 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6313 if (! ((flag_pic
&& reloc
)
6314 || !TREE_READONLY (decl
)
6315 || TREE_SIDE_EFFECTS (decl
)
6316 || !TREE_CONSTANT (decl
)))
6317 return readonly_data_section
;
6319 else if (TREE_CODE (decl
) == STRING_CST
)
6320 return readonly_data_section
;
6321 else if (! (flag_pic
&& reloc
))
6322 return readonly_data_section
;
6324 return data_section
;
6327 enum section_category
6328 categorize_decl_for_section (const_tree decl
, int reloc
)
6330 enum section_category ret
;
6332 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6334 else if (TREE_CODE (decl
) == STRING_CST
)
6336 if (flag_mudflap
) /* or !flag_merge_constants */
6337 return SECCAT_RODATA
;
6339 return SECCAT_RODATA_MERGE_STR
;
6341 else if (TREE_CODE (decl
) == VAR_DECL
)
6343 if (bss_initializer_p (decl
))
6345 else if (! TREE_READONLY (decl
)
6346 || TREE_SIDE_EFFECTS (decl
)
6347 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6349 /* Here the reloc_rw_mask is not testing whether the section should
6350 be read-only or not, but whether the dynamic link will have to
6351 do something. If so, we wish to segregate the data in order to
6352 minimize cache misses inside the dynamic linker. */
6353 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6354 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6358 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6359 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6360 else if (reloc
|| flag_merge_constants
< 2)
6361 /* C and C++ don't allow different variables to share the same
6362 location. -fmerge-all-constants allows even that (at the
6363 expense of not conforming). */
6364 ret
= SECCAT_RODATA
;
6365 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6366 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6368 ret
= SECCAT_RODATA_MERGE_CONST
;
6370 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6372 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6373 || TREE_SIDE_EFFECTS (decl
)
6374 || ! TREE_CONSTANT (decl
))
6377 ret
= SECCAT_RODATA
;
6380 ret
= SECCAT_RODATA
;
6382 /* There are no read-only thread-local sections. */
6383 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_TLS_MODEL (decl
))
6385 if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
)
6387 if (DECL_EMUTLS_VAR_P (decl
))
6389 if (targetm
.emutls
.var_section
)
6390 ret
= SECCAT_EMUTLS_VAR
;
6394 if (targetm
.emutls
.tmpl_prefix
)
6395 ret
= SECCAT_EMUTLS_TMPL
;
6398 /* Note that this would be *just* SECCAT_BSS, except that there's
6399 no concept of a read-only thread-local-data section. */
6400 else if (ret
== SECCAT_BSS
6401 || (flag_zero_initialized_in_bss
6402 && initializer_zerop (DECL_INITIAL (decl
))))
6408 /* If the target uses small data sections, select it. */
6409 else if (targetm
.in_small_data_p (decl
))
6411 if (ret
== SECCAT_BSS
)
6413 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6414 ret
= SECCAT_SRODATA
;
6423 decl_readonly_section (const_tree decl
, int reloc
)
6425 switch (categorize_decl_for_section (decl
, reloc
))
6428 case SECCAT_RODATA_MERGE_STR
:
6429 case SECCAT_RODATA_MERGE_STR_INIT
:
6430 case SECCAT_RODATA_MERGE_CONST
:
6431 case SECCAT_SRODATA
:
6440 /* Select a section based on the above categorization. */
6443 default_elf_select_section (tree decl
, int reloc
,
6444 unsigned HOST_WIDE_INT align
)
6447 switch (categorize_decl_for_section (decl
, reloc
))
6450 /* We're not supposed to be called on FUNCTION_DECLs. */
6453 return readonly_data_section
;
6454 case SECCAT_RODATA_MERGE_STR
:
6455 return mergeable_string_section (decl
, align
, 0);
6456 case SECCAT_RODATA_MERGE_STR_INIT
:
6457 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6458 case SECCAT_RODATA_MERGE_CONST
:
6459 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6460 case SECCAT_SRODATA
:
6464 return data_section
;
6465 case SECCAT_DATA_REL
:
6466 sname
= ".data.rel";
6468 case SECCAT_DATA_REL_LOCAL
:
6469 sname
= ".data.rel.local";
6471 case SECCAT_DATA_REL_RO
:
6472 sname
= ".data.rel.ro";
6474 case SECCAT_DATA_REL_RO_LOCAL
:
6475 sname
= ".data.rel.ro.local";
6494 case SECCAT_EMUTLS_VAR
:
6495 sname
= targetm
.emutls
.var_section
;
6497 case SECCAT_EMUTLS_TMPL
:
6498 sname
= targetm
.emutls
.tmpl_section
;
6506 return get_named_section (decl
, sname
, reloc
);
6509 /* Construct a unique section name based on the decl name and the
6510 categorization performed above. */
6513 default_unique_section (tree decl
, int reloc
)
6515 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6516 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6517 const char *prefix
, *name
, *linkonce
;
6520 switch (categorize_decl_for_section (decl
, reloc
))
6523 prefix
= one_only
? ".t" : ".text";
6526 case SECCAT_RODATA_MERGE_STR
:
6527 case SECCAT_RODATA_MERGE_STR_INIT
:
6528 case SECCAT_RODATA_MERGE_CONST
:
6529 prefix
= one_only
? ".r" : ".rodata";
6531 case SECCAT_SRODATA
:
6532 prefix
= one_only
? ".s2" : ".sdata2";
6535 prefix
= one_only
? ".d" : ".data";
6537 case SECCAT_DATA_REL
:
6538 prefix
= one_only
? ".d.rel" : ".data.rel";
6540 case SECCAT_DATA_REL_LOCAL
:
6541 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6543 case SECCAT_DATA_REL_RO
:
6544 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6546 case SECCAT_DATA_REL_RO_LOCAL
:
6547 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6550 prefix
= one_only
? ".s" : ".sdata";
6553 prefix
= one_only
? ".b" : ".bss";
6556 prefix
= one_only
? ".sb" : ".sbss";
6559 prefix
= one_only
? ".td" : ".tdata";
6562 prefix
= one_only
? ".tb" : ".tbss";
6564 case SECCAT_EMUTLS_VAR
:
6565 prefix
= targetm
.emutls
.var_section
;
6567 case SECCAT_EMUTLS_TMPL
:
6568 prefix
= targetm
.emutls
.tmpl_section
;
6574 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6575 name
= targetm
.strip_name_encoding (name
);
6577 /* If we're using one_only, then there needs to be a .gnu.linkonce
6578 prefix to the section name. */
6579 linkonce
= one_only
? ".gnu.linkonce" : "";
6581 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6583 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6586 /* Like compute_reloc_for_constant, except for an RTX. The return value
6587 is a mask for which bit 1 indicates a global relocation, and bit 0
6588 indicates a local relocation. */
6591 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6593 int *preloc
= (int *) data
;
6596 switch (GET_CODE (x
))
6599 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6612 compute_reloc_for_rtx (rtx x
)
6616 switch (GET_CODE (x
))
6622 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6631 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6633 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6635 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6636 return data_section
;
6638 return readonly_data_section
;
6642 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6643 unsigned HOST_WIDE_INT align
)
6645 int reloc
= compute_reloc_for_rtx (x
);
6647 /* ??? Handle small data here somehow. */
6649 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6652 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6654 return get_named_section (NULL
, ".data.rel.ro", 3);
6657 return mergeable_constant_section (mode
, align
, 0);
6660 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6663 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6668 /* Careful not to prod global register variables. */
6671 symbol
= XEXP (rtl
, 0);
6672 if (GET_CODE (symbol
) != SYMBOL_REF
)
6675 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6676 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6677 flags
|= SYMBOL_FLAG_FUNCTION
;
6678 if (targetm
.binds_local_p (decl
))
6679 flags
|= SYMBOL_FLAG_LOCAL
;
6680 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
)
6681 && DECL_TLS_MODEL (decl
) != TLS_MODEL_EMULATED
)
6682 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6683 else if (targetm
.in_small_data_p (decl
))
6684 flags
|= SYMBOL_FLAG_SMALL
;
6685 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6686 being PUBLIC, the thing *must* be defined in this translation unit.
6687 Prevent this buglet from being propagated into rtl code as well. */
6688 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6689 flags
|= SYMBOL_FLAG_EXTERNAL
;
6691 SYMBOL_REF_FLAGS (symbol
) = flags
;
6694 /* By default, we do nothing for encode_section_info, so we need not
6695 do anything but discard the '*' marker. */
6698 default_strip_name_encoding (const char *str
)
6700 return str
+ (*str
== '*');
6703 #ifdef ASM_OUTPUT_DEF
6704 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6705 anchor relative to ".", the current section position. */
6708 default_asm_output_anchor (rtx symbol
)
6712 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6713 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6714 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6718 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6721 default_use_anchors_for_symbol_p (const_rtx symbol
)
6726 /* Don't use anchors for mergeable sections. The linker might move
6727 the objects around. */
6728 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6729 if (sect
->common
.flags
& SECTION_MERGE
)
6732 /* Don't use anchors for small data sections. The small data register
6733 acts as an anchor for such sections. */
6734 if (sect
->common
.flags
& SECTION_SMALL
)
6737 decl
= SYMBOL_REF_DECL (symbol
);
6738 if (decl
&& DECL_P (decl
))
6740 /* Don't use section anchors for decls that might be defined by
6742 if (!targetm
.binds_local_p (decl
))
6745 /* Don't use section anchors for decls that will be placed in a
6746 small data section. */
6747 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6748 one above. The problem is that we only use SECTION_SMALL for
6749 sections that should be marked as small in the section directive. */
6750 if (targetm
.in_small_data_p (decl
))
6756 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6757 wrt cross-module name binding. */
6760 default_binds_local_p (const_tree exp
)
6762 return default_binds_local_p_1 (exp
, flag_shlib
);
6766 default_binds_local_p_1 (const_tree exp
, int shlib
)
6770 /* A non-decl is an entry in the constant pool. */
6773 /* Weakrefs may not bind locally, even though the weakref itself is
6774 always static and therefore local. */
6775 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6777 /* Static variables are always local. */
6778 else if (! TREE_PUBLIC (exp
))
6780 /* A variable is local if the user has said explicitly that it will
6782 else if (DECL_VISIBILITY_SPECIFIED (exp
)
6783 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6785 /* Variables defined outside this object might not be local. */
6786 else if (DECL_EXTERNAL (exp
))
6788 /* If defined in this object and visibility is not default, must be
6790 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6792 /* Default visibility weak data can be overridden by a strong symbol
6793 in another module and so are not local. */
6794 else if (DECL_WEAK (exp
))
6796 /* If PIC, then assume that any global name can be overridden by
6797 symbols resolved from other modules, unless we are compiling with
6798 -fwhole-program, which assumes that names are local. */
6800 local_p
= flag_whole_program
;
6801 /* Uninitialized COMMON variable may be unified with symbols
6802 resolved from other modules. */
6803 else if (DECL_COMMON (exp
)
6804 && (DECL_INITIAL (exp
) == NULL
6805 || DECL_INITIAL (exp
) == error_mark_node
))
6807 /* Otherwise we're left with initialized (or non-common) global data
6808 which is of necessity defined locally. */
6815 /* Default function to output code that will globalize a label. A
6816 target must define GLOBAL_ASM_OP or provide its own function to
6817 globalize a label. */
6818 #ifdef GLOBAL_ASM_OP
6820 default_globalize_label (FILE * stream
, const char *name
)
6822 fputs (GLOBAL_ASM_OP
, stream
);
6823 assemble_name (stream
, name
);
6824 putc ('\n', stream
);
6826 #endif /* GLOBAL_ASM_OP */
6828 /* Default function to output code that will globalize a declaration. */
6830 default_globalize_decl_name (FILE * stream
, tree decl
)
6832 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6833 targetm
.asm_out
.globalize_label (stream
, name
);
6836 /* Default function to output a label for unwind information. The
6837 default is to do nothing. A target that needs nonlocal labels for
6838 unwind information must provide its own function to do this. */
6840 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6841 tree decl ATTRIBUTE_UNUSED
,
6842 int for_eh ATTRIBUTE_UNUSED
,
6843 int empty ATTRIBUTE_UNUSED
)
6847 /* Default function to output a label to divide up the exception table.
6848 The default is to do nothing. A target that needs/wants to divide
6849 up the table must provide it's own function to do this. */
6851 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6855 /* This is how to output an internal numbered label where PREFIX is
6856 the class of label and LABELNO is the number within the class. */
6859 default_internal_label (FILE *stream
, const char *prefix
,
6860 unsigned long labelno
)
6862 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6863 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6864 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6867 /* This is the default behavior at the beginning of a file. It's
6868 controlled by two other target-hook toggles. */
6870 default_file_start (void)
6872 if (targetm
.file_start_app_off
6873 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6874 fputs (ASM_APP_OFF
, asm_out_file
);
6876 if (targetm
.file_start_file_directive
)
6877 output_file_directive (asm_out_file
, main_input_filename
);
6880 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6881 which emits a special section directive used to indicate whether or
6882 not this object file needs an executable stack. This is primarily
6883 a GNU extension to ELF but could be used on other targets. */
6885 int trampolines_created
;
6888 file_end_indicate_exec_stack (void)
6890 unsigned int flags
= SECTION_DEBUG
;
6891 if (trampolines_created
)
6892 flags
|= SECTION_CODE
;
6894 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6897 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6898 a get_unnamed_section callback. */
6901 output_section_asm_op (const void *directive
)
6903 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6906 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6907 the current section is NEW_SECTION. */
6910 switch_to_section (section
*new_section
)
6912 if (in_section
== new_section
)
6915 if (new_section
->common
.flags
& SECTION_FORGET
)
6918 in_section
= new_section
;
6920 switch (SECTION_STYLE (new_section
))
6924 && !crtl
->subsections
.unlikely_text_section_name
6925 && strcmp (new_section
->named
.name
,
6926 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6927 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6929 targetm
.asm_out
.named_section (new_section
->named
.name
,
6930 new_section
->named
.common
.flags
,
6931 new_section
->named
.decl
);
6934 case SECTION_UNNAMED
:
6935 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6938 case SECTION_NOSWITCH
:
6943 new_section
->common
.flags
|= SECTION_DECLARED
;
6946 /* If block symbol SYMBOL has not yet been assigned an offset, place
6947 it at the end of its block. */
6950 place_block_symbol (rtx symbol
)
6952 unsigned HOST_WIDE_INT size
, mask
, offset
;
6953 struct constant_descriptor_rtx
*desc
;
6954 unsigned int alignment
;
6955 struct object_block
*block
;
6958 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6959 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6962 /* Work out the symbol's size and alignment. */
6963 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6965 desc
= SYMBOL_REF_CONSTANT (symbol
);
6966 alignment
= desc
->align
;
6967 size
= GET_MODE_SIZE (desc
->mode
);
6969 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
6971 decl
= SYMBOL_REF_DECL (symbol
);
6972 alignment
= DECL_ALIGN (decl
);
6973 size
= get_constant_size (DECL_INITIAL (decl
));
6977 decl
= SYMBOL_REF_DECL (symbol
);
6978 alignment
= DECL_ALIGN (decl
);
6979 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
6982 /* Calculate the object's offset from the start of the block. */
6983 block
= SYMBOL_REF_BLOCK (symbol
);
6984 mask
= alignment
/ BITS_PER_UNIT
- 1;
6985 offset
= (block
->size
+ mask
) & ~mask
;
6986 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
6988 /* Record the block's new alignment and size. */
6989 block
->alignment
= MAX (block
->alignment
, alignment
);
6990 block
->size
= offset
+ size
;
6992 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
6995 /* Return the anchor that should be used to address byte offset OFFSET
6996 from the first object in BLOCK. MODEL is the TLS model used
7000 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7001 enum tls_model model
)
7004 unsigned int begin
, middle
, end
;
7005 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7008 /* Work out the anchor's offset. Use an offset of 0 for the first
7009 anchor so that we don't pessimize the case where we take the address
7010 of a variable at the beginning of the block. This is particularly
7011 useful when a block has only one variable assigned to it.
7013 We try to place anchors RANGE bytes apart, so there can then be
7014 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7015 a ptr_mode offset. With some target settings, the lowest such
7016 anchor might be out of range for the lowest ptr_mode offset;
7017 likewise the highest anchor for the highest offset. Use anchors
7018 at the extreme ends of the ptr_mode range in such cases.
7020 All arithmetic uses unsigned integers in order to avoid
7022 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7023 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7024 range
= max_offset
- min_offset
+ 1;
7029 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7032 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7033 delta
-= delta
% range
;
7036 offset
= (HOST_WIDE_INT
) (-delta
);
7040 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7041 delta
-= delta
% range
;
7042 if (delta
> bias
- 1)
7044 offset
= (HOST_WIDE_INT
) delta
;
7048 /* Do a binary search to see if there's already an anchor we can use.
7049 Set BEGIN to the new anchor's index if not. */
7051 end
= VEC_length (rtx
, block
->anchors
);
7052 while (begin
!= end
)
7054 middle
= (end
+ begin
) / 2;
7055 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
7056 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7058 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7060 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7062 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7068 /* Create a new anchor with a unique label. */
7069 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7070 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7071 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7072 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7074 /* Insert it at index BEGIN. */
7075 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
7079 /* Output the objects in BLOCK. */
7082 output_object_block (struct object_block
*block
)
7084 struct constant_descriptor_rtx
*desc
;
7086 HOST_WIDE_INT offset
;
7090 if (block
->objects
== NULL
)
7093 /* Switch to the section and make sure that the first byte is
7094 suitably aligned. */
7095 switch_to_section (block
->sect
);
7096 assemble_align (block
->alignment
);
7098 /* Define the values of all anchors relative to the current section
7100 for (i
= 0; VEC_iterate (rtx
, block
->anchors
, i
, symbol
); i
++)
7101 targetm
.asm_out
.output_anchor (symbol
);
7103 /* Output the objects themselves. */
7105 for (i
= 0; VEC_iterate (rtx
, block
->objects
, i
, symbol
); i
++)
7107 /* Move to the object's offset, padding with zeros if necessary. */
7108 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7109 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7110 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7112 desc
= SYMBOL_REF_CONSTANT (symbol
);
7113 output_constant_pool_1 (desc
, 1);
7114 offset
+= GET_MODE_SIZE (desc
->mode
);
7116 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7118 decl
= SYMBOL_REF_DECL (symbol
);
7119 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7121 offset
+= get_constant_size (DECL_INITIAL (decl
));
7125 decl
= SYMBOL_REF_DECL (symbol
);
7126 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7127 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7132 /* A htab_traverse callback used to call output_object_block for
7133 each member of object_block_htab. */
7136 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7138 output_object_block ((struct object_block
*) (*slot
));
7142 /* Output the definitions of all object_blocks. */
7145 output_object_blocks (void)
7147 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7150 /* This function provides a possible implementation of the
7151 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7152 by -frecord-gcc-switches it creates a new mergeable, string section in the
7153 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7154 contains the switches in ASCII format.
7156 FIXME: This code does not correctly handle double quote characters
7157 that appear inside strings, (it strips them rather than preserving them).
7158 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7159 characters - instead it treats them as sub-string separators. Since
7160 we want to emit NUL strings terminators into the object file we have to use
7164 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7166 static char buffer
[1024];
7168 /* This variable is used as part of a simplistic heuristic to detect
7169 command line switches which take an argument:
7171 "If a command line option does not start with a dash then
7172 it is an argument for the previous command line option."
7174 This fails in the case of the command line option which is the name
7175 of the file to compile, but otherwise it is pretty reasonable. */
7176 static bool previous_name_held_back
= FALSE
;
7180 case SWITCH_TYPE_PASSED
:
7183 if (previous_name_held_back
)
7185 unsigned int len
= strlen (buffer
);
7187 snprintf (buffer
+ len
, sizeof buffer
- len
, " %s", name
);
7188 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7189 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7190 previous_name_held_back
= FALSE
;
7194 strncpy (buffer
, name
, sizeof buffer
);
7195 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7196 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7201 if (previous_name_held_back
)
7203 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7204 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7207 strncpy (buffer
, name
, sizeof buffer
);
7208 previous_name_held_back
= TRUE
;
7212 case SWITCH_TYPE_DESCRIPTIVE
:
7215 /* Distinguish between invocations where name is NULL. */
7216 static bool started
= false;
7220 if (previous_name_held_back
)
7222 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7223 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7230 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7234 | (SECTION_ENTSIZE
& 1),
7236 switch_to_section (sec
);
7245 /* The return value is currently ignored by the caller, but must be 0.
7246 For -fverbose-asm the return value would be the number of characters
7247 emitted into the assembler file. */
7251 /* Emit text to declare externally defined symbols. It is needed to
7252 properly support non-default visibility. */
7254 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7256 const char *name ATTRIBUTE_UNUSED
)
7258 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7259 set in order to avoid putting out names that are never really
7261 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7262 && targetm
.binds_local_p (decl
))
7263 maybe_assemble_visibility (decl
);
7266 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7269 make_debug_expr_from_rtl (const_rtx exp
)
7271 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7272 enum machine_mode mode
= GET_MODE (exp
);
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
));
7282 if (type
&& TYPE_MODE (type
) == mode
)
7283 TREE_TYPE (ddecl
) = type
;
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
);
7293 #include "gt-varasm.h"