* Makefile.in (rtlanal.o): Depend on $(TM_P_H).
[official-gcc.git] / gcc / varasm.c
blob24c96cf213f1c135f256ca0c37faa73bc865453b
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 "tm_p.h"
47 #include "debug.h"
48 #include "target.h"
50 #ifdef XCOFF_DEBUGGING_INFO
51 #include "xcoffout.h" /* Needed for external data
52 declarations for e.g. AIX 4.x. */
53 #endif
55 #ifndef TRAMPOLINE_ALIGNMENT
56 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
57 #endif
59 #ifndef ASM_STABS_OP
60 #define ASM_STABS_OP "\t.stabs\t"
61 #endif
63 /* Define the prefix to use when check_memory_usage_flag is enable. */
64 #define CHKR_PREFIX "_CHKR_"
65 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
67 /* The (assembler) name of the first globally-visible object output. */
68 const char *first_global_object_name;
69 const char *weak_global_object_name;
71 extern struct obstack permanent_obstack;
72 #define obstack_chunk_alloc xmalloc
74 struct addr_const;
75 struct constant_descriptor;
76 struct rtx_const;
77 struct pool_constant;
79 #define MAX_RTX_HASH_TABLE 61
81 struct varasm_status
83 /* Hash facility for making memory-constants
84 from constant rtl-expressions. It is used on RISC machines
85 where immediate integer arguments and constant addresses are restricted
86 so that such constants must be stored in memory.
88 This pool of constants is reinitialized for each function
89 so each function gets its own constants-pool that comes right before
90 it. */
91 struct constant_descriptor **x_const_rtx_hash_table;
92 struct pool_constant **x_const_rtx_sym_hash_table;
94 /* Pointers to first and last constant in pool. */
95 struct pool_constant *x_first_pool, *x_last_pool;
97 /* Current offset in constant pool (does not include any machine-specific
98 header). */
99 int x_pool_offset;
101 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
102 They are chained through the CONST_DOUBLE_CHAIN.
103 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
104 In that case, CONST_DOUBLE_MEM is either a MEM,
105 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
106 rtx x_const_double_chain;
109 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
110 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
111 #define first_pool (cfun->varasm->x_first_pool)
112 #define last_pool (cfun->varasm->x_last_pool)
113 #define pool_offset (cfun->varasm->x_pool_offset)
114 #define const_double_chain (cfun->varasm->x_const_double_chain)
116 /* Number for making the label on the next
117 constant that is stored in memory. */
119 int const_labelno;
121 /* Number for making the label on the next
122 static variable internal to a function. */
124 int var_labelno;
126 /* Carry information from ASM_DECLARE_OBJECT_NAME
127 to ASM_FINISH_DECLARE_OBJECT. */
129 int size_directive_output;
131 /* The last decl for which assemble_variable was called,
132 if it did ASM_DECLARE_OBJECT_NAME.
133 If the last call to assemble_variable didn't do that,
134 this holds 0. */
136 tree last_assemble_variable_decl;
138 static const char *strip_reg_name PARAMS ((const char *));
139 static int contains_pointers_p PARAMS ((tree));
140 static void assemble_real_1 PARAMS ((PTR));
141 static void decode_addr_const PARAMS ((tree, struct addr_const *));
142 static int const_hash PARAMS ((tree));
143 static int compare_constant PARAMS ((tree,
144 struct constant_descriptor *));
145 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
146 static struct constant_descriptor *record_constant PARAMS ((tree));
147 static void record_constant_1 PARAMS ((tree));
148 static tree copy_constant PARAMS ((tree));
149 static void output_constant_def_contents PARAMS ((tree, int, int));
150 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
151 struct rtx_const *));
152 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
153 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
154 struct constant_descriptor *));
155 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
156 rtx));
157 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
158 static void mark_constant_pool PARAMS ((void));
159 static void mark_constants PARAMS ((rtx));
160 static int mark_constant PARAMS ((rtx *current_rtx, void *data));
161 static int output_addressed_constants PARAMS ((tree));
162 static void output_after_function_constants PARAMS ((void));
163 static unsigned HOST_WIDE_INT array_size_for_constructor PARAMS ((tree));
164 static unsigned min_align PARAMS ((unsigned, unsigned));
165 static void output_constructor PARAMS ((tree, int, unsigned));
166 #ifdef ASM_WEAKEN_LABEL
167 static void remove_from_pending_weak_list PARAMS ((const char *));
168 #endif
169 static int in_named_entry_eq PARAMS ((const PTR, const PTR));
170 static hashval_t in_named_entry_hash PARAMS ((const PTR));
171 #ifdef ASM_OUTPUT_BSS
172 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
173 #endif
174 #ifdef BSS_SECTION_ASM_OP
175 #ifdef ASM_OUTPUT_ALIGNED_BSS
176 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
177 int, int));
178 #endif
179 #endif /* BSS_SECTION_ASM_OP */
180 static void mark_pool_constant PARAMS ((struct pool_constant *));
181 static void mark_const_hash_entry PARAMS ((void *));
182 static int mark_const_str_htab_1 PARAMS ((void **, void *));
183 static void mark_const_str_htab PARAMS ((void *));
184 static hashval_t const_str_htab_hash PARAMS ((const void *x));
185 static int const_str_htab_eq PARAMS ((const void *x, const void *y));
186 static void const_str_htab_del PARAMS ((void *));
187 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
188 static void resolve_unique_section PARAMS ((tree, int));
190 static enum in_section { no_section, in_text, in_data, in_named
191 #ifdef BSS_SECTION_ASM_OP
192 , in_bss
193 #endif
194 #ifdef CTORS_SECTION_ASM_OP
195 , in_ctors
196 #endif
197 #ifdef DTORS_SECTION_ASM_OP
198 , in_dtors
199 #endif
200 #ifdef EXTRA_SECTIONS
201 , EXTRA_SECTIONS
202 #endif
203 } in_section = no_section;
205 /* Return a non-zero value if DECL has a section attribute. */
206 #ifndef IN_NAMED_SECTION
207 #define IN_NAMED_SECTION(DECL) \
208 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
209 && DECL_SECTION_NAME (DECL) != NULL_TREE)
210 #endif
212 /* Text of section name when in_section == in_named. */
213 static const char *in_named_name;
215 /* Hash table of flags that have been used for a particular named section. */
217 struct in_named_entry
219 const char *name;
220 unsigned int flags;
221 bool declared;
224 static htab_t in_named_htab;
226 /* Define functions like text_section for any extra sections. */
227 #ifdef EXTRA_SECTION_FUNCTIONS
228 EXTRA_SECTION_FUNCTIONS
229 #endif
231 /* Tell assembler to switch to text section. */
233 void
234 text_section ()
236 if (in_section != in_text)
238 #ifdef TEXT_SECTION
239 TEXT_SECTION ();
240 #else
241 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
242 #endif
243 in_section = in_text;
247 /* Tell assembler to switch to data section. */
249 void
250 data_section ()
252 if (in_section != in_data)
254 if (flag_shared_data)
256 #ifdef SHARED_SECTION_ASM_OP
257 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
258 #else
259 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
260 #endif
262 else
263 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
265 in_section = in_data;
268 /* Tell assembler to ALWAYS switch to data section, in case
269 it's not sure where it is. */
271 void
272 force_data_section ()
274 in_section = no_section;
275 data_section ();
278 /* Tell assembler to switch to read-only data section. This is normally
279 the text section. */
281 void
282 readonly_data_section ()
284 #ifdef READONLY_DATA_SECTION
285 READONLY_DATA_SECTION (); /* Note this can call data_section. */
286 #else
287 text_section ();
288 #endif
291 /* Determine if we're in the text section. */
294 in_text_section ()
296 return in_section == in_text;
299 /* Determine if we're in the data section. */
302 in_data_section ()
304 return in_section == in_data;
307 /* Helper routines for maintaining in_named_htab. */
309 static int
310 in_named_entry_eq (p1, p2)
311 const PTR p1;
312 const PTR p2;
314 const struct in_named_entry *old = p1;
315 const char *new = p2;
317 return strcmp (old->name, new) == 0;
320 static hashval_t
321 in_named_entry_hash (p)
322 const PTR p;
324 const struct in_named_entry *old = p;
325 return htab_hash_string (old->name);
328 /* If SECTION has been seen before as a named section, return the flags
329 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
330 set of flags for a section to have, so 0 does not mean that the section
331 has not been seen. */
333 unsigned int
334 get_named_section_flags (section)
335 const char *section;
337 struct in_named_entry **slot;
339 slot = (struct in_named_entry**)
340 htab_find_slot_with_hash (in_named_htab, section,
341 htab_hash_string (section), NO_INSERT);
343 return slot ? (*slot)->flags : 0;
346 /* Returns true if the section has been declared before. Sets internal
347 flag on this section in in_named_hash so subsequent calls on this
348 section will return false. */
350 bool
351 named_section_first_declaration (name)
352 const char *name;
354 struct in_named_entry **slot;
356 slot = (struct in_named_entry**)
357 htab_find_slot_with_hash (in_named_htab, name,
358 htab_hash_string (name), NO_INSERT);
359 if (! (*slot)->declared)
361 (*slot)->declared = true;
362 return true;
364 else
366 return false;
371 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
372 different set of flags, return false. */
374 bool
375 set_named_section_flags (section, flags)
376 const char *section;
377 unsigned int flags;
379 struct in_named_entry **slot, *entry;
381 slot = (struct in_named_entry**)
382 htab_find_slot_with_hash (in_named_htab, section,
383 htab_hash_string (section), INSERT);
384 entry = *slot;
386 if (!entry)
388 entry = (struct in_named_entry *) xmalloc (sizeof (*entry));
389 *slot = entry;
390 entry->name = ggc_strdup (section);
391 entry->flags = flags;
392 entry->declared = false;
394 else if (entry->flags != flags)
395 return false;
397 return true;
400 /* Tell assembler to change to section NAME with attributes FLAGS. */
402 void
403 named_section_flags (name, flags)
404 const char *name;
405 unsigned int flags;
407 if (in_section != in_named || strcmp (name, in_named_name) != 0)
409 if (! set_named_section_flags (name, flags))
410 abort ();
412 (* targetm.asm_out.named_section) (name, flags);
414 if (flags & SECTION_FORGET)
415 in_section = no_section;
416 else
418 in_named_name = ggc_strdup (name);
419 in_section = in_named;
424 /* Tell assembler to change to section NAME for DECL.
425 If DECL is NULL, just switch to section NAME.
426 If NAME is NULL, get the name from DECL.
427 If RELOC is 1, the initializer for DECL contains relocs. */
429 void
430 named_section (decl, name, reloc)
431 tree decl;
432 const char *name;
433 int reloc;
435 unsigned int flags;
437 if (decl != NULL_TREE && !DECL_P (decl))
438 abort ();
439 if (name == NULL)
440 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
442 flags = (* targetm.section_type_flags) (decl, name, reloc);
444 /* Sanity check user variables for flag changes. Non-user
445 section flag changes will abort in named_section_flags. */
446 if (decl && ! set_named_section_flags (name, flags))
448 error_with_decl (decl, "%s causes a section type conflict");
449 flags = get_named_section_flags (name);
452 named_section_flags (name, flags);
455 /* If required, set DECL_SECTION_NAME to a unique name. */
457 static void
458 resolve_unique_section (decl, reloc)
459 tree decl;
460 int reloc ATTRIBUTE_UNUSED;
462 if (DECL_SECTION_NAME (decl) == NULL_TREE
463 && (flag_function_sections
464 || (targetm.have_named_sections
465 && DECL_ONE_ONLY (decl))))
466 UNIQUE_SECTION (decl, reloc);
469 #ifdef BSS_SECTION_ASM_OP
471 /* Tell the assembler to switch to the bss section. */
473 void
474 bss_section ()
476 if (in_section != in_bss)
478 #ifdef SHARED_BSS_SECTION_ASM_OP
479 if (flag_shared_data)
480 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
481 else
482 #endif
483 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
485 in_section = in_bss;
489 #ifdef ASM_OUTPUT_BSS
491 /* Utility function for ASM_OUTPUT_BSS for targets to use if
492 they don't support alignments in .bss.
493 ??? It is believed that this function will work in most cases so such
494 support is localized here. */
496 static void
497 asm_output_bss (file, decl, name, size, rounded)
498 FILE *file;
499 tree decl ATTRIBUTE_UNUSED;
500 const char *name;
501 int size ATTRIBUTE_UNUSED, rounded;
503 ASM_GLOBALIZE_LABEL (file, name);
504 bss_section ();
505 #ifdef ASM_DECLARE_OBJECT_NAME
506 last_assemble_variable_decl = decl;
507 ASM_DECLARE_OBJECT_NAME (file, name, decl);
508 #else
509 /* Standard thing is just output label for the object. */
510 ASM_OUTPUT_LABEL (file, name);
511 #endif /* ASM_DECLARE_OBJECT_NAME */
512 ASM_OUTPUT_SKIP (file, rounded);
515 #endif
517 #ifdef ASM_OUTPUT_ALIGNED_BSS
519 /* Utility function for targets to use in implementing
520 ASM_OUTPUT_ALIGNED_BSS.
521 ??? It is believed that this function will work in most cases so such
522 support is localized here. */
524 static void
525 asm_output_aligned_bss (file, decl, name, size, align)
526 FILE *file;
527 tree decl ATTRIBUTE_UNUSED;
528 const char *name;
529 int size, align;
531 ASM_GLOBALIZE_LABEL (file, name);
532 bss_section ();
533 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
534 #ifdef ASM_DECLARE_OBJECT_NAME
535 last_assemble_variable_decl = decl;
536 ASM_DECLARE_OBJECT_NAME (file, name, decl);
537 #else
538 /* Standard thing is just output label for the object. */
539 ASM_OUTPUT_LABEL (file, name);
540 #endif /* ASM_DECLARE_OBJECT_NAME */
541 ASM_OUTPUT_SKIP (file, size ? size : 1);
544 #endif
546 #endif /* BSS_SECTION_ASM_OP */
548 /* Switch to the section for function DECL.
550 If DECL is NULL_TREE, switch to the text section.
551 ??? It's not clear that we will ever be passed NULL_TREE, but it's
552 safer to handle it. */
554 void
555 function_section (decl)
556 tree decl;
558 if (decl != NULL_TREE
559 && DECL_SECTION_NAME (decl) != NULL_TREE)
560 named_section (decl, (char *) 0, 0);
561 else
562 text_section ();
565 /* Switch to section for variable DECL.
567 RELOC is the `reloc' argument to SELECT_SECTION. */
569 void
570 variable_section (decl, reloc)
571 tree decl;
572 int reloc;
574 if (IN_NAMED_SECTION (decl))
575 named_section (decl, NULL, reloc);
576 else
578 /* C++ can have const variables that get initialized from constructors,
579 and thus can not be in a readonly section. We prevent this by
580 verifying that the initial value is constant for objects put in a
581 readonly section.
583 error_mark_node is used by the C front end to indicate that the
584 initializer has not been seen yet. In this case, we assume that
585 the initializer must be constant.
587 C++ uses error_mark_node for variables that have complicated
588 initializers, but these variables go in BSS so we won't be called
589 for them. */
591 #ifdef SELECT_SECTION
592 SELECT_SECTION (decl, reloc, DECL_ALIGN (decl));
593 #else
594 if (DECL_READONLY_SECTION (decl, reloc))
595 readonly_data_section ();
596 else
597 data_section ();
598 #endif
602 /* Tell assembler to switch to the section for the exception handling
603 table. */
605 void
606 exception_section ()
608 #if defined (EXCEPTION_SECTION)
609 EXCEPTION_SECTION ();
610 #else
611 if (targetm.have_named_sections)
612 named_section (NULL_TREE, ".gcc_except_table", 0);
613 else if (flag_pic)
614 data_section ();
615 else
616 readonly_data_section ();
617 #endif
620 /* Tell assembler to switch to the section for string merging. */
622 void
623 mergeable_string_section (decl, align, flags)
624 tree decl ATTRIBUTE_UNUSED;
625 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
626 unsigned int flags ATTRIBUTE_UNUSED;
628 #ifdef HAVE_GAS_SHF_MERGE
629 if (flag_merge_constants
630 && TREE_CODE (decl) == STRING_CST
631 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
632 && align <= 256
633 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
635 enum machine_mode mode;
636 unsigned int modesize;
637 const char *str;
638 int i, j, len, unit;
639 char name[30];
641 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
642 modesize = GET_MODE_BITSIZE (mode);
643 if (modesize >= 8 && modesize <= 256
644 && (modesize & (modesize - 1)) == 0)
646 if (align < modesize)
647 align = modesize;
649 str = TREE_STRING_POINTER (decl);
650 len = TREE_STRING_LENGTH (decl);
651 unit = GET_MODE_SIZE (mode);
653 /* Check for embedded NUL characters. */
654 for (i = 0; i < len; i += unit)
656 for (j = 0; j < unit; j++)
657 if (str [i + j] != '\0')
658 break;
659 if (j == unit)
660 break;
662 if (i == len - unit)
664 sprintf (name, ".rodata.str%d.%d", modesize / 8,
665 (int) (align / 8));
666 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
667 if (!i && modesize < align)
669 /* A "" string with requested alignment greater than
670 character size might cause a problem:
671 if some other string required even bigger
672 alignment than "", then linker might think the
673 "" is just part of padding after some other string
674 and not put it into the hash table initially.
675 But this means "" could have smaller alignment
676 than requested. */
677 #ifdef ASM_OUTPUT_SECTION_START
678 named_section_flags (name, flags);
679 ASM_OUTPUT_SECTION_START (asm_out_file);
680 #else
681 readonly_data_section ();
682 #endif
683 return;
686 named_section_flags (name, flags);
687 return;
691 #endif
692 readonly_data_section ();
695 /* Tell assembler to switch to the section for constant merging. */
697 void
698 mergeable_constant_section (mode, align, flags)
699 enum machine_mode mode ATTRIBUTE_UNUSED;
700 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
701 unsigned int flags ATTRIBUTE_UNUSED;
703 #ifdef HAVE_GAS_SHF_MERGE
704 unsigned int modesize = GET_MODE_BITSIZE (mode);
706 if (flag_merge_constants
707 && mode != VOIDmode
708 && mode != BLKmode
709 && modesize <= align
710 && align >= 8
711 && align <= 256
712 && (align & (align - 1)) == 0)
714 char name[24];
716 sprintf (name, ".rodata.cst%d", (int) (align / 8));
717 flags |= (align / 8) | SECTION_MERGE;
718 named_section_flags (name, flags);
719 return;
721 #endif
722 readonly_data_section ();
725 /* Given NAME, a putative register name, discard any customary prefixes. */
727 static const char *
728 strip_reg_name (name)
729 const char *name;
731 #ifdef REGISTER_PREFIX
732 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
733 name += strlen (REGISTER_PREFIX);
734 #endif
735 if (name[0] == '%' || name[0] == '#')
736 name++;
737 return name;
740 /* Decode an `asm' spec for a declaration as a register name.
741 Return the register number, or -1 if nothing specified,
742 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
743 or -3 if ASMSPEC is `cc' and is not recognized,
744 or -4 if ASMSPEC is `memory' and is not recognized.
745 Accept an exact spelling or a decimal number.
746 Prefixes such as % are optional. */
749 decode_reg_name (asmspec)
750 const char *asmspec;
752 if (asmspec != 0)
754 int i;
756 /* Get rid of confusing prefixes. */
757 asmspec = strip_reg_name (asmspec);
759 /* Allow a decimal number as a "register name". */
760 for (i = strlen (asmspec) - 1; i >= 0; i--)
761 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
762 break;
763 if (asmspec[0] != 0 && i < 0)
765 i = atoi (asmspec);
766 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
767 return i;
768 else
769 return -2;
772 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
773 if (reg_names[i][0]
774 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
775 return i;
777 #ifdef ADDITIONAL_REGISTER_NAMES
779 static const struct { const char *const name; const int number; } table[]
780 = ADDITIONAL_REGISTER_NAMES;
782 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
783 if (! strcmp (asmspec, table[i].name))
784 return table[i].number;
786 #endif /* ADDITIONAL_REGISTER_NAMES */
788 if (!strcmp (asmspec, "memory"))
789 return -4;
791 if (!strcmp (asmspec, "cc"))
792 return -3;
794 return -2;
797 return -1;
800 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
801 have static storage duration. In other words, it should not be an
802 automatic variable, including PARM_DECLs.
804 There is, however, one exception: this function handles variables
805 explicitly placed in a particular register by the user.
807 ASMSPEC, if not 0, is the string which the user specified as the
808 assembler symbol name.
810 This is never called for PARM_DECL nodes. */
812 void
813 make_decl_rtl (decl, asmspec)
814 tree decl;
815 const char *asmspec;
817 int top_level = (DECL_CONTEXT (decl) == NULL_TREE);
818 const char *name = 0;
819 const char *new_name = 0;
820 int reg_number;
821 rtx x;
823 /* Check that we are not being given an automatic variable. */
824 /* A weak alias has TREE_PUBLIC set but not the other bits. */
825 if (TREE_CODE (decl) == PARM_DECL
826 || TREE_CODE (decl) == RESULT_DECL
827 || (TREE_CODE (decl) == VAR_DECL
828 && !TREE_STATIC (decl)
829 && !TREE_PUBLIC (decl)
830 && !DECL_EXTERNAL (decl)
831 && !DECL_REGISTER (decl)))
832 abort ();
833 /* And that we were not given a type or a label. */
834 else if (TREE_CODE (decl) == TYPE_DECL
835 || TREE_CODE (decl) == LABEL_DECL)
836 abort ();
838 /* For a duplicate declaration, we can be called twice on the
839 same DECL node. Don't discard the RTL already made. */
840 if (DECL_RTL_SET_P (decl))
842 /* If the old RTL had the wrong mode, fix the mode. */
843 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
845 rtx rtl = DECL_RTL (decl);
846 PUT_MODE (rtl, DECL_MODE (decl));
849 /* ??? Another way to do this would be to do what halfpic.c does
850 and maintain a hashed table of such critters. */
851 /* ??? Another way to do this would be to pass a flag bit to
852 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
853 /* Let the target reassign the RTL if it wants.
854 This is necessary, for example, when one machine specific
855 decl attribute overrides another. */
856 #ifdef REDO_SECTION_INFO_P
857 if (REDO_SECTION_INFO_P (decl))
858 ENCODE_SECTION_INFO (decl);
859 #endif
860 return;
863 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
865 reg_number = decode_reg_name (asmspec);
866 if (reg_number == -2)
868 /* ASMSPEC is given, and not the name of a register. Mark the
869 name with a star so assemble_name won't munge it. */
870 char *starred = alloca (strlen (asmspec) + 2);
871 starred[0] = '*';
872 strcpy (starred + 1, asmspec);
873 new_name = starred;
876 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
878 /* First detect errors in declaring global registers. */
879 if (reg_number == -1)
880 error_with_decl (decl, "register name not specified for `%s'");
881 else if (reg_number < 0)
882 error_with_decl (decl, "invalid register name for `%s'");
883 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
884 error_with_decl (decl,
885 "data type of `%s' isn't suitable for a register");
886 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
887 error_with_decl (decl,
888 "register specified for `%s' isn't suitable for data type");
889 /* Now handle properly declared static register variables. */
890 else
892 int nregs;
894 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
896 DECL_INITIAL (decl) = 0;
897 error ("global register variable has initial value");
899 if (TREE_THIS_VOLATILE (decl))
900 warning ("volatile register variables don't work as you might wish");
902 /* If the user specified one of the eliminables registers here,
903 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
904 confused with that register and be eliminated. Although this
905 usage is somewhat suspect, we nevertheless use the following
906 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
908 SET_DECL_RTL (decl,
909 gen_rtx_REG (DECL_MODE (decl),
910 FIRST_PSEUDO_REGISTER));
911 REGNO (DECL_RTL (decl)) = reg_number;
912 REG_USERVAR_P (DECL_RTL (decl)) = 1;
914 if (TREE_STATIC (decl))
916 /* Make this register global, so not usable for anything
917 else. */
918 #ifdef ASM_DECLARE_REGISTER_GLOBAL
919 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
920 #endif
921 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
922 while (nregs > 0)
923 globalize_reg (reg_number + --nregs);
926 /* As a register variable, it has no section. */
927 return;
931 /* Now handle ordinary static variables and functions (in memory).
932 Also handle vars declared register invalidly. */
934 if (reg_number >= 0 || reg_number == -3)
935 error_with_decl (decl,
936 "register name given for non-register variable `%s'");
938 /* Specifying a section attribute on a variable forces it into a
939 non-.bss section, and thus it cannot be common. */
940 if (TREE_CODE (decl) == VAR_DECL
941 && DECL_SECTION_NAME (decl) != NULL_TREE
942 && DECL_INITIAL (decl) == NULL_TREE
943 && DECL_COMMON (decl))
944 DECL_COMMON (decl) = 0;
946 /* Can't use just the variable's own name for a variable
947 whose scope is less than the whole file, unless it's a member
948 of a local class (which will already be unambiguous).
949 Concatenate a distinguishing number. */
950 if (!top_level && !TREE_PUBLIC (decl)
951 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
952 && asmspec == 0
953 && name == IDENTIFIER_POINTER (DECL_NAME (decl)))
955 char *label;
956 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
957 var_labelno++;
958 new_name = label;
961 /* When -fprefix-function-name is used, the functions
962 names are prefixed. Only nested function names are not
963 prefixed. */
964 else if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
966 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
967 char *pname;
969 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
970 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
971 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
972 new_name = pname;
975 if (name != new_name)
977 SET_DECL_ASSEMBLER_NAME (decl, get_identifier (new_name));
978 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
981 /* If this variable is to be treated as volatile, show its
982 tree node has side effects. */
983 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
984 && TREE_PUBLIC (decl))
985 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
986 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
987 TREE_SIDE_EFFECTS (decl) = 1;
989 x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
990 SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
991 if (TREE_CODE (decl) != FUNCTION_DECL)
992 set_mem_attributes (x, decl, 1);
993 SET_DECL_RTL (decl, x);
995 /* Optionally set flags or add text to the name to record information
996 such as that it is a function name.
997 If the name is changed, the macro ASM_OUTPUT_LABELREF
998 will have to know how to strip this information. */
999 #ifdef ENCODE_SECTION_INFO
1000 ENCODE_SECTION_INFO (decl);
1001 #endif
1004 /* Make the rtl for variable VAR be volatile.
1005 Use this only for static variables. */
1007 void
1008 make_var_volatile (var)
1009 tree var;
1011 if (GET_CODE (DECL_RTL (var)) != MEM)
1012 abort ();
1014 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
1017 /* Output alignment directive to align for constant expression EXP. */
1019 void
1020 assemble_constant_align (exp)
1021 tree exp;
1023 int align;
1025 /* Align the location counter as required by EXP's data type. */
1026 align = TYPE_ALIGN (TREE_TYPE (exp));
1027 #ifdef CONSTANT_ALIGNMENT
1028 align = CONSTANT_ALIGNMENT (exp, align);
1029 #endif
1031 if (align > BITS_PER_UNIT)
1033 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1037 /* Output a string of literal assembler code
1038 for an `asm' keyword used between functions. */
1040 void
1041 assemble_asm (string)
1042 tree string;
1044 app_enable ();
1046 if (TREE_CODE (string) == ADDR_EXPR)
1047 string = TREE_OPERAND (string, 0);
1049 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1052 /* Record an element in the table of global destructors. SYMBOL is
1053 a SYMBOL_REF of the function to be called; PRIORITY is a number
1054 between 0 and MAX_INIT_PRIORITY. */
1056 void
1057 default_stabs_asm_out_destructor (symbol, priority)
1058 rtx symbol;
1059 int priority ATTRIBUTE_UNUSED;
1061 /* Tell GNU LD that this is part of the static destructor set.
1062 This will work for any system that uses stabs, most usefully
1063 aout systems. */
1064 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1065 assemble_name (asm_out_file, XSTR (symbol, 0));
1066 fputc ('\n', asm_out_file);
1069 void
1070 default_named_section_asm_out_destructor (symbol, priority)
1071 rtx symbol;
1072 int priority;
1074 const char *section = ".dtors";
1075 char buf[16];
1077 /* ??? This only works reliably with the GNU linker. */
1078 if (priority != DEFAULT_INIT_PRIORITY)
1080 sprintf (buf, ".dtors.%.5u",
1081 /* Invert the numbering so the linker puts us in the proper
1082 order; constructors are run from right to left, and the
1083 linker sorts in increasing order. */
1084 MAX_INIT_PRIORITY - priority);
1085 section = buf;
1088 named_section_flags (section, SECTION_WRITE);
1089 assemble_align (POINTER_SIZE);
1090 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1093 #ifdef DTORS_SECTION_ASM_OP
1094 void
1095 dtors_section ()
1097 if (in_section != in_dtors)
1099 in_section = in_dtors;
1100 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1101 fputc ('\n', asm_out_file);
1105 void
1106 default_dtor_section_asm_out_destructor (symbol, priority)
1107 rtx symbol;
1108 int priority ATTRIBUTE_UNUSED;
1110 dtors_section ();
1111 assemble_align (POINTER_SIZE);
1112 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1114 #endif
1116 /* Likewise for global constructors. */
1118 void
1119 default_stabs_asm_out_constructor (symbol, priority)
1120 rtx symbol;
1121 int priority ATTRIBUTE_UNUSED;
1123 /* Tell GNU LD that this is part of the static destructor set.
1124 This will work for any system that uses stabs, most usefully
1125 aout systems. */
1126 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1127 assemble_name (asm_out_file, XSTR (symbol, 0));
1128 fputc ('\n', asm_out_file);
1131 void
1132 default_named_section_asm_out_constructor (symbol, priority)
1133 rtx symbol;
1134 int priority;
1136 const char *section = ".ctors";
1137 char buf[16];
1139 /* ??? This only works reliably with the GNU linker. */
1140 if (priority != DEFAULT_INIT_PRIORITY)
1142 sprintf (buf, ".ctors.%.5u",
1143 /* Invert the numbering so the linker puts us in the proper
1144 order; constructors are run from right to left, and the
1145 linker sorts in increasing order. */
1146 MAX_INIT_PRIORITY - priority);
1147 section = buf;
1150 named_section_flags (section, SECTION_WRITE);
1151 assemble_align (POINTER_SIZE);
1152 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1155 #ifdef CTORS_SECTION_ASM_OP
1156 void
1157 ctors_section ()
1159 if (in_section != in_ctors)
1161 in_section = in_ctors;
1162 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1163 fputc ('\n', asm_out_file);
1167 void
1168 default_ctor_section_asm_out_constructor (symbol, priority)
1169 rtx symbol;
1170 int priority ATTRIBUTE_UNUSED;
1172 ctors_section ();
1173 assemble_align (POINTER_SIZE);
1174 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1176 #endif
1178 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1179 a non-zero value if the constant pool should be output before the
1180 start of the function, or a zero value if the pool should output
1181 after the end of the function. The default is to put it before the
1182 start. */
1184 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1185 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1186 #endif
1188 /* Output assembler code for the constant pool of a function and associated
1189 with defining the name of the function. DECL describes the function.
1190 NAME is the function's name. For the constant pool, we use the current
1191 constant pool data. */
1193 void
1194 assemble_start_function (decl, fnname)
1195 tree decl;
1196 const char *fnname;
1198 int align;
1200 /* The following code does not need preprocessing in the assembler. */
1202 app_disable ();
1204 if (CONSTANT_POOL_BEFORE_FUNCTION)
1205 output_constant_pool (fnname, decl);
1207 resolve_unique_section (decl, 0);
1208 function_section (decl);
1210 /* Tell assembler to move to target machine's alignment for functions. */
1211 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1212 if (align > 0)
1214 ASM_OUTPUT_ALIGN (asm_out_file, align);
1217 /* Handle a user-specified function alignment.
1218 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1219 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1220 if (align_functions_log > align)
1222 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1223 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1224 align_functions_log, align_functions-1);
1225 #else
1226 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1227 #endif
1230 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1231 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1232 #endif
1234 (*debug_hooks->begin_function) (decl);
1236 /* Make function name accessible from other files, if appropriate. */
1238 if (TREE_PUBLIC (decl))
1240 if (! first_global_object_name)
1242 const char *p;
1243 char *name;
1245 STRIP_NAME_ENCODING (p, fnname);
1246 name = permalloc (strlen (p) + 1);
1247 strcpy (name, p);
1249 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1250 first_global_object_name = name;
1251 else
1252 weak_global_object_name = name;
1255 #ifdef ASM_WEAKEN_LABEL
1256 if (DECL_WEAK (decl))
1258 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1259 /* Remove this function from the pending weak list so that
1260 we do not emit multiple .weak directives for it. */
1261 remove_from_pending_weak_list
1262 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1264 else
1265 #endif
1266 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1269 /* Do any machine/system dependent processing of the function name */
1270 #ifdef ASM_DECLARE_FUNCTION_NAME
1271 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1272 #else
1273 /* Standard thing is just output label for the function. */
1274 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1275 #endif /* ASM_DECLARE_FUNCTION_NAME */
1278 /* Output assembler code associated with defining the size of the
1279 function. DECL describes the function. NAME is the function's name. */
1281 void
1282 assemble_end_function (decl, fnname)
1283 tree decl;
1284 const char *fnname;
1286 #ifdef ASM_DECLARE_FUNCTION_SIZE
1287 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1288 #endif
1289 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1291 output_constant_pool (fnname, decl);
1292 function_section (decl); /* need to switch back */
1295 /* Output any constants which should appear after the function. */
1296 output_after_function_constants ();
1299 /* Assemble code to leave SIZE bytes of zeros. */
1301 void
1302 assemble_zeros (size)
1303 int size;
1305 /* Do no output if -fsyntax-only. */
1306 if (flag_syntax_only)
1307 return;
1309 #ifdef ASM_NO_SKIP_IN_TEXT
1310 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1311 so we must output 0s explicitly in the text section. */
1312 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1314 int i;
1315 for (i = 0; i < size; i++)
1316 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1318 else
1319 #endif
1320 if (size > 0)
1321 ASM_OUTPUT_SKIP (asm_out_file, size);
1324 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1326 void
1327 assemble_align (align)
1328 int align;
1330 if (align > BITS_PER_UNIT)
1332 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1336 /* Assemble a string constant with the specified C string as contents. */
1338 void
1339 assemble_string (p, size)
1340 const char *p;
1341 int size;
1343 int pos = 0;
1344 int maximum = 2000;
1346 /* If the string is very long, split it up. */
1348 while (pos < size)
1350 int thissize = size - pos;
1351 if (thissize > maximum)
1352 thissize = maximum;
1354 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1356 pos += thissize;
1357 p += thissize;
1362 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1363 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1364 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1365 #else
1366 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1367 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1368 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1369 #else
1370 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1371 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1372 #endif
1373 #endif
1375 #if defined ASM_OUTPUT_ALIGNED_BSS
1376 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1377 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1378 #else
1379 #if defined ASM_OUTPUT_BSS
1380 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1381 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1382 #else
1383 #undef ASM_EMIT_BSS
1384 #endif
1385 #endif
1387 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1388 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1389 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1390 #else
1391 #if defined ASM_OUTPUT_ALIGNED_COMMON
1392 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1393 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1394 #else
1395 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1396 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1397 #endif
1398 #endif
1400 static void
1401 asm_emit_uninitialised (decl, name, size, rounded)
1402 tree decl;
1403 const char * name;
1404 int size ATTRIBUTE_UNUSED;
1405 int rounded ATTRIBUTE_UNUSED;
1407 enum
1409 asm_dest_common,
1410 asm_dest_bss,
1411 asm_dest_local
1413 destination = asm_dest_local;
1415 if (TREE_PUBLIC (decl))
1417 #if defined ASM_EMIT_BSS
1418 if (! DECL_COMMON (decl))
1419 destination = asm_dest_bss;
1420 else
1421 #endif
1422 destination = asm_dest_common;
1425 if (flag_shared_data)
1427 switch (destination)
1429 #ifdef ASM_OUTPUT_SHARED_BSS
1430 case asm_dest_bss:
1431 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1432 return;
1433 #endif
1434 #ifdef ASM_OUTPUT_SHARED_COMMON
1435 case asm_dest_common:
1436 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1437 return;
1438 #endif
1439 #ifdef ASM_OUTPUT_SHARED_LOCAL
1440 case asm_dest_local:
1441 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1442 return;
1443 #endif
1444 default:
1445 break;
1449 resolve_unique_section (decl, 0);
1451 switch (destination)
1453 #ifdef ASM_EMIT_BSS
1454 case asm_dest_bss:
1455 ASM_EMIT_BSS (decl, name, size, rounded);
1456 break;
1457 #endif
1458 case asm_dest_common:
1459 ASM_EMIT_COMMON (decl, name, size, rounded);
1460 break;
1461 case asm_dest_local:
1462 ASM_EMIT_LOCAL (decl, name, size, rounded);
1463 break;
1464 default:
1465 abort ();
1468 return;
1471 /* Assemble everything that is needed for a variable or function declaration.
1472 Not used for automatic variables, and not used for function definitions.
1473 Should not be called for variables of incomplete structure type.
1475 TOP_LEVEL is nonzero if this variable has file scope.
1476 AT_END is nonzero if this is the special handling, at end of compilation,
1477 to define things that have had only tentative definitions.
1478 DONT_OUTPUT_DATA if nonzero means don't actually output the
1479 initial value (that will be done by the caller). */
1481 void
1482 assemble_variable (decl, top_level, at_end, dont_output_data)
1483 tree decl;
1484 int top_level ATTRIBUTE_UNUSED;
1485 int at_end ATTRIBUTE_UNUSED;
1486 int dont_output_data;
1488 const char *name;
1489 unsigned int align;
1490 int reloc = 0;
1491 rtx decl_rtl;
1493 last_assemble_variable_decl = 0;
1495 /* Normally no need to say anything here for external references,
1496 since assemble_external is called by the language-specific code
1497 when a declaration is first seen. */
1499 if (DECL_EXTERNAL (decl))
1500 return;
1502 /* Output no assembler code for a function declaration.
1503 Only definitions of functions output anything. */
1505 if (TREE_CODE (decl) == FUNCTION_DECL)
1506 return;
1508 /* Do nothing for global register variables. */
1509 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1511 TREE_ASM_WRITTEN (decl) = 1;
1512 return;
1515 /* If type was incomplete when the variable was declared,
1516 see if it is complete now. */
1518 if (DECL_SIZE (decl) == 0)
1519 layout_decl (decl, 0);
1521 /* Still incomplete => don't allocate it; treat the tentative defn
1522 (which is what it must have been) as an `extern' reference. */
1524 if (!dont_output_data && DECL_SIZE (decl) == 0)
1526 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1527 DECL_SOURCE_LINE (decl),
1528 "storage size of `%s' isn't known",
1529 IDENTIFIER_POINTER (DECL_NAME (decl)));
1530 TREE_ASM_WRITTEN (decl) = 1;
1531 return;
1534 /* The first declaration of a variable that comes through this function
1535 decides whether it is global (in C, has external linkage)
1536 or local (in C, has internal linkage). So do nothing more
1537 if this function has already run. */
1539 if (TREE_ASM_WRITTEN (decl))
1540 return;
1542 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1543 decl_rtl = DECL_RTL (decl);
1545 TREE_ASM_WRITTEN (decl) = 1;
1547 /* Do no output if -fsyntax-only. */
1548 if (flag_syntax_only)
1549 return;
1551 app_disable ();
1553 if (! dont_output_data
1554 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1556 error_with_decl (decl, "size of variable `%s' is too large");
1557 return;
1560 name = XSTR (XEXP (decl_rtl, 0), 0);
1561 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1562 && ! first_global_object_name
1563 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1564 || DECL_INITIAL (decl) == error_mark_node))
1565 && ! DECL_WEAK (decl)
1566 && ! DECL_ONE_ONLY (decl))
1568 const char *p;
1569 char *xname;
1571 STRIP_NAME_ENCODING (p, name);
1572 xname = permalloc (strlen (p) + 1);
1573 strcpy (xname, p);
1574 first_global_object_name = xname;
1577 /* Compute the alignment of this data. */
1579 align = DECL_ALIGN (decl);
1581 /* In the case for initialing an array whose length isn't specified,
1582 where we have not yet been able to do the layout,
1583 figure out the proper alignment now. */
1584 if (dont_output_data && DECL_SIZE (decl) == 0
1585 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1586 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1588 /* Some object file formats have a maximum alignment which they support.
1589 In particular, a.out format supports a maximum alignment of 4. */
1590 #ifndef MAX_OFILE_ALIGNMENT
1591 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1592 #endif
1593 if (align > MAX_OFILE_ALIGNMENT)
1595 warning_with_decl (decl,
1596 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1597 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1598 align = MAX_OFILE_ALIGNMENT;
1601 /* On some machines, it is good to increase alignment sometimes. */
1602 if (! DECL_USER_ALIGN (decl))
1604 #ifdef DATA_ALIGNMENT
1605 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1606 #endif
1607 #ifdef CONSTANT_ALIGNMENT
1608 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1609 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1610 #endif
1613 /* Reset the alignment in case we have made it tighter, so we can benefit
1614 from it in get_pointer_alignment. */
1615 DECL_ALIGN (decl) = align;
1617 /* Handle uninitialized definitions. */
1619 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1620 /* If the target can't output uninitialized but not common global data
1621 in .bss, then we have to use .data. */
1622 #if ! defined ASM_EMIT_BSS
1623 && DECL_COMMON (decl)
1624 #endif
1625 && DECL_SECTION_NAME (decl) == NULL_TREE
1626 && ! dont_output_data)
1628 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1629 unsigned HOST_WIDE_INT rounded = size;
1631 /* Don't allocate zero bytes of common,
1632 since that means "undefined external" in the linker. */
1633 if (size == 0)
1634 rounded = 1;
1636 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1637 so that each uninitialized object starts on such a boundary. */
1638 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1639 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1640 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1642 /* Don't continue this line--convex cc version 4.1 would lose. */
1643 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1644 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1645 warning_with_decl
1646 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1647 #endif
1649 asm_emit_uninitialised (decl, name, size, rounded);
1651 return;
1654 /* Handle initialized definitions.
1655 Also handle uninitialized global definitions if -fno-common and the
1656 target doesn't support ASM_OUTPUT_BSS. */
1658 /* First make the assembler name(s) global if appropriate. */
1659 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1661 #ifdef ASM_WEAKEN_LABEL
1662 if (DECL_WEAK (decl))
1664 ASM_WEAKEN_LABEL (asm_out_file, name);
1665 /* Remove this variable from the pending weak list so that
1666 we do not emit multiple .weak directives for it. */
1667 remove_from_pending_weak_list
1668 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1670 else
1671 #endif
1672 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1675 /* Output any data that we will need to use the address of. */
1676 if (DECL_INITIAL (decl) == error_mark_node)
1677 reloc = contains_pointers_p (TREE_TYPE (decl));
1678 else if (DECL_INITIAL (decl))
1679 reloc = output_addressed_constants (DECL_INITIAL (decl));
1681 /* Switch to the appropriate section. */
1682 resolve_unique_section (decl, reloc);
1683 variable_section (decl, reloc);
1685 /* dbxout.c needs to know this. */
1686 if (in_text_section ())
1687 DECL_IN_TEXT_SECTION (decl) = 1;
1689 /* Output the alignment of this data. */
1690 if (align > BITS_PER_UNIT)
1692 ASM_OUTPUT_ALIGN (asm_out_file,
1693 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1696 /* Do any machine/system dependent processing of the object. */
1697 #ifdef ASM_DECLARE_OBJECT_NAME
1698 last_assemble_variable_decl = decl;
1699 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1700 #else
1701 /* Standard thing is just output label for the object. */
1702 ASM_OUTPUT_LABEL (asm_out_file, name);
1703 #endif /* ASM_DECLARE_OBJECT_NAME */
1705 if (!dont_output_data)
1707 if (DECL_INITIAL (decl))
1708 /* Output the actual data. */
1709 output_constant (DECL_INITIAL (decl),
1710 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1711 align);
1712 else
1713 /* Leave space for it. */
1714 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1718 /* Return 1 if type TYPE contains any pointers. */
1720 static int
1721 contains_pointers_p (type)
1722 tree type;
1724 switch (TREE_CODE (type))
1726 case POINTER_TYPE:
1727 case REFERENCE_TYPE:
1728 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1729 so I'll play safe and return 1. */
1730 case OFFSET_TYPE:
1731 return 1;
1733 case RECORD_TYPE:
1734 case UNION_TYPE:
1735 case QUAL_UNION_TYPE:
1737 tree fields;
1738 /* For a type that has fields, see if the fields have pointers. */
1739 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1740 if (TREE_CODE (fields) == FIELD_DECL
1741 && contains_pointers_p (TREE_TYPE (fields)))
1742 return 1;
1743 return 0;
1746 case ARRAY_TYPE:
1747 /* An array type contains pointers if its element type does. */
1748 return contains_pointers_p (TREE_TYPE (type));
1750 default:
1751 return 0;
1755 /* Output something to declare an external symbol to the assembler.
1756 (Most assemblers don't need this, so we normally output nothing.)
1757 Do nothing if DECL is not external. */
1759 void
1760 assemble_external (decl)
1761 tree decl ATTRIBUTE_UNUSED;
1763 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1764 main body of this code is only rarely exercised. To provide some
1765 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1766 open. If it's not, we should not be calling this function. */
1767 if (!asm_out_file)
1768 abort ();
1770 #ifdef ASM_OUTPUT_EXTERNAL
1771 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1773 rtx rtl = DECL_RTL (decl);
1775 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1776 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1778 /* Some systems do require some output. */
1779 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1780 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1783 #endif
1786 /* Similar, for calling a library function FUN. */
1788 void
1789 assemble_external_libcall (fun)
1790 rtx fun ATTRIBUTE_UNUSED;
1792 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1793 /* Declare library function name external when first used, if nec. */
1794 if (! SYMBOL_REF_USED (fun))
1796 SYMBOL_REF_USED (fun) = 1;
1797 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1799 #endif
1802 /* Declare the label NAME global. */
1804 void
1805 assemble_global (name)
1806 const char *name;
1808 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1811 /* Assemble a label named NAME. */
1813 void
1814 assemble_label (name)
1815 const char *name;
1817 ASM_OUTPUT_LABEL (asm_out_file, name);
1820 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1821 If NAME starts with a *, the rest of NAME is output verbatim.
1822 Otherwise NAME is transformed in an implementation-defined way
1823 (usually by the addition of an underscore).
1824 Many macros in the tm file are defined to call this function. */
1826 void
1827 assemble_name (file, name)
1828 FILE *file;
1829 const char *name;
1831 const char *real_name;
1832 tree id;
1834 STRIP_NAME_ENCODING (real_name, name);
1835 if (flag_prefix_function_name
1836 && ! memcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1837 real_name = real_name + CHKR_PREFIX_SIZE;
1839 id = maybe_get_identifier (real_name);
1840 if (id)
1841 TREE_SYMBOL_REFERENCED (id) = 1;
1843 if (name[0] == '*')
1844 fputs (&name[1], file);
1845 else
1846 ASM_OUTPUT_LABELREF (file, name);
1849 /* Allocate SIZE bytes writable static space with a gensym name
1850 and return an RTX to refer to its address. */
1853 assemble_static_space (size)
1854 int size;
1856 char name[12];
1857 const char *namestring;
1858 rtx x;
1860 #if 0
1861 if (flag_shared_data)
1862 data_section ();
1863 #endif
1865 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1866 ++const_labelno;
1867 namestring = ggc_strdup (name);
1869 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1871 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1872 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1873 BIGGEST_ALIGNMENT);
1874 #else
1875 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1876 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1877 #else
1879 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1880 so that each uninitialized object starts on such a boundary. */
1881 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1882 int rounded ATTRIBUTE_UNUSED
1883 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1884 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1885 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1886 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1888 #endif
1889 #endif
1890 return x;
1893 /* Assemble the static constant template for function entry trampolines.
1894 This is done at most once per compilation.
1895 Returns an RTX for the address of the template. */
1897 #ifdef TRAMPOLINE_TEMPLATE
1899 assemble_trampoline_template ()
1901 char label[256];
1902 const char *name;
1903 int align;
1905 /* By default, put trampoline templates in read-only data section. */
1907 #ifdef TRAMPOLINE_SECTION
1908 TRAMPOLINE_SECTION ();
1909 #else
1910 readonly_data_section ();
1911 #endif
1913 /* Write the assembler code to define one. */
1914 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1915 if (align > 0)
1917 ASM_OUTPUT_ALIGN (asm_out_file, align);
1920 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1921 TRAMPOLINE_TEMPLATE (asm_out_file);
1923 /* Record the rtl to refer to it. */
1924 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1925 name = ggc_strdup (label);
1926 return gen_rtx_SYMBOL_REF (Pmode, name);
1928 #endif
1930 /* A and B are either alignments or offsets. Return the minimum alignment
1931 that may be assumed after adding the two together. */
1933 static inline unsigned
1934 min_align (a, b)
1935 unsigned int a, b;
1937 return (a | b) & -(a | b);
1940 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1941 the alignment of the integer in bits. Return 1 if we were able to output
1942 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1943 the constant. */
1946 assemble_integer (x, size, align, force)
1947 rtx x;
1948 unsigned int size;
1949 unsigned int align;
1950 int force;
1952 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1953 ASM_OUTPUT... macros. */
1955 if (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT))
1956 switch (size)
1958 #ifdef ASM_OUTPUT_CHAR
1959 case 1:
1960 ASM_OUTPUT_CHAR (asm_out_file, x);
1961 return 1;
1962 #endif
1963 #ifdef ASM_OUTPUT_SHORT
1964 case 2:
1965 ASM_OUTPUT_SHORT (asm_out_file, x);
1966 return 1;
1967 #endif
1968 #ifdef ASM_OUTPUT_INT
1969 case 4:
1970 ASM_OUTPUT_INT (asm_out_file, x);
1971 return 1;
1972 #endif
1973 #ifdef ASM_OUTPUT_DOUBLE_INT
1974 case 8:
1975 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1976 return 1;
1977 #endif
1978 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1979 case 16:
1980 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1981 return 1;
1982 #endif
1984 else
1986 const char *asm_op = NULL;
1988 /* ??? This isn't quite as flexible as the ASM_OUTPUT_INT type hooks.
1989 At present powerpc-eabi can't jump -mrelocatable hoops, so you can
1990 get assembler errors from symbolic references in packed structs. */
1991 switch (size)
1993 #ifdef UNALIGNED_SHORT_ASM_OP
1994 case 2:
1995 asm_op = UNALIGNED_SHORT_ASM_OP;
1996 break;
1997 #endif
1998 #ifdef UNALIGNED_INT_ASM_OP
1999 case 4:
2000 asm_op = UNALIGNED_INT_ASM_OP;
2001 break;
2002 #endif
2003 #ifdef UNALIGNED_DOUBLE_INT_ASM_OP
2004 case 8:
2005 asm_op = UNALIGNED_DOUBLE_INT_ASM_OP;
2006 break;
2007 #endif
2010 if (asm_op)
2012 fputs (asm_op, asm_out_file);
2013 output_addr_const (asm_out_file, x);
2014 fputc ('\n', asm_out_file);
2015 return 1;
2019 /* If we couldn't do it that way, there are two other possibilities: First,
2020 if the machine can output an explicit byte and this is a 1 byte constant,
2021 we can use ASM_OUTPUT_BYTE. */
2023 #ifdef ASM_OUTPUT_BYTE
2024 if (size == 1 && GET_CODE (x) == CONST_INT)
2026 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
2027 return 1;
2029 #endif
2031 /* If SIZE is larger than a single word, try to output the constant
2032 one word at a time. */
2034 if (size > UNITS_PER_WORD)
2036 enum machine_mode mode
2037 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2038 unsigned align2 = min_align (align, BITS_PER_WORD);
2039 unsigned int i;
2041 for (i = 0; i < size / UNITS_PER_WORD; i++)
2043 rtx word = operand_subword (x, i, 0, mode);
2044 if (word == 0)
2045 break;
2046 if (! assemble_integer (word, UNITS_PER_WORD, align2, 0))
2047 break;
2050 if (i == size / UNITS_PER_WORD)
2051 return 1;
2052 /* If we output at least one word and then could not finish,
2053 there is no valid way to continue. */
2054 if (i > 0)
2055 abort ();
2058 /* If unaligned, and this is a constant, emit it one byte at a time. */
2059 if (align < size * BITS_PER_UNIT)
2061 enum machine_mode omode, imode;
2062 unsigned int i;
2064 omode = mode_for_size (BITS_PER_UNIT, MODE_INT, 0);
2065 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2067 for (i = 0; i < size; i++)
2069 rtx byte = simplify_subreg (omode, x, imode, i);
2070 if (byte == 0)
2071 break;
2072 if (! assemble_integer (byte, 1, BITS_PER_UNIT, 0))
2073 break;
2076 if (i == size)
2077 return 1;
2078 /* If we output at least one byte and then could not finish,
2079 there is no valid way to continue. */
2080 if (i > 0)
2081 abort ();
2084 if (force)
2085 abort ();
2087 return 0;
2090 /* Assemble the floating-point constant D into an object of size MODE. */
2091 struct assemble_real_args
2093 REAL_VALUE_TYPE *d;
2094 enum machine_mode mode;
2097 static void
2098 assemble_real_1 (p)
2099 PTR p;
2101 struct assemble_real_args *args = (struct assemble_real_args *) p;
2102 REAL_VALUE_TYPE *d = args->d;
2103 enum machine_mode mode = args->mode;
2105 switch (mode)
2107 #ifdef ASM_OUTPUT_BYTE_FLOAT
2108 case QFmode:
2109 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, *d);
2110 break;
2111 #endif
2112 #ifdef ASM_OUTPUT_SHORT_FLOAT
2113 case HFmode:
2114 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, *d);
2115 break;
2116 #endif
2117 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2118 case TQFmode:
2119 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, *d);
2120 break;
2121 #endif
2122 #ifdef ASM_OUTPUT_FLOAT
2123 case SFmode:
2124 ASM_OUTPUT_FLOAT (asm_out_file, *d);
2125 break;
2126 #endif
2128 #ifdef ASM_OUTPUT_DOUBLE
2129 case DFmode:
2130 ASM_OUTPUT_DOUBLE (asm_out_file, *d);
2131 break;
2132 #endif
2134 #ifdef ASM_OUTPUT_LONG_DOUBLE
2135 case XFmode:
2136 case TFmode:
2137 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, *d);
2138 break;
2139 #endif
2141 default:
2142 abort ();
2146 void
2147 assemble_real (d, mode, align)
2148 REAL_VALUE_TYPE d;
2149 enum machine_mode mode;
2150 unsigned int align;
2152 struct assemble_real_args args;
2153 args.d = &d;
2154 args.mode = mode;
2156 /* We cannot emit unaligned floating point constants. This is slightly
2157 complicated in that we don't know what "unaligned" means exactly. */
2158 #ifdef BIGGEST_FIELD_ALIGNMENT
2159 if (align >= BIGGEST_FIELD_ALIGNMENT)
2161 else
2162 #endif
2163 if (align < GET_MODE_ALIGNMENT (mode))
2164 abort ();
2166 if (do_float_handler (assemble_real_1, (PTR) &args))
2167 return;
2169 internal_error ("floating point trap outputting a constant");
2172 /* Here we combine duplicate floating constants to make
2173 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2175 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2176 For an integer, I0 is the low-order word and I1 is the high-order word.
2177 For a real number, I0 is the word with the low address
2178 and I1 is the word with the high address. */
2181 immed_double_const (i0, i1, mode)
2182 HOST_WIDE_INT i0, i1;
2183 enum machine_mode mode;
2185 rtx r;
2187 if (GET_MODE_CLASS (mode) == MODE_INT
2188 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2190 /* We clear out all bits that don't belong in MODE, unless they and our
2191 sign bit are all one. So we get either a reasonable negative value
2192 or a reasonable unsigned value for this mode. */
2193 int width = GET_MODE_BITSIZE (mode);
2194 if (width < HOST_BITS_PER_WIDE_INT
2195 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2196 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2197 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2198 else if (width == HOST_BITS_PER_WIDE_INT
2199 && ! (i1 == ~0 && i0 < 0))
2200 i1 = 0;
2201 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2202 /* We cannot represent this value as a constant. */
2203 abort ();
2205 /* If this would be an entire word for the target, but is not for
2206 the host, then sign-extend on the host so that the number will look
2207 the same way on the host that it would on the target.
2209 For example, when building a 64 bit alpha hosted 32 bit sparc
2210 targeted compiler, then we want the 32 bit unsigned value -1 to be
2211 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2212 The later confuses the sparc backend. */
2214 if (width < HOST_BITS_PER_WIDE_INT
2215 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2216 i0 |= ((HOST_WIDE_INT) (-1) << width);
2218 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2220 ??? Strictly speaking, this is wrong if we create a CONST_INT
2221 for a large unsigned constant with the size of MODE being
2222 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2223 wider mode. In that case we will mis-interpret it as a negative
2224 number.
2226 Unfortunately, the only alternative is to make a CONST_DOUBLE
2227 for any constant in any mode if it is an unsigned constant larger
2228 than the maximum signed integer in an int on the host. However,
2229 doing this will break everyone that always expects to see a CONST_INT
2230 for SImode and smaller.
2232 We have always been making CONST_INTs in this case, so nothing new
2233 is being broken. */
2235 if (width <= HOST_BITS_PER_WIDE_INT)
2236 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2238 /* If this integer fits in one word, return a CONST_INT. */
2239 if ((i1 == 0 && i0 >= 0)
2240 || (i1 == ~0 && i0 < 0))
2241 return GEN_INT (i0);
2243 /* We use VOIDmode for integers. */
2244 mode = VOIDmode;
2247 /* Search the chain for an existing CONST_DOUBLE with the right value.
2248 If one is found, return it. */
2249 if (cfun != 0)
2250 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2251 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2252 && GET_MODE (r) == mode)
2253 return r;
2255 /* No; make a new one and add it to the chain. */
2256 r = gen_rtx_CONST_DOUBLE (mode, const0_rtx, i0, i1);
2258 /* Don't touch const_double_chain if not inside any function. */
2259 if (current_function_decl != 0)
2261 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2262 const_double_chain = r;
2265 return r;
2268 /* Return a CONST_DOUBLE for a specified `double' value
2269 and machine mode. */
2272 immed_real_const_1 (d, mode)
2273 REAL_VALUE_TYPE d;
2274 enum machine_mode mode;
2276 union real_extract u;
2277 rtx r;
2279 /* Get the desired `double' value as a sequence of ints
2280 since that is how they are stored in a CONST_DOUBLE. */
2282 u.d = d;
2284 /* Detect special cases. */
2285 if (REAL_VALUES_IDENTICAL (dconst0, d))
2286 return CONST0_RTX (mode);
2288 /* Check for NaN first, because some ports (specifically the i386) do not
2289 emit correct ieee-fp code by default, and thus will generate a core
2290 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2291 does a floating point comparison. */
2292 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2293 return CONST1_RTX (mode);
2295 if (sizeof u == sizeof (HOST_WIDE_INT))
2296 return immed_double_const (u.i[0], 0, mode);
2297 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2298 return immed_double_const (u.i[0], u.i[1], mode);
2300 /* The rest of this function handles the case where
2301 a float value requires more than 2 ints of space.
2302 It will be deleted as dead code on machines that don't need it. */
2304 /* Search the chain for an existing CONST_DOUBLE with the right value.
2305 If one is found, return it. */
2306 if (cfun != 0)
2307 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2308 if (! memcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2309 && GET_MODE (r) == mode)
2310 return r;
2312 /* No; make a new one and add it to the chain.
2314 We may be called by an optimizer which may be discarding any memory
2315 allocated during its processing (such as combine and loop). However,
2316 we will be leaving this constant on the chain, so we cannot tolerate
2317 freed memory. */
2318 r = rtx_alloc (CONST_DOUBLE);
2319 PUT_MODE (r, mode);
2320 memcpy ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u);
2322 /* If we aren't inside a function, don't put r on the
2323 const_double_chain. */
2324 if (current_function_decl != 0)
2326 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2327 const_double_chain = r;
2329 else
2330 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2332 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2333 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2334 is only through force_const_mem. */
2336 CONST_DOUBLE_MEM (r) = const0_rtx;
2338 return r;
2341 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2342 which must be a REAL_CST tree node. */
2345 immed_real_const (exp)
2346 tree exp;
2348 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2351 /* At the end of a function, forget the memory-constants
2352 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2353 Also clear out real_constant_chain and clear out all the chain-pointers. */
2355 void
2356 clear_const_double_mem ()
2358 rtx r, next;
2359 enum machine_mode mode;
2360 int i;
2362 for (r = const_double_chain; r; r = next)
2364 next = CONST_DOUBLE_CHAIN (r);
2365 CONST_DOUBLE_CHAIN (r) = 0;
2366 CONST_DOUBLE_MEM (r) = cc0_rtx;
2368 const_double_chain = 0;
2370 for (i = 0; i <= 2; i++)
2371 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
2372 mode = GET_MODE_WIDER_MODE (mode))
2374 r = const_tiny_rtx[i][(int) mode];
2375 CONST_DOUBLE_CHAIN (r) = 0;
2376 CONST_DOUBLE_MEM (r) = cc0_rtx;
2380 /* Given an expression EXP with a constant value,
2381 reduce it to the sum of an assembler symbol and an integer.
2382 Store them both in the structure *VALUE.
2383 Abort if EXP does not reduce. */
2385 struct addr_const
2387 rtx base;
2388 HOST_WIDE_INT offset;
2391 static void
2392 decode_addr_const (exp, value)
2393 tree exp;
2394 struct addr_const *value;
2396 tree target = TREE_OPERAND (exp, 0);
2397 int offset = 0;
2398 rtx x;
2400 while (1)
2402 if (TREE_CODE (target) == COMPONENT_REF
2403 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2406 offset += int_byte_position (TREE_OPERAND (target, 1));
2407 target = TREE_OPERAND (target, 0);
2409 else if (TREE_CODE (target) == ARRAY_REF
2410 || TREE_CODE (target) == ARRAY_RANGE_REF)
2412 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2413 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2414 target = TREE_OPERAND (target, 0);
2416 else
2417 break;
2420 switch (TREE_CODE (target))
2422 case VAR_DECL:
2423 case FUNCTION_DECL:
2424 x = DECL_RTL (target);
2425 break;
2427 case LABEL_DECL:
2428 x = gen_rtx_MEM (FUNCTION_MODE,
2429 gen_rtx_LABEL_REF (VOIDmode,
2430 label_rtx (TREE_OPERAND (exp, 0))));
2431 break;
2433 case REAL_CST:
2434 case STRING_CST:
2435 case COMPLEX_CST:
2436 case CONSTRUCTOR:
2437 case INTEGER_CST:
2438 x = TREE_CST_RTL (target);
2439 break;
2441 default:
2442 abort ();
2445 if (GET_CODE (x) != MEM)
2446 abort ();
2447 x = XEXP (x, 0);
2449 value->base = x;
2450 value->offset = offset;
2453 enum kind { RTX_DOUBLE, RTX_INT };
2454 struct rtx_const
2456 ENUM_BITFIELD(kind) kind : 16;
2457 ENUM_BITFIELD(machine_mode) mode : 16;
2458 union {
2459 union real_extract du;
2460 struct addr_const addr;
2461 struct {HOST_WIDE_INT high, low;} di;
2462 } un;
2465 /* Uniquize all constants that appear in memory.
2466 Each constant in memory thus far output is recorded
2467 in `const_hash_table' with a `struct constant_descriptor'
2468 that contains a polish representation of the value of
2469 the constant.
2471 We cannot store the trees in the hash table
2472 because the trees may be temporary. */
2474 struct constant_descriptor
2476 struct constant_descriptor *next;
2477 const char *label;
2478 rtx rtl;
2479 /* Make sure the data is reasonably aligned. */
2480 union
2482 unsigned char contents[1];
2483 #ifdef HAVE_LONG_DOUBLE
2484 long double d;
2485 #else
2486 double d;
2487 #endif
2488 } u;
2491 #define HASHBITS 30
2492 #define MAX_HASH_TABLE 1009
2493 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2495 #define STRHASH(x) ((hashval_t)((long)(x) >> 3))
2497 struct deferred_string
2499 const char *label;
2500 tree exp;
2501 int labelno;
2504 static htab_t const_str_htab;
2506 /* Mark a const_hash_table descriptor for GC. */
2508 static void
2509 mark_const_hash_entry (ptr)
2510 void *ptr;
2512 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2514 while (desc)
2516 ggc_mark_rtx (desc->rtl);
2517 desc = desc->next;
2521 /* Mark the hash-table element X (which is really a pointer to an
2522 struct deferred_string *). */
2524 static int
2525 mark_const_str_htab_1 (x, data)
2526 void **x;
2527 void *data ATTRIBUTE_UNUSED;
2529 ggc_mark_tree (((struct deferred_string *) *x)->exp);
2530 return 1;
2533 /* Mark a const_str_htab for GC. */
2535 static void
2536 mark_const_str_htab (htab)
2537 void *htab;
2539 htab_traverse (*((htab_t *) htab), mark_const_str_htab_1, NULL);
2542 /* Returns a hash code for X (which is a really a
2543 struct deferred_string *). */
2545 static hashval_t
2546 const_str_htab_hash (x)
2547 const void *x;
2549 return STRHASH (((const struct deferred_string *) x)->label);
2552 /* Returns non-zero if the value represented by X (which is really a
2553 struct deferred_string *) is the same as that given by Y
2554 (which is really a char *). */
2556 static int
2557 const_str_htab_eq (x, y)
2558 const void *x;
2559 const void *y;
2561 return (((const struct deferred_string *) x)->label == (const char *) y);
2564 /* Delete the hash table entry dfsp. */
2566 static void
2567 const_str_htab_del (dfsp)
2568 void *dfsp;
2570 free (dfsp);
2573 /* Compute a hash code for a constant expression. */
2575 static int
2576 const_hash (exp)
2577 tree exp;
2579 const char *p;
2580 int len, hi, i;
2581 enum tree_code code = TREE_CODE (exp);
2583 /* Either set P and LEN to the address and len of something to hash and
2584 exit the switch or return a value. */
2586 switch (code)
2588 case INTEGER_CST:
2589 p = (char *) &TREE_INT_CST (exp);
2590 len = sizeof TREE_INT_CST (exp);
2591 break;
2593 case REAL_CST:
2594 p = (char *) &TREE_REAL_CST (exp);
2595 len = sizeof TREE_REAL_CST (exp);
2596 break;
2598 case STRING_CST:
2599 p = TREE_STRING_POINTER (exp);
2600 len = TREE_STRING_LENGTH (exp);
2601 break;
2603 case COMPLEX_CST:
2604 return (const_hash (TREE_REALPART (exp)) * 5
2605 + const_hash (TREE_IMAGPART (exp)));
2607 case CONSTRUCTOR:
2608 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2610 char *tmp;
2612 len = int_size_in_bytes (TREE_TYPE (exp));
2613 tmp = (char *) alloca (len);
2614 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2615 p = tmp;
2616 break;
2618 else
2620 tree link;
2622 /* For record type, include the type in the hashing.
2623 We do not do so for array types
2624 because (1) the sizes of the elements are sufficient
2625 and (2) distinct array types can have the same constructor.
2626 Instead, we include the array size because the constructor could
2627 be shorter. */
2628 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2629 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2630 % MAX_HASH_TABLE;
2631 else
2632 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2633 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2635 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2636 if (TREE_VALUE (link))
2638 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2640 return hi;
2643 case ADDR_EXPR:
2645 struct addr_const value;
2647 decode_addr_const (exp, &value);
2648 if (GET_CODE (value.base) == SYMBOL_REF)
2650 /* Don't hash the address of the SYMBOL_REF;
2651 only use the offset and the symbol name. */
2652 hi = value.offset;
2653 p = XSTR (value.base, 0);
2654 for (i = 0; p[i] != 0; i++)
2655 hi = ((hi * 613) + (unsigned) (p[i]));
2657 else if (GET_CODE (value.base) == LABEL_REF)
2658 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2659 else
2660 abort();
2662 hi &= (1 << HASHBITS) - 1;
2663 hi %= MAX_HASH_TABLE;
2665 return hi;
2667 case PLUS_EXPR:
2668 case MINUS_EXPR:
2669 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2670 + const_hash (TREE_OPERAND (exp, 1)));
2672 case NOP_EXPR:
2673 case CONVERT_EXPR:
2674 case NON_LVALUE_EXPR:
2675 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2677 default:
2678 /* A language specific constant. Just hash the code. */
2679 return (int) code % MAX_HASH_TABLE;
2682 /* Compute hashing function */
2683 hi = len;
2684 for (i = 0; i < len; i++)
2685 hi = ((hi * 613) + (unsigned) (p[i]));
2687 hi &= (1 << HASHBITS) - 1;
2688 hi %= MAX_HASH_TABLE;
2689 return hi;
2692 /* Compare a constant expression EXP with a constant-descriptor DESC.
2693 Return 1 if DESC describes a constant with the same value as EXP. */
2695 static int
2696 compare_constant (exp, desc)
2697 tree exp;
2698 struct constant_descriptor *desc;
2700 return 0 != compare_constant_1 (exp, desc->u.contents);
2703 /* Compare constant expression EXP with a substring P of a constant descriptor.
2704 If they match, return a pointer to the end of the substring matched.
2705 If they do not match, return 0.
2707 Since descriptors are written in polish prefix notation,
2708 this function can be used recursively to test one operand of EXP
2709 against a subdescriptor, and if it succeeds it returns the
2710 address of the subdescriptor for the next operand. */
2712 static const unsigned char *
2713 compare_constant_1 (exp, p)
2714 tree exp;
2715 const unsigned char *p;
2717 const unsigned char *strp;
2718 int len;
2719 enum tree_code code = TREE_CODE (exp);
2721 if (code != (enum tree_code) *p++)
2722 return 0;
2724 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2725 switch, or return the result of the comparison. */
2727 switch (code)
2729 case INTEGER_CST:
2730 /* Integer constants are the same only if the same width of type. */
2731 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2732 return 0;
2734 strp = (unsigned char *) &TREE_INT_CST (exp);
2735 len = sizeof TREE_INT_CST (exp);
2736 break;
2738 case REAL_CST:
2739 /* Real constants are the same only if the same width of type. */
2740 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2741 return 0;
2743 strp = (unsigned char *) &TREE_REAL_CST (exp);
2744 len = sizeof TREE_REAL_CST (exp);
2745 break;
2747 case STRING_CST:
2748 if (flag_writable_strings)
2749 return 0;
2751 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2752 return 0;
2754 strp = (const unsigned char *)TREE_STRING_POINTER (exp);
2755 len = TREE_STRING_LENGTH (exp);
2756 if (memcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2757 sizeof TREE_STRING_LENGTH (exp)))
2758 return 0;
2760 p += sizeof TREE_STRING_LENGTH (exp);
2761 break;
2763 case COMPLEX_CST:
2764 p = compare_constant_1 (TREE_REALPART (exp), p);
2765 if (p == 0)
2766 return 0;
2768 return compare_constant_1 (TREE_IMAGPART (exp), p);
2770 case CONSTRUCTOR:
2771 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2773 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2774 unsigned char *tmp = (unsigned char *) alloca (len);
2776 get_set_constructor_bytes (exp, tmp, len);
2777 strp = (unsigned char *) tmp;
2778 if (memcmp ((char *) &xlen, p, sizeof xlen))
2779 return 0;
2781 p += sizeof xlen;
2782 break;
2784 else
2786 tree link;
2787 int length = list_length (CONSTRUCTOR_ELTS (exp));
2788 tree type;
2789 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2790 int have_purpose = 0;
2792 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2793 if (TREE_PURPOSE (link))
2794 have_purpose = 1;
2796 if (memcmp ((char *) &length, p, sizeof length))
2797 return 0;
2799 p += sizeof length;
2801 /* For record constructors, insist that the types match.
2802 For arrays, just verify both constructors are for arrays.
2803 Then insist that either both or none have any TREE_PURPOSE
2804 values. */
2805 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2806 type = TREE_TYPE (exp);
2807 else
2808 type = 0;
2810 if (memcmp ((char *) &type, p, sizeof type))
2811 return 0;
2813 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2815 if (memcmp ((char *) &mode, p, sizeof mode))
2816 return 0;
2818 p += sizeof mode;
2821 p += sizeof type;
2823 if (memcmp ((char *) &have_purpose, p, sizeof have_purpose))
2824 return 0;
2826 p += sizeof have_purpose;
2828 /* For arrays, insist that the size in bytes match. */
2829 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2831 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2833 if (memcmp ((char *) &size, p, sizeof size))
2834 return 0;
2836 p += sizeof size;
2839 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2841 if (TREE_VALUE (link))
2843 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2844 return 0;
2846 else
2848 tree zero = 0;
2850 if (memcmp ((char *) &zero, p, sizeof zero))
2851 return 0;
2853 p += sizeof zero;
2856 if (TREE_PURPOSE (link)
2857 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2859 if (memcmp ((char *) &TREE_PURPOSE (link), p,
2860 sizeof TREE_PURPOSE (link)))
2861 return 0;
2863 p += sizeof TREE_PURPOSE (link);
2865 else if (TREE_PURPOSE (link))
2867 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2868 return 0;
2870 else if (have_purpose)
2872 int zero = 0;
2874 if (memcmp ((char *) &zero, p, sizeof zero))
2875 return 0;
2877 p += sizeof zero;
2881 return p;
2884 case ADDR_EXPR:
2886 struct addr_const value;
2888 decode_addr_const (exp, &value);
2889 strp = (unsigned char *) &value.offset;
2890 len = sizeof value.offset;
2891 /* Compare the offset. */
2892 while (--len >= 0)
2893 if (*p++ != *strp++)
2894 return 0;
2896 /* Compare symbol name. */
2897 strp = (const unsigned char *) XSTR (value.base, 0);
2898 len = strlen ((const char *) strp) + 1;
2900 break;
2902 case PLUS_EXPR:
2903 case MINUS_EXPR:
2904 case RANGE_EXPR:
2905 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2906 if (p == 0)
2907 return 0;
2909 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2911 case NOP_EXPR:
2912 case CONVERT_EXPR:
2913 case NON_LVALUE_EXPR:
2914 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2916 default:
2917 if (lang_expand_constant)
2919 exp = (*lang_expand_constant) (exp);
2920 return compare_constant_1 (exp, p);
2922 return 0;
2925 /* Compare constant contents. */
2926 while (--len >= 0)
2927 if (*p++ != *strp++)
2928 return 0;
2930 return p;
2933 /* Construct a constant descriptor for the expression EXP.
2934 It is up to the caller to enter the descriptor in the hash table. */
2936 static struct constant_descriptor *
2937 record_constant (exp)
2938 tree exp;
2940 struct constant_descriptor *next = 0;
2941 char *label = 0;
2942 rtx rtl = 0;
2943 int pad;
2945 /* Make a struct constant_descriptor. The first three pointers will
2946 be filled in later. Here we just leave space for them. */
2948 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2949 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2950 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2952 /* Align the descriptor for the data payload. */
2953 pad = (offsetof (struct constant_descriptor, u)
2954 - offsetof(struct constant_descriptor, rtl)
2955 - sizeof(next->rtl));
2956 if (pad > 0)
2957 obstack_blank (&permanent_obstack, pad);
2959 record_constant_1 (exp);
2960 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2963 /* Add a description of constant expression EXP
2964 to the object growing in `permanent_obstack'.
2965 No need to return its address; the caller will get that
2966 from the obstack when the object is complete. */
2968 static void
2969 record_constant_1 (exp)
2970 tree exp;
2972 const unsigned char *strp;
2973 int len;
2974 enum tree_code code = TREE_CODE (exp);
2976 obstack_1grow (&permanent_obstack, (unsigned int) code);
2978 switch (code)
2980 case INTEGER_CST:
2981 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2982 strp = (unsigned char *) &TREE_INT_CST (exp);
2983 len = sizeof TREE_INT_CST (exp);
2984 break;
2986 case REAL_CST:
2987 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2988 strp = (unsigned char *) &TREE_REAL_CST (exp);
2989 len = sizeof TREE_REAL_CST (exp);
2990 break;
2992 case STRING_CST:
2993 if (flag_writable_strings)
2994 return;
2996 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2997 strp = (const unsigned char *) TREE_STRING_POINTER (exp);
2998 len = TREE_STRING_LENGTH (exp);
2999 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
3000 sizeof TREE_STRING_LENGTH (exp));
3001 break;
3003 case COMPLEX_CST:
3004 record_constant_1 (TREE_REALPART (exp));
3005 record_constant_1 (TREE_IMAGPART (exp));
3006 return;
3008 case CONSTRUCTOR:
3009 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3011 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
3012 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
3013 obstack_blank (&permanent_obstack, nbytes);
3014 get_set_constructor_bytes
3015 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
3016 nbytes);
3017 return;
3019 else
3021 tree link;
3022 int length = list_length (CONSTRUCTOR_ELTS (exp));
3023 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
3024 tree type;
3025 int have_purpose = 0;
3027 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3028 if (TREE_PURPOSE (link))
3029 have_purpose = 1;
3031 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
3033 /* For record constructors, insist that the types match.
3034 For arrays, just verify both constructors are for arrays
3035 of the same mode. Then insist that either both or none
3036 have any TREE_PURPOSE values. */
3037 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3038 type = TREE_TYPE (exp);
3039 else
3040 type = 0;
3042 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
3043 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3044 obstack_grow (&permanent_obstack, &mode, sizeof mode);
3046 obstack_grow (&permanent_obstack, (char *) &have_purpose,
3047 sizeof have_purpose);
3049 /* For arrays, insist that the size in bytes match. */
3050 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3052 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
3053 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
3056 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3058 if (TREE_VALUE (link))
3059 record_constant_1 (TREE_VALUE (link));
3060 else
3062 tree zero = 0;
3064 obstack_grow (&permanent_obstack,
3065 (char *) &zero, sizeof zero);
3068 if (TREE_PURPOSE (link)
3069 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
3070 obstack_grow (&permanent_obstack,
3071 (char *) &TREE_PURPOSE (link),
3072 sizeof TREE_PURPOSE (link));
3073 else if (TREE_PURPOSE (link))
3074 record_constant_1 (TREE_PURPOSE (link));
3075 else if (have_purpose)
3077 int zero = 0;
3079 obstack_grow (&permanent_obstack,
3080 (char *) &zero, sizeof zero);
3084 return;
3086 case ADDR_EXPR:
3088 struct addr_const value;
3090 decode_addr_const (exp, &value);
3091 /* Record the offset. */
3092 obstack_grow (&permanent_obstack,
3093 (char *) &value.offset, sizeof value.offset);
3095 switch (GET_CODE (value.base))
3097 case SYMBOL_REF:
3098 /* Record the symbol name. */
3099 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
3100 strlen (XSTR (value.base, 0)) + 1);
3101 break;
3102 case LABEL_REF:
3103 /* Record the address of the CODE_LABEL. It may not have
3104 been emitted yet, so it's UID may be zero. But pointer
3105 identity is good enough. */
3106 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
3107 sizeof (rtx));
3108 break;
3109 default:
3110 abort ();
3113 return;
3115 case PLUS_EXPR:
3116 case MINUS_EXPR:
3117 case RANGE_EXPR:
3118 record_constant_1 (TREE_OPERAND (exp, 0));
3119 record_constant_1 (TREE_OPERAND (exp, 1));
3120 return;
3122 case NOP_EXPR:
3123 case CONVERT_EXPR:
3124 case NON_LVALUE_EXPR:
3125 record_constant_1 (TREE_OPERAND (exp, 0));
3126 return;
3128 default:
3129 if (lang_expand_constant)
3131 exp = (*lang_expand_constant) (exp);
3132 record_constant_1 (exp);
3134 return;
3137 /* Record constant contents. */
3138 obstack_grow (&permanent_obstack, strp, len);
3141 /* Record a list of constant expressions that were passed to
3142 output_constant_def but that could not be output right away. */
3144 struct deferred_constant
3146 struct deferred_constant *next;
3147 tree exp;
3148 int reloc;
3149 int labelno;
3152 static struct deferred_constant *deferred_constants;
3154 /* Another list of constants which should be output after the
3155 function. */
3156 static struct deferred_constant *after_function_constants;
3158 /* Nonzero means defer output of addressed subconstants
3159 (i.e., those for which output_constant_def is called.) */
3160 static int defer_addressed_constants_flag;
3162 /* Start deferring output of subconstants. */
3164 void
3165 defer_addressed_constants ()
3167 defer_addressed_constants_flag++;
3170 /* Stop deferring output of subconstants,
3171 and output now all those that have been deferred. */
3173 void
3174 output_deferred_addressed_constants ()
3176 struct deferred_constant *p, *next;
3178 defer_addressed_constants_flag--;
3180 if (defer_addressed_constants_flag > 0)
3181 return;
3183 for (p = deferred_constants; p; p = next)
3185 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3186 next = p->next;
3187 free (p);
3190 deferred_constants = 0;
3193 /* Output any constants which should appear after a function. */
3195 static void
3196 output_after_function_constants ()
3198 struct deferred_constant *p, *next;
3200 for (p = after_function_constants; p; p = next)
3202 output_constant_def_contents (p->exp, p->reloc, p->labelno);
3203 next = p->next;
3204 free (p);
3207 after_function_constants = 0;
3210 /* Make a copy of the whole tree structure for a constant.
3211 This handles the same types of nodes that compare_constant
3212 and record_constant handle. */
3214 static tree
3215 copy_constant (exp)
3216 tree exp;
3218 switch (TREE_CODE (exp))
3220 case ADDR_EXPR:
3221 /* For ADDR_EXPR, we do not want to copy the decl whose address
3222 is requested. We do want to copy constants though. */
3223 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
3224 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3225 copy_constant (TREE_OPERAND (exp, 0)));
3226 else
3227 return copy_node (exp);
3229 case INTEGER_CST:
3230 case REAL_CST:
3231 case STRING_CST:
3232 return copy_node (exp);
3234 case COMPLEX_CST:
3235 return build_complex (TREE_TYPE (exp),
3236 copy_constant (TREE_REALPART (exp)),
3237 copy_constant (TREE_IMAGPART (exp)));
3239 case PLUS_EXPR:
3240 case MINUS_EXPR:
3241 return build (TREE_CODE (exp), TREE_TYPE (exp),
3242 copy_constant (TREE_OPERAND (exp, 0)),
3243 copy_constant (TREE_OPERAND (exp, 1)));
3245 case NOP_EXPR:
3246 case CONVERT_EXPR:
3247 case NON_LVALUE_EXPR:
3248 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3249 copy_constant (TREE_OPERAND (exp, 0)));
3251 case CONSTRUCTOR:
3253 tree copy = copy_node (exp);
3254 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3255 tree tail;
3257 CONSTRUCTOR_ELTS (copy) = list;
3258 for (tail = list; tail; tail = TREE_CHAIN (tail))
3259 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3260 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3261 for (tail = list; tail; tail = TREE_CHAIN (tail))
3262 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3264 return copy;
3267 default:
3268 abort ();
3272 /* Return an rtx representing a reference to constant data in memory
3273 for the constant expression EXP.
3275 If assembler code for such a constant has already been output,
3276 return an rtx to refer to it.
3277 Otherwise, output such a constant in memory (or defer it for later)
3278 and generate an rtx for it.
3280 If DEFER is non-zero, the output of string constants can be deferred
3281 and output only if referenced in the function after all optimizations.
3283 The TREE_CST_RTL of EXP is set up to point to that rtx.
3284 The const_hash_table records which constants already have label strings. */
3287 output_constant_def (exp, defer)
3288 tree exp;
3289 int defer;
3291 int hash;
3292 struct constant_descriptor *desc;
3293 struct deferred_string **defstr;
3294 char label[256];
3295 int reloc;
3296 int found = 1;
3297 int after_function = 0;
3298 int labelno = -1;
3300 if (TREE_CST_RTL (exp))
3301 return TREE_CST_RTL (exp);
3303 /* Make sure any other constants whose addresses appear in EXP
3304 are assigned label numbers. */
3306 reloc = output_addressed_constants (exp);
3308 /* Compute hash code of EXP. Search the descriptors for that hash code
3309 to see if any of them describes EXP. If yes, the descriptor records
3310 the label number already assigned. */
3312 hash = const_hash (exp) % MAX_HASH_TABLE;
3314 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3315 if (compare_constant (exp, desc))
3316 break;
3318 if (desc == 0)
3320 /* No constant equal to EXP is known to have been output.
3321 Make a constant descriptor to enter EXP in the hash table.
3322 Assign the label number and record it in the descriptor for
3323 future calls to this function to find. */
3325 /* Create a string containing the label name, in LABEL. */
3326 labelno = const_labelno++;
3327 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3329 desc = record_constant (exp);
3330 desc->next = const_hash_table[hash];
3331 desc->label = ggc_strdup (label);
3332 const_hash_table[hash] = desc;
3334 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3335 desc->rtl
3336 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3337 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3339 set_mem_attributes (desc->rtl, exp, 1);
3341 found = 0;
3344 TREE_CST_RTL (exp) = desc->rtl;
3346 /* Optionally set flags or add text to the name to record information
3347 such as that it is a function name. If the name is changed, the macro
3348 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3349 #ifdef ENCODE_SECTION_INFO
3350 /* A previously-processed constant would already have section info
3351 encoded in it. */
3352 if (! found)
3354 ENCODE_SECTION_INFO (exp);
3355 desc->rtl = TREE_CST_RTL (exp);
3356 desc->label = XSTR (XEXP (desc->rtl, 0), 0);
3358 #endif
3360 #ifdef CONSTANT_AFTER_FUNCTION_P
3361 if (current_function_decl != 0
3362 && CONSTANT_AFTER_FUNCTION_P (exp))
3363 after_function = 1;
3364 #endif
3366 if (found
3367 && STRING_POOL_ADDRESS_P (XEXP (desc->rtl, 0))
3368 && (!defer || defer_addressed_constants_flag || after_function))
3370 defstr = (struct deferred_string **)
3371 htab_find_slot_with_hash (const_str_htab, desc->label,
3372 STRHASH (desc->label), NO_INSERT);
3373 if (defstr)
3375 /* If the string is currently deferred but we need to output it now,
3376 remove it from deferred string hash table. */
3377 found = 0;
3378 labelno = (*defstr)->labelno;
3379 STRING_POOL_ADDRESS_P (XEXP (desc->rtl, 0)) = 0;
3380 htab_clear_slot (const_str_htab, (void **) defstr);
3384 /* If this is the first time we've seen this particular constant,
3385 output it (or defer its output for later). */
3386 if (! found)
3388 if (defer_addressed_constants_flag || after_function)
3390 struct deferred_constant *p;
3391 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3393 p->exp = copy_constant (exp);
3394 p->reloc = reloc;
3395 p->labelno = labelno;
3396 if (after_function)
3398 p->next = after_function_constants;
3399 after_function_constants = p;
3401 else
3403 p->next = deferred_constants;
3404 deferred_constants = p;
3407 else
3409 /* Do no output if -fsyntax-only. */
3410 if (! flag_syntax_only)
3412 if (TREE_CODE (exp) != STRING_CST
3413 || !defer
3414 || flag_writable_strings
3415 || (defstr = (struct deferred_string **)
3416 htab_find_slot_with_hash (const_str_htab,
3417 desc->label,
3418 STRHASH (desc->label),
3419 INSERT)) == NULL)
3420 output_constant_def_contents (exp, reloc, labelno);
3421 else
3423 struct deferred_string *p;
3425 p = (struct deferred_string *)
3426 xmalloc (sizeof (struct deferred_string));
3428 p->exp = copy_constant (exp);
3429 p->label = desc->label;
3430 p->labelno = labelno;
3431 *defstr = p;
3432 STRING_POOL_ADDRESS_P (XEXP (desc->rtl, 0)) = 1;
3438 return TREE_CST_RTL (exp);
3441 /* Now output assembler code to define the label for EXP,
3442 and follow it with the data of EXP. */
3444 static void
3445 output_constant_def_contents (exp, reloc, labelno)
3446 tree exp;
3447 int reloc;
3448 int labelno;
3450 int align;
3452 /* Align the location counter as required by EXP's data type. */
3453 align = TYPE_ALIGN (TREE_TYPE (exp));
3454 #ifdef CONSTANT_ALIGNMENT
3455 align = CONSTANT_ALIGNMENT (exp, align);
3456 #endif
3458 if (IN_NAMED_SECTION (exp))
3459 named_section (exp, NULL, reloc);
3460 else
3462 /* First switch to text section, except for writable strings. */
3463 #ifdef SELECT_SECTION
3464 SELECT_SECTION (exp, reloc, align);
3465 #else
3466 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3467 || (flag_pic && reloc))
3468 data_section ();
3469 else
3470 readonly_data_section ();
3471 #endif
3474 if (align > BITS_PER_UNIT)
3476 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3479 /* Output the label itself. */
3480 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3482 /* Output the value of EXP. */
3483 output_constant (exp,
3484 (TREE_CODE (exp) == STRING_CST
3485 ? MAX (TREE_STRING_LENGTH (exp),
3486 int_size_in_bytes (TREE_TYPE (exp)))
3487 : int_size_in_bytes (TREE_TYPE (exp))),
3488 align);
3492 /* Structure to represent sufficient information about a constant so that
3493 it can be output when the constant pool is output, so that function
3494 integration can be done, and to simplify handling on machines that reference
3495 constant pool as base+displacement. */
3497 struct pool_constant
3499 struct constant_descriptor *desc;
3500 struct pool_constant *next, *next_sym;
3501 const char *label;
3502 rtx constant;
3503 enum machine_mode mode;
3504 int labelno;
3505 int align;
3506 int offset;
3507 int mark;
3510 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3511 The argument is XSTR (... , 0) */
3513 #define SYMHASH(LABEL) \
3514 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3516 /* Initialize constant pool hashing for a new function. */
3518 void
3519 init_varasm_status (f)
3520 struct function *f;
3522 struct varasm_status *p;
3523 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3524 f->varasm = p;
3525 p->x_const_rtx_hash_table
3526 = ((struct constant_descriptor **)
3527 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct constant_descriptor *)));
3528 p->x_const_rtx_sym_hash_table
3529 = ((struct pool_constant **)
3530 xcalloc (MAX_RTX_HASH_TABLE, sizeof (struct pool_constant *)));
3532 p->x_first_pool = p->x_last_pool = 0;
3533 p->x_pool_offset = 0;
3534 p->x_const_double_chain = 0;
3537 /* Nested functions diddle with our const_double_chain via
3538 clear_const_double_mem and const_tiny_rtx. Remove these
3539 entries from our const_double_chain. */
3541 void
3542 restore_varasm_status (f)
3543 struct function *f;
3545 rtx *p = &f->varasm->x_const_double_chain;
3547 while (*p)
3548 if (CONST_DOUBLE_MEM (*p) == cc0_rtx)
3549 *p = CONST_DOUBLE_CHAIN (*p);
3550 else
3551 p = &CONST_DOUBLE_CHAIN (*p);
3554 /* Mark PC for GC. */
3556 static void
3557 mark_pool_constant (pc)
3558 struct pool_constant *pc;
3560 while (pc)
3562 ggc_mark (pc);
3563 ggc_mark_rtx (pc->constant);
3564 pc = pc->next;
3568 /* Mark P for GC. */
3570 void
3571 mark_varasm_status (p)
3572 struct varasm_status *p;
3574 if (p == NULL)
3575 return;
3577 mark_pool_constant (p->x_first_pool);
3578 ggc_mark_rtx (p->x_const_double_chain);
3581 /* Clear out all parts of the state in F that can safely be discarded
3582 after the function has been compiled, to let garbage collection
3583 reclaim the memory. */
3585 void
3586 free_varasm_status (f)
3587 struct function *f;
3589 struct varasm_status *p;
3590 int i;
3592 p = f->varasm;
3594 /* Clear out the hash tables. */
3595 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3597 struct constant_descriptor* cd;
3599 cd = p->x_const_rtx_hash_table[i];
3600 while (cd) {
3601 struct constant_descriptor* next = cd->next;
3602 free (cd);
3603 cd = next;
3607 free (p->x_const_rtx_hash_table);
3608 free (p->x_const_rtx_sym_hash_table);
3609 free (p);
3610 f->varasm = NULL;
3614 /* Express an rtx for a constant integer (perhaps symbolic)
3615 as the sum of a symbol or label plus an explicit integer.
3616 They are stored into VALUE. */
3618 static void
3619 decode_rtx_const (mode, x, value)
3620 enum machine_mode mode;
3621 rtx x;
3622 struct rtx_const *value;
3624 /* Clear the whole structure, including any gaps. */
3625 memset (value, 0, sizeof (struct rtx_const));
3627 value->kind = RTX_INT; /* Most usual kind. */
3628 value->mode = mode;
3630 switch (GET_CODE (x))
3632 case CONST_DOUBLE:
3633 value->kind = RTX_DOUBLE;
3634 if (GET_MODE (x) != VOIDmode)
3636 value->mode = GET_MODE (x);
3637 memcpy ((char *) &value->un.du,
3638 (char *) &CONST_DOUBLE_LOW (x), sizeof value->un.du);
3640 else
3642 value->un.di.low = CONST_DOUBLE_LOW (x);
3643 value->un.di.high = CONST_DOUBLE_HIGH (x);
3645 break;
3647 case CONST_INT:
3648 value->un.addr.offset = INTVAL (x);
3649 break;
3651 case SYMBOL_REF:
3652 case LABEL_REF:
3653 case PC:
3654 value->un.addr.base = x;
3655 break;
3657 case CONST:
3658 x = XEXP (x, 0);
3659 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3661 value->un.addr.base = XEXP (x, 0);
3662 value->un.addr.offset = INTVAL (XEXP (x, 1));
3664 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
3666 value->un.addr.base = XEXP (x, 0);
3667 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3669 else
3671 value->un.addr.base = x;
3672 value->un.addr.offset = 0;
3674 break;
3676 default:
3677 abort ();
3680 if (value->kind == RTX_INT && value->un.addr.base != 0)
3681 switch (GET_CODE (value->un.addr.base))
3683 case SYMBOL_REF:
3684 /* Use the string's address, not the SYMBOL_REF's address,
3685 for the sake of addresses of library routines. */
3686 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3687 break;
3689 case LABEL_REF:
3690 /* For a LABEL_REF, compare labels. */
3691 value->un.addr.base = XEXP (value->un.addr.base, 0);
3693 default:
3694 break;
3698 /* Given a MINUS expression, simplify it if both sides
3699 include the same symbol. */
3702 simplify_subtraction (x)
3703 rtx x;
3705 struct rtx_const val0, val1;
3707 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3708 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3710 if (val0.un.addr.base == val1.un.addr.base)
3711 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3712 return x;
3715 /* Compute a hash code for a constant RTL expression. */
3717 static int
3718 const_hash_rtx (mode, x)
3719 enum machine_mode mode;
3720 rtx x;
3722 int hi;
3723 size_t i;
3725 struct rtx_const value;
3726 decode_rtx_const (mode, x, &value);
3728 /* Compute hashing function */
3729 hi = 0;
3730 for (i = 0; i < sizeof value / sizeof (int); i++)
3731 hi += ((int *) &value)[i];
3733 hi &= (1 << HASHBITS) - 1;
3734 hi %= MAX_RTX_HASH_TABLE;
3735 return hi;
3738 /* Compare a constant rtl object X with a constant-descriptor DESC.
3739 Return 1 if DESC describes a constant with the same value as X. */
3741 static int
3742 compare_constant_rtx (mode, x, desc)
3743 enum machine_mode mode;
3744 rtx x;
3745 struct constant_descriptor *desc;
3747 int *p = (int *) desc->u.contents;
3748 int *strp;
3749 int len;
3750 struct rtx_const value;
3752 decode_rtx_const (mode, x, &value);
3753 strp = (int *) &value;
3754 len = sizeof value / sizeof (int);
3756 /* Compare constant contents. */
3757 while (--len >= 0)
3758 if (*p++ != *strp++)
3759 return 0;
3761 return 1;
3764 /* Construct a constant descriptor for the rtl-expression X.
3765 It is up to the caller to enter the descriptor in the hash table. */
3767 static struct constant_descriptor *
3768 record_constant_rtx (mode, x)
3769 enum machine_mode mode;
3770 rtx x;
3772 struct constant_descriptor *ptr;
3774 ptr = ((struct constant_descriptor *)
3775 xcalloc (1, (offsetof (struct constant_descriptor, u)
3776 + sizeof (struct rtx_const))));
3777 decode_rtx_const (mode, x, (struct rtx_const *) ptr->u.contents);
3779 return ptr;
3782 /* Given a constant rtx X, make (or find) a memory constant for its value
3783 and return a MEM rtx to refer to it in memory. */
3786 force_const_mem (mode, x)
3787 enum machine_mode mode;
3788 rtx x;
3790 int hash;
3791 struct constant_descriptor *desc;
3792 char label[256];
3793 const char *found = 0;
3794 rtx def;
3796 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3797 (this will always be true for floating CONST_DOUBLEs that have been
3798 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3799 use the previous copy. Otherwise, make a new one. Note that in
3800 the unlikely event that this same CONST_DOUBLE is used in two different
3801 modes in an alternating fashion, we will allocate a lot of different
3802 memory locations, but this should be extremely rare. */
3804 if (GET_CODE (x) == CONST_DOUBLE
3805 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3806 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3807 return CONST_DOUBLE_MEM (x);
3809 /* Compute hash code of X. Search the descriptors for that hash code
3810 to see if any of them describes X. If yes, the descriptor records
3811 the label number already assigned. */
3813 hash = const_hash_rtx (mode, x);
3815 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3816 if (compare_constant_rtx (mode, x, desc))
3818 found = desc->label;
3819 break;
3822 if (found == 0)
3824 struct pool_constant *pool;
3825 int align;
3827 /* No constant equal to X is known to have been output.
3828 Make a constant descriptor to enter X in the hash table.
3829 Assign the label number and record it in the descriptor for
3830 future calls to this function to find. */
3832 desc = record_constant_rtx (mode, x);
3833 desc->next = const_rtx_hash_table[hash];
3834 const_rtx_hash_table[hash] = desc;
3836 /* Align the location counter as required by EXP's data type. */
3837 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
3838 #ifdef CONSTANT_ALIGNMENT
3839 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3840 align);
3841 #endif
3843 pool_offset += (align / BITS_PER_UNIT) - 1;
3844 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
3846 if (GET_CODE (x) == LABEL_REF)
3847 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
3849 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3851 pool = (struct pool_constant *) ggc_alloc (sizeof (struct pool_constant));
3852 pool->desc = desc;
3853 pool->constant = x;
3854 pool->mode = mode;
3855 pool->labelno = const_labelno;
3856 pool->align = align;
3857 pool->offset = pool_offset;
3858 pool->mark = 1;
3859 pool->next = 0;
3861 if (last_pool == 0)
3862 first_pool = pool;
3863 else
3864 last_pool->next = pool;
3866 last_pool = pool;
3867 pool_offset += GET_MODE_SIZE (mode);
3869 /* Create a string containing the label name, in LABEL. */
3870 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3872 ++const_labelno;
3874 desc->label = found = ggc_strdup (label);
3876 /* Add label to symbol hash table. */
3877 hash = SYMHASH (found);
3878 pool->label = found;
3879 pool->next_sym = const_rtx_sym_hash_table[hash];
3880 const_rtx_sym_hash_table[hash] = pool;
3883 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3885 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3886 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3887 RTX_UNCHANGING_P (def) = 1;
3889 /* Mark the symbol_ref as belonging to this constants pool. */
3890 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3891 current_function_uses_const_pool = 1;
3893 if (GET_CODE (x) == CONST_DOUBLE)
3895 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3897 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3898 const_double_chain = x;
3900 CONST_DOUBLE_MEM (x) = def;
3903 return def;
3906 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3907 the corresponding pool_constant structure. */
3909 static struct pool_constant *
3910 find_pool_constant (f, addr)
3911 struct function *f;
3912 rtx addr;
3914 struct pool_constant *pool;
3915 const char *label = XSTR (addr, 0);
3917 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3918 pool = pool->next_sym)
3919 if (pool->label == label)
3920 return pool;
3922 abort ();
3925 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3928 get_pool_constant (addr)
3929 rtx addr;
3931 return (find_pool_constant (cfun, addr))->constant;
3934 /* Likewise, but for the constant pool of a specific function. */
3937 get_pool_constant_for_function (f, addr)
3938 struct function *f;
3939 rtx addr;
3941 return (find_pool_constant (f, addr))->constant;
3944 /* Similar, return the mode. */
3946 enum machine_mode
3947 get_pool_mode (addr)
3948 rtx addr;
3950 return (find_pool_constant (cfun, addr))->mode;
3953 enum machine_mode
3954 get_pool_mode_for_function (f, addr)
3955 struct function *f;
3956 rtx addr;
3958 return (find_pool_constant (f, addr))->mode;
3961 /* Similar, return the offset in the constant pool. */
3964 get_pool_offset (addr)
3965 rtx addr;
3967 return (find_pool_constant (cfun, addr))->offset;
3970 /* Return the size of the constant pool. */
3973 get_pool_size ()
3975 return pool_offset;
3978 /* Write all the constants in the constant pool. */
3980 void
3981 output_constant_pool (fnname, fndecl)
3982 const char *fnname ATTRIBUTE_UNUSED;
3983 tree fndecl ATTRIBUTE_UNUSED;
3985 struct pool_constant *pool;
3986 rtx x;
3987 union real_extract u;
3989 /* It is possible for gcc to call force_const_mem and then to later
3990 discard the instructions which refer to the constant. In such a
3991 case we do not need to output the constant. */
3992 mark_constant_pool ();
3994 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3995 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3996 #endif
3998 for (pool = first_pool; pool; pool = pool->next)
4000 rtx tmp;
4002 x = pool->constant;
4004 if (! pool->mark)
4005 continue;
4007 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4008 whose CODE_LABEL has been deleted. This can occur if a jump table
4009 is eliminated by optimization. If so, write a constant of zero
4010 instead. Note that this can also happen by turning the
4011 CODE_LABEL into a NOTE. */
4012 /* ??? This seems completely and utterly wrong. Certainly it's
4013 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4014 functioning even with INSN_DELETED_P and friends. */
4016 tmp = x;
4017 switch (GET_CODE (x))
4019 case CONST:
4020 if (GET_CODE (XEXP (x, 0)) != PLUS
4021 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
4022 break;
4023 tmp = XEXP (XEXP (x, 0), 0);
4024 /* FALLTHRU */
4026 case LABEL_REF:
4027 tmp = XEXP (x, 0);
4028 if (INSN_DELETED_P (tmp)
4029 || (GET_CODE (tmp) == NOTE
4030 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
4032 abort ();
4033 x = const0_rtx;
4035 break;
4037 default:
4038 break;
4041 /* First switch to correct section. */
4042 #ifdef SELECT_RTX_SECTION
4043 SELECT_RTX_SECTION (pool->mode, x, pool->align);
4044 #else
4045 readonly_data_section ();
4046 #endif
4048 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4049 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
4050 pool->align, pool->labelno, done);
4051 #endif
4053 assemble_align (pool->align);
4055 /* Output the label. */
4056 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
4058 /* Output the value of the constant itself. */
4059 switch (GET_MODE_CLASS (pool->mode))
4061 case MODE_FLOAT:
4062 if (GET_CODE (x) != CONST_DOUBLE)
4063 abort ();
4065 memcpy ((char *) &u, (char *) &CONST_DOUBLE_LOW (x), sizeof u);
4066 assemble_real (u.d, pool->mode, pool->align);
4067 break;
4069 case MODE_INT:
4070 case MODE_PARTIAL_INT:
4071 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
4072 break;
4074 default:
4075 abort ();
4078 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4079 done: ;
4080 #endif
4083 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4084 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
4085 #endif
4087 /* Done with this pool. */
4088 first_pool = last_pool = 0;
4091 /* Look through the instructions for this function, and mark all the
4092 entries in the constant pool which are actually being used.
4093 Emit used deferred strings. */
4095 static void
4096 mark_constant_pool ()
4098 rtx insn;
4099 struct pool_constant *pool;
4101 if (first_pool == 0 && htab_elements (const_str_htab) == 0)
4102 return;
4104 for (pool = first_pool; pool; pool = pool->next)
4105 pool->mark = 0;
4107 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4108 if (INSN_P (insn))
4109 mark_constants (PATTERN (insn));
4111 for (insn = current_function_epilogue_delay_list;
4112 insn;
4113 insn = XEXP (insn, 1))
4114 if (INSN_P (insn))
4115 mark_constants (PATTERN (insn));
4118 /* Look through appropriate parts of X, marking all entries in the
4119 constant pool which are actually being used. Entries that are only
4120 referenced by other constants are also marked as used. Emit
4121 deferred strings that are used. */
4123 static void
4124 mark_constants (x)
4125 rtx x;
4127 int i;
4128 const char *format_ptr;
4130 if (x == 0)
4131 return;
4133 if (GET_CODE (x) == SYMBOL_REF)
4135 mark_constant (&x, NULL);
4136 return;
4138 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
4139 a MEM, but does not constitute a use of that MEM. */
4140 else if (GET_CODE (x) == CONST_DOUBLE)
4141 return;
4143 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4144 insns, not any notes that may be attached. We don't want to mark
4145 a constant just because it happens to appear in a REG_EQUIV note. */
4146 if (INSN_P (x))
4148 mark_constants (PATTERN (x));
4149 return;
4152 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
4154 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
4156 switch (*format_ptr++)
4158 case 'e':
4159 mark_constants (XEXP (x, i));
4160 break;
4162 case 'E':
4163 if (XVEC (x, i) != 0)
4165 int j;
4167 for (j = 0; j < XVECLEN (x, i); j++)
4168 mark_constants (XVECEXP (x, i, j));
4170 break;
4172 case 'S':
4173 case 's':
4174 case '0':
4175 case 'i':
4176 case 'w':
4177 case 'n':
4178 case 'u':
4179 break;
4181 default:
4182 abort ();
4187 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4188 to as used. Emit referenced deferred strings. This function can
4189 be used with for_each_rtx () to mark all SYMBOL_REFs in an rtx. */
4191 static int
4192 mark_constant (current_rtx, data)
4193 rtx *current_rtx;
4194 void *data ATTRIBUTE_UNUSED;
4196 rtx x = *current_rtx;
4198 if (x == NULL_RTX)
4199 return 0;
4200 else if (GET_CODE(x) == CONST_DOUBLE)
4201 /* Never search inside a CONST_DOUBLE because CONST_DOUBLE_MEM may
4202 be a MEM but does not constitute a use of that MEM. */
4203 return -1;
4204 else if (GET_CODE (x) == SYMBOL_REF)
4206 if (CONSTANT_POOL_ADDRESS_P (x))
4208 struct pool_constant *pool = find_pool_constant (cfun, x);
4209 if (pool->mark == 0) {
4210 pool->mark = 1;
4211 for_each_rtx (&(pool->constant), &mark_constant, NULL);
4213 else
4214 return -1;
4216 else if (STRING_POOL_ADDRESS_P (x))
4218 struct deferred_string **defstr;
4220 defstr = (struct deferred_string **)
4221 htab_find_slot_with_hash (const_str_htab, XSTR (x, 0),
4222 STRHASH (XSTR (x, 0)), NO_INSERT);
4223 if (defstr)
4225 struct deferred_string *p = *defstr;
4227 STRING_POOL_ADDRESS_P (x) = 0;
4228 output_constant_def_contents (p->exp, 0, p->labelno);
4229 htab_clear_slot (const_str_htab, (void **) defstr);
4233 return 0;
4236 /* Find all the constants whose addresses are referenced inside of EXP,
4237 and make sure assembler code with a label has been output for each one.
4238 Indicate whether an ADDR_EXPR has been encountered. */
4240 static int
4241 output_addressed_constants (exp)
4242 tree exp;
4244 int reloc = 0;
4246 /* Give the front-end a chance to convert VALUE to something that
4247 looks more like a constant to the back-end. */
4248 if (lang_expand_constant)
4249 exp = (*lang_expand_constant) (exp);
4251 switch (TREE_CODE (exp))
4253 case ADDR_EXPR:
4255 tree constant = TREE_OPERAND (exp, 0);
4257 while (TREE_CODE (constant) == COMPONENT_REF)
4259 constant = TREE_OPERAND (constant, 0);
4262 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
4263 || TREE_CODE (constant) == CONSTRUCTOR)
4264 /* No need to do anything here
4265 for addresses of variables or functions. */
4266 output_constant_def (constant, 0);
4268 reloc = 1;
4269 break;
4271 case PLUS_EXPR:
4272 case MINUS_EXPR:
4273 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4274 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4275 break;
4277 case NOP_EXPR:
4278 case CONVERT_EXPR:
4279 case NON_LVALUE_EXPR:
4280 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4281 break;
4283 case CONSTRUCTOR:
4285 tree link;
4286 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
4287 if (TREE_VALUE (link) != 0)
4288 reloc |= output_addressed_constants (TREE_VALUE (link));
4290 break;
4292 default:
4293 break;
4295 return reloc;
4298 /* Return nonzero if VALUE is a valid constant-valued expression
4299 for use in initializing a static variable; one that can be an
4300 element of a "constant" initializer.
4302 Return null_pointer_node if the value is absolute;
4303 if it is relocatable, return the variable that determines the relocation.
4304 We assume that VALUE has been folded as much as possible;
4305 therefore, we do not need to check for such things as
4306 arithmetic-combinations of integers. */
4308 tree
4309 initializer_constant_valid_p (value, endtype)
4310 tree value;
4311 tree endtype;
4313 /* Give the front-end a chance to convert VALUE to something that
4314 looks more like a constant to the back-end. */
4315 if (lang_expand_constant)
4316 value = (*lang_expand_constant) (value);
4318 switch (TREE_CODE (value))
4320 case CONSTRUCTOR:
4321 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4322 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4323 && TREE_CONSTANT (value)
4324 && CONSTRUCTOR_ELTS (value))
4325 return
4326 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4327 endtype);
4329 return TREE_STATIC (value) ? null_pointer_node : 0;
4331 case INTEGER_CST:
4332 case REAL_CST:
4333 case STRING_CST:
4334 case COMPLEX_CST:
4335 return null_pointer_node;
4337 case ADDR_EXPR:
4338 case FDESC_EXPR:
4339 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4341 case NON_LVALUE_EXPR:
4342 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4344 case CONVERT_EXPR:
4345 case NOP_EXPR:
4346 /* Allow conversions between pointer types. */
4347 if (POINTER_TYPE_P (TREE_TYPE (value))
4348 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4349 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4351 /* Allow conversions between real types. */
4352 if (FLOAT_TYPE_P (TREE_TYPE (value))
4353 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4354 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4356 /* Allow length-preserving conversions between integer types. */
4357 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4358 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4359 && (TYPE_PRECISION (TREE_TYPE (value))
4360 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4361 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4363 /* Allow conversions between other integer types only if
4364 explicit value. */
4365 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4366 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4368 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4369 endtype);
4370 if (inner == null_pointer_node)
4371 return null_pointer_node;
4372 break;
4375 /* Allow (int) &foo provided int is as wide as a pointer. */
4376 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4377 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4378 && (TYPE_PRECISION (TREE_TYPE (value))
4379 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4380 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4381 endtype);
4383 /* Likewise conversions from int to pointers, but also allow
4384 conversions from 0. */
4385 if (POINTER_TYPE_P (TREE_TYPE (value))
4386 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4388 if (integer_zerop (TREE_OPERAND (value, 0)))
4389 return null_pointer_node;
4390 else if (TYPE_PRECISION (TREE_TYPE (value))
4391 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4392 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4393 endtype);
4396 /* Allow conversions to union types if the value inside is okay. */
4397 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4398 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4399 endtype);
4400 break;
4402 case PLUS_EXPR:
4403 if (! INTEGRAL_TYPE_P (endtype)
4404 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4406 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4407 endtype);
4408 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4409 endtype);
4410 /* If either term is absolute, use the other terms relocation. */
4411 if (valid0 == null_pointer_node)
4412 return valid1;
4413 if (valid1 == null_pointer_node)
4414 return valid0;
4416 break;
4418 case MINUS_EXPR:
4419 if (! INTEGRAL_TYPE_P (endtype)
4420 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4422 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4423 endtype);
4424 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4425 endtype);
4426 /* Win if second argument is absolute. */
4427 if (valid1 == null_pointer_node)
4428 return valid0;
4429 /* Win if both arguments have the same relocation.
4430 Then the value is absolute. */
4431 if (valid0 == valid1 && valid0 != 0)
4432 return null_pointer_node;
4434 /* Since GCC guarantees that string constants are unique in the
4435 generated code, a subtraction between two copies of the same
4436 constant string is absolute. */
4437 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
4438 valid1 && TREE_CODE (valid1) == STRING_CST &&
4439 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
4440 return null_pointer_node;
4443 /* Support differences between labels. */
4444 if (INTEGRAL_TYPE_P (endtype))
4446 tree op0, op1;
4447 op0 = TREE_OPERAND (value, 0);
4448 op1 = TREE_OPERAND (value, 1);
4449 STRIP_NOPS (op0);
4450 STRIP_NOPS (op1);
4452 if (TREE_CODE (op0) == ADDR_EXPR
4453 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4454 && TREE_CODE (op1) == ADDR_EXPR
4455 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4456 return null_pointer_node;
4458 break;
4460 default:
4461 break;
4464 return 0;
4467 /* Output assembler code for constant EXP to FILE, with no label.
4468 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4469 Assumes output_addressed_constants has been done on EXP already.
4471 Generate exactly SIZE bytes of assembler data, padding at the end
4472 with zeros if necessary. SIZE must always be specified.
4474 SIZE is important for structure constructors,
4475 since trailing members may have been omitted from the constructor.
4476 It is also important for initialization of arrays from string constants
4477 since the full length of the string constant might not be wanted.
4478 It is also needed for initialization of unions, where the initializer's
4479 type is just one member, and that may not be as long as the union.
4481 There a case in which we would fail to output exactly SIZE bytes:
4482 for a structure constructor that wants to produce more than SIZE bytes.
4483 But such constructors will never be generated for any possible input.
4485 ALIGN is the alignment of the data in bits. */
4487 void
4488 output_constant (exp, size, align)
4489 tree exp;
4490 int size;
4491 unsigned int align;
4493 enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4495 /* Some front-ends use constants other than the standard
4496 language-indepdent varieties, but which may still be output
4497 directly. Give the front-end a chance to convert EXP to a
4498 language-independent representation. */
4499 if (lang_expand_constant)
4501 exp = (*lang_expand_constant) (exp);
4502 code = TREE_CODE (TREE_TYPE (exp));
4505 if (size == 0 || flag_syntax_only)
4506 return;
4508 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4509 That way we get the constant (we hope) inside it. Also, strip off any
4510 NOP_EXPR that converts between two record, union, array, or set types
4511 or a CONVERT_EXPR that converts to a union TYPE. */
4512 while ((TREE_CODE (exp) == NOP_EXPR
4513 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4514 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4515 || (TREE_CODE (exp) == CONVERT_EXPR
4516 && code == UNION_TYPE)
4517 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4519 exp = TREE_OPERAND (exp, 0);
4520 code = TREE_CODE (TREE_TYPE (exp));
4523 /* Allow a constructor with no elements for any data type.
4524 This means to fill the space with zeros. */
4525 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4527 assemble_zeros (size);
4528 return;
4531 if (TREE_CODE (exp) == FDESC_EXPR)
4533 #ifdef ASM_OUTPUT_FDESC
4534 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
4535 tree decl = TREE_OPERAND (exp, 0);
4536 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
4537 #else
4538 abort ();
4539 #endif
4540 return;
4543 switch (code)
4545 case CHAR_TYPE:
4546 case BOOLEAN_TYPE:
4547 case INTEGER_TYPE:
4548 case ENUMERAL_TYPE:
4549 case POINTER_TYPE:
4550 case REFERENCE_TYPE:
4551 /* ??? What about (int)((float)(int)&foo + 4) */
4552 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4553 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4554 exp = TREE_OPERAND (exp, 0);
4556 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4557 EXPAND_INITIALIZER),
4558 size, align, 0))
4559 error ("initializer for integer value is too complicated");
4560 size = 0;
4561 break;
4563 case REAL_TYPE:
4564 if (TREE_CODE (exp) != REAL_CST)
4565 error ("initializer for floating value is not a floating constant");
4567 assemble_real (TREE_REAL_CST (exp),
4568 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0),
4569 align);
4570 size = 0;
4571 break;
4573 case COMPLEX_TYPE:
4574 output_constant (TREE_REALPART (exp), size / 2, align);
4575 output_constant (TREE_IMAGPART (exp), size / 2,
4576 min_align (align, BITS_PER_UNIT * (size / 2)));
4577 size -= (size / 2) * 2;
4578 break;
4580 case ARRAY_TYPE:
4581 if (TREE_CODE (exp) == CONSTRUCTOR)
4583 output_constructor (exp, size, align);
4584 return;
4586 else if (TREE_CODE (exp) == STRING_CST)
4588 int excess = 0;
4590 if (size > TREE_STRING_LENGTH (exp))
4592 excess = size - TREE_STRING_LENGTH (exp);
4593 size = TREE_STRING_LENGTH (exp);
4596 assemble_string (TREE_STRING_POINTER (exp), size);
4597 size = excess;
4599 else
4600 abort ();
4601 break;
4603 case RECORD_TYPE:
4604 case UNION_TYPE:
4605 if (TREE_CODE (exp) == CONSTRUCTOR)
4606 output_constructor (exp, size, align);
4607 else
4608 abort ();
4609 return;
4611 case SET_TYPE:
4612 if (TREE_CODE (exp) == INTEGER_CST)
4613 assemble_integer (expand_expr (exp, NULL_RTX,
4614 VOIDmode, EXPAND_INITIALIZER),
4615 size, align, 1);
4616 else if (TREE_CODE (exp) == CONSTRUCTOR)
4618 unsigned char *buffer = (unsigned char *) alloca (size);
4619 if (get_set_constructor_bytes (exp, buffer, size))
4620 abort ();
4621 assemble_string ((char *) buffer, size);
4623 else
4624 error ("unknown set constructor type");
4625 return;
4627 default:
4628 break; /* ??? */
4631 if (size > 0)
4632 assemble_zeros (size);
4636 /* Subroutine of output_constructor, used for computing the size of
4637 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4638 type with an unspecified upper bound. */
4640 static unsigned HOST_WIDE_INT
4641 array_size_for_constructor (val)
4642 tree val;
4644 tree max_index, i;
4646 if (TREE_CODE (val) == STRING_CST)
4648 HOST_WIDE_INT len = TREE_STRING_LENGTH(val);
4649 HOST_WIDE_INT esz = int_size_in_bytes (TREE_TYPE (TREE_TYPE (val)));
4650 HOST_WIDE_INT tsz = len * esz;
4651 return tsz;
4653 max_index = NULL_TREE;
4654 for (i = CONSTRUCTOR_ELTS (val); i ; i = TREE_CHAIN (i))
4656 tree index = TREE_PURPOSE (i);
4658 if (TREE_CODE (index) == RANGE_EXPR)
4659 index = TREE_OPERAND (index, 1);
4660 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
4661 max_index = index;
4664 if (max_index == NULL_TREE)
4665 return 0;
4667 /* Compute the total number of array elements. */
4668 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
4669 convert (sizetype,
4670 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
4671 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
4673 /* Multiply by the array element unit size to find number of bytes. */
4674 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
4676 return tree_low_cst (i, 1);
4679 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4680 Generate at least SIZE bytes, padding if necessary. */
4682 static void
4683 output_constructor (exp, size, align)
4684 tree exp;
4685 int size;
4686 unsigned int align;
4688 tree type = TREE_TYPE (exp);
4689 tree link, field = 0;
4690 tree min_index = 0;
4691 /* Number of bytes output or skipped so far.
4692 In other words, current position within the constructor. */
4693 HOST_WIDE_INT total_bytes = 0;
4694 /* Non-zero means BYTE contains part of a byte, to be output. */
4695 int byte_buffer_in_use = 0;
4696 int byte = 0;
4698 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4699 abort ();
4701 if (TREE_CODE (type) == RECORD_TYPE)
4702 field = TYPE_FIELDS (type);
4704 if (TREE_CODE (type) == ARRAY_TYPE
4705 && TYPE_DOMAIN (type) != 0)
4706 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4708 /* As LINK goes through the elements of the constant,
4709 FIELD goes through the structure fields, if the constant is a structure.
4710 if the constant is a union, then we override this,
4711 by getting the field from the TREE_LIST element.
4712 But the constant could also be an array. Then FIELD is zero.
4714 There is always a maximum of one element in the chain LINK for unions
4715 (even if the initializer in a source program incorrectly contains
4716 more one). */
4717 for (link = CONSTRUCTOR_ELTS (exp);
4718 link;
4719 link = TREE_CHAIN (link),
4720 field = field ? TREE_CHAIN (field) : 0)
4722 tree val = TREE_VALUE (link);
4723 tree index = 0;
4725 /* The element in a union constructor specifies the proper field
4726 or index. */
4727 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4728 || TREE_CODE (type) == QUAL_UNION_TYPE)
4729 && TREE_PURPOSE (link) != 0)
4730 field = TREE_PURPOSE (link);
4732 else if (TREE_CODE (type) == ARRAY_TYPE)
4733 index = TREE_PURPOSE (link);
4735 /* Eliminate the marker that makes a cast not be an lvalue. */
4736 if (val != 0)
4737 STRIP_NOPS (val);
4739 if (index && TREE_CODE (index) == RANGE_EXPR)
4741 unsigned HOST_WIDE_INT fieldsize
4742 = int_size_in_bytes (TREE_TYPE (type));
4743 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4744 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4745 HOST_WIDE_INT index;
4746 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
4748 for (index = lo_index; index <= hi_index; index++)
4750 /* Output the element's initial value. */
4751 if (val == 0)
4752 assemble_zeros (fieldsize);
4753 else
4754 output_constant (val, fieldsize, align2);
4756 /* Count its size. */
4757 total_bytes += fieldsize;
4760 else if (field == 0 || !DECL_BIT_FIELD (field))
4762 /* An element that is not a bit-field. */
4764 unsigned HOST_WIDE_INT fieldsize;
4765 /* Since this structure is static,
4766 we know the positions are constant. */
4767 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4768 unsigned int align2;
4770 if (index != 0)
4771 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4772 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4774 /* Output any buffered-up bit-fields preceding this element. */
4775 if (byte_buffer_in_use)
4777 ASM_OUTPUT_BYTE (asm_out_file, byte);
4778 total_bytes++;
4779 byte_buffer_in_use = 0;
4782 /* Advance to offset of this element.
4783 Note no alignment needed in an array, since that is guaranteed
4784 if each element has the proper size. */
4785 if ((field != 0 || index != 0) && pos != total_bytes)
4787 assemble_zeros (pos - total_bytes);
4788 total_bytes = pos;
4791 /* Find the alignment of this element. */
4792 align2 = min_align (align, BITS_PER_UNIT * pos);
4794 /* Determine size this element should occupy. */
4795 if (field)
4797 fieldsize = 0;
4799 /* If this is an array with an unspecified upper bound,
4800 the initializer determines the size. */
4801 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4802 but we cannot do this until the deprecated support for
4803 initializing zero-length array members is removed. */
4804 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4805 && TYPE_DOMAIN (TREE_TYPE (field))
4806 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4808 fieldsize = array_size_for_constructor (val);
4809 /* Given a non-empty initialization, this field had
4810 better be last. */
4811 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4812 abort ();
4814 else if (DECL_SIZE_UNIT (field))
4816 /* ??? This can't be right. If the decl size overflows
4817 a host integer we will silently emit no data. */
4818 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4819 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4822 else
4823 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4825 /* Output the element's initial value. */
4826 if (val == 0)
4827 assemble_zeros (fieldsize);
4828 else
4829 output_constant (val, fieldsize, align2);
4831 /* Count its size. */
4832 total_bytes += fieldsize;
4834 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4835 error ("invalid initial value for member `%s'",
4836 IDENTIFIER_POINTER (DECL_NAME (field)));
4837 else
4839 /* Element that is a bit-field. */
4841 HOST_WIDE_INT next_offset = int_bit_position (field);
4842 HOST_WIDE_INT end_offset
4843 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4845 if (val == 0)
4846 val = integer_zero_node;
4848 /* If this field does not start in this (or, next) byte,
4849 skip some bytes. */
4850 if (next_offset / BITS_PER_UNIT != total_bytes)
4852 /* Output remnant of any bit field in previous bytes. */
4853 if (byte_buffer_in_use)
4855 ASM_OUTPUT_BYTE (asm_out_file, byte);
4856 total_bytes++;
4857 byte_buffer_in_use = 0;
4860 /* If still not at proper byte, advance to there. */
4861 if (next_offset / BITS_PER_UNIT != total_bytes)
4863 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4864 total_bytes = next_offset / BITS_PER_UNIT;
4868 if (! byte_buffer_in_use)
4869 byte = 0;
4871 /* We must split the element into pieces that fall within
4872 separate bytes, and combine each byte with previous or
4873 following bit-fields. */
4875 /* next_offset is the offset n fbits from the beginning of
4876 the structure to the next bit of this element to be processed.
4877 end_offset is the offset of the first bit past the end of
4878 this element. */
4879 while (next_offset < end_offset)
4881 int this_time;
4882 int shift;
4883 HOST_WIDE_INT value;
4884 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4885 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4887 /* Advance from byte to byte
4888 within this element when necessary. */
4889 while (next_byte != total_bytes)
4891 ASM_OUTPUT_BYTE (asm_out_file, byte);
4892 total_bytes++;
4893 byte = 0;
4896 /* Number of bits we can process at once
4897 (all part of the same byte). */
4898 this_time = MIN (end_offset - next_offset,
4899 BITS_PER_UNIT - next_bit);
4900 if (BYTES_BIG_ENDIAN)
4902 /* On big-endian machine, take the most significant bits
4903 first (of the bits that are significant)
4904 and put them into bytes from the most significant end. */
4905 shift = end_offset - next_offset - this_time;
4907 /* Don't try to take a bunch of bits that cross
4908 the word boundary in the INTEGER_CST. We can
4909 only select bits from the LOW or HIGH part
4910 not from both. */
4911 if (shift < HOST_BITS_PER_WIDE_INT
4912 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4914 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4915 shift = HOST_BITS_PER_WIDE_INT;
4918 /* Now get the bits from the appropriate constant word. */
4919 if (shift < HOST_BITS_PER_WIDE_INT)
4920 value = TREE_INT_CST_LOW (val);
4921 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4923 value = TREE_INT_CST_HIGH (val);
4924 shift -= HOST_BITS_PER_WIDE_INT;
4926 else
4927 abort ();
4929 /* Get the result. This works only when:
4930 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4931 byte |= (((value >> shift)
4932 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4933 << (BITS_PER_UNIT - this_time - next_bit));
4935 else
4937 /* On little-endian machines,
4938 take first the least significant bits of the value
4939 and pack them starting at the least significant
4940 bits of the bytes. */
4941 shift = next_offset - int_bit_position (field);
4943 /* Don't try to take a bunch of bits that cross
4944 the word boundary in the INTEGER_CST. We can
4945 only select bits from the LOW or HIGH part
4946 not from both. */
4947 if (shift < HOST_BITS_PER_WIDE_INT
4948 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4949 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4951 /* Now get the bits from the appropriate constant word. */
4952 if (shift < HOST_BITS_PER_WIDE_INT)
4953 value = TREE_INT_CST_LOW (val);
4954 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4956 value = TREE_INT_CST_HIGH (val);
4957 shift -= HOST_BITS_PER_WIDE_INT;
4959 else
4960 abort ();
4962 /* Get the result. This works only when:
4963 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4964 byte |= (((value >> shift)
4965 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4966 << next_bit);
4969 next_offset += this_time;
4970 byte_buffer_in_use = 1;
4975 if (byte_buffer_in_use)
4977 ASM_OUTPUT_BYTE (asm_out_file, byte);
4978 total_bytes++;
4981 if (total_bytes < size)
4982 assemble_zeros (size - total_bytes);
4986 /* This structure contains any weak symbol declarations waiting
4987 to be emitted. */
4988 struct weak_syms
4990 struct weak_syms * next;
4991 const char * name;
4992 const char * value;
4995 static struct weak_syms * weak_decls;
4997 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4998 associated with NAME. */
5001 add_weak (name, value)
5002 const char *name;
5003 const char *value;
5005 struct weak_syms *weak;
5007 weak = (struct weak_syms *) xmalloc (sizeof (struct weak_syms));
5009 if (weak == NULL)
5010 return 0;
5012 weak->next = weak_decls;
5013 weak->name = name;
5014 weak->value = value;
5015 weak_decls = weak;
5017 return 1;
5020 /* Declare DECL to be a weak symbol. */
5022 void
5023 declare_weak (decl)
5024 tree decl;
5026 if (! TREE_PUBLIC (decl))
5027 error_with_decl (decl, "weak declaration of `%s' must be public");
5028 else if (TREE_ASM_WRITTEN (decl))
5029 error_with_decl (decl, "weak declaration of `%s' must precede definition");
5030 else if (SUPPORTS_WEAK)
5031 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
5032 else
5033 warning_with_decl (decl, "weak declaration of `%s' not supported");
5035 DECL_WEAK (decl) = 1;
5038 /* Emit any pending weak declarations. */
5040 void
5041 weak_finish ()
5043 if (SUPPORTS_WEAK)
5045 struct weak_syms *t;
5046 for (t = weak_decls; t; t = t->next)
5048 #ifdef ASM_OUTPUT_WEAK_ALIAS
5049 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, t->name, t->value);
5050 #else
5051 #ifdef ASM_WEAKEN_LABEL
5052 if (t->value)
5053 abort ();
5054 ASM_WEAKEN_LABEL (asm_out_file, t->name);
5055 #endif
5056 #endif
5061 /* Remove NAME from the pending list of weak symbols. This prevents
5062 the compiler from emitting multiple .weak directives which confuses
5063 some assemblers. */
5064 #ifdef ASM_WEAKEN_LABEL
5065 static void
5066 remove_from_pending_weak_list (name)
5067 const char *name;
5069 struct weak_syms *t;
5070 struct weak_syms **p;
5072 for (p = &weak_decls; *p; )
5074 t = *p;
5075 if (strcmp (name, t->name) == 0)
5077 *p = t->next;
5078 free (t);
5080 else
5081 p = &(t->next);
5084 #endif /* ASM_WEAKEN_LABEL */
5086 /* Emit an assembler directive to make the symbol for DECL an alias to
5087 the symbol for TARGET. */
5089 void
5090 assemble_alias (decl, target)
5091 tree decl, target ATTRIBUTE_UNUSED;
5093 const char *name;
5095 /* We must force creation of DECL_RTL for debug info generation, even though
5096 we don't use it here. */
5097 make_decl_rtl (decl, NULL);
5099 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5101 #ifdef ASM_OUTPUT_DEF
5102 /* Make name accessible from other files, if appropriate. */
5104 if (TREE_PUBLIC (decl))
5106 #ifdef ASM_WEAKEN_LABEL
5107 if (DECL_WEAK (decl))
5109 ASM_WEAKEN_LABEL (asm_out_file, name);
5110 /* Remove this function from the pending weak list so that
5111 we do not emit multiple .weak directives for it. */
5112 remove_from_pending_weak_list
5113 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
5115 else
5116 #endif
5117 ASM_GLOBALIZE_LABEL (asm_out_file, name);
5120 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
5121 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
5122 #else
5123 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
5124 #endif
5125 TREE_ASM_WRITTEN (decl) = 1;
5126 #else
5127 #ifdef ASM_OUTPUT_WEAK_ALIAS
5128 if (! DECL_WEAK (decl))
5129 warning ("only weak aliases are supported in this configuration");
5131 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
5132 TREE_ASM_WRITTEN (decl) = 1;
5133 #else
5134 warning ("alias definitions not supported in this configuration; ignored");
5135 #endif
5136 #endif
5139 /* Returns 1 if the target configuration supports defining public symbols
5140 so that one of them will be chosen at link time instead of generating a
5141 multiply-defined symbol error, whether through the use of weak symbols or
5142 a target-specific mechanism for having duplicates discarded. */
5145 supports_one_only ()
5147 if (SUPPORTS_ONE_ONLY)
5148 return 1;
5149 return SUPPORTS_WEAK;
5152 /* Set up DECL as a public symbol that can be defined in multiple
5153 translation units without generating a linker error. */
5155 void
5156 make_decl_one_only (decl)
5157 tree decl;
5159 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
5160 abort ();
5162 TREE_PUBLIC (decl) = 1;
5164 if (TREE_CODE (decl) == VAR_DECL
5165 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
5166 DECL_COMMON (decl) = 1;
5167 else if (SUPPORTS_ONE_ONLY)
5169 #ifdef MAKE_DECL_ONE_ONLY
5170 MAKE_DECL_ONE_ONLY (decl);
5171 #endif
5172 DECL_ONE_ONLY (decl) = 1;
5174 else if (SUPPORTS_WEAK)
5175 DECL_WEAK (decl) = 1;
5176 else
5177 abort ();
5180 void
5181 init_varasm_once ()
5183 const_str_htab = htab_create (128, const_str_htab_hash, const_str_htab_eq,
5184 const_str_htab_del);
5185 in_named_htab = htab_create (31, in_named_entry_hash,
5186 in_named_entry_eq, NULL);
5188 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
5189 mark_const_hash_entry);
5190 ggc_add_root (&const_str_htab, 1, sizeof const_str_htab,
5191 mark_const_str_htab);
5194 /* Select a set of attributes for section NAME based on the properties
5195 of DECL and whether or not RELOC indicates that DECL's initializer
5196 might contain runtime relocations.
5198 We make the section read-only and executable for a function decl,
5199 read-only for a const data decl, and writable for a non-const data decl. */
5201 unsigned int
5202 default_section_type_flags (decl, name, reloc)
5203 tree decl;
5204 const char *name;
5205 int reloc;
5207 unsigned int flags;
5209 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
5210 flags = SECTION_CODE;
5211 else if (decl && DECL_READONLY_SECTION (decl, reloc))
5212 flags = 0;
5213 else
5214 flags = SECTION_WRITE;
5216 if (decl && DECL_ONE_ONLY (decl))
5217 flags |= SECTION_LINKONCE;
5219 if (strcmp (name, ".bss") == 0
5220 || strncmp (name, ".bss.", 5) == 0
5221 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
5222 || strcmp (name, ".sbss") == 0
5223 || strncmp (name, ".sbss.", 6) == 0
5224 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0)
5225 flags |= SECTION_BSS;
5227 return flags;
5230 /* Output assembly to switch to section NAME with attribute FLAGS.
5231 Four variants for common object file formats. */
5233 void
5234 default_no_named_section (name, flags)
5235 const char *name ATTRIBUTE_UNUSED;
5236 unsigned int flags ATTRIBUTE_UNUSED;
5238 /* Some object formats don't support named sections at all. The
5239 front-end should already have flagged this as an error. */
5240 abort ();
5243 void
5244 default_elf_asm_named_section (name, flags)
5245 const char *name;
5246 unsigned int flags;
5248 char flagchars[10], *f = flagchars;
5249 const char *type;
5251 if (! named_section_first_declaration (name))
5253 fprintf (asm_out_file, "\t.section\t%s\n", name);
5254 return;
5257 if (!(flags & SECTION_DEBUG))
5258 *f++ = 'a';
5259 if (flags & SECTION_WRITE)
5260 *f++ = 'w';
5261 if (flags & SECTION_CODE)
5262 *f++ = 'x';
5263 if (flags & SECTION_SMALL)
5264 *f++ = 's';
5265 if (flags & SECTION_MERGE)
5266 *f++ = 'M';
5267 if (flags & SECTION_STRINGS)
5268 *f++ = 'S';
5269 *f = '\0';
5271 if (flags & SECTION_BSS)
5272 type = "nobits";
5273 else
5274 type = "progbits";
5276 if (flags & SECTION_ENTSIZE)
5277 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
5278 name, flagchars, type, flags & SECTION_ENTSIZE);
5279 else
5280 fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
5281 name, flagchars, type);
5284 void
5285 default_coff_asm_named_section (name, flags)
5286 const char *name;
5287 unsigned int flags;
5289 char flagchars[8], *f = flagchars;
5291 if (flags & SECTION_WRITE)
5292 *f++ = 'w';
5293 if (flags & SECTION_CODE)
5294 *f++ = 'x';
5295 *f = '\0';
5297 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
5300 void
5301 default_pe_asm_named_section (name, flags)
5302 const char *name;
5303 unsigned int flags;
5305 default_coff_asm_named_section (name, flags);
5307 if (flags & SECTION_LINKONCE)
5309 /* Functions may have been compiled at various levels of
5310 optimization so we can't use `same_size' here.
5311 Instead, have the linker pick one. */
5312 fprintf (asm_out_file, "\t.linkonce %s\n",
5313 (flags & SECTION_CODE ? "discard" : "same_size"));
5317 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5318 from SYMBOL is used in all classes derived from SYMBOL. */
5320 void
5321 assemble_vtable_entry (symbol, offset)
5322 rtx symbol;
5323 HOST_WIDE_INT offset;
5325 fputs ("\t.vtable_entry ", asm_out_file);
5326 output_addr_const (asm_out_file, symbol);
5327 fputs (", ", asm_out_file);
5328 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, offset);
5329 fputc ('\n', asm_out_file);
5332 /* Used for vtable gc in GNU binutils. Record the class heirarchy by noting
5333 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5335 void
5336 assemble_vtable_inherit (child, parent)
5337 rtx child, parent;
5339 fputs ("\t.vtable_inherit ", asm_out_file);
5340 output_addr_const (asm_out_file, child);
5341 fputs (", ", asm_out_file);
5342 output_addr_const (asm_out_file, parent);
5343 fputc ('\n', asm_out_file);