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 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. */
37 #include "hard-reg-set.h"
47 #include "langhooks.h"
52 #ifdef XCOFF_DEBUGGING_INFO
53 #include "xcoffout.h" /* Needed for external data
54 declarations for e.g. AIX 4.x. */
57 #ifndef TRAMPOLINE_ALIGNMENT
58 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
62 #define ASM_STABS_OP "\t.stabs\t"
65 /* The (assembler) name of the first globally-visible object output. */
66 const char *first_global_object_name
;
67 const char *weak_global_object_name
;
69 extern struct obstack permanent_obstack
;
70 #define obstack_chunk_alloc xmalloc
73 struct constant_descriptor
;
77 #define MAX_RTX_HASH_TABLE 61
81 /* Hash facility for making memory-constants
82 from constant rtl-expressions. It is used on RISC machines
83 where immediate integer arguments and constant addresses are restricted
84 so that such constants must be stored in memory.
86 This pool of constants is reinitialized for each function
87 so each function gets its own constants-pool that comes right before
89 struct constant_descriptor
**x_const_rtx_hash_table
;
90 struct pool_constant
**x_const_rtx_sym_hash_table
;
92 /* Pointers to first and last constant in pool. */
93 struct pool_constant
*x_first_pool
, *x_last_pool
;
95 /* Current offset in constant pool (does not include any machine-specific
97 HOST_WIDE_INT x_pool_offset
;
100 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
101 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
102 #define first_pool (cfun->varasm->x_first_pool)
103 #define last_pool (cfun->varasm->x_last_pool)
104 #define pool_offset (cfun->varasm->x_pool_offset)
106 /* Number for making the label on the next
107 constant that is stored in memory. */
111 /* Number for making the label on the next
112 static variable internal to a function. */
116 /* Carry information from ASM_DECLARE_OBJECT_NAME
117 to ASM_FINISH_DECLARE_OBJECT. */
119 int size_directive_output
;
121 /* The last decl for which assemble_variable was called,
122 if it did ASM_DECLARE_OBJECT_NAME.
123 If the last call to assemble_variable didn't do that,
126 tree last_assemble_variable_decl
;
128 /* RTX_UNCHANGING_P in a MEM can mean it is stored into, for initialization.
129 So giving constant the alias set for the type will allow such
130 initializations to appear to conflict with the load of the constant. We
131 avoid this by giving all constants an alias set for just constants.
132 Since there will be no stores to that alias set, nothing will ever
133 conflict with them. */
135 static HOST_WIDE_INT const_alias_set
;
137 static const char *strip_reg_name
PARAMS ((const char *));
138 static int contains_pointers_p
PARAMS ((tree
));
139 static void decode_addr_const
PARAMS ((tree
, struct addr_const
*));
140 static int const_hash
PARAMS ((tree
));
141 static int compare_constant
PARAMS ((tree
,
142 struct constant_descriptor
*));
143 static const unsigned char *compare_constant_1
PARAMS ((tree
, const unsigned char *));
144 static struct constant_descriptor
*record_constant
PARAMS ((tree
));
145 static void record_constant_1
PARAMS ((tree
));
146 static tree copy_constant
PARAMS ((tree
));
147 static void output_constant_def_contents
PARAMS ((tree
, int, int));
148 static void decode_rtx_const
PARAMS ((enum machine_mode
, rtx
,
149 struct rtx_const
*));
150 static int const_hash_rtx
PARAMS ((enum machine_mode
, rtx
));
151 static int compare_constant_rtx
PARAMS ((enum machine_mode
, rtx
,
152 struct constant_descriptor
*));
153 static struct constant_descriptor
*record_constant_rtx
PARAMS ((enum machine_mode
,
155 static struct pool_constant
*find_pool_constant
PARAMS ((struct function
*, rtx
));
156 static void mark_constant_pool
PARAMS ((void));
157 static void mark_constants
PARAMS ((rtx
));
158 static int mark_constant
PARAMS ((rtx
*current_rtx
, void *data
));
159 static int output_addressed_constants
PARAMS ((tree
));
160 static void output_after_function_constants
PARAMS ((void));
161 static unsigned HOST_WIDE_INT array_size_for_constructor
PARAMS ((tree
));
162 static unsigned min_align
PARAMS ((unsigned, unsigned));
163 static void output_constructor
PARAMS ((tree
, HOST_WIDE_INT
,
165 static void globalize_decl
PARAMS ((tree
));
166 static void maybe_assemble_visibility
PARAMS ((tree
));
167 static int in_named_entry_eq
PARAMS ((const PTR
, const PTR
));
168 static hashval_t in_named_entry_hash
PARAMS ((const PTR
));
169 #ifdef ASM_OUTPUT_BSS
170 static void asm_output_bss
PARAMS ((FILE *, tree
, const char *, int, int));
172 #ifdef BSS_SECTION_ASM_OP
173 #ifdef ASM_OUTPUT_ALIGNED_BSS
174 static void asm_output_aligned_bss
PARAMS ((FILE *, tree
, const char *,
177 #endif /* BSS_SECTION_ASM_OP */
178 static void mark_pool_constant
PARAMS ((struct pool_constant
*));
179 static void mark_const_hash_entry
PARAMS ((void *));
180 static int mark_const_str_htab_1
PARAMS ((void **, void *));
181 static void mark_const_str_htab
PARAMS ((void *));
182 static hashval_t const_str_htab_hash
PARAMS ((const void *x
));
183 static int const_str_htab_eq
PARAMS ((const void *x
, const void *y
));
184 static void const_str_htab_del
PARAMS ((void *));
185 static void asm_emit_uninitialised
PARAMS ((tree
, const char*, int, int));
186 static void resolve_unique_section
PARAMS ((tree
, int, int));
187 static void mark_weak
PARAMS ((tree
));
189 static enum in_section
{ no_section
, in_text
, in_data
, in_named
190 #ifdef BSS_SECTION_ASM_OP
193 #ifdef CTORS_SECTION_ASM_OP
196 #ifdef DTORS_SECTION_ASM_OP
199 #ifdef READONLY_DATA_SECTION_ASM_OP
202 #ifdef EXTRA_SECTIONS
205 } in_section
= no_section
;
207 /* Return a non-zero value if DECL has a section attribute. */
208 #ifndef IN_NAMED_SECTION
209 #define IN_NAMED_SECTION(DECL) \
210 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
211 && DECL_SECTION_NAME (DECL) != NULL_TREE)
214 /* Text of section name when in_section == in_named. */
215 static const char *in_named_name
;
217 /* Hash table of flags that have been used for a particular named section. */
219 struct in_named_entry
226 static htab_t in_named_htab
;
228 /* Define functions like text_section for any extra sections. */
229 #ifdef EXTRA_SECTION_FUNCTIONS
230 EXTRA_SECTION_FUNCTIONS
233 /* Tell assembler to switch to text section. */
238 if (in_section
!= in_text
)
240 in_section
= in_text
;
244 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
249 /* Tell assembler to switch to data section. */
254 if (in_section
!= in_data
)
256 in_section
= in_data
;
257 if (flag_shared_data
)
259 #ifdef SHARED_SECTION_ASM_OP
260 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
262 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
266 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
270 /* Tell assembler to ALWAYS switch to data section, in case
271 it's not sure where it is. */
274 force_data_section ()
276 in_section
= no_section
;
280 /* Tell assembler to switch to read-only data section. This is normally
284 readonly_data_section ()
286 #ifdef READONLY_DATA_SECTION
287 READONLY_DATA_SECTION (); /* Note this can call data_section. */
289 #ifdef READONLY_DATA_SECTION_ASM_OP
290 if (in_section
!= in_readonly_data
)
292 in_section
= in_readonly_data
;
293 fputs (READONLY_DATA_SECTION_ASM_OP
, asm_out_file
);
294 fputc ('\n', asm_out_file
);
302 /* Determine if we're in the text section. */
307 return in_section
== in_text
;
310 /* Determine if we're in the data section. */
315 return in_section
== in_data
;
318 /* Helper routines for maintaining in_named_htab. */
321 in_named_entry_eq (p1
, p2
)
325 const struct in_named_entry
*old
= p1
;
326 const char *new = p2
;
328 return strcmp (old
->name
, new) == 0;
332 in_named_entry_hash (p
)
335 const struct in_named_entry
*old
= p
;
336 return htab_hash_string (old
->name
);
339 /* If SECTION has been seen before as a named section, return the flags
340 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
341 set of flags for a section to have, so 0 does not mean that the section
342 has not been seen. */
345 get_named_section_flags (section
)
348 struct in_named_entry
**slot
;
350 slot
= (struct in_named_entry
**)
351 htab_find_slot_with_hash (in_named_htab
, section
,
352 htab_hash_string (section
), NO_INSERT
);
354 return slot
? (*slot
)->flags
: 0;
357 /* Returns true if the section has been declared before. Sets internal
358 flag on this section in in_named_hash so subsequent calls on this
359 section will return false. */
362 named_section_first_declaration (name
)
365 struct in_named_entry
**slot
;
367 slot
= (struct in_named_entry
**)
368 htab_find_slot_with_hash (in_named_htab
, name
,
369 htab_hash_string (name
), NO_INSERT
);
370 if (! (*slot
)->declared
)
372 (*slot
)->declared
= true;
382 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
383 different set of flags, return false. */
386 set_named_section_flags (section
, flags
)
390 struct in_named_entry
**slot
, *entry
;
392 slot
= (struct in_named_entry
**)
393 htab_find_slot_with_hash (in_named_htab
, section
,
394 htab_hash_string (section
), INSERT
);
399 entry
= (struct in_named_entry
*) xmalloc (sizeof (*entry
));
401 entry
->name
= ggc_strdup (section
);
402 entry
->flags
= flags
;
403 entry
->declared
= false;
405 else if (entry
->flags
!= flags
)
411 /* Tell assembler to change to section NAME with attributes FLAGS. */
414 named_section_flags (name
, flags
)
418 if (in_section
!= in_named
|| strcmp (name
, in_named_name
) != 0)
420 if (! set_named_section_flags (name
, flags
))
423 (*targetm
.asm_out
.named_section
) (name
, flags
);
425 if (flags
& SECTION_FORGET
)
426 in_section
= no_section
;
429 in_named_name
= ggc_strdup (name
);
430 in_section
= in_named
;
435 /* Tell assembler to change to section NAME for DECL.
436 If DECL is NULL, just switch to section NAME.
437 If NAME is NULL, get the name from DECL.
438 If RELOC is 1, the initializer for DECL contains relocs. */
441 named_section (decl
, name
, reloc
)
448 if (decl
!= NULL_TREE
&& !DECL_P (decl
))
451 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
453 flags
= (* targetm
.section_type_flags
) (decl
, name
, reloc
);
455 /* Sanity check user variables for flag changes. Non-user
456 section flag changes will abort in named_section_flags.
457 However, don't complain if SECTION_OVERRIDE is set.
458 We trust that the setter knows that it is safe to ignore
459 the default flags for this decl. */
460 if (decl
&& ! set_named_section_flags (name
, flags
))
462 flags
= get_named_section_flags (name
);
463 if ((flags
& SECTION_OVERRIDE
) == 0)
464 error_with_decl (decl
, "%s causes a section type conflict");
467 named_section_flags (name
, flags
);
470 /* If required, set DECL_SECTION_NAME to a unique name. */
473 resolve_unique_section (decl
, reloc
, flag_function_or_data_sections
)
475 int reloc ATTRIBUTE_UNUSED
;
476 int flag_function_or_data_sections
;
478 if (DECL_SECTION_NAME (decl
) == NULL_TREE
479 && targetm
.have_named_sections
480 && (flag_function_or_data_sections
481 || DECL_ONE_ONLY (decl
)))
482 (*targetm
.asm_out
.unique_section
) (decl
, reloc
);
485 #ifdef BSS_SECTION_ASM_OP
487 /* Tell the assembler to switch to the bss section. */
492 if (in_section
!= in_bss
)
494 #ifdef SHARED_BSS_SECTION_ASM_OP
495 if (flag_shared_data
)
496 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
499 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
505 #ifdef ASM_OUTPUT_BSS
507 /* Utility function for ASM_OUTPUT_BSS for targets to use if
508 they don't support alignments in .bss.
509 ??? It is believed that this function will work in most cases so such
510 support is localized here. */
513 asm_output_bss (file
, decl
, name
, size
, rounded
)
515 tree decl ATTRIBUTE_UNUSED
;
517 int size ATTRIBUTE_UNUSED
, rounded
;
519 ASM_GLOBALIZE_LABEL (file
, name
);
521 #ifdef ASM_DECLARE_OBJECT_NAME
522 last_assemble_variable_decl
= decl
;
523 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
525 /* Standard thing is just output label for the object. */
526 ASM_OUTPUT_LABEL (file
, name
);
527 #endif /* ASM_DECLARE_OBJECT_NAME */
528 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
533 #ifdef ASM_OUTPUT_ALIGNED_BSS
535 /* Utility function for targets to use in implementing
536 ASM_OUTPUT_ALIGNED_BSS.
537 ??? It is believed that this function will work in most cases so such
538 support is localized here. */
541 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
543 tree decl ATTRIBUTE_UNUSED
;
547 ASM_GLOBALIZE_LABEL (file
, name
);
549 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
550 #ifdef ASM_DECLARE_OBJECT_NAME
551 last_assemble_variable_decl
= decl
;
552 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
554 /* Standard thing is just output label for the object. */
555 ASM_OUTPUT_LABEL (file
, name
);
556 #endif /* ASM_DECLARE_OBJECT_NAME */
557 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
562 #endif /* BSS_SECTION_ASM_OP */
564 /* Switch to the section for function DECL.
566 If DECL is NULL_TREE, switch to the text section.
567 ??? It's not clear that we will ever be passed NULL_TREE, but it's
568 safer to handle it. */
571 function_section (decl
)
574 if (decl
!= NULL_TREE
575 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
576 named_section (decl
, (char *) 0, 0);
581 /* Switch to section for variable DECL. RELOC is the same as the
582 argument to SELECT_SECTION. */
585 variable_section (decl
, reloc
)
589 if (IN_NAMED_SECTION (decl
))
590 named_section (decl
, NULL
, reloc
);
592 (*targetm
.asm_out
.select_section
) (decl
, reloc
, DECL_ALIGN (decl
));
595 /* Tell assembler to switch to the section for the exception handling
599 default_exception_section ()
601 if (targetm
.have_named_sections
)
602 named_section (NULL_TREE
, ".gcc_except_table", 0);
606 readonly_data_section ();
609 /* Tell assembler to switch to the section for string merging. */
612 mergeable_string_section (decl
, align
, flags
)
613 tree decl ATTRIBUTE_UNUSED
;
614 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
615 unsigned int flags ATTRIBUTE_UNUSED
;
617 #ifdef HAVE_GAS_SHF_MERGE
618 if (flag_merge_constants
619 && TREE_CODE (decl
) == STRING_CST
620 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
622 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
624 enum machine_mode mode
;
625 unsigned int modesize
;
630 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
631 modesize
= GET_MODE_BITSIZE (mode
);
632 if (modesize
>= 8 && modesize
<= 256
633 && (modesize
& (modesize
- 1)) == 0)
635 if (align
< modesize
)
638 str
= TREE_STRING_POINTER (decl
);
639 len
= TREE_STRING_LENGTH (decl
);
640 unit
= GET_MODE_SIZE (mode
);
642 /* Check for embedded NUL characters. */
643 for (i
= 0; i
< len
; i
+= unit
)
645 for (j
= 0; j
< unit
; j
++)
646 if (str
[i
+ j
] != '\0')
653 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
655 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
656 if (!i
&& modesize
< align
)
658 /* A "" string with requested alignment greater than
659 character size might cause a problem:
660 if some other string required even bigger
661 alignment than "", then linker might think the
662 "" is just part of padding after some other string
663 and not put it into the hash table initially.
664 But this means "" could have smaller alignment
666 #ifdef ASM_OUTPUT_SECTION_START
667 named_section_flags (name
, flags
);
668 ASM_OUTPUT_SECTION_START (asm_out_file
);
670 readonly_data_section ();
675 named_section_flags (name
, flags
);
681 readonly_data_section ();
684 /* Tell assembler to switch to the section for constant merging. */
687 mergeable_constant_section (mode
, align
, flags
)
688 enum machine_mode mode ATTRIBUTE_UNUSED
;
689 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
690 unsigned int flags ATTRIBUTE_UNUSED
;
692 #ifdef HAVE_GAS_SHF_MERGE
693 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
695 if (flag_merge_constants
701 && (align
& (align
- 1)) == 0)
705 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
706 flags
|= (align
/ 8) | SECTION_MERGE
;
707 named_section_flags (name
, flags
);
711 readonly_data_section ();
714 /* Given NAME, a putative register name, discard any customary prefixes. */
717 strip_reg_name (name
)
720 #ifdef REGISTER_PREFIX
721 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
722 name
+= strlen (REGISTER_PREFIX
);
724 if (name
[0] == '%' || name
[0] == '#')
729 /* Decode an `asm' spec for a declaration as a register name.
730 Return the register number, or -1 if nothing specified,
731 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
732 or -3 if ASMSPEC is `cc' and is not recognized,
733 or -4 if ASMSPEC is `memory' and is not recognized.
734 Accept an exact spelling or a decimal number.
735 Prefixes such as % are optional. */
738 decode_reg_name (asmspec
)
745 /* Get rid of confusing prefixes. */
746 asmspec
= strip_reg_name (asmspec
);
748 /* Allow a decimal number as a "register name". */
749 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
750 if (! ISDIGIT (asmspec
[i
]))
752 if (asmspec
[0] != 0 && i
< 0)
755 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
761 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
763 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
766 #ifdef ADDITIONAL_REGISTER_NAMES
768 static const struct { const char *const name
; const int number
; } table
[]
769 = ADDITIONAL_REGISTER_NAMES
;
771 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
772 if (! strcmp (asmspec
, table
[i
].name
))
773 return table
[i
].number
;
775 #endif /* ADDITIONAL_REGISTER_NAMES */
777 if (!strcmp (asmspec
, "memory"))
780 if (!strcmp (asmspec
, "cc"))
789 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
790 have static storage duration. In other words, it should not be an
791 automatic variable, including PARM_DECLs.
793 There is, however, one exception: this function handles variables
794 explicitly placed in a particular register by the user.
796 ASMSPEC, if not 0, is the string which the user specified as the
797 assembler symbol name.
799 This is never called for PARM_DECL nodes. */
802 make_decl_rtl (decl
, asmspec
)
806 int top_level
= (DECL_CONTEXT (decl
) == NULL_TREE
);
807 const char *name
= 0;
808 const char *new_name
= 0;
812 /* Check that we are not being given an automatic variable. */
813 /* A weak alias has TREE_PUBLIC set but not the other bits. */
814 if (TREE_CODE (decl
) == PARM_DECL
815 || TREE_CODE (decl
) == RESULT_DECL
816 || (TREE_CODE (decl
) == VAR_DECL
817 && !TREE_STATIC (decl
)
818 && !TREE_PUBLIC (decl
)
819 && !DECL_EXTERNAL (decl
)
820 && !DECL_REGISTER (decl
)))
822 /* And that we were not given a type or a label. */
823 else if (TREE_CODE (decl
) == TYPE_DECL
824 || TREE_CODE (decl
) == LABEL_DECL
)
827 /* For a duplicate declaration, we can be called twice on the
828 same DECL node. Don't discard the RTL already made. */
829 if (DECL_RTL_SET_P (decl
))
831 /* If the old RTL had the wrong mode, fix the mode. */
832 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
833 SET_DECL_RTL (decl
, adjust_address_nv (DECL_RTL (decl
),
834 DECL_MODE (decl
), 0));
836 /* ??? Another way to do this would be to do what halfpic.c does
837 and maintain a hashed table of such critters. */
838 /* Let the target reassign the RTL if it wants.
839 This is necessary, for example, when one machine specific
840 decl attribute overrides another. */
841 (* targetm
.encode_section_info
) (decl
, false);
845 new_name
= name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
847 reg_number
= decode_reg_name (asmspec
);
848 if (reg_number
== -2)
850 /* ASMSPEC is given, and not the name of a register. Mark the
851 name with a star so assemble_name won't munge it. */
852 char *starred
= alloca (strlen (asmspec
) + 2);
854 strcpy (starred
+ 1, asmspec
);
858 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
860 /* First detect errors in declaring global registers. */
861 if (reg_number
== -1)
862 error_with_decl (decl
, "register name not specified for `%s'");
863 else if (reg_number
< 0)
864 error_with_decl (decl
, "invalid register name for `%s'");
865 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
866 error_with_decl (decl
,
867 "data type of `%s' isn't suitable for a register");
868 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
869 error_with_decl (decl
,
870 "register specified for `%s' isn't suitable for data type");
871 /* Now handle properly declared static register variables. */
876 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
878 DECL_INITIAL (decl
) = 0;
879 error ("global register variable has initial value");
881 if (TREE_THIS_VOLATILE (decl
))
882 warning ("volatile register variables don't work as you might wish");
884 /* If the user specified one of the eliminables registers here,
885 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
886 confused with that register and be eliminated. This usage is
887 somewhat suspect... */
889 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
890 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
891 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
893 if (TREE_STATIC (decl
))
895 /* Make this register global, so not usable for anything
897 #ifdef ASM_DECLARE_REGISTER_GLOBAL
898 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
900 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
902 globalize_reg (reg_number
+ --nregs
);
905 /* As a register variable, it has no section. */
910 /* Now handle ordinary static variables and functions (in memory).
911 Also handle vars declared register invalidly. */
913 if (reg_number
>= 0 || reg_number
== -3)
914 error_with_decl (decl
,
915 "register name given for non-register variable `%s'");
917 /* Specifying a section attribute on a variable forces it into a
918 non-.bss section, and thus it cannot be common. */
919 if (TREE_CODE (decl
) == VAR_DECL
920 && DECL_SECTION_NAME (decl
) != NULL_TREE
921 && DECL_INITIAL (decl
) == NULL_TREE
922 && DECL_COMMON (decl
))
923 DECL_COMMON (decl
) = 0;
925 /* Variables can't be both common and weak. */
926 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
927 DECL_COMMON (decl
) = 0;
929 /* Can't use just the variable's own name for a variable
930 whose scope is less than the whole file, unless it's a member
931 of a local class (which will already be unambiguous).
932 Concatenate a distinguishing number. */
933 if (!top_level
&& !TREE_PUBLIC (decl
)
934 && ! (DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
)))
936 && name
== IDENTIFIER_POINTER (DECL_NAME (decl
)))
940 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
945 if (name
!= new_name
)
947 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (new_name
));
948 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
951 /* If this variable is to be treated as volatile, show its
952 tree node has side effects. */
953 if ((flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
954 && TREE_PUBLIC (decl
))
955 || ((flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
956 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))))
957 TREE_SIDE_EFFECTS (decl
) = 1;
959 x
= gen_rtx_MEM (DECL_MODE (decl
), gen_rtx_SYMBOL_REF (Pmode
, name
));
960 SYMBOL_REF_WEAK (XEXP (x
, 0)) = DECL_WEAK (decl
);
961 if (TREE_CODE (decl
) != FUNCTION_DECL
)
962 set_mem_attributes (x
, decl
, 1);
963 SET_DECL_RTL (decl
, x
);
965 /* Optionally set flags or add text to the name to record information
966 such as that it is a function name.
967 If the name is changed, the macro ASM_OUTPUT_LABELREF
968 will have to know how to strip this information. */
969 (* targetm
.encode_section_info
) (decl
, true);
972 /* Make the rtl for variable VAR be volatile.
973 Use this only for static variables. */
976 make_var_volatile (var
)
979 if (GET_CODE (DECL_RTL (var
)) != MEM
)
982 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
985 /* Output alignment directive to align for constant expression EXP. */
988 assemble_constant_align (exp
)
993 /* Align the location counter as required by EXP's data type. */
994 align
= TYPE_ALIGN (TREE_TYPE (exp
));
995 #ifdef CONSTANT_ALIGNMENT
996 align
= CONSTANT_ALIGNMENT (exp
, align
);
999 if (align
> BITS_PER_UNIT
)
1001 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1005 /* Output a string of literal assembler code
1006 for an `asm' keyword used between functions. */
1009 assemble_asm (string
)
1014 if (TREE_CODE (string
) == ADDR_EXPR
)
1015 string
= TREE_OPERAND (string
, 0);
1017 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1020 /* Record an element in the table of global destructors. SYMBOL is
1021 a SYMBOL_REF of the function to be called; PRIORITY is a number
1022 between 0 and MAX_INIT_PRIORITY. */
1025 default_stabs_asm_out_destructor (symbol
, priority
)
1027 int priority ATTRIBUTE_UNUSED
;
1029 /* Tell GNU LD that this is part of the static destructor set.
1030 This will work for any system that uses stabs, most usefully
1032 fprintf (asm_out_file
, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1033 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1034 fputc ('\n', asm_out_file
);
1038 default_named_section_asm_out_destructor (symbol
, priority
)
1042 const char *section
= ".dtors";
1045 /* ??? This only works reliably with the GNU linker. */
1046 if (priority
!= DEFAULT_INIT_PRIORITY
)
1048 sprintf (buf
, ".dtors.%.5u",
1049 /* Invert the numbering so the linker puts us in the proper
1050 order; constructors are run from right to left, and the
1051 linker sorts in increasing order. */
1052 MAX_INIT_PRIORITY
- priority
);
1056 named_section_flags (section
, SECTION_WRITE
);
1057 assemble_align (POINTER_SIZE
);
1058 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1061 #ifdef DTORS_SECTION_ASM_OP
1065 if (in_section
!= in_dtors
)
1067 in_section
= in_dtors
;
1068 fputs (DTORS_SECTION_ASM_OP
, asm_out_file
);
1069 fputc ('\n', asm_out_file
);
1074 default_dtor_section_asm_out_destructor (symbol
, priority
)
1076 int priority ATTRIBUTE_UNUSED
;
1079 assemble_align (POINTER_SIZE
);
1080 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1084 /* Likewise for global constructors. */
1087 default_stabs_asm_out_constructor (symbol
, priority
)
1089 int priority ATTRIBUTE_UNUSED
;
1091 /* Tell GNU LD that this is part of the static destructor set.
1092 This will work for any system that uses stabs, most usefully
1094 fprintf (asm_out_file
, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1095 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1096 fputc ('\n', asm_out_file
);
1100 default_named_section_asm_out_constructor (symbol
, priority
)
1104 const char *section
= ".ctors";
1107 /* ??? This only works reliably with the GNU linker. */
1108 if (priority
!= DEFAULT_INIT_PRIORITY
)
1110 sprintf (buf
, ".ctors.%.5u",
1111 /* Invert the numbering so the linker puts us in the proper
1112 order; constructors are run from right to left, and the
1113 linker sorts in increasing order. */
1114 MAX_INIT_PRIORITY
- priority
);
1118 named_section_flags (section
, SECTION_WRITE
);
1119 assemble_align (POINTER_SIZE
);
1120 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1123 #ifdef CTORS_SECTION_ASM_OP
1127 if (in_section
!= in_ctors
)
1129 in_section
= in_ctors
;
1130 fputs (CTORS_SECTION_ASM_OP
, asm_out_file
);
1131 fputc ('\n', asm_out_file
);
1136 default_ctor_section_asm_out_constructor (symbol
, priority
)
1138 int priority ATTRIBUTE_UNUSED
;
1141 assemble_align (POINTER_SIZE
);
1142 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1146 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1147 a non-zero value if the constant pool should be output before the
1148 start of the function, or a zero value if the pool should output
1149 after the end of the function. The default is to put it before the
1152 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1153 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1156 /* Output assembler code for the constant pool of a function and associated
1157 with defining the name of the function. DECL describes the function.
1158 NAME is the function's name. For the constant pool, we use the current
1159 constant pool data. */
1162 assemble_start_function (decl
, fnname
)
1168 /* The following code does not need preprocessing in the assembler. */
1172 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1173 output_constant_pool (fnname
, decl
);
1175 resolve_unique_section (decl
, 0, flag_function_sections
);
1176 function_section (decl
);
1178 /* Tell assembler to move to target machine's alignment for functions. */
1179 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1182 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1185 /* Handle a user-specified function alignment.
1186 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1187 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1188 if (align_functions_log
> align
1189 && cfun
->function_frequency
!= FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
)
1191 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1192 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1193 align_functions_log
, align_functions
- 1);
1195 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1199 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1200 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1203 (*debug_hooks
->begin_function
) (decl
);
1205 /* Make function name accessible from other files, if appropriate. */
1207 if (TREE_PUBLIC (decl
))
1209 if (! first_global_object_name
)
1214 p
= (* targetm
.strip_name_encoding
) (fnname
);
1215 name
= permalloc (strlen (p
) + 1);
1218 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1219 first_global_object_name
= name
;
1221 weak_global_object_name
= name
;
1224 globalize_decl (decl
);
1226 maybe_assemble_visibility (decl
);
1229 /* Do any machine/system dependent processing of the function name */
1230 #ifdef ASM_DECLARE_FUNCTION_NAME
1231 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1233 /* Standard thing is just output label for the function. */
1234 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1235 #endif /* ASM_DECLARE_FUNCTION_NAME */
1238 /* Output assembler code associated with defining the size of the
1239 function. DECL describes the function. NAME is the function's name. */
1242 assemble_end_function (decl
, fnname
)
1246 #ifdef ASM_DECLARE_FUNCTION_SIZE
1247 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1249 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1251 output_constant_pool (fnname
, decl
);
1252 function_section (decl
); /* need to switch back */
1255 /* Output any constants which should appear after the function. */
1256 output_after_function_constants ();
1259 /* Assemble code to leave SIZE bytes of zeros. */
1262 assemble_zeros (size
)
1265 /* Do no output if -fsyntax-only. */
1266 if (flag_syntax_only
)
1269 #ifdef ASM_NO_SKIP_IN_TEXT
1270 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1271 so we must output 0s explicitly in the text section. */
1272 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1275 for (i
= 0; i
< size
; i
++)
1276 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1281 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1284 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1287 assemble_align (align
)
1290 if (align
> BITS_PER_UNIT
)
1292 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1296 /* Assemble a string constant with the specified C string as contents. */
1299 assemble_string (p
, size
)
1306 /* If the string is very long, split it up. */
1310 int thissize
= size
- pos
;
1311 if (thissize
> maximum
)
1314 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1322 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1323 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1324 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1326 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1327 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1328 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1330 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1331 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1335 #if defined ASM_OUTPUT_ALIGNED_BSS
1336 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1337 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1339 #if defined ASM_OUTPUT_BSS
1340 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1341 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1347 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1348 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1349 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1351 #if defined ASM_OUTPUT_ALIGNED_COMMON
1352 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1353 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1355 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1356 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1361 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1364 int size ATTRIBUTE_UNUSED
;
1365 int rounded ATTRIBUTE_UNUSED
;
1373 destination
= asm_dest_local
;
1375 if (TREE_PUBLIC (decl
))
1377 #if defined ASM_EMIT_BSS
1378 if (! DECL_COMMON (decl
))
1379 destination
= asm_dest_bss
;
1382 destination
= asm_dest_common
;
1385 if (destination
== asm_dest_bss
)
1386 globalize_decl (decl
);
1387 resolve_unique_section (decl
, 0, flag_data_sections
);
1389 if (flag_shared_data
)
1391 switch (destination
)
1393 #ifdef ASM_OUTPUT_SHARED_BSS
1395 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1398 #ifdef ASM_OUTPUT_SHARED_COMMON
1399 case asm_dest_common
:
1400 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1403 #ifdef ASM_OUTPUT_SHARED_LOCAL
1404 case asm_dest_local
:
1405 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1413 switch (destination
)
1417 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1420 case asm_dest_common
:
1421 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1423 case asm_dest_local
:
1424 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1433 /* Assemble everything that is needed for a variable or function declaration.
1434 Not used for automatic variables, and not used for function definitions.
1435 Should not be called for variables of incomplete structure type.
1437 TOP_LEVEL is nonzero if this variable has file scope.
1438 AT_END is nonzero if this is the special handling, at end of compilation,
1439 to define things that have had only tentative definitions.
1440 DONT_OUTPUT_DATA if nonzero means don't actually output the
1441 initial value (that will be done by the caller). */
1444 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1446 int top_level ATTRIBUTE_UNUSED
;
1447 int at_end ATTRIBUTE_UNUSED
;
1448 int dont_output_data
;
1455 last_assemble_variable_decl
= 0;
1457 /* Normally no need to say anything here for external references,
1458 since assemble_external is called by the language-specific code
1459 when a declaration is first seen. */
1461 if (DECL_EXTERNAL (decl
))
1464 /* Output no assembler code for a function declaration.
1465 Only definitions of functions output anything. */
1467 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1470 /* Do nothing for global register variables. */
1471 if (DECL_RTL_SET_P (decl
) && GET_CODE (DECL_RTL (decl
)) == REG
)
1473 TREE_ASM_WRITTEN (decl
) = 1;
1477 /* If type was incomplete when the variable was declared,
1478 see if it is complete now. */
1480 if (DECL_SIZE (decl
) == 0)
1481 layout_decl (decl
, 0);
1483 /* Still incomplete => don't allocate it; treat the tentative defn
1484 (which is what it must have been) as an `extern' reference. */
1486 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1488 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1489 DECL_SOURCE_LINE (decl
),
1490 "storage size of `%s' isn't known",
1491 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1492 TREE_ASM_WRITTEN (decl
) = 1;
1496 /* The first declaration of a variable that comes through this function
1497 decides whether it is global (in C, has external linkage)
1498 or local (in C, has internal linkage). So do nothing more
1499 if this function has already run. */
1501 if (TREE_ASM_WRITTEN (decl
))
1504 /* Make sure targetm.encode_section_info is invoked before we set
1506 decl_rtl
= DECL_RTL (decl
);
1508 TREE_ASM_WRITTEN (decl
) = 1;
1510 /* Do no output if -fsyntax-only. */
1511 if (flag_syntax_only
)
1516 if (! dont_output_data
1517 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1519 error_with_decl (decl
, "size of variable `%s' is too large");
1523 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1524 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1525 && ! first_global_object_name
1526 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1527 || DECL_INITIAL (decl
) == error_mark_node
))
1528 && ! DECL_WEAK (decl
)
1529 && ! DECL_ONE_ONLY (decl
))
1534 p
= (* targetm
.strip_name_encoding
) (name
);
1535 xname
= permalloc (strlen (p
) + 1);
1537 first_global_object_name
= xname
;
1540 /* Compute the alignment of this data. */
1542 align
= DECL_ALIGN (decl
);
1544 /* In the case for initialing an array whose length isn't specified,
1545 where we have not yet been able to do the layout,
1546 figure out the proper alignment now. */
1547 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1548 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1549 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1551 /* Some object file formats have a maximum alignment which they support.
1552 In particular, a.out format supports a maximum alignment of 4. */
1553 #ifndef MAX_OFILE_ALIGNMENT
1554 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1556 if (align
> MAX_OFILE_ALIGNMENT
)
1558 warning_with_decl (decl
,
1559 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1560 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1561 align
= MAX_OFILE_ALIGNMENT
;
1564 /* On some machines, it is good to increase alignment sometimes. */
1565 if (! DECL_USER_ALIGN (decl
))
1567 #ifdef DATA_ALIGNMENT
1568 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1570 #ifdef CONSTANT_ALIGNMENT
1571 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1572 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1576 /* Reset the alignment in case we have made it tighter, so we can benefit
1577 from it in get_pointer_alignment. */
1578 DECL_ALIGN (decl
) = align
;
1579 set_mem_align (decl_rtl
, align
);
1581 if (TREE_PUBLIC (decl
))
1582 maybe_assemble_visibility (decl
);
1584 /* Output any data that we will need to use the address of. */
1585 if (DECL_INITIAL (decl
) == error_mark_node
)
1586 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1587 else if (DECL_INITIAL (decl
))
1588 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1589 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1591 /* Handle uninitialized definitions. */
1593 /* If the decl has been given an explicit section name, then it
1594 isn't common, and shouldn't be handled as such. */
1595 if (DECL_SECTION_NAME (decl
) || dont_output_data
)
1597 /* We don't implement common thread-local data at present. */
1598 else if (DECL_THREAD_LOCAL (decl
))
1600 if (DECL_COMMON (decl
))
1601 sorry ("thread-local COMMON data not implemented");
1603 #ifndef ASM_EMIT_BSS
1604 /* If the target can't output uninitialized but not common global data
1605 in .bss, then we have to use .data. */
1606 /* ??? We should handle .bss via select_section mechanisms rather than
1607 via special target hooks. That would eliminate this special case. */
1608 else if (!DECL_COMMON (decl
))
1611 else if (DECL_INITIAL (decl
) == 0
1612 || DECL_INITIAL (decl
) == error_mark_node
1613 || (flag_zero_initialized_in_bss
1614 && initializer_zerop (DECL_INITIAL (decl
))))
1616 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1617 unsigned HOST_WIDE_INT rounded
= size
;
1619 /* Don't allocate zero bytes of common,
1620 since that means "undefined external" in the linker. */
1624 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1625 so that each uninitialized object starts on such a boundary. */
1626 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1627 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1628 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1630 /* Don't continue this line--convex cc version 4.1 would lose. */
1631 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1632 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN (decl
) / BITS_PER_UNIT
> rounded
)
1634 (decl
, "requested alignment for %s is greater than implemented alignment of %d",rounded
);
1637 asm_emit_uninitialised (decl
, name
, size
, rounded
);
1642 /* Handle initialized definitions.
1643 Also handle uninitialized global definitions if -fno-common and the
1644 target doesn't support ASM_OUTPUT_BSS. */
1646 /* First make the assembler name(s) global if appropriate. */
1647 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1648 globalize_decl (decl
);
1650 /* Switch to the appropriate section. */
1651 variable_section (decl
, reloc
);
1653 /* dbxout.c needs to know this. */
1654 if (in_text_section ())
1655 DECL_IN_TEXT_SECTION (decl
) = 1;
1657 /* Output the alignment of this data. */
1658 if (align
> BITS_PER_UNIT
)
1660 ASM_OUTPUT_ALIGN (asm_out_file
,
1661 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1664 /* Do any machine/system dependent processing of the object. */
1665 #ifdef ASM_DECLARE_OBJECT_NAME
1666 last_assemble_variable_decl
= decl
;
1667 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1669 /* Standard thing is just output label for the object. */
1670 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1671 #endif /* ASM_DECLARE_OBJECT_NAME */
1673 if (!dont_output_data
)
1675 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
1676 /* Output the actual data. */
1677 output_constant (DECL_INITIAL (decl
),
1678 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1681 /* Leave space for it. */
1682 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1686 /* Return 1 if type TYPE contains any pointers. */
1689 contains_pointers_p (type
)
1692 switch (TREE_CODE (type
))
1695 case REFERENCE_TYPE
:
1696 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1697 so I'll play safe and return 1. */
1703 case QUAL_UNION_TYPE
:
1706 /* For a type that has fields, see if the fields have pointers. */
1707 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1708 if (TREE_CODE (fields
) == FIELD_DECL
1709 && contains_pointers_p (TREE_TYPE (fields
)))
1715 /* An array type contains pointers if its element type does. */
1716 return contains_pointers_p (TREE_TYPE (type
));
1723 /* Output something to declare an external symbol to the assembler.
1724 (Most assemblers don't need this, so we normally output nothing.)
1725 Do nothing if DECL is not external. */
1728 assemble_external (decl
)
1729 tree decl ATTRIBUTE_UNUSED
;
1731 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1732 main body of this code is only rarely exercised. To provide some
1733 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1734 open. If it's not, we should not be calling this function. */
1738 #ifdef ASM_OUTPUT_EXTERNAL
1739 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1741 rtx rtl
= DECL_RTL (decl
);
1743 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1744 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1746 /* Some systems do require some output. */
1747 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1748 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1754 /* Similar, for calling a library function FUN. */
1757 assemble_external_libcall (fun
)
1758 rtx fun ATTRIBUTE_UNUSED
;
1760 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1761 /* Declare library function name external when first used, if nec. */
1762 if (! SYMBOL_REF_USED (fun
))
1764 SYMBOL_REF_USED (fun
) = 1;
1765 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1770 /* Declare the label NAME global. */
1773 assemble_global (name
)
1774 const char *name ATTRIBUTE_UNUSED
;
1776 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1779 /* Assemble a label named NAME. */
1782 assemble_label (name
)
1785 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1788 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1789 If NAME starts with a *, the rest of NAME is output verbatim.
1790 Otherwise NAME is transformed in an implementation-defined way
1791 (usually by the addition of an underscore).
1792 Many macros in the tm file are defined to call this function. */
1795 assemble_name (file
, name
)
1799 const char *real_name
;
1802 real_name
= (* targetm
.strip_name_encoding
) (name
);
1804 id
= maybe_get_identifier (real_name
);
1806 TREE_SYMBOL_REFERENCED (id
) = 1;
1809 fputs (&name
[1], file
);
1811 ASM_OUTPUT_LABELREF (file
, name
);
1814 /* Allocate SIZE bytes writable static space with a gensym name
1815 and return an RTX to refer to its address. */
1818 assemble_static_space (size
)
1822 const char *namestring
;
1826 if (flag_shared_data
)
1830 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1832 namestring
= ggc_strdup (name
);
1834 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1836 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1837 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1840 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1841 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1844 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1845 so that each uninitialized object starts on such a boundary. */
1846 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1847 int rounded ATTRIBUTE_UNUSED
1848 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1849 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1850 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1851 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1858 /* Assemble the static constant template for function entry trampolines.
1859 This is done at most once per compilation.
1860 Returns an RTX for the address of the template. */
1862 #ifdef TRAMPOLINE_TEMPLATE
1864 assemble_trampoline_template ()
1870 /* By default, put trampoline templates in read-only data section. */
1872 #ifdef TRAMPOLINE_SECTION
1873 TRAMPOLINE_SECTION ();
1875 readonly_data_section ();
1878 /* Write the assembler code to define one. */
1879 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1882 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1885 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1886 TRAMPOLINE_TEMPLATE (asm_out_file
);
1888 /* Record the rtl to refer to it. */
1889 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1890 name
= ggc_strdup (label
);
1891 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1895 /* A and B are either alignments or offsets. Return the minimum alignment
1896 that may be assumed after adding the two together. */
1898 static inline unsigned
1902 return (a
| b
) & -(a
| b
);
1905 /* Return the assembler directive for creating a given kind of integer
1906 object. SIZE is the number of bytes in the object and ALIGNED_P
1907 indicates whether it is known to be aligned. Return NULL if the
1908 assembly dialect has no such directive.
1910 The returned string should be printed at the start of a new line and
1911 be followed immediately by the object's initial value. */
1914 integer_asm_op (size
, aligned_p
)
1918 struct asm_int_op
*ops
;
1921 ops
= &targetm
.asm_out
.aligned_op
;
1923 ops
= &targetm
.asm_out
.unaligned_op
;
1928 return targetm
.asm_out
.byte_op
;
1942 /* Use directive OP to assemble an integer object X. Print OP at the
1943 start of the line, followed immediately by the value of X. */
1946 assemble_integer_with_op (op
, x
)
1950 fputs (op
, asm_out_file
);
1951 output_addr_const (asm_out_file
, x
);
1952 fputc ('\n', asm_out_file
);
1955 /* The default implementation of the asm_out.integer target hook. */
1958 default_assemble_integer (x
, size
, aligned_p
)
1959 rtx x ATTRIBUTE_UNUSED
;
1960 unsigned int size ATTRIBUTE_UNUSED
;
1961 int aligned_p ATTRIBUTE_UNUSED
;
1963 const char *op
= integer_asm_op (size
, aligned_p
);
1964 return op
&& (assemble_integer_with_op (op
, x
), true);
1967 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1968 the alignment of the integer in bits. Return 1 if we were able to output
1969 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1973 assemble_integer (x
, size
, align
, force
)
1981 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
1983 /* See if the target hook can handle this kind of object. */
1984 if ((*targetm
.asm_out
.integer
) (x
, size
, aligned_p
))
1987 /* If the object is a multi-byte one, try splitting it up. Split
1988 it into words it if is multi-word, otherwise split it into bytes. */
1991 enum machine_mode omode
, imode
;
1992 unsigned int subalign
;
1993 unsigned int subsize
, i
;
1995 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
1996 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
1997 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
1998 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
2000 for (i
= 0; i
< size
; i
+= subsize
)
2002 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2003 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2009 /* If we've printed some of it, but not all of it, there's no going
2022 assemble_real (d
, mode
, align
)
2024 enum machine_mode mode
;
2029 unsigned int nalign
= min_align (align
, 32);
2031 switch (BITS_PER_UNIT
)
2037 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2038 assemble_integer (GEN_INT (l
), 4, align
, 1);
2041 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2042 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
2043 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
2046 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d
, data
);
2047 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
2048 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
2049 assemble_integer (GEN_INT (data
[2]), 4, nalign
, 1);
2052 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d
, data
);
2053 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
2054 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
2055 assemble_integer (GEN_INT (data
[2]), 4, nalign
, 1);
2056 assemble_integer (GEN_INT (data
[3]), 4, nalign
, 1);
2067 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2068 assemble_integer (GEN_INT (l
), 2, align
, 1);
2071 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2072 assemble_integer (GEN_INT (data
[0]), 2, align
, 1);
2073 assemble_integer (GEN_INT (data
[1]), 1, nalign
, 1);
2084 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2085 assemble_integer (GEN_INT (l
), 1, align
, 1);
2088 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2089 assemble_integer (GEN_INT (data
[0]), 1, align
, 1);
2090 assemble_integer (GEN_INT (data
[1]), 1, nalign
, 1);
2102 /* Given an expression EXP with a constant value,
2103 reduce it to the sum of an assembler symbol and an integer.
2104 Store them both in the structure *VALUE.
2105 Abort if EXP does not reduce. */
2110 HOST_WIDE_INT offset
;
2114 decode_addr_const (exp
, value
)
2116 struct addr_const
*value
;
2118 tree target
= TREE_OPERAND (exp
, 0);
2124 if (TREE_CODE (target
) == COMPONENT_REF
2125 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2128 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2129 target
= TREE_OPERAND (target
, 0);
2131 else if (TREE_CODE (target
) == ARRAY_REF
2132 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2134 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2135 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2136 target
= TREE_OPERAND (target
, 0);
2142 switch (TREE_CODE (target
))
2146 x
= DECL_RTL (target
);
2150 x
= gen_rtx_MEM (FUNCTION_MODE
,
2151 gen_rtx_LABEL_REF (VOIDmode
,
2152 label_rtx (TREE_OPERAND (exp
, 0))));
2160 /* This constant should have been output already, but we can't simply
2161 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2162 x
= output_constant_def (target
, 1);
2169 if (GET_CODE (x
) != MEM
)
2174 value
->offset
= offset
;
2177 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2178 enum kind
{ RTX_UNKNOWN
, RTX_DOUBLE
, RTX_INT
, RTX_VECTOR
, RTX_UNSPEC
};
2181 ENUM_BITFIELD(kind
) kind
: 16;
2182 ENUM_BITFIELD(machine_mode
) mode
: 16;
2185 struct addr_const addr
;
2186 struct {HOST_WIDE_INT high
, low
;} di
;
2188 /* The max vector size we have is 8 wide. This should be enough. */
2189 HOST_WIDE_INT veclo
[16];
2190 HOST_WIDE_INT vechi
[16];
2194 /* Uniquize all constants that appear in memory.
2195 Each constant in memory thus far output is recorded
2196 in `const_hash_table' with a `struct constant_descriptor'
2197 that contains a polish representation of the value of
2200 We cannot store the trees in the hash table
2201 because the trees may be temporary. */
2203 struct constant_descriptor
2205 struct constant_descriptor
*next
;
2208 /* Make sure the data is reasonably aligned. */
2211 unsigned char contents
[1];
2212 #ifdef HAVE_LONG_DOUBLE
2221 #define MAX_HASH_TABLE 1009
2222 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2224 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2225 out a string constant, we defer output of the constants until we know
2226 they are actually used. This will be if something takes its address or if
2227 there is a usage of the string in the RTL of a function. */
2229 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2231 struct deferred_string
2238 static htab_t const_str_htab
;
2240 /* Mark a const_hash_table descriptor for GC. */
2243 mark_const_hash_entry (ptr
)
2246 struct constant_descriptor
*desc
= * (struct constant_descriptor
**) ptr
;
2250 ggc_mark_rtx (desc
->rtl
);
2255 /* Mark the hash-table element X (which is really a pointer to an
2256 struct deferred_string *). */
2259 mark_const_str_htab_1 (x
, data
)
2261 void *data ATTRIBUTE_UNUSED
;
2263 ggc_mark_tree (((struct deferred_string
*) *x
)->exp
);
2267 /* Mark a const_str_htab for GC. */
2270 mark_const_str_htab (htab
)
2273 htab_traverse (*((htab_t
*) htab
), mark_const_str_htab_1
, NULL
);
2276 /* Returns a hash code for X (which is a really a
2277 struct deferred_string *). */
2280 const_str_htab_hash (x
)
2283 return STRHASH (((const struct deferred_string
*) x
)->label
);
2286 /* Returns non-zero if the value represented by X (which is really a
2287 struct deferred_string *) is the same as that given by Y
2288 (which is really a char *). */
2291 const_str_htab_eq (x
, y
)
2295 return (((const struct deferred_string
*) x
)->label
== (const char *) y
);
2298 /* Delete the hash table entry dfsp. */
2301 const_str_htab_del (dfsp
)
2307 /* Compute a hash code for a constant expression. */
2315 enum tree_code code
= TREE_CODE (exp
);
2317 /* Either set P and LEN to the address and len of something to hash and
2318 exit the switch or return a value. */
2323 p
= (char *) &TREE_INT_CST (exp
);
2324 len
= sizeof TREE_INT_CST (exp
);
2328 p
= (char *) &TREE_REAL_CST (exp
);
2329 len
= sizeof TREE_REAL_CST (exp
);
2333 p
= TREE_STRING_POINTER (exp
);
2334 len
= TREE_STRING_LENGTH (exp
);
2338 return (const_hash (TREE_REALPART (exp
)) * 5
2339 + const_hash (TREE_IMAGPART (exp
)));
2342 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2346 len
= int_size_in_bytes (TREE_TYPE (exp
));
2347 tmp
= (char *) alloca (len
);
2348 get_set_constructor_bytes (exp
, (unsigned char *) tmp
, len
);
2356 /* For record type, include the type in the hashing.
2357 We do not do so for array types
2358 because (1) the sizes of the elements are sufficient
2359 and (2) distinct array types can have the same constructor.
2360 Instead, we include the array size because the constructor could
2362 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2363 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2366 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2367 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2369 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2370 if (TREE_VALUE (link
))
2372 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2379 struct addr_const value
;
2381 decode_addr_const (exp
, &value
);
2382 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2384 /* Don't hash the address of the SYMBOL_REF;
2385 only use the offset and the symbol name. */
2387 p
= XSTR (value
.base
, 0);
2388 for (i
= 0; p
[i
] != 0; i
++)
2389 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2391 else if (GET_CODE (value
.base
) == LABEL_REF
)
2392 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2396 hi
&= (1 << HASHBITS
) - 1;
2397 hi
%= MAX_HASH_TABLE
;
2403 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2404 + const_hash (TREE_OPERAND (exp
, 1)));
2408 case NON_LVALUE_EXPR
:
2409 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2412 /* A language specific constant. Just hash the code. */
2413 return (int) code
% MAX_HASH_TABLE
;
2416 /* Compute hashing function */
2418 for (i
= 0; i
< len
; i
++)
2419 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2421 hi
&= (1 << HASHBITS
) - 1;
2422 hi
%= MAX_HASH_TABLE
;
2426 /* Compare a constant expression EXP with a constant-descriptor DESC.
2427 Return 1 if DESC describes a constant with the same value as EXP. */
2430 compare_constant (exp
, desc
)
2432 struct constant_descriptor
*desc
;
2434 return 0 != compare_constant_1 (exp
, desc
->u
.contents
);
2437 /* Compare constant expression EXP with a substring P of a constant descriptor.
2438 If they match, return a pointer to the end of the substring matched.
2439 If they do not match, return 0.
2441 Since descriptors are written in polish prefix notation,
2442 this function can be used recursively to test one operand of EXP
2443 against a subdescriptor, and if it succeeds it returns the
2444 address of the subdescriptor for the next operand. */
2446 static const unsigned char *
2447 compare_constant_1 (exp
, p
)
2449 const unsigned char *p
;
2451 const unsigned char *strp
;
2453 enum tree_code code
= TREE_CODE (exp
);
2455 if (code
!= (enum tree_code
) *p
++)
2458 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2459 switch, or return the result of the comparison. */
2464 /* Integer constants are the same only if the same width of type. */
2465 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2468 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2469 len
= sizeof TREE_INT_CST (exp
);
2473 /* Real constants are the same only if the same width of type. */
2474 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2477 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2478 len
= sizeof TREE_REAL_CST (exp
);
2482 if (flag_writable_strings
)
2485 if ((enum machine_mode
) *p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2488 strp
= (const unsigned char *) TREE_STRING_POINTER (exp
);
2489 len
= TREE_STRING_LENGTH (exp
);
2490 if (memcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2491 sizeof TREE_STRING_LENGTH (exp
)))
2494 p
+= sizeof TREE_STRING_LENGTH (exp
);
2498 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2502 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2505 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2507 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2508 unsigned char *tmp
= (unsigned char *) alloca (len
);
2510 get_set_constructor_bytes (exp
, tmp
, len
);
2511 strp
= (unsigned char *) tmp
;
2512 if (memcmp ((char *) &xlen
, p
, sizeof xlen
))
2521 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2523 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2524 int have_purpose
= 0;
2526 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2527 if (TREE_PURPOSE (link
))
2530 if (memcmp ((char *) &length
, p
, sizeof length
))
2535 /* For record constructors, insist that the types match.
2536 For arrays, just verify both constructors are for arrays.
2537 Then insist that either both or none have any TREE_PURPOSE
2539 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2540 type
= TREE_TYPE (exp
);
2544 if (memcmp ((char *) &type
, p
, sizeof type
))
2547 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2549 if (memcmp ((char *) &mode
, p
, sizeof mode
))
2557 if (memcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2560 p
+= sizeof have_purpose
;
2562 /* For arrays, insist that the size in bytes match. */
2563 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2565 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2567 if (memcmp ((char *) &size
, p
, sizeof size
))
2573 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2575 if (TREE_VALUE (link
))
2577 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2584 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2590 if (TREE_PURPOSE (link
)
2591 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2593 if (memcmp ((char *) &TREE_PURPOSE (link
), p
,
2594 sizeof TREE_PURPOSE (link
)))
2597 p
+= sizeof TREE_PURPOSE (link
);
2599 else if (TREE_PURPOSE (link
))
2601 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2604 else if (have_purpose
)
2608 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2620 struct addr_const value
;
2622 decode_addr_const (exp
, &value
);
2623 strp
= (unsigned char *) &value
.offset
;
2624 len
= sizeof value
.offset
;
2625 /* Compare the offset. */
2627 if (*p
++ != *strp
++)
2630 /* Compare symbol name. */
2631 strp
= (const unsigned char *) XSTR (value
.base
, 0);
2632 len
= strlen ((const char *) strp
) + 1;
2639 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2643 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2647 case NON_LVALUE_EXPR
:
2648 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2652 tree
new = (*lang_hooks
.expand_constant
) (exp
);
2655 return compare_constant_1 (new, p
);
2661 /* Compare constant contents. */
2663 if (*p
++ != *strp
++)
2669 /* Construct a constant descriptor for the expression EXP.
2670 It is up to the caller to enter the descriptor in the hash table. */
2672 static struct constant_descriptor
*
2673 record_constant (exp
)
2676 struct constant_descriptor
*next
= 0;
2681 /* Make a struct constant_descriptor. The first three pointers will
2682 be filled in later. Here we just leave space for them. */
2684 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2685 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2686 obstack_grow (&permanent_obstack
, (char *) &rtl
, sizeof rtl
);
2688 /* Align the descriptor for the data payload. */
2689 pad
= (offsetof (struct constant_descriptor
, u
)
2690 - offsetof(struct constant_descriptor
, rtl
)
2691 - sizeof(next
->rtl
));
2693 obstack_blank (&permanent_obstack
, pad
);
2695 record_constant_1 (exp
);
2696 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2699 /* Add a description of constant expression EXP
2700 to the object growing in `permanent_obstack'.
2701 No need to return its address; the caller will get that
2702 from the obstack when the object is complete. */
2705 record_constant_1 (exp
)
2708 const unsigned char *strp
;
2710 enum tree_code code
= TREE_CODE (exp
);
2712 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2717 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2718 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2719 len
= sizeof TREE_INT_CST (exp
);
2723 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2724 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2725 len
= sizeof TREE_REAL_CST (exp
);
2729 if (flag_writable_strings
)
2732 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2733 strp
= (const unsigned char *) TREE_STRING_POINTER (exp
);
2734 len
= TREE_STRING_LENGTH (exp
);
2735 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2736 sizeof TREE_STRING_LENGTH (exp
));
2740 record_constant_1 (TREE_REALPART (exp
));
2741 record_constant_1 (TREE_IMAGPART (exp
));
2745 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2747 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2748 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2749 obstack_blank (&permanent_obstack
, nbytes
);
2750 get_set_constructor_bytes
2751 (exp
, (unsigned char *) permanent_obstack
.next_free
- nbytes
,
2758 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2759 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2761 int have_purpose
= 0;
2763 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2764 if (TREE_PURPOSE (link
))
2767 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2769 /* For record constructors, insist that the types match.
2770 For arrays, just verify both constructors are for arrays
2771 of the same mode. Then insist that either both or none
2772 have any TREE_PURPOSE values. */
2773 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2774 type
= TREE_TYPE (exp
);
2778 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2779 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2780 obstack_grow (&permanent_obstack
, &mode
, sizeof mode
);
2782 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2783 sizeof have_purpose
);
2785 /* For arrays, insist that the size in bytes match. */
2786 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2788 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2789 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2792 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2794 if (TREE_VALUE (link
))
2795 record_constant_1 (TREE_VALUE (link
));
2800 obstack_grow (&permanent_obstack
,
2801 (char *) &zero
, sizeof zero
);
2804 if (TREE_PURPOSE (link
)
2805 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2806 obstack_grow (&permanent_obstack
,
2807 (char *) &TREE_PURPOSE (link
),
2808 sizeof TREE_PURPOSE (link
));
2809 else if (TREE_PURPOSE (link
))
2810 record_constant_1 (TREE_PURPOSE (link
));
2811 else if (have_purpose
)
2815 obstack_grow (&permanent_obstack
,
2816 (char *) &zero
, sizeof zero
);
2824 struct addr_const value
;
2826 decode_addr_const (exp
, &value
);
2827 /* Record the offset. */
2828 obstack_grow (&permanent_obstack
,
2829 (char *) &value
.offset
, sizeof value
.offset
);
2831 switch (GET_CODE (value
.base
))
2834 /* Record the symbol name. */
2835 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2836 strlen (XSTR (value
.base
, 0)) + 1);
2839 /* Record the address of the CODE_LABEL. It may not have
2840 been emitted yet, so it's UID may be zero. But pointer
2841 identity is good enough. */
2842 obstack_grow (&permanent_obstack
, &XEXP (value
.base
, 0),
2854 record_constant_1 (TREE_OPERAND (exp
, 0));
2855 record_constant_1 (TREE_OPERAND (exp
, 1));
2860 case NON_LVALUE_EXPR
:
2861 record_constant_1 (TREE_OPERAND (exp
, 0));
2866 tree
new = (*lang_hooks
.expand_constant
) (exp
);
2869 record_constant_1 (new);
2874 /* Record constant contents. */
2875 obstack_grow (&permanent_obstack
, strp
, len
);
2878 /* Record a list of constant expressions that were passed to
2879 output_constant_def but that could not be output right away. */
2881 struct deferred_constant
2883 struct deferred_constant
*next
;
2889 static struct deferred_constant
*deferred_constants
;
2891 /* Another list of constants which should be output after the
2893 static struct deferred_constant
*after_function_constants
;
2895 /* Nonzero means defer output of addressed subconstants
2896 (i.e., those for which output_constant_def is called.) */
2897 static int defer_addressed_constants_flag
;
2899 /* Start deferring output of subconstants. */
2902 defer_addressed_constants ()
2904 defer_addressed_constants_flag
++;
2907 /* Stop deferring output of subconstants,
2908 and output now all those that have been deferred. */
2911 output_deferred_addressed_constants ()
2913 struct deferred_constant
*p
, *next
;
2915 defer_addressed_constants_flag
--;
2917 if (defer_addressed_constants_flag
> 0)
2920 for (p
= deferred_constants
; p
; p
= next
)
2922 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2927 deferred_constants
= 0;
2930 /* Output any constants which should appear after a function. */
2933 output_after_function_constants ()
2935 struct deferred_constant
*p
, *next
;
2937 for (p
= after_function_constants
; p
; p
= next
)
2939 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2944 after_function_constants
= 0;
2947 /* Make a copy of the whole tree structure for a constant.
2948 This handles the same types of nodes that compare_constant
2949 and record_constant handle. */
2955 switch (TREE_CODE (exp
))
2958 /* For ADDR_EXPR, we do not want to copy the decl whose address
2959 is requested. We do want to copy constants though. */
2960 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2961 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2962 copy_constant (TREE_OPERAND (exp
, 0)));
2964 return copy_node (exp
);
2969 return copy_node (exp
);
2972 return build_complex (TREE_TYPE (exp
),
2973 copy_constant (TREE_REALPART (exp
)),
2974 copy_constant (TREE_IMAGPART (exp
)));
2978 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2979 copy_constant (TREE_OPERAND (exp
, 0)),
2980 copy_constant (TREE_OPERAND (exp
, 1)));
2984 case NON_LVALUE_EXPR
:
2985 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2986 copy_constant (TREE_OPERAND (exp
, 0)));
2990 tree copy
= copy_node (exp
);
2991 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2994 CONSTRUCTOR_ELTS (copy
) = list
;
2995 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2996 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2997 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2998 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2999 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
3009 /* Return an rtx representing a reference to constant data in memory
3010 for the constant expression EXP.
3012 If assembler code for such a constant has already been output,
3013 return an rtx to refer to it.
3014 Otherwise, output such a constant in memory (or defer it for later)
3015 and generate an rtx for it.
3017 If DEFER is non-zero, the output of string constants can be deferred
3018 and output only if referenced in the function after all optimizations.
3020 The TREE_CST_RTL of EXP is set up to point to that rtx.
3021 The const_hash_table records which constants already have label strings. */
3024 output_constant_def (exp
, defer
)
3029 struct constant_descriptor
*desc
;
3030 struct deferred_string
**defstr
;
3034 int after_function
= 0;
3038 /* We can't just use the saved RTL if this is a defererred string constant
3039 and we are not to defer anymore. */
3040 if (TREE_CODE (exp
) != INTEGER_CST
&& TREE_CST_RTL (exp
)
3041 && (defer
|| !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp
), 0))))
3042 return TREE_CST_RTL (exp
);
3044 /* Make sure any other constants whose addresses appear in EXP
3045 are assigned label numbers. */
3047 reloc
= output_addressed_constants (exp
);
3049 /* Compute hash code of EXP. Search the descriptors for that hash code
3050 to see if any of them describes EXP. If yes, the descriptor records
3051 the label number already assigned. */
3053 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
3055 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
3056 if (compare_constant (exp
, desc
))
3061 /* No constant equal to EXP is known to have been output.
3062 Make a constant descriptor to enter EXP in the hash table.
3063 Assign the label number and record it in the descriptor for
3064 future calls to this function to find. */
3066 /* Create a string containing the label name, in LABEL. */
3067 labelno
= const_labelno
++;
3068 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3070 desc
= record_constant (exp
);
3071 desc
->next
= const_hash_table
[hash
];
3072 desc
->label
= ggc_strdup (label
);
3073 const_hash_table
[hash
] = desc
;
3075 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3077 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
3078 gen_rtx_SYMBOL_REF (Pmode
, desc
->label
));
3080 set_mem_attributes (rtl
, exp
, 1);
3081 set_mem_alias_set (rtl
, 0);
3082 set_mem_alias_set (rtl
, const_alias_set
);
3089 if (TREE_CODE (exp
) != INTEGER_CST
)
3090 TREE_CST_RTL (exp
) = rtl
;
3092 /* Optionally set flags or add text to the name to record information
3093 such as that it is a function name. If the name is changed, the macro
3094 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3095 /* A previously-processed constant would already have section info
3099 /* Take care not to invoke targetm.encode_section_info for
3100 constants which don't have a TREE_CST_RTL. */
3101 if (TREE_CODE (exp
) != INTEGER_CST
)
3102 (*targetm
.encode_section_info
) (exp
, true);
3105 desc
->label
= XSTR (XEXP (desc
->rtl
, 0), 0);
3108 #ifdef CONSTANT_AFTER_FUNCTION_P
3109 if (current_function_decl
!= 0
3110 && CONSTANT_AFTER_FUNCTION_P (exp
))
3115 && STRING_POOL_ADDRESS_P (XEXP (rtl
, 0))
3116 && (!defer
|| defer_addressed_constants_flag
|| after_function
))
3118 defstr
= (struct deferred_string
**)
3119 htab_find_slot_with_hash (const_str_htab
, desc
->label
,
3120 STRHASH (desc
->label
), NO_INSERT
);
3123 /* If the string is currently deferred but we need to output it now,
3124 remove it from deferred string hash table. */
3126 labelno
= (*defstr
)->labelno
;
3127 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 0;
3128 htab_clear_slot (const_str_htab
, (void **) defstr
);
3132 /* If this is the first time we've seen this particular constant,
3133 output it (or defer its output for later). */
3136 if (defer_addressed_constants_flag
|| after_function
)
3138 struct deferred_constant
*p
3139 = (struct deferred_constant
*)
3140 xmalloc (sizeof (struct deferred_constant
));
3142 p
->exp
= copy_constant (exp
);
3144 p
->labelno
= labelno
;
3147 p
->next
= after_function_constants
;
3148 after_function_constants
= p
;
3152 p
->next
= deferred_constants
;
3153 deferred_constants
= p
;
3158 /* Do no output if -fsyntax-only. */
3159 if (! flag_syntax_only
)
3161 if (TREE_CODE (exp
) != STRING_CST
3163 || flag_writable_strings
3164 || (defstr
= (struct deferred_string
**)
3165 htab_find_slot_with_hash (const_str_htab
,
3167 STRHASH (desc
->label
),
3169 output_constant_def_contents (exp
, reloc
, labelno
);
3172 struct deferred_string
*p
;
3174 p
= (struct deferred_string
*)
3175 xmalloc (sizeof (struct deferred_string
));
3177 p
->exp
= copy_constant (exp
);
3178 p
->label
= desc
->label
;
3179 p
->labelno
= labelno
;
3181 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 1;
3190 /* Now output assembler code to define the label for EXP,
3191 and follow it with the data of EXP. */
3194 output_constant_def_contents (exp
, reloc
, labelno
)
3201 /* Align the location counter as required by EXP's data type. */
3202 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3203 #ifdef CONSTANT_ALIGNMENT
3204 align
= CONSTANT_ALIGNMENT (exp
, align
);
3207 if (IN_NAMED_SECTION (exp
))
3208 named_section (exp
, NULL
, reloc
);
3210 (*targetm
.asm_out
.select_section
) (exp
, reloc
, align
);
3212 if (align
> BITS_PER_UNIT
)
3214 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3217 /* Output the label itself. */
3218 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3220 /* Output the value of EXP. */
3221 output_constant (exp
,
3222 (TREE_CODE (exp
) == STRING_CST
3223 ? MAX (TREE_STRING_LENGTH (exp
),
3224 int_size_in_bytes (TREE_TYPE (exp
)))
3225 : int_size_in_bytes (TREE_TYPE (exp
))),
3230 /* Structure to represent sufficient information about a constant so that
3231 it can be output when the constant pool is output, so that function
3232 integration can be done, and to simplify handling on machines that reference
3233 constant pool as base+displacement. */
3235 struct pool_constant
3237 struct constant_descriptor
*desc
;
3238 struct pool_constant
*next
, *next_sym
;
3240 enum machine_mode mode
;
3243 HOST_WIDE_INT offset
;
3247 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3248 The argument is XSTR (... , 0) */
3250 #define SYMHASH(LABEL) \
3251 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3253 /* Initialize constant pool hashing for a new function. */
3256 init_varasm_status (f
)
3259 struct varasm_status
*p
;
3260 p
= (struct varasm_status
*) xmalloc (sizeof (struct varasm_status
));
3262 p
->x_const_rtx_hash_table
3263 = ((struct constant_descriptor
**)
3264 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct constant_descriptor
*)));
3265 p
->x_const_rtx_sym_hash_table
3266 = ((struct pool_constant
**)
3267 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct pool_constant
*)));
3269 p
->x_first_pool
= p
->x_last_pool
= 0;
3270 p
->x_pool_offset
= 0;
3273 /* Mark PC for GC. */
3276 mark_pool_constant (pc
)
3277 struct pool_constant
*pc
;
3282 ggc_mark_rtx (pc
->constant
);
3283 ggc_mark_rtx (pc
->desc
->rtl
);
3288 /* Mark P for GC. */
3291 mark_varasm_status (p
)
3292 struct varasm_status
*p
;
3297 mark_pool_constant (p
->x_first_pool
);
3300 /* Clear out all parts of the state in F that can safely be discarded
3301 after the function has been compiled, to let garbage collection
3302 reclaim the memory. */
3305 free_varasm_status (f
)
3308 struct varasm_status
*p
;
3313 /* Clear out the hash tables. */
3314 for (i
= 0; i
< MAX_RTX_HASH_TABLE
; ++i
)
3316 struct constant_descriptor
*cd
;
3318 cd
= p
->x_const_rtx_hash_table
[i
];
3321 struct constant_descriptor
*next
= cd
->next
;
3328 free (p
->x_const_rtx_hash_table
);
3329 free (p
->x_const_rtx_sym_hash_table
);
3336 /* Express an rtx for a constant integer (perhaps symbolic)
3337 as the sum of a symbol or label plus an explicit integer.
3338 They are stored into VALUE. */
3341 decode_rtx_const (mode
, x
, value
)
3342 enum machine_mode mode
;
3344 struct rtx_const
*value
;
3346 /* Clear the whole structure, including any gaps. */
3347 memset (value
, 0, sizeof (struct rtx_const
));
3349 value
->kind
= RTX_INT
; /* Most usual kind. */
3352 switch (GET_CODE (x
))
3355 value
->kind
= RTX_DOUBLE
;
3356 if (GET_MODE (x
) != VOIDmode
)
3358 value
->mode
= GET_MODE (x
);
3359 REAL_VALUE_FROM_CONST_DOUBLE (value
->un
.du
, x
);
3363 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3364 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3373 units
= CONST_VECTOR_NUNITS (x
);
3374 value
->kind
= RTX_VECTOR
;
3377 for (i
= 0; i
< units
; ++i
)
3379 elt
= CONST_VECTOR_ELT (x
, i
);
3380 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
3382 value
->un
.veclo
[i
] = (HOST_WIDE_INT
) INTVAL (elt
);
3383 value
->un
.vechi
[i
] = 0;
3385 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
3387 value
->un
.veclo
[i
] = (HOST_WIDE_INT
) CONST_DOUBLE_LOW (elt
);
3388 value
->un
.vechi
[i
] = (HOST_WIDE_INT
) CONST_DOUBLE_HIGH (elt
);
3397 value
->un
.addr
.offset
= INTVAL (x
);
3403 value
->un
.addr
.base
= x
;
3408 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3410 value
->un
.addr
.base
= XEXP (x
, 0);
3411 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3413 else if (GET_CODE (x
) == MINUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3415 value
->un
.addr
.base
= XEXP (x
, 0);
3416 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3420 value
->un
.addr
.base
= x
;
3421 value
->un
.addr
.offset
= 0;
3426 value
->kind
= RTX_UNKNOWN
;
3430 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0
3431 && GET_CODE (value
->un
.addr
.base
) == UNSPEC
)
3433 /* For a simple UNSPEC, the base is set to the
3434 operand, the kind field is set to the index of
3435 the unspec expression.
3436 Together with the code below, in case that
3437 the operand is a SYMBOL_REF or LABEL_REF,
3438 the address of the string or the code_label
3439 is taken as base. */
3440 if (XVECLEN (value
->un
.addr
.base
, 0) == 1)
3442 value
->kind
= RTX_UNSPEC
+ XINT (value
->un
.addr
.base
, 1);
3443 value
->un
.addr
.base
= XVECEXP (value
->un
.addr
.base
, 0, 0);
3447 if (value
->kind
> RTX_DOUBLE
&& value
->un
.addr
.base
!= 0)
3448 switch (GET_CODE (value
->un
.addr
.base
))
3451 /* Use the string's address, not the SYMBOL_REF's address,
3452 for the sake of addresses of library routines. */
3453 value
->un
.addr
.base
= (rtx
) XSTR (value
->un
.addr
.base
, 0);
3457 /* For a LABEL_REF, compare labels. */
3458 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3465 /* Given a MINUS expression, simplify it if both sides
3466 include the same symbol. */
3469 simplify_subtraction (x
)
3472 struct rtx_const val0
, val1
;
3474 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3475 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3477 if (val0
.kind
> RTX_DOUBLE
3478 && val0
.kind
== val1
.kind
3479 && val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3480 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3485 /* Compute a hash code for a constant RTL expression. */
3488 const_hash_rtx (mode
, x
)
3489 enum machine_mode mode
;
3495 struct rtx_const value
;
3496 decode_rtx_const (mode
, x
, &value
);
3498 /* Compute hashing function */
3500 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3501 hi
+= ((int *) &value
)[i
];
3503 hi
&= (1 << HASHBITS
) - 1;
3504 hi
%= MAX_RTX_HASH_TABLE
;
3508 /* Compare a constant rtl object X with a constant-descriptor DESC.
3509 Return 1 if DESC describes a constant with the same value as X. */
3512 compare_constant_rtx (mode
, x
, desc
)
3513 enum machine_mode mode
;
3515 struct constant_descriptor
*desc
;
3517 int *p
= (int *) desc
->u
.contents
;
3520 struct rtx_const value
;
3522 decode_rtx_const (mode
, x
, &value
);
3523 strp
= (int *) &value
;
3524 len
= sizeof value
/ sizeof (int);
3526 /* Compare constant contents. */
3528 if (*p
++ != *strp
++)
3534 /* Construct a constant descriptor for the rtl-expression X.
3535 It is up to the caller to enter the descriptor in the hash table. */
3537 static struct constant_descriptor
*
3538 record_constant_rtx (mode
, x
)
3539 enum machine_mode mode
;
3542 struct constant_descriptor
*ptr
;
3544 ptr
= ((struct constant_descriptor
*)
3545 xcalloc (1, (offsetof (struct constant_descriptor
, u
)
3546 + sizeof (struct rtx_const
))));
3547 decode_rtx_const (mode
, x
, (struct rtx_const
*) ptr
->u
.contents
);
3552 /* Given a constant rtx X, return a MEM for the location in memory at which
3553 this constant has been placed. Return 0 if it not has been placed yet. */
3556 mem_for_const_double (x
)
3559 enum machine_mode mode
= GET_MODE (x
);
3560 struct constant_descriptor
*desc
;
3562 for (desc
= const_rtx_hash_table
[const_hash_rtx (mode
, x
)]; desc
;
3564 if (compare_constant_rtx (mode
, x
, desc
))
3570 /* Given a constant rtx X, make (or find) a memory constant for its value
3571 and return a MEM rtx to refer to it in memory. */
3574 force_const_mem (mode
, x
)
3575 enum machine_mode mode
;
3579 struct constant_descriptor
*desc
;
3582 struct pool_constant
*pool
;
3585 /* Compute hash code of X. Search the descriptors for that hash code
3586 to see if any of them describes X. If yes, we have an rtx to use. */
3587 hash
= const_hash_rtx (mode
, x
);
3588 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3589 if (compare_constant_rtx (mode
, x
, desc
))
3592 /* No constant equal to X is known to have been output.
3593 Make a constant descriptor to enter X in the hash table
3594 and make a MEM for it. */
3595 desc
= record_constant_rtx (mode
, x
);
3596 desc
->next
= const_rtx_hash_table
[hash
];
3597 const_rtx_hash_table
[hash
] = desc
;
3599 /* Align the location counter as required by EXP's data type. */
3600 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3601 #ifdef CONSTANT_ALIGNMENT
3602 align
= CONSTANT_ALIGNMENT (make_tree ((*lang_hooks
.types
.type_for_mode
)
3603 (mode
, 0), x
), align
);
3606 pool_offset
+= (align
/ BITS_PER_UNIT
) - 1;
3607 pool_offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3609 if (GET_CODE (x
) == LABEL_REF
)
3610 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3612 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3613 pool
= (struct pool_constant
*) ggc_alloc (sizeof (struct pool_constant
));
3617 pool
->labelno
= const_labelno
;
3618 pool
->align
= align
;
3619 pool
->offset
= pool_offset
;
3626 last_pool
->next
= pool
;
3629 pool_offset
+= GET_MODE_SIZE (mode
);
3631 /* Create a string containing the label name, in LABEL. */
3632 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3636 /* Construct the SYMBOL_REF and the MEM. */
3638 pool
->desc
->rtl
= def
3639 = gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
)));
3640 set_mem_alias_set (def
, const_alias_set
);
3641 set_mem_attributes (def
, (*lang_hooks
.types
.type_for_mode
) (mode
, 0), 1);
3642 RTX_UNCHANGING_P (def
) = 1;
3644 /* Add label to symbol hash table. */
3645 hash
= SYMHASH (XSTR (XEXP (def
, 0), 0));
3646 pool
->next_sym
= const_rtx_sym_hash_table
[hash
];
3647 const_rtx_sym_hash_table
[hash
] = pool
;
3649 /* Mark the symbol_ref as belonging to this constants pool. */
3650 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3651 current_function_uses_const_pool
= 1;
3656 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3657 the corresponding pool_constant structure. */
3659 static struct pool_constant
*
3660 find_pool_constant (f
, addr
)
3664 struct pool_constant
*pool
;
3665 const char *label
= XSTR (addr
, 0);
3667 for (pool
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; pool
;
3668 pool
= pool
->next_sym
)
3669 if (XSTR (XEXP (pool
->desc
->rtl
, 0), 0) == label
)
3675 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3678 get_pool_constant (addr
)
3681 return (find_pool_constant (cfun
, addr
))->constant
;
3684 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3685 and whether it has been output or not. */
3688 get_pool_constant_mark (addr
, pmarked
)
3692 struct pool_constant
*pool
= find_pool_constant (cfun
, addr
);
3693 *pmarked
= (pool
->mark
!= 0);
3694 return pool
->constant
;
3697 /* Likewise, but for the constant pool of a specific function. */
3700 get_pool_constant_for_function (f
, addr
)
3704 return (find_pool_constant (f
, addr
))->constant
;
3707 /* Similar, return the mode. */
3710 get_pool_mode (addr
)
3713 return (find_pool_constant (cfun
, addr
))->mode
;
3717 get_pool_mode_for_function (f
, addr
)
3721 return (find_pool_constant (f
, addr
))->mode
;
3724 /* Similar, return the offset in the constant pool. */
3727 get_pool_offset (addr
)
3730 return (find_pool_constant (cfun
, addr
))->offset
;
3733 /* Return the size of the constant pool. */
3741 /* Write all the constants in the constant pool. */
3744 output_constant_pool (fnname
, fndecl
)
3745 const char *fnname ATTRIBUTE_UNUSED
;
3746 tree fndecl ATTRIBUTE_UNUSED
;
3748 struct pool_constant
*pool
;
3752 /* It is possible for gcc to call force_const_mem and then to later
3753 discard the instructions which refer to the constant. In such a
3754 case we do not need to output the constant. */
3755 mark_constant_pool ();
3757 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3758 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3761 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3770 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3771 whose CODE_LABEL has been deleted. This can occur if a jump table
3772 is eliminated by optimization. If so, write a constant of zero
3773 instead. Note that this can also happen by turning the
3774 CODE_LABEL into a NOTE. */
3775 /* ??? This seems completely and utterly wrong. Certainly it's
3776 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3777 functioning even with INSN_DELETED_P and friends. */
3780 switch (GET_CODE (x
))
3783 if (GET_CODE (XEXP (x
, 0)) != PLUS
3784 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3786 tmp
= XEXP (XEXP (x
, 0), 0);
3791 if (INSN_DELETED_P (tmp
)
3792 || (GET_CODE (tmp
) == NOTE
3793 && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_DELETED
))
3804 /* First switch to correct section. */
3805 (*targetm
.asm_out
.select_rtx_section
) (pool
->mode
, x
, pool
->align
);
3807 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3808 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3809 pool
->align
, pool
->labelno
, done
);
3812 assemble_align (pool
->align
);
3814 /* Output the label. */
3815 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3817 /* Output the value of the constant itself. */
3818 switch (GET_MODE_CLASS (pool
->mode
))
3821 if (GET_CODE (x
) != CONST_DOUBLE
)
3824 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3825 assemble_real (r
, pool
->mode
, pool
->align
);
3829 case MODE_PARTIAL_INT
:
3830 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), pool
->align
, 1);
3833 case MODE_VECTOR_FLOAT
:
3838 if (GET_CODE (x
) != CONST_VECTOR
)
3841 units
= CONST_VECTOR_NUNITS (x
);
3843 for (i
= 0; i
< units
; i
++)
3845 elt
= CONST_VECTOR_ELT (x
, i
);
3846 REAL_VALUE_FROM_CONST_DOUBLE (r
, elt
);
3847 assemble_real (r
, GET_MODE_INNER (pool
->mode
), pool
->align
);
3852 case MODE_VECTOR_INT
:
3857 if (GET_CODE (x
) != CONST_VECTOR
)
3860 units
= CONST_VECTOR_NUNITS (x
);
3862 for (i
= 0; i
< units
; i
++)
3864 elt
= CONST_VECTOR_ELT (x
, i
);
3865 assemble_integer (elt
, GET_MODE_UNIT_SIZE (pool
->mode
),
3875 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3880 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3881 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3884 /* Done with this pool. */
3885 first_pool
= last_pool
= 0;
3888 /* Look through the instructions for this function, and mark all the
3889 entries in the constant pool which are actually being used.
3890 Emit used deferred strings. */
3893 mark_constant_pool ()
3897 struct pool_constant
*pool
;
3899 if (first_pool
== 0 && htab_elements (const_str_htab
) == 0)
3902 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3905 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3907 mark_constants (PATTERN (insn
));
3909 for (link
= current_function_epilogue_delay_list
;
3911 link
= XEXP (link
, 1))
3913 insn
= XEXP (link
, 0);
3916 mark_constants (PATTERN (insn
));
3920 /* Look through appropriate parts of X, marking all entries in the
3921 constant pool which are actually being used. Entries that are only
3922 referenced by other constants are also marked as used. Emit
3923 deferred strings that are used. */
3930 const char *format_ptr
;
3935 if (GET_CODE (x
) == SYMBOL_REF
)
3937 mark_constant (&x
, NULL
);
3941 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3942 insns, not any notes that may be attached. We don't want to mark
3943 a constant just because it happens to appear in a REG_EQUIV note. */
3946 mark_constants (PATTERN (x
));
3950 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3952 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3954 switch (*format_ptr
++)
3957 mark_constants (XEXP (x
, i
));
3961 if (XVEC (x
, i
) != 0)
3965 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3966 mark_constants (XVECEXP (x
, i
, j
));
3985 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3986 to as used. Emit referenced deferred strings. This function can
3987 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3990 mark_constant (current_rtx
, data
)
3992 void *data ATTRIBUTE_UNUSED
;
3994 rtx x
= *current_rtx
;
3999 else if (GET_CODE (x
) == SYMBOL_REF
)
4001 if (CONSTANT_POOL_ADDRESS_P (x
))
4003 struct pool_constant
*pool
= find_pool_constant (cfun
, x
);
4004 if (pool
->mark
== 0)
4007 for_each_rtx (&(pool
->constant
), &mark_constant
, NULL
);
4012 else if (STRING_POOL_ADDRESS_P (x
))
4014 struct deferred_string
**defstr
;
4016 defstr
= (struct deferred_string
**)
4017 htab_find_slot_with_hash (const_str_htab
, XSTR (x
, 0),
4018 STRHASH (XSTR (x
, 0)), NO_INSERT
);
4021 struct deferred_string
*p
= *defstr
;
4023 STRING_POOL_ADDRESS_P (x
) = 0;
4024 output_constant_def_contents (p
->exp
, 0, p
->labelno
);
4025 htab_clear_slot (const_str_htab
, (void **) defstr
);
4032 /* Find all the constants whose addresses are referenced inside of EXP,
4033 and make sure assembler code with a label has been output for each one.
4034 Indicate whether an ADDR_EXPR has been encountered. */
4037 output_addressed_constants (exp
)
4043 /* Give the front-end a chance to convert VALUE to something that
4044 looks more like a constant to the back-end. */
4045 exp
= (*lang_hooks
.expand_constant
) (exp
);
4047 switch (TREE_CODE (exp
))
4050 /* Go inside any operations that get_inner_reference can handle and see
4051 if what's inside is a constant: no need to do anything here for
4052 addresses of variables or functions. */
4053 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4054 tem
= TREE_OPERAND (tem
, 0))
4057 if (TREE_CODE_CLASS (TREE_CODE (tem
)) == 'c'
4058 || TREE_CODE (tem
) == CONSTRUCTOR
)
4059 output_constant_def (tem
, 0);
4061 if (TREE_PUBLIC (tem
))
4069 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
4070 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
4075 case NON_LVALUE_EXPR
:
4076 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
4080 for (tem
= CONSTRUCTOR_ELTS (exp
); tem
; tem
= TREE_CHAIN (tem
))
4081 if (TREE_VALUE (tem
) != 0)
4082 reloc
|= output_addressed_constants (TREE_VALUE (tem
));
4092 /* Return nonzero if VALUE is a valid constant-valued expression
4093 for use in initializing a static variable; one that can be an
4094 element of a "constant" initializer.
4096 Return null_pointer_node if the value is absolute;
4097 if it is relocatable, return the variable that determines the relocation.
4098 We assume that VALUE has been folded as much as possible;
4099 therefore, we do not need to check for such things as
4100 arithmetic-combinations of integers. */
4103 initializer_constant_valid_p (value
, endtype
)
4107 /* Give the front-end a chance to convert VALUE to something that
4108 looks more like a constant to the back-end. */
4109 value
= (*lang_hooks
.expand_constant
) (value
);
4111 switch (TREE_CODE (value
))
4114 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
4115 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
4116 && TREE_CONSTANT (value
)
4117 && CONSTRUCTOR_ELTS (value
))
4119 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
4122 return TREE_STATIC (value
) ? null_pointer_node
: 0;
4129 return null_pointer_node
;
4133 return staticp (TREE_OPERAND (value
, 0)) ? TREE_OPERAND (value
, 0) : 0;
4135 case VIEW_CONVERT_EXPR
:
4136 case NON_LVALUE_EXPR
:
4137 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4141 /* Allow conversions between pointer types. */
4142 if (POINTER_TYPE_P (TREE_TYPE (value
))
4143 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4144 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4146 /* Allow conversions between real types. */
4147 if (FLOAT_TYPE_P (TREE_TYPE (value
))
4148 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4149 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4151 /* Allow length-preserving conversions between integer types. */
4152 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4153 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4154 && (TYPE_PRECISION (TREE_TYPE (value
))
4155 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4156 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4158 /* Allow conversions between other integer types only if
4160 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4161 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4163 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4165 if (inner
== null_pointer_node
)
4166 return null_pointer_node
;
4170 /* Allow (int) &foo provided int is as wide as a pointer. */
4171 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4172 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4173 && (TYPE_PRECISION (TREE_TYPE (value
))
4174 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4175 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4178 /* Likewise conversions from int to pointers, but also allow
4179 conversions from 0. */
4180 if (POINTER_TYPE_P (TREE_TYPE (value
))
4181 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4183 if (integer_zerop (TREE_OPERAND (value
, 0)))
4184 return null_pointer_node
;
4185 else if (TYPE_PRECISION (TREE_TYPE (value
))
4186 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
4187 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4191 /* Allow conversions to union types if the value inside is okay. */
4192 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4193 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4198 if (! INTEGRAL_TYPE_P (endtype
)
4199 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4201 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4203 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4205 /* If either term is absolute, use the other terms relocation. */
4206 if (valid0
== null_pointer_node
)
4208 if (valid1
== null_pointer_node
)
4214 if (! INTEGRAL_TYPE_P (endtype
)
4215 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4217 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4219 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4221 /* Win if second argument is absolute. */
4222 if (valid1
== null_pointer_node
)
4224 /* Win if both arguments have the same relocation.
4225 Then the value is absolute. */
4226 if (valid0
== valid1
&& valid0
!= 0)
4227 return null_pointer_node
;
4229 /* Since GCC guarantees that string constants are unique in the
4230 generated code, a subtraction between two copies of the same
4231 constant string is absolute. */
4232 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
&&
4233 valid1
&& TREE_CODE (valid1
) == STRING_CST
&&
4234 TREE_STRING_POINTER (valid0
) == TREE_STRING_POINTER (valid1
))
4235 return null_pointer_node
;
4238 /* Support differences between labels. */
4239 if (INTEGRAL_TYPE_P (endtype
))
4242 op0
= TREE_OPERAND (value
, 0);
4243 op1
= TREE_OPERAND (value
, 1);
4245 /* Like STRIP_NOPS except allow the operand mode to widen.
4246 This works around a feature of fold that simplfies
4247 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4248 that the narrower operation is cheaper. */
4250 while (TREE_CODE (op0
) == NOP_EXPR
4251 || TREE_CODE (op0
) == CONVERT_EXPR
4252 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4254 tree inner
= TREE_OPERAND (op0
, 0);
4255 if (inner
== error_mark_node
4256 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4257 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4258 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4263 while (TREE_CODE (op1
) == NOP_EXPR
4264 || TREE_CODE (op1
) == CONVERT_EXPR
4265 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4267 tree inner
= TREE_OPERAND (op1
, 0);
4268 if (inner
== error_mark_node
4269 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4270 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4271 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4276 if (TREE_CODE (op0
) == ADDR_EXPR
4277 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
4278 && TREE_CODE (op1
) == ADDR_EXPR
4279 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
4280 return null_pointer_node
;
4291 /* Output assembler code for constant EXP to FILE, with no label.
4292 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4293 Assumes output_addressed_constants has been done on EXP already.
4295 Generate exactly SIZE bytes of assembler data, padding at the end
4296 with zeros if necessary. SIZE must always be specified.
4298 SIZE is important for structure constructors,
4299 since trailing members may have been omitted from the constructor.
4300 It is also important for initialization of arrays from string constants
4301 since the full length of the string constant might not be wanted.
4302 It is also needed for initialization of unions, where the initializer's
4303 type is just one member, and that may not be as long as the union.
4305 There a case in which we would fail to output exactly SIZE bytes:
4306 for a structure constructor that wants to produce more than SIZE bytes.
4307 But such constructors will never be generated for any possible input.
4309 ALIGN is the alignment of the data in bits. */
4312 output_constant (exp
, size
, align
)
4317 enum tree_code code
;
4318 HOST_WIDE_INT thissize
;
4320 /* Some front-ends use constants other than the standard language-indepdent
4321 varieties, but which may still be output directly. Give the front-end a
4322 chance to convert EXP to a language-independent representation. */
4323 exp
= (*lang_hooks
.expand_constant
) (exp
);
4325 if (size
== 0 || flag_syntax_only
)
4328 /* Eliminate any conversions since we'll be outputting the underlying
4330 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
4331 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4332 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4333 exp
= TREE_OPERAND (exp
, 0);
4335 code
= TREE_CODE (TREE_TYPE (exp
));
4336 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4338 /* Allow a constructor with no elements for any data type.
4339 This means to fill the space with zeros. */
4340 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
4342 assemble_zeros (size
);
4346 if (TREE_CODE (exp
) == FDESC_EXPR
)
4348 #ifdef ASM_OUTPUT_FDESC
4349 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4350 tree decl
= TREE_OPERAND (exp
, 0);
4351 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4358 /* Now output the underlying data. If we've handling the padding, return.
4359 Otherwise, break and ensure THISSIZE is the size written. */
4367 case REFERENCE_TYPE
:
4368 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4369 EXPAND_INITIALIZER
),
4371 error ("initializer for integer value is too complicated");
4375 if (TREE_CODE (exp
) != REAL_CST
)
4376 error ("initializer for floating value is not a floating constant");
4378 assemble_real (TREE_REAL_CST (exp
),
4379 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0),
4384 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4385 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4386 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4391 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4393 output_constructor (exp
, size
, align
);
4396 else if (TREE_CODE (exp
) == STRING_CST
)
4398 thissize
= MIN (TREE_STRING_LENGTH (exp
), size
);
4399 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4407 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4408 output_constructor (exp
, size
, align
);
4414 if (TREE_CODE (exp
) == INTEGER_CST
)
4415 assemble_integer (expand_expr (exp
, NULL_RTX
,
4416 VOIDmode
, EXPAND_INITIALIZER
),
4417 thissize
, align
, 1);
4418 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4420 unsigned char *buffer
= (unsigned char *) alloca (thissize
);
4421 if (get_set_constructor_bytes (exp
, buffer
, thissize
))
4423 assemble_string ((char *) buffer
, thissize
);
4426 error ("unknown set constructor type");
4438 assemble_zeros (size
);
4442 /* Subroutine of output_constructor, used for computing the size of
4443 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4444 type with an unspecified upper bound. */
4446 static unsigned HOST_WIDE_INT
4447 array_size_for_constructor (val
)
4452 /* This code used to attempt to handle string constants that are not
4453 arrays of single-bytes, but nothing else does, so there's no point in
4455 if (TREE_CODE (val
) == STRING_CST
)
4456 return TREE_STRING_LENGTH (val
);
4458 max_index
= NULL_TREE
;
4459 for (i
= CONSTRUCTOR_ELTS (val
); i
; i
= TREE_CHAIN (i
))
4461 tree index
= TREE_PURPOSE (i
);
4463 if (TREE_CODE (index
) == RANGE_EXPR
)
4464 index
= TREE_OPERAND (index
, 1);
4465 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4469 if (max_index
== NULL_TREE
)
4472 /* Compute the total number of array elements. */
4473 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
4475 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
4476 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
4478 /* Multiply by the array element unit size to find number of bytes. */
4479 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4481 return tree_low_cst (i
, 1);
4484 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4485 Generate at least SIZE bytes, padding if necessary. */
4488 output_constructor (exp
, size
, align
)
4493 tree type
= TREE_TYPE (exp
);
4494 tree link
, field
= 0;
4496 /* Number of bytes output or skipped so far.
4497 In other words, current position within the constructor. */
4498 HOST_WIDE_INT total_bytes
= 0;
4499 /* Non-zero means BYTE contains part of a byte, to be output. */
4500 int byte_buffer_in_use
= 0;
4503 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4506 if (TREE_CODE (type
) == RECORD_TYPE
)
4507 field
= TYPE_FIELDS (type
);
4509 if (TREE_CODE (type
) == ARRAY_TYPE
4510 && TYPE_DOMAIN (type
) != 0)
4511 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
4513 /* As LINK goes through the elements of the constant,
4514 FIELD goes through the structure fields, if the constant is a structure.
4515 if the constant is a union, then we override this,
4516 by getting the field from the TREE_LIST element.
4517 But the constant could also be an array. Then FIELD is zero.
4519 There is always a maximum of one element in the chain LINK for unions
4520 (even if the initializer in a source program incorrectly contains
4522 for (link
= CONSTRUCTOR_ELTS (exp
);
4524 link
= TREE_CHAIN (link
),
4525 field
= field
? TREE_CHAIN (field
) : 0)
4527 tree val
= TREE_VALUE (link
);
4530 /* The element in a union constructor specifies the proper field
4532 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
4533 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4534 && TREE_PURPOSE (link
) != 0)
4535 field
= TREE_PURPOSE (link
);
4537 else if (TREE_CODE (type
) == ARRAY_TYPE
)
4538 index
= TREE_PURPOSE (link
);
4540 /* Eliminate the marker that makes a cast not be an lvalue. */
4544 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4546 unsigned HOST_WIDE_INT fieldsize
4547 = int_size_in_bytes (TREE_TYPE (type
));
4548 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
4549 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
4550 HOST_WIDE_INT index
;
4551 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
4553 for (index
= lo_index
; index
<= hi_index
; index
++)
4555 /* Output the element's initial value. */
4557 assemble_zeros (fieldsize
);
4559 output_constant (val
, fieldsize
, align2
);
4561 /* Count its size. */
4562 total_bytes
+= fieldsize
;
4565 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4567 /* An element that is not a bit-field. */
4569 unsigned HOST_WIDE_INT fieldsize
;
4570 /* Since this structure is static,
4571 we know the positions are constant. */
4572 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4573 unsigned int align2
;
4576 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4577 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4579 /* Output any buffered-up bit-fields preceding this element. */
4580 if (byte_buffer_in_use
)
4582 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4584 byte_buffer_in_use
= 0;
4587 /* Advance to offset of this element.
4588 Note no alignment needed in an array, since that is guaranteed
4589 if each element has the proper size. */
4590 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4592 assemble_zeros (pos
- total_bytes
);
4596 /* Find the alignment of this element. */
4597 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4599 /* Determine size this element should occupy. */
4604 /* If this is an array with an unspecified upper bound,
4605 the initializer determines the size. */
4606 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4607 but we cannot do this until the deprecated support for
4608 initializing zero-length array members is removed. */
4609 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4610 && TYPE_DOMAIN (TREE_TYPE (field
))
4611 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4613 fieldsize
= array_size_for_constructor (val
);
4614 /* Given a non-empty initialization, this field had
4616 if (fieldsize
!= 0 && TREE_CHAIN (field
) != NULL_TREE
)
4619 else if (DECL_SIZE_UNIT (field
))
4621 /* ??? This can't be right. If the decl size overflows
4622 a host integer we will silently emit no data. */
4623 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4624 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4628 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4630 /* Output the element's initial value. */
4632 assemble_zeros (fieldsize
);
4634 output_constant (val
, fieldsize
, align2
);
4636 /* Count its size. */
4637 total_bytes
+= fieldsize
;
4639 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4640 error ("invalid initial value for member `%s'",
4641 IDENTIFIER_POINTER (DECL_NAME (field
)));
4644 /* Element that is a bit-field. */
4646 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4647 HOST_WIDE_INT end_offset
4648 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4651 val
= integer_zero_node
;
4653 /* If this field does not start in this (or, next) byte,
4655 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4657 /* Output remnant of any bit field in previous bytes. */
4658 if (byte_buffer_in_use
)
4660 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4662 byte_buffer_in_use
= 0;
4665 /* If still not at proper byte, advance to there. */
4666 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4668 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4669 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4673 if (! byte_buffer_in_use
)
4676 /* We must split the element into pieces that fall within
4677 separate bytes, and combine each byte with previous or
4678 following bit-fields. */
4680 /* next_offset is the offset n fbits from the beginning of
4681 the structure to the next bit of this element to be processed.
4682 end_offset is the offset of the first bit past the end of
4684 while (next_offset
< end_offset
)
4688 HOST_WIDE_INT value
;
4689 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4690 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4692 /* Advance from byte to byte
4693 within this element when necessary. */
4694 while (next_byte
!= total_bytes
)
4696 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4701 /* Number of bits we can process at once
4702 (all part of the same byte). */
4703 this_time
= MIN (end_offset
- next_offset
,
4704 BITS_PER_UNIT
- next_bit
);
4705 if (BYTES_BIG_ENDIAN
)
4707 /* On big-endian machine, take the most significant bits
4708 first (of the bits that are significant)
4709 and put them into bytes from the most significant end. */
4710 shift
= end_offset
- next_offset
- this_time
;
4712 /* Don't try to take a bunch of bits that cross
4713 the word boundary in the INTEGER_CST. We can
4714 only select bits from the LOW or HIGH part
4716 if (shift
< HOST_BITS_PER_WIDE_INT
4717 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4719 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4720 shift
= HOST_BITS_PER_WIDE_INT
;
4723 /* Now get the bits from the appropriate constant word. */
4724 if (shift
< HOST_BITS_PER_WIDE_INT
)
4725 value
= TREE_INT_CST_LOW (val
);
4726 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4728 value
= TREE_INT_CST_HIGH (val
);
4729 shift
-= HOST_BITS_PER_WIDE_INT
;
4734 /* Get the result. This works only when:
4735 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4736 byte
|= (((value
>> shift
)
4737 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4738 << (BITS_PER_UNIT
- this_time
- next_bit
));
4742 /* On little-endian machines,
4743 take first the least significant bits of the value
4744 and pack them starting at the least significant
4745 bits of the bytes. */
4746 shift
= next_offset
- int_bit_position (field
);
4748 /* Don't try to take a bunch of bits that cross
4749 the word boundary in the INTEGER_CST. We can
4750 only select bits from the LOW or HIGH part
4752 if (shift
< HOST_BITS_PER_WIDE_INT
4753 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4754 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4756 /* Now get the bits from the appropriate constant word. */
4757 if (shift
< HOST_BITS_PER_WIDE_INT
)
4758 value
= TREE_INT_CST_LOW (val
);
4759 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4761 value
= TREE_INT_CST_HIGH (val
);
4762 shift
-= HOST_BITS_PER_WIDE_INT
;
4767 /* Get the result. This works only when:
4768 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4769 byte
|= (((value
>> shift
)
4770 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4774 next_offset
+= this_time
;
4775 byte_buffer_in_use
= 1;
4780 if (byte_buffer_in_use
)
4782 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4786 if (total_bytes
< size
)
4787 assemble_zeros (size
- total_bytes
);
4790 /* This TREE_LIST contains any weak symbol declarations waiting
4792 static tree weak_decls
;
4794 /* Mark DECL as weak. */
4800 DECL_WEAK (decl
) = 1;
4802 if (DECL_RTL_SET_P (decl
)
4803 && GET_CODE (DECL_RTL (decl
)) == MEM
4804 && XEXP (DECL_RTL (decl
), 0)
4805 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
4806 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
4809 /* Merge weak status between NEWDECL and OLDDECL. */
4812 merge_weak (newdecl
, olddecl
)
4816 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
4819 if (DECL_WEAK (newdecl
))
4823 /* NEWDECL is weak, but OLDDECL is not. */
4825 /* If we already output the OLDDECL, we're in trouble; we can't
4826 go back and make it weak. This error cannot caught in
4827 declare_weak because the NEWDECL and OLDDECL was not yet
4828 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4829 if (TREE_ASM_WRITTEN (olddecl
))
4830 error_with_decl (newdecl
,
4831 "weak declaration of `%s' must precede definition");
4833 /* If we've already generated rtl referencing OLDDECL, we may
4834 have done so in a way that will not function properly with
4836 else if (TREE_USED (olddecl
)
4837 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
4838 warning_with_decl (newdecl
, "weak declaration of `%s' after first use results in unspecified behavior");
4842 /* We put the NEWDECL on the weak_decls list at some point.
4843 Replace it with the OLDDECL. */
4844 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
4845 if (TREE_VALUE (wd
) == newdecl
)
4847 TREE_VALUE (wd
) = olddecl
;
4850 /* We may not find the entry on the list. If NEWDECL is a
4851 weak alias, then we will have already called
4852 globalize_decl to remove the entry; in that case, we do
4853 not need to do anything. */
4856 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4857 mark_weak (olddecl
);
4860 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4861 weak. Just update NEWDECL to indicate that it's weak too. */
4862 mark_weak (newdecl
);
4865 /* Declare DECL to be a weak symbol. */
4871 if (! TREE_PUBLIC (decl
))
4872 error_with_decl (decl
, "weak declaration of `%s' must be public");
4873 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
4874 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4875 else if (SUPPORTS_WEAK
)
4877 if (! DECL_WEAK (decl
))
4878 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
4881 warning_with_decl (decl
, "weak declaration of `%s' not supported");
4886 /* Emit any pending weak declarations. */
4893 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
4895 tree decl
= TREE_VALUE (t
);
4896 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4898 if (! TREE_USED (decl
))
4901 #ifdef ASM_WEAKEN_DECL
4902 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
4904 #ifdef ASM_WEAKEN_LABEL
4905 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4907 #ifdef ASM_OUTPUT_WEAK_ALIAS
4908 warning ("only weak aliases are supported in this configuration");
4916 /* Emit the assembly bits to indicate that DECL is globally visible. */
4919 globalize_decl (decl
)
4922 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4924 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4925 if (DECL_WEAK (decl
))
4929 #ifdef ASM_WEAKEN_DECL
4930 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
4932 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4935 /* Remove this function from the pending weak list so that
4936 we do not emit multiple .weak directives for it. */
4937 for (p
= &weak_decls
; (t
= *p
) ; )
4939 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4940 *p
= TREE_CHAIN (t
);
4942 p
= &TREE_CHAIN (t
);
4948 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4951 /* Emit an assembler directive to make the symbol for DECL an alias to
4952 the symbol for TARGET. */
4955 assemble_alias (decl
, target
)
4956 tree decl
, target ATTRIBUTE_UNUSED
;
4960 /* We must force creation of DECL_RTL for debug info generation, even though
4961 we don't use it here. */
4962 make_decl_rtl (decl
, NULL
);
4964 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4966 #ifdef ASM_OUTPUT_DEF
4967 /* Make name accessible from other files, if appropriate. */
4969 if (TREE_PUBLIC (decl
))
4971 globalize_decl (decl
);
4972 maybe_assemble_visibility (decl
);
4975 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4976 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4978 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4980 #else /* !ASM_OUTPUT_DEF */
4981 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4982 if (! DECL_WEAK (decl
))
4983 warning ("only weak aliases are supported in this configuration");
4985 #ifdef ASM_WEAKEN_DECL
4986 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
4988 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4991 warning ("alias definitions not supported in this configuration; ignored");
4995 TREE_USED (decl
) = 1;
4996 TREE_ASM_WRITTEN (decl
) = 1;
4997 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5000 /* Emit an assembler directive to set symbol for DECL visibility to
5004 assemble_visibility (decl
, visibility_type
)
5006 const char *visibility_type ATTRIBUTE_UNUSED
;
5010 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5012 #ifdef HAVE_GAS_HIDDEN
5013 fprintf (asm_out_file
, "\t.%s\t%s\n", visibility_type
, name
);
5015 warning ("visibility attribute not supported in this configuration; ignored");
5019 /* A helper function to call assemble_visibility when needed for a decl. */
5022 maybe_assemble_visibility (decl
)
5025 tree visibility
= lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
));
5029 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility
)));
5030 assemble_visibility (decl
, type
);
5034 /* Returns 1 if the target configuration supports defining public symbols
5035 so that one of them will be chosen at link time instead of generating a
5036 multiply-defined symbol error, whether through the use of weak symbols or
5037 a target-specific mechanism for having duplicates discarded. */
5040 supports_one_only ()
5042 if (SUPPORTS_ONE_ONLY
)
5044 return SUPPORTS_WEAK
;
5047 /* Set up DECL as a public symbol that can be defined in multiple
5048 translation units without generating a linker error. */
5051 make_decl_one_only (decl
)
5054 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
5057 TREE_PUBLIC (decl
) = 1;
5059 if (TREE_CODE (decl
) == VAR_DECL
5060 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5061 DECL_COMMON (decl
) = 1;
5062 else if (SUPPORTS_ONE_ONLY
)
5064 #ifdef MAKE_DECL_ONE_ONLY
5065 MAKE_DECL_ONE_ONLY (decl
);
5067 DECL_ONE_ONLY (decl
) = 1;
5069 else if (SUPPORTS_WEAK
)
5070 DECL_WEAK (decl
) = 1;
5078 const_str_htab
= htab_create (128, const_str_htab_hash
, const_str_htab_eq
,
5079 const_str_htab_del
);
5080 in_named_htab
= htab_create (31, in_named_entry_hash
,
5081 in_named_entry_eq
, NULL
);
5083 ggc_add_root (const_hash_table
, MAX_HASH_TABLE
, sizeof const_hash_table
[0],
5084 mark_const_hash_entry
);
5085 ggc_add_root (&const_str_htab
, 1, sizeof const_str_htab
,
5086 mark_const_str_htab
);
5087 ggc_add_tree_root (&weak_decls
, 1);
5089 const_alias_set
= new_alias_set ();
5092 /* Select a set of attributes for section NAME based on the properties
5093 of DECL and whether or not RELOC indicates that DECL's initializer
5094 might contain runtime relocations.
5096 We make the section read-only and executable for a function decl,
5097 read-only for a const data decl, and writable for a non-const data decl. */
5100 default_section_type_flags (decl
, name
, reloc
)
5107 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5108 flags
= SECTION_CODE
;
5109 else if (decl
&& DECL_READONLY_SECTION (decl
, reloc
))
5112 flags
= SECTION_WRITE
;
5114 if (decl
&& DECL_ONE_ONLY (decl
))
5115 flags
|= SECTION_LINKONCE
;
5117 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
5118 flags
|= SECTION_TLS
| SECTION_WRITE
;
5120 if (strcmp (name
, ".bss") == 0
5121 || strncmp (name
, ".bss.", 5) == 0
5122 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5123 || strcmp (name
, ".sbss") == 0
5124 || strncmp (name
, ".sbss.", 6) == 0
5125 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0
5126 || strcmp (name
, ".tbss") == 0
5127 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
5128 flags
|= SECTION_BSS
;
5130 if (strcmp (name
, ".tdata") == 0
5131 || strcmp (name
, ".tbss") == 0
5132 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0
5133 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
5134 flags
|= SECTION_TLS
;
5139 /* Output assembly to switch to section NAME with attribute FLAGS.
5140 Four variants for common object file formats. */
5143 default_no_named_section (name
, flags
)
5144 const char *name ATTRIBUTE_UNUSED
;
5145 unsigned int flags ATTRIBUTE_UNUSED
;
5147 /* Some object formats don't support named sections at all. The
5148 front-end should already have flagged this as an error. */
5153 default_elf_asm_named_section (name
, flags
)
5157 char flagchars
[10], *f
= flagchars
;
5160 if (! named_section_first_declaration (name
))
5162 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5166 if (!(flags
& SECTION_DEBUG
))
5168 if (flags
& SECTION_WRITE
)
5170 if (flags
& SECTION_CODE
)
5172 if (flags
& SECTION_SMALL
)
5174 if (flags
& SECTION_MERGE
)
5176 if (flags
& SECTION_STRINGS
)
5178 if (flags
& SECTION_TLS
)
5182 if (flags
& SECTION_BSS
)
5187 if (flags
& SECTION_ENTSIZE
)
5188 fprintf (asm_out_file
, "\t.section\t%s,\"%s\",@%s,%d\n",
5189 name
, flagchars
, type
, flags
& SECTION_ENTSIZE
);
5191 fprintf (asm_out_file
, "\t.section\t%s,\"%s\",@%s\n",
5192 name
, flagchars
, type
);
5196 default_coff_asm_named_section (name
, flags
)
5200 char flagchars
[8], *f
= flagchars
;
5202 if (flags
& SECTION_WRITE
)
5204 if (flags
& SECTION_CODE
)
5208 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5212 default_pe_asm_named_section (name
, flags
)
5216 default_coff_asm_named_section (name
, flags
);
5218 if (flags
& SECTION_LINKONCE
)
5220 /* Functions may have been compiled at various levels of
5221 optimization so we can't use `same_size' here.
5222 Instead, have the linker pick one. */
5223 fprintf (asm_out_file
, "\t.linkonce %s\n",
5224 (flags
& SECTION_CODE
? "discard" : "same_size"));
5228 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5229 from SYMBOL is used in all classes derived from SYMBOL. */
5232 assemble_vtable_entry (symbol
, offset
)
5234 HOST_WIDE_INT offset
;
5236 fputs ("\t.vtable_entry ", asm_out_file
);
5237 output_addr_const (asm_out_file
, symbol
);
5238 fputs (", ", asm_out_file
);
5239 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_DEC
, offset
);
5240 fputc ('\n', asm_out_file
);
5243 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5244 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5247 assemble_vtable_inherit (child
, parent
)
5250 fputs ("\t.vtable_inherit ", asm_out_file
);
5251 output_addr_const (asm_out_file
, child
);
5252 fputs (", ", asm_out_file
);
5253 output_addr_const (asm_out_file
, parent
);
5254 fputc ('\n', asm_out_file
);
5257 /* The lame default section selector. */
5260 default_select_section (decl
, reloc
, align
)
5263 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
5265 bool readonly
= false;
5269 if (DECL_READONLY_SECTION (decl
, reloc
))
5272 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5274 if (! ((flag_pic
&& reloc
)
5275 || !TREE_READONLY (decl
)
5276 || TREE_SIDE_EFFECTS (decl
)
5277 || !TREE_CONSTANT (decl
)))
5280 else if (TREE_CODE (decl
) == STRING_CST
)
5281 readonly
= !flag_writable_strings
;
5282 else if (! (flag_pic
&& reloc
))
5286 readonly_data_section ();
5291 /* A helper function for default_elf_select_section and
5292 default_elf_unique_section. Categorizes the DECL. */
5294 enum section_category
5299 SECCAT_RODATA_MERGE_STR
,
5300 SECCAT_RODATA_MERGE_STR_INIT
,
5301 SECCAT_RODATA_MERGE_CONST
,
5305 /* To optimize loading of shared programs, define following subsections
5307 _REL Contains data that has relocations, so they get grouped
5308 together and dynamic linker will visit fewer pages in memory.
5309 _RO Contains data that is otherwise read-only. This is useful
5310 with prelinking as most relocations won't be dynamically
5311 linked and thus stay read only.
5312 _LOCAL Marks data containing relocations only to local objects.
5313 These relocations will get fully resolved by prelinking. */
5315 SECCAT_DATA_REL_LOCAL
,
5317 SECCAT_DATA_REL_RO_LOCAL
,
5327 static enum section_category categorize_decl_for_section
PARAMS ((tree
, int));
5329 static enum section_category
5330 categorize_decl_for_section (decl
, reloc
)
5334 enum section_category ret
;
5336 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5338 else if (TREE_CODE (decl
) == STRING_CST
)
5340 if (flag_writable_strings
)
5343 return SECCAT_RODATA_MERGE_STR
;
5345 else if (TREE_CODE (decl
) == VAR_DECL
)
5347 if (DECL_INITIAL (decl
) == NULL
5348 || DECL_INITIAL (decl
) == error_mark_node
)
5350 else if (! TREE_READONLY (decl
)
5351 || TREE_SIDE_EFFECTS (decl
)
5352 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5354 if (flag_pic
&& (reloc
& 2))
5355 ret
= SECCAT_DATA_REL
;
5356 else if (flag_pic
&& reloc
)
5357 ret
= SECCAT_DATA_REL_LOCAL
;
5361 else if (flag_pic
&& (reloc
& 2))
5362 ret
= SECCAT_DATA_REL_RO
;
5363 else if (flag_pic
&& reloc
)
5364 ret
= SECCAT_DATA_REL_RO_LOCAL
;
5365 else if (flag_merge_constants
< 2)
5366 /* C and C++ don't allow different variables to share the same
5367 location. -fmerge-all-constants allows even that (at the
5368 expense of not conforming). */
5369 ret
= SECCAT_RODATA
;
5370 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
5371 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
5373 ret
= SECCAT_RODATA_MERGE_CONST
;
5375 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5377 if ((flag_pic
&& reloc
)
5378 || TREE_SIDE_EFFECTS (decl
)
5379 || ! TREE_CONSTANT (decl
))
5382 ret
= SECCAT_RODATA
;
5385 ret
= SECCAT_RODATA
;
5387 /* There are no read-only thread-local sections. */
5388 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL (decl
))
5390 if (ret
== SECCAT_BSS
)
5396 /* If the target uses small data sections, select it. */
5397 else if ((*targetm
.in_small_data_p
) (decl
))
5399 if (ret
== SECCAT_BSS
)
5408 /* Select a section based on the above categorization. */
5411 default_elf_select_section (decl
, reloc
, align
)
5414 unsigned HOST_WIDE_INT align
;
5416 switch (categorize_decl_for_section (decl
, reloc
))
5419 /* We're not supposed to be called on FUNCTION_DECLs. */
5422 readonly_data_section ();
5424 case SECCAT_RODATA_MERGE_STR
:
5425 mergeable_string_section (decl
, align
, 0);
5427 case SECCAT_RODATA_MERGE_STR_INIT
:
5428 mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
5430 case SECCAT_RODATA_MERGE_CONST
:
5431 mergeable_constant_section (DECL_MODE (decl
), align
, 0);
5436 case SECCAT_DATA_REL
:
5437 named_section (NULL_TREE
, ".data.rel", reloc
);
5439 case SECCAT_DATA_REL_LOCAL
:
5440 named_section (NULL_TREE
, ".data.rel.local", reloc
);
5442 case SECCAT_DATA_REL_RO
:
5443 named_section (NULL_TREE
, ".data.rel.ro", reloc
);
5445 case SECCAT_DATA_REL_RO_LOCAL
:
5446 named_section (NULL_TREE
, ".data.rel.ro.local", reloc
);
5449 named_section (NULL_TREE
, ".sdata", reloc
);
5452 named_section (NULL_TREE
, ".tdata", reloc
);
5455 #ifdef BSS_SECTION_ASM_OP
5458 named_section (NULL_TREE
, ".bss", reloc
);
5462 named_section (NULL_TREE
, ".sbss", reloc
);
5465 named_section (NULL_TREE
, ".tbss", reloc
);
5472 /* Construct a unique section name based on the decl name and the
5473 categorization performed above. */
5476 default_unique_section (decl
, reloc
)
5480 bool one_only
= DECL_ONE_ONLY (decl
);
5481 const char *prefix
, *name
;
5485 switch (categorize_decl_for_section (decl
, reloc
))
5488 prefix
= one_only
? ".gnu.linkonce.t." : ".text.";
5491 case SECCAT_RODATA_MERGE_STR
:
5492 case SECCAT_RODATA_MERGE_STR_INIT
:
5493 case SECCAT_RODATA_MERGE_CONST
:
5494 prefix
= one_only
? ".gnu.linkonce.r." : ".rodata.";
5497 case SECCAT_DATA_REL
:
5498 case SECCAT_DATA_REL_LOCAL
:
5499 case SECCAT_DATA_REL_RO
:
5500 case SECCAT_DATA_REL_RO_LOCAL
:
5501 prefix
= one_only
? ".gnu.linkonce.d." : ".data.";
5504 prefix
= one_only
? ".gnu.linkonce.s." : ".sdata.";
5507 prefix
= one_only
? ".gnu.linkonce.b." : ".bss.";
5510 prefix
= one_only
? ".gnu.linkonce.sb." : ".sbss.";
5513 prefix
= one_only
? ".gnu.linkonce.td." : ".tdata.";
5516 prefix
= one_only
? ".gnu.linkonce.tb." : ".tbss.";
5521 plen
= strlen (prefix
);
5523 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5524 name
= (* targetm
.strip_name_encoding
) (name
);
5525 nlen
= strlen (name
);
5527 string
= alloca (nlen
+ plen
+ 1);
5528 memcpy (string
, prefix
, plen
);
5529 memcpy (string
+ plen
, name
, nlen
+ 1);
5531 DECL_SECTION_NAME (decl
) = build_string (nlen
+ plen
, string
);
5535 default_select_rtx_section (mode
, x
, align
)
5536 enum machine_mode mode ATTRIBUTE_UNUSED
;
5538 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
5541 switch (GET_CODE (x
))
5553 readonly_data_section ();
5557 default_elf_select_rtx_section (mode
, x
, align
)
5558 enum machine_mode mode
;
5560 unsigned HOST_WIDE_INT align
;
5562 /* ??? Handle small data here somehow. */
5565 switch (GET_CODE (x
))
5569 named_section (NULL_TREE
, ".data.rel.ro", 3);
5573 named_section (NULL_TREE
, ".data.rel.ro.local", 1);
5580 mergeable_constant_section (mode
, align
, 0);
5583 /* By default, we do nothing for encode_section_info, so we need not
5584 do anything but discard the '*' marker. */
5587 default_strip_name_encoding (str
)
5590 return str
+ (*str
== '*');
5593 /* Assume ELF-ish defaults, since that's pretty much the most liberal
5594 wrt cross-module name binding. */
5597 default_binds_local_p (exp
)
5602 /* A non-decl is an entry in the constant pool. */
5605 /* Static variables are always local. */
5606 else if (! TREE_PUBLIC (exp
))
5608 /* A variable is local if the user tells us so. */
5609 else if (MODULE_LOCAL_P (exp
))
5611 /* Otherwise, variables defined outside this object may not be local. */
5612 else if (DECL_EXTERNAL (exp
))
5614 /* Linkonce and weak data are never local. */
5615 else if (DECL_ONE_ONLY (exp
) || DECL_WEAK (exp
))
5617 /* If PIC, then assume that any global name can be overridden by
5618 symbols resolved from other modules. */
5621 /* Uninitialized COMMON variable may be unified with symbols
5622 resolved from other modules. */
5623 else if (DECL_COMMON (exp
)
5624 && (DECL_INITIAL (exp
) == NULL
5625 || DECL_INITIAL (exp
) == error_mark_node
))
5627 /* Otherwise we're left with initialized (or non-common) global data
5628 which is of necessity defined locally. */