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 EXTRA_SECTIONS
202 } in_section
= no_section
;
204 /* Return a non-zero value if DECL has a section attribute. */
205 #ifndef IN_NAMED_SECTION
206 #define IN_NAMED_SECTION(DECL) \
207 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
208 && DECL_SECTION_NAME (DECL) != NULL_TREE)
211 /* Text of section name when in_section == in_named. */
212 static const char *in_named_name
;
214 /* Hash table of flags that have been used for a particular named section. */
216 struct in_named_entry
223 static htab_t in_named_htab
;
225 /* Define functions like text_section for any extra sections. */
226 #ifdef EXTRA_SECTION_FUNCTIONS
227 EXTRA_SECTION_FUNCTIONS
230 /* Tell assembler to switch to text section. */
235 if (in_section
!= in_text
)
240 fprintf (asm_out_file
, "%s\n", TEXT_SECTION_ASM_OP
);
242 in_section
= in_text
;
246 /* Tell assembler to switch to data section. */
251 if (in_section
!= in_data
)
253 if (flag_shared_data
)
255 #ifdef SHARED_SECTION_ASM_OP
256 fprintf (asm_out_file
, "%s\n", SHARED_SECTION_ASM_OP
);
258 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
262 fprintf (asm_out_file
, "%s\n", DATA_SECTION_ASM_OP
);
264 in_section
= in_data
;
268 /* Tell assembler to ALWAYS switch to data section, in case
269 it's not sure where it is. */
272 force_data_section ()
274 in_section
= no_section
;
278 /* Tell assembler to switch to read-only data section. This is normally
282 readonly_data_section ()
284 #ifdef READONLY_DATA_SECTION
285 READONLY_DATA_SECTION (); /* Note this can call data_section. */
291 /* Determine if we're in the text section. */
296 return in_section
== in_text
;
299 /* Determine if we're in the data section. */
304 return in_section
== in_data
;
307 /* Helper routines for maintaining in_named_htab. */
310 in_named_entry_eq (p1
, p2
)
314 const struct in_named_entry
*old
= p1
;
315 const char *new = p2
;
317 return strcmp (old
->name
, new) == 0;
321 in_named_entry_hash (p
)
324 const struct in_named_entry
*old
= p
;
325 return htab_hash_string (old
->name
);
328 /* If SECTION has been seen before as a named section, return the flags
329 that were used. Otherwise, return 0. Note, that 0 is a perfectly valid
330 set of flags for a section to have, so 0 does not mean that the section
331 has not been seen. */
334 get_named_section_flags (section
)
337 struct in_named_entry
**slot
;
339 slot
= (struct in_named_entry
**)
340 htab_find_slot_with_hash (in_named_htab
, section
,
341 htab_hash_string (section
), NO_INSERT
);
343 return slot
? (*slot
)->flags
: 0;
346 /* Returns true if the section has been declared before. Sets internal
347 flag on this section in in_named_hash so subsequent calls on this
348 section will return false. */
351 named_section_first_declaration (name
)
354 struct in_named_entry
**slot
;
356 slot
= (struct in_named_entry
**)
357 htab_find_slot_with_hash (in_named_htab
, name
,
358 htab_hash_string (name
), NO_INSERT
);
359 if (! (*slot
)->declared
)
361 (*slot
)->declared
= true;
371 /* Record FLAGS for SECTION. If SECTION was previously recorded with a
372 different set of flags, return false. */
375 set_named_section_flags (section
, flags
)
379 struct in_named_entry
**slot
, *entry
;
381 slot
= (struct in_named_entry
**)
382 htab_find_slot_with_hash (in_named_htab
, section
,
383 htab_hash_string (section
), INSERT
);
388 entry
= (struct in_named_entry
*) xmalloc (sizeof (*entry
));
390 entry
->name
= ggc_strdup (section
);
391 entry
->flags
= flags
;
392 entry
->declared
= false;
394 else if (entry
->flags
!= flags
)
400 /* Tell assembler to change to section NAME with attributes FLAGS. */
403 named_section_flags (name
, flags
)
407 if (in_section
!= in_named
|| strcmp (name
, in_named_name
) != 0)
409 if (! set_named_section_flags (name
, flags
))
412 (*targetm
.asm_out
.named_section
) (name
, flags
);
414 if (flags
& SECTION_FORGET
)
415 in_section
= no_section
;
418 in_named_name
= ggc_strdup (name
);
419 in_section
= in_named
;
424 /* Tell assembler to change to section NAME for DECL.
425 If DECL is NULL, just switch to section NAME.
426 If NAME is NULL, get the name from DECL.
427 If RELOC is 1, the initializer for DECL contains relocs. */
430 named_section (decl
, name
, reloc
)
437 if (decl
!= NULL_TREE
&& !DECL_P (decl
))
440 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
442 flags
= (* targetm
.section_type_flags
) (decl
, name
, reloc
);
444 /* Sanity check user variables for flag changes. Non-user
445 section flag changes will abort in named_section_flags.
446 However, don't complain if SECTION_OVERRIDE is set.
447 We trust that the setter knows that it is safe to ignore
448 the default flags for this decl. */
449 if (decl
&& ! set_named_section_flags (name
, flags
))
451 flags
= get_named_section_flags (name
);
452 if ((flags
& SECTION_OVERRIDE
) == 0)
453 error_with_decl (decl
, "%s causes a section type conflict");
456 named_section_flags (name
, flags
);
459 /* If required, set DECL_SECTION_NAME to a unique name. */
462 resolve_unique_section (decl
, reloc
, flag_function_or_data_sections
)
464 int reloc ATTRIBUTE_UNUSED
;
465 int flag_function_or_data_sections
;
467 if (DECL_SECTION_NAME (decl
) == NULL_TREE
468 && targetm
.have_named_sections
469 && (flag_function_or_data_sections
470 || DECL_ONE_ONLY (decl
)))
471 (*targetm
.asm_out
.unique_section
) (decl
, reloc
);
474 #ifdef BSS_SECTION_ASM_OP
476 /* Tell the assembler to switch to the bss section. */
481 if (in_section
!= in_bss
)
483 #ifdef SHARED_BSS_SECTION_ASM_OP
484 if (flag_shared_data
)
485 fprintf (asm_out_file
, "%s\n", SHARED_BSS_SECTION_ASM_OP
);
488 fprintf (asm_out_file
, "%s\n", BSS_SECTION_ASM_OP
);
494 #ifdef ASM_OUTPUT_BSS
496 /* Utility function for ASM_OUTPUT_BSS for targets to use if
497 they don't support alignments in .bss.
498 ??? It is believed that this function will work in most cases so such
499 support is localized here. */
502 asm_output_bss (file
, decl
, name
, size
, rounded
)
504 tree decl ATTRIBUTE_UNUSED
;
506 int size ATTRIBUTE_UNUSED
, rounded
;
508 ASM_GLOBALIZE_LABEL (file
, name
);
510 #ifdef ASM_DECLARE_OBJECT_NAME
511 last_assemble_variable_decl
= decl
;
512 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
514 /* Standard thing is just output label for the object. */
515 ASM_OUTPUT_LABEL (file
, name
);
516 #endif /* ASM_DECLARE_OBJECT_NAME */
517 ASM_OUTPUT_SKIP (file
, rounded
);
522 #ifdef ASM_OUTPUT_ALIGNED_BSS
524 /* Utility function for targets to use in implementing
525 ASM_OUTPUT_ALIGNED_BSS.
526 ??? It is believed that this function will work in most cases so such
527 support is localized here. */
530 asm_output_aligned_bss (file
, decl
, name
, size
, align
)
532 tree decl ATTRIBUTE_UNUSED
;
536 ASM_GLOBALIZE_LABEL (file
, name
);
538 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
539 #ifdef ASM_DECLARE_OBJECT_NAME
540 last_assemble_variable_decl
= decl
;
541 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
543 /* Standard thing is just output label for the object. */
544 ASM_OUTPUT_LABEL (file
, name
);
545 #endif /* ASM_DECLARE_OBJECT_NAME */
546 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
551 #endif /* BSS_SECTION_ASM_OP */
553 /* Switch to the section for function DECL.
555 If DECL is NULL_TREE, switch to the text section.
556 ??? It's not clear that we will ever be passed NULL_TREE, but it's
557 safer to handle it. */
560 function_section (decl
)
563 if (decl
!= NULL_TREE
564 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
565 named_section (decl
, (char *) 0, 0);
570 /* Switch to section for variable DECL. RELOC is the same as the
571 argument to SELECT_SECTION. */
574 variable_section (decl
, reloc
)
578 if (IN_NAMED_SECTION (decl
))
579 named_section (decl
, NULL
, reloc
);
581 (*targetm
.asm_out
.select_section
) (decl
, reloc
, DECL_ALIGN (decl
));
584 /* Tell assembler to switch to the section for the exception handling
588 default_exception_section ()
590 if (targetm
.have_named_sections
)
591 named_section (NULL_TREE
, ".gcc_except_table", 0);
595 readonly_data_section ();
598 /* Tell assembler to switch to the section for string merging. */
601 mergeable_string_section (decl
, align
, flags
)
602 tree decl ATTRIBUTE_UNUSED
;
603 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
604 unsigned int flags ATTRIBUTE_UNUSED
;
606 #ifdef HAVE_GAS_SHF_MERGE
607 if (flag_merge_constants
608 && TREE_CODE (decl
) == STRING_CST
609 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
611 && TREE_STRING_LENGTH (decl
) >= int_size_in_bytes (TREE_TYPE (decl
)))
613 enum machine_mode mode
;
614 unsigned int modesize
;
619 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
620 modesize
= GET_MODE_BITSIZE (mode
);
621 if (modesize
>= 8 && modesize
<= 256
622 && (modesize
& (modesize
- 1)) == 0)
624 if (align
< modesize
)
627 str
= TREE_STRING_POINTER (decl
);
628 len
= TREE_STRING_LENGTH (decl
);
629 unit
= GET_MODE_SIZE (mode
);
631 /* Check for embedded NUL characters. */
632 for (i
= 0; i
< len
; i
+= unit
)
634 for (j
= 0; j
< unit
; j
++)
635 if (str
[i
+ j
] != '\0')
642 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
644 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
645 if (!i
&& modesize
< align
)
647 /* A "" string with requested alignment greater than
648 character size might cause a problem:
649 if some other string required even bigger
650 alignment than "", then linker might think the
651 "" is just part of padding after some other string
652 and not put it into the hash table initially.
653 But this means "" could have smaller alignment
655 #ifdef ASM_OUTPUT_SECTION_START
656 named_section_flags (name
, flags
);
657 ASM_OUTPUT_SECTION_START (asm_out_file
);
659 readonly_data_section ();
664 named_section_flags (name
, flags
);
670 readonly_data_section ();
673 /* Tell assembler to switch to the section for constant merging. */
676 mergeable_constant_section (mode
, align
, flags
)
677 enum machine_mode mode ATTRIBUTE_UNUSED
;
678 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
679 unsigned int flags ATTRIBUTE_UNUSED
;
681 #ifdef HAVE_GAS_SHF_MERGE
682 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
684 if (flag_merge_constants
690 && (align
& (align
- 1)) == 0)
694 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
695 flags
|= (align
/ 8) | SECTION_MERGE
;
696 named_section_flags (name
, flags
);
700 readonly_data_section ();
703 /* Given NAME, a putative register name, discard any customary prefixes. */
706 strip_reg_name (name
)
709 #ifdef REGISTER_PREFIX
710 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
711 name
+= strlen (REGISTER_PREFIX
);
713 if (name
[0] == '%' || name
[0] == '#')
718 /* Decode an `asm' spec for a declaration as a register name.
719 Return the register number, or -1 if nothing specified,
720 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
721 or -3 if ASMSPEC is `cc' and is not recognized,
722 or -4 if ASMSPEC is `memory' and is not recognized.
723 Accept an exact spelling or a decimal number.
724 Prefixes such as % are optional. */
727 decode_reg_name (asmspec
)
734 /* Get rid of confusing prefixes. */
735 asmspec
= strip_reg_name (asmspec
);
737 /* Allow a decimal number as a "register name". */
738 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
739 if (! ISDIGIT (asmspec
[i
]))
741 if (asmspec
[0] != 0 && i
< 0)
744 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
750 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
752 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
755 #ifdef ADDITIONAL_REGISTER_NAMES
757 static const struct { const char *const name
; const int number
; } table
[]
758 = ADDITIONAL_REGISTER_NAMES
;
760 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
761 if (! strcmp (asmspec
, table
[i
].name
))
762 return table
[i
].number
;
764 #endif /* ADDITIONAL_REGISTER_NAMES */
766 if (!strcmp (asmspec
, "memory"))
769 if (!strcmp (asmspec
, "cc"))
778 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
779 have static storage duration. In other words, it should not be an
780 automatic variable, including PARM_DECLs.
782 There is, however, one exception: this function handles variables
783 explicitly placed in a particular register by the user.
785 ASMSPEC, if not 0, is the string which the user specified as the
786 assembler symbol name.
788 This is never called for PARM_DECL nodes. */
791 make_decl_rtl (decl
, asmspec
)
795 int top_level
= (DECL_CONTEXT (decl
) == NULL_TREE
);
796 const char *name
= 0;
797 const char *new_name
= 0;
801 /* Check that we are not being given an automatic variable. */
802 /* A weak alias has TREE_PUBLIC set but not the other bits. */
803 if (TREE_CODE (decl
) == PARM_DECL
804 || TREE_CODE (decl
) == RESULT_DECL
805 || (TREE_CODE (decl
) == VAR_DECL
806 && !TREE_STATIC (decl
)
807 && !TREE_PUBLIC (decl
)
808 && !DECL_EXTERNAL (decl
)
809 && !DECL_REGISTER (decl
)))
811 /* And that we were not given a type or a label. */
812 else if (TREE_CODE (decl
) == TYPE_DECL
813 || TREE_CODE (decl
) == LABEL_DECL
)
816 /* For a duplicate declaration, we can be called twice on the
817 same DECL node. Don't discard the RTL already made. */
818 if (DECL_RTL_SET_P (decl
))
820 /* If the old RTL had the wrong mode, fix the mode. */
821 if (GET_MODE (DECL_RTL (decl
)) != DECL_MODE (decl
))
822 SET_DECL_RTL (decl
, adjust_address_nv (DECL_RTL (decl
),
823 DECL_MODE (decl
), 0));
825 /* ??? Another way to do this would be to do what halfpic.c does
826 and maintain a hashed table of such critters. */
827 /* Let the target reassign the RTL if it wants.
828 This is necessary, for example, when one machine specific
829 decl attribute overrides another. */
830 #ifdef ENCODE_SECTION_INFO
831 ENCODE_SECTION_INFO (decl
, false);
836 new_name
= name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
838 reg_number
= decode_reg_name (asmspec
);
839 if (reg_number
== -2)
841 /* ASMSPEC is given, and not the name of a register. Mark the
842 name with a star so assemble_name won't munge it. */
843 char *starred
= alloca (strlen (asmspec
) + 2);
845 strcpy (starred
+ 1, asmspec
);
849 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
851 /* First detect errors in declaring global registers. */
852 if (reg_number
== -1)
853 error_with_decl (decl
, "register name not specified for `%s'");
854 else if (reg_number
< 0)
855 error_with_decl (decl
, "invalid register name for `%s'");
856 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
857 error_with_decl (decl
,
858 "data type of `%s' isn't suitable for a register");
859 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
860 error_with_decl (decl
,
861 "register specified for `%s' isn't suitable for data type");
862 /* Now handle properly declared static register variables. */
867 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
869 DECL_INITIAL (decl
) = 0;
870 error ("global register variable has initial value");
872 if (TREE_THIS_VOLATILE (decl
))
873 warning ("volatile register variables don't work as you might wish");
875 /* If the user specified one of the eliminables registers here,
876 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
877 confused with that register and be eliminated. This usage is
878 somewhat suspect... */
880 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
881 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
882 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
884 if (TREE_STATIC (decl
))
886 /* Make this register global, so not usable for anything
888 #ifdef ASM_DECLARE_REGISTER_GLOBAL
889 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
891 nregs
= HARD_REGNO_NREGS (reg_number
, DECL_MODE (decl
));
893 globalize_reg (reg_number
+ --nregs
);
896 /* As a register variable, it has no section. */
901 /* Now handle ordinary static variables and functions (in memory).
902 Also handle vars declared register invalidly. */
904 if (reg_number
>= 0 || reg_number
== -3)
905 error_with_decl (decl
,
906 "register name given for non-register variable `%s'");
908 /* Specifying a section attribute on a variable forces it into a
909 non-.bss section, and thus it cannot be common. */
910 if (TREE_CODE (decl
) == VAR_DECL
911 && DECL_SECTION_NAME (decl
) != NULL_TREE
912 && DECL_INITIAL (decl
) == NULL_TREE
913 && DECL_COMMON (decl
))
914 DECL_COMMON (decl
) = 0;
916 /* Can't use just the variable's own name for a variable
917 whose scope is less than the whole file, unless it's a member
918 of a local class (which will already be unambiguous).
919 Concatenate a distinguishing number. */
920 if (!top_level
&& !TREE_PUBLIC (decl
)
921 && ! (DECL_CONTEXT (decl
) && TYPE_P (DECL_CONTEXT (decl
)))
923 && name
== IDENTIFIER_POINTER (DECL_NAME (decl
)))
927 ASM_FORMAT_PRIVATE_NAME (label
, name
, var_labelno
);
932 if (name
!= new_name
)
934 SET_DECL_ASSEMBLER_NAME (decl
, get_identifier (new_name
));
935 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
938 /* If this variable is to be treated as volatile, show its
939 tree node has side effects. */
940 if ((flag_volatile_global
&& TREE_CODE (decl
) == VAR_DECL
941 && TREE_PUBLIC (decl
))
942 || ((flag_volatile_static
&& TREE_CODE (decl
) == VAR_DECL
943 && (TREE_PUBLIC (decl
) || TREE_STATIC (decl
)))))
944 TREE_SIDE_EFFECTS (decl
) = 1;
946 x
= gen_rtx_MEM (DECL_MODE (decl
), gen_rtx_SYMBOL_REF (Pmode
, name
));
947 SYMBOL_REF_WEAK (XEXP (x
, 0)) = DECL_WEAK (decl
);
948 if (TREE_CODE (decl
) != FUNCTION_DECL
)
949 set_mem_attributes (x
, decl
, 1);
950 SET_DECL_RTL (decl
, x
);
952 /* Optionally set flags or add text to the name to record information
953 such as that it is a function name.
954 If the name is changed, the macro ASM_OUTPUT_LABELREF
955 will have to know how to strip this information. */
956 #ifdef ENCODE_SECTION_INFO
957 ENCODE_SECTION_INFO (decl
, true);
961 /* Make the rtl for variable VAR be volatile.
962 Use this only for static variables. */
965 make_var_volatile (var
)
968 if (GET_CODE (DECL_RTL (var
)) != MEM
)
971 MEM_VOLATILE_P (DECL_RTL (var
)) = 1;
974 /* Output alignment directive to align for constant expression EXP. */
977 assemble_constant_align (exp
)
982 /* Align the location counter as required by EXP's data type. */
983 align
= TYPE_ALIGN (TREE_TYPE (exp
));
984 #ifdef CONSTANT_ALIGNMENT
985 align
= CONSTANT_ALIGNMENT (exp
, align
);
988 if (align
> BITS_PER_UNIT
)
990 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
994 /* Output a string of literal assembler code
995 for an `asm' keyword used between functions. */
998 assemble_asm (string
)
1003 if (TREE_CODE (string
) == ADDR_EXPR
)
1004 string
= TREE_OPERAND (string
, 0);
1006 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1009 /* Record an element in the table of global destructors. SYMBOL is
1010 a SYMBOL_REF of the function to be called; PRIORITY is a number
1011 between 0 and MAX_INIT_PRIORITY. */
1014 default_stabs_asm_out_destructor (symbol
, priority
)
1016 int priority ATTRIBUTE_UNUSED
;
1018 /* Tell GNU LD that this is part of the static destructor set.
1019 This will work for any system that uses stabs, most usefully
1021 fprintf (asm_out_file
, "%s\"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1022 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1023 fputc ('\n', asm_out_file
);
1027 default_named_section_asm_out_destructor (symbol
, priority
)
1031 const char *section
= ".dtors";
1034 /* ??? This only works reliably with the GNU linker. */
1035 if (priority
!= DEFAULT_INIT_PRIORITY
)
1037 sprintf (buf
, ".dtors.%.5u",
1038 /* Invert the numbering so the linker puts us in the proper
1039 order; constructors are run from right to left, and the
1040 linker sorts in increasing order. */
1041 MAX_INIT_PRIORITY
- priority
);
1045 named_section_flags (section
, SECTION_WRITE
);
1046 assemble_align (POINTER_SIZE
);
1047 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1050 #ifdef DTORS_SECTION_ASM_OP
1054 if (in_section
!= in_dtors
)
1056 in_section
= in_dtors
;
1057 fputs (DTORS_SECTION_ASM_OP
, asm_out_file
);
1058 fputc ('\n', asm_out_file
);
1063 default_dtor_section_asm_out_destructor (symbol
, priority
)
1065 int priority ATTRIBUTE_UNUSED
;
1068 assemble_align (POINTER_SIZE
);
1069 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1073 /* Likewise for global constructors. */
1076 default_stabs_asm_out_constructor (symbol
, priority
)
1078 int priority ATTRIBUTE_UNUSED
;
1080 /* Tell GNU LD that this is part of the static destructor set.
1081 This will work for any system that uses stabs, most usefully
1083 fprintf (asm_out_file
, "%s\"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP
);
1084 assemble_name (asm_out_file
, XSTR (symbol
, 0));
1085 fputc ('\n', asm_out_file
);
1089 default_named_section_asm_out_constructor (symbol
, priority
)
1093 const char *section
= ".ctors";
1096 /* ??? This only works reliably with the GNU linker. */
1097 if (priority
!= DEFAULT_INIT_PRIORITY
)
1099 sprintf (buf
, ".ctors.%.5u",
1100 /* Invert the numbering so the linker puts us in the proper
1101 order; constructors are run from right to left, and the
1102 linker sorts in increasing order. */
1103 MAX_INIT_PRIORITY
- priority
);
1107 named_section_flags (section
, SECTION_WRITE
);
1108 assemble_align (POINTER_SIZE
);
1109 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1112 #ifdef CTORS_SECTION_ASM_OP
1116 if (in_section
!= in_ctors
)
1118 in_section
= in_ctors
;
1119 fputs (CTORS_SECTION_ASM_OP
, asm_out_file
);
1120 fputc ('\n', asm_out_file
);
1125 default_ctor_section_asm_out_constructor (symbol
, priority
)
1127 int priority ATTRIBUTE_UNUSED
;
1130 assemble_align (POINTER_SIZE
);
1131 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1135 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1136 a non-zero value if the constant pool should be output before the
1137 start of the function, or a zero value if the pool should output
1138 after the end of the function. The default is to put it before the
1141 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1142 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1145 /* Output assembler code for the constant pool of a function and associated
1146 with defining the name of the function. DECL describes the function.
1147 NAME is the function's name. For the constant pool, we use the current
1148 constant pool data. */
1151 assemble_start_function (decl
, fnname
)
1157 /* The following code does not need preprocessing in the assembler. */
1161 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1162 output_constant_pool (fnname
, decl
);
1164 resolve_unique_section (decl
, 0, flag_function_sections
);
1165 function_section (decl
);
1167 /* Tell assembler to move to target machine's alignment for functions. */
1168 align
= floor_log2 (FUNCTION_BOUNDARY
/ BITS_PER_UNIT
);
1171 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1174 /* Handle a user-specified function alignment.
1175 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1176 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1177 if (align_functions_log
> align
1178 && cfun
->function_frequency
!= FUNCTION_FREQUENCY_UNLIKELY_EXECUTED
)
1180 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1181 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1182 align_functions_log
, align_functions
- 1);
1184 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1188 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1189 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1192 (*debug_hooks
->begin_function
) (decl
);
1194 /* Make function name accessible from other files, if appropriate. */
1196 if (TREE_PUBLIC (decl
))
1198 if (! first_global_object_name
)
1203 STRIP_NAME_ENCODING (p
, fnname
);
1204 name
= permalloc (strlen (p
) + 1);
1207 if (! DECL_WEAK (decl
) && ! DECL_ONE_ONLY (decl
))
1208 first_global_object_name
= name
;
1210 weak_global_object_name
= name
;
1213 globalize_decl (decl
);
1215 maybe_assemble_visibility (decl
);
1218 /* Do any machine/system dependent processing of the function name */
1219 #ifdef ASM_DECLARE_FUNCTION_NAME
1220 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1222 /* Standard thing is just output label for the function. */
1223 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1224 #endif /* ASM_DECLARE_FUNCTION_NAME */
1227 /* Output assembler code associated with defining the size of the
1228 function. DECL describes the function. NAME is the function's name. */
1231 assemble_end_function (decl
, fnname
)
1235 #ifdef ASM_DECLARE_FUNCTION_SIZE
1236 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1238 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1240 output_constant_pool (fnname
, decl
);
1241 function_section (decl
); /* need to switch back */
1244 /* Output any constants which should appear after the function. */
1245 output_after_function_constants ();
1248 /* Assemble code to leave SIZE bytes of zeros. */
1251 assemble_zeros (size
)
1254 /* Do no output if -fsyntax-only. */
1255 if (flag_syntax_only
)
1258 #ifdef ASM_NO_SKIP_IN_TEXT
1259 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1260 so we must output 0s explicitly in the text section. */
1261 if (ASM_NO_SKIP_IN_TEXT
&& in_text_section ())
1264 for (i
= 0; i
< size
; i
++)
1265 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1270 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1273 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1276 assemble_align (align
)
1279 if (align
> BITS_PER_UNIT
)
1281 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1285 /* Assemble a string constant with the specified C string as contents. */
1288 assemble_string (p
, size
)
1295 /* If the string is very long, split it up. */
1299 int thissize
= size
- pos
;
1300 if (thissize
> maximum
)
1303 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1311 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1312 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1313 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1315 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1316 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1317 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1319 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1320 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1324 #if defined ASM_OUTPUT_ALIGNED_BSS
1325 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1326 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1328 #if defined ASM_OUTPUT_BSS
1329 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1330 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1336 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1337 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1338 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1340 #if defined ASM_OUTPUT_ALIGNED_COMMON
1341 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1342 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1344 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1345 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1350 asm_emit_uninitialised (decl
, name
, size
, rounded
)
1353 int size ATTRIBUTE_UNUSED
;
1354 int rounded ATTRIBUTE_UNUSED
;
1362 destination
= asm_dest_local
;
1364 if (TREE_PUBLIC (decl
))
1366 #if defined ASM_EMIT_BSS
1367 if (! DECL_COMMON (decl
))
1368 destination
= asm_dest_bss
;
1371 destination
= asm_dest_common
;
1374 if (destination
== asm_dest_bss
)
1375 globalize_decl (decl
);
1376 resolve_unique_section (decl
, 0, flag_data_sections
);
1378 if (flag_shared_data
)
1380 switch (destination
)
1382 #ifdef ASM_OUTPUT_SHARED_BSS
1384 ASM_OUTPUT_SHARED_BSS (asm_out_file
, decl
, name
, size
, rounded
);
1387 #ifdef ASM_OUTPUT_SHARED_COMMON
1388 case asm_dest_common
:
1389 ASM_OUTPUT_SHARED_COMMON (asm_out_file
, name
, size
, rounded
);
1392 #ifdef ASM_OUTPUT_SHARED_LOCAL
1393 case asm_dest_local
:
1394 ASM_OUTPUT_SHARED_LOCAL (asm_out_file
, name
, size
, rounded
);
1402 switch (destination
)
1406 ASM_EMIT_BSS (decl
, name
, size
, rounded
);
1409 case asm_dest_common
:
1410 ASM_EMIT_COMMON (decl
, name
, size
, rounded
);
1412 case asm_dest_local
:
1413 ASM_EMIT_LOCAL (decl
, name
, size
, rounded
);
1422 /* Assemble everything that is needed for a variable or function declaration.
1423 Not used for automatic variables, and not used for function definitions.
1424 Should not be called for variables of incomplete structure type.
1426 TOP_LEVEL is nonzero if this variable has file scope.
1427 AT_END is nonzero if this is the special handling, at end of compilation,
1428 to define things that have had only tentative definitions.
1429 DONT_OUTPUT_DATA if nonzero means don't actually output the
1430 initial value (that will be done by the caller). */
1433 assemble_variable (decl
, top_level
, at_end
, dont_output_data
)
1435 int top_level ATTRIBUTE_UNUSED
;
1436 int at_end ATTRIBUTE_UNUSED
;
1437 int dont_output_data
;
1444 last_assemble_variable_decl
= 0;
1446 /* Normally no need to say anything here for external references,
1447 since assemble_external is called by the language-specific code
1448 when a declaration is first seen. */
1450 if (DECL_EXTERNAL (decl
))
1453 /* Output no assembler code for a function declaration.
1454 Only definitions of functions output anything. */
1456 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1459 /* Do nothing for global register variables. */
1460 if (DECL_RTL_SET_P (decl
) && GET_CODE (DECL_RTL (decl
)) == REG
)
1462 TREE_ASM_WRITTEN (decl
) = 1;
1466 /* If type was incomplete when the variable was declared,
1467 see if it is complete now. */
1469 if (DECL_SIZE (decl
) == 0)
1470 layout_decl (decl
, 0);
1472 /* Still incomplete => don't allocate it; treat the tentative defn
1473 (which is what it must have been) as an `extern' reference. */
1475 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
1477 error_with_file_and_line (DECL_SOURCE_FILE (decl
),
1478 DECL_SOURCE_LINE (decl
),
1479 "storage size of `%s' isn't known",
1480 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1481 TREE_ASM_WRITTEN (decl
) = 1;
1485 /* The first declaration of a variable that comes through this function
1486 decides whether it is global (in C, has external linkage)
1487 or local (in C, has internal linkage). So do nothing more
1488 if this function has already run. */
1490 if (TREE_ASM_WRITTEN (decl
))
1493 /* Make sure ENCODE_SECTION_INFO is invoked before we set ASM_WRITTEN. */
1494 decl_rtl
= DECL_RTL (decl
);
1496 TREE_ASM_WRITTEN (decl
) = 1;
1498 /* Do no output if -fsyntax-only. */
1499 if (flag_syntax_only
)
1504 if (! dont_output_data
1505 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
1507 error_with_decl (decl
, "size of variable `%s' is too large");
1511 name
= XSTR (XEXP (decl_rtl
, 0), 0);
1512 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
)
1513 && ! first_global_object_name
1514 && ! (DECL_COMMON (decl
) && (DECL_INITIAL (decl
) == 0
1515 || DECL_INITIAL (decl
) == error_mark_node
))
1516 && ! DECL_WEAK (decl
)
1517 && ! DECL_ONE_ONLY (decl
))
1522 STRIP_NAME_ENCODING (p
, name
);
1523 xname
= permalloc (strlen (p
) + 1);
1525 first_global_object_name
= xname
;
1528 /* Compute the alignment of this data. */
1530 align
= DECL_ALIGN (decl
);
1532 /* In the case for initialing an array whose length isn't specified,
1533 where we have not yet been able to do the layout,
1534 figure out the proper alignment now. */
1535 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1536 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1537 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1539 /* Some object file formats have a maximum alignment which they support.
1540 In particular, a.out format supports a maximum alignment of 4. */
1541 #ifndef MAX_OFILE_ALIGNMENT
1542 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1544 if (align
> MAX_OFILE_ALIGNMENT
)
1546 warning_with_decl (decl
,
1547 "alignment of `%s' is greater than maximum object file alignment. Using %d",
1548 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1549 align
= MAX_OFILE_ALIGNMENT
;
1552 /* On some machines, it is good to increase alignment sometimes. */
1553 if (! DECL_USER_ALIGN (decl
))
1555 #ifdef DATA_ALIGNMENT
1556 align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1558 #ifdef CONSTANT_ALIGNMENT
1559 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1560 align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
), align
);
1564 /* Reset the alignment in case we have made it tighter, so we can benefit
1565 from it in get_pointer_alignment. */
1566 DECL_ALIGN (decl
) = align
;
1567 set_mem_align (decl_rtl
, align
);
1569 if (TREE_PUBLIC (decl
))
1570 maybe_assemble_visibility (decl
);
1572 /* Output any data that we will need to use the address of. */
1573 if (DECL_INITIAL (decl
) == error_mark_node
)
1574 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1575 else if (DECL_INITIAL (decl
))
1576 reloc
= output_addressed_constants (DECL_INITIAL (decl
));
1577 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1579 /* Handle uninitialized definitions. */
1581 if ((DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
1582 #if defined ASM_EMIT_BSS
1583 || (flag_zero_initialized_in_bss
1584 && initializer_zerop (DECL_INITIAL (decl
)))
1587 /* If the target can't output uninitialized but not common global data
1588 in .bss, then we have to use .data. */
1589 #if ! defined ASM_EMIT_BSS
1590 && DECL_COMMON (decl
)
1592 && DECL_SECTION_NAME (decl
) == NULL_TREE
1593 && ! dont_output_data
)
1595 unsigned HOST_WIDE_INT size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
1596 unsigned HOST_WIDE_INT rounded
= size
;
1598 /* Don't allocate zero bytes of common,
1599 since that means "undefined external" in the linker. */
1603 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1604 so that each uninitialized object starts on such a boundary. */
1605 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
1606 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1607 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1609 /* Don't continue this line--convex cc version 4.1 would lose. */
1610 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1611 if ((unsigned HOST_WIDE_INT
) DECL_ALIGN (decl
) / BITS_PER_UNIT
> rounded
)
1613 (decl
, "requested alignment for %s is greater than implemented alignment of %d",rounded
);
1616 asm_emit_uninitialised (decl
, name
, size
, rounded
);
1621 /* Handle initialized definitions.
1622 Also handle uninitialized global definitions if -fno-common and the
1623 target doesn't support ASM_OUTPUT_BSS. */
1625 /* First make the assembler name(s) global if appropriate. */
1626 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
1627 globalize_decl (decl
);
1629 /* Switch to the appropriate section. */
1630 variable_section (decl
, reloc
);
1632 /* dbxout.c needs to know this. */
1633 if (in_text_section ())
1634 DECL_IN_TEXT_SECTION (decl
) = 1;
1636 /* Output the alignment of this data. */
1637 if (align
> BITS_PER_UNIT
)
1639 ASM_OUTPUT_ALIGN (asm_out_file
,
1640 floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
));
1643 /* Do any machine/system dependent processing of the object. */
1644 #ifdef ASM_DECLARE_OBJECT_NAME
1645 last_assemble_variable_decl
= decl
;
1646 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
1648 /* Standard thing is just output label for the object. */
1649 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1650 #endif /* ASM_DECLARE_OBJECT_NAME */
1652 if (!dont_output_data
)
1654 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
1655 /* Output the actual data. */
1656 output_constant (DECL_INITIAL (decl
),
1657 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
1660 /* Leave space for it. */
1661 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
1665 /* Return 1 if type TYPE contains any pointers. */
1668 contains_pointers_p (type
)
1671 switch (TREE_CODE (type
))
1674 case REFERENCE_TYPE
:
1675 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1676 so I'll play safe and return 1. */
1682 case QUAL_UNION_TYPE
:
1685 /* For a type that has fields, see if the fields have pointers. */
1686 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
1687 if (TREE_CODE (fields
) == FIELD_DECL
1688 && contains_pointers_p (TREE_TYPE (fields
)))
1694 /* An array type contains pointers if its element type does. */
1695 return contains_pointers_p (TREE_TYPE (type
));
1702 /* Output something to declare an external symbol to the assembler.
1703 (Most assemblers don't need this, so we normally output nothing.)
1704 Do nothing if DECL is not external. */
1707 assemble_external (decl
)
1708 tree decl ATTRIBUTE_UNUSED
;
1710 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
1711 main body of this code is only rarely exercised. To provide some
1712 testing, on all platforms, we make sure that the ASM_OUT_FILE is
1713 open. If it's not, we should not be calling this function. */
1717 #ifdef ASM_OUTPUT_EXTERNAL
1718 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
1720 rtx rtl
= DECL_RTL (decl
);
1722 if (GET_CODE (rtl
) == MEM
&& GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
1723 && ! SYMBOL_REF_USED (XEXP (rtl
, 0)))
1725 /* Some systems do require some output. */
1726 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
1727 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
1733 /* Similar, for calling a library function FUN. */
1736 assemble_external_libcall (fun
)
1737 rtx fun ATTRIBUTE_UNUSED
;
1739 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1740 /* Declare library function name external when first used, if nec. */
1741 if (! SYMBOL_REF_USED (fun
))
1743 SYMBOL_REF_USED (fun
) = 1;
1744 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file
, fun
);
1749 /* Declare the label NAME global. */
1752 assemble_global (name
)
1753 const char *name ATTRIBUTE_UNUSED
;
1755 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
1758 /* Assemble a label named NAME. */
1761 assemble_label (name
)
1764 ASM_OUTPUT_LABEL (asm_out_file
, name
);
1767 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1768 If NAME starts with a *, the rest of NAME is output verbatim.
1769 Otherwise NAME is transformed in an implementation-defined way
1770 (usually by the addition of an underscore).
1771 Many macros in the tm file are defined to call this function. */
1774 assemble_name (file
, name
)
1778 const char *real_name
;
1781 STRIP_NAME_ENCODING (real_name
, name
);
1783 id
= maybe_get_identifier (real_name
);
1785 TREE_SYMBOL_REFERENCED (id
) = 1;
1788 fputs (&name
[1], file
);
1790 ASM_OUTPUT_LABELREF (file
, name
);
1793 /* Allocate SIZE bytes writable static space with a gensym name
1794 and return an RTX to refer to its address. */
1797 assemble_static_space (size
)
1801 const char *namestring
;
1805 if (flag_shared_data
)
1809 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
1811 namestring
= ggc_strdup (name
);
1813 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
1815 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1816 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
1819 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1820 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
1823 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1824 so that each uninitialized object starts on such a boundary. */
1825 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1826 int rounded ATTRIBUTE_UNUSED
1827 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
1828 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
1829 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
1830 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1837 /* Assemble the static constant template for function entry trampolines.
1838 This is done at most once per compilation.
1839 Returns an RTX for the address of the template. */
1841 #ifdef TRAMPOLINE_TEMPLATE
1843 assemble_trampoline_template ()
1849 /* By default, put trampoline templates in read-only data section. */
1851 #ifdef TRAMPOLINE_SECTION
1852 TRAMPOLINE_SECTION ();
1854 readonly_data_section ();
1857 /* Write the assembler code to define one. */
1858 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
1861 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1864 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LTRAMP", 0);
1865 TRAMPOLINE_TEMPLATE (asm_out_file
);
1867 /* Record the rtl to refer to it. */
1868 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
1869 name
= ggc_strdup (label
);
1870 return gen_rtx_SYMBOL_REF (Pmode
, name
);
1874 /* A and B are either alignments or offsets. Return the minimum alignment
1875 that may be assumed after adding the two together. */
1877 static inline unsigned
1881 return (a
| b
) & -(a
| b
);
1884 /* Return the assembler directive for creating a given kind of integer
1885 object. SIZE is the number of bytes in the object and ALIGNED_P
1886 indicates whether it is known to be aligned. Return NULL if the
1887 assembly dialect has no such directive.
1889 The returned string should be printed at the start of a new line and
1890 be followed immediately by the object's initial value. */
1893 integer_asm_op (size
, aligned_p
)
1897 struct asm_int_op
*ops
;
1900 ops
= &targetm
.asm_out
.aligned_op
;
1902 ops
= &targetm
.asm_out
.unaligned_op
;
1907 return targetm
.asm_out
.byte_op
;
1921 /* Use directive OP to assemble an integer object X. Print OP at the
1922 start of the line, followed immediately by the value of X. */
1925 assemble_integer_with_op (op
, x
)
1929 fputs (op
, asm_out_file
);
1930 output_addr_const (asm_out_file
, x
);
1931 fputc ('\n', asm_out_file
);
1934 /* The default implementation of the asm_out.integer target hook. */
1937 default_assemble_integer (x
, size
, aligned_p
)
1938 rtx x ATTRIBUTE_UNUSED
;
1939 unsigned int size ATTRIBUTE_UNUSED
;
1940 int aligned_p ATTRIBUTE_UNUSED
;
1942 const char *op
= integer_asm_op (size
, aligned_p
);
1943 return op
&& (assemble_integer_with_op (op
, x
), true);
1946 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
1947 the alignment of the integer in bits. Return 1 if we were able to output
1948 the constant, otherwise 0. If FORCE is non-zero, abort if we can't output
1952 assemble_integer (x
, size
, align
, force
)
1960 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
1962 /* See if the target hook can handle this kind of object. */
1963 if ((*targetm
.asm_out
.integer
) (x
, size
, aligned_p
))
1966 /* If the object is a multi-byte one, try splitting it up. Split
1967 it into words it if is multi-word, otherwise split it into bytes. */
1970 enum machine_mode omode
, imode
;
1971 unsigned int subalign
;
1972 unsigned int subsize
, i
;
1974 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
1975 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
1976 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, MODE_INT
, 0);
1977 imode
= mode_for_size (size
* BITS_PER_UNIT
, MODE_INT
, 0);
1979 for (i
= 0; i
< size
; i
+= subsize
)
1981 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
1982 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
1988 /* If we've printed some of it, but not all of it, there's no going
2001 assemble_real (d
, mode
, align
)
2003 enum machine_mode mode
;
2008 unsigned int nalign
= min_align (align
, 32);
2010 switch (BITS_PER_UNIT
)
2016 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2017 assemble_integer (GEN_INT (l
), 4, align
, 1);
2020 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2021 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
2022 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
2025 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d
, data
);
2026 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
2027 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
2028 assemble_integer (GEN_INT (data
[2]), 4, nalign
, 1);
2031 REAL_VALUE_TO_TARGET_LONG_DOUBLE (d
, data
);
2032 assemble_integer (GEN_INT (data
[0]), 4, align
, 1);
2033 assemble_integer (GEN_INT (data
[1]), 4, nalign
, 1);
2034 assemble_integer (GEN_INT (data
[2]), 4, nalign
, 1);
2035 assemble_integer (GEN_INT (data
[3]), 4, nalign
, 1);
2046 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2047 assemble_integer (GEN_INT (l
), 2, align
, 1);
2050 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2051 assemble_integer (GEN_INT (data
[0]), 2, align
, 1);
2052 assemble_integer (GEN_INT (data
[1]), 1, nalign
, 1);
2063 REAL_VALUE_TO_TARGET_SINGLE (d
, l
);
2064 assemble_integer (GEN_INT (l
), 1, align
, 1);
2067 REAL_VALUE_TO_TARGET_DOUBLE (d
, data
);
2068 assemble_integer (GEN_INT (data
[0]), 1, align
, 1);
2069 assemble_integer (GEN_INT (data
[1]), 1, nalign
, 1);
2081 /* Given an expression EXP with a constant value,
2082 reduce it to the sum of an assembler symbol and an integer.
2083 Store them both in the structure *VALUE.
2084 Abort if EXP does not reduce. */
2089 HOST_WIDE_INT offset
;
2093 decode_addr_const (exp
, value
)
2095 struct addr_const
*value
;
2097 tree target
= TREE_OPERAND (exp
, 0);
2103 if (TREE_CODE (target
) == COMPONENT_REF
2104 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2107 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2108 target
= TREE_OPERAND (target
, 0);
2110 else if (TREE_CODE (target
) == ARRAY_REF
2111 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2113 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2114 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2115 target
= TREE_OPERAND (target
, 0);
2121 switch (TREE_CODE (target
))
2125 x
= DECL_RTL (target
);
2129 x
= gen_rtx_MEM (FUNCTION_MODE
,
2130 gen_rtx_LABEL_REF (VOIDmode
,
2131 label_rtx (TREE_OPERAND (exp
, 0))));
2139 /* This constant should have been output already, but we can't simply
2140 use TREE_CST_RTL since INTEGER_CST doesn't have one. */
2141 x
= output_constant_def (target
, 1);
2148 if (GET_CODE (x
) != MEM
)
2153 value
->offset
= offset
;
2156 /* We do RTX_UNSPEC + XINT (blah), so nothing can go after RTX_UNSPEC. */
2157 enum kind
{ RTX_UNKNOWN
, RTX_DOUBLE
, RTX_INT
, RTX_VECTOR
, RTX_UNSPEC
};
2160 ENUM_BITFIELD(kind
) kind
: 16;
2161 ENUM_BITFIELD(machine_mode
) mode
: 16;
2164 struct addr_const addr
;
2165 struct {HOST_WIDE_INT high
, low
;} di
;
2167 /* The max vector size we have is 8 wide. This should be enough. */
2168 HOST_WIDE_INT veclo
[16];
2169 HOST_WIDE_INT vechi
[16];
2173 /* Uniquize all constants that appear in memory.
2174 Each constant in memory thus far output is recorded
2175 in `const_hash_table' with a `struct constant_descriptor'
2176 that contains a polish representation of the value of
2179 We cannot store the trees in the hash table
2180 because the trees may be temporary. */
2182 struct constant_descriptor
2184 struct constant_descriptor
*next
;
2187 /* Make sure the data is reasonably aligned. */
2190 unsigned char contents
[1];
2191 #ifdef HAVE_LONG_DOUBLE
2200 #define MAX_HASH_TABLE 1009
2201 static struct constant_descriptor
*const_hash_table
[MAX_HASH_TABLE
];
2203 /* We maintain a hash table of STRING_CST values. Unless we are asked to force
2204 out a string constant, we defer output of the constants until we know
2205 they are actually used. This will be if something takes its address or if
2206 there is a usage of the string in the RTL of a function. */
2208 #define STRHASH(x) ((hashval_t) ((long) (x) >> 3))
2210 struct deferred_string
2217 static htab_t const_str_htab
;
2219 /* Mark a const_hash_table descriptor for GC. */
2222 mark_const_hash_entry (ptr
)
2225 struct constant_descriptor
*desc
= * (struct constant_descriptor
**) ptr
;
2229 ggc_mark_rtx (desc
->rtl
);
2234 /* Mark the hash-table element X (which is really a pointer to an
2235 struct deferred_string *). */
2238 mark_const_str_htab_1 (x
, data
)
2240 void *data ATTRIBUTE_UNUSED
;
2242 ggc_mark_tree (((struct deferred_string
*) *x
)->exp
);
2246 /* Mark a const_str_htab for GC. */
2249 mark_const_str_htab (htab
)
2252 htab_traverse (*((htab_t
*) htab
), mark_const_str_htab_1
, NULL
);
2255 /* Returns a hash code for X (which is a really a
2256 struct deferred_string *). */
2259 const_str_htab_hash (x
)
2262 return STRHASH (((const struct deferred_string
*) x
)->label
);
2265 /* Returns non-zero if the value represented by X (which is really a
2266 struct deferred_string *) is the same as that given by Y
2267 (which is really a char *). */
2270 const_str_htab_eq (x
, y
)
2274 return (((const struct deferred_string
*) x
)->label
== (const char *) y
);
2277 /* Delete the hash table entry dfsp. */
2280 const_str_htab_del (dfsp
)
2286 /* Compute a hash code for a constant expression. */
2294 enum tree_code code
= TREE_CODE (exp
);
2296 /* Either set P and LEN to the address and len of something to hash and
2297 exit the switch or return a value. */
2302 p
= (char *) &TREE_INT_CST (exp
);
2303 len
= sizeof TREE_INT_CST (exp
);
2307 p
= (char *) &TREE_REAL_CST (exp
);
2308 len
= sizeof TREE_REAL_CST (exp
);
2312 p
= TREE_STRING_POINTER (exp
);
2313 len
= TREE_STRING_LENGTH (exp
);
2317 return (const_hash (TREE_REALPART (exp
)) * 5
2318 + const_hash (TREE_IMAGPART (exp
)));
2321 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2325 len
= int_size_in_bytes (TREE_TYPE (exp
));
2326 tmp
= (char *) alloca (len
);
2327 get_set_constructor_bytes (exp
, (unsigned char *) tmp
, len
);
2335 /* For record type, include the type in the hashing.
2336 We do not do so for array types
2337 because (1) the sizes of the elements are sufficient
2338 and (2) distinct array types can have the same constructor.
2339 Instead, we include the array size because the constructor could
2341 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2342 hi
= ((unsigned long) TREE_TYPE (exp
) & ((1 << HASHBITS
) - 1))
2345 hi
= ((5 + int_size_in_bytes (TREE_TYPE (exp
)))
2346 & ((1 << HASHBITS
) - 1)) % MAX_HASH_TABLE
;
2348 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2349 if (TREE_VALUE (link
))
2351 = (hi
* 603 + const_hash (TREE_VALUE (link
))) % MAX_HASH_TABLE
;
2358 struct addr_const value
;
2360 decode_addr_const (exp
, &value
);
2361 if (GET_CODE (value
.base
) == SYMBOL_REF
)
2363 /* Don't hash the address of the SYMBOL_REF;
2364 only use the offset and the symbol name. */
2366 p
= XSTR (value
.base
, 0);
2367 for (i
= 0; p
[i
] != 0; i
++)
2368 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2370 else if (GET_CODE (value
.base
) == LABEL_REF
)
2371 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
2375 hi
&= (1 << HASHBITS
) - 1;
2376 hi
%= MAX_HASH_TABLE
;
2382 return (const_hash (TREE_OPERAND (exp
, 0)) * 9
2383 + const_hash (TREE_OPERAND (exp
, 1)));
2387 case NON_LVALUE_EXPR
:
2388 return const_hash (TREE_OPERAND (exp
, 0)) * 7 + 2;
2391 /* A language specific constant. Just hash the code. */
2392 return (int) code
% MAX_HASH_TABLE
;
2395 /* Compute hashing function */
2397 for (i
= 0; i
< len
; i
++)
2398 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2400 hi
&= (1 << HASHBITS
) - 1;
2401 hi
%= MAX_HASH_TABLE
;
2405 /* Compare a constant expression EXP with a constant-descriptor DESC.
2406 Return 1 if DESC describes a constant with the same value as EXP. */
2409 compare_constant (exp
, desc
)
2411 struct constant_descriptor
*desc
;
2413 return 0 != compare_constant_1 (exp
, desc
->u
.contents
);
2416 /* Compare constant expression EXP with a substring P of a constant descriptor.
2417 If they match, return a pointer to the end of the substring matched.
2418 If they do not match, return 0.
2420 Since descriptors are written in polish prefix notation,
2421 this function can be used recursively to test one operand of EXP
2422 against a subdescriptor, and if it succeeds it returns the
2423 address of the subdescriptor for the next operand. */
2425 static const unsigned char *
2426 compare_constant_1 (exp
, p
)
2428 const unsigned char *p
;
2430 const unsigned char *strp
;
2432 enum tree_code code
= TREE_CODE (exp
);
2434 if (code
!= (enum tree_code
) *p
++)
2437 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2438 switch, or return the result of the comparison. */
2443 /* Integer constants are the same only if the same width of type. */
2444 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2447 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2448 len
= sizeof TREE_INT_CST (exp
);
2452 /* Real constants are the same only if the same width of type. */
2453 if (*p
++ != TYPE_PRECISION (TREE_TYPE (exp
)))
2456 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2457 len
= sizeof TREE_REAL_CST (exp
);
2461 if (flag_writable_strings
)
2464 if ((enum machine_mode
) *p
++ != TYPE_MODE (TREE_TYPE (exp
)))
2467 strp
= (const unsigned char *) TREE_STRING_POINTER (exp
);
2468 len
= TREE_STRING_LENGTH (exp
);
2469 if (memcmp ((char *) &TREE_STRING_LENGTH (exp
), p
,
2470 sizeof TREE_STRING_LENGTH (exp
)))
2473 p
+= sizeof TREE_STRING_LENGTH (exp
);
2477 p
= compare_constant_1 (TREE_REALPART (exp
), p
);
2481 return compare_constant_1 (TREE_IMAGPART (exp
), p
);
2484 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2486 int xlen
= len
= int_size_in_bytes (TREE_TYPE (exp
));
2487 unsigned char *tmp
= (unsigned char *) alloca (len
);
2489 get_set_constructor_bytes (exp
, tmp
, len
);
2490 strp
= (unsigned char *) tmp
;
2491 if (memcmp ((char *) &xlen
, p
, sizeof xlen
))
2500 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2502 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2503 int have_purpose
= 0;
2505 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2506 if (TREE_PURPOSE (link
))
2509 if (memcmp ((char *) &length
, p
, sizeof length
))
2514 /* For record constructors, insist that the types match.
2515 For arrays, just verify both constructors are for arrays.
2516 Then insist that either both or none have any TREE_PURPOSE
2518 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2519 type
= TREE_TYPE (exp
);
2523 if (memcmp ((char *) &type
, p
, sizeof type
))
2526 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2528 if (memcmp ((char *) &mode
, p
, sizeof mode
))
2536 if (memcmp ((char *) &have_purpose
, p
, sizeof have_purpose
))
2539 p
+= sizeof have_purpose
;
2541 /* For arrays, insist that the size in bytes match. */
2542 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2544 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2546 if (memcmp ((char *) &size
, p
, sizeof size
))
2552 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2554 if (TREE_VALUE (link
))
2556 if ((p
= compare_constant_1 (TREE_VALUE (link
), p
)) == 0)
2563 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2569 if (TREE_PURPOSE (link
)
2570 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2572 if (memcmp ((char *) &TREE_PURPOSE (link
), p
,
2573 sizeof TREE_PURPOSE (link
)))
2576 p
+= sizeof TREE_PURPOSE (link
);
2578 else if (TREE_PURPOSE (link
))
2580 if ((p
= compare_constant_1 (TREE_PURPOSE (link
), p
)) == 0)
2583 else if (have_purpose
)
2587 if (memcmp ((char *) &zero
, p
, sizeof zero
))
2599 struct addr_const value
;
2601 decode_addr_const (exp
, &value
);
2602 strp
= (unsigned char *) &value
.offset
;
2603 len
= sizeof value
.offset
;
2604 /* Compare the offset. */
2606 if (*p
++ != *strp
++)
2609 /* Compare symbol name. */
2610 strp
= (const unsigned char *) XSTR (value
.base
, 0);
2611 len
= strlen ((const char *) strp
) + 1;
2618 p
= compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2622 return compare_constant_1 (TREE_OPERAND (exp
, 1), p
);
2626 case NON_LVALUE_EXPR
:
2627 return compare_constant_1 (TREE_OPERAND (exp
, 0), p
);
2631 tree
new = (*lang_hooks
.expand_constant
) (exp
);
2634 return compare_constant_1 (new, p
);
2640 /* Compare constant contents. */
2642 if (*p
++ != *strp
++)
2648 /* Construct a constant descriptor for the expression EXP.
2649 It is up to the caller to enter the descriptor in the hash table. */
2651 static struct constant_descriptor
*
2652 record_constant (exp
)
2655 struct constant_descriptor
*next
= 0;
2660 /* Make a struct constant_descriptor. The first three pointers will
2661 be filled in later. Here we just leave space for them. */
2663 obstack_grow (&permanent_obstack
, (char *) &next
, sizeof next
);
2664 obstack_grow (&permanent_obstack
, (char *) &label
, sizeof label
);
2665 obstack_grow (&permanent_obstack
, (char *) &rtl
, sizeof rtl
);
2667 /* Align the descriptor for the data payload. */
2668 pad
= (offsetof (struct constant_descriptor
, u
)
2669 - offsetof(struct constant_descriptor
, rtl
)
2670 - sizeof(next
->rtl
));
2672 obstack_blank (&permanent_obstack
, pad
);
2674 record_constant_1 (exp
);
2675 return (struct constant_descriptor
*) obstack_finish (&permanent_obstack
);
2678 /* Add a description of constant expression EXP
2679 to the object growing in `permanent_obstack'.
2680 No need to return its address; the caller will get that
2681 from the obstack when the object is complete. */
2684 record_constant_1 (exp
)
2687 const unsigned char *strp
;
2689 enum tree_code code
= TREE_CODE (exp
);
2691 obstack_1grow (&permanent_obstack
, (unsigned int) code
);
2696 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2697 strp
= (unsigned char *) &TREE_INT_CST (exp
);
2698 len
= sizeof TREE_INT_CST (exp
);
2702 obstack_1grow (&permanent_obstack
, TYPE_PRECISION (TREE_TYPE (exp
)));
2703 strp
= (unsigned char *) &TREE_REAL_CST (exp
);
2704 len
= sizeof TREE_REAL_CST (exp
);
2708 if (flag_writable_strings
)
2711 obstack_1grow (&permanent_obstack
, TYPE_MODE (TREE_TYPE (exp
)));
2712 strp
= (const unsigned char *) TREE_STRING_POINTER (exp
);
2713 len
= TREE_STRING_LENGTH (exp
);
2714 obstack_grow (&permanent_obstack
, (char *) &TREE_STRING_LENGTH (exp
),
2715 sizeof TREE_STRING_LENGTH (exp
));
2719 record_constant_1 (TREE_REALPART (exp
));
2720 record_constant_1 (TREE_IMAGPART (exp
));
2724 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2726 int nbytes
= int_size_in_bytes (TREE_TYPE (exp
));
2727 obstack_grow (&permanent_obstack
, &nbytes
, sizeof (nbytes
));
2728 obstack_blank (&permanent_obstack
, nbytes
);
2729 get_set_constructor_bytes
2730 (exp
, (unsigned char *) permanent_obstack
.next_free
- nbytes
,
2737 int length
= list_length (CONSTRUCTOR_ELTS (exp
));
2738 enum machine_mode mode
= TYPE_MODE (TREE_TYPE (exp
));
2740 int have_purpose
= 0;
2742 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2743 if (TREE_PURPOSE (link
))
2746 obstack_grow (&permanent_obstack
, (char *) &length
, sizeof length
);
2748 /* For record constructors, insist that the types match.
2749 For arrays, just verify both constructors are for arrays
2750 of the same mode. Then insist that either both or none
2751 have any TREE_PURPOSE values. */
2752 if (TREE_CODE (TREE_TYPE (exp
)) == RECORD_TYPE
)
2753 type
= TREE_TYPE (exp
);
2757 obstack_grow (&permanent_obstack
, (char *) &type
, sizeof type
);
2758 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2759 obstack_grow (&permanent_obstack
, &mode
, sizeof mode
);
2761 obstack_grow (&permanent_obstack
, (char *) &have_purpose
,
2762 sizeof have_purpose
);
2764 /* For arrays, insist that the size in bytes match. */
2765 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
2767 HOST_WIDE_INT size
= int_size_in_bytes (TREE_TYPE (exp
));
2768 obstack_grow (&permanent_obstack
, (char *) &size
, sizeof size
);
2771 for (link
= CONSTRUCTOR_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2773 if (TREE_VALUE (link
))
2774 record_constant_1 (TREE_VALUE (link
));
2779 obstack_grow (&permanent_obstack
,
2780 (char *) &zero
, sizeof zero
);
2783 if (TREE_PURPOSE (link
)
2784 && TREE_CODE (TREE_PURPOSE (link
)) == FIELD_DECL
)
2785 obstack_grow (&permanent_obstack
,
2786 (char *) &TREE_PURPOSE (link
),
2787 sizeof TREE_PURPOSE (link
));
2788 else if (TREE_PURPOSE (link
))
2789 record_constant_1 (TREE_PURPOSE (link
));
2790 else if (have_purpose
)
2794 obstack_grow (&permanent_obstack
,
2795 (char *) &zero
, sizeof zero
);
2803 struct addr_const value
;
2805 decode_addr_const (exp
, &value
);
2806 /* Record the offset. */
2807 obstack_grow (&permanent_obstack
,
2808 (char *) &value
.offset
, sizeof value
.offset
);
2810 switch (GET_CODE (value
.base
))
2813 /* Record the symbol name. */
2814 obstack_grow (&permanent_obstack
, XSTR (value
.base
, 0),
2815 strlen (XSTR (value
.base
, 0)) + 1);
2818 /* Record the address of the CODE_LABEL. It may not have
2819 been emitted yet, so it's UID may be zero. But pointer
2820 identity is good enough. */
2821 obstack_grow (&permanent_obstack
, &XEXP (value
.base
, 0),
2833 record_constant_1 (TREE_OPERAND (exp
, 0));
2834 record_constant_1 (TREE_OPERAND (exp
, 1));
2839 case NON_LVALUE_EXPR
:
2840 record_constant_1 (TREE_OPERAND (exp
, 0));
2845 tree
new = (*lang_hooks
.expand_constant
) (exp
);
2848 record_constant_1 (new);
2853 /* Record constant contents. */
2854 obstack_grow (&permanent_obstack
, strp
, len
);
2857 /* Record a list of constant expressions that were passed to
2858 output_constant_def but that could not be output right away. */
2860 struct deferred_constant
2862 struct deferred_constant
*next
;
2868 static struct deferred_constant
*deferred_constants
;
2870 /* Another list of constants which should be output after the
2872 static struct deferred_constant
*after_function_constants
;
2874 /* Nonzero means defer output of addressed subconstants
2875 (i.e., those for which output_constant_def is called.) */
2876 static int defer_addressed_constants_flag
;
2878 /* Start deferring output of subconstants. */
2881 defer_addressed_constants ()
2883 defer_addressed_constants_flag
++;
2886 /* Stop deferring output of subconstants,
2887 and output now all those that have been deferred. */
2890 output_deferred_addressed_constants ()
2892 struct deferred_constant
*p
, *next
;
2894 defer_addressed_constants_flag
--;
2896 if (defer_addressed_constants_flag
> 0)
2899 for (p
= deferred_constants
; p
; p
= next
)
2901 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2906 deferred_constants
= 0;
2909 /* Output any constants which should appear after a function. */
2912 output_after_function_constants ()
2914 struct deferred_constant
*p
, *next
;
2916 for (p
= after_function_constants
; p
; p
= next
)
2918 output_constant_def_contents (p
->exp
, p
->reloc
, p
->labelno
);
2923 after_function_constants
= 0;
2926 /* Make a copy of the whole tree structure for a constant.
2927 This handles the same types of nodes that compare_constant
2928 and record_constant handle. */
2934 switch (TREE_CODE (exp
))
2937 /* For ADDR_EXPR, we do not want to copy the decl whose address
2938 is requested. We do want to copy constants though. */
2939 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp
, 0))) == 'c')
2940 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2941 copy_constant (TREE_OPERAND (exp
, 0)));
2943 return copy_node (exp
);
2948 return copy_node (exp
);
2951 return build_complex (TREE_TYPE (exp
),
2952 copy_constant (TREE_REALPART (exp
)),
2953 copy_constant (TREE_IMAGPART (exp
)));
2957 return build (TREE_CODE (exp
), TREE_TYPE (exp
),
2958 copy_constant (TREE_OPERAND (exp
, 0)),
2959 copy_constant (TREE_OPERAND (exp
, 1)));
2963 case NON_LVALUE_EXPR
:
2964 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
2965 copy_constant (TREE_OPERAND (exp
, 0)));
2969 tree copy
= copy_node (exp
);
2970 tree list
= copy_list (CONSTRUCTOR_ELTS (exp
));
2973 CONSTRUCTOR_ELTS (copy
) = list
;
2974 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2975 TREE_VALUE (tail
) = copy_constant (TREE_VALUE (tail
));
2976 if (TREE_CODE (TREE_TYPE (exp
)) == SET_TYPE
)
2977 for (tail
= list
; tail
; tail
= TREE_CHAIN (tail
))
2978 TREE_PURPOSE (tail
) = copy_constant (TREE_PURPOSE (tail
));
2988 /* Return an rtx representing a reference to constant data in memory
2989 for the constant expression EXP.
2991 If assembler code for such a constant has already been output,
2992 return an rtx to refer to it.
2993 Otherwise, output such a constant in memory (or defer it for later)
2994 and generate an rtx for it.
2996 If DEFER is non-zero, the output of string constants can be deferred
2997 and output only if referenced in the function after all optimizations.
2999 The TREE_CST_RTL of EXP is set up to point to that rtx.
3000 The const_hash_table records which constants already have label strings. */
3003 output_constant_def (exp
, defer
)
3008 struct constant_descriptor
*desc
;
3009 struct deferred_string
**defstr
;
3013 int after_function
= 0;
3017 /* We can't just use the saved RTL if this is a defererred string constant
3018 and we are not to defer anymode. */
3019 if (TREE_CODE (exp
) != INTEGER_CST
&& TREE_CST_RTL (exp
)
3020 && (defer
|| !STRING_POOL_ADDRESS_P (XEXP (TREE_CST_RTL (exp
), 0))))
3021 return TREE_CST_RTL (exp
);
3023 /* Make sure any other constants whose addresses appear in EXP
3024 are assigned label numbers. */
3026 reloc
= output_addressed_constants (exp
);
3028 /* Compute hash code of EXP. Search the descriptors for that hash code
3029 to see if any of them describes EXP. If yes, the descriptor records
3030 the label number already assigned. */
3032 hash
= const_hash (exp
) % MAX_HASH_TABLE
;
3034 for (desc
= const_hash_table
[hash
]; desc
; desc
= desc
->next
)
3035 if (compare_constant (exp
, desc
))
3040 /* No constant equal to EXP is known to have been output.
3041 Make a constant descriptor to enter EXP in the hash table.
3042 Assign the label number and record it in the descriptor for
3043 future calls to this function to find. */
3045 /* Create a string containing the label name, in LABEL. */
3046 labelno
= const_labelno
++;
3047 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3049 desc
= record_constant (exp
);
3050 desc
->next
= const_hash_table
[hash
];
3051 desc
->label
= ggc_strdup (label
);
3052 const_hash_table
[hash
] = desc
;
3054 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3056 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)),
3057 gen_rtx_SYMBOL_REF (Pmode
, desc
->label
));
3059 set_mem_attributes (rtl
, exp
, 1);
3060 set_mem_alias_set (rtl
, 0);
3061 set_mem_alias_set (rtl
, const_alias_set
);
3068 if (TREE_CODE (exp
) != INTEGER_CST
)
3069 TREE_CST_RTL (exp
) = rtl
;
3071 /* Optionally set flags or add text to the name to record information
3072 such as that it is a function name. If the name is changed, the macro
3073 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3074 #ifdef ENCODE_SECTION_INFO
3075 /* A previously-processed constant would already have section info
3079 /* Take care not to invoke ENCODE_SECTION_INFO for constants
3080 which don't have a TREE_CST_RTL. */
3081 if (TREE_CODE (exp
) != INTEGER_CST
)
3082 ENCODE_SECTION_INFO (exp
, true);
3085 desc
->label
= XSTR (XEXP (desc
->rtl
, 0), 0);
3089 #ifdef CONSTANT_AFTER_FUNCTION_P
3090 if (current_function_decl
!= 0
3091 && CONSTANT_AFTER_FUNCTION_P (exp
))
3096 && STRING_POOL_ADDRESS_P (XEXP (rtl
, 0))
3097 && (!defer
|| defer_addressed_constants_flag
|| after_function
))
3099 defstr
= (struct deferred_string
**)
3100 htab_find_slot_with_hash (const_str_htab
, desc
->label
,
3101 STRHASH (desc
->label
), NO_INSERT
);
3104 /* If the string is currently deferred but we need to output it now,
3105 remove it from deferred string hash table. */
3107 labelno
= (*defstr
)->labelno
;
3108 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 0;
3109 htab_clear_slot (const_str_htab
, (void **) defstr
);
3113 /* If this is the first time we've seen this particular constant,
3114 output it (or defer its output for later). */
3117 if (defer_addressed_constants_flag
|| after_function
)
3119 struct deferred_constant
*p
3120 = (struct deferred_constant
*)
3121 xmalloc (sizeof (struct deferred_constant
));
3123 p
->exp
= copy_constant (exp
);
3125 p
->labelno
= labelno
;
3128 p
->next
= after_function_constants
;
3129 after_function_constants
= p
;
3133 p
->next
= deferred_constants
;
3134 deferred_constants
= p
;
3139 /* Do no output if -fsyntax-only. */
3140 if (! flag_syntax_only
)
3142 if (TREE_CODE (exp
) != STRING_CST
3144 || flag_writable_strings
3145 || (defstr
= (struct deferred_string
**)
3146 htab_find_slot_with_hash (const_str_htab
,
3148 STRHASH (desc
->label
),
3150 output_constant_def_contents (exp
, reloc
, labelno
);
3153 struct deferred_string
*p
;
3155 p
= (struct deferred_string
*)
3156 xmalloc (sizeof (struct deferred_string
));
3158 p
->exp
= copy_constant (exp
);
3159 p
->label
= desc
->label
;
3160 p
->labelno
= labelno
;
3162 STRING_POOL_ADDRESS_P (XEXP (rtl
, 0)) = 1;
3171 /* Now output assembler code to define the label for EXP,
3172 and follow it with the data of EXP. */
3175 output_constant_def_contents (exp
, reloc
, labelno
)
3182 /* Align the location counter as required by EXP's data type. */
3183 align
= TYPE_ALIGN (TREE_TYPE (exp
));
3184 #ifdef CONSTANT_ALIGNMENT
3185 align
= CONSTANT_ALIGNMENT (exp
, align
);
3188 if (IN_NAMED_SECTION (exp
))
3189 named_section (exp
, NULL
, reloc
);
3191 (*targetm
.asm_out
.select_section
) (exp
, reloc
, align
);
3193 if (align
> BITS_PER_UNIT
)
3195 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3198 /* Output the label itself. */
3199 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", labelno
);
3201 /* Output the value of EXP. */
3202 output_constant (exp
,
3203 (TREE_CODE (exp
) == STRING_CST
3204 ? MAX (TREE_STRING_LENGTH (exp
),
3205 int_size_in_bytes (TREE_TYPE (exp
)))
3206 : int_size_in_bytes (TREE_TYPE (exp
))),
3211 /* Structure to represent sufficient information about a constant so that
3212 it can be output when the constant pool is output, so that function
3213 integration can be done, and to simplify handling on machines that reference
3214 constant pool as base+displacement. */
3216 struct pool_constant
3218 struct constant_descriptor
*desc
;
3219 struct pool_constant
*next
, *next_sym
;
3221 enum machine_mode mode
;
3224 HOST_WIDE_INT offset
;
3228 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3229 The argument is XSTR (... , 0) */
3231 #define SYMHASH(LABEL) \
3232 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3234 /* Initialize constant pool hashing for a new function. */
3237 init_varasm_status (f
)
3240 struct varasm_status
*p
;
3241 p
= (struct varasm_status
*) xmalloc (sizeof (struct varasm_status
));
3243 p
->x_const_rtx_hash_table
3244 = ((struct constant_descriptor
**)
3245 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct constant_descriptor
*)));
3246 p
->x_const_rtx_sym_hash_table
3247 = ((struct pool_constant
**)
3248 xcalloc (MAX_RTX_HASH_TABLE
, sizeof (struct pool_constant
*)));
3250 p
->x_first_pool
= p
->x_last_pool
= 0;
3251 p
->x_pool_offset
= 0;
3254 /* Mark PC for GC. */
3257 mark_pool_constant (pc
)
3258 struct pool_constant
*pc
;
3263 ggc_mark_rtx (pc
->constant
);
3264 ggc_mark_rtx (pc
->desc
->rtl
);
3269 /* Mark P for GC. */
3272 mark_varasm_status (p
)
3273 struct varasm_status
*p
;
3278 mark_pool_constant (p
->x_first_pool
);
3281 /* Clear out all parts of the state in F that can safely be discarded
3282 after the function has been compiled, to let garbage collection
3283 reclaim the memory. */
3286 free_varasm_status (f
)
3289 struct varasm_status
*p
;
3294 /* Clear out the hash tables. */
3295 for (i
= 0; i
< MAX_RTX_HASH_TABLE
; ++i
)
3297 struct constant_descriptor
*cd
;
3299 cd
= p
->x_const_rtx_hash_table
[i
];
3302 struct constant_descriptor
*next
= cd
->next
;
3309 free (p
->x_const_rtx_hash_table
);
3310 free (p
->x_const_rtx_sym_hash_table
);
3317 /* Express an rtx for a constant integer (perhaps symbolic)
3318 as the sum of a symbol or label plus an explicit integer.
3319 They are stored into VALUE. */
3322 decode_rtx_const (mode
, x
, value
)
3323 enum machine_mode mode
;
3325 struct rtx_const
*value
;
3327 /* Clear the whole structure, including any gaps. */
3328 memset (value
, 0, sizeof (struct rtx_const
));
3330 value
->kind
= RTX_INT
; /* Most usual kind. */
3333 switch (GET_CODE (x
))
3336 value
->kind
= RTX_DOUBLE
;
3337 if (GET_MODE (x
) != VOIDmode
)
3339 value
->mode
= GET_MODE (x
);
3340 REAL_VALUE_FROM_CONST_DOUBLE (value
->un
.du
, x
);
3344 value
->un
.di
.low
= CONST_DOUBLE_LOW (x
);
3345 value
->un
.di
.high
= CONST_DOUBLE_HIGH (x
);
3354 units
= CONST_VECTOR_NUNITS (x
);
3355 value
->kind
= RTX_VECTOR
;
3358 for (i
= 0; i
< units
; ++i
)
3360 elt
= CONST_VECTOR_ELT (x
, i
);
3361 if (GET_MODE_CLASS (mode
) == MODE_VECTOR_INT
)
3363 value
->un
.veclo
[i
] = (HOST_WIDE_INT
) INTVAL (elt
);
3364 value
->un
.vechi
[i
] = 0;
3366 else if (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)
3368 value
->un
.veclo
[i
] = (HOST_WIDE_INT
) CONST_DOUBLE_LOW (elt
);
3369 value
->un
.vechi
[i
] = (HOST_WIDE_INT
) CONST_DOUBLE_HIGH (elt
);
3378 value
->un
.addr
.offset
= INTVAL (x
);
3384 value
->un
.addr
.base
= x
;
3389 if (GET_CODE (x
) == PLUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3391 value
->un
.addr
.base
= XEXP (x
, 0);
3392 value
->un
.addr
.offset
= INTVAL (XEXP (x
, 1));
3394 else if (GET_CODE (x
) == MINUS
&& GET_CODE (XEXP (x
, 1)) == CONST_INT
)
3396 value
->un
.addr
.base
= XEXP (x
, 0);
3397 value
->un
.addr
.offset
= - INTVAL (XEXP (x
, 1));
3401 value
->un
.addr
.base
= x
;
3402 value
->un
.addr
.offset
= 0;
3407 value
->kind
= RTX_UNKNOWN
;
3411 if (value
->kind
== RTX_INT
&& value
->un
.addr
.base
!= 0
3412 && GET_CODE (value
->un
.addr
.base
) == UNSPEC
)
3414 /* For a simple UNSPEC, the base is set to the
3415 operand, the kind field is set to the index of
3416 the unspec expression.
3417 Together with the code below, in case that
3418 the operand is a SYMBOL_REF or LABEL_REF,
3419 the address of the string or the code_label
3420 is taken as base. */
3421 if (XVECLEN (value
->un
.addr
.base
, 0) == 1)
3423 value
->kind
= RTX_UNSPEC
+ XINT (value
->un
.addr
.base
, 1);
3424 value
->un
.addr
.base
= XVECEXP (value
->un
.addr
.base
, 0, 0);
3428 if (value
->kind
> RTX_DOUBLE
&& value
->un
.addr
.base
!= 0)
3429 switch (GET_CODE (value
->un
.addr
.base
))
3432 /* Use the string's address, not the SYMBOL_REF's address,
3433 for the sake of addresses of library routines. */
3434 value
->un
.addr
.base
= (rtx
) XSTR (value
->un
.addr
.base
, 0);
3438 /* For a LABEL_REF, compare labels. */
3439 value
->un
.addr
.base
= XEXP (value
->un
.addr
.base
, 0);
3446 /* Given a MINUS expression, simplify it if both sides
3447 include the same symbol. */
3450 simplify_subtraction (x
)
3453 struct rtx_const val0
, val1
;
3455 decode_rtx_const (GET_MODE (x
), XEXP (x
, 0), &val0
);
3456 decode_rtx_const (GET_MODE (x
), XEXP (x
, 1), &val1
);
3458 if (val0
.kind
> RTX_DOUBLE
3459 && val0
.kind
== val1
.kind
3460 && val0
.un
.addr
.base
== val1
.un
.addr
.base
)
3461 return GEN_INT (val0
.un
.addr
.offset
- val1
.un
.addr
.offset
);
3466 /* Compute a hash code for a constant RTL expression. */
3469 const_hash_rtx (mode
, x
)
3470 enum machine_mode mode
;
3476 struct rtx_const value
;
3477 decode_rtx_const (mode
, x
, &value
);
3479 /* Compute hashing function */
3481 for (i
= 0; i
< sizeof value
/ sizeof (int); i
++)
3482 hi
+= ((int *) &value
)[i
];
3484 hi
&= (1 << HASHBITS
) - 1;
3485 hi
%= MAX_RTX_HASH_TABLE
;
3489 /* Compare a constant rtl object X with a constant-descriptor DESC.
3490 Return 1 if DESC describes a constant with the same value as X. */
3493 compare_constant_rtx (mode
, x
, desc
)
3494 enum machine_mode mode
;
3496 struct constant_descriptor
*desc
;
3498 int *p
= (int *) desc
->u
.contents
;
3501 struct rtx_const value
;
3503 decode_rtx_const (mode
, x
, &value
);
3504 strp
= (int *) &value
;
3505 len
= sizeof value
/ sizeof (int);
3507 /* Compare constant contents. */
3509 if (*p
++ != *strp
++)
3515 /* Construct a constant descriptor for the rtl-expression X.
3516 It is up to the caller to enter the descriptor in the hash table. */
3518 static struct constant_descriptor
*
3519 record_constant_rtx (mode
, x
)
3520 enum machine_mode mode
;
3523 struct constant_descriptor
*ptr
;
3525 ptr
= ((struct constant_descriptor
*)
3526 xcalloc (1, (offsetof (struct constant_descriptor
, u
)
3527 + sizeof (struct rtx_const
))));
3528 decode_rtx_const (mode
, x
, (struct rtx_const
*) ptr
->u
.contents
);
3533 /* Given a constant rtx X, return a MEM for the location in memory at which
3534 this constant has been placed. Return 0 if it not has been placed yet. */
3537 mem_for_const_double (x
)
3540 enum machine_mode mode
= GET_MODE (x
);
3541 struct constant_descriptor
*desc
;
3543 for (desc
= const_rtx_hash_table
[const_hash_rtx (mode
, x
)]; desc
;
3545 if (compare_constant_rtx (mode
, x
, desc
))
3551 /* Given a constant rtx X, make (or find) a memory constant for its value
3552 and return a MEM rtx to refer to it in memory. */
3555 force_const_mem (mode
, x
)
3556 enum machine_mode mode
;
3560 struct constant_descriptor
*desc
;
3563 struct pool_constant
*pool
;
3566 /* Compute hash code of X. Search the descriptors for that hash code
3567 to see if any of them describes X. If yes, we have an rtx to use. */
3568 hash
= const_hash_rtx (mode
, x
);
3569 for (desc
= const_rtx_hash_table
[hash
]; desc
; desc
= desc
->next
)
3570 if (compare_constant_rtx (mode
, x
, desc
))
3573 /* No constant equal to X is known to have been output.
3574 Make a constant descriptor to enter X in the hash table
3575 and make a MEM for it. */
3576 desc
= record_constant_rtx (mode
, x
);
3577 desc
->next
= const_rtx_hash_table
[hash
];
3578 const_rtx_hash_table
[hash
] = desc
;
3580 /* Align the location counter as required by EXP's data type. */
3581 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3582 #ifdef CONSTANT_ALIGNMENT
3583 align
= CONSTANT_ALIGNMENT (make_tree ((*lang_hooks
.types
.type_for_mode
)
3584 (mode
, 0), x
), align
);
3587 pool_offset
+= (align
/ BITS_PER_UNIT
) - 1;
3588 pool_offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3590 if (GET_CODE (x
) == LABEL_REF
)
3591 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3593 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3594 pool
= (struct pool_constant
*) ggc_alloc (sizeof (struct pool_constant
));
3598 pool
->labelno
= const_labelno
;
3599 pool
->align
= align
;
3600 pool
->offset
= pool_offset
;
3607 last_pool
->next
= pool
;
3610 pool_offset
+= GET_MODE_SIZE (mode
);
3612 /* Create a string containing the label name, in LABEL. */
3613 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3617 /* Construct the SYMBOL_REF and the MEM. */
3619 pool
->desc
->rtl
= def
3620 = gen_rtx_MEM (mode
, gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
)));
3621 set_mem_alias_set (def
, const_alias_set
);
3622 set_mem_attributes (def
, (*lang_hooks
.types
.type_for_mode
) (mode
, 0), 1);
3623 RTX_UNCHANGING_P (def
) = 1;
3625 /* Add label to symbol hash table. */
3626 hash
= SYMHASH (XSTR (XEXP (def
, 0), 0));
3627 pool
->next_sym
= const_rtx_sym_hash_table
[hash
];
3628 const_rtx_sym_hash_table
[hash
] = pool
;
3630 /* Mark the symbol_ref as belonging to this constants pool. */
3631 CONSTANT_POOL_ADDRESS_P (XEXP (def
, 0)) = 1;
3632 current_function_uses_const_pool
= 1;
3637 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3638 the corresponding pool_constant structure. */
3640 static struct pool_constant
*
3641 find_pool_constant (f
, addr
)
3645 struct pool_constant
*pool
;
3646 const char *label
= XSTR (addr
, 0);
3648 for (pool
= f
->varasm
->x_const_rtx_sym_hash_table
[SYMHASH (label
)]; pool
;
3649 pool
= pool
->next_sym
)
3650 if (XSTR (XEXP (pool
->desc
->rtl
, 0), 0) == label
)
3656 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3659 get_pool_constant (addr
)
3662 return (find_pool_constant (cfun
, addr
))->constant
;
3665 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3666 and whether it has been output or not. */
3669 get_pool_constant_mark (addr
, pmarked
)
3673 struct pool_constant
*pool
= find_pool_constant (cfun
, addr
);
3674 *pmarked
= (pool
->mark
!= 0);
3675 return pool
->constant
;
3678 /* Likewise, but for the constant pool of a specific function. */
3681 get_pool_constant_for_function (f
, addr
)
3685 return (find_pool_constant (f
, addr
))->constant
;
3688 /* Similar, return the mode. */
3691 get_pool_mode (addr
)
3694 return (find_pool_constant (cfun
, addr
))->mode
;
3698 get_pool_mode_for_function (f
, addr
)
3702 return (find_pool_constant (f
, addr
))->mode
;
3705 /* Similar, return the offset in the constant pool. */
3708 get_pool_offset (addr
)
3711 return (find_pool_constant (cfun
, addr
))->offset
;
3714 /* Return the size of the constant pool. */
3722 /* Write all the constants in the constant pool. */
3725 output_constant_pool (fnname
, fndecl
)
3726 const char *fnname ATTRIBUTE_UNUSED
;
3727 tree fndecl ATTRIBUTE_UNUSED
;
3729 struct pool_constant
*pool
;
3733 /* It is possible for gcc to call force_const_mem and then to later
3734 discard the instructions which refer to the constant. In such a
3735 case we do not need to output the constant. */
3736 mark_constant_pool ();
3738 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3739 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3742 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3751 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3752 whose CODE_LABEL has been deleted. This can occur if a jump table
3753 is eliminated by optimization. If so, write a constant of zero
3754 instead. Note that this can also happen by turning the
3755 CODE_LABEL into a NOTE. */
3756 /* ??? This seems completely and utterly wrong. Certainly it's
3757 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3758 functioning even with INSN_DELETED_P and friends. */
3761 switch (GET_CODE (x
))
3764 if (GET_CODE (XEXP (x
, 0)) != PLUS
3765 || GET_CODE (XEXP (XEXP (x
, 0), 0)) != LABEL_REF
)
3767 tmp
= XEXP (XEXP (x
, 0), 0);
3772 if (INSN_DELETED_P (tmp
)
3773 || (GET_CODE (tmp
) == NOTE
3774 && NOTE_LINE_NUMBER (tmp
) == NOTE_INSN_DELETED
))
3785 /* First switch to correct section. */
3786 #ifdef SELECT_RTX_SECTION
3787 SELECT_RTX_SECTION (pool
->mode
, x
, pool
->align
);
3789 readonly_data_section ();
3792 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3793 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, pool
->mode
,
3794 pool
->align
, pool
->labelno
, done
);
3797 assemble_align (pool
->align
);
3799 /* Output the label. */
3800 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file
, "LC", pool
->labelno
);
3802 /* Output the value of the constant itself. */
3803 switch (GET_MODE_CLASS (pool
->mode
))
3806 if (GET_CODE (x
) != CONST_DOUBLE
)
3809 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3810 assemble_real (r
, pool
->mode
, pool
->align
);
3814 case MODE_PARTIAL_INT
:
3815 assemble_integer (x
, GET_MODE_SIZE (pool
->mode
), pool
->align
, 1);
3818 case MODE_VECTOR_FLOAT
:
3823 if (GET_CODE (x
) != CONST_VECTOR
)
3826 units
= CONST_VECTOR_NUNITS (x
);
3828 for (i
= 0; i
< units
; i
++)
3830 elt
= CONST_VECTOR_ELT (x
, i
);
3831 REAL_VALUE_FROM_CONST_DOUBLE (r
, elt
);
3832 assemble_real (r
, GET_MODE_INNER (pool
->mode
), pool
->align
);
3837 case MODE_VECTOR_INT
:
3842 if (GET_CODE (x
) != CONST_VECTOR
)
3845 units
= CONST_VECTOR_NUNITS (x
);
3847 for (i
= 0; i
< units
; i
++)
3849 elt
= CONST_VECTOR_ELT (x
, i
);
3850 assemble_integer (elt
, GET_MODE_UNIT_SIZE (pool
->mode
),
3860 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3865 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3866 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool_offset
);
3869 /* Done with this pool. */
3870 first_pool
= last_pool
= 0;
3873 /* Look through the instructions for this function, and mark all the
3874 entries in the constant pool which are actually being used.
3875 Emit used deferred strings. */
3878 mark_constant_pool ()
3881 struct pool_constant
*pool
;
3883 if (first_pool
== 0 && htab_elements (const_str_htab
) == 0)
3886 for (pool
= first_pool
; pool
; pool
= pool
->next
)
3889 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
3891 mark_constants (PATTERN (insn
));
3893 for (insn
= current_function_epilogue_delay_list
;
3895 insn
= XEXP (insn
, 1))
3897 mark_constants (PATTERN (insn
));
3900 /* Look through appropriate parts of X, marking all entries in the
3901 constant pool which are actually being used. Entries that are only
3902 referenced by other constants are also marked as used. Emit
3903 deferred strings that are used. */
3910 const char *format_ptr
;
3915 if (GET_CODE (x
) == SYMBOL_REF
)
3917 mark_constant (&x
, NULL
);
3921 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3922 insns, not any notes that may be attached. We don't want to mark
3923 a constant just because it happens to appear in a REG_EQUIV note. */
3926 mark_constants (PATTERN (x
));
3930 format_ptr
= GET_RTX_FORMAT (GET_CODE (x
));
3932 for (i
= 0; i
< GET_RTX_LENGTH (GET_CODE (x
)); i
++)
3934 switch (*format_ptr
++)
3937 mark_constants (XEXP (x
, i
));
3941 if (XVEC (x
, i
) != 0)
3945 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3946 mark_constants (XVECEXP (x
, i
, j
));
3965 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
3966 to as used. Emit referenced deferred strings. This function can
3967 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
3970 mark_constant (current_rtx
, data
)
3972 void *data ATTRIBUTE_UNUSED
;
3974 rtx x
= *current_rtx
;
3979 else if (GET_CODE (x
) == SYMBOL_REF
)
3981 if (CONSTANT_POOL_ADDRESS_P (x
))
3983 struct pool_constant
*pool
= find_pool_constant (cfun
, x
);
3984 if (pool
->mark
== 0)
3987 for_each_rtx (&(pool
->constant
), &mark_constant
, NULL
);
3992 else if (STRING_POOL_ADDRESS_P (x
))
3994 struct deferred_string
**defstr
;
3996 defstr
= (struct deferred_string
**)
3997 htab_find_slot_with_hash (const_str_htab
, XSTR (x
, 0),
3998 STRHASH (XSTR (x
, 0)), NO_INSERT
);
4001 struct deferred_string
*p
= *defstr
;
4003 STRING_POOL_ADDRESS_P (x
) = 0;
4004 output_constant_def_contents (p
->exp
, 0, p
->labelno
);
4005 htab_clear_slot (const_str_htab
, (void **) defstr
);
4012 /* Find all the constants whose addresses are referenced inside of EXP,
4013 and make sure assembler code with a label has been output for each one.
4014 Indicate whether an ADDR_EXPR has been encountered. */
4017 output_addressed_constants (exp
)
4023 /* Give the front-end a chance to convert VALUE to something that
4024 looks more like a constant to the back-end. */
4025 exp
= (*lang_hooks
.expand_constant
) (exp
);
4027 switch (TREE_CODE (exp
))
4030 /* Go inside any operations that get_inner_reference can handle and see
4031 if what's inside is a constant: no need to do anything here for
4032 addresses of variables or functions. */
4033 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4034 tem
= TREE_OPERAND (tem
, 0))
4037 if (TREE_CODE_CLASS (TREE_CODE (tem
)) == 'c'
4038 || TREE_CODE (tem
) == CONSTRUCTOR
)
4039 output_constant_def (tem
, 0);
4041 if (TREE_PUBLIC (tem
))
4049 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
4050 reloc
|= output_addressed_constants (TREE_OPERAND (exp
, 1));
4055 case NON_LVALUE_EXPR
:
4056 reloc
= output_addressed_constants (TREE_OPERAND (exp
, 0));
4060 for (tem
= CONSTRUCTOR_ELTS (exp
); tem
; tem
= TREE_CHAIN (tem
))
4061 if (TREE_VALUE (tem
) != 0)
4062 reloc
|= output_addressed_constants (TREE_VALUE (tem
));
4072 /* Return nonzero if VALUE is a valid constant-valued expression
4073 for use in initializing a static variable; one that can be an
4074 element of a "constant" initializer.
4076 Return null_pointer_node if the value is absolute;
4077 if it is relocatable, return the variable that determines the relocation.
4078 We assume that VALUE has been folded as much as possible;
4079 therefore, we do not need to check for such things as
4080 arithmetic-combinations of integers. */
4083 initializer_constant_valid_p (value
, endtype
)
4087 /* Give the front-end a chance to convert VALUE to something that
4088 looks more like a constant to the back-end. */
4089 value
= (*lang_hooks
.expand_constant
) (value
);
4091 switch (TREE_CODE (value
))
4094 if ((TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
4095 || TREE_CODE (TREE_TYPE (value
)) == RECORD_TYPE
)
4096 && TREE_CONSTANT (value
)
4097 && CONSTRUCTOR_ELTS (value
))
4099 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value
)),
4102 return TREE_STATIC (value
) ? null_pointer_node
: 0;
4109 return null_pointer_node
;
4113 return staticp (TREE_OPERAND (value
, 0)) ? TREE_OPERAND (value
, 0) : 0;
4115 case VIEW_CONVERT_EXPR
:
4116 case NON_LVALUE_EXPR
:
4117 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4121 /* Allow conversions between pointer types. */
4122 if (POINTER_TYPE_P (TREE_TYPE (value
))
4123 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4124 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4126 /* Allow conversions between real types. */
4127 if (FLOAT_TYPE_P (TREE_TYPE (value
))
4128 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4129 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4131 /* Allow length-preserving conversions between integer types. */
4132 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4133 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4134 && (TYPE_PRECISION (TREE_TYPE (value
))
4135 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4136 return initializer_constant_valid_p (TREE_OPERAND (value
, 0), endtype
);
4138 /* Allow conversions between other integer types only if
4140 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4141 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4143 tree inner
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4145 if (inner
== null_pointer_node
)
4146 return null_pointer_node
;
4150 /* Allow (int) &foo provided int is as wide as a pointer. */
4151 if (INTEGRAL_TYPE_P (TREE_TYPE (value
))
4152 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0)))
4153 && (TYPE_PRECISION (TREE_TYPE (value
))
4154 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0)))))
4155 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4158 /* Likewise conversions from int to pointers, but also allow
4159 conversions from 0. */
4160 if (POINTER_TYPE_P (TREE_TYPE (value
))
4161 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value
, 0))))
4163 if (integer_zerop (TREE_OPERAND (value
, 0)))
4164 return null_pointer_node
;
4165 else if (TYPE_PRECISION (TREE_TYPE (value
))
4166 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value
, 0))))
4167 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4171 /* Allow conversions to union types if the value inside is okay. */
4172 if (TREE_CODE (TREE_TYPE (value
)) == UNION_TYPE
)
4173 return initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4178 if (! INTEGRAL_TYPE_P (endtype
)
4179 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4181 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4183 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4185 /* If either term is absolute, use the other terms relocation. */
4186 if (valid0
== null_pointer_node
)
4188 if (valid1
== null_pointer_node
)
4194 if (! INTEGRAL_TYPE_P (endtype
)
4195 || TYPE_PRECISION (endtype
) >= POINTER_SIZE
)
4197 tree valid0
= initializer_constant_valid_p (TREE_OPERAND (value
, 0),
4199 tree valid1
= initializer_constant_valid_p (TREE_OPERAND (value
, 1),
4201 /* Win if second argument is absolute. */
4202 if (valid1
== null_pointer_node
)
4204 /* Win if both arguments have the same relocation.
4205 Then the value is absolute. */
4206 if (valid0
== valid1
&& valid0
!= 0)
4207 return null_pointer_node
;
4209 /* Since GCC guarantees that string constants are unique in the
4210 generated code, a subtraction between two copies of the same
4211 constant string is absolute. */
4212 if (valid0
&& TREE_CODE (valid0
) == STRING_CST
&&
4213 valid1
&& TREE_CODE (valid1
) == STRING_CST
&&
4214 TREE_STRING_POINTER (valid0
) == TREE_STRING_POINTER (valid1
))
4215 return null_pointer_node
;
4218 /* Support differences between labels. */
4219 if (INTEGRAL_TYPE_P (endtype
))
4222 op0
= TREE_OPERAND (value
, 0);
4223 op1
= TREE_OPERAND (value
, 1);
4225 /* Like STRIP_NOPS except allow the operand mode to widen.
4226 This works around a feature of fold that simplfies
4227 (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory
4228 that the narrower operation is cheaper. */
4230 while (TREE_CODE (op0
) == NOP_EXPR
4231 || TREE_CODE (op0
) == CONVERT_EXPR
4232 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4234 tree inner
= TREE_OPERAND (op0
, 0);
4235 if (inner
== error_mark_node
4236 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4237 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4238 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4243 while (TREE_CODE (op1
) == NOP_EXPR
4244 || TREE_CODE (op1
) == CONVERT_EXPR
4245 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4247 tree inner
= TREE_OPERAND (op1
, 0);
4248 if (inner
== error_mark_node
4249 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4250 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4251 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4256 if (TREE_CODE (op0
) == ADDR_EXPR
4257 && TREE_CODE (TREE_OPERAND (op0
, 0)) == LABEL_DECL
4258 && TREE_CODE (op1
) == ADDR_EXPR
4259 && TREE_CODE (TREE_OPERAND (op1
, 0)) == LABEL_DECL
)
4260 return null_pointer_node
;
4271 /* Output assembler code for constant EXP to FILE, with no label.
4272 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4273 Assumes output_addressed_constants has been done on EXP already.
4275 Generate exactly SIZE bytes of assembler data, padding at the end
4276 with zeros if necessary. SIZE must always be specified.
4278 SIZE is important for structure constructors,
4279 since trailing members may have been omitted from the constructor.
4280 It is also important for initialization of arrays from string constants
4281 since the full length of the string constant might not be wanted.
4282 It is also needed for initialization of unions, where the initializer's
4283 type is just one member, and that may not be as long as the union.
4285 There a case in which we would fail to output exactly SIZE bytes:
4286 for a structure constructor that wants to produce more than SIZE bytes.
4287 But such constructors will never be generated for any possible input.
4289 ALIGN is the alignment of the data in bits. */
4292 output_constant (exp
, size
, align
)
4297 enum tree_code code
;
4298 HOST_WIDE_INT thissize
;
4300 /* Some front-ends use constants other than the standard language-indepdent
4301 varieties, but which may still be output directly. Give the front-end a
4302 chance to convert EXP to a language-independent representation. */
4303 exp
= (*lang_hooks
.expand_constant
) (exp
);
4305 if (size
== 0 || flag_syntax_only
)
4308 /* Eliminate any conversions since we'll be outputting the underlying
4310 while (TREE_CODE (exp
) == NOP_EXPR
|| TREE_CODE (exp
) == CONVERT_EXPR
4311 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4312 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4313 exp
= TREE_OPERAND (exp
, 0);
4315 code
= TREE_CODE (TREE_TYPE (exp
));
4316 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4318 /* Allow a constructor with no elements for any data type.
4319 This means to fill the space with zeros. */
4320 if (TREE_CODE (exp
) == CONSTRUCTOR
&& CONSTRUCTOR_ELTS (exp
) == 0)
4322 assemble_zeros (size
);
4326 if (TREE_CODE (exp
) == FDESC_EXPR
)
4328 #ifdef ASM_OUTPUT_FDESC
4329 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4330 tree decl
= TREE_OPERAND (exp
, 0);
4331 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4338 /* Now output the underlying data. If we've handling the padding, return.
4339 Otherwise, break and ensure THISSIZE is the size written. */
4347 case REFERENCE_TYPE
:
4348 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4349 EXPAND_INITIALIZER
),
4351 error ("initializer for integer value is too complicated");
4355 if (TREE_CODE (exp
) != REAL_CST
)
4356 error ("initializer for floating value is not a floating constant");
4358 assemble_real (TREE_REAL_CST (exp
),
4359 mode_for_size (size
* BITS_PER_UNIT
, MODE_FLOAT
, 0),
4364 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4365 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4366 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4371 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4373 output_constructor (exp
, size
, align
);
4376 else if (TREE_CODE (exp
) == STRING_CST
)
4378 thissize
= MIN (TREE_STRING_LENGTH (exp
), size
);
4379 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4387 if (TREE_CODE (exp
) == CONSTRUCTOR
)
4388 output_constructor (exp
, size
, align
);
4394 if (TREE_CODE (exp
) == INTEGER_CST
)
4395 assemble_integer (expand_expr (exp
, NULL_RTX
,
4396 VOIDmode
, EXPAND_INITIALIZER
),
4397 thissize
, align
, 1);
4398 else if (TREE_CODE (exp
) == CONSTRUCTOR
)
4400 unsigned char *buffer
= (unsigned char *) alloca (thissize
);
4401 if (get_set_constructor_bytes (exp
, buffer
, thissize
))
4403 assemble_string ((char *) buffer
, thissize
);
4406 error ("unknown set constructor type");
4418 assemble_zeros (size
);
4422 /* Subroutine of output_constructor, used for computing the size of
4423 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4424 type with an unspecified upper bound. */
4426 static unsigned HOST_WIDE_INT
4427 array_size_for_constructor (val
)
4432 /* This code used to attempt to handle string constants that are not
4433 arrays of single-bytes, but nothing else does, so there's no point in
4435 if (TREE_CODE (val
) == STRING_CST
)
4436 return TREE_STRING_LENGTH (val
);
4438 max_index
= NULL_TREE
;
4439 for (i
= CONSTRUCTOR_ELTS (val
); i
; i
= TREE_CHAIN (i
))
4441 tree index
= TREE_PURPOSE (i
);
4443 if (TREE_CODE (index
) == RANGE_EXPR
)
4444 index
= TREE_OPERAND (index
, 1);
4445 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4449 if (max_index
== NULL_TREE
)
4452 /* Compute the total number of array elements. */
4453 i
= size_binop (MINUS_EXPR
, convert (sizetype
, max_index
),
4455 TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)))));
4456 i
= size_binop (PLUS_EXPR
, i
, convert (sizetype
, integer_one_node
));
4458 /* Multiply by the array element unit size to find number of bytes. */
4459 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4461 return tree_low_cst (i
, 1);
4464 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
4465 Generate at least SIZE bytes, padding if necessary. */
4468 output_constructor (exp
, size
, align
)
4473 tree type
= TREE_TYPE (exp
);
4474 tree link
, field
= 0;
4476 /* Number of bytes output or skipped so far.
4477 In other words, current position within the constructor. */
4478 HOST_WIDE_INT total_bytes
= 0;
4479 /* Non-zero means BYTE contains part of a byte, to be output. */
4480 int byte_buffer_in_use
= 0;
4483 if (HOST_BITS_PER_WIDE_INT
< BITS_PER_UNIT
)
4486 if (TREE_CODE (type
) == RECORD_TYPE
)
4487 field
= TYPE_FIELDS (type
);
4489 if (TREE_CODE (type
) == ARRAY_TYPE
4490 && TYPE_DOMAIN (type
) != 0)
4491 min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (type
));
4493 /* As LINK goes through the elements of the constant,
4494 FIELD goes through the structure fields, if the constant is a structure.
4495 if the constant is a union, then we override this,
4496 by getting the field from the TREE_LIST element.
4497 But the constant could also be an array. Then FIELD is zero.
4499 There is always a maximum of one element in the chain LINK for unions
4500 (even if the initializer in a source program incorrectly contains
4502 for (link
= CONSTRUCTOR_ELTS (exp
);
4504 link
= TREE_CHAIN (link
),
4505 field
= field
? TREE_CHAIN (field
) : 0)
4507 tree val
= TREE_VALUE (link
);
4510 /* The element in a union constructor specifies the proper field
4512 if ((TREE_CODE (type
) == RECORD_TYPE
|| TREE_CODE (type
) == UNION_TYPE
4513 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
4514 && TREE_PURPOSE (link
) != 0)
4515 field
= TREE_PURPOSE (link
);
4517 else if (TREE_CODE (type
) == ARRAY_TYPE
)
4518 index
= TREE_PURPOSE (link
);
4520 /* Eliminate the marker that makes a cast not be an lvalue. */
4524 if (index
&& TREE_CODE (index
) == RANGE_EXPR
)
4526 unsigned HOST_WIDE_INT fieldsize
4527 = int_size_in_bytes (TREE_TYPE (type
));
4528 HOST_WIDE_INT lo_index
= tree_low_cst (TREE_OPERAND (index
, 0), 0);
4529 HOST_WIDE_INT hi_index
= tree_low_cst (TREE_OPERAND (index
, 1), 0);
4530 HOST_WIDE_INT index
;
4531 unsigned int align2
= min_align (align
, fieldsize
* BITS_PER_UNIT
);
4533 for (index
= lo_index
; index
<= hi_index
; index
++)
4535 /* Output the element's initial value. */
4537 assemble_zeros (fieldsize
);
4539 output_constant (val
, fieldsize
, align2
);
4541 /* Count its size. */
4542 total_bytes
+= fieldsize
;
4545 else if (field
== 0 || !DECL_BIT_FIELD (field
))
4547 /* An element that is not a bit-field. */
4549 unsigned HOST_WIDE_INT fieldsize
;
4550 /* Since this structure is static,
4551 we know the positions are constant. */
4552 HOST_WIDE_INT pos
= field
? int_byte_position (field
) : 0;
4553 unsigned int align2
;
4556 pos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val
)), 1)
4557 * (tree_low_cst (index
, 0) - tree_low_cst (min_index
, 0)));
4559 /* Output any buffered-up bit-fields preceding this element. */
4560 if (byte_buffer_in_use
)
4562 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4564 byte_buffer_in_use
= 0;
4567 /* Advance to offset of this element.
4568 Note no alignment needed in an array, since that is guaranteed
4569 if each element has the proper size. */
4570 if ((field
!= 0 || index
!= 0) && pos
!= total_bytes
)
4572 assemble_zeros (pos
- total_bytes
);
4576 /* Find the alignment of this element. */
4577 align2
= min_align (align
, BITS_PER_UNIT
* pos
);
4579 /* Determine size this element should occupy. */
4584 /* If this is an array with an unspecified upper bound,
4585 the initializer determines the size. */
4586 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
4587 but we cannot do this until the deprecated support for
4588 initializing zero-length array members is removed. */
4589 if (TREE_CODE (TREE_TYPE (field
)) == ARRAY_TYPE
4590 && TYPE_DOMAIN (TREE_TYPE (field
))
4591 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field
))))
4593 fieldsize
= array_size_for_constructor (val
);
4594 /* Given a non-empty initialization, this field had
4596 if (fieldsize
!= 0 && TREE_CHAIN (field
) != NULL_TREE
)
4599 else if (DECL_SIZE_UNIT (field
))
4601 /* ??? This can't be right. If the decl size overflows
4602 a host integer we will silently emit no data. */
4603 if (host_integerp (DECL_SIZE_UNIT (field
), 1))
4604 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (field
), 1);
4608 fieldsize
= int_size_in_bytes (TREE_TYPE (type
));
4610 /* Output the element's initial value. */
4612 assemble_zeros (fieldsize
);
4614 output_constant (val
, fieldsize
, align2
);
4616 /* Count its size. */
4617 total_bytes
+= fieldsize
;
4619 else if (val
!= 0 && TREE_CODE (val
) != INTEGER_CST
)
4620 error ("invalid initial value for member `%s'",
4621 IDENTIFIER_POINTER (DECL_NAME (field
)));
4624 /* Element that is a bit-field. */
4626 HOST_WIDE_INT next_offset
= int_bit_position (field
);
4627 HOST_WIDE_INT end_offset
4628 = (next_offset
+ tree_low_cst (DECL_SIZE (field
), 1));
4631 val
= integer_zero_node
;
4633 /* If this field does not start in this (or, next) byte,
4635 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4637 /* Output remnant of any bit field in previous bytes. */
4638 if (byte_buffer_in_use
)
4640 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4642 byte_buffer_in_use
= 0;
4645 /* If still not at proper byte, advance to there. */
4646 if (next_offset
/ BITS_PER_UNIT
!= total_bytes
)
4648 assemble_zeros (next_offset
/ BITS_PER_UNIT
- total_bytes
);
4649 total_bytes
= next_offset
/ BITS_PER_UNIT
;
4653 if (! byte_buffer_in_use
)
4656 /* We must split the element into pieces that fall within
4657 separate bytes, and combine each byte with previous or
4658 following bit-fields. */
4660 /* next_offset is the offset n fbits from the beginning of
4661 the structure to the next bit of this element to be processed.
4662 end_offset is the offset of the first bit past the end of
4664 while (next_offset
< end_offset
)
4668 HOST_WIDE_INT value
;
4669 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
4670 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
4672 /* Advance from byte to byte
4673 within this element when necessary. */
4674 while (next_byte
!= total_bytes
)
4676 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4681 /* Number of bits we can process at once
4682 (all part of the same byte). */
4683 this_time
= MIN (end_offset
- next_offset
,
4684 BITS_PER_UNIT
- next_bit
);
4685 if (BYTES_BIG_ENDIAN
)
4687 /* On big-endian machine, take the most significant bits
4688 first (of the bits that are significant)
4689 and put them into bytes from the most significant end. */
4690 shift
= end_offset
- next_offset
- this_time
;
4692 /* Don't try to take a bunch of bits that cross
4693 the word boundary in the INTEGER_CST. We can
4694 only select bits from the LOW or HIGH part
4696 if (shift
< HOST_BITS_PER_WIDE_INT
4697 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4699 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
4700 shift
= HOST_BITS_PER_WIDE_INT
;
4703 /* Now get the bits from the appropriate constant word. */
4704 if (shift
< HOST_BITS_PER_WIDE_INT
)
4705 value
= TREE_INT_CST_LOW (val
);
4706 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4708 value
= TREE_INT_CST_HIGH (val
);
4709 shift
-= HOST_BITS_PER_WIDE_INT
;
4714 /* Get the result. This works only when:
4715 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4716 byte
|= (((value
>> shift
)
4717 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4718 << (BITS_PER_UNIT
- this_time
- next_bit
));
4722 /* On little-endian machines,
4723 take first the least significant bits of the value
4724 and pack them starting at the least significant
4725 bits of the bytes. */
4726 shift
= next_offset
- int_bit_position (field
);
4728 /* Don't try to take a bunch of bits that cross
4729 the word boundary in the INTEGER_CST. We can
4730 only select bits from the LOW or HIGH part
4732 if (shift
< HOST_BITS_PER_WIDE_INT
4733 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
4734 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
4736 /* Now get the bits from the appropriate constant word. */
4737 if (shift
< HOST_BITS_PER_WIDE_INT
)
4738 value
= TREE_INT_CST_LOW (val
);
4739 else if (shift
< 2 * HOST_BITS_PER_WIDE_INT
)
4741 value
= TREE_INT_CST_HIGH (val
);
4742 shift
-= HOST_BITS_PER_WIDE_INT
;
4747 /* Get the result. This works only when:
4748 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4749 byte
|= (((value
>> shift
)
4750 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
4754 next_offset
+= this_time
;
4755 byte_buffer_in_use
= 1;
4760 if (byte_buffer_in_use
)
4762 assemble_integer (GEN_INT (byte
), 1, BITS_PER_UNIT
, 1);
4766 if (total_bytes
< size
)
4767 assemble_zeros (size
- total_bytes
);
4770 /* This TREE_LIST contains any weak symbol declarations waiting
4772 static tree weak_decls
;
4774 /* Mark DECL as weak. */
4780 DECL_WEAK (decl
) = 1;
4782 if (DECL_RTL_SET_P (decl
)
4783 && GET_CODE (DECL_RTL (decl
)) == MEM
4784 && XEXP (DECL_RTL (decl
), 0)
4785 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
4786 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
4789 /* Merge weak status between NEWDECL and OLDDECL. */
4792 merge_weak (newdecl
, olddecl
)
4796 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
4799 if (DECL_WEAK (newdecl
))
4803 /* NEWDECL is weak, but OLDDECL is not. */
4805 /* If we already output the OLDDECL, we're in trouble; we can't
4806 go back and make it weak. This error cannot caught in
4807 declare_weak because the NEWDECL and OLDDECL was not yet
4808 been merged; therefore, TREE_ASM_WRITTEN was not set. */
4809 if (TREE_ASM_WRITTEN (olddecl
))
4810 error_with_decl (newdecl
,
4811 "weak declaration of `%s' must precede definition");
4813 /* If we've already generated rtl referencing OLDDECL, we may
4814 have done so in a way that will not function properly with
4816 else if (TREE_USED (olddecl
)
4817 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
4818 warning_with_decl (newdecl
, "weak declaration of `%s' after first use results in unspecified behavior");
4822 /* We put the NEWDECL on the weak_decls list at some point.
4823 Replace it with the OLDDECL. */
4824 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
4825 if (TREE_VALUE (wd
) == newdecl
)
4827 TREE_VALUE (wd
) = olddecl
;
4830 /* We may not find the entry on the list. If NEWDECL is a
4831 weak alias, then we will have already called
4832 globalize_decl to remove the entry; in that case, we do
4833 not need to do anything. */
4836 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
4837 mark_weak (olddecl
);
4840 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
4841 weak. Just update NEWDECL to indicate that it's weak too. */
4842 mark_weak (newdecl
);
4845 /* Declare DECL to be a weak symbol. */
4851 if (! TREE_PUBLIC (decl
))
4852 error_with_decl (decl
, "weak declaration of `%s' must be public");
4853 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
4854 error_with_decl (decl
, "weak declaration of `%s' must precede definition");
4855 else if (SUPPORTS_WEAK
)
4857 if (! DECL_WEAK (decl
))
4858 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
4861 warning_with_decl (decl
, "weak declaration of `%s' not supported");
4866 /* Emit any pending weak declarations. */
4873 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
4875 tree decl
= TREE_VALUE (t
);
4876 const char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4878 if (! TREE_USED (decl
))
4881 #ifdef ASM_WEAKEN_DECL
4882 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
4884 #ifdef ASM_WEAKEN_LABEL
4885 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4887 #ifdef ASM_OUTPUT_WEAK_ALIAS
4888 warning ("only weak aliases are supported in this configuration");
4896 /* Emit the assembly bits to indicate that DECL is globally visible. */
4899 globalize_decl (decl
)
4902 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
4904 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
4905 if (DECL_WEAK (decl
))
4909 #ifdef ASM_WEAKEN_DECL
4910 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
4912 ASM_WEAKEN_LABEL (asm_out_file
, name
);
4915 /* Remove this function from the pending weak list so that
4916 we do not emit multiple .weak directives for it. */
4917 for (p
= &weak_decls
; (t
= *p
) ; )
4919 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
4920 *p
= TREE_CHAIN (t
);
4922 p
= &TREE_CHAIN (t
);
4928 ASM_GLOBALIZE_LABEL (asm_out_file
, name
);
4931 /* Emit an assembler directive to make the symbol for DECL an alias to
4932 the symbol for TARGET. */
4935 assemble_alias (decl
, target
)
4936 tree decl
, target ATTRIBUTE_UNUSED
;
4940 /* We must force creation of DECL_RTL for debug info generation, even though
4941 we don't use it here. */
4942 make_decl_rtl (decl
, NULL
);
4944 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4946 #ifdef ASM_OUTPUT_DEF
4947 /* Make name accessible from other files, if appropriate. */
4949 if (TREE_PUBLIC (decl
))
4951 globalize_decl (decl
);
4952 maybe_assemble_visibility (decl
);
4955 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4956 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
4958 ASM_OUTPUT_DEF (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4960 #else /* !ASM_OUTPUT_DEF */
4961 #if defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
4962 if (! DECL_WEAK (decl
))
4963 warning ("only weak aliases are supported in this configuration");
4965 #ifdef ASM_WEAKEN_DECL
4966 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
4968 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
4971 warning ("alias definitions not supported in this configuration; ignored");
4975 TREE_USED (decl
) = 1;
4976 TREE_ASM_WRITTEN (decl
) = 1;
4977 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
4980 /* Emit an assembler directive to set symbol for DECL visibility to
4984 assemble_visibility (decl
, visibility_type
)
4986 const char *visibility_type ATTRIBUTE_UNUSED
;
4990 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
4992 #ifdef HAVE_GAS_HIDDEN
4993 fprintf (asm_out_file
, "\t.%s\t%s\n", visibility_type
, name
);
4995 warning ("visibility attribute not supported in this configuration; ignored");
4999 /* A helper function to call assemble_visibility when needed for a decl. */
5002 maybe_assemble_visibility (decl
)
5005 tree visibility
= lookup_attribute ("visibility", DECL_ATTRIBUTES (decl
));
5009 = TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (visibility
)));
5010 assemble_visibility (decl
, type
);
5014 /* Returns 1 if the target configuration supports defining public symbols
5015 so that one of them will be chosen at link time instead of generating a
5016 multiply-defined symbol error, whether through the use of weak symbols or
5017 a target-specific mechanism for having duplicates discarded. */
5020 supports_one_only ()
5022 if (SUPPORTS_ONE_ONLY
)
5024 return SUPPORTS_WEAK
;
5027 /* Set up DECL as a public symbol that can be defined in multiple
5028 translation units without generating a linker error. */
5031 make_decl_one_only (decl
)
5034 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != FUNCTION_DECL
)
5037 TREE_PUBLIC (decl
) = 1;
5039 if (TREE_CODE (decl
) == VAR_DECL
5040 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
5041 DECL_COMMON (decl
) = 1;
5042 else if (SUPPORTS_ONE_ONLY
)
5044 #ifdef MAKE_DECL_ONE_ONLY
5045 MAKE_DECL_ONE_ONLY (decl
);
5047 DECL_ONE_ONLY (decl
) = 1;
5049 else if (SUPPORTS_WEAK
)
5050 DECL_WEAK (decl
) = 1;
5058 const_str_htab
= htab_create (128, const_str_htab_hash
, const_str_htab_eq
,
5059 const_str_htab_del
);
5060 in_named_htab
= htab_create (31, in_named_entry_hash
,
5061 in_named_entry_eq
, NULL
);
5063 ggc_add_root (const_hash_table
, MAX_HASH_TABLE
, sizeof const_hash_table
[0],
5064 mark_const_hash_entry
);
5065 ggc_add_root (&const_str_htab
, 1, sizeof const_str_htab
,
5066 mark_const_str_htab
);
5067 ggc_add_tree_root (&weak_decls
, 1);
5069 const_alias_set
= new_alias_set ();
5072 /* Select a set of attributes for section NAME based on the properties
5073 of DECL and whether or not RELOC indicates that DECL's initializer
5074 might contain runtime relocations.
5076 We make the section read-only and executable for a function decl,
5077 read-only for a const data decl, and writable for a non-const data decl. */
5080 default_section_type_flags (decl
, name
, reloc
)
5087 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
5088 flags
= SECTION_CODE
;
5089 else if (decl
&& DECL_READONLY_SECTION (decl
, reloc
))
5092 flags
= SECTION_WRITE
;
5094 if (decl
&& DECL_ONE_ONLY (decl
))
5095 flags
|= SECTION_LINKONCE
;
5097 if (strcmp (name
, ".bss") == 0
5098 || strncmp (name
, ".bss.", 5) == 0
5099 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
5100 || strcmp (name
, ".sbss") == 0
5101 || strncmp (name
, ".sbss.", 6) == 0
5102 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
5103 flags
|= SECTION_BSS
;
5108 /* Output assembly to switch to section NAME with attribute FLAGS.
5109 Four variants for common object file formats. */
5112 default_no_named_section (name
, flags
)
5113 const char *name ATTRIBUTE_UNUSED
;
5114 unsigned int flags ATTRIBUTE_UNUSED
;
5116 /* Some object formats don't support named sections at all. The
5117 front-end should already have flagged this as an error. */
5122 default_elf_asm_named_section (name
, flags
)
5126 char flagchars
[10], *f
= flagchars
;
5129 if (! named_section_first_declaration (name
))
5131 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
5135 if (!(flags
& SECTION_DEBUG
))
5137 if (flags
& SECTION_WRITE
)
5139 if (flags
& SECTION_CODE
)
5141 if (flags
& SECTION_SMALL
)
5143 if (flags
& SECTION_MERGE
)
5145 if (flags
& SECTION_STRINGS
)
5149 if (flags
& SECTION_BSS
)
5154 if (flags
& SECTION_ENTSIZE
)
5155 fprintf (asm_out_file
, "\t.section\t%s,\"%s\",@%s,%d\n",
5156 name
, flagchars
, type
, flags
& SECTION_ENTSIZE
);
5158 fprintf (asm_out_file
, "\t.section\t%s,\"%s\",@%s\n",
5159 name
, flagchars
, type
);
5163 default_coff_asm_named_section (name
, flags
)
5167 char flagchars
[8], *f
= flagchars
;
5169 if (flags
& SECTION_WRITE
)
5171 if (flags
& SECTION_CODE
)
5175 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
5179 default_pe_asm_named_section (name
, flags
)
5183 default_coff_asm_named_section (name
, flags
);
5185 if (flags
& SECTION_LINKONCE
)
5187 /* Functions may have been compiled at various levels of
5188 optimization so we can't use `same_size' here.
5189 Instead, have the linker pick one. */
5190 fprintf (asm_out_file
, "\t.linkonce %s\n",
5191 (flags
& SECTION_CODE
? "discard" : "same_size"));
5195 /* Used for vtable gc in GNU binutils. Record that the pointer at OFFSET
5196 from SYMBOL is used in all classes derived from SYMBOL. */
5199 assemble_vtable_entry (symbol
, offset
)
5201 HOST_WIDE_INT offset
;
5203 fputs ("\t.vtable_entry ", asm_out_file
);
5204 output_addr_const (asm_out_file
, symbol
);
5205 fputs (", ", asm_out_file
);
5206 fprintf (asm_out_file
, HOST_WIDE_INT_PRINT_DEC
, offset
);
5207 fputc ('\n', asm_out_file
);
5210 /* Used for vtable gc in GNU binutils. Record the class hierarchy by noting
5211 that the vtable symbol CHILD is derived from the vtable symbol PARENT. */
5214 assemble_vtable_inherit (child
, parent
)
5217 fputs ("\t.vtable_inherit ", asm_out_file
);
5218 output_addr_const (asm_out_file
, child
);
5219 fputs (", ", asm_out_file
);
5220 output_addr_const (asm_out_file
, parent
);
5221 fputc ('\n', asm_out_file
);
5224 /* The lame default section selector. */
5227 default_select_section (decl
, reloc
, align
)
5230 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
;
5232 bool readonly
= false;
5236 if (DECL_READONLY_SECTION (decl
, reloc
))
5239 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5241 if (! ((flag_pic
&& reloc
)
5242 || !TREE_READONLY (decl
)
5243 || TREE_SIDE_EFFECTS (decl
)
5244 || !TREE_CONSTANT (decl
)))
5247 else if (TREE_CODE (decl
) == STRING_CST
)
5248 readonly
= !flag_writable_strings
;
5249 else if (! (flag_pic
&& reloc
))
5253 readonly_data_section ();
5258 /* A helper function for default_elf_select_section and
5259 default_elf_unique_section. Categorizes the DECL. */
5261 enum section_category
5266 SECCAT_RODATA_MERGE_STR
,
5267 SECCAT_RODATA_MERGE_STR_INIT
,
5268 SECCAT_RODATA_MERGE_CONST
,
5272 /* To optimize loading of shared programs, define following subsections
5274 _REL Contains data that has relocations, so they get grouped
5275 together and dynamic linker will visit fewer pages in memory.
5276 _RO Contains data that is otherwise read-only. This is useful
5277 with prelinking as most relocations won't be dynamically
5278 linked and thus stay read only.
5279 _LOCAL Marks data containing relocations only to local objects.
5280 These relocations will get fully resolved by prelinking. */
5282 SECCAT_DATA_REL_LOCAL
,
5284 SECCAT_DATA_REL_RO_LOCAL
,
5294 static enum section_category categorize_decl_for_section
PARAMS ((tree
, int));
5296 static enum section_category
5297 categorize_decl_for_section (decl
, reloc
)
5301 enum section_category ret
;
5303 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5305 else if (TREE_CODE (decl
) == STRING_CST
)
5307 if (flag_writable_strings
)
5310 return SECCAT_RODATA_MERGE_STR
;
5312 else if (TREE_CODE (decl
) == VAR_DECL
)
5314 if (DECL_INITIAL (decl
) == NULL
5315 || DECL_INITIAL (decl
) == error_mark_node
)
5317 else if (! TREE_READONLY (decl
)
5318 || TREE_SIDE_EFFECTS (decl
)
5319 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
5321 if (flag_pic
&& (reloc
& 2))
5322 ret
= SECCAT_DATA_REL
;
5323 else if (flag_pic
&& reloc
)
5324 ret
= SECCAT_DATA_REL_LOCAL
;
5328 else if (flag_pic
&& (reloc
& 2))
5329 ret
= SECCAT_DATA_REL_RO
;
5330 else if (flag_pic
&& reloc
)
5331 ret
= SECCAT_DATA_REL_RO_LOCAL
;
5332 else if (flag_merge_constants
< 2)
5333 /* C and C++ don't allow different variables to share the same
5334 location. -fmerge-all-constants allows even that (at the
5335 expense of not conforming). */
5336 ret
= SECCAT_RODATA
;
5337 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
5338 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
5340 ret
= SECCAT_RODATA_MERGE_CONST
;
5342 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
5344 if ((flag_pic
&& reloc
)
5345 || TREE_SIDE_EFFECTS (decl
)
5346 || ! TREE_CONSTANT (decl
))
5349 ret
= SECCAT_RODATA
;
5352 ret
= SECCAT_RODATA
;
5354 /* If the target uses small data sections, select it. */
5355 if ((*targetm
.in_small_data_p
) (decl
))
5357 if (ret
== SECCAT_BSS
)
5366 /* Select a section based on the above categorization. */
5369 default_elf_select_section (decl
, reloc
, align
)
5372 unsigned HOST_WIDE_INT align
;
5374 switch (categorize_decl_for_section (decl
, reloc
))
5377 /* We're not supposed to be called on FUNCTION_DECLs. */
5380 readonly_data_section ();
5382 case SECCAT_RODATA_MERGE_STR
:
5383 mergeable_string_section (decl
, align
, 0);
5385 case SECCAT_RODATA_MERGE_STR_INIT
:
5386 mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
5388 case SECCAT_RODATA_MERGE_CONST
:
5389 mergeable_constant_section (DECL_MODE (decl
), align
, 0);
5394 case SECCAT_DATA_REL
:
5395 named_section (NULL_TREE
, ".data.rel", reloc
);
5397 case SECCAT_DATA_REL_LOCAL
:
5398 named_section (NULL_TREE
, ".data.rel.local", reloc
);
5400 case SECCAT_DATA_REL_RO
:
5401 named_section (NULL_TREE
, ".data.rel.ro", reloc
);
5403 case SECCAT_DATA_REL_RO_LOCAL
:
5404 named_section (NULL_TREE
, ".data.rel.ro.local", reloc
);
5407 named_section (NULL_TREE
, ".sdata", reloc
);
5410 named_section (NULL_TREE
, ".tdata", reloc
);
5413 #ifdef BSS_SECTION_ASM_OP
5416 named_section (NULL_TREE
, ".bss", reloc
);
5420 named_section (NULL_TREE
, ".sbss", reloc
);
5423 named_section (NULL_TREE
, ".tbss", reloc
);
5430 /* Construct a unique section name based on the decl name and the
5431 categorization performed above. */
5434 default_unique_section (decl
, reloc
)
5438 bool one_only
= DECL_ONE_ONLY (decl
);
5439 const char *prefix
, *name
;
5443 switch (categorize_decl_for_section (decl
, reloc
))
5446 prefix
= one_only
? ".gnu.linkonce.t." : ".text.";
5449 case SECCAT_RODATA_MERGE_STR
:
5450 case SECCAT_RODATA_MERGE_STR_INIT
:
5451 case SECCAT_RODATA_MERGE_CONST
:
5452 prefix
= one_only
? ".gnu.linkonce.r." : ".rodata.";
5455 case SECCAT_DATA_REL
:
5456 case SECCAT_DATA_REL_LOCAL
:
5457 case SECCAT_DATA_REL_RO
:
5458 case SECCAT_DATA_REL_RO_LOCAL
:
5459 prefix
= one_only
? ".gnu.linkonce.d." : ".data.";
5462 prefix
= one_only
? ".gnu.linkonce.s." : ".sdata.";
5465 prefix
= one_only
? ".gnu.linkonce.b." : ".bss.";
5468 prefix
= one_only
? ".gnu.linkonce.sb." : ".sbss.";
5475 plen
= strlen (prefix
);
5477 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5478 STRIP_NAME_ENCODING (name
, name
);
5479 nlen
= strlen (name
);
5481 string
= alloca (nlen
+ plen
+ 1);
5482 memcpy (string
, prefix
, plen
);
5483 memcpy (string
+ plen
, name
, nlen
+ 1);
5485 DECL_SECTION_NAME (decl
) = build_string (nlen
+ plen
, string
);