* c-decl.c (duplicate_decls): Conditionalize DECL_SAVED_TREE copy.
[official-gcc.git] / gcc / varasm.c
blob875430f7fc0ba3d4b88fd3d524624957ad98bf18
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
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 "ggc.h"
46 #include "langhooks.h"
47 #include "tm_p.h"
48 #include "debug.h"
49 #include "target.h"
51 #ifdef XCOFF_DEBUGGING_INFO
52 #include "xcoffout.h" /* Needed for external data
53 declarations for e.g. AIX 4.x. */
54 #endif
56 #ifndef TRAMPOLINE_ALIGNMENT
57 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
58 #endif
60 #ifndef ASM_STABS_OP
61 #define ASM_STABS_OP "\t.stabs\t"
62 #endif
64 /* Define the prefix to use when check_memory_usage_flag is enable. */
65 #define CHKR_PREFIX "_CHKR_"
66 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
68 /* The (assembler) name of the first globally-visible object output. */
69 const char *first_global_object_name;
70 const char *weak_global_object_name;
72 extern struct obstack permanent_obstack;
73 #define obstack_chunk_alloc xmalloc
75 struct addr_const;
76 struct constant_descriptor;
77 struct rtx_const;
78 struct pool_constant;
80 #define MAX_RTX_HASH_TABLE 61
82 struct varasm_status
84 /* Hash facility for making memory-constants
85 from constant rtl-expressions. It is used on RISC machines
86 where immediate integer arguments and constant addresses are restricted
87 so that such constants must be stored in memory.
89 This pool of constants is reinitialized for each function
90 so each function gets its own constants-pool that comes right before
91 it. */
92 struct constant_descriptor **x_const_rtx_hash_table;
93 struct pool_constant **x_const_rtx_sym_hash_table;
95 /* Pointers to first and last constant in pool. */
96 struct pool_constant *x_first_pool, *x_last_pool;
98 /* Current offset in constant pool (does not include any machine-specific
99 header). */
100 HOST_WIDE_INT x_pool_offset;
102 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
103 They are chained through the CONST_DOUBLE_CHAIN. */
104 rtx x_const_double_chain;
107 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
108 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
109 #define first_pool (cfun->varasm->x_first_pool)
110 #define last_pool (cfun->varasm->x_last_pool)
111 #define pool_offset (cfun->varasm->x_pool_offset)
112 #define const_double_chain (cfun->varasm->x_const_double_chain)
114 /* Number for making the label on the next
115 constant that is stored in memory. */
117 int const_labelno;
119 /* Number for making the label on the next
120 static variable internal to a function. */
122 int var_labelno;
124 /* Carry information from ASM_DECLARE_OBJECT_NAME
125 to ASM_FINISH_DECLARE_OBJECT. */
127 int size_directive_output;
129 /* The last decl for which assemble_variable was called,
130 if it did ASM_DECLARE_OBJECT_NAME.
131 If the last call to assemble_variable didn't do that,
132 this holds 0. */
134 tree last_assemble_variable_decl;
136 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
137 So giving constant the alias set for the type will allow such
138 initializations to appear to conflict with the load of the constant. We
139 avoid this by giving all constants an alias set for just constants.
140 Since there will be no stores to that a alias set, nothing will ever
141 conflict with them. */
143 static HOST_WIDE_INT const_alias_set;
145 static const char *strip_reg_name PARAMS ((const char *));
146 static int contains_pointers_p PARAMS ((tree));
147 static void assemble_real_1 PARAMS ((PTR));
148 static void decode_addr_const PARAMS ((tree, struct addr_const *));
149 static int const_hash PARAMS ((tree));
150 static int compare_constant PARAMS ((tree,
151 struct constant_descriptor *));
152 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
153 static struct constant_descriptor *record_constant PARAMS ((tree));
154 static void record_constant_1 PARAMS ((tree));
155 static tree copy_constant PARAMS ((tree));
156 static void output_constant_def_contents PARAMS ((tree, int, int));
157 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
158 struct rtx_const *));
159 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
160 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
161 struct constant_descriptor *));
162 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
163 rtx));
164 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
165 static void mark_constant_pool PARAMS ((void));
166 static void mark_constants PARAMS ((rtx));
167 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
168 static int output_addressed_constants PARAMS ((tree));
169 static void output_after_function_constants PARAMS ((void));
170 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
171 static unsigned min_align PARAMS ((unsigned, unsigned));
172 static void output_constructor PARAMS ((tree, HOST_WIDE_INT,
173 unsigned int));
174 #ifdef ASM_WEAKEN_LABEL
175 static void remove_from_pending_weak_list PARAMS ((const char *));
176 #endif
177 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
178 static hashval_t in_named_entry_hash PARAMS ((const PTR));
179 #ifdef ASM_OUTPUT_BSS
180 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
181 #endif
182 #ifdef BSS_SECTION_ASM_OP
183 #ifdef ASM_OUTPUT_ALIGNED_BSS
184 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
185 int, int));
186 #endif
187 #endif /* BSS_SECTION_ASM_OP */
188 static void mark_pool_constant PARAMS ((struct pool_constant *));
189 static void mark_const_hash_entry PARAMS ((void *));
190 static int mark_const_str_htab_1 PARAMS ((void **, void *));
191 static void mark_const_str_htab PARAMS ((void *));
192 static hashval_t const_str_htab_hash PARAMS ((const void *x));
193 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
194 static void const_str_htab_del PARAMS ((void *));
195 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
196 static void resolve_unique_section PARAMS ((tree, int));
198 static enum in_section { no_section, in_text, in_data, in_named
199 #ifdef BSS_SECTION_ASM_OP
200 , in_bss
201 #endif
202 #ifdef CTORS_SECTION_ASM_OP
203 , in_ctors
204 #endif
205 #ifdef DTORS_SECTION_ASM_OP
206 , in_dtors
207 #endif
208 #ifdef EXTRA_SECTIONS
209 , EXTRA_SECTIONS
210 #endif
211 } in_section = no_section;
213 /* Return a non-zero value if DECL has a section attribute. */
214 #ifndef IN_NAMED_SECTION
215 #define IN_NAMED_SECTION(DECL) \
216 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
217 && DECL_SECTION_NAME (DECL) != NULL_TREE)
218 #endif
220 /* Text of section name when in_section == in_named. */
221 static const char *in_named_name;
223 /* Hash table of flags that have been used for a particular named section. */
225 struct in_named_entry
227 const char *name;
228 unsigned int flags;
229 bool declared;
232 static htab_t in_named_htab;
234 /* Define functions like text_section for any extra sections. */
235 #ifdef EXTRA_SECTION_FUNCTIONS
236 EXTRA_SECTION_FUNCTIONS
237 #endif
239 /* Tell assembler to switch to text section. */
241 void
242 text_section ()
244 if (in_section != in_text)
246 #ifdef TEXT_SECTION
247 TEXT_SECTION ();
248 #else
249 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
250 #endif
251 in_section = in_text;
255 /* Tell assembler to switch to data section. */
257 void
258 data_section ()
260 if (in_section != in_data)
262 if (flag_shared_data)
264 #ifdef SHARED_SECTION_ASM_OP
265 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
266 #else
267 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
268 #endif
270 else
271 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
273 in_section = in_data;
276 /* Tell assembler to ALWAYS switch to data section, in case
277 it's not sure where it is. */
279 void
280 force_data_section ()
282 in_section = no_section;
283 data_section ();
286 /* Tell assembler to switch to read-only data section. This is normally
287 the text section. */
289 void
290 readonly_data_section ()
292 #ifdef READONLY_DATA_SECTION
293 READONLY_DATA_SECTION (); /* Note this can call data_section. */
294 #else
295 text_section ();
296 #endif
299 /* Determine if we're in the text section. */
302 in_text_section ()
304 return in_section == in_text;
307 /* Determine if we're in the data section. */
310 in_data_section ()
312 return in_section == in_data;
315 /* Helper routines for maintaining in_named_htab. */
317 static int
318 in_named_entry_eq (p1, p2)
319 const PTR p1;
320 const PTR p2;
322 const struct in_named_entry *old = p1;
323 const char *new = p2;
325 return strcmp (old->name, new) == 0;
328 static hashval_t
329 in_named_entry_hash (p)
330 const PTR p;
332 const struct in_named_entry *old = p;
333 return htab_hash_string (old->name);
336 /* If SECTION has been seen before as a named section, return the flags
337 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
338 set of flags for a section to have, so 0 does not mean that the section
339 has not been seen. */
341 unsigned int
342 get_named_section_flags (section)
343 const char *section;
345 struct in_named_entry **slot;
347 slot = (struct in_named_entry**)
348 htab_find_slot_with_hash (in_named_htab, section,
349 htab_hash_string (section), NO_INSERT);
351 return slot ? (*slot)->flags : 0;
354 /* Returns true if the section has been declared before. Sets internal
355 flag on this section in in_named_hash so subsequent calls on this
356 section will return false. */
358 bool
359 named_section_first_declaration (name)
360 const char *name;
362 struct in_named_entry **slot;
364 slot = (struct in_named_entry**)
365 htab_find_slot_with_hash (in_named_htab, name,
366 htab_hash_string (name), NO_INSERT);
367 if (! (*slot)->declared)
369 (*slot)->declared = true;
370 return true;
372 else
374 return false;
379 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
380 different set of flags, return false. */
382 bool
383 set_named_section_flags (section, flags)
384 const char *section;
385 unsigned int flags;
387 struct in_named_entry **slot, *entry;
389 slot = (struct in_named_entry**)
390 htab_find_slot_with_hash (in_named_htab, section,
391 htab_hash_string (section), INSERT);
392 entry = *slot;
394 if (!entry)
396 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
397 *slot = entry;
398 entry->name = ggc_strdup (section);
399 entry->flags = flags;
400 entry->declared = false;
402 else if (entry->flags != flags)
403 return false;
405 return true;
408 /* Tell assembler to change to section NAME with attributes FLAGS. */
410 void
411 named_section_flags (name, flags)
412 const char *name;
413 unsigned int flags;
415 if (in_section != in_named || strcmp (name, in_named_name) != 0)
417 if (! set_named_section_flags (name, flags))
418 abort ();
420 (* targetm.asm_out.named_section) (name, flags);
422 if (flags & SECTION_FORGET)
423 in_section = no_section;
424 else
426 in_named_name = ggc_strdup (name);
427 in_section = in_named;
432 /* Tell assembler to change to section NAME for DECL.
433 If DECL is NULL, just switch to section NAME.
434 If NAME is NULL, get the name from DECL.
435 If RELOC is 1, the initializer for DECL contains relocs. */
437 void
438 named_section (decl, name, reloc)
439 tree decl;
440 const char *name;
441 int reloc;
443 unsigned int flags;
445 if (decl != NULL_TREE && !DECL_P (decl))
446 abort ();
447 if (name == NULL)
448 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
450 flags = (* targetm.section_type_flags) (decl, name, reloc);
452 /* Sanity check user variables for flag changes. Non-user
453 section flag changes will abort in named_section_flags. */
454 if (decl && ! set_named_section_flags (name, flags))
456 error_with_decl (decl, "%s causes a section type conflict");
457 flags = get_named_section_flags (name);
460 named_section_flags (name, flags);
463 /* If required, set DECL_SECTION_NAME to a unique name. */
465 static void
466 resolve_unique_section (decl, reloc)
467 tree decl;
468 int reloc ATTRIBUTE_UNUSED;
470 if (DECL_SECTION_NAME (decl) == NULL_TREE
471 && (flag_function_sections
472 || (targetm.have_named_sections
473 && DECL_ONE_ONLY (decl))))
474 UNIQUE_SECTION (decl, reloc);
477 #ifdef BSS_SECTION_ASM_OP
479 /* Tell the assembler to switch to the bss section. */
481 void
482 bss_section ()
484 if (in_section != in_bss)
486 #ifdef SHARED_BSS_SECTION_ASM_OP
487 if (flag_shared_data)
488 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
489 else
490 #endif
491 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
493 in_section = in_bss;
497 #ifdef ASM_OUTPUT_BSS
499 /* Utility function for ASM_OUTPUT_BSS for targets to use if
500 they don't support alignments in .bss.
501 ??? It is believed that this function will work in most cases so such
502 support is localized here. */
504 static void
505 asm_output_bss (file, decl, name, size, rounded)
506 FILE *file;
507 tree decl ATTRIBUTE_UNUSED;
508 const char *name;
509 int size ATTRIBUTE_UNUSED, rounded;
511 ASM_GLOBALIZE_LABEL (file, name);
512 bss_section ();
513 #ifdef ASM_DECLARE_OBJECT_NAME
514 last_assemble_variable_decl = decl;
515 ASM_DECLARE_OBJECT_NAME (file, name, decl);
516 #else
517 /* Standard thing is just output label for the object. */
518 ASM_OUTPUT_LABEL (file, name);
519 #endif /* ASM_DECLARE_OBJECT_NAME */
520 ASM_OUTPUT_SKIP (file, rounded);
523 #endif
525 #ifdef ASM_OUTPUT_ALIGNED_BSS
527 /* Utility function for targets to use in implementing
528 ASM_OUTPUT_ALIGNED_BSS.
529 ??? It is believed that this function will work in most cases so such
530 support is localized here. */
532 static void
533 asm_output_aligned_bss (file, decl, name, size, align)
534 FILE *file;
535 tree decl ATTRIBUTE_UNUSED;
536 const char *name;
537 int size, align;
539 ASM_GLOBALIZE_LABEL (file, name);
540 bss_section ();
541 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
542 #ifdef ASM_DECLARE_OBJECT_NAME
543 last_assemble_variable_decl = decl;
544 ASM_DECLARE_OBJECT_NAME (file, name, decl);
545 #else
546 /* Standard thing is just output label for the object. */
547 ASM_OUTPUT_LABEL (file, name);
548 #endif /* ASM_DECLARE_OBJECT_NAME */
549 ASM_OUTPUT_SKIP (file, size ? size : 1);
552 #endif
554 #endif /* BSS_SECTION_ASM_OP */
556 /* Switch to the section for function DECL.
558 If DECL is NULL_TREE, switch to the text section.
559 ??? It's not clear that we will ever be passed NULL_TREE, but it's
560 safer to handle it. */
562 void
563 function_section (decl)
564 tree decl;
566 if (decl != NULL_TREE
567 && DECL_SECTION_NAME (decl) != NULL_TREE)
568 named_section (decl, (char *) 0, 0);
569 else
570 text_section ();
573 /* Switch to section for variable DECL.
575 RELOC is the `reloc' argument to SELECT_SECTION. */
577 void
578 variable_section (decl, reloc)
579 tree decl;
580 int reloc;
582 if (IN_NAMED_SECTION (decl))
583 named_section (decl, NULL, reloc);
584 else
586 /* C++ can have const variables that get initialized from constructors,
587 and thus can not be in a readonly section. We prevent this by
588 verifying that the initial value is constant for objects put in a
589 readonly section.
591 error_mark_node is used by the C front end to indicate that the
592 initializer has not been seen yet. In this case, we assume that
593 the initializer must be constant.
595 C++ uses error_mark_node for variables that have complicated
596 initializers, but these variables go in BSS so we won't be called
597 for them. */
599 #ifdef SELECT_SECTION
600 SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
601 #else
602 if (DECL_READONLY_SECTION (decl, reloc))
603 readonly_data_section ();
604 else
605 data_section ();
606 #endif
610 /* Tell assembler to switch to the section for the exception handling
611 table. */
613 void
614 default_exception_section ()
616 if (targetm.have_named_sections)
617 named_section (NULL_TREE, ".gcc_except_table", 0);
618 else if (flag_pic)
619 data_section ();
620 else
621 readonly_data_section ();
624 /* Tell assembler to switch to the section for string merging. */
626 void
627 mergeable_string_section (decl, align, flags)
628 tree decl ATTRIBUTE_UNUSED;
629 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
630 unsigned int flags ATTRIBUTE_UNUSED;
632 #ifdef HAVE_GAS_SHF_MERGE
633 if (flag_merge_constants
634 && TREE_CODE (decl) == STRING_CST
635 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
636 && align <= 256
637 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
639 enum machine_mode mode;
640 unsigned int modesize;
641 const char *str;
642 int i, j, len, unit;
643 char name[30];
645 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
646 modesize = GET_MODE_BITSIZE (mode);
647 if (modesize >= 8 && modesize <= 256
648 && (modesize & (modesize - 1)) == 0)
650 if (align < modesize)
651 align = modesize;
653 str = TREE_STRING_POINTER (decl);
654 len = TREE_STRING_LENGTH (decl);
655 unit = GET_MODE_SIZE (mode);
657 /* Check for embedded NUL characters. */
658 for (i = 0; i < len; i += unit)
660 for (j = 0; j < unit; j++)
661 if (str [i + j] != '\0')
662 break;
663 if (j == unit)
664 break;
666 if (i == len - unit)
668 sprintf (name, ".rodata.str%d.%d", modesize / 8,
669 (int) (align / 8));
670 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
671 if (!i && modesize < align)
673 /* A "" string with requested alignment greater than
674 character size might cause a problem:
675 if some other string required even bigger
676 alignment than "", then linker might think the
677 "" is just part of padding after some other string
678 and not put it into the hash table initially.
679 But this means "" could have smaller alignment
680 than requested. */
681 #ifdef ASM_OUTPUT_SECTION_START
682 named_section_flags (name, flags);
683 ASM_OUTPUT_SECTION_START (asm_out_file);
684 #else
685 readonly_data_section ();
686 #endif
687 return;
690 named_section_flags (name, flags);
691 return;
695 #endif
696 readonly_data_section ();
699 /* Tell assembler to switch to the section for constant merging. */
701 void
702 mergeable_constant_section (mode, align, flags)
703 enum machine_mode mode ATTRIBUTE_UNUSED;
704 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
705 unsigned int flags ATTRIBUTE_UNUSED;
707 #ifdef HAVE_GAS_SHF_MERGE
708 unsigned int modesize = GET_MODE_BITSIZE (mode);
710 if (flag_merge_constants
711 && mode != VOIDmode
712 && mode != BLKmode
713 && modesize <= align
714 && align >= 8
715 && align <= 256
716 && (align & (align - 1)) == 0)
718 char name[24];
720 sprintf (name, ".rodata.cst%d", (int) (align / 8));
721 flags |= (align / 8) | SECTION_MERGE;
722 named_section_flags (name, flags);
723 return;
725 #endif
726 readonly_data_section ();
729 /* Given NAME, a putative register name, discard any customary prefixes. */
731 static const char *
732 strip_reg_name (name)
733 const char *name;
735 #ifdef REGISTER_PREFIX
736 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
737 name += strlen (REGISTER_PREFIX);
738 #endif
739 if (name[0] == '%' || name[0] == '#')
740 name++;
741 return name;
744 /* Decode an `asm' spec for a declaration as a register name.
745 Return the register number, or -1 if nothing specified,
746 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
747 or -3 if ASMSPEC is `cc' and is not recognized,
748 or -4 if ASMSPEC is `memory' and is not recognized.
749 Accept an exact spelling or a decimal number.
750 Prefixes such as % are optional. */
753 decode_reg_name (asmspec)
754 const char *asmspec;
756 if (asmspec != 0)
758 int i;
760 /* Get rid of confusing prefixes. */
761 asmspec = strip_reg_name (asmspec);
763 /* Allow a decimal number as a "register name". */
764 for (i = strlen (asmspec) - 1; i >= 0; i--)
765 if (! ISDIGIT (asmspec[i]))
766 break;
767 if (asmspec[0] != 0 && i < 0)
769 i = atoi (asmspec);
770 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
771 return i;
772 else
773 return -2;
776 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
777 if (reg_names[i][0]
778 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
779 return i;
781 #ifdef ADDITIONAL_REGISTER_NAMES
783 static const struct { const char *const name; const int number; } table[]
784 = ADDITIONAL_REGISTER_NAMES;
786 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
787 if (! strcmp (asmspec, table[i].name))
788 return table[i].number;
790 #endif /* ADDITIONAL_REGISTER_NAMES */
792 if (!strcmp (asmspec, "memory"))
793 return -4;
795 if (!strcmp (asmspec, "cc"))
796 return -3;
798 return -2;
801 return -1;
804 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
805 have static storage duration. In other words, it should not be an
806 automatic variable, including PARM_DECLs.
808 There is, however, one exception: this function handles variables
809 explicitly placed in a particular register by the user.
811 ASMSPEC, if not 0, is the string which the user specified as the
812 assembler symbol name.
814 This is never called for PARM_DECL nodes. */
816 void
817 make_decl_rtl (decl, asmspec)
818 tree decl;
819 const char *asmspec;
821 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
822 const char *name = 0;
823 const char *new_name = 0;
824 int reg_number;
825 rtx x;
827 /* Check that we are not being given an automatic variable. */
828 /* A weak alias has TREE_PUBLIC set but not the other bits. */
829 if (TREE_CODE (decl) == PARM_DECL
830 || TREE_CODE (decl) == RESULT_DECL
831 || (TREE_CODE (decl) == VAR_DECL
832 && !TREE_STATIC (decl)
833 && !TREE_PUBLIC (decl)
834 && !DECL_EXTERNAL (decl)
835 && !DECL_REGISTER (decl)))
836 abort ();
837 /* And that we were not given a type or a label. */
838 else if (TREE_CODE (decl) == TYPE_DECL
839 || TREE_CODE (decl) == LABEL_DECL)
840 abort ();
842 /* For a duplicate declaration, we can be called twice on the
843 same DECL node. Don't discard the RTL already made. */
844 if (DECL_RTL_SET_P (decl))
846 /* If the old RTL had the wrong mode, fix the mode. */
847 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
849 rtx rtl = DECL_RTL (decl);
850 PUT_MODE (rtl, DECL_MODE (decl));
853 /* ??? Another way to do this would be to do what halfpic.c does
854 and maintain a hashed table of such critters. */
855 /* ??? Another way to do this would be to pass a flag bit to
856 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
857 /* Let the target reassign the RTL if it wants.
858 This is necessary, for example, when one machine specific
859 decl attribute overrides another. */
860 #ifdef REDO_SECTION_INFO_P
861 if (REDO_SECTION_INFO_P (decl))
862 ENCODE_SECTION_INFO (decl);
863 #endif
864 return;
867 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
869 reg_number = decode_reg_name (asmspec);
870 if (reg_number == -2)
872 /* ASMSPEC is given, and not the name of a register. Mark the
873 name with a star so assemble_name won't munge it. */
874 char *starred = alloca (strlen (asmspec) + 2);
875 starred[0] = '*';
876 strcpy (starred + 1, asmspec);
877 new_name = starred;
880 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
882 /* First detect errors in declaring global registers. */
883 if (reg_number == -1)
884 error_with_decl (decl, "register name not specified for `%s'");
885 else if (reg_number < 0)
886 error_with_decl (decl, "invalid register name for `%s'");
887 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
888 error_with_decl (decl,
889 "data type of `%s' isn't suitable for a register");
890 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
891 error_with_decl (decl,
892 "register specified for `%s' isn't suitable for data type");
893 /* Now handle properly declared static register variables. */
894 else
896 int nregs;
898 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
900 DECL_INITIAL (decl) = 0;
901 error ("global register variable has initial value");
903 if (TREE_THIS_VOLATILE (decl))
904 warning ("volatile register variables don't work as you might wish");
906 /* If the user specified one of the eliminables registers here,
907 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
908 confused with that register and be eliminated. Although this
909 usage is somewhat suspect, we nevertheless use the following
910 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
912 SET_DECL_RTL (decl,
913 gen_rtx_REG (DECL_MODE (decl),
914 FIRST_PSEUDO_REGISTER));
915 REGNO (DECL_RTL (decl)) = reg_number;
916 REG_USERVAR_P (DECL_RTL (decl)) = 1;
918 if (TREE_STATIC (decl))
920 /* Make this register global, so not usable for anything
921 else. */
922 #ifdef ASM_DECLARE_REGISTER_GLOBAL
923 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
924 #endif
925 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
926 while (nregs > 0)
927 globalize_reg (reg_number + --nregs);
930 /* As a register variable, it has no section. */
931 return;
935 /* Now handle ordinary static variables and functions (in memory).
936 Also handle vars declared register invalidly. */
938 if (reg_number >= 0 || reg_number == -3)
939 error_with_decl (decl,
940 "register name given for non-register variable `%s'");
942 /* Specifying a section attribute on a variable forces it into a
943 non-.bss section, and thus it cannot be common. */
944 if (TREE_CODE (decl) == VAR_DECL
945 && DECL_SECTION_NAME (decl) != NULL_TREE
946 && DECL_INITIAL (decl) == NULL_TREE
947 && DECL_COMMON (decl))
948 DECL_COMMON (decl) = 0;
950 /* Can't use just the variable's own name for a variable
951 whose scope is less than the whole file, unless it's a member
952 of a local class (which will already be unambiguous).
953 Concatenate a distinguishing number. */
954 if (!top_level && !TREE_PUBLIC (decl)
955 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
956 && asmspec == 0
957 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
959 char *label;
960 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
961 var_labelno++;
962 new_name = label;
965 /* When -fprefix-function-name is used, the functions
966 names are prefixed. Only nested function names are not
967 prefixed. */
968 else if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
970 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
971 char *pname;
973 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
974 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
975 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
976 new_name = pname;
979 if (name != new_name)
981 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
982 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
985 /* If this variable is to be treated as volatile, show its
986 tree node has side effects. */
987 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
988 && TREE_PUBLIC (decl))
989 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
990 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
991 TREE_SIDE_EFFECTS (decl) = 1;
993 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
994 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
995 if (TREE_CODE (decl) != FUNCTION_DECL)
996 set_mem_attributes (x, decl, 1);
997 SET_DECL_RTL (decl, x);
999 /* Optionally set flags or add text to the name to record information
1000 such as that it is a function name.
1001 If the name is changed, the macro ASM_OUTPUT_LABELREF
1002 will have to know how to strip this information. */
1003 #ifdef ENCODE_SECTION_INFO
1004 ENCODE_SECTION_INFO (decl);
1005 #endif
1008 /* Make the rtl for variable VAR be volatile.
1009 Use this only for static variables. */
1011 void
1012 make_var_volatile (var)
1013 tree var;
1015 if (GET_CODE (DECL_RTL (var)) != MEM)
1016 abort ();
1018 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1021 /* Output alignment directive to align for constant expression EXP. */
1023 void
1024 assemble_constant_align (exp)
1025 tree exp;
1027 int align;
1029 /* Align the location counter as required by EXP's data type. */
1030 align = TYPE_ALIGN (TREE_TYPE (exp));
1031 #ifdef CONSTANT_ALIGNMENT
1032 align = CONSTANT_ALIGNMENT (exp, align);
1033 #endif
1035 if (align > BITS_PER_UNIT)
1037 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1041 /* Output a string of literal assembler code
1042 for an `asm' keyword used between functions. */
1044 void
1045 assemble_asm (string)
1046 tree string;
1048 app_enable ();
1050 if (TREE_CODE (string) == ADDR_EXPR)
1051 string = TREE_OPERAND (string, 0);
1053 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1056 /* Record an element in the table of global destructors. SYMBOL is
1057 a SYMBOL_REF of the function to be called; PRIORITY is a number
1058 between 0 and MAX_INIT_PRIORITY. */
1060 void
1061 default_stabs_asm_out_destructor (symbol, priority)
1062 rtx symbol;
1063 int priority ATTRIBUTE_UNUSED;
1065 /* Tell GNU LD that this is part of the static destructor set.
1066 This will work for any system that uses stabs, most usefully
1067 aout systems. */
1068 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1069 assemble_name (asm_out_file, XSTR (symbol, 0));
1070 fputc ('\n', asm_out_file);
1073 void
1074 default_named_section_asm_out_destructor (symbol, priority)
1075 rtx symbol;
1076 int priority;
1078 const char *section = ".dtors";
1079 char buf[16];
1081 /* ??? This only works reliably with the GNU linker. */
1082 if (priority != DEFAULT_INIT_PRIORITY)
1084 sprintf (buf, ".dtors.%.5u",
1085 /* Invert the numbering so the linker puts us in the proper
1086 order; constructors are run from right to left, and the
1087 linker sorts in increasing order. */
1088 MAX_INIT_PRIORITY - priority);
1089 section = buf;
1092 named_section_flags (section, SECTION_WRITE);
1093 assemble_align (POINTER_SIZE);
1094 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1097 #ifdef DTORS_SECTION_ASM_OP
1098 void
1099 dtors_section ()
1101 if (in_section != in_dtors)
1103 in_section = in_dtors;
1104 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1105 fputc ('\n', asm_out_file);
1109 void
1110 default_dtor_section_asm_out_destructor (symbol, priority)
1111 rtx symbol;
1112 int priority ATTRIBUTE_UNUSED;
1114 dtors_section ();
1115 assemble_align (POINTER_SIZE);
1116 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1118 #endif
1120 /* Likewise for global constructors. */
1122 void
1123 default_stabs_asm_out_constructor (symbol, priority)
1124 rtx symbol;
1125 int priority ATTRIBUTE_UNUSED;
1127 /* Tell GNU LD that this is part of the static destructor set.
1128 This will work for any system that uses stabs, most usefully
1129 aout systems. */
1130 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1131 assemble_name (asm_out_file, XSTR (symbol, 0));
1132 fputc ('\n', asm_out_file);
1135 void
1136 default_named_section_asm_out_constructor (symbol, priority)
1137 rtx symbol;
1138 int priority;
1140 const char *section = ".ctors";
1141 char buf[16];
1143 /* ??? This only works reliably with the GNU linker. */
1144 if (priority != DEFAULT_INIT_PRIORITY)
1146 sprintf (buf, ".ctors.%.5u",
1147 /* Invert the numbering so the linker puts us in the proper
1148 order; constructors are run from right to left, and the
1149 linker sorts in increasing order. */
1150 MAX_INIT_PRIORITY - priority);
1151 section = buf;
1154 named_section_flags (section, SECTION_WRITE);
1155 assemble_align (POINTER_SIZE);
1156 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1159 #ifdef CTORS_SECTION_ASM_OP
1160 void
1161 ctors_section ()
1163 if (in_section != in_ctors)
1165 in_section = in_ctors;
1166 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1167 fputc ('\n', asm_out_file);
1171 void
1172 default_ctor_section_asm_out_constructor (symbol, priority)
1173 rtx symbol;
1174 int priority ATTRIBUTE_UNUSED;
1176 ctors_section ();
1177 assemble_align (POINTER_SIZE);
1178 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1180 #endif
1182 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1183 a non-zero value if the constant pool should be output before the
1184 start of the function, or a zero value if the pool should output
1185 after the end of the function. The default is to put it before the
1186 start. */
1188 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1189 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1190 #endif
1192 /* Output assembler code for the constant pool of a function and associated
1193 with defining the name of the function. DECL describes the function.
1194 NAME is the function's name. For the constant pool, we use the current
1195 constant pool data. */
1197 void
1198 assemble_start_function (decl, fnname)
1199 tree decl;
1200 const char *fnname;
1202 int align;
1204 /* The following code does not need preprocessing in the assembler. */
1206 app_disable ();
1208 if (CONSTANT_POOL_BEFORE_FUNCTION)
1209 output_constant_pool (fnname, decl);
1211 resolve_unique_section (decl, 0);
1212 function_section (decl);
1214 /* Tell assembler to move to target machine's alignment for functions. */
1215 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1216 if (align > 0)
1218 ASM_OUTPUT_ALIGN (asm_out_file, align);
1221 /* Handle a user-specified function alignment.
1222 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1223 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1224 if (align_functions_log > align)
1226 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1227 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1228 align_functions_log, align_functions-1);
1229 #else
1230 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1231 #endif
1234 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1235 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1236 #endif
1238 (*debug_hooks->begin_function) (decl);
1240 /* Make function name accessible from other files, if appropriate. */
1242 if (TREE_PUBLIC (decl))
1244 if (! first_global_object_name)
1246 const char *p;
1247 char *name;
1249 STRIP_NAME_ENCODING (p, fnname);
1250 name = permalloc (strlen (p) + 1);
1251 strcpy (name, p);
1253 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1254 first_global_object_name = name;
1255 else
1256 weak_global_object_name = name;
1259 #ifdef ASM_WEAKEN_LABEL
1260 if (DECL_WEAK (decl))
1262 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1263 /* Remove this function from the pending weak list so that
1264 we do not emit multiple .weak directives for it. */
1265 remove_from_pending_weak_list
1266 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1268 else
1269 #endif
1270 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1273 /* Do any machine/system dependent processing of the function name */
1274 #ifdef ASM_DECLARE_FUNCTION_NAME
1275 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1276 #else
1277 /* Standard thing is just output label for the function. */
1278 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1279 #endif /* ASM_DECLARE_FUNCTION_NAME */
1282 /* Output assembler code associated with defining the size of the
1283 function. DECL describes the function. NAME is the function's name. */
1285 void
1286 assemble_end_function (decl, fnname)
1287 tree decl;
1288 const char *fnname;
1290 #ifdef ASM_DECLARE_FUNCTION_SIZE
1291 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1292 #endif
1293 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1295 output_constant_pool (fnname, decl);
1296 function_section (decl); /* need to switch back */
1299 /* Output any constants which should appear after the function. */
1300 output_after_function_constants ();
1303 /* Assemble code to leave SIZE bytes of zeros. */
1305 void
1306 assemble_zeros (size)
1307 int size;
1309 /* Do no output if -fsyntax-only. */
1310 if (flag_syntax_only)
1311 return;
1313 #ifdef ASM_NO_SKIP_IN_TEXT
1314 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1315 so we must output 0s explicitly in the text section. */
1316 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1318 int i;
1319 for (i = 0; i < size; i++)
1320 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1322 else
1323 #endif
1324 if (size > 0)
1325 ASM_OUTPUT_SKIP (asm_out_file, size);
1328 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1330 void
1331 assemble_align (align)
1332 int align;
1334 if (align > BITS_PER_UNIT)
1336 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1340 /* Assemble a string constant with the specified C string as contents. */
1342 void
1343 assemble_string (p, size)
1344 const char *p;
1345 int size;
1347 int pos = 0;
1348 int maximum = 2000;
1350 /* If the string is very long, split it up. */
1352 while (pos < size)
1354 int thissize = size - pos;
1355 if (thissize > maximum)
1356 thissize = maximum;
1358 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1360 pos += thissize;
1361 p += thissize;
1366 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1367 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1368 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1369 #else
1370 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1371 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1372 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1373 #else
1374 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1375 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1376 #endif
1377 #endif
1379 #if defined ASM_OUTPUT_ALIGNED_BSS
1380 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1381 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1382 #else
1383 #if defined ASM_OUTPUT_BSS
1384 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1385 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1386 #else
1387 #undef ASM_EMIT_BSS
1388 #endif
1389 #endif
1391 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1392 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1393 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1394 #else
1395 #if defined ASM_OUTPUT_ALIGNED_COMMON
1396 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1397 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1398 #else
1399 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1400 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1401 #endif
1402 #endif
1404 static void
1405 asm_emit_uninitialised (decl, name, size, rounded)
1406 tree decl;
1407 const char * name;
1408 int size ATTRIBUTE_UNUSED;
1409 int rounded ATTRIBUTE_UNUSED;
1411 enum
1413 asm_dest_common,
1414 asm_dest_bss,
1415 asm_dest_local
1417 destination = asm_dest_local;
1419 if (TREE_PUBLIC (decl))
1421 #if defined ASM_EMIT_BSS
1422 if (! DECL_COMMON (decl))
1423 destination = asm_dest_bss;
1424 else
1425 #endif
1426 destination = asm_dest_common;
1429 if (flag_shared_data)
1431 switch (destination)
1433 #ifdef ASM_OUTPUT_SHARED_BSS
1434 case asm_dest_bss:
1435 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1436 return;
1437 #endif
1438 #ifdef ASM_OUTPUT_SHARED_COMMON
1439 case asm_dest_common:
1440 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1441 return;
1442 #endif
1443 #ifdef ASM_OUTPUT_SHARED_LOCAL
1444 case asm_dest_local:
1445 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1446 return;
1447 #endif
1448 default:
1449 break;
1453 resolve_unique_section (decl, 0);
1455 switch (destination)
1457 #ifdef ASM_EMIT_BSS
1458 case asm_dest_bss:
1459 ASM_EMIT_BSS (decl, name, size, rounded);
1460 break;
1461 #endif
1462 case asm_dest_common:
1463 ASM_EMIT_COMMON (decl, name, size, rounded);
1464 break;
1465 case asm_dest_local:
1466 ASM_EMIT_LOCAL (decl, name, size, rounded);
1467 break;
1468 default:
1469 abort ();
1472 return;
1475 /* Assemble everything that is needed for a variable or function declaration.
1476 Not used for automatic variables, and not used for function definitions.
1477 Should not be called for variables of incomplete structure type.
1479 TOP_LEVEL is nonzero if this variable has file scope.
1480 AT_END is nonzero if this is the special handling, at end of compilation,
1481 to define things that have had only tentative definitions.
1482 DONT_OUTPUT_DATA if nonzero means don't actually output the
1483 initial value (that will be done by the caller). */
1485 void
1486 assemble_variable (decl, top_level, at_end, dont_output_data)
1487 tree decl;
1488 int top_level ATTRIBUTE_UNUSED;
1489 int at_end ATTRIBUTE_UNUSED;
1490 int dont_output_data;
1492 const char *name;
1493 unsigned int align;
1494 int reloc = 0;
1495 rtx decl_rtl;
1497 last_assemble_variable_decl = 0;
1499 /* Normally no need to say anything here for external references,
1500 since assemble_external is called by the language-specific code
1501 when a declaration is first seen. */
1503 if (DECL_EXTERNAL (decl))
1504 return;
1506 /* Output no assembler code for a function declaration.
1507 Only definitions of functions output anything. */
1509 if (TREE_CODE (decl) == FUNCTION_DECL)
1510 return;
1512 /* Do nothing for global register variables. */
1513 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1515 TREE_ASM_WRITTEN (decl) = 1;
1516 return;
1519 /* If type was incomplete when the variable was declared,
1520 see if it is complete now. */
1522 if (DECL_SIZE (decl) == 0)
1523 layout_decl (decl, 0);
1525 /* Still incomplete => don't allocate it; treat the tentative defn
1526 (which is what it must have been) as an `extern' reference. */
1528 if (!dont_output_data && DECL_SIZE (decl) == 0)
1530 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1531 DECL_SOURCE_LINE (decl),
1532 "storage size of `%s' isn't known",
1533 IDENTIFIER_POINTER (DECL_NAME (decl)));
1534 TREE_ASM_WRITTEN (decl) = 1;
1535 return;
1538 /* The first declaration of a variable that comes through this function
1539 decides whether it is global (in C, has external linkage)
1540 or local (in C, has internal linkage). So do nothing more
1541 if this function has already run. */
1543 if (TREE_ASM_WRITTEN (decl))
1544 return;
1546 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1547 decl_rtl = DECL_RTL (decl);
1549 TREE_ASM_WRITTEN (decl) = 1;
1551 /* Do no output if -fsyntax-only. */
1552 if (flag_syntax_only)
1553 return;
1555 app_disable ();
1557 if (! dont_output_data
1558 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1560 error_with_decl (decl, "size of variable `%s' is too large");
1561 return;
1564 name = XSTR (XEXP (decl_rtl, 0), 0);
1565 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1566 && ! first_global_object_name
1567 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1568 || DECL_INITIAL (decl) == error_mark_node))
1569 && ! DECL_WEAK (decl)
1570 && ! DECL_ONE_ONLY (decl))
1572 const char *p;
1573 char *xname;
1575 STRIP_NAME_ENCODING (p, name);
1576 xname = permalloc (strlen (p) + 1);
1577 strcpy (xname, p);
1578 first_global_object_name = xname;
1581 /* Compute the alignment of this data. */
1583 align = DECL_ALIGN (decl);
1585 /* In the case for initialing an array whose length isn't specified,
1586 where we have not yet been able to do the layout,
1587 figure out the proper alignment now. */
1588 if (dont_output_data && DECL_SIZE (decl) == 0
1589 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1590 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1592 /* Some object file formats have a maximum alignment which they support.
1593 In particular, a.out format supports a maximum alignment of 4. */
1594 #ifndef MAX_OFILE_ALIGNMENT
1595 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1596 #endif
1597 if (align > MAX_OFILE_ALIGNMENT)
1599 warning_with_decl (decl,
1600 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1601 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1602 align = MAX_OFILE_ALIGNMENT;
1605 /* On some machines, it is good to increase alignment sometimes. */
1606 if (! DECL_USER_ALIGN (decl))
1608 #ifdef DATA_ALIGNMENT
1609 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1610 #endif
1611 #ifdef CONSTANT_ALIGNMENT
1612 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1613 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1614 #endif
1617 /* Reset the alignment in case we have made it tighter, so we can benefit
1618 from it in get_pointer_alignment. */
1619 DECL_ALIGN (decl) = align;
1620 set_mem_align (decl_rtl, align);
1622 /* Handle uninitialized definitions. */
1624 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1625 /* If the target can't output uninitialized but not common global data
1626 in .bss, then we have to use .data. */
1627 #if ! defined ASM_EMIT_BSS
1628 && DECL_COMMON (decl)
1629 #endif
1630 && DECL_SECTION_NAME (decl) == NULL_TREE
1631 && ! dont_output_data)
1633 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1634 unsigned HOST_WIDE_INT rounded = size;
1636 /* Don't allocate zero bytes of common,
1637 since that means "undefined external" in the linker. */
1638 if (size == 0)
1639 rounded = 1;
1641 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1642 so that each uninitialized object starts on such a boundary. */
1643 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1644 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1645 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1647 /* Don't continue this line--convex cc version 4.1 would lose. */
1648 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1649 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1650 warning_with_decl
1651 (decl, "requested alignment for %s is greater than implemented alignment of %d",rounded);
1652 #endif
1654 asm_emit_uninitialised (decl, name, size, rounded);
1656 return;
1659 /* Handle initialized definitions.
1660 Also handle uninitialized global definitions if -fno-common and the
1661 target doesn't support ASM_OUTPUT_BSS. */
1663 /* First make the assembler name(s) global if appropriate. */
1664 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1666 #ifdef ASM_WEAKEN_LABEL
1667 if (DECL_WEAK (decl))
1669 ASM_WEAKEN_LABEL (asm_out_file, name);
1670 /* Remove this variable from the pending weak list so that
1671 we do not emit multiple .weak directives for it. */
1672 remove_from_pending_weak_list
1673 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1675 else
1676 #endif
1677 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1680 /* Output any data that we will need to use the address of. */
1681 if (DECL_INITIAL (decl) == error_mark_node)
1682 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1683 else if (DECL_INITIAL (decl))
1684 reloc = output_addressed_constants (DECL_INITIAL (decl));
1686 /* Switch to the appropriate section. */
1687 resolve_unique_section (decl, reloc);
1688 variable_section (decl, reloc);
1690 /* dbxout.c needs to know this. */
1691 if (in_text_section ())
1692 DECL_IN_TEXT_SECTION (decl) = 1;
1694 /* Output the alignment of this data. */
1695 if (align > BITS_PER_UNIT)
1697 ASM_OUTPUT_ALIGN (asm_out_file,
1698 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1701 /* Do any machine/system dependent processing of the object. */
1702 #ifdef ASM_DECLARE_OBJECT_NAME
1703 last_assemble_variable_decl = decl;
1704 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1705 #else
1706 /* Standard thing is just output label for the object. */
1707 ASM_OUTPUT_LABEL (asm_out_file, name);
1708 #endif /* ASM_DECLARE_OBJECT_NAME */
1710 if (!dont_output_data)
1712 if (DECL_INITIAL (decl))
1713 /* Output the actual data. */
1714 output_constant (DECL_INITIAL (decl),
1715 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1716 align);
1717 else
1718 /* Leave space for it. */
1719 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1723 /* Return 1 if type TYPE contains any pointers. */
1725 static int
1726 contains_pointers_p (type)
1727 tree type;
1729 switch (TREE_CODE (type))
1731 case POINTER_TYPE:
1732 case REFERENCE_TYPE:
1733 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1734 so I'll play safe and return 1. */
1735 case OFFSET_TYPE:
1736 return 1;
1738 case RECORD_TYPE:
1739 case UNION_TYPE:
1740 case QUAL_UNION_TYPE:
1742 tree fields;
1743 /* For a type that has fields, see if the fields have pointers. */
1744 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1745 if (TREE_CODE (fields) == FIELD_DECL
1746 && contains_pointers_p (TREE_TYPE (fields)))
1747 return 1;
1748 return 0;
1751 case ARRAY_TYPE:
1752 /* An array type contains pointers if its element type does. */
1753 return contains_pointers_p (TREE_TYPE (type));
1755 default:
1756 return 0;
1760 /* Output something to declare an external symbol to the assembler.
1761 (Most assemblers don't need this, so we normally output nothing.)
1762 Do nothing if DECL is not external. */
1764 void
1765 assemble_external (decl)
1766 tree decl ATTRIBUTE_UNUSED;
1768 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1769 main body of this code is only rarely exercised. To provide some
1770 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1771 open. If it's not, we should not be calling this function. */
1772 if (!asm_out_file)
1773 abort ();
1775 #ifdef ASM_OUTPUT_EXTERNAL
1776 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1778 rtx rtl = DECL_RTL (decl);
1780 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1781 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1783 /* Some systems do require some output. */
1784 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1785 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1788 #endif
1791 /* Similar, for calling a library function FUN. */
1793 void
1794 assemble_external_libcall (fun)
1795 rtx fun ATTRIBUTE_UNUSED;
1797 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1798 /* Declare library function name external when first used, if nec. */
1799 if (! SYMBOL_REF_USED (fun))
1801 SYMBOL_REF_USED (fun) = 1;
1802 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1804 #endif
1807 /* Declare the label NAME global. */
1809 void
1810 assemble_global (name)
1811 const char *name ATTRIBUTE_UNUSED;
1813 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1816 /* Assemble a label named NAME. */
1818 void
1819 assemble_label (name)
1820 const char *name;
1822 ASM_OUTPUT_LABEL (asm_out_file, name);
1825 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1826 If NAME starts with a *, the rest of NAME is output verbatim.
1827 Otherwise NAME is transformed in an implementation-defined way
1828 (usually by the addition of an underscore).
1829 Many macros in the tm file are defined to call this function. */
1831 void
1832 assemble_name (file, name)
1833 FILE *file;
1834 const char *name;
1836 const char *real_name;
1837 tree id;
1839 STRIP_NAME_ENCODING (real_name, name);
1840 if (flag_prefix_function_name
1841 && ! memcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1842 real_name = real_name + CHKR_PREFIX_SIZE;
1844 id = maybe_get_identifier (real_name);
1845 if (id)
1846 TREE_SYMBOL_REFERENCED (id) = 1;
1848 if (name[0] == '*')
1849 fputs (&name[1], file);
1850 else
1851 ASM_OUTPUT_LABELREF (file, name);
1854 /* Allocate SIZE bytes writable static space with a gensym name
1855 and return an RTX to refer to its address. */
1858 assemble_static_space (size)
1859 int size;
1861 char name[12];
1862 const char *namestring;
1863 rtx x;
1865 #if 0
1866 if (flag_shared_data)
1867 data_section ();
1868 #endif
1870 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1871 ++const_labelno;
1872 namestring = ggc_strdup (name);
1874 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1876 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1877 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1878 BIGGEST_ALIGNMENT);
1879 #else
1880 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1881 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1882 #else
1884 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1885 so that each uninitialized object starts on such a boundary. */
1886 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1887 int rounded ATTRIBUTE_UNUSED
1888 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1889 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1890 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1891 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1893 #endif
1894 #endif
1895 return x;
1898 /* Assemble the static constant template for function entry trampolines.
1899 This is done at most once per compilation.
1900 Returns an RTX for the address of the template. */
1902 #ifdef TRAMPOLINE_TEMPLATE
1904 assemble_trampoline_template ()
1906 char label[256];
1907 const char *name;
1908 int align;
1910 /* By default, put trampoline templates in read-only data section. */
1912 #ifdef TRAMPOLINE_SECTION
1913 TRAMPOLINE_SECTION ();
1914 #else
1915 readonly_data_section ();
1916 #endif
1918 /* Write the assembler code to define one. */
1919 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1920 if (align > 0)
1922 ASM_OUTPUT_ALIGN (asm_out_file, align);
1925 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1926 TRAMPOLINE_TEMPLATE (asm_out_file);
1928 /* Record the rtl to refer to it. */
1929 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1930 name = ggc_strdup (label);
1931 return gen_rtx_SYMBOL_REF (Pmode, name);
1933 #endif
1935 /* A and B are either alignments or offsets. Return the minimum alignment
1936 that may be assumed after adding the two together. */
1938 static inline unsigned
1939 min_align (a, b)
1940 unsigned int a, b;
1942 return (a | b) & -(a | b);
1945 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1946 the alignment of the integer in bits. Return 1 if we were able to output
1947 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1948 the constant. */
1951 assemble_integer (x, size, align, force)
1952 rtx x;
1953 unsigned int size;
1954 unsigned int align;
1955 int force;
1957 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1958 ASM_OUTPUT... macros. */
1960 if (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT))
1961 switch (size)
1963 #ifdef ASM_OUTPUT_CHAR
1964 case 1:
1965 ASM_OUTPUT_CHAR (asm_out_file, x);
1966 return 1;
1967 #endif
1968 #ifdef ASM_OUTPUT_SHORT
1969 case 2:
1970 ASM_OUTPUT_SHORT (asm_out_file, x);
1971 return 1;
1972 #endif
1973 #ifdef ASM_OUTPUT_INT
1974 case 4:
1975 ASM_OUTPUT_INT (asm_out_file, x);
1976 return 1;
1977 #endif
1978 #ifdef ASM_OUTPUT_DOUBLE_INT
1979 case 8:
1980 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1981 return 1;
1982 #endif
1983 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1984 case 16:
1985 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1986 return 1;
1987 #endif
1989 else
1991 const char *asm_op = NULL;
1993 /* ??? This isn't quite as flexible as the ASM_OUTPUT_INT type hooks.
1994 At present powerpc-eabi can't jump -mrelocatable hoops, so you can
1995 get assembler errors from symbolic references in packed structs. */
1996 switch (size)
1998 #ifdef UNALIGNED_SHORT_ASM_OP
1999 case 2:
2000 asm_op = UNALIGNED_SHORT_ASM_OP;
2001 break;
2002 #endif
2003 #ifdef UNALIGNED_INT_ASM_OP
2004 case 4:
2005 asm_op = UNALIGNED_INT_ASM_OP;
2006 break;
2007 #endif
2008 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
2009 case 8:
2010 asm_op = UNALIGNED_DOUBLE_INT_ASM_OP;
2011 break;
2012 #endif
2015 if (asm_op)
2017 fputs (asm_op, asm_out_file);
2018 output_addr_const (asm_out_file, x);
2019 fputc ('\n', asm_out_file);
2020 return 1;
2024 /* If we couldn't do it that way, there are two other possibilities: First,
2025 if the machine can output an explicit byte and this is a 1 byte constant,
2026 we can use ASM_OUTPUT_BYTE. */
2028 #ifdef ASM_OUTPUT_BYTE
2029 if (size == 1 && GET_CODE (x) == CONST_INT)
2031 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
2032 return 1;
2034 #endif
2036 /* If SIZE is larger than a single word, try to output the constant
2037 one word at a time. */
2039 if (size > UNITS_PER_WORD)
2041 enum machine_mode mode
2042 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2043 unsigned align2 = min_align (align, BITS_PER_WORD);
2044 unsigned int i;
2046 for (i = 0; i < size / UNITS_PER_WORD; i++)
2048 rtx word = operand_subword (x, i, 0, mode);
2049 if (word == 0)
2050 break;
2051 if (! assemble_integer (word, UNITS_PER_WORD, align2, 0))
2052 break;
2055 if (i == size / UNITS_PER_WORD)
2056 return 1;
2057 /* If we output at least one word and then could not finish,
2058 there is no valid way to continue. */
2059 if (i > 0)
2060 abort ();
2063 /* If unaligned, and this is a constant, emit it one byte at a time. */
2064 if (align < size * BITS_PER_UNIT)
2066 enum machine_mode omode, imode;
2067 unsigned int i;
2069 omode = mode_for_size (BITS_PER_UNIT, MODE_INT, 0);
2070 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2072 for (i = 0; i < size; i++)
2074 rtx byte = simplify_subreg (omode, x, imode, i);
2075 if (byte == 0)
2076 break;
2077 if (! assemble_integer (byte, 1, BITS_PER_UNIT, 0))
2078 break;
2081 if (i == size)
2082 return 1;
2083 /* If we output at least one byte and then could not finish,
2084 there is no valid way to continue. */
2085 if (i > 0)
2086 abort ();
2089 if (force)
2090 abort ();
2092 return 0;
2095 /* Assemble the floating-point constant D into an object of size MODE. */
2096 struct assemble_real_args
2098 REAL_VALUE_TYPE *d;
2099 enum machine_mode mode;
2102 static void
2103 assemble_real_1 (p)
2104 PTR p;
2106 struct assemble_real_args *args = (struct assemble_real_args *) p;
2107 REAL_VALUE_TYPE *d = args->d;
2108 enum machine_mode mode = args->mode;
2110 switch (mode)
2112 #ifdef ASM_OUTPUT_BYTE_FLOAT
2113 case QFmode:
2114 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, *d);
2115 break;
2116 #endif
2117 #ifdef ASM_OUTPUT_SHORT_FLOAT
2118 case HFmode:
2119 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, *d);
2120 break;
2121 #endif
2122 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2123 case TQFmode:
2124 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, *d);
2125 break;
2126 #endif
2127 #ifdef ASM_OUTPUT_FLOAT
2128 case SFmode:
2129 ASM_OUTPUT_FLOAT (asm_out_file, *d);
2130 break;
2131 #endif
2133 #ifdef ASM_OUTPUT_DOUBLE
2134 case DFmode:
2135 ASM_OUTPUT_DOUBLE (asm_out_file, *d);
2136 break;
2137 #endif
2139 #ifdef ASM_OUTPUT_LONG_DOUBLE
2140 case XFmode:
2141 case TFmode:
2142 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, *d);
2143 break;
2144 #endif
2146 default:
2147 abort ();
2151 void
2152 assemble_real (d, mode, align)
2153 REAL_VALUE_TYPE d;
2154 enum machine_mode mode;
2155 unsigned int align;
2157 struct assemble_real_args args;
2158 args.d = &d;
2159 args.mode = mode;
2161 /* We cannot emit unaligned floating point constants. This is slightly
2162 complicated in that we don't know what "unaligned" means exactly. */
2163 #ifdef BIGGEST_FIELD_ALIGNMENT
2164 if (align >= BIGGEST_FIELD_ALIGNMENT)
2166 else
2167 #endif
2168 if (align < GET_MODE_ALIGNMENT (mode))
2169 abort ();
2171 if (do_float_handler (assemble_real_1, (PTR) &args))
2172 return;
2174 internal_error ("floating point trap outputting a constant");
2177 /* Here we combine duplicate floating constants to make
2178 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2180 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2181 For an integer, I0 is the low-order word and I1 is the high-order word.
2182 For a real number, I0 is the word with the low address
2183 and I1 is the word with the high address. */
2186 immed_double_const (i0, i1, mode)
2187 HOST_WIDE_INT i0, i1;
2188 enum machine_mode mode;
2190 rtx r;
2192 if (GET_MODE_CLASS (mode) == MODE_INT
2193 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2195 /* We clear out all bits that don't belong in MODE, unless they and our
2196 sign bit are all one. So we get either a reasonable negative value
2197 or a reasonable unsigned value for this mode. */
2198 int width = GET_MODE_BITSIZE (mode);
2199 if (width < HOST_BITS_PER_WIDE_INT
2200 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2201 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2202 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2203 else if (width == HOST_BITS_PER_WIDE_INT
2204 && ! (i1 == ~0 && i0 < 0))
2205 i1 = 0;
2206 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2207 /* We cannot represent this value as a constant. */
2208 abort ();
2210 /* If this would be an entire word for the target, but is not for
2211 the host, then sign-extend on the host so that the number will look
2212 the same way on the host that it would on the target.
2214 For example, when building a 64 bit alpha hosted 32 bit sparc
2215 targeted compiler, then we want the 32 bit unsigned value -1 to be
2216 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2217 The later confuses the sparc backend. */
2219 if (width < HOST_BITS_PER_WIDE_INT
2220 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2221 i0 |= ((HOST_WIDE_INT) (-1) << width);
2223 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2225 ??? Strictly speaking, this is wrong if we create a CONST_INT
2226 for a large unsigned constant with the size of MODE being
2227 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2228 wider mode. In that case we will mis-interpret it as a negative
2229 number.
2231 Unfortunately, the only alternative is to make a CONST_DOUBLE
2232 for any constant in any mode if it is an unsigned constant larger
2233 than the maximum signed integer in an int on the host. However,
2234 doing this will break everyone that always expects to see a CONST_INT
2235 for SImode and smaller.
2237 We have always been making CONST_INTs in this case, so nothing new
2238 is being broken. */
2240 if (width <= HOST_BITS_PER_WIDE_INT)
2241 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2243 /* If this integer fits in one word, return a CONST_INT. */
2244 if ((i1 == 0 && i0 >= 0)
2245 || (i1 == ~0 && i0 < 0))
2246 return GEN_INT (i0);
2248 /* We use VOIDmode for integers. */
2249 mode = VOIDmode;
2252 /* Search the chain for an existing CONST_DOUBLE with the right value.
2253 If one is found, return it. */
2254 if (cfun != 0)
2255 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2256 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2257 && GET_MODE (r) == mode)
2258 return r;
2260 /* No; make a new one and add it to the chain. */
2261 r = gen_rtx_CONST_DOUBLE (mode, i0, i1);
2263 /* Don't touch const_double_chain if not inside any function. */
2264 if (current_function_decl != 0)
2266 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2267 const_double_chain = r;
2270 return r;
2273 /* Return a CONST_DOUBLE for a specified `double' value
2274 and machine mode. */
2277 immed_real_const_1 (d, mode)
2278 REAL_VALUE_TYPE d;
2279 enum machine_mode mode;
2281 union real_extract u;
2282 rtx r;
2284 /* Get the desired `double' value as a sequence of ints
2285 since that is how they are stored in a CONST_DOUBLE. */
2287 u.d = d;
2289 /* Detect special cases. Check for NaN first, because some ports
2290 (specifically the i386) do not emit correct ieee-fp code by default, and
2291 thus will generate a core dump here if we pass a NaN to REAL_VALUES_EQUAL
2292 and if REAL_VALUES_EQUAL does a floating point comparison. */
2293 if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_IDENTICAL (dconst0, d))
2294 return CONST0_RTX (mode);
2295 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2296 return CONST1_RTX (mode);
2297 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst2, d))
2298 return CONST2_RTX (mode);
2300 if (sizeof u == sizeof (HOST_WIDE_INT))
2301 return immed_double_const (u.i[0], 0, mode);
2302 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2303 return immed_double_const (u.i[0], u.i[1], mode);
2305 /* The rest of this function handles the case where
2306 a float value requires more than 2 ints of space.
2307 It will be deleted as dead code on machines that don't need it. */
2309 /* Search the chain for an existing CONST_DOUBLE with the right value.
2310 If one is found, return it. */
2311 if (cfun != 0)
2312 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2313 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2314 && GET_MODE (r) == mode)
2315 return r;
2317 /* No; make a new one and add it to the chain.
2319 We may be called by an optimizer which may be discarding any memory
2320 allocated during its processing (such as combine and loop). However,
2321 we will be leaving this constant on the chain, so we cannot tolerate
2322 freed memory. */
2323 r = rtx_alloc (CONST_DOUBLE);
2324 PUT_MODE (r, mode);
2325 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2327 /* If we aren't inside a function, don't put r on the
2328 const_double_chain. */
2329 if (current_function_decl != 0)
2331 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2332 const_double_chain = r;
2334 else
2335 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2337 return r;
2340 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2341 which must be a REAL_CST tree node. */
2344 immed_real_const (exp)
2345 tree exp;
2347 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2350 /* At the end of a function, forget the memory-constants
2351 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2352 Also clear out real_constant_chain and clear out all the chain-pointers. */
2354 void
2355 clear_const_double_mem ()
2357 rtx r, next;
2359 for (r = const_double_chain; r; r = next)
2361 next = CONST_DOUBLE_CHAIN (r);
2362 CONST_DOUBLE_CHAIN (r) = 0;
2364 const_double_chain = 0;
2367 /* Given an expression EXP with a constant value,
2368 reduce it to the sum of an assembler symbol and an integer.
2369 Store them both in the structure *VALUE.
2370 Abort if EXP does not reduce. */
2372 struct addr_const
2374 rtx base;
2375 HOST_WIDE_INT offset;
2378 static void
2379 decode_addr_const (exp, value)
2380 tree exp;
2381 struct addr_const *value;
2383 tree target = TREE_OPERAND (exp, 0);
2384 int offset = 0;
2385 rtx x;
2387 while (1)
2389 if (TREE_CODE (target) == COMPONENT_REF
2390 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2393 offset += int_byte_position (TREE_OPERAND (target, 1));
2394 target = TREE_OPERAND (target, 0);
2396 else if (TREE_CODE (target) == ARRAY_REF
2397 || TREE_CODE (target) == ARRAY_RANGE_REF)
2399 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2400 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2401 target = TREE_OPERAND (target, 0);
2403 else
2404 break;
2407 switch (TREE_CODE (target))
2409 case VAR_DECL:
2410 case FUNCTION_DECL:
2411 x = DECL_RTL (target);
2412 break;
2414 case LABEL_DECL:
2415 x = gen_rtx_MEM (FUNCTION_MODE,
2416 gen_rtx_LABEL_REF (VOIDmode,
2417 label_rtx (TREE_OPERAND (exp, 0))));
2418 break;
2420 case REAL_CST:
2421 case STRING_CST:
2422 case COMPLEX_CST:
2423 case CONSTRUCTOR:
2424 case INTEGER_CST:
2425 x = TREE_CST_RTL (target);
2426 break;
2428 default:
2429 abort ();
2432 if (GET_CODE (x) != MEM)
2433 abort ();
2434 x = XEXP (x, 0);
2436 value->base = x;
2437 value->offset = offset;
2440 enum kind { RTX_DOUBLE, RTX_INT };
2441 struct rtx_const
2443 ENUM_BITFIELD(kind) kind : 16;
2444 ENUM_BITFIELD(machine_mode) mode : 16;
2445 union {
2446 union real_extract du;
2447 struct addr_const addr;
2448 struct {HOST_WIDE_INT high, low;} di;
2449 } un;
2452 /* Uniquize all constants that appear in memory.
2453 Each constant in memory thus far output is recorded
2454 in `const_hash_table' with a `struct constant_descriptor'
2455 that contains a polish representation of the value of
2456 the constant.
2458 We cannot store the trees in the hash table
2459 because the trees may be temporary. */
2461 struct constant_descriptor
2463 struct constant_descriptor *next;
2464 const char *label;
2465 rtx rtl;
2466 /* Make sure the data is reasonably aligned. */
2467 union
2469 unsigned char contents[1];
2470 #ifdef HAVE_LONG_DOUBLE
2471 long double d;
2472 #else
2473 double d;
2474 #endif
2475 } u;
2478 #define HASHBITS 30
2479 #define MAX_HASH_TABLE 1009
2480 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2482 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2483 out a string constant, we defer output of the constants until we know
2484 they are actually used. This will be if something takes its address or if
2485 there is a usage of the string in the RTL of a function. */
2487 #define STRHASH(x) ((hashval_t)((long)(x) >> 3))
2489 struct deferred_string
2491 const char *label;
2492 tree exp;
2493 int labelno;
2496 static htab_t const_str_htab;
2498 /* Mark a const_hash_table descriptor for GC. */
2500 static void
2501 mark_const_hash_entry (ptr)
2502 void *ptr;
2504 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2506 while (desc)
2508 ggc_mark_rtx (desc->rtl);
2509 desc = desc->next;
2513 /* Mark the hash-table element X (which is really a pointer to an
2514 struct deferred_string *). */
2516 static int
2517 mark_const_str_htab_1 (x, data)
2518 void **x;
2519 void *data ATTRIBUTE_UNUSED;
2521 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2522 return 1;
2525 /* Mark a const_str_htab for GC. */
2527 static void
2528 mark_const_str_htab (htab)
2529 void *htab;
2531 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2534 /* Returns a hash code for X (which is a really a
2535 struct deferred_string *). */
2537 static hashval_t
2538 const_str_htab_hash (x)
2539 const void *x;
2541 return STRHASH (((const struct deferred_string *) x)->label);
2544 /* Returns non-zero if the value represented by X (which is really a
2545 struct deferred_string *) is the same as that given by Y
2546 (which is really a char *). */
2548 static int
2549 const_str_htab_eq (x, y)
2550 const void *x;
2551 const void *y;
2553 return (((const struct deferred_string *) x)->label == (const char *) y);
2556 /* Delete the hash table entry dfsp. */
2558 static void
2559 const_str_htab_del (dfsp)
2560 void *dfsp;
2562 free (dfsp);
2565 /* Compute a hash code for a constant expression. */
2567 static int
2568 const_hash (exp)
2569 tree exp;
2571 const char *p;
2572 int len, hi, i;
2573 enum tree_code code = TREE_CODE (exp);
2575 /* Either set P and LEN to the address and len of something to hash and
2576 exit the switch or return a value. */
2578 switch (code)
2580 case INTEGER_CST:
2581 p = (char *) &TREE_INT_CST (exp);
2582 len = sizeof TREE_INT_CST (exp);
2583 break;
2585 case REAL_CST:
2586 p = (char *) &TREE_REAL_CST (exp);
2587 len = sizeof TREE_REAL_CST (exp);
2588 break;
2590 case STRING_CST:
2591 p = TREE_STRING_POINTER (exp);
2592 len = TREE_STRING_LENGTH (exp);
2593 break;
2595 case COMPLEX_CST:
2596 return (const_hash (TREE_REALPART (exp)) * 5
2597 + const_hash (TREE_IMAGPART (exp)));
2599 case CONSTRUCTOR:
2600 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2602 char *tmp;
2604 len = int_size_in_bytes (TREE_TYPE (exp));
2605 tmp = (char *) alloca (len);
2606 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2607 p = tmp;
2608 break;
2610 else
2612 tree link;
2614 /* For record type, include the type in the hashing.
2615 We do not do so for array types
2616 because (1) the sizes of the elements are sufficient
2617 and (2) distinct array types can have the same constructor.
2618 Instead, we include the array size because the constructor could
2619 be shorter. */
2620 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2621 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2622 % MAX_HASH_TABLE;
2623 else
2624 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2625 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2627 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2628 if (TREE_VALUE (link))
2630 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2632 return hi;
2635 case ADDR_EXPR:
2637 struct addr_const value;
2639 decode_addr_const (exp, &value);
2640 if (GET_CODE (value.base) == SYMBOL_REF)
2642 /* Don't hash the address of the SYMBOL_REF;
2643 only use the offset and the symbol name. */
2644 hi = value.offset;
2645 p = XSTR (value.base, 0);
2646 for (i = 0; p[i] != 0; i++)
2647 hi = ((hi * 613) + (unsigned) (p[i]));
2649 else if (GET_CODE (value.base) == LABEL_REF)
2650 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2651 else
2652 abort();
2654 hi &= (1 << HASHBITS) - 1;
2655 hi %= MAX_HASH_TABLE;
2657 return hi;
2659 case PLUS_EXPR:
2660 case MINUS_EXPR:
2661 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2662 + const_hash (TREE_OPERAND (exp, 1)));
2664 case NOP_EXPR:
2665 case CONVERT_EXPR:
2666 case NON_LVALUE_EXPR:
2667 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2669 default:
2670 /* A language specific constant. Just hash the code. */
2671 return (int) code % MAX_HASH_TABLE;
2674 /* Compute hashing function */
2675 hi = len;
2676 for (i = 0; i < len; i++)
2677 hi = ((hi * 613) + (unsigned) (p[i]));
2679 hi &= (1 << HASHBITS) - 1;
2680 hi %= MAX_HASH_TABLE;
2681 return hi;
2684 /* Compare a constant expression EXP with a constant-descriptor DESC.
2685 Return 1 if DESC describes a constant with the same value as EXP. */
2687 static int
2688 compare_constant (exp, desc)
2689 tree exp;
2690 struct constant_descriptor *desc;
2692 return 0 != compare_constant_1 (exp, desc->u.contents);
2695 /* Compare constant expression EXP with a substring P of a constant descriptor.
2696 If they match, return a pointer to the end of the substring matched.
2697 If they do not match, return 0.
2699 Since descriptors are written in polish prefix notation,
2700 this function can be used recursively to test one operand of EXP
2701 against a subdescriptor, and if it succeeds it returns the
2702 address of the subdescriptor for the next operand. */
2704 static const unsigned char *
2705 compare_constant_1 (exp, p)
2706 tree exp;
2707 const unsigned char *p;
2709 const unsigned char *strp;
2710 int len;
2711 enum tree_code code = TREE_CODE (exp);
2713 if (code != (enum tree_code) *p++)
2714 return 0;
2716 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2717 switch, or return the result of the comparison. */
2719 switch (code)
2721 case INTEGER_CST:
2722 /* Integer constants are the same only if the same width of type. */
2723 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2724 return 0;
2726 strp = (unsigned char *) &TREE_INT_CST (exp);
2727 len = sizeof TREE_INT_CST (exp);
2728 break;
2730 case REAL_CST:
2731 /* Real constants are the same only if the same width of type. */
2732 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2733 return 0;
2735 strp = (unsigned char *) &TREE_REAL_CST (exp);
2736 len = sizeof TREE_REAL_CST (exp);
2737 break;
2739 case STRING_CST:
2740 if (flag_writable_strings)
2741 return 0;
2743 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2744 return 0;
2746 strp = (const unsigned char *)TREE_STRING_POINTER (exp);
2747 len = TREE_STRING_LENGTH (exp);
2748 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2749 sizeof TREE_STRING_LENGTH (exp)))
2750 return 0;
2752 p += sizeof TREE_STRING_LENGTH (exp);
2753 break;
2755 case COMPLEX_CST:
2756 p = compare_constant_1 (TREE_REALPART (exp), p);
2757 if (p == 0)
2758 return 0;
2760 return compare_constant_1 (TREE_IMAGPART (exp), p);
2762 case CONSTRUCTOR:
2763 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2765 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2766 unsigned char *tmp = (unsigned char *) alloca (len);
2768 get_set_constructor_bytes (exp, tmp, len);
2769 strp = (unsigned char *) tmp;
2770 if (memcmp ((char *) &xlen, p, sizeof xlen))
2771 return 0;
2773 p += sizeof xlen;
2774 break;
2776 else
2778 tree link;
2779 int length = list_length (CONSTRUCTOR_ELTS (exp));
2780 tree type;
2781 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2782 int have_purpose = 0;
2784 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2785 if (TREE_PURPOSE (link))
2786 have_purpose = 1;
2788 if (memcmp ((char *) &length, p, sizeof length))
2789 return 0;
2791 p += sizeof length;
2793 /* For record constructors, insist that the types match.
2794 For arrays, just verify both constructors are for arrays.
2795 Then insist that either both or none have any TREE_PURPOSE
2796 values. */
2797 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2798 type = TREE_TYPE (exp);
2799 else
2800 type = 0;
2802 if (memcmp ((char *) &type, p, sizeof type))
2803 return 0;
2805 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2807 if (memcmp ((char *) &mode, p, sizeof mode))
2808 return 0;
2810 p += sizeof mode;
2813 p += sizeof type;
2815 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2816 return 0;
2818 p += sizeof have_purpose;
2820 /* For arrays, insist that the size in bytes match. */
2821 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2823 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2825 if (memcmp ((char *) &size, p, sizeof size))
2826 return 0;
2828 p += sizeof size;
2831 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2833 if (TREE_VALUE (link))
2835 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2836 return 0;
2838 else
2840 tree zero = 0;
2842 if (memcmp ((char *) &zero, p, sizeof zero))
2843 return 0;
2845 p += sizeof zero;
2848 if (TREE_PURPOSE (link)
2849 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2851 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2852 sizeof TREE_PURPOSE (link)))
2853 return 0;
2855 p += sizeof TREE_PURPOSE (link);
2857 else if (TREE_PURPOSE (link))
2859 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2860 return 0;
2862 else if (have_purpose)
2864 int zero = 0;
2866 if (memcmp ((char *) &zero, p, sizeof zero))
2867 return 0;
2869 p += sizeof zero;
2873 return p;
2876 case ADDR_EXPR:
2878 struct addr_const value;
2880 decode_addr_const (exp, &value);
2881 strp = (unsigned char *) &value.offset;
2882 len = sizeof value.offset;
2883 /* Compare the offset. */
2884 while (--len >= 0)
2885 if (*p++ != *strp++)
2886 return 0;
2888 /* Compare symbol name. */
2889 strp = (const unsigned char *) XSTR (value.base, 0);
2890 len = strlen ((const char *) strp) + 1;
2892 break;
2894 case PLUS_EXPR:
2895 case MINUS_EXPR:
2896 case RANGE_EXPR:
2897 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2898 if (p == 0)
2899 return 0;
2901 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2903 case NOP_EXPR:
2904 case CONVERT_EXPR:
2905 case NON_LVALUE_EXPR:
2906 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2908 default:
2910 tree new = (*lang_hooks.expand_constant) (exp);
2912 if (new != exp)
2913 return compare_constant_1 (new, p);
2914 else
2915 return 0;
2919 /* Compare constant contents. */
2920 while (--len >= 0)
2921 if (*p++ != *strp++)
2922 return 0;
2924 return p;
2927 /* Construct a constant descriptor for the expression EXP.
2928 It is up to the caller to enter the descriptor in the hash table. */
2930 static struct constant_descriptor *
2931 record_constant (exp)
2932 tree exp;
2934 struct constant_descriptor *next = 0;
2935 char *label = 0;
2936 rtx rtl = 0;
2937 int pad;
2939 /* Make a struct constant_descriptor. The first three pointers will
2940 be filled in later. Here we just leave space for them. */
2942 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2943 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2944 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2946 /* Align the descriptor for the data payload. */
2947 pad = (offsetof (struct constant_descriptor, u)
2948 - offsetof(struct constant_descriptor, rtl)
2949 - sizeof(next->rtl));
2950 if (pad > 0)
2951 obstack_blank (&permanent_obstack, pad);
2953 record_constant_1 (exp);
2954 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2957 /* Add a description of constant expression EXP
2958 to the object growing in `permanent_obstack'.
2959 No need to return its address; the caller will get that
2960 from the obstack when the object is complete. */
2962 static void
2963 record_constant_1 (exp)
2964 tree exp;
2966 const unsigned char *strp;
2967 int len;
2968 enum tree_code code = TREE_CODE (exp);
2970 obstack_1grow (&permanent_obstack, (unsigned int) code);
2972 switch (code)
2974 case INTEGER_CST:
2975 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2976 strp = (unsigned char *) &TREE_INT_CST (exp);
2977 len = sizeof TREE_INT_CST (exp);
2978 break;
2980 case REAL_CST:
2981 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2982 strp = (unsigned char *) &TREE_REAL_CST (exp);
2983 len = sizeof TREE_REAL_CST (exp);
2984 break;
2986 case STRING_CST:
2987 if (flag_writable_strings)
2988 return;
2990 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2991 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2992 len = TREE_STRING_LENGTH (exp);
2993 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2994 sizeof TREE_STRING_LENGTH (exp));
2995 break;
2997 case COMPLEX_CST:
2998 record_constant_1 (TREE_REALPART (exp));
2999 record_constant_1 (TREE_IMAGPART (exp));
3000 return;
3002 case CONSTRUCTOR:
3003 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3005 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
3006 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
3007 obstack_blank (&permanent_obstack, nbytes);
3008 get_set_constructor_bytes
3009 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
3010 nbytes);
3011 return;
3013 else
3015 tree link;
3016 int length = list_length (CONSTRUCTOR_ELTS (exp));
3017 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
3018 tree type;
3019 int have_purpose = 0;
3021 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3022 if (TREE_PURPOSE (link))
3023 have_purpose = 1;
3025 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
3027 /* For record constructors, insist that the types match.
3028 For arrays, just verify both constructors are for arrays
3029 of the same mode. Then insist that either both or none
3030 have any TREE_PURPOSE values. */
3031 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3032 type = TREE_TYPE (exp);
3033 else
3034 type = 0;
3036 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
3037 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3038 obstack_grow (&permanent_obstack, &mode, sizeof mode);
3040 obstack_grow (&permanent_obstack, (char *) &have_purpose,
3041 sizeof have_purpose);
3043 /* For arrays, insist that the size in bytes match. */
3044 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3046 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3047 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
3050 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3052 if (TREE_VALUE (link))
3053 record_constant_1 (TREE_VALUE (link));
3054 else
3056 tree zero = 0;
3058 obstack_grow (&permanent_obstack,
3059 (char *) &zero, sizeof zero);
3062 if (TREE_PURPOSE (link)
3063 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
3064 obstack_grow (&permanent_obstack,
3065 (char *) &TREE_PURPOSE (link),
3066 sizeof TREE_PURPOSE (link));
3067 else if (TREE_PURPOSE (link))
3068 record_constant_1 (TREE_PURPOSE (link));
3069 else if (have_purpose)
3071 int zero = 0;
3073 obstack_grow (&permanent_obstack,
3074 (char *) &zero, sizeof zero);
3078 return;
3080 case ADDR_EXPR:
3082 struct addr_const value;
3084 decode_addr_const (exp, &value);
3085 /* Record the offset. */
3086 obstack_grow (&permanent_obstack,
3087 (char *) &value.offset, sizeof value.offset);
3089 switch (GET_CODE (value.base))
3091 case SYMBOL_REF:
3092 /* Record the symbol name. */
3093 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3094 strlen (XSTR (value.base, 0)) + 1);
3095 break;
3096 case LABEL_REF:
3097 /* Record the address of the CODE_LABEL. It may not have
3098 been emitted yet, so it's UID may be zero. But pointer
3099 identity is good enough. */
3100 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3101 sizeof (rtx));
3102 break;
3103 default:
3104 abort ();
3107 return;
3109 case PLUS_EXPR:
3110 case MINUS_EXPR:
3111 case RANGE_EXPR:
3112 record_constant_1 (TREE_OPERAND (exp, 0));
3113 record_constant_1 (TREE_OPERAND (exp, 1));
3114 return;
3116 case NOP_EXPR:
3117 case CONVERT_EXPR:
3118 case NON_LVALUE_EXPR:
3119 record_constant_1 (TREE_OPERAND (exp, 0));
3120 return;
3122 default:
3124 tree new = (*lang_hooks.expand_constant) (exp);
3126 if (new != exp)
3127 record_constant_1 (exp);
3128 return;
3132 /* Record constant contents. */
3133 obstack_grow (&permanent_obstack, strp, len);
3136 /* Record a list of constant expressions that were passed to
3137 output_constant_def but that could not be output right away. */
3139 struct deferred_constant
3141 struct deferred_constant *next;
3142 tree exp;
3143 int reloc;
3144 int labelno;
3147 static struct deferred_constant *deferred_constants;
3149 /* Another list of constants which should be output after the
3150 function. */
3151 static struct deferred_constant *after_function_constants;
3153 /* Nonzero means defer output of addressed subconstants
3154 (i.e., those for which output_constant_def is called.) */
3155 static int defer_addressed_constants_flag;
3157 /* Start deferring output of subconstants. */
3159 void
3160 defer_addressed_constants ()
3162 defer_addressed_constants_flag++;
3165 /* Stop deferring output of subconstants,
3166 and output now all those that have been deferred. */
3168 void
3169 output_deferred_addressed_constants ()
3171 struct deferred_constant *p, *next;
3173 defer_addressed_constants_flag--;
3175 if (defer_addressed_constants_flag > 0)
3176 return;
3178 for (p = deferred_constants; p; p = next)
3180 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3181 next = p->next;
3182 free (p);
3185 deferred_constants = 0;
3188 /* Output any constants which should appear after a function. */
3190 static void
3191 output_after_function_constants ()
3193 struct deferred_constant *p, *next;
3195 for (p = after_function_constants; p; p = next)
3197 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3198 next = p->next;
3199 free (p);
3202 after_function_constants = 0;
3205 /* Make a copy of the whole tree structure for a constant.
3206 This handles the same types of nodes that compare_constant
3207 and record_constant handle. */
3209 static tree
3210 copy_constant (exp)
3211 tree exp;
3213 switch (TREE_CODE (exp))
3215 case ADDR_EXPR:
3216 /* For ADDR_EXPR, we do not want to copy the decl whose address
3217 is requested. We do want to copy constants though. */
3218 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3219 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3220 copy_constant (TREE_OPERAND (exp, 0)));
3221 else
3222 return copy_node (exp);
3224 case INTEGER_CST:
3225 case REAL_CST:
3226 case STRING_CST:
3227 return copy_node (exp);
3229 case COMPLEX_CST:
3230 return build_complex (TREE_TYPE (exp),
3231 copy_constant (TREE_REALPART (exp)),
3232 copy_constant (TREE_IMAGPART (exp)));
3234 case PLUS_EXPR:
3235 case MINUS_EXPR:
3236 return build (TREE_CODE (exp), TREE_TYPE (exp),
3237 copy_constant (TREE_OPERAND (exp, 0)),
3238 copy_constant (TREE_OPERAND (exp, 1)));
3240 case NOP_EXPR:
3241 case CONVERT_EXPR:
3242 case NON_LVALUE_EXPR:
3243 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3244 copy_constant (TREE_OPERAND (exp, 0)));
3246 case CONSTRUCTOR:
3248 tree copy = copy_node (exp);
3249 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3250 tree tail;
3252 CONSTRUCTOR_ELTS (copy) = list;
3253 for (tail = list; tail; tail = TREE_CHAIN (tail))
3254 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3255 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3256 for (tail = list; tail; tail = TREE_CHAIN (tail))
3257 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3259 return copy;
3262 default:
3263 abort ();
3267 /* Return an rtx representing a reference to constant data in memory
3268 for the constant expression EXP.
3270 If assembler code for such a constant has already been output,
3271 return an rtx to refer to it.
3272 Otherwise, output such a constant in memory (or defer it for later)
3273 and generate an rtx for it.
3275 If DEFER is non-zero, the output of string constants can be deferred
3276 and output only if referenced in the function after all optimizations.
3278 The TREE_CST_RTL of EXP is set up to point to that rtx.
3279 The const_hash_table records which constants already have label strings. */
3282 output_constant_def (exp, defer)
3283 tree exp;
3284 int defer;
3286 int hash;
3287 struct constant_descriptor *desc;
3288 struct deferred_string **defstr;
3289 char label[256];
3290 int reloc;
3291 int found = 1;
3292 int after_function = 0;
3293 int labelno = -1;
3294 rtx rtl;
3296 /* We can't just use the saved RTL if this is a defererred string constant
3297 and we are not to defer anymode. */
3298 if (TREE_CODE (exp) != INTEGER_CST && TREE_CST_RTL (exp)
3299 && (defer || !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp), 0))))
3300 return TREE_CST_RTL (exp);
3302 /* Make sure any other constants whose addresses appear in EXP
3303 are assigned label numbers. */
3305 reloc = output_addressed_constants (exp);
3307 /* Compute hash code of EXP. Search the descriptors for that hash code
3308 to see if any of them describes EXP. If yes, the descriptor records
3309 the label number already assigned. */
3311 hash = const_hash (exp) % MAX_HASH_TABLE;
3313 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3314 if (compare_constant (exp, desc))
3315 break;
3317 if (desc == 0)
3319 /* No constant equal to EXP is known to have been output.
3320 Make a constant descriptor to enter EXP in the hash table.
3321 Assign the label number and record it in the descriptor for
3322 future calls to this function to find. */
3324 /* Create a string containing the label name, in LABEL. */
3325 labelno = const_labelno++;
3326 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3328 desc = record_constant (exp);
3329 desc->next = const_hash_table[hash];
3330 desc->label = ggc_strdup (label);
3331 const_hash_table[hash] = desc;
3333 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3334 rtl = desc->rtl
3335 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3336 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3338 set_mem_attributes (rtl, exp, 1);
3339 set_mem_alias_set (rtl, 0);
3340 set_mem_alias_set (rtl, const_alias_set);
3342 found = 0;
3344 else
3345 rtl = desc->rtl;
3347 if (TREE_CODE (exp) != INTEGER_CST)
3348 TREE_CST_RTL (exp) = rtl;
3350 /* Optionally set flags or add text to the name to record information
3351 such as that it is a function name. If the name is changed, the macro
3352 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3353 #ifdef ENCODE_SECTION_INFO
3354 /* A previously-processed constant would already have section info
3355 encoded in it. */
3356 if (! found)
3358 ENCODE_SECTION_INFO (exp);
3359 desc->rtl = rtl;
3360 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3362 #endif
3364 #ifdef CONSTANT_AFTER_FUNCTION_P
3365 if (current_function_decl != 0
3366 && CONSTANT_AFTER_FUNCTION_P (exp))
3367 after_function = 1;
3368 #endif
3370 if (found
3371 && STRING_POOL_ADDRESS_P (XEXP (rtl, 0))
3372 && (!defer || defer_addressed_constants_flag || after_function))
3374 defstr = (struct deferred_string **)
3375 htab_find_slot_with_hash (const_str_htab, desc->label,
3376 STRHASH (desc->label), NO_INSERT);
3377 if (defstr)
3379 /* If the string is currently deferred but we need to output it now,
3380 remove it from deferred string hash table. */
3381 found = 0;
3382 labelno = (*defstr)->labelno;
3383 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 0;
3384 htab_clear_slot (const_str_htab, (void **) defstr);
3388 /* If this is the first time we've seen this particular constant,
3389 output it (or defer its output for later). */
3390 if (! found)
3392 if (defer_addressed_constants_flag || after_function)
3394 struct deferred_constant *p
3395 = (struct deferred_constant *)
3396 xmalloc (sizeof (struct deferred_constant));
3398 p->exp = copy_constant (exp);
3399 p->reloc = reloc;
3400 p->labelno = labelno;
3401 if (after_function)
3403 p->next = after_function_constants;
3404 after_function_constants = p;
3406 else
3408 p->next = deferred_constants;
3409 deferred_constants = p;
3412 else
3414 /* Do no output if -fsyntax-only. */
3415 if (! flag_syntax_only)
3417 if (TREE_CODE (exp) != STRING_CST
3418 || !defer
3419 || flag_writable_strings
3420 || (defstr = (struct deferred_string **)
3421 htab_find_slot_with_hash (const_str_htab,
3422 desc->label,
3423 STRHASH (desc->label),
3424 INSERT)) == NULL)
3425 output_constant_def_contents (exp, reloc, labelno);
3426 else
3428 struct deferred_string *p;
3430 p = (struct deferred_string *)
3431 xmalloc (sizeof (struct deferred_string));
3433 p->exp = copy_constant (exp);
3434 p->label = desc->label;
3435 p->labelno = labelno;
3436 *defstr = p;
3437 STRING_POOL_ADDRESS_P (XEXP (rtl, 0)) = 1;
3443 return rtl;
3446 /* Now output assembler code to define the label for EXP,
3447 and follow it with the data of EXP. */
3449 static void
3450 output_constant_def_contents (exp, reloc, labelno)
3451 tree exp;
3452 int reloc;
3453 int labelno;
3455 int align;
3457 /* Align the location counter as required by EXP's data type. */
3458 align = TYPE_ALIGN (TREE_TYPE (exp));
3459 #ifdef CONSTANT_ALIGNMENT
3460 align = CONSTANT_ALIGNMENT (exp, align);
3461 #endif
3463 if (IN_NAMED_SECTION (exp))
3464 named_section (exp, NULL, reloc);
3465 else
3467 /* First switch to text section, except for writable strings. */
3468 #ifdef SELECT_SECTION
3469 SELECT_SECTION (exp, reloc, align);
3470 #else
3471 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3472 || (flag_pic && reloc))
3473 data_section ();
3474 else
3475 readonly_data_section ();
3476 #endif
3479 if (align > BITS_PER_UNIT)
3481 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3484 /* Output the label itself. */
3485 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3487 /* Output the value of EXP. */
3488 output_constant (exp,
3489 (TREE_CODE (exp) == STRING_CST
3490 ? MAX (TREE_STRING_LENGTH (exp),
3491 int_size_in_bytes (TREE_TYPE (exp)))
3492 : int_size_in_bytes (TREE_TYPE (exp))),
3493 align);
3497 /* Structure to represent sufficient information about a constant so that
3498 it can be output when the constant pool is output, so that function
3499 integration can be done, and to simplify handling on machines that reference
3500 constant pool as base+displacement. */
3502 struct pool_constant
3504 struct constant_descriptor *desc;
3505 struct pool_constant *next, *next_sym;
3506 rtx constant;
3507 enum machine_mode mode;
3508 int labelno;
3509 unsigned int align;
3510 HOST_WIDE_INT offset;
3511 int mark;
3514 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3515 The argument is XSTR (... , 0) */
3517 #define SYMHASH(LABEL) \
3518 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3520 /* Initialize constant pool hashing for a new function. */
3522 void
3523 init_varasm_status (f)
3524 struct function *f;
3526 struct varasm_status *p;
3527 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3528 f->varasm = p;
3529 p->x_const_rtx_hash_table
3530 = ((struct constant_descriptor **)
3531 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3532 p->x_const_rtx_sym_hash_table
3533 = ((struct pool_constant **)
3534 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3536 p->x_first_pool = p->x_last_pool = 0;
3537 p->x_pool_offset = 0;
3538 p->x_const_double_chain = 0;
3541 /* Mark PC for GC. */
3543 static void
3544 mark_pool_constant (pc)
3545 struct pool_constant *pc;
3547 while (pc)
3549 ggc_mark (pc);
3550 ggc_mark_rtx (pc->constant);
3551 ggc_mark_rtx (pc->desc->rtl);
3552 pc = pc->next;
3556 /* Mark P for GC. */
3558 void
3559 mark_varasm_status (p)
3560 struct varasm_status *p;
3562 if (p == NULL)
3563 return;
3565 mark_pool_constant (p->x_first_pool);
3566 ggc_mark_rtx (p->x_const_double_chain);
3569 /* Clear out all parts of the state in F that can safely be discarded
3570 after the function has been compiled, to let garbage collection
3571 reclaim the memory. */
3573 void
3574 free_varasm_status (f)
3575 struct function *f;
3577 struct varasm_status *p;
3578 int i;
3580 p = f->varasm;
3582 /* Clear out the hash tables. */
3583 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3585 struct constant_descriptor *cd;
3587 cd = p->x_const_rtx_hash_table[i];
3588 while (cd)
3590 struct constant_descriptor *next = cd->next;
3592 free (cd);
3593 cd = next;
3597 free (p->x_const_rtx_hash_table);
3598 free (p->x_const_rtx_sym_hash_table);
3599 free (p);
3601 f->varasm = NULL;
3605 /* Express an rtx for a constant integer (perhaps symbolic)
3606 as the sum of a symbol or label plus an explicit integer.
3607 They are stored into VALUE. */
3609 static void
3610 decode_rtx_const (mode, x, value)
3611 enum machine_mode mode;
3612 rtx x;
3613 struct rtx_const *value;
3615 /* Clear the whole structure, including any gaps. */
3616 memset (value, 0, sizeof (struct rtx_const));
3618 value->kind = RTX_INT; /* Most usual kind. */
3619 value->mode = mode;
3621 switch (GET_CODE (x))
3623 case CONST_DOUBLE:
3624 value->kind = RTX_DOUBLE;
3625 if (GET_MODE (x) != VOIDmode)
3627 value->mode = GET_MODE (x);
3628 memcpy ((char *) &value->un.du,
3629 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3631 else
3633 value->un.di.low = CONST_DOUBLE_LOW (x);
3634 value->un.di.high = CONST_DOUBLE_HIGH (x);
3636 break;
3638 case CONST_INT:
3639 value->un.addr.offset = INTVAL (x);
3640 break;
3642 case SYMBOL_REF:
3643 case LABEL_REF:
3644 case PC:
3645 value->un.addr.base = x;
3646 break;
3648 case CONST:
3649 x = XEXP (x, 0);
3650 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3652 value->un.addr.base = XEXP (x, 0);
3653 value->un.addr.offset = INTVAL (XEXP (x, 1));
3655 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3657 value->un.addr.base = XEXP (x, 0);
3658 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3660 else
3662 value->un.addr.base = x;
3663 value->un.addr.offset = 0;
3665 break;
3667 default:
3668 abort ();
3671 if (value->kind == RTX_INT && value->un.addr.base != 0)
3672 switch (GET_CODE (value->un.addr.base))
3674 case SYMBOL_REF:
3675 /* Use the string's address, not the SYMBOL_REF's address,
3676 for the sake of addresses of library routines. */
3677 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3678 break;
3680 case LABEL_REF:
3681 /* For a LABEL_REF, compare labels. */
3682 value->un.addr.base = XEXP (value->un.addr.base, 0);
3684 default:
3685 break;
3689 /* Given a MINUS expression, simplify it if both sides
3690 include the same symbol. */
3693 simplify_subtraction (x)
3694 rtx x;
3696 struct rtx_const val0, val1;
3698 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3699 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3701 if (val0.un.addr.base == val1.un.addr.base)
3702 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3703 return x;
3706 /* Compute a hash code for a constant RTL expression. */
3708 static int
3709 const_hash_rtx (mode, x)
3710 enum machine_mode mode;
3711 rtx x;
3713 int hi;
3714 size_t i;
3716 struct rtx_const value;
3717 decode_rtx_const (mode, x, &value);
3719 /* Compute hashing function */
3720 hi = 0;
3721 for (i = 0; i < sizeof value / sizeof (int); i++)
3722 hi += ((int *) &value)[i];
3724 hi &= (1 << HASHBITS) - 1;
3725 hi %= MAX_RTX_HASH_TABLE;
3726 return hi;
3729 /* Compare a constant rtl object X with a constant-descriptor DESC.
3730 Return 1 if DESC describes a constant with the same value as X. */
3732 static int
3733 compare_constant_rtx (mode, x, desc)
3734 enum machine_mode mode;
3735 rtx x;
3736 struct constant_descriptor *desc;
3738 int *p = (int *) desc->u.contents;
3739 int *strp;
3740 int len;
3741 struct rtx_const value;
3743 decode_rtx_const (mode, x, &value);
3744 strp = (int *) &value;
3745 len = sizeof value / sizeof (int);
3747 /* Compare constant contents. */
3748 while (--len >= 0)
3749 if (*p++ != *strp++)
3750 return 0;
3752 return 1;
3755 /* Construct a constant descriptor for the rtl-expression X.
3756 It is up to the caller to enter the descriptor in the hash table. */
3758 static struct constant_descriptor *
3759 record_constant_rtx (mode, x)
3760 enum machine_mode mode;
3761 rtx x;
3763 struct constant_descriptor *ptr;
3765 ptr = ((struct constant_descriptor *)
3766 xcalloc (1, (offsetof (struct constant_descriptor, u)
3767 + sizeof (struct rtx_const))));
3768 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3770 return ptr;
3773 /* Given a constant rtx X, return a MEM for the location in memory at which
3774 this constant has been placed. Return 0 if it not has been placed yet. */
3777 mem_for_const_double (x)
3778 rtx x;
3780 enum machine_mode mode = GET_MODE (x);
3781 struct constant_descriptor *desc;
3783 for (desc = const_rtx_hash_table[const_hash_rtx (mode, x)]; desc;
3784 desc = desc->next)
3785 if (compare_constant_rtx (mode, x, desc))
3786 return desc->rtl;
3788 return 0;
3791 /* Given a constant rtx X, make (or find) a memory constant for its value
3792 and return a MEM rtx to refer to it in memory. */
3795 force_const_mem (mode, x)
3796 enum machine_mode mode;
3797 rtx x;
3799 int hash;
3800 struct constant_descriptor *desc;
3801 char label[256];
3802 rtx def;
3803 struct pool_constant *pool;
3804 unsigned int align;
3806 /* Compute hash code of X. Search the descriptors for that hash code
3807 to see if any of them describes X. If yes, we have an rtx to use. */
3808 hash = const_hash_rtx (mode, x);
3809 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3810 if (compare_constant_rtx (mode, x, desc))
3811 return desc->rtl;
3813 /* No constant equal to X is known to have been output.
3814 Make a constant descriptor to enter X in the hash table
3815 and make a MEM for it. */
3816 desc = record_constant_rtx (mode, x);
3817 desc->next = const_rtx_hash_table[hash];
3818 const_rtx_hash_table[hash] = desc;
3820 /* Align the location counter as required by EXP's data type. */
3821 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3822 #ifdef CONSTANT_ALIGNMENT
3823 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x), align);
3824 #endif
3826 pool_offset += (align / BITS_PER_UNIT) - 1;
3827 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3829 if (GET_CODE (x) == LABEL_REF)
3830 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3832 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3833 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3834 pool->desc = desc;
3835 pool->constant = x;
3836 pool->mode = mode;
3837 pool->labelno = const_labelno;
3838 pool->align = align;
3839 pool->offset = pool_offset;
3840 pool->mark = 1;
3841 pool->next = 0;
3843 if (last_pool == 0)
3844 first_pool = pool;
3845 else
3846 last_pool->next = pool;
3848 last_pool = pool;
3849 pool_offset += GET_MODE_SIZE (mode);
3851 /* Create a string containing the label name, in LABEL. */
3852 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3854 ++const_labelno;
3856 /* Construct the SYMBOL_REF and the MEM. */
3858 pool->desc->rtl = def
3859 = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
3860 set_mem_alias_set (def, const_alias_set);
3861 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3862 RTX_UNCHANGING_P (def) = 1;
3864 /* Add label to symbol hash table. */
3865 hash = SYMHASH (XSTR (XEXP (def, 0), 0));
3866 pool->next_sym = const_rtx_sym_hash_table[hash];
3867 const_rtx_sym_hash_table[hash] = pool;
3869 /* Mark the symbol_ref as belonging to this constants pool. */
3870 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3871 current_function_uses_const_pool = 1;
3873 return def;
3876 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3877 the corresponding pool_constant structure. */
3879 static struct pool_constant *
3880 find_pool_constant (f, addr)
3881 struct function *f;
3882 rtx addr;
3884 struct pool_constant *pool;
3885 const char *label = XSTR (addr, 0);
3887 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3888 pool = pool->next_sym)
3889 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3890 return pool;
3892 abort ();
3895 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3898 get_pool_constant (addr)
3899 rtx addr;
3901 return (find_pool_constant (cfun, addr))->constant;
3904 /* Likewise, but for the constant pool of a specific function. */
3907 get_pool_constant_for_function (f, addr)
3908 struct function *f;
3909 rtx addr;
3911 return (find_pool_constant (f, addr))->constant;
3914 /* Similar, return the mode. */
3916 enum machine_mode
3917 get_pool_mode (addr)
3918 rtx addr;
3920 return (find_pool_constant (cfun, addr))->mode;
3923 enum machine_mode
3924 get_pool_mode_for_function (f, addr)
3925 struct function *f;
3926 rtx addr;
3928 return (find_pool_constant (f, addr))->mode;
3931 /* Similar, return the offset in the constant pool. */
3934 get_pool_offset (addr)
3935 rtx addr;
3937 return (find_pool_constant (cfun, addr))->offset;
3940 /* Return the size of the constant pool. */
3943 get_pool_size ()
3945 return pool_offset;
3948 /* Write all the constants in the constant pool. */
3950 void
3951 output_constant_pool (fnname, fndecl)
3952 const char *fnname ATTRIBUTE_UNUSED;
3953 tree fndecl ATTRIBUTE_UNUSED;
3955 struct pool_constant *pool;
3956 rtx x;
3957 union real_extract u;
3959 /* It is possible for gcc to call force_const_mem and then to later
3960 discard the instructions which refer to the constant. In such a
3961 case we do not need to output the constant. */
3962 mark_constant_pool ();
3964 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3965 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3966 #endif
3968 for (pool = first_pool; pool; pool = pool->next)
3970 rtx tmp;
3972 x = pool->constant;
3974 if (! pool->mark)
3975 continue;
3977 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3978 whose CODE_LABEL has been deleted. This can occur if a jump table
3979 is eliminated by optimization. If so, write a constant of zero
3980 instead. Note that this can also happen by turning the
3981 CODE_LABEL into a NOTE. */
3982 /* ??? This seems completely and utterly wrong. Certainly it's
3983 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3984 functioning even with INSN_DELETED_P and friends. */
3986 tmp = x;
3987 switch (GET_CODE (x))
3989 case CONST:
3990 if (GET_CODE (XEXP (x, 0)) != PLUS
3991 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3992 break;
3993 tmp = XEXP (XEXP (x, 0), 0);
3994 /* FALLTHRU */
3996 case LABEL_REF:
3997 tmp = XEXP (x, 0);
3998 if (INSN_DELETED_P (tmp)
3999 || (GET_CODE (tmp) == NOTE
4000 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
4002 abort ();
4003 x = const0_rtx;
4005 break;
4007 default:
4008 break;
4011 /* First switch to correct section. */
4012 #ifdef SELECT_RTX_SECTION
4013 SELECT_RTX_SECTION (pool->mode, x, pool->align);
4014 #else
4015 readonly_data_section ();
4016 #endif
4018 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4019 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4020 pool->align, pool->labelno, done);
4021 #endif
4023 assemble_align (pool->align);
4025 /* Output the label. */
4026 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4028 /* Output the value of the constant itself. */
4029 switch (GET_MODE_CLASS (pool->mode))
4031 case MODE_FLOAT:
4032 if (GET_CODE (x) != CONST_DOUBLE)
4033 abort ();
4035 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4036 assemble_real (u.d, pool->mode, pool->align);
4037 break;
4039 case MODE_INT:
4040 case MODE_PARTIAL_INT:
4041 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4042 break;
4044 default:
4045 abort ();
4048 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4049 done: ;
4050 #endif
4053 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4054 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4055 #endif
4057 /* Done with this pool. */
4058 first_pool = last_pool = 0;
4061 /* Look through the instructions for this function, and mark all the
4062 entries in the constant pool which are actually being used.
4063 Emit used deferred strings. */
4065 static void
4066 mark_constant_pool ()
4068 rtx insn;
4069 struct pool_constant *pool;
4071 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4072 return;
4074 for (pool = first_pool; pool; pool = pool->next)
4075 pool->mark = 0;
4077 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4078 if (INSN_P (insn))
4079 mark_constants (PATTERN (insn));
4081 for (insn = current_function_epilogue_delay_list;
4082 insn;
4083 insn = XEXP (insn, 1))
4084 if (INSN_P (insn))
4085 mark_constants (PATTERN (insn));
4088 /* Look through appropriate parts of X, marking all entries in the
4089 constant pool which are actually being used. Entries that are only
4090 referenced by other constants are also marked as used. Emit
4091 deferred strings that are used. */
4093 static void
4094 mark_constants (x)
4095 rtx x;
4097 int i;
4098 const char *format_ptr;
4100 if (x == 0)
4101 return;
4103 if (GET_CODE (x) == SYMBOL_REF)
4105 mark_constant (&x, NULL);
4106 return;
4109 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4110 insns, not any notes that may be attached. We don't want to mark
4111 a constant just because it happens to appear in a REG_EQUIV note. */
4112 if (INSN_P (x))
4114 mark_constants (PATTERN (x));
4115 return;
4118 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4120 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4122 switch (*format_ptr++)
4124 case 'e':
4125 mark_constants (XEXP (x, i));
4126 break;
4128 case 'E':
4129 if (XVEC (x, i) != 0)
4131 int j;
4133 for (j = 0; j < XVECLEN (x, i); j++)
4134 mark_constants (XVECEXP (x, i, j));
4136 break;
4138 case 'S':
4139 case 's':
4140 case '0':
4141 case 'i':
4142 case 'w':
4143 case 'n':
4144 case 'u':
4145 break;
4147 default:
4148 abort ();
4153 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4154 to as used. Emit referenced deferred strings. This function can
4155 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4157 static int
4158 mark_constant (current_rtx, data)
4159 rtx *current_rtx;
4160 void *data ATTRIBUTE_UNUSED;
4162 rtx x = *current_rtx;
4164 if (x == NULL_RTX)
4165 return 0;
4167 else if (GET_CODE (x) == SYMBOL_REF)
4169 if (CONSTANT_POOL_ADDRESS_P (x))
4171 struct pool_constant *pool = find_pool_constant (cfun, x);
4172 if (pool->mark == 0) {
4173 pool->mark = 1;
4174 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4176 else
4177 return -1;
4179 else if (STRING_POOL_ADDRESS_P (x))
4181 struct deferred_string **defstr;
4183 defstr = (struct deferred_string **)
4184 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4185 STRHASH (XSTR (x, 0)), NO_INSERT);
4186 if (defstr)
4188 struct deferred_string *p = *defstr;
4190 STRING_POOL_ADDRESS_P (x) = 0;
4191 output_constant_def_contents (p->exp, 0, p->labelno);
4192 htab_clear_slot (const_str_htab, (void **) defstr);
4196 return 0;
4199 /* Find all the constants whose addresses are referenced inside of EXP,
4200 and make sure assembler code with a label has been output for each one.
4201 Indicate whether an ADDR_EXPR has been encountered. */
4203 static int
4204 output_addressed_constants (exp)
4205 tree exp;
4207 int reloc = 0;
4208 tree tem;
4210 /* Give the front-end a chance to convert VALUE to something that
4211 looks more like a constant to the back-end. */
4212 exp = (*lang_hooks.expand_constant) (exp);
4214 switch (TREE_CODE (exp))
4216 case ADDR_EXPR:
4217 /* Go inside any operations that get_inner_reference can handle and see
4218 if what's inside is a constant: no need to do anything here for
4219 addresses of variables or functions. */
4220 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4221 tem = TREE_OPERAND (tem, 0))
4224 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
4225 || TREE_CODE (tem) == CONSTRUCTOR)
4226 output_constant_def (tem, 0);
4228 if (TREE_PUBLIC (tem))
4229 reloc |= 2;
4230 else
4231 reloc |= 1;
4232 break;
4234 case PLUS_EXPR:
4235 case MINUS_EXPR:
4236 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4237 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4238 break;
4240 case NOP_EXPR:
4241 case CONVERT_EXPR:
4242 case NON_LVALUE_EXPR:
4243 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4244 break;
4246 case CONSTRUCTOR:
4247 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
4248 if (TREE_VALUE (tem) != 0)
4249 reloc |= output_addressed_constants (TREE_VALUE (tem));
4251 break;
4253 default:
4254 break;
4256 return reloc;
4259 /* Return nonzero if VALUE is a valid constant-valued expression
4260 for use in initializing a static variable; one that can be an
4261 element of a "constant" initializer.
4263 Return null_pointer_node if the value is absolute;
4264 if it is relocatable, return the variable that determines the relocation.
4265 We assume that VALUE has been folded as much as possible;
4266 therefore, we do not need to check for such things as
4267 arithmetic-combinations of integers. */
4269 tree
4270 initializer_constant_valid_p (value, endtype)
4271 tree value;
4272 tree endtype;
4274 /* Give the front-end a chance to convert VALUE to something that
4275 looks more like a constant to the back-end. */
4276 value = (*lang_hooks.expand_constant) (value);
4278 switch (TREE_CODE (value))
4280 case CONSTRUCTOR:
4281 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4282 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4283 && TREE_CONSTANT (value)
4284 && CONSTRUCTOR_ELTS (value))
4285 return
4286 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4287 endtype);
4289 return TREE_STATIC (value) ? null_pointer_node : 0;
4291 case INTEGER_CST:
4292 case REAL_CST:
4293 case STRING_CST:
4294 case COMPLEX_CST:
4295 return null_pointer_node;
4297 case ADDR_EXPR:
4298 case FDESC_EXPR:
4299 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4301 case VIEW_CONVERT_EXPR:
4302 case NON_LVALUE_EXPR:
4303 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4305 case CONVERT_EXPR:
4306 case NOP_EXPR:
4307 /* Allow conversions between pointer types. */
4308 if (POINTER_TYPE_P (TREE_TYPE (value))
4309 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4310 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4312 /* Allow conversions between real types. */
4313 if (FLOAT_TYPE_P (TREE_TYPE (value))
4314 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4315 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4317 /* Allow length-preserving conversions between integer types. */
4318 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4319 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4320 && (TYPE_PRECISION (TREE_TYPE (value))
4321 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4322 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4324 /* Allow conversions between other integer types only if
4325 explicit value. */
4326 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4327 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4329 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4330 endtype);
4331 if (inner == null_pointer_node)
4332 return null_pointer_node;
4333 break;
4336 /* Allow (int) &foo provided int is as wide as a pointer. */
4337 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4338 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4339 && (TYPE_PRECISION (TREE_TYPE (value))
4340 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4341 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4342 endtype);
4344 /* Likewise conversions from int to pointers, but also allow
4345 conversions from 0. */
4346 if (POINTER_TYPE_P (TREE_TYPE (value))
4347 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4349 if (integer_zerop (TREE_OPERAND (value, 0)))
4350 return null_pointer_node;
4351 else if (TYPE_PRECISION (TREE_TYPE (value))
4352 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4353 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4354 endtype);
4357 /* Allow conversions to union types if the value inside is okay. */
4358 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4359 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4360 endtype);
4361 break;
4363 case PLUS_EXPR:
4364 if (! INTEGRAL_TYPE_P (endtype)
4365 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4367 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4368 endtype);
4369 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4370 endtype);
4371 /* If either term is absolute, use the other terms relocation. */
4372 if (valid0 == null_pointer_node)
4373 return valid1;
4374 if (valid1 == null_pointer_node)
4375 return valid0;
4377 break;
4379 case MINUS_EXPR:
4380 if (! INTEGRAL_TYPE_P (endtype)
4381 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4383 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4384 endtype);
4385 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4386 endtype);
4387 /* Win if second argument is absolute. */
4388 if (valid1 == null_pointer_node)
4389 return valid0;
4390 /* Win if both arguments have the same relocation.
4391 Then the value is absolute. */
4392 if (valid0 == valid1 && valid0 != 0)
4393 return null_pointer_node;
4395 /* Since GCC guarantees that string constants are unique in the
4396 generated code, a subtraction between two copies of the same
4397 constant string is absolute. */
4398 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4399 valid1 && TREE_CODE (valid1) == STRING_CST &&
4400 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4401 return null_pointer_node;
4404 /* Support differences between labels. */
4405 if (INTEGRAL_TYPE_P (endtype))
4407 tree op0, op1;
4408 op0 = TREE_OPERAND (value, 0);
4409 op1 = TREE_OPERAND (value, 1);
4410 STRIP_NOPS (op0);
4411 STRIP_NOPS (op1);
4413 if (TREE_CODE (op0) == ADDR_EXPR
4414 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4415 && TREE_CODE (op1) == ADDR_EXPR
4416 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4417 return null_pointer_node;
4419 break;
4421 default:
4422 break;
4425 return 0;
4428 /* Output assembler code for constant EXP to FILE, with no label.
4429 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4430 Assumes output_addressed_constants has been done on EXP already.
4432 Generate exactly SIZE bytes of assembler data, padding at the end
4433 with zeros if necessary. SIZE must always be specified.
4435 SIZE is important for structure constructors,
4436 since trailing members may have been omitted from the constructor.
4437 It is also important for initialization of arrays from string constants
4438 since the full length of the string constant might not be wanted.
4439 It is also needed for initialization of unions, where the initializer's
4440 type is just one member, and that may not be as long as the union.
4442 There a case in which we would fail to output exactly SIZE bytes:
4443 for a structure constructor that wants to produce more than SIZE bytes.
4444 But such constructors will never be generated for any possible input.
4446 ALIGN is the alignment of the data in bits. */
4448 void
4449 output_constant (exp, size, align)
4450 tree exp;
4451 HOST_WIDE_INT size;
4452 unsigned int align;
4454 enum tree_code code;
4455 HOST_WIDE_INT thissize;
4457 /* Some front-ends use constants other than the standard language-indepdent
4458 varieties, but which may still be output directly. Give the front-end a
4459 chance to convert EXP to a language-independent representation. */
4460 exp = (*lang_hooks.expand_constant) (exp);
4462 if (size == 0 || flag_syntax_only)
4463 return;
4465 /* Eliminate any conversions since we'll be outputting the underlying
4466 constant. */
4467 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4468 || TREE_CODE (exp) == NON_LVALUE_EXPR
4469 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
4470 exp = TREE_OPERAND (exp, 0);
4472 code = TREE_CODE (TREE_TYPE (exp));
4473 thissize = int_size_in_bytes (TREE_TYPE (exp));
4475 /* Allow a constructor with no elements for any data type.
4476 This means to fill the space with zeros. */
4477 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4479 assemble_zeros (size);
4480 return;
4483 if (TREE_CODE (exp) == FDESC_EXPR)
4485 #ifdef ASM_OUTPUT_FDESC
4486 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4487 tree decl = TREE_OPERAND (exp, 0);
4488 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4489 #else
4490 abort ();
4491 #endif
4492 return;
4495 /* Now output the underlying data. If we've handling the padding, return.
4496 Otherwise, break and ensure THISSIZE is the size written. */
4497 switch (code)
4499 case CHAR_TYPE:
4500 case BOOLEAN_TYPE:
4501 case INTEGER_TYPE:
4502 case ENUMERAL_TYPE:
4503 case POINTER_TYPE:
4504 case REFERENCE_TYPE:
4505 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4506 EXPAND_INITIALIZER),
4507 size, align, 0))
4508 error ("initializer for integer value is too complicated");
4509 break;
4511 case REAL_TYPE:
4512 if (TREE_CODE (exp) != REAL_CST)
4513 error ("initializer for floating value is not a floating constant");
4515 assemble_real (TREE_REAL_CST (exp),
4516 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4517 align);
4518 break;
4520 case COMPLEX_TYPE:
4521 output_constant (TREE_REALPART (exp), thissize / 2, align);
4522 output_constant (TREE_IMAGPART (exp), thissize / 2,
4523 min_align (align, BITS_PER_UNIT * (thissize / 2)));
4524 break;
4526 case ARRAY_TYPE:
4527 if (TREE_CODE (exp) == CONSTRUCTOR)
4529 output_constructor (exp, size, align);
4530 return;
4532 else if (TREE_CODE (exp) == STRING_CST)
4534 thissize = MIN (TREE_STRING_LENGTH (exp), size);
4535 assemble_string (TREE_STRING_POINTER (exp), thissize);
4537 else
4538 abort ();
4539 break;
4541 case RECORD_TYPE:
4542 case UNION_TYPE:
4543 if (TREE_CODE (exp) == CONSTRUCTOR)
4544 output_constructor (exp, size, align);
4545 else
4546 abort ();
4547 return;
4549 case SET_TYPE:
4550 if (TREE_CODE (exp) == INTEGER_CST)
4551 assemble_integer (expand_expr (exp, NULL_RTX,
4552 VOIDmode, EXPAND_INITIALIZER),
4553 thissize, align, 1);
4554 else if (TREE_CODE (exp) == CONSTRUCTOR)
4556 unsigned char *buffer = (unsigned char *) alloca (thissize);
4557 if (get_set_constructor_bytes (exp, buffer, thissize))
4558 abort ();
4559 assemble_string ((char *) buffer, thissize);
4561 else
4562 error ("unknown set constructor type");
4563 return;
4565 default:
4566 abort ();
4569 size -= thissize;
4570 if (size > 0)
4571 assemble_zeros (size);
4575 /* Subroutine of output_constructor, used for computing the size of
4576 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4577 type with an unspecified upper bound. */
4579 static unsigned HOST_WIDE_INT
4580 array_size_for_constructor (val)
4581 tree val;
4583 tree max_index, i;
4585 /* This code used to attempt to handle string constants that are not
4586 arrays of single-bytes, but nothing else does, so there's no point in
4587 doing it here. */
4588 if (TREE_CODE (val) == STRING_CST)
4589 return TREE_STRING_LENGTH (val);
4591 max_index = NULL_TREE;
4592 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4594 tree index = TREE_PURPOSE (i);
4596 if (TREE_CODE (index) == RANGE_EXPR)
4597 index = TREE_OPERAND (index, 1);
4598 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4599 max_index = index;
4602 if (max_index == NULL_TREE)
4603 return 0;
4605 /* Compute the total number of array elements. */
4606 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4607 convert (sizetype,
4608 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4609 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4611 /* Multiply by the array element unit size to find number of bytes. */
4612 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4614 return tree_low_cst (i, 1);
4617 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4618 Generate at least SIZE bytes, padding if necessary. */
4620 static void
4621 output_constructor (exp, size, align)
4622 tree exp;
4623 HOST_WIDE_INT size;
4624 unsigned int align;
4626 tree type = TREE_TYPE (exp);
4627 tree link, field = 0;
4628 tree min_index = 0;
4629 /* Number of bytes output or skipped so far.
4630 In other words, current position within the constructor. */
4631 HOST_WIDE_INT total_bytes = 0;
4632 /* Non-zero means BYTE contains part of a byte, to be output. */
4633 int byte_buffer_in_use = 0;
4634 int byte = 0;
4636 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4637 abort ();
4639 if (TREE_CODE (type) == RECORD_TYPE)
4640 field = TYPE_FIELDS (type);
4642 if (TREE_CODE (type) == ARRAY_TYPE
4643 && TYPE_DOMAIN (type) != 0)
4644 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4646 /* As LINK goes through the elements of the constant,
4647 FIELD goes through the structure fields, if the constant is a structure.
4648 if the constant is a union, then we override this,
4649 by getting the field from the TREE_LIST element.
4650 But the constant could also be an array. Then FIELD is zero.
4652 There is always a maximum of one element in the chain LINK for unions
4653 (even if the initializer in a source program incorrectly contains
4654 more one). */
4655 for (link = CONSTRUCTOR_ELTS (exp);
4656 link;
4657 link = TREE_CHAIN (link),
4658 field = field ? TREE_CHAIN (field) : 0)
4660 tree val = TREE_VALUE (link);
4661 tree index = 0;
4663 /* The element in a union constructor specifies the proper field
4664 or index. */
4665 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4666 || TREE_CODE (type) == QUAL_UNION_TYPE)
4667 && TREE_PURPOSE (link) != 0)
4668 field = TREE_PURPOSE (link);
4670 else if (TREE_CODE (type) == ARRAY_TYPE)
4671 index = TREE_PURPOSE (link);
4673 /* Eliminate the marker that makes a cast not be an lvalue. */
4674 if (val != 0)
4675 STRIP_NOPS (val);
4677 if (index && TREE_CODE (index) == RANGE_EXPR)
4679 unsigned HOST_WIDE_INT fieldsize
4680 = int_size_in_bytes (TREE_TYPE (type));
4681 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4682 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4683 HOST_WIDE_INT index;
4684 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4686 for (index = lo_index; index <= hi_index; index++)
4688 /* Output the element's initial value. */
4689 if (val == 0)
4690 assemble_zeros (fieldsize);
4691 else
4692 output_constant (val, fieldsize, align2);
4694 /* Count its size. */
4695 total_bytes += fieldsize;
4698 else if (field == 0 || !DECL_BIT_FIELD (field))
4700 /* An element that is not a bit-field. */
4702 unsigned HOST_WIDE_INT fieldsize;
4703 /* Since this structure is static,
4704 we know the positions are constant. */
4705 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4706 unsigned int align2;
4708 if (index != 0)
4709 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4710 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4712 /* Output any buffered-up bit-fields preceding this element. */
4713 if (byte_buffer_in_use)
4715 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4716 total_bytes++;
4717 byte_buffer_in_use = 0;
4720 /* Advance to offset of this element.
4721 Note no alignment needed in an array, since that is guaranteed
4722 if each element has the proper size. */
4723 if ((field != 0 || index != 0) && pos != total_bytes)
4725 assemble_zeros (pos - total_bytes);
4726 total_bytes = pos;
4729 /* Find the alignment of this element. */
4730 align2 = min_align (align, BITS_PER_UNIT * pos);
4732 /* Determine size this element should occupy. */
4733 if (field)
4735 fieldsize = 0;
4737 /* If this is an array with an unspecified upper bound,
4738 the initializer determines the size. */
4739 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4740 but we cannot do this until the deprecated support for
4741 initializing zero-length array members is removed. */
4742 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4743 && TYPE_DOMAIN (TREE_TYPE (field))
4744 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4746 fieldsize = array_size_for_constructor (val);
4747 /* Given a non-empty initialization, this field had
4748 better be last. */
4749 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4750 abort ();
4752 else if (DECL_SIZE_UNIT (field))
4754 /* ??? This can't be right. If the decl size overflows
4755 a host integer we will silently emit no data. */
4756 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4757 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4760 else
4761 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4763 /* Output the element's initial value. */
4764 if (val == 0)
4765 assemble_zeros (fieldsize);
4766 else
4767 output_constant (val, fieldsize, align2);
4769 /* Count its size. */
4770 total_bytes += fieldsize;
4772 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4773 error ("invalid initial value for member `%s'",
4774 IDENTIFIER_POINTER (DECL_NAME (field)));
4775 else
4777 /* Element that is a bit-field. */
4779 HOST_WIDE_INT next_offset = int_bit_position (field);
4780 HOST_WIDE_INT end_offset
4781 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4783 if (val == 0)
4784 val = integer_zero_node;
4786 /* If this field does not start in this (or, next) byte,
4787 skip some bytes. */
4788 if (next_offset / BITS_PER_UNIT != total_bytes)
4790 /* Output remnant of any bit field in previous bytes. */
4791 if (byte_buffer_in_use)
4793 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4794 total_bytes++;
4795 byte_buffer_in_use = 0;
4798 /* If still not at proper byte, advance to there. */
4799 if (next_offset / BITS_PER_UNIT != total_bytes)
4801 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4802 total_bytes = next_offset / BITS_PER_UNIT;
4806 if (! byte_buffer_in_use)
4807 byte = 0;
4809 /* We must split the element into pieces that fall within
4810 separate bytes, and combine each byte with previous or
4811 following bit-fields. */
4813 /* next_offset is the offset n fbits from the beginning of
4814 the structure to the next bit of this element to be processed.
4815 end_offset is the offset of the first bit past the end of
4816 this element. */
4817 while (next_offset < end_offset)
4819 int this_time;
4820 int shift;
4821 HOST_WIDE_INT value;
4822 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4823 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4825 /* Advance from byte to byte
4826 within this element when necessary. */
4827 while (next_byte != total_bytes)
4829 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4830 total_bytes++;
4831 byte = 0;
4834 /* Number of bits we can process at once
4835 (all part of the same byte). */
4836 this_time = MIN (end_offset - next_offset,
4837 BITS_PER_UNIT - next_bit);
4838 if (BYTES_BIG_ENDIAN)
4840 /* On big-endian machine, take the most significant bits
4841 first (of the bits that are significant)
4842 and put them into bytes from the most significant end. */
4843 shift = end_offset - next_offset - this_time;
4845 /* Don't try to take a bunch of bits that cross
4846 the word boundary in the INTEGER_CST. We can
4847 only select bits from the LOW or HIGH part
4848 not from both. */
4849 if (shift < HOST_BITS_PER_WIDE_INT
4850 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4852 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4853 shift = HOST_BITS_PER_WIDE_INT;
4856 /* Now get the bits from the appropriate constant word. */
4857 if (shift < HOST_BITS_PER_WIDE_INT)
4858 value = TREE_INT_CST_LOW (val);
4859 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4861 value = TREE_INT_CST_HIGH (val);
4862 shift -= HOST_BITS_PER_WIDE_INT;
4864 else
4865 abort ();
4867 /* Get the result. This works only when:
4868 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4869 byte |= (((value >> shift)
4870 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4871 << (BITS_PER_UNIT - this_time - next_bit));
4873 else
4875 /* On little-endian machines,
4876 take first the least significant bits of the value
4877 and pack them starting at the least significant
4878 bits of the bytes. */
4879 shift = next_offset - int_bit_position (field);
4881 /* Don't try to take a bunch of bits that cross
4882 the word boundary in the INTEGER_CST. We can
4883 only select bits from the LOW or HIGH part
4884 not from both. */
4885 if (shift < HOST_BITS_PER_WIDE_INT
4886 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4887 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4889 /* Now get the bits from the appropriate constant word. */
4890 if (shift < HOST_BITS_PER_WIDE_INT)
4891 value = TREE_INT_CST_LOW (val);
4892 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4894 value = TREE_INT_CST_HIGH (val);
4895 shift -= HOST_BITS_PER_WIDE_INT;
4897 else
4898 abort ();
4900 /* Get the result. This works only when:
4901 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4902 byte |= (((value >> shift)
4903 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4904 << next_bit);
4907 next_offset += this_time;
4908 byte_buffer_in_use = 1;
4913 if (byte_buffer_in_use)
4915 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4916 total_bytes++;
4919 if (total_bytes < size)
4920 assemble_zeros (size - total_bytes);
4924 /* This structure contains any weak symbol declarations waiting
4925 to be emitted. */
4926 struct weak_syms
4928 struct weak_syms * next;
4929 const char * name;
4930 const char * value;
4933 static struct weak_syms * weak_decls;
4935 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4936 associated with NAME. */
4939 add_weak (name, value)
4940 const char *name;
4941 const char *value;
4943 struct weak_syms *weak;
4945 weak = (struct weak_syms *) xmalloc (sizeof (struct weak_syms));
4947 if (weak == NULL)
4948 return 0;
4950 weak->next = weak_decls;
4951 weak->name = name;
4952 weak->value = value;
4953 weak_decls = weak;
4955 return 1;
4958 /* Declare DECL to be a weak symbol. */
4960 void
4961 declare_weak (decl)
4962 tree decl;
4964 if (! TREE_PUBLIC (decl))
4965 error_with_decl (decl, "weak declaration of `%s' must be public");
4966 else if (TREE_ASM_WRITTEN (decl))
4967 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4968 else if (SUPPORTS_WEAK)
4969 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4970 else
4971 warning_with_decl (decl, "weak declaration of `%s' not supported");
4973 DECL_WEAK (decl) = 1;
4976 /* Emit any pending weak declarations. */
4978 void
4979 weak_finish ()
4981 if (SUPPORTS_WEAK)
4983 struct weak_syms *t;
4984 for (t = weak_decls; t; t = t->next)
4986 #ifdef ASM_OUTPUT_WEAK_ALIAS
4987 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
4988 #else
4989 #ifdef ASM_WEAKEN_LABEL
4990 if (t->value)
4991 abort ();
4992 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4993 #endif
4994 #endif
4999 /* Remove NAME from the pending list of weak symbols. This prevents
5000 the compiler from emitting multiple .weak directives which confuses
5001 some assemblers. */
5002 #ifdef ASM_WEAKEN_LABEL
5003 static void
5004 remove_from_pending_weak_list (name)
5005 const char *name;
5007 struct weak_syms *t;
5008 struct weak_syms **p;
5010 for (p = &weak_decls; *p; )
5012 t = *p;
5013 if (strcmp (name, t->name) == 0)
5015 *p = t->next;
5016 free (t);
5018 else
5019 p = &(t->next);
5022 #endif /* ASM_WEAKEN_LABEL */
5024 /* Emit an assembler directive to make the symbol for DECL an alias to
5025 the symbol for TARGET. */
5027 void
5028 assemble_alias (decl, target)
5029 tree decl, target ATTRIBUTE_UNUSED;
5031 const char *name;
5033 /* We must force creation of DECL_RTL for debug info generation, even though
5034 we don't use it here. */
5035 make_decl_rtl (decl, NULL);
5037 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5039 #ifdef ASM_OUTPUT_DEF
5040 /* Make name accessible from other files, if appropriate. */
5042 if (TREE_PUBLIC (decl))
5044 #ifdef ASM_WEAKEN_LABEL
5045 if (DECL_WEAK (decl))
5047 ASM_WEAKEN_LABEL (asm_out_file, name);
5048 /* Remove this function from the pending weak list so that
5049 we do not emit multiple .weak directives for it. */
5050 remove_from_pending_weak_list
5051 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5053 else
5054 #endif
5055 ASM_GLOBALIZE_LABEL (asm_out_file, name);
5058 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5059 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5060 #else
5061 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5062 #endif
5063 TREE_ASM_WRITTEN (decl) = 1;
5064 #else
5065 #ifdef ASM_OUTPUT_WEAK_ALIAS
5066 if (! DECL_WEAK (decl))
5067 warning ("only weak aliases are supported in this configuration");
5069 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5070 TREE_ASM_WRITTEN (decl) = 1;
5071 #else
5072 warning ("alias definitions not supported in this configuration; ignored");
5073 #endif
5074 #endif
5077 /* Returns 1 if the target configuration supports defining public symbols
5078 so that one of them will be chosen at link time instead of generating a
5079 multiply-defined symbol error, whether through the use of weak symbols or
5080 a target-specific mechanism for having duplicates discarded. */
5083 supports_one_only ()
5085 if (SUPPORTS_ONE_ONLY)
5086 return 1;
5087 return SUPPORTS_WEAK;
5090 /* Set up DECL as a public symbol that can be defined in multiple
5091 translation units without generating a linker error. */
5093 void
5094 make_decl_one_only (decl)
5095 tree decl;
5097 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5098 abort ();
5100 TREE_PUBLIC (decl) = 1;
5102 if (TREE_CODE (decl) == VAR_DECL
5103 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5104 DECL_COMMON (decl) = 1;
5105 else if (SUPPORTS_ONE_ONLY)
5107 #ifdef MAKE_DECL_ONE_ONLY
5108 MAKE_DECL_ONE_ONLY (decl);
5109 #endif
5110 DECL_ONE_ONLY (decl) = 1;
5112 else if (SUPPORTS_WEAK)
5113 DECL_WEAK (decl) = 1;
5114 else
5115 abort ();
5118 void
5119 init_varasm_once ()
5121 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5122 const_str_htab_del);
5123 in_named_htab = htab_create (31, in_named_entry_hash,
5124 in_named_entry_eq, NULL);
5126 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5127 mark_const_hash_entry);
5128 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5129 mark_const_str_htab);
5131 const_alias_set = new_alias_set ();
5134 /* Select a set of attributes for section NAME based on the properties
5135 of DECL and whether or not RELOC indicates that DECL's initializer
5136 might contain runtime relocations.
5138 We make the section read-only and executable for a function decl,
5139 read-only for a const data decl, and writable for a non-const data decl. */
5141 unsigned int
5142 default_section_type_flags (decl, name, reloc)
5143 tree decl;
5144 const char *name;
5145 int reloc;
5147 unsigned int flags;
5149 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5150 flags = SECTION_CODE;
5151 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5152 flags = 0;
5153 else
5154 flags = SECTION_WRITE;
5156 if (decl && DECL_ONE_ONLY (decl))
5157 flags |= SECTION_LINKONCE;
5159 if (strcmp (name, ".bss") == 0
5160 || strncmp (name, ".bss.", 5) == 0
5161 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5162 || strcmp (name, ".sbss") == 0
5163 || strncmp (name, ".sbss.", 6) == 0
5164 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5165 flags |= SECTION_BSS;
5167 return flags;
5170 /* Output assembly to switch to section NAME with attribute FLAGS.
5171 Four variants for common object file formats. */
5173 void
5174 default_no_named_section (name, flags)
5175 const char *name ATTRIBUTE_UNUSED;
5176 unsigned int flags ATTRIBUTE_UNUSED;
5178 /* Some object formats don't support named sections at all. The
5179 front-end should already have flagged this as an error. */
5180 abort ();
5183 void
5184 default_elf_asm_named_section (name, flags)
5185 const char *name;
5186 unsigned int flags;
5188 char flagchars[10], *f = flagchars;
5189 const char *type;
5191 if (! named_section_first_declaration (name))
5193 fprintf (asm_out_file, "\t.section\t%s\n", name);
5194 return;
5197 if (!(flags & SECTION_DEBUG))
5198 *f++ = 'a';
5199 if (flags & SECTION_WRITE)
5200 *f++ = 'w';
5201 if (flags & SECTION_CODE)
5202 *f++ = 'x';
5203 if (flags & SECTION_SMALL)
5204 *f++ = 's';
5205 if (flags & SECTION_MERGE)
5206 *f++ = 'M';
5207 if (flags & SECTION_STRINGS)
5208 *f++ = 'S';
5209 *f = '\0';
5211 if (flags & SECTION_BSS)
5212 type = "nobits";
5213 else
5214 type = "progbits";
5216 if (flags & SECTION_ENTSIZE)
5217 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5218 name, flagchars, type, flags & SECTION_ENTSIZE);
5219 else
5220 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5221 name, flagchars, type);
5224 void
5225 default_coff_asm_named_section (name, flags)
5226 const char *name;
5227 unsigned int flags;
5229 char flagchars[8], *f = flagchars;
5231 if (flags & SECTION_WRITE)
5232 *f++ = 'w';
5233 if (flags & SECTION_CODE)
5234 *f++ = 'x';
5235 *f = '\0';
5237 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5240 void
5241 default_pe_asm_named_section (name, flags)
5242 const char *name;
5243 unsigned int flags;
5245 default_coff_asm_named_section (name, flags);
5247 if (flags & SECTION_LINKONCE)
5249 /* Functions may have been compiled at various levels of
5250 optimization so we can't use `same_size' here.
5251 Instead, have the linker pick one. */
5252 fprintf (asm_out_file, "\t.linkonce %s\n",
5253 (flags & SECTION_CODE ? "discard" : "same_size"));
5257 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5258 from SYMBOL is used in all classes derived from SYMBOL. */
5260 void
5261 assemble_vtable_entry (symbol, offset)
5262 rtx symbol;
5263 HOST_WIDE_INT offset;
5265 fputs ("\t.vtable_entry ", asm_out_file);
5266 output_addr_const (asm_out_file, symbol);
5267 fputs (", ", asm_out_file);
5268 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5269 fputc ('\n', asm_out_file);
5272 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5273 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5275 void
5276 assemble_vtable_inherit (child, parent)
5277 rtx child, parent;
5279 fputs ("\t.vtable_inherit ", asm_out_file);
5280 output_addr_const (asm_out_file, child);
5281 fputs (", ", asm_out_file);
5282 output_addr_const (asm_out_file, parent);
5283 fputc ('\n', asm_out_file);