* config/i386/i386.c (output_fp_compare): Add generation
[official-gcc.git] / gcc / varasm.c
blob1561dc7b7816899f9e609a1f5ce5c40c8fed79c6
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
30 #include "config.h"
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "rtl.h"
35 #include "tree.h"
36 #include "flags.h"
37 #include "function.h"
38 #include "expr.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "real.h"
42 #include "output.h"
43 #include "toplev.h"
44 #include "hashtab.h"
45 #include "c-pragma.h"
46 #include "ggc.h"
47 #include "langhooks.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
51 #include "tree-mudflap.h"
52 #include "cgraph.h"
53 #include "cfglayout.h"
55 #ifdef XCOFF_DEBUGGING_INFO
56 #include "xcoffout.h" /* Needed for external data
57 declarations for e.g. AIX 4.x. */
58 #endif
60 #ifndef ASM_STABS_OP
61 #define ASM_STABS_OP "\t.stabs\t"
62 #endif
64 /* The (assembler) name of the first globally-visible object output. */
65 const char *first_global_object_name;
66 const char *weak_global_object_name;
68 struct addr_const;
69 struct constant_descriptor_rtx;
70 struct rtx_constant_pool;
72 struct varasm_status GTY(())
74 /* If we're using a per-function constant pool, this is it. */
75 struct rtx_constant_pool *pool;
77 /* Number of tree-constants deferred during the expansion of this
78 function. */
79 unsigned int deferred_constants;
82 #define n_deferred_constants (cfun->varasm->deferred_constants)
84 /* Number for making the label on the next
85 constant that is stored in memory. */
87 static GTY(()) int const_labelno;
89 /* Carry information from ASM_DECLARE_OBJECT_NAME
90 to ASM_FINISH_DECLARE_OBJECT. */
92 int size_directive_output;
94 /* The last decl for which assemble_variable was called,
95 if it did ASM_DECLARE_OBJECT_NAME.
96 If the last call to assemble_variable didn't do that,
97 this holds 0. */
99 tree last_assemble_variable_decl;
101 /* The following global variable indicates if the section label for the
102 "cold" section of code has been output yet to the assembler. The
103 label is useful when running gdb. This is part of the optimization that
104 partitions hot and cold basic blocks into separate sections of the .o
105 file. */
107 static bool unlikely_section_label_printed = false;
109 /* The following global variable indicates the label name to be put at
110 the start of the first cold section within each function, when
111 partitioning basic blocks into hot and cold sections. */
113 static char *unlikely_section_label = NULL;
115 /* The following global variable indicates the section name to be used
116 for the current cold section, when partitioning hot and cold basic
117 blocks into separate sections. */
119 static char *unlikely_text_section_name = NULL;
121 /* We give all constants their own alias set. Perhaps redundant with
122 MEM_READONLY_P, but pre-dates it. */
124 static HOST_WIDE_INT const_alias_set;
126 static const char *strip_reg_name (const char *);
127 static int contains_pointers_p (tree);
128 #ifdef ASM_OUTPUT_EXTERNAL
129 static bool incorporeal_function_p (tree);
130 #endif
131 static void decode_addr_const (tree, struct addr_const *);
132 static hashval_t const_desc_hash (const void *);
133 static int const_desc_eq (const void *, const void *);
134 static hashval_t const_hash_1 (const tree);
135 static int compare_constant (const tree, const tree);
136 static tree copy_constant (tree);
137 static void output_constant_def_contents (rtx);
138 static void output_addressed_constants (tree);
139 static unsigned HOST_WIDE_INT array_size_for_constructor (tree);
140 static unsigned min_align (unsigned, unsigned);
141 static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int);
142 static void globalize_decl (tree);
143 static void maybe_assemble_visibility (tree);
144 static int in_named_entry_eq (const void *, const void *);
145 static hashval_t in_named_entry_hash (const void *);
146 #ifdef BSS_SECTION_ASM_OP
147 #ifdef ASM_OUTPUT_BSS
148 static void asm_output_bss (FILE *, tree, const char *,
149 unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT);
150 #endif
151 #ifdef ASM_OUTPUT_ALIGNED_BSS
152 static void asm_output_aligned_bss (FILE *, tree, const char *,
153 unsigned HOST_WIDE_INT, int)
154 ATTRIBUTE_UNUSED;
155 #endif
156 #endif /* BSS_SECTION_ASM_OP */
157 static bool asm_emit_uninitialised (tree, const char*,
158 unsigned HOST_WIDE_INT,
159 unsigned HOST_WIDE_INT);
160 static void mark_weak (tree);
162 enum in_section { no_section, in_text, in_unlikely_executed_text, in_data,
163 in_named
164 #ifdef BSS_SECTION_ASM_OP
165 , in_bss
166 #endif
167 #ifdef CTORS_SECTION_ASM_OP
168 , in_ctors
169 #endif
170 #ifdef DTORS_SECTION_ASM_OP
171 , in_dtors
172 #endif
173 #ifdef READONLY_DATA_SECTION_ASM_OP
174 , in_readonly_data
175 #endif
176 #ifdef EXTRA_SECTIONS
177 , EXTRA_SECTIONS
178 #endif
180 static GTY(()) enum in_section in_section = no_section;
182 /* Return a nonzero value if DECL has a section attribute. */
183 #ifndef IN_NAMED_SECTION
184 #define IN_NAMED_SECTION(DECL) \
185 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
186 && DECL_SECTION_NAME (DECL) != NULL_TREE)
187 #endif
189 /* Text of section name when in_section == in_named. */
190 static GTY(()) const char *in_named_name;
192 /* Hash table of flags that have been used for a particular named section. */
194 struct in_named_entry GTY(())
196 const char *name;
197 unsigned int flags;
198 bool declared;
201 static GTY((param_is (struct in_named_entry))) htab_t in_named_htab;
203 /* Define functions like text_section for any extra sections. */
204 #ifdef EXTRA_SECTION_FUNCTIONS
205 EXTRA_SECTION_FUNCTIONS
206 #endif
208 /* Tell assembler to switch to text section. */
210 void
211 text_section (void)
213 if (in_section != in_text)
215 in_section = in_text;
216 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
220 /* Tell assembler to switch to unlikely-to-be-executed text section. */
222 void
223 unlikely_text_section (void)
225 const char *name;
226 int len;
228 if (! unlikely_text_section_name)
230 if (DECL_SECTION_NAME (current_function_decl)
231 && (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME
232 (current_function_decl)),
233 HOT_TEXT_SECTION_NAME) != 0)
234 && (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME
235 (current_function_decl)),
236 UNLIKELY_EXECUTED_TEXT_SECTION_NAME) != 0))
238 name = TREE_STRING_POINTER (DECL_SECTION_NAME
239 (current_function_decl));
240 len = strlen (name);
241 unlikely_text_section_name = xmalloc ((len + 10) * sizeof (char));
242 strcpy (unlikely_text_section_name, name);
243 strcat (unlikely_text_section_name, "_unlikely");
245 else
247 len = strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
248 unlikely_text_section_name = xmalloc (len+1 * sizeof (char));
249 strcpy (unlikely_text_section_name,
250 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
254 if ((in_section != in_unlikely_executed_text)
255 && (in_section != in_named
256 || strcmp (in_named_name, unlikely_text_section_name) != 0))
258 named_section (NULL_TREE, unlikely_text_section_name, 0);
259 in_section = in_unlikely_executed_text;
261 if (!unlikely_section_label_printed)
263 ASM_OUTPUT_LABEL (asm_out_file, unlikely_section_label);
264 unlikely_section_label_printed = true;
269 /* Tell assembler to switch to data section. */
271 void
272 data_section (void)
274 if (in_section != in_data)
276 in_section = in_data;
277 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
281 /* Tell assembler to switch to read-only data section. This is normally
282 the text section. */
284 void
285 readonly_data_section (void)
287 #ifdef READONLY_DATA_SECTION
288 READONLY_DATA_SECTION (); /* Note this can call data_section. */
289 #else
290 #ifdef READONLY_DATA_SECTION_ASM_OP
291 if (in_section != in_readonly_data)
293 in_section = in_readonly_data;
294 fputs (READONLY_DATA_SECTION_ASM_OP, asm_out_file);
295 fputc ('\n', asm_out_file);
297 #else
298 text_section ();
299 #endif
300 #endif
303 /* Determine if we're in the text section. */
306 in_text_section (void)
308 return in_section == in_text;
311 /* Determine if we're in the unlikely-to-be-executed text section. */
314 in_unlikely_text_section (void)
316 bool ret_val;
318 ret_val = ((in_section == in_unlikely_executed_text)
319 || (in_section == in_named
320 && unlikely_text_section_name
321 && strcmp (in_named_name, unlikely_text_section_name) == 0));
323 return ret_val;
326 /* Determine if we're in the data section. */
329 in_data_section (void)
331 return in_section == in_data;
334 /* Helper routines for maintaining in_named_htab. */
336 static int
337 in_named_entry_eq (const void *p1, const void *p2)
339 const struct in_named_entry *old = p1;
340 const char *new = p2;
342 return strcmp (old->name, new) == 0;
345 static hashval_t
346 in_named_entry_hash (const void *p)
348 const struct in_named_entry *old = p;
349 return htab_hash_string (old->name);
352 /* If SECTION has been seen before as a named section, return the flags
353 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
354 set of flags for a section to have, so 0 does not mean that the section
355 has not been seen. */
357 unsigned int
358 get_named_section_flags (const char *section)
360 struct in_named_entry **slot;
362 slot = (struct in_named_entry **)
363 htab_find_slot_with_hash (in_named_htab, section,
364 htab_hash_string (section), NO_INSERT);
366 return slot ? (*slot)->flags : 0;
369 /* Returns true if the section has been declared before. Sets internal
370 flag on this section in in_named_hash so subsequent calls on this
371 section will return false. */
373 bool
374 named_section_first_declaration (const char *name)
376 struct in_named_entry **slot;
378 slot = (struct in_named_entry **)
379 htab_find_slot_with_hash (in_named_htab, name,
380 htab_hash_string (name), NO_INSERT);
381 if (! (*slot)->declared)
383 (*slot)->declared = true;
384 return true;
386 else
388 return false;
393 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
394 different set of flags, return false. */
396 bool
397 set_named_section_flags (const char *section, unsigned int flags)
399 struct in_named_entry **slot, *entry;
401 slot = (struct in_named_entry **)
402 htab_find_slot_with_hash (in_named_htab, section,
403 htab_hash_string (section), INSERT);
404 entry = *slot;
406 if (!entry)
408 entry = ggc_alloc (sizeof (*entry));
409 *slot = entry;
410 entry->name = ggc_strdup (section);
411 entry->flags = flags;
412 entry->declared = false;
414 else if (entry->flags != flags)
415 return false;
417 return true;
420 /* Tell assembler to change to section NAME with attributes FLAGS. */
422 void
423 named_section_flags (const char *name, unsigned int flags)
425 if (in_section != in_named || strcmp (name, in_named_name) != 0)
427 if (! set_named_section_flags (name, flags))
428 abort ();
430 targetm.asm_out.named_section (name, flags);
432 if (flags & SECTION_FORGET)
433 in_section = no_section;
434 else
436 in_named_name = ggc_strdup (name);
437 in_section = in_named;
442 /* Tell assembler to change to section NAME for DECL.
443 If DECL is NULL, just switch to section NAME.
444 If NAME is NULL, get the name from DECL.
445 If RELOC is 1, the initializer for DECL contains relocs. */
447 void
448 named_section (tree decl, const char *name, int reloc)
450 unsigned int flags;
452 if (decl != NULL_TREE && !DECL_P (decl))
453 abort ();
454 if (name == NULL)
455 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
457 if (strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0
458 && !unlikely_text_section_name)
460 unlikely_text_section_name = xmalloc
461 (strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME) + 1
462 * sizeof (char));
463 strcpy (unlikely_text_section_name,
464 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
467 flags = targetm.section_type_flags (decl, name, reloc);
469 /* Sanity check user variables for flag changes. Non-user
470 section flag changes will abort in named_section_flags.
471 However, don't complain if SECTION_OVERRIDE is set.
472 We trust that the setter knows that it is safe to ignore
473 the default flags for this decl. */
474 if (decl && ! set_named_section_flags (name, flags))
476 flags = get_named_section_flags (name);
477 if ((flags & SECTION_OVERRIDE) == 0)
478 error ("%J%D causes a section type conflict", decl, decl);
481 named_section_flags (name, flags);
484 /* If required, set DECL_SECTION_NAME to a unique name. */
486 void
487 resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
488 int flag_function_or_data_sections)
490 if (DECL_SECTION_NAME (decl) == NULL_TREE
491 && targetm.have_named_sections
492 && (flag_function_or_data_sections
493 || DECL_ONE_ONLY (decl)))
494 targetm.asm_out.unique_section (decl, reloc);
497 #ifdef BSS_SECTION_ASM_OP
499 /* Tell the assembler to switch to the bss section. */
501 void
502 bss_section (void)
504 if (in_section != in_bss)
506 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
507 in_section = in_bss;
511 #ifdef ASM_OUTPUT_BSS
513 /* Utility function for ASM_OUTPUT_BSS for targets to use if
514 they don't support alignments in .bss.
515 ??? It is believed that this function will work in most cases so such
516 support is localized here. */
518 static void
519 asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
520 const char *name,
521 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
522 unsigned HOST_WIDE_INT rounded)
524 targetm.asm_out.globalize_label (file, name);
525 bss_section ();
526 #ifdef ASM_DECLARE_OBJECT_NAME
527 last_assemble_variable_decl = decl;
528 ASM_DECLARE_OBJECT_NAME (file, name, decl);
529 #else
530 /* Standard thing is just output label for the object. */
531 ASM_OUTPUT_LABEL (file, name);
532 #endif /* ASM_DECLARE_OBJECT_NAME */
533 ASM_OUTPUT_SKIP (file, rounded ? rounded : 1);
536 #endif
538 #ifdef ASM_OUTPUT_ALIGNED_BSS
540 /* Utility function for targets to use in implementing
541 ASM_OUTPUT_ALIGNED_BSS.
542 ??? It is believed that this function will work in most cases so such
543 support is localized here. */
545 static void
546 asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
547 const char *name, unsigned HOST_WIDE_INT size,
548 int align)
550 bss_section ();
551 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
552 #ifdef ASM_DECLARE_OBJECT_NAME
553 last_assemble_variable_decl = decl;
554 ASM_DECLARE_OBJECT_NAME (file, name, decl);
555 #else
556 /* Standard thing is just output label for the object. */
557 ASM_OUTPUT_LABEL (file, name);
558 #endif /* ASM_DECLARE_OBJECT_NAME */
559 ASM_OUTPUT_SKIP (file, size ? size : 1);
562 #endif
564 #endif /* BSS_SECTION_ASM_OP */
566 /* Switch to the section for function DECL.
568 If DECL is NULL_TREE, switch to the text section.
569 ??? It's not clear that we will ever be passed NULL_TREE, but it's
570 safer to handle it. */
572 void
573 function_section (tree decl)
575 if (scan_ahead_for_unlikely_executed_note (get_insns()))
576 unlikely_text_section ();
577 else if (decl != NULL_TREE
578 && DECL_SECTION_NAME (decl) != NULL_TREE)
579 named_section (decl, (char *) 0, 0);
580 else
581 text_section ();
584 /* Switch to read-only data section associated with function DECL. */
586 void
587 default_function_rodata_section (tree decl)
589 if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
591 const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
593 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
594 if (DECL_ONE_ONLY (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
596 size_t len = strlen (name) + 1;
597 char *rname = alloca (len);
599 memcpy (rname, name, len);
600 rname[14] = 'r';
601 named_section_flags (rname, SECTION_LINKONCE);
602 return;
604 /* For .text.foo we want to use .rodata.foo. */
605 else if (flag_function_sections && flag_data_sections
606 && strncmp (name, ".text.", 6) == 0)
608 size_t len = strlen (name) + 1;
609 char *rname = alloca (len + 2);
611 memcpy (rname, ".rodata", 7);
612 memcpy (rname + 7, name + 5, len - 5);
613 named_section_flags (rname, 0);
614 return;
618 readonly_data_section ();
621 /* Switch to read-only data section associated with function DECL
622 for targets where that section should be always the single
623 readonly data section. */
625 void
626 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
628 readonly_data_section ();
631 /* Switch to section for variable DECL. RELOC is the same as the
632 argument to SELECT_SECTION. */
634 void
635 variable_section (tree decl, int reloc)
637 if (IN_NAMED_SECTION (decl))
638 named_section (decl, NULL, reloc);
639 else
640 targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl));
643 /* Tell assembler to switch to the section for string merging. */
645 void
646 mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
647 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
648 unsigned int flags ATTRIBUTE_UNUSED)
650 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
651 && TREE_CODE (decl) == STRING_CST
652 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
653 && align <= 256
654 && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl)))
656 enum machine_mode mode;
657 unsigned int modesize;
658 const char *str;
659 int i, j, len, unit;
660 char name[30];
662 mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
663 modesize = GET_MODE_BITSIZE (mode);
664 if (modesize >= 8 && modesize <= 256
665 && (modesize & (modesize - 1)) == 0)
667 if (align < modesize)
668 align = modesize;
670 str = TREE_STRING_POINTER (decl);
671 len = TREE_STRING_LENGTH (decl);
672 unit = GET_MODE_SIZE (mode);
674 /* Check for embedded NUL characters. */
675 for (i = 0; i < len; i += unit)
677 for (j = 0; j < unit; j++)
678 if (str[i + j] != '\0')
679 break;
680 if (j == unit)
681 break;
683 if (i == len - unit)
685 sprintf (name, ".rodata.str%d.%d", modesize / 8,
686 (int) (align / 8));
687 flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
688 if (!i && modesize < align)
690 /* A "" string with requested alignment greater than
691 character size might cause a problem:
692 if some other string required even bigger
693 alignment than "", then linker might think the
694 "" is just part of padding after some other string
695 and not put it into the hash table initially.
696 But this means "" could have smaller alignment
697 than requested. */
698 #ifdef ASM_OUTPUT_SECTION_START
699 named_section_flags (name, flags);
700 ASM_OUTPUT_SECTION_START (asm_out_file);
701 #else
702 readonly_data_section ();
703 #endif
704 return;
707 named_section_flags (name, flags);
708 return;
713 readonly_data_section ();
716 /* Tell assembler to switch to the section for constant merging. */
718 void
719 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED,
720 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
721 unsigned int flags ATTRIBUTE_UNUSED)
723 unsigned int modesize = GET_MODE_BITSIZE (mode);
725 if (HAVE_GAS_SHF_MERGE && flag_merge_constants
726 && mode != VOIDmode
727 && mode != BLKmode
728 && modesize <= align
729 && align >= 8
730 && align <= 256
731 && (align & (align - 1)) == 0)
733 char name[24];
735 sprintf (name, ".rodata.cst%d", (int) (align / 8));
736 flags |= (align / 8) | SECTION_MERGE;
737 named_section_flags (name, flags);
738 return;
741 readonly_data_section ();
744 /* Given NAME, a putative register name, discard any customary prefixes. */
746 static const char *
747 strip_reg_name (const char *name)
749 #ifdef REGISTER_PREFIX
750 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
751 name += strlen (REGISTER_PREFIX);
752 #endif
753 if (name[0] == '%' || name[0] == '#')
754 name++;
755 return name;
758 /* The user has asked for a DECL to have a particular name. Set (or
759 change) it in such a way that we don't prefix an underscore to
760 it. */
761 void
762 set_user_assembler_name (tree decl, const char *name)
764 char *starred = alloca (strlen (name) + 2);
765 starred[0] = '*';
766 strcpy (starred + 1, name);
767 change_decl_assembler_name (decl, get_identifier (starred));
768 SET_DECL_RTL (decl, NULL_RTX);
771 /* Decode an `asm' spec for a declaration as a register name.
772 Return the register number, or -1 if nothing specified,
773 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
774 or -3 if ASMSPEC is `cc' and is not recognized,
775 or -4 if ASMSPEC is `memory' and is not recognized.
776 Accept an exact spelling or a decimal number.
777 Prefixes such as % are optional. */
780 decode_reg_name (const char *asmspec)
782 if (asmspec != 0 && strlen (asmspec) != 0)
784 int i;
786 /* Get rid of confusing prefixes. */
787 asmspec = strip_reg_name (asmspec);
789 /* Allow a decimal number as a "register name". */
790 for (i = strlen (asmspec) - 1; i >= 0; i--)
791 if (! ISDIGIT (asmspec[i]))
792 break;
793 if (asmspec[0] != 0 && i < 0)
795 i = atoi (asmspec);
796 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
797 return i;
798 else
799 return -2;
802 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
803 if (reg_names[i][0]
804 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
805 return i;
807 #ifdef ADDITIONAL_REGISTER_NAMES
809 static const struct { const char *const name; const int number; } table[]
810 = ADDITIONAL_REGISTER_NAMES;
812 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
813 if (! strcmp (asmspec, table[i].name))
814 return table[i].number;
816 #endif /* ADDITIONAL_REGISTER_NAMES */
818 if (!strcmp (asmspec, "memory"))
819 return -4;
821 if (!strcmp (asmspec, "cc"))
822 return -3;
824 return -2;
827 return -1;
830 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
831 have static storage duration. In other words, it should not be an
832 automatic variable, including PARM_DECLs.
834 There is, however, one exception: this function handles variables
835 explicitly placed in a particular register by the user.
837 This is never called for PARM_DECL nodes. */
839 void
840 make_decl_rtl (tree decl)
842 const char *name = 0;
843 int reg_number;
844 rtx x;
846 /* Check that we are not being given an automatic variable. */
847 /* A weak alias has TREE_PUBLIC set but not the other bits. */
848 if (TREE_CODE (decl) == PARM_DECL
849 || TREE_CODE (decl) == RESULT_DECL
850 || (TREE_CODE (decl) == VAR_DECL
851 && !TREE_STATIC (decl)
852 && !TREE_PUBLIC (decl)
853 && !DECL_EXTERNAL (decl)
854 && !DECL_REGISTER (decl)))
855 abort ();
856 /* And that we were not given a type or a label. */
857 else if (TREE_CODE (decl) == TYPE_DECL
858 || TREE_CODE (decl) == LABEL_DECL)
859 abort ();
861 /* For a duplicate declaration, we can be called twice on the
862 same DECL node. Don't discard the RTL already made. */
863 if (DECL_RTL_SET_P (decl))
865 /* If the old RTL had the wrong mode, fix the mode. */
866 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
867 SET_DECL_RTL (decl, adjust_address_nv (DECL_RTL (decl),
868 DECL_MODE (decl), 0));
870 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
871 return;
873 /* ??? Another way to do this would be to maintain a hashed
874 table of such critters. Instead of adding stuff to a DECL
875 to give certain attributes to it, we could use an external
876 hash map from DECL to set of attributes. */
878 /* Let the target reassign the RTL if it wants.
879 This is necessary, for example, when one machine specific
880 decl attribute overrides another. */
881 targetm.encode_section_info (decl, DECL_RTL (decl), false);
883 /* Make this function static known to the mudflap runtime. */
884 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
885 mudflap_enqueue_decl (decl);
887 return;
890 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
892 reg_number = decode_reg_name (name);
894 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
896 /* First detect errors in declaring global registers. */
897 if (reg_number == -1)
898 error ("%Jregister name not specified for '%D'", decl, decl);
899 else if (reg_number < 0)
900 error ("%Jinvalid register name for '%D'", decl, decl);
901 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
902 error ("%Jdata type of '%D' isn't suitable for a register",
903 decl, decl);
904 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
905 error ("%Jregister specified for '%D' isn't suitable for data type",
906 decl, decl);
907 /* Now handle properly declared static register variables. */
908 else
910 int nregs;
912 if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
914 DECL_INITIAL (decl) = 0;
915 error ("global register variable has initial value");
917 if (TREE_THIS_VOLATILE (decl))
918 warning ("volatile register variables don't work as you might wish");
920 /* If the user specified one of the eliminables registers here,
921 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
922 confused with that register and be eliminated. This usage is
923 somewhat suspect... */
925 SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number));
926 ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
927 REG_USERVAR_P (DECL_RTL (decl)) = 1;
929 if (TREE_STATIC (decl))
931 /* Make this register global, so not usable for anything
932 else. */
933 #ifdef ASM_DECLARE_REGISTER_GLOBAL
934 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
935 #endif
936 nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)];
937 while (nregs > 0)
938 globalize_reg (reg_number + --nregs);
941 /* As a register variable, it has no section. */
942 return;
946 /* Now handle ordinary static variables and functions (in memory).
947 Also handle vars declared register invalidly. */
949 if (name[0] == '*' && (reg_number >= 0 || reg_number == -3))
950 error ("%Jregister name given for non-register variable '%D'", decl, decl);
952 /* Specifying a section attribute on a variable forces it into a
953 non-.bss section, and thus it cannot be common. */
954 if (TREE_CODE (decl) == VAR_DECL
955 && DECL_SECTION_NAME (decl) != NULL_TREE
956 && DECL_INITIAL (decl) == NULL_TREE
957 && DECL_COMMON (decl))
958 DECL_COMMON (decl) = 0;
960 /* Variables can't be both common and weak. */
961 if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl))
962 DECL_COMMON (decl) = 0;
964 x = gen_rtx_SYMBOL_REF (Pmode, name);
965 SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
966 SYMBOL_REF_DECL (x) = decl;
968 x = gen_rtx_MEM (DECL_MODE (decl), x);
969 if (TREE_CODE (decl) != FUNCTION_DECL)
970 set_mem_attributes (x, decl, 1);
971 SET_DECL_RTL (decl, x);
973 /* Optionally set flags or add text to the name to record information
974 such as that it is a function name.
975 If the name is changed, the macro ASM_OUTPUT_LABELREF
976 will have to know how to strip this information. */
977 targetm.encode_section_info (decl, DECL_RTL (decl), true);
979 /* Make this function static known to the mudflap runtime. */
980 if (flag_mudflap && TREE_CODE (decl) == VAR_DECL)
981 mudflap_enqueue_decl (decl);
984 /* Make the rtl for variable VAR be volatile.
985 Use this only for static variables. */
987 void
988 make_var_volatile (tree var)
990 if (!MEM_P (DECL_RTL (var)))
991 abort ();
993 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
996 /* Output a string of literal assembler code
997 for an `asm' keyword used between functions. */
999 void
1000 assemble_asm (tree string)
1002 app_enable ();
1004 if (TREE_CODE (string) == ADDR_EXPR)
1005 string = TREE_OPERAND (string, 0);
1007 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
1010 /* Record an element in the table of global destructors. SYMBOL is
1011 a SYMBOL_REF of the function to be called; PRIORITY is a number
1012 between 0 and MAX_INIT_PRIORITY. */
1014 void
1015 default_stabs_asm_out_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
1017 /* Tell GNU LD that this is part of the static destructor set.
1018 This will work for any system that uses stabs, most usefully
1019 aout systems. */
1020 fprintf (asm_out_file, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1021 assemble_name (asm_out_file, XSTR (symbol, 0));
1022 fputc ('\n', asm_out_file);
1025 void
1026 default_named_section_asm_out_destructor (rtx symbol, int priority)
1028 const char *section = ".dtors";
1029 char buf[16];
1031 /* ??? This only works reliably with the GNU linker. */
1032 if (priority != DEFAULT_INIT_PRIORITY)
1034 sprintf (buf, ".dtors.%.5u",
1035 /* Invert the numbering so the linker puts us in the proper
1036 order; constructors are run from right to left, and the
1037 linker sorts in increasing order. */
1038 MAX_INIT_PRIORITY - priority);
1039 section = buf;
1042 named_section_flags (section, SECTION_WRITE);
1043 assemble_align (POINTER_SIZE);
1044 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1047 #ifdef DTORS_SECTION_ASM_OP
1048 void
1049 dtors_section (void)
1051 if (in_section != in_dtors)
1053 in_section = in_dtors;
1054 fputs (DTORS_SECTION_ASM_OP, asm_out_file);
1055 fputc ('\n', asm_out_file);
1059 void
1060 default_dtor_section_asm_out_destructor (rtx symbol,
1061 int priority ATTRIBUTE_UNUSED)
1063 dtors_section ();
1064 assemble_align (POINTER_SIZE);
1065 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1067 #endif
1069 /* Likewise for global constructors. */
1071 void
1072 default_stabs_asm_out_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
1074 /* Tell GNU LD that this is part of the static destructor set.
1075 This will work for any system that uses stabs, most usefully
1076 aout systems. */
1077 fprintf (asm_out_file, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
1078 assemble_name (asm_out_file, XSTR (symbol, 0));
1079 fputc ('\n', asm_out_file);
1082 void
1083 default_named_section_asm_out_constructor (rtx symbol, int priority)
1085 const char *section = ".ctors";
1086 char buf[16];
1088 /* ??? This only works reliably with the GNU linker. */
1089 if (priority != DEFAULT_INIT_PRIORITY)
1091 sprintf (buf, ".ctors.%.5u",
1092 /* Invert the numbering so the linker puts us in the proper
1093 order; constructors are run from right to left, and the
1094 linker sorts in increasing order. */
1095 MAX_INIT_PRIORITY - priority);
1096 section = buf;
1099 named_section_flags (section, SECTION_WRITE);
1100 assemble_align (POINTER_SIZE);
1101 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1104 #ifdef CTORS_SECTION_ASM_OP
1105 void
1106 ctors_section (void)
1108 if (in_section != in_ctors)
1110 in_section = in_ctors;
1111 fputs (CTORS_SECTION_ASM_OP, asm_out_file);
1112 fputc ('\n', asm_out_file);
1116 void
1117 default_ctor_section_asm_out_constructor (rtx symbol,
1118 int priority ATTRIBUTE_UNUSED)
1120 ctors_section ();
1121 assemble_align (POINTER_SIZE);
1122 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
1124 #endif
1126 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1127 a nonzero value if the constant pool should be output before the
1128 start of the function, or a zero value if the pool should output
1129 after the end of the function. The default is to put it before the
1130 start. */
1132 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1133 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1134 #endif
1136 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1137 to be output to assembler.
1138 Set first_global_object_name and weak_global_object_name as appropriate. */
1140 void
1141 notice_global_symbol (tree decl)
1143 const char **type = &first_global_object_name;
1145 if (first_global_object_name
1146 || !TREE_PUBLIC (decl) || DECL_EXTERNAL (decl)
1147 || !DECL_NAME (decl)
1148 || (TREE_CODE (decl) != FUNCTION_DECL
1149 && (TREE_CODE (decl) != VAR_DECL
1150 || (DECL_COMMON (decl)
1151 && (DECL_INITIAL (decl) == 0
1152 || DECL_INITIAL (decl) == error_mark_node))))
1153 || !MEM_P (DECL_RTL (decl)))
1154 return;
1156 /* We win when global object is found, but it is useful to know about weak
1157 symbol as well so we can produce nicer unique names. */
1158 if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl))
1159 type = &weak_global_object_name;
1161 if (!*type)
1163 const char *p;
1164 char *name;
1165 rtx decl_rtl = DECL_RTL (decl);
1167 p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0));
1168 name = xstrdup (p);
1170 *type = name;
1174 /* Output assembler code for the constant pool of a function and associated
1175 with defining the name of the function. DECL describes the function.
1176 NAME is the function's name. For the constant pool, we use the current
1177 constant pool data. */
1179 void
1180 assemble_start_function (tree decl, const char *fnname)
1182 int align;
1184 if (unlikely_text_section_name)
1185 free (unlikely_text_section_name);
1187 unlikely_section_label_printed = false;
1188 unlikely_text_section_name = NULL;
1190 unlikely_section_label = reconcat (unlikely_section_label,
1191 fnname, ".unlikely_section", NULL);
1193 /* The following code does not need preprocessing in the assembler. */
1195 app_disable ();
1197 if (CONSTANT_POOL_BEFORE_FUNCTION)
1198 output_constant_pool (fnname, decl);
1200 /* Make sure the cold text (code) section is properly aligned. This
1201 is necessary here in the case where the function has both hot and
1202 cold sections, because we don't want to re-set the alignment when the
1203 section switch happens mid-function. We don't need to set the hot
1204 section alignment here, because code further down in this function
1205 sets the alignment for whichever section comes first, and if there
1206 is a hot section it is guaranteed to be first. */
1208 if (flag_reorder_blocks_and_partition)
1210 unlikely_text_section ();
1211 assemble_align (FUNCTION_BOUNDARY);
1214 resolve_unique_section (decl, 0, flag_function_sections);
1215 function_section (decl);
1217 /* Tell assembler to move to target machine's alignment for functions. */
1218 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1219 if (align < force_align_functions_log)
1220 align = force_align_functions_log;
1221 if (align > 0)
1223 ASM_OUTPUT_ALIGN (asm_out_file, align);
1226 /* Handle a user-specified function alignment.
1227 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1228 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1229 if (align_functions_log > align
1230 && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED)
1232 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1233 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1234 align_functions_log, align_functions - 1);
1235 #else
1236 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1237 #endif
1240 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1241 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1242 #endif
1244 (*debug_hooks->begin_function) (decl);
1246 /* Make function name accessible from other files, if appropriate. */
1248 if (TREE_PUBLIC (decl))
1250 notice_global_symbol (decl);
1252 globalize_decl (decl);
1254 maybe_assemble_visibility (decl);
1257 if (DECL_PRESERVE_P (decl))
1258 targetm.asm_out.mark_decl_preserved (fnname);
1260 /* Do any machine/system dependent processing of the function name. */
1261 #ifdef ASM_DECLARE_FUNCTION_NAME
1262 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1263 #else
1264 /* Standard thing is just output label for the function. */
1265 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1266 #endif /* ASM_DECLARE_FUNCTION_NAME */
1268 if (in_unlikely_text_section ()
1269 && !unlikely_section_label_printed)
1271 ASM_OUTPUT_LABEL (asm_out_file, unlikely_section_label);
1272 unlikely_section_label_printed = true;
1276 /* Output assembler code associated with defining the size of the
1277 function. DECL describes the function. NAME is the function's name. */
1279 void
1280 assemble_end_function (tree decl, const char *fnname)
1282 #ifdef ASM_DECLARE_FUNCTION_SIZE
1283 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1284 #endif
1285 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1287 output_constant_pool (fnname, decl);
1288 function_section (decl); /* need to switch back */
1292 /* Assemble code to leave SIZE bytes of zeros. */
1294 void
1295 assemble_zeros (unsigned HOST_WIDE_INT size)
1297 /* Do no output if -fsyntax-only. */
1298 if (flag_syntax_only)
1299 return;
1301 #ifdef ASM_NO_SKIP_IN_TEXT
1302 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1303 so we must output 0s explicitly in the text section. */
1304 if ((ASM_NO_SKIP_IN_TEXT && in_text_section ())
1305 || (ASM_NO_SKIP_IN_TEXT && in_unlikely_text_section ()))
1307 unsigned HOST_WIDE_INT i;
1308 for (i = 0; i < size; i++)
1309 assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
1311 else
1312 #endif
1313 if (size > 0)
1314 ASM_OUTPUT_SKIP (asm_out_file, size);
1317 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1319 void
1320 assemble_align (int align)
1322 if (align > BITS_PER_UNIT)
1324 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1328 /* Assemble a string constant with the specified C string as contents. */
1330 void
1331 assemble_string (const char *p, int size)
1333 int pos = 0;
1334 int maximum = 2000;
1336 /* If the string is very long, split it up. */
1338 while (pos < size)
1340 int thissize = size - pos;
1341 if (thissize > maximum)
1342 thissize = maximum;
1344 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1346 pos += thissize;
1347 p += thissize;
1352 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1353 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1354 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1355 #else
1356 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1357 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1358 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1359 #else
1360 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1361 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1362 #endif
1363 #endif
1365 #if defined ASM_OUTPUT_ALIGNED_BSS
1366 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1367 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1368 #else
1369 #if defined ASM_OUTPUT_BSS
1370 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1371 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1372 #else
1373 #undef ASM_EMIT_BSS
1374 #endif
1375 #endif
1377 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1378 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1379 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1380 #else
1381 #if defined ASM_OUTPUT_ALIGNED_COMMON
1382 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1383 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1384 #else
1385 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1386 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1387 #endif
1388 #endif
1390 static bool
1391 asm_emit_uninitialised (tree decl, const char *name,
1392 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
1393 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
1395 enum
1397 asm_dest_common,
1398 asm_dest_bss,
1399 asm_dest_local
1401 destination = asm_dest_local;
1403 /* ??? We should handle .bss via select_section mechanisms rather than
1404 via special target hooks. That would eliminate this special case. */
1405 if (TREE_PUBLIC (decl))
1407 if (!DECL_COMMON (decl))
1408 #ifdef ASM_EMIT_BSS
1409 destination = asm_dest_bss;
1410 #else
1411 return false;
1412 #endif
1413 else
1414 destination = asm_dest_common;
1417 if (destination == asm_dest_bss)
1418 globalize_decl (decl);
1419 resolve_unique_section (decl, 0, flag_data_sections);
1421 if (flag_shared_data)
1423 switch (destination)
1425 #ifdef ASM_OUTPUT_SHARED_BSS
1426 case asm_dest_bss:
1427 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1428 return;
1429 #endif
1430 #ifdef ASM_OUTPUT_SHARED_COMMON
1431 case asm_dest_common:
1432 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1433 return;
1434 #endif
1435 #ifdef ASM_OUTPUT_SHARED_LOCAL
1436 case asm_dest_local:
1437 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1438 return;
1439 #endif
1440 default:
1441 break;
1445 switch (destination)
1447 #ifdef ASM_EMIT_BSS
1448 case asm_dest_bss:
1449 ASM_EMIT_BSS (decl, name, size, rounded);
1450 break;
1451 #endif
1452 case asm_dest_common:
1453 ASM_EMIT_COMMON (decl, name, size, rounded);
1454 break;
1455 case asm_dest_local:
1456 ASM_EMIT_LOCAL (decl, name, size, rounded);
1457 break;
1458 default:
1459 abort ();
1462 return true;
1465 /* Assemble everything that is needed for a variable or function declaration.
1466 Not used for automatic variables, and not used for function definitions.
1467 Should not be called for variables of incomplete structure type.
1469 TOP_LEVEL is nonzero if this variable has file scope.
1470 AT_END is nonzero if this is the special handling, at end of compilation,
1471 to define things that have had only tentative definitions.
1472 DONT_OUTPUT_DATA if nonzero means don't actually output the
1473 initial value (that will be done by the caller). */
1475 void
1476 assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
1477 int at_end ATTRIBUTE_UNUSED, int dont_output_data)
1479 const char *name;
1480 unsigned int align;
1481 int reloc = 0;
1482 rtx decl_rtl;
1484 if (lang_hooks.decls.prepare_assemble_variable)
1485 lang_hooks.decls.prepare_assemble_variable (decl);
1487 last_assemble_variable_decl = 0;
1489 /* Normally no need to say anything here for external references,
1490 since assemble_external is called by the language-specific code
1491 when a declaration is first seen. */
1493 if (DECL_EXTERNAL (decl))
1494 return;
1496 /* Output no assembler code for a function declaration.
1497 Only definitions of functions output anything. */
1499 if (TREE_CODE (decl) == FUNCTION_DECL)
1500 return;
1502 /* Do nothing for global register variables. */
1503 if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
1505 TREE_ASM_WRITTEN (decl) = 1;
1506 return;
1509 /* If type was incomplete when the variable was declared,
1510 see if it is complete now. */
1512 if (DECL_SIZE (decl) == 0)
1513 layout_decl (decl, 0);
1515 /* Still incomplete => don't allocate it; treat the tentative defn
1516 (which is what it must have been) as an `extern' reference. */
1518 if (!dont_output_data && DECL_SIZE (decl) == 0)
1520 error ("%Jstorage size of `%D' isn't known", decl, decl);
1521 TREE_ASM_WRITTEN (decl) = 1;
1522 return;
1525 /* The first declaration of a variable that comes through this function
1526 decides whether it is global (in C, has external linkage)
1527 or local (in C, has internal linkage). So do nothing more
1528 if this function has already run. */
1530 if (TREE_ASM_WRITTEN (decl))
1531 return;
1533 /* Make sure targetm.encode_section_info is invoked before we set
1534 ASM_WRITTEN. */
1535 decl_rtl = DECL_RTL (decl);
1537 TREE_ASM_WRITTEN (decl) = 1;
1539 /* Do no output if -fsyntax-only. */
1540 if (flag_syntax_only)
1541 return;
1543 app_disable ();
1545 if (! dont_output_data
1546 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1548 error ("%Jsize of variable '%D' is too large", decl, decl);
1549 return;
1552 name = XSTR (XEXP (decl_rtl, 0), 0);
1553 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1554 notice_global_symbol (decl);
1556 /* Compute the alignment of this data. */
1558 align = DECL_ALIGN (decl);
1560 /* In the case for initialing an array whose length isn't specified,
1561 where we have not yet been able to do the layout,
1562 figure out the proper alignment now. */
1563 if (dont_output_data && DECL_SIZE (decl) == 0
1564 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1565 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1567 /* Some object file formats have a maximum alignment which they support.
1568 In particular, a.out format supports a maximum alignment of 4. */
1569 if (align > MAX_OFILE_ALIGNMENT)
1571 warning ("%Jalignment of '%D' is greater than maximum object "
1572 "file alignment. Using %d", decl, decl,
1573 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1574 align = MAX_OFILE_ALIGNMENT;
1577 /* On some machines, it is good to increase alignment sometimes. */
1578 if (! DECL_USER_ALIGN (decl))
1580 #ifdef DATA_ALIGNMENT
1581 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1582 #endif
1583 #ifdef CONSTANT_ALIGNMENT
1584 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1585 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1586 #endif
1589 /* Reset the alignment in case we have made it tighter, so we can benefit
1590 from it in get_pointer_alignment. */
1591 DECL_ALIGN (decl) = align;
1592 set_mem_align (decl_rtl, align);
1594 if (TREE_PUBLIC (decl))
1595 maybe_assemble_visibility (decl);
1597 if (DECL_PRESERVE_P (decl))
1598 targetm.asm_out.mark_decl_preserved (name);
1600 /* Output any data that we will need to use the address of. */
1601 if (DECL_INITIAL (decl) == error_mark_node)
1602 reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1603 else if (DECL_INITIAL (decl))
1605 reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1606 output_addressed_constants (DECL_INITIAL (decl));
1608 resolve_unique_section (decl, reloc, flag_data_sections);
1610 /* Handle uninitialized definitions. */
1612 /* If the decl has been given an explicit section name, then it
1613 isn't common, and shouldn't be handled as such. */
1614 if (DECL_SECTION_NAME (decl) || dont_output_data)
1616 /* We don't implement common thread-local data at present. */
1617 else if (DECL_THREAD_LOCAL (decl))
1619 if (DECL_COMMON (decl))
1620 sorry ("thread-local COMMON data not implemented");
1622 else if (DECL_INITIAL (decl) == 0
1623 || DECL_INITIAL (decl) == error_mark_node
1624 || (flag_zero_initialized_in_bss
1625 /* Leave constant zeroes in .rodata so they can be shared. */
1626 && !TREE_READONLY (decl)
1627 && initializer_zerop (DECL_INITIAL (decl))))
1629 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1630 unsigned HOST_WIDE_INT rounded = size;
1632 /* Don't allocate zero bytes of common,
1633 since that means "undefined external" in the linker. */
1634 if (size == 0)
1635 rounded = 1;
1637 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1638 so that each uninitialized object starts on such a boundary. */
1639 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1640 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1641 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1643 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1644 if ((unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded)
1645 warning ("%Jrequested alignment for '%D' is greater than "
1646 "implemented alignment of %d", decl, decl, rounded);
1647 #endif
1649 /* If the target cannot output uninitialized but not common global data
1650 in .bss, then we have to use .data, so fall through. */
1651 if (asm_emit_uninitialised (decl, name, size, rounded))
1652 return;
1655 /* Handle initialized definitions.
1656 Also handle uninitialized global definitions if -fno-common and the
1657 target doesn't support ASM_OUTPUT_BSS. */
1659 /* First make the assembler name(s) global if appropriate. */
1660 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1661 globalize_decl (decl);
1663 /* Switch to the appropriate section. */
1664 variable_section (decl, reloc);
1666 /* dbxout.c needs to know this. */
1667 if (in_text_section () || in_unlikely_text_section ())
1668 DECL_IN_TEXT_SECTION (decl) = 1;
1670 /* Output the alignment of this data. */
1671 if (align > BITS_PER_UNIT)
1672 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl)));
1674 /* Do any machine/system dependent processing of the object. */
1675 #ifdef ASM_DECLARE_OBJECT_NAME
1676 last_assemble_variable_decl = decl;
1677 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1678 #else
1679 /* Standard thing is just output label for the object. */
1680 ASM_OUTPUT_LABEL (asm_out_file, name);
1681 #endif /* ASM_DECLARE_OBJECT_NAME */
1683 if (!dont_output_data)
1685 if (DECL_INITIAL (decl)
1686 && DECL_INITIAL (decl) != error_mark_node
1687 && !initializer_zerop (DECL_INITIAL (decl)))
1688 /* Output the actual data. */
1689 output_constant (DECL_INITIAL (decl),
1690 tree_low_cst (DECL_SIZE_UNIT (decl), 1),
1691 align);
1692 else
1693 /* Leave space for it. */
1694 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1698 /* Return 1 if type TYPE contains any pointers. */
1700 static int
1701 contains_pointers_p (tree type)
1703 switch (TREE_CODE (type))
1705 case POINTER_TYPE:
1706 case REFERENCE_TYPE:
1707 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1708 so I'll play safe and return 1. */
1709 case OFFSET_TYPE:
1710 return 1;
1712 case RECORD_TYPE:
1713 case UNION_TYPE:
1714 case QUAL_UNION_TYPE:
1716 tree fields;
1717 /* For a type that has fields, see if the fields have pointers. */
1718 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1719 if (TREE_CODE (fields) == FIELD_DECL
1720 && contains_pointers_p (TREE_TYPE (fields)))
1721 return 1;
1722 return 0;
1725 case ARRAY_TYPE:
1726 /* An array type contains pointers if its element type does. */
1727 return contains_pointers_p (TREE_TYPE (type));
1729 default:
1730 return 0;
1734 #ifdef ASM_OUTPUT_EXTERNAL
1735 /* True if DECL is a function decl for which no out-of-line copy exists.
1736 It is assumed that DECL's assembler name has been set. */
1738 static bool
1739 incorporeal_function_p (tree decl)
1741 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl))
1743 const char *name;
1745 if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
1746 && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA)
1747 return true;
1749 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1750 if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
1751 return true;
1753 return false;
1755 #endif
1757 /* Output something to declare an external symbol to the assembler.
1758 (Most assemblers don't need this, so we normally output nothing.)
1759 Do nothing if DECL is not external. */
1761 void
1762 assemble_external (tree decl ATTRIBUTE_UNUSED)
1764 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1765 main body of this code is only rarely exercised. To provide some
1766 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1767 open. If it's not, we should not be calling this function. */
1768 if (!asm_out_file)
1769 abort ();
1771 #ifdef ASM_OUTPUT_EXTERNAL
1772 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1774 rtx rtl = DECL_RTL (decl);
1776 if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1777 && !SYMBOL_REF_USED (XEXP (rtl, 0))
1778 && !incorporeal_function_p (decl))
1780 /* Some systems do require some output. */
1781 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1782 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1785 #endif
1788 /* Similar, for calling a library function FUN. */
1790 void
1791 assemble_external_libcall (rtx fun)
1793 /* Declare library function name external when first used, if nec. */
1794 if (! SYMBOL_REF_USED (fun))
1796 SYMBOL_REF_USED (fun) = 1;
1797 targetm.asm_out.external_libcall (fun);
1801 /* Assemble a label named NAME. */
1803 void
1804 assemble_label (const char *name)
1806 ASM_OUTPUT_LABEL (asm_out_file, name);
1809 /* Set the symbol_referenced flag for ID. */
1810 void
1811 mark_referenced (tree id)
1813 TREE_SYMBOL_REFERENCED (id) = 1;
1816 /* Set the symbol_referenced flag for DECL and notify callgraph. */
1817 void
1818 mark_decl_referenced (tree decl)
1820 if (TREE_CODE (decl) == FUNCTION_DECL)
1821 cgraph_mark_needed_node (cgraph_node (decl));
1822 else if (TREE_CODE (decl) == VAR_DECL)
1823 cgraph_varpool_mark_needed_node (cgraph_varpool_node (decl));
1824 /* else do nothing - we can get various sorts of CST nodes here,
1825 which do not need to be marked. */
1828 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1829 If NAME starts with a *, the rest of NAME is output verbatim.
1830 Otherwise NAME is transformed in an implementation-defined way
1831 (usually by the addition of an underscore).
1832 Many macros in the tm file are defined to call this function. */
1834 void
1835 assemble_name (FILE *file, const char *name)
1837 const char *real_name;
1838 tree id;
1840 real_name = targetm.strip_name_encoding (name);
1842 id = maybe_get_identifier (real_name);
1843 if (id)
1844 mark_referenced (id);
1846 if (name[0] == '*')
1847 fputs (&name[1], file);
1848 else
1849 ASM_OUTPUT_LABELREF (file, name);
1852 /* Allocate SIZE bytes writable static space with a gensym name
1853 and return an RTX to refer to its address. */
1856 assemble_static_space (unsigned HOST_WIDE_INT size)
1858 char name[12];
1859 const char *namestring;
1860 rtx x;
1862 #if 0
1863 if (flag_shared_data)
1864 data_section ();
1865 #endif
1867 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1868 ++const_labelno;
1869 namestring = ggc_strdup (name);
1871 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1872 SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
1874 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1875 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1876 BIGGEST_ALIGNMENT);
1877 #else
1878 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1879 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1880 #else
1882 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1883 so that each uninitialized object starts on such a boundary. */
1884 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1885 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
1886 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1887 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1888 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1889 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1891 #endif
1892 #endif
1893 return x;
1896 /* Assemble the static constant template for function entry trampolines.
1897 This is done at most once per compilation.
1898 Returns an RTX for the address of the template. */
1900 static GTY(()) rtx initial_trampoline;
1902 #ifdef TRAMPOLINE_TEMPLATE
1904 assemble_trampoline_template (void)
1906 char label[256];
1907 const char *name;
1908 int align;
1909 rtx symbol;
1911 if (initial_trampoline)
1912 return initial_trampoline;
1914 /* By default, put trampoline templates in read-only data section. */
1916 #ifdef TRAMPOLINE_SECTION
1917 TRAMPOLINE_SECTION ();
1918 #else
1919 readonly_data_section ();
1920 #endif
1922 /* Write the assembler code to define one. */
1923 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1924 if (align > 0)
1926 ASM_OUTPUT_ALIGN (asm_out_file, align);
1929 targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
1930 TRAMPOLINE_TEMPLATE (asm_out_file);
1932 /* Record the rtl to refer to it. */
1933 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1934 name = ggc_strdup (label);
1935 symbol = gen_rtx_SYMBOL_REF (Pmode, name);
1936 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
1938 initial_trampoline = gen_rtx_MEM (BLKmode, symbol);
1939 set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
1941 return initial_trampoline;
1943 #endif
1945 /* A and B are either alignments or offsets. Return the minimum alignment
1946 that may be assumed after adding the two together. */
1948 static inline unsigned
1949 min_align (unsigned int a, unsigned int b)
1951 return (a | b) & -(a | b);
1954 /* Return the assembler directive for creating a given kind of integer
1955 object. SIZE is the number of bytes in the object and ALIGNED_P
1956 indicates whether it is known to be aligned. Return NULL if the
1957 assembly dialect has no such directive.
1959 The returned string should be printed at the start of a new line and
1960 be followed immediately by the object's initial value. */
1962 const char *
1963 integer_asm_op (int size, int aligned_p)
1965 struct asm_int_op *ops;
1967 if (aligned_p)
1968 ops = &targetm.asm_out.aligned_op;
1969 else
1970 ops = &targetm.asm_out.unaligned_op;
1972 switch (size)
1974 case 1:
1975 return targetm.asm_out.byte_op;
1976 case 2:
1977 return ops->hi;
1978 case 4:
1979 return ops->si;
1980 case 8:
1981 return ops->di;
1982 case 16:
1983 return ops->ti;
1984 default:
1985 return NULL;
1989 /* Use directive OP to assemble an integer object X. Print OP at the
1990 start of the line, followed immediately by the value of X. */
1992 void
1993 assemble_integer_with_op (const char *op, rtx x)
1995 fputs (op, asm_out_file);
1996 output_addr_const (asm_out_file, x);
1997 fputc ('\n', asm_out_file);
2000 /* The default implementation of the asm_out.integer target hook. */
2002 bool
2003 default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
2004 unsigned int size ATTRIBUTE_UNUSED,
2005 int aligned_p ATTRIBUTE_UNUSED)
2007 const char *op = integer_asm_op (size, aligned_p);
2008 return op && (assemble_integer_with_op (op, x), true);
2011 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2012 the alignment of the integer in bits. Return 1 if we were able to output
2013 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
2014 the constant. */
2016 bool
2017 assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
2019 int aligned_p;
2021 aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
2023 /* See if the target hook can handle this kind of object. */
2024 if (targetm.asm_out.integer (x, size, aligned_p))
2025 return true;
2027 /* If the object is a multi-byte one, try splitting it up. Split
2028 it into words it if is multi-word, otherwise split it into bytes. */
2029 if (size > 1)
2031 enum machine_mode omode, imode;
2032 unsigned int subalign;
2033 unsigned int subsize, i;
2035 subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
2036 subalign = MIN (align, subsize * BITS_PER_UNIT);
2037 omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0);
2038 imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
2040 for (i = 0; i < size; i += subsize)
2042 rtx partial = simplify_subreg (omode, x, imode, i);
2043 if (!partial || !assemble_integer (partial, subsize, subalign, 0))
2044 break;
2046 if (i == size)
2047 return true;
2049 /* If we've printed some of it, but not all of it, there's no going
2050 back now. */
2051 if (i > 0)
2052 abort ();
2055 if (force)
2056 abort ();
2058 return false;
2061 void
2062 assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align)
2064 long data[4];
2065 int i;
2066 int bitsize, nelts, nunits, units_per;
2068 /* This is hairy. We have a quantity of known size. real_to_target
2069 will put it into an array of *host* longs, 32 bits per element
2070 (even if long is more than 32 bits). We need to determine the
2071 number of array elements that are occupied (nelts) and the number
2072 of *target* min-addressable units that will be occupied in the
2073 object file (nunits). We cannot assume that 32 divides the
2074 mode's bitsize (size * BITS_PER_UNIT) evenly.
2076 size * BITS_PER_UNIT is used here to make sure that padding bits
2077 (which might appear at either end of the value; real_to_target
2078 will include the padding bits in its output array) are included. */
2080 nunits = GET_MODE_SIZE (mode);
2081 bitsize = nunits * BITS_PER_UNIT;
2082 nelts = CEIL (bitsize, 32);
2083 units_per = 32 / BITS_PER_UNIT;
2085 real_to_target (data, &d, mode);
2087 /* Put out the first word with the specified alignment. */
2088 assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1);
2089 nunits -= units_per;
2091 /* Subsequent words need only 32-bit alignment. */
2092 align = min_align (align, 32);
2094 for (i = 1; i < nelts; i++)
2096 assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1);
2097 nunits -= units_per;
2101 /* Given an expression EXP with a constant value,
2102 reduce it to the sum of an assembler symbol and an integer.
2103 Store them both in the structure *VALUE.
2104 Abort if EXP does not reduce. */
2106 struct addr_const GTY(())
2108 rtx base;
2109 HOST_WIDE_INT offset;
2112 static void
2113 decode_addr_const (tree exp, struct addr_const *value)
2115 tree target = TREE_OPERAND (exp, 0);
2116 int offset = 0;
2117 rtx x;
2119 while (1)
2121 if (TREE_CODE (target) == COMPONENT_REF
2122 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2125 offset += int_byte_position (TREE_OPERAND (target, 1));
2126 target = TREE_OPERAND (target, 0);
2128 else if (TREE_CODE (target) == ARRAY_REF
2129 || TREE_CODE (target) == ARRAY_RANGE_REF)
2131 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2132 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2133 target = TREE_OPERAND (target, 0);
2135 else
2136 break;
2139 switch (TREE_CODE (target))
2141 case VAR_DECL:
2142 case FUNCTION_DECL:
2143 x = DECL_RTL (target);
2144 break;
2146 case LABEL_DECL:
2147 x = gen_rtx_MEM (FUNCTION_MODE,
2148 gen_rtx_LABEL_REF (VOIDmode, force_label_rtx (target)));
2149 break;
2151 case REAL_CST:
2152 case STRING_CST:
2153 case COMPLEX_CST:
2154 case CONSTRUCTOR:
2155 case INTEGER_CST:
2156 x = output_constant_def (target, 1);
2157 break;
2159 default:
2160 abort ();
2163 if (!MEM_P (x))
2164 abort ();
2165 x = XEXP (x, 0);
2167 value->base = x;
2168 value->offset = offset;
2171 /* Uniquize all constants that appear in memory.
2172 Each constant in memory thus far output is recorded
2173 in `const_desc_table'. */
2175 struct constant_descriptor_tree GTY(())
2177 /* A MEM for the constant. */
2178 rtx rtl;
2180 /* The value of the constant. */
2181 tree value;
2184 static GTY((param_is (struct constant_descriptor_tree)))
2185 htab_t const_desc_htab;
2187 static struct constant_descriptor_tree * build_constant_desc (tree);
2188 static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
2190 /* Compute a hash code for a constant expression. */
2192 static hashval_t
2193 const_desc_hash (const void *ptr)
2195 return const_hash_1 (((struct constant_descriptor_tree *)ptr)->value);
2198 static hashval_t
2199 const_hash_1 (const tree exp)
2201 const char *p;
2202 hashval_t hi;
2203 int len, i;
2204 enum tree_code code = TREE_CODE (exp);
2206 /* Either set P and LEN to the address and len of something to hash and
2207 exit the switch or return a value. */
2209 switch (code)
2211 case INTEGER_CST:
2212 p = (char *) &TREE_INT_CST (exp);
2213 len = sizeof TREE_INT_CST (exp);
2214 break;
2216 case REAL_CST:
2217 return real_hash (TREE_REAL_CST_PTR (exp));
2219 case STRING_CST:
2220 p = TREE_STRING_POINTER (exp);
2221 len = TREE_STRING_LENGTH (exp);
2222 break;
2224 case COMPLEX_CST:
2225 return (const_hash_1 (TREE_REALPART (exp)) * 5
2226 + const_hash_1 (TREE_IMAGPART (exp)));
2228 case CONSTRUCTOR:
2229 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2231 char *tmp;
2233 len = int_size_in_bytes (TREE_TYPE (exp));
2234 tmp = alloca (len);
2235 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2236 p = tmp;
2237 break;
2239 else
2241 tree link;
2243 hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
2245 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2246 if (TREE_VALUE (link))
2247 hi = hi * 603 + const_hash_1 (TREE_VALUE (link));
2249 return hi;
2252 case ADDR_EXPR:
2253 case FDESC_EXPR:
2255 struct addr_const value;
2257 decode_addr_const (exp, &value);
2258 if (GET_CODE (value.base) == SYMBOL_REF)
2260 /* Don't hash the address of the SYMBOL_REF;
2261 only use the offset and the symbol name. */
2262 hi = value.offset;
2263 p = XSTR (value.base, 0);
2264 for (i = 0; p[i] != 0; i++)
2265 hi = ((hi * 613) + (unsigned) (p[i]));
2267 else if (GET_CODE (value.base) == LABEL_REF)
2268 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2269 else
2270 abort ();
2272 return hi;
2274 case PLUS_EXPR:
2275 case MINUS_EXPR:
2276 return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
2277 + const_hash_1 (TREE_OPERAND (exp, 1)));
2279 case NOP_EXPR:
2280 case CONVERT_EXPR:
2281 case NON_LVALUE_EXPR:
2282 return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
2284 default:
2285 /* A language specific constant. Just hash the code. */
2286 return code;
2289 /* Compute hashing function. */
2290 hi = len;
2291 for (i = 0; i < len; i++)
2292 hi = ((hi * 613) + (unsigned) (p[i]));
2294 return hi;
2297 /* Wrapper of compare_constant, for the htab interface. */
2298 static int
2299 const_desc_eq (const void *p1, const void *p2)
2301 return compare_constant (((struct constant_descriptor_tree *)p1)->value,
2302 ((struct constant_descriptor_tree *)p2)->value);
2305 /* Compare t1 and t2, and return 1 only if they are known to result in
2306 the same bit pattern on output. */
2308 static int
2309 compare_constant (const tree t1, const tree t2)
2311 enum tree_code typecode;
2313 if (t1 == NULL_TREE)
2314 return t2 == NULL_TREE;
2315 if (t2 == NULL_TREE)
2316 return 0;
2318 if (TREE_CODE (t1) != TREE_CODE (t2))
2319 return 0;
2321 switch (TREE_CODE (t1))
2323 case INTEGER_CST:
2324 /* Integer constants are the same only if the same width of type. */
2325 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2326 return 0;
2327 return tree_int_cst_equal (t1, t2);
2329 case REAL_CST:
2330 /* Real constants are the same only if the same width of type. */
2331 if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
2332 return 0;
2334 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2));
2336 case STRING_CST:
2337 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
2338 return 0;
2340 return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
2341 && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
2342 TREE_STRING_LENGTH (t1)));
2344 case COMPLEX_CST:
2345 return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
2346 && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
2348 case CONSTRUCTOR:
2349 typecode = TREE_CODE (TREE_TYPE (t1));
2350 if (typecode != TREE_CODE (TREE_TYPE (t2)))
2351 return 0;
2353 if (typecode == SET_TYPE)
2355 int len = int_size_in_bytes (TREE_TYPE (t2));
2356 unsigned char *tmp1, *tmp2;
2358 if (int_size_in_bytes (TREE_TYPE (t1)) != len)
2359 return 0;
2361 tmp1 = alloca (len);
2362 tmp2 = alloca (len);
2364 if (get_set_constructor_bytes (t1, tmp1, len) != NULL_TREE)
2365 return 0;
2366 if (get_set_constructor_bytes (t2, tmp2, len) != NULL_TREE)
2367 return 0;
2369 return memcmp (tmp1, tmp2, len) == 0;
2371 else
2373 tree l1, l2;
2375 if (typecode == ARRAY_TYPE)
2377 HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
2378 /* For arrays, check that the sizes all match. */
2379 if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
2380 || size_1 == -1
2381 || size_1 != int_size_in_bytes (TREE_TYPE (t2)))
2382 return 0;
2384 else
2386 /* For record and union constructors, require exact type
2387 equality. */
2388 if (TREE_TYPE (t1) != TREE_TYPE (t2))
2389 return 0;
2392 for (l1 = CONSTRUCTOR_ELTS (t1), l2 = CONSTRUCTOR_ELTS (t2);
2393 l1 && l2;
2394 l1 = TREE_CHAIN (l1), l2 = TREE_CHAIN (l2))
2396 /* Check that each value is the same... */
2397 if (! compare_constant (TREE_VALUE (l1), TREE_VALUE (l2)))
2398 return 0;
2399 /* ... and that they apply to the same fields! */
2400 if (typecode == ARRAY_TYPE)
2402 if (! compare_constant (TREE_PURPOSE (l1),
2403 TREE_PURPOSE (l2)))
2404 return 0;
2406 else
2408 if (TREE_PURPOSE (l1) != TREE_PURPOSE (l2))
2409 return 0;
2413 return l1 == NULL_TREE && l2 == NULL_TREE;
2416 case ADDR_EXPR:
2417 case FDESC_EXPR:
2419 struct addr_const value1, value2;
2421 decode_addr_const (t1, &value1);
2422 decode_addr_const (t2, &value2);
2423 return (value1.offset == value2.offset
2424 && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
2427 case PLUS_EXPR:
2428 case MINUS_EXPR:
2429 case RANGE_EXPR:
2430 return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
2431 && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
2433 case NOP_EXPR:
2434 case CONVERT_EXPR:
2435 case NON_LVALUE_EXPR:
2436 case VIEW_CONVERT_EXPR:
2437 return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
2439 default:
2441 tree nt1, nt2;
2442 nt1 = lang_hooks.expand_constant (t1);
2443 nt2 = lang_hooks.expand_constant (t2);
2444 if (nt1 != t1 || nt2 != t2)
2445 return compare_constant (nt1, nt2);
2446 else
2447 return 0;
2451 /* Should not get here. */
2452 abort ();
2455 /* Make a copy of the whole tree structure for a constant. This
2456 handles the same types of nodes that compare_constant handles. */
2458 static tree
2459 copy_constant (tree exp)
2461 switch (TREE_CODE (exp))
2463 case ADDR_EXPR:
2464 /* For ADDR_EXPR, we do not want to copy the decl whose address
2465 is requested. We do want to copy constants though. */
2466 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2467 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2468 copy_constant (TREE_OPERAND (exp, 0)));
2469 else
2470 return copy_node (exp);
2472 case INTEGER_CST:
2473 case REAL_CST:
2474 case STRING_CST:
2475 return copy_node (exp);
2477 case COMPLEX_CST:
2478 return build_complex (TREE_TYPE (exp),
2479 copy_constant (TREE_REALPART (exp)),
2480 copy_constant (TREE_IMAGPART (exp)));
2482 case PLUS_EXPR:
2483 case MINUS_EXPR:
2484 return build2 (TREE_CODE (exp), TREE_TYPE (exp),
2485 copy_constant (TREE_OPERAND (exp, 0)),
2486 copy_constant (TREE_OPERAND (exp, 1)));
2488 case NOP_EXPR:
2489 case CONVERT_EXPR:
2490 case NON_LVALUE_EXPR:
2491 case VIEW_CONVERT_EXPR:
2492 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2493 copy_constant (TREE_OPERAND (exp, 0)));
2495 case CONSTRUCTOR:
2497 tree copy = copy_node (exp);
2498 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2499 tree tail;
2501 CONSTRUCTOR_ELTS (copy) = list;
2502 for (tail = list; tail; tail = TREE_CHAIN (tail))
2503 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2504 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2505 for (tail = list; tail; tail = TREE_CHAIN (tail))
2506 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2508 return copy;
2511 default:
2513 tree t;
2514 t = lang_hooks.expand_constant (exp);
2515 if (t != exp)
2516 return copy_constant (t);
2517 else
2518 abort ();
2523 /* Subroutine of output_constant_def:
2524 No constant equal to EXP is known to have been output.
2525 Make a constant descriptor to enter EXP in the hash table.
2526 Assign the label number and construct RTL to refer to the
2527 constant's location in memory.
2528 Caller is responsible for updating the hash table. */
2530 static struct constant_descriptor_tree *
2531 build_constant_desc (tree exp)
2533 rtx symbol;
2534 rtx rtl;
2535 char label[256];
2536 int labelno;
2537 struct constant_descriptor_tree *desc;
2539 desc = ggc_alloc (sizeof (*desc));
2540 desc->value = copy_constant (exp);
2542 /* Propagate marked-ness to copied constant. */
2543 if (flag_mudflap && mf_marked_p (exp))
2544 mf_mark (desc->value);
2546 /* Create a string containing the label name, in LABEL. */
2547 labelno = const_labelno++;
2548 ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
2550 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2551 symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2552 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2553 SYMBOL_REF_DECL (symbol) = desc->value;
2554 TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2556 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
2557 set_mem_attributes (rtl, exp, 1);
2558 set_mem_alias_set (rtl, 0);
2559 set_mem_alias_set (rtl, const_alias_set);
2561 /* Set flags or add text to the name to record information, such as
2562 that it is a local symbol. If the name is changed, the macro
2563 ASM_OUTPUT_LABELREF will have to know how to strip this
2564 information. This call might invalidate our local variable
2565 SYMBOL; we can't use it afterward. */
2567 targetm.encode_section_info (exp, rtl, true);
2569 desc->rtl = rtl;
2571 return desc;
2574 /* Return an rtx representing a reference to constant data in memory
2575 for the constant expression EXP.
2577 If assembler code for such a constant has already been output,
2578 return an rtx to refer to it.
2579 Otherwise, output such a constant in memory
2580 and generate an rtx for it.
2582 If DEFER is nonzero, this constant can be deferred and output only
2583 if referenced in the function after all optimizations.
2585 `const_desc_table' records which constants already have label strings. */
2588 output_constant_def (tree exp, int defer)
2590 struct constant_descriptor_tree *desc;
2591 struct constant_descriptor_tree key;
2592 void **loc;
2594 /* Look up EXP in the table of constant descriptors. If we didn't find
2595 it, create a new one. */
2596 key.value = exp;
2597 loc = htab_find_slot (const_desc_htab, &key, INSERT);
2599 desc = *loc;
2600 if (desc == 0)
2602 desc = build_constant_desc (exp);
2603 *loc = desc;
2606 maybe_output_constant_def_contents (desc, defer);
2607 return desc->rtl;
2610 /* Subroutine of output_constant_def: Decide whether or not we need to
2611 output the constant DESC now, and if so, do it. */
2612 static void
2613 maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
2614 int defer)
2616 rtx symbol = XEXP (desc->rtl, 0);
2617 tree exp = desc->value;
2619 if (flag_syntax_only)
2620 return;
2622 if (TREE_ASM_WRITTEN (exp))
2623 /* Already output; don't do it again. */
2624 return;
2626 /* We can always defer constants as long as the context allows
2627 doing so. */
2628 if (defer)
2630 /* Increment n_deferred_constants if it exists. It needs to be at
2631 least as large as the number of constants actually referred to
2632 by the function. If it's too small we'll stop looking too early
2633 and fail to emit constants; if it's too large we'll only look
2634 through the entire function when we could have stopped earlier. */
2635 if (cfun)
2636 n_deferred_constants++;
2637 return;
2640 output_constant_def_contents (symbol);
2643 /* We must output the constant data referred to by SYMBOL; do so. */
2645 static void
2646 output_constant_def_contents (rtx symbol)
2648 tree exp = SYMBOL_REF_DECL (symbol);
2649 const char *label = XSTR (symbol, 0);
2650 HOST_WIDE_INT size;
2652 /* Make sure any other constants whose addresses appear in EXP
2653 are assigned label numbers. */
2654 int reloc = compute_reloc_for_constant (exp);
2656 /* Align the location counter as required by EXP's data type. */
2657 unsigned int align = TYPE_ALIGN (TREE_TYPE (exp));
2658 #ifdef CONSTANT_ALIGNMENT
2659 align = CONSTANT_ALIGNMENT (exp, align);
2660 #endif
2662 output_addressed_constants (exp);
2664 /* We are no longer deferring this constant. */
2665 TREE_ASM_WRITTEN (exp) = 1;
2667 if (IN_NAMED_SECTION (exp))
2668 named_section (exp, NULL, reloc);
2669 else
2670 targetm.asm_out.select_section (exp, reloc, align);
2672 if (align > BITS_PER_UNIT)
2674 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2677 size = int_size_in_bytes (TREE_TYPE (exp));
2678 if (TREE_CODE (exp) == STRING_CST)
2679 size = MAX (TREE_STRING_LENGTH (exp), size);
2681 /* Do any machine/system dependent processing of the constant. */
2682 #ifdef ASM_DECLARE_CONSTANT_NAME
2683 ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size);
2684 #else
2685 /* Standard thing is just output label for the constant. */
2686 ASM_OUTPUT_LABEL (asm_out_file, label);
2687 #endif /* ASM_DECLARE_CONSTANT_NAME */
2689 /* Output the value of EXP. */
2690 output_constant (exp, size, align);
2691 if (flag_mudflap)
2692 mudflap_enqueue_constant (exp);
2695 /* Look up EXP in the table of constant descriptors. Return the rtl
2696 if it has been emitted, else null. */
2699 lookup_constant_def (tree exp)
2701 struct constant_descriptor_tree *desc;
2702 struct constant_descriptor_tree key;
2704 key.value = exp;
2705 desc = htab_find (const_desc_htab, &key);
2707 return (desc ? desc->rtl : NULL_RTX);
2710 /* Used in the hash tables to avoid outputting the same constant
2711 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2712 are output once per function, not once per file. */
2713 /* ??? Only a few targets need per-function constant pools. Most
2714 can use one per-file pool. Should add a targetm bit to tell the
2715 difference. */
2717 struct rtx_constant_pool GTY(())
2719 /* Pointers to first and last constant in pool, as ordered by offset. */
2720 struct constant_descriptor_rtx *first;
2721 struct constant_descriptor_rtx *last;
2723 /* Hash facility for making memory-constants from constant rtl-expressions.
2724 It is used on RISC machines where immediate integer arguments and
2725 constant addresses are restricted so that such constants must be stored
2726 in memory. */
2727 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab;
2728 htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_sym_htab;
2730 /* Current offset in constant pool (does not include any
2731 machine-specific header). */
2732 HOST_WIDE_INT offset;
2735 struct constant_descriptor_rtx GTY((chain_next ("%h.next")))
2737 struct constant_descriptor_rtx *next;
2738 rtx mem;
2739 rtx sym;
2740 rtx constant;
2741 HOST_WIDE_INT offset;
2742 hashval_t hash;
2743 enum machine_mode mode;
2744 unsigned int align;
2745 int labelno;
2746 int mark;
2749 /* Hash and compare functions for const_rtx_htab. */
2751 static hashval_t
2752 const_desc_rtx_hash (const void *ptr)
2754 const struct constant_descriptor_rtx *desc = ptr;
2755 return desc->hash;
2758 static int
2759 const_desc_rtx_eq (const void *a, const void *b)
2761 const struct constant_descriptor_rtx *x = a;
2762 const struct constant_descriptor_rtx *y = b;
2764 if (x->mode != y->mode)
2765 return 0;
2766 return rtx_equal_p (x->constant, y->constant);
2769 /* Hash and compare functions for const_rtx_sym_htab. */
2771 static hashval_t
2772 const_desc_rtx_sym_hash (const void *ptr)
2774 const struct constant_descriptor_rtx *desc = ptr;
2775 return htab_hash_string (XSTR (desc->sym, 0));
2778 static int
2779 const_desc_rtx_sym_eq (const void *a, const void *b)
2781 const struct constant_descriptor_rtx *x = a;
2782 const struct constant_descriptor_rtx *y = b;
2783 return XSTR (x->sym, 0) == XSTR (y->sym, 0);
2786 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
2788 static int
2789 const_rtx_hash_1 (rtx *xp, void *data)
2791 unsigned HOST_WIDE_INT hwi;
2792 enum machine_mode mode;
2793 enum rtx_code code;
2794 hashval_t h, *hp;
2795 rtx x;
2797 x = *xp;
2798 code = GET_CODE (x);
2799 mode = GET_MODE (x);
2800 h = (hashval_t) code * 1048573 + mode;
2802 switch (code)
2804 case CONST_INT:
2805 hwi = INTVAL (x);
2806 fold_hwi:
2808 const int shift = sizeof (hashval_t) * CHAR_BIT;
2809 const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
2810 int i;
2812 h ^= (hashval_t) hwi;
2813 for (i = 1; i < n; ++i)
2815 hwi >>= shift;
2816 h ^= (hashval_t) hwi;
2819 break;
2821 case CONST_DOUBLE:
2822 if (mode == VOIDmode)
2824 hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
2825 goto fold_hwi;
2827 else
2828 h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
2829 break;
2831 case SYMBOL_REF:
2832 h ^= htab_hash_string (XSTR (x, 0));
2833 break;
2835 case LABEL_REF:
2836 h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0));
2837 break;
2839 case UNSPEC:
2840 case UNSPEC_VOLATILE:
2841 h = h * 251 + XINT (x, 1);
2842 break;
2844 default:
2845 break;
2848 hp = data;
2849 *hp = *hp * 509 + h;
2850 return 0;
2853 /* Compute a hash value for X, which should be a constant. */
2855 static hashval_t
2856 const_rtx_hash (rtx x)
2858 hashval_t h = 0;
2859 for_each_rtx (&x, const_rtx_hash_1, &h);
2860 return h;
2864 /* Initialize constant pool hashing for a new function. */
2866 void
2867 init_varasm_status (struct function *f)
2869 struct varasm_status *p;
2870 struct rtx_constant_pool *pool;
2872 p = ggc_alloc (sizeof (struct varasm_status));
2873 f->varasm = p;
2875 pool = ggc_alloc (sizeof (struct rtx_constant_pool));
2876 p->pool = pool;
2877 p->deferred_constants = 0;
2879 pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash,
2880 const_desc_rtx_eq, NULL);
2881 pool->const_rtx_sym_htab = htab_create_ggc (31, const_desc_rtx_sym_hash,
2882 const_desc_rtx_sym_eq, NULL);
2883 pool->first = pool->last = NULL;
2884 pool->offset = 0;
2887 /* Given a MINUS expression, simplify it if both sides
2888 include the same symbol. */
2891 simplify_subtraction (rtx x)
2893 rtx r = simplify_rtx (x);
2894 return r ? r : x;
2897 /* Given a constant rtx X, make (or find) a memory constant for its value
2898 and return a MEM rtx to refer to it in memory. */
2901 force_const_mem (enum machine_mode mode, rtx x)
2903 struct constant_descriptor_rtx *desc, tmp;
2904 struct rtx_constant_pool *pool = cfun->varasm->pool;
2905 char label[256];
2906 rtx def, symbol;
2907 hashval_t hash;
2908 unsigned int align;
2909 void **slot;
2911 /* If we're not allowed to drop X into the constant pool, don't. */
2912 if (targetm.cannot_force_const_mem (x))
2913 return NULL_RTX;
2915 /* Lookup the value in the hashtable. */
2916 tmp.constant = x;
2917 tmp.mode = mode;
2918 hash = const_rtx_hash (x);
2919 slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT);
2920 desc = *slot;
2922 /* If the constant was already present, return its memory. */
2923 if (desc)
2924 return copy_rtx (desc->mem);
2926 /* Otherwise, create a new descriptor. */
2927 desc = ggc_alloc (sizeof (*desc));
2928 *slot = desc;
2930 /* Align the location counter as required by EXP's data type. */
2931 align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode);
2932 #ifdef CONSTANT_ALIGNMENT
2934 tree type = lang_hooks.types.type_for_mode (mode, 0);
2935 if (type != NULL_TREE)
2936 align = CONSTANT_ALIGNMENT (make_tree (type, x), align);
2938 #endif
2940 pool->offset += (align / BITS_PER_UNIT) - 1;
2941 pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
2943 desc->next = NULL;
2944 desc->constant = tmp.constant;
2945 desc->offset = pool->offset;
2946 desc->hash = hash;
2947 desc->mode = mode;
2948 desc->align = align;
2949 desc->labelno = const_labelno;
2950 desc->mark = 0;
2952 pool->offset += GET_MODE_SIZE (mode);
2953 if (pool->last)
2954 pool->last->next = desc;
2955 else
2956 pool->first = pool->last = desc;
2957 pool->last = desc;
2959 /* Create a string containing the label name, in LABEL. */
2960 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2961 ++const_labelno;
2963 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
2964 the constants pool. */
2965 desc->sym = symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
2966 SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
2967 CONSTANT_POOL_ADDRESS_P (symbol) = 1;
2968 current_function_uses_const_pool = 1;
2970 /* Insert the descriptor into the symbol cross-reference table too. */
2971 slot = htab_find_slot (pool->const_rtx_sym_htab, desc, INSERT);
2972 if (*slot)
2973 abort ();
2974 *slot = desc;
2976 /* Construct the MEM. */
2977 desc->mem = def = gen_const_mem (mode, symbol);
2978 set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1);
2980 /* If we're dropping a label to the constant pool, make sure we
2981 don't delete it. */
2982 if (GET_CODE (x) == LABEL_REF)
2983 LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
2985 return copy_rtx (def);
2988 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2989 the corresponding constant_descriptor_rtx structure. */
2991 static struct constant_descriptor_rtx *
2992 find_pool_constant (struct rtx_constant_pool *pool, rtx sym)
2994 struct constant_descriptor_rtx tmp;
2995 tmp.sym = sym;
2996 return htab_find (pool->const_rtx_sym_htab, &tmp);
2999 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3002 get_pool_constant (rtx addr)
3004 return find_pool_constant (cfun->varasm->pool, addr)->constant;
3007 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3008 and whether it has been output or not. */
3011 get_pool_constant_mark (rtx addr, bool *pmarked)
3013 struct constant_descriptor_rtx *desc;
3015 desc = find_pool_constant (cfun->varasm->pool, addr);
3016 *pmarked = (desc->mark != 0);
3017 return desc->constant;
3020 /* Likewise, but for the constant pool of a specific function. */
3023 get_pool_constant_for_function (struct function *f, rtx addr)
3025 return find_pool_constant (f->varasm->pool, addr)->constant;
3028 /* Similar, return the mode. */
3030 enum machine_mode
3031 get_pool_mode (rtx addr)
3033 return find_pool_constant (cfun->varasm->pool, addr)->mode;
3036 enum machine_mode
3037 get_pool_mode_for_function (struct function *f, rtx addr)
3039 return find_pool_constant (f->varasm->pool, addr)->mode;
3042 /* Similar, return the offset in the constant pool. */
3045 get_pool_offset (rtx addr)
3047 return find_pool_constant (cfun->varasm->pool, addr)->offset;
3050 /* Return the size of the constant pool. */
3053 get_pool_size (void)
3055 return cfun->varasm->pool->offset;
3058 /* Worker function for output_constant_pool_1. Emit assembly for X
3059 in MODE with known alignment ALIGN. */
3061 static void
3062 output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align)
3064 switch (GET_MODE_CLASS (mode))
3066 case MODE_FLOAT:
3067 if (GET_CODE (x) != CONST_DOUBLE)
3068 abort ();
3069 else
3071 REAL_VALUE_TYPE r;
3072 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
3073 assemble_real (r, mode, align);
3075 break;
3077 case MODE_INT:
3078 case MODE_PARTIAL_INT:
3079 assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
3080 break;
3082 case MODE_VECTOR_FLOAT:
3083 case MODE_VECTOR_INT:
3085 int i, units;
3086 enum machine_mode submode = GET_MODE_INNER (mode);
3087 unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
3089 if (GET_CODE (x) != CONST_VECTOR)
3090 abort ();
3091 units = CONST_VECTOR_NUNITS (x);
3093 for (i = 0; i < units; i++)
3095 rtx elt = CONST_VECTOR_ELT (x, i);
3096 output_constant_pool_2 (submode, elt, i ? subalign : align);
3099 break;
3101 default:
3102 abort ();
3106 /* Worker function for output_constant_pool. Emit POOL. */
3108 static void
3109 output_constant_pool_1 (struct constant_descriptor_rtx *desc)
3111 rtx x, tmp;
3113 if (!desc->mark)
3114 return;
3115 x = desc->constant;
3117 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3118 whose CODE_LABEL has been deleted. This can occur if a jump table
3119 is eliminated by optimization. If so, write a constant of zero
3120 instead. Note that this can also happen by turning the
3121 CODE_LABEL into a NOTE. */
3122 /* ??? This seems completely and utterly wrong. Certainly it's
3123 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3124 functioning even with INSN_DELETED_P and friends. */
3126 tmp = x;
3127 switch (GET_CODE (x))
3129 case CONST:
3130 if (GET_CODE (XEXP (x, 0)) != PLUS
3131 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3132 break;
3133 tmp = XEXP (XEXP (x, 0), 0);
3134 /* FALLTHRU */
3136 case LABEL_REF:
3137 tmp = XEXP (x, 0);
3138 if (INSN_DELETED_P (tmp)
3139 || (NOTE_P (tmp)
3140 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3142 abort ();
3143 x = const0_rtx;
3145 break;
3147 default:
3148 break;
3151 /* First switch to correct section. */
3152 targetm.asm_out.select_rtx_section (desc->mode, x, desc->align);
3154 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3155 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
3156 desc->align, desc->labelno, done);
3157 #endif
3159 assemble_align (desc->align);
3161 /* Output the label. */
3162 targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
3164 /* Output the data. */
3165 output_constant_pool_2 (desc->mode, x, desc->align);
3167 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3168 sections have proper size. */
3169 if (desc->align > GET_MODE_BITSIZE (desc->mode)
3170 && in_section == in_named
3171 && get_named_section_flags (in_named_name) & SECTION_MERGE)
3172 assemble_align (desc->align);
3174 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3175 done:
3176 #endif
3177 return;
3180 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3181 to as used. Emit referenced deferred strings. This function can
3182 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3184 static int
3185 mark_constant (rtx *current_rtx, void *data)
3187 struct rtx_constant_pool *pool = data;
3188 rtx x = *current_rtx;
3190 if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF)
3191 return 0;
3193 if (CONSTANT_POOL_ADDRESS_P (x))
3195 struct constant_descriptor_rtx *desc = find_pool_constant (pool, x);
3196 if (desc->mark == 0)
3198 desc->mark = 1;
3199 for_each_rtx (&desc->constant, mark_constant, pool);
3202 else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
3204 tree exp = SYMBOL_REF_DECL (x);
3205 if (!TREE_ASM_WRITTEN (exp))
3207 n_deferred_constants--;
3208 output_constant_def_contents (x);
3212 return -1;
3215 /* Look through appropriate parts of INSN, marking all entries in the
3216 constant pool which are actually being used. Entries that are only
3217 referenced by other constants are also marked as used. Emit
3218 deferred strings that are used. */
3220 static void
3221 mark_constants (struct rtx_constant_pool *pool, rtx insn)
3223 if (!INSN_P (insn))
3224 return;
3226 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3227 insns, not any notes that may be attached. We don't want to mark
3228 a constant just because it happens to appear in a REG_EQUIV note. */
3229 if (GET_CODE (PATTERN (insn)) == SEQUENCE)
3231 rtx seq = PATTERN (insn);
3232 int i, n = XVECLEN (seq, 0);
3233 for (i = 0; i < n; ++i)
3235 rtx subinsn = XVECEXP (seq, 0, i);
3236 if (INSN_P (subinsn))
3237 for_each_rtx (&PATTERN (subinsn), mark_constant, pool);
3240 else
3241 for_each_rtx (&PATTERN (insn), mark_constant, pool);
3244 /* Look through the instructions for this function, and mark all the
3245 entries in POOL which are actually being used. Emit deferred constants
3246 which have indeed been used. */
3248 static void
3249 mark_constant_pool (struct rtx_constant_pool *pool)
3251 rtx insn, link;
3253 if (pool->first == 0 && n_deferred_constants == 0)
3254 return;
3256 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3257 mark_constants (pool, insn);
3259 for (link = current_function_epilogue_delay_list;
3260 link;
3261 link = XEXP (link, 1))
3262 mark_constants (pool, XEXP (link, 0));
3265 /* Write all the constants in the constant pool. */
3267 void
3268 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
3269 tree fndecl ATTRIBUTE_UNUSED)
3271 struct rtx_constant_pool *pool = cfun->varasm->pool;
3272 struct constant_descriptor_rtx *desc;
3274 /* It is possible for gcc to call force_const_mem and then to later
3275 discard the instructions which refer to the constant. In such a
3276 case we do not need to output the constant. */
3277 mark_constant_pool (pool);
3279 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3280 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
3281 #endif
3283 for (desc = pool->first; desc ; desc = desc->next)
3284 output_constant_pool_1 (desc);
3286 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3287 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
3288 #endif
3291 /* Determine what kind of relocations EXP may need. */
3294 compute_reloc_for_constant (tree exp)
3296 int reloc = 0, reloc2;
3297 tree tem;
3299 /* Give the front-end a chance to convert VALUE to something that
3300 looks more like a constant to the back-end. */
3301 exp = lang_hooks.expand_constant (exp);
3303 switch (TREE_CODE (exp))
3305 case ADDR_EXPR:
3306 case FDESC_EXPR:
3307 /* Go inside any operations that get_inner_reference can handle and see
3308 if what's inside is a constant: no need to do anything here for
3309 addresses of variables or functions. */
3310 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3311 tem = TREE_OPERAND (tem, 0))
3314 if (TREE_PUBLIC (tem))
3315 reloc |= 2;
3316 else
3317 reloc |= 1;
3318 break;
3320 case PLUS_EXPR:
3321 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3322 reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3323 break;
3325 case MINUS_EXPR:
3326 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3327 reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
3328 /* The difference of two local labels is computable at link time. */
3329 if (reloc == 1 && reloc2 == 1)
3330 reloc = 0;
3331 else
3332 reloc |= reloc2;
3333 break;
3335 case NOP_EXPR:
3336 case CONVERT_EXPR:
3337 case NON_LVALUE_EXPR:
3338 reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
3339 break;
3341 case CONSTRUCTOR:
3342 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3343 if (TREE_VALUE (tem) != 0)
3344 reloc |= compute_reloc_for_constant (TREE_VALUE (tem));
3346 break;
3348 default:
3349 break;
3351 return reloc;
3354 /* Find all the constants whose addresses are referenced inside of EXP,
3355 and make sure assembler code with a label has been output for each one.
3356 Indicate whether an ADDR_EXPR has been encountered. */
3358 static void
3359 output_addressed_constants (tree exp)
3361 tree tem;
3363 /* Give the front-end a chance to convert VALUE to something that
3364 looks more like a constant to the back-end. */
3365 exp = lang_hooks.expand_constant (exp);
3367 switch (TREE_CODE (exp))
3369 case ADDR_EXPR:
3370 case FDESC_EXPR:
3371 /* Go inside any operations that get_inner_reference can handle and see
3372 if what's inside is a constant: no need to do anything here for
3373 addresses of variables or functions. */
3374 for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
3375 tem = TREE_OPERAND (tem, 0))
3378 if (TREE_CODE_CLASS (TREE_CODE (tem)) == 'c'
3379 || TREE_CODE (tem) == CONSTRUCTOR)
3380 output_constant_def (tem, 0);
3381 break;
3383 case PLUS_EXPR:
3384 case MINUS_EXPR:
3385 output_addressed_constants (TREE_OPERAND (exp, 1));
3386 /* Fall through. */
3388 case NOP_EXPR:
3389 case CONVERT_EXPR:
3390 case NON_LVALUE_EXPR:
3391 output_addressed_constants (TREE_OPERAND (exp, 0));
3392 break;
3394 case CONSTRUCTOR:
3395 for (tem = CONSTRUCTOR_ELTS (exp); tem; tem = TREE_CHAIN (tem))
3396 if (TREE_VALUE (tem) != 0)
3397 output_addressed_constants (TREE_VALUE (tem));
3399 break;
3401 default:
3402 break;
3406 /* Return nonzero if VALUE is a valid constant-valued expression
3407 for use in initializing a static variable; one that can be an
3408 element of a "constant" initializer.
3410 Return null_pointer_node if the value is absolute;
3411 if it is relocatable, return the variable that determines the relocation.
3412 We assume that VALUE has been folded as much as possible;
3413 therefore, we do not need to check for such things as
3414 arithmetic-combinations of integers. */
3416 tree
3417 initializer_constant_valid_p (tree value, tree endtype)
3419 /* Give the front-end a chance to convert VALUE to something that
3420 looks more like a constant to the back-end. */
3421 value = lang_hooks.expand_constant (value);
3423 switch (TREE_CODE (value))
3425 case CONSTRUCTOR:
3426 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
3427 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
3428 && TREE_CONSTANT (value)
3429 && CONSTRUCTOR_ELTS (value))
3431 tree elt;
3432 bool absolute = true;
3434 for (elt = CONSTRUCTOR_ELTS (value); elt; elt = TREE_CHAIN (elt))
3436 tree reloc;
3437 value = TREE_VALUE (elt);
3438 reloc = initializer_constant_valid_p (value, TREE_TYPE (value));
3439 if (!reloc)
3440 return NULL_TREE;
3441 if (reloc != null_pointer_node)
3442 absolute = false;
3444 /* For a non-absolute relocation, there is no single
3445 variable that can be "the variable that determines the
3446 relocation." */
3447 return absolute ? null_pointer_node : error_mark_node;
3450 return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
3452 case INTEGER_CST:
3453 case VECTOR_CST:
3454 case REAL_CST:
3455 case STRING_CST:
3456 case COMPLEX_CST:
3457 return null_pointer_node;
3459 case ADDR_EXPR:
3460 case FDESC_EXPR:
3461 value = staticp (TREE_OPERAND (value, 0));
3462 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to
3463 be a constant, this is old-skool offsetof-like nonsense. */
3464 if (value
3465 && TREE_CODE (value) == INDIRECT_REF
3466 && TREE_CONSTANT (TREE_OPERAND (value, 0)))
3467 return null_pointer_node;
3468 return value;
3470 case VIEW_CONVERT_EXPR:
3471 case NON_LVALUE_EXPR:
3472 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3474 case CONVERT_EXPR:
3475 case NOP_EXPR:
3476 /* Allow conversions between pointer types. */
3477 if (POINTER_TYPE_P (TREE_TYPE (value))
3478 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3479 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3481 /* Allow conversions between real types. */
3482 if (FLOAT_TYPE_P (TREE_TYPE (value))
3483 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3484 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3486 /* Allow length-preserving conversions between integer types. */
3487 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3488 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3489 && (TYPE_PRECISION (TREE_TYPE (value))
3490 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3491 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
3493 /* Allow conversions between other integer types only if
3494 explicit value. */
3495 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3496 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3498 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3499 endtype);
3500 if (inner == null_pointer_node)
3501 return null_pointer_node;
3502 break;
3505 /* Allow (int) &foo provided int is as wide as a pointer. */
3506 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
3507 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
3508 && (TYPE_PRECISION (TREE_TYPE (value))
3509 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
3510 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3511 endtype);
3513 /* Likewise conversions from int to pointers, but also allow
3514 conversions from 0. */
3515 if ((POINTER_TYPE_P (TREE_TYPE (value))
3516 || TREE_CODE (TREE_TYPE (value)) == OFFSET_TYPE)
3517 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
3519 if (integer_zerop (TREE_OPERAND (value, 0)))
3520 return null_pointer_node;
3521 else if (TYPE_PRECISION (TREE_TYPE (value))
3522 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
3523 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3524 endtype);
3527 /* Allow conversions to struct or union types if the value
3528 inside is okay. */
3529 if (TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE
3530 || TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
3531 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
3532 endtype);
3533 break;
3535 case PLUS_EXPR:
3536 if (! INTEGRAL_TYPE_P (endtype)
3537 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3539 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3540 endtype);
3541 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3542 endtype);
3543 /* If either term is absolute, use the other terms relocation. */
3544 if (valid0 == null_pointer_node)
3545 return valid1;
3546 if (valid1 == null_pointer_node)
3547 return valid0;
3549 break;
3551 case MINUS_EXPR:
3552 if (! INTEGRAL_TYPE_P (endtype)
3553 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
3555 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
3556 endtype);
3557 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
3558 endtype);
3559 /* Win if second argument is absolute. */
3560 if (valid1 == null_pointer_node)
3561 return valid0;
3562 /* Win if both arguments have the same relocation.
3563 Then the value is absolute. */
3564 if (valid0 == valid1 && valid0 != 0)
3565 return null_pointer_node;
3567 /* Since GCC guarantees that string constants are unique in the
3568 generated code, a subtraction between two copies of the same
3569 constant string is absolute. */
3570 if (valid0 && TREE_CODE (valid0) == STRING_CST
3571 && valid1 && TREE_CODE (valid1) == STRING_CST
3572 && operand_equal_p (valid0, valid1, 1))
3573 return null_pointer_node;
3576 /* Support narrowing differences. */
3577 if (INTEGRAL_TYPE_P (endtype))
3579 tree op0, op1;
3581 op0 = TREE_OPERAND (value, 0);
3582 op1 = TREE_OPERAND (value, 1);
3584 /* Like STRIP_NOPS except allow the operand mode to widen.
3585 This works around a feature of fold that simplifies
3586 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3587 that the narrower operation is cheaper. */
3589 while (TREE_CODE (op0) == NOP_EXPR
3590 || TREE_CODE (op0) == CONVERT_EXPR
3591 || TREE_CODE (op0) == NON_LVALUE_EXPR)
3593 tree inner = TREE_OPERAND (op0, 0);
3594 if (inner == error_mark_node
3595 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3596 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))
3597 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3598 break;
3599 op0 = inner;
3602 while (TREE_CODE (op1) == NOP_EXPR
3603 || TREE_CODE (op1) == CONVERT_EXPR
3604 || TREE_CODE (op1) == NON_LVALUE_EXPR)
3606 tree inner = TREE_OPERAND (op1, 0);
3607 if (inner == error_mark_node
3608 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
3609 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1)))
3610 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner)))))
3611 break;
3612 op1 = inner;
3615 op0 = initializer_constant_valid_p (op0, endtype);
3616 op1 = initializer_constant_valid_p (op1, endtype);
3618 /* Both initializers must be known. */
3619 if (op0 && op1)
3621 if (op0 == op1)
3622 return null_pointer_node;
3624 /* Support differences between labels. */
3625 if (TREE_CODE (op0) == LABEL_DECL
3626 && TREE_CODE (op1) == LABEL_DECL)
3627 return null_pointer_node;
3629 if (TREE_CODE (op0) == STRING_CST
3630 && TREE_CODE (op1) == STRING_CST
3631 && operand_equal_p (op0, op1, 1))
3632 return null_pointer_node;
3635 break;
3637 default:
3638 break;
3641 return 0;
3644 /* Output assembler code for constant EXP to FILE, with no label.
3645 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3646 Assumes output_addressed_constants has been done on EXP already.
3648 Generate exactly SIZE bytes of assembler data, padding at the end
3649 with zeros if necessary. SIZE must always be specified.
3651 SIZE is important for structure constructors,
3652 since trailing members may have been omitted from the constructor.
3653 It is also important for initialization of arrays from string constants
3654 since the full length of the string constant might not be wanted.
3655 It is also needed for initialization of unions, where the initializer's
3656 type is just one member, and that may not be as long as the union.
3658 There a case in which we would fail to output exactly SIZE bytes:
3659 for a structure constructor that wants to produce more than SIZE bytes.
3660 But such constructors will never be generated for any possible input.
3662 ALIGN is the alignment of the data in bits. */
3664 void
3665 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
3667 enum tree_code code;
3668 unsigned HOST_WIDE_INT thissize;
3670 /* Some front-ends use constants other than the standard language-independent
3671 varieties, but which may still be output directly. Give the front-end a
3672 chance to convert EXP to a language-independent representation. */
3673 exp = lang_hooks.expand_constant (exp);
3675 if (size == 0 || flag_syntax_only)
3676 return;
3678 /* Eliminate any conversions since we'll be outputting the underlying
3679 constant. */
3680 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3681 || TREE_CODE (exp) == NON_LVALUE_EXPR
3682 || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
3683 exp = TREE_OPERAND (exp, 0);
3685 code = TREE_CODE (TREE_TYPE (exp));
3686 thissize = int_size_in_bytes (TREE_TYPE (exp));
3688 /* Allow a constructor with no elements for any data type.
3689 This means to fill the space with zeros. */
3690 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3692 assemble_zeros (size);
3693 return;
3696 if (TREE_CODE (exp) == FDESC_EXPR)
3698 #ifdef ASM_OUTPUT_FDESC
3699 HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0);
3700 tree decl = TREE_OPERAND (exp, 0);
3701 ASM_OUTPUT_FDESC (asm_out_file, decl, part);
3702 #else
3703 abort ();
3704 #endif
3705 return;
3708 /* Now output the underlying data. If we've handling the padding, return.
3709 Otherwise, break and ensure SIZE is the size written. */
3710 switch (code)
3712 case CHAR_TYPE:
3713 case BOOLEAN_TYPE:
3714 case INTEGER_TYPE:
3715 case ENUMERAL_TYPE:
3716 case POINTER_TYPE:
3717 case REFERENCE_TYPE:
3718 case OFFSET_TYPE:
3719 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3720 EXPAND_INITIALIZER),
3721 MIN (size, thissize), align, 0))
3722 error ("initializer for integer value is too complicated");
3723 break;
3725 case REAL_TYPE:
3726 if (TREE_CODE (exp) != REAL_CST)
3727 error ("initializer for floating value is not a floating constant");
3729 assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align);
3730 break;
3732 case COMPLEX_TYPE:
3733 output_constant (TREE_REALPART (exp), thissize / 2, align);
3734 output_constant (TREE_IMAGPART (exp), thissize / 2,
3735 min_align (align, BITS_PER_UNIT * (thissize / 2)));
3736 break;
3738 case ARRAY_TYPE:
3739 case VECTOR_TYPE:
3740 if (TREE_CODE (exp) == CONSTRUCTOR)
3742 output_constructor (exp, size, align);
3743 return;
3745 else if (TREE_CODE (exp) == STRING_CST)
3747 thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
3748 size);
3749 assemble_string (TREE_STRING_POINTER (exp), thissize);
3751 else if (TREE_CODE (exp) == VECTOR_CST)
3753 int elt_size;
3754 tree link;
3755 unsigned int nalign;
3756 enum machine_mode inner;
3758 inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
3759 nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
3761 elt_size = GET_MODE_SIZE (inner);
3763 link = TREE_VECTOR_CST_ELTS (exp);
3764 output_constant (TREE_VALUE (link), elt_size, align);
3765 while ((link = TREE_CHAIN (link)) != NULL)
3766 output_constant (TREE_VALUE (link), elt_size, nalign);
3768 else
3769 abort ();
3770 break;
3772 case RECORD_TYPE:
3773 case UNION_TYPE:
3774 if (TREE_CODE (exp) == CONSTRUCTOR)
3775 output_constructor (exp, size, align);
3776 else
3777 abort ();
3778 return;
3780 case SET_TYPE:
3781 if (TREE_CODE (exp) == INTEGER_CST)
3782 assemble_integer (expand_expr (exp, NULL_RTX,
3783 VOIDmode, EXPAND_INITIALIZER),
3784 thissize, align, 1);
3785 else if (TREE_CODE (exp) == CONSTRUCTOR)
3787 unsigned char *buffer = alloca (thissize);
3788 if (get_set_constructor_bytes (exp, buffer, thissize))
3789 abort ();
3790 assemble_string ((char *) buffer, thissize);
3792 else
3793 error ("unknown set constructor type");
3794 return;
3796 case ERROR_MARK:
3797 return;
3799 default:
3800 abort ();
3803 if (size > thissize)
3804 assemble_zeros (size - thissize);
3808 /* Subroutine of output_constructor, used for computing the size of
3809 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3810 type with an unspecified upper bound. */
3812 static unsigned HOST_WIDE_INT
3813 array_size_for_constructor (tree val)
3815 tree max_index, i;
3817 /* This code used to attempt to handle string constants that are not
3818 arrays of single-bytes, but nothing else does, so there's no point in
3819 doing it here. */
3820 if (TREE_CODE (val) == STRING_CST)
3821 return TREE_STRING_LENGTH (val);
3823 max_index = NULL_TREE;
3824 for (i = CONSTRUCTOR_ELTS (val); i; i = TREE_CHAIN (i))
3826 tree index = TREE_PURPOSE (i);
3828 if (TREE_CODE (index) == RANGE_EXPR)
3829 index = TREE_OPERAND (index, 1);
3830 if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
3831 max_index = index;
3834 if (max_index == NULL_TREE)
3835 return 0;
3837 /* Compute the total number of array elements. */
3838 i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
3839 convert (sizetype,
3840 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
3841 i = size_binop (PLUS_EXPR, i, convert (sizetype, integer_one_node));
3843 /* Multiply by the array element unit size to find number of bytes. */
3844 i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
3846 return tree_low_cst (i, 1);
3849 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
3850 Generate at least SIZE bytes, padding if necessary. */
3852 static void
3853 output_constructor (tree exp, unsigned HOST_WIDE_INT size,
3854 unsigned int align)
3856 tree type = TREE_TYPE (exp);
3857 tree link, field = 0;
3858 tree min_index = 0;
3859 /* Number of bytes output or skipped so far.
3860 In other words, current position within the constructor. */
3861 HOST_WIDE_INT total_bytes = 0;
3862 /* Nonzero means BYTE contains part of a byte, to be output. */
3863 int byte_buffer_in_use = 0;
3864 int byte = 0;
3866 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3867 abort ();
3869 if (TREE_CODE (type) == RECORD_TYPE)
3870 field = TYPE_FIELDS (type);
3872 if (TREE_CODE (type) == ARRAY_TYPE
3873 && TYPE_DOMAIN (type) != 0)
3874 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
3876 /* As LINK goes through the elements of the constant,
3877 FIELD goes through the structure fields, if the constant is a structure.
3878 if the constant is a union, then we override this,
3879 by getting the field from the TREE_LIST element.
3880 But the constant could also be an array. Then FIELD is zero.
3882 There is always a maximum of one element in the chain LINK for unions
3883 (even if the initializer in a source program incorrectly contains
3884 more one). */
3885 for (link = CONSTRUCTOR_ELTS (exp);
3886 link;
3887 link = TREE_CHAIN (link),
3888 field = field ? TREE_CHAIN (field) : 0)
3890 tree val = TREE_VALUE (link);
3891 tree index = 0;
3893 /* The element in a union constructor specifies the proper field
3894 or index. */
3895 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
3896 || TREE_CODE (type) == QUAL_UNION_TYPE)
3897 && TREE_PURPOSE (link) != 0)
3898 field = TREE_PURPOSE (link);
3900 else if (TREE_CODE (type) == ARRAY_TYPE)
3901 index = TREE_PURPOSE (link);
3903 #ifdef ASM_COMMENT_START
3904 if (field && flag_verbose_asm)
3905 fprintf (asm_out_file, "%s %s:\n",
3906 ASM_COMMENT_START,
3907 DECL_NAME (field)
3908 ? IDENTIFIER_POINTER (DECL_NAME (field))
3909 : "<anonymous>");
3910 #endif
3912 /* Eliminate the marker that makes a cast not be an lvalue. */
3913 if (val != 0)
3914 STRIP_NOPS (val);
3916 if (index && TREE_CODE (index) == RANGE_EXPR)
3918 unsigned HOST_WIDE_INT fieldsize
3919 = int_size_in_bytes (TREE_TYPE (type));
3920 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
3921 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
3922 HOST_WIDE_INT index;
3923 unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT);
3925 for (index = lo_index; index <= hi_index; index++)
3927 /* Output the element's initial value. */
3928 if (val == 0)
3929 assemble_zeros (fieldsize);
3930 else
3931 output_constant (val, fieldsize, align2);
3933 /* Count its size. */
3934 total_bytes += fieldsize;
3937 else if (field == 0 || !DECL_BIT_FIELD (field))
3939 /* An element that is not a bit-field. */
3941 unsigned HOST_WIDE_INT fieldsize;
3942 /* Since this structure is static,
3943 we know the positions are constant. */
3944 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
3945 unsigned int align2;
3947 if (index != 0)
3948 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
3949 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
3951 /* Output any buffered-up bit-fields preceding this element. */
3952 if (byte_buffer_in_use)
3954 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
3955 total_bytes++;
3956 byte_buffer_in_use = 0;
3959 /* Advance to offset of this element.
3960 Note no alignment needed in an array, since that is guaranteed
3961 if each element has the proper size. */
3962 if ((field != 0 || index != 0) && pos != total_bytes)
3964 assemble_zeros (pos - total_bytes);
3965 total_bytes = pos;
3968 /* Find the alignment of this element. */
3969 align2 = min_align (align, BITS_PER_UNIT * pos);
3971 /* Determine size this element should occupy. */
3972 if (field)
3974 fieldsize = 0;
3976 /* If this is an array with an unspecified upper bound,
3977 the initializer determines the size. */
3978 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
3979 but we cannot do this until the deprecated support for
3980 initializing zero-length array members is removed. */
3981 if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE
3982 && TYPE_DOMAIN (TREE_TYPE (field))
3983 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field))))
3985 fieldsize = array_size_for_constructor (val);
3986 /* Given a non-empty initialization, this field had
3987 better be last. */
3988 if (fieldsize != 0 && TREE_CHAIN (field) != NULL_TREE)
3989 abort ();
3991 else if (DECL_SIZE_UNIT (field))
3993 /* ??? This can't be right. If the decl size overflows
3994 a host integer we will silently emit no data. */
3995 if (host_integerp (DECL_SIZE_UNIT (field), 1))
3996 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
3999 else
4000 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4002 /* Output the element's initial value. */
4003 if (val == 0)
4004 assemble_zeros (fieldsize);
4005 else
4006 output_constant (val, fieldsize, align2);
4008 /* Count its size. */
4009 total_bytes += fieldsize;
4011 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4012 error ("invalid initial value for member `%s'",
4013 IDENTIFIER_POINTER (DECL_NAME (field)));
4014 else
4016 /* Element that is a bit-field. */
4018 HOST_WIDE_INT next_offset = int_bit_position (field);
4019 HOST_WIDE_INT end_offset
4020 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4022 if (val == 0)
4023 val = integer_zero_node;
4025 /* If this field does not start in this (or, next) byte,
4026 skip some bytes. */
4027 if (next_offset / BITS_PER_UNIT != total_bytes)
4029 /* Output remnant of any bit field in previous bytes. */
4030 if (byte_buffer_in_use)
4032 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4033 total_bytes++;
4034 byte_buffer_in_use = 0;
4037 /* If still not at proper byte, advance to there. */
4038 if (next_offset / BITS_PER_UNIT != total_bytes)
4040 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4041 total_bytes = next_offset / BITS_PER_UNIT;
4045 if (! byte_buffer_in_use)
4046 byte = 0;
4048 /* We must split the element into pieces that fall within
4049 separate bytes, and combine each byte with previous or
4050 following bit-fields. */
4052 /* next_offset is the offset n fbits from the beginning of
4053 the structure to the next bit of this element to be processed.
4054 end_offset is the offset of the first bit past the end of
4055 this element. */
4056 while (next_offset < end_offset)
4058 int this_time;
4059 int shift;
4060 HOST_WIDE_INT value;
4061 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4062 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4064 /* Advance from byte to byte
4065 within this element when necessary. */
4066 while (next_byte != total_bytes)
4068 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4069 total_bytes++;
4070 byte = 0;
4073 /* Number of bits we can process at once
4074 (all part of the same byte). */
4075 this_time = MIN (end_offset - next_offset,
4076 BITS_PER_UNIT - next_bit);
4077 if (BYTES_BIG_ENDIAN)
4079 /* On big-endian machine, take the most significant bits
4080 first (of the bits that are significant)
4081 and put them into bytes from the most significant end. */
4082 shift = end_offset - next_offset - this_time;
4084 /* Don't try to take a bunch of bits that cross
4085 the word boundary in the INTEGER_CST. We can
4086 only select bits from the LOW or HIGH part
4087 not from both. */
4088 if (shift < HOST_BITS_PER_WIDE_INT
4089 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4091 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4092 shift = HOST_BITS_PER_WIDE_INT;
4095 /* Now get the bits from the appropriate constant word. */
4096 if (shift < HOST_BITS_PER_WIDE_INT)
4097 value = TREE_INT_CST_LOW (val);
4098 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4100 value = TREE_INT_CST_HIGH (val);
4101 shift -= HOST_BITS_PER_WIDE_INT;
4103 else
4104 abort ();
4106 /* Get the result. This works only when:
4107 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4108 byte |= (((value >> shift)
4109 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4110 << (BITS_PER_UNIT - this_time - next_bit));
4112 else
4114 /* On little-endian machines,
4115 take first the least significant bits of the value
4116 and pack them starting at the least significant
4117 bits of the bytes. */
4118 shift = next_offset - int_bit_position (field);
4120 /* Don't try to take a bunch of bits that cross
4121 the word boundary in the INTEGER_CST. We can
4122 only select bits from the LOW or HIGH part
4123 not from both. */
4124 if (shift < HOST_BITS_PER_WIDE_INT
4125 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4126 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4128 /* Now get the bits from the appropriate constant word. */
4129 if (shift < HOST_BITS_PER_WIDE_INT)
4130 value = TREE_INT_CST_LOW (val);
4131 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4133 value = TREE_INT_CST_HIGH (val);
4134 shift -= HOST_BITS_PER_WIDE_INT;
4136 else
4137 abort ();
4139 /* Get the result. This works only when:
4140 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4141 byte |= (((value >> shift)
4142 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4143 << next_bit);
4146 next_offset += this_time;
4147 byte_buffer_in_use = 1;
4152 if (byte_buffer_in_use)
4154 assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1);
4155 total_bytes++;
4158 if ((unsigned HOST_WIDE_INT)total_bytes < size)
4159 assemble_zeros (size - total_bytes);
4162 /* This TREE_LIST contains any weak symbol declarations waiting
4163 to be emitted. */
4164 static GTY(()) tree weak_decls;
4166 /* Mark DECL as weak. */
4168 static void
4169 mark_weak (tree decl)
4171 DECL_WEAK (decl) = 1;
4173 if (DECL_RTL_SET_P (decl)
4174 && MEM_P (DECL_RTL (decl))
4175 && XEXP (DECL_RTL (decl), 0)
4176 && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
4177 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
4180 /* Merge weak status between NEWDECL and OLDDECL. */
4182 void
4183 merge_weak (tree newdecl, tree olddecl)
4185 if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
4186 return;
4188 if (DECL_WEAK (newdecl))
4190 tree wd;
4192 /* NEWDECL is weak, but OLDDECL is not. */
4194 /* If we already output the OLDDECL, we're in trouble; we can't
4195 go back and make it weak. This error cannot caught in
4196 declare_weak because the NEWDECL and OLDDECL was not yet
4197 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4198 if (TREE_ASM_WRITTEN (olddecl))
4199 error ("%Jweak declaration of '%D' must precede definition",
4200 newdecl, newdecl);
4202 /* If we've already generated rtl referencing OLDDECL, we may
4203 have done so in a way that will not function properly with
4204 a weak symbol. */
4205 else if (TREE_USED (olddecl)
4206 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)))
4207 warning ("%Jweak declaration of '%D' after first use results "
4208 "in unspecified behavior", newdecl, newdecl);
4210 if (SUPPORTS_WEAK)
4212 /* We put the NEWDECL on the weak_decls list at some point.
4213 Replace it with the OLDDECL. */
4214 for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
4215 if (TREE_VALUE (wd) == newdecl)
4217 TREE_VALUE (wd) = olddecl;
4218 break;
4220 /* We may not find the entry on the list. If NEWDECL is a
4221 weak alias, then we will have already called
4222 globalize_decl to remove the entry; in that case, we do
4223 not need to do anything. */
4226 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4227 mark_weak (olddecl);
4229 else
4230 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4231 weak. Just update NEWDECL to indicate that it's weak too. */
4232 mark_weak (newdecl);
4235 /* Declare DECL to be a weak symbol. */
4237 void
4238 declare_weak (tree decl)
4240 if (! TREE_PUBLIC (decl))
4241 error ("%Jweak declaration of '%D' must be public", decl, decl);
4242 else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl))
4243 error ("%Jweak declaration of '%D' must precede definition", decl, decl);
4244 else if (SUPPORTS_WEAK)
4246 if (! DECL_WEAK (decl))
4247 weak_decls = tree_cons (NULL, decl, weak_decls);
4249 else
4250 warning ("%Jweak declaration of '%D' not supported", decl, decl);
4252 mark_weak (decl);
4255 /* Emit any pending weak declarations. */
4257 void
4258 weak_finish (void)
4260 tree t;
4262 for (t = weak_decls; t; t = TREE_CHAIN (t))
4264 tree decl = TREE_VALUE (t);
4265 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4266 const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4267 #endif
4269 if (! TREE_USED (decl))
4270 continue;
4272 #ifdef ASM_WEAKEN_DECL
4273 ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
4274 #else
4275 #ifdef ASM_WEAKEN_LABEL
4276 ASM_WEAKEN_LABEL (asm_out_file, name);
4277 #else
4278 #ifdef ASM_OUTPUT_WEAK_ALIAS
4279 warning ("only weak aliases are supported in this configuration");
4280 return;
4281 #endif
4282 #endif
4283 #endif
4287 /* Emit the assembly bits to indicate that DECL is globally visible. */
4289 static void
4290 globalize_decl (tree decl)
4292 const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4294 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4295 if (DECL_WEAK (decl))
4297 tree *p, t;
4299 #ifdef ASM_WEAKEN_DECL
4300 ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
4301 #else
4302 ASM_WEAKEN_LABEL (asm_out_file, name);
4303 #endif
4305 /* Remove this function from the pending weak list so that
4306 we do not emit multiple .weak directives for it. */
4307 for (p = &weak_decls; (t = *p) ; )
4309 if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4310 *p = TREE_CHAIN (t);
4311 else
4312 p = &TREE_CHAIN (t);
4314 return;
4316 #elif defined(ASM_MAKE_LABEL_LINKONCE)
4317 if (DECL_ONE_ONLY (decl))
4318 ASM_MAKE_LABEL_LINKONCE (asm_out_file, name);
4319 #endif
4321 targetm.asm_out.globalize_label (asm_out_file, name);
4324 /* Emit an assembler directive to make the symbol for DECL an alias to
4325 the symbol for TARGET. */
4327 void
4328 assemble_alias (tree decl, tree target ATTRIBUTE_UNUSED)
4330 const char *name;
4332 /* We must force creation of DECL_RTL for debug info generation, even though
4333 we don't use it here. */
4334 make_decl_rtl (decl);
4336 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4338 #ifdef ASM_OUTPUT_DEF
4339 /* Make name accessible from other files, if appropriate. */
4341 if (TREE_PUBLIC (decl))
4343 globalize_decl (decl);
4344 maybe_assemble_visibility (decl);
4347 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4348 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4349 #else
4350 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4351 #endif
4352 #else /* !ASM_OUTPUT_DEF */
4353 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4354 if (DECL_WEAK (decl))
4356 tree *p, t;
4357 #ifdef ASM_WEAKEN_DECL
4358 ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
4359 #else
4360 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4361 #endif
4362 /* Remove this function from the pending weak list so that
4363 we do not emit multiple .weak directives for it. */
4364 for (p = &weak_decls; (t = *p) ; )
4365 if (DECL_ASSEMBLER_NAME (decl)
4366 == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
4367 *p = TREE_CHAIN (t);
4368 else
4369 p = &TREE_CHAIN (t);
4371 else
4372 warning ("only weak aliases are supported in this configuration");
4374 #else
4375 warning ("alias definitions not supported in this configuration; ignored");
4376 #endif
4377 #endif
4379 TREE_USED (decl) = 1;
4380 TREE_ASM_WRITTEN (decl) = 1;
4381 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
4384 /* Emit an assembler directive to set symbol for DECL visibility to
4385 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4387 void
4388 default_assemble_visibility (tree decl, int vis)
4390 static const char * const visibility_types[] = {
4391 NULL, "internal", "hidden", "protected"
4394 const char *name, *type;
4396 name = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4397 type = visibility_types[vis];
4399 #ifdef HAVE_GAS_HIDDEN
4400 fprintf (asm_out_file, "\t.%s\t", type);
4401 assemble_name (asm_out_file, name);
4402 fprintf (asm_out_file, "\n");
4403 #else
4404 warning ("visibility attribute not supported in this configuration; ignored");
4405 #endif
4408 /* A helper function to call assemble_visibility when needed for a decl. */
4410 static void
4411 maybe_assemble_visibility (tree decl)
4413 enum symbol_visibility vis = DECL_VISIBILITY (decl);
4415 if (vis != VISIBILITY_DEFAULT)
4416 targetm.asm_out.visibility (decl, vis);
4419 /* Returns 1 if the target configuration supports defining public symbols
4420 so that one of them will be chosen at link time instead of generating a
4421 multiply-defined symbol error, whether through the use of weak symbols or
4422 a target-specific mechanism for having duplicates discarded. */
4425 supports_one_only (void)
4427 if (SUPPORTS_ONE_ONLY)
4428 return 1;
4429 return SUPPORTS_WEAK;
4432 /* Set up DECL as a public symbol that can be defined in multiple
4433 translation units without generating a linker error. */
4435 void
4436 make_decl_one_only (tree decl)
4438 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4439 abort ();
4441 TREE_PUBLIC (decl) = 1;
4443 if (SUPPORTS_ONE_ONLY)
4445 #ifdef MAKE_DECL_ONE_ONLY
4446 MAKE_DECL_ONE_ONLY (decl);
4447 #endif
4448 DECL_ONE_ONLY (decl) = 1;
4450 else if (TREE_CODE (decl) == VAR_DECL
4451 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4452 DECL_COMMON (decl) = 1;
4453 else if (SUPPORTS_WEAK)
4454 DECL_WEAK (decl) = 1;
4455 else
4456 abort ();
4459 void
4460 init_varasm_once (void)
4462 in_named_htab = htab_create_ggc (31, in_named_entry_hash,
4463 in_named_entry_eq, NULL);
4464 const_desc_htab = htab_create_ggc (1009, const_desc_hash,
4465 const_desc_eq, NULL);
4467 const_alias_set = new_alias_set ();
4470 enum tls_model
4471 decl_tls_model (tree decl)
4473 enum tls_model kind;
4474 tree attr = lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl));
4475 bool is_local;
4477 if (attr)
4479 attr = TREE_VALUE (TREE_VALUE (attr));
4480 if (TREE_CODE (attr) != STRING_CST)
4481 abort ();
4482 if (!strcmp (TREE_STRING_POINTER (attr), "local-exec"))
4483 kind = TLS_MODEL_LOCAL_EXEC;
4484 else if (!strcmp (TREE_STRING_POINTER (attr), "initial-exec"))
4485 kind = TLS_MODEL_INITIAL_EXEC;
4486 else if (!strcmp (TREE_STRING_POINTER (attr), "local-dynamic"))
4487 kind = optimize ? TLS_MODEL_LOCAL_DYNAMIC : TLS_MODEL_GLOBAL_DYNAMIC;
4488 else if (!strcmp (TREE_STRING_POINTER (attr), "global-dynamic"))
4489 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4490 else
4491 abort ();
4492 return kind;
4495 is_local = targetm.binds_local_p (decl);
4496 if (!flag_pic)
4498 if (is_local)
4499 kind = TLS_MODEL_LOCAL_EXEC;
4500 else
4501 kind = TLS_MODEL_INITIAL_EXEC;
4503 /* Local dynamic is inefficient when we're not combining the
4504 parts of the address. */
4505 else if (optimize && is_local)
4506 kind = TLS_MODEL_LOCAL_DYNAMIC;
4507 else
4508 kind = TLS_MODEL_GLOBAL_DYNAMIC;
4509 if (kind < flag_tls_default)
4510 kind = flag_tls_default;
4512 return kind;
4515 /* Select a set of attributes for section NAME based on the properties
4516 of DECL and whether or not RELOC indicates that DECL's initializer
4517 might contain runtime relocations.
4519 We make the section read-only and executable for a function decl,
4520 read-only for a const data decl, and writable for a non-const data decl. */
4522 unsigned int
4523 default_section_type_flags (tree decl, const char *name, int reloc)
4525 return default_section_type_flags_1 (decl, name, reloc, flag_pic);
4528 unsigned int
4529 default_section_type_flags_1 (tree decl, const char *name, int reloc,
4530 int shlib)
4532 unsigned int flags;
4534 if (decl && TREE_CODE (decl) == FUNCTION_DECL)
4535 flags = SECTION_CODE;
4536 else if (decl && decl_readonly_section_1 (decl, reloc, shlib))
4537 flags = 0;
4538 else if (unlikely_text_section_name
4539 && strcmp (name, unlikely_text_section_name) == 0)
4540 flags = SECTION_CODE;
4541 else
4542 flags = SECTION_WRITE;
4544 if (decl && DECL_ONE_ONLY (decl))
4545 flags |= SECTION_LINKONCE;
4547 if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4548 flags |= SECTION_TLS | SECTION_WRITE;
4550 if (strcmp (name, ".bss") == 0
4551 || strncmp (name, ".bss.", 5) == 0
4552 || strncmp (name, ".gnu.linkonce.b.", 16) == 0
4553 || strcmp (name, ".sbss") == 0
4554 || strncmp (name, ".sbss.", 6) == 0
4555 || strncmp (name, ".gnu.linkonce.sb.", 17) == 0
4556 || strcmp (name, ".tbss") == 0
4557 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4558 flags |= SECTION_BSS;
4560 if (strcmp (name, ".tdata") == 0
4561 || strcmp (name, ".tbss") == 0
4562 || strncmp (name, ".gnu.linkonce.td.", 17) == 0
4563 || strncmp (name, ".gnu.linkonce.tb.", 17) == 0)
4564 flags |= SECTION_TLS;
4566 /* These three sections have special ELF types. They are neither
4567 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4568 want to print a section type (@progbits or @nobits). If someone
4569 is silly enough to emit code or TLS variables to one of these
4570 sections, then don't handle them specially. */
4571 if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS))
4572 && (strcmp (name, ".init_array") == 0
4573 || strcmp (name, ".fini_array") == 0
4574 || strcmp (name, ".preinit_array") == 0))
4575 flags |= SECTION_NOTYPE;
4577 return flags;
4580 /* Output assembly to switch to section NAME with attribute FLAGS.
4581 Four variants for common object file formats. */
4583 void
4584 default_no_named_section (const char *name ATTRIBUTE_UNUSED,
4585 unsigned int flags ATTRIBUTE_UNUSED)
4587 /* Some object formats don't support named sections at all. The
4588 front-end should already have flagged this as an error. */
4589 abort ();
4592 void
4593 default_elf_asm_named_section (const char *name, unsigned int flags)
4595 char flagchars[10], *f = flagchars;
4597 if (! named_section_first_declaration (name))
4599 fprintf (asm_out_file, "\t.section\t%s\n", name);
4600 return;
4603 if (!(flags & SECTION_DEBUG))
4604 *f++ = 'a';
4605 if (flags & SECTION_WRITE)
4606 *f++ = 'w';
4607 if (flags & SECTION_CODE)
4608 *f++ = 'x';
4609 if (flags & SECTION_SMALL)
4610 *f++ = 's';
4611 if (flags & SECTION_MERGE)
4612 *f++ = 'M';
4613 if (flags & SECTION_STRINGS)
4614 *f++ = 'S';
4615 if (flags & SECTION_TLS)
4616 *f++ = 'T';
4617 *f = '\0';
4619 fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
4621 if (!(flags & SECTION_NOTYPE))
4623 const char *type;
4625 if (flags & SECTION_BSS)
4626 type = "nobits";
4627 else
4628 type = "progbits";
4630 fprintf (asm_out_file, ",@%s", type);
4632 if (flags & SECTION_ENTSIZE)
4633 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
4636 putc ('\n', asm_out_file);
4639 void
4640 default_coff_asm_named_section (const char *name, unsigned int flags)
4642 char flagchars[8], *f = flagchars;
4644 if (flags & SECTION_WRITE)
4645 *f++ = 'w';
4646 if (flags & SECTION_CODE)
4647 *f++ = 'x';
4648 *f = '\0';
4650 fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
4653 void
4654 default_pe_asm_named_section (const char *name, unsigned int flags)
4656 default_coff_asm_named_section (name, flags);
4658 if (flags & SECTION_LINKONCE)
4660 /* Functions may have been compiled at various levels of
4661 optimization so we can't use `same_size' here.
4662 Instead, have the linker pick one. */
4663 fprintf (asm_out_file, "\t.linkonce %s\n",
4664 (flags & SECTION_CODE ? "discard" : "same_size"));
4668 /* The lame default section selector. */
4670 void
4671 default_select_section (tree decl, int reloc,
4672 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4674 bool readonly = false;
4676 if (DECL_P (decl))
4678 if (decl_readonly_section (decl, reloc))
4679 readonly = true;
4681 else if (TREE_CODE (decl) == CONSTRUCTOR)
4683 if (! ((flag_pic && reloc)
4684 || !TREE_READONLY (decl)
4685 || TREE_SIDE_EFFECTS (decl)
4686 || !TREE_CONSTANT (decl)))
4687 readonly = true;
4689 else if (TREE_CODE (decl) == STRING_CST)
4690 readonly = true;
4691 else if (! (flag_pic && reloc))
4692 readonly = true;
4694 if (readonly)
4695 readonly_data_section ();
4696 else
4697 data_section ();
4700 /* A helper function for default_elf_select_section and
4701 default_elf_unique_section. Categorizes the DECL. */
4703 enum section_category
4705 SECCAT_TEXT,
4707 SECCAT_RODATA,
4708 SECCAT_RODATA_MERGE_STR,
4709 SECCAT_RODATA_MERGE_STR_INIT,
4710 SECCAT_RODATA_MERGE_CONST,
4711 SECCAT_SRODATA,
4713 SECCAT_DATA,
4715 /* To optimize loading of shared programs, define following subsections
4716 of data section:
4717 _REL Contains data that has relocations, so they get grouped
4718 together and dynamic linker will visit fewer pages in memory.
4719 _RO Contains data that is otherwise read-only. This is useful
4720 with prelinking as most relocations won't be dynamically
4721 linked and thus stay read only.
4722 _LOCAL Marks data containing relocations only to local objects.
4723 These relocations will get fully resolved by prelinking. */
4724 SECCAT_DATA_REL,
4725 SECCAT_DATA_REL_LOCAL,
4726 SECCAT_DATA_REL_RO,
4727 SECCAT_DATA_REL_RO_LOCAL,
4729 SECCAT_SDATA,
4730 SECCAT_TDATA,
4732 SECCAT_BSS,
4733 SECCAT_SBSS,
4734 SECCAT_TBSS
4737 static enum section_category
4738 categorize_decl_for_section (tree, int, int);
4740 static enum section_category
4741 categorize_decl_for_section (tree decl, int reloc, int shlib)
4743 enum section_category ret;
4745 if (TREE_CODE (decl) == FUNCTION_DECL)
4746 return SECCAT_TEXT;
4747 else if (TREE_CODE (decl) == STRING_CST)
4749 if (flag_mudflap) /* or !flag_merge_constants */
4750 return SECCAT_RODATA;
4751 else
4752 return SECCAT_RODATA_MERGE_STR;
4754 else if (TREE_CODE (decl) == VAR_DECL)
4756 if (DECL_INITIAL (decl) == NULL
4757 || DECL_INITIAL (decl) == error_mark_node
4758 || (flag_zero_initialized_in_bss
4759 /* Leave constant zeroes in .rodata so they can be shared. */
4760 && !TREE_READONLY (decl)
4761 && initializer_zerop (DECL_INITIAL (decl))))
4762 ret = SECCAT_BSS;
4763 else if (! TREE_READONLY (decl)
4764 || TREE_SIDE_EFFECTS (decl)
4765 || ! TREE_CONSTANT (DECL_INITIAL (decl)))
4767 if (shlib && (reloc & 2))
4768 ret = SECCAT_DATA_REL;
4769 else if (shlib && reloc)
4770 ret = SECCAT_DATA_REL_LOCAL;
4771 else
4772 ret = SECCAT_DATA;
4774 else if (shlib && (reloc & 2))
4775 ret = SECCAT_DATA_REL_RO;
4776 else if (shlib && reloc)
4777 ret = SECCAT_DATA_REL_RO_LOCAL;
4778 else if (reloc || flag_merge_constants < 2)
4779 /* C and C++ don't allow different variables to share the same
4780 location. -fmerge-all-constants allows even that (at the
4781 expense of not conforming). */
4782 ret = SECCAT_RODATA;
4783 else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
4784 ret = SECCAT_RODATA_MERGE_STR_INIT;
4785 else
4786 ret = SECCAT_RODATA_MERGE_CONST;
4788 else if (TREE_CODE (decl) == CONSTRUCTOR)
4790 if ((shlib && reloc)
4791 || TREE_SIDE_EFFECTS (decl)
4792 || ! TREE_CONSTANT (decl))
4793 ret = SECCAT_DATA;
4794 else
4795 ret = SECCAT_RODATA;
4797 else
4798 ret = SECCAT_RODATA;
4800 /* There are no read-only thread-local sections. */
4801 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
4803 /* Note that this would be *just* SECCAT_BSS, except that there's
4804 no concept of a read-only thread-local-data section. */
4805 if (ret == SECCAT_BSS
4806 || (flag_zero_initialized_in_bss
4807 && initializer_zerop (DECL_INITIAL (decl))))
4808 ret = SECCAT_TBSS;
4809 else
4810 ret = SECCAT_TDATA;
4813 /* If the target uses small data sections, select it. */
4814 else if (targetm.in_small_data_p (decl))
4816 if (ret == SECCAT_BSS)
4817 ret = SECCAT_SBSS;
4818 else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
4819 ret = SECCAT_SRODATA;
4820 else
4821 ret = SECCAT_SDATA;
4824 return ret;
4827 bool
4828 decl_readonly_section (tree decl, int reloc)
4830 return decl_readonly_section_1 (decl, reloc, flag_pic);
4833 bool
4834 decl_readonly_section_1 (tree decl, int reloc, int shlib)
4836 switch (categorize_decl_for_section (decl, reloc, shlib))
4838 case SECCAT_RODATA:
4839 case SECCAT_RODATA_MERGE_STR:
4840 case SECCAT_RODATA_MERGE_STR_INIT:
4841 case SECCAT_RODATA_MERGE_CONST:
4842 case SECCAT_SRODATA:
4843 return true;
4844 break;
4845 default:
4846 return false;
4847 break;
4851 /* Select a section based on the above categorization. */
4853 void
4854 default_elf_select_section (tree decl, int reloc,
4855 unsigned HOST_WIDE_INT align)
4857 default_elf_select_section_1 (decl, reloc, align, flag_pic);
4860 void
4861 default_elf_select_section_1 (tree decl, int reloc,
4862 unsigned HOST_WIDE_INT align, int shlib)
4864 switch (categorize_decl_for_section (decl, reloc, shlib))
4866 case SECCAT_TEXT:
4867 /* We're not supposed to be called on FUNCTION_DECLs. */
4868 abort ();
4869 case SECCAT_RODATA:
4870 readonly_data_section ();
4871 break;
4872 case SECCAT_RODATA_MERGE_STR:
4873 mergeable_string_section (decl, align, 0);
4874 break;
4875 case SECCAT_RODATA_MERGE_STR_INIT:
4876 mergeable_string_section (DECL_INITIAL (decl), align, 0);
4877 break;
4878 case SECCAT_RODATA_MERGE_CONST:
4879 mergeable_constant_section (DECL_MODE (decl), align, 0);
4880 break;
4881 case SECCAT_SRODATA:
4882 named_section (NULL_TREE, ".sdata2", reloc);
4883 break;
4884 case SECCAT_DATA:
4885 data_section ();
4886 break;
4887 case SECCAT_DATA_REL:
4888 named_section (NULL_TREE, ".data.rel", reloc);
4889 break;
4890 case SECCAT_DATA_REL_LOCAL:
4891 named_section (NULL_TREE, ".data.rel.local", reloc);
4892 break;
4893 case SECCAT_DATA_REL_RO:
4894 named_section (NULL_TREE, ".data.rel.ro", reloc);
4895 break;
4896 case SECCAT_DATA_REL_RO_LOCAL:
4897 named_section (NULL_TREE, ".data.rel.ro.local", reloc);
4898 break;
4899 case SECCAT_SDATA:
4900 named_section (NULL_TREE, ".sdata", reloc);
4901 break;
4902 case SECCAT_TDATA:
4903 named_section (NULL_TREE, ".tdata", reloc);
4904 break;
4905 case SECCAT_BSS:
4906 #ifdef BSS_SECTION_ASM_OP
4907 bss_section ();
4908 #else
4909 named_section (NULL_TREE, ".bss", reloc);
4910 #endif
4911 break;
4912 case SECCAT_SBSS:
4913 named_section (NULL_TREE, ".sbss", reloc);
4914 break;
4915 case SECCAT_TBSS:
4916 named_section (NULL_TREE, ".tbss", reloc);
4917 break;
4918 default:
4919 abort ();
4923 /* Construct a unique section name based on the decl name and the
4924 categorization performed above. */
4926 void
4927 default_unique_section (tree decl, int reloc)
4929 default_unique_section_1 (decl, reloc, flag_pic);
4932 void
4933 default_unique_section_1 (tree decl, int reloc, int shlib)
4935 bool one_only = DECL_ONE_ONLY (decl);
4936 const char *prefix, *name;
4937 size_t nlen, plen;
4938 char *string;
4940 switch (categorize_decl_for_section (decl, reloc, shlib))
4942 case SECCAT_TEXT:
4943 prefix = one_only ? ".gnu.linkonce.t." : ".text.";
4944 break;
4945 case SECCAT_RODATA:
4946 case SECCAT_RODATA_MERGE_STR:
4947 case SECCAT_RODATA_MERGE_STR_INIT:
4948 case SECCAT_RODATA_MERGE_CONST:
4949 prefix = one_only ? ".gnu.linkonce.r." : ".rodata.";
4950 break;
4951 case SECCAT_SRODATA:
4952 prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2.";
4953 break;
4954 case SECCAT_DATA:
4955 case SECCAT_DATA_REL:
4956 case SECCAT_DATA_REL_LOCAL:
4957 case SECCAT_DATA_REL_RO:
4958 case SECCAT_DATA_REL_RO_LOCAL:
4959 prefix = one_only ? ".gnu.linkonce.d." : ".data.";
4960 break;
4961 case SECCAT_SDATA:
4962 prefix = one_only ? ".gnu.linkonce.s." : ".sdata.";
4963 break;
4964 case SECCAT_BSS:
4965 prefix = one_only ? ".gnu.linkonce.b." : ".bss.";
4966 break;
4967 case SECCAT_SBSS:
4968 prefix = one_only ? ".gnu.linkonce.sb." : ".sbss.";
4969 break;
4970 case SECCAT_TDATA:
4971 prefix = one_only ? ".gnu.linkonce.td." : ".tdata.";
4972 break;
4973 case SECCAT_TBSS:
4974 prefix = one_only ? ".gnu.linkonce.tb." : ".tbss.";
4975 break;
4976 default:
4977 abort ();
4979 plen = strlen (prefix);
4981 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
4982 name = targetm.strip_name_encoding (name);
4983 nlen = strlen (name);
4985 string = alloca (nlen + plen + 1);
4986 memcpy (string, prefix, plen);
4987 memcpy (string + plen, name, nlen + 1);
4989 DECL_SECTION_NAME (decl) = build_string (nlen + plen, string);
4992 void
4993 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED,
4994 rtx x,
4995 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
4997 if (flag_pic)
4998 switch (GET_CODE (x))
5000 case CONST:
5001 case SYMBOL_REF:
5002 case LABEL_REF:
5003 data_section ();
5004 return;
5006 default:
5007 break;
5010 readonly_data_section ();
5013 void
5014 default_elf_select_rtx_section (enum machine_mode mode, rtx x,
5015 unsigned HOST_WIDE_INT align)
5017 /* ??? Handle small data here somehow. */
5019 if (flag_pic)
5020 switch (GET_CODE (x))
5022 case CONST:
5023 case SYMBOL_REF:
5024 named_section (NULL_TREE, ".data.rel.ro", 3);
5025 return;
5027 case LABEL_REF:
5028 named_section (NULL_TREE, ".data.rel.ro.local", 1);
5029 return;
5031 default:
5032 break;
5035 mergeable_constant_section (mode, align, 0);
5038 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5040 void
5041 default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
5043 rtx symbol;
5044 int flags;
5046 /* Careful not to prod global register variables. */
5047 if (!MEM_P (rtl))
5048 return;
5049 symbol = XEXP (rtl, 0);
5050 if (GET_CODE (symbol) != SYMBOL_REF)
5051 return;
5053 flags = 0;
5054 if (TREE_CODE (decl) == FUNCTION_DECL)
5055 flags |= SYMBOL_FLAG_FUNCTION;
5056 if (targetm.binds_local_p (decl))
5057 flags |= SYMBOL_FLAG_LOCAL;
5058 if (targetm.in_small_data_p (decl))
5059 flags |= SYMBOL_FLAG_SMALL;
5060 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
5061 flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
5062 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5063 being PUBLIC, the thing *must* be defined in this translation unit.
5064 Prevent this buglet from being propagated into rtl code as well. */
5065 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
5066 flags |= SYMBOL_FLAG_EXTERNAL;
5068 SYMBOL_REF_FLAGS (symbol) = flags;
5071 /* By default, we do nothing for encode_section_info, so we need not
5072 do anything but discard the '*' marker. */
5074 const char *
5075 default_strip_name_encoding (const char *str)
5077 return str + (*str == '*');
5080 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5081 wrt cross-module name binding. */
5083 bool
5084 default_binds_local_p (tree exp)
5086 return default_binds_local_p_1 (exp, flag_shlib);
5089 bool
5090 default_binds_local_p_1 (tree exp, int shlib)
5092 bool local_p;
5094 /* A non-decl is an entry in the constant pool. */
5095 if (!DECL_P (exp))
5096 local_p = true;
5097 /* Static variables are always local. */
5098 else if (! TREE_PUBLIC (exp))
5099 local_p = true;
5100 /* A variable is local if the user explicitly tells us so. */
5101 else if (DECL_VISIBILITY_SPECIFIED (exp) && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5102 local_p = true;
5103 /* Otherwise, variables defined outside this object may not be local. */
5104 else if (DECL_EXTERNAL (exp))
5105 local_p = false;
5106 /* Linkonce and weak data are never local. */
5107 else if (DECL_ONE_ONLY (exp) || DECL_WEAK (exp))
5108 local_p = false;
5109 /* If none of the above and visibility is not default, make local. */
5110 else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT)
5111 local_p = true;
5112 /* If PIC, then assume that any global name can be overridden by
5113 symbols resolved from other modules. */
5114 else if (shlib)
5115 local_p = false;
5116 /* Uninitialized COMMON variable may be unified with symbols
5117 resolved from other modules. */
5118 else if (DECL_COMMON (exp)
5119 && (DECL_INITIAL (exp) == NULL
5120 || DECL_INITIAL (exp) == error_mark_node))
5121 local_p = false;
5122 /* Otherwise we're left with initialized (or non-common) global data
5123 which is of necessity defined locally. */
5124 else
5125 local_p = true;
5127 return local_p;
5130 /* Determine whether or not a pointer mode is valid. Assume defaults
5131 of ptr_mode or Pmode - can be overridden. */
5132 bool
5133 default_valid_pointer_mode (enum machine_mode mode)
5135 return (mode == ptr_mode || mode == Pmode);
5138 /* Default function to output code that will globalize a label. A
5139 target must define GLOBAL_ASM_OP or provide it's own function to
5140 globalize a label. */
5141 #ifdef GLOBAL_ASM_OP
5142 void
5143 default_globalize_label (FILE * stream, const char *name)
5145 fputs (GLOBAL_ASM_OP, stream);
5146 assemble_name (stream, name);
5147 putc ('\n', stream);
5149 #endif /* GLOBAL_ASM_OP */
5151 /* Default function to output a label for unwind information. The
5152 default is to do nothing. A target that needs nonlocal labels for
5153 unwind information must provide its own function to do this. */
5154 void
5155 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
5156 tree decl ATTRIBUTE_UNUSED,
5157 int for_eh ATTRIBUTE_UNUSED,
5158 int empty ATTRIBUTE_UNUSED)
5162 /* This is how to output an internal numbered label where PREFIX is
5163 the class of label and LABELNO is the number within the class. */
5165 void
5166 default_internal_label (FILE *stream, const char *prefix,
5167 unsigned long labelno)
5169 char *const buf = alloca (40 + strlen (prefix));
5170 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
5171 ASM_OUTPUT_LABEL (stream, buf);
5174 /* This is the default behavior at the beginning of a file. It's
5175 controlled by two other target-hook toggles. */
5176 void
5177 default_file_start (void)
5179 if (targetm.file_start_app_off && !flag_verbose_asm)
5180 fputs (ASM_APP_OFF, asm_out_file);
5182 if (targetm.file_start_file_directive)
5183 output_file_directive (asm_out_file, main_input_filename);
5186 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
5187 which emits a special section directive used to indicate whether or
5188 not this object file needs an executable stack. This is primarily
5189 a GNU extension to ELF but could be used on other targets. */
5191 int trampolines_created;
5193 void
5194 file_end_indicate_exec_stack (void)
5196 unsigned int flags = SECTION_DEBUG;
5197 if (trampolines_created)
5198 flags |= SECTION_CODE;
5200 named_section_flags (".note.GNU-stack", flags);
5203 #include "gt-varasm.h"