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, 2011 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"
33 #include "pointer-set.h"
40 #include "hard-reg-set.h"
43 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "common/common-target.h"
51 #include "targhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
56 #include "tree-iterator.h"
57 #include "pointer-set.h"
59 #ifdef XCOFF_DEBUGGING_INFO
60 #include "xcoffout.h" /* Needed for external data
61 declarations for e.g. AIX 4.x. */
64 /* The (assembler) name of the first globally-visible object output. */
65 extern GTY(()) const char *first_global_object_name;
66 extern GTY(()) const char *weak_global_object_name;
68 const char *first_global_object_name;
69 const char *weak_global_object_name;
72 struct constant_descriptor_rtx;
73 struct rtx_constant_pool;
75 #define n_deferred_constants (crtl->varasm.deferred_constants)
77 /* Number for making the label on the next
78 constant that is stored in memory. */
80 static GTY(()) int const_labelno;
82 /* Carry information from ASM_DECLARE_OBJECT_NAME
83 to ASM_FINISH_DECLARE_OBJECT. */
85 int size_directive_output;
87 /* The last decl for which assemble_variable was called,
88 if it did ASM_DECLARE_OBJECT_NAME.
89 If the last call to assemble_variable didn't do that,
92 tree last_assemble_variable_decl;
94 /* The following global variable indicates if the first basic block
95 in a function belongs to the cold partition or not. */
97 bool first_function_block_is_cold;
99 /* We give all constants their own alias set. Perhaps redundant with
100 MEM_READONLY_P, but pre-dates it. */
102 static alias_set_type const_alias_set;
104 /* Whether we saw any functions with no_split_stack. */
106 static bool saw_no_split_stack;
108 static const char *strip_reg_name (const char *);
109 static int contains_pointers_p (tree);
110 #ifdef ASM_OUTPUT_EXTERNAL
111 static bool incorporeal_function_p (tree);
113 static void decode_addr_const (tree, struct addr_const *);
114 static hashval_t const_desc_hash (const void *);
115 static int const_desc_eq (const void *, const void *);
116 static hashval_t const_hash_1 (const tree);
117 static int compare_constant (const tree, const tree);
118 static tree copy_constant (tree);
119 static void output_constant_def_contents (rtx);
120 static void output_addressed_constants (tree);
121 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
122 static unsigned min_align (unsigned, unsigned);
123 static void globalize_decl (tree);
124 static bool decl_readonly_section_1 (enum section_category);
125 #ifdef BSS_SECTION_ASM_OP
126 #ifdef ASM_OUTPUT_ALIGNED_BSS
127 static void asm_output_aligned_bss (FILE *, tree, const char *,
128 unsigned HOST_WIDE_INT, int)
131 #endif /* BSS_SECTION_ASM_OP */
132 static void mark_weak (tree);
133 static void output_constant_pool (const char *, tree);
135 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
136 section *text_section;
137 section *data_section;
138 section *readonly_data_section;
139 section *sdata_section;
140 section *ctors_section;
141 section *dtors_section;
142 section *bss_section;
143 section *sbss_section;
145 /* Various forms of common section. All are guaranteed to be nonnull. */
146 section *tls_comm_section;
147 section *comm_section;
148 section *lcomm_section;
150 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
152 section *bss_noswitch_section;
154 /* The section that holds the main exception table, when known. The section
155 is set either by the target's init_sections hook or by the first call to
156 switch_to_exception_section. */
157 section *exception_section;
159 /* The section that holds the DWARF2 frame unwind information, when known.
160 The section is set either by the target's init_sections hook or by the
161 first call to switch_to_eh_frame_section. */
162 section *eh_frame_section;
164 /* asm_out_file's current section. This is NULL if no section has yet
165 been selected or if we lose track of what the current section is. */
168 /* True if code for the current function is currently being directed
169 at the cold section. */
170 bool in_cold_section_p;
172 /* A linked list of all the unnamed sections. */
173 static GTY(()) section *unnamed_sections;
175 /* Return a nonzero value if DECL has a section attribute. */
176 #define IN_NAMED_SECTION(DECL) \
177 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
178 && DECL_SECTION_NAME (DECL) != NULL_TREE)
180 /* Hash table of named sections. */
181 static GTY((param_is (section))) htab_t section_htab;
183 /* A table of object_blocks, indexed by section. */
184 static GTY((param_is (struct object_block))) htab_t object_block_htab;
186 /* The next number to use for internal anchor labels. */
187 static GTY(()) int anchor_labelno;
189 /* A pool of constants that can be shared between functions. */
190 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
192 /* Helper routines for maintaining section_htab. */
195 section_entry_eq (const void *p1, const void *p2)
197 const section *old = (const section *) p1;
198 const char *new_name = (const char *) p2;
200 return strcmp (old->named.name, new_name) == 0;
204 section_entry_hash (const void *p)
206 const section *old = (const section *) p;
207 return htab_hash_string (old->named.name);
210 /* Return a hash value for section SECT. */
213 hash_section (section *sect)
215 if (sect->common.flags & SECTION_NAMED)
216 return htab_hash_string (sect->named.name);
217 return sect->common.flags;
220 /* Helper routines for maintaining object_block_htab. */
223 object_block_entry_eq (const void *p1, const void *p2)
225 const struct object_block *old = (const struct object_block *) p1;
226 const section *new_section = (const section *) p2;
228 return old->sect == new_section;
232 object_block_entry_hash (const void *p)
234 const struct object_block *old = (const struct object_block *) p;
235 return hash_section (old->sect);
238 /* Return a new unnamed section with the given fields. */
241 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
246 sect = ggc_alloc_section ();
247 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
248 sect->unnamed.callback = callback;
249 sect->unnamed.data = data;
250 sect->unnamed.next = unnamed_sections;
252 unnamed_sections = sect;
256 /* Return a SECTION_NOSWITCH section with the given fields. */
259 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
263 sect = ggc_alloc_section ();
264 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
265 sect->noswitch.callback = callback;
270 /* Return the named section structure associated with NAME. Create
271 a new section with the given fields if no such structure exists. */
274 get_section (const char *name, unsigned int flags, tree decl)
276 section *sect, **slot;
279 htab_find_slot_with_hash (section_htab, name,
280 htab_hash_string (name), INSERT);
281 flags |= SECTION_NAMED;
284 sect = ggc_alloc_section ();
285 sect->named.common.flags = flags;
286 sect->named.name = ggc_strdup (name);
287 sect->named.decl = decl;
293 if ((sect->common.flags & ~SECTION_DECLARED) != flags
294 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
296 /* It is fine if one of the section flags is
297 SECTION_WRITE | SECTION_RELRO and the other has none of these
298 flags (i.e. read-only) in named sections and either the
299 section hasn't been declared yet or has been declared as writable.
300 In that case just make sure the resulting flags are
301 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
303 if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
304 == (SECTION_WRITE | SECTION_RELRO)
305 && (sect->common.flags
306 & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
307 == (flags & ~(SECTION_WRITE | SECTION_RELRO))
308 && ((sect->common.flags & SECTION_DECLARED) == 0
309 || (sect->common.flags & SECTION_WRITE)))
311 sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
314 /* Sanity check user variables for flag changes. */
316 decl = sect->named.decl;
318 error ("%+D causes a section type conflict with %D",
319 decl, sect->named.decl);
320 if (decl != sect->named.decl)
321 inform (DECL_SOURCE_LOCATION (sect->named.decl),
322 "%qD was declared here", sect->named.decl);
323 /* Make sure we don't error about one section multiple times. */
324 sect->common.flags |= SECTION_OVERRIDE;
330 /* Return true if the current compilation mode benefits from having
331 objects grouped into blocks. */
334 use_object_blocks_p (void)
336 return flag_section_anchors;
339 /* Return the object_block structure for section SECT. Create a new
340 structure if we haven't created one already. Return null if SECT
343 static struct object_block *
344 get_block_for_section (section *sect)
346 struct object_block *block;
352 slot = htab_find_slot_with_hash (object_block_htab, sect,
353 hash_section (sect), INSERT);
354 block = (struct object_block *) *slot;
357 block = ggc_alloc_cleared_object_block ();
364 /* Create a symbol with label LABEL and place it at byte offset
365 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
366 is not yet known. LABEL must be a garbage-collected string. */
369 create_block_symbol (const char *label, struct object_block *block,
370 HOST_WIDE_INT offset)
375 /* Create the extended SYMBOL_REF. */
376 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
377 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
379 /* Initialize the normal SYMBOL_REF fields. */
380 memset (symbol, 0, size);
381 PUT_CODE (symbol, SYMBOL_REF);
382 PUT_MODE (symbol, Pmode);
383 XSTR (symbol, 0) = label;
384 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
386 /* Initialize the block_symbol stuff. */
387 SYMBOL_REF_BLOCK (symbol) = block;
388 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
393 /* Return a section with a particular name and with whatever SECTION_*
394 flags section_type_flags deems appropriate. The name of the section
395 is taken from NAME if nonnull, otherwise it is taken from DECL's
396 DECL_SECTION_NAME. DECL is the decl associated with the section
397 (see the section comment for details) and RELOC is as for
398 section_type_flags. */
401 get_named_section (tree decl, const char *name, int reloc)
405 gcc_assert (!decl || DECL_P (decl));
407 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
409 flags = targetm.section_type_flags (decl, name, reloc);
411 return get_section (name, flags, decl);
414 /* If required, set DECL_SECTION_NAME to a unique name. */
417 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
418 int flag_function_or_data_sections)
420 if (DECL_SECTION_NAME (decl) == NULL_TREE
421 && targetm_common.have_named_sections
422 && (flag_function_or_data_sections
423 || DECL_ONE_ONLY (decl)))
425 targetm.asm_out.unique_section (decl, reloc);
426 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl) = true;
430 #ifdef BSS_SECTION_ASM_OP
432 #ifdef ASM_OUTPUT_ALIGNED_BSS
434 /* Utility function for targets to use in implementing
435 ASM_OUTPUT_ALIGNED_BSS.
436 ??? It is believed that this function will work in most cases so such
437 support is localized here. */
440 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
441 const char *name, unsigned HOST_WIDE_INT size,
444 switch_to_section (bss_section);
445 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
446 #ifdef ASM_DECLARE_OBJECT_NAME
447 last_assemble_variable_decl = decl;
448 ASM_DECLARE_OBJECT_NAME (file, name, decl);
450 /* Standard thing is just output label for the object. */
451 ASM_OUTPUT_LABEL (file, name);
452 #endif /* ASM_DECLARE_OBJECT_NAME */
453 ASM_OUTPUT_SKIP (file, size ? size : 1);
458 #endif /* BSS_SECTION_ASM_OP */
460 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
461 /* Return the hot section for function DECL. Return text_section for
465 hot_function_section (tree decl)
467 if (decl != NULL_TREE
468 && DECL_SECTION_NAME (decl) != NULL_TREE
469 && targetm_common.have_named_sections)
470 return get_named_section (decl, NULL, 0);
476 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
479 When DECL_SECTION_NAME is non-NULL and it is implicit section and
480 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
481 concatenate the name with NAMED_SECTION_SUFFIX.
482 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
485 get_named_text_section (tree decl,
486 const char *text_section_name,
487 const char *named_section_suffix)
489 if (decl && DECL_SECTION_NAME (decl))
491 if (named_section_suffix)
493 tree dsn = DECL_SECTION_NAME (decl);
494 const char *stripped_name;
497 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
498 memcpy (name, TREE_STRING_POINTER (dsn),
499 TREE_STRING_LENGTH (dsn) + 1);
501 stripped_name = targetm.strip_name_encoding (name);
503 buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
504 return get_named_section (decl, buffer, 0);
506 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
510 /* Do not try to split gnu_linkonce functions. This gets somewhat
512 if (DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP)
514 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
515 name = targetm.strip_name_encoding (name);
516 return get_named_section (decl, ACONCAT ((text_section_name, ".",
522 return get_named_section (decl, text_section_name, 0);
525 /* Choose named function section based on its frequency. */
528 default_function_section (tree decl, enum node_frequency freq,
529 bool startup, bool exit)
531 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
532 /* Old GNU linkers have buggy --gc-section support, which sometimes
533 results in .gcc_except_table* sections being garbage collected. */
535 && DECL_SECTION_NAME (decl)
536 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
540 if (!flag_reorder_functions
541 || !targetm_common.have_named_sections)
543 /* Startup code should go to startup subsection unless it is
544 unlikely executed (this happens especially with function splitting
545 where we can split away unnecesary parts of static constructors. */
546 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
547 return get_named_text_section (decl, ".text.startup", NULL);
549 /* Similarly for exit. */
550 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
551 return get_named_text_section (decl, ".text.exit", NULL);
553 /* Group cold functions together, similarly for hot code. */
556 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
557 return get_named_text_section (decl, ".text.unlikely", NULL);
558 case NODE_FREQUENCY_HOT:
559 return get_named_text_section (decl, ".text.hot", NULL);
565 /* Return the section for function DECL.
567 If DECL is NULL_TREE, return the text section. We can be passed
568 NULL_TREE under some circumstances by dbxout.c at least.
570 If FORCE_COLD is true, return cold function section ignoring
571 the frequency info of cgraph_node. */
574 function_section_1 (tree decl, bool force_cold)
576 section *section = NULL;
577 enum node_frequency freq = NODE_FREQUENCY_NORMAL;
578 bool startup = false, exit = false;
582 struct cgraph_node *node = cgraph_get_node (decl);
586 freq = node->frequency;
587 startup = node->only_called_at_startup;
588 exit = node->only_called_at_exit;
592 freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
594 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
595 if (decl != NULL_TREE
596 && DECL_SECTION_NAME (decl) != NULL_TREE)
598 if (targetm.asm_out.function_section)
599 section = targetm.asm_out.function_section (decl, freq,
603 return get_named_section (decl, NULL, 0);
606 return targetm.asm_out.select_section
607 (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
610 if (targetm.asm_out.function_section)
611 section = targetm.asm_out.function_section (decl, freq, startup, exit);
614 return hot_function_section (decl);
618 /* Return the section for function DECL.
620 If DECL is NULL_TREE, return the text section. We can be passed
621 NULL_TREE under some circumstances by dbxout.c at least. */
624 function_section (tree decl)
626 /* Handle cases where function splitting code decides
627 to put function entry point into unlikely executed section
628 despite the fact that the function itself is not cold
629 (i.e. it is called rarely but contains a hot loop that is
630 better to live in hot subsection for the code locality). */
631 return function_section_1 (decl,
632 first_function_block_is_cold);
635 /* Return the section for the current function, take IN_COLD_SECTION_P
639 current_function_section (void)
641 return function_section_1 (current_function_decl, in_cold_section_p);
644 /* Tell assembler to switch to unlikely-to-be-executed text section. */
647 unlikely_text_section (void)
649 return function_section_1 (current_function_decl, true);
652 /* When called within a function context, return true if the function
653 has been assigned a cold text section and if SECT is that section.
654 When called outside a function context, return true if SECT is the
655 default cold section. */
658 unlikely_text_section_p (section *sect)
660 return sect == function_section_1 (current_function_decl, true);
663 /* Return the read-only data section associated with function DECL. */
666 default_function_rodata_section (tree decl)
668 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
670 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
672 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
678 dot = strchr (name + 1, '.');
681 len = strlen (dot) + 8;
682 rname = (char *) alloca (len);
684 strcpy (rname, ".rodata");
686 return get_section (rname, SECTION_LINKONCE, decl);
688 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
689 else if (DECL_ONE_ONLY (decl)
690 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
692 size_t len = strlen (name) + 1;
693 char *rname = (char *) alloca (len);
695 memcpy (rname, name, len);
697 return get_section (rname, SECTION_LINKONCE, decl);
699 /* For .text.foo we want to use .rodata.foo. */
700 else if (flag_function_sections && flag_data_sections
701 && strncmp (name, ".text.", 6) == 0)
703 size_t len = strlen (name) + 1;
704 char *rname = (char *) alloca (len + 2);
706 memcpy (rname, ".rodata", 7);
707 memcpy (rname + 7, name + 5, len - 5);
708 return get_section (rname, 0, decl);
712 return readonly_data_section;
715 /* Return the read-only data section associated with function DECL
716 for targets where that section should be always the single
717 readonly data section. */
720 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
722 return readonly_data_section;
725 /* Return the section to use for string merging. */
728 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
729 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
730 unsigned int flags ATTRIBUTE_UNUSED)
734 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
735 && TREE_CODE (decl) == STRING_CST
736 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
738 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
739 && TREE_STRING_LENGTH (decl) >= len)
741 enum machine_mode mode;
742 unsigned int modesize;
746 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
747 char *name = (char *) alloca (strlen (prefix) + 30);
749 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
750 modesize = GET_MODE_BITSIZE (mode);
751 if (modesize >= 8 && modesize <= 256
752 && (modesize & (modesize - 1)) == 0)
754 if (align < modesize)
757 str = TREE_STRING_POINTER (decl);
758 unit = GET_MODE_SIZE (mode);
760 /* Check for embedded NUL characters. */
761 for (i = 0; i < len; i += unit)
763 for (j = 0; j < unit; j++)
764 if (str[i + j] != '\0')
771 sprintf (name, "%s.str%d.%d", prefix,
772 modesize / 8, (int) (align / 8));
773 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
774 return get_section (name, flags, NULL);
779 return readonly_data_section;
782 /* Return the section to use for constant merging. */
785 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
786 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
787 unsigned int flags ATTRIBUTE_UNUSED)
789 unsigned int modesize = GET_MODE_BITSIZE (mode);
791 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
797 && (align & (align - 1)) == 0)
799 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
800 char *name = (char *) alloca (strlen (prefix) + 30);
802 sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
803 flags |= (align / 8) | SECTION_MERGE;
804 return get_section (name, flags, NULL);
806 return readonly_data_section;
809 /* Given NAME, a putative register name, discard any customary prefixes. */
812 strip_reg_name (const char *name)
814 #ifdef REGISTER_PREFIX
815 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
816 name += strlen (REGISTER_PREFIX);
818 if (name[0] == '%' || name[0] == '#')
823 /* The user has asked for a DECL to have a particular name. Set (or
824 change) it in such a way that we don't prefix an underscore to
827 set_user_assembler_name (tree decl, const char *name)
829 char *starred = (char *) alloca (strlen (name) + 2);
831 strcpy (starred + 1, name);
832 change_decl_assembler_name (decl, get_identifier (starred));
833 SET_DECL_RTL (decl, NULL_RTX);
836 /* Decode an `asm' spec for a declaration as a register name.
837 Return the register number, or -1 if nothing specified,
838 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
839 or -3 if ASMSPEC is `cc' and is not recognized,
840 or -4 if ASMSPEC is `memory' and is not recognized.
841 Accept an exact spelling or a decimal number.
842 Prefixes such as % are optional. */
845 decode_reg_name_and_count (const char *asmspec, int *pnregs)
847 /* Presume just one register is clobbered. */
854 /* Get rid of confusing prefixes. */
855 asmspec = strip_reg_name (asmspec);
857 /* Allow a decimal number as a "register name". */
858 for (i = strlen (asmspec) - 1; i >= 0; i--)
859 if (! ISDIGIT (asmspec[i]))
861 if (asmspec[0] != 0 && i < 0)
864 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
870 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
872 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
875 #ifdef OVERLAPPING_REGISTER_NAMES
879 const char *const name;
882 } table[] = OVERLAPPING_REGISTER_NAMES;
884 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
886 && ! strcmp (asmspec, table[i].name))
888 *pnregs = table[i].nregs;
889 return table[i].number;
892 #endif /* OVERLAPPING_REGISTER_NAMES */
894 #ifdef ADDITIONAL_REGISTER_NAMES
896 static const struct { const char *const name; const int number; } table[]
897 = ADDITIONAL_REGISTER_NAMES;
899 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
901 && ! strcmp (asmspec, table[i].name))
902 return table[i].number;
904 #endif /* ADDITIONAL_REGISTER_NAMES */
906 if (!strcmp (asmspec, "memory"))
909 if (!strcmp (asmspec, "cc"))
919 decode_reg_name (const char *name)
922 return decode_reg_name_and_count (name, &count);
926 /* Return true if DECL's initializer is suitable for a BSS section. */
929 bss_initializer_p (const_tree decl)
931 return (DECL_INITIAL (decl) == NULL
932 || DECL_INITIAL (decl) == error_mark_node
933 || (flag_zero_initialized_in_bss
934 /* Leave constant zeroes in .rodata so they
936 && !TREE_READONLY (decl)
937 && initializer_zerop (DECL_INITIAL (decl))));
940 /* Compute the alignment of variable specified by DECL.
941 DONT_OUTPUT_DATA is from assemble_variable. */
944 align_variable (tree decl, bool dont_output_data)
946 unsigned int align = DECL_ALIGN (decl);
948 /* In the case for initialing an array whose length isn't specified,
949 where we have not yet been able to do the layout,
950 figure out the proper alignment now. */
951 if (dont_output_data && DECL_SIZE (decl) == 0
952 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
953 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
955 /* Some object file formats have a maximum alignment which they support.
956 In particular, a.out format supports a maximum alignment of 4. */
957 if (align > MAX_OFILE_ALIGNMENT)
959 warning (0, "alignment of %q+D is greater than maximum object "
960 "file alignment. Using %d", decl,
961 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
962 align = MAX_OFILE_ALIGNMENT;
965 /* On some machines, it is good to increase alignment sometimes. */
966 if (! DECL_USER_ALIGN (decl))
968 #ifdef DATA_ALIGNMENT
969 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
970 /* Don't increase alignment too much for TLS variables - TLS space
972 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
975 #ifdef CONSTANT_ALIGNMENT
976 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
978 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
980 /* Don't increase alignment too much for TLS variables - TLS space
982 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
988 /* Reset the alignment in case we have made it tighter, so we can benefit
989 from it in get_pointer_alignment. */
990 DECL_ALIGN (decl) = align;
993 /* Return the section into which the given VAR_DECL or CONST_DECL
994 should be placed. PREFER_NOSWITCH_P is true if a noswitch
995 section should be used wherever possible. */
998 get_variable_section (tree decl, bool prefer_noswitch_p)
1000 addr_space_t as = ADDR_SPACE_GENERIC;
1003 if (TREE_TYPE (decl) != error_mark_node)
1004 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1006 if (DECL_COMMON (decl))
1008 /* If the decl has been given an explicit section name, or it resides
1009 in a non-generic address space, then it isn't common, and shouldn't
1010 be handled as such. */
1011 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1012 && ADDR_SPACE_GENERIC_P (as));
1013 if (DECL_THREAD_LOCAL_P (decl))
1014 return tls_comm_section;
1015 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1016 return comm_section;
1019 if (DECL_INITIAL (decl) == error_mark_node)
1020 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1021 else if (DECL_INITIAL (decl))
1022 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1026 resolve_unique_section (decl, reloc, flag_data_sections);
1027 if (IN_NAMED_SECTION (decl))
1028 return get_named_section (decl, NULL, reloc);
1030 if (ADDR_SPACE_GENERIC_P (as)
1031 && !DECL_THREAD_LOCAL_P (decl)
1032 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1033 && bss_initializer_p (decl))
1035 if (!TREE_PUBLIC (decl))
1036 return lcomm_section;
1037 if (bss_noswitch_section)
1038 return bss_noswitch_section;
1041 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1044 /* Return the block into which object_block DECL should be placed. */
1046 static struct object_block *
1047 get_block_for_decl (tree decl)
1051 if (TREE_CODE (decl) == VAR_DECL)
1053 /* The object must be defined in this translation unit. */
1054 if (DECL_EXTERNAL (decl))
1057 /* There's no point using object blocks for something that is
1058 isolated by definition. */
1059 if (DECL_ONE_ONLY (decl))
1063 /* We can only calculate block offsets if the decl has a known
1065 if (DECL_SIZE_UNIT (decl) == NULL)
1067 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1070 /* Find out which section should contain DECL. We cannot put it into
1071 an object block if it requires a standalone definition. */
1072 if (TREE_CODE (decl) == VAR_DECL)
1073 align_variable (decl, 0);
1074 sect = get_variable_section (decl, true);
1075 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1078 return get_block_for_section (sect);
1081 /* Make sure block symbol SYMBOL is in block BLOCK. */
1084 change_symbol_block (rtx symbol, struct object_block *block)
1086 if (block != SYMBOL_REF_BLOCK (symbol))
1088 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1089 SYMBOL_REF_BLOCK (symbol) = block;
1093 /* Return true if it is possible to put DECL in an object_block. */
1096 use_blocks_for_decl_p (tree decl)
1098 /* Only data DECLs can be placed into object blocks. */
1099 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1102 /* Detect decls created by dw2_force_const_mem. Such decls are
1103 special because DECL_INITIAL doesn't specify the decl's true value.
1104 dw2_output_indirect_constants will instead call assemble_variable
1105 with dont_output_data set to 1 and then print the contents itself. */
1106 if (DECL_INITIAL (decl) == decl)
1109 /* If this decl is an alias, then we don't want to emit a
1111 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1117 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1118 have static storage duration. In other words, it should not be an
1119 automatic variable, including PARM_DECLs.
1121 There is, however, one exception: this function handles variables
1122 explicitly placed in a particular register by the user.
1124 This is never called for PARM_DECL nodes. */
1127 make_decl_rtl (tree decl)
1129 const char *name = 0;
1133 /* Check that we are not being given an automatic variable. */
1134 gcc_assert (TREE_CODE (decl) != PARM_DECL
1135 && TREE_CODE (decl) != RESULT_DECL);
1137 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1138 gcc_assert (TREE_CODE (decl) != VAR_DECL
1139 || TREE_STATIC (decl)
1140 || TREE_PUBLIC (decl)
1141 || DECL_EXTERNAL (decl)
1142 || DECL_REGISTER (decl));
1144 /* And that we were not given a type or a label. */
1145 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1146 && TREE_CODE (decl) != LABEL_DECL);
1148 /* For a duplicate declaration, we can be called twice on the
1149 same DECL node. Don't discard the RTL already made. */
1150 if (DECL_RTL_SET_P (decl))
1152 /* If the old RTL had the wrong mode, fix the mode. */
1153 x = DECL_RTL (decl);
1154 if (GET_MODE (x) != DECL_MODE (decl))
1155 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1157 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1160 /* ??? Another way to do this would be to maintain a hashed
1161 table of such critters. Instead of adding stuff to a DECL
1162 to give certain attributes to it, we could use an external
1163 hash map from DECL to set of attributes. */
1165 /* Let the target reassign the RTL if it wants.
1166 This is necessary, for example, when one machine specific
1167 decl attribute overrides another. */
1168 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1170 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1171 on the new decl information. */
1173 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1174 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1175 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1177 /* Make this function static known to the mudflap runtime. */
1178 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1179 mudflap_enqueue_decl (decl);
1184 /* If this variable belongs to the global constant pool, retrieve the
1185 pre-computed RTL or recompute it in LTO mode. */
1186 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1188 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1192 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1194 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1195 && DECL_REGISTER (decl))
1197 error ("register name not specified for %q+D", decl);
1199 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1201 const char *asmspec = name+1;
1202 enum machine_mode mode = DECL_MODE (decl);
1203 reg_number = decode_reg_name (asmspec);
1204 /* First detect errors in declaring global registers. */
1205 if (reg_number == -1)
1206 error ("register name not specified for %q+D", decl);
1207 else if (reg_number < 0)
1208 error ("invalid register name for %q+D", decl);
1209 else if (mode == BLKmode)
1210 error ("data type of %q+D isn%'t suitable for a register",
1212 else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1213 error ("the register specified for %q+D cannot be accessed"
1214 " by the current target", decl);
1215 else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1216 error ("the register specified for %q+D is not general enough"
1217 " to be used as a register variable", decl);
1218 else if (!HARD_REGNO_MODE_OK (reg_number, mode))
1219 error ("register specified for %q+D isn%'t suitable for data type",
1221 /* Now handle properly declared static register variables. */
1226 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1228 DECL_INITIAL (decl) = 0;
1229 error ("global register variable has initial value");
1231 if (TREE_THIS_VOLATILE (decl))
1232 warning (OPT_Wvolatile_register_var,
1233 "optimization may eliminate reads and/or "
1234 "writes to register variables");
1236 /* If the user specified one of the eliminables registers here,
1237 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1238 confused with that register and be eliminated. This usage is
1239 somewhat suspect... */
1241 SET_DECL_RTL (decl, gen_rtx_raw_REG (mode, reg_number));
1242 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1243 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1245 if (TREE_STATIC (decl))
1247 /* Make this register global, so not usable for anything
1249 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1250 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1251 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1253 nregs = hard_regno_nregs[reg_number][mode];
1255 globalize_reg (decl, reg_number + --nregs);
1258 /* As a register variable, it has no section. */
1262 /* Now handle ordinary static variables and functions (in memory).
1263 Also handle vars declared register invalidly. */
1264 else if (name[0] == '*')
1266 #ifdef REGISTER_PREFIX
1267 if (strlen (REGISTER_PREFIX) != 0)
1269 reg_number = decode_reg_name (name);
1270 if (reg_number >= 0 || reg_number == -3)
1271 error ("register name given for non-register variable %q+D", decl);
1276 /* Specifying a section attribute on a variable forces it into a
1277 non-.bss section, and thus it cannot be common. */
1278 /* FIXME: In general this code should not be necessary because
1279 visibility pass is doing the same work. But notice_global_symbol
1280 is called early and it needs to make DECL_RTL to get the name.
1281 we take care of recomputing the DECL_RTL after visibility is changed. */
1282 if (TREE_CODE (decl) == VAR_DECL
1283 && DECL_SECTION_NAME (decl) != NULL_TREE
1284 && DECL_INITIAL (decl) == NULL_TREE
1285 && DECL_COMMON (decl))
1286 DECL_COMMON (decl) = 0;
1288 /* Variables can't be both common and weak. */
1289 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1290 DECL_COMMON (decl) = 0;
1292 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1293 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1296 enum machine_mode address_mode = Pmode;
1297 if (TREE_TYPE (decl) != error_mark_node)
1299 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1300 address_mode = targetm.addr_space.address_mode (as);
1302 x = gen_rtx_SYMBOL_REF (address_mode, name);
1304 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1305 SET_SYMBOL_REF_DECL (x, decl);
1307 x = gen_rtx_MEM (DECL_MODE (decl), x);
1308 if (TREE_CODE (decl) != FUNCTION_DECL)
1309 set_mem_attributes (x, decl, 1);
1310 SET_DECL_RTL (decl, x);
1312 /* Optionally set flags or add text to the name to record information
1313 such as that it is a function name.
1314 If the name is changed, the macro ASM_OUTPUT_LABELREF
1315 will have to know how to strip this information. */
1316 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1318 /* Make this function static known to the mudflap runtime. */
1319 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1320 mudflap_enqueue_decl (decl);
1323 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1324 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1328 make_decl_rtl_for_debug (tree decl)
1330 unsigned int save_aliasing_flag, save_mudflap_flag;
1333 if (DECL_RTL_SET_P (decl))
1334 return DECL_RTL (decl);
1336 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1337 call new_alias_set. If running with -fcompare-debug, sometimes
1338 we do not want to create alias sets that will throw the alias
1339 numbers off in the comparison dumps. So... clearing
1340 flag_strict_aliasing will keep new_alias_set() from creating a
1341 new set. It is undesirable to register decl with mudflap
1342 in this case as well. */
1343 save_aliasing_flag = flag_strict_aliasing;
1344 flag_strict_aliasing = 0;
1345 save_mudflap_flag = flag_mudflap;
1348 rtl = DECL_RTL (decl);
1349 /* Reset DECL_RTL back, as various parts of the compiler expects
1350 DECL_RTL set meaning it is actually going to be output. */
1351 SET_DECL_RTL (decl, NULL);
1353 flag_strict_aliasing = save_aliasing_flag;
1354 flag_mudflap = save_mudflap_flag;
1359 /* Output a string of literal assembler code
1360 for an `asm' keyword used between functions. */
1363 assemble_asm (tree string)
1367 if (TREE_CODE (string) == ADDR_EXPR)
1368 string = TREE_OPERAND (string, 0);
1370 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1373 /* Record an element in the table of global destructors. SYMBOL is
1374 a SYMBOL_REF of the function to be called; PRIORITY is a number
1375 between 0 and MAX_INIT_PRIORITY. */
1378 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1379 int priority ATTRIBUTE_UNUSED)
1381 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1382 /* Tell GNU LD that this is part of the static destructor set.
1383 This will work for any system that uses stabs, most usefully
1385 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1386 dbxout_stab_value_label (XSTR (symbol, 0));
1388 sorry ("global destructors not supported on this target");
1392 /* Write the address of the entity given by SYMBOL to SEC. */
1394 assemble_addr_to_section (rtx symbol, section *sec)
1396 switch_to_section (sec);
1397 assemble_align (POINTER_SIZE);
1398 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1401 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1402 not) section for PRIORITY. */
1404 get_cdtor_priority_section (int priority, bool constructor_p)
1408 /* ??? This only works reliably with the GNU linker. */
1409 sprintf (buf, "%s.%.5u",
1410 constructor_p ? ".ctors" : ".dtors",
1411 /* Invert the numbering so the linker puts us in the proper
1412 order; constructors are run from right to left, and the
1413 linker sorts in increasing order. */
1414 MAX_INIT_PRIORITY - priority);
1415 return get_section (buf, SECTION_WRITE, NULL);
1419 default_named_section_asm_out_destructor (rtx symbol, int priority)
1423 if (priority != DEFAULT_INIT_PRIORITY)
1424 sec = get_cdtor_priority_section (priority,
1425 /*constructor_p=*/false);
1427 sec = get_section (".dtors", SECTION_WRITE, NULL);
1429 assemble_addr_to_section (symbol, sec);
1432 #ifdef DTORS_SECTION_ASM_OP
1434 default_dtor_section_asm_out_destructor (rtx symbol,
1435 int priority ATTRIBUTE_UNUSED)
1437 assemble_addr_to_section (symbol, dtors_section);
1441 /* Likewise for global constructors. */
1444 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1445 int priority ATTRIBUTE_UNUSED)
1447 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1448 /* Tell GNU LD that this is part of the static destructor set.
1449 This will work for any system that uses stabs, most usefully
1451 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1452 dbxout_stab_value_label (XSTR (symbol, 0));
1454 sorry ("global constructors not supported on this target");
1459 default_named_section_asm_out_constructor (rtx symbol, int priority)
1463 if (priority != DEFAULT_INIT_PRIORITY)
1464 sec = get_cdtor_priority_section (priority,
1465 /*constructor_p=*/true);
1467 sec = get_section (".ctors", SECTION_WRITE, NULL);
1469 assemble_addr_to_section (symbol, sec);
1472 #ifdef CTORS_SECTION_ASM_OP
1474 default_ctor_section_asm_out_constructor (rtx symbol,
1475 int priority ATTRIBUTE_UNUSED)
1477 assemble_addr_to_section (symbol, ctors_section);
1481 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1482 a nonzero value if the constant pool should be output before the
1483 start of the function, or a zero value if the pool should output
1484 after the end of the function. The default is to put it before the
1487 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1488 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1491 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1492 to be output to assembler.
1493 Set first_global_object_name and weak_global_object_name as appropriate. */
1496 notice_global_symbol (tree decl)
1498 const char **type = &first_global_object_name;
1500 if (first_global_object_name
1501 || !TREE_PUBLIC (decl)
1502 || DECL_EXTERNAL (decl)
1503 || !DECL_NAME (decl)
1504 || (TREE_CODE (decl) != FUNCTION_DECL
1505 && (TREE_CODE (decl) != VAR_DECL
1506 || (DECL_COMMON (decl)
1507 && (DECL_INITIAL (decl) == 0
1508 || DECL_INITIAL (decl) == error_mark_node))))
1509 || !MEM_P (DECL_RTL (decl)))
1512 /* We win when global object is found, but it is useful to know about weak
1513 symbol as well so we can produce nicer unique names. */
1514 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1515 type = &weak_global_object_name;
1521 rtx decl_rtl = DECL_RTL (decl);
1523 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1524 name = ggc_strdup (p);
1530 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1531 current function goes into the cold section, so that targets can use
1532 current_function_section during RTL expansion. DECL describes the
1536 decide_function_section (tree decl)
1538 first_function_block_is_cold = false;
1540 if (flag_reorder_blocks_and_partition)
1541 /* We will decide in assemble_start_function. */
1544 if (DECL_SECTION_NAME (decl))
1546 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1547 /* Calls to function_section rely on first_function_block_is_cold
1549 first_function_block_is_cold = (node
1551 == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1554 in_cold_section_p = first_function_block_is_cold;
1557 /* Output assembler code for the constant pool of a function and associated
1558 with defining the name of the function. DECL describes the function.
1559 NAME is the function's name. For the constant pool, we use the current
1560 constant pool data. */
1563 assemble_start_function (tree decl, const char *fnname)
1566 char tmp_label[100];
1567 bool hot_label_written = false;
1569 if (flag_reorder_blocks_and_partition)
1571 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1572 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1573 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1574 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1575 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1576 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1577 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1578 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1583 crtl->subsections.hot_section_label = NULL;
1584 crtl->subsections.cold_section_label = NULL;
1585 crtl->subsections.hot_section_end_label = NULL;
1586 crtl->subsections.cold_section_end_label = NULL;
1589 /* The following code does not need preprocessing in the assembler. */
1593 if (CONSTANT_POOL_BEFORE_FUNCTION)
1594 output_constant_pool (fnname, decl);
1596 /* Make sure the not and cold text (code) sections are properly
1597 aligned. This is necessary here in the case where the function
1598 has both hot and cold sections, because we don't want to re-set
1599 the alignment when the section switch happens mid-function. */
1601 if (flag_reorder_blocks_and_partition)
1603 first_function_block_is_cold = false;
1605 switch_to_section (unlikely_text_section ());
1606 assemble_align (DECL_ALIGN (decl));
1607 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1609 /* When the function starts with a cold section, we need to explicitly
1610 align the hot section and write out the hot section label.
1611 But if the current function is a thunk, we do not have a CFG. */
1613 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1615 switch_to_section (text_section);
1616 assemble_align (DECL_ALIGN (decl));
1617 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1618 hot_label_written = true;
1619 first_function_block_is_cold = true;
1621 in_cold_section_p = first_function_block_is_cold;
1625 /* Switch to the correct text section for the start of the function. */
1627 switch_to_section (function_section (decl));
1628 if (flag_reorder_blocks_and_partition
1629 && !hot_label_written)
1630 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1632 /* Tell assembler to move to target machine's alignment for functions. */
1633 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1636 ASM_OUTPUT_ALIGN (asm_out_file, align);
1639 /* Handle a user-specified function alignment.
1640 Note that we still need to align to DECL_ALIGN, as above,
1641 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1642 if (! DECL_USER_ALIGN (decl)
1643 && align_functions_log > align
1644 && optimize_function_for_speed_p (cfun))
1646 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1647 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1648 align_functions_log, align_functions - 1);
1650 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1654 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1655 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1658 if (!DECL_IGNORED_P (decl))
1659 (*debug_hooks->begin_function) (decl);
1661 /* Make function name accessible from other files, if appropriate. */
1663 if (TREE_PUBLIC (decl))
1665 notice_global_symbol (decl);
1667 globalize_decl (decl);
1669 maybe_assemble_visibility (decl);
1672 if (DECL_PRESERVE_P (decl))
1673 targetm.asm_out.mark_decl_preserved (fnname);
1675 /* Do any machine/system dependent processing of the function name. */
1676 #ifdef ASM_DECLARE_FUNCTION_NAME
1677 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1679 /* Standard thing is just output label for the function. */
1680 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1681 #endif /* ASM_DECLARE_FUNCTION_NAME */
1683 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
1684 saw_no_split_stack = true;
1687 /* Output assembler code associated with defining the size of the
1688 function. DECL describes the function. NAME is the function's name. */
1691 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1693 #ifdef ASM_DECLARE_FUNCTION_SIZE
1694 /* We could have switched section in the middle of the function. */
1695 if (flag_reorder_blocks_and_partition)
1696 switch_to_section (function_section (decl));
1697 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1699 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1701 output_constant_pool (fnname, decl);
1702 switch_to_section (function_section (decl)); /* need to switch back */
1704 /* Output labels for end of hot/cold text sections (to be used by
1706 if (flag_reorder_blocks_and_partition)
1708 section *save_text_section;
1710 save_text_section = in_section;
1711 switch_to_section (unlikely_text_section ());
1712 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1713 if (first_function_block_is_cold)
1714 switch_to_section (text_section);
1716 switch_to_section (function_section (decl));
1717 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1718 switch_to_section (save_text_section);
1722 /* Assemble code to leave SIZE bytes of zeros. */
1725 assemble_zeros (unsigned HOST_WIDE_INT size)
1727 /* Do no output if -fsyntax-only. */
1728 if (flag_syntax_only)
1731 #ifdef ASM_NO_SKIP_IN_TEXT
1732 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1733 so we must output 0s explicitly in the text section. */
1734 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1736 unsigned HOST_WIDE_INT i;
1737 for (i = 0; i < size; i++)
1738 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1743 ASM_OUTPUT_SKIP (asm_out_file, size);
1746 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1749 assemble_align (int align)
1751 if (align > BITS_PER_UNIT)
1753 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1757 /* Assemble a string constant with the specified C string as contents. */
1760 assemble_string (const char *p, int size)
1765 /* If the string is very long, split it up. */
1769 int thissize = size - pos;
1770 if (thissize > maximum)
1773 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1781 /* A noswitch_section_callback for lcomm_section. */
1784 emit_local (tree decl ATTRIBUTE_UNUSED,
1785 const char *name ATTRIBUTE_UNUSED,
1786 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1787 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1789 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1790 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1791 size, DECL_ALIGN (decl));
1793 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1794 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1797 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1802 /* A noswitch_section_callback for bss_noswitch_section. */
1804 #if defined ASM_OUTPUT_ALIGNED_BSS
1806 emit_bss (tree decl ATTRIBUTE_UNUSED,
1807 const char *name ATTRIBUTE_UNUSED,
1808 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1809 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1811 #if defined ASM_OUTPUT_ALIGNED_BSS
1812 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1818 /* A noswitch_section_callback for comm_section. */
1821 emit_common (tree decl ATTRIBUTE_UNUSED,
1822 const char *name ATTRIBUTE_UNUSED,
1823 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1824 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1826 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1827 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1828 size, DECL_ALIGN (decl));
1830 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1831 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1834 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1839 /* A noswitch_section_callback for tls_comm_section. */
1842 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1843 const char *name ATTRIBUTE_UNUSED,
1844 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1845 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1847 #ifdef ASM_OUTPUT_TLS_COMMON
1848 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1851 sorry ("thread-local COMMON data not implemented");
1856 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1857 NAME is the name of DECL's SYMBOL_REF. */
1860 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1862 unsigned HOST_WIDE_INT size, rounded;
1864 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1867 /* Don't allocate zero bytes of common,
1868 since that means "undefined external" in the linker. */
1872 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1873 so that each uninitialized object starts on such a boundary. */
1874 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1875 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1876 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1878 if (!sect->noswitch.callback (decl, name, size, rounded)
1879 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1880 warning (0, "requested alignment for %q+D is greater than "
1881 "implemented alignment of %wu", decl, rounded);
1884 /* A subroutine of assemble_variable. Output the label and contents of
1885 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1886 is as for assemble_variable. */
1889 assemble_variable_contents (tree decl, const char *name,
1890 bool dont_output_data)
1892 /* Do any machine/system dependent processing of the object. */
1893 #ifdef ASM_DECLARE_OBJECT_NAME
1894 last_assemble_variable_decl = decl;
1895 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1897 /* Standard thing is just output label for the object. */
1898 ASM_OUTPUT_LABEL (asm_out_file, name);
1899 #endif /* ASM_DECLARE_OBJECT_NAME */
1901 if (!dont_output_data)
1903 if (DECL_INITIAL (decl)
1904 && DECL_INITIAL (decl) != error_mark_node
1905 && !initializer_zerop (DECL_INITIAL (decl)))
1906 /* Output the actual data. */
1907 output_constant (DECL_INITIAL (decl),
1908 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1911 /* Leave space for it. */
1912 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1916 /* Assemble everything that is needed for a variable or function declaration.
1917 Not used for automatic variables, and not used for function definitions.
1918 Should not be called for variables of incomplete structure type.
1920 TOP_LEVEL is nonzero if this variable has file scope.
1921 AT_END is nonzero if this is the special handling, at end of compilation,
1922 to define things that have had only tentative definitions.
1923 DONT_OUTPUT_DATA if nonzero means don't actually output the
1924 initial value (that will be done by the caller). */
1927 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1928 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1931 rtx decl_rtl, symbol;
1934 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1935 gcc_assert (TREE_CODE (decl) == VAR_DECL);
1937 /* Emulated TLS had better not get this far. */
1938 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
1940 last_assemble_variable_decl = 0;
1942 /* Normally no need to say anything here for external references,
1943 since assemble_external is called by the language-specific code
1944 when a declaration is first seen. */
1946 if (DECL_EXTERNAL (decl))
1949 /* Do nothing for global register variables. */
1950 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1952 TREE_ASM_WRITTEN (decl) = 1;
1956 /* If type was incomplete when the variable was declared,
1957 see if it is complete now. */
1959 if (DECL_SIZE (decl) == 0)
1960 layout_decl (decl, 0);
1962 /* Still incomplete => don't allocate it; treat the tentative defn
1963 (which is what it must have been) as an `extern' reference. */
1965 if (!dont_output_data && DECL_SIZE (decl) == 0)
1967 error ("storage size of %q+D isn%'t known", decl);
1968 TREE_ASM_WRITTEN (decl) = 1;
1972 /* The first declaration of a variable that comes through this function
1973 decides whether it is global (in C, has external linkage)
1974 or local (in C, has internal linkage). So do nothing more
1975 if this function has already run. */
1977 if (TREE_ASM_WRITTEN (decl))
1980 /* Make sure targetm.encode_section_info is invoked before we set
1982 decl_rtl = DECL_RTL (decl);
1984 TREE_ASM_WRITTEN (decl) = 1;
1986 /* Do no output if -fsyntax-only. */
1987 if (flag_syntax_only)
1990 if (! dont_output_data
1991 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1993 error ("size of variable %q+D is too large", decl);
1997 gcc_assert (MEM_P (decl_rtl));
1998 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
1999 symbol = XEXP (decl_rtl, 0);
2001 /* If this symbol belongs to the tree constant pool, output the constant
2002 if it hasn't already been written. */
2003 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2005 tree decl = SYMBOL_REF_DECL (symbol);
2006 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2007 output_constant_def_contents (symbol);
2013 name = XSTR (symbol, 0);
2014 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2015 notice_global_symbol (decl);
2017 /* Compute the alignment of this data. */
2019 align_variable (decl, dont_output_data);
2020 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2022 if (TREE_PUBLIC (decl))
2023 maybe_assemble_visibility (decl);
2025 if (DECL_PRESERVE_P (decl))
2026 targetm.asm_out.mark_decl_preserved (name);
2028 /* First make the assembler name(s) global if appropriate. */
2029 sect = get_variable_section (decl, false);
2030 if (TREE_PUBLIC (decl)
2031 && (sect->common.flags & SECTION_COMMON) == 0)
2032 globalize_decl (decl);
2034 /* Output any data that we will need to use the address of. */
2035 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2036 output_addressed_constants (DECL_INITIAL (decl));
2038 /* dbxout.c needs to know this. */
2039 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2040 DECL_IN_TEXT_SECTION (decl) = 1;
2042 /* If the decl is part of an object_block, make sure that the decl
2043 has been positioned within its block, but do not write out its
2044 definition yet. output_object_blocks will do that later. */
2045 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2047 gcc_assert (!dont_output_data);
2048 place_block_symbol (symbol);
2050 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2051 assemble_noswitch_variable (decl, name, sect);
2054 switch_to_section (sect);
2055 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2056 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2057 assemble_variable_contents (decl, name, dont_output_data);
2061 /* Return 1 if type TYPE contains any pointers. */
2064 contains_pointers_p (tree type)
2066 switch (TREE_CODE (type))
2069 case REFERENCE_TYPE:
2070 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2071 so I'll play safe and return 1. */
2077 case QUAL_UNION_TYPE:
2080 /* For a type that has fields, see if the fields have pointers. */
2081 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2082 if (TREE_CODE (fields) == FIELD_DECL
2083 && contains_pointers_p (TREE_TYPE (fields)))
2089 /* An array type contains pointers if its element type does. */
2090 return contains_pointers_p (TREE_TYPE (type));
2097 /* We delay assemble_external processing until
2098 the compilation unit is finalized. This is the best we can do for
2099 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2100 it all the way to final. See PR 17982 for further discussion. */
2101 static GTY(()) tree pending_assemble_externals;
2103 /* FIXME: Trunk is at GCC 4.8 now and the above problem still hasn't been
2104 addressed properly. This caused PR 52640 due to O(external_decls**2)
2105 lookups in the pending_assemble_externals TREE_LIST in assemble_external.
2106 Paper over with this pointer set, which we use to see if we have already
2107 added a decl to pending_assemble_externals without first traversing
2108 the entire pending_assemble_externals list. See assemble_external(). */
2109 static struct pointer_set_t *pending_assemble_externals_set;
2111 /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2112 As a result, assemble_external can be called after the list of externals
2113 is processed and the pointer set destroyed. */
2114 static bool pending_assemble_externals_processed;
2116 #ifdef ASM_OUTPUT_EXTERNAL
2117 /* True if DECL is a function decl for which no out-of-line copy exists.
2118 It is assumed that DECL's assembler name has been set. */
2121 incorporeal_function_p (tree decl)
2123 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2127 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2128 && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
2129 || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
2132 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2133 /* Atomic or sync builtins which have survived this far will be
2134 resolved externally and therefore are not incorporeal. */
2135 if (strncmp (name, "__builtin_", 10) == 0)
2141 /* Actually do the tests to determine if this is necessary, and invoke
2142 ASM_OUTPUT_EXTERNAL. */
2144 assemble_external_real (tree decl)
2146 rtx rtl = DECL_RTL (decl);
2148 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2149 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2150 && !incorporeal_function_p (decl))
2152 /* Some systems do require some output. */
2153 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2154 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2160 process_pending_assemble_externals (void)
2162 #ifdef ASM_OUTPUT_EXTERNAL
2164 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2165 assemble_external_real (TREE_VALUE (list));
2167 pending_assemble_externals = 0;
2168 pending_assemble_externals_processed = true;
2169 pointer_set_destroy (pending_assemble_externals_set);
2173 /* This TREE_LIST contains any weak symbol declarations waiting
2175 static GTY(()) tree weak_decls;
2177 /* Output something to declare an external symbol to the assembler,
2178 and qualifiers such as weakness. (Most assemblers don't need
2179 extern declaration, so we normally output nothing.) Do nothing if
2180 DECL is not external. */
2183 assemble_external (tree decl ATTRIBUTE_UNUSED)
2185 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2186 main body of this code is only rarely exercised. To provide some
2187 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2188 open. If it's not, we should not be calling this function. */
2189 gcc_assert (asm_out_file);
2191 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2194 /* We want to output annotation for weak and external symbols at
2195 very last to check if they are references or not. */
2197 if (TARGET_SUPPORTS_WEAK
2199 /* TREE_STATIC is a weird and abused creature which is not
2200 generally the right test for whether an entity has been
2201 locally emitted, inlined or otherwise not-really-extern, but
2202 for declarations that can be weak, it happens to be
2204 && !TREE_STATIC (decl)
2205 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2206 && value_member (decl, weak_decls) == NULL_TREE)
2207 weak_decls = tree_cons (NULL, decl, weak_decls);
2209 #ifdef ASM_OUTPUT_EXTERNAL
2210 if (pending_assemble_externals_processed)
2212 assemble_external_real (decl);
2216 if (! pointer_set_insert (pending_assemble_externals_set, decl))
2217 pending_assemble_externals = tree_cons (NULL, decl,
2218 pending_assemble_externals);
2222 /* Similar, for calling a library function FUN. */
2225 assemble_external_libcall (rtx fun)
2227 /* Declare library function name external when first used, if nec. */
2228 if (! SYMBOL_REF_USED (fun))
2230 SYMBOL_REF_USED (fun) = 1;
2231 targetm.asm_out.external_libcall (fun);
2235 /* Assemble a label named NAME. */
2238 assemble_label (FILE *file, const char *name)
2240 ASM_OUTPUT_LABEL (file, name);
2243 /* Set the symbol_referenced flag for ID. */
2245 mark_referenced (tree id)
2247 TREE_SYMBOL_REFERENCED (id) = 1;
2250 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2252 mark_decl_referenced (tree decl)
2254 if (TREE_CODE (decl) == FUNCTION_DECL)
2256 /* Extern inline functions don't become needed when referenced.
2257 If we know a method will be emitted in other TU and no new
2258 functions can be marked reachable, just use the external
2260 struct cgraph_node *node = cgraph_get_create_node (decl);
2261 if (!DECL_EXTERNAL (decl)
2262 && !node->local.finalized)
2263 cgraph_mark_needed_node (node);
2265 else if (TREE_CODE (decl) == VAR_DECL)
2267 struct varpool_node *node = varpool_node (decl);
2268 varpool_mark_needed_node (node);
2269 /* C++ frontend use mark_decl_references to force COMDAT variables
2270 to be output that might appear dead otherwise. */
2271 node->force_output = true;
2273 /* else do nothing - we can get various sorts of CST nodes here,
2274 which do not need to be marked. */
2278 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2279 until we find an identifier that is not itself a transparent alias.
2280 Modify the alias passed to it by reference (and all aliases on the
2281 way to the ultimate target), such that they do not have to be
2282 followed again, and return the ultimate target of the alias
2286 ultimate_transparent_alias_target (tree *alias)
2288 tree target = *alias;
2290 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2292 gcc_assert (TREE_CHAIN (target));
2293 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2294 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2295 && ! TREE_CHAIN (target));
2302 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2303 starts with a *, the rest of NAME is output verbatim. Otherwise
2304 NAME is transformed in a target-specific way (usually by the
2305 addition of an underscore). */
2308 assemble_name_raw (FILE *file, const char *name)
2311 fputs (&name[1], file);
2313 ASM_OUTPUT_LABELREF (file, name);
2316 /* Like assemble_name_raw, but should be used when NAME might refer to
2317 an entity that is also represented as a tree (like a function or
2318 variable). If NAME does refer to such an entity, that entity will
2319 be marked as referenced. */
2322 assemble_name (FILE *file, const char *name)
2324 const char *real_name;
2327 real_name = targetm.strip_name_encoding (name);
2329 id = maybe_get_identifier (real_name);
2334 mark_referenced (id);
2335 ultimate_transparent_alias_target (&id);
2337 name = IDENTIFIER_POINTER (id);
2338 gcc_assert (! TREE_CHAIN (id));
2341 assemble_name_raw (file, name);
2344 /* Allocate SIZE bytes writable static space with a gensym name
2345 and return an RTX to refer to its address. */
2348 assemble_static_space (unsigned HOST_WIDE_INT size)
2351 const char *namestring;
2354 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2356 namestring = ggc_strdup (name);
2358 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2359 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2361 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2362 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2365 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2366 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2369 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2370 so that each uninitialized object starts on such a boundary. */
2371 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2372 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2373 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2374 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2375 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2376 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2383 /* Assemble the static constant template for function entry trampolines.
2384 This is done at most once per compilation.
2385 Returns an RTX for the address of the template. */
2387 static GTY(()) rtx initial_trampoline;
2390 assemble_trampoline_template (void)
2397 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2399 if (initial_trampoline)
2400 return initial_trampoline;
2402 /* By default, put trampoline templates in read-only data section. */
2404 #ifdef TRAMPOLINE_SECTION
2405 switch_to_section (TRAMPOLINE_SECTION);
2407 switch_to_section (readonly_data_section);
2410 /* Write the assembler code to define one. */
2411 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2413 ASM_OUTPUT_ALIGN (asm_out_file, align);
2415 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2416 targetm.asm_out.trampoline_template (asm_out_file);
2418 /* Record the rtl to refer to it. */
2419 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2420 name = ggc_strdup (label);
2421 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2422 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2424 initial_trampoline = gen_const_mem (BLKmode, symbol);
2425 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2426 set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
2428 return initial_trampoline;
2431 /* A and B are either alignments or offsets. Return the minimum alignment
2432 that may be assumed after adding the two together. */
2434 static inline unsigned
2435 min_align (unsigned int a, unsigned int b)
2437 return (a | b) & -(a | b);
2440 /* Return the assembler directive for creating a given kind of integer
2441 object. SIZE is the number of bytes in the object and ALIGNED_P
2442 indicates whether it is known to be aligned. Return NULL if the
2443 assembly dialect has no such directive.
2445 The returned string should be printed at the start of a new line and
2446 be followed immediately by the object's initial value. */
2449 integer_asm_op (int size, int aligned_p)
2451 struct asm_int_op *ops;
2454 ops = &targetm.asm_out.aligned_op;
2456 ops = &targetm.asm_out.unaligned_op;
2461 return targetm.asm_out.byte_op;
2475 /* Use directive OP to assemble an integer object X. Print OP at the
2476 start of the line, followed immediately by the value of X. */
2479 assemble_integer_with_op (const char *op, rtx x)
2481 fputs (op, asm_out_file);
2482 output_addr_const (asm_out_file, x);
2483 fputc ('\n', asm_out_file);
2486 /* The default implementation of the asm_out.integer target hook. */
2489 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2490 unsigned int size ATTRIBUTE_UNUSED,
2491 int aligned_p ATTRIBUTE_UNUSED)
2493 const char *op = integer_asm_op (size, aligned_p);
2494 /* Avoid GAS bugs for large values. Specifically negative values whose
2495 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2496 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2498 return op && (assemble_integer_with_op (op, x), true);
2501 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2502 the alignment of the integer in bits. Return 1 if we were able to output
2503 the constant, otherwise 0. We must be able to output the constant,
2504 if FORCE is nonzero. */
2507 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2511 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2513 /* See if the target hook can handle this kind of object. */
2514 if (targetm.asm_out.integer (x, size, aligned_p))
2517 /* If the object is a multi-byte one, try splitting it up. Split
2518 it into words it if is multi-word, otherwise split it into bytes. */
2521 enum machine_mode omode, imode;
2522 unsigned int subalign;
2523 unsigned int subsize, i;
2524 enum mode_class mclass;
2526 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2527 subalign = MIN (align, subsize * BITS_PER_UNIT);
2528 if (GET_CODE (x) == CONST_FIXED)
2529 mclass = GET_MODE_CLASS (GET_MODE (x));
2533 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2534 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2536 for (i = 0; i < size; i += subsize)
2538 rtx partial = simplify_subreg (omode, x, imode, i);
2539 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2545 /* If we've printed some of it, but not all of it, there's no going
2550 gcc_assert (!force);
2556 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2558 long data[4] = {0, 0, 0, 0};
2560 int bitsize, nelts, nunits, units_per;
2562 /* This is hairy. We have a quantity of known size. real_to_target
2563 will put it into an array of *host* longs, 32 bits per element
2564 (even if long is more than 32 bits). We need to determine the
2565 number of array elements that are occupied (nelts) and the number
2566 of *target* min-addressable units that will be occupied in the
2567 object file (nunits). We cannot assume that 32 divides the
2568 mode's bitsize (size * BITS_PER_UNIT) evenly.
2570 size * BITS_PER_UNIT is used here to make sure that padding bits
2571 (which might appear at either end of the value; real_to_target
2572 will include the padding bits in its output array) are included. */
2574 nunits = GET_MODE_SIZE (mode);
2575 bitsize = nunits * BITS_PER_UNIT;
2576 nelts = CEIL (bitsize, 32);
2577 units_per = 32 / BITS_PER_UNIT;
2579 real_to_target (data, &d, mode);
2581 /* Put out the first word with the specified alignment. */
2582 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2583 nunits -= units_per;
2585 /* Subsequent words need only 32-bit alignment. */
2586 align = min_align (align, 32);
2588 for (i = 1; i < nelts; i++)
2590 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2591 nunits -= units_per;
2595 /* Given an expression EXP with a constant value,
2596 reduce it to the sum of an assembler symbol and an integer.
2597 Store them both in the structure *VALUE.
2598 EXP must be reducible. */
2602 HOST_WIDE_INT offset;
2606 decode_addr_const (tree exp, struct addr_const *value)
2608 tree target = TREE_OPERAND (exp, 0);
2614 if (TREE_CODE (target) == COMPONENT_REF
2615 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2617 offset += int_byte_position (TREE_OPERAND (target, 1));
2618 target = TREE_OPERAND (target, 0);
2620 else if (TREE_CODE (target) == ARRAY_REF
2621 || TREE_CODE (target) == ARRAY_RANGE_REF)
2623 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2624 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2625 target = TREE_OPERAND (target, 0);
2627 else if (TREE_CODE (target) == MEM_REF
2628 && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
2630 offset += mem_ref_offset (target).low;
2631 target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
2633 else if (TREE_CODE (target) == INDIRECT_REF
2634 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2635 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2637 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2642 switch (TREE_CODE (target))
2646 x = DECL_RTL (target);
2650 x = gen_rtx_MEM (FUNCTION_MODE,
2651 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2660 x = output_constant_def (target, 1);
2667 gcc_assert (MEM_P (x));
2671 value->offset = offset;
2675 static GTY((param_is (struct constant_descriptor_tree)))
2676 htab_t const_desc_htab;
2678 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2680 /* Constant pool accessor function. */
2683 constant_pool_htab (void)
2685 return const_desc_htab;
2688 /* Compute a hash code for a constant expression. */
2691 const_desc_hash (const void *ptr)
2693 return ((const struct constant_descriptor_tree *)ptr)->hash;
2697 const_hash_1 (const tree exp)
2702 enum tree_code code = TREE_CODE (exp);
2704 /* Either set P and LEN to the address and len of something to hash and
2705 exit the switch or return a value. */
2710 p = (char *) &TREE_INT_CST (exp);
2711 len = sizeof TREE_INT_CST (exp);
2715 return real_hash (TREE_REAL_CST_PTR (exp));
2718 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2721 p = TREE_STRING_POINTER (exp);
2722 len = TREE_STRING_LENGTH (exp);
2726 return (const_hash_1 (TREE_REALPART (exp)) * 5
2727 + const_hash_1 (TREE_IMAGPART (exp)));
2733 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2735 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2736 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2743 unsigned HOST_WIDE_INT idx;
2746 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2748 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2750 hi = hi * 603 + const_hash_1 (value);
2758 struct addr_const value;
2760 decode_addr_const (exp, &value);
2761 switch (GET_CODE (value.base))
2764 /* Don't hash the address of the SYMBOL_REF;
2765 only use the offset and the symbol name. */
2767 p = XSTR (value.base, 0);
2768 for (i = 0; p[i] != 0; i++)
2769 hi = ((hi * 613) + (unsigned) (p[i]));
2773 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2783 case POINTER_PLUS_EXPR:
2785 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2786 + const_hash_1 (TREE_OPERAND (exp, 1)));
2789 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2792 /* A language specific constant. Just hash the code. */
2796 /* Compute hashing function. */
2798 for (i = 0; i < len; i++)
2799 hi = ((hi * 613) + (unsigned) (p[i]));
2804 /* Wrapper of compare_constant, for the htab interface. */
2806 const_desc_eq (const void *p1, const void *p2)
2808 const struct constant_descriptor_tree *const c1
2809 = (const struct constant_descriptor_tree *) p1;
2810 const struct constant_descriptor_tree *const c2
2811 = (const struct constant_descriptor_tree *) p2;
2812 if (c1->hash != c2->hash)
2814 return compare_constant (c1->value, c2->value);
2817 /* Compare t1 and t2, and return 1 only if they are known to result in
2818 the same bit pattern on output. */
2821 compare_constant (const tree t1, const tree t2)
2823 enum tree_code typecode;
2825 if (t1 == NULL_TREE)
2826 return t2 == NULL_TREE;
2827 if (t2 == NULL_TREE)
2830 if (TREE_CODE (t1) != TREE_CODE (t2))
2833 switch (TREE_CODE (t1))
2836 /* Integer constants are the same only if the same width of type. */
2837 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2839 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2841 return tree_int_cst_equal (t1, t2);
2844 /* Real constants are the same only if the same width of type. */
2845 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2848 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2851 /* Fixed constants are the same only if the same width of type. */
2852 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2855 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2858 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2861 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2862 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2863 TREE_STRING_LENGTH (t1)));
2866 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2867 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2873 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
2874 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
2877 link2 = TREE_VECTOR_CST_ELTS (t2);
2878 for (link1 = TREE_VECTOR_CST_ELTS (t1);
2880 link1 = TREE_CHAIN (link1))
2882 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
2884 link2 = TREE_CHAIN (link2);
2892 VEC(constructor_elt, gc) *v1, *v2;
2893 unsigned HOST_WIDE_INT idx;
2895 typecode = TREE_CODE (TREE_TYPE (t1));
2896 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2899 if (typecode == ARRAY_TYPE)
2901 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2902 /* For arrays, check that the sizes all match. */
2903 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2905 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2910 /* For record and union constructors, require exact type
2912 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2916 v1 = CONSTRUCTOR_ELTS (t1);
2917 v2 = CONSTRUCTOR_ELTS (t2);
2918 if (VEC_length (constructor_elt, v1)
2919 != VEC_length (constructor_elt, v2))
2922 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2924 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2925 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2927 /* Check that each value is the same... */
2928 if (!compare_constant (c1->value, c2->value))
2930 /* ... and that they apply to the same fields! */
2931 if (typecode == ARRAY_TYPE)
2933 if (!compare_constant (c1->index, c2->index))
2938 if (c1->index != c2->index)
2949 struct addr_const value1, value2;
2953 decode_addr_const (t1, &value1);
2954 decode_addr_const (t2, &value2);
2956 if (value1.offset != value2.offset)
2959 code = GET_CODE (value1.base);
2960 if (code != GET_CODE (value2.base))
2966 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2970 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
2971 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
2981 case POINTER_PLUS_EXPR:
2984 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2985 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2988 case VIEW_CONVERT_EXPR:
2989 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2998 /* Make a copy of the whole tree structure for a constant. This
2999 handles the same types of nodes that compare_constant handles. */
3002 copy_constant (tree exp)
3004 switch (TREE_CODE (exp))
3007 /* For ADDR_EXPR, we do not want to copy the decl whose address
3008 is requested. We do want to copy constants though. */
3009 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3010 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3011 copy_constant (TREE_OPERAND (exp, 0)));
3013 return copy_node (exp);
3019 return copy_node (exp);
3022 return build_complex (TREE_TYPE (exp),
3023 copy_constant (TREE_REALPART (exp)),
3024 copy_constant (TREE_IMAGPART (exp)));
3027 case POINTER_PLUS_EXPR:
3029 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3030 copy_constant (TREE_OPERAND (exp, 0)),
3031 copy_constant (TREE_OPERAND (exp, 1)));
3034 case VIEW_CONVERT_EXPR:
3035 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3036 copy_constant (TREE_OPERAND (exp, 0)));
3039 return build_vector (TREE_TYPE (exp),
3040 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3044 tree copy = copy_node (exp);
3045 VEC(constructor_elt, gc) *v;
3046 unsigned HOST_WIDE_INT idx;
3047 tree purpose, value;
3049 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3050 CONSTRUCTOR_ELTS (exp)));
3051 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3053 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3054 ce->index = purpose;
3055 ce->value = copy_constant (value);
3057 CONSTRUCTOR_ELTS (copy) = v;
3066 /* Return the section into which constant EXP should be placed. */
3069 get_constant_section (tree exp, unsigned int align)
3071 return targetm.asm_out.select_section (exp,
3072 compute_reloc_for_constant (exp),
3076 /* Return the size of constant EXP in bytes. */
3078 static HOST_WIDE_INT
3079 get_constant_size (tree exp)
3083 size = int_size_in_bytes (TREE_TYPE (exp));
3084 if (TREE_CODE (exp) == STRING_CST)
3085 size = MAX (TREE_STRING_LENGTH (exp), size);
3089 /* Subroutine of output_constant_def:
3090 No constant equal to EXP is known to have been output.
3091 Make a constant descriptor to enter EXP in the hash table.
3092 Assign the label number and construct RTL to refer to the
3093 constant's location in memory.
3094 Caller is responsible for updating the hash table. */
3096 static struct constant_descriptor_tree *
3097 build_constant_desc (tree exp)
3099 struct constant_descriptor_tree *desc;
3105 desc = ggc_alloc_constant_descriptor_tree ();
3106 desc->value = copy_constant (exp);
3108 /* Propagate marked-ness to copied constant. */
3109 if (flag_mudflap && mf_marked_p (exp))
3110 mf_mark (desc->value);
3112 /* Create a string containing the label name, in LABEL. */
3113 labelno = const_labelno++;
3114 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3116 /* Construct the VAR_DECL associated with the constant. */
3117 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3119 DECL_ARTIFICIAL (decl) = 1;
3120 DECL_IGNORED_P (decl) = 1;
3121 TREE_READONLY (decl) = 1;
3122 TREE_STATIC (decl) = 1;
3123 TREE_ADDRESSABLE (decl) = 1;
3124 /* We don't set the RTL yet as this would cause varpool to assume that the
3125 variable is referenced. Moreover, it would just be dropped in LTO mode.
3126 Instead we set the flag that will be recognized in make_decl_rtl. */
3127 DECL_IN_CONSTANT_POOL (decl) = 1;
3128 DECL_INITIAL (decl) = desc->value;
3129 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3130 architectures so use DATA_ALIGNMENT as well, except for strings. */
3131 if (TREE_CODE (exp) == STRING_CST)
3133 #ifdef CONSTANT_ALIGNMENT
3134 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3138 align_variable (decl, 0);
3140 /* Now construct the SYMBOL_REF and the MEM. */
3141 if (use_object_blocks_p ())
3143 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3144 symbol = create_block_symbol (ggc_strdup (label),
3145 get_block_for_section (sect), -1);
3148 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3149 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3150 SET_SYMBOL_REF_DECL (symbol, decl);
3151 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3153 rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3154 set_mem_attributes (rtl, exp, 1);
3155 set_mem_alias_set (rtl, 0);
3156 set_mem_alias_set (rtl, const_alias_set);
3158 /* We cannot share RTX'es in pool entries.
3159 Mark this piece of RTL as required for unsharing. */
3160 RTX_FLAG (rtl, used) = 1;
3162 /* Set flags or add text to the name to record information, such as
3163 that it is a local symbol. If the name is changed, the macro
3164 ASM_OUTPUT_LABELREF will have to know how to strip this
3165 information. This call might invalidate our local variable
3166 SYMBOL; we can't use it afterward. */
3167 targetm.encode_section_info (exp, rtl, true);
3174 /* Return an rtx representing a reference to constant data in memory
3175 for the constant expression EXP.
3177 If assembler code for such a constant has already been output,
3178 return an rtx to refer to it.
3179 Otherwise, output such a constant in memory
3180 and generate an rtx for it.
3182 If DEFER is nonzero, this constant can be deferred and output only
3183 if referenced in the function after all optimizations.
3185 `const_desc_table' records which constants already have label strings. */
3188 output_constant_def (tree exp, int defer)
3190 struct constant_descriptor_tree *desc;
3191 struct constant_descriptor_tree key;
3194 /* Look up EXP in the table of constant descriptors. If we didn't find
3195 it, create a new one. */
3197 key.hash = const_hash_1 (exp);
3198 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3200 desc = (struct constant_descriptor_tree *) *loc;
3203 desc = build_constant_desc (exp);
3204 desc->hash = key.hash;
3208 maybe_output_constant_def_contents (desc, defer);
3212 /* Subroutine of output_constant_def: Decide whether or not we need to
3213 output the constant DESC now, and if so, do it. */
3215 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3218 rtx symbol = XEXP (desc->rtl, 0);
3219 tree exp = desc->value;
3221 if (flag_syntax_only)
3224 if (TREE_ASM_WRITTEN (exp))
3225 /* Already output; don't do it again. */
3228 /* We can always defer constants as long as the context allows
3232 /* Increment n_deferred_constants if it exists. It needs to be at
3233 least as large as the number of constants actually referred to
3234 by the function. If it's too small we'll stop looking too early
3235 and fail to emit constants; if it's too large we'll only look
3236 through the entire function when we could have stopped earlier. */
3238 n_deferred_constants++;
3242 output_constant_def_contents (symbol);
3245 /* Subroutine of output_constant_def_contents. Output the definition
3246 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3247 constant's alignment in bits. */
3250 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3254 size = get_constant_size (exp);
3256 /* Do any machine/system dependent processing of the constant. */
3257 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3259 /* Output the value of EXP. */
3260 output_constant (exp, size, align);
3263 /* We must output the constant data referred to by SYMBOL; do so. */
3266 output_constant_def_contents (rtx symbol)
3268 tree decl = SYMBOL_REF_DECL (symbol);
3269 tree exp = DECL_INITIAL (decl);
3272 /* Make sure any other constants whose addresses appear in EXP
3273 are assigned label numbers. */
3274 output_addressed_constants (exp);
3276 /* We are no longer deferring this constant. */
3277 TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3279 /* If the constant is part of an object block, make sure that the
3280 decl has been positioned within its block, but do not write out
3281 its definition yet. output_object_blocks will do that later. */
3282 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3283 place_block_symbol (symbol);
3286 align = DECL_ALIGN (decl);
3287 switch_to_section (get_constant_section (exp, align));
3288 if (align > BITS_PER_UNIT)
3289 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3290 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3293 mudflap_enqueue_constant (exp);
3296 /* Look up EXP in the table of constant descriptors. Return the rtl
3297 if it has been emitted, else null. */
3300 lookup_constant_def (tree exp)
3302 struct constant_descriptor_tree *desc;
3303 struct constant_descriptor_tree key;
3306 key.hash = const_hash_1 (exp);
3307 desc = (struct constant_descriptor_tree *)
3308 htab_find_with_hash (const_desc_htab, &key, key.hash);
3310 return (desc ? desc->rtl : NULL_RTX);
3313 /* Return a tree representing a reference to constant data in memory
3314 for the constant expression EXP.
3316 This is the counterpart of output_constant_def at the Tree level. */
3319 tree_output_constant_def (tree exp)
3321 struct constant_descriptor_tree *desc, key;
3325 /* Look up EXP in the table of constant descriptors. If we didn't find
3326 it, create a new one. */
3328 key.hash = const_hash_1 (exp);
3329 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3331 desc = (struct constant_descriptor_tree *) *loc;
3334 desc = build_constant_desc (exp);
3335 desc->hash = key.hash;
3339 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3340 varpool_finalize_decl (decl);
3344 /* Used in the hash tables to avoid outputting the same constant
3345 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3346 are output once per function, not once per file. */
3347 /* ??? Only a few targets need per-function constant pools. Most
3348 can use one per-file pool. Should add a targetm bit to tell the
3351 struct GTY(()) rtx_constant_pool {
3352 /* Pointers to first and last constant in pool, as ordered by offset. */
3353 struct constant_descriptor_rtx *first;
3354 struct constant_descriptor_rtx *last;
3356 /* Hash facility for making memory-constants from constant rtl-expressions.
3357 It is used on RISC machines where immediate integer arguments and
3358 constant addresses are restricted so that such constants must be stored
3360 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3362 /* Current offset in constant pool (does not include any
3363 machine-specific header). */
3364 HOST_WIDE_INT offset;
3367 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3368 struct constant_descriptor_rtx *next;
3372 HOST_WIDE_INT offset;
3374 enum machine_mode mode;
3380 /* Hash and compare functions for const_rtx_htab. */
3383 const_desc_rtx_hash (const void *ptr)
3385 const struct constant_descriptor_rtx *const desc
3386 = (const struct constant_descriptor_rtx *) ptr;
3391 const_desc_rtx_eq (const void *a, const void *b)
3393 const struct constant_descriptor_rtx *const x
3394 = (const struct constant_descriptor_rtx *) a;
3395 const struct constant_descriptor_rtx *const y
3396 = (const struct constant_descriptor_rtx *) b;
3398 if (x->mode != y->mode)
3400 return rtx_equal_p (x->constant, y->constant);
3403 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3406 const_rtx_hash_1 (rtx *xp, void *data)
3408 unsigned HOST_WIDE_INT hwi;
3409 enum machine_mode mode;
3415 code = GET_CODE (x);
3416 mode = GET_MODE (x);
3417 h = (hashval_t) code * 1048573 + mode;
3425 int shift = sizeof (hashval_t) * CHAR_BIT;
3426 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3429 h ^= (hashval_t) hwi;
3430 for (i = 1; i < n; ++i)
3433 h ^= (hashval_t) hwi;
3439 if (mode == VOIDmode)
3441 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3445 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3449 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3455 for (i = XVECLEN (x, 0); i-- > 0; )
3456 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3461 h ^= htab_hash_string (XSTR (x, 0));
3465 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3469 case UNSPEC_VOLATILE:
3470 h = h * 251 + XINT (x, 1);
3477 hp = (hashval_t *) data;
3478 *hp = *hp * 509 + h;
3482 /* Compute a hash value for X, which should be a constant. */
3485 const_rtx_hash (rtx x)
3488 for_each_rtx (&x, const_rtx_hash_1, &h);
3493 /* Create and return a new rtx constant pool. */
3495 static struct rtx_constant_pool *
3496 create_constant_pool (void)
3498 struct rtx_constant_pool *pool;
3500 pool = ggc_alloc_rtx_constant_pool ();
3501 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3502 const_desc_rtx_eq, NULL);
3509 /* Initialize constant pool hashing for a new function. */
3512 init_varasm_status (void)
3514 crtl->varasm.pool = create_constant_pool ();
3515 crtl->varasm.deferred_constants = 0;
3518 /* Given a MINUS expression, simplify it if both sides
3519 include the same symbol. */
3522 simplify_subtraction (rtx x)
3524 rtx r = simplify_rtx (x);
3528 /* Given a constant rtx X, make (or find) a memory constant for its value
3529 and return a MEM rtx to refer to it in memory. */
3532 force_const_mem (enum machine_mode mode, rtx x)
3534 struct constant_descriptor_rtx *desc, tmp;
3535 struct rtx_constant_pool *pool;
3542 /* If we're not allowed to drop X into the constant pool, don't. */
3543 if (targetm.cannot_force_const_mem (mode, x))
3546 /* Record that this function has used a constant pool entry. */
3547 crtl->uses_const_pool = 1;
3549 /* Decide which pool to use. */
3550 pool = (targetm.use_blocks_for_constant_p (mode, x)
3551 ? shared_constant_pool
3552 : crtl->varasm.pool);
3554 /* Lookup the value in the hashtable. */
3557 hash = const_rtx_hash (x);
3558 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3559 desc = (struct constant_descriptor_rtx *) *slot;
3561 /* If the constant was already present, return its memory. */
3563 return copy_rtx (desc->mem);
3565 /* Otherwise, create a new descriptor. */
3566 desc = ggc_alloc_constant_descriptor_rtx ();
3569 /* Align the location counter as required by EXP's data type. */
3570 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3571 #ifdef CONSTANT_ALIGNMENT
3573 tree type = lang_hooks.types.type_for_mode (mode, 0);
3574 if (type != NULL_TREE)
3575 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3579 pool->offset += (align / BITS_PER_UNIT) - 1;
3580 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3583 desc->constant = copy_rtx (tmp.constant);
3584 desc->offset = pool->offset;
3587 desc->align = align;
3588 desc->labelno = const_labelno;
3591 pool->offset += GET_MODE_SIZE (mode);
3593 pool->last->next = desc;
3595 pool->first = pool->last = desc;
3598 /* Create a string containing the label name, in LABEL. */
3599 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3602 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3603 the constants pool. */
3604 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3606 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3607 symbol = create_block_symbol (ggc_strdup (label),
3608 get_block_for_section (sect), -1);
3611 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3613 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3614 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3615 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3617 /* Construct the MEM. */
3618 desc->mem = def = gen_const_mem (mode, symbol);
3619 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3620 set_mem_align (def, align);
3622 /* If we're dropping a label to the constant pool, make sure we
3624 if (GET_CODE (x) == LABEL_REF)
3625 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3627 return copy_rtx (def);
3630 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3633 get_pool_constant (rtx addr)
3635 return SYMBOL_REF_CONSTANT (addr)->constant;
3638 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3639 and whether it has been output or not. */
3642 get_pool_constant_mark (rtx addr, bool *pmarked)
3644 struct constant_descriptor_rtx *desc;
3646 desc = SYMBOL_REF_CONSTANT (addr);
3647 *pmarked = (desc->mark != 0);
3648 return desc->constant;
3651 /* Similar, return the mode. */
3654 get_pool_mode (const_rtx addr)
3656 return SYMBOL_REF_CONSTANT (addr)->mode;
3659 /* Return the size of the constant pool. */
3662 get_pool_size (void)
3664 return crtl->varasm.pool->offset;
3667 /* Worker function for output_constant_pool_1. Emit assembly for X
3668 in MODE with known alignment ALIGN. */
3671 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3673 switch (GET_MODE_CLASS (mode))
3676 case MODE_DECIMAL_FLOAT:
3680 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3681 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3682 assemble_real (r, mode, align);
3687 case MODE_PARTIAL_INT:
3692 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3695 case MODE_VECTOR_FLOAT:
3696 case MODE_VECTOR_INT:
3697 case MODE_VECTOR_FRACT:
3698 case MODE_VECTOR_UFRACT:
3699 case MODE_VECTOR_ACCUM:
3700 case MODE_VECTOR_UACCUM:
3703 enum machine_mode submode = GET_MODE_INNER (mode);
3704 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3706 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3707 units = CONST_VECTOR_NUNITS (x);
3709 for (i = 0; i < units; i++)
3711 rtx elt = CONST_VECTOR_ELT (x, i);
3712 output_constant_pool_2 (submode, elt, i ? subalign : align);