1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
46 #include "langhooks.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
57 #ifdef XCOFF_DEBUGGING_INFO
58 #include "xcoffout.h" /* Needed for external data
59 declarations for e.g. AIX 4.x. */
62 /* The (assembler) name of the first globally-visible object output. */
63 extern GTY(()) const char *first_global_object_name;
64 extern GTY(()) const char *weak_global_object_name;
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
70 struct constant_descriptor_rtx;
71 struct rtx_constant_pool;
73 #define n_deferred_constants (crtl->varasm.deferred_constants)
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 static GTY(()) int const_labelno;
80 /* Carry information from ASM_DECLARE_OBJECT_NAME
81 to ASM_FINISH_DECLARE_OBJECT. */
83 int size_directive_output;
85 /* The last decl for which assemble_variable was called,
86 if it did ASM_DECLARE_OBJECT_NAME.
87 If the last call to assemble_variable didn't do that,
90 tree last_assemble_variable_decl;
92 /* The following global variable indicates if the first basic block
93 in a function belongs to the cold partition or not. */
95 bool first_function_block_is_cold;
97 /* We give all constants their own alias set. Perhaps redundant with
98 MEM_READONLY_P, but pre-dates it. */
100 static alias_set_type const_alias_set;
102 static const char *strip_reg_name (const char *);
103 static int contains_pointers_p (tree);
104 #ifdef ASM_OUTPUT_EXTERNAL
105 static bool incorporeal_function_p (tree);
107 static void decode_addr_const (tree, struct addr_const *);
108 static hashval_t const_desc_hash (const void *);
109 static int const_desc_eq (const void *, const void *);
110 static hashval_t const_hash_1 (const tree);
111 static int compare_constant (const tree, const tree);
112 static tree copy_constant (tree);
113 static void output_constant_def_contents (rtx);
114 static void output_addressed_constants (tree);
115 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
116 static unsigned min_align (unsigned, unsigned);
117 static void globalize_decl (tree);
118 #ifdef BSS_SECTION_ASM_OP
119 #ifdef ASM_OUTPUT_BSS
120 static void asm_output_bss (FILE *, tree, const char *,
121 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
123 #ifdef ASM_OUTPUT_ALIGNED_BSS
124 static void asm_output_aligned_bss (FILE *, tree, const char *,
125 unsigned HOST_WIDE_INT, int)
128 #endif /* BSS_SECTION_ASM_OP */
129 static void mark_weak (tree);
130 static void output_constant_pool (const char *, tree);
132 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 section *text_section;
134 section *data_section;
135 section *readonly_data_section;
136 section *sdata_section;
137 section *ctors_section;
138 section *dtors_section;
139 section *bss_section;
140 section *sbss_section;
142 /* Various forms of common section. All are guaranteed to be nonnull. */
143 section *tls_comm_section;
144 section *comm_section;
145 section *lcomm_section;
147 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
149 section *bss_noswitch_section;
151 /* The section that holds the main exception table, when known. The section
152 is set either by the target's init_sections hook or by the first call to
153 switch_to_exception_section. */
154 section *exception_section;
156 /* The section that holds the DWARF2 frame unwind information, when known.
157 The section is set either by the target's init_sections hook or by the
158 first call to switch_to_eh_frame_section. */
159 section *eh_frame_section;
161 /* asm_out_file's current section. This is NULL if no section has yet
162 been selected or if we lose track of what the current section is. */
165 /* True if code for the current function is currently being directed
166 at the cold section. */
167 bool in_cold_section_p;
169 /* A linked list of all the unnamed sections. */
170 static GTY(()) section *unnamed_sections;
172 /* Return a nonzero value if DECL has a section attribute. */
173 #define IN_NAMED_SECTION(DECL) \
174 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
175 && DECL_SECTION_NAME (DECL) != NULL_TREE)
177 /* Hash table of named sections. */
178 static GTY((param_is (section))) htab_t section_htab;
180 /* A table of object_blocks, indexed by section. */
181 static GTY((param_is (struct object_block))) htab_t object_block_htab;
183 /* The next number to use for internal anchor labels. */
184 static GTY(()) int anchor_labelno;
186 /* A pool of constants that can be shared between functions. */
187 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
191 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map)))
193 static GTY (()) tree emutls_object_type;
194 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
195 macro can be used on them to distinguish the control variable from
196 the initialization template. */
197 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
199 #if !defined (NO_DOT_IN_LABEL)
200 # define EMUTLS_SEPARATOR "."
201 #elif !defined (NO_DOLLAR_IN_LABEL)
202 # define EMUTLS_SEPARATOR "$"
204 # define EMUTLS_SEPARATOR "_"
207 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
208 IDENTIFIER_NODE NAME's name. */
211 prefix_name (const char *prefix, tree name)
213 unsigned plen = strlen (prefix);
214 unsigned nlen = strlen (IDENTIFIER_POINTER (name));
215 char *toname = (char *) alloca (plen + nlen + 1);
217 memcpy (toname, prefix, plen);
218 memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1);
220 return get_identifier (toname);
223 /* Create an identifier for the struct __emutls_object, given an identifier
224 of the DECL_ASSEMBLY_NAME of the original object. */
227 get_emutls_object_name (tree name)
229 const char *prefix = (targetm.emutls.var_prefix
230 ? targetm.emutls.var_prefix
231 : "__emutls_v" EMUTLS_SEPARATOR);
232 return prefix_name (prefix, name);
236 default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED)
238 tree word_type_node, field, next_field;
240 field = build_decl (UNKNOWN_LOCATION,
241 FIELD_DECL, get_identifier ("__templ"), ptr_type_node);
242 DECL_CONTEXT (field) = type;
245 field = build_decl (UNKNOWN_LOCATION,
246 FIELD_DECL, get_identifier ("__offset"),
248 DECL_CONTEXT (field) = type;
249 TREE_CHAIN (field) = next_field;
252 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
253 field = build_decl (UNKNOWN_LOCATION,
254 FIELD_DECL, get_identifier ("__align"),
256 DECL_CONTEXT (field) = type;
257 TREE_CHAIN (field) = next_field;
260 field = build_decl (UNKNOWN_LOCATION,
261 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 (UNKNOWN_LOCATION,
286 TYPE_DECL, type_name, type);
287 TYPE_NAME (type) = type_name;
288 TYPE_FIELDS (type) = field;
294 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
295 This will be used for initializing the emulated tls data area. */
298 get_emutls_init_templ_addr (tree decl)
302 if (targetm.emutls.register_common && !DECL_INITIAL (decl)
303 && !DECL_SECTION_NAME (decl))
304 return null_pointer_node;
306 name = DECL_ASSEMBLER_NAME (decl);
307 if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0])
309 const char *prefix = (targetm.emutls.tmpl_prefix
310 ? targetm.emutls.tmpl_prefix
311 : "__emutls_t" EMUTLS_SEPARATOR);
312 name = prefix_name (prefix, name);
315 to = build_decl (DECL_SOURCE_LOCATION (decl),
316 VAR_DECL, name, TREE_TYPE (decl));
317 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
318 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
319 DECL_ARTIFICIAL (to) = 1;
320 TREE_USED (to) = TREE_USED (decl);
321 TREE_READONLY (to) = 1;
322 DECL_IGNORED_P (to) = 1;
323 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
324 DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl);
326 DECL_WEAK (to) = DECL_WEAK (decl);
327 if (DECL_ONE_ONLY (decl))
329 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
330 TREE_STATIC (to) = TREE_STATIC (decl);
331 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
332 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
335 TREE_STATIC (to) = 1;
337 DECL_INITIAL (to) = DECL_INITIAL (decl);
338 DECL_INITIAL (decl) = NULL;
340 varpool_finalize_decl (to);
341 return build_fold_addr_expr (to);
344 /* When emulating tls, we use a control structure for use by the runtime.
345 Create and return this structure. */
348 emutls_decl (tree decl)
351 struct tree_map *h, in;
354 if (targetm.have_tls || decl == NULL || decl == error_mark_node
355 || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl))
358 /* Look up the object in the hash; return the control structure if
359 it has already been created. */
361 emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0);
363 name = DECL_ASSEMBLER_NAME (decl);
365 /* Note that we use the hash of the decl's name, rather than a hash
366 of the decl's pointer. In emutls_finish we iterate through the
367 hash table, and we want this traversal to be predictable. */
368 in.hash = htab_hash_string (IDENTIFIER_POINTER (name));
370 loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT);
371 h = (struct tree_map *) *loc;
376 to = build_decl (DECL_SOURCE_LOCATION (decl),
377 VAR_DECL, get_emutls_object_name (name),
378 get_emutls_object_type ());
380 h = GGC_NEW (struct tree_map);
384 *(struct tree_map **) loc = h;
386 DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED;
387 DECL_ARTIFICIAL (to) = 1;
388 DECL_IGNORED_P (to) = 1;
389 TREE_READONLY (to) = 0;
390 SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to));
391 if (DECL_ONE_ONLY (decl))
392 make_decl_one_only (to, DECL_ASSEMBLER_NAME (to));
393 DECL_CONTEXT (to) = DECL_CONTEXT (decl);
394 if (targetm.emutls.var_align_fixed)
395 /* If we're not allowed to change the proxy object's
396 alignment, pretend it's been set by the user. */
397 DECL_USER_ALIGN (to) = 1;
400 /* Note that these fields may need to be updated from time to time from
401 the original decl. Consider:
402 extern __thread int i;
403 int foo() { return i; }
405 in which I goes from external to locally defined and initialized. */
407 TREE_STATIC (to) = TREE_STATIC (decl);
408 TREE_USED (to) = TREE_USED (decl);
409 TREE_PUBLIC (to) = TREE_PUBLIC (decl);
410 DECL_EXTERNAL (to) = DECL_EXTERNAL (decl);
411 DECL_COMMON (to) = DECL_COMMON (decl);
412 DECL_WEAK (to) = DECL_WEAK (decl);
413 DECL_VISIBILITY (to) = DECL_VISIBILITY (decl);
419 emutls_common_1 (void **loc, void *xstmts)
421 struct tree_map *h = *(struct tree_map **) loc;
422 tree args, x, *pstmts = (tree *) xstmts;
425 if (! DECL_COMMON (h->base.from)
426 || (DECL_INITIAL (h->base.from)
427 && DECL_INITIAL (h->base.from) != error_mark_node))
430 word_type_node = lang_hooks.types.type_for_mode (word_mode, 1);
432 /* The idea was to call get_emutls_init_templ_addr here, but if we
433 do this and there is an initializer, -fanchor_section loses,
434 because it would be too late to ensure the template is
436 x = null_pointer_node;
437 args = tree_cons (NULL, x, NULL);
438 x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from));
439 args = tree_cons (NULL, x, args);
440 x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from));
441 args = tree_cons (NULL, x, args);
442 x = build_fold_addr_expr (h->to);
443 args = tree_cons (NULL, x, args);
445 x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON];
446 x = build_function_call_expr (UNKNOWN_LOCATION, x, args);
448 append_to_statement_list (x, pstmts);
455 if (targetm.emutls.register_common)
457 tree body = NULL_TREE;
459 if (emutls_htab == NULL)
462 htab_traverse_noresize (emutls_htab, emutls_common_1, &body);
463 if (body == NULL_TREE)
466 cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY);
470 /* Helper routines for maintaining section_htab. */
473 section_entry_eq (const void *p1, const void *p2)
475 const section *old = (const section *) p1;
476 const char *new_name = (const char *) p2;
478 return strcmp (old->named.name, new_name) == 0;
482 section_entry_hash (const void *p)
484 const section *old = (const section *) p;
485 return htab_hash_string (old->named.name);
488 /* Return a hash value for section SECT. */
491 hash_section (section *sect)
493 if (sect->common.flags & SECTION_NAMED)
494 return htab_hash_string (sect->named.name);
495 return sect->common.flags;
498 /* Helper routines for maintaining object_block_htab. */
501 object_block_entry_eq (const void *p1, const void *p2)
503 const struct object_block *old = (const struct object_block *) p1;
504 const section *new_section = (const section *) p2;
506 return old->sect == new_section;
510 object_block_entry_hash (const void *p)
512 const struct object_block *old = (const struct object_block *) p;
513 return hash_section (old->sect);
516 /* Return a new unnamed section with the given fields. */
519 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
524 sect = GGC_NEW (section);
525 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
526 sect->unnamed.callback = callback;
527 sect->unnamed.data = data;
528 sect->unnamed.next = unnamed_sections;
530 unnamed_sections = sect;
534 /* Return a SECTION_NOSWITCH section with the given fields. */
537 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
541 sect = GGC_NEW (section);
542 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
543 sect->noswitch.callback = callback;
548 /* Return the named section structure associated with NAME. Create
549 a new section with the given fields if no such structure exists. */
552 get_section (const char *name, unsigned int flags, tree decl)
554 section *sect, **slot;
557 htab_find_slot_with_hash (section_htab, name,
558 htab_hash_string (name), INSERT);
559 flags |= SECTION_NAMED;
562 sect = GGC_NEW (section);
563 sect->named.common.flags = flags;
564 sect->named.name = ggc_strdup (name);
565 sect->named.decl = decl;
571 if ((sect->common.flags & ~SECTION_DECLARED) != flags
572 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
574 /* Sanity check user variables for flag changes. */
576 decl = sect->named.decl;
578 error ("%+D causes a section type conflict", decl);
584 /* Return true if the current compilation mode benefits from having
585 objects grouped into blocks. */
588 use_object_blocks_p (void)
590 return flag_section_anchors;
593 /* Return the object_block structure for section SECT. Create a new
594 structure if we haven't created one already. Return null if SECT
597 static struct object_block *
598 get_block_for_section (section *sect)
600 struct object_block *block;
606 slot = htab_find_slot_with_hash (object_block_htab, sect,
607 hash_section (sect), INSERT);
608 block = (struct object_block *) *slot;
611 block = (struct object_block *)
612 ggc_alloc_cleared (sizeof (struct object_block));
619 /* Create a symbol with label LABEL and place it at byte offset
620 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
621 is not yet known. LABEL must be a garbage-collected string. */
624 create_block_symbol (const char *label, struct object_block *block,
625 HOST_WIDE_INT offset)
630 /* Create the extended SYMBOL_REF. */
631 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
632 symbol = (rtx) ggc_alloc_zone (size, &rtl_zone);
634 /* Initialize the normal SYMBOL_REF fields. */
635 memset (symbol, 0, size);
636 PUT_CODE (symbol, SYMBOL_REF);
637 PUT_MODE (symbol, Pmode);
638 XSTR (symbol, 0) = label;
639 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
641 /* Initialize the block_symbol stuff. */
642 SYMBOL_REF_BLOCK (symbol) = block;
643 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
649 initialize_cold_section_name (void)
651 const char *stripped_name;
655 gcc_assert (cfun && current_function_decl);
656 if (crtl->subsections.unlikely_text_section_name)
659 dsn = DECL_SECTION_NAME (current_function_decl);
660 if (flag_function_sections && dsn)
662 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
663 memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1);
665 stripped_name = targetm.strip_name_encoding (name);
667 buffer = ACONCAT ((stripped_name, "_unlikely", NULL));
668 crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer);
671 crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
674 /* Tell assembler to switch to unlikely-to-be-executed text section. */
677 unlikely_text_section (void)
681 if (!crtl->subsections.unlikely_text_section_name)
682 initialize_cold_section_name ();
684 return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0);
687 return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0);
690 /* When called within a function context, return true if the function
691 has been assigned a cold text section and if SECT is that section.
692 When called outside a function context, return true if SECT is the
693 default cold section. */
696 unlikely_text_section_p (section *sect)
701 name = crtl->subsections.unlikely_text_section_name;
703 name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME;
707 && SECTION_STYLE (sect) == SECTION_NAMED
708 && strcmp (name, sect->named.name) == 0);
711 /* Return a section with a particular name and with whatever SECTION_*
712 flags section_type_flags deems appropriate. The name of the section
713 is taken from NAME if nonnull, otherwise it is taken from DECL's
714 DECL_SECTION_NAME. DECL is the decl associated with the section
715 (see the section comment for details) and RELOC is as for
716 section_type_flags. */
719 get_named_section (tree decl, const char *name, int reloc)
723 gcc_assert (!decl || DECL_P (decl));
725 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
727 flags = targetm.section_type_flags (decl, name, reloc);
729 return get_section (name, flags, decl);
732 /* If required, set DECL_SECTION_NAME to a unique name. */
735 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
736 int flag_function_or_data_sections)
738 if (DECL_SECTION_NAME (decl) == NULL_TREE
739 && targetm.have_named_sections
740 && (flag_function_or_data_sections
741 || DECL_ONE_ONLY (decl)))
742 targetm.asm_out.unique_section (decl, reloc);
745 #ifdef BSS_SECTION_ASM_OP
747 #ifdef ASM_OUTPUT_BSS
749 /* Utility function for ASM_OUTPUT_BSS for targets to use if
750 they don't support alignments in .bss.
751 ??? It is believed that this function will work in most cases so such
752 support is localized here. */
755 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
757 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
758 unsigned HOST_WIDE_INT rounded)
760 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0);
761 targetm.asm_out.globalize_decl_name (file, decl);
762 switch_to_section (bss_section);
763 #ifdef ASM_DECLARE_OBJECT_NAME
764 last_assemble_variable_decl = decl;
765 ASM_DECLARE_OBJECT_NAME (file, name, decl);
767 /* Standard thing is just output label for the object. */
768 ASM_OUTPUT_LABEL (file, name);
769 #endif /* ASM_DECLARE_OBJECT_NAME */
770 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
775 #ifdef ASM_OUTPUT_ALIGNED_BSS
777 /* Utility function for targets to use in implementing
778 ASM_OUTPUT_ALIGNED_BSS.
779 ??? It is believed that this function will work in most cases so such
780 support is localized here. */
783 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
784 const char *name, unsigned HOST_WIDE_INT size,
787 switch_to_section (bss_section);
788 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
789 #ifdef ASM_DECLARE_OBJECT_NAME
790 last_assemble_variable_decl = decl;
791 ASM_DECLARE_OBJECT_NAME (file, name, decl);
793 /* Standard thing is just output label for the object. */
794 ASM_OUTPUT_LABEL (file, name);
795 #endif /* ASM_DECLARE_OBJECT_NAME */
796 ASM_OUTPUT_SKIP (file, size ? size : 1);
801 #endif /* BSS_SECTION_ASM_OP */
803 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
804 /* Return the hot section for function DECL. Return text_section for
808 hot_function_section (tree decl)
810 if (decl != NULL_TREE
811 && DECL_SECTION_NAME (decl) != NULL_TREE
812 && targetm.have_named_sections)
813 return get_named_section (decl, NULL, 0);
819 /* Return the section for function DECL.
821 If DECL is NULL_TREE, return the text section. We can be passed
822 NULL_TREE under some circumstances by dbxout.c at least. */
825 function_section (tree decl)
829 if (first_function_block_is_cold)
832 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
833 if (decl != NULL_TREE
834 && DECL_SECTION_NAME (decl) != NULL_TREE)
835 return reloc ? unlikely_text_section ()
836 : get_named_section (decl, NULL, 0);
838 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
840 return reloc ? unlikely_text_section () : hot_function_section (decl);
845 current_function_section (void)
847 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
848 if (current_function_decl != NULL_TREE
849 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
850 return in_cold_section_p ? unlikely_text_section ()
851 : get_named_section (current_function_decl,
854 return targetm.asm_out.select_section (current_function_decl,
856 DECL_ALIGN (current_function_decl));
858 return (in_cold_section_p
859 ? unlikely_text_section ()
860 : hot_function_section (current_function_decl));
864 /* Return the read-only data section associated with function DECL. */
867 default_function_rodata_section (tree decl)
869 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
871 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
873 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
879 dot = strchr (name + 1, '.');
882 len = strlen (dot) + 8;
883 rname = (char *) alloca (len);
885 strcpy (rname, ".rodata");
887 return get_section (rname, SECTION_LINKONCE, decl);
889 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
890 else if (DECL_ONE_ONLY (decl)
891 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
893 size_t len = strlen (name) + 1;
894 char *rname = (char *) alloca (len);
896 memcpy (rname, name, len);
898 return get_section (rname, SECTION_LINKONCE, decl);
900 /* For .text.foo we want to use .rodata.foo. */
901 else if (flag_function_sections && flag_data_sections
902 && strncmp (name, ".text.", 6) == 0)
904 size_t len = strlen (name) + 1;
905 char *rname = (char *) alloca (len + 2);
907 memcpy (rname, ".rodata", 7);
908 memcpy (rname + 7, name + 5, len - 5);
909 return get_section (rname, 0, decl);
913 return readonly_data_section;
916 /* Return the read-only data section associated with function DECL
917 for targets where that section should be always the single
918 readonly data section. */
921 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
923 return readonly_data_section;
926 /* Return the section to use for string merging. */
929 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
930 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
931 unsigned int flags ATTRIBUTE_UNUSED)
935 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
936 && TREE_CODE (decl) == STRING_CST
937 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
939 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
940 && TREE_STRING_LENGTH (decl) >= len)
942 enum machine_mode mode;
943 unsigned int modesize;
949 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
950 modesize = GET_MODE_BITSIZE (mode);
951 if (modesize >= 8 && modesize <= 256
952 && (modesize & (modesize - 1)) == 0)
954 if (align < modesize)
957 str = TREE_STRING_POINTER (decl);
958 unit = GET_MODE_SIZE (mode);
960 /* Check for embedded NUL characters. */
961 for (i = 0; i < len; i += unit)
963 for (j = 0; j < unit; j++)
964 if (str[i + j] != '\0')
971 sprintf (name, ".rodata.str%d.%d", modesize / 8,
973 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
974 return get_section (name, flags, NULL);
979 return readonly_data_section;
982 /* Return the section to use for constant merging. */
985 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
986 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
987 unsigned int flags ATTRIBUTE_UNUSED)
989 unsigned int modesize = GET_MODE_BITSIZE (mode);
991 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
997 && (align & (align - 1)) == 0)
1001 sprintf (name, ".rodata.cst%d", (int) (align / 8));
1002 flags |= (align / 8) | SECTION_MERGE;
1003 return get_section (name, flags, NULL);
1005 return readonly_data_section;
1008 /* Given NAME, a putative register name, discard any customary prefixes. */
1011 strip_reg_name (const char *name)
1013 #ifdef REGISTER_PREFIX
1014 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
1015 name += strlen (REGISTER_PREFIX);
1017 if (name[0] == '%' || name[0] == '#')
1022 /* The user has asked for a DECL to have a particular name. Set (or
1023 change) it in such a way that we don't prefix an underscore to
1026 set_user_assembler_name (tree decl, const char *name)
1028 char *starred = (char *) alloca (strlen (name) + 2);
1030 strcpy (starred + 1, name);
1031 change_decl_assembler_name (decl, get_identifier (starred));
1032 SET_DECL_RTL (decl, NULL_RTX);
1035 /* Decode an `asm' spec for a declaration as a register name.
1036 Return the register number, or -1 if nothing specified,
1037 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1038 or -3 if ASMSPEC is `cc' and is not recognized,
1039 or -4 if ASMSPEC is `memory' and is not recognized.
1040 Accept an exact spelling or a decimal number.
1041 Prefixes such as % are optional. */
1044 decode_reg_name (const char *asmspec)
1050 /* Get rid of confusing prefixes. */
1051 asmspec = strip_reg_name (asmspec);
1053 /* Allow a decimal number as a "register name". */
1054 for (i = strlen (asmspec) - 1; i >= 0; i--)
1055 if (! ISDIGIT (asmspec[i]))
1057 if (asmspec[0] != 0 && i < 0)
1060 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
1066 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1068 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1071 #ifdef ADDITIONAL_REGISTER_NAMES
1073 static const struct { const char *const name; const int number; } table[]
1074 = ADDITIONAL_REGISTER_NAMES;
1076 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1077 if (table[i].name[0]
1078 && ! strcmp (asmspec, table[i].name))
1079 return table[i].number;
1081 #endif /* ADDITIONAL_REGISTER_NAMES */
1083 if (!strcmp (asmspec, "memory"))
1086 if (!strcmp (asmspec, "cc"))
1095 /* Return true if DECL's initializer is suitable for a BSS section. */
1098 bss_initializer_p (const_tree decl)
1100 return (DECL_INITIAL (decl) == NULL
1101 || DECL_INITIAL (decl) == error_mark_node
1102 || (flag_zero_initialized_in_bss
1103 /* Leave constant zeroes in .rodata so they
1105 && !TREE_READONLY (decl)
1106 && initializer_zerop (DECL_INITIAL (decl))));
1109 /* Compute the alignment of variable specified by DECL.
1110 DONT_OUTPUT_DATA is from assemble_variable. */
1113 align_variable (tree decl, bool dont_output_data)
1115 unsigned int align = DECL_ALIGN (decl);
1117 /* In the case for initialing an array whose length isn't specified,
1118 where we have not yet been able to do the layout,
1119 figure out the proper alignment now. */
1120 if (dont_output_data && DECL_SIZE (decl) == 0
1121 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1122 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1124 /* Some object file formats have a maximum alignment which they support.
1125 In particular, a.out format supports a maximum alignment of 4. */
1126 if (align > MAX_OFILE_ALIGNMENT)
1128 warning (0, "alignment of %q+D is greater than maximum object "
1129 "file alignment. Using %d", decl,
1130 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1131 align = MAX_OFILE_ALIGNMENT;
1134 /* On some machines, it is good to increase alignment sometimes. */
1135 if (! DECL_USER_ALIGN (decl))
1137 #ifdef DATA_ALIGNMENT
1138 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1139 /* Don't increase alignment too much for TLS variables - TLS space
1141 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1144 #ifdef CONSTANT_ALIGNMENT
1145 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1147 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
1149 /* Don't increase alignment too much for TLS variables - TLS space
1151 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1152 align = const_align;
1157 /* Reset the alignment in case we have made it tighter, so we can benefit
1158 from it in get_pointer_alignment. */
1159 DECL_ALIGN (decl) = align;
1162 /* Return the section into which the given VAR_DECL or CONST_DECL
1163 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1164 section should be used wherever possible. */
1167 get_variable_section (tree decl, bool prefer_noswitch_p)
1169 addr_space_t as = ADDR_SPACE_GENERIC;
1172 if (TREE_TYPE (decl) != error_mark_node)
1173 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1175 if (DECL_COMMON (decl))
1177 /* If the decl has been given an explicit section name, or it resides
1178 in a non-generic address space, then it isn't common, and shouldn't
1179 be handled as such. */
1180 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1181 && ADDR_SPACE_GENERIC_P (as));
1182 if (DECL_THREAD_LOCAL_P (decl))
1183 return tls_comm_section;
1184 /* This cannot be common bss for an emulated TLS object without
1185 a register_common hook. */
1186 else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED
1187 && !targetm.emutls.register_common)
1189 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1190 return comm_section;
1193 if (DECL_INITIAL (decl) == error_mark_node)
1194 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1195 else if (DECL_INITIAL (decl))
1196 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1200 resolve_unique_section (decl, reloc, flag_data_sections);
1201 if (IN_NAMED_SECTION (decl))
1202 return get_named_section (decl, NULL, reloc);
1204 if (ADDR_SPACE_GENERIC_P (as)
1205 && !DECL_THREAD_LOCAL_P (decl)
1206 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1207 && bss_initializer_p (decl))
1209 if (!TREE_PUBLIC (decl))
1210 return lcomm_section;
1211 if (bss_noswitch_section)
1212 return bss_noswitch_section;
1215 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1218 /* Return the block into which object_block DECL should be placed. */
1220 static struct object_block *
1221 get_block_for_decl (tree decl)
1225 if (TREE_CODE (decl) == VAR_DECL)
1227 /* The object must be defined in this translation unit. */
1228 if (DECL_EXTERNAL (decl))
1231 /* There's no point using object blocks for something that is
1232 isolated by definition. */
1233 if (DECL_ONE_ONLY (decl))
1237 /* We can only calculate block offsets if the decl has a known
1239 if (DECL_SIZE_UNIT (decl) == NULL)
1241 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1244 /* Find out which section should contain DECL. We cannot put it into
1245 an object block if it requires a standalone definition. */
1246 if (TREE_CODE (decl) == VAR_DECL)
1247 align_variable (decl, 0);
1248 sect = get_variable_section (decl, true);
1249 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1252 return get_block_for_section (sect);
1255 /* Make sure block symbol SYMBOL is in block BLOCK. */
1258 change_symbol_block (rtx symbol, struct object_block *block)
1260 if (block != SYMBOL_REF_BLOCK (symbol))
1262 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1263 SYMBOL_REF_BLOCK (symbol) = block;
1267 /* Return true if it is possible to put DECL in an object_block. */
1270 use_blocks_for_decl_p (tree decl)
1272 /* Only data DECLs can be placed into object blocks. */
1273 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1276 /* Detect decls created by dw2_force_const_mem. Such decls are
1277 special because DECL_INITIAL doesn't specify the decl's true value.
1278 dw2_output_indirect_constants will instead call assemble_variable
1279 with dont_output_data set to 1 and then print the contents itself. */
1280 if (DECL_INITIAL (decl) == decl)
1283 /* If this decl is an alias, then we don't want to emit a definition. */
1284 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1290 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1291 have static storage duration. In other words, it should not be an
1292 automatic variable, including PARM_DECLs.
1294 There is, however, one exception: this function handles variables
1295 explicitly placed in a particular register by the user.
1297 This is never called for PARM_DECL nodes. */
1300 make_decl_rtl (tree decl)
1302 const char *name = 0;
1306 /* Check that we are not being given an automatic variable. */
1307 gcc_assert (TREE_CODE (decl) != PARM_DECL
1308 && TREE_CODE (decl) != RESULT_DECL);
1310 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1311 gcc_assert (TREE_CODE (decl) != VAR_DECL
1312 || TREE_STATIC (decl)
1313 || TREE_PUBLIC (decl)
1314 || DECL_EXTERNAL (decl)
1315 || DECL_REGISTER (decl));
1317 /* And that we were not given a type or a label. */
1318 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1319 && TREE_CODE (decl) != LABEL_DECL);
1321 /* For a duplicate declaration, we can be called twice on the
1322 same DECL node. Don't discard the RTL already made. */
1323 if (DECL_RTL_SET_P (decl))
1325 /* If the old RTL had the wrong mode, fix the mode. */
1326 x = DECL_RTL (decl);
1327 if (GET_MODE (x) != DECL_MODE (decl))
1328 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1330 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1333 /* ??? Another way to do this would be to maintain a hashed
1334 table of such critters. Instead of adding stuff to a DECL
1335 to give certain attributes to it, we could use an external
1336 hash map from DECL to set of attributes. */
1338 /* Let the target reassign the RTL if it wants.
1339 This is necessary, for example, when one machine specific
1340 decl attribute overrides another. */
1341 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1343 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1344 on the new decl information. */
1346 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1347 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1348 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1350 /* Make this function static known to the mudflap runtime. */
1351 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1352 mudflap_enqueue_decl (decl);
1357 /* If this variable belongs to the global constant pool, retrieve the
1358 pre-computed RTL or recompute it in LTO mode. */
1359 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1361 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1365 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1367 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1368 && DECL_REGISTER (decl))
1370 error ("register name not specified for %q+D", decl);
1372 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1374 const char *asmspec = name+1;
1375 reg_number = decode_reg_name (asmspec);
1376 /* First detect errors in declaring global registers. */
1377 if (reg_number == -1)
1378 error ("register name not specified for %q+D", decl);
1379 else if (reg_number < 0)
1380 error ("invalid register name for %q+D", decl);
1381 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1382 error ("data type of %q+D isn%'t suitable for a register",
1384 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1385 error ("register specified for %q+D isn%'t suitable for data type",
1387 /* Now handle properly declared static register variables. */
1392 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1394 DECL_INITIAL (decl) = 0;
1395 error ("global register variable has initial value");
1397 if (TREE_THIS_VOLATILE (decl))
1398 warning (OPT_Wvolatile_register_var,
1399 "optimization may eliminate reads and/or "
1400 "writes to register variables");
1402 /* If the user specified one of the eliminables registers here,
1403 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1404 confused with that register and be eliminated. This usage is
1405 somewhat suspect... */
1407 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1408 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1409 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1411 if (TREE_STATIC (decl))
1413 /* Make this register global, so not usable for anything
1415 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1416 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1417 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1419 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1421 globalize_reg (reg_number + --nregs);
1424 /* As a register variable, it has no section. */
1428 /* Now handle ordinary static variables and functions (in memory).
1429 Also handle vars declared register invalidly. */
1430 else if (name[0] == '*')
1432 #ifdef REGISTER_PREFIX
1433 if (strlen (REGISTER_PREFIX) != 0)
1435 reg_number = decode_reg_name (name);
1436 if (reg_number >= 0 || reg_number == -3)
1437 error ("register name given for non-register variable %q+D", decl);
1442 /* Specifying a section attribute on a variable forces it into a
1443 non-.bss section, and thus it cannot be common. */
1444 /* FIXME: In general this code should not be necessary because
1445 visibility pass is doing the same work. But notice_global_symbol
1446 is called early and it needs to make DECL_RTL to get the name.
1447 we take care of recomputing the DECL_RTL after visibility is changed. */
1448 if (TREE_CODE (decl) == VAR_DECL
1449 && DECL_SECTION_NAME (decl) != NULL_TREE
1450 && DECL_INITIAL (decl) == NULL_TREE
1451 && DECL_COMMON (decl))
1452 DECL_COMMON (decl) = 0;
1454 /* Variables can't be both common and weak. */
1455 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1456 DECL_COMMON (decl) = 0;
1458 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1459 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1462 enum machine_mode address_mode = Pmode;
1463 if (TREE_TYPE (decl) != error_mark_node)
1465 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1466 address_mode = targetm.addr_space.address_mode (as);
1468 x = gen_rtx_SYMBOL_REF (address_mode, name);
1470 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1471 SET_SYMBOL_REF_DECL (x, decl);
1473 x = gen_rtx_MEM (DECL_MODE (decl), x);
1474 if (TREE_CODE (decl) != FUNCTION_DECL)
1475 set_mem_attributes (x, decl, 1);
1476 SET_DECL_RTL (decl, x);
1478 /* Optionally set flags or add text to the name to record information
1479 such as that it is a function name.
1480 If the name is changed, the macro ASM_OUTPUT_LABELREF
1481 will have to know how to strip this information. */
1482 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1484 /* Make this function static known to the mudflap runtime. */
1485 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1486 mudflap_enqueue_decl (decl);
1489 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1490 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1494 make_decl_rtl_for_debug (tree decl)
1496 unsigned int save_aliasing_flag, save_mudflap_flag;
1499 if (DECL_RTL_SET_P (decl))
1500 return DECL_RTL (decl);
1502 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1503 call new_alias_set. If running with -fcompare-debug, sometimes
1504 we do not want to create alias sets that will throw the alias
1505 numbers off in the comparison dumps. So... clearing
1506 flag_strict_aliasing will keep new_alias_set() from creating a
1507 new set. It is undesirable to register decl with mudflap
1508 in this case as well. */
1509 save_aliasing_flag = flag_strict_aliasing;
1510 flag_strict_aliasing = 0;
1511 save_mudflap_flag = flag_mudflap;
1514 rtl = DECL_RTL (decl);
1515 /* Reset DECL_RTL back, as various parts of the compiler expects
1516 DECL_RTL set meaning it is actually going to be output. */
1517 SET_DECL_RTL (decl, NULL);
1519 flag_strict_aliasing = save_aliasing_flag;
1520 flag_mudflap = save_mudflap_flag;
1525 /* Output a string of literal assembler code
1526 for an `asm' keyword used between functions. */
1529 assemble_asm (tree string)
1533 if (TREE_CODE (string) == ADDR_EXPR)
1534 string = TREE_OPERAND (string, 0);
1536 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1539 /* Record an element in the table of global destructors. SYMBOL is
1540 a SYMBOL_REF of the function to be called; PRIORITY is a number
1541 between 0 and MAX_INIT_PRIORITY. */
1544 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1545 int priority ATTRIBUTE_UNUSED)
1547 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1548 /* Tell GNU LD that this is part of the static destructor set.
1549 This will work for any system that uses stabs, most usefully
1551 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1552 dbxout_stab_value_label (XSTR (symbol, 0));
1554 sorry ("global destructors not supported on this target");
1558 /* Write the address of the entity given by SYMBOL to SEC. */
1560 assemble_addr_to_section (rtx symbol, section *sec)
1562 switch_to_section (sec);
1563 assemble_align (POINTER_SIZE);
1564 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1567 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1568 not) section for PRIORITY. */
1570 get_cdtor_priority_section (int priority, bool constructor_p)
1574 /* ??? This only works reliably with the GNU linker. */
1575 sprintf (buf, "%s.%.5u",
1576 constructor_p ? ".ctors" : ".dtors",
1577 /* Invert the numbering so the linker puts us in the proper
1578 order; constructors are run from right to left, and the
1579 linker sorts in increasing order. */
1580 MAX_INIT_PRIORITY - priority);
1581 return get_section (buf, SECTION_WRITE, NULL);
1585 default_named_section_asm_out_destructor (rtx symbol, int priority)
1589 if (priority != DEFAULT_INIT_PRIORITY)
1590 sec = get_cdtor_priority_section (priority,
1591 /*constructor_p=*/false);
1593 sec = get_section (".dtors", SECTION_WRITE, NULL);
1595 assemble_addr_to_section (symbol, sec);
1598 #ifdef DTORS_SECTION_ASM_OP
1600 default_dtor_section_asm_out_destructor (rtx symbol,
1601 int priority ATTRIBUTE_UNUSED)
1603 assemble_addr_to_section (symbol, dtors_section);
1607 /* Likewise for global constructors. */
1610 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1611 int priority ATTRIBUTE_UNUSED)
1613 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1614 /* Tell GNU LD that this is part of the static destructor set.
1615 This will work for any system that uses stabs, most usefully
1617 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1618 dbxout_stab_value_label (XSTR (symbol, 0));
1620 sorry ("global constructors not supported on this target");
1625 default_named_section_asm_out_constructor (rtx symbol, int priority)
1629 if (priority != DEFAULT_INIT_PRIORITY)
1630 sec = get_cdtor_priority_section (priority,
1631 /*constructor_p=*/true);
1633 sec = get_section (".ctors", SECTION_WRITE, NULL);
1635 assemble_addr_to_section (symbol, sec);
1638 #ifdef CTORS_SECTION_ASM_OP
1640 default_ctor_section_asm_out_constructor (rtx symbol,
1641 int priority ATTRIBUTE_UNUSED)
1643 assemble_addr_to_section (symbol, ctors_section);
1647 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1648 a nonzero value if the constant pool should be output before the
1649 start of the function, or a zero value if the pool should output
1650 after the end of the function. The default is to put it before the
1653 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1654 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1657 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1658 to be output to assembler.
1659 Set first_global_object_name and weak_global_object_name as appropriate. */
1662 notice_global_symbol (tree decl)
1664 const char **type = &first_global_object_name;
1666 if (first_global_object_name
1667 || !TREE_PUBLIC (decl)
1668 || DECL_EXTERNAL (decl)
1669 || !DECL_NAME (decl)
1670 || (TREE_CODE (decl) != FUNCTION_DECL
1671 && (TREE_CODE (decl) != VAR_DECL
1672 || (DECL_COMMON (decl)
1673 && (DECL_INITIAL (decl) == 0
1674 || DECL_INITIAL (decl) == error_mark_node))))
1675 || !MEM_P (DECL_RTL (decl)))
1678 /* We win when global object is found, but it is useful to know about weak
1679 symbol as well so we can produce nicer unique names. */
1680 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1681 type = &weak_global_object_name;
1687 rtx decl_rtl = DECL_RTL (decl);
1689 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1690 name = ggc_strdup (p);
1696 /* Output assembler code for the constant pool of a function and associated
1697 with defining the name of the function. DECL describes the function.
1698 NAME is the function's name. For the constant pool, we use the current
1699 constant pool data. */
1702 assemble_start_function (tree decl, const char *fnname)
1705 char tmp_label[100];
1706 bool hot_label_written = false;
1708 crtl->subsections.unlikely_text_section_name = NULL;
1710 first_function_block_is_cold = false;
1711 if (flag_reorder_blocks_and_partition)
1713 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1714 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1715 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1716 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1717 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1718 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1719 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1720 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1725 crtl->subsections.hot_section_label = NULL;
1726 crtl->subsections.cold_section_label = NULL;
1727 crtl->subsections.hot_section_end_label = NULL;
1728 crtl->subsections.cold_section_end_label = NULL;
1731 /* The following code does not need preprocessing in the assembler. */
1735 if (CONSTANT_POOL_BEFORE_FUNCTION)
1736 output_constant_pool (fnname, decl);
1738 resolve_unique_section (decl, 0, flag_function_sections);
1740 /* Make sure the not and cold text (code) sections are properly
1741 aligned. This is necessary here in the case where the function
1742 has both hot and cold sections, because we don't want to re-set
1743 the alignment when the section switch happens mid-function. */
1745 if (flag_reorder_blocks_and_partition)
1747 switch_to_section (unlikely_text_section ());
1748 assemble_align (DECL_ALIGN (decl));
1749 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1751 /* When the function starts with a cold section, we need to explicitly
1752 align the hot section and write out the hot section label.
1753 But if the current function is a thunk, we do not have a CFG. */
1755 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1757 switch_to_section (text_section);
1758 assemble_align (DECL_ALIGN (decl));
1759 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1760 hot_label_written = true;
1761 first_function_block_is_cold = true;
1764 else if (DECL_SECTION_NAME (decl))
1766 /* Calls to function_section rely on first_function_block_is_cold
1767 being accurate. The first block may be cold even if we aren't
1768 doing partitioning, if the entire function was decided by
1769 choose_function_section (predict.c) to be cold. */
1771 initialize_cold_section_name ();
1773 if (crtl->subsections.unlikely_text_section_name
1774 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)),
1775 crtl->subsections.unlikely_text_section_name) == 0)
1776 first_function_block_is_cold = true;
1779 in_cold_section_p = first_function_block_is_cold;
1781 /* Switch to the correct text section for the start of the function. */
1783 switch_to_section (function_section (decl));
1784 if (flag_reorder_blocks_and_partition
1785 && !hot_label_written)
1786 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1788 /* Tell assembler to move to target machine's alignment for functions. */
1789 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1792 ASM_OUTPUT_ALIGN (asm_out_file, align);
1795 /* Handle a user-specified function alignment.
1796 Note that we still need to align to DECL_ALIGN, as above,
1797 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1798 if (! DECL_USER_ALIGN (decl)
1799 && align_functions_log > align
1800 && optimize_function_for_speed_p (cfun))
1802 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1803 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1804 align_functions_log, align_functions - 1);
1806 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1810 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1811 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1814 if (!DECL_IGNORED_P (decl))
1815 (*debug_hooks->begin_function) (decl);
1817 /* Make function name accessible from other files, if appropriate. */
1819 if (TREE_PUBLIC (decl))
1821 notice_global_symbol (decl);
1823 globalize_decl (decl);
1825 maybe_assemble_visibility (decl);
1828 if (DECL_PRESERVE_P (decl))
1829 targetm.asm_out.mark_decl_preserved (fnname);
1831 /* Do any machine/system dependent processing of the function name. */
1832 #ifdef ASM_DECLARE_FUNCTION_NAME
1833 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1835 /* Standard thing is just output label for the function. */
1836 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1837 #endif /* ASM_DECLARE_FUNCTION_NAME */
1840 /* Output assembler code associated with defining the size of the
1841 function. DECL describes the function. NAME is the function's name. */
1844 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1846 #ifdef ASM_DECLARE_FUNCTION_SIZE
1847 /* We could have switched section in the middle of the function. */
1848 if (flag_reorder_blocks_and_partition)
1849 switch_to_section (function_section (decl));
1850 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1852 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1854 output_constant_pool (fnname, decl);
1855 switch_to_section (function_section (decl)); /* need to switch back */
1857 /* Output labels for end of hot/cold text sections (to be used by
1859 if (flag_reorder_blocks_and_partition)
1861 section *save_text_section;
1863 save_text_section = in_section;
1864 switch_to_section (unlikely_text_section ());
1865 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1866 if (first_function_block_is_cold)
1867 switch_to_section (text_section);
1869 switch_to_section (function_section (decl));
1870 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1871 switch_to_section (save_text_section);
1875 /* Assemble code to leave SIZE bytes of zeros. */
1878 assemble_zeros (unsigned HOST_WIDE_INT size)
1880 /* Do no output if -fsyntax-only. */
1881 if (flag_syntax_only)
1884 #ifdef ASM_NO_SKIP_IN_TEXT
1885 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1886 so we must output 0s explicitly in the text section. */
1887 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1889 unsigned HOST_WIDE_INT i;
1890 for (i = 0; i < size; i++)
1891 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1896 ASM_OUTPUT_SKIP (asm_out_file, size);
1899 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1902 assemble_align (int align)
1904 if (align > BITS_PER_UNIT)
1906 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1910 /* Assemble a string constant with the specified C string as contents. */
1913 assemble_string (const char *p, int size)
1918 /* If the string is very long, split it up. */
1922 int thissize = size - pos;
1923 if (thissize > maximum)
1926 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1934 /* A noswitch_section_callback for lcomm_section. */
1937 emit_local (tree decl ATTRIBUTE_UNUSED,
1938 const char *name ATTRIBUTE_UNUSED,
1939 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1940 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1942 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1943 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1944 size, DECL_ALIGN (decl));
1946 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1947 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1950 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1955 /* A noswitch_section_callback for bss_noswitch_section. */
1957 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1959 emit_bss (tree decl ATTRIBUTE_UNUSED,
1960 const char *name ATTRIBUTE_UNUSED,
1961 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1962 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1964 #if defined ASM_OUTPUT_ALIGNED_BSS
1965 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1968 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1974 /* A noswitch_section_callback for comm_section. */
1977 emit_common (tree decl ATTRIBUTE_UNUSED,
1978 const char *name ATTRIBUTE_UNUSED,
1979 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1980 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1982 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1983 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1984 size, DECL_ALIGN (decl));
1986 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1987 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1990 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1995 /* A noswitch_section_callback for tls_comm_section. */
1998 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1999 const char *name ATTRIBUTE_UNUSED,
2000 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2001 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2003 #ifdef ASM_OUTPUT_TLS_COMMON
2004 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2007 sorry ("thread-local COMMON data not implemented");
2012 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2013 NAME is the name of DECL's SYMBOL_REF. */
2016 assemble_noswitch_variable (tree decl, const char *name, section *sect)
2018 unsigned HOST_WIDE_INT size, rounded;
2020 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
2023 /* Don't allocate zero bytes of common,
2024 since that means "undefined external" in the linker. */
2028 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2029 so that each uninitialized object starts on such a boundary. */
2030 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2031 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2032 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2034 if (!sect->noswitch.callback (decl, name, size, rounded)
2035 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
2036 warning (0, "requested alignment for %q+D is greater than "
2037 "implemented alignment of %wu", decl, rounded);
2040 /* A subroutine of assemble_variable. Output the label and contents of
2041 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2042 is as for assemble_variable. */
2045 assemble_variable_contents (tree decl, const char *name,
2046 bool dont_output_data)
2048 /* Do any machine/system dependent processing of the object. */
2049 #ifdef ASM_DECLARE_OBJECT_NAME
2050 last_assemble_variable_decl = decl;
2051 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2053 /* Standard thing is just output label for the object. */
2054 ASM_OUTPUT_LABEL (asm_out_file, name);
2055 #endif /* ASM_DECLARE_OBJECT_NAME */
2057 if (!dont_output_data)
2059 if (DECL_INITIAL (decl)
2060 && DECL_INITIAL (decl) != error_mark_node
2061 && !initializer_zerop (DECL_INITIAL (decl)))
2062 /* Output the actual data. */
2063 output_constant (DECL_INITIAL (decl),
2064 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
2067 /* Leave space for it. */
2068 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
2072 /* Initialize emulated tls object TO, which refers to TLS variable
2073 DECL and is initialized by PROXY. */
2076 default_emutls_var_init (tree to, tree decl, tree proxy)
2078 VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4);
2079 constructor_elt *elt;
2080 tree type = TREE_TYPE (to);
2081 tree field = TYPE_FIELDS (type);
2083 elt = VEC_quick_push (constructor_elt, v, NULL);
2085 elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
2087 elt = VEC_quick_push (constructor_elt, v, NULL);
2088 field = TREE_CHAIN (field);
2090 elt->value = build_int_cst (TREE_TYPE (field),
2091 DECL_ALIGN_UNIT (decl));
2093 elt = VEC_quick_push (constructor_elt, v, NULL);
2094 field = TREE_CHAIN (field);
2096 elt->value = null_pointer_node;
2098 elt = VEC_quick_push (constructor_elt, v, NULL);
2099 field = TREE_CHAIN (field);
2103 return build_constructor (type, v);
2106 /* Assemble everything that is needed for a variable or function declaration.
2107 Not used for automatic variables, and not used for function definitions.
2108 Should not be called for variables of incomplete structure type.
2110 TOP_LEVEL is nonzero if this variable has file scope.
2111 AT_END is nonzero if this is the special handling, at end of compilation,
2112 to define things that have had only tentative definitions.
2113 DONT_OUTPUT_DATA if nonzero means don't actually output the
2114 initial value (that will be done by the caller). */
2117 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2118 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2121 rtx decl_rtl, symbol;
2124 if (! targetm.have_tls
2125 && TREE_CODE (decl) == VAR_DECL
2126 && DECL_THREAD_LOCAL_P (decl))
2128 tree to = emutls_decl (decl);
2130 /* If this variable is defined locally, then we need to initialize the
2131 control structure with size and alignment information. We do this
2132 at the last moment because tentative definitions can take a locally
2133 defined but uninitialized variable and initialize it later, which
2134 would result in incorrect contents. */
2135 if (! DECL_EXTERNAL (to)
2136 && (! DECL_COMMON (to)
2137 || (DECL_INITIAL (decl)
2138 && DECL_INITIAL (decl) != error_mark_node)))
2140 DECL_INITIAL (to) = targetm.emutls.var_init
2141 (to, decl, get_emutls_init_templ_addr (decl));
2143 /* Make sure the template is marked as needed early enough.
2144 Without this, if the variable is placed in a
2145 section-anchored block, the template will only be marked
2146 when it's too late. */
2147 record_references_in_initializer (to, false);
2153 last_assemble_variable_decl = 0;
2155 /* Normally no need to say anything here for external references,
2156 since assemble_external is called by the language-specific code
2157 when a declaration is first seen. */
2159 if (DECL_EXTERNAL (decl))
2162 /* Output no assembler code for a function declaration.
2163 Only definitions of functions output anything. */
2165 if (TREE_CODE (decl) == FUNCTION_DECL)
2168 /* Do nothing for global register variables. */
2169 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2171 TREE_ASM_WRITTEN (decl) = 1;
2175 /* If type was incomplete when the variable was declared,
2176 see if it is complete now. */
2178 if (DECL_SIZE (decl) == 0)
2179 layout_decl (decl, 0);
2181 /* Still incomplete => don't allocate it; treat the tentative defn
2182 (which is what it must have been) as an `extern' reference. */
2184 if (!dont_output_data && DECL_SIZE (decl) == 0)
2186 error ("storage size of %q+D isn%'t known", decl);
2187 TREE_ASM_WRITTEN (decl) = 1;
2191 /* The first declaration of a variable that comes through this function
2192 decides whether it is global (in C, has external linkage)
2193 or local (in C, has internal linkage). So do nothing more
2194 if this function has already run. */
2196 if (TREE_ASM_WRITTEN (decl))
2199 /* Make sure targetm.encode_section_info is invoked before we set
2201 decl_rtl = DECL_RTL (decl);
2203 TREE_ASM_WRITTEN (decl) = 1;
2205 /* Do no output if -fsyntax-only. */
2206 if (flag_syntax_only)
2209 if (! dont_output_data
2210 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
2212 error ("size of variable %q+D is too large", decl);
2216 gcc_assert (MEM_P (decl_rtl));
2217 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2218 symbol = XEXP (decl_rtl, 0);
2220 /* If this symbol belongs to the tree constant pool, output the constant
2221 if it hasn't already been written. */
2222 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2224 tree decl = SYMBOL_REF_DECL (symbol);
2225 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2226 output_constant_def_contents (symbol);
2232 name = XSTR (symbol, 0);
2233 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2234 notice_global_symbol (decl);
2236 /* Compute the alignment of this data. */
2238 align_variable (decl, dont_output_data);
2239 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2241 if (TREE_PUBLIC (decl))
2242 maybe_assemble_visibility (decl);
2244 if (DECL_PRESERVE_P (decl))
2245 targetm.asm_out.mark_decl_preserved (name);
2247 /* First make the assembler name(s) global if appropriate. */
2248 sect = get_variable_section (decl, false);
2249 if (TREE_PUBLIC (decl)
2250 && (sect->common.flags & SECTION_COMMON) == 0)
2251 globalize_decl (decl);
2253 /* Output any data that we will need to use the address of. */
2254 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2255 output_addressed_constants (DECL_INITIAL (decl));
2257 /* dbxout.c needs to know this. */
2258 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2259 DECL_IN_TEXT_SECTION (decl) = 1;
2261 /* If the decl is part of an object_block, make sure that the decl
2262 has been positioned within its block, but do not write out its
2263 definition yet. output_object_blocks will do that later. */
2264 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2266 gcc_assert (!dont_output_data);
2267 place_block_symbol (symbol);
2269 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2270 assemble_noswitch_variable (decl, name, sect);
2273 switch_to_section (sect);
2274 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2275 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2276 assemble_variable_contents (decl, name, dont_output_data);
2280 /* Return 1 if type TYPE contains any pointers. */
2283 contains_pointers_p (tree type)
2285 switch (TREE_CODE (type))
2288 case REFERENCE_TYPE:
2289 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2290 so I'll play safe and return 1. */
2296 case QUAL_UNION_TYPE:
2299 /* For a type that has fields, see if the fields have pointers. */
2300 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
2301 if (TREE_CODE (fields) == FIELD_DECL
2302 && contains_pointers_p (TREE_TYPE (fields)))
2308 /* An array type contains pointers if its element type does. */
2309 return contains_pointers_p (TREE_TYPE (type));
2316 /* We delay assemble_external processing until
2317 the compilation unit is finalized. This is the best we can do for
2318 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2319 it all the way to final. See PR 17982 for further discussion. */
2320 static GTY(()) tree pending_assemble_externals;
2322 #ifdef ASM_OUTPUT_EXTERNAL
2323 /* True if DECL is a function decl for which no out-of-line copy exists.
2324 It is assumed that DECL's assembler name has been set. */
2327 incorporeal_function_p (tree decl)
2329 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2333 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2334 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
2337 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2338 if (is_builtin_name (name))
2344 /* Actually do the tests to determine if this is necessary, and invoke
2345 ASM_OUTPUT_EXTERNAL. */
2347 assemble_external_real (tree decl)
2349 rtx rtl = DECL_RTL (decl);
2351 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2352 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2353 && !incorporeal_function_p (decl))
2355 /* Some systems do require some output. */
2356 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2357 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2363 process_pending_assemble_externals (void)
2365 #ifdef ASM_OUTPUT_EXTERNAL
2367 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2368 assemble_external_real (TREE_VALUE (list));
2370 pending_assemble_externals = 0;
2374 /* This TREE_LIST contains any weak symbol declarations waiting
2376 static GTY(()) tree weak_decls;
2378 /* Output something to declare an external symbol to the assembler,
2379 and qualifiers such as weakness. (Most assemblers don't need
2380 extern declaration, so we normally output nothing.) Do nothing if
2381 DECL is not external. */
2384 assemble_external (tree decl ATTRIBUTE_UNUSED)
2386 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2387 main body of this code is only rarely exercised. To provide some
2388 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2389 open. If it's not, we should not be calling this function. */
2390 gcc_assert (asm_out_file);
2392 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2395 /* We want to output annotation for weak and external symbols at
2396 very last to check if they are references or not. */
2400 /* TREE_STATIC is a weird and abused creature which is not
2401 generally the right test for whether an entity has been
2402 locally emitted, inlined or otherwise not-really-extern, but
2403 for declarations that can be weak, it happens to be
2405 && !TREE_STATIC (decl)
2406 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2407 && value_member (decl, weak_decls) == NULL_TREE)
2408 weak_decls = tree_cons (NULL, decl, weak_decls);
2410 #ifdef ASM_OUTPUT_EXTERNAL
2411 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2412 pending_assemble_externals = tree_cons (NULL, decl,
2413 pending_assemble_externals);
2417 /* Similar, for calling a library function FUN. */
2420 assemble_external_libcall (rtx fun)
2422 /* Declare library function name external when first used, if nec. */
2423 if (! SYMBOL_REF_USED (fun))
2425 SYMBOL_REF_USED (fun) = 1;
2426 targetm.asm_out.external_libcall (fun);
2430 /* Assemble a label named NAME. */
2433 assemble_label (const char *name)
2435 ASM_OUTPUT_LABEL (asm_out_file, name);
2438 /* Set the symbol_referenced flag for ID. */
2440 mark_referenced (tree id)
2442 TREE_SYMBOL_REFERENCED (id) = 1;
2445 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2447 mark_decl_referenced (tree decl)
2449 if (TREE_CODE (decl) == FUNCTION_DECL)
2451 /* Extern inline functions don't become needed when referenced.
2452 If we know a method will be emitted in other TU and no new
2453 functions can be marked reachable, just use the external
2455 struct cgraph_node *node = cgraph_node (decl);
2456 if (!DECL_EXTERNAL (decl)
2457 && (!node->local.vtable_method || !cgraph_global_info_ready
2458 || !node->local.finalized))
2459 cgraph_mark_needed_node (node);
2461 else if (TREE_CODE (decl) == VAR_DECL)
2463 struct varpool_node *node = varpool_node (decl);
2464 varpool_mark_needed_node (node);
2465 /* C++ frontend use mark_decl_references to force COMDAT variables
2466 to be output that might appear dead otherwise. */
2467 node->force_output = true;
2469 /* else do nothing - we can get various sorts of CST nodes here,
2470 which do not need to be marked. */
2474 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2475 until we find an identifier that is not itself a transparent alias.
2476 Modify the alias passed to it by reference (and all aliases on the
2477 way to the ultimate target), such that they do not have to be
2478 followed again, and return the ultimate target of the alias
2482 ultimate_transparent_alias_target (tree *alias)
2484 tree target = *alias;
2486 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2488 gcc_assert (TREE_CHAIN (target));
2489 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2490 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2491 && ! TREE_CHAIN (target));
2498 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2499 starts with a *, the rest of NAME is output verbatim. Otherwise
2500 NAME is transformed in a target-specific way (usually by the
2501 addition of an underscore). */
2504 assemble_name_raw (FILE *file, const char *name)
2507 fputs (&name[1], file);
2509 ASM_OUTPUT_LABELREF (file, name);
2512 /* Like assemble_name_raw, but should be used when NAME might refer to
2513 an entity that is also represented as a tree (like a function or
2514 variable). If NAME does refer to such an entity, that entity will
2515 be marked as referenced. */
2518 assemble_name (FILE *file, const char *name)
2520 const char *real_name;
2523 real_name = targetm.strip_name_encoding (name);
2525 id = maybe_get_identifier (real_name);
2530 mark_referenced (id);
2531 ultimate_transparent_alias_target (&id);
2533 name = IDENTIFIER_POINTER (id);
2534 gcc_assert (! TREE_CHAIN (id));
2537 assemble_name_raw (file, name);
2540 /* Allocate SIZE bytes writable static space with a gensym name
2541 and return an RTX to refer to its address. */
2544 assemble_static_space (unsigned HOST_WIDE_INT size)
2547 const char *namestring;
2550 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2552 namestring = ggc_strdup (name);
2554 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2555 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2557 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2558 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2561 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2562 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2565 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2566 so that each uninitialized object starts on such a boundary. */
2567 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2568 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2569 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2570 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2571 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2572 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2579 /* Assemble the static constant template for function entry trampolines.
2580 This is done at most once per compilation.
2581 Returns an RTX for the address of the template. */
2583 static GTY(()) rtx initial_trampoline;
2586 assemble_trampoline_template (void)
2593 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2595 if (initial_trampoline)
2596 return initial_trampoline;
2598 /* By default, put trampoline templates in read-only data section. */
2600 #ifdef TRAMPOLINE_SECTION
2601 switch_to_section (TRAMPOLINE_SECTION);
2603 switch_to_section (readonly_data_section);
2606 /* Write the assembler code to define one. */
2607 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2609 ASM_OUTPUT_ALIGN (asm_out_file, align);
2611 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2612 targetm.asm_out.trampoline_template (asm_out_file);
2614 /* Record the rtl to refer to it. */
2615 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2616 name = ggc_strdup (label);
2617 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2618 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2620 initial_trampoline = gen_const_mem (BLKmode, symbol);
2621 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2622 set_mem_size (initial_trampoline, GEN_INT (TRAMPOLINE_SIZE));
2624 return initial_trampoline;
2627 /* A and B are either alignments or offsets. Return the minimum alignment
2628 that may be assumed after adding the two together. */
2630 static inline unsigned
2631 min_align (unsigned int a, unsigned int b)
2633 return (a | b) & -(a | b);
2636 /* Return the assembler directive for creating a given kind of integer
2637 object. SIZE is the number of bytes in the object and ALIGNED_P
2638 indicates whether it is known to be aligned. Return NULL if the
2639 assembly dialect has no such directive.
2641 The returned string should be printed at the start of a new line and
2642 be followed immediately by the object's initial value. */
2645 integer_asm_op (int size, int aligned_p)
2647 struct asm_int_op *ops;
2650 ops = &targetm.asm_out.aligned_op;
2652 ops = &targetm.asm_out.unaligned_op;
2657 return targetm.asm_out.byte_op;
2671 /* Use directive OP to assemble an integer object X. Print OP at the
2672 start of the line, followed immediately by the value of X. */
2675 assemble_integer_with_op (const char *op, rtx x)
2677 fputs (op, asm_out_file);
2678 output_addr_const (asm_out_file, x);
2679 fputc ('\n', asm_out_file);
2682 /* The default implementation of the asm_out.integer target hook. */
2685 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2686 unsigned int size ATTRIBUTE_UNUSED,
2687 int aligned_p ATTRIBUTE_UNUSED)
2689 const char *op = integer_asm_op (size, aligned_p);
2690 /* Avoid GAS bugs for large values. Specifically negative values whose
2691 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2692 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2694 return op && (assemble_integer_with_op (op, x), true);
2697 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2698 the alignment of the integer in bits. Return 1 if we were able to output
2699 the constant, otherwise 0. We must be able to output the constant,
2700 if FORCE is nonzero. */
2703 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2707 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2709 /* See if the target hook can handle this kind of object. */
2710 if (targetm.asm_out.integer (x, size, aligned_p))
2713 /* If the object is a multi-byte one, try splitting it up. Split
2714 it into words it if is multi-word, otherwise split it into bytes. */
2717 enum machine_mode omode, imode;
2718 unsigned int subalign;
2719 unsigned int subsize, i;
2720 enum mode_class mclass;
2722 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2723 subalign = MIN (align, subsize * BITS_PER_UNIT);
2724 if (GET_CODE (x) == CONST_FIXED)
2725 mclass = GET_MODE_CLASS (GET_MODE (x));
2729 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2730 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2732 for (i = 0; i < size; i += subsize)
2734 rtx partial = simplify_subreg (omode, x, imode, i);
2735 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2741 /* If we've printed some of it, but not all of it, there's no going
2746 gcc_assert (!force);
2752 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2754 long data[4] = {0, 0, 0, 0};
2756 int bitsize, nelts, nunits, units_per;
2758 /* This is hairy. We have a quantity of known size. real_to_target
2759 will put it into an array of *host* longs, 32 bits per element
2760 (even if long is more than 32 bits). We need to determine the
2761 number of array elements that are occupied (nelts) and the number
2762 of *target* min-addressable units that will be occupied in the
2763 object file (nunits). We cannot assume that 32 divides the
2764 mode's bitsize (size * BITS_PER_UNIT) evenly.
2766 size * BITS_PER_UNIT is used here to make sure that padding bits
2767 (which might appear at either end of the value; real_to_target
2768 will include the padding bits in its output array) are included. */
2770 nunits = GET_MODE_SIZE (mode);
2771 bitsize = nunits * BITS_PER_UNIT;
2772 nelts = CEIL (bitsize, 32);
2773 units_per = 32 / BITS_PER_UNIT;
2775 real_to_target (data, &d, mode);
2777 /* Put out the first word with the specified alignment. */
2778 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2779 nunits -= units_per;
2781 /* Subsequent words need only 32-bit alignment. */
2782 align = min_align (align, 32);
2784 for (i = 1; i < nelts; i++)
2786 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2787 nunits -= units_per;
2791 /* Given an expression EXP with a constant value,
2792 reduce it to the sum of an assembler symbol and an integer.
2793 Store them both in the structure *VALUE.
2794 EXP must be reducible. */
2796 struct GTY(()) addr_const {
2798 HOST_WIDE_INT offset;
2802 decode_addr_const (tree exp, struct addr_const *value)
2804 tree target = TREE_OPERAND (exp, 0);
2810 if (TREE_CODE (target) == COMPONENT_REF
2811 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2813 offset += int_byte_position (TREE_OPERAND (target, 1));
2814 target = TREE_OPERAND (target, 0);
2816 else if (TREE_CODE (target) == ARRAY_REF
2817 || TREE_CODE (target) == ARRAY_RANGE_REF)
2819 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2820 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2821 target = TREE_OPERAND (target, 0);
2823 else if (TREE_CODE (target) == INDIRECT_REF
2824 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2825 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2827 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2832 switch (TREE_CODE (target))
2836 x = DECL_RTL (target);
2840 x = gen_rtx_MEM (FUNCTION_MODE,
2841 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2850 x = output_constant_def (target, 1);
2857 gcc_assert (MEM_P (x));
2861 value->offset = offset;
2865 static GTY((param_is (struct constant_descriptor_tree)))
2866 htab_t const_desc_htab;
2868 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2870 /* Constant pool accessor function. */
2873 constant_pool_htab (void)
2875 return const_desc_htab;
2878 /* Compute a hash code for a constant expression. */
2881 const_desc_hash (const void *ptr)
2883 return ((const struct constant_descriptor_tree *)ptr)->hash;
2887 const_hash_1 (const tree exp)
2892 enum tree_code code = TREE_CODE (exp);
2894 /* Either set P and LEN to the address and len of something to hash and
2895 exit the switch or return a value. */
2900 p = (char *) &TREE_INT_CST (exp);
2901 len = sizeof TREE_INT_CST (exp);
2905 return real_hash (TREE_REAL_CST_PTR (exp));
2908 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2911 p = TREE_STRING_POINTER (exp);
2912 len = TREE_STRING_LENGTH (exp);
2916 return (const_hash_1 (TREE_REALPART (exp)) * 5
2917 + const_hash_1 (TREE_IMAGPART (exp)));
2923 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2925 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2926 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2933 unsigned HOST_WIDE_INT idx;
2936 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2938 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2940 hi = hi * 603 + const_hash_1 (value);
2948 struct addr_const value;
2950 decode_addr_const (exp, &value);
2951 switch (GET_CODE (value.base))
2954 /* Don't hash the address of the SYMBOL_REF;
2955 only use the offset and the symbol name. */
2957 p = XSTR (value.base, 0);
2958 for (i = 0; p[i] != 0; i++)
2959 hi = ((hi * 613) + (unsigned) (p[i]));
2963 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2973 case POINTER_PLUS_EXPR:
2975 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2976 + const_hash_1 (TREE_OPERAND (exp, 1)));
2979 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2982 /* A language specific constant. Just hash the code. */
2986 /* Compute hashing function. */
2988 for (i = 0; i < len; i++)
2989 hi = ((hi * 613) + (unsigned) (p[i]));
2994 /* Wrapper of compare_constant, for the htab interface. */
2996 const_desc_eq (const void *p1, const void *p2)
2998 const struct constant_descriptor_tree *const c1
2999 = (const struct constant_descriptor_tree *) p1;
3000 const struct constant_descriptor_tree *const c2
3001 = (const struct constant_descriptor_tree *) p2;
3002 if (c1->hash != c2->hash)
3004 return compare_constant (c1->value, c2->value);
3007 /* Compare t1 and t2, and return 1 only if they are known to result in
3008 the same bit pattern on output. */
3011 compare_constant (const tree t1, const tree t2)
3013 enum tree_code typecode;
3015 if (t1 == NULL_TREE)
3016 return t2 == NULL_TREE;
3017 if (t2 == NULL_TREE)
3020 if (TREE_CODE (t1) != TREE_CODE (t2))
3023 switch (TREE_CODE (t1))
3026 /* Integer constants are the same only if the same width of type. */
3027 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3029 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3031 return tree_int_cst_equal (t1, t2);
3034 /* Real constants are the same only if the same width of type. */
3035 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3038 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
3041 /* Fixed constants are the same only if the same width of type. */
3042 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3045 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3048 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3051 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3052 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3053 TREE_STRING_LENGTH (t1)));
3056 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3057 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3063 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
3064 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
3067 link2 = TREE_VECTOR_CST_ELTS (t2);
3068 for (link1 = TREE_VECTOR_CST_ELTS (t1);
3070 link1 = TREE_CHAIN (link1))
3072 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
3074 link2 = TREE_CHAIN (link2);
3082 VEC(constructor_elt, gc) *v1, *v2;
3083 unsigned HOST_WIDE_INT idx;
3085 typecode = TREE_CODE (TREE_TYPE (t1));
3086 if (typecode != TREE_CODE (TREE_TYPE (t2)))
3089 if (typecode == ARRAY_TYPE)
3091 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3092 /* For arrays, check that the sizes all match. */
3093 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3095 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
3100 /* For record and union constructors, require exact type
3102 if (TREE_TYPE (t1) != TREE_TYPE (t2))
3106 v1 = CONSTRUCTOR_ELTS (t1);
3107 v2 = CONSTRUCTOR_ELTS (t2);
3108 if (VEC_length (constructor_elt, v1)
3109 != VEC_length (constructor_elt, v2))
3112 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
3114 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
3115 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
3117 /* Check that each value is the same... */
3118 if (!compare_constant (c1->value, c2->value))
3120 /* ... and that they apply to the same fields! */
3121 if (typecode == ARRAY_TYPE)
3123 if (!compare_constant (c1->index, c2->index))
3128 if (c1->index != c2->index)
3139 struct addr_const value1, value2;
3143 decode_addr_const (t1, &value1);
3144 decode_addr_const (t2, &value2);
3146 if (value1.offset != value2.offset)
3149 code = GET_CODE (value1.base);
3150 if (code != GET_CODE (value2.base))
3156 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3160 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
3161 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
3171 case POINTER_PLUS_EXPR:
3174 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3175 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3178 case VIEW_CONVERT_EXPR:
3179 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3188 /* Make a copy of the whole tree structure for a constant. This
3189 handles the same types of nodes that compare_constant handles. */
3192 copy_constant (tree exp)
3194 switch (TREE_CODE (exp))
3197 /* For ADDR_EXPR, we do not want to copy the decl whose address
3198 is requested. We do want to copy constants though. */
3199 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3200 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3201 copy_constant (TREE_OPERAND (exp, 0)));
3203 return copy_node (exp);
3209 return copy_node (exp);
3212 return build_complex (TREE_TYPE (exp),
3213 copy_constant (TREE_REALPART (exp)),
3214 copy_constant (TREE_IMAGPART (exp)));
3217 case POINTER_PLUS_EXPR:
3219 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3220 copy_constant (TREE_OPERAND (exp, 0)),
3221 copy_constant (TREE_OPERAND (exp, 1)));
3224 case VIEW_CONVERT_EXPR:
3225 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3226 copy_constant (TREE_OPERAND (exp, 0)));
3229 return build_vector (TREE_TYPE (exp),
3230 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3234 tree copy = copy_node (exp);
3235 VEC(constructor_elt, gc) *v;
3236 unsigned HOST_WIDE_INT idx;
3237 tree purpose, value;
3239 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3240 CONSTRUCTOR_ELTS (exp)));
3241 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3243 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3244 ce->index = purpose;
3245 ce->value = copy_constant (value);
3247 CONSTRUCTOR_ELTS (copy) = v;
3256 /* Return the section into which constant EXP should be placed. */
3259 get_constant_section (tree exp, unsigned int align)
3261 return targetm.asm_out.select_section (exp,
3262 compute_reloc_for_constant (exp),
3266 /* Return the size of constant EXP in bytes. */
3268 static HOST_WIDE_INT
3269 get_constant_size (tree exp)
3273 size = int_size_in_bytes (TREE_TYPE (exp));
3274 if (TREE_CODE (exp) == STRING_CST)
3275 size = MAX (TREE_STRING_LENGTH (exp), size);
3279 /* Subroutine of output_constant_def:
3280 No constant equal to EXP is known to have been output.
3281 Make a constant descriptor to enter EXP in the hash table.
3282 Assign the label number and construct RTL to refer to the
3283 constant's location in memory.
3284 Caller is responsible for updating the hash table. */
3286 static struct constant_descriptor_tree *
3287 build_constant_desc (tree exp)
3289 struct constant_descriptor_tree *desc;
3295 desc = GGC_NEW (struct constant_descriptor_tree);
3296 desc->value = copy_constant (exp);
3298 /* Propagate marked-ness to copied constant. */
3299 if (flag_mudflap && mf_marked_p (exp))
3300 mf_mark (desc->value);
3302 /* Create a string containing the label name, in LABEL. */
3303 labelno = const_labelno++;
3304 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3306 /* Construct the VAR_DECL associated with the constant. */
3307 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3309 DECL_ARTIFICIAL (decl) = 1;
3310 DECL_IGNORED_P (decl) = 1;
3311 TREE_READONLY (decl) = 1;
3312 TREE_STATIC (decl) = 1;
3313 TREE_ADDRESSABLE (decl) = 1;
3314 /* We don't set the RTL yet as this would cause varpool to assume that the
3315 variable is referenced. Moreover, it would just be dropped in LTO mode.
3316 Instead we set the flag that will be recognized in make_decl_rtl. */
3317 DECL_IN_CONSTANT_POOL (decl) = 1;
3318 DECL_INITIAL (decl) = desc->value;
3319 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3320 architectures so use DATA_ALIGNMENT as well, except for strings. */
3321 if (TREE_CODE (exp) == STRING_CST)
3323 #ifdef CONSTANT_ALIGNMENT
3324 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3328 align_variable (decl, 0);
3330 /* Now construct the SYMBOL_REF and the MEM. */
3331 if (use_object_blocks_p ())
3333 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3334 symbol = create_block_symbol (ggc_strdup (label),
3335 get_block_for_section (sect), -1);
3338 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3339 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3340 SET_SYMBOL_REF_DECL (symbol, decl);
3341 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3343 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
3344 set_mem_attributes (rtl, exp, 1);
3345 set_mem_alias_set (rtl, 0);
3346 set_mem_alias_set (rtl, const_alias_set);
3348 /* We cannot share RTX'es in pool entries.
3349 Mark this piece of RTL as required for unsharing. */
3350 RTX_FLAG (rtl, used) = 1;
3352 /* Set flags or add text to the name to record information, such as
3353 that it is a local symbol. If the name is changed, the macro
3354 ASM_OUTPUT_LABELREF will have to know how to strip this
3355 information. This call might invalidate our local variable
3356 SYMBOL; we can't use it afterward. */
3357 targetm.encode_section_info (exp, rtl, true);
3364 /* Return an rtx representing a reference to constant data in memory
3365 for the constant expression EXP.
3367 If assembler code for such a constant has already been output,
3368 return an rtx to refer to it.
3369 Otherwise, output such a constant in memory
3370 and generate an rtx for it.
3372 If DEFER is nonzero, this constant can be deferred and output only
3373 if referenced in the function after all optimizations.
3375 `const_desc_table' records which constants already have label strings. */
3378 output_constant_def (tree exp, int defer)
3380 struct constant_descriptor_tree *desc;
3381 struct constant_descriptor_tree key;
3384 /* Look up EXP in the table of constant descriptors. If we didn't find
3385 it, create a new one. */
3387 key.hash = const_hash_1 (exp);
3388 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3390 desc = (struct constant_descriptor_tree *) *loc;
3393 desc = build_constant_desc (exp);
3394 desc->hash = key.hash;
3398 maybe_output_constant_def_contents (desc, defer);
3402 /* Subroutine of output_constant_def: Decide whether or not we need to
3403 output the constant DESC now, and if so, do it. */
3405 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3408 rtx symbol = XEXP (desc->rtl, 0);
3409 tree exp = desc->value;
3411 if (flag_syntax_only)
3414 if (TREE_ASM_WRITTEN (exp))
3415 /* Already output; don't do it again. */
3418 /* We can always defer constants as long as the context allows
3422 /* Increment n_deferred_constants if it exists. It needs to be at
3423 least as large as the number of constants actually referred to
3424 by the function. If it's too small we'll stop looking too early
3425 and fail to emit constants; if it's too large we'll only look
3426 through the entire function when we could have stopped earlier. */
3428 n_deferred_constants++;
3432 output_constant_def_contents (symbol);
3435 /* Subroutine of output_constant_def_contents. Output the definition
3436 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3437 constant's alignment in bits. */
3440 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3444 size = get_constant_size (exp);
3446 /* Do any machine/system dependent processing of the constant. */
3447 #ifdef ASM_DECLARE_CONSTANT_NAME
3448 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
3450 /* Standard thing is just output label for the constant. */
3451 ASM_OUTPUT_LABEL (asm_out_file, label);
3452 #endif /* ASM_DECLARE_CONSTANT_NAME */
3454 /* Output the value of EXP. */
3455 output_constant (exp, size, align);
3458 /* We must output the constant data referred to by SYMBOL; do so. */
3461 output_constant_def_contents (rtx symbol)
3463 tree decl = SYMBOL_REF_DECL (symbol);
3464 tree exp = DECL_INITIAL (decl);
3467 /* Make sure any other constants whose addresses appear in EXP
3468 are assigned label numbers. */
3469 output_addressed_constants (exp);
3471 /* We are no longer deferring this constant. */
3472 TREE_ASM_WRITTEN (exp) = 1;
3474 /* If the constant is part of an object block, make sure that the
3475 decl has been positioned within its block, but do not write out
3476 its definition yet. output_object_blocks will do that later. */
3477 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3478 place_block_symbol (symbol);
3481 align = DECL_ALIGN (decl);
3482 switch_to_section (get_constant_section (exp, align));
3483 if (align > BITS_PER_UNIT)
3484 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3485 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3488 mudflap_enqueue_constant (exp);
3491 /* Look up EXP in the table of constant descriptors. Return the rtl
3492 if it has been emitted, else null. */
3495 lookup_constant_def (tree exp)
3497 struct constant_descriptor_tree *desc;
3498 struct constant_descriptor_tree key;
3501 key.hash = const_hash_1 (exp);
3502 desc = (struct constant_descriptor_tree *)
3503 htab_find_with_hash (const_desc_htab, &key, key.hash);
3505 return (desc ? desc->rtl : NULL_RTX);
3508 /* Return a tree representing a reference to constant data in memory
3509 for the constant expression EXP.
3511 This is the counterpart of output_constant_def at the Tree level. */
3514 tree_output_constant_def (tree exp)
3516 struct constant_descriptor_tree *desc, key;
3520 /* Look up EXP in the table of constant descriptors. If we didn't find
3521 it, create a new one. */
3523 key.hash = const_hash_1 (exp);
3524 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3526 desc = (struct constant_descriptor_tree *) *loc;
3529 desc = build_constant_desc (exp);
3530 desc->hash = key.hash;
3534 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3535 varpool_finalize_decl (decl);
3539 /* Used in the hash tables to avoid outputting the same constant
3540 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3541 are output once per function, not once per file. */
3542 /* ??? Only a few targets need per-function constant pools. Most
3543 can use one per-file pool. Should add a targetm bit to tell the
3546 struct GTY(()) rtx_constant_pool {
3547 /* Pointers to first and last constant in pool, as ordered by offset. */
3548 struct constant_descriptor_rtx *first;
3549 struct constant_descriptor_rtx *last;
3551 /* Hash facility for making memory-constants from constant rtl-expressions.
3552 It is used on RISC machines where immediate integer arguments and
3553 constant addresses are restricted so that such constants must be stored
3555 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3557 /* Current offset in constant pool (does not include any
3558 machine-specific header). */
3559 HOST_WIDE_INT offset;
3562 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3563 struct constant_descriptor_rtx *next;
3567 HOST_WIDE_INT offset;
3569 enum machine_mode mode;
3575 /* Hash and compare functions for const_rtx_htab. */
3578 const_desc_rtx_hash (const void *ptr)
3580 const struct constant_descriptor_rtx *const desc
3581 = (const struct constant_descriptor_rtx *) ptr;
3586 const_desc_rtx_eq (const void *a, const void *b)
3588 const struct constant_descriptor_rtx *const x
3589 = (const struct constant_descriptor_rtx *) a;
3590 const struct constant_descriptor_rtx *const y
3591 = (const struct constant_descriptor_rtx *) b;
3593 if (x->mode != y->mode)
3595 return rtx_equal_p (x->constant, y->constant);
3598 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3601 const_rtx_hash_1 (rtx *xp, void *data)
3603 unsigned HOST_WIDE_INT hwi;
3604 enum machine_mode mode;
3610 code = GET_CODE (x);
3611 mode = GET_MODE (x);
3612 h = (hashval_t) code * 1048573 + mode;
3620 int shift = sizeof (hashval_t) * CHAR_BIT;
3621 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3624 h ^= (hashval_t) hwi;
3625 for (i = 1; i < n; ++i)
3628 h ^= (hashval_t) hwi;
3634 if (mode == VOIDmode)
3636 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3640 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3644 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3650 for (i = XVECLEN (x, 0); i-- > 0; )
3651 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3656 h ^= htab_hash_string (XSTR (x, 0));
3660 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3664 case UNSPEC_VOLATILE:
3665 h = h * 251 + XINT (x, 1);
3672 hp = (hashval_t *) data;
3673 *hp = *hp * 509 + h;
3677 /* Compute a hash value for X, which should be a constant. */
3680 const_rtx_hash (rtx x)
3683 for_each_rtx (&x, const_rtx_hash_1, &h);
3688 /* Create and return a new rtx constant pool. */
3690 static struct rtx_constant_pool *
3691 create_constant_pool (void)
3693 struct rtx_constant_pool *pool;
3695 pool = GGC_NEW (struct rtx_constant_pool);
3696 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3697 const_desc_rtx_eq, NULL);
3704 /* Initialize constant pool hashing for a new function. */
3707 init_varasm_status (void)
3709 crtl->varasm.pool = create_constant_pool ();
3710 crtl->varasm.deferred_constants = 0;
3713 /* Given a MINUS expression, simplify it if both sides
3714 include the same symbol. */
3717 simplify_subtraction (rtx x)
3719 rtx r = simplify_rtx (x);
3723 /* Given a constant rtx X, make (or find) a memory constant for its value
3724 and return a MEM rtx to refer to it in memory. */
3727 force_const_mem (enum machine_mode mode, rtx x)
3729 struct constant_descriptor_rtx *desc, tmp;
3730 struct rtx_constant_pool *pool;
3737 /* If we're not allowed to drop X into the constant pool, don't. */
3738 if (targetm.cannot_force_const_mem (x))
3741 /* Record that this function has used a constant pool entry. */
3742 crtl->uses_const_pool = 1;
3744 /* Decide which pool to use. */
3745 pool = (targetm.use_blocks_for_constant_p (mode, x)
3746 ? shared_constant_pool
3747 : crtl->varasm.pool);
3749 /* Lookup the value in the hashtable. */
3752 hash = const_rtx_hash (x);
3753 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3754 desc = (struct constant_descriptor_rtx *) *slot;
3756 /* If the constant was already present, return its memory. */
3758 return copy_rtx (desc->mem);
3760 /* Otherwise, create a new descriptor. */
3761 desc = GGC_NEW (struct constant_descriptor_rtx);
3764 /* Align the location counter as required by EXP's data type. */
3765 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3766 #ifdef CONSTANT_ALIGNMENT
3768 tree type = lang_hooks.types.type_for_mode (mode, 0);
3769 if (type != NULL_TREE)
3770 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3774 pool->offset += (align / BITS_PER_UNIT) - 1;
3775 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3778 desc->constant = tmp.constant;
3779 desc->offset = pool->offset;
3782 desc->align = align;
3783 desc->labelno = const_labelno;
3786 pool->offset += GET_MODE_SIZE (mode);
3788 pool->last->next = desc;
3790 pool->first = pool->last = desc;
3793 /* Create a string containing the label name, in LABEL. */
3794 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3797 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3798 the constants pool. */
3799 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3801 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3802 symbol = create_block_symbol (ggc_strdup (label),
3803 get_block_for_section (sect), -1);
3806 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3808 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3809 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3810 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3812 /* Construct the MEM. */
3813 desc->mem = def = gen_const_mem (mode, symbol);
3814 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3815 set_mem_align (def, align);
3817 /* If we're dropping a label to the constant pool, make sure we
3819 if (GET_CODE (x) == LABEL_REF)
3820 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3822 return copy_rtx (def);
3825 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3828 get_pool_constant (rtx addr)
3830 return SYMBOL_REF_CONSTANT (addr)->constant;
3833 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3834 and whether it has been output or not. */
3837 get_pool_constant_mark (rtx addr, bool *pmarked)
3839 struct constant_descriptor_rtx *desc;
3841 desc = SYMBOL_REF_CONSTANT (addr);
3842 *pmarked = (desc->mark != 0);
3843 return desc->constant;
3846 /* Similar, return the mode. */
3849 get_pool_mode (const_rtx addr)
3851 return SYMBOL_REF_CONSTANT (addr)->mode;
3854 /* Return the size of the constant pool. */
3857 get_pool_size (void)
3859 return crtl->varasm.pool->offset;
3862 /* Worker function for output_constant_pool_1. Emit assembly for X
3863 in MODE with known alignment ALIGN. */
3866 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3868 switch (GET_MODE_CLASS (mode))
3871 case MODE_DECIMAL_FLOAT:
3875 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3876 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3877 assemble_real (r, mode, align);
3882 case MODE_PARTIAL_INT:
3887 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3890 case MODE_VECTOR_FLOAT:
3891 case MODE_VECTOR_INT:
3892 case MODE_VECTOR_FRACT:
3893 case MODE_VECTOR_UFRACT:
3894 case MODE_VECTOR_ACCUM:
3895 case MODE_VECTOR_UACCUM:
3898 enum machine_mode submode = GET_MODE_INNER (mode);
3899 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3901 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3902 units = CONST_VECTOR_NUNITS (x);
3904 for (i = 0; i < units; i++)
3906 rtx elt = CONST_VECTOR_ELT (x, i);
3907 output_constant_pool_2 (submode, elt, i ? subalign : align);
3917 /* Worker function for output_constant_pool. Emit constant DESC,
3918 giving it ALIGN bits of alignment. */
3921 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3928 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3929 whose CODE_LABEL has been deleted. This can occur if a jump table
3930 is eliminated by optimization. If so, write a constant of zero
3931 instead. Note that this can also happen by turning the
3932 CODE_LABEL into a NOTE. */
3933 /* ??? This seems completely and utterly wrong. Certainly it's
3934 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3935 functioning even with INSN_DELETED_P and friends. */
3938 switch (GET_CODE (tmp))
3941 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3942 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3944 tmp = XEXP (XEXP (tmp, 0), 0);
3948 tmp = XEXP (tmp, 0);
3949 gcc_assert (!INSN_DELETED_P (tmp));
3950 gcc_assert (!NOTE_P (tmp)
3951 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3958 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3959 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3960 align, desc->labelno, done);
3963 assemble_align (align);
3965 /* Output the label. */
3966 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3968 /* Output the data. */
3969 output_constant_pool_2 (desc->mode, x, align);
3971 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3972 sections have proper size. */
3973 if (align > GET_MODE_BITSIZE (desc->mode)
3975 && (in_section->common.flags & SECTION_MERGE))
3976 assemble_align (align);
3978 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3984 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3985 to as used. Emit referenced deferred strings. This function can
3986 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3989 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3991 rtx x = *current_rtx;
3993 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3996 if (CONSTANT_POOL_ADDRESS_P (x))
3998 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3999 if (desc->mark == 0)
4002 for_each_rtx (&desc->constant, mark_constant, NULL);
4005 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4007 tree decl = SYMBOL_REF_DECL (x);
4008 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4010 n_deferred_constants--;
4011 output_constant_def_contents (x);
4018 /* Look through appropriate parts of INSN, marking all entries in the
4019 constant pool which are actually being used. Entries that are only
4020 referenced by other constants are also marked as used. Emit
4021 deferred strings that are used. */
4024 mark_constants (rtx insn)
4029 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4030 insns, not any notes that may be attached. We don't want to mark
4031 a constant just because it happens to appear in a REG_EQUIV note. */
4032 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
4034 rtx seq = PATTERN (insn);
4035 int i, n = XVECLEN (seq, 0);
4036 for (i = 0; i < n; ++i)
4038 rtx subinsn = XVECEXP (seq, 0, i);
4039 if (INSN_P (subinsn))
4040 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
4044 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
4047 /* Look through the instructions for this function, and mark all the
4048 entries in POOL which are actually being used. Emit deferred constants
4049 which have indeed been used. */
4052 mark_constant_pool (void)
4056 if (!crtl->uses_const_pool && n_deferred_constants == 0)
4059 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4060 mark_constants (insn);
4062 for (link = crtl->epilogue_delay_list;
4064 link = XEXP (link, 1))
4065 mark_constants (XEXP (link, 0));
4068 /* Write all the constants in POOL. */
4071 output_constant_pool_contents (struct rtx_constant_pool *pool)
4073 struct constant_descriptor_rtx *desc;
4075 for (desc = pool->first; desc ; desc = desc->next)
4078 /* If the constant is part of an object_block, make sure that
4079 the constant has been positioned within its block, but do not
4080 write out its definition yet. output_object_blocks will do
4082 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4083 && SYMBOL_REF_BLOCK (desc->sym))
4084 place_block_symbol (desc->sym);
4087 switch_to_section (targetm.asm_out.select_rtx_section
4088 (desc->mode, desc->constant, desc->align));
4089 output_constant_pool_1 (desc, desc->align);
4094 /* Mark all constants that are used in the current function, then write
4095 out the function's private constant pool. */
4098 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4099 tree fndecl ATTRIBUTE_UNUSED)
4101 struct rtx_constant_pool *pool = crtl->varasm.pool;
4103 /* It is possible for gcc to call force_const_mem and then to later
4104 discard the instructions which refer to the constant. In such a
4105 case we do not need to output the constant. */
4106 mark_constant_pool ();
4108 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4109 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4112 output_constant_pool_contents (pool);
4114 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4115 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4119 /* Write the contents of the shared constant pool. */
4122 output_shared_constant_pool (void)
4124 output_constant_pool_contents (shared_constant_pool);
4127 /* Determine what kind of relocations EXP may need. */
4130 compute_reloc_for_constant (tree exp)
4132 int reloc = 0, reloc2;
4135 switch (TREE_CODE (exp))
4139 /* Go inside any operations that get_inner_reference can handle and see
4140 if what's inside is a constant: no need to do anything here for
4141 addresses of variables or functions. */
4142 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4143 tem = TREE_OPERAND (tem, 0))
4146 if (TREE_PUBLIC (tem))
4153 case POINTER_PLUS_EXPR:
4154 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4155 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4159 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4160 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4161 /* The difference of two local labels is computable at link time. */
4162 if (reloc == 1 && reloc2 == 1)
4169 case VIEW_CONVERT_EXPR:
4170 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4175 unsigned HOST_WIDE_INT idx;
4176 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4178 reloc |= compute_reloc_for_constant (tem);
4188 /* Find all the constants whose addresses are referenced inside of EXP,
4189 and make sure assembler code with a label has been output for each one.
4190 Indicate whether an ADDR_EXPR has been encountered. */
4193 output_addressed_constants (tree exp)
4197 switch (TREE_CODE (exp))
4201 /* Go inside any operations that get_inner_reference can handle and see
4202 if what's inside is a constant: no need to do anything here for
4203 addresses of variables or functions. */
4204 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4205 tem = TREE_OPERAND (tem, 0))
4208 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4209 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4210 tem = DECL_INITIAL (tem);
4212 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4213 output_constant_def (tem, 0);
4217 case POINTER_PLUS_EXPR:
4219 output_addressed_constants (TREE_OPERAND (exp, 1));
4223 case VIEW_CONVERT_EXPR:
4224 output_addressed_constants (TREE_OPERAND (exp, 0));
4229 unsigned HOST_WIDE_INT idx;
4230 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4232 output_addressed_constants (tem);
4241 /* Whether a constructor CTOR is a valid static constant initializer if all
4242 its elements are. This used to be internal to initializer_constant_valid_p
4243 and has been exposed to let other functions like categorize_ctor_elements
4244 evaluate the property while walking a constructor for other purposes. */
4247 constructor_static_from_elts_p (const_tree ctor)
4249 return (TREE_CONSTANT (ctor)
4250 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4251 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE)
4252 && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)));
4255 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4258 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4259 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4260 which are valid when ENDTYPE is an integer of any size; in
4261 particular, this does not accept a pointer minus a constant. This
4262 returns null_pointer_node if the VALUE is an absolute constant
4263 which can be used to initialize a static variable. Otherwise it
4267 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4271 if (!INTEGRAL_TYPE_P (endtype))
4274 op0 = TREE_OPERAND (value, 0);
4275 op1 = TREE_OPERAND (value, 1);
4277 /* Like STRIP_NOPS except allow the operand mode to widen. This
4278 works around a feature of fold that simplifies (int)(p1 - p2) to
4279 ((int)p1 - (int)p2) under the theory that the narrower operation
4282 while (CONVERT_EXPR_P (op0)
4283 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4285 tree inner = TREE_OPERAND (op0, 0);
4286 if (inner == error_mark_node
4287 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4288 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4289 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4294 while (CONVERT_EXPR_P (op1)
4295 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4297 tree inner = TREE_OPERAND (op1, 0);
4298 if (inner == error_mark_node
4299 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4300 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4301 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4306 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4310 op1 = initializer_constant_valid_p_1 (op1, endtype,
4311 cache ? cache + 2 : NULL);
4312 /* Both initializers must be known. */
4316 && (op0 == null_pointer_node
4317 || TREE_CODE (value) == MINUS_EXPR))
4318 return null_pointer_node;
4320 /* Support differences between labels. */
4321 if (TREE_CODE (op0) == LABEL_DECL
4322 && TREE_CODE (op1) == LABEL_DECL)
4323 return null_pointer_node;
4325 if (TREE_CODE (op0) == STRING_CST
4326 && TREE_CODE (op1) == STRING_CST
4327 && operand_equal_p (op0, op1, 1))
4328 return null_pointer_node;
4334 /* Helper function of initializer_constant_valid_p.
4335 Return nonzero if VALUE is a valid constant-valued expression
4336 for use in initializing a static variable; one that can be an
4337 element of a "constant" initializer.
4339 Return null_pointer_node if the value is absolute;
4340 if it is relocatable, return the variable that determines the relocation.
4341 We assume that VALUE has been folded as much as possible;
4342 therefore, we do not need to check for such things as
4343 arithmetic-combinations of integers.
4345 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4348 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4352 switch (TREE_CODE (value))
4355 if (constructor_static_from_elts_p (value))
4357 unsigned HOST_WIDE_INT idx;
4359 bool absolute = true;
4361 if (cache && cache[0] == value)
4363 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4366 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4373 cache[1] = NULL_TREE;
4377 if (reloc != null_pointer_node)
4380 /* For a non-absolute relocation, there is no single
4381 variable that can be "the variable that determines the
4386 cache[1] = absolute ? null_pointer_node : error_mark_node;
4388 return absolute ? null_pointer_node : error_mark_node;
4391 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4399 return null_pointer_node;
4404 tree op0 = staticp (TREE_OPERAND (value, 0));
4407 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4408 to be a constant, this is old-skool offsetof-like nonsense. */
4409 if (TREE_CODE (op0) == INDIRECT_REF
4410 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4411 return null_pointer_node;
4412 /* Taking the address of a nested function involves a trampoline,
4413 unless we don't need or want one. */
4414 if (TREE_CODE (op0) == FUNCTION_DECL
4415 && DECL_STATIC_CHAIN (op0)
4416 && !TREE_NO_TRAMPOLINE (value))
4418 /* "&{...}" requires a temporary to hold the constructed