Makefile.am (noinst_LIBRARIES): New target.
[official-gcc.git] / gcc / varasm.c
blob73ba7cdd11c18c0a2c9448290d5e530eddd054db
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
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
15 for more details.
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
20 02111-1307, USA. */
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. */
30 #include "config.h"
31 #include "system.h"
32 #include "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "hard-reg-set.h"
38 #include "regs.h"
39 #include "output.h"
40 #include "real.h"
41 #include "toplev.h"
42 #include "obstack.h"
43 #include "hashtab.h"
44 #include "c-pragma.h"
45 #include "c-tree.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
52 #ifdef XCOFF_DEBUGGING_INFO
53 #include "xcoffout.h" /* Needed for external data
54 declarations for e.g. AIX 4.x. */
55 #endif
57 #ifndef TRAMPOLINE_ALIGNMENT
58 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
59 #endif
61 #ifndef ASM_STABS_OP
62 #define ASM_STABS_OP "\t.stabs\t"
63 #endif
65 /* The (assembler) name of the first globally-visible object output. */
66 const char *first_global_object_name;
67 const char *weak_global_object_name;
69 extern struct obstack permanent_obstack;
70 #define obstack_chunk_alloc xmalloc
72 struct addr_const;
73 struct constant_descriptor;
74 struct rtx_const;
75 struct pool_constant;
77 #define MAX_RTX_HASH_TABLE 61
79 struct varasm_status
81 /* Hash facility for making memory-constants
82 from constant rtl-expressions. It is used on RISC machines
83 where immediate integer arguments and constant addresses are restricted
84 so that such constants must be stored in memory.
86 This pool of constants is reinitialized for each function
87 so each function gets its own constants-pool that comes right before
88 it. */
89 struct constant_descriptor **x_const_rtx_hash_table;
90 struct pool_constant **x_const_rtx_sym_hash_table;
92 /* Pointers to first and last constant in pool. */
93 struct pool_constant *x_first_pool, *x_last_pool;
95 /* Current offset in constant pool (does not include any machine-specific
96 header). */
97 HOST_WIDE_INT x_pool_offset;
100 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
101 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
102 #define first_pool (cfun->varasm->x_first_pool)
103 #define last_pool (cfun->varasm->x_last_pool)
104 #define pool_offset (cfun->varasm->x_pool_offset)
106 /* Number for making the label on the next
107 constant that is stored in memory. */
109 int const_labelno;
111 /* Number for making the label on the next
112 static variable internal to a function. */
114 int var_labelno;
116 /* Carry information from ASM_DECLARE_OBJECT_NAME
117 to ASM_FINISH_DECLARE_OBJECT. */
119 int size_directive_output;
121 /* The last decl for which assemble_variable was called,
122 if it did ASM_DECLARE_OBJECT_NAME.
123 If the last call to assemble_variable didn't do that,
124 this holds 0. */
126 tree last_assemble_variable_decl;
128 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
129 So giving constant the alias set for the type will allow such
130 initializations to appear to conflict with the load of the constant. We
131 avoid this by giving all constants an alias set for just constants.
132 Since there will be no stores to that alias set, nothing will ever
133 conflict with them. */
135 static HOST_WIDE_INT const_alias_set;
137 static const char *strip_reg_name PARAMS ((const char *));
138 static int contains_pointers_p PARAMS ((tree));
139 static void decode_addr_const PARAMS ((tree, struct addr_const *));
140 static int const_hash PARAMS ((tree));
141 static int compare_constant PARAMS ((tree,
142 struct constant_descriptor *));
143 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
144 static struct constant_descriptor *record_constant PARAMS ((tree));
145 static void record_constant_1 PARAMS ((tree));
146 static tree copy_constant PARAMS ((tree));
147 static void output_constant_def_contents PARAMS ((tree, int, int));
148 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
149 struct rtx_const *));
150 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
151 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
152 struct constant_descriptor *));
153 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
154 rtx));
155 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
156 static void mark_constant_pool PARAMS ((void));
157 static void mark_constants PARAMS ((rtx));
158 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
159 static int output_addressed_constants PARAMS ((tree));
160 static void output_after_function_constants PARAMS ((void));
161 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
162 static unsigned min_align PARAMS ((unsigned, unsigned));
163 static void output_constructor PARAMS ((tree, HOST_WIDE_INT,
164 unsigned int));
165 static void globalize_decl PARAMS ((tree));
166 static void maybe_assemble_visibility PARAMS ((tree));
167 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
168 static hashval_t in_named_entry_hash PARAMS ((const PTR));
169 #ifdef ASM_OUTPUT_BSS
170 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
171 #endif
172 #ifdef BSS_SECTION_ASM_OP
173 #ifdef ASM_OUTPUT_ALIGNED_BSS
174 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
175 int, int));
176 #endif
177 #endif /* BSS_SECTION_ASM_OP */
178 static void mark_pool_constant PARAMS ((struct pool_constant *));
179 static void mark_const_hash_entry PARAMS ((void *));
180 static int mark_const_str_htab_1 PARAMS ((void **, void *));
181 static void mark_const_str_htab PARAMS ((void *));
182 static hashval_t const_str_htab_hash PARAMS ((const void *x));
183 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
184 static void const_str_htab_del PARAMS ((void *));
185 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
186 static void resolve_unique_section PARAMS ((tree, int, int));
187 static void mark_weak PARAMS ((tree));
189 static enum in_section { no_section, in_text, in_data, in_named
190 #ifdef BSS_SECTION_ASM_OP
191 , in_bss
192 #endif
193 #ifdef CTORS_SECTION_ASM_OP
194 , in_ctors
195 #endif
196 #ifdef DTORS_SECTION_ASM_OP
197 , in_dtors
198 #endif
199 #ifdef READONLY_DATA_SECTION_ASM_OP
200 , in_readonly_data
201 #endif
202 #ifdef EXTRA_SECTIONS
203 , EXTRA_SECTIONS
204 #endif
205 } in_section = no_section;
207 /* Return a non-zero value if DECL has a section attribute. */
208 #ifndef IN_NAMED_SECTION
209 #define IN_NAMED_SECTION(DECL) \
210 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
211 && DECL_SECTION_NAME (DECL) != NULL_TREE)
212 #endif
214 /* Text of section name when in_section == in_named. */
215 static const char *in_named_name;
217 /* Hash table of flags that have been used for a particular named section. */
219 struct in_named_entry
221 const char *name;
222 unsigned int flags;
223 bool declared;
226 static htab_t in_named_htab;
228 /* Define functions like text_section for any extra sections. */
229 #ifdef EXTRA_SECTION_FUNCTIONS
230 EXTRA_SECTION_FUNCTIONS
231 #endif
233 /* Tell assembler to switch to text section. */
235 void
236 text_section ()
238 if (in_section != in_text)
240 in_section = in_text;
241 #ifdef TEXT_SECTION
242 TEXT_SECTION ();
243 #else
244 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
245 #endif
249 /* Tell assembler to switch to data section. */
251 void
252 data_section ()
254 if (in_section != in_data)
256 in_section = in_data;
257 if (flag_shared_data)
259 #ifdef SHARED_SECTION_ASM_OP
260 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
261 #else
262 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
263 #endif
265 else
266 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
270 /* Tell assembler to ALWAYS switch to data section, in case
271 it's not sure where it is. */
273 void
274 force_data_section ()
276 in_section = no_section;
277 data_section ();
280 /* Tell assembler to switch to read-only data section. This is normally
281 the text section. */
283 void
284 readonly_data_section ()
286 #ifdef READONLY_DATA_SECTION
287 READONLY_DATA_SECTION (); /* Note this can call data_section. */
288 #else
289 #ifdef READONLY_DATA_SECTION_ASM_OP
290 if (in_section != in_readonly_data)
292 in_section = in_readonly_data;
293 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
294 fputc ('\n', asm_out_file);
296 #else
297 text_section ();
298 #endif
299 #endif
302 /* Determine if we're in the text section. */
305 in_text_section ()
307 return in_section == in_text;
310 /* Determine if we're in the data section. */
313 in_data_section ()
315 return in_section == in_data;
318 /* Helper routines for maintaining in_named_htab. */
320 static int
321 in_named_entry_eq (p1, p2)
322 const PTR p1;
323 const PTR p2;
325 const struct in_named_entry *old = p1;
326 const char *new = p2;
328 return strcmp (old->name, new) == 0;
331 static hashval_t
332 in_named_entry_hash (p)
333 const PTR p;
335 const struct in_named_entry *old = p;
336 return htab_hash_string (old->name);
339 /* If SECTION has been seen before as a named section, return the flags
340 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
341 set of flags for a section to have, so 0 does not mean that the section
342 has not been seen. */
344 unsigned int
345 get_named_section_flags (section)
346 const char *section;
348 struct in_named_entry **slot;
350 slot = (struct in_named_entry **)
351 htab_find_slot_with_hash (in_named_htab, section,
352 htab_hash_string (section), NO_INSERT);
354 return slot ? (*slot)->flags : 0;
357 /* Returns true if the section has been declared before. Sets internal
358 flag on this section in in_named_hash so subsequent calls on this
359 section will return false. */
361 bool
362 named_section_first_declaration (name)
363 const char *name;
365 struct in_named_entry **slot;
367 slot = (struct in_named_entry **)
368 htab_find_slot_with_hash (in_named_htab, name,
369 htab_hash_string (name), NO_INSERT);
370 if (! (*slot)->declared)
372 (*slot)->declared = true;
373 return true;
375 else
377 return false;
382 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
383 different set of flags, return false. */
385 bool
386 set_named_section_flags (section, flags)
387 const char *section;
388 unsigned int flags;
390 struct in_named_entry **slot, *entry;
392 slot = (struct in_named_entry **)
393 htab_find_slot_with_hash (in_named_htab, section,
394 htab_hash_string (section), INSERT);
395 entry = *slot;
397 if (!entry)
399 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
400 *slot = entry;
401 entry->name = ggc_strdup (section);
402 entry->flags = flags;
403 entry->declared = false;
405 else if (entry->flags != flags)
406 return false;
408 return true;
411 /* Tell assembler to change to section NAME with attributes FLAGS. */
413 void
414 named_section_flags (name, flags)
415 const char *name;
416 unsigned int flags;
418 if (in_section != in_named || strcmp (name, in_named_name) != 0)
420 if (! set_named_section_flags (name, flags))
421 abort ();
423 (*targetm.asm_out.named_section) (name, flags);
425 if (flags & SECTION_FORGET)
426 in_section = no_section;
427 else
429 in_named_name = ggc_strdup (name);
430 in_section = in_named;
435 /* Tell assembler to change to section NAME for DECL.
436 If DECL is NULL, just switch to section NAME.
437 If NAME is NULL, get the name from DECL.
438 If RELOC is 1, the initializer for DECL contains relocs. */
440 void
441 named_section (decl, name, reloc)
442 tree decl;
443 const char *name;
444 int reloc;
446 unsigned int flags;
448 if (decl != NULL_TREE && !DECL_P (decl))
449 abort ();
450 if (name == NULL)
451 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
453 flags = (* targetm.section_type_flags) (decl, name, reloc);
455 /* Sanity check user variables for flag changes. Non-user
456 section flag changes will abort in named_section_flags.
457 However, don't complain if SECTION_OVERRIDE is set.
458 We trust that the setter knows that it is safe to ignore
459 the default flags for this decl. */
460 if (decl && ! set_named_section_flags (name, flags))
462 flags = get_named_section_flags (name);
463 if ((flags & SECTION_OVERRIDE) == 0)
464 error_with_decl (decl, "%s causes a section type conflict");
467 named_section_flags (name, flags);
470 /* If required, set DECL_SECTION_NAME to a unique name. */
472 static void
473 resolve_unique_section (decl, reloc, flag_function_or_data_sections)
474 tree decl;
475 int reloc ATTRIBUTE_UNUSED;
476 int flag_function_or_data_sections;
478 if (DECL_SECTION_NAME (decl) == NULL_TREE
479 && targetm.have_named_sections
480 && (flag_function_or_data_sections
481 || DECL_ONE_ONLY (decl)))
482 (*targetm.asm_out.unique_section) (decl, reloc);
485 #ifdef BSS_SECTION_ASM_OP
487 /* Tell the assembler to switch to the bss section. */
489 void
490 bss_section ()
492 if (in_section != in_bss)
494 #ifdef SHARED_BSS_SECTION_ASM_OP
495 if (flag_shared_data)
496 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
497 else
498 #endif
499 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
501 in_section = in_bss;
505 #ifdef ASM_OUTPUT_BSS
507 /* Utility function for ASM_OUTPUT_BSS for targets to use if
508 they don't support alignments in .bss.
509 ??? It is believed that this function will work in most cases so such
510 support is localized here. */
512 static void
513 asm_output_bss (file, decl, name, size, rounded)
514 FILE *file;
515 tree decl ATTRIBUTE_UNUSED;
516 const char *name;
517 int size ATTRIBUTE_UNUSED, rounded;
519 ASM_GLOBALIZE_LABEL (file, name);
520 bss_section ();
521 #ifdef ASM_DECLARE_OBJECT_NAME
522 last_assemble_variable_decl = decl;
523 ASM_DECLARE_OBJECT_NAME (file, name, decl);
524 #else
525 /* Standard thing is just output label for the object. */
526 ASM_OUTPUT_LABEL (file, name);
527 #endif /* ASM_DECLARE_OBJECT_NAME */
528 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
531 #endif
533 #ifdef ASM_OUTPUT_ALIGNED_BSS
535 /* Utility function for targets to use in implementing
536 ASM_OUTPUT_ALIGNED_BSS.
537 ??? It is believed that this function will work in most cases so such
538 support is localized here. */
540 static void
541 asm_output_aligned_bss (file, decl, name, size, align)
542 FILE *file;
543 tree decl ATTRIBUTE_UNUSED;
544 const char *name;
545 int size, align;
547 ASM_GLOBALIZE_LABEL (file, name);
548 bss_section ();
549 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
550 #ifdef ASM_DECLARE_OBJECT_NAME
551 last_assemble_variable_decl = decl;
552 ASM_DECLARE_OBJECT_NAME (file, name, decl);
553 #else
554 /* Standard thing is just output label for the object. */
555 ASM_OUTPUT_LABEL (file, name);
556 #endif /* ASM_DECLARE_OBJECT_NAME */
557 ASM_OUTPUT_SKIP (file, size ? size : 1);
560 #endif
562 #endif /* BSS_SECTION_ASM_OP */
564 /* Switch to the section for function DECL.
566 If DECL is NULL_TREE, switch to the text section.
567 ??? It's not clear that we will ever be passed NULL_TREE, but it's
568 safer to handle it. */
570 void
571 function_section (decl)
572 tree decl;
574 if (decl != NULL_TREE
575 && DECL_SECTION_NAME (decl) != NULL_TREE)
576 named_section (decl, (char *) 0, 0);
577 else
578 text_section ();
581 /* Switch to section for variable DECL. RELOC is the same as the
582 argument to SELECT_SECTION. */
584 void
585 variable_section (decl, reloc)
586 tree decl;
587 int reloc;
589 if (IN_NAMED_SECTION (decl))
590 named_section (decl, NULL, reloc);
591 else
592 (*targetm.asm_out.select_section) (decl, reloc, DECL_ALIGN (decl));
595 /* Tell assembler to switch to the section for the exception handling
596 table. */
598 void
599 default_exception_section ()
601 if (targetm.have_named_sections)
602 named_section (NULL_TREE, ".gcc_except_table", 0);
603 else if (flag_pic)
604 data_section ();
605 else
606 readonly_data_section ();
609 /* Tell assembler to switch to the section for string merging. */
611 void
612 mergeable_string_section (decl, align, flags)
613 tree decl ATTRIBUTE_UNUSED;
614 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
615 unsigned int flags ATTRIBUTE_UNUSED;
617 #ifdef HAVE_GAS_SHF_MERGE
618 if (flag_merge_constants
619 && TREE_CODE (decl) == STRING_CST
620 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
621 && align <= 256
622 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
624 enum machine_mode mode;
625 unsigned int modesize;
626 const char *str;
627 int i, j, len, unit;
628 char name[30];
630 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
631 modesize = GET_MODE_BITSIZE (mode);
632 if (modesize >= 8 && modesize <= 256
633 && (modesize & (modesize - 1)) == 0)
635 if (align < modesize)
636 align = modesize;
638 str = TREE_STRING_POINTER (decl);
639 len = TREE_STRING_LENGTH (decl);
640 unit = GET_MODE_SIZE (mode);
642 /* Check for embedded NUL characters. */
643 for (i = 0; i < len; i += unit)
645 for (j = 0; j < unit; j++)
646 if (str[i + j] != '\0')
647 break;
648 if (j == unit)
649 break;
651 if (i == len - unit)
653 sprintf (name, ".rodata.str%d.%d", modesize / 8,
654 (int) (align / 8));
655 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
656 if (!i && modesize < align)
658 /* A "" string with requested alignment greater than
659 character size might cause a problem:
660 if some other string required even bigger
661 alignment than "", then linker might think the
662 "" is just part of padding after some other string
663 and not put it into the hash table initially.
664 But this means "" could have smaller alignment
665 than requested. */
666 #ifdef ASM_OUTPUT_SECTION_START
667 named_section_flags (name, flags);
668 ASM_OUTPUT_SECTION_START (asm_out_file);
669 #else
670 readonly_data_section ();
671 #endif
672 return;
675 named_section_flags (name, flags);
676 return;
680 #endif
681 readonly_data_section ();
684 /* Tell assembler to switch to the section for constant merging. */
686 void
687 mergeable_constant_section (mode, align, flags)
688 enum machine_mode mode ATTRIBUTE_UNUSED;
689 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
690 unsigned int flags ATTRIBUTE_UNUSED;
692 #ifdef HAVE_GAS_SHF_MERGE
693 unsigned int modesize = GET_MODE_BITSIZE (mode);
695 if (flag_merge_constants
696 && mode != VOIDmode
697 && mode != BLKmode
698 && modesize <= align
699 && align >= 8
700 && align <= 256
701 && (align & (align - 1)) == 0)
703 char name[24];
705 sprintf (name, ".rodata.cst%d", (int) (align / 8));
706 flags |= (align / 8) | SECTION_MERGE;
707 named_section_flags (name, flags);
708 return;
710 #endif
711 readonly_data_section ();
714 /* Given NAME, a putative register name, discard any customary prefixes. */
716 static const char *
717 strip_reg_name (name)
718 const char *name;
720 #ifdef REGISTER_PREFIX
721 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
722 name += strlen (REGISTER_PREFIX);
723 #endif
724 if (name[0] == '%' || name[0] == '#')
725 name++;
726 return name;
729 /* Decode an `asm' spec for a declaration as a register name.
730 Return the register number, or -1 if nothing specified,
731 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
732 or -3 if ASMSPEC is `cc' and is not recognized,
733 or -4 if ASMSPEC is `memory' and is not recognized.
734 Accept an exact spelling or a decimal number.
735 Prefixes such as % are optional. */
738 decode_reg_name (asmspec)
739 const char *asmspec;
741 if (asmspec != 0)
743 int i;
745 /* Get rid of confusing prefixes. */
746 asmspec = strip_reg_name (asmspec);
748 /* Allow a decimal number as a "register name". */
749 for (i = strlen (asmspec) - 1; i >= 0; i--)
750 if (! ISDIGIT (asmspec[i]))
751 break;
752 if (asmspec[0] != 0 && i < 0)
754 i = atoi (asmspec);
755 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
756 return i;
757 else
758 return -2;
761 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
762 if (reg_names[i][0]
763 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
764 return i;
766 #ifdef ADDITIONAL_REGISTER_NAMES
768 static const struct { const char *const name; const int number; } table[]
769 = ADDITIONAL_REGISTER_NAMES;
771 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
772 if (! strcmp (asmspec, table[i].name))
773 return table[i].number;
775 #endif /* ADDITIONAL_REGISTER_NAMES */
777 if (!strcmp (asmspec, "memory"))
778 return -4;
780 if (!strcmp (asmspec, "cc"))
781 return -3;
783 return -2;
786 return -1;
789 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
790 have static storage duration. In other words, it should not be an
791 automatic variable, including PARM_DECLs.
793 There is, however, one exception: this function handles variables
794 explicitly placed in a particular register by the user.
796 ASMSPEC, if not 0, is the string which the user specified as the
797 assembler symbol name.
799 This is never called for PARM_DECL nodes. */
801 void
802 make_decl_rtl (decl, asmspec)
803 tree decl;
804 const char *asmspec;
806 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
807 const char *name = 0;
808 const char *new_name = 0;
809 int reg_number;
810 rtx x;
812 /* Check that we are not being given an automatic variable. */
813 /* A weak alias has TREE_PUBLIC set but not the other bits. */
814 if (TREE_CODE (decl) == PARM_DECL
815 || TREE_CODE (decl) == RESULT_DECL
816 || (TREE_CODE (decl) == VAR_DECL
817 && !TREE_STATIC (decl)
818 && !TREE_PUBLIC (decl)
819 && !DECL_EXTERNAL (decl)
820 && !DECL_REGISTER (decl)))
821 abort ();
822 /* And that we were not given a type or a label. */
823 else if (TREE_CODE (decl) == TYPE_DECL
824 || TREE_CODE (decl) == LABEL_DECL)
825 abort ();
827 /* For a duplicate declaration, we can be called twice on the
828 same DECL node. Don't discard the RTL already made. */
829 if (DECL_RTL_SET_P (decl))
831 /* If the old RTL had the wrong mode, fix the mode. */
832 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
833 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
834 DECL_MODE (decl), 0));
836 /* ??? Another way to do this would be to do what halfpic.c does
837 and maintain a hashed table of such critters. */
838 /* Let the target reassign the RTL if it wants.
839 This is necessary, for example, when one machine specific
840 decl attribute overrides another. */
841 (* targetm.encode_section_info) (decl, false);
842 return;
845 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
847 reg_number = decode_reg_name (asmspec);
848 if (reg_number == -2)
850 /* ASMSPEC is given, and not the name of a register. Mark the
851 name with a star so assemble_name won't munge it. */
852 char *starred = alloca (strlen (asmspec) + 2);
853 starred[0] = '*';
854 strcpy (starred + 1, asmspec);
855 new_name = starred;
858 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
860 /* First detect errors in declaring global registers. */
861 if (reg_number == -1)
862 error_with_decl (decl, "register name not specified for `%s'");
863 else if (reg_number < 0)
864 error_with_decl (decl, "invalid register name for `%s'");
865 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
866 error_with_decl (decl,
867 "data type of `%s' isn't suitable for a register");
868 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
869 error_with_decl (decl,
870 "register specified for `%s' isn't suitable for data type");
871 /* Now handle properly declared static register variables. */
872 else
874 int nregs;
876 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
878 DECL_INITIAL (decl) = 0;
879 error ("global register variable has initial value");
881 if (TREE_THIS_VOLATILE (decl))
882 warning ("volatile register variables don't work as you might wish");
884 /* If the user specified one of the eliminables registers here,
885 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
886 confused with that register and be eliminated. This usage is
887 somewhat suspect... */
889 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
890 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
891 REG_USERVAR_P (DECL_RTL (decl)) = 1;
893 if (TREE_STATIC (decl))
895 /* Make this register global, so not usable for anything
896 else. */
897 #ifdef ASM_DECLARE_REGISTER_GLOBAL
898 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
899 #endif
900 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
901 while (nregs > 0)
902 globalize_reg (reg_number + --nregs);
905 /* As a register variable, it has no section. */
906 return;
910 /* Now handle ordinary static variables and functions (in memory).
911 Also handle vars declared register invalidly. */
913 if (reg_number >= 0 || reg_number == -3)
914 error_with_decl (decl,
915 "register name given for non-register variable `%s'");
917 /* Specifying a section attribute on a variable forces it into a
918 non-.bss section, and thus it cannot be common. */
919 if (TREE_CODE (decl) == VAR_DECL
920 && DECL_SECTION_NAME (decl) != NULL_TREE
921 && DECL_INITIAL (decl) == NULL_TREE
922 && DECL_COMMON (decl))
923 DECL_COMMON (decl) = 0;
925 /* Variables can't be both common and weak. */
926 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
927 DECL_COMMON (decl) = 0;
929 /* Can't use just the variable's own name for a variable
930 whose scope is less than the whole file, unless it's a member
931 of a local class (which will already be unambiguous).
932 Concatenate a distinguishing number. */
933 if (!top_level && !TREE_PUBLIC (decl)
934 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
935 && asmspec == 0
936 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
938 char *label;
940 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
941 var_labelno++;
942 new_name = label;
945 if (name != new_name)
947 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
948 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
951 /* If this variable is to be treated as volatile, show its
952 tree node has side effects. */
953 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
954 && TREE_PUBLIC (decl))
955 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
956 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
957 TREE_SIDE_EFFECTS (decl) = 1;
959 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
960 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
961 if (TREE_CODE (decl) != FUNCTION_DECL)
962 set_mem_attributes (x, decl, 1);
963 SET_DECL_RTL (decl, x);
965 /* Optionally set flags or add text to the name to record information
966 such as that it is a function name.
967 If the name is changed, the macro ASM_OUTPUT_LABELREF
968 will have to know how to strip this information. */
969 (* targetm.encode_section_info) (decl, true);
972 /* Make the rtl for variable VAR be volatile.
973 Use this only for static variables. */
975 void
976 make_var_volatile (var)
977 tree var;
979 if (GET_CODE (DECL_RTL (var)) != MEM)
980 abort ();
982 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
985 /* Output alignment directive to align for constant expression EXP. */
987 void
988 assemble_constant_align (exp)
989 tree exp;
991 int align;
993 /* Align the location counter as required by EXP's data type. */
994 align = TYPE_ALIGN (TREE_TYPE (exp));
995 #ifdef CONSTANT_ALIGNMENT
996 align = CONSTANT_ALIGNMENT (exp, align);
997 #endif
999 if (align > BITS_PER_UNIT)
1001 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1005 /* Output a string of literal assembler code
1006 for an `asm' keyword used between functions. */
1008 void
1009 assemble_asm (string)
1010 tree string;
1012 app_enable ();
1014 if (TREE_CODE (string) == ADDR_EXPR)
1015 string = TREE_OPERAND (string, 0);
1017 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1020 /* Record an element in the table of global destructors. SYMBOL is
1021 a SYMBOL_REF of the function to be called; PRIORITY is a number
1022 between 0 and MAX_INIT_PRIORITY. */
1024 void
1025 default_stabs_asm_out_destructor (symbol, priority)
1026 rtx symbol;
1027 int priority ATTRIBUTE_UNUSED;
1029 /* Tell GNU LD that this is part of the static destructor set.
1030 This will work for any system that uses stabs, most usefully
1031 aout systems. */
1032 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1033 assemble_name (asm_out_file, XSTR (symbol, 0));
1034 fputc ('\n', asm_out_file);
1037 void
1038 default_named_section_asm_out_destructor (symbol, priority)
1039 rtx symbol;
1040 int priority;
1042 const char *section = ".dtors";
1043 char buf[16];
1045 /* ??? This only works reliably with the GNU linker. */
1046 if (priority != DEFAULT_INIT_PRIORITY)
1048 sprintf (buf, ".dtors.%.5u",
1049 /* Invert the numbering so the linker puts us in the proper
1050 order; constructors are run from right to left, and the
1051 linker sorts in increasing order. */
1052 MAX_INIT_PRIORITY - priority);
1053 section = buf;
1056 named_section_flags (section, SECTION_WRITE);
1057 assemble_align (POINTER_SIZE);
1058 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1061 #ifdef DTORS_SECTION_ASM_OP
1062 void
1063 dtors_section ()
1065 if (in_section != in_dtors)
1067 in_section = in_dtors;
1068 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1069 fputc ('\n', asm_out_file);
1073 void
1074 default_dtor_section_asm_out_destructor (symbol, priority)
1075 rtx symbol;
1076 int priority ATTRIBUTE_UNUSED;
1078 dtors_section ();
1079 assemble_align (POINTER_SIZE);
1080 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1082 #endif
1084 /* Likewise for global constructors. */
1086 void
1087 default_stabs_asm_out_constructor (symbol, priority)
1088 rtx symbol;
1089 int priority ATTRIBUTE_UNUSED;
1091 /* Tell GNU LD that this is part of the static destructor set.
1092 This will work for any system that uses stabs, most usefully
1093 aout systems. */
1094 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1095 assemble_name (asm_out_file, XSTR (symbol, 0));
1096 fputc ('\n', asm_out_file);
1099 void
1100 default_named_section_asm_out_constructor (symbol, priority)
1101 rtx symbol;
1102 int priority;
1104 const char *section = ".ctors";
1105 char buf[16];
1107 /* ??? This only works reliably with the GNU linker. */
1108 if (priority != DEFAULT_INIT_PRIORITY)
1110 sprintf (buf, ".ctors.%.5u",
1111 /* Invert the numbering so the linker puts us in the proper
1112 order; constructors are run from right to left, and the
1113 linker sorts in increasing order. */
1114 MAX_INIT_PRIORITY - priority);
1115 section = buf;
1118 named_section_flags (section, SECTION_WRITE);
1119 assemble_align (POINTER_SIZE);
1120 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1123 #ifdef CTORS_SECTION_ASM_OP
1124 void
1125 ctors_section ()
1127 if (in_section != in_ctors)
1129 in_section = in_ctors;
1130 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1131 fputc ('\n', asm_out_file);
1135 void
1136 default_ctor_section_asm_out_constructor (symbol, priority)
1137 rtx symbol;
1138 int priority ATTRIBUTE_UNUSED;
1140 ctors_section ();
1141 assemble_align (POINTER_SIZE);
1142 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1144 #endif
1146 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1147 a non-zero value if the constant pool should be output before the
1148 start of the function, or a zero value if the pool should output
1149 after the end of the function. The default is to put it before the
1150 start. */
1152 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1153 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1154 #endif
1156 /* Output assembler code for the constant pool of a function and associated
1157 with defining the name of the function. DECL describes the function.
1158 NAME is the function's name. For the constant pool, we use the current
1159 constant pool data. */
1161 void
1162 assemble_start_function (decl, fnname)
1163 tree decl;
1164 const char *fnname;
1166 int align;
1168 /* The following code does not need preprocessing in the assembler. */
1170 app_disable ();
1172 if (CONSTANT_POOL_BEFORE_FUNCTION)
1173 output_constant_pool (fnname, decl);
1175 resolve_unique_section (decl, 0, flag_function_sections);
1176 function_section (decl);
1178 /* Tell assembler to move to target machine's alignment for functions. */
1179 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1180 if (align > 0)
1182 ASM_OUTPUT_ALIGN (asm_out_file, align);
1185 /* Handle a user-specified function alignment.
1186 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1187 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1188 if (align_functions_log > align
1189 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1191 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1192 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1193 align_functions_log, align_functions - 1);
1194 #else
1195 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1196 #endif
1199 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1200 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1201 #endif
1203 (*debug_hooks->begin_function) (decl);
1205 /* Make function name accessible from other files, if appropriate. */
1207 if (TREE_PUBLIC (decl))
1209 if (! first_global_object_name)
1211 const char *p;
1212 char *name;
1214 p = (* targetm.strip_name_encoding) (fnname);
1215 name = permalloc (strlen (p) + 1);
1216 strcpy (name, p);
1218 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1219 first_global_object_name = name;
1220 else
1221 weak_global_object_name = name;
1224 globalize_decl (decl);
1226 maybe_assemble_visibility (decl);
1229 /* Do any machine/system dependent processing of the function name */
1230 #ifdef ASM_DECLARE_FUNCTION_NAME
1231 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1232 #else
1233 /* Standard thing is just output label for the function. */
1234 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1235 #endif /* ASM_DECLARE_FUNCTION_NAME */
1238 /* Output assembler code associated with defining the size of the
1239 function. DECL describes the function. NAME is the function's name. */
1241 void
1242 assemble_end_function (decl, fnname)
1243 tree decl;
1244 const char *fnname;
1246 #ifdef ASM_DECLARE_FUNCTION_SIZE
1247 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1248 #endif
1249 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1251 output_constant_pool (fnname, decl);
1252 function_section (decl); /* need to switch back */
1255 /* Output any constants which should appear after the function. */
1256 output_after_function_constants ();
1259 /* Assemble code to leave SIZE bytes of zeros. */
1261 void
1262 assemble_zeros (size)
1263 int size;
1265 /* Do no output if -fsyntax-only. */
1266 if (flag_syntax_only)
1267 return;
1269 #ifdef ASM_NO_SKIP_IN_TEXT
1270 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1271 so we must output 0s explicitly in the text section. */
1272 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1274 int i;
1275 for (i = 0; i < size; i++)
1276 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1278 else
1279 #endif
1280 if (size > 0)
1281 ASM_OUTPUT_SKIP (asm_out_file, size);
1284 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1286 void
1287 assemble_align (align)
1288 int align;
1290 if (align > BITS_PER_UNIT)
1292 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1296 /* Assemble a string constant with the specified C string as contents. */
1298 void
1299 assemble_string (p, size)
1300 const char *p;
1301 int size;
1303 int pos = 0;
1304 int maximum = 2000;
1306 /* If the string is very long, split it up. */
1308 while (pos < size)
1310 int thissize = size - pos;
1311 if (thissize > maximum)
1312 thissize = maximum;
1314 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1316 pos += thissize;
1317 p += thissize;
1322 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1323 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1324 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1325 #else
1326 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1327 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1328 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1329 #else
1330 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1331 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1332 #endif
1333 #endif
1335 #if defined ASM_OUTPUT_ALIGNED_BSS
1336 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1337 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1338 #else
1339 #if defined ASM_OUTPUT_BSS
1340 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1341 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1342 #else
1343 #undef ASM_EMIT_BSS
1344 #endif
1345 #endif
1347 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1348 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1349 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1350 #else
1351 #if defined ASM_OUTPUT_ALIGNED_COMMON
1352 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1353 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1354 #else
1355 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1356 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1357 #endif
1358 #endif
1360 static void
1361 asm_emit_uninitialised (decl, name, size, rounded)
1362 tree decl;
1363 const char *name;
1364 int size ATTRIBUTE_UNUSED;
1365 int rounded ATTRIBUTE_UNUSED;
1367 enum
1369 asm_dest_common,
1370 asm_dest_bss,
1371 asm_dest_local
1373 destination = asm_dest_local;
1375 if (TREE_PUBLIC (decl))
1377 #if defined ASM_EMIT_BSS
1378 if (! DECL_COMMON (decl))
1379 destination = asm_dest_bss;
1380 else
1381 #endif
1382 destination = asm_dest_common;
1385 if (destination == asm_dest_bss)
1386 globalize_decl (decl);
1387 resolve_unique_section (decl, 0, flag_data_sections);
1389 if (flag_shared_data)
1391 switch (destination)
1393 #ifdef ASM_OUTPUT_SHARED_BSS
1394 case asm_dest_bss:
1395 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1396 return;
1397 #endif
1398 #ifdef ASM_OUTPUT_SHARED_COMMON
1399 case asm_dest_common:
1400 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1401 return;
1402 #endif
1403 #ifdef ASM_OUTPUT_SHARED_LOCAL
1404 case asm_dest_local:
1405 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1406 return;
1407 #endif
1408 default:
1409 break;
1413 switch (destination)
1415 #ifdef ASM_EMIT_BSS
1416 case asm_dest_bss:
1417 ASM_EMIT_BSS (decl, name, size, rounded);
1418 break;
1419 #endif
1420 case asm_dest_common:
1421 ASM_EMIT_COMMON (decl, name, size, rounded);
1422 break;
1423 case asm_dest_local:
1424 ASM_EMIT_LOCAL (decl, name, size, rounded);
1425 break;
1426 default:
1427 abort ();
1430 return;
1433 /* Assemble everything that is needed for a variable or function declaration.
1434 Not used for automatic variables, and not used for function definitions.
1435 Should not be called for variables of incomplete structure type.
1437 TOP_LEVEL is nonzero if this variable has file scope.
1438 AT_END is nonzero if this is the special handling, at end of compilation,
1439 to define things that have had only tentative definitions.
1440 DONT_OUTPUT_DATA if nonzero means don't actually output the
1441 initial value (that will be done by the caller). */
1443 void
1444 assemble_variable (decl, top_level, at_end, dont_output_data)
1445 tree decl;
1446 int top_level ATTRIBUTE_UNUSED;
1447 int at_end ATTRIBUTE_UNUSED;
1448 int dont_output_data;
1450 const char *name;
1451 unsigned int align;
1452 int reloc = 0;
1453 rtx decl_rtl;
1455 last_assemble_variable_decl = 0;
1457 /* Normally no need to say anything here for external references,
1458 since assemble_external is called by the language-specific code
1459 when a declaration is first seen. */
1461 if (DECL_EXTERNAL (decl))
1462 return;
1464 /* Output no assembler code for a function declaration.
1465 Only definitions of functions output anything. */
1467 if (TREE_CODE (decl) == FUNCTION_DECL)
1468 return;
1470 /* Do nothing for global register variables. */
1471 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1473 TREE_ASM_WRITTEN (decl) = 1;
1474 return;
1477 /* If type was incomplete when the variable was declared,
1478 see if it is complete now. */
1480 if (DECL_SIZE (decl) == 0)
1481 layout_decl (decl, 0);
1483 /* Still incomplete => don't allocate it; treat the tentative defn
1484 (which is what it must have been) as an `extern' reference. */
1486 if (!dont_output_data && DECL_SIZE (decl) == 0)
1488 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1489 DECL_SOURCE_LINE (decl),
1490 "storage size of `%s' isn't known",
1491 IDENTIFIER_POINTER (DECL_NAME (decl)));
1492 TREE_ASM_WRITTEN (decl) = 1;
1493 return;
1496 /* The first declaration of a variable that comes through this function
1497 decides whether it is global (in C, has external linkage)
1498 or local (in C, has internal linkage). So do nothing more
1499 if this function has already run. */
1501 if (TREE_ASM_WRITTEN (decl))
1502 return;
1504 /* Make sure targetm.encode_section_info is invoked before we set
1505 ASM_WRITTEN. */
1506 decl_rtl = DECL_RTL (decl);
1508 TREE_ASM_WRITTEN (decl) = 1;
1510 /* Do no output if -fsyntax-only. */
1511 if (flag_syntax_only)
1512 return;
1514 app_disable ();
1516 if (! dont_output_data
1517 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1519 error_with_decl (decl, "size of variable `%s' is too large");
1520 return;
1523 name = XSTR (XEXP (decl_rtl, 0), 0);
1524 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1525 && ! first_global_object_name
1526 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1527 || DECL_INITIAL (decl) == error_mark_node))
1528 && ! DECL_WEAK (decl)
1529 && ! DECL_ONE_ONLY (decl))
1531 const char *p;
1532 char *xname;
1534 p = (* targetm.strip_name_encoding) (name);
1535 xname = permalloc (strlen (p) + 1);
1536 strcpy (xname, p);
1537 first_global_object_name = xname;
1540 /* Compute the alignment of this data. */
1542 align = DECL_ALIGN (decl);
1544 /* In the case for initialing an array whose length isn't specified,
1545 where we have not yet been able to do the layout,
1546 figure out the proper alignment now. */
1547 if (dont_output_data && DECL_SIZE (decl) == 0
1548 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1549 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1551 /* Some object file formats have a maximum alignment which they support.
1552 In particular, a.out format supports a maximum alignment of 4. */
1553 #ifndef MAX_OFILE_ALIGNMENT
1554 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1555 #endif
1556 if (align > MAX_OFILE_ALIGNMENT)
1558 warning_with_decl (decl,
1559 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1560 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1561 align = MAX_OFILE_ALIGNMENT;
1564 /* On some machines, it is good to increase alignment sometimes. */
1565 if (! DECL_USER_ALIGN (decl))
1567 #ifdef DATA_ALIGNMENT
1568 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1569 #endif
1570 #ifdef CONSTANT_ALIGNMENT
1571 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1572 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1573 #endif
1576 /* Reset the alignment in case we have made it tighter, so we can benefit
1577 from it in get_pointer_alignment. */
1578 DECL_ALIGN (decl) = align;
1579 set_mem_align (decl_rtl, align);
1581 if (TREE_PUBLIC (decl))
1582 maybe_assemble_visibility (decl);
1584 /* Output any data that we will need to use the address of. */
1585 if (DECL_INITIAL (decl) == error_mark_node)
1586 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1587 else if (DECL_INITIAL (decl))
1588 reloc = output_addressed_constants (DECL_INITIAL (decl));
1589 resolve_unique_section (decl, reloc, flag_data_sections);
1591 /* Handle uninitialized definitions. */
1593 /* If the decl has been given an explicit section name, then it
1594 isn't common, and shouldn't be handled as such. */
1595 if (DECL_SECTION_NAME (decl) || dont_output_data)
1597 /* We don't implement common thread-local data at present. */
1598 else if (DECL_THREAD_LOCAL (decl))
1600 if (DECL_COMMON (decl))
1601 sorry ("thread-local COMMON data not implemented");
1603 #ifndef ASM_EMIT_BSS
1604 /* If the target can't output uninitialized but not common global data
1605 in .bss, then we have to use .data. */
1606 /* ??? We should handle .bss via select_section mechanisms rather than
1607 via special target hooks. That would eliminate this special case. */
1608 else if (!DECL_COMMON (decl))
1610 #endif
1611 else if (DECL_INITIAL (decl) == 0
1612 || DECL_INITIAL (decl) == error_mark_node
1613 || (flag_zero_initialized_in_bss
1614 && initializer_zerop (DECL_INITIAL (decl))))
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. */
1621 if (size == 0)
1622 rounded = 1;
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)
1633 warning_with_decl
1634 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1635 #endif
1637 asm_emit_uninitialised (decl, name, size, rounded);
1639 return;
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))
1648 globalize_decl (decl);
1650 /* Switch to the appropriate section. */
1651 variable_section (decl, reloc);
1653 /* dbxout.c needs to know this. */
1654 if (in_text_section ())
1655 DECL_IN_TEXT_SECTION (decl) = 1;
1657 /* Output the alignment of this data. */
1658 if (align > BITS_PER_UNIT)
1660 ASM_OUTPUT_ALIGN (asm_out_file,
1661 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1664 /* Do any machine/system dependent processing of the object. */
1665 #ifdef ASM_DECLARE_OBJECT_NAME
1666 last_assemble_variable_decl = decl;
1667 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1668 #else
1669 /* Standard thing is just output label for the object. */
1670 ASM_OUTPUT_LABEL (asm_out_file, name);
1671 #endif /* ASM_DECLARE_OBJECT_NAME */
1673 if (!dont_output_data)
1675 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1676 /* Output the actual data. */
1677 output_constant (DECL_INITIAL (decl),
1678 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1679 align);
1680 else
1681 /* Leave space for it. */
1682 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1686 /* Return 1 if type TYPE contains any pointers. */
1688 static int
1689 contains_pointers_p (type)
1690 tree type;
1692 switch (TREE_CODE (type))
1694 case POINTER_TYPE:
1695 case REFERENCE_TYPE:
1696 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1697 so I'll play safe and return 1. */
1698 case OFFSET_TYPE:
1699 return 1;
1701 case RECORD_TYPE:
1702 case UNION_TYPE:
1703 case QUAL_UNION_TYPE:
1705 tree fields;
1706 /* For a type that has fields, see if the fields have pointers. */
1707 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1708 if (TREE_CODE (fields) == FIELD_DECL
1709 && contains_pointers_p (TREE_TYPE (fields)))
1710 return 1;
1711 return 0;
1714 case ARRAY_TYPE:
1715 /* An array type contains pointers if its element type does. */
1716 return contains_pointers_p (TREE_TYPE (type));
1718 default:
1719 return 0;
1723 /* Output something to declare an external symbol to the assembler.
1724 (Most assemblers don't need this, so we normally output nothing.)
1725 Do nothing if DECL is not external. */
1727 void
1728 assemble_external (decl)
1729 tree decl ATTRIBUTE_UNUSED;
1731 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1732 main body of this code is only rarely exercised. To provide some
1733 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1734 open. If it's not, we should not be calling this function. */
1735 if (!asm_out_file)
1736 abort ();
1738 #ifdef ASM_OUTPUT_EXTERNAL
1739 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1741 rtx rtl = DECL_RTL (decl);
1743 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1744 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1746 /* Some systems do require some output. */
1747 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1748 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1751 #endif
1754 /* Similar, for calling a library function FUN. */
1756 void
1757 assemble_external_libcall (fun)
1758 rtx fun ATTRIBUTE_UNUSED;
1760 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1761 /* Declare library function name external when first used, if nec. */
1762 if (! SYMBOL_REF_USED (fun))
1764 SYMBOL_REF_USED (fun) = 1;
1765 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1767 #endif
1770 /* Declare the label NAME global. */
1772 void
1773 assemble_global (name)
1774 const char *name ATTRIBUTE_UNUSED;
1776 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1779 /* Assemble a label named NAME. */
1781 void
1782 assemble_label (name)
1783 const char *name;
1785 ASM_OUTPUT_LABEL (asm_out_file, name);
1788 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1789 If NAME starts with a *, the rest of NAME is output verbatim.
1790 Otherwise NAME is transformed in an implementation-defined way
1791 (usually by the addition of an underscore).
1792 Many macros in the tm file are defined to call this function. */
1794 void
1795 assemble_name (file, name)
1796 FILE *file;
1797 const char *name;
1799 const char *real_name;
1800 tree id;
1802 real_name = (* targetm.strip_name_encoding) (name);
1804 id = maybe_get_identifier (real_name);
1805 if (id)
1806 TREE_SYMBOL_REFERENCED (id) = 1;
1808 if (name[0] == '*')
1809 fputs (&name[1], file);
1810 else
1811 ASM_OUTPUT_LABELREF (file, name);
1814 /* Allocate SIZE bytes writable static space with a gensym name
1815 and return an RTX to refer to its address. */
1818 assemble_static_space (size)
1819 int size;
1821 char name[12];
1822 const char *namestring;
1823 rtx x;
1825 #if 0
1826 if (flag_shared_data)
1827 data_section ();
1828 #endif
1830 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1831 ++const_labelno;
1832 namestring = ggc_strdup (name);
1834 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1836 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1837 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1838 BIGGEST_ALIGNMENT);
1839 #else
1840 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1841 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1842 #else
1844 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1845 so that each uninitialized object starts on such a boundary. */
1846 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1847 int rounded ATTRIBUTE_UNUSED
1848 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1849 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1850 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1851 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1853 #endif
1854 #endif
1855 return x;
1858 /* Assemble the static constant template for function entry trampolines.
1859 This is done at most once per compilation.
1860 Returns an RTX for the address of the template. */
1862 #ifdef TRAMPOLINE_TEMPLATE
1864 assemble_trampoline_template ()
1866 char label[256];
1867 const char *name;
1868 int align;
1870 /* By default, put trampoline templates in read-only data section. */
1872 #ifdef TRAMPOLINE_SECTION
1873 TRAMPOLINE_SECTION ();
1874 #else
1875 readonly_data_section ();
1876 #endif
1878 /* Write the assembler code to define one. */
1879 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1880 if (align > 0)
1882 ASM_OUTPUT_ALIGN (asm_out_file, align);
1885 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1886 TRAMPOLINE_TEMPLATE (asm_out_file);
1888 /* Record the rtl to refer to it. */
1889 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1890 name = ggc_strdup (label);
1891 return gen_rtx_SYMBOL_REF (Pmode, name);
1893 #endif
1895 /* A and B are either alignments or offsets. Return the minimum alignment
1896 that may be assumed after adding the two together. */
1898 static inline unsigned
1899 min_align (a, b)
1900 unsigned int a, b;
1902 return (a | b) & -(a | b);
1905 /* Return the assembler directive for creating a given kind of integer
1906 object. SIZE is the number of bytes in the object and ALIGNED_P
1907 indicates whether it is known to be aligned. Return NULL if the
1908 assembly dialect has no such directive.
1910 The returned string should be printed at the start of a new line and
1911 be followed immediately by the object's initial value. */
1913 const char *
1914 integer_asm_op (size, aligned_p)
1915 int size;
1916 int aligned_p;
1918 struct asm_int_op *ops;
1920 if (aligned_p)
1921 ops = &targetm.asm_out.aligned_op;
1922 else
1923 ops = &targetm.asm_out.unaligned_op;
1925 switch (size)
1927 case 1:
1928 return targetm.asm_out.byte_op;
1929 case 2:
1930 return ops->hi;
1931 case 4:
1932 return ops->si;
1933 case 8:
1934 return ops->di;
1935 case 16:
1936 return ops->ti;
1937 default:
1938 return NULL;
1942 /* Use directive OP to assemble an integer object X. Print OP at the
1943 start of the line, followed immediately by the value of X. */
1945 void
1946 assemble_integer_with_op (op, x)
1947 const char *op;
1948 rtx x;
1950 fputs (op, asm_out_file);
1951 output_addr_const (asm_out_file, x);
1952 fputc ('\n', asm_out_file);
1955 /* The default implementation of the asm_out.integer target hook. */
1957 bool
1958 default_assemble_integer (x, size, aligned_p)
1959 rtx x ATTRIBUTE_UNUSED;
1960 unsigned int size ATTRIBUTE_UNUSED;
1961 int aligned_p ATTRIBUTE_UNUSED;
1963 const char *op = integer_asm_op (size, aligned_p);
1964 return op && (assemble_integer_with_op (op, x), true);
1967 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1968 the alignment of the integer in bits. Return 1 if we were able to output
1969 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1970 the constant. */
1972 bool
1973 assemble_integer (x, size, align, force)
1974 rtx x;
1975 unsigned int size;
1976 unsigned int align;
1977 int force;
1979 int aligned_p;
1981 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1983 /* See if the target hook can handle this kind of object. */
1984 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1985 return true;
1987 /* If the object is a multi-byte one, try splitting it up. Split
1988 it into words it if is multi-word, otherwise split it into bytes. */
1989 if (size > 1)
1991 enum machine_mode omode, imode;
1992 unsigned int subalign;
1993 unsigned int subsize, i;
1995 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1996 subalign = MIN (align, subsize * BITS_PER_UNIT);
1997 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1998 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2000 for (i = 0; i < size; i += subsize)
2002 rtx partial = simplify_subreg (omode, x, imode, i);
2003 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2004 break;
2006 if (i == size)
2007 return true;
2009 /* If we've printed some of it, but not all of it, there's no going
2010 back now. */
2011 if (i > 0)
2012 abort ();
2015 if (force)
2016 abort ();
2018 return false;
2021 void
2022 assemble_real (d, mode, align)
2023 REAL_VALUE_TYPE d;
2024 enum machine_mode mode;
2025 unsigned int align;
2027 long data[4];
2028 long l;
2029 unsigned int nalign = min_align (align, 32);
2031 switch (BITS_PER_UNIT)
2033 case 8:
2034 switch (mode)
2036 case SFmode:
2037 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2038 assemble_integer (GEN_INT (l), 4, align, 1);
2039 break;
2040 case DFmode:
2041 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2042 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2043 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2044 break;
2045 case XFmode:
2046 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2047 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2048 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2049 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2050 break;
2051 case TFmode:
2052 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2053 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2054 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2055 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2056 assemble_integer (GEN_INT (data[3]), 4, nalign, 1);
2057 break;
2058 default:
2059 abort ();
2061 break;
2063 case 16:
2064 switch (mode)
2066 case HFmode:
2067 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2068 assemble_integer (GEN_INT (l), 2, align, 1);
2069 break;
2070 case TQFmode:
2071 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2072 assemble_integer (GEN_INT (data[0]), 2, align, 1);
2073 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2074 break;
2075 default:
2076 abort ();
2078 break;
2080 case 32:
2081 switch (mode)
2083 case QFmode:
2084 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2085 assemble_integer (GEN_INT (l), 1, align, 1);
2086 break;
2087 case HFmode:
2088 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2089 assemble_integer (GEN_INT (data[0]), 1, align, 1);
2090 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2091 break;
2092 default:
2093 abort ();
2095 break;
2097 default:
2098 abort ();
2102 /* Given an expression EXP with a constant value,
2103 reduce it to the sum of an assembler symbol and an integer.
2104 Store them both in the structure *VALUE.
2105 Abort if EXP does not reduce. */
2107 struct addr_const
2109 rtx base;
2110 HOST_WIDE_INT offset;
2113 static void
2114 decode_addr_const (exp, value)
2115 tree exp;
2116 struct addr_const *value;
2118 tree target = TREE_OPERAND (exp, 0);
2119 int offset = 0;
2120 rtx x;
2122 while (1)
2124 if (TREE_CODE (target) == COMPONENT_REF
2125 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2128 offset += int_byte_position (TREE_OPERAND (target, 1));
2129 target = TREE_OPERAND (target, 0);
2131 else if (TREE_CODE (target) == ARRAY_REF
2132 || TREE_CODE (target) == ARRAY_RANGE_REF)
2134 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2135 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2136 target = TREE_OPERAND (target, 0);
2138 else
2139 break;
2142 switch (TREE_CODE (target))
2144 case VAR_DECL:
2145 case FUNCTION_DECL:
2146 x = DECL_RTL (target);
2147 break;
2149 case LABEL_DECL:
2150 x = gen_rtx_MEM (FUNCTION_MODE,
2151 gen_rtx_LABEL_REF (VOIDmode,
2152 label_rtx (TREE_OPERAND (exp, 0))));
2153 break;
2155 case REAL_CST:
2156 case STRING_CST:
2157 case COMPLEX_CST:
2158 case CONSTRUCTOR:
2159 case INTEGER_CST:
2160 /* This constant should have been output already, but we can't simply
2161 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2162 x = output_constant_def (target, 1);
2163 break;
2165 default:
2166 abort ();
2169 if (GET_CODE (x) != MEM)
2170 abort ();
2171 x = XEXP (x, 0);
2173 value->base = x;
2174 value->offset = offset;
2177 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2178 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_INT, RTX_VECTOR, RTX_UNSPEC };
2179 struct rtx_const
2181 ENUM_BITFIELD(kind) kind : 16;
2182 ENUM_BITFIELD(machine_mode) mode : 16;
2183 union {
2184 REAL_VALUE_TYPE du;
2185 struct addr_const addr;
2186 struct {HOST_WIDE_INT high, low;} di;
2188 /* The max vector size we have is 8 wide. This should be enough. */
2189 HOST_WIDE_INT veclo[16];
2190 HOST_WIDE_INT vechi[16];
2191 } un;
2194 /* Uniquize all constants that appear in memory.
2195 Each constant in memory thus far output is recorded
2196 in `const_hash_table' with a `struct constant_descriptor'
2197 that contains a polish representation of the value of
2198 the constant.
2200 We cannot store the trees in the hash table
2201 because the trees may be temporary. */
2203 struct constant_descriptor
2205 struct constant_descriptor *next;
2206 const char *label;
2207 rtx rtl;
2208 /* Make sure the data is reasonably aligned. */
2209 union
2211 unsigned char contents[1];
2212 #ifdef HAVE_LONG_DOUBLE
2213 long double d;
2214 #else
2215 double d;
2216 #endif
2217 } u;
2220 #define HASHBITS 30
2221 #define MAX_HASH_TABLE 1009
2222 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2224 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2225 out a string constant, we defer output of the constants until we know
2226 they are actually used. This will be if something takes its address or if
2227 there is a usage of the string in the RTL of a function. */
2229 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2231 struct deferred_string
2233 const char *label;
2234 tree exp;
2235 int labelno;
2238 static htab_t const_str_htab;
2240 /* Mark a const_hash_table descriptor for GC. */
2242 static void
2243 mark_const_hash_entry (ptr)
2244 void *ptr;
2246 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2248 while (desc)
2250 ggc_mark_rtx (desc->rtl);
2251 desc = desc->next;
2255 /* Mark the hash-table element X (which is really a pointer to an
2256 struct deferred_string *). */
2258 static int
2259 mark_const_str_htab_1 (x, data)
2260 void **x;
2261 void *data ATTRIBUTE_UNUSED;
2263 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2264 return 1;
2267 /* Mark a const_str_htab for GC. */
2269 static void
2270 mark_const_str_htab (htab)
2271 void *htab;
2273 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2276 /* Returns a hash code for X (which is a really a
2277 struct deferred_string *). */
2279 static hashval_t
2280 const_str_htab_hash (x)
2281 const void *x;
2283 return STRHASH (((const struct deferred_string *) x)->label);
2286 /* Returns non-zero if the value represented by X (which is really a
2287 struct deferred_string *) is the same as that given by Y
2288 (which is really a char *). */
2290 static int
2291 const_str_htab_eq (x, y)
2292 const void *x;
2293 const void *y;
2295 return (((const struct deferred_string *) x)->label == (const char *) y);
2298 /* Delete the hash table entry dfsp. */
2300 static void
2301 const_str_htab_del (dfsp)
2302 void *dfsp;
2304 free (dfsp);
2307 /* Compute a hash code for a constant expression. */
2309 static int
2310 const_hash (exp)
2311 tree exp;
2313 const char *p;
2314 int len, hi, i;
2315 enum tree_code code = TREE_CODE (exp);
2317 /* Either set P and LEN to the address and len of something to hash and
2318 exit the switch or return a value. */
2320 switch (code)
2322 case INTEGER_CST:
2323 p = (char *) &TREE_INT_CST (exp);
2324 len = sizeof TREE_INT_CST (exp);
2325 break;
2327 case REAL_CST:
2328 p = (char *) &TREE_REAL_CST (exp);
2329 len = sizeof TREE_REAL_CST (exp);
2330 break;
2332 case STRING_CST:
2333 p = TREE_STRING_POINTER (exp);
2334 len = TREE_STRING_LENGTH (exp);
2335 break;
2337 case COMPLEX_CST:
2338 return (const_hash (TREE_REALPART (exp)) * 5
2339 + const_hash (TREE_IMAGPART (exp)));
2341 case CONSTRUCTOR:
2342 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2344 char *tmp;
2346 len = int_size_in_bytes (TREE_TYPE (exp));
2347 tmp = (char *) alloca (len);
2348 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2349 p = tmp;
2350 break;
2352 else
2354 tree link;
2356 /* For record type, include the type in the hashing.
2357 We do not do so for array types
2358 because (1) the sizes of the elements are sufficient
2359 and (2) distinct array types can have the same constructor.
2360 Instead, we include the array size because the constructor could
2361 be shorter. */
2362 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2363 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2364 % MAX_HASH_TABLE;
2365 else
2366 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2367 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2369 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2370 if (TREE_VALUE (link))
2372 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2374 return hi;
2377 case ADDR_EXPR:
2379 struct addr_const value;
2381 decode_addr_const (exp, &value);
2382 if (GET_CODE (value.base) == SYMBOL_REF)
2384 /* Don't hash the address of the SYMBOL_REF;
2385 only use the offset and the symbol name. */
2386 hi = value.offset;
2387 p = XSTR (value.base, 0);
2388 for (i = 0; p[i] != 0; i++)
2389 hi = ((hi * 613) + (unsigned) (p[i]));
2391 else if (GET_CODE (value.base) == LABEL_REF)
2392 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2393 else
2394 abort ();
2396 hi &= (1 << HASHBITS) - 1;
2397 hi %= MAX_HASH_TABLE;
2399 return hi;
2401 case PLUS_EXPR:
2402 case MINUS_EXPR:
2403 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2404 + const_hash (TREE_OPERAND (exp, 1)));
2406 case NOP_EXPR:
2407 case CONVERT_EXPR:
2408 case NON_LVALUE_EXPR:
2409 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2411 default:
2412 /* A language specific constant. Just hash the code. */
2413 return (int) code % MAX_HASH_TABLE;
2416 /* Compute hashing function */
2417 hi = len;
2418 for (i = 0; i < len; i++)
2419 hi = ((hi * 613) + (unsigned) (p[i]));
2421 hi &= (1 << HASHBITS) - 1;
2422 hi %= MAX_HASH_TABLE;
2423 return hi;
2426 /* Compare a constant expression EXP with a constant-descriptor DESC.
2427 Return 1 if DESC describes a constant with the same value as EXP. */
2429 static int
2430 compare_constant (exp, desc)
2431 tree exp;
2432 struct constant_descriptor *desc;
2434 return 0 != compare_constant_1 (exp, desc->u.contents);
2437 /* Compare constant expression EXP with a substring P of a constant descriptor.
2438 If they match, return a pointer to the end of the substring matched.
2439 If they do not match, return 0.
2441 Since descriptors are written in polish prefix notation,
2442 this function can be used recursively to test one operand of EXP
2443 against a subdescriptor, and if it succeeds it returns the
2444 address of the subdescriptor for the next operand. */
2446 static const unsigned char *
2447 compare_constant_1 (exp, p)
2448 tree exp;
2449 const unsigned char *p;
2451 const unsigned char *strp;
2452 int len;
2453 enum tree_code code = TREE_CODE (exp);
2455 if (code != (enum tree_code) *p++)
2456 return 0;
2458 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2459 switch, or return the result of the comparison. */
2461 switch (code)
2463 case INTEGER_CST:
2464 /* Integer constants are the same only if the same width of type. */
2465 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2466 return 0;
2468 strp = (unsigned char *) &TREE_INT_CST (exp);
2469 len = sizeof TREE_INT_CST (exp);
2470 break;
2472 case REAL_CST:
2473 /* Real constants are the same only if the same width of type. */
2474 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2475 return 0;
2477 strp = (unsigned char *) &TREE_REAL_CST (exp);
2478 len = sizeof TREE_REAL_CST (exp);
2479 break;
2481 case STRING_CST:
2482 if (flag_writable_strings)
2483 return 0;
2485 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2486 return 0;
2488 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2489 len = TREE_STRING_LENGTH (exp);
2490 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2491 sizeof TREE_STRING_LENGTH (exp)))
2492 return 0;
2494 p += sizeof TREE_STRING_LENGTH (exp);
2495 break;
2497 case COMPLEX_CST:
2498 p = compare_constant_1 (TREE_REALPART (exp), p);
2499 if (p == 0)
2500 return 0;
2502 return compare_constant_1 (TREE_IMAGPART (exp), p);
2504 case CONSTRUCTOR:
2505 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2507 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2508 unsigned char *tmp = (unsigned char *) alloca (len);
2510 get_set_constructor_bytes (exp, tmp, len);
2511 strp = (unsigned char *) tmp;
2512 if (memcmp ((char *) &xlen, p, sizeof xlen))
2513 return 0;
2515 p += sizeof xlen;
2516 break;
2518 else
2520 tree link;
2521 int length = list_length (CONSTRUCTOR_ELTS (exp));
2522 tree type;
2523 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2524 int have_purpose = 0;
2526 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2527 if (TREE_PURPOSE (link))
2528 have_purpose = 1;
2530 if (memcmp ((char *) &length, p, sizeof length))
2531 return 0;
2533 p += sizeof length;
2535 /* For record constructors, insist that the types match.
2536 For arrays, just verify both constructors are for arrays.
2537 Then insist that either both or none have any TREE_PURPOSE
2538 values. */
2539 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2540 type = TREE_TYPE (exp);
2541 else
2542 type = 0;
2544 if (memcmp ((char *) &type, p, sizeof type))
2545 return 0;
2547 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2549 if (memcmp ((char *) &mode, p, sizeof mode))
2550 return 0;
2552 p += sizeof mode;
2555 p += sizeof type;
2557 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2558 return 0;
2560 p += sizeof have_purpose;
2562 /* For arrays, insist that the size in bytes match. */
2563 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2565 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2567 if (memcmp ((char *) &size, p, sizeof size))
2568 return 0;
2570 p += sizeof size;
2573 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2575 if (TREE_VALUE (link))
2577 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2578 return 0;
2580 else
2582 tree zero = 0;
2584 if (memcmp ((char *) &zero, p, sizeof zero))
2585 return 0;
2587 p += sizeof zero;
2590 if (TREE_PURPOSE (link)
2591 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2593 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2594 sizeof TREE_PURPOSE (link)))
2595 return 0;
2597 p += sizeof TREE_PURPOSE (link);
2599 else if (TREE_PURPOSE (link))
2601 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2602 return 0;
2604 else if (have_purpose)
2606 int zero = 0;
2608 if (memcmp ((char *) &zero, p, sizeof zero))
2609 return 0;
2611 p += sizeof zero;
2615 return p;
2618 case ADDR_EXPR:
2620 struct addr_const value;
2622 decode_addr_const (exp, &value);
2623 strp = (unsigned char *) &value.offset;
2624 len = sizeof value.offset;
2625 /* Compare the offset. */
2626 while (--len >= 0)
2627 if (*p++ != *strp++)
2628 return 0;
2630 /* Compare symbol name. */
2631 strp = (const unsigned char *) XSTR (value.base, 0);
2632 len = strlen ((const char *) strp) + 1;
2634 break;
2636 case PLUS_EXPR:
2637 case MINUS_EXPR:
2638 case RANGE_EXPR:
2639 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2640 if (p == 0)
2641 return 0;
2643 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2645 case NOP_EXPR:
2646 case CONVERT_EXPR:
2647 case NON_LVALUE_EXPR:
2648 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2650 default:
2652 tree new = (*lang_hooks.expand_constant) (exp);
2654 if (new != exp)
2655 return compare_constant_1 (new, p);
2656 else
2657 return 0;
2661 /* Compare constant contents. */
2662 while (--len >= 0)
2663 if (*p++ != *strp++)
2664 return 0;
2666 return p;
2669 /* Construct a constant descriptor for the expression EXP.
2670 It is up to the caller to enter the descriptor in the hash table. */
2672 static struct constant_descriptor *
2673 record_constant (exp)
2674 tree exp;
2676 struct constant_descriptor *next = 0;
2677 char *label = 0;
2678 rtx rtl = 0;
2679 int pad;
2681 /* Make a struct constant_descriptor. The first three pointers will
2682 be filled in later. Here we just leave space for them. */
2684 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2685 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2686 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2688 /* Align the descriptor for the data payload. */
2689 pad = (offsetof (struct constant_descriptor, u)
2690 - offsetof(struct constant_descriptor, rtl)
2691 - sizeof(next->rtl));
2692 if (pad > 0)
2693 obstack_blank (&permanent_obstack, pad);
2695 record_constant_1 (exp);
2696 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2699 /* Add a description of constant expression EXP
2700 to the object growing in `permanent_obstack'.
2701 No need to return its address; the caller will get that
2702 from the obstack when the object is complete. */
2704 static void
2705 record_constant_1 (exp)
2706 tree exp;
2708 const unsigned char *strp;
2709 int len;
2710 enum tree_code code = TREE_CODE (exp);
2712 obstack_1grow (&permanent_obstack, (unsigned int) code);
2714 switch (code)
2716 case INTEGER_CST:
2717 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2718 strp = (unsigned char *) &TREE_INT_CST (exp);
2719 len = sizeof TREE_INT_CST (exp);
2720 break;
2722 case REAL_CST:
2723 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2724 strp = (unsigned char *) &TREE_REAL_CST (exp);
2725 len = sizeof TREE_REAL_CST (exp);
2726 break;
2728 case STRING_CST:
2729 if (flag_writable_strings)
2730 return;
2732 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2733 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2734 len = TREE_STRING_LENGTH (exp);
2735 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2736 sizeof TREE_STRING_LENGTH (exp));
2737 break;
2739 case COMPLEX_CST:
2740 record_constant_1 (TREE_REALPART (exp));
2741 record_constant_1 (TREE_IMAGPART (exp));
2742 return;
2744 case CONSTRUCTOR:
2745 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2747 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2748 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2749 obstack_blank (&permanent_obstack, nbytes);
2750 get_set_constructor_bytes
2751 (exp, (unsigned char *) permanent_obstack.next_free - nbytes,
2752 nbytes);
2753 return;
2755 else
2757 tree link;
2758 int length = list_length (CONSTRUCTOR_ELTS (exp));
2759 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2760 tree type;
2761 int have_purpose = 0;
2763 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2764 if (TREE_PURPOSE (link))
2765 have_purpose = 1;
2767 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2769 /* For record constructors, insist that the types match.
2770 For arrays, just verify both constructors are for arrays
2771 of the same mode. Then insist that either both or none
2772 have any TREE_PURPOSE values. */
2773 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2774 type = TREE_TYPE (exp);
2775 else
2776 type = 0;
2778 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2779 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2780 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2782 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2783 sizeof have_purpose);
2785 /* For arrays, insist that the size in bytes match. */
2786 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2788 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2789 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2792 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2794 if (TREE_VALUE (link))
2795 record_constant_1 (TREE_VALUE (link));
2796 else
2798 tree zero = 0;
2800 obstack_grow (&permanent_obstack,
2801 (char *) &zero, sizeof zero);
2804 if (TREE_PURPOSE (link)
2805 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2806 obstack_grow (&permanent_obstack,
2807 (char *) &TREE_PURPOSE (link),
2808 sizeof TREE_PURPOSE (link));
2809 else if (TREE_PURPOSE (link))
2810 record_constant_1 (TREE_PURPOSE (link));
2811 else if (have_purpose)
2813 int zero = 0;
2815 obstack_grow (&permanent_obstack,
2816 (char *) &zero, sizeof zero);
2820 return;
2822 case ADDR_EXPR:
2824 struct addr_const value;
2826 decode_addr_const (exp, &value);
2827 /* Record the offset. */
2828 obstack_grow (&permanent_obstack,
2829 (char *) &value.offset, sizeof value.offset);
2831 switch (GET_CODE (value.base))
2833 case SYMBOL_REF:
2834 /* Record the symbol name. */
2835 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2836 strlen (XSTR (value.base, 0)) + 1);
2837 break;
2838 case LABEL_REF:
2839 /* Record the address of the CODE_LABEL. It may not have
2840 been emitted yet, so it's UID may be zero. But pointer
2841 identity is good enough. */
2842 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
2843 sizeof (rtx));
2844 break;
2845 default:
2846 abort ();
2849 return;
2851 case PLUS_EXPR:
2852 case MINUS_EXPR:
2853 case RANGE_EXPR:
2854 record_constant_1 (TREE_OPERAND (exp, 0));
2855 record_constant_1 (TREE_OPERAND (exp, 1));
2856 return;
2858 case NOP_EXPR:
2859 case CONVERT_EXPR:
2860 case NON_LVALUE_EXPR:
2861 record_constant_1 (TREE_OPERAND (exp, 0));
2862 return;
2864 default:
2866 tree new = (*lang_hooks.expand_constant) (exp);
2868 if (new != exp)
2869 record_constant_1 (new);
2870 return;
2874 /* Record constant contents. */
2875 obstack_grow (&permanent_obstack, strp, len);
2878 /* Record a list of constant expressions that were passed to
2879 output_constant_def but that could not be output right away. */
2881 struct deferred_constant
2883 struct deferred_constant *next;
2884 tree exp;
2885 int reloc;
2886 int labelno;
2889 static struct deferred_constant *deferred_constants;
2891 /* Another list of constants which should be output after the
2892 function. */
2893 static struct deferred_constant *after_function_constants;
2895 /* Nonzero means defer output of addressed subconstants
2896 (i.e., those for which output_constant_def is called.) */
2897 static int defer_addressed_constants_flag;
2899 /* Start deferring output of subconstants. */
2901 void
2902 defer_addressed_constants ()
2904 defer_addressed_constants_flag++;
2907 /* Stop deferring output of subconstants,
2908 and output now all those that have been deferred. */
2910 void
2911 output_deferred_addressed_constants ()
2913 struct deferred_constant *p, *next;
2915 defer_addressed_constants_flag--;
2917 if (defer_addressed_constants_flag > 0)
2918 return;
2920 for (p = deferred_constants; p; p = next)
2922 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2923 next = p->next;
2924 free (p);
2927 deferred_constants = 0;
2930 /* Output any constants which should appear after a function. */
2932 static void
2933 output_after_function_constants ()
2935 struct deferred_constant *p, *next;
2937 for (p = after_function_constants; p; p = next)
2939 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2940 next = p->next;
2941 free (p);
2944 after_function_constants = 0;
2947 /* Make a copy of the whole tree structure for a constant.
2948 This handles the same types of nodes that compare_constant
2949 and record_constant handle. */
2951 static tree
2952 copy_constant (exp)
2953 tree exp;
2955 switch (TREE_CODE (exp))
2957 case ADDR_EXPR:
2958 /* For ADDR_EXPR, we do not want to copy the decl whose address
2959 is requested. We do want to copy constants though. */
2960 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2961 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2962 copy_constant (TREE_OPERAND (exp, 0)));
2963 else
2964 return copy_node (exp);
2966 case INTEGER_CST:
2967 case REAL_CST:
2968 case STRING_CST:
2969 return copy_node (exp);
2971 case COMPLEX_CST:
2972 return build_complex (TREE_TYPE (exp),
2973 copy_constant (TREE_REALPART (exp)),
2974 copy_constant (TREE_IMAGPART (exp)));
2976 case PLUS_EXPR:
2977 case MINUS_EXPR:
2978 return build (TREE_CODE (exp), TREE_TYPE (exp),
2979 copy_constant (TREE_OPERAND (exp, 0)),
2980 copy_constant (TREE_OPERAND (exp, 1)));
2982 case NOP_EXPR:
2983 case CONVERT_EXPR:
2984 case NON_LVALUE_EXPR:
2985 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2986 copy_constant (TREE_OPERAND (exp, 0)));
2988 case CONSTRUCTOR:
2990 tree copy = copy_node (exp);
2991 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2992 tree tail;
2994 CONSTRUCTOR_ELTS (copy) = list;
2995 for (tail = list; tail; tail = TREE_CHAIN (tail))
2996 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2997 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2998 for (tail = list; tail; tail = TREE_CHAIN (tail))
2999 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3001 return copy;
3004 default:
3005 abort ();
3009 /* Return an rtx representing a reference to constant data in memory
3010 for the constant expression EXP.
3012 If assembler code for such a constant has already been output,
3013 return an rtx to refer to it.
3014 Otherwise, output such a constant in memory (or defer it for later)
3015 and generate an rtx for it.
3017 If DEFER is non-zero, the output of string constants can be deferred
3018 and output only if referenced in the function after all optimizations.
3020 The TREE_CST_RTL of EXP is set up to point to that rtx.
3021 The const_hash_table records which constants already have label strings. */
3024 output_constant_def (exp, defer)
3025 tree exp;
3026 int defer;
3028 int hash;
3029 struct constant_descriptor *desc;
3030 struct deferred_string **defstr;
3031 char label[256];
3032 int reloc;
3033 int found = 1;
3034 int after_function = 0;
3035 int labelno = -1;
3036 rtx rtl;
3038 /* We can't just use the saved RTL if this is a defererred string constant
3039 and we are not to defer anymore. */
3040 if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3041 && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3042 return TREE_CST_RTL (exp);
3044 /* Make sure any other constants whose addresses appear in EXP
3045 are assigned label numbers. */
3047 reloc = output_addressed_constants (exp);
3049 /* Compute hash code of EXP. Search the descriptors for that hash code
3050 to see if any of them describes EXP. If yes, the descriptor records
3051 the label number already assigned. */
3053 hash = const_hash (exp) % MAX_HASH_TABLE;
3055 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3056 if (compare_constant (exp, desc))
3057 break;
3059 if (desc == 0)
3061 /* No constant equal to EXP is known to have been output.
3062 Make a constant descriptor to enter EXP in the hash table.
3063 Assign the label number and record it in the descriptor for
3064 future calls to this function to find. */
3066 /* Create a string containing the label name, in LABEL. */
3067 labelno = const_labelno++;
3068 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3070 desc = record_constant (exp);
3071 desc->next = const_hash_table[hash];
3072 desc->label = ggc_strdup (label);
3073 const_hash_table[hash] = desc;
3075 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3076 rtl = desc->rtl
3077 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3078 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3080 set_mem_attributes (rtl, exp, 1);
3081 set_mem_alias_set (rtl, 0);
3082 set_mem_alias_set (rtl, const_alias_set);
3084 found = 0;
3086 else
3087 rtl = desc->rtl;
3089 if (TREE_CODE (exp) != INTEGER_CST)
3090 TREE_CST_RTL (exp) = rtl;
3092 /* Optionally set flags or add text to the name to record information
3093 such as that it is a function name. If the name is changed, the macro
3094 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3095 /* A previously-processed constant would already have section info
3096 encoded in it. */
3097 if (! found)
3099 /* Take care not to invoke targetm.encode_section_info for
3100 constants which don't have a TREE_CST_RTL. */
3101 if (TREE_CODE (exp) != INTEGER_CST)
3102 (*targetm.encode_section_info) (exp, true);
3104 desc->rtl = rtl;
3105 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3108 #ifdef CONSTANT_AFTER_FUNCTION_P
3109 if (current_function_decl != 0
3110 && CONSTANT_AFTER_FUNCTION_P (exp))
3111 after_function = 1;
3112 #endif
3114 if (found
3115 && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3116 && (!defer || defer_addressed_constants_flag || after_function))
3118 defstr = (struct deferred_string **)
3119 htab_find_slot_with_hash (const_str_htab, desc->label,
3120 STRHASH (desc->label), NO_INSERT);
3121 if (defstr)
3123 /* If the string is currently deferred but we need to output it now,
3124 remove it from deferred string hash table. */
3125 found = 0;
3126 labelno = (*defstr)->labelno;
3127 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3128 htab_clear_slot (const_str_htab, (void **) defstr);
3132 /* If this is the first time we've seen this particular constant,
3133 output it (or defer its output for later). */
3134 if (! found)
3136 if (defer_addressed_constants_flag || after_function)
3138 struct deferred_constant *p
3139 = (struct deferred_constant *)
3140 xmalloc (sizeof (struct deferred_constant));
3142 p->exp = copy_constant (exp);
3143 p->reloc = reloc;
3144 p->labelno = labelno;
3145 if (after_function)
3147 p->next = after_function_constants;
3148 after_function_constants = p;
3150 else
3152 p->next = deferred_constants;
3153 deferred_constants = p;
3156 else
3158 /* Do no output if -fsyntax-only. */
3159 if (! flag_syntax_only)
3161 if (TREE_CODE (exp) != STRING_CST
3162 || !defer
3163 || flag_writable_strings
3164 || (defstr = (struct deferred_string **)
3165 htab_find_slot_with_hash (const_str_htab,
3166 desc->label,
3167 STRHASH (desc->label),
3168 INSERT)) == NULL)
3169 output_constant_def_contents (exp, reloc, labelno);
3170 else
3172 struct deferred_string *p;
3174 p = (struct deferred_string *)
3175 xmalloc (sizeof (struct deferred_string));
3177 p->exp = copy_constant (exp);
3178 p->label = desc->label;
3179 p->labelno = labelno;
3180 *defstr = p;
3181 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3187 return rtl;
3190 /* Now output assembler code to define the label for EXP,
3191 and follow it with the data of EXP. */
3193 static void
3194 output_constant_def_contents (exp, reloc, labelno)
3195 tree exp;
3196 int reloc;
3197 int labelno;
3199 int align;
3201 /* Align the location counter as required by EXP's data type. */
3202 align = TYPE_ALIGN (TREE_TYPE (exp));
3203 #ifdef CONSTANT_ALIGNMENT
3204 align = CONSTANT_ALIGNMENT (exp, align);
3205 #endif
3207 if (IN_NAMED_SECTION (exp))
3208 named_section (exp, NULL, reloc);
3209 else
3210 (*targetm.asm_out.select_section) (exp, reloc, align);
3212 if (align > BITS_PER_UNIT)
3214 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3217 /* Output the label itself. */
3218 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3220 /* Output the value of EXP. */
3221 output_constant (exp,
3222 (TREE_CODE (exp) == STRING_CST
3223 ? MAX (TREE_STRING_LENGTH (exp),
3224 int_size_in_bytes (TREE_TYPE (exp)))
3225 : int_size_in_bytes (TREE_TYPE (exp))),
3226 align);
3230 /* Structure to represent sufficient information about a constant so that
3231 it can be output when the constant pool is output, so that function
3232 integration can be done, and to simplify handling on machines that reference
3233 constant pool as base+displacement. */
3235 struct pool_constant
3237 struct constant_descriptor *desc;
3238 struct pool_constant *next, *next_sym;
3239 rtx constant;
3240 enum machine_mode mode;
3241 int labelno;
3242 unsigned int align;
3243 HOST_WIDE_INT offset;
3244 int mark;
3247 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3248 The argument is XSTR (... , 0) */
3250 #define SYMHASH(LABEL) \
3251 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3253 /* Initialize constant pool hashing for a new function. */
3255 void
3256 init_varasm_status (f)
3257 struct function *f;
3259 struct varasm_status *p;
3260 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3261 f->varasm = p;
3262 p->x_const_rtx_hash_table
3263 = ((struct constant_descriptor **)
3264 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3265 p->x_const_rtx_sym_hash_table
3266 = ((struct pool_constant **)
3267 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3269 p->x_first_pool = p->x_last_pool = 0;
3270 p->x_pool_offset = 0;
3273 /* Mark PC for GC. */
3275 static void
3276 mark_pool_constant (pc)
3277 struct pool_constant *pc;
3279 while (pc)
3281 ggc_mark (pc);
3282 ggc_mark_rtx (pc->constant);
3283 ggc_mark_rtx (pc->desc->rtl);
3284 pc = pc->next;
3288 /* Mark P for GC. */
3290 void
3291 mark_varasm_status (p)
3292 struct varasm_status *p;
3294 if (p == NULL)
3295 return;
3297 mark_pool_constant (p->x_first_pool);
3300 /* Clear out all parts of the state in F that can safely be discarded
3301 after the function has been compiled, to let garbage collection
3302 reclaim the memory. */
3304 void
3305 free_varasm_status (f)
3306 struct function *f;
3308 struct varasm_status *p;
3309 int i;
3311 p = f->varasm;
3313 /* Clear out the hash tables. */
3314 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3316 struct constant_descriptor *cd;
3318 cd = p->x_const_rtx_hash_table[i];
3319 while (cd)
3321 struct constant_descriptor *next = cd->next;
3323 free (cd);
3324 cd = next;
3328 free (p->x_const_rtx_hash_table);
3329 free (p->x_const_rtx_sym_hash_table);
3330 free (p);
3332 f->varasm = NULL;
3336 /* Express an rtx for a constant integer (perhaps symbolic)
3337 as the sum of a symbol or label plus an explicit integer.
3338 They are stored into VALUE. */
3340 static void
3341 decode_rtx_const (mode, x, value)
3342 enum machine_mode mode;
3343 rtx x;
3344 struct rtx_const *value;
3346 /* Clear the whole structure, including any gaps. */
3347 memset (value, 0, sizeof (struct rtx_const));
3349 value->kind = RTX_INT; /* Most usual kind. */
3350 value->mode = mode;
3352 switch (GET_CODE (x))
3354 case CONST_DOUBLE:
3355 value->kind = RTX_DOUBLE;
3356 if (GET_MODE (x) != VOIDmode)
3358 value->mode = GET_MODE (x);
3359 REAL_VALUE_FROM_CONST_DOUBLE (value->un.du, x);
3361 else
3363 value->un.di.low = CONST_DOUBLE_LOW (x);
3364 value->un.di.high = CONST_DOUBLE_HIGH (x);
3366 break;
3368 case CONST_VECTOR:
3370 int units, i;
3371 rtx elt;
3373 units = CONST_VECTOR_NUNITS (x);
3374 value->kind = RTX_VECTOR;
3375 value->mode = mode;
3377 for (i = 0; i < units; ++i)
3379 elt = CONST_VECTOR_ELT (x, i);
3380 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
3382 value->un.veclo[i] = (HOST_WIDE_INT) INTVAL (elt);
3383 value->un.vechi[i] = 0;
3385 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3387 value->un.veclo[i] = (HOST_WIDE_INT) CONST_DOUBLE_LOW (elt);
3388 value->un.vechi[i] = (HOST_WIDE_INT) CONST_DOUBLE_HIGH (elt);
3390 else
3391 abort ();
3394 break;
3396 case CONST_INT:
3397 value->un.addr.offset = INTVAL (x);
3398 break;
3400 case SYMBOL_REF:
3401 case LABEL_REF:
3402 case PC:
3403 value->un.addr.base = x;
3404 break;
3406 case CONST:
3407 x = XEXP (x, 0);
3408 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3410 value->un.addr.base = XEXP (x, 0);
3411 value->un.addr.offset = INTVAL (XEXP (x, 1));
3413 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3415 value->un.addr.base = XEXP (x, 0);
3416 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3418 else
3420 value->un.addr.base = x;
3421 value->un.addr.offset = 0;
3423 break;
3425 default:
3426 value->kind = RTX_UNKNOWN;
3427 break;
3430 if (value->kind == RTX_INT && value->un.addr.base != 0
3431 && GET_CODE (value->un.addr.base) == UNSPEC)
3433 /* For a simple UNSPEC, the base is set to the
3434 operand, the kind field is set to the index of
3435 the unspec expression.
3436 Together with the code below, in case that
3437 the operand is a SYMBOL_REF or LABEL_REF,
3438 the address of the string or the code_label
3439 is taken as base. */
3440 if (XVECLEN (value->un.addr.base, 0) == 1)
3442 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
3443 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
3447 if (value->kind > RTX_DOUBLE && value->un.addr.base != 0)
3448 switch (GET_CODE (value->un.addr.base))
3450 case SYMBOL_REF:
3451 /* Use the string's address, not the SYMBOL_REF's address,
3452 for the sake of addresses of library routines. */
3453 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3454 break;
3456 case LABEL_REF:
3457 /* For a LABEL_REF, compare labels. */
3458 value->un.addr.base = XEXP (value->un.addr.base, 0);
3460 default:
3461 break;
3465 /* Given a MINUS expression, simplify it if both sides
3466 include the same symbol. */
3469 simplify_subtraction (x)
3470 rtx x;
3472 struct rtx_const val0, val1;
3474 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3475 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3477 if (val0.kind > RTX_DOUBLE
3478 && val0.kind == val1.kind
3479 && val0.un.addr.base == val1.un.addr.base)
3480 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3482 return x;
3485 /* Compute a hash code for a constant RTL expression. */
3487 static int
3488 const_hash_rtx (mode, x)
3489 enum machine_mode mode;
3490 rtx x;
3492 int hi;
3493 size_t i;
3495 struct rtx_const value;
3496 decode_rtx_const (mode, x, &value);
3498 /* Compute hashing function */
3499 hi = 0;
3500 for (i = 0; i < sizeof value / sizeof (int); i++)
3501 hi += ((int *) &value)[i];
3503 hi &= (1 << HASHBITS) - 1;
3504 hi %= MAX_RTX_HASH_TABLE;
3505 return hi;
3508 /* Compare a constant rtl object X with a constant-descriptor DESC.
3509 Return 1 if DESC describes a constant with the same value as X. */
3511 static int
3512 compare_constant_rtx (mode, x, desc)
3513 enum machine_mode mode;
3514 rtx x;
3515 struct constant_descriptor *desc;
3517 int *p = (int *) desc->u.contents;
3518 int *strp;
3519 int len;
3520 struct rtx_const value;
3522 decode_rtx_const (mode, x, &value);
3523 strp = (int *) &value;
3524 len = sizeof value / sizeof (int);
3526 /* Compare constant contents. */
3527 while (--len >= 0)
3528 if (*p++ != *strp++)
3529 return 0;
3531 return 1;
3534 /* Construct a constant descriptor for the rtl-expression X.
3535 It is up to the caller to enter the descriptor in the hash table. */
3537 static struct constant_descriptor *
3538 record_constant_rtx (mode, x)
3539 enum machine_mode mode;
3540 rtx x;
3542 struct constant_descriptor *ptr;
3544 ptr = ((struct constant_descriptor *)
3545 xcalloc (1, (offsetof (struct constant_descriptor, u)
3546 + sizeof (struct rtx_const))));
3547 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3549 return ptr;
3552 /* Given a constant rtx X, return a MEM for the location in memory at which
3553 this constant has been placed. Return 0 if it not has been placed yet. */
3556 mem_for_const_double (x)
3557 rtx x;
3559 enum machine_mode mode = GET_MODE (x);
3560 struct constant_descriptor *desc;
3562 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3563 desc = desc->next)
3564 if (compare_constant_rtx (mode, x, desc))
3565 return desc->rtl;
3567 return 0;
3570 /* Given a constant rtx X, make (or find) a memory constant for its value
3571 and return a MEM rtx to refer to it in memory. */
3574 force_const_mem (mode, x)
3575 enum machine_mode mode;
3576 rtx x;
3578 int hash;
3579 struct constant_descriptor *desc;
3580 char label[256];
3581 rtx def;
3582 struct pool_constant *pool;
3583 unsigned int align;
3585 /* Compute hash code of X. Search the descriptors for that hash code
3586 to see if any of them describes X. If yes, we have an rtx to use. */
3587 hash = const_hash_rtx (mode, x);
3588 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3589 if (compare_constant_rtx (mode, x, desc))
3590 return desc->rtl;
3592 /* No constant equal to X is known to have been output.
3593 Make a constant descriptor to enter X in the hash table
3594 and make a MEM for it. */
3595 desc = record_constant_rtx (mode, x);
3596 desc->next = const_rtx_hash_table[hash];
3597 const_rtx_hash_table[hash] = desc;
3599 /* Align the location counter as required by EXP's data type. */
3600 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3601 #ifdef CONSTANT_ALIGNMENT
3602 align = CONSTANT_ALIGNMENT (make_tree ((*lang_hooks.types.type_for_mode)
3603 (mode, 0), x), align);
3604 #endif
3606 pool_offset += (align / BITS_PER_UNIT) - 1;
3607 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3609 if (GET_CODE (x) == LABEL_REF)
3610 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3612 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3613 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3614 pool->desc = desc;
3615 pool->constant = x;
3616 pool->mode = mode;
3617 pool->labelno = const_labelno;
3618 pool->align = align;
3619 pool->offset = pool_offset;
3620 pool->mark = 1;
3621 pool->next = 0;
3623 if (last_pool == 0)
3624 first_pool = pool;
3625 else
3626 last_pool->next = pool;
3628 last_pool = pool;
3629 pool_offset += GET_MODE_SIZE (mode);
3631 /* Create a string containing the label name, in LABEL. */
3632 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3634 ++const_labelno;
3636 /* Construct the SYMBOL_REF and the MEM. */
3638 pool->desc->rtl = def
3639 = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3640 set_mem_alias_set (def, const_alias_set);
3641 set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
3642 RTX_UNCHANGING_P (def) = 1;
3644 /* Add label to symbol hash table. */
3645 hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3646 pool->next_sym = const_rtx_sym_hash_table[hash];
3647 const_rtx_sym_hash_table[hash] = pool;
3649 /* Mark the symbol_ref as belonging to this constants pool. */
3650 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3651 current_function_uses_const_pool = 1;
3653 return def;
3656 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3657 the corresponding pool_constant structure. */
3659 static struct pool_constant *
3660 find_pool_constant (f, addr)
3661 struct function *f;
3662 rtx addr;
3664 struct pool_constant *pool;
3665 const char *label = XSTR (addr, 0);
3667 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3668 pool = pool->next_sym)
3669 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3670 return pool;
3672 abort ();
3675 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3678 get_pool_constant (addr)
3679 rtx addr;
3681 return (find_pool_constant (cfun, addr))->constant;
3684 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3685 and whether it has been output or not. */
3688 get_pool_constant_mark (addr, pmarked)
3689 rtx addr;
3690 bool *pmarked;
3692 struct pool_constant *pool = find_pool_constant (cfun, addr);
3693 *pmarked = (pool->mark != 0);
3694 return pool->constant;
3697 /* Likewise, but for the constant pool of a specific function. */
3700 get_pool_constant_for_function (f, addr)
3701 struct function *f;
3702 rtx addr;
3704 return (find_pool_constant (f, addr))->constant;
3707 /* Similar, return the mode. */
3709 enum machine_mode
3710 get_pool_mode (addr)
3711 rtx addr;
3713 return (find_pool_constant (cfun, addr))->mode;
3716 enum machine_mode
3717 get_pool_mode_for_function (f, addr)
3718 struct function *f;
3719 rtx addr;
3721 return (find_pool_constant (f, addr))->mode;
3724 /* Similar, return the offset in the constant pool. */
3727 get_pool_offset (addr)
3728 rtx addr;
3730 return (find_pool_constant (cfun, addr))->offset;
3733 /* Return the size of the constant pool. */
3736 get_pool_size ()
3738 return pool_offset;
3741 /* Write all the constants in the constant pool. */
3743 void
3744 output_constant_pool (fnname, fndecl)
3745 const char *fnname ATTRIBUTE_UNUSED;
3746 tree fndecl ATTRIBUTE_UNUSED;
3748 struct pool_constant *pool;
3749 rtx x;
3750 REAL_VALUE_TYPE r;
3752 /* It is possible for gcc to call force_const_mem and then to later
3753 discard the instructions which refer to the constant. In such a
3754 case we do not need to output the constant. */
3755 mark_constant_pool ();
3757 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3758 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3759 #endif
3761 for (pool = first_pool; pool; pool = pool->next)
3763 rtx tmp;
3765 x = pool->constant;
3767 if (! pool->mark)
3768 continue;
3770 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3771 whose CODE_LABEL has been deleted. This can occur if a jump table
3772 is eliminated by optimization. If so, write a constant of zero
3773 instead. Note that this can also happen by turning the
3774 CODE_LABEL into a NOTE. */
3775 /* ??? This seems completely and utterly wrong. Certainly it's
3776 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3777 functioning even with INSN_DELETED_P and friends. */
3779 tmp = x;
3780 switch (GET_CODE (x))
3782 case CONST:
3783 if (GET_CODE (XEXP (x, 0)) != PLUS
3784 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3785 break;
3786 tmp = XEXP (XEXP (x, 0), 0);
3787 /* FALLTHRU */
3789 case LABEL_REF:
3790 tmp = XEXP (x, 0);
3791 if (INSN_DELETED_P (tmp)
3792 || (GET_CODE (tmp) == NOTE
3793 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3795 abort ();
3796 x = const0_rtx;
3798 break;
3800 default:
3801 break;
3804 /* First switch to correct section. */
3805 (*targetm.asm_out.select_rtx_section) (pool->mode, x, pool->align);
3807 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3808 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3809 pool->align, pool->labelno, done);
3810 #endif
3812 assemble_align (pool->align);
3814 /* Output the label. */
3815 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3817 /* Output the value of the constant itself. */
3818 switch (GET_MODE_CLASS (pool->mode))
3820 case MODE_FLOAT:
3821 if (GET_CODE (x) != CONST_DOUBLE)
3822 abort ();
3824 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3825 assemble_real (r, pool->mode, pool->align);
3826 break;
3828 case MODE_INT:
3829 case MODE_PARTIAL_INT:
3830 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
3831 break;
3833 case MODE_VECTOR_FLOAT:
3835 int i, units;
3836 rtx elt;
3838 if (GET_CODE (x) != CONST_VECTOR)
3839 abort ();
3841 units = CONST_VECTOR_NUNITS (x);
3843 for (i = 0; i < units; i++)
3845 elt = CONST_VECTOR_ELT (x, i);
3846 REAL_VALUE_FROM_CONST_DOUBLE (r, elt);
3847 assemble_real (r, GET_MODE_INNER (pool->mode), pool->align);
3850 break;
3852 case MODE_VECTOR_INT:
3854 int i, units;
3855 rtx elt;
3857 if (GET_CODE (x) != CONST_VECTOR)
3858 abort ();
3860 units = CONST_VECTOR_NUNITS (x);
3862 for (i = 0; i < units; i++)
3864 elt = CONST_VECTOR_ELT (x, i);
3865 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
3866 pool->align, 1);
3869 break;
3871 default:
3872 abort ();
3875 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3876 done: ;
3877 #endif
3880 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3881 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3882 #endif
3884 /* Done with this pool. */
3885 first_pool = last_pool = 0;
3888 /* Look through the instructions for this function, and mark all the
3889 entries in the constant pool which are actually being used.
3890 Emit used deferred strings. */
3892 static void
3893 mark_constant_pool ()
3895 rtx insn;
3896 struct pool_constant *pool;
3898 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
3899 return;
3901 for (pool = first_pool; pool; pool = pool->next)
3902 pool->mark = 0;
3904 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3905 if (INSN_P (insn))
3906 mark_constants (PATTERN (insn));
3908 for (insn = current_function_epilogue_delay_list;
3909 insn;
3910 insn = XEXP (insn, 1))
3911 if (INSN_P (insn))
3912 mark_constants (PATTERN (insn));
3915 /* Look through appropriate parts of X, marking all entries in the
3916 constant pool which are actually being used. Entries that are only
3917 referenced by other constants are also marked as used. Emit
3918 deferred strings that are used. */
3920 static void
3921 mark_constants (x)
3922 rtx x;
3924 int i;
3925 const char *format_ptr;
3927 if (x == 0)
3928 return;
3930 if (GET_CODE (x) == SYMBOL_REF)
3932 mark_constant (&x, NULL);
3933 return;
3936 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3937 insns, not any notes that may be attached. We don't want to mark
3938 a constant just because it happens to appear in a REG_EQUIV note. */
3939 if (INSN_P (x))
3941 mark_constants (PATTERN (x));
3942 return;
3945 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3947 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3949 switch (*format_ptr++)
3951 case 'e':
3952 mark_constants (XEXP (x, i));
3953 break;
3955 case 'E':
3956 if (XVEC (x, i) != 0)
3958 int j;
3960 for (j = 0; j < XVECLEN (x, i); j++)
3961 mark_constants (XVECEXP (x, i, j));
3963 break;
3965 case 'S':
3966 case 's':
3967 case '0':
3968 case 'i':
3969 case 'w':
3970 case 'n':
3971 case 'u':
3972 break;
3974 default:
3975 abort ();
3980 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3981 to as used. Emit referenced deferred strings. This function can
3982 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3984 static int
3985 mark_constant (current_rtx, data)
3986 rtx *current_rtx;
3987 void *data ATTRIBUTE_UNUSED;
3989 rtx x = *current_rtx;
3991 if (x == NULL_RTX)
3992 return 0;
3994 else if (GET_CODE (x) == SYMBOL_REF)
3996 if (CONSTANT_POOL_ADDRESS_P (x))
3998 struct pool_constant *pool = find_pool_constant (cfun, x);
3999 if (pool->mark == 0)
4001 pool->mark = 1;
4002 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4004 else
4005 return -1;
4007 else if (STRING_POOL_ADDRESS_P (x))
4009 struct deferred_string **defstr;
4011 defstr = (struct deferred_string **)
4012 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4013 STRHASH (XSTR (x, 0)), NO_INSERT);
4014 if (defstr)
4016 struct deferred_string *p = *defstr;
4018 STRING_POOL_ADDRESS_P (x) = 0;
4019 output_constant_def_contents (p->exp, 0, p->labelno);
4020 htab_clear_slot (const_str_htab, (void **) defstr);
4024 return 0;
4027 /* Find all the constants whose addresses are referenced inside of EXP,
4028 and make sure assembler code with a label has been output for each one.
4029 Indicate whether an ADDR_EXPR has been encountered. */
4031 static int
4032 output_addressed_constants (exp)
4033 tree exp;
4035 int reloc = 0;
4036 tree tem;
4038 /* Give the front-end a chance to convert VALUE to something that
4039 looks more like a constant to the back-end. */
4040 exp = (*lang_hooks.expand_constant) (exp);
4042 switch (TREE_CODE (exp))
4044 case ADDR_EXPR:
4045 /* Go inside any operations that get_inner_reference can handle and see
4046 if what's inside is a constant: no need to do anything here for
4047 addresses of variables or functions. */
4048 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4049 tem = TREE_OPERAND (tem, 0))
4052 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4053 || TREE_CODE (tem) == CONSTRUCTOR)
4054 output_constant_def (tem, 0);
4056 if (TREE_PUBLIC (tem))
4057 reloc |= 2;
4058 else
4059 reloc |= 1;
4060 break;
4062 case PLUS_EXPR:
4063 case MINUS_EXPR:
4064 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4065 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4066 break;
4068 case NOP_EXPR:
4069 case CONVERT_EXPR:
4070 case NON_LVALUE_EXPR:
4071 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4072 break;
4074 case CONSTRUCTOR:
4075 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4076 if (TREE_VALUE (tem) != 0)
4077 reloc |= output_addressed_constants (TREE_VALUE (tem));
4079 break;
4081 default:
4082 break;
4084 return reloc;
4087 /* Return nonzero if VALUE is a valid constant-valued expression
4088 for use in initializing a static variable; one that can be an
4089 element of a "constant" initializer.
4091 Return null_pointer_node if the value is absolute;
4092 if it is relocatable, return the variable that determines the relocation.
4093 We assume that VALUE has been folded as much as possible;
4094 therefore, we do not need to check for such things as
4095 arithmetic-combinations of integers. */
4097 tree
4098 initializer_constant_valid_p (value, endtype)
4099 tree value;
4100 tree endtype;
4102 /* Give the front-end a chance to convert VALUE to something that
4103 looks more like a constant to the back-end. */
4104 value = (*lang_hooks.expand_constant) (value);
4106 switch (TREE_CODE (value))
4108 case CONSTRUCTOR:
4109 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4110 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4111 && TREE_CONSTANT (value)
4112 && CONSTRUCTOR_ELTS (value))
4113 return
4114 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4115 endtype);
4117 return TREE_STATIC (value) ? null_pointer_node : 0;
4119 case INTEGER_CST:
4120 case VECTOR_CST:
4121 case REAL_CST:
4122 case STRING_CST:
4123 case COMPLEX_CST:
4124 return null_pointer_node;
4126 case ADDR_EXPR:
4127 case FDESC_EXPR:
4128 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4130 case VIEW_CONVERT_EXPR:
4131 case NON_LVALUE_EXPR:
4132 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4134 case CONVERT_EXPR:
4135 case NOP_EXPR:
4136 /* Allow conversions between pointer types. */
4137 if (POINTER_TYPE_P (TREE_TYPE (value))
4138 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4139 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4141 /* Allow conversions between real types. */
4142 if (FLOAT_TYPE_P (TREE_TYPE (value))
4143 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4144 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4146 /* Allow length-preserving conversions between integer types. */
4147 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4148 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4149 && (TYPE_PRECISION (TREE_TYPE (value))
4150 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4151 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4153 /* Allow conversions between other integer types only if
4154 explicit value. */
4155 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4156 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4158 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4159 endtype);
4160 if (inner == null_pointer_node)
4161 return null_pointer_node;
4162 break;
4165 /* Allow (int) &foo provided int is as wide as a pointer. */
4166 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4167 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4168 && (TYPE_PRECISION (TREE_TYPE (value))
4169 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4170 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4171 endtype);
4173 /* Likewise conversions from int to pointers, but also allow
4174 conversions from 0. */
4175 if (POINTER_TYPE_P (TREE_TYPE (value))
4176 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4178 if (integer_zerop (TREE_OPERAND (value, 0)))
4179 return null_pointer_node;
4180 else if (TYPE_PRECISION (TREE_TYPE (value))
4181 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4182 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4183 endtype);
4186 /* Allow conversions to union types if the value inside is okay. */
4187 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4188 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4189 endtype);
4190 break;
4192 case PLUS_EXPR:
4193 if (! INTEGRAL_TYPE_P (endtype)
4194 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4196 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4197 endtype);
4198 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4199 endtype);
4200 /* If either term is absolute, use the other terms relocation. */
4201 if (valid0 == null_pointer_node)
4202 return valid1;
4203 if (valid1 == null_pointer_node)
4204 return valid0;
4206 break;
4208 case MINUS_EXPR:
4209 if (! INTEGRAL_TYPE_P (endtype)
4210 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4212 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4213 endtype);
4214 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4215 endtype);
4216 /* Win if second argument is absolute. */
4217 if (valid1 == null_pointer_node)
4218 return valid0;
4219 /* Win if both arguments have the same relocation.
4220 Then the value is absolute. */
4221 if (valid0 == valid1 && valid0 != 0)
4222 return null_pointer_node;
4224 /* Since GCC guarantees that string constants are unique in the
4225 generated code, a subtraction between two copies of the same
4226 constant string is absolute. */
4227 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4228 valid1 && TREE_CODE (valid1) == STRING_CST &&
4229 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4230 return null_pointer_node;
4233 /* Support differences between labels. */
4234 if (INTEGRAL_TYPE_P (endtype))
4236 tree op0, op1;
4237 op0 = TREE_OPERAND (value, 0);
4238 op1 = TREE_OPERAND (value, 1);
4240 /* Like STRIP_NOPS except allow the operand mode to widen.
4241 This works around a feature of fold that simplfies
4242 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4243 that the narrower operation is cheaper. */
4245 while (TREE_CODE (op0) == NOP_EXPR
4246 || TREE_CODE (op0) == CONVERT_EXPR
4247 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4249 tree inner = TREE_OPERAND (op0, 0);
4250 if (inner == error_mark_node
4251 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4252 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4253 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4254 break;
4255 op0 = inner;
4258 while (TREE_CODE (op1) == NOP_EXPR
4259 || TREE_CODE (op1) == CONVERT_EXPR
4260 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4262 tree inner = TREE_OPERAND (op1, 0);
4263 if (inner == error_mark_node
4264 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4265 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4266 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4267 break;
4268 op1 = inner;
4271 if (TREE_CODE (op0) == ADDR_EXPR
4272 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4273 && TREE_CODE (op1) == ADDR_EXPR
4274 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4275 return null_pointer_node;
4277 break;
4279 default:
4280 break;
4283 return 0;
4286 /* Output assembler code for constant EXP to FILE, with no label.
4287 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4288 Assumes output_addressed_constants has been done on EXP already.
4290 Generate exactly SIZE bytes of assembler data, padding at the end
4291 with zeros if necessary. SIZE must always be specified.
4293 SIZE is important for structure constructors,
4294 since trailing members may have been omitted from the constructor.
4295 It is also important for initialization of arrays from string constants
4296 since the full length of the string constant might not be wanted.
4297 It is also needed for initialization of unions, where the initializer's
4298 type is just one member, and that may not be as long as the union.
4300 There a case in which we would fail to output exactly SIZE bytes:
4301 for a structure constructor that wants to produce more than SIZE bytes.
4302 But such constructors will never be generated for any possible input.
4304 ALIGN is the alignment of the data in bits. */
4306 void
4307 output_constant (exp, size, align)
4308 tree exp;
4309 HOST_WIDE_INT size;
4310 unsigned int align;
4312 enum tree_code code;
4313 HOST_WIDE_INT thissize;
4315 /* Some front-ends use constants other than the standard language-indepdent
4316 varieties, but which may still be output directly. Give the front-end a
4317 chance to convert EXP to a language-independent representation. */
4318 exp = (*lang_hooks.expand_constant) (exp);
4320 if (size == 0 || flag_syntax_only)
4321 return;
4323 /* Eliminate any conversions since we'll be outputting the underlying
4324 constant. */
4325 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4326 || TREE_CODE (exp) == NON_LVALUE_EXPR
4327 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4328 exp = TREE_OPERAND (exp, 0);
4330 code = TREE_CODE (TREE_TYPE (exp));
4331 thissize = int_size_in_bytes (TREE_TYPE (exp));
4333 /* Allow a constructor with no elements for any data type.
4334 This means to fill the space with zeros. */
4335 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4337 assemble_zeros (size);
4338 return;
4341 if (TREE_CODE (exp) == FDESC_EXPR)
4343 #ifdef ASM_OUTPUT_FDESC
4344 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4345 tree decl = TREE_OPERAND (exp, 0);
4346 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4347 #else
4348 abort ();
4349 #endif
4350 return;
4353 /* Now output the underlying data. If we've handling the padding, return.
4354 Otherwise, break and ensure THISSIZE is the size written. */
4355 switch (code)
4357 case CHAR_TYPE:
4358 case BOOLEAN_TYPE:
4359 case INTEGER_TYPE:
4360 case ENUMERAL_TYPE:
4361 case POINTER_TYPE:
4362 case REFERENCE_TYPE:
4363 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4364 EXPAND_INITIALIZER),
4365 size, align, 0))
4366 error ("initializer for integer value is too complicated");
4367 break;
4369 case REAL_TYPE:
4370 if (TREE_CODE (exp) != REAL_CST)
4371 error ("initializer for floating value is not a floating constant");
4373 assemble_real (TREE_REAL_CST (exp),
4374 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4375 align);
4376 break;
4378 case COMPLEX_TYPE:
4379 output_constant (TREE_REALPART (exp), thissize / 2, align);
4380 output_constant (TREE_IMAGPART (exp), thissize / 2,
4381 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4382 break;
4384 case ARRAY_TYPE:
4385 case VECTOR_TYPE:
4386 if (TREE_CODE (exp) == CONSTRUCTOR)
4388 output_constructor (exp, size, align);
4389 return;
4391 else if (TREE_CODE (exp) == STRING_CST)
4393 thissize = MIN (TREE_STRING_LENGTH (exp), size);
4394 assemble_string (TREE_STRING_POINTER (exp), thissize);
4396 else
4397 abort ();
4398 break;
4400 case RECORD_TYPE:
4401 case UNION_TYPE:
4402 if (TREE_CODE (exp) == CONSTRUCTOR)
4403 output_constructor (exp, size, align);
4404 else
4405 abort ();
4406 return;
4408 case SET_TYPE:
4409 if (TREE_CODE (exp) == INTEGER_CST)
4410 assemble_integer (expand_expr (exp, NULL_RTX,
4411 VOIDmode, EXPAND_INITIALIZER),
4412 thissize, align, 1);
4413 else if (TREE_CODE (exp) == CONSTRUCTOR)
4415 unsigned char *buffer = (unsigned char *) alloca (thissize);
4416 if (get_set_constructor_bytes (exp, buffer, thissize))
4417 abort ();
4418 assemble_string ((char *) buffer, thissize);
4420 else
4421 error ("unknown set constructor type");
4422 return;
4424 case ERROR_MARK:
4425 return;
4427 default:
4428 abort ();
4431 size -= thissize;
4432 if (size > 0)
4433 assemble_zeros (size);
4437 /* Subroutine of output_constructor, used for computing the size of
4438 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4439 type with an unspecified upper bound. */
4441 static unsigned HOST_WIDE_INT
4442 array_size_for_constructor (val)
4443 tree val;
4445 tree max_index, i;
4447 /* This code used to attempt to handle string constants that are not
4448 arrays of single-bytes, but nothing else does, so there's no point in
4449 doing it here. */
4450 if (TREE_CODE (val) == STRING_CST)
4451 return TREE_STRING_LENGTH (val);
4453 max_index = NULL_TREE;
4454 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
4456 tree index = TREE_PURPOSE (i);
4458 if (TREE_CODE (index) == RANGE_EXPR)
4459 index = TREE_OPERAND (index, 1);
4460 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4461 max_index = index;
4464 if (max_index == NULL_TREE)
4465 return 0;
4467 /* Compute the total number of array elements. */
4468 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4469 convert (sizetype,
4470 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4471 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4473 /* Multiply by the array element unit size to find number of bytes. */
4474 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4476 return tree_low_cst (i, 1);
4479 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4480 Generate at least SIZE bytes, padding if necessary. */
4482 static void
4483 output_constructor (exp, size, align)
4484 tree exp;
4485 HOST_WIDE_INT size;
4486 unsigned int align;
4488 tree type = TREE_TYPE (exp);
4489 tree link, field = 0;
4490 tree min_index = 0;
4491 /* Number of bytes output or skipped so far.
4492 In other words, current position within the constructor. */
4493 HOST_WIDE_INT total_bytes = 0;
4494 /* Non-zero means BYTE contains part of a byte, to be output. */
4495 int byte_buffer_in_use = 0;
4496 int byte = 0;
4498 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4499 abort ();
4501 if (TREE_CODE (type) == RECORD_TYPE)
4502 field = TYPE_FIELDS (type);
4504 if (TREE_CODE (type) == ARRAY_TYPE
4505 && TYPE_DOMAIN (type) != 0)
4506 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4508 /* As LINK goes through the elements of the constant,
4509 FIELD goes through the structure fields, if the constant is a structure.
4510 if the constant is a union, then we override this,
4511 by getting the field from the TREE_LIST element.
4512 But the constant could also be an array. Then FIELD is zero.
4514 There is always a maximum of one element in the chain LINK for unions
4515 (even if the initializer in a source program incorrectly contains
4516 more one). */
4517 for (link = CONSTRUCTOR_ELTS (exp);
4518 link;
4519 link = TREE_CHAIN (link),
4520 field = field ? TREE_CHAIN (field) : 0)
4522 tree val = TREE_VALUE (link);
4523 tree index = 0;
4525 /* The element in a union constructor specifies the proper field
4526 or index. */
4527 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4528 || TREE_CODE (type) == QUAL_UNION_TYPE)
4529 && TREE_PURPOSE (link) != 0)
4530 field = TREE_PURPOSE (link);
4532 else if (TREE_CODE (type) == ARRAY_TYPE)
4533 index = TREE_PURPOSE (link);
4535 /* Eliminate the marker that makes a cast not be an lvalue. */
4536 if (val != 0)
4537 STRIP_NOPS (val);
4539 if (index && TREE_CODE (index) == RANGE_EXPR)
4541 unsigned HOST_WIDE_INT fieldsize
4542 = int_size_in_bytes (TREE_TYPE (type));
4543 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4544 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4545 HOST_WIDE_INT index;
4546 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4548 for (index = lo_index; index <= hi_index; index++)
4550 /* Output the element's initial value. */
4551 if (val == 0)
4552 assemble_zeros (fieldsize);
4553 else
4554 output_constant (val, fieldsize, align2);
4556 /* Count its size. */
4557 total_bytes += fieldsize;
4560 else if (field == 0 || !DECL_BIT_FIELD (field))
4562 /* An element that is not a bit-field. */
4564 unsigned HOST_WIDE_INT fieldsize;
4565 /* Since this structure is static,
4566 we know the positions are constant. */
4567 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4568 unsigned int align2;
4570 if (index != 0)
4571 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4572 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4574 /* Output any buffered-up bit-fields preceding this element. */
4575 if (byte_buffer_in_use)
4577 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4578 total_bytes++;
4579 byte_buffer_in_use = 0;
4582 /* Advance to offset of this element.
4583 Note no alignment needed in an array, since that is guaranteed
4584 if each element has the proper size. */
4585 if ((field != 0 || index != 0) && pos != total_bytes)
4587 assemble_zeros (pos - total_bytes);
4588 total_bytes = pos;
4591 /* Find the alignment of this element. */
4592 align2 = min_align (align, BITS_PER_UNIT * pos);
4594 /* Determine size this element should occupy. */
4595 if (field)
4597 fieldsize = 0;
4599 /* If this is an array with an unspecified upper bound,
4600 the initializer determines the size. */
4601 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4602 but we cannot do this until the deprecated support for
4603 initializing zero-length array members is removed. */
4604 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4605 && TYPE_DOMAIN (TREE_TYPE (field))
4606 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4608 fieldsize = array_size_for_constructor (val);
4609 /* Given a non-empty initialization, this field had
4610 better be last. */
4611 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4612 abort ();
4614 else if (DECL_SIZE_UNIT (field))
4616 /* ??? This can't be right. If the decl size overflows
4617 a host integer we will silently emit no data. */
4618 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4619 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4622 else
4623 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4625 /* Output the element's initial value. */
4626 if (val == 0)
4627 assemble_zeros (fieldsize);
4628 else
4629 output_constant (val, fieldsize, align2);
4631 /* Count its size. */
4632 total_bytes += fieldsize;
4634 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4635 error ("invalid initial value for member `%s'",
4636 IDENTIFIER_POINTER (DECL_NAME (field)));
4637 else
4639 /* Element that is a bit-field. */
4641 HOST_WIDE_INT next_offset = int_bit_position (field);
4642 HOST_WIDE_INT end_offset
4643 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4645 if (val == 0)
4646 val = integer_zero_node;
4648 /* If this field does not start in this (or, next) byte,
4649 skip some bytes. */
4650 if (next_offset / BITS_PER_UNIT != total_bytes)
4652 /* Output remnant of any bit field in previous bytes. */
4653 if (byte_buffer_in_use)
4655 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4656 total_bytes++;
4657 byte_buffer_in_use = 0;
4660 /* If still not at proper byte, advance to there. */
4661 if (next_offset / BITS_PER_UNIT != total_bytes)
4663 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4664 total_bytes = next_offset / BITS_PER_UNIT;
4668 if (! byte_buffer_in_use)
4669 byte = 0;
4671 /* We must split the element into pieces that fall within
4672 separate bytes, and combine each byte with previous or
4673 following bit-fields. */
4675 /* next_offset is the offset n fbits from the beginning of
4676 the structure to the next bit of this element to be processed.
4677 end_offset is the offset of the first bit past the end of
4678 this element. */
4679 while (next_offset < end_offset)
4681 int this_time;
4682 int shift;
4683 HOST_WIDE_INT value;
4684 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4685 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4687 /* Advance from byte to byte
4688 within this element when necessary. */
4689 while (next_byte != total_bytes)
4691 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4692 total_bytes++;
4693 byte = 0;
4696 /* Number of bits we can process at once
4697 (all part of the same byte). */
4698 this_time = MIN (end_offset - next_offset,
4699 BITS_PER_UNIT - next_bit);
4700 if (BYTES_BIG_ENDIAN)
4702 /* On big-endian machine, take the most significant bits
4703 first (of the bits that are significant)
4704 and put them into bytes from the most significant end. */
4705 shift = end_offset - next_offset - this_time;
4707 /* Don't try to take a bunch of bits that cross
4708 the word boundary in the INTEGER_CST. We can
4709 only select bits from the LOW or HIGH part
4710 not from both. */
4711 if (shift < HOST_BITS_PER_WIDE_INT
4712 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4714 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4715 shift = HOST_BITS_PER_WIDE_INT;
4718 /* Now get the bits from the appropriate constant word. */
4719 if (shift < HOST_BITS_PER_WIDE_INT)
4720 value = TREE_INT_CST_LOW (val);
4721 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4723 value = TREE_INT_CST_HIGH (val);
4724 shift -= HOST_BITS_PER_WIDE_INT;
4726 else
4727 abort ();
4729 /* Get the result. This works only when:
4730 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4731 byte |= (((value >> shift)
4732 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4733 << (BITS_PER_UNIT - this_time - next_bit));
4735 else
4737 /* On little-endian machines,
4738 take first the least significant bits of the value
4739 and pack them starting at the least significant
4740 bits of the bytes. */
4741 shift = next_offset - int_bit_position (field);
4743 /* Don't try to take a bunch of bits that cross
4744 the word boundary in the INTEGER_CST. We can
4745 only select bits from the LOW or HIGH part
4746 not from both. */
4747 if (shift < HOST_BITS_PER_WIDE_INT
4748 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4749 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4751 /* Now get the bits from the appropriate constant word. */
4752 if (shift < HOST_BITS_PER_WIDE_INT)
4753 value = TREE_INT_CST_LOW (val);
4754 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4756 value = TREE_INT_CST_HIGH (val);
4757 shift -= HOST_BITS_PER_WIDE_INT;
4759 else
4760 abort ();
4762 /* Get the result. This works only when:
4763 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4764 byte |= (((value >> shift)
4765 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4766 << next_bit);
4769 next_offset += this_time;
4770 byte_buffer_in_use = 1;
4775 if (byte_buffer_in_use)
4777 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4778 total_bytes++;
4781 if (total_bytes < size)
4782 assemble_zeros (size - total_bytes);
4785 /* This TREE_LIST contains any weak symbol declarations waiting
4786 to be emitted. */
4787 static tree weak_decls;
4789 /* Mark DECL as weak. */
4791 static void
4792 mark_weak (decl)
4793 tree decl;
4795 DECL_WEAK (decl) = 1;
4797 if (DECL_RTL_SET_P (decl)
4798 && GET_CODE (DECL_RTL (decl)) == MEM
4799 && XEXP (DECL_RTL (decl), 0)
4800 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4801 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4804 /* Merge weak status between NEWDECL and OLDDECL. */
4806 void
4807 merge_weak (newdecl, olddecl)
4808 tree newdecl;
4809 tree olddecl;
4811 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4812 return;
4814 if (DECL_WEAK (newdecl))
4816 tree wd;
4818 /* NEWDECL is weak, but OLDDECL is not. */
4820 /* If we already output the OLDDECL, we're in trouble; we can't
4821 go back and make it weak. This error cannot caught in
4822 declare_weak because the NEWDECL and OLDDECL was not yet
4823 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4824 if (TREE_ASM_WRITTEN (olddecl))
4825 error_with_decl (newdecl,
4826 "weak declaration of `%s' must precede definition");
4828 /* If we've already generated rtl referencing OLDDECL, we may
4829 have done so in a way that will not function properly with
4830 a weak symbol. */
4831 else if (TREE_USED (olddecl)
4832 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4833 warning_with_decl (newdecl, "weak declaration of `%s' after first use results in unspecified behavior");
4835 if (SUPPORTS_WEAK)
4837 /* We put the NEWDECL on the weak_decls list at some point.
4838 Replace it with the OLDDECL. */
4839 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4840 if (TREE_VALUE (wd) == newdecl)
4842 TREE_VALUE (wd) = olddecl;
4843 break;
4845 /* We may not find the entry on the list. If NEWDECL is a
4846 weak alias, then we will have already called
4847 globalize_decl to remove the entry; in that case, we do
4848 not need to do anything. */
4851 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4852 mark_weak (olddecl);
4854 else
4855 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4856 weak. Just update NEWDECL to indicate that it's weak too. */
4857 mark_weak (newdecl);
4860 /* Declare DECL to be a weak symbol. */
4862 void
4863 declare_weak (decl)
4864 tree decl;
4866 if (! TREE_PUBLIC (decl))
4867 error_with_decl (decl, "weak declaration of `%s' must be public");
4868 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4869 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4870 else if (SUPPORTS_WEAK)
4872 if (! DECL_WEAK (decl))
4873 weak_decls = tree_cons (NULL, decl, weak_decls);
4875 else
4876 warning_with_decl (decl, "weak declaration of `%s' not supported");
4878 mark_weak (decl);
4881 /* Emit any pending weak declarations. */
4883 void
4884 weak_finish ()
4886 tree t;
4888 for (t = weak_decls; t; t = TREE_CHAIN (t))
4890 tree decl = TREE_VALUE (t);
4891 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4893 if (! TREE_USED (decl))
4894 continue;
4896 #ifdef ASM_WEAKEN_DECL
4897 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4898 #else
4899 #ifdef ASM_WEAKEN_LABEL
4900 ASM_WEAKEN_LABEL (asm_out_file, name);
4901 #else
4902 #ifdef ASM_OUTPUT_WEAK_ALIAS
4903 warning ("only weak aliases are supported in this configuration");
4904 return;
4905 #endif
4906 #endif
4907 #endif
4911 /* Emit the assembly bits to indicate that DECL is globally visible. */
4913 static void
4914 globalize_decl (decl)
4915 tree decl;
4917 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4919 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4920 if (DECL_WEAK (decl))
4922 tree *p, t;
4924 #ifdef ASM_WEAKEN_DECL
4925 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4926 #else
4927 ASM_WEAKEN_LABEL (asm_out_file, name);
4928 #endif
4930 /* Remove this function from the pending weak list so that
4931 we do not emit multiple .weak directives for it. */
4932 for (p = &weak_decls; (t = *p) ; )
4934 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4935 *p = TREE_CHAIN (t);
4936 else
4937 p = &TREE_CHAIN (t);
4939 return;
4941 #endif
4943 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4946 /* Emit an assembler directive to make the symbol for DECL an alias to
4947 the symbol for TARGET. */
4949 void
4950 assemble_alias (decl, target)
4951 tree decl, target ATTRIBUTE_UNUSED;
4953 const char *name;
4955 /* We must force creation of DECL_RTL for debug info generation, even though
4956 we don't use it here. */
4957 make_decl_rtl (decl, NULL);
4959 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4961 #ifdef ASM_OUTPUT_DEF
4962 /* Make name accessible from other files, if appropriate. */
4964 if (TREE_PUBLIC (decl))
4966 globalize_decl (decl);
4967 maybe_assemble_visibility (decl);
4970 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4971 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4972 #else
4973 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4974 #endif
4975 #else /* !ASM_OUTPUT_DEF */
4976 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4977 if (! DECL_WEAK (decl))
4978 warning ("only weak aliases are supported in this configuration");
4980 #ifdef ASM_WEAKEN_DECL
4981 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4982 #else
4983 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4984 #endif
4985 #else
4986 warning ("alias definitions not supported in this configuration; ignored");
4987 #endif
4988 #endif
4990 TREE_USED (decl) = 1;
4991 TREE_ASM_WRITTEN (decl) = 1;
4992 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4995 /* Emit an assembler directive to set symbol for DECL visibility to
4996 VISIBILITY_TYPE. */
4998 void
4999 assemble_visibility (decl, visibility_type)
5000 tree decl;
5001 const char *visibility_type ATTRIBUTE_UNUSED;
5003 const char *name;
5005 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5007 #ifdef HAVE_GAS_HIDDEN
5008 fprintf (asm_out_file, "\t.%s\t%s\n", visibility_type, name);
5009 #else
5010 warning ("visibility attribute not supported in this configuration; ignored");
5011 #endif
5014 /* A helper function to call assemble_visibility when needed for a decl. */
5016 static void
5017 maybe_assemble_visibility (decl)
5018 tree decl;
5020 tree visibility = lookup_attribute ("visibility", DECL_ATTRIBUTES (decl));
5021 if (visibility)
5023 const char *type
5024 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility)));
5025 assemble_visibility (decl, type);
5029 /* Returns 1 if the target configuration supports defining public symbols
5030 so that one of them will be chosen at link time instead of generating a
5031 multiply-defined symbol error, whether through the use of weak symbols or
5032 a target-specific mechanism for having duplicates discarded. */
5035 supports_one_only ()
5037 if (SUPPORTS_ONE_ONLY)
5038 return 1;
5039 return SUPPORTS_WEAK;
5042 /* Set up DECL as a public symbol that can be defined in multiple
5043 translation units without generating a linker error. */
5045 void
5046 make_decl_one_only (decl)
5047 tree decl;
5049 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5050 abort ();
5052 TREE_PUBLIC (decl) = 1;
5054 if (TREE_CODE (decl) == VAR_DECL
5055 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5056 DECL_COMMON (decl) = 1;
5057 else if (SUPPORTS_ONE_ONLY)
5059 #ifdef MAKE_DECL_ONE_ONLY
5060 MAKE_DECL_ONE_ONLY (decl);
5061 #endif
5062 DECL_ONE_ONLY (decl) = 1;
5064 else if (SUPPORTS_WEAK)
5065 DECL_WEAK (decl) = 1;
5066 else
5067 abort ();
5070 void
5071 init_varasm_once ()
5073 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5074 const_str_htab_del);
5075 in_named_htab = htab_create (31, in_named_entry_hash,
5076 in_named_entry_eq, NULL);
5078 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5079 mark_const_hash_entry);
5080 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5081 mark_const_str_htab);
5082 ggc_add_tree_root (&weak_decls, 1);
5084 const_alias_set = new_alias_set ();
5087 /* Select a set of attributes for section NAME based on the properties
5088 of DECL and whether or not RELOC indicates that DECL's initializer
5089 might contain runtime relocations.
5091 We make the section read-only and executable for a function decl,
5092 read-only for a const data decl, and writable for a non-const data decl. */
5094 unsigned int
5095 default_section_type_flags (decl, name, reloc)
5096 tree decl;
5097 const char *name;
5098 int reloc;
5100 unsigned int flags;
5102 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5103 flags = SECTION_CODE;
5104 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5105 flags = 0;
5106 else
5107 flags = SECTION_WRITE;
5109 if (decl && DECL_ONE_ONLY (decl))
5110 flags |= SECTION_LINKONCE;
5112 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5113 flags |= SECTION_TLS | SECTION_WRITE;
5115 if (strcmp (name, ".bss") == 0
5116 || strncmp (name, ".bss.", 5) == 0
5117 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5118 || strcmp (name, ".sbss") == 0
5119 || strncmp (name, ".sbss.", 6) == 0
5120 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
5121 || strcmp (name, ".tbss") == 0
5122 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5123 flags |= SECTION_BSS;
5125 if (strcmp (name, ".tdata") == 0
5126 || strcmp (name, ".tbss") == 0
5127 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
5128 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
5129 flags |= SECTION_TLS;
5131 return flags;
5134 /* Output assembly to switch to section NAME with attribute FLAGS.
5135 Four variants for common object file formats. */
5137 void
5138 default_no_named_section (name, flags)
5139 const char *name ATTRIBUTE_UNUSED;
5140 unsigned int flags ATTRIBUTE_UNUSED;
5142 /* Some object formats don't support named sections at all. The
5143 front-end should already have flagged this as an error. */
5144 abort ();
5147 void
5148 default_elf_asm_named_section (name, flags)
5149 const char *name;
5150 unsigned int flags;
5152 char flagchars[10], *f = flagchars;
5153 const char *type;
5155 if (! named_section_first_declaration (name))
5157 fprintf (asm_out_file, "\t.section\t%s\n", name);
5158 return;
5161 if (!(flags & SECTION_DEBUG))
5162 *f++ = 'a';
5163 if (flags & SECTION_WRITE)
5164 *f++ = 'w';
5165 if (flags & SECTION_CODE)
5166 *f++ = 'x';
5167 if (flags & SECTION_SMALL)
5168 *f++ = 's';
5169 if (flags & SECTION_MERGE)
5170 *f++ = 'M';
5171 if (flags & SECTION_STRINGS)
5172 *f++ = 'S';
5173 if (flags & SECTION_TLS)
5174 *f++ = 'T';
5175 *f = '\0';
5177 if (flags & SECTION_BSS)
5178 type = "nobits";
5179 else
5180 type = "progbits";
5182 if (flags & SECTION_ENTSIZE)
5183 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5184 name, flagchars, type, flags & SECTION_ENTSIZE);
5185 else
5186 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5187 name, flagchars, type);
5190 void
5191 default_coff_asm_named_section (name, flags)
5192 const char *name;
5193 unsigned int flags;
5195 char flagchars[8], *f = flagchars;
5197 if (flags & SECTION_WRITE)
5198 *f++ = 'w';
5199 if (flags & SECTION_CODE)
5200 *f++ = 'x';
5201 *f = '\0';
5203 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5206 void
5207 default_pe_asm_named_section (name, flags)
5208 const char *name;
5209 unsigned int flags;
5211 default_coff_asm_named_section (name, flags);
5213 if (flags & SECTION_LINKONCE)
5215 /* Functions may have been compiled at various levels of
5216 optimization so we can't use `same_size' here.
5217 Instead, have the linker pick one. */
5218 fprintf (asm_out_file, "\t.linkonce %s\n",
5219 (flags & SECTION_CODE ? "discard" : "same_size"));
5223 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5224 from SYMBOL is used in all classes derived from SYMBOL. */
5226 void
5227 assemble_vtable_entry (symbol, offset)
5228 rtx symbol;
5229 HOST_WIDE_INT offset;
5231 fputs ("\t.vtable_entry ", asm_out_file);
5232 output_addr_const (asm_out_file, symbol);
5233 fputs (", ", asm_out_file);
5234 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5235 fputc ('\n', asm_out_file);
5238 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5239 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5241 void
5242 assemble_vtable_inherit (child, parent)
5243 rtx child, parent;
5245 fputs ("\t.vtable_inherit ", asm_out_file);
5246 output_addr_const (asm_out_file, child);
5247 fputs (", ", asm_out_file);
5248 output_addr_const (asm_out_file, parent);
5249 fputc ('\n', asm_out_file);
5252 /* The lame default section selector. */
5254 void
5255 default_select_section (decl, reloc, align)
5256 tree decl;
5257 int reloc;
5258 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
5260 bool readonly = false;
5262 if (DECL_P (decl))
5264 if (DECL_READONLY_SECTION (decl, reloc))
5265 readonly = true;
5267 else if (TREE_CODE (decl) == CONSTRUCTOR)
5269 if (! ((flag_pic && reloc)
5270 || !TREE_READONLY (decl)
5271 || TREE_SIDE_EFFECTS (decl)
5272 || !TREE_CONSTANT (decl)))
5273 readonly = true;
5275 else if (TREE_CODE (decl) == STRING_CST)
5276 readonly = !flag_writable_strings;
5277 else if (! (flag_pic && reloc))
5278 readonly = true;
5280 if (readonly)
5281 readonly_data_section ();
5282 else
5283 data_section ();
5286 /* A helper function for default_elf_select_section and
5287 default_elf_unique_section. Categorizes the DECL. */
5289 enum section_category
5291 SECCAT_TEXT,
5293 SECCAT_RODATA,
5294 SECCAT_RODATA_MERGE_STR,
5295 SECCAT_RODATA_MERGE_STR_INIT,
5296 SECCAT_RODATA_MERGE_CONST,
5298 SECCAT_DATA,
5300 /* To optimize loading of shared programs, define following subsections
5301 of data section:
5302 _REL Contains data that has relocations, so they get grouped
5303 together and dynamic linker will visit fewer pages in memory.
5304 _RO Contains data that is otherwise read-only. This is useful
5305 with prelinking as most relocations won't be dynamically
5306 linked and thus stay read only.
5307 _LOCAL Marks data containing relocations only to local objects.
5308 These relocations will get fully resolved by prelinking. */
5309 SECCAT_DATA_REL,
5310 SECCAT_DATA_REL_LOCAL,
5311 SECCAT_DATA_REL_RO,
5312 SECCAT_DATA_REL_RO_LOCAL,
5314 SECCAT_SDATA,
5315 SECCAT_TDATA,
5317 SECCAT_BSS,
5318 SECCAT_SBSS,
5319 SECCAT_TBSS
5322 static enum section_category categorize_decl_for_section PARAMS ((tree, int));
5324 static enum section_category
5325 categorize_decl_for_section (decl, reloc)
5326 tree decl;
5327 int reloc;
5329 enum section_category ret;
5331 if (TREE_CODE (decl) == FUNCTION_DECL)
5332 return SECCAT_TEXT;
5333 else if (TREE_CODE (decl) == STRING_CST)
5335 if (flag_writable_strings)
5336 return SECCAT_DATA;
5337 else
5338 return SECCAT_RODATA_MERGE_STR;
5340 else if (TREE_CODE (decl) == VAR_DECL)
5342 if (DECL_INITIAL (decl) == NULL
5343 || DECL_INITIAL (decl) == error_mark_node)
5344 ret = SECCAT_BSS;
5345 else if (! TREE_READONLY (decl)
5346 || TREE_SIDE_EFFECTS (decl)
5347 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
5349 if (flag_pic && (reloc & 2))
5350 ret = SECCAT_DATA_REL;
5351 else if (flag_pic && reloc)
5352 ret = SECCAT_DATA_REL_LOCAL;
5353 else
5354 ret = SECCAT_DATA;
5356 else if (flag_pic && (reloc & 2))
5357 ret = SECCAT_DATA_REL_RO;
5358 else if (flag_pic && reloc)
5359 ret = SECCAT_DATA_REL_RO_LOCAL;
5360 else if (flag_merge_constants < 2)
5361 /* C and C++ don't allow different variables to share the same
5362 location. -fmerge-all-constants allows even that (at the
5363 expense of not conforming). */
5364 ret = SECCAT_RODATA;
5365 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
5366 ret = SECCAT_RODATA_MERGE_STR_INIT;
5367 else
5368 ret = SECCAT_RODATA_MERGE_CONST;
5370 else if (TREE_CODE (decl) == CONSTRUCTOR)
5372 if ((flag_pic && reloc)
5373 || TREE_SIDE_EFFECTS (decl)
5374 || ! TREE_CONSTANT (decl))
5375 ret = SECCAT_DATA;
5376 else
5377 ret = SECCAT_RODATA;
5379 else
5380 ret = SECCAT_RODATA;
5382 /* There are no read-only thread-local sections. */
5383 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5385 if (ret == SECCAT_BSS)
5386 ret = SECCAT_TBSS;
5387 else
5388 ret = SECCAT_TDATA;
5391 /* If the target uses small data sections, select it. */
5392 else if ((*targetm.in_small_data_p) (decl))
5394 if (ret == SECCAT_BSS)
5395 ret = SECCAT_SBSS;
5396 else
5397 ret = SECCAT_SDATA;
5400 return ret;
5403 /* Select a section based on the above categorization. */
5405 void
5406 default_elf_select_section (decl, reloc, align)
5407 tree decl;
5408 int reloc;
5409 unsigned HOST_WIDE_INT align;
5411 switch (categorize_decl_for_section (decl, reloc))
5413 case SECCAT_TEXT:
5414 /* We're not supposed to be called on FUNCTION_DECLs. */
5415 abort ();
5416 case SECCAT_RODATA:
5417 readonly_data_section ();
5418 break;
5419 case SECCAT_RODATA_MERGE_STR:
5420 mergeable_string_section (decl, align, 0);
5421 break;
5422 case SECCAT_RODATA_MERGE_STR_INIT:
5423 mergeable_string_section (DECL_INITIAL (decl), align, 0);
5424 break;
5425 case SECCAT_RODATA_MERGE_CONST:
5426 mergeable_constant_section (DECL_MODE (decl), align, 0);
5427 break;
5428 case SECCAT_DATA:
5429 data_section ();
5430 break;
5431 case SECCAT_DATA_REL:
5432 named_section (NULL_TREE, ".data.rel", reloc);
5433 break;
5434 case SECCAT_DATA_REL_LOCAL:
5435 named_section (NULL_TREE, ".data.rel.local", reloc);
5436 break;
5437 case SECCAT_DATA_REL_RO:
5438 named_section (NULL_TREE, ".data.rel.ro", reloc);
5439 break;
5440 case SECCAT_DATA_REL_RO_LOCAL:
5441 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
5442 break;
5443 case SECCAT_SDATA:
5444 named_section (NULL_TREE, ".sdata", reloc);
5445 break;
5446 case SECCAT_TDATA:
5447 named_section (NULL_TREE, ".tdata", reloc);
5448 break;
5449 case SECCAT_BSS:
5450 #ifdef BSS_SECTION_ASM_OP
5451 bss_section ();
5452 #else
5453 named_section (NULL_TREE, ".bss", reloc);
5454 #endif
5455 break;
5456 case SECCAT_SBSS:
5457 named_section (NULL_TREE, ".sbss", reloc);
5458 break;
5459 case SECCAT_TBSS:
5460 named_section (NULL_TREE, ".tbss", reloc);
5461 break;
5462 default:
5463 abort ();
5467 /* Construct a unique section name based on the decl name and the
5468 categorization performed above. */
5470 void
5471 default_unique_section (decl, reloc)
5472 tree decl;
5473 int reloc;
5475 bool one_only = DECL_ONE_ONLY (decl);
5476 const char *prefix, *name;
5477 size_t nlen, plen;
5478 char *string;
5480 switch (categorize_decl_for_section (decl, reloc))
5482 case SECCAT_TEXT:
5483 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
5484 break;
5485 case SECCAT_RODATA:
5486 case SECCAT_RODATA_MERGE_STR:
5487 case SECCAT_RODATA_MERGE_STR_INIT:
5488 case SECCAT_RODATA_MERGE_CONST:
5489 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
5490 break;
5491 case SECCAT_DATA:
5492 case SECCAT_DATA_REL:
5493 case SECCAT_DATA_REL_LOCAL:
5494 case SECCAT_DATA_REL_RO:
5495 case SECCAT_DATA_REL_RO_LOCAL:
5496 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
5497 break;
5498 case SECCAT_SDATA:
5499 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5500 break;
5501 case SECCAT_BSS:
5502 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5503 break;
5504 case SECCAT_SBSS:
5505 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5506 break;
5507 case SECCAT_TDATA:
5508 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5509 break;
5510 case SECCAT_TBSS:
5511 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5512 break;
5513 default:
5514 abort ();
5516 plen = strlen (prefix);
5518 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5519 name = (* targetm.strip_name_encoding) (name);
5520 nlen = strlen (name);
5522 string = alloca (nlen + plen + 1);
5523 memcpy (string, prefix, plen);
5524 memcpy (string + plen, name, nlen + 1);
5526 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5529 void
5530 default_select_rtx_section (mode, x, align)
5531 enum machine_mode mode ATTRIBUTE_UNUSED;
5532 rtx x;
5533 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
5535 if (flag_pic)
5536 switch (GET_CODE (x))
5538 case CONST:
5539 case SYMBOL_REF:
5540 case LABEL_REF:
5541 data_section ();
5542 return;
5544 default:
5545 break;
5548 readonly_data_section ();
5551 void
5552 default_elf_select_rtx_section (mode, x, align)
5553 enum machine_mode mode;
5554 rtx x;
5555 unsigned HOST_WIDE_INT align;
5557 /* ??? Handle small data here somehow. */
5559 if (flag_pic)
5560 switch (GET_CODE (x))
5562 case CONST:
5563 case SYMBOL_REF:
5564 named_section (NULL_TREE, ".data.rel.ro", 3);
5565 return;
5567 case LABEL_REF:
5568 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5569 return;
5571 default:
5572 break;
5575 mergeable_constant_section (mode, align, 0);
5578 /* By default, we do nothing for encode_section_info, so we need not
5579 do anything but discard the '*' marker. */
5581 const char *
5582 default_strip_name_encoding (str)
5583 const char *str;
5585 return str + (*str == '*');
5588 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5589 wrt cross-module name binding. */
5591 bool
5592 default_binds_local_p (exp)
5593 tree exp;
5595 bool local_p;
5597 /* A non-decl is an entry in the constant pool. */
5598 if (!DECL_P (exp))
5599 local_p = true;
5600 /* Static variables are always local. */
5601 else if (! TREE_PUBLIC (exp))
5602 local_p = true;
5603 /* A variable is local if the user tells us so. */
5604 else if (MODULE_LOCAL_P (exp))
5605 local_p = true;
5606 /* Otherwise, variables defined outside this object may not be local. */
5607 else if (DECL_EXTERNAL (exp))
5608 local_p = false;
5609 /* Linkonce and weak data are never local. */
5610 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5611 local_p = false;
5612 /* If PIC, then assume that any global name can be overridden by
5613 symbols resolved from other modules. */
5614 else if (flag_pic)
5615 local_p = false;
5616 /* Uninitialized COMMON variable may be unified with symbols
5617 resolved from other modules. */
5618 else if (DECL_COMMON (exp)
5619 && (DECL_INITIAL (exp) == NULL
5620 || DECL_INITIAL (exp) == error_mark_node))
5621 local_p = false;
5622 /* Otherwise we're left with initialized (or non-common) global data
5623 which is of necessity defined locally. */
5624 else
5625 local_p = true;
5627 return local_p;