1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
33 #include "pointer-set.h"
40 #include "hard-reg-set.h"
43 #include "diagnostic-core.h"
46 #include "langhooks.h"
50 #include "common/common-target.h"
51 #include "targhooks.h"
52 #include "tree-mudflap.h"
54 #include "cfglayout.h"
55 #include "basic-block.h"
56 #include "tree-iterator.h"
57 #include "pointer-set.h"
59 #ifdef XCOFF_DEBUGGING_INFO
60 #include "xcoffout.h" /* Needed for external data
61 declarations for e.g. AIX 4.x. */
64 /* The (assembler) name of the first globally-visible object output. */
65 extern GTY(()) const char *first_global_object_name;
66 extern GTY(()) const char *weak_global_object_name;
68 const char *first_global_object_name;
69 const char *weak_global_object_name;
72 struct constant_descriptor_rtx;
73 struct rtx_constant_pool;
75 #define n_deferred_constants (crtl->varasm.deferred_constants)
77 /* Number for making the label on the next
78 constant that is stored in memory. */
80 static GTY(()) int const_labelno;
82 /* Carry information from ASM_DECLARE_OBJECT_NAME
83 to ASM_FINISH_DECLARE_OBJECT. */
85 int size_directive_output;
87 /* The last decl for which assemble_variable was called,
88 if it did ASM_DECLARE_OBJECT_NAME.
89 If the last call to assemble_variable didn't do that,
92 tree last_assemble_variable_decl;
94 /* The following global variable indicates if the first basic block
95 in a function belongs to the cold partition or not. */
97 bool first_function_block_is_cold;
99 /* We give all constants their own alias set. Perhaps redundant with
100 MEM_READONLY_P, but pre-dates it. */
102 static alias_set_type const_alias_set;
104 /* Whether we saw any functions with no_split_stack. */
106 static bool saw_no_split_stack;
108 static const char *strip_reg_name (const char *);
109 static int contains_pointers_p (tree);
110 #ifdef ASM_OUTPUT_EXTERNAL
111 static bool incorporeal_function_p (tree);
113 static void decode_addr_const (tree, struct addr_const *);
114 static hashval_t const_desc_hash (const void *);
115 static int const_desc_eq (const void *, const void *);
116 static hashval_t const_hash_1 (const tree);
117 static int compare_constant (const tree, const tree);
118 static tree copy_constant (tree);
119 static void output_constant_def_contents (rtx);
120 static void output_addressed_constants (tree);
121 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
122 static unsigned min_align (unsigned, unsigned);
123 static void globalize_decl (tree);
124 static bool decl_readonly_section_1 (enum section_category);
125 #ifdef BSS_SECTION_ASM_OP
126 #ifdef ASM_OUTPUT_ALIGNED_BSS
127 static void asm_output_aligned_bss (FILE *, tree, const char *,
128 unsigned HOST_WIDE_INT, int)
131 #endif /* BSS_SECTION_ASM_OP */
132 static void mark_weak (tree);
133 static void output_constant_pool (const char *, tree);
135 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
136 section *text_section;
137 section *data_section;
138 section *readonly_data_section;
139 section *sdata_section;
140 section *ctors_section;
141 section *dtors_section;
142 section *bss_section;
143 section *sbss_section;
145 /* Various forms of common section. All are guaranteed to be nonnull. */
146 section *tls_comm_section;
147 section *comm_section;
148 section *lcomm_section;
150 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
152 section *bss_noswitch_section;
154 /* The section that holds the main exception table, when known. The section
155 is set either by the target's init_sections hook or by the first call to
156 switch_to_exception_section. */
157 section *exception_section;
159 /* The section that holds the DWARF2 frame unwind information, when known.
160 The section is set either by the target's init_sections hook or by the
161 first call to switch_to_eh_frame_section. */
162 section *eh_frame_section;
164 /* asm_out_file's current section. This is NULL if no section has yet
165 been selected or if we lose track of what the current section is. */
168 /* True if code for the current function is currently being directed
169 at the cold section. */
170 bool in_cold_section_p;
172 /* A linked list of all the unnamed sections. */
173 static GTY(()) section *unnamed_sections;
175 /* Return a nonzero value if DECL has a section attribute. */
176 #define IN_NAMED_SECTION(DECL) \
177 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
178 && DECL_SECTION_NAME (DECL) != NULL_TREE)
180 /* Hash table of named sections. */
181 static GTY((param_is (section))) htab_t section_htab;
183 /* A table of object_blocks, indexed by section. */
184 static GTY((param_is (struct object_block))) htab_t object_block_htab;
186 /* The next number to use for internal anchor labels. */
187 static GTY(()) int anchor_labelno;
189 /* A pool of constants that can be shared between functions. */
190 static GTY(()) struct rtx_constant_pool *shared_constant_pool;
192 /* Helper routines for maintaining section_htab. */
195 section_entry_eq (const void *p1, const void *p2)
197 const section *old = (const section *) p1;
198 const char *new_name = (const char *) p2;
200 return strcmp (old->named.name, new_name) == 0;
204 section_entry_hash (const void *p)
206 const section *old = (const section *) p;
207 return htab_hash_string (old->named.name);
210 /* Return a hash value for section SECT. */
213 hash_section (section *sect)
215 if (sect->common.flags & SECTION_NAMED)
216 return htab_hash_string (sect->named.name);
217 return sect->common.flags;
220 /* Helper routines for maintaining object_block_htab. */
223 object_block_entry_eq (const void *p1, const void *p2)
225 const struct object_block *old = (const struct object_block *) p1;
226 const section *new_section = (const section *) p2;
228 return old->sect == new_section;
232 object_block_entry_hash (const void *p)
234 const struct object_block *old = (const struct object_block *) p;
235 return hash_section (old->sect);
238 /* Return a new unnamed section with the given fields. */
241 get_unnamed_section (unsigned int flags, void (*callback) (const void *),
246 sect = ggc_alloc_section ();
247 sect->unnamed.common.flags = flags | SECTION_UNNAMED;
248 sect->unnamed.callback = callback;
249 sect->unnamed.data = data;
250 sect->unnamed.next = unnamed_sections;
252 unnamed_sections = sect;
256 /* Return a SECTION_NOSWITCH section with the given fields. */
259 get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
263 sect = ggc_alloc_section ();
264 sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
265 sect->noswitch.callback = callback;
270 /* Return the named section structure associated with NAME. Create
271 a new section with the given fields if no such structure exists. */
274 get_section (const char *name, unsigned int flags, tree decl)
276 section *sect, **slot;
279 htab_find_slot_with_hash (section_htab, name,
280 htab_hash_string (name), INSERT);
281 flags |= SECTION_NAMED;
284 sect = ggc_alloc_section ();
285 sect->named.common.flags = flags;
286 sect->named.name = ggc_strdup (name);
287 sect->named.decl = decl;
293 if ((sect->common.flags & ~SECTION_DECLARED) != flags
294 && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
296 /* It is fine if one of the section flags is
297 SECTION_WRITE | SECTION_RELRO and the other has none of these
298 flags (i.e. read-only) in named sections and either the
299 section hasn't been declared yet or has been declared as writable.
300 In that case just make sure the resulting flags are
301 SECTION_WRITE | SECTION_RELRO, ie. writable only because of
303 if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
304 == (SECTION_WRITE | SECTION_RELRO)
305 && (sect->common.flags
306 & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
307 == (flags & ~(SECTION_WRITE | SECTION_RELRO))
308 && ((sect->common.flags & SECTION_DECLARED) == 0
309 || (sect->common.flags & SECTION_WRITE)))
311 sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
314 /* Sanity check user variables for flag changes. */
316 decl = sect->named.decl;
318 error ("%+D causes a section type conflict with %D",
319 decl, sect->named.decl);
320 if (decl != sect->named.decl)
321 inform (DECL_SOURCE_LOCATION (sect->named.decl),
322 "%qD was declared here", sect->named.decl);
323 /* Make sure we don't error about one section multiple times. */
324 sect->common.flags |= SECTION_OVERRIDE;
330 /* Return true if the current compilation mode benefits from having
331 objects grouped into blocks. */
334 use_object_blocks_p (void)
336 return flag_section_anchors;
339 /* Return the object_block structure for section SECT. Create a new
340 structure if we haven't created one already. Return null if SECT
343 static struct object_block *
344 get_block_for_section (section *sect)
346 struct object_block *block;
352 slot = htab_find_slot_with_hash (object_block_htab, sect,
353 hash_section (sect), INSERT);
354 block = (struct object_block *) *slot;
357 block = ggc_alloc_cleared_object_block ();
364 /* Create a symbol with label LABEL and place it at byte offset
365 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
366 is not yet known. LABEL must be a garbage-collected string. */
369 create_block_symbol (const char *label, struct object_block *block,
370 HOST_WIDE_INT offset)
375 /* Create the extended SYMBOL_REF. */
376 size = RTX_HDR_SIZE + sizeof (struct block_symbol);
377 symbol = ggc_alloc_zone_rtx_def (size, &rtl_zone);
379 /* Initialize the normal SYMBOL_REF fields. */
380 memset (symbol, 0, size);
381 PUT_CODE (symbol, SYMBOL_REF);
382 PUT_MODE (symbol, Pmode);
383 XSTR (symbol, 0) = label;
384 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
386 /* Initialize the block_symbol stuff. */
387 SYMBOL_REF_BLOCK (symbol) = block;
388 SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
393 /* Return a section with a particular name and with whatever SECTION_*
394 flags section_type_flags deems appropriate. The name of the section
395 is taken from NAME if nonnull, otherwise it is taken from DECL's
396 DECL_SECTION_NAME. DECL is the decl associated with the section
397 (see the section comment for details) and RELOC is as for
398 section_type_flags. */
401 get_named_section (tree decl, const char *name, int reloc)
405 gcc_assert (!decl || DECL_P (decl));
407 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
409 flags = targetm.section_type_flags (decl, name, reloc);
411 return get_section (name, flags, decl);
414 /* If required, set DECL_SECTION_NAME to a unique name. */
417 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
418 int flag_function_or_data_sections)
420 if (DECL_SECTION_NAME (decl) == NULL_TREE
421 && targetm_common.have_named_sections
422 && (flag_function_or_data_sections
423 || DECL_ONE_ONLY (decl)))
425 targetm.asm_out.unique_section (decl, reloc);
426 DECL_HAS_IMPLICIT_SECTION_NAME_P (decl) = true;
430 #ifdef BSS_SECTION_ASM_OP
432 #ifdef ASM_OUTPUT_ALIGNED_BSS
434 /* Utility function for targets to use in implementing
435 ASM_OUTPUT_ALIGNED_BSS.
436 ??? It is believed that this function will work in most cases so such
437 support is localized here. */
440 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
441 const char *name, unsigned HOST_WIDE_INT size,
444 switch_to_section (bss_section);
445 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
446 #ifdef ASM_DECLARE_OBJECT_NAME
447 last_assemble_variable_decl = decl;
448 ASM_DECLARE_OBJECT_NAME (file, name, decl);
450 /* Standard thing is just output label for the object. */
451 ASM_OUTPUT_LABEL (file, name);
452 #endif /* ASM_DECLARE_OBJECT_NAME */
453 ASM_OUTPUT_SKIP (file, size ? size : 1);
458 #endif /* BSS_SECTION_ASM_OP */
460 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
461 /* Return the hot section for function DECL. Return text_section for
465 hot_function_section (tree decl)
467 if (decl != NULL_TREE
468 && DECL_SECTION_NAME (decl) != NULL_TREE
469 && targetm_common.have_named_sections)
470 return get_named_section (decl, NULL, 0);
476 /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
479 When DECL_SECTION_NAME is non-NULL and it is implicit section and
480 NAMED_SECTION_SUFFIX is non-NULL, then produce section called
481 concatenate the name with NAMED_SECTION_SUFFIX.
482 Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
485 get_named_text_section (tree decl,
486 const char *text_section_name,
487 const char *named_section_suffix)
489 if (decl && DECL_SECTION_NAME (decl))
491 if (named_section_suffix)
493 tree dsn = DECL_SECTION_NAME (decl);
494 const char *stripped_name;
497 name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1);
498 memcpy (name, TREE_STRING_POINTER (dsn),
499 TREE_STRING_LENGTH (dsn) + 1);
501 stripped_name = targetm.strip_name_encoding (name);
503 buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
504 return get_named_section (decl, buffer, 0);
506 else if (DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
510 /* Do not try to split gnu_linkonce functions. This gets somewhat
512 if (DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP)
514 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
515 name = targetm.strip_name_encoding (name);
516 return get_named_section (decl, ACONCAT ((text_section_name, ".",
522 return get_named_section (decl, text_section_name, 0);
525 /* Choose named function section based on its frequency. */
528 default_function_section (tree decl, enum node_frequency freq,
529 bool startup, bool exit)
531 #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
532 /* Old GNU linkers have buggy --gc-section support, which sometimes
533 results in .gcc_except_table* sections being garbage collected. */
535 && DECL_SECTION_NAME (decl)
536 && DECL_HAS_IMPLICIT_SECTION_NAME_P (decl))
540 if (!flag_reorder_functions
541 || !targetm_common.have_named_sections)
543 /* Startup code should go to startup subsection unless it is
544 unlikely executed (this happens especially with function splitting
545 where we can split away unnecesary parts of static constructors. */
546 if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
547 return get_named_text_section (decl, ".text.startup", NULL);
549 /* Similarly for exit. */
550 if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
551 return get_named_text_section (decl, ".text.exit", NULL);
553 /* Group cold functions together, similarly for hot code. */
556 case NODE_FREQUENCY_UNLIKELY_EXECUTED:
557 return get_named_text_section (decl, ".text.unlikely", NULL);
558 case NODE_FREQUENCY_HOT:
559 return get_named_text_section (decl, ".text.hot", NULL);
565 /* Return the section for function DECL.
567 If DECL is NULL_TREE, return the text section. We can be passed
568 NULL_TREE under some circumstances by dbxout.c at least.
570 If FORCE_COLD is true, return cold function section ignoring
571 the frequency info of cgraph_node. */
574 function_section_1 (tree decl, bool force_cold)
576 section *section = NULL;
577 enum node_frequency freq = NODE_FREQUENCY_NORMAL;
578 bool startup = false, exit = false;
582 struct cgraph_node *node = cgraph_get_node (decl);
586 freq = node->frequency;
587 startup = node->only_called_at_startup;
588 exit = node->only_called_at_exit;
592 freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
594 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
595 if (decl != NULL_TREE
596 && DECL_SECTION_NAME (decl) != NULL_TREE)
598 if (targetm.asm_out.function_section)
599 section = targetm.asm_out.function_section (decl, freq,
603 return get_named_section (decl, NULL, 0);
606 return targetm.asm_out.select_section
607 (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
610 if (targetm.asm_out.function_section)
611 section = targetm.asm_out.function_section (decl, freq, startup, exit);
614 return hot_function_section (decl);
618 /* Return the section for function DECL.
620 If DECL is NULL_TREE, return the text section. We can be passed
621 NULL_TREE under some circumstances by dbxout.c at least. */
624 function_section (tree decl)
626 /* Handle cases where function splitting code decides
627 to put function entry point into unlikely executed section
628 despite the fact that the function itself is not cold
629 (i.e. it is called rarely but contains a hot loop that is
630 better to live in hot subsection for the code locality). */
631 return function_section_1 (decl,
632 first_function_block_is_cold);
635 /* Return the section for the current function, take IN_COLD_SECTION_P
639 current_function_section (void)
641 return function_section_1 (current_function_decl, in_cold_section_p);
644 /* Tell assembler to switch to unlikely-to-be-executed text section. */
647 unlikely_text_section (void)
649 return function_section_1 (current_function_decl, true);
652 /* When called within a function context, return true if the function
653 has been assigned a cold text section and if SECT is that section.
654 When called outside a function context, return true if SECT is the
655 default cold section. */
658 unlikely_text_section_p (section *sect)
660 return sect == function_section_1 (current_function_decl, true);
663 /* Return the read-only data section associated with function DECL. */
666 default_function_rodata_section (tree decl)
668 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
670 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
672 if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP)
678 dot = strchr (name + 1, '.');
681 len = strlen (dot) + 8;
682 rname = (char *) alloca (len);
684 strcpy (rname, ".rodata");
686 return get_section (rname, SECTION_LINKONCE, decl);
688 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
689 else if (DECL_ONE_ONLY (decl)
690 && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
692 size_t len = strlen (name) + 1;
693 char *rname = (char *) alloca (len);
695 memcpy (rname, name, len);
697 return get_section (rname, SECTION_LINKONCE, decl);
699 /* For .text.foo we want to use .rodata.foo. */
700 else if (flag_function_sections && flag_data_sections
701 && strncmp (name, ".text.", 6) == 0)
703 size_t len = strlen (name) + 1;
704 char *rname = (char *) alloca (len + 2);
706 memcpy (rname, ".rodata", 7);
707 memcpy (rname + 7, name + 5, len - 5);
708 return get_section (rname, 0, decl);
712 return readonly_data_section;
715 /* Return the read-only data section associated with function DECL
716 for targets where that section should be always the single
717 readonly data section. */
720 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
722 return readonly_data_section;
725 /* Return the section to use for string merging. */
728 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
729 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
730 unsigned int flags ATTRIBUTE_UNUSED)
734 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
735 && TREE_CODE (decl) == STRING_CST
736 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
738 && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
739 && TREE_STRING_LENGTH (decl) >= len)
741 enum machine_mode mode;
742 unsigned int modesize;
746 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
747 char *name = (char *) alloca (strlen (prefix) + 30);
749 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
750 modesize = GET_MODE_BITSIZE (mode);
751 if (modesize >= 8 && modesize <= 256
752 && (modesize & (modesize - 1)) == 0)
754 if (align < modesize)
757 str = TREE_STRING_POINTER (decl);
758 unit = GET_MODE_SIZE (mode);
760 /* Check for embedded NUL characters. */
761 for (i = 0; i < len; i += unit)
763 for (j = 0; j < unit; j++)
764 if (str[i + j] != '\0')
771 sprintf (name, "%s.str%d.%d", prefix,
772 modesize / 8, (int) (align / 8));
773 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
774 return get_section (name, flags, NULL);
779 return readonly_data_section;
782 /* Return the section to use for constant merging. */
785 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
786 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
787 unsigned int flags ATTRIBUTE_UNUSED)
789 unsigned int modesize = GET_MODE_BITSIZE (mode);
791 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
797 && (align & (align - 1)) == 0)
799 const char *prefix = targetm.asm_out.mergeable_rodata_prefix;
800 char *name = (char *) alloca (strlen (prefix) + 30);
802 sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
803 flags |= (align / 8) | SECTION_MERGE;
804 return get_section (name, flags, NULL);
806 return readonly_data_section;
809 /* Given NAME, a putative register name, discard any customary prefixes. */
812 strip_reg_name (const char *name)
814 #ifdef REGISTER_PREFIX
815 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
816 name += strlen (REGISTER_PREFIX);
818 if (name[0] == '%' || name[0] == '#')
823 /* The user has asked for a DECL to have a particular name. Set (or
824 change) it in such a way that we don't prefix an underscore to
827 set_user_assembler_name (tree decl, const char *name)
829 char *starred = (char *) alloca (strlen (name) + 2);
831 strcpy (starred + 1, name);
832 change_decl_assembler_name (decl, get_identifier (starred));
833 SET_DECL_RTL (decl, NULL_RTX);
836 /* Decode an `asm' spec for a declaration as a register name.
837 Return the register number, or -1 if nothing specified,
838 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
839 or -3 if ASMSPEC is `cc' and is not recognized,
840 or -4 if ASMSPEC is `memory' and is not recognized.
841 Accept an exact spelling or a decimal number.
842 Prefixes such as % are optional. */
845 decode_reg_name_and_count (const char *asmspec, int *pnregs)
847 /* Presume just one register is clobbered. */
854 /* Get rid of confusing prefixes. */
855 asmspec = strip_reg_name (asmspec);
857 /* Allow a decimal number as a "register name". */
858 for (i = strlen (asmspec) - 1; i >= 0; i--)
859 if (! ISDIGIT (asmspec[i]))
861 if (asmspec[0] != 0 && i < 0)
864 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
870 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
872 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
875 #ifdef OVERLAPPING_REGISTER_NAMES
879 const char *const name;
882 } table[] = OVERLAPPING_REGISTER_NAMES;
884 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
886 && ! strcmp (asmspec, table[i].name))
888 *pnregs = table[i].nregs;
889 return table[i].number;
892 #endif /* OVERLAPPING_REGISTER_NAMES */
894 #ifdef ADDITIONAL_REGISTER_NAMES
896 static const struct { const char *const name; const int number; } table[]
897 = ADDITIONAL_REGISTER_NAMES;
899 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
901 && ! strcmp (asmspec, table[i].name))
902 return table[i].number;
904 #endif /* ADDITIONAL_REGISTER_NAMES */
906 if (!strcmp (asmspec, "memory"))
909 if (!strcmp (asmspec, "cc"))
919 decode_reg_name (const char *name)
922 return decode_reg_name_and_count (name, &count);
926 /* Return true if DECL's initializer is suitable for a BSS section. */
929 bss_initializer_p (const_tree decl)
931 return (DECL_INITIAL (decl) == NULL
932 || DECL_INITIAL (decl) == error_mark_node
933 || (flag_zero_initialized_in_bss
934 /* Leave constant zeroes in .rodata so they
936 && !TREE_READONLY (decl)
937 && initializer_zerop (DECL_INITIAL (decl))));
940 /* Compute the alignment of variable specified by DECL.
941 DONT_OUTPUT_DATA is from assemble_variable. */
944 align_variable (tree decl, bool dont_output_data)
946 unsigned int align = DECL_ALIGN (decl);
948 /* In the case for initialing an array whose length isn't specified,
949 where we have not yet been able to do the layout,
950 figure out the proper alignment now. */
951 if (dont_output_data && DECL_SIZE (decl) == 0
952 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
953 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
955 /* Some object file formats have a maximum alignment which they support.
956 In particular, a.out format supports a maximum alignment of 4. */
957 if (align > MAX_OFILE_ALIGNMENT)
959 warning (0, "alignment of %q+D is greater than maximum object "
960 "file alignment. Using %d", decl,
961 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
962 align = MAX_OFILE_ALIGNMENT;
965 /* On some machines, it is good to increase alignment sometimes. */
966 if (! DECL_USER_ALIGN (decl))
968 #ifdef DATA_ALIGNMENT
969 unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
970 /* Don't increase alignment too much for TLS variables - TLS space
972 if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
975 #ifdef CONSTANT_ALIGNMENT
976 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
978 unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl),
980 /* Don't increase alignment too much for TLS variables - TLS space
982 if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
988 /* Reset the alignment in case we have made it tighter, so we can benefit
989 from it in get_pointer_alignment. */
990 DECL_ALIGN (decl) = align;
993 /* Return the section into which the given VAR_DECL or CONST_DECL
994 should be placed. PREFER_NOSWITCH_P is true if a noswitch
995 section should be used wherever possible. */
998 get_variable_section (tree decl, bool prefer_noswitch_p)
1000 addr_space_t as = ADDR_SPACE_GENERIC;
1003 if (TREE_TYPE (decl) != error_mark_node)
1004 as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1006 if (DECL_COMMON (decl))
1008 /* If the decl has been given an explicit section name, or it resides
1009 in a non-generic address space, then it isn't common, and shouldn't
1010 be handled as such. */
1011 gcc_assert (DECL_SECTION_NAME (decl) == NULL
1012 && ADDR_SPACE_GENERIC_P (as));
1013 if (DECL_THREAD_LOCAL_P (decl))
1014 return tls_comm_section;
1015 else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1016 return comm_section;
1019 if (DECL_INITIAL (decl) == error_mark_node)
1020 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1021 else if (DECL_INITIAL (decl))
1022 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1026 resolve_unique_section (decl, reloc, flag_data_sections);
1027 if (IN_NAMED_SECTION (decl))
1028 return get_named_section (decl, NULL, reloc);
1030 if (ADDR_SPACE_GENERIC_P (as)
1031 && !DECL_THREAD_LOCAL_P (decl)
1032 && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1033 && bss_initializer_p (decl))
1035 if (!TREE_PUBLIC (decl))
1036 return lcomm_section;
1037 if (bss_noswitch_section)
1038 return bss_noswitch_section;
1041 return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
1044 /* Return the block into which object_block DECL should be placed. */
1046 static struct object_block *
1047 get_block_for_decl (tree decl)
1051 if (TREE_CODE (decl) == VAR_DECL)
1053 /* The object must be defined in this translation unit. */
1054 if (DECL_EXTERNAL (decl))
1057 /* There's no point using object blocks for something that is
1058 isolated by definition. */
1059 if (DECL_ONE_ONLY (decl))
1063 /* We can only calculate block offsets if the decl has a known
1065 if (DECL_SIZE_UNIT (decl) == NULL)
1067 if (!host_integerp (DECL_SIZE_UNIT (decl), 1))
1070 /* Find out which section should contain DECL. We cannot put it into
1071 an object block if it requires a standalone definition. */
1072 if (TREE_CODE (decl) == VAR_DECL)
1073 align_variable (decl, 0);
1074 sect = get_variable_section (decl, true);
1075 if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1078 return get_block_for_section (sect);
1081 /* Make sure block symbol SYMBOL is in block BLOCK. */
1084 change_symbol_block (rtx symbol, struct object_block *block)
1086 if (block != SYMBOL_REF_BLOCK (symbol))
1088 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1089 SYMBOL_REF_BLOCK (symbol) = block;
1093 /* Return true if it is possible to put DECL in an object_block. */
1096 use_blocks_for_decl_p (tree decl)
1098 /* Only data DECLs can be placed into object blocks. */
1099 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL)
1102 /* Detect decls created by dw2_force_const_mem. Such decls are
1103 special because DECL_INITIAL doesn't specify the decl's true value.
1104 dw2_output_indirect_constants will instead call assemble_variable
1105 with dont_output_data set to 1 and then print the contents itself. */
1106 if (DECL_INITIAL (decl) == decl)
1109 /* If this decl is an alias, then we don't want to emit a
1111 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl)))
1117 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1118 have static storage duration. In other words, it should not be an
1119 automatic variable, including PARM_DECLs.
1121 There is, however, one exception: this function handles variables
1122 explicitly placed in a particular register by the user.
1124 This is never called for PARM_DECL nodes. */
1127 make_decl_rtl (tree decl)
1129 const char *name = 0;
1133 /* Check that we are not being given an automatic variable. */
1134 gcc_assert (TREE_CODE (decl) != PARM_DECL
1135 && TREE_CODE (decl) != RESULT_DECL);
1137 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1138 gcc_assert (TREE_CODE (decl) != VAR_DECL
1139 || TREE_STATIC (decl)
1140 || TREE_PUBLIC (decl)
1141 || DECL_EXTERNAL (decl)
1142 || DECL_REGISTER (decl));
1144 /* And that we were not given a type or a label. */
1145 gcc_assert (TREE_CODE (decl) != TYPE_DECL
1146 && TREE_CODE (decl) != LABEL_DECL);
1148 /* For a duplicate declaration, we can be called twice on the
1149 same DECL node. Don't discard the RTL already made. */
1150 if (DECL_RTL_SET_P (decl))
1152 /* If the old RTL had the wrong mode, fix the mode. */
1153 x = DECL_RTL (decl);
1154 if (GET_MODE (x) != DECL_MODE (decl))
1155 SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1157 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1160 /* ??? Another way to do this would be to maintain a hashed
1161 table of such critters. Instead of adding stuff to a DECL
1162 to give certain attributes to it, we could use an external
1163 hash map from DECL to set of attributes. */
1165 /* Let the target reassign the RTL if it wants.
1166 This is necessary, for example, when one machine specific
1167 decl attribute overrides another. */
1168 targetm.encode_section_info (decl, DECL_RTL (decl), false);
1170 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1171 on the new decl information. */
1173 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1174 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1175 change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1177 /* Make this function static known to the mudflap runtime. */
1178 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1179 mudflap_enqueue_decl (decl);
1184 /* If this variable belongs to the global constant pool, retrieve the
1185 pre-computed RTL or recompute it in LTO mode. */
1186 if (TREE_CODE (decl) == VAR_DECL && DECL_IN_CONSTANT_POOL (decl))
1188 SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1192 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1194 if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1195 && DECL_REGISTER (decl))
1197 error ("register name not specified for %q+D", decl);
1199 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1201 const char *asmspec = name+1;
1202 enum machine_mode mode = DECL_MODE (decl);
1203 reg_number = decode_reg_name (asmspec);
1204 /* First detect errors in declaring global registers. */
1205 if (reg_number == -1)
1206 error ("register name not specified for %q+D", decl);
1207 else if (reg_number < 0)
1208 error ("invalid register name for %q+D", decl);
1209 else if (mode == BLKmode)
1210 error ("data type of %q+D isn%'t suitable for a register",
1212 else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1213 error ("the register specified for %q+D cannot be accessed"
1214 " by the current target", decl);
1215 else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1216 error ("the register specified for %q+D is not general enough"
1217 " to be used as a register variable", decl);
1218 else if (!HARD_REGNO_MODE_OK (reg_number, mode))
1219 error ("register specified for %q+D isn%'t suitable for data type",
1221 /* Now handle properly declared static register variables. */
1226 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1228 DECL_INITIAL (decl) = 0;
1229 error ("global register variable has initial value");
1231 if (TREE_THIS_VOLATILE (decl))
1232 warning (OPT_Wvolatile_register_var,
1233 "optimization may eliminate reads and/or "
1234 "writes to register variables");
1236 /* If the user specified one of the eliminables registers here,
1237 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1238 confused with that register and be eliminated. This usage is
1239 somewhat suspect... */
1241 SET_DECL_RTL (decl, gen_rtx_raw_REG (mode, reg_number));
1242 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1243 REG_USERVAR_P (DECL_RTL (decl)) = 1;
1245 if (TREE_STATIC (decl))
1247 /* Make this register global, so not usable for anything
1249 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1250 name = IDENTIFIER_POINTER (DECL_NAME (decl));
1251 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1253 nregs = hard_regno_nregs[reg_number][mode];
1255 globalize_reg (decl, reg_number + --nregs);
1258 /* As a register variable, it has no section. */
1262 /* Now handle ordinary static variables and functions (in memory).
1263 Also handle vars declared register invalidly. */
1264 else if (name[0] == '*')
1266 #ifdef REGISTER_PREFIX
1267 if (strlen (REGISTER_PREFIX) != 0)
1269 reg_number = decode_reg_name (name);
1270 if (reg_number >= 0 || reg_number == -3)
1271 error ("register name given for non-register variable %q+D", decl);
1276 /* Specifying a section attribute on a variable forces it into a
1277 non-.bss section, and thus it cannot be common. */
1278 /* FIXME: In general this code should not be necessary because
1279 visibility pass is doing the same work. But notice_global_symbol
1280 is called early and it needs to make DECL_RTL to get the name.
1281 we take care of recomputing the DECL_RTL after visibility is changed. */
1282 if (TREE_CODE (decl) == VAR_DECL
1283 && DECL_SECTION_NAME (decl) != NULL_TREE
1284 && DECL_INITIAL (decl) == NULL_TREE
1285 && DECL_COMMON (decl))
1286 DECL_COMMON (decl) = 0;
1288 /* Variables can't be both common and weak. */
1289 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
1290 DECL_COMMON (decl) = 0;
1292 if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1293 x = create_block_symbol (name, get_block_for_decl (decl), -1);
1296 enum machine_mode address_mode = Pmode;
1297 if (TREE_TYPE (decl) != error_mark_node)
1299 addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1300 address_mode = targetm.addr_space.address_mode (as);
1302 x = gen_rtx_SYMBOL_REF (address_mode, name);
1304 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1305 SET_SYMBOL_REF_DECL (x, decl);
1307 x = gen_rtx_MEM (DECL_MODE (decl), x);
1308 if (TREE_CODE (decl) != FUNCTION_DECL)
1309 set_mem_attributes (x, decl, 1);
1310 SET_DECL_RTL (decl, x);
1312 /* Optionally set flags or add text to the name to record information
1313 such as that it is a function name.
1314 If the name is changed, the macro ASM_OUTPUT_LABELREF
1315 will have to know how to strip this information. */
1316 targetm.encode_section_info (decl, DECL_RTL (decl), true);
1318 /* Make this function static known to the mudflap runtime. */
1319 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
1320 mudflap_enqueue_decl (decl);
1323 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1324 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1328 make_decl_rtl_for_debug (tree decl)
1330 unsigned int save_aliasing_flag, save_mudflap_flag;
1333 if (DECL_RTL_SET_P (decl))
1334 return DECL_RTL (decl);
1336 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1337 call new_alias_set. If running with -fcompare-debug, sometimes
1338 we do not want to create alias sets that will throw the alias
1339 numbers off in the comparison dumps. So... clearing
1340 flag_strict_aliasing will keep new_alias_set() from creating a
1341 new set. It is undesirable to register decl with mudflap
1342 in this case as well. */
1343 save_aliasing_flag = flag_strict_aliasing;
1344 flag_strict_aliasing = 0;
1345 save_mudflap_flag = flag_mudflap;
1348 rtl = DECL_RTL (decl);
1349 /* Reset DECL_RTL back, as various parts of the compiler expects
1350 DECL_RTL set meaning it is actually going to be output. */
1351 SET_DECL_RTL (decl, NULL);
1353 flag_strict_aliasing = save_aliasing_flag;
1354 flag_mudflap = save_mudflap_flag;
1359 /* Output a string of literal assembler code
1360 for an `asm' keyword used between functions. */
1363 assemble_asm (tree string)
1367 if (TREE_CODE (string) == ADDR_EXPR)
1368 string = TREE_OPERAND (string, 0);
1370 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1373 /* Record an element in the table of global destructors. SYMBOL is
1374 a SYMBOL_REF of the function to be called; PRIORITY is a number
1375 between 0 and MAX_INIT_PRIORITY. */
1378 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED,
1379 int priority ATTRIBUTE_UNUSED)
1381 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1382 /* Tell GNU LD that this is part of the static destructor set.
1383 This will work for any system that uses stabs, most usefully
1385 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1386 dbxout_stab_value_label (XSTR (symbol, 0));
1388 sorry ("global destructors not supported on this target");
1392 /* Write the address of the entity given by SYMBOL to SEC. */
1394 assemble_addr_to_section (rtx symbol, section *sec)
1396 switch_to_section (sec);
1397 assemble_align (POINTER_SIZE);
1398 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1401 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1402 not) section for PRIORITY. */
1404 get_cdtor_priority_section (int priority, bool constructor_p)
1408 /* ??? This only works reliably with the GNU linker. */
1409 sprintf (buf, "%s.%.5u",
1410 constructor_p ? ".ctors" : ".dtors",
1411 /* Invert the numbering so the linker puts us in the proper
1412 order; constructors are run from right to left, and the
1413 linker sorts in increasing order. */
1414 MAX_INIT_PRIORITY - priority);
1415 return get_section (buf, SECTION_WRITE, NULL);
1419 default_named_section_asm_out_destructor (rtx symbol, int priority)
1423 if (priority != DEFAULT_INIT_PRIORITY)
1424 sec = get_cdtor_priority_section (priority,
1425 /*constructor_p=*/false);
1427 sec = get_section (".dtors", SECTION_WRITE, NULL);
1429 assemble_addr_to_section (symbol, sec);
1432 #ifdef DTORS_SECTION_ASM_OP
1434 default_dtor_section_asm_out_destructor (rtx symbol,
1435 int priority ATTRIBUTE_UNUSED)
1437 assemble_addr_to_section (symbol, dtors_section);
1441 /* Likewise for global constructors. */
1444 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED,
1445 int priority ATTRIBUTE_UNUSED)
1447 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1448 /* Tell GNU LD that this is part of the static destructor set.
1449 This will work for any system that uses stabs, most usefully
1451 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1452 dbxout_stab_value_label (XSTR (symbol, 0));
1454 sorry ("global constructors not supported on this target");
1459 default_named_section_asm_out_constructor (rtx symbol, int priority)
1463 if (priority != DEFAULT_INIT_PRIORITY)
1464 sec = get_cdtor_priority_section (priority,
1465 /*constructor_p=*/true);
1467 sec = get_section (".ctors", SECTION_WRITE, NULL);
1469 assemble_addr_to_section (symbol, sec);
1472 #ifdef CTORS_SECTION_ASM_OP
1474 default_ctor_section_asm_out_constructor (rtx symbol,
1475 int priority ATTRIBUTE_UNUSED)
1477 assemble_addr_to_section (symbol, ctors_section);
1481 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1482 a nonzero value if the constant pool should be output before the
1483 start of the function, or a zero value if the pool should output
1484 after the end of the function. The default is to put it before the
1487 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1488 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1491 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1492 to be output to assembler.
1493 Set first_global_object_name and weak_global_object_name as appropriate. */
1496 notice_global_symbol (tree decl)
1498 const char **type = &first_global_object_name;
1500 if (first_global_object_name
1501 || !TREE_PUBLIC (decl)
1502 || DECL_EXTERNAL (decl)
1503 || !DECL_NAME (decl)
1504 || (TREE_CODE (decl) != FUNCTION_DECL
1505 && (TREE_CODE (decl) != VAR_DECL
1506 || (DECL_COMMON (decl)
1507 && (DECL_INITIAL (decl) == 0
1508 || DECL_INITIAL (decl) == error_mark_node))))
1509 || !MEM_P (DECL_RTL (decl)))
1512 /* We win when global object is found, but it is useful to know about weak
1513 symbol as well so we can produce nicer unique names. */
1514 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1515 type = &weak_global_object_name;
1521 rtx decl_rtl = DECL_RTL (decl);
1523 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1524 name = ggc_strdup (p);
1530 /* If not using flag_reorder_blocks_and_partition, decide early whether the
1531 current function goes into the cold section, so that targets can use
1532 current_function_section during RTL expansion. DECL describes the
1536 decide_function_section (tree decl)
1538 first_function_block_is_cold = false;
1540 if (flag_reorder_blocks_and_partition)
1541 /* We will decide in assemble_start_function. */
1544 if (DECL_SECTION_NAME (decl))
1546 struct cgraph_node *node = cgraph_get_node (current_function_decl);
1547 /* Calls to function_section rely on first_function_block_is_cold
1549 first_function_block_is_cold = (node
1551 == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1554 in_cold_section_p = first_function_block_is_cold;
1557 /* Output assembler code for the constant pool of a function and associated
1558 with defining the name of the function. DECL describes the function.
1559 NAME is the function's name. For the constant pool, we use the current
1560 constant pool data. */
1563 assemble_start_function (tree decl, const char *fnname)
1566 char tmp_label[100];
1567 bool hot_label_written = false;
1569 if (flag_reorder_blocks_and_partition)
1571 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
1572 crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
1573 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
1574 crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
1575 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
1576 crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
1577 ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
1578 crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
1583 crtl->subsections.hot_section_label = NULL;
1584 crtl->subsections.cold_section_label = NULL;
1585 crtl->subsections.hot_section_end_label = NULL;
1586 crtl->subsections.cold_section_end_label = NULL;
1589 /* The following code does not need preprocessing in the assembler. */
1593 if (CONSTANT_POOL_BEFORE_FUNCTION)
1594 output_constant_pool (fnname, decl);
1596 /* Make sure the not and cold text (code) sections are properly
1597 aligned. This is necessary here in the case where the function
1598 has both hot and cold sections, because we don't want to re-set
1599 the alignment when the section switch happens mid-function. */
1601 if (flag_reorder_blocks_and_partition)
1603 first_function_block_is_cold = false;
1605 switch_to_section (unlikely_text_section ());
1606 assemble_align (DECL_ALIGN (decl));
1607 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
1609 /* When the function starts with a cold section, we need to explicitly
1610 align the hot section and write out the hot section label.
1611 But if the current function is a thunk, we do not have a CFG. */
1613 && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION)
1615 switch_to_section (text_section);
1616 assemble_align (DECL_ALIGN (decl));
1617 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1618 hot_label_written = true;
1619 first_function_block_is_cold = true;
1621 in_cold_section_p = first_function_block_is_cold;
1625 /* Switch to the correct text section for the start of the function. */
1627 switch_to_section (function_section (decl));
1628 if (flag_reorder_blocks_and_partition
1629 && !hot_label_written)
1630 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
1632 /* Tell assembler to move to target machine's alignment for functions. */
1633 align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT);
1636 ASM_OUTPUT_ALIGN (asm_out_file, align);
1639 /* Handle a user-specified function alignment.
1640 Note that we still need to align to DECL_ALIGN, as above,
1641 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1642 if (! DECL_USER_ALIGN (decl)
1643 && align_functions_log > align
1644 && optimize_function_for_speed_p (cfun))
1646 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1647 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1648 align_functions_log, align_functions - 1);
1650 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1654 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1655 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1658 if (!DECL_IGNORED_P (decl))
1659 (*debug_hooks->begin_function) (decl);
1661 /* Make function name accessible from other files, if appropriate. */
1663 if (TREE_PUBLIC (decl))
1665 notice_global_symbol (decl);
1667 globalize_decl (decl);
1669 maybe_assemble_visibility (decl);
1672 if (DECL_PRESERVE_P (decl))
1673 targetm.asm_out.mark_decl_preserved (fnname);
1675 /* Do any machine/system dependent processing of the function name. */
1676 #ifdef ASM_DECLARE_FUNCTION_NAME
1677 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1679 /* Standard thing is just output label for the function. */
1680 ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
1681 #endif /* ASM_DECLARE_FUNCTION_NAME */
1683 if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
1684 saw_no_split_stack = true;
1687 /* Output assembler code associated with defining the size of the
1688 function. DECL describes the function. NAME is the function's name. */
1691 assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
1693 #ifdef ASM_DECLARE_FUNCTION_SIZE
1694 /* We could have switched section in the middle of the function. */
1695 if (flag_reorder_blocks_and_partition)
1696 switch_to_section (function_section (decl));
1697 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1699 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1701 output_constant_pool (fnname, decl);
1702 switch_to_section (function_section (decl)); /* need to switch back */
1704 /* Output labels for end of hot/cold text sections (to be used by
1706 if (flag_reorder_blocks_and_partition)
1708 section *save_text_section;
1710 save_text_section = in_section;
1711 switch_to_section (unlikely_text_section ());
1712 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
1713 if (first_function_block_is_cold)
1714 switch_to_section (text_section);
1716 switch_to_section (function_section (decl));
1717 ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
1718 switch_to_section (save_text_section);
1722 /* Assemble code to leave SIZE bytes of zeros. */
1725 assemble_zeros (unsigned HOST_WIDE_INT size)
1727 /* Do no output if -fsyntax-only. */
1728 if (flag_syntax_only)
1731 #ifdef ASM_NO_SKIP_IN_TEXT
1732 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1733 so we must output 0s explicitly in the text section. */
1734 if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
1736 unsigned HOST_WIDE_INT i;
1737 for (i = 0; i < size; i++)
1738 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1743 ASM_OUTPUT_SKIP (asm_out_file, size);
1746 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1749 assemble_align (int align)
1751 if (align > BITS_PER_UNIT)
1753 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1757 /* Assemble a string constant with the specified C string as contents. */
1760 assemble_string (const char *p, int size)
1765 /* If the string is very long, split it up. */
1769 int thissize = size - pos;
1770 if (thissize > maximum)
1773 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1781 /* A noswitch_section_callback for lcomm_section. */
1784 emit_local (tree decl ATTRIBUTE_UNUSED,
1785 const char *name ATTRIBUTE_UNUSED,
1786 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1787 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1789 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1790 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
1791 size, DECL_ALIGN (decl));
1793 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1794 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl));
1797 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1802 /* A noswitch_section_callback for bss_noswitch_section. */
1804 #if defined ASM_OUTPUT_ALIGNED_BSS
1806 emit_bss (tree decl ATTRIBUTE_UNUSED,
1807 const char *name ATTRIBUTE_UNUSED,
1808 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1809 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1811 #if defined ASM_OUTPUT_ALIGNED_BSS
1812 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl));
1818 /* A noswitch_section_callback for comm_section. */
1821 emit_common (tree decl ATTRIBUTE_UNUSED,
1822 const char *name ATTRIBUTE_UNUSED,
1823 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1824 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1826 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1827 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
1828 size, DECL_ALIGN (decl));
1830 #elif defined ASM_OUTPUT_ALIGNED_COMMON
1831 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl));
1834 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1839 /* A noswitch_section_callback for tls_comm_section. */
1842 emit_tls_common (tree decl ATTRIBUTE_UNUSED,
1843 const char *name ATTRIBUTE_UNUSED,
1844 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1845 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1847 #ifdef ASM_OUTPUT_TLS_COMMON
1848 ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
1851 sorry ("thread-local COMMON data not implemented");
1856 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
1857 NAME is the name of DECL's SYMBOL_REF. */
1860 assemble_noswitch_variable (tree decl, const char *name, section *sect)
1862 unsigned HOST_WIDE_INT size, rounded;
1864 size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1867 /* Don't allocate zero bytes of common,
1868 since that means "undefined external" in the linker. */
1872 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1873 so that each uninitialized object starts on such a boundary. */
1874 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1875 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1876 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1878 if (!sect->noswitch.callback (decl, name, size, rounded)
1879 && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1880 warning (0, "requested alignment for %q+D is greater than "
1881 "implemented alignment of %wu", decl, rounded);
1884 /* A subroutine of assemble_variable. Output the label and contents of
1885 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
1886 is as for assemble_variable. */
1889 assemble_variable_contents (tree decl, const char *name,
1890 bool dont_output_data)
1892 /* Do any machine/system dependent processing of the object. */
1893 #ifdef ASM_DECLARE_OBJECT_NAME
1894 last_assemble_variable_decl = decl;
1895 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1897 /* Standard thing is just output label for the object. */
1898 ASM_OUTPUT_LABEL (asm_out_file, name);
1899 #endif /* ASM_DECLARE_OBJECT_NAME */
1901 if (!dont_output_data)
1903 if (DECL_INITIAL (decl)
1904 && DECL_INITIAL (decl) != error_mark_node
1905 && !initializer_zerop (DECL_INITIAL (decl)))
1906 /* Output the actual data. */
1907 output_constant (DECL_INITIAL (decl),
1908 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1911 /* Leave space for it. */
1912 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1916 /* Assemble everything that is needed for a variable or function declaration.
1917 Not used for automatic variables, and not used for function definitions.
1918 Should not be called for variables of incomplete structure type.
1920 TOP_LEVEL is nonzero if this variable has file scope.
1921 AT_END is nonzero if this is the special handling, at end of compilation,
1922 to define things that have had only tentative definitions.
1923 DONT_OUTPUT_DATA if nonzero means don't actually output the
1924 initial value (that will be done by the caller). */
1927 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1928 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1931 rtx decl_rtl, symbol;
1934 /* This function is supposed to handle VARIABLES. Ensure we have one. */
1935 gcc_assert (TREE_CODE (decl) == VAR_DECL);
1937 /* Emulated TLS had better not get this far. */
1938 gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
1940 last_assemble_variable_decl = 0;
1942 /* Normally no need to say anything here for external references,
1943 since assemble_external is called by the language-specific code
1944 when a declaration is first seen. */
1946 if (DECL_EXTERNAL (decl))
1949 /* Do nothing for global register variables. */
1950 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1952 TREE_ASM_WRITTEN (decl) = 1;
1956 /* If type was incomplete when the variable was declared,
1957 see if it is complete now. */
1959 if (DECL_SIZE (decl) == 0)
1960 layout_decl (decl, 0);
1962 /* Still incomplete => don't allocate it; treat the tentative defn
1963 (which is what it must have been) as an `extern' reference. */
1965 if (!dont_output_data && DECL_SIZE (decl) == 0)
1967 error ("storage size of %q+D isn%'t known", decl);
1968 TREE_ASM_WRITTEN (decl) = 1;
1972 /* The first declaration of a variable that comes through this function
1973 decides whether it is global (in C, has external linkage)
1974 or local (in C, has internal linkage). So do nothing more
1975 if this function has already run. */
1977 if (TREE_ASM_WRITTEN (decl))
1980 /* Make sure targetm.encode_section_info is invoked before we set
1982 decl_rtl = DECL_RTL (decl);
1984 TREE_ASM_WRITTEN (decl) = 1;
1986 /* Do no output if -fsyntax-only. */
1987 if (flag_syntax_only)
1990 if (! dont_output_data
1991 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1993 error ("size of variable %q+D is too large", decl);
1997 gcc_assert (MEM_P (decl_rtl));
1998 gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
1999 symbol = XEXP (decl_rtl, 0);
2001 /* If this symbol belongs to the tree constant pool, output the constant
2002 if it hasn't already been written. */
2003 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2005 tree decl = SYMBOL_REF_DECL (symbol);
2006 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2007 output_constant_def_contents (symbol);
2013 name = XSTR (symbol, 0);
2014 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2015 notice_global_symbol (decl);
2017 /* Compute the alignment of this data. */
2019 align_variable (decl, dont_output_data);
2020 set_mem_align (decl_rtl, DECL_ALIGN (decl));
2022 if (TREE_PUBLIC (decl))
2023 maybe_assemble_visibility (decl);
2025 if (DECL_PRESERVE_P (decl))
2026 targetm.asm_out.mark_decl_preserved (name);
2028 /* First make the assembler name(s) global if appropriate. */
2029 sect = get_variable_section (decl, false);
2030 if (TREE_PUBLIC (decl)
2031 && (sect->common.flags & SECTION_COMMON) == 0)
2032 globalize_decl (decl);
2034 /* Output any data that we will need to use the address of. */
2035 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2036 output_addressed_constants (DECL_INITIAL (decl));
2038 /* dbxout.c needs to know this. */
2039 if (sect && (sect->common.flags & SECTION_CODE) != 0)
2040 DECL_IN_TEXT_SECTION (decl) = 1;
2042 /* If the decl is part of an object_block, make sure that the decl
2043 has been positioned within its block, but do not write out its
2044 definition yet. output_object_blocks will do that later. */
2045 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2047 gcc_assert (!dont_output_data);
2048 place_block_symbol (symbol);
2050 else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2051 assemble_noswitch_variable (decl, name, sect);
2054 switch_to_section (sect);
2055 if (DECL_ALIGN (decl) > BITS_PER_UNIT)
2056 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
2057 assemble_variable_contents (decl, name, dont_output_data);
2061 /* Return 1 if type TYPE contains any pointers. */
2064 contains_pointers_p (tree type)
2066 switch (TREE_CODE (type))
2069 case REFERENCE_TYPE:
2070 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2071 so I'll play safe and return 1. */
2077 case QUAL_UNION_TYPE:
2080 /* For a type that has fields, see if the fields have pointers. */
2081 for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2082 if (TREE_CODE (fields) == FIELD_DECL
2083 && contains_pointers_p (TREE_TYPE (fields)))
2089 /* An array type contains pointers if its element type does. */
2090 return contains_pointers_p (TREE_TYPE (type));
2097 /* We delay assemble_external processing until
2098 the compilation unit is finalized. This is the best we can do for
2099 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2100 it all the way to final. See PR 17982 for further discussion. */
2101 static GTY(()) tree pending_assemble_externals;
2103 /* FIXME: Trunk is at GCC 4.8 now and the above problem still hasn't been
2104 addressed properly. This caused PR 52640 due to O(external_decls**2)
2105 lookups in the pending_assemble_externals TREE_LIST in assemble_external.
2106 Paper over with this pointer set, which we use to see if we have already
2107 added a decl to pending_assemble_externals without first traversing
2108 the entire pending_assemble_externals list. See assemble_external(). */
2109 static struct pointer_set_t *pending_assemble_externals_set;
2111 #ifdef ASM_OUTPUT_EXTERNAL
2112 /* True if DECL is a function decl for which no out-of-line copy exists.
2113 It is assumed that DECL's assembler name has been set. */
2116 incorporeal_function_p (tree decl)
2118 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
2122 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2123 && (DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA
2124 || DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA_WITH_ALIGN))
2127 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2128 /* Atomic or sync builtins which have survived this far will be
2129 resolved externally and therefore are not incorporeal. */
2130 if (strncmp (name, "__builtin_", 10) == 0)
2136 /* Actually do the tests to determine if this is necessary, and invoke
2137 ASM_OUTPUT_EXTERNAL. */
2139 assemble_external_real (tree decl)
2141 rtx rtl = DECL_RTL (decl);
2143 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2144 && !SYMBOL_REF_USED (XEXP (rtl, 0))
2145 && !incorporeal_function_p (decl))
2147 /* Some systems do require some output. */
2148 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2149 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2155 process_pending_assemble_externals (void)
2157 #ifdef ASM_OUTPUT_EXTERNAL
2159 for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2160 assemble_external_real (TREE_VALUE (list));
2162 pending_assemble_externals = 0;
2163 pointer_set_destroy (pending_assemble_externals_set);
2167 /* This TREE_LIST contains any weak symbol declarations waiting
2169 static GTY(()) tree weak_decls;
2171 /* Output something to declare an external symbol to the assembler,
2172 and qualifiers such as weakness. (Most assemblers don't need
2173 extern declaration, so we normally output nothing.) Do nothing if
2174 DECL is not external. */
2177 assemble_external (tree decl ATTRIBUTE_UNUSED)
2179 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2180 main body of this code is only rarely exercised. To provide some
2181 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2182 open. If it's not, we should not be calling this function. */
2183 gcc_assert (asm_out_file);
2185 if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2188 /* We want to output annotation for weak and external symbols at
2189 very last to check if they are references or not. */
2191 if (TARGET_SUPPORTS_WEAK
2193 /* TREE_STATIC is a weird and abused creature which is not
2194 generally the right test for whether an entity has been
2195 locally emitted, inlined or otherwise not-really-extern, but
2196 for declarations that can be weak, it happens to be
2198 && !TREE_STATIC (decl)
2199 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2200 && value_member (decl, weak_decls) == NULL_TREE)
2201 weak_decls = tree_cons (NULL, decl, weak_decls);
2203 #ifdef ASM_OUTPUT_EXTERNAL
2204 if (! pointer_set_insert (pending_assemble_externals_set, decl))
2205 pending_assemble_externals = tree_cons (NULL, decl,
2206 pending_assemble_externals);
2210 /* Similar, for calling a library function FUN. */
2213 assemble_external_libcall (rtx fun)
2215 /* Declare library function name external when first used, if nec. */
2216 if (! SYMBOL_REF_USED (fun))
2218 SYMBOL_REF_USED (fun) = 1;
2219 targetm.asm_out.external_libcall (fun);
2223 /* Assemble a label named NAME. */
2226 assemble_label (FILE *file, const char *name)
2228 ASM_OUTPUT_LABEL (file, name);
2231 /* Set the symbol_referenced flag for ID. */
2233 mark_referenced (tree id)
2235 TREE_SYMBOL_REFERENCED (id) = 1;
2238 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2240 mark_decl_referenced (tree decl)
2242 if (TREE_CODE (decl) == FUNCTION_DECL)
2244 /* Extern inline functions don't become needed when referenced.
2245 If we know a method will be emitted in other TU and no new
2246 functions can be marked reachable, just use the external
2248 struct cgraph_node *node = cgraph_get_create_node (decl);
2249 if (!DECL_EXTERNAL (decl)
2250 && !node->local.finalized)
2251 cgraph_mark_needed_node (node);
2253 else if (TREE_CODE (decl) == VAR_DECL)
2255 struct varpool_node *node = varpool_node (decl);
2256 varpool_mark_needed_node (node);
2257 /* C++ frontend use mark_decl_references to force COMDAT variables
2258 to be output that might appear dead otherwise. */
2259 node->force_output = true;
2261 /* else do nothing - we can get various sorts of CST nodes here,
2262 which do not need to be marked. */
2266 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2267 until we find an identifier that is not itself a transparent alias.
2268 Modify the alias passed to it by reference (and all aliases on the
2269 way to the ultimate target), such that they do not have to be
2270 followed again, and return the ultimate target of the alias
2274 ultimate_transparent_alias_target (tree *alias)
2276 tree target = *alias;
2278 if (IDENTIFIER_TRANSPARENT_ALIAS (target))
2280 gcc_assert (TREE_CHAIN (target));
2281 target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
2282 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
2283 && ! TREE_CHAIN (target));
2290 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2291 starts with a *, the rest of NAME is output verbatim. Otherwise
2292 NAME is transformed in a target-specific way (usually by the
2293 addition of an underscore). */
2296 assemble_name_raw (FILE *file, const char *name)
2299 fputs (&name[1], file);
2301 ASM_OUTPUT_LABELREF (file, name);
2304 /* Like assemble_name_raw, but should be used when NAME might refer to
2305 an entity that is also represented as a tree (like a function or
2306 variable). If NAME does refer to such an entity, that entity will
2307 be marked as referenced. */
2310 assemble_name (FILE *file, const char *name)
2312 const char *real_name;
2315 real_name = targetm.strip_name_encoding (name);
2317 id = maybe_get_identifier (real_name);
2322 mark_referenced (id);
2323 ultimate_transparent_alias_target (&id);
2325 name = IDENTIFIER_POINTER (id);
2326 gcc_assert (! TREE_CHAIN (id));
2329 assemble_name_raw (file, name);
2332 /* Allocate SIZE bytes writable static space with a gensym name
2333 and return an RTX to refer to its address. */
2336 assemble_static_space (unsigned HOST_WIDE_INT size)
2339 const char *namestring;
2342 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2344 namestring = ggc_strdup (name);
2346 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2347 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2349 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2350 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2353 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2354 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2357 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2358 so that each uninitialized object starts on such a boundary. */
2359 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2360 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2361 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2362 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2363 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2364 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2371 /* Assemble the static constant template for function entry trampolines.
2372 This is done at most once per compilation.
2373 Returns an RTX for the address of the template. */
2375 static GTY(()) rtx initial_trampoline;
2378 assemble_trampoline_template (void)
2385 gcc_assert (targetm.asm_out.trampoline_template != NULL);
2387 if (initial_trampoline)
2388 return initial_trampoline;
2390 /* By default, put trampoline templates in read-only data section. */
2392 #ifdef TRAMPOLINE_SECTION
2393 switch_to_section (TRAMPOLINE_SECTION);
2395 switch_to_section (readonly_data_section);
2398 /* Write the assembler code to define one. */
2399 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2401 ASM_OUTPUT_ALIGN (asm_out_file, align);
2403 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2404 targetm.asm_out.trampoline_template (asm_out_file);
2406 /* Record the rtl to refer to it. */
2407 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
2408 name = ggc_strdup (label);
2409 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
2410 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2412 initial_trampoline = gen_const_mem (BLKmode, symbol);
2413 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
2414 set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
2416 return initial_trampoline;
2419 /* A and B are either alignments or offsets. Return the minimum alignment
2420 that may be assumed after adding the two together. */
2422 static inline unsigned
2423 min_align (unsigned int a, unsigned int b)
2425 return (a | b) & -(a | b);
2428 /* Return the assembler directive for creating a given kind of integer
2429 object. SIZE is the number of bytes in the object and ALIGNED_P
2430 indicates whether it is known to be aligned. Return NULL if the
2431 assembly dialect has no such directive.
2433 The returned string should be printed at the start of a new line and
2434 be followed immediately by the object's initial value. */
2437 integer_asm_op (int size, int aligned_p)
2439 struct asm_int_op *ops;
2442 ops = &targetm.asm_out.aligned_op;
2444 ops = &targetm.asm_out.unaligned_op;
2449 return targetm.asm_out.byte_op;
2463 /* Use directive OP to assemble an integer object X. Print OP at the
2464 start of the line, followed immediately by the value of X. */
2467 assemble_integer_with_op (const char *op, rtx x)
2469 fputs (op, asm_out_file);
2470 output_addr_const (asm_out_file, x);
2471 fputc ('\n', asm_out_file);
2474 /* The default implementation of the asm_out.integer target hook. */
2477 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2478 unsigned int size ATTRIBUTE_UNUSED,
2479 int aligned_p ATTRIBUTE_UNUSED)
2481 const char *op = integer_asm_op (size, aligned_p);
2482 /* Avoid GAS bugs for large values. Specifically negative values whose
2483 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2484 if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT)
2486 return op && (assemble_integer_with_op (op, x), true);
2489 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2490 the alignment of the integer in bits. Return 1 if we were able to output
2491 the constant, otherwise 0. We must be able to output the constant,
2492 if FORCE is nonzero. */
2495 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2499 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2501 /* See if the target hook can handle this kind of object. */
2502 if (targetm.asm_out.integer (x, size, aligned_p))
2505 /* If the object is a multi-byte one, try splitting it up. Split
2506 it into words it if is multi-word, otherwise split it into bytes. */
2509 enum machine_mode omode, imode;
2510 unsigned int subalign;
2511 unsigned int subsize, i;
2512 enum mode_class mclass;
2514 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2515 subalign = MIN (align, subsize * BITS_PER_UNIT);
2516 if (GET_CODE (x) == CONST_FIXED)
2517 mclass = GET_MODE_CLASS (GET_MODE (x));
2521 omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0);
2522 imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0);
2524 for (i = 0; i < size; i += subsize)
2526 rtx partial = simplify_subreg (omode, x, imode, i);
2527 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2533 /* If we've printed some of it, but not all of it, there's no going
2538 gcc_assert (!force);
2544 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2546 long data[4] = {0, 0, 0, 0};
2548 int bitsize, nelts, nunits, units_per;
2550 /* This is hairy. We have a quantity of known size. real_to_target
2551 will put it into an array of *host* longs, 32 bits per element
2552 (even if long is more than 32 bits). We need to determine the
2553 number of array elements that are occupied (nelts) and the number
2554 of *target* min-addressable units that will be occupied in the
2555 object file (nunits). We cannot assume that 32 divides the
2556 mode's bitsize (size * BITS_PER_UNIT) evenly.
2558 size * BITS_PER_UNIT is used here to make sure that padding bits
2559 (which might appear at either end of the value; real_to_target
2560 will include the padding bits in its output array) are included. */
2562 nunits = GET_MODE_SIZE (mode);
2563 bitsize = nunits * BITS_PER_UNIT;
2564 nelts = CEIL (bitsize, 32);
2565 units_per = 32 / BITS_PER_UNIT;
2567 real_to_target (data, &d, mode);
2569 /* Put out the first word with the specified alignment. */
2570 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2571 nunits -= units_per;
2573 /* Subsequent words need only 32-bit alignment. */
2574 align = min_align (align, 32);
2576 for (i = 1; i < nelts; i++)
2578 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2579 nunits -= units_per;
2583 /* Given an expression EXP with a constant value,
2584 reduce it to the sum of an assembler symbol and an integer.
2585 Store them both in the structure *VALUE.
2586 EXP must be reducible. */
2590 HOST_WIDE_INT offset;
2594 decode_addr_const (tree exp, struct addr_const *value)
2596 tree target = TREE_OPERAND (exp, 0);
2602 if (TREE_CODE (target) == COMPONENT_REF
2603 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2605 offset += int_byte_position (TREE_OPERAND (target, 1));
2606 target = TREE_OPERAND (target, 0);
2608 else if (TREE_CODE (target) == ARRAY_REF
2609 || TREE_CODE (target) == ARRAY_RANGE_REF)
2611 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2612 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2613 target = TREE_OPERAND (target, 0);
2615 else if (TREE_CODE (target) == MEM_REF
2616 && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
2618 offset += mem_ref_offset (target).low;
2619 target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
2621 else if (TREE_CODE (target) == INDIRECT_REF
2622 && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
2623 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
2625 target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
2630 switch (TREE_CODE (target))
2634 x = DECL_RTL (target);
2638 x = gen_rtx_MEM (FUNCTION_MODE,
2639 gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
2648 x = output_constant_def (target, 1);
2655 gcc_assert (MEM_P (x));
2659 value->offset = offset;
2663 static GTY((param_is (struct constant_descriptor_tree)))
2664 htab_t const_desc_htab;
2666 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2668 /* Constant pool accessor function. */
2671 constant_pool_htab (void)
2673 return const_desc_htab;
2676 /* Compute a hash code for a constant expression. */
2679 const_desc_hash (const void *ptr)
2681 return ((const struct constant_descriptor_tree *)ptr)->hash;
2685 const_hash_1 (const tree exp)
2690 enum tree_code code = TREE_CODE (exp);
2692 /* Either set P and LEN to the address and len of something to hash and
2693 exit the switch or return a value. */
2698 p = (char *) &TREE_INT_CST (exp);
2699 len = sizeof TREE_INT_CST (exp);
2703 return real_hash (TREE_REAL_CST_PTR (exp));
2706 return fixed_hash (TREE_FIXED_CST_PTR (exp));
2709 p = TREE_STRING_POINTER (exp);
2710 len = TREE_STRING_LENGTH (exp);
2714 return (const_hash_1 (TREE_REALPART (exp)) * 5
2715 + const_hash_1 (TREE_IMAGPART (exp)));
2721 hi = 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp));
2723 for (link = TREE_VECTOR_CST_ELTS (exp); link; link = TREE_CHAIN (link))
2724 hi = hi * 563 + const_hash_1 (TREE_VALUE (link));
2731 unsigned HOST_WIDE_INT idx;
2734 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2736 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
2738 hi = hi * 603 + const_hash_1 (value);
2746 struct addr_const value;
2748 decode_addr_const (exp, &value);
2749 switch (GET_CODE (value.base))
2752 /* Don't hash the address of the SYMBOL_REF;
2753 only use the offset and the symbol name. */
2755 p = XSTR (value.base, 0);
2756 for (i = 0; p[i] != 0; i++)
2757 hi = ((hi * 613) + (unsigned) (p[i]));
2761 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2771 case POINTER_PLUS_EXPR:
2773 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2774 + const_hash_1 (TREE_OPERAND (exp, 1)));
2777 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2780 /* A language specific constant. Just hash the code. */
2784 /* Compute hashing function. */
2786 for (i = 0; i < len; i++)
2787 hi = ((hi * 613) + (unsigned) (p[i]));
2792 /* Wrapper of compare_constant, for the htab interface. */
2794 const_desc_eq (const void *p1, const void *p2)
2796 const struct constant_descriptor_tree *const c1
2797 = (const struct constant_descriptor_tree *) p1;
2798 const struct constant_descriptor_tree *const c2
2799 = (const struct constant_descriptor_tree *) p2;
2800 if (c1->hash != c2->hash)
2802 return compare_constant (c1->value, c2->value);
2805 /* Compare t1 and t2, and return 1 only if they are known to result in
2806 the same bit pattern on output. */
2809 compare_constant (const tree t1, const tree t2)
2811 enum tree_code typecode;
2813 if (t1 == NULL_TREE)
2814 return t2 == NULL_TREE;
2815 if (t2 == NULL_TREE)
2818 if (TREE_CODE (t1) != TREE_CODE (t2))
2821 switch (TREE_CODE (t1))
2824 /* Integer constants are the same only if the same width of type. */
2825 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2827 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2829 return tree_int_cst_equal (t1, t2);
2832 /* Real constants are the same only if the same width of type. */
2833 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2836 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2839 /* Fixed constants are the same only if the same width of type. */
2840 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2843 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
2846 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2849 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2850 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2851 TREE_STRING_LENGTH (t1)));
2854 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2855 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2861 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1))
2862 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2)))
2865 link2 = TREE_VECTOR_CST_ELTS (t2);
2866 for (link1 = TREE_VECTOR_CST_ELTS (t1);
2868 link1 = TREE_CHAIN (link1))
2870 if (!compare_constant (TREE_VALUE (link1), TREE_VALUE (link2)))
2872 link2 = TREE_CHAIN (link2);
2880 VEC(constructor_elt, gc) *v1, *v2;
2881 unsigned HOST_WIDE_INT idx;
2883 typecode = TREE_CODE (TREE_TYPE (t1));
2884 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2887 if (typecode == ARRAY_TYPE)
2889 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2890 /* For arrays, check that the sizes all match. */
2891 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2893 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2898 /* For record and union constructors, require exact type
2900 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2904 v1 = CONSTRUCTOR_ELTS (t1);
2905 v2 = CONSTRUCTOR_ELTS (t2);
2906 if (VEC_length (constructor_elt, v1)
2907 != VEC_length (constructor_elt, v2))
2910 for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx)
2912 constructor_elt *c1 = VEC_index (constructor_elt, v1, idx);
2913 constructor_elt *c2 = VEC_index (constructor_elt, v2, idx);
2915 /* Check that each value is the same... */
2916 if (!compare_constant (c1->value, c2->value))
2918 /* ... and that they apply to the same fields! */
2919 if (typecode == ARRAY_TYPE)
2921 if (!compare_constant (c1->index, c2->index))
2926 if (c1->index != c2->index)
2937 struct addr_const value1, value2;
2941 decode_addr_const (t1, &value1);
2942 decode_addr_const (t2, &value2);
2944 if (value1.offset != value2.offset)
2947 code = GET_CODE (value1.base);
2948 if (code != GET_CODE (value2.base))
2954 ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2958 ret = (CODE_LABEL_NUMBER (XEXP (value1.base, 0))
2959 == CODE_LABEL_NUMBER (XEXP (value2.base, 0)));
2969 case POINTER_PLUS_EXPR:
2972 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2973 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2976 case VIEW_CONVERT_EXPR:
2977 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2986 /* Make a copy of the whole tree structure for a constant. This
2987 handles the same types of nodes that compare_constant handles. */
2990 copy_constant (tree exp)
2992 switch (TREE_CODE (exp))
2995 /* For ADDR_EXPR, we do not want to copy the decl whose address
2996 is requested. We do want to copy constants though. */
2997 if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
2998 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2999 copy_constant (TREE_OPERAND (exp, 0)));
3001 return copy_node (exp);
3007 return copy_node (exp);
3010 return build_complex (TREE_TYPE (exp),
3011 copy_constant (TREE_REALPART (exp)),
3012 copy_constant (TREE_IMAGPART (exp)));
3015 case POINTER_PLUS_EXPR:
3017 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
3018 copy_constant (TREE_OPERAND (exp, 0)),
3019 copy_constant (TREE_OPERAND (exp, 1)));
3022 case VIEW_CONVERT_EXPR:
3023 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3024 copy_constant (TREE_OPERAND (exp, 0)));
3027 return build_vector (TREE_TYPE (exp),
3028 copy_list (TREE_VECTOR_CST_ELTS (exp)));
3032 tree copy = copy_node (exp);
3033 VEC(constructor_elt, gc) *v;
3034 unsigned HOST_WIDE_INT idx;
3035 tree purpose, value;
3037 v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt,
3038 CONSTRUCTOR_ELTS (exp)));
3039 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value)
3041 constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL);
3042 ce->index = purpose;
3043 ce->value = copy_constant (value);
3045 CONSTRUCTOR_ELTS (copy) = v;
3054 /* Return the section into which constant EXP should be placed. */
3057 get_constant_section (tree exp, unsigned int align)
3059 return targetm.asm_out.select_section (exp,
3060 compute_reloc_for_constant (exp),
3064 /* Return the size of constant EXP in bytes. */
3066 static HOST_WIDE_INT
3067 get_constant_size (tree exp)
3071 size = int_size_in_bytes (TREE_TYPE (exp));
3072 if (TREE_CODE (exp) == STRING_CST)
3073 size = MAX (TREE_STRING_LENGTH (exp), size);
3077 /* Subroutine of output_constant_def:
3078 No constant equal to EXP is known to have been output.
3079 Make a constant descriptor to enter EXP in the hash table.
3080 Assign the label number and construct RTL to refer to the
3081 constant's location in memory.
3082 Caller is responsible for updating the hash table. */
3084 static struct constant_descriptor_tree *
3085 build_constant_desc (tree exp)
3087 struct constant_descriptor_tree *desc;
3093 desc = ggc_alloc_constant_descriptor_tree ();
3094 desc->value = copy_constant (exp);
3096 /* Propagate marked-ness to copied constant. */
3097 if (flag_mudflap && mf_marked_p (exp))
3098 mf_mark (desc->value);
3100 /* Create a string containing the label name, in LABEL. */
3101 labelno = const_labelno++;
3102 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3104 /* Construct the VAR_DECL associated with the constant. */
3105 decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3107 DECL_ARTIFICIAL (decl) = 1;
3108 DECL_IGNORED_P (decl) = 1;
3109 TREE_READONLY (decl) = 1;
3110 TREE_STATIC (decl) = 1;
3111 TREE_ADDRESSABLE (decl) = 1;
3112 /* We don't set the RTL yet as this would cause varpool to assume that the
3113 variable is referenced. Moreover, it would just be dropped in LTO mode.
3114 Instead we set the flag that will be recognized in make_decl_rtl. */
3115 DECL_IN_CONSTANT_POOL (decl) = 1;
3116 DECL_INITIAL (decl) = desc->value;
3117 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3118 architectures so use DATA_ALIGNMENT as well, except for strings. */
3119 if (TREE_CODE (exp) == STRING_CST)
3121 #ifdef CONSTANT_ALIGNMENT
3122 DECL_ALIGN (decl) = CONSTANT_ALIGNMENT (exp, DECL_ALIGN (decl));
3126 align_variable (decl, 0);
3128 /* Now construct the SYMBOL_REF and the MEM. */
3129 if (use_object_blocks_p ())
3131 section *sect = get_constant_section (exp, DECL_ALIGN (decl));
3132 symbol = create_block_symbol (ggc_strdup (label),
3133 get_block_for_section (sect), -1);
3136 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3137 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3138 SET_SYMBOL_REF_DECL (symbol, decl);
3139 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3141 rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3142 set_mem_attributes (rtl, exp, 1);
3143 set_mem_alias_set (rtl, 0);
3144 set_mem_alias_set (rtl, const_alias_set);
3146 /* We cannot share RTX'es in pool entries.
3147 Mark this piece of RTL as required for unsharing. */
3148 RTX_FLAG (rtl, used) = 1;
3150 /* Set flags or add text to the name to record information, such as
3151 that it is a local symbol. If the name is changed, the macro
3152 ASM_OUTPUT_LABELREF will have to know how to strip this
3153 information. This call might invalidate our local variable
3154 SYMBOL; we can't use it afterward. */
3155 targetm.encode_section_info (exp, rtl, true);
3162 /* Return an rtx representing a reference to constant data in memory
3163 for the constant expression EXP.
3165 If assembler code for such a constant has already been output,
3166 return an rtx to refer to it.
3167 Otherwise, output such a constant in memory
3168 and generate an rtx for it.
3170 If DEFER is nonzero, this constant can be deferred and output only
3171 if referenced in the function after all optimizations.
3173 `const_desc_table' records which constants already have label strings. */
3176 output_constant_def (tree exp, int defer)
3178 struct constant_descriptor_tree *desc;
3179 struct constant_descriptor_tree key;
3182 /* Look up EXP in the table of constant descriptors. If we didn't find
3183 it, create a new one. */
3185 key.hash = const_hash_1 (exp);
3186 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3188 desc = (struct constant_descriptor_tree *) *loc;
3191 desc = build_constant_desc (exp);
3192 desc->hash = key.hash;
3196 maybe_output_constant_def_contents (desc, defer);
3200 /* Subroutine of output_constant_def: Decide whether or not we need to
3201 output the constant DESC now, and if so, do it. */
3203 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3206 rtx symbol = XEXP (desc->rtl, 0);
3207 tree exp = desc->value;
3209 if (flag_syntax_only)
3212 if (TREE_ASM_WRITTEN (exp))
3213 /* Already output; don't do it again. */
3216 /* We can always defer constants as long as the context allows
3220 /* Increment n_deferred_constants if it exists. It needs to be at
3221 least as large as the number of constants actually referred to
3222 by the function. If it's too small we'll stop looking too early
3223 and fail to emit constants; if it's too large we'll only look
3224 through the entire function when we could have stopped earlier. */
3226 n_deferred_constants++;
3230 output_constant_def_contents (symbol);
3233 /* Subroutine of output_constant_def_contents. Output the definition
3234 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3235 constant's alignment in bits. */
3238 assemble_constant_contents (tree exp, const char *label, unsigned int align)
3242 size = get_constant_size (exp);
3244 /* Do any machine/system dependent processing of the constant. */
3245 targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3247 /* Output the value of EXP. */
3248 output_constant (exp, size, align);
3251 /* We must output the constant data referred to by SYMBOL; do so. */
3254 output_constant_def_contents (rtx symbol)
3256 tree decl = SYMBOL_REF_DECL (symbol);
3257 tree exp = DECL_INITIAL (decl);
3260 /* Make sure any other constants whose addresses appear in EXP
3261 are assigned label numbers. */
3262 output_addressed_constants (exp);
3264 /* We are no longer deferring this constant. */
3265 TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3267 /* If the constant is part of an object block, make sure that the
3268 decl has been positioned within its block, but do not write out
3269 its definition yet. output_object_blocks will do that later. */
3270 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3271 place_block_symbol (symbol);
3274 align = DECL_ALIGN (decl);
3275 switch_to_section (get_constant_section (exp, align));
3276 if (align > BITS_PER_UNIT)
3277 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3278 assemble_constant_contents (exp, XSTR (symbol, 0), align);
3281 mudflap_enqueue_constant (exp);
3284 /* Look up EXP in the table of constant descriptors. Return the rtl
3285 if it has been emitted, else null. */
3288 lookup_constant_def (tree exp)
3290 struct constant_descriptor_tree *desc;
3291 struct constant_descriptor_tree key;
3294 key.hash = const_hash_1 (exp);
3295 desc = (struct constant_descriptor_tree *)
3296 htab_find_with_hash (const_desc_htab, &key, key.hash);
3298 return (desc ? desc->rtl : NULL_RTX);
3301 /* Return a tree representing a reference to constant data in memory
3302 for the constant expression EXP.
3304 This is the counterpart of output_constant_def at the Tree level. */
3307 tree_output_constant_def (tree exp)
3309 struct constant_descriptor_tree *desc, key;
3313 /* Look up EXP in the table of constant descriptors. If we didn't find
3314 it, create a new one. */
3316 key.hash = const_hash_1 (exp);
3317 loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT);
3319 desc = (struct constant_descriptor_tree *) *loc;
3322 desc = build_constant_desc (exp);
3323 desc->hash = key.hash;
3327 decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3328 varpool_finalize_decl (decl);
3332 /* Used in the hash tables to avoid outputting the same constant
3333 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3334 are output once per function, not once per file. */
3335 /* ??? Only a few targets need per-function constant pools. Most
3336 can use one per-file pool. Should add a targetm bit to tell the
3339 struct GTY(()) rtx_constant_pool {
3340 /* Pointers to first and last constant in pool, as ordered by offset. */
3341 struct constant_descriptor_rtx *first;
3342 struct constant_descriptor_rtx *last;
3344 /* Hash facility for making memory-constants from constant rtl-expressions.
3345 It is used on RISC machines where immediate integer arguments and
3346 constant addresses are restricted so that such constants must be stored
3348 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
3350 /* Current offset in constant pool (does not include any
3351 machine-specific header). */
3352 HOST_WIDE_INT offset;
3355 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx {
3356 struct constant_descriptor_rtx *next;
3360 HOST_WIDE_INT offset;
3362 enum machine_mode mode;
3368 /* Hash and compare functions for const_rtx_htab. */
3371 const_desc_rtx_hash (const void *ptr)
3373 const struct constant_descriptor_rtx *const desc
3374 = (const struct constant_descriptor_rtx *) ptr;
3379 const_desc_rtx_eq (const void *a, const void *b)
3381 const struct constant_descriptor_rtx *const x
3382 = (const struct constant_descriptor_rtx *) a;
3383 const struct constant_descriptor_rtx *const y
3384 = (const struct constant_descriptor_rtx *) b;
3386 if (x->mode != y->mode)
3388 return rtx_equal_p (x->constant, y->constant);
3391 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3394 const_rtx_hash_1 (rtx *xp, void *data)
3396 unsigned HOST_WIDE_INT hwi;
3397 enum machine_mode mode;
3403 code = GET_CODE (x);
3404 mode = GET_MODE (x);
3405 h = (hashval_t) code * 1048573 + mode;
3413 int shift = sizeof (hashval_t) * CHAR_BIT;
3414 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
3417 h ^= (hashval_t) hwi;
3418 for (i = 1; i < n; ++i)
3421 h ^= (hashval_t) hwi;
3427 if (mode == VOIDmode)
3429 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
3433 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
3437 h ^= fixed_hash (CONST_FIXED_VALUE (x));
3443 for (i = XVECLEN (x, 0); i-- > 0; )
3444 h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data);
3449 h ^= htab_hash_string (XSTR (x, 0));
3453 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
3457 case UNSPEC_VOLATILE:
3458 h = h * 251 + XINT (x, 1);
3465 hp = (hashval_t *) data;
3466 *hp = *hp * 509 + h;
3470 /* Compute a hash value for X, which should be a constant. */
3473 const_rtx_hash (rtx x)
3476 for_each_rtx (&x, const_rtx_hash_1, &h);
3481 /* Create and return a new rtx constant pool. */
3483 static struct rtx_constant_pool *
3484 create_constant_pool (void)
3486 struct rtx_constant_pool *pool;
3488 pool = ggc_alloc_rtx_constant_pool ();
3489 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
3490 const_desc_rtx_eq, NULL);
3497 /* Initialize constant pool hashing for a new function. */
3500 init_varasm_status (void)
3502 crtl->varasm.pool = create_constant_pool ();
3503 crtl->varasm.deferred_constants = 0;
3506 /* Given a MINUS expression, simplify it if both sides
3507 include the same symbol. */
3510 simplify_subtraction (rtx x)
3512 rtx r = simplify_rtx (x);
3516 /* Given a constant rtx X, make (or find) a memory constant for its value
3517 and return a MEM rtx to refer to it in memory. */
3520 force_const_mem (enum machine_mode mode, rtx x)
3522 struct constant_descriptor_rtx *desc, tmp;
3523 struct rtx_constant_pool *pool;
3530 /* If we're not allowed to drop X into the constant pool, don't. */
3531 if (targetm.cannot_force_const_mem (mode, x))
3534 /* Record that this function has used a constant pool entry. */
3535 crtl->uses_const_pool = 1;
3537 /* Decide which pool to use. */
3538 pool = (targetm.use_blocks_for_constant_p (mode, x)
3539 ? shared_constant_pool
3540 : crtl->varasm.pool);
3542 /* Lookup the value in the hashtable. */
3545 hash = const_rtx_hash (x);
3546 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
3547 desc = (struct constant_descriptor_rtx *) *slot;
3549 /* If the constant was already present, return its memory. */
3551 return copy_rtx (desc->mem);
3553 /* Otherwise, create a new descriptor. */
3554 desc = ggc_alloc_constant_descriptor_rtx ();
3557 /* Align the location counter as required by EXP's data type. */
3558 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3559 #ifdef CONSTANT_ALIGNMENT
3561 tree type = lang_hooks.types.type_for_mode (mode, 0);
3562 if (type != NULL_TREE)
3563 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
3567 pool->offset += (align / BITS_PER_UNIT) - 1;
3568 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
3571 desc->constant = copy_rtx (tmp.constant);
3572 desc->offset = pool->offset;
3575 desc->align = align;
3576 desc->labelno = const_labelno;
3579 pool->offset += GET_MODE_SIZE (mode);
3581 pool->last->next = desc;
3583 pool->first = pool->last = desc;
3586 /* Create a string containing the label name, in LABEL. */
3587 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3590 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3591 the constants pool. */
3592 if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
3594 section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
3595 symbol = create_block_symbol (ggc_strdup (label),
3596 get_block_for_section (sect), -1);
3599 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3601 SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3602 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3603 SET_SYMBOL_REF_CONSTANT (symbol, desc);
3605 /* Construct the MEM. */
3606 desc->mem = def = gen_const_mem (mode, symbol);
3607 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
3608 set_mem_align (def, align);
3610 /* If we're dropping a label to the constant pool, make sure we
3612 if (GET_CODE (x) == LABEL_REF)
3613 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3615 return copy_rtx (def);
3618 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3621 get_pool_constant (rtx addr)
3623 return SYMBOL_REF_CONSTANT (addr)->constant;
3626 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3627 and whether it has been output or not. */
3630 get_pool_constant_mark (rtx addr, bool *pmarked)
3632 struct constant_descriptor_rtx *desc;
3634 desc = SYMBOL_REF_CONSTANT (addr);
3635 *pmarked = (desc->mark != 0);
3636 return desc->constant;
3639 /* Similar, return the mode. */
3642 get_pool_mode (const_rtx addr)
3644 return SYMBOL_REF_CONSTANT (addr)->mode;
3647 /* Return the size of the constant pool. */
3650 get_pool_size (void)
3652 return crtl->varasm.pool->offset;
3655 /* Worker function for output_constant_pool_1. Emit assembly for X
3656 in MODE with known alignment ALIGN. */
3659 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3661 switch (GET_MODE_CLASS (mode))
3664 case MODE_DECIMAL_FLOAT:
3668 gcc_assert (GET_CODE (x) == CONST_DOUBLE);
3669 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3670 assemble_real (r, mode, align);
3675 case MODE_PARTIAL_INT:
3680 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3683 case MODE_VECTOR_FLOAT:
3684 case MODE_VECTOR_INT:
3685 case MODE_VECTOR_FRACT:
3686 case MODE_VECTOR_UFRACT:
3687 case MODE_VECTOR_ACCUM:
3688 case MODE_VECTOR_UACCUM:
3691 enum machine_mode submode = GET_MODE_INNER (mode);
3692 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3694 gcc_assert (GET_CODE (x) == CONST_VECTOR);
3695 units = CONST_VECTOR_NUNITS (x);
3697 for (i = 0; i < units; i++)
3699 rtx elt = CONST_VECTOR_ELT (x, i);
3700 output_constant_pool_2 (submode, elt, i ? subalign : align);
3710 /* Worker function for output_constant_pool. Emit constant DESC,
3711 giving it ALIGN bits of alignment. */
3714 output_constant_pool_1 (struct constant_descriptor_rtx *desc,
3721 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3722 whose CODE_LABEL has been deleted. This can occur if a jump table
3723 is eliminated by optimization. If so, write a constant of zero
3724 instead. Note that this can also happen by turning the
3725 CODE_LABEL into a NOTE. */
3726 /* ??? This seems completely and utterly wrong. Certainly it's
3727 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3728 functioning even with INSN_DELETED_P and friends. */
3731 switch (GET_CODE (tmp))
3734 if (GET_CODE (XEXP (tmp, 0)) != PLUS
3735 || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
3737 tmp = XEXP (XEXP (tmp, 0), 0);
3741 tmp = XEXP (tmp, 0);
3742 gcc_assert (!INSN_DELETED_P (tmp));
3743 gcc_assert (!NOTE_P (tmp)
3744 || NOTE_KIND (tmp) != NOTE_INSN_DELETED);
3751 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3752 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3753 align, desc->labelno, done);
3756 assemble_align (align);
3758 /* Output the label. */
3759 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3761 /* Output the data. */
3762 output_constant_pool_2 (desc->mode, x, align);
3764 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3765 sections have proper size. */
3766 if (align > GET_MODE_BITSIZE (desc->mode)
3768 && (in_section->common.flags & SECTION_MERGE))
3769 assemble_align (align);
3771 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3777 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3778 to as used. Emit referenced deferred strings. This function can
3779 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3782 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3784 rtx x = *current_rtx;
3786 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3789 if (CONSTANT_POOL_ADDRESS_P (x))
3791 struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
3792 if (desc->mark == 0)
3795 for_each_rtx (&desc->constant, mark_constant, NULL);
3798 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3800 tree decl = SYMBOL_REF_DECL (x);
3801 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
3803 n_deferred_constants--;
3804 output_constant_def_contents (x);
3811 /* Look through appropriate parts of INSN, marking all entries in the
3812 constant pool which are actually being used. Entries that are only
3813 referenced by other constants are also marked as used. Emit
3814 deferred strings that are used. */
3817 mark_constants (rtx insn)
3822 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3823 insns, not any notes that may be attached. We don't want to mark
3824 a constant just because it happens to appear in a REG_EQUIV note. */
3825 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3827 rtx seq = PATTERN (insn);
3828 int i, n = XVECLEN (seq, 0);
3829 for (i = 0; i < n; ++i)
3831 rtx subinsn = XVECEXP (seq, 0, i);
3832 if (INSN_P (subinsn))
3833 for_each_rtx (&PATTERN (subinsn), mark_constant, NULL);
3837 for_each_rtx (&PATTERN (insn), mark_constant, NULL);
3840 /* Look through the instructions for this function, and mark all the
3841 entries in POOL which are actually being used. Emit deferred constants
3842 which have indeed been used. */
3845 mark_constant_pool (void)
3849 if (!crtl->uses_const_pool && n_deferred_constants == 0)
3852 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3853 mark_constants (insn);
3855 for (link = crtl->epilogue_delay_list;
3857 link = XEXP (link, 1))
3858 mark_constants (XEXP (link, 0));
3861 /* Write all the constants in POOL. */
3864 output_constant_pool_contents (struct rtx_constant_pool *pool)
3866 struct constant_descriptor_rtx *desc;
3868 for (desc = pool->first; desc ; desc = desc->next)
3871 /* If the constant is part of an object_block, make sure that
3872 the constant has been positioned within its block, but do not
3873 write out its definition yet. output_object_blocks will do
3875 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
3876 && SYMBOL_REF_BLOCK (desc->sym))
3877 place_block_symbol (desc->sym);
3880 switch_to_section (targetm.asm_out.select_rtx_section
3881 (desc->mode, desc->constant, desc->align));
3882 output_constant_pool_1 (desc, desc->align);
3887 /* Mark all constants that are used in the current function, then write
3888 out the function's private constant pool. */
3891 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3892 tree fndecl ATTRIBUTE_UNUSED)
3894 struct rtx_constant_pool *pool = crtl->varasm.pool;
3896 /* It is possible for gcc to call force_const_mem and then to later
3897 discard the instructions which refer to the constant. In such a
3898 case we do not need to output the constant. */
3899 mark_constant_pool ();
3901 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3902 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3905 output_constant_pool_contents (pool);
3907 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3908 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3912 /* Write the contents of the shared constant pool. */
3915 output_shared_constant_pool (void)
3917 output_constant_pool_contents (shared_constant_pool);
3920 /* Determine what kind of relocations EXP may need. */
3923 compute_reloc_for_constant (tree exp)
3925 int reloc = 0, reloc2;
3928 switch (TREE_CODE (exp))
3932 /* Go inside any operations that get_inner_reference can handle and see
3933 if what's inside is a constant: no need to do anything here for
3934 addresses of variables or functions. */
3935 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3936 tem = TREE_OPERAND (tem, 0))
3939 if (TREE_PUBLIC (tem))
3946 case POINTER_PLUS_EXPR:
3947 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3948 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3952 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3953 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3954 /* The difference of two local labels is computable at link time. */
3955 if (reloc == 1 && reloc2 == 1)
3962 case VIEW_CONVERT_EXPR:
3963 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3968 unsigned HOST_WIDE_INT idx;
3969 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
3971 reloc |= compute_reloc_for_constant (tem);
3981 /* Find all the constants whose addresses are referenced inside of EXP,
3982 and make sure assembler code with a label has been output for each one.
3983 Indicate whether an ADDR_EXPR has been encountered. */
3986 output_addressed_constants (tree exp)
3990 switch (TREE_CODE (exp))
3994 /* Go inside any operations that get_inner_reference can handle and see
3995 if what's inside is a constant: no need to do anything here for
3996 addresses of variables or functions. */
3997 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3998 tem = TREE_OPERAND (tem, 0))
4001 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4002 if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4003 tem = DECL_INITIAL (tem);
4005 if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4006 output_constant_def (tem, 0);
4010 case POINTER_PLUS_EXPR:
4012 output_addressed_constants (TREE_OPERAND (exp, 1));
4016 case VIEW_CONVERT_EXPR:
4017 output_addressed_constants (TREE_OPERAND (exp, 0));
4022 unsigned HOST_WIDE_INT idx;
4023 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4025 output_addressed_constants (tem);
4034 /* Whether a constructor CTOR is a valid static constant initializer if all
4035 its elements are. This used to be internal to initializer_constant_valid_p
4036 and has been exposed to let other functions like categorize_ctor_elements
4037 evaluate the property while walking a constructor for other purposes. */
4040 constructor_static_from_elts_p (const_tree ctor)
4042 return (TREE_CONSTANT (ctor)
4043 && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4044 || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
4045 || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
4048 static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4051 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4052 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4053 which are valid when ENDTYPE is an integer of any size; in
4054 particular, this does not accept a pointer minus a constant. This
4055 returns null_pointer_node if the VALUE is an absolute constant
4056 which can be used to initialize a static variable. Otherwise it
4060 narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4064 if (!INTEGRAL_TYPE_P (endtype))
4067 op0 = TREE_OPERAND (value, 0);
4068 op1 = TREE_OPERAND (value, 1);
4070 /* Like STRIP_NOPS except allow the operand mode to widen. This
4071 works around a feature of fold that simplifies (int)(p1 - p2) to
4072 ((int)p1 - (int)p2) under the theory that the narrower operation
4075 while (CONVERT_EXPR_P (op0)
4076 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4078 tree inner = TREE_OPERAND (op0, 0);
4079 if (inner == error_mark_node
4080 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4081 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4082 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4087 while (CONVERT_EXPR_P (op1)
4088 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4090 tree inner = TREE_OPERAND (op1, 0);
4091 if (inner == error_mark_node
4092 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4093 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4094 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4099 op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4103 op1 = initializer_constant_valid_p_1 (op1, endtype,
4104 cache ? cache + 2 : NULL);
4105 /* Both initializers must be known. */
4109 && (op0 == null_pointer_node
4110 || TREE_CODE (value) == MINUS_EXPR))
4111 return null_pointer_node;
4113 /* Support differences between labels. */
4114 if (TREE_CODE (op0) == LABEL_DECL
4115 && TREE_CODE (op1) == LABEL_DECL)
4116 return null_pointer_node;
4118 if (TREE_CODE (op0) == STRING_CST
4119 && TREE_CODE (op1) == STRING_CST
4120 && operand_equal_p (op0, op1, 1))
4121 return null_pointer_node;
4127 /* Helper function of initializer_constant_valid_p.
4128 Return nonzero if VALUE is a valid constant-valued expression
4129 for use in initializing a static variable; one that can be an
4130 element of a "constant" initializer.
4132 Return null_pointer_node if the value is absolute;
4133 if it is relocatable, return the variable that determines the relocation.
4134 We assume that VALUE has been folded as much as possible;
4135 therefore, we do not need to check for such things as
4136 arithmetic-combinations of integers.
4138 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4141 initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
4145 switch (TREE_CODE (value))
4148 if (constructor_static_from_elts_p (value))
4150 unsigned HOST_WIDE_INT idx;
4152 bool absolute = true;
4154 if (cache && cache[0] == value)
4156 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
4159 reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
4166 cache[1] = NULL_TREE;
4170 if (reloc != null_pointer_node)
4173 /* For a non-absolute relocation, there is no single
4174 variable that can be "the variable that determines the
4179 cache[1] = absolute ? null_pointer_node : error_mark_node;
4181 return absolute ? null_pointer_node : error_mark_node;
4184 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
4192 return null_pointer_node;
4197 tree op0 = staticp (TREE_OPERAND (value, 0));
4200 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4201 to be a constant, this is old-skool offsetof-like nonsense. */
4202 if (TREE_CODE (op0) == INDIRECT_REF
4203 && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
4204 return null_pointer_node;
4205 /* Taking the address of a nested function involves a trampoline,
4206 unless we don't need or want one. */
4207 if (TREE_CODE (op0) == FUNCTION_DECL
4208 && DECL_STATIC_CHAIN (op0)
4209 && !TREE_NO_TRAMPOLINE (value))
4211 /* "&{...}" requires a temporary to hold the constructed
4213 if (TREE_CODE (op0) == CONSTRUCTOR)
4219 case NON_LVALUE_EXPR:
4220 return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4223 case VIEW_CONVERT_EXPR:
4225 tree src = TREE_OPERAND (value, 0);
4226 tree src_type = TREE_TYPE (src);
4227 tree dest_type = TREE_TYPE (value);
4229 /* Allow view-conversions from aggregate to non-aggregate type only
4230 if the bit pattern is fully preserved afterwards; otherwise, the
4231 RTL expander won't be able to apply a subsequent transformation
4232 to the underlying constructor. */
4233 if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
4235 if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
4236 return initializer_constant_valid_p_1 (src, endtype, cache);
4241 /* Allow all other kinds of view-conversion. */
4242 return initializer_constant_valid_p_1 (src, endtype, cache);
4247 tree src = TREE_OPERAND (value, 0);
4248 tree src_type = TREE_TYPE (src);
4249 tree dest_type = TREE_TYPE (value);
4251 /* Allow conversions between pointer types, floating-point
4252 types, and offset types. */
4253 if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
4254 || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type))
4255 || (TREE_CODE (dest_type) == OFFSET_TYPE
4256 && TREE_CODE (src_type) == OFFSET_TYPE))
4257 return initializer_constant_valid_p_1 (src, endtype, cache);
4259 /* Allow length-preserving conversions between integer types. */
4260 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)
4261 && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
4262 return initializer_constant_valid_p_1 (src, endtype, cache);
4264 /* Allow conversions between other integer types only if
4266 if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
4268 tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
4269 if (inner == null_pointer_node)
4270 return null_pointer_node;
4274 /* Allow (int) &foo provided int is as wide as a pointer. */
4275 if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
4276 && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
4277 return initializer_constant_valid_p_1 (src, endtype, cache);
4279 /* Likewise conversions from int to pointers, but also allow
4280 conversions from 0. */
4281 if ((POINTER_TYPE_P (dest_type)
4282 || TREE_CODE (dest_type) == OFFSET_TYPE)
4283 && INTEGRAL_TYPE_P (src_type))
4285 if (TREE_CODE (src) == INTEGER_CST
4286 && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
4287 return null_pointer_node;
4288 if (integer_zerop (src))
4289 return null_pointer_node;
4290 else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
4291 return initializer_constant_valid_p_1 (src, endtype, cache);
4294 /* Allow conversions to struct or union types if the value
4296 if (TREE_CODE (dest_type) == RECORD_TYPE
4297 || TREE_CODE (dest_type) == UNION_TYPE)
4298 return initializer_constant_valid_p_1 (src, endtype, cache);
4302 case POINTER_PLUS_EXPR:
4304 /* Any valid floating-point constants will have been folded by now;
4305 with -frounding-math we hit this with addition of two constants. */
4306 if (TREE_CODE (endtype) == REAL_TYPE)
4308 if (cache && cache[0] == value)
4310 if (! INTEGRAL_TYPE_P (endtype)
4311 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4313 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4315 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4318 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4319 endtype, ncache + 2);
4320 /* If either term is absolute, use the other term's relocation. */
4321 if (valid0 == null_pointer_node)
4323 else if (valid1 == null_pointer_node)
4325 /* Support narrowing pointer differences. */
4327 ret = narrowing_initializer_constant_valid_p (value, endtype,
4331 /* Support narrowing pointer differences. */
4332 ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
4341 if (TREE_CODE (endtype) == REAL_TYPE)
4343 if (cache && cache[0] == value)
4345 if (! INTEGRAL_TYPE_P (endtype)
4346 || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
4348 tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
4350 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
4353 = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
4354 endtype, ncache + 2);
4355 /* Win if second argument is absolute. */
4356 if (valid1 == null_pointer_node)
4358 /* Win if both arguments have the same relocation.
4359 Then the value is absolute. */
4360 else if (valid0 == valid1 && valid0 != 0)
4361 ret = null_pointer_node;
4362 /* Since GCC guarantees that string constants are unique in the
4363 generated code, a subtraction between two copies of the same
4364 constant string is absolute. */
4365 else if (valid0 && TREE_CODE (valid0) == STRING_CST
4366 && valid1 && TREE_CODE (valid1) == STRING_CST
4367 && operand_equal_p (valid0, valid1, 1))