* gcc.dg/const-elim-1.c: xfail for xtensa.
[official-gcc.git] / gcc / varasm.c
blob061cbcac3ef32e6cd0a7d35dfe5a9a7e4e0b66c5
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 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 "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "real.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "hashtab.h"
45 #include "c-pragma.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
51 #include "cgraph.h"
53 #ifdef XCOFF_DEBUGGING_INFO
54 #include "xcoffout.h" /* Needed for external data
55 declarations for e.g. AIX 4.x. */
56 #endif
58 #ifndef TRAMPOLINE_ALIGNMENT
59 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
60 #endif
62 #ifndef ASM_STABS_OP
63 #define ASM_STABS_OP "\t.stabs\t"
64 #endif
66 /* The (assembler) name of the first globally-visible object output. */
67 const char *first_global_object_name;
68 const char *weak_global_object_name;
70 struct addr_const;
71 struct constant_descriptor_rtx;
72 struct rtx_constant_pool;
74 struct varasm_status GTY(())
76 /* If we're using a per-function constant pool, this is it. */
77 struct rtx_constant_pool *pool;
79 /* Number of tree-constants deferred during the expansion of this
80 function. */
81 unsigned int deferred_constants;
84 #define n_deferred_constants (cfun->varasm->deferred_constants)
86 /* Number for making the label on the next
87 constant that is stored in memory. */
89 static GTY(()) int const_labelno;
91 /* Carry information from ASM_DECLARE_OBJECT_NAME
92 to ASM_FINISH_DECLARE_OBJECT. */
94 int size_directive_output;
96 /* The last decl for which assemble_variable was called,
97 if it did ASM_DECLARE_OBJECT_NAME.
98 If the last call to assemble_variable didn't do that,
99 this holds 0. */
101 tree last_assemble_variable_decl;
103 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
104 So giving constant the alias set for the type will allow such
105 initializations to appear to conflict with the load of the constant. We
106 avoid this by giving all constants an alias set for just constants.
107 Since there will be no stores to that alias set, nothing will ever
108 conflict with them. */
110 static HOST_WIDE_INT const_alias_set;
112 static const char *strip_reg_name (const char *);
113 static int contains_pointers_p (tree);
114 #ifdef ASM_OUTPUT_EXTERNAL
115 static bool incorporeal_function_p (tree);
116 #endif
117 static void decode_addr_const (tree, struct addr_const *);
118 static hashval_t const_desc_hash (const void *);
119 static int const_desc_eq (const void *, const void *);
120 static hashval_t const_hash_1 (const tree);
121 static int compare_constant (const tree, const tree);
122 static tree copy_constant (tree);
123 static void output_constant_def_contents (rtx);
124 static void output_addressed_constants (tree);
125 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
126 static unsigned min_align (unsigned, unsigned);
127 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
128 static void globalize_decl (tree);
129 static void maybe_assemble_visibility (tree);
130 static int in_named_entry_eq (const void *, const void *);
131 static hashval_t in_named_entry_hash (const void *);
132 #ifdef ASM_OUTPUT_BSS
133 static void asm_output_bss (FILE *, tree, const char *,
134 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
135 #endif
136 #ifdef BSS_SECTION_ASM_OP
137 #ifdef ASM_OUTPUT_ALIGNED_BSS
138 static void asm_output_aligned_bss (FILE *, tree, const char *,
139 unsigned HOST_WIDE_INT, int)
140 ATTRIBUTE_UNUSED;
141 #endif
142 #endif /* BSS_SECTION_ASM_OP */
143 static bool asm_emit_uninitialised (tree, const char*,
144 unsigned HOST_WIDE_INT,
145 unsigned HOST_WIDE_INT);
146 static void mark_weak (tree);
148 enum in_section { no_section, in_text, in_data, in_named
149 #ifdef BSS_SECTION_ASM_OP
150 , in_bss
151 #endif
152 #ifdef CTORS_SECTION_ASM_OP
153 , in_ctors
154 #endif
155 #ifdef DTORS_SECTION_ASM_OP
156 , in_dtors
157 #endif
158 #ifdef READONLY_DATA_SECTION_ASM_OP
159 , in_readonly_data
160 #endif
161 #ifdef EXTRA_SECTIONS
162 , EXTRA_SECTIONS
163 #endif
165 static GTY(()) enum in_section in_section = no_section;
167 /* Return a nonzero value if DECL has a section attribute. */
168 #ifndef IN_NAMED_SECTION
169 #define IN_NAMED_SECTION(DECL) \
170 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
171 && DECL_SECTION_NAME (DECL) != NULL_TREE)
172 #endif
174 /* Text of section name when in_section == in_named. */
175 static GTY(()) const char *in_named_name;
177 /* Hash table of flags that have been used for a particular named section. */
179 struct in_named_entry GTY(())
181 const char *name;
182 unsigned int flags;
183 bool declared;
186 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
188 /* Define functions like text_section for any extra sections. */
189 #ifdef EXTRA_SECTION_FUNCTIONS
190 EXTRA_SECTION_FUNCTIONS
191 #endif
193 /* Tell assembler to switch to text section. */
195 void
196 text_section (void)
198 if (in_section != in_text)
200 in_section = in_text;
201 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
205 /* Tell assembler to switch to data section. */
207 void
208 data_section (void)
210 if (in_section != in_data)
212 in_section = in_data;
213 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
217 /* Tell assembler to switch to read-only data section. This is normally
218 the text section. */
220 void
221 readonly_data_section (void)
223 #ifdef READONLY_DATA_SECTION
224 READONLY_DATA_SECTION (); /* Note this can call data_section. */
225 #else
226 #ifdef READONLY_DATA_SECTION_ASM_OP
227 if (in_section != in_readonly_data)
229 in_section = in_readonly_data;
230 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
231 fputc ('\n', asm_out_file);
233 #else
234 text_section ();
235 #endif
236 #endif
239 /* Determine if we're in the text section. */
242 in_text_section (void)
244 return in_section == in_text;
247 /* Determine if we're in the data section. */
250 in_data_section (void)
252 return in_section == in_data;
255 /* Helper routines for maintaining in_named_htab. */
257 static int
258 in_named_entry_eq (const void *p1, const void *p2)
260 const struct in_named_entry *old = p1;
261 const char *new = p2;
263 return strcmp (old->name, new) == 0;
266 static hashval_t
267 in_named_entry_hash (const void *p)
269 const struct in_named_entry *old = p;
270 return htab_hash_string (old->name);
273 /* If SECTION has been seen before as a named section, return the flags
274 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
275 set of flags for a section to have, so 0 does not mean that the section
276 has not been seen. */
278 unsigned int
279 get_named_section_flags (const char *section)
281 struct in_named_entry **slot;
283 slot = (struct in_named_entry **)
284 htab_find_slot_with_hash (in_named_htab, section,
285 htab_hash_string (section), NO_INSERT);
287 return slot ? (*slot)->flags : 0;
290 /* Returns true if the section has been declared before. Sets internal
291 flag on this section in in_named_hash so subsequent calls on this
292 section will return false. */
294 bool
295 named_section_first_declaration (const char *name)
297 struct in_named_entry **slot;
299 slot = (struct in_named_entry **)
300 htab_find_slot_with_hash (in_named_htab, name,
301 htab_hash_string (name), NO_INSERT);
302 if (! (*slot)->declared)
304 (*slot)->declared = true;
305 return true;
307 else
309 return false;
314 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
315 different set of flags, return false. */
317 bool
318 set_named_section_flags (const char *section, unsigned int flags)
320 struct in_named_entry **slot, *entry;
322 slot = (struct in_named_entry **)
323 htab_find_slot_with_hash (in_named_htab, section,
324 htab_hash_string (section), INSERT);
325 entry = *slot;
327 if (!entry)
329 entry = ggc_alloc (sizeof (*entry));
330 *slot = entry;
331 entry->name = ggc_strdup (section);
332 entry->flags = flags;
333 entry->declared = false;
335 else if (entry->flags != flags)
336 return false;
338 return true;
341 /* Tell assembler to change to section NAME with attributes FLAGS. */
343 void
344 named_section_flags (const char *name, unsigned int flags)
346 if (in_section != in_named || strcmp (name, in_named_name) != 0)
348 if (! set_named_section_flags (name, flags))
349 abort ();
351 (*targetm.asm_out.named_section) (name, flags);
353 if (flags & SECTION_FORGET)
354 in_section = no_section;
355 else
357 in_named_name = ggc_strdup (name);
358 in_section = in_named;
363 /* Tell assembler to change to section NAME for DECL.
364 If DECL is NULL, just switch to section NAME.
365 If NAME is NULL, get the name from DECL.
366 If RELOC is 1, the initializer for DECL contains relocs. */
368 void
369 named_section (tree decl, const char *name, int reloc)
371 unsigned int flags;
373 if (decl != NULL_TREE && !DECL_P (decl))
374 abort ();
375 if (name == NULL)
376 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
378 flags = (* targetm.section_type_flags) (decl, name, reloc);
380 /* Sanity check user variables for flag changes. Non-user
381 section flag changes will abort in named_section_flags.
382 However, don't complain if SECTION_OVERRIDE is set.
383 We trust that the setter knows that it is safe to ignore
384 the default flags for this decl. */
385 if (decl && ! set_named_section_flags (name, flags))
387 flags = get_named_section_flags (name);
388 if ((flags & SECTION_OVERRIDE) == 0)
389 error ("%J%D causes a section type conflict", decl, decl);
392 named_section_flags (name, flags);
395 /* If required, set DECL_SECTION_NAME to a unique name. */
397 void
398 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
399 int flag_function_or_data_sections)
401 if (DECL_SECTION_NAME (decl) == NULL_TREE
402 && targetm.have_named_sections
403 && (flag_function_or_data_sections
404 || DECL_ONE_ONLY (decl)))
405 (*targetm.asm_out.unique_section) (decl, reloc);
408 #ifdef BSS_SECTION_ASM_OP
410 /* Tell the assembler to switch to the bss section. */
412 void
413 bss_section (void)
415 if (in_section != in_bss)
417 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
418 in_section = in_bss;
422 #ifdef ASM_OUTPUT_BSS
424 /* Utility function for ASM_OUTPUT_BSS for targets to use if
425 they don't support alignments in .bss.
426 ??? It is believed that this function will work in most cases so such
427 support is localized here. */
429 static void
430 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
431 const char *name,
432 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
433 unsigned HOST_WIDE_INT rounded)
435 (*targetm.asm_out.globalize_label) (file, name);
436 bss_section ();
437 #ifdef ASM_DECLARE_OBJECT_NAME
438 last_assemble_variable_decl = decl;
439 ASM_DECLARE_OBJECT_NAME (file, name, decl);
440 #else
441 /* Standard thing is just output label for the object. */
442 ASM_OUTPUT_LABEL (file, name);
443 #endif /* ASM_DECLARE_OBJECT_NAME */
444 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
447 #endif
449 #ifdef ASM_OUTPUT_ALIGNED_BSS
451 /* Utility function for targets to use in implementing
452 ASM_OUTPUT_ALIGNED_BSS.
453 ??? It is believed that this function will work in most cases so such
454 support is localized here. */
456 static void
457 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
458 const char *name, unsigned HOST_WIDE_INT size,
459 int align)
461 bss_section ();
462 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
463 #ifdef ASM_DECLARE_OBJECT_NAME
464 last_assemble_variable_decl = decl;
465 ASM_DECLARE_OBJECT_NAME (file, name, decl);
466 #else
467 /* Standard thing is just output label for the object. */
468 ASM_OUTPUT_LABEL (file, name);
469 #endif /* ASM_DECLARE_OBJECT_NAME */
470 ASM_OUTPUT_SKIP (file, size ? size : 1);
473 #endif
475 #endif /* BSS_SECTION_ASM_OP */
477 /* Switch to the section for function DECL.
479 If DECL is NULL_TREE, switch to the text section.
480 ??? It's not clear that we will ever be passed NULL_TREE, but it's
481 safer to handle it. */
483 void
484 function_section (tree decl)
486 if (decl != NULL_TREE
487 && DECL_SECTION_NAME (decl) != NULL_TREE)
488 named_section (decl, (char *) 0, 0);
489 else
490 text_section ();
493 /* Switch to section for variable DECL. RELOC is the same as the
494 argument to SELECT_SECTION. */
496 void
497 variable_section (tree decl, int reloc)
499 if (IN_NAMED_SECTION (decl))
500 named_section (decl, NULL, reloc);
501 else
502 (*targetm.asm_out.select_section) (decl, reloc, DECL_ALIGN (decl));
505 /* Tell assembler to switch to the section for string merging. */
507 void
508 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
509 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
510 unsigned int flags ATTRIBUTE_UNUSED)
512 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
513 && TREE_CODE (decl) == STRING_CST
514 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
515 && align <= 256
516 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
518 enum machine_mode mode;
519 unsigned int modesize;
520 const char *str;
521 int i, j, len, unit;
522 char name[30];
524 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
525 modesize = GET_MODE_BITSIZE (mode);
526 if (modesize >= 8 && modesize <= 256
527 && (modesize & (modesize - 1)) == 0)
529 if (align < modesize)
530 align = modesize;
532 str = TREE_STRING_POINTER (decl);
533 len = TREE_STRING_LENGTH (decl);
534 unit = GET_MODE_SIZE (mode);
536 /* Check for embedded NUL characters. */
537 for (i = 0; i < len; i += unit)
539 for (j = 0; j < unit; j++)
540 if (str[i + j] != '\0')
541 break;
542 if (j == unit)
543 break;
545 if (i == len - unit)
547 sprintf (name, ".rodata.str%d.%d", modesize / 8,
548 (int) (align / 8));
549 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
550 if (!i && modesize < align)
552 /* A "" string with requested alignment greater than
553 character size might cause a problem:
554 if some other string required even bigger
555 alignment than "", then linker might think the
556 "" is just part of padding after some other string
557 and not put it into the hash table initially.
558 But this means "" could have smaller alignment
559 than requested. */
560 #ifdef ASM_OUTPUT_SECTION_START
561 named_section_flags (name, flags);
562 ASM_OUTPUT_SECTION_START (asm_out_file);
563 #else
564 readonly_data_section ();
565 #endif
566 return;
569 named_section_flags (name, flags);
570 return;
575 readonly_data_section ();
578 /* Tell assembler to switch to the section for constant merging. */
580 void
581 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
582 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
583 unsigned int flags ATTRIBUTE_UNUSED)
585 unsigned int modesize = GET_MODE_BITSIZE (mode);
587 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
588 && mode != VOIDmode
589 && mode != BLKmode
590 && modesize <= align
591 && align >= 8
592 && align <= 256
593 && (align & (align - 1)) == 0)
595 char name[24];
597 sprintf (name, ".rodata.cst%d", (int) (align / 8));
598 flags |= (align / 8) | SECTION_MERGE;
599 named_section_flags (name, flags);
600 return;
603 readonly_data_section ();
606 /* Given NAME, a putative register name, discard any customary prefixes. */
608 static const char *
609 strip_reg_name (const char *name)
611 #ifdef REGISTER_PREFIX
612 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
613 name += strlen (REGISTER_PREFIX);
614 #endif
615 if (name[0] == '%' || name[0] == '#')
616 name++;
617 return name;
620 /* Decode an `asm' spec for a declaration as a register name.
621 Return the register number, or -1 if nothing specified,
622 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
623 or -3 if ASMSPEC is `cc' and is not recognized,
624 or -4 if ASMSPEC is `memory' and is not recognized.
625 Accept an exact spelling or a decimal number.
626 Prefixes such as % are optional. */
629 decode_reg_name (const char *asmspec)
631 if (asmspec != 0)
633 int i;
635 /* Get rid of confusing prefixes. */
636 asmspec = strip_reg_name (asmspec);
638 /* Allow a decimal number as a "register name". */
639 for (i = strlen (asmspec) - 1; i >= 0; i--)
640 if (! ISDIGIT (asmspec[i]))
641 break;
642 if (asmspec[0] != 0 && i < 0)
644 i = atoi (asmspec);
645 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
646 return i;
647 else
648 return -2;
651 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
652 if (reg_names[i][0]
653 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
654 return i;
656 #ifdef ADDITIONAL_REGISTER_NAMES
658 static const struct { const char *const name; const int number; } table[]
659 = ADDITIONAL_REGISTER_NAMES;
661 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
662 if (! strcmp (asmspec, table[i].name))
663 return table[i].number;
665 #endif /* ADDITIONAL_REGISTER_NAMES */
667 if (!strcmp (asmspec, "memory"))
668 return -4;
670 if (!strcmp (asmspec, "cc"))
671 return -3;
673 return -2;
676 return -1;
679 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
680 have static storage duration. In other words, it should not be an
681 automatic variable, including PARM_DECLs.
683 There is, however, one exception: this function handles variables
684 explicitly placed in a particular register by the user.
686 ASMSPEC, if not 0, is the string which the user specified as the
687 assembler symbol name.
689 This is never called for PARM_DECL nodes. */
691 void
692 make_decl_rtl (tree decl, const char *asmspec)
694 const char *name = 0;
695 int reg_number;
696 rtx x;
698 /* Check that we are not being given an automatic variable. */
699 /* A weak alias has TREE_PUBLIC set but not the other bits. */
700 if (TREE_CODE (decl) == PARM_DECL
701 || TREE_CODE (decl) == RESULT_DECL
702 || (TREE_CODE (decl) == VAR_DECL
703 && !TREE_STATIC (decl)
704 && !TREE_PUBLIC (decl)
705 && !DECL_EXTERNAL (decl)
706 && !DECL_REGISTER (decl)))
707 abort ();
708 /* And that we were not given a type or a label. */
709 else if (TREE_CODE (decl) == TYPE_DECL
710 || TREE_CODE (decl) == LABEL_DECL)
711 abort ();
713 /* For a duplicate declaration, we can be called twice on the
714 same DECL node. Don't discard the RTL already made. */
715 if (DECL_RTL_SET_P (decl))
717 /* If the old RTL had the wrong mode, fix the mode. */
718 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
719 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
720 DECL_MODE (decl), 0));
722 /* ??? Another way to do this would be to maintain a hashed
723 table of such critters. Instead of adding stuff to a DECL
724 to give certain attributes to it, we could use an external
725 hash map from DECL to set of attributes. */
727 /* Let the target reassign the RTL if it wants.
728 This is necessary, for example, when one machine specific
729 decl attribute overrides another. */
730 (* targetm.encode_section_info) (decl, DECL_RTL (decl), false);
731 return;
734 reg_number = decode_reg_name (asmspec);
735 if (reg_number == -2)
737 /* ASMSPEC is given, and not the name of a register. Mark the
738 name with a star so assemble_name won't munge it. */
739 char *starred = alloca (strlen (asmspec) + 2);
740 starred[0] = '*';
741 strcpy (starred + 1, asmspec);
742 change_decl_assembler_name (decl, get_identifier (starred));
745 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
747 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
749 /* First detect errors in declaring global registers. */
750 if (reg_number == -1)
751 error ("%Jregister name not specified for '%D'", decl, decl);
752 else if (reg_number < 0)
753 error ("%Jinvalid register name for '%D'", decl, decl);
754 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
755 error ("%Jdata type of '%D' isn't suitable for a register",
756 decl, decl);
757 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
758 error ("%Jregister specified for '%D' isn't suitable for data type",
759 decl, decl);
760 /* Now handle properly declared static register variables. */
761 else
763 int nregs;
765 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
767 DECL_INITIAL (decl) = 0;
768 error ("global register variable has initial value");
770 if (TREE_THIS_VOLATILE (decl))
771 warning ("volatile register variables don't work as you might wish");
773 /* If the user specified one of the eliminables registers here,
774 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
775 confused with that register and be eliminated. This usage is
776 somewhat suspect... */
778 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
779 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
780 REG_USERVAR_P (DECL_RTL (decl)) = 1;
782 if (TREE_STATIC (decl))
784 /* Make this register global, so not usable for anything
785 else. */
786 #ifdef ASM_DECLARE_REGISTER_GLOBAL
787 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
788 #endif
789 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
790 while (nregs > 0)
791 globalize_reg (reg_number + --nregs);
794 /* As a register variable, it has no section. */
795 return;
799 /* Now handle ordinary static variables and functions (in memory).
800 Also handle vars declared register invalidly. */
802 if (reg_number >= 0 || reg_number == -3)
803 error ("%Jregister name given for non-register variable '%D'", decl, decl);
805 /* Specifying a section attribute on a variable forces it into a
806 non-.bss section, and thus it cannot be common. */
807 if (TREE_CODE (decl) == VAR_DECL
808 && DECL_SECTION_NAME (decl) != NULL_TREE
809 && DECL_INITIAL (decl) == NULL_TREE
810 && DECL_COMMON (decl))
811 DECL_COMMON (decl) = 0;
813 /* Variables can't be both common and weak. */
814 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
815 DECL_COMMON (decl) = 0;
817 x = gen_rtx_SYMBOL_REF (Pmode, name);
818 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
819 SYMBOL_REF_DECL (x) = decl;
821 x = gen_rtx_MEM (DECL_MODE (decl), x);
822 if (TREE_CODE (decl) != FUNCTION_DECL)
823 set_mem_attributes (x, decl, 1);
824 SET_DECL_RTL (decl, x);
826 /* Optionally set flags or add text to the name to record information
827 such as that it is a function name.
828 If the name is changed, the macro ASM_OUTPUT_LABELREF
829 will have to know how to strip this information. */
830 (* targetm.encode_section_info) (decl, DECL_RTL (decl), true);
833 /* Make the rtl for variable VAR be volatile.
834 Use this only for static variables. */
836 void
837 make_var_volatile (tree var)
839 if (GET_CODE (DECL_RTL (var)) != MEM)
840 abort ();
842 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
845 /* Output a string of literal assembler code
846 for an `asm' keyword used between functions. */
848 void
849 assemble_asm (tree string)
851 app_enable ();
853 if (TREE_CODE (string) == ADDR_EXPR)
854 string = TREE_OPERAND (string, 0);
856 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
859 /* Record an element in the table of global destructors. SYMBOL is
860 a SYMBOL_REF of the function to be called; PRIORITY is a number
861 between 0 and MAX_INIT_PRIORITY. */
863 void
864 default_stabs_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
866 /* Tell GNU LD that this is part of the static destructor set.
867 This will work for any system that uses stabs, most usefully
868 aout systems. */
869 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
870 assemble_name (asm_out_file, XSTR (symbol, 0));
871 fputc ('\n', asm_out_file);
874 void
875 default_named_section_asm_out_destructor (rtx symbol, int priority)
877 const char *section = ".dtors";
878 char buf[16];
880 /* ??? This only works reliably with the GNU linker. */
881 if (priority != DEFAULT_INIT_PRIORITY)
883 sprintf (buf, ".dtors.%.5u",
884 /* Invert the numbering so the linker puts us in the proper
885 order; constructors are run from right to left, and the
886 linker sorts in increasing order. */
887 MAX_INIT_PRIORITY - priority);
888 section = buf;
891 named_section_flags (section, SECTION_WRITE);
892 assemble_align (POINTER_SIZE);
893 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
896 #ifdef DTORS_SECTION_ASM_OP
897 void
898 dtors_section (void)
900 if (in_section != in_dtors)
902 in_section = in_dtors;
903 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
904 fputc ('\n', asm_out_file);
908 void
909 default_dtor_section_asm_out_destructor (rtx symbol,
910 int priority ATTRIBUTE_UNUSED)
912 dtors_section ();
913 assemble_align (POINTER_SIZE);
914 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
916 #endif
918 /* Likewise for global constructors. */
920 void
921 default_stabs_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
923 /* Tell GNU LD that this is part of the static destructor set.
924 This will work for any system that uses stabs, most usefully
925 aout systems. */
926 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
927 assemble_name (asm_out_file, XSTR (symbol, 0));
928 fputc ('\n', asm_out_file);
931 void
932 default_named_section_asm_out_constructor (rtx symbol, int priority)
934 const char *section = ".ctors";
935 char buf[16];
937 /* ??? This only works reliably with the GNU linker. */
938 if (priority != DEFAULT_INIT_PRIORITY)
940 sprintf (buf, ".ctors.%.5u",
941 /* Invert the numbering so the linker puts us in the proper
942 order; constructors are run from right to left, and the
943 linker sorts in increasing order. */
944 MAX_INIT_PRIORITY - priority);
945 section = buf;
948 named_section_flags (section, SECTION_WRITE);
949 assemble_align (POINTER_SIZE);
950 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
953 #ifdef CTORS_SECTION_ASM_OP
954 void
955 ctors_section (void)
957 if (in_section != in_ctors)
959 in_section = in_ctors;
960 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
961 fputc ('\n', asm_out_file);
965 void
966 default_ctor_section_asm_out_constructor (rtx symbol,
967 int priority ATTRIBUTE_UNUSED)
969 ctors_section ();
970 assemble_align (POINTER_SIZE);
971 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
973 #endif
975 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
976 a nonzero value if the constant pool should be output before the
977 start of the function, or a zero value if the pool should output
978 after the end of the function. The default is to put it before the
979 start. */
981 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
982 #define CONSTANT_POOL_BEFORE_FUNCTION 1
983 #endif
985 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
986 to be output to assembler.
987 Set first_global_object_name and weak_global_object_name as appropriate. */
989 void
990 notice_global_symbol (tree decl)
992 const char **type = &first_global_object_name;
994 if (first_global_object_name
995 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
996 || !DECL_NAME (decl)
997 || (TREE_CODE (decl) != FUNCTION_DECL
998 && (TREE_CODE (decl) != VAR_DECL
999 || (DECL_COMMON (decl)
1000 && (DECL_INITIAL (decl) == 0
1001 || DECL_INITIAL (decl) == error_mark_node))))
1002 || GET_CODE (DECL_RTL (decl)) != MEM)
1003 return;
1005 /* We win when global object is found, but it is useful to know about weak
1006 symbol as well so we can produce nicer unique names. */
1007 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1008 type = &weak_global_object_name;
1010 if (!*type)
1012 const char *p;
1013 char *name;
1014 rtx decl_rtl = DECL_RTL (decl);
1016 p = (* targetm.strip_name_encoding) (XSTR (XEXP (decl_rtl, 0), 0));
1017 name = xstrdup (p);
1019 *type = name;
1023 /* Output assembler code for the constant pool of a function and associated
1024 with defining the name of the function. DECL describes the function.
1025 NAME is the function's name. For the constant pool, we use the current
1026 constant pool data. */
1028 void
1029 assemble_start_function (tree decl, const char *fnname)
1031 int align;
1033 /* The following code does not need preprocessing in the assembler. */
1035 app_disable ();
1037 if (CONSTANT_POOL_BEFORE_FUNCTION)
1038 output_constant_pool (fnname, decl);
1040 resolve_unique_section (decl, 0, flag_function_sections);
1041 function_section (decl);
1043 /* Tell assembler to move to target machine's alignment for functions. */
1044 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1045 if (align < force_align_functions_log)
1046 align = force_align_functions_log;
1047 if (align > 0)
1049 ASM_OUTPUT_ALIGN (asm_out_file, align);
1052 /* Handle a user-specified function alignment.
1053 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1054 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1055 if (align_functions_log > align
1056 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1058 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1059 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1060 align_functions_log, align_functions - 1);
1061 #else
1062 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1063 #endif
1066 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1067 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1068 #endif
1070 (*debug_hooks->begin_function) (decl);
1072 /* Make function name accessible from other files, if appropriate. */
1074 if (TREE_PUBLIC (decl))
1076 notice_global_symbol (decl);
1078 globalize_decl (decl);
1080 maybe_assemble_visibility (decl);
1083 /* Do any machine/system dependent processing of the function name. */
1084 #ifdef ASM_DECLARE_FUNCTION_NAME
1085 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1086 #else
1087 /* Standard thing is just output label for the function. */
1088 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1089 #endif /* ASM_DECLARE_FUNCTION_NAME */
1092 /* Output assembler code associated with defining the size of the
1093 function. DECL describes the function. NAME is the function's name. */
1095 void
1096 assemble_end_function (tree decl, const char *fnname)
1098 #ifdef ASM_DECLARE_FUNCTION_SIZE
1099 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1100 #endif
1101 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1103 output_constant_pool (fnname, decl);
1104 function_section (decl); /* need to switch back */
1108 /* Assemble code to leave SIZE bytes of zeros. */
1110 void
1111 assemble_zeros (unsigned HOST_WIDE_INT size)
1113 /* Do no output if -fsyntax-only. */
1114 if (flag_syntax_only)
1115 return;
1117 #ifdef ASM_NO_SKIP_IN_TEXT
1118 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1119 so we must output 0s explicitly in the text section. */
1120 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1122 unsigned HOST_WIDE_INT i;
1123 for (i = 0; i < size; i++)
1124 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1126 else
1127 #endif
1128 if (size > 0)
1129 ASM_OUTPUT_SKIP (asm_out_file, size);
1132 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1134 void
1135 assemble_align (int align)
1137 if (align > BITS_PER_UNIT)
1139 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1143 /* Assemble a string constant with the specified C string as contents. */
1145 void
1146 assemble_string (const char *p, int size)
1148 int pos = 0;
1149 int maximum = 2000;
1151 /* If the string is very long, split it up. */
1153 while (pos < size)
1155 int thissize = size - pos;
1156 if (thissize > maximum)
1157 thissize = maximum;
1159 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1161 pos += thissize;
1162 p += thissize;
1167 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1168 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1169 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1170 #else
1171 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1172 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1173 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1174 #else
1175 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1176 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1177 #endif
1178 #endif
1180 #if defined ASM_OUTPUT_ALIGNED_BSS
1181 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1182 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1183 #else
1184 #if defined ASM_OUTPUT_BSS
1185 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1186 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1187 #else
1188 #undef ASM_EMIT_BSS
1189 #endif
1190 #endif
1192 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1193 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1194 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1195 #else
1196 #if defined ASM_OUTPUT_ALIGNED_COMMON
1197 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1198 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1199 #else
1200 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1201 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1202 #endif
1203 #endif
1205 static bool
1206 asm_emit_uninitialised (tree decl, const char *name,
1207 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1208 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1210 enum
1212 asm_dest_common,
1213 asm_dest_bss,
1214 asm_dest_local
1216 destination = asm_dest_local;
1218 /* ??? We should handle .bss via select_section mechanisms rather than
1219 via special target hooks. That would eliminate this special case. */
1220 if (TREE_PUBLIC (decl))
1222 if (!DECL_COMMON (decl))
1223 #ifdef ASM_EMIT_BSS
1224 destination = asm_dest_bss;
1225 #else
1226 return false;
1227 #endif
1228 else
1229 destination = asm_dest_common;
1232 if (destination == asm_dest_bss)
1233 globalize_decl (decl);
1234 resolve_unique_section (decl, 0, flag_data_sections);
1236 if (flag_shared_data)
1238 switch (destination)
1240 #ifdef ASM_OUTPUT_SHARED_BSS
1241 case asm_dest_bss:
1242 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1243 return;
1244 #endif
1245 #ifdef ASM_OUTPUT_SHARED_COMMON
1246 case asm_dest_common:
1247 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1248 return;
1249 #endif
1250 #ifdef ASM_OUTPUT_SHARED_LOCAL
1251 case asm_dest_local:
1252 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1253 return;
1254 #endif
1255 default:
1256 break;
1260 switch (destination)
1262 #ifdef ASM_EMIT_BSS
1263 case asm_dest_bss:
1264 ASM_EMIT_BSS (decl, name, size, rounded);
1265 break;
1266 #endif
1267 case asm_dest_common:
1268 ASM_EMIT_COMMON (decl, name, size, rounded);
1269 break;
1270 case asm_dest_local:
1271 ASM_EMIT_LOCAL (decl, name, size, rounded);
1272 break;
1273 default:
1274 abort ();
1277 return true;
1280 /* Assemble everything that is needed for a variable or function declaration.
1281 Not used for automatic variables, and not used for function definitions.
1282 Should not be called for variables of incomplete structure type.
1284 TOP_LEVEL is nonzero if this variable has file scope.
1285 AT_END is nonzero if this is the special handling, at end of compilation,
1286 to define things that have had only tentative definitions.
1287 DONT_OUTPUT_DATA if nonzero means don't actually output the
1288 initial value (that will be done by the caller). */
1290 void
1291 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1292 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1294 const char *name;
1295 unsigned int align;
1296 int reloc = 0;
1297 rtx decl_rtl;
1299 if (lang_hooks.decls.prepare_assemble_variable)
1300 (*lang_hooks.decls.prepare_assemble_variable) (decl);
1302 last_assemble_variable_decl = 0;
1304 /* Normally no need to say anything here for external references,
1305 since assemble_external is called by the language-specific code
1306 when a declaration is first seen. */
1308 if (DECL_EXTERNAL (decl))
1309 return;
1311 /* Output no assembler code for a function declaration.
1312 Only definitions of functions output anything. */
1314 if (TREE_CODE (decl) == FUNCTION_DECL)
1315 return;
1317 /* Do nothing for global register variables. */
1318 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1320 TREE_ASM_WRITTEN (decl) = 1;
1321 return;
1324 /* If type was incomplete when the variable was declared,
1325 see if it is complete now. */
1327 if (DECL_SIZE (decl) == 0)
1328 layout_decl (decl, 0);
1330 /* Still incomplete => don't allocate it; treat the tentative defn
1331 (which is what it must have been) as an `extern' reference. */
1333 if (!dont_output_data && DECL_SIZE (decl) == 0)
1335 error ("%Jstorage size of `%D' isn't known", decl, decl);
1336 TREE_ASM_WRITTEN (decl) = 1;
1337 return;
1340 /* The first declaration of a variable that comes through this function
1341 decides whether it is global (in C, has external linkage)
1342 or local (in C, has internal linkage). So do nothing more
1343 if this function has already run. */
1345 if (TREE_ASM_WRITTEN (decl))
1346 return;
1348 /* Make sure targetm.encode_section_info is invoked before we set
1349 ASM_WRITTEN. */
1350 decl_rtl = DECL_RTL (decl);
1352 TREE_ASM_WRITTEN (decl) = 1;
1354 /* Do no output if -fsyntax-only. */
1355 if (flag_syntax_only)
1356 return;
1358 app_disable ();
1360 if (! dont_output_data
1361 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1363 error ("%Jsize of variable '%D' is too large", decl, decl);
1364 return;
1367 name = XSTR (XEXP (decl_rtl, 0), 0);
1368 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1369 notice_global_symbol (decl);
1371 /* Compute the alignment of this data. */
1373 align = DECL_ALIGN (decl);
1375 /* In the case for initialing an array whose length isn't specified,
1376 where we have not yet been able to do the layout,
1377 figure out the proper alignment now. */
1378 if (dont_output_data && DECL_SIZE (decl) == 0
1379 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1380 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1382 /* Some object file formats have a maximum alignment which they support.
1383 In particular, a.out format supports a maximum alignment of 4. */
1384 #ifndef MAX_OFILE_ALIGNMENT
1385 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1386 #endif
1387 if (align > MAX_OFILE_ALIGNMENT)
1389 warning ("%Jalignment of '%D' is greater than maximum object "
1390 "file alignment. Using %d", decl, decl,
1391 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1392 align = MAX_OFILE_ALIGNMENT;
1395 /* On some machines, it is good to increase alignment sometimes. */
1396 if (! DECL_USER_ALIGN (decl))
1398 #ifdef DATA_ALIGNMENT
1399 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1400 #endif
1401 #ifdef CONSTANT_ALIGNMENT
1402 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1403 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1404 #endif
1407 /* Reset the alignment in case we have made it tighter, so we can benefit
1408 from it in get_pointer_alignment. */
1409 DECL_ALIGN (decl) = align;
1410 set_mem_align (decl_rtl, align);
1412 if (TREE_PUBLIC (decl))
1413 maybe_assemble_visibility (decl);
1415 /* Output any data that we will need to use the address of. */
1416 if (DECL_INITIAL (decl) == error_mark_node)
1417 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1418 else if (DECL_INITIAL (decl))
1420 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1421 output_addressed_constants (DECL_INITIAL (decl));
1423 resolve_unique_section (decl, reloc, flag_data_sections);
1425 /* Handle uninitialized definitions. */
1427 /* If the decl has been given an explicit section name, then it
1428 isn't common, and shouldn't be handled as such. */
1429 if (DECL_SECTION_NAME (decl) || dont_output_data)
1431 /* We don't implement common thread-local data at present. */
1432 else if (DECL_THREAD_LOCAL (decl))
1434 if (DECL_COMMON (decl))
1435 sorry ("thread-local COMMON data not implemented");
1437 else if (DECL_INITIAL (decl) == 0
1438 || DECL_INITIAL (decl) == error_mark_node
1439 || (flag_zero_initialized_in_bss
1440 /* Leave constant zeroes in .rodata so they can be shared. */
1441 && !TREE_READONLY (decl)
1442 && initializer_zerop (DECL_INITIAL (decl))))
1444 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1445 unsigned HOST_WIDE_INT rounded = size;
1447 /* Don't allocate zero bytes of common,
1448 since that means "undefined external" in the linker. */
1449 if (size == 0)
1450 rounded = 1;
1452 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1453 so that each uninitialized object starts on such a boundary. */
1454 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1455 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1456 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1458 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1459 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1460 warning ("%Jrequested alignment for '%D' is greater than "
1461 "implemented alignment of %d", decl, decl, rounded);
1462 #endif
1464 /* If the target cannot output uninitialized but not common global data
1465 in .bss, then we have to use .data, so fall through. */
1466 if (asm_emit_uninitialised (decl, name, size, rounded))
1467 return;
1470 /* Handle initialized definitions.
1471 Also handle uninitialized global definitions if -fno-common and the
1472 target doesn't support ASM_OUTPUT_BSS. */
1474 /* First make the assembler name(s) global if appropriate. */
1475 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1476 globalize_decl (decl);
1478 /* Switch to the appropriate section. */
1479 variable_section (decl, reloc);
1481 /* dbxout.c needs to know this. */
1482 if (in_text_section ())
1483 DECL_IN_TEXT_SECTION (decl) = 1;
1485 /* Output the alignment of this data. */
1486 if (align > BITS_PER_UNIT)
1488 ASM_OUTPUT_ALIGN (asm_out_file,
1489 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1492 /* Do any machine/system dependent processing of the object. */
1493 #ifdef ASM_DECLARE_OBJECT_NAME
1494 last_assemble_variable_decl = decl;
1495 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1496 #else
1497 /* Standard thing is just output label for the object. */
1498 ASM_OUTPUT_LABEL (asm_out_file, name);
1499 #endif /* ASM_DECLARE_OBJECT_NAME */
1501 if (!dont_output_data)
1503 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1504 /* Output the actual data. */
1505 output_constant (DECL_INITIAL (decl),
1506 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1507 align);
1508 else
1509 /* Leave space for it. */
1510 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1514 /* Return 1 if type TYPE contains any pointers. */
1516 static int
1517 contains_pointers_p (tree type)
1519 switch (TREE_CODE (type))
1521 case POINTER_TYPE:
1522 case REFERENCE_TYPE:
1523 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1524 so I'll play safe and return 1. */
1525 case OFFSET_TYPE:
1526 return 1;
1528 case RECORD_TYPE:
1529 case UNION_TYPE:
1530 case QUAL_UNION_TYPE:
1532 tree fields;
1533 /* For a type that has fields, see if the fields have pointers. */
1534 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1535 if (TREE_CODE (fields) == FIELD_DECL
1536 && contains_pointers_p (TREE_TYPE (fields)))
1537 return 1;
1538 return 0;
1541 case ARRAY_TYPE:
1542 /* An array type contains pointers if its element type does. */
1543 return contains_pointers_p (TREE_TYPE (type));
1545 default:
1546 return 0;
1550 #ifdef ASM_OUTPUT_EXTERNAL
1551 /* True if DECL is a function decl for which no out-of-line copy exists.
1552 It is assumed that DECL's assembler name has been set. */
1554 static bool
1555 incorporeal_function_p (tree decl)
1557 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1559 const char *name;
1561 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1562 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1563 return true;
1565 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1566 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1567 return true;
1569 return false;
1571 #endif
1573 /* Output something to declare an external symbol to the assembler.
1574 (Most assemblers don't need this, so we normally output nothing.)
1575 Do nothing if DECL is not external. */
1577 void
1578 assemble_external (tree decl ATTRIBUTE_UNUSED)
1580 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1581 main body of this code is only rarely exercised. To provide some
1582 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1583 open. If it's not, we should not be calling this function. */
1584 if (!asm_out_file)
1585 abort ();
1587 #ifdef ASM_OUTPUT_EXTERNAL
1588 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1590 rtx rtl = DECL_RTL (decl);
1592 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1593 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1594 && !incorporeal_function_p (decl))
1596 /* Some systems do require some output. */
1597 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1598 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1601 #endif
1604 /* Similar, for calling a library function FUN. */
1606 void
1607 assemble_external_libcall (rtx fun)
1609 /* Declare library function name external when first used, if nec. */
1610 if (! SYMBOL_REF_USED (fun))
1612 SYMBOL_REF_USED (fun) = 1;
1613 (*targetm.asm_out.external_libcall) (fun);
1617 /* Assemble a label named NAME. */
1619 void
1620 assemble_label (const char *name)
1622 ASM_OUTPUT_LABEL (asm_out_file, name);
1625 /* Set the symbol_referenced flag for ID and notify callgraph code. */
1626 void
1627 mark_referenced (tree id)
1629 if (!TREE_SYMBOL_REFERENCED (id))
1631 struct cgraph_node *node;
1632 struct cgraph_varpool_node *vnode;
1634 if (!cgraph_global_info_ready)
1636 node = cgraph_node_for_identifier (id);
1637 if (node)
1638 cgraph_mark_needed_node (node);
1641 vnode = cgraph_varpool_node_for_identifier (id);
1642 if (vnode)
1643 cgraph_varpool_mark_needed_node (vnode);
1645 TREE_SYMBOL_REFERENCED (id) = 1;
1648 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1649 If NAME starts with a *, the rest of NAME is output verbatim.
1650 Otherwise NAME is transformed in an implementation-defined way
1651 (usually by the addition of an underscore).
1652 Many macros in the tm file are defined to call this function. */
1654 void
1655 assemble_name (FILE *file, const char *name)
1657 const char *real_name;
1658 tree id;
1660 real_name = (* targetm.strip_name_encoding) (name);
1662 id = maybe_get_identifier (real_name);
1663 if (id)
1664 mark_referenced (id);
1666 if (name[0] == '*')
1667 fputs (&name[1], file);
1668 else
1669 ASM_OUTPUT_LABELREF (file, name);
1672 /* Allocate SIZE bytes writable static space with a gensym name
1673 and return an RTX to refer to its address. */
1676 assemble_static_space (unsigned HOST_WIDE_INT size)
1678 char name[12];
1679 const char *namestring;
1680 rtx x;
1682 #if 0
1683 if (flag_shared_data)
1684 data_section ();
1685 #endif
1687 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1688 ++const_labelno;
1689 namestring = ggc_strdup (name);
1691 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1692 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1694 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1695 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1696 BIGGEST_ALIGNMENT);
1697 #else
1698 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1699 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1700 #else
1702 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1703 so that each uninitialized object starts on such a boundary. */
1704 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1705 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1706 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1707 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1708 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1709 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1711 #endif
1712 #endif
1713 return x;
1716 /* Assemble the static constant template for function entry trampolines.
1717 This is done at most once per compilation.
1718 Returns an RTX for the address of the template. */
1720 #ifdef TRAMPOLINE_TEMPLATE
1722 assemble_trampoline_template (void)
1724 char label[256];
1725 const char *name;
1726 int align;
1727 rtx symbol;
1729 /* By default, put trampoline templates in read-only data section. */
1731 #ifdef TRAMPOLINE_SECTION
1732 TRAMPOLINE_SECTION ();
1733 #else
1734 readonly_data_section ();
1735 #endif
1737 /* Write the assembler code to define one. */
1738 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1739 if (align > 0)
1741 ASM_OUTPUT_ALIGN (asm_out_file, align);
1744 (*targetm.asm_out.internal_label) (asm_out_file, "LTRAMP", 0);
1745 TRAMPOLINE_TEMPLATE (asm_out_file);
1747 /* Record the rtl to refer to it. */
1748 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1749 name = ggc_strdup (label);
1750 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
1751 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
1753 return symbol;
1755 #endif
1757 /* A and B are either alignments or offsets. Return the minimum alignment
1758 that may be assumed after adding the two together. */
1760 static inline unsigned
1761 min_align (unsigned int a, unsigned int b)
1763 return (a | b) & -(a | b);
1766 /* Return the assembler directive for creating a given kind of integer
1767 object. SIZE is the number of bytes in the object and ALIGNED_P
1768 indicates whether it is known to be aligned. Return NULL if the
1769 assembly dialect has no such directive.
1771 The returned string should be printed at the start of a new line and
1772 be followed immediately by the object's initial value. */
1774 const char *
1775 integer_asm_op (int size, int aligned_p)
1777 struct asm_int_op *ops;
1779 if (aligned_p)
1780 ops = &targetm.asm_out.aligned_op;
1781 else
1782 ops = &targetm.asm_out.unaligned_op;
1784 switch (size)
1786 case 1:
1787 return targetm.asm_out.byte_op;
1788 case 2:
1789 return ops->hi;
1790 case 4:
1791 return ops->si;
1792 case 8:
1793 return ops->di;
1794 case 16:
1795 return ops->ti;
1796 default:
1797 return NULL;
1801 /* Use directive OP to assemble an integer object X. Print OP at the
1802 start of the line, followed immediately by the value of X. */
1804 void
1805 assemble_integer_with_op (const char *op, rtx x)
1807 fputs (op, asm_out_file);
1808 output_addr_const (asm_out_file, x);
1809 fputc ('\n', asm_out_file);
1812 /* The default implementation of the asm_out.integer target hook. */
1814 bool
1815 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
1816 unsigned int size ATTRIBUTE_UNUSED,
1817 int aligned_p ATTRIBUTE_UNUSED)
1819 const char *op = integer_asm_op (size, aligned_p);
1820 return op && (assemble_integer_with_op (op, x), true);
1823 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1824 the alignment of the integer in bits. Return 1 if we were able to output
1825 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
1826 the constant. */
1828 bool
1829 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
1831 int aligned_p;
1833 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1835 /* See if the target hook can handle this kind of object. */
1836 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1837 return true;
1839 /* If the object is a multi-byte one, try splitting it up. Split
1840 it into words it if is multi-word, otherwise split it into bytes. */
1841 if (size > 1)
1843 enum machine_mode omode, imode;
1844 unsigned int subalign;
1845 unsigned int subsize, i;
1847 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1848 subalign = MIN (align, subsize * BITS_PER_UNIT);
1849 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1850 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1852 for (i = 0; i < size; i += subsize)
1854 rtx partial = simplify_subreg (omode, x, imode, i);
1855 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
1856 break;
1858 if (i == size)
1859 return true;
1861 /* If we've printed some of it, but not all of it, there's no going
1862 back now. */
1863 if (i > 0)
1864 abort ();
1867 if (force)
1868 abort ();
1870 return false;
1873 void
1874 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
1876 long data[4];
1877 int i;
1878 int bitsize, nelts, nunits, units_per;
1880 /* This is hairy. We have a quantity of known size. real_to_target
1881 will put it into an array of *host* longs, 32 bits per element
1882 (even if long is more than 32 bits). We need to determine the
1883 number of array elements that are occupied (nelts) and the number
1884 of *target* min-addressable units that will be occupied in the
1885 object file (nunits). We cannot assume that 32 divides the
1886 mode's bitsize (size * BITS_PER_UNIT) evenly.
1888 size * BITS_PER_UNIT is used here to make sure that padding bits
1889 (which might appear at either end of the value; real_to_target
1890 will include the padding bits in its output array) are included. */
1892 nunits = GET_MODE_SIZE (mode);
1893 bitsize = nunits * BITS_PER_UNIT;
1894 nelts = CEIL (bitsize, 32);
1895 units_per = 32 / BITS_PER_UNIT;
1897 real_to_target (data, &d, mode);
1899 /* Put out the first word with the specified alignment. */
1900 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
1901 nunits -= units_per;
1903 /* Subsequent words need only 32-bit alignment. */
1904 align = min_align (align, 32);
1906 for (i = 1; i < nelts; i++)
1908 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
1909 nunits -= units_per;
1913 /* Given an expression EXP with a constant value,
1914 reduce it to the sum of an assembler symbol and an integer.
1915 Store them both in the structure *VALUE.
1916 Abort if EXP does not reduce. */
1918 struct addr_const GTY(())
1920 rtx base;
1921 HOST_WIDE_INT offset;
1924 static void
1925 decode_addr_const (tree exp, struct addr_const *value)
1927 tree target = TREE_OPERAND (exp, 0);
1928 int offset = 0;
1929 rtx x;
1931 while (1)
1933 if (TREE_CODE (target) == COMPONENT_REF
1934 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
1937 offset += int_byte_position (TREE_OPERAND (target, 1));
1938 target = TREE_OPERAND (target, 0);
1940 else if (TREE_CODE (target) == ARRAY_REF
1941 || TREE_CODE (target) == ARRAY_RANGE_REF)
1943 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
1944 * tree_low_cst (TREE_OPERAND (target, 1), 0));
1945 target = TREE_OPERAND (target, 0);
1947 else
1948 break;
1951 switch (TREE_CODE (target))
1953 case VAR_DECL:
1954 case FUNCTION_DECL:
1955 x = DECL_RTL (target);
1956 break;
1958 case LABEL_DECL:
1959 x = gen_rtx_MEM (FUNCTION_MODE,
1960 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
1961 break;
1963 case REAL_CST:
1964 case STRING_CST:
1965 case COMPLEX_CST:
1966 case CONSTRUCTOR:
1967 case INTEGER_CST:
1968 x = output_constant_def (target, 1);
1969 break;
1971 default:
1972 abort ();
1975 if (GET_CODE (x) != MEM)
1976 abort ();
1977 x = XEXP (x, 0);
1979 value->base = x;
1980 value->offset = offset;
1983 /* Uniquize all constants that appear in memory.
1984 Each constant in memory thus far output is recorded
1985 in `const_desc_table'. */
1987 struct constant_descriptor_tree GTY(())
1989 /* A MEM for the constant. */
1990 rtx rtl;
1992 /* The value of the constant. */
1993 tree value;
1996 static GTY((param_is (struct constant_descriptor_tree)))
1997 htab_t const_desc_htab;
1999 static struct constant_descriptor_tree * build_constant_desc (tree);
2000 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2002 /* Compute a hash code for a constant expression. */
2004 static hashval_t
2005 const_desc_hash (const void *ptr)
2007 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2010 static hashval_t
2011 const_hash_1 (const tree exp)
2013 const char *p;
2014 hashval_t hi;
2015 int len, i;
2016 enum tree_code code = TREE_CODE (exp);
2018 /* Either set P and LEN to the address and len of something to hash and
2019 exit the switch or return a value. */
2021 switch (code)
2023 case INTEGER_CST:
2024 p = (char *) &TREE_INT_CST (exp);
2025 len = sizeof TREE_INT_CST (exp);
2026 break;
2028 case REAL_CST:
2029 return real_hash (TREE_REAL_CST_PTR (exp));
2031 case STRING_CST:
2032 p = TREE_STRING_POINTER (exp);
2033 len = TREE_STRING_LENGTH (exp);
2034 break;
2036 case COMPLEX_CST:
2037 return (const_hash_1 (TREE_REALPART (exp)) * 5
2038 + const_hash_1 (TREE_IMAGPART (exp)));
2040 case CONSTRUCTOR:
2041 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2043 char *tmp;
2045 len = int_size_in_bytes (TREE_TYPE (exp));
2046 tmp = alloca (len);
2047 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2048 p = tmp;
2049 break;
2051 else
2053 tree link;
2055 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2057 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2058 if (TREE_VALUE (link))
2059 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2061 return hi;
2064 case ADDR_EXPR:
2065 case FDESC_EXPR:
2067 struct addr_const value;
2069 decode_addr_const (exp, &value);
2070 if (GET_CODE (value.base) == SYMBOL_REF)
2072 /* Don't hash the address of the SYMBOL_REF;
2073 only use the offset and the symbol name. */
2074 hi = value.offset;
2075 p = XSTR (value.base, 0);
2076 for (i = 0; p[i] != 0; i++)
2077 hi = ((hi * 613) + (unsigned) (p[i]));
2079 else if (GET_CODE (value.base) == LABEL_REF)
2080 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2081 else
2082 abort ();
2084 return hi;
2086 case PLUS_EXPR:
2087 case MINUS_EXPR:
2088 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2089 + const_hash_1 (TREE_OPERAND (exp, 1)));
2091 case NOP_EXPR:
2092 case CONVERT_EXPR:
2093 case NON_LVALUE_EXPR:
2094 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2096 default:
2097 /* A language specific constant. Just hash the code. */
2098 return code;
2101 /* Compute hashing function. */
2102 hi = len;
2103 for (i = 0; i < len; i++)
2104 hi = ((hi * 613) + (unsigned) (p[i]));
2106 return hi;
2109 /* Wrapper of compare_constant, for the htab interface. */
2110 static int
2111 const_desc_eq (const void *p1, const void *p2)
2113 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2114 ((struct constant_descriptor_tree *)p2)->value);
2117 /* Compare t1 and t2, and return 1 only if they are known to result in
2118 the same bit pattern on output. */
2120 static int
2121 compare_constant (const tree t1, const tree t2)
2123 enum tree_code typecode;
2125 if (t1 == NULL_TREE)
2126 return t2 == NULL_TREE;
2127 if (t2 == NULL_TREE)
2128 return 0;
2130 if (TREE_CODE (t1) != TREE_CODE (t2))
2131 return 0;
2133 switch (TREE_CODE (t1))
2135 case INTEGER_CST:
2136 /* Integer constants are the same only if the same width of type. */
2137 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2138 return 0;
2139 return tree_int_cst_equal (t1, t2);
2141 case REAL_CST:
2142 /* Real constants are the same only if the same width of type. */
2143 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2144 return 0;
2146 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2148 case STRING_CST:
2149 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2150 return 0;
2152 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2153 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2154 TREE_STRING_LENGTH (t1)));
2156 case COMPLEX_CST:
2157 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2158 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2160 case CONSTRUCTOR:
2161 typecode = TREE_CODE (TREE_TYPE (t1));
2162 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2163 return 0;
2165 if (typecode == SET_TYPE)
2167 int len = int_size_in_bytes (TREE_TYPE (t2));
2168 unsigned char *tmp1, *tmp2;
2170 if (int_size_in_bytes (TREE_TYPE (t1)) != len)
2171 return 0;
2173 tmp1 = alloca (len);
2174 tmp2 = alloca (len);
2176 if (get_set_constructor_bytes (t1, tmp1, len) != NULL_TREE)
2177 return 0;
2178 if (get_set_constructor_bytes (t2, tmp2, len) != NULL_TREE)
2179 return 0;
2181 return memcmp (tmp1, tmp2, len) == 0;
2183 else
2185 tree l1, l2;
2187 if (typecode == ARRAY_TYPE)
2189 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2190 /* For arrays, check that the sizes all match. */
2191 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2192 || size_1 == -1
2193 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2194 return 0;
2196 else
2198 /* For record and union constructors, require exact type
2199 equality. */
2200 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2201 return 0;
2204 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2205 l1 && l2;
2206 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2208 /* Check that each value is the same... */
2209 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2210 return 0;
2211 /* ... and that they apply to the same fields! */
2212 if (typecode == ARRAY_TYPE)
2214 if (! compare_constant (TREE_PURPOSE (l1),
2215 TREE_PURPOSE (l2)))
2216 return 0;
2218 else
2220 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2221 return 0;
2225 return l1 == NULL_TREE && l2 == NULL_TREE;
2228 case ADDR_EXPR:
2229 case FDESC_EXPR:
2231 struct addr_const value1, value2;
2233 decode_addr_const (t1, &value1);
2234 decode_addr_const (t2, &value2);
2235 return (value1.offset == value2.offset
2236 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2239 case PLUS_EXPR:
2240 case MINUS_EXPR:
2241 case RANGE_EXPR:
2242 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2243 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2245 case NOP_EXPR:
2246 case CONVERT_EXPR:
2247 case NON_LVALUE_EXPR:
2248 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2250 default:
2252 tree nt1, nt2;
2253 nt1 = (*lang_hooks.expand_constant) (t1);
2254 nt2 = (*lang_hooks.expand_constant) (t2);
2255 if (nt1 != t1 || nt2 != t2)
2256 return compare_constant (nt1, nt2);
2257 else
2258 return 0;
2262 /* Should not get here. */
2263 abort ();
2266 /* Make a copy of the whole tree structure for a constant. This
2267 handles the same types of nodes that compare_constant handles. */
2269 static tree
2270 copy_constant (tree exp)
2272 switch (TREE_CODE (exp))
2274 case ADDR_EXPR:
2275 /* For ADDR_EXPR, we do not want to copy the decl whose address
2276 is requested. We do want to copy constants though. */
2277 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2278 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2279 copy_constant (TREE_OPERAND (exp, 0)));
2280 else
2281 return copy_node (exp);
2283 case INTEGER_CST:
2284 case REAL_CST:
2285 case STRING_CST:
2286 return copy_node (exp);
2288 case COMPLEX_CST:
2289 return build_complex (TREE_TYPE (exp),
2290 copy_constant (TREE_REALPART (exp)),
2291 copy_constant (TREE_IMAGPART (exp)));
2293 case PLUS_EXPR:
2294 case MINUS_EXPR:
2295 return build (TREE_CODE (exp), TREE_TYPE (exp),
2296 copy_constant (TREE_OPERAND (exp, 0)),
2297 copy_constant (TREE_OPERAND (exp, 1)));
2299 case NOP_EXPR:
2300 case CONVERT_EXPR:
2301 case NON_LVALUE_EXPR:
2302 case VIEW_CONVERT_EXPR:
2303 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2304 copy_constant (TREE_OPERAND (exp, 0)));
2306 case CONSTRUCTOR:
2308 tree copy = copy_node (exp);
2309 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2310 tree tail;
2312 CONSTRUCTOR_ELTS (copy) = list;
2313 for (tail = list; tail; tail = TREE_CHAIN (tail))
2314 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2315 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2316 for (tail = list; tail; tail = TREE_CHAIN (tail))
2317 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2319 return copy;
2322 default:
2324 tree t;
2325 t = (*lang_hooks.expand_constant) (exp);
2326 if (t != exp)
2327 return copy_constant (t);
2328 else
2329 abort ();
2334 /* Subroutine of output_constant_def:
2335 No constant equal to EXP is known to have been output.
2336 Make a constant descriptor to enter EXP in the hash table.
2337 Assign the label number and construct RTL to refer to the
2338 constant's location in memory.
2339 Caller is responsible for updating the hash table. */
2341 static struct constant_descriptor_tree *
2342 build_constant_desc (tree exp)
2344 rtx symbol;
2345 rtx rtl;
2346 char label[256];
2347 int labelno;
2348 struct constant_descriptor_tree *desc;
2350 desc = ggc_alloc (sizeof (*desc));
2351 desc->value = copy_constant (exp);
2353 /* Create a string containing the label name, in LABEL. */
2354 labelno = const_labelno++;
2355 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2357 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2358 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2359 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2360 SYMBOL_REF_DECL (symbol) = desc->value;
2361 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2363 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2364 set_mem_attributes (rtl, exp, 1);
2365 set_mem_alias_set (rtl, 0);
2366 set_mem_alias_set (rtl, const_alias_set);
2368 /* Set flags or add text to the name to record information, such as
2369 that it is a local symbol. If the name is changed, the macro
2370 ASM_OUTPUT_LABELREF will have to know how to strip this
2371 information. This call might invalidate our local variable
2372 SYMBOL; we can't use it afterward. */
2374 (*targetm.encode_section_info) (exp, rtl, true);
2376 desc->rtl = rtl;
2378 return desc;
2381 /* Return an rtx representing a reference to constant data in memory
2382 for the constant expression EXP.
2384 If assembler code for such a constant has already been output,
2385 return an rtx to refer to it.
2386 Otherwise, output such a constant in memory
2387 and generate an rtx for it.
2389 If DEFER is nonzero, this constant can be deferred and output only
2390 if referenced in the function after all optimizations.
2392 `const_desc_table' records which constants already have label strings. */
2395 output_constant_def (tree exp, int defer)
2397 struct constant_descriptor_tree *desc;
2398 struct constant_descriptor_tree key;
2399 void **loc;
2401 /* Look up EXP in the table of constant descriptors. If we didn't find
2402 it, create a new one. */
2403 key.value = exp;
2404 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2406 desc = *loc;
2407 if (desc == 0)
2409 desc = build_constant_desc (exp);
2410 *loc = desc;
2413 maybe_output_constant_def_contents (desc, defer);
2414 return desc->rtl;
2417 /* Subroutine of output_constant_def: Decide whether or not we need to
2418 output the constant DESC now, and if so, do it. */
2419 static void
2420 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2421 int defer)
2423 rtx symbol = XEXP (desc->rtl, 0);
2424 tree exp = desc->value;
2426 if (flag_syntax_only)
2427 return;
2429 if (TREE_ASM_WRITTEN (exp))
2430 /* Already output; don't do it again. */
2431 return;
2433 /* We can always defer constants as long as the context allows
2434 doing so. */
2435 if (defer)
2437 /* Increment n_deferred_constants if it exists. It needs to be at
2438 least as large as the number of constants actually referred to
2439 by the function. If it's too small we'll stop looking too early
2440 and fail to emit constants; if it's too large we'll only look
2441 through the entire function when we could have stopped earlier. */
2442 if (cfun)
2443 n_deferred_constants++;
2444 return;
2447 output_constant_def_contents (symbol);
2450 /* We must output the constant data referred to by SYMBOL; do so. */
2452 static void
2453 output_constant_def_contents (rtx symbol)
2455 tree exp = SYMBOL_REF_DECL (symbol);
2456 const char *label = XSTR (symbol, 0);
2457 HOST_WIDE_INT size;
2459 /* Make sure any other constants whose addresses appear in EXP
2460 are assigned label numbers. */
2461 int reloc = compute_reloc_for_constant (exp);
2463 /* Align the location counter as required by EXP's data type. */
2464 int align = TYPE_ALIGN (TREE_TYPE (exp));
2465 #ifdef CONSTANT_ALIGNMENT
2466 align = CONSTANT_ALIGNMENT (exp, align);
2467 #endif
2469 output_addressed_constants (exp);
2471 /* We are no longer deferring this constant. */
2472 TREE_ASM_WRITTEN (exp) = 1;
2474 if (IN_NAMED_SECTION (exp))
2475 named_section (exp, NULL, reloc);
2476 else
2477 (*targetm.asm_out.select_section) (exp, reloc, align);
2479 if (align > BITS_PER_UNIT)
2481 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2484 size = int_size_in_bytes (TREE_TYPE (exp));
2485 if (TREE_CODE (exp) == STRING_CST)
2486 size = MAX (TREE_STRING_LENGTH (exp), size);
2488 /* Do any machine/system dependent processing of the constant. */
2489 #ifdef ASM_DECLARE_CONSTANT_NAME
2490 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2491 #else
2492 /* Standard thing is just output label for the constant. */
2493 ASM_OUTPUT_LABEL (asm_out_file, label);
2494 #endif /* ASM_DECLARE_CONSTANT_NAME */
2496 /* Output the value of EXP. */
2497 output_constant (exp, size, align);
2500 /* A constant which was deferred in its original location has been
2501 inserted by the RTL inliner into a different function. The
2502 current function's deferred constant count must be incremented. */
2503 void
2504 notice_rtl_inlining_of_deferred_constant (void)
2506 n_deferred_constants++;
2509 /* Look up EXP in the table of constant descriptors. Return the rtl
2510 if it has been emitted, else null. */
2513 lookup_constant_def (tree exp)
2515 struct constant_descriptor_tree *desc;
2516 struct constant_descriptor_tree key;
2518 key.value = exp;
2519 desc = htab_find (const_desc_htab, &key);
2521 return (desc ? desc->rtl : NULL_RTX);
2524 /* Used in the hash tables to avoid outputting the same constant
2525 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2526 are output once per function, not once per file. */
2527 /* ??? Only a few targets need per-function constant pools. Most
2528 can use one per-file pool. Should add a targetm bit to tell the
2529 difference. */
2531 struct rtx_constant_pool GTY(())
2533 /* Pointers to first and last constant in pool, as ordered by offset. */
2534 struct constant_descriptor_rtx *first;
2535 struct constant_descriptor_rtx *last;
2537 /* Hash facility for making memory-constants from constant rtl-expressions.
2538 It is used on RISC machines where immediate integer arguments and
2539 constant addresses are restricted so that such constants must be stored
2540 in memory. */
2541 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
2542 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_sym_htab;
2544 /* Current offset in constant pool (does not include any
2545 machine-specific header). */
2546 HOST_WIDE_INT offset;
2549 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
2551 struct constant_descriptor_rtx *next;
2552 rtx mem;
2553 rtx sym;
2554 rtx constant;
2555 HOST_WIDE_INT offset;
2556 hashval_t hash;
2557 enum machine_mode mode;
2558 unsigned int align;
2559 int labelno;
2560 int mark;
2563 /* Hash and compare functions for const_rtx_htab. */
2565 static hashval_t
2566 const_desc_rtx_hash (const void *ptr)
2568 const struct constant_descriptor_rtx *desc = ptr;
2569 return desc->hash;
2572 static int
2573 const_desc_rtx_eq (const void *a, const void *b)
2575 const struct constant_descriptor_rtx *x = a;
2576 const struct constant_descriptor_rtx *y = b;
2578 if (x->mode != y->mode)
2579 return 0;
2580 return rtx_equal_p (x->constant, y->constant);
2583 /* Hash and compare functions for const_rtx_sym_htab. */
2585 static hashval_t
2586 const_desc_rtx_sym_hash (const void *ptr)
2588 const struct constant_descriptor_rtx *desc = ptr;
2589 return htab_hash_string (XSTR (desc->sym, 0));
2592 static int
2593 const_desc_rtx_sym_eq (const void *a, const void *b)
2595 const struct constant_descriptor_rtx *x = a;
2596 const struct constant_descriptor_rtx *y = b;
2597 return XSTR (x->sym, 0) == XSTR (y->sym, 0);
2600 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2602 static int
2603 const_rtx_hash_1 (rtx *xp, void *data)
2605 unsigned HOST_WIDE_INT hwi;
2606 enum machine_mode mode;
2607 enum rtx_code code;
2608 hashval_t h, *hp;
2609 rtx x;
2611 x = *xp;
2612 code = GET_CODE (x);
2613 mode = GET_MODE (x);
2614 h = (hashval_t) code * 1048573 + mode;
2616 switch (code)
2618 case CONST_INT:
2619 hwi = INTVAL (x);
2620 fold_hwi:
2622 const int shift = sizeof (hashval_t) * CHAR_BIT;
2623 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
2624 int i;
2626 h ^= (hashval_t) hwi;
2627 for (i = 1; i < n; ++i)
2629 hwi >>= shift;
2630 h ^= (hashval_t) hwi;
2633 break;
2635 case CONST_DOUBLE:
2636 if (mode == VOIDmode)
2638 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
2639 goto fold_hwi;
2641 else
2642 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
2643 break;
2645 case SYMBOL_REF:
2646 h ^= htab_hash_string (XSTR (x, 0));
2647 break;
2649 case LABEL_REF:
2650 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
2651 break;
2653 case UNSPEC:
2654 case UNSPEC_VOLATILE:
2655 h = h * 251 + XINT (x, 1);
2656 break;
2658 default:
2659 break;
2662 hp = data;
2663 *hp = *hp * 509 + h;
2664 return 0;
2667 /* Compute a hash value for X, which should be a constant. */
2669 static hashval_t
2670 const_rtx_hash (rtx x)
2672 hashval_t h = 0;
2673 for_each_rtx (&x, const_rtx_hash_1, &h);
2674 return h;
2678 /* Initialize constant pool hashing for a new function. */
2680 void
2681 init_varasm_status (struct function *f)
2683 struct varasm_status *p;
2684 struct rtx_constant_pool *pool;
2686 p = ggc_alloc (sizeof (struct varasm_status));
2687 f->varasm = p;
2689 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
2690 p->pool = pool;
2691 p->deferred_constants = 0;
2693 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
2694 const_desc_rtx_eq, NULL);
2695 pool->const_rtx_sym_htab = htab_create_ggc (31, const_desc_rtx_sym_hash,
2696 const_desc_rtx_sym_eq, NULL);
2697 pool->first = pool->last = NULL;
2698 pool->offset = 0;
2701 /* Given a MINUS expression, simplify it if both sides
2702 include the same symbol. */
2705 simplify_subtraction (rtx x)
2707 rtx r = simplify_rtx (x);
2708 return r ? r : x;
2711 /* Given a constant rtx X, make (or find) a memory constant for its value
2712 and return a MEM rtx to refer to it in memory. */
2715 force_const_mem (enum machine_mode mode, rtx x)
2717 struct constant_descriptor_rtx *desc, tmp;
2718 struct rtx_constant_pool *pool = cfun->varasm->pool;
2719 char label[256];
2720 rtx def, symbol;
2721 hashval_t hash;
2722 unsigned int align;
2723 void **slot;
2725 /* If we're not allowed to drop X into the constant pool, don't. */
2726 if ((*targetm.cannot_force_const_mem) (x))
2727 return NULL_RTX;
2729 /* Lookup the value in the hashtable. */
2730 tmp.constant = x;
2731 tmp.mode = mode;
2732 hash = const_rtx_hash (x);
2733 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
2734 desc = *slot;
2736 /* If the constant was already present, return its memory. */
2737 if (desc)
2738 return copy_rtx (desc->mem);
2740 /* Otherwise, create a new descriptor. */
2741 desc = ggc_alloc (sizeof (*desc));
2742 *slot = desc;
2744 /* Align the location counter as required by EXP's data type. */
2745 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2746 #ifdef CONSTANT_ALIGNMENT
2748 tree type = (*lang_hooks.types.type_for_mode) (mode, 0);
2749 if (type != NULL_TREE)
2750 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2752 #endif
2754 pool->offset += (align / BITS_PER_UNIT) - 1;
2755 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
2757 desc->next = NULL;
2758 desc->constant = tmp.constant;
2759 desc->offset = pool->offset;
2760 desc->hash = hash;
2761 desc->mode = mode;
2762 desc->align = align;
2763 desc->labelno = const_labelno;
2764 desc->mark = 0;
2766 pool->offset += GET_MODE_SIZE (mode);
2767 if (pool->last)
2768 pool->last->next = desc;
2769 else
2770 pool->first = pool->last = desc;
2771 pool->last = desc;
2773 /* Create a string containing the label name, in LABEL. */
2774 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2775 ++const_labelno;
2777 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
2778 the constants pool. */
2779 desc->sym = symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2780 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2781 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2782 current_function_uses_const_pool = 1;
2784 /* Insert the descriptor into the symbol cross-reference table too. */
2785 slot = htab_find_slot (pool->const_rtx_sym_htab, desc, INSERT);
2786 if (*slot)
2787 abort ();
2788 *slot = desc;
2790 /* Construct the MEM. */
2791 desc->mem = def = gen_rtx_MEM (mode, symbol);
2792 set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
2793 RTX_UNCHANGING_P (def) = 1;
2795 /* If we're dropping a label to the constant pool, make sure we
2796 don't delete it. */
2797 if (GET_CODE (x) == LABEL_REF)
2798 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
2800 return copy_rtx (def);
2803 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2804 the corresponding constant_descriptor_rtx structure. */
2806 static struct constant_descriptor_rtx *
2807 find_pool_constant (struct rtx_constant_pool *pool, rtx sym)
2809 struct constant_descriptor_rtx tmp;
2810 tmp.sym = sym;
2811 return htab_find (pool->const_rtx_sym_htab, &tmp);
2814 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2817 get_pool_constant (rtx addr)
2819 return find_pool_constant (cfun->varasm->pool, addr)->constant;
2822 /* Given a constant pool SYMBOL_REF, return the corresponding constant
2823 and whether it has been output or not. */
2826 get_pool_constant_mark (rtx addr, bool *pmarked)
2828 struct constant_descriptor_rtx *desc;
2830 desc = find_pool_constant (cfun->varasm->pool, addr);
2831 *pmarked = (desc->mark != 0);
2832 return desc->constant;
2835 /* Likewise, but for the constant pool of a specific function. */
2838 get_pool_constant_for_function (struct function *f, rtx addr)
2840 return find_pool_constant (f->varasm->pool, addr)->constant;
2843 /* Similar, return the mode. */
2845 enum machine_mode
2846 get_pool_mode (rtx addr)
2848 return find_pool_constant (cfun->varasm->pool, addr)->mode;
2851 enum machine_mode
2852 get_pool_mode_for_function (struct function *f, rtx addr)
2854 return find_pool_constant (f->varasm->pool, addr)->mode;
2857 /* Similar, return the offset in the constant pool. */
2860 get_pool_offset (rtx addr)
2862 return find_pool_constant (cfun->varasm->pool, addr)->offset;
2865 /* Return the size of the constant pool. */
2868 get_pool_size (void)
2870 return cfun->varasm->pool->offset;
2873 /* Worker function for output_constant_pool_1. Emit assembly for X
2874 in MODE with known alignment ALIGN. */
2876 static void
2877 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
2879 switch (GET_MODE_CLASS (mode))
2881 case MODE_FLOAT:
2882 if (GET_CODE (x) != CONST_DOUBLE)
2883 abort ();
2884 else
2886 REAL_VALUE_TYPE r;
2887 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
2888 assemble_real (r, mode, align);
2890 break;
2892 case MODE_INT:
2893 case MODE_PARTIAL_INT:
2894 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
2895 break;
2897 case MODE_VECTOR_FLOAT:
2898 case MODE_VECTOR_INT:
2900 int i, units;
2901 enum machine_mode submode = GET_MODE_INNER (mode);
2902 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
2904 if (GET_CODE (x) != CONST_VECTOR)
2905 abort ();
2906 units = CONST_VECTOR_NUNITS (x);
2908 for (i = 0; i < units; i++)
2910 rtx elt = CONST_VECTOR_ELT (x, i);
2911 output_constant_pool_2 (submode, elt, i ? subalign : align);
2914 break;
2916 default:
2917 abort ();
2921 /* Worker function for output_constant_pool. Emit POOL. */
2923 static void
2924 output_constant_pool_1 (struct constant_descriptor_rtx *desc)
2926 rtx x, tmp;
2928 if (!desc->mark)
2929 return;
2930 x = desc->constant;
2932 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2933 whose CODE_LABEL has been deleted. This can occur if a jump table
2934 is eliminated by optimization. If so, write a constant of zero
2935 instead. Note that this can also happen by turning the
2936 CODE_LABEL into a NOTE. */
2937 /* ??? This seems completely and utterly wrong. Certainly it's
2938 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
2939 functioning even with INSN_DELETED_P and friends. */
2941 tmp = x;
2942 switch (GET_CODE (x))
2944 case CONST:
2945 if (GET_CODE (XEXP (x, 0)) != PLUS
2946 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
2947 break;
2948 tmp = XEXP (XEXP (x, 0), 0);
2949 /* FALLTHRU */
2951 case LABEL_REF:
2952 tmp = XEXP (x, 0);
2953 if (INSN_DELETED_P (tmp)
2954 || (GET_CODE (tmp) == NOTE
2955 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
2957 abort ();
2958 x = const0_rtx;
2960 break;
2962 default:
2963 break;
2966 /* First switch to correct section. */
2967 (*targetm.asm_out.select_rtx_section) (desc->mode, x, desc->align);
2969 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2970 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
2971 desc->align, desc->labelno, done);
2972 #endif
2974 assemble_align (desc->align);
2976 /* Output the label. */
2977 (*targetm.asm_out.internal_label) (asm_out_file, "LC", desc->labelno);
2979 /* Output the data. */
2980 output_constant_pool_2 (desc->mode, x, desc->align);
2982 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
2983 sections have proper size. */
2984 if (desc->align > GET_MODE_BITSIZE (desc->mode)
2985 && in_section == in_named
2986 && get_named_section_flags (in_named_name) & SECTION_MERGE)
2987 assemble_align (desc->align);
2989 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2990 done:
2991 #endif
2992 return;
2995 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
2996 to as used. Emit referenced deferred strings. This function can
2997 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
2999 static int
3000 mark_constant (rtx *current_rtx, void *data)
3002 struct rtx_constant_pool *pool = data;
3003 rtx x = *current_rtx;
3005 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3006 return 0;
3008 if (CONSTANT_POOL_ADDRESS_P (x))
3010 struct constant_descriptor_rtx *desc = find_pool_constant (pool, x);
3011 if (desc->mark == 0)
3013 desc->mark = 1;
3014 for_each_rtx (&desc->constant, mark_constant, pool);
3017 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3019 tree exp = SYMBOL_REF_DECL (x);
3020 if (!TREE_ASM_WRITTEN (exp))
3022 n_deferred_constants--;
3023 output_constant_def_contents (x);
3027 return -1;
3030 /* Look through appropriate parts of INSN, marking all entries in the
3031 constant pool which are actually being used. Entries that are only
3032 referenced by other constants are also marked as used. Emit
3033 deferred strings that are used. */
3035 static void
3036 mark_constants (struct rtx_constant_pool *pool, rtx insn)
3038 if (!INSN_P (insn))
3039 return;
3041 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3042 insns, not any notes that may be attached. We don't want to mark
3043 a constant just because it happens to appear in a REG_EQUIV note. */
3044 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3046 rtx seq = PATTERN (insn);
3047 int i, n = XVECLEN (seq, 0);
3048 for (i = 0; i < n; ++i)
3050 rtx subinsn = XVECEXP (seq, 0, i);
3051 if (INSN_P (subinsn))
3052 for_each_rtx (&PATTERN (subinsn), mark_constant, pool);
3055 else
3056 for_each_rtx (&PATTERN (insn), mark_constant, pool);
3059 /* Look through the instructions for this function, and mark all the
3060 entries in POOL which are actually being used. Emit deferred constants
3061 which have indeed been used. */
3063 static void
3064 mark_constant_pool (struct rtx_constant_pool *pool)
3066 rtx insn, link;
3068 if (pool->first == 0 && n_deferred_constants == 0)
3069 return;
3071 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3072 mark_constants (pool, insn);
3074 for (link = current_function_epilogue_delay_list;
3075 link;
3076 link = XEXP (link, 1))
3077 mark_constants (pool, XEXP (link, 0));
3080 /* Write all the constants in the constant pool. */
3082 void
3083 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3084 tree fndecl ATTRIBUTE_UNUSED)
3086 struct rtx_constant_pool *pool = cfun->varasm->pool;
3087 struct constant_descriptor_rtx *desc;
3089 /* It is possible for gcc to call force_const_mem and then to later
3090 discard the instructions which refer to the constant. In such a
3091 case we do not need to output the constant. */
3092 mark_constant_pool (pool);
3094 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3095 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3096 #endif
3098 for (desc = pool->first; desc ; desc = desc->next)
3099 output_constant_pool_1 (desc);
3101 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3102 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3103 #endif
3106 /* Determine what kind of relocations EXP may need. */
3109 compute_reloc_for_constant (tree exp)
3111 int reloc = 0, reloc2;
3112 tree tem;
3114 /* Give the front-end a chance to convert VALUE to something that
3115 looks more like a constant to the back-end. */
3116 exp = (*lang_hooks.expand_constant) (exp);
3118 switch (TREE_CODE (exp))
3120 case ADDR_EXPR:
3121 case FDESC_EXPR:
3122 /* Go inside any operations that get_inner_reference can handle and see
3123 if what's inside is a constant: no need to do anything here for
3124 addresses of variables or functions. */
3125 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3126 tem = TREE_OPERAND (tem, 0))
3129 if (TREE_PUBLIC (tem))
3130 reloc |= 2;
3131 else
3132 reloc |= 1;
3133 break;
3135 case PLUS_EXPR:
3136 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3137 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3138 break;
3140 case MINUS_EXPR:
3141 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3142 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3143 /* The difference of two local labels is computable at link time. */
3144 if (reloc == 1 && reloc2 == 1)
3145 reloc = 0;
3146 else
3147 reloc |= reloc2;
3148 break;
3150 case NOP_EXPR:
3151 case CONVERT_EXPR:
3152 case NON_LVALUE_EXPR:
3153 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3154 break;
3156 case CONSTRUCTOR:
3157 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3158 if (TREE_VALUE (tem) != 0)
3159 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3161 break;
3163 default:
3164 break;
3166 return reloc;
3169 /* Find all the constants whose addresses are referenced inside of EXP,
3170 and make sure assembler code with a label has been output for each one.
3171 Indicate whether an ADDR_EXPR has been encountered. */
3173 static void
3174 output_addressed_constants (tree exp)
3176 tree tem;
3178 /* Give the front-end a chance to convert VALUE to something that
3179 looks more like a constant to the back-end. */
3180 exp = (*lang_hooks.expand_constant) (exp);
3182 switch (TREE_CODE (exp))
3184 case ADDR_EXPR:
3185 case FDESC_EXPR:
3186 /* Go inside any operations that get_inner_reference can handle and see
3187 if what's inside is a constant: no need to do anything here for
3188 addresses of variables or functions. */
3189 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3190 tem = TREE_OPERAND (tem, 0))
3193 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
3194 || TREE_CODE (tem) == CONSTRUCTOR)
3195 output_constant_def (tem, 0);
3196 break;
3198 case PLUS_EXPR:
3199 case MINUS_EXPR:
3200 output_addressed_constants (TREE_OPERAND (exp, 1));
3201 /* Fall through. */
3203 case NOP_EXPR:
3204 case CONVERT_EXPR:
3205 case NON_LVALUE_EXPR:
3206 output_addressed_constants (TREE_OPERAND (exp, 0));
3207 break;
3209 case CONSTRUCTOR:
3210 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3211 if (TREE_VALUE (tem) != 0)
3212 output_addressed_constants (TREE_VALUE (tem));
3214 break;
3216 default:
3217 break;
3221 /* Return nonzero if VALUE is a valid constant-valued expression
3222 for use in initializing a static variable; one that can be an
3223 element of a "constant" initializer.
3225 Return null_pointer_node if the value is absolute;
3226 if it is relocatable, return the variable that determines the relocation.
3227 We assume that VALUE has been folded as much as possible;
3228 therefore, we do not need to check for such things as
3229 arithmetic-combinations of integers. */
3231 tree
3232 initializer_constant_valid_p (tree value, tree endtype)
3234 /* Give the front-end a chance to convert VALUE to something that
3235 looks more like a constant to the back-end. */
3236 value = (*lang_hooks.expand_constant) (value);
3238 switch (TREE_CODE (value))
3240 case CONSTRUCTOR:
3241 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3242 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3243 && TREE_CONSTANT (value)
3244 && CONSTRUCTOR_ELTS (value))
3246 tree elt;
3247 bool absolute = true;
3249 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3251 tree reloc;
3252 value = TREE_VALUE (elt);
3253 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3254 if (!reloc)
3255 return NULL_TREE;
3256 if (reloc != null_pointer_node)
3257 absolute = false;
3259 /* For a non-absolute relocation, there is no single
3260 variable that can be "the variable that determines the
3261 relocation." */
3262 return absolute ? null_pointer_node : error_mark_node;
3265 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3267 case INTEGER_CST:
3268 case VECTOR_CST:
3269 case REAL_CST:
3270 case STRING_CST:
3271 case COMPLEX_CST:
3272 return null_pointer_node;
3274 case ADDR_EXPR:
3275 case FDESC_EXPR:
3276 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
3278 case VIEW_CONVERT_EXPR:
3279 case NON_LVALUE_EXPR:
3280 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3282 case CONVERT_EXPR:
3283 case NOP_EXPR:
3284 /* Allow conversions between pointer types. */
3285 if (POINTER_TYPE_P (TREE_TYPE (value))
3286 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3287 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3289 /* Allow conversions between real types. */
3290 if (FLOAT_TYPE_P (TREE_TYPE (value))
3291 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3292 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3294 /* Allow length-preserving conversions between integer types. */
3295 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3296 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3297 && (TYPE_PRECISION (TREE_TYPE (value))
3298 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3299 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3301 /* Allow conversions between other integer types only if
3302 explicit value. */
3303 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3304 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3306 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3307 endtype);
3308 if (inner == null_pointer_node)
3309 return null_pointer_node;
3310 break;
3313 /* Allow (int) &foo provided int is as wide as a pointer. */
3314 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3315 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3316 && (TYPE_PRECISION (TREE_TYPE (value))
3317 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3318 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3319 endtype);
3321 /* Likewise conversions from int to pointers, but also allow
3322 conversions from 0. */
3323 if ((POINTER_TYPE_P (TREE_TYPE (value))
3324 || TREE_CODE (TREE_TYPE (value)) == OFFSET_TYPE)
3325 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3327 if (integer_zerop (TREE_OPERAND (value, 0)))
3328 return null_pointer_node;
3329 else if (TYPE_PRECISION (TREE_TYPE (value))
3330 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
3331 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3332 endtype);
3335 /* Allow conversions to union types if the value inside is okay. */
3336 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
3337 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3338 endtype);
3339 break;
3341 case PLUS_EXPR:
3342 if (! INTEGRAL_TYPE_P (endtype)
3343 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3345 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3346 endtype);
3347 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3348 endtype);
3349 /* If either term is absolute, use the other terms relocation. */
3350 if (valid0 == null_pointer_node)
3351 return valid1;
3352 if (valid1 == null_pointer_node)
3353 return valid0;
3355 break;
3357 case MINUS_EXPR:
3358 if (! INTEGRAL_TYPE_P (endtype)
3359 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3361 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3362 endtype);
3363 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3364 endtype);
3365 /* Win if second argument is absolute. */
3366 if (valid1 == null_pointer_node)
3367 return valid0;
3368 /* Win if both arguments have the same relocation.
3369 Then the value is absolute. */
3370 if (valid0 == valid1 && valid0 != 0)
3371 return null_pointer_node;
3373 /* Since GCC guarantees that string constants are unique in the
3374 generated code, a subtraction between two copies of the same
3375 constant string is absolute. */
3376 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
3377 valid1 && TREE_CODE (valid1) == STRING_CST &&
3378 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
3379 return null_pointer_node;
3382 /* Support differences between labels. */
3383 if (INTEGRAL_TYPE_P (endtype))
3385 tree op0, op1;
3386 op0 = TREE_OPERAND (value, 0);
3387 op1 = TREE_OPERAND (value, 1);
3389 /* Like STRIP_NOPS except allow the operand mode to widen.
3390 This works around a feature of fold that simplifies
3391 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3392 that the narrower operation is cheaper. */
3394 while (TREE_CODE (op0) == NOP_EXPR
3395 || TREE_CODE (op0) == CONVERT_EXPR
3396 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3398 tree inner = TREE_OPERAND (op0, 0);
3399 if (inner == error_mark_node
3400 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3401 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3402 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3403 break;
3404 op0 = inner;
3407 while (TREE_CODE (op1) == NOP_EXPR
3408 || TREE_CODE (op1) == CONVERT_EXPR
3409 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3411 tree inner = TREE_OPERAND (op1, 0);
3412 if (inner == error_mark_node
3413 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3414 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3415 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3416 break;
3417 op1 = inner;
3420 if (TREE_CODE (op0) == ADDR_EXPR
3421 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
3422 && TREE_CODE (op1) == ADDR_EXPR
3423 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
3424 return null_pointer_node;
3426 break;
3428 default:
3429 break;
3432 return 0;
3435 /* Output assembler code for constant EXP to FILE, with no label.
3436 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3437 Assumes output_addressed_constants has been done on EXP already.
3439 Generate exactly SIZE bytes of assembler data, padding at the end
3440 with zeros if necessary. SIZE must always be specified.
3442 SIZE is important for structure constructors,
3443 since trailing members may have been omitted from the constructor.
3444 It is also important for initialization of arrays from string constants
3445 since the full length of the string constant might not be wanted.
3446 It is also needed for initialization of unions, where the initializer's
3447 type is just one member, and that may not be as long as the union.
3449 There a case in which we would fail to output exactly SIZE bytes:
3450 for a structure constructor that wants to produce more than SIZE bytes.
3451 But such constructors will never be generated for any possible input.
3453 ALIGN is the alignment of the data in bits. */
3455 void
3456 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3458 enum tree_code code;
3459 unsigned HOST_WIDE_INT thissize;
3461 /* Some front-ends use constants other than the standard language-independent
3462 varieties, but which may still be output directly. Give the front-end a
3463 chance to convert EXP to a language-independent representation. */
3464 exp = (*lang_hooks.expand_constant) (exp);
3466 if (size == 0 || flag_syntax_only)
3467 return;
3469 /* Eliminate any conversions since we'll be outputting the underlying
3470 constant. */
3471 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3472 || TREE_CODE (exp) == NON_LVALUE_EXPR
3473 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3474 exp = TREE_OPERAND (exp, 0);
3476 code = TREE_CODE (TREE_TYPE (exp));
3477 thissize = int_size_in_bytes (TREE_TYPE (exp));
3479 /* Allow a constructor with no elements for any data type.
3480 This means to fill the space with zeros. */
3481 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3483 assemble_zeros (size);
3484 return;
3487 if (TREE_CODE (exp) == FDESC_EXPR)
3489 #ifdef ASM_OUTPUT_FDESC
3490 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3491 tree decl = TREE_OPERAND (exp, 0);
3492 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3493 #else
3494 abort ();
3495 #endif
3496 return;
3499 /* Now output the underlying data. If we've handling the padding, return.
3500 Otherwise, break and ensure THISSIZE is the size written. */
3501 switch (code)
3503 case CHAR_TYPE:
3504 case BOOLEAN_TYPE:
3505 case INTEGER_TYPE:
3506 case ENUMERAL_TYPE:
3507 case POINTER_TYPE:
3508 case REFERENCE_TYPE:
3509 case OFFSET_TYPE:
3510 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3511 EXPAND_INITIALIZER),
3512 size, align, 0))
3513 error ("initializer for integer value is too complicated");
3514 break;
3516 case REAL_TYPE:
3517 if (TREE_CODE (exp) != REAL_CST)
3518 error ("initializer for floating value is not a floating constant");
3520 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3521 break;
3523 case COMPLEX_TYPE:
3524 output_constant (TREE_REALPART (exp), thissize / 2, align);
3525 output_constant (TREE_IMAGPART (exp), thissize / 2,
3526 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3527 break;
3529 case ARRAY_TYPE:
3530 case VECTOR_TYPE:
3531 if (TREE_CODE (exp) == CONSTRUCTOR)
3533 output_constructor (exp, size, align);
3534 return;
3536 else if (TREE_CODE (exp) == STRING_CST)
3538 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3539 size);
3540 assemble_string (TREE_STRING_POINTER (exp), thissize);
3542 else if (TREE_CODE (exp) == VECTOR_CST)
3544 int elt_size;
3545 tree link;
3546 unsigned int nalign;
3547 enum machine_mode inner;
3549 inner = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (exp)));
3550 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3552 elt_size = GET_MODE_UNIT_SIZE (TYPE_MODE (TREE_TYPE (exp)));
3554 link = TREE_VECTOR_CST_ELTS (exp);
3555 output_constant (TREE_VALUE (link), elt_size, align);
3556 while ((link = TREE_CHAIN (link)) != NULL)
3557 output_constant (TREE_VALUE (link), elt_size, nalign);
3559 else
3560 abort ();
3561 break;
3563 case RECORD_TYPE:
3564 case UNION_TYPE:
3565 if (TREE_CODE (exp) == CONSTRUCTOR)
3566 output_constructor (exp, size, align);
3567 else
3568 abort ();
3569 return;
3571 case SET_TYPE:
3572 if (TREE_CODE (exp) == INTEGER_CST)
3573 assemble_integer (expand_expr (exp, NULL_RTX,
3574 VOIDmode, EXPAND_INITIALIZER),
3575 thissize, align, 1);
3576 else if (TREE_CODE (exp) == CONSTRUCTOR)
3578 unsigned char *buffer = alloca (thissize);
3579 if (get_set_constructor_bytes (exp, buffer, thissize))
3580 abort ();
3581 assemble_string ((char *) buffer, thissize);
3583 else
3584 error ("unknown set constructor type");
3585 return;
3587 case ERROR_MARK:
3588 return;
3590 default:
3591 abort ();
3594 if (size > thissize)
3595 assemble_zeros (size - thissize);
3599 /* Subroutine of output_constructor, used for computing the size of
3600 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3601 type with an unspecified upper bound. */
3603 static unsigned HOST_WIDE_INT
3604 array_size_for_constructor (tree val)
3606 tree max_index, i;
3608 /* This code used to attempt to handle string constants that are not
3609 arrays of single-bytes, but nothing else does, so there's no point in
3610 doing it here. */
3611 if (TREE_CODE (val) == STRING_CST)
3612 return TREE_STRING_LENGTH (val);
3614 max_index = NULL_TREE;
3615 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3617 tree index = TREE_PURPOSE (i);
3619 if (TREE_CODE (index) == RANGE_EXPR)
3620 index = TREE_OPERAND (index, 1);
3621 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3622 max_index = index;
3625 if (max_index == NULL_TREE)
3626 return 0;
3628 /* Compute the total number of array elements. */
3629 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3630 convert (sizetype,
3631 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3632 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3634 /* Multiply by the array element unit size to find number of bytes. */
3635 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3637 return tree_low_cst (i, 1);
3640 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3641 Generate at least SIZE bytes, padding if necessary. */
3643 static void
3644 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3645 unsigned int align)
3647 tree type = TREE_TYPE (exp);
3648 tree link, field = 0;
3649 tree min_index = 0;
3650 /* Number of bytes output or skipped so far.
3651 In other words, current position within the constructor. */
3652 HOST_WIDE_INT total_bytes = 0;
3653 /* Nonzero means BYTE contains part of a byte, to be output. */
3654 int byte_buffer_in_use = 0;
3655 int byte = 0;
3657 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3658 abort ();
3660 if (TREE_CODE (type) == RECORD_TYPE)
3661 field = TYPE_FIELDS (type);
3663 if (TREE_CODE (type) == ARRAY_TYPE
3664 && TYPE_DOMAIN (type) != 0)
3665 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3667 /* As LINK goes through the elements of the constant,
3668 FIELD goes through the structure fields, if the constant is a structure.
3669 if the constant is a union, then we override this,
3670 by getting the field from the TREE_LIST element.
3671 But the constant could also be an array. Then FIELD is zero.
3673 There is always a maximum of one element in the chain LINK for unions
3674 (even if the initializer in a source program incorrectly contains
3675 more one). */
3676 for (link = CONSTRUCTOR_ELTS (exp);
3677 link;
3678 link = TREE_CHAIN (link),
3679 field = field ? TREE_CHAIN (field) : 0)
3681 tree val = TREE_VALUE (link);
3682 tree index = 0;
3684 /* The element in a union constructor specifies the proper field
3685 or index. */
3686 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3687 || TREE_CODE (type) == QUAL_UNION_TYPE)
3688 && TREE_PURPOSE (link) != 0)
3689 field = TREE_PURPOSE (link);
3691 else if (TREE_CODE (type) == ARRAY_TYPE)
3692 index = TREE_PURPOSE (link);
3694 #ifdef ASM_COMMENT_START
3695 if (field && flag_verbose_asm)
3696 fprintf (asm_out_file, "%s %s:\n",
3697 ASM_COMMENT_START,
3698 DECL_NAME (field)
3699 ? IDENTIFIER_POINTER (DECL_NAME (field))
3700 : "<anonymous>");
3701 #endif
3703 /* Eliminate the marker that makes a cast not be an lvalue. */
3704 if (val != 0)
3705 STRIP_NOPS (val);
3707 if (index && TREE_CODE (index) == RANGE_EXPR)
3709 unsigned HOST_WIDE_INT fieldsize
3710 = int_size_in_bytes (TREE_TYPE (type));
3711 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3712 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3713 HOST_WIDE_INT index;
3714 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3716 for (index = lo_index; index <= hi_index; index++)
3718 /* Output the element's initial value. */
3719 if (val == 0)
3720 assemble_zeros (fieldsize);
3721 else
3722 output_constant (val, fieldsize, align2);
3724 /* Count its size. */
3725 total_bytes += fieldsize;
3728 else if (field == 0 || !DECL_BIT_FIELD (field))
3730 /* An element that is not a bit-field. */
3732 unsigned HOST_WIDE_INT fieldsize;
3733 /* Since this structure is static,
3734 we know the positions are constant. */
3735 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
3736 unsigned int align2;
3738 if (index != 0)
3739 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
3740 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
3742 /* Output any buffered-up bit-fields preceding this element. */
3743 if (byte_buffer_in_use)
3745 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3746 total_bytes++;
3747 byte_buffer_in_use = 0;
3750 /* Advance to offset of this element.
3751 Note no alignment needed in an array, since that is guaranteed
3752 if each element has the proper size. */
3753 if ((field != 0 || index != 0) && pos != total_bytes)
3755 assemble_zeros (pos - total_bytes);
3756 total_bytes = pos;
3759 /* Find the alignment of this element. */
3760 align2 = min_align (align, BITS_PER_UNIT * pos);
3762 /* Determine size this element should occupy. */
3763 if (field)
3765 fieldsize = 0;
3767 /* If this is an array with an unspecified upper bound,
3768 the initializer determines the size. */
3769 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
3770 but we cannot do this until the deprecated support for
3771 initializing zero-length array members is removed. */
3772 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
3773 && TYPE_DOMAIN (TREE_TYPE (field))
3774 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
3776 fieldsize = array_size_for_constructor (val);
3777 /* Given a non-empty initialization, this field had
3778 better be last. */
3779 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
3780 abort ();
3782 else if (DECL_SIZE_UNIT (field))
3784 /* ??? This can't be right. If the decl size overflows
3785 a host integer we will silently emit no data. */
3786 if (host_integerp (DECL_SIZE_UNIT (field), 1))
3787 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
3790 else
3791 fieldsize = int_size_in_bytes (TREE_TYPE (type));
3793 /* Output the element's initial value. */
3794 if (val == 0)
3795 assemble_zeros (fieldsize);
3796 else
3797 output_constant (val, fieldsize, align2);
3799 /* Count its size. */
3800 total_bytes += fieldsize;
3802 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3803 error ("invalid initial value for member `%s'",
3804 IDENTIFIER_POINTER (DECL_NAME (field)));
3805 else
3807 /* Element that is a bit-field. */
3809 HOST_WIDE_INT next_offset = int_bit_position (field);
3810 HOST_WIDE_INT end_offset
3811 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
3813 if (val == 0)
3814 val = integer_zero_node;
3816 /* If this field does not start in this (or, next) byte,
3817 skip some bytes. */
3818 if (next_offset / BITS_PER_UNIT != total_bytes)
3820 /* Output remnant of any bit field in previous bytes. */
3821 if (byte_buffer_in_use)
3823 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3824 total_bytes++;
3825 byte_buffer_in_use = 0;
3828 /* If still not at proper byte, advance to there. */
3829 if (next_offset / BITS_PER_UNIT != total_bytes)
3831 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3832 total_bytes = next_offset / BITS_PER_UNIT;
3836 if (! byte_buffer_in_use)
3837 byte = 0;
3839 /* We must split the element into pieces that fall within
3840 separate bytes, and combine each byte with previous or
3841 following bit-fields. */
3843 /* next_offset is the offset n fbits from the beginning of
3844 the structure to the next bit of this element to be processed.
3845 end_offset is the offset of the first bit past the end of
3846 this element. */
3847 while (next_offset < end_offset)
3849 int this_time;
3850 int shift;
3851 HOST_WIDE_INT value;
3852 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
3853 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
3855 /* Advance from byte to byte
3856 within this element when necessary. */
3857 while (next_byte != total_bytes)
3859 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3860 total_bytes++;
3861 byte = 0;
3864 /* Number of bits we can process at once
3865 (all part of the same byte). */
3866 this_time = MIN (end_offset - next_offset,
3867 BITS_PER_UNIT - next_bit);
3868 if (BYTES_BIG_ENDIAN)
3870 /* On big-endian machine, take the most significant bits
3871 first (of the bits that are significant)
3872 and put them into bytes from the most significant end. */
3873 shift = end_offset - next_offset - this_time;
3875 /* Don't try to take a bunch of bits that cross
3876 the word boundary in the INTEGER_CST. We can
3877 only select bits from the LOW or HIGH part
3878 not from both. */
3879 if (shift < HOST_BITS_PER_WIDE_INT
3880 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3882 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
3883 shift = HOST_BITS_PER_WIDE_INT;
3886 /* Now get the bits from the appropriate constant word. */
3887 if (shift < HOST_BITS_PER_WIDE_INT)
3888 value = TREE_INT_CST_LOW (val);
3889 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3891 value = TREE_INT_CST_HIGH (val);
3892 shift -= HOST_BITS_PER_WIDE_INT;
3894 else
3895 abort ();
3897 /* Get the result. This works only when:
3898 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
3899 byte |= (((value >> shift)
3900 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
3901 << (BITS_PER_UNIT - this_time - next_bit));
3903 else
3905 /* On little-endian machines,
3906 take first the least significant bits of the value
3907 and pack them starting at the least significant
3908 bits of the bytes. */
3909 shift = next_offset - int_bit_position (field);
3911 /* Don't try to take a bunch of bits that cross
3912 the word boundary in the INTEGER_CST. We can
3913 only select bits from the LOW or HIGH part
3914 not from both. */
3915 if (shift < HOST_BITS_PER_WIDE_INT
3916 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3917 this_time = (HOST_BITS_PER_WIDE_INT - shift);
3919 /* Now get the bits from the appropriate constant word. */
3920 if (shift < HOST_BITS_PER_WIDE_INT)
3921 value = TREE_INT_CST_LOW (val);
3922 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3924 value = TREE_INT_CST_HIGH (val);
3925 shift -= HOST_BITS_PER_WIDE_INT;
3927 else
3928 abort ();
3930 /* Get the result. This works only when:
3931 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
3932 byte |= (((value >> shift)
3933 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
3934 << next_bit);
3937 next_offset += this_time;
3938 byte_buffer_in_use = 1;
3943 if (byte_buffer_in_use)
3945 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3946 total_bytes++;
3949 if ((unsigned HOST_WIDE_INT)total_bytes < size)
3950 assemble_zeros (size - total_bytes);
3953 /* This TREE_LIST contains any weak symbol declarations waiting
3954 to be emitted. */
3955 static GTY(()) tree weak_decls;
3957 /* Mark DECL as weak. */
3959 static void
3960 mark_weak (tree decl)
3962 DECL_WEAK (decl) = 1;
3964 if (DECL_RTL_SET_P (decl)
3965 && GET_CODE (DECL_RTL (decl)) == MEM
3966 && XEXP (DECL_RTL (decl), 0)
3967 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
3968 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
3971 /* Merge weak status between NEWDECL and OLDDECL. */
3973 void
3974 merge_weak (tree newdecl, tree olddecl)
3976 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
3977 return;
3979 if (DECL_WEAK (newdecl))
3981 tree wd;
3983 /* NEWDECL is weak, but OLDDECL is not. */
3985 /* If we already output the OLDDECL, we're in trouble; we can't
3986 go back and make it weak. This error cannot caught in
3987 declare_weak because the NEWDECL and OLDDECL was not yet
3988 been merged; therefore, TREE_ASM_WRITTEN was not set. */
3989 if (TREE_ASM_WRITTEN (olddecl))
3990 error ("%Jweak declaration of '%D' must precede definition",
3991 newdecl, newdecl);
3993 /* If we've already generated rtl referencing OLDDECL, we may
3994 have done so in a way that will not function properly with
3995 a weak symbol. */
3996 else if (TREE_USED (olddecl)
3997 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
3998 warning ("%Jweak declaration of '%D' after first use results "
3999 "in unspecified behavior", newdecl, newdecl);
4001 if (SUPPORTS_WEAK)
4003 /* We put the NEWDECL on the weak_decls list at some point.
4004 Replace it with the OLDDECL. */
4005 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4006 if (TREE_VALUE (wd) == newdecl)
4008 TREE_VALUE (wd) = olddecl;
4009 break;
4011 /* We may not find the entry on the list. If NEWDECL is a
4012 weak alias, then we will have already called
4013 globalize_decl to remove the entry; in that case, we do
4014 not need to do anything. */
4017 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4018 mark_weak (olddecl);
4020 else
4021 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4022 weak. Just update NEWDECL to indicate that it's weak too. */
4023 mark_weak (newdecl);
4026 /* Declare DECL to be a weak symbol. */
4028 void
4029 declare_weak (tree decl)
4031 if (! TREE_PUBLIC (decl))
4032 error ("%Jweak declaration of '%D' must be public", decl, decl);
4033 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4034 error ("%Jweak declaration of '%D' must precede definition", decl, decl);
4035 else if (SUPPORTS_WEAK)
4037 if (! DECL_WEAK (decl))
4038 weak_decls = tree_cons (NULL, decl, weak_decls);
4040 else
4041 warning ("%Jweak declaration of '%D' not supported", decl, decl);
4043 mark_weak (decl);
4046 /* Emit any pending weak declarations. */
4048 void
4049 weak_finish (void)
4051 tree t;
4053 for (t = weak_decls; t; t = TREE_CHAIN (t))
4055 tree decl = TREE_VALUE (t);
4056 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4057 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4058 #endif
4060 if (! TREE_USED (decl))
4061 continue;
4063 #ifdef ASM_WEAKEN_DECL
4064 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4065 #else
4066 #ifdef ASM_WEAKEN_LABEL
4067 ASM_WEAKEN_LABEL (asm_out_file, name);
4068 #else
4069 #ifdef ASM_OUTPUT_WEAK_ALIAS
4070 warning ("only weak aliases are supported in this configuration");
4071 return;
4072 #endif
4073 #endif
4074 #endif
4078 /* Emit the assembly bits to indicate that DECL is globally visible. */
4080 static void
4081 globalize_decl (tree decl)
4083 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4085 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4086 if (DECL_WEAK (decl))
4088 tree *p, t;
4090 #ifdef ASM_WEAKEN_DECL
4091 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4092 #else
4093 ASM_WEAKEN_LABEL (asm_out_file, name);
4094 #endif
4096 /* Remove this function from the pending weak list so that
4097 we do not emit multiple .weak directives for it. */
4098 for (p = &weak_decls; (t = *p) ; )
4100 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4101 *p = TREE_CHAIN (t);
4102 else
4103 p = &TREE_CHAIN (t);
4105 return;
4107 #endif
4109 (*targetm.asm_out.globalize_label) (asm_out_file, name);
4112 /* Emit an assembler directive to make the symbol for DECL an alias to
4113 the symbol for TARGET. */
4115 void
4116 assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4118 const char *name;
4120 /* We must force creation of DECL_RTL for debug info generation, even though
4121 we don't use it here. */
4122 make_decl_rtl (decl, NULL);
4124 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4126 #ifdef ASM_OUTPUT_DEF
4127 /* Make name accessible from other files, if appropriate. */
4129 if (TREE_PUBLIC (decl))
4131 globalize_decl (decl);
4132 maybe_assemble_visibility (decl);
4135 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4136 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4137 #else
4138 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4139 #endif
4140 #else /* !ASM_OUTPUT_DEF */
4141 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4142 if (DECL_WEAK (decl))
4144 tree *p, t;
4145 #ifdef ASM_WEAKEN_DECL
4146 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4147 #else
4148 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4149 #endif
4150 /* Remove this function from the pending weak list so that
4151 we do not emit multiple .weak directives for it. */
4152 for (p = &weak_decls; (t = *p) ; )
4153 if (DECL_ASSEMBLER_NAME (decl)
4154 == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4155 *p = TREE_CHAIN (t);
4156 else
4157 p = &TREE_CHAIN (t);
4159 else
4160 warning ("only weak aliases are supported in this configuration");
4162 #else
4163 warning ("alias definitions not supported in this configuration; ignored");
4164 #endif
4165 #endif
4167 TREE_USED (decl) = 1;
4168 TREE_ASM_WRITTEN (decl) = 1;
4169 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4172 /* Emit an assembler directive to set symbol for DECL visibility to
4173 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4175 void
4176 default_assemble_visibility (tree decl, int vis)
4178 static const char * const visibility_types[] = {
4179 NULL, "internal", "hidden", "protected"
4182 const char *name, *type;
4184 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4185 type = visibility_types[vis];
4187 #ifdef HAVE_GAS_HIDDEN
4188 fprintf (asm_out_file, "\t.%s\t", type);
4189 assemble_name (asm_out_file, name);
4190 fprintf (asm_out_file, "\n");
4191 #else
4192 warning ("visibility attribute not supported in this configuration; ignored");
4193 #endif
4196 /* A helper function to call assemble_visibility when needed for a decl. */
4198 static void
4199 maybe_assemble_visibility (tree decl)
4201 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4203 if (vis != VISIBILITY_DEFAULT)
4204 (* targetm.asm_out.visibility) (decl, vis);
4207 /* Returns 1 if the target configuration supports defining public symbols
4208 so that one of them will be chosen at link time instead of generating a
4209 multiply-defined symbol error, whether through the use of weak symbols or
4210 a target-specific mechanism for having duplicates discarded. */
4213 supports_one_only (void)
4215 if (SUPPORTS_ONE_ONLY)
4216 return 1;
4217 return SUPPORTS_WEAK;
4220 /* Set up DECL as a public symbol that can be defined in multiple
4221 translation units without generating a linker error. */
4223 void
4224 make_decl_one_only (tree decl)
4226 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4227 abort ();
4229 TREE_PUBLIC (decl) = 1;
4231 if (TREE_CODE (decl) == VAR_DECL
4232 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4233 DECL_COMMON (decl) = 1;
4234 else if (SUPPORTS_ONE_ONLY)
4236 #ifdef MAKE_DECL_ONE_ONLY
4237 MAKE_DECL_ONE_ONLY (decl);
4238 #endif
4239 DECL_ONE_ONLY (decl) = 1;
4241 else if (SUPPORTS_WEAK)
4242 DECL_WEAK (decl) = 1;
4243 else
4244 abort ();
4247 void
4248 init_varasm_once (void)
4250 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4251 in_named_entry_eq, NULL);
4252 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4253 const_desc_eq, NULL);
4255 const_alias_set = new_alias_set ();
4258 enum tls_model
4259 decl_tls_model (tree decl)
4261 enum tls_model kind;
4262 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4263 bool is_local;
4265 if (attr)
4267 attr = TREE_VALUE (TREE_VALUE (attr));
4268 if (TREE_CODE (attr) != STRING_CST)
4269 abort ();
4270 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4271 kind = TLS_MODEL_LOCAL_EXEC;
4272 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4273 kind = TLS_MODEL_INITIAL_EXEC;
4274 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4275 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4276 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4277 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4278 else
4279 abort ();
4280 return kind;
4283 is_local = (*targetm.binds_local_p) (decl);
4284 if (!flag_pic)
4286 if (is_local)
4287 kind = TLS_MODEL_LOCAL_EXEC;
4288 else
4289 kind = TLS_MODEL_INITIAL_EXEC;
4291 /* Local dynamic is inefficient when we're not combining the
4292 parts of the address. */
4293 else if (optimize && is_local)
4294 kind = TLS_MODEL_LOCAL_DYNAMIC;
4295 else
4296 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4297 if (kind < flag_tls_default)
4298 kind = flag_tls_default;
4300 return kind;
4303 /* Select a set of attributes for section NAME based on the properties
4304 of DECL and whether or not RELOC indicates that DECL's initializer
4305 might contain runtime relocations.
4307 We make the section read-only and executable for a function decl,
4308 read-only for a const data decl, and writable for a non-const data decl. */
4310 unsigned int
4311 default_section_type_flags (tree decl, const char *name, int reloc)
4313 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4316 unsigned int
4317 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4318 int shlib)
4320 unsigned int flags;
4322 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4323 flags = SECTION_CODE;
4324 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4325 flags = 0;
4326 else
4327 flags = SECTION_WRITE;
4329 if (decl && DECL_ONE_ONLY (decl))
4330 flags |= SECTION_LINKONCE;
4332 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4333 flags |= SECTION_TLS | SECTION_WRITE;
4335 if (strcmp (name, ".bss") == 0
4336 || strncmp (name, ".bss.", 5) == 0
4337 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4338 || strcmp (name, ".sbss") == 0
4339 || strncmp (name, ".sbss.", 6) == 0
4340 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
4341 || strcmp (name, ".tbss") == 0
4342 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4343 flags |= SECTION_BSS;
4345 if (strcmp (name, ".tdata") == 0
4346 || strcmp (name, ".tbss") == 0
4347 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
4348 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4349 flags |= SECTION_TLS;
4351 /* These three sections have special ELF types. They are neither
4352 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4353 want to print a section type (@progbits or @nobits). If someone
4354 is silly enough to emit code or TLS variables to one of these
4355 sections, then don't handle them specially. */
4356 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4357 && (strcmp (name, ".init_array") == 0
4358 || strcmp (name, ".fini_array") == 0
4359 || strcmp (name, ".preinit_array") == 0))
4360 flags |= SECTION_NOTYPE;
4362 return flags;
4365 /* Output assembly to switch to section NAME with attribute FLAGS.
4366 Four variants for common object file formats. */
4368 void
4369 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4370 unsigned int flags ATTRIBUTE_UNUSED)
4372 /* Some object formats don't support named sections at all. The
4373 front-end should already have flagged this as an error. */
4374 abort ();
4377 void
4378 default_elf_asm_named_section (const char *name, unsigned int flags)
4380 char flagchars[10], *f = flagchars;
4382 if (! named_section_first_declaration (name))
4384 fprintf (asm_out_file, "\t.section\t%s\n", name);
4385 return;
4388 if (!(flags & SECTION_DEBUG))
4389 *f++ = 'a';
4390 if (flags & SECTION_WRITE)
4391 *f++ = 'w';
4392 if (flags & SECTION_CODE)
4393 *f++ = 'x';
4394 if (flags & SECTION_SMALL)
4395 *f++ = 's';
4396 if (flags & SECTION_MERGE)
4397 *f++ = 'M';
4398 if (flags & SECTION_STRINGS)
4399 *f++ = 'S';
4400 if (flags & SECTION_TLS)
4401 *f++ = 'T';
4402 *f = '\0';
4404 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4406 if (!(flags & SECTION_NOTYPE))
4408 const char *type;
4410 if (flags & SECTION_BSS)
4411 type = "nobits";
4412 else
4413 type = "progbits";
4415 fprintf (asm_out_file, ",@%s", type);
4417 if (flags & SECTION_ENTSIZE)
4418 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4421 putc ('\n', asm_out_file);
4424 void
4425 default_coff_asm_named_section (const char *name, unsigned int flags)
4427 char flagchars[8], *f = flagchars;
4429 if (flags & SECTION_WRITE)
4430 *f++ = 'w';
4431 if (flags & SECTION_CODE)
4432 *f++ = 'x';
4433 *f = '\0';
4435 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4438 void
4439 default_pe_asm_named_section (const char *name, unsigned int flags)
4441 default_coff_asm_named_section (name, flags);
4443 if (flags & SECTION_LINKONCE)
4445 /* Functions may have been compiled at various levels of
4446 optimization so we can't use `same_size' here.
4447 Instead, have the linker pick one. */
4448 fprintf (asm_out_file, "\t.linkonce %s\n",
4449 (flags & SECTION_CODE ? "discard" : "same_size"));
4453 /* The lame default section selector. */
4455 void
4456 default_select_section (tree decl, int reloc,
4457 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4459 bool readonly = false;
4461 if (DECL_P (decl))
4463 if (decl_readonly_section (decl, reloc))
4464 readonly = true;
4466 else if (TREE_CODE (decl) == CONSTRUCTOR)
4468 if (! ((flag_pic && reloc)
4469 || !TREE_READONLY (decl)
4470 || TREE_SIDE_EFFECTS (decl)
4471 || !TREE_CONSTANT (decl)))
4472 readonly = true;
4474 else if (TREE_CODE (decl) == STRING_CST)
4475 readonly = true;
4476 else if (! (flag_pic && reloc))
4477 readonly = true;
4479 if (readonly)
4480 readonly_data_section ();
4481 else
4482 data_section ();
4485 /* A helper function for default_elf_select_section and
4486 default_elf_unique_section. Categorizes the DECL. */
4488 enum section_category
4490 SECCAT_TEXT,
4492 SECCAT_RODATA,
4493 SECCAT_RODATA_MERGE_STR,
4494 SECCAT_RODATA_MERGE_STR_INIT,
4495 SECCAT_RODATA_MERGE_CONST,
4496 SECCAT_SRODATA,
4498 SECCAT_DATA,
4500 /* To optimize loading of shared programs, define following subsections
4501 of data section:
4502 _REL Contains data that has relocations, so they get grouped
4503 together and dynamic linker will visit fewer pages in memory.
4504 _RO Contains data that is otherwise read-only. This is useful
4505 with prelinking as most relocations won't be dynamically
4506 linked and thus stay read only.
4507 _LOCAL Marks data containing relocations only to local objects.
4508 These relocations will get fully resolved by prelinking. */
4509 SECCAT_DATA_REL,
4510 SECCAT_DATA_REL_LOCAL,
4511 SECCAT_DATA_REL_RO,
4512 SECCAT_DATA_REL_RO_LOCAL,
4514 SECCAT_SDATA,
4515 SECCAT_TDATA,
4517 SECCAT_BSS,
4518 SECCAT_SBSS,
4519 SECCAT_TBSS
4522 static enum section_category
4523 categorize_decl_for_section (tree, int, int);
4525 static enum section_category
4526 categorize_decl_for_section (tree decl, int reloc, int shlib)
4528 enum section_category ret;
4530 if (TREE_CODE (decl) == FUNCTION_DECL)
4531 return SECCAT_TEXT;
4532 else if (TREE_CODE (decl) == STRING_CST)
4533 return SECCAT_RODATA_MERGE_STR;
4534 else if (TREE_CODE (decl) == VAR_DECL)
4536 if (DECL_INITIAL (decl) == NULL
4537 || DECL_INITIAL (decl) == error_mark_node)
4538 ret = SECCAT_BSS;
4539 else if (! TREE_READONLY (decl)
4540 || TREE_SIDE_EFFECTS (decl)
4541 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4543 if (shlib && (reloc & 2))
4544 ret = SECCAT_DATA_REL;
4545 else if (shlib && reloc)
4546 ret = SECCAT_DATA_REL_LOCAL;
4547 else
4548 ret = SECCAT_DATA;
4550 else if (shlib && (reloc & 2))
4551 ret = SECCAT_DATA_REL_RO;
4552 else if (shlib && reloc)
4553 ret = SECCAT_DATA_REL_RO_LOCAL;
4554 else if (reloc || flag_merge_constants < 2)
4555 /* C and C++ don't allow different variables to share the same
4556 location. -fmerge-all-constants allows even that (at the
4557 expense of not conforming). */
4558 ret = SECCAT_RODATA;
4559 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4560 ret = SECCAT_RODATA_MERGE_STR_INIT;
4561 else
4562 ret = SECCAT_RODATA_MERGE_CONST;
4564 else if (TREE_CODE (decl) == CONSTRUCTOR)
4566 if ((shlib && reloc)
4567 || TREE_SIDE_EFFECTS (decl)
4568 || ! TREE_CONSTANT (decl))
4569 ret = SECCAT_DATA;
4570 else
4571 ret = SECCAT_RODATA;
4573 else
4574 ret = SECCAT_RODATA;
4576 /* There are no read-only thread-local sections. */
4577 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4579 if (ret == SECCAT_BSS)
4580 ret = SECCAT_TBSS;
4581 else
4582 ret = SECCAT_TDATA;
4585 /* If the target uses small data sections, select it. */
4586 else if ((*targetm.in_small_data_p) (decl))
4588 if (ret == SECCAT_BSS)
4589 ret = SECCAT_SBSS;
4590 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4591 ret = SECCAT_SRODATA;
4592 else
4593 ret = SECCAT_SDATA;
4596 return ret;
4599 bool
4600 decl_readonly_section (tree decl, int reloc)
4602 return decl_readonly_section_1 (decl, reloc, flag_pic);
4605 bool
4606 decl_readonly_section_1 (tree decl, int reloc, int shlib)
4608 switch (categorize_decl_for_section (decl, reloc, shlib))
4610 case SECCAT_RODATA:
4611 case SECCAT_RODATA_MERGE_STR:
4612 case SECCAT_RODATA_MERGE_STR_INIT:
4613 case SECCAT_RODATA_MERGE_CONST:
4614 case SECCAT_SRODATA:
4615 return true;
4616 break;
4617 default:
4618 return false;
4619 break;
4623 /* Select a section based on the above categorization. */
4625 void
4626 default_elf_select_section (tree decl, int reloc,
4627 unsigned HOST_WIDE_INT align)
4629 default_elf_select_section_1 (decl, reloc, align, flag_pic);
4632 void
4633 default_elf_select_section_1 (tree decl, int reloc,
4634 unsigned HOST_WIDE_INT align, int shlib)
4636 switch (categorize_decl_for_section (decl, reloc, shlib))
4638 case SECCAT_TEXT:
4639 /* We're not supposed to be called on FUNCTION_DECLs. */
4640 abort ();
4641 case SECCAT_RODATA:
4642 readonly_data_section ();
4643 break;
4644 case SECCAT_RODATA_MERGE_STR:
4645 mergeable_string_section (decl, align, 0);
4646 break;
4647 case SECCAT_RODATA_MERGE_STR_INIT:
4648 mergeable_string_section (DECL_INITIAL (decl), align, 0);
4649 break;
4650 case SECCAT_RODATA_MERGE_CONST:
4651 mergeable_constant_section (DECL_MODE (decl), align, 0);
4652 break;
4653 case SECCAT_SRODATA:
4654 named_section (NULL_TREE, ".sdata2", reloc);
4655 break;
4656 case SECCAT_DATA:
4657 data_section ();
4658 break;
4659 case SECCAT_DATA_REL:
4660 named_section (NULL_TREE, ".data.rel", reloc);
4661 break;
4662 case SECCAT_DATA_REL_LOCAL:
4663 named_section (NULL_TREE, ".data.rel.local", reloc);
4664 break;
4665 case SECCAT_DATA_REL_RO:
4666 named_section (NULL_TREE, ".data.rel.ro", reloc);
4667 break;
4668 case SECCAT_DATA_REL_RO_LOCAL:
4669 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
4670 break;
4671 case SECCAT_SDATA:
4672 named_section (NULL_TREE, ".sdata", reloc);
4673 break;
4674 case SECCAT_TDATA:
4675 named_section (NULL_TREE, ".tdata", reloc);
4676 break;
4677 case SECCAT_BSS:
4678 #ifdef BSS_SECTION_ASM_OP
4679 bss_section ();
4680 #else
4681 named_section (NULL_TREE, ".bss", reloc);
4682 #endif
4683 break;
4684 case SECCAT_SBSS:
4685 named_section (NULL_TREE, ".sbss", reloc);
4686 break;
4687 case SECCAT_TBSS:
4688 named_section (NULL_TREE, ".tbss", reloc);
4689 break;
4690 default:
4691 abort ();
4695 /* Construct a unique section name based on the decl name and the
4696 categorization performed above. */
4698 void
4699 default_unique_section (tree decl, int reloc)
4701 default_unique_section_1 (decl, reloc, flag_pic);
4704 void
4705 default_unique_section_1 (tree decl, int reloc, int shlib)
4707 bool one_only = DECL_ONE_ONLY (decl);
4708 const char *prefix, *name;
4709 size_t nlen, plen;
4710 char *string;
4712 switch (categorize_decl_for_section (decl, reloc, shlib))
4714 case SECCAT_TEXT:
4715 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
4716 break;
4717 case SECCAT_RODATA:
4718 case SECCAT_RODATA_MERGE_STR:
4719 case SECCAT_RODATA_MERGE_STR_INIT:
4720 case SECCAT_RODATA_MERGE_CONST:
4721 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
4722 break;
4723 case SECCAT_SRODATA:
4724 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
4725 break;
4726 case SECCAT_DATA:
4727 case SECCAT_DATA_REL:
4728 case SECCAT_DATA_REL_LOCAL:
4729 case SECCAT_DATA_REL_RO:
4730 case SECCAT_DATA_REL_RO_LOCAL:
4731 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
4732 break;
4733 case SECCAT_SDATA:
4734 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
4735 break;
4736 case SECCAT_BSS:
4737 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
4738 break;
4739 case SECCAT_SBSS:
4740 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
4741 break;
4742 case SECCAT_TDATA:
4743 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
4744 break;
4745 case SECCAT_TBSS:
4746 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
4747 break;
4748 default:
4749 abort ();
4751 plen = strlen (prefix);
4753 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4754 name = (* targetm.strip_name_encoding) (name);
4755 nlen = strlen (name);
4757 string = alloca (nlen + plen + 1);
4758 memcpy (string, prefix, plen);
4759 memcpy (string + plen, name, nlen + 1);
4761 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
4764 void
4765 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
4766 rtx x,
4767 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4769 if (flag_pic)
4770 switch (GET_CODE (x))
4772 case CONST:
4773 case SYMBOL_REF:
4774 case LABEL_REF:
4775 data_section ();
4776 return;
4778 default:
4779 break;
4782 readonly_data_section ();
4785 void
4786 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
4787 unsigned HOST_WIDE_INT align)
4789 /* ??? Handle small data here somehow. */
4791 if (flag_pic)
4792 switch (GET_CODE (x))
4794 case CONST:
4795 case SYMBOL_REF:
4796 named_section (NULL_TREE, ".data.rel.ro", 3);
4797 return;
4799 case LABEL_REF:
4800 named_section (NULL_TREE, ".data.rel.ro.local", 1);
4801 return;
4803 default:
4804 break;
4807 mergeable_constant_section (mode, align, 0);
4810 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
4812 void
4813 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
4815 rtx symbol;
4816 int flags;
4818 /* Careful not to prod global register variables. */
4819 if (GET_CODE (rtl) != MEM)
4820 return;
4821 symbol = XEXP (rtl, 0);
4822 if (GET_CODE (symbol) != SYMBOL_REF)
4823 return;
4825 flags = 0;
4826 if (TREE_CODE (decl) == FUNCTION_DECL)
4827 flags |= SYMBOL_FLAG_FUNCTION;
4828 if ((*targetm.binds_local_p) (decl))
4829 flags |= SYMBOL_FLAG_LOCAL;
4830 if ((*targetm.in_small_data_p) (decl))
4831 flags |= SYMBOL_FLAG_SMALL;
4832 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4833 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
4834 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
4835 being PUBLIC, the thing *must* be defined in this translation unit.
4836 Prevent this buglet from being propagated into rtl code as well. */
4837 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
4838 flags |= SYMBOL_FLAG_EXTERNAL;
4840 SYMBOL_REF_FLAGS (symbol) = flags;
4843 /* By default, we do nothing for encode_section_info, so we need not
4844 do anything but discard the '*' marker. */
4846 const char *
4847 default_strip_name_encoding (const char *str)
4849 return str + (*str == '*');
4852 /* Assume ELF-ish defaults, since that's pretty much the most liberal
4853 wrt cross-module name binding. */
4855 bool
4856 default_binds_local_p (tree exp)
4858 return default_binds_local_p_1 (exp, flag_shlib);
4861 bool
4862 default_binds_local_p_1 (tree exp, int shlib)
4864 bool local_p;
4866 /* A non-decl is an entry in the constant pool. */
4867 if (!DECL_P (exp))
4868 local_p = true;
4869 /* Static variables are always local. */
4870 else if (! TREE_PUBLIC (exp))
4871 local_p = true;
4872 /* A variable is local if the user tells us so. */
4873 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
4874 local_p = true;
4875 /* Otherwise, variables defined outside this object may not be local. */
4876 else if (DECL_EXTERNAL (exp))
4877 local_p = false;
4878 /* Linkonce and weak data are never local. */
4879 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
4880 local_p = false;
4881 /* If PIC, then assume that any global name can be overridden by
4882 symbols resolved from other modules. */
4883 else if (shlib)
4884 local_p = false;
4885 /* Uninitialized COMMON variable may be unified with symbols
4886 resolved from other modules. */
4887 else if (DECL_COMMON (exp)
4888 && (DECL_INITIAL (exp) == NULL
4889 || DECL_INITIAL (exp) == error_mark_node))
4890 local_p = false;
4891 /* Otherwise we're left with initialized (or non-common) global data
4892 which is of necessity defined locally. */
4893 else
4894 local_p = true;
4896 return local_p;
4899 /* Determine whether or not a pointer mode is valid. Assume defaults
4900 of ptr_mode or Pmode - can be overridden. */
4901 bool
4902 default_valid_pointer_mode (enum machine_mode mode)
4904 return (mode == ptr_mode || mode == Pmode);
4907 /* Default function to output code that will globalize a label. A
4908 target must define GLOBAL_ASM_OP or provide it's own function to
4909 globalize a label. */
4910 #ifdef GLOBAL_ASM_OP
4911 void
4912 default_globalize_label (FILE * stream, const char *name)
4914 fputs (GLOBAL_ASM_OP, stream);
4915 assemble_name (stream, name);
4916 putc ('\n', stream);
4918 #endif /* GLOBAL_ASM_OP */
4920 /* This is how to output an internal numbered label where PREFIX is
4921 the class of label and LABELNO is the number within the class. */
4923 void
4924 default_internal_label (FILE *stream, const char *prefix,
4925 unsigned long labelno)
4927 char *const buf = alloca (40 + strlen (prefix));
4928 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
4929 ASM_OUTPUT_LABEL (stream, buf);
4932 /* This is the default behavior at the beginning of a file. It's
4933 controlled by two other target-hook toggles. */
4934 void
4935 default_file_start (void)
4937 if (targetm.file_start_app_off && !flag_verbose_asm)
4938 fputs (ASM_APP_OFF, asm_out_file);
4940 if (targetm.file_start_file_directive)
4941 output_file_directive (asm_out_file, main_input_filename);
4944 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
4945 which emits a special section directive used to indicate whether or
4946 not this object file needs an executable stack. This is primarily
4947 a GNU extension to ELF but could be used on other targets. */
4948 void
4949 file_end_indicate_exec_stack (void)
4951 unsigned int flags = SECTION_DEBUG;
4952 if (trampolines_created)
4953 flags |= SECTION_CODE;
4955 named_section_flags (".note.GNU-stack", flags);
4958 #include "gt-varasm.h"