* config/mips/mips.h (SUBTARGET_CPP_SIZE_SPEC): Remove duplicate
[official-gcc.git] / gcc / varasm.c
blob187429eb5120cc1d92ce0a1d024e098d25fb0e6f
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 maybe_assemble_visibility PARAMS ((tree));
175 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
176 static hashval_t in_named_entry_hash PARAMS ((const PTR));
177 #ifdef ASM_OUTPUT_BSS
178 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
179 #endif
180 #ifdef BSS_SECTION_ASM_OP
181 #ifdef ASM_OUTPUT_ALIGNED_BSS
182 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
183 int, int));
184 #endif
185 #endif /* BSS_SECTION_ASM_OP */
186 static void mark_pool_constant PARAMS ((struct pool_constant *));
187 static void mark_const_hash_entry PARAMS ((void *));
188 static int mark_const_str_htab_1 PARAMS ((void **, void *));
189 static void mark_const_str_htab PARAMS ((void *));
190 static hashval_t const_str_htab_hash PARAMS ((const void *x));
191 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
192 static void const_str_htab_del PARAMS ((void *));
193 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
194 static void resolve_unique_section PARAMS ((tree, int));
196 static enum in_section { no_section, in_text, in_data, in_named
197 #ifdef BSS_SECTION_ASM_OP
198 , in_bss
199 #endif
200 #ifdef CTORS_SECTION_ASM_OP
201 , in_ctors
202 #endif
203 #ifdef DTORS_SECTION_ASM_OP
204 , in_dtors
205 #endif
206 #ifdef EXTRA_SECTIONS
207 , EXTRA_SECTIONS
208 #endif
209 } in_section = no_section;
211 /* Return a non-zero value if DECL has a section attribute. */
212 #ifndef IN_NAMED_SECTION
213 #define IN_NAMED_SECTION(DECL) \
214 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
215 && DECL_SECTION_NAME (DECL) != NULL_TREE)
216 #endif
218 /* Text of section name when in_section == in_named. */
219 static const char *in_named_name;
221 /* Hash table of flags that have been used for a particular named section. */
223 struct in_named_entry
225 const char *name;
226 unsigned int flags;
227 bool declared;
230 static htab_t in_named_htab;
232 /* Define functions like text_section for any extra sections. */
233 #ifdef EXTRA_SECTION_FUNCTIONS
234 EXTRA_SECTION_FUNCTIONS
235 #endif
237 /* Tell assembler to switch to text section. */
239 void
240 text_section ()
242 if (in_section != in_text)
244 #ifdef TEXT_SECTION
245 TEXT_SECTION ();
246 #else
247 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
248 #endif
249 in_section = in_text;
253 /* Tell assembler to switch to data section. */
255 void
256 data_section ()
258 if (in_section != in_data)
260 if (flag_shared_data)
262 #ifdef SHARED_SECTION_ASM_OP
263 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
264 #else
265 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
266 #endif
268 else
269 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
271 in_section = in_data;
274 /* Tell assembler to ALWAYS switch to data section, in case
275 it's not sure where it is. */
277 void
278 force_data_section ()
280 in_section = no_section;
281 data_section ();
284 /* Tell assembler to switch to read-only data section. This is normally
285 the text section. */
287 void
288 readonly_data_section ()
290 #ifdef READONLY_DATA_SECTION
291 READONLY_DATA_SECTION (); /* Note this can call data_section. */
292 #else
293 text_section ();
294 #endif
297 /* Determine if we're in the text section. */
300 in_text_section ()
302 return in_section == in_text;
305 /* Determine if we're in the data section. */
308 in_data_section ()
310 return in_section == in_data;
313 /* Helper routines for maintaining in_named_htab. */
315 static int
316 in_named_entry_eq (p1, p2)
317 const PTR p1;
318 const PTR p2;
320 const struct in_named_entry *old = p1;
321 const char *new = p2;
323 return strcmp (old->name, new) == 0;
326 static hashval_t
327 in_named_entry_hash (p)
328 const PTR p;
330 const struct in_named_entry *old = p;
331 return htab_hash_string (old->name);
334 /* If SECTION has been seen before as a named section, return the flags
335 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
336 set of flags for a section to have, so 0 does not mean that the section
337 has not been seen. */
339 unsigned int
340 get_named_section_flags (section)
341 const char *section;
343 struct in_named_entry **slot;
345 slot = (struct in_named_entry**)
346 htab_find_slot_with_hash (in_named_htab, section,
347 htab_hash_string (section), NO_INSERT);
349 return slot ? (*slot)->flags : 0;
352 /* Returns true if the section has been declared before. Sets internal
353 flag on this section in in_named_hash so subsequent calls on this
354 section will return false. */
356 bool
357 named_section_first_declaration (name)
358 const char *name;
360 struct in_named_entry **slot;
362 slot = (struct in_named_entry**)
363 htab_find_slot_with_hash (in_named_htab, name,
364 htab_hash_string (name), NO_INSERT);
365 if (! (*slot)->declared)
367 (*slot)->declared = true;
368 return true;
370 else
372 return false;
377 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
378 different set of flags, return false. */
380 bool
381 set_named_section_flags (section, flags)
382 const char *section;
383 unsigned int flags;
385 struct in_named_entry **slot, *entry;
387 slot = (struct in_named_entry**)
388 htab_find_slot_with_hash (in_named_htab, section,
389 htab_hash_string (section), INSERT);
390 entry = *slot;
392 if (!entry)
394 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
395 *slot = entry;
396 entry->name = ggc_strdup (section);
397 entry->flags = flags;
398 entry->declared = false;
400 else if (entry->flags != flags)
401 return false;
403 return true;
406 /* Tell assembler to change to section NAME with attributes FLAGS. */
408 void
409 named_section_flags (name, flags)
410 const char *name;
411 unsigned int flags;
413 if (in_section != in_named || strcmp (name, in_named_name) != 0)
415 if (! set_named_section_flags (name, flags))
416 abort ();
418 (* targetm.asm_out.named_section) (name, flags);
420 if (flags & SECTION_FORGET)
421 in_section = no_section;
422 else
424 in_named_name = ggc_strdup (name);
425 in_section = in_named;
430 /* Tell assembler to change to section NAME for DECL.
431 If DECL is NULL, just switch to section NAME.
432 If NAME is NULL, get the name from DECL.
433 If RELOC is 1, the initializer for DECL contains relocs. */
435 void
436 named_section (decl, name, reloc)
437 tree decl;
438 const char *name;
439 int reloc;
441 unsigned int flags;
443 if (decl != NULL_TREE && !DECL_P (decl))
444 abort ();
445 if (name == NULL)
446 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
448 flags = (* targetm.section_type_flags) (decl, name, reloc);
450 /* Sanity check user variables for flag changes. Non-user
451 section flag changes will abort in named_section_flags.
452 However, don't complain if SECTION_OVERRIDE is set.
453 We trust that the setter knows that it is safe to ignore
454 the default flags for this decl. */
455 if (decl && ! set_named_section_flags (name, flags))
457 flags = get_named_section_flags (name);
458 if ((flags & SECTION_OVERRIDE) == 0)
459 error_with_decl (decl, "%s causes a section type conflict");
462 named_section_flags (name, flags);
465 /* If required, set DECL_SECTION_NAME to a unique name. */
467 static void
468 resolve_unique_section (decl, reloc)
469 tree decl;
470 int reloc ATTRIBUTE_UNUSED;
472 if (DECL_SECTION_NAME (decl) == NULL_TREE
473 && (flag_function_sections
474 || (targetm.have_named_sections
475 && DECL_ONE_ONLY (decl))))
476 UNIQUE_SECTION (decl, reloc);
479 #ifdef BSS_SECTION_ASM_OP
481 /* Tell the assembler to switch to the bss section. */
483 void
484 bss_section ()
486 if (in_section != in_bss)
488 #ifdef SHARED_BSS_SECTION_ASM_OP
489 if (flag_shared_data)
490 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
491 else
492 #endif
493 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
495 in_section = in_bss;
499 #ifdef ASM_OUTPUT_BSS
501 /* Utility function for ASM_OUTPUT_BSS for targets to use if
502 they don't support alignments in .bss.
503 ??? It is believed that this function will work in most cases so such
504 support is localized here. */
506 static void
507 asm_output_bss (file, decl, name, size, rounded)
508 FILE *file;
509 tree decl ATTRIBUTE_UNUSED;
510 const char *name;
511 int size ATTRIBUTE_UNUSED, rounded;
513 ASM_GLOBALIZE_LABEL (file, name);
514 bss_section ();
515 #ifdef ASM_DECLARE_OBJECT_NAME
516 last_assemble_variable_decl = decl;
517 ASM_DECLARE_OBJECT_NAME (file, name, decl);
518 #else
519 /* Standard thing is just output label for the object. */
520 ASM_OUTPUT_LABEL (file, name);
521 #endif /* ASM_DECLARE_OBJECT_NAME */
522 ASM_OUTPUT_SKIP (file, rounded);
525 #endif
527 #ifdef ASM_OUTPUT_ALIGNED_BSS
529 /* Utility function for targets to use in implementing
530 ASM_OUTPUT_ALIGNED_BSS.
531 ??? It is believed that this function will work in most cases so such
532 support is localized here. */
534 static void
535 asm_output_aligned_bss (file, decl, name, size, align)
536 FILE *file;
537 tree decl ATTRIBUTE_UNUSED;
538 const char *name;
539 int size, align;
541 ASM_GLOBALIZE_LABEL (file, name);
542 bss_section ();
543 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
544 #ifdef ASM_DECLARE_OBJECT_NAME
545 last_assemble_variable_decl = decl;
546 ASM_DECLARE_OBJECT_NAME (file, name, decl);
547 #else
548 /* Standard thing is just output label for the object. */
549 ASM_OUTPUT_LABEL (file, name);
550 #endif /* ASM_DECLARE_OBJECT_NAME */
551 ASM_OUTPUT_SKIP (file, size ? size : 1);
554 #endif
556 #endif /* BSS_SECTION_ASM_OP */
558 /* Switch to the section for function DECL.
560 If DECL is NULL_TREE, switch to the text section.
561 ??? It's not clear that we will ever be passed NULL_TREE, but it's
562 safer to handle it. */
564 void
565 function_section (decl)
566 tree decl;
568 if (decl != NULL_TREE
569 && DECL_SECTION_NAME (decl) != NULL_TREE)
570 named_section (decl, (char *) 0, 0);
571 else
572 text_section ();
575 /* Switch to section for variable DECL.
577 RELOC is the `reloc' argument to SELECT_SECTION. */
579 void
580 variable_section (decl, reloc)
581 tree decl;
582 int reloc;
584 if (IN_NAMED_SECTION (decl))
585 named_section (decl, NULL, reloc);
586 else
588 /* C++ can have const variables that get initialized from constructors,
589 and thus can not be in a readonly section. We prevent this by
590 verifying that the initial value is constant for objects put in a
591 readonly section.
593 error_mark_node is used by the C front end to indicate that the
594 initializer has not been seen yet. In this case, we assume that
595 the initializer must be constant.
597 C++ uses error_mark_node for variables that have complicated
598 initializers, but these variables go in BSS so we won't be called
599 for them. */
601 #ifdef SELECT_SECTION
602 SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
603 #else
604 if (DECL_READONLY_SECTION (decl, reloc))
605 readonly_data_section ();
606 else
607 data_section ();
608 #endif
612 /* Tell assembler to switch to the section for the exception handling
613 table. */
615 void
616 default_exception_section ()
618 if (targetm.have_named_sections)
619 named_section (NULL_TREE, ".gcc_except_table", 0);
620 else if (flag_pic)
621 data_section ();
622 else
623 readonly_data_section ();
626 /* Tell assembler to switch to the section for string merging. */
628 void
629 mergeable_string_section (decl, align, flags)
630 tree decl ATTRIBUTE_UNUSED;
631 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
632 unsigned int flags ATTRIBUTE_UNUSED;
634 #ifdef HAVE_GAS_SHF_MERGE
635 if (flag_merge_constants
636 && TREE_CODE (decl) == STRING_CST
637 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
638 && align <= 256
639 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
641 enum machine_mode mode;
642 unsigned int modesize;
643 const char *str;
644 int i, j, len, unit;
645 char name[30];
647 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
648 modesize = GET_MODE_BITSIZE (mode);
649 if (modesize >= 8 && modesize <= 256
650 && (modesize & (modesize - 1)) == 0)
652 if (align < modesize)
653 align = modesize;
655 str = TREE_STRING_POINTER (decl);
656 len = TREE_STRING_LENGTH (decl);
657 unit = GET_MODE_SIZE (mode);
659 /* Check for embedded NUL characters. */
660 for (i = 0; i < len; i += unit)
662 for (j = 0; j < unit; j++)
663 if (str [i + j] != '\0')
664 break;
665 if (j == unit)
666 break;
668 if (i == len - unit)
670 sprintf (name, ".rodata.str%d.%d", modesize / 8,
671 (int) (align / 8));
672 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
673 if (!i && modesize < align)
675 /* A "" string with requested alignment greater than
676 character size might cause a problem:
677 if some other string required even bigger
678 alignment than "", then linker might think the
679 "" is just part of padding after some other string
680 and not put it into the hash table initially.
681 But this means "" could have smaller alignment
682 than requested. */
683 #ifdef ASM_OUTPUT_SECTION_START
684 named_section_flags (name, flags);
685 ASM_OUTPUT_SECTION_START (asm_out_file);
686 #else
687 readonly_data_section ();
688 #endif
689 return;
692 named_section_flags (name, flags);
693 return;
697 #endif
698 readonly_data_section ();
701 /* Tell assembler to switch to the section for constant merging. */
703 void
704 mergeable_constant_section (mode, align, flags)
705 enum machine_mode mode ATTRIBUTE_UNUSED;
706 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
707 unsigned int flags ATTRIBUTE_UNUSED;
709 #ifdef HAVE_GAS_SHF_MERGE
710 unsigned int modesize = GET_MODE_BITSIZE (mode);
712 if (flag_merge_constants
713 && mode != VOIDmode
714 && mode != BLKmode
715 && modesize <= align
716 && align >= 8
717 && align <= 256
718 && (align & (align - 1)) == 0)
720 char name[24];
722 sprintf (name, ".rodata.cst%d", (int) (align / 8));
723 flags |= (align / 8) | SECTION_MERGE;
724 named_section_flags (name, flags);
725 return;
727 #endif
728 readonly_data_section ();
731 /* Given NAME, a putative register name, discard any customary prefixes. */
733 static const char *
734 strip_reg_name (name)
735 const char *name;
737 #ifdef REGISTER_PREFIX
738 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
739 name += strlen (REGISTER_PREFIX);
740 #endif
741 if (name[0] == '%' || name[0] == '#')
742 name++;
743 return name;
746 /* Decode an `asm' spec for a declaration as a register name.
747 Return the register number, or -1 if nothing specified,
748 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
749 or -3 if ASMSPEC is `cc' and is not recognized,
750 or -4 if ASMSPEC is `memory' and is not recognized.
751 Accept an exact spelling or a decimal number.
752 Prefixes such as % are optional. */
755 decode_reg_name (asmspec)
756 const char *asmspec;
758 if (asmspec != 0)
760 int i;
762 /* Get rid of confusing prefixes. */
763 asmspec = strip_reg_name (asmspec);
765 /* Allow a decimal number as a "register name". */
766 for (i = strlen (asmspec) - 1; i >= 0; i--)
767 if (! ISDIGIT (asmspec[i]))
768 break;
769 if (asmspec[0] != 0 && i < 0)
771 i = atoi (asmspec);
772 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
773 return i;
774 else
775 return -2;
778 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
779 if (reg_names[i][0]
780 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
781 return i;
783 #ifdef ADDITIONAL_REGISTER_NAMES
785 static const struct { const char *const name; const int number; } table[]
786 = ADDITIONAL_REGISTER_NAMES;
788 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
789 if (! strcmp (asmspec, table[i].name))
790 return table[i].number;
792 #endif /* ADDITIONAL_REGISTER_NAMES */
794 if (!strcmp (asmspec, "memory"))
795 return -4;
797 if (!strcmp (asmspec, "cc"))
798 return -3;
800 return -2;
803 return -1;
806 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
807 have static storage duration. In other words, it should not be an
808 automatic variable, including PARM_DECLs.
810 There is, however, one exception: this function handles variables
811 explicitly placed in a particular register by the user.
813 ASMSPEC, if not 0, is the string which the user specified as the
814 assembler symbol name.
816 This is never called for PARM_DECL nodes. */
818 void
819 make_decl_rtl (decl, asmspec)
820 tree decl;
821 const char *asmspec;
823 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
824 const char *name = 0;
825 const char *new_name = 0;
826 int reg_number;
827 rtx x;
829 /* Check that we are not being given an automatic variable. */
830 /* A weak alias has TREE_PUBLIC set but not the other bits. */
831 if (TREE_CODE (decl) == PARM_DECL
832 || TREE_CODE (decl) == RESULT_DECL
833 || (TREE_CODE (decl) == VAR_DECL
834 && !TREE_STATIC (decl)
835 && !TREE_PUBLIC (decl)
836 && !DECL_EXTERNAL (decl)
837 && !DECL_REGISTER (decl)))
838 abort ();
839 /* And that we were not given a type or a label. */
840 else if (TREE_CODE (decl) == TYPE_DECL
841 || TREE_CODE (decl) == LABEL_DECL)
842 abort ();
844 /* For a duplicate declaration, we can be called twice on the
845 same DECL node. Don't discard the RTL already made. */
846 if (DECL_RTL_SET_P (decl))
848 /* If the old RTL had the wrong mode, fix the mode. */
849 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
850 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
851 DECL_MODE (decl), 0));
853 /* ??? Another way to do this would be to do what halfpic.c does
854 and maintain a hashed table of such critters. */
855 /* Let the target reassign the RTL if it wants.
856 This is necessary, for example, when one machine specific
857 decl attribute overrides another. */
858 #ifdef ENCODE_SECTION_INFO
859 ENCODE_SECTION_INFO (decl, false);
860 #endif
861 return;
864 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
866 reg_number = decode_reg_name (asmspec);
867 if (reg_number == -2)
869 /* ASMSPEC is given, and not the name of a register. Mark the
870 name with a star so assemble_name won't munge it. */
871 char *starred = alloca (strlen (asmspec) + 2);
872 starred[0] = '*';
873 strcpy (starred + 1, asmspec);
874 new_name = starred;
877 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
879 /* First detect errors in declaring global registers. */
880 if (reg_number == -1)
881 error_with_decl (decl, "register name not specified for `%s'");
882 else if (reg_number < 0)
883 error_with_decl (decl, "invalid register name for `%s'");
884 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
885 error_with_decl (decl,
886 "data type of `%s' isn't suitable for a register");
887 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
888 error_with_decl (decl,
889 "register specified for `%s' isn't suitable for data type");
890 /* Now handle properly declared static register variables. */
891 else
893 int nregs;
895 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
897 DECL_INITIAL (decl) = 0;
898 error ("global register variable has initial value");
900 if (TREE_THIS_VOLATILE (decl))
901 warning ("volatile register variables don't work as you might wish");
903 /* If the user specified one of the eliminables registers here,
904 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
905 confused with that register and be eliminated. This usage is
906 somewhat suspect... */
908 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
909 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
910 REG_USERVAR_P (DECL_RTL (decl)) = 1;
912 if (TREE_STATIC (decl))
914 /* Make this register global, so not usable for anything
915 else. */
916 #ifdef ASM_DECLARE_REGISTER_GLOBAL
917 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
918 #endif
919 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
920 while (nregs > 0)
921 globalize_reg (reg_number + --nregs);
924 /* As a register variable, it has no section. */
925 return;
929 /* Now handle ordinary static variables and functions (in memory).
930 Also handle vars declared register invalidly. */
932 if (reg_number >= 0 || reg_number == -3)
933 error_with_decl (decl,
934 "register name given for non-register variable `%s'");
936 /* Specifying a section attribute on a variable forces it into a
937 non-.bss section, and thus it cannot be common. */
938 if (TREE_CODE (decl) == VAR_DECL
939 && DECL_SECTION_NAME (decl) != NULL_TREE
940 && DECL_INITIAL (decl) == NULL_TREE
941 && DECL_COMMON (decl))
942 DECL_COMMON (decl) = 0;
944 /* Can't use just the variable's own name for a variable
945 whose scope is less than the whole file, unless it's a member
946 of a local class (which will already be unambiguous).
947 Concatenate a distinguishing number. */
948 if (!top_level && !TREE_PUBLIC (decl)
949 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
950 && asmspec == 0
951 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
953 char *label;
955 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
956 var_labelno++;
957 new_name = label;
960 if (name != new_name)
962 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
963 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
966 /* If this variable is to be treated as volatile, show its
967 tree node has side effects. */
968 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
969 && TREE_PUBLIC (decl))
970 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
971 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
972 TREE_SIDE_EFFECTS (decl) = 1;
974 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
975 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
976 if (TREE_CODE (decl) != FUNCTION_DECL)
977 set_mem_attributes (x, decl, 1);
978 SET_DECL_RTL (decl, x);
980 /* Optionally set flags or add text to the name to record information
981 such as that it is a function name.
982 If the name is changed, the macro ASM_OUTPUT_LABELREF
983 will have to know how to strip this information. */
984 #ifdef ENCODE_SECTION_INFO
985 ENCODE_SECTION_INFO (decl, true);
986 #endif
989 /* Make the rtl for variable VAR be volatile.
990 Use this only for static variables. */
992 void
993 make_var_volatile (var)
994 tree var;
996 if (GET_CODE (DECL_RTL (var)) != MEM)
997 abort ();
999 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1002 /* Output alignment directive to align for constant expression EXP. */
1004 void
1005 assemble_constant_align (exp)
1006 tree exp;
1008 int align;
1010 /* Align the location counter as required by EXP's data type. */
1011 align = TYPE_ALIGN (TREE_TYPE (exp));
1012 #ifdef CONSTANT_ALIGNMENT
1013 align = CONSTANT_ALIGNMENT (exp, align);
1014 #endif
1016 if (align > BITS_PER_UNIT)
1018 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1022 /* Output a string of literal assembler code
1023 for an `asm' keyword used between functions. */
1025 void
1026 assemble_asm (string)
1027 tree string;
1029 app_enable ();
1031 if (TREE_CODE (string) == ADDR_EXPR)
1032 string = TREE_OPERAND (string, 0);
1034 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1037 /* Record an element in the table of global destructors. SYMBOL is
1038 a SYMBOL_REF of the function to be called; PRIORITY is a number
1039 between 0 and MAX_INIT_PRIORITY. */
1041 void
1042 default_stabs_asm_out_destructor (symbol, priority)
1043 rtx symbol;
1044 int priority ATTRIBUTE_UNUSED;
1046 /* Tell GNU LD that this is part of the static destructor set.
1047 This will work for any system that uses stabs, most usefully
1048 aout systems. */
1049 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1050 assemble_name (asm_out_file, XSTR (symbol, 0));
1051 fputc ('\n', asm_out_file);
1054 void
1055 default_named_section_asm_out_destructor (symbol, priority)
1056 rtx symbol;
1057 int priority;
1059 const char *section = ".dtors";
1060 char buf[16];
1062 /* ??? This only works reliably with the GNU linker. */
1063 if (priority != DEFAULT_INIT_PRIORITY)
1065 sprintf (buf, ".dtors.%.5u",
1066 /* Invert the numbering so the linker puts us in the proper
1067 order; constructors are run from right to left, and the
1068 linker sorts in increasing order. */
1069 MAX_INIT_PRIORITY - priority);
1070 section = buf;
1073 named_section_flags (section, SECTION_WRITE);
1074 assemble_align (POINTER_SIZE);
1075 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1078 #ifdef DTORS_SECTION_ASM_OP
1079 void
1080 dtors_section ()
1082 if (in_section != in_dtors)
1084 in_section = in_dtors;
1085 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1086 fputc ('\n', asm_out_file);
1090 void
1091 default_dtor_section_asm_out_destructor (symbol, priority)
1092 rtx symbol;
1093 int priority ATTRIBUTE_UNUSED;
1095 dtors_section ();
1096 assemble_align (POINTER_SIZE);
1097 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1099 #endif
1101 /* Likewise for global constructors. */
1103 void
1104 default_stabs_asm_out_constructor (symbol, priority)
1105 rtx symbol;
1106 int priority ATTRIBUTE_UNUSED;
1108 /* Tell GNU LD that this is part of the static destructor set.
1109 This will work for any system that uses stabs, most usefully
1110 aout systems. */
1111 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1112 assemble_name (asm_out_file, XSTR (symbol, 0));
1113 fputc ('\n', asm_out_file);
1116 void
1117 default_named_section_asm_out_constructor (symbol, priority)
1118 rtx symbol;
1119 int priority;
1121 const char *section = ".ctors";
1122 char buf[16];
1124 /* ??? This only works reliably with the GNU linker. */
1125 if (priority != DEFAULT_INIT_PRIORITY)
1127 sprintf (buf, ".ctors.%.5u",
1128 /* Invert the numbering so the linker puts us in the proper
1129 order; constructors are run from right to left, and the
1130 linker sorts in increasing order. */
1131 MAX_INIT_PRIORITY - priority);
1132 section = buf;
1135 named_section_flags (section, SECTION_WRITE);
1136 assemble_align (POINTER_SIZE);
1137 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1140 #ifdef CTORS_SECTION_ASM_OP
1141 void
1142 ctors_section ()
1144 if (in_section != in_ctors)
1146 in_section = in_ctors;
1147 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1148 fputc ('\n', asm_out_file);
1152 void
1153 default_ctor_section_asm_out_constructor (symbol, priority)
1154 rtx symbol;
1155 int priority ATTRIBUTE_UNUSED;
1157 ctors_section ();
1158 assemble_align (POINTER_SIZE);
1159 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1161 #endif
1163 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1164 a non-zero value if the constant pool should be output before the
1165 start of the function, or a zero value if the pool should output
1166 after the end of the function. The default is to put it before the
1167 start. */
1169 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1170 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1171 #endif
1173 /* Output assembler code for the constant pool of a function and associated
1174 with defining the name of the function. DECL describes the function.
1175 NAME is the function's name. For the constant pool, we use the current
1176 constant pool data. */
1178 void
1179 assemble_start_function (decl, fnname)
1180 tree decl;
1181 const char *fnname;
1183 int align;
1185 /* The following code does not need preprocessing in the assembler. */
1187 app_disable ();
1189 if (CONSTANT_POOL_BEFORE_FUNCTION)
1190 output_constant_pool (fnname, decl);
1192 resolve_unique_section (decl, 0);
1193 function_section (decl);
1195 /* Tell assembler to move to target machine's alignment for functions. */
1196 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1197 if (align > 0)
1199 ASM_OUTPUT_ALIGN (asm_out_file, align);
1202 /* Handle a user-specified function alignment.
1203 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1204 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1205 if (align_functions_log > align)
1207 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1208 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1209 align_functions_log, align_functions-1);
1210 #else
1211 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1212 #endif
1215 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1216 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1217 #endif
1219 (*debug_hooks->begin_function) (decl);
1221 /* Make function name accessible from other files, if appropriate. */
1223 if (TREE_PUBLIC (decl))
1225 if (! first_global_object_name)
1227 const char *p;
1228 char *name;
1230 STRIP_NAME_ENCODING (p, fnname);
1231 name = permalloc (strlen (p) + 1);
1232 strcpy (name, p);
1234 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1235 first_global_object_name = name;
1236 else
1237 weak_global_object_name = name;
1240 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
1241 if (DECL_WEAK (decl))
1243 #ifdef ASM_WEAKEN_DECL
1244 ASM_WEAKEN_DECL (asm_out_file, decl, fnname, 0);
1245 #else
1246 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1247 #endif
1248 /* Remove this function from the pending weak list so that
1249 we do not emit multiple .weak directives for it. */
1250 remove_from_pending_weak_list
1251 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1253 else
1254 #endif
1255 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1257 maybe_assemble_visibility (decl);
1260 /* Do any machine/system dependent processing of the function name */
1261 #ifdef ASM_DECLARE_FUNCTION_NAME
1262 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1263 #else
1264 /* Standard thing is just output label for the function. */
1265 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1266 #endif /* ASM_DECLARE_FUNCTION_NAME */
1269 /* Output assembler code associated with defining the size of the
1270 function. DECL describes the function. NAME is the function's name. */
1272 void
1273 assemble_end_function (decl, fnname)
1274 tree decl;
1275 const char *fnname;
1277 #ifdef ASM_DECLARE_FUNCTION_SIZE
1278 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1279 #endif
1280 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1282 output_constant_pool (fnname, decl);
1283 function_section (decl); /* need to switch back */
1286 /* Output any constants which should appear after the function. */
1287 output_after_function_constants ();
1290 /* Assemble code to leave SIZE bytes of zeros. */
1292 void
1293 assemble_zeros (size)
1294 int size;
1296 /* Do no output if -fsyntax-only. */
1297 if (flag_syntax_only)
1298 return;
1300 #ifdef ASM_NO_SKIP_IN_TEXT
1301 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1302 so we must output 0s explicitly in the text section. */
1303 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1305 int i;
1306 for (i = 0; i < size; i++)
1307 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1309 else
1310 #endif
1311 if (size > 0)
1312 ASM_OUTPUT_SKIP (asm_out_file, size);
1315 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1317 void
1318 assemble_align (align)
1319 int align;
1321 if (align > BITS_PER_UNIT)
1323 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1327 /* Assemble a string constant with the specified C string as contents. */
1329 void
1330 assemble_string (p, size)
1331 const char *p;
1332 int size;
1334 int pos = 0;
1335 int maximum = 2000;
1337 /* If the string is very long, split it up. */
1339 while (pos < size)
1341 int thissize = size - pos;
1342 if (thissize > maximum)
1343 thissize = maximum;
1345 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1347 pos += thissize;
1348 p += thissize;
1353 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1354 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1355 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1356 #else
1357 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1358 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1359 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1360 #else
1361 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1362 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1363 #endif
1364 #endif
1366 #if defined ASM_OUTPUT_ALIGNED_BSS
1367 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1368 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1369 #else
1370 #if defined ASM_OUTPUT_BSS
1371 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1372 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1373 #else
1374 #undef ASM_EMIT_BSS
1375 #endif
1376 #endif
1378 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1379 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1380 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1381 #else
1382 #if defined ASM_OUTPUT_ALIGNED_COMMON
1383 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1384 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1385 #else
1386 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1387 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1388 #endif
1389 #endif
1391 static void
1392 asm_emit_uninitialised (decl, name, size, rounded)
1393 tree decl;
1394 const char * name;
1395 int size ATTRIBUTE_UNUSED;
1396 int rounded ATTRIBUTE_UNUSED;
1398 enum
1400 asm_dest_common,
1401 asm_dest_bss,
1402 asm_dest_local
1404 destination = asm_dest_local;
1406 if (TREE_PUBLIC (decl))
1408 #if defined ASM_EMIT_BSS
1409 if (! DECL_COMMON (decl))
1410 destination = asm_dest_bss;
1411 else
1412 #endif
1413 destination = asm_dest_common;
1416 if (flag_shared_data)
1418 switch (destination)
1420 #ifdef ASM_OUTPUT_SHARED_BSS
1421 case asm_dest_bss:
1422 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1423 return;
1424 #endif
1425 #ifdef ASM_OUTPUT_SHARED_COMMON
1426 case asm_dest_common:
1427 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1428 return;
1429 #endif
1430 #ifdef ASM_OUTPUT_SHARED_LOCAL
1431 case asm_dest_local:
1432 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1433 return;
1434 #endif
1435 default:
1436 break;
1440 resolve_unique_section (decl, 0);
1442 switch (destination)
1444 #ifdef ASM_EMIT_BSS
1445 case asm_dest_bss:
1446 ASM_EMIT_BSS (decl, name, size, rounded);
1447 break;
1448 #endif
1449 case asm_dest_common:
1450 ASM_EMIT_COMMON (decl, name, size, rounded);
1451 break;
1452 case asm_dest_local:
1453 ASM_EMIT_LOCAL (decl, name, size, rounded);
1454 break;
1455 default:
1456 abort ();
1459 return;
1462 /* Assemble everything that is needed for a variable or function declaration.
1463 Not used for automatic variables, and not used for function definitions.
1464 Should not be called for variables of incomplete structure type.
1466 TOP_LEVEL is nonzero if this variable has file scope.
1467 AT_END is nonzero if this is the special handling, at end of compilation,
1468 to define things that have had only tentative definitions.
1469 DONT_OUTPUT_DATA if nonzero means don't actually output the
1470 initial value (that will be done by the caller). */
1472 void
1473 assemble_variable (decl, top_level, at_end, dont_output_data)
1474 tree decl;
1475 int top_level ATTRIBUTE_UNUSED;
1476 int at_end ATTRIBUTE_UNUSED;
1477 int dont_output_data;
1479 const char *name;
1480 unsigned int align;
1481 int reloc = 0;
1482 rtx decl_rtl;
1484 last_assemble_variable_decl = 0;
1486 /* Normally no need to say anything here for external references,
1487 since assemble_external is called by the language-specific code
1488 when a declaration is first seen. */
1490 if (DECL_EXTERNAL (decl))
1491 return;
1493 /* Output no assembler code for a function declaration.
1494 Only definitions of functions output anything. */
1496 if (TREE_CODE (decl) == FUNCTION_DECL)
1497 return;
1499 /* Do nothing for global register variables. */
1500 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1502 TREE_ASM_WRITTEN (decl) = 1;
1503 return;
1506 /* If type was incomplete when the variable was declared,
1507 see if it is complete now. */
1509 if (DECL_SIZE (decl) == 0)
1510 layout_decl (decl, 0);
1512 /* Still incomplete => don't allocate it; treat the tentative defn
1513 (which is what it must have been) as an `extern' reference. */
1515 if (!dont_output_data && DECL_SIZE (decl) == 0)
1517 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1518 DECL_SOURCE_LINE (decl),
1519 "storage size of `%s' isn't known",
1520 IDENTIFIER_POINTER (DECL_NAME (decl)));
1521 TREE_ASM_WRITTEN (decl) = 1;
1522 return;
1525 /* The first declaration of a variable that comes through this function
1526 decides whether it is global (in C, has external linkage)
1527 or local (in C, has internal linkage). So do nothing more
1528 if this function has already run. */
1530 if (TREE_ASM_WRITTEN (decl))
1531 return;
1533 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1534 decl_rtl = DECL_RTL (decl);
1536 TREE_ASM_WRITTEN (decl) = 1;
1538 /* Do no output if -fsyntax-only. */
1539 if (flag_syntax_only)
1540 return;
1542 app_disable ();
1544 if (! dont_output_data
1545 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1547 error_with_decl (decl, "size of variable `%s' is too large");
1548 return;
1551 name = XSTR (XEXP (decl_rtl, 0), 0);
1552 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1553 && ! first_global_object_name
1554 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1555 || DECL_INITIAL (decl) == error_mark_node))
1556 && ! DECL_WEAK (decl)
1557 && ! DECL_ONE_ONLY (decl))
1559 const char *p;
1560 char *xname;
1562 STRIP_NAME_ENCODING (p, name);
1563 xname = permalloc (strlen (p) + 1);
1564 strcpy (xname, p);
1565 first_global_object_name = xname;
1568 /* Compute the alignment of this data. */
1570 align = DECL_ALIGN (decl);
1572 /* In the case for initialing an array whose length isn't specified,
1573 where we have not yet been able to do the layout,
1574 figure out the proper alignment now. */
1575 if (dont_output_data && DECL_SIZE (decl) == 0
1576 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1577 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1579 /* Some object file formats have a maximum alignment which they support.
1580 In particular, a.out format supports a maximum alignment of 4. */
1581 #ifndef MAX_OFILE_ALIGNMENT
1582 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1583 #endif
1584 if (align > MAX_OFILE_ALIGNMENT)
1586 warning_with_decl (decl,
1587 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1588 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1589 align = MAX_OFILE_ALIGNMENT;
1592 /* On some machines, it is good to increase alignment sometimes. */
1593 if (! DECL_USER_ALIGN (decl))
1595 #ifdef DATA_ALIGNMENT
1596 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1597 #endif
1598 #ifdef CONSTANT_ALIGNMENT
1599 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1600 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1601 #endif
1604 /* Reset the alignment in case we have made it tighter, so we can benefit
1605 from it in get_pointer_alignment. */
1606 DECL_ALIGN (decl) = align;
1607 set_mem_align (decl_rtl, align);
1609 if (TREE_PUBLIC (decl))
1610 maybe_assemble_visibility (decl);
1612 /* Handle uninitialized definitions. */
1614 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node
1615 #if defined ASM_EMIT_BSS
1616 || (flag_zero_initialized_in_bss
1617 && initializer_zerop (DECL_INITIAL (decl)))
1618 #endif
1620 /* If the target can't output uninitialized but not common global data
1621 in .bss, then we have to use .data. */
1622 #if ! defined ASM_EMIT_BSS
1623 && DECL_COMMON (decl)
1624 #endif
1625 && DECL_SECTION_NAME (decl) == NULL_TREE
1626 && ! dont_output_data)
1628 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1629 unsigned HOST_WIDE_INT rounded = size;
1631 /* Don't allocate zero bytes of common,
1632 since that means "undefined external" in the linker. */
1633 if (size == 0)
1634 rounded = 1;
1636 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1637 so that each uninitialized object starts on such a boundary. */
1638 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1639 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1640 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1642 /* Don't continue this line--convex cc version 4.1 would lose. */
1643 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1644 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1645 warning_with_decl
1646 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1647 #endif
1649 asm_emit_uninitialised (decl, name, size, rounded);
1651 return;
1654 /* Handle initialized definitions.
1655 Also handle uninitialized global definitions if -fno-common and the
1656 target doesn't support ASM_OUTPUT_BSS. */
1658 /* First make the assembler name(s) global if appropriate. */
1659 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1661 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
1662 if (DECL_WEAK (decl))
1664 #ifdef ASM_WEAKEN_DECL
1665 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
1666 #else
1667 ASM_WEAKEN_LABEL (asm_out_file, name);
1668 #endif
1669 /* Remove this variable from the pending weak list so that
1670 we do not emit multiple .weak directives for it. */
1671 remove_from_pending_weak_list
1672 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1674 else
1675 #endif
1676 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1679 /* Output any data that we will need to use the address of. */
1680 if (DECL_INITIAL (decl) == error_mark_node)
1681 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1682 else if (DECL_INITIAL (decl))
1683 reloc = output_addressed_constants (DECL_INITIAL (decl));
1685 /* Switch to the appropriate section. */
1686 resolve_unique_section (decl, reloc);
1687 variable_section (decl, reloc);
1689 /* dbxout.c needs to know this. */
1690 if (in_text_section ())
1691 DECL_IN_TEXT_SECTION (decl) = 1;
1693 /* Output the alignment of this data. */
1694 if (align > BITS_PER_UNIT)
1696 ASM_OUTPUT_ALIGN (asm_out_file,
1697 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1700 /* Do any machine/system dependent processing of the object. */
1701 #ifdef ASM_DECLARE_OBJECT_NAME
1702 last_assemble_variable_decl = decl;
1703 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1704 #else
1705 /* Standard thing is just output label for the object. */
1706 ASM_OUTPUT_LABEL (asm_out_file, name);
1707 #endif /* ASM_DECLARE_OBJECT_NAME */
1709 if (!dont_output_data)
1711 if (DECL_INITIAL (decl))
1712 /* Output the actual data. */
1713 output_constant (DECL_INITIAL (decl),
1714 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1715 align);
1716 else
1717 /* Leave space for it. */
1718 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1722 /* Return 1 if type TYPE contains any pointers. */
1724 static int
1725 contains_pointers_p (type)
1726 tree type;
1728 switch (TREE_CODE (type))
1730 case POINTER_TYPE:
1731 case REFERENCE_TYPE:
1732 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1733 so I'll play safe and return 1. */
1734 case OFFSET_TYPE:
1735 return 1;
1737 case RECORD_TYPE:
1738 case UNION_TYPE:
1739 case QUAL_UNION_TYPE:
1741 tree fields;
1742 /* For a type that has fields, see if the fields have pointers. */
1743 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1744 if (TREE_CODE (fields) == FIELD_DECL
1745 && contains_pointers_p (TREE_TYPE (fields)))
1746 return 1;
1747 return 0;
1750 case ARRAY_TYPE:
1751 /* An array type contains pointers if its element type does. */
1752 return contains_pointers_p (TREE_TYPE (type));
1754 default:
1755 return 0;
1759 /* Output something to declare an external symbol to the assembler.
1760 (Most assemblers don't need this, so we normally output nothing.)
1761 Do nothing if DECL is not external. */
1763 void
1764 assemble_external (decl)
1765 tree decl ATTRIBUTE_UNUSED;
1767 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1768 main body of this code is only rarely exercised. To provide some
1769 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1770 open. If it's not, we should not be calling this function. */
1771 if (!asm_out_file)
1772 abort ();
1774 #ifdef ASM_OUTPUT_EXTERNAL
1775 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1777 rtx rtl = DECL_RTL (decl);
1779 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1780 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1782 /* Some systems do require some output. */
1783 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1784 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1787 #endif
1790 /* Similar, for calling a library function FUN. */
1792 void
1793 assemble_external_libcall (fun)
1794 rtx fun ATTRIBUTE_UNUSED;
1796 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1797 /* Declare library function name external when first used, if nec. */
1798 if (! SYMBOL_REF_USED (fun))
1800 SYMBOL_REF_USED (fun) = 1;
1801 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1803 #endif
1806 /* Declare the label NAME global. */
1808 void
1809 assemble_global (name)
1810 const char *name ATTRIBUTE_UNUSED;
1812 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1815 /* Assemble a label named NAME. */
1817 void
1818 assemble_label (name)
1819 const char *name;
1821 ASM_OUTPUT_LABEL (asm_out_file, name);
1824 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1825 If NAME starts with a *, the rest of NAME is output verbatim.
1826 Otherwise NAME is transformed in an implementation-defined way
1827 (usually by the addition of an underscore).
1828 Many macros in the tm file are defined to call this function. */
1830 void
1831 assemble_name (file, name)
1832 FILE *file;
1833 const char *name;
1835 const char *real_name;
1836 tree id;
1838 STRIP_NAME_ENCODING (real_name, name);
1840 id = maybe_get_identifier (real_name);
1841 if (id)
1842 TREE_SYMBOL_REFERENCED (id) = 1;
1844 if (name[0] == '*')
1845 fputs (&name[1], file);
1846 else
1847 ASM_OUTPUT_LABELREF (file, name);
1850 /* Allocate SIZE bytes writable static space with a gensym name
1851 and return an RTX to refer to its address. */
1854 assemble_static_space (size)
1855 int size;
1857 char name[12];
1858 const char *namestring;
1859 rtx x;
1861 #if 0
1862 if (flag_shared_data)
1863 data_section ();
1864 #endif
1866 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1867 ++const_labelno;
1868 namestring = ggc_strdup (name);
1870 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1872 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1873 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1874 BIGGEST_ALIGNMENT);
1875 #else
1876 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1877 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1878 #else
1880 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1881 so that each uninitialized object starts on such a boundary. */
1882 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1883 int rounded ATTRIBUTE_UNUSED
1884 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1885 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1886 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1887 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1889 #endif
1890 #endif
1891 return x;
1894 /* Assemble the static constant template for function entry trampolines.
1895 This is done at most once per compilation.
1896 Returns an RTX for the address of the template. */
1898 #ifdef TRAMPOLINE_TEMPLATE
1900 assemble_trampoline_template ()
1902 char label[256];
1903 const char *name;
1904 int align;
1906 /* By default, put trampoline templates in read-only data section. */
1908 #ifdef TRAMPOLINE_SECTION
1909 TRAMPOLINE_SECTION ();
1910 #else
1911 readonly_data_section ();
1912 #endif
1914 /* Write the assembler code to define one. */
1915 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1916 if (align > 0)
1918 ASM_OUTPUT_ALIGN (asm_out_file, align);
1921 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1922 TRAMPOLINE_TEMPLATE (asm_out_file);
1924 /* Record the rtl to refer to it. */
1925 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1926 name = ggc_strdup (label);
1927 return gen_rtx_SYMBOL_REF (Pmode, name);
1929 #endif
1931 /* A and B are either alignments or offsets. Return the minimum alignment
1932 that may be assumed after adding the two together. */
1934 static inline unsigned
1935 min_align (a, b)
1936 unsigned int a, b;
1938 return (a | b) & -(a | b);
1941 /* Return the assembler directive for creating a given kind of integer
1942 object. SIZE is the number of bytes in the object and ALIGNED_P
1943 indicates whether it is known to be aligned. Return NULL if the
1944 assembly dialect has no such directive.
1946 The returned string should be printed at the start of a new line and
1947 be followed immediately by the object's initial value. */
1949 const char *
1950 integer_asm_op (size, aligned_p)
1951 int size;
1952 int aligned_p;
1954 struct asm_int_op *ops;
1956 if (aligned_p)
1957 ops = &targetm.asm_out.aligned_op;
1958 else
1959 ops = &targetm.asm_out.unaligned_op;
1961 switch (size)
1963 case 1:
1964 return targetm.asm_out.byte_op;
1965 case 2:
1966 return ops->hi;
1967 case 4:
1968 return ops->si;
1969 case 8:
1970 return ops->di;
1971 case 16:
1972 return ops->ti;
1973 default:
1974 return NULL;
1978 /* Use directive OP to assemble an integer object X. Print OP at the
1979 start of the line, followed immediately by the value of X. */
1981 void
1982 assemble_integer_with_op (op, x)
1983 const char *op;
1984 rtx x;
1986 fputs (op, asm_out_file);
1987 output_addr_const (asm_out_file, x);
1988 fputc ('\n', asm_out_file);
1991 /* The default implementation of the asm_out.integer target hook. */
1993 bool
1994 default_assemble_integer (x, size, aligned_p)
1995 rtx x ATTRIBUTE_UNUSED;
1996 unsigned int size ATTRIBUTE_UNUSED;
1997 int aligned_p ATTRIBUTE_UNUSED;
1999 const char *op = integer_asm_op (size, aligned_p);
2000 return op && (assemble_integer_with_op (op, x), true);
2003 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2004 the alignment of the integer in bits. Return 1 if we were able to output
2005 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
2006 the constant. */
2008 bool
2009 assemble_integer (x, size, align, force)
2010 rtx x;
2011 unsigned int size;
2012 unsigned int align;
2013 int force;
2015 int aligned_p;
2017 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2019 /* See if the target hook can handle this kind of object. */
2020 if ((*targetm.asm_out.integer) (x, size, aligned_p))
2021 return true;
2023 /* If the object is a multi-byte one, try splitting it up. Split
2024 it into words it if is multi-word, otherwise split it into bytes. */
2025 if (size > 1)
2027 enum machine_mode omode, imode;
2028 unsigned int subalign;
2029 unsigned int subsize, i;
2031 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2032 subalign = MIN (align, subsize * BITS_PER_UNIT);
2033 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2034 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2036 for (i = 0; i < size; i += subsize)
2038 rtx partial = simplify_subreg (omode, x, imode, i);
2039 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2040 break;
2042 if (i == size)
2043 return true;
2045 /* If we've printed some of it, but not all of it, there's no going
2046 back now. */
2047 if (i > 0)
2048 abort ();
2051 if (force)
2052 abort ();
2054 return false;
2057 void
2058 assemble_real (d, mode, align)
2059 REAL_VALUE_TYPE d;
2060 enum machine_mode mode;
2061 unsigned int align;
2063 long data[4];
2064 long l;
2065 unsigned int nalign = min_align (align, 32);
2067 switch (BITS_PER_UNIT)
2069 case 8:
2070 switch (mode)
2072 case SFmode:
2073 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2074 assemble_integer (GEN_INT (l), 4, align, 1);
2075 break;
2076 case DFmode:
2077 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2078 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2079 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2080 break;
2081 case XFmode:
2082 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2083 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2084 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2085 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2086 break;
2087 case TFmode:
2088 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d, data);
2089 assemble_integer (GEN_INT (data[0]), 4, align, 1);
2090 assemble_integer (GEN_INT (data[1]), 4, nalign, 1);
2091 assemble_integer (GEN_INT (data[2]), 4, nalign, 1);
2092 assemble_integer (GEN_INT (data[3]), 4, nalign, 1);
2093 break;
2094 default:
2095 abort ();
2097 break;
2099 case 16:
2100 switch (mode)
2102 case HFmode:
2103 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2104 assemble_integer (GEN_INT (l), 2, align, 1);
2105 break;
2106 case TQFmode:
2107 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2108 assemble_integer (GEN_INT (data[0]), 2, align, 1);
2109 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2110 break;
2111 default:
2112 abort ();
2114 break;
2116 case 32:
2117 switch (mode)
2119 case QFmode:
2120 REAL_VALUE_TO_TARGET_SINGLE (d, l);
2121 assemble_integer (GEN_INT (l), 1, align, 1);
2122 break;
2123 case HFmode:
2124 REAL_VALUE_TO_TARGET_DOUBLE (d, data);
2125 assemble_integer (GEN_INT (data[0]), 1, align, 1);
2126 assemble_integer (GEN_INT (data[1]), 1, nalign, 1);
2127 break;
2128 default:
2129 abort ();
2131 break;
2133 default:
2134 abort ();
2138 /* Here we combine duplicate floating constants to make
2139 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2141 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2142 For an integer, I0 is the low-order word and I1 is the high-order word.
2143 For a real number, I0 is the word with the low address
2144 and I1 is the word with the high address. */
2147 immed_double_const (i0, i1, mode)
2148 HOST_WIDE_INT i0, i1;
2149 enum machine_mode mode;
2151 rtx r;
2153 if (GET_MODE_CLASS (mode) == MODE_INT
2154 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2156 /* We clear out all bits that don't belong in MODE, unless they and our
2157 sign bit are all one. So we get either a reasonable negative value
2158 or a reasonable unsigned value for this mode. */
2159 int width = GET_MODE_BITSIZE (mode);
2160 if (width < HOST_BITS_PER_WIDE_INT
2161 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2162 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2163 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2164 else if (width == HOST_BITS_PER_WIDE_INT
2165 && ! (i1 == ~0 && i0 < 0))
2166 i1 = 0;
2167 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2168 /* We cannot represent this value as a constant. */
2169 abort ();
2171 /* If this would be an entire word for the target, but is not for
2172 the host, then sign-extend on the host so that the number will look
2173 the same way on the host that it would on the target.
2175 For example, when building a 64 bit alpha hosted 32 bit sparc
2176 targeted compiler, then we want the 32 bit unsigned value -1 to be
2177 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2178 The later confuses the sparc backend. */
2180 if (width < HOST_BITS_PER_WIDE_INT
2181 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2182 i0 |= ((HOST_WIDE_INT) (-1) << width);
2184 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2186 ??? Strictly speaking, this is wrong if we create a CONST_INT
2187 for a large unsigned constant with the size of MODE being
2188 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2189 wider mode. In that case we will mis-interpret it as a negative
2190 number.
2192 Unfortunately, the only alternative is to make a CONST_DOUBLE
2193 for any constant in any mode if it is an unsigned constant larger
2194 than the maximum signed integer in an int on the host. However,
2195 doing this will break everyone that always expects to see a CONST_INT
2196 for SImode and smaller.
2198 We have always been making CONST_INTs in this case, so nothing new
2199 is being broken. */
2201 if (width <= HOST_BITS_PER_WIDE_INT)
2202 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2204 /* If this integer fits in one word, return a CONST_INT. */
2205 if ((i1 == 0 && i0 >= 0)
2206 || (i1 == ~0 && i0 < 0))
2207 return GEN_INT (i0);
2209 /* We use VOIDmode for integers. */
2210 mode = VOIDmode;
2213 /* Search the chain for an existing CONST_DOUBLE with the right value.
2214 If one is found, return it. */
2215 if (cfun != 0)
2216 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2217 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2218 && GET_MODE (r) == mode)
2219 return r;
2221 /* No; make a new one and add it to the chain. */
2222 r = gen_rtx_CONST_DOUBLE (mode, i0, i1);
2224 /* Don't touch const_double_chain if not inside any function. */
2225 if (current_function_decl != 0)
2227 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2228 const_double_chain = r;
2231 return r;
2234 /* Return a CONST_DOUBLE for a specified `double' value
2235 and machine mode. */
2238 immed_real_const_1 (d, mode)
2239 REAL_VALUE_TYPE d;
2240 enum machine_mode mode;
2242 union real_extract u;
2243 rtx r;
2245 /* Get the desired `double' value as a sequence of ints
2246 since that is how they are stored in a CONST_DOUBLE. */
2248 u.d = d;
2250 /* Detect special cases. Check for NaN first, because some ports
2251 (specifically the i386) do not emit correct ieee-fp code by default, and
2252 thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2253 and if REAL_VALUES_EQUAL does a floating point comparison. */
2254 if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_IDENTICAL (dconst0, d))
2255 return CONST0_RTX (mode);
2256 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2257 return CONST1_RTX (mode);
2258 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst2, d))
2259 return CONST2_RTX (mode);
2261 if (sizeof u == sizeof (HOST_WIDE_INT))
2262 return immed_double_const (u.i[0], 0, mode);
2263 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2264 return immed_double_const (u.i[0], u.i[1], mode);
2266 /* The rest of this function handles the case where
2267 a float value requires more than 2 ints of space.
2268 It will be deleted as dead code on machines that don't need it. */
2270 /* Search the chain for an existing CONST_DOUBLE with the right value.
2271 If one is found, return it. */
2272 if (cfun != 0)
2273 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2274 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2275 && GET_MODE (r) == mode)
2276 return r;
2278 /* No; make a new one and add it to the chain.
2280 We may be called by an optimizer which may be discarding any memory
2281 allocated during its processing (such as combine and loop). However,
2282 we will be leaving this constant on the chain, so we cannot tolerate
2283 freed memory. */
2284 r = rtx_alloc (CONST_DOUBLE);
2285 PUT_MODE (r, mode);
2286 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2288 /* If we aren't inside a function, don't put r on the
2289 const_double_chain. */
2290 if (current_function_decl != 0)
2292 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2293 const_double_chain = r;
2295 else
2296 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2298 return r;
2301 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2302 which must be a REAL_CST tree node. */
2305 immed_real_const (exp)
2306 tree exp;
2308 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2311 /* At the end of a function, forget the memory-constants
2312 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2313 Also clear out real_constant_chain and clear out all the chain-pointers. */
2315 void
2316 clear_const_double_mem ()
2318 rtx r, next;
2320 for (r = const_double_chain; r; r = next)
2322 next = CONST_DOUBLE_CHAIN (r);
2323 CONST_DOUBLE_CHAIN (r) = 0;
2325 const_double_chain = 0;
2328 /* Given an expression EXP with a constant value,
2329 reduce it to the sum of an assembler symbol and an integer.
2330 Store them both in the structure *VALUE.
2331 Abort if EXP does not reduce. */
2333 struct addr_const
2335 rtx base;
2336 HOST_WIDE_INT offset;
2339 static void
2340 decode_addr_const (exp, value)
2341 tree exp;
2342 struct addr_const *value;
2344 tree target = TREE_OPERAND (exp, 0);
2345 int offset = 0;
2346 rtx x;
2348 while (1)
2350 if (TREE_CODE (target) == COMPONENT_REF
2351 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2354 offset += int_byte_position (TREE_OPERAND (target, 1));
2355 target = TREE_OPERAND (target, 0);
2357 else if (TREE_CODE (target) == ARRAY_REF
2358 || TREE_CODE (target) == ARRAY_RANGE_REF)
2360 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2361 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2362 target = TREE_OPERAND (target, 0);
2364 else
2365 break;
2368 switch (TREE_CODE (target))
2370 case VAR_DECL:
2371 case FUNCTION_DECL:
2372 x = DECL_RTL (target);
2373 break;
2375 case LABEL_DECL:
2376 x = gen_rtx_MEM (FUNCTION_MODE,
2377 gen_rtx_LABEL_REF (VOIDmode,
2378 label_rtx (TREE_OPERAND (exp, 0))));
2379 break;
2381 case REAL_CST:
2382 case STRING_CST:
2383 case COMPLEX_CST:
2384 case CONSTRUCTOR:
2385 case INTEGER_CST:
2386 /* This constant should have been output already, but we can't simply
2387 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2388 x = output_constant_def (target, 1);
2389 break;
2391 default:
2392 abort ();
2395 if (GET_CODE (x) != MEM)
2396 abort ();
2397 x = XEXP (x, 0);
2399 value->base = x;
2400 value->offset = offset;
2403 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2404 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_INT, RTX_VECTOR, RTX_UNSPEC };
2405 struct rtx_const
2407 ENUM_BITFIELD(kind) kind : 16;
2408 ENUM_BITFIELD(machine_mode) mode : 16;
2409 union {
2410 union real_extract du;
2411 struct addr_const addr;
2412 struct {HOST_WIDE_INT high, low;} di;
2414 /* The max vector size we have is 8 wide. This should be enough. */
2415 HOST_WIDE_INT veclo[16];
2416 HOST_WIDE_INT vechi[16];
2417 } un;
2420 /* Uniquize all constants that appear in memory.
2421 Each constant in memory thus far output is recorded
2422 in `const_hash_table' with a `struct constant_descriptor'
2423 that contains a polish representation of the value of
2424 the constant.
2426 We cannot store the trees in the hash table
2427 because the trees may be temporary. */
2429 struct constant_descriptor
2431 struct constant_descriptor *next;
2432 const char *label;
2433 rtx rtl;
2434 /* Make sure the data is reasonably aligned. */
2435 union
2437 unsigned char contents[1];
2438 #ifdef HAVE_LONG_DOUBLE
2439 long double d;
2440 #else
2441 double d;
2442 #endif
2443 } u;
2446 #define HASHBITS 30
2447 #define MAX_HASH_TABLE 1009
2448 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2450 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2451 out a string constant, we defer output of the constants until we know
2452 they are actually used. This will be if something takes its address or if
2453 there is a usage of the string in the RTL of a function. */
2455 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2457 struct deferred_string
2459 const char *label;
2460 tree exp;
2461 int labelno;
2464 static htab_t const_str_htab;
2466 /* Mark a const_hash_table descriptor for GC. */
2468 static void
2469 mark_const_hash_entry (ptr)
2470 void *ptr;
2472 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2474 while (desc)
2476 ggc_mark_rtx (desc->rtl);
2477 desc = desc->next;
2481 /* Mark the hash-table element X (which is really a pointer to an
2482 struct deferred_string *). */
2484 static int
2485 mark_const_str_htab_1 (x, data)
2486 void **x;
2487 void *data ATTRIBUTE_UNUSED;
2489 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2490 return 1;
2493 /* Mark a const_str_htab for GC. */
2495 static void
2496 mark_const_str_htab (htab)
2497 void *htab;
2499 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2502 /* Returns a hash code for X (which is a really a
2503 struct deferred_string *). */
2505 static hashval_t
2506 const_str_htab_hash (x)
2507 const void *x;
2509 return STRHASH (((const struct deferred_string *) x)->label);
2512 /* Returns non-zero if the value represented by X (which is really a
2513 struct deferred_string *) is the same as that given by Y
2514 (which is really a char *). */
2516 static int
2517 const_str_htab_eq (x, y)
2518 const void *x;
2519 const void *y;
2521 return (((const struct deferred_string *) x)->label == (const char *) y);
2524 /* Delete the hash table entry dfsp. */
2526 static void
2527 const_str_htab_del (dfsp)
2528 void *dfsp;
2530 free (dfsp);
2533 /* Compute a hash code for a constant expression. */
2535 static int
2536 const_hash (exp)
2537 tree exp;
2539 const char *p;
2540 int len, hi, i;
2541 enum tree_code code = TREE_CODE (exp);
2543 /* Either set P and LEN to the address and len of something to hash and
2544 exit the switch or return a value. */
2546 switch (code)
2548 case INTEGER_CST:
2549 p = (char *) &TREE_INT_CST (exp);
2550 len = sizeof TREE_INT_CST (exp);
2551 break;
2553 case REAL_CST:
2554 p = (char *) &TREE_REAL_CST (exp);
2555 len = sizeof TREE_REAL_CST (exp);
2556 break;
2558 case STRING_CST:
2559 p = TREE_STRING_POINTER (exp);
2560 len = TREE_STRING_LENGTH (exp);
2561 break;
2563 case COMPLEX_CST:
2564 return (const_hash (TREE_REALPART (exp)) * 5
2565 + const_hash (TREE_IMAGPART (exp)));
2567 case CONSTRUCTOR:
2568 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2570 char *tmp;
2572 len = int_size_in_bytes (TREE_TYPE (exp));
2573 tmp = (char *) alloca (len);
2574 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2575 p = tmp;
2576 break;
2578 else
2580 tree link;
2582 /* For record type, include the type in the hashing.
2583 We do not do so for array types
2584 because (1) the sizes of the elements are sufficient
2585 and (2) distinct array types can have the same constructor.
2586 Instead, we include the array size because the constructor could
2587 be shorter. */
2588 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2589 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2590 % MAX_HASH_TABLE;
2591 else
2592 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2593 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2595 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2596 if (TREE_VALUE (link))
2598 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2600 return hi;
2603 case ADDR_EXPR:
2605 struct addr_const value;
2607 decode_addr_const (exp, &value);
2608 if (GET_CODE (value.base) == SYMBOL_REF)
2610 /* Don't hash the address of the SYMBOL_REF;
2611 only use the offset and the symbol name. */
2612 hi = value.offset;
2613 p = XSTR (value.base, 0);
2614 for (i = 0; p[i] != 0; i++)
2615 hi = ((hi * 613) + (unsigned) (p[i]));
2617 else if (GET_CODE (value.base) == LABEL_REF)
2618 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2619 else
2620 abort ();
2622 hi &= (1 << HASHBITS) - 1;
2623 hi %= MAX_HASH_TABLE;
2625 return hi;
2627 case PLUS_EXPR:
2628 case MINUS_EXPR:
2629 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2630 + const_hash (TREE_OPERAND (exp, 1)));
2632 case NOP_EXPR:
2633 case CONVERT_EXPR:
2634 case NON_LVALUE_EXPR:
2635 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2637 default:
2638 /* A language specific constant. Just hash the code. */
2639 return (int) code % MAX_HASH_TABLE;
2642 /* Compute hashing function */
2643 hi = len;
2644 for (i = 0; i < len; i++)
2645 hi = ((hi * 613) + (unsigned) (p[i]));
2647 hi &= (1 << HASHBITS) - 1;
2648 hi %= MAX_HASH_TABLE;
2649 return hi;
2652 /* Compare a constant expression EXP with a constant-descriptor DESC.
2653 Return 1 if DESC describes a constant with the same value as EXP. */
2655 static int
2656 compare_constant (exp, desc)
2657 tree exp;
2658 struct constant_descriptor *desc;
2660 return 0 != compare_constant_1 (exp, desc->u.contents);
2663 /* Compare constant expression EXP with a substring P of a constant descriptor.
2664 If they match, return a pointer to the end of the substring matched.
2665 If they do not match, return 0.
2667 Since descriptors are written in polish prefix notation,
2668 this function can be used recursively to test one operand of EXP
2669 against a subdescriptor, and if it succeeds it returns the
2670 address of the subdescriptor for the next operand. */
2672 static const unsigned char *
2673 compare_constant_1 (exp, p)
2674 tree exp;
2675 const unsigned char *p;
2677 const unsigned char *strp;
2678 int len;
2679 enum tree_code code = TREE_CODE (exp);
2681 if (code != (enum tree_code) *p++)
2682 return 0;
2684 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2685 switch, or return the result of the comparison. */
2687 switch (code)
2689 case INTEGER_CST:
2690 /* Integer constants are the same only if the same width of type. */
2691 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2692 return 0;
2694 strp = (unsigned char *) &TREE_INT_CST (exp);
2695 len = sizeof TREE_INT_CST (exp);
2696 break;
2698 case REAL_CST:
2699 /* Real constants are the same only if the same width of type. */
2700 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2701 return 0;
2703 strp = (unsigned char *) &TREE_REAL_CST (exp);
2704 len = sizeof TREE_REAL_CST (exp);
2705 break;
2707 case STRING_CST:
2708 if (flag_writable_strings)
2709 return 0;
2711 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2712 return 0;
2714 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2715 len = TREE_STRING_LENGTH (exp);
2716 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2717 sizeof TREE_STRING_LENGTH (exp)))
2718 return 0;
2720 p += sizeof TREE_STRING_LENGTH (exp);
2721 break;
2723 case COMPLEX_CST:
2724 p = compare_constant_1 (TREE_REALPART (exp), p);
2725 if (p == 0)
2726 return 0;
2728 return compare_constant_1 (TREE_IMAGPART (exp), p);
2730 case CONSTRUCTOR:
2731 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2733 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2734 unsigned char *tmp = (unsigned char *) alloca (len);
2736 get_set_constructor_bytes (exp, tmp, len);
2737 strp = (unsigned char *) tmp;
2738 if (memcmp ((char *) &xlen, p, sizeof xlen))
2739 return 0;
2741 p += sizeof xlen;
2742 break;
2744 else
2746 tree link;
2747 int length = list_length (CONSTRUCTOR_ELTS (exp));
2748 tree type;
2749 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2750 int have_purpose = 0;
2752 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2753 if (TREE_PURPOSE (link))
2754 have_purpose = 1;
2756 if (memcmp ((char *) &length, p, sizeof length))
2757 return 0;
2759 p += sizeof length;
2761 /* For record constructors, insist that the types match.
2762 For arrays, just verify both constructors are for arrays.
2763 Then insist that either both or none have any TREE_PURPOSE
2764 values. */
2765 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2766 type = TREE_TYPE (exp);
2767 else
2768 type = 0;
2770 if (memcmp ((char *) &type, p, sizeof type))
2771 return 0;
2773 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2775 if (memcmp ((char *) &mode, p, sizeof mode))
2776 return 0;
2778 p += sizeof mode;
2781 p += sizeof type;
2783 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2784 return 0;
2786 p += sizeof have_purpose;
2788 /* For arrays, insist that the size in bytes match. */
2789 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2791 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2793 if (memcmp ((char *) &size, p, sizeof size))
2794 return 0;
2796 p += sizeof size;
2799 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2801 if (TREE_VALUE (link))
2803 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2804 return 0;
2806 else
2808 tree zero = 0;
2810 if (memcmp ((char *) &zero, p, sizeof zero))
2811 return 0;
2813 p += sizeof zero;
2816 if (TREE_PURPOSE (link)
2817 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2819 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2820 sizeof TREE_PURPOSE (link)))
2821 return 0;
2823 p += sizeof TREE_PURPOSE (link);
2825 else if (TREE_PURPOSE (link))
2827 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2828 return 0;
2830 else if (have_purpose)
2832 int zero = 0;
2834 if (memcmp ((char *) &zero, p, sizeof zero))
2835 return 0;
2837 p += sizeof zero;
2841 return p;
2844 case ADDR_EXPR:
2846 struct addr_const value;
2848 decode_addr_const (exp, &value);
2849 strp = (unsigned char *) &value.offset;
2850 len = sizeof value.offset;
2851 /* Compare the offset. */
2852 while (--len >= 0)
2853 if (*p++ != *strp++)
2854 return 0;
2856 /* Compare symbol name. */
2857 strp = (const unsigned char *) XSTR (value.base, 0);
2858 len = strlen ((const char *) strp) + 1;
2860 break;
2862 case PLUS_EXPR:
2863 case MINUS_EXPR:
2864 case RANGE_EXPR:
2865 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2866 if (p == 0)
2867 return 0;
2869 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2871 case NOP_EXPR:
2872 case CONVERT_EXPR:
2873 case NON_LVALUE_EXPR:
2874 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2876 default:
2878 tree new = (*lang_hooks.expand_constant) (exp);
2880 if (new != exp)
2881 return compare_constant_1 (new, p);
2882 else
2883 return 0;
2887 /* Compare constant contents. */
2888 while (--len >= 0)
2889 if (*p++ != *strp++)
2890 return 0;
2892 return p;
2895 /* Construct a constant descriptor for the expression EXP.
2896 It is up to the caller to enter the descriptor in the hash table. */
2898 static struct constant_descriptor *
2899 record_constant (exp)
2900 tree exp;
2902 struct constant_descriptor *next = 0;
2903 char *label = 0;
2904 rtx rtl = 0;
2905 int pad;
2907 /* Make a struct constant_descriptor. The first three pointers will
2908 be filled in later. Here we just leave space for them. */
2910 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2911 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2912 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2914 /* Align the descriptor for the data payload. */
2915 pad = (offsetof (struct constant_descriptor, u)
2916 - offsetof(struct constant_descriptor, rtl)
2917 - sizeof(next->rtl));
2918 if (pad > 0)
2919 obstack_blank (&permanent_obstack, pad);
2921 record_constant_1 (exp);
2922 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2925 /* Add a description of constant expression EXP
2926 to the object growing in `permanent_obstack'.
2927 No need to return its address; the caller will get that
2928 from the obstack when the object is complete. */
2930 static void
2931 record_constant_1 (exp)
2932 tree exp;
2934 const unsigned char *strp;
2935 int len;
2936 enum tree_code code = TREE_CODE (exp);
2938 obstack_1grow (&permanent_obstack, (unsigned int) code);
2940 switch (code)
2942 case INTEGER_CST:
2943 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2944 strp = (unsigned char *) &TREE_INT_CST (exp);
2945 len = sizeof TREE_INT_CST (exp);
2946 break;
2948 case REAL_CST:
2949 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2950 strp = (unsigned char *) &TREE_REAL_CST (exp);
2951 len = sizeof TREE_REAL_CST (exp);
2952 break;
2954 case STRING_CST:
2955 if (flag_writable_strings)
2956 return;
2958 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2959 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2960 len = TREE_STRING_LENGTH (exp);
2961 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2962 sizeof TREE_STRING_LENGTH (exp));
2963 break;
2965 case COMPLEX_CST:
2966 record_constant_1 (TREE_REALPART (exp));
2967 record_constant_1 (TREE_IMAGPART (exp));
2968 return;
2970 case CONSTRUCTOR:
2971 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2973 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2974 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2975 obstack_blank (&permanent_obstack, nbytes);
2976 get_set_constructor_bytes
2977 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2978 nbytes);
2979 return;
2981 else
2983 tree link;
2984 int length = list_length (CONSTRUCTOR_ELTS (exp));
2985 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2986 tree type;
2987 int have_purpose = 0;
2989 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2990 if (TREE_PURPOSE (link))
2991 have_purpose = 1;
2993 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2995 /* For record constructors, insist that the types match.
2996 For arrays, just verify both constructors are for arrays
2997 of the same mode. Then insist that either both or none
2998 have any TREE_PURPOSE values. */
2999 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3000 type = TREE_TYPE (exp);
3001 else
3002 type = 0;
3004 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
3005 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3006 obstack_grow (&permanent_obstack, &mode, sizeof mode);
3008 obstack_grow (&permanent_obstack, (char *) &have_purpose,
3009 sizeof have_purpose);
3011 /* For arrays, insist that the size in bytes match. */
3012 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3014 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3015 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
3018 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3020 if (TREE_VALUE (link))
3021 record_constant_1 (TREE_VALUE (link));
3022 else
3024 tree zero = 0;
3026 obstack_grow (&permanent_obstack,
3027 (char *) &zero, sizeof zero);
3030 if (TREE_PURPOSE (link)
3031 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
3032 obstack_grow (&permanent_obstack,
3033 (char *) &TREE_PURPOSE (link),
3034 sizeof TREE_PURPOSE (link));
3035 else if (TREE_PURPOSE (link))
3036 record_constant_1 (TREE_PURPOSE (link));
3037 else if (have_purpose)
3039 int zero = 0;
3041 obstack_grow (&permanent_obstack,
3042 (char *) &zero, sizeof zero);
3046 return;
3048 case ADDR_EXPR:
3050 struct addr_const value;
3052 decode_addr_const (exp, &value);
3053 /* Record the offset. */
3054 obstack_grow (&permanent_obstack,
3055 (char *) &value.offset, sizeof value.offset);
3057 switch (GET_CODE (value.base))
3059 case SYMBOL_REF:
3060 /* Record the symbol name. */
3061 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3062 strlen (XSTR (value.base, 0)) + 1);
3063 break;
3064 case LABEL_REF:
3065 /* Record the address of the CODE_LABEL. It may not have
3066 been emitted yet, so it's UID may be zero. But pointer
3067 identity is good enough. */
3068 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3069 sizeof (rtx));
3070 break;
3071 default:
3072 abort ();
3075 return;
3077 case PLUS_EXPR:
3078 case MINUS_EXPR:
3079 case RANGE_EXPR:
3080 record_constant_1 (TREE_OPERAND (exp, 0));
3081 record_constant_1 (TREE_OPERAND (exp, 1));
3082 return;
3084 case NOP_EXPR:
3085 case CONVERT_EXPR:
3086 case NON_LVALUE_EXPR:
3087 record_constant_1 (TREE_OPERAND (exp, 0));
3088 return;
3090 default:
3092 tree new = (*lang_hooks.expand_constant) (exp);
3094 if (new != exp)
3095 record_constant_1 (new);
3096 return;
3100 /* Record constant contents. */
3101 obstack_grow (&permanent_obstack, strp, len);
3104 /* Record a list of constant expressions that were passed to
3105 output_constant_def but that could not be output right away. */
3107 struct deferred_constant
3109 struct deferred_constant *next;
3110 tree exp;
3111 int reloc;
3112 int labelno;
3115 static struct deferred_constant *deferred_constants;
3117 /* Another list of constants which should be output after the
3118 function. */
3119 static struct deferred_constant *after_function_constants;
3121 /* Nonzero means defer output of addressed subconstants
3122 (i.e., those for which output_constant_def is called.) */
3123 static int defer_addressed_constants_flag;
3125 /* Start deferring output of subconstants. */
3127 void
3128 defer_addressed_constants ()
3130 defer_addressed_constants_flag++;
3133 /* Stop deferring output of subconstants,
3134 and output now all those that have been deferred. */
3136 void
3137 output_deferred_addressed_constants ()
3139 struct deferred_constant *p, *next;
3141 defer_addressed_constants_flag--;
3143 if (defer_addressed_constants_flag > 0)
3144 return;
3146 for (p = deferred_constants; p; p = next)
3148 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3149 next = p->next;
3150 free (p);
3153 deferred_constants = 0;
3156 /* Output any constants which should appear after a function. */
3158 static void
3159 output_after_function_constants ()
3161 struct deferred_constant *p, *next;
3163 for (p = after_function_constants; p; p = next)
3165 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3166 next = p->next;
3167 free (p);
3170 after_function_constants = 0;
3173 /* Make a copy of the whole tree structure for a constant.
3174 This handles the same types of nodes that compare_constant
3175 and record_constant handle. */
3177 static tree
3178 copy_constant (exp)
3179 tree exp;
3181 switch (TREE_CODE (exp))
3183 case ADDR_EXPR:
3184 /* For ADDR_EXPR, we do not want to copy the decl whose address
3185 is requested. We do want to copy constants though. */
3186 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3187 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3188 copy_constant (TREE_OPERAND (exp, 0)));
3189 else
3190 return copy_node (exp);
3192 case INTEGER_CST:
3193 case REAL_CST:
3194 case STRING_CST:
3195 return copy_node (exp);
3197 case COMPLEX_CST:
3198 return build_complex (TREE_TYPE (exp),
3199 copy_constant (TREE_REALPART (exp)),
3200 copy_constant (TREE_IMAGPART (exp)));
3202 case PLUS_EXPR:
3203 case MINUS_EXPR:
3204 return build (TREE_CODE (exp), TREE_TYPE (exp),
3205 copy_constant (TREE_OPERAND (exp, 0)),
3206 copy_constant (TREE_OPERAND (exp, 1)));
3208 case NOP_EXPR:
3209 case CONVERT_EXPR:
3210 case NON_LVALUE_EXPR:
3211 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3212 copy_constant (TREE_OPERAND (exp, 0)));
3214 case CONSTRUCTOR:
3216 tree copy = copy_node (exp);
3217 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3218 tree tail;
3220 CONSTRUCTOR_ELTS (copy) = list;
3221 for (tail = list; tail; tail = TREE_CHAIN (tail))
3222 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3223 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3224 for (tail = list; tail; tail = TREE_CHAIN (tail))
3225 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3227 return copy;
3230 default:
3231 abort ();
3235 /* Return an rtx representing a reference to constant data in memory
3236 for the constant expression EXP.
3238 If assembler code for such a constant has already been output,
3239 return an rtx to refer to it.
3240 Otherwise, output such a constant in memory (or defer it for later)
3241 and generate an rtx for it.
3243 If DEFER is non-zero, the output of string constants can be deferred
3244 and output only if referenced in the function after all optimizations.
3246 The TREE_CST_RTL of EXP is set up to point to that rtx.
3247 The const_hash_table records which constants already have label strings. */
3250 output_constant_def (exp, defer)
3251 tree exp;
3252 int defer;
3254 int hash;
3255 struct constant_descriptor *desc;
3256 struct deferred_string **defstr;
3257 char label[256];
3258 int reloc;
3259 int found = 1;
3260 int after_function = 0;
3261 int labelno = -1;
3262 rtx rtl;
3264 /* We can't just use the saved RTL if this is a defererred string constant
3265 and we are not to defer anymode. */
3266 if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3267 && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3268 return TREE_CST_RTL (exp);
3270 /* Make sure any other constants whose addresses appear in EXP
3271 are assigned label numbers. */
3273 reloc = output_addressed_constants (exp);
3275 /* Compute hash code of EXP. Search the descriptors for that hash code
3276 to see if any of them describes EXP. If yes, the descriptor records
3277 the label number already assigned. */
3279 hash = const_hash (exp) % MAX_HASH_TABLE;
3281 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3282 if (compare_constant (exp, desc))
3283 break;
3285 if (desc == 0)
3287 /* No constant equal to EXP is known to have been output.
3288 Make a constant descriptor to enter EXP in the hash table.
3289 Assign the label number and record it in the descriptor for
3290 future calls to this function to find. */
3292 /* Create a string containing the label name, in LABEL. */
3293 labelno = const_labelno++;
3294 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3296 desc = record_constant (exp);
3297 desc->next = const_hash_table[hash];
3298 desc->label = ggc_strdup (label);
3299 const_hash_table[hash] = desc;
3301 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3302 rtl = desc->rtl
3303 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3304 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3306 set_mem_attributes (rtl, exp, 1);
3307 set_mem_alias_set (rtl, 0);
3308 set_mem_alias_set (rtl, const_alias_set);
3310 found = 0;
3312 else
3313 rtl = desc->rtl;
3315 if (TREE_CODE (exp) != INTEGER_CST)
3316 TREE_CST_RTL (exp) = rtl;
3318 /* Optionally set flags or add text to the name to record information
3319 such as that it is a function name. If the name is changed, the macro
3320 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3321 #ifdef ENCODE_SECTION_INFO
3322 /* A previously-processed constant would already have section info
3323 encoded in it. */
3324 if (! found)
3326 ENCODE_SECTION_INFO (exp, true);
3327 desc->rtl = rtl;
3328 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3330 #endif
3332 #ifdef CONSTANT_AFTER_FUNCTION_P
3333 if (current_function_decl != 0
3334 && CONSTANT_AFTER_FUNCTION_P (exp))
3335 after_function = 1;
3336 #endif
3338 if (found
3339 && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3340 && (!defer || defer_addressed_constants_flag || after_function))
3342 defstr = (struct deferred_string **)
3343 htab_find_slot_with_hash (const_str_htab, desc->label,
3344 STRHASH (desc->label), NO_INSERT);
3345 if (defstr)
3347 /* If the string is currently deferred but we need to output it now,
3348 remove it from deferred string hash table. */
3349 found = 0;
3350 labelno = (*defstr)->labelno;
3351 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3352 htab_clear_slot (const_str_htab, (void **) defstr);
3356 /* If this is the first time we've seen this particular constant,
3357 output it (or defer its output for later). */
3358 if (! found)
3360 if (defer_addressed_constants_flag || after_function)
3362 struct deferred_constant *p
3363 = (struct deferred_constant *)
3364 xmalloc (sizeof (struct deferred_constant));
3366 p->exp = copy_constant (exp);
3367 p->reloc = reloc;
3368 p->labelno = labelno;
3369 if (after_function)
3371 p->next = after_function_constants;
3372 after_function_constants = p;
3374 else
3376 p->next = deferred_constants;
3377 deferred_constants = p;
3380 else
3382 /* Do no output if -fsyntax-only. */
3383 if (! flag_syntax_only)
3385 if (TREE_CODE (exp) != STRING_CST
3386 || !defer
3387 || flag_writable_strings
3388 || (defstr = (struct deferred_string **)
3389 htab_find_slot_with_hash (const_str_htab,
3390 desc->label,
3391 STRHASH (desc->label),
3392 INSERT)) == NULL)
3393 output_constant_def_contents (exp, reloc, labelno);
3394 else
3396 struct deferred_string *p;
3398 p = (struct deferred_string *)
3399 xmalloc (sizeof (struct deferred_string));
3401 p->exp = copy_constant (exp);
3402 p->label = desc->label;
3403 p->labelno = labelno;
3404 *defstr = p;
3405 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3411 return rtl;
3414 /* Now output assembler code to define the label for EXP,
3415 and follow it with the data of EXP. */
3417 static void
3418 output_constant_def_contents (exp, reloc, labelno)
3419 tree exp;
3420 int reloc;
3421 int labelno;
3423 int align;
3425 /* Align the location counter as required by EXP's data type. */
3426 align = TYPE_ALIGN (TREE_TYPE (exp));
3427 #ifdef CONSTANT_ALIGNMENT
3428 align = CONSTANT_ALIGNMENT (exp, align);
3429 #endif
3431 if (IN_NAMED_SECTION (exp))
3432 named_section (exp, NULL, reloc);
3433 else
3435 /* First switch to text section, except for writable strings. */
3436 #ifdef SELECT_SECTION
3437 SELECT_SECTION (exp, reloc, align);
3438 #else
3439 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3440 || (flag_pic && reloc))
3441 data_section ();
3442 else
3443 readonly_data_section ();
3444 #endif
3447 if (align > BITS_PER_UNIT)
3449 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3452 /* Output the label itself. */
3453 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3455 /* Output the value of EXP. */
3456 output_constant (exp,
3457 (TREE_CODE (exp) == STRING_CST
3458 ? MAX (TREE_STRING_LENGTH (exp),
3459 int_size_in_bytes (TREE_TYPE (exp)))
3460 : int_size_in_bytes (TREE_TYPE (exp))),
3461 align);
3465 /* Structure to represent sufficient information about a constant so that
3466 it can be output when the constant pool is output, so that function
3467 integration can be done, and to simplify handling on machines that reference
3468 constant pool as base+displacement. */
3470 struct pool_constant
3472 struct constant_descriptor *desc;
3473 struct pool_constant *next, *next_sym;
3474 rtx constant;
3475 enum machine_mode mode;
3476 int labelno;
3477 unsigned int align;
3478 HOST_WIDE_INT offset;
3479 int mark;
3482 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3483 The argument is XSTR (... , 0) */
3485 #define SYMHASH(LABEL) \
3486 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3488 /* Initialize constant pool hashing for a new function. */
3490 void
3491 init_varasm_status (f)
3492 struct function *f;
3494 struct varasm_status *p;
3495 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3496 f->varasm = p;
3497 p->x_const_rtx_hash_table
3498 = ((struct constant_descriptor **)
3499 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3500 p->x_const_rtx_sym_hash_table
3501 = ((struct pool_constant **)
3502 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3504 p->x_first_pool = p->x_last_pool = 0;
3505 p->x_pool_offset = 0;
3506 p->x_const_double_chain = 0;
3509 /* Mark PC for GC. */
3511 static void
3512 mark_pool_constant (pc)
3513 struct pool_constant *pc;
3515 while (pc)
3517 ggc_mark (pc);
3518 ggc_mark_rtx (pc->constant);
3519 ggc_mark_rtx (pc->desc->rtl);
3520 pc = pc->next;
3524 /* Mark P for GC. */
3526 void
3527 mark_varasm_status (p)
3528 struct varasm_status *p;
3530 if (p == NULL)
3531 return;
3533 mark_pool_constant (p->x_first_pool);
3534 ggc_mark_rtx (p->x_const_double_chain);
3537 /* Clear out all parts of the state in F that can safely be discarded
3538 after the function has been compiled, to let garbage collection
3539 reclaim the memory. */
3541 void
3542 free_varasm_status (f)
3543 struct function *f;
3545 struct varasm_status *p;
3546 int i;
3548 p = f->varasm;
3550 /* Clear out the hash tables. */
3551 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3553 struct constant_descriptor *cd;
3555 cd = p->x_const_rtx_hash_table[i];
3556 while (cd)
3558 struct constant_descriptor *next = cd->next;
3560 free (cd);
3561 cd = next;
3565 free (p->x_const_rtx_hash_table);
3566 free (p->x_const_rtx_sym_hash_table);
3567 free (p);
3569 f->varasm = NULL;
3573 /* Express an rtx for a constant integer (perhaps symbolic)
3574 as the sum of a symbol or label plus an explicit integer.
3575 They are stored into VALUE. */
3577 static void
3578 decode_rtx_const (mode, x, value)
3579 enum machine_mode mode;
3580 rtx x;
3581 struct rtx_const *value;
3583 /* Clear the whole structure, including any gaps. */
3584 memset (value, 0, sizeof (struct rtx_const));
3586 value->kind = RTX_INT; /* Most usual kind. */
3587 value->mode = mode;
3589 switch (GET_CODE (x))
3591 case CONST_DOUBLE:
3592 value->kind = RTX_DOUBLE;
3593 if (GET_MODE (x) != VOIDmode)
3595 value->mode = GET_MODE (x);
3596 memcpy ((char *) &value->un.du,
3597 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3599 else
3601 value->un.di.low = CONST_DOUBLE_LOW (x);
3602 value->un.di.high = CONST_DOUBLE_HIGH (x);
3604 break;
3606 case CONST_VECTOR:
3608 int units, i;
3609 rtx elt;
3611 units = CONST_VECTOR_NUNITS (x);
3612 value->kind = RTX_VECTOR;
3613 value->mode = mode;
3615 for (i = 0; i < units; ++i)
3617 elt = CONST_VECTOR_ELT (x, i);
3618 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
3620 value->un.veclo[i] = (HOST_WIDE_INT) INTVAL (elt);
3621 value->un.vechi[i] = 0;
3623 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
3625 value->un.veclo[i] = (HOST_WIDE_INT) CONST_DOUBLE_LOW (elt);
3626 value->un.vechi[i] = (HOST_WIDE_INT) CONST_DOUBLE_HIGH (elt);
3628 else
3629 abort ();
3632 break;
3634 case CONST_INT:
3635 value->un.addr.offset = INTVAL (x);
3636 break;
3638 case SYMBOL_REF:
3639 case LABEL_REF:
3640 case PC:
3641 value->un.addr.base = x;
3642 break;
3644 case CONST:
3645 x = XEXP (x, 0);
3646 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3648 value->un.addr.base = XEXP (x, 0);
3649 value->un.addr.offset = INTVAL (XEXP (x, 1));
3651 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3653 value->un.addr.base = XEXP (x, 0);
3654 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3656 else
3658 value->un.addr.base = x;
3659 value->un.addr.offset = 0;
3661 break;
3663 default:
3664 value->kind = RTX_UNKNOWN;
3665 break;
3668 if (value->kind == RTX_INT && value->un.addr.base != 0
3669 && GET_CODE (value->un.addr.base) == UNSPEC)
3671 /* For a simple UNSPEC, the base is set to the
3672 operand, the kind field is set to the index of
3673 the unspec expression.
3674 Together with the code below, in case that
3675 the operand is a SYMBOL_REF or LABEL_REF,
3676 the address of the string or the code_label
3677 is taken as base. */
3678 if (XVECLEN (value->un.addr.base, 0) == 1)
3680 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
3681 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
3685 if (value->kind > RTX_DOUBLE && value->un.addr.base != 0)
3686 switch (GET_CODE (value->un.addr.base))
3688 case SYMBOL_REF:
3689 /* Use the string's address, not the SYMBOL_REF's address,
3690 for the sake of addresses of library routines. */
3691 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3692 break;
3694 case LABEL_REF:
3695 /* For a LABEL_REF, compare labels. */
3696 value->un.addr.base = XEXP (value->un.addr.base, 0);
3698 default:
3699 break;
3703 /* Given a MINUS expression, simplify it if both sides
3704 include the same symbol. */
3707 simplify_subtraction (x)
3708 rtx x;
3710 struct rtx_const val0, val1;
3712 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3713 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3715 if (val0.kind > RTX_DOUBLE
3716 && val0.kind == val1.kind
3717 && val0.un.addr.base == val1.un.addr.base)
3718 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3720 return x;
3723 /* Compute a hash code for a constant RTL expression. */
3725 static int
3726 const_hash_rtx (mode, x)
3727 enum machine_mode mode;
3728 rtx x;
3730 int hi;
3731 size_t i;
3733 struct rtx_const value;
3734 decode_rtx_const (mode, x, &value);
3736 /* Compute hashing function */
3737 hi = 0;
3738 for (i = 0; i < sizeof value / sizeof (int); i++)
3739 hi += ((int *) &value)[i];
3741 hi &= (1 << HASHBITS) - 1;
3742 hi %= MAX_RTX_HASH_TABLE;
3743 return hi;
3746 /* Compare a constant rtl object X with a constant-descriptor DESC.
3747 Return 1 if DESC describes a constant with the same value as X. */
3749 static int
3750 compare_constant_rtx (mode, x, desc)
3751 enum machine_mode mode;
3752 rtx x;
3753 struct constant_descriptor *desc;
3755 int *p = (int *) desc->u.contents;
3756 int *strp;
3757 int len;
3758 struct rtx_const value;
3760 decode_rtx_const (mode, x, &value);
3761 strp = (int *) &value;
3762 len = sizeof value / sizeof (int);
3764 /* Compare constant contents. */
3765 while (--len >= 0)
3766 if (*p++ != *strp++)
3767 return 0;
3769 return 1;
3772 /* Construct a constant descriptor for the rtl-expression X.
3773 It is up to the caller to enter the descriptor in the hash table. */
3775 static struct constant_descriptor *
3776 record_constant_rtx (mode, x)
3777 enum machine_mode mode;
3778 rtx x;
3780 struct constant_descriptor *ptr;
3782 ptr = ((struct constant_descriptor *)
3783 xcalloc (1, (offsetof (struct constant_descriptor, u)
3784 + sizeof (struct rtx_const))));
3785 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3787 return ptr;
3790 /* Given a constant rtx X, return a MEM for the location in memory at which
3791 this constant has been placed. Return 0 if it not has been placed yet. */
3794 mem_for_const_double (x)
3795 rtx x;
3797 enum machine_mode mode = GET_MODE (x);
3798 struct constant_descriptor *desc;
3800 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3801 desc = desc->next)
3802 if (compare_constant_rtx (mode, x, desc))
3803 return desc->rtl;
3805 return 0;
3808 /* Given a constant rtx X, make (or find) a memory constant for its value
3809 and return a MEM rtx to refer to it in memory. */
3812 force_const_mem (mode, x)
3813 enum machine_mode mode;
3814 rtx x;
3816 int hash;
3817 struct constant_descriptor *desc;
3818 char label[256];
3819 rtx def;
3820 struct pool_constant *pool;
3821 unsigned int align;
3823 /* Compute hash code of X. Search the descriptors for that hash code
3824 to see if any of them describes X. If yes, we have an rtx to use. */
3825 hash = const_hash_rtx (mode, x);
3826 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3827 if (compare_constant_rtx (mode, x, desc))
3828 return desc->rtl;
3830 /* No constant equal to X is known to have been output.
3831 Make a constant descriptor to enter X in the hash table
3832 and make a MEM for it. */
3833 desc = record_constant_rtx (mode, x);
3834 desc->next = const_rtx_hash_table[hash];
3835 const_rtx_hash_table[hash] = desc;
3837 /* Align the location counter as required by EXP's data type. */
3838 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3839 #ifdef CONSTANT_ALIGNMENT
3840 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x), align);
3841 #endif
3843 pool_offset += (align / BITS_PER_UNIT) - 1;
3844 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3846 if (GET_CODE (x) == LABEL_REF)
3847 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3849 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3850 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3851 pool->desc = desc;
3852 pool->constant = x;
3853 pool->mode = mode;
3854 pool->labelno = const_labelno;
3855 pool->align = align;
3856 pool->offset = pool_offset;
3857 pool->mark = 1;
3858 pool->next = 0;
3860 if (last_pool == 0)
3861 first_pool = pool;
3862 else
3863 last_pool->next = pool;
3865 last_pool = pool;
3866 pool_offset += GET_MODE_SIZE (mode);
3868 /* Create a string containing the label name, in LABEL. */
3869 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3871 ++const_labelno;
3873 /* Construct the SYMBOL_REF and the MEM. */
3875 pool->desc->rtl = def
3876 = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3877 set_mem_alias_set (def, const_alias_set);
3878 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3879 RTX_UNCHANGING_P (def) = 1;
3881 /* Add label to symbol hash table. */
3882 hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3883 pool->next_sym = const_rtx_sym_hash_table[hash];
3884 const_rtx_sym_hash_table[hash] = pool;
3886 /* Mark the symbol_ref as belonging to this constants pool. */
3887 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3888 current_function_uses_const_pool = 1;
3890 return def;
3893 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3894 the corresponding pool_constant structure. */
3896 static struct pool_constant *
3897 find_pool_constant (f, addr)
3898 struct function *f;
3899 rtx addr;
3901 struct pool_constant *pool;
3902 const char *label = XSTR (addr, 0);
3904 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3905 pool = pool->next_sym)
3906 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3907 return pool;
3909 abort ();
3912 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3915 get_pool_constant (addr)
3916 rtx addr;
3918 return (find_pool_constant (cfun, addr))->constant;
3921 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3922 and whether it has been output or not. */
3925 get_pool_constant_mark (addr, pmarked)
3926 rtx addr;
3927 bool *pmarked;
3929 struct pool_constant *pool = find_pool_constant (cfun, addr);
3930 *pmarked = (pool->mark != 0);
3931 return pool->constant;
3934 /* Likewise, but for the constant pool of a specific function. */
3937 get_pool_constant_for_function (f, addr)
3938 struct function *f;
3939 rtx addr;
3941 return (find_pool_constant (f, addr))->constant;
3944 /* Similar, return the mode. */
3946 enum machine_mode
3947 get_pool_mode (addr)
3948 rtx addr;
3950 return (find_pool_constant (cfun, addr))->mode;
3953 enum machine_mode
3954 get_pool_mode_for_function (f, addr)
3955 struct function *f;
3956 rtx addr;
3958 return (find_pool_constant (f, addr))->mode;
3961 /* Similar, return the offset in the constant pool. */
3964 get_pool_offset (addr)
3965 rtx addr;
3967 return (find_pool_constant (cfun, addr))->offset;
3970 /* Return the size of the constant pool. */
3973 get_pool_size ()
3975 return pool_offset;
3978 /* Write all the constants in the constant pool. */
3980 void
3981 output_constant_pool (fnname, fndecl)
3982 const char *fnname ATTRIBUTE_UNUSED;
3983 tree fndecl ATTRIBUTE_UNUSED;
3985 struct pool_constant *pool;
3986 rtx x;
3987 union real_extract u;
3989 /* It is possible for gcc to call force_const_mem and then to later
3990 discard the instructions which refer to the constant. In such a
3991 case we do not need to output the constant. */
3992 mark_constant_pool ();
3994 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3995 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3996 #endif
3998 for (pool = first_pool; pool; pool = pool->next)
4000 rtx tmp;
4002 x = pool->constant;
4004 if (! pool->mark)
4005 continue;
4007 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4008 whose CODE_LABEL has been deleted. This can occur if a jump table
4009 is eliminated by optimization. If so, write a constant of zero
4010 instead. Note that this can also happen by turning the
4011 CODE_LABEL into a NOTE. */
4012 /* ??? This seems completely and utterly wrong. Certainly it's
4013 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4014 functioning even with INSN_DELETED_P and friends. */
4016 tmp = x;
4017 switch (GET_CODE (x))
4019 case CONST:
4020 if (GET_CODE (XEXP (x, 0)) != PLUS
4021 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
4022 break;
4023 tmp = XEXP (XEXP (x, 0), 0);
4024 /* FALLTHRU */
4026 case LABEL_REF:
4027 tmp = XEXP (x, 0);
4028 if (INSN_DELETED_P (tmp)
4029 || (GET_CODE (tmp) == NOTE
4030 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
4032 abort ();
4033 x = const0_rtx;
4035 break;
4037 default:
4038 break;
4041 /* First switch to correct section. */
4042 #ifdef SELECT_RTX_SECTION
4043 SELECT_RTX_SECTION (pool->mode, x, pool->align);
4044 #else
4045 readonly_data_section ();
4046 #endif
4048 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4049 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4050 pool->align, pool->labelno, done);
4051 #endif
4053 assemble_align (pool->align);
4055 /* Output the label. */
4056 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4058 /* Output the value of the constant itself. */
4059 switch (GET_MODE_CLASS (pool->mode))
4061 case MODE_FLOAT:
4062 if (GET_CODE (x) != CONST_DOUBLE)
4063 abort ();
4065 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4066 assemble_real (u.d, pool->mode, pool->align);
4067 break;
4069 case MODE_INT:
4070 case MODE_PARTIAL_INT:
4071 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4072 break;
4074 case MODE_VECTOR_FLOAT:
4076 int i, units;
4077 rtx elt;
4079 if (GET_CODE (x) != CONST_VECTOR)
4080 abort ();
4082 units = CONST_VECTOR_NUNITS (x);
4084 for (i = 0; i < units; i++)
4086 elt = CONST_VECTOR_ELT (x, i);
4087 memcpy ((char *) &u,
4088 (char *) &CONST_DOUBLE_LOW (elt),
4089 sizeof u);
4090 assemble_real (u.d, GET_MODE_INNER (pool->mode), pool->align);
4093 break;
4095 case MODE_VECTOR_INT:
4097 int i, units;
4098 rtx elt;
4100 if (GET_CODE (x) != CONST_VECTOR)
4101 abort ();
4103 units = CONST_VECTOR_NUNITS (x);
4105 for (i = 0; i < units; i++)
4107 elt = CONST_VECTOR_ELT (x, i);
4108 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
4109 pool->align, 1);
4112 break;
4114 default:
4115 abort ();
4118 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4119 done: ;
4120 #endif
4123 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4124 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4125 #endif
4127 /* Done with this pool. */
4128 first_pool = last_pool = 0;
4131 /* Look through the instructions for this function, and mark all the
4132 entries in the constant pool which are actually being used.
4133 Emit used deferred strings. */
4135 static void
4136 mark_constant_pool ()
4138 rtx insn;
4139 struct pool_constant *pool;
4141 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4142 return;
4144 for (pool = first_pool; pool; pool = pool->next)
4145 pool->mark = 0;
4147 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4148 if (INSN_P (insn))
4149 mark_constants (PATTERN (insn));
4151 for (insn = current_function_epilogue_delay_list;
4152 insn;
4153 insn = XEXP (insn, 1))
4154 if (INSN_P (insn))
4155 mark_constants (PATTERN (insn));
4158 /* Look through appropriate parts of X, marking all entries in the
4159 constant pool which are actually being used. Entries that are only
4160 referenced by other constants are also marked as used. Emit
4161 deferred strings that are used. */
4163 static void
4164 mark_constants (x)
4165 rtx x;
4167 int i;
4168 const char *format_ptr;
4170 if (x == 0)
4171 return;
4173 if (GET_CODE (x) == SYMBOL_REF)
4175 mark_constant (&x, NULL);
4176 return;
4179 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4180 insns, not any notes that may be attached. We don't want to mark
4181 a constant just because it happens to appear in a REG_EQUIV note. */
4182 if (INSN_P (x))
4184 mark_constants (PATTERN (x));
4185 return;
4188 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4190 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4192 switch (*format_ptr++)
4194 case 'e':
4195 mark_constants (XEXP (x, i));
4196 break;
4198 case 'E':
4199 if (XVEC (x, i) != 0)
4201 int j;
4203 for (j = 0; j < XVECLEN (x, i); j++)
4204 mark_constants (XVECEXP (x, i, j));
4206 break;
4208 case 'S':
4209 case 's':
4210 case '0':
4211 case 'i':
4212 case 'w':
4213 case 'n':
4214 case 'u':
4215 break;
4217 default:
4218 abort ();
4223 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4224 to as used. Emit referenced deferred strings. This function can
4225 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4227 static int
4228 mark_constant (current_rtx, data)
4229 rtx *current_rtx;
4230 void *data ATTRIBUTE_UNUSED;
4232 rtx x = *current_rtx;
4234 if (x == NULL_RTX)
4235 return 0;
4237 else if (GET_CODE (x) == SYMBOL_REF)
4239 if (CONSTANT_POOL_ADDRESS_P (x))
4241 struct pool_constant *pool = find_pool_constant (cfun, x);
4242 if (pool->mark == 0) {
4243 pool->mark = 1;
4244 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4246 else
4247 return -1;
4249 else if (STRING_POOL_ADDRESS_P (x))
4251 struct deferred_string **defstr;
4253 defstr = (struct deferred_string **)
4254 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4255 STRHASH (XSTR (x, 0)), NO_INSERT);
4256 if (defstr)
4258 struct deferred_string *p = *defstr;
4260 STRING_POOL_ADDRESS_P (x) = 0;
4261 output_constant_def_contents (p->exp, 0, p->labelno);
4262 htab_clear_slot (const_str_htab, (void **) defstr);
4266 return 0;
4269 /* Find all the constants whose addresses are referenced inside of EXP,
4270 and make sure assembler code with a label has been output for each one.
4271 Indicate whether an ADDR_EXPR has been encountered. */
4273 static int
4274 output_addressed_constants (exp)
4275 tree exp;
4277 int reloc = 0;
4278 tree tem;
4280 /* Give the front-end a chance to convert VALUE to something that
4281 looks more like a constant to the back-end. */
4282 exp = (*lang_hooks.expand_constant) (exp);
4284 switch (TREE_CODE (exp))
4286 case ADDR_EXPR:
4287 /* Go inside any operations that get_inner_reference can handle and see
4288 if what's inside is a constant: no need to do anything here for
4289 addresses of variables or functions. */
4290 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4291 tem = TREE_OPERAND (tem, 0))
4294 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4295 || TREE_CODE (tem) == CONSTRUCTOR)
4296 output_constant_def (tem, 0);
4298 if (TREE_PUBLIC (tem))
4299 reloc |= 2;
4300 else
4301 reloc |= 1;
4302 break;
4304 case PLUS_EXPR:
4305 case MINUS_EXPR:
4306 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4307 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4308 break;
4310 case NOP_EXPR:
4311 case CONVERT_EXPR:
4312 case NON_LVALUE_EXPR:
4313 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4314 break;
4316 case CONSTRUCTOR:
4317 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4318 if (TREE_VALUE (tem) != 0)
4319 reloc |= output_addressed_constants (TREE_VALUE (tem));
4321 break;
4323 default:
4324 break;
4326 return reloc;
4329 /* Return nonzero if VALUE is a valid constant-valued expression
4330 for use in initializing a static variable; one that can be an
4331 element of a "constant" initializer.
4333 Return null_pointer_node if the value is absolute;
4334 if it is relocatable, return the variable that determines the relocation.
4335 We assume that VALUE has been folded as much as possible;
4336 therefore, we do not need to check for such things as
4337 arithmetic-combinations of integers. */
4339 tree
4340 initializer_constant_valid_p (value, endtype)
4341 tree value;
4342 tree endtype;
4344 /* Give the front-end a chance to convert VALUE to something that
4345 looks more like a constant to the back-end. */
4346 value = (*lang_hooks.expand_constant) (value);
4348 switch (TREE_CODE (value))
4350 case CONSTRUCTOR:
4351 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4352 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4353 && TREE_CONSTANT (value)
4354 && CONSTRUCTOR_ELTS (value))
4355 return
4356 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4357 endtype);
4359 return TREE_STATIC (value) ? null_pointer_node : 0;
4361 case INTEGER_CST:
4362 case VECTOR_CST:
4363 case REAL_CST:
4364 case STRING_CST:
4365 case COMPLEX_CST:
4366 return null_pointer_node;
4368 case ADDR_EXPR:
4369 case FDESC_EXPR:
4370 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4372 case VIEW_CONVERT_EXPR:
4373 case NON_LVALUE_EXPR:
4374 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4376 case CONVERT_EXPR:
4377 case NOP_EXPR:
4378 /* Allow conversions between pointer types. */
4379 if (POINTER_TYPE_P (TREE_TYPE (value))
4380 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4381 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4383 /* Allow conversions between real types. */
4384 if (FLOAT_TYPE_P (TREE_TYPE (value))
4385 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4386 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4388 /* Allow length-preserving conversions between integer types. */
4389 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4390 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4391 && (TYPE_PRECISION (TREE_TYPE (value))
4392 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4393 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4395 /* Allow conversions between other integer types only if
4396 explicit value. */
4397 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4398 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4400 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4401 endtype);
4402 if (inner == null_pointer_node)
4403 return null_pointer_node;
4404 break;
4407 /* Allow (int) &foo provided int is as wide as a pointer. */
4408 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4409 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4410 && (TYPE_PRECISION (TREE_TYPE (value))
4411 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4412 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4413 endtype);
4415 /* Likewise conversions from int to pointers, but also allow
4416 conversions from 0. */
4417 if (POINTER_TYPE_P (TREE_TYPE (value))
4418 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4420 if (integer_zerop (TREE_OPERAND (value, 0)))
4421 return null_pointer_node;
4422 else if (TYPE_PRECISION (TREE_TYPE (value))
4423 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4424 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4425 endtype);
4428 /* Allow conversions to union types if the value inside is okay. */
4429 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4430 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4431 endtype);
4432 break;
4434 case PLUS_EXPR:
4435 if (! INTEGRAL_TYPE_P (endtype)
4436 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4438 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4439 endtype);
4440 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4441 endtype);
4442 /* If either term is absolute, use the other terms relocation. */
4443 if (valid0 == null_pointer_node)
4444 return valid1;
4445 if (valid1 == null_pointer_node)
4446 return valid0;
4448 break;
4450 case MINUS_EXPR:
4451 if (! INTEGRAL_TYPE_P (endtype)
4452 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4454 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4455 endtype);
4456 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4457 endtype);
4458 /* Win if second argument is absolute. */
4459 if (valid1 == null_pointer_node)
4460 return valid0;
4461 /* Win if both arguments have the same relocation.
4462 Then the value is absolute. */
4463 if (valid0 == valid1 && valid0 != 0)
4464 return null_pointer_node;
4466 /* Since GCC guarantees that string constants are unique in the
4467 generated code, a subtraction between two copies of the same
4468 constant string is absolute. */
4469 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4470 valid1 && TREE_CODE (valid1) == STRING_CST &&
4471 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4472 return null_pointer_node;
4475 /* Support differences between labels. */
4476 if (INTEGRAL_TYPE_P (endtype))
4478 tree op0, op1;
4479 op0 = TREE_OPERAND (value, 0);
4480 op1 = TREE_OPERAND (value, 1);
4482 /* Like STRIP_NOPS except allow the operand mode to widen.
4483 This works around a feature of fold that simplfies
4484 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4485 that the narrower operation is cheaper. */
4487 while (TREE_CODE (op0) == NOP_EXPR
4488 || TREE_CODE (op0) == CONVERT_EXPR
4489 || TREE_CODE (op0) == NON_LVALUE_EXPR)
4491 tree inner = TREE_OPERAND (op0, 0);
4492 if (inner == error_mark_node
4493 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4494 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
4495 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4496 break;
4497 op0 = inner;
4500 while (TREE_CODE (op1) == NOP_EXPR
4501 || TREE_CODE (op1) == CONVERT_EXPR
4502 || TREE_CODE (op1) == NON_LVALUE_EXPR)
4504 tree inner = TREE_OPERAND (op1, 0);
4505 if (inner == error_mark_node
4506 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4507 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
4508 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
4509 break;
4510 op1 = inner;
4513 if (TREE_CODE (op0) == ADDR_EXPR
4514 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4515 && TREE_CODE (op1) == ADDR_EXPR
4516 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4517 return null_pointer_node;
4519 break;
4521 default:
4522 break;
4525 return 0;
4528 /* Output assembler code for constant EXP to FILE, with no label.
4529 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4530 Assumes output_addressed_constants has been done on EXP already.
4532 Generate exactly SIZE bytes of assembler data, padding at the end
4533 with zeros if necessary. SIZE must always be specified.
4535 SIZE is important for structure constructors,
4536 since trailing members may have been omitted from the constructor.
4537 It is also important for initialization of arrays from string constants
4538 since the full length of the string constant might not be wanted.
4539 It is also needed for initialization of unions, where the initializer's
4540 type is just one member, and that may not be as long as the union.
4542 There a case in which we would fail to output exactly SIZE bytes:
4543 for a structure constructor that wants to produce more than SIZE bytes.
4544 But such constructors will never be generated for any possible input.
4546 ALIGN is the alignment of the data in bits. */
4548 void
4549 output_constant (exp, size, align)
4550 tree exp;
4551 HOST_WIDE_INT size;
4552 unsigned int align;
4554 enum tree_code code;
4555 HOST_WIDE_INT thissize;
4557 /* Some front-ends use constants other than the standard language-indepdent
4558 varieties, but which may still be output directly. Give the front-end a
4559 chance to convert EXP to a language-independent representation. */
4560 exp = (*lang_hooks.expand_constant) (exp);
4562 if (size == 0 || flag_syntax_only)
4563 return;
4565 /* Eliminate any conversions since we'll be outputting the underlying
4566 constant. */
4567 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4568 || TREE_CODE (exp) == NON_LVALUE_EXPR
4569 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4570 exp = TREE_OPERAND (exp, 0);
4572 code = TREE_CODE (TREE_TYPE (exp));
4573 thissize = int_size_in_bytes (TREE_TYPE (exp));
4575 /* Allow a constructor with no elements for any data type.
4576 This means to fill the space with zeros. */
4577 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4579 assemble_zeros (size);
4580 return;
4583 if (TREE_CODE (exp) == FDESC_EXPR)
4585 #ifdef ASM_OUTPUT_FDESC
4586 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4587 tree decl = TREE_OPERAND (exp, 0);
4588 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4589 #else
4590 abort ();
4591 #endif
4592 return;
4595 /* Now output the underlying data. If we've handling the padding, return.
4596 Otherwise, break and ensure THISSIZE is the size written. */
4597 switch (code)
4599 case CHAR_TYPE:
4600 case BOOLEAN_TYPE:
4601 case INTEGER_TYPE:
4602 case ENUMERAL_TYPE:
4603 case POINTER_TYPE:
4604 case REFERENCE_TYPE:
4605 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4606 EXPAND_INITIALIZER),
4607 size, align, 0))
4608 error ("initializer for integer value is too complicated");
4609 break;
4611 case REAL_TYPE:
4612 if (TREE_CODE (exp) != REAL_CST)
4613 error ("initializer for floating value is not a floating constant");
4615 assemble_real (TREE_REAL_CST (exp),
4616 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4617 align);
4618 break;
4620 case COMPLEX_TYPE:
4621 output_constant (TREE_REALPART (exp), thissize / 2, align);
4622 output_constant (TREE_IMAGPART (exp), thissize / 2,
4623 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4624 break;
4626 case ARRAY_TYPE:
4627 case VECTOR_TYPE:
4628 if (TREE_CODE (exp) == CONSTRUCTOR)
4630 output_constructor (exp, size, align);
4631 return;
4633 else if (TREE_CODE (exp) == STRING_CST)
4635 thissize = MIN (TREE_STRING_LENGTH (exp), size);
4636 assemble_string (TREE_STRING_POINTER (exp), thissize);
4638 else
4639 abort ();
4640 break;
4642 case RECORD_TYPE:
4643 case UNION_TYPE:
4644 if (TREE_CODE (exp) == CONSTRUCTOR)
4645 output_constructor (exp, size, align);
4646 else
4647 abort ();
4648 return;
4650 case SET_TYPE:
4651 if (TREE_CODE (exp) == INTEGER_CST)
4652 assemble_integer (expand_expr (exp, NULL_RTX,
4653 VOIDmode, EXPAND_INITIALIZER),
4654 thissize, align, 1);
4655 else if (TREE_CODE (exp) == CONSTRUCTOR)
4657 unsigned char *buffer = (unsigned char *) alloca (thissize);
4658 if (get_set_constructor_bytes (exp, buffer, thissize))
4659 abort ();
4660 assemble_string ((char *) buffer, thissize);
4662 else
4663 error ("unknown set constructor type");
4664 return;
4666 case ERROR_MARK:
4667 return;
4669 default:
4670 abort ();
4673 size -= thissize;
4674 if (size > 0)
4675 assemble_zeros (size);
4679 /* Subroutine of output_constructor, used for computing the size of
4680 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4681 type with an unspecified upper bound. */
4683 static unsigned HOST_WIDE_INT
4684 array_size_for_constructor (val)
4685 tree val;
4687 tree max_index, i;
4689 /* This code used to attempt to handle string constants that are not
4690 arrays of single-bytes, but nothing else does, so there's no point in
4691 doing it here. */
4692 if (TREE_CODE (val) == STRING_CST)
4693 return TREE_STRING_LENGTH (val);
4695 max_index = NULL_TREE;
4696 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4698 tree index = TREE_PURPOSE (i);
4700 if (TREE_CODE (index) == RANGE_EXPR)
4701 index = TREE_OPERAND (index, 1);
4702 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4703 max_index = index;
4706 if (max_index == NULL_TREE)
4707 return 0;
4709 /* Compute the total number of array elements. */
4710 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4711 convert (sizetype,
4712 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4713 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4715 /* Multiply by the array element unit size to find number of bytes. */
4716 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4718 return tree_low_cst (i, 1);
4721 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4722 Generate at least SIZE bytes, padding if necessary. */
4724 static void
4725 output_constructor (exp, size, align)
4726 tree exp;
4727 HOST_WIDE_INT size;
4728 unsigned int align;
4730 tree type = TREE_TYPE (exp);
4731 tree link, field = 0;
4732 tree min_index = 0;
4733 /* Number of bytes output or skipped so far.
4734 In other words, current position within the constructor. */
4735 HOST_WIDE_INT total_bytes = 0;
4736 /* Non-zero means BYTE contains part of a byte, to be output. */
4737 int byte_buffer_in_use = 0;
4738 int byte = 0;
4740 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4741 abort ();
4743 if (TREE_CODE (type) == RECORD_TYPE)
4744 field = TYPE_FIELDS (type);
4746 if (TREE_CODE (type) == ARRAY_TYPE
4747 && TYPE_DOMAIN (type) != 0)
4748 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4750 /* As LINK goes through the elements of the constant,
4751 FIELD goes through the structure fields, if the constant is a structure.
4752 if the constant is a union, then we override this,
4753 by getting the field from the TREE_LIST element.
4754 But the constant could also be an array. Then FIELD is zero.
4756 There is always a maximum of one element in the chain LINK for unions
4757 (even if the initializer in a source program incorrectly contains
4758 more one). */
4759 for (link = CONSTRUCTOR_ELTS (exp);
4760 link;
4761 link = TREE_CHAIN (link),
4762 field = field ? TREE_CHAIN (field) : 0)
4764 tree val = TREE_VALUE (link);
4765 tree index = 0;
4767 /* The element in a union constructor specifies the proper field
4768 or index. */
4769 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4770 || TREE_CODE (type) == QUAL_UNION_TYPE)
4771 && TREE_PURPOSE (link) != 0)
4772 field = TREE_PURPOSE (link);
4774 else if (TREE_CODE (type) == ARRAY_TYPE)
4775 index = TREE_PURPOSE (link);
4777 /* Eliminate the marker that makes a cast not be an lvalue. */
4778 if (val != 0)
4779 STRIP_NOPS (val);
4781 if (index && TREE_CODE (index) == RANGE_EXPR)
4783 unsigned HOST_WIDE_INT fieldsize
4784 = int_size_in_bytes (TREE_TYPE (type));
4785 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4786 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4787 HOST_WIDE_INT index;
4788 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4790 for (index = lo_index; index <= hi_index; index++)
4792 /* Output the element's initial value. */
4793 if (val == 0)
4794 assemble_zeros (fieldsize);
4795 else
4796 output_constant (val, fieldsize, align2);
4798 /* Count its size. */
4799 total_bytes += fieldsize;
4802 else if (field == 0 || !DECL_BIT_FIELD (field))
4804 /* An element that is not a bit-field. */
4806 unsigned HOST_WIDE_INT fieldsize;
4807 /* Since this structure is static,
4808 we know the positions are constant. */
4809 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4810 unsigned int align2;
4812 if (index != 0)
4813 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4814 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4816 /* Output any buffered-up bit-fields preceding this element. */
4817 if (byte_buffer_in_use)
4819 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4820 total_bytes++;
4821 byte_buffer_in_use = 0;
4824 /* Advance to offset of this element.
4825 Note no alignment needed in an array, since that is guaranteed
4826 if each element has the proper size. */
4827 if ((field != 0 || index != 0) && pos != total_bytes)
4829 assemble_zeros (pos - total_bytes);
4830 total_bytes = pos;
4833 /* Find the alignment of this element. */
4834 align2 = min_align (align, BITS_PER_UNIT * pos);
4836 /* Determine size this element should occupy. */
4837 if (field)
4839 fieldsize = 0;
4841 /* If this is an array with an unspecified upper bound,
4842 the initializer determines the size. */
4843 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4844 but we cannot do this until the deprecated support for
4845 initializing zero-length array members is removed. */
4846 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4847 && TYPE_DOMAIN (TREE_TYPE (field))
4848 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4850 fieldsize = array_size_for_constructor (val);
4851 /* Given a non-empty initialization, this field had
4852 better be last. */
4853 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4854 abort ();
4856 else if (DECL_SIZE_UNIT (field))
4858 /* ??? This can't be right. If the decl size overflows
4859 a host integer we will silently emit no data. */
4860 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4861 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4864 else
4865 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4867 /* Output the element's initial value. */
4868 if (val == 0)
4869 assemble_zeros (fieldsize);
4870 else
4871 output_constant (val, fieldsize, align2);
4873 /* Count its size. */
4874 total_bytes += fieldsize;
4876 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4877 error ("invalid initial value for member `%s'",
4878 IDENTIFIER_POINTER (DECL_NAME (field)));
4879 else
4881 /* Element that is a bit-field. */
4883 HOST_WIDE_INT next_offset = int_bit_position (field);
4884 HOST_WIDE_INT end_offset
4885 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4887 if (val == 0)
4888 val = integer_zero_node;
4890 /* If this field does not start in this (or, next) byte,
4891 skip some bytes. */
4892 if (next_offset / BITS_PER_UNIT != total_bytes)
4894 /* Output remnant of any bit field in previous bytes. */
4895 if (byte_buffer_in_use)
4897 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4898 total_bytes++;
4899 byte_buffer_in_use = 0;
4902 /* If still not at proper byte, advance to there. */
4903 if (next_offset / BITS_PER_UNIT != total_bytes)
4905 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4906 total_bytes = next_offset / BITS_PER_UNIT;
4910 if (! byte_buffer_in_use)
4911 byte = 0;
4913 /* We must split the element into pieces that fall within
4914 separate bytes, and combine each byte with previous or
4915 following bit-fields. */
4917 /* next_offset is the offset n fbits from the beginning of
4918 the structure to the next bit of this element to be processed.
4919 end_offset is the offset of the first bit past the end of
4920 this element. */
4921 while (next_offset < end_offset)
4923 int this_time;
4924 int shift;
4925 HOST_WIDE_INT value;
4926 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4927 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4929 /* Advance from byte to byte
4930 within this element when necessary. */
4931 while (next_byte != total_bytes)
4933 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4934 total_bytes++;
4935 byte = 0;
4938 /* Number of bits we can process at once
4939 (all part of the same byte). */
4940 this_time = MIN (end_offset - next_offset,
4941 BITS_PER_UNIT - next_bit);
4942 if (BYTES_BIG_ENDIAN)
4944 /* On big-endian machine, take the most significant bits
4945 first (of the bits that are significant)
4946 and put them into bytes from the most significant end. */
4947 shift = end_offset - next_offset - this_time;
4949 /* Don't try to take a bunch of bits that cross
4950 the word boundary in the INTEGER_CST. We can
4951 only select bits from the LOW or HIGH part
4952 not from both. */
4953 if (shift < HOST_BITS_PER_WIDE_INT
4954 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4956 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4957 shift = HOST_BITS_PER_WIDE_INT;
4960 /* Now get the bits from the appropriate constant word. */
4961 if (shift < HOST_BITS_PER_WIDE_INT)
4962 value = TREE_INT_CST_LOW (val);
4963 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4965 value = TREE_INT_CST_HIGH (val);
4966 shift -= HOST_BITS_PER_WIDE_INT;
4968 else
4969 abort ();
4971 /* Get the result. This works only when:
4972 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4973 byte |= (((value >> shift)
4974 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4975 << (BITS_PER_UNIT - this_time - next_bit));
4977 else
4979 /* On little-endian machines,
4980 take first the least significant bits of the value
4981 and pack them starting at the least significant
4982 bits of the bytes. */
4983 shift = next_offset - int_bit_position (field);
4985 /* Don't try to take a bunch of bits that cross
4986 the word boundary in the INTEGER_CST. We can
4987 only select bits from the LOW or HIGH part
4988 not from both. */
4989 if (shift < HOST_BITS_PER_WIDE_INT
4990 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4991 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4993 /* Now get the bits from the appropriate constant word. */
4994 if (shift < HOST_BITS_PER_WIDE_INT)
4995 value = TREE_INT_CST_LOW (val);
4996 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4998 value = TREE_INT_CST_HIGH (val);
4999 shift -= HOST_BITS_PER_WIDE_INT;
5001 else
5002 abort ();
5004 /* Get the result. This works only when:
5005 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5006 byte |= (((value >> shift)
5007 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
5008 << next_bit);
5011 next_offset += this_time;
5012 byte_buffer_in_use = 1;
5017 if (byte_buffer_in_use)
5019 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
5020 total_bytes++;
5023 if (total_bytes < size)
5024 assemble_zeros (size - total_bytes);
5028 /* This structure contains any weak symbol declarations waiting
5029 to be emitted. */
5030 struct weak_syms
5032 struct weak_syms * next;
5033 tree decl;
5034 const char * name;
5035 const char * value;
5038 static struct weak_syms * weak_decls;
5040 /* Mark weak_decls for garbage collection. */
5042 static void
5043 mark_weak_decls (arg)
5044 void *arg;
5046 struct weak_syms *t;
5048 for (t = *(struct weak_syms **) arg; t != NULL; t = t->next)
5049 ggc_mark_tree (t->decl);
5052 /* Add function NAME to the weak symbols list. VALUE is a weak alias
5053 associated with NAME. */
5056 add_weak (decl, name, value)
5057 tree decl;
5058 const char *name;
5059 const char *value;
5061 struct weak_syms *weak;
5063 weak = (struct weak_syms *) xmalloc (sizeof (struct weak_syms));
5065 if (weak == NULL)
5066 return 0;
5068 weak->next = weak_decls;
5069 weak->decl = decl;
5070 weak->name = name;
5071 weak->value = value;
5072 weak_decls = weak;
5074 return 1;
5077 /* Declare DECL to be a weak symbol. */
5079 void
5080 declare_weak (decl)
5081 tree decl;
5083 if (! TREE_PUBLIC (decl))
5084 error_with_decl (decl, "weak declaration of `%s' must be public");
5085 else if (TREE_ASM_WRITTEN (decl))
5086 error_with_decl (decl, "weak declaration of `%s' must precede definition");
5087 else if (SUPPORTS_WEAK)
5088 add_weak (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
5089 else
5090 warning_with_decl (decl, "weak declaration of `%s' not supported");
5092 DECL_WEAK (decl) = 1;
5095 /* Emit any pending weak declarations. */
5097 void
5098 weak_finish ()
5100 if (SUPPORTS_WEAK)
5102 struct weak_syms *t;
5103 for (t = weak_decls; t != NULL; t = t->next)
5105 #ifdef ASM_WEAKEN_DECL
5106 tree decl = t->decl;
5107 if (decl == NULL_TREE)
5109 tree name = get_identifier (t->name);
5110 if (name)
5111 decl = lookup_name (name);
5113 ASM_WEAKEN_DECL (asm_out_file, decl, t->name, t->value);
5114 #else
5115 #ifdef ASM_OUTPUT_WEAK_ALIAS
5116 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
5117 #else
5118 #ifdef ASM_WEAKEN_LABEL
5119 if (t->value)
5120 abort ();
5121 ASM_WEAKEN_LABEL (asm_out_file, t->name);
5122 #endif
5123 #endif
5124 #endif
5129 /* Remove NAME from the pending list of weak symbols. This prevents
5130 the compiler from emitting multiple .weak directives which confuses
5131 some assemblers. */
5132 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5133 static void
5134 remove_from_pending_weak_list (name)
5135 const char *name;
5137 struct weak_syms *t;
5138 struct weak_syms **p;
5140 for (p = &weak_decls; *p; )
5142 t = *p;
5143 if (strcmp (name, t->name) == 0)
5145 *p = t->next;
5146 free (t);
5148 else
5149 p = &(t->next);
5152 #endif /* defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL) */
5154 /* Emit an assembler directive to make the symbol for DECL an alias to
5155 the symbol for TARGET. */
5157 void
5158 assemble_alias (decl, target)
5159 tree decl, target ATTRIBUTE_UNUSED;
5161 const char *name;
5163 /* We must force creation of DECL_RTL for debug info generation, even though
5164 we don't use it here. */
5165 make_decl_rtl (decl, NULL);
5167 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5169 #ifdef ASM_OUTPUT_DEF
5170 /* Make name accessible from other files, if appropriate. */
5172 if (TREE_PUBLIC (decl))
5174 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5175 if (DECL_WEAK (decl))
5177 #ifdef ASM_WEAKEN_DECL
5178 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
5179 #else
5180 ASM_WEAKEN_LABEL (asm_out_file, name);
5181 #endif
5182 /* Remove this function from the pending weak list so that
5183 we do not emit multiple .weak directives for it. */
5184 remove_from_pending_weak_list
5185 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5187 else
5188 #endif
5189 ASM_GLOBALIZE_LABEL (asm_out_file, name);
5191 maybe_assemble_visibility (decl);
5194 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5195 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5196 #else
5197 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5198 #endif
5199 TREE_ASM_WRITTEN (decl) = 1;
5200 #else /* !ASM_OUTPUT_DEF */
5201 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5202 if (! DECL_WEAK (decl))
5203 warning ("only weak aliases are supported in this configuration");
5205 #ifdef ASM_WEAKEN_DECL
5206 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
5207 #else
5208 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5209 #endif
5210 TREE_ASM_WRITTEN (decl) = 1;
5211 #else
5212 warning ("alias definitions not supported in this configuration; ignored");
5213 #endif
5214 #endif
5217 /* Emit an assembler directive to set symbol for DECL visibility to
5218 VISIBILITY_TYPE. */
5220 void
5221 assemble_visibility (decl, visibility_type)
5222 tree decl;
5223 const char *visibility_type ATTRIBUTE_UNUSED;
5225 const char *name;
5227 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5229 #ifdef HAVE_GAS_HIDDEN
5230 fprintf (asm_out_file, "\t.%s\t%s\n", visibility_type, name);
5231 #else
5232 warning ("visibility attribute not supported in this configuration; ignored");
5233 #endif
5236 /* A helper function to call assemble_visibility when needed for a decl. */
5238 static void
5239 maybe_assemble_visibility (decl)
5240 tree decl;
5242 tree visibility = lookup_attribute ("visibility", DECL_ATTRIBUTES (decl));
5243 if (visibility)
5245 const char *type
5246 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility)));
5247 assemble_visibility (decl, type);
5251 /* Returns 1 if the target configuration supports defining public symbols
5252 so that one of them will be chosen at link time instead of generating a
5253 multiply-defined symbol error, whether through the use of weak symbols or
5254 a target-specific mechanism for having duplicates discarded. */
5257 supports_one_only ()
5259 if (SUPPORTS_ONE_ONLY)
5260 return 1;
5261 return SUPPORTS_WEAK;
5264 /* Set up DECL as a public symbol that can be defined in multiple
5265 translation units without generating a linker error. */
5267 void
5268 make_decl_one_only (decl)
5269 tree decl;
5271 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5272 abort ();
5274 TREE_PUBLIC (decl) = 1;
5276 if (TREE_CODE (decl) == VAR_DECL
5277 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5278 DECL_COMMON (decl) = 1;
5279 else if (SUPPORTS_ONE_ONLY)
5281 #ifdef MAKE_DECL_ONE_ONLY
5282 MAKE_DECL_ONE_ONLY (decl);
5283 #endif
5284 DECL_ONE_ONLY (decl) = 1;
5286 else if (SUPPORTS_WEAK)
5287 DECL_WEAK (decl) = 1;
5288 else
5289 abort ();
5292 void
5293 init_varasm_once ()
5295 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5296 const_str_htab_del);
5297 in_named_htab = htab_create (31, in_named_entry_hash,
5298 in_named_entry_eq, NULL);
5300 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5301 mark_const_hash_entry);
5302 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5303 mark_const_str_htab);
5304 ggc_add_root (&weak_decls, 1, sizeof weak_decls, mark_weak_decls);
5306 const_alias_set = new_alias_set ();
5309 /* Select a set of attributes for section NAME based on the properties
5310 of DECL and whether or not RELOC indicates that DECL's initializer
5311 might contain runtime relocations.
5313 We make the section read-only and executable for a function decl,
5314 read-only for a const data decl, and writable for a non-const data decl. */
5316 unsigned int
5317 default_section_type_flags (decl, name, reloc)
5318 tree decl;
5319 const char *name;
5320 int reloc;
5322 unsigned int flags;
5324 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5325 flags = SECTION_CODE;
5326 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5327 flags = 0;
5328 else
5329 flags = SECTION_WRITE;
5331 if (decl && DECL_ONE_ONLY (decl))
5332 flags |= SECTION_LINKONCE;
5334 if (strcmp (name, ".bss") == 0
5335 || strncmp (name, ".bss.", 5) == 0
5336 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5337 || strcmp (name, ".sbss") == 0
5338 || strncmp (name, ".sbss.", 6) == 0
5339 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5340 flags |= SECTION_BSS;
5342 return flags;
5345 /* Output assembly to switch to section NAME with attribute FLAGS.
5346 Four variants for common object file formats. */
5348 void
5349 default_no_named_section (name, flags)
5350 const char *name ATTRIBUTE_UNUSED;
5351 unsigned int flags ATTRIBUTE_UNUSED;
5353 /* Some object formats don't support named sections at all. The
5354 front-end should already have flagged this as an error. */
5355 abort ();
5358 void
5359 default_elf_asm_named_section (name, flags)
5360 const char *name;
5361 unsigned int flags;
5363 char flagchars[10], *f = flagchars;
5364 const char *type;
5366 if (! named_section_first_declaration (name))
5368 fprintf (asm_out_file, "\t.section\t%s\n", name);
5369 return;
5372 if (!(flags & SECTION_DEBUG))
5373 *f++ = 'a';
5374 if (flags & SECTION_WRITE)
5375 *f++ = 'w';
5376 if (flags & SECTION_CODE)
5377 *f++ = 'x';
5378 if (flags & SECTION_SMALL)
5379 *f++ = 's';
5380 if (flags & SECTION_MERGE)
5381 *f++ = 'M';
5382 if (flags & SECTION_STRINGS)
5383 *f++ = 'S';
5384 *f = '\0';
5386 if (flags & SECTION_BSS)
5387 type = "nobits";
5388 else
5389 type = "progbits";
5391 if (flags & SECTION_ENTSIZE)
5392 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5393 name, flagchars, type, flags & SECTION_ENTSIZE);
5394 else
5395 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5396 name, flagchars, type);
5399 void
5400 default_coff_asm_named_section (name, flags)
5401 const char *name;
5402 unsigned int flags;
5404 char flagchars[8], *f = flagchars;
5406 if (flags & SECTION_WRITE)
5407 *f++ = 'w';
5408 if (flags & SECTION_CODE)
5409 *f++ = 'x';
5410 *f = '\0';
5412 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5415 void
5416 default_pe_asm_named_section (name, flags)
5417 const char *name;
5418 unsigned int flags;
5420 default_coff_asm_named_section (name, flags);
5422 if (flags & SECTION_LINKONCE)
5424 /* Functions may have been compiled at various levels of
5425 optimization so we can't use `same_size' here.
5426 Instead, have the linker pick one. */
5427 fprintf (asm_out_file, "\t.linkonce %s\n",
5428 (flags & SECTION_CODE ? "discard" : "same_size"));
5432 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5433 from SYMBOL is used in all classes derived from SYMBOL. */
5435 void
5436 assemble_vtable_entry (symbol, offset)
5437 rtx symbol;
5438 HOST_WIDE_INT offset;
5440 fputs ("\t.vtable_entry ", asm_out_file);
5441 output_addr_const (asm_out_file, symbol);
5442 fputs (", ", asm_out_file);
5443 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5444 fputc ('\n', asm_out_file);
5447 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5448 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5450 void
5451 assemble_vtable_inherit (child, parent)
5452 rtx child, parent;
5454 fputs ("\t.vtable_inherit ", asm_out_file);
5455 output_addr_const (asm_out_file, child);
5456 fputs (", ", asm_out_file);
5457 output_addr_const (asm_out_file, parent);
5458 fputc ('\n', asm_out_file);