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 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 a 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 assemble_real_1 PARAMS ((PTR));
144 static void decode_addr_const PARAMS ((tree, struct addr_const *));
145 static int const_hash PARAMS ((tree));
146 static int compare_constant PARAMS ((tree,
147 struct constant_descriptor *));
148 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
149 static struct constant_descriptor *record_constant PARAMS ((tree));
150 static void record_constant_1 PARAMS ((tree));
151 static tree copy_constant PARAMS ((tree));
152 static void output_constant_def_contents PARAMS ((tree, int, int));
153 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
154 struct rtx_const *));
155 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
156 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
157 struct constant_descriptor *));
158 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
160 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
161 static void mark_constant_pool PARAMS ((void));
162 static void mark_constants PARAMS ((rtx));
163 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
164 static int output_addressed_constants PARAMS ((tree));
165 static void output_after_function_constants PARAMS ((void));
166 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
167 static unsigned min_align PARAMS ((unsigned, unsigned));
168 static void output_constructor PARAMS ((tree, HOST_WIDE_INT,
170 #ifdef ASM_WEAKEN_LABEL
171 static void remove_from_pending_weak_list PARAMS ((const char *));
173 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
174 static hashval_t in_named_entry_hash PARAMS ((const PTR));
175 #ifdef ASM_OUTPUT_BSS
176 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
178 #ifdef BSS_SECTION_ASM_OP
179 #ifdef ASM_OUTPUT_ALIGNED_BSS
180 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
183 #endif /* BSS_SECTION_ASM_OP */
184 static void mark_pool_constant PARAMS ((struct pool_constant *));
185 static void mark_const_hash_entry PARAMS ((void *));
186 static int mark_const_str_htab_1 PARAMS ((void **, void *));
187 static void mark_const_str_htab PARAMS ((void *));
188 static hashval_t const_str_htab_hash PARAMS ((const void *x));
189 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
190 static void const_str_htab_del PARAMS ((void *));
191 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
192 static void resolve_unique_section PARAMS ((tree, int));
194 static enum in_section { no_section, in_text, in_data, in_named
195 #ifdef BSS_SECTION_ASM_OP
198 #ifdef CTORS_SECTION_ASM_OP
201 #ifdef DTORS_SECTION_ASM_OP
204 #ifdef EXTRA_SECTIONS
207 } in_section = no_section;
209 /* Return a non-zero value if DECL has a section attribute. */
210 #ifndef IN_NAMED_SECTION
211 #define IN_NAMED_SECTION(DECL) \
212 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
213 && DECL_SECTION_NAME (DECL) != NULL_TREE)
216 /* Text of section name when in_section == in_named. */
217 static const char *in_named_name;
219 /* Hash table of flags that have been used for a particular named section. */
221 struct in_named_entry
228 static htab_t in_named_htab;
230 /* Define functions like text_section for any extra sections. */
231 #ifdef EXTRA_SECTION_FUNCTIONS
232 EXTRA_SECTION_FUNCTIONS
235 /* Tell assembler to switch to text section. */
240 if (in_section != in_text)
245 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
247 in_section = in_text;
251 /* Tell assembler to switch to data section. */
256 if (in_section != in_data)
258 if (flag_shared_data)
260 #ifdef SHARED_SECTION_ASM_OP
261 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
263 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
267 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
269 in_section = in_data;
272 /* Tell assembler to ALWAYS switch to data section, in case
273 it's not sure where it is. */
276 force_data_section ()
278 in_section = no_section;
282 /* Tell assembler to switch to read-only data section. This is normally
286 readonly_data_section ()
288 #ifdef READONLY_DATA_SECTION
289 READONLY_DATA_SECTION (); /* Note this can call data_section. */
295 /* Determine if we're in the text section. */
300 return in_section == in_text;
303 /* Determine if we're in the data section. */
308 return in_section == in_data;
311 /* Helper routines for maintaining in_named_htab. */
314 in_named_entry_eq (p1, p2)
318 const struct in_named_entry *old = p1;
319 const char *new = p2;
321 return strcmp (old->name, new) == 0;
325 in_named_entry_hash (p)
328 const struct in_named_entry *old = p;
329 return htab_hash_string (old->name);
332 /* If SECTION has been seen before as a named section, return the flags
333 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
334 set of flags for a section to have, so 0 does not mean that the section
335 has not been seen. */
338 get_named_section_flags (section)
341 struct in_named_entry **slot;
343 slot = (struct in_named_entry**)
344 htab_find_slot_with_hash (in_named_htab, section,
345 htab_hash_string (section), NO_INSERT);
347 return slot ? (*slot)->flags : 0;
350 /* Returns true if the section has been declared before. Sets internal
351 flag on this section in in_named_hash so subsequent calls on this
352 section will return false. */
355 named_section_first_declaration (name)
358 struct in_named_entry **slot;
360 slot = (struct in_named_entry**)
361 htab_find_slot_with_hash (in_named_htab, name,
362 htab_hash_string (name), NO_INSERT);
363 if (! (*slot)->declared)
365 (*slot)->declared = true;
375 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
376 different set of flags, return false. */
379 set_named_section_flags (section, flags)
383 struct in_named_entry **slot, *entry;
385 slot = (struct in_named_entry**)
386 htab_find_slot_with_hash (in_named_htab, section,
387 htab_hash_string (section), INSERT);
392 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
394 entry->name = ggc_strdup (section);
395 entry->flags = flags;
396 entry->declared = false;
398 else if (entry->flags != flags)
404 /* Tell assembler to change to section NAME with attributes FLAGS. */
407 named_section_flags (name, flags)
411 if (in_section != in_named || strcmp (name, in_named_name) != 0)
413 if (! set_named_section_flags (name, flags))
416 (* targetm.asm_out.named_section) (name, flags);
418 if (flags & SECTION_FORGET)
419 in_section = no_section;
422 in_named_name = ggc_strdup (name);
423 in_section = in_named;
428 /* Tell assembler to change to section NAME for DECL.
429 If DECL is NULL, just switch to section NAME.
430 If NAME is NULL, get the name from DECL.
431 If RELOC is 1, the initializer for DECL contains relocs. */
434 named_section (decl, name, reloc)
441 if (decl != NULL_TREE && !DECL_P (decl))
444 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
446 flags = (* targetm.section_type_flags) (decl, name, reloc);
448 /* Sanity check user variables for flag changes. Non-user
449 section flag changes will abort in named_section_flags. */
450 if (decl && ! set_named_section_flags (name, flags))
452 error_with_decl (decl, "%s causes a section type conflict");
453 flags = get_named_section_flags (name);
456 named_section_flags (name, flags);
459 /* If required, set DECL_SECTION_NAME to a unique name. */
462 resolve_unique_section (decl, reloc)
464 int reloc ATTRIBUTE_UNUSED;
466 if (DECL_SECTION_NAME (decl) == NULL_TREE
467 && (flag_function_sections
468 || (targetm.have_named_sections
469 && DECL_ONE_ONLY (decl))))
470 UNIQUE_SECTION (decl, reloc);
473 #ifdef BSS_SECTION_ASM_OP
475 /* Tell the assembler to switch to the bss section. */
480 if (in_section != in_bss)
482 #ifdef SHARED_BSS_SECTION_ASM_OP
483 if (flag_shared_data)
484 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
487 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
493 #ifdef ASM_OUTPUT_BSS
495 /* Utility function for ASM_OUTPUT_BSS for targets to use if
496 they don't support alignments in .bss.
497 ??? It is believed that this function will work in most cases so such
498 support is localized here. */
501 asm_output_bss (file, decl, name, size, rounded)
503 tree decl ATTRIBUTE_UNUSED;
505 int size ATTRIBUTE_UNUSED, rounded;
507 ASM_GLOBALIZE_LABEL (file, name);
509 #ifdef ASM_DECLARE_OBJECT_NAME
510 last_assemble_variable_decl = decl;
511 ASM_DECLARE_OBJECT_NAME (file, name, decl);
513 /* Standard thing is just output label for the object. */
514 ASM_OUTPUT_LABEL (file, name);
515 #endif /* ASM_DECLARE_OBJECT_NAME */
516 ASM_OUTPUT_SKIP (file, rounded);
521 #ifdef ASM_OUTPUT_ALIGNED_BSS
523 /* Utility function for targets to use in implementing
524 ASM_OUTPUT_ALIGNED_BSS.
525 ??? It is believed that this function will work in most cases so such
526 support is localized here. */
529 asm_output_aligned_bss (file, decl, name, size, align)
531 tree decl ATTRIBUTE_UNUSED;
535 ASM_GLOBALIZE_LABEL (file, name);
537 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
538 #ifdef ASM_DECLARE_OBJECT_NAME
539 last_assemble_variable_decl = decl;
540 ASM_DECLARE_OBJECT_NAME (file, name, decl);
542 /* Standard thing is just output label for the object. */
543 ASM_OUTPUT_LABEL (file, name);
544 #endif /* ASM_DECLARE_OBJECT_NAME */
545 ASM_OUTPUT_SKIP (file, size ? size : 1);
550 #endif /* BSS_SECTION_ASM_OP */
552 /* Switch to the section for function DECL.
554 If DECL is NULL_TREE, switch to the text section.
555 ??? It's not clear that we will ever be passed NULL_TREE, but it's
556 safer to handle it. */
559 function_section (decl)
562 if (decl != NULL_TREE
563 && DECL_SECTION_NAME (decl) != NULL_TREE)
564 named_section (decl, (char *) 0, 0);
569 /* Switch to section for variable DECL.
571 RELOC is the `reloc' argument to SELECT_SECTION. */
574 variable_section (decl, reloc)
578 if (IN_NAMED_SECTION (decl))
579 named_section (decl, NULL, reloc);
582 /* C++ can have const variables that get initialized from constructors,
583 and thus can not be in a readonly section. We prevent this by
584 verifying that the initial value is constant for objects put in a
587 error_mark_node is used by the C front end to indicate that the
588 initializer has not been seen yet. In this case, we assume that
589 the initializer must be constant.
591 C++ uses error_mark_node for variables that have complicated
592 initializers, but these variables go in BSS so we won't be called
595 #ifdef SELECT_SECTION
596 SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
598 if (DECL_READONLY_SECTION (decl, reloc))
599 readonly_data_section ();
606 /* Tell assembler to switch to the section for the exception handling
610 default_exception_section ()
612 if (targetm.have_named_sections)
613 named_section (NULL_TREE, ".gcc_except_table", 0);
617 readonly_data_section ();
620 /* Tell assembler to switch to the section for string merging. */
623 mergeable_string_section (decl, align, flags)
624 tree decl ATTRIBUTE_UNUSED;
625 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
626 unsigned int flags ATTRIBUTE_UNUSED;
628 #ifdef HAVE_GAS_SHF_MERGE
629 if (flag_merge_constants
630 && TREE_CODE (decl) == STRING_CST
631 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
633 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
635 enum machine_mode mode;
636 unsigned int modesize;
641 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
642 modesize = GET_MODE_BITSIZE (mode);
643 if (modesize >= 8 && modesize <= 256
644 && (modesize & (modesize - 1)) == 0)
646 if (align < modesize)
649 str = TREE_STRING_POINTER (decl);
650 len = TREE_STRING_LENGTH (decl);
651 unit = GET_MODE_SIZE (mode);
653 /* Check for embedded NUL characters. */
654 for (i = 0; i < len; i += unit)
656 for (j = 0; j < unit; j++)
657 if (str [i + j] != '\0')
664 sprintf (name, ".rodata.str%d.%d", modesize / 8,
666 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
667 if (!i && modesize < align)
669 /* A "" string with requested alignment greater than
670 character size might cause a problem:
671 if some other string required even bigger
672 alignment than "", then linker might think the
673 "" is just part of padding after some other string
674 and not put it into the hash table initially.
675 But this means "" could have smaller alignment
677 #ifdef ASM_OUTPUT_SECTION_START
678 named_section_flags (name, flags);
679 ASM_OUTPUT_SECTION_START (asm_out_file);
681 readonly_data_section ();
686 named_section_flags (name, flags);
692 readonly_data_section ();
695 /* Tell assembler to switch to the section for constant merging. */
698 mergeable_constant_section (mode, align, flags)
699 enum machine_mode mode ATTRIBUTE_UNUSED;
700 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
701 unsigned int flags ATTRIBUTE_UNUSED;
703 #ifdef HAVE_GAS_SHF_MERGE
704 unsigned int modesize = GET_MODE_BITSIZE (mode);
706 if (flag_merge_constants
712 && (align & (align - 1)) == 0)
716 sprintf (name, ".rodata.cst%d", (int) (align / 8));
717 flags |= (align / 8) | SECTION_MERGE;
718 named_section_flags (name, flags);
722 readonly_data_section ();
725 /* Given NAME, a putative register name, discard any customary prefixes. */
728 strip_reg_name (name)
731 #ifdef REGISTER_PREFIX
732 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
733 name += strlen (REGISTER_PREFIX);
735 if (name[0] == '%' || name[0] == '#')
740 /* Decode an `asm' spec for a declaration as a register name.
741 Return the register number, or -1 if nothing specified,
742 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
743 or -3 if ASMSPEC is `cc' and is not recognized,
744 or -4 if ASMSPEC is `memory' and is not recognized.
745 Accept an exact spelling or a decimal number.
746 Prefixes such as % are optional. */
749 decode_reg_name (asmspec)
756 /* Get rid of confusing prefixes. */
757 asmspec = strip_reg_name (asmspec);
759 /* Allow a decimal number as a "register name". */
760 for (i = strlen (asmspec) - 1; i >= 0; i--)
761 if (! ISDIGIT (asmspec[i]))
763 if (asmspec[0] != 0 && i < 0)
766 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
772 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
774 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
777 #ifdef ADDITIONAL_REGISTER_NAMES
779 static const struct { const char *const name; const int number; } table[]
780 = ADDITIONAL_REGISTER_NAMES;
782 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
783 if (! strcmp (asmspec, table[i].name))
784 return table[i].number;
786 #endif /* ADDITIONAL_REGISTER_NAMES */
788 if (!strcmp (asmspec, "memory"))
791 if (!strcmp (asmspec, "cc"))
800 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
801 have static storage duration. In other words, it should not be an
802 automatic variable, including PARM_DECLs.
804 There is, however, one exception: this function handles variables
805 explicitly placed in a particular register by the user.
807 ASMSPEC, if not 0, is the string which the user specified as the
808 assembler symbol name.
810 This is never called for PARM_DECL nodes. */
813 make_decl_rtl (decl, asmspec)
817 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
818 const char *name = 0;
819 const char *new_name = 0;
823 /* Check that we are not being given an automatic variable. */
824 /* A weak alias has TREE_PUBLIC set but not the other bits. */
825 if (TREE_CODE (decl) == PARM_DECL
826 || TREE_CODE (decl) == RESULT_DECL
827 || (TREE_CODE (decl) == VAR_DECL
828 && !TREE_STATIC (decl)
829 && !TREE_PUBLIC (decl)
830 && !DECL_EXTERNAL (decl)
831 && !DECL_REGISTER (decl)))
833 /* And that we were not given a type or a label. */
834 else if (TREE_CODE (decl) == TYPE_DECL
835 || TREE_CODE (decl) == LABEL_DECL)
838 /* For a duplicate declaration, we can be called twice on the
839 same DECL node. Don't discard the RTL already made. */
840 if (DECL_RTL_SET_P (decl))
842 /* If the old RTL had the wrong mode, fix the mode. */
843 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
845 rtx rtl = DECL_RTL (decl);
846 PUT_MODE (rtl, DECL_MODE (decl));
849 /* ??? Another way to do this would be to do what halfpic.c does
850 and maintain a hashed table of such critters. */
851 /* ??? Another way to do this would be to pass a flag bit to
852 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
853 /* Let the target reassign the RTL if it wants.
854 This is necessary, for example, when one machine specific
855 decl attribute overrides another. */
856 #ifdef REDO_SECTION_INFO_P
857 if (REDO_SECTION_INFO_P (decl))
858 ENCODE_SECTION_INFO (decl);
863 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
865 reg_number = decode_reg_name (asmspec);
866 if (reg_number == -2)
868 /* ASMSPEC is given, and not the name of a register. Mark the
869 name with a star so assemble_name won't munge it. */
870 char *starred = alloca (strlen (asmspec) + 2);
872 strcpy (starred + 1, asmspec);
876 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
878 /* First detect errors in declaring global registers. */
879 if (reg_number == -1)
880 error_with_decl (decl, "register name not specified for `%s'");
881 else if (reg_number < 0)
882 error_with_decl (decl, "invalid register name for `%s'");
883 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
884 error_with_decl (decl,
885 "data type of `%s' isn't suitable for a register");
886 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
887 error_with_decl (decl,
888 "register specified for `%s' isn't suitable for data type");
889 /* Now handle properly declared static register variables. */
894 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
896 DECL_INITIAL (decl) = 0;
897 error ("global register variable has initial value");
899 if (TREE_THIS_VOLATILE (decl))
900 warning ("volatile register variables don't work as you might wish");
902 /* If the user specified one of the eliminables registers here,
903 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
904 confused with that register and be eliminated. Although this
905 usage is somewhat suspect, we nevertheless use the following
906 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
909 gen_rtx_REG (DECL_MODE (decl),
910 FIRST_PSEUDO_REGISTER));
911 REGNO (DECL_RTL (decl)) = reg_number;
912 REG_USERVAR_P (DECL_RTL (decl)) = 1;
914 if (TREE_STATIC (decl))
916 /* Make this register global, so not usable for anything
918 #ifdef ASM_DECLARE_REGISTER_GLOBAL
919 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
921 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
923 globalize_reg (reg_number + --nregs);
926 /* As a register variable, it has no section. */
931 /* Now handle ordinary static variables and functions (in memory).
932 Also handle vars declared register invalidly. */
934 if (reg_number >= 0 || reg_number == -3)
935 error_with_decl (decl,
936 "register name given for non-register variable `%s'");
938 /* Specifying a section attribute on a variable forces it into a
939 non-.bss section, and thus it cannot be common. */
940 if (TREE_CODE (decl) == VAR_DECL
941 && DECL_SECTION_NAME (decl) != NULL_TREE
942 && DECL_INITIAL (decl) == NULL_TREE
943 && DECL_COMMON (decl))
944 DECL_COMMON (decl) = 0;
946 /* Can't use just the variable's own name for a variable
947 whose scope is less than the whole file, unless it's a member
948 of a local class (which will already be unambiguous).
949 Concatenate a distinguishing number. */
950 if (!top_level && !TREE_PUBLIC (decl)
951 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
953 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
957 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
962 if (name != new_name)
964 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
965 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
968 /* If this variable is to be treated as volatile, show its
969 tree node has side effects. */
970 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
971 && TREE_PUBLIC (decl))
972 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
973 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
974 TREE_SIDE_EFFECTS (decl) = 1;
976 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
977 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
978 if (TREE_CODE (decl) != FUNCTION_DECL)
979 set_mem_attributes (x, decl, 1);
980 SET_DECL_RTL (decl, x);
982 /* Optionally set flags or add text to the name to record information
983 such as that it is a function name.
984 If the name is changed, the macro ASM_OUTPUT_LABELREF
985 will have to know how to strip this information. */
986 #ifdef ENCODE_SECTION_INFO
987 ENCODE_SECTION_INFO (decl);
991 /* Make the rtl for variable VAR be volatile.
992 Use this only for static variables. */
995 make_var_volatile (var)
998 if (GET_CODE (DECL_RTL (var)) != MEM)
1001 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1004 /* Output alignment directive to align for constant expression EXP. */
1007 assemble_constant_align (exp)
1012 /* Align the location counter as required by EXP's data type. */
1013 align = TYPE_ALIGN (TREE_TYPE (exp));
1014 #ifdef CONSTANT_ALIGNMENT
1015 align = CONSTANT_ALIGNMENT (exp, align);
1018 if (align > BITS_PER_UNIT)
1020 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1024 /* Output a string of literal assembler code
1025 for an `asm' keyword used between functions. */
1028 assemble_asm (string)
1033 if (TREE_CODE (string) == ADDR_EXPR)
1034 string = TREE_OPERAND (string, 0);
1036 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1039 /* Record an element in the table of global destructors. SYMBOL is
1040 a SYMBOL_REF of the function to be called; PRIORITY is a number
1041 between 0 and MAX_INIT_PRIORITY. */
1044 default_stabs_asm_out_destructor (symbol, priority)
1046 int priority ATTRIBUTE_UNUSED;
1048 /* Tell GNU LD that this is part of the static destructor set.
1049 This will work for any system that uses stabs, most usefully
1051 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1052 assemble_name (asm_out_file, XSTR (symbol, 0));
1053 fputc ('\n', asm_out_file);
1057 default_named_section_asm_out_destructor (symbol, priority)
1061 const char *section = ".dtors";
1064 /* ??? This only works reliably with the GNU linker. */
1065 if (priority != DEFAULT_INIT_PRIORITY)
1067 sprintf (buf, ".dtors.%.5u",
1068 /* Invert the numbering so the linker puts us in the proper
1069 order; constructors are run from right to left, and the
1070 linker sorts in increasing order. */
1071 MAX_INIT_PRIORITY - priority);
1075 named_section_flags (section, SECTION_WRITE);
1076 assemble_align (POINTER_SIZE);
1077 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1080 #ifdef DTORS_SECTION_ASM_OP
1084 if (in_section != in_dtors)
1086 in_section = in_dtors;
1087 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1088 fputc ('\n', asm_out_file);
1093 default_dtor_section_asm_out_destructor (symbol, priority)
1095 int priority ATTRIBUTE_UNUSED;
1098 assemble_align (POINTER_SIZE);
1099 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1103 /* Likewise for global constructors. */
1106 default_stabs_asm_out_constructor (symbol, priority)
1108 int priority ATTRIBUTE_UNUSED;
1110 /* Tell GNU LD that this is part of the static destructor set.
1111 This will work for any system that uses stabs, most usefully
1113 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1114 assemble_name (asm_out_file, XSTR (symbol, 0));
1115 fputc ('\n', asm_out_file);
1119 default_named_section_asm_out_constructor (symbol, priority)
1123 const char *section = ".ctors";
1126 /* ??? This only works reliably with the GNU linker. */
1127 if (priority != DEFAULT_INIT_PRIORITY)
1129 sprintf (buf, ".ctors.%.5u",
1130 /* Invert the numbering so the linker puts us in the proper
1131 order; constructors are run from right to left, and the
1132 linker sorts in increasing order. */
1133 MAX_INIT_PRIORITY - priority);
1137 named_section_flags (section, SECTION_WRITE);
1138 assemble_align (POINTER_SIZE);
1139 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1142 #ifdef CTORS_SECTION_ASM_OP
1146 if (in_section != in_ctors)
1148 in_section = in_ctors;
1149 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1150 fputc ('\n', asm_out_file);
1155 default_ctor_section_asm_out_constructor (symbol, priority)
1157 int priority ATTRIBUTE_UNUSED;
1160 assemble_align (POINTER_SIZE);
1161 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1165 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1166 a non-zero value if the constant pool should be output before the
1167 start of the function, or a zero value if the pool should output
1168 after the end of the function. The default is to put it before the
1171 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1172 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1175 /* Output assembler code for the constant pool of a function and associated
1176 with defining the name of the function. DECL describes the function.
1177 NAME is the function's name. For the constant pool, we use the current
1178 constant pool data. */
1181 assemble_start_function (decl, fnname)
1187 /* The following code does not need preprocessing in the assembler. */
1191 if (CONSTANT_POOL_BEFORE_FUNCTION)
1192 output_constant_pool (fnname, decl);
1194 resolve_unique_section (decl, 0);
1195 function_section (decl);
1197 /* Tell assembler to move to target machine's alignment for functions. */
1198 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
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 #ifdef ASM_WEAKEN_LABEL
1243 if (DECL_WEAK (decl))
1245 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1246 /* Remove this function from the pending weak list so that
1247 we do not emit multiple .weak directives for it. */
1248 remove_from_pending_weak_list
1249 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1253 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1256 /* Do any machine/system dependent processing of the function name */
1257 #ifdef ASM_DECLARE_FUNCTION_NAME
1258 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1260 /* Standard thing is just output label for the function. */
1261 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1262 #endif /* ASM_DECLARE_FUNCTION_NAME */
1265 /* Output assembler code associated with defining the size of the
1266 function. DECL describes the function. NAME is the function's name. */
1269 assemble_end_function (decl, fnname)
1273 #ifdef ASM_DECLARE_FUNCTION_SIZE
1274 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1276 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1278 output_constant_pool (fnname, decl);
1279 function_section (decl); /* need to switch back */
1282 /* Output any constants which should appear after the function. */
1283 output_after_function_constants ();
1286 /* Assemble code to leave SIZE bytes of zeros. */
1289 assemble_zeros (size)
1292 /* Do no output if -fsyntax-only. */
1293 if (flag_syntax_only)
1296 #ifdef ASM_NO_SKIP_IN_TEXT
1297 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1298 so we must output 0s explicitly in the text section. */
1299 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1302 for (i = 0; i < size; i++)
1303 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1308 ASM_OUTPUT_SKIP (asm_out_file, size);
1311 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1314 assemble_align (align)
1317 if (align > BITS_PER_UNIT)
1319 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1323 /* Assemble a string constant with the specified C string as contents. */
1326 assemble_string (p, size)
1333 /* If the string is very long, split it up. */
1337 int thissize = size - pos;
1338 if (thissize > maximum)
1341 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1349 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1350 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1351 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1353 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1354 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1355 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1357 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1358 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1362 #if defined ASM_OUTPUT_ALIGNED_BSS
1363 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1364 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1366 #if defined ASM_OUTPUT_BSS
1367 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1368 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1374 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1375 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1376 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1378 #if defined ASM_OUTPUT_ALIGNED_COMMON
1379 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1380 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1382 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1383 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1388 asm_emit_uninitialised (decl, name, size, rounded)
1391 int size ATTRIBUTE_UNUSED;
1392 int rounded ATTRIBUTE_UNUSED;
1400 destination = asm_dest_local;
1402 if (TREE_PUBLIC (decl))
1404 #if defined ASM_EMIT_BSS
1405 if (! DECL_COMMON (decl))
1406 destination = asm_dest_bss;
1409 destination = asm_dest_common;
1412 if (flag_shared_data)
1414 switch (destination)
1416 #ifdef ASM_OUTPUT_SHARED_BSS
1418 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1421 #ifdef ASM_OUTPUT_SHARED_COMMON
1422 case asm_dest_common:
1423 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1426 #ifdef ASM_OUTPUT_SHARED_LOCAL
1427 case asm_dest_local:
1428 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1436 resolve_unique_section (decl, 0);
1438 switch (destination)
1442 ASM_EMIT_BSS (decl, name, size, rounded);
1445 case asm_dest_common:
1446 ASM_EMIT_COMMON (decl, name, size, rounded);
1448 case asm_dest_local:
1449 ASM_EMIT_LOCAL (decl, name, size, rounded);
1458 /* Assemble everything that is needed for a variable or function declaration.
1459 Not used for automatic variables, and not used for function definitions.
1460 Should not be called for variables of incomplete structure type.
1462 TOP_LEVEL is nonzero if this variable has file scope.
1463 AT_END is nonzero if this is the special handling, at end of compilation,
1464 to define things that have had only tentative definitions.
1465 DONT_OUTPUT_DATA if nonzero means don't actually output the
1466 initial value (that will be done by the caller). */
1469 assemble_variable (decl, top_level, at_end, dont_output_data)
1471 int top_level ATTRIBUTE_UNUSED;
1472 int at_end ATTRIBUTE_UNUSED;
1473 int dont_output_data;
1480 last_assemble_variable_decl = 0;
1482 /* Normally no need to say anything here for external references,
1483 since assemble_external is called by the language-specific code
1484 when a declaration is first seen. */
1486 if (DECL_EXTERNAL (decl))
1489 /* Output no assembler code for a function declaration.
1490 Only definitions of functions output anything. */
1492 if (TREE_CODE (decl) == FUNCTION_DECL)
1495 /* Do nothing for global register variables. */
1496 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1498 TREE_ASM_WRITTEN (decl) = 1;
1502 /* If type was incomplete when the variable was declared,
1503 see if it is complete now. */
1505 if (DECL_SIZE (decl) == 0)
1506 layout_decl (decl, 0);
1508 /* Still incomplete => don't allocate it; treat the tentative defn
1509 (which is what it must have been) as an `extern' reference. */
1511 if (!dont_output_data && DECL_SIZE (decl) == 0)
1513 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1514 DECL_SOURCE_LINE (decl),
1515 "storage size of `%s' isn't known",
1516 IDENTIFIER_POINTER (DECL_NAME (decl)));
1517 TREE_ASM_WRITTEN (decl) = 1;
1521 /* The first declaration of a variable that comes through this function
1522 decides whether it is global (in C, has external linkage)
1523 or local (in C, has internal linkage). So do nothing more
1524 if this function has already run. */
1526 if (TREE_ASM_WRITTEN (decl))
1529 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1530 decl_rtl = DECL_RTL (decl);
1532 TREE_ASM_WRITTEN (decl) = 1;
1534 /* Do no output if -fsyntax-only. */
1535 if (flag_syntax_only)
1540 if (! dont_output_data
1541 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1543 error_with_decl (decl, "size of variable `%s' is too large");
1547 name = XSTR (XEXP (decl_rtl, 0), 0);
1548 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1549 && ! first_global_object_name
1550 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1551 || DECL_INITIAL (decl) == error_mark_node))
1552 && ! DECL_WEAK (decl)
1553 && ! DECL_ONE_ONLY (decl))
1558 STRIP_NAME_ENCODING (p, name);
1559 xname = permalloc (strlen (p) + 1);
1561 first_global_object_name = xname;
1564 /* Compute the alignment of this data. */
1566 align = DECL_ALIGN (decl);
1568 /* In the case for initialing an array whose length isn't specified,
1569 where we have not yet been able to do the layout,
1570 figure out the proper alignment now. */
1571 if (dont_output_data && DECL_SIZE (decl) == 0
1572 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1573 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1575 /* Some object file formats have a maximum alignment which they support.
1576 In particular, a.out format supports a maximum alignment of 4. */
1577 #ifndef MAX_OFILE_ALIGNMENT
1578 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1580 if (align > MAX_OFILE_ALIGNMENT)
1582 warning_with_decl (decl,
1583 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1584 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1585 align = MAX_OFILE_ALIGNMENT;
1588 /* On some machines, it is good to increase alignment sometimes. */
1589 if (! DECL_USER_ALIGN (decl))
1591 #ifdef DATA_ALIGNMENT
1592 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1594 #ifdef CONSTANT_ALIGNMENT
1595 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1596 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1600 /* Reset the alignment in case we have made it tighter, so we can benefit
1601 from it in get_pointer_alignment. */
1602 DECL_ALIGN (decl) = align;
1603 set_mem_align (decl_rtl, align);
1605 /* Handle uninitialized definitions. */
1607 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1608 /* If the target can't output uninitialized but not common global data
1609 in .bss, then we have to use .data. */
1610 #if ! defined ASM_EMIT_BSS
1611 && DECL_COMMON (decl)
1613 && DECL_SECTION_NAME (decl) == NULL_TREE
1614 && ! dont_output_data)
1616 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1617 unsigned HOST_WIDE_INT rounded = size;
1619 /* Don't allocate zero bytes of common,
1620 since that means "undefined external" in the linker. */
1624 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1625 so that each uninitialized object starts on such a boundary. */
1626 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1627 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1628 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1630 /* Don't continue this line--convex cc version 4.1 would lose. */
1631 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1632 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1634 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1637 asm_emit_uninitialised (decl, name, size, rounded);
1642 /* Handle initialized definitions.
1643 Also handle uninitialized global definitions if -fno-common and the
1644 target doesn't support ASM_OUTPUT_BSS. */
1646 /* First make the assembler name(s) global if appropriate. */
1647 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1649 #ifdef ASM_WEAKEN_LABEL
1650 if (DECL_WEAK (decl))
1652 ASM_WEAKEN_LABEL (asm_out_file, name);
1653 /* Remove this variable from the pending weak list so that
1654 we do not emit multiple .weak directives for it. */
1655 remove_from_pending_weak_list
1656 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1660 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1663 /* Output any data that we will need to use the address of. */
1664 if (DECL_INITIAL (decl) == error_mark_node)
1665 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1666 else if (DECL_INITIAL (decl))
1667 reloc = output_addressed_constants (DECL_INITIAL (decl));
1669 /* Switch to the appropriate section. */
1670 resolve_unique_section (decl, reloc);
1671 variable_section (decl, reloc);
1673 /* dbxout.c needs to know this. */
1674 if (in_text_section ())
1675 DECL_IN_TEXT_SECTION (decl) = 1;
1677 /* Output the alignment of this data. */
1678 if (align > BITS_PER_UNIT)
1680 ASM_OUTPUT_ALIGN (asm_out_file,
1681 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1684 /* Do any machine/system dependent processing of the object. */
1685 #ifdef ASM_DECLARE_OBJECT_NAME
1686 last_assemble_variable_decl = decl;
1687 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1689 /* Standard thing is just output label for the object. */
1690 ASM_OUTPUT_LABEL (asm_out_file, name);
1691 #endif /* ASM_DECLARE_OBJECT_NAME */
1693 if (!dont_output_data)
1695 if (DECL_INITIAL (decl))
1696 /* Output the actual data. */
1697 output_constant (DECL_INITIAL (decl),
1698 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1701 /* Leave space for it. */
1702 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1706 /* Return 1 if type TYPE contains any pointers. */
1709 contains_pointers_p (type)
1712 switch (TREE_CODE (type))
1715 case REFERENCE_TYPE:
1716 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1717 so I'll play safe and return 1. */
1723 case QUAL_UNION_TYPE:
1726 /* For a type that has fields, see if the fields have pointers. */
1727 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1728 if (TREE_CODE (fields) == FIELD_DECL
1729 && contains_pointers_p (TREE_TYPE (fields)))
1735 /* An array type contains pointers if its element type does. */
1736 return contains_pointers_p (TREE_TYPE (type));
1743 /* Output something to declare an external symbol to the assembler.
1744 (Most assemblers don't need this, so we normally output nothing.)
1745 Do nothing if DECL is not external. */
1748 assemble_external (decl)
1749 tree decl ATTRIBUTE_UNUSED;
1751 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1752 main body of this code is only rarely exercised. To provide some
1753 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1754 open. If it's not, we should not be calling this function. */
1758 #ifdef ASM_OUTPUT_EXTERNAL
1759 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1761 rtx rtl = DECL_RTL (decl);
1763 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1764 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1766 /* Some systems do require some output. */
1767 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1768 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1774 /* Similar, for calling a library function FUN. */
1777 assemble_external_libcall (fun)
1778 rtx fun ATTRIBUTE_UNUSED;
1780 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1781 /* Declare library function name external when first used, if nec. */
1782 if (! SYMBOL_REF_USED (fun))
1784 SYMBOL_REF_USED (fun) = 1;
1785 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1790 /* Declare the label NAME global. */
1793 assemble_global (name)
1794 const char *name ATTRIBUTE_UNUSED;
1796 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1799 /* Assemble a label named NAME. */
1802 assemble_label (name)
1805 ASM_OUTPUT_LABEL (asm_out_file, name);
1808 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1809 If NAME starts with a *, the rest of NAME is output verbatim.
1810 Otherwise NAME is transformed in an implementation-defined way
1811 (usually by the addition of an underscore).
1812 Many macros in the tm file are defined to call this function. */
1815 assemble_name (file, name)
1819 const char *real_name;
1822 STRIP_NAME_ENCODING (real_name, name);
1824 id = maybe_get_identifier (real_name);
1826 TREE_SYMBOL_REFERENCED (id) = 1;
1829 fputs (&name[1], file);
1831 ASM_OUTPUT_LABELREF (file, name);
1834 /* Allocate SIZE bytes writable static space with a gensym name
1835 and return an RTX to refer to its address. */
1838 assemble_static_space (size)
1842 const char *namestring;
1846 if (flag_shared_data)
1850 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1852 namestring = ggc_strdup (name);
1854 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1856 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1857 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1860 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1861 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1864 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1865 so that each uninitialized object starts on such a boundary. */
1866 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1867 int rounded ATTRIBUTE_UNUSED
1868 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1869 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1870 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1871 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1878 /* Assemble the static constant template for function entry trampolines.
1879 This is done at most once per compilation.
1880 Returns an RTX for the address of the template. */
1882 #ifdef TRAMPOLINE_TEMPLATE
1884 assemble_trampoline_template ()
1890 /* By default, put trampoline templates in read-only data section. */
1892 #ifdef TRAMPOLINE_SECTION
1893 TRAMPOLINE_SECTION ();
1895 readonly_data_section ();
1898 /* Write the assembler code to define one. */
1899 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1902 ASM_OUTPUT_ALIGN (asm_out_file, align);
1905 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1906 TRAMPOLINE_TEMPLATE (asm_out_file);
1908 /* Record the rtl to refer to it. */
1909 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1910 name = ggc_strdup (label);
1911 return gen_rtx_SYMBOL_REF (Pmode, name);
1915 /* A and B are either alignments or offsets. Return the minimum alignment
1916 that may be assumed after adding the two together. */
1918 static inline unsigned
1922 return (a | b) & -(a | b);
1925 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1926 the alignment of the integer in bits. Return 1 if we were able to output
1927 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1931 assemble_integer (x, size, align, force)
1937 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1938 ASM_OUTPUT... macros. */
1940 if (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT))
1943 #ifdef ASM_OUTPUT_CHAR
1945 ASM_OUTPUT_CHAR (asm_out_file, x);
1948 #ifdef ASM_OUTPUT_SHORT
1950 ASM_OUTPUT_SHORT (asm_out_file, x);
1953 #ifdef ASM_OUTPUT_INT
1955 ASM_OUTPUT_INT (asm_out_file, x);
1958 #ifdef ASM_OUTPUT_DOUBLE_INT
1960 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1963 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1965 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1971 const char *asm_op = NULL;
1973 /* ??? This isn't quite as flexible as the ASM_OUTPUT_INT type hooks.
1974 At present powerpc-eabi can't jump -mrelocatable hoops, so you can
1975 get assembler errors from symbolic references in packed structs. */
1978 #ifdef UNALIGNED_SHORT_ASM_OP
1980 asm_op = UNALIGNED_SHORT_ASM_OP;
1983 #ifdef UNALIGNED_INT_ASM_OP
1985 asm_op = UNALIGNED_INT_ASM_OP;
1988 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
1990 asm_op = UNALIGNED_DOUBLE_INT_ASM_OP;
1997 fputs (asm_op, asm_out_file);
1998 output_addr_const (asm_out_file, x);
1999 fputc ('\n', asm_out_file);
2004 /* If we couldn't do it that way, there are two other possibilities: First,
2005 if the machine can output an explicit byte and this is a 1 byte constant,
2006 we can use ASM_OUTPUT_BYTE. */
2008 #ifdef ASM_OUTPUT_BYTE
2009 if (size == 1 && GET_CODE (x) == CONST_INT)
2011 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
2016 /* If SIZE is larger than a single word, try to output the constant
2017 one word at a time. */
2019 if (size > UNITS_PER_WORD)
2021 enum machine_mode mode
2022 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2023 unsigned align2 = min_align (align, BITS_PER_WORD);
2026 for (i = 0; i < size / UNITS_PER_WORD; i++)
2028 rtx word = operand_subword (x, i, 0, mode);
2031 if (! assemble_integer (word, UNITS_PER_WORD, align2, 0))
2035 if (i == size / UNITS_PER_WORD)
2037 /* If we output at least one word and then could not finish,
2038 there is no valid way to continue. */
2043 /* If unaligned, and this is a constant, emit it one byte at a time. */
2044 if (align < size * BITS_PER_UNIT)
2046 enum machine_mode omode, imode;
2049 omode = mode_for_size (BITS_PER_UNIT, MODE_INT, 0);
2050 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2052 for (i = 0; i < size; i++)
2054 rtx byte = simplify_subreg (omode, x, imode, i);
2057 if (! assemble_integer (byte, 1, BITS_PER_UNIT, 0))
2063 /* If we output at least one byte and then could not finish,
2064 there is no valid way to continue. */
2075 /* Assemble the floating-point constant D into an object of size MODE. */
2076 struct assemble_real_args
2079 enum machine_mode mode;
2086 struct assemble_real_args *args = (struct assemble_real_args *) p;
2087 REAL_VALUE_TYPE *d = args->d;
2088 enum machine_mode mode = args->mode;
2092 #ifdef ASM_OUTPUT_BYTE_FLOAT
2094 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, *d);
2097 #ifdef ASM_OUTPUT_SHORT_FLOAT
2099 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, *d);
2102 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2104 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, *d);
2107 #ifdef ASM_OUTPUT_FLOAT
2109 ASM_OUTPUT_FLOAT (asm_out_file, *d);
2113 #ifdef ASM_OUTPUT_DOUBLE
2115 ASM_OUTPUT_DOUBLE (asm_out_file, *d);
2119 #ifdef ASM_OUTPUT_LONG_DOUBLE
2122 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, *d);
2132 assemble_real (d, mode, align)
2134 enum machine_mode mode;
2137 struct assemble_real_args args;
2141 /* We cannot emit unaligned floating point constants. This is slightly
2142 complicated in that we don't know what "unaligned" means exactly. */
2143 #ifdef BIGGEST_FIELD_ALIGNMENT
2144 if (align >= BIGGEST_FIELD_ALIGNMENT)
2148 if (align < GET_MODE_ALIGNMENT (mode))
2151 if (do_float_handler (assemble_real_1, (PTR) &args))
2154 internal_error ("floating point trap outputting a constant");
2157 /* Here we combine duplicate floating constants to make
2158 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2160 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2161 For an integer, I0 is the low-order word and I1 is the high-order word.
2162 For a real number, I0 is the word with the low address
2163 and I1 is the word with the high address. */
2166 immed_double_const (i0, i1, mode)
2167 HOST_WIDE_INT i0, i1;
2168 enum machine_mode mode;
2172 if (GET_MODE_CLASS (mode) == MODE_INT
2173 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2175 /* We clear out all bits that don't belong in MODE, unless they and our
2176 sign bit are all one. So we get either a reasonable negative value
2177 or a reasonable unsigned value for this mode. */
2178 int width = GET_MODE_BITSIZE (mode);
2179 if (width < HOST_BITS_PER_WIDE_INT
2180 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2181 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2182 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2183 else if (width == HOST_BITS_PER_WIDE_INT
2184 && ! (i1 == ~0 && i0 < 0))
2186 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2187 /* We cannot represent this value as a constant. */
2190 /* If this would be an entire word for the target, but is not for
2191 the host, then sign-extend on the host so that the number will look
2192 the same way on the host that it would on the target.
2194 For example, when building a 64 bit alpha hosted 32 bit sparc
2195 targeted compiler, then we want the 32 bit unsigned value -1 to be
2196 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2197 The later confuses the sparc backend. */
2199 if (width < HOST_BITS_PER_WIDE_INT
2200 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2201 i0 |= ((HOST_WIDE_INT) (-1) << width);
2203 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2205 ??? Strictly speaking, this is wrong if we create a CONST_INT
2206 for a large unsigned constant with the size of MODE being
2207 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2208 wider mode. In that case we will mis-interpret it as a negative
2211 Unfortunately, the only alternative is to make a CONST_DOUBLE
2212 for any constant in any mode if it is an unsigned constant larger
2213 than the maximum signed integer in an int on the host. However,
2214 doing this will break everyone that always expects to see a CONST_INT
2215 for SImode and smaller.
2217 We have always been making CONST_INTs in this case, so nothing new
2220 if (width <= HOST_BITS_PER_WIDE_INT)
2221 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2223 /* If this integer fits in one word, return a CONST_INT. */
2224 if ((i1 == 0 && i0 >= 0)
2225 || (i1 == ~0 && i0 < 0))
2226 return GEN_INT (i0);
2228 /* We use VOIDmode for integers. */
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 (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2237 && GET_MODE (r) == mode)
2240 /* No; make a new one and add it to the chain. */
2241 r = gen_rtx_CONST_DOUBLE (mode, i0, i1);
2243 /* Don't touch const_double_chain if not inside any function. */
2244 if (current_function_decl != 0)
2246 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2247 const_double_chain = r;
2253 /* Return a CONST_DOUBLE for a specified `double' value
2254 and machine mode. */
2257 immed_real_const_1 (d, mode)
2259 enum machine_mode mode;
2261 union real_extract u;
2264 /* Get the desired `double' value as a sequence of ints
2265 since that is how they are stored in a CONST_DOUBLE. */
2269 /* Detect special cases. Check for NaN first, because some ports
2270 (specifically the i386) do not emit correct ieee-fp code by default, and
2271 thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2272 and if REAL_VALUES_EQUAL does a floating point comparison. */
2273 if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_IDENTICAL (dconst0, d))
2274 return CONST0_RTX (mode);
2275 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2276 return CONST1_RTX (mode);
2277 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst2, d))
2278 return CONST2_RTX (mode);
2280 if (sizeof u == sizeof (HOST_WIDE_INT))
2281 return immed_double_const (u.i[0], 0, mode);
2282 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2283 return immed_double_const (u.i[0], u.i[1], mode);
2285 /* The rest of this function handles the case where
2286 a float value requires more than 2 ints of space.
2287 It will be deleted as dead code on machines that don't need it. */
2289 /* Search the chain for an existing CONST_DOUBLE with the right value.
2290 If one is found, return it. */
2292 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2293 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2294 && GET_MODE (r) == mode)
2297 /* No; make a new one and add it to the chain.
2299 We may be called by an optimizer which may be discarding any memory
2300 allocated during its processing (such as combine and loop). However,
2301 we will be leaving this constant on the chain, so we cannot tolerate
2303 r = rtx_alloc (CONST_DOUBLE);
2305 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2307 /* If we aren't inside a function, don't put r on the
2308 const_double_chain. */
2309 if (current_function_decl != 0)
2311 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2312 const_double_chain = r;
2315 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2320 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2321 which must be a REAL_CST tree node. */
2324 immed_real_const (exp)
2327 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2330 /* At the end of a function, forget the memory-constants
2331 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2332 Also clear out real_constant_chain and clear out all the chain-pointers. */
2335 clear_const_double_mem ()
2339 for (r = const_double_chain; r; r = next)
2341 next = CONST_DOUBLE_CHAIN (r);
2342 CONST_DOUBLE_CHAIN (r) = 0;
2344 const_double_chain = 0;
2347 /* Given an expression EXP with a constant value,
2348 reduce it to the sum of an assembler symbol and an integer.
2349 Store them both in the structure *VALUE.
2350 Abort if EXP does not reduce. */
2355 HOST_WIDE_INT offset;
2359 decode_addr_const (exp, value)
2361 struct addr_const *value;
2363 tree target = TREE_OPERAND (exp, 0);
2369 if (TREE_CODE (target) == COMPONENT_REF
2370 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2373 offset += int_byte_position (TREE_OPERAND (target, 1));
2374 target = TREE_OPERAND (target, 0);
2376 else if (TREE_CODE (target) == ARRAY_REF
2377 || TREE_CODE (target) == ARRAY_RANGE_REF)
2379 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2380 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2381 target = TREE_OPERAND (target, 0);
2387 switch (TREE_CODE (target))
2391 x = DECL_RTL (target);
2395 x = gen_rtx_MEM (FUNCTION_MODE,
2396 gen_rtx_LABEL_REF (VOIDmode,
2397 label_rtx (TREE_OPERAND (exp, 0))));
2405 x = TREE_CST_RTL (target);
2412 if (GET_CODE (x) != MEM)
2417 value->offset = offset;
2420 enum kind { RTX_DOUBLE, RTX_INT };
2423 ENUM_BITFIELD(kind) kind : 16;
2424 ENUM_BITFIELD(machine_mode) mode : 16;
2426 union real_extract du;
2427 struct addr_const addr;
2428 struct {HOST_WIDE_INT high, low;} di;
2432 /* Uniquize all constants that appear in memory.
2433 Each constant in memory thus far output is recorded
2434 in `const_hash_table' with a `struct constant_descriptor'
2435 that contains a polish representation of the value of
2438 We cannot store the trees in the hash table
2439 because the trees may be temporary. */
2441 struct constant_descriptor
2443 struct constant_descriptor *next;
2446 /* Make sure the data is reasonably aligned. */
2449 unsigned char contents[1];
2450 #ifdef HAVE_LONG_DOUBLE
2459 #define MAX_HASH_TABLE 1009
2460 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2462 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2463 out a string constant, we defer output of the constants until we know
2464 they are actually used. This will be if something takes its address or if
2465 there is a usage of the string in the RTL of a function. */
2467 #define STRHASH(x) ((hashval_t)((long)(x) >> 3))
2469 struct deferred_string
2476 static htab_t const_str_htab;
2478 /* Mark a const_hash_table descriptor for GC. */
2481 mark_const_hash_entry (ptr)
2484 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2488 ggc_mark_rtx (desc->rtl);
2493 /* Mark the hash-table element X (which is really a pointer to an
2494 struct deferred_string *). */
2497 mark_const_str_htab_1 (x, data)
2499 void *data ATTRIBUTE_UNUSED;
2501 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2505 /* Mark a const_str_htab for GC. */
2508 mark_const_str_htab (htab)
2511 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2514 /* Returns a hash code for X (which is a really a
2515 struct deferred_string *). */
2518 const_str_htab_hash (x)
2521 return STRHASH (((const struct deferred_string *) x)->label);
2524 /* Returns non-zero if the value represented by X (which is really a
2525 struct deferred_string *) is the same as that given by Y
2526 (which is really a char *). */
2529 const_str_htab_eq (x, y)
2533 return (((const struct deferred_string *) x)->label == (const char *) y);
2536 /* Delete the hash table entry dfsp. */
2539 const_str_htab_del (dfsp)
2545 /* Compute a hash code for a constant expression. */
2553 enum tree_code code = TREE_CODE (exp);
2555 /* Either set P and LEN to the address and len of something to hash and
2556 exit the switch or return a value. */
2561 p = (char *) &TREE_INT_CST (exp);
2562 len = sizeof TREE_INT_CST (exp);
2566 p = (char *) &TREE_REAL_CST (exp);
2567 len = sizeof TREE_REAL_CST (exp);
2571 p = TREE_STRING_POINTER (exp);
2572 len = TREE_STRING_LENGTH (exp);
2576 return (const_hash (TREE_REALPART (exp)) * 5
2577 + const_hash (TREE_IMAGPART (exp)));
2580 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2584 len = int_size_in_bytes (TREE_TYPE (exp));
2585 tmp = (char *) alloca (len);
2586 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2594 /* For record type, include the type in the hashing.
2595 We do not do so for array types
2596 because (1) the sizes of the elements are sufficient
2597 and (2) distinct array types can have the same constructor.
2598 Instead, we include the array size because the constructor could
2600 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2601 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2604 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2605 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2607 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2608 if (TREE_VALUE (link))
2610 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2617 struct addr_const value;
2619 decode_addr_const (exp, &value);
2620 if (GET_CODE (value.base) == SYMBOL_REF)
2622 /* Don't hash the address of the SYMBOL_REF;
2623 only use the offset and the symbol name. */
2625 p = XSTR (value.base, 0);
2626 for (i = 0; p[i] != 0; i++)
2627 hi = ((hi * 613) + (unsigned) (p[i]));
2629 else if (GET_CODE (value.base) == LABEL_REF)
2630 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2634 hi &= (1 << HASHBITS) - 1;
2635 hi %= MAX_HASH_TABLE;
2641 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2642 + const_hash (TREE_OPERAND (exp, 1)));
2646 case NON_LVALUE_EXPR:
2647 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2650 /* A language specific constant. Just hash the code. */
2651 return (int) code % MAX_HASH_TABLE;
2654 /* Compute hashing function */
2656 for (i = 0; i < len; i++)
2657 hi = ((hi * 613) + (unsigned) (p[i]));
2659 hi &= (1 << HASHBITS) - 1;
2660 hi %= MAX_HASH_TABLE;
2664 /* Compare a constant expression EXP with a constant-descriptor DESC.
2665 Return 1 if DESC describes a constant with the same value as EXP. */
2668 compare_constant (exp, desc)
2670 struct constant_descriptor *desc;
2672 return 0 != compare_constant_1 (exp, desc->u.contents);
2675 /* Compare constant expression EXP with a substring P of a constant descriptor.
2676 If they match, return a pointer to the end of the substring matched.
2677 If they do not match, return 0.
2679 Since descriptors are written in polish prefix notation,
2680 this function can be used recursively to test one operand of EXP
2681 against a subdescriptor, and if it succeeds it returns the
2682 address of the subdescriptor for the next operand. */
2684 static const unsigned char *
2685 compare_constant_1 (exp, p)
2687 const unsigned char *p;
2689 const unsigned char *strp;
2691 enum tree_code code = TREE_CODE (exp);
2693 if (code != (enum tree_code) *p++)
2696 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2697 switch, or return the result of the comparison. */
2702 /* Integer constants are the same only if the same width of type. */
2703 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2706 strp = (unsigned char *) &TREE_INT_CST (exp);
2707 len = sizeof TREE_INT_CST (exp);
2711 /* Real constants are the same only if the same width of type. */
2712 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2715 strp = (unsigned char *) &TREE_REAL_CST (exp);
2716 len = sizeof TREE_REAL_CST (exp);
2720 if (flag_writable_strings)
2723 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2726 strp = (const unsigned char *)TREE_STRING_POINTER (exp);
2727 len = TREE_STRING_LENGTH (exp);
2728 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2729 sizeof TREE_STRING_LENGTH (exp)))
2732 p += sizeof TREE_STRING_LENGTH (exp);
2736 p = compare_constant_1 (TREE_REALPART (exp), p);
2740 return compare_constant_1 (TREE_IMAGPART (exp), p);
2743 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2745 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2746 unsigned char *tmp = (unsigned char *) alloca (len);
2748 get_set_constructor_bytes (exp, tmp, len);
2749 strp = (unsigned char *) tmp;
2750 if (memcmp ((char *) &xlen, p, sizeof xlen))
2759 int length = list_length (CONSTRUCTOR_ELTS (exp));
2761 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2762 int have_purpose = 0;
2764 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2765 if (TREE_PURPOSE (link))
2768 if (memcmp ((char *) &length, p, sizeof length))
2773 /* For record constructors, insist that the types match.
2774 For arrays, just verify both constructors are for arrays.
2775 Then insist that either both or none have any TREE_PURPOSE
2777 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2778 type = TREE_TYPE (exp);
2782 if (memcmp ((char *) &type, p, sizeof type))
2785 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2787 if (memcmp ((char *) &mode, p, sizeof mode))
2795 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2798 p += sizeof have_purpose;
2800 /* For arrays, insist that the size in bytes match. */
2801 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2803 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2805 if (memcmp ((char *) &size, p, sizeof size))
2811 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2813 if (TREE_VALUE (link))
2815 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2822 if (memcmp ((char *) &zero, p, sizeof zero))
2828 if (TREE_PURPOSE (link)
2829 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2831 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2832 sizeof TREE_PURPOSE (link)))
2835 p += sizeof TREE_PURPOSE (link);
2837 else if (TREE_PURPOSE (link))
2839 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2842 else if (have_purpose)
2846 if (memcmp ((char *) &zero, p, sizeof zero))
2858 struct addr_const value;
2860 decode_addr_const (exp, &value);
2861 strp = (unsigned char *) &value.offset;
2862 len = sizeof value.offset;
2863 /* Compare the offset. */
2865 if (*p++ != *strp++)
2868 /* Compare symbol name. */
2869 strp = (const unsigned char *) XSTR (value.base, 0);
2870 len = strlen ((const char *) strp) + 1;
2877 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2881 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2885 case NON_LVALUE_EXPR:
2886 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2890 tree new = (*lang_hooks.expand_constant) (exp);
2893 return compare_constant_1 (new, p);
2899 /* Compare constant contents. */
2901 if (*p++ != *strp++)
2907 /* Construct a constant descriptor for the expression EXP.
2908 It is up to the caller to enter the descriptor in the hash table. */
2910 static struct constant_descriptor *
2911 record_constant (exp)
2914 struct constant_descriptor *next = 0;
2919 /* Make a struct constant_descriptor. The first three pointers will
2920 be filled in later. Here we just leave space for them. */
2922 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2923 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2924 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2926 /* Align the descriptor for the data payload. */
2927 pad = (offsetof (struct constant_descriptor, u)
2928 - offsetof(struct constant_descriptor, rtl)
2929 - sizeof(next->rtl));
2931 obstack_blank (&permanent_obstack, pad);
2933 record_constant_1 (exp);
2934 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2937 /* Add a description of constant expression EXP
2938 to the object growing in `permanent_obstack'.
2939 No need to return its address; the caller will get that
2940 from the obstack when the object is complete. */
2943 record_constant_1 (exp)
2946 const unsigned char *strp;
2948 enum tree_code code = TREE_CODE (exp);
2950 obstack_1grow (&permanent_obstack, (unsigned int) code);
2955 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2956 strp = (unsigned char *) &TREE_INT_CST (exp);
2957 len = sizeof TREE_INT_CST (exp);
2961 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2962 strp = (unsigned char *) &TREE_REAL_CST (exp);
2963 len = sizeof TREE_REAL_CST (exp);
2967 if (flag_writable_strings)
2970 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2971 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2972 len = TREE_STRING_LENGTH (exp);
2973 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2974 sizeof TREE_STRING_LENGTH (exp));
2978 record_constant_1 (TREE_REALPART (exp));
2979 record_constant_1 (TREE_IMAGPART (exp));
2983 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2985 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2986 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2987 obstack_blank (&permanent_obstack, nbytes);
2988 get_set_constructor_bytes
2989 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2996 int length = list_length (CONSTRUCTOR_ELTS (exp));
2997 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2999 int have_purpose = 0;
3001 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3002 if (TREE_PURPOSE (link))
3005 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
3007 /* For record constructors, insist that the types match.
3008 For arrays, just verify both constructors are for arrays
3009 of the same mode. Then insist that either both or none
3010 have any TREE_PURPOSE values. */
3011 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3012 type = TREE_TYPE (exp);
3016 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
3017 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3018 obstack_grow (&permanent_obstack, &mode, sizeof mode);
3020 obstack_grow (&permanent_obstack, (char *) &have_purpose,
3021 sizeof have_purpose);
3023 /* For arrays, insist that the size in bytes match. */
3024 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3026 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3027 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
3030 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3032 if (TREE_VALUE (link))
3033 record_constant_1 (TREE_VALUE (link));
3038 obstack_grow (&permanent_obstack,
3039 (char *) &zero, sizeof zero);
3042 if (TREE_PURPOSE (link)
3043 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
3044 obstack_grow (&permanent_obstack,
3045 (char *) &TREE_PURPOSE (link),
3046 sizeof TREE_PURPOSE (link));
3047 else if (TREE_PURPOSE (link))
3048 record_constant_1 (TREE_PURPOSE (link));
3049 else if (have_purpose)
3053 obstack_grow (&permanent_obstack,
3054 (char *) &zero, sizeof zero);
3062 struct addr_const value;
3064 decode_addr_const (exp, &value);
3065 /* Record the offset. */
3066 obstack_grow (&permanent_obstack,
3067 (char *) &value.offset, sizeof value.offset);
3069 switch (GET_CODE (value.base))
3072 /* Record the symbol name. */
3073 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3074 strlen (XSTR (value.base, 0)) + 1);
3077 /* Record the address of the CODE_LABEL. It may not have
3078 been emitted yet, so it's UID may be zero. But pointer
3079 identity is good enough. */
3080 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3092 record_constant_1 (TREE_OPERAND (exp, 0));
3093 record_constant_1 (TREE_OPERAND (exp, 1));
3098 case NON_LVALUE_EXPR:
3099 record_constant_1 (TREE_OPERAND (exp, 0));
3104 tree new = (*lang_hooks.expand_constant) (exp);
3107 record_constant_1 (exp);
3112 /* Record constant contents. */
3113 obstack_grow (&permanent_obstack, strp, len);
3116 /* Record a list of constant expressions that were passed to
3117 output_constant_def but that could not be output right away. */
3119 struct deferred_constant
3121 struct deferred_constant *next;
3127 static struct deferred_constant *deferred_constants;
3129 /* Another list of constants which should be output after the
3131 static struct deferred_constant *after_function_constants;
3133 /* Nonzero means defer output of addressed subconstants
3134 (i.e., those for which output_constant_def is called.) */
3135 static int defer_addressed_constants_flag;
3137 /* Start deferring output of subconstants. */
3140 defer_addressed_constants ()
3142 defer_addressed_constants_flag++;
3145 /* Stop deferring output of subconstants,
3146 and output now all those that have been deferred. */
3149 output_deferred_addressed_constants ()
3151 struct deferred_constant *p, *next;
3153 defer_addressed_constants_flag--;
3155 if (defer_addressed_constants_flag > 0)
3158 for (p = deferred_constants; p; p = next)
3160 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3165 deferred_constants = 0;
3168 /* Output any constants which should appear after a function. */
3171 output_after_function_constants ()
3173 struct deferred_constant *p, *next;
3175 for (p = after_function_constants; p; p = next)
3177 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3182 after_function_constants = 0;
3185 /* Make a copy of the whole tree structure for a constant.
3186 This handles the same types of nodes that compare_constant
3187 and record_constant handle. */
3193 switch (TREE_CODE (exp))
3196 /* For ADDR_EXPR, we do not want to copy the decl whose address
3197 is requested. We do want to copy constants though. */
3198 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3199 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3200 copy_constant (TREE_OPERAND (exp, 0)));
3202 return copy_node (exp);
3207 return copy_node (exp);
3210 return build_complex (TREE_TYPE (exp),
3211 copy_constant (TREE_REALPART (exp)),
3212 copy_constant (TREE_IMAGPART (exp)));
3216 return build (TREE_CODE (exp), TREE_TYPE (exp),
3217 copy_constant (TREE_OPERAND (exp, 0)),
3218 copy_constant (TREE_OPERAND (exp, 1)));
3222 case NON_LVALUE_EXPR:
3223 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3224 copy_constant (TREE_OPERAND (exp, 0)));
3228 tree copy = copy_node (exp);
3229 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3232 CONSTRUCTOR_ELTS (copy) = list;
3233 for (tail = list; tail; tail = TREE_CHAIN (tail))
3234 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3235 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3236 for (tail = list; tail; tail = TREE_CHAIN (tail))
3237 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3247 /* Return an rtx representing a reference to constant data in memory
3248 for the constant expression EXP.
3250 If assembler code for such a constant has already been output,
3251 return an rtx to refer to it.
3252 Otherwise, output such a constant in memory (or defer it for later)
3253 and generate an rtx for it.
3255 If DEFER is non-zero, the output of string constants can be deferred
3256 and output only if referenced in the function after all optimizations.
3258 The TREE_CST_RTL of EXP is set up to point to that rtx.
3259 The const_hash_table records which constants already have label strings. */
3262 output_constant_def (exp, defer)
3267 struct constant_descriptor *desc;
3268 struct deferred_string **defstr;
3272 int after_function = 0;
3276 /* We can't just use the saved RTL if this is a defererred string constant
3277 and we are not to defer anymode. */
3278 if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3279 && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3280 return TREE_CST_RTL (exp);
3282 /* Make sure any other constants whose addresses appear in EXP
3283 are assigned label numbers. */
3285 reloc = output_addressed_constants (exp);
3287 /* Compute hash code of EXP. Search the descriptors for that hash code
3288 to see if any of them describes EXP. If yes, the descriptor records
3289 the label number already assigned. */
3291 hash = const_hash (exp) % MAX_HASH_TABLE;
3293 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3294 if (compare_constant (exp, desc))
3299 /* No constant equal to EXP is known to have been output.
3300 Make a constant descriptor to enter EXP in the hash table.
3301 Assign the label number and record it in the descriptor for
3302 future calls to this function to find. */
3304 /* Create a string containing the label name, in LABEL. */
3305 labelno = const_labelno++;
3306 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3308 desc = record_constant (exp);
3309 desc->next = const_hash_table[hash];
3310 desc->label = ggc_strdup (label);
3311 const_hash_table[hash] = desc;
3313 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3315 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3316 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3318 set_mem_attributes (rtl, exp, 1);
3319 set_mem_alias_set (rtl, 0);
3320 set_mem_alias_set (rtl, const_alias_set);
3327 if (TREE_CODE (exp) != INTEGER_CST)
3328 TREE_CST_RTL (exp) = rtl;
3330 /* Optionally set flags or add text to the name to record information
3331 such as that it is a function name. If the name is changed, the macro
3332 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3333 #ifdef ENCODE_SECTION_INFO
3334 /* A previously-processed constant would already have section info
3338 ENCODE_SECTION_INFO (exp);
3340 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3344 #ifdef CONSTANT_AFTER_FUNCTION_P
3345 if (current_function_decl != 0
3346 && CONSTANT_AFTER_FUNCTION_P (exp))
3351 && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3352 && (!defer || defer_addressed_constants_flag || after_function))
3354 defstr = (struct deferred_string **)
3355 htab_find_slot_with_hash (const_str_htab, desc->label,
3356 STRHASH (desc->label), NO_INSERT);
3359 /* If the string is currently deferred but we need to output it now,
3360 remove it from deferred string hash table. */
3362 labelno = (*defstr)->labelno;
3363 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3364 htab_clear_slot (const_str_htab, (void **) defstr);
3368 /* If this is the first time we've seen this particular constant,
3369 output it (or defer its output for later). */
3372 if (defer_addressed_constants_flag || after_function)
3374 struct deferred_constant *p
3375 = (struct deferred_constant *)
3376 xmalloc (sizeof (struct deferred_constant));
3378 p->exp = copy_constant (exp);
3380 p->labelno = labelno;
3383 p->next = after_function_constants;
3384 after_function_constants = p;
3388 p->next = deferred_constants;
3389 deferred_constants = p;
3394 /* Do no output if -fsyntax-only. */
3395 if (! flag_syntax_only)
3397 if (TREE_CODE (exp) != STRING_CST
3399 || flag_writable_strings
3400 || (defstr = (struct deferred_string **)
3401 htab_find_slot_with_hash (const_str_htab,
3403 STRHASH (desc->label),
3405 output_constant_def_contents (exp, reloc, labelno);
3408 struct deferred_string *p;
3410 p = (struct deferred_string *)
3411 xmalloc (sizeof (struct deferred_string));
3413 p->exp = copy_constant (exp);
3414 p->label = desc->label;
3415 p->labelno = labelno;
3417 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3426 /* Now output assembler code to define the label for EXP,
3427 and follow it with the data of EXP. */
3430 output_constant_def_contents (exp, reloc, labelno)
3437 /* Align the location counter as required by EXP's data type. */
3438 align = TYPE_ALIGN (TREE_TYPE (exp));
3439 #ifdef CONSTANT_ALIGNMENT
3440 align = CONSTANT_ALIGNMENT (exp, align);
3443 if (IN_NAMED_SECTION (exp))
3444 named_section (exp, NULL, reloc);
3447 /* First switch to text section, except for writable strings. */
3448 #ifdef SELECT_SECTION
3449 SELECT_SECTION (exp, reloc, align);
3451 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3452 || (flag_pic && reloc))
3455 readonly_data_section ();
3459 if (align > BITS_PER_UNIT)
3461 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3464 /* Output the label itself. */
3465 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3467 /* Output the value of EXP. */
3468 output_constant (exp,
3469 (TREE_CODE (exp) == STRING_CST
3470 ? MAX (TREE_STRING_LENGTH (exp),
3471 int_size_in_bytes (TREE_TYPE (exp)))
3472 : int_size_in_bytes (TREE_TYPE (exp))),
3477 /* Structure to represent sufficient information about a constant so that
3478 it can be output when the constant pool is output, so that function
3479 integration can be done, and to simplify handling on machines that reference
3480 constant pool as base+displacement. */
3482 struct pool_constant
3484 struct constant_descriptor *desc;
3485 struct pool_constant *next, *next_sym;
3487 enum machine_mode mode;
3490 HOST_WIDE_INT offset;
3494 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3495 The argument is XSTR (... , 0) */
3497 #define SYMHASH(LABEL) \
3498 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3500 /* Initialize constant pool hashing for a new function. */
3503 init_varasm_status (f)
3506 struct varasm_status *p;
3507 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3509 p->x_const_rtx_hash_table
3510 = ((struct constant_descriptor **)
3511 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3512 p->x_const_rtx_sym_hash_table
3513 = ((struct pool_constant **)
3514 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3516 p->x_first_pool = p->x_last_pool = 0;
3517 p->x_pool_offset = 0;
3518 p->x_const_double_chain = 0;
3521 /* Mark PC for GC. */
3524 mark_pool_constant (pc)
3525 struct pool_constant *pc;
3530 ggc_mark_rtx (pc->constant);
3531 ggc_mark_rtx (pc->desc->rtl);
3536 /* Mark P for GC. */
3539 mark_varasm_status (p)
3540 struct varasm_status *p;
3545 mark_pool_constant (p->x_first_pool);
3546 ggc_mark_rtx (p->x_const_double_chain);
3549 /* Clear out all parts of the state in F that can safely be discarded
3550 after the function has been compiled, to let garbage collection
3551 reclaim the memory. */
3554 free_varasm_status (f)
3557 struct varasm_status *p;
3562 /* Clear out the hash tables. */
3563 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3565 struct constant_descriptor *cd;
3567 cd = p->x_const_rtx_hash_table[i];
3570 struct constant_descriptor *next = cd->next;
3577 free (p->x_const_rtx_hash_table);
3578 free (p->x_const_rtx_sym_hash_table);
3585 /* Express an rtx for a constant integer (perhaps symbolic)
3586 as the sum of a symbol or label plus an explicit integer.
3587 They are stored into VALUE. */
3590 decode_rtx_const (mode, x, value)
3591 enum machine_mode mode;
3593 struct rtx_const *value;
3595 /* Clear the whole structure, including any gaps. */
3596 memset (value, 0, sizeof (struct rtx_const));
3598 value->kind = RTX_INT; /* Most usual kind. */
3601 switch (GET_CODE (x))
3604 value->kind = RTX_DOUBLE;
3605 if (GET_MODE (x) != VOIDmode)
3607 value->mode = GET_MODE (x);
3608 memcpy ((char *) &value->un.du,
3609 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3613 value->un.di.low = CONST_DOUBLE_LOW (x);
3614 value->un.di.high = CONST_DOUBLE_HIGH (x);
3619 value->un.addr.offset = INTVAL (x);
3625 value->un.addr.base = x;
3630 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3632 value->un.addr.base = XEXP (x, 0);
3633 value->un.addr.offset = INTVAL (XEXP (x, 1));
3635 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3637 value->un.addr.base = XEXP (x, 0);
3638 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3642 value->un.addr.base = x;
3643 value->un.addr.offset = 0;
3651 if (value->kind == RTX_INT && value->un.addr.base != 0)
3652 switch (GET_CODE (value->un.addr.base))
3655 /* Use the string's address, not the SYMBOL_REF's address,
3656 for the sake of addresses of library routines. */
3657 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3661 /* For a LABEL_REF, compare labels. */
3662 value->un.addr.base = XEXP (value->un.addr.base, 0);
3669 /* Given a MINUS expression, simplify it if both sides
3670 include the same symbol. */
3673 simplify_subtraction (x)
3676 struct rtx_const val0, val1;
3678 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3679 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3681 if (val0.un.addr.base == val1.un.addr.base)
3682 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3686 /* Compute a hash code for a constant RTL expression. */
3689 const_hash_rtx (mode, x)
3690 enum machine_mode mode;
3696 struct rtx_const value;
3697 decode_rtx_const (mode, x, &value);
3699 /* Compute hashing function */
3701 for (i = 0; i < sizeof value / sizeof (int); i++)
3702 hi += ((int *) &value)[i];
3704 hi &= (1 << HASHBITS) - 1;
3705 hi %= MAX_RTX_HASH_TABLE;
3709 /* Compare a constant rtl object X with a constant-descriptor DESC.
3710 Return 1 if DESC describes a constant with the same value as X. */
3713 compare_constant_rtx (mode, x, desc)
3714 enum machine_mode mode;
3716 struct constant_descriptor *desc;
3718 int *p = (int *) desc->u.contents;
3721 struct rtx_const value;
3723 decode_rtx_const (mode, x, &value);
3724 strp = (int *) &value;
3725 len = sizeof value / sizeof (int);
3727 /* Compare constant contents. */
3729 if (*p++ != *strp++)
3735 /* Construct a constant descriptor for the rtl-expression X.
3736 It is up to the caller to enter the descriptor in the hash table. */
3738 static struct constant_descriptor *
3739 record_constant_rtx (mode, x)
3740 enum machine_mode mode;
3743 struct constant_descriptor *ptr;
3745 ptr = ((struct constant_descriptor *)
3746 xcalloc (1, (offsetof (struct constant_descriptor, u)
3747 + sizeof (struct rtx_const))));
3748 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3753 /* Given a constant rtx X, return a MEM for the location in memory at which
3754 this constant has been placed. Return 0 if it not has been placed yet. */
3757 mem_for_const_double (x)
3760 enum machine_mode mode = GET_MODE (x);
3761 struct constant_descriptor *desc;
3763 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3765 if (compare_constant_rtx (mode, x, desc))
3771 /* Given a constant rtx X, make (or find) a memory constant for its value
3772 and return a MEM rtx to refer to it in memory. */
3775 force_const_mem (mode, x)
3776 enum machine_mode mode;
3780 struct constant_descriptor *desc;
3783 struct pool_constant *pool;
3786 /* Compute hash code of X. Search the descriptors for that hash code
3787 to see if any of them describes X. If yes, we have an rtx to use. */
3788 hash = const_hash_rtx (mode, x);
3789 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3790 if (compare_constant_rtx (mode, x, desc))
3793 /* No constant equal to X is known to have been output.
3794 Make a constant descriptor to enter X in the hash table
3795 and make a MEM for it. */
3796 desc = record_constant_rtx (mode, x);
3797 desc->next = const_rtx_hash_table[hash];
3798 const_rtx_hash_table[hash] = desc;
3800 /* Align the location counter as required by EXP's data type. */
3801 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3802 #ifdef CONSTANT_ALIGNMENT
3803 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x), align);
3806 pool_offset += (align / BITS_PER_UNIT) - 1;
3807 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3809 if (GET_CODE (x) == LABEL_REF)
3810 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3812 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3813 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3817 pool->labelno = const_labelno;
3818 pool->align = align;
3819 pool->offset = pool_offset;
3826 last_pool->next = pool;
3829 pool_offset += GET_MODE_SIZE (mode);
3831 /* Create a string containing the label name, in LABEL. */
3832 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3836 /* Construct the SYMBOL_REF and the MEM. */
3838 pool->desc->rtl = def
3839 = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3840 set_mem_alias_set (def, const_alias_set);
3841 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3842 RTX_UNCHANGING_P (def) = 1;
3844 /* Add label to symbol hash table. */
3845 hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3846 pool->next_sym = const_rtx_sym_hash_table[hash];
3847 const_rtx_sym_hash_table[hash] = pool;
3849 /* Mark the symbol_ref as belonging to this constants pool. */
3850 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3851 current_function_uses_const_pool = 1;
3856 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3857 the corresponding pool_constant structure. */
3859 static struct pool_constant *
3860 find_pool_constant (f, addr)
3864 struct pool_constant *pool;
3865 const char *label = XSTR (addr, 0);
3867 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3868 pool = pool->next_sym)
3869 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3875 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3878 get_pool_constant (addr)
3881 return (find_pool_constant (cfun, addr))->constant;
3884 /* Likewise, but for the constant pool of a specific function. */
3887 get_pool_constant_for_function (f, addr)
3891 return (find_pool_constant (f, addr))->constant;
3894 /* Similar, return the mode. */
3897 get_pool_mode (addr)
3900 return (find_pool_constant (cfun, addr))->mode;
3904 get_pool_mode_for_function (f, addr)
3908 return (find_pool_constant (f, addr))->mode;
3911 /* Similar, return the offset in the constant pool. */
3914 get_pool_offset (addr)
3917 return (find_pool_constant (cfun, addr))->offset;
3920 /* Return the size of the constant pool. */
3928 /* Write all the constants in the constant pool. */
3931 output_constant_pool (fnname, fndecl)
3932 const char *fnname ATTRIBUTE_UNUSED;
3933 tree fndecl ATTRIBUTE_UNUSED;
3935 struct pool_constant *pool;
3937 union real_extract u;
3939 /* It is possible for gcc to call force_const_mem and then to later
3940 discard the instructions which refer to the constant. In such a
3941 case we do not need to output the constant. */
3942 mark_constant_pool ();
3944 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3945 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3948 for (pool = first_pool; pool; pool = pool->next)
3957 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3958 whose CODE_LABEL has been deleted. This can occur if a jump table
3959 is eliminated by optimization. If so, write a constant of zero
3960 instead. Note that this can also happen by turning the
3961 CODE_LABEL into a NOTE. */
3962 /* ??? This seems completely and utterly wrong. Certainly it's
3963 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3964 functioning even with INSN_DELETED_P and friends. */
3967 switch (GET_CODE (x))
3970 if (GET_CODE (XEXP (x, 0)) != PLUS
3971 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3973 tmp = XEXP (XEXP (x, 0), 0);
3978 if (INSN_DELETED_P (tmp)
3979 || (GET_CODE (tmp) == NOTE
3980 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3991 /* First switch to correct section. */
3992 #ifdef SELECT_RTX_SECTION
3993 SELECT_RTX_SECTION (pool->mode, x, pool->align);
3995 readonly_data_section ();
3998 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3999 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4000 pool->align, pool->labelno, done);
4003 assemble_align (pool->align);
4005 /* Output the label. */
4006 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4008 /* Output the value of the constant itself. */
4009 switch (GET_MODE_CLASS (pool->mode))
4012 if (GET_CODE (x) != CONST_DOUBLE)
4015 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4016 assemble_real (u.d, pool->mode, pool->align);
4020 case MODE_PARTIAL_INT:
4021 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4028 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4033 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4034 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4037 /* Done with this pool. */
4038 first_pool = last_pool = 0;
4041 /* Look through the instructions for this function, and mark all the
4042 entries in the constant pool which are actually being used.
4043 Emit used deferred strings. */
4046 mark_constant_pool ()
4049 struct pool_constant *pool;
4051 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4054 for (pool = first_pool; pool; pool = pool->next)
4057 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4059 mark_constants (PATTERN (insn));
4061 for (insn = current_function_epilogue_delay_list;
4063 insn = XEXP (insn, 1))
4065 mark_constants (PATTERN (insn));
4068 /* Look through appropriate parts of X, marking all entries in the
4069 constant pool which are actually being used. Entries that are only
4070 referenced by other constants are also marked as used. Emit
4071 deferred strings that are used. */
4078 const char *format_ptr;
4083 if (GET_CODE (x) == SYMBOL_REF)
4085 mark_constant (&x, NULL);
4089 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4090 insns, not any notes that may be attached. We don't want to mark
4091 a constant just because it happens to appear in a REG_EQUIV note. */
4094 mark_constants (PATTERN (x));
4098 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4100 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4102 switch (*format_ptr++)
4105 mark_constants (XEXP (x, i));
4109 if (XVEC (x, i) != 0)
4113 for (j = 0; j < XVECLEN (x, i); j++)
4114 mark_constants (XVECEXP (x, i, j));
4133 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4134 to as used. Emit referenced deferred strings. This function can
4135 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4138 mark_constant (current_rtx, data)
4140 void *data ATTRIBUTE_UNUSED;
4142 rtx x = *current_rtx;
4147 else if (GET_CODE (x) == SYMBOL_REF)
4149 if (CONSTANT_POOL_ADDRESS_P (x))
4151 struct pool_constant *pool = find_pool_constant (cfun, x);
4152 if (pool->mark == 0) {
4154 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4159 else if (STRING_POOL_ADDRESS_P (x))
4161 struct deferred_string **defstr;
4163 defstr = (struct deferred_string **)
4164 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4165 STRHASH (XSTR (x, 0)), NO_INSERT);
4168 struct deferred_string *p = *defstr;
4170 STRING_POOL_ADDRESS_P (x) = 0;
4171 output_constant_def_contents (p->exp, 0, p->labelno);
4172 htab_clear_slot (const_str_htab, (void **) defstr);
4179 /* Find all the constants whose addresses are referenced inside of EXP,
4180 and make sure assembler code with a label has been output for each one.
4181 Indicate whether an ADDR_EXPR has been encountered. */
4184 output_addressed_constants (exp)
4190 /* Give the front-end a chance to convert VALUE to something that
4191 looks more like a constant to the back-end. */
4192 exp = (*lang_hooks.expand_constant) (exp);
4194 switch (TREE_CODE (exp))
4197 /* Go inside any operations that get_inner_reference can handle and see
4198 if what's inside is a constant: no need to do anything here for
4199 addresses of variables or functions. */
4200 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4201 tem = TREE_OPERAND (tem, 0))
4204 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4205 || TREE_CODE (tem) == CONSTRUCTOR)
4206 output_constant_def (tem, 0);
4208 if (TREE_PUBLIC (tem))
4216 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4217 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4222 case NON_LVALUE_EXPR:
4223 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4227 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4228 if (TREE_VALUE (tem) != 0)
4229 reloc |= output_addressed_constants (TREE_VALUE (tem));
4239 /* Return nonzero if VALUE is a valid constant-valued expression
4240 for use in initializing a static variable; one that can be an
4241 element of a "constant" initializer.
4243 Return null_pointer_node if the value is absolute;
4244 if it is relocatable, return the variable that determines the relocation.
4245 We assume that VALUE has been folded as much as possible;
4246 therefore, we do not need to check for such things as
4247 arithmetic-combinations of integers. */
4250 initializer_constant_valid_p (value, endtype)
4254 /* Give the front-end a chance to convert VALUE to something that
4255 looks more like a constant to the back-end. */
4256 value = (*lang_hooks.expand_constant) (value);
4258 switch (TREE_CODE (value))
4261 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4262 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4263 && TREE_CONSTANT (value)
4264 && CONSTRUCTOR_ELTS (value))
4266 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4269 return TREE_STATIC (value) ? null_pointer_node : 0;
4275 return null_pointer_node;
4279 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4281 case VIEW_CONVERT_EXPR:
4282 case NON_LVALUE_EXPR:
4283 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4287 /* Allow conversions between pointer types. */
4288 if (POINTER_TYPE_P (TREE_TYPE (value))
4289 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4290 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4292 /* Allow conversions between real types. */
4293 if (FLOAT_TYPE_P (TREE_TYPE (value))
4294 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4295 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4297 /* Allow length-preserving conversions between integer types. */
4298 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4299 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4300 && (TYPE_PRECISION (TREE_TYPE (value))
4301 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4302 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4304 /* Allow conversions between other integer types only if
4306 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4307 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4309 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4311 if (inner == null_pointer_node)
4312 return null_pointer_node;
4316 /* Allow (int) &foo provided int is as wide as a pointer. */
4317 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4318 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4319 && (TYPE_PRECISION (TREE_TYPE (value))
4320 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4321 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4324 /* Likewise conversions from int to pointers, but also allow
4325 conversions from 0. */
4326 if (POINTER_TYPE_P (TREE_TYPE (value))
4327 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4329 if (integer_zerop (TREE_OPERAND (value, 0)))
4330 return null_pointer_node;
4331 else if (TYPE_PRECISION (TREE_TYPE (value))
4332 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4333 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4337 /* Allow conversions to union types if the value inside is okay. */
4338 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4339 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4344 if (! INTEGRAL_TYPE_P (endtype)
4345 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4347 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4349 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4351 /* If either term is absolute, use the other terms relocation. */
4352 if (valid0 == null_pointer_node)
4354 if (valid1 == null_pointer_node)
4360 if (! INTEGRAL_TYPE_P (endtype)
4361 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4363 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4365 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4367 /* Win if second argument is absolute. */
4368 if (valid1 == null_pointer_node)
4370 /* Win if both arguments have the same relocation.
4371 Then the value is absolute. */
4372 if (valid0 == valid1 && valid0 != 0)
4373 return null_pointer_node;
4375 /* Since GCC guarantees that string constants are unique in the
4376 generated code, a subtraction between two copies of the same
4377 constant string is absolute. */
4378 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4379 valid1 && TREE_CODE (valid1) == STRING_CST &&
4380 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4381 return null_pointer_node;
4384 /* Support differences between labels. */
4385 if (INTEGRAL_TYPE_P (endtype))
4388 op0 = TREE_OPERAND (value, 0);
4389 op1 = TREE_OPERAND (value, 1);
4393 if (TREE_CODE (op0) == ADDR_EXPR
4394 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4395 && TREE_CODE (op1) == ADDR_EXPR
4396 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4397 return null_pointer_node;
4408 /* Output assembler code for constant EXP to FILE, with no label.
4409 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4410 Assumes output_addressed_constants has been done on EXP already.
4412 Generate exactly SIZE bytes of assembler data, padding at the end
4413 with zeros if necessary. SIZE must always be specified.
4415 SIZE is important for structure constructors,
4416 since trailing members may have been omitted from the constructor.
4417 It is also important for initialization of arrays from string constants
4418 since the full length of the string constant might not be wanted.
4419 It is also needed for initialization of unions, where the initializer's
4420 type is just one member, and that may not be as long as the union.
4422 There a case in which we would fail to output exactly SIZE bytes:
4423 for a structure constructor that wants to produce more than SIZE bytes.
4424 But such constructors will never be generated for any possible input.
4426 ALIGN is the alignment of the data in bits. */
4429 output_constant (exp, size, align)
4434 enum tree_code code;
4435 HOST_WIDE_INT thissize;
4437 /* Some front-ends use constants other than the standard language-indepdent
4438 varieties, but which may still be output directly. Give the front-end a
4439 chance to convert EXP to a language-independent representation. */
4440 exp = (*lang_hooks.expand_constant) (exp);
4442 if (size == 0 || flag_syntax_only)
4445 /* Eliminate any conversions since we'll be outputting the underlying
4447 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4448 || TREE_CODE (exp) == NON_LVALUE_EXPR
4449 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4450 exp = TREE_OPERAND (exp, 0);
4452 code = TREE_CODE (TREE_TYPE (exp));
4453 thissize = int_size_in_bytes (TREE_TYPE (exp));
4455 /* Allow a constructor with no elements for any data type.
4456 This means to fill the space with zeros. */
4457 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4459 assemble_zeros (size);
4463 if (TREE_CODE (exp) == FDESC_EXPR)
4465 #ifdef ASM_OUTPUT_FDESC
4466 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4467 tree decl = TREE_OPERAND (exp, 0);
4468 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4475 /* Now output the underlying data. If we've handling the padding, return.
4476 Otherwise, break and ensure THISSIZE is the size written. */
4484 case REFERENCE_TYPE:
4485 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4486 EXPAND_INITIALIZER),
4488 error ("initializer for integer value is too complicated");
4492 if (TREE_CODE (exp) != REAL_CST)
4493 error ("initializer for floating value is not a floating constant");
4495 assemble_real (TREE_REAL_CST (exp),
4496 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4501 output_constant (TREE_REALPART (exp), thissize / 2, align);
4502 output_constant (TREE_IMAGPART (exp), thissize / 2,
4503 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4507 if (TREE_CODE (exp) == CONSTRUCTOR)
4509 output_constructor (exp, size, align);
4512 else if (TREE_CODE (exp) == STRING_CST)
4514 thissize = MIN (TREE_STRING_LENGTH (exp), size);
4515 assemble_string (TREE_STRING_POINTER (exp), thissize);
4523 if (TREE_CODE (exp) == CONSTRUCTOR)
4524 output_constructor (exp, size, align);
4530 if (TREE_CODE (exp) == INTEGER_CST)
4531 assemble_integer (expand_expr (exp, NULL_RTX,
4532 VOIDmode, EXPAND_INITIALIZER),
4533 thissize, align, 1);
4534 else if (TREE_CODE (exp) == CONSTRUCTOR)
4536 unsigned char *buffer = (unsigned char *) alloca (thissize);
4537 if (get_set_constructor_bytes (exp, buffer, thissize))
4539 assemble_string ((char *) buffer, thissize);
4542 error ("unknown set constructor type");
4554 assemble_zeros (size);
4558 /* Subroutine of output_constructor, used for computing the size of
4559 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4560 type with an unspecified upper bound. */
4562 static unsigned HOST_WIDE_INT
4563 array_size_for_constructor (val)
4568 /* This code used to attempt to handle string constants that are not
4569 arrays of single-bytes, but nothing else does, so there's no point in
4571 if (TREE_CODE (val) == STRING_CST)
4572 return TREE_STRING_LENGTH (val);
4574 max_index = NULL_TREE;
4575 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4577 tree index = TREE_PURPOSE (i);
4579 if (TREE_CODE (index) == RANGE_EXPR)
4580 index = TREE_OPERAND (index, 1);
4581 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4585 if (max_index == NULL_TREE)
4588 /* Compute the total number of array elements. */
4589 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4591 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4592 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4594 /* Multiply by the array element unit size to find number of bytes. */
4595 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4597 return tree_low_cst (i, 1);
4600 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4601 Generate at least SIZE bytes, padding if necessary. */
4604 output_constructor (exp, size, align)
4609 tree type = TREE_TYPE (exp);
4610 tree link, field = 0;
4612 /* Number of bytes output or skipped so far.
4613 In other words, current position within the constructor. */
4614 HOST_WIDE_INT total_bytes = 0;
4615 /* Non-zero means BYTE contains part of a byte, to be output. */
4616 int byte_buffer_in_use = 0;
4619 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4622 if (TREE_CODE (type) == RECORD_TYPE)
4623 field = TYPE_FIELDS (type);
4625 if (TREE_CODE (type) == ARRAY_TYPE
4626 && TYPE_DOMAIN (type) != 0)
4627 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4629 /* As LINK goes through the elements of the constant,
4630 FIELD goes through the structure fields, if the constant is a structure.
4631 if the constant is a union, then we override this,
4632 by getting the field from the TREE_LIST element.
4633 But the constant could also be an array. Then FIELD is zero.
4635 There is always a maximum of one element in the chain LINK for unions
4636 (even if the initializer in a source program incorrectly contains
4638 for (link = CONSTRUCTOR_ELTS (exp);
4640 link = TREE_CHAIN (link),
4641 field = field ? TREE_CHAIN (field) : 0)
4643 tree val = TREE_VALUE (link);
4646 /* The element in a union constructor specifies the proper field
4648 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4649 || TREE_CODE (type) == QUAL_UNION_TYPE)
4650 && TREE_PURPOSE (link) != 0)
4651 field = TREE_PURPOSE (link);
4653 else if (TREE_CODE (type) == ARRAY_TYPE)
4654 index = TREE_PURPOSE (link);
4656 /* Eliminate the marker that makes a cast not be an lvalue. */
4660 if (index && TREE_CODE (index) == RANGE_EXPR)
4662 unsigned HOST_WIDE_INT fieldsize
4663 = int_size_in_bytes (TREE_TYPE (type));
4664 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4665 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4666 HOST_WIDE_INT index;
4667 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4669 for (index = lo_index; index <= hi_index; index++)
4671 /* Output the element's initial value. */
4673 assemble_zeros (fieldsize);
4675 output_constant (val, fieldsize, align2);
4677 /* Count its size. */
4678 total_bytes += fieldsize;
4681 else if (field == 0 || !DECL_BIT_FIELD (field))
4683 /* An element that is not a bit-field. */
4685 unsigned HOST_WIDE_INT fieldsize;
4686 /* Since this structure is static,
4687 we know the positions are constant. */
4688 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4689 unsigned int align2;
4692 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4693 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4695 /* Output any buffered-up bit-fields preceding this element. */
4696 if (byte_buffer_in_use)
4698 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4700 byte_buffer_in_use = 0;
4703 /* Advance to offset of this element.
4704 Note no alignment needed in an array, since that is guaranteed
4705 if each element has the proper size. */
4706 if ((field != 0 || index != 0) && pos != total_bytes)
4708 assemble_zeros (pos - total_bytes);
4712 /* Find the alignment of this element. */
4713 align2 = min_align (align, BITS_PER_UNIT * pos);
4715 /* Determine size this element should occupy. */
4720 /* If this is an array with an unspecified upper bound,
4721 the initializer determines the size. */
4722 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4723 but we cannot do this until the deprecated support for
4724 initializing zero-length array members is removed. */
4725 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4726 && TYPE_DOMAIN (TREE_TYPE (field))
4727 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4729 fieldsize = array_size_for_constructor (val);
4730 /* Given a non-empty initialization, this field had
4732 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4735 else if (DECL_SIZE_UNIT (field))
4737 /* ??? This can't be right. If the decl size overflows
4738 a host integer we will silently emit no data. */
4739 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4740 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4744 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4746 /* Output the element's initial value. */
4748 assemble_zeros (fieldsize);
4750 output_constant (val, fieldsize, align2);
4752 /* Count its size. */
4753 total_bytes += fieldsize;
4755 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4756 error ("invalid initial value for member `%s'",
4757 IDENTIFIER_POINTER (DECL_NAME (field)));
4760 /* Element that is a bit-field. */
4762 HOST_WIDE_INT next_offset = int_bit_position (field);
4763 HOST_WIDE_INT end_offset
4764 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4767 val = integer_zero_node;
4769 /* If this field does not start in this (or, next) byte,
4771 if (next_offset / BITS_PER_UNIT != total_bytes)
4773 /* Output remnant of any bit field in previous bytes. */
4774 if (byte_buffer_in_use)
4776 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4778 byte_buffer_in_use = 0;
4781 /* If still not at proper byte, advance to there. */
4782 if (next_offset / BITS_PER_UNIT != total_bytes)
4784 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4785 total_bytes = next_offset / BITS_PER_UNIT;
4789 if (! byte_buffer_in_use)
4792 /* We must split the element into pieces that fall within
4793 separate bytes, and combine each byte with previous or
4794 following bit-fields. */
4796 /* next_offset is the offset n fbits from the beginning of
4797 the structure to the next bit of this element to be processed.
4798 end_offset is the offset of the first bit past the end of
4800 while (next_offset < end_offset)
4804 HOST_WIDE_INT value;
4805 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4806 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4808 /* Advance from byte to byte
4809 within this element when necessary. */
4810 while (next_byte != total_bytes)
4812 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4817 /* Number of bits we can process at once
4818 (all part of the same byte). */
4819 this_time = MIN (end_offset - next_offset,
4820 BITS_PER_UNIT - next_bit);
4821 if (BYTES_BIG_ENDIAN)
4823 /* On big-endian machine, take the most significant bits
4824 first (of the bits that are significant)
4825 and put them into bytes from the most significant end. */
4826 shift = end_offset - next_offset - this_time;
4828 /* Don't try to take a bunch of bits that cross
4829 the word boundary in the INTEGER_CST. We can
4830 only select bits from the LOW or HIGH part
4832 if (shift < HOST_BITS_PER_WIDE_INT
4833 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4835 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4836 shift = HOST_BITS_PER_WIDE_INT;
4839 /* Now get the bits from the appropriate constant word. */
4840 if (shift < HOST_BITS_PER_WIDE_INT)
4841 value = TREE_INT_CST_LOW (val);
4842 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4844 value = TREE_INT_CST_HIGH (val);
4845 shift -= HOST_BITS_PER_WIDE_INT;
4850 /* Get the result. This works only when:
4851 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4852 byte |= (((value >> shift)
4853 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4854 << (BITS_PER_UNIT - this_time - next_bit));
4858 /* On little-endian machines,
4859 take first the least significant bits of the value
4860 and pack them starting at the least significant
4861 bits of the bytes. */
4862 shift = next_offset - int_bit_position (field);
4864 /* Don't try to take a bunch of bits that cross
4865 the word boundary in the INTEGER_CST. We can
4866 only select bits from the LOW or HIGH part
4868 if (shift < HOST_BITS_PER_WIDE_INT
4869 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4870 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4872 /* Now get the bits from the appropriate constant word. */
4873 if (shift < HOST_BITS_PER_WIDE_INT)
4874 value = TREE_INT_CST_LOW (val);
4875 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4877 value = TREE_INT_CST_HIGH (val);
4878 shift -= HOST_BITS_PER_WIDE_INT;
4883 /* Get the result. This works only when:
4884 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4885 byte |= (((value >> shift)
4886 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4890 next_offset += this_time;
4891 byte_buffer_in_use = 1;
4896 if (byte_buffer_in_use)
4898 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4902 if (total_bytes < size)
4903 assemble_zeros (size - total_bytes);
4907 /* This structure contains any weak symbol declarations waiting
4911 struct weak_syms * next;
4916 static struct weak_syms * weak_decls;
4918 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4919 associated with NAME. */
4922 add_weak (name, value)
4926 struct weak_syms *weak;
4928 weak = (struct weak_syms *) xmalloc (sizeof (struct weak_syms));
4933 weak->next = weak_decls;
4935 weak->value = value;
4941 /* Declare DECL to be a weak symbol. */
4947 if (! TREE_PUBLIC (decl))
4948 error_with_decl (decl, "weak declaration of `%s' must be public");
4949 else if (TREE_ASM_WRITTEN (decl))
4950 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4951 else if (SUPPORTS_WEAK)
4952 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4954 warning_with_decl (decl, "weak declaration of `%s' not supported");
4956 DECL_WEAK (decl) = 1;
4959 /* Emit any pending weak declarations. */
4966 struct weak_syms *t;
4967 for (t = weak_decls; t; t = t->next)
4969 #ifdef ASM_OUTPUT_WEAK_ALIAS
4970 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
4972 #ifdef ASM_WEAKEN_LABEL
4975 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4982 /* Remove NAME from the pending list of weak symbols. This prevents
4983 the compiler from emitting multiple .weak directives which confuses
4985 #ifdef ASM_WEAKEN_LABEL
4987 remove_from_pending_weak_list (name)
4990 struct weak_syms *t;
4991 struct weak_syms **p;
4993 for (p = &weak_decls; *p; )
4996 if (strcmp (name, t->name) == 0)
5005 #endif /* ASM_WEAKEN_LABEL */
5007 /* Emit an assembler directive to make the symbol for DECL an alias to
5008 the symbol for TARGET. */
5011 assemble_alias (decl, target)
5012 tree decl, target ATTRIBUTE_UNUSED;
5016 /* We must force creation of DECL_RTL for debug info generation, even though
5017 we don't use it here. */
5018 make_decl_rtl (decl, NULL);
5020 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5022 #ifdef ASM_OUTPUT_DEF
5023 /* Make name accessible from other files, if appropriate. */
5025 if (TREE_PUBLIC (decl))
5027 #ifdef ASM_WEAKEN_LABEL
5028 if (DECL_WEAK (decl))
5030 ASM_WEAKEN_LABEL (asm_out_file, name);
5031 /* Remove this function from the pending weak list so that
5032 we do not emit multiple .weak directives for it. */
5033 remove_from_pending_weak_list
5034 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5038 ASM_GLOBALIZE_LABEL (asm_out_file, name);
5041 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5042 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5044 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5046 TREE_ASM_WRITTEN (decl) = 1;
5048 #ifdef ASM_OUTPUT_WEAK_ALIAS
5049 if (! DECL_WEAK (decl))
5050 warning ("only weak aliases are supported in this configuration");
5052 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5053 TREE_ASM_WRITTEN (decl) = 1;
5055 warning ("alias definitions not supported in this configuration; ignored");
5060 /* Returns 1 if the target configuration supports defining public symbols
5061 so that one of them will be chosen at link time instead of generating a
5062 multiply-defined symbol error, whether through the use of weak symbols or
5063 a target-specific mechanism for having duplicates discarded. */
5066 supports_one_only ()
5068 if (SUPPORTS_ONE_ONLY)
5070 return SUPPORTS_WEAK;
5073 /* Set up DECL as a public symbol that can be defined in multiple
5074 translation units without generating a linker error. */
5077 make_decl_one_only (decl)
5080 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5083 TREE_PUBLIC (decl) = 1;
5085 if (TREE_CODE (decl) == VAR_DECL
5086 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5087 DECL_COMMON (decl) = 1;
5088 else if (SUPPORTS_ONE_ONLY)
5090 #ifdef MAKE_DECL_ONE_ONLY
5091 MAKE_DECL_ONE_ONLY (decl);
5093 DECL_ONE_ONLY (decl) = 1;
5095 else if (SUPPORTS_WEAK)
5096 DECL_WEAK (decl) = 1;
5104 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5105 const_str_htab_del);
5106 in_named_htab = htab_create (31, in_named_entry_hash,
5107 in_named_entry_eq, NULL);
5109 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5110 mark_const_hash_entry);
5111 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5112 mark_const_str_htab);
5114 const_alias_set = new_alias_set ();
5117 /* Select a set of attributes for section NAME based on the properties
5118 of DECL and whether or not RELOC indicates that DECL's initializer
5119 might contain runtime relocations.
5121 We make the section read-only and executable for a function decl,
5122 read-only for a const data decl, and writable for a non-const data decl. */
5125 default_section_type_flags (decl, name, reloc)
5132 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5133 flags = SECTION_CODE;
5134 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5137 flags = SECTION_WRITE;
5139 if (decl && DECL_ONE_ONLY (decl))
5140 flags |= SECTION_LINKONCE;
5142 if (strcmp (name, ".bss") == 0
5143 || strncmp (name, ".bss.", 5) == 0
5144 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5145 || strcmp (name, ".sbss") == 0
5146 || strncmp (name, ".sbss.", 6) == 0
5147 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5148 flags |= SECTION_BSS;
5153 /* Output assembly to switch to section NAME with attribute FLAGS.
5154 Four variants for common object file formats. */
5157 default_no_named_section (name, flags)
5158 const char *name ATTRIBUTE_UNUSED;
5159 unsigned int flags ATTRIBUTE_UNUSED;
5161 /* Some object formats don't support named sections at all. The
5162 front-end should already have flagged this as an error. */
5167 default_elf_asm_named_section (name, flags)
5171 char flagchars[10], *f = flagchars;
5174 if (! named_section_first_declaration (name))
5176 fprintf (asm_out_file, "\t.section\t%s\n", name);
5180 if (!(flags & SECTION_DEBUG))
5182 if (flags & SECTION_WRITE)
5184 if (flags & SECTION_CODE)
5186 if (flags & SECTION_SMALL)
5188 if (flags & SECTION_MERGE)
5190 if (flags & SECTION_STRINGS)
5194 if (flags & SECTION_BSS)
5199 if (flags & SECTION_ENTSIZE)
5200 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5201 name, flagchars, type, flags & SECTION_ENTSIZE);
5203 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5204 name, flagchars, type);
5208 default_coff_asm_named_section (name, flags)
5212 char flagchars[8], *f = flagchars;
5214 if (flags & SECTION_WRITE)
5216 if (flags & SECTION_CODE)
5220 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5224 default_pe_asm_named_section (name, flags)
5228 default_coff_asm_named_section (name, flags);
5230 if (flags & SECTION_LINKONCE)
5232 /* Functions may have been compiled at various levels of
5233 optimization so we can't use `same_size' here.
5234 Instead, have the linker pick one. */
5235 fprintf (asm_out_file, "\t.linkonce %s\n",
5236 (flags & SECTION_CODE ? "discard" : "same_size"));
5240 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5241 from SYMBOL is used in all classes derived from SYMBOL. */
5244 assemble_vtable_entry (symbol, offset)
5246 HOST_WIDE_INT offset;
5248 fputs ("\t.vtable_entry ", asm_out_file);
5249 output_addr_const (asm_out_file, symbol);
5250 fputs (", ", asm_out_file);
5251 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5252 fputc ('\n', asm_out_file);
5255 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5256 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5259 assemble_vtable_inherit (child, parent)
5262 fputs ("\t.vtable_inherit ", asm_out_file);
5263 output_addr_const (asm_out_file, child);
5264 fputs (", ", asm_out_file);
5265 output_addr_const (asm_out_file, parent);
5266 fputc ('\n', asm_out_file);