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 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"
47 #include "langhooks.h"
51 #include "targhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
56 #include "tree-iterator.h"
58 #ifdef XCOFF_DEBUGGING_INFO
59 #include "xcoffout.h" /* Needed for external data
60 declarations for e.g. AIX 4.x. */
63 /* The (assembler) name of the first globally-visible object output. */
64 extern GTY(()) const char *first_global_object_name;
65 extern GTY(()) const char *weak_global_object_name;
67 const char *first_global_object_name;
68 const char *weak_global_object_name;
71 struct constant_descriptor_rtx;
72 struct rtx_constant_pool;
74 #define n_deferred_constants (crtl->varasm.deferred_constants)
76 /* Number for making the label on the next
77 constant that is stored in memory. */
79 static GTY(()) int const_labelno;
81 /* Carry information from ASM_DECLARE_OBJECT_NAME
82 to ASM_FINISH_DECLARE_OBJECT. */
84 int size_directive_output;
86 /* The last decl for which assemble_variable was called,
87 if it did ASM_DECLARE_OBJECT_NAME.
88 If the last call to assemble_variable didn't do that,
91 tree last_assemble_variable_decl;
93 /* The following global variable indicates if the first basic block
94 in a function belongs to the cold partition or not. */
96 bool first_function_block_is_cold;
98 /* We give all constants their own alias set. Perhaps redundant with
99 MEM_READONLY_P, but pre-dates it. */
101 static alias_set_type const_alias_set;
103 static const char *strip_reg_name (const char *);
104 static int contains_pointers_p (tree);
105 #ifdef ASM_OUTPUT_EXTERNAL
106 static bool incorporeal_function_p (tree);
108 static void decode_addr_const (tree, struct addr_const *);
109 static hashval_t const_desc_hash (const void *);
110 static int const_desc_eq (const void *, const void *);
111 static hashval_t const_hash_1 (const tree);
112 static int compare_constant (const tree, const tree);
113 static tree copy_constant (tree);
114 static void output_constant_def_contents (rtx);
115 static void output_addressed_constants (tree);
116 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
117 static unsigned min_align (unsigned, unsigned);
118 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
119 static void globalize_decl (tree);
120 #ifdef BSS_SECTION_ASM_OP
121 #ifdef ASM_OUTPUT_BSS
122 static void asm_output_bss (FILE *, tree, const char *,
123 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
125 #ifdef ASM_OUTPUT_ALIGNED_BSS
126 static void asm_output_aligned_bss (FILE *, tree, const char *,
127 unsigned HOST_WIDE_INT, int)
130 #endif /* BSS_SECTION_ASM_OP */
131 static void mark_weak (tree);
132 static void output_constant_pool (const char *, tree);
134 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
135 section *text_section;
136 section *data_section;
137 section *readonly_data_section;
138 section *sdata_section;
139 section *ctors_section;
140 section *dtors_section;
141 section *bss_section;
142 section *sbss_section;
144 /* Various forms of common section. All are guaranteed to be nonnull. */
145 section *tls_comm_section;
146 section *comm_section;
147 section *lcomm_section;
149 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
151 section *bss_noswitch_section;
153 /* The section that holds the main exception table, when known. The section
154 is set either by the target's init_sections hook or by the first call to
155 switch_to_exception_section. */
156 section *exception_section;
158 /* The section that holds the DWARF2 frame unwind information, when known.
159 The section is set either by the target's init_sections hook or by the
160 first call to switch_to_eh_frame_section. */
161 section *eh_frame_section;
163 /* asm_out_file's current section. This is NULL if no section has yet
164 been selected or if we lose track of what the current section is. */
167 /* True if code for the current function is currently being directed
168 at the cold section. */
169 bool in_cold_section_p;
171 /* A linked list of all the unnamed sections. */
172 static GTY(()) section *unnamed_sections;
174 /* Return a nonzero value if DECL has a section attribute. */
175 #ifndef IN_NAMED_SECTION
176 #define IN_NAMED_SECTION(DECL) \
177 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
178 && DECL_SECTION_NAME (DECL) != NULL_TREE)
181 /* Hash table of named sections. */
182 static GTY((param_is (section))) htab_t section_htab;
184 /* A table of object_blocks, indexed by section. */
185 static GTY((param_is (struct object_block))) htab_t object_block_htab;
187 /* The next number to use for internal anchor labels. */
188 static GTY(()) int anchor_labelno;
190 /* A pool of constants that can be shared between functions. */
191 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
195 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
197 static GTY (()) tree emutls_object_type;
198 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
199 macro can be used on them to distinguish the control variable from
200 the initialization template. */
201 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
203 #if !defined (NO_DOT_IN_LABEL)
204 # define EMUTLS_SEPARATOR "."
205 #elif !defined (NO_DOLLAR_IN_LABEL)
206 # define EMUTLS_SEPARATOR "$"
208 # define EMUTLS_SEPARATOR "_"
211 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
212 IDENTIFIER_NODE NAME's name. */
215 prefix_name (const char *prefix, tree name)
217 unsigned plen = strlen (prefix);
218 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
219 char *toname = (char *) alloca (plen + nlen + 1);
221 memcpy (toname, prefix, plen);
222 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
224 return get_identifier (toname);
227 /* Create an identifier for the struct __emutls_object, given an identifier
228 of the DECL_ASSEMBLY_NAME of the original object. */
231 get_emutls_object_name (tree name)
233 const char *prefix = (targetm.emutls.var_prefix
234 ? targetm.emutls.var_prefix
235 : "__emutls_v" EMUTLS_SEPARATOR);
236 return prefix_name (prefix, name);
240 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
242 tree word_type_node, field, next_field;
244 field = build_decl (FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
245 DECL_CONTEXT (field) = type;
248 field = build_decl (FIELD_DECL, get_identifier ("__offset"),
250 DECL_CONTEXT (field) = type;
251 TREE_CHAIN (field) = next_field;
254 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
255 field = build_decl (FIELD_DECL, get_identifier ("__align"),
257 DECL_CONTEXT (field) = type;
258 TREE_CHAIN (field) = next_field;
261 field = build_decl (FIELD_DECL, get_identifier ("__size"), word_type_node);
262 DECL_CONTEXT (field) = type;
263 TREE_CHAIN (field) = next_field;
268 /* Create the structure for struct __emutls_object. This should match the
269 structure at the top of emutls.c, modulo the union there. */
272 get_emutls_object_type (void)
274 tree type, type_name, field;
276 type = emutls_object_type;
280 emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE);
282 field = targetm.emutls.var_fields (type, &type_name);
284 type_name = get_identifier ("__emutls_object");
285 type_name = build_decl (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 (VAR_DECL, name, TREE_TYPE (decl));
315 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
316 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
317 DECL_ARTIFICIAL (to) = 1;
318 TREE_USED (to) = TREE_USED (decl);
319 TREE_READONLY (to) = 1;
320 DECL_IGNORED_P (to) = 1;
321 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
322 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
324 DECL_WEAK (to) = DECL_WEAK (decl);
325 if (DECL_ONE_ONLY (decl))
327 make_decl_one_only (to);
328 TREE_STATIC (to) = TREE_STATIC (decl);
329 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
330 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
333 TREE_STATIC (to) = 1;
335 DECL_INITIAL (to) = DECL_INITIAL (decl);
336 DECL_INITIAL (decl) = NULL;
338 varpool_finalize_decl (to);
339 return build_fold_addr_expr (to);
342 /* When emulating tls, we use a control structure for use by the runtime.
343 Create and return this structure. */
346 emutls_decl (tree decl)
349 struct tree_map *h, in;
352 if (targetm.have_tls || decl == NULL || decl == error_mark_node
353 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
356 /* Look up the object in the hash; return the control structure if
357 it has already been created. */
359 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
361 name = DECL_ASSEMBLER_NAME (decl);
363 /* Note that we use the hash of the decl's name, rather than a hash
364 of the decl's pointer. In emutls_finish we iterate through the
365 hash table, and we want this traversal to be predictable. */
366 in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
368 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
369 h = (struct tree_map *) *loc;
374 to = build_decl (VAR_DECL, get_emutls_object_name (name),
375 get_emutls_object_type ());
377 h = GGC_NEW (struct tree_map);
381 *(struct tree_map **) loc = h;
383 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
384 DECL_ARTIFICIAL (to) = 1;
385 DECL_IGNORED_P (to) = 1;
386 TREE_READONLY (to) = 0;
387 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
388 if (DECL_ONE_ONLY (decl))
389 make_decl_one_only (to);
390 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
391 if (targetm.emutls.var_align_fixed)
392 /* If we're not allowed to change the proxy object's
393 alignment, pretend it's been set by the user. */
394 DECL_USER_ALIGN (to) = 1;
397 /* Note that these fields may need to be updated from time to time from
398 the original decl. Consider:
399 extern __thread int i;
400 int foo() { return i; }
402 in which I goes from external to locally defined and initialized. */
404 TREE_STATIC (to) = TREE_STATIC (decl);
405 TREE_USED (to) = TREE_USED (decl);
406 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
407 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
408 DECL_COMMON (to) = DECL_COMMON (decl);
409 DECL_WEAK (to) = DECL_WEAK (decl);
410 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
416 emutls_common_1 (void **loc, void *xstmts)
418 struct tree_map *h = *(struct tree_map **) loc;
419 tree args, x, *pstmts = (tree *) xstmts;
422 if (! DECL_COMMON (h->base.from)
423 || (DECL_INITIAL (h->base.from)
424 && DECL_INITIAL (h->base.from) != error_mark_node))
427 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
429 /* The idea was to call get_emutls_init_templ_addr here, but if we
430 do this and there is an initializer, -fanchor_section loses,
431 because it would be too late to ensure the template is
433 x = null_pointer_node;
434 args = tree_cons (NULL, x, NULL);
435 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
436 args = tree_cons (NULL, x, args);
437 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
438 args = tree_cons (NULL, x, args);
439 x = build_fold_addr_expr (h->to);
440 args = tree_cons (NULL, x, args);
442 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
443 x = build_function_call_expr (x, args);
445 append_to_statement_list (x, pstmts);
452 if (targetm.emutls.register_common)
454 tree body = NULL_TREE;
456 if (emutls_htab == NULL)
459 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
460 if (body == NULL_TREE)
463 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
467 /* Helper routines for maintaining section_htab. */
470 section_entry_eq (const void *p1, const void *p2)
472 const section *old = (const section *) p1;
473 const char *new_name = (const char *) p2;
475 return strcmp (old->named.name, new_name) == 0;
479 section_entry_hash (const void *p)
481 const section *old = (const section *) p;
482 return htab_hash_string (old->named.name);
485 /* Return a hash value for section SECT. */
488 hash_section (section *sect)
490 if (sect->common.flags & SECTION_NAMED)
491 return htab_hash_string (sect->named.name);
492 return sect->common.flags;
495 /* Helper routines for maintaining object_block_htab. */
498 object_block_entry_eq (const void *p1, const void *p2)
500 const struct object_block *old = (const struct object_block *) p1;
501 const section *new_section = (const section *) p2;
503 return old->sect == new_section;
507 object_block_entry_hash (const void *p)
509 const struct object_block *old = (const struct object_block *) p;
510 return hash_section (old->sect);
513 /* Return a new unnamed section with the given fields. */
516 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
521 sect = GGC_NEW (section);
522 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
523 sect->unnamed.callback = callback;
524 sect->unnamed.data = data;
525 sect->unnamed.next = unnamed_sections;
527 unnamed_sections = sect;
531 /* Return a SECTION_NOSWITCH section with the given fields. */
534 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
538 sect = GGC_NEW (section);
539 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
540 sect->noswitch.callback = callback;
545 /* Return the named section structure associated with NAME. Create
546 a new section with the given fields if no such structure exists. */
549 get_section (const char *name, unsigned int flags, tree decl)
551 section *sect, **slot;
554 htab_find_slot_with_hash (section_htab, name,
555 htab_hash_string (name), INSERT);
556 flags |= SECTION_NAMED;
559 sect = GGC_NEW (section);
560 sect->named.common.flags = flags;
561 sect->named.name = ggc_strdup (name);
562 sect->named.decl = decl;
568 if ((sect->common.flags & ~SECTION_DECLARED) != flags
569 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
571 /* Sanity check user variables for flag changes. */
573 decl = sect->named.decl;
575 error ("%+D causes a section type conflict", decl);
581 /* Return true if the current compilation mode benefits from having
582 objects grouped into blocks. */
585 use_object_blocks_p (void)
587 return flag_section_anchors;
590 /* Return the object_block structure for section SECT. Create a new
591 structure if we haven't created one already. Return null if SECT
594 static struct object_block *
595 get_block_for_section (section *sect)
597 struct object_block *block;
603 slot = htab_find_slot_with_hash (object_block_htab, sect,
604 hash_section (sect), INSERT);
605 block = (struct object_block *) *slot;
608 block = (struct object_block *)
609 ggc_alloc_cleared (sizeof (struct object_block));
616 /* Create a symbol with label LABEL and place it at byte offset
617 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
618 is not yet known. LABEL must be a garbage-collected string. */
621 create_block_symbol (const char *label, struct object_block *block,
622 HOST_WIDE_INT offset)
627 /* Create the extended SYMBOL_REF. */
628 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
629 symbol = (rtx) ggc_alloc_zone (size, &rtl_zone);
631 /* Initialize the normal SYMBOL_REF fields. */
632 memset (symbol, 0, size);
633 PUT_CODE (symbol, SYMBOL_REF);
634 PUT_MODE (symbol, Pmode);
635 XSTR (symbol, 0) = label;
636 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
638 /* Initialize the block_symbol stuff. */
639 SYMBOL_REF_BLOCK (symbol) = block;
640 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
646 initialize_cold_section_name (void)
648 const char *stripped_name;
652 gcc_assert (cfun && current_function_decl);
653 if (crtl->subsections.unlikely_text_section_name)
656 dsn = DECL_SECTION_NAME (current_function_decl);
657 if (flag_function_sections && dsn)
659 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
660 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
662 stripped_name = targetm.strip_name_encoding (name);
664 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
665 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
668 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
671 /* Tell assembler to switch to unlikely-to-be-executed text section. */
674 unlikely_text_section (void)
678 if (!crtl->subsections.unlikely_text_section_name)
679 initialize_cold_section_name ();
681 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
684 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
687 /* When called within a function context, return true if the function
688 has been assigned a cold text section and if SECT is that section.
689 When called outside a function context, return true if SECT is the
690 default cold section. */
693 unlikely_text_section_p (section *sect)
698 name = crtl->subsections.unlikely_text_section_name;
700 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
704 && SECTION_STYLE (sect) == SECTION_NAMED
705 && strcmp (name, sect->named.name) == 0);
708 /* Return a section with a particular name and with whatever SECTION_*
709 flags section_type_flags deems appropriate. The name of the section
710 is taken from NAME if nonnull, otherwise it is taken from DECL's
711 DECL_SECTION_NAME. DECL is the decl associated with the section
712 (see the section comment for details) and RELOC is as for
713 section_type_flags. */
716 get_named_section (tree decl, const char *name, int reloc)
720 gcc_assert (!decl || DECL_P (decl));
722 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
724 flags = targetm.section_type_flags (decl, name, reloc);
726 return get_section (name, flags, decl);
729 /* If required, set DECL_SECTION_NAME to a unique name. */
732 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
733 int flag_function_or_data_sections)
735 if (DECL_SECTION_NAME (decl) == NULL_TREE
736 && targetm.have_named_sections
737 && (flag_function_or_data_sections
738 || DECL_ONE_ONLY (decl)))
739 targetm.asm_out.unique_section (decl, reloc);
742 #ifdef BSS_SECTION_ASM_OP
744 #ifdef ASM_OUTPUT_BSS
746 /* Utility function for ASM_OUTPUT_BSS for targets to use if
747 they don't support alignments in .bss.
748 ??? It is believed that this function will work in most cases so such
749 support is localized here. */
752 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
754 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
755 unsigned HOST_WIDE_INT rounded)
757 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
758 targetm.asm_out.globalize_decl_name (file, decl);
759 switch_to_section (bss_section);
760 #ifdef ASM_DECLARE_OBJECT_NAME
761 last_assemble_variable_decl = decl;
762 ASM_DECLARE_OBJECT_NAME (file, name, decl);
764 /* Standard thing is just output label for the object. */
765 ASM_OUTPUT_LABEL (file, name);
766 #endif /* ASM_DECLARE_OBJECT_NAME */
767 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
772 #ifdef ASM_OUTPUT_ALIGNED_BSS
774 /* Utility function for targets to use in implementing
775 ASM_OUTPUT_ALIGNED_BSS.
776 ??? It is believed that this function will work in most cases so such
777 support is localized here. */
780 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
781 const char *name, unsigned HOST_WIDE_INT size,
784 switch_to_section (bss_section);
785 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
786 #ifdef ASM_DECLARE_OBJECT_NAME
787 last_assemble_variable_decl = decl;
788 ASM_DECLARE_OBJECT_NAME (file, name, decl);
790 /* Standard thing is just output label for the object. */
791 ASM_OUTPUT_LABEL (file, name);
792 #endif /* ASM_DECLARE_OBJECT_NAME */
793 ASM_OUTPUT_SKIP (file, size ? size : 1);
798 #endif /* BSS_SECTION_ASM_OP */
800 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
801 /* Return the hot section for function DECL. Return text_section for
805 hot_function_section (tree decl)
807 if (decl != NULL_TREE
808 && DECL_SECTION_NAME (decl) != NULL_TREE
809 && targetm.have_named_sections)
810 return get_named_section (decl, NULL, 0);
816 /* Return the section for function DECL.
818 If DECL is NULL_TREE, return the text section. We can be passed
819 NULL_TREE under some circumstances by dbxout.c at least. */
822 function_section (tree decl)
826 if (first_function_block_is_cold)
829 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
830 if (decl != NULL_TREE
831 && DECL_SECTION_NAME (decl) != NULL_TREE)
832 return reloc ? unlikely_text_section ()
833 : get_named_section (decl, NULL, 0);
835 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
837 return reloc ? unlikely_text_section () : hot_function_section (decl);
842 current_function_section (void)
844 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
845 if (current_function_decl != NULL_TREE
846 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
847 return in_cold_section_p ? unlikely_text_section ()
848 : get_named_section (current_function_decl,
851 return targetm.asm_out.select_section (current_function_decl,
853 DECL_ALIGN (current_function_decl));
855 return (in_cold_section_p
856 ? unlikely_text_section ()
857 : hot_function_section (current_function_decl));
861 /* Return the read-only data section associated with function DECL. */
864 default_function_rodata_section (tree decl)
866 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
868 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
870 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
876 dot = strchr (name + 1, '.');
879 len = strlen (dot) + 8;
880 rname = (char *) alloca (len);
882 strcpy (rname, ".rodata");
884 return get_section (rname, SECTION_LINKONCE, decl);
886 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
887 else if (DECL_ONE_ONLY (decl)
888 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
890 size_t len = strlen (name) + 1;
891 char *rname = (char *) alloca (len);
893 memcpy (rname, name, len);
895 return get_section (rname, SECTION_LINKONCE, decl);
897 /* For .text.foo we want to use .rodata.foo. */
898 else if (flag_function_sections && flag_data_sections
899 && strncmp (name, ".text.", 6) == 0)
901 size_t len = strlen (name) + 1;
902 char *rname = (char *) alloca (len + 2);
904 memcpy (rname, ".rodata", 7);
905 memcpy (rname + 7, name + 5, len - 5);
906 return get_section (rname, 0, decl);
910 return readonly_data_section;
913 /* Return the read-only data section associated with function DECL
914 for targets where that section should be always the single
915 readonly data section. */
918 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
920 return readonly_data_section;
923 /* Return the section to use for string merging. */
926 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
927 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
928 unsigned int flags ATTRIBUTE_UNUSED)
932 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
933 && TREE_CODE (decl) == STRING_CST
934 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
936 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
937 && TREE_STRING_LENGTH (decl) >= len)
939 enum machine_mode mode;
940 unsigned int modesize;
946 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
947 modesize = GET_MODE_BITSIZE (mode);
948 if (modesize >= 8 && modesize <= 256
949 && (modesize & (modesize - 1)) == 0)
951 if (align < modesize)
954 str = TREE_STRING_POINTER (decl);
955 unit = GET_MODE_SIZE (mode);
957 /* Check for embedded NUL characters. */
958 for (i = 0; i < len; i += unit)
960 for (j = 0; j < unit; j++)
961 if (str[i + j] != '\0')
968 sprintf (name, ".rodata.str%d.%d", modesize / 8,
970 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
971 return get_section (name, flags, NULL);
976 return readonly_data_section;
979 /* Return the section to use for constant merging. */
982 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
983 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
984 unsigned int flags ATTRIBUTE_UNUSED)
986 unsigned int modesize = GET_MODE_BITSIZE (mode);
988 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
994 && (align & (align - 1)) == 0)
998 sprintf (name, ".rodata.cst%d", (int) (align / 8));
999 flags |= (align / 8) | SECTION_MERGE;
1000 return get_section (name, flags, NULL);
1002 return readonly_data_section;
1005 /* Given NAME, a putative register name, discard any customary prefixes. */
1008 strip_reg_name (const char *name)
1010 #ifdef REGISTER_PREFIX
1011 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1012 name += strlen (REGISTER_PREFIX);
1014 if (name[0] == '%' || name[0] == '#')
1019 /* The user has asked for a DECL to have a particular name. Set (or
1020 change) it in such a way that we don't prefix an underscore to
1023 set_user_assembler_name (tree decl, const char *name)
1025 char *starred = (char *) alloca (strlen (name) + 2);
1027 strcpy (starred + 1, name);
1028 change_decl_assembler_name (decl, get_identifier (starred));
1029 SET_DECL_RTL (decl, NULL_RTX);
1032 /* Decode an `asm' spec for a declaration as a register name.
1033 Return the register number, or -1 if nothing specified,
1034 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1035 or -3 if ASMSPEC is `cc' and is not recognized,
1036 or -4 if ASMSPEC is `memory' and is not recognized.
1037 Accept an exact spelling or a decimal number.
1038 Prefixes such as % are optional. */
1041 decode_reg_name (const char *asmspec)
1047 /* Get rid of confusing prefixes. */
1048 asmspec = strip_reg_name (asmspec);
1050 /* Allow a decimal number as a "register name". */
1051 for (i = strlen (asmspec) - 1; i >= 0; i--)
1052 if (! ISDIGIT (asmspec[i]))
1054 if (asmspec[0] != 0 && i < 0)
1057 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1063 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1065 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1068 #ifdef ADDITIONAL_REGISTER_NAMES
1070 static const struct { const char *const name; const int number; } table[]
1071 = ADDITIONAL_REGISTER_NAMES;
1073 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1074 if (table[i].name[0]
1075 && ! strcmp (asmspec, table[i].name))
1076 return table[i].number;
1078 #endif /* ADDITIONAL_REGISTER_NAMES */
1080 if (!strcmp (asmspec, "memory"))
1083 if (!strcmp (asmspec, "cc"))
1092 /* Return true if DECL's initializer is suitable for a BSS section. */
1095 bss_initializer_p (const_tree decl)
1097 return (DECL_INITIAL (decl) == NULL
1098 || DECL_INITIAL (decl) == error_mark_node
1099 || (flag_zero_initialized_in_bss
1100 /* Leave constant zeroes in .rodata so they
1102 && !TREE_READONLY (decl)
1103 && initializer_zerop (DECL_INITIAL (decl))));
1106 /* Compute the alignment of variable specified by DECL.
1107 DONT_OUTPUT_DATA is from assemble_variable. */
1110 align_variable (tree decl, bool dont_output_data)
1112 unsigned int align = DECL_ALIGN (decl);
1114 /* In the case for initialing an array whose length isn't specified,
1115 where we have not yet been able to do the layout,
1116 figure out the proper alignment now. */
1117 if (dont_output_data && DECL_SIZE (decl) == 0
1118 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1119 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1121 /* Some object file formats have a maximum alignment which they support.
1122 In particular, a.out format supports a maximum alignment of 4. */
1123 if (align > MAX_OFILE_ALIGNMENT)
1125 warning (0, "alignment of %q+D is greater than maximum object "
1126 "file alignment. Using %d", decl,
1127 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1128 align = MAX_OFILE_ALIGNMENT;
1131 /* On some machines, it is good to increase alignment sometimes. */
1132 if (! DECL_USER_ALIGN (decl))
1134 #ifdef DATA_ALIGNMENT
1135 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1136 /* Don't increase alignment too much for TLS variables - TLS space
1138 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1141 #ifdef CONSTANT_ALIGNMENT
1142 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1144 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1146 /* Don't increase alignment too much for TLS variables - TLS space
1148 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1149 align = const_align;
1154 /* Reset the alignment in case we have made it tighter, so we can benefit
1155 from it in get_pointer_alignment. */
1156 DECL_ALIGN (decl) = align;
1159 /* Return the section into which the given VAR_DECL or CONST_DECL
1160 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1161 section should be used wherever possible. */
1164 get_variable_section (tree decl, bool prefer_noswitch_p)
1168 /* If the decl has been given an explicit section name, then it
1169 isn't common, and shouldn't be handled as such. */
1170 if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL)
1172 if (DECL_THREAD_LOCAL_P (decl))
1173 return tls_comm_section;
1174 /* This cannot be common bss for an emulated TLS object without
1175 a register_common hook. */
1176 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1177 && !targetm.emutls.register_common)
1179 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1180 return comm_section;
1183 if (DECL_INITIAL (decl) == error_mark_node)
1184 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1185 else if (DECL_INITIAL (decl))
1186 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1190 resolve_unique_section (decl, reloc, flag_data_sections);
1191 if (IN_NAMED_SECTION (decl))
1192 return get_named_section (decl, NULL, reloc);
1194 if (!DECL_THREAD_LOCAL_P (decl)
1195 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1196 && bss_initializer_p (decl))
1198 if (!TREE_PUBLIC (decl))
1199 return lcomm_section;
1200 if (bss_noswitch_section)
1201 return bss_noswitch_section;
1204 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1207 /* Return the block into which object_block DECL should be placed. */
1209 static struct object_block *
1210 get_block_for_decl (tree decl)
1214 if (TREE_CODE (decl) == VAR_DECL)
1216 /* The object must be defined in this translation unit. */
1217 if (DECL_EXTERNAL (decl))
1220 /* There's no point using object blocks for something that is
1221 isolated by definition. */
1222 if (DECL_ONE_ONLY (decl))
1226 /* We can only calculate block offsets if the decl has a known
1228 if (DECL_SIZE_UNIT (decl) == NULL)
1230 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1233 /* Find out which section should contain DECL. We cannot put it into
1234 an object block if it requires a standalone definition. */
1235 if (TREE_CODE (decl) == VAR_DECL)
1236 align_variable (decl, 0);
1237 sect = get_variable_section (decl, true);
1238 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1241 return get_block_for_section (sect);
1244 /* Make sure block symbol SYMBOL is in block BLOCK. */
1247 change_symbol_block (rtx symbol, struct object_block *block)
1249 if (block != SYMBOL_REF_BLOCK (symbol))
1251 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1252 SYMBOL_REF_BLOCK (symbol) = block;
1256 /* Return true if it is possible to put DECL in an object_block. */
1259 use_blocks_for_decl_p (tree decl)
1261 /* Only data DECLs can be placed into object blocks. */
1262 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1265 /* Detect decls created by dw2_force_const_mem. Such decls are
1266 special because DECL_INITIAL doesn't specify the decl's true value.
1267 dw2_output_indirect_constants will instead call assemble_variable
1268 with dont_output_data set to 1 and then print the contents itself. */
1269 if (DECL_INITIAL (decl) == decl)
1272 /* If this decl is an alias, then we don't want to emit a definition. */
1273 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1279 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1280 have static storage duration. In other words, it should not be an
1281 automatic variable, including PARM_DECLs.
1283 There is, however, one exception: this function handles variables
1284 explicitly placed in a particular register by the user.
1286 This is never called for PARM_DECL nodes. */
1289 make_decl_rtl (tree decl)
1291 const char *name = 0;
1295 /* Check that we are not being given an automatic variable. */
1296 gcc_assert (TREE_CODE (decl) != PARM_DECL
1297 && TREE_CODE (decl) != RESULT_DECL);
1299 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1300 gcc_assert (TREE_CODE (decl) != VAR_DECL
1301 || TREE_STATIC (decl)
1302 || TREE_PUBLIC (decl)
1303 || DECL_EXTERNAL (decl)
1304 || DECL_REGISTER (decl));
1306 /* And that we were not given a type or a label. */
1307 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1308 && TREE_CODE (decl) != LABEL_DECL);
1310 /* For a duplicate declaration, we can be called twice on the
1311 same DECL node. Don't discard the RTL already made. */
1312 if (DECL_RTL_SET_P (decl))
1314 /* If the old RTL had the wrong mode, fix the mode. */
1315 x = DECL_RTL (decl);
1316 if (GET_MODE (x) != DECL_MODE (decl))
1317 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1319 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1322 /* ??? Another way to do this would be to maintain a hashed
1323 table of such critters. Instead of adding stuff to a DECL
1324 to give certain attributes to it, we could use an external
1325 hash map from DECL to set of attributes. */
1327 /* Let the target reassign the RTL if it wants.
1328 This is necessary, for example, when one machine specific
1329 decl attribute overrides another. */
1330 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1332 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1333 on the new decl information. */
1335 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1336 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1337 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1339 /* Make this function static known to the mudflap runtime. */
1340 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1341 mudflap_enqueue_decl (decl);
1346 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1348 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1349 && DECL_REGISTER (decl))
1351 error ("register name not specified for %q+D", decl);
1353 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1355 const char *asmspec = name+1;
1356 reg_number = decode_reg_name (asmspec);
1357 /* First detect errors in declaring global registers. */
1358 if (reg_number == -1)
1359 error ("register name not specified for %q+D", decl);
1360 else if (reg_number < 0)
1361 error ("invalid register name for %q+D", decl);
1362 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1363 error ("data type of %q+D isn%'t suitable for a register",
1365 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1366 error ("register specified for %q+D isn%'t suitable for data type",
1368 /* Now handle properly declared static register variables. */
1373 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1375 DECL_INITIAL (decl) = 0;
1376 error ("global register variable has initial value");
1378 if (TREE_THIS_VOLATILE (decl))
1379 warning (OPT_Wvolatile_register_var,
1380 "optimization may eliminate reads and/or "
1381 "writes to register variables");
1383 /* If the user specified one of the eliminables registers here,
1384 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1385 confused with that register and be eliminated. This usage is
1386 somewhat suspect... */
1388 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1389 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1390 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1392 if (TREE_STATIC (decl))
1394 /* Make this register global, so not usable for anything
1396 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1397 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1398 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1400 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1402 globalize_reg (reg_number + --nregs);
1405 /* As a register variable, it has no section. */
1409 /* Now handle ordinary static variables and functions (in memory).
1410 Also handle vars declared register invalidly. */
1411 else if (name[0] == '*')
1413 #ifdef REGISTER_PREFIX
1414 if (strlen (REGISTER_PREFIX) != 0)
1416 reg_number = decode_reg_name (name);
1417 if (reg_number >= 0 || reg_number == -3)
1418 error ("register name given for non-register variable %q+D", decl);
1423 /* Specifying a section attribute on a variable forces it into a
1424 non-.bss section, and thus it cannot be common. */
1425 if (TREE_CODE (decl) == VAR_DECL
1426 && DECL_SECTION_NAME (decl) != NULL_TREE
1427 && DECL_INITIAL (decl) == NULL_TREE
1428 && DECL_COMMON (decl))
1429 DECL_COMMON (decl) = 0;
1431 /* Variables can't be both common and weak. */
1432 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1433 DECL_COMMON (decl) = 0;
1435 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1436 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1438 x = gen_rtx_SYMBOL_REF (Pmode, name);
1439 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1440 SET_SYMBOL_REF_DECL (x, decl);
1442 x = gen_rtx_MEM (DECL_MODE (decl), x);
1443 if (TREE_CODE (decl) != FUNCTION_DECL)
1444 set_mem_attributes (x, decl, 1);
1445 SET_DECL_RTL (decl, x);
1447 /* Optionally set flags or add text to the name to record information
1448 such as that it is a function name.
1449 If the name is changed, the macro ASM_OUTPUT_LABELREF
1450 will have to know how to strip this information. */
1451 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1453 /* Make this function static known to the mudflap runtime. */
1454 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1455 mudflap_enqueue_decl (decl);
1458 /* Output a string of literal assembler code
1459 for an `asm' keyword used between functions. */
1462 assemble_asm (tree string)
1466 if (TREE_CODE (string) == ADDR_EXPR)
1467 string = TREE_OPERAND (string, 0);
1469 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1472 /* Record an element in the table of global destructors. SYMBOL is
1473 a SYMBOL_REF of the function to be called; PRIORITY is a number
1474 between 0 and MAX_INIT_PRIORITY. */
1477 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1478 int priority ATTRIBUTE_UNUSED)
1480 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1481 /* Tell GNU LD that this is part of the static destructor set.
1482 This will work for any system that uses stabs, most usefully
1484 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1485 dbxout_stab_value_label (XSTR (symbol, 0));
1487 sorry ("global destructors not supported on this target");
1491 /* Write the address of the entity given by SYMBOL to SEC. */
1493 assemble_addr_to_section (rtx symbol, section *sec)
1495 switch_to_section (sec);
1496 assemble_align (POINTER_SIZE);
1497 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1500 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1501 not) section for PRIORITY. */
1503 get_cdtor_priority_section (int priority, bool constructor_p)
1507 /* ??? This only works reliably with the GNU linker. */
1508 sprintf (buf, "%s.%.5u",
1509 constructor_p ? ".ctors" : ".dtors",
1510 /* Invert the numbering so the linker puts us in the proper
1511 order; constructors are run from right to left, and the
1512 linker sorts in increasing order. */
1513 MAX_INIT_PRIORITY - priority);
1514 return get_section (buf, SECTION_WRITE, NULL);
1518 default_named_section_asm_out_destructor (rtx symbol, int priority)
1522 if (priority != DEFAULT_INIT_PRIORITY)
1523 sec = get_cdtor_priority_section (priority,
1524 /*constructor_p=*/false);
1526 sec = get_section (".dtors", SECTION_WRITE, NULL);
1528 assemble_addr_to_section (symbol, sec);
1531 #ifdef DTORS_SECTION_ASM_OP
1533 default_dtor_section_asm_out_destructor (rtx symbol,
1534 int priority ATTRIBUTE_UNUSED)
1536 assemble_addr_to_section (symbol, dtors_section);
1540 /* Likewise for global constructors. */
1543 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1544 int priority ATTRIBUTE_UNUSED)
1546 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1547 /* Tell GNU LD that this is part of the static destructor set.
1548 This will work for any system that uses stabs, most usefully
1550 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1551 dbxout_stab_value_label (XSTR (symbol, 0));
1553 sorry ("global constructors not supported on this target");
1558 default_named_section_asm_out_constructor (rtx symbol, int priority)
1562 if (priority != DEFAULT_INIT_PRIORITY)
1563 sec = get_cdtor_priority_section (priority,
1564 /*constructor_p=*/true);
1566 sec = get_section (".ctors", SECTION_WRITE, NULL);
1568 assemble_addr_to_section (symbol, sec);
1571 #ifdef CTORS_SECTION_ASM_OP
1573 default_ctor_section_asm_out_constructor (rtx symbol,
1574 int priority ATTRIBUTE_UNUSED)
1576 assemble_addr_to_section (symbol, ctors_section);
1580 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1581 a nonzero value if the constant pool should be output before the
1582 start of the function, or a zero value if the pool should output
1583 after the end of the function. The default is to put it before the
1586 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1587 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1590 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1591 to be output to assembler.
1592 Set first_global_object_name and weak_global_object_name as appropriate. */
1595 notice_global_symbol (tree decl)
1597 const char **type = &first_global_object_name;
1599 if (first_global_object_name
1600 || !TREE_PUBLIC (decl)
1601 || DECL_EXTERNAL (decl)
1602 || !DECL_NAME (decl)
1603 || (TREE_CODE (decl) != FUNCTION_DECL
1604 && (TREE_CODE (decl) != VAR_DECL
1605 || (DECL_COMMON (decl)
1606 && (DECL_INITIAL (decl) == 0
1607 || DECL_INITIAL (decl) == error_mark_node))))
1608 || !MEM_P (DECL_RTL (decl)))
1611 /* We win when global object is found, but it is useful to know about weak
1612 symbol as well so we can produce nicer unique names. */
1613 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1614 type = &weak_global_object_name;
1620 rtx decl_rtl = DECL_RTL (decl);
1622 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1623 name = ggc_strdup (p);
1629 /* Output assembler code for the constant pool of a function and associated
1630 with defining the name of the function. DECL describes the function.
1631 NAME is the function's name. For the constant pool, we use the current
1632 constant pool data. */
1635 assemble_start_function (tree decl, const char *fnname)
1638 char tmp_label[100];
1639 bool hot_label_written = false;
1641 crtl->subsections.unlikely_text_section_name = NULL;
1643 first_function_block_is_cold = false;
1644 if (flag_reorder_blocks_and_partition)
1646 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1647 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1648 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1649 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1650 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1651 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1652 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1653 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1658 crtl->subsections.hot_section_label = NULL;
1659 crtl->subsections.cold_section_label = NULL;
1660 crtl->subsections.hot_section_end_label = NULL;
1661 crtl->subsections.cold_section_end_label = NULL;
1664 /* The following code does not need preprocessing in the assembler. */
1668 if (CONSTANT_POOL_BEFORE_FUNCTION)
1669 output_constant_pool (fnname, decl);
1671 resolve_unique_section (decl, 0, flag_function_sections);
1673 /* Make sure the not and cold text (code) sections are properly
1674 aligned. This is necessary here in the case where the function
1675 has both hot and cold sections, because we don't want to re-set
1676 the alignment when the section switch happens mid-function. */
1678 if (flag_reorder_blocks_and_partition)
1680 switch_to_section (unlikely_text_section ());
1681 assemble_align (DECL_ALIGN (decl));
1682 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1684 /* When the function starts with a cold section, we need to explicitly
1685 align the hot section and write out the hot section label.
1686 But if the current function is a thunk, we do not have a CFG. */
1688 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1690 switch_to_section (text_section);
1691 assemble_align (DECL_ALIGN (decl));
1692 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1693 hot_label_written = true;
1694 first_function_block_is_cold = true;
1697 else if (DECL_SECTION_NAME (decl))
1699 /* Calls to function_section rely on first_function_block_is_cold
1700 being accurate. The first block may be cold even if we aren't
1701 doing partitioning, if the entire function was decided by
1702 choose_function_section (predict.c) to be cold. */
1704 initialize_cold_section_name ();
1706 if (crtl->subsections.unlikely_text_section_name
1707 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1708 crtl->subsections.unlikely_text_section_name) == 0)
1709 first_function_block_is_cold = true;
1712 in_cold_section_p = first_function_block_is_cold;
1714 /* Switch to the correct text section for the start of the function. */
1716 switch_to_section (function_section (decl));
1717 if (flag_reorder_blocks_and_partition
1718 && !hot_label_written)
1719 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1721 /* Tell assembler to move to target machine's alignment for functions. */
1722 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1725 ASM_OUTPUT_ALIGN (asm_out_file, align);
1728 /* Handle a user-specified function alignment.
1729 Note that we still need to align to DECL_ALIGN, as above,
1730 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1731 if (! DECL_USER_ALIGN (decl)
1732 && align_functions_log > align
1733 && optimize_function_for_speed_p (cfun))
1735 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1736 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1737 align_functions_log, align_functions - 1);
1739 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1743 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1744 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1747 (*debug_hooks->begin_function) (decl);
1749 /* Make function name accessible from other files, if appropriate. */
1751 if (TREE_PUBLIC (decl))
1753 notice_global_symbol (decl);
1755 globalize_decl (decl);
1757 maybe_assemble_visibility (decl);
1760 if (DECL_PRESERVE_P (decl))
1761 targetm.asm_out.mark_decl_preserved (fnname);
1763 /* Do any machine/system dependent processing of the function name. */
1764 #ifdef ASM_DECLARE_FUNCTION_NAME
1765 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1767 /* Standard thing is just output label for the function. */
1768 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1769 #endif /* ASM_DECLARE_FUNCTION_NAME */
1772 /* Output assembler code associated with defining the size of the
1773 function. DECL describes the function. NAME is the function's name. */
1776 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1778 #ifdef ASM_DECLARE_FUNCTION_SIZE
1779 /* We could have switched section in the middle of the function. */
1780 if (flag_reorder_blocks_and_partition)
1781 switch_to_section (function_section (decl));
1782 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1784 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1786 output_constant_pool (fnname, decl);
1787 switch_to_section (function_section (decl)); /* need to switch back */
1789 /* Output labels for end of hot/cold text sections (to be used by
1791 if (flag_reorder_blocks_and_partition)
1793 section *save_text_section;
1795 save_text_section = in_section;
1796 switch_to_section (unlikely_text_section ());
1797 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1798 if (first_function_block_is_cold)
1799 switch_to_section (text_section);
1801 switch_to_section (function_section (decl));
1802 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1803 switch_to_section (save_text_section);
1807 /* Assemble code to leave SIZE bytes of zeros. */
1810 assemble_zeros (unsigned HOST_WIDE_INT size)
1812 /* Do no output if -fsyntax-only. */
1813 if (flag_syntax_only)
1816 #ifdef ASM_NO_SKIP_IN_TEXT
1817 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1818 so we must output 0s explicitly in the text section. */
1819 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1821 unsigned HOST_WIDE_INT i;
1822 for (i = 0; i < size; i++)
1823 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1828 ASM_OUTPUT_SKIP (asm_out_file, size);
1831 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1834 assemble_align (int align)
1836 if (align > BITS_PER_UNIT)
1838 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1842 /* Assemble a string constant with the specified C string as contents. */
1845 assemble_string (const char *p, int size)
1850 /* If the string is very long, split it up. */
1854 int thissize = size - pos;
1855 if (thissize > maximum)
1858 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1866 /* A noswitch_section_callback for lcomm_section. */
1869 emit_local (tree decl ATTRIBUTE_UNUSED,
1870 const char *name ATTRIBUTE_UNUSED,
1871 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1872 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1874 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1875 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1876 size, DECL_ALIGN (decl));
1878 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1879 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1882 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1887 /* A noswitch_section_callback for bss_noswitch_section. */
1889 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1891 emit_bss (tree decl ATTRIBUTE_UNUSED,
1892 const char *name ATTRIBUTE_UNUSED,
1893 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1894 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1896 #if defined ASM_OUTPUT_ALIGNED_BSS
1897 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1900 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1906 /* A noswitch_section_callback for comm_section. */
1909 emit_common (tree decl ATTRIBUTE_UNUSED,
1910 const char *name ATTRIBUTE_UNUSED,
1911 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1912 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1914 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1915 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1916 size, DECL_ALIGN (decl));
1918 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1919 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1922 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1927 /* A noswitch_section_callback for tls_comm_section. */
1930 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1931 const char *name ATTRIBUTE_UNUSED,
1932 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1933 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1935 #ifdef ASM_OUTPUT_TLS_COMMON
1936 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1939 sorry ("thread-local COMMON data not implemented");
1944 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1945 NAME is the name of DECL's SYMBOL_REF. */
1948 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1950 unsigned HOST_WIDE_INT size, rounded;
1952 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1955 /* Don't allocate zero bytes of common,
1956 since that means "undefined external" in the linker. */
1960 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1961 so that each uninitialized object starts on such a boundary. */
1962 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1963 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1964 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1966 if (!sect->noswitch.callback (decl, name, size, rounded)
1967 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1968 warning (0, "requested alignment for %q+D is greater than "
1969 "implemented alignment of %wu", decl, rounded);
1972 /* A subroutine of assemble_variable. Output the label and contents of
1973 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1974 is as for assemble_variable. */
1977 assemble_variable_contents (tree decl, const char *name,
1978 bool dont_output_data)
1980 /* Do any machine/system dependent processing of the object. */
1981 #ifdef ASM_DECLARE_OBJECT_NAME
1982 last_assemble_variable_decl = decl;
1983 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1985 /* Standard thing is just output label for the object. */
1986 ASM_OUTPUT_LABEL (asm_out_file, name);
1987 #endif /* ASM_DECLARE_OBJECT_NAME */
1989 if (!dont_output_data)
1991 if (DECL_INITIAL (decl)
1992 && DECL_INITIAL (decl) != error_mark_node
1993 && !initializer_zerop (DECL_INITIAL (decl)))
1994 /* Output the actual data. */
1995 output_constant (DECL_INITIAL (decl),
1996 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1999 /* Leave space for it. */
2000 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2004 /* Initialize emulated tls object TO, which refers to TLS variable
2005 DECL and is initialized by PROXY. */
2008 default_emutls_var_init (tree to, tree decl, tree proxy)
2010 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2011 constructor_elt *elt;
2012 tree type = TREE_TYPE (to);
2013 tree field = TYPE_FIELDS (type);
2015 elt = VEC_quick_push (constructor_elt, v, NULL);
2017 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2019 elt = VEC_quick_push (constructor_elt, v, NULL);
2020 field = TREE_CHAIN (field);
2022 elt->value = build_int_cst (TREE_TYPE (field),
2023 DECL_ALIGN_UNIT (decl));
2025 elt = VEC_quick_push (constructor_elt, v, NULL);
2026 field = TREE_CHAIN (field);
2028 elt->value = null_pointer_node;
2030 elt = VEC_quick_push (constructor_elt, v, NULL);
2031 field = TREE_CHAIN (field);
2035 return build_constructor (type, v);
2038 /* Assemble everything that is needed for a variable or function declaration.
2039 Not used for automatic variables, and not used for function definitions.
2040 Should not be called for variables of incomplete structure type.
2042 TOP_LEVEL is nonzero if this variable has file scope.
2043 AT_END is nonzero if this is the special handling, at end of compilation,
2044 to define things that have had only tentative definitions.
2045 DONT_OUTPUT_DATA if nonzero means don't actually output the
2046 initial value (that will be done by the caller). */
2049 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2050 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2053 rtx decl_rtl, symbol;
2056 if (! targetm.have_tls
2057 && TREE_CODE (decl) == VAR_DECL
2058 && DECL_THREAD_LOCAL_P (decl))
2060 tree to = emutls_decl (decl);
2062 /* If this variable is defined locally, then we need to initialize the
2063 control structure with size and alignment information. We do this
2064 at the last moment because tentative definitions can take a locally
2065 defined but uninitialized variable and initialize it later, which
2066 would result in incorrect contents. */
2067 if (! DECL_EXTERNAL (to)
2068 && (! DECL_COMMON (to)
2069 || (DECL_INITIAL (decl)
2070 && DECL_INITIAL (decl) != error_mark_node)))
2072 DECL_INITIAL (to) = targetm.emutls.var_init
2073 (to, decl, get_emutls_init_templ_addr (decl));
2075 /* Make sure the template is marked as needed early enough.
2076 Without this, if the variable is placed in a
2077 section-anchored block, the template will only be marked
2078 when it's too late. */
2079 record_references_in_initializer (to);
2085 last_assemble_variable_decl = 0;
2087 /* Normally no need to say anything here for external references,
2088 since assemble_external is called by the language-specific code
2089 when a declaration is first seen. */
2091 if (DECL_EXTERNAL (decl))
2094 /* Output no assembler code for a function declaration.
2095 Only definitions of functions output anything. */
2097 if (TREE_CODE (decl) == FUNCTION_DECL)
2100 /* Do nothing for global register variables. */
2101 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2103 TREE_ASM_WRITTEN (decl) = 1;
2107 /* If type was incomplete when the variable was declared,
2108 see if it is complete now. */
2110 if (DECL_SIZE (decl) == 0)
2111 layout_decl (decl, 0);
2113 /* Still incomplete => don't allocate it; treat the tentative defn
2114 (which is what it must have been) as an `extern' reference. */
2116 if (!dont_output_data && DECL_SIZE (decl) == 0)
2118 error ("storage size of %q+D isn%'t known", decl);
2119 TREE_ASM_WRITTEN (decl) = 1;
2123 /* The first declaration of a variable that comes through this function
2124 decides whether it is global (in C, has external linkage)
2125 or local (in C, has internal linkage). So do nothing more
2126 if this function has already run. */
2128 if (TREE_ASM_WRITTEN (decl))
2131 /* Make sure targetm.encode_section_info is invoked before we set
2133 decl_rtl = DECL_RTL (decl);
2135 TREE_ASM_WRITTEN (decl) = 1;
2137 /* Do no output if -fsyntax-only. */
2138 if (flag_syntax_only)
2143 if (! dont_output_data
2144 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2146 error ("size of variable %q+D is too large", decl);
2150 gcc_assert (MEM_P (decl_rtl));
2151 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2152 symbol = XEXP (decl_rtl, 0);
2153 name = XSTR (symbol, 0);
2154 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2155 notice_global_symbol (decl);
2157 /* Compute the alignment of this data. */
2159 align_variable (decl, dont_output_data);
2160 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2162 if (TREE_PUBLIC (decl))
2163 maybe_assemble_visibility (decl);
2165 if (DECL_PRESERVE_P (decl))
2166 targetm.asm_out.mark_decl_preserved (name);
2168 /* First make the assembler name(s) global if appropriate. */
2169 sect = get_variable_section (decl, false);
2170 if (TREE_PUBLIC (decl)
2171 && (sect->common.flags & SECTION_COMMON) == 0)
2172 globalize_decl (decl);
2174 /* Output any data that we will need to use the address of. */
2175 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2176 output_addressed_constants (DECL_INITIAL (decl));
2178 /* dbxout.c needs to know this. */
2179 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2180 DECL_IN_TEXT_SECTION (decl) = 1;
2182 /* If the decl is part of an object_block, make sure that the decl
2183 has been positioned within its block, but do not write out its
2184 definition yet. output_object_blocks will do that later. */
2185 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2187 gcc_assert (!dont_output_data);
2188 place_block_symbol (symbol);
2190 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2191 assemble_noswitch_variable (decl, name, sect);
2194 switch_to_section (sect);
2195 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2196 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2197 assemble_variable_contents (decl, name, dont_output_data);
2201 /* Return 1 if type TYPE contains any pointers. */
2204 contains_pointers_p (tree type)
2206 switch (TREE_CODE (type))
2209 case REFERENCE_TYPE:
2210 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2211 so I'll play safe and return 1. */
2217 case QUAL_UNION_TYPE:
2220 /* For a type that has fields, see if the fields have pointers. */
2221 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2222 if (TREE_CODE (fields) == FIELD_DECL
2223 && contains_pointers_p (TREE_TYPE (fields)))
2229 /* An array type contains pointers if its element type does. */
2230 return contains_pointers_p (TREE_TYPE (type));
2237 /* We delay assemble_external processing until
2238 the compilation unit is finalized. This is the best we can do for
2239 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2240 it all the way to final. See PR 17982 for further discussion. */
2241 static GTY(()) tree pending_assemble_externals;
2243 #ifdef ASM_OUTPUT_EXTERNAL
2244 /* True if DECL is a function decl for which no out-of-line copy exists.
2245 It is assumed that DECL's assembler name has been set. */
2248 incorporeal_function_p (tree decl)
2250 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2254 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2255 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2258 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2259 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
2265 /* Actually do the tests to determine if this is necessary, and invoke
2266 ASM_OUTPUT_EXTERNAL. */
2268 assemble_external_real (tree decl)
2270 rtx rtl = DECL_RTL (decl);
2272 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2273 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2274 && !incorporeal_function_p (decl))
2276 /* Some systems do require some output. */
2277 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2278 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2284 process_pending_assemble_externals (void)
2286 #ifdef ASM_OUTPUT_EXTERNAL
2288 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2289 assemble_external_real (TREE_VALUE (list));
2291 pending_assemble_externals = 0;
2295 /* This TREE_LIST contains any weak symbol declarations waiting
2297 static GTY(()) tree weak_decls;
2299 /* Output something to declare an external symbol to the assembler,
2300 and qualifiers such as weakness. (Most assemblers don't need
2301 extern declaration, so we normally output nothing.) Do nothing if
2302 DECL is not external. */
2305 assemble_external (tree decl ATTRIBUTE_UNUSED)
2307 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2308 main body of this code is only rarely exercised. To provide some
2309 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2310 open. If it's not, we should not be calling this function. */
2311 gcc_assert (asm_out_file);
2313 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2316 /* We want to output annotation for weak and external symbols at
2317 very last to check if they are references or not. */
2319 if (SUPPORTS_WEAK && DECL_WEAK (decl)
2320 /* TREE_STATIC is a weird and abused creature which is not
2321 generally the right test for whether an entity has been
2322 locally emitted, inlined or otherwise not-really-extern, but
2323 for declarations that can be weak, it happens to be
2325 && !TREE_STATIC (decl)
2326 && tree_find_value (weak_decls, decl) == NULL_TREE)
2327 weak_decls = tree_cons (NULL, decl, weak_decls);
2329 #ifdef ASM_OUTPUT_EXTERNAL
2330 if (tree_find_value (pending_assemble_externals, decl) == NULL_TREE)
2331 pending_assemble_externals = tree_cons (NULL, decl,
2332 pending_assemble_externals);
2336 /* Similar, for calling a library function FUN. */
2339 assemble_external_libcall (rtx fun)
2341 /* Declare library function name external when first used, if nec. */
2342 if (! SYMBOL_REF_USED (fun))
2344 SYMBOL_REF_USED (fun) = 1;
2345 targetm.asm_out.external_libcall (fun);
2349 /* Assemble a label named NAME. */
2352 assemble_label (const char *name)
2354 ASM_OUTPUT_LABEL (asm_out_file, name);
2357 /* Set the symbol_referenced flag for ID. */
2359 mark_referenced (tree id)
2361 TREE_SYMBOL_REFERENCED (id) = 1;
2364 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2366 mark_decl_referenced (tree decl)
2368 if (TREE_CODE (decl) == FUNCTION_DECL)
2370 /* Extern inline functions don't become needed when referenced.
2371 If we know a method will be emitted in other TU and no new
2372 functions can be marked reachable, just use the external
2374 struct cgraph_node *node = cgraph_node (decl);
2375 if (!DECL_EXTERNAL (decl)
2376 && (!node->local.vtable_method || !cgraph_global_info_ready
2377 || !node->local.finalized))
2378 cgraph_mark_needed_node (node);
2380 else if (TREE_CODE (decl) == VAR_DECL)
2382 struct varpool_node *node = varpool_node (decl);
2383 varpool_mark_needed_node (node);
2384 /* C++ frontend use mark_decl_references to force COMDAT variables
2385 to be output that might appear dead otherwise. */
2386 node->force_output = true;
2388 /* else do nothing - we can get various sorts of CST nodes here,
2389 which do not need to be marked. */
2393 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2394 until we find an identifier that is not itself a transparent alias.
2395 Modify the alias passed to it by reference (and all aliases on the
2396 way to the ultimate target), such that they do not have to be
2397 followed again, and return the ultimate target of the alias
2401 ultimate_transparent_alias_target (tree *alias)
2403 tree target = *alias;
2405 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2407 gcc_assert (TREE_CHAIN (target));
2408 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2409 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2410 && ! TREE_CHAIN (target));
2417 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2418 starts with a *, the rest of NAME is output verbatim. Otherwise
2419 NAME is transformed in a target-specific way (usually by the
2420 addition of an underscore). */
2423 assemble_name_raw (FILE *file, const char *name)
2426 fputs (&name[1], file);
2428 ASM_OUTPUT_LABELREF (file, name);
2431 /* Like assemble_name_raw, but should be used when NAME might refer to
2432 an entity that is also represented as a tree (like a function or
2433 variable). If NAME does refer to such an entity, that entity will
2434 be marked as referenced. */
2437 assemble_name (FILE *file, const char *name)
2439 const char *real_name;
2442 real_name = targetm.strip_name_encoding (name);
2444 id = maybe_get_identifier (real_name);
2449 mark_referenced (id);
2450 ultimate_transparent_alias_target (&id);
2452 name = IDENTIFIER_POINTER (id);
2453 gcc_assert (! TREE_CHAIN (id));
2456 assemble_name_raw (file, name);
2459 /* Allocate SIZE bytes writable static space with a gensym name
2460 and return an RTX to refer to its address. */
2463 assemble_static_space (unsigned HOST_WIDE_INT size)
2466 const char *namestring;
2469 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2471 namestring = ggc_strdup (name);
2473 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2474 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2476 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2477 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2480 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2481 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2484 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2485 so that each uninitialized object starts on such a boundary. */
2486 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2487 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2488 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2489 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2490 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2491 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2498 /* Assemble the static constant template for function entry trampolines.
2499 This is done at most once per compilation.
2500 Returns an RTX for the address of the template. */
2502 static GTY(()) rtx initial_trampoline;
2504 #ifdef TRAMPOLINE_TEMPLATE
2506 assemble_trampoline_template (void)
2513 if (initial_trampoline)
2514 return initial_trampoline;
2516 /* By default, put trampoline templates in read-only data section. */
2518 #ifdef TRAMPOLINE_SECTION
2519 switch_to_section (TRAMPOLINE_SECTION);
2521 switch_to_section (readonly_data_section);
2524 /* Write the assembler code to define one. */
2525 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2528 ASM_OUTPUT_ALIGN (asm_out_file, align);
2531 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2532 TRAMPOLINE_TEMPLATE (asm_out_file);
2534 /* Record the rtl to refer to it. */
2535 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2536 name = ggc_strdup (label);
2537 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2538 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2540 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
2541 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2543 return initial_trampoline;
2547 /* A and B are either alignments or offsets. Return the minimum alignment
2548 that may be assumed after adding the two together. */
2550 static inline unsigned
2551 min_align (unsigned int a, unsigned int b)
2553 return (a | b) & -(a | b);
2556 /* Return the assembler directive for creating a given kind of integer
2557 object. SIZE is the number of bytes in the object and ALIGNED_P
2558 indicates whether it is known to be aligned. Return NULL if the
2559 assembly dialect has no such directive.
2561 The returned string should be printed at the start of a new line and
2562 be followed immediately by the object's initial value. */
2565 integer_asm_op (int size, int aligned_p)
2567 struct asm_int_op *ops;
2570 ops = &targetm.asm_out.aligned_op;
2572 ops = &targetm.asm_out.unaligned_op;
2577 return targetm.asm_out.byte_op;
2591 /* Use directive OP to assemble an integer object X. Print OP at the
2592 start of the line, followed immediately by the value of X. */
2595 assemble_integer_with_op (const char *op, rtx x)
2597 fputs (op, asm_out_file);
2598 output_addr_const (asm_out_file, x);
2599 fputc ('\n', asm_out_file);
2602 /* The default implementation of the asm_out.integer target hook. */
2605 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2606 unsigned int size ATTRIBUTE_UNUSED,
2607 int aligned_p ATTRIBUTE_UNUSED)
2609 const char *op = integer_asm_op (size, aligned_p);
2610 /* Avoid GAS bugs for large values. Specifically negative values whose
2611 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2612 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2614 return op && (assemble_integer_with_op (op, x), true);
2617 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2618 the alignment of the integer in bits. Return 1 if we were able to output
2619 the constant, otherwise 0. We must be able to output the constant,
2620 if FORCE is nonzero. */
2623 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2627 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2629 /* See if the target hook can handle this kind of object. */
2630 if (targetm.asm_out.integer (x, size, aligned_p))
2633 /* If the object is a multi-byte one, try splitting it up. Split
2634 it into words it if is multi-word, otherwise split it into bytes. */
2637 enum machine_mode omode, imode;
2638 unsigned int subalign;
2639 unsigned int subsize, i;
2640 unsigned char mclass;
2642 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2643 subalign = MIN (align, subsize * BITS_PER_UNIT);
2644 if (GET_CODE (x) == CONST_FIXED)
2645 mclass = GET_MODE_CLASS (GET_MODE (x));
2649 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2650 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2652 for (i = 0; i < size; i += subsize)
2654 rtx partial = simplify_subreg (omode, x, imode, i);
2655 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2661 /* If we've printed some of it, but not all of it, there's no going
2666 gcc_assert (!force);
2672 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2674 long data[4] = {0, 0, 0, 0};
2676 int bitsize, nelts, nunits, units_per;
2678 /* This is hairy. We have a quantity of known size. real_to_target
2679 will put it into an array of *host* longs, 32 bits per element
2680 (even if long is more than 32 bits). We need to determine the
2681 number of array elements that are occupied (nelts) and the number
2682 of *target* min-addressable units that will be occupied in the
2683 object file (nunits). We cannot assume that 32 divides the
2684 mode's bitsize (size * BITS_PER_UNIT) evenly.
2686 size * BITS_PER_UNIT is used here to make sure that padding bits
2687 (which might appear at either end of the value; real_to_target
2688 will include the padding bits in its output array) are included. */
2690 nunits = GET_MODE_SIZE (mode);
2691 bitsize = nunits * BITS_PER_UNIT;
2692 nelts = CEIL (bitsize, 32);
2693 units_per = 32 / BITS_PER_UNIT;
2695 real_to_target (data, &d, mode);
2697 /* Put out the first word with the specified alignment. */
2698 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2699 nunits -= units_per;
2701 /* Subsequent words need only 32-bit alignment. */
2702 align = min_align (align, 32);
2704 for (i = 1; i < nelts; i++)
2706 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2707 nunits -= units_per;
2711 /* Given an expression EXP with a constant value,
2712 reduce it to the sum of an assembler symbol and an integer.
2713 Store them both in the structure *VALUE.
2714 EXP must be reducible. */
2716 struct addr_const GTY(())
2719 HOST_WIDE_INT offset;
2723 decode_addr_const (tree exp, struct addr_const *value)
2725 tree target = TREE_OPERAND (exp, 0);
2731 if (TREE_CODE (target) == COMPONENT_REF
2732 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2735 offset += int_byte_position (TREE_OPERAND (target, 1));
2736 target = TREE_OPERAND (target, 0);
2738 else if (TREE_CODE (target) == ARRAY_REF
2739 || TREE_CODE (target) == ARRAY_RANGE_REF)
2741 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2742 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2743 target = TREE_OPERAND (target, 0);
2749 switch (TREE_CODE (target))
2753 x = DECL_RTL (target);
2757 x = gen_rtx_MEM (FUNCTION_MODE,
2758 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2767 x = output_constant_def (target, 1);
2774 gcc_assert (MEM_P (x));
2778 value->offset = offset;
2781 /* Uniquize all constants that appear in memory.
2782 Each constant in memory thus far output is recorded
2783 in `const_desc_table'. */
2785 struct constant_descriptor_tree GTY(())
2787 /* A MEM for the constant. */
2790 /* The value of the constant. */
2793 /* Hash of value. Computing the hash from value each time
2794 hashfn is called can't work properly, as that means recursive
2795 use of the hash table during hash table expansion. */
2799 static GTY((param_is (struct constant_descriptor_tree)))
2800 htab_t const_desc_htab;
2802 static struct constant_descriptor_tree * build_constant_desc (tree);
2803 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2805 /* Compute a hash code for a constant expression. */
2808 const_desc_hash (const void *ptr)
2810 return ((const struct constant_descriptor_tree *)ptr)->hash;
2814 const_hash_1 (const tree exp)
2819 enum tree_code code = TREE_CODE (exp);
2821 /* Either set P and LEN to the address and len of something to hash and
2822 exit the switch or return a value. */
2827 p = (char *) &TREE_INT_CST (exp);
2828 len = sizeof TREE_INT_CST (exp);
2832 return real_hash (TREE_REAL_CST_PTR (exp));
2835 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2838 p = TREE_STRING_POINTER (exp);
2839 len = TREE_STRING_LENGTH (exp);
2843 return (const_hash_1 (TREE_REALPART (exp)) * 5
2844 + const_hash_1 (TREE_IMAGPART (exp)));
2848 unsigned HOST_WIDE_INT idx;
2851 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2853 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2855 hi = hi * 603 + const_hash_1 (value);
2863 struct addr_const value;
2865 decode_addr_const (exp, &value);
2866 switch (GET_CODE (value.base))
2869 /* Don't hash the address of the SYMBOL_REF;
2870 only use the offset and the symbol name. */
2872 p = XSTR (value.base, 0);
2873 for (i = 0; p[i] != 0; i++)
2874 hi = ((hi * 613) + (unsigned) (p[i]));
2878 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2888 case POINTER_PLUS_EXPR:
2890 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2891 + const_hash_1 (TREE_OPERAND (exp, 1)));
2894 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2897 /* A language specific constant. Just hash the code. */
2901 /* Compute hashing function. */
2903 for (i = 0; i < len; i++)
2904 hi = ((hi * 613) + (unsigned) (p[i]));
2909 /* Wrapper of compare_constant, for the htab interface. */
2911 const_desc_eq (const void *p1, const void *p2)
2913 const struct constant_descriptor_tree *const c1
2914 = (const struct constant_descriptor_tree *) p1;
2915 const struct constant_descriptor_tree *const c2
2916 = (const struct constant_descriptor_tree *) p2;
2917 if (c1->hash != c2->hash)
2919 return compare_constant (c1->value, c2->value);
2922 /* Compare t1 and t2, and return 1 only if they are known to result in
2923 the same bit pattern on output. */
2926 compare_constant (const tree t1, const tree t2)
2928 enum tree_code typecode;
2930 if (t1 == NULL_TREE)
2931 return t2 == NULL_TREE;
2932 if (t2 == NULL_TREE)
2935 if (TREE_CODE (t1) != TREE_CODE (t2))
2938 switch (TREE_CODE (t1))
2941 /* Integer constants are the same only if the same width of type. */
2942 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2944 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2946 return tree_int_cst_equal (t1, t2);
2949 /* Real constants are the same only if the same width of type. */
2950 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2953 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2956 /* Fixed constants are the same only if the same width of type. */
2957 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2960 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2963 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2966 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2967 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2968 TREE_STRING_LENGTH (t1)));
2971 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2972 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2976 VEC(constructor_elt, gc) *v1, *v2;
2977 unsigned HOST_WIDE_INT idx;
2979 typecode = TREE_CODE (TREE_TYPE (t1));
2980 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2983 if (typecode == ARRAY_TYPE)
2985 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2986 /* For arrays, check that the sizes all match. */
2987 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2989 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2994 /* For record and union constructors, require exact type
2996 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3000 v1 = CONSTRUCTOR_ELTS (t1);
3001 v2 = CONSTRUCTOR_ELTS (t2);
3002 if (VEC_length (constructor_elt, v1)
3003 != VEC_length (constructor_elt, v2))
3006 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3008 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3009 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3011 /* Check that each value is the same... */
3012 if (!compare_constant (c1->value, c2->value))
3014 /* ... and that they apply to the same fields! */
3015 if (typecode == ARRAY_TYPE)
3017 if (!compare_constant (c1->index, c2->index))
3022 if (c1->index != c2->index)
3033 struct addr_const value1, value2;
3035 decode_addr_const (t1, &value1);
3036 decode_addr_const (t2, &value2);
3037 return (value1.offset == value2.offset
3038 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3042 case POINTER_PLUS_EXPR:
3045 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3046 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3049 case VIEW_CONVERT_EXPR:
3050 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3059 /* Make a copy of the whole tree structure for a constant. This
3060 handles the same types of nodes that compare_constant handles. */
3063 copy_constant (tree exp)
3065 switch (TREE_CODE (exp))
3068 /* For ADDR_EXPR, we do not want to copy the decl whose address
3069 is requested. We do want to copy constants though. */
3070 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3071 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3072 copy_constant (TREE_OPERAND (exp, 0)));
3074 return copy_node (exp);
3080 return copy_node (exp);
3083 return build_complex (TREE_TYPE (exp),
3084 copy_constant (TREE_REALPART (exp)),
3085 copy_constant (TREE_IMAGPART (exp)));
3088 case POINTER_PLUS_EXPR:
3090 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3091 copy_constant (TREE_OPERAND (exp, 0)),
3092 copy_constant (TREE_OPERAND (exp, 1)));
3095 case VIEW_CONVERT_EXPR:
3096 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3097 copy_constant (TREE_OPERAND (exp, 0)));
3101 tree copy = copy_node (exp);
3102 VEC(constructor_elt, gc) *v;
3103 unsigned HOST_WIDE_INT idx;
3104 tree purpose, value;
3106 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3107 CONSTRUCTOR_ELTS (exp)));
3108 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3110 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3111 ce->index = purpose;
3112 ce->value = copy_constant (value);
3114 CONSTRUCTOR_ELTS (copy) = v;
3123 /* Return the alignment of constant EXP in bits. */
3126 get_constant_alignment (tree exp)
3130 align = TYPE_ALIGN (TREE_TYPE (exp));
3131 #ifdef CONSTANT_ALIGNMENT
3132 align = CONSTANT_ALIGNMENT (exp, align);
3137 /* Return the section into which constant EXP should be placed. */
3140 get_constant_section (tree exp)
3142 if (IN_NAMED_SECTION (exp))
3143 return get_named_section (exp, NULL, compute_reloc_for_constant (exp));
3145 return targetm.asm_out.select_section (exp,
3146 compute_reloc_for_constant (exp),
3147 get_constant_alignment (exp));
3150 /* Return the size of constant EXP in bytes. */
3152 static HOST_WIDE_INT
3153 get_constant_size (tree exp)
3157 size = int_size_in_bytes (TREE_TYPE (exp));
3158 if (TREE_CODE (exp) == STRING_CST)
3159 size = MAX (TREE_STRING_LENGTH (exp), size);
3163 /* Subroutine of output_constant_def:
3164 No constant equal to EXP is known to have been output.
3165 Make a constant descriptor to enter EXP in the hash table.
3166 Assign the label number and construct RTL to refer to the
3167 constant's location in memory.
3168 Caller is responsible for updating the hash table. */
3170 static struct constant_descriptor_tree *
3171 build_constant_desc (tree exp)
3177 struct constant_descriptor_tree *desc;
3179 desc = GGC_NEW (struct constant_descriptor_tree);
3180 desc->value = copy_constant (exp);
3182 /* Propagate marked-ness to copied constant. */
3183 if (flag_mudflap && mf_marked_p (exp))
3184 mf_mark (desc->value);
3186 /* Create a string containing the label name, in LABEL. */
3187 labelno = const_labelno++;
3188 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3190 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3191 if (use_object_blocks_p ())
3193 section *sect = get_constant_section (exp);
3194 symbol = create_block_symbol (ggc_strdup (label),
3195 get_block_for_section (sect), -1);
3198 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3199 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3200 SET_SYMBOL_REF_DECL (symbol, desc->value);
3201 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3203 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3204 set_mem_attributes (rtl, exp, 1);
3205 set_mem_alias_set (rtl, 0);
3206 set_mem_alias_set (rtl, const_alias_set);
3208 /* Set flags or add text to the name to record information, such as
3209 that it is a local symbol. If the name is changed, the macro
3210 ASM_OUTPUT_LABELREF will have to know how to strip this
3211 information. This call might invalidate our local variable
3212 SYMBOL; we can't use it afterward. */
3214 targetm.encode_section_info (exp, rtl, true);
3221 /* Return an rtx representing a reference to constant data in memory
3222 for the constant expression EXP.
3224 If assembler code for such a constant has already been output,
3225 return an rtx to refer to it.
3226 Otherwise, output such a constant in memory
3227 and generate an rtx for it.
3229 If DEFER is nonzero, this constant can be deferred and output only
3230 if referenced in the function after all optimizations.
3232 `const_desc_table' records which constants already have label strings. */
3235 output_constant_def (tree exp, int defer)
3237 struct constant_descriptor_tree *desc;
3238 struct constant_descriptor_tree key;
3241 /* Look up EXP in the table of constant descriptors. If we didn't find
3242 it, create a new one. */
3244 key.hash = const_hash_1 (exp);
3245 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3247 desc = (struct constant_descriptor_tree *) *loc;
3250 desc = build_constant_desc (exp);
3251 desc->hash = key.hash;
3255 maybe_output_constant_def_contents (desc, defer);
3259 /* Subroutine of output_constant_def: Decide whether or not we need to
3260 output the constant DESC now, and if so, do it. */
3262 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3265 rtx symbol = XEXP (desc->rtl, 0);
3266 tree exp = desc->value;
3268 if (flag_syntax_only)
3271 if (TREE_ASM_WRITTEN (exp))
3272 /* Already output; don't do it again. */
3275 /* We can always defer constants as long as the context allows
3279 /* Increment n_deferred_constants if it exists. It needs to be at
3280 least as large as the number of constants actually referred to
3281 by the function. If it's too small we'll stop looking too early
3282 and fail to emit constants; if it's too large we'll only look
3283 through the entire function when we could have stopped earlier. */
3285 n_deferred_constants++;
3289 output_constant_def_contents (symbol);
3292 /* Subroutine of output_constant_def_contents. Output the definition
3293 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3294 constant's alignment in bits. */
3297 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3301 size = get_constant_size (exp);
3303 /* Do any machine/system dependent processing of the constant. */
3304 #ifdef ASM_DECLARE_CONSTANT_NAME
3305 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3307 /* Standard thing is just output label for the constant. */
3308 ASM_OUTPUT_LABEL (asm_out_file, label);
3309 #endif /* ASM_DECLARE_CONSTANT_NAME */
3311 /* Output the value of EXP. */
3312 output_constant (exp, size, align);
3315 /* We must output the constant data referred to by SYMBOL; do so. */
3318 output_constant_def_contents (rtx symbol)
3320 tree exp = SYMBOL_REF_DECL (symbol);
3323 /* Make sure any other constants whose addresses appear in EXP
3324 are assigned label numbers. */
3325 output_addressed_constants (exp);
3327 /* We are no longer deferring this constant. */
3328 TREE_ASM_WRITTEN (exp) = 1;
3330 /* If the constant is part of an object block, make sure that the
3331 decl has been positioned within its block, but do not write out
3332 its definition yet. output_object_blocks will do that later. */
3333 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3334 place_block_symbol (symbol);
3337 switch_to_section (get_constant_section (exp));
3338 align = get_constant_alignment (exp);
3339 if (align > BITS_PER_UNIT)
3340 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3341 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3344 mudflap_enqueue_constant (exp);
3347 /* Look up EXP in the table of constant descriptors. Return the rtl
3348 if it has been emitted, else null. */
3351 lookup_constant_def (tree exp)
3353 struct constant_descriptor_tree *desc;
3354 struct constant_descriptor_tree key;
3357 key.hash = const_hash_1 (exp);
3358 desc = (struct constant_descriptor_tree *)
3359 htab_find_with_hash (const_desc_htab, &key, key.hash);
3361 return (desc ? desc->rtl : NULL_RTX);
3364 /* Used in the hash tables to avoid outputting the same constant
3365 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3366 are output once per function, not once per file. */
3367 /* ??? Only a few targets need per-function constant pools. Most
3368 can use one per-file pool. Should add a targetm bit to tell the
3371 struct rtx_constant_pool GTY(())
3373 /* Pointers to first and last constant in pool, as ordered by offset. */
3374 struct constant_descriptor_rtx *first;
3375 struct constant_descriptor_rtx *last;
3377 /* Hash facility for making memory-constants from constant rtl-expressions.
3378 It is used on RISC machines where immediate integer arguments and
3379 constant addresses are restricted so that such constants must be stored
3381 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3383 /* Current offset in constant pool (does not include any
3384 machine-specific header). */
3385 HOST_WIDE_INT offset;
3388 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
3390 struct constant_descriptor_rtx *next;
3394 HOST_WIDE_INT offset;
3396 enum machine_mode mode;
3402 /* Hash and compare functions for const_rtx_htab. */
3405 const_desc_rtx_hash (const void *ptr)
3407 const struct constant_descriptor_rtx *const desc
3408 = (const struct constant_descriptor_rtx *) ptr;
3413 const_desc_rtx_eq (const void *a, const void *b)
3415 const struct constant_descriptor_rtx *const x
3416 = (const struct constant_descriptor_rtx *) a;
3417 const struct constant_descriptor_rtx *const y
3418 = (const struct constant_descriptor_rtx *) b;
3420 if (x->mode != y->mode)
3422 return rtx_equal_p (x->constant, y->constant);
3425 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3428 const_rtx_hash_1 (rtx *xp, void *data)
3430 unsigned HOST_WIDE_INT hwi;
3431 enum machine_mode mode;
3437 code = GET_CODE (x);
3438 mode = GET_MODE (x);
3439 h = (hashval_t) code * 1048573 + mode;
3447 const int shift = sizeof (hashval_t) * CHAR_BIT;
3448 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3451 h ^= (hashval_t) hwi;
3452 for (i = 1; i < n; ++i)
3455 h ^= (hashval_t) hwi;
3461 if (mode == VOIDmode)
3463 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3467 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3471 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3477 for (i = XVECLEN (x, 0); i-- > 0; )
3478 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3483 h ^= htab_hash_string (XSTR (x, 0));
3487 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3491 case UNSPEC_VOLATILE:
3492 h = h * 251 + XINT (x, 1);
3499 hp = (hashval_t *) data;
3500 *hp = *hp * 509 + h;
3504 /* Compute a hash value for X, which should be a constant. */
3507 const_rtx_hash (rtx x)
3510 for_each_rtx (&x, const_rtx_hash_1, &h);
3515 /* Create and return a new rtx constant pool. */
3517 static struct rtx_constant_pool *
3518 create_constant_pool (void)
3520 struct rtx_constant_pool *pool;
3522 pool = GGC_NEW (struct rtx_constant_pool);
3523 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3524 const_desc_rtx_eq, NULL);
3531 /* Initialize constant pool hashing for a new function. */
3534 init_varasm_status (void)
3536 crtl->varasm.pool = create_constant_pool ();
3537 crtl->varasm.deferred_constants = 0;
3540 /* Given a MINUS expression, simplify it if both sides
3541 include the same symbol. */
3544 simplify_subtraction (rtx x)
3546 rtx r = simplify_rtx (x);
3550 /* Given a constant rtx X, make (or find) a memory constant for its value
3551 and return a MEM rtx to refer to it in memory. */
3554 force_const_mem (enum machine_mode mode, rtx x)
3556 struct constant_descriptor_rtx *desc, tmp;
3557 struct rtx_constant_pool *pool;
3564 /* If we're not allowed to drop X into the constant pool, don't. */
3565 if (targetm.cannot_force_const_mem (x))
3568 /* Record that this function has used a constant pool entry. */
3569 crtl->uses_const_pool = 1;
3571 /* Decide which pool to use. */
3572 pool = (targetm.use_blocks_for_constant_p (mode, x)
3573 ? shared_constant_pool
3574 : crtl->varasm.pool);
3576 /* Lookup the value in the hashtable. */
3579 hash = const_rtx_hash (x);
3580 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3581 desc = (struct constant_descriptor_rtx *) *slot;
3583 /* If the constant was already present, return its memory. */
3585 return copy_rtx (desc->mem);
3587 /* Otherwise, create a new descriptor. */
3588 desc = GGC_NEW (struct constant_descriptor_rtx);
3591 /* Align the location counter as required by EXP's data type. */
3592 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3593 #ifdef CONSTANT_ALIGNMENT
3595 tree type = lang_hooks.types.type_for_mode (mode, 0);
3596 if (type != NULL_TREE)
3597 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3601 pool->offset += (align / BITS_PER_UNIT) - 1;
3602 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3605 desc->constant = tmp.constant;
3606 desc->offset = pool->offset;
3609 desc->align = align;
3610 desc->labelno = const_labelno;
3613 pool->offset += GET_MODE_SIZE (mode);
3615 pool->last->next = desc;
3617 pool->first = pool->last = desc;
3620 /* Create a string containing the label name, in LABEL. */
3621 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3624 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3625 the constants pool. */
3626 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3628 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3629 symbol = create_block_symbol (ggc_strdup (label),
3630 get_block_for_section (sect), -1);
3633 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3635 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3636 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3637 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3639 /* Construct the MEM. */
3640 desc->mem = def = gen_const_mem (mode, symbol);
3641 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3642 set_mem_align (def, align);
3644 /* If we're dropping a label to the constant pool, make sure we
3646 if (GET_CODE (x) == LABEL_REF)
3647 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3649 return copy_rtx (def);
3652 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3655 get_pool_constant (rtx addr)
3657 return SYMBOL_REF_CONSTANT (addr)->constant;
3660 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3661 and whether it has been output or not. */
3664 get_pool_constant_mark (rtx addr, bool *pmarked)
3666 struct constant_descriptor_rtx *desc;
3668 desc = SYMBOL_REF_CONSTANT (addr);
3669 *pmarked = (desc->mark != 0);
3670 return desc->constant;
3673 /* Similar, return the mode. */
3676 get_pool_mode (const_rtx addr)
3678 return SYMBOL_REF_CONSTANT (addr)->mode;
3681 /* Return the size of the constant pool. */
3684 get_pool_size (void)
3686 return crtl->varasm.pool->offset;
3689 /* Worker function for output_constant_pool_1. Emit assembly for X
3690 in MODE with known alignment ALIGN. */
3693 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3695 switch (GET_MODE_CLASS (mode))
3698 case MODE_DECIMAL_FLOAT:
3702 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3703 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3704 assemble_real (r, mode, align);
3709 case MODE_PARTIAL_INT:
3714 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3717 case MODE_VECTOR_FLOAT:
3718 case MODE_VECTOR_INT:
3719 case MODE_VECTOR_FRACT:
3720 case MODE_VECTOR_UFRACT:
3721 case MODE_VECTOR_ACCUM:
3722 case MODE_VECTOR_UACCUM:
3725 enum machine_mode submode = GET_MODE_INNER (mode);
3726 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3728 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3729 units = CONST_VECTOR_NUNITS (x);
3731 for (i = 0; i < units; i++)
3733 rtx elt = CONST_VECTOR_ELT (x, i);
3734 output_constant_pool_2 (submode, elt, i ? subalign : align);