Branch data Line data Source code
1 : : /* Output variables, constants and external declarations, for GNU compiler.
2 : : Copyright (C) 1987-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : :
21 : : /* This file handles generation of all the assembler code
22 : : *except* the instructions of a function.
23 : : This includes declarations of variables and their initial values.
24 : :
25 : : We also output the assembler code for constants stored in memory
26 : : and are responsible for combining constants with the same value. */
27 : :
28 : : #include "config.h"
29 : : #include "system.h"
30 : : #include "coretypes.h"
31 : : #include "backend.h"
32 : : #include "target.h"
33 : : #include "rtl.h"
34 : : #include "tree.h"
35 : : #include "predict.h"
36 : : #include "memmodel.h"
37 : : #include "tm_p.h"
38 : : #include "stringpool.h"
39 : : #include "regs.h"
40 : : #include "emit-rtl.h"
41 : : #include "cgraph.h"
42 : : #include "diagnostic-core.h"
43 : : #include "fold-const.h"
44 : : #include "stor-layout.h"
45 : : #include "varasm.h"
46 : : #include "version.h"
47 : : #include "flags.h"
48 : : #include "stmt.h"
49 : : #include "expr.h"
50 : : #include "expmed.h"
51 : : #include "optabs.h"
52 : : #include "output.h"
53 : : #include "langhooks.h"
54 : : #include "debug.h"
55 : : #include "common/common-target.h"
56 : : #include "stringpool.h"
57 : : #include "attribs.h"
58 : : #include "asan.h"
59 : : #include "rtl-iter.h"
60 : : #include "file-prefix-map.h" /* remap_debug_filename() */
61 : : #include "alloc-pool.h"
62 : : #include "toplev.h"
63 : : #include "opts.h"
64 : : #include "asan.h"
65 : : #include "recog.h"
66 : : #include "gimple-expr.h"
67 : :
68 : : /* The (assembler) name of the first globally-visible object output. */
69 : : extern GTY(()) const char *first_global_object_name;
70 : : extern GTY(()) const char *weak_global_object_name;
71 : :
72 : : const char *first_global_object_name;
73 : : const char *weak_global_object_name;
74 : :
75 : : class addr_const;
76 : : class constant_descriptor_rtx;
77 : : struct rtx_constant_pool;
78 : :
79 : : #define n_deferred_constants (crtl->varasm.deferred_constants)
80 : :
81 : : /* Number for making the label on the next
82 : : constant that is stored in memory. */
83 : :
84 : : static GTY(()) int const_labelno;
85 : :
86 : : /* Carry information from ASM_DECLARE_OBJECT_NAME
87 : : to ASM_FINISH_DECLARE_OBJECT. */
88 : :
89 : : int size_directive_output;
90 : :
91 : : /* The last decl for which assemble_variable was called,
92 : : if it did ASM_DECLARE_OBJECT_NAME.
93 : : If the last call to assemble_variable didn't do that,
94 : : this holds 0. */
95 : :
96 : : tree last_assemble_variable_decl;
97 : :
98 : : /* The following global variable indicates if the first basic block
99 : : in a function belongs to the cold partition or not. */
100 : :
101 : : bool first_function_block_is_cold;
102 : :
103 : : /* Whether we saw any functions with no_split_stack. */
104 : :
105 : : static bool saw_no_split_stack;
106 : :
107 : : static const char *strip_reg_name (const char *);
108 : : static bool contains_pointers_p (tree);
109 : : #ifdef ASM_OUTPUT_EXTERNAL
110 : : static bool incorporeal_function_p (tree);
111 : : #endif
112 : : static void decode_addr_const (tree, class addr_const *);
113 : : static hashval_t const_hash_1 (const tree);
114 : : static bool compare_constant (const tree, const tree);
115 : : static void output_constant_def_contents (rtx);
116 : : static void output_addressed_constants (tree, int);
117 : : static unsigned HOST_WIDE_INT output_constant (tree, unsigned HOST_WIDE_INT,
118 : : unsigned int, bool, bool);
119 : : static void globalize_decl (tree);
120 : : static bool decl_readonly_section_1 (enum section_category);
121 : : #ifdef BSS_SECTION_ASM_OP
122 : : #ifdef ASM_OUTPUT_ALIGNED_BSS
123 : : static void asm_output_aligned_bss (FILE *, tree, const char *,
124 : : unsigned HOST_WIDE_INT, int)
125 : : ATTRIBUTE_UNUSED;
126 : : #endif
127 : : #endif /* BSS_SECTION_ASM_OP */
128 : : static void mark_weak (tree);
129 : : static void output_constant_pool (const char *, tree);
130 : : static void handle_vtv_comdat_section (section *, const_tree);
131 : :
132 : : /* Well-known sections, each one associated with some sort of *_ASM_OP. */
133 : : section *text_section;
134 : : section *data_section;
135 : : section *readonly_data_section;
136 : : section *sdata_section;
137 : : section *ctors_section;
138 : : section *dtors_section;
139 : : section *bss_section;
140 : : section *sbss_section;
141 : :
142 : : /* Various forms of common section. All are guaranteed to be nonnull. */
143 : : section *tls_comm_section;
144 : : section *comm_section;
145 : : section *lcomm_section;
146 : :
147 : : /* A SECTION_NOSWITCH section used for declaring global BSS variables.
148 : : May be null. */
149 : : section *bss_noswitch_section;
150 : :
151 : : /* The section that holds the main exception table, when known. The section
152 : : is set either by the target's init_sections hook or by the first call to
153 : : switch_to_exception_section. */
154 : : section *exception_section;
155 : :
156 : : /* The section that holds the DWARF2 frame unwind information, when known.
157 : : The section is set either by the target's init_sections hook or by the
158 : : first call to switch_to_eh_frame_section. */
159 : : section *eh_frame_section;
160 : :
161 : : /* asm_out_file's current section. This is NULL if no section has yet
162 : : been selected or if we lose track of what the current section is. */
163 : : section *in_section;
164 : :
165 : : /* True if code for the current function is currently being directed
166 : : at the cold section. */
167 : : bool in_cold_section_p;
168 : :
169 : : /* The following global holds the "function name" for the code in the
170 : : cold section of a function, if hot/cold function splitting is enabled
171 : : and there was actually code that went into the cold section. A
172 : : pseudo function name is needed for the cold section of code for some
173 : : debugging tools that perform symbolization. */
174 : : tree cold_function_name = NULL_TREE;
175 : :
176 : : /* A linked list of all the unnamed sections. */
177 : : static GTY(()) section *unnamed_sections;
178 : :
179 : : /* Return a nonzero value if DECL has a section attribute. */
180 : : #define IN_NAMED_SECTION(DECL) \
181 : : (VAR_OR_FUNCTION_DECL_P (DECL) && DECL_SECTION_NAME (DECL) != NULL)
182 : :
183 : : struct section_hasher : ggc_ptr_hash<section>
184 : : {
185 : : typedef const char *compare_type;
186 : :
187 : : static hashval_t hash (section *);
188 : : static bool equal (section *, const char *);
189 : : };
190 : :
191 : : /* Hash table of named sections. */
192 : : static GTY(()) hash_table<section_hasher> *section_htab;
193 : :
194 : : struct object_block_hasher : ggc_ptr_hash<object_block>
195 : : {
196 : : typedef const section *compare_type;
197 : :
198 : : static hashval_t hash (object_block *);
199 : : static bool equal (object_block *, const section *);
200 : : };
201 : :
202 : : /* A table of object_blocks, indexed by section. */
203 : : static GTY(()) hash_table<object_block_hasher> *object_block_htab;
204 : :
205 : : /* The next number to use for internal anchor labels. */
206 : : static GTY(()) int anchor_labelno;
207 : :
208 : : /* A pool of constants that can be shared between functions. */
209 : : static GTY(()) struct rtx_constant_pool *shared_constant_pool;
210 : :
211 : : /* Helper routines for maintaining section_htab. */
212 : :
213 : : bool
214 : 373952376 : section_hasher::equal (section *old, const char *new_name)
215 : : {
216 : 373952376 : return strcmp (old->named.name, new_name) == 0;
217 : : }
218 : :
219 : : hashval_t
220 : 273745860 : section_hasher::hash (section *old)
221 : : {
222 : 273745860 : return htab_hash_string (old->named.name);
223 : : }
224 : :
225 : : /* Return a hash value for section SECT. */
226 : :
227 : : static hashval_t
228 : 0 : hash_section (section *sect)
229 : : {
230 : 0 : if (sect->common.flags & SECTION_NAMED)
231 : 0 : return htab_hash_string (sect->named.name);
232 : 0 : return sect->common.flags & ~SECTION_DECLARED;
233 : : }
234 : :
235 : : /* Helper routines for maintaining object_block_htab. */
236 : :
237 : : inline bool
238 : 0 : object_block_hasher::equal (object_block *old, const section *new_section)
239 : : {
240 : 0 : return old->sect == new_section;
241 : : }
242 : :
243 : : hashval_t
244 : 0 : object_block_hasher::hash (object_block *old)
245 : : {
246 : 0 : return hash_section (old->sect);
247 : : }
248 : :
249 : : /* Return a new unnamed section with the given fields. */
250 : :
251 : : section *
252 : 1098048 : get_unnamed_section (unsigned int flags, void (*callback) (const char *),
253 : : const char *data)
254 : : {
255 : 1098048 : section *sect;
256 : :
257 : 1098048 : sect = ggc_alloc<section> ();
258 : 1098048 : sect->unnamed.common.flags = flags | SECTION_UNNAMED;
259 : 1098048 : sect->unnamed.callback = callback;
260 : 1098048 : sect->unnamed.data = data;
261 : 1098048 : sect->unnamed.next = unnamed_sections;
262 : :
263 : 1098048 : unnamed_sections = sect;
264 : 1098048 : return sect;
265 : : }
266 : :
267 : : /* Return a SECTION_NOSWITCH section with the given fields. */
268 : :
269 : : static section *
270 : 1098048 : get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
271 : : {
272 : 1098048 : section *sect;
273 : :
274 : 0 : sect = ggc_alloc<section> ();
275 : 1098048 : sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
276 : 1098048 : sect->noswitch.callback = callback;
277 : :
278 : 1098048 : return sect;
279 : : }
280 : :
281 : : /* Return the named section structure associated with NAME. Create
282 : : a new section with the given fields if no such structure exists.
283 : : When NOT_EXISTING, then fail if the section already exists. Return
284 : : the existing section if the SECTION_RETAIN bit doesn't match. Set
285 : : the SECTION_WRITE | SECTION_RELRO bits on the existing section
286 : : if one of the section flags is SECTION_WRITE | SECTION_RELRO and the
287 : : other has none of these flags in named sections and either the section
288 : : hasn't been declared yet or has been declared as writable. */
289 : :
290 : : section *
291 : 59626002 : get_section (const char *name, unsigned int flags, tree decl,
292 : : bool not_existing)
293 : : {
294 : 59626002 : section *sect, **slot;
295 : :
296 : 59626002 : slot = section_htab->find_slot_with_hash (name, htab_hash_string (name),
297 : : INSERT);
298 : 59626002 : flags |= SECTION_NAMED;
299 : 59626002 : if (decl != nullptr
300 : 57669061 : && DECL_P (decl)
301 : 117295063 : && lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
302 : 454 : flags |= SECTION_RETAIN;
303 : 59626002 : if (*slot == NULL)
304 : : {
305 : 3375443 : sect = ggc_alloc<section> ();
306 : 3375443 : sect->named.common.flags = flags;
307 : 3375443 : sect->named.name = ggc_strdup (name);
308 : 3375443 : sect->named.decl = decl;
309 : 3375443 : *slot = sect;
310 : : }
311 : : else
312 : : {
313 : 56250559 : if (not_existing)
314 : 0 : internal_error ("section already exists: %qs", name);
315 : :
316 : 56250559 : sect = *slot;
317 : : /* It is fine if one of the sections has SECTION_NOTYPE as long as
318 : : the other has none of the contrary flags (see the logic at the end
319 : : of default_section_type_flags, below). */
320 : 56250559 : if (((sect->common.flags ^ flags) & SECTION_NOTYPE)
321 : 5 : && !((sect->common.flags | flags)
322 : 5 : & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE
323 : : | (HAVE_COMDAT_GROUP ? SECTION_LINKONCE : 0))))
324 : : {
325 : 3 : sect->common.flags |= SECTION_NOTYPE;
326 : 3 : flags |= SECTION_NOTYPE;
327 : : }
328 : 56250559 : if ((sect->common.flags & ~SECTION_DECLARED) != flags
329 : 54 : && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0)
330 : : {
331 : : /* It is fine if one of the section flags is
332 : : SECTION_WRITE | SECTION_RELRO and the other has none of these
333 : : flags (i.e. read-only) in named sections and either the
334 : : section hasn't been declared yet or has been declared as writable.
335 : : In that case just make sure the resulting flags are
336 : : SECTION_WRITE | SECTION_RELRO, ie. writable only because of
337 : : relocations. */
338 : 50 : if (((sect->common.flags ^ flags) & (SECTION_WRITE | SECTION_RELRO))
339 : : == (SECTION_WRITE | SECTION_RELRO)
340 : 8 : && (sect->common.flags
341 : 8 : & ~(SECTION_DECLARED | SECTION_WRITE | SECTION_RELRO))
342 : 8 : == (flags & ~(SECTION_WRITE | SECTION_RELRO))
343 : 8 : && ((sect->common.flags & SECTION_DECLARED) == 0
344 : 8 : || (sect->common.flags & SECTION_WRITE)))
345 : : {
346 : 8 : sect->common.flags |= (SECTION_WRITE | SECTION_RELRO);
347 : 8 : return sect;
348 : : }
349 : : /* If the SECTION_RETAIN bit doesn't match, return and switch
350 : : to a new section later. */
351 : 42 : if ((sect->common.flags & SECTION_RETAIN)
352 : 42 : != (flags & SECTION_RETAIN))
353 : : return sect;
354 : : /* Sanity check user variables for flag changes. */
355 : 2 : if (sect->named.decl != NULL
356 : 2 : && DECL_P (sect->named.decl)
357 : 2 : && decl != sect->named.decl)
358 : : {
359 : 2 : if (decl != NULL && DECL_P (decl))
360 : 2 : error ("%+qD causes a section type conflict with %qD"
361 : : " in section %qs",
362 : : decl, sect->named.decl, name);
363 : : else
364 : 0 : error ("section type conflict with %qD in section %qs",
365 : : sect->named.decl, name);
366 : 2 : inform (DECL_SOURCE_LOCATION (sect->named.decl),
367 : : "%qD was declared here", sect->named.decl);
368 : : }
369 : 0 : else if (decl != NULL && DECL_P (decl))
370 : 0 : error ("%+qD causes a section type conflict for section %qs",
371 : : decl, name);
372 : : else
373 : 0 : error ("section type conflict for section %qs", name);
374 : : /* Make sure we don't error about one section multiple times. */
375 : 2 : sect->common.flags |= SECTION_OVERRIDE;
376 : : }
377 : : }
378 : : return sect;
379 : : }
380 : :
381 : : /* Return true if the current compilation mode benefits from having
382 : : objects grouped into blocks. */
383 : :
384 : : static bool
385 : 9986059 : use_object_blocks_p (void)
386 : : {
387 : 9986059 : return flag_section_anchors;
388 : : }
389 : :
390 : : /* Return the object_block structure for section SECT. Create a new
391 : : structure if we haven't created one already. Return null if SECT
392 : : itself is null. Return also null for mergeable sections since
393 : : section anchors can't be used in mergeable sections anyway,
394 : : because the linker might move objects around, and using the
395 : : object blocks infrastructure in that case is both a waste and a
396 : : maintenance burden. */
397 : :
398 : : static struct object_block *
399 : 0 : get_block_for_section (section *sect)
400 : : {
401 : 0 : struct object_block *block;
402 : :
403 : 0 : if (sect == NULL)
404 : : return NULL;
405 : :
406 : 0 : if (sect->common.flags & SECTION_MERGE)
407 : : return NULL;
408 : :
409 : 0 : object_block **slot
410 : 0 : = object_block_htab->find_slot_with_hash (sect, hash_section (sect),
411 : : INSERT);
412 : 0 : block = *slot;
413 : 0 : if (block == NULL)
414 : : {
415 : 0 : block = ggc_cleared_alloc<object_block> ();
416 : 0 : block->sect = sect;
417 : 0 : *slot = block;
418 : : }
419 : : return block;
420 : : }
421 : :
422 : : /* Create a symbol with label LABEL and place it at byte offset
423 : : OFFSET in BLOCK. OFFSET can be negative if the symbol's offset
424 : : is not yet known. LABEL must be a garbage-collected string. */
425 : :
426 : : static rtx
427 : 0 : create_block_symbol (const char *label, struct object_block *block,
428 : : HOST_WIDE_INT offset)
429 : : {
430 : 0 : rtx symbol;
431 : 0 : unsigned int size;
432 : :
433 : : /* Create the extended SYMBOL_REF. */
434 : 0 : size = RTX_HDR_SIZE + sizeof (struct block_symbol);
435 : 0 : symbol = (rtx) ggc_internal_alloc (size);
436 : :
437 : : /* Initialize the normal SYMBOL_REF fields. */
438 : 0 : memset (symbol, 0, size);
439 : 0 : PUT_CODE (symbol, SYMBOL_REF);
440 : 0 : PUT_MODE (symbol, Pmode);
441 : 0 : XSTR (symbol, 0) = label;
442 : 0 : SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO;
443 : :
444 : : /* Initialize the block_symbol stuff. */
445 : 0 : SYMBOL_REF_BLOCK (symbol) = block;
446 : 0 : SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
447 : :
448 : 0 : return symbol;
449 : : }
450 : :
451 : : /* Return a section with a particular name and with whatever SECTION_*
452 : : flags section_type_flags deems appropriate. The name of the section
453 : : is taken from NAME if nonnull, otherwise it is taken from DECL's
454 : : DECL_SECTION_NAME. DECL is the decl associated with the section
455 : : (see the section comment for details) and RELOC is as for
456 : : section_type_flags. */
457 : :
458 : : section *
459 : 57508425 : get_named_section (tree decl, const char *name, int reloc)
460 : : {
461 : 57508425 : unsigned int flags;
462 : :
463 : 57508425 : if (name == NULL)
464 : : {
465 : 51196752 : gcc_assert (decl && DECL_P (decl) && DECL_SECTION_NAME (decl));
466 : 51196752 : name = DECL_SECTION_NAME (decl);
467 : : }
468 : :
469 : 57508425 : flags = targetm.section_type_flags (decl, name, reloc);
470 : 57508425 : return get_section (name, flags, decl);
471 : : }
472 : :
473 : : /* Worker for resolve_unique_section. */
474 : :
475 : : static bool
476 : 1810612 : set_implicit_section (struct symtab_node *n, void *data ATTRIBUTE_UNUSED)
477 : : {
478 : 1810612 : n->implicit_section = true;
479 : 1810612 : return false;
480 : : }
481 : :
482 : : /* If required, set DECL_SECTION_NAME to a unique name. */
483 : :
484 : : void
485 : 7380649 : resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
486 : : int flag_function_or_data_sections)
487 : : {
488 : 7380649 : if (DECL_SECTION_NAME (decl) == NULL
489 : 4510302 : && targetm_common.have_named_sections
490 : 11890951 : && (flag_function_or_data_sections
491 : 2849679 : || lookup_attribute ("retain", DECL_ATTRIBUTES (decl))
492 : 2849561 : || DECL_COMDAT_GROUP (decl)))
493 : : {
494 : 1770527 : targetm.asm_out.unique_section (decl, reloc);
495 : 1770527 : if (DECL_SECTION_NAME (decl))
496 : 1770527 : symtab_node::get (decl)->call_for_symbol_and_aliases
497 : 1770527 : (set_implicit_section, NULL, true);
498 : : }
499 : 7380649 : }
500 : :
501 : : #ifdef BSS_SECTION_ASM_OP
502 : :
503 : : #ifdef ASM_OUTPUT_ALIGNED_BSS
504 : :
505 : : /* Utility function for targets to use in implementing
506 : : ASM_OUTPUT_ALIGNED_BSS.
507 : : ??? It is believed that this function will work in most cases so such
508 : : support is localized here. */
509 : :
510 : : static void
511 : 0 : asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED,
512 : : const char *name, unsigned HOST_WIDE_INT size,
513 : : int align)
514 : : {
515 : 0 : switch_to_section (bss_section);
516 : 0 : ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
517 : : #ifdef ASM_DECLARE_OBJECT_NAME
518 : 0 : last_assemble_variable_decl = decl;
519 : 0 : ASM_DECLARE_OBJECT_NAME (file, name, decl);
520 : : #else
521 : : /* Standard thing is just output label for the object. */
522 : : ASM_OUTPUT_LABEL (file, name);
523 : : #endif /* ASM_DECLARE_OBJECT_NAME */
524 : 0 : ASM_OUTPUT_SKIP (file, size ? size : 1);
525 : 0 : }
526 : :
527 : : #endif
528 : :
529 : : #endif /* BSS_SECTION_ASM_OP */
530 : :
531 : : #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS
532 : : /* Return the hot section for function DECL. Return text_section for
533 : : null DECLs. */
534 : :
535 : : static section *
536 : 72728552 : hot_function_section (tree decl)
537 : : {
538 : 72728552 : if (decl != NULL_TREE
539 : 72728552 : && DECL_SECTION_NAME (decl) != NULL
540 : 120974138 : && targetm_common.have_named_sections)
541 : 48245586 : return get_named_section (decl, NULL, 0);
542 : : else
543 : 24482966 : return text_section;
544 : : }
545 : : #endif
546 : :
547 : : /* Return section for TEXT_SECTION_NAME if DECL or DECL_SECTION_NAME (DECL)
548 : : is NULL.
549 : :
550 : : When DECL_SECTION_NAME is non-NULL and it is implicit section and
551 : : NAMED_SECTION_SUFFIX is non-NULL, then produce section called
552 : : concatenate the name with NAMED_SECTION_SUFFIX.
553 : : Otherwise produce "TEXT_SECTION_NAME.IMPLICIT_NAME". */
554 : :
555 : : section *
556 : 6306485 : get_named_text_section (tree decl,
557 : : const char *text_section_name,
558 : : const char *named_section_suffix)
559 : : {
560 : 6306485 : if (decl && DECL_SECTION_NAME (decl))
561 : : {
562 : 5441360 : if (named_section_suffix)
563 : : {
564 : 0 : const char *dsn = DECL_SECTION_NAME (decl);
565 : 0 : const char *stripped_name;
566 : 0 : char *name, *buffer;
567 : :
568 : 0 : name = (char *) alloca (strlen (dsn) + 1);
569 : 0 : memcpy (name, dsn,
570 : 0 : strlen (dsn) + 1);
571 : :
572 : 0 : stripped_name = targetm.strip_name_encoding (name);
573 : :
574 : 0 : buffer = ACONCAT ((stripped_name, named_section_suffix, NULL));
575 : 0 : return get_named_section (decl, buffer, 0);
576 : : }
577 : 5441360 : else if (symtab_node::get (decl)->implicit_section)
578 : : {
579 : 5441339 : const char *name;
580 : :
581 : : /* Do not try to split gnu_linkonce functions. This gets somewhat
582 : : slipperly. */
583 : 5441339 : if (DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP)
584 : : return NULL;
585 : 5441339 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
586 : 5441339 : name = targetm.strip_name_encoding (name);
587 : 5441339 : return get_named_section (decl, ACONCAT ((text_section_name, ".",
588 : 5441339 : name, NULL)), 0);
589 : : }
590 : : else
591 : : return NULL;
592 : : }
593 : 865125 : return get_named_section (decl, text_section_name, 0);
594 : : }
595 : :
596 : : /* Choose named function section based on its frequency. */
597 : :
598 : : section *
599 : 79035016 : default_function_section (tree decl, enum node_frequency freq,
600 : : bool startup, bool exit)
601 : : {
602 : : #if defined HAVE_LD_EH_GC_SECTIONS && defined HAVE_LD_EH_GC_SECTIONS_BUG
603 : : /* Old GNU linkers have buggy --gc-section support, which sometimes
604 : : results in .gcc_except_table* sections being garbage collected. */
605 : : if (decl
606 : : && symtab_node::get (decl)->implicit_section)
607 : : return NULL;
608 : : #endif
609 : :
610 : 79035016 : if (!flag_reorder_functions
611 : 76714642 : || !targetm_common.have_named_sections)
612 : : return NULL;
613 : : /* Startup code should go to startup subsection unless it is
614 : : unlikely executed (this happens especially with function splitting
615 : : where we can split away unnecessary parts of static constructors. */
616 : 76714642 : if (startup && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
617 : : {
618 : : /* During LTO the tp_first_run profiling will naturally place all
619 : : initialization code first. Using separate section is counter-productive
620 : : because startup only code may call functions which are no longer
621 : : startup only. */
622 : 1139151 : if (!in_lto_p
623 : 35265 : || !cgraph_node::get (decl)->tp_first_run
624 : 1139159 : || !opt_for_fn (decl, flag_profile_reorder_functions))
625 : 1139143 : return get_named_text_section (decl, ".text.startup", NULL);
626 : : else
627 : : return NULL;
628 : : }
629 : :
630 : : /* Similarly for exit. */
631 : 75575491 : if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
632 : 3864 : return get_named_text_section (decl, ".text.exit", NULL);
633 : :
634 : : /* Group cold functions together, similarly for hot code. */
635 : 75571627 : switch (freq)
636 : : {
637 : 5162858 : case NODE_FREQUENCY_UNLIKELY_EXECUTED:
638 : 5162858 : return get_named_text_section (decl, ".text.unlikely", NULL);
639 : 620 : case NODE_FREQUENCY_HOT:
640 : 620 : return get_named_text_section (decl, ".text.hot", NULL);
641 : : /* FALLTHRU */
642 : : default:
643 : : return NULL;
644 : : }
645 : : }
646 : :
647 : : /* Return the section for function DECL.
648 : :
649 : : If DECL is NULL_TREE, return the text section. We can be passed
650 : : NULL_TREE under some circumstances by dbxout.cc at least.
651 : :
652 : : If FORCE_COLD is true, return cold function section ignoring
653 : : the frequency info of cgraph_node. */
654 : :
655 : : static section *
656 : 79035016 : function_section_1 (tree decl, bool force_cold)
657 : : {
658 : 79035016 : section *section = NULL;
659 : 79035016 : enum node_frequency freq = NODE_FREQUENCY_NORMAL;
660 : 79035016 : bool startup = false, exit = false;
661 : :
662 : 79035016 : if (decl)
663 : : {
664 : 79035016 : struct cgraph_node *node = cgraph_node::get (decl);
665 : :
666 : 79035016 : if (node)
667 : : {
668 : 79035016 : freq = node->frequency;
669 : 79035016 : startup = node->only_called_at_startup;
670 : 79035016 : exit = node->only_called_at_exit;
671 : : }
672 : : }
673 : 79035016 : if (force_cold)
674 : 5044952 : freq = NODE_FREQUENCY_UNLIKELY_EXECUTED;
675 : :
676 : : #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS
677 : : if (decl != NULL_TREE
678 : : && DECL_SECTION_NAME (decl) != NULL)
679 : : {
680 : : if (targetm.asm_out.function_section)
681 : : section = targetm.asm_out.function_section (decl, freq,
682 : : startup, exit);
683 : : if (section)
684 : : return section;
685 : : return get_named_section (decl, NULL, 0);
686 : : }
687 : : else
688 : : return targetm.asm_out.select_section
689 : : (decl, freq == NODE_FREQUENCY_UNLIKELY_EXECUTED,
690 : : symtab_node::get (decl)->definition_alignment ());
691 : : #else
692 : 79035016 : if (targetm.asm_out.function_section)
693 : 79035016 : section = targetm.asm_out.function_section (decl, freq, startup, exit);
694 : 79035016 : if (section)
695 : : return section;
696 : 72728552 : return hot_function_section (decl);
697 : : #endif
698 : : }
699 : :
700 : : /* Return the section for function DECL.
701 : :
702 : : If DECL is NULL_TREE, return the text section. We can be passed
703 : : NULL_TREE under some circumstances by dbxout.cc at least. */
704 : :
705 : : section *
706 : 3523105 : function_section (tree decl)
707 : : {
708 : : /* Handle cases where function splitting code decides
709 : : to put function entry point into unlikely executed section
710 : : despite the fact that the function itself is not cold
711 : : (i.e. it is called rarely but contains a hot loop that is
712 : : better to live in hot subsection for the code locality). */
713 : 3523105 : return function_section_1 (decl,
714 : 3523105 : first_function_block_is_cold);
715 : : }
716 : :
717 : : /* Return the section for the current function, take IN_COLD_SECTION_P
718 : : into account. */
719 : :
720 : : section *
721 : 75382910 : current_function_section (void)
722 : : {
723 : 75382910 : return function_section_1 (current_function_decl, in_cold_section_p);
724 : : }
725 : :
726 : : /* Tell assembler to switch to unlikely-to-be-executed text section. */
727 : :
728 : : section *
729 : 129001 : unlikely_text_section (void)
730 : : {
731 : 129001 : return function_section_1 (current_function_decl, true);
732 : : }
733 : :
734 : : /* When called within a function context, return true if the function
735 : : has been assigned a cold text section and if SECT is that section.
736 : : When called outside a function context, return true if SECT is the
737 : : default cold section. */
738 : :
739 : : bool
740 : 0 : unlikely_text_section_p (section *sect)
741 : : {
742 : 0 : return sect == function_section_1 (current_function_decl, true);
743 : : }
744 : :
745 : : /* Switch to the other function partition (if inside of hot section
746 : : into cold section, otherwise into the hot section). */
747 : :
748 : : void
749 : 0 : switch_to_other_text_partition (void)
750 : : {
751 : 0 : in_cold_section_p = !in_cold_section_p;
752 : 0 : switch_to_section (current_function_section ());
753 : 0 : }
754 : :
755 : : /* Return the read-only or relocated read-only data section
756 : : associated with function DECL. */
757 : :
758 : : section *
759 : 623967 : default_function_rodata_section (tree decl, bool relocatable)
760 : : {
761 : 623967 : const char* sname;
762 : 623967 : unsigned int flags;
763 : :
764 : 623967 : flags = 0;
765 : :
766 : 623967 : if (relocatable)
767 : : {
768 : : sname = ".data.rel.ro.local";
769 : : flags = (SECTION_WRITE | SECTION_RELRO);
770 : : }
771 : : else
772 : 623967 : sname = ".rodata";
773 : :
774 : 623967 : if (decl && DECL_SECTION_NAME (decl))
775 : : {
776 : 113179 : const char *name = DECL_SECTION_NAME (decl);
777 : :
778 : 113179 : if (DECL_COMDAT_GROUP (decl) && HAVE_COMDAT_GROUP)
779 : : {
780 : 27458 : const char *dot;
781 : 27458 : size_t len;
782 : 27458 : char* rname;
783 : :
784 : 27458 : dot = strchr (name + 1, '.');
785 : 27458 : if (!dot)
786 : 0 : dot = name;
787 : 27458 : len = strlen (dot) + strlen (sname) + 1;
788 : 27458 : rname = (char *) alloca (len);
789 : :
790 : 27458 : strcpy (rname, sname);
791 : 27458 : strcat (rname, dot);
792 : 27458 : return get_section (rname, (SECTION_LINKONCE | flags), decl);
793 : : }
794 : : /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo or
795 : : .gnu.linkonce.d.rel.ro.local.foo if the jump table is relocatable. */
796 : 85721 : else if (DECL_COMDAT_GROUP (decl)
797 : 85721 : && startswith (name, ".gnu.linkonce.t."))
798 : : {
799 : 0 : size_t len;
800 : 0 : char *rname;
801 : :
802 : 0 : if (relocatable)
803 : : {
804 : 0 : len = strlen (name) + strlen (".rel.ro.local") + 1;
805 : 0 : rname = (char *) alloca (len);
806 : :
807 : 0 : strcpy (rname, ".gnu.linkonce.d.rel.ro.local");
808 : 0 : strcat (rname, name + 15);
809 : : }
810 : : else
811 : : {
812 : 0 : len = strlen (name) + 1;
813 : 0 : rname = (char *) alloca (len);
814 : :
815 : 0 : memcpy (rname, name, len);
816 : 0 : rname[14] = 'r';
817 : : }
818 : 0 : return get_section (rname, (SECTION_LINKONCE | flags), decl);
819 : : }
820 : : /* For .text.foo we want to use .rodata.foo. */
821 : 85717 : else if (flag_function_sections && flag_data_sections
822 : 171438 : && startswith (name, ".text."))
823 : : {
824 : 85717 : size_t len = strlen (name) + 1;
825 : 85717 : char *rname = (char *) alloca (len + strlen (sname) - 5);
826 : :
827 : 85717 : memcpy (rname, sname, strlen (sname));
828 : 85717 : memcpy (rname + strlen (sname), name + 5, len - 5);
829 : 85717 : return get_section (rname, flags, decl);
830 : : }
831 : : }
832 : :
833 : 510792 : if (relocatable)
834 : 0 : return get_section (sname, flags, decl);
835 : : else
836 : 510792 : return readonly_data_section;
837 : : }
838 : :
839 : : /* Return the read-only data section associated with function DECL
840 : : for targets where that section should be always the single
841 : : readonly data section. */
842 : :
843 : : section *
844 : 0 : default_no_function_rodata_section (tree, bool)
845 : : {
846 : 0 : return readonly_data_section;
847 : : }
848 : :
849 : : /* A subroutine of mergeable_string_section and mergeable_constant_section. */
850 : :
851 : : static const char *
852 : 610841 : function_mergeable_rodata_prefix (void)
853 : : {
854 : 610841 : section *s = targetm.asm_out.function_rodata_section (current_function_decl,
855 : : false);
856 : 610841 : if (SECTION_STYLE (s) == SECTION_NAMED)
857 : 106075 : return s->named.name;
858 : : else
859 : 504766 : return targetm.asm_out.mergeable_rodata_prefix;
860 : : }
861 : :
862 : : /* Return the section to use for string merging. */
863 : :
864 : : static section *
865 : 1218240 : mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
866 : : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
867 : : unsigned int flags ATTRIBUTE_UNUSED)
868 : : {
869 : 1218240 : HOST_WIDE_INT len;
870 : :
871 : 1218240 : if (HAVE_GAS_SHF_MERGE && flag_merge_constants
872 : 1035857 : && TREE_CODE (decl) == STRING_CST
873 : 1035857 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
874 : 1035857 : && align <= 256
875 : 1035857 : && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
876 : 2253961 : && TREE_STRING_LENGTH (decl) == len)
877 : : {
878 : 394191 : scalar_int_mode mode;
879 : 394191 : unsigned int modesize;
880 : 394191 : const char *str;
881 : 394191 : HOST_WIDE_INT i;
882 : 394191 : int j, unit;
883 : 394191 : const char *prefix = function_mergeable_rodata_prefix ();
884 : 394191 : char *name = (char *) alloca (strlen (prefix) + 30);
885 : :
886 : 394191 : mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
887 : 394191 : modesize = GET_MODE_BITSIZE (mode);
888 : 394191 : if (modesize >= 8 && modesize <= 256
889 : 394191 : && (modesize & (modesize - 1)) == 0)
890 : : {
891 : 394191 : if (align < modesize)
892 : : align = modesize;
893 : :
894 : 394191 : str = TREE_STRING_POINTER (decl);
895 : 394191 : unit = GET_MODE_SIZE (mode);
896 : :
897 : : /* Check for embedded NUL characters. */
898 : 114776792 : for (i = 0; i < len; i += unit)
899 : : {
900 : 115107074 : for (j = 0; j < unit; j++)
901 : 114748877 : if (str[i + j] != '\0')
902 : : break;
903 : 114740798 : if (j == unit)
904 : : break;
905 : : }
906 : 394191 : if (i == len - unit || (unit == 1 && i == len))
907 : : {
908 : 390487 : sprintf (name, "%s.str%d.%d", prefix,
909 : 390487 : modesize / 8, (int) (align / 8));
910 : 390487 : flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS;
911 : 390487 : return get_section (name, flags, NULL);
912 : : }
913 : : }
914 : : }
915 : :
916 : 827753 : return readonly_data_section;
917 : : }
918 : :
919 : : /* Return the section to use for constant merging. */
920 : :
921 : : section *
922 : 259289 : mergeable_constant_section (machine_mode mode ATTRIBUTE_UNUSED,
923 : : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
924 : : unsigned int flags ATTRIBUTE_UNUSED)
925 : : {
926 : 259289 : if (HAVE_GAS_SHF_MERGE && flag_merge_constants
927 : 220586 : && mode != VOIDmode
928 : 220586 : && mode != BLKmode
929 : 220555 : && known_le (GET_MODE_BITSIZE (mode), align)
930 : 220555 : && align >= 8
931 : 220555 : && align <= 256
932 : 475939 : && (align & (align - 1)) == 0)
933 : : {
934 : 216650 : const char *prefix = function_mergeable_rodata_prefix ();
935 : 216650 : char *name = (char *) alloca (strlen (prefix) + 30);
936 : :
937 : 216650 : sprintf (name, "%s.cst%d", prefix, (int) (align / 8));
938 : 216650 : flags |= (align / 8) | SECTION_MERGE;
939 : 216650 : return get_section (name, flags, NULL);
940 : : }
941 : 42639 : return readonly_data_section;
942 : : }
943 : :
944 : : /* Given NAME, a putative register name, discard any customary prefixes. */
945 : :
946 : : static const char *
947 : 7465951 : strip_reg_name (const char *name)
948 : : {
949 : : #ifdef REGISTER_PREFIX
950 : : if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
951 : : name += strlen (REGISTER_PREFIX);
952 : : #endif
953 : 7465672 : if (name[0] == '%' || name[0] == '#')
954 : 279 : name++;
955 : 7465951 : return name;
956 : : }
957 : :
958 : : /* The user has asked for a DECL to have a particular name. Set (or
959 : : change) it in such a way that we don't prefix an underscore to
960 : : it. */
961 : : void
962 : 2725967 : set_user_assembler_name (tree decl, const char *name)
963 : : {
964 : 2725967 : char *starred = (char *) alloca (strlen (name) + 2);
965 : 2725967 : starred[0] = '*';
966 : 2725967 : strcpy (starred + 1, name);
967 : 2725967 : symtab->change_decl_assembler_name (decl, get_identifier (starred));
968 : 2725967 : SET_DECL_RTL (decl, NULL_RTX);
969 : 2725967 : }
970 : :
971 : : /* Decode an `asm' spec for a declaration as a register name.
972 : : Return the register number, or -1 if nothing specified,
973 : : or -2 if the ASMSPEC is not `cc' or `memory' or `redzone' and is not
974 : : recognized,
975 : : or -3 if ASMSPEC is `cc' and is not recognized,
976 : : or -4 if ASMSPEC is `memory' and is not recognized,
977 : : or -5 if ASMSPEC is `redzone' and is not recognized.
978 : : Accept an exact spelling or a decimal number.
979 : : Prefixes such as % are optional. */
980 : :
981 : : int
982 : 97335 : decode_reg_name_and_count (const char *asmspec, int *pnregs)
983 : : {
984 : : /* Presume just one register is clobbered. */
985 : 97335 : *pnregs = 1;
986 : :
987 : 97335 : if (asmspec != 0)
988 : : {
989 : 97335 : int i;
990 : :
991 : : /* Get rid of confusing prefixes. */
992 : 97335 : asmspec = strip_reg_name (asmspec);
993 : :
994 : : /* Allow a decimal number as a "register name". */
995 : 97335 : if (ISDIGIT (asmspec[0]))
996 : : {
997 : 29 : char *pend;
998 : 29 : errno = 0;
999 : 29 : unsigned long j = strtoul (asmspec, &pend, 10);
1000 : 29 : if (*pend == '\0')
1001 : : {
1002 : 25 : static_assert (FIRST_PSEUDO_REGISTER <= INT_MAX, "");
1003 : 25 : if (errno != ERANGE
1004 : 23 : && j < FIRST_PSEUDO_REGISTER
1005 : 13 : && reg_names[j][0])
1006 : 25 : return j;
1007 : : else
1008 : : return -2;
1009 : : }
1010 : : }
1011 : :
1012 : 7433982 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1013 : 7368616 : if (reg_names[i][0]
1014 : 14737232 : && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
1015 : : return i;
1016 : :
1017 : : #ifdef OVERLAPPING_REGISTER_NAMES
1018 : : {
1019 : : static const struct
1020 : : {
1021 : : const char *const name;
1022 : : const int number;
1023 : : const int nregs;
1024 : : } table[] = OVERLAPPING_REGISTER_NAMES;
1025 : :
1026 : : for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1027 : : if (table[i].name[0]
1028 : : && ! strcmp (asmspec, table[i].name))
1029 : : {
1030 : : *pnregs = table[i].nregs;
1031 : : return table[i].number;
1032 : : }
1033 : : }
1034 : : #endif /* OVERLAPPING_REGISTER_NAMES */
1035 : :
1036 : : #ifdef ADDITIONAL_REGISTER_NAMES
1037 : : {
1038 : : static const struct { const char *const name; const int number; } table[]
1039 : : = ADDITIONAL_REGISTER_NAMES;
1040 : :
1041 : 5210895 : for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1042 : 5156306 : if (table[i].name[0]
1043 : 5156306 : && ! strcmp (asmspec, table[i].name)
1044 : 10777 : && reg_names[table[i].number][0])
1045 : : return table[i].number;
1046 : : }
1047 : : #endif /* ADDITIONAL_REGISTER_NAMES */
1048 : :
1049 : 54589 : if (!strcmp (asmspec, "redzone"))
1050 : : return -5;
1051 : :
1052 : 54587 : if (!strcmp (asmspec, "memory"))
1053 : : return -4;
1054 : :
1055 : 15759 : if (!strcmp (asmspec, "cc"))
1056 : : return -3;
1057 : :
1058 : 35 : return -2;
1059 : : }
1060 : :
1061 : : return -1;
1062 : : }
1063 : :
1064 : : int
1065 : 1203 : decode_reg_name (const char *name)
1066 : : {
1067 : 1203 : int count;
1068 : 1203 : return decode_reg_name_and_count (name, &count);
1069 : : }
1070 : :
1071 : :
1072 : : /* Return true if DECL's initializer is suitable for a BSS section. */
1073 : :
1074 : : bool
1075 : 6404436 : bss_initializer_p (const_tree decl, bool named)
1076 : : {
1077 : : /* Do not put non-common constants into the .bss section, they belong in
1078 : : a readonly section, except when NAMED is true. */
1079 : 11033206 : return ((!TREE_READONLY (decl) || DECL_COMMON (decl) || named)
1080 : 6428070 : && (DECL_INITIAL (decl) == NULL
1081 : : /* In LTO we have no errors in program; error_mark_node is used
1082 : : to mark offlined constructors. */
1083 : 649347 : || (DECL_INITIAL (decl) == error_mark_node
1084 : 4 : && !in_lto_p)
1085 : 649343 : || (flag_zero_initialized_in_bss
1086 : 649285 : && initializer_zerop (DECL_INITIAL (decl))
1087 : : /* A decl with the "persistent" attribute applied and
1088 : : explicitly initialized to 0 should not be treated as a BSS
1089 : : variable. */
1090 : 37396 : && !DECL_PERSISTENT_P (decl))));
1091 : : }
1092 : :
1093 : : /* Compute the alignment of variable specified by DECL.
1094 : : DONT_OUTPUT_DATA is from assemble_variable. */
1095 : :
1096 : : void
1097 : 5861479 : align_variable (tree decl, bool dont_output_data)
1098 : : {
1099 : 5861479 : unsigned int align = DECL_ALIGN (decl);
1100 : :
1101 : : /* In the case for initialing an array whose length isn't specified,
1102 : : where we have not yet been able to do the layout,
1103 : : figure out the proper alignment now. */
1104 : 804 : if (dont_output_data && DECL_SIZE (decl) == 0
1105 : 5861479 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1106 : 0 : align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1107 : :
1108 : : /* Some object file formats have a maximum alignment which they support.
1109 : : In particular, a.out format supports a maximum alignment of 4. */
1110 : 0 : if (align > MAX_OFILE_ALIGNMENT)
1111 : : {
1112 : : error ("alignment of %q+D is greater than maximum object "
1113 : : "file alignment %d", decl,
1114 : : MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1115 : : align = MAX_OFILE_ALIGNMENT;
1116 : : }
1117 : :
1118 : 5861479 : if (! DECL_USER_ALIGN (decl))
1119 : : {
1120 : : #ifdef DATA_ABI_ALIGNMENT
1121 : 5739677 : unsigned int data_abi_align
1122 : 5739677 : = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1123 : : /* For backwards compatibility, don't assume the ABI alignment for
1124 : : TLS variables. */
1125 : 5739769 : if (! DECL_THREAD_LOCAL_P (decl) || data_abi_align <= BITS_PER_WORD)
1126 : : align = data_abi_align;
1127 : : #endif
1128 : :
1129 : : /* On some machines, it is good to increase alignment sometimes.
1130 : : But as DECL_ALIGN is used both for actually emitting the variable
1131 : : and for code accessing the variable as guaranteed alignment, we
1132 : : can only increase the alignment if it is a performance optimization
1133 : : if the references to it must bind to the current definition. */
1134 : 5739677 : if (decl_binds_to_current_def_p (decl)
1135 : 5739677 : && !DECL_VIRTUAL_P (decl))
1136 : : {
1137 : : #ifdef DATA_ALIGNMENT
1138 : 5133413 : unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1139 : : /* Don't increase alignment too much for TLS variables - TLS space
1140 : : is too precious. */
1141 : 5133481 : if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1142 : : align = data_align;
1143 : : #endif
1144 : 5133413 : if (DECL_INITIAL (decl) != 0
1145 : : /* In LTO we have no errors in program; error_mark_node is used
1146 : : to mark offlined constructors. */
1147 : 5133413 : && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1148 : : {
1149 : 3209484 : unsigned int const_align
1150 : 3209484 : = targetm.constant_alignment (DECL_INITIAL (decl), align);
1151 : : /* Don't increase alignment too much for TLS variables - TLS
1152 : : space is too precious. */
1153 : 3209490 : if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1154 : : align = const_align;
1155 : : }
1156 : : }
1157 : : }
1158 : :
1159 : : /* Reset the alignment in case we have made it tighter, so we can benefit
1160 : : from it in get_pointer_alignment. */
1161 : 5861479 : SET_DECL_ALIGN (decl, align);
1162 : 5861479 : }
1163 : :
1164 : : /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1165 : : beyond what align_variable returned. */
1166 : :
1167 : : static unsigned int
1168 : 5731229 : get_variable_align (tree decl)
1169 : : {
1170 : 5731229 : unsigned int align = DECL_ALIGN (decl);
1171 : :
1172 : : /* For user aligned vars or static vars align_variable already did
1173 : : everything. */
1174 : 5731229 : if (DECL_USER_ALIGN (decl) || !TREE_PUBLIC (decl))
1175 : : return align;
1176 : :
1177 : : #ifdef DATA_ABI_ALIGNMENT
1178 : 2852909 : if (DECL_THREAD_LOCAL_P (decl))
1179 : 5917 : align = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1180 : : #endif
1181 : :
1182 : : /* For decls that bind to the current definition, align_variable
1183 : : did also everything, except for not assuming ABI required alignment
1184 : : of TLS variables. For other vars, increase the alignment here
1185 : : as an optimization. */
1186 : 2852909 : if (!decl_binds_to_current_def_p (decl))
1187 : : {
1188 : : /* On some machines, it is good to increase alignment sometimes. */
1189 : : #ifdef DATA_ALIGNMENT
1190 : 588775 : unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1191 : : /* Don't increase alignment too much for TLS variables - TLS space
1192 : : is too precious. */
1193 : 588796 : if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1194 : : align = data_align;
1195 : : #endif
1196 : 588775 : if (DECL_INITIAL (decl) != 0
1197 : : /* In LTO we have no errors in program; error_mark_node is used
1198 : : to mark offlined constructors. */
1199 : 588775 : && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1200 : : {
1201 : 574850 : unsigned int const_align
1202 : 574850 : = targetm.constant_alignment (DECL_INITIAL (decl), align);
1203 : : /* Don't increase alignment too much for TLS variables - TLS space
1204 : : is too precious. */
1205 : 574855 : if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD)
1206 : : align = const_align;
1207 : : }
1208 : : }
1209 : :
1210 : : return align;
1211 : : }
1212 : :
1213 : : /* Compute reloc for get_variable_section. The return value
1214 : : is a mask for which bit 1 indicates a global relocation, and bit 0
1215 : : indicates a local relocation. */
1216 : :
1217 : : int
1218 : 4462262 : compute_reloc_for_var (tree decl)
1219 : : {
1220 : 4462262 : int reloc;
1221 : :
1222 : 4462262 : if (DECL_INITIAL (decl) == error_mark_node)
1223 : 2 : reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1224 : 4462260 : else if (DECL_INITIAL (decl))
1225 : 3332820 : reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1226 : : else
1227 : : reloc = 0;
1228 : :
1229 : 4462262 : return reloc;
1230 : : }
1231 : :
1232 : : /* Return the section into which the given VAR_DECL or CONST_DECL
1233 : : should be placed. PREFER_NOSWITCH_P is true if a noswitch
1234 : : section should be used wherever possible. */
1235 : :
1236 : : section *
1237 : 4463684 : get_variable_section (tree decl, bool prefer_noswitch_p)
1238 : : {
1239 : 4463684 : addr_space_t as = ADDR_SPACE_GENERIC;
1240 : 4463684 : int reloc;
1241 : 4463684 : varpool_node *vnode = varpool_node::get (decl);
1242 : 4463684 : if (vnode)
1243 : : {
1244 : 4463669 : vnode = vnode->ultimate_alias_target ();
1245 : 4463669 : decl = vnode->decl;
1246 : : }
1247 : :
1248 : 4463684 : if (TREE_TYPE (decl) != error_mark_node)
1249 : 4463684 : as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1250 : :
1251 : : /* We need the constructor to figure out reloc flag. */
1252 : 4463684 : if (vnode)
1253 : 4463669 : vnode->get_constructor ();
1254 : :
1255 : 4463684 : if (DECL_COMMON (decl)
1256 : 4463684 : && !lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
1257 : : {
1258 : : /* If the decl has been given an explicit section name, or it resides
1259 : : in a non-generic address space, then it isn't common, and shouldn't
1260 : : be handled as such. */
1261 : 1422 : gcc_assert (DECL_SECTION_NAME (decl) == NULL
1262 : : && ADDR_SPACE_GENERIC_P (as));
1263 : 1422 : if (DECL_THREAD_LOCAL_P (decl))
1264 : 50 : return tls_comm_section;
1265 : 1372 : else if (TREE_PUBLIC (decl) && bss_initializer_p (decl))
1266 : 1372 : return comm_section;
1267 : : }
1268 : :
1269 : 4462262 : reloc = compute_reloc_for_var (decl);
1270 : :
1271 : 4462262 : resolve_unique_section (decl, reloc, flag_data_sections);
1272 : 4462262 : if (IN_NAMED_SECTION (decl))
1273 : : {
1274 : 2947607 : section *sect = get_named_section (decl, NULL, reloc);
1275 : :
1276 : 2947607 : if ((sect->common.flags & SECTION_BSS)
1277 : 2947607 : && !bss_initializer_p (decl, true))
1278 : : {
1279 : 2 : if (flag_zero_initialized_in_bss)
1280 : 2 : error_at (DECL_SOURCE_LOCATION (decl),
1281 : : "only zero initializers are allowed in section %qs",
1282 : : sect->named.name);
1283 : : else
1284 : 0 : error_at (DECL_SOURCE_LOCATION (decl),
1285 : : "no initializers are allowed in section %qs",
1286 : : sect->named.name);
1287 : 2 : DECL_INITIAL (decl) = error_mark_node;
1288 : : }
1289 : 2947607 : return sect;
1290 : : }
1291 : :
1292 : 1514655 : if (ADDR_SPACE_GENERIC_P (as)
1293 : 1514650 : && !DECL_THREAD_LOCAL_P (decl)
1294 : 1511143 : && !DECL_NOINIT_P (decl)
1295 : 1511143 : && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1296 : 3025798 : && bss_initializer_p (decl))
1297 : : {
1298 : 1137448 : if (!TREE_PUBLIC (decl)
1299 : 1137625 : && !((flag_sanitize & SANITIZE_ADDRESS)
1300 : 177 : && asan_protect_global (decl)))
1301 : 152142 : return lcomm_section;
1302 : 985306 : if (bss_noswitch_section)
1303 : : return bss_noswitch_section;
1304 : : }
1305 : :
1306 : 377207 : return targetm.asm_out.select_section (decl, reloc,
1307 : 754414 : get_variable_align (decl));
1308 : : }
1309 : :
1310 : : /* Return the block into which object_block DECL should be placed. */
1311 : :
1312 : : static struct object_block *
1313 : 0 : get_block_for_decl (tree decl)
1314 : : {
1315 : 0 : section *sect;
1316 : :
1317 : 0 : if (VAR_P (decl))
1318 : : {
1319 : : /* The object must be defined in this translation unit. */
1320 : 0 : if (DECL_EXTERNAL (decl))
1321 : : return NULL;
1322 : :
1323 : : /* There's no point using object blocks for something that is
1324 : : isolated by definition. */
1325 : 0 : if (DECL_COMDAT_GROUP (decl))
1326 : : return NULL;
1327 : : }
1328 : :
1329 : : /* We can only calculate block offsets if the decl has a known
1330 : : constant size. */
1331 : 0 : if (DECL_SIZE_UNIT (decl) == NULL)
1332 : : return NULL;
1333 : 0 : if (!tree_fits_uhwi_p (DECL_SIZE_UNIT (decl)))
1334 : : return NULL;
1335 : :
1336 : : /* Find out which section should contain DECL. We cannot put it into
1337 : : an object block if it requires a standalone definition. */
1338 : 0 : if (VAR_P (decl))
1339 : 0 : align_variable (decl, 0);
1340 : 0 : sect = get_variable_section (decl, true);
1341 : 0 : if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
1342 : : return NULL;
1343 : :
1344 : 0 : if (bool (lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
1345 : 0 : != bool (sect->common.flags & SECTION_RETAIN))
1346 : : return NULL;
1347 : :
1348 : 0 : return get_block_for_section (sect);
1349 : : }
1350 : :
1351 : : /* Make sure block symbol SYMBOL is in block BLOCK. */
1352 : :
1353 : : static void
1354 : 0 : change_symbol_block (rtx symbol, struct object_block *block)
1355 : : {
1356 : 0 : if (block != SYMBOL_REF_BLOCK (symbol))
1357 : : {
1358 : 0 : gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0);
1359 : 0 : SYMBOL_REF_BLOCK (symbol) = block;
1360 : : }
1361 : 0 : }
1362 : :
1363 : : /* Return true if it is possible to put DECL in an object_block. */
1364 : :
1365 : : static bool
1366 : 0 : use_blocks_for_decl_p (tree decl)
1367 : : {
1368 : 0 : struct symtab_node *snode;
1369 : :
1370 : : /* Don't create object blocks if each DECL is placed into a separate
1371 : : section because that will uselessly create a section anchor for
1372 : : each DECL. */
1373 : 0 : if (flag_data_sections)
1374 : : return false;
1375 : :
1376 : : /* Only data DECLs can be placed into object blocks. */
1377 : 0 : if (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
1378 : : return false;
1379 : :
1380 : : /* DECL_INITIAL (decl) set to decl is a hack used for some decls that
1381 : : are never used from code directly and we never want object block handling
1382 : : for those. */
1383 : 0 : if (DECL_INITIAL (decl) == decl)
1384 : : return false;
1385 : :
1386 : : /* If this decl is an alias, then we don't want to emit a
1387 : : definition. */
1388 : 0 : if (VAR_P (decl)
1389 : 0 : && (snode = symtab_node::get (decl)) != NULL
1390 : 0 : && snode->alias)
1391 : : return false;
1392 : :
1393 : 0 : return targetm.use_blocks_for_decl_p (decl);
1394 : : }
1395 : :
1396 : : /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS
1397 : : until we find an identifier that is not itself a transparent alias.
1398 : : Modify the alias passed to it by reference (and all aliases on the
1399 : : way to the ultimate target), such that they do not have to be
1400 : : followed again, and return the ultimate target of the alias
1401 : : chain. */
1402 : :
1403 : : static inline tree
1404 : 35880100 : ultimate_transparent_alias_target (tree *alias)
1405 : : {
1406 : 35880100 : tree target = *alias;
1407 : :
1408 : 35880100 : if (IDENTIFIER_TRANSPARENT_ALIAS (target))
1409 : : {
1410 : 0 : gcc_assert (TREE_CHAIN (target));
1411 : 0 : target = ultimate_transparent_alias_target (&TREE_CHAIN (target));
1412 : 0 : gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target)
1413 : : && ! TREE_CHAIN (target));
1414 : 0 : *alias = target;
1415 : : }
1416 : :
1417 : 35880100 : return target;
1418 : : }
1419 : :
1420 : : /* Return true if REGNUM is mentioned in ELIMINABLE_REGS as a from
1421 : : register number. */
1422 : :
1423 : : static bool
1424 : 0 : eliminable_regno_p (int regnum)
1425 : : {
1426 : 0 : static const struct
1427 : : {
1428 : : const int from;
1429 : : const int to;
1430 : : } eliminables[] = ELIMINABLE_REGS;
1431 : 13 : for (size_t i = 0; i < ARRAY_SIZE (eliminables); i++)
1432 : 13 : if (regnum == eliminables[i].from)
1433 : : return true;
1434 : : return false;
1435 : : }
1436 : :
1437 : : /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should
1438 : : have static storage duration. In other words, it should not be an
1439 : : automatic variable, including PARM_DECLs.
1440 : :
1441 : : There is, however, one exception: this function handles variables
1442 : : explicitly placed in a particular register by the user.
1443 : :
1444 : : This is never called for PARM_DECL nodes. */
1445 : :
1446 : : void
1447 : 8397526 : make_decl_rtl (tree decl)
1448 : : {
1449 : 8397526 : const char *name = 0;
1450 : 8397526 : int reg_number;
1451 : 8397526 : tree id;
1452 : 8397526 : rtx x;
1453 : :
1454 : : /* Check that we are not being given an automatic variable. */
1455 : 8397526 : gcc_assert (TREE_CODE (decl) != PARM_DECL
1456 : : && TREE_CODE (decl) != RESULT_DECL);
1457 : :
1458 : : /* A weak alias has TREE_PUBLIC set but not the other bits. */
1459 : 8397526 : gcc_assert (!VAR_P (decl)
1460 : : || TREE_STATIC (decl)
1461 : : || TREE_PUBLIC (decl)
1462 : : || DECL_EXTERNAL (decl)
1463 : : || DECL_REGISTER (decl));
1464 : :
1465 : : /* And that we were not given a type or a label. */
1466 : 8397526 : gcc_assert (TREE_CODE (decl) != TYPE_DECL
1467 : : && TREE_CODE (decl) != LABEL_DECL);
1468 : :
1469 : : /* For a duplicate declaration, we can be called twice on the
1470 : : same DECL node. Don't discard the RTL already made. */
1471 : 8397526 : if (DECL_RTL_SET_P (decl))
1472 : : {
1473 : : /* If the old RTL had the wrong mode, fix the mode. */
1474 : 11686 : x = DECL_RTL (decl);
1475 : 11686 : if (GET_MODE (x) != DECL_MODE (decl))
1476 : 0 : SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1477 : :
1478 : 11686 : if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1479 : : return;
1480 : :
1481 : : /* ??? Another way to do this would be to maintain a hashed
1482 : : table of such critters. Instead of adding stuff to a DECL
1483 : : to give certain attributes to it, we could use an external
1484 : : hash map from DECL to set of attributes. */
1485 : :
1486 : : /* Let the target reassign the RTL if it wants.
1487 : : This is necessary, for example, when one machine specific
1488 : : decl attribute overrides another. */
1489 : 11618 : targetm.encode_section_info (decl, DECL_RTL (decl), false);
1490 : :
1491 : : /* If the symbol has a SYMBOL_REF_BLOCK field, update it based
1492 : : on the new decl information. */
1493 : 11618 : if (MEM_P (x)
1494 : 11618 : && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1495 : 23236 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0)))
1496 : 0 : change_symbol_block (XEXP (x, 0), get_block_for_decl (decl));
1497 : :
1498 : 11618 : return;
1499 : : }
1500 : :
1501 : : /* If this variable belongs to the global constant pool, retrieve the
1502 : : pre-computed RTL or recompute it in LTO mode. */
1503 : 8385840 : if (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
1504 : : {
1505 : 5145 : SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1506 : 5145 : return;
1507 : : }
1508 : :
1509 : 8380695 : id = DECL_ASSEMBLER_NAME (decl);
1510 : 8380695 : name = IDENTIFIER_POINTER (id);
1511 : :
1512 : 8324872 : if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1513 : 11480745 : && DECL_REGISTER (decl))
1514 : : {
1515 : 13 : error ("register name not specified for %q+D", decl);
1516 : : }
1517 : 8380682 : else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1518 : : {
1519 : 1203 : const char *asmspec = name+1;
1520 : 1203 : machine_mode mode = DECL_MODE (decl);
1521 : 1203 : reg_number = decode_reg_name (asmspec);
1522 : : /* First detect errors in declaring global registers. */
1523 : 1203 : if (reg_number == -1)
1524 : 0 : error ("register name not specified for %q+D", decl);
1525 : 1203 : else if (reg_number < 0)
1526 : 33 : error ("invalid register name for %q+D", decl);
1527 : 1170 : else if (mode == BLKmode)
1528 : 5 : error ("data type of %q+D isn%'t suitable for a register",
1529 : : decl);
1530 : 1165 : else if (!in_hard_reg_set_p (accessible_reg_set, mode, reg_number))
1531 : 2 : error ("the register specified for %q+D cannot be accessed"
1532 : : " by the current target", decl);
1533 : 1163 : else if (!in_hard_reg_set_p (operand_reg_set, mode, reg_number))
1534 : 0 : error ("the register specified for %q+D is not general enough"
1535 : : " to be used as a register variable", decl);
1536 : 1163 : else if (!targetm.hard_regno_mode_ok (reg_number, mode))
1537 : 2 : error ("register specified for %q+D isn%'t suitable for data type",
1538 : : decl);
1539 : 1161 : else if (reg_number != HARD_FRAME_POINTER_REGNUM
1540 : 1155 : && (reg_number == FRAME_POINTER_REGNUM
1541 : : #ifdef RETURN_ADDRESS_POINTER_REGNUM
1542 : : || reg_number == RETURN_ADDRESS_POINTER_REGNUM
1543 : : #endif
1544 : 1155 : || reg_number == ARG_POINTER_REGNUM)
1545 : 1166 : && eliminable_regno_p (reg_number))
1546 : 5 : error ("register specified for %q+D is an internal GCC "
1547 : : "implementation detail", decl);
1548 : : /* Now handle properly declared static register variables. */
1549 : : else
1550 : : {
1551 : 1156 : int nregs;
1552 : :
1553 : 1156 : if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl))
1554 : : {
1555 : 0 : DECL_INITIAL (decl) = 0;
1556 : 0 : error ("global register variable has initial value");
1557 : : }
1558 : 1156 : if (TREE_THIS_VOLATILE (decl))
1559 : 10 : warning (OPT_Wvolatile_register_var,
1560 : : "optimization may eliminate reads and/or "
1561 : : "writes to register variables");
1562 : :
1563 : : /* If the user specified one of the eliminables registers here,
1564 : : e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
1565 : : confused with that register and be eliminated. This usage is
1566 : : somewhat suspect... */
1567 : :
1568 : 1156 : SET_DECL_RTL (decl, gen_raw_REG (mode, reg_number));
1569 : 1156 : ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1570 : 1156 : REG_USERVAR_P (DECL_RTL (decl)) = 1;
1571 : :
1572 : 1156 : if (TREE_STATIC (decl))
1573 : : {
1574 : : /* Make this register global, so not usable for anything
1575 : : else. */
1576 : : #ifdef ASM_DECLARE_REGISTER_GLOBAL
1577 : : name = IDENTIFIER_POINTER (DECL_NAME (decl));
1578 : : ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
1579 : : #endif
1580 : 109 : nregs = hard_regno_nregs (reg_number, mode);
1581 : 218 : while (nregs > 0)
1582 : 109 : globalize_reg (decl, reg_number + --nregs);
1583 : : }
1584 : :
1585 : : /* As a register variable, it has no section. */
1586 : 1156 : return;
1587 : : }
1588 : : /* Avoid internal errors from invalid register
1589 : : specifications. */
1590 : 47 : SET_DECL_ASSEMBLER_NAME (decl, NULL_TREE);
1591 : 47 : DECL_HARD_REGISTER (decl) = 0;
1592 : : /* Also avoid SSA inconsistencies by pretending this is an external
1593 : : decl now. */
1594 : 47 : DECL_EXTERNAL (decl) = 1;
1595 : 47 : return;
1596 : : }
1597 : : /* Now handle ordinary static variables and functions (in memory).
1598 : : Also handle vars declared register invalidly. */
1599 : : else if (name[0] == '*')
1600 : : {
1601 : : #ifdef REGISTER_PREFIX
1602 : : if (strlen (REGISTER_PREFIX) != 0)
1603 : : {
1604 : : reg_number = decode_reg_name (name);
1605 : : if (reg_number >= 0 || reg_number == -3)
1606 : : error ("register name given for non-register variable %q+D", decl);
1607 : : }
1608 : : #endif
1609 : : }
1610 : :
1611 : : /* Specifying a section attribute on a variable forces it into a
1612 : : non-.bss section, and thus it cannot be common. */
1613 : : /* FIXME: In general this code should not be necessary because
1614 : : visibility pass is doing the same work. But notice_global_symbol
1615 : : is called early and it needs to make DECL_RTL to get the name.
1616 : : we take care of recomputing the DECL_RTL after visibility is changed. */
1617 : 8379492 : if (VAR_P (decl)
1618 : 3136475 : && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
1619 : 3136475 : && DECL_SECTION_NAME (decl) != NULL
1620 : 1431529 : && DECL_INITIAL (decl) == NULL_TREE
1621 : 8379609 : && DECL_COMMON (decl))
1622 : 0 : DECL_COMMON (decl) = 0;
1623 : :
1624 : : /* Variables can't be both common and weak. */
1625 : 8379492 : if (VAR_P (decl) && DECL_WEAK (decl))
1626 : 317889 : DECL_COMMON (decl) = 0;
1627 : :
1628 : 8379492 : if (use_object_blocks_p () && use_blocks_for_decl_p (decl))
1629 : 0 : x = create_block_symbol (name, get_block_for_decl (decl), -1);
1630 : : else
1631 : : {
1632 : 8379492 : machine_mode address_mode = Pmode;
1633 : 8379492 : if (TREE_TYPE (decl) != error_mark_node)
1634 : : {
1635 : 8379492 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1636 : 8379492 : address_mode = targetm.addr_space.address_mode (as);
1637 : : }
1638 : 8379492 : x = gen_rtx_SYMBOL_REF (address_mode, name);
1639 : : }
1640 : 8379492 : SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1641 : 8379492 : SET_SYMBOL_REF_DECL (x, decl);
1642 : :
1643 : 8379492 : x = gen_rtx_MEM (DECL_MODE (decl), x);
1644 : 8379492 : if (TREE_CODE (decl) != FUNCTION_DECL)
1645 : 3136475 : set_mem_attributes (x, decl, 1);
1646 : 8379492 : SET_DECL_RTL (decl, x);
1647 : :
1648 : : /* Optionally set flags or add text to the name to record information
1649 : : such as that it is a function name.
1650 : : If the name is changed, the macro ASM_OUTPUT_LABELREF
1651 : : will have to know how to strip this information. */
1652 : 8379492 : targetm.encode_section_info (decl, DECL_RTL (decl), true);
1653 : : }
1654 : :
1655 : : /* Like make_decl_rtl, but inhibit creation of new alias sets when
1656 : : calling make_decl_rtl. Also, reset DECL_RTL before returning the
1657 : : rtl. */
1658 : :
1659 : : rtx
1660 : 21549 : make_decl_rtl_for_debug (tree decl)
1661 : : {
1662 : 21549 : unsigned int save_aliasing_flag;
1663 : 21549 : rtx rtl;
1664 : :
1665 : 21549 : if (DECL_RTL_SET_P (decl))
1666 : 0 : return DECL_RTL (decl);
1667 : :
1668 : : /* Kludge alert! Somewhere down the call chain, make_decl_rtl will
1669 : : call new_alias_set. If running with -fcompare-debug, sometimes
1670 : : we do not want to create alias sets that will throw the alias
1671 : : numbers off in the comparison dumps. So... clearing
1672 : : flag_strict_aliasing will keep new_alias_set() from creating a
1673 : : new set. */
1674 : 21549 : save_aliasing_flag = flag_strict_aliasing;
1675 : 21549 : flag_strict_aliasing = 0;
1676 : :
1677 : 21549 : rtl = DECL_RTL (decl);
1678 : : /* Reset DECL_RTL back, as various parts of the compiler expects
1679 : : DECL_RTL set meaning it is actually going to be output. */
1680 : 21549 : SET_DECL_RTL (decl, NULL);
1681 : :
1682 : 21549 : flag_strict_aliasing = save_aliasing_flag;
1683 : 21549 : return rtl;
1684 : : }
1685 : :
1686 : : /* Output a string of literal assembler code
1687 : : for an `asm' keyword used between functions. */
1688 : :
1689 : : void
1690 : 12353 : assemble_asm (tree asm_str)
1691 : : {
1692 : 12353 : const char *p;
1693 : :
1694 : 12353 : if (TREE_CODE (asm_str) != ASM_EXPR)
1695 : : {
1696 : 12317 : app_enable ();
1697 : 12317 : if (TREE_CODE (asm_str) == ADDR_EXPR)
1698 : 0 : asm_str = TREE_OPERAND (asm_str, 0);
1699 : :
1700 : 12317 : p = TREE_STRING_POINTER (asm_str);
1701 : 24604 : fprintf (asm_out_file, "%s%s\n", p[0] == '\t' ? "" : "\t", p);
1702 : : }
1703 : : else
1704 : : {
1705 : 36 : location_t save_loc = input_location;
1706 : 36 : int save_reload_completed = reload_completed;
1707 : 36 : int save_cse_not_expected = cse_not_expected;
1708 : 36 : input_location = EXPR_LOCATION (asm_str);
1709 : 36 : int noutputs = list_length (ASM_OUTPUTS (asm_str));
1710 : 36 : int ninputs = list_length (ASM_INPUTS (asm_str));
1711 : 36 : const char **constraints = NULL;
1712 : 36 : int i;
1713 : 36 : tree tail;
1714 : 36 : bool allows_mem, allows_reg, is_inout;
1715 : 36 : rtx *ops = NULL;
1716 : 36 : if (noutputs + ninputs > MAX_RECOG_OPERANDS)
1717 : : {
1718 : 0 : error ("more than %d operands in %<asm%>", MAX_RECOG_OPERANDS);
1719 : 0 : goto done;
1720 : : }
1721 : 36 : constraints = XALLOCAVEC (const char *, noutputs + ninputs);
1722 : 36 : ops = XALLOCAVEC (rtx, noutputs + ninputs);
1723 : 36 : memset (&recog_data, 0, sizeof (recog_data));
1724 : 36 : recog_data.n_operands = ninputs + noutputs;
1725 : 36 : recog_data.is_asm = true;
1726 : 36 : reload_completed = 0;
1727 : 36 : cse_not_expected = 1;
1728 : 40 : for (i = 0, tail = ASM_OUTPUTS (asm_str); tail;
1729 : 4 : ++i, tail = TREE_CHAIN (tail))
1730 : : {
1731 : 16 : tree output = TREE_VALUE (tail);
1732 : 16 : if (output == error_mark_node)
1733 : 0 : goto done;
1734 : 32 : constraints[i]
1735 : 16 : = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
1736 : 16 : if (!parse_output_constraint (&constraints[i], i, ninputs, noutputs,
1737 : : &allows_mem, &allows_reg, &is_inout))
1738 : 0 : goto done;
1739 : 16 : if (is_inout)
1740 : : {
1741 : 4 : error ("%qc in output operand outside of a function", '+');
1742 : 4 : goto done;
1743 : : }
1744 : 12 : if (strchr (constraints[i], '&'))
1745 : : {
1746 : 4 : error ("%qc in output operand outside of a function", '&');
1747 : 4 : goto done;
1748 : : }
1749 : 8 : if (strchr (constraints[i], '%'))
1750 : : {
1751 : 4 : error ("%qc in output operand outside of a function", '%');
1752 : 4 : goto done;
1753 : : }
1754 : 4 : output_addressed_constants (output, 0);
1755 : 4 : if (!is_gimple_addressable (output))
1756 : : {
1757 : 0 : error ("output number %d not directly addressable", i);
1758 : 0 : goto done;
1759 : : }
1760 : 4 : ops[i] = expand_expr (build_fold_addr_expr (output), NULL_RTX,
1761 : : VOIDmode, EXPAND_INITIALIZER);
1762 : 4 : ops[i] = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (output)), ops[i]);
1763 : :
1764 : 4 : recog_data.operand[i] = ops[i];
1765 : 4 : recog_data.operand_loc[i] = &ops[i];
1766 : 4 : recog_data.constraints[i] = constraints[i];
1767 : 4 : recog_data.operand_mode[i] = TYPE_MODE (TREE_TYPE (output));
1768 : : }
1769 : 108 : for (i = 0, tail = ASM_INPUTS (asm_str); tail;
1770 : 84 : ++i, tail = TREE_CHAIN (tail))
1771 : : {
1772 : 88 : tree input = TREE_VALUE (tail);
1773 : 88 : if (input == error_mark_node)
1774 : 0 : goto done;
1775 : 176 : constraints[i + noutputs]
1776 : 88 : = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (tail)));
1777 : 88 : if (!parse_input_constraint (&constraints[i + noutputs], i,
1778 : : ninputs, noutputs, 0, constraints,
1779 : : &allows_mem, &allows_reg))
1780 : 0 : goto done;
1781 : 88 : if (strchr (constraints[i], '%'))
1782 : : {
1783 : 4 : error ("%qc in input operand outside of a function", '%');
1784 : 4 : goto done;
1785 : : }
1786 : 84 : const char *constraint = constraints[i + noutputs];
1787 : 84 : size_t c_len = strlen (constraint);
1788 : 188 : for (size_t j = 0; j < c_len;
1789 : 104 : j += CONSTRAINT_LEN (constraint[j], constraint + j))
1790 : 104 : if (constraint[j] >= '0' && constraint[j] <= '9')
1791 : : {
1792 : 0 : error ("matching constraint outside of a function");
1793 : 0 : goto done;
1794 : : }
1795 : 84 : output_addressed_constants (input, 0);
1796 : 84 : if (allows_mem && is_gimple_addressable (input))
1797 : : {
1798 : 8 : ops[i + noutputs]
1799 : 8 : = expand_expr (build_fold_addr_expr (input), NULL_RTX,
1800 : : VOIDmode, EXPAND_INITIALIZER);
1801 : 8 : ops[i + noutputs] = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (input)),
1802 : : ops[i + noutputs]);
1803 : : }
1804 : : else
1805 : 76 : ops[i + noutputs] = expand_expr (input, NULL_RTX, VOIDmode,
1806 : : EXPAND_INITIALIZER);
1807 : 84 : if (asm_operand_ok (ops[i + noutputs], constraint, NULL) <= 0)
1808 : : {
1809 : 0 : if (!allows_mem)
1810 : 0 : warning (0, "%<asm%> operand %d probably does not "
1811 : : "match constraints", i + noutputs);
1812 : : }
1813 : 84 : recog_data.operand[i + noutputs] = ops[i + noutputs];
1814 : 84 : recog_data.operand_loc[i + noutputs] = &ops[i + noutputs];
1815 : 84 : recog_data.constraints[i + noutputs] = constraints[i + noutputs];
1816 : 84 : recog_data.operand_mode[i + noutputs]
1817 : 84 : = TYPE_MODE (TREE_TYPE (input));
1818 : : }
1819 : 20 : if (recog_data.n_operands > 0)
1820 : : {
1821 : 20 : const char *p = recog_data.constraints[0];
1822 : 20 : recog_data.n_alternatives = 1;
1823 : 44 : while (*p)
1824 : 24 : recog_data.n_alternatives += (*p++ == ',');
1825 : : }
1826 : 108 : for (i = 0; i < recog_data.n_operands; i++)
1827 : 88 : recog_data.operand_type[i]
1828 : 172 : = recog_data.constraints[i][0] == '=' ? OP_OUT : OP_IN;
1829 : 20 : reload_completed = 1;
1830 : 20 : constrain_operands (1, ALL_ALTERNATIVES);
1831 : 20 : if (which_alternative < 0)
1832 : : {
1833 : 0 : error ("impossible constraint in %<asm%>");
1834 : 0 : goto done;
1835 : : }
1836 : 20 : this_is_asm_operands = make_insn_raw (gen_nop ());
1837 : 20 : insn_noperands = recog_data.n_operands;
1838 : 20 : if (TREE_STRING_POINTER (ASM_STRING (asm_str))[0])
1839 : : {
1840 : 20 : app_enable ();
1841 : 20 : output_asm_insn (TREE_STRING_POINTER (ASM_STRING (asm_str)), ops);
1842 : : }
1843 : 20 : insn_noperands = 0;
1844 : 20 : this_is_asm_operands = NULL;
1845 : :
1846 : 36 : done:
1847 : 36 : input_location = save_loc;
1848 : 36 : reload_completed = save_reload_completed;
1849 : 36 : cse_not_expected = save_cse_not_expected;
1850 : : }
1851 : 12353 : }
1852 : :
1853 : : /* Write the address of the entity given by SYMBOL to SEC. */
1854 : : void
1855 : 23585 : assemble_addr_to_section (rtx symbol, section *sec)
1856 : : {
1857 : 23585 : switch_to_section (sec);
1858 : 23970 : assemble_align (POINTER_SIZE);
1859 : 24355 : assemble_integer (symbol, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
1860 : 23585 : }
1861 : :
1862 : : /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if
1863 : : not) section for PRIORITY. */
1864 : : section *
1865 : 0 : get_cdtor_priority_section (int priority, bool constructor_p)
1866 : : {
1867 : : /* Buffer conservatively large enough for the full range of a 32-bit
1868 : : int plus the text below. */
1869 : 0 : char buf[18];
1870 : :
1871 : : /* ??? This only works reliably with the GNU linker. */
1872 : 0 : sprintf (buf, "%s.%.5u",
1873 : : constructor_p ? ".ctors" : ".dtors",
1874 : : /* Invert the numbering so the linker puts us in the proper
1875 : : order; constructors are run from right to left, and the
1876 : : linker sorts in increasing order. */
1877 : : MAX_INIT_PRIORITY - priority);
1878 : 0 : return get_section (buf, SECTION_WRITE, NULL);
1879 : : }
1880 : :
1881 : : void
1882 : 0 : default_named_section_asm_out_destructor (rtx symbol, int priority)
1883 : : {
1884 : 0 : section *sec;
1885 : :
1886 : 0 : if (priority != DEFAULT_INIT_PRIORITY)
1887 : 0 : sec = get_cdtor_priority_section (priority,
1888 : : /*constructor_p=*/false);
1889 : : else
1890 : 0 : sec = get_section (".dtors", SECTION_WRITE, NULL);
1891 : :
1892 : 0 : assemble_addr_to_section (symbol, sec);
1893 : 0 : }
1894 : :
1895 : : #ifdef DTORS_SECTION_ASM_OP
1896 : : void
1897 : : default_dtor_section_asm_out_destructor (rtx symbol,
1898 : : int priority ATTRIBUTE_UNUSED)
1899 : : {
1900 : : assemble_addr_to_section (symbol, dtors_section);
1901 : : }
1902 : : #endif
1903 : :
1904 : : void
1905 : 0 : default_named_section_asm_out_constructor (rtx symbol, int priority)
1906 : : {
1907 : 0 : section *sec;
1908 : :
1909 : 0 : if (priority != DEFAULT_INIT_PRIORITY)
1910 : 0 : sec = get_cdtor_priority_section (priority,
1911 : : /*constructor_p=*/true);
1912 : : else
1913 : 0 : sec = get_section (".ctors", SECTION_WRITE, NULL);
1914 : :
1915 : 0 : assemble_addr_to_section (symbol, sec);
1916 : 0 : }
1917 : :
1918 : : #ifdef CTORS_SECTION_ASM_OP
1919 : : void
1920 : : default_ctor_section_asm_out_constructor (rtx symbol,
1921 : : int priority ATTRIBUTE_UNUSED)
1922 : : {
1923 : : assemble_addr_to_section (symbol, ctors_section);
1924 : : }
1925 : : #endif
1926 : :
1927 : : /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
1928 : : a nonzero value if the constant pool should be output before the
1929 : : start of the function, or a zero value if the pool should output
1930 : : after the end of the function. The default is to put it before the
1931 : : start. */
1932 : :
1933 : : #ifndef CONSTANT_POOL_BEFORE_FUNCTION
1934 : : #define CONSTANT_POOL_BEFORE_FUNCTION 1
1935 : : #endif
1936 : :
1937 : : /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going
1938 : : to be output to assembler.
1939 : : Set first_global_object_name and weak_global_object_name as appropriate. */
1940 : :
1941 : : void
1942 : 97873102 : notice_global_symbol (tree decl)
1943 : : {
1944 : 97873102 : const char **t = &first_global_object_name;
1945 : :
1946 : 97873102 : if (first_global_object_name
1947 : 70847460 : || !TREE_PUBLIC (decl)
1948 : 69971308 : || DECL_EXTERNAL (decl)
1949 : 15389858 : || !DECL_NAME (decl)
1950 : 15389807 : || (VAR_P (decl) && DECL_HARD_REGISTER (decl))
1951 : 113262869 : || (TREE_CODE (decl) != FUNCTION_DECL
1952 : 9389526 : && (!VAR_P (decl)
1953 : 9389526 : || (DECL_COMMON (decl)
1954 : 9009 : && (DECL_INITIAL (decl) == 0
1955 : 8773 : || DECL_INITIAL (decl) == error_mark_node)))))
1956 : : return;
1957 : :
1958 : : /* We win when global object is found, but it is useful to know about weak
1959 : : symbol as well so we can produce nicer unique names. */
1960 : 15389531 : if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1961 : : t = &weak_global_object_name;
1962 : :
1963 : 15389531 : if (!*t)
1964 : : {
1965 : 267259 : tree id = DECL_ASSEMBLER_NAME (decl);
1966 : 267259 : ultimate_transparent_alias_target (&id);
1967 : 267259 : *t = ggc_strdup (targetm.strip_name_encoding (IDENTIFIER_POINTER (id)));
1968 : : }
1969 : : }
1970 : :
1971 : : /* If not using flag_reorder_blocks_and_partition, decide early whether the
1972 : : current function goes into the cold section, so that targets can use
1973 : : current_function_section during RTL expansion. DECL describes the
1974 : : function. */
1975 : :
1976 : : void
1977 : 1433459 : decide_function_section (tree decl)
1978 : : {
1979 : 1433459 : first_function_block_is_cold = false;
1980 : :
1981 : 1433459 : if (DECL_SECTION_NAME (decl))
1982 : : {
1983 : 8538 : struct cgraph_node *node = cgraph_node::get (current_function_decl);
1984 : : /* Calls to function_section rely on first_function_block_is_cold
1985 : : being accurate. */
1986 : 8538 : first_function_block_is_cold = (node
1987 : 8538 : && node->frequency
1988 : 8538 : == NODE_FREQUENCY_UNLIKELY_EXECUTED);
1989 : : }
1990 : :
1991 : 1433459 : in_cold_section_p = first_function_block_is_cold;
1992 : 1433459 : }
1993 : :
1994 : : /* Get the function's name, as described by its RTL. This may be
1995 : : different from the DECL_NAME name used in the source file. */
1996 : : const char *
1997 : 1498836 : get_fnname_from_decl (tree decl)
1998 : : {
1999 : 1498836 : rtx x = DECL_RTL (decl);
2000 : 1498836 : gcc_assert (MEM_P (x));
2001 : 1498836 : x = XEXP (x, 0);
2002 : 1498836 : gcc_assert (GET_CODE (x) == SYMBOL_REF);
2003 : 1498836 : return XSTR (x, 0);
2004 : : }
2005 : :
2006 : : /* Output function label, possibly with accompanying metadata. No additional
2007 : : code or data is output after the label. */
2008 : :
2009 : : void
2010 : 1492881 : assemble_function_label_raw (FILE *file, const char *name)
2011 : : {
2012 : 1492881 : ASM_OUTPUT_LABEL (file, name);
2013 : 1492881 : assemble_function_label_final ();
2014 : 1492881 : }
2015 : :
2016 : : /* Finish outputting function label. Needs to be called when outputting
2017 : : function label without using assemble_function_label_raw (). */
2018 : :
2019 : : void
2020 : 1492881 : assemble_function_label_final (void)
2021 : : {
2022 : 1492881 : if ((flag_sanitize & SANITIZE_ADDRESS)
2023 : : /* Notify ASAN only about the first function label. */
2024 : 5887 : && (in_cold_section_p == first_function_block_is_cold)
2025 : : /* Do not notify ASAN when called from, e.g., code_end (). */
2026 : 5767 : && cfun)
2027 : 5767 : asan_function_start ();
2028 : 1492881 : }
2029 : :
2030 : : /* Output assembler code for the constant pool of a function and associated
2031 : : with defining the name of the function. DECL describes the function.
2032 : : NAME is the function's name. For the constant pool, we use the current
2033 : : constant pool data. */
2034 : :
2035 : : void
2036 : 1428990 : assemble_start_function (tree decl, const char *fnname)
2037 : : {
2038 : 1428990 : int align;
2039 : 1428990 : char tmp_label[100];
2040 : 1428990 : bool hot_label_written = false;
2041 : :
2042 : 1428990 : if (crtl->has_bb_partition)
2043 : : {
2044 : 60332 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
2045 : 60332 : crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
2046 : 60332 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
2047 : 60332 : crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
2048 : 60332 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
2049 : 60332 : crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
2050 : 60332 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
2051 : 60332 : crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
2052 : 60332 : const_labelno++;
2053 : 60332 : cold_function_name = NULL_TREE;
2054 : : }
2055 : : else
2056 : : {
2057 : 1368658 : crtl->subsections.hot_section_label = NULL;
2058 : 1368658 : crtl->subsections.cold_section_label = NULL;
2059 : 1368658 : crtl->subsections.hot_section_end_label = NULL;
2060 : 1368658 : crtl->subsections.cold_section_end_label = NULL;
2061 : : }
2062 : :
2063 : : /* The following code does not need preprocessing in the assembler. */
2064 : :
2065 : 1428990 : app_disable ();
2066 : :
2067 : 1428990 : if (CONSTANT_POOL_BEFORE_FUNCTION)
2068 : 1428990 : output_constant_pool (fnname, decl);
2069 : :
2070 : 1428990 : align = symtab_node::get (decl)->definition_alignment ();
2071 : :
2072 : : /* Make sure the not and cold text (code) sections are properly
2073 : : aligned. This is necessary here in the case where the function
2074 : : has both hot and cold sections, because we don't want to re-set
2075 : : the alignment when the section switch happens mid-function. */
2076 : :
2077 : 1428990 : if (crtl->has_bb_partition)
2078 : : {
2079 : 60332 : first_function_block_is_cold = false;
2080 : :
2081 : 60332 : switch_to_section (unlikely_text_section ());
2082 : 60332 : assemble_align (align);
2083 : 60332 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label);
2084 : :
2085 : : /* When the function starts with a cold section, we need to explicitly
2086 : : align the hot section and write out the hot section label.
2087 : : But if the current function is a thunk, we do not have a CFG. */
2088 : 60332 : if (!cfun->is_thunk
2089 : 60332 : && BB_PARTITION (ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb) == BB_COLD_PARTITION)
2090 : : {
2091 : 0 : switch_to_section (text_section);
2092 : 0 : assemble_align (align);
2093 : 0 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
2094 : 0 : hot_label_written = true;
2095 : 0 : first_function_block_is_cold = true;
2096 : : }
2097 : 60332 : in_cold_section_p = first_function_block_is_cold;
2098 : : }
2099 : :
2100 : :
2101 : : /* Switch to the correct text section for the start of the function. */
2102 : :
2103 : 1428990 : switch_to_section (function_section (decl), decl);
2104 : 1428990 : if (crtl->has_bb_partition && !hot_label_written)
2105 : 60332 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label);
2106 : :
2107 : : /* Tell assembler to move to target machine's alignment for functions. */
2108 : 1428990 : align = floor_log2 (align / BITS_PER_UNIT);
2109 : : /* Handle forced alignment. This really ought to apply to all functions,
2110 : : since it is used by patchable entries. */
2111 : 1428990 : if (flag_min_function_alignment)
2112 : 0 : align = MAX (align, floor_log2 (flag_min_function_alignment));
2113 : :
2114 : 1428990 : if (align > 0)
2115 : : {
2116 : 158767 : ASM_OUTPUT_ALIGN (asm_out_file, align);
2117 : : }
2118 : :
2119 : : /* Handle a user-specified function alignment.
2120 : : Note that we still need to align to DECL_ALIGN, as above,
2121 : : because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
2122 : 1428990 : if (! DECL_USER_ALIGN (decl)
2123 : 1428956 : && align_functions.levels[0].log > align
2124 : 2314470 : && optimize_function_for_speed_p (cfun))
2125 : : {
2126 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2127 : 867450 : int align_log = align_functions.levels[0].log;
2128 : : #endif
2129 : 867450 : int max_skip = align_functions.levels[0].maxskip;
2130 : 867450 : if (flag_limit_function_alignment && crtl->max_insn_address > 0
2131 : 1 : && max_skip >= crtl->max_insn_address)
2132 : 1 : max_skip = crtl->max_insn_address - 1;
2133 : :
2134 : : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2135 : 867450 : ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, align_log, max_skip);
2136 : 867450 : if (max_skip == align_functions.levels[0].maxskip)
2137 : 867449 : ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
2138 : : align_functions.levels[1].log,
2139 : : align_functions.levels[1].maxskip);
2140 : : #else
2141 : : ASM_OUTPUT_ALIGN (asm_out_file, align_functions.levels[0].log);
2142 : : #endif
2143 : : }
2144 : :
2145 : : #ifdef ASM_OUTPUT_FUNCTION_PREFIX
2146 : : ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
2147 : : #endif
2148 : :
2149 : 1428990 : if (!DECL_IGNORED_P (decl))
2150 : 1405735 : (*debug_hooks->begin_function) (decl);
2151 : :
2152 : : /* Make function name accessible from other files, if appropriate. */
2153 : :
2154 : 1428990 : if (TREE_PUBLIC (decl))
2155 : : {
2156 : 1172200 : notice_global_symbol (decl);
2157 : :
2158 : 1172200 : globalize_decl (decl);
2159 : :
2160 : 1172200 : maybe_assemble_visibility (decl);
2161 : : }
2162 : :
2163 : 1428990 : if (DECL_PRESERVE_P (decl))
2164 : 4094 : targetm.asm_out.mark_decl_preserved (fnname);
2165 : :
2166 : 1428990 : unsigned short patch_area_size = crtl->patch_area_size;
2167 : 1428990 : unsigned short patch_area_entry = crtl->patch_area_entry;
2168 : :
2169 : : /* Emit the patching area before the entry label, if any. */
2170 : 1428990 : if (patch_area_entry > 0)
2171 : 8 : targetm.asm_out.print_patchable_function_entry (asm_out_file,
2172 : : patch_area_entry, true);
2173 : :
2174 : : /* Do any machine/system dependent processing of the function name. */
2175 : : #ifdef ASM_DECLARE_FUNCTION_NAME
2176 : 1428990 : ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
2177 : : #else
2178 : : /* Standard thing is just output label for the function. */
2179 : : ASM_OUTPUT_FUNCTION_LABEL (asm_out_file, fnname, current_function_decl);
2180 : : #endif /* ASM_DECLARE_FUNCTION_NAME */
2181 : :
2182 : : /* And the area after the label. Record it if we haven't done so yet. */
2183 : 1428990 : if (patch_area_size > patch_area_entry)
2184 : 51 : targetm.asm_out.print_patchable_function_entry (asm_out_file,
2185 : 51 : patch_area_size
2186 : 51 : - patch_area_entry,
2187 : : patch_area_entry == 0);
2188 : :
2189 : 1428990 : if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
2190 : 2458 : saw_no_split_stack = true;
2191 : 1428990 : }
2192 : :
2193 : : /* Output assembler code associated with defining the size of the
2194 : : function. DECL describes the function. NAME is the function's name. */
2195 : :
2196 : : void
2197 : 1428990 : assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED)
2198 : : {
2199 : : #ifdef ASM_DECLARE_FUNCTION_SIZE
2200 : : /* We could have switched section in the middle of the function. */
2201 : 1428990 : if (crtl->has_bb_partition)
2202 : 60332 : switch_to_section (function_section (decl));
2203 : 1428990 : ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
2204 : : #endif
2205 : 1428990 : if (! CONSTANT_POOL_BEFORE_FUNCTION)
2206 : : {
2207 : : output_constant_pool (fnname, decl);
2208 : : switch_to_section (function_section (decl)); /* need to switch back */
2209 : : }
2210 : : /* Output labels for end of hot/cold text sections (to be used by
2211 : : debug info.) */
2212 : 1428990 : if (crtl->has_bb_partition)
2213 : : {
2214 : 60332 : section *save_text_section;
2215 : :
2216 : 60332 : save_text_section = in_section;
2217 : 60332 : switch_to_section (unlikely_text_section ());
2218 : : #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
2219 : 60332 : if (cold_function_name != NULL_TREE)
2220 : 60332 : ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file,
2221 : : IDENTIFIER_POINTER (cold_function_name),
2222 : : decl);
2223 : : #endif
2224 : 60332 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
2225 : 60332 : if (first_function_block_is_cold)
2226 : 0 : switch_to_section (text_section);
2227 : : else
2228 : 60332 : switch_to_section (function_section (decl));
2229 : 60332 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
2230 : 60332 : switch_to_section (save_text_section);
2231 : : }
2232 : 1428990 : }
2233 : :
2234 : : /* Assemble code to leave SIZE bytes of zeros. */
2235 : :
2236 : : void
2237 : 1044994 : assemble_zeros (unsigned HOST_WIDE_INT size)
2238 : : {
2239 : : /* Do no output if -fsyntax-only. */
2240 : 1044994 : if (flag_syntax_only)
2241 : : return;
2242 : :
2243 : : #ifdef ASM_NO_SKIP_IN_TEXT
2244 : : /* The `space' pseudo in the text section outputs nop insns rather than 0s,
2245 : : so we must output 0s explicitly in the text section. */
2246 : 1044994 : if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0)
2247 : : {
2248 : : unsigned HOST_WIDE_INT i;
2249 : 0 : for (i = 0; i < size; i++)
2250 : 0 : assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1);
2251 : : }
2252 : : else
2253 : : #endif
2254 : 1044994 : if (size > 0)
2255 : 973571 : ASM_OUTPUT_SKIP (asm_out_file, size);
2256 : : }
2257 : :
2258 : : /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
2259 : :
2260 : : void
2261 : 388249 : assemble_align (unsigned int align)
2262 : : {
2263 : 388249 : if (align > BITS_PER_UNIT)
2264 : : {
2265 : 332756 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2266 : : }
2267 : 388249 : }
2268 : :
2269 : : /* Assemble a string constant with the specified C string as contents. */
2270 : :
2271 : : void
2272 : 31373555 : assemble_string (const char *p, int size)
2273 : : {
2274 : 31373555 : int pos = 0;
2275 : : #if defined(BASE64_ASM_OP) \
2276 : : && BITS_PER_UNIT == 8 \
2277 : : && CHAR_BIT == 8 \
2278 : : && 'A' == 65 \
2279 : : && 'a' == 97 \
2280 : : && '0' == 48 \
2281 : : && '+' == 43 \
2282 : : && '/' == 47 \
2283 : : && '=' == 61
2284 : 31373555 : int maximum = 16384;
2285 : : #else
2286 : : int maximum = 2000;
2287 : : #endif
2288 : :
2289 : : /* If the string is very long, split it up. */
2290 : :
2291 : 62743419 : while (pos < size)
2292 : : {
2293 : 31369864 : int thissize = size - pos;
2294 : 31369864 : if (thissize > maximum)
2295 : : thissize = maximum;
2296 : :
2297 : 31369864 : ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
2298 : :
2299 : 31369864 : pos += thissize;
2300 : 31369864 : p += thissize;
2301 : : }
2302 : 31373555 : }
2303 : :
2304 : :
2305 : : /* A noswitch_section_callback for lcomm_section. */
2306 : :
2307 : : static bool
2308 : 152138 : emit_local (tree decl ATTRIBUTE_UNUSED,
2309 : : const char *name ATTRIBUTE_UNUSED,
2310 : : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2311 : : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2312 : : {
2313 : : #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
2314 : 152138 : unsigned int align = symtab_node::get (decl)->definition_alignment ();
2315 : 152138 : ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
2316 : : size, align);
2317 : 152138 : return true;
2318 : : #elif defined ASM_OUTPUT_ALIGNED_LOCAL
2319 : : unsigned int align = symtab_node::get (decl)->definition_alignment ();
2320 : : ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, align);
2321 : : return true;
2322 : : #else
2323 : : ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2324 : : return false;
2325 : : #endif
2326 : : }
2327 : :
2328 : : /* A noswitch_section_callback for bss_noswitch_section. */
2329 : :
2330 : : #if defined ASM_OUTPUT_ALIGNED_BSS
2331 : : static bool
2332 : 762862 : emit_bss (tree decl ATTRIBUTE_UNUSED,
2333 : : const char *name ATTRIBUTE_UNUSED,
2334 : : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2335 : : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2336 : : {
2337 : 762862 : ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
2338 : : get_variable_align (decl));
2339 : 762862 : return true;
2340 : : }
2341 : : #endif
2342 : :
2343 : : /* A noswitch_section_callback for comm_section. */
2344 : :
2345 : : static bool
2346 : 1310 : emit_common (tree decl ATTRIBUTE_UNUSED,
2347 : : const char *name ATTRIBUTE_UNUSED,
2348 : : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2349 : : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2350 : : {
2351 : : #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
2352 : 1310 : ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name,
2353 : 1310 : size, get_variable_align (decl));
2354 : 1310 : return true;
2355 : : #elif defined ASM_OUTPUT_ALIGNED_COMMON
2356 : : ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
2357 : : get_variable_align (decl));
2358 : : return true;
2359 : : #else
2360 : : ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
2361 : : return false;
2362 : : #endif
2363 : : }
2364 : :
2365 : : /* A noswitch_section_callback for tls_comm_section. */
2366 : :
2367 : : static bool
2368 : 50 : emit_tls_common (tree decl ATTRIBUTE_UNUSED,
2369 : : const char *name ATTRIBUTE_UNUSED,
2370 : : unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED,
2371 : : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED)
2372 : : {
2373 : : #ifdef ASM_OUTPUT_TLS_COMMON
2374 : 50 : ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size);
2375 : 50 : return true;
2376 : : #else
2377 : : sorry ("thread-local COMMON data not implemented");
2378 : : return true;
2379 : : #endif
2380 : : }
2381 : :
2382 : : /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT.
2383 : : NAME is the name of DECL's SYMBOL_REF. */
2384 : :
2385 : : static void
2386 : 916360 : assemble_noswitch_variable (tree decl, const char *name, section *sect,
2387 : : unsigned int align)
2388 : : {
2389 : 916360 : unsigned HOST_WIDE_INT size, rounded;
2390 : :
2391 : 916360 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2392 : 916360 : rounded = size;
2393 : :
2394 : 916360 : if ((flag_sanitize & SANITIZE_ADDRESS) && asan_protect_global (decl))
2395 : 1878 : size += asan_red_zone_size (size);
2396 : :
2397 : : /* Don't allocate zero bytes of common,
2398 : : since that means "undefined external" in the linker. */
2399 : 916360 : if (size == 0)
2400 : 1535 : rounded = 1;
2401 : :
2402 : : /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2403 : : so that each uninitialized object starts on such a boundary. */
2404 : 916360 : rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2405 : 916360 : rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2406 : 916360 : * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2407 : :
2408 : 916360 : if (!sect->noswitch.callback (decl, name, size, rounded)
2409 : 916360 : && (unsigned HOST_WIDE_INT) (align / BITS_PER_UNIT) > rounded)
2410 : 0 : error ("requested alignment for %q+D is greater than "
2411 : : "implemented alignment of %wu", decl, rounded);
2412 : 916360 : }
2413 : :
2414 : : /* A subroutine of assemble_variable. Output the label and contents of
2415 : : DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA
2416 : : is as for assemble_variable. */
2417 : :
2418 : : static void
2419 : 1883633 : assemble_variable_contents (tree decl, const char *name,
2420 : : bool dont_output_data, bool merge_strings)
2421 : : {
2422 : : /* Do any machine/system dependent processing of the object. */
2423 : : #ifdef ASM_DECLARE_OBJECT_NAME
2424 : 1883633 : last_assemble_variable_decl = decl;
2425 : 1883633 : ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
2426 : : #else
2427 : : /* Standard thing is just output label for the object. */
2428 : : ASM_OUTPUT_LABEL (asm_out_file, name);
2429 : : #endif /* ASM_DECLARE_OBJECT_NAME */
2430 : :
2431 : 1883633 : if (!dont_output_data)
2432 : : {
2433 : : /* Caller is supposed to use varpool_get_constructor when it wants
2434 : : to output the body. */
2435 : 1882829 : gcc_assert (!in_lto_p || DECL_INITIAL (decl) != error_mark_node);
2436 : 1882829 : if (DECL_INITIAL (decl)
2437 : 1871382 : && DECL_INITIAL (decl) != error_mark_node
2438 : 3754209 : && !initializer_zerop (DECL_INITIAL (decl)))
2439 : : /* Output the actual data. */
2440 : 3579714 : output_constant (DECL_INITIAL (decl),
2441 : 1789857 : tree_to_uhwi (DECL_SIZE_UNIT (decl)),
2442 : : get_variable_align (decl),
2443 : : false, merge_strings);
2444 : : else
2445 : : /* Leave space for it. */
2446 : 92972 : assemble_zeros (tree_to_uhwi (DECL_SIZE_UNIT (decl)));
2447 : 1882829 : targetm.asm_out.decl_end ();
2448 : : }
2449 : 1883633 : }
2450 : :
2451 : : /* Write out assembly for the variable DECL, which is not defined in
2452 : : the current translation unit. */
2453 : : void
2454 : 292132 : assemble_undefined_decl (tree decl)
2455 : : {
2456 : 292132 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2457 : 292132 : targetm.asm_out.assemble_undefined_decl (asm_out_file, name, decl);
2458 : 292132 : }
2459 : :
2460 : : /* Assemble everything that is needed for a variable or function declaration.
2461 : : Not used for automatic variables, and not used for function definitions.
2462 : : Should not be called for variables of incomplete structure type.
2463 : :
2464 : : TOP_LEVEL is nonzero if this variable has file scope.
2465 : : AT_END is nonzero if this is the special handling, at end of compilation,
2466 : : to define things that have had only tentative definitions.
2467 : : DONT_OUTPUT_DATA if nonzero means don't actually output the
2468 : : initial value (that will be done by the caller). */
2469 : :
2470 : : void
2471 : 2803885 : assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2472 : : int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2473 : : {
2474 : 2803885 : const char *name;
2475 : 2803885 : rtx decl_rtl, symbol;
2476 : 2803885 : section *sect;
2477 : 2803885 : unsigned int align;
2478 : 2803885 : bool asan_protected = false;
2479 : :
2480 : : /* This function is supposed to handle VARIABLES. Ensure we have one. */
2481 : 2803885 : gcc_assert (VAR_P (decl));
2482 : :
2483 : : /* Emulated TLS had better not get this far. */
2484 : 2803885 : gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
2485 : :
2486 : 2803885 : last_assemble_variable_decl = 0;
2487 : :
2488 : : /* Normally no need to say anything here for external references,
2489 : : since assemble_external is called by the language-specific code
2490 : : when a declaration is first seen. */
2491 : :
2492 : 2803885 : if (DECL_EXTERNAL (decl))
2493 : : return;
2494 : :
2495 : : /* Do nothing for global register variables. */
2496 : 2801759 : if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl)))
2497 : : {
2498 : 0 : TREE_ASM_WRITTEN (decl) = 1;
2499 : 0 : return;
2500 : : }
2501 : :
2502 : : /* If type was incomplete when the variable was declared,
2503 : : see if it is complete now. */
2504 : :
2505 : 2801759 : if (DECL_SIZE (decl) == 0)
2506 : 1 : layout_decl (decl, 0);
2507 : :
2508 : : /* Still incomplete => don't allocate it; treat the tentative defn
2509 : : (which is what it must have been) as an `extern' reference. */
2510 : :
2511 : 2801759 : if (!dont_output_data && DECL_SIZE (decl) == 0)
2512 : : {
2513 : 1 : error ("storage size of %q+D isn%'t known", decl);
2514 : 1 : TREE_ASM_WRITTEN (decl) = 1;
2515 : 1 : return;
2516 : : }
2517 : :
2518 : : /* The first declaration of a variable that comes through this function
2519 : : decides whether it is global (in C, has external linkage)
2520 : : or local (in C, has internal linkage). So do nothing more
2521 : : if this function has already run. */
2522 : :
2523 : 2801758 : if (TREE_ASM_WRITTEN (decl))
2524 : : return;
2525 : :
2526 : : /* Make sure targetm.encode_section_info is invoked before we set
2527 : : ASM_WRITTEN. */
2528 : 2801758 : decl_rtl = DECL_RTL (decl);
2529 : :
2530 : 2801758 : TREE_ASM_WRITTEN (decl) = 1;
2531 : :
2532 : : /* Do no output if -fsyntax-only. */
2533 : 2801758 : if (flag_syntax_only)
2534 : : return;
2535 : :
2536 : 2801758 : if (! dont_output_data
2537 : 2801758 : && ! valid_constant_size_p (DECL_SIZE_UNIT (decl)))
2538 : : {
2539 : 2 : error ("size of variable %q+D is too large", decl);
2540 : 2 : return;
2541 : : }
2542 : :
2543 : 2801756 : gcc_assert (MEM_P (decl_rtl));
2544 : 2801756 : gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2545 : 2801756 : symbol = XEXP (decl_rtl, 0);
2546 : :
2547 : : /* If this symbol belongs to the tree constant pool, output the constant
2548 : : if it hasn't already been written. */
2549 : 2801756 : if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2550 : : {
2551 : 1763 : tree decl = SYMBOL_REF_DECL (symbol);
2552 : 1763 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2553 : 1100 : output_constant_def_contents (symbol);
2554 : 1763 : return;
2555 : : }
2556 : :
2557 : 2799993 : app_disable ();
2558 : :
2559 : 2799993 : name = XSTR (symbol, 0);
2560 : 2799993 : if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2561 : 1396537 : notice_global_symbol (decl);
2562 : :
2563 : : /* Compute the alignment of this data. */
2564 : :
2565 : 2799993 : align_variable (decl, dont_output_data);
2566 : :
2567 : 2799993 : if ((flag_sanitize & SANITIZE_ADDRESS)
2568 : 2799993 : && asan_protect_global (decl))
2569 : : {
2570 : 2209 : asan_protected = true;
2571 : 2209 : SET_DECL_ALIGN (decl, MAX (DECL_ALIGN (decl),
2572 : : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT));
2573 : : }
2574 : :
2575 : 2799993 : set_mem_align (decl_rtl, DECL_ALIGN (decl));
2576 : :
2577 : 2799993 : align = get_variable_align (decl);
2578 : :
2579 : 2799993 : if (TREE_PUBLIC (decl))
2580 : 1396759 : maybe_assemble_visibility (decl);
2581 : :
2582 : 2799993 : if (DECL_PRESERVE_P (decl))
2583 : 956 : targetm.asm_out.mark_decl_preserved (name);
2584 : :
2585 : : /* First make the assembler name(s) global if appropriate. */
2586 : 2799993 : sect = get_variable_section (decl, false);
2587 : 2799993 : if (TREE_PUBLIC (decl)
2588 : 1396759 : && (sect->common.flags & SECTION_COMMON) == 0)
2589 : 1395399 : globalize_decl (decl);
2590 : :
2591 : : /* Output any data that we will need to use the address of. */
2592 : 2799993 : if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2593 : 1891999 : output_addressed_constants (DECL_INITIAL (decl), 0);
2594 : :
2595 : : /* dbxout.cc needs to know this. */
2596 : 2799993 : if (sect && (sect->common.flags & SECTION_CODE) != 0)
2597 : 0 : DECL_IN_TEXT_SECTION (decl) = 1;
2598 : :
2599 : : /* If the decl is part of an object_block, make sure that the decl
2600 : : has been positioned within its block, but do not write out its
2601 : : definition yet. output_object_blocks will do that later. */
2602 : 2799993 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
2603 : : {
2604 : 0 : gcc_assert (!dont_output_data);
2605 : 0 : place_block_symbol (symbol);
2606 : : }
2607 : 2799993 : else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2608 : 916360 : assemble_noswitch_variable (decl, name, sect, align);
2609 : : else
2610 : : {
2611 : : /* Special-case handling of vtv comdat sections. */
2612 : 1883633 : if (SECTION_STYLE (sect) == SECTION_NAMED
2613 : 1516968 : && (strcmp (sect->named.name, ".vtable_map_vars") == 0))
2614 : 3 : handle_vtv_comdat_section (sect, decl);
2615 : : else
2616 : 1883630 : switch_to_section (sect, decl);
2617 : 1883633 : if (align > BITS_PER_UNIT)
2618 : 1799785 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2619 : 1883633 : assemble_variable_contents (decl, name, dont_output_data,
2620 : : (sect->common.flags & SECTION_MERGE)
2621 : 1883633 : && (sect->common.flags & SECTION_STRINGS));
2622 : 1883633 : if (asan_protected)
2623 : : {
2624 : 1219 : unsigned HOST_WIDE_INT int size
2625 : 1219 : = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2626 : 2302 : assemble_zeros (asan_red_zone_size (size));
2627 : : }
2628 : : }
2629 : : }
2630 : :
2631 : : /* Return true if type TYPE contains any pointers. */
2632 : :
2633 : : static bool
2634 : 2 : contains_pointers_p (tree type)
2635 : : {
2636 : 2 : switch (TREE_CODE (type))
2637 : : {
2638 : : case POINTER_TYPE:
2639 : : case REFERENCE_TYPE:
2640 : : /* I'm not sure whether OFFSET_TYPE needs this treatment,
2641 : : so I'll play safe and return 1. */
2642 : : case OFFSET_TYPE:
2643 : : return true;
2644 : :
2645 : 0 : case RECORD_TYPE:
2646 : 0 : case UNION_TYPE:
2647 : 0 : case QUAL_UNION_TYPE:
2648 : 0 : {
2649 : 0 : tree fields;
2650 : : /* For a type that has fields, see if the fields have pointers. */
2651 : 0 : for (fields = TYPE_FIELDS (type); fields; fields = DECL_CHAIN (fields))
2652 : 0 : if (TREE_CODE (fields) == FIELD_DECL
2653 : 0 : && contains_pointers_p (TREE_TYPE (fields)))
2654 : : return true;
2655 : : return false;
2656 : : }
2657 : :
2658 : 0 : case ARRAY_TYPE:
2659 : : /* An array type contains pointers if its element type does. */
2660 : 0 : return contains_pointers_p (TREE_TYPE (type));
2661 : :
2662 : : default:
2663 : : return false;
2664 : : }
2665 : : }
2666 : :
2667 : : /* We delay assemble_external processing until
2668 : : the compilation unit is finalized. This is the best we can do for
2669 : : right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay
2670 : : it all the way to final. See PR 17982 for further discussion. */
2671 : : static GTY(()) tree pending_assemble_externals;
2672 : :
2673 : : /* A similar list of pending libcall symbols. We only want to declare
2674 : : symbols that are actually used in the final assembly. */
2675 : : static GTY(()) rtx pending_libcall_symbols;
2676 : :
2677 : : #ifdef ASM_OUTPUT_EXTERNAL
2678 : : /* Some targets delay some output to final using TARGET_ASM_FILE_END.
2679 : : As a result, assemble_external can be called after the list of externals
2680 : : is processed and the pointer set destroyed. */
2681 : : static bool pending_assemble_externals_processed;
2682 : :
2683 : : /* Avoid O(external_decls**2) lookups in the pending_assemble_externals
2684 : : TREE_LIST in assemble_external. */
2685 : : static hash_set<tree> *pending_assemble_externals_set;
2686 : :
2687 : : /* True if DECL is a function decl for which no out-of-line copy exists.
2688 : : It is assumed that DECL's assembler name has been set. */
2689 : :
2690 : : static bool
2691 : 1774707 : incorporeal_function_p (tree decl)
2692 : : {
2693 : 1774707 : if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl))
2694 : : {
2695 : 189730 : const char *name;
2696 : :
2697 : 189730 : if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2698 : 189730 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
2699 : : return true;
2700 : :
2701 : 189725 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2702 : : /* Atomic or sync builtins which have survived this far will be
2703 : : resolved externally and therefore are not incorporeal. */
2704 : 189725 : if (startswith (name, "__builtin_"))
2705 : : return true;
2706 : : }
2707 : : return false;
2708 : : }
2709 : :
2710 : : /* Actually do the tests to determine if this is necessary, and invoke
2711 : : ASM_OUTPUT_EXTERNAL. */
2712 : : static void
2713 : 1786054 : assemble_external_real (tree decl)
2714 : : {
2715 : 1786054 : rtx rtl = DECL_RTL (decl);
2716 : :
2717 : 1786054 : if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2718 : 1786054 : && !SYMBOL_REF_USED (XEXP (rtl, 0))
2719 : 3560761 : && !incorporeal_function_p (decl))
2720 : : {
2721 : : /* Some systems do require some output. */
2722 : 1774702 : SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2723 : 1774702 : ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2724 : : }
2725 : 1786054 : }
2726 : : #endif
2727 : :
2728 : : void
2729 : 225316 : process_pending_assemble_externals (void)
2730 : : {
2731 : : #ifdef ASM_OUTPUT_EXTERNAL
2732 : 225316 : tree list;
2733 : 2011370 : for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2734 : 1786054 : assemble_external_real (TREE_VALUE (list));
2735 : :
2736 : 251308 : for (rtx list = pending_libcall_symbols; list; list = XEXP (list, 1))
2737 : : {
2738 : 25992 : rtx symbol = XEXP (list, 0);
2739 : 25992 : const char *name = targetm.strip_name_encoding (XSTR (symbol, 0));
2740 : 25992 : tree id = get_identifier (name);
2741 : 25992 : if (TREE_SYMBOL_REFERENCED (id))
2742 : 25935 : targetm.asm_out.external_libcall (symbol);
2743 : : }
2744 : :
2745 : 225316 : pending_assemble_externals = 0;
2746 : 225316 : pending_assemble_externals_processed = true;
2747 : 225316 : pending_libcall_symbols = NULL_RTX;
2748 : 450632 : delete pending_assemble_externals_set;
2749 : 225316 : pending_assemble_externals_set = nullptr;
2750 : : #endif
2751 : 225316 : }
2752 : :
2753 : : /* This TREE_LIST contains any weak symbol declarations waiting
2754 : : to be emitted. */
2755 : : static GTY(()) tree weak_decls;
2756 : :
2757 : : /* Output something to declare an external symbol to the assembler,
2758 : : and qualifiers such as weakness. (Most assemblers don't need
2759 : : extern declaration, so we normally output nothing.) Do nothing if
2760 : : DECL is not external. */
2761 : :
2762 : : void
2763 : 39174741 : assemble_external (tree decl ATTRIBUTE_UNUSED)
2764 : : {
2765 : : /* Make sure that the ASM_OUT_FILE is open.
2766 : : If it's not, we should not be calling this function. */
2767 : 39174741 : gcc_assert (asm_out_file);
2768 : :
2769 : : /* In a perfect world, the following condition would be true.
2770 : : Sadly, the Go front end emit assembly *from the front end*,
2771 : : bypassing the call graph. See PR52739. Fix before GCC 4.8. */
2772 : : #if 0
2773 : : /* This function should only be called if we are expanding, or have
2774 : : expanded, to RTL.
2775 : : Ideally, only final.cc would be calling this function, but it is
2776 : : not clear whether that would break things somehow. See PR 17982
2777 : : for further discussion. */
2778 : : gcc_assert (state == EXPANSION
2779 : : || state == FINISHED);
2780 : : #endif
2781 : :
2782 : 39174741 : if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
2783 : : return;
2784 : :
2785 : : /* We want to output annotation for weak and external symbols at
2786 : : very last to check if they are references or not. */
2787 : :
2788 : 17208319 : if (TARGET_SUPPORTS_WEAK
2789 : 17208319 : && DECL_WEAK (decl)
2790 : : /* TREE_STATIC is a weird and abused creature which is not
2791 : : generally the right test for whether an entity has been
2792 : : locally emitted, inlined or otherwise not-really-extern, but
2793 : : for declarations that can be weak, it happens to be
2794 : : match. */
2795 : 10594 : && !TREE_STATIC (decl)
2796 : 5206 : && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2797 : 17213052 : && value_member (decl, weak_decls) == NULL_TREE)
2798 : 948 : weak_decls = tree_cons (NULL, decl, weak_decls);
2799 : :
2800 : : #ifdef ASM_OUTPUT_EXTERNAL
2801 : 17208319 : if (pending_assemble_externals_processed)
2802 : : {
2803 : 0 : assemble_external_real (decl);
2804 : 0 : return;
2805 : : }
2806 : :
2807 : 17208319 : if (! pending_assemble_externals_set->add (decl))
2808 : 1786099 : pending_assemble_externals = tree_cons (NULL, decl,
2809 : : pending_assemble_externals);
2810 : : #endif
2811 : : }
2812 : :
2813 : : /* Similar, for calling a library function FUN. */
2814 : :
2815 : : void
2816 : 190266 : assemble_external_libcall (rtx fun)
2817 : : {
2818 : : /* Declare library function name external when first used, if nec. */
2819 : 190266 : if (! SYMBOL_REF_USED (fun))
2820 : : {
2821 : : #ifdef ASM_OUTPUT_EXTERNAL
2822 : 26003 : gcc_assert (!pending_assemble_externals_processed);
2823 : : #endif
2824 : 26003 : SYMBOL_REF_USED (fun) = 1;
2825 : : /* Make sure the libcall symbol is in the symtab so any
2826 : : reference to it will mark its tree node as referenced, via
2827 : : assemble_name_resolve. These are eventually emitted, if
2828 : : used, in process_pending_assemble_externals. */
2829 : 26003 : const char *name = targetm.strip_name_encoding (XSTR (fun, 0));
2830 : 26003 : get_identifier (name);
2831 : 26003 : pending_libcall_symbols = gen_rtx_EXPR_LIST (VOIDmode, fun,
2832 : : pending_libcall_symbols);
2833 : : }
2834 : 190266 : }
2835 : :
2836 : : /* Assemble a label named NAME. */
2837 : :
2838 : : void
2839 : 1250302 : assemble_label (FILE *file, const char *name)
2840 : : {
2841 : 1250302 : ASM_OUTPUT_LABEL (file, name);
2842 : 1250302 : }
2843 : :
2844 : : /* Set the symbol_referenced flag for ID. */
2845 : : void
2846 : 33681115 : mark_referenced (tree id)
2847 : : {
2848 : 33681115 : TREE_SYMBOL_REFERENCED (id) = 1;
2849 : 33681115 : }
2850 : :
2851 : : /* Set the symbol_referenced flag for DECL and notify callgraph. */
2852 : : void
2853 : 5634 : mark_decl_referenced (tree decl)
2854 : : {
2855 : 5634 : if (TREE_CODE (decl) == FUNCTION_DECL)
2856 : : {
2857 : : /* Extern inline functions don't become needed when referenced.
2858 : : If we know a method will be emitted in other TU and no new
2859 : : functions can be marked reachable, just use the external
2860 : : definition. */
2861 : 5632 : struct cgraph_node *node = cgraph_node::get_create (decl);
2862 : 5632 : if (!DECL_EXTERNAL (decl)
2863 : 5632 : && !node->definition)
2864 : 12 : node->mark_force_output ();
2865 : : }
2866 : 2 : else if (VAR_P (decl))
2867 : : {
2868 : 2 : varpool_node *node = varpool_node::get_create (decl);
2869 : : /* C++ frontend use mark_decl_references to force COMDAT variables
2870 : : to be output that might appear dead otherwise. */
2871 : 2 : node->force_output = true;
2872 : : }
2873 : : /* else do nothing - we can get various sorts of CST nodes here,
2874 : : which do not need to be marked. */
2875 : 5634 : }
2876 : :
2877 : :
2878 : : /* Output to FILE (an assembly file) a reference to NAME. If NAME
2879 : : starts with a *, the rest of NAME is output verbatim. Otherwise
2880 : : NAME is transformed in a target-specific way (usually by the
2881 : : addition of an underscore). */
2882 : :
2883 : : void
2884 : 410404100 : assemble_name_raw (FILE *file, const char *name)
2885 : : {
2886 : 410404100 : if (name[0] == '*')
2887 : 376376730 : fputs (&name[1], file);
2888 : : else
2889 : 34027370 : ASM_OUTPUT_LABELREF (file, name);
2890 : 410404100 : }
2891 : :
2892 : : /* Return NAME that should actually be emitted, looking through
2893 : : transparent aliases. If NAME refers to an entity that is also
2894 : : represented as a tree (like a function or variable), mark the entity
2895 : : as referenced. */
2896 : : const char *
2897 : 344919874 : assemble_name_resolve (const char *name)
2898 : : {
2899 : 344919874 : const char *real_name = targetm.strip_name_encoding (name);
2900 : 344919874 : tree id = maybe_get_identifier (real_name);
2901 : :
2902 : 344919874 : if (id)
2903 : : {
2904 : 33681115 : tree id_orig = id;
2905 : :
2906 : 33681115 : mark_referenced (id);
2907 : 33681115 : ultimate_transparent_alias_target (&id);
2908 : 33681115 : if (id != id_orig)
2909 : 0 : name = IDENTIFIER_POINTER (id);
2910 : 33681115 : gcc_assert (! TREE_CHAIN (id));
2911 : : }
2912 : :
2913 : 344919874 : return name;
2914 : : }
2915 : :
2916 : : /* Like assemble_name_raw, but should be used when NAME might refer to
2917 : : an entity that is also represented as a tree (like a function or
2918 : : variable). If NAME does refer to such an entity, that entity will
2919 : : be marked as referenced. */
2920 : :
2921 : : void
2922 : 235479758 : assemble_name (FILE *file, const char *name)
2923 : : {
2924 : 235479758 : assemble_name_raw (file, assemble_name_resolve (name));
2925 : 235479758 : }
2926 : :
2927 : : /* Allocate SIZE bytes writable static space with a gensym name
2928 : : and return an RTX to refer to its address. */
2929 : :
2930 : : rtx
2931 : 0 : assemble_static_space (unsigned HOST_WIDE_INT size)
2932 : : {
2933 : 0 : char name[17];
2934 : 0 : const char *namestring;
2935 : 0 : rtx x;
2936 : :
2937 : 0 : ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
2938 : 0 : ++const_labelno;
2939 : 0 : namestring = ggc_strdup (name);
2940 : :
2941 : 0 : x = gen_rtx_SYMBOL_REF (Pmode, namestring);
2942 : 0 : SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
2943 : :
2944 : : #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
2945 : 0 : ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
2946 : : BIGGEST_ALIGNMENT);
2947 : : #else
2948 : : #ifdef ASM_OUTPUT_ALIGNED_LOCAL
2949 : : ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
2950 : : #else
2951 : : {
2952 : : /* Round size up to multiple of BIGGEST_ALIGNMENT bits
2953 : : so that each uninitialized object starts on such a boundary. */
2954 : : /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
2955 : : unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED
2956 : : = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
2957 : : / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2958 : : * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2959 : : ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
2960 : : }
2961 : : #endif
2962 : : #endif
2963 : 0 : return x;
2964 : : }
2965 : :
2966 : : /* Assemble the static constant template for function entry trampolines.
2967 : : This is done at most once per compilation.
2968 : : Returns an RTX for the address of the template. */
2969 : :
2970 : : static GTY(()) rtx initial_trampoline;
2971 : :
2972 : : rtx
2973 : 0 : assemble_trampoline_template (void)
2974 : : {
2975 : 0 : char label[256];
2976 : 0 : const char *name;
2977 : 0 : int align;
2978 : 0 : rtx symbol;
2979 : :
2980 : 0 : gcc_assert (targetm.asm_out.trampoline_template != NULL);
2981 : :
2982 : 0 : if (initial_trampoline)
2983 : : return initial_trampoline;
2984 : :
2985 : : /* By default, put trampoline templates in read-only data section. */
2986 : :
2987 : : #ifdef TRAMPOLINE_SECTION
2988 : : switch_to_section (TRAMPOLINE_SECTION);
2989 : : #else
2990 : 0 : switch_to_section (readonly_data_section);
2991 : : #endif
2992 : :
2993 : : /* Write the assembler code to define one. */
2994 : 0 : align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
2995 : 0 : if (align > 0)
2996 : 0 : ASM_OUTPUT_ALIGN (asm_out_file, align);
2997 : :
2998 : 0 : targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0);
2999 : 0 : targetm.asm_out.trampoline_template (asm_out_file);
3000 : :
3001 : : /* Record the rtl to refer to it. */
3002 : 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
3003 : 0 : name = ggc_strdup (label);
3004 : 0 : symbol = gen_rtx_SYMBOL_REF (Pmode, name);
3005 : 0 : SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
3006 : :
3007 : 0 : initial_trampoline = gen_const_mem (BLKmode, symbol);
3008 : 0 : set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT);
3009 : 0 : set_mem_size (initial_trampoline, TRAMPOLINE_SIZE);
3010 : :
3011 : 0 : return initial_trampoline;
3012 : : }
3013 : :
3014 : : /* A and B are either alignments or offsets. Return the minimum alignment
3015 : : that may be assumed after adding the two together. */
3016 : :
3017 : : static inline unsigned
3018 : 14883501 : min_align (unsigned int a, unsigned int b)
3019 : : {
3020 : 14883501 : return least_bit_hwi (a | b);
3021 : : }
3022 : :
3023 : : /* Return the assembler directive for creating a given kind of integer
3024 : : object. SIZE is the number of bytes in the object and ALIGNED_P
3025 : : indicates whether it is known to be aligned. Return NULL if the
3026 : : assembly dialect has no such directive.
3027 : :
3028 : : The returned string should be printed at the start of a new line and
3029 : : be followed immediately by the object's initial value. */
3030 : :
3031 : : const char *
3032 : 398453091 : integer_asm_op (int size, int aligned_p)
3033 : : {
3034 : 398453091 : struct asm_int_op *ops;
3035 : :
3036 : 398453091 : if (aligned_p)
3037 : : ops = &targetm.asm_out.aligned_op;
3038 : : else
3039 : 384320442 : ops = &targetm.asm_out.unaligned_op;
3040 : :
3041 : 398453091 : switch (size)
3042 : : {
3043 : 201046483 : case 1:
3044 : 201046483 : return targetm.asm_out.byte_op;
3045 : 19884385 : case 2:
3046 : 19884385 : return ops->hi;
3047 : 0 : case 3:
3048 : 0 : return ops->psi;
3049 : 144432551 : case 4:
3050 : 144432551 : return ops->si;
3051 : 0 : case 5:
3052 : 0 : case 6:
3053 : 0 : case 7:
3054 : 0 : return ops->pdi;
3055 : 33066168 : case 8:
3056 : 33066168 : return ops->di;
3057 : 0 : case 9:
3058 : 0 : case 10:
3059 : 0 : case 11:
3060 : 0 : case 12:
3061 : 0 : case 13:
3062 : 0 : case 14:
3063 : 0 : case 15:
3064 : 0 : return ops->pti;
3065 : 22897 : case 16:
3066 : 22897 : return ops->ti;
3067 : : default:
3068 : : return NULL;
3069 : : }
3070 : : }
3071 : :
3072 : : /* Use directive OP to assemble an integer object X. Print OP at the
3073 : : start of the line, followed immediately by the value of X. */
3074 : :
3075 : : void
3076 : 13856736 : assemble_integer_with_op (const char *op, rtx x)
3077 : : {
3078 : 13856736 : fputs (op, asm_out_file);
3079 : 13856736 : output_addr_const (asm_out_file, x);
3080 : 13856736 : fputc ('\n', asm_out_file);
3081 : 13856736 : }
3082 : :
3083 : : /* The default implementation of the asm_out.integer target hook. */
3084 : :
3085 : : bool
3086 : 14154527 : default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
3087 : : unsigned int size ATTRIBUTE_UNUSED,
3088 : : int aligned_p ATTRIBUTE_UNUSED)
3089 : : {
3090 : 14154527 : const char *op = integer_asm_op (size, aligned_p);
3091 : : /* Avoid GAS bugs for large values. Specifically negative values whose
3092 : : absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */
3093 : 19152118 : if (size > UNITS_PER_WORD && size > POINTER_SIZE_UNITS)
3094 : : return false;
3095 : 13856736 : return op && (assemble_integer_with_op (op, x), true);
3096 : : }
3097 : :
3098 : : /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is
3099 : : the alignment of the integer in bits. Return 1 if we were able to output
3100 : : the constant, otherwise 0. We must be able to output the constant,
3101 : : if FORCE is nonzero. */
3102 : :
3103 : : bool
3104 : 14154527 : assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
3105 : : {
3106 : 14154527 : int aligned_p;
3107 : :
3108 : 14154527 : aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
3109 : :
3110 : : /* See if the target hook can handle this kind of object. */
3111 : 14154527 : if (targetm.asm_out.integer (x, size, aligned_p))
3112 : : return true;
3113 : :
3114 : : /* If the object is a multi-byte one, try splitting it up. Split
3115 : : it into words it if is multi-word, otherwise split it into bytes. */
3116 : 297791 : if (size > 1)
3117 : : {
3118 : 297791 : machine_mode omode, imode;
3119 : 297791 : unsigned int subalign;
3120 : 297791 : unsigned int subsize, i;
3121 : 297791 : enum mode_class mclass;
3122 : :
3123 : 573755 : subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
3124 : 297791 : subalign = MIN (align, subsize * BITS_PER_UNIT);
3125 : 297791 : if (GET_CODE (x) == CONST_FIXED)
3126 : 0 : mclass = GET_MODE_CLASS (GET_MODE (x));
3127 : : else
3128 : : mclass = MODE_INT;
3129 : :
3130 : 297791 : omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0).require ();
3131 : 297791 : imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0).require ();
3132 : :
3133 : 897061 : for (i = 0; i < size; i += subsize)
3134 : : {
3135 : 599270 : rtx partial = simplify_subreg (omode, x, imode, i);
3136 : 599270 : if (!partial || !assemble_integer (partial, subsize, subalign, 0))
3137 : : break;
3138 : : }
3139 : 297791 : if (i == size)
3140 : 14154527 : return true;
3141 : :
3142 : : /* If we've printed some of it, but not all of it, there's no going
3143 : : back now. */
3144 : 0 : gcc_assert (!i);
3145 : : }
3146 : :
3147 : 0 : gcc_assert (!force);
3148 : :
3149 : : return false;
3150 : : }
3151 : :
3152 : : /* Assemble the floating-point constant D into an object of size MODE. ALIGN
3153 : : is the alignment of the constant in bits. If REVERSE is true, D is output
3154 : : in reverse storage order. */
3155 : :
3156 : : void
3157 : 778716 : assemble_real (REAL_VALUE_TYPE d, scalar_float_mode mode, unsigned int align,
3158 : : bool reverse)
3159 : : {
3160 : 778716 : long data[4] = {0, 0, 0, 0};
3161 : 778716 : int bitsize, nelts, nunits, units_per;
3162 : 778716 : rtx elt;
3163 : :
3164 : : /* This is hairy. We have a quantity of known size. real_to_target
3165 : : will put it into an array of *host* longs, 32 bits per element
3166 : : (even if long is more than 32 bits). We need to determine the
3167 : : number of array elements that are occupied (nelts) and the number
3168 : : of *target* min-addressable units that will be occupied in the
3169 : : object file (nunits). We cannot assume that 32 divides the
3170 : : mode's bitsize (size * BITS_PER_UNIT) evenly.
3171 : :
3172 : : size * BITS_PER_UNIT is used here to make sure that padding bits
3173 : : (which might appear at either end of the value; real_to_target
3174 : : will include the padding bits in its output array) are included. */
3175 : :
3176 : 778716 : nunits = GET_MODE_SIZE (mode);
3177 : 778716 : bitsize = nunits * BITS_PER_UNIT;
3178 : 778716 : nelts = CEIL (bitsize, 32);
3179 : 778716 : units_per = 32 / BITS_PER_UNIT;
3180 : :
3181 : 778716 : real_to_target (data, &d, mode);
3182 : :
3183 : : /* Put out the first word with the specified alignment. */
3184 : 778716 : unsigned int chunk_nunits = MIN (nunits, units_per);
3185 : 778716 : if (reverse)
3186 : 72 : elt = flip_storage_order (SImode, gen_int_mode (data[nelts - 1], SImode));
3187 : : else
3188 : 778644 : elt = GEN_INT (sext_hwi (data[0], chunk_nunits * BITS_PER_UNIT));
3189 : 778716 : assemble_integer (elt, chunk_nunits, align, 1);
3190 : 778716 : nunits -= chunk_nunits;
3191 : :
3192 : : /* Subsequent words need only 32-bit alignment. */
3193 : 778716 : align = min_align (align, 32);
3194 : :
3195 : 1185647 : for (int i = 1; i < nelts; i++)
3196 : : {
3197 : 406931 : chunk_nunits = MIN (nunits, units_per);
3198 : 406931 : if (reverse)
3199 : 18 : elt = flip_storage_order (SImode,
3200 : 18 : gen_int_mode (data[nelts - 1 - i], SImode));
3201 : : else
3202 : 406913 : elt = GEN_INT (sext_hwi (data[i], chunk_nunits * BITS_PER_UNIT));
3203 : 406931 : assemble_integer (elt, chunk_nunits, align, 1);
3204 : 406931 : nunits -= chunk_nunits;
3205 : : }
3206 : 778716 : }
3207 : :
3208 : : /* Given an expression EXP with a constant value,
3209 : : reduce it to the sum of an assembler symbol and an integer.
3210 : : Store them both in the structure *VALUE.
3211 : : EXP must be reducible. */
3212 : :
3213 : : class addr_const {
3214 : : public:
3215 : : rtx base;
3216 : : poly_int64 offset;
3217 : : };
3218 : :
3219 : : static void
3220 : 27898 : decode_addr_const (tree exp, class addr_const *value)
3221 : : {
3222 : 27898 : tree target = TREE_OPERAND (exp, 0);
3223 : 27898 : poly_int64 offset = 0;
3224 : 28350 : rtx x;
3225 : :
3226 : 28802 : while (1)
3227 : : {
3228 : 28350 : poly_int64 bytepos;
3229 : 28350 : if (TREE_CODE (target) == COMPONENT_REF
3230 : 28350 : && poly_int_tree_p (byte_position (TREE_OPERAND (target, 1)),
3231 : : &bytepos))
3232 : : {
3233 : 438 : offset += bytepos;
3234 : 438 : target = TREE_OPERAND (target, 0);
3235 : : }
3236 : 27912 : else if (TREE_CODE (target) == ARRAY_REF
3237 : 27912 : || TREE_CODE (target) == ARRAY_RANGE_REF)
3238 : : {
3239 : : /* Truncate big offset. */
3240 : 14 : offset
3241 : 14 : += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target)))
3242 : 28 : * wi::to_poly_widest (TREE_OPERAND (target, 1)).force_shwi ());
3243 : 14 : target = TREE_OPERAND (target, 0);
3244 : : }
3245 : 27898 : else if (TREE_CODE (target) == MEM_REF
3246 : 27898 : && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
3247 : : {
3248 : 0 : offset += mem_ref_offset (target).force_shwi ();
3249 : 0 : target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
3250 : : }
3251 : 27898 : else if (INDIRECT_REF_P (target)
3252 : 0 : && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
3253 : 27898 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
3254 : : == ADDR_EXPR)
3255 : 0 : target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
3256 : : else
3257 : : break;
3258 : 452 : }
3259 : :
3260 : 27898 : switch (TREE_CODE (target))
3261 : : {
3262 : 27796 : case VAR_DECL:
3263 : 27796 : case FUNCTION_DECL:
3264 : 27796 : x = DECL_RTL (target);
3265 : : break;
3266 : :
3267 : 0 : case LABEL_DECL:
3268 : 0 : x = gen_rtx_MEM (FUNCTION_MODE,
3269 : 0 : gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
3270 : 0 : break;
3271 : :
3272 : 0 : case REAL_CST:
3273 : 0 : case FIXED_CST:
3274 : 0 : case STRING_CST:
3275 : 0 : case COMPLEX_CST:
3276 : 0 : case CONSTRUCTOR:
3277 : 0 : case INTEGER_CST:
3278 : 0 : x = lookup_constant_def (target);
3279 : : /* Should have been added by output_addressed_constants. */
3280 : 0 : gcc_assert (x);
3281 : : break;
3282 : :
3283 : 0 : case INDIRECT_REF:
3284 : : /* This deals with absolute addresses. */
3285 : 0 : offset += tree_to_shwi (TREE_OPERAND (target, 0));
3286 : 0 : x = gen_rtx_MEM (QImode,
3287 : 0 : gen_rtx_SYMBOL_REF (Pmode, "origin of addresses"));
3288 : 0 : break;
3289 : :
3290 : 102 : case COMPOUND_LITERAL_EXPR:
3291 : 102 : gcc_assert (COMPOUND_LITERAL_EXPR_DECL (target));
3292 : 102 : x = DECL_RTL (COMPOUND_LITERAL_EXPR_DECL (target));
3293 : : break;
3294 : :
3295 : 0 : default:
3296 : 0 : gcc_unreachable ();
3297 : : }
3298 : :
3299 : 27898 : gcc_assert (MEM_P (x));
3300 : 27898 : x = XEXP (x, 0);
3301 : :
3302 : 27898 : value->base = x;
3303 : 27898 : value->offset = offset;
3304 : 27898 : }
3305 : :
3306 : : static GTY(()) hash_table<tree_descriptor_hasher> *const_desc_htab;
3307 : :
3308 : : static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
3309 : :
3310 : : /* Constant pool accessor function. */
3311 : :
3312 : : hash_table<tree_descriptor_hasher> *
3313 : 2348 : constant_pool_htab (void)
3314 : : {
3315 : 2348 : return const_desc_htab;
3316 : : }
3317 : :
3318 : : /* Compute a hash code for a constant expression. */
3319 : :
3320 : : hashval_t
3321 : 9125091 : tree_descriptor_hasher::hash (constant_descriptor_tree *ptr)
3322 : : {
3323 : 9125091 : return ptr->hash;
3324 : : }
3325 : :
3326 : : static hashval_t
3327 : 5202156 : const_hash_1 (const tree exp)
3328 : : {
3329 : 5468550 : const char *p;
3330 : 5468550 : hashval_t hi;
3331 : 5468550 : int len, i;
3332 : 5468550 : enum tree_code code = TREE_CODE (exp);
3333 : :
3334 : : /* Either set P and LEN to the address and len of something to hash and
3335 : : exit the switch or return a value. */
3336 : :
3337 : 5468550 : switch (code)
3338 : : {
3339 : 661697 : case INTEGER_CST:
3340 : 661697 : p = (char *) &TREE_INT_CST_ELT (exp, 0);
3341 : 661697 : len = TREE_INT_CST_NUNITS (exp) * sizeof (HOST_WIDE_INT);
3342 : 661697 : break;
3343 : :
3344 : 45666 : case REAL_CST:
3345 : 45666 : return real_hash (TREE_REAL_CST_PTR (exp));
3346 : :
3347 : 0 : case FIXED_CST:
3348 : 0 : return fixed_hash (TREE_FIXED_CST_PTR (exp));
3349 : :
3350 : 4238352 : case STRING_CST:
3351 : 4238352 : p = TREE_STRING_POINTER (exp);
3352 : 4238352 : len = TREE_STRING_LENGTH (exp);
3353 : 4238352 : break;
3354 : :
3355 : 19692 : case COMPLEX_CST:
3356 : 19692 : return (const_hash_1 (TREE_REALPART (exp)) * 5
3357 : 19692 : + const_hash_1 (TREE_IMAGPART (exp)));
3358 : :
3359 : 0 : case VECTOR_CST:
3360 : 0 : {
3361 : 0 : hi = 7 + VECTOR_CST_NPATTERNS (exp);
3362 : 0 : hi = hi * 563 + VECTOR_CST_NELTS_PER_PATTERN (exp);
3363 : 0 : unsigned int count = vector_cst_encoded_nelts (exp);
3364 : 0 : for (unsigned int i = 0; i < count; ++i)
3365 : 0 : hi = hi * 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp, i));
3366 : : return hi;
3367 : : }
3368 : :
3369 : 106 : case RAW_DATA_CST:
3370 : 106 : p = RAW_DATA_POINTER (exp);
3371 : 106 : len = RAW_DATA_LENGTH (exp);
3372 : 106 : break;
3373 : :
3374 : 228442 : case CONSTRUCTOR:
3375 : 228442 : {
3376 : 228442 : unsigned HOST_WIDE_INT idx;
3377 : 228442 : tree value;
3378 : :
3379 : 228442 : hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
3380 : :
3381 : 1181901 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
3382 : 953459 : if (value)
3383 : 953459 : hi = hi * 603 + const_hash_1 (value);
3384 : :
3385 : : return hi;
3386 : : }
3387 : :
3388 : 122989 : case ADDR_EXPR:
3389 : 122989 : if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3390 : 95097 : return const_hash_1 (TREE_OPERAND (exp, 0));
3391 : :
3392 : : /* Fallthru. */
3393 : 27892 : case FDESC_EXPR:
3394 : 27892 : {
3395 : 27892 : class addr_const value;
3396 : :
3397 : 27892 : decode_addr_const (exp, &value);
3398 : 27892 : switch (GET_CODE (value.base))
3399 : : {
3400 : 27892 : case SYMBOL_REF:
3401 : : /* Don't hash the address of the SYMBOL_REF;
3402 : : only use the offset and the symbol name. */
3403 : 27892 : hi = value.offset.coeffs[0];
3404 : 27892 : p = XSTR (value.base, 0);
3405 : 955684 : for (i = 0; p[i] != 0; i++)
3406 : 927792 : hi = ((hi * 613) + (unsigned) (p[i]));
3407 : : break;
3408 : :
3409 : 0 : case LABEL_REF:
3410 : 0 : hi = (value.offset.coeffs[0]
3411 : 0 : + CODE_LABEL_NUMBER (label_ref_label (value.base)) * 13);
3412 : 0 : break;
3413 : :
3414 : 0 : default:
3415 : 0 : gcc_unreachable ();
3416 : : }
3417 : : }
3418 : 27892 : return hi;
3419 : :
3420 : 24 : case PLUS_EXPR:
3421 : 24 : case POINTER_PLUS_EXPR:
3422 : 24 : case MINUS_EXPR:
3423 : 24 : return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3424 : 24 : + const_hash_1 (TREE_OPERAND (exp, 1)));
3425 : :
3426 : 151581 : CASE_CONVERT:
3427 : 151581 : return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3428 : :
3429 : : default:
3430 : : /* A language specific constant. Just hash the code. */
3431 : : return code;
3432 : : }
3433 : :
3434 : : /* Compute hashing function. */
3435 : 4900155 : hi = len;
3436 : 313357540 : for (i = 0; i < len; i++)
3437 : 308457385 : hi = ((hi * 613) + (unsigned) (p[i]));
3438 : :
3439 : : return hi;
3440 : : }
3441 : :
3442 : : /* Wrapper of compare_constant, for the htab interface. */
3443 : : bool
3444 : 12595736 : tree_descriptor_hasher::equal (constant_descriptor_tree *c1,
3445 : : constant_descriptor_tree *c2)
3446 : : {
3447 : 12595736 : if (c1->hash != c2->hash)
3448 : : return false;
3449 : 2792546 : return compare_constant (c1->value, c2->value);
3450 : : }
3451 : :
3452 : : /* Compare t1 and t2, and return true only if they are known to result in
3453 : : the same bit pattern on output. */
3454 : :
3455 : : static bool
3456 : 3238089 : compare_constant (const tree t1, const tree t2)
3457 : : {
3458 : 3238089 : enum tree_code typecode;
3459 : :
3460 : 3238089 : if (t1 == NULL_TREE)
3461 : 20224 : return t2 == NULL_TREE;
3462 : 3217865 : if (t2 == NULL_TREE)
3463 : : return false;
3464 : :
3465 : 3217865 : if (TREE_CODE (t1) != TREE_CODE (t2))
3466 : : return false;
3467 : :
3468 : 3217840 : switch (TREE_CODE (t1))
3469 : : {
3470 : 407103 : case INTEGER_CST:
3471 : : /* Integer constants are the same only if the same width of type. */
3472 : 407103 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3473 : : return false;
3474 : 398552 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3475 : : return false;
3476 : 398480 : return tree_int_cst_equal (t1, t2);
3477 : :
3478 : 40669 : case REAL_CST:
3479 : : /* Real constants are the same only if the same width of type. In
3480 : : addition to the same width, we need to check whether the modes are the
3481 : : same. There might be two floating point modes that are the same size
3482 : : but have different representations, such as the PowerPC that has 2
3483 : : different 128-bit floating point types (IBM extended double and IEEE
3484 : : 128-bit floating point). */
3485 : 40669 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3486 : : return false;
3487 : 27740 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3488 : : return false;
3489 : 27740 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3490 : :
3491 : 0 : case FIXED_CST:
3492 : : /* Fixed constants are the same only if the same width of type. */
3493 : 0 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3494 : : return false;
3495 : :
3496 : 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3497 : :
3498 : 2714021 : case STRING_CST:
3499 : 2714021 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3500 : 5428042 : || int_size_in_bytes (TREE_TYPE (t1))
3501 : 2714021 : != int_size_in_bytes (TREE_TYPE (t2)))
3502 : 4 : return false;
3503 : :
3504 : 2714017 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3505 : 2714017 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3506 : 2714017 : TREE_STRING_LENGTH (t1)));
3507 : :
3508 : 25561 : case COMPLEX_CST:
3509 : 25561 : return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3510 : 40304 : && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3511 : :
3512 : 0 : case VECTOR_CST:
3513 : 0 : {
3514 : 0 : if (VECTOR_CST_NPATTERNS (t1)
3515 : 0 : != VECTOR_CST_NPATTERNS (t2))
3516 : : return false;
3517 : :
3518 : 0 : if (VECTOR_CST_NELTS_PER_PATTERN (t1)
3519 : 0 : != VECTOR_CST_NELTS_PER_PATTERN (t2))
3520 : : return false;
3521 : :
3522 : 0 : unsigned int count = vector_cst_encoded_nelts (t1);
3523 : 0 : for (unsigned int i = 0; i < count; ++i)
3524 : 0 : if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1, i),
3525 : 0 : VECTOR_CST_ENCODED_ELT (t2, i)))
3526 : : return false;
3527 : :
3528 : : return true;
3529 : : }
3530 : :
3531 : 44 : case RAW_DATA_CST:
3532 : 44 : return (RAW_DATA_LENGTH (t1) == RAW_DATA_LENGTH (t2)
3533 : 44 : && ! memcmp (RAW_DATA_POINTER (t1), RAW_DATA_POINTER (t2),
3534 : 44 : RAW_DATA_LENGTH (t1)));
3535 : :
3536 : 30439 : case CONSTRUCTOR:
3537 : 30439 : {
3538 : 30439 : vec<constructor_elt, va_gc> *v1, *v2;
3539 : 30439 : unsigned HOST_WIDE_INT idx;
3540 : :
3541 : 30439 : typecode = TREE_CODE (TREE_TYPE (t1));
3542 : 30439 : if (typecode != TREE_CODE (TREE_TYPE (t2)))
3543 : : return false;
3544 : :
3545 : 30439 : if (typecode == ARRAY_TYPE)
3546 : : {
3547 : 798 : HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3548 : : /* For arrays, check that mode, size and storage order match. */
3549 : 798 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3550 : 798 : || size_1 == -1
3551 : 798 : || size_1 != int_size_in_bytes (TREE_TYPE (t2))
3552 : 1596 : || TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t1))
3553 : 798 : != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t2)))
3554 : 0 : return false;
3555 : : }
3556 : : else
3557 : : {
3558 : : /* For record and union constructors, require exact type
3559 : : equality. */
3560 : 29641 : if (TREE_TYPE (t1) != TREE_TYPE (t2))
3561 : : return false;
3562 : : }
3563 : :
3564 : 30431 : v1 = CONSTRUCTOR_ELTS (t1);
3565 : 30431 : v2 = CONSTRUCTOR_ELTS (t2);
3566 : 91293 : if (vec_safe_length (v1) != vec_safe_length (v2))
3567 : : return false;
3568 : :
3569 : 279611 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
3570 : : {
3571 : 249186 : constructor_elt *c1 = &(*v1)[idx];
3572 : 249186 : constructor_elt *c2 = &(*v2)[idx];
3573 : :
3574 : : /* Check that each value is the same... */
3575 : 249186 : if (!compare_constant (c1->value, c2->value))
3576 : : return false;
3577 : : /* ... and that they apply to the same fields! */
3578 : 249180 : if (typecode == ARRAY_TYPE)
3579 : : {
3580 : 156053 : if (!compare_constant (c1->index, c2->index))
3581 : : return false;
3582 : : }
3583 : : else
3584 : : {
3585 : 93127 : if (c1->index != c2->index)
3586 : : return false;
3587 : : }
3588 : : }
3589 : :
3590 : : return true;
3591 : : }
3592 : :
3593 : 3 : case ADDR_EXPR:
3594 : 3 : case FDESC_EXPR:
3595 : 3 : {
3596 : 3 : class addr_const value1, value2;
3597 : 3 : enum rtx_code code;
3598 : 3 : bool ret;
3599 : :
3600 : 3 : decode_addr_const (t1, &value1);
3601 : 3 : decode_addr_const (t2, &value2);
3602 : :
3603 : 3 : if (maybe_ne (value1.offset, value2.offset))
3604 : : return false;
3605 : :
3606 : 3 : code = GET_CODE (value1.base);
3607 : 3 : if (code != GET_CODE (value2.base))
3608 : : return false;
3609 : :
3610 : 3 : switch (code)
3611 : : {
3612 : 3 : case SYMBOL_REF:
3613 : 3 : ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3614 : 3 : break;
3615 : :
3616 : 0 : case LABEL_REF:
3617 : 0 : ret = (CODE_LABEL_NUMBER (label_ref_label (value1.base))
3618 : 0 : == CODE_LABEL_NUMBER (label_ref_label (value2.base)));
3619 : 0 : break;
3620 : :
3621 : 0 : default:
3622 : 0 : gcc_unreachable ();
3623 : : }
3624 : : return ret;
3625 : : }
3626 : :
3627 : 0 : case PLUS_EXPR:
3628 : 0 : case POINTER_PLUS_EXPR:
3629 : 0 : case MINUS_EXPR:
3630 : 0 : case RANGE_EXPR:
3631 : 0 : return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3632 : 0 : && compare_constant (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3633 : :
3634 : 0 : CASE_CONVERT:
3635 : 0 : case VIEW_CONVERT_EXPR:
3636 : 0 : return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3637 : :
3638 : : default:
3639 : : return false;
3640 : : }
3641 : : }
3642 : :
3643 : : /* Return the section into which constant EXP should be placed. */
3644 : :
3645 : : static section *
3646 : 1250302 : get_constant_section (tree exp, unsigned int align)
3647 : : {
3648 : 1250302 : return targetm.asm_out.select_section (exp,
3649 : : compute_reloc_for_constant (exp),
3650 : 1250302 : align);
3651 : : }
3652 : :
3653 : : /* Return the size of constant EXP in bytes. */
3654 : :
3655 : : static HOST_WIDE_INT
3656 : 1251834 : get_constant_size (tree exp)
3657 : : {
3658 : 1251834 : HOST_WIDE_INT size;
3659 : :
3660 : 1251834 : size = int_size_in_bytes (TREE_TYPE (exp));
3661 : 1251834 : gcc_checking_assert (size >= 0);
3662 : 1251834 : gcc_checking_assert (TREE_CODE (exp) != STRING_CST
3663 : : || size >= TREE_STRING_LENGTH (exp));
3664 : 1251834 : return size;
3665 : : }
3666 : :
3667 : : /* Subroutine of output_constant_def:
3668 : : No constant equal to EXP is known to have been output.
3669 : : Make a constant descriptor to enter EXP in the hash table.
3670 : : Assign the label number and construct RTL to refer to the
3671 : : constant's location in memory.
3672 : : Caller is responsible for updating the hash table. */
3673 : :
3674 : : static struct constant_descriptor_tree *
3675 : 1259023 : build_constant_desc (tree exp)
3676 : : {
3677 : 1259023 : struct constant_descriptor_tree *desc;
3678 : 1259023 : rtx symbol, rtl;
3679 : 1259023 : char label[256];
3680 : 1259023 : int labelno;
3681 : 1259023 : tree decl;
3682 : :
3683 : 1259023 : desc = ggc_alloc<constant_descriptor_tree> ();
3684 : 1259023 : desc->value = exp;
3685 : :
3686 : : /* Create a string containing the label name, in LABEL. */
3687 : 1259023 : labelno = const_labelno++;
3688 : 1259023 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3689 : :
3690 : : /* Construct the VAR_DECL associated with the constant. */
3691 : 1259023 : decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3692 : 1259023 : TREE_TYPE (exp));
3693 : 1259023 : DECL_ARTIFICIAL (decl) = 1;
3694 : 1259023 : DECL_IGNORED_P (decl) = 1;
3695 : 1259023 : TREE_READONLY (decl) = 1;
3696 : 1259023 : TREE_STATIC (decl) = 1;
3697 : 1259023 : TREE_ADDRESSABLE (decl) = 1;
3698 : : /* We don't set the RTL yet as this would cause varpool to assume that the
3699 : : variable is referenced. Moreover, it would just be dropped in LTO mode.
3700 : : Instead we set the flag that will be recognized in make_decl_rtl. */
3701 : 1259023 : DECL_IN_CONSTANT_POOL (decl) = 1;
3702 : 1259023 : DECL_INITIAL (decl) = desc->value;
3703 : : /* ??? targetm.constant_alignment hasn't been updated for vector types on
3704 : : most architectures so use DATA_ALIGNMENT as well, except for strings. */
3705 : 1259023 : if (TREE_CODE (exp) == STRING_CST)
3706 : 1227354 : SET_DECL_ALIGN (decl, targetm.constant_alignment (exp, DECL_ALIGN (decl)));
3707 : : else
3708 : : {
3709 : 31669 : align_variable (decl, 0);
3710 : 31669 : if (DECL_ALIGN (decl) < GET_MODE_ALIGNMENT (DECL_MODE (decl))
3711 : 31669 : && ((optab_handler (movmisalign_optab, DECL_MODE (decl))
3712 : : != CODE_FOR_nothing)
3713 : 0 : || targetm.slow_unaligned_access (DECL_MODE (decl),
3714 : 0 : DECL_ALIGN (decl))))
3715 : 0 : SET_DECL_ALIGN (decl, GET_MODE_ALIGNMENT (DECL_MODE (decl)));
3716 : : }
3717 : :
3718 : : /* Now construct the SYMBOL_REF and the MEM. */
3719 : 1259023 : if (use_object_blocks_p ())
3720 : : {
3721 : 0 : int align = (TREE_CODE (decl) == CONST_DECL
3722 : 0 : || (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
3723 : 0 : ? DECL_ALIGN (decl)
3724 : 0 : : symtab_node::get (decl)->definition_alignment ());
3725 : 0 : section *sect = get_constant_section (exp, align);
3726 : 0 : symbol = create_block_symbol (ggc_strdup (label),
3727 : : get_block_for_section (sect), -1);
3728 : : }
3729 : : else
3730 : 1259023 : symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3731 : 1259023 : SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3732 : 1259023 : SET_SYMBOL_REF_DECL (symbol, decl);
3733 : 1259023 : TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3734 : :
3735 : 1259023 : rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3736 : 1259023 : set_mem_alias_set (rtl, 0);
3737 : :
3738 : : /* Putting EXP into the literal pool might have imposed a different
3739 : : alignment which should be visible in the RTX as well. */
3740 : 1259023 : set_mem_align (rtl, DECL_ALIGN (decl));
3741 : :
3742 : : /* We cannot share RTX'es in pool entries.
3743 : : Mark this piece of RTL as required for unsharing. */
3744 : 1259023 : RTX_FLAG (rtl, used) = 1;
3745 : :
3746 : : /* Set flags or add text to the name to record information, such as
3747 : : that it is a local symbol. If the name is changed, the macro
3748 : : ASM_OUTPUT_LABELREF will have to know how to strip this
3749 : : information. This call might invalidate our local variable
3750 : : SYMBOL; we can't use it afterward. */
3751 : 1259023 : targetm.encode_section_info (exp, rtl, true);
3752 : :
3753 : 1259023 : desc->rtl = rtl;
3754 : :
3755 : 1259023 : return desc;
3756 : : }
3757 : :
3758 : : /* Subroutine of output_constant_def and tree_output_constant_def:
3759 : : Add a constant to the hash table that tracks which constants
3760 : : already have labels. */
3761 : :
3762 : : static constant_descriptor_tree *
3763 : 3793714 : add_constant_to_table (tree exp, int defer)
3764 : : {
3765 : : /* The hash table methods may call output_constant_def for addressed
3766 : : constants, so handle them first. */
3767 : 3793714 : output_addressed_constants (exp, defer);
3768 : :
3769 : : /* Sanity check to catch recursive insertion. */
3770 : 3793714 : static bool inserting;
3771 : 3793714 : gcc_assert (!inserting);
3772 : 3793714 : inserting = true;
3773 : :
3774 : : /* Look up EXP in the table of constant descriptors. If we didn't
3775 : : find it, create a new one. */
3776 : 3793714 : struct constant_descriptor_tree key;
3777 : 3793714 : key.value = exp;
3778 : 3793714 : key.hash = const_hash_1 (exp);
3779 : 3793714 : constant_descriptor_tree **loc
3780 : 3793714 : = const_desc_htab->find_slot_with_hash (&key, key.hash, INSERT);
3781 : :
3782 : 3793714 : inserting = false;
3783 : :
3784 : 3793714 : struct constant_descriptor_tree *desc = *loc;
3785 : 3793714 : if (!desc)
3786 : : {
3787 : 1259023 : desc = build_constant_desc (exp);
3788 : 1259023 : desc->hash = key.hash;
3789 : 1259023 : *loc = desc;
3790 : : }
3791 : :
3792 : 3793714 : return desc;
3793 : : }
3794 : :
3795 : : /* Return an rtx representing a reference to constant data in memory
3796 : : for the constant expression EXP.
3797 : :
3798 : : If assembler code for such a constant has already been output,
3799 : : return an rtx to refer to it.
3800 : : Otherwise, output such a constant in memory
3801 : : and generate an rtx for it.
3802 : :
3803 : : If DEFER is nonzero, this constant can be deferred and output only
3804 : : if referenced in the function after all optimizations.
3805 : :
3806 : : `const_desc_table' records which constants already have label strings. */
3807 : :
3808 : : rtx
3809 : 3784489 : output_constant_def (tree exp, int defer)
3810 : : {
3811 : 3784489 : struct constant_descriptor_tree *desc = add_constant_to_table (exp, defer);
3812 : 3784489 : maybe_output_constant_def_contents (desc, defer);
3813 : 3784489 : return desc->rtl;
3814 : : }
3815 : :
3816 : : /* Subroutine of output_constant_def: Decide whether or not we need to
3817 : : output the constant DESC now, and if so, do it. */
3818 : : static void
3819 : 3784489 : maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3820 : : int defer)
3821 : : {
3822 : 3784489 : rtx symbol = XEXP (desc->rtl, 0);
3823 : 3784489 : tree exp = desc->value;
3824 : :
3825 : 3784489 : if (flag_syntax_only)
3826 : : return;
3827 : :
3828 : 3784489 : if (TREE_ASM_WRITTEN (exp))
3829 : : /* Already output; don't do it again. */
3830 : : return;
3831 : :
3832 : : /* We can always defer constants as long as the context allows
3833 : : doing so. */
3834 : 1413541 : if (defer)
3835 : : {
3836 : : /* Increment n_deferred_constants if it exists. It needs to be at
3837 : : least as large as the number of constants actually referred to
3838 : : by the function. If it's too small we'll stop looking too early
3839 : : and fail to emit constants; if it's too large we'll only look
3840 : : through the entire function when we could have stopped earlier. */
3841 : 171274 : if (cfun)
3842 : 107565 : n_deferred_constants++;
3843 : 171274 : return;
3844 : : }
3845 : :
3846 : 1242267 : output_constant_def_contents (symbol);
3847 : : }
3848 : :
3849 : : /* Subroutine of output_constant_def_contents. Output the definition
3850 : : of constant EXP, which is pointed to by label LABEL. ALIGN is the
3851 : : constant's alignment in bits. */
3852 : :
3853 : : static void
3854 : 1250302 : assemble_constant_contents (tree exp, const char *label, unsigned int align,
3855 : : bool merge_strings)
3856 : : {
3857 : 1250302 : HOST_WIDE_INT size;
3858 : :
3859 : 1250302 : size = get_constant_size (exp);
3860 : :
3861 : : /* Do any machine/system dependent processing of the constant. */
3862 : 1250302 : targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3863 : :
3864 : : /* Output the value of EXP. */
3865 : 1250302 : output_constant (exp, size, align, false, merge_strings);
3866 : :
3867 : 1250302 : targetm.asm_out.decl_end ();
3868 : 1250302 : }
3869 : :
3870 : : /* We must output the constant data referred to by SYMBOL; do so. */
3871 : :
3872 : : static void
3873 : 1250302 : output_constant_def_contents (rtx symbol)
3874 : : {
3875 : 1250302 : tree decl = SYMBOL_REF_DECL (symbol);
3876 : 1250302 : tree exp = DECL_INITIAL (decl);
3877 : 1250302 : bool asan_protected = false;
3878 : :
3879 : : /* Make sure any other constants whose addresses appear in EXP
3880 : : are assigned label numbers. */
3881 : 1250302 : output_addressed_constants (exp, 0);
3882 : :
3883 : : /* We are no longer deferring this constant. */
3884 : 1250302 : TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3885 : :
3886 : 1250302 : if ((flag_sanitize & SANITIZE_ADDRESS)
3887 : 2945 : && TREE_CODE (exp) == STRING_CST
3888 : 1253226 : && asan_protect_global (exp))
3889 : : {
3890 : 1532 : asan_protected = true;
3891 : 1532 : SET_DECL_ALIGN (decl, MAX (DECL_ALIGN (decl),
3892 : : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT));
3893 : : }
3894 : :
3895 : : /* If the constant is part of an object block, make sure that the
3896 : : decl has been positioned within its block, but do not write out
3897 : : its definition yet. output_object_blocks will do that later. */
3898 : 1250302 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3899 : 0 : place_block_symbol (symbol);
3900 : : else
3901 : : {
3902 : 1250302 : int align = (TREE_CODE (decl) == CONST_DECL
3903 : 1250302 : || (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
3904 : 2500604 : ? DECL_ALIGN (decl)
3905 : 0 : : symtab_node::get (decl)->definition_alignment ());
3906 : 1250302 : section *sect = get_constant_section (exp, align);
3907 : 1250302 : switch_to_section (sect);
3908 : 1250302 : if (align > BITS_PER_UNIT)
3909 : 389328 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3910 : 1250302 : assemble_constant_contents (exp, XSTR (symbol, 0), align,
3911 : : (sect->common.flags & SECTION_MERGE)
3912 : 1250302 : && (sect->common.flags & SECTION_STRINGS));
3913 : 1250302 : if (asan_protected)
3914 : : {
3915 : 1532 : HOST_WIDE_INT size = get_constant_size (exp);
3916 : 3033 : assemble_zeros (asan_red_zone_size (size));
3917 : : }
3918 : : }
3919 : 1250302 : }
3920 : :
3921 : : /* Look up EXP in the table of constant descriptors. Return the rtl
3922 : : if it has been emitted, else null. */
3923 : :
3924 : : rtx
3925 : 435267 : lookup_constant_def (tree exp)
3926 : : {
3927 : 435267 : struct constant_descriptor_tree key;
3928 : :
3929 : 435267 : key.value = exp;
3930 : 435267 : key.hash = const_hash_1 (exp);
3931 : 435267 : constant_descriptor_tree *desc
3932 : 435267 : = const_desc_htab->find_with_hash (&key, key.hash);
3933 : :
3934 : 435267 : return (desc ? desc->rtl : NULL_RTX);
3935 : : }
3936 : :
3937 : : /* Return a tree representing a reference to constant data in memory
3938 : : for the constant expression EXP.
3939 : :
3940 : : This is the counterpart of output_constant_def at the Tree level. */
3941 : :
3942 : : tree
3943 : 9225 : tree_output_constant_def (tree exp)
3944 : : {
3945 : 9225 : struct constant_descriptor_tree *desc = add_constant_to_table (exp, 1);
3946 : 9225 : tree decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3947 : 9225 : varpool_node::finalize_decl (decl);
3948 : 9225 : return decl;
3949 : : }
3950 : :
3951 : 3950368 : class GTY((chain_next ("%h.next"), for_user)) constant_descriptor_rtx {
3952 : : public:
3953 : : class constant_descriptor_rtx *next;
3954 : : rtx mem;
3955 : : rtx sym;
3956 : : rtx constant;
3957 : : HOST_WIDE_INT offset;
3958 : : hashval_t hash;
3959 : : fixed_size_mode mode;
3960 : : unsigned int align;
3961 : : int labelno;
3962 : : int mark;
3963 : : };
3964 : :
3965 : : struct const_rtx_desc_hasher : ggc_ptr_hash<constant_descriptor_rtx>
3966 : : {
3967 : : static hashval_t hash (constant_descriptor_rtx *);
3968 : : static bool equal (constant_descriptor_rtx *, constant_descriptor_rtx *);
3969 : : };
3970 : :
3971 : : /* Used in the hash tables to avoid outputting the same constant
3972 : : twice. Unlike 'struct constant_descriptor_tree', RTX constants
3973 : : are output once per function, not once per file. */
3974 : : /* ??? Only a few targets need per-function constant pools. Most
3975 : : can use one per-file pool. Should add a targetm bit to tell the
3976 : : difference. */
3977 : :
3978 : : struct GTY(()) rtx_constant_pool {
3979 : : /* Pointers to first and last constant in pool, as ordered by offset. */
3980 : : class constant_descriptor_rtx *first;
3981 : : class constant_descriptor_rtx *last;
3982 : :
3983 : : /* Hash facility for making memory-constants from constant rtl-expressions.
3984 : : It is used on RISC machines where immediate integer arguments and
3985 : : constant addresses are restricted so that such constants must be stored
3986 : : in memory. */
3987 : : hash_table<const_rtx_desc_hasher> *const_rtx_htab;
3988 : :
3989 : : /* Current offset in constant pool (does not include any
3990 : : machine-specific header). */
3991 : : HOST_WIDE_INT offset;
3992 : : };
3993 : :
3994 : : /* Hash and compare functions for const_rtx_htab. */
3995 : :
3996 : : hashval_t
3997 : 15544585 : const_rtx_desc_hasher::hash (constant_descriptor_rtx *desc)
3998 : : {
3999 : 15544585 : return desc->hash;
4000 : : }
4001 : :
4002 : : bool
4003 : 19549292 : const_rtx_desc_hasher::equal (constant_descriptor_rtx *x,
4004 : : constant_descriptor_rtx *y)
4005 : : {
4006 : 19549292 : if (x->mode != y->mode)
4007 : : return false;
4008 : 11030588 : return rtx_equal_p (x->constant, y->constant);
4009 : : }
4010 : :
4011 : : /* Hash one component of a constant. */
4012 : :
4013 : : static hashval_t
4014 : 12804464 : const_rtx_hash_1 (const_rtx x)
4015 : : {
4016 : 12804464 : unsigned HOST_WIDE_INT hwi;
4017 : 12804464 : machine_mode mode;
4018 : 12804464 : enum rtx_code code;
4019 : 12804464 : hashval_t h;
4020 : 12804464 : int i;
4021 : :
4022 : 12804464 : code = GET_CODE (x);
4023 : 12804464 : mode = GET_MODE (x);
4024 : 12804464 : h = (hashval_t) code * 1048573 + mode;
4025 : :
4026 : 12804464 : switch (code)
4027 : : {
4028 : 7668802 : case CONST_INT:
4029 : 7668802 : hwi = INTVAL (x);
4030 : :
4031 : 7804748 : fold_hwi:
4032 : 7804748 : {
4033 : 7804748 : int shift = sizeof (hashval_t) * CHAR_BIT;
4034 : 7804748 : const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
4035 : :
4036 : 7804748 : h ^= (hashval_t) hwi;
4037 : 15609496 : for (i = 1; i < n; ++i)
4038 : : {
4039 : 7804748 : hwi >>= shift;
4040 : 7804748 : h ^= (hashval_t) hwi;
4041 : : }
4042 : : }
4043 : : break;
4044 : :
4045 : : case CONST_WIDE_INT:
4046 : : hwi = 0;
4047 : : {
4048 : 417366 : for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
4049 : 281420 : hwi ^= CONST_WIDE_INT_ELT (x, i);
4050 : 135946 : goto fold_hwi;
4051 : : }
4052 : :
4053 : 2831983 : case CONST_DOUBLE:
4054 : 2831983 : if (TARGET_SUPPORTS_WIDE_INT == 0 && mode == VOIDmode)
4055 : : {
4056 : : hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
4057 : : goto fold_hwi;
4058 : : }
4059 : : else
4060 : 2831983 : h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
4061 : 2831983 : break;
4062 : :
4063 : 0 : case CONST_FIXED:
4064 : 0 : h ^= fixed_hash (CONST_FIXED_VALUE (x));
4065 : 0 : break;
4066 : :
4067 : 106839 : case SYMBOL_REF:
4068 : 106839 : h ^= htab_hash_string (XSTR (x, 0));
4069 : 106839 : break;
4070 : :
4071 : 29 : case LABEL_REF:
4072 : 29 : h = h * 251 + CODE_LABEL_NUMBER (label_ref_label (x));
4073 : 29 : break;
4074 : :
4075 : 0 : case UNSPEC:
4076 : 0 : case UNSPEC_VOLATILE:
4077 : 0 : h = h * 251 + XINT (x, 1);
4078 : 0 : break;
4079 : :
4080 : : default:
4081 : : break;
4082 : : }
4083 : :
4084 : 12804464 : return h;
4085 : : }
4086 : :
4087 : : /* Compute a hash value for X, which should be a constant. */
4088 : :
4089 : : static hashval_t
4090 : 3929601 : const_rtx_hash (rtx x)
4091 : : {
4092 : 3929601 : hashval_t h = 0;
4093 : 3929601 : subrtx_iterator::array_type array;
4094 : 16734065 : FOR_EACH_SUBRTX (iter, array, x, ALL)
4095 : 12804464 : h = h * 509 + const_rtx_hash_1 (*iter);
4096 : 3929601 : return h;
4097 : 3929601 : }
4098 : :
4099 : :
4100 : : /* Create and return a new rtx constant pool. */
4101 : :
4102 : : static struct rtx_constant_pool *
4103 : 1916978 : create_constant_pool (void)
4104 : : {
4105 : 1916978 : struct rtx_constant_pool *pool;
4106 : :
4107 : 1916978 : pool = ggc_alloc<rtx_constant_pool> ();
4108 : 1916978 : pool->const_rtx_htab = hash_table<const_rtx_desc_hasher>::create_ggc (31);
4109 : 1916978 : pool->first = NULL;
4110 : 1916978 : pool->last = NULL;
4111 : 1916978 : pool->offset = 0;
4112 : 1916978 : return pool;
4113 : : }
4114 : :
4115 : : /* Initialize constant pool hashing for a new function. */
4116 : :
4117 : : void
4118 : 1642466 : init_varasm_status (void)
4119 : : {
4120 : 1642466 : crtl->varasm.pool = create_constant_pool ();
4121 : 1642466 : crtl->varasm.deferred_constants = 0;
4122 : 1642466 : }
4123 : :
4124 : : /* Given a MINUS expression, simplify it if both sides
4125 : : include the same symbol. */
4126 : :
4127 : : rtx
4128 : 4410406 : simplify_subtraction (rtx x)
4129 : : {
4130 : 4410406 : rtx r = simplify_rtx (x);
4131 : 4410406 : return r ? r : x;
4132 : : }
4133 : :
4134 : : /* Given a constant rtx X, make (or find) a memory constant for its value
4135 : : and return a MEM rtx to refer to it in memory. IN_MODE is the mode
4136 : : of X. */
4137 : :
4138 : : rtx
4139 : 3950368 : force_const_mem (machine_mode in_mode, rtx x)
4140 : : {
4141 : 3950368 : class constant_descriptor_rtx *desc, tmp;
4142 : 3950368 : struct rtx_constant_pool *pool;
4143 : 3950368 : char label[256];
4144 : 3950368 : rtx def, symbol;
4145 : 3950368 : hashval_t hash;
4146 : 3950368 : unsigned int align;
4147 : 3950368 : constant_descriptor_rtx **slot;
4148 : 3950368 : fixed_size_mode mode;
4149 : :
4150 : : /* We can't force variable-sized objects to memory. */
4151 : 3950368 : if (!is_a <fixed_size_mode> (in_mode, &mode))
4152 : : return NULL_RTX;
4153 : :
4154 : : /* If we're not allowed to drop X into the constant pool, don't. */
4155 : 3950368 : if (targetm.cannot_force_const_mem (mode, x))
4156 : : return NULL_RTX;
4157 : :
4158 : : /* Record that this function has used a constant pool entry. */
4159 : 3929601 : crtl->uses_const_pool = 1;
4160 : :
4161 : : /* Decide which pool to use. */
4162 : 3929601 : pool = (targetm.use_blocks_for_constant_p (mode, x)
4163 : 3929601 : ? shared_constant_pool
4164 : : : crtl->varasm.pool);
4165 : :
4166 : : /* Lookup the value in the hashtable. */
4167 : 3929601 : tmp.constant = x;
4168 : 3929601 : tmp.mode = mode;
4169 : 3929601 : hash = const_rtx_hash (x);
4170 : 3929601 : slot = pool->const_rtx_htab->find_slot_with_hash (&tmp, hash, INSERT);
4171 : 3929601 : desc = *slot;
4172 : :
4173 : : /* If the constant was already present, return its memory. */
4174 : 3929601 : if (desc)
4175 : 3582148 : return copy_rtx (desc->mem);
4176 : :
4177 : : /* Otherwise, create a new descriptor. */
4178 : 347453 : desc = ggc_alloc<constant_descriptor_rtx> ();
4179 : 347453 : *slot = desc;
4180 : :
4181 : : /* Align the location counter as required by EXP's data type. */
4182 : 347453 : machine_mode align_mode = (mode == VOIDmode ? word_mode : mode);
4183 : 347453 : align = targetm.static_rtx_alignment (align_mode);
4184 : :
4185 : 347453 : pool->offset += (align / BITS_PER_UNIT) - 1;
4186 : 347453 : pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
4187 : :
4188 : 347453 : desc->next = NULL;
4189 : 347453 : desc->constant = copy_rtx (tmp.constant);
4190 : 347453 : desc->offset = pool->offset;
4191 : 347453 : desc->hash = hash;
4192 : 347453 : desc->mode = mode;
4193 : 347453 : desc->align = align;
4194 : 347453 : desc->labelno = const_labelno;
4195 : 347453 : desc->mark = 0;
4196 : :
4197 : 347453 : pool->offset += GET_MODE_SIZE (mode);
4198 : 347453 : if (pool->last)
4199 : 304104 : pool->last->next = desc;
4200 : : else
4201 : 43349 : pool->first = pool->last = desc;
4202 : 347453 : pool->last = desc;
4203 : :
4204 : : /* Create a string containing the label name, in LABEL. */
4205 : 347453 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4206 : 347453 : ++const_labelno;
4207 : :
4208 : : /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
4209 : : the constants pool. */
4210 : 347453 : if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
4211 : : {
4212 : 0 : section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
4213 : 0 : symbol = create_block_symbol (ggc_strdup (label),
4214 : : get_block_for_section (sect), -1);
4215 : : }
4216 : : else
4217 : 347453 : symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
4218 : 347453 : desc->sym = symbol;
4219 : 347453 : SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
4220 : 347453 : CONSTANT_POOL_ADDRESS_P (symbol) = 1;
4221 : 347453 : SET_SYMBOL_REF_CONSTANT (symbol, desc);
4222 : :
4223 : : /* Construct the MEM. */
4224 : 347453 : desc->mem = def = gen_const_mem (mode, symbol);
4225 : 347453 : set_mem_align (def, align);
4226 : :
4227 : : /* If we're dropping a label to the constant pool, make sure we
4228 : : don't delete it. */
4229 : 347453 : if (GET_CODE (x) == LABEL_REF)
4230 : 29 : LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
4231 : :
4232 : 347453 : return copy_rtx (def);
4233 : : }
4234 : :
4235 : : /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
4236 : :
4237 : : rtx
4238 : 11601462 : get_pool_constant (const_rtx addr)
4239 : : {
4240 : 11601462 : return SYMBOL_REF_CONSTANT (addr)->constant;
4241 : : }
4242 : :
4243 : : /* Given a constant pool SYMBOL_REF, return the corresponding constant
4244 : : and whether it has been output or not. */
4245 : :
4246 : : rtx
4247 : 0 : get_pool_constant_mark (rtx addr, bool *pmarked)
4248 : : {
4249 : 0 : class constant_descriptor_rtx *desc;
4250 : :
4251 : 0 : desc = SYMBOL_REF_CONSTANT (addr);
4252 : 0 : *pmarked = (desc->mark != 0);
4253 : 0 : return desc->constant;
4254 : : }
4255 : :
4256 : : /* Similar, return the mode. */
4257 : :
4258 : : fixed_size_mode
4259 : 5244572 : get_pool_mode (const_rtx addr)
4260 : : {
4261 : 5244572 : return SYMBOL_REF_CONSTANT (addr)->mode;
4262 : : }
4263 : :
4264 : : /* Return TRUE if and only if the constant pool has no entries. Note
4265 : : that even entries we might end up choosing not to emit are counted
4266 : : here, so there is the potential for missed optimizations. */
4267 : :
4268 : : bool
4269 : 0 : constant_pool_empty_p (void)
4270 : : {
4271 : 0 : return crtl->varasm.pool->first == NULL;
4272 : : }
4273 : :
4274 : : /* Worker function for output_constant_pool_1. Emit assembly for X
4275 : : in MODE with known alignment ALIGN. */
4276 : :
4277 : : static void
4278 : 684634 : output_constant_pool_2 (fixed_size_mode mode, rtx x, unsigned int align)
4279 : : {
4280 : 684634 : switch (GET_MODE_CLASS (mode))
4281 : : {
4282 : 198324 : case MODE_FLOAT:
4283 : 198324 : case MODE_DECIMAL_FLOAT:
4284 : 198324 : {
4285 : 198324 : gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x));
4286 : 198324 : assemble_real (*CONST_DOUBLE_REAL_VALUE (x),
4287 : : as_a <scalar_float_mode> (mode), align, false);
4288 : 198324 : break;
4289 : : }
4290 : :
4291 : 384653 : case MODE_INT:
4292 : 384653 : case MODE_PARTIAL_INT:
4293 : 384653 : case MODE_FRACT:
4294 : 384653 : case MODE_UFRACT:
4295 : 384653 : case MODE_ACCUM:
4296 : 384653 : case MODE_UACCUM:
4297 : 384653 : assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
4298 : 384653 : break;
4299 : :
4300 : 0 : case MODE_VECTOR_BOOL:
4301 : 0 : {
4302 : 0 : gcc_assert (GET_CODE (x) == CONST_VECTOR);
4303 : :
4304 : 0 : auto_vec<target_unit, 128> buffer;
4305 : 0 : buffer.reserve (GET_MODE_SIZE (mode));
4306 : :
4307 : 0 : bool ok = native_encode_rtx (mode, x, buffer, 0, GET_MODE_SIZE (mode));
4308 : 0 : gcc_assert (ok);
4309 : :
4310 : 0 : for (unsigned i = 0; i < GET_MODE_SIZE (mode); i++)
4311 : : {
4312 : 0 : unsigned HOST_WIDE_INT value = buffer[i];
4313 : 0 : output_constant_pool_2 (byte_mode, gen_int_mode (value, byte_mode),
4314 : : i == 0 ? align : 1);
4315 : : }
4316 : 0 : break;
4317 : 0 : }
4318 : 101657 : case MODE_VECTOR_FLOAT:
4319 : 101657 : case MODE_VECTOR_INT:
4320 : 101657 : case MODE_VECTOR_FRACT:
4321 : 101657 : case MODE_VECTOR_UFRACT:
4322 : 101657 : case MODE_VECTOR_ACCUM:
4323 : 101657 : case MODE_VECTOR_UACCUM:
4324 : 101657 : {
4325 : 101657 : int i, units;
4326 : 101657 : scalar_mode submode = GET_MODE_INNER (mode);
4327 : 304971 : unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
4328 : :
4329 : 101657 : gcc_assert (GET_CODE (x) == CONST_VECTOR);
4330 : 101657 : units = GET_MODE_NUNITS (mode);
4331 : :
4332 : 527017 : for (i = 0; i < units; i++)
4333 : : {
4334 : 425360 : rtx elt = CONST_VECTOR_ELT (x, i);
4335 : 527017 : output_constant_pool_2 (submode, elt, i ? subalign : align);
4336 : : }
4337 : : }
4338 : : break;
4339 : :
4340 : 0 : default:
4341 : 0 : gcc_unreachable ();
4342 : : }
4343 : 684634 : }
4344 : :
4345 : : /* Worker function for output_constant_pool. Emit constant DESC,
4346 : : giving it ALIGN bits of alignment. */
4347 : :
4348 : : static void
4349 : 259274 : output_constant_pool_1 (class constant_descriptor_rtx *desc,
4350 : : unsigned int align)
4351 : : {
4352 : 259274 : rtx x, tmp;
4353 : :
4354 : 259274 : x = desc->constant;
4355 : :
4356 : : /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4357 : : whose CODE_LABEL has been deleted. This can occur if a jump table
4358 : : is eliminated by optimization. If so, write a constant of zero
4359 : : instead. Note that this can also happen by turning the
4360 : : CODE_LABEL into a NOTE. */
4361 : : /* ??? This seems completely and utterly wrong. Certainly it's
4362 : : not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4363 : : functioning even with rtx_insn::deleted and friends. */
4364 : :
4365 : 259274 : tmp = x;
4366 : 259274 : switch (GET_CODE (tmp))
4367 : : {
4368 : 3614 : case CONST:
4369 : 3614 : if (GET_CODE (XEXP (tmp, 0)) != PLUS
4370 : 3614 : || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
4371 : : break;
4372 : : tmp = XEXP (XEXP (tmp, 0), 0);
4373 : : /* FALLTHRU */
4374 : :
4375 : 29 : case LABEL_REF:
4376 : 29 : {
4377 : 29 : rtx_insn *insn = label_ref_label (tmp);
4378 : 29 : gcc_assert (!insn->deleted ());
4379 : 29 : gcc_assert (!NOTE_P (insn)
4380 : : || NOTE_KIND (insn) != NOTE_INSN_DELETED);
4381 : : break;
4382 : : }
4383 : :
4384 : : default:
4385 : : break;
4386 : : }
4387 : :
4388 : : #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4389 : : ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
4390 : : align, desc->labelno, done);
4391 : : #endif
4392 : :
4393 : 259274 : assemble_align (align);
4394 : :
4395 : : /* Output the label. */
4396 : 259274 : targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
4397 : :
4398 : : /* Output the data.
4399 : : Pass actual alignment value while emitting string constant to asm code
4400 : : as function 'output_constant_pool_1' explicitly passes the alignment as 1
4401 : : assuming that the data is already aligned which prevents the generation
4402 : : of fix-up table entries. */
4403 : 259274 : output_constant_pool_2 (desc->mode, x, desc->align);
4404 : :
4405 : : /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4406 : : sections have proper size. */
4407 : 259274 : if (align > GET_MODE_BITSIZE (desc->mode)
4408 : 97 : && in_section
4409 : 259371 : && (in_section->common.flags & SECTION_MERGE))
4410 : 97 : assemble_align (align);
4411 : :
4412 : : #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4413 : : done:
4414 : : #endif
4415 : 259274 : return;
4416 : : }
4417 : :
4418 : : /* Recompute the offsets of entries in POOL, and the overall size of
4419 : : POOL. Do this after calling mark_constant_pool to ensure that we
4420 : : are computing the offset values for the pool which we will actually
4421 : : emit. */
4422 : :
4423 : : static void
4424 : 1428990 : recompute_pool_offsets (struct rtx_constant_pool *pool)
4425 : : {
4426 : 1428990 : class constant_descriptor_rtx *desc;
4427 : 1428990 : pool->offset = 0;
4428 : :
4429 : 1428990 : for (desc = pool->first; desc ; desc = desc->next)
4430 : 0 : if (desc->mark)
4431 : : {
4432 : : /* Recalculate offset. */
4433 : 0 : unsigned int align = desc->align;
4434 : 0 : pool->offset += (align / BITS_PER_UNIT) - 1;
4435 : 0 : pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
4436 : 0 : desc->offset = pool->offset;
4437 : 0 : pool->offset += GET_MODE_SIZE (desc->mode);
4438 : : }
4439 : 1428990 : }
4440 : :
4441 : : /* Mark all constants that are referenced by SYMBOL_REFs in X.
4442 : : Emit referenced deferred strings. */
4443 : :
4444 : : static void
4445 : 37326694 : mark_constants_in_pattern (rtx insn)
4446 : : {
4447 : 37326694 : subrtx_iterator::array_type array;
4448 : 249867430 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
4449 : : {
4450 : 212540736 : const_rtx x = *iter;
4451 : 212540736 : if (GET_CODE (x) == SYMBOL_REF)
4452 : : {
4453 : 7414471 : if (CONSTANT_POOL_ADDRESS_P (x))
4454 : : {
4455 : 805972 : class constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4456 : 805972 : if (desc->mark == 0)
4457 : : {
4458 : 268952 : desc->mark = 1;
4459 : 268952 : iter.substitute (desc->constant);
4460 : : }
4461 : : }
4462 : 6608499 : else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4463 : : {
4464 : 640160 : tree decl = SYMBOL_REF_DECL (x);
4465 : 640160 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4466 : : {
4467 : 6935 : n_deferred_constants--;
4468 : 6935 : output_constant_def_contents (CONST_CAST_RTX (x));
4469 : : }
4470 : : }
4471 : : }
4472 : : }
4473 : 37326694 : }
4474 : :
4475 : : /* Look through appropriate parts of INSN, marking all entries in the
4476 : : constant pool which are actually being used. Entries that are only
4477 : : referenced by other constants are also marked as used. Emit
4478 : : deferred strings that are used. */
4479 : :
4480 : : static void
4481 : 78627050 : mark_constants (rtx_insn *insn)
4482 : : {
4483 : 78627050 : if (!INSN_P (insn))
4484 : : return;
4485 : :
4486 : : /* Insns may appear inside a SEQUENCE. Only check the patterns of
4487 : : insns, not any notes that may be attached. We don't want to mark
4488 : : a constant just because it happens to appear in a REG_EQUIV note. */
4489 : 37326694 : if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
4490 : : {
4491 : 0 : int i, n = seq->len ();
4492 : 0 : for (i = 0; i < n; ++i)
4493 : : {
4494 : 0 : rtx subinsn = seq->element (i);
4495 : 0 : if (INSN_P (subinsn))
4496 : 0 : mark_constants_in_pattern (subinsn);
4497 : : }
4498 : : }
4499 : : else
4500 : 37326694 : mark_constants_in_pattern (insn);
4501 : : }
4502 : :
4503 : : /* Look through the instructions for this function, and mark all the
4504 : : entries in POOL which are actually being used. Emit deferred constants
4505 : : which have indeed been used. */
4506 : :
4507 : : static void
4508 : 1428990 : mark_constant_pool (void)
4509 : : {
4510 : 1428990 : rtx_insn *insn;
4511 : :
4512 : 1428990 : if (!crtl->uses_const_pool && n_deferred_constants == 0)
4513 : : return;
4514 : :
4515 : 78798478 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4516 : 78627050 : mark_constants (insn);
4517 : : }
4518 : :
4519 : : /* Write all the constants in POOL. */
4520 : :
4521 : : static void
4522 : 1654306 : output_constant_pool_contents (struct rtx_constant_pool *pool)
4523 : : {
4524 : 1654306 : class constant_descriptor_rtx *desc;
4525 : :
4526 : 2001727 : for (desc = pool->first; desc ; desc = desc->next)
4527 : 347421 : if (desc->mark < 0)
4528 : : {
4529 : : #ifdef ASM_OUTPUT_DEF
4530 : 9678 : gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
4531 : :
4532 : 9678 : const char *name = XSTR (desc->sym, 0);
4533 : 9678 : char label[256];
4534 : 9678 : char buffer[256 + 32];
4535 : 9678 : const char *p;
4536 : :
4537 : 9678 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", ~desc->mark);
4538 : 9678 : p = label;
4539 : 9678 : if (desc->offset)
4540 : : {
4541 : 3263 : sprintf (buffer, "%s+" HOST_WIDE_INT_PRINT_DEC, p, desc->offset);
4542 : 3263 : p = buffer;
4543 : : }
4544 : 9678 : ASM_OUTPUT_DEF (asm_out_file, name, p);
4545 : : #else
4546 : : gcc_unreachable ();
4547 : : #endif
4548 : : }
4549 : 337743 : else if (desc->mark)
4550 : : {
4551 : : /* If the constant is part of an object_block, make sure that
4552 : : the constant has been positioned within its block, but do not
4553 : : write out its definition yet. output_object_blocks will do
4554 : : that later. */
4555 : 259274 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4556 : 259274 : && SYMBOL_REF_BLOCK (desc->sym))
4557 : 0 : place_block_symbol (desc->sym);
4558 : : else
4559 : : {
4560 : 259274 : switch_to_section (targetm.asm_out.select_rtx_section
4561 : 259274 : (desc->mode, desc->constant, desc->align));
4562 : 259274 : output_constant_pool_1 (desc, desc->align);
4563 : : }
4564 : : }
4565 : 1654306 : }
4566 : :
4567 : : struct constant_descriptor_rtx_data {
4568 : : constant_descriptor_rtx *desc;
4569 : : target_unit *bytes;
4570 : : unsigned short size;
4571 : : unsigned short offset;
4572 : : unsigned int hash;
4573 : : };
4574 : :
4575 : : /* qsort callback to sort constant_descriptor_rtx_data * vector by
4576 : : decreasing size. */
4577 : :
4578 : : static int
4579 : 3998576 : constant_descriptor_rtx_data_cmp (const void *p1, const void *p2)
4580 : : {
4581 : 3998576 : constant_descriptor_rtx_data *const data1
4582 : : = *(constant_descriptor_rtx_data * const *) p1;
4583 : 3998576 : constant_descriptor_rtx_data *const data2
4584 : : = *(constant_descriptor_rtx_data * const *) p2;
4585 : 3998576 : if (data1->size > data2->size)
4586 : : return -1;
4587 : 3637496 : if (data1->size < data2->size)
4588 : : return 1;
4589 : 3367814 : if (data1->hash < data2->hash)
4590 : : return -1;
4591 : 1748531 : gcc_assert (data1->hash > data2->hash);
4592 : : return 1;
4593 : : }
4594 : :
4595 : : struct const_rtx_data_hasher : nofree_ptr_hash<constant_descriptor_rtx_data>
4596 : : {
4597 : : static hashval_t hash (constant_descriptor_rtx_data *);
4598 : : static bool equal (constant_descriptor_rtx_data *,
4599 : : constant_descriptor_rtx_data *);
4600 : : };
4601 : :
4602 : : /* Hash and compare functions for const_rtx_data_htab. */
4603 : :
4604 : : hashval_t
4605 : 2740525 : const_rtx_data_hasher::hash (constant_descriptor_rtx_data *data)
4606 : : {
4607 : 2740525 : return data->hash;
4608 : : }
4609 : :
4610 : : bool
4611 : 2978185 : const_rtx_data_hasher::equal (constant_descriptor_rtx_data *x,
4612 : : constant_descriptor_rtx_data *y)
4613 : : {
4614 : 2978185 : if (x->hash != y->hash || x->size != y->size)
4615 : : return false;
4616 : 198891 : unsigned int align1 = x->desc->align;
4617 : 198891 : unsigned int align2 = y->desc->align;
4618 : 198891 : unsigned int offset1 = (x->offset * BITS_PER_UNIT) & (align1 - 1);
4619 : 198891 : unsigned int offset2 = (y->offset * BITS_PER_UNIT) & (align2 - 1);
4620 : 198891 : if (offset1)
4621 : 105962 : align1 = least_bit_hwi (offset1);
4622 : 198891 : if (offset2)
4623 : 139339 : align2 = least_bit_hwi (offset2);
4624 : 198891 : if (align2 > align1)
4625 : : return false;
4626 : 166881 : if (memcmp (x->bytes, y->bytes, x->size * sizeof (target_unit)) != 0)
4627 : 0 : return false;
4628 : : return true;
4629 : : }
4630 : :
4631 : : /* Attempt to optimize constant pool POOL. If it contains both CONST_VECTOR
4632 : : constants and scalar constants with the values of CONST_VECTOR elements,
4633 : : try to alias the scalar constants with the CONST_VECTOR elements. */
4634 : :
4635 : : static void
4636 : 145182 : optimize_constant_pool (struct rtx_constant_pool *pool)
4637 : : {
4638 : 145182 : auto_vec<target_unit, 128> buffer;
4639 : 145182 : auto_vec<constant_descriptor_rtx_data *, 128> vec;
4640 : 145182 : object_allocator<constant_descriptor_rtx_data>
4641 : 145182 : data_pool ("constant_descriptor_rtx_data_pool");
4642 : 145182 : int idx = 0;
4643 : 145182 : size_t size = 0;
4644 : 450777 : for (constant_descriptor_rtx *desc = pool->first; desc; desc = desc->next)
4645 : 305595 : if (desc->mark > 0
4646 : 305595 : && ! (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4647 : 0 : && SYMBOL_REF_BLOCK (desc->sym)))
4648 : : {
4649 : 230465 : buffer.truncate (0);
4650 : 460930 : buffer.reserve (GET_MODE_SIZE (desc->mode));
4651 : 230465 : if (native_encode_rtx (desc->mode, desc->constant, buffer, 0,
4652 : 460930 : GET_MODE_SIZE (desc->mode)))
4653 : : {
4654 : 199033 : constant_descriptor_rtx_data *data = data_pool.allocate ();
4655 : 199033 : data->desc = desc;
4656 : 199033 : data->bytes = NULL;
4657 : 199033 : data->size = GET_MODE_SIZE (desc->mode);
4658 : 199033 : data->offset = 0;
4659 : 199033 : data->hash = idx++;
4660 : 199033 : size += data->size;
4661 : 199033 : vec.safe_push (data);
4662 : : }
4663 : : }
4664 : 145182 : if (idx)
4665 : : {
4666 : 30687 : vec.qsort (constant_descriptor_rtx_data_cmp);
4667 : 30687 : unsigned min_size = vec.last ()->size;
4668 : 30687 : target_unit *bytes = XNEWVEC (target_unit, size);
4669 : 30687 : unsigned int i;
4670 : 30687 : constant_descriptor_rtx_data *data;
4671 : 30687 : hash_table<const_rtx_data_hasher> * htab
4672 : 30687 : = new hash_table<const_rtx_data_hasher> (31);
4673 : 30687 : size = 0;
4674 : 229720 : FOR_EACH_VEC_ELT (vec, i, data)
4675 : : {
4676 : 199033 : buffer.truncate (0);
4677 : 199033 : native_encode_rtx (data->desc->mode, data->desc->constant,
4678 : 199033 : buffer, 0, data->size);
4679 : 199033 : memcpy (bytes + size, buffer.address (), data->size);
4680 : 199033 : data->bytes = bytes + size;
4681 : 398066 : data->hash = iterative_hash (data->bytes,
4682 : 199033 : data->size * sizeof (target_unit), 0);
4683 : 199033 : size += data->size;
4684 : 199033 : constant_descriptor_rtx_data **slot
4685 : 199033 : = htab->find_slot_with_hash (data, data->hash, INSERT);
4686 : 199033 : if (*slot)
4687 : : {
4688 : 9678 : data->desc->mark = ~(*slot)->desc->labelno;
4689 : 9678 : data->desc->offset = (*slot)->offset;
4690 : : }
4691 : : else
4692 : : {
4693 : 189355 : unsigned int sz = 1 << floor_log2 (data->size);
4694 : :
4695 : 189355 : *slot = data;
4696 : 303068 : for (sz >>= 1; sz >= min_size; sz >>= 1)
4697 : 494760 : for (unsigned off = 0; off + sz <= data->size; off += sz)
4698 : : {
4699 : 381047 : constant_descriptor_rtx_data tmp;
4700 : 381047 : tmp.desc = data->desc;
4701 : 381047 : tmp.bytes = data->bytes + off;
4702 : 381047 : tmp.size = sz;
4703 : 381047 : tmp.offset = off;
4704 : 381047 : tmp.hash = iterative_hash (tmp.bytes,
4705 : : sz * sizeof (target_unit), 0);
4706 : 381047 : slot = htab->find_slot_with_hash (&tmp, tmp.hash, INSERT);
4707 : 381047 : if (*slot == NULL)
4708 : : {
4709 : 223844 : *slot = data_pool.allocate ();
4710 : 223844 : **slot = tmp;
4711 : : }
4712 : : }
4713 : : }
4714 : : }
4715 : 30687 : delete htab;
4716 : 30687 : XDELETE (bytes);
4717 : : }
4718 : 145182 : data_pool.release ();
4719 : 145182 : }
4720 : :
4721 : : /* Mark all constants that are used in the current function, then write
4722 : : out the function's private constant pool. */
4723 : :
4724 : : static void
4725 : 1428990 : output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4726 : : tree fndecl ATTRIBUTE_UNUSED)
4727 : : {
4728 : 1428990 : struct rtx_constant_pool *pool = crtl->varasm.pool;
4729 : :
4730 : : /* It is possible for gcc to call force_const_mem and then to later
4731 : : discard the instructions which refer to the constant. In such a
4732 : : case we do not need to output the constant. */
4733 : 1428990 : mark_constant_pool ();
4734 : :
4735 : : /* Having marked the constant pool entries we'll actually emit, we
4736 : : now need to rebuild the offset information, which may have become
4737 : : stale. */
4738 : 1428990 : recompute_pool_offsets (pool);
4739 : :
4740 : : #ifdef ASM_OUTPUT_POOL_PROLOGUE
4741 : : ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4742 : : #endif
4743 : :
4744 : 1428990 : output_constant_pool_contents (pool);
4745 : :
4746 : : #ifdef ASM_OUTPUT_POOL_EPILOGUE
4747 : : ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4748 : : #endif
4749 : 1428990 : }
4750 : :
4751 : : /* Write the contents of the shared constant pool. */
4752 : :
4753 : : void
4754 : 225316 : output_shared_constant_pool (void)
4755 : : {
4756 : 225316 : if (optimize
4757 : : && TARGET_SUPPORTS_ALIASES)
4758 : 145182 : optimize_constant_pool (shared_constant_pool);
4759 : :
4760 : 225316 : output_constant_pool_contents (shared_constant_pool);
4761 : 225316 : }
4762 : :
4763 : : /* Determine what kind of relocations EXP may need. */
4764 : :
4765 : : int
4766 : 35109922 : compute_reloc_for_constant (tree exp)
4767 : : {
4768 : 37579211 : int reloc = 0, reloc2;
4769 : 37579211 : tree tem;
4770 : :
4771 : 37579211 : switch (TREE_CODE (exp))
4772 : : {
4773 : 10034977 : case ADDR_EXPR:
4774 : 10034977 : case FDESC_EXPR:
4775 : : /* Go inside any operations that get_inner_reference can handle and see
4776 : : if what's inside is a constant: no need to do anything here for
4777 : : addresses of variables or functions. */
4778 : 10087262 : for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4779 : 52285 : tem = TREE_OPERAND (tem, 0))
4780 : : ;
4781 : :
4782 : 10034977 : if (TREE_CODE (tem) == MEM_REF
4783 : 10034977 : && TREE_CODE (TREE_OPERAND (tem, 0)) == ADDR_EXPR)
4784 : : {
4785 : 54910 : reloc = compute_reloc_for_constant (TREE_OPERAND (tem, 0));
4786 : 54910 : break;
4787 : : }
4788 : :
4789 : 9980067 : if (!targetm.binds_local_p (tem))
4790 : : reloc |= 2;
4791 : : else
4792 : 7656616 : reloc |= 1;
4793 : : break;
4794 : :
4795 : 19242 : case PLUS_EXPR:
4796 : 19242 : case POINTER_PLUS_EXPR:
4797 : 19242 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4798 : 19242 : reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4799 : 19242 : break;
4800 : :
4801 : 26 : case MINUS_EXPR:
4802 : 26 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4803 : 26 : reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4804 : : /* The difference of two local labels is computable at link time. */
4805 : 26 : if (reloc == 1 && reloc2 == 1)
4806 : : reloc = 0;
4807 : : else
4808 : 0 : reloc |= reloc2;
4809 : : break;
4810 : :
4811 : 2414379 : CASE_CONVERT:
4812 : 2414379 : case VIEW_CONVERT_EXPR:
4813 : 2414379 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4814 : 2414379 : break;
4815 : :
4816 : : case CONSTRUCTOR:
4817 : : {
4818 : : unsigned HOST_WIDE_INT idx;
4819 : 37243370 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4820 : 29360319 : if (tem != 0)
4821 : 29360319 : reloc |= compute_reloc_for_constant (tem);
4822 : : }
4823 : : break;
4824 : :
4825 : : default:
4826 : : break;
4827 : : }
4828 : 35109922 : return reloc;
4829 : : }
4830 : :
4831 : : /* Find all the constants whose addresses are referenced inside of EXP,
4832 : : and make sure assembler code with a label has been output for each one.
4833 : : Indicate whether an ADDR_EXPR has been encountered. */
4834 : :
4835 : : static void
4836 : 22019489 : output_addressed_constants (tree exp, int defer)
4837 : : {
4838 : 22497086 : tree tem;
4839 : :
4840 : 22497086 : switch (TREE_CODE (exp))
4841 : : {
4842 : 4524594 : case ADDR_EXPR:
4843 : 4524594 : case FDESC_EXPR:
4844 : : /* Go inside any operations that get_inner_reference can handle and see
4845 : : if what's inside is a constant: no need to do anything here for
4846 : : addresses of variables or functions. */
4847 : 4577096 : for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4848 : 52502 : tem = TREE_OPERAND (tem, 0))
4849 : : ;
4850 : :
4851 : : /* If we have an initialized CONST_DECL, retrieve the initializer. */
4852 : 4524594 : if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4853 : 0 : tem = DECL_INITIAL (tem);
4854 : :
4855 : 4524594 : if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4856 : 968650 : output_constant_def (tem, defer);
4857 : :
4858 : 4524594 : if (TREE_CODE (tem) == MEM_REF)
4859 : 50503 : output_addressed_constants (TREE_OPERAND (tem, 0), defer);
4860 : : break;
4861 : :
4862 : 16793 : case PLUS_EXPR:
4863 : 16793 : case POINTER_PLUS_EXPR:
4864 : 16793 : case MINUS_EXPR:
4865 : 16793 : output_addressed_constants (TREE_OPERAND (exp, 1), defer);
4866 : 427094 : gcc_fallthrough ();
4867 : :
4868 : 427094 : CASE_CONVERT:
4869 : 427094 : case VIEW_CONVERT_EXPR:
4870 : 427094 : output_addressed_constants (TREE_OPERAND (exp, 0), defer);
4871 : 427094 : break;
4872 : :
4873 : : case CONSTRUCTOR:
4874 : : {
4875 : : unsigned HOST_WIDE_INT idx;
4876 : 19109066 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4877 : 15066593 : if (tem != 0)
4878 : 15066593 : output_addressed_constants (tem, defer);
4879 : : }
4880 : : break;
4881 : :
4882 : : default:
4883 : : break;
4884 : : }
4885 : 22019489 : }
4886 : :
4887 : : /* Whether a constructor CTOR is a valid static constant initializer if all
4888 : : its elements are. This used to be internal to initializer_constant_valid_p
4889 : : and has been exposed to let other functions like categorize_ctor_elements
4890 : : evaluate the property while walking a constructor for other purposes. */
4891 : :
4892 : : bool
4893 : 10984741 : constructor_static_from_elts_p (const_tree ctor)
4894 : : {
4895 : 10984741 : return (TREE_CONSTANT (ctor)
4896 : 10984741 : && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4897 : 10368693 : || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
4898 : 1374506 : || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
4899 : : }
4900 : :
4901 : : static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4902 : : tree *cache);
4903 : :
4904 : : /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4905 : : PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4906 : : which are valid when ENDTYPE is an integer of any size; in
4907 : : particular, this does not accept a pointer minus a constant. This
4908 : : returns null_pointer_node if the VALUE is an absolute constant
4909 : : which can be used to initialize a static variable. Otherwise it
4910 : : returns NULL. */
4911 : :
4912 : : static tree
4913 : 538019 : narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4914 : : {
4915 : 538019 : tree op0, op1;
4916 : :
4917 : 538019 : if (!INTEGRAL_TYPE_P (endtype))
4918 : : return NULL_TREE;
4919 : :
4920 : 505794 : op0 = TREE_OPERAND (value, 0);
4921 : 505794 : op1 = TREE_OPERAND (value, 1);
4922 : :
4923 : : /* Like STRIP_NOPS except allow the operand mode to widen. This
4924 : : works around a feature of fold that simplifies (int)(p1 - p2) to
4925 : : ((int)p1 - (int)p2) under the theory that the narrower operation
4926 : : is cheaper. */
4927 : :
4928 : 1000830 : while (CONVERT_EXPR_P (op0)
4929 : 1183401 : || TREE_CODE (op0) == NON_LVALUE_EXPR)
4930 : : {
4931 : 197888 : tree inner = TREE_OPERAND (op0, 0);
4932 : 395776 : if (inner == error_mark_node
4933 : 197888 : || ! INTEGRAL_TYPE_P (TREE_TYPE (op0))
4934 : 197629 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op0)))
4935 : 197629 : || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
4936 : 197476 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4937 : 395364 : || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0)))
4938 : 407991 : > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
4939 : : break;
4940 : : op0 = inner;
4941 : : }
4942 : :
4943 : 494825 : while (CONVERT_EXPR_P (op1)
4944 : 1068487 : || TREE_CODE (op1) == NON_LVALUE_EXPR)
4945 : : {
4946 : 87750 : tree inner = TREE_OPERAND (op1, 0);
4947 : 175500 : if (inner == error_mark_node
4948 : 87750 : || ! INTEGRAL_TYPE_P (TREE_TYPE (op1))
4949 : 83069 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op1)))
4950 : 83069 : || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
4951 : 82986 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4952 : 170736 : || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1)))
4953 : 181631 : > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
4954 : : break;
4955 : : op1 = inner;
4956 : : }
4957 : :
4958 : 505794 : op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
4959 : 505794 : if (!op0)
4960 : : return NULL_TREE;
4961 : :
4962 : 831 : op1 = initializer_constant_valid_p_1 (op1, endtype,
4963 : : cache ? cache + 2 : NULL);
4964 : : /* Both initializers must be known. */
4965 : 831 : if (op1)
4966 : : {
4967 : 201 : if (op0 == op1
4968 : 30 : && (op0 == null_pointer_node
4969 : 11 : || TREE_CODE (value) == MINUS_EXPR))
4970 : : return null_pointer_node;
4971 : :
4972 : : /* Support differences between labels. */
4973 : 182 : if (TREE_CODE (op0) == LABEL_DECL
4974 : 169 : && TREE_CODE (op1) == LABEL_DECL)
4975 : 169 : return null_pointer_node;
4976 : :
4977 : 13 : if (TREE_CODE (op0) == STRING_CST
4978 : 0 : && TREE_CODE (op1) == STRING_CST
4979 : 13 : && operand_equal_p (op0, op1, 1))
4980 : 0 : return null_pointer_node;
4981 : : }
4982 : :
4983 : : return NULL_TREE;
4984 : : }
4985 : :
4986 : : /* Helper function of initializer_constant_valid_p.
4987 : : Return nonzero if VALUE is a valid constant-valued expression
4988 : : for use in initializing a static variable; one that can be an
4989 : : element of a "constant" initializer.
4990 : :
4991 : : Return null_pointer_node if the value is absolute;
4992 : : if it is relocatable, return the variable that determines the relocation.
4993 : : We assume that VALUE has been folded as much as possible;
4994 : : therefore, we do not need to check for such things as
4995 : : arithmetic-combinations of integers.
4996 : :
4997 : : Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
4998 : :
4999 : : static tree
5000 : 586993913 : initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
5001 : : {
5002 : 627642972 : tree ret;
5003 : :
5004 : 627642972 : switch (TREE_CODE (value))
5005 : : {
5006 : 9592317 : case CONSTRUCTOR:
5007 : 9592317 : if (constructor_static_from_elts_p (value))
5008 : : {
5009 : 9581424 : unsigned HOST_WIDE_INT idx;
5010 : 9581424 : tree elt;
5011 : 9581424 : bool absolute = true;
5012 : :
5013 : 9581424 : if (cache && cache[0] == value)
5014 : 0 : return cache[1];
5015 : 36143141 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
5016 : : {
5017 : 26561932 : tree reloc;
5018 : 26561932 : reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
5019 : : NULL);
5020 : 26561932 : if (!reloc
5021 : : /* An absolute value is required with reverse SSO. */
5022 : 26561932 : || (reloc != null_pointer_node
5023 : 9651829 : && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (value))
5024 : 1 : && !AGGREGATE_TYPE_P (TREE_TYPE (elt))))
5025 : : {
5026 : 215 : if (cache)
5027 : : {
5028 : 0 : cache[0] = value;
5029 : 0 : cache[1] = NULL_TREE;
5030 : : }
5031 : 215 : return NULL_TREE;
5032 : : }
5033 : 26561717 : if (reloc != null_pointer_node)
5034 : 9651828 : absolute = false;
5035 : : }
5036 : : /* For a non-absolute relocation, there is no single
5037 : : variable that can be "the variable that determines the
5038 : : relocation." */
5039 : 9581209 : if (cache)
5040 : : {
5041 : 0 : cache[0] = value;
5042 : 0 : cache[1] = absolute ? null_pointer_node : error_mark_node;
5043 : : }
5044 : 9581209 : return absolute ? null_pointer_node : error_mark_node;
5045 : : }
5046 : :
5047 : 10893 : return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
5048 : :
5049 : 509202789 : case INTEGER_CST:
5050 : 509202789 : case VECTOR_CST:
5051 : 509202789 : case REAL_CST:
5052 : 509202789 : case FIXED_CST:
5053 : 509202789 : case STRING_CST:
5054 : 509202789 : case COMPLEX_CST:
5055 : 509202789 : case RAW_DATA_CST:
5056 : 509202789 : return null_pointer_node;
5057 : :
5058 : 39919560 : case ADDR_EXPR:
5059 : 39919560 : case FDESC_EXPR:
5060 : 39919560 : {
5061 : 39919560 : tree op0 = staticp (TREE_OPERAND (value, 0));
5062 : 39919560 : if (op0)
5063 : : {
5064 : : /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
5065 : : to be a constant, this is old-skool offsetof-like nonsense. */
5066 : 36907169 : if (TREE_CODE (op0) == INDIRECT_REF
5067 : 36907169 : && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
5068 : 50 : return null_pointer_node;
5069 : : /* Taking the address of a nested function involves a trampoline,
5070 : : unless we don't need or want one. */
5071 : 36907119 : if (TREE_CODE (op0) == FUNCTION_DECL
5072 : 7558591 : && DECL_STATIC_CHAIN (op0)
5073 : 36907134 : && !TREE_NO_TRAMPOLINE (value))
5074 : : return NULL_TREE;
5075 : : /* "&{...}" requires a temporary to hold the constructed
5076 : : object. */
5077 : 36907104 : if (TREE_CODE (op0) == CONSTRUCTOR)
5078 : : return NULL_TREE;
5079 : : }
5080 : : return op0;
5081 : : }
5082 : :
5083 : 872748 : case NON_LVALUE_EXPR:
5084 : 872748 : return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5085 : 872748 : endtype, cache);
5086 : :
5087 : 1004780 : case VIEW_CONVERT_EXPR:
5088 : 1004780 : {
5089 : 1004780 : tree src = TREE_OPERAND (value, 0);
5090 : 1004780 : tree src_type = TREE_TYPE (src);
5091 : 1004780 : tree dest_type = TREE_TYPE (value);
5092 : :
5093 : : /* Allow view-conversions from aggregate to non-aggregate type only
5094 : : if the bit pattern is fully preserved afterwards; otherwise, the
5095 : : RTL expander won't be able to apply a subsequent transformation
5096 : : to the underlying constructor. */
5097 : 1004780 : if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
5098 : : {
5099 : 0 : if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
5100 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5101 : : else
5102 : : return NULL_TREE;
5103 : : }
5104 : :
5105 : : /* Allow all other kinds of view-conversion. */
5106 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5107 : : }
5108 : :
5109 : 39144233 : CASE_CONVERT:
5110 : 39144233 : {
5111 : 39144233 : tree src = TREE_OPERAND (value, 0);
5112 : 39144233 : tree src_type = TREE_TYPE (src);
5113 : 39144233 : tree dest_type = TREE_TYPE (value);
5114 : :
5115 : : /* Allow conversions between pointer types and offset types. */
5116 : 39144233 : if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
5117 : 1582125 : || (TREE_CODE (dest_type) == OFFSET_TYPE
5118 : 82 : && TREE_CODE (src_type) == OFFSET_TYPE))
5119 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5120 : :
5121 : : /* Allow length-preserving conversions between integer types and
5122 : : floating-point types. */
5123 : 1331418 : if (((INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
5124 : 317081 : || (SCALAR_FLOAT_TYPE_P (dest_type)
5125 : 65904 : && SCALAR_FLOAT_TYPE_P (src_type)))
5126 : 2912945 : && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
5127 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5128 : :
5129 : : /* Allow conversions between other integer types only if
5130 : : explicit value. Don't allow sign-extension to a type larger
5131 : : than word and pointer, there aren't relocations that would
5132 : : allow to sign extend it to a wider type. */
5133 : 556934 : if (INTEGRAL_TYPE_P (dest_type)
5134 : 369245 : && INTEGRAL_TYPE_P (src_type)
5135 : 859741 : && (TYPE_UNSIGNED (src_type)
5136 : 97915 : || TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)
5137 : 64126 : || TYPE_PRECISION (dest_type) <= BITS_PER_WORD
5138 : 708 : || TYPE_PRECISION (dest_type) <= POINTER_SIZE))
5139 : : {
5140 : 302453 : tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
5141 : 302453 : if (inner == null_pointer_node)
5142 : : return null_pointer_node;
5143 : : break;
5144 : : }
5145 : :
5146 : : /* Allow (int) &foo provided int is as wide as a pointer. */
5147 : 66792 : if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
5148 : 320904 : && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
5149 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5150 : :
5151 : : /* Likewise conversions from int to pointers, but also allow
5152 : : conversions from 0. */
5153 : 188290 : if ((POINTER_TYPE_P (dest_type)
5154 : 125042 : || TREE_CODE (dest_type) == OFFSET_TYPE)
5155 : 63266 : && INTEGRAL_TYPE_P (src_type))
5156 : : {
5157 : 543 : if (TREE_CODE (src) == INTEGER_CST
5158 : 543 : && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
5159 : 0 : return null_pointer_node;
5160 : 543 : if (integer_zerop (src))
5161 : 0 : return null_pointer_node;
5162 : 543 : else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
5163 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5164 : : }
5165 : :
5166 : : /* Allow conversions to struct or union types if the value
5167 : : inside is okay. */
5168 : 187747 : if (TREE_CODE (dest_type) == RECORD_TYPE
5169 : 187747 : || TREE_CODE (dest_type) == UNION_TYPE)
5170 : : return initializer_constant_valid_p_1 (src, endtype, cache);
5171 : : }
5172 : : break;
5173 : :
5174 : 5689936 : case POINTER_PLUS_EXPR:
5175 : 5689936 : case PLUS_EXPR:
5176 : : /* Any valid floating-point constants will have been folded by now;
5177 : : with -frounding-math we hit this with addition of two constants. */
5178 : 5689936 : if (TREE_CODE (endtype) == REAL_TYPE)
5179 : : return NULL_TREE;
5180 : 4714076 : if (cache && cache[0] == value)
5181 : 73539 : return cache[1];
5182 : 4640537 : if (! INTEGRAL_TYPE_P (endtype)
5183 : 395729 : || ! INTEGRAL_TYPE_P (TREE_TYPE (value))
5184 : 5035795 : || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
5185 : : {
5186 : 4640467 : tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
5187 : 4640467 : tree valid0
5188 : 4640467 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5189 : : endtype, ncache);
5190 : 4640467 : tree valid1
5191 : 4640467 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
5192 : : endtype, ncache + 2);
5193 : : /* If either term is absolute, use the other term's relocation. */
5194 : 4640467 : if (valid0 == null_pointer_node)
5195 : : ret = valid1;
5196 : 4638037 : else if (valid1 == null_pointer_node)
5197 : : ret = valid0;
5198 : : /* Support narrowing pointer differences. */
5199 : : else
5200 : 185709 : ret = narrowing_initializer_constant_valid_p (value, endtype,
5201 : : ncache);
5202 : : }
5203 : : else
5204 : : /* Support narrowing pointer differences. */
5205 : 70 : ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
5206 : 4640537 : if (cache)
5207 : : {
5208 : 73809 : cache[0] = value;
5209 : 73809 : cache[1] = ret;
5210 : : }
5211 : : return ret;
5212 : :
5213 : 1104011 : case POINTER_DIFF_EXPR:
5214 : 1104011 : case MINUS_EXPR:
5215 : 1104011 : if (TREE_CODE (endtype) == REAL_TYPE)
5216 : : return NULL_TREE;
5217 : 601175 : if (cache && cache[0] == value)
5218 : 85002 : return cache[1];
5219 : 516173 : if (! INTEGRAL_TYPE_P (endtype)
5220 : 516136 : || ! INTEGRAL_TYPE_P (TREE_TYPE (value))
5221 : 1032306 : || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
5222 : : {
5223 : 502749 : tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
5224 : 502749 : tree valid0
5225 : 502749 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5226 : : endtype, ncache);
5227 : 502749 : tree valid1
5228 : 502749 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
5229 : : endtype, ncache + 2);
5230 : : /* Win if second argument is absolute. */
5231 : 502749 : if (valid1 == null_pointer_node)
5232 : : ret = valid0;
5233 : : /* Win if both arguments have the same relocation.
5234 : : Then the value is absolute. */
5235 : 338816 : else if (valid0 == valid1 && valid0 != 0)
5236 : : ret = null_pointer_node;
5237 : : /* Since GCC guarantees that string constants are unique in the
5238 : : generated code, a subtraction between two copies of the same
5239 : : constant string is absolute. */
5240 : 704 : else if (valid0 && TREE_CODE (valid0) == STRING_CST
5241 : 0 : && valid1 && TREE_CODE (valid1) == STRING_CST
5242 : 338816 : && operand_equal_p (valid0, valid1, 1))
5243 : 0 : ret = null_pointer_node;
5244 : : /* Support narrowing differences. */
5245 : : else
5246 : 338816 : ret = narrowing_initializer_constant_valid_p (value, endtype,
5247 : : ncache);
5248 : : }
5249 : : else
5250 : : /* Support narrowing differences. */
5251 : 13424 : ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
5252 : 516173 : if (cache)
5253 : : {
5254 : 86373 : cache[0] = value;
5255 : 86373 : cache[1] = ret;
5256 : : }
5257 : : return ret;
5258 : :
5259 : : default:
5260 : : break;
5261 : : }
5262 : :
5263 : : return NULL_TREE;
5264 : : }
5265 : :
5266 : : /* Return nonzero if VALUE is a valid constant-valued expression
5267 : : for use in initializing a static variable; one that can be an
5268 : : element of a "constant" initializer.
5269 : :
5270 : : Return null_pointer_node if the value is absolute;
5271 : : if it is relocatable, return the variable that determines the relocation.
5272 : : We assume that VALUE has been folded as much as possible;
5273 : : therefore, we do not need to check for such things as
5274 : : arithmetic-combinations of integers. */
5275 : : tree
5276 : 549336471 : initializer_constant_valid_p (tree value, tree endtype, bool reverse)
5277 : : {
5278 : 549336471 : tree reloc = initializer_constant_valid_p_1 (value, endtype, NULL);
5279 : :
5280 : : /* An absolute value is required with reverse storage order. */
5281 : 549336471 : if (reloc
5282 : 524518372 : && reloc != null_pointer_node
5283 : 33828708 : && reverse
5284 : 1 : && !AGGREGATE_TYPE_P (endtype)
5285 : 1 : && !VECTOR_TYPE_P (endtype))
5286 : 549336471 : reloc = NULL_TREE;
5287 : :
5288 : 549336471 : return reloc;
5289 : : }
5290 : :
5291 : : /* Return true if VALUE is a valid constant-valued expression
5292 : : for use in initializing a static bit-field; one that can be
5293 : : an element of a "constant" initializer. */
5294 : :
5295 : : bool
5296 : 769 : initializer_constant_valid_for_bitfield_p (const_tree value)
5297 : : {
5298 : : /* For bitfields we support integer constants or possibly nested aggregates
5299 : : of such. */
5300 : 769 : switch (TREE_CODE (value))
5301 : : {
5302 : : case CONSTRUCTOR:
5303 : : {
5304 : : unsigned HOST_WIDE_INT idx;
5305 : : const_tree elt;
5306 : :
5307 : 821 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
5308 : 616 : if (!initializer_constant_valid_for_bitfield_p (elt))
5309 : : return false;
5310 : : return true;
5311 : : }
5312 : :
5313 : : case INTEGER_CST:
5314 : : case REAL_CST:
5315 : : return true;
5316 : :
5317 : 0 : case VIEW_CONVERT_EXPR:
5318 : 0 : case NON_LVALUE_EXPR:
5319 : 0 : return
5320 : 0 : initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
5321 : :
5322 : : default:
5323 : : break;
5324 : : }
5325 : :
5326 : : return false;
5327 : : }
5328 : :
5329 : : /* Check if a STRING_CST fits into the field.
5330 : : Tolerate only the case when the NUL termination
5331 : : does not fit into the field. */
5332 : :
5333 : : static bool
5334 : 1301500 : check_string_literal (tree string, unsigned HOST_WIDE_INT size)
5335 : : {
5336 : 1301500 : tree type = TREE_TYPE (string);
5337 : 1301500 : tree eltype = TREE_TYPE (type);
5338 : 1301500 : unsigned HOST_WIDE_INT elts = tree_to_uhwi (TYPE_SIZE_UNIT (eltype));
5339 : 1301500 : unsigned HOST_WIDE_INT mem_size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
5340 : 1301500 : int len = TREE_STRING_LENGTH (string);
5341 : :
5342 : 1301500 : if (elts != 1 && elts != 2 && elts != 4)
5343 : : return false;
5344 : 1301500 : if (len < 0 || len % elts != 0)
5345 : : return false;
5346 : 1301500 : if (size < (unsigned)len)
5347 : : return false;
5348 : 1301500 : if (mem_size != size)
5349 : 0 : return false;
5350 : : return true;
5351 : : }
5352 : :
5353 : : /* output_constructor outer state of relevance in recursive calls, typically
5354 : : for nested aggregate bitfields. */
5355 : :
5356 : : struct oc_outer_state {
5357 : : unsigned int bit_offset; /* current position in ... */
5358 : : int byte; /* ... the outer byte buffer. */
5359 : : };
5360 : :
5361 : : static unsigned HOST_WIDE_INT
5362 : : output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int, bool,
5363 : : oc_outer_state *);
5364 : :
5365 : : /* Output assembler code for constant EXP, with no label.
5366 : : This includes the pseudo-op such as ".int" or ".byte", and a newline.
5367 : : Assumes output_addressed_constants has been done on EXP already.
5368 : :
5369 : : Generate at least SIZE bytes of assembler data, padding at the end
5370 : : with zeros if necessary. SIZE must always be specified. The returned
5371 : : value is the actual number of bytes of assembler data generated, which
5372 : : may be bigger than SIZE if the object contains a variable length field.
5373 : :
5374 : : SIZE is important for structure constructors,
5375 : : since trailing members may have been omitted from the constructor.
5376 : : It is also important for initialization of arrays from string constants
5377 : : since the full length of the string constant might not be wanted.
5378 : : It is also needed for initialization of unions, where the initializer's
5379 : : type is just one member, and that may not be as long as the union.
5380 : :
5381 : : There a case in which we would fail to output exactly SIZE bytes:
5382 : : for a structure constructor that wants to produce more than SIZE bytes.
5383 : : But such constructors will never be generated for any possible input.
5384 : :
5385 : : ALIGN is the alignment of the data in bits.
5386 : :
5387 : : If REVERSE is true, EXP is output in reverse storage order. */
5388 : :
5389 : : static unsigned HOST_WIDE_INT
5390 : 17572858 : output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align,
5391 : : bool reverse, bool merge_strings)
5392 : : {
5393 : 17572858 : enum tree_code code;
5394 : 17572858 : unsigned HOST_WIDE_INT thissize;
5395 : 17572858 : rtx cst;
5396 : :
5397 : 17572858 : if (size == 0 || flag_syntax_only)
5398 : : return size;
5399 : :
5400 : : /* See if we're trying to initialize a pointer in a non-default mode
5401 : : to the address of some declaration somewhere. If the target says
5402 : : the mode is valid for pointers, assume the target has a way of
5403 : : resolving it. */
5404 : 17572620 : if (TREE_CODE (exp) == NOP_EXPR
5405 : 175 : && POINTER_TYPE_P (TREE_TYPE (exp))
5406 : 17572763 : && targetm.addr_space.valid_pointer_mode
5407 : 143 : (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)),
5408 : 143 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
5409 : : {
5410 : 143 : tree saved_type = TREE_TYPE (exp);
5411 : :
5412 : : /* Peel off any intermediate conversions-to-pointer for valid
5413 : : pointer modes. */
5414 : 143 : while (TREE_CODE (exp) == NOP_EXPR
5415 : 143 : && POINTER_TYPE_P (TREE_TYPE (exp))
5416 : 429 : && targetm.addr_space.valid_pointer_mode
5417 : 143 : (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)),
5418 : 143 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
5419 : 143 : exp = TREE_OPERAND (exp, 0);
5420 : :
5421 : : /* If what we're left with is the address of something, we can
5422 : : convert the address to the final type and output it that
5423 : : way. */
5424 : 143 : if (TREE_CODE (exp) == ADDR_EXPR)
5425 : 8 : exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
5426 : : /* Likewise for constant ints. */
5427 : 135 : else if (TREE_CODE (exp) == INTEGER_CST)
5428 : 135 : exp = fold_convert (saved_type, exp);
5429 : :
5430 : : }
5431 : :
5432 : : /* Eliminate any conversions since we'll be outputting the underlying
5433 : : constant. */
5434 : 17575889 : while (CONVERT_EXPR_P (exp)
5435 : 17575850 : || TREE_CODE (exp) == NON_LVALUE_EXPR
5436 : 35151771 : || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
5437 : : {
5438 : 3307 : HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
5439 : 3307 : HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
5440 : :
5441 : : /* Make sure eliminating the conversion is really a no-op, except with
5442 : : VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
5443 : : union types to allow for Ada unchecked unions. */
5444 : 3307 : if (type_size > op_size
5445 : 6 : && TREE_CODE (exp) != VIEW_CONVERT_EXPR
5446 : 3313 : && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
5447 : : /* Keep the conversion. */
5448 : : break;
5449 : : else
5450 : 3301 : exp = TREE_OPERAND (exp, 0);
5451 : : }
5452 : :
5453 : 17572620 : code = TREE_CODE (TREE_TYPE (exp));
5454 : 17572620 : thissize = int_size_in_bytes (TREE_TYPE (exp));
5455 : :
5456 : : /* Allow a constructor with no elements for any data type.
5457 : : This means to fill the space with zeros. */
5458 : 17572620 : if (TREE_CODE (exp) == CONSTRUCTOR
5459 : 17572620 : && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp)))
5460 : : {
5461 : 3004 : assemble_zeros (size);
5462 : 3004 : return size;
5463 : : }
5464 : :
5465 : 17569616 : if (TREE_CODE (exp) == FDESC_EXPR)
5466 : : {
5467 : : #ifdef ASM_OUTPUT_FDESC
5468 : : HOST_WIDE_INT part = tree_to_shwi (TREE_OPERAND (exp, 1));
5469 : : tree decl = TREE_OPERAND (exp, 0);
5470 : : ASM_OUTPUT_FDESC (asm_out_file, decl, part);
5471 : : #else
5472 : 0 : gcc_unreachable ();
5473 : : #endif
5474 : : return size;
5475 : : }
5476 : :
5477 : : /* Now output the underlying data. If we've handling the padding, return.
5478 : : Otherwise, break and ensure SIZE is the size written. */
5479 : 17569616 : switch (code)
5480 : : {
5481 : 11924507 : case BOOLEAN_TYPE:
5482 : 11924507 : case INTEGER_TYPE:
5483 : 11924507 : case ENUMERAL_TYPE:
5484 : 11924507 : case POINTER_TYPE:
5485 : 11924507 : case REFERENCE_TYPE:
5486 : 11924507 : case OFFSET_TYPE:
5487 : 11924507 : case FIXED_POINT_TYPE:
5488 : 11924507 : case NULLPTR_TYPE:
5489 : 11924507 : cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
5490 : 11924507 : if (reverse)
5491 : 558 : cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst);
5492 : 11924507 : if (!assemble_integer (cst, MIN (size, thissize), align, 0))
5493 : 0 : error ("initializer for integer/fixed-point value is too complicated");
5494 : : break;
5495 : :
5496 : 580393 : case REAL_TYPE:
5497 : 580393 : gcc_assert (size == thissize);
5498 : 580393 : if (TREE_CODE (exp) != REAL_CST)
5499 : 1 : error ("initializer for floating value is not a floating constant");
5500 : : else
5501 : 580392 : assemble_real (TREE_REAL_CST (exp),
5502 : 580392 : SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (exp)),
5503 : : align, reverse);
5504 : : break;
5505 : :
5506 : 12184 : case COMPLEX_TYPE:
5507 : 12184 : output_constant (TREE_REALPART (exp), thissize / 2, align,
5508 : : reverse, false);
5509 : 12184 : output_constant (TREE_IMAGPART (exp), thissize / 2,
5510 : : min_align (align, BITS_PER_UNIT * (thissize / 2)),
5511 : : reverse, false);
5512 : 12184 : break;
5513 : :
5514 : 7879 : case BITINT_TYPE:
5515 : 7879 : if (TREE_CODE (exp) != INTEGER_CST)
5516 : 0 : error ("initializer for %<_BitInt(%d)%> value is not an integer "
5517 : 0 : "constant", TYPE_PRECISION (TREE_TYPE (exp)));
5518 : : else
5519 : : {
5520 : 7879 : struct bitint_info info;
5521 : 7879 : tree type = TREE_TYPE (exp);
5522 : 7879 : bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
5523 : 7879 : gcc_assert (ok);
5524 : 7879 : scalar_int_mode limb_mode
5525 : 7879 : = as_a <scalar_int_mode> (info.abi_limb_mode);
5526 : 7879 : if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode))
5527 : : {
5528 : 427 : cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
5529 : 427 : if (reverse)
5530 : 0 : cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst);
5531 : 427 : if (!assemble_integer (cst, MIN (size, thissize), align, 0))
5532 : 0 : error ("initializer for integer/fixed-point value is too "
5533 : : "complicated");
5534 : 427 : break;
5535 : : }
5536 : 7452 : int prec = GET_MODE_PRECISION (limb_mode);
5537 : 7452 : int cnt = CEIL (TYPE_PRECISION (type), prec);
5538 : 7452 : tree limb_type = build_nonstandard_integer_type (prec, 1);
5539 : 7452 : int elt_size = GET_MODE_SIZE (limb_mode);
5540 : 7452 : unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (limb_mode));
5541 : 7452 : thissize = 0;
5542 : 7452 : if (prec == HOST_BITS_PER_WIDE_INT)
5543 : 82472 : for (int i = 0; i < cnt; i++)
5544 : : {
5545 : 75020 : int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i;
5546 : 75020 : tree c;
5547 : 75020 : if (idx >= TREE_INT_CST_EXT_NUNITS (exp))
5548 : 16273 : c = build_int_cst (limb_type,
5549 : 30425 : tree_int_cst_sgn (exp) < 0 ? -1 : 0);
5550 : : else
5551 : 58747 : c = build_int_cst (limb_type,
5552 : 58747 : TREE_INT_CST_ELT (exp, idx));
5553 : 75020 : output_constant (c, elt_size, nalign, reverse, false);
5554 : 75020 : thissize += elt_size;
5555 : : }
5556 : : else
5557 : 0 : for (int i = 0; i < cnt; i++)
5558 : : {
5559 : 0 : int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i;
5560 : 0 : wide_int w = wi::rshift (wi::to_wide (exp), idx * prec,
5561 : 0 : TYPE_SIGN (TREE_TYPE (exp)));
5562 : 0 : tree c = wide_int_to_tree (limb_type,
5563 : 0 : wide_int::from (w, prec, UNSIGNED));
5564 : 0 : output_constant (c, elt_size, nalign, reverse, false);
5565 : 0 : thissize += elt_size;
5566 : 0 : }
5567 : : }
5568 : : break;
5569 : :
5570 : 1872382 : case ARRAY_TYPE:
5571 : 1872382 : case VECTOR_TYPE:
5572 : 1872382 : switch (TREE_CODE (exp))
5573 : : {
5574 : 558827 : case CONSTRUCTOR:
5575 : 558827 : return output_constructor (exp, size, align, reverse, NULL);
5576 : 1301500 : case STRING_CST:
5577 : 1301500 : thissize = (unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp);
5578 : 1301500 : if (merge_strings
5579 : 1301500 : && (thissize == 0
5580 : 390479 : || TREE_STRING_POINTER (exp) [thissize - 1] != '\0'))
5581 : 33542 : thissize++;
5582 : 1301500 : gcc_checking_assert (check_string_literal (exp, size));
5583 : 1301500 : assemble_string (TREE_STRING_POINTER (exp), thissize);
5584 : 1301500 : break;
5585 : 12055 : case VECTOR_CST:
5586 : 12055 : {
5587 : 12055 : scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
5588 : 12055 : unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
5589 : 12055 : int elt_size = GET_MODE_SIZE (inner);
5590 : 12055 : output_constant (VECTOR_CST_ELT (exp, 0), elt_size, align,
5591 : : reverse, false);
5592 : 12055 : thissize = elt_size;
5593 : : /* Static constants must have a fixed size. */
5594 : 12055 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
5595 : 67932 : for (unsigned int i = 1; i < nunits; i++)
5596 : : {
5597 : 55877 : output_constant (VECTOR_CST_ELT (exp, i), elt_size, nalign,
5598 : : reverse, false);
5599 : 55877 : thissize += elt_size;
5600 : : }
5601 : : break;
5602 : : }
5603 : 0 : default:
5604 : 0 : gcc_unreachable ();
5605 : : }
5606 : : break;
5607 : :
5608 : 3172271 : case RECORD_TYPE:
5609 : 3172271 : case UNION_TYPE:
5610 : 3172271 : gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
5611 : 3172271 : return output_constructor (exp, size, align, reverse, NULL);
5612 : :
5613 : : case ERROR_MARK:
5614 : : return 0;
5615 : :
5616 : 0 : default:
5617 : 0 : gcc_unreachable ();
5618 : : }
5619 : :
5620 : 13838518 : if (size > thissize)
5621 : 714094 : assemble_zeros (size - thissize);
5622 : :
5623 : : return size;
5624 : : }
5625 : :
5626 : : /* Subroutine of output_constructor, used for computing the size of
5627 : : arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
5628 : : type with an unspecified upper bound. */
5629 : :
5630 : : static unsigned HOST_WIDE_INT
5631 : 5102 : array_size_for_constructor (tree val)
5632 : : {
5633 : 5102 : tree max_index;
5634 : 5102 : unsigned HOST_WIDE_INT cnt;
5635 : 5102 : tree index, value, tmp;
5636 : 5102 : offset_int i;
5637 : :
5638 : : /* This code used to attempt to handle string constants that are not
5639 : : arrays of single-bytes, but nothing else does, so there's no point in
5640 : : doing it here. */
5641 : 5102 : if (TREE_CODE (val) == STRING_CST)
5642 : 4939 : return TREE_STRING_LENGTH (val);
5643 : :
5644 : : max_index = NULL_TREE;
5645 : 458 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
5646 : : {
5647 : 295 : if (TREE_CODE (index) == RANGE_EXPR)
5648 : 0 : index = TREE_OPERAND (index, 1);
5649 : 295 : if (value && TREE_CODE (value) == RAW_DATA_CST)
5650 : 8 : index = size_binop (PLUS_EXPR, index,
5651 : : build_int_cst (TREE_TYPE (index),
5652 : : RAW_DATA_LENGTH (value) - 1));
5653 : 295 : if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
5654 : : max_index = index;
5655 : : }
5656 : :
5657 : 163 : if (max_index == NULL_TREE)
5658 : : return 0;
5659 : :
5660 : : /* Compute the total number of array elements. */
5661 : 129 : tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
5662 : 129 : i = wi::to_offset (max_index) - wi::to_offset (tmp) + 1;
5663 : :
5664 : : /* Multiply by the array element unit size to find number of bytes. */
5665 : 129 : i *= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
5666 : :
5667 : 129 : gcc_assert (wi::fits_uhwi_p (i));
5668 : 129 : return i.to_uhwi ();
5669 : : }
5670 : :
5671 : : /* Other datastructures + helpers for output_constructor. */
5672 : :
5673 : : /* output_constructor local state to support interaction with helpers. */
5674 : :
5675 : : struct oc_local_state {
5676 : :
5677 : : /* Received arguments. */
5678 : : tree exp; /* Constructor expression. */
5679 : : tree type; /* Type of constructor expression. */
5680 : : unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
5681 : : unsigned int align; /* Known initial alignment. */
5682 : : tree min_index; /* Lower bound if specified for an array. */
5683 : :
5684 : : /* Output processing state. */
5685 : : HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
5686 : : int byte; /* Part of a bitfield byte yet to be output. */
5687 : : int last_relative_index; /* Implicit or explicit index of the last
5688 : : array element output within a bitfield. */
5689 : : bool byte_buffer_in_use; /* Whether BYTE is in use. */
5690 : : bool reverse; /* Whether reverse storage order is in use. */
5691 : :
5692 : : /* Current element. */
5693 : : tree field; /* Current field decl in a record. */
5694 : : tree val; /* Current element value. */
5695 : : tree index; /* Current element index. */
5696 : :
5697 : : };
5698 : :
5699 : : /* Helper for output_constructor. From the current LOCAL state, output a
5700 : : RANGE_EXPR element. */
5701 : :
5702 : : static void
5703 : 783 : output_constructor_array_range (oc_local_state *local)
5704 : : {
5705 : : /* Perform the index calculation in modulo arithmetic but
5706 : : sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5707 : : but we are using an unsigned sizetype. */
5708 : 783 : unsigned prec = TYPE_PRECISION (sizetype);
5709 : 783 : offset_int idx = wi::sext (wi::to_offset (TREE_OPERAND (local->index, 0))
5710 : 1566 : - wi::to_offset (local->min_index), prec);
5711 : 783 : tree valtype = TREE_TYPE (local->val);
5712 : 783 : HOST_WIDE_INT fieldpos
5713 : 783 : = (idx * wi::to_offset (TYPE_SIZE_UNIT (valtype))).to_short_addr ();
5714 : :
5715 : : /* Advance to offset of this element. */
5716 : 783 : if (fieldpos > local->total_bytes)
5717 : : {
5718 : 8 : assemble_zeros (fieldpos - local->total_bytes);
5719 : 8 : local->total_bytes = fieldpos;
5720 : : }
5721 : : else
5722 : : /* Must not go backwards. */
5723 : 775 : gcc_assert (fieldpos == local->total_bytes);
5724 : :
5725 : 783 : unsigned HOST_WIDE_INT fieldsize
5726 : 783 : = int_size_in_bytes (TREE_TYPE (local->type));
5727 : :
5728 : 783 : HOST_WIDE_INT lo_index
5729 : 783 : = tree_to_shwi (TREE_OPERAND (local->index, 0));
5730 : 783 : HOST_WIDE_INT hi_index
5731 : 783 : = tree_to_shwi (TREE_OPERAND (local->index, 1));
5732 : 783 : HOST_WIDE_INT index;
5733 : :
5734 : 783 : unsigned int align2
5735 : 783 : = min_align (local->align, fieldsize * BITS_PER_UNIT);
5736 : :
5737 : 274729 : for (index = lo_index; index <= hi_index; index++)
5738 : : {
5739 : : /* Output the element's initial value. */
5740 : 273946 : if (local->val == NULL_TREE)
5741 : 0 : assemble_zeros (fieldsize);
5742 : : else
5743 : 273946 : fieldsize = output_constant (local->val, fieldsize, align2,
5744 : 273946 : local->reverse, false);
5745 : :
5746 : : /* Count its size. */
5747 : 273946 : local->total_bytes += fieldsize;
5748 : : }
5749 : 783 : }
5750 : :
5751 : : /* Helper for output_constructor. From the current LOCAL state, output a
5752 : : field element that is not true bitfield or part of an outer one. */
5753 : :
5754 : : static void
5755 : 14091818 : output_constructor_regular_field (oc_local_state *local)
5756 : : {
5757 : : /* Field size and position. Since this structure is static, we know the
5758 : : positions are constant. */
5759 : 14091818 : unsigned HOST_WIDE_INT fieldsize;
5760 : 14091818 : HOST_WIDE_INT fieldpos;
5761 : :
5762 : 14091818 : unsigned int align2;
5763 : :
5764 : : /* Output any buffered-up bit-fields preceding this element. */
5765 : 14091818 : if (local->byte_buffer_in_use)
5766 : : {
5767 : 134 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5768 : 134 : local->total_bytes++;
5769 : 134 : local->byte_buffer_in_use = false;
5770 : : }
5771 : :
5772 : 14091818 : if (local->index != NULL_TREE)
5773 : : {
5774 : : /* Perform the index calculation in modulo arithmetic but
5775 : : sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5776 : : but we are using an unsigned sizetype. */
5777 : 3878398 : unsigned prec = TYPE_PRECISION (sizetype);
5778 : 3878398 : offset_int idx = wi::sext (wi::to_offset (local->index)
5779 : 7756796 : - wi::to_offset (local->min_index), prec);
5780 : 3878398 : fieldpos = (idx * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local->val))))
5781 : 3878398 : .to_short_addr ();
5782 : : }
5783 : 10213420 : else if (local->field != NULL_TREE)
5784 : 9446937 : fieldpos = int_byte_position (local->field);
5785 : : else
5786 : : fieldpos = 0;
5787 : :
5788 : : /* Advance to offset of this element.
5789 : : Note no alignment needed in an array, since that is guaranteed
5790 : : if each element has the proper size. */
5791 : 14091818 : if (local->field != NULL_TREE || local->index != NULL_TREE)
5792 : : {
5793 : 13325335 : if (fieldpos > local->total_bytes)
5794 : : {
5795 : 176195 : assemble_zeros (fieldpos - local->total_bytes);
5796 : 176195 : local->total_bytes = fieldpos;
5797 : : }
5798 : : else
5799 : : /* Must not go backwards. */
5800 : 13149140 : gcc_assert (fieldpos == local->total_bytes);
5801 : : }
5802 : :
5803 : : /* Find the alignment of this element. */
5804 : 14091818 : align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5805 : :
5806 : : /* Determine size this element should occupy. */
5807 : 14091818 : if (local->field)
5808 : : {
5809 : 9446937 : fieldsize = 0;
5810 : :
5811 : : /* If this is an array with an unspecified upper bound,
5812 : : the initializer determines the size. */
5813 : : /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5814 : : but we cannot do this until the deprecated support for
5815 : : initializing zero-length array members is removed. */
5816 : 9446937 : if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5817 : 9446937 : && (!TYPE_DOMAIN (TREE_TYPE (local->field))
5818 : 179938 : || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field)))))
5819 : : {
5820 : 5102 : unsigned HOST_WIDE_INT fldsize
5821 : 5102 : = array_size_for_constructor (local->val);
5822 : 5102 : fieldsize = int_size_in_bytes (TREE_TYPE (local->val));
5823 : : /* In most cases fieldsize == fldsize as the size of the initializer
5824 : : determines how many elements the flexible array member has. For
5825 : : C++ fldsize can be smaller though, if the last or several last or
5826 : : all initializers of the flexible array member have side-effects
5827 : : and the FE splits them into dynamic initialization. */
5828 : 5102 : gcc_checking_assert (fieldsize >= fldsize);
5829 : : /* Given a non-empty initialization, this field had better
5830 : : be last. Given a flexible array member, the next field
5831 : : on the chain is a TYPE_DECL of the enclosing struct. */
5832 : 5102 : const_tree next = DECL_CHAIN (local->field);
5833 : 5102 : gcc_assert (!fieldsize || !next || TREE_CODE (next) != FIELD_DECL);
5834 : : }
5835 : : else
5836 : 9441835 : fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field));
5837 : : }
5838 : : else
5839 : 4644881 : fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5840 : :
5841 : : /* Output the element's initial value. */
5842 : 14091818 : if (local->val == NULL_TREE)
5843 : 0 : assemble_zeros (fieldsize);
5844 : 14091818 : else if (local->val && TREE_CODE (local->val) == RAW_DATA_CST)
5845 : : {
5846 : 385 : fieldsize *= RAW_DATA_LENGTH (local->val);
5847 : 385 : assemble_string (RAW_DATA_POINTER (local->val),
5848 : 385 : RAW_DATA_LENGTH (local->val));
5849 : : }
5850 : : else
5851 : 14091433 : fieldsize = output_constant (local->val, fieldsize, align2,
5852 : 14091433 : local->reverse, false);
5853 : :
5854 : : /* Count its size. */
5855 : 14091818 : local->total_bytes += fieldsize;
5856 : 14091818 : }
5857 : :
5858 : : /* Helper for output_constructor. From the LOCAL state, output an element
5859 : : that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5860 : : from the start of a possibly ongoing outer byte buffer. */
5861 : :
5862 : : static void
5863 : 5837 : output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset)
5864 : : {
5865 : : /* Bit size of this element. */
5866 : 5837 : HOST_WIDE_INT ebitsize
5867 : 5837 : = (local->field
5868 : 5837 : ? tree_to_uhwi (DECL_SIZE (local->field))
5869 : 0 : : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local->type))));
5870 : :
5871 : : /* Relative index of this element if this is an array component. */
5872 : 11674 : HOST_WIDE_INT relative_index
5873 : : = (local->field
5874 : 5837 : ? 0
5875 : 0 : : (local->index
5876 : 0 : ? tree_to_uhwi (local->index) - tree_to_uhwi (local->min_index)
5877 : 0 : : local->last_relative_index + 1));
5878 : :
5879 : : /* Bit position of this element from the start of the containing
5880 : : constructor. */
5881 : 5837 : HOST_WIDE_INT constructor_relative_ebitpos
5882 : : = (local->field
5883 : 5837 : ? int_bit_position (local->field)
5884 : 5837 : : ebitsize * relative_index);
5885 : :
5886 : : /* Bit position of this element from the start of a possibly ongoing
5887 : : outer byte buffer. */
5888 : 5837 : HOST_WIDE_INT byte_relative_ebitpos
5889 : 5837 : = bit_offset + constructor_relative_ebitpos;
5890 : :
5891 : : /* From the start of a possibly ongoing outer byte buffer, offsets to
5892 : : the first bit of this element and to the first bit past the end of
5893 : : this element. */
5894 : 5837 : HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5895 : 5837 : HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5896 : :
5897 : 5837 : local->last_relative_index = relative_index;
5898 : :
5899 : 5837 : if (local->val == NULL_TREE)
5900 : 0 : local->val = integer_zero_node;
5901 : :
5902 : 5837 : while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5903 : 5837 : || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5904 : 0 : local->val = TREE_OPERAND (local->val, 0);
5905 : :
5906 : 5837 : if (TREE_CODE (local->val) != INTEGER_CST
5907 : 0 : && TREE_CODE (local->val) != CONSTRUCTOR)
5908 : : {
5909 : 0 : error ("invalid initial value for member %qE", DECL_NAME (local->field));
5910 : 0 : return;
5911 : : }
5912 : :
5913 : : /* If this field does not start in this (or next) byte, skip some bytes. */
5914 : 5837 : if (next_offset / BITS_PER_UNIT != local->total_bytes)
5915 : : {
5916 : : /* Output remnant of any bit field in previous bytes. */
5917 : 1248 : if (local->byte_buffer_in_use)
5918 : : {
5919 : 1223 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5920 : 1223 : local->total_bytes++;
5921 : 1223 : local->byte_buffer_in_use = false;
5922 : : }
5923 : :
5924 : : /* If still not at proper byte, advance to there. */
5925 : 1248 : if (next_offset / BITS_PER_UNIT != local->total_bytes)
5926 : : {
5927 : 104 : gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5928 : 104 : assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5929 : 104 : local->total_bytes = next_offset / BITS_PER_UNIT;
5930 : : }
5931 : : }
5932 : :
5933 : : /* Set up the buffer if necessary. */
5934 : 5837 : if (!local->byte_buffer_in_use)
5935 : : {
5936 : 3325 : local->byte = 0;
5937 : 3325 : if (ebitsize > 0)
5938 : 3325 : local->byte_buffer_in_use = true;
5939 : : }
5940 : :
5941 : : /* If this is nested constructor, recurse passing the bit offset and the
5942 : : pending data, then retrieve the new pending data afterwards. */
5943 : 5837 : if (TREE_CODE (local->val) == CONSTRUCTOR)
5944 : : {
5945 : 0 : oc_outer_state temp_state;
5946 : 0 : temp_state.bit_offset = next_offset % BITS_PER_UNIT;
5947 : 0 : temp_state.byte = local->byte;
5948 : 0 : local->total_bytes
5949 : 0 : += output_constructor (local->val, 0, 0, local->reverse, &temp_state);
5950 : 0 : local->byte = temp_state.byte;
5951 : 0 : return;
5952 : : }
5953 : :
5954 : : /* Otherwise, we must split the element into pieces that fall within
5955 : : separate bytes, and combine each byte with previous or following
5956 : : bit-fields. */
5957 : 22358 : while (next_offset < end_offset)
5958 : : {
5959 : 16521 : int this_time;
5960 : 16521 : int shift;
5961 : 16521 : unsigned HOST_WIDE_INT value;
5962 : 16521 : HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
5963 : 16521 : HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
5964 : :
5965 : : /* Advance from byte to byte within this element when necessary. */
5966 : 26989 : while (next_byte != local->total_bytes)
5967 : : {
5968 : 10468 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5969 : 10468 : local->total_bytes++;
5970 : 10468 : local->byte = 0;
5971 : : }
5972 : :
5973 : : /* Number of bits we can process at once (all part of the same byte). */
5974 : 16521 : this_time = MIN (end_offset - next_offset, BITS_PER_UNIT - next_bit);
5975 : 16521 : if (local->reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
5976 : : {
5977 : : /* For big-endian data, take the most significant bits (of the
5978 : : bits that are significant) first and put them into bytes from
5979 : : the most significant end. */
5980 : 778 : shift = end_offset - next_offset - this_time;
5981 : :
5982 : : /* Don't try to take a bunch of bits that cross
5983 : : the word boundary in the INTEGER_CST. We can
5984 : : only select bits from one element. */
5985 : 778 : if ((shift / HOST_BITS_PER_WIDE_INT)
5986 : 778 : != ((shift + this_time - 1) / HOST_BITS_PER_WIDE_INT))
5987 : : {
5988 : 0 : const int end = shift + this_time - 1;
5989 : 0 : shift = end & -HOST_BITS_PER_WIDE_INT;
5990 : 0 : this_time = end - shift + 1;
5991 : : }
5992 : :
5993 : : /* Now get the bits we want to insert. */
5994 : 778 : value = wi::extract_uhwi (wi::to_widest (local->val),
5995 : : shift, this_time);
5996 : :
5997 : : /* Get the result. This works only when:
5998 : : 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
5999 : 778 : local->byte |= value << (BITS_PER_UNIT - this_time - next_bit);
6000 : : }
6001 : : else
6002 : : {
6003 : : /* On little-endian machines, take the least significant bits of
6004 : : the value first and pack them starting at the least significant
6005 : : bits of the bytes. */
6006 : 15743 : shift = next_offset - byte_relative_ebitpos;
6007 : :
6008 : : /* Don't try to take a bunch of bits that cross
6009 : : the word boundary in the INTEGER_CST. We can
6010 : : only select bits from one element. */
6011 : 15743 : if ((shift / HOST_BITS_PER_WIDE_INT)
6012 : 15743 : != ((shift + this_time - 1) / HOST_BITS_PER_WIDE_INT))
6013 : 216 : this_time
6014 : 216 : = HOST_BITS_PER_WIDE_INT - (shift & (HOST_BITS_PER_WIDE_INT - 1));
6015 : :
6016 : : /* Now get the bits we want to insert. */
6017 : 15743 : value = wi::extract_uhwi (wi::to_widest (local->val),
6018 : : shift, this_time);
6019 : :
6020 : : /* Get the result. This works only when:
6021 : : 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
6022 : 15743 : local->byte |= value << next_bit;
6023 : : }
6024 : :
6025 : 16521 : next_offset += this_time;
6026 : 16521 : local->byte_buffer_in_use = true;
6027 : : }
6028 : : }
6029 : :
6030 : : /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
6031 : : Generate at least SIZE bytes, padding if necessary. OUTER designates the
6032 : : caller output state of relevance in recursive invocations. */
6033 : :
6034 : : static unsigned HOST_WIDE_INT
6035 : 3731098 : output_constructor (tree exp, unsigned HOST_WIDE_INT size, unsigned int align,
6036 : : bool reverse, oc_outer_state *outer)
6037 : : {
6038 : 3731098 : unsigned HOST_WIDE_INT cnt;
6039 : 3731098 : constructor_elt *ce;
6040 : 3731098 : oc_local_state local;
6041 : :
6042 : : /* Setup our local state to communicate with helpers. */
6043 : 3731098 : local.exp = exp;
6044 : 3731098 : local.type = TREE_TYPE (exp);
6045 : 3731098 : local.size = size;
6046 : 3731098 : local.align = align;
6047 : 3731098 : if (TREE_CODE (local.type) == ARRAY_TYPE && TYPE_DOMAIN (local.type))
6048 : 558827 : local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
6049 : : else
6050 : 3172271 : local.min_index = integer_zero_node;
6051 : :
6052 : 3731098 : local.total_bytes = 0;
6053 : 3731098 : local.byte_buffer_in_use = outer != NULL;
6054 : 3731098 : local.byte = outer ? outer->byte : 0;
6055 : 3731098 : local.last_relative_index = -1;
6056 : : /* The storage order is specified for every aggregate type. */
6057 : 3731098 : if (AGGREGATE_TYPE_P (local.type))
6058 : 3731098 : local.reverse = TYPE_REVERSE_STORAGE_ORDER (local.type);
6059 : : else
6060 : 0 : local.reverse = reverse;
6061 : :
6062 : 3731098 : gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
6063 : :
6064 : : /* As CE goes through the elements of the constant, FIELD goes through the
6065 : : structure fields if the constant is a structure. If the constant is a
6066 : : union, we override this by getting the field from the TREE_LIST element.
6067 : : But the constant could also be an array. Then FIELD is zero.
6068 : :
6069 : : There is always a maximum of one element in the chain LINK for unions
6070 : : (even if the initializer in a source program incorrectly contains
6071 : : more one). */
6072 : :
6073 : 3731098 : if (TREE_CODE (local.type) == RECORD_TYPE)
6074 : 3154643 : local.field = TYPE_FIELDS (local.type);
6075 : : else
6076 : 576455 : local.field = NULL_TREE;
6077 : :
6078 : : for (cnt = 0;
6079 : 17829536 : vec_safe_iterate (CONSTRUCTOR_ELTS (exp), cnt, &ce);
6080 : 14098438 : cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
6081 : : {
6082 : 14098438 : local.val = ce->value;
6083 : 14098438 : local.index = NULL_TREE;
6084 : :
6085 : : /* The element in a union constructor specifies the proper field
6086 : : or index. */
6087 : 14098438 : if (RECORD_OR_UNION_TYPE_P (local.type) && ce->index != NULL_TREE)
6088 : 9264443 : local.field = ce->index;
6089 : :
6090 : 4833995 : else if (TREE_CODE (local.type) == ARRAY_TYPE)
6091 : 4645664 : local.index = ce->index;
6092 : :
6093 : 14098438 : if (local.field && flag_verbose_asm)
6094 : 0 : fprintf (asm_out_file, "%s %s:\n",
6095 : : ASM_COMMENT_START,
6096 : 0 : DECL_NAME (local.field)
6097 : 0 : ? IDENTIFIER_POINTER (DECL_NAME (local.field))
6098 : : : "<anonymous>");
6099 : :
6100 : : /* Eliminate the marker that makes a cast not be an lvalue. */
6101 : 14098438 : if (local.val != NULL_TREE)
6102 : 14098438 : STRIP_NOPS (local.val);
6103 : :
6104 : : /* Output the current element, using the appropriate helper ... */
6105 : :
6106 : : /* For an array slice not part of an outer bitfield. */
6107 : 14098438 : if (!outer
6108 : 14098438 : && local.index != NULL_TREE
6109 : 3879181 : && TREE_CODE (local.index) == RANGE_EXPR)
6110 : 783 : output_constructor_array_range (&local);
6111 : :
6112 : : /* For a field that is neither a true bitfield nor part of an outer one,
6113 : : known to be at least byte aligned and multiple-of-bytes long. */
6114 : 14097655 : else if (!outer
6115 : 14097655 : && (local.field == NULL_TREE
6116 : 9452774 : || !CONSTRUCTOR_BITFIELD_P (local.field)))
6117 : 14091818 : output_constructor_regular_field (&local);
6118 : :
6119 : : /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
6120 : : supported for scalar fields, so we may need to convert first. */
6121 : : else
6122 : : {
6123 : 5837 : if (TREE_CODE (local.val) == REAL_CST)
6124 : 0 : local.val
6125 : 0 : = fold_unary (VIEW_CONVERT_EXPR,
6126 : : build_nonstandard_integer_type
6127 : : (TYPE_PRECISION (TREE_TYPE (local.val)), 0),
6128 : : local.val);
6129 : 5837 : output_constructor_bitfield (&local, outer ? outer->bit_offset : 0);
6130 : : }
6131 : : }
6132 : :
6133 : : /* If we are not at toplevel, save the pending data for our caller.
6134 : : Otherwise output the pending data and padding zeros as needed. */
6135 : 3731098 : if (outer)
6136 : 0 : outer->byte = local.byte;
6137 : : else
6138 : : {
6139 : 3731098 : if (local.byte_buffer_in_use)
6140 : : {
6141 : 1968 : assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
6142 : 1968 : local.total_bytes++;
6143 : : }
6144 : :
6145 : 3731098 : if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
6146 : : {
6147 : 55866 : assemble_zeros (local.size - local.total_bytes);
6148 : 55866 : local.total_bytes = local.size;
6149 : : }
6150 : : }
6151 : :
6152 : 3731098 : return local.total_bytes;
6153 : : }
6154 : :
6155 : : /* Mark DECL as weak. */
6156 : :
6157 : : static void
6158 : 111645 : mark_weak (tree decl)
6159 : : {
6160 : 111645 : if (DECL_WEAK (decl))
6161 : : return;
6162 : :
6163 : 111631 : struct symtab_node *n = symtab_node::get (decl);
6164 : 111631 : if (n && n->refuse_visibility_changes)
6165 : 3 : error ("%qD declared weak after being used", decl);
6166 : 111631 : DECL_WEAK (decl) = 1;
6167 : :
6168 : 111631 : if (DECL_RTL_SET_P (decl)
6169 : 0 : && MEM_P (DECL_RTL (decl))
6170 : 0 : && XEXP (DECL_RTL (decl), 0)
6171 : 111631 : && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
6172 : 0 : SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
6173 : : }
6174 : :
6175 : : /* Merge weak status between NEWDECL and OLDDECL. */
6176 : :
6177 : : void
6178 : 18260081 : merge_weak (tree newdecl, tree olddecl)
6179 : : {
6180 : 18260081 : if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
6181 : : {
6182 : 18250224 : if (DECL_WEAK (newdecl) && TARGET_SUPPORTS_WEAK)
6183 : : {
6184 : : tree *pwd;
6185 : : /* We put the NEWDECL on the weak_decls list at some point
6186 : : and OLDDECL as well. Keep just OLDDECL on the list. */
6187 : 158 : for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
6188 : 0 : if (TREE_VALUE (*pwd) == newdecl)
6189 : : {
6190 : 0 : *pwd = TREE_CHAIN (*pwd);
6191 : 0 : break;
6192 : : }
6193 : : }
6194 : 18250224 : return;
6195 : : }
6196 : :
6197 : 9857 : if (DECL_WEAK (newdecl))
6198 : : {
6199 : 291 : tree wd;
6200 : :
6201 : : /* NEWDECL is weak, but OLDDECL is not. */
6202 : :
6203 : : /* If we already output the OLDDECL, we're in trouble; we can't
6204 : : go back and make it weak. This should never happen in
6205 : : unit-at-a-time compilation. */
6206 : 291 : gcc_assert (!TREE_ASM_WRITTEN (olddecl));
6207 : :
6208 : : /* If we've already generated rtl referencing OLDDECL, we may
6209 : : have done so in a way that will not function properly with
6210 : : a weak symbol. Again in unit-at-a-time this should be
6211 : : impossible. */
6212 : 291 : gcc_assert (!TREE_USED (olddecl)
6213 : : || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
6214 : :
6215 : : /* PR 49899: You cannot convert a static function into a weak, public function. */
6216 : 291 : if (! TREE_PUBLIC (olddecl) && TREE_PUBLIC (newdecl))
6217 : 1 : error ("weak declaration of %q+D being applied to a already "
6218 : : "existing, static definition", newdecl);
6219 : :
6220 : 291 : if (TARGET_SUPPORTS_WEAK)
6221 : : {
6222 : : /* We put the NEWDECL on the weak_decls list at some point.
6223 : : Replace it with the OLDDECL. */
6224 : 291 : for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
6225 : 0 : if (TREE_VALUE (wd) == newdecl)
6226 : : {
6227 : 0 : TREE_VALUE (wd) = olddecl;
6228 : 0 : break;
6229 : : }
6230 : : /* We may not find the entry on the list. If NEWDECL is a
6231 : : weak alias, then we will have already called
6232 : : globalize_decl to remove the entry; in that case, we do
6233 : : not need to do anything. */
6234 : : }
6235 : :
6236 : : /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
6237 : 291 : mark_weak (olddecl);
6238 : : }
6239 : : else
6240 : : /* OLDDECL was weak, but NEWDECL was not explicitly marked as
6241 : : weak. Just update NEWDECL to indicate that it's weak too. */
6242 : 9566 : mark_weak (newdecl);
6243 : : }
6244 : :
6245 : : /* Declare DECL to be a weak symbol. */
6246 : :
6247 : : void
6248 : 101793 : declare_weak (tree decl)
6249 : : {
6250 : : /* With -fsyntax-only, TREE_ASM_WRITTEN might be set on certain function
6251 : : decls earlier than normally, but as with -fsyntax-only nothing is really
6252 : : emitted, there is no harm in marking it weak later. */
6253 : 101793 : gcc_assert (TREE_CODE (decl) != FUNCTION_DECL
6254 : : || !TREE_ASM_WRITTEN (decl)
6255 : : || flag_syntax_only);
6256 : 101793 : if (! TREE_PUBLIC (decl))
6257 : : {
6258 : 5 : error ("weak declaration of %q+D must be public", decl);
6259 : 5 : return;
6260 : : }
6261 : 101788 : else if (!TARGET_SUPPORTS_WEAK)
6262 : : warning (0, "weak declaration of %q+D not supported", decl);
6263 : :
6264 : 101788 : mark_weak (decl);
6265 : 101788 : if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
6266 : 101774 : DECL_ATTRIBUTES (decl)
6267 : 203548 : = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
6268 : : }
6269 : :
6270 : : static void
6271 : 948 : weak_finish_1 (tree decl)
6272 : : {
6273 : : #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
6274 : 948 : const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6275 : : #endif
6276 : :
6277 : 948 : if (! TREE_USED (decl))
6278 : : return;
6279 : :
6280 : : #ifdef ASM_WEAKEN_DECL
6281 : : ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
6282 : : #else
6283 : : #ifdef ASM_WEAKEN_LABEL
6284 : 948 : ASM_WEAKEN_LABEL (asm_out_file, name);
6285 : : #else
6286 : : #ifdef ASM_OUTPUT_WEAK_ALIAS
6287 : : {
6288 : : static bool warn_once = 0;
6289 : : if (! warn_once)
6290 : : {
6291 : : warning (0, "only weak aliases are supported in this configuration");
6292 : : warn_once = 1;
6293 : : }
6294 : : return;
6295 : : }
6296 : : #endif
6297 : : #endif
6298 : : #endif
6299 : : }
6300 : :
6301 : : /* Fiven an assembly name, find the decl it is associated with. */
6302 : : static tree
6303 : 0 : find_decl (tree target)
6304 : : {
6305 : 0 : symtab_node *node = symtab_node::get_for_asmname (target);
6306 : 0 : if (node)
6307 : 0 : return node->decl;
6308 : : return NULL_TREE;
6309 : : }
6310 : :
6311 : : /* This TREE_LIST contains weakref targets. */
6312 : :
6313 : : static GTY(()) tree weakref_targets;
6314 : :
6315 : : /* Emit any pending weak declarations. */
6316 : :
6317 : : void
6318 : 225316 : weak_finish (void)
6319 : : {
6320 : 225316 : tree t;
6321 : :
6322 : 225416 : for (t = weakref_targets; t; t = TREE_CHAIN (t))
6323 : : {
6324 : 100 : tree alias_decl = TREE_PURPOSE (t);
6325 : 100 : tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
6326 : :
6327 : 100 : if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl))
6328 : 200 : || TREE_SYMBOL_REFERENCED (target))
6329 : : /* Remove alias_decl from the weak list, but leave entries for
6330 : : the target alone. */
6331 : : target = NULL_TREE;
6332 : : #ifndef ASM_OUTPUT_WEAKREF
6333 : : else if (! TREE_SYMBOL_REFERENCED (target))
6334 : : {
6335 : : /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
6336 : : defined, otherwise we and weak_finish_1 would use
6337 : : different macros. */
6338 : : # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
6339 : : ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
6340 : : # else
6341 : : tree decl = find_decl (target);
6342 : :
6343 : : if (! decl)
6344 : : {
6345 : : decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
6346 : : TREE_CODE (alias_decl), target,
6347 : : TREE_TYPE (alias_decl));
6348 : :
6349 : : DECL_EXTERNAL (decl) = 1;
6350 : : TREE_PUBLIC (decl) = 1;
6351 : : DECL_ARTIFICIAL (decl) = 1;
6352 : : TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
6353 : : TREE_USED (decl) = 1;
6354 : : }
6355 : :
6356 : : weak_finish_1 (decl);
6357 : : # endif
6358 : : }
6359 : : #endif
6360 : :
6361 : 100 : {
6362 : 100 : tree *p;
6363 : 100 : tree t2;
6364 : :
6365 : : /* Remove the alias and the target from the pending weak list
6366 : : so that we do not emit any .weak directives for the former,
6367 : : nor multiple .weak directives for the latter. */
6368 : 168 : for (p = &weak_decls; (t2 = *p) ; )
6369 : : {
6370 : 68 : if (TREE_VALUE (t2) == alias_decl
6371 : 68 : || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
6372 : 0 : *p = TREE_CHAIN (t2);
6373 : : else
6374 : 68 : p = &TREE_CHAIN (t2);
6375 : : }
6376 : :
6377 : : /* Remove other weakrefs to the same target, to speed things up. */
6378 : 212 : for (p = &TREE_CHAIN (t); (t2 = *p) ; )
6379 : : {
6380 : 112 : if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
6381 : 0 : *p = TREE_CHAIN (t2);
6382 : : else
6383 : 112 : p = &TREE_CHAIN (t2);
6384 : : }
6385 : : }
6386 : : }
6387 : :
6388 : 226264 : for (t = weak_decls; t; t = TREE_CHAIN (t))
6389 : : {
6390 : 948 : tree decl = TREE_VALUE (t);
6391 : :
6392 : 948 : weak_finish_1 (decl);
6393 : : }
6394 : 225316 : }
6395 : :
6396 : : /* Emit the assembly bits to indicate that DECL is globally visible. */
6397 : :
6398 : : static void
6399 : 2612906 : globalize_decl (tree decl)
6400 : : {
6401 : :
6402 : : #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
6403 : 2612906 : if (DECL_WEAK (decl))
6404 : : {
6405 : 513216 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6406 : 513216 : tree *p, t;
6407 : :
6408 : : #ifdef ASM_WEAKEN_DECL
6409 : : ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
6410 : : #else
6411 : 513216 : ASM_WEAKEN_LABEL (asm_out_file, name);
6412 : : #endif
6413 : :
6414 : : /* Remove this function from the pending weak list so that
6415 : : we do not emit multiple .weak directives for it. */
6416 : 1030020 : for (p = &weak_decls; (t = *p) ; )
6417 : : {
6418 : 3588 : if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
6419 : 0 : *p = TREE_CHAIN (t);
6420 : : else
6421 : 3588 : p = &TREE_CHAIN (t);
6422 : : }
6423 : :
6424 : : /* Remove weakrefs to the same target from the pending weakref
6425 : : list, for the same reason. */
6426 : 513216 : for (p = &weakref_targets; (t = *p) ; )
6427 : : {
6428 : 0 : if (DECL_ASSEMBLER_NAME (decl)
6429 : 0 : == ultimate_transparent_alias_target (&TREE_VALUE (t)))
6430 : 0 : *p = TREE_CHAIN (t);
6431 : : else
6432 : 0 : p = &TREE_CHAIN (t);
6433 : : }
6434 : :
6435 : : return;
6436 : : }
6437 : : #endif
6438 : :
6439 : 2099690 : targetm.asm_out.globalize_decl_name (asm_out_file, decl);
6440 : : }
6441 : :
6442 : : vec<alias_pair, va_gc> *alias_pairs;
6443 : :
6444 : : /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
6445 : : or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
6446 : : tree node is DECL to have the value of the tree node TARGET. */
6447 : :
6448 : : void
6449 : 64044 : do_assemble_alias (tree decl, tree target)
6450 : : {
6451 : 64044 : tree id;
6452 : :
6453 : : /* Emulated TLS had better not get this var. */
6454 : 64044 : gcc_assert (!(!targetm.have_tls
6455 : : && VAR_P (decl)
6456 : : && DECL_THREAD_LOCAL_P (decl)));
6457 : :
6458 : 64044 : if (TREE_ASM_WRITTEN (decl))
6459 : 127 : return;
6460 : :
6461 : 64044 : id = DECL_ASSEMBLER_NAME (decl);
6462 : 64044 : ultimate_transparent_alias_target (&id);
6463 : 64044 : ultimate_transparent_alias_target (&target);
6464 : :
6465 : : /* We must force creation of DECL_RTL for debug info generation, even though
6466 : : we don't use it here. */
6467 : 64044 : make_decl_rtl (decl);
6468 : :
6469 : 64044 : TREE_ASM_WRITTEN (decl) = 1;
6470 : 64044 : TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
6471 : 64044 : TREE_ASM_WRITTEN (id) = 1;
6472 : :
6473 : 64044 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6474 : : {
6475 : 127 : if (!TREE_SYMBOL_REFERENCED (target))
6476 : 100 : weakref_targets = tree_cons (decl, target, weakref_targets);
6477 : :
6478 : : #ifdef ASM_OUTPUT_WEAKREF
6479 : 127 : ASM_OUTPUT_WEAKREF (asm_out_file, decl,
6480 : : IDENTIFIER_POINTER (id),
6481 : : IDENTIFIER_POINTER (target));
6482 : : #else
6483 : : if (!TARGET_SUPPORTS_WEAK)
6484 : : {
6485 : : error_at (DECL_SOURCE_LOCATION (decl),
6486 : : "%qs is not supported in this configuration", "weakref ");
6487 : : return;
6488 : : }
6489 : : #endif
6490 : 127 : return;
6491 : : }
6492 : :
6493 : : #ifdef ASM_OUTPUT_DEF
6494 : 63917 : tree orig_decl = decl;
6495 : :
6496 : : /* Make name accessible from other files, if appropriate. */
6497 : :
6498 : 63917 : if (TREE_PUBLIC (decl) || TREE_PUBLIC (orig_decl))
6499 : : {
6500 : 45307 : globalize_decl (decl);
6501 : 45307 : maybe_assemble_visibility (decl);
6502 : : }
6503 : 63917 : if (TREE_CODE (decl) == FUNCTION_DECL
6504 : 63917 : && cgraph_node::get (decl)->ifunc_resolver)
6505 : : {
6506 : : #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
6507 : 252 : if (targetm.has_ifunc_p ())
6508 : 252 : ASM_OUTPUT_TYPE_DIRECTIVE
6509 : : (asm_out_file, IDENTIFIER_POINTER (id),
6510 : : IFUNC_ASM_TYPE);
6511 : : else
6512 : : #endif
6513 : 0 : error_at (DECL_SOURCE_LOCATION (decl),
6514 : : "%qs is not supported on this target", "ifunc");
6515 : : }
6516 : :
6517 : : # ifdef ASM_OUTPUT_DEF_FROM_DECLS
6518 : : ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
6519 : : # else
6520 : 63917 : ASM_OUTPUT_DEF (asm_out_file,
6521 : : IDENTIFIER_POINTER (id),
6522 : : IDENTIFIER_POINTER (target));
6523 : : # endif
6524 : : /* If symbol aliases aren't actually supported... */
6525 : 63917 : if (!TARGET_SUPPORTS_ALIASES)
6526 : : /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error. */
6527 : : gcc_checking_assert (seen_error ());
6528 : : #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
6529 : : {
6530 : : const char *name;
6531 : : tree *p, t;
6532 : :
6533 : : name = IDENTIFIER_POINTER (id);
6534 : : # ifdef ASM_WEAKEN_DECL
6535 : : ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
6536 : : # else
6537 : : ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
6538 : : # endif
6539 : : /* Remove this function from the pending weak list so that
6540 : : we do not emit multiple .weak directives for it. */
6541 : : for (p = &weak_decls; (t = *p) ; )
6542 : : if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))
6543 : : || id == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
6544 : : *p = TREE_CHAIN (t);
6545 : : else
6546 : : p = &TREE_CHAIN (t);
6547 : :
6548 : : /* Remove weakrefs to the same target from the pending weakref
6549 : : list, for the same reason. */
6550 : : for (p = &weakref_targets; (t = *p) ; )
6551 : : {
6552 : : if (id == ultimate_transparent_alias_target (&TREE_VALUE (t)))
6553 : : *p = TREE_CHAIN (t);
6554 : : else
6555 : : p = &TREE_CHAIN (t);
6556 : : }
6557 : : }
6558 : : #endif
6559 : : }
6560 : :
6561 : : /* Output .symver directive. */
6562 : :
6563 : : void
6564 : 2 : do_assemble_symver (tree decl, tree target)
6565 : : {
6566 : 2 : tree id = DECL_ASSEMBLER_NAME (decl);
6567 : 2 : ultimate_transparent_alias_target (&id);
6568 : 2 : ultimate_transparent_alias_target (&target);
6569 : : #ifdef ASM_OUTPUT_SYMVER_DIRECTIVE
6570 : 2 : ASM_OUTPUT_SYMVER_DIRECTIVE (asm_out_file,
6571 : : IDENTIFIER_POINTER (target),
6572 : : IDENTIFIER_POINTER (id));
6573 : : #else
6574 : : error ("symver is only supported on ELF platforms");
6575 : : #endif
6576 : 2 : }
6577 : :
6578 : : /* Emit an assembler directive to make the symbol for DECL an alias to
6579 : : the symbol for TARGET. */
6580 : :
6581 : : void
6582 : 5573 : assemble_alias (tree decl, tree target)
6583 : : {
6584 : 5573 : tree target_decl;
6585 : :
6586 : 5573 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6587 : : {
6588 : 454 : tree alias = DECL_ASSEMBLER_NAME (decl);
6589 : :
6590 : 454 : ultimate_transparent_alias_target (&target);
6591 : :
6592 : 454 : if (alias == target)
6593 : 0 : error ("%qs symbol %q+D ultimately targets itself", "weakref", decl);
6594 : 454 : if (TREE_PUBLIC (decl))
6595 : 1 : error ("%qs symbol %q+D must have static linkage", "weakref", decl);
6596 : : }
6597 : : else if (!TARGET_SUPPORTS_ALIASES)
6598 : : {
6599 : : # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
6600 : : error_at (DECL_SOURCE_LOCATION (decl),
6601 : : "alias definitions not supported in this configuration");
6602 : : TREE_ASM_WRITTEN (decl) = 1;
6603 : : return;
6604 : : # else
6605 : : if (!DECL_WEAK (decl))
6606 : : {
6607 : : /* NB: ifunc_resolver isn't set when an error is detected. */
6608 : : if (TREE_CODE (decl) == FUNCTION_DECL
6609 : : && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
6610 : : error_at (DECL_SOURCE_LOCATION (decl),
6611 : : "%qs is not supported in this configuration", "ifunc");
6612 : : else
6613 : : error_at (DECL_SOURCE_LOCATION (decl),
6614 : : "only weak aliases are supported in this configuration");
6615 : : TREE_ASM_WRITTEN (decl) = 1;
6616 : : return;
6617 : : }
6618 : : # endif
6619 : : gcc_unreachable ();
6620 : : }
6621 : 5573 : TREE_USED (decl) = 1;
6622 : :
6623 : : /* Allow aliases to aliases. */
6624 : 5573 : if (TREE_CODE (decl) == FUNCTION_DECL)
6625 : 5378 : cgraph_node::get_create (decl)->alias = true;
6626 : : else
6627 : 195 : varpool_node::get_create (decl)->alias = true;
6628 : :
6629 : : /* If the target has already been emitted, we don't have to queue the
6630 : : alias. This saves a tad of memory. */
6631 : 5573 : if (symtab->global_info_ready)
6632 : 0 : target_decl = find_decl (target);
6633 : : else
6634 : : target_decl= NULL;
6635 : 0 : if ((target_decl && TREE_ASM_WRITTEN (target_decl))
6636 : 5573 : || symtab->state >= EXPANSION)
6637 : 0 : do_assemble_alias (decl, target);
6638 : : else
6639 : : {
6640 : 5573 : alias_pair p = {decl, target};
6641 : 5573 : vec_safe_push (alias_pairs, p);
6642 : : }
6643 : : }
6644 : :
6645 : : /* Record and output a table of translations from original function
6646 : : to its transaction aware clone. Note that tm_pure functions are
6647 : : considered to be their own clone. */
6648 : :
6649 : : struct tm_clone_hasher : ggc_cache_ptr_hash<tree_map>
6650 : : {
6651 : 220 : static hashval_t hash (tree_map *m) { return tree_map_hash (m); }
6652 : 253 : static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); }
6653 : :
6654 : : static int
6655 : 13 : keep_cache_entry (tree_map *&e)
6656 : : {
6657 : 13 : return ggc_marked_p (e->base.from);
6658 : : }
6659 : : };
6660 : :
6661 : : static GTY((cache)) hash_table<tm_clone_hasher> *tm_clone_hash;
6662 : :
6663 : : void
6664 : 457 : record_tm_clone_pair (tree o, tree n)
6665 : : {
6666 : 457 : struct tree_map **slot, *h;
6667 : :
6668 : 457 : if (tm_clone_hash == NULL)
6669 : 165 : tm_clone_hash = hash_table<tm_clone_hasher>::create_ggc (32);
6670 : :
6671 : 457 : h = ggc_alloc<tree_map> ();
6672 : 457 : h->hash = htab_hash_pointer (o);
6673 : 457 : h->base.from = o;
6674 : 457 : h->to = n;
6675 : :
6676 : 457 : slot = tm_clone_hash->find_slot_with_hash (h, h->hash, INSERT);
6677 : 457 : *slot = h;
6678 : 457 : }
6679 : :
6680 : : tree
6681 : 7 : get_tm_clone_pair (tree o)
6682 : : {
6683 : 7 : if (tm_clone_hash)
6684 : : {
6685 : 7 : struct tree_map *h, in;
6686 : :
6687 : 7 : in.base.from = o;
6688 : 7 : in.hash = htab_hash_pointer (o);
6689 : 7 : h = tm_clone_hash->find_with_hash (&in, in.hash);
6690 : 7 : if (h)
6691 : 0 : return h->to;
6692 : : }
6693 : : return NULL_TREE;
6694 : : }
6695 : :
6696 : : struct tm_alias_pair
6697 : : {
6698 : : unsigned int uid;
6699 : : tree from;
6700 : : tree to;
6701 : : };
6702 : :
6703 : :
6704 : : /* Dump the actual pairs to the .tm_clone_table section. */
6705 : :
6706 : : static void
6707 : 148 : dump_tm_clone_pairs (vec<tm_alias_pair> tm_alias_pairs)
6708 : : {
6709 : 148 : unsigned i;
6710 : 148 : tm_alias_pair *p;
6711 : 148 : bool switched = false;
6712 : :
6713 : 559 : FOR_EACH_VEC_ELT (tm_alias_pairs, i, p)
6714 : : {
6715 : 411 : tree src = p->from;
6716 : 411 : tree dst = p->to;
6717 : 411 : struct cgraph_node *src_n = cgraph_node::get (src);
6718 : 411 : struct cgraph_node *dst_n = cgraph_node::get (dst);
6719 : :
6720 : : /* The function ipa_tm_create_version() marks the clone as needed if
6721 : : the original function was needed. But we also mark the clone as
6722 : : needed if we ever called the clone indirectly through
6723 : : TM_GETTMCLONE. If neither of these are true, we didn't generate
6724 : : a clone, and we didn't call it indirectly... no sense keeping it
6725 : : in the clone table. */
6726 : 411 : if (!dst_n || !dst_n->definition)
6727 : 129 : continue;
6728 : :
6729 : : /* This covers the case where we have optimized the original
6730 : : function away, and only access the transactional clone. */
6731 : 282 : if (!src_n || !src_n->definition)
6732 : 9 : continue;
6733 : :
6734 : 273 : if (!switched)
6735 : : {
6736 : 120 : switch_to_section (targetm.asm_out.tm_clone_table_section ());
6737 : 120 : assemble_align (POINTER_SIZE);
6738 : 120 : switched = true;
6739 : : }
6740 : :
6741 : 546 : assemble_integer (XEXP (DECL_RTL (src), 0),
6742 : 546 : POINTER_SIZE_UNITS, POINTER_SIZE, 1);
6743 : 546 : assemble_integer (XEXP (DECL_RTL (dst), 0),
6744 : 546 : POINTER_SIZE_UNITS, POINTER_SIZE, 1);
6745 : : }
6746 : 148 : }
6747 : :
6748 : : /* Provide a default for the tm_clone_table section. */
6749 : :
6750 : : section *
6751 : 120 : default_clone_table_section (void)
6752 : : {
6753 : 120 : return get_named_section (NULL, ".tm_clone_table", 3);
6754 : : }
6755 : :
6756 : : /* Helper comparison function for qsorting by the DECL_UID stored in
6757 : : alias_pair->emitted_diags. */
6758 : :
6759 : : static int
6760 : 3421 : tm_alias_pair_cmp (const void *x, const void *y)
6761 : : {
6762 : 3421 : const tm_alias_pair *p1 = (const tm_alias_pair *) x;
6763 : 3421 : const tm_alias_pair *p2 = (const tm_alias_pair *) y;
6764 : 3421 : if (p1->uid < p2->uid)
6765 : : return -1;
6766 : 1541 : if (p1->uid > p2->uid)
6767 : 1541 : return 1;
6768 : : return 0;
6769 : : }
6770 : :
6771 : : void
6772 : 225316 : finish_tm_clone_pairs (void)
6773 : : {
6774 : 225316 : vec<tm_alias_pair> tm_alias_pairs = vNULL;
6775 : :
6776 : 225316 : if (tm_clone_hash == NULL)
6777 : 225168 : return;
6778 : :
6779 : : /* We need a determenistic order for the .tm_clone_table, otherwise
6780 : : we will get bootstrap comparison failures, so dump the hash table
6781 : : to a vector, sort it, and dump the vector. */
6782 : :
6783 : : /* Dump the hashtable to a vector. */
6784 : 148 : tree_map *map;
6785 : 148 : hash_table<tm_clone_hasher>::iterator iter;
6786 : 970 : FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash, map, tree_map *, iter)
6787 : : {
6788 : 411 : tm_alias_pair p = {DECL_UID (map->base.from), map->base.from, map->to};
6789 : 411 : tm_alias_pairs.safe_push (p);
6790 : : }
6791 : : /* Sort it. */
6792 : 148 : tm_alias_pairs.qsort (tm_alias_pair_cmp);
6793 : :
6794 : : /* Dump it. */
6795 : 148 : dump_tm_clone_pairs (tm_alias_pairs);
6796 : :
6797 : 148 : tm_clone_hash->empty ();
6798 : 148 : tm_clone_hash = NULL;
6799 : 148 : tm_alias_pairs.release ();
6800 : : }
6801 : :
6802 : :
6803 : : /* Emit an assembler directive to set symbol for DECL visibility to
6804 : : the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6805 : :
6806 : : void
6807 : 28885 : default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
6808 : : int vis ATTRIBUTE_UNUSED)
6809 : : {
6810 : : #ifdef HAVE_GAS_HIDDEN
6811 : 28885 : static const char * const visibility_types[] = {
6812 : : NULL, "protected", "hidden", "internal"
6813 : : };
6814 : :
6815 : 28885 : const char *name, *type;
6816 : 28885 : tree id;
6817 : :
6818 : 28885 : id = DECL_ASSEMBLER_NAME (decl);
6819 : 28885 : ultimate_transparent_alias_target (&id);
6820 : 28885 : name = IDENTIFIER_POINTER (id);
6821 : :
6822 : 28885 : type = visibility_types[vis];
6823 : :
6824 : 28885 : fprintf (asm_out_file, "\t.%s\t", type);
6825 : 28885 : assemble_name (asm_out_file, name);
6826 : 28885 : fprintf (asm_out_file, "\n");
6827 : : #else
6828 : : if (!DECL_ARTIFICIAL (decl))
6829 : : warning (OPT_Wattributes, "visibility attribute not supported "
6830 : : "in this configuration; ignored");
6831 : : #endif
6832 : 28885 : }
6833 : :
6834 : : /* A helper function to call assemble_visibility when needed for a decl. */
6835 : :
6836 : : bool
6837 : 2803388 : maybe_assemble_visibility (tree decl)
6838 : : {
6839 : 2803388 : enum symbol_visibility vis = DECL_VISIBILITY (decl);
6840 : 2803388 : if (vis != VISIBILITY_DEFAULT)
6841 : : {
6842 : 27573 : targetm.asm_out.assemble_visibility (decl, vis);
6843 : 27573 : return true;
6844 : : }
6845 : : else
6846 : : return false;
6847 : : }
6848 : :
6849 : : /* Returns true if the target configuration supports defining public symbols
6850 : : so that one of them will be chosen at link time instead of generating a
6851 : : multiply-defined symbol error, whether through the use of weak symbols or
6852 : : a target-specific mechanism for having duplicates discarded. */
6853 : :
6854 : : bool
6855 : 92794 : supports_one_only (void)
6856 : : {
6857 : 92794 : if (SUPPORTS_ONE_ONLY)
6858 : 92794 : return true;
6859 : : if (TARGET_SUPPORTS_WEAK)
6860 : : return true;
6861 : : return false;
6862 : : }
6863 : :
6864 : : /* Set up DECL as a public symbol that can be defined in multiple
6865 : : translation units without generating a linker error. */
6866 : :
6867 : : void
6868 : 61515306 : make_decl_one_only (tree decl, tree comdat_group)
6869 : : {
6870 : 61515306 : struct symtab_node *symbol;
6871 : 61515306 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
6872 : :
6873 : 61515306 : TREE_PUBLIC (decl) = 1;
6874 : :
6875 : 61515306 : if (VAR_P (decl))
6876 : 22894213 : symbol = varpool_node::get_create (decl);
6877 : : else
6878 : 38621093 : symbol = cgraph_node::get_create (decl);
6879 : :
6880 : 61515306 : if (SUPPORTS_ONE_ONLY)
6881 : : {
6882 : : #ifdef MAKE_DECL_ONE_ONLY
6883 : 61515306 : MAKE_DECL_ONE_ONLY (decl);
6884 : : #endif
6885 : 61515306 : symbol->set_comdat_group (comdat_group);
6886 : : }
6887 : : else if (VAR_P (decl)
6888 : : && (DECL_INITIAL (decl) == 0
6889 : : || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))
6890 : : DECL_COMMON (decl) = 1;
6891 : : else
6892 : : {
6893 : : gcc_assert (TARGET_SUPPORTS_WEAK);
6894 : : DECL_WEAK (decl) = 1;
6895 : : }
6896 : 61515306 : }
6897 : :
6898 : : void
6899 : 274512 : init_varasm_once (void)
6900 : : {
6901 : 274512 : section_htab = hash_table<section_hasher>::create_ggc (31);
6902 : 274512 : object_block_htab = hash_table<object_block_hasher>::create_ggc (31);
6903 : 274512 : const_desc_htab = hash_table<tree_descriptor_hasher>::create_ggc (1009);
6904 : :
6905 : 274512 : shared_constant_pool = create_constant_pool ();
6906 : :
6907 : : #ifdef TEXT_SECTION_ASM_OP
6908 : 274512 : text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6909 : : TEXT_SECTION_ASM_OP);
6910 : : #endif
6911 : :
6912 : : #ifdef DATA_SECTION_ASM_OP
6913 : 274512 : data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6914 : : DATA_SECTION_ASM_OP);
6915 : : #endif
6916 : :
6917 : : #ifdef SDATA_SECTION_ASM_OP
6918 : : sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6919 : : SDATA_SECTION_ASM_OP);
6920 : : #endif
6921 : :
6922 : : #ifdef READONLY_DATA_SECTION_ASM_OP
6923 : 274512 : readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6924 : : READONLY_DATA_SECTION_ASM_OP);
6925 : : #endif
6926 : :
6927 : : #ifdef CTORS_SECTION_ASM_OP
6928 : : ctors_section = get_unnamed_section (0, output_section_asm_op,
6929 : : CTORS_SECTION_ASM_OP);
6930 : : #endif
6931 : :
6932 : : #ifdef DTORS_SECTION_ASM_OP
6933 : : dtors_section = get_unnamed_section (0, output_section_asm_op,
6934 : : DTORS_SECTION_ASM_OP);
6935 : : #endif
6936 : :
6937 : : #ifdef BSS_SECTION_ASM_OP
6938 : 274512 : bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6939 : : output_section_asm_op,
6940 : : BSS_SECTION_ASM_OP);
6941 : : #endif
6942 : :
6943 : : #ifdef SBSS_SECTION_ASM_OP
6944 : : sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
6945 : : output_section_asm_op,
6946 : : SBSS_SECTION_ASM_OP);
6947 : : #endif
6948 : :
6949 : 274512 : tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6950 : : | SECTION_COMMON, emit_tls_common);
6951 : 274512 : lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6952 : : | SECTION_COMMON, emit_local);
6953 : 274512 : comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
6954 : : | SECTION_COMMON, emit_common);
6955 : :
6956 : : #if defined ASM_OUTPUT_ALIGNED_BSS
6957 : 274512 : bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
6958 : : emit_bss);
6959 : : #endif
6960 : :
6961 : 274512 : targetm.asm_out.init_sections ();
6962 : :
6963 : 274512 : if (readonly_data_section == NULL)
6964 : 0 : readonly_data_section = text_section;
6965 : :
6966 : : #ifdef ASM_OUTPUT_EXTERNAL
6967 : 274512 : pending_assemble_externals_set = new hash_set<tree>;
6968 : : #endif
6969 : 274512 : }
6970 : :
6971 : : /* Determine whether SYMBOL is used in any optimized function. */
6972 : :
6973 : : static bool
6974 : 147 : have_optimized_refs (struct symtab_node *symbol)
6975 : : {
6976 : 147 : struct ipa_ref *ref;
6977 : :
6978 : 171 : for (int i = 0; symbol->iterate_referring (i, ref); i++)
6979 : : {
6980 : 187 : cgraph_node *cnode = dyn_cast <cgraph_node *> (ref->referring);
6981 : :
6982 : 163 : if (cnode && opt_for_fn (cnode->decl, optimize))
6983 : : return true;
6984 : : }
6985 : :
6986 : : return false;
6987 : : }
6988 : :
6989 : : /* Check if promoting general-dynamic TLS access model to local-dynamic is
6990 : : desirable for DECL. */
6991 : :
6992 : : static bool
6993 : 262 : optimize_dyn_tls_for_decl_p (const_tree decl)
6994 : : {
6995 : 262 : if (cfun)
6996 : 22 : return optimize;
6997 : 240 : return symtab->state >= IPA && have_optimized_refs (symtab_node::get (decl));
6998 : : }
6999 : :
7000 : :
7001 : : enum tls_model
7002 : 27877 : decl_default_tls_model (const_tree decl)
7003 : : {
7004 : 27877 : enum tls_model kind;
7005 : 27877 : bool is_local;
7006 : :
7007 : 27877 : is_local = targetm.binds_local_p (decl);
7008 : 27877 : if (!flag_shlib)
7009 : : {
7010 : 25621 : if (is_local)
7011 : : kind = TLS_MODEL_LOCAL_EXEC;
7012 : : else
7013 : 20247 : kind = TLS_MODEL_INITIAL_EXEC;
7014 : : }
7015 : :
7016 : : /* Local dynamic is inefficient when we're not combining the
7017 : : parts of the address. */
7018 : 2256 : else if (is_local && optimize_dyn_tls_for_decl_p (decl))
7019 : : kind = TLS_MODEL_LOCAL_DYNAMIC;
7020 : : else
7021 : : kind = TLS_MODEL_GLOBAL_DYNAMIC;
7022 : 27877 : if (kind < flag_tls_default)
7023 : 176 : kind = flag_tls_default;
7024 : :
7025 : 27877 : return kind;
7026 : : }
7027 : :
7028 : : /* Select a set of attributes for section NAME based on the properties
7029 : : of DECL and whether or not RELOC indicates that DECL's initializer
7030 : : might contain runtime relocations.
7031 : :
7032 : : We make the section read-only and executable for a function decl,
7033 : : read-only for a const data decl, and writable for a non-const data decl. */
7034 : :
7035 : : unsigned int
7036 : 57508425 : default_section_type_flags (tree decl, const char *name, int reloc)
7037 : : {
7038 : 57508425 : unsigned int flags;
7039 : :
7040 : 57508425 : if (decl && TREE_CODE (decl) == FUNCTION_DECL)
7041 : : flags = SECTION_CODE;
7042 : 2952816 : else if (strcmp (name, ".data.rel.ro") == 0
7043 : 2952703 : || strcmp (name, ".data.rel.ro.local") == 0)
7044 : : flags = SECTION_WRITE | SECTION_RELRO;
7045 : 2952328 : else if (decl)
7046 : : {
7047 : 2952208 : enum section_category category
7048 : 2952208 : = categorize_decl_for_section (decl, reloc);
7049 : 6539120 : if (decl_readonly_section_1 (category))
7050 : : flags = 0;
7051 : 634216 : else if (category == SECCAT_DATA_REL_RO
7052 : 634216 : || category == SECCAT_DATA_REL_RO_LOCAL)
7053 : : flags = SECTION_WRITE | SECTION_RELRO;
7054 : : else
7055 : 2952696 : flags = SECTION_WRITE;
7056 : : }
7057 : : else
7058 : : flags = SECTION_WRITE;
7059 : :
7060 : 57508305 : if (decl && DECL_P (decl) && DECL_COMDAT_GROUP (decl))
7061 : 29989675 : flags |= SECTION_LINKONCE;
7062 : :
7063 : 57508425 : if (strcmp (name, ".vtable_map_vars") == 0)
7064 : 6 : flags |= SECTION_LINKONCE;
7065 : :
7066 : 57508425 : if (decl && VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7067 : 3567 : flags |= SECTION_TLS | SECTION_WRITE;
7068 : :
7069 : 57508425 : if (strcmp (name, ".bss") == 0
7070 : 57508425 : || startswith (name, ".bss.")
7071 : 57494453 : || startswith (name, ".gnu.linkonce.b.")
7072 : 57494453 : || strcmp (name, ".persistent.bss") == 0
7073 : 57494453 : || strcmp (name, ".sbss") == 0
7074 : 57494453 : || startswith (name, ".sbss.")
7075 : 115002878 : || startswith (name, ".gnu.linkonce.sb."))
7076 : 13972 : flags |= SECTION_BSS;
7077 : :
7078 : 57508425 : if (strcmp (name, ".tdata") == 0
7079 : 57508118 : || startswith (name, ".tdata.")
7080 : 115016537 : || startswith (name, ".gnu.linkonce.td."))
7081 : 313 : flags |= SECTION_TLS;
7082 : :
7083 : 57508425 : if (strcmp (name, ".tbss") == 0
7084 : 57505225 : || startswith (name, ".tbss.")
7085 : 115013602 : || startswith (name, ".gnu.linkonce.tb."))
7086 : 3248 : flags |= SECTION_TLS | SECTION_BSS;
7087 : :
7088 : 57508425 : if (strcmp (name, ".noinit") == 0)
7089 : 0 : flags |= SECTION_WRITE | SECTION_BSS | SECTION_NOTYPE;
7090 : :
7091 : 57508425 : if (strcmp (name, ".persistent") == 0)
7092 : 0 : flags |= SECTION_WRITE | SECTION_NOTYPE;
7093 : :
7094 : : /* Various sections have special ELF types that the assembler will
7095 : : assign by default based on the name. They are neither SHT_PROGBITS
7096 : : nor SHT_NOBITS, so when changing sections we don't want to print a
7097 : : section type (@progbits or @nobits). Rather than duplicating the
7098 : : assembler's knowledge of what those special name patterns are, just
7099 : : let the assembler choose the type if we don't know a specific
7100 : : reason to set it to something other than the default. SHT_PROGBITS
7101 : : is the default for sections whose name is not specially known to
7102 : : the assembler, so it does no harm to leave the choice to the
7103 : : assembler when @progbits is the best thing we know to use. If
7104 : : someone is silly enough to emit code or TLS variables to one of
7105 : : these sections, then don't handle them specially.
7106 : :
7107 : : default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
7108 : : LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
7109 : 57508425 : if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE))
7110 : 57508425 : && !(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)))
7111 : 2392105 : flags |= SECTION_NOTYPE;
7112 : :
7113 : 57508425 : return flags;
7114 : : }
7115 : :
7116 : : /* Return true if the target supports some form of global BSS,
7117 : : either through bss_noswitch_section, or by selecting a BSS
7118 : : section in TARGET_ASM_SELECT_SECTION. */
7119 : :
7120 : : bool
7121 : 0 : have_global_bss_p (void)
7122 : : {
7123 : 0 : return bss_noswitch_section || targetm.have_switchable_bss_sections;
7124 : : }
7125 : :
7126 : : /* Output assembly to switch to section NAME with attribute FLAGS.
7127 : : Four variants for common object file formats. */
7128 : :
7129 : : void
7130 : 0 : default_no_named_section (const char *name ATTRIBUTE_UNUSED,
7131 : : unsigned int flags ATTRIBUTE_UNUSED,
7132 : : tree decl ATTRIBUTE_UNUSED)
7133 : : {
7134 : : /* Some object formats don't support named sections at all. The
7135 : : front-end should already have flagged this as an error. */
7136 : 0 : gcc_unreachable ();
7137 : : }
7138 : :
7139 : : #ifndef TLS_SECTION_ASM_FLAG
7140 : : #define TLS_SECTION_ASM_FLAG 'T'
7141 : : #endif
7142 : :
7143 : : void
7144 : 3503894 : default_elf_asm_named_section (const char *name, unsigned int flags,
7145 : : tree decl)
7146 : : {
7147 : 3503894 : char flagchars[11], *f = flagchars;
7148 : 3503894 : unsigned int numeric_value = 0;
7149 : :
7150 : : /* If we have already declared this section, we can use an
7151 : : abbreviated form to switch back to it -- unless this section is
7152 : : part of a COMDAT groups or with SHF_GNU_RETAIN or with SHF_LINK_ORDER,
7153 : : in which case GAS requires the full declaration every time. */
7154 : 3503894 : if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7155 : : && !(flags & (SECTION_RETAIN | SECTION_LINK_ORDER))
7156 : 3503894 : && (flags & SECTION_DECLARED))
7157 : : {
7158 : 374550 : fprintf (asm_out_file, "\t.section\t%s\n", name);
7159 : 374550 : return;
7160 : : }
7161 : :
7162 : : /* If we have a machine specific flag, then use the numeric value to pass
7163 : : this on to GAS. */
7164 : 3129344 : if (targetm.asm_out.elf_flags_numeric (flags, &numeric_value))
7165 : 0 : snprintf (f, sizeof (flagchars), "0x%08x", numeric_value);
7166 : : else
7167 : : {
7168 : 3129344 : if (!(flags & SECTION_DEBUG))
7169 : 2077327 : *f++ = 'a';
7170 : : #if HAVE_GAS_SECTION_EXCLUDE
7171 : 3129344 : if (flags & SECTION_EXCLUDE)
7172 : 432236 : *f++ = 'e';
7173 : : #endif
7174 : 3129344 : if (flags & SECTION_WRITE)
7175 : 346671 : *f++ = 'w';
7176 : 3129344 : if (flags & SECTION_CODE)
7177 : 357297 : *f++ = 'x';
7178 : 3129344 : if (flags & SECTION_SMALL)
7179 : 0 : *f++ = 's';
7180 : 3129344 : if (flags & SECTION_MERGE)
7181 : 218855 : *f++ = 'M';
7182 : 3129344 : if (flags & SECTION_STRINGS)
7183 : 174090 : *f++ = 'S';
7184 : 3129344 : if (flags & SECTION_TLS)
7185 : 1018 : *f++ = TLS_SECTION_ASM_FLAG;
7186 : 3129344 : if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7187 : 537609 : *f++ = 'G';
7188 : 3129344 : if (flags & SECTION_RETAIN)
7189 : 258 : *f++ = 'R';
7190 : 3129344 : if (flags & SECTION_LINK_ORDER)
7191 : 53 : *f++ = 'o';
7192 : : #ifdef MACH_DEP_SECTION_ASM_FLAG
7193 : : if (flags & SECTION_MACH_DEP)
7194 : : *f++ = MACH_DEP_SECTION_ASM_FLAG;
7195 : : #endif
7196 : 3129344 : *f = '\0';
7197 : : }
7198 : :
7199 : 3129344 : fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
7200 : :
7201 : : /* default_section_type_flags (above) knows which flags need special
7202 : : handling here, and sets NOTYPE when none of these apply so that the
7203 : : assembler's logic for default types can apply to user-chosen
7204 : : section names. */
7205 : 3129344 : if (!(flags & SECTION_NOTYPE))
7206 : : {
7207 : 1888391 : const char *type;
7208 : 1888391 : const char *format;
7209 : :
7210 : 1888391 : if (flags & SECTION_BSS)
7211 : : type = "nobits";
7212 : : else
7213 : 1875488 : type = "progbits";
7214 : :
7215 : 1888391 : format = ",@%s";
7216 : : /* On platforms that use "@" as the assembly comment character,
7217 : : use "%" instead. */
7218 : 1888391 : if (strcmp (ASM_COMMENT_START, "@") == 0)
7219 : : format = ",%%%s";
7220 : 1888391 : fprintf (asm_out_file, format, type);
7221 : :
7222 : 1888391 : if (flags & SECTION_ENTSIZE)
7223 : 218855 : fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
7224 : 1888391 : if (flags & SECTION_LINK_ORDER)
7225 : : {
7226 : : /* For now, only section "__patchable_function_entries"
7227 : : adopts flag SECTION_LINK_ORDER, internal label LPFE*
7228 : : was emitted in default_print_patchable_function_entry,
7229 : : just place it here for linked_to section. */
7230 : 53 : gcc_assert (!strcmp (name, "__patchable_function_entries"));
7231 : 53 : fprintf (asm_out_file, ",");
7232 : 53 : char buf[256];
7233 : 53 : ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE",
7234 : : current_function_funcdef_no);
7235 : 53 : assemble_name_raw (asm_out_file, buf);
7236 : : }
7237 : 1888391 : if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7238 : : {
7239 : 537609 : if (TREE_CODE (decl) == IDENTIFIER_NODE)
7240 : 1564 : fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
7241 : : else
7242 : 1072090 : fprintf (asm_out_file, ",%s,comdat",
7243 : 536045 : IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
7244 : : }
7245 : : }
7246 : :
7247 : 3129344 : putc ('\n', asm_out_file);
7248 : : }
7249 : :
7250 : : void
7251 : 0 : default_coff_asm_named_section (const char *name, unsigned int flags,
7252 : : tree decl ATTRIBUTE_UNUSED)
7253 : : {
7254 : 0 : char flagchars[8], *f = flagchars;
7255 : :
7256 : 0 : if (flags & SECTION_WRITE)
7257 : 0 : *f++ = 'w';
7258 : 0 : if (flags & SECTION_CODE)
7259 : 0 : *f++ = 'x';
7260 : 0 : *f = '\0';
7261 : :
7262 : 0 : fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
7263 : 0 : }
7264 : :
7265 : : void
7266 : 0 : default_pe_asm_named_section (const char *name, unsigned int flags,
7267 : : tree decl)
7268 : : {
7269 : 0 : default_coff_asm_named_section (name, flags, decl);
7270 : :
7271 : 0 : if (flags & SECTION_LINKONCE)
7272 : : {
7273 : : /* Functions may have been compiled at various levels of
7274 : : optimization so we can't use `same_size' here.
7275 : : Instead, have the linker pick one. */
7276 : 0 : fprintf (asm_out_file, "\t.linkonce %s\n",
7277 : 0 : (flags & SECTION_CODE ? "discard" : "same_size"));
7278 : : }
7279 : 0 : }
7280 : :
7281 : : /* The lame default section selector. */
7282 : :
7283 : : section *
7284 : 0 : default_select_section (tree decl, int reloc,
7285 : : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
7286 : : {
7287 : 0 : if (DECL_P (decl))
7288 : : {
7289 : 0 : if (decl_readonly_section (decl, reloc))
7290 : 0 : return readonly_data_section;
7291 : : }
7292 : 0 : else if (TREE_CODE (decl) == CONSTRUCTOR)
7293 : : {
7294 : 0 : if (! ((flag_pic && reloc)
7295 : 0 : || !TREE_READONLY (decl)
7296 : 0 : || !TREE_CONSTANT (decl)))
7297 : 0 : return readonly_data_section;
7298 : : }
7299 : 0 : else if (TREE_CODE (decl) == STRING_CST)
7300 : 0 : return readonly_data_section;
7301 : 0 : else if (! (flag_pic && reloc))
7302 : 0 : return readonly_data_section;
7303 : :
7304 : 0 : return data_section;
7305 : : }
7306 : :
7307 : : enum section_category
7308 : 6374259 : categorize_decl_for_section (const_tree decl, int reloc)
7309 : : {
7310 : 6374259 : enum section_category ret;
7311 : :
7312 : 6374259 : if (TREE_CODE (decl) == FUNCTION_DECL)
7313 : : return SECCAT_TEXT;
7314 : 6146188 : else if (TREE_CODE (decl) == STRING_CST)
7315 : : {
7316 : 1237749 : if ((flag_sanitize & SANITIZE_ADDRESS)
7317 : 1237749 : && asan_protect_global (CONST_CAST_TREE (decl)))
7318 : : /* or !flag_merge_constants */
7319 : : return SECCAT_RODATA;
7320 : : else
7321 : 1236187 : return SECCAT_RODATA_MERGE_STR;
7322 : : }
7323 : 4908439 : else if (VAR_P (decl))
7324 : : {
7325 : 4877898 : tree d = CONST_CAST_TREE (decl);
7326 : 4877898 : if (bss_initializer_p (decl))
7327 : : ret = SECCAT_BSS;
7328 : 4843386 : else if (! TREE_READONLY (decl)
7329 : 4843386 : || (DECL_INITIAL (decl)
7330 : 4530770 : && ! TREE_CONSTANT (DECL_INITIAL (decl))))
7331 : : {
7332 : : /* Here the reloc_rw_mask is not testing whether the section should
7333 : : be read-only or not, but whether the dynamic link will have to
7334 : : do something. If so, we wish to segregate the data in order to
7335 : : minimize cache misses inside the dynamic linker. */
7336 : 312568 : if (reloc & targetm.asm_out.reloc_rw_mask ())
7337 : 6037 : ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
7338 : : else
7339 : : ret = SECCAT_DATA;
7340 : : }
7341 : 4530818 : else if (reloc & targetm.asm_out.reloc_rw_mask ())
7342 : 917426 : ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
7343 : 720799 : else if (reloc || (flag_merge_constants < 2 && !DECL_MERGEABLE (decl))
7344 : 3615027 : || ((flag_sanitize & SANITIZE_ADDRESS)
7345 : : /* PR 81697: for architectures that use section anchors we
7346 : : need to ignore DECL_RTL_SET_P (decl) for string constants
7347 : : inside this asan_protect_global call because otherwise
7348 : : we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
7349 : : section, set DECL_RTL (decl) later on and add DECL to
7350 : : protected globals via successive asan_protect_global
7351 : : calls. In this scenario we'll end up with wrong
7352 : : alignment of these strings at runtime and possible ASan
7353 : : false positives. */
7354 : 91 : && asan_protect_global (d, use_object_blocks_p ()
7355 : 91 : && use_blocks_for_decl_p (d))))
7356 : : /* C and C++ don't allow different variables to share the same
7357 : : location. -fmerge-all-constants allows even that (at the
7358 : : expense of not conforming). */
7359 : : ret = SECCAT_RODATA;
7360 : 1556 : else if (DECL_INITIAL (decl)
7361 : 1556 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
7362 : : ret = SECCAT_RODATA_MERGE_STR_INIT;
7363 : : else
7364 : : ret = SECCAT_RODATA_MERGE_CONST;
7365 : : }
7366 : 30541 : else if (TREE_CODE (decl) == CONSTRUCTOR)
7367 : : {
7368 : 1502 : if ((reloc & targetm.asm_out.reloc_rw_mask ())
7369 : 1502 : || ! TREE_CONSTANT (decl))
7370 : : ret = SECCAT_DATA;
7371 : : else
7372 : : ret = SECCAT_RODATA;
7373 : : }
7374 : : else
7375 : : ret = SECCAT_RODATA;
7376 : :
7377 : : /* There are no read-only thread-local sections. */
7378 : 4908439 : if (VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7379 : : {
7380 : : /* Note that this would be *just* SECCAT_BSS, except that there's
7381 : : no concept of a read-only thread-local-data section. */
7382 : 7128 : if (ret == SECCAT_BSS
7383 : 634 : || DECL_INITIAL (decl) == NULL
7384 : 7754 : || (flag_zero_initialized_in_bss
7385 : 626 : && initializer_zerop (DECL_INITIAL (decl))))
7386 : : ret = SECCAT_TBSS;
7387 : : else
7388 : : ret = SECCAT_TDATA;
7389 : : }
7390 : :
7391 : : /* If the target uses small data sections, select it. */
7392 : 4901311 : else if (targetm.in_small_data_p (decl))
7393 : : {
7394 : 0 : if (ret == SECCAT_BSS)
7395 : : ret = SECCAT_SBSS;
7396 : 0 : else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
7397 : : ret = SECCAT_SRODATA;
7398 : : else
7399 : 0 : ret = SECCAT_SDATA;
7400 : : }
7401 : :
7402 : : return ret;
7403 : : }
7404 : :
7405 : : static bool
7406 : 2972581 : decl_readonly_section_1 (enum section_category category)
7407 : : {
7408 : 2952208 : switch (category)
7409 : : {
7410 : : case SECCAT_RODATA:
7411 : : case SECCAT_RODATA_MERGE_STR:
7412 : : case SECCAT_RODATA_MERGE_STR_INIT:
7413 : : case SECCAT_RODATA_MERGE_CONST:
7414 : : case SECCAT_SRODATA:
7415 : : return true;
7416 : 636487 : default:
7417 : 636487 : return false;
7418 : : }
7419 : : }
7420 : :
7421 : : bool
7422 : 20373 : decl_readonly_section (const_tree decl, int reloc)
7423 : : {
7424 : 20373 : return decl_readonly_section_1 (categorize_decl_for_section (decl, reloc));
7425 : : }
7426 : :
7427 : : /* Select a section based on the above categorization. */
7428 : :
7429 : : section *
7430 : 1627503 : default_elf_select_section (tree decl, int reloc,
7431 : : unsigned HOST_WIDE_INT align)
7432 : : {
7433 : 1627503 : const char *sname;
7434 : :
7435 : 1627503 : switch (categorize_decl_for_section (decl, reloc))
7436 : : {
7437 : 0 : case SECCAT_TEXT:
7438 : : /* We're not supposed to be called on FUNCTION_DECLs. */
7439 : 0 : gcc_unreachable ();
7440 : 127798 : case SECCAT_RODATA:
7441 : 127798 : return readonly_data_section;
7442 : 1218226 : case SECCAT_RODATA_MERGE_STR:
7443 : 1218226 : return mergeable_string_section (decl, align, 0);
7444 : 14 : case SECCAT_RODATA_MERGE_STR_INIT:
7445 : 14 : return mergeable_string_section (DECL_INITIAL (decl), align, 0);
7446 : 272 : case SECCAT_RODATA_MERGE_CONST:
7447 : 272 : return mergeable_constant_section (DECL_MODE (decl), align, 0);
7448 : : case SECCAT_SRODATA:
7449 : : sname = ".sdata2";
7450 : : break;
7451 : 276358 : case SECCAT_DATA:
7452 : 276358 : if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
7453 : : {
7454 : : sname = ".persistent";
7455 : : break;
7456 : : }
7457 : 276358 : return data_section;
7458 : 125 : case SECCAT_DATA_REL:
7459 : 125 : sname = ".data.rel";
7460 : 125 : break;
7461 : 970 : case SECCAT_DATA_REL_LOCAL:
7462 : 970 : sname = ".data.rel.local";
7463 : 970 : break;
7464 : 99 : case SECCAT_DATA_REL_RO:
7465 : 99 : sname = ".data.rel.ro";
7466 : 99 : break;
7467 : 130 : case SECCAT_DATA_REL_RO_LOCAL:
7468 : 130 : sname = ".data.rel.ro.local";
7469 : 130 : break;
7470 : 0 : case SECCAT_SDATA:
7471 : 0 : sname = ".sdata";
7472 : 0 : break;
7473 : 307 : case SECCAT_TDATA:
7474 : 307 : sname = ".tdata";
7475 : 307 : break;
7476 : 4 : case SECCAT_BSS:
7477 : 4 : if (DECL_P (decl) && DECL_NOINIT_P (decl))
7478 : : {
7479 : : sname = ".noinit";
7480 : : break;
7481 : : }
7482 : 4 : if (bss_section)
7483 : : return bss_section;
7484 : : sname = ".bss";
7485 : : break;
7486 : 0 : case SECCAT_SBSS:
7487 : 0 : sname = ".sbss";
7488 : 0 : break;
7489 : 3200 : case SECCAT_TBSS:
7490 : 3200 : sname = ".tbss";
7491 : 3200 : break;
7492 : 0 : default:
7493 : 0 : gcc_unreachable ();
7494 : : }
7495 : :
7496 : 4831 : return get_named_section (decl, sname, reloc);
7497 : : }
7498 : :
7499 : : /* Construct a unique section name based on the decl name and the
7500 : : categorization performed above. */
7501 : :
7502 : : void
7503 : 1774083 : default_unique_section (tree decl, int reloc)
7504 : : {
7505 : : /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
7506 : 1774083 : bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
7507 : 1774083 : const char *prefix, *name, *linkonce;
7508 : 1774083 : char *string;
7509 : 1774083 : tree id;
7510 : :
7511 : 1774083 : switch (categorize_decl_for_section (decl, reloc))
7512 : : {
7513 : : case SECCAT_TEXT:
7514 : : prefix = one_only ? ".t" : ".text";
7515 : : break;
7516 : 1199202 : case SECCAT_RODATA:
7517 : 1199202 : case SECCAT_RODATA_MERGE_STR:
7518 : 1199202 : case SECCAT_RODATA_MERGE_STR_INIT:
7519 : 1199202 : case SECCAT_RODATA_MERGE_CONST:
7520 : 1199202 : prefix = one_only ? ".r" : ".rodata";
7521 : 1199202 : break;
7522 : 0 : case SECCAT_SRODATA:
7523 : 0 : prefix = one_only ? ".s2" : ".sdata2";
7524 : 0 : break;
7525 : 9449 : case SECCAT_DATA:
7526 : 9449 : prefix = one_only ? ".d" : ".data";
7527 : 9449 : if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
7528 : : {
7529 : : prefix = one_only ? ".p" : ".persistent";
7530 : : break;
7531 : : }
7532 : : break;
7533 : 1137 : case SECCAT_DATA_REL:
7534 : 1137 : prefix = one_only ? ".d.rel" : ".data.rel";
7535 : 1137 : break;
7536 : 815 : case SECCAT_DATA_REL_LOCAL:
7537 : 815 : prefix = one_only ? ".d.rel.local" : ".data.rel.local" |