2003-12-21 Michael Koch <konqueror@gmx.de>
[official-gcc.git] / gcc / varasm.c
blob70c13bb6bd1a199433ed8fc40515c90895dd1440
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 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_const;
73 struct pool_constant;
75 #define MAX_RTX_HASH_TABLE 61
77 struct varasm_status GTY(())
79 /* Hash facility for making memory-constants
80 from constant rtl-expressions. It is used on RISC machines
81 where immediate integer arguments and constant addresses are restricted
82 so that such constants must be stored in memory.
84 This pool of constants is reinitialized for each function
85 so each function gets its own constants-pool that comes right before
86 it. */
87 struct constant_descriptor_rtx ** GTY ((length ("MAX_RTX_HASH_TABLE")))
88 x_const_rtx_hash_table;
89 struct pool_constant ** GTY ((length ("MAX_RTX_HASH_TABLE")))
90 x_const_rtx_sym_hash_table;
92 /* Pointers to first and last constant in pool. */
93 struct pool_constant *x_first_pool;
94 struct pool_constant *x_last_pool;
96 /* Current offset in constant pool (does not include any machine-specific
97 header). */
98 HOST_WIDE_INT x_pool_offset;
100 /* Number of tree-constants deferred during the expansion of this
101 function. */
102 unsigned int deferred_constants;
105 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
106 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
107 #define first_pool (cfun->varasm->x_first_pool)
108 #define last_pool (cfun->varasm->x_last_pool)
109 #define pool_offset (cfun->varasm->x_pool_offset)
110 #define n_deferred_constants (cfun->varasm->deferred_constants)
112 /* Number for making the label on the next
113 constant that is stored in memory. */
115 static GTY(()) int const_labelno;
117 /* Carry information from ASM_DECLARE_OBJECT_NAME
118 to ASM_FINISH_DECLARE_OBJECT. */
120 int size_directive_output;
122 /* The last decl for which assemble_variable was called,
123 if it did ASM_DECLARE_OBJECT_NAME.
124 If the last call to assemble_variable didn't do that,
125 this holds 0. */
127 tree last_assemble_variable_decl;
129 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
130 So giving constant the alias set for the type will allow such
131 initializations to appear to conflict with the load of the constant. We
132 avoid this by giving all constants an alias set for just constants.
133 Since there will be no stores to that alias set, nothing will ever
134 conflict with them. */
136 static HOST_WIDE_INT const_alias_set;
138 static const char *strip_reg_name (const char *);
139 static int contains_pointers_p (tree);
140 #ifdef ASM_OUTPUT_EXTERNAL
141 static bool incorporeal_function_p (tree);
142 #endif
143 static void decode_addr_const (tree, struct addr_const *);
144 static hashval_t const_desc_hash (const void *);
145 static int const_desc_eq (const void *, const void *);
146 static hashval_t const_hash_1 (const tree);
147 static int compare_constant (const tree, const tree);
148 static tree copy_constant (tree);
149 static void output_constant_def_contents (rtx);
150 static void decode_rtx_const (enum machine_mode, rtx, struct rtx_const *);
151 static unsigned int const_hash_rtx (enum machine_mode, rtx);
152 static int compare_constant_rtx (enum machine_mode, rtx,
153 struct constant_descriptor_rtx *);
154 static struct constant_descriptor_rtx * record_constant_rtx
155 (enum machine_mode, rtx);
156 static struct pool_constant *find_pool_constant (struct function *, rtx);
157 static void mark_constant_pool (void);
158 static void mark_constants (rtx);
159 static int mark_constant (rtx *current_rtx, void *data);
160 static void output_addressed_constants (tree);
161 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
162 static unsigned min_align (unsigned, unsigned);
163 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
164 static void globalize_decl (tree);
165 static void maybe_assemble_visibility (tree);
166 static int in_named_entry_eq (const void *, const void *);
167 static hashval_t in_named_entry_hash (const void *);
168 #ifdef ASM_OUTPUT_BSS
169 static void asm_output_bss (FILE *, tree, const char *,
170 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
171 #endif
172 #ifdef BSS_SECTION_ASM_OP
173 #ifdef ASM_OUTPUT_ALIGNED_BSS
174 static void asm_output_aligned_bss (FILE *, tree, const char *,
175 unsigned HOST_WIDE_INT, int)
176 ATTRIBUTE_UNUSED;
177 #endif
178 #endif /* BSS_SECTION_ASM_OP */
179 static bool asm_emit_uninitialised (tree, const char*,
180 unsigned HOST_WIDE_INT,
181 unsigned HOST_WIDE_INT);
182 static void mark_weak (tree);
184 enum in_section { no_section, in_text, in_data, in_named
185 #ifdef BSS_SECTION_ASM_OP
186 , in_bss
187 #endif
188 #ifdef CTORS_SECTION_ASM_OP
189 , in_ctors
190 #endif
191 #ifdef DTORS_SECTION_ASM_OP
192 , in_dtors
193 #endif
194 #ifdef READONLY_DATA_SECTION_ASM_OP
195 , in_readonly_data
196 #endif
197 #ifdef EXTRA_SECTIONS
198 , EXTRA_SECTIONS
199 #endif
201 static GTY(()) enum in_section in_section = no_section;
203 /* Return a nonzero value if DECL has a section attribute. */
204 #ifndef IN_NAMED_SECTION
205 #define IN_NAMED_SECTION(DECL) \
206 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
207 && DECL_SECTION_NAME (DECL) != NULL_TREE)
208 #endif
210 /* Text of section name when in_section == in_named. */
211 static GTY(()) const char *in_named_name;
213 /* Hash table of flags that have been used for a particular named section. */
215 struct in_named_entry GTY(())
217 const char *name;
218 unsigned int flags;
219 bool declared;
222 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
224 /* Define functions like text_section for any extra sections. */
225 #ifdef EXTRA_SECTION_FUNCTIONS
226 EXTRA_SECTION_FUNCTIONS
227 #endif
229 /* Tell assembler to switch to text section. */
231 void
232 text_section (void)
234 if (in_section != in_text)
236 in_section = in_text;
237 #ifdef TEXT_SECTION
238 TEXT_SECTION ();
239 #else
240 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
241 #endif
245 /* Tell assembler to switch to data section. */
247 void
248 data_section (void)
250 if (in_section != in_data)
252 in_section = in_data;
253 if (flag_shared_data)
255 #ifdef SHARED_SECTION_ASM_OP
256 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
257 #else
258 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
259 #endif
261 else
262 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
266 /* Tell assembler to switch to read-only data section. This is normally
267 the text section. */
269 void
270 readonly_data_section (void)
272 #ifdef READONLY_DATA_SECTION
273 READONLY_DATA_SECTION (); /* Note this can call data_section. */
274 #else
275 #ifdef READONLY_DATA_SECTION_ASM_OP
276 if (in_section != in_readonly_data)
278 in_section = in_readonly_data;
279 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
280 fputc ('\n', asm_out_file);
282 #else
283 text_section ();
284 #endif
285 #endif
288 /* Determine if we're in the text section. */
291 in_text_section (void)
293 return in_section == in_text;
296 /* Determine if we're in the data section. */
299 in_data_section (void)
301 return in_section == in_data;
304 /* Helper routines for maintaining in_named_htab. */
306 static int
307 in_named_entry_eq (const void *p1, const void *p2)
309 const struct in_named_entry *old = p1;
310 const char *new = p2;
312 return strcmp (old->name, new) == 0;
315 static hashval_t
316 in_named_entry_hash (const void *p)
318 const struct in_named_entry *old = p;
319 return htab_hash_string (old->name);
322 /* If SECTION has been seen before as a named section, return the flags
323 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
324 set of flags for a section to have, so 0 does not mean that the section
325 has not been seen. */
327 unsigned int
328 get_named_section_flags (const char *section)
330 struct in_named_entry **slot;
332 slot = (struct in_named_entry **)
333 htab_find_slot_with_hash (in_named_htab, section,
334 htab_hash_string (section), NO_INSERT);
336 return slot ? (*slot)->flags : 0;
339 /* Returns true if the section has been declared before. Sets internal
340 flag on this section in in_named_hash so subsequent calls on this
341 section will return false. */
343 bool
344 named_section_first_declaration (const char *name)
346 struct in_named_entry **slot;
348 slot = (struct in_named_entry **)
349 htab_find_slot_with_hash (in_named_htab, name,
350 htab_hash_string (name), NO_INSERT);
351 if (! (*slot)->declared)
353 (*slot)->declared = true;
354 return true;
356 else
358 return false;
363 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
364 different set of flags, return false. */
366 bool
367 set_named_section_flags (const char *section, unsigned int flags)
369 struct in_named_entry **slot, *entry;
371 slot = (struct in_named_entry **)
372 htab_find_slot_with_hash (in_named_htab, section,
373 htab_hash_string (section), INSERT);
374 entry = *slot;
376 if (!entry)
378 entry = ggc_alloc (sizeof (*entry));
379 *slot = entry;
380 entry->name = ggc_strdup (section);
381 entry->flags = flags;
382 entry->declared = false;
384 else if (entry->flags != flags)
385 return false;
387 return true;
390 /* Tell assembler to change to section NAME with attributes FLAGS. */
392 void
393 named_section_flags (const char *name, unsigned int flags)
395 if (in_section != in_named || strcmp (name, in_named_name) != 0)
397 if (! set_named_section_flags (name, flags))
398 abort ();
400 (*targetm.asm_out.named_section) (name, flags);
402 if (flags & SECTION_FORGET)
403 in_section = no_section;
404 else
406 in_named_name = ggc_strdup (name);
407 in_section = in_named;
412 /* Tell assembler to change to section NAME for DECL.
413 If DECL is NULL, just switch to section NAME.
414 If NAME is NULL, get the name from DECL.
415 If RELOC is 1, the initializer for DECL contains relocs. */
417 void
418 named_section (tree decl, const char *name, int reloc)
420 unsigned int flags;
422 if (decl != NULL_TREE && !DECL_P (decl))
423 abort ();
424 if (name == NULL)
425 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
427 flags = (* targetm.section_type_flags) (decl, name, reloc);
429 /* Sanity check user variables for flag changes. Non-user
430 section flag changes will abort in named_section_flags.
431 However, don't complain if SECTION_OVERRIDE is set.
432 We trust that the setter knows that it is safe to ignore
433 the default flags for this decl. */
434 if (decl && ! set_named_section_flags (name, flags))
436 flags = get_named_section_flags (name);
437 if ((flags & SECTION_OVERRIDE) == 0)
438 error ("%J%D causes a section type conflict", decl, decl);
441 named_section_flags (name, flags);
444 /* If required, set DECL_SECTION_NAME to a unique name. */
446 void
447 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
448 int flag_function_or_data_sections)
450 if (DECL_SECTION_NAME (decl) == NULL_TREE
451 && targetm.have_named_sections
452 && (flag_function_or_data_sections
453 || DECL_ONE_ONLY (decl)))
454 (*targetm.asm_out.unique_section) (decl, reloc);
457 #ifdef BSS_SECTION_ASM_OP
459 /* Tell the assembler to switch to the bss section. */
461 void
462 bss_section (void)
464 if (in_section != in_bss)
466 #ifdef SHARED_BSS_SECTION_ASM_OP
467 if (flag_shared_data)
468 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
469 else
470 #endif
471 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
473 in_section = in_bss;
477 #ifdef ASM_OUTPUT_BSS
479 /* Utility function for ASM_OUTPUT_BSS for targets to use if
480 they don't support alignments in .bss.
481 ??? It is believed that this function will work in most cases so such
482 support is localized here. */
484 static void
485 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
486 const char *name,
487 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
488 unsigned HOST_WIDE_INT rounded)
490 (*targetm.asm_out.globalize_label) (file, name);
491 bss_section ();
492 #ifdef ASM_DECLARE_OBJECT_NAME
493 last_assemble_variable_decl = decl;
494 ASM_DECLARE_OBJECT_NAME (file, name, decl);
495 #else
496 /* Standard thing is just output label for the object. */
497 ASM_OUTPUT_LABEL (file, name);
498 #endif /* ASM_DECLARE_OBJECT_NAME */
499 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
502 #endif
504 #ifdef ASM_OUTPUT_ALIGNED_BSS
506 /* Utility function for targets to use in implementing
507 ASM_OUTPUT_ALIGNED_BSS.
508 ??? It is believed that this function will work in most cases so such
509 support is localized here. */
511 static void
512 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
513 const char *name, unsigned HOST_WIDE_INT size,
514 int align)
516 bss_section ();
517 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
518 #ifdef ASM_DECLARE_OBJECT_NAME
519 last_assemble_variable_decl = decl;
520 ASM_DECLARE_OBJECT_NAME (file, name, decl);
521 #else
522 /* Standard thing is just output label for the object. */
523 ASM_OUTPUT_LABEL (file, name);
524 #endif /* ASM_DECLARE_OBJECT_NAME */
525 ASM_OUTPUT_SKIP (file, size ? size : 1);
528 #endif
530 #endif /* BSS_SECTION_ASM_OP */
532 /* Switch to the section for function DECL.
534 If DECL is NULL_TREE, switch to the text section.
535 ??? It's not clear that we will ever be passed NULL_TREE, but it's
536 safer to handle it. */
538 void
539 function_section (tree decl)
541 if (decl != NULL_TREE
542 && DECL_SECTION_NAME (decl) != NULL_TREE)
543 named_section (decl, (char *) 0, 0);
544 else
545 text_section ();
548 /* Switch to section for variable DECL. RELOC is the same as the
549 argument to SELECT_SECTION. */
551 void
552 variable_section (tree decl, int reloc)
554 if (IN_NAMED_SECTION (decl))
555 named_section (decl, NULL, reloc);
556 else
557 (*targetm.asm_out.select_section) (decl, reloc, DECL_ALIGN (decl));
560 /* Tell assembler to switch to the section for string merging. */
562 void
563 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
564 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
565 unsigned int flags ATTRIBUTE_UNUSED)
567 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
568 && TREE_CODE (decl) == STRING_CST
569 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
570 && align <= 256
571 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
573 enum machine_mode mode;
574 unsigned int modesize;
575 const char *str;
576 int i, j, len, unit;
577 char name[30];
579 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
580 modesize = GET_MODE_BITSIZE (mode);
581 if (modesize >= 8 && modesize <= 256
582 && (modesize & (modesize - 1)) == 0)
584 if (align < modesize)
585 align = modesize;
587 str = TREE_STRING_POINTER (decl);
588 len = TREE_STRING_LENGTH (decl);
589 unit = GET_MODE_SIZE (mode);
591 /* Check for embedded NUL characters. */
592 for (i = 0; i < len; i += unit)
594 for (j = 0; j < unit; j++)
595 if (str[i + j] != '\0')
596 break;
597 if (j == unit)
598 break;
600 if (i == len - unit)
602 sprintf (name, ".rodata.str%d.%d", modesize / 8,
603 (int) (align / 8));
604 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
605 if (!i && modesize < align)
607 /* A "" string with requested alignment greater than
608 character size might cause a problem:
609 if some other string required even bigger
610 alignment than "", then linker might think the
611 "" is just part of padding after some other string
612 and not put it into the hash table initially.
613 But this means "" could have smaller alignment
614 than requested. */
615 #ifdef ASM_OUTPUT_SECTION_START
616 named_section_flags (name, flags);
617 ASM_OUTPUT_SECTION_START (asm_out_file);
618 #else
619 readonly_data_section ();
620 #endif
621 return;
624 named_section_flags (name, flags);
625 return;
630 readonly_data_section ();
633 /* Tell assembler to switch to the section for constant merging. */
635 void
636 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
637 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
638 unsigned int flags ATTRIBUTE_UNUSED)
640 unsigned int modesize = GET_MODE_BITSIZE (mode);
642 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
643 && mode != VOIDmode
644 && mode != BLKmode
645 && modesize <= align
646 && align >= 8
647 && align <= 256
648 && (align & (align - 1)) == 0)
650 char name[24];
652 sprintf (name, ".rodata.cst%d", (int) (align / 8));
653 flags |= (align / 8) | SECTION_MERGE;
654 named_section_flags (name, flags);
655 return;
658 readonly_data_section ();
661 /* Given NAME, a putative register name, discard any customary prefixes. */
663 static const char *
664 strip_reg_name (const char *name)
666 #ifdef REGISTER_PREFIX
667 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
668 name += strlen (REGISTER_PREFIX);
669 #endif
670 if (name[0] == '%' || name[0] == '#')
671 name++;
672 return name;
675 /* Decode an `asm' spec for a declaration as a register name.
676 Return the register number, or -1 if nothing specified,
677 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
678 or -3 if ASMSPEC is `cc' and is not recognized,
679 or -4 if ASMSPEC is `memory' and is not recognized.
680 Accept an exact spelling or a decimal number.
681 Prefixes such as % are optional. */
684 decode_reg_name (const char *asmspec)
686 if (asmspec != 0)
688 int i;
690 /* Get rid of confusing prefixes. */
691 asmspec = strip_reg_name (asmspec);
693 /* Allow a decimal number as a "register name". */
694 for (i = strlen (asmspec) - 1; i >= 0; i--)
695 if (! ISDIGIT (asmspec[i]))
696 break;
697 if (asmspec[0] != 0 && i < 0)
699 i = atoi (asmspec);
700 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
701 return i;
702 else
703 return -2;
706 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
707 if (reg_names[i][0]
708 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
709 return i;
711 #ifdef ADDITIONAL_REGISTER_NAMES
713 static const struct { const char *const name; const int number; } table[]
714 = ADDITIONAL_REGISTER_NAMES;
716 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
717 if (! strcmp (asmspec, table[i].name))
718 return table[i].number;
720 #endif /* ADDITIONAL_REGISTER_NAMES */
722 if (!strcmp (asmspec, "memory"))
723 return -4;
725 if (!strcmp (asmspec, "cc"))
726 return -3;
728 return -2;
731 return -1;
734 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
735 have static storage duration. In other words, it should not be an
736 automatic variable, including PARM_DECLs.
738 There is, however, one exception: this function handles variables
739 explicitly placed in a particular register by the user.
741 ASMSPEC, if not 0, is the string which the user specified as the
742 assembler symbol name.
744 This is never called for PARM_DECL nodes. */
746 void
747 make_decl_rtl (tree decl, const char *asmspec)
749 const char *name = 0;
750 int reg_number;
751 rtx x;
753 /* Check that we are not being given an automatic variable. */
754 /* A weak alias has TREE_PUBLIC set but not the other bits. */
755 if (TREE_CODE (decl) == PARM_DECL
756 || TREE_CODE (decl) == RESULT_DECL
757 || (TREE_CODE (decl) == VAR_DECL
758 && !TREE_STATIC (decl)
759 && !TREE_PUBLIC (decl)
760 && !DECL_EXTERNAL (decl)
761 && !DECL_REGISTER (decl)))
762 abort ();
763 /* And that we were not given a type or a label. */
764 else if (TREE_CODE (decl) == TYPE_DECL
765 || TREE_CODE (decl) == LABEL_DECL)
766 abort ();
768 /* For a duplicate declaration, we can be called twice on the
769 same DECL node. Don't discard the RTL already made. */
770 if (DECL_RTL_SET_P (decl))
772 /* If the old RTL had the wrong mode, fix the mode. */
773 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
774 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
775 DECL_MODE (decl), 0));
777 /* ??? Another way to do this would be to maintain a hashed
778 table of such critters. Instead of adding stuff to a DECL
779 to give certain attributes to it, we could use an external
780 hash map from DECL to set of attributes. */
782 /* Let the target reassign the RTL if it wants.
783 This is necessary, for example, when one machine specific
784 decl attribute overrides another. */
785 (* targetm.encode_section_info) (decl, DECL_RTL (decl), false);
786 return;
789 reg_number = decode_reg_name (asmspec);
790 if (reg_number == -2)
792 /* ASMSPEC is given, and not the name of a register. Mark the
793 name with a star so assemble_name won't munge it. */
794 char *starred = alloca (strlen (asmspec) + 2);
795 starred[0] = '*';
796 strcpy (starred + 1, asmspec);
797 change_decl_assembler_name (decl, get_identifier (starred));
800 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
802 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
804 /* First detect errors in declaring global registers. */
805 if (reg_number == -1)
806 error ("%Jregister name not specified for '%D'", decl, decl);
807 else if (reg_number < 0)
808 error ("%Jinvalid register name for '%D'", decl, decl);
809 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
810 error ("%Jdata type of '%D' isn't suitable for a register",
811 decl, decl);
812 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
813 error ("%Jregister specified for '%D' isn't suitable for data type",
814 decl, decl);
815 /* Now handle properly declared static register variables. */
816 else
818 int nregs;
820 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
822 DECL_INITIAL (decl) = 0;
823 error ("global register variable has initial value");
825 if (TREE_THIS_VOLATILE (decl))
826 warning ("volatile register variables don't work as you might wish");
828 /* If the user specified one of the eliminables registers here,
829 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
830 confused with that register and be eliminated. This usage is
831 somewhat suspect... */
833 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
834 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
835 REG_USERVAR_P (DECL_RTL (decl)) = 1;
837 if (TREE_STATIC (decl))
839 /* Make this register global, so not usable for anything
840 else. */
841 #ifdef ASM_DECLARE_REGISTER_GLOBAL
842 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
843 #endif
844 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
845 while (nregs > 0)
846 globalize_reg (reg_number + --nregs);
849 /* As a register variable, it has no section. */
850 return;
854 /* Now handle ordinary static variables and functions (in memory).
855 Also handle vars declared register invalidly. */
857 if (reg_number >= 0 || reg_number == -3)
858 error ("%Jregister name given for non-register variable '%D'", decl, decl);
860 /* Specifying a section attribute on a variable forces it into a
861 non-.bss section, and thus it cannot be common. */
862 if (TREE_CODE (decl) == VAR_DECL
863 && DECL_SECTION_NAME (decl) != NULL_TREE
864 && DECL_INITIAL (decl) == NULL_TREE
865 && DECL_COMMON (decl))
866 DECL_COMMON (decl) = 0;
868 /* Variables can't be both common and weak. */
869 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
870 DECL_COMMON (decl) = 0;
872 x = gen_rtx_SYMBOL_REF (Pmode, name);
873 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
874 SYMBOL_REF_DECL (x) = decl;
876 x = gen_rtx_MEM (DECL_MODE (decl), x);
877 if (TREE_CODE (decl) != FUNCTION_DECL)
878 set_mem_attributes (x, decl, 1);
879 SET_DECL_RTL (decl, x);
881 /* Optionally set flags or add text to the name to record information
882 such as that it is a function name.
883 If the name is changed, the macro ASM_OUTPUT_LABELREF
884 will have to know how to strip this information. */
885 (* targetm.encode_section_info) (decl, DECL_RTL (decl), true);
888 /* Make the rtl for variable VAR be volatile.
889 Use this only for static variables. */
891 void
892 make_var_volatile (tree var)
894 if (GET_CODE (DECL_RTL (var)) != MEM)
895 abort ();
897 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
900 /* Output a string of literal assembler code
901 for an `asm' keyword used between functions. */
903 void
904 assemble_asm (tree string)
906 app_enable ();
908 if (TREE_CODE (string) == ADDR_EXPR)
909 string = TREE_OPERAND (string, 0);
911 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
914 /* Record an element in the table of global destructors. SYMBOL is
915 a SYMBOL_REF of the function to be called; PRIORITY is a number
916 between 0 and MAX_INIT_PRIORITY. */
918 void
919 default_stabs_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
921 /* Tell GNU LD that this is part of the static destructor set.
922 This will work for any system that uses stabs, most usefully
923 aout systems. */
924 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
925 assemble_name (asm_out_file, XSTR (symbol, 0));
926 fputc ('\n', asm_out_file);
929 void
930 default_named_section_asm_out_destructor (rtx symbol, int priority)
932 const char *section = ".dtors";
933 char buf[16];
935 /* ??? This only works reliably with the GNU linker. */
936 if (priority != DEFAULT_INIT_PRIORITY)
938 sprintf (buf, ".dtors.%.5u",
939 /* Invert the numbering so the linker puts us in the proper
940 order; constructors are run from right to left, and the
941 linker sorts in increasing order. */
942 MAX_INIT_PRIORITY - priority);
943 section = buf;
946 named_section_flags (section, SECTION_WRITE);
947 assemble_align (POINTER_SIZE);
948 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
951 #ifdef DTORS_SECTION_ASM_OP
952 void
953 dtors_section (void)
955 if (in_section != in_dtors)
957 in_section = in_dtors;
958 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
959 fputc ('\n', asm_out_file);
963 void
964 default_dtor_section_asm_out_destructor (rtx symbol,
965 int priority ATTRIBUTE_UNUSED)
967 dtors_section ();
968 assemble_align (POINTER_SIZE);
969 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
971 #endif
973 /* Likewise for global constructors. */
975 void
976 default_stabs_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
978 /* Tell GNU LD that this is part of the static destructor set.
979 This will work for any system that uses stabs, most usefully
980 aout systems. */
981 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
982 assemble_name (asm_out_file, XSTR (symbol, 0));
983 fputc ('\n', asm_out_file);
986 void
987 default_named_section_asm_out_constructor (rtx symbol, int priority)
989 const char *section = ".ctors";
990 char buf[16];
992 /* ??? This only works reliably with the GNU linker. */
993 if (priority != DEFAULT_INIT_PRIORITY)
995 sprintf (buf, ".ctors.%.5u",
996 /* Invert the numbering so the linker puts us in the proper
997 order; constructors are run from right to left, and the
998 linker sorts in increasing order. */
999 MAX_INIT_PRIORITY - priority);
1000 section = buf;
1003 named_section_flags (section, SECTION_WRITE);
1004 assemble_align (POINTER_SIZE);
1005 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1008 #ifdef CTORS_SECTION_ASM_OP
1009 void
1010 ctors_section (void)
1012 if (in_section != in_ctors)
1014 in_section = in_ctors;
1015 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1016 fputc ('\n', asm_out_file);
1020 void
1021 default_ctor_section_asm_out_constructor (rtx symbol,
1022 int priority ATTRIBUTE_UNUSED)
1024 ctors_section ();
1025 assemble_align (POINTER_SIZE);
1026 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1028 #endif
1030 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1031 a nonzero value if the constant pool should be output before the
1032 start of the function, or a zero value if the pool should output
1033 after the end of the function. The default is to put it before the
1034 start. */
1036 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1037 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1038 #endif
1040 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1041 to be output to assembler.
1042 Set first_global_object_name and weak_global_object_name as appropriate. */
1044 void
1045 notice_global_symbol (tree decl)
1047 const char **type = &first_global_object_name;
1049 if (first_global_object_name
1050 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
1051 || !DECL_NAME (decl)
1052 || (TREE_CODE (decl) != FUNCTION_DECL
1053 && (TREE_CODE (decl) != VAR_DECL
1054 || (DECL_COMMON (decl)
1055 && (DECL_INITIAL (decl) == 0
1056 || DECL_INITIAL (decl) == error_mark_node))))
1057 || GET_CODE (DECL_RTL (decl)) != MEM)
1058 return;
1060 /* We win when global object is found, but it is usefull to know about weak
1061 symbol as well so we can produce nicer unique names. */
1062 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1063 type = &weak_global_object_name;
1065 if (!*type)
1067 const char *p;
1068 char *name;
1069 rtx decl_rtl = DECL_RTL (decl);
1071 p = (* targetm.strip_name_encoding) (XSTR (XEXP (decl_rtl, 0), 0));
1072 name = xstrdup (p);
1074 *type = name;
1078 /* Output assembler code for the constant pool of a function and associated
1079 with defining the name of the function. DECL describes the function.
1080 NAME is the function's name. For the constant pool, we use the current
1081 constant pool data. */
1083 void
1084 assemble_start_function (tree decl, const char *fnname)
1086 int align;
1088 /* The following code does not need preprocessing in the assembler. */
1090 app_disable ();
1092 if (CONSTANT_POOL_BEFORE_FUNCTION)
1093 output_constant_pool (fnname, decl);
1095 resolve_unique_section (decl, 0, flag_function_sections);
1096 function_section (decl);
1098 /* Tell assembler to move to target machine's alignment for functions. */
1099 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1100 if (align < force_align_functions_log)
1101 align = force_align_functions_log;
1102 if (align > 0)
1104 ASM_OUTPUT_ALIGN (asm_out_file, align);
1107 /* Handle a user-specified function alignment.
1108 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1109 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1110 if (align_functions_log > align
1111 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1113 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1114 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1115 align_functions_log, align_functions - 1);
1116 #else
1117 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1118 #endif
1121 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1122 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1123 #endif
1125 (*debug_hooks->begin_function) (decl);
1127 /* Make function name accessible from other files, if appropriate. */
1129 if (TREE_PUBLIC (decl))
1131 notice_global_symbol (decl);
1133 globalize_decl (decl);
1135 maybe_assemble_visibility (decl);
1138 /* Do any machine/system dependent processing of the function name. */
1139 #ifdef ASM_DECLARE_FUNCTION_NAME
1140 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1141 #else
1142 /* Standard thing is just output label for the function. */
1143 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1144 #endif /* ASM_DECLARE_FUNCTION_NAME */
1147 /* Output assembler code associated with defining the size of the
1148 function. DECL describes the function. NAME is the function's name. */
1150 void
1151 assemble_end_function (tree decl, const char *fnname)
1153 #ifdef ASM_DECLARE_FUNCTION_SIZE
1154 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1155 #endif
1156 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1158 output_constant_pool (fnname, decl);
1159 function_section (decl); /* need to switch back */
1163 /* Assemble code to leave SIZE bytes of zeros. */
1165 void
1166 assemble_zeros (unsigned HOST_WIDE_INT size)
1168 /* Do no output if -fsyntax-only. */
1169 if (flag_syntax_only)
1170 return;
1172 #ifdef ASM_NO_SKIP_IN_TEXT
1173 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1174 so we must output 0s explicitly in the text section. */
1175 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1177 unsigned HOST_WIDE_INT i;
1178 for (i = 0; i < size; i++)
1179 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1181 else
1182 #endif
1183 if (size > 0)
1184 ASM_OUTPUT_SKIP (asm_out_file, size);
1187 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1189 void
1190 assemble_align (int align)
1192 if (align > BITS_PER_UNIT)
1194 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1198 /* Assemble a string constant with the specified C string as contents. */
1200 void
1201 assemble_string (const char *p, int size)
1203 int pos = 0;
1204 int maximum = 2000;
1206 /* If the string is very long, split it up. */
1208 while (pos < size)
1210 int thissize = size - pos;
1211 if (thissize > maximum)
1212 thissize = maximum;
1214 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1216 pos += thissize;
1217 p += thissize;
1222 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1223 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1224 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1225 #else
1226 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1227 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1228 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1229 #else
1230 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1231 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1232 #endif
1233 #endif
1235 #if defined ASM_OUTPUT_ALIGNED_BSS
1236 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1237 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1238 #else
1239 #if defined ASM_OUTPUT_BSS
1240 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1241 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1242 #else
1243 #undef ASM_EMIT_BSS
1244 #endif
1245 #endif
1247 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1248 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1249 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1250 #else
1251 #if defined ASM_OUTPUT_ALIGNED_COMMON
1252 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1253 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1254 #else
1255 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1256 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1257 #endif
1258 #endif
1260 static bool
1261 asm_emit_uninitialised (tree decl, const char *name,
1262 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1263 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1265 enum
1267 asm_dest_common,
1268 asm_dest_bss,
1269 asm_dest_local
1271 destination = asm_dest_local;
1273 /* ??? We should handle .bss via select_section mechanisms rather than
1274 via special target hooks. That would eliminate this special case. */
1275 if (TREE_PUBLIC (decl))
1277 if (!DECL_COMMON (decl))
1278 #ifdef ASM_EMIT_BSS
1279 destination = asm_dest_bss;
1280 #else
1281 return false;
1282 #endif
1283 else
1284 destination = asm_dest_common;
1287 if (destination == asm_dest_bss)
1288 globalize_decl (decl);
1289 resolve_unique_section (decl, 0, flag_data_sections);
1291 if (flag_shared_data)
1293 switch (destination)
1295 #ifdef ASM_OUTPUT_SHARED_BSS
1296 case asm_dest_bss:
1297 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1298 return;
1299 #endif
1300 #ifdef ASM_OUTPUT_SHARED_COMMON
1301 case asm_dest_common:
1302 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1303 return;
1304 #endif
1305 #ifdef ASM_OUTPUT_SHARED_LOCAL
1306 case asm_dest_local:
1307 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1308 return;
1309 #endif
1310 default:
1311 break;
1315 switch (destination)
1317 #ifdef ASM_EMIT_BSS
1318 case asm_dest_bss:
1319 ASM_EMIT_BSS (decl, name, size, rounded);
1320 break;
1321 #endif
1322 case asm_dest_common:
1323 ASM_EMIT_COMMON (decl, name, size, rounded);
1324 break;
1325 case asm_dest_local:
1326 ASM_EMIT_LOCAL (decl, name, size, rounded);
1327 break;
1328 default:
1329 abort ();
1332 return true;
1335 /* Assemble everything that is needed for a variable or function declaration.
1336 Not used for automatic variables, and not used for function definitions.
1337 Should not be called for variables of incomplete structure type.
1339 TOP_LEVEL is nonzero if this variable has file scope.
1340 AT_END is nonzero if this is the special handling, at end of compilation,
1341 to define things that have had only tentative definitions.
1342 DONT_OUTPUT_DATA if nonzero means don't actually output the
1343 initial value (that will be done by the caller). */
1345 void
1346 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1347 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1349 const char *name;
1350 unsigned int align;
1351 int reloc = 0;
1352 rtx decl_rtl;
1354 if (lang_hooks.decls.prepare_assemble_variable)
1355 (*lang_hooks.decls.prepare_assemble_variable) (decl);
1357 last_assemble_variable_decl = 0;
1359 /* Normally no need to say anything here for external references,
1360 since assemble_external is called by the language-specific code
1361 when a declaration is first seen. */
1363 if (DECL_EXTERNAL (decl))
1364 return;
1366 /* Output no assembler code for a function declaration.
1367 Only definitions of functions output anything. */
1369 if (TREE_CODE (decl) == FUNCTION_DECL)
1370 return;
1372 /* Do nothing for global register variables. */
1373 if (DECL_RTL_SET_P (decl) && GET_CODE (DECL_RTL (decl)) == REG)
1375 TREE_ASM_WRITTEN (decl) = 1;
1376 return;
1379 /* If type was incomplete when the variable was declared,
1380 see if it is complete now. */
1382 if (DECL_SIZE (decl) == 0)
1383 layout_decl (decl, 0);
1385 /* Still incomplete => don't allocate it; treat the tentative defn
1386 (which is what it must have been) as an `extern' reference. */
1388 if (!dont_output_data && DECL_SIZE (decl) == 0)
1390 error ("%Jstorage size of `%D' isn't known", decl, decl);
1391 TREE_ASM_WRITTEN (decl) = 1;
1392 return;
1395 /* The first declaration of a variable that comes through this function
1396 decides whether it is global (in C, has external linkage)
1397 or local (in C, has internal linkage). So do nothing more
1398 if this function has already run. */
1400 if (TREE_ASM_WRITTEN (decl))
1401 return;
1403 /* Make sure targetm.encode_section_info is invoked before we set
1404 ASM_WRITTEN. */
1405 decl_rtl = DECL_RTL (decl);
1407 TREE_ASM_WRITTEN (decl) = 1;
1409 /* Do no output if -fsyntax-only. */
1410 if (flag_syntax_only)
1411 return;
1413 app_disable ();
1415 if (! dont_output_data
1416 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1418 error ("%Jsize of variable '%D' is too large", decl, decl);
1419 return;
1422 name = XSTR (XEXP (decl_rtl, 0), 0);
1423 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1424 notice_global_symbol (decl);
1426 /* Compute the alignment of this data. */
1428 align = DECL_ALIGN (decl);
1430 /* In the case for initialing an array whose length isn't specified,
1431 where we have not yet been able to do the layout,
1432 figure out the proper alignment now. */
1433 if (dont_output_data && DECL_SIZE (decl) == 0
1434 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1435 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1437 /* Some object file formats have a maximum alignment which they support.
1438 In particular, a.out format supports a maximum alignment of 4. */
1439 #ifndef MAX_OFILE_ALIGNMENT
1440 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1441 #endif
1442 if (align > MAX_OFILE_ALIGNMENT)
1444 warning ("%Jalignment of '%D' is greater than maximum object "
1445 "file alignment. Using %d", decl, decl,
1446 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1447 align = MAX_OFILE_ALIGNMENT;
1450 /* On some machines, it is good to increase alignment sometimes. */
1451 if (! DECL_USER_ALIGN (decl))
1453 #ifdef DATA_ALIGNMENT
1454 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1455 #endif
1456 #ifdef CONSTANT_ALIGNMENT
1457 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1458 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1459 #endif
1462 /* Reset the alignment in case we have made it tighter, so we can benefit
1463 from it in get_pointer_alignment. */
1464 DECL_ALIGN (decl) = align;
1465 set_mem_align (decl_rtl, align);
1467 if (TREE_PUBLIC (decl))
1468 maybe_assemble_visibility (decl);
1470 /* Output any data that we will need to use the address of. */
1471 if (DECL_INITIAL (decl) == error_mark_node)
1472 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1473 else if (DECL_INITIAL (decl))
1475 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1476 output_addressed_constants (DECL_INITIAL (decl));
1478 resolve_unique_section (decl, reloc, flag_data_sections);
1480 /* Handle uninitialized definitions. */
1482 /* If the decl has been given an explicit section name, then it
1483 isn't common, and shouldn't be handled as such. */
1484 if (DECL_SECTION_NAME (decl) || dont_output_data)
1486 /* We don't implement common thread-local data at present. */
1487 else if (DECL_THREAD_LOCAL (decl))
1489 if (DECL_COMMON (decl))
1490 sorry ("thread-local COMMON data not implemented");
1492 else if (DECL_INITIAL (decl) == 0
1493 || DECL_INITIAL (decl) == error_mark_node
1494 || (flag_zero_initialized_in_bss
1495 /* Leave constant zeroes in .rodata so they can be shared. */
1496 && !TREE_READONLY (decl)
1497 && initializer_zerop (DECL_INITIAL (decl))))
1499 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1500 unsigned HOST_WIDE_INT rounded = size;
1502 /* Don't allocate zero bytes of common,
1503 since that means "undefined external" in the linker. */
1504 if (size == 0)
1505 rounded = 1;
1507 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1508 so that each uninitialized object starts on such a boundary. */
1509 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1510 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1511 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1513 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1514 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1515 warning ("%Jrequested alignment for '%D' is greater than "
1516 "implemented alignment of %d", decl, decl, rounded);
1517 #endif
1519 /* If the target cannot output uninitialized but not common global data
1520 in .bss, then we have to use .data, so fall through. */
1521 if (asm_emit_uninitialised (decl, name, size, rounded))
1522 return;
1525 /* Handle initialized definitions.
1526 Also handle uninitialized global definitions if -fno-common and the
1527 target doesn't support ASM_OUTPUT_BSS. */
1529 /* First make the assembler name(s) global if appropriate. */
1530 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1531 globalize_decl (decl);
1533 /* Switch to the appropriate section. */
1534 variable_section (decl, reloc);
1536 /* dbxout.c needs to know this. */
1537 if (in_text_section ())
1538 DECL_IN_TEXT_SECTION (decl) = 1;
1540 /* Output the alignment of this data. */
1541 if (align > BITS_PER_UNIT)
1543 ASM_OUTPUT_ALIGN (asm_out_file,
1544 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1547 /* Do any machine/system dependent processing of the object. */
1548 #ifdef ASM_DECLARE_OBJECT_NAME
1549 last_assemble_variable_decl = decl;
1550 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1551 #else
1552 /* Standard thing is just output label for the object. */
1553 ASM_OUTPUT_LABEL (asm_out_file, name);
1554 #endif /* ASM_DECLARE_OBJECT_NAME */
1556 if (!dont_output_data)
1558 if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
1559 /* Output the actual data. */
1560 output_constant (DECL_INITIAL (decl),
1561 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1562 align);
1563 else
1564 /* Leave space for it. */
1565 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1569 /* Return 1 if type TYPE contains any pointers. */
1571 static int
1572 contains_pointers_p (tree type)
1574 switch (TREE_CODE (type))
1576 case POINTER_TYPE:
1577 case REFERENCE_TYPE:
1578 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1579 so I'll play safe and return 1. */
1580 case OFFSET_TYPE:
1581 return 1;
1583 case RECORD_TYPE:
1584 case UNION_TYPE:
1585 case QUAL_UNION_TYPE:
1587 tree fields;
1588 /* For a type that has fields, see if the fields have pointers. */
1589 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1590 if (TREE_CODE (fields) == FIELD_DECL
1591 && contains_pointers_p (TREE_TYPE (fields)))
1592 return 1;
1593 return 0;
1596 case ARRAY_TYPE:
1597 /* An array type contains pointers if its element type does. */
1598 return contains_pointers_p (TREE_TYPE (type));
1600 default:
1601 return 0;
1605 #ifdef ASM_OUTPUT_EXTERNAL
1606 /* True if DECL is a function decl for which no out-of-line copy exists.
1607 It is assumed that DECL's assembler name has been set. */
1609 static bool
1610 incorporeal_function_p (tree decl)
1612 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1614 const char *name;
1616 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1617 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1618 return true;
1620 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1621 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1622 return true;
1624 return false;
1626 #endif
1628 /* Output something to declare an external symbol to the assembler.
1629 (Most assemblers don't need this, so we normally output nothing.)
1630 Do nothing if DECL is not external. */
1632 void
1633 assemble_external (tree decl ATTRIBUTE_UNUSED)
1635 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1636 main body of this code is only rarely exercised. To provide some
1637 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1638 open. If it's not, we should not be calling this function. */
1639 if (!asm_out_file)
1640 abort ();
1642 #ifdef ASM_OUTPUT_EXTERNAL
1643 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1645 rtx rtl = DECL_RTL (decl);
1647 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1648 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1649 && !incorporeal_function_p (decl))
1651 /* Some systems do require some output. */
1652 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1653 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1656 #endif
1659 /* Similar, for calling a library function FUN. */
1661 void
1662 assemble_external_libcall (rtx fun)
1664 /* Declare library function name external when first used, if nec. */
1665 if (! SYMBOL_REF_USED (fun))
1667 SYMBOL_REF_USED (fun) = 1;
1668 (*targetm.asm_out.external_libcall) (fun);
1672 /* Assemble a label named NAME. */
1674 void
1675 assemble_label (const char *name)
1677 ASM_OUTPUT_LABEL (asm_out_file, name);
1680 /* Set the symbol_referenced flag for ID and notify callgraph code. */
1681 void
1682 mark_referenced (tree id)
1684 if (!TREE_SYMBOL_REFERENCED (id))
1686 struct cgraph_node *node;
1687 struct cgraph_varpool_node *vnode;
1689 if (!cgraph_global_info_ready)
1691 node = cgraph_node_for_identifier (id);
1692 if (node)
1693 cgraph_mark_needed_node (node);
1696 vnode = cgraph_varpool_node_for_identifier (id);
1697 if (vnode)
1698 cgraph_varpool_mark_needed_node (vnode);
1700 TREE_SYMBOL_REFERENCED (id) = 1;
1703 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1704 If NAME starts with a *, the rest of NAME is output verbatim.
1705 Otherwise NAME is transformed in an implementation-defined way
1706 (usually by the addition of an underscore).
1707 Many macros in the tm file are defined to call this function. */
1709 void
1710 assemble_name (FILE *file, const char *name)
1712 const char *real_name;
1713 tree id;
1715 real_name = (* targetm.strip_name_encoding) (name);
1717 id = maybe_get_identifier (real_name);
1718 if (id)
1719 mark_referenced (id);
1721 if (name[0] == '*')
1722 fputs (&name[1], file);
1723 else
1724 ASM_OUTPUT_LABELREF (file, name);
1727 /* Allocate SIZE bytes writable static space with a gensym name
1728 and return an RTX to refer to its address. */
1731 assemble_static_space (unsigned HOST_WIDE_INT size)
1733 char name[12];
1734 const char *namestring;
1735 rtx x;
1737 #if 0
1738 if (flag_shared_data)
1739 data_section ();
1740 #endif
1742 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1743 ++const_labelno;
1744 namestring = ggc_strdup (name);
1746 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1747 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1749 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1750 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1751 BIGGEST_ALIGNMENT);
1752 #else
1753 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1754 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1755 #else
1757 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1758 so that each uninitialized object starts on such a boundary. */
1759 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1760 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1761 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1762 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1763 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1764 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1766 #endif
1767 #endif
1768 return x;
1771 /* Assemble the static constant template for function entry trampolines.
1772 This is done at most once per compilation.
1773 Returns an RTX for the address of the template. */
1775 #ifdef TRAMPOLINE_TEMPLATE
1777 assemble_trampoline_template (void)
1779 char label[256];
1780 const char *name;
1781 int align;
1782 rtx symbol;
1784 /* By default, put trampoline templates in read-only data section. */
1786 #ifdef TRAMPOLINE_SECTION
1787 TRAMPOLINE_SECTION ();
1788 #else
1789 readonly_data_section ();
1790 #endif
1792 /* Write the assembler code to define one. */
1793 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1794 if (align > 0)
1796 ASM_OUTPUT_ALIGN (asm_out_file, align);
1799 (*targetm.asm_out.internal_label) (asm_out_file, "LTRAMP", 0);
1800 TRAMPOLINE_TEMPLATE (asm_out_file);
1802 /* Record the rtl to refer to it. */
1803 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1804 name = ggc_strdup (label);
1805 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
1806 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
1808 return symbol;
1810 #endif
1812 /* A and B are either alignments or offsets. Return the minimum alignment
1813 that may be assumed after adding the two together. */
1815 static inline unsigned
1816 min_align (unsigned int a, unsigned int b)
1818 return (a | b) & -(a | b);
1821 /* Return the assembler directive for creating a given kind of integer
1822 object. SIZE is the number of bytes in the object and ALIGNED_P
1823 indicates whether it is known to be aligned. Return NULL if the
1824 assembly dialect has no such directive.
1826 The returned string should be printed at the start of a new line and
1827 be followed immediately by the object's initial value. */
1829 const char *
1830 integer_asm_op (int size, int aligned_p)
1832 struct asm_int_op *ops;
1834 if (aligned_p)
1835 ops = &targetm.asm_out.aligned_op;
1836 else
1837 ops = &targetm.asm_out.unaligned_op;
1839 switch (size)
1841 case 1:
1842 return targetm.asm_out.byte_op;
1843 case 2:
1844 return ops->hi;
1845 case 4:
1846 return ops->si;
1847 case 8:
1848 return ops->di;
1849 case 16:
1850 return ops->ti;
1851 default:
1852 return NULL;
1856 /* Use directive OP to assemble an integer object X. Print OP at the
1857 start of the line, followed immediately by the value of X. */
1859 void
1860 assemble_integer_with_op (const char *op, rtx x)
1862 fputs (op, asm_out_file);
1863 output_addr_const (asm_out_file, x);
1864 fputc ('\n', asm_out_file);
1867 /* The default implementation of the asm_out.integer target hook. */
1869 bool
1870 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
1871 unsigned int size ATTRIBUTE_UNUSED,
1872 int aligned_p ATTRIBUTE_UNUSED)
1874 const char *op = integer_asm_op (size, aligned_p);
1875 return op && (assemble_integer_with_op (op, x), true);
1878 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1879 the alignment of the integer in bits. Return 1 if we were able to output
1880 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
1881 the constant. */
1883 bool
1884 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
1886 int aligned_p;
1888 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
1890 /* See if the target hook can handle this kind of object. */
1891 if ((*targetm.asm_out.integer) (x, size, aligned_p))
1892 return true;
1894 /* If the object is a multi-byte one, try splitting it up. Split
1895 it into words it if is multi-word, otherwise split it into bytes. */
1896 if (size > 1)
1898 enum machine_mode omode, imode;
1899 unsigned int subalign;
1900 unsigned int subsize, i;
1902 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
1903 subalign = MIN (align, subsize * BITS_PER_UNIT);
1904 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
1905 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1907 for (i = 0; i < size; i += subsize)
1909 rtx partial = simplify_subreg (omode, x, imode, i);
1910 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
1911 break;
1913 if (i == size)
1914 return true;
1916 /* If we've printed some of it, but not all of it, there's no going
1917 back now. */
1918 if (i > 0)
1919 abort ();
1922 if (force)
1923 abort ();
1925 return false;
1928 void
1929 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
1931 long data[4];
1932 int i;
1933 int bitsize, nelts, nunits, units_per;
1935 /* This is hairy. We have a quantity of known size. real_to_target
1936 will put it into an array of *host* longs, 32 bits per element
1937 (even if long is more than 32 bits). We need to determine the
1938 number of array elements that are occupied (nelts) and the number
1939 of *target* min-addressable units that will be occupied in the
1940 object file (nunits). We cannot assume that 32 divides the
1941 mode's bitsize (size * BITS_PER_UNIT) evenly.
1943 size * BITS_PER_UNIT is used here to make sure that padding bits
1944 (which might appear at either end of the value; real_to_target
1945 will include the padding bits in its output array) are included. */
1947 nunits = GET_MODE_SIZE (mode);
1948 bitsize = nunits * BITS_PER_UNIT;
1949 nelts = CEIL (bitsize, 32);
1950 units_per = 32 / BITS_PER_UNIT;
1952 real_to_target (data, &d, mode);
1954 /* Put out the first word with the specified alignment. */
1955 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
1956 nunits -= units_per;
1958 /* Subsequent words need only 32-bit alignment. */
1959 align = min_align (align, 32);
1961 for (i = 1; i < nelts; i++)
1963 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
1964 nunits -= units_per;
1968 /* Given an expression EXP with a constant value,
1969 reduce it to the sum of an assembler symbol and an integer.
1970 Store them both in the structure *VALUE.
1971 Abort if EXP does not reduce. */
1973 struct addr_const GTY(())
1975 rtx base;
1976 HOST_WIDE_INT offset;
1979 static void
1980 decode_addr_const (tree exp, struct addr_const *value)
1982 tree target = TREE_OPERAND (exp, 0);
1983 int offset = 0;
1984 rtx x;
1986 while (1)
1988 if (TREE_CODE (target) == COMPONENT_REF
1989 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
1992 offset += int_byte_position (TREE_OPERAND (target, 1));
1993 target = TREE_OPERAND (target, 0);
1995 else if (TREE_CODE (target) == ARRAY_REF
1996 || TREE_CODE (target) == ARRAY_RANGE_REF)
1998 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
1999 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2000 target = TREE_OPERAND (target, 0);
2002 else
2003 break;
2006 switch (TREE_CODE (target))
2008 case VAR_DECL:
2009 case FUNCTION_DECL:
2010 x = DECL_RTL (target);
2011 break;
2013 case LABEL_DECL:
2014 x = gen_rtx_MEM (FUNCTION_MODE,
2015 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2016 break;
2018 case REAL_CST:
2019 case STRING_CST:
2020 case COMPLEX_CST:
2021 case CONSTRUCTOR:
2022 case INTEGER_CST:
2023 x = output_constant_def (target, 1);
2024 break;
2026 default:
2027 abort ();
2030 if (GET_CODE (x) != MEM)
2031 abort ();
2032 x = XEXP (x, 0);
2034 value->base = x;
2035 value->offset = offset;
2038 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2039 enum kind { RTX_UNKNOWN, RTX_DOUBLE, RTX_VECTOR, RTX_INT, RTX_UNSPEC };
2040 struct rtx_const GTY(())
2042 ENUM_BITFIELD(kind) kind : 16;
2043 ENUM_BITFIELD(machine_mode) mode : 16;
2044 union rtx_const_un {
2045 REAL_VALUE_TYPE GTY ((tag ("4"))) du;
2046 struct rtx_const_u_addr {
2047 rtx base;
2048 const char *symbol;
2049 HOST_WIDE_INT offset;
2050 } GTY ((tag ("1"))) addr;
2051 struct rtx_const_u_di {
2052 HOST_WIDE_INT high;
2053 HOST_WIDE_INT low;
2054 } GTY ((tag ("0"))) di;
2056 /* The max vector size we have is 16 wide; two variants for
2057 integral and floating point vectors. */
2058 struct rtx_const_int_vec {
2059 HOST_WIDE_INT high;
2060 HOST_WIDE_INT low;
2061 } GTY ((tag ("2"))) int_vec[16];
2063 REAL_VALUE_TYPE GTY ((tag ("3"))) fp_vec[8];
2065 } GTY ((desc ("%1.kind >= RTX_INT"), descbits ("1"))) un;
2068 /* Uniquize all constants that appear in memory.
2069 Each constant in memory thus far output is recorded
2070 in `const_hash_table'. */
2072 struct constant_descriptor_tree GTY(())
2074 /* A MEM for the constant. */
2075 rtx rtl;
2077 /* The value of the constant. */
2078 tree value;
2081 static GTY((param_is (struct constant_descriptor_tree)))
2082 htab_t const_desc_htab;
2084 static struct constant_descriptor_tree * build_constant_desc (tree);
2085 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2087 /* Compute a hash code for a constant expression. */
2089 static hashval_t
2090 const_desc_hash (const void *ptr)
2092 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2095 static hashval_t
2096 const_hash_1 (const tree exp)
2098 const char *p;
2099 hashval_t hi;
2100 int len, i;
2101 enum tree_code code = TREE_CODE (exp);
2103 /* Either set P and LEN to the address and len of something to hash and
2104 exit the switch or return a value. */
2106 switch (code)
2108 case INTEGER_CST:
2109 p = (char *) &TREE_INT_CST (exp);
2110 len = sizeof TREE_INT_CST (exp);
2111 break;
2113 case REAL_CST:
2114 return real_hash (TREE_REAL_CST_PTR (exp));
2116 case STRING_CST:
2117 p = TREE_STRING_POINTER (exp);
2118 len = TREE_STRING_LENGTH (exp);
2119 break;
2120 case COMPLEX_CST:
2121 return (const_hash_1 (TREE_REALPART (exp)) * 5
2122 + const_hash_1 (TREE_IMAGPART (exp)));
2124 case CONSTRUCTOR:
2125 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2127 char *tmp;
2129 len = int_size_in_bytes (TREE_TYPE (exp));
2130 tmp = alloca (len);
2131 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2132 p = tmp;
2133 break;
2135 else
2137 tree link;
2139 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2141 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2142 if (TREE_VALUE (link))
2143 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2145 return hi;
2148 case ADDR_EXPR:
2149 case FDESC_EXPR:
2151 struct addr_const value;
2153 decode_addr_const (exp, &value);
2154 if (GET_CODE (value.base) == SYMBOL_REF)
2156 /* Don't hash the address of the SYMBOL_REF;
2157 only use the offset and the symbol name. */
2158 hi = value.offset;
2159 p = XSTR (value.base, 0);
2160 for (i = 0; p[i] != 0; i++)
2161 hi = ((hi * 613) + (unsigned) (p[i]));
2163 else if (GET_CODE (value.base) == LABEL_REF)
2164 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2165 else
2166 abort ();
2168 return hi;
2170 case PLUS_EXPR:
2171 case MINUS_EXPR:
2172 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2173 + const_hash_1 (TREE_OPERAND (exp, 1)));
2175 case NOP_EXPR:
2176 case CONVERT_EXPR:
2177 case NON_LVALUE_EXPR:
2178 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2180 default:
2181 /* A language specific constant. Just hash the code. */
2182 return code;
2185 /* Compute hashing function. */
2186 hi = len;
2187 for (i = 0; i < len; i++)
2188 hi = ((hi * 613) + (unsigned) (p[i]));
2190 return hi;
2193 /* Wrapper of compare_constant, for the htab interface. */
2194 static int
2195 const_desc_eq (const void *p1, const void *p2)
2197 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2198 ((struct constant_descriptor_tree *)p2)->value);
2201 /* Compare t1 and t2, and return 1 only if they are known to result in
2202 the same bit pattern on output. */
2204 static int
2205 compare_constant (const tree t1, const tree t2)
2207 enum tree_code typecode;
2209 if (t1 == NULL_TREE)
2210 return t2 == NULL_TREE;
2211 if (t2 == NULL_TREE)
2212 return 0;
2214 if (TREE_CODE (t1) != TREE_CODE (t2))
2215 return 0;
2217 switch (TREE_CODE (t1))
2219 case INTEGER_CST:
2220 /* Integer constants are the same only if the same width of type. */
2221 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2222 return 0;
2223 return tree_int_cst_equal (t1, t2);
2225 case REAL_CST:
2226 /* Real constants are the same only if the same width of type. */
2227 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2228 return 0;
2230 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2232 case STRING_CST:
2233 if (flag_writable_strings)
2234 return 0;
2236 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2237 return 0;
2239 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2240 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2241 TREE_STRING_LENGTH (t1)));
2243 case COMPLEX_CST:
2244 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2245 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2247 case CONSTRUCTOR:
2248 typecode = TREE_CODE (TREE_TYPE (t1));
2249 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2250 return 0;
2252 if (typecode == SET_TYPE)
2254 int len = int_size_in_bytes (TREE_TYPE (t2));
2255 unsigned char *tmp1, *tmp2;
2257 if (int_size_in_bytes (TREE_TYPE (t1)) != len)
2258 return 0;
2260 tmp1 = alloca (len);
2261 tmp2 = alloca (len);
2263 if (get_set_constructor_bytes (t1, tmp1, len) != NULL_TREE)
2264 return 0;
2265 if (get_set_constructor_bytes (t2, tmp2, len) != NULL_TREE)
2266 return 0;
2268 return memcmp (tmp1, tmp2, len) == 0;
2270 else
2272 tree l1, l2;
2274 if (typecode == ARRAY_TYPE)
2276 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2277 /* For arrays, check that the sizes all match. */
2278 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2279 || size_1 == -1
2280 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2281 return 0;
2283 else
2285 /* For record and union constructors, require exact type
2286 equality. */
2287 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2288 return 0;
2291 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2292 l1 && l2;
2293 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2295 /* Check that each value is the same... */
2296 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2297 return 0;
2298 /* ... and that they apply to the same fields! */
2299 if (typecode == ARRAY_TYPE)
2301 if (! compare_constant (TREE_PURPOSE (l1),
2302 TREE_PURPOSE (l2)))
2303 return 0;
2305 else
2307 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2308 return 0;
2312 return l1 == NULL_TREE && l2 == NULL_TREE;
2315 case ADDR_EXPR:
2316 case FDESC_EXPR:
2318 struct addr_const value1, value2;
2320 decode_addr_const (t1, &value1);
2321 decode_addr_const (t2, &value2);
2322 return (value1.offset == value2.offset
2323 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2326 case PLUS_EXPR:
2327 case MINUS_EXPR:
2328 case RANGE_EXPR:
2329 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2330 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2332 case NOP_EXPR:
2333 case CONVERT_EXPR:
2334 case NON_LVALUE_EXPR:
2335 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2337 default:
2339 tree nt1, nt2;
2340 nt1 = (*lang_hooks.expand_constant) (t1);
2341 nt2 = (*lang_hooks.expand_constant) (t2);
2342 if (nt1 != t1 || nt2 != t2)
2343 return compare_constant (nt1, nt2);
2344 else
2345 return 0;
2349 /* Should not get here. */
2350 abort ();
2353 /* Make a copy of the whole tree structure for a constant. This
2354 handles the same types of nodes that compare_constant handles. */
2356 static tree
2357 copy_constant (tree exp)
2359 switch (TREE_CODE (exp))
2361 case ADDR_EXPR:
2362 /* For ADDR_EXPR, we do not want to copy the decl whose address
2363 is requested. We do want to copy constants though. */
2364 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2365 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2366 copy_constant (TREE_OPERAND (exp, 0)));
2367 else
2368 return copy_node (exp);
2370 case INTEGER_CST:
2371 case REAL_CST:
2372 case STRING_CST:
2373 return copy_node (exp);
2375 case COMPLEX_CST:
2376 return build_complex (TREE_TYPE (exp),
2377 copy_constant (TREE_REALPART (exp)),
2378 copy_constant (TREE_IMAGPART (exp)));
2380 case PLUS_EXPR:
2381 case MINUS_EXPR:
2382 return build (TREE_CODE (exp), TREE_TYPE (exp),
2383 copy_constant (TREE_OPERAND (exp, 0)),
2384 copy_constant (TREE_OPERAND (exp, 1)));
2386 case NOP_EXPR:
2387 case CONVERT_EXPR:
2388 case NON_LVALUE_EXPR:
2389 case VIEW_CONVERT_EXPR:
2390 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2391 copy_constant (TREE_OPERAND (exp, 0)));
2393 case CONSTRUCTOR:
2395 tree copy = copy_node (exp);
2396 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2397 tree tail;
2399 CONSTRUCTOR_ELTS (copy) = list;
2400 for (tail = list; tail; tail = TREE_CHAIN (tail))
2401 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2402 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2403 for (tail = list; tail; tail = TREE_CHAIN (tail))
2404 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2406 return copy;
2409 default:
2411 tree t;
2412 t = (*lang_hooks.expand_constant) (exp);
2413 if (t != exp)
2414 return copy_constant (t);
2415 else
2416 abort ();
2421 /* Subroutine of output_constant_def:
2422 No constant equal to EXP is known to have been output.
2423 Make a constant descriptor to enter EXP in the hash table.
2424 Assign the label number and construct RTL to refer to the
2425 constant's location in memory.
2426 Caller is responsible for updating the hash table. */
2428 static struct constant_descriptor_tree *
2429 build_constant_desc (tree exp)
2431 rtx symbol;
2432 rtx rtl;
2433 char label[256];
2434 int labelno;
2435 struct constant_descriptor_tree *desc;
2437 desc = ggc_alloc (sizeof (*desc));
2438 desc->value = copy_constant (exp);
2440 /* Create a string containing the label name, in LABEL. */
2441 labelno = const_labelno++;
2442 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2444 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2445 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2446 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2447 SYMBOL_REF_DECL (symbol) = desc->value;
2448 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2450 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2451 set_mem_attributes (rtl, exp, 1);
2452 set_mem_alias_set (rtl, 0);
2453 set_mem_alias_set (rtl, const_alias_set);
2455 /* Set flags or add text to the name to record information, such as
2456 that it is a local symbol. If the name is changed, the macro
2457 ASM_OUTPUT_LABELREF will have to know how to strip this
2458 information. This call might invalidate our local variable
2459 SYMBOL; we can't use it afterward. */
2461 (*targetm.encode_section_info) (exp, rtl, true);
2463 desc->rtl = rtl;
2465 return desc;
2468 /* Return an rtx representing a reference to constant data in memory
2469 for the constant expression EXP.
2471 If assembler code for such a constant has already been output,
2472 return an rtx to refer to it.
2473 Otherwise, output such a constant in memory
2474 and generate an rtx for it.
2476 If DEFER is nonzero, this constant can be deferred and output only
2477 if referenced in the function after all optimizations.
2479 The const_hash_table records which constants already have label strings. */
2482 output_constant_def (tree exp, int defer)
2484 struct constant_descriptor_tree *desc;
2485 struct constant_descriptor_tree key;
2486 void **loc;
2488 /* Look up EXP in the table of constant descriptors. If we didn't find
2489 it, create a new one. */
2490 key.value = exp;
2491 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2493 desc = *loc;
2494 if (desc == 0)
2496 desc = build_constant_desc (exp);
2497 *loc = desc;
2500 maybe_output_constant_def_contents (desc, defer);
2501 return desc->rtl;
2504 /* Subroutine of output_constant_def: Decide whether or not we need to
2505 output the constant DESC now, and if so, do it. */
2506 static void
2507 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2508 int defer)
2510 rtx symbol = XEXP (desc->rtl, 0);
2511 tree exp = desc->value;
2513 if (flag_syntax_only)
2514 return;
2516 if (TREE_ASM_WRITTEN (exp))
2517 /* Already output; don't do it again. */
2518 return;
2520 /* The only constants that cannot safely be deferred, assuming the
2521 context allows it, are strings under flag_writable_strings. */
2522 if (defer && (TREE_CODE (exp) != STRING_CST || !flag_writable_strings))
2524 /* Increment n_deferred_constants if it exists. It needs to be at
2525 least as large as the number of constants actually referred to
2526 by the function. If it's too small we'll stop looking too early
2527 and fail to emit constants; if it's too large we'll only look
2528 through the entire function when we could have stopped earlier. */
2529 if (cfun)
2530 n_deferred_constants++;
2531 return;
2534 output_constant_def_contents (symbol);
2537 /* We must output the constant data referred to by SYMBOL; do so. */
2539 static void
2540 output_constant_def_contents (rtx symbol)
2542 tree exp = SYMBOL_REF_DECL (symbol);
2543 const char *label = XSTR (symbol, 0);
2544 HOST_WIDE_INT size;
2546 /* Make sure any other constants whose addresses appear in EXP
2547 are assigned label numbers. */
2548 int reloc = compute_reloc_for_constant (exp);
2550 /* Align the location counter as required by EXP's data type. */
2551 int align = TYPE_ALIGN (TREE_TYPE (exp));
2552 #ifdef CONSTANT_ALIGNMENT
2553 align = CONSTANT_ALIGNMENT (exp, align);
2554 #endif
2556 output_addressed_constants (exp);
2558 /* We are no longer deferring this constant. */
2559 TREE_ASM_WRITTEN (exp) = 1;
2561 if (IN_NAMED_SECTION (exp))
2562 named_section (exp, NULL, reloc);
2563 else
2564 (*targetm.asm_out.select_section) (exp, reloc, align);
2566 if (align > BITS_PER_UNIT)
2568 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2571 size = int_size_in_bytes (TREE_TYPE (exp));
2572 if (TREE_CODE (exp) == STRING_CST)
2573 size = MAX (TREE_STRING_LENGTH (exp), size);
2575 /* Do any machine/system dependent processing of the constant. */
2576 #ifdef ASM_DECLARE_CONSTANT_NAME
2577 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2578 #else
2579 /* Standard thing is just output label for the constant. */
2580 ASM_OUTPUT_LABEL (asm_out_file, label);
2581 #endif /* ASM_DECLARE_CONSTANT_NAME */
2583 /* Output the value of EXP. */
2584 output_constant (exp, size, align);
2587 /* A constant which was deferred in its original location has been
2588 inserted by the RTL inliner into a different function. The
2589 current function's deferred constant count must be incremented. */
2590 void
2591 notice_rtl_inlining_of_deferred_constant (void)
2593 n_deferred_constants++;
2596 /* Look up EXP in the table of constant descriptors. Return the rtl
2597 if it has been emitted, else null. */
2600 lookup_constant_def (tree exp)
2602 struct constant_descriptor_tree *desc;
2603 struct constant_descriptor_tree key;
2605 key.value = exp;
2606 desc = htab_find (const_desc_htab, &key);
2608 return (desc ? desc->rtl : NULL_RTX);
2611 /* Used in the hash tables to avoid outputting the same constant
2612 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2613 are output once per function, not once per file; there seems
2614 to be no reason for the difference. */
2616 struct constant_descriptor_rtx GTY(())
2618 /* More constant_descriptors with the same hash code. */
2619 struct constant_descriptor_rtx *next;
2621 /* A MEM for the constant. */
2622 rtx rtl;
2624 /* The value of the constant. */
2625 struct rtx_const value;
2628 /* Structure to represent sufficient information about a constant so that
2629 it can be output when the constant pool is output, so that function
2630 integration can be done, and to simplify handling on machines that reference
2631 constant pool as base+displacement. */
2633 struct pool_constant GTY(())
2635 struct constant_descriptor_rtx *desc;
2636 struct pool_constant *next;
2637 struct pool_constant *next_sym;
2638 rtx constant;
2639 enum machine_mode mode;
2640 int labelno;
2641 unsigned int align;
2642 HOST_WIDE_INT offset;
2643 int mark;
2646 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2647 The argument is XSTR (... , 0) */
2649 #define SYMHASH(LABEL) (((unsigned long) (LABEL)) % MAX_RTX_HASH_TABLE)
2651 /* Initialize constant pool hashing for a new function. */
2653 void
2654 init_varasm_status (struct function *f)
2656 struct varasm_status *p;
2657 p = ggc_alloc (sizeof (struct varasm_status));
2658 f->varasm = p;
2659 p->x_const_rtx_hash_table
2660 = ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2661 * sizeof (struct constant_descriptor_rtx *));
2662 p->x_const_rtx_sym_hash_table
2663 = ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2664 * sizeof (struct pool_constant *));
2666 p->x_first_pool = p->x_last_pool = 0;
2667 p->x_pool_offset = 0;
2668 p->deferred_constants = 0;
2672 /* Express an rtx for a constant integer (perhaps symbolic)
2673 as the sum of a symbol or label plus an explicit integer.
2674 They are stored into VALUE. */
2676 static void
2677 decode_rtx_const (enum machine_mode mode, rtx x, struct rtx_const *value)
2679 /* Clear the whole structure, including any gaps. */
2680 memset (value, 0, sizeof (struct rtx_const));
2682 value->kind = RTX_INT; /* Most usual kind. */
2683 value->mode = mode;
2685 switch (GET_CODE (x))
2687 case CONST_DOUBLE:
2688 value->kind = RTX_DOUBLE;
2689 if (GET_MODE (x) != VOIDmode)
2691 const REAL_VALUE_TYPE *r = CONST_DOUBLE_REAL_VALUE (x);
2693 value->mode = GET_MODE (x);
2695 /* Copy the REAL_VALUE_TYPE by members so that we don't
2696 copy garbage from the original structure into our
2697 carefully cleaned hashing structure. */
2698 value->un.du.class = r->class;
2699 value->un.du.sign = r->sign;
2700 switch (r->class)
2702 case rvc_zero:
2703 case rvc_inf:
2704 break;
2705 case rvc_normal:
2706 value->un.du.exp = r->exp;
2707 /* FALLTHRU */
2708 case rvc_nan:
2709 memcpy (value->un.du.sig, r->sig, sizeof (r->sig));
2710 break;
2711 default:
2712 abort ();
2715 else
2717 value->un.di.low = CONST_DOUBLE_LOW (x);
2718 value->un.di.high = CONST_DOUBLE_HIGH (x);
2720 break;
2722 case CONST_VECTOR:
2724 int units, i;
2726 units = CONST_VECTOR_NUNITS (x);
2727 value->kind = RTX_VECTOR;
2728 value->mode = mode;
2730 if (GET_MODE_CLASS (mode) == MODE_VECTOR_INT)
2732 for (i = 0; i < units; ++i)
2734 rtx elt = CONST_VECTOR_ELT (x, i);
2735 if (GET_CODE (elt) == CONST_INT)
2737 value->un.int_vec[i].low = INTVAL (elt);
2738 value->un.int_vec[i].high = 0;
2740 else
2742 value->un.int_vec[i].low = CONST_DOUBLE_LOW (elt);
2743 value->un.int_vec[i].high = CONST_DOUBLE_HIGH (elt);
2747 else if (GET_MODE_CLASS (mode) == MODE_VECTOR_FLOAT)
2749 for (i = 0; i < units; ++i)
2751 const REAL_VALUE_TYPE *r
2752 = CONST_DOUBLE_REAL_VALUE (CONST_VECTOR_ELT (x, i));
2753 REAL_VALUE_TYPE *d = &value->un.fp_vec[i];
2755 /* Copy the REAL_VALUE_TYPE by members so that we don't
2756 copy garbage from the original structure into our
2757 carefully cleaned hashing structure. */
2758 d->class = r->class;
2759 d->sign = r->sign;
2760 switch (r->class)
2762 case rvc_zero:
2763 case rvc_inf:
2764 break;
2765 case rvc_normal:
2766 d->exp = r->exp;
2767 /* FALLTHRU */
2768 case rvc_nan:
2769 memcpy (d->sig, r->sig, sizeof (r->sig));
2770 break;
2771 default:
2772 abort ();
2776 else
2777 abort ();
2779 break;
2781 case CONST_INT:
2782 value->un.addr.offset = INTVAL (x);
2783 break;
2785 case SYMBOL_REF:
2786 case LABEL_REF:
2787 case PC:
2788 value->un.addr.base = x;
2789 break;
2791 case CONST:
2792 x = XEXP (x, 0);
2793 if (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2795 value->un.addr.base = XEXP (x, 0);
2796 value->un.addr.offset = INTVAL (XEXP (x, 1));
2798 else if (GET_CODE (x) == MINUS && GET_CODE (XEXP (x, 1)) == CONST_INT)
2800 value->un.addr.base = XEXP (x, 0);
2801 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2803 else
2805 value->un.addr.base = x;
2806 value->un.addr.offset = 0;
2808 break;
2810 default:
2811 value->kind = RTX_UNKNOWN;
2812 break;
2815 if (value->kind == RTX_INT && value->un.addr.base != 0
2816 && GET_CODE (value->un.addr.base) == UNSPEC)
2818 /* For a simple UNSPEC, the base is set to the
2819 operand, the kind field is set to the index of
2820 the unspec expression.
2821 Together with the code below, in case that
2822 the operand is a SYMBOL_REF or LABEL_REF,
2823 the address of the string or the code_label
2824 is taken as base. */
2825 if (XVECLEN (value->un.addr.base, 0) == 1)
2827 value->kind = RTX_UNSPEC + XINT (value->un.addr.base, 1);
2828 value->un.addr.base = XVECEXP (value->un.addr.base, 0, 0);
2832 if (value->kind >= RTX_INT && value->un.addr.base != 0)
2833 switch (GET_CODE (value->un.addr.base))
2835 case SYMBOL_REF:
2836 /* Use the string's address, not the SYMBOL_REF's address,
2837 for the sake of addresses of library routines. */
2838 value->un.addr.symbol = XSTR (value->un.addr.base, 0);
2839 value->un.addr.base = NULL_RTX;
2840 break;
2842 case LABEL_REF:
2843 /* For a LABEL_REF, compare labels. */
2844 value->un.addr.base = XEXP (value->un.addr.base, 0);
2846 default:
2847 break;
2851 /* Given a MINUS expression, simplify it if both sides
2852 include the same symbol. */
2855 simplify_subtraction (rtx x)
2857 struct rtx_const val0, val1;
2859 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2860 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2862 if (val0.kind >= RTX_INT
2863 && val0.kind == val1.kind
2864 && val0.un.addr.base == val1.un.addr.base
2865 && val0.un.addr.symbol == val1.un.addr.symbol)
2866 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2868 return x;
2871 /* Compute a hash code for a constant RTL expression. */
2873 static unsigned int
2874 const_hash_rtx (enum machine_mode mode, rtx x)
2876 union {
2877 struct rtx_const value;
2878 unsigned int data[sizeof(struct rtx_const) / sizeof (unsigned int)];
2879 } u;
2881 unsigned int hi;
2882 size_t i;
2884 decode_rtx_const (mode, x, &u.value);
2886 /* Compute hashing function. */
2887 hi = 0;
2888 for (i = 0; i < ARRAY_SIZE (u.data); i++)
2889 hi = hi * 613 + u.data[i];
2891 return hi % MAX_RTX_HASH_TABLE;
2894 /* Compare a constant rtl object X with a constant-descriptor DESC.
2895 Return 1 if DESC describes a constant with the same value as X. */
2897 static int
2898 compare_constant_rtx (enum machine_mode mode, rtx x,
2899 struct constant_descriptor_rtx *desc)
2901 struct rtx_const value;
2903 decode_rtx_const (mode, x, &value);
2905 /* Compare constant contents. */
2906 return memcmp (&value, &desc->value, sizeof (struct rtx_const)) == 0;
2909 /* Construct a constant descriptor for the rtl-expression X.
2910 It is up to the caller to enter the descriptor in the hash table. */
2912 static struct constant_descriptor_rtx *
2913 record_constant_rtx (enum machine_mode mode, rtx x)
2915 struct constant_descriptor_rtx *ptr;
2917 ptr = ggc_alloc (sizeof (*ptr));
2918 decode_rtx_const (mode, x, &ptr->value);
2920 return ptr;
2923 /* Given a constant rtx X, make (or find) a memory constant for its value
2924 and return a MEM rtx to refer to it in memory. */
2927 force_const_mem (enum machine_mode mode, rtx x)
2929 int hash;
2930 struct constant_descriptor_rtx *desc;
2931 char label[256];
2932 rtx def, symbol;
2933 struct pool_constant *pool;
2934 unsigned int align;
2936 /* If we're not allowed to drop X into the constant pool, don't. */
2937 if ((*targetm.cannot_force_const_mem) (x))
2938 return NULL_RTX;
2940 /* Compute hash code of X. Search the descriptors for that hash code
2941 to see if any of them describes X. If yes, we have an rtx to use. */
2942 hash = const_hash_rtx (mode, x);
2943 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2944 if (compare_constant_rtx (mode, x, desc))
2945 return copy_rtx (desc->rtl);
2947 /* No constant equal to X is known to have been output.
2948 Make a constant descriptor to enter X in the hash table
2949 and make a MEM for it. */
2950 desc = record_constant_rtx (mode, x);
2951 desc->next = const_rtx_hash_table[hash];
2952 const_rtx_hash_table[hash] = desc;
2954 /* Align the location counter as required by EXP's data type. */
2955 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2956 #ifdef CONSTANT_ALIGNMENT
2958 tree type = (*lang_hooks.types.type_for_mode) (mode, 0);
2959 if (type != NULL_TREE)
2960 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2962 #endif
2964 pool_offset += (align / BITS_PER_UNIT) - 1;
2965 pool_offset &= ~ ((align / BITS_PER_UNIT) - 1);
2967 if (GET_CODE (x) == LABEL_REF)
2968 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
2970 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2971 pool = ggc_alloc (sizeof (struct pool_constant));
2972 pool->desc = desc;
2973 pool->constant = x;
2974 pool->mode = mode;
2975 pool->labelno = const_labelno;
2976 pool->align = align;
2977 pool->offset = pool_offset;
2978 pool->mark = 1;
2979 pool->next = 0;
2981 if (last_pool == 0)
2982 first_pool = pool;
2983 else
2984 last_pool->next = pool;
2986 last_pool = pool;
2987 pool_offset += GET_MODE_SIZE (mode);
2989 /* Create a string containing the label name, in LABEL. */
2990 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2992 ++const_labelno;
2994 /* Construct the SYMBOL_REF and the MEM. */
2996 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2997 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2999 pool->desc->rtl = def = gen_rtx_MEM (mode, symbol);
3000 set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
3001 RTX_UNCHANGING_P (def) = 1;
3003 /* Add label to symbol hash table. */
3004 hash = SYMHASH (XSTR (symbol, 0));
3005 pool->next_sym = const_rtx_sym_hash_table[hash];
3006 const_rtx_sym_hash_table[hash] = pool;
3008 /* Mark the symbol_ref as belonging to this constants pool. */
3009 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3010 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3011 current_function_uses_const_pool = 1;
3013 return copy_rtx (def);
3016 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3017 the corresponding pool_constant structure. */
3019 static struct pool_constant *
3020 find_pool_constant (struct function *f, rtx addr)
3022 struct pool_constant *pool;
3023 const char *label = XSTR (addr, 0);
3025 for (pool = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; pool;
3026 pool = pool->next_sym)
3027 if (XSTR (XEXP (pool->desc->rtl, 0), 0) == label)
3028 return pool;
3030 abort ();
3033 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3036 get_pool_constant (rtx addr)
3038 return (find_pool_constant (cfun, addr))->constant;
3041 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3042 and whether it has been output or not. */
3045 get_pool_constant_mark (rtx addr, bool *pmarked)
3047 struct pool_constant *pool = find_pool_constant (cfun, addr);
3048 *pmarked = (pool->mark != 0);
3049 return pool->constant;
3052 /* Likewise, but for the constant pool of a specific function. */
3055 get_pool_constant_for_function (struct function *f, rtx addr)
3057 return (find_pool_constant (f, addr))->constant;
3060 /* Similar, return the mode. */
3062 enum machine_mode
3063 get_pool_mode (rtx addr)
3065 return (find_pool_constant (cfun, addr))->mode;
3068 enum machine_mode
3069 get_pool_mode_for_function (struct function *f, rtx addr)
3071 return (find_pool_constant (f, addr))->mode;
3074 /* Similar, return the offset in the constant pool. */
3077 get_pool_offset (rtx addr)
3079 return (find_pool_constant (cfun, addr))->offset;
3082 /* Return the size of the constant pool. */
3085 get_pool_size (void)
3087 return pool_offset;
3090 /* Write all the constants in the constant pool. */
3092 void
3093 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3094 tree fndecl ATTRIBUTE_UNUSED)
3096 struct pool_constant *pool;
3097 rtx x;
3098 REAL_VALUE_TYPE r;
3100 /* It is possible for gcc to call force_const_mem and then to later
3101 discard the instructions which refer to the constant. In such a
3102 case we do not need to output the constant. */
3103 mark_constant_pool ();
3105 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3106 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3107 #endif
3109 for (pool = first_pool; pool; pool = pool->next)
3111 rtx tmp;
3113 x = pool->constant;
3115 if (! pool->mark)
3116 continue;
3118 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3119 whose CODE_LABEL has been deleted. This can occur if a jump table
3120 is eliminated by optimization. If so, write a constant of zero
3121 instead. Note that this can also happen by turning the
3122 CODE_LABEL into a NOTE. */
3123 /* ??? This seems completely and utterly wrong. Certainly it's
3124 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3125 functioning even with INSN_DELETED_P and friends. */
3127 tmp = x;
3128 switch (GET_CODE (x))
3130 case CONST:
3131 if (GET_CODE (XEXP (x, 0)) != PLUS
3132 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3133 break;
3134 tmp = XEXP (XEXP (x, 0), 0);
3135 /* FALLTHRU */
3137 case LABEL_REF:
3138 tmp = XEXP (x, 0);
3139 if (INSN_DELETED_P (tmp)
3140 || (GET_CODE (tmp) == NOTE
3141 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3143 abort ();
3144 x = const0_rtx;
3146 break;
3148 default:
3149 break;
3152 /* First switch to correct section. */
3153 (*targetm.asm_out.select_rtx_section) (pool->mode, x, pool->align);
3155 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3156 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3157 pool->align, pool->labelno, done);
3158 #endif
3160 assemble_align (pool->align);
3162 /* Output the label. */
3163 (*targetm.asm_out.internal_label) (asm_out_file, "LC", pool->labelno);
3165 /* Output the value of the constant itself. */
3166 switch (GET_MODE_CLASS (pool->mode))
3168 case MODE_FLOAT:
3169 if (GET_CODE (x) != CONST_DOUBLE)
3170 abort ();
3172 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3173 assemble_real (r, pool->mode, pool->align);
3174 break;
3176 case MODE_INT:
3177 case MODE_PARTIAL_INT:
3178 assemble_integer (x, GET_MODE_SIZE (pool->mode), pool->align, 1);
3179 break;
3181 case MODE_VECTOR_FLOAT:
3183 int i, units;
3184 rtx elt;
3186 if (GET_CODE (x) != CONST_VECTOR)
3187 abort ();
3189 units = CONST_VECTOR_NUNITS (x);
3191 for (i = 0; i < units; i++)
3193 elt = CONST_VECTOR_ELT (x, i);
3194 REAL_VALUE_FROM_CONST_DOUBLE (r, elt);
3195 assemble_real (r, GET_MODE_INNER (pool->mode), pool->align);
3198 break;
3200 case MODE_VECTOR_INT:
3202 int i, units;
3203 rtx elt;
3205 if (GET_CODE (x) != CONST_VECTOR)
3206 abort ();
3208 units = CONST_VECTOR_NUNITS (x);
3210 for (i = 0; i < units; i++)
3212 elt = CONST_VECTOR_ELT (x, i);
3213 assemble_integer (elt, GET_MODE_UNIT_SIZE (pool->mode),
3214 pool->align, 1);
3217 break;
3219 default:
3220 abort ();
3223 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3224 sections have proper size. */
3225 if (pool->align > GET_MODE_BITSIZE (pool->mode)
3226 && in_section == in_named
3227 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3228 assemble_align (pool->align);
3230 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3231 done: ;
3232 #endif
3235 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3236 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3237 #endif
3239 /* Done with this pool. */
3240 first_pool = last_pool = 0;
3243 /* Look through the instructions for this function, and mark all the
3244 entries in the constant pool which are actually being used. Emit
3245 deferred constants which have indeed been used. */
3247 static void
3248 mark_constant_pool (void)
3250 rtx insn;
3251 rtx link;
3252 struct pool_constant *pool;
3254 if (first_pool == 0 && n_deferred_constants == 0)
3255 return;
3257 for (pool = first_pool; pool; pool = pool->next)
3258 pool->mark = 0;
3260 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3261 if (INSN_P (insn))
3262 mark_constants (PATTERN (insn));
3264 for (link = current_function_epilogue_delay_list;
3265 link;
3266 link = XEXP (link, 1))
3268 insn = XEXP (link, 0);
3270 if (INSN_P (insn))
3271 mark_constants (PATTERN (insn));
3275 /* Look through appropriate parts of X, marking all entries in the
3276 constant pool which are actually being used. Entries that are only
3277 referenced by other constants are also marked as used. Emit
3278 deferred strings that are used. */
3280 static void
3281 mark_constants (rtx x)
3283 int i;
3284 const char *format_ptr;
3286 if (x == 0)
3287 return;
3289 if (GET_CODE (x) == SYMBOL_REF)
3291 mark_constant (&x, NULL);
3292 return;
3295 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3296 insns, not any notes that may be attached. We don't want to mark
3297 a constant just because it happens to appear in a REG_EQUIV note. */
3298 if (INSN_P (x))
3300 mark_constants (PATTERN (x));
3301 return;
3304 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3306 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3308 switch (*format_ptr++)
3310 case 'e':
3311 mark_constants (XEXP (x, i));
3312 break;
3314 case 'E':
3315 if (XVEC (x, i) != 0)
3317 int j;
3319 for (j = 0; j < XVECLEN (x, i); j++)
3320 mark_constants (XVECEXP (x, i, j));
3322 break;
3324 case 'S':
3325 case 's':
3326 case '0':
3327 case 'i':
3328 case 'w':
3329 case 'n':
3330 case 'u':
3331 case 'B':
3332 break;
3334 default:
3335 abort ();
3340 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3341 to as used. Emit referenced deferred strings. This function can
3342 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3344 static int
3345 mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED)
3347 rtx x = *current_rtx;
3349 if (x == NULL_RTX)
3350 return 0;
3352 else if (GET_CODE (x) == SYMBOL_REF)
3354 if (CONSTANT_POOL_ADDRESS_P (x))
3356 struct pool_constant *pool = find_pool_constant (cfun, x);
3357 if (pool->mark == 0)
3359 pool->mark = 1;
3360 for_each_rtx (&(pool->constant), &mark_constant, NULL);
3362 else
3363 return -1;
3365 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3367 tree exp = SYMBOL_REF_DECL (x);
3368 if (!TREE_ASM_WRITTEN (exp))
3370 n_deferred_constants--;
3371 output_constant_def_contents (x);
3375 return 0;
3378 /* Determine what kind of relocations EXP may need. */
3381 compute_reloc_for_constant (tree exp)
3383 int reloc = 0, reloc2;
3384 tree tem;
3386 /* Give the front-end a chance to convert VALUE to something that
3387 looks more like a constant to the back-end. */
3388 exp = (*lang_hooks.expand_constant) (exp);
3390 switch (TREE_CODE (exp))
3392 case ADDR_EXPR:
3393 case FDESC_EXPR:
3394 /* Go inside any operations that get_inner_reference can handle and see
3395 if what's inside is a constant: no need to do anything here for
3396 addresses of variables or functions. */
3397 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3398 tem = TREE_OPERAND (tem, 0))
3401 if (TREE_PUBLIC (tem))
3402 reloc |= 2;
3403 else
3404 reloc |= 1;
3405 break;
3407 case PLUS_EXPR:
3408 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3409 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3410 break;
3412 case MINUS_EXPR:
3413 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3414 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3415 /* The difference of two local labels is computable at link time. */
3416 if (reloc == 1 && reloc2 == 1)
3417 reloc = 0;
3418 else
3419 reloc |= reloc2;
3420 break;
3422 case NOP_EXPR:
3423 case CONVERT_EXPR:
3424 case NON_LVALUE_EXPR:
3425 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3426 break;
3428 case CONSTRUCTOR:
3429 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3430 if (TREE_VALUE (tem) != 0)
3431 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3433 break;
3435 default:
3436 break;
3438 return reloc;
3441 /* Find all the constants whose addresses are referenced inside of EXP,
3442 and make sure assembler code with a label has been output for each one.
3443 Indicate whether an ADDR_EXPR has been encountered. */
3445 static void
3446 output_addressed_constants (tree exp)
3448 tree tem;
3450 /* Give the front-end a chance to convert VALUE to something that
3451 looks more like a constant to the back-end. */
3452 exp = (*lang_hooks.expand_constant) (exp);
3454 switch (TREE_CODE (exp))
3456 case ADDR_EXPR:
3457 case FDESC_EXPR:
3458 /* Go inside any operations that get_inner_reference can handle and see
3459 if what's inside is a constant: no need to do anything here for
3460 addresses of variables or functions. */
3461 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3462 tem = TREE_OPERAND (tem, 0))
3465 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
3466 || TREE_CODE (tem) == CONSTRUCTOR)
3467 output_constant_def (tem, 0);
3468 break;
3470 case PLUS_EXPR:
3471 case MINUS_EXPR:
3472 output_addressed_constants (TREE_OPERAND (exp, 1));
3473 /* Fall through. */
3475 case NOP_EXPR:
3476 case CONVERT_EXPR:
3477 case NON_LVALUE_EXPR:
3478 output_addressed_constants (TREE_OPERAND (exp, 0));
3479 break;
3481 case CONSTRUCTOR:
3482 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3483 if (TREE_VALUE (tem) != 0)
3484 output_addressed_constants (TREE_VALUE (tem));
3486 break;
3488 default:
3489 break;
3493 /* Return nonzero if VALUE is a valid constant-valued expression
3494 for use in initializing a static variable; one that can be an
3495 element of a "constant" initializer.
3497 Return null_pointer_node if the value is absolute;
3498 if it is relocatable, return the variable that determines the relocation.
3499 We assume that VALUE has been folded as much as possible;
3500 therefore, we do not need to check for such things as
3501 arithmetic-combinations of integers. */
3503 tree
3504 initializer_constant_valid_p (tree value, tree endtype)
3506 /* Give the front-end a chance to convert VALUE to something that
3507 looks more like a constant to the back-end. */
3508 value = (*lang_hooks.expand_constant) (value);
3510 switch (TREE_CODE (value))
3512 case CONSTRUCTOR:
3513 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3514 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3515 && TREE_CONSTANT (value)
3516 && CONSTRUCTOR_ELTS (value))
3518 tree elt;
3519 bool absolute = true;
3521 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3523 tree reloc;
3524 value = TREE_VALUE (elt);
3525 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3526 if (!reloc)
3527 return NULL_TREE;
3528 if (reloc != null_pointer_node)
3529 absolute = false;
3531 /* For a non-absolute relocation, there is no single
3532 variable that can be "the variable that determines the
3533 relocation." */
3534 return absolute ? null_pointer_node : error_mark_node;
3537 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3539 case INTEGER_CST:
3540 case VECTOR_CST:
3541 case REAL_CST:
3542 case STRING_CST:
3543 case COMPLEX_CST:
3544 return null_pointer_node;
3546 case ADDR_EXPR:
3547 case FDESC_EXPR:
3548 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
3550 case VIEW_CONVERT_EXPR:
3551 case NON_LVALUE_EXPR:
3552 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3554 case CONVERT_EXPR:
3555 case NOP_EXPR:
3556 /* Allow conversions between pointer types. */
3557 if (POINTER_TYPE_P (TREE_TYPE (value))
3558 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3559 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3561 /* Allow conversions between real types. */
3562 if (FLOAT_TYPE_P (TREE_TYPE (value))
3563 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3564 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3566 /* Allow length-preserving conversions between integer types. */
3567 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3568 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3569 && (TYPE_PRECISION (TREE_TYPE (value))
3570 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3571 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3573 /* Allow conversions between other integer types only if
3574 explicit value. */
3575 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3576 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3578 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3579 endtype);
3580 if (inner == null_pointer_node)
3581 return null_pointer_node;
3582 break;
3585 /* Allow (int) &foo provided int is as wide as a pointer. */
3586 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3587 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3588 && (TYPE_PRECISION (TREE_TYPE (value))
3589 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3590 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3591 endtype);
3593 /* Likewise conversions from int to pointers, but also allow
3594 conversions from 0. */
3595 if ((POINTER_TYPE_P (TREE_TYPE (value))
3596 || TREE_CODE (TREE_TYPE (value)) == OFFSET_TYPE)
3597 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3599 if (integer_zerop (TREE_OPERAND (value, 0)))
3600 return null_pointer_node;
3601 else if (TYPE_PRECISION (TREE_TYPE (value))
3602 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
3603 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3604 endtype);
3607 /* Allow conversions to union types if the value inside is okay. */
3608 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
3609 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3610 endtype);
3611 break;
3613 case PLUS_EXPR:
3614 if (! INTEGRAL_TYPE_P (endtype)
3615 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3617 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3618 endtype);
3619 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3620 endtype);
3621 /* If either term is absolute, use the other terms relocation. */
3622 if (valid0 == null_pointer_node)
3623 return valid1;
3624 if (valid1 == null_pointer_node)
3625 return valid0;
3627 break;
3629 case MINUS_EXPR:
3630 if (! INTEGRAL_TYPE_P (endtype)
3631 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3633 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3634 endtype);
3635 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3636 endtype);
3637 /* Win if second argument is absolute. */
3638 if (valid1 == null_pointer_node)
3639 return valid0;
3640 /* Win if both arguments have the same relocation.
3641 Then the value is absolute. */
3642 if (valid0 == valid1 && valid0 != 0)
3643 return null_pointer_node;
3645 /* Since GCC guarantees that string constants are unique in the
3646 generated code, a subtraction between two copies of the same
3647 constant string is absolute. */
3648 if (valid0 && TREE_CODE (valid0) == STRING_CST &&
3649 valid1 && TREE_CODE (valid1) == STRING_CST &&
3650 TREE_STRING_POINTER (valid0) == TREE_STRING_POINTER (valid1))
3651 return null_pointer_node;
3654 /* Support differences between labels. */
3655 if (INTEGRAL_TYPE_P (endtype))
3657 tree op0, op1;
3658 op0 = TREE_OPERAND (value, 0);
3659 op1 = TREE_OPERAND (value, 1);
3661 /* Like STRIP_NOPS except allow the operand mode to widen.
3662 This works around a feature of fold that simplifies
3663 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3664 that the narrower operation is cheaper. */
3666 while (TREE_CODE (op0) == NOP_EXPR
3667 || TREE_CODE (op0) == CONVERT_EXPR
3668 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3670 tree inner = TREE_OPERAND (op0, 0);
3671 if (inner == error_mark_node
3672 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3673 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3674 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3675 break;
3676 op0 = inner;
3679 while (TREE_CODE (op1) == NOP_EXPR
3680 || TREE_CODE (op1) == CONVERT_EXPR
3681 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3683 tree inner = TREE_OPERAND (op1, 0);
3684 if (inner == error_mark_node
3685 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3686 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3687 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3688 break;
3689 op1 = inner;
3692 if (TREE_CODE (op0) == ADDR_EXPR
3693 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
3694 && TREE_CODE (op1) == ADDR_EXPR
3695 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
3696 return null_pointer_node;
3698 break;
3700 default:
3701 break;
3704 return 0;
3707 /* Output assembler code for constant EXP to FILE, with no label.
3708 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3709 Assumes output_addressed_constants has been done on EXP already.
3711 Generate exactly SIZE bytes of assembler data, padding at the end
3712 with zeros if necessary. SIZE must always be specified.
3714 SIZE is important for structure constructors,
3715 since trailing members may have been omitted from the constructor.
3716 It is also important for initialization of arrays from string constants
3717 since the full length of the string constant might not be wanted.
3718 It is also needed for initialization of unions, where the initializer's
3719 type is just one member, and that may not be as long as the union.
3721 There a case in which we would fail to output exactly SIZE bytes:
3722 for a structure constructor that wants to produce more than SIZE bytes.
3723 But such constructors will never be generated for any possible input.
3725 ALIGN is the alignment of the data in bits. */
3727 void
3728 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3730 enum tree_code code;
3731 unsigned HOST_WIDE_INT thissize;
3733 /* Some front-ends use constants other than the standard language-independent
3734 varieties, but which may still be output directly. Give the front-end a
3735 chance to convert EXP to a language-independent representation. */
3736 exp = (*lang_hooks.expand_constant) (exp);
3738 if (size == 0 || flag_syntax_only)
3739 return;
3741 /* Eliminate any conversions since we'll be outputting the underlying
3742 constant. */
3743 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3744 || TREE_CODE (exp) == NON_LVALUE_EXPR
3745 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3746 exp = TREE_OPERAND (exp, 0);
3748 code = TREE_CODE (TREE_TYPE (exp));
3749 thissize = int_size_in_bytes (TREE_TYPE (exp));
3751 /* Allow a constructor with no elements for any data type.
3752 This means to fill the space with zeros. */
3753 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3755 assemble_zeros (size);
3756 return;
3759 if (TREE_CODE (exp) == FDESC_EXPR)
3761 #ifdef ASM_OUTPUT_FDESC
3762 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3763 tree decl = TREE_OPERAND (exp, 0);
3764 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3765 #else
3766 abort ();
3767 #endif
3768 return;
3771 /* Now output the underlying data. If we've handling the padding, return.
3772 Otherwise, break and ensure THISSIZE is the size written. */
3773 switch (code)
3775 case CHAR_TYPE:
3776 case BOOLEAN_TYPE:
3777 case INTEGER_TYPE:
3778 case ENUMERAL_TYPE:
3779 case POINTER_TYPE:
3780 case REFERENCE_TYPE:
3781 case OFFSET_TYPE:
3782 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3783 EXPAND_INITIALIZER),
3784 size, align, 0))
3785 error ("initializer for integer value is too complicated");
3786 break;
3788 case REAL_TYPE:
3789 if (TREE_CODE (exp) != REAL_CST)
3790 error ("initializer for floating value is not a floating constant");
3792 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3793 break;
3795 case COMPLEX_TYPE:
3796 output_constant (TREE_REALPART (exp), thissize / 2, align);
3797 output_constant (TREE_IMAGPART (exp), thissize / 2,
3798 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3799 break;
3801 case ARRAY_TYPE:
3802 case VECTOR_TYPE:
3803 if (TREE_CODE (exp) == CONSTRUCTOR)
3805 output_constructor (exp, size, align);
3806 return;
3808 else if (TREE_CODE (exp) == STRING_CST)
3810 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3811 size);
3812 assemble_string (TREE_STRING_POINTER (exp), thissize);
3814 else if (TREE_CODE (exp) == VECTOR_CST)
3816 int elt_size;
3817 tree link;
3818 unsigned int nalign;
3819 enum machine_mode inner;
3821 inner = GET_MODE_INNER (TYPE_MODE (TREE_TYPE (exp)));
3822 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3824 elt_size = GET_MODE_UNIT_SIZE (TYPE_MODE (TREE_TYPE (exp)));
3826 link = TREE_VECTOR_CST_ELTS (exp);
3827 output_constant (TREE_VALUE (link), elt_size, align);
3828 while ((link = TREE_CHAIN (link)) != NULL)
3829 output_constant (TREE_VALUE (link), elt_size, nalign);
3831 else
3832 abort ();
3833 break;
3835 case RECORD_TYPE:
3836 case UNION_TYPE:
3837 if (TREE_CODE (exp) == CONSTRUCTOR)
3838 output_constructor (exp, size, align);
3839 else
3840 abort ();
3841 return;
3843 case SET_TYPE:
3844 if (TREE_CODE (exp) == INTEGER_CST)
3845 assemble_integer (expand_expr (exp, NULL_RTX,
3846 VOIDmode, EXPAND_INITIALIZER),
3847 thissize, align, 1);
3848 else if (TREE_CODE (exp) == CONSTRUCTOR)
3850 unsigned char *buffer = alloca (thissize);
3851 if (get_set_constructor_bytes (exp, buffer, thissize))
3852 abort ();
3853 assemble_string ((char *) buffer, thissize);
3855 else
3856 error ("unknown set constructor type");
3857 return;
3859 case ERROR_MARK:
3860 return;
3862 default:
3863 abort ();
3866 if (size > thissize)
3867 assemble_zeros (size - thissize);
3871 /* Subroutine of output_constructor, used for computing the size of
3872 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3873 type with an unspecified upper bound. */
3875 static unsigned HOST_WIDE_INT
3876 array_size_for_constructor (tree val)
3878 tree max_index, i;
3880 /* This code used to attempt to handle string constants that are not
3881 arrays of single-bytes, but nothing else does, so there's no point in
3882 doing it here. */
3883 if (TREE_CODE (val) == STRING_CST)
3884 return TREE_STRING_LENGTH (val);
3886 max_index = NULL_TREE;
3887 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3889 tree index = TREE_PURPOSE (i);
3891 if (TREE_CODE (index) == RANGE_EXPR)
3892 index = TREE_OPERAND (index, 1);
3893 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3894 max_index = index;
3897 if (max_index == NULL_TREE)
3898 return 0;
3900 /* Compute the total number of array elements. */
3901 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3902 convert (sizetype,
3903 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3904 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3906 /* Multiply by the array element unit size to find number of bytes. */
3907 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3909 return tree_low_cst (i, 1);
3912 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3913 Generate at least SIZE bytes, padding if necessary. */
3915 static void
3916 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3917 unsigned int align)
3919 tree type = TREE_TYPE (exp);
3920 tree link, field = 0;
3921 tree min_index = 0;
3922 /* Number of bytes output or skipped so far.
3923 In other words, current position within the constructor. */
3924 HOST_WIDE_INT total_bytes = 0;
3925 /* Nonzero means BYTE contains part of a byte, to be output. */
3926 int byte_buffer_in_use = 0;
3927 int byte = 0;
3929 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3930 abort ();
3932 if (TREE_CODE (type) == RECORD_TYPE)
3933 field = TYPE_FIELDS (type);
3935 if (TREE_CODE (type) == ARRAY_TYPE
3936 && TYPE_DOMAIN (type) != 0)
3937 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3939 /* As LINK goes through the elements of the constant,
3940 FIELD goes through the structure fields, if the constant is a structure.
3941 if the constant is a union, then we override this,
3942 by getting the field from the TREE_LIST element.
3943 But the constant could also be an array. Then FIELD is zero.
3945 There is always a maximum of one element in the chain LINK for unions
3946 (even if the initializer in a source program incorrectly contains
3947 more one). */
3948 for (link = CONSTRUCTOR_ELTS (exp);
3949 link;
3950 link = TREE_CHAIN (link),
3951 field = field ? TREE_CHAIN (field) : 0)
3953 tree val = TREE_VALUE (link);
3954 tree index = 0;
3956 /* The element in a union constructor specifies the proper field
3957 or index. */
3958 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3959 || TREE_CODE (type) == QUAL_UNION_TYPE)
3960 && TREE_PURPOSE (link) != 0)
3961 field = TREE_PURPOSE (link);
3963 else if (TREE_CODE (type) == ARRAY_TYPE)
3964 index = TREE_PURPOSE (link);
3966 #ifdef ASM_COMMENT_START
3967 if (field && flag_verbose_asm)
3968 fprintf (asm_out_file, "%s %s:\n",
3969 ASM_COMMENT_START,
3970 DECL_NAME (field)
3971 ? IDENTIFIER_POINTER (DECL_NAME (field))
3972 : "<anonymous>");
3973 #endif
3975 /* Eliminate the marker that makes a cast not be an lvalue. */
3976 if (val != 0)
3977 STRIP_NOPS (val);
3979 if (index && TREE_CODE (index) == RANGE_EXPR)
3981 unsigned HOST_WIDE_INT fieldsize
3982 = int_size_in_bytes (TREE_TYPE (type));
3983 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3984 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3985 HOST_WIDE_INT index;
3986 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3988 for (index = lo_index; index <= hi_index; index++)
3990 /* Output the element's initial value. */
3991 if (val == 0)
3992 assemble_zeros (fieldsize);
3993 else
3994 output_constant (val, fieldsize, align2);
3996 /* Count its size. */
3997 total_bytes += fieldsize;
4000 else if (field == 0 || !DECL_BIT_FIELD (field))
4002 /* An element that is not a bit-field. */
4004 unsigned HOST_WIDE_INT fieldsize;
4005 /* Since this structure is static,
4006 we know the positions are constant. */
4007 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4008 unsigned int align2;
4010 if (index != 0)
4011 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4012 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4014 /* Output any buffered-up bit-fields preceding this element. */
4015 if (byte_buffer_in_use)
4017 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4018 total_bytes++;
4019 byte_buffer_in_use = 0;
4022 /* Advance to offset of this element.
4023 Note no alignment needed in an array, since that is guaranteed
4024 if each element has the proper size. */
4025 if ((field != 0 || index != 0) && pos != total_bytes)
4027 assemble_zeros (pos - total_bytes);
4028 total_bytes = pos;
4031 /* Find the alignment of this element. */
4032 align2 = min_align (align, BITS_PER_UNIT * pos);
4034 /* Determine size this element should occupy. */
4035 if (field)
4037 fieldsize = 0;
4039 /* If this is an array with an unspecified upper bound,
4040 the initializer determines the size. */
4041 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4042 but we cannot do this until the deprecated support for
4043 initializing zero-length array members is removed. */
4044 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
4045 && TYPE_DOMAIN (TREE_TYPE (field))
4046 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
4048 fieldsize = array_size_for_constructor (val);
4049 /* Given a non-empty initialization, this field had
4050 better be last. */
4051 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
4052 abort ();
4054 else if (DECL_SIZE_UNIT (field))
4056 /* ??? This can't be right. If the decl size overflows
4057 a host integer we will silently emit no data. */
4058 if (host_integerp (DECL_SIZE_UNIT (field), 1))
4059 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4062 else
4063 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4065 /* Output the element's initial value. */
4066 if (val == 0)
4067 assemble_zeros (fieldsize);
4068 else
4069 output_constant (val, fieldsize, align2);
4071 /* Count its size. */
4072 total_bytes += fieldsize;
4074 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4075 error ("invalid initial value for member `%s'",
4076 IDENTIFIER_POINTER (DECL_NAME (field)));
4077 else
4079 /* Element that is a bit-field. */
4081 HOST_WIDE_INT next_offset = int_bit_position (field);
4082 HOST_WIDE_INT end_offset
4083 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4085 if (val == 0)
4086 val = integer_zero_node;
4088 /* If this field does not start in this (or, next) byte,
4089 skip some bytes. */
4090 if (next_offset / BITS_PER_UNIT != total_bytes)
4092 /* Output remnant of any bit field in previous bytes. */
4093 if (byte_buffer_in_use)
4095 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4096 total_bytes++;
4097 byte_buffer_in_use = 0;
4100 /* If still not at proper byte, advance to there. */
4101 if (next_offset / BITS_PER_UNIT != total_bytes)
4103 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4104 total_bytes = next_offset / BITS_PER_UNIT;
4108 if (! byte_buffer_in_use)
4109 byte = 0;
4111 /* We must split the element into pieces that fall within
4112 separate bytes, and combine each byte with previous or
4113 following bit-fields. */
4115 /* next_offset is the offset n fbits from the beginning of
4116 the structure to the next bit of this element to be processed.
4117 end_offset is the offset of the first bit past the end of
4118 this element. */
4119 while (next_offset < end_offset)
4121 int this_time;
4122 int shift;
4123 HOST_WIDE_INT value;
4124 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4125 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4127 /* Advance from byte to byte
4128 within this element when necessary. */
4129 while (next_byte != total_bytes)
4131 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4132 total_bytes++;
4133 byte = 0;
4136 /* Number of bits we can process at once
4137 (all part of the same byte). */
4138 this_time = MIN (end_offset - next_offset,
4139 BITS_PER_UNIT - next_bit);
4140 if (BYTES_BIG_ENDIAN)
4142 /* On big-endian machine, take the most significant bits
4143 first (of the bits that are significant)
4144 and put them into bytes from the most significant end. */
4145 shift = end_offset - next_offset - this_time;
4147 /* Don't try to take a bunch of bits that cross
4148 the word boundary in the INTEGER_CST. We can
4149 only select bits from the LOW or HIGH part
4150 not from both. */
4151 if (shift < HOST_BITS_PER_WIDE_INT
4152 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4154 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4155 shift = HOST_BITS_PER_WIDE_INT;
4158 /* Now get the bits from the appropriate constant word. */
4159 if (shift < HOST_BITS_PER_WIDE_INT)
4160 value = TREE_INT_CST_LOW (val);
4161 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4163 value = TREE_INT_CST_HIGH (val);
4164 shift -= HOST_BITS_PER_WIDE_INT;
4166 else
4167 abort ();
4169 /* Get the result. This works only when:
4170 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4171 byte |= (((value >> shift)
4172 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4173 << (BITS_PER_UNIT - this_time - next_bit));
4175 else
4177 /* On little-endian machines,
4178 take first the least significant bits of the value
4179 and pack them starting at the least significant
4180 bits of the bytes. */
4181 shift = next_offset - int_bit_position (field);
4183 /* Don't try to take a bunch of bits that cross
4184 the word boundary in the INTEGER_CST. We can
4185 only select bits from the LOW or HIGH part
4186 not from both. */
4187 if (shift < HOST_BITS_PER_WIDE_INT
4188 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4189 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4191 /* Now get the bits from the appropriate constant word. */
4192 if (shift < HOST_BITS_PER_WIDE_INT)
4193 value = TREE_INT_CST_LOW (val);
4194 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4196 value = TREE_INT_CST_HIGH (val);
4197 shift -= HOST_BITS_PER_WIDE_INT;
4199 else
4200 abort ();
4202 /* Get the result. This works only when:
4203 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4204 byte |= (((value >> shift)
4205 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4206 << next_bit);
4209 next_offset += this_time;
4210 byte_buffer_in_use = 1;
4215 if (byte_buffer_in_use)
4217 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4218 total_bytes++;
4221 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4222 assemble_zeros (size - total_bytes);
4225 /* This TREE_LIST contains any weak symbol declarations waiting
4226 to be emitted. */
4227 static GTY(()) tree weak_decls;
4229 /* Mark DECL as weak. */
4231 static void
4232 mark_weak (tree decl)
4234 DECL_WEAK (decl) = 1;
4236 if (DECL_RTL_SET_P (decl)
4237 && GET_CODE (DECL_RTL (decl)) == MEM
4238 && XEXP (DECL_RTL (decl), 0)
4239 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4240 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4243 /* Merge weak status between NEWDECL and OLDDECL. */
4245 void
4246 merge_weak (tree newdecl, tree olddecl)
4248 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4249 return;
4251 if (DECL_WEAK (newdecl))
4253 tree wd;
4255 /* NEWDECL is weak, but OLDDECL is not. */
4257 /* If we already output the OLDDECL, we're in trouble; we can't
4258 go back and make it weak. This error cannot caught in
4259 declare_weak because the NEWDECL and OLDDECL was not yet
4260 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4261 if (TREE_ASM_WRITTEN (olddecl))
4262 error ("%Jweak declaration of '%D' must precede definition",
4263 newdecl, newdecl);
4265 /* If we've already generated rtl referencing OLDDECL, we may
4266 have done so in a way that will not function properly with
4267 a weak symbol. */
4268 else if (TREE_USED (olddecl)
4269 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4270 warning ("%Jweak declaration of '%D' after first use results "
4271 "in unspecified behavior", newdecl, newdecl);
4273 if (SUPPORTS_WEAK)
4275 /* We put the NEWDECL on the weak_decls list at some point.
4276 Replace it with the OLDDECL. */
4277 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4278 if (TREE_VALUE (wd) == newdecl)
4280 TREE_VALUE (wd) = olddecl;
4281 break;
4283 /* We may not find the entry on the list. If NEWDECL is a
4284 weak alias, then we will have already called
4285 globalize_decl to remove the entry; in that case, we do
4286 not need to do anything. */
4289 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4290 mark_weak (olddecl);
4292 else
4293 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4294 weak. Just update NEWDECL to indicate that it's weak too. */
4295 mark_weak (newdecl);
4298 /* Declare DECL to be a weak symbol. */
4300 void
4301 declare_weak (tree decl)
4303 if (! TREE_PUBLIC (decl))
4304 error ("%Jweak declaration of '%D' must be public", decl, decl);
4305 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4306 error ("%Jweak declaration of '%D' must precede definition", decl, decl);
4307 else if (SUPPORTS_WEAK)
4309 if (! DECL_WEAK (decl))
4310 weak_decls = tree_cons (NULL, decl, weak_decls);
4312 else
4313 warning ("%Jweak declaration of '%D' not supported", decl, decl);
4315 mark_weak (decl);
4318 /* Emit any pending weak declarations. */
4320 void
4321 weak_finish (void)
4323 tree t;
4325 for (t = weak_decls; t; t = TREE_CHAIN (t))
4327 tree decl = TREE_VALUE (t);
4328 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4329 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4330 #endif
4332 if (! TREE_USED (decl))
4333 continue;
4335 #ifdef ASM_WEAKEN_DECL
4336 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4337 #else
4338 #ifdef ASM_WEAKEN_LABEL
4339 ASM_WEAKEN_LABEL (asm_out_file, name);
4340 #else
4341 #ifdef ASM_OUTPUT_WEAK_ALIAS
4342 warning ("only weak aliases are supported in this configuration");
4343 return;
4344 #endif
4345 #endif
4346 #endif
4350 /* Emit the assembly bits to indicate that DECL is globally visible. */
4352 static void
4353 globalize_decl (tree decl)
4355 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4357 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4358 if (DECL_WEAK (decl))
4360 tree *p, t;
4362 #ifdef ASM_WEAKEN_DECL
4363 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4364 #else
4365 ASM_WEAKEN_LABEL (asm_out_file, name);
4366 #endif
4368 /* Remove this function from the pending weak list so that
4369 we do not emit multiple .weak directives for it. */
4370 for (p = &weak_decls; (t = *p) ; )
4372 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4373 *p = TREE_CHAIN (t);
4374 else
4375 p = &TREE_CHAIN (t);
4377 return;
4379 #endif
4381 (*targetm.asm_out.globalize_label) (asm_out_file, name);
4384 /* Emit an assembler directive to make the symbol for DECL an alias to
4385 the symbol for TARGET. */
4387 void
4388 assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4390 const char *name;
4392 /* We must force creation of DECL_RTL for debug info generation, even though
4393 we don't use it here. */
4394 make_decl_rtl (decl, NULL);
4396 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4398 #ifdef ASM_OUTPUT_DEF
4399 /* Make name accessible from other files, if appropriate. */
4401 if (TREE_PUBLIC (decl))
4403 globalize_decl (decl);
4404 maybe_assemble_visibility (decl);
4407 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4408 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4409 #else
4410 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4411 #endif
4412 #else /* !ASM_OUTPUT_DEF */
4413 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4414 if (! DECL_WEAK (decl))
4415 warning ("only weak aliases are supported in this configuration");
4417 #ifdef ASM_WEAKEN_DECL
4418 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4419 #else
4420 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4421 #endif
4422 #else
4423 warning ("alias definitions not supported in this configuration; ignored");
4424 #endif
4425 #endif
4427 TREE_USED (decl) = 1;
4428 TREE_ASM_WRITTEN (decl) = 1;
4429 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4432 /* Emit an assembler directive to set symbol for DECL visibility to
4433 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4435 void
4436 default_assemble_visibility (tree decl, int vis)
4438 static const char * const visibility_types[] = {
4439 NULL, "internal", "hidden", "protected"
4442 const char *name, *type;
4444 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4445 type = visibility_types[vis];
4447 #ifdef HAVE_GAS_HIDDEN
4448 fprintf (asm_out_file, "\t.%s\t", type);
4449 assemble_name (asm_out_file, name);
4450 fprintf (asm_out_file, "\n");
4451 #else
4452 warning ("visibility attribute not supported in this configuration; ignored");
4453 #endif
4456 /* A helper function to call assemble_visibility when needed for a decl. */
4458 static void
4459 maybe_assemble_visibility (tree decl)
4461 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4463 if (vis != VISIBILITY_DEFAULT)
4464 (* targetm.asm_out.visibility) (decl, vis);
4467 /* Returns 1 if the target configuration supports defining public symbols
4468 so that one of them will be chosen at link time instead of generating a
4469 multiply-defined symbol error, whether through the use of weak symbols or
4470 a target-specific mechanism for having duplicates discarded. */
4473 supports_one_only (void)
4475 if (SUPPORTS_ONE_ONLY)
4476 return 1;
4477 return SUPPORTS_WEAK;
4480 /* Set up DECL as a public symbol that can be defined in multiple
4481 translation units without generating a linker error. */
4483 void
4484 make_decl_one_only (tree decl)
4486 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4487 abort ();
4489 TREE_PUBLIC (decl) = 1;
4491 if (TREE_CODE (decl) == VAR_DECL
4492 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4493 DECL_COMMON (decl) = 1;
4494 else if (SUPPORTS_ONE_ONLY)
4496 #ifdef MAKE_DECL_ONE_ONLY
4497 MAKE_DECL_ONE_ONLY (decl);
4498 #endif
4499 DECL_ONE_ONLY (decl) = 1;
4501 else if (SUPPORTS_WEAK)
4502 DECL_WEAK (decl) = 1;
4503 else
4504 abort ();
4507 void
4508 init_varasm_once (void)
4510 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4511 in_named_entry_eq, NULL);
4512 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4513 const_desc_eq, NULL);
4515 const_alias_set = new_alias_set ();
4518 enum tls_model
4519 decl_tls_model (tree decl)
4521 enum tls_model kind;
4522 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4523 bool is_local;
4525 if (attr)
4527 attr = TREE_VALUE (TREE_VALUE (attr));
4528 if (TREE_CODE (attr) != STRING_CST)
4529 abort ();
4530 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4531 kind = TLS_MODEL_LOCAL_EXEC;
4532 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4533 kind = TLS_MODEL_INITIAL_EXEC;
4534 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4535 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4536 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4537 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4538 else
4539 abort ();
4540 return kind;
4543 is_local = (*targetm.binds_local_p) (decl);
4544 if (!flag_pic)
4546 if (is_local)
4547 kind = TLS_MODEL_LOCAL_EXEC;
4548 else
4549 kind = TLS_MODEL_INITIAL_EXEC;
4551 /* Local dynamic is inefficient when we're not combining the
4552 parts of the address. */
4553 else if (optimize && is_local)
4554 kind = TLS_MODEL_LOCAL_DYNAMIC;
4555 else
4556 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4557 if (kind < flag_tls_default)
4558 kind = flag_tls_default;
4560 return kind;
4563 /* Select a set of attributes for section NAME based on the properties
4564 of DECL and whether or not RELOC indicates that DECL's initializer
4565 might contain runtime relocations.
4567 We make the section read-only and executable for a function decl,
4568 read-only for a const data decl, and writable for a non-const data decl. */
4570 unsigned int
4571 default_section_type_flags (tree decl, const char *name, int reloc)
4573 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4576 unsigned int
4577 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4578 int shlib)
4580 unsigned int flags;
4582 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4583 flags = SECTION_CODE;
4584 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4585 flags = 0;
4586 else
4587 flags = SECTION_WRITE;
4589 if (decl && DECL_ONE_ONLY (decl))
4590 flags |= SECTION_LINKONCE;
4592 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4593 flags |= SECTION_TLS | SECTION_WRITE;
4595 if (strcmp (name, ".bss") == 0
4596 || strncmp (name, ".bss.", 5) == 0
4597 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4598 || strcmp (name, ".sbss") == 0
4599 || strncmp (name, ".sbss.", 6) == 0
4600 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
4601 || strcmp (name, ".tbss") == 0
4602 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4603 flags |= SECTION_BSS;
4605 if (strcmp (name, ".tdata") == 0
4606 || strcmp (name, ".tbss") == 0
4607 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
4608 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4609 flags |= SECTION_TLS;
4611 /* These three sections have special ELF types. They are neither
4612 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4613 want to print a section type (@progbits or @nobits). If someone
4614 is silly enough to emit code or TLS variables to one of these
4615 sections, then don't handle them specially. */
4616 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4617 && (strcmp (name, ".init_array") == 0
4618 || strcmp (name, ".fini_array") == 0
4619 || strcmp (name, ".preinit_array") == 0))
4620 flags |= SECTION_NOTYPE;
4622 return flags;
4625 /* Output assembly to switch to section NAME with attribute FLAGS.
4626 Four variants for common object file formats. */
4628 void
4629 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4630 unsigned int flags ATTRIBUTE_UNUSED)
4632 /* Some object formats don't support named sections at all. The
4633 front-end should already have flagged this as an error. */
4634 abort ();
4637 void
4638 default_elf_asm_named_section (const char *name, unsigned int flags)
4640 char flagchars[10], *f = flagchars;
4642 if (! named_section_first_declaration (name))
4644 fprintf (asm_out_file, "\t.section\t%s\n", name);
4645 return;
4648 if (!(flags & SECTION_DEBUG))
4649 *f++ = 'a';
4650 if (flags & SECTION_WRITE)
4651 *f++ = 'w';
4652 if (flags & SECTION_CODE)
4653 *f++ = 'x';
4654 if (flags & SECTION_SMALL)
4655 *f++ = 's';
4656 if (flags & SECTION_MERGE)
4657 *f++ = 'M';
4658 if (flags & SECTION_STRINGS)
4659 *f++ = 'S';
4660 if (flags & SECTION_TLS)
4661 *f++ = 'T';
4662 *f = '\0';
4664 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4666 if (!(flags & SECTION_NOTYPE))
4668 const char *type;
4670 if (flags & SECTION_BSS)
4671 type = "nobits";
4672 else
4673 type = "progbits";
4675 fprintf (asm_out_file, ",@%s", type);
4677 if (flags & SECTION_ENTSIZE)
4678 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4681 putc ('\n', asm_out_file);
4684 void
4685 default_coff_asm_named_section (const char *name, unsigned int flags)
4687 char flagchars[8], *f = flagchars;
4689 if (flags & SECTION_WRITE)
4690 *f++ = 'w';
4691 if (flags & SECTION_CODE)
4692 *f++ = 'x';
4693 *f = '\0';
4695 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4698 void
4699 default_pe_asm_named_section (const char *name, unsigned int flags)
4701 default_coff_asm_named_section (name, flags);
4703 if (flags & SECTION_LINKONCE)
4705 /* Functions may have been compiled at various levels of
4706 optimization so we can't use `same_size' here.
4707 Instead, have the linker pick one. */
4708 fprintf (asm_out_file, "\t.linkonce %s\n",
4709 (flags & SECTION_CODE ? "discard" : "same_size"));
4713 /* The lame default section selector. */
4715 void
4716 default_select_section (tree decl, int reloc,
4717 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4719 bool readonly = false;
4721 if (DECL_P (decl))
4723 if (decl_readonly_section (decl, reloc))
4724 readonly = true;
4726 else if (TREE_CODE (decl) == CONSTRUCTOR)
4728 if (! ((flag_pic && reloc)
4729 || !TREE_READONLY (decl)
4730 || TREE_SIDE_EFFECTS (decl)
4731 || !TREE_CONSTANT (decl)))
4732 readonly = true;
4734 else if (TREE_CODE (decl) == STRING_CST)
4735 readonly = !flag_writable_strings;
4736 else if (! (flag_pic && reloc))
4737 readonly = true;
4739 if (readonly)
4740 readonly_data_section ();
4741 else
4742 data_section ();
4745 /* A helper function for default_elf_select_section and
4746 default_elf_unique_section. Categorizes the DECL. */
4748 enum section_category
4750 SECCAT_TEXT,
4752 SECCAT_RODATA,
4753 SECCAT_RODATA_MERGE_STR,
4754 SECCAT_RODATA_MERGE_STR_INIT,
4755 SECCAT_RODATA_MERGE_CONST,
4756 SECCAT_SRODATA,
4758 SECCAT_DATA,
4760 /* To optimize loading of shared programs, define following subsections
4761 of data section:
4762 _REL Contains data that has relocations, so they get grouped
4763 together and dynamic linker will visit fewer pages in memory.
4764 _RO Contains data that is otherwise read-only. This is useful
4765 with prelinking as most relocations won't be dynamically
4766 linked and thus stay read only.
4767 _LOCAL Marks data containing relocations only to local objects.
4768 These relocations will get fully resolved by prelinking. */
4769 SECCAT_DATA_REL,
4770 SECCAT_DATA_REL_LOCAL,
4771 SECCAT_DATA_REL_RO,
4772 SECCAT_DATA_REL_RO_LOCAL,
4774 SECCAT_SDATA,
4775 SECCAT_TDATA,
4777 SECCAT_BSS,
4778 SECCAT_SBSS,
4779 SECCAT_TBSS
4782 static enum section_category
4783 categorize_decl_for_section (tree, int, int);
4785 static enum section_category
4786 categorize_decl_for_section (tree decl, int reloc, int shlib)
4788 enum section_category ret;
4790 if (TREE_CODE (decl) == FUNCTION_DECL)
4791 return SECCAT_TEXT;
4792 else if (TREE_CODE (decl) == STRING_CST)
4794 if (flag_writable_strings)
4795 return SECCAT_DATA;
4796 else
4797 return SECCAT_RODATA_MERGE_STR;
4799 else if (TREE_CODE (decl) == VAR_DECL)
4801 if (DECL_INITIAL (decl) == NULL
4802 || DECL_INITIAL (decl) == error_mark_node)
4803 ret = SECCAT_BSS;
4804 else if (! TREE_READONLY (decl)
4805 || TREE_SIDE_EFFECTS (decl)
4806 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4808 if (shlib && (reloc & 2))
4809 ret = SECCAT_DATA_REL;
4810 else if (shlib && reloc)
4811 ret = SECCAT_DATA_REL_LOCAL;
4812 else
4813 ret = SECCAT_DATA;
4815 else if (shlib && (reloc & 2))
4816 ret = SECCAT_DATA_REL_RO;
4817 else if (shlib && reloc)
4818 ret = SECCAT_DATA_REL_RO_LOCAL;
4819 else if (reloc || flag_merge_constants < 2)
4820 /* C and C++ don't allow different variables to share the same
4821 location. -fmerge-all-constants allows even that (at the
4822 expense of not conforming). */
4823 ret = SECCAT_RODATA;
4824 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4825 ret = SECCAT_RODATA_MERGE_STR_INIT;
4826 else
4827 ret = SECCAT_RODATA_MERGE_CONST;
4829 else if (TREE_CODE (decl) == CONSTRUCTOR)
4831 if ((shlib && reloc)
4832 || TREE_SIDE_EFFECTS (decl)
4833 || ! TREE_CONSTANT (decl))
4834 ret = SECCAT_DATA;
4835 else
4836 ret = SECCAT_RODATA;
4838 else
4839 ret = SECCAT_RODATA;
4841 /* There are no read-only thread-local sections. */
4842 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4844 if (ret == SECCAT_BSS)
4845 ret = SECCAT_TBSS;
4846 else
4847 ret = SECCAT_TDATA;
4850 /* If the target uses small data sections, select it. */
4851 else if ((*targetm.in_small_data_p) (decl))
4853 if (ret == SECCAT_BSS)
4854 ret = SECCAT_SBSS;
4855 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4856 ret = SECCAT_SRODATA;
4857 else
4858 ret = SECCAT_SDATA;
4861 return ret;
4864 bool
4865 decl_readonly_section (tree decl, int reloc)
4867 return decl_readonly_section_1 (decl, reloc, flag_pic);
4870 bool
4871 decl_readonly_section_1 (tree decl, int reloc, int shlib)
4873 switch (categorize_decl_for_section (decl, reloc, shlib))
4875 case SECCAT_RODATA:
4876 case SECCAT_RODATA_MERGE_STR:
4877 case SECCAT_RODATA_MERGE_STR_INIT:
4878 case SECCAT_RODATA_MERGE_CONST:
4879 case SECCAT_SRODATA:
4880 return true;
4881 break;
4882 default:
4883 return false;
4884 break;
4888 /* Select a section based on the above categorization. */
4890 void
4891 default_elf_select_section (tree decl, int reloc,
4892 unsigned HOST_WIDE_INT align)
4894 default_elf_select_section_1 (decl, reloc, align, flag_pic);
4897 void
4898 default_elf_select_section_1 (tree decl, int reloc,
4899 unsigned HOST_WIDE_INT align, int shlib)
4901 switch (categorize_decl_for_section (decl, reloc, shlib))
4903 case SECCAT_TEXT:
4904 /* We're not supposed to be called on FUNCTION_DECLs. */
4905 abort ();
4906 case SECCAT_RODATA:
4907 readonly_data_section ();
4908 break;
4909 case SECCAT_RODATA_MERGE_STR:
4910 mergeable_string_section (decl, align, 0);
4911 break;
4912 case SECCAT_RODATA_MERGE_STR_INIT:
4913 mergeable_string_section (DECL_INITIAL (decl), align, 0);
4914 break;
4915 case SECCAT_RODATA_MERGE_CONST:
4916 mergeable_constant_section (DECL_MODE (decl), align, 0);
4917 break;
4918 case SECCAT_SRODATA:
4919 named_section (NULL_TREE, ".sdata2", reloc);
4920 break;
4921 case SECCAT_DATA:
4922 data_section ();
4923 break;
4924 case SECCAT_DATA_REL:
4925 named_section (NULL_TREE, ".data.rel", reloc);
4926 break;
4927 case SECCAT_DATA_REL_LOCAL:
4928 named_section (NULL_TREE, ".data.rel.local", reloc);
4929 break;
4930 case SECCAT_DATA_REL_RO:
4931 named_section (NULL_TREE, ".data.rel.ro", reloc);
4932 break;
4933 case SECCAT_DATA_REL_RO_LOCAL:
4934 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
4935 break;
4936 case SECCAT_SDATA:
4937 named_section (NULL_TREE, ".sdata", reloc);
4938 break;
4939 case SECCAT_TDATA:
4940 named_section (NULL_TREE, ".tdata", reloc);
4941 break;
4942 case SECCAT_BSS:
4943 #ifdef BSS_SECTION_ASM_OP
4944 bss_section ();
4945 #else
4946 named_section (NULL_TREE, ".bss", reloc);
4947 #endif
4948 break;
4949 case SECCAT_SBSS:
4950 named_section (NULL_TREE, ".sbss", reloc);
4951 break;
4952 case SECCAT_TBSS:
4953 named_section (NULL_TREE, ".tbss", reloc);
4954 break;
4955 default:
4956 abort ();
4960 /* Construct a unique section name based on the decl name and the
4961 categorization performed above. */
4963 void
4964 default_unique_section (tree decl, int reloc)
4966 default_unique_section_1 (decl, reloc, flag_pic);
4969 void
4970 default_unique_section_1 (tree decl, int reloc, int shlib)
4972 bool one_only = DECL_ONE_ONLY (decl);
4973 const char *prefix, *name;
4974 size_t nlen, plen;
4975 char *string;
4977 switch (categorize_decl_for_section (decl, reloc, shlib))
4979 case SECCAT_TEXT:
4980 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
4981 break;
4982 case SECCAT_RODATA:
4983 case SECCAT_RODATA_MERGE_STR:
4984 case SECCAT_RODATA_MERGE_STR_INIT:
4985 case SECCAT_RODATA_MERGE_CONST:
4986 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
4987 break;
4988 case SECCAT_SRODATA:
4989 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
4990 break;
4991 case SECCAT_DATA:
4992 case SECCAT_DATA_REL:
4993 case SECCAT_DATA_REL_LOCAL:
4994 case SECCAT_DATA_REL_RO:
4995 case SECCAT_DATA_REL_RO_LOCAL:
4996 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
4997 break;
4998 case SECCAT_SDATA:
4999 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
5000 break;
5001 case SECCAT_BSS:
5002 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
5003 break;
5004 case SECCAT_SBSS:
5005 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
5006 break;
5007 case SECCAT_TDATA:
5008 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
5009 break;
5010 case SECCAT_TBSS:
5011 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
5012 break;
5013 default:
5014 abort ();
5016 plen = strlen (prefix);
5018 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
5019 name = (* targetm.strip_name_encoding) (name);
5020 nlen = strlen (name);
5022 string = alloca (nlen + plen + 1);
5023 memcpy (string, prefix, plen);
5024 memcpy (string + plen, name, nlen + 1);
5026 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
5029 void
5030 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
5031 rtx x,
5032 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
5034 if (flag_pic)
5035 switch (GET_CODE (x))
5037 case CONST:
5038 case SYMBOL_REF:
5039 case LABEL_REF:
5040 data_section ();
5041 return;
5043 default:
5044 break;
5047 readonly_data_section ();
5050 void
5051 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5052 unsigned HOST_WIDE_INT align)
5054 /* ??? Handle small data here somehow. */
5056 if (flag_pic)
5057 switch (GET_CODE (x))
5059 case CONST:
5060 case SYMBOL_REF:
5061 named_section (NULL_TREE, ".data.rel.ro", 3);
5062 return;
5064 case LABEL_REF:
5065 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5066 return;
5068 default:
5069 break;
5072 mergeable_constant_section (mode, align, 0);
5075 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5077 void
5078 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5080 rtx symbol;
5081 int flags;
5083 /* Careful not to prod global register variables. */
5084 if (GET_CODE (rtl) != MEM)
5085 return;
5086 symbol = XEXP (rtl, 0);
5087 if (GET_CODE (symbol) != SYMBOL_REF)
5088 return;
5090 flags = 0;
5091 if (TREE_CODE (decl) == FUNCTION_DECL)
5092 flags |= SYMBOL_FLAG_FUNCTION;
5093 if ((*targetm.binds_local_p) (decl))
5094 flags |= SYMBOL_FLAG_LOCAL;
5095 if ((*targetm.in_small_data_p) (decl))
5096 flags |= SYMBOL_FLAG_SMALL;
5097 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5098 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5099 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5100 being PUBLIC, the thing *must* be defined in this translation unit.
5101 Prevent this buglet from being propagated into rtl code as well. */
5102 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5103 flags |= SYMBOL_FLAG_EXTERNAL;
5105 SYMBOL_REF_FLAGS (symbol) = flags;
5108 /* By default, we do nothing for encode_section_info, so we need not
5109 do anything but discard the '*' marker. */
5111 const char *
5112 default_strip_name_encoding (const char *str)
5114 return str + (*str == '*');
5117 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5118 wrt cross-module name binding. */
5120 bool
5121 default_binds_local_p (tree exp)
5123 return default_binds_local_p_1 (exp, flag_shlib);
5126 bool
5127 default_binds_local_p_1 (tree exp, int shlib)
5129 bool local_p;
5131 /* A non-decl is an entry in the constant pool. */
5132 if (!DECL_P (exp))
5133 local_p = true;
5134 /* Static variables are always local. */
5135 else if (! TREE_PUBLIC (exp))
5136 local_p = true;
5137 /* A variable is local if the user tells us so. */
5138 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5139 local_p = true;
5140 /* Otherwise, variables defined outside this object may not be local. */
5141 else if (DECL_EXTERNAL (exp))
5142 local_p = false;
5143 /* Linkonce and weak data are never local. */
5144 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5145 local_p = false;
5146 /* If PIC, then assume that any global name can be overridden by
5147 symbols resolved from other modules. */
5148 else if (shlib)
5149 local_p = false;
5150 /* Uninitialized COMMON variable may be unified with symbols
5151 resolved from other modules. */
5152 else if (DECL_COMMON (exp)
5153 && (DECL_INITIAL (exp) == NULL
5154 || DECL_INITIAL (exp) == error_mark_node))
5155 local_p = false;
5156 /* Otherwise we're left with initialized (or non-common) global data
5157 which is of necessity defined locally. */
5158 else
5159 local_p = true;
5161 return local_p;
5164 /* Determine whether or not a pointer mode is valid. Assume defaults
5165 of ptr_mode or Pmode - can be overridden. */
5166 bool
5167 default_valid_pointer_mode (enum machine_mode mode)
5169 return (mode == ptr_mode || mode == Pmode);
5172 /* Default function to output code that will globalize a label. A
5173 target must define GLOBAL_ASM_OP or provide it's own function to
5174 globalize a label. */
5175 #ifdef GLOBAL_ASM_OP
5176 void
5177 default_globalize_label (FILE * stream, const char *name)
5179 fputs (GLOBAL_ASM_OP, stream);
5180 assemble_name (stream, name);
5181 putc ('\n', stream);
5183 #endif /* GLOBAL_ASM_OP */
5185 /* This is how to output an internal numbered label where PREFIX is
5186 the class of label and LABELNO is the number within the class. */
5188 void
5189 default_internal_label (FILE *stream, const char *prefix,
5190 unsigned long labelno)
5192 char *const buf = alloca (40 + strlen (prefix));
5193 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5194 ASM_OUTPUT_LABEL (stream, buf);
5197 /* This is the default behavior at the beginning of a file. It's
5198 controlled by two other target-hook toggles. */
5199 void
5200 default_file_start (void)
5202 if (targetm.file_start_app_off && !flag_verbose_asm)
5203 fputs (ASM_APP_OFF, asm_out_file);
5205 if (targetm.file_start_file_directive)
5206 output_file_directive (asm_out_file, main_input_filename);
5209 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5210 which emits a special section directive used to indicate whether or
5211 not this object file needs an executable stack. This is primarily
5212 a GNU extension to ELF but could be used on other targets. */
5213 void
5214 file_end_indicate_exec_stack (void)
5216 unsigned int flags = SECTION_DEBUG;
5217 if (trampolines_created)
5218 flags |= SECTION_CODE;
5220 named_section_flags (".note.GNU-stack", flags);
5223 #include "gt-varasm.h"