1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
32 #include "coretypes.h"
39 #include "hard-reg-set.h"
45 #include "langhooks.h"
49 #include "targhooks.h"
50 #include "tree-mudflap.h"
52 #include "cfglayout.h"
53 #include "basic-block.h"
54 #include "tree-iterator.h"
56 #ifdef XCOFF_DEBUGGING_INFO
57 #include "xcoffout.h" /* Needed for external data
58 declarations for e.g. AIX 4.x. */
61 /* The (assembler) name of the first globally-visible object output. */
62 extern GTY(()) const char *first_global_object_name
;
63 extern GTY(()) const char *weak_global_object_name
;
65 const char *first_global_object_name
;
66 const char *weak_global_object_name
;
69 struct constant_descriptor_rtx
;
70 struct rtx_constant_pool
;
72 #define n_deferred_constants (crtl->varasm.deferred_constants)
74 /* Number for making the label on the next
75 constant that is stored in memory. */
77 static GTY(()) int const_labelno
;
79 /* Carry information from ASM_DECLARE_OBJECT_NAME
80 to ASM_FINISH_DECLARE_OBJECT. */
82 int size_directive_output
;
84 /* The last decl for which assemble_variable was called,
85 if it did ASM_DECLARE_OBJECT_NAME.
86 If the last call to assemble_variable didn't do that,
89 tree last_assemble_variable_decl
;
91 /* The following global variable indicates if the first basic block
92 in a function belongs to the cold partition or not. */
94 bool first_function_block_is_cold
;
96 /* We give all constants their own alias set. Perhaps redundant with
97 MEM_READONLY_P, but pre-dates it. */
99 static alias_set_type const_alias_set
;
101 static const char *strip_reg_name (const char *);
102 static int contains_pointers_p (tree
);
103 #ifdef ASM_OUTPUT_EXTERNAL
104 static bool incorporeal_function_p (tree
);
106 static void decode_addr_const (tree
, struct addr_const
*);
107 static hashval_t
const_desc_hash (const void *);
108 static int const_desc_eq (const void *, const void *);
109 static hashval_t
const_hash_1 (const tree
);
110 static int compare_constant (const tree
, const tree
);
111 static tree
copy_constant (tree
);
112 static void output_constant_def_contents (rtx
);
113 static void output_addressed_constants (tree
);
114 static unsigned HOST_WIDE_INT
array_size_for_constructor (tree
);
115 static unsigned min_align (unsigned, unsigned);
116 static void globalize_decl (tree
);
117 #ifdef BSS_SECTION_ASM_OP
118 #ifdef ASM_OUTPUT_BSS
119 static void asm_output_bss (FILE *, tree
, const char *,
120 unsigned HOST_WIDE_INT
, unsigned HOST_WIDE_INT
);
122 #ifdef ASM_OUTPUT_ALIGNED_BSS
123 static void asm_output_aligned_bss (FILE *, tree
, const char *,
124 unsigned HOST_WIDE_INT
, int)
127 #endif /* BSS_SECTION_ASM_OP */
128 static void mark_weak (tree
);
129 static void output_constant_pool (const char *, tree
);
131 /* Well-known sections, each one associated with some sort of *_ASM_OP. */
132 section
*text_section
;
133 section
*data_section
;
134 section
*readonly_data_section
;
135 section
*sdata_section
;
136 section
*ctors_section
;
137 section
*dtors_section
;
138 section
*bss_section
;
139 section
*sbss_section
;
141 /* Various forms of common section. All are guaranteed to be nonnull. */
142 section
*tls_comm_section
;
143 section
*comm_section
;
144 section
*lcomm_section
;
146 /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148 section
*bss_noswitch_section
;
150 /* The section that holds the main exception table, when known. The section
151 is set either by the target's init_sections hook or by the first call to
152 switch_to_exception_section. */
153 section
*exception_section
;
155 /* The section that holds the DWARF2 frame unwind information, when known.
156 The section is set either by the target's init_sections hook or by the
157 first call to switch_to_eh_frame_section. */
158 section
*eh_frame_section
;
160 /* asm_out_file's current section. This is NULL if no section has yet
161 been selected or if we lose track of what the current section is. */
164 /* True if code for the current function is currently being directed
165 at the cold section. */
166 bool in_cold_section_p
;
168 /* A linked list of all the unnamed sections. */
169 static GTY(()) section
*unnamed_sections
;
171 /* Return a nonzero value if DECL has a section attribute. */
172 #define IN_NAMED_SECTION(DECL) \
173 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
174 && DECL_SECTION_NAME (DECL) != NULL_TREE)
176 /* Hash table of named sections. */
177 static GTY((param_is (section
))) htab_t section_htab
;
179 /* A table of object_blocks, indexed by section. */
180 static GTY((param_is (struct object_block
))) htab_t object_block_htab
;
182 /* The next number to use for internal anchor labels. */
183 static GTY(()) int anchor_labelno
;
185 /* A pool of constants that can be shared between functions. */
186 static GTY(()) struct rtx_constant_pool
*shared_constant_pool
;
190 static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map
)))
192 static GTY (()) tree emutls_object_type
;
193 /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This
194 macro can be used on them to distinguish the control variable from
195 the initialization template. */
196 #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type)
198 #if !defined (NO_DOT_IN_LABEL)
199 # define EMUTLS_SEPARATOR "."
200 #elif !defined (NO_DOLLAR_IN_LABEL)
201 # define EMUTLS_SEPARATOR "$"
203 # define EMUTLS_SEPARATOR "_"
206 /* Create an IDENTIFIER_NODE by prefixing PREFIX to the
207 IDENTIFIER_NODE NAME's name. */
210 prefix_name (const char *prefix
, tree name
)
212 unsigned plen
= strlen (prefix
);
213 unsigned nlen
= strlen (IDENTIFIER_POINTER (name
));
214 char *toname
= (char *) alloca (plen
+ nlen
+ 1);
216 memcpy (toname
, prefix
, plen
);
217 memcpy (toname
+ plen
, IDENTIFIER_POINTER (name
), nlen
+ 1);
219 return get_identifier (toname
);
222 /* Create an identifier for the struct __emutls_object, given an identifier
223 of the DECL_ASSEMBLY_NAME of the original object. */
226 get_emutls_object_name (tree name
)
228 const char *prefix
= (targetm
.emutls
.var_prefix
229 ? targetm
.emutls
.var_prefix
230 : "__emutls_v" EMUTLS_SEPARATOR
);
231 return prefix_name (prefix
, name
);
235 default_emutls_var_fields (tree type
, tree
*name ATTRIBUTE_UNUSED
)
237 tree word_type_node
, field
, next_field
;
239 field
= build_decl (UNKNOWN_LOCATION
,
240 FIELD_DECL
, get_identifier ("__templ"), ptr_type_node
);
241 DECL_CONTEXT (field
) = type
;
244 field
= build_decl (UNKNOWN_LOCATION
,
245 FIELD_DECL
, get_identifier ("__offset"),
247 DECL_CONTEXT (field
) = type
;
248 TREE_CHAIN (field
) = next_field
;
251 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
252 field
= build_decl (UNKNOWN_LOCATION
,
253 FIELD_DECL
, get_identifier ("__align"),
255 DECL_CONTEXT (field
) = type
;
256 TREE_CHAIN (field
) = next_field
;
259 field
= build_decl (UNKNOWN_LOCATION
,
260 FIELD_DECL
, get_identifier ("__size"), word_type_node
);
261 DECL_CONTEXT (field
) = type
;
262 TREE_CHAIN (field
) = next_field
;
267 /* Create the structure for struct __emutls_object. This should match the
268 structure at the top of emutls.c, modulo the union there. */
271 get_emutls_object_type (void)
273 tree type
, type_name
, field
;
275 type
= emutls_object_type
;
279 emutls_object_type
= type
= lang_hooks
.types
.make_type (RECORD_TYPE
);
281 field
= targetm
.emutls
.var_fields (type
, &type_name
);
283 type_name
= get_identifier ("__emutls_object");
284 type_name
= build_decl (UNKNOWN_LOCATION
,
285 TYPE_DECL
, type_name
, type
);
286 TYPE_NAME (type
) = type_name
;
287 TYPE_FIELDS (type
) = field
;
293 /* Create a read-only variable like DECL, with the same DECL_INITIAL.
294 This will be used for initializing the emulated tls data area. */
297 get_emutls_init_templ_addr (tree decl
)
301 if (targetm
.emutls
.register_common
&& !DECL_INITIAL (decl
)
302 && !DECL_SECTION_NAME (decl
))
303 return null_pointer_node
;
305 name
= DECL_ASSEMBLER_NAME (decl
);
306 if (!targetm
.emutls
.tmpl_prefix
|| targetm
.emutls
.tmpl_prefix
[0])
308 const char *prefix
= (targetm
.emutls
.tmpl_prefix
309 ? targetm
.emutls
.tmpl_prefix
310 : "__emutls_t" EMUTLS_SEPARATOR
);
311 name
= prefix_name (prefix
, name
);
314 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
315 VAR_DECL
, name
, TREE_TYPE (decl
));
316 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
318 DECL_ARTIFICIAL (to
) = 1;
319 TREE_USED (to
) = TREE_USED (decl
);
320 TREE_READONLY (to
) = 1;
321 DECL_IGNORED_P (to
) = 1;
322 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
323 DECL_SECTION_NAME (to
) = DECL_SECTION_NAME (decl
);
324 DECL_PRESERVE_P (to
) = DECL_PRESERVE_P (decl
);
326 DECL_WEAK (to
) = DECL_WEAK (decl
);
327 if (DECL_ONE_ONLY (decl
))
329 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
330 TREE_STATIC (to
) = TREE_STATIC (decl
);
331 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
332 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
335 TREE_STATIC (to
) = 1;
337 DECL_VISIBILITY_SPECIFIED (to
) = DECL_VISIBILITY_SPECIFIED (decl
);
338 DECL_INITIAL (to
) = DECL_INITIAL (decl
);
339 DECL_INITIAL (decl
) = NULL
;
341 varpool_finalize_decl (to
);
342 return build_fold_addr_expr (to
);
345 /* When emulating tls, we use a control structure for use by the runtime.
346 Create and return this structure. */
349 emutls_decl (tree decl
)
352 struct tree_map
*h
, in
;
355 if (targetm
.have_tls
|| decl
== NULL
|| decl
== error_mark_node
356 || TREE_CODE (decl
) != VAR_DECL
|| ! DECL_THREAD_LOCAL_P (decl
))
359 /* Look up the object in the hash; return the control structure if
360 it has already been created. */
362 emutls_htab
= htab_create_ggc (512, tree_map_hash
, tree_map_eq
, 0);
364 name
= DECL_ASSEMBLER_NAME (decl
);
366 /* Note that we use the hash of the decl's name, rather than a hash
367 of the decl's pointer. In emutls_finish we iterate through the
368 hash table, and we want this traversal to be predictable. */
369 in
.hash
= IDENTIFIER_HASH_VALUE (name
);
371 loc
= htab_find_slot_with_hash (emutls_htab
, &in
, in
.hash
, INSERT
);
372 h
= (struct tree_map
*) *loc
;
377 to
= build_decl (DECL_SOURCE_LOCATION (decl
),
378 VAR_DECL
, get_emutls_object_name (name
),
379 get_emutls_object_type ());
381 h
= ggc_alloc_tree_map ();
385 *(struct tree_map
**) loc
= h
;
387 DECL_TLS_MODEL (to
) = TLS_MODEL_EMULATED
;
388 DECL_ARTIFICIAL (to
) = 1;
389 DECL_IGNORED_P (to
) = 1;
390 /* FIXME: work around PR44132. */
391 DECL_PRESERVE_P (to
) = 1;
392 TREE_READONLY (to
) = 0;
393 SET_DECL_ASSEMBLER_NAME (to
, DECL_NAME (to
));
394 if (DECL_ONE_ONLY (decl
))
395 make_decl_one_only (to
, DECL_ASSEMBLER_NAME (to
));
396 DECL_CONTEXT (to
) = DECL_CONTEXT (decl
);
397 if (targetm
.emutls
.var_align_fixed
)
398 /* If we're not allowed to change the proxy object's
399 alignment, pretend it's been set by the user. */
400 DECL_USER_ALIGN (to
) = 1;
403 /* Note that these fields may need to be updated from time to time from
404 the original decl. Consider:
405 extern __thread int i;
406 int foo() { return i; }
408 in which I goes from external to locally defined and initialized. */
409 DECL_DLLIMPORT_P (to
) = DECL_DLLIMPORT_P (decl
);
410 DECL_ATTRIBUTES (to
) = targetm
.merge_decl_attributes (decl
, to
);
412 TREE_STATIC (to
) = TREE_STATIC (decl
);
413 TREE_USED (to
) = TREE_USED (decl
);
414 TREE_PUBLIC (to
) = TREE_PUBLIC (decl
);
415 DECL_EXTERNAL (to
) = DECL_EXTERNAL (decl
);
416 DECL_COMMON (to
) = DECL_COMMON (decl
);
417 DECL_WEAK (to
) = DECL_WEAK (decl
);
418 DECL_VISIBILITY (to
) = DECL_VISIBILITY (decl
);
419 DECL_VISIBILITY_SPECIFIED (to
) = DECL_VISIBILITY_SPECIFIED (decl
);
421 /* Fortran might pass this to us. */
422 DECL_RESTRICTED_P (to
) = DECL_RESTRICTED_P (decl
);
428 emutls_common_1 (void **loc
, void *xstmts
)
430 struct tree_map
*h
= *(struct tree_map
**) loc
;
431 tree args
, x
, *pstmts
= (tree
*) xstmts
;
434 if (! DECL_COMMON (h
->base
.from
)
435 || (DECL_INITIAL (h
->base
.from
)
436 && DECL_INITIAL (h
->base
.from
) != error_mark_node
))
439 word_type_node
= lang_hooks
.types
.type_for_mode (word_mode
, 1);
441 /* The idea was to call get_emutls_init_templ_addr here, but if we
442 do this and there is an initializer, -fanchor_section loses,
443 because it would be too late to ensure the template is
445 x
= null_pointer_node
;
446 args
= tree_cons (NULL
, x
, NULL
);
447 x
= build_int_cst (word_type_node
, DECL_ALIGN_UNIT (h
->base
.from
));
448 args
= tree_cons (NULL
, x
, args
);
449 x
= fold_convert (word_type_node
, DECL_SIZE_UNIT (h
->base
.from
));
450 args
= tree_cons (NULL
, x
, args
);
451 x
= build_fold_addr_expr (h
->to
);
452 args
= tree_cons (NULL
, x
, args
);
454 x
= built_in_decls
[BUILT_IN_EMUTLS_REGISTER_COMMON
];
455 x
= build_function_call_expr (UNKNOWN_LOCATION
, x
, args
);
457 append_to_statement_list (x
, pstmts
);
461 /* Callback to finalize one emutls control variable. */
464 emutls_finalize_control_var (void **loc
,
465 void *unused ATTRIBUTE_UNUSED
)
467 struct tree_map
*h
= *(struct tree_map
**) loc
;
470 struct varpool_node
*node
= varpool_node (h
->to
);
471 /* Because varpool_finalize_decl () has side-effects,
472 only apply to un-finalized vars. */
473 if (node
&& !node
->finalized
)
474 varpool_finalize_decl (h
->to
);
479 /* Finalize emutls control vars and add a static constructor if
485 if (emutls_htab
== NULL
)
487 htab_traverse_noresize (emutls_htab
,
488 emutls_finalize_control_var
, NULL
);
490 if (targetm
.emutls
.register_common
)
492 tree body
= NULL_TREE
;
494 htab_traverse_noresize (emutls_htab
, emutls_common_1
, &body
);
495 if (body
== NULL_TREE
)
498 cgraph_build_static_cdtor ('I', body
, DEFAULT_INIT_PRIORITY
);
502 /* Helper routines for maintaining section_htab. */
505 section_entry_eq (const void *p1
, const void *p2
)
507 const section
*old
= (const section
*) p1
;
508 const char *new_name
= (const char *) p2
;
510 return strcmp (old
->named
.name
, new_name
) == 0;
514 section_entry_hash (const void *p
)
516 const section
*old
= (const section
*) p
;
517 return htab_hash_string (old
->named
.name
);
520 /* Return a hash value for section SECT. */
523 hash_section (section
*sect
)
525 if (sect
->common
.flags
& SECTION_NAMED
)
526 return htab_hash_string (sect
->named
.name
);
527 return sect
->common
.flags
;
530 /* Helper routines for maintaining object_block_htab. */
533 object_block_entry_eq (const void *p1
, const void *p2
)
535 const struct object_block
*old
= (const struct object_block
*) p1
;
536 const section
*new_section
= (const section
*) p2
;
538 return old
->sect
== new_section
;
542 object_block_entry_hash (const void *p
)
544 const struct object_block
*old
= (const struct object_block
*) p
;
545 return hash_section (old
->sect
);
548 /* Return a new unnamed section with the given fields. */
551 get_unnamed_section (unsigned int flags
, void (*callback
) (const void *),
556 sect
= ggc_alloc_section ();
557 sect
->unnamed
.common
.flags
= flags
| SECTION_UNNAMED
;
558 sect
->unnamed
.callback
= callback
;
559 sect
->unnamed
.data
= data
;
560 sect
->unnamed
.next
= unnamed_sections
;
562 unnamed_sections
= sect
;
566 /* Return a SECTION_NOSWITCH section with the given fields. */
569 get_noswitch_section (unsigned int flags
, noswitch_section_callback callback
)
573 sect
= ggc_alloc_section ();
574 sect
->noswitch
.common
.flags
= flags
| SECTION_NOSWITCH
;
575 sect
->noswitch
.callback
= callback
;
580 /* Return the named section structure associated with NAME. Create
581 a new section with the given fields if no such structure exists. */
584 get_section (const char *name
, unsigned int flags
, tree decl
)
586 section
*sect
, **slot
;
589 htab_find_slot_with_hash (section_htab
, name
,
590 htab_hash_string (name
), INSERT
);
591 flags
|= SECTION_NAMED
;
594 sect
= ggc_alloc_section ();
595 sect
->named
.common
.flags
= flags
;
596 sect
->named
.name
= ggc_strdup (name
);
597 sect
->named
.decl
= decl
;
603 if ((sect
->common
.flags
& ~SECTION_DECLARED
) != flags
604 && ((sect
->common
.flags
| flags
) & SECTION_OVERRIDE
) == 0)
606 /* Sanity check user variables for flag changes. */
608 decl
= sect
->named
.decl
;
610 error ("%+D causes a section type conflict", decl
);
616 /* Return true if the current compilation mode benefits from having
617 objects grouped into blocks. */
620 use_object_blocks_p (void)
622 return flag_section_anchors
;
625 /* Return the object_block structure for section SECT. Create a new
626 structure if we haven't created one already. Return null if SECT
629 static struct object_block
*
630 get_block_for_section (section
*sect
)
632 struct object_block
*block
;
638 slot
= htab_find_slot_with_hash (object_block_htab
, sect
,
639 hash_section (sect
), INSERT
);
640 block
= (struct object_block
*) *slot
;
643 block
= ggc_alloc_cleared_object_block ();
650 /* Create a symbol with label LABEL and place it at byte offset
651 OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
652 is not yet known. LABEL must be a garbage-collected string. */
655 create_block_symbol (const char *label
, struct object_block
*block
,
656 HOST_WIDE_INT offset
)
661 /* Create the extended SYMBOL_REF. */
662 size
= RTX_HDR_SIZE
+ sizeof (struct block_symbol
);
663 symbol
= ggc_alloc_zone_rtx_def (size
, &rtl_zone
);
665 /* Initialize the normal SYMBOL_REF fields. */
666 memset (symbol
, 0, size
);
667 PUT_CODE (symbol
, SYMBOL_REF
);
668 PUT_MODE (symbol
, Pmode
);
669 XSTR (symbol
, 0) = label
;
670 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_HAS_BLOCK_INFO
;
672 /* Initialize the block_symbol stuff. */
673 SYMBOL_REF_BLOCK (symbol
) = block
;
674 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
680 initialize_cold_section_name (void)
682 const char *stripped_name
;
686 gcc_assert (cfun
&& current_function_decl
);
687 if (crtl
->subsections
.unlikely_text_section_name
)
690 dsn
= DECL_SECTION_NAME (current_function_decl
);
691 if (flag_function_sections
&& dsn
)
693 name
= (char *) alloca (TREE_STRING_LENGTH (dsn
) + 1);
694 memcpy (name
, TREE_STRING_POINTER (dsn
), TREE_STRING_LENGTH (dsn
) + 1);
696 stripped_name
= targetm
.strip_name_encoding (name
);
698 buffer
= ACONCAT ((stripped_name
, "_unlikely", NULL
));
699 crtl
->subsections
.unlikely_text_section_name
= ggc_strdup (buffer
);
702 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
705 /* Tell assembler to switch to unlikely-to-be-executed text section. */
708 unlikely_text_section (void)
712 if (!crtl
->subsections
.unlikely_text_section_name
)
713 initialize_cold_section_name ();
715 return get_named_section (NULL
, crtl
->subsections
.unlikely_text_section_name
, 0);
718 return get_named_section (NULL
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
, 0);
721 /* When called within a function context, return true if the function
722 has been assigned a cold text section and if SECT is that section.
723 When called outside a function context, return true if SECT is the
724 default cold section. */
727 unlikely_text_section_p (section
*sect
)
732 name
= crtl
->subsections
.unlikely_text_section_name
;
734 name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
738 && SECTION_STYLE (sect
) == SECTION_NAMED
739 && strcmp (name
, sect
->named
.name
) == 0);
742 /* Return a section with a particular name and with whatever SECTION_*
743 flags section_type_flags deems appropriate. The name of the section
744 is taken from NAME if nonnull, otherwise it is taken from DECL's
745 DECL_SECTION_NAME. DECL is the decl associated with the section
746 (see the section comment for details) and RELOC is as for
747 section_type_flags. */
750 get_named_section (tree decl
, const char *name
, int reloc
)
754 gcc_assert (!decl
|| DECL_P (decl
));
756 name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
758 flags
= targetm
.section_type_flags (decl
, name
, reloc
);
760 return get_section (name
, flags
, decl
);
763 /* If required, set DECL_SECTION_NAME to a unique name. */
766 resolve_unique_section (tree decl
, int reloc ATTRIBUTE_UNUSED
,
767 int flag_function_or_data_sections
)
769 if (DECL_SECTION_NAME (decl
) == NULL_TREE
770 && targetm
.have_named_sections
771 && (flag_function_or_data_sections
772 || DECL_ONE_ONLY (decl
)))
773 targetm
.asm_out
.unique_section (decl
, reloc
);
776 #ifdef BSS_SECTION_ASM_OP
778 #ifdef ASM_OUTPUT_BSS
780 /* Utility function for ASM_OUTPUT_BSS for targets to use if
781 they don't support alignments in .bss.
782 ??? It is believed that this function will work in most cases so such
783 support is localized here. */
786 asm_output_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
788 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
789 unsigned HOST_WIDE_INT rounded
)
791 gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl
), 0), 0), name
) == 0);
792 targetm
.asm_out
.globalize_decl_name (file
, decl
);
793 switch_to_section (bss_section
);
794 #ifdef ASM_DECLARE_OBJECT_NAME
795 last_assemble_variable_decl
= decl
;
796 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
798 /* Standard thing is just output label for the object. */
799 ASM_OUTPUT_LABEL (file
, name
);
800 #endif /* ASM_DECLARE_OBJECT_NAME */
801 ASM_OUTPUT_SKIP (file
, rounded
? rounded
: 1);
806 #ifdef ASM_OUTPUT_ALIGNED_BSS
808 /* Utility function for targets to use in implementing
809 ASM_OUTPUT_ALIGNED_BSS.
810 ??? It is believed that this function will work in most cases so such
811 support is localized here. */
814 asm_output_aligned_bss (FILE *file
, tree decl ATTRIBUTE_UNUSED
,
815 const char *name
, unsigned HOST_WIDE_INT size
,
818 switch_to_section (bss_section
);
819 ASM_OUTPUT_ALIGN (file
, floor_log2 (align
/ BITS_PER_UNIT
));
820 #ifdef ASM_DECLARE_OBJECT_NAME
821 last_assemble_variable_decl
= decl
;
822 ASM_DECLARE_OBJECT_NAME (file
, name
, decl
);
824 /* Standard thing is just output label for the object. */
825 ASM_OUTPUT_LABEL (file
, name
);
826 #endif /* ASM_DECLARE_OBJECT_NAME */
827 ASM_OUTPUT_SKIP (file
, size
? size
: 1);
832 #endif /* BSS_SECTION_ASM_OP */
834 #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
835 /* Return the hot section for function DECL. Return text_section for
839 hot_function_section (tree decl
)
841 if (decl
!= NULL_TREE
842 && DECL_SECTION_NAME (decl
) != NULL_TREE
843 && targetm
.have_named_sections
)
844 return get_named_section (decl
, NULL
, 0);
850 /* Return the section for function DECL.
852 If DECL is NULL_TREE, return the text section. We can be passed
853 NULL_TREE under some circumstances by dbxout.c at least. */
856 function_section (tree decl
)
860 if (first_function_block_is_cold
)
863 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
864 if (decl
!= NULL_TREE
865 && DECL_SECTION_NAME (decl
) != NULL_TREE
)
866 return reloc
? unlikely_text_section ()
867 : get_named_section (decl
, NULL
, 0);
869 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
871 return reloc
? unlikely_text_section () : hot_function_section (decl
);
876 current_function_section (void)
878 #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
879 if (current_function_decl
!= NULL_TREE
880 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
881 return in_cold_section_p
? unlikely_text_section ()
882 : get_named_section (current_function_decl
,
885 return targetm
.asm_out
.select_section (current_function_decl
,
887 DECL_ALIGN (current_function_decl
));
889 return (in_cold_section_p
890 ? unlikely_text_section ()
891 : hot_function_section (current_function_decl
));
895 /* Return the read-only data section associated with function DECL. */
898 default_function_rodata_section (tree decl
)
900 if (decl
!= NULL_TREE
&& DECL_SECTION_NAME (decl
))
902 const char *name
= TREE_STRING_POINTER (DECL_SECTION_NAME (decl
));
904 if (DECL_ONE_ONLY (decl
) && HAVE_COMDAT_GROUP
)
910 dot
= strchr (name
+ 1, '.');
913 len
= strlen (dot
) + 8;
914 rname
= (char *) alloca (len
);
916 strcpy (rname
, ".rodata");
918 return get_section (rname
, SECTION_LINKONCE
, decl
);
920 /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
921 else if (DECL_ONE_ONLY (decl
)
922 && strncmp (name
, ".gnu.linkonce.t.", 16) == 0)
924 size_t len
= strlen (name
) + 1;
925 char *rname
= (char *) alloca (len
);
927 memcpy (rname
, name
, len
);
929 return get_section (rname
, SECTION_LINKONCE
, decl
);
931 /* For .text.foo we want to use .rodata.foo. */
932 else if (flag_function_sections
&& flag_data_sections
933 && strncmp (name
, ".text.", 6) == 0)
935 size_t len
= strlen (name
) + 1;
936 char *rname
= (char *) alloca (len
+ 2);
938 memcpy (rname
, ".rodata", 7);
939 memcpy (rname
+ 7, name
+ 5, len
- 5);
940 return get_section (rname
, 0, decl
);
944 return readonly_data_section
;
947 /* Return the read-only data section associated with function DECL
948 for targets where that section should be always the single
949 readonly data section. */
952 default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED
)
954 return readonly_data_section
;
957 /* Return the section to use for string merging. */
960 mergeable_string_section (tree decl ATTRIBUTE_UNUSED
,
961 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
962 unsigned int flags ATTRIBUTE_UNUSED
)
966 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
967 && TREE_CODE (decl
) == STRING_CST
968 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
970 && (len
= int_size_in_bytes (TREE_TYPE (decl
))) > 0
971 && TREE_STRING_LENGTH (decl
) >= len
)
973 enum machine_mode mode
;
974 unsigned int modesize
;
980 mode
= TYPE_MODE (TREE_TYPE (TREE_TYPE (decl
)));
981 modesize
= GET_MODE_BITSIZE (mode
);
982 if (modesize
>= 8 && modesize
<= 256
983 && (modesize
& (modesize
- 1)) == 0)
985 if (align
< modesize
)
988 str
= TREE_STRING_POINTER (decl
);
989 unit
= GET_MODE_SIZE (mode
);
991 /* Check for embedded NUL characters. */
992 for (i
= 0; i
< len
; i
+= unit
)
994 for (j
= 0; j
< unit
; j
++)
995 if (str
[i
+ j
] != '\0')
1000 if (i
== len
- unit
)
1002 sprintf (name
, ".rodata.str%d.%d", modesize
/ 8,
1004 flags
|= (modesize
/ 8) | SECTION_MERGE
| SECTION_STRINGS
;
1005 return get_section (name
, flags
, NULL
);
1010 return readonly_data_section
;
1013 /* Return the section to use for constant merging. */
1016 mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
1017 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
,
1018 unsigned int flags ATTRIBUTE_UNUSED
)
1020 unsigned int modesize
= GET_MODE_BITSIZE (mode
);
1022 if (HAVE_GAS_SHF_MERGE
&& flag_merge_constants
1025 && modesize
<= align
1028 && (align
& (align
- 1)) == 0)
1032 sprintf (name
, ".rodata.cst%d", (int) (align
/ 8));
1033 flags
|= (align
/ 8) | SECTION_MERGE
;
1034 return get_section (name
, flags
, NULL
);
1036 return readonly_data_section
;
1039 /* Given NAME, a putative register name, discard any customary prefixes. */
1042 strip_reg_name (const char *name
)
1044 #ifdef REGISTER_PREFIX
1045 if (!strncmp (name
, REGISTER_PREFIX
, strlen (REGISTER_PREFIX
)))
1046 name
+= strlen (REGISTER_PREFIX
);
1048 if (name
[0] == '%' || name
[0] == '#')
1053 /* The user has asked for a DECL to have a particular name. Set (or
1054 change) it in such a way that we don't prefix an underscore to
1057 set_user_assembler_name (tree decl
, const char *name
)
1059 char *starred
= (char *) alloca (strlen (name
) + 2);
1061 strcpy (starred
+ 1, name
);
1062 change_decl_assembler_name (decl
, get_identifier (starred
));
1063 SET_DECL_RTL (decl
, NULL_RTX
);
1066 /* Decode an `asm' spec for a declaration as a register name.
1067 Return the register number, or -1 if nothing specified,
1068 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
1069 or -3 if ASMSPEC is `cc' and is not recognized,
1070 or -4 if ASMSPEC is `memory' and is not recognized.
1071 Accept an exact spelling or a decimal number.
1072 Prefixes such as % are optional. */
1075 decode_reg_name (const char *asmspec
)
1081 /* Get rid of confusing prefixes. */
1082 asmspec
= strip_reg_name (asmspec
);
1084 /* Allow a decimal number as a "register name". */
1085 for (i
= strlen (asmspec
) - 1; i
>= 0; i
--)
1086 if (! ISDIGIT (asmspec
[i
]))
1088 if (asmspec
[0] != 0 && i
< 0)
1091 if (i
< FIRST_PSEUDO_REGISTER
&& i
>= 0)
1097 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1099 && ! strcmp (asmspec
, strip_reg_name (reg_names
[i
])))
1102 #ifdef ADDITIONAL_REGISTER_NAMES
1104 static const struct { const char *const name
; const int number
; } table
[]
1105 = ADDITIONAL_REGISTER_NAMES
;
1107 for (i
= 0; i
< (int) ARRAY_SIZE (table
); i
++)
1108 if (table
[i
].name
[0]
1109 && ! strcmp (asmspec
, table
[i
].name
))
1110 return table
[i
].number
;
1112 #endif /* ADDITIONAL_REGISTER_NAMES */
1114 if (!strcmp (asmspec
, "memory"))
1117 if (!strcmp (asmspec
, "cc"))
1126 /* Return true if DECL's initializer is suitable for a BSS section. */
1129 bss_initializer_p (const_tree decl
)
1131 return (DECL_INITIAL (decl
) == NULL
1132 || DECL_INITIAL (decl
) == error_mark_node
1133 || (flag_zero_initialized_in_bss
1134 /* Leave constant zeroes in .rodata so they
1136 && !TREE_READONLY (decl
)
1137 && initializer_zerop (DECL_INITIAL (decl
))));
1140 /* Compute the alignment of variable specified by DECL.
1141 DONT_OUTPUT_DATA is from assemble_variable. */
1144 align_variable (tree decl
, bool dont_output_data
)
1146 unsigned int align
= DECL_ALIGN (decl
);
1148 /* In the case for initialing an array whose length isn't specified,
1149 where we have not yet been able to do the layout,
1150 figure out the proper alignment now. */
1151 if (dont_output_data
&& DECL_SIZE (decl
) == 0
1152 && TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
)
1153 align
= MAX (align
, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl
))));
1155 /* Some object file formats have a maximum alignment which they support.
1156 In particular, a.out format supports a maximum alignment of 4. */
1157 if (align
> MAX_OFILE_ALIGNMENT
)
1159 warning (0, "alignment of %q+D is greater than maximum object "
1160 "file alignment. Using %d", decl
,
1161 MAX_OFILE_ALIGNMENT
/BITS_PER_UNIT
);
1162 align
= MAX_OFILE_ALIGNMENT
;
1165 /* On some machines, it is good to increase alignment sometimes. */
1166 if (! DECL_USER_ALIGN (decl
))
1168 #ifdef DATA_ALIGNMENT
1169 unsigned int data_align
= DATA_ALIGNMENT (TREE_TYPE (decl
), align
);
1170 /* Don't increase alignment too much for TLS variables - TLS space
1172 if (! DECL_THREAD_LOCAL_P (decl
) || data_align
<= BITS_PER_WORD
)
1175 #ifdef CONSTANT_ALIGNMENT
1176 if (DECL_INITIAL (decl
) != 0 && DECL_INITIAL (decl
) != error_mark_node
)
1178 unsigned int const_align
= CONSTANT_ALIGNMENT (DECL_INITIAL (decl
),
1180 /* Don't increase alignment too much for TLS variables - TLS space
1182 if (! DECL_THREAD_LOCAL_P (decl
) || const_align
<= BITS_PER_WORD
)
1183 align
= const_align
;
1188 /* Reset the alignment in case we have made it tighter, so we can benefit
1189 from it in get_pointer_alignment. */
1190 DECL_ALIGN (decl
) = align
;
1193 /* Return the section into which the given VAR_DECL or CONST_DECL
1194 should be placed. PREFER_NOSWITCH_P is true if a noswitch
1195 section should be used wherever possible. */
1198 get_variable_section (tree decl
, bool prefer_noswitch_p
)
1200 addr_space_t as
= ADDR_SPACE_GENERIC
;
1203 if (TREE_TYPE (decl
) != error_mark_node
)
1204 as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1206 if (DECL_COMMON (decl
))
1208 /* If the decl has been given an explicit section name, or it resides
1209 in a non-generic address space, then it isn't common, and shouldn't
1210 be handled as such. */
1211 gcc_assert (DECL_SECTION_NAME (decl
) == NULL
1212 && ADDR_SPACE_GENERIC_P (as
));
1213 if (DECL_THREAD_LOCAL_P (decl
))
1214 return tls_comm_section
;
1215 /* This cannot be common bss for an emulated TLS object without
1216 a register_common hook. */
1217 else if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
1218 && !targetm
.emutls
.register_common
)
1220 else if (TREE_PUBLIC (decl
) && bss_initializer_p (decl
))
1221 return comm_section
;
1224 if (DECL_INITIAL (decl
) == error_mark_node
)
1225 reloc
= contains_pointers_p (TREE_TYPE (decl
)) ? 3 : 0;
1226 else if (DECL_INITIAL (decl
))
1227 reloc
= compute_reloc_for_constant (DECL_INITIAL (decl
));
1231 resolve_unique_section (decl
, reloc
, flag_data_sections
);
1232 if (IN_NAMED_SECTION (decl
))
1233 return get_named_section (decl
, NULL
, reloc
);
1235 if (ADDR_SPACE_GENERIC_P (as
)
1236 && !DECL_THREAD_LOCAL_P (decl
)
1237 && !(prefer_noswitch_p
&& targetm
.have_switchable_bss_sections
)
1238 && bss_initializer_p (decl
))
1240 if (!TREE_PUBLIC (decl
))
1241 return lcomm_section
;
1242 if (bss_noswitch_section
)
1243 return bss_noswitch_section
;
1246 return targetm
.asm_out
.select_section (decl
, reloc
, DECL_ALIGN (decl
));
1249 /* Return the block into which object_block DECL should be placed. */
1251 static struct object_block
*
1252 get_block_for_decl (tree decl
)
1256 if (TREE_CODE (decl
) == VAR_DECL
)
1258 /* The object must be defined in this translation unit. */
1259 if (DECL_EXTERNAL (decl
))
1262 /* There's no point using object blocks for something that is
1263 isolated by definition. */
1264 if (DECL_ONE_ONLY (decl
))
1268 /* We can only calculate block offsets if the decl has a known
1270 if (DECL_SIZE_UNIT (decl
) == NULL
)
1272 if (!host_integerp (DECL_SIZE_UNIT (decl
), 1))
1275 /* Find out which section should contain DECL. We cannot put it into
1276 an object block if it requires a standalone definition. */
1277 if (TREE_CODE (decl
) == VAR_DECL
)
1278 align_variable (decl
, 0);
1279 sect
= get_variable_section (decl
, true);
1280 if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
1283 return get_block_for_section (sect
);
1286 /* Make sure block symbol SYMBOL is in block BLOCK. */
1289 change_symbol_block (rtx symbol
, struct object_block
*block
)
1291 if (block
!= SYMBOL_REF_BLOCK (symbol
))
1293 gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol
) < 0);
1294 SYMBOL_REF_BLOCK (symbol
) = block
;
1298 /* Return true if it is possible to put DECL in an object_block. */
1301 use_blocks_for_decl_p (tree decl
)
1303 /* Only data DECLs can be placed into object blocks. */
1304 if (TREE_CODE (decl
) != VAR_DECL
&& TREE_CODE (decl
) != CONST_DECL
)
1307 /* Detect decls created by dw2_force_const_mem. Such decls are
1308 special because DECL_INITIAL doesn't specify the decl's true value.
1309 dw2_output_indirect_constants will instead call assemble_variable
1310 with dont_output_data set to 1 and then print the contents itself. */
1311 if (DECL_INITIAL (decl
) == decl
)
1314 /* If this decl is an alias, then we don't want to emit a definition. */
1315 if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl
)))
1321 /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1322 have static storage duration. In other words, it should not be an
1323 automatic variable, including PARM_DECLs.
1325 There is, however, one exception: this function handles variables
1326 explicitly placed in a particular register by the user.
1328 This is never called for PARM_DECL nodes. */
1331 make_decl_rtl (tree decl
)
1333 const char *name
= 0;
1337 /* Check that we are not being given an automatic variable. */
1338 gcc_assert (TREE_CODE (decl
) != PARM_DECL
1339 && TREE_CODE (decl
) != RESULT_DECL
);
1341 /* A weak alias has TREE_PUBLIC set but not the other bits. */
1342 gcc_assert (TREE_CODE (decl
) != VAR_DECL
1343 || TREE_STATIC (decl
)
1344 || TREE_PUBLIC (decl
)
1345 || DECL_EXTERNAL (decl
)
1346 || DECL_REGISTER (decl
));
1348 /* And that we were not given a type or a label. */
1349 gcc_assert (TREE_CODE (decl
) != TYPE_DECL
1350 && TREE_CODE (decl
) != LABEL_DECL
);
1352 /* For a duplicate declaration, we can be called twice on the
1353 same DECL node. Don't discard the RTL already made. */
1354 if (DECL_RTL_SET_P (decl
))
1356 /* If the old RTL had the wrong mode, fix the mode. */
1357 x
= DECL_RTL (decl
);
1358 if (GET_MODE (x
) != DECL_MODE (decl
))
1359 SET_DECL_RTL (decl
, adjust_address_nv (x
, DECL_MODE (decl
), 0));
1361 if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1364 /* ??? Another way to do this would be to maintain a hashed
1365 table of such critters. Instead of adding stuff to a DECL
1366 to give certain attributes to it, we could use an external
1367 hash map from DECL to set of attributes. */
1369 /* Let the target reassign the RTL if it wants.
1370 This is necessary, for example, when one machine specific
1371 decl attribute overrides another. */
1372 targetm
.encode_section_info (decl
, DECL_RTL (decl
), false);
1374 /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1375 on the new decl information. */
1377 && GET_CODE (XEXP (x
, 0)) == SYMBOL_REF
1378 && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x
, 0)))
1379 change_symbol_block (XEXP (x
, 0), get_block_for_decl (decl
));
1381 /* Make this function static known to the mudflap runtime. */
1382 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1383 mudflap_enqueue_decl (decl
);
1388 /* If this variable belongs to the global constant pool, retrieve the
1389 pre-computed RTL or recompute it in LTO mode. */
1390 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_IN_CONSTANT_POOL (decl
))
1392 SET_DECL_RTL (decl
, output_constant_def (DECL_INITIAL (decl
), 1));
1396 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
1398 if (name
[0] != '*' && TREE_CODE (decl
) != FUNCTION_DECL
1399 && DECL_REGISTER (decl
))
1401 error ("register name not specified for %q+D", decl
);
1403 else if (TREE_CODE (decl
) != FUNCTION_DECL
&& DECL_REGISTER (decl
))
1405 const char *asmspec
= name
+1;
1406 reg_number
= decode_reg_name (asmspec
);
1407 /* First detect errors in declaring global registers. */
1408 if (reg_number
== -1)
1409 error ("register name not specified for %q+D", decl
);
1410 else if (reg_number
< 0)
1411 error ("invalid register name for %q+D", decl
);
1412 else if (TYPE_MODE (TREE_TYPE (decl
)) == BLKmode
)
1413 error ("data type of %q+D isn%'t suitable for a register",
1415 else if (! HARD_REGNO_MODE_OK (reg_number
, TYPE_MODE (TREE_TYPE (decl
))))
1416 error ("register specified for %q+D isn%'t suitable for data type",
1418 /* Now handle properly declared static register variables. */
1423 if (DECL_INITIAL (decl
) != 0 && TREE_STATIC (decl
))
1425 DECL_INITIAL (decl
) = 0;
1426 error ("global register variable has initial value");
1428 if (TREE_THIS_VOLATILE (decl
))
1429 warning (OPT_Wvolatile_register_var
,
1430 "optimization may eliminate reads and/or "
1431 "writes to register variables");
1433 /* If the user specified one of the eliminables registers here,
1434 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1435 confused with that register and be eliminated. This usage is
1436 somewhat suspect... */
1438 SET_DECL_RTL (decl
, gen_rtx_raw_REG (DECL_MODE (decl
), reg_number
));
1439 ORIGINAL_REGNO (DECL_RTL (decl
)) = reg_number
;
1440 REG_USERVAR_P (DECL_RTL (decl
)) = 1;
1442 if (TREE_STATIC (decl
))
1444 /* Make this register global, so not usable for anything
1446 #ifdef ASM_DECLARE_REGISTER_GLOBAL
1447 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
1448 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file
, decl
, reg_number
, name
);
1450 nregs
= hard_regno_nregs
[reg_number
][DECL_MODE (decl
)];
1452 globalize_reg (reg_number
+ --nregs
);
1455 /* As a register variable, it has no section. */
1459 /* Now handle ordinary static variables and functions (in memory).
1460 Also handle vars declared register invalidly. */
1461 else if (name
[0] == '*')
1463 #ifdef REGISTER_PREFIX
1464 if (strlen (REGISTER_PREFIX
) != 0)
1466 reg_number
= decode_reg_name (name
);
1467 if (reg_number
>= 0 || reg_number
== -3)
1468 error ("register name given for non-register variable %q+D", decl
);
1473 /* Specifying a section attribute on a variable forces it into a
1474 non-.bss section, and thus it cannot be common. */
1475 /* FIXME: In general this code should not be necessary because
1476 visibility pass is doing the same work. But notice_global_symbol
1477 is called early and it needs to make DECL_RTL to get the name.
1478 we take care of recomputing the DECL_RTL after visibility is changed. */
1479 if (TREE_CODE (decl
) == VAR_DECL
1480 && DECL_SECTION_NAME (decl
) != NULL_TREE
1481 && DECL_INITIAL (decl
) == NULL_TREE
1482 && DECL_COMMON (decl
))
1483 DECL_COMMON (decl
) = 0;
1485 /* Variables can't be both common and weak. */
1486 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_WEAK (decl
))
1487 DECL_COMMON (decl
) = 0;
1489 if (use_object_blocks_p () && use_blocks_for_decl_p (decl
))
1490 x
= create_block_symbol (name
, get_block_for_decl (decl
), -1);
1493 enum machine_mode address_mode
= Pmode
;
1494 if (TREE_TYPE (decl
) != error_mark_node
)
1496 addr_space_t as
= TYPE_ADDR_SPACE (TREE_TYPE (decl
));
1497 address_mode
= targetm
.addr_space
.address_mode (as
);
1499 x
= gen_rtx_SYMBOL_REF (address_mode
, name
);
1501 SYMBOL_REF_WEAK (x
) = DECL_WEAK (decl
);
1502 SET_SYMBOL_REF_DECL (x
, decl
);
1504 x
= gen_rtx_MEM (DECL_MODE (decl
), x
);
1505 if (TREE_CODE (decl
) != FUNCTION_DECL
)
1506 set_mem_attributes (x
, decl
, 1);
1507 SET_DECL_RTL (decl
, x
);
1509 /* Optionally set flags or add text to the name to record information
1510 such as that it is a function name.
1511 If the name is changed, the macro ASM_OUTPUT_LABELREF
1512 will have to know how to strip this information. */
1513 targetm
.encode_section_info (decl
, DECL_RTL (decl
), true);
1515 /* Make this function static known to the mudflap runtime. */
1516 if (flag_mudflap
&& TREE_CODE (decl
) == VAR_DECL
)
1517 mudflap_enqueue_decl (decl
);
1520 /* Like make_decl_rtl, but inhibit creation of new alias sets when
1521 calling make_decl_rtl. Also, reset DECL_RTL before returning the
1525 make_decl_rtl_for_debug (tree decl
)
1527 unsigned int save_aliasing_flag
, save_mudflap_flag
;
1530 if (DECL_RTL_SET_P (decl
))
1531 return DECL_RTL (decl
);
1533 /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1534 call new_alias_set. If running with -fcompare-debug, sometimes
1535 we do not want to create alias sets that will throw the alias
1536 numbers off in the comparison dumps. So... clearing
1537 flag_strict_aliasing will keep new_alias_set() from creating a
1538 new set. It is undesirable to register decl with mudflap
1539 in this case as well. */
1540 save_aliasing_flag
= flag_strict_aliasing
;
1541 flag_strict_aliasing
= 0;
1542 save_mudflap_flag
= flag_mudflap
;
1545 rtl
= DECL_RTL (decl
);
1546 /* Reset DECL_RTL back, as various parts of the compiler expects
1547 DECL_RTL set meaning it is actually going to be output. */
1548 SET_DECL_RTL (decl
, NULL
);
1550 flag_strict_aliasing
= save_aliasing_flag
;
1551 flag_mudflap
= save_mudflap_flag
;
1556 /* Output a string of literal assembler code
1557 for an `asm' keyword used between functions. */
1560 assemble_asm (tree string
)
1564 if (TREE_CODE (string
) == ADDR_EXPR
)
1565 string
= TREE_OPERAND (string
, 0);
1567 fprintf (asm_out_file
, "\t%s\n", TREE_STRING_POINTER (string
));
1570 /* Record an element in the table of global destructors. SYMBOL is
1571 a SYMBOL_REF of the function to be called; PRIORITY is a number
1572 between 0 and MAX_INIT_PRIORITY. */
1575 default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED
,
1576 int priority ATTRIBUTE_UNUSED
)
1578 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1579 /* Tell GNU LD that this is part of the static destructor set.
1580 This will work for any system that uses stabs, most usefully
1582 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */);
1583 dbxout_stab_value_label (XSTR (symbol
, 0));
1585 sorry ("global destructors not supported on this target");
1589 /* Write the address of the entity given by SYMBOL to SEC. */
1591 assemble_addr_to_section (rtx symbol
, section
*sec
)
1593 switch_to_section (sec
);
1594 assemble_align (POINTER_SIZE
);
1595 assemble_integer (symbol
, POINTER_SIZE
/ BITS_PER_UNIT
, POINTER_SIZE
, 1);
1598 /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1599 not) section for PRIORITY. */
1601 get_cdtor_priority_section (int priority
, bool constructor_p
)
1605 /* ??? This only works reliably with the GNU linker. */
1606 sprintf (buf
, "%s.%.5u",
1607 constructor_p
? ".ctors" : ".dtors",
1608 /* Invert the numbering so the linker puts us in the proper
1609 order; constructors are run from right to left, and the
1610 linker sorts in increasing order. */
1611 MAX_INIT_PRIORITY
- priority
);
1612 return get_section (buf
, SECTION_WRITE
, NULL
);
1616 default_named_section_asm_out_destructor (rtx symbol
, int priority
)
1620 if (priority
!= DEFAULT_INIT_PRIORITY
)
1621 sec
= get_cdtor_priority_section (priority
,
1622 /*constructor_p=*/false);
1624 sec
= get_section (".dtors", SECTION_WRITE
, NULL
);
1626 assemble_addr_to_section (symbol
, sec
);
1629 #ifdef DTORS_SECTION_ASM_OP
1631 default_dtor_section_asm_out_destructor (rtx symbol
,
1632 int priority ATTRIBUTE_UNUSED
)
1634 assemble_addr_to_section (symbol
, dtors_section
);
1638 /* Likewise for global constructors. */
1641 default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED
,
1642 int priority ATTRIBUTE_UNUSED
)
1644 #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO
1645 /* Tell GNU LD that this is part of the static destructor set.
1646 This will work for any system that uses stabs, most usefully
1648 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */);
1649 dbxout_stab_value_label (XSTR (symbol
, 0));
1651 sorry ("global constructors not supported on this target");
1656 default_named_section_asm_out_constructor (rtx symbol
, int priority
)
1660 if (priority
!= DEFAULT_INIT_PRIORITY
)
1661 sec
= get_cdtor_priority_section (priority
,
1662 /*constructor_p=*/true);
1664 sec
= get_section (".ctors", SECTION_WRITE
, NULL
);
1666 assemble_addr_to_section (symbol
, sec
);
1669 #ifdef CTORS_SECTION_ASM_OP
1671 default_ctor_section_asm_out_constructor (rtx symbol
,
1672 int priority ATTRIBUTE_UNUSED
)
1674 assemble_addr_to_section (symbol
, ctors_section
);
1678 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1679 a nonzero value if the constant pool should be output before the
1680 start of the function, or a zero value if the pool should output
1681 after the end of the function. The default is to put it before the
1684 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1685 #define CONSTANT_POOL_BEFORE_FUNCTION 1
1688 /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1689 to be output to assembler.
1690 Set first_global_object_name and weak_global_object_name as appropriate. */
1693 notice_global_symbol (tree decl
)
1695 const char **type
= &first_global_object_name
;
1697 if (first_global_object_name
1698 || !TREE_PUBLIC (decl
)
1699 || DECL_EXTERNAL (decl
)
1700 || !DECL_NAME (decl
)
1701 || (TREE_CODE (decl
) != FUNCTION_DECL
1702 && (TREE_CODE (decl
) != VAR_DECL
1703 || (DECL_COMMON (decl
)
1704 && (DECL_INITIAL (decl
) == 0
1705 || DECL_INITIAL (decl
) == error_mark_node
))))
1706 || !MEM_P (DECL_RTL (decl
)))
1709 /* We win when global object is found, but it is useful to know about weak
1710 symbol as well so we can produce nicer unique names. */
1711 if (DECL_WEAK (decl
) || DECL_ONE_ONLY (decl
) || flag_shlib
)
1712 type
= &weak_global_object_name
;
1718 rtx decl_rtl
= DECL_RTL (decl
);
1720 p
= targetm
.strip_name_encoding (XSTR (XEXP (decl_rtl
, 0), 0));
1721 name
= ggc_strdup (p
);
1727 /* Output assembler code for the constant pool of a function and associated
1728 with defining the name of the function. DECL describes the function.
1729 NAME is the function's name. For the constant pool, we use the current
1730 constant pool data. */
1733 assemble_start_function (tree decl
, const char *fnname
)
1736 char tmp_label
[100];
1737 bool hot_label_written
= false;
1739 crtl
->subsections
.unlikely_text_section_name
= NULL
;
1741 first_function_block_is_cold
= false;
1742 if (flag_reorder_blocks_and_partition
)
1744 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTB", const_labelno
);
1745 crtl
->subsections
.hot_section_label
= ggc_strdup (tmp_label
);
1746 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDB", const_labelno
);
1747 crtl
->subsections
.cold_section_label
= ggc_strdup (tmp_label
);
1748 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LHOTE", const_labelno
);
1749 crtl
->subsections
.hot_section_end_label
= ggc_strdup (tmp_label
);
1750 ASM_GENERATE_INTERNAL_LABEL (tmp_label
, "LCOLDE", const_labelno
);
1751 crtl
->subsections
.cold_section_end_label
= ggc_strdup (tmp_label
);
1756 crtl
->subsections
.hot_section_label
= NULL
;
1757 crtl
->subsections
.cold_section_label
= NULL
;
1758 crtl
->subsections
.hot_section_end_label
= NULL
;
1759 crtl
->subsections
.cold_section_end_label
= NULL
;
1762 /* The following code does not need preprocessing in the assembler. */
1766 if (CONSTANT_POOL_BEFORE_FUNCTION
)
1767 output_constant_pool (fnname
, decl
);
1769 resolve_unique_section (decl
, 0, flag_function_sections
);
1771 /* Make sure the not and cold text (code) sections are properly
1772 aligned. This is necessary here in the case where the function
1773 has both hot and cold sections, because we don't want to re-set
1774 the alignment when the section switch happens mid-function. */
1776 if (flag_reorder_blocks_and_partition
)
1778 switch_to_section (unlikely_text_section ());
1779 assemble_align (DECL_ALIGN (decl
));
1780 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_label
);
1782 /* When the function starts with a cold section, we need to explicitly
1783 align the hot section and write out the hot section label.
1784 But if the current function is a thunk, we do not have a CFG. */
1786 && BB_PARTITION (ENTRY_BLOCK_PTR
->next_bb
) == BB_COLD_PARTITION
)
1788 switch_to_section (text_section
);
1789 assemble_align (DECL_ALIGN (decl
));
1790 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1791 hot_label_written
= true;
1792 first_function_block_is_cold
= true;
1795 else if (DECL_SECTION_NAME (decl
))
1797 /* Calls to function_section rely on first_function_block_is_cold
1798 being accurate. The first block may be cold even if we aren't
1799 doing partitioning, if the entire function was decided by
1800 choose_function_section (predict.c) to be cold. */
1802 initialize_cold_section_name ();
1804 if (crtl
->subsections
.unlikely_text_section_name
1805 && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl
)),
1806 crtl
->subsections
.unlikely_text_section_name
) == 0)
1807 first_function_block_is_cold
= true;
1810 in_cold_section_p
= first_function_block_is_cold
;
1812 /* Switch to the correct text section for the start of the function. */
1814 switch_to_section (function_section (decl
));
1815 if (flag_reorder_blocks_and_partition
1816 && !hot_label_written
)
1817 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_label
);
1819 /* Tell assembler to move to target machine's alignment for functions. */
1820 align
= floor_log2 (DECL_ALIGN (decl
) / BITS_PER_UNIT
);
1823 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
1826 /* Handle a user-specified function alignment.
1827 Note that we still need to align to DECL_ALIGN, as above,
1828 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1829 if (! DECL_USER_ALIGN (decl
)
1830 && align_functions_log
> align
1831 && optimize_function_for_speed_p (cfun
))
1833 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1834 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file
,
1835 align_functions_log
, align_functions
- 1);
1837 ASM_OUTPUT_ALIGN (asm_out_file
, align_functions_log
);
1841 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1842 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file
, fnname
);
1845 if (!DECL_IGNORED_P (decl
))
1846 (*debug_hooks
->begin_function
) (decl
);
1848 /* Make function name accessible from other files, if appropriate. */
1850 if (TREE_PUBLIC (decl
))
1852 notice_global_symbol (decl
);
1854 globalize_decl (decl
);
1856 maybe_assemble_visibility (decl
);
1859 if (DECL_PRESERVE_P (decl
))
1860 targetm
.asm_out
.mark_decl_preserved (fnname
);
1862 /* Do any machine/system dependent processing of the function name. */
1863 #ifdef ASM_DECLARE_FUNCTION_NAME
1864 ASM_DECLARE_FUNCTION_NAME (asm_out_file
, fnname
, current_function_decl
);
1866 /* Standard thing is just output label for the function. */
1867 ASM_OUTPUT_LABEL (asm_out_file
, fnname
);
1868 #endif /* ASM_DECLARE_FUNCTION_NAME */
1871 /* Output assembler code associated with defining the size of the
1872 function. DECL describes the function. NAME is the function's name. */
1875 assemble_end_function (tree decl
, const char *fnname ATTRIBUTE_UNUSED
)
1877 #ifdef ASM_DECLARE_FUNCTION_SIZE
1878 /* We could have switched section in the middle of the function. */
1879 if (flag_reorder_blocks_and_partition
)
1880 switch_to_section (function_section (decl
));
1881 ASM_DECLARE_FUNCTION_SIZE (asm_out_file
, fnname
, decl
);
1883 if (! CONSTANT_POOL_BEFORE_FUNCTION
)
1885 output_constant_pool (fnname
, decl
);
1886 switch_to_section (function_section (decl
)); /* need to switch back */
1888 /* Output labels for end of hot/cold text sections (to be used by
1890 if (flag_reorder_blocks_and_partition
)
1892 section
*save_text_section
;
1894 save_text_section
= in_section
;
1895 switch_to_section (unlikely_text_section ());
1896 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.cold_section_end_label
);
1897 if (first_function_block_is_cold
)
1898 switch_to_section (text_section
);
1900 switch_to_section (function_section (decl
));
1901 ASM_OUTPUT_LABEL (asm_out_file
, crtl
->subsections
.hot_section_end_label
);
1902 switch_to_section (save_text_section
);
1906 /* Assemble code to leave SIZE bytes of zeros. */
1909 assemble_zeros (unsigned HOST_WIDE_INT size
)
1911 /* Do no output if -fsyntax-only. */
1912 if (flag_syntax_only
)
1915 #ifdef ASM_NO_SKIP_IN_TEXT
1916 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1917 so we must output 0s explicitly in the text section. */
1918 if (ASM_NO_SKIP_IN_TEXT
&& (in_section
->common
.flags
& SECTION_CODE
) != 0)
1920 unsigned HOST_WIDE_INT i
;
1921 for (i
= 0; i
< size
; i
++)
1922 assemble_integer (const0_rtx
, 1, BITS_PER_UNIT
, 1);
1927 ASM_OUTPUT_SKIP (asm_out_file
, size
);
1930 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1933 assemble_align (int align
)
1935 if (align
> BITS_PER_UNIT
)
1937 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
1941 /* Assemble a string constant with the specified C string as contents. */
1944 assemble_string (const char *p
, int size
)
1949 /* If the string is very long, split it up. */
1953 int thissize
= size
- pos
;
1954 if (thissize
> maximum
)
1957 ASM_OUTPUT_ASCII (asm_out_file
, p
, thissize
);
1965 /* A noswitch_section_callback for lcomm_section. */
1968 emit_local (tree decl ATTRIBUTE_UNUSED
,
1969 const char *name ATTRIBUTE_UNUSED
,
1970 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1971 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1973 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1974 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, decl
, name
,
1975 size
, DECL_ALIGN (decl
));
1977 #elif defined ASM_OUTPUT_ALIGNED_LOCAL
1978 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
1981 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
1986 /* A noswitch_section_callback for bss_noswitch_section. */
1988 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
1990 emit_bss (tree decl ATTRIBUTE_UNUSED
,
1991 const char *name ATTRIBUTE_UNUSED
,
1992 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
1993 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
1995 #if defined ASM_OUTPUT_ALIGNED_BSS
1996 ASM_OUTPUT_ALIGNED_BSS (asm_out_file
, decl
, name
, size
, DECL_ALIGN (decl
));
1999 ASM_OUTPUT_BSS (asm_out_file
, decl
, name
, size
, rounded
);
2005 /* A noswitch_section_callback for comm_section. */
2008 emit_common (tree decl ATTRIBUTE_UNUSED
,
2009 const char *name ATTRIBUTE_UNUSED
,
2010 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2011 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2013 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2014 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file
, decl
, name
,
2015 size
, DECL_ALIGN (decl
));
2017 #elif defined ASM_OUTPUT_ALIGNED_COMMON
2018 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file
, name
, size
, DECL_ALIGN (decl
));
2021 ASM_OUTPUT_COMMON (asm_out_file
, name
, size
, rounded
);
2026 /* A noswitch_section_callback for tls_comm_section. */
2029 emit_tls_common (tree decl ATTRIBUTE_UNUSED
,
2030 const char *name ATTRIBUTE_UNUSED
,
2031 unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED
,
2032 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
)
2034 #ifdef ASM_OUTPUT_TLS_COMMON
2035 ASM_OUTPUT_TLS_COMMON (asm_out_file
, decl
, name
, size
);
2038 sorry ("thread-local COMMON data not implemented");
2043 /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2044 NAME is the name of DECL's SYMBOL_REF. */
2047 assemble_noswitch_variable (tree decl
, const char *name
, section
*sect
)
2049 unsigned HOST_WIDE_INT size
, rounded
;
2051 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
2054 /* Don't allocate zero bytes of common,
2055 since that means "undefined external" in the linker. */
2059 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2060 so that each uninitialized object starts on such a boundary. */
2061 rounded
+= (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1;
2062 rounded
= (rounded
/ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2063 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2065 if (!sect
->noswitch
.callback (decl
, name
, size
, rounded
)
2066 && (unsigned HOST_WIDE_INT
) DECL_ALIGN_UNIT (decl
) > rounded
)
2067 warning (0, "requested alignment for %q+D is greater than "
2068 "implemented alignment of %wu", decl
, rounded
);
2071 /* A subroutine of assemble_variable. Output the label and contents of
2072 DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2073 is as for assemble_variable. */
2076 assemble_variable_contents (tree decl
, const char *name
,
2077 bool dont_output_data
)
2079 /* Do any machine/system dependent processing of the object. */
2080 #ifdef ASM_DECLARE_OBJECT_NAME
2081 last_assemble_variable_decl
= decl
;
2082 ASM_DECLARE_OBJECT_NAME (asm_out_file
, name
, decl
);
2084 /* Standard thing is just output label for the object. */
2085 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2086 #endif /* ASM_DECLARE_OBJECT_NAME */
2088 if (!dont_output_data
)
2090 if (DECL_INITIAL (decl
)
2091 && DECL_INITIAL (decl
) != error_mark_node
2092 && !initializer_zerop (DECL_INITIAL (decl
)))
2093 /* Output the actual data. */
2094 output_constant (DECL_INITIAL (decl
),
2095 tree_low_cst (DECL_SIZE_UNIT (decl
), 1),
2098 /* Leave space for it. */
2099 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl
), 1));
2103 /* Initialize emulated tls object TO, which refers to TLS variable
2104 DECL and is initialized by PROXY. */
2107 default_emutls_var_init (tree to
, tree decl
, tree proxy
)
2109 VEC(constructor_elt
,gc
) *v
= VEC_alloc (constructor_elt
, gc
, 4);
2110 constructor_elt
*elt
;
2111 tree type
= TREE_TYPE (to
);
2112 tree field
= TYPE_FIELDS (type
);
2114 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2116 elt
->value
= fold_convert (TREE_TYPE (field
), DECL_SIZE_UNIT (decl
));
2118 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2119 field
= TREE_CHAIN (field
);
2121 elt
->value
= build_int_cst (TREE_TYPE (field
),
2122 DECL_ALIGN_UNIT (decl
));
2124 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2125 field
= TREE_CHAIN (field
);
2127 elt
->value
= null_pointer_node
;
2129 elt
= VEC_quick_push (constructor_elt
, v
, NULL
);
2130 field
= TREE_CHAIN (field
);
2134 return build_constructor (type
, v
);
2137 /* Assemble everything that is needed for a variable or function declaration.
2138 Not used for automatic variables, and not used for function definitions.
2139 Should not be called for variables of incomplete structure type.
2141 TOP_LEVEL is nonzero if this variable has file scope.
2142 AT_END is nonzero if this is the special handling, at end of compilation,
2143 to define things that have had only tentative definitions.
2144 DONT_OUTPUT_DATA if nonzero means don't actually output the
2145 initial value (that will be done by the caller). */
2148 assemble_variable (tree decl
, int top_level ATTRIBUTE_UNUSED
,
2149 int at_end ATTRIBUTE_UNUSED
, int dont_output_data
)
2152 rtx decl_rtl
, symbol
;
2155 if (! targetm
.have_tls
2156 && TREE_CODE (decl
) == VAR_DECL
2157 && DECL_THREAD_LOCAL_P (decl
))
2159 tree to
= emutls_decl (decl
);
2161 /* If this variable is defined locally, then we need to initialize the
2162 control structure with size and alignment information. We do this
2163 at the last moment because tentative definitions can take a locally
2164 defined but uninitialized variable and initialize it later, which
2165 would result in incorrect contents. */
2166 if (! DECL_EXTERNAL (to
)
2167 && (! DECL_COMMON (to
)
2168 || (DECL_INITIAL (decl
)
2169 && DECL_INITIAL (decl
) != error_mark_node
)))
2171 DECL_INITIAL (to
) = targetm
.emutls
.var_init
2172 (to
, decl
, get_emutls_init_templ_addr (decl
));
2174 /* Make sure the template is marked as needed early enough.
2175 Without this, if the variable is placed in a
2176 section-anchored block, the template will only be marked
2177 when it's too late. */
2178 record_references_in_initializer (to
, false);
2184 last_assemble_variable_decl
= 0;
2186 /* Normally no need to say anything here for external references,
2187 since assemble_external is called by the language-specific code
2188 when a declaration is first seen. */
2190 if (DECL_EXTERNAL (decl
))
2193 /* Output no assembler code for a function declaration.
2194 Only definitions of functions output anything. */
2196 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2199 /* Do nothing for global register variables. */
2200 if (DECL_RTL_SET_P (decl
) && REG_P (DECL_RTL (decl
)))
2202 TREE_ASM_WRITTEN (decl
) = 1;
2206 /* If type was incomplete when the variable was declared,
2207 see if it is complete now. */
2209 if (DECL_SIZE (decl
) == 0)
2210 layout_decl (decl
, 0);
2212 /* Still incomplete => don't allocate it; treat the tentative defn
2213 (which is what it must have been) as an `extern' reference. */
2215 if (!dont_output_data
&& DECL_SIZE (decl
) == 0)
2217 error ("storage size of %q+D isn%'t known", decl
);
2218 TREE_ASM_WRITTEN (decl
) = 1;
2222 /* The first declaration of a variable that comes through this function
2223 decides whether it is global (in C, has external linkage)
2224 or local (in C, has internal linkage). So do nothing more
2225 if this function has already run. */
2227 if (TREE_ASM_WRITTEN (decl
))
2230 /* Make sure targetm.encode_section_info is invoked before we set
2232 decl_rtl
= DECL_RTL (decl
);
2234 TREE_ASM_WRITTEN (decl
) = 1;
2236 /* Do no output if -fsyntax-only. */
2237 if (flag_syntax_only
)
2240 if (! dont_output_data
2241 && ! host_integerp (DECL_SIZE_UNIT (decl
), 1))
2243 error ("size of variable %q+D is too large", decl
);
2247 gcc_assert (MEM_P (decl_rtl
));
2248 gcc_assert (GET_CODE (XEXP (decl_rtl
, 0)) == SYMBOL_REF
);
2249 symbol
= XEXP (decl_rtl
, 0);
2251 /* If this symbol belongs to the tree constant pool, output the constant
2252 if it hasn't already been written. */
2253 if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
2255 tree decl
= SYMBOL_REF_DECL (symbol
);
2256 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
2257 output_constant_def_contents (symbol
);
2263 name
= XSTR (symbol
, 0);
2264 if (TREE_PUBLIC (decl
) && DECL_NAME (decl
))
2265 notice_global_symbol (decl
);
2267 /* Compute the alignment of this data. */
2269 align_variable (decl
, dont_output_data
);
2270 set_mem_align (decl_rtl
, DECL_ALIGN (decl
));
2272 if (TREE_PUBLIC (decl
))
2273 maybe_assemble_visibility (decl
);
2275 if (DECL_PRESERVE_P (decl
))
2276 targetm
.asm_out
.mark_decl_preserved (name
);
2278 /* First make the assembler name(s) global if appropriate. */
2279 sect
= get_variable_section (decl
, false);
2280 if (TREE_PUBLIC (decl
)
2281 && (sect
->common
.flags
& SECTION_COMMON
) == 0)
2282 globalize_decl (decl
);
2284 /* Output any data that we will need to use the address of. */
2285 if (DECL_INITIAL (decl
) && DECL_INITIAL (decl
) != error_mark_node
)
2286 output_addressed_constants (DECL_INITIAL (decl
));
2288 /* dbxout.c needs to know this. */
2289 if (sect
&& (sect
->common
.flags
& SECTION_CODE
) != 0)
2290 DECL_IN_TEXT_SECTION (decl
) = 1;
2292 /* If the decl is part of an object_block, make sure that the decl
2293 has been positioned within its block, but do not write out its
2294 definition yet. output_object_blocks will do that later. */
2295 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
2297 gcc_assert (!dont_output_data
);
2298 place_block_symbol (symbol
);
2300 else if (SECTION_STYLE (sect
) == SECTION_NOSWITCH
)
2301 assemble_noswitch_variable (decl
, name
, sect
);
2304 switch_to_section (sect
);
2305 if (DECL_ALIGN (decl
) > BITS_PER_UNIT
)
2306 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (DECL_ALIGN_UNIT (decl
)));
2307 assemble_variable_contents (decl
, name
, dont_output_data
);
2311 /* Return 1 if type TYPE contains any pointers. */
2314 contains_pointers_p (tree type
)
2316 switch (TREE_CODE (type
))
2319 case REFERENCE_TYPE
:
2320 /* I'm not sure whether OFFSET_TYPE needs this treatment,
2321 so I'll play safe and return 1. */
2327 case QUAL_UNION_TYPE
:
2330 /* For a type that has fields, see if the fields have pointers. */
2331 for (fields
= TYPE_FIELDS (type
); fields
; fields
= TREE_CHAIN (fields
))
2332 if (TREE_CODE (fields
) == FIELD_DECL
2333 && contains_pointers_p (TREE_TYPE (fields
)))
2339 /* An array type contains pointers if its element type does. */
2340 return contains_pointers_p (TREE_TYPE (type
));
2347 /* We delay assemble_external processing until
2348 the compilation unit is finalized. This is the best we can do for
2349 right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2350 it all the way to final. See PR 17982 for further discussion. */
2351 static GTY(()) tree pending_assemble_externals
;
2353 #ifdef ASM_OUTPUT_EXTERNAL
2354 /* True if DECL is a function decl for which no out-of-line copy exists.
2355 It is assumed that DECL's assembler name has been set. */
2358 incorporeal_function_p (tree decl
)
2360 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_BUILT_IN (decl
))
2364 if (DECL_BUILT_IN_CLASS (decl
) == BUILT_IN_NORMAL
2365 && DECL_FUNCTION_CODE (decl
) == BUILT_IN_ALLOCA
)
2368 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
2369 if (is_builtin_name (name
))
2375 /* Actually do the tests to determine if this is necessary, and invoke
2376 ASM_OUTPUT_EXTERNAL. */
2378 assemble_external_real (tree decl
)
2380 rtx rtl
= DECL_RTL (decl
);
2382 if (MEM_P (rtl
) && GET_CODE (XEXP (rtl
, 0)) == SYMBOL_REF
2383 && !SYMBOL_REF_USED (XEXP (rtl
, 0))
2384 && !incorporeal_function_p (decl
))
2386 /* Some systems do require some output. */
2387 SYMBOL_REF_USED (XEXP (rtl
, 0)) = 1;
2388 ASM_OUTPUT_EXTERNAL (asm_out_file
, decl
, XSTR (XEXP (rtl
, 0), 0));
2394 process_pending_assemble_externals (void)
2396 #ifdef ASM_OUTPUT_EXTERNAL
2398 for (list
= pending_assemble_externals
; list
; list
= TREE_CHAIN (list
))
2399 assemble_external_real (TREE_VALUE (list
));
2401 pending_assemble_externals
= 0;
2405 /* This TREE_LIST contains any weak symbol declarations waiting
2407 static GTY(()) tree weak_decls
;
2409 /* Output something to declare an external symbol to the assembler,
2410 and qualifiers such as weakness. (Most assemblers don't need
2411 extern declaration, so we normally output nothing.) Do nothing if
2412 DECL is not external. */
2415 assemble_external (tree decl ATTRIBUTE_UNUSED
)
2417 /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the
2418 main body of this code is only rarely exercised. To provide some
2419 testing, on all platforms, we make sure that the ASM_OUT_FILE is
2420 open. If it's not, we should not be calling this function. */
2421 gcc_assert (asm_out_file
);
2423 if (!DECL_P (decl
) || !DECL_EXTERNAL (decl
) || !TREE_PUBLIC (decl
))
2426 /* We want to output annotation for weak and external symbols at
2427 very last to check if they are references or not. */
2431 /* TREE_STATIC is a weird and abused creature which is not
2432 generally the right test for whether an entity has been
2433 locally emitted, inlined or otherwise not-really-extern, but
2434 for declarations that can be weak, it happens to be
2436 && !TREE_STATIC (decl
)
2437 && lookup_attribute ("weak", DECL_ATTRIBUTES (decl
))
2438 && value_member (decl
, weak_decls
) == NULL_TREE
)
2439 weak_decls
= tree_cons (NULL
, decl
, weak_decls
);
2441 #ifdef ASM_OUTPUT_EXTERNAL
2442 if (value_member (decl
, pending_assemble_externals
) == NULL_TREE
)
2443 pending_assemble_externals
= tree_cons (NULL
, decl
,
2444 pending_assemble_externals
);
2448 /* Similar, for calling a library function FUN. */
2451 assemble_external_libcall (rtx fun
)
2453 /* Declare library function name external when first used, if nec. */
2454 if (! SYMBOL_REF_USED (fun
))
2456 SYMBOL_REF_USED (fun
) = 1;
2457 targetm
.asm_out
.external_libcall (fun
);
2461 /* Assemble a label named NAME. */
2464 assemble_label (const char *name
)
2466 ASM_OUTPUT_LABEL (asm_out_file
, name
);
2469 /* Set the symbol_referenced flag for ID. */
2471 mark_referenced (tree id
)
2473 TREE_SYMBOL_REFERENCED (id
) = 1;
2476 /* Set the symbol_referenced flag for DECL and notify callgraph. */
2478 mark_decl_referenced (tree decl
)
2480 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2482 /* Extern inline functions don't become needed when referenced.
2483 If we know a method will be emitted in other TU and no new
2484 functions can be marked reachable, just use the external
2486 struct cgraph_node
*node
= cgraph_node (decl
);
2487 if (!DECL_EXTERNAL (decl
)
2488 && (!node
->local
.vtable_method
|| !cgraph_global_info_ready
2489 || !node
->local
.finalized
))
2490 cgraph_mark_needed_node (node
);
2492 else if (TREE_CODE (decl
) == VAR_DECL
)
2494 struct varpool_node
*node
= varpool_node (decl
);
2495 varpool_mark_needed_node (node
);
2496 /* C++ frontend use mark_decl_references to force COMDAT variables
2497 to be output that might appear dead otherwise. */
2498 node
->force_output
= true;
2500 /* else do nothing - we can get various sorts of CST nodes here,
2501 which do not need to be marked. */
2505 /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
2506 until we find an identifier that is not itself a transparent alias.
2507 Modify the alias passed to it by reference (and all aliases on the
2508 way to the ultimate target), such that they do not have to be
2509 followed again, and return the ultimate target of the alias
2513 ultimate_transparent_alias_target (tree
*alias
)
2515 tree target
= *alias
;
2517 if (IDENTIFIER_TRANSPARENT_ALIAS (target
))
2519 gcc_assert (TREE_CHAIN (target
));
2520 target
= ultimate_transparent_alias_target (&TREE_CHAIN (target
));
2521 gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target
)
2522 && ! TREE_CHAIN (target
));
2529 /* Output to FILE (an assembly file) a reference to NAME. If NAME
2530 starts with a *, the rest of NAME is output verbatim. Otherwise
2531 NAME is transformed in a target-specific way (usually by the
2532 addition of an underscore). */
2535 assemble_name_raw (FILE *file
, const char *name
)
2538 fputs (&name
[1], file
);
2540 ASM_OUTPUT_LABELREF (file
, name
);
2543 /* Like assemble_name_raw, but should be used when NAME might refer to
2544 an entity that is also represented as a tree (like a function or
2545 variable). If NAME does refer to such an entity, that entity will
2546 be marked as referenced. */
2549 assemble_name (FILE *file
, const char *name
)
2551 const char *real_name
;
2554 real_name
= targetm
.strip_name_encoding (name
);
2556 id
= maybe_get_identifier (real_name
);
2561 mark_referenced (id
);
2562 ultimate_transparent_alias_target (&id
);
2564 name
= IDENTIFIER_POINTER (id
);
2565 gcc_assert (! TREE_CHAIN (id
));
2568 assemble_name_raw (file
, name
);
2571 /* Allocate SIZE bytes writable static space with a gensym name
2572 and return an RTX to refer to its address. */
2575 assemble_static_space (unsigned HOST_WIDE_INT size
)
2578 const char *namestring
;
2581 ASM_GENERATE_INTERNAL_LABEL (name
, "LF", const_labelno
);
2583 namestring
= ggc_strdup (name
);
2585 x
= gen_rtx_SYMBOL_REF (Pmode
, namestring
);
2586 SYMBOL_REF_FLAGS (x
) = SYMBOL_FLAG_LOCAL
;
2588 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2589 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file
, NULL_TREE
, name
, size
,
2592 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2593 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file
, name
, size
, BIGGEST_ALIGNMENT
);
2596 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2597 so that each uninitialized object starts on such a boundary. */
2598 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2599 unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2600 = ((size
+ (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
) - 1)
2601 / (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
)
2602 * (BIGGEST_ALIGNMENT
/ BITS_PER_UNIT
));
2603 ASM_OUTPUT_LOCAL (asm_out_file
, name
, size
, rounded
);
2610 /* Assemble the static constant template for function entry trampolines.
2611 This is done at most once per compilation.
2612 Returns an RTX for the address of the template. */
2614 static GTY(()) rtx initial_trampoline
;
2617 assemble_trampoline_template (void)
2624 gcc_assert (targetm
.asm_out
.trampoline_template
!= NULL
);
2626 if (initial_trampoline
)
2627 return initial_trampoline
;
2629 /* By default, put trampoline templates in read-only data section. */
2631 #ifdef TRAMPOLINE_SECTION
2632 switch_to_section (TRAMPOLINE_SECTION
);
2634 switch_to_section (readonly_data_section
);
2637 /* Write the assembler code to define one. */
2638 align
= floor_log2 (TRAMPOLINE_ALIGNMENT
/ BITS_PER_UNIT
);
2640 ASM_OUTPUT_ALIGN (asm_out_file
, align
);
2642 targetm
.asm_out
.internal_label (asm_out_file
, "LTRAMP", 0);
2643 targetm
.asm_out
.trampoline_template (asm_out_file
);
2645 /* Record the rtl to refer to it. */
2646 ASM_GENERATE_INTERNAL_LABEL (label
, "LTRAMP", 0);
2647 name
= ggc_strdup (label
);
2648 symbol
= gen_rtx_SYMBOL_REF (Pmode
, name
);
2649 SYMBOL_REF_FLAGS (symbol
) = SYMBOL_FLAG_LOCAL
;
2651 initial_trampoline
= gen_const_mem (BLKmode
, symbol
);
2652 set_mem_align (initial_trampoline
, TRAMPOLINE_ALIGNMENT
);
2653 set_mem_size (initial_trampoline
, GEN_INT (TRAMPOLINE_SIZE
));
2655 return initial_trampoline
;
2658 /* A and B are either alignments or offsets. Return the minimum alignment
2659 that may be assumed after adding the two together. */
2661 static inline unsigned
2662 min_align (unsigned int a
, unsigned int b
)
2664 return (a
| b
) & -(a
| b
);
2667 /* Return the assembler directive for creating a given kind of integer
2668 object. SIZE is the number of bytes in the object and ALIGNED_P
2669 indicates whether it is known to be aligned. Return NULL if the
2670 assembly dialect has no such directive.
2672 The returned string should be printed at the start of a new line and
2673 be followed immediately by the object's initial value. */
2676 integer_asm_op (int size
, int aligned_p
)
2678 struct asm_int_op
*ops
;
2681 ops
= &targetm
.asm_out
.aligned_op
;
2683 ops
= &targetm
.asm_out
.unaligned_op
;
2688 return targetm
.asm_out
.byte_op
;
2702 /* Use directive OP to assemble an integer object X. Print OP at the
2703 start of the line, followed immediately by the value of X. */
2706 assemble_integer_with_op (const char *op
, rtx x
)
2708 fputs (op
, asm_out_file
);
2709 output_addr_const (asm_out_file
, x
);
2710 fputc ('\n', asm_out_file
);
2713 /* The default implementation of the asm_out.integer target hook. */
2716 default_assemble_integer (rtx x ATTRIBUTE_UNUSED
,
2717 unsigned int size ATTRIBUTE_UNUSED
,
2718 int aligned_p ATTRIBUTE_UNUSED
)
2720 const char *op
= integer_asm_op (size
, aligned_p
);
2721 /* Avoid GAS bugs for large values. Specifically negative values whose
2722 absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
2723 if (size
> UNITS_PER_WORD
&& size
> POINTER_SIZE
/ BITS_PER_UNIT
)
2725 return op
&& (assemble_integer_with_op (op
, x
), true);
2728 /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
2729 the alignment of the integer in bits. Return 1 if we were able to output
2730 the constant, otherwise 0. We must be able to output the constant,
2731 if FORCE is nonzero. */
2734 assemble_integer (rtx x
, unsigned int size
, unsigned int align
, int force
)
2738 aligned_p
= (align
>= MIN (size
* BITS_PER_UNIT
, BIGGEST_ALIGNMENT
));
2740 /* See if the target hook can handle this kind of object. */
2741 if (targetm
.asm_out
.integer (x
, size
, aligned_p
))
2744 /* If the object is a multi-byte one, try splitting it up. Split
2745 it into words it if is multi-word, otherwise split it into bytes. */
2748 enum machine_mode omode
, imode
;
2749 unsigned int subalign
;
2750 unsigned int subsize
, i
;
2751 enum mode_class mclass
;
2753 subsize
= size
> UNITS_PER_WORD
? UNITS_PER_WORD
: 1;
2754 subalign
= MIN (align
, subsize
* BITS_PER_UNIT
);
2755 if (GET_CODE (x
) == CONST_FIXED
)
2756 mclass
= GET_MODE_CLASS (GET_MODE (x
));
2760 omode
= mode_for_size (subsize
* BITS_PER_UNIT
, mclass
, 0);
2761 imode
= mode_for_size (size
* BITS_PER_UNIT
, mclass
, 0);
2763 for (i
= 0; i
< size
; i
+= subsize
)
2765 rtx partial
= simplify_subreg (omode
, x
, imode
, i
);
2766 if (!partial
|| !assemble_integer (partial
, subsize
, subalign
, 0))
2772 /* If we've printed some of it, but not all of it, there's no going
2777 gcc_assert (!force
);
2783 assemble_real (REAL_VALUE_TYPE d
, enum machine_mode mode
, unsigned int align
)
2785 long data
[4] = {0, 0, 0, 0};
2787 int bitsize
, nelts
, nunits
, units_per
;
2789 /* This is hairy. We have a quantity of known size. real_to_target
2790 will put it into an array of *host* longs, 32 bits per element
2791 (even if long is more than 32 bits). We need to determine the
2792 number of array elements that are occupied (nelts) and the number
2793 of *target* min-addressable units that will be occupied in the
2794 object file (nunits). We cannot assume that 32 divides the
2795 mode's bitsize (size * BITS_PER_UNIT) evenly.
2797 size * BITS_PER_UNIT is used here to make sure that padding bits
2798 (which might appear at either end of the value; real_to_target
2799 will include the padding bits in its output array) are included. */
2801 nunits
= GET_MODE_SIZE (mode
);
2802 bitsize
= nunits
* BITS_PER_UNIT
;
2803 nelts
= CEIL (bitsize
, 32);
2804 units_per
= 32 / BITS_PER_UNIT
;
2806 real_to_target (data
, &d
, mode
);
2808 /* Put out the first word with the specified alignment. */
2809 assemble_integer (GEN_INT (data
[0]), MIN (nunits
, units_per
), align
, 1);
2810 nunits
-= units_per
;
2812 /* Subsequent words need only 32-bit alignment. */
2813 align
= min_align (align
, 32);
2815 for (i
= 1; i
< nelts
; i
++)
2817 assemble_integer (GEN_INT (data
[i
]), MIN (nunits
, units_per
), align
, 1);
2818 nunits
-= units_per
;
2822 /* Given an expression EXP with a constant value,
2823 reduce it to the sum of an assembler symbol and an integer.
2824 Store them both in the structure *VALUE.
2825 EXP must be reducible. */
2827 struct GTY(()) addr_const
{
2829 HOST_WIDE_INT offset
;
2833 decode_addr_const (tree exp
, struct addr_const
*value
)
2835 tree target
= TREE_OPERAND (exp
, 0);
2841 if (TREE_CODE (target
) == COMPONENT_REF
2842 && host_integerp (byte_position (TREE_OPERAND (target
, 1)), 0))
2844 offset
+= int_byte_position (TREE_OPERAND (target
, 1));
2845 target
= TREE_OPERAND (target
, 0);
2847 else if (TREE_CODE (target
) == ARRAY_REF
2848 || TREE_CODE (target
) == ARRAY_RANGE_REF
)
2850 offset
+= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target
)), 1)
2851 * tree_low_cst (TREE_OPERAND (target
, 1), 0));
2852 target
= TREE_OPERAND (target
, 0);
2854 else if (TREE_CODE (target
) == INDIRECT_REF
2855 && TREE_CODE (TREE_OPERAND (target
, 0)) == NOP_EXPR
2856 && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target
, 0), 0))
2858 target
= TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target
, 0), 0), 0);
2863 switch (TREE_CODE (target
))
2867 x
= DECL_RTL (target
);
2871 x
= gen_rtx_MEM (FUNCTION_MODE
,
2872 gen_rtx_LABEL_REF (Pmode
, force_label_rtx (target
)));
2881 x
= output_constant_def (target
, 1);
2888 gcc_assert (MEM_P (x
));
2892 value
->offset
= offset
;
2896 static GTY((param_is (struct constant_descriptor_tree
)))
2897 htab_t const_desc_htab
;
2899 static void maybe_output_constant_def_contents (struct constant_descriptor_tree
*, int);
2901 /* Constant pool accessor function. */
2904 constant_pool_htab (void)
2906 return const_desc_htab
;
2909 /* Compute a hash code for a constant expression. */
2912 const_desc_hash (const void *ptr
)
2914 return ((const struct constant_descriptor_tree
*)ptr
)->hash
;
2918 const_hash_1 (const tree exp
)
2923 enum tree_code code
= TREE_CODE (exp
);
2925 /* Either set P and LEN to the address and len of something to hash and
2926 exit the switch or return a value. */
2931 p
= (char *) &TREE_INT_CST (exp
);
2932 len
= sizeof TREE_INT_CST (exp
);
2936 return real_hash (TREE_REAL_CST_PTR (exp
));
2939 return fixed_hash (TREE_FIXED_CST_PTR (exp
));
2942 p
= TREE_STRING_POINTER (exp
);
2943 len
= TREE_STRING_LENGTH (exp
);
2947 return (const_hash_1 (TREE_REALPART (exp
)) * 5
2948 + const_hash_1 (TREE_IMAGPART (exp
)));
2954 hi
= 7 + TYPE_VECTOR_SUBPARTS (TREE_TYPE (exp
));
2956 for (link
= TREE_VECTOR_CST_ELTS (exp
); link
; link
= TREE_CHAIN (link
))
2957 hi
= hi
* 563 + const_hash_1 (TREE_VALUE (link
));
2964 unsigned HOST_WIDE_INT idx
;
2967 hi
= 5 + int_size_in_bytes (TREE_TYPE (exp
));
2969 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, value
)
2971 hi
= hi
* 603 + const_hash_1 (value
);
2979 struct addr_const value
;
2981 decode_addr_const (exp
, &value
);
2982 switch (GET_CODE (value
.base
))
2985 /* Don't hash the address of the SYMBOL_REF;
2986 only use the offset and the symbol name. */
2988 p
= XSTR (value
.base
, 0);
2989 for (i
= 0; p
[i
] != 0; i
++)
2990 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
2994 hi
= value
.offset
+ CODE_LABEL_NUMBER (XEXP (value
.base
, 0)) * 13;
3004 case POINTER_PLUS_EXPR
:
3006 return (const_hash_1 (TREE_OPERAND (exp
, 0)) * 9
3007 + const_hash_1 (TREE_OPERAND (exp
, 1)));
3010 return const_hash_1 (TREE_OPERAND (exp
, 0)) * 7 + 2;
3013 /* A language specific constant. Just hash the code. */
3017 /* Compute hashing function. */
3019 for (i
= 0; i
< len
; i
++)
3020 hi
= ((hi
* 613) + (unsigned) (p
[i
]));
3025 /* Wrapper of compare_constant, for the htab interface. */
3027 const_desc_eq (const void *p1
, const void *p2
)
3029 const struct constant_descriptor_tree
*const c1
3030 = (const struct constant_descriptor_tree
*) p1
;
3031 const struct constant_descriptor_tree
*const c2
3032 = (const struct constant_descriptor_tree
*) p2
;
3033 if (c1
->hash
!= c2
->hash
)
3035 return compare_constant (c1
->value
, c2
->value
);
3038 /* Compare t1 and t2, and return 1 only if they are known to result in
3039 the same bit pattern on output. */
3042 compare_constant (const tree t1
, const tree t2
)
3044 enum tree_code typecode
;
3046 if (t1
== NULL_TREE
)
3047 return t2
== NULL_TREE
;
3048 if (t2
== NULL_TREE
)
3051 if (TREE_CODE (t1
) != TREE_CODE (t2
))
3054 switch (TREE_CODE (t1
))
3057 /* Integer constants are the same only if the same width of type. */
3058 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3060 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3062 return tree_int_cst_equal (t1
, t2
);
3065 /* Real constants are the same only if the same width of type. */
3066 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3069 return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1
), TREE_REAL_CST (t2
));
3072 /* Fixed constants are the same only if the same width of type. */
3073 if (TYPE_PRECISION (TREE_TYPE (t1
)) != TYPE_PRECISION (TREE_TYPE (t2
)))
3076 return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1
), TREE_FIXED_CST (t2
));
3079 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
)))
3082 return (TREE_STRING_LENGTH (t1
) == TREE_STRING_LENGTH (t2
)
3083 && ! memcmp (TREE_STRING_POINTER (t1
), TREE_STRING_POINTER (t2
),
3084 TREE_STRING_LENGTH (t1
)));
3087 return (compare_constant (TREE_REALPART (t1
), TREE_REALPART (t2
))
3088 && compare_constant (TREE_IMAGPART (t1
), TREE_IMAGPART (t2
)));
3094 if (TYPE_VECTOR_SUBPARTS (TREE_TYPE (t1
))
3095 != TYPE_VECTOR_SUBPARTS (TREE_TYPE (t2
)))
3098 link2
= TREE_VECTOR_CST_ELTS (t2
);
3099 for (link1
= TREE_VECTOR_CST_ELTS (t1
);
3101 link1
= TREE_CHAIN (link1
))
3103 if (!compare_constant (TREE_VALUE (link1
), TREE_VALUE (link2
)))
3105 link2
= TREE_CHAIN (link2
);
3113 VEC(constructor_elt
, gc
) *v1
, *v2
;
3114 unsigned HOST_WIDE_INT idx
;
3116 typecode
= TREE_CODE (TREE_TYPE (t1
));
3117 if (typecode
!= TREE_CODE (TREE_TYPE (t2
)))
3120 if (typecode
== ARRAY_TYPE
)
3122 HOST_WIDE_INT size_1
= int_size_in_bytes (TREE_TYPE (t1
));
3123 /* For arrays, check that the sizes all match. */
3124 if (TYPE_MODE (TREE_TYPE (t1
)) != TYPE_MODE (TREE_TYPE (t2
))
3126 || size_1
!= int_size_in_bytes (TREE_TYPE (t2
)))
3131 /* For record and union constructors, require exact type
3133 if (TREE_TYPE (t1
) != TREE_TYPE (t2
))
3137 v1
= CONSTRUCTOR_ELTS (t1
);
3138 v2
= CONSTRUCTOR_ELTS (t2
);
3139 if (VEC_length (constructor_elt
, v1
)
3140 != VEC_length (constructor_elt
, v2
))
3143 for (idx
= 0; idx
< VEC_length (constructor_elt
, v1
); ++idx
)
3145 constructor_elt
*c1
= VEC_index (constructor_elt
, v1
, idx
);
3146 constructor_elt
*c2
= VEC_index (constructor_elt
, v2
, idx
);
3148 /* Check that each value is the same... */
3149 if (!compare_constant (c1
->value
, c2
->value
))
3151 /* ... and that they apply to the same fields! */
3152 if (typecode
== ARRAY_TYPE
)
3154 if (!compare_constant (c1
->index
, c2
->index
))
3159 if (c1
->index
!= c2
->index
)
3170 struct addr_const value1
, value2
;
3174 decode_addr_const (t1
, &value1
);
3175 decode_addr_const (t2
, &value2
);
3177 if (value1
.offset
!= value2
.offset
)
3180 code
= GET_CODE (value1
.base
);
3181 if (code
!= GET_CODE (value2
.base
))
3187 ret
= (strcmp (XSTR (value1
.base
, 0), XSTR (value2
.base
, 0)) == 0);
3191 ret
= (CODE_LABEL_NUMBER (XEXP (value1
.base
, 0))
3192 == CODE_LABEL_NUMBER (XEXP (value2
.base
, 0)));
3202 case POINTER_PLUS_EXPR
:
3205 return (compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0))
3206 && compare_constant(TREE_OPERAND (t1
, 1), TREE_OPERAND (t2
, 1)));
3209 case VIEW_CONVERT_EXPR
:
3210 return compare_constant (TREE_OPERAND (t1
, 0), TREE_OPERAND (t2
, 0));
3219 /* Make a copy of the whole tree structure for a constant. This
3220 handles the same types of nodes that compare_constant handles. */
3223 copy_constant (tree exp
)
3225 switch (TREE_CODE (exp
))
3228 /* For ADDR_EXPR, we do not want to copy the decl whose address
3229 is requested. We do want to copy constants though. */
3230 if (CONSTANT_CLASS_P (TREE_OPERAND (exp
, 0)))
3231 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3232 copy_constant (TREE_OPERAND (exp
, 0)));
3234 return copy_node (exp
);
3240 return copy_node (exp
);
3243 return build_complex (TREE_TYPE (exp
),
3244 copy_constant (TREE_REALPART (exp
)),
3245 copy_constant (TREE_IMAGPART (exp
)));
3248 case POINTER_PLUS_EXPR
:
3250 return build2 (TREE_CODE (exp
), TREE_TYPE (exp
),
3251 copy_constant (TREE_OPERAND (exp
, 0)),
3252 copy_constant (TREE_OPERAND (exp
, 1)));
3255 case VIEW_CONVERT_EXPR
:
3256 return build1 (TREE_CODE (exp
), TREE_TYPE (exp
),
3257 copy_constant (TREE_OPERAND (exp
, 0)));
3260 return build_vector (TREE_TYPE (exp
),
3261 copy_list (TREE_VECTOR_CST_ELTS (exp
)));
3265 tree copy
= copy_node (exp
);
3266 VEC(constructor_elt
, gc
) *v
;
3267 unsigned HOST_WIDE_INT idx
;
3268 tree purpose
, value
;
3270 v
= VEC_alloc(constructor_elt
, gc
, VEC_length(constructor_elt
,
3271 CONSTRUCTOR_ELTS (exp
)));
3272 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp
), idx
, purpose
, value
)
3274 constructor_elt
*ce
= VEC_quick_push (constructor_elt
, v
, NULL
);
3275 ce
->index
= purpose
;
3276 ce
->value
= copy_constant (value
);
3278 CONSTRUCTOR_ELTS (copy
) = v
;
3287 /* Return the section into which constant EXP should be placed. */
3290 get_constant_section (tree exp
, unsigned int align
)
3292 return targetm
.asm_out
.select_section (exp
,
3293 compute_reloc_for_constant (exp
),
3297 /* Return the size of constant EXP in bytes. */
3299 static HOST_WIDE_INT
3300 get_constant_size (tree exp
)
3304 size
= int_size_in_bytes (TREE_TYPE (exp
));
3305 if (TREE_CODE (exp
) == STRING_CST
)
3306 size
= MAX (TREE_STRING_LENGTH (exp
), size
);
3310 /* Subroutine of output_constant_def:
3311 No constant equal to EXP is known to have been output.
3312 Make a constant descriptor to enter EXP in the hash table.
3313 Assign the label number and construct RTL to refer to the
3314 constant's location in memory.
3315 Caller is responsible for updating the hash table. */
3317 static struct constant_descriptor_tree
*
3318 build_constant_desc (tree exp
)
3320 struct constant_descriptor_tree
*desc
;
3326 desc
= ggc_alloc_constant_descriptor_tree ();
3327 desc
->value
= copy_constant (exp
);
3329 /* Propagate marked-ness to copied constant. */
3330 if (flag_mudflap
&& mf_marked_p (exp
))
3331 mf_mark (desc
->value
);
3333 /* Create a string containing the label name, in LABEL. */
3334 labelno
= const_labelno
++;
3335 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", labelno
);
3337 /* Construct the VAR_DECL associated with the constant. */
3338 decl
= build_decl (UNKNOWN_LOCATION
, VAR_DECL
, get_identifier (label
),
3340 DECL_ARTIFICIAL (decl
) = 1;
3341 DECL_IGNORED_P (decl
) = 1;
3342 TREE_READONLY (decl
) = 1;
3343 TREE_STATIC (decl
) = 1;
3344 TREE_ADDRESSABLE (decl
) = 1;
3345 /* We don't set the RTL yet as this would cause varpool to assume that the
3346 variable is referenced. Moreover, it would just be dropped in LTO mode.
3347 Instead we set the flag that will be recognized in make_decl_rtl. */
3348 DECL_IN_CONSTANT_POOL (decl
) = 1;
3349 DECL_INITIAL (decl
) = desc
->value
;
3350 /* ??? CONSTANT_ALIGNMENT hasn't been updated for vector types on most
3351 architectures so use DATA_ALIGNMENT as well, except for strings. */
3352 if (TREE_CODE (exp
) == STRING_CST
)
3354 #ifdef CONSTANT_ALIGNMENT
3355 DECL_ALIGN (decl
) = CONSTANT_ALIGNMENT (exp
, DECL_ALIGN (decl
));
3359 align_variable (decl
, 0);
3361 /* Now construct the SYMBOL_REF and the MEM. */
3362 if (use_object_blocks_p ())
3364 section
*sect
= get_constant_section (exp
, DECL_ALIGN (decl
));
3365 symbol
= create_block_symbol (ggc_strdup (label
),
3366 get_block_for_section (sect
), -1);
3369 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3370 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3371 SET_SYMBOL_REF_DECL (symbol
, decl
);
3372 TREE_CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3374 rtl
= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp
)), symbol
);
3375 set_mem_attributes (rtl
, exp
, 1);
3376 set_mem_alias_set (rtl
, 0);
3377 set_mem_alias_set (rtl
, const_alias_set
);
3379 /* We cannot share RTX'es in pool entries.
3380 Mark this piece of RTL as required for unsharing. */
3381 RTX_FLAG (rtl
, used
) = 1;
3383 /* Set flags or add text to the name to record information, such as
3384 that it is a local symbol. If the name is changed, the macro
3385 ASM_OUTPUT_LABELREF will have to know how to strip this
3386 information. This call might invalidate our local variable
3387 SYMBOL; we can't use it afterward. */
3388 targetm
.encode_section_info (exp
, rtl
, true);
3395 /* Return an rtx representing a reference to constant data in memory
3396 for the constant expression EXP.
3398 If assembler code for such a constant has already been output,
3399 return an rtx to refer to it.
3400 Otherwise, output such a constant in memory
3401 and generate an rtx for it.
3403 If DEFER is nonzero, this constant can be deferred and output only
3404 if referenced in the function after all optimizations.
3406 `const_desc_table' records which constants already have label strings. */
3409 output_constant_def (tree exp
, int defer
)
3411 struct constant_descriptor_tree
*desc
;
3412 struct constant_descriptor_tree key
;
3415 /* Look up EXP in the table of constant descriptors. If we didn't find
3416 it, create a new one. */
3418 key
.hash
= const_hash_1 (exp
);
3419 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3421 desc
= (struct constant_descriptor_tree
*) *loc
;
3424 desc
= build_constant_desc (exp
);
3425 desc
->hash
= key
.hash
;
3429 maybe_output_constant_def_contents (desc
, defer
);
3433 /* Subroutine of output_constant_def: Decide whether or not we need to
3434 output the constant DESC now, and if so, do it. */
3436 maybe_output_constant_def_contents (struct constant_descriptor_tree
*desc
,
3439 rtx symbol
= XEXP (desc
->rtl
, 0);
3440 tree exp
= desc
->value
;
3442 if (flag_syntax_only
)
3445 if (TREE_ASM_WRITTEN (exp
))
3446 /* Already output; don't do it again. */
3449 /* We can always defer constants as long as the context allows
3453 /* Increment n_deferred_constants if it exists. It needs to be at
3454 least as large as the number of constants actually referred to
3455 by the function. If it's too small we'll stop looking too early
3456 and fail to emit constants; if it's too large we'll only look
3457 through the entire function when we could have stopped earlier. */
3459 n_deferred_constants
++;
3463 output_constant_def_contents (symbol
);
3466 /* Subroutine of output_constant_def_contents. Output the definition
3467 of constant EXP, which is pointed to by label LABEL. ALIGN is the
3468 constant's alignment in bits. */
3471 assemble_constant_contents (tree exp
, const char *label
, unsigned int align
)
3475 size
= get_constant_size (exp
);
3477 /* Do any machine/system dependent processing of the constant. */
3478 #ifdef ASM_DECLARE_CONSTANT_NAME
3479 ASM_DECLARE_CONSTANT_NAME (asm_out_file
, label
, exp
, size
);
3481 /* Standard thing is just output label for the constant. */
3482 ASM_OUTPUT_LABEL (asm_out_file
, label
);
3483 #endif /* ASM_DECLARE_CONSTANT_NAME */
3485 /* Output the value of EXP. */
3486 output_constant (exp
, size
, align
);
3489 /* We must output the constant data referred to by SYMBOL; do so. */
3492 output_constant_def_contents (rtx symbol
)
3494 tree decl
= SYMBOL_REF_DECL (symbol
);
3495 tree exp
= DECL_INITIAL (decl
);
3498 /* Make sure any other constants whose addresses appear in EXP
3499 are assigned label numbers. */
3500 output_addressed_constants (exp
);
3502 /* We are no longer deferring this constant. */
3503 TREE_ASM_WRITTEN (exp
) = 1;
3505 /* If the constant is part of an object block, make sure that the
3506 decl has been positioned within its block, but do not write out
3507 its definition yet. output_object_blocks will do that later. */
3508 if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol
) && SYMBOL_REF_BLOCK (symbol
))
3509 place_block_symbol (symbol
);
3512 align
= DECL_ALIGN (decl
);
3513 switch_to_section (get_constant_section (exp
, align
));
3514 if (align
> BITS_PER_UNIT
)
3515 ASM_OUTPUT_ALIGN (asm_out_file
, floor_log2 (align
/ BITS_PER_UNIT
));
3516 assemble_constant_contents (exp
, XSTR (symbol
, 0), align
);
3519 mudflap_enqueue_constant (exp
);
3522 /* Look up EXP in the table of constant descriptors. Return the rtl
3523 if it has been emitted, else null. */
3526 lookup_constant_def (tree exp
)
3528 struct constant_descriptor_tree
*desc
;
3529 struct constant_descriptor_tree key
;
3532 key
.hash
= const_hash_1 (exp
);
3533 desc
= (struct constant_descriptor_tree
*)
3534 htab_find_with_hash (const_desc_htab
, &key
, key
.hash
);
3536 return (desc
? desc
->rtl
: NULL_RTX
);
3539 /* Return a tree representing a reference to constant data in memory
3540 for the constant expression EXP.
3542 This is the counterpart of output_constant_def at the Tree level. */
3545 tree_output_constant_def (tree exp
)
3547 struct constant_descriptor_tree
*desc
, key
;
3551 /* Look up EXP in the table of constant descriptors. If we didn't find
3552 it, create a new one. */
3554 key
.hash
= const_hash_1 (exp
);
3555 loc
= htab_find_slot_with_hash (const_desc_htab
, &key
, key
.hash
, INSERT
);
3557 desc
= (struct constant_descriptor_tree
*) *loc
;
3560 desc
= build_constant_desc (exp
);
3561 desc
->hash
= key
.hash
;
3565 decl
= SYMBOL_REF_DECL (XEXP (desc
->rtl
, 0));
3566 varpool_finalize_decl (decl
);
3570 /* Used in the hash tables to avoid outputting the same constant
3571 twice. Unlike 'struct constant_descriptor_tree', RTX constants
3572 are output once per function, not once per file. */
3573 /* ??? Only a few targets need per-function constant pools. Most
3574 can use one per-file pool. Should add a targetm bit to tell the
3577 struct GTY(()) rtx_constant_pool
{
3578 /* Pointers to first and last constant in pool, as ordered by offset. */
3579 struct constant_descriptor_rtx
*first
;
3580 struct constant_descriptor_rtx
*last
;
3582 /* Hash facility for making memory-constants from constant rtl-expressions.
3583 It is used on RISC machines where immediate integer arguments and
3584 constant addresses are restricted so that such constants must be stored
3586 htab_t
GTY((param_is (struct constant_descriptor_rtx
))) const_rtx_htab
;
3588 /* Current offset in constant pool (does not include any
3589 machine-specific header). */
3590 HOST_WIDE_INT offset
;
3593 struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx
{
3594 struct constant_descriptor_rtx
*next
;
3598 HOST_WIDE_INT offset
;
3600 enum machine_mode mode
;
3606 /* Hash and compare functions for const_rtx_htab. */
3609 const_desc_rtx_hash (const void *ptr
)
3611 const struct constant_descriptor_rtx
*const desc
3612 = (const struct constant_descriptor_rtx
*) ptr
;
3617 const_desc_rtx_eq (const void *a
, const void *b
)
3619 const struct constant_descriptor_rtx
*const x
3620 = (const struct constant_descriptor_rtx
*) a
;
3621 const struct constant_descriptor_rtx
*const y
3622 = (const struct constant_descriptor_rtx
*) b
;
3624 if (x
->mode
!= y
->mode
)
3626 return rtx_equal_p (x
->constant
, y
->constant
);
3629 /* This is the worker function for const_rtx_hash, called via for_each_rtx. */
3632 const_rtx_hash_1 (rtx
*xp
, void *data
)
3634 unsigned HOST_WIDE_INT hwi
;
3635 enum machine_mode mode
;
3641 code
= GET_CODE (x
);
3642 mode
= GET_MODE (x
);
3643 h
= (hashval_t
) code
* 1048573 + mode
;
3651 int shift
= sizeof (hashval_t
) * CHAR_BIT
;
3652 const int n
= sizeof (HOST_WIDE_INT
) / sizeof (hashval_t
);
3655 h
^= (hashval_t
) hwi
;
3656 for (i
= 1; i
< n
; ++i
)
3659 h
^= (hashval_t
) hwi
;
3665 if (mode
== VOIDmode
)
3667 hwi
= CONST_DOUBLE_LOW (x
) ^ CONST_DOUBLE_HIGH (x
);
3671 h
^= real_hash (CONST_DOUBLE_REAL_VALUE (x
));
3675 h
^= fixed_hash (CONST_FIXED_VALUE (x
));
3681 for (i
= XVECLEN (x
, 0); i
-- > 0; )
3682 h
= h
* 251 + const_rtx_hash_1 (&XVECEXP (x
, 0, i
), data
);
3687 h
^= htab_hash_string (XSTR (x
, 0));
3691 h
= h
* 251 + CODE_LABEL_NUMBER (XEXP (x
, 0));
3695 case UNSPEC_VOLATILE
:
3696 h
= h
* 251 + XINT (x
, 1);
3703 hp
= (hashval_t
*) data
;
3704 *hp
= *hp
* 509 + h
;
3708 /* Compute a hash value for X, which should be a constant. */
3711 const_rtx_hash (rtx x
)
3714 for_each_rtx (&x
, const_rtx_hash_1
, &h
);
3719 /* Create and return a new rtx constant pool. */
3721 static struct rtx_constant_pool
*
3722 create_constant_pool (void)
3724 struct rtx_constant_pool
*pool
;
3726 pool
= ggc_alloc_rtx_constant_pool ();
3727 pool
->const_rtx_htab
= htab_create_ggc (31, const_desc_rtx_hash
,
3728 const_desc_rtx_eq
, NULL
);
3735 /* Initialize constant pool hashing for a new function. */
3738 init_varasm_status (void)
3740 crtl
->varasm
.pool
= create_constant_pool ();
3741 crtl
->varasm
.deferred_constants
= 0;
3744 /* Given a MINUS expression, simplify it if both sides
3745 include the same symbol. */
3748 simplify_subtraction (rtx x
)
3750 rtx r
= simplify_rtx (x
);
3754 /* Given a constant rtx X, make (or find) a memory constant for its value
3755 and return a MEM rtx to refer to it in memory. */
3758 force_const_mem (enum machine_mode mode
, rtx x
)
3760 struct constant_descriptor_rtx
*desc
, tmp
;
3761 struct rtx_constant_pool
*pool
;
3768 /* If we're not allowed to drop X into the constant pool, don't. */
3769 if (targetm
.cannot_force_const_mem (x
))
3772 /* Record that this function has used a constant pool entry. */
3773 crtl
->uses_const_pool
= 1;
3775 /* Decide which pool to use. */
3776 pool
= (targetm
.use_blocks_for_constant_p (mode
, x
)
3777 ? shared_constant_pool
3778 : crtl
->varasm
.pool
);
3780 /* Lookup the value in the hashtable. */
3783 hash
= const_rtx_hash (x
);
3784 slot
= htab_find_slot_with_hash (pool
->const_rtx_htab
, &tmp
, hash
, INSERT
);
3785 desc
= (struct constant_descriptor_rtx
*) *slot
;
3787 /* If the constant was already present, return its memory. */
3789 return copy_rtx (desc
->mem
);
3791 /* Otherwise, create a new descriptor. */
3792 desc
= ggc_alloc_constant_descriptor_rtx ();
3795 /* Align the location counter as required by EXP's data type. */
3796 align
= GET_MODE_ALIGNMENT (mode
== VOIDmode
? word_mode
: mode
);
3797 #ifdef CONSTANT_ALIGNMENT
3799 tree type
= lang_hooks
.types
.type_for_mode (mode
, 0);
3800 if (type
!= NULL_TREE
)
3801 align
= CONSTANT_ALIGNMENT (make_tree (type
, x
), align
);
3805 pool
->offset
+= (align
/ BITS_PER_UNIT
) - 1;
3806 pool
->offset
&= ~ ((align
/ BITS_PER_UNIT
) - 1);
3809 desc
->constant
= tmp
.constant
;
3810 desc
->offset
= pool
->offset
;
3813 desc
->align
= align
;
3814 desc
->labelno
= const_labelno
;
3817 pool
->offset
+= GET_MODE_SIZE (mode
);
3819 pool
->last
->next
= desc
;
3821 pool
->first
= pool
->last
= desc
;
3824 /* Create a string containing the label name, in LABEL. */
3825 ASM_GENERATE_INTERNAL_LABEL (label
, "LC", const_labelno
);
3828 /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
3829 the constants pool. */
3830 if (use_object_blocks_p () && targetm
.use_blocks_for_constant_p (mode
, x
))
3832 section
*sect
= targetm
.asm_out
.select_rtx_section (mode
, x
, align
);
3833 symbol
= create_block_symbol (ggc_strdup (label
),
3834 get_block_for_section (sect
), -1);
3837 symbol
= gen_rtx_SYMBOL_REF (Pmode
, ggc_strdup (label
));
3839 SYMBOL_REF_FLAGS (symbol
) |= SYMBOL_FLAG_LOCAL
;
3840 CONSTANT_POOL_ADDRESS_P (symbol
) = 1;
3841 SET_SYMBOL_REF_CONSTANT (symbol
, desc
);
3843 /* Construct the MEM. */
3844 desc
->mem
= def
= gen_const_mem (mode
, symbol
);
3845 set_mem_attributes (def
, lang_hooks
.types
.type_for_mode (mode
, 0), 1);
3846 set_mem_align (def
, align
);
3848 /* If we're dropping a label to the constant pool, make sure we
3850 if (GET_CODE (x
) == LABEL_REF
)
3851 LABEL_PRESERVE_P (XEXP (x
, 0)) = 1;
3853 return copy_rtx (def
);
3856 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3859 get_pool_constant (rtx addr
)
3861 return SYMBOL_REF_CONSTANT (addr
)->constant
;
3864 /* Given a constant pool SYMBOL_REF, return the corresponding constant
3865 and whether it has been output or not. */
3868 get_pool_constant_mark (rtx addr
, bool *pmarked
)
3870 struct constant_descriptor_rtx
*desc
;
3872 desc
= SYMBOL_REF_CONSTANT (addr
);
3873 *pmarked
= (desc
->mark
!= 0);
3874 return desc
->constant
;
3877 /* Similar, return the mode. */
3880 get_pool_mode (const_rtx addr
)
3882 return SYMBOL_REF_CONSTANT (addr
)->mode
;
3885 /* Return the size of the constant pool. */
3888 get_pool_size (void)
3890 return crtl
->varasm
.pool
->offset
;
3893 /* Worker function for output_constant_pool_1. Emit assembly for X
3894 in MODE with known alignment ALIGN. */
3897 output_constant_pool_2 (enum machine_mode mode
, rtx x
, unsigned int align
)
3899 switch (GET_MODE_CLASS (mode
))
3902 case MODE_DECIMAL_FLOAT
:
3906 gcc_assert (GET_CODE (x
) == CONST_DOUBLE
);
3907 REAL_VALUE_FROM_CONST_DOUBLE (r
, x
);
3908 assemble_real (r
, mode
, align
);
3913 case MODE_PARTIAL_INT
:
3918 assemble_integer (x
, GET_MODE_SIZE (mode
), align
, 1);
3921 case MODE_VECTOR_FLOAT
:
3922 case MODE_VECTOR_INT
:
3923 case MODE_VECTOR_FRACT
:
3924 case MODE_VECTOR_UFRACT
:
3925 case MODE_VECTOR_ACCUM
:
3926 case MODE_VECTOR_UACCUM
:
3929 enum machine_mode submode
= GET_MODE_INNER (mode
);
3930 unsigned int subalign
= MIN (align
, GET_MODE_BITSIZE (submode
));
3932 gcc_assert (GET_CODE (x
) == CONST_VECTOR
);
3933 units
= CONST_VECTOR_NUNITS (x
);
3935 for (i
= 0; i
< units
; i
++)
3937 rtx elt
= CONST_VECTOR_ELT (x
, i
);
3938 output_constant_pool_2 (submode
, elt
, i
? subalign
: align
);
3948 /* Worker function for output_constant_pool. Emit constant DESC,
3949 giving it ALIGN bits of alignment. */
3952 output_constant_pool_1 (struct constant_descriptor_rtx
*desc
,
3959 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3960 whose CODE_LABEL has been deleted. This can occur if a jump table
3961 is eliminated by optimization. If so, write a constant of zero
3962 instead. Note that this can also happen by turning the
3963 CODE_LABEL into a NOTE. */
3964 /* ??? This seems completely and utterly wrong. Certainly it's
3965 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3966 functioning even with INSN_DELETED_P and friends. */
3969 switch (GET_CODE (tmp
))
3972 if (GET_CODE (XEXP (tmp
, 0)) != PLUS
3973 || GET_CODE (XEXP (XEXP (tmp
, 0), 0)) != LABEL_REF
)
3975 tmp
= XEXP (XEXP (tmp
, 0), 0);
3979 tmp
= XEXP (tmp
, 0);
3980 gcc_assert (!INSN_DELETED_P (tmp
));
3981 gcc_assert (!NOTE_P (tmp
)
3982 || NOTE_KIND (tmp
) != NOTE_INSN_DELETED
);
3989 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3990 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file
, x
, desc
->mode
,
3991 align
, desc
->labelno
, done
);
3994 assemble_align (align
);
3996 /* Output the label. */
3997 targetm
.asm_out
.internal_label (asm_out_file
, "LC", desc
->labelno
);
3999 /* Output the data. */
4000 output_constant_pool_2 (desc
->mode
, x
, align
);
4002 /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4003 sections have proper size. */
4004 if (align
> GET_MODE_BITSIZE (desc
->mode
)
4006 && (in_section
->common
.flags
& SECTION_MERGE
))
4007 assemble_align (align
);
4009 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4015 /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers
4016 to as used. Emit referenced deferred strings. This function can
4017 be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */
4020 mark_constant (rtx
*current_rtx
, void *data ATTRIBUTE_UNUSED
)
4022 rtx x
= *current_rtx
;
4024 if (x
== NULL_RTX
|| GET_CODE (x
) != SYMBOL_REF
)
4027 if (CONSTANT_POOL_ADDRESS_P (x
))
4029 struct constant_descriptor_rtx
*desc
= SYMBOL_REF_CONSTANT (x
);
4030 if (desc
->mark
== 0)
4033 for_each_rtx (&desc
->constant
, mark_constant
, NULL
);
4036 else if (TREE_CONSTANT_POOL_ADDRESS_P (x
))
4038 tree decl
= SYMBOL_REF_DECL (x
);
4039 if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl
)))
4041 n_deferred_constants
--;
4042 output_constant_def_contents (x
);
4049 /* Look through appropriate parts of INSN, marking all entries in the
4050 constant pool which are actually being used. Entries that are only
4051 referenced by other constants are also marked as used. Emit
4052 deferred strings that are used. */
4055 mark_constants (rtx insn
)
4060 /* Insns may appear inside a SEQUENCE. Only check the patterns of
4061 insns, not any notes that may be attached. We don't want to mark
4062 a constant just because it happens to appear in a REG_EQUIV note. */
4063 if (GET_CODE (PATTERN (insn
)) == SEQUENCE
)
4065 rtx seq
= PATTERN (insn
);
4066 int i
, n
= XVECLEN (seq
, 0);
4067 for (i
= 0; i
< n
; ++i
)
4069 rtx subinsn
= XVECEXP (seq
, 0, i
);
4070 if (INSN_P (subinsn
))
4071 for_each_rtx (&PATTERN (subinsn
), mark_constant
, NULL
);
4075 for_each_rtx (&PATTERN (insn
), mark_constant
, NULL
);
4078 /* Look through the instructions for this function, and mark all the
4079 entries in POOL which are actually being used. Emit deferred constants
4080 which have indeed been used. */
4083 mark_constant_pool (void)
4087 if (!crtl
->uses_const_pool
&& n_deferred_constants
== 0)
4090 for (insn
= get_insns (); insn
; insn
= NEXT_INSN (insn
))
4091 mark_constants (insn
);
4093 for (link
= crtl
->epilogue_delay_list
;
4095 link
= XEXP (link
, 1))
4096 mark_constants (XEXP (link
, 0));
4099 /* Write all the constants in POOL. */
4102 output_constant_pool_contents (struct rtx_constant_pool
*pool
)
4104 struct constant_descriptor_rtx
*desc
;
4106 for (desc
= pool
->first
; desc
; desc
= desc
->next
)
4109 /* If the constant is part of an object_block, make sure that
4110 the constant has been positioned within its block, but do not
4111 write out its definition yet. output_object_blocks will do
4113 if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc
->sym
)
4114 && SYMBOL_REF_BLOCK (desc
->sym
))
4115 place_block_symbol (desc
->sym
);
4118 switch_to_section (targetm
.asm_out
.select_rtx_section
4119 (desc
->mode
, desc
->constant
, desc
->align
));
4120 output_constant_pool_1 (desc
, desc
->align
);
4125 /* Mark all constants that are used in the current function, then write
4126 out the function's private constant pool. */
4129 output_constant_pool (const char *fnname ATTRIBUTE_UNUSED
,
4130 tree fndecl ATTRIBUTE_UNUSED
)
4132 struct rtx_constant_pool
*pool
= crtl
->varasm
.pool
;
4134 /* It is possible for gcc to call force_const_mem and then to later
4135 discard the instructions which refer to the constant. In such a
4136 case we do not need to output the constant. */
4137 mark_constant_pool ();
4139 #ifdef ASM_OUTPUT_POOL_PROLOGUE
4140 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4143 output_constant_pool_contents (pool
);
4145 #ifdef ASM_OUTPUT_POOL_EPILOGUE
4146 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file
, fnname
, fndecl
, pool
->offset
);
4150 /* Write the contents of the shared constant pool. */
4153 output_shared_constant_pool (void)
4155 output_constant_pool_contents (shared_constant_pool
);
4158 /* Determine what kind of relocations EXP may need. */
4161 compute_reloc_for_constant (tree exp
)
4163 int reloc
= 0, reloc2
;
4166 switch (TREE_CODE (exp
))
4170 /* Go inside any operations that get_inner_reference can handle and see
4171 if what's inside is a constant: no need to do anything here for
4172 addresses of variables or functions. */
4173 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4174 tem
= TREE_OPERAND (tem
, 0))
4177 if (TREE_PUBLIC (tem
))
4184 case POINTER_PLUS_EXPR
:
4185 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4186 reloc
|= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4190 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4191 reloc2
= compute_reloc_for_constant (TREE_OPERAND (exp
, 1));
4192 /* The difference of two local labels is computable at link time. */
4193 if (reloc
== 1 && reloc2
== 1)
4200 case VIEW_CONVERT_EXPR
:
4201 reloc
= compute_reloc_for_constant (TREE_OPERAND (exp
, 0));
4206 unsigned HOST_WIDE_INT idx
;
4207 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4209 reloc
|= compute_reloc_for_constant (tem
);
4219 /* Find all the constants whose addresses are referenced inside of EXP,
4220 and make sure assembler code with a label has been output for each one.
4221 Indicate whether an ADDR_EXPR has been encountered. */
4224 output_addressed_constants (tree exp
)
4228 switch (TREE_CODE (exp
))
4232 /* Go inside any operations that get_inner_reference can handle and see
4233 if what's inside is a constant: no need to do anything here for
4234 addresses of variables or functions. */
4235 for (tem
= TREE_OPERAND (exp
, 0); handled_component_p (tem
);
4236 tem
= TREE_OPERAND (tem
, 0))
4239 /* If we have an initialized CONST_DECL, retrieve the initializer. */
4240 if (TREE_CODE (tem
) == CONST_DECL
&& DECL_INITIAL (tem
))
4241 tem
= DECL_INITIAL (tem
);
4243 if (CONSTANT_CLASS_P (tem
) || TREE_CODE (tem
) == CONSTRUCTOR
)
4244 output_constant_def (tem
, 0);
4248 case POINTER_PLUS_EXPR
:
4250 output_addressed_constants (TREE_OPERAND (exp
, 1));
4254 case VIEW_CONVERT_EXPR
:
4255 output_addressed_constants (TREE_OPERAND (exp
, 0));
4260 unsigned HOST_WIDE_INT idx
;
4261 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp
), idx
, tem
)
4263 output_addressed_constants (tem
);
4272 /* Whether a constructor CTOR is a valid static constant initializer if all
4273 its elements are. This used to be internal to initializer_constant_valid_p
4274 and has been exposed to let other functions like categorize_ctor_elements
4275 evaluate the property while walking a constructor for other purposes. */
4278 constructor_static_from_elts_p (const_tree ctor
)
4280 return (TREE_CONSTANT (ctor
)
4281 && (TREE_CODE (TREE_TYPE (ctor
)) == UNION_TYPE
4282 || TREE_CODE (TREE_TYPE (ctor
)) == RECORD_TYPE
)
4283 && !VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (ctor
)));
4286 static tree
initializer_constant_valid_p_1 (tree value
, tree endtype
,
4289 /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4290 PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4291 which are valid when ENDTYPE is an integer of any size; in
4292 particular, this does not accept a pointer minus a constant. This
4293 returns null_pointer_node if the VALUE is an absolute constant
4294 which can be used to initialize a static variable. Otherwise it
4298 narrowing_initializer_constant_valid_p (tree value
, tree endtype
, tree
*cache
)
4302 if (!INTEGRAL_TYPE_P (endtype
))
4305 op0
= TREE_OPERAND (value
, 0);
4306 op1
= TREE_OPERAND (value
, 1);
4308 /* Like STRIP_NOPS except allow the operand mode to widen. This
4309 works around a feature of fold that simplifies (int)(p1 - p2) to
4310 ((int)p1 - (int)p2) under the theory that the narrower operation
4313 while (CONVERT_EXPR_P (op0
)
4314 || TREE_CODE (op0
) == NON_LVALUE_EXPR
)
4316 tree inner
= TREE_OPERAND (op0
, 0);
4317 if (inner
== error_mark_node
4318 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4319 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0
)))
4320 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4325 while (CONVERT_EXPR_P (op1
)
4326 || TREE_CODE (op1
) == NON_LVALUE_EXPR
)
4328 tree inner
= TREE_OPERAND (op1
, 0);
4329 if (inner
== error_mark_node
4330 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner
)))
4331 || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1
)))
4332 > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner
)))))
4337 op0
= initializer_constant_valid_p_1 (op0
, endtype
, cache
);
4341 op1
= initializer_constant_valid_p_1 (op1
, endtype
,
4342 cache
? cache
+ 2 : NULL
);
4343 /* Both initializers must be known. */
4347 && (op0
== null_pointer_node
4348 || TREE_CODE (value
) == MINUS_EXPR
))
4349 return null_pointer_node
;
4351 /* Support differences between labels. */
4352 if (TREE_CODE (op0
) == LABEL_DECL
4353 && TREE_CODE (op1
) == LABEL_DECL
)
4354 return null_pointer_node
;
4356 if (TREE_CODE (op0
) == STRING_CST
4357 && TREE_CODE (op1
) == STRING_CST
4358 && operand_equal_p (op0
, op1
, 1))
4359 return null_pointer_node
;
4365 /* Helper function of initializer_constant_valid_p.
4366 Return nonzero if VALUE is a valid constant-valued expression
4367 for use in initializing a static variable; one that can be an
4368 element of a "constant" initializer.
4370 Return null_pointer_node if the value is absolute;
4371 if it is relocatable, return the variable that determines the relocation.
4372 We assume that VALUE has been folded as much as possible;
4373 therefore, we do not need to check for such things as
4374 arithmetic-combinations of integers.
4376 Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4379 initializer_constant_valid_p_1 (tree value
, tree endtype
, tree
*cache
)
4383 switch (TREE_CODE (value
))
4386 if (constructor_static_from_elts_p (value
))
4388 unsigned HOST_WIDE_INT idx
;
4390 bool absolute
= true;
4392 if (cache
&& cache
[0] == value
)
4394 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4397 reloc
= initializer_constant_valid_p_1 (elt
, TREE_TYPE (elt
),
4404 cache
[1] = NULL_TREE
;
4408 if (reloc
!= null_pointer_node
)
4411 /* For a non-absolute relocation, there is no single
4412 variable that can be "the variable that determines the
4417 cache
[1] = absolute
? null_pointer_node
: error_mark_node
;
4419 return absolute
? null_pointer_node
: error_mark_node
;
4422 return TREE_STATIC (value
) ? null_pointer_node
: NULL_TREE
;
4430 return null_pointer_node
;
4435 tree op0
= staticp (TREE_OPERAND (value
, 0));
4438 /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
4439 to be a constant, this is old-skool offsetof-like nonsense. */
4440 if (TREE_CODE (op0
) == INDIRECT_REF
4441 && TREE_CONSTANT (TREE_OPERAND (op0
, 0)))
4442 return null_pointer_node
;
4443 /* Taking the address of a nested function involves a trampoline,
4444 unless we don't need or want one. */
4445 if (TREE_CODE (op0
) == FUNCTION_DECL
4446 && DECL_STATIC_CHAIN (op0
)
4447 && !TREE_NO_TRAMPOLINE (value
))
4449 /* "&{...}" requires a temporary to hold the constructed
4451 if (TREE_CODE (op0
) == CONSTRUCTOR
)
4457 case NON_LVALUE_EXPR
:
4458 return initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4461 case VIEW_CONVERT_EXPR
:
4463 tree src
= TREE_OPERAND (value
, 0);
4464 tree src_type
= TREE_TYPE (src
);
4465 tree dest_type
= TREE_TYPE (value
);
4467 /* Allow view-conversions from aggregate to non-aggregate type only
4468 if the bit pattern is fully preserved afterwards; otherwise, the
4469 RTL expander won't be able to apply a subsequent transformation
4470 to the underlying constructor. */
4471 if (AGGREGATE_TYPE_P (src_type
) && !AGGREGATE_TYPE_P (dest_type
))
4473 if (TYPE_MODE (endtype
) == TYPE_MODE (dest_type
))
4474 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4479 /* Allow all other kinds of view-conversion. */
4480 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4485 tree src
= TREE_OPERAND (value
, 0);
4486 tree src_type
= TREE_TYPE (src
);
4487 tree dest_type
= TREE_TYPE (value
);
4489 /* Allow conversions between pointer types, floating-point
4490 types, and offset types. */
4491 if ((POINTER_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
))
4492 || (FLOAT_TYPE_P (dest_type
) && FLOAT_TYPE_P (src_type
))
4493 || (TREE_CODE (dest_type
) == OFFSET_TYPE
4494 && TREE_CODE (src_type
) == OFFSET_TYPE
))
4495 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4497 /* Allow length-preserving conversions between integer types. */
4498 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
)
4499 && (TYPE_PRECISION (dest_type
) == TYPE_PRECISION (src_type
)))
4500 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4502 /* Allow conversions between other integer types only if
4504 if (INTEGRAL_TYPE_P (dest_type
) && INTEGRAL_TYPE_P (src_type
))
4506 tree inner
= initializer_constant_valid_p_1 (src
, endtype
, cache
);
4507 if (inner
== null_pointer_node
)
4508 return null_pointer_node
;
4512 /* Allow (int) &foo provided int is as wide as a pointer. */
4513 if (INTEGRAL_TYPE_P (dest_type
) && POINTER_TYPE_P (src_type
)
4514 && (TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
)))
4515 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4517 /* Likewise conversions from int to pointers, but also allow
4518 conversions from 0. */
4519 if ((POINTER_TYPE_P (dest_type
)
4520 || TREE_CODE (dest_type
) == OFFSET_TYPE
)
4521 && INTEGRAL_TYPE_P (src_type
))
4523 if (TREE_CODE (src
) == INTEGER_CST
4524 && TYPE_PRECISION (dest_type
) >= TYPE_PRECISION (src_type
))
4525 return null_pointer_node
;
4526 if (integer_zerop (src
))
4527 return null_pointer_node
;
4528 else if (TYPE_PRECISION (dest_type
) <= TYPE_PRECISION (src_type
))
4529 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4532 /* Allow conversions to struct or union types if the value
4534 if (TREE_CODE (dest_type
) == RECORD_TYPE
4535 || TREE_CODE (dest_type
) == UNION_TYPE
)
4536 return initializer_constant_valid_p_1 (src
, endtype
, cache
);
4540 case POINTER_PLUS_EXPR
:
4542 /* Any valid floating-point constants will have been folded by now;
4543 with -frounding-math we hit this with addition of two constants. */
4544 if (TREE_CODE (endtype
) == REAL_TYPE
)
4546 if (cache
&& cache
[0] == value
)
4548 if (! INTEGRAL_TYPE_P (endtype
)
4549 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4551 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4553 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4556 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4557 endtype
, ncache
+ 2);
4558 /* If either term is absolute, use the other term's relocation. */
4559 if (valid0
== null_pointer_node
)
4561 else if (valid1
== null_pointer_node
)
4563 /* Support narrowing pointer differences. */
4565 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4569 /* Support narrowing pointer differences. */
4570 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4579 if (TREE_CODE (endtype
) == REAL_TYPE
)
4581 if (cache
&& cache
[0] == value
)
4583 if (! INTEGRAL_TYPE_P (endtype
)
4584 || TYPE_PRECISION (endtype
) >= TYPE_PRECISION (TREE_TYPE (value
)))
4586 tree ncache
[4] = { NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
};
4588 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 0),
4591 = initializer_constant_valid_p_1 (TREE_OPERAND (value
, 1),
4592 endtype
, ncache
+ 2);
4593 /* Win if second argument is absolute. */
4594 if (valid1
== null_pointer_node
)
4596 /* Win if both arguments have the same relocation.
4597 Then the value is absolute. */
4598 else if (valid0
== valid1
&& valid0
!= 0)
4599 ret
= null_pointer_node
;
4600 /* Since GCC guarantees that string constants are unique in the
4601 generated code, a subtraction between two copies of the same
4602 constant string is absolute. */
4603 else if (valid0
&& TREE_CODE (valid0
) == STRING_CST
4604 && valid1
&& TREE_CODE (valid1
) == STRING_CST
4605 && operand_equal_p (valid0
, valid1
, 1))
4606 ret
= null_pointer_node
;
4607 /* Support narrowing differences. */
4609 ret
= narrowing_initializer_constant_valid_p (value
, endtype
,
4613 /* Support narrowing differences. */
4614 ret
= narrowing_initializer_constant_valid_p (value
, endtype
, NULL
);
4629 /* Return nonzero if VALUE is a valid constant-valued expression
4630 for use in initializing a static variable; one that can be an
4631 element of a "constant" initializer.
4633 Return null_pointer_node if the value is absolute;
4634 if it is relocatable, return the variable that determines the relocation.
4635 We assume that VALUE has been folded as much as possible;
4636 therefore, we do not need to check for such things as
4637 arithmetic-combinations of integers. */
4639 initializer_constant_valid_p (tree value
, tree endtype
)
4641 return initializer_constant_valid_p_1 (value
, endtype
, NULL
);
4644 /* Return true if VALUE is a valid constant-valued expression
4645 for use in initializing a static bit-field; one that can be
4646 an element of a "constant" initializer. */
4649 initializer_constant_valid_for_bitfield_p (tree value
)
4651 /* For bitfields we support integer constants or possibly nested aggregates
4653 switch (TREE_CODE (value
))
4657 unsigned HOST_WIDE_INT idx
;
4660 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value
), idx
, elt
)
4661 if (!initializer_constant_valid_for_bitfield_p (elt
))
4669 case VIEW_CONVERT_EXPR
:
4670 case NON_LVALUE_EXPR
:
4672 initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value
, 0));
4681 /* output_constructor outer state of relevance in recursive calls, typically
4682 for nested aggregate bitfields. */
4685 unsigned int bit_offset
; /* current position in ... */
4686 int byte
; /* ... the outer byte buffer. */
4689 static unsigned HOST_WIDE_INT
4690 output_constructor (tree
, unsigned HOST_WIDE_INT
, unsigned int,
4693 /* Output assembler code for constant EXP to FILE, with no label.
4694 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4695 Assumes output_addressed_constants has been done on EXP already.
4697 Generate exactly SIZE bytes of assembler data, padding at the end
4698 with zeros if necessary. SIZE must always be specified.
4700 SIZE is important for structure constructors,
4701 since trailing members may have been omitted from the constructor.
4702 It is also important for initialization of arrays from string constants
4703 since the full length of the string constant might not be wanted.
4704 It is also needed for initialization of unions, where the initializer's
4705 type is just one member, and that may not be as long as the union.
4707 There a case in which we would fail to output exactly SIZE bytes:
4708 for a structure constructor that wants to produce more than SIZE bytes.
4709 But such constructors will never be generated for any possible input.
4711 ALIGN is the alignment of the data in bits. */
4714 output_constant (tree exp
, unsigned HOST_WIDE_INT size
, unsigned int align
)
4716 enum tree_code code
;
4717 unsigned HOST_WIDE_INT thissize
;
4719 if (size
== 0 || flag_syntax_only
)
4722 /* See if we're trying to initialize a pointer in a non-default mode
4723 to the address of some declaration somewhere. If the target says
4724 the mode is valid for pointers, assume the target has a way of
4726 if (TREE_CODE (exp
) == NOP_EXPR
4727 && POINTER_TYPE_P (TREE_TYPE (exp
))
4728 && targetm
.addr_space
.valid_pointer_mode
4729 (TYPE_MODE (TREE_TYPE (exp
)),
4730 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4732 tree saved_type
= TREE_TYPE (exp
);
4734 /* Peel off any intermediate conversions-to-pointer for valid
4736 while (TREE_CODE (exp
) == NOP_EXPR
4737 && POINTER_TYPE_P (TREE_TYPE (exp
))
4738 && targetm
.addr_space
.valid_pointer_mode
4739 (TYPE_MODE (TREE_TYPE (exp
)),
4740 TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp
)))))
4741 exp
= TREE_OPERAND (exp
, 0);
4743 /* If what we're left with is the address of something, we can
4744 convert the address to the final type and output it that
4746 if (TREE_CODE (exp
) == ADDR_EXPR
)
4747 exp
= build1 (ADDR_EXPR
, saved_type
, TREE_OPERAND (exp
, 0));
4748 /* Likewise for constant ints. */
4749 else if (TREE_CODE (exp
) == INTEGER_CST
)
4750 exp
= build_int_cst_wide (saved_type
, TREE_INT_CST_LOW (exp
),
4751 TREE_INT_CST_HIGH (exp
));
4755 /* Eliminate any conversions since we'll be outputting the underlying
4757 while (CONVERT_EXPR_P (exp
)
4758 || TREE_CODE (exp
) == NON_LVALUE_EXPR
4759 || TREE_CODE (exp
) == VIEW_CONVERT_EXPR
)
4761 HOST_WIDE_INT type_size
= int_size_in_bytes (TREE_TYPE (exp
));
4762 HOST_WIDE_INT op_size
= int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp
, 0)));
4764 /* Make sure eliminating the conversion is really a no-op, except with
4765 VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
4766 union types to allow for Ada unchecked unions. */
4767 if (type_size
> op_size
4768 && TREE_CODE (exp
) != VIEW_CONVERT_EXPR
4769 && TREE_CODE (TREE_TYPE (exp
)) != UNION_TYPE
)
4770 /* Keep the conversion. */
4773 exp
= TREE_OPERAND (exp
, 0);
4776 code
= TREE_CODE (TREE_TYPE (exp
));
4777 thissize
= int_size_in_bytes (TREE_TYPE (exp
));
4779 /* Allow a constructor with no elements for any data type.
4780 This means to fill the space with zeros. */
4781 if (TREE_CODE (exp
) == CONSTRUCTOR
4782 && VEC_empty (constructor_elt
, CONSTRUCTOR_ELTS (exp
)))
4784 assemble_zeros (size
);
4788 if (TREE_CODE (exp
) == FDESC_EXPR
)
4790 #ifdef ASM_OUTPUT_FDESC
4791 HOST_WIDE_INT part
= tree_low_cst (TREE_OPERAND (exp
, 1), 0);
4792 tree decl
= TREE_OPERAND (exp
, 0);
4793 ASM_OUTPUT_FDESC (asm_out_file
, decl
, part
);
4800 /* Now output the underlying data. If we've handling the padding, return.
4801 Otherwise, break and ensure SIZE is the size written. */
4808 case REFERENCE_TYPE
:
4810 case FIXED_POINT_TYPE
:
4811 if (! assemble_integer (expand_expr (exp
, NULL_RTX
, VOIDmode
,
4812 EXPAND_INITIALIZER
),
4813 MIN (size
, thissize
), align
, 0))
4814 error ("initializer for integer/fixed-point value is too complicated");
4818 if (TREE_CODE (exp
) != REAL_CST
)
4819 error ("initializer for floating value is not a floating constant");
4821 assemble_real (TREE_REAL_CST (exp
), TYPE_MODE (TREE_TYPE (exp
)), align
);
4825 output_constant (TREE_REALPART (exp
), thissize
/ 2, align
);
4826 output_constant (TREE_IMAGPART (exp
), thissize
/ 2,
4827 min_align (align
, BITS_PER_UNIT
* (thissize
/ 2)));
4832 switch (TREE_CODE (exp
))
4835 output_constructor (exp
, size
, align
, NULL
);
4838 thissize
= MIN ((unsigned HOST_WIDE_INT
)TREE_STRING_LENGTH (exp
),
4840 assemble_string (TREE_STRING_POINTER (exp
), thissize
);
4847 unsigned int nalign
;
4848 enum machine_mode inner
;
4850 inner
= TYPE_MODE (TREE_TYPE (TREE_TYPE (exp
)));
4851 nalign
= MIN (align
, GET_MODE_ALIGNMENT (inner
));
4853 elt_size
= GET_MODE_SIZE (inner
);
4855 link
= TREE_VECTOR_CST_ELTS (exp
);
4856 output_constant (TREE_VALUE (link
), elt_size
, align
);
4857 thissize
= elt_size
;
4858 while ((link
= TREE_CHAIN (link
)) != NULL
)
4860 output_constant (TREE_VALUE (link
), elt_size
, nalign
);
4861 thissize
+= elt_size
;
4872 gcc_assert (TREE_CODE (exp
) == CONSTRUCTOR
);
4873 output_constructor (exp
, size
, align
, NULL
);
4883 if (size
> thissize
)
4884 assemble_zeros (size
- thissize
);
4888 /* Subroutine of output_constructor, used for computing the size of
4889 arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
4890 type with an unspecified upper bound. */
4892 static unsigned HOST_WIDE_INT
4893 array_size_for_constructor (tree val
)
4896 unsigned HOST_WIDE_INT cnt
;
4897 tree index
, value
, tmp
;
4899 /* This code used to attempt to handle string constants that are not
4900 arrays of single-bytes, but nothing else does, so there's no point in
4902 if (TREE_CODE (val
) == STRING_CST
)
4903 return TREE_STRING_LENGTH (val
);
4905 max_index
= NULL_TREE
;
4906 FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val
), cnt
, index
, value
)
4908 if (TREE_CODE (index
) == RANGE_EXPR
)
4909 index
= TREE_OPERAND (index
, 1);
4910 if (max_index
== NULL_TREE
|| tree_int_cst_lt (max_index
, index
))
4914 if (max_index
== NULL_TREE
)
4917 /* Compute the total number of array elements. */
4918 tmp
= TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val
)));
4919 i
= size_binop (MINUS_EXPR
, fold_convert (sizetype
, max_index
),
4920 fold_convert (sizetype
, tmp
));
4921 i
= size_binop (PLUS_EXPR
, i
, build_int_cst (sizetype
, 1));
4923 /* Multiply by the array element unit size to find number of bytes. */
4924 i
= size_binop (MULT_EXPR
, i
, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val
))));
4926 return tree_low_cst (i
, 1);
4929 /* Other datastructures + helpers for output_constructor. */
4931 /* output_constructor local state to support interaction with helpers. */
4935 /* Received arguments. */
4936 tree exp
; /* Constructor expression. */
4937 unsigned HOST_WIDE_INT size
; /* # bytes to output - pad if necessary. */
4938 unsigned int align
; /* Known initial alignment. */
4940 /* Constructor expression data. */
4941 tree type
; /* Expression type. */
4942 tree field
; /* Current field decl in a record. */
4943 tree min_index
; /* Lower bound if specified for an array. */
4945 /* Output processing state. */
4946 HOST_WIDE_INT total_bytes
; /* # bytes output so far / current position. */
4947 bool byte_buffer_in_use
; /* Whether byte ... */
4948 int byte
; /* ... contains part of a bitfield byte yet to
4951 int last_relative_index
; /* Implicit or explicit index of the last
4952 array element output within a bitfield. */
4953 /* Current element. */
4954 tree val
; /* Current element value. */
4955 tree index
; /* Current element index. */
4959 /* Helper for output_constructor. From the current LOCAL state, output a
4960 RANGE_EXPR element. */
4963 output_constructor_array_range (oc_local_state
*local
)
4965 unsigned HOST_WIDE_INT fieldsize
4966 = int_size_in_bytes (TREE_TYPE (local
->type
));
4968 HOST_WIDE_INT lo_index
4969 = tree_low_cst (TREE_OPERAND (local
->index
, 0), 0);
4970 HOST_WIDE_INT hi_index
4971 = tree_low_cst (TREE_OPERAND (local
->index
, 1), 0);
4972 HOST_WIDE_INT index
;
4975 = min_align (local
->align
, fieldsize
* BITS_PER_UNIT
);
4977 for (index
= lo_index
; index
<= hi_index
; index
++)
4979 /* Output the element's initial value. */
4980 if (local
->val
== NULL_TREE
)
4981 assemble_zeros (fieldsize
);
4983 output_constant (local
->val
, fieldsize
, align2
);
4985 /* Count its size. */
4986 local
->total_bytes
+= fieldsize
;
4990 /* Helper for output_constructor. From the current LOCAL state, output a
4991 field element that is not true bitfield or part of an outer one. */
4994 output_constructor_regular_field (oc_local_state
*local
)
4996 /* Field size and position. Since this structure is static, we know the
4997 positions are constant. */
4998 unsigned HOST_WIDE_INT fieldsize
;
4999 HOST_WIDE_INT fieldpos
;
5001 unsigned int align2
;
5003 if (local
->index
!= NULL_TREE
)
5004 fieldpos
= (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local
->val
)), 1)
5005 * ((tree_low_cst (local
->index
, 0)
5006 - tree_low_cst (local
->min_index
, 0))));
5007 else if (local
->field
!= NULL_TREE
)
5008 fieldpos
= int_byte_position (local
->field
);
5012 /* Output any buffered-up bit-fields preceding this element. */
5013 if (local
->byte_buffer_in_use
)
5015 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5016 local
->total_bytes
++;
5017 local
->byte_buffer_in_use
= false;
5020 /* Advance to offset of this element.
5021 Note no alignment needed in an array, since that is guaranteed
5022 if each element has the proper size. */
5023 if ((local
->field
!= NULL_TREE
|| local
->index
!= NULL_TREE
)
5024 && fieldpos
!= local
->total_bytes
)
5026 gcc_assert (fieldpos
>= local
->total_bytes
);
5027 assemble_zeros (fieldpos
- local
->total_bytes
);
5028 local
->total_bytes
= fieldpos
;
5031 /* Find the alignment of this element. */
5032 align2
= min_align (local
->align
, BITS_PER_UNIT
* fieldpos
);
5034 /* Determine size this element should occupy. */
5039 /* If this is an array with an unspecified upper bound,
5040 the initializer determines the size. */
5041 /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5042 but we cannot do this until the deprecated support for
5043 initializing zero-length array members is removed. */
5044 if (TREE_CODE (TREE_TYPE (local
->field
)) == ARRAY_TYPE
5045 && TYPE_DOMAIN (TREE_TYPE (local
->field
))
5046 && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local
->field
))))
5048 fieldsize
= array_size_for_constructor (local
->val
);
5049 /* Given a non-empty initialization, this field had
5051 gcc_assert (!fieldsize
|| !TREE_CHAIN (local
->field
));
5053 else if (DECL_SIZE_UNIT (local
->field
))
5055 /* ??? This can't be right. If the decl size overflows
5056 a host integer we will silently emit no data. */
5057 if (host_integerp (DECL_SIZE_UNIT (local
->field
), 1))
5058 fieldsize
= tree_low_cst (DECL_SIZE_UNIT (local
->field
), 1);
5062 fieldsize
= int_size_in_bytes (TREE_TYPE (local
->type
));
5064 /* Output the element's initial value. */
5065 if (local
->val
== NULL_TREE
)
5066 assemble_zeros (fieldsize
);
5068 output_constant (local
->val
, fieldsize
, align2
);
5070 /* Count its size. */
5071 local
->total_bytes
+= fieldsize
;
5074 /* Helper for output_constructor. From the current LOCAL and OUTER states,
5075 output an element that is a true bitfield or part of an outer one. */
5078 output_constructor_bitfield (oc_local_state
*local
, oc_outer_state
*outer
)
5080 /* Bit size of this element. */
5081 HOST_WIDE_INT ebitsize
5083 ? tree_low_cst (DECL_SIZE (local
->field
), 1)
5084 : tree_low_cst (TYPE_SIZE (TREE_TYPE (local
->type
)), 1));
5086 /* Relative index of this element if this is an array component. */
5087 HOST_WIDE_INT relative_index
5090 ? (tree_low_cst (local
->index
, 0)
5091 - tree_low_cst (local
->min_index
, 0))
5092 : local
->last_relative_index
+ 1)
5095 /* Bit position of this element from the start of the containing
5097 HOST_WIDE_INT constructor_relative_ebitpos
5099 ? int_bit_position (local
->field
)
5100 : ebitsize
* relative_index
);
5102 /* Bit position of this element from the start of a possibly ongoing
5103 outer byte buffer. */
5104 HOST_WIDE_INT byte_relative_ebitpos
5105 = ((outer
? outer
->bit_offset
: 0) + constructor_relative_ebitpos
);
5107 /* From the start of a possibly ongoing outer byte buffer, offsets to
5108 the first bit of this element and to the first bit past the end of
5110 HOST_WIDE_INT next_offset
= byte_relative_ebitpos
;
5111 HOST_WIDE_INT end_offset
= byte_relative_ebitpos
+ ebitsize
;
5113 local
->last_relative_index
= relative_index
;
5115 if (local
->val
== NULL_TREE
)
5116 local
->val
= integer_zero_node
;
5118 while (TREE_CODE (local
->val
) == VIEW_CONVERT_EXPR
5119 || TREE_CODE (local
->val
) == NON_LVALUE_EXPR
)
5120 local
->val
= TREE_OPERAND (local
->val
, 0);
5122 if (TREE_CODE (local
->val
) != INTEGER_CST
5123 && TREE_CODE (local
->val
) != CONSTRUCTOR
)
5125 error ("invalid initial value for member %qE", DECL_NAME (local
->field
));
5129 /* If this field does not start in this (or, next) byte,
5131 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5133 /* Output remnant of any bit field in previous bytes. */
5134 if (local
->byte_buffer_in_use
)
5136 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5137 local
->total_bytes
++;
5138 local
->byte_buffer_in_use
= false;
5141 /* If still not at proper byte, advance to there. */
5142 if (next_offset
/ BITS_PER_UNIT
!= local
->total_bytes
)
5144 gcc_assert (next_offset
/ BITS_PER_UNIT
>= local
->total_bytes
);
5145 assemble_zeros (next_offset
/ BITS_PER_UNIT
- local
->total_bytes
);
5146 local
->total_bytes
= next_offset
/ BITS_PER_UNIT
;
5150 /* Set up the buffer if necessary. */
5151 if (!local
->byte_buffer_in_use
)
5155 local
->byte_buffer_in_use
= true;
5158 /* If this is nested constructor, recurse passing the bit offset and the
5159 pending data, then retrieve the new pending data afterwards. */
5160 if (TREE_CODE (local
->val
) == CONSTRUCTOR
)
5162 oc_outer_state output_state
;
5164 output_state
.bit_offset
= next_offset
% BITS_PER_UNIT
;
5165 output_state
.byte
= local
->byte
;
5167 += output_constructor (local
->val
, 0, 0, &output_state
);
5168 local
->byte
= output_state
.byte
;
5172 /* Otherwise, we must split the element into pieces that fall within
5173 separate bytes, and combine each byte with previous or following
5175 while (next_offset
< end_offset
)
5179 HOST_WIDE_INT value
;
5180 HOST_WIDE_INT next_byte
= next_offset
/ BITS_PER_UNIT
;
5181 HOST_WIDE_INT next_bit
= next_offset
% BITS_PER_UNIT
;
5183 /* Advance from byte to byte
5184 within this element when necessary. */
5185 while (next_byte
!= local
->total_bytes
)
5187 assemble_integer (GEN_INT (local
->byte
), 1, BITS_PER_UNIT
, 1);
5188 local
->total_bytes
++;
5192 /* Number of bits we can process at once
5193 (all part of the same byte). */
5194 this_time
= MIN (end_offset
- next_offset
,
5195 BITS_PER_UNIT
- next_bit
);
5196 if (BYTES_BIG_ENDIAN
)
5198 /* On big-endian machine, take the most significant bits
5199 first (of the bits that are significant)
5200 and put them into bytes from the most significant end. */
5201 shift
= end_offset
- next_offset
- this_time
;
5203 /* Don't try to take a bunch of bits that cross
5204 the word boundary in the INTEGER_CST. We can
5205 only select bits from the LOW or HIGH part
5207 if (shift
< HOST_BITS_PER_WIDE_INT
5208 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5210 this_time
= shift
+ this_time
- HOST_BITS_PER_WIDE_INT
;
5211 shift
= HOST_BITS_PER_WIDE_INT
;
5214 /* Now get the bits from the appropriate constant word. */
5215 if (shift
< HOST_BITS_PER_WIDE_INT
)
5216 value
= TREE_INT_CST_LOW (local
->val
);
5219 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5220 value
= TREE_INT_CST_HIGH (local
->val
);
5221 shift
-= HOST_BITS_PER_WIDE_INT
;
5224 /* Get the result. This works only when:
5225 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5226 local
->byte
|= (((value
>> shift
)
5227 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5228 << (BITS_PER_UNIT
- this_time
- next_bit
));
5232 /* On little-endian machines,
5233 take first the least significant bits of the value
5234 and pack them starting at the least significant
5235 bits of the bytes. */
5236 shift
= next_offset
- byte_relative_ebitpos
;
5238 /* Don't try to take a bunch of bits that cross
5239 the word boundary in the INTEGER_CST. We can
5240 only select bits from the LOW or HIGH part
5242 if (shift
< HOST_BITS_PER_WIDE_INT
5243 && shift
+ this_time
> HOST_BITS_PER_WIDE_INT
)
5244 this_time
= (HOST_BITS_PER_WIDE_INT
- shift
);
5246 /* Now get the bits from the appropriate constant word. */
5247 if (shift
< HOST_BITS_PER_WIDE_INT
)
5248 value
= TREE_INT_CST_LOW (local
->val
);
5251 gcc_assert (shift
< 2 * HOST_BITS_PER_WIDE_INT
);
5252 value
= TREE_INT_CST_HIGH (local
->val
);
5253 shift
-= HOST_BITS_PER_WIDE_INT
;
5256 /* Get the result. This works only when:
5257 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5258 local
->byte
|= (((value
>> shift
)
5259 & (((HOST_WIDE_INT
) 2 << (this_time
- 1)) - 1))
5263 next_offset
+= this_time
;
5264 local
->byte_buffer_in_use
= true;
5268 /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
5269 Generate at least SIZE bytes, padding if necessary. OUTER designates the
5270 caller output state of relevance in recursive invocations. */
5272 static unsigned HOST_WIDE_INT
5273 output_constructor (tree exp
, unsigned HOST_WIDE_INT size
,
5274 unsigned int align
, oc_outer_state
* outer
)
5276 unsigned HOST_WIDE_INT cnt
;
5277 constructor_elt
*ce
;
5279 oc_local_state local
;
5281 /* Setup our local state to communicate with helpers. */
5284 local
.align
= align
;
5286 local
.total_bytes
= 0;
5287 local
.byte_buffer_in_use
= outer
!= NULL
;
5288 local
.byte
= outer
? outer
->byte
: 0;
5290 local
.type
= TREE_TYPE (exp
);
5292 local
.last_relative_index
= -1;
5294 local
.min_index
= NULL_TREE
;
5295 if (TREE_CODE (local
.type
) == ARRAY_TYPE
5296 && TYPE_DOMAIN (local
.type
) != NULL_TREE
)
5297 local
.min_index
= TYPE_MIN_VALUE (TYPE_DOMAIN (local
.type
));
5299 gcc_assert (HOST_BITS_PER_WIDE_INT
>= BITS_PER_UNIT
);
5301 /* As CE goes through the elements of the constant, FIELD goes through the
5302 structure fields if the constant is a structure. If the constant is a
5303 union, we override this by getting the field from the TREE_LIST element.
5304 But the constant could also be an array. Then FIELD is zero.
5306 There is always a maximum of one element in the chain LINK for unions
5307 (even if the initializer in a source program incorrectly contains
5310 local
.field
= NULL_TREE
;
5311 if (TREE_CODE (local
.type
) == RECORD_TYPE
)
5312 local
.field
= TYPE_FIELDS (local
.type
);
5315 VEC_iterate (constructor_elt
, CONSTRUCTOR_ELTS (exp
), cnt
, ce
);
5316 cnt
++, local
.field
= local
.field
? TREE_CHAIN (local
.field
) : 0)
5318 local
.val
= ce
->value
;
5319 local
.index
= NULL_TREE
;
5321 /* The element in a union constructor specifies the proper field
5323 if ((TREE_CODE (local
.type
) == RECORD_TYPE
5324 || TREE_CODE (local
.type
) == UNION_TYPE
5325 || TREE_CODE (local
.type
) == QUAL_UNION_TYPE
)
5326 && ce
->index
!= NULL_TREE
)
5327 local
.field
= ce
->index
;
5329 else if (TREE_CODE (local
.type
) == ARRAY_TYPE
)
5330 local
.index
= ce
->index
;
5332 #ifdef ASM_COMMENT_START
5333 if (local
.field
&& flag_verbose_asm
)
5334 fprintf (asm_out_file
, "%s %s:\n",
5336 DECL_NAME (local
.field
)
5337 ? IDENTIFIER_POINTER (DECL_NAME (local
.field
))
5341 /* Eliminate the marker that makes a cast not be an lvalue. */
5342 if (local
.val
!= NULL_TREE
)
5343 STRIP_NOPS (local
.val
);
5345 /* Output the current element, using the appropriate helper ... */
5347 /* For an array slice not part of an outer bitfield. */
5349 && local
.index
!= NULL_TREE
5350 && TREE_CODE (local
.index
) == RANGE_EXPR
)
5351 output_constructor_array_range (&local
);
5353 /* For a field that is neither a true bitfield nor part of an outer one,
5354 known to be at least byte aligned and multiple-of-bytes long. */
5356 && (local
.field
== NULL_TREE
5357 || !CONSTRUCTOR_BITFIELD_P (local
.field
)))
5358 output_constructor_regular_field (&local
);
5360 /* For a true bitfield or part of an outer one. */
5362 output_constructor_bitfield (&local
, outer
);
5365 /* If we are not at toplevel, save the pending data for our caller.
5366 Otherwise output the pending data and padding zeros as needed. */
5368 outer
->byte
= local
.byte
;
5371 if (local
.byte_buffer_in_use
)
5373 assemble_integer (GEN_INT (local
.byte
), 1, BITS_PER_UNIT
, 1);
5374 local
.total_bytes
++;
5377 if ((unsigned HOST_WIDE_INT
)local
.total_bytes
< local
.size
)
5379 assemble_zeros (local
.size
- local
.total_bytes
);
5380 local
.total_bytes
= local
.size
;
5384 return local
.total_bytes
;
5387 /* Mark DECL as weak. */
5390 mark_weak (tree decl
)
5392 DECL_WEAK (decl
) = 1;
5394 if (DECL_RTL_SET_P (decl
)
5395 && MEM_P (DECL_RTL (decl
))
5396 && XEXP (DECL_RTL (decl
), 0)
5397 && GET_CODE (XEXP (DECL_RTL (decl
), 0)) == SYMBOL_REF
)
5398 SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl
), 0)) = 1;
5401 /* Merge weak status between NEWDECL and OLDDECL. */
5404 merge_weak (tree newdecl
, tree olddecl
)
5406 if (DECL_WEAK (newdecl
) == DECL_WEAK (olddecl
))
5408 if (DECL_WEAK (newdecl
) && SUPPORTS_WEAK
)
5411 /* We put the NEWDECL on the weak_decls list at some point
5412 and OLDDECL as well. Keep just OLDDECL on the list. */
5413 for (pwd
= &weak_decls
; *pwd
; pwd
= &TREE_CHAIN (*pwd
))
5414 if (TREE_VALUE (*pwd
) == newdecl
)
5416 *pwd
= TREE_CHAIN (*pwd
);
5423 if (DECL_WEAK (newdecl
))
5427 /* NEWDECL is weak, but OLDDECL is not. */
5429 /* If we already output the OLDDECL, we're in trouble; we can't
5430 go back and make it weak. This error cannot be caught in
5431 declare_weak because the NEWDECL and OLDDECL was not yet
5432 been merged; therefore, TREE_ASM_WRITTEN was not set. */
5433 if (TREE_ASM_WRITTEN (olddecl
))
5434 error ("weak declaration of %q+D must precede definition",
5437 /* If we've already generated rtl referencing OLDDECL, we may
5438 have done so in a way that will not function properly with
5440 else if (TREE_USED (olddecl
)
5441 && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl
)))
5442 warning (0, "weak declaration of %q+D after first use results "
5443 "in unspecified behavior", newdecl
);
5447 /* We put the NEWDECL on the weak_decls list at some point.
5448 Replace it with the OLDDECL. */
5449 for (wd
= weak_decls
; wd
; wd
= TREE_CHAIN (wd
))
5450 if (TREE_VALUE (wd
) == newdecl
)
5452 TREE_VALUE (wd
) = olddecl
;
5455 /* We may not find the entry on the list. If NEWDECL is a
5456 weak alias, then we will have already called
5457 globalize_decl to remove the entry; in that case, we do
5458 not need to do anything. */
5461 /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
5462 mark_weak (olddecl
);
5465 /* OLDDECL was weak, but NEWDECL was not explicitly marked as
5466 weak. Just update NEWDECL to indicate that it's weak too. */
5467 mark_weak (newdecl
);
5470 /* Declare DECL to be a weak symbol. */
5473 declare_weak (tree decl
)
5475 if (! TREE_PUBLIC (decl
))
5476 error ("weak declaration of %q+D must be public", decl
);
5477 else if (TREE_CODE (decl
) == FUNCTION_DECL
&& TREE_ASM_WRITTEN (decl
))
5478 error ("weak declaration of %q+D must precede definition", decl
);
5479 else if (!SUPPORTS_WEAK
)
5480 warning (0, "weak declaration of %q+D not supported", decl
);
5483 if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl
)))
5484 DECL_ATTRIBUTES (decl
)
5485 = tree_cons (get_identifier ("weak"), NULL
, DECL_ATTRIBUTES (decl
));
5489 weak_finish_1 (tree decl
)
5491 #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
5492 const char *const name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5495 if (! TREE_USED (decl
))
5498 #ifdef ASM_WEAKEN_DECL
5499 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, NULL
);
5501 #ifdef ASM_WEAKEN_LABEL
5502 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5504 #ifdef ASM_OUTPUT_WEAK_ALIAS
5506 static bool warn_once
= 0;
5509 warning (0, "only weak aliases are supported in this configuration");
5519 /* This TREE_LIST contains weakref targets. */
5521 static GTY(()) tree weakref_targets
;
5523 /* Forward declaration. */
5524 static tree
find_decl_and_mark_needed (tree decl
, tree target
);
5526 /* Emit any pending weak declarations. */
5533 for (t
= weakref_targets
; t
; t
= TREE_CHAIN (t
))
5535 tree alias_decl
= TREE_PURPOSE (t
);
5536 tree target
= ultimate_transparent_alias_target (&TREE_VALUE (t
));
5538 if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl
)))
5539 /* Remove alias_decl from the weak list, but leave entries for
5540 the target alone. */
5542 #ifndef ASM_OUTPUT_WEAKREF
5543 else if (! TREE_SYMBOL_REFERENCED (target
))
5545 /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
5546 defined, otherwise we and weak_finish_1 would use
5547 different macros. */
5548 # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
5549 ASM_WEAKEN_LABEL (asm_out_file
, IDENTIFIER_POINTER (target
));
5551 tree decl
= find_decl_and_mark_needed (alias_decl
, target
);
5555 decl
= build_decl (DECL_SOURCE_LOCATION (alias_decl
),
5556 TREE_CODE (alias_decl
), target
,
5557 TREE_TYPE (alias_decl
));
5559 DECL_EXTERNAL (decl
) = 1;
5560 TREE_PUBLIC (decl
) = 1;
5561 DECL_ARTIFICIAL (decl
) = 1;
5562 TREE_NOTHROW (decl
) = TREE_NOTHROW (alias_decl
);
5563 TREE_USED (decl
) = 1;
5566 weak_finish_1 (decl
);
5575 /* Remove the alias and the target from the pending weak list
5576 so that we do not emit any .weak directives for the former,
5577 nor multiple .weak directives for the latter. */
5578 for (p
= &weak_decls
; (t2
= *p
) ; )
5580 if (TREE_VALUE (t2
) == alias_decl
5581 || target
== DECL_ASSEMBLER_NAME (TREE_VALUE (t2
)))
5582 *p
= TREE_CHAIN (t2
);
5584 p
= &TREE_CHAIN (t2
);
5587 /* Remove other weakrefs to the same target, to speed things up. */
5588 for (p
= &TREE_CHAIN (t
); (t2
= *p
) ; )
5590 if (target
== ultimate_transparent_alias_target (&TREE_VALUE (t2
)))
5591 *p
= TREE_CHAIN (t2
);
5593 p
= &TREE_CHAIN (t2
);
5598 for (t
= weak_decls
; t
; t
= TREE_CHAIN (t
))
5600 tree decl
= TREE_VALUE (t
);
5602 weak_finish_1 (decl
);
5606 /* Emit the assembly bits to indicate that DECL is globally visible. */
5609 globalize_decl (tree decl
)
5612 #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
5613 if (DECL_WEAK (decl
))
5615 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
5618 #ifdef ASM_WEAKEN_DECL
5619 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, 0);
5621 ASM_WEAKEN_LABEL (asm_out_file
, name
);
5624 /* Remove this function from the pending weak list so that
5625 we do not emit multiple .weak directives for it. */
5626 for (p
= &weak_decls
; (t
= *p
) ; )
5628 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5629 *p
= TREE_CHAIN (t
);
5631 p
= &TREE_CHAIN (t
);
5634 /* Remove weakrefs to the same target from the pending weakref
5635 list, for the same reason. */
5636 for (p
= &weakref_targets
; (t
= *p
) ; )
5638 if (DECL_ASSEMBLER_NAME (decl
)
5639 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5640 *p
= TREE_CHAIN (t
);
5642 p
= &TREE_CHAIN (t
);
5649 targetm
.asm_out
.globalize_decl_name (asm_out_file
, decl
);
5652 VEC(alias_pair
,gc
) *alias_pairs
;
5654 /* Given an assembly name, find the decl it is associated with. At the
5655 same time, mark it needed for cgraph. */
5658 find_decl_and_mark_needed (tree decl
, tree target
)
5660 struct cgraph_node
*fnode
= NULL
;
5661 struct varpool_node
*vnode
= NULL
;
5663 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5665 fnode
= cgraph_node_for_asm (target
);
5667 vnode
= varpool_node_for_asm (target
);
5671 vnode
= varpool_node_for_asm (target
);
5673 fnode
= cgraph_node_for_asm (target
);
5678 cgraph_mark_needed_node (fnode
);
5683 varpool_mark_needed_node (vnode
);
5684 vnode
->force_output
= 1;
5691 /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
5692 or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
5693 tree node is DECL to have the value of the tree node TARGET. */
5696 do_assemble_alias (tree decl
, tree target
)
5698 if (TREE_ASM_WRITTEN (decl
))
5701 /* We must force creation of DECL_RTL for debug info generation, even though
5702 we don't use it here. */
5703 make_decl_rtl (decl
);
5705 TREE_ASM_WRITTEN (decl
) = 1;
5706 TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl
)) = 1;
5708 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5710 ultimate_transparent_alias_target (&target
);
5712 if (!targetm
.have_tls
5713 && TREE_CODE (decl
) == VAR_DECL
5714 && DECL_THREAD_LOCAL_P (decl
))
5716 decl
= emutls_decl (decl
);
5717 target
= get_emutls_object_name (target
);
5720 if (!TREE_SYMBOL_REFERENCED (target
))
5721 weakref_targets
= tree_cons (decl
, target
, weakref_targets
);
5723 #ifdef ASM_OUTPUT_WEAKREF
5724 ASM_OUTPUT_WEAKREF (asm_out_file
, decl
,
5725 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5726 IDENTIFIER_POINTER (target
));
5730 error_at (DECL_SOURCE_LOCATION (decl
),
5731 "weakref is not supported in this configuration");
5738 if (!targetm
.have_tls
5739 && TREE_CODE (decl
) == VAR_DECL
5740 && DECL_THREAD_LOCAL_P (decl
))
5742 decl
= emutls_decl (decl
);
5743 target
= get_emutls_object_name (target
);
5746 #ifdef ASM_OUTPUT_DEF
5747 /* Make name accessible from other files, if appropriate. */
5749 if (TREE_PUBLIC (decl
))
5751 globalize_decl (decl
);
5752 maybe_assemble_visibility (decl
);
5755 # ifdef ASM_OUTPUT_DEF_FROM_DECLS
5756 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file
, decl
, target
);
5758 ASM_OUTPUT_DEF (asm_out_file
,
5759 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)),
5760 IDENTIFIER_POINTER (target
));
5762 #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
5767 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5768 # ifdef ASM_WEAKEN_DECL
5769 ASM_WEAKEN_DECL (asm_out_file
, decl
, name
, IDENTIFIER_POINTER (target
));
5771 ASM_OUTPUT_WEAK_ALIAS (asm_out_file
, name
, IDENTIFIER_POINTER (target
));
5773 /* Remove this function from the pending weak list so that
5774 we do not emit multiple .weak directives for it. */
5775 for (p
= &weak_decls
; (t
= *p
) ; )
5776 if (DECL_ASSEMBLER_NAME (decl
) == DECL_ASSEMBLER_NAME (TREE_VALUE (t
)))
5777 *p
= TREE_CHAIN (t
);
5779 p
= &TREE_CHAIN (t
);
5781 /* Remove weakrefs to the same target from the pending weakref
5782 list, for the same reason. */
5783 for (p
= &weakref_targets
; (t
= *p
) ; )
5785 if (DECL_ASSEMBLER_NAME (decl
)
5786 == ultimate_transparent_alias_target (&TREE_VALUE (t
)))
5787 *p
= TREE_CHAIN (t
);
5789 p
= &TREE_CHAIN (t
);
5796 /* Remove the alias pairing for functions that are no longer in the call
5800 remove_unreachable_alias_pairs (void)
5805 if (alias_pairs
== NULL
)
5808 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); )
5810 if (!DECL_EXTERNAL (p
->decl
))
5812 struct cgraph_node
*fnode
= NULL
;
5813 struct varpool_node
*vnode
= NULL
;
5814 fnode
= cgraph_node_for_asm (p
->target
);
5815 vnode
= (fnode
== NULL
) ? varpool_node_for_asm (p
->target
) : NULL
;
5816 if (fnode
== NULL
&& vnode
== NULL
)
5818 VEC_unordered_remove (alias_pair
, alias_pairs
, i
);
5828 /* First pass of completing pending aliases. Make sure that cgraph knows
5829 which symbols will be required. */
5832 finish_aliases_1 (void)
5837 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5841 target_decl
= find_decl_and_mark_needed (p
->decl
, p
->target
);
5842 if (target_decl
== NULL
)
5844 if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5845 error ("%q+D aliased to undefined symbol %qE",
5846 p
->decl
, p
->target
);
5848 else if (DECL_EXTERNAL (target_decl
)
5849 /* We use local aliases for C++ thunks to force the tailcall
5850 to bind locally. Of course this is a hack - to keep it
5851 working do the following (which is not strictly correct). */
5852 && (! TREE_CODE (target_decl
) == FUNCTION_DECL
5853 || ! DECL_VIRTUAL_P (target_decl
))
5854 && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p
->decl
)))
5855 error ("%q+D aliased to external symbol %qE",
5856 p
->decl
, p
->target
);
5860 /* Second pass of completing pending aliases. Emit the actual assembly.
5861 This happens at the end of compilation and thus it is assured that the
5862 target symbol has been emitted. */
5865 finish_aliases_2 (void)
5870 for (i
= 0; VEC_iterate (alias_pair
, alias_pairs
, i
, p
); i
++)
5871 do_assemble_alias (p
->decl
, p
->target
);
5873 VEC_truncate (alias_pair
, alias_pairs
, 0);
5876 /* Emit an assembler directive to make the symbol for DECL an alias to
5877 the symbol for TARGET. */
5880 assemble_alias (tree decl
, tree target
)
5883 bool is_weakref
= false;
5885 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl
)))
5887 tree alias
= DECL_ASSEMBLER_NAME (decl
);
5891 ultimate_transparent_alias_target (&target
);
5893 if (alias
== target
)
5894 error ("weakref %q+D ultimately targets itself", decl
);
5897 #ifndef ASM_OUTPUT_WEAKREF
5898 IDENTIFIER_TRANSPARENT_ALIAS (alias
) = 1;
5899 TREE_CHAIN (alias
) = target
;
5902 if (TREE_PUBLIC (decl
))
5903 error ("weakref %q+D must have static linkage", decl
);
5907 #if !defined (ASM_OUTPUT_DEF)
5908 # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
5909 error_at (DECL_SOURCE_LOCATION (decl
),
5910 "alias definitions not supported in this configuration");
5913 if (!DECL_WEAK (decl
))
5915 error_at (DECL_SOURCE_LOCATION (decl
),
5916 "only weak aliases are supported in this configuration");
5922 TREE_USED (decl
) = 1;
5924 /* A quirk of the initial implementation of aliases required that the user
5925 add "extern" to all of them. Which is silly, but now historical. Do
5926 note that the symbol is in fact locally defined. */
5928 DECL_EXTERNAL (decl
) = 0;
5930 /* Allow aliases to aliases. */
5931 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5932 cgraph_node (decl
)->alias
= true;
5934 varpool_node (decl
)->alias
= true;
5936 /* If the target has already been emitted, we don't have to queue the
5937 alias. This saves a tad of memory. */
5938 if (cgraph_global_info_ready
)
5939 target_decl
= find_decl_and_mark_needed (decl
, target
);
5942 if (target_decl
&& TREE_ASM_WRITTEN (target_decl
))
5943 do_assemble_alias (decl
, target
);
5946 alias_pair
*p
= VEC_safe_push (alias_pair
, gc
, alias_pairs
, NULL
);
5952 /* Emit an assembler directive to set symbol for DECL visibility to
5953 the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
5956 default_assemble_visibility (tree decl ATTRIBUTE_UNUSED
,
5957 int vis ATTRIBUTE_UNUSED
)
5959 #ifdef HAVE_GAS_HIDDEN
5960 static const char * const visibility_types
[] = {
5961 NULL
, "protected", "hidden", "internal"
5964 const char *name
, *type
;
5966 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
5967 type
= visibility_types
[vis
];
5969 fprintf (asm_out_file
, "\t.%s\t", type
);
5970 assemble_name (asm_out_file
, name
);
5971 fprintf (asm_out_file
, "\n");
5973 warning (OPT_Wattributes
, "visibility attribute not supported "
5974 "in this configuration; ignored");
5978 /* A helper function to call assemble_visibility when needed for a decl. */
5981 maybe_assemble_visibility (tree decl
)
5983 enum symbol_visibility vis
= DECL_VISIBILITY (decl
);
5985 if (vis
!= VISIBILITY_DEFAULT
)
5987 targetm
.asm_out
.visibility (decl
, vis
);
5994 /* Returns 1 if the target configuration supports defining public symbols
5995 so that one of them will be chosen at link time instead of generating a
5996 multiply-defined symbol error, whether through the use of weak symbols or
5997 a target-specific mechanism for having duplicates discarded. */
6000 supports_one_only (void)
6002 if (SUPPORTS_ONE_ONLY
)
6004 return SUPPORTS_WEAK
;
6007 /* Set up DECL as a public symbol that can be defined in multiple
6008 translation units without generating a linker error. */
6011 make_decl_one_only (tree decl
, tree comdat_group
)
6013 gcc_assert (TREE_CODE (decl
) == VAR_DECL
6014 || TREE_CODE (decl
) == FUNCTION_DECL
);
6016 TREE_PUBLIC (decl
) = 1;
6018 if (SUPPORTS_ONE_ONLY
)
6020 #ifdef MAKE_DECL_ONE_ONLY
6021 MAKE_DECL_ONE_ONLY (decl
);
6023 DECL_COMDAT_GROUP (decl
) = comdat_group
;
6025 else if (TREE_CODE (decl
) == VAR_DECL
6026 && (DECL_INITIAL (decl
) == 0 || DECL_INITIAL (decl
) == error_mark_node
))
6027 DECL_COMMON (decl
) = 1;
6030 gcc_assert (SUPPORTS_WEAK
);
6031 DECL_WEAK (decl
) = 1;
6036 init_varasm_once (void)
6038 section_htab
= htab_create_ggc (31, section_entry_hash
,
6039 section_entry_eq
, NULL
);
6040 object_block_htab
= htab_create_ggc (31, object_block_entry_hash
,
6041 object_block_entry_eq
, NULL
);
6042 const_desc_htab
= htab_create_ggc (1009, const_desc_hash
,
6043 const_desc_eq
, NULL
);
6045 const_alias_set
= new_alias_set ();
6046 shared_constant_pool
= create_constant_pool ();
6048 #ifdef TEXT_SECTION_ASM_OP
6049 text_section
= get_unnamed_section (SECTION_CODE
, output_section_asm_op
,
6050 TEXT_SECTION_ASM_OP
);
6053 #ifdef DATA_SECTION_ASM_OP
6054 data_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6055 DATA_SECTION_ASM_OP
);
6058 #ifdef SDATA_SECTION_ASM_OP
6059 sdata_section
= get_unnamed_section (SECTION_WRITE
, output_section_asm_op
,
6060 SDATA_SECTION_ASM_OP
);
6063 #ifdef READONLY_DATA_SECTION_ASM_OP
6064 readonly_data_section
= get_unnamed_section (0, output_section_asm_op
,
6065 READONLY_DATA_SECTION_ASM_OP
);
6068 #ifdef CTORS_SECTION_ASM_OP
6069 ctors_section
= get_unnamed_section (0, output_section_asm_op
,
6070 CTORS_SECTION_ASM_OP
);
6073 #ifdef DTORS_SECTION_ASM_OP
6074 dtors_section
= get_unnamed_section (0, output_section_asm_op
,
6075 DTORS_SECTION_ASM_OP
);
6078 #ifdef BSS_SECTION_ASM_OP
6079 bss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6080 output_section_asm_op
,
6081 BSS_SECTION_ASM_OP
);
6084 #ifdef SBSS_SECTION_ASM_OP
6085 sbss_section
= get_unnamed_section (SECTION_WRITE
| SECTION_BSS
,
6086 output_section_asm_op
,
6087 SBSS_SECTION_ASM_OP
);
6090 tls_comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6091 | SECTION_COMMON
, emit_tls_common
);
6092 lcomm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6093 | SECTION_COMMON
, emit_local
);
6094 comm_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
6095 | SECTION_COMMON
, emit_common
);
6097 #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS
6098 bss_noswitch_section
= get_noswitch_section (SECTION_WRITE
| SECTION_BSS
,
6102 targetm
.asm_out
.init_sections ();
6104 if (readonly_data_section
== NULL
)
6105 readonly_data_section
= text_section
;
6109 decl_default_tls_model (const_tree decl
)
6111 enum tls_model kind
;
6114 is_local
= targetm
.binds_local_p (decl
);
6118 kind
= TLS_MODEL_LOCAL_EXEC
;
6120 kind
= TLS_MODEL_INITIAL_EXEC
;
6123 /* Local dynamic is inefficient when we're not combining the
6124 parts of the address. */
6125 else if (optimize
&& is_local
)
6126 kind
= TLS_MODEL_LOCAL_DYNAMIC
;
6128 kind
= TLS_MODEL_GLOBAL_DYNAMIC
;
6129 if (kind
< flag_tls_default
)
6130 kind
= flag_tls_default
;
6135 /* Select a set of attributes for section NAME based on the properties
6136 of DECL and whether or not RELOC indicates that DECL's initializer
6137 might contain runtime relocations.
6139 We make the section read-only and executable for a function decl,
6140 read-only for a const data decl, and writable for a non-const data decl. */
6143 default_section_type_flags (tree decl
, const char *name
, int reloc
)
6147 if (decl
&& TREE_CODE (decl
) == FUNCTION_DECL
)
6148 flags
= SECTION_CODE
;
6149 else if (decl
&& decl_readonly_section (decl
, reloc
))
6151 else if (current_function_decl
6153 && crtl
->subsections
.unlikely_text_section_name
6154 && strcmp (name
, crtl
->subsections
.unlikely_text_section_name
) == 0)
6155 flags
= SECTION_CODE
;
6157 && (!current_function_decl
|| !cfun
)
6158 && strcmp (name
, UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6159 flags
= SECTION_CODE
;
6161 flags
= SECTION_WRITE
;
6163 if (decl
&& DECL_ONE_ONLY (decl
))
6164 flags
|= SECTION_LINKONCE
;
6166 if (decl
&& TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
))
6167 flags
|= SECTION_TLS
| SECTION_WRITE
;
6169 if (strcmp (name
, ".bss") == 0
6170 || strncmp (name
, ".bss.", 5) == 0
6171 || strncmp (name
, ".gnu.linkonce.b.", 16) == 0
6172 || strcmp (name
, ".sbss") == 0
6173 || strncmp (name
, ".sbss.", 6) == 0
6174 || strncmp (name
, ".gnu.linkonce.sb.", 17) == 0)
6175 flags
|= SECTION_BSS
;
6177 if (strcmp (name
, ".tdata") == 0
6178 || strncmp (name
, ".tdata.", 7) == 0
6179 || strncmp (name
, ".gnu.linkonce.td.", 17) == 0)
6180 flags
|= SECTION_TLS
;
6182 if (strcmp (name
, ".tbss") == 0
6183 || strncmp (name
, ".tbss.", 6) == 0
6184 || strncmp (name
, ".gnu.linkonce.tb.", 17) == 0)
6185 flags
|= SECTION_TLS
| SECTION_BSS
;
6187 /* These three sections have special ELF types. They are neither
6188 SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't
6189 want to print a section type (@progbits or @nobits). If someone
6190 is silly enough to emit code or TLS variables to one of these
6191 sections, then don't handle them specially. */
6192 if (!(flags
& (SECTION_CODE
| SECTION_BSS
| SECTION_TLS
))
6193 && (strcmp (name
, ".init_array") == 0
6194 || strcmp (name
, ".fini_array") == 0
6195 || strcmp (name
, ".preinit_array") == 0))
6196 flags
|= SECTION_NOTYPE
;
6201 /* Return true if the target supports some form of global BSS,
6202 either through bss_noswitch_section, or by selecting a BSS
6203 section in TARGET_ASM_SELECT_SECTION. */
6206 have_global_bss_p (void)
6208 return bss_noswitch_section
|| targetm
.have_switchable_bss_sections
;
6211 /* Output assembly to switch to section NAME with attribute FLAGS.
6212 Four variants for common object file formats. */
6215 default_no_named_section (const char *name ATTRIBUTE_UNUSED
,
6216 unsigned int flags ATTRIBUTE_UNUSED
,
6217 tree decl ATTRIBUTE_UNUSED
)
6219 /* Some object formats don't support named sections at all. The
6220 front-end should already have flagged this as an error. */
6224 #ifndef TLS_SECTION_ASM_FLAG
6225 #define TLS_SECTION_ASM_FLAG 'T'
6229 default_elf_asm_named_section (const char *name
, unsigned int flags
,
6230 tree decl ATTRIBUTE_UNUSED
)
6232 char flagchars
[10], *f
= flagchars
;
6234 /* If we have already declared this section, we can use an
6235 abbreviated form to switch back to it -- unless this section is
6236 part of a COMDAT groups, in which case GAS requires the full
6237 declaration every time. */
6238 if (!(HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6239 && (flags
& SECTION_DECLARED
))
6241 fprintf (asm_out_file
, "\t.section\t%s\n", name
);
6245 if (!(flags
& SECTION_DEBUG
))
6247 if (flags
& SECTION_WRITE
)
6249 if (flags
& SECTION_CODE
)
6251 if (flags
& SECTION_SMALL
)
6253 if (flags
& SECTION_MERGE
)
6255 if (flags
& SECTION_STRINGS
)
6257 if (flags
& SECTION_TLS
)
6258 *f
++ = TLS_SECTION_ASM_FLAG
;
6259 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6263 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"", name
, flagchars
);
6265 if (!(flags
& SECTION_NOTYPE
))
6270 if (flags
& SECTION_BSS
)
6276 #ifdef ASM_COMMENT_START
6277 /* On platforms that use "@" as the assembly comment character,
6279 if (strcmp (ASM_COMMENT_START
, "@") == 0)
6282 fprintf (asm_out_file
, format
, type
);
6284 if (flags
& SECTION_ENTSIZE
)
6285 fprintf (asm_out_file
, ",%d", flags
& SECTION_ENTSIZE
);
6286 if (HAVE_COMDAT_GROUP
&& (flags
& SECTION_LINKONCE
))
6288 if (TREE_CODE (decl
) == IDENTIFIER_NODE
)
6289 fprintf (asm_out_file
, ",%s,comdat", IDENTIFIER_POINTER (decl
));
6291 fprintf (asm_out_file
, ",%s,comdat",
6292 IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl
)));
6296 putc ('\n', asm_out_file
);
6300 default_coff_asm_named_section (const char *name
, unsigned int flags
,
6301 tree decl ATTRIBUTE_UNUSED
)
6303 char flagchars
[8], *f
= flagchars
;
6305 if (flags
& SECTION_WRITE
)
6307 if (flags
& SECTION_CODE
)
6311 fprintf (asm_out_file
, "\t.section\t%s,\"%s\"\n", name
, flagchars
);
6315 default_pe_asm_named_section (const char *name
, unsigned int flags
,
6318 default_coff_asm_named_section (name
, flags
, decl
);
6320 if (flags
& SECTION_LINKONCE
)
6322 /* Functions may have been compiled at various levels of
6323 optimization so we can't use `same_size' here.
6324 Instead, have the linker pick one. */
6325 fprintf (asm_out_file
, "\t.linkonce %s\n",
6326 (flags
& SECTION_CODE
? "discard" : "same_size"));
6330 /* The lame default section selector. */
6333 default_select_section (tree decl
, int reloc
,
6334 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6338 if (decl_readonly_section (decl
, reloc
))
6339 return readonly_data_section
;
6341 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6343 if (! ((flag_pic
&& reloc
)
6344 || !TREE_READONLY (decl
)
6345 || TREE_SIDE_EFFECTS (decl
)
6346 || !TREE_CONSTANT (decl
)))
6347 return readonly_data_section
;
6349 else if (TREE_CODE (decl
) == STRING_CST
)
6350 return readonly_data_section
;
6351 else if (! (flag_pic
&& reloc
))
6352 return readonly_data_section
;
6354 return data_section
;
6357 enum section_category
6358 categorize_decl_for_section (const_tree decl
, int reloc
)
6360 enum section_category ret
;
6362 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6364 else if (TREE_CODE (decl
) == STRING_CST
)
6366 if (flag_mudflap
) /* or !flag_merge_constants */
6367 return SECCAT_RODATA
;
6369 return SECCAT_RODATA_MERGE_STR
;
6371 else if (TREE_CODE (decl
) == VAR_DECL
)
6373 if (bss_initializer_p (decl
))
6375 else if (! TREE_READONLY (decl
)
6376 || TREE_SIDE_EFFECTS (decl
)
6377 || ! TREE_CONSTANT (DECL_INITIAL (decl
)))
6379 /* Here the reloc_rw_mask is not testing whether the section should
6380 be read-only or not, but whether the dynamic link will have to
6381 do something. If so, we wish to segregate the data in order to
6382 minimize cache misses inside the dynamic linker. */
6383 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6384 ret
= reloc
== 1 ? SECCAT_DATA_REL_LOCAL
: SECCAT_DATA_REL
;
6388 else if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6389 ret
= reloc
== 1 ? SECCAT_DATA_REL_RO_LOCAL
: SECCAT_DATA_REL_RO
;
6390 else if (reloc
|| flag_merge_constants
< 2)
6391 /* C and C++ don't allow different variables to share the same
6392 location. -fmerge-all-constants allows even that (at the
6393 expense of not conforming). */
6394 ret
= SECCAT_RODATA
;
6395 else if (TREE_CODE (DECL_INITIAL (decl
)) == STRING_CST
)
6396 ret
= SECCAT_RODATA_MERGE_STR_INIT
;
6398 ret
= SECCAT_RODATA_MERGE_CONST
;
6400 else if (TREE_CODE (decl
) == CONSTRUCTOR
)
6402 if ((reloc
& targetm
.asm_out
.reloc_rw_mask ())
6403 || TREE_SIDE_EFFECTS (decl
)
6404 || ! TREE_CONSTANT (decl
))
6407 ret
= SECCAT_RODATA
;
6410 ret
= SECCAT_RODATA
;
6412 /* There are no read-only thread-local sections. */
6413 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_TLS_MODEL (decl
))
6415 if (DECL_TLS_MODEL (decl
) == TLS_MODEL_EMULATED
)
6417 if (DECL_EMUTLS_VAR_P (decl
))
6419 if (targetm
.emutls
.var_section
)
6420 ret
= SECCAT_EMUTLS_VAR
;
6424 if (targetm
.emutls
.tmpl_prefix
)
6425 ret
= SECCAT_EMUTLS_TMPL
;
6428 /* Note that this would be *just* SECCAT_BSS, except that there's
6429 no concept of a read-only thread-local-data section. */
6430 else if (ret
== SECCAT_BSS
6431 || (flag_zero_initialized_in_bss
6432 && initializer_zerop (DECL_INITIAL (decl
))))
6438 /* If the target uses small data sections, select it. */
6439 else if (targetm
.in_small_data_p (decl
))
6441 if (ret
== SECCAT_BSS
)
6443 else if (targetm
.have_srodata_section
&& ret
== SECCAT_RODATA
)
6444 ret
= SECCAT_SRODATA
;
6453 decl_readonly_section (const_tree decl
, int reloc
)
6455 switch (categorize_decl_for_section (decl
, reloc
))
6458 case SECCAT_RODATA_MERGE_STR
:
6459 case SECCAT_RODATA_MERGE_STR_INIT
:
6460 case SECCAT_RODATA_MERGE_CONST
:
6461 case SECCAT_SRODATA
:
6470 /* Select a section based on the above categorization. */
6473 default_elf_select_section (tree decl
, int reloc
,
6474 unsigned HOST_WIDE_INT align
)
6477 switch (categorize_decl_for_section (decl
, reloc
))
6480 /* We're not supposed to be called on FUNCTION_DECLs. */
6483 return readonly_data_section
;
6484 case SECCAT_RODATA_MERGE_STR
:
6485 return mergeable_string_section (decl
, align
, 0);
6486 case SECCAT_RODATA_MERGE_STR_INIT
:
6487 return mergeable_string_section (DECL_INITIAL (decl
), align
, 0);
6488 case SECCAT_RODATA_MERGE_CONST
:
6489 return mergeable_constant_section (DECL_MODE (decl
), align
, 0);
6490 case SECCAT_SRODATA
:
6494 return data_section
;
6495 case SECCAT_DATA_REL
:
6496 sname
= ".data.rel";
6498 case SECCAT_DATA_REL_LOCAL
:
6499 sname
= ".data.rel.local";
6501 case SECCAT_DATA_REL_RO
:
6502 sname
= ".data.rel.ro";
6504 case SECCAT_DATA_REL_RO_LOCAL
:
6505 sname
= ".data.rel.ro.local";
6524 case SECCAT_EMUTLS_VAR
:
6525 sname
= targetm
.emutls
.var_section
;
6527 case SECCAT_EMUTLS_TMPL
:
6528 sname
= targetm
.emutls
.tmpl_section
;
6536 return get_named_section (decl
, sname
, reloc
);
6539 /* Construct a unique section name based on the decl name and the
6540 categorization performed above. */
6543 default_unique_section (tree decl
, int reloc
)
6545 /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
6546 bool one_only
= DECL_ONE_ONLY (decl
) && !HAVE_COMDAT_GROUP
;
6547 const char *prefix
, *name
, *linkonce
;
6550 switch (categorize_decl_for_section (decl
, reloc
))
6553 prefix
= one_only
? ".t" : ".text";
6556 case SECCAT_RODATA_MERGE_STR
:
6557 case SECCAT_RODATA_MERGE_STR_INIT
:
6558 case SECCAT_RODATA_MERGE_CONST
:
6559 prefix
= one_only
? ".r" : ".rodata";
6561 case SECCAT_SRODATA
:
6562 prefix
= one_only
? ".s2" : ".sdata2";
6565 prefix
= one_only
? ".d" : ".data";
6567 case SECCAT_DATA_REL
:
6568 prefix
= one_only
? ".d.rel" : ".data.rel";
6570 case SECCAT_DATA_REL_LOCAL
:
6571 prefix
= one_only
? ".d.rel.local" : ".data.rel.local";
6573 case SECCAT_DATA_REL_RO
:
6574 prefix
= one_only
? ".d.rel.ro" : ".data.rel.ro";
6576 case SECCAT_DATA_REL_RO_LOCAL
:
6577 prefix
= one_only
? ".d.rel.ro.local" : ".data.rel.ro.local";
6580 prefix
= one_only
? ".s" : ".sdata";
6583 prefix
= one_only
? ".b" : ".bss";
6586 prefix
= one_only
? ".sb" : ".sbss";
6589 prefix
= one_only
? ".td" : ".tdata";
6592 prefix
= one_only
? ".tb" : ".tbss";
6594 case SECCAT_EMUTLS_VAR
:
6595 prefix
= targetm
.emutls
.var_section
;
6597 case SECCAT_EMUTLS_TMPL
:
6598 prefix
= targetm
.emutls
.tmpl_section
;
6604 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
6605 name
= targetm
.strip_name_encoding (name
);
6607 /* If we're using one_only, then there needs to be a .gnu.linkonce
6608 prefix to the section name. */
6609 linkonce
= one_only
? ".gnu.linkonce" : "";
6611 string
= ACONCAT ((linkonce
, prefix
, ".", name
, NULL
));
6613 DECL_SECTION_NAME (decl
) = build_string (strlen (string
), string
);
6616 /* Like compute_reloc_for_constant, except for an RTX. The return value
6617 is a mask for which bit 1 indicates a global relocation, and bit 0
6618 indicates a local relocation. */
6621 compute_reloc_for_rtx_1 (rtx
*xp
, void *data
)
6623 int *preloc
= (int *) data
;
6626 switch (GET_CODE (x
))
6629 *preloc
|= SYMBOL_REF_LOCAL_P (x
) ? 1 : 2;
6642 compute_reloc_for_rtx (rtx x
)
6646 switch (GET_CODE (x
))
6652 for_each_rtx (&x
, compute_reloc_for_rtx_1
, &reloc
);
6661 default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED
,
6663 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED
)
6665 if (compute_reloc_for_rtx (x
) & targetm
.asm_out
.reloc_rw_mask ())
6666 return data_section
;
6668 return readonly_data_section
;
6672 default_elf_select_rtx_section (enum machine_mode mode
, rtx x
,
6673 unsigned HOST_WIDE_INT align
)
6675 int reloc
= compute_reloc_for_rtx (x
);
6677 /* ??? Handle small data here somehow. */
6679 if (reloc
& targetm
.asm_out
.reloc_rw_mask ())
6682 return get_named_section (NULL
, ".data.rel.ro.local", 1);
6684 return get_named_section (NULL
, ".data.rel.ro", 3);
6687 return mergeable_constant_section (mode
, align
, 0);
6690 /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
6693 default_encode_section_info (tree decl
, rtx rtl
, int first ATTRIBUTE_UNUSED
)
6698 /* Careful not to prod global register variables. */
6701 symbol
= XEXP (rtl
, 0);
6702 if (GET_CODE (symbol
) != SYMBOL_REF
)
6705 flags
= SYMBOL_REF_FLAGS (symbol
) & SYMBOL_FLAG_HAS_BLOCK_INFO
;
6706 if (TREE_CODE (decl
) == FUNCTION_DECL
)
6707 flags
|= SYMBOL_FLAG_FUNCTION
;
6708 if (targetm
.binds_local_p (decl
))
6709 flags
|= SYMBOL_FLAG_LOCAL
;
6710 if (TREE_CODE (decl
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (decl
)
6711 && DECL_TLS_MODEL (decl
) != TLS_MODEL_EMULATED
)
6712 flags
|= DECL_TLS_MODEL (decl
) << SYMBOL_FLAG_TLS_SHIFT
;
6713 else if (targetm
.in_small_data_p (decl
))
6714 flags
|= SYMBOL_FLAG_SMALL
;
6715 /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
6716 being PUBLIC, the thing *must* be defined in this translation unit.
6717 Prevent this buglet from being propagated into rtl code as well. */
6718 if (DECL_P (decl
) && DECL_EXTERNAL (decl
) && TREE_PUBLIC (decl
))
6719 flags
|= SYMBOL_FLAG_EXTERNAL
;
6721 SYMBOL_REF_FLAGS (symbol
) = flags
;
6724 /* By default, we do nothing for encode_section_info, so we need not
6725 do anything but discard the '*' marker. */
6728 default_strip_name_encoding (const char *str
)
6730 return str
+ (*str
== '*');
6733 #ifdef ASM_OUTPUT_DEF
6734 /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
6735 anchor relative to ".", the current section position. */
6738 default_asm_output_anchor (rtx symbol
)
6742 sprintf (buffer
, "*. + " HOST_WIDE_INT_PRINT_DEC
,
6743 SYMBOL_REF_BLOCK_OFFSET (symbol
));
6744 ASM_OUTPUT_DEF (asm_out_file
, XSTR (symbol
, 0), buffer
);
6748 /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
6751 default_use_anchors_for_symbol_p (const_rtx symbol
)
6756 /* Don't use anchors for mergeable sections. The linker might move
6757 the objects around. */
6758 sect
= SYMBOL_REF_BLOCK (symbol
)->sect
;
6759 if (sect
->common
.flags
& SECTION_MERGE
)
6762 /* Don't use anchors for small data sections. The small data register
6763 acts as an anchor for such sections. */
6764 if (sect
->common
.flags
& SECTION_SMALL
)
6767 decl
= SYMBOL_REF_DECL (symbol
);
6768 if (decl
&& DECL_P (decl
))
6770 /* Don't use section anchors for decls that might be defined by
6772 if (!targetm
.binds_local_p (decl
))
6775 /* Don't use section anchors for decls that will be placed in a
6776 small data section. */
6777 /* ??? Ideally, this check would be redundant with the SECTION_SMALL
6778 one above. The problem is that we only use SECTION_SMALL for
6779 sections that should be marked as small in the section directive. */
6780 if (targetm
.in_small_data_p (decl
))
6786 /* Assume ELF-ish defaults, since that's pretty much the most liberal
6787 wrt cross-module name binding. */
6790 default_binds_local_p (const_tree exp
)
6792 return default_binds_local_p_1 (exp
, flag_shlib
);
6796 default_binds_local_p_1 (const_tree exp
, int shlib
)
6800 /* A non-decl is an entry in the constant pool. */
6803 /* Weakrefs may not bind locally, even though the weakref itself is
6804 always static and therefore local. */
6805 else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp
)))
6807 /* Static variables are always local. */
6808 else if (! TREE_PUBLIC (exp
))
6810 /* A variable is local if the user has said explicitly that it will
6812 else if (DECL_VISIBILITY_SPECIFIED (exp
)
6813 && DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6815 /* Variables defined outside this object might not be local. */
6816 else if (DECL_EXTERNAL (exp
))
6818 /* If defined in this object and visibility is not default, must be
6820 else if (DECL_VISIBILITY (exp
) != VISIBILITY_DEFAULT
)
6822 /* Default visibility weak data can be overridden by a strong symbol
6823 in another module and so are not local. */
6824 else if (DECL_WEAK (exp
))
6826 /* If PIC, then assume that any global name can be overridden by
6827 symbols resolved from other modules, unless we are compiling with
6828 -fwhole-program, which assumes that names are local. */
6830 local_p
= flag_whole_program
;
6831 /* Uninitialized COMMON variable may be unified with symbols
6832 resolved from other modules. */
6833 else if (DECL_COMMON (exp
)
6834 && (DECL_INITIAL (exp
) == NULL
6835 || DECL_INITIAL (exp
) == error_mark_node
))
6837 /* Otherwise we're left with initialized (or non-common) global data
6838 which is of necessity defined locally. */
6845 /* Default function to output code that will globalize a label. A
6846 target must define GLOBAL_ASM_OP or provide its own function to
6847 globalize a label. */
6848 #ifdef GLOBAL_ASM_OP
6850 default_globalize_label (FILE * stream
, const char *name
)
6852 fputs (GLOBAL_ASM_OP
, stream
);
6853 assemble_name (stream
, name
);
6854 putc ('\n', stream
);
6856 #endif /* GLOBAL_ASM_OP */
6858 /* Default function to output code that will globalize a declaration. */
6860 default_globalize_decl_name (FILE * stream
, tree decl
)
6862 const char *name
= XSTR (XEXP (DECL_RTL (decl
), 0), 0);
6863 targetm
.asm_out
.globalize_label (stream
, name
);
6866 /* Default function to output a label for unwind information. The
6867 default is to do nothing. A target that needs nonlocal labels for
6868 unwind information must provide its own function to do this. */
6870 default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED
,
6871 tree decl ATTRIBUTE_UNUSED
,
6872 int for_eh ATTRIBUTE_UNUSED
,
6873 int empty ATTRIBUTE_UNUSED
)
6877 /* Default function to output a label to divide up the exception table.
6878 The default is to do nothing. A target that needs/wants to divide
6879 up the table must provide it's own function to do this. */
6881 default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED
)
6885 /* This is how to output an internal numbered label where PREFIX is
6886 the class of label and LABELNO is the number within the class. */
6889 default_internal_label (FILE *stream
, const char *prefix
,
6890 unsigned long labelno
)
6892 char *const buf
= (char *) alloca (40 + strlen (prefix
));
6893 ASM_GENERATE_INTERNAL_LABEL (buf
, prefix
, labelno
);
6894 ASM_OUTPUT_INTERNAL_LABEL (stream
, buf
);
6897 /* This is the default behavior at the beginning of a file. It's
6898 controlled by two other target-hook toggles. */
6900 default_file_start (void)
6902 if (targetm
.file_start_app_off
6903 && !(flag_verbose_asm
|| flag_debug_asm
|| flag_dump_rtl_in_asm
))
6904 fputs (ASM_APP_OFF
, asm_out_file
);
6906 if (targetm
.file_start_file_directive
)
6907 output_file_directive (asm_out_file
, main_input_filename
);
6910 /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
6911 which emits a special section directive used to indicate whether or
6912 not this object file needs an executable stack. This is primarily
6913 a GNU extension to ELF but could be used on other targets. */
6915 int trampolines_created
;
6918 file_end_indicate_exec_stack (void)
6920 unsigned int flags
= SECTION_DEBUG
;
6921 if (trampolines_created
)
6922 flags
|= SECTION_CODE
;
6924 switch_to_section (get_section (".note.GNU-stack", flags
, NULL
));
6927 /* Output DIRECTIVE (a C string) followed by a newline. This is used as
6928 a get_unnamed_section callback. */
6931 output_section_asm_op (const void *directive
)
6933 fprintf (asm_out_file
, "%s\n", (const char *) directive
);
6936 /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
6937 the current section is NEW_SECTION. */
6940 switch_to_section (section
*new_section
)
6942 if (in_section
== new_section
)
6945 if (new_section
->common
.flags
& SECTION_FORGET
)
6948 in_section
= new_section
;
6950 switch (SECTION_STYLE (new_section
))
6954 && !crtl
->subsections
.unlikely_text_section_name
6955 && strcmp (new_section
->named
.name
,
6956 UNLIKELY_EXECUTED_TEXT_SECTION_NAME
) == 0)
6957 crtl
->subsections
.unlikely_text_section_name
= UNLIKELY_EXECUTED_TEXT_SECTION_NAME
;
6959 targetm
.asm_out
.named_section (new_section
->named
.name
,
6960 new_section
->named
.common
.flags
,
6961 new_section
->named
.decl
);
6964 case SECTION_UNNAMED
:
6965 new_section
->unnamed
.callback (new_section
->unnamed
.data
);
6968 case SECTION_NOSWITCH
:
6973 new_section
->common
.flags
|= SECTION_DECLARED
;
6976 /* If block symbol SYMBOL has not yet been assigned an offset, place
6977 it at the end of its block. */
6980 place_block_symbol (rtx symbol
)
6982 unsigned HOST_WIDE_INT size
, mask
, offset
;
6983 struct constant_descriptor_rtx
*desc
;
6984 unsigned int alignment
;
6985 struct object_block
*block
;
6988 gcc_assert (SYMBOL_REF_BLOCK (symbol
));
6989 if (SYMBOL_REF_BLOCK_OFFSET (symbol
) >= 0)
6992 /* Work out the symbol's size and alignment. */
6993 if (CONSTANT_POOL_ADDRESS_P (symbol
))
6995 desc
= SYMBOL_REF_CONSTANT (symbol
);
6996 alignment
= desc
->align
;
6997 size
= GET_MODE_SIZE (desc
->mode
);
6999 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7001 decl
= SYMBOL_REF_DECL (symbol
);
7002 alignment
= DECL_ALIGN (decl
);
7003 size
= get_constant_size (DECL_INITIAL (decl
));
7007 decl
= SYMBOL_REF_DECL (symbol
);
7008 alignment
= DECL_ALIGN (decl
);
7009 size
= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7012 /* Calculate the object's offset from the start of the block. */
7013 block
= SYMBOL_REF_BLOCK (symbol
);
7014 mask
= alignment
/ BITS_PER_UNIT
- 1;
7015 offset
= (block
->size
+ mask
) & ~mask
;
7016 SYMBOL_REF_BLOCK_OFFSET (symbol
) = offset
;
7018 /* Record the block's new alignment and size. */
7019 block
->alignment
= MAX (block
->alignment
, alignment
);
7020 block
->size
= offset
+ size
;
7022 VEC_safe_push (rtx
, gc
, block
->objects
, symbol
);
7025 /* Return the anchor that should be used to address byte offset OFFSET
7026 from the first object in BLOCK. MODEL is the TLS model used
7030 get_section_anchor (struct object_block
*block
, HOST_WIDE_INT offset
,
7031 enum tls_model model
)
7034 unsigned int begin
, middle
, end
;
7035 unsigned HOST_WIDE_INT min_offset
, max_offset
, range
, bias
, delta
;
7038 /* Work out the anchor's offset. Use an offset of 0 for the first
7039 anchor so that we don't pessimize the case where we take the address
7040 of a variable at the beginning of the block. This is particularly
7041 useful when a block has only one variable assigned to it.
7043 We try to place anchors RANGE bytes apart, so there can then be
7044 anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
7045 a ptr_mode offset. With some target settings, the lowest such
7046 anchor might be out of range for the lowest ptr_mode offset;
7047 likewise the highest anchor for the highest offset. Use anchors
7048 at the extreme ends of the ptr_mode range in such cases.
7050 All arithmetic uses unsigned integers in order to avoid
7052 max_offset
= (unsigned HOST_WIDE_INT
) targetm
.max_anchor_offset
;
7053 min_offset
= (unsigned HOST_WIDE_INT
) targetm
.min_anchor_offset
;
7054 range
= max_offset
- min_offset
+ 1;
7059 bias
= 1 << (GET_MODE_BITSIZE (ptr_mode
) - 1);
7062 delta
= -(unsigned HOST_WIDE_INT
) offset
+ max_offset
;
7063 delta
-= delta
% range
;
7066 offset
= (HOST_WIDE_INT
) (-delta
);
7070 delta
= (unsigned HOST_WIDE_INT
) offset
- min_offset
;
7071 delta
-= delta
% range
;
7072 if (delta
> bias
- 1)
7074 offset
= (HOST_WIDE_INT
) delta
;
7078 /* Do a binary search to see if there's already an anchor we can use.
7079 Set BEGIN to the new anchor's index if not. */
7081 end
= VEC_length (rtx
, block
->anchors
);
7082 while (begin
!= end
)
7084 middle
= (end
+ begin
) / 2;
7085 anchor
= VEC_index (rtx
, block
->anchors
, middle
);
7086 if (SYMBOL_REF_BLOCK_OFFSET (anchor
) > offset
)
7088 else if (SYMBOL_REF_BLOCK_OFFSET (anchor
) < offset
)
7090 else if (SYMBOL_REF_TLS_MODEL (anchor
) > model
)
7092 else if (SYMBOL_REF_TLS_MODEL (anchor
) < model
)
7098 /* Create a new anchor with a unique label. */
7099 ASM_GENERATE_INTERNAL_LABEL (label
, "LANCHOR", anchor_labelno
++);
7100 anchor
= create_block_symbol (ggc_strdup (label
), block
, offset
);
7101 SYMBOL_REF_FLAGS (anchor
) |= SYMBOL_FLAG_LOCAL
| SYMBOL_FLAG_ANCHOR
;
7102 SYMBOL_REF_FLAGS (anchor
) |= model
<< SYMBOL_FLAG_TLS_SHIFT
;
7104 /* Insert it at index BEGIN. */
7105 VEC_safe_insert (rtx
, gc
, block
->anchors
, begin
, anchor
);
7109 /* Output the objects in BLOCK. */
7112 output_object_block (struct object_block
*block
)
7114 struct constant_descriptor_rtx
*desc
;
7116 HOST_WIDE_INT offset
;
7120 if (block
->objects
== NULL
)
7123 /* Switch to the section and make sure that the first byte is
7124 suitably aligned. */
7125 switch_to_section (block
->sect
);
7126 assemble_align (block
->alignment
);
7128 /* Define the values of all anchors relative to the current section
7130 for (i
= 0; VEC_iterate (rtx
, block
->anchors
, i
, symbol
); i
++)
7131 targetm
.asm_out
.output_anchor (symbol
);
7133 /* Output the objects themselves. */
7135 for (i
= 0; VEC_iterate (rtx
, block
->objects
, i
, symbol
); i
++)
7137 /* Move to the object's offset, padding with zeros if necessary. */
7138 assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol
) - offset
);
7139 offset
= SYMBOL_REF_BLOCK_OFFSET (symbol
);
7140 if (CONSTANT_POOL_ADDRESS_P (symbol
))
7142 desc
= SYMBOL_REF_CONSTANT (symbol
);
7143 output_constant_pool_1 (desc
, 1);
7144 offset
+= GET_MODE_SIZE (desc
->mode
);
7146 else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol
))
7148 decl
= SYMBOL_REF_DECL (symbol
);
7149 assemble_constant_contents (DECL_INITIAL (decl
), XSTR (symbol
, 0),
7151 offset
+= get_constant_size (DECL_INITIAL (decl
));
7155 decl
= SYMBOL_REF_DECL (symbol
);
7156 assemble_variable_contents (decl
, XSTR (symbol
, 0), false);
7157 offset
+= tree_low_cst (DECL_SIZE_UNIT (decl
), 1);
7162 /* A htab_traverse callback used to call output_object_block for
7163 each member of object_block_htab. */
7166 output_object_block_htab (void **slot
, void *data ATTRIBUTE_UNUSED
)
7168 output_object_block ((struct object_block
*) (*slot
));
7172 /* Output the definitions of all object_blocks. */
7175 output_object_blocks (void)
7177 htab_traverse (object_block_htab
, output_object_block_htab
, NULL
);
7180 /* This function provides a possible implementation of the
7181 TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
7182 by -frecord-gcc-switches it creates a new mergeable, string section in the
7183 assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
7184 contains the switches in ASCII format.
7186 FIXME: This code does not correctly handle double quote characters
7187 that appear inside strings, (it strips them rather than preserving them).
7188 FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
7189 characters - instead it treats them as sub-string separators. Since
7190 we want to emit NUL strings terminators into the object file we have to use
7194 elf_record_gcc_switches (print_switch_type type
, const char * name
)
7196 static char buffer
[1024];
7198 /* This variable is used as part of a simplistic heuristic to detect
7199 command line switches which take an argument:
7201 "If a command line option does not start with a dash then
7202 it is an argument for the previous command line option."
7204 This fails in the case of the command line option which is the name
7205 of the file to compile, but otherwise it is pretty reasonable. */
7206 static bool previous_name_held_back
= FALSE
;
7210 case SWITCH_TYPE_PASSED
:
7213 if (previous_name_held_back
)
7215 unsigned int len
= strlen (buffer
);
7217 snprintf (buffer
+ len
, sizeof buffer
- len
, " %s", name
);
7218 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7219 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7220 previous_name_held_back
= FALSE
;
7224 strncpy (buffer
, name
, sizeof buffer
);
7225 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7226 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7231 if (previous_name_held_back
)
7233 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7234 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7237 strncpy (buffer
, name
, sizeof buffer
);
7238 previous_name_held_back
= TRUE
;
7242 case SWITCH_TYPE_DESCRIPTIVE
:
7245 /* Distinguish between invocations where name is NULL. */
7246 static bool started
= false;
7250 if (previous_name_held_back
)
7252 ASM_OUTPUT_ASCII (asm_out_file
, buffer
, strlen (buffer
));
7253 ASM_OUTPUT_SKIP (asm_out_file
, (unsigned HOST_WIDE_INT
) 1);
7260 sec
= get_section (targetm
.asm_out
.record_gcc_switches_section
,
7264 | (SECTION_ENTSIZE
& 1),
7266 switch_to_section (sec
);
7275 /* The return value is currently ignored by the caller, but must be 0.
7276 For -fverbose-asm the return value would be the number of characters
7277 emitted into the assembler file. */
7281 /* Emit text to declare externally defined symbols. It is needed to
7282 properly support non-default visibility. */
7284 default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED
,
7286 const char *name ATTRIBUTE_UNUSED
)
7288 /* We output the name if and only if TREE_SYMBOL_REFERENCED is
7289 set in order to avoid putting out names that are never really
7291 if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl
))
7292 && targetm
.binds_local_p (decl
))
7293 maybe_assemble_visibility (decl
);
7296 /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
7299 make_debug_expr_from_rtl (const_rtx exp
)
7301 tree ddecl
= make_node (DEBUG_EXPR_DECL
), type
;
7302 enum machine_mode mode
= GET_MODE (exp
);
7305 DECL_ARTIFICIAL (ddecl
) = 1;
7306 if (REG_P (exp
) && REG_EXPR (exp
))
7307 type
= TREE_TYPE (REG_EXPR (exp
));
7308 else if (MEM_P (exp
) && MEM_EXPR (exp
))
7309 type
= TREE_TYPE (MEM_EXPR (exp
));
7312 if (type
&& TYPE_MODE (type
) == mode
)
7313 TREE_TYPE (ddecl
) = type
;
7315 TREE_TYPE (ddecl
) = lang_hooks
.types
.type_for_mode (mode
, 1);
7316 DECL_MODE (ddecl
) = mode
;
7317 dval
= gen_rtx_DEBUG_EXPR (mode
);
7318 DEBUG_EXPR_TREE_DECL (dval
) = ddecl
;
7319 SET_DECL_RTL (ddecl
, dval
);
7323 #include "gt-varasm.h"