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"
39 #include "hard-reg-set.h"
42 #include "diagnostic-core.h"
45 #include "langhooks.h"
49 #include "common/common-target.h"
50 #include "targhooks.h"
51 #include "tree-mudflap.h"
53 #include "cfglayout.h"
54 #include "basic-block.h"
55 #include "tree-iterator.h"
56 #include "pointer-set.h"
58 #ifdef XCOFF_DEBUGGING_INFO
59 #include "xcoffout.h" /* Needed for external data
60 declarations for e.g. AIX 4.x. */
63 /* The (assembler) name of the first globally-visible object output. */
64 extern GTY(()) const char *first_global_object_name;
65 extern GTY(()) const char *weak_global_object_name;
67 const char *first_global_object_name;
68 const char *weak_global_object_name;
71 struct constant_descriptor_rtx;
72 struct rtx_constant_pool;
74 #define n_deferred_constants (crtl->varasm.deferred_constants)
76 /* Number for making the label on the next
77 constant that is stored in memory. */
79 static GTY(()) int const_labelno;
81 /* Carry information from ASM_DECLARE_OBJECT_NAME
82 to ASM_FINISH_DECLARE_OBJECT. */
84 int size_directive_output;
86 /* The last decl for which assemble_variable was called,
87 if it did ASM_DECLARE_OBJECT_NAME.
88 If the last call to assemble_variable didn't do that,
91 tree last_assemble_variable_decl;
93 /* The following global variable indicates if the first basic block
94 in a function belongs to the cold partition or not. */
96 bool first_function_block_is_cold;
98 /* We give all constants their own alias set. Perhaps redundant with
99 MEM_READONLY_P, but pre-dates it. */
101 static alias_set_type const_alias_set;
103 /* Whether we saw any functions with no_split_stack. */
105 static bool saw_no_split_stack;
107 static const char *strip_reg_name (const char *);
108 static int contains_pointers_p (tree);
109 #ifdef ASM_OUTPUT_EXTERNAL
110 static bool incorporeal_function_p (tree);
112 static void decode_addr_const (tree, struct addr_const *);
113 static hashval_t const_desc_hash (const void *);
114 static int const_desc_eq (const void *, const void *);
115 static hashval_t const_hash_1 (const tree);
116 static int compare_constant (const tree, const tree);
117 static tree copy_constant (tree);
118 static void output_constant_def_contents (rtx);
119 static void output_addressed_constants (tree);
120 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
121 static unsigned min_align (unsigned, unsigned);
122 static void globalize_decl (tree);
123 static bool decl_readonly_section_1 (enum section_category);
124 #ifdef BSS_SECTION_ASM_OP
125 #ifdef ASM_OUTPUT_ALIGNED_BSS
126 static void asm_output_aligned_bss (FILE *, tree, const char *,
127 unsigned HOST_WIDE_INT, int)
130 #endif /* BSS_SECTION_ASM_OP */
131 static void mark_weak (tree);
132 static void output_constant_pool (const char *, tree);
134 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
135 section *text_section;
136 section *data_section;
137 section *readonly_data_section;
138 section *sdata_section;
139 section *ctors_section;
140 section *dtors_section;
141 section *bss_section;
142 section *sbss_section;
144 /* Various forms of common section. All are guaranteed to be nonnull. */
145 section *tls_comm_section;
146 section *comm_section;
147 section *lcomm_section;
149 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
151 section *bss_noswitch_section;
153 /* The section that holds the main exception table, when known. The section
154 is set either by the target's init_sections hook or by the first call to
155 switch_to_exception_section. */
156 section *exception_section;
158 /* The section that holds the DWARF2 frame unwind information, when known.
159 The section is set either by the target's init_sections hook or by the
160 first call to switch_to_eh_frame_section. */
161 section *eh_frame_section;
163 /* asm_out_file's current section. This is NULL if no section has yet
164 been selected or if we lose track of what the current section is. */
167 /* True if code for the current function is currently being directed
168 at the cold section. */
169 bool in_cold_section_p;
171 /* A linked list of all the unnamed sections. */
172 static GTY(()) section *unnamed_sections;
174 /* Return a nonzero value if DECL has a section attribute. */
175 #define IN_NAMED_SECTION(DECL) \
176 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
177 && DECL_SECTION_NAME (DECL) != NULL_TREE)
179 /* Hash table of named sections. */
180 static GTY((param_is (section))) htab_t section_htab;
182 /* A table of object_blocks, indexed by section. */
183 static GTY((param_is (struct object_block))) htab_t object_block_htab;
185 /* The next number to use for internal anchor labels. */
186 static GTY(()) int anchor_labelno;
188 /* A pool of constants that can be shared between functions. */
189 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
191 /* Helper routines for maintaining section_htab. */
194 section_entry_eq (const void *p1, const void *p2)
196 const section *old = (const section *) p1;
197 const char *new_name = (const char *) p2;
199 return strcmp (old->named.name, new_name) == 0;
203 section_entry_hash (const void *p)
205 const section *old = (const section *) p;
206 return htab_hash_string (old->named.name);
209 /* Return a hash value for section SECT. */
212 hash_section (section *sect)
214 if (sect->common.flags & SECTION_NAMED)
215 return htab_hash_string (sect->named.name);
216 return sect->common.flags;
219 /* Helper routines for maintaining object_block_htab. */
222 object_block_entry_eq (const void *p1, const void *p2)
224 const struct object_block *old = (const struct object_block *) p1;
225 const section *new_section = (const section *) p2;
227 return old->sect == new_section;
231 object_block_entry_hash (const void *p)
233 const struct object_block *old = (const struct object_block *) p;
234 return hash_section (old->sect);
237 /* Return a new unnamed section with the given fields. */
240 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
245 sect = ggc_alloc_section ();
246 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
247 sect->unnamed.callback = callback;
248 sect->unnamed.data = data;
249 sect->unnamed.next = unnamed_sections;
251 unnamed_sections = sect;
255 /* Return a SECTION_NOSWITCH section with the given fields. */
258 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
262 sect = ggc_alloc_section ();
263 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
264 sect->noswitch.callback = callback;
269 /* Return the named section structure associated with NAME. Create
270 a new section with the given fields if no such structure exists. */
273 get_section (const char *name, unsigned int flags, tree decl)
275 section *sect, **slot;
278 htab_find_slot_with_hash (section_htab, name,
279 htab_hash_string (name), INSERT);
280 flags |= SECTION_NAMED;
283 sect = ggc_alloc_section ();
284 sect->named.common.flags = flags;
285 sect->named.name = ggc_strdup (name);
286 sect->named.decl = decl;
292 if ((sect->common.flags & ~SECTION_DECLARED) != flags
293 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
295 /* It is fine if one of the section flags is
296 SECTION_WRITE | SECTION_RELRO and the other has none of these
297 flags (i.e. read-only) in named sections and either the
298 section hasn't been declared yet or has been declared as writable.
299 In that case just make sure the resulting flags are
300 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
302 if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
303 == (SECTION_WRITE | SECTION_RELRO)
304 && (sect->common.flags
305 & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
306 == (flags & ~(SECTION_WRITE | SECTION_RELRO))
307 && ((sect->common.flags & SECTION_DECLARED) == 0
308 || (sect->common.flags & SECTION_WRITE)))
310 sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
313 /* Sanity check user variables for flag changes. */
315 decl = sect->named.decl;
317 error ("%+D causes a section type conflict with %D",
318 decl, sect->named.decl);
319 if (decl != sect->named.decl)
320 inform (DECL_SOURCE_LOCATION (sect->named.decl),
321 "%qD was declared here", sect->named.decl);
322 /* Make sure we don't error about one section multiple times. */
323 sect->common.flags |= SECTION_OVERRIDE;
329 /* Return true if the current compilation mode benefits from having
330 objects grouped into blocks. */
333 use_object_blocks_p (void)
335 return flag_section_anchors;
338 /* Return the object_block structure for section SECT. Create a new
339 structure if we haven't created one already. Return null if SECT
342 static struct object_block *
343 get_block_for_section (section *sect)
345 struct object_block *block;
351 slot = htab_find_slot_with_hash (object_block_htab, sect,
352 hash_section (sect), INSERT);
353 block = (struct object_block *) *slot;
356 block = ggc_alloc_cleared_object_block ();
363 /* Create a symbol with label LABEL and place it at byte offset
364 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
365 is not yet known. LABEL must be a garbage-collected string. */
368 create_block_symbol (const char *label, struct object_block *block,
369 HOST_WIDE_INT offset)
374 /* Create the extended SYMBOL_REF. */
375 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
376 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
378 /* Initialize the normal SYMBOL_REF fields. */
379 memset (symbol, 0, size);
380 PUT_CODE (symbol, SYMBOL_REF);
381 PUT_MODE (symbol, Pmode);
382 XSTR (symbol, 0) = label;
383 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
385 /* Initialize the block_symbol stuff. */
386 SYMBOL_REF_BLOCK (symbol) = block;
387 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
392 /* Return a section with a particular name and with whatever SECTION_*
393 flags section_type_flags deems appropriate. The name of the section
394 is taken from NAME if nonnull, otherwise it is taken from DECL's
395 DECL_SECTION_NAME. DECL is the decl associated with the section
396 (see the section comment for details) and RELOC is as for
397 section_type_flags. */
400 get_named_section (tree decl, const char *name, int reloc)
404 gcc_assert (!decl || DECL_P (decl));
406 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
408 flags = targetm.section_type_flags (decl, name, reloc);
410 return get_section (name, flags, decl);
413 /* If required, set DECL_SECTION_NAME to a unique name. */
416 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
417 int flag_function_or_data_sections)
419 if (DECL_SECTION_NAME (decl) == NULL_TREE
420 && targetm_common.have_named_sections
421 && (flag_function_or_data_sections
422 || DECL_ONE_ONLY (decl)))
424 targetm.asm_out.unique_section (decl, reloc);
425 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl) = true;
429 #ifdef BSS_SECTION_ASM_OP
431 #ifdef ASM_OUTPUT_ALIGNED_BSS
433 /* Utility function for targets to use in implementing
434 ASM_OUTPUT_ALIGNED_BSS.
435 ??? It is believed that this function will work in most cases so such
436 support is localized here. */
439 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
440 const char *name, unsigned HOST_WIDE_INT size,
443 switch_to_section (bss_section);
444 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
445 #ifdef ASM_DECLARE_OBJECT_NAME
446 last_assemble_variable_decl = decl;
447 ASM_DECLARE_OBJECT_NAME (file, name, decl);
449 /* Standard thing is just output label for the object. */
450 ASM_OUTPUT_LABEL (file, name);
451 #endif /* ASM_DECLARE_OBJECT_NAME */
452 ASM_OUTPUT_SKIP (file, size ? size : 1);
457 #endif /* BSS_SECTION_ASM_OP */
459 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
460 /* Return the hot section for function DECL. Return text_section for
464 hot_function_section (tree decl)
466 if (decl != NULL_TREE
467 && DECL_SECTION_NAME (decl) != NULL_TREE
468 && targetm_common.have_named_sections)
469 return get_named_section (decl, NULL, 0);
475 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
478 When DECL_SECTION_NAME is non-NULL and it is implicit section and
479 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
480 concatenate the name with NAMED_SECTION_SUFFIX.
481 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
484 get_named_text_section (tree decl,
485 const char *text_section_name,
486 const char *named_section_suffix)
488 if (decl && DECL_SECTION_NAME (decl))
490 if (named_section_suffix)
492 tree dsn = DECL_SECTION_NAME (decl);
493 const char *stripped_name;
496 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
497 memcpy (name, TREE_STRING_POINTER (dsn),
498 TREE_STRING_LENGTH (dsn) + 1);
500 stripped_name = targetm.strip_name_encoding (name);
502 buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
503 return get_named_section (decl, buffer, 0);
505 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
509 /* Do not try to split gnu_linkonce functions. This gets somewhat
511 if (DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP)
513 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
514 name = targetm.strip_name_encoding (name);
515 return get_named_section (decl, ACONCAT ((text_section_name, ".",
521 return get_named_section (decl, text_section_name, 0);
524 /* Choose named function section based on its frequency. */
527 default_function_section (tree decl, enum node_frequency freq,
528 bool startup, bool exit)
530 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
531 /* Old GNU linkers have buggy --gc-section support, which sometimes
532 results in .gcc_except_table* sections being garbage collected. */
534 && DECL_SECTION_NAME (decl)
535 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
539 if (!flag_reorder_functions
540 || !targetm_common.have_named_sections)
542 /* Startup code should go to startup subsection unless it is
543 unlikely executed (this happens especially with function splitting
544 where we can split away unnecesary parts of static constructors. */
545 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
546 return get_named_text_section (decl, ".text.startup", NULL);
548 /* Similarly for exit. */
549 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
550 return get_named_text_section (decl, ".text.exit", NULL);
552 /* Group cold functions together, similarly for hot code. */
555 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
556 return get_named_text_section (decl, ".text.unlikely", NULL);
557 case NODE_FREQUENCY_HOT:
558 return get_named_text_section (decl, ".text.hot", NULL);
564 /* Return the section for function DECL.
566 If DECL is NULL_TREE, return the text section. We can be passed
567 NULL_TREE under some circumstances by dbxout.c at least.
569 If FORCE_COLD is true, return cold function section ignoring
570 the frequency info of cgraph_node. */
573 function_section_1 (tree decl, bool force_cold)
575 section *section = NULL;
576 enum node_frequency freq = NODE_FREQUENCY_NORMAL;
577 bool startup = false, exit = false;
581 struct cgraph_node *node = cgraph_get_node (decl);
585 freq = node->frequency;
586 startup = node->only_called_at_startup;
587 exit = node->only_called_at_exit;
591 freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
593 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
594 if (decl != NULL_TREE
595 && DECL_SECTION_NAME (decl) != NULL_TREE)
597 if (targetm.asm_out.function_section)
598 section = targetm.asm_out.function_section (decl, freq,
602 return get_named_section (decl, NULL, 0);
605 return targetm.asm_out.select_section
606 (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
609 if (targetm.asm_out.function_section)
610 section = targetm.asm_out.function_section (decl, freq, startup, exit);
613 return hot_function_section (decl);
617 /* Return the section for function DECL.
619 If DECL is NULL_TREE, return the text section. We can be passed
620 NULL_TREE under some circumstances by dbxout.c at least. */
623 function_section (tree decl)
625 /* Handle cases where function splitting code decides
626 to put function entry point into unlikely executed section
627 despite the fact that the function itself is not cold
628 (i.e. it is called rarely but contains a hot loop that is
629 better to live in hot subsection for the code locality). */
630 return function_section_1 (decl,
631 first_function_block_is_cold);
634 /* Return the section for the current function, take IN_COLD_SECTION_P
638 current_function_section (void)
640 return function_section_1 (current_function_decl, in_cold_section_p);
643 /* Tell assembler to switch to unlikely-to-be-executed text section. */
646 unlikely_text_section (void)
648 return function_section_1 (current_function_decl, true);
651 /* When called within a function context, return true if the function
652 has been assigned a cold text section and if SECT is that section.
653 When called outside a function context, return true if SECT is the
654 default cold section. */
657 unlikely_text_section_p (section *sect)
659 return sect == function_section_1 (current_function_decl, true);
662 /* Return the read-only data section associated with function DECL. */
665 default_function_rodata_section (tree decl)
667 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
669 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
671 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
677 dot = strchr (name + 1, '.');
680 len = strlen (dot) + 8;
681 rname = (char *) alloca (len);
683 strcpy (rname, ".rodata");
685 return get_section (rname, SECTION_LINKONCE, decl);
687 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
688 else if (DECL_ONE_ONLY (decl)
689 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
691 size_t len = strlen (name) + 1;
692 char *rname = (char *) alloca (len);
694 memcpy (rname, name, len);
696 return get_section (rname, SECTION_LINKONCE, decl);
698 /* For .text.foo we want to use .rodata.foo. */
699 else if (flag_function_sections && flag_data_sections
700 && strncmp (name, ".text.", 6) == 0)
702 size_t len = strlen (name) + 1;
703 char *rname = (char *) alloca (len + 2);
705 memcpy (rname, ".rodata", 7);
706 memcpy (rname + 7, name + 5, len - 5);
707 return get_section (rname, 0, decl);
711 return readonly_data_section;
714 /* Return the read-only data section associated with function DECL
715 for targets where that section should be always the single
716 readonly data section. */
719 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
721 return readonly_data_section;
724 /* Return the section to use for string merging. */
727 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
728 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
729 unsigned int flags ATTRIBUTE_UNUSED)
733 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
734 && TREE_CODE (decl) == STRING_CST
735 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
737 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
738 && TREE_STRING_LENGTH (decl) >= len)
740 enum machine_mode mode;
741 unsigned int modesize;
745 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
746 char *name = (char *) alloca (strlen (prefix) + 30);
748 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
749 modesize = GET_MODE_BITSIZE (mode);
750 if (modesize >= 8 && modesize <= 256
751 && (modesize & (modesize - 1)) == 0)
753 if (align < modesize)
756 str = TREE_STRING_POINTER (decl);
757 unit = GET_MODE_SIZE (mode);
759 /* Check for embedded NUL characters. */
760 for (i = 0; i < len; i += unit)
762 for (j = 0; j < unit; j++)
763 if (str[i + j] != '\0')
770 sprintf (name, "%s.str%d.%d", prefix,
771 modesize / 8, (int) (align / 8));
772 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
773 return get_section (name, flags, NULL);
778 return readonly_data_section;
781 /* Return the section to use for constant merging. */
784 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
785 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
786 unsigned int flags ATTRIBUTE_UNUSED)
788 unsigned int modesize = GET_MODE_BITSIZE (mode);
790 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
796 && (align & (align - 1)) == 0)
798 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
799 char *name = (char *) alloca (strlen (prefix) + 30);
801 sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
802 flags |= (align / 8) | SECTION_MERGE;
803 return get_section (name, flags, NULL);
805 return readonly_data_section;
808 /* Given NAME, a putative register name, discard any customary prefixes. */
811 strip_reg_name (const char *name)
813 #ifdef REGISTER_PREFIX
814 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
815 name += strlen (REGISTER_PREFIX);
817 if (name[0] == '%' || name[0] == '#')
822 /* The user has asked for a DECL to have a particular name. Set (or
823 change) it in such a way that we don't prefix an underscore to
826 set_user_assembler_name (tree decl, const char *name)
828 char *starred = (char *) alloca (strlen (name) + 2);
830 strcpy (starred + 1, name);
831 change_decl_assembler_name (decl, get_identifier (starred));
832 SET_DECL_RTL (decl, NULL_RTX);
835 /* Decode an `asm' spec for a declaration as a register name.
836 Return the register number, or -1 if nothing specified,
837 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
838 or -3 if ASMSPEC is `cc' and is not recognized,
839 or -4 if ASMSPEC is `memory' and is not recognized.
840 Accept an exact spelling or a decimal number.
841 Prefixes such as % are optional. */
844 decode_reg_name_and_count (const char *asmspec, int *pnregs)
846 /* Presume just one register is clobbered. */
853 /* Get rid of confusing prefixes. */
854 asmspec = strip_reg_name (asmspec);
856 /* Allow a decimal number as a "register name". */
857 for (i = strlen (asmspec) - 1; i >= 0; i--)
858 if (! ISDIGIT (asmspec[i]))
860 if (asmspec[0] != 0 && i < 0)
863 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
869 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
871 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
874 #ifdef OVERLAPPING_REGISTER_NAMES
878 const char *const name;
881 } table[] = OVERLAPPING_REGISTER_NAMES;
883 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
885 && ! strcmp (asmspec, table[i].name))
887 *pnregs = table[i].nregs;
888 return table[i].number;
891 #endif /* OVERLAPPING_REGISTER_NAMES */
893 #ifdef ADDITIONAL_REGISTER_NAMES
895 static const struct { const char *const name; const int number; } table[]
896 = ADDITIONAL_REGISTER_NAMES;
898 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
900 && ! strcmp (asmspec, table[i].name))
901 return table[i].number;
903 #endif /* ADDITIONAL_REGISTER_NAMES */
905 if (!strcmp (asmspec, "memory"))
908 if (!strcmp (asmspec, "cc"))
918 decode_reg_name (const char *name)
921 return decode_reg_name_and_count (name, &count);
925 /* Return true if DECL's initializer is suitable for a BSS section. */
928 bss_initializer_p (const_tree decl)
930 return (DECL_INITIAL (decl) == NULL
931 || DECL_INITIAL (decl) == error_mark_node
932 || (flag_zero_initialized_in_bss
933 /* Leave constant zeroes in .rodata so they
935 && !TREE_READONLY (decl)
936 && initializer_zerop (DECL_INITIAL (decl))));
939 /* Compute the alignment of variable specified by DECL.
940 DONT_OUTPUT_DATA is from assemble_variable. */
943 align_variable (tree decl, bool dont_output_data)
945 unsigned int align = DECL_ALIGN (decl);
947 /* In the case for initialing an array whose length isn't specified,
948 where we have not yet been able to do the layout,
949 figure out the proper alignment now. */
950 if (dont_output_data && DECL_SIZE (decl) == 0
951 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
952 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
954 /* Some object file formats have a maximum alignment which they support.
955 In particular, a.out format supports a maximum alignment of 4. */
956 if (align > MAX_OFILE_ALIGNMENT)
958 warning (0, "alignment of %q+D is greater than maximum object "
959 "file alignment. Using %d", decl,
960 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
961 align = MAX_OFILE_ALIGNMENT;
964 /* On some machines, it is good to increase alignment sometimes. */
965 if (! DECL_USER_ALIGN (decl))
967 #ifdef DATA_ALIGNMENT
968 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
969 /* Don't increase alignment too much for TLS variables - TLS space
971 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
974 #ifdef CONSTANT_ALIGNMENT
975 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
977 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
979 /* Don't increase alignment too much for TLS variables - TLS space
981 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
987 /* Reset the alignment in case we have made it tighter, so we can benefit
988 from it in get_pointer_alignment. */
989 DECL_ALIGN (decl) = align;
992 /* Return the section into which the given VAR_DECL or CONST_DECL
993 should be placed. PREFER_NOSWITCH_P is true if a noswitch
994 section should be used wherever possible. */
997 get_variable_section (tree decl, bool prefer_noswitch_p)
999 addr_space_t as = ADDR_SPACE_GENERIC;
1002 if (TREE_TYPE (decl) != error_mark_node)
1003 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1005 if (DECL_COMMON (decl))
1007 /* If the decl has been given an explicit section name, or it resides
1008 in a non-generic address space, then it isn't common, and shouldn't
1009 be handled as such. */
1010 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1011 && ADDR_SPACE_GENERIC_P (as));
1012 if (DECL_THREAD_LOCAL_P (decl))
1013 return tls_comm_section;
1014 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1015 return comm_section;
1018 if (DECL_INITIAL (decl) == error_mark_node)
1019 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1020 else if (DECL_INITIAL (decl))
1021 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1025 resolve_unique_section (decl, reloc, flag_data_sections);
1026 if (IN_NAMED_SECTION (decl))
1027 return get_named_section (decl, NULL, reloc);
1029 if (ADDR_SPACE_GENERIC_P (as)
1030 && !DECL_THREAD_LOCAL_P (decl)
1031 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1032 && bss_initializer_p (decl))
1034 if (!TREE_PUBLIC (decl))
1035 return lcomm_section;
1036 if (bss_noswitch_section)
1037 return bss_noswitch_section;
1040 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1043 /* Return the block into which object_block DECL should be placed. */
1045 static struct object_block *
1046 get_block_for_decl (tree decl)
1050 if (TREE_CODE (decl) == VAR_DECL)
1052 /* The object must be defined in this translation unit. */
1053 if (DECL_EXTERNAL (decl))
1056 /* There's no point using object blocks for something that is
1057 isolated by definition. */
1058 if (DECL_ONE_ONLY (decl))
1062 /* We can only calculate block offsets if the decl has a known
1064 if (DECL_SIZE_UNIT (decl) == NULL)
1066 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1069 /* Find out which section should contain DECL. We cannot put it into
1070 an object block if it requires a standalone definition. */
1071 if (TREE_CODE (decl) == VAR_DECL)
1072 align_variable (decl, 0);
1073 sect = get_variable_section (decl, true);
1074 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1077 return get_block_for_section (sect);
1080 /* Make sure block symbol SYMBOL is in block BLOCK. */
1083 change_symbol_block (rtx symbol, struct object_block *block)
1085 if (block != SYMBOL_REF_BLOCK (symbol))
1087 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1088 SYMBOL_REF_BLOCK (symbol) = block;
1092 /* Return true if it is possible to put DECL in an object_block. */
1095 use_blocks_for_decl_p (tree decl)
1097 /* Only data DECLs can be placed into object blocks. */
1098 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1101 /* Detect decls created by dw2_force_const_mem. Such decls are
1102 special because DECL_INITIAL doesn't specify the decl's true value.
1103 dw2_output_indirect_constants will instead call assemble_variable
1104 with dont_output_data set to 1 and then print the contents itself. */
1105 if (DECL_INITIAL (decl) == decl)
1108 /* If this decl is an alias, then we don't want to emit a
1110 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1116 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1117 have static storage duration. In other words, it should not be an
1118 automatic variable, including PARM_DECLs.
1120 There is, however, one exception: this function handles variables
1121 explicitly placed in a particular register by the user.
1123 This is never called for PARM_DECL nodes. */
1126 make_decl_rtl (tree decl)
1128 const char *name = 0;
1132 /* Check that we are not being given an automatic variable. */
1133 gcc_assert (TREE_CODE (decl) != PARM_DECL
1134 && TREE_CODE (decl) != RESULT_DECL);
1136 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1137 gcc_assert (TREE_CODE (decl) != VAR_DECL
1138 || TREE_STATIC (decl)
1139 || TREE_PUBLIC (decl)
1140 || DECL_EXTERNAL (decl)
1141 || DECL_REGISTER (decl));
1143 /* And that we were not given a type or a label. */
1144 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1145 && TREE_CODE (decl) != LABEL_DECL);
1147 /* For a duplicate declaration, we can be called twice on the
1148 same DECL node. Don't discard the RTL already made. */
1149 if (DECL_RTL_SET_P (decl))
1151 /* If the old RTL had the wrong mode, fix the mode. */
1152 x = DECL_RTL (decl);
1153 if (GET_MODE (x) != DECL_MODE (decl))
1154 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1156 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1159 /* ??? Another way to do this would be to maintain a hashed
1160 table of such critters. Instead of adding stuff to a DECL
1161 to give certain attributes to it, we could use an external
1162 hash map from DECL to set of attributes. */
1164 /* Let the target reassign the RTL if it wants.
1165 This is necessary, for example, when one machine specific
1166 decl attribute overrides another. */
1167 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1169 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1170 on the new decl information. */
1172 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1173 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1174 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1176 /* Make this function static known to the mudflap runtime. */
1177 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1178 mudflap_enqueue_decl (decl);
1183 /* If this variable belongs to the global constant pool, retrieve the
1184 pre-computed RTL or recompute it in LTO mode. */
1185 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1187 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1191 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1193 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1194 && DECL_REGISTER (decl))
1196 error ("register name not specified for %q+D", decl);
1198 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1200 const char *asmspec = name+1;
1201 reg_number = decode_reg_name (asmspec);
1202 /* First detect errors in declaring global registers. */
1203 if (reg_number == -1)
1204 error ("register name not specified for %q+D", decl);
1205 else if (reg_number < 0)
1206 error ("invalid register name for %q+D", decl);
1207 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
1208 error ("data type of %q+D isn%'t suitable for a register",
1210 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
1211 error ("register specified for %q+D isn%'t suitable for data type",
1213 /* Now handle properly declared static register variables. */
1218 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1220 DECL_INITIAL (decl) = 0;
1221 error ("global register variable has initial value");
1223 if (TREE_THIS_VOLATILE (decl))
1224 warning (OPT_Wvolatile_register_var,
1225 "optimization may eliminate reads and/or "
1226 "writes to register variables");
1228 /* If the user specified one of the eliminables registers here,
1229 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1230 confused with that register and be eliminated. This usage is
1231 somewhat suspect... */
1233 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
1234 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1235 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1237 if (TREE_STATIC (decl))
1239 /* Make this register global, so not usable for anything
1241 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1242 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1243 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1245 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
1247 globalize_reg (decl, reg_number + --nregs);
1250 /* As a register variable, it has no section. */
1254 /* Now handle ordinary static variables and functions (in memory).
1255 Also handle vars declared register invalidly. */
1256 else if (name[0] == '*')
1258 #ifdef REGISTER_PREFIX
1259 if (strlen (REGISTER_PREFIX) != 0)
1261 reg_number = decode_reg_name (name);
1262 if (reg_number >= 0 || reg_number == -3)
1263 error ("register name given for non-register variable %q+D", decl);
1268 /* Specifying a section attribute on a variable forces it into a
1269 non-.bss section, and thus it cannot be common. */
1270 /* FIXME: In general this code should not be necessary because
1271 visibility pass is doing the same work. But notice_global_symbol
1272 is called early and it needs to make DECL_RTL to get the name.
1273 we take care of recomputing the DECL_RTL after visibility is changed. */
1274 if (TREE_CODE (decl) == VAR_DECL
1275 && DECL_SECTION_NAME (decl) != NULL_TREE
1276 && DECL_INITIAL (decl) == NULL_TREE
1277 && DECL_COMMON (decl))
1278 DECL_COMMON (decl) = 0;
1280 /* Variables can't be both common and weak. */
1281 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1282 DECL_COMMON (decl) = 0;
1284 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1285 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1288 enum machine_mode address_mode = Pmode;
1289 if (TREE_TYPE (decl) != error_mark_node)
1291 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1292 address_mode = targetm.addr_space.address_mode (as);
1294 x = gen_rtx_SYMBOL_REF (address_mode, name);
1296 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1297 SET_SYMBOL_REF_DECL (x, decl);
1299 x = gen_rtx_MEM (DECL_MODE (decl), x);
1300 if (TREE_CODE (decl) != FUNCTION_DECL)
1301 set_mem_attributes (x, decl, 1);
1302 SET_DECL_RTL (decl, x);
1304 /* Optionally set flags or add text to the name to record information
1305 such as that it is a function name.
1306 If the name is changed, the macro ASM_OUTPUT_LABELREF
1307 will have to know how to strip this information. */
1308 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1310 /* Make this function static known to the mudflap runtime. */
1311 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1312 mudflap_enqueue_decl (decl);
1315 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1316 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1320 make_decl_rtl_for_debug (tree decl)
1322 unsigned int save_aliasing_flag, save_mudflap_flag;
1325 if (DECL_RTL_SET_P (decl))
1326 return DECL_RTL (decl);
1328 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1329 call new_alias_set. If running with -fcompare-debug, sometimes
1330 we do not want to create alias sets that will throw the alias
1331 numbers off in the comparison dumps. So... clearing
1332 flag_strict_aliasing will keep new_alias_set() from creating a
1333 new set. It is undesirable to register decl with mudflap
1334 in this case as well. */
1335 save_aliasing_flag = flag_strict_aliasing;
1336 flag_strict_aliasing = 0;
1337 save_mudflap_flag = flag_mudflap;
1340 rtl = DECL_RTL (decl);
1341 /* Reset DECL_RTL back, as various parts of the compiler expects
1342 DECL_RTL set meaning it is actually going to be output. */
1343 SET_DECL_RTL (decl, NULL);
1345 flag_strict_aliasing = save_aliasing_flag;
1346 flag_mudflap = save_mudflap_flag;
1351 /* Output a string of literal assembler code
1352 for an `asm' keyword used between functions. */
1355 assemble_asm (tree string)
1359 if (TREE_CODE (string) == ADDR_EXPR)
1360 string = TREE_OPERAND (string, 0);
1362 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1365 /* Record an element in the table of global destructors. SYMBOL is
1366 a SYMBOL_REF of the function to be called; PRIORITY is a number
1367 between 0 and MAX_INIT_PRIORITY. */
1370 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1371 int priority ATTRIBUTE_UNUSED)
1373 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1374 /* Tell GNU LD that this is part of the static destructor set.
1375 This will work for any system that uses stabs, most usefully
1377 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1378 dbxout_stab_value_label (XSTR (symbol, 0));
1380 sorry ("global destructors not supported on this target");
1384 /* Write the address of the entity given by SYMBOL to SEC. */
1386 assemble_addr_to_section (rtx symbol, section *sec)
1388 switch_to_section (sec);
1389 assemble_align (POINTER_SIZE);
1390 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1393 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1394 not) section for PRIORITY. */
1396 get_cdtor_priority_section (int priority, bool constructor_p)
1400 /* ??? This only works reliably with the GNU linker. */
1401 sprintf (buf, "%s.%.5u",
1402 constructor_p ? ".ctors" : ".dtors",
1403 /* Invert the numbering so the linker puts us in the proper
1404 order; constructors are run from right to left, and the
1405 linker sorts in increasing order. */
1406 MAX_INIT_PRIORITY - priority);
1407 return get_section (buf, SECTION_WRITE, NULL);
1411 default_named_section_asm_out_destructor (rtx symbol, int priority)
1415 if (priority != DEFAULT_INIT_PRIORITY)
1416 sec = get_cdtor_priority_section (priority,
1417 /*constructor_p=*/false);
1419 sec = get_section (".dtors", SECTION_WRITE, NULL);
1421 assemble_addr_to_section (symbol, sec);
1424 #ifdef DTORS_SECTION_ASM_OP
1426 default_dtor_section_asm_out_destructor (rtx symbol,
1427 int priority ATTRIBUTE_UNUSED)
1429 assemble_addr_to_section (symbol, dtors_section);
1433 /* Likewise for global constructors. */
1436 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1437 int priority ATTRIBUTE_UNUSED)
1439 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1440 /* Tell GNU LD that this is part of the static destructor set.
1441 This will work for any system that uses stabs, most usefully
1443 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1444 dbxout_stab_value_label (XSTR (symbol, 0));
1446 sorry ("global constructors not supported on this target");
1451 default_named_section_asm_out_constructor (rtx symbol, int priority)
1455 if (priority != DEFAULT_INIT_PRIORITY)
1456 sec = get_cdtor_priority_section (priority,
1457 /*constructor_p=*/true);
1459 sec = get_section (".ctors", SECTION_WRITE, NULL);
1461 assemble_addr_to_section (symbol, sec);
1464 #ifdef CTORS_SECTION_ASM_OP
1466 default_ctor_section_asm_out_constructor (rtx symbol,
1467 int priority ATTRIBUTE_UNUSED)
1469 assemble_addr_to_section (symbol, ctors_section);
1473 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1474 a nonzero value if the constant pool should be output before the
1475 start of the function, or a zero value if the pool should output
1476 after the end of the function. The default is to put it before the
1479 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1480 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1483 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1484 to be output to assembler.
1485 Set first_global_object_name and weak_global_object_name as appropriate. */
1488 notice_global_symbol (tree decl)
1490 const char **type = &first_global_object_name;
1492 if (first_global_object_name
1493 || !TREE_PUBLIC (decl)
1494 || DECL_EXTERNAL (decl)
1495 || !DECL_NAME (decl)
1496 || (TREE_CODE (decl) != FUNCTION_DECL
1497 && (TREE_CODE (decl) != VAR_DECL
1498 || (DECL_COMMON (decl)
1499 && (DECL_INITIAL (decl) == 0
1500 || DECL_INITIAL (decl) == error_mark_node))))
1501 || !MEM_P (DECL_RTL (decl)))
1504 /* We win when global object is found, but it is useful to know about weak
1505 symbol as well so we can produce nicer unique names. */
1506 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1507 type = &weak_global_object_name;
1513 rtx decl_rtl = DECL_RTL (decl);
1515 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1516 name = ggc_strdup (p);
1522 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1523 current function goes into the cold section, so that targets can use
1524 current_function_section during RTL expansion. DECL describes the
1528 decide_function_section (tree decl)
1530 first_function_block_is_cold = false;
1532 if (flag_reorder_blocks_and_partition)
1533 /* We will decide in assemble_start_function. */
1536 if (DECL_SECTION_NAME (decl))
1538 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1539 /* Calls to function_section rely on first_function_block_is_cold
1541 first_function_block_is_cold = (node
1543 == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1546 in_cold_section_p = first_function_block_is_cold;
1549 /* Output assembler code for the constant pool of a function and associated
1550 with defining the name of the function. DECL describes the function.
1551 NAME is the function's name. For the constant pool, we use the current
1552 constant pool data. */
1555 assemble_start_function (tree decl, const char *fnname)
1558 char tmp_label[100];
1559 bool hot_label_written = false;
1561 if (flag_reorder_blocks_and_partition)
1563 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1564 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1565 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1566 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1567 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1568 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1569 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1570 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1575 crtl->subsections.hot_section_label = NULL;
1576 crtl->subsections.cold_section_label = NULL;
1577 crtl->subsections.hot_section_end_label = NULL;
1578 crtl->subsections.cold_section_end_label = NULL;
1581 /* The following code does not need preprocessing in the assembler. */
1585 if (CONSTANT_POOL_BEFORE_FUNCTION)
1586 output_constant_pool (fnname, decl);
1588 /* Make sure the not and cold text (code) sections are properly
1589 aligned. This is necessary here in the case where the function
1590 has both hot and cold sections, because we don't want to re-set
1591 the alignment when the section switch happens mid-function. */
1593 if (flag_reorder_blocks_and_partition)
1595 first_function_block_is_cold = false;
1597 switch_to_section (unlikely_text_section ());
1598 assemble_align (DECL_ALIGN (decl));
1599 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1601 /* When the function starts with a cold section, we need to explicitly
1602 align the hot section and write out the hot section label.
1603 But if the current function is a thunk, we do not have a CFG. */
1605 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1607 switch_to_section (text_section);
1608 assemble_align (DECL_ALIGN (decl));
1609 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1610 hot_label_written = true;
1611 first_function_block_is_cold = true;
1613 in_cold_section_p = first_function_block_is_cold;
1617 /* Switch to the correct text section for the start of the function. */
1619 switch_to_section (function_section (decl));
1620 if (flag_reorder_blocks_and_partition
1621 && !hot_label_written)
1622 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1624 /* Tell assembler to move to target machine's alignment for functions. */
1625 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1628 ASM_OUTPUT_ALIGN (asm_out_file, align);
1631 /* Handle a user-specified function alignment.
1632 Note that we still need to align to DECL_ALIGN, as above,
1633 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1634 if (! DECL_USER_ALIGN (decl)
1635 && align_functions_log > align
1636 && optimize_function_for_speed_p (cfun))
1638 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1639 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1640 align_functions_log, align_functions - 1);
1642 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1646 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1647 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1650 if (!DECL_IGNORED_P (decl))
1651 (*debug_hooks->begin_function) (decl);
1653 /* Make function name accessible from other files, if appropriate. */
1655 if (TREE_PUBLIC (decl))
1657 notice_global_symbol (decl);
1659 globalize_decl (decl);
1661 maybe_assemble_visibility (decl);
1664 if (DECL_PRESERVE_P (decl))
1665 targetm.asm_out.mark_decl_preserved (fnname);
1667 /* Do any machine/system dependent processing of the function name. */
1668 #ifdef ASM_DECLARE_FUNCTION_NAME
1669 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1671 /* Standard thing is just output label for the function. */
1672 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1673 #endif /* ASM_DECLARE_FUNCTION_NAME */
1675 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
1676 saw_no_split_stack = true;
1679 /* Output assembler code associated with defining the size of the
1680 function. DECL describes the function. NAME is the function's name. */
1683 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1685 #ifdef ASM_DECLARE_FUNCTION_SIZE
1686 /* We could have switched section in the middle of the function. */
1687 if (flag_reorder_blocks_and_partition)
1688 switch_to_section (function_section (decl));
1689 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1691 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1693 output_constant_pool (fnname, decl);
1694 switch_to_section (function_section (decl)); /* need to switch back */
1696 /* Output labels for end of hot/cold text sections (to be used by
1698 if (flag_reorder_blocks_and_partition)
1700 section *save_text_section;
1702 save_text_section = in_section;
1703 switch_to_section (unlikely_text_section ());
1704 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1705 if (first_function_block_is_cold)
1706 switch_to_section (text_section);
1708 switch_to_section (function_section (decl));
1709 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1710 switch_to_section (save_text_section);
1714 /* Assemble code to leave SIZE bytes of zeros. */
1717 assemble_zeros (unsigned HOST_WIDE_INT size)
1719 /* Do no output if -fsyntax-only. */
1720 if (flag_syntax_only)
1723 #ifdef ASM_NO_SKIP_IN_TEXT
1724 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1725 so we must output 0s explicitly in the text section. */
1726 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1728 unsigned HOST_WIDE_INT i;
1729 for (i = 0; i < size; i++)
1730 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1735 ASM_OUTPUT_SKIP (asm_out_file, size);
1738 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1741 assemble_align (int align)
1743 if (align > BITS_PER_UNIT)
1745 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1749 /* Assemble a string constant with the specified C string as contents. */
1752 assemble_string (const char *p, int size)
1757 /* If the string is very long, split it up. */
1761 int thissize = size - pos;
1762 if (thissize > maximum)
1765 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1773 /* A noswitch_section_callback for lcomm_section. */
1776 emit_local (tree decl ATTRIBUTE_UNUSED,
1777 const char *name ATTRIBUTE_UNUSED,
1778 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1779 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1781 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1782 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1783 size, DECL_ALIGN (decl));
1785 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1786 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1789 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1794 /* A noswitch_section_callback for bss_noswitch_section. */
1796 #if defined ASM_OUTPUT_ALIGNED_BSS
1798 emit_bss (tree decl ATTRIBUTE_UNUSED,
1799 const char *name ATTRIBUTE_UNUSED,
1800 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1801 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1803 #if defined ASM_OUTPUT_ALIGNED_BSS
1804 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1810 /* A noswitch_section_callback for comm_section. */
1813 emit_common (tree decl ATTRIBUTE_UNUSED,
1814 const char *name ATTRIBUTE_UNUSED,
1815 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1816 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1818 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1819 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1820 size, DECL_ALIGN (decl));
1822 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1823 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1826 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1831 /* A noswitch_section_callback for tls_comm_section. */
1834 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1835 const char *name ATTRIBUTE_UNUSED,
1836 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1837 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1839 #ifdef ASM_OUTPUT_TLS_COMMON
1840 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1843 sorry ("thread-local COMMON data not implemented");
1848 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1849 NAME is the name of DECL's SYMBOL_REF. */
1852 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1854 unsigned HOST_WIDE_INT size, rounded;
1856 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1859 /* Don't allocate zero bytes of common,
1860 since that means "undefined external" in the linker. */
1864 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1865 so that each uninitialized object starts on such a boundary. */
1866 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1867 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1868 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1870 if (!sect->noswitch.callback (decl, name, size, rounded)
1871 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1872 warning (0, "requested alignment for %q+D is greater than "
1873 "implemented alignment of %wu", decl, rounded);
1876 /* A subroutine of assemble_variable. Output the label and contents of
1877 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1878 is as for assemble_variable. */
1881 assemble_variable_contents (tree decl, const char *name,
1882 bool dont_output_data)
1884 /* Do any machine/system dependent processing of the object. */
1885 #ifdef ASM_DECLARE_OBJECT_NAME
1886 last_assemble_variable_decl = decl;
1887 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1889 /* Standard thing is just output label for the object. */
1890 ASM_OUTPUT_LABEL (asm_out_file, name);
1891 #endif /* ASM_DECLARE_OBJECT_NAME */
1893 if (!dont_output_data)
1895 if (DECL_INITIAL (decl)
1896 && DECL_INITIAL (decl) != error_mark_node
1897 && !initializer_zerop (DECL_INITIAL (decl)))
1898 /* Output the actual data. */
1899 output_constant (DECL_INITIAL (decl),
1900 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1903 /* Leave space for it. */
1904 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1908 /* Assemble everything that is needed for a variable or function declaration.
1909 Not used for automatic variables, and not used for function definitions.
1910 Should not be called for variables of incomplete structure type.
1912 TOP_LEVEL is nonzero if this variable has file scope.
1913 AT_END is nonzero if this is the special handling, at end of compilation,
1914 to define things that have had only tentative definitions.
1915 DONT_OUTPUT_DATA if nonzero means don't actually output the
1916 initial value (that will be done by the caller). */
1919 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1920 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1923 rtx decl_rtl, symbol;
1926 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1927 gcc_assert (TREE_CODE (decl) == VAR_DECL);
1929 /* Emulated TLS had better not get this far. */
1930 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
1932 last_assemble_variable_decl = 0;
1934 /* Normally no need to say anything here for external references,
1935 since assemble_external is called by the language-specific code
1936 when a declaration is first seen. */
1938 if (DECL_EXTERNAL (decl))
1941 /* Do nothing for global register variables. */
1942 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1944 TREE_ASM_WRITTEN (decl) = 1;
1948 /* If type was incomplete when the variable was declared,
1949 see if it is complete now. */
1951 if (DECL_SIZE (decl) == 0)
1952 layout_decl (decl, 0);
1954 /* Still incomplete => don't allocate it; treat the tentative defn
1955 (which is what it must have been) as an `extern' reference. */
1957 if (!dont_output_data && DECL_SIZE (decl) == 0)
1959 error ("storage size of %q+D isn%'t known", decl);
1960 TREE_ASM_WRITTEN (decl) = 1;
1964 /* The first declaration of a variable that comes through this function
1965 decides whether it is global (in C, has external linkage)
1966 or local (in C, has internal linkage). So do nothing more
1967 if this function has already run. */
1969 if (TREE_ASM_WRITTEN (decl))
1972 /* Make sure targetm.encode_section_info is invoked before we set
1974 decl_rtl = DECL_RTL (decl);
1976 TREE_ASM_WRITTEN (decl) = 1;
1978 /* Do no output if -fsyntax-only. */
1979 if (flag_syntax_only)
1982 if (! dont_output_data
1983 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1985 error ("size of variable %q+D is too large", decl);
1989 gcc_assert (MEM_P (decl_rtl));
1990 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
1991 symbol = XEXP (decl_rtl, 0);
1993 /* If this symbol belongs to the tree constant pool, output the constant
1994 if it hasn't already been written. */
1995 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
1997 tree decl = SYMBOL_REF_DECL (symbol);
1998 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
1999 output_constant_def_contents (symbol);
2005 name = XSTR (symbol, 0);
2006 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2007 notice_global_symbol (decl);
2009 /* Compute the alignment of this data. */
2011 align_variable (decl, dont_output_data);
2012 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2014 if (TREE_PUBLIC (decl))
2015 maybe_assemble_visibility (decl);
2017 if (DECL_PRESERVE_P (decl))
2018 targetm.asm_out.mark_decl_preserved (name);
2020 /* First make the assembler name(s) global if appropriate. */
2021 sect = get_variable_section (decl, false);
2022 if (TREE_PUBLIC (decl)
2023 && (sect->common.flags & SECTION_COMMON) == 0)
2024 globalize_decl (decl);
2026 /* Output any data that we will need to use the address of. */
2027 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2028 output_addressed_constants (DECL_INITIAL (decl));
2030 /* dbxout.c needs to know this. */
2031 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2032 DECL_IN_TEXT_SECTION (decl) = 1;
2034 /* If the decl is part of an object_block, make sure that the decl
2035 has been positioned within its block, but do not write out its
2036 definition yet. output_object_blocks will do that later. */
2037 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2039 gcc_assert (!dont_output_data);
2040 place_block_symbol (symbol);
2042 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2043 assemble_noswitch_variable (decl, name, sect);
2046 switch_to_section (sect);
2047 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2048 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2049 assemble_variable_contents (decl, name, dont_output_data);
2053 /* Return 1 if type TYPE contains any pointers. */
2056 contains_pointers_p (tree type)
2058 switch (TREE_CODE (type))
2061 case REFERENCE_TYPE:
2062 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2063 so I'll play safe and return 1. */
2069 case QUAL_UNION_TYPE:
2072 /* For a type that has fields, see if the fields have pointers. */
2073 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2074 if (TREE_CODE (fields) == FIELD_DECL
2075 && contains_pointers_p (TREE_TYPE (fields)))
2081 /* An array type contains pointers if its element type does. */
2082 return contains_pointers_p (TREE_TYPE (type));
2089 /* We delay assemble_external processing until
2090 the compilation unit is finalized. This is the best we can do for
2091 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2092 it all the way to final. See PR 17982 for further discussion. */
2093 static GTY(()) tree pending_assemble_externals;
2095 #ifdef ASM_OUTPUT_EXTERNAL
2096 /* True if DECL is a function decl for which no out-of-line copy exists.
2097 It is assumed that DECL's assembler name has been set. */
2100 incorporeal_function_p (tree decl)
2102 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2106 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2107 && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
2108 || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
2111 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2112 if (is_builtin_name (name))
2118 /* Actually do the tests to determine if this is necessary, and invoke
2119 ASM_OUTPUT_EXTERNAL. */
2121 assemble_external_real (tree decl)
2123 rtx rtl = DECL_RTL (decl);
2125 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2126 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2127 && !incorporeal_function_p (decl))
2129 /* Some systems do require some output. */
2130 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2131 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2137 process_pending_assemble_externals (void)
2139 #ifdef ASM_OUTPUT_EXTERNAL
2141 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2142 assemble_external_real (TREE_VALUE (list));
2144 pending_assemble_externals = 0;
2148 /* This TREE_LIST contains any weak symbol declarations waiting
2150 static GTY(()) tree weak_decls;
2152 /* Output something to declare an external symbol to the assembler,
2153 and qualifiers such as weakness. (Most assemblers don't need
2154 extern declaration, so we normally output nothing.) Do nothing if
2155 DECL is not external. */
2158 assemble_external (tree decl ATTRIBUTE_UNUSED)
2160 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2161 main body of this code is only rarely exercised. To provide some
2162 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2163 open. If it's not, we should not be calling this function. */
2164 gcc_assert (asm_out_file);
2166 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2169 /* We want to output annotation for weak and external symbols at
2170 very last to check if they are references or not. */
2172 if (TARGET_SUPPORTS_WEAK
2174 /* TREE_STATIC is a weird and abused creature which is not
2175 generally the right test for whether an entity has been
2176 locally emitted, inlined or otherwise not-really-extern, but
2177 for declarations that can be weak, it happens to be
2179 && !TREE_STATIC (decl)
2180 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2181 && value_member (decl, weak_decls) == NULL_TREE)
2182 weak_decls = tree_cons (NULL, decl, weak_decls);
2184 #ifdef ASM_OUTPUT_EXTERNAL
2185 if (value_member (decl, pending_assemble_externals) == NULL_TREE)
2186 pending_assemble_externals = tree_cons (NULL, decl,
2187 pending_assemble_externals);
2191 /* Similar, for calling a library function FUN. */
2194 assemble_external_libcall (rtx fun)
2196 /* Declare library function name external when first used, if nec. */
2197 if (! SYMBOL_REF_USED (fun))
2199 SYMBOL_REF_USED (fun) = 1;
2200 targetm.asm_out.external_libcall (fun);
2204 /* Assemble a label named NAME. */
2207 assemble_label (FILE *file, const char *name)
2209 ASM_OUTPUT_LABEL (file, name);
2212 /* Set the symbol_referenced flag for ID. */
2214 mark_referenced (tree id)
2216 TREE_SYMBOL_REFERENCED (id) = 1;
2219 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2221 mark_decl_referenced (tree decl)
2223 if (TREE_CODE (decl) == FUNCTION_DECL)
2225 /* Extern inline functions don't become needed when referenced.
2226 If we know a method will be emitted in other TU and no new
2227 functions can be marked reachable, just use the external
2229 struct cgraph_node *node = cgraph_get_create_node (decl);
2230 if (!DECL_EXTERNAL (decl)
2231 && !node->local.finalized)
2232 cgraph_mark_needed_node (node);
2234 else if (TREE_CODE (decl) == VAR_DECL)
2236 struct varpool_node *node = varpool_node (decl);
2237 varpool_mark_needed_node (node);
2238 /* C++ frontend use mark_decl_references to force COMDAT variables
2239 to be output that might appear dead otherwise. */
2240 node->force_output = true;
2242 /* else do nothing - we can get various sorts of CST nodes here,
2243 which do not need to be marked. */
2247 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2248 until we find an identifier that is not itself a transparent alias.
2249 Modify the alias passed to it by reference (and all aliases on the
2250 way to the ultimate target), such that they do not have to be
2251 followed again, and return the ultimate target of the alias
2255 ultimate_transparent_alias_target (tree *alias)
2257 tree target = *alias;
2259 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2261 gcc_assert (TREE_CHAIN (target));
2262 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2263 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2264 && ! TREE_CHAIN (target));
2271 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2272 starts with a *, the rest of NAME is output verbatim. Otherwise
2273 NAME is transformed in a target-specific way (usually by the
2274 addition of an underscore). */
2277 assemble_name_raw (FILE *file, const char *name)
2280 fputs (&name[1], file);
2282 ASM_OUTPUT_LABELREF (file, name);
2285 /* Like assemble_name_raw, but should be used when NAME might refer to
2286 an entity that is also represented as a tree (like a function or
2287 variable). If NAME does refer to such an entity, that entity will
2288 be marked as referenced. */
2291 assemble_name (FILE *file, const char *name)
2293 const char *real_name;
2296 real_name = targetm.strip_name_encoding (name);
2298 id = maybe_get_identifier (real_name);
2303 mark_referenced (id);
2304 ultimate_transparent_alias_target (&id);
2306 name = IDENTIFIER_POINTER (id);
2307 gcc_assert (! TREE_CHAIN (id));
2310 assemble_name_raw (file, name);
2313 /* Allocate SIZE bytes writable static space with a gensym name
2314 and return an RTX to refer to its address. */
2317 assemble_static_space (unsigned HOST_WIDE_INT size)
2320 const char *namestring;
2323 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2325 namestring = ggc_strdup (name);
2327 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2328 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2330 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2331 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2334 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2335 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2338 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2339 so that each uninitialized object starts on such a boundary. */
2340 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2341 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2342 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2343 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2344 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2345 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2352 /* Assemble the static constant template for function entry trampolines.
2353 This is done at most once per compilation.
2354 Returns an RTX for the address of the template. */
2356 static GTY(()) rtx initial_trampoline;
2359 assemble_trampoline_template (void)
2366 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2368 if (initial_trampoline)
2369 return initial_trampoline;
2371 /* By default, put trampoline templates in read-only data section. */
2373 #ifdef TRAMPOLINE_SECTION
2374 switch_to_section (TRAMPOLINE_SECTION);
2376 switch_to_section (readonly_data_section);
2379 /* Write the assembler code to define one. */
2380 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2382 ASM_OUTPUT_ALIGN (asm_out_file, align);
2384 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2385 targetm.asm_out.trampoline_template (asm_out_file);
2387 /* Record the rtl to refer to it. */
2388 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2389 name = ggc_strdup (label);
2390 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2391 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2393 initial_trampoline = gen_const_mem (BLKmode, symbol);
2394 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2395 set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
2397 return initial_trampoline;
2400 /* A and B are either alignments or offsets. Return the minimum alignment
2401 that may be assumed after adding the two together. */
2403 static inline unsigned
2404 min_align (unsigned int a, unsigned int b)
2406 return (a | b) & -(a | b);
2409 /* Return the assembler directive for creating a given kind of integer
2410 object. SIZE is the number of bytes in the object and ALIGNED_P
2411 indicates whether it is known to be aligned. Return NULL if the
2412 assembly dialect has no such directive.
2414 The returned string should be printed at the start of a new line and
2415 be followed immediately by the object's initial value. */
2418 integer_asm_op (int size, int aligned_p)
2420 struct asm_int_op *ops;
2423 ops = &targetm.asm_out.aligned_op;
2425 ops = &targetm.asm_out.unaligned_op;
2430 return targetm.asm_out.byte_op;
2444 /* Use directive OP to assemble an integer object X. Print OP at the
2445 start of the line, followed immediately by the value of X. */
2448 assemble_integer_with_op (const char *op, rtx x)
2450 fputs (op, asm_out_file);
2451 output_addr_const (asm_out_file, x);
2452 fputc ('\n', asm_out_file);
2455 /* The default implementation of the asm_out.integer target hook. */
2458 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2459 unsigned int size ATTRIBUTE_UNUSED,
2460 int aligned_p ATTRIBUTE_UNUSED)
2462 const char *op = integer_asm_op (size, aligned_p);
2463 /* Avoid GAS bugs for large values. Specifically negative values whose
2464 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2465 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2467 return op && (assemble_integer_with_op (op, x), true);
2470 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2471 the alignment of the integer in bits. Return 1 if we were able to output
2472 the constant, otherwise 0. We must be able to output the constant,
2473 if FORCE is nonzero. */
2476 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2480 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2482 /* See if the target hook can handle this kind of object. */
2483 if (targetm.asm_out.integer (x, size, aligned_p))
2486 /* If the object is a multi-byte one, try splitting it up. Split
2487 it into words it if is multi-word, otherwise split it into bytes. */
2490 enum machine_mode omode, imode;
2491 unsigned int subalign;
2492 unsigned int subsize, i;
2493 enum mode_class mclass;
2495 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2496 subalign = MIN (align, subsize * BITS_PER_UNIT);
2497 if (GET_CODE (x) == CONST_FIXED)
2498 mclass = GET_MODE_CLASS (GET_MODE (x));
2502 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2503 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2505 for (i = 0; i < size; i += subsize)
2507 rtx partial = simplify_subreg (omode, x, imode, i);
2508 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2514 /* If we've printed some of it, but not all of it, there's no going
2519 gcc_assert (!force);
2525 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2527 long data[4] = {0, 0, 0, 0};
2529 int bitsize, nelts, nunits, units_per;
2531 /* This is hairy. We have a quantity of known size. real_to_target
2532 will put it into an array of *host* longs, 32 bits per element
2533 (even if long is more than 32 bits). We need to determine the
2534 number of array elements that are occupied (nelts) and the number
2535 of *target* min-addressable units that will be occupied in the
2536 object file (nunits). We cannot assume that 32 divides the
2537 mode's bitsize (size * BITS_PER_UNIT) evenly.
2539 size * BITS_PER_UNIT is used here to make sure that padding bits
2540 (which might appear at either end of the value; real_to_target
2541 will include the padding bits in its output array) are included. */
2543 nunits = GET_MODE_SIZE (mode);
2544 bitsize = nunits * BITS_PER_UNIT;
2545 nelts = CEIL (bitsize, 32);
2546 units_per = 32 / BITS_PER_UNIT;
2548 real_to_target (data, &d, mode);
2550 /* Put out the first word with the specified alignment. */
2551 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2552 nunits -= units_per;
2554 /* Subsequent words need only 32-bit alignment. */
2555 align = min_align (align, 32);
2557 for (i = 1; i < nelts; i++)
2559 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2560 nunits -= units_per;
2564 /* Given an expression EXP with a constant value,
2565 reduce it to the sum of an assembler symbol and an integer.
2566 Store them both in the structure *VALUE.
2567 EXP must be reducible. */
2571 HOST_WIDE_INT offset;
2575 decode_addr_const (tree exp, struct addr_const *value)
2577 tree target = TREE_OPERAND (exp, 0);
2583 if (TREE_CODE (target) == COMPONENT_REF
2584 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2586 offset += int_byte_position (TREE_OPERAND (target, 1));
2587 target = TREE_OPERAND (target, 0);
2589 else if (TREE_CODE (target) == ARRAY_REF
2590 || TREE_CODE (target) == ARRAY_RANGE_REF)
2592 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2593 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2594 target = TREE_OPERAND (target, 0);
2596 else if (TREE_CODE (target) == MEM_REF
2597 && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
2599 offset += mem_ref_offset (target).low;
2600 target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
2602 else if (TREE_CODE (target) == INDIRECT_REF
2603 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2604 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2606 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2611 switch (TREE_CODE (target))
2615 x = DECL_RTL (target);
2619 x = gen_rtx_MEM (FUNCTION_MODE,
2620 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2629 x = output_constant_def (target, 1);
2636 gcc_assert (MEM_P (x));
2640 value->offset = offset;
2644 static GTY((param_is (struct constant_descriptor_tree)))
2645 htab_t const_desc_htab;
2647 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2649 /* Constant pool accessor function. */
2652 constant_pool_htab (void)
2654 return const_desc_htab;
2657 /* Compute a hash code for a constant expression. */
2660 const_desc_hash (const void *ptr)
2662 return ((const struct constant_descriptor_tree *)ptr)->hash;
2666 const_hash_1 (const tree exp)
2671 enum tree_code code = TREE_CODE (exp);
2673 /* Either set P and LEN to the address and len of something to hash and
2674 exit the switch or return a value. */
2679 p = (char *) &TREE_INT_CST (exp);
2680 len = sizeof TREE_INT_CST (exp);
2684 return real_hash (TREE_REAL_CST_PTR (exp));
2687 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2690 p = TREE_STRING_POINTER (exp);
2691 len = TREE_STRING_LENGTH (exp);
2695 return (const_hash_1 (TREE_REALPART (exp)) * 5
2696 + const_hash_1 (TREE_IMAGPART (exp)));
2702 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2704 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2705 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2712 unsigned HOST_WIDE_INT idx;
2715 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2717 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2719 hi = hi * 603 + const_hash_1 (value);
2727 struct addr_const value;
2729 decode_addr_const (exp, &value);
2730 switch (GET_CODE (value.base))
2733 /* Don't hash the address of the SYMBOL_REF;
2734 only use the offset and the symbol name. */
2736 p = XSTR (value.base, 0);
2737 for (i = 0; p[i] != 0; i++)
2738 hi = ((hi * 613) + (unsigned) (p[i]));
2742 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2752 case POINTER_PLUS_EXPR:
2754 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2755 + const_hash_1 (TREE_OPERAND (exp, 1)));
2758 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2761 /* A language specific constant. Just hash the code. */
2765 /* Compute hashing function. */
2767 for (i = 0; i < len; i++)
2768 hi = ((hi * 613) + (unsigned) (p[i]));
2773 /* Wrapper of compare_constant, for the htab interface. */
2775 const_desc_eq (const void *p1, const void *p2)
2777 const struct constant_descriptor_tree *const c1
2778 = (const struct constant_descriptor_tree *) p1;
2779 const struct constant_descriptor_tree *const c2
2780 = (const struct constant_descriptor_tree *) p2;
2781 if (c1->hash != c2->hash)
2783 return compare_constant (c1->value, c2->value);
2786 /* Compare t1 and t2, and return 1 only if they are known to result in
2787 the same bit pattern on output. */
2790 compare_constant (const tree t1, const tree t2)
2792 enum tree_code typecode;
2794 if (t1 == NULL_TREE)
2795 return t2 == NULL_TREE;
2796 if (t2 == NULL_TREE)
2799 if (TREE_CODE (t1) != TREE_CODE (t2))
2802 switch (TREE_CODE (t1))
2805 /* Integer constants are the same only if the same width of type. */
2806 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2808 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2810 return tree_int_cst_equal (t1, t2);
2813 /* Real constants are the same only if the same width of type. */
2814 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2817 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2820 /* Fixed constants are the same only if the same width of type. */
2821 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2824 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2827 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2830 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2831 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2832 TREE_STRING_LENGTH (t1)));
2835 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2836 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2842 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
2843 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
2846 link2 = TREE_VECTOR_CST_ELTS (t2);
2847 for (link1 = TREE_VECTOR_CST_ELTS (t1);
2849 link1 = TREE_CHAIN (link1))
2851 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
2853 link2 = TREE_CHAIN (link2);
2861 VEC(constructor_elt, gc) *v1, *v2;
2862 unsigned HOST_WIDE_INT idx;
2864 typecode = TREE_CODE (TREE_TYPE (t1));
2865 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2868 if (typecode == ARRAY_TYPE)
2870 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2871 /* For arrays, check that the sizes all match. */
2872 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2874 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2879 /* For record and union constructors, require exact type
2881 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2885 v1 = CONSTRUCTOR_ELTS (t1);
2886 v2 = CONSTRUCTOR_ELTS (t2);
2887 if (VEC_length (constructor_elt, v1)
2888 != VEC_length (constructor_elt, v2))
2891 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2893 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2894 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2896 /* Check that each value is the same... */
2897 if (!compare_constant (c1->value, c2->value))
2899 /* ... and that they apply to the same fields! */
2900 if (typecode == ARRAY_TYPE)
2902 if (!compare_constant (c1->index, c2->index))
2907 if (c1->index != c2->index)
2918 struct addr_const value1, value2;
2922 decode_addr_const (t1, &value1);
2923 decode_addr_const (t2, &value2);
2925 if (value1.offset != value2.offset)
2928 code = GET_CODE (value1.base);
2929 if (code != GET_CODE (value2.base))
2935 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2939 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
2940 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
2950 case POINTER_PLUS_EXPR:
2953 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2954 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2957 case VIEW_CONVERT_EXPR:
2958 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2967 /* Make a copy of the whole tree structure for a constant. This
2968 handles the same types of nodes that compare_constant handles. */
2971 copy_constant (tree exp)
2973 switch (TREE_CODE (exp))
2976 /* For ADDR_EXPR, we do not want to copy the decl whose address
2977 is requested. We do want to copy constants though. */
2978 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2979 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2980 copy_constant (TREE_OPERAND (exp, 0)));
2982 return copy_node (exp);
2988 return copy_node (exp);
2991 return build_complex (TREE_TYPE (exp),
2992 copy_constant (TREE_REALPART (exp)),
2993 copy_constant (TREE_IMAGPART (exp)));
2996 case POINTER_PLUS_EXPR:
2998 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2999 copy_constant (TREE_OPERAND (exp, 0)),
3000 copy_constant (TREE_OPERAND (exp, 1)));
3003 case VIEW_CONVERT_EXPR:
3004 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3005 copy_constant (TREE_OPERAND (exp, 0)));
3008 return build_vector (TREE_TYPE (exp),
3009 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3013 tree copy = copy_node (exp);
3014 VEC(constructor_elt, gc) *v;
3015 unsigned HOST_WIDE_INT idx;
3016 tree purpose, value;
3018 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3019 CONSTRUCTOR_ELTS (exp)));
3020 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3022 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3023 ce->index = purpose;
3024 ce->value = copy_constant (value);
3026 CONSTRUCTOR_ELTS (copy) = v;
3035 /* Return the section into which constant EXP should be placed. */
3038 get_constant_section (tree exp, unsigned int align)
3040 return targetm.asm_out.select_section (exp,
3041 compute_reloc_for_constant (exp),
3045 /* Return the size of constant EXP in bytes. */
3047 static HOST_WIDE_INT
3048 get_constant_size (tree exp)
3052 size = int_size_in_bytes (TREE_TYPE (exp));
3053 if (TREE_CODE (exp) == STRING_CST)
3054 size = MAX (TREE_STRING_LENGTH (exp), size);
3058 /* Subroutine of output_constant_def:
3059 No constant equal to EXP is known to have been output.
3060 Make a constant descriptor to enter EXP in the hash table.
3061 Assign the label number and construct RTL to refer to the
3062 constant's location in memory.
3063 Caller is responsible for updating the hash table. */
3065 static struct constant_descriptor_tree *
3066 build_constant_desc (tree exp)
3068 struct constant_descriptor_tree *desc;
3074 desc = ggc_alloc_constant_descriptor_tree ();
3075 desc->value = copy_constant (exp);
3077 /* Propagate marked-ness to copied constant. */
3078 if (flag_mudflap && mf_marked_p (exp))
3079 mf_mark (desc->value);
3081 /* Create a string containing the label name, in LABEL. */
3082 labelno = const_labelno++;
3083 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3085 /* Construct the VAR_DECL associated with the constant. */
3086 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3088 DECL_ARTIFICIAL (decl) = 1;
3089 DECL_IGNORED_P (decl) = 1;
3090 TREE_READONLY (decl) = 1;
3091 TREE_STATIC (decl) = 1;
3092 TREE_ADDRESSABLE (decl) = 1;
3093 /* We don't set the RTL yet as this would cause varpool to assume that the
3094 variable is referenced. Moreover, it would just be dropped in LTO mode.
3095 Instead we set the flag that will be recognized in make_decl_rtl. */
3096 DECL_IN_CONSTANT_POOL (decl) = 1;
3097 DECL_INITIAL (decl) = desc->value;
3098 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3099 architectures so use DATA_ALIGNMENT as well, except for strings. */
3100 if (TREE_CODE (exp) == STRING_CST)
3102 #ifdef CONSTANT_ALIGNMENT
3103 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3107 align_variable (decl, 0);
3109 /* Now construct the SYMBOL_REF and the MEM. */
3110 if (use_object_blocks_p ())
3112 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3113 symbol = create_block_symbol (ggc_strdup (label),
3114 get_block_for_section (sect), -1);
3117 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3118 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3119 SET_SYMBOL_REF_DECL (symbol, decl);
3120 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3122 rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3123 set_mem_attributes (rtl, exp, 1);
3124 set_mem_alias_set (rtl, 0);
3125 set_mem_alias_set (rtl, const_alias_set);
3127 /* We cannot share RTX'es in pool entries.
3128 Mark this piece of RTL as required for unsharing. */
3129 RTX_FLAG (rtl, used) = 1;
3131 /* Set flags or add text to the name to record information, such as
3132 that it is a local symbol. If the name is changed, the macro
3133 ASM_OUTPUT_LABELREF will have to know how to strip this
3134 information. This call might invalidate our local variable
3135 SYMBOL; we can't use it afterward. */
3136 targetm.encode_section_info (exp, rtl, true);
3143 /* Return an rtx representing a reference to constant data in memory
3144 for the constant expression EXP.
3146 If assembler code for such a constant has already been output,
3147 return an rtx to refer to it.
3148 Otherwise, output such a constant in memory
3149 and generate an rtx for it.
3151 If DEFER is nonzero, this constant can be deferred and output only
3152 if referenced in the function after all optimizations.
3154 `const_desc_table' records which constants already have label strings. */
3157 output_constant_def (tree exp, int defer)
3159 struct constant_descriptor_tree *desc;
3160 struct constant_descriptor_tree key;
3163 /* Look up EXP in the table of constant descriptors. If we didn't find
3164 it, create a new one. */
3166 key.hash = const_hash_1 (exp);
3167 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3169 desc = (struct constant_descriptor_tree *) *loc;
3172 desc = build_constant_desc (exp);
3173 desc->hash = key.hash;
3177 maybe_output_constant_def_contents (desc, defer);
3181 /* Subroutine of output_constant_def: Decide whether or not we need to
3182 output the constant DESC now, and if so, do it. */
3184 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3187 rtx symbol = XEXP (desc->rtl, 0);
3188 tree exp = desc->value;
3190 if (flag_syntax_only)
3193 if (TREE_ASM_WRITTEN (exp))
3194 /* Already output; don't do it again. */
3197 /* We can always defer constants as long as the context allows
3201 /* Increment n_deferred_constants if it exists. It needs to be at
3202 least as large as the number of constants actually referred to
3203 by the function. If it's too small we'll stop looking too early
3204 and fail to emit constants; if it's too large we'll only look
3205 through the entire function when we could have stopped earlier. */
3207 n_deferred_constants++;
3211 output_constant_def_contents (symbol);
3214 /* Subroutine of output_constant_def_contents. Output the definition
3215 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3216 constant's alignment in bits. */
3219 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3223 size = get_constant_size (exp);
3225 /* Do any machine/system dependent processing of the constant. */
3226 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3228 /* Output the value of EXP. */
3229 output_constant (exp, size, align);
3232 /* We must output the constant data referred to by SYMBOL; do so. */
3235 output_constant_def_contents (rtx symbol)
3237 tree decl = SYMBOL_REF_DECL (symbol);
3238 tree exp = DECL_INITIAL (decl);
3241 /* Make sure any other constants whose addresses appear in EXP
3242 are assigned label numbers. */
3243 output_addressed_constants (exp);
3245 /* We are no longer deferring this constant. */
3246 TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3248 /* If the constant is part of an object block, make sure that the
3249 decl has been positioned within its block, but do not write out
3250 its definition yet. output_object_blocks will do that later. */
3251 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3252 place_block_symbol (symbol);
3255 align = DECL_ALIGN (decl);
3256 switch_to_section (get_constant_section (exp, align));
3257 if (align > BITS_PER_UNIT)
3258 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3259 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3262 mudflap_enqueue_constant (exp);
3265 /* Look up EXP in the table of constant descriptors. Return the rtl
3266 if it has been emitted, else null. */
3269 lookup_constant_def (tree exp)
3271 struct constant_descriptor_tree *desc;
3272 struct constant_descriptor_tree key;
3275 key.hash = const_hash_1 (exp);
3276 desc = (struct constant_descriptor_tree *)
3277 htab_find_with_hash (const_desc_htab, &key, key.hash);
3279 return (desc ? desc->rtl : NULL_RTX);
3282 /* Return a tree representing a reference to constant data in memory
3283 for the constant expression EXP.
3285 This is the counterpart of output_constant_def at the Tree level. */
3288 tree_output_constant_def (tree exp)
3290 struct constant_descriptor_tree *desc, key;
3294 /* Look up EXP in the table of constant descriptors. If we didn't find
3295 it, create a new one. */
3297 key.hash = const_hash_1 (exp);
3298 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3300 desc = (struct constant_descriptor_tree *) *loc;
3303 desc = build_constant_desc (exp);
3304 desc->hash = key.hash;
3308 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3309 varpool_finalize_decl (decl);
3313 /* Used in the hash tables to avoid outputting the same constant
3314 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3315 are output once per function, not once per file. */
3316 /* ??? Only a few targets need per-function constant pools. Most
3317 can use one per-file pool. Should add a targetm bit to tell the
3320 struct GTY(()) rtx_constant_pool {
3321 /* Pointers to first and last constant in pool, as ordered by offset. */
3322 struct constant_descriptor_rtx *first;
3323 struct constant_descriptor_rtx *last;
3325 /* Hash facility for making memory-constants from constant rtl-expressions.
3326 It is used on RISC machines where immediate integer arguments and
3327 constant addresses are restricted so that such constants must be stored
3329 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3331 /* Current offset in constant pool (does not include any
3332 machine-specific header). */
3333 HOST_WIDE_INT offset;
3336 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3337 struct constant_descriptor_rtx *next;
3341 HOST_WIDE_INT offset;
3343 enum machine_mode mode;
3349 /* Hash and compare functions for const_rtx_htab. */
3352 const_desc_rtx_hash (const void *ptr)
3354 const struct constant_descriptor_rtx *const desc
3355 = (const struct constant_descriptor_rtx *) ptr;
3360 const_desc_rtx_eq (const void *a, const void *b)
3362 const struct constant_descriptor_rtx *const x
3363 = (const struct constant_descriptor_rtx *) a;
3364 const struct constant_descriptor_rtx *const y
3365 = (const struct constant_descriptor_rtx *) b;
3367 if (x->mode != y->mode)
3369 return rtx_equal_p (x->constant, y->constant);
3372 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3375 const_rtx_hash_1 (rtx *xp, void *data)
3377 unsigned HOST_WIDE_INT hwi;
3378 enum machine_mode mode;
3384 code = GET_CODE (x);
3385 mode = GET_MODE (x);
3386 h = (hashval_t) code * 1048573 + mode;
3394 int shift = sizeof (hashval_t) * CHAR_BIT;
3395 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3398 h ^= (hashval_t) hwi;
3399 for (i = 1; i < n; ++i)
3402 h ^= (hashval_t) hwi;
3408 if (mode == VOIDmode)
3410 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3414 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3418 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3424 for (i = XVECLEN (x, 0); i-- > 0; )
3425 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3430 h ^= htab_hash_string (XSTR (x, 0));
3434 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3438 case UNSPEC_VOLATILE:
3439 h = h * 251 + XINT (x, 1);
3446 hp = (hashval_t *) data;
3447 *hp = *hp * 509 + h;
3451 /* Compute a hash value for X, which should be a constant. */
3454 const_rtx_hash (rtx x)
3457 for_each_rtx (&x, const_rtx_hash_1, &h);
3462 /* Create and return a new rtx constant pool. */
3464 static struct rtx_constant_pool *
3465 create_constant_pool (void)
3467 struct rtx_constant_pool *pool;
3469 pool = ggc_alloc_rtx_constant_pool ();
3470 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3471 const_desc_rtx_eq, NULL);
3478 /* Initialize constant pool hashing for a new function. */
3481 init_varasm_status (void)
3483 crtl->varasm.pool = create_constant_pool ();
3484 crtl->varasm.deferred_constants = 0;
3487 /* Given a MINUS expression, simplify it if both sides
3488 include the same symbol. */
3491 simplify_subtraction (rtx x)
3493 rtx r = simplify_rtx (x);
3497 /* Given a constant rtx X, make (or find) a memory constant for its value
3498 and return a MEM rtx to refer to it in memory. */
3501 force_const_mem (enum machine_mode mode, rtx x)
3503 struct constant_descriptor_rtx *desc, tmp;
3504 struct rtx_constant_pool *pool;
3511 /* If we're not allowed to drop X into the constant pool, don't. */
3512 if (targetm.cannot_force_const_mem (mode, x))
3515 /* Record that this function has used a constant pool entry. */
3516 crtl->uses_const_pool = 1;
3518 /* Decide which pool to use. */
3519 pool = (targetm.use_blocks_for_constant_p (mode, x)
3520 ? shared_constant_pool
3521 : crtl->varasm.pool);
3523 /* Lookup the value in the hashtable. */
3526 hash = const_rtx_hash (x);
3527 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3528 desc = (struct constant_descriptor_rtx *) *slot;
3530 /* If the constant was already present, return its memory. */
3532 return copy_rtx (desc->mem);
3534 /* Otherwise, create a new descriptor. */
3535 desc = ggc_alloc_constant_descriptor_rtx ();
3538 /* Align the location counter as required by EXP's data type. */
3539 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3540 #ifdef CONSTANT_ALIGNMENT
3542 tree type = lang_hooks.types.type_for_mode (mode, 0);
3543 if (type != NULL_TREE)
3544 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3548 pool->offset += (align / BITS_PER_UNIT) - 1;
3549 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3552 desc->constant = copy_rtx (tmp.constant);
3553 desc->offset = pool->offset;
3556 desc->align = align;
3557 desc->labelno = const_labelno;
3560 pool->offset += GET_MODE_SIZE (mode);
3562 pool->last->next = desc;
3564 pool->first = pool->last = desc;
3567 /* Create a string containing the label name, in LABEL. */
3568 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3571 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3572 the constants pool. */
3573 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3575 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3576 symbol = create_block_symbol (ggc_strdup (label),
3577 get_block_for_section (sect), -1);
3580 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3582 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3583 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3584 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3586 /* Construct the MEM. */
3587 desc->mem = def = gen_const_mem (mode, symbol);
3588 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3589 set_mem_align (def, align);
3591 /* If we're dropping a label to the constant pool, make sure we
3593 if (GET_CODE (x) == LABEL_REF)
3594 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3596 return copy_rtx (def);
3599 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3602 get_pool_constant (rtx addr)
3604 return SYMBOL_REF_CONSTANT (addr)->constant;
3607 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3608 and whether it has been output or not. */
3611 get_pool_constant_mark (rtx addr, bool *pmarked)
3613 struct constant_descriptor_rtx *desc;
3615 desc = SYMBOL_REF_CONSTANT (addr);
3616 *pmarked = (desc->mark != 0);
3617 return desc->constant;
3620 /* Similar, return the mode. */
3623 get_pool_mode (const_rtx addr)
3625 return SYMBOL_REF_CONSTANT (addr)->mode;
3628 /* Return the size of the constant pool. */
3631 get_pool_size (void)
3633 return crtl->varasm.pool->offset;
3636 /* Worker function for output_constant_pool_1. Emit assembly for X
3637 in MODE with known alignment ALIGN. */
3640 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3642 switch (GET_MODE_CLASS (mode))
3645 case MODE_DECIMAL_FLOAT:
3649 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3650 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3651 assemble_real (r, mode, align);
3656 case MODE_PARTIAL_INT:
3661 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3664 case MODE_VECTOR_FLOAT:
3665 case MODE_VECTOR_INT:
3666 case MODE_VECTOR_FRACT:
3667 case MODE_VECTOR_UFRACT:
3668 case MODE_VECTOR_ACCUM:
3669 case MODE_VECTOR_UACCUM:
3672 enum machine_mode submode = GET_MODE_INNER (mode);
3673 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3675 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3676 units = CONST_VECTOR_NUNITS (x);
3678 for (i = 0; i < units; i++)
3680 rtx elt = CONST_VECTOR_ELT (x, i);
3681 output_constant_pool_2 (submode, elt, i ? subalign : align);
3691 /* Worker function for output_constant_pool. Emit constant DESC,
3692 giving it ALIGN bits of alignment. */
3695 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3702 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3703 whose CODE_LABEL has been deleted. This can occur if a jump table
3704 is eliminated by optimization. If so, write a constant of zero
3705 instead. Note that this can also happen by turning the
3706 CODE_LABEL into a NOTE. */
3707 /* ??? This seems completely and utterly wrong. Certainly it's
3708 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3709 functioning even with INSN_DELETED_P and friends. */
3712 switch (GET_CODE (tmp))
3715 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3716 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3718 tmp = XEXP (XEXP (tmp, 0), 0);