1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
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
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
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. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
48 #include "langhooks.h"
53 #ifdef XCOFF_DEBUGGING_INFO
54 #include "xcoffout.h" /* Needed for external data
55 declarations for e.g. AIX 4.x. */
58 #ifndef TRAMPOLINE_ALIGNMENT
59 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
63 #define ASM_STABS_OP "\t.stabs\t"
66 /* The (assembler) name of the first globally-visible object output. */
67 const char *first_global_object_name
;
68 const char *weak_global_object_name
;
71 struct constant_descriptor_rtx
;
75 #define MAX_RTX_HASH_TABLE 61
77 struct varasm_status
GTY(())
79 /* Hash facility for making memory-constants
80 from constant rtl-expressions. It is used on RISC machines
81 where immediate integer arguments and constant addresses are restricted
82 so that such constants must be stored in memory.
84 This pool of constants is reinitialized for each function
85 so each function gets its own constants-pool that comes right before
87 struct constant_descriptor_rtx
** GTY ((length ("MAX_RTX_HASH_TABLE")))
88 x_const_rtx_hash_table
;
89 struct pool_constant
** GTY ((length ("MAX_RTX_HASH_TABLE")))
90 x_const_rtx_sym_hash_table
;
92 /* Pointers to first and last constant in pool. */
93 struct pool_constant
*x_first_pool
;
94 struct pool_constant
*x_last_pool
;
96 /* Current offset in constant pool (does not include any machine-specific
98 HOST_WIDE_INT x_pool_offset
;
101 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
102 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
103 #define first_pool (cfun->varasm->x_first_pool)
104 #define last_pool (cfun->varasm->x_last_pool)
105 #define pool_offset (cfun->varasm->x_pool_offset)
107 /* Number for making the label on the next
108 constant that is stored in memory. */
110 static GTY(()) int const_labelno
;
112 /* Number for making the label on the next
113 static variable internal to a function. */
115 static GTY(()) int var_labelno
;
117 /* Carry information from ASM_DECLARE_OBJECT_NAME
118 to ASM_FINISH_DECLARE_OBJECT. */
120 int size_directive_output
;
122 /* The last decl for which assemble_variable was called,
123 if it did ASM_DECLARE_OBJECT_NAME.
124 If the last call to assemble_variable didn't do that,
127 tree last_assemble_variable_decl
;
129 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
130 So giving constant the alias set for the type will allow such
131 initializations to appear to conflict with the load of the constant. We
132 avoid this by giving all constants an alias set for just constants.
133 Since there will be no stores to that alias set, nothing will ever
134 conflict with them. */
136 static HOST_WIDE_INT const_alias_set
;
138 static const char *strip_reg_name
PARAMS ((const char *));
139 static int contains_pointers_p
PARAMS ((tree
));
140 static void decode_addr_const
PARAMS ((tree
, struct addr_const
*));
141 static unsigned int const_hash
PARAMS ((tree
));
142 static unsigned int const_hash_1
PARAMS ((tree
));
143 static int compare_constant
PARAMS ((tree
, tree
));
144 static tree copy_constant
PARAMS ((tree
));
145 static void maybe_output_constant_def_contents
PARAMS ((tree
, rtx
, int));
146 static void output_constant_def_contents
PARAMS ((tree
, const char *));
147 static void decode_rtx_const
PARAMS ((enum machine_mode
, rtx
,
148 struct rtx_const
*));
149 static unsigned int const_hash_rtx
PARAMS ((enum machine_mode
, rtx
));
150 static int compare_constant_rtx
151 PARAMS ((enum machine_mode
, rtx
, struct constant_descriptor_rtx
*));
152 static struct constant_descriptor_rtx
* record_constant_rtx
153 PARAMS ((enum machine_mode
, rtx
));
154 static struct pool_constant
*find_pool_constant
PARAMS ((struct function
*, rtx
));
155 static void mark_constant_pool
PARAMS ((void));
156 static void mark_constants
PARAMS ((rtx
));
157 static int mark_constant
PARAMS ((rtx
*current_rtx
, void *data
));
158 static int output_addressed_constants
PARAMS ((tree
));
159 static unsigned HOST_WIDE_INT array_size_for_constructor
PARAMS ((tree
));
160 static unsigned min_align
PARAMS ((unsigned, unsigned));
161 static void output_constructor
PARAMS ((tree
, HOST_WIDE_INT
,
163 static void globalize_decl
PARAMS ((tree
));
164 static void maybe_assemble_visibility
PARAMS ((tree
));
165 static int in_named_entry_eq
PARAMS ((const PTR
, const PTR
));
166 static hashval_t in_named_entry_hash
PARAMS ((const PTR
));
167 #ifdef ASM_OUTPUT_BSS
168 static void asm_output_bss
PARAMS ((FILE *, tree
, const char *, int, int));
170 #ifdef BSS_SECTION_ASM_OP
171 #ifdef ASM_OUTPUT_ALIGNED_BSS
172 static void asm_output_aligned_bss
173 PARAMS ((FILE *, tree
, const char *, int, int)) ATTRIBUTE_UNUSED
;
175 #endif /* BSS_SECTION_ASM_OP */
176 static hashval_t const_str_htab_hash
PARAMS ((const void *x
));
177 static int const_str_htab_eq
PARAMS ((const void *x
, const void *y
));
178 static bool asm_emit_uninitialised
PARAMS ((tree
, const char*, int, int));
179 static void resolve_unique_section
PARAMS ((tree
, int, int));
180 static void mark_weak
PARAMS ((tree
));
182 enum in_section
{ no_section
, in_text
, in_data
, in_named
183 #ifdef BSS_SECTION_ASM_OP
186 #ifdef CTORS_SECTION_ASM_OP
189 #ifdef DTORS_SECTION_ASM_OP
192 #ifdef READONLY_DATA_SECTION_ASM_OP
195 #ifdef EXTRA_SECTIONS
199 static GTY(()) enum in_section in_section
= no_section
;
201 /* Return a nonzero value if DECL has a section attribute. */
202 #ifndef IN_NAMED_SECTION
203 #define IN_NAMED_SECTION(DECL) \
204 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
205 && DECL_SECTION_NAME (DECL) != NULL_TREE)
208 /* Text of section name when in_section == in_named. */
209 static GTY(()) const char *in_named_name
;
211 /* Hash table of flags that have been used for a particular named section. */
213 struct in_named_entry
GTY(())
220 static GTY((param_is (struct in_named_entry
))) htab_t in_named_htab
;
222 /* Define functions like text_section for any extra sections. */
223 #ifdef EXTRA_SECTION_FUNCTIONS
224 EXTRA_SECTION_FUNCTIONS
227 /* Tell assembler to switch to text section. */
232 if (in_section
!= in_text
)
234 in_section
= in_text
;
238 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
243 /* Tell assembler to switch to data section. */
248 if (in_section
!= in_data
)
250 in_section
= in_data
;
251 if (flag_shared_data
)
253 #ifdef SHARED_SECTION_ASM_OP
254 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
256 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
260 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
264 /* Tell assembler to switch to read-only data section. This is normally
268 readonly_data_section ()
270 #ifdef READONLY_DATA_SECTION
271 READONLY_DATA_SECTION (); /* Note this can call data_section. */
273 #ifdef READONLY_DATA_SECTION_ASM_OP
274 if (in_section
!= in_readonly_data
)
276 in_section
= in_readonly_data
;
277 fputs (READONLY_DATA_SECTION_ASM_OP
, asm_out_file
);
278 fputc ('\n', asm_out_file
);
286 /* Determine if we're in the text section. */
291 return in_section
== in_text
;
294 /* Determine if we're in the data section. */
299 return in_section
== in_data
;
302 /* Helper routines for maintaining in_named_htab. */
305 in_named_entry_eq (p1
, p2
)
309 const struct in_named_entry
*old
= p1
;
310 const char *new = p2
;
312 return strcmp (old
->name
, new) == 0;
316 in_named_entry_hash (p
)
319 const struct in_named_entry
*old
= p
;
320 return htab_hash_string (old
->name
);
323 /* If SECTION has been seen before as a named section, return the flags
324 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
325 set of flags for a section to have, so 0 does not mean that the section
326 has not been seen. */
329 get_named_section_flags (section
)
332 struct in_named_entry
**slot
;
334 slot
= (struct in_named_entry
**)
335 htab_find_slot_with_hash (in_named_htab
, section
,
336 htab_hash_string (section
), NO_INSERT
);
338 return slot
? (*slot
)->flags
: 0;
341 /* Returns true if the section has been declared before. Sets internal
342 flag on this section in in_named_hash so subsequent calls on this
343 section will return false. */
346 named_section_first_declaration (name
)
349 struct in_named_entry
**slot
;
351 slot
= (struct in_named_entry
**)
352 htab_find_slot_with_hash (in_named_htab
, name
,
353 htab_hash_string (name
), NO_INSERT
);
354 if (! (*slot
)->declared
)
356 (*slot
)->declared
= true;
366 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
367 different set of flags, return false. */
370 set_named_section_flags (section
, flags
)
374 struct in_named_entry
**slot
, *entry
;
376 slot
= (struct in_named_entry
**)
377 htab_find_slot_with_hash (in_named_htab
, section
,
378 htab_hash_string (section
), INSERT
);
383 entry
= (struct in_named_entry
*) ggc_alloc (sizeof (*entry
));
385 entry
->name
= ggc_strdup (section
);
386 entry
->flags
= flags
;
387 entry
->declared
= false;
389 else if (entry
->flags
!= flags
)
395 /* Tell assembler to change to section NAME with attributes FLAGS. */
398 named_section_flags (name
, flags
)
402 if (in_section
!= in_named
|| strcmp (name
, in_named_name
) != 0)
404 if (! set_named_section_flags (name
, flags
))
407 (*targetm
.asm_out
.named_section
) (name
, flags
);
409 if (flags
& SECTION_FORGET
)
410 in_section
= no_section
;
413 in_named_name
= ggc_strdup (name
);
414 in_section
= in_named
;
419 /* Tell assembler to change to section NAME for DECL.
420 If DECL is NULL, just switch to section NAME.
421 If NAME is NULL, get the name from DECL.
422 If RELOC is 1, the initializer for DECL contains relocs. */
425 named_section (decl
, name
, reloc
)
432 if (decl
!= NULL_TREE
&& !DECL_P (decl
))
435 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
437 flags
= (* targetm
.section_type_flags
) (decl
, name
, reloc
);
439 /* Sanity check user variables for flag changes. Non-user
440 section flag changes will abort in named_section_flags.
441 However, don't complain if SECTION_OVERRIDE is set.
442 We trust that the setter knows that it is safe to ignore
443 the default flags for this decl. */
444 if (decl
&& ! set_named_section_flags (name
, flags
))
446 flags
= get_named_section_flags (name
);
447 if ((flags
& SECTION_OVERRIDE
) == 0)
448 error_with_decl (decl
, "%s causes a section type conflict");
451 named_section_flags (name
, flags
);
454 /* If required, set DECL_SECTION_NAME to a unique name. */
457 resolve_unique_section (decl
, reloc
, flag_function_or_data_sections
)
459 int reloc ATTRIBUTE_UNUSED
;
460 int flag_function_or_data_sections
;
462 if (DECL_SECTION_NAME (decl
) == NULL_TREE
463 && targetm
.have_named_sections
464 && (flag_function_or_data_sections
465 || DECL_ONE_ONLY (decl
)))
466 (*targetm
.asm_out
.unique_section
) (decl
, reloc
);
469 #ifdef BSS_SECTION_ASM_OP
471 /* Tell the assembler to switch to the bss section. */
476 if (in_section
!= in_bss
)
478 #ifdef SHARED_BSS_SECTION_ASM_OP
479 if (flag_shared_data
)
480 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
483 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
489 #ifdef ASM_OUTPUT_BSS
491 /* Utility function for ASM_OUTPUT_BSS for targets to use if
492 they don't support alignments in .bss.
493 ??? It is believed that this function will work in most cases so such
494 support is localized here. */
497 asm_output_bss (file
, decl
, name
, size
, rounded
)
499 tree decl ATTRIBUTE_UNUSED
;
501 int size ATTRIBUTE_UNUSED
, rounded
;
503 (*targetm
.asm_out
.globalize_label
) (file
, name
);
505 #ifdef ASM_DECLARE_OBJECT_NAME
506 last_assemble_variable_decl
= decl
;
507 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
509 /* Standard thing is just output label for the object. */
510 ASM_OUTPUT_LABEL (file
, name
);
511 #endif /* ASM_DECLARE_OBJECT_NAME */
512 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
517 #ifdef ASM_OUTPUT_ALIGNED_BSS
519 /* Utility function for targets to use in implementing
520 ASM_OUTPUT_ALIGNED_BSS.
521 ??? It is believed that this function will work in most cases so such
522 support is localized here. */
525 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
527 tree decl ATTRIBUTE_UNUSED
;
532 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
533 #ifdef ASM_DECLARE_OBJECT_NAME
534 last_assemble_variable_decl
= decl
;
535 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
537 /* Standard thing is just output label for the object. */
538 ASM_OUTPUT_LABEL (file
, name
);
539 #endif /* ASM_DECLARE_OBJECT_NAME */
540 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
545 #endif /* BSS_SECTION_ASM_OP */
547 /* Switch to the section for function DECL.
549 If DECL is NULL_TREE, switch to the text section.
550 ??? It's not clear that we will ever be passed NULL_TREE, but it's
551 safer to handle it. */
554 function_section (decl
)
557 if (decl
!= NULL_TREE
558 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
559 named_section (decl
, (char *) 0, 0);
564 /* Switch to section for variable DECL. RELOC is the same as the
565 argument to SELECT_SECTION. */
568 variable_section (decl
, reloc
)
572 if (IN_NAMED_SECTION (decl
))
573 named_section (decl
, NULL
, reloc
);
575 (*targetm
.asm_out
.select_section
) (decl
, reloc
, DECL_ALIGN (decl
));
578 /* Tell assembler to switch to the section for string merging. */
581 mergeable_string_section (decl
, align
, flags
)
582 tree decl ATTRIBUTE_UNUSED
;
583 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
584 unsigned int flags ATTRIBUTE_UNUSED
;
586 #ifdef HAVE_GAS_SHF_MERGE
587 if (flag_merge_constants
588 && TREE_CODE (decl
) == STRING_CST
589 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
591 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
593 enum machine_mode mode
;
594 unsigned int modesize
;
599 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
600 modesize
= GET_MODE_BITSIZE (mode
);
601 if (modesize
>= 8 && modesize
<= 256
602 && (modesize
& (modesize
- 1)) == 0)
604 if (align
< modesize
)
607 str
= TREE_STRING_POINTER (decl
);
608 len
= TREE_STRING_LENGTH (decl
);
609 unit
= GET_MODE_SIZE (mode
);
611 /* Check for embedded NUL characters. */
612 for (i
= 0; i
< len
; i
+= unit
)
614 for (j
= 0; j
< unit
; j
++)
615 if (str
[i
+ j
] != '\0')
622 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
624 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
625 if (!i
&& modesize
< align
)
627 /* A "" string with requested alignment greater than
628 character size might cause a problem:
629 if some other string required even bigger
630 alignment than "", then linker might think the
631 "" is just part of padding after some other string
632 and not put it into the hash table initially.
633 But this means "" could have smaller alignment
635 #ifdef ASM_OUTPUT_SECTION_START
636 named_section_flags (name
, flags
);
637 ASM_OUTPUT_SECTION_START (asm_out_file
);
639 readonly_data_section ();
644 named_section_flags (name
, flags
);
650 readonly_data_section ();
653 /* Tell assembler to switch to the section for constant merging. */
656 mergeable_constant_section (mode
, align
, flags
)
657 enum machine_mode mode ATTRIBUTE_UNUSED
;
658 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
659 unsigned int flags ATTRIBUTE_UNUSED
;
661 #ifdef HAVE_GAS_SHF_MERGE
662 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
664 if (flag_merge_constants
670 && (align
& (align
- 1)) == 0)
674 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
675 flags
|= (align
/ 8) | SECTION_MERGE
;
676 named_section_flags (name
, flags
);
680 readonly_data_section ();
683 /* Given NAME, a putative register name, discard any customary prefixes. */
686 strip_reg_name (name
)
689 #ifdef REGISTER_PREFIX
690 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
691 name
+= strlen (REGISTER_PREFIX
);
693 if (name
[0] == '%' || name
[0] == '#')
698 /* Decode an `asm' spec for a declaration as a register name.
699 Return the register number, or -1 if nothing specified,
700 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
701 or -3 if ASMSPEC is `cc' and is not recognized,
702 or -4 if ASMSPEC is `memory' and is not recognized.
703 Accept an exact spelling or a decimal number.
704 Prefixes such as % are optional. */
707 decode_reg_name (asmspec
)
714 /* Get rid of confusing prefixes. */
715 asmspec
= strip_reg_name (asmspec
);
717 /* Allow a decimal number as a "register name". */
718 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
719 if (! ISDIGIT (asmspec
[i
]))
721 if (asmspec
[0] != 0 && i
< 0)
724 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
730 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
732 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
735 #ifdef ADDITIONAL_REGISTER_NAMES
737 static const struct { const char *const name
; const int number
; } table
[]
738 = ADDITIONAL_REGISTER_NAMES
;
740 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
741 if (! strcmp (asmspec
, table
[i
].name
))
742 return table
[i
].number
;
744 #endif /* ADDITIONAL_REGISTER_NAMES */
746 if (!strcmp (asmspec
, "memory"))
749 if (!strcmp (asmspec
, "cc"))
758 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
759 have static storage duration. In other words, it should not be an
760 automatic variable, including PARM_DECLs.
762 There is, however, one exception: this function handles variables
763 explicitly placed in a particular register by the user.
765 ASMSPEC, if not 0, is the string which the user specified as the
766 assembler symbol name.
768 This is never called for PARM_DECL nodes. */
771 make_decl_rtl (decl
, asmspec
)
775 int top_level
= (DECL_CONTEXT (decl
) == NULL_TREE
);
776 const char *name
= 0;
777 const char *new_name
= 0;
781 /* Check that we are not being given an automatic variable. */
782 /* A weak alias has TREE_PUBLIC set but not the other bits. */
783 if (TREE_CODE (decl
) == PARM_DECL
784 || TREE_CODE (decl
) == RESULT_DECL
785 || (TREE_CODE (decl
) == VAR_DECL
786 && !TREE_STATIC (decl
)
787 && !TREE_PUBLIC (decl
)
788 && !DECL_EXTERNAL (decl
)
789 && !DECL_REGISTER (decl
)))
791 /* And that we were not given a type or a label. */
792 else if (TREE_CODE (decl
) == TYPE_DECL
793 || TREE_CODE (decl
) == LABEL_DECL
)
796 /* For a duplicate declaration, we can be called twice on the
797 same DECL node. Don't discard the RTL already made. */
798 if (DECL_RTL_SET_P (decl
))
800 /* If the old RTL had the wrong mode, fix the mode. */
801 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
802 SET_DECL_RTL (decl
, adjust_address_nv (DECL_RTL (decl
),
803 DECL_MODE (decl
), 0));
805 /* ??? Another way to do this would be to maintain a hashed
806 table of such critters. Instead of adding stuff to a DECL
807 to give certain attributes to it, we could use an external
808 hash map from DECL to set of attributes. */
810 /* Let the target reassign the RTL if it wants.
811 This is necessary, for example, when one machine specific
812 decl attribute overrides another. */
813 (* targetm
.encode_section_info
) (decl
, DECL_RTL (decl
), false);
817 new_name
= name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
819 reg_number
= decode_reg_name (asmspec
);
820 if (reg_number
== -2)
822 /* ASMSPEC is given, and not the name of a register. Mark the
823 name with a star so assemble_name won't munge it. */
824 char *starred
= alloca (strlen (asmspec
) + 2);
826 strcpy (starred
+ 1, asmspec
);
830 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
832 /* First detect errors in declaring global registers. */
833 if (reg_number
== -1)
834 error_with_decl (decl
, "register name not specified for `%s'");
835 else if (reg_number
< 0)
836 error_with_decl (decl
, "invalid register name for `%s'");
837 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
838 error_with_decl (decl
,
839 "data type of `%s' isn't suitable for a register");
840 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
841 error_with_decl (decl
,
842 "register specified for `%s' isn't suitable for data type");
843 /* Now handle properly declared static register variables. */
848 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
850 DECL_INITIAL (decl
) = 0;
851 error ("global register variable has initial value");
853 if (TREE_THIS_VOLATILE (decl
))
854 warning ("volatile register variables don't work as you might wish");
856 /* If the user specified one of the eliminables registers here,
857 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
858 confused with that register and be eliminated. This usage is
859 somewhat suspect... */
861 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
862 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
863 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
865 if (TREE_STATIC (decl
))
867 /* Make this register global, so not usable for anything
869 #ifdef ASM_DECLARE_REGISTER_GLOBAL
870 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
872 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
874 globalize_reg (reg_number
+ --nregs
);
877 /* As a register variable, it has no section. */
882 /* Now handle ordinary static variables and functions (in memory).
883 Also handle vars declared register invalidly. */
885 if (reg_number
>= 0 || reg_number
== -3)
886 error_with_decl (decl
,
887 "register name given for non-register variable `%s'");
889 /* Specifying a section attribute on a variable forces it into a
890 non-.bss section, and thus it cannot be common. */
891 if (TREE_CODE (decl
) == VAR_DECL
892 && DECL_SECTION_NAME (decl
) != NULL_TREE
893 && DECL_INITIAL (decl
) == NULL_TREE
894 && DECL_COMMON (decl
))
895 DECL_COMMON (decl
) = 0;
897 /* Variables can't be both common and weak. */
898 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
899 DECL_COMMON (decl
) = 0;
901 /* Can't use just the variable's own name for a variable
902 whose scope is less than the whole file, unless it's a member
903 of a local class (which will already be unambiguous).
904 Concatenate a distinguishing number. */
905 if (!top_level
&& !TREE_PUBLIC (decl
)
906 && ! (DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
)))
908 && name
== IDENTIFIER_POINTER (DECL_NAME (decl
)))
912 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
917 if (name
!= new_name
)
919 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (new_name
));
920 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
923 x
= gen_rtx_SYMBOL_REF (Pmode
, name
);
924 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
925 SYMBOL_REF_DECL (x
) = decl
;
927 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
928 if (TREE_CODE (decl
) != FUNCTION_DECL
)
929 set_mem_attributes (x
, decl
, 1);
930 SET_DECL_RTL (decl
, x
);
932 /* Optionally set flags or add text to the name to record information
933 such as that it is a function name.
934 If the name is changed, the macro ASM_OUTPUT_LABELREF
935 will have to know how to strip this information. */
936 (* targetm
.encode_section_info
) (decl
, DECL_RTL (decl
), true);
939 /* Make the rtl for variable VAR be volatile.
940 Use this only for static variables. */
943 make_var_volatile (var
)
946 if (GET_CODE (DECL_RTL (var
)) != MEM
)
949 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
952 /* Output a string of literal assembler code
953 for an `asm' keyword used between functions. */
956 assemble_asm (string
)
961 if (TREE_CODE (string
) == ADDR_EXPR
)
962 string
= TREE_OPERAND (string
, 0);
964 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
967 /* Record an element in the table of global destructors. SYMBOL is
968 a SYMBOL_REF of the function to be called; PRIORITY is a number
969 between 0 and MAX_INIT_PRIORITY. */
972 default_stabs_asm_out_destructor (symbol
, priority
)
974 int priority ATTRIBUTE_UNUSED
;
976 /* Tell GNU LD that this is part of the static destructor set.
977 This will work for any system that uses stabs, most usefully
979 fprintf (asm_out_file
, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
980 assemble_name (asm_out_file
, XSTR (symbol
, 0));
981 fputc ('\n', asm_out_file
);
985 default_named_section_asm_out_destructor (symbol
, priority
)
989 const char *section
= ".dtors";
992 /* ??? This only works reliably with the GNU linker. */
993 if (priority
!= DEFAULT_INIT_PRIORITY
)
995 sprintf (buf
, ".dtors.%.5u",
996 /* Invert the numbering so the linker puts us in the proper
997 order; constructors are run from right to left, and the
998 linker sorts in increasing order. */
999 MAX_INIT_PRIORITY
- priority
);
1003 named_section_flags (section
, SECTION_WRITE
);
1004 assemble_align (POINTER_SIZE
);
1005 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1008 #ifdef DTORS_SECTION_ASM_OP
1012 if (in_section
!= in_dtors
)
1014 in_section
= in_dtors
;
1015 fputs (DTORS_SECTION_ASM_OP
, asm_out_file
);
1016 fputc ('\n', asm_out_file
);
1021 default_dtor_section_asm_out_destructor (symbol
, priority
)
1023 int priority ATTRIBUTE_UNUSED
;
1026 assemble_align (POINTER_SIZE
);
1027 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1031 /* Likewise for global constructors. */
1034 default_stabs_asm_out_constructor (symbol
, priority
)
1036 int priority ATTRIBUTE_UNUSED
;
1038 /* Tell GNU LD that this is part of the static destructor set.
1039 This will work for any system that uses stabs, most usefully
1041 fprintf (asm_out_file
, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1042 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1043 fputc ('\n', asm_out_file
);
1047 default_named_section_asm_out_constructor (symbol
, priority
)
1051 const char *section
= ".ctors";
1054 /* ??? This only works reliably with the GNU linker. */
1055 if (priority
!= DEFAULT_INIT_PRIORITY
)
1057 sprintf (buf
, ".ctors.%.5u",
1058 /* Invert the numbering so the linker puts us in the proper
1059 order; constructors are run from right to left, and the
1060 linker sorts in increasing order. */
1061 MAX_INIT_PRIORITY
- priority
);
1065 named_section_flags (section
, SECTION_WRITE
);
1066 assemble_align (POINTER_SIZE
);
1067 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1070 #ifdef CTORS_SECTION_ASM_OP
1074 if (in_section
!= in_ctors
)
1076 in_section
= in_ctors
;
1077 fputs (CTORS_SECTION_ASM_OP
, asm_out_file
);
1078 fputc ('\n', asm_out_file
);
1083 default_ctor_section_asm_out_constructor (symbol
, priority
)
1085 int priority ATTRIBUTE_UNUSED
;
1088 assemble_align (POINTER_SIZE
);
1089 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1093 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1094 a nonzero value if the constant pool should be output before the
1095 start of the function, or a zero value if the pool should output
1096 after the end of the function. The default is to put it before the
1099 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1100 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1103 /* Output assembler code for the constant pool of a function and associated
1104 with defining the name of the function. DECL describes the function.
1105 NAME is the function's name. For the constant pool, we use the current
1106 constant pool data. */
1109 assemble_start_function (decl
, fnname
)
1115 /* The following code does not need preprocessing in the assembler. */
1119 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1120 output_constant_pool (fnname
, decl
);
1122 resolve_unique_section (decl
, 0, flag_function_sections
);
1123 function_section (decl
);
1125 /* Tell assembler to move to target machine's alignment for functions. */
1126 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1127 if (align
< force_align_functions_log
)
1128 align
= force_align_functions_log
;
1131 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1134 /* Handle a user-specified function alignment.
1135 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1136 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1137 if (align_functions_log
> align
1138 && cfun
->function_frequency
!= FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
)
1140 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1141 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1142 align_functions_log
, align_functions
- 1);
1144 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1148 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1149 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1152 (*debug_hooks
->begin_function
) (decl
);
1154 /* Make function name accessible from other files, if appropriate. */
1156 if (TREE_PUBLIC (decl
))
1158 if (! first_global_object_name
)
1163 p
= (* targetm
.strip_name_encoding
) (fnname
);
1166 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1167 first_global_object_name
= name
;
1169 weak_global_object_name
= name
;
1172 globalize_decl (decl
);
1174 maybe_assemble_visibility (decl
);
1177 /* Do any machine/system dependent processing of the function name */
1178 #ifdef ASM_DECLARE_FUNCTION_NAME
1179 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1181 /* Standard thing is just output label for the function. */
1182 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1183 #endif /* ASM_DECLARE_FUNCTION_NAME */
1186 /* Output assembler code associated with defining the size of the
1187 function. DECL describes the function. NAME is the function's name. */
1190 assemble_end_function (decl
, fnname
)
1194 #ifdef ASM_DECLARE_FUNCTION_SIZE
1195 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1197 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1199 output_constant_pool (fnname
, decl
);
1200 function_section (decl
); /* need to switch back */
1204 /* Assemble code to leave SIZE bytes of zeros. */
1207 assemble_zeros (size
)
1210 /* Do no output if -fsyntax-only. */
1211 if (flag_syntax_only
)
1214 #ifdef ASM_NO_SKIP_IN_TEXT
1215 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1216 so we must output 0s explicitly in the text section. */
1217 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1220 for (i
= 0; i
< size
; i
++)
1221 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1226 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1229 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1232 assemble_align (align
)
1235 if (align
> BITS_PER_UNIT
)
1237 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1241 /* Assemble a string constant with the specified C string as contents. */
1244 assemble_string (p
, size
)
1251 /* If the string is very long, split it up. */
1255 int thissize
= size
- pos
;
1256 if (thissize
> maximum
)
1259 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1267 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1268 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1269 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1271 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1272 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1273 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1275 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1276 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1280 #if defined ASM_OUTPUT_ALIGNED_BSS
1281 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1282 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1284 #if defined ASM_OUTPUT_BSS
1285 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1286 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1292 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1293 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1294 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1296 #if defined ASM_OUTPUT_ALIGNED_COMMON
1297 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1298 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1300 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1301 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1306 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1309 int size ATTRIBUTE_UNUSED
;
1310 int rounded ATTRIBUTE_UNUSED
;
1318 destination
= asm_dest_local
;
1320 /* ??? We should handle .bss via select_section mechanisms rather than
1321 via special target hooks. That would eliminate this special case. */
1322 if (TREE_PUBLIC (decl
))
1324 if (!DECL_COMMON (decl
))
1326 destination
= asm_dest_bss
;
1331 destination
= asm_dest_common
;
1334 if (destination
== asm_dest_bss
)
1335 globalize_decl (decl
);
1336 resolve_unique_section (decl
, 0, flag_data_sections
);
1338 if (flag_shared_data
)
1340 switch (destination
)
1342 #ifdef ASM_OUTPUT_SHARED_BSS
1344 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1347 #ifdef ASM_OUTPUT_SHARED_COMMON
1348 case asm_dest_common
:
1349 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1352 #ifdef ASM_OUTPUT_SHARED_LOCAL
1353 case asm_dest_local
:
1354 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1362 switch (destination
)
1366 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1369 case asm_dest_common
:
1370 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1372 case asm_dest_local
:
1373 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1382 /* Assemble everything that is needed for a variable or function declaration.
1383 Not used for automatic variables, and not used for function definitions.
1384 Should not be called for variables of incomplete structure type.
1386 TOP_LEVEL is nonzero if this variable has file scope.
1387 AT_END is nonzero if this is the special handling, at end of compilation,
1388 to define things that have had only tentative definitions.
1389 DONT_OUTPUT_DATA if nonzero means don't actually output the
1390 initial value (that will be done by the caller). */
1393 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1395 int top_level ATTRIBUTE_UNUSED
;
1396 int at_end ATTRIBUTE_UNUSED
;
1397 int dont_output_data
;
1404 last_assemble_variable_decl
= 0;
1406 /* Normally no need to say anything here for external references,
1407 since assemble_external is called by the language-specific code
1408 when a declaration is first seen. */
1410 if (DECL_EXTERNAL (decl
))
1413 /* Output no assembler code for a function declaration.
1414 Only definitions of functions output anything. */
1416 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1419 /* Do nothing for global register variables. */
1420 if (DECL_RTL_SET_P (decl
) && GET_CODE (DECL_RTL (decl
)) == REG
)
1422 TREE_ASM_WRITTEN (decl
) = 1;
1426 /* If type was incomplete when the variable was declared,
1427 see if it is complete now. */
1429 if (DECL_SIZE (decl
) == 0)
1430 layout_decl (decl
, 0);
1432 /* Still incomplete => don't allocate it; treat the tentative defn
1433 (which is what it must have been) as an `extern' reference. */
1435 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1437 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1438 DECL_SOURCE_LINE (decl
),
1439 "storage size of `%s' isn't known",
1440 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1441 TREE_ASM_WRITTEN (decl
) = 1;
1445 /* The first declaration of a variable that comes through this function
1446 decides whether it is global (in C, has external linkage)
1447 or local (in C, has internal linkage). So do nothing more
1448 if this function has already run. */
1450 if (TREE_ASM_WRITTEN (decl
))
1453 /* Make sure targetm.encode_section_info is invoked before we set
1455 decl_rtl
= DECL_RTL (decl
);
1457 TREE_ASM_WRITTEN (decl
) = 1;
1459 /* Do no output if -fsyntax-only. */
1460 if (flag_syntax_only
)
1465 if (! dont_output_data
1466 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1468 error_with_decl (decl
, "size of variable `%s' is too large");
1472 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1473 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1474 && ! first_global_object_name
1475 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1476 || DECL_INITIAL (decl
) == error_mark_node
))
1477 && ! DECL_WEAK (decl
)
1478 && ! DECL_ONE_ONLY (decl
))
1483 p
= (* targetm
.strip_name_encoding
) (name
);
1484 xname
= xstrdup (p
);
1485 first_global_object_name
= xname
;
1488 /* Compute the alignment of this data. */
1490 align
= DECL_ALIGN (decl
);
1492 /* In the case for initialing an array whose length isn't specified,
1493 where we have not yet been able to do the layout,
1494 figure out the proper alignment now. */
1495 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1496 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1497 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1499 /* Some object file formats have a maximum alignment which they support.
1500 In particular, a.out format supports a maximum alignment of 4. */
1501 #ifndef MAX_OFILE_ALIGNMENT
1502 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1504 if (align
> MAX_OFILE_ALIGNMENT
)
1506 warning_with_decl (decl
,
1507 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1508 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1509 align
= MAX_OFILE_ALIGNMENT
;
1512 /* On some machines, it is good to increase alignment sometimes. */
1513 if (! DECL_USER_ALIGN (decl
))
1515 #ifdef DATA_ALIGNMENT
1516 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1518 #ifdef CONSTANT_ALIGNMENT
1519 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1520 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1524 /* Reset the alignment in case we have made it tighter, so we can benefit
1525 from it in get_pointer_alignment. */
1526 DECL_ALIGN (decl
) = align
;
1527 set_mem_align (decl_rtl
, align
);
1529 if (TREE_PUBLIC (decl
))
1530 maybe_assemble_visibility (decl
);
1532 /* Output any data that we will need to use the address of. */
1533 if (DECL_INITIAL (decl
) == error_mark_node
)
1534 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1535 else if (DECL_INITIAL (decl
))
1536 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1537 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1539 /* Handle uninitialized definitions. */
1541 /* If the decl has been given an explicit section name, then it
1542 isn't common, and shouldn't be handled as such. */
1543 if (DECL_SECTION_NAME (decl
) || dont_output_data
)
1545 /* We don't implement common thread-local data at present. */
1546 else if (DECL_THREAD_LOCAL (decl
))
1548 if (DECL_COMMON (decl
))
1549 sorry ("thread-local COMMON data not implemented");
1551 else if (DECL_INITIAL (decl
) == 0
1552 || DECL_INITIAL (decl
) == error_mark_node
1553 || (flag_zero_initialized_in_bss
1554 /* Leave constant zeroes in .rodata so they can be shared. */
1555 && !TREE_READONLY (decl
)
1556 && initializer_zerop (DECL_INITIAL (decl
))))
1558 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1559 unsigned HOST_WIDE_INT rounded
= size
;
1561 /* Don't allocate zero bytes of common,
1562 since that means "undefined external" in the linker. */
1566 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1567 so that each uninitialized object starts on such a boundary. */
1568 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1569 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1570 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1572 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1573 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN (decl
) / BITS_PER_UNIT
> rounded
)
1575 (decl
, "requested alignment for %s is greater than implemented alignment of %d",rounded
);
1578 /* If the target cannot output uninitialized but not common global data
1579 in .bss, then we have to use .data, so fall through. */
1580 if (asm_emit_uninitialised (decl
, name
, size
, rounded
))
1584 /* Handle initialized definitions.
1585 Also handle uninitialized global definitions if -fno-common and the
1586 target doesn't support ASM_OUTPUT_BSS. */
1588 /* First make the assembler name(s) global if appropriate. */
1589 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1590 globalize_decl (decl
);
1592 /* Switch to the appropriate section. */
1593 variable_section (decl
, reloc
);
1595 /* dbxout.c needs to know this. */
1596 if (in_text_section ())
1597 DECL_IN_TEXT_SECTION (decl
) = 1;
1599 /* Output the alignment of this data. */
1600 if (align
> BITS_PER_UNIT
)
1602 ASM_OUTPUT_ALIGN (asm_out_file
,
1603 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1606 /* Do any machine/system dependent processing of the object. */
1607 #ifdef ASM_DECLARE_OBJECT_NAME
1608 last_assemble_variable_decl
= decl
;
1609 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1611 /* Standard thing is just output label for the object. */
1612 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1613 #endif /* ASM_DECLARE_OBJECT_NAME */
1615 if (!dont_output_data
)
1617 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
1618 /* Output the actual data. */
1619 output_constant (DECL_INITIAL (decl
),
1620 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1623 /* Leave space for it. */
1624 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1628 /* Return 1 if type TYPE contains any pointers. */
1631 contains_pointers_p (type
)
1634 switch (TREE_CODE (type
))
1637 case REFERENCE_TYPE
:
1638 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1639 so I'll play safe and return 1. */
1645 case QUAL_UNION_TYPE
:
1648 /* For a type that has fields, see if the fields have pointers. */
1649 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1650 if (TREE_CODE (fields
) == FIELD_DECL
1651 && contains_pointers_p (TREE_TYPE (fields
)))
1657 /* An array type contains pointers if its element type does. */
1658 return contains_pointers_p (TREE_TYPE (type
));
1665 /* Output something to declare an external symbol to the assembler.
1666 (Most assemblers don't need this, so we normally output nothing.)
1667 Do nothing if DECL is not external. */
1670 assemble_external (decl
)
1671 tree decl ATTRIBUTE_UNUSED
;
1673 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1674 main body of this code is only rarely exercised. To provide some
1675 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1676 open. If it's not, we should not be calling this function. */
1680 #ifdef ASM_OUTPUT_EXTERNAL
1681 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1683 rtx rtl
= DECL_RTL (decl
);
1685 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1686 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1688 /* Some systems do require some output. */
1689 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1690 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1696 /* Similar, for calling a library function FUN. */
1699 assemble_external_libcall (fun
)
1700 rtx fun ATTRIBUTE_UNUSED
;
1702 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1703 /* Declare library function name external when first used, if nec. */
1704 if (! SYMBOL_REF_USED (fun
))
1706 SYMBOL_REF_USED (fun
) = 1;
1707 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1712 /* Assemble a label named NAME. */
1715 assemble_label (name
)
1718 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1721 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1722 If NAME starts with a *, the rest of NAME is output verbatim.
1723 Otherwise NAME is transformed in an implementation-defined way
1724 (usually by the addition of an underscore).
1725 Many macros in the tm file are defined to call this function. */
1728 assemble_name (file
, name
)
1732 const char *real_name
;
1735 real_name
= (* targetm
.strip_name_encoding
) (name
);
1737 id
= maybe_get_identifier (real_name
);
1739 TREE_SYMBOL_REFERENCED (id
) = 1;
1742 fputs (&name
[1], file
);
1744 ASM_OUTPUT_LABELREF (file
, name
);
1747 /* Allocate SIZE bytes writable static space with a gensym name
1748 and return an RTX to refer to its address. */
1751 assemble_static_space (size
)
1755 const char *namestring
;
1759 if (flag_shared_data
)
1763 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1765 namestring
= ggc_strdup (name
);
1767 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1768 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
1770 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1771 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1774 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1775 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1778 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1779 so that each uninitialized object starts on such a boundary. */
1780 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1781 int rounded ATTRIBUTE_UNUSED
1782 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1783 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1784 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1785 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1792 /* Assemble the static constant template for function entry trampolines.
1793 This is done at most once per compilation.
1794 Returns an RTX for the address of the template. */
1796 #ifdef TRAMPOLINE_TEMPLATE
1798 assemble_trampoline_template ()
1805 /* By default, put trampoline templates in read-only data section. */
1807 #ifdef TRAMPOLINE_SECTION
1808 TRAMPOLINE_SECTION ();
1810 readonly_data_section ();
1813 /* Write the assembler code to define one. */
1814 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1817 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1820 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "LTRAMP", 0);
1821 TRAMPOLINE_TEMPLATE (asm_out_file
);
1823 /* Record the rtl to refer to it. */
1824 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1825 name
= ggc_strdup (label
);
1826 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
1827 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
1833 /* A and B are either alignments or offsets. Return the minimum alignment
1834 that may be assumed after adding the two together. */
1836 static inline unsigned
1840 return (a
| b
) & -(a
| b
);
1843 /* Return the assembler directive for creating a given kind of integer
1844 object. SIZE is the number of bytes in the object and ALIGNED_P
1845 indicates whether it is known to be aligned. Return NULL if the
1846 assembly dialect has no such directive.
1848 The returned string should be printed at the start of a new line and
1849 be followed immediately by the object's initial value. */
1852 integer_asm_op (size
, aligned_p
)
1856 struct asm_int_op
*ops
;
1859 ops
= &targetm
.asm_out
.aligned_op
;
1861 ops
= &targetm
.asm_out
.unaligned_op
;
1866 return targetm
.asm_out
.byte_op
;
1880 /* Use directive OP to assemble an integer object X. Print OP at the
1881 start of the line, followed immediately by the value of X. */
1884 assemble_integer_with_op (op
, x
)
1888 fputs (op
, asm_out_file
);
1889 output_addr_const (asm_out_file
, x
);
1890 fputc ('\n', asm_out_file
);
1893 /* The default implementation of the asm_out.integer target hook. */
1896 default_assemble_integer (x
, size
, aligned_p
)
1897 rtx x ATTRIBUTE_UNUSED
;
1898 unsigned int size ATTRIBUTE_UNUSED
;
1899 int aligned_p ATTRIBUTE_UNUSED
;
1901 const char *op
= integer_asm_op (size
, aligned_p
);
1902 return op
&& (assemble_integer_with_op (op
, x
), true);
1905 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1906 the alignment of the integer in bits. Return 1 if we were able to output
1907 the constant, otherwise 0. If FORCE is nonzero, abort if we can't output
1911 assemble_integer (x
, size
, align
, force
)
1919 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
1921 /* See if the target hook can handle this kind of object. */
1922 if ((*targetm
.asm_out
.integer
) (x
, size
, aligned_p
))
1925 /* If the object is a multi-byte one, try splitting it up. Split
1926 it into words it if is multi-word, otherwise split it into bytes. */
1929 enum machine_mode omode
, imode
;
1930 unsigned int subalign
;
1931 unsigned int subsize
, i
;
1933 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
1934 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
1935 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
1936 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1938 for (i
= 0; i
< size
; i
+= subsize
)
1940 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
1941 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
1947 /* If we've printed some of it, but not all of it, there's no going
1960 assemble_real (d
, mode
, align
)
1962 enum machine_mode mode
;
1967 unsigned int nalign
= min_align (align
, 32);
1969 switch (BITS_PER_UNIT
)
1975 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
1976 assemble_integer (GEN_INT (l
), 4, align
, 1);
1979 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
1980 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
1981 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
1984 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d
, data
);
1985 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
1986 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
1987 assemble_integer (GEN_INT (data
[2]), 4, nalign
, 1);
1990 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d
, data
);
1991 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
1992 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
1993 assemble_integer (GEN_INT (data
[2]), 4, nalign
, 1);
1994 assemble_integer (GEN_INT (data
[3]), 4, nalign
, 1);
2005 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2006 assemble_integer (GEN_INT (l
), 2, align
, 1);
2009 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2010 assemble_integer (GEN_INT (data
[0]), 2, align
, 1);
2011 assemble_integer (GEN_INT (data
[1]), 1, nalign
, 1);
2022 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2023 assemble_integer (GEN_INT (l
), 1, align
, 1);
2026 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2027 assemble_integer (GEN_INT (data
[0]), 1, align
, 1);
2028 assemble_integer (GEN_INT (data
[1]), 1, nalign
, 1);
2040 /* Given an expression EXP with a constant value,
2041 reduce it to the sum of an assembler symbol and an integer.
2042 Store them both in the structure *VALUE.
2043 Abort if EXP does not reduce. */
2045 struct addr_const
GTY(())
2048 HOST_WIDE_INT offset
;
2052 decode_addr_const (exp
, value
)
2054 struct addr_const
*value
;
2056 tree target
= TREE_OPERAND (exp
, 0);
2062 if (TREE_CODE (target
) == COMPONENT_REF
2063 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2066 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2067 target
= TREE_OPERAND (target
, 0);
2069 else if (TREE_CODE (target
) == ARRAY_REF
2070 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2072 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2073 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2074 target
= TREE_OPERAND (target
, 0);
2080 switch (TREE_CODE (target
))
2084 x
= DECL_RTL (target
);
2088 x
= gen_rtx_MEM (FUNCTION_MODE
,
2089 gen_rtx_LABEL_REF (VOIDmode
,
2090 label_rtx (TREE_OPERAND (exp
, 0))));
2098 /* This constant should have been output already, but we can't simply
2099 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2100 x
= output_constant_def (target
, 1);
2107 if (GET_CODE (x
) != MEM
)
2112 value
->offset
= offset
;
2115 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2116 enum kind
{ RTX_UNKNOWN
, RTX_DOUBLE
, RTX_VECTOR
, RTX_INT
, RTX_UNSPEC
};
2117 struct rtx_const
GTY(())
2119 ENUM_BITFIELD(kind
) kind
: 16;
2120 ENUM_BITFIELD(machine_mode
) mode
: 16;
2121 union rtx_const_un
{
2122 REAL_VALUE_TYPE
GTY ((tag ("4"))) du
;
2123 struct rtx_const_u_addr
{
2126 HOST_WIDE_INT offset
;
2127 } GTY ((tag ("1"))) addr
;
2128 struct rtx_const_u_di
{
2131 } GTY ((tag ("0"))) di
;
2133 /* The max vector size we have is 16 wide; two variants for
2134 integral and floating point vectors. */
2135 struct rtx_const_int_vec
{
2138 } GTY ((tag ("2"))) int_vec
[16];
2140 REAL_VALUE_TYPE
GTY ((tag ("3"))) fp_vec
[8];
2142 } GTY ((desc ("%1.kind >= RTX_INT"), descbits ("1"))) un
;
2145 /* Uniquize all constants that appear in memory.
2146 Each constant in memory thus far output is recorded
2147 in `const_hash_table'. */
2149 struct constant_descriptor_tree
GTY(())
2151 /* More constant_descriptors with the same hash code. */
2152 struct constant_descriptor_tree
*next
;
2154 /* The label of the constant. */
2157 /* A MEM for the constant. */
2160 /* The value of the constant. */
2164 #define MAX_HASH_TABLE 1009
2165 static GTY(()) struct constant_descriptor_tree
*
2166 const_hash_table
[MAX_HASH_TABLE
];
2168 static struct constant_descriptor_tree
* build_constant_desc
PARAMS ((tree
));
2170 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2171 out a string constant, we defer output of the constants until we know
2172 they are actually used. This will be if something takes its address or if
2173 there is a usage of the string in the RTL of a function. */
2175 #define STRHASH(x) htab_hash_pointer (x)
2177 struct deferred_string
GTY(())
2183 static GTY ((param_is (struct deferred_string
))) htab_t const_str_htab
;
2185 /* Returns a hash code for X (which is a really a
2186 struct deferred_string *). */
2189 const_str_htab_hash (x
)
2192 return STRHASH (((const struct deferred_string
*) x
)->label
);
2195 /* Returns nonzero if the value represented by X (which is really a
2196 struct deferred_string *) is the same as that given by Y
2197 (which is really a char *). */
2200 const_str_htab_eq (x
, y
)
2204 return (((const struct deferred_string
*) x
)->label
== (const char *) y
);
2207 /* Compute a hash code for a constant expression. */
2213 return const_hash_1 (exp
) % MAX_HASH_TABLE
;
2223 enum tree_code code
= TREE_CODE (exp
);
2225 /* Either set P and LEN to the address and len of something to hash and
2226 exit the switch or return a value. */
2231 p
= (char *) &TREE_INT_CST (exp
);
2232 len
= sizeof TREE_INT_CST (exp
);
2236 return real_hash (TREE_REAL_CST_PTR (exp
));
2239 p
= TREE_STRING_POINTER (exp
);
2240 len
= TREE_STRING_LENGTH (exp
);
2244 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2245 + const_hash_1 (TREE_IMAGPART (exp
)));
2248 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2252 len
= int_size_in_bytes (TREE_TYPE (exp
));
2253 tmp
= (char *) alloca (len
);
2254 get_set_constructor_bytes (exp
, (unsigned char *) tmp
, len
);
2262 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2264 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2265 if (TREE_VALUE (link
))
2266 hi
= hi
* 603 + const_hash_1 (TREE_VALUE (link
));
2274 struct addr_const value
;
2276 decode_addr_const (exp
, &value
);
2277 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2279 /* Don't hash the address of the SYMBOL_REF;
2280 only use the offset and the symbol name. */
2282 p
= XSTR (value
.base
, 0);
2283 for (i
= 0; p
[i
] != 0; i
++)
2284 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2286 else if (GET_CODE (value
.base
) == LABEL_REF
)
2287 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2295 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
2296 + const_hash_1 (TREE_OPERAND (exp
, 1)));
2300 case NON_LVALUE_EXPR
:
2301 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
2304 /* A language specific constant. Just hash the code. */
2308 /* Compute hashing function */
2310 for (i
= 0; i
< len
; i
++)
2311 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2316 /* Compare t1 and t2, and return 1 only if they are known to result in
2317 the same bit pattern on output. */
2320 compare_constant (t1
, t2
)
2324 enum tree_code typecode
;
2326 if (t1
== NULL_TREE
)
2327 return t2
== NULL_TREE
;
2328 if (t2
== NULL_TREE
)
2331 if (TREE_CODE (t1
) != TREE_CODE (t2
))
2334 switch (TREE_CODE (t1
))
2337 /* Integer constants are the same only if the same width of type. */
2338 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2340 return tree_int_cst_equal (t1
, t2
);
2343 /* Real constants are the same only if the same width of type. */
2344 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
2347 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
2350 if (flag_writable_strings
)
2353 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
2356 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
2357 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
2358 TREE_STRING_LENGTH (t1
)));
2361 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
2362 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
2365 typecode
= TREE_CODE (TREE_TYPE (t1
));
2366 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
2369 if (typecode
== SET_TYPE
)
2371 int len
= int_size_in_bytes (TREE_TYPE (t2
));
2372 unsigned char *tmp1
, *tmp2
;
2374 if (int_size_in_bytes (TREE_TYPE (t1
)) != len
)
2377 tmp1
= (unsigned char *) alloca (len
);
2378 tmp2
= (unsigned char *) alloca (len
);
2380 if (get_set_constructor_bytes (t1
, tmp1
, len
) != NULL_TREE
)
2382 if (get_set_constructor_bytes (t2
, tmp2
, len
) != NULL_TREE
)
2385 return memcmp (tmp1
, tmp2
, len
) != 0;
2391 if (typecode
== ARRAY_TYPE
)
2393 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
2394 /* For arrays, check that the sizes all match. */
2395 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
2397 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
2402 /* For record and union constructors, require exact type
2404 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
2408 for (l1
= CONSTRUCTOR_ELTS (t1
), l2
= CONSTRUCTOR_ELTS (t2
);
2410 l1
= TREE_CHAIN (l1
), l2
= TREE_CHAIN (l2
))
2412 /* Check that each value is the same... */
2413 if (! compare_constant (TREE_VALUE (l1
), TREE_VALUE (l2
)))
2415 /* ... and that they apply to the same fields! */
2416 if (typecode
== ARRAY_TYPE
)
2418 if (! compare_constant (TREE_PURPOSE (l1
),
2424 if (TREE_PURPOSE (l1
) != TREE_PURPOSE (l2
))
2429 return l1
== NULL_TREE
&& l2
== NULL_TREE
;
2435 struct addr_const value1
, value2
;
2437 decode_addr_const (t1
, &value1
);
2438 decode_addr_const (t2
, &value2
);
2439 return (value1
.offset
== value2
.offset
2440 && strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
2446 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
2447 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
2451 case NON_LVALUE_EXPR
:
2452 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
2457 nt1
= (*lang_hooks
.expand_constant
) (t1
);
2458 nt2
= (*lang_hooks
.expand_constant
) (t2
);
2459 if (nt1
!= t1
|| nt2
!= t2
)
2460 return compare_constant (nt1
, nt2
);
2466 /* Should not get here. */
2470 /* Make a copy of the whole tree structure for a constant. This
2471 handles the same types of nodes that compare_constant handles. */
2477 switch (TREE_CODE (exp
))
2480 /* For ADDR_EXPR, we do not want to copy the decl whose address
2481 is requested. We do want to copy constants though. */
2482 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2483 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2484 copy_constant (TREE_OPERAND (exp
, 0)));
2486 return copy_node (exp
);
2491 return copy_node (exp
);
2494 return build_complex (TREE_TYPE (exp
),
2495 copy_constant (TREE_REALPART (exp
)),
2496 copy_constant (TREE_IMAGPART (exp
)));
2500 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2501 copy_constant (TREE_OPERAND (exp
, 0)),
2502 copy_constant (TREE_OPERAND (exp
, 1)));
2506 case NON_LVALUE_EXPR
:
2507 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2508 copy_constant (TREE_OPERAND (exp
, 0)));
2512 tree copy
= copy_node (exp
);
2513 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2516 CONSTRUCTOR_ELTS (copy
) = list
;
2517 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2518 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2519 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2520 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2521 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
2529 t
= (*lang_hooks
.expand_constant
) (exp
);
2531 return copy_constant (t
);
2538 /* Subroutine of output_constant_def:
2539 No constant equal to EXP is known to have been output.
2540 Make a constant descriptor to enter EXP in the hash table.
2541 Assign the label number and construct RTL to refer to the
2542 constant's location in memory.
2543 Caller is responsible for updating the hash table. */
2545 static struct constant_descriptor_tree
*
2546 build_constant_desc (exp
)
2553 struct constant_descriptor_tree
*desc
;
2555 desc
= ggc_alloc (sizeof (*desc
));
2556 desc
->value
= copy_constant (exp
);
2558 /* Create a string containing the label name, in LABEL. */
2559 labelno
= const_labelno
++;
2560 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
2562 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2563 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
2564 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2566 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
2567 set_mem_attributes (rtl
, exp
, 1);
2568 set_mem_alias_set (rtl
, 0);
2569 set_mem_alias_set (rtl
, const_alias_set
);
2571 /* Set flags or add text to the name to record information, such as
2572 that it is a local symbol. If the name is changed, the macro
2573 ASM_OUTPUT_LABELREF will have to know how to strip this
2575 (*targetm
.encode_section_info
) (exp
, rtl
, true);
2578 desc
->label
= XSTR (XEXP (desc
->rtl
, 0), 0);
2583 /* Return an rtx representing a reference to constant data in memory
2584 for the constant expression EXP.
2586 If assembler code for such a constant has already been output,
2587 return an rtx to refer to it.
2588 Otherwise, output such a constant in memory
2589 and generate an rtx for it.
2591 If DEFER is nonzero, the output of string constants can be deferred
2592 and output only if referenced in the function after all optimizations.
2594 The TREE_CST_RTL of EXP is set up to point to that rtx.
2595 The const_hash_table records which constants already have label strings. */
2598 output_constant_def (exp
, defer
)
2603 struct constant_descriptor_tree
*desc
;
2605 /* We can't just use the saved RTL if this is a deferred string constant
2606 and we are not to defer anymore. */
2607 if (TREE_CODE (exp
) != INTEGER_CST
&& TREE_CST_RTL (exp
)
2608 && (defer
|| !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp
), 0))))
2609 return TREE_CST_RTL (exp
);
2611 /* Compute hash code of EXP. Search the descriptors for that hash code
2612 to see if any of them describes EXP. If yes, the descriptor records
2613 the label number already assigned. */
2615 hash
= const_hash (exp
);
2616 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
2617 if (compare_constant (exp
, desc
->value
))
2622 desc
= build_constant_desc (exp
);
2623 desc
->next
= const_hash_table
[hash
];
2624 const_hash_table
[hash
] = desc
;
2626 maybe_output_constant_def_contents (exp
, desc
->rtl
, defer
);
2628 else if (!defer
&& STRING_POOL_ADDRESS_P (XEXP (desc
->rtl
, 0)))
2630 /* If the string is currently deferred but we need to output it
2631 now, remove it from the deferred string hash table. */
2632 struct deferred_string
**defstr
;
2634 defstr
= (struct deferred_string
**)
2635 htab_find_slot_with_hash (const_str_htab
, desc
->label
,
2636 STRHASH (desc
->label
), NO_INSERT
);
2637 #ifdef ENABLE_CHECKING
2642 STRING_POOL_ADDRESS_P (XEXP (desc
->rtl
, 0)) = 0;
2643 htab_clear_slot (const_str_htab
, (void **) defstr
);
2644 maybe_output_constant_def_contents (exp
, desc
->rtl
, 0);
2647 TREE_CST_RTL (exp
) = desc
->rtl
;
2651 /* Subroutine of output_constant_def:
2652 Decide whether or not to defer the output of EXP, which can be
2653 accesed through rtl RTL, and either do the output or record EXP in
2654 the table of deferred strings. */
2656 maybe_output_constant_def_contents (exp
, rtl
, defer
)
2663 if (flag_syntax_only
)
2666 label
= XSTR (XEXP (rtl
, 0), 0);
2668 if (defer
&& TREE_CODE (exp
) == STRING_CST
&& !flag_writable_strings
)
2670 struct deferred_string
**defstr
;
2671 defstr
= (struct deferred_string
**)
2672 htab_find_slot_with_hash (const_str_htab
, label
,
2673 STRHASH (label
), INSERT
);
2676 struct deferred_string
*p
;
2678 p
= (struct deferred_string
*)
2679 ggc_alloc (sizeof (struct deferred_string
));
2685 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 1;
2690 output_constant_def_contents (exp
, label
);
2693 /* Now output assembler code to define the label for EXP,
2694 and follow it with the data of EXP. */
2697 output_constant_def_contents (exp
, label
)
2701 /* Make sure any other constants whose addresses appear in EXP
2702 are assigned label numbers. */
2703 int reloc
= output_addressed_constants (exp
);
2705 /* Align the location counter as required by EXP's data type. */
2706 int align
= TYPE_ALIGN (TREE_TYPE (exp
));
2707 #ifdef CONSTANT_ALIGNMENT
2708 align
= CONSTANT_ALIGNMENT (exp
, align
);
2711 if (IN_NAMED_SECTION (exp
))
2712 named_section (exp
, NULL
, reloc
);
2714 (*targetm
.asm_out
.select_section
) (exp
, reloc
, align
);
2716 if (align
> BITS_PER_UNIT
)
2718 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
2721 /* Output the label itself. */
2722 ASM_OUTPUT_LABEL (asm_out_file
, label
);
2724 /* Output the value of EXP. */
2725 output_constant (exp
,
2726 (TREE_CODE (exp
) == STRING_CST
2727 ? MAX (TREE_STRING_LENGTH (exp
),
2728 int_size_in_bytes (TREE_TYPE (exp
)))
2729 : int_size_in_bytes (TREE_TYPE (exp
))),
2734 /* Used in the hash tables to avoid outputting the same constant
2735 twice. Unlike 'struct constant_descriptor_tree', RTX constants
2736 are output once per function, not once per file; there seems
2737 to be no reason for the difference. */
2739 struct constant_descriptor_rtx
GTY(())
2741 /* More constant_descriptors with the same hash code. */
2742 struct constant_descriptor_rtx
*next
;
2744 /* A MEM for the constant. */
2747 /* The value of the constant. */
2748 struct rtx_const value
;
2751 /* Structure to represent sufficient information about a constant so that
2752 it can be output when the constant pool is output, so that function
2753 integration can be done, and to simplify handling on machines that reference
2754 constant pool as base+displacement. */
2756 struct pool_constant
GTY(())
2758 struct constant_descriptor_rtx
*desc
;
2759 struct pool_constant
*next
;
2760 struct pool_constant
*next_sym
;
2762 enum machine_mode mode
;
2765 HOST_WIDE_INT offset
;
2769 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2770 The argument is XSTR (... , 0) */
2772 #define SYMHASH(LABEL) (((unsigned long) (LABEL)) % MAX_RTX_HASH_TABLE)
2774 /* Initialize constant pool hashing for a new function. */
2777 init_varasm_status (f
)
2780 struct varasm_status
*p
;
2781 p
= (struct varasm_status
*) ggc_alloc (sizeof (struct varasm_status
));
2783 p
->x_const_rtx_hash_table
2784 = ((struct constant_descriptor_rtx
**)
2785 ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2786 * sizeof (struct constant_descriptor_rtx
*)));
2787 p
->x_const_rtx_sym_hash_table
2788 = ((struct pool_constant
**)
2789 ggc_alloc_cleared (MAX_RTX_HASH_TABLE
2790 * sizeof (struct pool_constant
*)));
2792 p
->x_first_pool
= p
->x_last_pool
= 0;
2793 p
->x_pool_offset
= 0;
2797 /* Express an rtx for a constant integer (perhaps symbolic)
2798 as the sum of a symbol or label plus an explicit integer.
2799 They are stored into VALUE. */
2802 decode_rtx_const (mode
, x
, value
)
2803 enum machine_mode mode
;
2805 struct rtx_const
*value
;
2807 /* Clear the whole structure, including any gaps. */
2808 memset (value
, 0, sizeof (struct rtx_const
));
2810 value
->kind
= RTX_INT
; /* Most usual kind. */
2813 switch (GET_CODE (x
))
2816 value
->kind
= RTX_DOUBLE
;
2817 if (GET_MODE (x
) != VOIDmode
)
2819 const REAL_VALUE_TYPE
*r
= CONST_DOUBLE_REAL_VALUE (x
);
2821 value
->mode
= GET_MODE (x
);
2823 /* Copy the REAL_VALUE_TYPE by members so that we don't
2824 copy garbage from the original structure into our
2825 carefully cleaned hashing structure. */
2826 value
->un
.du
.class = r
->class;
2827 value
->un
.du
.sign
= r
->sign
;
2834 value
->un
.du
.exp
= r
->exp
;
2837 memcpy (value
->un
.du
.sig
, r
->sig
, sizeof (r
->sig
));
2845 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
2846 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
2854 units
= CONST_VECTOR_NUNITS (x
);
2855 value
->kind
= RTX_VECTOR
;
2858 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
2860 for (i
= 0; i
< units
; ++i
)
2862 rtx elt
= CONST_VECTOR_ELT (x
, i
);
2863 if (GET_CODE (elt
) == CONST_INT
)
2865 value
->un
.int_vec
[i
].low
= INTVAL (elt
);
2866 value
->un
.int_vec
[i
].high
= 0;
2870 value
->un
.int_vec
[i
].low
= CONST_DOUBLE_LOW (elt
);
2871 value
->un
.int_vec
[i
].high
= CONST_DOUBLE_HIGH (elt
);
2875 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
2877 for (i
= 0; i
< units
; ++i
)
2879 const REAL_VALUE_TYPE
*r
2880 = CONST_DOUBLE_REAL_VALUE (CONST_VECTOR_ELT (x
, i
));
2881 REAL_VALUE_TYPE
*d
= &value
->un
.fp_vec
[i
];
2883 /* Copy the REAL_VALUE_TYPE by members so that we don't
2884 copy garbage from the original structure into our
2885 carefully cleaned hashing structure. */
2886 d
->class = r
->class;
2897 memcpy (d
->sig
, r
->sig
, sizeof (r
->sig
));
2910 value
->un
.addr
.offset
= INTVAL (x
);
2916 value
->un
.addr
.base
= x
;
2921 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
2923 value
->un
.addr
.base
= XEXP (x
, 0);
2924 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
2926 else if (GET_CODE (x
) == MINUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
2928 value
->un
.addr
.base
= XEXP (x
, 0);
2929 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
2933 value
->un
.addr
.base
= x
;
2934 value
->un
.addr
.offset
= 0;
2939 value
->kind
= RTX_UNKNOWN
;
2943 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0
2944 && GET_CODE (value
->un
.addr
.base
) == UNSPEC
)
2946 /* For a simple UNSPEC, the base is set to the
2947 operand, the kind field is set to the index of
2948 the unspec expression.
2949 Together with the code below, in case that
2950 the operand is a SYMBOL_REF or LABEL_REF,
2951 the address of the string or the code_label
2952 is taken as base. */
2953 if (XVECLEN (value
->un
.addr
.base
, 0) == 1)
2955 value
->kind
= RTX_UNSPEC
+ XINT (value
->un
.addr
.base
, 1);
2956 value
->un
.addr
.base
= XVECEXP (value
->un
.addr
.base
, 0, 0);
2960 if (value
->kind
>= RTX_INT
&& value
->un
.addr
.base
!= 0)
2961 switch (GET_CODE (value
->un
.addr
.base
))
2964 /* Use the string's address, not the SYMBOL_REF's address,
2965 for the sake of addresses of library routines. */
2966 value
->un
.addr
.symbol
= XSTR (value
->un
.addr
.base
, 0);
2967 value
->un
.addr
.base
= NULL_RTX
;
2971 /* For a LABEL_REF, compare labels. */
2972 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
2979 /* Given a MINUS expression, simplify it if both sides
2980 include the same symbol. */
2983 simplify_subtraction (x
)
2986 struct rtx_const val0
, val1
;
2988 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
2989 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
2991 if (val0
.kind
>= RTX_INT
2992 && val0
.kind
== val1
.kind
2993 && val0
.un
.addr
.base
== val1
.un
.addr
.base
2994 && val0
.un
.addr
.symbol
== val1
.un
.addr
.symbol
)
2995 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3000 /* Compute a hash code for a constant RTL expression. */
3003 const_hash_rtx (mode
, x
)
3004 enum machine_mode mode
;
3008 struct rtx_const value
;
3009 unsigned int data
[sizeof(struct rtx_const
) / sizeof (unsigned int)];
3015 decode_rtx_const (mode
, x
, &u
.value
);
3017 /* Compute hashing function */
3019 for (i
= 0; i
< ARRAY_SIZE (u
.data
); i
++)
3020 hi
= hi
* 613 + u
.data
[i
];
3022 return hi
% MAX_RTX_HASH_TABLE
;
3025 /* Compare a constant rtl object X with a constant-descriptor DESC.
3026 Return 1 if DESC describes a constant with the same value as X. */
3029 compare_constant_rtx (mode
, x
, desc
)
3030 enum machine_mode mode
;
3032 struct constant_descriptor_rtx
*desc
;
3034 struct rtx_const value
;
3036 decode_rtx_const (mode
, x
, &value
);
3038 /* Compare constant contents. */
3039 return memcmp (&value
, &desc
->value
, sizeof (struct rtx_const
)) == 0;
3042 /* Construct a constant descriptor for the rtl-expression X.
3043 It is up to the caller to enter the descriptor in the hash table. */
3045 static struct constant_descriptor_rtx
*
3046 record_constant_rtx (mode
, x
)
3047 enum machine_mode mode
;
3050 struct constant_descriptor_rtx
*ptr
;
3052 ptr
= (struct constant_descriptor_rtx
*) ggc_alloc (sizeof (*ptr
));
3053 decode_rtx_const (mode
, x
, &ptr
->value
);
3058 /* Given a constant rtx X, return a MEM for the location in memory at which
3059 this constant has been placed. Return 0 if it not has been placed yet. */
3062 mem_for_const_double (x
)
3065 enum machine_mode mode
= GET_MODE (x
);
3066 struct constant_descriptor_rtx
*desc
;
3068 for (desc
= const_rtx_hash_table
[const_hash_rtx (mode
, x
)]; desc
;
3070 if (compare_constant_rtx (mode
, x
, desc
))
3076 /* Given a constant rtx X, make (or find) a memory constant for its value
3077 and return a MEM rtx to refer to it in memory. */
3080 force_const_mem (mode
, x
)
3081 enum machine_mode mode
;
3085 struct constant_descriptor_rtx
*desc
;
3088 struct pool_constant
*pool
;
3091 /* If we're not allowed to drop X into the constant pool, don't. */
3092 if ((*targetm
.cannot_force_const_mem
) (x
))
3095 /* Compute hash code of X. Search the descriptors for that hash code
3096 to see if any of them describes X. If yes, we have an rtx to use. */
3097 hash
= const_hash_rtx (mode
, x
);
3098 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3099 if (compare_constant_rtx (mode
, x
, desc
))
3102 /* No constant equal to X is known to have been output.
3103 Make a constant descriptor to enter X in the hash table
3104 and make a MEM for it. */
3105 desc
= record_constant_rtx (mode
, x
);
3106 desc
->next
= const_rtx_hash_table
[hash
];
3107 const_rtx_hash_table
[hash
] = desc
;
3109 /* Align the location counter as required by EXP's data type. */
3110 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3111 #ifdef CONSTANT_ALIGNMENT
3112 align
= CONSTANT_ALIGNMENT (make_tree ((*lang_hooks
.types
.type_for_mode
)
3113 (mode
, 0), x
), align
);
3116 pool_offset
+= (align
/ BITS_PER_UNIT
) - 1;
3117 pool_offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3119 if (GET_CODE (x
) == LABEL_REF
)
3120 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3122 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3123 pool
= (struct pool_constant
*) ggc_alloc (sizeof (struct pool_constant
));
3127 pool
->labelno
= const_labelno
;
3128 pool
->align
= align
;
3129 pool
->offset
= pool_offset
;
3136 last_pool
->next
= pool
;
3139 pool_offset
+= GET_MODE_SIZE (mode
);
3141 /* Create a string containing the label name, in LABEL. */
3142 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3146 /* Construct the SYMBOL_REF and the MEM. */
3148 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3149 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
3151 pool
->desc
->rtl
= def
= gen_rtx_MEM (mode
, symbol
);
3152 set_mem_attributes (def
, (*lang_hooks
.types
.type_for_mode
) (mode
, 0), 1);
3153 RTX_UNCHANGING_P (def
) = 1;
3155 /* Add label to symbol hash table. */
3156 hash
= SYMHASH (XSTR (symbol
, 0));
3157 pool
->next_sym
= const_rtx_sym_hash_table
[hash
];
3158 const_rtx_sym_hash_table
[hash
] = pool
;
3160 /* Mark the symbol_ref as belonging to this constants pool. */
3161 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3162 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
3163 current_function_uses_const_pool
= 1;
3168 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3169 the corresponding pool_constant structure. */
3171 static struct pool_constant
*
3172 find_pool_constant (f
, addr
)
3176 struct pool_constant
*pool
;
3177 const char *label
= XSTR (addr
, 0);
3179 for (pool
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; pool
;
3180 pool
= pool
->next_sym
)
3181 if (XSTR (XEXP (pool
->desc
->rtl
, 0), 0) == label
)
3187 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3190 get_pool_constant (addr
)
3193 return (find_pool_constant (cfun
, addr
))->constant
;
3196 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3197 and whether it has been output or not. */
3200 get_pool_constant_mark (addr
, pmarked
)
3204 struct pool_constant
*pool
= find_pool_constant (cfun
, addr
);
3205 *pmarked
= (pool
->mark
!= 0);
3206 return pool
->constant
;
3209 /* Likewise, but for the constant pool of a specific function. */
3212 get_pool_constant_for_function (f
, addr
)
3216 return (find_pool_constant (f
, addr
))->constant
;
3219 /* Similar, return the mode. */
3222 get_pool_mode (addr
)
3225 return (find_pool_constant (cfun
, addr
))->mode
;
3229 get_pool_mode_for_function (f
, addr
)
3233 return (find_pool_constant (f
, addr
))->mode
;
3236 /* Similar, return the offset in the constant pool. */
3239 get_pool_offset (addr
)
3242 return (find_pool_constant (cfun
, addr
))->offset
;
3245 /* Return the size of the constant pool. */
3253 /* Write all the constants in the constant pool. */
3256 output_constant_pool (fnname
, fndecl
)
3257 const char *fnname ATTRIBUTE_UNUSED
;
3258 tree fndecl ATTRIBUTE_UNUSED
;
3260 struct pool_constant
*pool
;
3264 /* It is possible for gcc to call force_const_mem and then to later
3265 discard the instructions which refer to the constant. In such a
3266 case we do not need to output the constant. */
3267 mark_constant_pool ();
3269 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3270 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3273 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3282 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3283 whose CODE_LABEL has been deleted. This can occur if a jump table
3284 is eliminated by optimization. If so, write a constant of zero
3285 instead. Note that this can also happen by turning the
3286 CODE_LABEL into a NOTE. */
3287 /* ??? This seems completely and utterly wrong. Certainly it's
3288 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3289 functioning even with INSN_DELETED_P and friends. */
3292 switch (GET_CODE (x
))
3295 if (GET_CODE (XEXP (x
, 0)) != PLUS
3296 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3298 tmp
= XEXP (XEXP (x
, 0), 0);
3303 if (INSN_DELETED_P (tmp
)
3304 || (GET_CODE (tmp
) == NOTE
3305 && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_DELETED
))
3316 /* First switch to correct section. */
3317 (*targetm
.asm_out
.select_rtx_section
) (pool
->mode
, x
, pool
->align
);
3319 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3320 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3321 pool
->align
, pool
->labelno
, done
);
3324 assemble_align (pool
->align
);
3326 /* Output the label. */
3327 (*targetm
.asm_out
.internal_label
) (asm_out_file
, "LC", pool
->labelno
);
3329 /* Output the value of the constant itself. */
3330 switch (GET_MODE_CLASS (pool
->mode
))
3333 if (GET_CODE (x
) != CONST_DOUBLE
)
3336 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3337 assemble_real (r
, pool
->mode
, pool
->align
);
3341 case MODE_PARTIAL_INT
:
3342 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), pool
->align
, 1);
3345 case MODE_VECTOR_FLOAT
:
3350 if (GET_CODE (x
) != CONST_VECTOR
)
3353 units
= CONST_VECTOR_NUNITS (x
);
3355 for (i
= 0; i
< units
; i
++)
3357 elt
= CONST_VECTOR_ELT (x
, i
);
3358 REAL_VALUE_FROM_CONST_DOUBLE (r
, elt
);
3359 assemble_real (r
, GET_MODE_INNER (pool
->mode
), pool
->align
);
3364 case MODE_VECTOR_INT
:
3369 if (GET_CODE (x
) != CONST_VECTOR
)
3372 units
= CONST_VECTOR_NUNITS (x
);
3374 for (i
= 0; i
< units
; i
++)
3376 elt
= CONST_VECTOR_ELT (x
, i
);
3377 assemble_integer (elt
, GET_MODE_UNIT_SIZE (pool
->mode
),
3387 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
3388 sections have proper size. */
3389 if (pool
->align
> GET_MODE_BITSIZE (pool
->mode
)
3390 && in_section
== in_named
3391 && get_named_section_flags (in_named_name
) & SECTION_MERGE
)
3392 assemble_align (pool
->align
);
3394 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3399 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3400 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3403 /* Done with this pool. */
3404 first_pool
= last_pool
= 0;
3407 /* Look through the instructions for this function, and mark all the
3408 entries in the constant pool which are actually being used.
3409 Emit used deferred strings. */
3412 mark_constant_pool ()
3416 struct pool_constant
*pool
;
3418 if (first_pool
== 0 && htab_elements (const_str_htab
) == 0)
3421 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3424 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3426 mark_constants (PATTERN (insn
));
3428 for (link
= current_function_epilogue_delay_list
;
3430 link
= XEXP (link
, 1))
3432 insn
= XEXP (link
, 0);
3435 mark_constants (PATTERN (insn
));
3439 /* Look through appropriate parts of X, marking all entries in the
3440 constant pool which are actually being used. Entries that are only
3441 referenced by other constants are also marked as used. Emit
3442 deferred strings that are used. */
3449 const char *format_ptr
;
3454 if (GET_CODE (x
) == SYMBOL_REF
)
3456 mark_constant (&x
, NULL
);
3460 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3461 insns, not any notes that may be attached. We don't want to mark
3462 a constant just because it happens to appear in a REG_EQUIV note. */
3465 mark_constants (PATTERN (x
));
3469 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3471 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3473 switch (*format_ptr
++)
3476 mark_constants (XEXP (x
, i
));
3480 if (XVEC (x
, i
) != 0)
3484 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3485 mark_constants (XVECEXP (x
, i
, j
));
3505 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3506 to as used. Emit referenced deferred strings. This function can
3507 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3510 mark_constant (current_rtx
, data
)
3512 void *data ATTRIBUTE_UNUSED
;
3514 rtx x
= *current_rtx
;
3519 else if (GET_CODE (x
) == SYMBOL_REF
)
3521 if (CONSTANT_POOL_ADDRESS_P (x
))
3523 struct pool_constant
*pool
= find_pool_constant (cfun
, x
);
3524 if (pool
->mark
== 0)
3527 for_each_rtx (&(pool
->constant
), &mark_constant
, NULL
);
3532 else if (STRING_POOL_ADDRESS_P (x
))
3534 struct deferred_string
*p
, **defstr
;
3536 defstr
= (struct deferred_string
**)
3537 htab_find_slot_with_hash (const_str_htab
, XSTR (x
, 0),
3538 STRHASH (XSTR (x
, 0)), NO_INSERT
);
3539 #ifdef ENABLE_CHECKING
3545 STRING_POOL_ADDRESS_P (x
) = 0;
3546 output_constant_def_contents (p
->exp
, p
->label
);
3547 htab_clear_slot (const_str_htab
, (void **) defstr
);
3553 /* Find all the constants whose addresses are referenced inside of EXP,
3554 and make sure assembler code with a label has been output for each one.
3555 Indicate whether an ADDR_EXPR has been encountered. */
3558 output_addressed_constants (exp
)
3561 int reloc
= 0, reloc2
;
3564 /* Give the front-end a chance to convert VALUE to something that
3565 looks more like a constant to the back-end. */
3566 exp
= (*lang_hooks
.expand_constant
) (exp
);
3568 switch (TREE_CODE (exp
))
3572 /* Go inside any operations that get_inner_reference can handle and see
3573 if what's inside is a constant: no need to do anything here for
3574 addresses of variables or functions. */
3575 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
3576 tem
= TREE_OPERAND (tem
, 0))
3579 if (TREE_CODE_CLASS (TREE_CODE (tem
)) == 'c'
3580 || TREE_CODE (tem
) == CONSTRUCTOR
)
3581 output_constant_def (tem
, 0);
3583 if (TREE_PUBLIC (tem
))
3590 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3591 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
3595 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3596 reloc2
= output_addressed_constants (TREE_OPERAND (exp
, 1));
3597 /* The difference of two local labels is computable at link time. */
3598 if (reloc
== 1 && reloc2
== 1)
3606 case NON_LVALUE_EXPR
:
3607 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
3611 for (tem
= CONSTRUCTOR_ELTS (exp
); tem
; tem
= TREE_CHAIN (tem
))
3612 if (TREE_VALUE (tem
) != 0)
3613 reloc
|= output_addressed_constants (TREE_VALUE (tem
));
3623 /* Return nonzero if VALUE is a valid constant-valued expression
3624 for use in initializing a static variable; one that can be an
3625 element of a "constant" initializer.
3627 Return null_pointer_node if the value is absolute;
3628 if it is relocatable, return the variable that determines the relocation.
3629 We assume that VALUE has been folded as much as possible;
3630 therefore, we do not need to check for such things as
3631 arithmetic-combinations of integers. */
3634 initializer_constant_valid_p (value
, endtype
)
3638 /* Give the front-end a chance to convert VALUE to something that
3639 looks more like a constant to the back-end. */
3640 value
= (*lang_hooks
.expand_constant
) (value
);
3642 switch (TREE_CODE (value
))
3645 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
3646 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
3647 && TREE_CONSTANT (value
)
3648 && CONSTRUCTOR_ELTS (value
))
3650 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
3653 return TREE_STATIC (value
) ? null_pointer_node
: 0;
3660 return null_pointer_node
;
3664 return staticp (TREE_OPERAND (value
, 0)) ? TREE_OPERAND (value
, 0) : 0;
3666 case VIEW_CONVERT_EXPR
:
3667 case NON_LVALUE_EXPR
:
3668 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3672 /* Allow conversions between pointer types. */
3673 if (POINTER_TYPE_P (TREE_TYPE (value
))
3674 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3675 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3677 /* Allow conversions between real types. */
3678 if (FLOAT_TYPE_P (TREE_TYPE (value
))
3679 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3680 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3682 /* Allow length-preserving conversions between integer types. */
3683 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3684 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
3685 && (TYPE_PRECISION (TREE_TYPE (value
))
3686 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
3687 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
3689 /* Allow conversions between other integer types only if
3691 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3692 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3694 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3696 if (inner
== null_pointer_node
)
3697 return null_pointer_node
;
3701 /* Allow (int) &foo provided int is as wide as a pointer. */
3702 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
3703 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
3704 && (TYPE_PRECISION (TREE_TYPE (value
))
3705 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
3706 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3709 /* Likewise conversions from int to pointers, but also allow
3710 conversions from 0. */
3711 if (POINTER_TYPE_P (TREE_TYPE (value
))
3712 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
3714 if (integer_zerop (TREE_OPERAND (value
, 0)))
3715 return null_pointer_node
;
3716 else if (TYPE_PRECISION (TREE_TYPE (value
))
3717 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
3718 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3722 /* Allow conversions to union types if the value inside is okay. */
3723 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
3724 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3729 if (! INTEGRAL_TYPE_P (endtype
)
3730 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3732 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3734 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3736 /* If either term is absolute, use the other terms relocation. */
3737 if (valid0
== null_pointer_node
)
3739 if (valid1
== null_pointer_node
)
3745 if (! INTEGRAL_TYPE_P (endtype
)
3746 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
3748 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
3750 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
3752 /* Win if second argument is absolute. */
3753 if (valid1
== null_pointer_node
)
3755 /* Win if both arguments have the same relocation.
3756 Then the value is absolute. */
3757 if (valid0
== valid1
&& valid0
!= 0)
3758 return null_pointer_node
;
3760 /* Since GCC guarantees that string constants are unique in the
3761 generated code, a subtraction between two copies of the same
3762 constant string is absolute. */
3763 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
&&
3764 valid1
&& TREE_CODE (valid1
) == STRING_CST
&&
3765 TREE_STRING_POINTER (valid0
) == TREE_STRING_POINTER (valid1
))
3766 return null_pointer_node
;
3769 /* Support differences between labels. */
3770 if (INTEGRAL_TYPE_P (endtype
))
3773 op0
= TREE_OPERAND (value
, 0);
3774 op1
= TREE_OPERAND (value
, 1);
3776 /* Like STRIP_NOPS except allow the operand mode to widen.
3777 This works around a feature of fold that simplifies
3778 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
3779 that the narrower operation is cheaper. */
3781 while (TREE_CODE (op0
) == NOP_EXPR
3782 || TREE_CODE (op0
) == CONVERT_EXPR
3783 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
3785 tree inner
= TREE_OPERAND (op0
, 0);
3786 if (inner
== error_mark_node
3787 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3788 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
3789 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3794 while (TREE_CODE (op1
) == NOP_EXPR
3795 || TREE_CODE (op1
) == CONVERT_EXPR
3796 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
3798 tree inner
= TREE_OPERAND (op1
, 0);
3799 if (inner
== error_mark_node
3800 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
3801 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
3802 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
3807 if (TREE_CODE (op0
) == ADDR_EXPR
3808 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
3809 && TREE_CODE (op1
) == ADDR_EXPR
3810 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
3811 return null_pointer_node
;
3822 /* Output assembler code for constant EXP to FILE, with no label.
3823 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3824 Assumes output_addressed_constants has been done on EXP already.
3826 Generate exactly SIZE bytes of assembler data, padding at the end
3827 with zeros if necessary. SIZE must always be specified.
3829 SIZE is important for structure constructors,
3830 since trailing members may have been omitted from the constructor.
3831 It is also important for initialization of arrays from string constants
3832 since the full length of the string constant might not be wanted.
3833 It is also needed for initialization of unions, where the initializer's
3834 type is just one member, and that may not be as long as the union.
3836 There a case in which we would fail to output exactly SIZE bytes:
3837 for a structure constructor that wants to produce more than SIZE bytes.
3838 But such constructors will never be generated for any possible input.
3840 ALIGN is the alignment of the data in bits. */
3843 output_constant (exp
, size
, align
)
3848 enum tree_code code
;
3849 HOST_WIDE_INT thissize
;
3851 /* Some front-ends use constants other than the standard language-independent
3852 varieties, but which may still be output directly. Give the front-end a
3853 chance to convert EXP to a language-independent representation. */
3854 exp
= (*lang_hooks
.expand_constant
) (exp
);
3856 if (size
== 0 || flag_syntax_only
)
3859 /* Eliminate any conversions since we'll be outputting the underlying
3861 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
3862 || TREE_CODE (exp
) == NON_LVALUE_EXPR
3863 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
3864 exp
= TREE_OPERAND (exp
, 0);
3866 code
= TREE_CODE (TREE_TYPE (exp
));
3867 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
3869 /* Allow a constructor with no elements for any data type.
3870 This means to fill the space with zeros. */
3871 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
3873 assemble_zeros (size
);
3877 if (TREE_CODE (exp
) == FDESC_EXPR
)
3879 #ifdef ASM_OUTPUT_FDESC
3880 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
3881 tree decl
= TREE_OPERAND (exp
, 0);
3882 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
3889 /* Now output the underlying data. If we've handling the padding, return.
3890 Otherwise, break and ensure THISSIZE is the size written. */
3898 case REFERENCE_TYPE
:
3899 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
3900 EXPAND_INITIALIZER
),
3902 error ("initializer for integer value is too complicated");
3906 if (TREE_CODE (exp
) != REAL_CST
)
3907 error ("initializer for floating value is not a floating constant");
3909 assemble_real (TREE_REAL_CST (exp
),
3910 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0),
3915 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
3916 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
3917 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
3922 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3924 output_constructor (exp
, size
, align
);
3927 else if (TREE_CODE (exp
) == STRING_CST
)
3929 thissize
= MIN (TREE_STRING_LENGTH (exp
), size
);
3930 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
3932 else if (TREE_CODE (exp
) == VECTOR_CST
)
3936 unsigned int nalign
;
3937 enum machine_mode inner
;
3939 inner
= GET_MODE_INNER (TYPE_MODE (TREE_TYPE (exp
)));
3940 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
3942 elt_size
= GET_MODE_UNIT_SIZE (TYPE_MODE (TREE_TYPE (exp
)));
3944 link
= TREE_VECTOR_CST_ELTS (exp
);
3945 output_constant (TREE_VALUE (link
), elt_size
, align
);
3946 while ((link
= TREE_CHAIN (link
)) != NULL
)
3947 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
3955 if (TREE_CODE (exp
) == CONSTRUCTOR
)
3956 output_constructor (exp
, size
, align
);
3962 if (TREE_CODE (exp
) == INTEGER_CST
)
3963 assemble_integer (expand_expr (exp
, NULL_RTX
,
3964 VOIDmode
, EXPAND_INITIALIZER
),
3965 thissize
, align
, 1);
3966 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
3968 unsigned char *buffer
= (unsigned char *) alloca (thissize
);
3969 if (get_set_constructor_bytes (exp
, buffer
, thissize
))
3971 assemble_string ((char *) buffer
, thissize
);
3974 error ("unknown set constructor type");
3986 assemble_zeros (size
);
3990 /* Subroutine of output_constructor, used for computing the size of
3991 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
3992 type with an unspecified upper bound. */
3994 static unsigned HOST_WIDE_INT
3995 array_size_for_constructor (val
)
4000 /* This code used to attempt to handle string constants that are not
4001 arrays of single-bytes, but nothing else does, so there's no point in
4003 if (TREE_CODE (val
) == STRING_CST
)
4004 return TREE_STRING_LENGTH (val
);
4006 max_index
= NULL_TREE
;
4007 for (i
= CONSTRUCTOR_ELTS (val
); i
; i
= TREE_CHAIN (i
))
4009 tree index
= TREE_PURPOSE (i
);
4011 if (TREE_CODE (index
) == RANGE_EXPR
)
4012 index
= TREE_OPERAND (index
, 1);
4013 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4017 if (max_index
== NULL_TREE
)
4020 /* Compute the total number of array elements. */
4021 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
4023 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
4024 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
4026 /* Multiply by the array element unit size to find number of bytes. */
4027 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4029 return tree_low_cst (i
, 1);
4032 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4033 Generate at least SIZE bytes, padding if necessary. */
4036 output_constructor (exp
, size
, align
)
4041 tree type
= TREE_TYPE (exp
);
4042 tree link
, field
= 0;
4044 /* Number of bytes output or skipped so far.
4045 In other words, current position within the constructor. */
4046 HOST_WIDE_INT total_bytes
= 0;
4047 /* Nonzero means BYTE contains part of a byte, to be output. */
4048 int byte_buffer_in_use
= 0;
4051 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4054 if (TREE_CODE (type
) == RECORD_TYPE
)
4055 field
= TYPE_FIELDS (type
);
4057 if (TREE_CODE (type
) == ARRAY_TYPE
4058 && TYPE_DOMAIN (type
) != 0)
4059 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
4061 /* As LINK goes through the elements of the constant,
4062 FIELD goes through the structure fields, if the constant is a structure.
4063 if the constant is a union, then we override this,
4064 by getting the field from the TREE_LIST element.
4065 But the constant could also be an array. Then FIELD is zero.
4067 There is always a maximum of one element in the chain LINK for unions
4068 (even if the initializer in a source program incorrectly contains
4070 for (link
= CONSTRUCTOR_ELTS (exp
);
4072 link
= TREE_CHAIN (link
),
4073 field
= field
? TREE_CHAIN (field
) : 0)
4075 tree val
= TREE_VALUE (link
);
4078 /* The element in a union constructor specifies the proper field
4080 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
4081 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4082 && TREE_PURPOSE (link
) != 0)
4083 field
= TREE_PURPOSE (link
);
4085 else if (TREE_CODE (type
) == ARRAY_TYPE
)
4086 index
= TREE_PURPOSE (link
);
4088 /* Eliminate the marker that makes a cast not be an lvalue. */
4092 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4094 unsigned HOST_WIDE_INT fieldsize
4095 = int_size_in_bytes (TREE_TYPE (type
));
4096 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
4097 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
4098 HOST_WIDE_INT index
;
4099 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
4101 for (index
= lo_index
; index
<= hi_index
; index
++)
4103 /* Output the element's initial value. */
4105 assemble_zeros (fieldsize
);
4107 output_constant (val
, fieldsize
, align2
);
4109 /* Count its size. */
4110 total_bytes
+= fieldsize
;
4113 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4115 /* An element that is not a bit-field. */
4117 unsigned HOST_WIDE_INT fieldsize
;
4118 /* Since this structure is static,
4119 we know the positions are constant. */
4120 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4121 unsigned int align2
;
4124 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4125 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4127 /* Output any buffered-up bit-fields preceding this element. */
4128 if (byte_buffer_in_use
)
4130 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4132 byte_buffer_in_use
= 0;
4135 /* Advance to offset of this element.
4136 Note no alignment needed in an array, since that is guaranteed
4137 if each element has the proper size. */
4138 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4140 assemble_zeros (pos
- total_bytes
);
4144 /* Find the alignment of this element. */
4145 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4147 /* Determine size this element should occupy. */
4152 /* If this is an array with an unspecified upper bound,
4153 the initializer determines the size. */
4154 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4155 but we cannot do this until the deprecated support for
4156 initializing zero-length array members is removed. */
4157 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4158 && TYPE_DOMAIN (TREE_TYPE (field
))
4159 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4161 fieldsize
= array_size_for_constructor (val
);
4162 /* Given a non-empty initialization, this field had
4164 if (fieldsize
!= 0 && TREE_CHAIN (field
) != NULL_TREE
)
4167 else if (DECL_SIZE_UNIT (field
))
4169 /* ??? This can't be right. If the decl size overflows
4170 a host integer we will silently emit no data. */
4171 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4172 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4176 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4178 /* Output the element's initial value. */
4180 assemble_zeros (fieldsize
);
4182 output_constant (val
, fieldsize
, align2
);
4184 /* Count its size. */
4185 total_bytes
+= fieldsize
;
4187 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4188 error ("invalid initial value for member `%s'",
4189 IDENTIFIER_POINTER (DECL_NAME (field
)));
4192 /* Element that is a bit-field. */
4194 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4195 HOST_WIDE_INT end_offset
4196 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4199 val
= integer_zero_node
;
4201 /* If this field does not start in this (or, next) byte,
4203 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4205 /* Output remnant of any bit field in previous bytes. */
4206 if (byte_buffer_in_use
)
4208 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4210 byte_buffer_in_use
= 0;
4213 /* If still not at proper byte, advance to there. */
4214 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4216 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4217 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4221 if (! byte_buffer_in_use
)
4224 /* We must split the element into pieces that fall within
4225 separate bytes, and combine each byte with previous or
4226 following bit-fields. */
4228 /* next_offset is the offset n fbits from the beginning of
4229 the structure to the next bit of this element to be processed.
4230 end_offset is the offset of the first bit past the end of
4232 while (next_offset
< end_offset
)
4236 HOST_WIDE_INT value
;
4237 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4238 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4240 /* Advance from byte to byte
4241 within this element when necessary. */
4242 while (next_byte
!= total_bytes
)
4244 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4249 /* Number of bits we can process at once
4250 (all part of the same byte). */
4251 this_time
= MIN (end_offset
- next_offset
,
4252 BITS_PER_UNIT
- next_bit
);
4253 if (BYTES_BIG_ENDIAN
)
4255 /* On big-endian machine, take the most significant bits
4256 first (of the bits that are significant)
4257 and put them into bytes from the most significant end. */
4258 shift
= end_offset
- next_offset
- this_time
;
4260 /* Don't try to take a bunch of bits that cross
4261 the word boundary in the INTEGER_CST. We can
4262 only select bits from the LOW or HIGH part
4264 if (shift
< HOST_BITS_PER_WIDE_INT
4265 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4267 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4268 shift
= HOST_BITS_PER_WIDE_INT
;
4271 /* Now get the bits from the appropriate constant word. */
4272 if (shift
< HOST_BITS_PER_WIDE_INT
)
4273 value
= TREE_INT_CST_LOW (val
);
4274 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4276 value
= TREE_INT_CST_HIGH (val
);
4277 shift
-= HOST_BITS_PER_WIDE_INT
;
4282 /* Get the result. This works only when:
4283 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4284 byte
|= (((value
>> shift
)
4285 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4286 << (BITS_PER_UNIT
- this_time
- next_bit
));
4290 /* On little-endian machines,
4291 take first the least significant bits of the value
4292 and pack them starting at the least significant
4293 bits of the bytes. */
4294 shift
= next_offset
- int_bit_position (field
);
4296 /* Don't try to take a bunch of bits that cross
4297 the word boundary in the INTEGER_CST. We can
4298 only select bits from the LOW or HIGH part
4300 if (shift
< HOST_BITS_PER_WIDE_INT
4301 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4302 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4304 /* Now get the bits from the appropriate constant word. */
4305 if (shift
< HOST_BITS_PER_WIDE_INT
)
4306 value
= TREE_INT_CST_LOW (val
);
4307 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4309 value
= TREE_INT_CST_HIGH (val
);
4310 shift
-= HOST_BITS_PER_WIDE_INT
;
4315 /* Get the result. This works only when:
4316 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4317 byte
|= (((value
>> shift
)
4318 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4322 next_offset
+= this_time
;
4323 byte_buffer_in_use
= 1;
4328 if (byte_buffer_in_use
)
4330 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4334 if (total_bytes
< size
)
4335 assemble_zeros (size
- total_bytes
);
4338 /* This TREE_LIST contains any weak symbol declarations waiting
4340 static GTY(()) tree weak_decls
;
4342 /* Mark DECL as weak. */
4348 DECL_WEAK (decl
) = 1;
4350 if (DECL_RTL_SET_P (decl
)
4351 && GET_CODE (DECL_RTL (decl
)) == MEM
4352 && XEXP (DECL_RTL (decl
), 0)
4353 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
4354 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
4357 /* Merge weak status between NEWDECL and OLDDECL. */
4360 merge_weak (newdecl
, olddecl
)
4364 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
4367 if (DECL_WEAK (newdecl
))
4371 /* NEWDECL is weak, but OLDDECL is not. */
4373 /* If we already output the OLDDECL, we're in trouble; we can't
4374 go back and make it weak. This error cannot caught in
4375 declare_weak because the NEWDECL and OLDDECL was not yet
4376 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4377 if (TREE_ASM_WRITTEN (olddecl
))
4378 error_with_decl (newdecl
,
4379 "weak declaration of `%s' must precede definition");
4381 /* If we've already generated rtl referencing OLDDECL, we may
4382 have done so in a way that will not function properly with
4384 else if (TREE_USED (olddecl
)
4385 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
4386 warning_with_decl (newdecl
, "weak declaration of `%s' after first use results in unspecified behavior");
4390 /* We put the NEWDECL on the weak_decls list at some point.
4391 Replace it with the OLDDECL. */
4392 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
4393 if (TREE_VALUE (wd
) == newdecl
)
4395 TREE_VALUE (wd
) = olddecl
;
4398 /* We may not find the entry on the list. If NEWDECL is a
4399 weak alias, then we will have already called
4400 globalize_decl to remove the entry; in that case, we do
4401 not need to do anything. */
4404 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4405 mark_weak (olddecl
);
4408 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4409 weak. Just update NEWDECL to indicate that it's weak too. */
4410 mark_weak (newdecl
);
4413 /* Declare DECL to be a weak symbol. */
4419 if (! TREE_PUBLIC (decl
))
4420 error_with_decl (decl
, "weak declaration of `%s' must be public");
4421 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
4422 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4423 else if (SUPPORTS_WEAK
)
4425 if (! DECL_WEAK (decl
))
4426 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
4429 warning_with_decl (decl
, "weak declaration of `%s' not supported");
4434 /* Emit any pending weak declarations. */
4441 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
4443 tree decl
= TREE_VALUE (t
);
4444 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
4445 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4448 if (! TREE_USED (decl
))
4451 #ifdef ASM_WEAKEN_DECL
4452 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
4454 #ifdef ASM_WEAKEN_LABEL
4455 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4457 #ifdef ASM_OUTPUT_WEAK_ALIAS
4458 warning ("only weak aliases are supported in this configuration");
4466 /* Emit the assembly bits to indicate that DECL is globally visible. */
4469 globalize_decl (decl
)
4472 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4474 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4475 if (DECL_WEAK (decl
))
4479 #ifdef ASM_WEAKEN_DECL
4480 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
4482 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4485 /* Remove this function from the pending weak list so that
4486 we do not emit multiple .weak directives for it. */
4487 for (p
= &weak_decls
; (t
= *p
) ; )
4489 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4490 *p
= TREE_CHAIN (t
);
4492 p
= &TREE_CHAIN (t
);
4498 (*targetm
.asm_out
.globalize_label
) (asm_out_file
, name
);
4501 /* Emit an assembler directive to make the symbol for DECL an alias to
4502 the symbol for TARGET. */
4505 assemble_alias (decl
, target
)
4506 tree decl
, target ATTRIBUTE_UNUSED
;
4510 /* We must force creation of DECL_RTL for debug info generation, even though
4511 we don't use it here. */
4512 make_decl_rtl (decl
, NULL
);
4514 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4516 #ifdef ASM_OUTPUT_DEF
4517 /* Make name accessible from other files, if appropriate. */
4519 if (TREE_PUBLIC (decl
))
4521 globalize_decl (decl
);
4522 maybe_assemble_visibility (decl
);
4525 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4526 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4528 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4530 #else /* !ASM_OUTPUT_DEF */
4531 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4532 if (! DECL_WEAK (decl
))
4533 warning ("only weak aliases are supported in this configuration");
4535 #ifdef ASM_WEAKEN_DECL
4536 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
4538 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4541 warning ("alias definitions not supported in this configuration; ignored");
4545 TREE_USED (decl
) = 1;
4546 TREE_ASM_WRITTEN (decl
) = 1;
4547 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
4550 /* Emit an assembler directive to set symbol for DECL visibility to
4551 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
4554 default_assemble_visibility (decl
, vis
)
4558 static const char * const visibility_types
[] = {
4559 NULL
, "internal", "hidden", "protected"
4562 const char *name
, *type
;
4564 name
= (* targetm
.strip_name_encoding
)
4565 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
4566 type
= visibility_types
[vis
];
4568 #ifdef HAVE_GAS_HIDDEN
4569 fprintf (asm_out_file
, "\t.%s\t%s\n", type
, name
);
4571 warning ("visibility attribute not supported in this configuration; ignored");
4575 /* A helper function to call assemble_visibility when needed for a decl. */
4578 maybe_assemble_visibility (decl
)
4581 enum symbol_visibility vis
= decl_visibility (decl
);
4583 if (vis
!= VISIBILITY_DEFAULT
)
4584 (* targetm
.asm_out
.visibility
) (decl
, vis
);
4587 /* Returns 1 if the target configuration supports defining public symbols
4588 so that one of them will be chosen at link time instead of generating a
4589 multiply-defined symbol error, whether through the use of weak symbols or
4590 a target-specific mechanism for having duplicates discarded. */
4593 supports_one_only ()
4595 if (SUPPORTS_ONE_ONLY
)
4597 return SUPPORTS_WEAK
;
4600 /* Set up DECL as a public symbol that can be defined in multiple
4601 translation units without generating a linker error. */
4604 make_decl_one_only (decl
)
4607 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
4610 TREE_PUBLIC (decl
) = 1;
4612 if (TREE_CODE (decl
) == VAR_DECL
4613 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
4614 DECL_COMMON (decl
) = 1;
4615 else if (SUPPORTS_ONE_ONLY
)
4617 #ifdef MAKE_DECL_ONE_ONLY
4618 MAKE_DECL_ONE_ONLY (decl
);
4620 DECL_ONE_ONLY (decl
) = 1;
4622 else if (SUPPORTS_WEAK
)
4623 DECL_WEAK (decl
) = 1;
4631 const_str_htab
= htab_create_ggc (128, const_str_htab_hash
,
4632 const_str_htab_eq
, NULL
);
4633 in_named_htab
= htab_create_ggc (31, in_named_entry_hash
,
4634 in_named_entry_eq
, NULL
);
4636 const_alias_set
= new_alias_set ();
4640 decl_tls_model (decl
)
4643 enum tls_model kind
;
4644 tree attr
= lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl
));
4649 attr
= TREE_VALUE (TREE_VALUE (attr
));
4650 if (TREE_CODE (attr
) != STRING_CST
)
4652 if (!strcmp (TREE_STRING_POINTER (attr
), "local-exec"))
4653 kind
= TLS_MODEL_LOCAL_EXEC
;
4654 else if (!strcmp (TREE_STRING_POINTER (attr
), "initial-exec"))
4655 kind
= TLS_MODEL_INITIAL_EXEC
;
4656 else if (!strcmp (TREE_STRING_POINTER (attr
), "local-dynamic"))
4657 kind
= optimize
? TLS_MODEL_LOCAL_DYNAMIC
: TLS_MODEL_GLOBAL_DYNAMIC
;
4658 else if (!strcmp (TREE_STRING_POINTER (attr
), "global-dynamic"))
4659 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
4665 is_local
= (*targetm
.binds_local_p
) (decl
);
4669 kind
= TLS_MODEL_LOCAL_EXEC
;
4671 kind
= TLS_MODEL_INITIAL_EXEC
;
4673 /* Local dynamic is inefficient when we're not combining the
4674 parts of the address. */
4675 else if (optimize
&& is_local
)
4676 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
4678 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
4679 if (kind
< flag_tls_default
)
4680 kind
= flag_tls_default
;
4685 enum symbol_visibility
4686 decl_visibility (decl
)
4689 tree attr
= lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
));
4693 const char *which
= TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr
)));
4695 if (strcmp (which
, "default") == 0)
4696 return VISIBILITY_DEFAULT
;
4697 if (strcmp (which
, "internal") == 0)
4698 return VISIBILITY_INTERNAL
;
4699 if (strcmp (which
, "hidden") == 0)
4700 return VISIBILITY_HIDDEN
;
4701 if (strcmp (which
, "protected") == 0)
4702 return VISIBILITY_PROTECTED
;
4707 return VISIBILITY_DEFAULT
;
4710 /* Select a set of attributes for section NAME based on the properties
4711 of DECL and whether or not RELOC indicates that DECL's initializer
4712 might contain runtime relocations.
4714 We make the section read-only and executable for a function decl,
4715 read-only for a const data decl, and writable for a non-const data decl. */
4718 default_section_type_flags (decl
, name
, reloc
)
4723 return default_section_type_flags_1 (decl
, name
, reloc
, flag_pic
);
4727 default_section_type_flags_1 (decl
, name
, reloc
, shlib
)
4735 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
4736 flags
= SECTION_CODE
;
4737 else if (decl
&& decl_readonly_section_1 (decl
, reloc
, shlib
))
4740 flags
= SECTION_WRITE
;
4742 if (decl
&& DECL_ONE_ONLY (decl
))
4743 flags
|= SECTION_LINKONCE
;
4745 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
4746 flags
|= SECTION_TLS
| SECTION_WRITE
;
4748 if (strcmp (name
, ".bss") == 0
4749 || strncmp (name
, ".bss.", 5) == 0
4750 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
4751 || strcmp (name
, ".sbss") == 0
4752 || strncmp (name
, ".sbss.", 6) == 0
4753 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0
4754 || strcmp (name
, ".tbss") == 0
4755 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
4756 flags
|= SECTION_BSS
;
4758 if (strcmp (name
, ".tdata") == 0
4759 || strcmp (name
, ".tbss") == 0
4760 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0
4761 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
4762 flags
|= SECTION_TLS
;
4764 /* These three sections have special ELF types. They are neither
4765 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
4766 want to print a section type (@progbits or @nobits). If someone
4767 is silly enough to emit code or TLS variables to one of these
4768 sections, then don't handle them specially. */
4769 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
4770 && (strcmp (name
, ".init_array") == 0
4771 || strcmp (name
, ".fini_array") == 0
4772 || strcmp (name
, ".preinit_array") == 0))
4773 flags
|= SECTION_NOTYPE
;
4778 /* Output assembly to switch to section NAME with attribute FLAGS.
4779 Four variants for common object file formats. */
4782 default_no_named_section (name
, flags
)
4783 const char *name ATTRIBUTE_UNUSED
;
4784 unsigned int flags ATTRIBUTE_UNUSED
;
4786 /* Some object formats don't support named sections at all. The
4787 front-end should already have flagged this as an error. */
4792 default_elf_asm_named_section (name
, flags
)
4796 char flagchars
[10], *f
= flagchars
;
4798 if (! named_section_first_declaration (name
))
4800 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
4804 if (!(flags
& SECTION_DEBUG
))
4806 if (flags
& SECTION_WRITE
)
4808 if (flags
& SECTION_CODE
)
4810 if (flags
& SECTION_SMALL
)
4812 if (flags
& SECTION_MERGE
)
4814 if (flags
& SECTION_STRINGS
)
4816 if (flags
& SECTION_TLS
)
4820 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
4822 if (!(flags
& SECTION_NOTYPE
))
4826 if (flags
& SECTION_BSS
)
4831 fprintf (asm_out_file
, ",@%s", type
);
4833 if (flags
& SECTION_ENTSIZE
)
4834 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
4837 putc ('\n', asm_out_file
);
4841 default_coff_asm_named_section (name
, flags
)
4845 char flagchars
[8], *f
= flagchars
;
4847 if (flags
& SECTION_WRITE
)
4849 if (flags
& SECTION_CODE
)
4853 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
4857 default_pe_asm_named_section (name
, flags
)
4861 default_coff_asm_named_section (name
, flags
);
4863 if (flags
& SECTION_LINKONCE
)
4865 /* Functions may have been compiled at various levels of
4866 optimization so we can't use `same_size' here.
4867 Instead, have the linker pick one. */
4868 fprintf (asm_out_file
, "\t.linkonce %s\n",
4869 (flags
& SECTION_CODE
? "discard" : "same_size"));
4873 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
4874 from SYMBOL is used in all classes derived from SYMBOL. */
4877 assemble_vtable_entry (symbol
, offset
)
4879 HOST_WIDE_INT offset
;
4881 fputs ("\t.vtable_entry ", asm_out_file
);
4882 output_addr_const (asm_out_file
, symbol
);
4883 fputs (", ", asm_out_file
);
4884 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_DEC
, offset
);
4885 fputc ('\n', asm_out_file
);
4888 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
4889 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
4892 assemble_vtable_inherit (child
, parent
)
4895 fputs ("\t.vtable_inherit ", asm_out_file
);
4896 output_addr_const (asm_out_file
, child
);
4897 fputs (", ", asm_out_file
);
4898 output_addr_const (asm_out_file
, parent
);
4899 fputc ('\n', asm_out_file
);
4902 /* The lame default section selector. */
4905 default_select_section (decl
, reloc
, align
)
4908 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
4910 bool readonly
= false;
4914 if (decl_readonly_section (decl
, reloc
))
4917 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
4919 if (! ((flag_pic
&& reloc
)
4920 || !TREE_READONLY (decl
)
4921 || TREE_SIDE_EFFECTS (decl
)
4922 || !TREE_CONSTANT (decl
)))
4925 else if (TREE_CODE (decl
) == STRING_CST
)
4926 readonly
= !flag_writable_strings
;
4927 else if (! (flag_pic
&& reloc
))
4931 readonly_data_section ();
4936 /* A helper function for default_elf_select_section and
4937 default_elf_unique_section. Categorizes the DECL. */
4939 enum section_category
4944 SECCAT_RODATA_MERGE_STR
,
4945 SECCAT_RODATA_MERGE_STR_INIT
,
4946 SECCAT_RODATA_MERGE_CONST
,
4951 /* To optimize loading of shared programs, define following subsections
4953 _REL Contains data that has relocations, so they get grouped
4954 together and dynamic linker will visit fewer pages in memory.
4955 _RO Contains data that is otherwise read-only. This is useful
4956 with prelinking as most relocations won't be dynamically
4957 linked and thus stay read only.
4958 _LOCAL Marks data containing relocations only to local objects.
4959 These relocations will get fully resolved by prelinking. */
4961 SECCAT_DATA_REL_LOCAL
,
4963 SECCAT_DATA_REL_RO_LOCAL
,
4973 static enum section_category
4974 categorize_decl_for_section
PARAMS ((tree
, int, int));
4976 static enum section_category
4977 categorize_decl_for_section (decl
, reloc
, shlib
)
4982 enum section_category ret
;
4984 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4986 else if (TREE_CODE (decl
) == STRING_CST
)
4988 if (flag_writable_strings
)
4991 return SECCAT_RODATA_MERGE_STR
;
4993 else if (TREE_CODE (decl
) == VAR_DECL
)
4995 if (DECL_INITIAL (decl
) == NULL
4996 || DECL_INITIAL (decl
) == error_mark_node
)
4998 else if (! TREE_READONLY (decl
)
4999 || TREE_SIDE_EFFECTS (decl
)
5000 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5002 if (shlib
&& (reloc
& 2))
5003 ret
= SECCAT_DATA_REL
;
5004 else if (shlib
&& reloc
)
5005 ret
= SECCAT_DATA_REL_LOCAL
;
5009 else if (shlib
&& (reloc
& 2))
5010 ret
= SECCAT_DATA_REL_RO
;
5011 else if (shlib
&& reloc
)
5012 ret
= SECCAT_DATA_REL_RO_LOCAL
;
5013 else if (reloc
|| flag_merge_constants
< 2)
5014 /* C and C++ don't allow different variables to share the same
5015 location. -fmerge-all-constants allows even that (at the
5016 expense of not conforming). */
5017 ret
= SECCAT_RODATA
;
5018 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
5019 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
5021 ret
= SECCAT_RODATA_MERGE_CONST
;
5023 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5025 if ((shlib
&& reloc
)
5026 || TREE_SIDE_EFFECTS (decl
)
5027 || ! TREE_CONSTANT (decl
))
5030 ret
= SECCAT_RODATA
;
5033 ret
= SECCAT_RODATA
;
5035 /* There are no read-only thread-local sections. */
5036 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
5038 if (ret
== SECCAT_BSS
)
5044 /* If the target uses small data sections, select it. */
5045 else if ((*targetm
.in_small_data_p
) (decl
))
5047 if (ret
== SECCAT_BSS
)
5049 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
5050 ret
= SECCAT_SRODATA
;
5059 decl_readonly_section (decl
, reloc
)
5063 return decl_readonly_section_1 (decl
, reloc
, flag_pic
);
5067 decl_readonly_section_1 (decl
, reloc
, shlib
)
5072 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5075 case SECCAT_RODATA_MERGE_STR
:
5076 case SECCAT_RODATA_MERGE_STR_INIT
:
5077 case SECCAT_RODATA_MERGE_CONST
:
5078 case SECCAT_SRODATA
:
5087 /* Select a section based on the above categorization. */
5090 default_elf_select_section (decl
, reloc
, align
)
5093 unsigned HOST_WIDE_INT align
;
5095 default_elf_select_section_1 (decl
, reloc
, align
, flag_pic
);
5099 default_elf_select_section_1 (decl
, reloc
, align
, shlib
)
5102 unsigned HOST_WIDE_INT align
;
5105 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5108 /* We're not supposed to be called on FUNCTION_DECLs. */
5111 readonly_data_section ();
5113 case SECCAT_RODATA_MERGE_STR
:
5114 mergeable_string_section (decl
, align
, 0);
5116 case SECCAT_RODATA_MERGE_STR_INIT
:
5117 mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
5119 case SECCAT_RODATA_MERGE_CONST
:
5120 mergeable_constant_section (DECL_MODE (decl
), align
, 0);
5122 case SECCAT_SRODATA
:
5123 named_section (NULL_TREE
, ".sdata2", reloc
);
5128 case SECCAT_DATA_REL
:
5129 named_section (NULL_TREE
, ".data.rel", reloc
);
5131 case SECCAT_DATA_REL_LOCAL
:
5132 named_section (NULL_TREE
, ".data.rel.local", reloc
);
5134 case SECCAT_DATA_REL_RO
:
5135 named_section (NULL_TREE
, ".data.rel.ro", reloc
);
5137 case SECCAT_DATA_REL_RO_LOCAL
:
5138 named_section (NULL_TREE
, ".data.rel.ro.local", reloc
);
5141 named_section (NULL_TREE
, ".sdata", reloc
);
5144 named_section (NULL_TREE
, ".tdata", reloc
);
5147 #ifdef BSS_SECTION_ASM_OP
5150 named_section (NULL_TREE
, ".bss", reloc
);
5154 named_section (NULL_TREE
, ".sbss", reloc
);
5157 named_section (NULL_TREE
, ".tbss", reloc
);
5164 /* Construct a unique section name based on the decl name and the
5165 categorization performed above. */
5168 default_unique_section (decl
, reloc
)
5172 default_unique_section_1 (decl
, reloc
, flag_pic
);
5176 default_unique_section_1 (decl
, reloc
, shlib
)
5181 bool one_only
= DECL_ONE_ONLY (decl
);
5182 const char *prefix
, *name
;
5186 switch (categorize_decl_for_section (decl
, reloc
, shlib
))
5189 prefix
= one_only
? ".gnu.linkonce.t." : ".text.";
5192 case SECCAT_RODATA_MERGE_STR
:
5193 case SECCAT_RODATA_MERGE_STR_INIT
:
5194 case SECCAT_RODATA_MERGE_CONST
:
5195 prefix
= one_only
? ".gnu.linkonce.r." : ".rodata.";
5197 case SECCAT_SRODATA
:
5198 prefix
= one_only
? ".gnu.linkonce.s2." : ".sdata2.";
5201 case SECCAT_DATA_REL
:
5202 case SECCAT_DATA_REL_LOCAL
:
5203 case SECCAT_DATA_REL_RO
:
5204 case SECCAT_DATA_REL_RO_LOCAL
:
5205 prefix
= one_only
? ".gnu.linkonce.d." : ".data.";
5208 prefix
= one_only
? ".gnu.linkonce.s." : ".sdata.";
5211 prefix
= one_only
? ".gnu.linkonce.b." : ".bss.";
5214 prefix
= one_only
? ".gnu.linkonce.sb." : ".sbss.";
5217 prefix
= one_only
? ".gnu.linkonce.td." : ".tdata.";
5220 prefix
= one_only
? ".gnu.linkonce.tb." : ".tbss.";
5225 plen
= strlen (prefix
);
5227 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5228 name
= (* targetm
.strip_name_encoding
) (name
);
5229 nlen
= strlen (name
);
5231 string
= alloca (nlen
+ plen
+ 1);
5232 memcpy (string
, prefix
, plen
);
5233 memcpy (string
+ plen
, name
, nlen
+ 1);
5235 DECL_SECTION_NAME (decl
) = build_string (nlen
+ plen
, string
);
5239 default_select_rtx_section (mode
, x
, align
)
5240 enum machine_mode mode ATTRIBUTE_UNUSED
;
5242 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
5245 switch (GET_CODE (x
))
5257 readonly_data_section ();
5261 default_elf_select_rtx_section (mode
, x
, align
)
5262 enum machine_mode mode
;
5264 unsigned HOST_WIDE_INT align
;
5266 /* ??? Handle small data here somehow. */
5269 switch (GET_CODE (x
))
5273 named_section (NULL_TREE
, ".data.rel.ro", 3);
5277 named_section (NULL_TREE
, ".data.rel.ro.local", 1);
5284 mergeable_constant_section (mode
, align
, 0);
5287 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
5290 default_encode_section_info (decl
, rtl
, first
)
5293 int first ATTRIBUTE_UNUSED
;
5298 /* Careful not to prod global register variables. */
5299 if (GET_CODE (rtl
) != MEM
)
5301 symbol
= XEXP (rtl
, 0);
5302 if (GET_CODE (symbol
) != SYMBOL_REF
)
5306 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5307 flags
|= SYMBOL_FLAG_FUNCTION
;
5308 if ((*targetm
.binds_local_p
) (decl
))
5309 flags
|= SYMBOL_FLAG_LOCAL
;
5310 if ((*targetm
.in_small_data_p
) (decl
))
5311 flags
|= SYMBOL_FLAG_SMALL
;
5312 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
5313 flags
|= decl_tls_model (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
5314 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
5315 being PUBLIC, the thing *must* be defined in this translation unit.
5316 Prevent this buglet from being propagated into rtl code as well. */
5317 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
5318 flags
|= SYMBOL_FLAG_EXTERNAL
;
5320 SYMBOL_REF_FLAGS (symbol
) = flags
;
5323 /* By default, we do nothing for encode_section_info, so we need not
5324 do anything but discard the '*' marker. */
5327 default_strip_name_encoding (str
)
5330 return str
+ (*str
== '*');
5333 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5334 wrt cross-module name binding. */
5337 default_binds_local_p (exp
)
5340 return default_binds_local_p_1 (exp
, flag_pic
);
5344 default_binds_local_p_1 (exp
, shlib
)
5350 /* A non-decl is an entry in the constant pool. */
5353 /* Static variables are always local. */
5354 else if (! TREE_PUBLIC (exp
))
5356 /* A variable is local if the user tells us so. */
5357 else if (decl_visibility (exp
) != VISIBILITY_DEFAULT
)
5359 /* Otherwise, variables defined outside this object may not be local. */
5360 else if (DECL_EXTERNAL (exp
))
5362 /* Linkonce and weak data are never local. */
5363 else if (DECL_ONE_ONLY (exp
) || DECL_WEAK (exp
))
5365 /* If PIC, then assume that any global name can be overridden by
5366 symbols resolved from other modules. */
5369 /* Uninitialized COMMON variable may be unified with symbols
5370 resolved from other modules. */
5371 else if (DECL_COMMON (exp
)
5372 && (DECL_INITIAL (exp
) == NULL
5373 || DECL_INITIAL (exp
) == error_mark_node
))
5375 /* Otherwise we're left with initialized (or non-common) global data
5376 which is of necessity defined locally. */
5383 /* Determine whether or not a pointer mode is valid. Assume defaults
5384 of ptr_mode or Pmode - can be overridden. */
5386 default_valid_pointer_mode (mode
)
5387 enum machine_mode mode
;
5389 return (mode
== ptr_mode
|| mode
== Pmode
);
5392 /* Default function to output code that will globalize a label. A
5393 target must define GLOBAL_ASM_OP or provide it's own function to
5394 globalize a label. */
5395 #ifdef GLOBAL_ASM_OP
5397 default_globalize_label (stream
, name
)
5401 fputs (GLOBAL_ASM_OP
, stream
);
5402 assemble_name (stream
, name
);
5403 putc ('\n', stream
);
5405 #endif /* GLOBAL_ASM_OP */
5407 /* This is how to output an internal numbered label where PREFIX is
5408 the class of label and LABELNO is the number within the class. */
5411 default_internal_label (stream
, prefix
, labelno
)
5414 unsigned long labelno
;
5416 char *const buf
= alloca (40 + strlen (prefix
));
5417 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
5418 ASM_OUTPUT_LABEL (stream
, buf
);
5421 #include "gt-varasm.h"