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 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
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. */
37 #include "hard-reg-set.h"
46 #include "langhooks.h"
51 #ifdef XCOFF_DEBUGGING_INFO
52 #include "xcoffout.h" /* Needed for external data
53 declarations for e.g. AIX 4.x. */
56 #ifndef TRAMPOLINE_ALIGNMENT
57 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
61 #define ASM_STABS_OP "\t.stabs\t"
64 /* The (assembler) name of the first globally-visible object output. */
65 const char *first_global_object_name;
66 const char *weak_global_object_name;
68 extern struct obstack permanent_obstack;
69 #define obstack_chunk_alloc xmalloc
72 struct constant_descriptor;
76 #define MAX_RTX_HASH_TABLE 61
80 /* Hash facility for making memory-constants
81 from constant rtl-expressions. It is used on RISC machines
82 where immediate integer arguments and constant addresses are restricted
83 so that such constants must be stored in memory.
85 This pool of constants is reinitialized for each function
86 so each function gets its own constants-pool that comes right before
88 struct constant_descriptor **x_const_rtx_hash_table;
89 struct pool_constant **x_const_rtx_sym_hash_table;
91 /* Pointers to first and last constant in pool. */
92 struct pool_constant *x_first_pool, *x_last_pool;
94 /* Current offset in constant pool (does not include any machine-specific
96 HOST_WIDE_INT x_pool_offset;
98 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
99 They are chained through the CONST_DOUBLE_CHAIN. */
100 rtx x_const_double_chain;
103 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
104 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
105 #define first_pool (cfun->varasm->x_first_pool)
106 #define last_pool (cfun->varasm->x_last_pool)
107 #define pool_offset (cfun->varasm->x_pool_offset)
108 #define const_double_chain (cfun->varasm->x_const_double_chain)
110 /* Number for making the label on the next
111 constant that is stored in memory. */
115 /* Number for making the label on the next
116 static variable internal to a function. */
120 /* Carry information from ASM_DECLARE_OBJECT_NAME
121 to ASM_FINISH_DECLARE_OBJECT. */
123 int size_directive_output;
125 /* The last decl for which assemble_variable was called,
126 if it did ASM_DECLARE_OBJECT_NAME.
127 If the last call to assemble_variable didn't do that,
130 tree last_assemble_variable_decl;
132 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
133 So giving constant the alias set for the type will allow such
134 initializations to appear to conflict with the load of the constant. We
135 avoid this by giving all constants an alias set for just constants.
136 Since there will be no stores to that alias set, nothing will ever
137 conflict with them. */
139 static HOST_WIDE_INT const_alias_set;
141 static const char *strip_reg_name PARAMS ((const char *));
142 static int contains_pointers_p PARAMS ((tree));
143 static void decode_addr_const PARAMS ((tree, struct addr_const *));
144 static int const_hash PARAMS ((tree));
145 static int compare_constant PARAMS ((tree,
146 struct constant_descriptor *));
147 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
148 static struct constant_descriptor *record_constant PARAMS ((tree));
149 static void record_constant_1 PARAMS ((tree));
150 static tree copy_constant PARAMS ((tree));
151 static void output_constant_def_contents PARAMS ((tree, int, int));
152 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
153 struct rtx_const *));
154 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
155 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
156 struct constant_descriptor *));
157 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
159 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
160 static void mark_constant_pool PARAMS ((void));
161 static void mark_constants PARAMS ((rtx));
162 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
163 static int output_addressed_constants PARAMS ((tree));
164 static void output_after_function_constants PARAMS ((void));
165 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
166 static unsigned min_align PARAMS ((unsigned, unsigned));
167 static void output_constructor PARAMS ((tree, HOST_WIDE_INT,
169 static void globalize_decl PARAMS ((tree));
170 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
171 static hashval_t in_named_entry_hash PARAMS ((const PTR));
172 #ifdef ASM_OUTPUT_BSS
173 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
175 #ifdef BSS_SECTION_ASM_OP
176 #ifdef ASM_OUTPUT_ALIGNED_BSS
177 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
180 #endif /* BSS_SECTION_ASM_OP */
181 static void mark_pool_constant PARAMS ((struct pool_constant *));
182 static void mark_const_hash_entry PARAMS ((void *));
183 static int mark_const_str_htab_1 PARAMS ((void **, void *));
184 static void mark_const_str_htab PARAMS ((void *));
185 static hashval_t const_str_htab_hash PARAMS ((const void *x));
186 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
187 static void const_str_htab_del PARAMS ((void *));
188 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
189 static void resolve_unique_section PARAMS ((tree, int, int));
190 static void mark_weak PARAMS ((tree));
192 static enum in_section { no_section, in_text, in_data, in_named
193 #ifdef BSS_SECTION_ASM_OP
196 #ifdef CTORS_SECTION_ASM_OP
199 #ifdef DTORS_SECTION_ASM_OP
202 #ifdef EXTRA_SECTIONS
205 } in_section = no_section;
207 /* Return a non-zero value if DECL has a section attribute. */
208 #ifndef IN_NAMED_SECTION
209 #define IN_NAMED_SECTION(DECL) \
210 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
211 && DECL_SECTION_NAME (DECL) != NULL_TREE)
214 /* Text of section name when in_section == in_named. */
215 static const char *in_named_name;
217 /* Hash table of flags that have been used for a particular named section. */
219 struct in_named_entry
226 static htab_t in_named_htab;
228 /* Define functions like text_section for any extra sections. */
229 #ifdef EXTRA_SECTION_FUNCTIONS
230 EXTRA_SECTION_FUNCTIONS
233 /* Tell assembler to switch to text section. */
238 if (in_section != in_text)
243 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
245 in_section = in_text;
249 /* Tell assembler to switch to data section. */
254 if (in_section != in_data)
256 if (flag_shared_data)
258 #ifdef SHARED_SECTION_ASM_OP
259 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
261 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
265 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
267 in_section = in_data;
270 /* Tell assembler to ALWAYS switch to data section, in case
271 it's not sure where it is. */
274 force_data_section ()
276 in_section = no_section;
280 /* Tell assembler to switch to read-only data section. This is normally
284 readonly_data_section ()
286 #ifdef READONLY_DATA_SECTION
287 READONLY_DATA_SECTION (); /* Note this can call data_section. */
293 /* Determine if we're in the text section. */
298 return in_section == in_text;
301 /* Determine if we're in the data section. */
306 return in_section == in_data;
309 /* Helper routines for maintaining in_named_htab. */
312 in_named_entry_eq (p1, p2)
316 const struct in_named_entry *old = p1;
317 const char *new = p2;
319 return strcmp (old->name, new) == 0;
323 in_named_entry_hash (p)
326 const struct in_named_entry *old = p;
327 return htab_hash_string (old->name);
330 /* If SECTION has been seen before as a named section, return the flags
331 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
332 set of flags for a section to have, so 0 does not mean that the section
333 has not been seen. */
336 get_named_section_flags (section)
339 struct in_named_entry **slot;
341 slot = (struct in_named_entry**)
342 htab_find_slot_with_hash (in_named_htab, section,
343 htab_hash_string (section), NO_INSERT);
345 return slot ? (*slot)->flags : 0;
348 /* Returns true if the section has been declared before. Sets internal
349 flag on this section in in_named_hash so subsequent calls on this
350 section will return false. */
353 named_section_first_declaration (name)
356 struct in_named_entry **slot;
358 slot = (struct in_named_entry**)
359 htab_find_slot_with_hash (in_named_htab, name,
360 htab_hash_string (name), NO_INSERT);
361 if (! (*slot)->declared)
363 (*slot)->declared = true;
373 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
374 different set of flags, return false. */
377 set_named_section_flags (section, flags)
381 struct in_named_entry **slot, *entry;
383 slot = (struct in_named_entry**)
384 htab_find_slot_with_hash (in_named_htab, section,
385 htab_hash_string (section), INSERT);
390 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
392 entry->name = ggc_strdup (section);
393 entry->flags = flags;
394 entry->declared = false;
396 else if (entry->flags != flags)
402 /* Tell assembler to change to section NAME with attributes FLAGS. */
405 named_section_flags (name, flags)
409 if (in_section != in_named || strcmp (name, in_named_name) != 0)
411 if (! set_named_section_flags (name, flags))
414 (* targetm.asm_out.named_section) (name, flags);
416 if (flags & SECTION_FORGET)
417 in_section = no_section;
420 in_named_name = ggc_strdup (name);
421 in_section = in_named;
426 /* Tell assembler to change to section NAME for DECL.
427 If DECL is NULL, just switch to section NAME.
428 If NAME is NULL, get the name from DECL.
429 If RELOC is 1, the initializer for DECL contains relocs. */
432 named_section (decl, name, reloc)
439 if (decl != NULL_TREE && !DECL_P (decl))
442 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
444 flags = (* targetm.section_type_flags) (decl, name, reloc);
446 /* Sanity check user variables for flag changes. Non-user
447 section flag changes will abort in named_section_flags.
448 However, don't complain if SECTION_OVERRIDE is set.
449 We trust that the setter knows that it is safe to ignore
450 the default flags for this decl. */
451 if (decl && ! set_named_section_flags (name, flags))
453 flags = get_named_section_flags (name);
454 if ((flags & SECTION_OVERRIDE) == 0)
455 error_with_decl (decl, "%s causes a section type conflict");
458 named_section_flags (name, flags);
461 /* If required, set DECL_SECTION_NAME to a unique name. */
464 resolve_unique_section (decl, reloc, flag_function_or_data_sections)
466 int reloc ATTRIBUTE_UNUSED;
467 int flag_function_or_data_sections;
469 if (DECL_SECTION_NAME (decl) == NULL_TREE
470 && (flag_function_or_data_sections
471 || (targetm.have_named_sections
472 && DECL_ONE_ONLY (decl))))
473 UNIQUE_SECTION (decl, reloc);
476 #ifdef BSS_SECTION_ASM_OP
478 /* Tell the assembler to switch to the bss section. */
483 if (in_section != in_bss)
485 #ifdef SHARED_BSS_SECTION_ASM_OP
486 if (flag_shared_data)
487 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
490 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
496 #ifdef ASM_OUTPUT_BSS
498 /* Utility function for ASM_OUTPUT_BSS for targets to use if
499 they don't support alignments in .bss.
500 ??? It is believed that this function will work in most cases so such
501 support is localized here. */
504 asm_output_bss (file, decl, name, size, rounded)
506 tree decl ATTRIBUTE_UNUSED;
508 int size ATTRIBUTE_UNUSED, rounded;
510 ASM_GLOBALIZE_LABEL (file, name);
512 #ifdef ASM_DECLARE_OBJECT_NAME
513 last_assemble_variable_decl = decl;
514 ASM_DECLARE_OBJECT_NAME (file, name, decl);
516 /* Standard thing is just output label for the object. */
517 ASM_OUTPUT_LABEL (file, name);
518 #endif /* ASM_DECLARE_OBJECT_NAME */
519 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
524 #ifdef ASM_OUTPUT_ALIGNED_BSS
526 /* Utility function for targets to use in implementing
527 ASM_OUTPUT_ALIGNED_BSS.
528 ??? It is believed that this function will work in most cases so such
529 support is localized here. */
532 asm_output_aligned_bss (file, decl, name, size, align)
534 tree decl ATTRIBUTE_UNUSED;
538 ASM_GLOBALIZE_LABEL (file, name);
540 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
541 #ifdef ASM_DECLARE_OBJECT_NAME
542 last_assemble_variable_decl = decl;
543 ASM_DECLARE_OBJECT_NAME (file, name, decl);
545 /* Standard thing is just output label for the object. */
546 ASM_OUTPUT_LABEL (file, name);
547 #endif /* ASM_DECLARE_OBJECT_NAME */
548 ASM_OUTPUT_SKIP (file, size ? size : 1);
553 #endif /* BSS_SECTION_ASM_OP */
555 /* Switch to the section for function DECL.
557 If DECL is NULL_TREE, switch to the text section.
558 ??? It's not clear that we will ever be passed NULL_TREE, but it's
559 safer to handle it. */
562 function_section (decl)
565 if (decl != NULL_TREE
566 && DECL_SECTION_NAME (decl) != NULL_TREE)
567 named_section (decl, (char *) 0, 0);
572 /* Switch to section for variable DECL.
574 RELOC is the `reloc' argument to SELECT_SECTION. */
577 variable_section (decl, reloc)
581 if (IN_NAMED_SECTION (decl))
582 named_section (decl, NULL, reloc);
585 /* C++ can have const variables that get initialized from constructors,
586 and thus can not be in a readonly section. We prevent this by
587 verifying that the initial value is constant for objects put in a
590 error_mark_node is used by the C front end to indicate that the
591 initializer has not been seen yet. In this case, we assume that
592 the initializer must be constant.
594 C++ uses error_mark_node for variables that have complicated
595 initializers, but these variables go in BSS so we won't be called
598 #ifdef SELECT_SECTION
599 SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
601 if (DECL_READONLY_SECTION (decl, reloc))
602 readonly_data_section ();
609 /* Tell assembler to switch to the section for the exception handling
613 default_exception_section ()
615 if (targetm.have_named_sections)
616 named_section (NULL_TREE, ".gcc_except_table", 0);
620 readonly_data_section ();
623 /* Tell assembler to switch to the section for string merging. */
626 mergeable_string_section (decl, align, flags)
627 tree decl ATTRIBUTE_UNUSED;
628 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
629 unsigned int flags ATTRIBUTE_UNUSED;
631 #ifdef HAVE_GAS_SHF_MERGE
632 if (flag_merge_constants
633 && TREE_CODE (decl) == STRING_CST
634 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
636 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
638 enum machine_mode mode;
639 unsigned int modesize;
644 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
645 modesize = GET_MODE_BITSIZE (mode);
646 if (modesize >= 8 && modesize <= 256
647 && (modesize & (modesize - 1)) == 0)
649 if (align < modesize)
652 str = TREE_STRING_POINTER (decl);
653 len = TREE_STRING_LENGTH (decl);
654 unit = GET_MODE_SIZE (mode);
656 /* Check for embedded NUL characters. */
657 for (i = 0; i < len; i += unit)
659 for (j = 0; j < unit; j++)
660 if (str [i + j] != '\0')
667 sprintf (name, ".rodata.str%d.%d", modesize / 8,
669 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
670 if (!i && modesize < align)
672 /* A "" string with requested alignment greater than
673 character size might cause a problem:
674 if some other string required even bigger
675 alignment than "", then linker might think the
676 "" is just part of padding after some other string
677 and not put it into the hash table initially.
678 But this means "" could have smaller alignment
680 #ifdef ASM_OUTPUT_SECTION_START
681 named_section_flags (name, flags);
682 ASM_OUTPUT_SECTION_START (asm_out_file);
684 readonly_data_section ();
689 named_section_flags (name, flags);
695 readonly_data_section ();
698 /* Tell assembler to switch to the section for constant merging. */
701 mergeable_constant_section (mode, align, flags)
702 enum machine_mode mode ATTRIBUTE_UNUSED;
703 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
704 unsigned int flags ATTRIBUTE_UNUSED;
706 #ifdef HAVE_GAS_SHF_MERGE
707 unsigned int modesize = GET_MODE_BITSIZE (mode);
709 if (flag_merge_constants
715 && (align & (align - 1)) == 0)
719 sprintf (name, ".rodata.cst%d", (int) (align / 8));
720 flags |= (align / 8) | SECTION_MERGE;
721 named_section_flags (name, flags);
725 readonly_data_section ();
728 /* Given NAME, a putative register name, discard any customary prefixes. */
731 strip_reg_name (name)
734 #ifdef REGISTER_PREFIX
735 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
736 name += strlen (REGISTER_PREFIX);
738 if (name[0] == '%' || name[0] == '#')
743 /* Decode an `asm' spec for a declaration as a register name.
744 Return the register number, or -1 if nothing specified,
745 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
746 or -3 if ASMSPEC is `cc' and is not recognized,
747 or -4 if ASMSPEC is `memory' and is not recognized.
748 Accept an exact spelling or a decimal number.
749 Prefixes such as % are optional. */
752 decode_reg_name (asmspec)
759 /* Get rid of confusing prefixes. */
760 asmspec = strip_reg_name (asmspec);
762 /* Allow a decimal number as a "register name". */
763 for (i = strlen (asmspec) - 1; i >= 0; i--)
764 if (! ISDIGIT (asmspec[i]))
766 if (asmspec[0] != 0 && i < 0)
769 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
775 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
777 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
780 #ifdef ADDITIONAL_REGISTER_NAMES
782 static const struct { const char *const name; const int number; } table[]
783 = ADDITIONAL_REGISTER_NAMES;
785 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
786 if (! strcmp (asmspec, table[i].name))
787 return table[i].number;
789 #endif /* ADDITIONAL_REGISTER_NAMES */
791 if (!strcmp (asmspec, "memory"))
794 if (!strcmp (asmspec, "cc"))
803 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
804 have static storage duration. In other words, it should not be an
805 automatic variable, including PARM_DECLs.
807 There is, however, one exception: this function handles variables
808 explicitly placed in a particular register by the user.
810 ASMSPEC, if not 0, is the string which the user specified as the
811 assembler symbol name.
813 This is never called for PARM_DECL nodes. */
816 make_decl_rtl (decl, asmspec)
820 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
821 const char *name = 0;
822 const char *new_name = 0;
826 /* Check that we are not being given an automatic variable. */
827 /* A weak alias has TREE_PUBLIC set but not the other bits. */
828 if (TREE_CODE (decl) == PARM_DECL
829 || TREE_CODE (decl) == RESULT_DECL
830 || (TREE_CODE (decl) == VAR_DECL
831 && !TREE_STATIC (decl)
832 && !TREE_PUBLIC (decl)
833 && !DECL_EXTERNAL (decl)
834 && !DECL_REGISTER (decl)))
836 /* And that we were not given a type or a label. */
837 else if (TREE_CODE (decl) == TYPE_DECL
838 || TREE_CODE (decl) == LABEL_DECL)
841 /* For a duplicate declaration, we can be called twice on the
842 same DECL node. Don't discard the RTL already made. */
843 if (DECL_RTL_SET_P (decl))
845 /* If the old RTL had the wrong mode, fix the mode. */
846 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
847 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
848 DECL_MODE (decl), 0));
850 /* ??? Another way to do this would be to do what halfpic.c does
851 and maintain a hashed table of such critters. */
852 /* ??? Another way to do this would be to pass a flag bit to
853 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
854 /* Let the target reassign the RTL if it wants.
855 This is necessary, for example, when one machine specific
856 decl attribute overrides another. */
857 #ifdef REDO_SECTION_INFO_P
858 if (REDO_SECTION_INFO_P (decl))
859 ENCODE_SECTION_INFO (decl);
864 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
866 reg_number = decode_reg_name (asmspec);
867 if (reg_number == -2)
869 /* ASMSPEC is given, and not the name of a register. Mark the
870 name with a star so assemble_name won't munge it. */
871 char *starred = alloca (strlen (asmspec) + 2);
873 strcpy (starred + 1, asmspec);
877 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
879 /* First detect errors in declaring global registers. */
880 if (reg_number == -1)
881 error_with_decl (decl, "register name not specified for `%s'");
882 else if (reg_number < 0)
883 error_with_decl (decl, "invalid register name for `%s'");
884 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
885 error_with_decl (decl,
886 "data type of `%s' isn't suitable for a register");
887 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
888 error_with_decl (decl,
889 "register specified for `%s' isn't suitable for data type");
890 /* Now handle properly declared static register variables. */
895 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
897 DECL_INITIAL (decl) = 0;
898 error ("global register variable has initial value");
900 if (TREE_THIS_VOLATILE (decl))
901 warning ("volatile register variables don't work as you might wish");
903 /* If the user specified one of the eliminables registers here,
904 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
905 confused with that register and be eliminated. This usage is
906 somewhat suspect... */
908 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
909 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
910 REG_USERVAR_P (DECL_RTL (decl)) = 1;
912 if (TREE_STATIC (decl))
914 /* Make this register global, so not usable for anything
916 #ifdef ASM_DECLARE_REGISTER_GLOBAL
917 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
919 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
921 globalize_reg (reg_number + --nregs);
924 /* As a register variable, it has no section. */
929 /* Now handle ordinary static variables and functions (in memory).
930 Also handle vars declared register invalidly. */
932 if (reg_number >= 0 || reg_number == -3)
933 error_with_decl (decl,
934 "register name given for non-register variable `%s'");
936 /* Specifying a section attribute on a variable forces it into a
937 non-.bss section, and thus it cannot be common. */
938 if (TREE_CODE (decl) == VAR_DECL
939 && DECL_SECTION_NAME (decl) != NULL_TREE
940 && DECL_INITIAL (decl) == NULL_TREE
941 && DECL_COMMON (decl))
942 DECL_COMMON (decl) = 0;
944 /* Can't use just the variable's own name for a variable
945 whose scope is less than the whole file, unless it's a member
946 of a local class (which will already be unambiguous).
947 Concatenate a distinguishing number. */
948 if (!top_level && !TREE_PUBLIC (decl)
949 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
951 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
955 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
960 if (name != new_name)
962 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
963 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
966 /* If this variable is to be treated as volatile, show its
967 tree node has side effects. */
968 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
969 && TREE_PUBLIC (decl))
970 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
971 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
972 TREE_SIDE_EFFECTS (decl) = 1;
974 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
975 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
976 if (TREE_CODE (decl) != FUNCTION_DECL)
977 set_mem_attributes (x, decl, 1);
978 SET_DECL_RTL (decl, x);
980 /* Optionally set flags or add text to the name to record information
981 such as that it is a function name.
982 If the name is changed, the macro ASM_OUTPUT_LABELREF
983 will have to know how to strip this information. */
984 #ifdef ENCODE_SECTION_INFO
985 ENCODE_SECTION_INFO (decl);
989 /* Make the rtl for variable VAR be volatile.
990 Use this only for static variables. */
993 make_var_volatile (var)
996 if (GET_CODE (DECL_RTL (var)) != MEM)
999 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1002 /* Output alignment directive to align for constant expression EXP. */
1005 assemble_constant_align (exp)
1010 /* Align the location counter as required by EXP's data type. */
1011 align = TYPE_ALIGN (TREE_TYPE (exp));
1012 #ifdef CONSTANT_ALIGNMENT
1013 align = CONSTANT_ALIGNMENT (exp, align);
1016 if (align > BITS_PER_UNIT)
1018 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1022 /* Output a string of literal assembler code
1023 for an `asm' keyword used between functions. */
1026 assemble_asm (string)
1031 if (TREE_CODE (string) == ADDR_EXPR)
1032 string = TREE_OPERAND (string, 0);
1034 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1037 /* Record an element in the table of global destructors. SYMBOL is
1038 a SYMBOL_REF of the function to be called; PRIORITY is a number
1039 between 0 and MAX_INIT_PRIORITY. */
1042 default_stabs_asm_out_destructor (symbol, priority)
1044 int priority ATTRIBUTE_UNUSED;
1046 /* Tell GNU LD that this is part of the static destructor set.
1047 This will work for any system that uses stabs, most usefully
1049 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1050 assemble_name (asm_out_file, XSTR (symbol, 0));
1051 fputc ('\n', asm_out_file);
1055 default_named_section_asm_out_destructor (symbol, priority)
1059 const char *section = ".dtors";
1062 /* ??? This only works reliably with the GNU linker. */
1063 if (priority != DEFAULT_INIT_PRIORITY)
1065 sprintf (buf, ".dtors.%.5u",
1066 /* Invert the numbering so the linker puts us in the proper
1067 order; constructors are run from right to left, and the
1068 linker sorts in increasing order. */
1069 MAX_INIT_PRIORITY - priority);
1073 named_section_flags (section, SECTION_WRITE);
1074 assemble_align (POINTER_SIZE);
1075 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1078 #ifdef DTORS_SECTION_ASM_OP
1082 if (in_section != in_dtors)
1084 in_section = in_dtors;
1085 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1086 fputc ('\n', asm_out_file);
1091 default_dtor_section_asm_out_destructor (symbol, priority)
1093 int priority ATTRIBUTE_UNUSED;
1096 assemble_align (POINTER_SIZE);
1097 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1101 /* Likewise for global constructors. */
1104 default_stabs_asm_out_constructor (symbol, priority)
1106 int priority ATTRIBUTE_UNUSED;
1108 /* Tell GNU LD that this is part of the static destructor set.
1109 This will work for any system that uses stabs, most usefully
1111 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1112 assemble_name (asm_out_file, XSTR (symbol, 0));
1113 fputc ('\n', asm_out_file);
1117 default_named_section_asm_out_constructor (symbol, priority)
1121 const char *section = ".ctors";
1124 /* ??? This only works reliably with the GNU linker. */
1125 if (priority != DEFAULT_INIT_PRIORITY)
1127 sprintf (buf, ".ctors.%.5u",
1128 /* Invert the numbering so the linker puts us in the proper
1129 order; constructors are run from right to left, and the
1130 linker sorts in increasing order. */
1131 MAX_INIT_PRIORITY - priority);
1135 named_section_flags (section, SECTION_WRITE);
1136 assemble_align (POINTER_SIZE);
1137 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1140 #ifdef CTORS_SECTION_ASM_OP
1144 if (in_section != in_ctors)
1146 in_section = in_ctors;
1147 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1148 fputc ('\n', asm_out_file);
1153 default_ctor_section_asm_out_constructor (symbol, priority)
1155 int priority ATTRIBUTE_UNUSED;
1158 assemble_align (POINTER_SIZE);
1159 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1163 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1164 a non-zero value if the constant pool should be output before the
1165 start of the function, or a zero value if the pool should output
1166 after the end of the function. The default is to put it before the
1169 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1170 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1173 /* Output assembler code for the constant pool of a function and associated
1174 with defining the name of the function. DECL describes the function.
1175 NAME is the function's name. For the constant pool, we use the current
1176 constant pool data. */
1179 assemble_start_function (decl, fnname)
1185 /* The following code does not need preprocessing in the assembler. */
1189 if (CONSTANT_POOL_BEFORE_FUNCTION)
1190 output_constant_pool (fnname, decl);
1192 resolve_unique_section (decl, 0, flag_function_sections);
1193 function_section (decl);
1195 /* Tell assembler to move to target machine's alignment for functions. */
1196 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1197 if (align < force_align_functions_log)
1198 align = force_align_functions_log;
1201 ASM_OUTPUT_ALIGN (asm_out_file, align);
1204 /* Handle a user-specified function alignment.
1205 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1206 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1207 if (align_functions_log > align)
1209 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1210 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1211 align_functions_log, align_functions-1);
1213 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1217 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1218 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1221 (*debug_hooks->begin_function) (decl);
1223 /* Make function name accessible from other files, if appropriate. */
1225 if (TREE_PUBLIC (decl))
1227 if (! first_global_object_name)
1232 STRIP_NAME_ENCODING (p, fnname);
1233 name = permalloc (strlen (p) + 1);
1236 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1237 first_global_object_name = name;
1239 weak_global_object_name = name;
1242 globalize_decl (decl);
1245 /* Do any machine/system dependent processing of the function name */
1246 #ifdef ASM_DECLARE_FUNCTION_NAME
1247 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1249 /* Standard thing is just output label for the function. */
1250 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1251 #endif /* ASM_DECLARE_FUNCTION_NAME */
1254 /* Output assembler code associated with defining the size of the
1255 function. DECL describes the function. NAME is the function's name. */
1258 assemble_end_function (decl, fnname)
1262 #ifdef ASM_DECLARE_FUNCTION_SIZE
1263 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1265 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1267 output_constant_pool (fnname, decl);
1268 function_section (decl); /* need to switch back */
1271 /* Output any constants which should appear after the function. */
1272 output_after_function_constants ();
1275 /* Assemble code to leave SIZE bytes of zeros. */
1278 assemble_zeros (size)
1281 /* Do no output if -fsyntax-only. */
1282 if (flag_syntax_only)
1285 #ifdef ASM_NO_SKIP_IN_TEXT
1286 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1287 so we must output 0s explicitly in the text section. */
1288 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1291 for (i = 0; i < size; i++)
1292 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1297 ASM_OUTPUT_SKIP (asm_out_file, size);
1300 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1303 assemble_align (align)
1306 if (align > BITS_PER_UNIT)
1308 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1312 /* Assemble a string constant with the specified C string as contents. */
1315 assemble_string (p, size)
1322 /* If the string is very long, split it up. */
1326 int thissize = size - pos;
1327 if (thissize > maximum)
1330 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1338 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1339 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1340 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1342 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1343 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1344 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1346 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1347 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1351 #if defined ASM_OUTPUT_ALIGNED_BSS
1352 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1353 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1355 #if defined ASM_OUTPUT_BSS
1356 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1357 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1363 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1364 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1365 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1367 #if defined ASM_OUTPUT_ALIGNED_COMMON
1368 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1369 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1371 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1372 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1377 asm_emit_uninitialised (decl, name, size, rounded)
1380 int size ATTRIBUTE_UNUSED;
1381 int rounded ATTRIBUTE_UNUSED;
1389 destination = asm_dest_local;
1391 if (TREE_PUBLIC (decl))
1393 #if defined ASM_EMIT_BSS
1394 if (! DECL_COMMON (decl))
1395 destination = asm_dest_bss;
1398 destination = asm_dest_common;
1401 if (destination == asm_dest_bss)
1402 globalize_decl (decl);
1403 resolve_unique_section (decl, 0, flag_data_sections);
1405 if (flag_shared_data)
1407 switch (destination)
1409 #ifdef ASM_OUTPUT_SHARED_BSS
1411 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1414 #ifdef ASM_OUTPUT_SHARED_COMMON
1415 case asm_dest_common:
1416 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1419 #ifdef ASM_OUTPUT_SHARED_LOCAL
1420 case asm_dest_local:
1421 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1429 switch (destination)
1433 ASM_EMIT_BSS (decl, name, size, rounded);
1436 case asm_dest_common:
1437 ASM_EMIT_COMMON (decl, name, size, rounded);
1439 case asm_dest_local:
1440 ASM_EMIT_LOCAL (decl, name, size, rounded);
1449 /* Assemble everything that is needed for a variable or function declaration.
1450 Not used for automatic variables, and not used for function definitions.
1451 Should not be called for variables of incomplete structure type.
1453 TOP_LEVEL is nonzero if this variable has file scope.
1454 AT_END is nonzero if this is the special handling, at end of compilation,
1455 to define things that have had only tentative definitions.
1456 DONT_OUTPUT_DATA if nonzero means don't actually output the
1457 initial value (that will be done by the caller). */
1460 assemble_variable (decl, top_level, at_end, dont_output_data)
1462 int top_level ATTRIBUTE_UNUSED;
1463 int at_end ATTRIBUTE_UNUSED;
1464 int dont_output_data;
1471 last_assemble_variable_decl = 0;
1473 /* Normally no need to say anything here for external references,
1474 since assemble_external is called by the language-specific code
1475 when a declaration is first seen. */
1477 if (DECL_EXTERNAL (decl))
1480 /* Output no assembler code for a function declaration.
1481 Only definitions of functions output anything. */
1483 if (TREE_CODE (decl) == FUNCTION_DECL)
1486 /* Do nothing for global register variables. */
1487 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1489 TREE_ASM_WRITTEN (decl) = 1;
1493 /* If type was incomplete when the variable was declared,
1494 see if it is complete now. */
1496 if (DECL_SIZE (decl) == 0)
1497 layout_decl (decl, 0);
1499 /* Still incomplete => don't allocate it; treat the tentative defn
1500 (which is what it must have been) as an `extern' reference. */
1502 if (!dont_output_data && DECL_SIZE (decl) == 0)
1504 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1505 DECL_SOURCE_LINE (decl),
1506 "storage size of `%s' isn't known",
1507 IDENTIFIER_POINTER (DECL_NAME (decl)));
1508 TREE_ASM_WRITTEN (decl) = 1;
1512 /* The first declaration of a variable that comes through this function
1513 decides whether it is global (in C, has external linkage)
1514 or local (in C, has internal linkage). So do nothing more
1515 if this function has already run. */
1517 if (TREE_ASM_WRITTEN (decl))
1520 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1521 decl_rtl = DECL_RTL (decl);
1523 TREE_ASM_WRITTEN (decl) = 1;
1525 /* Do no output if -fsyntax-only. */
1526 if (flag_syntax_only)
1531 if (! dont_output_data
1532 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1534 error_with_decl (decl, "size of variable `%s' is too large");
1538 name = XSTR (XEXP (decl_rtl, 0), 0);
1539 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1540 && ! first_global_object_name
1541 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1542 || DECL_INITIAL (decl) == error_mark_node))
1543 && ! DECL_WEAK (decl)
1544 && ! DECL_ONE_ONLY (decl))
1549 STRIP_NAME_ENCODING (p, name);
1550 xname = permalloc (strlen (p) + 1);
1552 first_global_object_name = xname;
1555 /* Compute the alignment of this data. */
1557 align = DECL_ALIGN (decl);
1559 /* In the case for initialing an array whose length isn't specified,
1560 where we have not yet been able to do the layout,
1561 figure out the proper alignment now. */
1562 if (dont_output_data && DECL_SIZE (decl) == 0
1563 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1564 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1566 /* Some object file formats have a maximum alignment which they support.
1567 In particular, a.out format supports a maximum alignment of 4. */
1568 #ifndef MAX_OFILE_ALIGNMENT
1569 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1571 if (align > MAX_OFILE_ALIGNMENT)
1573 warning_with_decl (decl,
1574 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1575 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1576 align = MAX_OFILE_ALIGNMENT;
1579 /* On some machines, it is good to increase alignment sometimes. */
1580 if (! DECL_USER_ALIGN (decl))
1582 #ifdef DATA_ALIGNMENT
1583 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1585 #ifdef CONSTANT_ALIGNMENT
1586 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1587 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1591 /* Reset the alignment in case we have made it tighter, so we can benefit
1592 from it in get_pointer_alignment. */
1593 DECL_ALIGN (decl) = align;
1594 set_mem_align (decl_rtl, align);
1596 /* Handle uninitialized definitions. */
1598 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1599 /* If the target can't output uninitialized but not common global data
1600 in .bss, then we have to use .data. */
1601 #if ! defined ASM_EMIT_BSS
1602 && DECL_COMMON (decl)
1604 && DECL_SECTION_NAME (decl) == NULL_TREE
1605 && ! dont_output_data)
1607 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1608 unsigned HOST_WIDE_INT rounded = size;
1610 /* Don't allocate zero bytes of common,
1611 since that means "undefined external" in the linker. */
1615 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1616 so that each uninitialized object starts on such a boundary. */
1617 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1618 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1619 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1621 /* Don't continue this line--convex cc version 4.1 would lose. */
1622 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1623 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1625 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1628 asm_emit_uninitialised (decl, name, size, rounded);
1633 /* Handle initialized definitions.
1634 Also handle uninitialized global definitions if -fno-common and the
1635 target doesn't support ASM_OUTPUT_BSS. */
1637 /* First make the assembler name(s) global if appropriate. */
1638 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1639 globalize_decl (decl);
1641 /* Output any data that we will need to use the address of. */
1642 if (DECL_INITIAL (decl) == error_mark_node)
1643 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1644 else if (DECL_INITIAL (decl))
1645 reloc = output_addressed_constants (DECL_INITIAL (decl));
1647 /* Switch to the appropriate section. */
1648 resolve_unique_section (decl, reloc, flag_data_sections);
1649 variable_section (decl, reloc);
1651 /* dbxout.c needs to know this. */
1652 if (in_text_section ())
1653 DECL_IN_TEXT_SECTION (decl) = 1;
1655 /* Output the alignment of this data. */
1656 if (align > BITS_PER_UNIT)
1658 ASM_OUTPUT_ALIGN (asm_out_file,
1659 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1662 /* Do any machine/system dependent processing of the object. */
1663 #ifdef ASM_DECLARE_OBJECT_NAME
1664 last_assemble_variable_decl = decl;
1665 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1667 /* Standard thing is just output label for the object. */
1668 ASM_OUTPUT_LABEL (asm_out_file, name);
1669 #endif /* ASM_DECLARE_OBJECT_NAME */
1671 if (!dont_output_data)
1673 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1674 /* Output the actual data. */
1675 output_constant (DECL_INITIAL (decl),
1676 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1679 /* Leave space for it. */
1680 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1684 /* Return 1 if type TYPE contains any pointers. */
1687 contains_pointers_p (type)
1690 switch (TREE_CODE (type))
1693 case REFERENCE_TYPE:
1694 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1695 so I'll play safe and return 1. */
1701 case QUAL_UNION_TYPE:
1704 /* For a type that has fields, see if the fields have pointers. */
1705 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1706 if (TREE_CODE (fields) == FIELD_DECL
1707 && contains_pointers_p (TREE_TYPE (fields)))
1713 /* An array type contains pointers if its element type does. */
1714 return contains_pointers_p (TREE_TYPE (type));
1721 /* Output something to declare an external symbol to the assembler.
1722 (Most assemblers don't need this, so we normally output nothing.)
1723 Do nothing if DECL is not external. */
1726 assemble_external (decl)
1727 tree decl ATTRIBUTE_UNUSED;
1729 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1730 main body of this code is only rarely exercised. To provide some
1731 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1732 open. If it's not, we should not be calling this function. */
1736 #ifdef ASM_OUTPUT_EXTERNAL
1737 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1739 rtx rtl = DECL_RTL (decl);
1741 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1742 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1744 /* Some systems do require some output. */
1745 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1746 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1752 /* Similar, for calling a library function FUN. */
1755 assemble_external_libcall (fun)
1756 rtx fun ATTRIBUTE_UNUSED;
1758 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1759 /* Declare library function name external when first used, if nec. */
1760 if (! SYMBOL_REF_USED (fun))
1762 SYMBOL_REF_USED (fun) = 1;
1763 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1768 /* Declare the label NAME global. */
1771 assemble_global (name)
1772 const char *name ATTRIBUTE_UNUSED;
1774 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1777 /* Assemble a label named NAME. */
1780 assemble_label (name)
1783 ASM_OUTPUT_LABEL (asm_out_file, name);
1786 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1787 If NAME starts with a *, the rest of NAME is output verbatim.
1788 Otherwise NAME is transformed in an implementation-defined way
1789 (usually by the addition of an underscore).
1790 Many macros in the tm file are defined to call this function. */
1793 assemble_name (file, name)
1797 const char *real_name;
1800 STRIP_NAME_ENCODING (real_name, name);
1802 id = maybe_get_identifier (real_name);
1804 TREE_SYMBOL_REFERENCED (id) = 1;
1807 fputs (&name[1], file);
1809 ASM_OUTPUT_LABELREF (file, name);
1812 /* Allocate SIZE bytes writable static space with a gensym name
1813 and return an RTX to refer to its address. */
1816 assemble_static_space (size)
1820 const char *namestring;
1824 if (flag_shared_data)
1828 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1830 namestring = ggc_strdup (name);
1832 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1834 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1835 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1838 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1839 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1842 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1843 so that each uninitialized object starts on such a boundary. */
1844 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1845 int rounded ATTRIBUTE_UNUSED
1846 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1847 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1848 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1849 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1856 /* Assemble the static constant template for function entry trampolines.
1857 This is done at most once per compilation.
1858 Returns an RTX for the address of the template. */
1860 #ifdef TRAMPOLINE_TEMPLATE
1862 assemble_trampoline_template ()
1868 /* By default, put trampoline templates in read-only data section. */
1870 #ifdef TRAMPOLINE_SECTION
1871 TRAMPOLINE_SECTION ();
1873 readonly_data_section ();
1876 /* Write the assembler code to define one. */
1877 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1880 ASM_OUTPUT_ALIGN (asm_out_file, align);
1883 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1884 TRAMPOLINE_TEMPLATE (asm_out_file);
1886 /* Record the rtl to refer to it. */
1887 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1888 name = ggc_strdup (label);
1889 return gen_rtx_SYMBOL_REF (Pmode, name);
1893 /* A and B are either alignments or offsets. Return the minimum alignment
1894 that may be assumed after adding the two together. */
1896 static inline unsigned
1900 return (a | b) & -(a | b);
1903 /* Return the assembler directive for creating a given kind of integer
1904 object. SIZE is the number of bytes in the object and ALIGNED_P
1905 indicates whether it is known to be aligned. Return NULL if the
1906 assembly dialect has no such directive.
1908 The returned string should be printed at the start of a new line and
1909 be followed immediately by the object's initial value. */
1912 integer_asm_op (size, aligned_p)
1916 struct asm_int_op *ops;
1919 ops = &targetm.asm_out.aligned_op;
1921 ops = &targetm.asm_out.unaligned_op;
1926 return targetm.asm_out.byte_op;
1940 /* Use directive OP to assemble an integer object X. Print OP at the
1941 start of the line, followed immediately by the value of X. */
1944 assemble_integer_with_op (op, x)
1948 fputs (op, asm_out_file);
1949 output_addr_const (asm_out_file, x);
1950 fputc ('\n', asm_out_file);
1953 /* The default implementation of the asm_out.integer target hook. */
1956 default_assemble_integer (x, size, aligned_p)
1957 rtx x ATTRIBUTE_UNUSED;
1958 unsigned int size ATTRIBUTE_UNUSED;
1959 int aligned_p ATTRIBUTE_UNUSED;
1961 const char *op = integer_asm_op (size, aligned_p);
1962 return op && (assemble_integer_with_op (op, x), true);
1965 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1966 the alignment of the integer in bits. Return 1 if we were able to output
1967 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1971 assemble_integer (x, size, align, force)
1979 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1981 /* See if the target hook can handle this kind of object. */
1982 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1985 /* If the object is a multi-byte one, try splitting it up. Split
1986 it into words it if is multi-word, otherwise split it into bytes. */
1989 enum machine_mode omode, imode;
1990 unsigned int subalign;
1991 unsigned int subsize, i;
1993 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1994 subalign = MIN (align, subsize * BITS_PER_UNIT);
1995 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1996 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1998 for (i = 0; i < size; i += subsize)
2000 rtx partial = simplify_subreg (omode, x, imode, i);
2001 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2007 /* If we've printed some of it, but not all of it, there's no going
2020 assemble_real (d, mode, align)
2022 enum machine_mode mode;
2027 unsigned int nalign = min_align (align, 32);
2029 switch (BITS_PER_UNIT)
2035 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2036 assemble_integer (GEN_INT (l), 4, align, 1);
2039 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2040 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2041 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2044 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2045 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2046 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2047 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2050 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2051 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2052 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2053 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2054 assemble_integer (GEN_INT (data[3]), 4, nalign, 1);
2065 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2066 assemble_integer (GEN_INT (l), 2, align, 1);
2069 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2070 assemble_integer (GEN_INT (data[0]), 2, align, 1);
2071 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2082 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2083 assemble_integer (GEN_INT (l), 1, align, 1);
2086 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2087 assemble_integer (GEN_INT (data[0]), 1, align, 1);
2088 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2100 /* Here we combine duplicate floating constants to make
2101 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2103 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2104 For an integer, I0 is the low-order word and I1 is the high-order word.
2105 For a real number, I0 is the word with the low address
2106 and I1 is the word with the high address. */
2109 immed_double_const (i0, i1, mode)
2110 HOST_WIDE_INT i0, i1;
2111 enum machine_mode mode;
2115 if (GET_MODE_CLASS (mode) == MODE_INT
2116 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2118 /* We clear out all bits that don't belong in MODE, unless they and our
2119 sign bit are all one. So we get either a reasonable negative value
2120 or a reasonable unsigned value for this mode. */
2121 int width = GET_MODE_BITSIZE (mode);
2122 if (width < HOST_BITS_PER_WIDE_INT
2123 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2124 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2125 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2126 else if (width == HOST_BITS_PER_WIDE_INT
2127 && ! (i1 == ~0 && i0 < 0))
2129 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2130 /* We cannot represent this value as a constant. */
2133 /* If this would be an entire word for the target, but is not for
2134 the host, then sign-extend on the host so that the number will look
2135 the same way on the host that it would on the target.
2137 For example, when building a 64 bit alpha hosted 32 bit sparc
2138 targeted compiler, then we want the 32 bit unsigned value -1 to be
2139 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2140 The later confuses the sparc backend. */
2142 if (width < HOST_BITS_PER_WIDE_INT
2143 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2144 i0 |= ((HOST_WIDE_INT) (-1) << width);
2146 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2148 ??? Strictly speaking, this is wrong if we create a CONST_INT
2149 for a large unsigned constant with the size of MODE being
2150 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2151 wider mode. In that case we will mis-interpret it as a negative
2154 Unfortunately, the only alternative is to make a CONST_DOUBLE
2155 for any constant in any mode if it is an unsigned constant larger
2156 than the maximum signed integer in an int on the host. However,
2157 doing this will break everyone that always expects to see a CONST_INT
2158 for SImode and smaller.
2160 We have always been making CONST_INTs in this case, so nothing new
2163 if (width <= HOST_BITS_PER_WIDE_INT)
2164 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2166 /* If this integer fits in one word, return a CONST_INT. */
2167 if ((i1 == 0 && i0 >= 0)
2168 || (i1 == ~0 && i0 < 0))
2169 return GEN_INT (i0);
2171 /* We use VOIDmode for integers. */
2175 /* Search the chain for an existing CONST_DOUBLE with the right value.
2176 If one is found, return it. */
2178 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2179 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2180 && GET_MODE (r) == mode)
2183 /* No; make a new one and add it to the chain. */
2184 r = gen_rtx_CONST_DOUBLE (mode, i0, i1);
2186 /* Don't touch const_double_chain if not inside any function. */
2187 if (current_function_decl != 0)
2189 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2190 const_double_chain = r;
2196 /* Return a CONST_DOUBLE for a specified `double' value
2197 and machine mode. */
2200 immed_real_const_1 (d, mode)
2202 enum machine_mode mode;
2204 union real_extract u;
2207 /* Get the desired `double' value as a sequence of ints
2208 since that is how they are stored in a CONST_DOUBLE. */
2212 /* Detect special cases. Check for NaN first, because some ports
2213 (specifically the i386) do not emit correct ieee-fp code by default, and
2214 thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2215 and if REAL_VALUES_EQUAL does a floating point comparison. */
2216 if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_IDENTICAL (dconst0, d))
2217 return CONST0_RTX (mode);
2218 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2219 return CONST1_RTX (mode);
2220 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst2, d))
2221 return CONST2_RTX (mode);
2223 if (sizeof u == sizeof (HOST_WIDE_INT))
2224 return immed_double_const (u.i[0], 0, mode);
2225 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2226 return immed_double_const (u.i[0], u.i[1], mode);
2228 /* The rest of this function handles the case where
2229 a float value requires more than 2 ints of space.
2230 It will be deleted as dead code on machines that don't need it. */
2232 /* Search the chain for an existing CONST_DOUBLE with the right value.
2233 If one is found, return it. */
2235 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2236 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2237 && GET_MODE (r) == mode)
2240 /* No; make a new one and add it to the chain.
2242 We may be called by an optimizer which may be discarding any memory
2243 allocated during its processing (such as combine and loop). However,
2244 we will be leaving this constant on the chain, so we cannot tolerate
2246 r = rtx_alloc (CONST_DOUBLE);
2248 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2250 /* If we aren't inside a function, don't put r on the
2251 const_double_chain. */
2252 if (current_function_decl != 0)
2254 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2255 const_double_chain = r;
2258 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2263 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2264 which must be a REAL_CST tree node. */
2267 immed_real_const (exp)
2270 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2273 /* At the end of a function, forget the memory-constants
2274 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2275 Also clear out real_constant_chain and clear out all the chain-pointers. */
2278 clear_const_double_mem ()
2282 for (r = const_double_chain; r; r = next)
2284 next = CONST_DOUBLE_CHAIN (r);
2285 CONST_DOUBLE_CHAIN (r) = 0;
2287 const_double_chain = 0;
2290 /* Given an expression EXP with a constant value,
2291 reduce it to the sum of an assembler symbol and an integer.
2292 Store them both in the structure *VALUE.
2293 Abort if EXP does not reduce. */
2298 HOST_WIDE_INT offset;
2302 decode_addr_const (exp, value)
2304 struct addr_const *value;
2306 tree target = TREE_OPERAND (exp, 0);
2312 if (TREE_CODE (target) == COMPONENT_REF
2313 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2316 offset += int_byte_position (TREE_OPERAND (target, 1));
2317 target = TREE_OPERAND (target, 0);
2319 else if (TREE_CODE (target) == ARRAY_REF
2320 || TREE_CODE (target) == ARRAY_RANGE_REF)
2322 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2323 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2324 target = TREE_OPERAND (target, 0);
2330 switch (TREE_CODE (target))
2334 x = DECL_RTL (target);
2338 x = gen_rtx_MEM (FUNCTION_MODE,
2339 gen_rtx_LABEL_REF (VOIDmode,
2340 label_rtx (TREE_OPERAND (exp, 0))));
2348 /* This constant should have been output already, but we can't simply
2349 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2350 x = output_constant_def (target, 1);
2357 if (GET_CODE (x) != MEM)
2362 value->offset = offset;
2365 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2366 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_INT, RTX_VECTOR, RTX_UNSPEC };
2369 ENUM_BITFIELD(kind) kind : 16;
2370 ENUM_BITFIELD(machine_mode) mode : 16;
2372 union real_extract du;
2373 struct addr_const addr;
2374 struct {HOST_WIDE_INT high, low;} di;
2376 /* The max vector size we have is 8 wide. This should be enough. */
2377 HOST_WIDE_INT veclo[16];
2378 HOST_WIDE_INT vechi[16];
2382 /* Uniquize all constants that appear in memory.
2383 Each constant in memory thus far output is recorded
2384 in `const_hash_table' with a `struct constant_descriptor'
2385 that contains a polish representation of the value of
2388 We cannot store the trees in the hash table
2389 because the trees may be temporary. */
2391 struct constant_descriptor
2393 struct constant_descriptor *next;
2396 /* Make sure the data is reasonably aligned. */
2399 unsigned char contents[1];
2400 #ifdef HAVE_LONG_DOUBLE
2409 #define MAX_HASH_TABLE 1009
2410 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2412 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2413 out a string constant, we defer output of the constants until we know
2414 they are actually used. This will be if something takes its address or if
2415 there is a usage of the string in the RTL of a function. */
2417 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2419 struct deferred_string
2426 static htab_t const_str_htab;
2428 /* Mark a const_hash_table descriptor for GC. */
2431 mark_const_hash_entry (ptr)
2434 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2438 ggc_mark_rtx (desc->rtl);
2443 /* Mark the hash-table element X (which is really a pointer to an
2444 struct deferred_string *). */
2447 mark_const_str_htab_1 (x, data)
2449 void *data ATTRIBUTE_UNUSED;
2451 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2455 /* Mark a const_str_htab for GC. */
2458 mark_const_str_htab (htab)
2461 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2464 /* Returns a hash code for X (which is a really a
2465 struct deferred_string *). */
2468 const_str_htab_hash (x)
2471 return STRHASH (((const struct deferred_string *) x)->label);
2474 /* Returns non-zero if the value represented by X (which is really a
2475 struct deferred_string *) is the same as that given by Y
2476 (which is really a char *). */
2479 const_str_htab_eq (x, y)
2483 return (((const struct deferred_string *) x)->label == (const char *) y);
2486 /* Delete the hash table entry dfsp. */
2489 const_str_htab_del (dfsp)
2495 /* Compute a hash code for a constant expression. */
2503 enum tree_code code = TREE_CODE (exp);
2505 /* Either set P and LEN to the address and len of something to hash and
2506 exit the switch or return a value. */
2511 p = (char *) &TREE_INT_CST (exp);
2512 len = sizeof TREE_INT_CST (exp);
2516 p = (char *) &TREE_REAL_CST (exp);
2517 len = sizeof TREE_REAL_CST (exp);
2521 p = TREE_STRING_POINTER (exp);
2522 len = TREE_STRING_LENGTH (exp);
2526 return (const_hash (TREE_REALPART (exp)) * 5
2527 + const_hash (TREE_IMAGPART (exp)));
2530 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2534 len = int_size_in_bytes (TREE_TYPE (exp));
2535 tmp = (char *) alloca (len);
2536 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2544 /* For record type, include the type in the hashing.
2545 We do not do so for array types
2546 because (1) the sizes of the elements are sufficient
2547 and (2) distinct array types can have the same constructor.
2548 Instead, we include the array size because the constructor could
2550 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2551 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2554 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2555 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2557 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2558 if (TREE_VALUE (link))
2560 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2568 struct addr_const value;
2570 decode_addr_const (exp, &value);
2571 if (GET_CODE (value.base) == SYMBOL_REF)
2573 /* Don't hash the address of the SYMBOL_REF;
2574 only use the offset and the symbol name. */
2576 p = XSTR (value.base, 0);
2577 for (i = 0; p[i] != 0; i++)
2578 hi = ((hi * 613) + (unsigned) (p[i]));
2580 else if (GET_CODE (value.base) == LABEL_REF)
2581 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2585 hi &= (1 << HASHBITS) - 1;
2586 hi %= MAX_HASH_TABLE;
2592 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2593 + const_hash (TREE_OPERAND (exp, 1)));
2597 case NON_LVALUE_EXPR:
2598 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2601 /* A language specific constant. Just hash the code. */
2602 return (int) code % MAX_HASH_TABLE;
2605 /* Compute hashing function */
2607 for (i = 0; i < len; i++)
2608 hi = ((hi * 613) + (unsigned) (p[i]));
2610 hi &= (1 << HASHBITS) - 1;
2611 hi %= MAX_HASH_TABLE;
2615 /* Compare a constant expression EXP with a constant-descriptor DESC.
2616 Return 1 if DESC describes a constant with the same value as EXP. */
2619 compare_constant (exp, desc)
2621 struct constant_descriptor *desc;
2623 return 0 != compare_constant_1 (exp, desc->u.contents);
2626 /* Compare constant expression EXP with a substring P of a constant descriptor.
2627 If they match, return a pointer to the end of the substring matched.
2628 If they do not match, return 0.
2630 Since descriptors are written in polish prefix notation,
2631 this function can be used recursively to test one operand of EXP
2632 against a subdescriptor, and if it succeeds it returns the
2633 address of the subdescriptor for the next operand. */
2635 static const unsigned char *
2636 compare_constant_1 (exp, p)
2638 const unsigned char *p;
2640 const unsigned char *strp;
2642 enum tree_code code = TREE_CODE (exp);
2644 if (code != (enum tree_code) *p++)
2647 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2648 switch, or return the result of the comparison. */
2653 /* Integer constants are the same only if the same width of type. */
2654 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2657 strp = (unsigned char *) &TREE_INT_CST (exp);
2658 len = sizeof TREE_INT_CST (exp);
2662 /* Real constants are the same only if the same width of type. */
2663 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2666 strp = (unsigned char *) &TREE_REAL_CST (exp);
2667 len = sizeof TREE_REAL_CST (exp);
2671 if (flag_writable_strings)
2674 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2677 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2678 len = TREE_STRING_LENGTH (exp);
2679 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2680 sizeof TREE_STRING_LENGTH (exp)))
2683 p += sizeof TREE_STRING_LENGTH (exp);
2687 p = compare_constant_1 (TREE_REALPART (exp), p);
2691 return compare_constant_1 (TREE_IMAGPART (exp), p);
2694 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2696 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2697 unsigned char *tmp = (unsigned char *) alloca (len);
2699 get_set_constructor_bytes (exp, tmp, len);
2700 strp = (unsigned char *) tmp;
2701 if (memcmp ((char *) &xlen, p, sizeof xlen))
2710 int length = list_length (CONSTRUCTOR_ELTS (exp));
2712 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2713 int have_purpose = 0;
2715 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2716 if (TREE_PURPOSE (link))
2719 if (memcmp ((char *) &length, p, sizeof length))
2724 /* For record constructors, insist that the types match.
2725 For arrays, just verify both constructors are for arrays.
2726 Then insist that either both or none have any TREE_PURPOSE
2728 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2729 type = TREE_TYPE (exp);
2733 if (memcmp ((char *) &type, p, sizeof type))
2736 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2738 if (memcmp ((char *) &mode, p, sizeof mode))
2746 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2749 p += sizeof have_purpose;
2751 /* For arrays, insist that the size in bytes match. */
2752 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2754 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2756 if (memcmp ((char *) &size, p, sizeof size))
2762 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2764 if (TREE_VALUE (link))
2766 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2773 if (memcmp ((char *) &zero, p, sizeof zero))
2779 if (TREE_PURPOSE (link)
2780 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2782 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2783 sizeof TREE_PURPOSE (link)))
2786 p += sizeof TREE_PURPOSE (link);
2788 else if (TREE_PURPOSE (link))
2790 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2793 else if (have_purpose)
2797 if (memcmp ((char *) &zero, p, sizeof zero))
2810 struct addr_const value;
2812 decode_addr_const (exp, &value);
2813 strp = (unsigned char *) &value.offset;
2814 len = sizeof value.offset;
2815 /* Compare the offset. */
2817 if (*p++ != *strp++)
2820 /* Compare symbol name. */
2821 strp = (const unsigned char *) XSTR (value.base, 0);
2822 len = strlen ((const char *) strp) + 1;
2829 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2833 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2837 case NON_LVALUE_EXPR:
2838 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2842 tree new = (*lang_hooks.expand_constant) (exp);
2845 return compare_constant_1 (new, p);
2851 /* Compare constant contents. */
2853 if (*p++ != *strp++)
2859 /* Construct a constant descriptor for the expression EXP.
2860 It is up to the caller to enter the descriptor in the hash table. */
2862 static struct constant_descriptor *
2863 record_constant (exp)
2866 struct constant_descriptor *next = 0;
2871 /* Make a struct constant_descriptor. The first three pointers will
2872 be filled in later. Here we just leave space for them. */
2874 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2875 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2876 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2878 /* Align the descriptor for the data payload. */
2879 pad = (offsetof (struct constant_descriptor, u)
2880 - offsetof(struct constant_descriptor, rtl)
2881 - sizeof(next->rtl));
2883 obstack_blank (&permanent_obstack, pad);
2885 record_constant_1 (exp);
2886 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2889 /* Add a description of constant expression EXP
2890 to the object growing in `permanent_obstack'.
2891 No need to return its address; the caller will get that
2892 from the obstack when the object is complete. */
2895 record_constant_1 (exp)
2898 const unsigned char *strp;
2900 enum tree_code code = TREE_CODE (exp);
2902 obstack_1grow (&permanent_obstack, (unsigned int) code);
2907 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2908 strp = (unsigned char *) &TREE_INT_CST (exp);
2909 len = sizeof TREE_INT_CST (exp);
2913 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2914 strp = (unsigned char *) &TREE_REAL_CST (exp);
2915 len = sizeof TREE_REAL_CST (exp);
2919 if (flag_writable_strings)
2922 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2923 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2924 len = TREE_STRING_LENGTH (exp);
2925 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2926 sizeof TREE_STRING_LENGTH (exp));
2930 record_constant_1 (TREE_REALPART (exp));
2931 record_constant_1 (TREE_IMAGPART (exp));
2935 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2937 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2938 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2939 obstack_blank (&permanent_obstack, nbytes);
2940 get_set_constructor_bytes
2941 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2948 int length = list_length (CONSTRUCTOR_ELTS (exp));
2949 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2951 int have_purpose = 0;
2953 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2954 if (TREE_PURPOSE (link))
2957 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2959 /* For record constructors, insist that the types match.
2960 For arrays, just verify both constructors are for arrays
2961 of the same mode. Then insist that either both or none
2962 have any TREE_PURPOSE values. */
2963 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2964 type = TREE_TYPE (exp);
2968 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2969 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2970 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2972 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2973 sizeof have_purpose);
2975 /* For arrays, insist that the size in bytes match. */
2976 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2978 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2979 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2982 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2984 if (TREE_VALUE (link))
2985 record_constant_1 (TREE_VALUE (link));
2990 obstack_grow (&permanent_obstack,
2991 (char *) &zero, sizeof zero);
2994 if (TREE_PURPOSE (link)
2995 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2996 obstack_grow (&permanent_obstack,
2997 (char *) &TREE_PURPOSE (link),
2998 sizeof TREE_PURPOSE (link));
2999 else if (TREE_PURPOSE (link))
3000 record_constant_1 (TREE_PURPOSE (link));
3001 else if (have_purpose)
3005 obstack_grow (&permanent_obstack,
3006 (char *) &zero, sizeof zero);
3014 struct addr_const value;
3016 decode_addr_const (exp, &value);
3017 /* Record the offset. */
3018 obstack_grow (&permanent_obstack,
3019 (char *) &value.offset, sizeof value.offset);
3021 switch (GET_CODE (value.base))
3024 /* Record the symbol name. */
3025 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3026 strlen (XSTR (value.base, 0)) + 1);
3029 /* Record the address of the CODE_LABEL. It may not have
3030 been emitted yet, so it's UID may be zero. But pointer
3031 identity is good enough. */
3032 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3044 record_constant_1 (TREE_OPERAND (exp, 0));
3045 record_constant_1 (TREE_OPERAND (exp, 1));
3050 case NON_LVALUE_EXPR:
3051 record_constant_1 (TREE_OPERAND (exp, 0));
3056 tree new = (*lang_hooks.expand_constant) (exp);
3059 record_constant_1 (new);
3064 /* Record constant contents. */
3065 obstack_grow (&permanent_obstack, strp, len);
3068 /* Record a list of constant expressions that were passed to
3069 output_constant_def but that could not be output right away. */
3071 struct deferred_constant
3073 struct deferred_constant *next;
3079 static struct deferred_constant *deferred_constants;
3081 /* Another list of constants which should be output after the
3083 static struct deferred_constant *after_function_constants;
3085 /* Nonzero means defer output of addressed subconstants
3086 (i.e., those for which output_constant_def is called.) */
3087 static int defer_addressed_constants_flag;
3089 /* Start deferring output of subconstants. */
3092 defer_addressed_constants ()
3094 defer_addressed_constants_flag++;
3097 /* Stop deferring output of subconstants,
3098 and output now all those that have been deferred. */
3101 output_deferred_addressed_constants ()
3103 struct deferred_constant *p, *next;
3105 defer_addressed_constants_flag--;
3107 if (defer_addressed_constants_flag > 0)
3110 for (p = deferred_constants; p; p = next)
3112 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3117 deferred_constants = 0;
3120 /* Output any constants which should appear after a function. */
3123 output_after_function_constants ()
3125 struct deferred_constant *p, *next;
3127 for (p = after_function_constants; p; p = next)
3129 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3134 after_function_constants = 0;
3137 /* Make a copy of the whole tree structure for a constant.
3138 This handles the same types of nodes that compare_constant
3139 and record_constant handle. */
3145 switch (TREE_CODE (exp))
3148 /* For ADDR_EXPR, we do not want to copy the decl whose address
3149 is requested. We do want to copy constants though. */
3150 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3151 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3152 copy_constant (TREE_OPERAND (exp, 0)));
3154 return copy_node (exp);
3159 return copy_node (exp);
3162 return build_complex (TREE_TYPE (exp),
3163 copy_constant (TREE_REALPART (exp)),
3164 copy_constant (TREE_IMAGPART (exp)));
3168 return build (TREE_CODE (exp), TREE_TYPE (exp),
3169 copy_constant (TREE_OPERAND (exp, 0)),
3170 copy_constant (TREE_OPERAND (exp, 1)));
3174 case NON_LVALUE_EXPR:
3175 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3176 copy_constant (TREE_OPERAND (exp, 0)));
3180 tree copy = copy_node (exp);
3181 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3184 CONSTRUCTOR_ELTS (copy) = list;
3185 for (tail = list; tail; tail = TREE_CHAIN (tail))
3186 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3187 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3188 for (tail = list; tail; tail = TREE_CHAIN (tail))
3189 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3199 /* Return an rtx representing a reference to constant data in memory
3200 for the constant expression EXP.
3202 If assembler code for such a constant has already been output,
3203 return an rtx to refer to it.
3204 Otherwise, output such a constant in memory (or defer it for later)
3205 and generate an rtx for it.
3207 If DEFER is non-zero, the output of string constants can be deferred
3208 and output only if referenced in the function after all optimizations.
3210 The TREE_CST_RTL of EXP is set up to point to that rtx.
3211 The const_hash_table records which constants already have label strings. */
3214 output_constant_def (exp, defer)
3219 struct constant_descriptor *desc;
3220 struct deferred_string **defstr;
3224 int after_function = 0;
3228 /* We can't just use the saved RTL if this is a defererred string constant
3229 and we are not to defer anymode. */
3230 if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3231 && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3232 return TREE_CST_RTL (exp);
3234 /* Make sure any other constants whose addresses appear in EXP
3235 are assigned label numbers. */
3237 reloc = output_addressed_constants (exp);
3239 /* Compute hash code of EXP. Search the descriptors for that hash code
3240 to see if any of them describes EXP. If yes, the descriptor records
3241 the label number already assigned. */
3243 hash = const_hash (exp) % MAX_HASH_TABLE;
3245 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3246 if (compare_constant (exp, desc))
3251 /* No constant equal to EXP is known to have been output.
3252 Make a constant descriptor to enter EXP in the hash table.
3253 Assign the label number and record it in the descriptor for
3254 future calls to this function to find. */
3256 /* Create a string containing the label name, in LABEL. */
3257 labelno = const_labelno++;
3258 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3260 desc = record_constant (exp);
3261 desc->next = const_hash_table[hash];
3262 desc->label = ggc_strdup (label);
3263 const_hash_table[hash] = desc;
3265 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3267 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3268 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3270 set_mem_attributes (rtl, exp, 1);
3271 set_mem_alias_set (rtl, 0);
3272 set_mem_alias_set (rtl, const_alias_set);
3279 if (TREE_CODE (exp) != INTEGER_CST)
3280 TREE_CST_RTL (exp) = rtl;
3282 /* Optionally set flags or add text to the name to record information
3283 such as that it is a function name. If the name is changed, the macro
3284 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3285 #ifdef ENCODE_SECTION_INFO
3286 /* A previously-processed constant would already have section info
3290 /* Take care not to invoque ENCODE_SECTION_INFO for constants
3291 which don't have a TREE_CST_RTL. */
3292 if (TREE_CODE (exp) != INTEGER_CST)
3293 ENCODE_SECTION_INFO (exp);
3296 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3300 #ifdef CONSTANT_AFTER_FUNCTION_P
3301 if (current_function_decl != 0
3302 && CONSTANT_AFTER_FUNCTION_P (exp))
3307 && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3308 && (!defer || defer_addressed_constants_flag || after_function))
3310 defstr = (struct deferred_string **)
3311 htab_find_slot_with_hash (const_str_htab, desc->label,
3312 STRHASH (desc->label), NO_INSERT);
3315 /* If the string is currently deferred but we need to output it now,
3316 remove it from deferred string hash table. */
3318 labelno = (*defstr)->labelno;
3319 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3320 htab_clear_slot (const_str_htab, (void **) defstr);
3324 /* If this is the first time we've seen this particular constant,
3325 output it (or defer its output for later). */
3328 if (defer_addressed_constants_flag || after_function)
3330 struct deferred_constant *p
3331 = (struct deferred_constant *)
3332 xmalloc (sizeof (struct deferred_constant));
3334 p->exp = copy_constant (exp);
3336 p->labelno = labelno;
3339 p->next = after_function_constants;
3340 after_function_constants = p;
3344 p->next = deferred_constants;
3345 deferred_constants = p;
3350 /* Do no output if -fsyntax-only. */
3351 if (! flag_syntax_only)
3353 if (TREE_CODE (exp) != STRING_CST
3355 || flag_writable_strings
3356 || (defstr = (struct deferred_string **)
3357 htab_find_slot_with_hash (const_str_htab,
3359 STRHASH (desc->label),
3361 output_constant_def_contents (exp, reloc, labelno);
3364 struct deferred_string *p;
3366 p = (struct deferred_string *)
3367 xmalloc (sizeof (struct deferred_string));
3369 p->exp = copy_constant (exp);
3370 p->label = desc->label;
3371 p->labelno = labelno;
3373 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3382 /* Now output assembler code to define the label for EXP,
3383 and follow it with the data of EXP. */
3386 output_constant_def_contents (exp, reloc, labelno)
3393 /* Align the location counter as required by EXP's data type. */
3394 align = TYPE_ALIGN (TREE_TYPE (exp));
3395 #ifdef CONSTANT_ALIGNMENT
3396 align = CONSTANT_ALIGNMENT (exp, align);
3399 if (IN_NAMED_SECTION (exp))
3400 named_section (exp, NULL, reloc);
3403 /* First switch to text section, except for writable strings. */
3404 #ifdef SELECT_SECTION
3405 SELECT_SECTION (exp, reloc, align);
3407 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3408 || (flag_pic && reloc))
3411 readonly_data_section ();
3415 if (align > BITS_PER_UNIT)
3417 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3420 /* Output the label itself. */
3421 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3423 /* Output the value of EXP. */
3424 output_constant (exp,
3425 (TREE_CODE (exp) == STRING_CST
3426 ? MAX (TREE_STRING_LENGTH (exp),
3427 int_size_in_bytes (TREE_TYPE (exp)))
3428 : int_size_in_bytes (TREE_TYPE (exp))),
3433 /* Structure to represent sufficient information about a constant so that
3434 it can be output when the constant pool is output, so that function
3435 integration can be done, and to simplify handling on machines that reference
3436 constant pool as base+displacement. */
3438 struct pool_constant
3440 struct constant_descriptor *desc;
3441 struct pool_constant *next, *next_sym;
3443 enum machine_mode mode;
3446 HOST_WIDE_INT offset;
3450 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3451 The argument is XSTR (... , 0) */
3453 #define SYMHASH(LABEL) \
3454 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3456 /* Initialize constant pool hashing for a new function. */
3459 init_varasm_status (f)
3462 struct varasm_status *p;
3463 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3465 p->x_const_rtx_hash_table
3466 = ((struct constant_descriptor **)
3467 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3468 p->x_const_rtx_sym_hash_table
3469 = ((struct pool_constant **)
3470 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3472 p->x_first_pool = p->x_last_pool = 0;
3473 p->x_pool_offset = 0;
3474 p->x_const_double_chain = 0;
3477 /* Mark PC for GC. */
3480 mark_pool_constant (pc)
3481 struct pool_constant *pc;
3486 ggc_mark_rtx (pc->constant);
3487 ggc_mark_rtx (pc->desc->rtl);
3492 /* Mark P for GC. */
3495 mark_varasm_status (p)
3496 struct varasm_status *p;
3501 mark_pool_constant (p->x_first_pool);
3502 ggc_mark_rtx (p->x_const_double_chain);
3505 /* Clear out all parts of the state in F that can safely be discarded
3506 after the function has been compiled, to let garbage collection
3507 reclaim the memory. */
3510 free_varasm_status (f)
3513 struct varasm_status *p;
3518 /* Clear out the hash tables. */
3519 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3521 struct constant_descriptor *cd;
3523 cd = p->x_const_rtx_hash_table[i];
3526 struct constant_descriptor *next = cd->next;
3533 free (p->x_const_rtx_hash_table);
3534 free (p->x_const_rtx_sym_hash_table);
3541 /* Express an rtx for a constant integer (perhaps symbolic)
3542 as the sum of a symbol or label plus an explicit integer.
3543 They are stored into VALUE. */
3546 decode_rtx_const (mode, x, value)
3547 enum machine_mode mode;
3549 struct rtx_const *value;
3551 /* Clear the whole structure, including any gaps. */
3552 memset (value, 0, sizeof (struct rtx_const));
3554 value->kind = RTX_INT; /* Most usual kind. */
3557 switch (GET_CODE (x))
3560 value->kind = RTX_DOUBLE;
3561 if (GET_MODE (x) != VOIDmode)
3563 value->mode = GET_MODE (x);
3564 memcpy ((char *) &value->un.du,
3565 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3569 value->un.di.low = CONST_DOUBLE_LOW (x);
3570 value->un.di.high = CONST_DOUBLE_HIGH (x);
3579 units = CONST_VECTOR_NUNITS (x);
3580 value->kind = RTX_VECTOR;
3583 for (i = 0; i < units; ++i)
3585 elt = CONST_VECTOR_ELT (x, i);
3586 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
3588 value->un.veclo[i] = (HOST_WIDE_INT) INTVAL (elt);
3589 value->un.vechi[i] = 0;
3591 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3593 value->un.veclo[i] = (HOST_WIDE_INT) CONST_DOUBLE_LOW (elt);
3594 value->un.vechi[i] = (HOST_WIDE_INT) CONST_DOUBLE_HIGH (elt);
3603 value->un.addr.offset = INTVAL (x);
3609 value->un.addr.base = x;
3614 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3616 value->un.addr.base = XEXP (x, 0);
3617 value->un.addr.offset = INTVAL (XEXP (x, 1));
3619 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3621 value->un.addr.base = XEXP (x, 0);
3622 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3626 value->un.addr.base = x;
3627 value->un.addr.offset = 0;
3632 value->kind = RTX_UNKNOWN;
3636 if (value->kind == RTX_INT && value->un.addr.base != 0
3637 && GET_CODE (value->un.addr.base) == UNSPEC)
3639 /* For a simple UNSPEC, the base is set to the
3640 operand, the kind field is set to the index of
3641 the unspec expression.
3642 Together with the code below, in case that
3643 the operand is a SYMBOL_REF or LABEL_REF,
3644 the address of the string or the code_label
3645 is taken as base. */
3646 if (XVECLEN (value->un.addr.base, 0) == 1)
3648 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
3649 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
3653 if (value->kind > RTX_DOUBLE && value->un.addr.base != 0)
3654 switch (GET_CODE (value->un.addr.base))
3657 /* Use the string's address, not the SYMBOL_REF's address,
3658 for the sake of addresses of library routines. */
3659 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3663 /* For a LABEL_REF, compare labels. */
3664 value->un.addr.base = XEXP (value->un.addr.base, 0);
3671 /* Given a MINUS expression, simplify it if both sides
3672 include the same symbol. */
3675 simplify_subtraction (x)
3678 struct rtx_const val0, val1;
3680 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3681 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3683 if (val0.kind > RTX_DOUBLE
3684 && val0.kind == val1.kind
3685 && val0.un.addr.base == val1.un.addr.base)
3686 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3691 /* Compute a hash code for a constant RTL expression. */
3694 const_hash_rtx (mode, x)
3695 enum machine_mode mode;
3701 struct rtx_const value;
3702 decode_rtx_const (mode, x, &value);
3704 /* Compute hashing function */
3706 for (i = 0; i < sizeof value / sizeof (int); i++)
3707 hi += ((int *) &value)[i];
3709 hi &= (1 << HASHBITS) - 1;
3710 hi %= MAX_RTX_HASH_TABLE;
3714 /* Compare a constant rtl object X with a constant-descriptor DESC.
3715 Return 1 if DESC describes a constant with the same value as X. */
3718 compare_constant_rtx (mode, x, desc)
3719 enum machine_mode mode;
3721 struct constant_descriptor *desc;
3723 int *p = (int *) desc->u.contents;
3726 struct rtx_const value;
3728 decode_rtx_const (mode, x, &value);
3729 strp = (int *) &value;
3730 len = sizeof value / sizeof (int);
3732 /* Compare constant contents. */
3734 if (*p++ != *strp++)
3740 /* Construct a constant descriptor for the rtl-expression X.
3741 It is up to the caller to enter the descriptor in the hash table. */
3743 static struct constant_descriptor *
3744 record_constant_rtx (mode, x)
3745 enum machine_mode mode;
3748 struct constant_descriptor *ptr;
3750 ptr = ((struct constant_descriptor *)
3751 xcalloc (1, (offsetof (struct constant_descriptor, u)
3752 + sizeof (struct rtx_const))));
3753 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3758 /* Given a constant rtx X, return a MEM for the location in memory at which
3759 this constant has been placed. Return 0 if it not has been placed yet. */
3762 mem_for_const_double (x)
3765 enum machine_mode mode = GET_MODE (x);
3766 struct constant_descriptor *desc;
3768 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3770 if (compare_constant_rtx (mode, x, desc))
3776 /* Given a constant rtx X, make (or find) a memory constant for its value
3777 and return a MEM rtx to refer to it in memory. */
3780 force_const_mem (mode, x)
3781 enum machine_mode mode;
3785 struct constant_descriptor *desc;
3788 struct pool_constant *pool;
3791 /* Compute hash code of X. Search the descriptors for that hash code
3792 to see if any of them describes X. If yes, we have an rtx to use. */
3793 hash = const_hash_rtx (mode, x);
3794 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3795 if (compare_constant_rtx (mode, x, desc))
3798 /* No constant equal to X is known to have been output.
3799 Make a constant descriptor to enter X in the hash table
3800 and make a MEM for it. */
3801 desc = record_constant_rtx (mode, x);
3802 desc->next = const_rtx_hash_table[hash];
3803 const_rtx_hash_table[hash] = desc;
3805 /* Align the location counter as required by EXP's data type. */
3806 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3807 #ifdef CONSTANT_ALIGNMENT
3808 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x), align);
3811 pool_offset += (align / BITS_PER_UNIT) - 1;
3812 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3814 if (GET_CODE (x) == LABEL_REF)
3815 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3817 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3818 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3822 pool->labelno = const_labelno;
3823 pool->align = align;
3824 pool->offset = pool_offset;
3831 last_pool->next = pool;
3834 pool_offset += GET_MODE_SIZE (mode);
3836 /* Create a string containing the label name, in LABEL. */
3837 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3841 /* Construct the SYMBOL_REF and the MEM. */
3843 pool->desc->rtl = def
3844 = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3845 set_mem_alias_set (def, const_alias_set);
3846 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3847 RTX_UNCHANGING_P (def) = 1;
3849 /* Add label to symbol hash table. */
3850 hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3851 pool->next_sym = const_rtx_sym_hash_table[hash];
3852 const_rtx_sym_hash_table[hash] = pool;
3854 /* Mark the symbol_ref as belonging to this constants pool. */
3855 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3856 current_function_uses_const_pool = 1;
3861 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3862 the corresponding pool_constant structure. */
3864 static struct pool_constant *
3865 find_pool_constant (f, addr)
3869 struct pool_constant *pool;
3870 const char *label = XSTR (addr, 0);
3872 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3873 pool = pool->next_sym)
3874 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3880 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3883 get_pool_constant (addr)
3886 return (find_pool_constant (cfun, addr))->constant;
3889 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3890 and whether it has been output or not. */
3893 get_pool_constant_mark (addr, pmarked)
3897 struct pool_constant *pool = find_pool_constant (cfun, addr);
3898 *pmarked = (pool->mark != 0);
3899 return pool->constant;
3902 /* Likewise, but for the constant pool of a specific function. */
3905 get_pool_constant_for_function (f, addr)
3909 return (find_pool_constant (f, addr))->constant;
3912 /* Similar, return the mode. */
3915 get_pool_mode (addr)
3918 return (find_pool_constant (cfun, addr))->mode;
3922 get_pool_mode_for_function (f, addr)
3926 return (find_pool_constant (f, addr))->mode;
3929 /* Similar, return the offset in the constant pool. */
3932 get_pool_offset (addr)
3935 return (find_pool_constant (cfun, addr))->offset;
3938 /* Return the size of the constant pool. */
3946 /* Write all the constants in the constant pool. */
3949 output_constant_pool (fnname, fndecl)
3950 const char *fnname ATTRIBUTE_UNUSED;
3951 tree fndecl ATTRIBUTE_UNUSED;
3953 struct pool_constant *pool;
3955 union real_extract u;
3957 /* It is possible for gcc to call force_const_mem and then to later
3958 discard the instructions which refer to the constant. In such a
3959 case we do not need to output the constant. */
3960 mark_constant_pool ();
3962 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3963 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3966 for (pool = first_pool; pool; pool = pool->next)
3975 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3976 whose CODE_LABEL has been deleted. This can occur if a jump table
3977 is eliminated by optimization. If so, write a constant of zero
3978 instead. Note that this can also happen by turning the
3979 CODE_LABEL into a NOTE. */
3980 /* ??? This seems completely and utterly wrong. Certainly it's
3981 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3982 functioning even with INSN_DELETED_P and friends. */
3985 switch (GET_CODE (x))
3988 if (GET_CODE (XEXP (x, 0)) != PLUS
3989 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3991 tmp = XEXP (XEXP (x, 0), 0);
3996 if (INSN_DELETED_P (tmp)
3997 || (GET_CODE (tmp) == NOTE
3998 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
4009 /* First switch to correct section. */
4010 #ifdef SELECT_RTX_SECTION
4011 SELECT_RTX_SECTION (pool->mode, x, pool->align);
4013 readonly_data_section ();
4016 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4017 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4018 pool->align, pool->labelno, done);
4021 assemble_align (pool->align);
4023 /* Output the label. */
4024 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4026 /* Output the value of the constant itself. */
4027 switch (GET_MODE_CLASS (pool->mode))
4030 if (GET_CODE (x) != CONST_DOUBLE)
4033 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4034 assemble_real (u.d, pool->mode, pool->align);
4038 case MODE_PARTIAL_INT:
4039 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4042 case MODE_VECTOR_FLOAT:
4047 if (GET_CODE (x) != CONST_VECTOR)
4050 units = CONST_VECTOR_NUNITS (x);
4052 for (i = 0; i < units; i++)
4054 elt = CONST_VECTOR_ELT (x, i);
4055 memcpy ((char *) &u,
4056 (char *) &CONST_DOUBLE_LOW (elt),
4058 assemble_real (u.d, GET_MODE_INNER (pool->mode), pool->align);
4063 case MODE_VECTOR_INT:
4068 if (GET_CODE (x) != CONST_VECTOR)
4071 units = CONST_VECTOR_NUNITS (x);
4073 for (i = 0; i < units; i++)
4075 elt = CONST_VECTOR_ELT (x, i);
4076 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
4086 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4091 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4092 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4095 /* Done with this pool. */
4096 first_pool = last_pool = 0;
4099 /* Look through the instructions for this function, and mark all the
4100 entries in the constant pool which are actually being used.
4101 Emit used deferred strings. */
4104 mark_constant_pool ()
4107 struct pool_constant *pool;
4109 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4112 for (pool = first_pool; pool; pool = pool->next)
4115 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4117 mark_constants (PATTERN (insn));
4119 for (insn = current_function_epilogue_delay_list;
4121 insn = XEXP (insn, 1))
4123 mark_constants (PATTERN (insn));
4126 /* Look through appropriate parts of X, marking all entries in the
4127 constant pool which are actually being used. Entries that are only
4128 referenced by other constants are also marked as used. Emit
4129 deferred strings that are used. */
4136 const char *format_ptr;
4141 if (GET_CODE (x) == SYMBOL_REF)
4143 mark_constant (&x, NULL);
4147 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4148 insns, not any notes that may be attached. We don't want to mark
4149 a constant just because it happens to appear in a REG_EQUIV note. */
4152 mark_constants (PATTERN (x));
4156 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4158 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4160 switch (*format_ptr++)
4163 mark_constants (XEXP (x, i));
4167 if (XVEC (x, i) != 0)
4171 for (j = 0; j < XVECLEN (x, i); j++)
4172 mark_constants (XVECEXP (x, i, j));
4191 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4192 to as used. Emit referenced deferred strings. This function can
4193 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4196 mark_constant (current_rtx, data)
4198 void *data ATTRIBUTE_UNUSED;
4200 rtx x = *current_rtx;
4205 else if (GET_CODE (x) == SYMBOL_REF)
4207 if (CONSTANT_POOL_ADDRESS_P (x))
4209 struct pool_constant *pool = find_pool_constant (cfun, x);
4210 if (pool->mark == 0) {
4212 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4217 else if (STRING_POOL_ADDRESS_P (x))
4219 struct deferred_string **defstr;
4221 defstr = (struct deferred_string **)
4222 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4223 STRHASH (XSTR (x, 0)), NO_INSERT);
4226 struct deferred_string *p = *defstr;
4228 STRING_POOL_ADDRESS_P (x) = 0;
4229 output_constant_def_contents (p->exp, 0, p->labelno);
4230 htab_clear_slot (const_str_htab, (void **) defstr);
4237 /* Find all the constants whose addresses are referenced inside of EXP,
4238 and make sure assembler code with a label has been output for each one.
4239 Indicate whether an ADDR_EXPR has been encountered. */
4242 output_addressed_constants (exp)
4248 /* Give the front-end a chance to convert VALUE to something that
4249 looks more like a constant to the back-end. */
4250 exp = (*lang_hooks.expand_constant) (exp);
4252 switch (TREE_CODE (exp))
4256 /* Go inside any operations that get_inner_reference can handle and see
4257 if what's inside is a constant: no need to do anything here for
4258 addresses of variables or functions. */
4259 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4260 tem = TREE_OPERAND (tem, 0))
4263 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4264 || TREE_CODE (tem) == CONSTRUCTOR)
4265 output_constant_def (tem, 0);
4267 if (TREE_PUBLIC (tem))
4275 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4276 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4281 case NON_LVALUE_EXPR:
4282 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4286 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4287 if (TREE_VALUE (tem) != 0)
4288 reloc |= output_addressed_constants (TREE_VALUE (tem));
4298 /* Return nonzero if VALUE is a valid constant-valued expression
4299 for use in initializing a static variable; one that can be an
4300 element of a "constant" initializer.
4302 Return null_pointer_node if the value is absolute;
4303 if it is relocatable, return the variable that determines the relocation.
4304 We assume that VALUE has been folded as much as possible;
4305 therefore, we do not need to check for such things as
4306 arithmetic-combinations of integers. */
4309 initializer_constant_valid_p (value, endtype)
4313 /* Give the front-end a chance to convert VALUE to something that
4314 looks more like a constant to the back-end. */
4315 value = (*lang_hooks.expand_constant) (value);
4317 switch (TREE_CODE (value))
4320 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4321 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4322 && TREE_CONSTANT (value)
4323 && CONSTRUCTOR_ELTS (value))
4325 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4328 return TREE_STATIC (value) ? null_pointer_node : 0;
4335 return null_pointer_node;
4339 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4341 case VIEW_CONVERT_EXPR:
4342 case NON_LVALUE_EXPR:
4343 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4347 /* Allow conversions between pointer types. */
4348 if (POINTER_TYPE_P (TREE_TYPE (value))
4349 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4350 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4352 /* Allow conversions between real types. */
4353 if (FLOAT_TYPE_P (TREE_TYPE (value))
4354 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4355 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4357 /* Allow length-preserving conversions between integer types. */
4358 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4359 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4360 && (TYPE_PRECISION (TREE_TYPE (value))
4361 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4362 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4364 /* Allow conversions between other integer types only if
4366 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4367 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4369 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4371 if (inner == null_pointer_node)
4372 return null_pointer_node;
4376 /* Allow (int) &foo provided int is as wide as a pointer. */
4377 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4378 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4379 && (TYPE_PRECISION (TREE_TYPE (value))
4380 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4381 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4384 /* Likewise conversions from int to pointers, but also allow
4385 conversions from 0. */
4386 if (POINTER_TYPE_P (TREE_TYPE (value))
4387 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4389 if (integer_zerop (TREE_OPERAND (value, 0)))
4390 return null_pointer_node;
4391 else if (TYPE_PRECISION (TREE_TYPE (value))
4392 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4393 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4397 /* Allow conversions to union types if the value inside is okay. */
4398 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4399 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4404 if (! INTEGRAL_TYPE_P (endtype)
4405 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4407 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4409 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4411 /* If either term is absolute, use the other terms relocation. */
4412 if (valid0 == null_pointer_node)
4414 if (valid1 == null_pointer_node)
4420 if (! INTEGRAL_TYPE_P (endtype)
4421 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4423 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4425 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4427 /* Win if second argument is absolute. */
4428 if (valid1 == null_pointer_node)
4430 /* Win if both arguments have the same relocation.
4431 Then the value is absolute. */
4432 if (valid0 == valid1 && valid0 != 0)
4433 return null_pointer_node;
4435 /* Since GCC guarantees that string constants are unique in the
4436 generated code, a subtraction between two copies of the same
4437 constant string is absolute. */
4438 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4439 valid1 && TREE_CODE (valid1) == STRING_CST &&
4440 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4441 return null_pointer_node;
4444 /* Support differences between labels. */
4445 if (INTEGRAL_TYPE_P (endtype))
4448 op0 = TREE_OPERAND (value, 0);
4449 op1 = TREE_OPERAND (value, 1);
4451 /* Like STRIP_NOPS except allow the operand mode to widen.
4452 This works around a feature of fold that simplfies
4453 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4454 that the narrower operation is cheaper. */
4456 while (TREE_CODE (op0) == NOP_EXPR
4457 || TREE_CODE (op0) == CONVERT_EXPR
4458 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4460 tree inner = TREE_OPERAND (op0, 0);
4461 if (inner == error_mark_node
4462 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4463 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4464 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4469 while (TREE_CODE (op1) == NOP_EXPR
4470 || TREE_CODE (op1) == CONVERT_EXPR
4471 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4473 tree inner = TREE_OPERAND (op1, 0);
4474 if (inner == error_mark_node
4475 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4476 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4477 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4482 if (TREE_CODE (op0) == ADDR_EXPR
4483 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4484 && TREE_CODE (op1) == ADDR_EXPR
4485 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4486 return null_pointer_node;
4497 /* Output assembler code for constant EXP to FILE, with no label.
4498 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4499 Assumes output_addressed_constants has been done on EXP already.
4501 Generate exactly SIZE bytes of assembler data, padding at the end
4502 with zeros if necessary. SIZE must always be specified.
4504 SIZE is important for structure constructors,
4505 since trailing members may have been omitted from the constructor.
4506 It is also important for initialization of arrays from string constants
4507 since the full length of the string constant might not be wanted.
4508 It is also needed for initialization of unions, where the initializer's
4509 type is just one member, and that may not be as long as the union.
4511 There a case in which we would fail to output exactly SIZE bytes:
4512 for a structure constructor that wants to produce more than SIZE bytes.
4513 But such constructors will never be generated for any possible input.
4515 ALIGN is the alignment of the data in bits. */
4518 output_constant (exp, size, align)
4523 enum tree_code code;
4524 HOST_WIDE_INT thissize;
4526 /* Some front-ends use constants other than the standard language-indepdent
4527 varieties, but which may still be output directly. Give the front-end a
4528 chance to convert EXP to a language-independent representation. */
4529 exp = (*lang_hooks.expand_constant) (exp);
4531 if (size == 0 || flag_syntax_only)
4534 /* Eliminate any conversions since we'll be outputting the underlying
4536 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4537 || TREE_CODE (exp) == NON_LVALUE_EXPR
4538 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4539 exp = TREE_OPERAND (exp, 0);
4541 code = TREE_CODE (TREE_TYPE (exp));
4542 thissize = int_size_in_bytes (TREE_TYPE (exp));
4544 /* Allow a constructor with no elements for any data type.
4545 This means to fill the space with zeros. */
4546 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4548 assemble_zeros (size);
4552 if (TREE_CODE (exp) == FDESC_EXPR)
4554 #ifdef ASM_OUTPUT_FDESC
4555 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4556 tree decl = TREE_OPERAND (exp, 0);
4557 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4564 /* Now output the underlying data. If we've handling the padding, return.
4565 Otherwise, break and ensure THISSIZE is the size written. */
4573 case REFERENCE_TYPE:
4574 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4575 EXPAND_INITIALIZER),
4577 error ("initializer for integer value is too complicated");
4581 if (TREE_CODE (exp) != REAL_CST)
4582 error ("initializer for floating value is not a floating constant");
4584 assemble_real (TREE_REAL_CST (exp),
4585 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4590 output_constant (TREE_REALPART (exp), thissize / 2, align);
4591 output_constant (TREE_IMAGPART (exp), thissize / 2,
4592 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4597 if (TREE_CODE (exp) == CONSTRUCTOR)
4599 output_constructor (exp, size, align);
4602 else if (TREE_CODE (exp) == STRING_CST)
4604 thissize = MIN (TREE_STRING_LENGTH (exp), size);
4605 assemble_string (TREE_STRING_POINTER (exp), thissize);
4613 if (TREE_CODE (exp) == CONSTRUCTOR)
4614 output_constructor (exp, size, align);
4620 if (TREE_CODE (exp) == INTEGER_CST)
4621 assemble_integer (expand_expr (exp, NULL_RTX,
4622 VOIDmode, EXPAND_INITIALIZER),
4623 thissize, align, 1);
4624 else if (TREE_CODE (exp) == CONSTRUCTOR)
4626 unsigned char *buffer = (unsigned char *) alloca (thissize);
4627 if (get_set_constructor_bytes (exp, buffer, thissize))
4629 assemble_string ((char *) buffer, thissize);
4632 error ("unknown set constructor type");
4644 assemble_zeros (size);
4648 /* Subroutine of output_constructor, used for computing the size of
4649 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4650 type with an unspecified upper bound. */
4652 static unsigned HOST_WIDE_INT
4653 array_size_for_constructor (val)
4658 /* This code used to attempt to handle string constants that are not
4659 arrays of single-bytes, but nothing else does, so there's no point in
4661 if (TREE_CODE (val) == STRING_CST)
4662 return TREE_STRING_LENGTH (val);
4664 max_index = NULL_TREE;
4665 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4667 tree index = TREE_PURPOSE (i);
4669 if (TREE_CODE (index) == RANGE_EXPR)
4670 index = TREE_OPERAND (index, 1);
4671 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4675 if (max_index == NULL_TREE)
4678 /* Compute the total number of array elements. */
4679 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4681 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4682 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4684 /* Multiply by the array element unit size to find number of bytes. */
4685 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4687 return tree_low_cst (i, 1);
4690 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4691 Generate at least SIZE bytes, padding if necessary. */
4694 output_constructor (exp, size, align)
4699 tree type = TREE_TYPE (exp);
4700 tree link, field = 0;
4702 /* Number of bytes output or skipped so far.
4703 In other words, current position within the constructor. */
4704 HOST_WIDE_INT total_bytes = 0;
4705 /* Non-zero means BYTE contains part of a byte, to be output. */
4706 int byte_buffer_in_use = 0;
4709 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4712 if (TREE_CODE (type) == RECORD_TYPE)
4713 field = TYPE_FIELDS (type);
4715 if (TREE_CODE (type) == ARRAY_TYPE
4716 && TYPE_DOMAIN (type) != 0)
4717 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4719 /* As LINK goes through the elements of the constant,
4720 FIELD goes through the structure fields, if the constant is a structure.
4721 if the constant is a union, then we override this,
4722 by getting the field from the TREE_LIST element.
4723 But the constant could also be an array. Then FIELD is zero.
4725 There is always a maximum of one element in the chain LINK for unions
4726 (even if the initializer in a source program incorrectly contains
4728 for (link = CONSTRUCTOR_ELTS (exp);
4730 link = TREE_CHAIN (link),
4731 field = field ? TREE_CHAIN (field) : 0)
4733 tree val = TREE_VALUE (link);
4736 /* The element in a union constructor specifies the proper field
4738 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4739 || TREE_CODE (type) == QUAL_UNION_TYPE)
4740 && TREE_PURPOSE (link) != 0)
4741 field = TREE_PURPOSE (link);
4743 else if (TREE_CODE (type) == ARRAY_TYPE)
4744 index = TREE_PURPOSE (link);
4746 /* Eliminate the marker that makes a cast not be an lvalue. */
4750 if (index && TREE_CODE (index) == RANGE_EXPR)
4752 unsigned HOST_WIDE_INT fieldsize
4753 = int_size_in_bytes (TREE_TYPE (type));
4754 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4755 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4756 HOST_WIDE_INT index;
4757 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4759 for (index = lo_index; index <= hi_index; index++)
4761 /* Output the element's initial value. */
4763 assemble_zeros (fieldsize);
4765 output_constant (val, fieldsize, align2);
4767 /* Count its size. */
4768 total_bytes += fieldsize;
4771 else if (field == 0 || !DECL_BIT_FIELD (field))
4773 /* An element that is not a bit-field. */
4775 unsigned HOST_WIDE_INT fieldsize;
4776 /* Since this structure is static,
4777 we know the positions are constant. */
4778 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4779 unsigned int align2;
4782 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4783 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4785 /* Output any buffered-up bit-fields preceding this element. */
4786 if (byte_buffer_in_use)
4788 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4790 byte_buffer_in_use = 0;
4793 /* Advance to offset of this element.
4794 Note no alignment needed in an array, since that is guaranteed
4795 if each element has the proper size. */
4796 if ((field != 0 || index != 0) && pos != total_bytes)
4798 assemble_zeros (pos - total_bytes);
4802 /* Find the alignment of this element. */
4803 align2 = min_align (align, BITS_PER_UNIT * pos);
4805 /* Determine size this element should occupy. */
4810 /* If this is an array with an unspecified upper bound,
4811 the initializer determines the size. */
4812 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4813 but we cannot do this until the deprecated support for
4814 initializing zero-length array members is removed. */
4815 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4816 && TYPE_DOMAIN (TREE_TYPE (field))
4817 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4819 fieldsize = array_size_for_constructor (val);
4820 /* Given a non-empty initialization, this field had
4822 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4825 else if (DECL_SIZE_UNIT (field))
4827 /* ??? This can't be right. If the decl size overflows
4828 a host integer we will silently emit no data. */
4829 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4830 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4834 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4836 /* Output the element's initial value. */
4838 assemble_zeros (fieldsize);
4840 output_constant (val, fieldsize, align2);
4842 /* Count its size. */
4843 total_bytes += fieldsize;
4845 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4846 error ("invalid initial value for member `%s'",
4847 IDENTIFIER_POINTER (DECL_NAME (field)));
4850 /* Element that is a bit-field. */
4852 HOST_WIDE_INT next_offset = int_bit_position (field);
4853 HOST_WIDE_INT end_offset
4854 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4857 val = integer_zero_node;
4859 /* If this field does not start in this (or, next) byte,
4861 if (next_offset / BITS_PER_UNIT != total_bytes)
4863 /* Output remnant of any bit field in previous bytes. */
4864 if (byte_buffer_in_use)
4866 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4868 byte_buffer_in_use = 0;
4871 /* If still not at proper byte, advance to there. */
4872 if (next_offset / BITS_PER_UNIT != total_bytes)
4874 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4875 total_bytes = next_offset / BITS_PER_UNIT;
4879 if (! byte_buffer_in_use)
4882 /* We must split the element into pieces that fall within
4883 separate bytes, and combine each byte with previous or
4884 following bit-fields. */
4886 /* next_offset is the offset n fbits from the beginning of
4887 the structure to the next bit of this element to be processed.
4888 end_offset is the offset of the first bit past the end of
4890 while (next_offset < end_offset)
4894 HOST_WIDE_INT value;
4895 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4896 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4898 /* Advance from byte to byte
4899 within this element when necessary. */
4900 while (next_byte != total_bytes)
4902 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4907 /* Number of bits we can process at once
4908 (all part of the same byte). */
4909 this_time = MIN (end_offset - next_offset,
4910 BITS_PER_UNIT - next_bit);
4911 if (BYTES_BIG_ENDIAN)
4913 /* On big-endian machine, take the most significant bits
4914 first (of the bits that are significant)
4915 and put them into bytes from the most significant end. */
4916 shift = end_offset - next_offset - this_time;
4918 /* Don't try to take a bunch of bits that cross
4919 the word boundary in the INTEGER_CST. We can
4920 only select bits from the LOW or HIGH part
4922 if (shift < HOST_BITS_PER_WIDE_INT
4923 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4925 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4926 shift = HOST_BITS_PER_WIDE_INT;
4929 /* Now get the bits from the appropriate constant word. */
4930 if (shift < HOST_BITS_PER_WIDE_INT)
4931 value = TREE_INT_CST_LOW (val);
4932 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4934 value = TREE_INT_CST_HIGH (val);
4935 shift -= HOST_BITS_PER_WIDE_INT;
4940 /* Get the result. This works only when:
4941 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4942 byte |= (((value >> shift)
4943 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4944 << (BITS_PER_UNIT - this_time - next_bit));
4948 /* On little-endian machines,
4949 take first the least significant bits of the value
4950 and pack them starting at the least significant
4951 bits of the bytes. */
4952 shift = next_offset - int_bit_position (field);
4954 /* Don't try to take a bunch of bits that cross
4955 the word boundary in the INTEGER_CST. We can
4956 only select bits from the LOW or HIGH part
4958 if (shift < HOST_BITS_PER_WIDE_INT
4959 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4960 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4962 /* Now get the bits from the appropriate constant word. */
4963 if (shift < HOST_BITS_PER_WIDE_INT)
4964 value = TREE_INT_CST_LOW (val);
4965 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4967 value = TREE_INT_CST_HIGH (val);
4968 shift -= HOST_BITS_PER_WIDE_INT;
4973 /* Get the result. This works only when:
4974 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4975 byte |= (((value >> shift)
4976 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4980 next_offset += this_time;
4981 byte_buffer_in_use = 1;
4986 if (byte_buffer_in_use)
4988 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4992 if (total_bytes < size)
4993 assemble_zeros (size - total_bytes);
4996 /* This TREE_LIST contains any weak symbol declarations waiting
4998 static tree weak_decls;
5000 /* Mark DECL as weak. */
5006 DECL_WEAK (decl) = 1;
5008 if (DECL_RTL_SET_P (decl)
5009 && GET_CODE (DECL_RTL (decl)) == MEM
5010 && XEXP (DECL_RTL (decl), 0)
5011 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
5012 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
5015 /* Merge weak status between NEWDECL and OLDDECL. */
5018 merge_weak (newdecl, olddecl)
5022 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
5025 if (DECL_WEAK (newdecl))
5029 /* NEWDECL is weak, but OLDDECL is not. */
5031 /* If we already output the OLDDECL, we're in trouble; we can't
5032 go back and make it weak. This error cannot caught in
5033 declare_weak because the NEWDECL and OLDDECL was not yet
5034 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5035 if (TREE_ASM_WRITTEN (olddecl))
5036 error_with_decl (newdecl,
5037 "weak declaration of `%s' must precede definition");
5039 /* If we've already generated rtl referencing OLDDECL, we may
5040 have done so in a way that will not function properly with
5042 else if (TREE_USED (olddecl)
5043 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
5044 warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
5048 /* We put the NEWDECL on the weak_decls list at some point.
5049 Replace it with the OLDDECL. */
5050 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
5051 if (TREE_VALUE (wd) == newdecl)
5053 TREE_VALUE (wd) = olddecl;
5056 /* We may not find the entry on the list. If NEWDECL is a
5057 weak alias, then we will have already called
5058 globalize_decl to remove the entry; in that case, we do
5059 not need to do anything. */
5062 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5063 mark_weak (olddecl);
5066 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5067 weak. Just update NEWDECL to indicate that it's weak too. */
5068 mark_weak (newdecl);
5071 /* Declare DECL to be a weak symbol. */
5077 if (! TREE_PUBLIC (decl))
5078 error_with_decl (decl, "weak declaration of `%s' must be public");
5079 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
5080 error_with_decl (decl, "weak declaration of `%s' must precede definition");
5081 else if (SUPPORTS_WEAK)
5083 if (! DECL_WEAK (decl))
5084 weak_decls = tree_cons (NULL, decl, weak_decls);
5087 warning_with_decl (decl, "weak declaration of `%s' not supported");
5092 /* Emit any pending weak declarations. */
5099 for (t = weak_decls; t ; t = TREE_CHAIN (t))
5101 tree decl = TREE_VALUE (t);
5102 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5104 if (! TREE_USED (decl))
5107 #ifdef ASM_WEAKEN_DECL
5108 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
5110 #ifdef ASM_WEAKEN_LABEL
5111 ASM_WEAKEN_LABEL (asm_out_file, name);
5113 #ifdef ASM_OUTPUT_WEAK_ALIAS
5114 warning ("only weak aliases are supported in this configuration");
5122 /* Emit the assembly bits to indicate that DECL is globally visible. */
5125 globalize_decl (decl)
5128 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
5130 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5131 if (DECL_WEAK (decl))
5135 #ifdef ASM_WEAKEN_DECL
5136 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5138 ASM_WEAKEN_LABEL (asm_out_file, name);
5141 /* Remove this function from the pending weak list so that
5142 we do not emit multiple .weak directives for it. */
5143 for (p = &weak_decls; (t = *p) ; )
5145 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
5146 *p = TREE_CHAIN (t);
5148 p = &TREE_CHAIN (t);
5154 ASM_GLOBALIZE_LABEL (asm_out_file, name);
5157 /* Emit an assembler directive to make the symbol for DECL an alias to
5158 the symbol for TARGET. */
5161 assemble_alias (decl, target)
5162 tree decl, target ATTRIBUTE_UNUSED;
5166 /* We must force creation of DECL_RTL for debug info generation, even though
5167 we don't use it here. */
5168 make_decl_rtl (decl, NULL);
5170 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5172 #ifdef ASM_OUTPUT_DEF
5173 /* Make name accessible from other files, if appropriate. */
5174 if (TREE_PUBLIC (decl))
5175 globalize_decl (decl);
5177 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5178 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5180 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5182 #else /* !ASM_OUTPUT_DEF */
5183 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5184 if (! DECL_WEAK (decl))
5185 warning ("only weak aliases are supported in this configuration");
5187 #ifdef ASM_WEAKEN_DECL
5188 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5190 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5193 warning ("alias definitions not supported in this configuration; ignored");
5197 TREE_USED (decl) = 1;
5198 TREE_ASM_WRITTEN (decl) = 1;
5199 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
5202 /* Returns 1 if the target configuration supports defining public symbols
5203 so that one of them will be chosen at link time instead of generating a
5204 multiply-defined symbol error, whether through the use of weak symbols or
5205 a target-specific mechanism for having duplicates discarded. */
5208 supports_one_only ()
5210 if (SUPPORTS_ONE_ONLY)
5212 return SUPPORTS_WEAK;
5215 /* Set up DECL as a public symbol that can be defined in multiple
5216 translation units without generating a linker error. */
5219 make_decl_one_only (decl)
5222 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5225 TREE_PUBLIC (decl) = 1;
5227 if (TREE_CODE (decl) == VAR_DECL
5228 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5229 DECL_COMMON (decl) = 1;
5230 else if (SUPPORTS_ONE_ONLY)
5232 #ifdef MAKE_DECL_ONE_ONLY
5233 MAKE_DECL_ONE_ONLY (decl);
5235 DECL_ONE_ONLY (decl) = 1;
5237 else if (SUPPORTS_WEAK)
5238 DECL_WEAK (decl) = 1;
5246 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5247 const_str_htab_del);
5248 in_named_htab = htab_create (31, in_named_entry_hash,
5249 in_named_entry_eq, NULL);
5251 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5252 mark_const_hash_entry);
5253 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5254 mark_const_str_htab);
5255 ggc_add_tree_root (&weak_decls, 1);
5257 const_alias_set = new_alias_set ();
5260 /* Select a set of attributes for section NAME based on the properties
5261 of DECL and whether or not RELOC indicates that DECL's initializer
5262 might contain runtime relocations.
5264 We make the section read-only and executable for a function decl,
5265 read-only for a const data decl, and writable for a non-const data decl. */
5268 default_section_type_flags (decl, name, reloc)
5275 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5276 flags = SECTION_CODE;
5277 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5280 flags = SECTION_WRITE;
5282 if (decl && DECL_ONE_ONLY (decl))
5283 flags |= SECTION_LINKONCE;
5285 if (strcmp (name, ".bss") == 0
5286 || strncmp (name, ".bss.", 5) == 0
5287 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5288 || strcmp (name, ".sbss") == 0
5289 || strncmp (name, ".sbss.", 6) == 0
5290 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5291 flags |= SECTION_BSS;
5296 /* Output assembly to switch to section NAME with attribute FLAGS.
5297 Four variants for common object file formats. */
5300 default_no_named_section (name, flags)
5301 const char *name ATTRIBUTE_UNUSED;
5302 unsigned int flags ATTRIBUTE_UNUSED;
5304 /* Some object formats don't support named sections at all. The
5305 front-end should already have flagged this as an error. */
5310 default_elf_asm_named_section (name, flags)
5314 char flagchars[10], *f = flagchars;
5317 if (! named_section_first_declaration (name))
5319 fprintf (asm_out_file, "\t.section\t%s\n", name);
5323 if (!(flags & SECTION_DEBUG))
5325 if (flags & SECTION_WRITE)
5327 if (flags & SECTION_CODE)
5329 if (flags & SECTION_SMALL)
5331 if (flags & SECTION_MERGE)
5333 if (flags & SECTION_STRINGS)
5337 if (flags & SECTION_BSS)
5342 if (flags & SECTION_ENTSIZE)
5343 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5344 name, flagchars, type, flags & SECTION_ENTSIZE);
5346 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5347 name, flagchars, type);
5351 default_coff_asm_named_section (name, flags)
5355 char flagchars[8], *f = flagchars;
5357 if (flags & SECTION_WRITE)
5359 if (flags & SECTION_CODE)
5363 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5367 default_pe_asm_named_section (name, flags)
5371 default_coff_asm_named_section (name, flags);
5373 if (flags & SECTION_LINKONCE)
5375 /* Functions may have been compiled at various levels of
5376 optimization so we can't use `same_size' here.
5377 Instead, have the linker pick one. */
5378 fprintf (asm_out_file, "\t.linkonce %s\n",
5379 (flags & SECTION_CODE ? "discard" : "same_size"));
5383 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5384 from SYMBOL is used in all classes derived from SYMBOL. */
5387 assemble_vtable_entry (symbol, offset)
5389 HOST_WIDE_INT offset;
5391 fputs ("\t.vtable_entry ", asm_out_file);
5392 output_addr_const (asm_out_file, symbol);
5393 fputs (", ", asm_out_file);
5394 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5395 fputc ('\n', asm_out_file);
5398 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5399 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5402 assemble_vtable_inherit (child, parent)
5405 fputs ("\t.vtable_inherit ", asm_out_file);
5406 output_addr_const (asm_out_file, child);
5407 fputs (", ", asm_out_file);
5408 output_addr_const (asm_out_file, parent);
5409 fputc ('\n', asm_out_file);