PR target/5828
[official-gcc.git] / gcc / varasm.c
blob5d41f638ab1f0250960cbc84ea054b0c580d24cf
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;
99 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
100 They are chained through the CONST_DOUBLE_CHAIN. */
101 rtx x_const_double_chain;
104 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
105 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
106 #define first_pool (cfun->varasm->x_first_pool)
107 #define last_pool (cfun->varasm->x_last_pool)
108 #define pool_offset (cfun->varasm->x_pool_offset)
109 #define const_double_chain (cfun->varasm->x_const_double_chain)
111 /* Number for making the label on the next
112 constant that is stored in memory. */
114 int const_labelno;
116 /* Number for making the label on the next
117 static variable internal to a function. */
119 int var_labelno;
121 /* Carry information from ASM_DECLARE_OBJECT_NAME
122 to ASM_FINISH_DECLARE_OBJECT. */
124 int size_directive_output;
126 /* The last decl for which assemble_variable was called,
127 if it did ASM_DECLARE_OBJECT_NAME.
128 If the last call to assemble_variable didn't do that,
129 this holds 0. */
131 tree last_assemble_variable_decl;
133 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
134 So giving constant the alias set for the type will allow such
135 initializations to appear to conflict with the load of the constant. We
136 avoid this by giving all constants an alias set for just constants.
137 Since there will be no stores to that alias set, nothing will ever
138 conflict with them. */
140 static HOST_WIDE_INT const_alias_set;
142 static const char *strip_reg_name PARAMS ((const char *));
143 static int contains_pointers_p PARAMS ((tree));
144 static void decode_addr_const PARAMS ((tree, struct addr_const *));
145 static int const_hash PARAMS ((tree));
146 static int compare_constant PARAMS ((tree,
147 struct constant_descriptor *));
148 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
149 static struct constant_descriptor *record_constant PARAMS ((tree));
150 static void record_constant_1 PARAMS ((tree));
151 static tree copy_constant PARAMS ((tree));
152 static void output_constant_def_contents PARAMS ((tree, int, int));
153 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
154 struct rtx_const *));
155 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
156 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
157 struct constant_descriptor *));
158 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
159 rtx));
160 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
161 static void mark_constant_pool PARAMS ((void));
162 static void mark_constants PARAMS ((rtx));
163 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
164 static int output_addressed_constants PARAMS ((tree));
165 static void output_after_function_constants PARAMS ((void));
166 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
167 static unsigned min_align PARAMS ((unsigned, unsigned));
168 static void output_constructor PARAMS ((tree, HOST_WIDE_INT,
169 unsigned int));
170 static void mark_weak_decls PARAMS ((void *));
171 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
172 static void remove_from_pending_weak_list PARAMS ((const char *));
173 #endif
174 static void globalize_decl PARAMS ((tree));
175 static void maybe_assemble_visibility PARAMS ((tree));
176 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
177 static hashval_t in_named_entry_hash PARAMS ((const PTR));
178 #ifdef ASM_OUTPUT_BSS
179 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
180 #endif
181 #ifdef BSS_SECTION_ASM_OP
182 #ifdef ASM_OUTPUT_ALIGNED_BSS
183 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
184 int, int));
185 #endif
186 #endif /* BSS_SECTION_ASM_OP */
187 static void mark_pool_constant PARAMS ((struct pool_constant *));
188 static void mark_const_hash_entry PARAMS ((void *));
189 static int mark_const_str_htab_1 PARAMS ((void **, void *));
190 static void mark_const_str_htab PARAMS ((void *));
191 static hashval_t const_str_htab_hash PARAMS ((const void *x));
192 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
193 static void const_str_htab_del PARAMS ((void *));
194 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
195 static void resolve_unique_section PARAMS ((tree, int));
197 static enum in_section { no_section, in_text, in_data, in_named
198 #ifdef BSS_SECTION_ASM_OP
199 , in_bss
200 #endif
201 #ifdef CTORS_SECTION_ASM_OP
202 , in_ctors
203 #endif
204 #ifdef DTORS_SECTION_ASM_OP
205 , in_dtors
206 #endif
207 #ifdef EXTRA_SECTIONS
208 , EXTRA_SECTIONS
209 #endif
210 } in_section = no_section;
212 /* Return a non-zero value if DECL has a section attribute. */
213 #ifndef IN_NAMED_SECTION
214 #define IN_NAMED_SECTION(DECL) \
215 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
216 && DECL_SECTION_NAME (DECL) != NULL_TREE)
217 #endif
219 /* Text of section name when in_section == in_named. */
220 static const char *in_named_name;
222 /* Hash table of flags that have been used for a particular named section. */
224 struct in_named_entry
226 const char *name;
227 unsigned int flags;
228 bool declared;
231 static htab_t in_named_htab;
233 /* Define functions like text_section for any extra sections. */
234 #ifdef EXTRA_SECTION_FUNCTIONS
235 EXTRA_SECTION_FUNCTIONS
236 #endif
238 /* Tell assembler to switch to text section. */
240 void
241 text_section ()
243 if (in_section != in_text)
245 #ifdef TEXT_SECTION
246 TEXT_SECTION ();
247 #else
248 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
249 #endif
250 in_section = in_text;
254 /* Tell assembler to switch to data section. */
256 void
257 data_section ()
259 if (in_section != in_data)
261 if (flag_shared_data)
263 #ifdef SHARED_SECTION_ASM_OP
264 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
265 #else
266 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
267 #endif
269 else
270 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
272 in_section = in_data;
275 /* Tell assembler to ALWAYS switch to data section, in case
276 it's not sure where it is. */
278 void
279 force_data_section ()
281 in_section = no_section;
282 data_section ();
285 /* Tell assembler to switch to read-only data section. This is normally
286 the text section. */
288 void
289 readonly_data_section ()
291 #ifdef READONLY_DATA_SECTION
292 READONLY_DATA_SECTION (); /* Note this can call data_section. */
293 #else
294 text_section ();
295 #endif
298 /* Determine if we're in the text section. */
301 in_text_section ()
303 return in_section == in_text;
306 /* Determine if we're in the data section. */
309 in_data_section ()
311 return in_section == in_data;
314 /* Helper routines for maintaining in_named_htab. */
316 static int
317 in_named_entry_eq (p1, p2)
318 const PTR p1;
319 const PTR p2;
321 const struct in_named_entry *old = p1;
322 const char *new = p2;
324 return strcmp (old->name, new) == 0;
327 static hashval_t
328 in_named_entry_hash (p)
329 const PTR p;
331 const struct in_named_entry *old = p;
332 return htab_hash_string (old->name);
335 /* If SECTION has been seen before as a named section, return the flags
336 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
337 set of flags for a section to have, so 0 does not mean that the section
338 has not been seen. */
340 unsigned int
341 get_named_section_flags (section)
342 const char *section;
344 struct in_named_entry **slot;
346 slot = (struct in_named_entry**)
347 htab_find_slot_with_hash (in_named_htab, section,
348 htab_hash_string (section), NO_INSERT);
350 return slot ? (*slot)->flags : 0;
353 /* Returns true if the section has been declared before. Sets internal
354 flag on this section in in_named_hash so subsequent calls on this
355 section will return false. */
357 bool
358 named_section_first_declaration (name)
359 const char *name;
361 struct in_named_entry **slot;
363 slot = (struct in_named_entry**)
364 htab_find_slot_with_hash (in_named_htab, name,
365 htab_hash_string (name), NO_INSERT);
366 if (! (*slot)->declared)
368 (*slot)->declared = true;
369 return true;
371 else
373 return false;
378 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
379 different set of flags, return false. */
381 bool
382 set_named_section_flags (section, flags)
383 const char *section;
384 unsigned int flags;
386 struct in_named_entry **slot, *entry;
388 slot = (struct in_named_entry**)
389 htab_find_slot_with_hash (in_named_htab, section,
390 htab_hash_string (section), INSERT);
391 entry = *slot;
393 if (!entry)
395 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
396 *slot = entry;
397 entry->name = ggc_strdup (section);
398 entry->flags = flags;
399 entry->declared = false;
401 else if (entry->flags != flags)
402 return false;
404 return true;
407 /* Tell assembler to change to section NAME with attributes FLAGS. */
409 void
410 named_section_flags (name, flags)
411 const char *name;
412 unsigned int flags;
414 if (in_section != in_named || strcmp (name, in_named_name) != 0)
416 if (! set_named_section_flags (name, flags))
417 abort ();
419 (* targetm.asm_out.named_section) (name, flags);
421 if (flags & SECTION_FORGET)
422 in_section = no_section;
423 else
425 in_named_name = ggc_strdup (name);
426 in_section = in_named;
431 /* Tell assembler to change to section NAME for DECL.
432 If DECL is NULL, just switch to section NAME.
433 If NAME is NULL, get the name from DECL.
434 If RELOC is 1, the initializer for DECL contains relocs. */
436 void
437 named_section (decl, name, reloc)
438 tree decl;
439 const char *name;
440 int reloc;
442 unsigned int flags;
444 if (decl != NULL_TREE && !DECL_P (decl))
445 abort ();
446 if (name == NULL)
447 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
449 flags = (* targetm.section_type_flags) (decl, name, reloc);
451 /* Sanity check user variables for flag changes. Non-user
452 section flag changes will abort in named_section_flags.
453 However, don't complain if SECTION_OVERRIDE is set.
454 We trust that the setter knows that it is safe to ignore
455 the default flags for this decl. */
456 if (decl && ! set_named_section_flags (name, flags))
458 flags = get_named_section_flags (name);
459 if ((flags & SECTION_OVERRIDE) == 0)
460 error_with_decl (decl, "%s causes a section type conflict");
463 named_section_flags (name, flags);
466 /* If required, set DECL_SECTION_NAME to a unique name. */
468 static void
469 resolve_unique_section (decl, reloc)
470 tree decl;
471 int reloc ATTRIBUTE_UNUSED;
473 if (DECL_SECTION_NAME (decl) == NULL_TREE
474 && (flag_function_sections
475 || (targetm.have_named_sections
476 && DECL_ONE_ONLY (decl))))
477 UNIQUE_SECTION (decl, reloc);
480 #ifdef BSS_SECTION_ASM_OP
482 /* Tell the assembler to switch to the bss section. */
484 void
485 bss_section ()
487 if (in_section != in_bss)
489 #ifdef SHARED_BSS_SECTION_ASM_OP
490 if (flag_shared_data)
491 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
492 else
493 #endif
494 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
496 in_section = in_bss;
500 #ifdef ASM_OUTPUT_BSS
502 /* Utility function for ASM_OUTPUT_BSS for targets to use if
503 they don't support alignments in .bss.
504 ??? It is believed that this function will work in most cases so such
505 support is localized here. */
507 static void
508 asm_output_bss (file, decl, name, size, rounded)
509 FILE *file;
510 tree decl ATTRIBUTE_UNUSED;
511 const char *name;
512 int size ATTRIBUTE_UNUSED, rounded;
514 ASM_GLOBALIZE_LABEL (file, name);
515 bss_section ();
516 #ifdef ASM_DECLARE_OBJECT_NAME
517 last_assemble_variable_decl = decl;
518 ASM_DECLARE_OBJECT_NAME (file, name, decl);
519 #else
520 /* Standard thing is just output label for the object. */
521 ASM_OUTPUT_LABEL (file, name);
522 #endif /* ASM_DECLARE_OBJECT_NAME */
523 ASM_OUTPUT_SKIP (file, rounded);
526 #endif
528 #ifdef ASM_OUTPUT_ALIGNED_BSS
530 /* Utility function for targets to use in implementing
531 ASM_OUTPUT_ALIGNED_BSS.
532 ??? It is believed that this function will work in most cases so such
533 support is localized here. */
535 static void
536 asm_output_aligned_bss (file, decl, name, size, align)
537 FILE *file;
538 tree decl ATTRIBUTE_UNUSED;
539 const char *name;
540 int size, align;
542 ASM_GLOBALIZE_LABEL (file, name);
543 bss_section ();
544 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
545 #ifdef ASM_DECLARE_OBJECT_NAME
546 last_assemble_variable_decl = decl;
547 ASM_DECLARE_OBJECT_NAME (file, name, decl);
548 #else
549 /* Standard thing is just output label for the object. */
550 ASM_OUTPUT_LABEL (file, name);
551 #endif /* ASM_DECLARE_OBJECT_NAME */
552 ASM_OUTPUT_SKIP (file, size ? size : 1);
555 #endif
557 #endif /* BSS_SECTION_ASM_OP */
559 /* Switch to the section for function DECL.
561 If DECL is NULL_TREE, switch to the text section.
562 ??? It's not clear that we will ever be passed NULL_TREE, but it's
563 safer to handle it. */
565 void
566 function_section (decl)
567 tree decl;
569 if (decl != NULL_TREE
570 && DECL_SECTION_NAME (decl) != NULL_TREE)
571 named_section (decl, (char *) 0, 0);
572 else
573 text_section ();
576 /* Switch to section for variable DECL.
578 RELOC is the `reloc' argument to SELECT_SECTION. */
580 void
581 variable_section (decl, reloc)
582 tree decl;
583 int reloc;
585 if (IN_NAMED_SECTION (decl))
586 named_section (decl, NULL, reloc);
587 else
589 /* C++ can have const variables that get initialized from constructors,
590 and thus can not be in a readonly section. We prevent this by
591 verifying that the initial value is constant for objects put in a
592 readonly section.
594 error_mark_node is used by the C front end to indicate that the
595 initializer has not been seen yet. In this case, we assume that
596 the initializer must be constant.
598 C++ uses error_mark_node for variables that have complicated
599 initializers, but these variables go in BSS so we won't be called
600 for them. */
602 #ifdef SELECT_SECTION
603 SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
604 #else
605 if (DECL_READONLY_SECTION (decl, reloc))
606 readonly_data_section ();
607 else
608 data_section ();
609 #endif
613 /* Tell assembler to switch to the section for the exception handling
614 table. */
616 void
617 default_exception_section ()
619 if (targetm.have_named_sections)
620 named_section (NULL_TREE, ".gcc_except_table", 0);
621 else if (flag_pic)
622 data_section ();
623 else
624 readonly_data_section ();
627 /* Tell assembler to switch to the section for string merging. */
629 void
630 mergeable_string_section (decl, align, flags)
631 tree decl ATTRIBUTE_UNUSED;
632 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
633 unsigned int flags ATTRIBUTE_UNUSED;
635 #ifdef HAVE_GAS_SHF_MERGE
636 if (flag_merge_constants
637 && TREE_CODE (decl) == STRING_CST
638 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
639 && align <= 256
640 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
642 enum machine_mode mode;
643 unsigned int modesize;
644 const char *str;
645 int i, j, len, unit;
646 char name[30];
648 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
649 modesize = GET_MODE_BITSIZE (mode);
650 if (modesize >= 8 && modesize <= 256
651 && (modesize & (modesize - 1)) == 0)
653 if (align < modesize)
654 align = modesize;
656 str = TREE_STRING_POINTER (decl);
657 len = TREE_STRING_LENGTH (decl);
658 unit = GET_MODE_SIZE (mode);
660 /* Check for embedded NUL characters. */
661 for (i = 0; i < len; i += unit)
663 for (j = 0; j < unit; j++)
664 if (str [i + j] != '\0')
665 break;
666 if (j == unit)
667 break;
669 if (i == len - unit)
671 sprintf (name, ".rodata.str%d.%d", modesize / 8,
672 (int) (align / 8));
673 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
674 if (!i && modesize < align)
676 /* A "" string with requested alignment greater than
677 character size might cause a problem:
678 if some other string required even bigger
679 alignment than "", then linker might think the
680 "" is just part of padding after some other string
681 and not put it into the hash table initially.
682 But this means "" could have smaller alignment
683 than requested. */
684 #ifdef ASM_OUTPUT_SECTION_START
685 named_section_flags (name, flags);
686 ASM_OUTPUT_SECTION_START (asm_out_file);
687 #else
688 readonly_data_section ();
689 #endif
690 return;
693 named_section_flags (name, flags);
694 return;
698 #endif
699 readonly_data_section ();
702 /* Tell assembler to switch to the section for constant merging. */
704 void
705 mergeable_constant_section (mode, align, flags)
706 enum machine_mode mode ATTRIBUTE_UNUSED;
707 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
708 unsigned int flags ATTRIBUTE_UNUSED;
710 #ifdef HAVE_GAS_SHF_MERGE
711 unsigned int modesize = GET_MODE_BITSIZE (mode);
713 if (flag_merge_constants
714 && mode != VOIDmode
715 && mode != BLKmode
716 && modesize <= align
717 && align >= 8
718 && align <= 256
719 && (align & (align - 1)) == 0)
721 char name[24];
723 sprintf (name, ".rodata.cst%d", (int) (align / 8));
724 flags |= (align / 8) | SECTION_MERGE;
725 named_section_flags (name, flags);
726 return;
728 #endif
729 readonly_data_section ();
732 /* Given NAME, a putative register name, discard any customary prefixes. */
734 static const char *
735 strip_reg_name (name)
736 const char *name;
738 #ifdef REGISTER_PREFIX
739 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
740 name += strlen (REGISTER_PREFIX);
741 #endif
742 if (name[0] == '%' || name[0] == '#')
743 name++;
744 return name;
747 /* Decode an `asm' spec for a declaration as a register name.
748 Return the register number, or -1 if nothing specified,
749 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
750 or -3 if ASMSPEC is `cc' and is not recognized,
751 or -4 if ASMSPEC is `memory' and is not recognized.
752 Accept an exact spelling or a decimal number.
753 Prefixes such as % are optional. */
756 decode_reg_name (asmspec)
757 const char *asmspec;
759 if (asmspec != 0)
761 int i;
763 /* Get rid of confusing prefixes. */
764 asmspec = strip_reg_name (asmspec);
766 /* Allow a decimal number as a "register name". */
767 for (i = strlen (asmspec) - 1; i >= 0; i--)
768 if (! ISDIGIT (asmspec[i]))
769 break;
770 if (asmspec[0] != 0 && i < 0)
772 i = atoi (asmspec);
773 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
774 return i;
775 else
776 return -2;
779 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
780 if (reg_names[i][0]
781 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
782 return i;
784 #ifdef ADDITIONAL_REGISTER_NAMES
786 static const struct { const char *const name; const int number; } table[]
787 = ADDITIONAL_REGISTER_NAMES;
789 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
790 if (! strcmp (asmspec, table[i].name))
791 return table[i].number;
793 #endif /* ADDITIONAL_REGISTER_NAMES */
795 if (!strcmp (asmspec, "memory"))
796 return -4;
798 if (!strcmp (asmspec, "cc"))
799 return -3;
801 return -2;
804 return -1;
807 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
808 have static storage duration. In other words, it should not be an
809 automatic variable, including PARM_DECLs.
811 There is, however, one exception: this function handles variables
812 explicitly placed in a particular register by the user.
814 ASMSPEC, if not 0, is the string which the user specified as the
815 assembler symbol name.
817 This is never called for PARM_DECL nodes. */
819 void
820 make_decl_rtl (decl, asmspec)
821 tree decl;
822 const char *asmspec;
824 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
825 const char *name = 0;
826 const char *new_name = 0;
827 int reg_number;
828 rtx x;
830 /* Check that we are not being given an automatic variable. */
831 /* A weak alias has TREE_PUBLIC set but not the other bits. */
832 if (TREE_CODE (decl) == PARM_DECL
833 || TREE_CODE (decl) == RESULT_DECL
834 || (TREE_CODE (decl) == VAR_DECL
835 && !TREE_STATIC (decl)
836 && !TREE_PUBLIC (decl)
837 && !DECL_EXTERNAL (decl)
838 && !DECL_REGISTER (decl)))
839 abort ();
840 /* And that we were not given a type or a label. */
841 else if (TREE_CODE (decl) == TYPE_DECL
842 || TREE_CODE (decl) == LABEL_DECL)
843 abort ();
845 /* For a duplicate declaration, we can be called twice on the
846 same DECL node. Don't discard the RTL already made. */
847 if (DECL_RTL_SET_P (decl))
849 /* If the old RTL had the wrong mode, fix the mode. */
850 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
851 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
852 DECL_MODE (decl), 0));
854 /* ??? Another way to do this would be to do what halfpic.c does
855 and maintain a hashed table of such critters. */
856 /* Let the target reassign the RTL if it wants.
857 This is necessary, for example, when one machine specific
858 decl attribute overrides another. */
859 #ifdef ENCODE_SECTION_INFO
860 ENCODE_SECTION_INFO (decl, false);
861 #endif
862 return;
865 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
867 reg_number = decode_reg_name (asmspec);
868 if (reg_number == -2)
870 /* ASMSPEC is given, and not the name of a register. Mark the
871 name with a star so assemble_name won't munge it. */
872 char *starred = alloca (strlen (asmspec) + 2);
873 starred[0] = '*';
874 strcpy (starred + 1, asmspec);
875 new_name = starred;
878 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
880 /* First detect errors in declaring global registers. */
881 if (reg_number == -1)
882 error_with_decl (decl, "register name not specified for `%s'");
883 else if (reg_number < 0)
884 error_with_decl (decl, "invalid register name for `%s'");
885 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
886 error_with_decl (decl,
887 "data type of `%s' isn't suitable for a register");
888 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
889 error_with_decl (decl,
890 "register specified for `%s' isn't suitable for data type");
891 /* Now handle properly declared static register variables. */
892 else
894 int nregs;
896 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
898 DECL_INITIAL (decl) = 0;
899 error ("global register variable has initial value");
901 if (TREE_THIS_VOLATILE (decl))
902 warning ("volatile register variables don't work as you might wish");
904 /* If the user specified one of the eliminables registers here,
905 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
906 confused with that register and be eliminated. This usage is
907 somewhat suspect... */
909 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
910 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
911 REG_USERVAR_P (DECL_RTL (decl)) = 1;
913 if (TREE_STATIC (decl))
915 /* Make this register global, so not usable for anything
916 else. */
917 #ifdef ASM_DECLARE_REGISTER_GLOBAL
918 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
919 #endif
920 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
921 while (nregs > 0)
922 globalize_reg (reg_number + --nregs);
925 /* As a register variable, it has no section. */
926 return;
930 /* Now handle ordinary static variables and functions (in memory).
931 Also handle vars declared register invalidly. */
933 if (reg_number >= 0 || reg_number == -3)
934 error_with_decl (decl,
935 "register name given for non-register variable `%s'");
937 /* Specifying a section attribute on a variable forces it into a
938 non-.bss section, and thus it cannot be common. */
939 if (TREE_CODE (decl) == VAR_DECL
940 && DECL_SECTION_NAME (decl) != NULL_TREE
941 && DECL_INITIAL (decl) == NULL_TREE
942 && DECL_COMMON (decl))
943 DECL_COMMON (decl) = 0;
945 /* Can't use just the variable's own name for a variable
946 whose scope is less than the whole file, unless it's a member
947 of a local class (which will already be unambiguous).
948 Concatenate a distinguishing number. */
949 if (!top_level && !TREE_PUBLIC (decl)
950 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
951 && asmspec == 0
952 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
954 char *label;
956 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
957 var_labelno++;
958 new_name = label;
961 if (name != new_name)
963 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
964 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
967 /* If this variable is to be treated as volatile, show its
968 tree node has side effects. */
969 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
970 && TREE_PUBLIC (decl))
971 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
972 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
973 TREE_SIDE_EFFECTS (decl) = 1;
975 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
976 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
977 if (TREE_CODE (decl) != FUNCTION_DECL)
978 set_mem_attributes (x, decl, 1);
979 SET_DECL_RTL (decl, x);
981 /* Optionally set flags or add text to the name to record information
982 such as that it is a function name.
983 If the name is changed, the macro ASM_OUTPUT_LABELREF
984 will have to know how to strip this information. */
985 #ifdef ENCODE_SECTION_INFO
986 ENCODE_SECTION_INFO (decl, true);
987 #endif
990 /* Make the rtl for variable VAR be volatile.
991 Use this only for static variables. */
993 void
994 make_var_volatile (var)
995 tree var;
997 if (GET_CODE (DECL_RTL (var)) != MEM)
998 abort ();
1000 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1003 /* Output alignment directive to align for constant expression EXP. */
1005 void
1006 assemble_constant_align (exp)
1007 tree exp;
1009 int align;
1011 /* Align the location counter as required by EXP's data type. */
1012 align = TYPE_ALIGN (TREE_TYPE (exp));
1013 #ifdef CONSTANT_ALIGNMENT
1014 align = CONSTANT_ALIGNMENT (exp, align);
1015 #endif
1017 if (align > BITS_PER_UNIT)
1019 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1023 /* Output a string of literal assembler code
1024 for an `asm' keyword used between functions. */
1026 void
1027 assemble_asm (string)
1028 tree string;
1030 app_enable ();
1032 if (TREE_CODE (string) == ADDR_EXPR)
1033 string = TREE_OPERAND (string, 0);
1035 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1038 /* Record an element in the table of global destructors. SYMBOL is
1039 a SYMBOL_REF of the function to be called; PRIORITY is a number
1040 between 0 and MAX_INIT_PRIORITY. */
1042 void
1043 default_stabs_asm_out_destructor (symbol, priority)
1044 rtx symbol;
1045 int priority ATTRIBUTE_UNUSED;
1047 /* Tell GNU LD that this is part of the static destructor set.
1048 This will work for any system that uses stabs, most usefully
1049 aout systems. */
1050 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1051 assemble_name (asm_out_file, XSTR (symbol, 0));
1052 fputc ('\n', asm_out_file);
1055 void
1056 default_named_section_asm_out_destructor (symbol, priority)
1057 rtx symbol;
1058 int priority;
1060 const char *section = ".dtors";
1061 char buf[16];
1063 /* ??? This only works reliably with the GNU linker. */
1064 if (priority != DEFAULT_INIT_PRIORITY)
1066 sprintf (buf, ".dtors.%.5u",
1067 /* Invert the numbering so the linker puts us in the proper
1068 order; constructors are run from right to left, and the
1069 linker sorts in increasing order. */
1070 MAX_INIT_PRIORITY - priority);
1071 section = buf;
1074 named_section_flags (section, SECTION_WRITE);
1075 assemble_align (POINTER_SIZE);
1076 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1079 #ifdef DTORS_SECTION_ASM_OP
1080 void
1081 dtors_section ()
1083 if (in_section != in_dtors)
1085 in_section = in_dtors;
1086 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1087 fputc ('\n', asm_out_file);
1091 void
1092 default_dtor_section_asm_out_destructor (symbol, priority)
1093 rtx symbol;
1094 int priority ATTRIBUTE_UNUSED;
1096 dtors_section ();
1097 assemble_align (POINTER_SIZE);
1098 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1100 #endif
1102 /* Likewise for global constructors. */
1104 void
1105 default_stabs_asm_out_constructor (symbol, priority)
1106 rtx symbol;
1107 int priority ATTRIBUTE_UNUSED;
1109 /* Tell GNU LD that this is part of the static destructor set.
1110 This will work for any system that uses stabs, most usefully
1111 aout systems. */
1112 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1113 assemble_name (asm_out_file, XSTR (symbol, 0));
1114 fputc ('\n', asm_out_file);
1117 void
1118 default_named_section_asm_out_constructor (symbol, priority)
1119 rtx symbol;
1120 int priority;
1122 const char *section = ".ctors";
1123 char buf[16];
1125 /* ??? This only works reliably with the GNU linker. */
1126 if (priority != DEFAULT_INIT_PRIORITY)
1128 sprintf (buf, ".ctors.%.5u",
1129 /* Invert the numbering so the linker puts us in the proper
1130 order; constructors are run from right to left, and the
1131 linker sorts in increasing order. */
1132 MAX_INIT_PRIORITY - priority);
1133 section = buf;
1136 named_section_flags (section, SECTION_WRITE);
1137 assemble_align (POINTER_SIZE);
1138 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1141 #ifdef CTORS_SECTION_ASM_OP
1142 void
1143 ctors_section ()
1145 if (in_section != in_ctors)
1147 in_section = in_ctors;
1148 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1149 fputc ('\n', asm_out_file);
1153 void
1154 default_ctor_section_asm_out_constructor (symbol, priority)
1155 rtx symbol;
1156 int priority ATTRIBUTE_UNUSED;
1158 ctors_section ();
1159 assemble_align (POINTER_SIZE);
1160 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1162 #endif
1164 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1165 a non-zero value if the constant pool should be output before the
1166 start of the function, or a zero value if the pool should output
1167 after the end of the function. The default is to put it before the
1168 start. */
1170 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1171 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1172 #endif
1174 /* Output assembler code for the constant pool of a function and associated
1175 with defining the name of the function. DECL describes the function.
1176 NAME is the function's name. For the constant pool, we use the current
1177 constant pool data. */
1179 void
1180 assemble_start_function (decl, fnname)
1181 tree decl;
1182 const char *fnname;
1184 int align;
1186 /* The following code does not need preprocessing in the assembler. */
1188 app_disable ();
1190 if (CONSTANT_POOL_BEFORE_FUNCTION)
1191 output_constant_pool (fnname, decl);
1193 resolve_unique_section (decl, 0);
1194 function_section (decl);
1196 /* Tell assembler to move to target machine's alignment for functions. */
1197 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1198 if (align > 0)
1200 ASM_OUTPUT_ALIGN (asm_out_file, align);
1203 /* Handle a user-specified function alignment.
1204 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1205 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1206 if (align_functions_log > align)
1208 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1209 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1210 align_functions_log, align_functions-1);
1211 #else
1212 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1213 #endif
1216 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1217 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1218 #endif
1220 (*debug_hooks->begin_function) (decl);
1222 /* Make function name accessible from other files, if appropriate. */
1224 if (TREE_PUBLIC (decl))
1226 if (! first_global_object_name)
1228 const char *p;
1229 char *name;
1231 STRIP_NAME_ENCODING (p, fnname);
1232 name = permalloc (strlen (p) + 1);
1233 strcpy (name, p);
1235 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1236 first_global_object_name = name;
1237 else
1238 weak_global_object_name = name;
1241 globalize_decl (decl);
1243 maybe_assemble_visibility (decl);
1246 /* Do any machine/system dependent processing of the function name */
1247 #ifdef ASM_DECLARE_FUNCTION_NAME
1248 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1249 #else
1250 /* Standard thing is just output label for the function. */
1251 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1252 #endif /* ASM_DECLARE_FUNCTION_NAME */
1255 /* Output assembler code associated with defining the size of the
1256 function. DECL describes the function. NAME is the function's name. */
1258 void
1259 assemble_end_function (decl, fnname)
1260 tree decl;
1261 const char *fnname;
1263 #ifdef ASM_DECLARE_FUNCTION_SIZE
1264 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1265 #endif
1266 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1268 output_constant_pool (fnname, decl);
1269 function_section (decl); /* need to switch back */
1272 /* Output any constants which should appear after the function. */
1273 output_after_function_constants ();
1276 /* Assemble code to leave SIZE bytes of zeros. */
1278 void
1279 assemble_zeros (size)
1280 int size;
1282 /* Do no output if -fsyntax-only. */
1283 if (flag_syntax_only)
1284 return;
1286 #ifdef ASM_NO_SKIP_IN_TEXT
1287 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1288 so we must output 0s explicitly in the text section. */
1289 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1291 int i;
1292 for (i = 0; i < size; i++)
1293 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1295 else
1296 #endif
1297 if (size > 0)
1298 ASM_OUTPUT_SKIP (asm_out_file, size);
1301 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1303 void
1304 assemble_align (align)
1305 int align;
1307 if (align > BITS_PER_UNIT)
1309 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1313 /* Assemble a string constant with the specified C string as contents. */
1315 void
1316 assemble_string (p, size)
1317 const char *p;
1318 int size;
1320 int pos = 0;
1321 int maximum = 2000;
1323 /* If the string is very long, split it up. */
1325 while (pos < size)
1327 int thissize = size - pos;
1328 if (thissize > maximum)
1329 thissize = maximum;
1331 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1333 pos += thissize;
1334 p += thissize;
1339 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1340 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1341 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1342 #else
1343 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1344 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1345 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1346 #else
1347 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1348 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1349 #endif
1350 #endif
1352 #if defined ASM_OUTPUT_ALIGNED_BSS
1353 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1354 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1355 #else
1356 #if defined ASM_OUTPUT_BSS
1357 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1358 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1359 #else
1360 #undef ASM_EMIT_BSS
1361 #endif
1362 #endif
1364 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1365 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1366 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1367 #else
1368 #if defined ASM_OUTPUT_ALIGNED_COMMON
1369 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1370 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1371 #else
1372 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1373 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1374 #endif
1375 #endif
1377 static void
1378 asm_emit_uninitialised (decl, name, size, rounded)
1379 tree decl;
1380 const char * name;
1381 int size ATTRIBUTE_UNUSED;
1382 int rounded ATTRIBUTE_UNUSED;
1384 enum
1386 asm_dest_common,
1387 asm_dest_bss,
1388 asm_dest_local
1390 destination = asm_dest_local;
1392 if (TREE_PUBLIC (decl))
1394 #if defined ASM_EMIT_BSS
1395 if (! DECL_COMMON (decl))
1396 destination = asm_dest_bss;
1397 else
1398 #endif
1399 destination = asm_dest_common;
1402 if (flag_shared_data)
1404 switch (destination)
1406 #ifdef ASM_OUTPUT_SHARED_BSS
1407 case asm_dest_bss:
1408 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1409 return;
1410 #endif
1411 #ifdef ASM_OUTPUT_SHARED_COMMON
1412 case asm_dest_common:
1413 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1414 return;
1415 #endif
1416 #ifdef ASM_OUTPUT_SHARED_LOCAL
1417 case asm_dest_local:
1418 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1419 return;
1420 #endif
1421 default:
1422 break;
1426 resolve_unique_section (decl, 0);
1428 switch (destination)
1430 #ifdef ASM_EMIT_BSS
1431 case asm_dest_bss:
1432 globalize_decl (decl);
1433 ASM_EMIT_BSS (decl, name, size, rounded);
1434 break;
1435 #endif
1436 case asm_dest_common:
1437 ASM_EMIT_COMMON (decl, name, size, rounded);
1438 break;
1439 case asm_dest_local:
1440 ASM_EMIT_LOCAL (decl, name, size, rounded);
1441 break;
1442 default:
1443 abort ();
1446 return;
1449 /* Assemble everything that is needed for a variable or function declaration.
1450 Not used for automatic variables, and not used for function definitions.
1451 Should not be called for variables of incomplete structure type.
1453 TOP_LEVEL is nonzero if this variable has file scope.
1454 AT_END is nonzero if this is the special handling, at end of compilation,
1455 to define things that have had only tentative definitions.
1456 DONT_OUTPUT_DATA if nonzero means don't actually output the
1457 initial value (that will be done by the caller). */
1459 void
1460 assemble_variable (decl, top_level, at_end, dont_output_data)
1461 tree decl;
1462 int top_level ATTRIBUTE_UNUSED;
1463 int at_end ATTRIBUTE_UNUSED;
1464 int dont_output_data;
1466 const char *name;
1467 unsigned int align;
1468 int reloc = 0;
1469 rtx decl_rtl;
1471 last_assemble_variable_decl = 0;
1473 /* Normally no need to say anything here for external references,
1474 since assemble_external is called by the language-specific code
1475 when a declaration is first seen. */
1477 if (DECL_EXTERNAL (decl))
1478 return;
1480 /* Output no assembler code for a function declaration.
1481 Only definitions of functions output anything. */
1483 if (TREE_CODE (decl) == FUNCTION_DECL)
1484 return;
1486 /* Do nothing for global register variables. */
1487 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1489 TREE_ASM_WRITTEN (decl) = 1;
1490 return;
1493 /* If type was incomplete when the variable was declared,
1494 see if it is complete now. */
1496 if (DECL_SIZE (decl) == 0)
1497 layout_decl (decl, 0);
1499 /* Still incomplete => don't allocate it; treat the tentative defn
1500 (which is what it must have been) as an `extern' reference. */
1502 if (!dont_output_data && DECL_SIZE (decl) == 0)
1504 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1505 DECL_SOURCE_LINE (decl),
1506 "storage size of `%s' isn't known",
1507 IDENTIFIER_POINTER (DECL_NAME (decl)));
1508 TREE_ASM_WRITTEN (decl) = 1;
1509 return;
1512 /* The first declaration of a variable that comes through this function
1513 decides whether it is global (in C, has external linkage)
1514 or local (in C, has internal linkage). So do nothing more
1515 if this function has already run. */
1517 if (TREE_ASM_WRITTEN (decl))
1518 return;
1520 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1521 decl_rtl = DECL_RTL (decl);
1523 TREE_ASM_WRITTEN (decl) = 1;
1525 /* Do no output if -fsyntax-only. */
1526 if (flag_syntax_only)
1527 return;
1529 app_disable ();
1531 if (! dont_output_data
1532 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1534 error_with_decl (decl, "size of variable `%s' is too large");
1535 return;
1538 name = XSTR (XEXP (decl_rtl, 0), 0);
1539 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1540 && ! first_global_object_name
1541 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1542 || DECL_INITIAL (decl) == error_mark_node))
1543 && ! DECL_WEAK (decl)
1544 && ! DECL_ONE_ONLY (decl))
1546 const char *p;
1547 char *xname;
1549 STRIP_NAME_ENCODING (p, name);
1550 xname = permalloc (strlen (p) + 1);
1551 strcpy (xname, p);
1552 first_global_object_name = xname;
1555 /* Compute the alignment of this data. */
1557 align = DECL_ALIGN (decl);
1559 /* In the case for initialing an array whose length isn't specified,
1560 where we have not yet been able to do the layout,
1561 figure out the proper alignment now. */
1562 if (dont_output_data && DECL_SIZE (decl) == 0
1563 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1564 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1566 /* Some object file formats have a maximum alignment which they support.
1567 In particular, a.out format supports a maximum alignment of 4. */
1568 #ifndef MAX_OFILE_ALIGNMENT
1569 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1570 #endif
1571 if (align > MAX_OFILE_ALIGNMENT)
1573 warning_with_decl (decl,
1574 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1575 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1576 align = MAX_OFILE_ALIGNMENT;
1579 /* On some machines, it is good to increase alignment sometimes. */
1580 if (! DECL_USER_ALIGN (decl))
1582 #ifdef DATA_ALIGNMENT
1583 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1584 #endif
1585 #ifdef CONSTANT_ALIGNMENT
1586 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1587 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1588 #endif
1591 /* Reset the alignment in case we have made it tighter, so we can benefit
1592 from it in get_pointer_alignment. */
1593 DECL_ALIGN (decl) = align;
1594 set_mem_align (decl_rtl, align);
1596 if (TREE_PUBLIC (decl))
1597 maybe_assemble_visibility (decl);
1599 /* Handle uninitialized definitions. */
1601 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node
1602 #if defined ASM_EMIT_BSS
1603 || (flag_zero_initialized_in_bss
1604 && initializer_zerop (DECL_INITIAL (decl)))
1605 #endif
1607 /* If the target can't output uninitialized but not common global data
1608 in .bss, then we have to use .data. */
1609 #if ! defined ASM_EMIT_BSS
1610 && DECL_COMMON (decl)
1611 #endif
1612 && DECL_SECTION_NAME (decl) == NULL_TREE
1613 && ! dont_output_data)
1615 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1616 unsigned HOST_WIDE_INT rounded = size;
1618 /* Don't allocate zero bytes of common,
1619 since that means "undefined external" in the linker. */
1620 if (size == 0)
1621 rounded = 1;
1623 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1624 so that each uninitialized object starts on such a boundary. */
1625 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1626 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1627 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1629 /* Don't continue this line--convex cc version 4.1 would lose. */
1630 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1631 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1632 warning_with_decl
1633 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1634 #endif
1636 asm_emit_uninitialised (decl, name, size, rounded);
1638 return;
1641 /* Handle initialized definitions.
1642 Also handle uninitialized global definitions if -fno-common and the
1643 target doesn't support ASM_OUTPUT_BSS. */
1645 /* First make the assembler name(s) global if appropriate. */
1646 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1647 globalize_decl (decl);
1649 /* Output any data that we will need to use the address of. */
1650 if (DECL_INITIAL (decl) == error_mark_node)
1651 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1652 else if (DECL_INITIAL (decl))
1653 reloc = output_addressed_constants (DECL_INITIAL (decl));
1655 /* Switch to the appropriate section. */
1656 resolve_unique_section (decl, reloc);
1657 variable_section (decl, reloc);
1659 /* dbxout.c needs to know this. */
1660 if (in_text_section ())
1661 DECL_IN_TEXT_SECTION (decl) = 1;
1663 /* Output the alignment of this data. */
1664 if (align > BITS_PER_UNIT)
1666 ASM_OUTPUT_ALIGN (asm_out_file,
1667 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1670 /* Do any machine/system dependent processing of the object. */
1671 #ifdef ASM_DECLARE_OBJECT_NAME
1672 last_assemble_variable_decl = decl;
1673 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1674 #else
1675 /* Standard thing is just output label for the object. */
1676 ASM_OUTPUT_LABEL (asm_out_file, name);
1677 #endif /* ASM_DECLARE_OBJECT_NAME */
1679 if (!dont_output_data)
1681 if (DECL_INITIAL (decl))
1682 /* Output the actual data. */
1683 output_constant (DECL_INITIAL (decl),
1684 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1685 align);
1686 else
1687 /* Leave space for it. */
1688 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1692 /* Return 1 if type TYPE contains any pointers. */
1694 static int
1695 contains_pointers_p (type)
1696 tree type;
1698 switch (TREE_CODE (type))
1700 case POINTER_TYPE:
1701 case REFERENCE_TYPE:
1702 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1703 so I'll play safe and return 1. */
1704 case OFFSET_TYPE:
1705 return 1;
1707 case RECORD_TYPE:
1708 case UNION_TYPE:
1709 case QUAL_UNION_TYPE:
1711 tree fields;
1712 /* For a type that has fields, see if the fields have pointers. */
1713 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1714 if (TREE_CODE (fields) == FIELD_DECL
1715 && contains_pointers_p (TREE_TYPE (fields)))
1716 return 1;
1717 return 0;
1720 case ARRAY_TYPE:
1721 /* An array type contains pointers if its element type does. */
1722 return contains_pointers_p (TREE_TYPE (type));
1724 default:
1725 return 0;
1729 /* Output something to declare an external symbol to the assembler.
1730 (Most assemblers don't need this, so we normally output nothing.)
1731 Do nothing if DECL is not external. */
1733 void
1734 assemble_external (decl)
1735 tree decl ATTRIBUTE_UNUSED;
1737 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1738 main body of this code is only rarely exercised. To provide some
1739 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1740 open. If it's not, we should not be calling this function. */
1741 if (!asm_out_file)
1742 abort ();
1744 #ifdef ASM_OUTPUT_EXTERNAL
1745 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1747 rtx rtl = DECL_RTL (decl);
1749 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1750 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1752 /* Some systems do require some output. */
1753 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1754 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1757 #endif
1760 /* Similar, for calling a library function FUN. */
1762 void
1763 assemble_external_libcall (fun)
1764 rtx fun ATTRIBUTE_UNUSED;
1766 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1767 /* Declare library function name external when first used, if nec. */
1768 if (! SYMBOL_REF_USED (fun))
1770 SYMBOL_REF_USED (fun) = 1;
1771 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1773 #endif
1776 /* Declare the label NAME global. */
1778 void
1779 assemble_global (name)
1780 const char *name ATTRIBUTE_UNUSED;
1782 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1785 /* Assemble a label named NAME. */
1787 void
1788 assemble_label (name)
1789 const char *name;
1791 ASM_OUTPUT_LABEL (asm_out_file, name);
1794 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1795 If NAME starts with a *, the rest of NAME is output verbatim.
1796 Otherwise NAME is transformed in an implementation-defined way
1797 (usually by the addition of an underscore).
1798 Many macros in the tm file are defined to call this function. */
1800 void
1801 assemble_name (file, name)
1802 FILE *file;
1803 const char *name;
1805 const char *real_name;
1806 tree id;
1808 STRIP_NAME_ENCODING (real_name, name);
1810 id = maybe_get_identifier (real_name);
1811 if (id)
1812 TREE_SYMBOL_REFERENCED (id) = 1;
1814 if (name[0] == '*')
1815 fputs (&name[1], file);
1816 else
1817 ASM_OUTPUT_LABELREF (file, name);
1820 /* Allocate SIZE bytes writable static space with a gensym name
1821 and return an RTX to refer to its address. */
1824 assemble_static_space (size)
1825 int size;
1827 char name[12];
1828 const char *namestring;
1829 rtx x;
1831 #if 0
1832 if (flag_shared_data)
1833 data_section ();
1834 #endif
1836 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1837 ++const_labelno;
1838 namestring = ggc_strdup (name);
1840 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1842 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1843 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1844 BIGGEST_ALIGNMENT);
1845 #else
1846 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1847 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1848 #else
1850 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1851 so that each uninitialized object starts on such a boundary. */
1852 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1853 int rounded ATTRIBUTE_UNUSED
1854 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1855 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1856 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1857 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1859 #endif
1860 #endif
1861 return x;
1864 /* Assemble the static constant template for function entry trampolines.
1865 This is done at most once per compilation.
1866 Returns an RTX for the address of the template. */
1868 #ifdef TRAMPOLINE_TEMPLATE
1870 assemble_trampoline_template ()
1872 char label[256];
1873 const char *name;
1874 int align;
1876 /* By default, put trampoline templates in read-only data section. */
1878 #ifdef TRAMPOLINE_SECTION
1879 TRAMPOLINE_SECTION ();
1880 #else
1881 readonly_data_section ();
1882 #endif
1884 /* Write the assembler code to define one. */
1885 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1886 if (align > 0)
1888 ASM_OUTPUT_ALIGN (asm_out_file, align);
1891 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1892 TRAMPOLINE_TEMPLATE (asm_out_file);
1894 /* Record the rtl to refer to it. */
1895 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1896 name = ggc_strdup (label);
1897 return gen_rtx_SYMBOL_REF (Pmode, name);
1899 #endif
1901 /* A and B are either alignments or offsets. Return the minimum alignment
1902 that may be assumed after adding the two together. */
1904 static inline unsigned
1905 min_align (a, b)
1906 unsigned int a, b;
1908 return (a | b) & -(a | b);
1911 /* Return the assembler directive for creating a given kind of integer
1912 object. SIZE is the number of bytes in the object and ALIGNED_P
1913 indicates whether it is known to be aligned. Return NULL if the
1914 assembly dialect has no such directive.
1916 The returned string should be printed at the start of a new line and
1917 be followed immediately by the object's initial value. */
1919 const char *
1920 integer_asm_op (size, aligned_p)
1921 int size;
1922 int aligned_p;
1924 struct asm_int_op *ops;
1926 if (aligned_p)
1927 ops = &targetm.asm_out.aligned_op;
1928 else
1929 ops = &targetm.asm_out.unaligned_op;
1931 switch (size)
1933 case 1:
1934 return targetm.asm_out.byte_op;
1935 case 2:
1936 return ops->hi;
1937 case 4:
1938 return ops->si;
1939 case 8:
1940 return ops->di;
1941 case 16:
1942 return ops->ti;
1943 default:
1944 return NULL;
1948 /* Use directive OP to assemble an integer object X. Print OP at the
1949 start of the line, followed immediately by the value of X. */
1951 void
1952 assemble_integer_with_op (op, x)
1953 const char *op;
1954 rtx x;
1956 fputs (op, asm_out_file);
1957 output_addr_const (asm_out_file, x);
1958 fputc ('\n', asm_out_file);
1961 /* The default implementation of the asm_out.integer target hook. */
1963 bool
1964 default_assemble_integer (x, size, aligned_p)
1965 rtx x ATTRIBUTE_UNUSED;
1966 unsigned int size ATTRIBUTE_UNUSED;
1967 int aligned_p ATTRIBUTE_UNUSED;
1969 const char *op = integer_asm_op (size, aligned_p);
1970 return op && (assemble_integer_with_op (op, x), true);
1973 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1974 the alignment of the integer in bits. Return 1 if we were able to output
1975 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1976 the constant. */
1978 bool
1979 assemble_integer (x, size, align, force)
1980 rtx x;
1981 unsigned int size;
1982 unsigned int align;
1983 int force;
1985 int aligned_p;
1987 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1989 /* See if the target hook can handle this kind of object. */
1990 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1991 return true;
1993 /* If the object is a multi-byte one, try splitting it up. Split
1994 it into words it if is multi-word, otherwise split it into bytes. */
1995 if (size > 1)
1997 enum machine_mode omode, imode;
1998 unsigned int subalign;
1999 unsigned int subsize, i;
2001 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2002 subalign = MIN (align, subsize * BITS_PER_UNIT);
2003 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2004 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2006 for (i = 0; i < size; i += subsize)
2008 rtx partial = simplify_subreg (omode, x, imode, i);
2009 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2010 break;
2012 if (i == size)
2013 return true;
2015 /* If we've printed some of it, but not all of it, there's no going
2016 back now. */
2017 if (i > 0)
2018 abort ();
2021 if (force)
2022 abort ();
2024 return false;
2027 void
2028 assemble_real (d, mode, align)
2029 REAL_VALUE_TYPE d;
2030 enum machine_mode mode;
2031 unsigned int align;
2033 long data[4];
2034 long l;
2035 unsigned int nalign = min_align (align, 32);
2037 switch (BITS_PER_UNIT)
2039 case 8:
2040 switch (mode)
2042 case SFmode:
2043 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2044 assemble_integer (GEN_INT (l), 4, align, 1);
2045 break;
2046 case DFmode:
2047 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2048 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2049 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2050 break;
2051 case XFmode:
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 break;
2057 case TFmode:
2058 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2059 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2060 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2061 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2062 assemble_integer (GEN_INT (data[3]), 4, nalign, 1);
2063 break;
2064 default:
2065 abort ();
2067 break;
2069 case 16:
2070 switch (mode)
2072 case HFmode:
2073 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2074 assemble_integer (GEN_INT (l), 2, align, 1);
2075 break;
2076 case TQFmode:
2077 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2078 assemble_integer (GEN_INT (data[0]), 2, align, 1);
2079 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2080 break;
2081 default:
2082 abort ();
2084 break;
2086 case 32:
2087 switch (mode)
2089 case QFmode:
2090 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2091 assemble_integer (GEN_INT (l), 1, align, 1);
2092 break;
2093 case HFmode:
2094 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2095 assemble_integer (GEN_INT (data[0]), 1, align, 1);
2096 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2097 break;
2098 default:
2099 abort ();
2101 break;
2103 default:
2104 abort ();
2108 /* Here we combine duplicate floating constants to make
2109 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2111 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2112 For an integer, I0 is the low-order word and I1 is the high-order word.
2113 For a real number, I0 is the word with the low address
2114 and I1 is the word with the high address. */
2117 immed_double_const (i0, i1, mode)
2118 HOST_WIDE_INT i0, i1;
2119 enum machine_mode mode;
2121 rtx r;
2123 if (GET_MODE_CLASS (mode) == MODE_INT
2124 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2126 /* We clear out all bits that don't belong in MODE, unless they and our
2127 sign bit are all one. So we get either a reasonable negative value
2128 or a reasonable unsigned value for this mode. */
2129 int width = GET_MODE_BITSIZE (mode);
2130 if (width < HOST_BITS_PER_WIDE_INT
2131 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2132 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2133 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2134 else if (width == HOST_BITS_PER_WIDE_INT
2135 && ! (i1 == ~0 && i0 < 0))
2136 i1 = 0;
2137 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2138 /* We cannot represent this value as a constant. */
2139 abort ();
2141 /* If this would be an entire word for the target, but is not for
2142 the host, then sign-extend on the host so that the number will look
2143 the same way on the host that it would on the target.
2145 For example, when building a 64 bit alpha hosted 32 bit sparc
2146 targeted compiler, then we want the 32 bit unsigned value -1 to be
2147 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2148 The later confuses the sparc backend. */
2150 if (width < HOST_BITS_PER_WIDE_INT
2151 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2152 i0 |= ((HOST_WIDE_INT) (-1) << width);
2154 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2156 ??? Strictly speaking, this is wrong if we create a CONST_INT
2157 for a large unsigned constant with the size of MODE being
2158 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2159 wider mode. In that case we will mis-interpret it as a negative
2160 number.
2162 Unfortunately, the only alternative is to make a CONST_DOUBLE
2163 for any constant in any mode if it is an unsigned constant larger
2164 than the maximum signed integer in an int on the host. However,
2165 doing this will break everyone that always expects to see a CONST_INT
2166 for SImode and smaller.
2168 We have always been making CONST_INTs in this case, so nothing new
2169 is being broken. */
2171 if (width <= HOST_BITS_PER_WIDE_INT)
2172 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2174 /* If this integer fits in one word, return a CONST_INT. */
2175 if ((i1 == 0 && i0 >= 0)
2176 || (i1 == ~0 && i0 < 0))
2177 return GEN_INT (i0);
2179 /* We use VOIDmode for integers. */
2180 mode = VOIDmode;
2183 /* Search the chain for an existing CONST_DOUBLE with the right value.
2184 If one is found, return it. */
2185 if (cfun != 0)
2186 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2187 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2188 && GET_MODE (r) == mode)
2189 return r;
2191 /* No; make a new one and add it to the chain. */
2192 r = gen_rtx_CONST_DOUBLE (mode, i0, i1);
2194 /* Don't touch const_double_chain if not inside any function. */
2195 if (current_function_decl != 0)
2197 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2198 const_double_chain = r;
2201 return r;
2204 /* Return a CONST_DOUBLE for a specified `double' value
2205 and machine mode. */
2208 immed_real_const_1 (d, mode)
2209 REAL_VALUE_TYPE d;
2210 enum machine_mode mode;
2212 union real_extract u;
2213 rtx r;
2215 /* Get the desired `double' value as a sequence of ints
2216 since that is how they are stored in a CONST_DOUBLE. */
2218 u.d = d;
2220 /* Detect special cases. Check for NaN first, because some ports
2221 (specifically the i386) do not emit correct ieee-fp code by default, and
2222 thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2223 and if REAL_VALUES_EQUAL does a floating point comparison. */
2224 if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_IDENTICAL (dconst0, d))
2225 return CONST0_RTX (mode);
2226 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2227 return CONST1_RTX (mode);
2228 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst2, d))
2229 return CONST2_RTX (mode);
2231 if (sizeof u == sizeof (HOST_WIDE_INT))
2232 return immed_double_const (u.i[0], 0, mode);
2233 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2234 return immed_double_const (u.i[0], u.i[1], mode);
2236 /* The rest of this function handles the case where
2237 a float value requires more than 2 ints of space.
2238 It will be deleted as dead code on machines that don't need it. */
2240 /* Search the chain for an existing CONST_DOUBLE with the right value.
2241 If one is found, return it. */
2242 if (cfun != 0)
2243 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2244 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2245 && GET_MODE (r) == mode)
2246 return r;
2248 /* No; make a new one and add it to the chain.
2250 We may be called by an optimizer which may be discarding any memory
2251 allocated during its processing (such as combine and loop). However,
2252 we will be leaving this constant on the chain, so we cannot tolerate
2253 freed memory. */
2254 r = rtx_alloc (CONST_DOUBLE);
2255 PUT_MODE (r, mode);
2256 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2258 /* If we aren't inside a function, don't put r on the
2259 const_double_chain. */
2260 if (current_function_decl != 0)
2262 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2263 const_double_chain = r;
2265 else
2266 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2268 return r;
2271 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2272 which must be a REAL_CST tree node. */
2275 immed_real_const (exp)
2276 tree exp;
2278 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2281 /* At the end of a function, forget the memory-constants
2282 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2283 Also clear out real_constant_chain and clear out all the chain-pointers. */
2285 void
2286 clear_const_double_mem ()
2288 rtx r, next;
2290 for (r = const_double_chain; r; r = next)
2292 next = CONST_DOUBLE_CHAIN (r);
2293 CONST_DOUBLE_CHAIN (r) = 0;
2295 const_double_chain = 0;
2298 /* Given an expression EXP with a constant value,
2299 reduce it to the sum of an assembler symbol and an integer.
2300 Store them both in the structure *VALUE.
2301 Abort if EXP does not reduce. */
2303 struct addr_const
2305 rtx base;
2306 HOST_WIDE_INT offset;
2309 static void
2310 decode_addr_const (exp, value)
2311 tree exp;
2312 struct addr_const *value;
2314 tree target = TREE_OPERAND (exp, 0);
2315 int offset = 0;
2316 rtx x;
2318 while (1)
2320 if (TREE_CODE (target) == COMPONENT_REF
2321 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2324 offset += int_byte_position (TREE_OPERAND (target, 1));
2325 target = TREE_OPERAND (target, 0);
2327 else if (TREE_CODE (target) == ARRAY_REF
2328 || TREE_CODE (target) == ARRAY_RANGE_REF)
2330 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2331 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2332 target = TREE_OPERAND (target, 0);
2334 else
2335 break;
2338 switch (TREE_CODE (target))
2340 case VAR_DECL:
2341 case FUNCTION_DECL:
2342 x = DECL_RTL (target);
2343 break;
2345 case LABEL_DECL:
2346 x = gen_rtx_MEM (FUNCTION_MODE,
2347 gen_rtx_LABEL_REF (VOIDmode,
2348 label_rtx (TREE_OPERAND (exp, 0))));
2349 break;
2351 case REAL_CST:
2352 case STRING_CST:
2353 case COMPLEX_CST:
2354 case CONSTRUCTOR:
2355 case INTEGER_CST:
2356 /* This constant should have been output already, but we can't simply
2357 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2358 x = output_constant_def (target, 1);
2359 break;
2361 default:
2362 abort ();
2365 if (GET_CODE (x) != MEM)
2366 abort ();
2367 x = XEXP (x, 0);
2369 value->base = x;
2370 value->offset = offset;
2373 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2374 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_INT, RTX_VECTOR, RTX_UNSPEC };
2375 struct rtx_const
2377 ENUM_BITFIELD(kind) kind : 16;
2378 ENUM_BITFIELD(machine_mode) mode : 16;
2379 union {
2380 union real_extract du;
2381 struct addr_const addr;
2382 struct {HOST_WIDE_INT high, low;} di;
2384 /* The max vector size we have is 8 wide. This should be enough. */
2385 HOST_WIDE_INT veclo[16];
2386 HOST_WIDE_INT vechi[16];
2387 } un;
2390 /* Uniquize all constants that appear in memory.
2391 Each constant in memory thus far output is recorded
2392 in `const_hash_table' with a `struct constant_descriptor'
2393 that contains a polish representation of the value of
2394 the constant.
2396 We cannot store the trees in the hash table
2397 because the trees may be temporary. */
2399 struct constant_descriptor
2401 struct constant_descriptor *next;
2402 const char *label;
2403 rtx rtl;
2404 /* Make sure the data is reasonably aligned. */
2405 union
2407 unsigned char contents[1];
2408 #ifdef HAVE_LONG_DOUBLE
2409 long double d;
2410 #else
2411 double d;
2412 #endif
2413 } u;
2416 #define HASHBITS 30
2417 #define MAX_HASH_TABLE 1009
2418 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2420 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2421 out a string constant, we defer output of the constants until we know
2422 they are actually used. This will be if something takes its address or if
2423 there is a usage of the string in the RTL of a function. */
2425 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2427 struct deferred_string
2429 const char *label;
2430 tree exp;
2431 int labelno;
2434 static htab_t const_str_htab;
2436 /* Mark a const_hash_table descriptor for GC. */
2438 static void
2439 mark_const_hash_entry (ptr)
2440 void *ptr;
2442 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2444 while (desc)
2446 ggc_mark_rtx (desc->rtl);
2447 desc = desc->next;
2451 /* Mark the hash-table element X (which is really a pointer to an
2452 struct deferred_string *). */
2454 static int
2455 mark_const_str_htab_1 (x, data)
2456 void **x;
2457 void *data ATTRIBUTE_UNUSED;
2459 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2460 return 1;
2463 /* Mark a const_str_htab for GC. */
2465 static void
2466 mark_const_str_htab (htab)
2467 void *htab;
2469 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2472 /* Returns a hash code for X (which is a really a
2473 struct deferred_string *). */
2475 static hashval_t
2476 const_str_htab_hash (x)
2477 const void *x;
2479 return STRHASH (((const struct deferred_string *) x)->label);
2482 /* Returns non-zero if the value represented by X (which is really a
2483 struct deferred_string *) is the same as that given by Y
2484 (which is really a char *). */
2486 static int
2487 const_str_htab_eq (x, y)
2488 const void *x;
2489 const void *y;
2491 return (((const struct deferred_string *) x)->label == (const char *) y);
2494 /* Delete the hash table entry dfsp. */
2496 static void
2497 const_str_htab_del (dfsp)
2498 void *dfsp;
2500 free (dfsp);
2503 /* Compute a hash code for a constant expression. */
2505 static int
2506 const_hash (exp)
2507 tree exp;
2509 const char *p;
2510 int len, hi, i;
2511 enum tree_code code = TREE_CODE (exp);
2513 /* Either set P and LEN to the address and len of something to hash and
2514 exit the switch or return a value. */
2516 switch (code)
2518 case INTEGER_CST:
2519 p = (char *) &TREE_INT_CST (exp);
2520 len = sizeof TREE_INT_CST (exp);
2521 break;
2523 case REAL_CST:
2524 p = (char *) &TREE_REAL_CST (exp);
2525 len = sizeof TREE_REAL_CST (exp);
2526 break;
2528 case STRING_CST:
2529 p = TREE_STRING_POINTER (exp);
2530 len = TREE_STRING_LENGTH (exp);
2531 break;
2533 case COMPLEX_CST:
2534 return (const_hash (TREE_REALPART (exp)) * 5
2535 + const_hash (TREE_IMAGPART (exp)));
2537 case CONSTRUCTOR:
2538 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2540 char *tmp;
2542 len = int_size_in_bytes (TREE_TYPE (exp));
2543 tmp = (char *) alloca (len);
2544 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2545 p = tmp;
2546 break;
2548 else
2550 tree link;
2552 /* For record type, include the type in the hashing.
2553 We do not do so for array types
2554 because (1) the sizes of the elements are sufficient
2555 and (2) distinct array types can have the same constructor.
2556 Instead, we include the array size because the constructor could
2557 be shorter. */
2558 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2559 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2560 % MAX_HASH_TABLE;
2561 else
2562 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2563 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2565 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2566 if (TREE_VALUE (link))
2568 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2570 return hi;
2573 case ADDR_EXPR:
2575 struct addr_const value;
2577 decode_addr_const (exp, &value);
2578 if (GET_CODE (value.base) == SYMBOL_REF)
2580 /* Don't hash the address of the SYMBOL_REF;
2581 only use the offset and the symbol name. */
2582 hi = value.offset;
2583 p = XSTR (value.base, 0);
2584 for (i = 0; p[i] != 0; i++)
2585 hi = ((hi * 613) + (unsigned) (p[i]));
2587 else if (GET_CODE (value.base) == LABEL_REF)
2588 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2589 else
2590 abort ();
2592 hi &= (1 << HASHBITS) - 1;
2593 hi %= MAX_HASH_TABLE;
2595 return hi;
2597 case PLUS_EXPR:
2598 case MINUS_EXPR:
2599 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2600 + const_hash (TREE_OPERAND (exp, 1)));
2602 case NOP_EXPR:
2603 case CONVERT_EXPR:
2604 case NON_LVALUE_EXPR:
2605 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2607 default:
2608 /* A language specific constant. Just hash the code. */
2609 return (int) code % MAX_HASH_TABLE;
2612 /* Compute hashing function */
2613 hi = len;
2614 for (i = 0; i < len; i++)
2615 hi = ((hi * 613) + (unsigned) (p[i]));
2617 hi &= (1 << HASHBITS) - 1;
2618 hi %= MAX_HASH_TABLE;
2619 return hi;
2622 /* Compare a constant expression EXP with a constant-descriptor DESC.
2623 Return 1 if DESC describes a constant with the same value as EXP. */
2625 static int
2626 compare_constant (exp, desc)
2627 tree exp;
2628 struct constant_descriptor *desc;
2630 return 0 != compare_constant_1 (exp, desc->u.contents);
2633 /* Compare constant expression EXP with a substring P of a constant descriptor.
2634 If they match, return a pointer to the end of the substring matched.
2635 If they do not match, return 0.
2637 Since descriptors are written in polish prefix notation,
2638 this function can be used recursively to test one operand of EXP
2639 against a subdescriptor, and if it succeeds it returns the
2640 address of the subdescriptor for the next operand. */
2642 static const unsigned char *
2643 compare_constant_1 (exp, p)
2644 tree exp;
2645 const unsigned char *p;
2647 const unsigned char *strp;
2648 int len;
2649 enum tree_code code = TREE_CODE (exp);
2651 if (code != (enum tree_code) *p++)
2652 return 0;
2654 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2655 switch, or return the result of the comparison. */
2657 switch (code)
2659 case INTEGER_CST:
2660 /* Integer constants are the same only if the same width of type. */
2661 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2662 return 0;
2664 strp = (unsigned char *) &TREE_INT_CST (exp);
2665 len = sizeof TREE_INT_CST (exp);
2666 break;
2668 case REAL_CST:
2669 /* Real constants are the same only if the same width of type. */
2670 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2671 return 0;
2673 strp = (unsigned char *) &TREE_REAL_CST (exp);
2674 len = sizeof TREE_REAL_CST (exp);
2675 break;
2677 case STRING_CST:
2678 if (flag_writable_strings)
2679 return 0;
2681 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2682 return 0;
2684 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2685 len = TREE_STRING_LENGTH (exp);
2686 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2687 sizeof TREE_STRING_LENGTH (exp)))
2688 return 0;
2690 p += sizeof TREE_STRING_LENGTH (exp);
2691 break;
2693 case COMPLEX_CST:
2694 p = compare_constant_1 (TREE_REALPART (exp), p);
2695 if (p == 0)
2696 return 0;
2698 return compare_constant_1 (TREE_IMAGPART (exp), p);
2700 case CONSTRUCTOR:
2701 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2703 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2704 unsigned char *tmp = (unsigned char *) alloca (len);
2706 get_set_constructor_bytes (exp, tmp, len);
2707 strp = (unsigned char *) tmp;
2708 if (memcmp ((char *) &xlen, p, sizeof xlen))
2709 return 0;
2711 p += sizeof xlen;
2712 break;
2714 else
2716 tree link;
2717 int length = list_length (CONSTRUCTOR_ELTS (exp));
2718 tree type;
2719 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2720 int have_purpose = 0;
2722 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2723 if (TREE_PURPOSE (link))
2724 have_purpose = 1;
2726 if (memcmp ((char *) &length, p, sizeof length))
2727 return 0;
2729 p += sizeof length;
2731 /* For record constructors, insist that the types match.
2732 For arrays, just verify both constructors are for arrays.
2733 Then insist that either both or none have any TREE_PURPOSE
2734 values. */
2735 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2736 type = TREE_TYPE (exp);
2737 else
2738 type = 0;
2740 if (memcmp ((char *) &type, p, sizeof type))
2741 return 0;
2743 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2745 if (memcmp ((char *) &mode, p, sizeof mode))
2746 return 0;
2748 p += sizeof mode;
2751 p += sizeof type;
2753 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2754 return 0;
2756 p += sizeof have_purpose;
2758 /* For arrays, insist that the size in bytes match. */
2759 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2761 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2763 if (memcmp ((char *) &size, p, sizeof size))
2764 return 0;
2766 p += sizeof size;
2769 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2771 if (TREE_VALUE (link))
2773 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2774 return 0;
2776 else
2778 tree zero = 0;
2780 if (memcmp ((char *) &zero, p, sizeof zero))
2781 return 0;
2783 p += sizeof zero;
2786 if (TREE_PURPOSE (link)
2787 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2789 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2790 sizeof TREE_PURPOSE (link)))
2791 return 0;
2793 p += sizeof TREE_PURPOSE (link);
2795 else if (TREE_PURPOSE (link))
2797 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2798 return 0;
2800 else if (have_purpose)
2802 int zero = 0;
2804 if (memcmp ((char *) &zero, p, sizeof zero))
2805 return 0;
2807 p += sizeof zero;
2811 return p;
2814 case ADDR_EXPR:
2816 struct addr_const value;
2818 decode_addr_const (exp, &value);
2819 strp = (unsigned char *) &value.offset;
2820 len = sizeof value.offset;
2821 /* Compare the offset. */
2822 while (--len >= 0)
2823 if (*p++ != *strp++)
2824 return 0;
2826 /* Compare symbol name. */
2827 strp = (const unsigned char *) XSTR (value.base, 0);
2828 len = strlen ((const char *) strp) + 1;
2830 break;
2832 case PLUS_EXPR:
2833 case MINUS_EXPR:
2834 case RANGE_EXPR:
2835 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2836 if (p == 0)
2837 return 0;
2839 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2841 case NOP_EXPR:
2842 case CONVERT_EXPR:
2843 case NON_LVALUE_EXPR:
2844 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2846 default:
2848 tree new = (*lang_hooks.expand_constant) (exp);
2850 if (new != exp)
2851 return compare_constant_1 (new, p);
2852 else
2853 return 0;
2857 /* Compare constant contents. */
2858 while (--len >= 0)
2859 if (*p++ != *strp++)
2860 return 0;
2862 return p;
2865 /* Construct a constant descriptor for the expression EXP.
2866 It is up to the caller to enter the descriptor in the hash table. */
2868 static struct constant_descriptor *
2869 record_constant (exp)
2870 tree exp;
2872 struct constant_descriptor *next = 0;
2873 char *label = 0;
2874 rtx rtl = 0;
2875 int pad;
2877 /* Make a struct constant_descriptor. The first three pointers will
2878 be filled in later. Here we just leave space for them. */
2880 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2881 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2882 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2884 /* Align the descriptor for the data payload. */
2885 pad = (offsetof (struct constant_descriptor, u)
2886 - offsetof(struct constant_descriptor, rtl)
2887 - sizeof(next->rtl));
2888 if (pad > 0)
2889 obstack_blank (&permanent_obstack, pad);
2891 record_constant_1 (exp);
2892 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2895 /* Add a description of constant expression EXP
2896 to the object growing in `permanent_obstack'.
2897 No need to return its address; the caller will get that
2898 from the obstack when the object is complete. */
2900 static void
2901 record_constant_1 (exp)
2902 tree exp;
2904 const unsigned char *strp;
2905 int len;
2906 enum tree_code code = TREE_CODE (exp);
2908 obstack_1grow (&permanent_obstack, (unsigned int) code);
2910 switch (code)
2912 case INTEGER_CST:
2913 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2914 strp = (unsigned char *) &TREE_INT_CST (exp);
2915 len = sizeof TREE_INT_CST (exp);
2916 break;
2918 case REAL_CST:
2919 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2920 strp = (unsigned char *) &TREE_REAL_CST (exp);
2921 len = sizeof TREE_REAL_CST (exp);
2922 break;
2924 case STRING_CST:
2925 if (flag_writable_strings)
2926 return;
2928 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2929 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2930 len = TREE_STRING_LENGTH (exp);
2931 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2932 sizeof TREE_STRING_LENGTH (exp));
2933 break;
2935 case COMPLEX_CST:
2936 record_constant_1 (TREE_REALPART (exp));
2937 record_constant_1 (TREE_IMAGPART (exp));
2938 return;
2940 case CONSTRUCTOR:
2941 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2943 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2944 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2945 obstack_blank (&permanent_obstack, nbytes);
2946 get_set_constructor_bytes
2947 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2948 nbytes);
2949 return;
2951 else
2953 tree link;
2954 int length = list_length (CONSTRUCTOR_ELTS (exp));
2955 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2956 tree type;
2957 int have_purpose = 0;
2959 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2960 if (TREE_PURPOSE (link))
2961 have_purpose = 1;
2963 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2965 /* For record constructors, insist that the types match.
2966 For arrays, just verify both constructors are for arrays
2967 of the same mode. Then insist that either both or none
2968 have any TREE_PURPOSE values. */
2969 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2970 type = TREE_TYPE (exp);
2971 else
2972 type = 0;
2974 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2975 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2976 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2978 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2979 sizeof have_purpose);
2981 /* For arrays, insist that the size in bytes match. */
2982 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2984 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2985 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2988 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2990 if (TREE_VALUE (link))
2991 record_constant_1 (TREE_VALUE (link));
2992 else
2994 tree zero = 0;
2996 obstack_grow (&permanent_obstack,
2997 (char *) &zero, sizeof zero);
3000 if (TREE_PURPOSE (link)
3001 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
3002 obstack_grow (&permanent_obstack,
3003 (char *) &TREE_PURPOSE (link),
3004 sizeof TREE_PURPOSE (link));
3005 else if (TREE_PURPOSE (link))
3006 record_constant_1 (TREE_PURPOSE (link));
3007 else if (have_purpose)
3009 int zero = 0;
3011 obstack_grow (&permanent_obstack,
3012 (char *) &zero, sizeof zero);
3016 return;
3018 case ADDR_EXPR:
3020 struct addr_const value;
3022 decode_addr_const (exp, &value);
3023 /* Record the offset. */
3024 obstack_grow (&permanent_obstack,
3025 (char *) &value.offset, sizeof value.offset);
3027 switch (GET_CODE (value.base))
3029 case SYMBOL_REF:
3030 /* Record the symbol name. */
3031 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3032 strlen (XSTR (value.base, 0)) + 1);
3033 break;
3034 case LABEL_REF:
3035 /* Record the address of the CODE_LABEL. It may not have
3036 been emitted yet, so it's UID may be zero. But pointer
3037 identity is good enough. */
3038 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3039 sizeof (rtx));
3040 break;
3041 default:
3042 abort ();
3045 return;
3047 case PLUS_EXPR:
3048 case MINUS_EXPR:
3049 case RANGE_EXPR:
3050 record_constant_1 (TREE_OPERAND (exp, 0));
3051 record_constant_1 (TREE_OPERAND (exp, 1));
3052 return;
3054 case NOP_EXPR:
3055 case CONVERT_EXPR:
3056 case NON_LVALUE_EXPR:
3057 record_constant_1 (TREE_OPERAND (exp, 0));
3058 return;
3060 default:
3062 tree new = (*lang_hooks.expand_constant) (exp);
3064 if (new != exp)
3065 record_constant_1 (new);
3066 return;
3070 /* Record constant contents. */
3071 obstack_grow (&permanent_obstack, strp, len);
3074 /* Record a list of constant expressions that were passed to
3075 output_constant_def but that could not be output right away. */
3077 struct deferred_constant
3079 struct deferred_constant *next;
3080 tree exp;
3081 int reloc;
3082 int labelno;
3085 static struct deferred_constant *deferred_constants;
3087 /* Another list of constants which should be output after the
3088 function. */
3089 static struct deferred_constant *after_function_constants;
3091 /* Nonzero means defer output of addressed subconstants
3092 (i.e., those for which output_constant_def is called.) */
3093 static int defer_addressed_constants_flag;
3095 /* Start deferring output of subconstants. */
3097 void
3098 defer_addressed_constants ()
3100 defer_addressed_constants_flag++;
3103 /* Stop deferring output of subconstants,
3104 and output now all those that have been deferred. */
3106 void
3107 output_deferred_addressed_constants ()
3109 struct deferred_constant *p, *next;
3111 defer_addressed_constants_flag--;
3113 if (defer_addressed_constants_flag > 0)
3114 return;
3116 for (p = deferred_constants; p; p = next)
3118 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3119 next = p->next;
3120 free (p);
3123 deferred_constants = 0;
3126 /* Output any constants which should appear after a function. */
3128 static void
3129 output_after_function_constants ()
3131 struct deferred_constant *p, *next;
3133 for (p = after_function_constants; p; p = next)
3135 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3136 next = p->next;
3137 free (p);
3140 after_function_constants = 0;
3143 /* Make a copy of the whole tree structure for a constant.
3144 This handles the same types of nodes that compare_constant
3145 and record_constant handle. */
3147 static tree
3148 copy_constant (exp)
3149 tree exp;
3151 switch (TREE_CODE (exp))
3153 case ADDR_EXPR:
3154 /* For ADDR_EXPR, we do not want to copy the decl whose address
3155 is requested. We do want to copy constants though. */
3156 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3157 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3158 copy_constant (TREE_OPERAND (exp, 0)));
3159 else
3160 return copy_node (exp);
3162 case INTEGER_CST:
3163 case REAL_CST:
3164 case STRING_CST:
3165 return copy_node (exp);
3167 case COMPLEX_CST:
3168 return build_complex (TREE_TYPE (exp),
3169 copy_constant (TREE_REALPART (exp)),
3170 copy_constant (TREE_IMAGPART (exp)));
3172 case PLUS_EXPR:
3173 case MINUS_EXPR:
3174 return build (TREE_CODE (exp), TREE_TYPE (exp),
3175 copy_constant (TREE_OPERAND (exp, 0)),
3176 copy_constant (TREE_OPERAND (exp, 1)));
3178 case NOP_EXPR:
3179 case CONVERT_EXPR:
3180 case NON_LVALUE_EXPR:
3181 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3182 copy_constant (TREE_OPERAND (exp, 0)));
3184 case CONSTRUCTOR:
3186 tree copy = copy_node (exp);
3187 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3188 tree tail;
3190 CONSTRUCTOR_ELTS (copy) = list;
3191 for (tail = list; tail; tail = TREE_CHAIN (tail))
3192 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3193 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3194 for (tail = list; tail; tail = TREE_CHAIN (tail))
3195 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3197 return copy;
3200 default:
3201 abort ();
3205 /* Return an rtx representing a reference to constant data in memory
3206 for the constant expression EXP.
3208 If assembler code for such a constant has already been output,
3209 return an rtx to refer to it.
3210 Otherwise, output such a constant in memory (or defer it for later)
3211 and generate an rtx for it.
3213 If DEFER is non-zero, the output of string constants can be deferred
3214 and output only if referenced in the function after all optimizations.
3216 The TREE_CST_RTL of EXP is set up to point to that rtx.
3217 The const_hash_table records which constants already have label strings. */
3220 output_constant_def (exp, defer)
3221 tree exp;
3222 int defer;
3224 int hash;
3225 struct constant_descriptor *desc;
3226 struct deferred_string **defstr;
3227 char label[256];
3228 int reloc;
3229 int found = 1;
3230 int after_function = 0;
3231 int labelno = -1;
3232 rtx rtl;
3234 /* We can't just use the saved RTL if this is a defererred string constant
3235 and we are not to defer anymode. */
3236 if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3237 && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3238 return TREE_CST_RTL (exp);
3240 /* Make sure any other constants whose addresses appear in EXP
3241 are assigned label numbers. */
3243 reloc = output_addressed_constants (exp);
3245 /* Compute hash code of EXP. Search the descriptors for that hash code
3246 to see if any of them describes EXP. If yes, the descriptor records
3247 the label number already assigned. */
3249 hash = const_hash (exp) % MAX_HASH_TABLE;
3251 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3252 if (compare_constant (exp, desc))
3253 break;
3255 if (desc == 0)
3257 /* No constant equal to EXP is known to have been output.
3258 Make a constant descriptor to enter EXP in the hash table.
3259 Assign the label number and record it in the descriptor for
3260 future calls to this function to find. */
3262 /* Create a string containing the label name, in LABEL. */
3263 labelno = const_labelno++;
3264 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3266 desc = record_constant (exp);
3267 desc->next = const_hash_table[hash];
3268 desc->label = ggc_strdup (label);
3269 const_hash_table[hash] = desc;
3271 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3272 rtl = desc->rtl
3273 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3274 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3276 set_mem_attributes (rtl, exp, 1);
3277 set_mem_alias_set (rtl, 0);
3278 set_mem_alias_set (rtl, const_alias_set);
3280 found = 0;
3282 else
3283 rtl = desc->rtl;
3285 if (TREE_CODE (exp) != INTEGER_CST)
3286 TREE_CST_RTL (exp) = rtl;
3288 /* Optionally set flags or add text to the name to record information
3289 such as that it is a function name. If the name is changed, the macro
3290 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3291 #ifdef ENCODE_SECTION_INFO
3292 /* A previously-processed constant would already have section info
3293 encoded in it. */
3294 if (! found)
3296 ENCODE_SECTION_INFO (exp, true);
3297 desc->rtl = rtl;
3298 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3300 #endif
3302 #ifdef CONSTANT_AFTER_FUNCTION_P
3303 if (current_function_decl != 0
3304 && CONSTANT_AFTER_FUNCTION_P (exp))
3305 after_function = 1;
3306 #endif
3308 if (found
3309 && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3310 && (!defer || defer_addressed_constants_flag || after_function))
3312 defstr = (struct deferred_string **)
3313 htab_find_slot_with_hash (const_str_htab, desc->label,
3314 STRHASH (desc->label), NO_INSERT);
3315 if (defstr)
3317 /* If the string is currently deferred but we need to output it now,
3318 remove it from deferred string hash table. */
3319 found = 0;
3320 labelno = (*defstr)->labelno;
3321 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3322 htab_clear_slot (const_str_htab, (void **) defstr);
3326 /* If this is the first time we've seen this particular constant,
3327 output it (or defer its output for later). */
3328 if (! found)
3330 if (defer_addressed_constants_flag || after_function)
3332 struct deferred_constant *p
3333 = (struct deferred_constant *)
3334 xmalloc (sizeof (struct deferred_constant));
3336 p->exp = copy_constant (exp);
3337 p->reloc = reloc;
3338 p->labelno = labelno;
3339 if (after_function)
3341 p->next = after_function_constants;
3342 after_function_constants = p;
3344 else
3346 p->next = deferred_constants;
3347 deferred_constants = p;
3350 else
3352 /* Do no output if -fsyntax-only. */
3353 if (! flag_syntax_only)
3355 if (TREE_CODE (exp) != STRING_CST
3356 || !defer
3357 || flag_writable_strings
3358 || (defstr = (struct deferred_string **)
3359 htab_find_slot_with_hash (const_str_htab,
3360 desc->label,
3361 STRHASH (desc->label),
3362 INSERT)) == NULL)
3363 output_constant_def_contents (exp, reloc, labelno);
3364 else
3366 struct deferred_string *p;
3368 p = (struct deferred_string *)
3369 xmalloc (sizeof (struct deferred_string));
3371 p->exp = copy_constant (exp);
3372 p->label = desc->label;
3373 p->labelno = labelno;
3374 *defstr = p;
3375 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3381 return rtl;
3384 /* Now output assembler code to define the label for EXP,
3385 and follow it with the data of EXP. */
3387 static void
3388 output_constant_def_contents (exp, reloc, labelno)
3389 tree exp;
3390 int reloc;
3391 int labelno;
3393 int align;
3395 /* Align the location counter as required by EXP's data type. */
3396 align = TYPE_ALIGN (TREE_TYPE (exp));
3397 #ifdef CONSTANT_ALIGNMENT
3398 align = CONSTANT_ALIGNMENT (exp, align);
3399 #endif
3401 if (IN_NAMED_SECTION (exp))
3402 named_section (exp, NULL, reloc);
3403 else
3405 /* First switch to text section, except for writable strings. */
3406 #ifdef SELECT_SECTION
3407 SELECT_SECTION (exp, reloc, align);
3408 #else
3409 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3410 || (flag_pic && reloc))
3411 data_section ();
3412 else
3413 readonly_data_section ();
3414 #endif
3417 if (align > BITS_PER_UNIT)
3419 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3422 /* Output the label itself. */
3423 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3425 /* Output the value of EXP. */
3426 output_constant (exp,
3427 (TREE_CODE (exp) == STRING_CST
3428 ? MAX (TREE_STRING_LENGTH (exp),
3429 int_size_in_bytes (TREE_TYPE (exp)))
3430 : int_size_in_bytes (TREE_TYPE (exp))),
3431 align);
3435 /* Structure to represent sufficient information about a constant so that
3436 it can be output when the constant pool is output, so that function
3437 integration can be done, and to simplify handling on machines that reference
3438 constant pool as base+displacement. */
3440 struct pool_constant
3442 struct constant_descriptor *desc;
3443 struct pool_constant *next, *next_sym;
3444 rtx constant;
3445 enum machine_mode mode;
3446 int labelno;
3447 unsigned int align;
3448 HOST_WIDE_INT offset;
3449 int mark;
3452 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3453 The argument is XSTR (... , 0) */
3455 #define SYMHASH(LABEL) \
3456 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3458 /* Initialize constant pool hashing for a new function. */
3460 void
3461 init_varasm_status (f)
3462 struct function *f;
3464 struct varasm_status *p;
3465 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3466 f->varasm = p;
3467 p->x_const_rtx_hash_table
3468 = ((struct constant_descriptor **)
3469 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3470 p->x_const_rtx_sym_hash_table
3471 = ((struct pool_constant **)
3472 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3474 p->x_first_pool = p->x_last_pool = 0;
3475 p->x_pool_offset = 0;
3476 p->x_const_double_chain = 0;
3479 /* Mark PC for GC. */
3481 static void
3482 mark_pool_constant (pc)
3483 struct pool_constant *pc;
3485 while (pc)
3487 ggc_mark (pc);
3488 ggc_mark_rtx (pc->constant);
3489 ggc_mark_rtx (pc->desc->rtl);
3490 pc = pc->next;
3494 /* Mark P for GC. */
3496 void
3497 mark_varasm_status (p)
3498 struct varasm_status *p;
3500 if (p == NULL)
3501 return;
3503 mark_pool_constant (p->x_first_pool);
3504 ggc_mark_rtx (p->x_const_double_chain);
3507 /* Clear out all parts of the state in F that can safely be discarded
3508 after the function has been compiled, to let garbage collection
3509 reclaim the memory. */
3511 void
3512 free_varasm_status (f)
3513 struct function *f;
3515 struct varasm_status *p;
3516 int i;
3518 p = f->varasm;
3520 /* Clear out the hash tables. */
3521 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3523 struct constant_descriptor *cd;
3525 cd = p->x_const_rtx_hash_table[i];
3526 while (cd)
3528 struct constant_descriptor *next = cd->next;
3530 free (cd);
3531 cd = next;
3535 free (p->x_const_rtx_hash_table);
3536 free (p->x_const_rtx_sym_hash_table);
3537 free (p);
3539 f->varasm = NULL;
3543 /* Express an rtx for a constant integer (perhaps symbolic)
3544 as the sum of a symbol or label plus an explicit integer.
3545 They are stored into VALUE. */
3547 static void
3548 decode_rtx_const (mode, x, value)
3549 enum machine_mode mode;
3550 rtx x;
3551 struct rtx_const *value;
3553 /* Clear the whole structure, including any gaps. */
3554 memset (value, 0, sizeof (struct rtx_const));
3556 value->kind = RTX_INT; /* Most usual kind. */
3557 value->mode = mode;
3559 switch (GET_CODE (x))
3561 case CONST_DOUBLE:
3562 value->kind = RTX_DOUBLE;
3563 if (GET_MODE (x) != VOIDmode)
3565 value->mode = GET_MODE (x);
3566 memcpy ((char *) &value->un.du,
3567 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3569 else
3571 value->un.di.low = CONST_DOUBLE_LOW (x);
3572 value->un.di.high = CONST_DOUBLE_HIGH (x);
3574 break;
3576 case CONST_VECTOR:
3578 int units, i;
3579 rtx elt;
3581 units = CONST_VECTOR_NUNITS (x);
3582 value->kind = RTX_VECTOR;
3583 value->mode = mode;
3585 for (i = 0; i < units; ++i)
3587 elt = CONST_VECTOR_ELT (x, i);
3588 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
3590 value->un.veclo[i] = (HOST_WIDE_INT) INTVAL (elt);
3591 value->un.vechi[i] = 0;
3593 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3595 value->un.veclo[i] = (HOST_WIDE_INT) CONST_DOUBLE_LOW (elt);
3596 value->un.vechi[i] = (HOST_WIDE_INT) CONST_DOUBLE_HIGH (elt);
3598 else
3599 abort ();
3602 break;
3604 case CONST_INT:
3605 value->un.addr.offset = INTVAL (x);
3606 break;
3608 case SYMBOL_REF:
3609 case LABEL_REF:
3610 case PC:
3611 value->un.addr.base = x;
3612 break;
3614 case CONST:
3615 x = XEXP (x, 0);
3616 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3618 value->un.addr.base = XEXP (x, 0);
3619 value->un.addr.offset = INTVAL (XEXP (x, 1));
3621 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3623 value->un.addr.base = XEXP (x, 0);
3624 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3626 else
3628 value->un.addr.base = x;
3629 value->un.addr.offset = 0;
3631 break;
3633 default:
3634 value->kind = RTX_UNKNOWN;
3635 break;
3638 if (value->kind == RTX_INT && value->un.addr.base != 0
3639 && GET_CODE (value->un.addr.base) == UNSPEC)
3641 /* For a simple UNSPEC, the base is set to the
3642 operand, the kind field is set to the index of
3643 the unspec expression.
3644 Together with the code below, in case that
3645 the operand is a SYMBOL_REF or LABEL_REF,
3646 the address of the string or the code_label
3647 is taken as base. */
3648 if (XVECLEN (value->un.addr.base, 0) == 1)
3650 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
3651 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
3655 if (value->kind > RTX_DOUBLE && value->un.addr.base != 0)
3656 switch (GET_CODE (value->un.addr.base))
3658 case SYMBOL_REF:
3659 /* Use the string's address, not the SYMBOL_REF's address,
3660 for the sake of addresses of library routines. */
3661 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3662 break;
3664 case LABEL_REF:
3665 /* For a LABEL_REF, compare labels. */
3666 value->un.addr.base = XEXP (value->un.addr.base, 0);
3668 default:
3669 break;
3673 /* Given a MINUS expression, simplify it if both sides
3674 include the same symbol. */
3677 simplify_subtraction (x)
3678 rtx x;
3680 struct rtx_const val0, val1;
3682 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3683 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3685 if (val0.kind > RTX_DOUBLE
3686 && val0.kind == val1.kind
3687 && val0.un.addr.base == val1.un.addr.base)
3688 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3690 return x;
3693 /* Compute a hash code for a constant RTL expression. */
3695 static int
3696 const_hash_rtx (mode, x)
3697 enum machine_mode mode;
3698 rtx x;
3700 int hi;
3701 size_t i;
3703 struct rtx_const value;
3704 decode_rtx_const (mode, x, &value);
3706 /* Compute hashing function */
3707 hi = 0;
3708 for (i = 0; i < sizeof value / sizeof (int); i++)
3709 hi += ((int *) &value)[i];
3711 hi &= (1 << HASHBITS) - 1;
3712 hi %= MAX_RTX_HASH_TABLE;
3713 return hi;
3716 /* Compare a constant rtl object X with a constant-descriptor DESC.
3717 Return 1 if DESC describes a constant with the same value as X. */
3719 static int
3720 compare_constant_rtx (mode, x, desc)
3721 enum machine_mode mode;
3722 rtx x;
3723 struct constant_descriptor *desc;
3725 int *p = (int *) desc->u.contents;
3726 int *strp;
3727 int len;
3728 struct rtx_const value;
3730 decode_rtx_const (mode, x, &value);
3731 strp = (int *) &value;
3732 len = sizeof value / sizeof (int);
3734 /* Compare constant contents. */
3735 while (--len >= 0)
3736 if (*p++ != *strp++)
3737 return 0;
3739 return 1;
3742 /* Construct a constant descriptor for the rtl-expression X.
3743 It is up to the caller to enter the descriptor in the hash table. */
3745 static struct constant_descriptor *
3746 record_constant_rtx (mode, x)
3747 enum machine_mode mode;
3748 rtx x;
3750 struct constant_descriptor *ptr;
3752 ptr = ((struct constant_descriptor *)
3753 xcalloc (1, (offsetof (struct constant_descriptor, u)
3754 + sizeof (struct rtx_const))));
3755 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3757 return ptr;
3760 /* Given a constant rtx X, return a MEM for the location in memory at which
3761 this constant has been placed. Return 0 if it not has been placed yet. */
3764 mem_for_const_double (x)
3765 rtx x;
3767 enum machine_mode mode = GET_MODE (x);
3768 struct constant_descriptor *desc;
3770 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3771 desc = desc->next)
3772 if (compare_constant_rtx (mode, x, desc))
3773 return desc->rtl;
3775 return 0;
3778 /* Given a constant rtx X, make (or find) a memory constant for its value
3779 and return a MEM rtx to refer to it in memory. */
3782 force_const_mem (mode, x)
3783 enum machine_mode mode;
3784 rtx x;
3786 int hash;
3787 struct constant_descriptor *desc;
3788 char label[256];
3789 rtx def;
3790 struct pool_constant *pool;
3791 unsigned int align;
3793 /* Compute hash code of X. Search the descriptors for that hash code
3794 to see if any of them describes X. If yes, we have an rtx to use. */
3795 hash = const_hash_rtx (mode, x);
3796 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3797 if (compare_constant_rtx (mode, x, desc))
3798 return desc->rtl;
3800 /* No constant equal to X is known to have been output.
3801 Make a constant descriptor to enter X in the hash table
3802 and make a MEM for it. */
3803 desc = record_constant_rtx (mode, x);
3804 desc->next = const_rtx_hash_table[hash];
3805 const_rtx_hash_table[hash] = desc;
3807 /* Align the location counter as required by EXP's data type. */
3808 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3809 #ifdef CONSTANT_ALIGNMENT
3810 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x), align);
3811 #endif
3813 pool_offset += (align / BITS_PER_UNIT) - 1;
3814 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3816 if (GET_CODE (x) == LABEL_REF)
3817 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3819 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3820 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3821 pool->desc = desc;
3822 pool->constant = x;
3823 pool->mode = mode;
3824 pool->labelno = const_labelno;
3825 pool->align = align;
3826 pool->offset = pool_offset;
3827 pool->mark = 1;
3828 pool->next = 0;
3830 if (last_pool == 0)
3831 first_pool = pool;
3832 else
3833 last_pool->next = pool;
3835 last_pool = pool;
3836 pool_offset += GET_MODE_SIZE (mode);
3838 /* Create a string containing the label name, in LABEL. */
3839 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3841 ++const_labelno;
3843 /* Construct the SYMBOL_REF and the MEM. */
3845 pool->desc->rtl = def
3846 = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3847 set_mem_alias_set (def, const_alias_set);
3848 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3849 RTX_UNCHANGING_P (def) = 1;
3851 /* Add label to symbol hash table. */
3852 hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3853 pool->next_sym = const_rtx_sym_hash_table[hash];
3854 const_rtx_sym_hash_table[hash] = pool;
3856 /* Mark the symbol_ref as belonging to this constants pool. */
3857 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3858 current_function_uses_const_pool = 1;
3860 return def;
3863 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3864 the corresponding pool_constant structure. */
3866 static struct pool_constant *
3867 find_pool_constant (f, addr)
3868 struct function *f;
3869 rtx addr;
3871 struct pool_constant *pool;
3872 const char *label = XSTR (addr, 0);
3874 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3875 pool = pool->next_sym)
3876 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3877 return pool;
3879 abort ();
3882 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3885 get_pool_constant (addr)
3886 rtx addr;
3888 return (find_pool_constant (cfun, addr))->constant;
3891 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3892 and whether it has been output or not. */
3895 get_pool_constant_mark (addr, pmarked)
3896 rtx addr;
3897 bool *pmarked;
3899 struct pool_constant *pool = find_pool_constant (cfun, addr);
3900 *pmarked = (pool->mark != 0);
3901 return pool->constant;
3904 /* Likewise, but for the constant pool of a specific function. */
3907 get_pool_constant_for_function (f, addr)
3908 struct function *f;
3909 rtx addr;
3911 return (find_pool_constant (f, addr))->constant;
3914 /* Similar, return the mode. */
3916 enum machine_mode
3917 get_pool_mode (addr)
3918 rtx addr;
3920 return (find_pool_constant (cfun, addr))->mode;
3923 enum machine_mode
3924 get_pool_mode_for_function (f, addr)
3925 struct function *f;
3926 rtx addr;
3928 return (find_pool_constant (f, addr))->mode;
3931 /* Similar, return the offset in the constant pool. */
3934 get_pool_offset (addr)
3935 rtx addr;
3937 return (find_pool_constant (cfun, addr))->offset;
3940 /* Return the size of the constant pool. */
3943 get_pool_size ()
3945 return pool_offset;
3948 /* Write all the constants in the constant pool. */
3950 void
3951 output_constant_pool (fnname, fndecl)
3952 const char *fnname ATTRIBUTE_UNUSED;
3953 tree fndecl ATTRIBUTE_UNUSED;
3955 struct pool_constant *pool;
3956 rtx x;
3957 union real_extract u;
3959 /* It is possible for gcc to call force_const_mem and then to later
3960 discard the instructions which refer to the constant. In such a
3961 case we do not need to output the constant. */
3962 mark_constant_pool ();
3964 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3965 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3966 #endif
3968 for (pool = first_pool; pool; pool = pool->next)
3970 rtx tmp;
3972 x = pool->constant;
3974 if (! pool->mark)
3975 continue;
3977 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3978 whose CODE_LABEL has been deleted. This can occur if a jump table
3979 is eliminated by optimization. If so, write a constant of zero
3980 instead. Note that this can also happen by turning the
3981 CODE_LABEL into a NOTE. */
3982 /* ??? This seems completely and utterly wrong. Certainly it's
3983 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3984 functioning even with INSN_DELETED_P and friends. */
3986 tmp = x;
3987 switch (GET_CODE (x))
3989 case CONST:
3990 if (GET_CODE (XEXP (x, 0)) != PLUS
3991 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3992 break;
3993 tmp = XEXP (XEXP (x, 0), 0);
3994 /* FALLTHRU */
3996 case LABEL_REF:
3997 tmp = XEXP (x, 0);
3998 if (INSN_DELETED_P (tmp)
3999 || (GET_CODE (tmp) == NOTE
4000 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
4002 abort ();
4003 x = const0_rtx;
4005 break;
4007 default:
4008 break;
4011 /* First switch to correct section. */
4012 #ifdef SELECT_RTX_SECTION
4013 SELECT_RTX_SECTION (pool->mode, x, pool->align);
4014 #else
4015 readonly_data_section ();
4016 #endif
4018 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4019 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4020 pool->align, pool->labelno, done);
4021 #endif
4023 assemble_align (pool->align);
4025 /* Output the label. */
4026 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4028 /* Output the value of the constant itself. */
4029 switch (GET_MODE_CLASS (pool->mode))
4031 case MODE_FLOAT:
4032 if (GET_CODE (x) != CONST_DOUBLE)
4033 abort ();
4035 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4036 assemble_real (u.d, pool->mode, pool->align);
4037 break;
4039 case MODE_INT:
4040 case MODE_PARTIAL_INT:
4041 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4042 break;
4044 case MODE_VECTOR_FLOAT:
4046 int i, units;
4047 rtx elt;
4049 if (GET_CODE (x) != CONST_VECTOR)
4050 abort ();
4052 units = CONST_VECTOR_NUNITS (x);
4054 for (i = 0; i < units; i++)
4056 elt = CONST_VECTOR_ELT (x, i);
4057 memcpy ((char *) &u,
4058 (char *) &CONST_DOUBLE_LOW (elt),
4059 sizeof u);
4060 assemble_real (u.d, GET_MODE_INNER (pool->mode), pool->align);
4063 break;
4065 case MODE_VECTOR_INT:
4067 int i, units;
4068 rtx elt;
4070 if (GET_CODE (x) != CONST_VECTOR)
4071 abort ();
4073 units = CONST_VECTOR_NUNITS (x);
4075 for (i = 0; i < units; i++)
4077 elt = CONST_VECTOR_ELT (x, i);
4078 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
4079 pool->align, 1);
4082 break;
4084 default:
4085 abort ();
4088 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4089 done: ;
4090 #endif
4093 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4094 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4095 #endif
4097 /* Done with this pool. */
4098 first_pool = last_pool = 0;
4101 /* Look through the instructions for this function, and mark all the
4102 entries in the constant pool which are actually being used.
4103 Emit used deferred strings. */
4105 static void
4106 mark_constant_pool ()
4108 rtx insn;
4109 struct pool_constant *pool;
4111 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4112 return;
4114 for (pool = first_pool; pool; pool = pool->next)
4115 pool->mark = 0;
4117 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4118 if (INSN_P (insn))
4119 mark_constants (PATTERN (insn));
4121 for (insn = current_function_epilogue_delay_list;
4122 insn;
4123 insn = XEXP (insn, 1))
4124 if (INSN_P (insn))
4125 mark_constants (PATTERN (insn));
4128 /* Look through appropriate parts of X, marking all entries in the
4129 constant pool which are actually being used. Entries that are only
4130 referenced by other constants are also marked as used. Emit
4131 deferred strings that are used. */
4133 static void
4134 mark_constants (x)
4135 rtx x;
4137 int i;
4138 const char *format_ptr;
4140 if (x == 0)
4141 return;
4143 if (GET_CODE (x) == SYMBOL_REF)
4145 mark_constant (&x, NULL);
4146 return;
4149 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4150 insns, not any notes that may be attached. We don't want to mark
4151 a constant just because it happens to appear in a REG_EQUIV note. */
4152 if (INSN_P (x))
4154 mark_constants (PATTERN (x));
4155 return;
4158 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4160 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4162 switch (*format_ptr++)
4164 case 'e':
4165 mark_constants (XEXP (x, i));
4166 break;
4168 case 'E':
4169 if (XVEC (x, i) != 0)
4171 int j;
4173 for (j = 0; j < XVECLEN (x, i); j++)
4174 mark_constants (XVECEXP (x, i, j));
4176 break;
4178 case 'S':
4179 case 's':
4180 case '0':
4181 case 'i':
4182 case 'w':
4183 case 'n':
4184 case 'u':
4185 break;
4187 default:
4188 abort ();
4193 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4194 to as used. Emit referenced deferred strings. This function can
4195 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4197 static int
4198 mark_constant (current_rtx, data)
4199 rtx *current_rtx;
4200 void *data ATTRIBUTE_UNUSED;
4202 rtx x = *current_rtx;
4204 if (x == NULL_RTX)
4205 return 0;
4207 else if (GET_CODE (x) == SYMBOL_REF)
4209 if (CONSTANT_POOL_ADDRESS_P (x))
4211 struct pool_constant *pool = find_pool_constant (cfun, x);
4212 if (pool->mark == 0) {
4213 pool->mark = 1;
4214 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4216 else
4217 return -1;
4219 else if (STRING_POOL_ADDRESS_P (x))
4221 struct deferred_string **defstr;
4223 defstr = (struct deferred_string **)
4224 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4225 STRHASH (XSTR (x, 0)), NO_INSERT);
4226 if (defstr)
4228 struct deferred_string *p = *defstr;
4230 STRING_POOL_ADDRESS_P (x) = 0;
4231 output_constant_def_contents (p->exp, 0, p->labelno);
4232 htab_clear_slot (const_str_htab, (void **) defstr);
4236 return 0;
4239 /* Find all the constants whose addresses are referenced inside of EXP,
4240 and make sure assembler code with a label has been output for each one.
4241 Indicate whether an ADDR_EXPR has been encountered. */
4243 static int
4244 output_addressed_constants (exp)
4245 tree exp;
4247 int reloc = 0;
4248 tree tem;
4250 /* Give the front-end a chance to convert VALUE to something that
4251 looks more like a constant to the back-end. */
4252 exp = (*lang_hooks.expand_constant) (exp);
4254 switch (TREE_CODE (exp))
4256 case ADDR_EXPR:
4257 /* Go inside any operations that get_inner_reference can handle and see
4258 if what's inside is a constant: no need to do anything here for
4259 addresses of variables or functions. */
4260 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4261 tem = TREE_OPERAND (tem, 0))
4264 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4265 || TREE_CODE (tem) == CONSTRUCTOR)
4266 output_constant_def (tem, 0);
4268 if (TREE_PUBLIC (tem))
4269 reloc |= 2;
4270 else
4271 reloc |= 1;
4272 break;
4274 case PLUS_EXPR:
4275 case MINUS_EXPR:
4276 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4277 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4278 break;
4280 case NOP_EXPR:
4281 case CONVERT_EXPR:
4282 case NON_LVALUE_EXPR:
4283 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4284 break;
4286 case CONSTRUCTOR:
4287 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4288 if (TREE_VALUE (tem) != 0)
4289 reloc |= output_addressed_constants (TREE_VALUE (tem));
4291 break;
4293 default:
4294 break;
4296 return reloc;
4299 /* Return nonzero if VALUE is a valid constant-valued expression
4300 for use in initializing a static variable; one that can be an
4301 element of a "constant" initializer.
4303 Return null_pointer_node if the value is absolute;
4304 if it is relocatable, return the variable that determines the relocation.
4305 We assume that VALUE has been folded as much as possible;
4306 therefore, we do not need to check for such things as
4307 arithmetic-combinations of integers. */
4309 tree
4310 initializer_constant_valid_p (value, endtype)
4311 tree value;
4312 tree endtype;
4314 /* Give the front-end a chance to convert VALUE to something that
4315 looks more like a constant to the back-end. */
4316 value = (*lang_hooks.expand_constant) (value);
4318 switch (TREE_CODE (value))
4320 case CONSTRUCTOR:
4321 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4322 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4323 && TREE_CONSTANT (value)
4324 && CONSTRUCTOR_ELTS (value))
4325 return
4326 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4327 endtype);
4329 return TREE_STATIC (value) ? null_pointer_node : 0;
4331 case INTEGER_CST:
4332 case VECTOR_CST:
4333 case REAL_CST:
4334 case STRING_CST:
4335 case COMPLEX_CST:
4336 return null_pointer_node;
4338 case ADDR_EXPR:
4339 case FDESC_EXPR:
4340 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4342 case VIEW_CONVERT_EXPR:
4343 case NON_LVALUE_EXPR:
4344 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4346 case CONVERT_EXPR:
4347 case NOP_EXPR:
4348 /* Allow conversions between pointer types. */
4349 if (POINTER_TYPE_P (TREE_TYPE (value))
4350 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4351 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4353 /* Allow conversions between real types. */
4354 if (FLOAT_TYPE_P (TREE_TYPE (value))
4355 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4356 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4358 /* Allow length-preserving conversions between integer types. */
4359 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4360 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4361 && (TYPE_PRECISION (TREE_TYPE (value))
4362 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4363 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4365 /* Allow conversions between other integer types only if
4366 explicit value. */
4367 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4368 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4370 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4371 endtype);
4372 if (inner == null_pointer_node)
4373 return null_pointer_node;
4374 break;
4377 /* Allow (int) &foo provided int is as wide as a pointer. */
4378 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4379 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4380 && (TYPE_PRECISION (TREE_TYPE (value))
4381 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4382 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4383 endtype);
4385 /* Likewise conversions from int to pointers, but also allow
4386 conversions from 0. */
4387 if (POINTER_TYPE_P (TREE_TYPE (value))
4388 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4390 if (integer_zerop (TREE_OPERAND (value, 0)))
4391 return null_pointer_node;
4392 else if (TYPE_PRECISION (TREE_TYPE (value))
4393 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4394 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4395 endtype);
4398 /* Allow conversions to union types if the value inside is okay. */
4399 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4400 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4401 endtype);
4402 break;
4404 case PLUS_EXPR:
4405 if (! INTEGRAL_TYPE_P (endtype)
4406 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4408 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4409 endtype);
4410 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4411 endtype);
4412 /* If either term is absolute, use the other terms relocation. */
4413 if (valid0 == null_pointer_node)
4414 return valid1;
4415 if (valid1 == null_pointer_node)
4416 return valid0;
4418 break;
4420 case MINUS_EXPR:
4421 if (! INTEGRAL_TYPE_P (endtype)
4422 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4424 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4425 endtype);
4426 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4427 endtype);
4428 /* Win if second argument is absolute. */
4429 if (valid1 == null_pointer_node)
4430 return valid0;
4431 /* Win if both arguments have the same relocation.
4432 Then the value is absolute. */
4433 if (valid0 == valid1 && valid0 != 0)
4434 return null_pointer_node;
4436 /* Since GCC guarantees that string constants are unique in the
4437 generated code, a subtraction between two copies of the same
4438 constant string is absolute. */
4439 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4440 valid1 && TREE_CODE (valid1) == STRING_CST &&
4441 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4442 return null_pointer_node;
4445 /* Support differences between labels. */
4446 if (INTEGRAL_TYPE_P (endtype))
4448 tree op0, op1;
4449 op0 = TREE_OPERAND (value, 0);
4450 op1 = TREE_OPERAND (value, 1);
4452 /* Like STRIP_NOPS except allow the operand mode to widen.
4453 This works around a feature of fold that simplfies
4454 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4455 that the narrower operation is cheaper. */
4457 while (TREE_CODE (op0) == NOP_EXPR
4458 || TREE_CODE (op0) == CONVERT_EXPR
4459 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4461 tree inner = TREE_OPERAND (op0, 0);
4462 if (inner == error_mark_node
4463 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4464 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4465 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4466 break;
4467 op0 = inner;
4470 while (TREE_CODE (op1) == NOP_EXPR
4471 || TREE_CODE (op1) == CONVERT_EXPR
4472 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4474 tree inner = TREE_OPERAND (op1, 0);
4475 if (inner == error_mark_node
4476 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4477 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4478 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4479 break;
4480 op1 = inner;
4483 if (TREE_CODE (op0) == ADDR_EXPR
4484 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4485 && TREE_CODE (op1) == ADDR_EXPR
4486 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4487 return null_pointer_node;
4489 break;
4491 default:
4492 break;
4495 return 0;
4498 /* Output assembler code for constant EXP to FILE, with no label.
4499 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4500 Assumes output_addressed_constants has been done on EXP already.
4502 Generate exactly SIZE bytes of assembler data, padding at the end
4503 with zeros if necessary. SIZE must always be specified.
4505 SIZE is important for structure constructors,
4506 since trailing members may have been omitted from the constructor.
4507 It is also important for initialization of arrays from string constants
4508 since the full length of the string constant might not be wanted.
4509 It is also needed for initialization of unions, where the initializer's
4510 type is just one member, and that may not be as long as the union.
4512 There a case in which we would fail to output exactly SIZE bytes:
4513 for a structure constructor that wants to produce more than SIZE bytes.
4514 But such constructors will never be generated for any possible input.
4516 ALIGN is the alignment of the data in bits. */
4518 void
4519 output_constant (exp, size, align)
4520 tree exp;
4521 HOST_WIDE_INT size;
4522 unsigned int align;
4524 enum tree_code code;
4525 HOST_WIDE_INT thissize;
4527 /* Some front-ends use constants other than the standard language-indepdent
4528 varieties, but which may still be output directly. Give the front-end a
4529 chance to convert EXP to a language-independent representation. */
4530 exp = (*lang_hooks.expand_constant) (exp);
4532 if (size == 0 || flag_syntax_only)
4533 return;
4535 /* Eliminate any conversions since we'll be outputting the underlying
4536 constant. */
4537 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4538 || TREE_CODE (exp) == NON_LVALUE_EXPR
4539 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4540 exp = TREE_OPERAND (exp, 0);
4542 code = TREE_CODE (TREE_TYPE (exp));
4543 thissize = int_size_in_bytes (TREE_TYPE (exp));
4545 /* Allow a constructor with no elements for any data type.
4546 This means to fill the space with zeros. */
4547 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4549 assemble_zeros (size);
4550 return;
4553 if (TREE_CODE (exp) == FDESC_EXPR)
4555 #ifdef ASM_OUTPUT_FDESC
4556 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4557 tree decl = TREE_OPERAND (exp, 0);
4558 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4559 #else
4560 abort ();
4561 #endif
4562 return;
4565 /* Now output the underlying data. If we've handling the padding, return.
4566 Otherwise, break and ensure THISSIZE is the size written. */
4567 switch (code)
4569 case CHAR_TYPE:
4570 case BOOLEAN_TYPE:
4571 case INTEGER_TYPE:
4572 case ENUMERAL_TYPE:
4573 case POINTER_TYPE:
4574 case REFERENCE_TYPE:
4575 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4576 EXPAND_INITIALIZER),
4577 size, align, 0))
4578 error ("initializer for integer value is too complicated");
4579 break;
4581 case REAL_TYPE:
4582 if (TREE_CODE (exp) != REAL_CST)
4583 error ("initializer for floating value is not a floating constant");
4585 assemble_real (TREE_REAL_CST (exp),
4586 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4587 align);
4588 break;
4590 case COMPLEX_TYPE:
4591 output_constant (TREE_REALPART (exp), thissize / 2, align);
4592 output_constant (TREE_IMAGPART (exp), thissize / 2,
4593 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4594 break;
4596 case ARRAY_TYPE:
4597 case VECTOR_TYPE:
4598 if (TREE_CODE (exp) == CONSTRUCTOR)
4600 output_constructor (exp, size, align);
4601 return;
4603 else if (TREE_CODE (exp) == STRING_CST)
4605 thissize = MIN (TREE_STRING_LENGTH (exp), size);
4606 assemble_string (TREE_STRING_POINTER (exp), thissize);
4608 else
4609 abort ();
4610 break;
4612 case RECORD_TYPE:
4613 case UNION_TYPE:
4614 if (TREE_CODE (exp) == CONSTRUCTOR)
4615 output_constructor (exp, size, align);
4616 else
4617 abort ();
4618 return;
4620 case SET_TYPE:
4621 if (TREE_CODE (exp) == INTEGER_CST)
4622 assemble_integer (expand_expr (exp, NULL_RTX,
4623 VOIDmode, EXPAND_INITIALIZER),
4624 thissize, align, 1);
4625 else if (TREE_CODE (exp) == CONSTRUCTOR)
4627 unsigned char *buffer = (unsigned char *) alloca (thissize);
4628 if (get_set_constructor_bytes (exp, buffer, thissize))
4629 abort ();
4630 assemble_string ((char *) buffer, thissize);
4632 else
4633 error ("unknown set constructor type");
4634 return;
4636 case ERROR_MARK:
4637 return;
4639 default:
4640 abort ();
4643 size -= thissize;
4644 if (size > 0)
4645 assemble_zeros (size);
4649 /* Subroutine of output_constructor, used for computing the size of
4650 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4651 type with an unspecified upper bound. */
4653 static unsigned HOST_WIDE_INT
4654 array_size_for_constructor (val)
4655 tree val;
4657 tree max_index, i;
4659 /* This code used to attempt to handle string constants that are not
4660 arrays of single-bytes, but nothing else does, so there's no point in
4661 doing it here. */
4662 if (TREE_CODE (val) == STRING_CST)
4663 return TREE_STRING_LENGTH (val);
4665 max_index = NULL_TREE;
4666 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4668 tree index = TREE_PURPOSE (i);
4670 if (TREE_CODE (index) == RANGE_EXPR)
4671 index = TREE_OPERAND (index, 1);
4672 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4673 max_index = index;
4676 if (max_index == NULL_TREE)
4677 return 0;
4679 /* Compute the total number of array elements. */
4680 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4681 convert (sizetype,
4682 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4683 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4685 /* Multiply by the array element unit size to find number of bytes. */
4686 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4688 return tree_low_cst (i, 1);
4691 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4692 Generate at least SIZE bytes, padding if necessary. */
4694 static void
4695 output_constructor (exp, size, align)
4696 tree exp;
4697 HOST_WIDE_INT size;
4698 unsigned int align;
4700 tree type = TREE_TYPE (exp);
4701 tree link, field = 0;
4702 tree min_index = 0;
4703 /* Number of bytes output or skipped so far.
4704 In other words, current position within the constructor. */
4705 HOST_WIDE_INT total_bytes = 0;
4706 /* Non-zero means BYTE contains part of a byte, to be output. */
4707 int byte_buffer_in_use = 0;
4708 int byte = 0;
4710 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4711 abort ();
4713 if (TREE_CODE (type) == RECORD_TYPE)
4714 field = TYPE_FIELDS (type);
4716 if (TREE_CODE (type) == ARRAY_TYPE
4717 && TYPE_DOMAIN (type) != 0)
4718 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4720 /* As LINK goes through the elements of the constant,
4721 FIELD goes through the structure fields, if the constant is a structure.
4722 if the constant is a union, then we override this,
4723 by getting the field from the TREE_LIST element.
4724 But the constant could also be an array. Then FIELD is zero.
4726 There is always a maximum of one element in the chain LINK for unions
4727 (even if the initializer in a source program incorrectly contains
4728 more one). */
4729 for (link = CONSTRUCTOR_ELTS (exp);
4730 link;
4731 link = TREE_CHAIN (link),
4732 field = field ? TREE_CHAIN (field) : 0)
4734 tree val = TREE_VALUE (link);
4735 tree index = 0;
4737 /* The element in a union constructor specifies the proper field
4738 or index. */
4739 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4740 || TREE_CODE (type) == QUAL_UNION_TYPE)
4741 && TREE_PURPOSE (link) != 0)
4742 field = TREE_PURPOSE (link);
4744 else if (TREE_CODE (type) == ARRAY_TYPE)
4745 index = TREE_PURPOSE (link);
4747 /* Eliminate the marker that makes a cast not be an lvalue. */
4748 if (val != 0)
4749 STRIP_NOPS (val);
4751 if (index && TREE_CODE (index) == RANGE_EXPR)
4753 unsigned HOST_WIDE_INT fieldsize
4754 = int_size_in_bytes (TREE_TYPE (type));
4755 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4756 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4757 HOST_WIDE_INT index;
4758 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4760 for (index = lo_index; index <= hi_index; index++)
4762 /* Output the element's initial value. */
4763 if (val == 0)
4764 assemble_zeros (fieldsize);
4765 else
4766 output_constant (val, fieldsize, align2);
4768 /* Count its size. */
4769 total_bytes += fieldsize;
4772 else if (field == 0 || !DECL_BIT_FIELD (field))
4774 /* An element that is not a bit-field. */
4776 unsigned HOST_WIDE_INT fieldsize;
4777 /* Since this structure is static,
4778 we know the positions are constant. */
4779 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4780 unsigned int align2;
4782 if (index != 0)
4783 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4784 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4786 /* Output any buffered-up bit-fields preceding this element. */
4787 if (byte_buffer_in_use)
4789 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4790 total_bytes++;
4791 byte_buffer_in_use = 0;
4794 /* Advance to offset of this element.
4795 Note no alignment needed in an array, since that is guaranteed
4796 if each element has the proper size. */
4797 if ((field != 0 || index != 0) && pos != total_bytes)
4799 assemble_zeros (pos - total_bytes);
4800 total_bytes = pos;
4803 /* Find the alignment of this element. */
4804 align2 = min_align (align, BITS_PER_UNIT * pos);
4806 /* Determine size this element should occupy. */
4807 if (field)
4809 fieldsize = 0;
4811 /* If this is an array with an unspecified upper bound,
4812 the initializer determines the size. */
4813 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4814 but we cannot do this until the deprecated support for
4815 initializing zero-length array members is removed. */
4816 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4817 && TYPE_DOMAIN (TREE_TYPE (field))
4818 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4820 fieldsize = array_size_for_constructor (val);
4821 /* Given a non-empty initialization, this field had
4822 better be last. */
4823 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4824 abort ();
4826 else if (DECL_SIZE_UNIT (field))
4828 /* ??? This can't be right. If the decl size overflows
4829 a host integer we will silently emit no data. */
4830 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4831 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4834 else
4835 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4837 /* Output the element's initial value. */
4838 if (val == 0)
4839 assemble_zeros (fieldsize);
4840 else
4841 output_constant (val, fieldsize, align2);
4843 /* Count its size. */
4844 total_bytes += fieldsize;
4846 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4847 error ("invalid initial value for member `%s'",
4848 IDENTIFIER_POINTER (DECL_NAME (field)));
4849 else
4851 /* Element that is a bit-field. */
4853 HOST_WIDE_INT next_offset = int_bit_position (field);
4854 HOST_WIDE_INT end_offset
4855 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4857 if (val == 0)
4858 val = integer_zero_node;
4860 /* If this field does not start in this (or, next) byte,
4861 skip some bytes. */
4862 if (next_offset / BITS_PER_UNIT != total_bytes)
4864 /* Output remnant of any bit field in previous bytes. */
4865 if (byte_buffer_in_use)
4867 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4868 total_bytes++;
4869 byte_buffer_in_use = 0;
4872 /* If still not at proper byte, advance to there. */
4873 if (next_offset / BITS_PER_UNIT != total_bytes)
4875 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4876 total_bytes = next_offset / BITS_PER_UNIT;
4880 if (! byte_buffer_in_use)
4881 byte = 0;
4883 /* We must split the element into pieces that fall within
4884 separate bytes, and combine each byte with previous or
4885 following bit-fields. */
4887 /* next_offset is the offset n fbits from the beginning of
4888 the structure to the next bit of this element to be processed.
4889 end_offset is the offset of the first bit past the end of
4890 this element. */
4891 while (next_offset < end_offset)
4893 int this_time;
4894 int shift;
4895 HOST_WIDE_INT value;
4896 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4897 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4899 /* Advance from byte to byte
4900 within this element when necessary. */
4901 while (next_byte != total_bytes)
4903 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4904 total_bytes++;
4905 byte = 0;
4908 /* Number of bits we can process at once
4909 (all part of the same byte). */
4910 this_time = MIN (end_offset - next_offset,
4911 BITS_PER_UNIT - next_bit);
4912 if (BYTES_BIG_ENDIAN)
4914 /* On big-endian machine, take the most significant bits
4915 first (of the bits that are significant)
4916 and put them into bytes from the most significant end. */
4917 shift = end_offset - next_offset - this_time;
4919 /* Don't try to take a bunch of bits that cross
4920 the word boundary in the INTEGER_CST. We can
4921 only select bits from the LOW or HIGH part
4922 not from both. */
4923 if (shift < HOST_BITS_PER_WIDE_INT
4924 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4926 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4927 shift = HOST_BITS_PER_WIDE_INT;
4930 /* Now get the bits from the appropriate constant word. */
4931 if (shift < HOST_BITS_PER_WIDE_INT)
4932 value = TREE_INT_CST_LOW (val);
4933 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4935 value = TREE_INT_CST_HIGH (val);
4936 shift -= HOST_BITS_PER_WIDE_INT;
4938 else
4939 abort ();
4941 /* Get the result. This works only when:
4942 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4943 byte |= (((value >> shift)
4944 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4945 << (BITS_PER_UNIT - this_time - next_bit));
4947 else
4949 /* On little-endian machines,
4950 take first the least significant bits of the value
4951 and pack them starting at the least significant
4952 bits of the bytes. */
4953 shift = next_offset - int_bit_position (field);
4955 /* Don't try to take a bunch of bits that cross
4956 the word boundary in the INTEGER_CST. We can
4957 only select bits from the LOW or HIGH part
4958 not from both. */
4959 if (shift < HOST_BITS_PER_WIDE_INT
4960 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4961 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4963 /* Now get the bits from the appropriate constant word. */
4964 if (shift < HOST_BITS_PER_WIDE_INT)
4965 value = TREE_INT_CST_LOW (val);
4966 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4968 value = TREE_INT_CST_HIGH (val);
4969 shift -= HOST_BITS_PER_WIDE_INT;
4971 else
4972 abort ();
4974 /* Get the result. This works only when:
4975 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4976 byte |= (((value >> shift)
4977 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4978 << next_bit);
4981 next_offset += this_time;
4982 byte_buffer_in_use = 1;
4987 if (byte_buffer_in_use)
4989 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4990 total_bytes++;
4993 if (total_bytes < size)
4994 assemble_zeros (size - total_bytes);
4998 /* This structure contains any weak symbol declarations waiting
4999 to be emitted. */
5000 struct weak_syms
5002 struct weak_syms * next;
5003 tree decl;
5004 const char * name;
5005 const char * value;
5008 static struct weak_syms * weak_decls;
5010 /* Mark weak_decls for garbage collection. */
5012 static void
5013 mark_weak_decls (arg)
5014 void *arg;
5016 struct weak_syms *t;
5018 for (t = *(struct weak_syms **) arg; t != NULL; t = t->next)
5019 ggc_mark_tree (t->decl);
5022 /* Add function NAME to the weak symbols list. VALUE is a weak alias
5023 associated with NAME. */
5026 add_weak (decl, name, value)
5027 tree decl;
5028 const char *name;
5029 const char *value;
5031 struct weak_syms *weak;
5033 weak = (struct weak_syms *) xmalloc (sizeof (struct weak_syms));
5035 if (weak == NULL)
5036 return 0;
5038 weak->next = weak_decls;
5039 weak->decl = decl;
5040 weak->name = name;
5041 weak->value = value;
5042 weak_decls = weak;
5044 return 1;
5047 /* Declare DECL to be a weak symbol. */
5049 void
5050 declare_weak (decl)
5051 tree decl;
5053 if (! TREE_PUBLIC (decl))
5054 error_with_decl (decl, "weak declaration of `%s' must be public");
5055 else if (TREE_ASM_WRITTEN (decl))
5056 error_with_decl (decl, "weak declaration of `%s' must precede definition");
5057 else if (SUPPORTS_WEAK)
5058 add_weak (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
5059 else
5060 warning_with_decl (decl, "weak declaration of `%s' not supported");
5062 DECL_WEAK (decl) = 1;
5065 /* Emit any pending weak declarations. */
5067 void
5068 weak_finish ()
5070 if (SUPPORTS_WEAK)
5072 struct weak_syms *t;
5073 for (t = weak_decls; t != NULL; t = t->next)
5075 #ifdef ASM_WEAKEN_DECL
5076 tree decl = t->decl;
5077 if (decl == NULL_TREE)
5079 tree name = get_identifier (t->name);
5080 if (name)
5081 decl = lookup_name (name);
5083 ASM_WEAKEN_DECL (asm_out_file, decl, t->name, t->value);
5084 #else
5085 #ifdef ASM_OUTPUT_WEAK_ALIAS
5086 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
5087 #else
5088 #ifdef ASM_WEAKEN_LABEL
5089 if (t->value)
5090 abort ();
5091 ASM_WEAKEN_LABEL (asm_out_file, t->name);
5092 #endif
5093 #endif
5094 #endif
5099 /* Remove NAME from the pending list of weak symbols. This prevents
5100 the compiler from emitting multiple .weak directives which confuses
5101 some assemblers. */
5102 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5103 static void
5104 remove_from_pending_weak_list (name)
5105 const char *name;
5107 struct weak_syms *t;
5108 struct weak_syms **p;
5110 for (p = &weak_decls; *p; )
5112 t = *p;
5113 if (strcmp (name, t->name) == 0)
5115 *p = t->next;
5116 free (t);
5118 else
5119 p = &(t->next);
5122 #endif /* defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL) */
5124 /* Emit the assembly bits to indicate that DECL is globally visible. */
5126 static void
5127 globalize_decl (decl)
5128 tree decl;
5130 const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5132 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5133 if (DECL_WEAK (decl))
5135 #ifdef ASM_WEAKEN_DECL
5136 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5137 #else
5138 ASM_WEAKEN_LABEL (asm_out_file, name);
5139 #endif
5140 /* Remove this function from the pending weak list so that
5141 we do not emit multiple .weak directives for it. */
5142 remove_from_pending_weak_list (name);
5143 return;
5145 /* else */
5146 #endif
5147 ASM_GLOBALIZE_LABEL (asm_out_file, name);
5150 /* Emit an assembler directive to make the symbol for DECL an alias to
5151 the symbol for TARGET. */
5153 void
5154 assemble_alias (decl, target)
5155 tree decl, target ATTRIBUTE_UNUSED;
5157 const char *name;
5159 /* We must force creation of DECL_RTL for debug info generation, even though
5160 we don't use it here. */
5161 make_decl_rtl (decl, NULL);
5163 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5165 #ifdef ASM_OUTPUT_DEF
5166 /* Make name accessible from other files, if appropriate. */
5168 if (TREE_PUBLIC (decl))
5170 globalize_decl (decl);
5172 maybe_assemble_visibility (decl);
5175 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5176 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5177 #else
5178 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5179 #endif
5180 TREE_ASM_WRITTEN (decl) = 1;
5181 #else /* !ASM_OUTPUT_DEF */
5182 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5183 if (! DECL_WEAK (decl))
5184 warning ("only weak aliases are supported in this configuration");
5186 #ifdef ASM_WEAKEN_DECL
5187 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5188 #else
5189 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5190 #endif
5191 TREE_ASM_WRITTEN (decl) = 1;
5192 #else
5193 warning ("alias definitions not supported in this configuration; ignored");
5194 #endif
5195 #endif
5198 /* Emit an assembler directive to set symbol for DECL visibility to
5199 VISIBILITY_TYPE. */
5201 void
5202 assemble_visibility (decl, visibility_type)
5203 tree decl;
5204 const char *visibility_type ATTRIBUTE_UNUSED;
5206 const char *name;
5208 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5210 #ifdef HAVE_GAS_HIDDEN
5211 fprintf (asm_out_file, "\t.%s\t%s\n", visibility_type, name);
5212 #else
5213 warning ("visibility attribute not supported in this configuration; ignored");
5214 #endif
5217 /* A helper function to call assemble_visibility when needed for a decl. */
5219 static void
5220 maybe_assemble_visibility (decl)
5221 tree decl;
5223 tree visibility = lookup_attribute ("visibility", DECL_ATTRIBUTES (decl));
5224 if (visibility)
5226 const char *type
5227 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility)));
5228 assemble_visibility (decl, type);
5232 /* Returns 1 if the target configuration supports defining public symbols
5233 so that one of them will be chosen at link time instead of generating a
5234 multiply-defined symbol error, whether through the use of weak symbols or
5235 a target-specific mechanism for having duplicates discarded. */
5238 supports_one_only ()
5240 if (SUPPORTS_ONE_ONLY)
5241 return 1;
5242 return SUPPORTS_WEAK;
5245 /* Set up DECL as a public symbol that can be defined in multiple
5246 translation units without generating a linker error. */
5248 void
5249 make_decl_one_only (decl)
5250 tree decl;
5252 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5253 abort ();
5255 TREE_PUBLIC (decl) = 1;
5257 if (TREE_CODE (decl) == VAR_DECL
5258 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5259 DECL_COMMON (decl) = 1;
5260 else if (SUPPORTS_ONE_ONLY)
5262 #ifdef MAKE_DECL_ONE_ONLY
5263 MAKE_DECL_ONE_ONLY (decl);
5264 #endif
5265 DECL_ONE_ONLY (decl) = 1;
5267 else if (SUPPORTS_WEAK)
5268 DECL_WEAK (decl) = 1;
5269 else
5270 abort ();
5273 void
5274 init_varasm_once ()
5276 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5277 const_str_htab_del);
5278 in_named_htab = htab_create (31, in_named_entry_hash,
5279 in_named_entry_eq, NULL);
5281 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5282 mark_const_hash_entry);
5283 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5284 mark_const_str_htab);
5285 ggc_add_root (&weak_decls, 1, sizeof weak_decls, mark_weak_decls);
5287 const_alias_set = new_alias_set ();
5290 /* Select a set of attributes for section NAME based on the properties
5291 of DECL and whether or not RELOC indicates that DECL's initializer
5292 might contain runtime relocations.
5294 We make the section read-only and executable for a function decl,
5295 read-only for a const data decl, and writable for a non-const data decl. */
5297 unsigned int
5298 default_section_type_flags (decl, name, reloc)
5299 tree decl;
5300 const char *name;
5301 int reloc;
5303 unsigned int flags;
5305 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5306 flags = SECTION_CODE;
5307 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5308 flags = 0;
5309 else
5310 flags = SECTION_WRITE;
5312 if (decl && DECL_ONE_ONLY (decl))
5313 flags |= SECTION_LINKONCE;
5315 if (strcmp (name, ".bss") == 0
5316 || strncmp (name, ".bss.", 5) == 0
5317 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5318 || strcmp (name, ".sbss") == 0
5319 || strncmp (name, ".sbss.", 6) == 0
5320 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5321 flags |= SECTION_BSS;
5323 return flags;
5326 /* Output assembly to switch to section NAME with attribute FLAGS.
5327 Four variants for common object file formats. */
5329 void
5330 default_no_named_section (name, flags)
5331 const char *name ATTRIBUTE_UNUSED;
5332 unsigned int flags ATTRIBUTE_UNUSED;
5334 /* Some object formats don't support named sections at all. The
5335 front-end should already have flagged this as an error. */
5336 abort ();
5339 void
5340 default_elf_asm_named_section (name, flags)
5341 const char *name;
5342 unsigned int flags;
5344 char flagchars[10], *f = flagchars;
5345 const char *type;
5347 if (! named_section_first_declaration (name))
5349 fprintf (asm_out_file, "\t.section\t%s\n", name);
5350 return;
5353 if (!(flags & SECTION_DEBUG))
5354 *f++ = 'a';
5355 if (flags & SECTION_WRITE)
5356 *f++ = 'w';
5357 if (flags & SECTION_CODE)
5358 *f++ = 'x';
5359 if (flags & SECTION_SMALL)
5360 *f++ = 's';
5361 if (flags & SECTION_MERGE)
5362 *f++ = 'M';
5363 if (flags & SECTION_STRINGS)
5364 *f++ = 'S';
5365 *f = '\0';
5367 if (flags & SECTION_BSS)
5368 type = "nobits";
5369 else
5370 type = "progbits";
5372 if (flags & SECTION_ENTSIZE)
5373 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5374 name, flagchars, type, flags & SECTION_ENTSIZE);
5375 else
5376 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5377 name, flagchars, type);
5380 void
5381 default_coff_asm_named_section (name, flags)
5382 const char *name;
5383 unsigned int flags;
5385 char flagchars[8], *f = flagchars;
5387 if (flags & SECTION_WRITE)
5388 *f++ = 'w';
5389 if (flags & SECTION_CODE)
5390 *f++ = 'x';
5391 *f = '\0';
5393 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5396 void
5397 default_pe_asm_named_section (name, flags)
5398 const char *name;
5399 unsigned int flags;
5401 default_coff_asm_named_section (name, flags);
5403 if (flags & SECTION_LINKONCE)
5405 /* Functions may have been compiled at various levels of
5406 optimization so we can't use `same_size' here.
5407 Instead, have the linker pick one. */
5408 fprintf (asm_out_file, "\t.linkonce %s\n",
5409 (flags & SECTION_CODE ? "discard" : "same_size"));
5413 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5414 from SYMBOL is used in all classes derived from SYMBOL. */
5416 void
5417 assemble_vtable_entry (symbol, offset)
5418 rtx symbol;
5419 HOST_WIDE_INT offset;
5421 fputs ("\t.vtable_entry ", asm_out_file);
5422 output_addr_const (asm_out_file, symbol);
5423 fputs (", ", asm_out_file);
5424 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5425 fputc ('\n', asm_out_file);
5428 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5429 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5431 void
5432 assemble_vtable_inherit (child, parent)
5433 rtx child, parent;
5435 fputs ("\t.vtable_inherit ", asm_out_file);
5436 output_addr_const (asm_out_file, child);
5437 fputs (", ", asm_out_file);
5438 output_addr_const (asm_out_file, parent);
5439 fputc ('\n', asm_out_file);