Silence overactive sanity check with -fpartial-profile-training
[gcc.git] / gcc / varpool.c
1 /* Callgraph handling code.
2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "target.h"
26 #include "tree.h"
27 #include "gimple.h"
28 #include "timevar.h"
29 #include "cgraph.h"
30 #include "lto-streamer.h"
31 #include "varasm.h"
32 #include "debug.h"
33 #include "output.h"
34 #include "omp-offload.h"
35 #include "context.h"
36 #include "stringpool.h"
37 #include "attribs.h"
38
39 const char * const tls_model_names[]={"none", "emulated",
40 "global-dynamic", "local-dynamic",
41 "initial-exec", "local-exec"};
42
43 /* List of hooks triggered on varpool_node events. */
44 struct varpool_node_hook_list {
45 varpool_node_hook hook;
46 void *data;
47 struct varpool_node_hook_list *next;
48 };
49
50 /* Register HOOK to be called with DATA on each removed node. */
51 varpool_node_hook_list *
52 symbol_table::add_varpool_removal_hook (varpool_node_hook hook, void *data)
53 {
54 varpool_node_hook_list *entry;
55 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
56
57 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
58 entry->hook = hook;
59 entry->data = data;
60 entry->next = NULL;
61 while (*ptr)
62 ptr = &(*ptr)->next;
63 *ptr = entry;
64 return entry;
65 }
66
67 /* Remove ENTRY from the list of hooks called on removing nodes. */
68 void
69 symbol_table::remove_varpool_removal_hook (varpool_node_hook_list *entry)
70 {
71 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
72
73 while (*ptr != entry)
74 ptr = &(*ptr)->next;
75 *ptr = entry->next;
76 free (entry);
77 }
78
79 /* Call all node removal hooks. */
80 void
81 symbol_table::call_varpool_removal_hooks (varpool_node *node)
82 {
83 varpool_node_hook_list *entry = m_first_varpool_removal_hook;
84 while (entry)
85 {
86 entry->hook (node, entry->data);
87 entry = entry->next;
88 }
89 }
90
91 /* Register HOOK to be called with DATA on each inserted node. */
92 varpool_node_hook_list *
93 symbol_table::add_varpool_insertion_hook (varpool_node_hook hook, void *data)
94 {
95 varpool_node_hook_list *entry;
96 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
97
98 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
99 entry->hook = hook;
100 entry->data = data;
101 entry->next = NULL;
102 while (*ptr)
103 ptr = &(*ptr)->next;
104 *ptr = entry;
105 return entry;
106 }
107
108 /* Remove ENTRY from the list of hooks called on inserted nodes. */
109 void
110 symbol_table::remove_varpool_insertion_hook (varpool_node_hook_list *entry)
111 {
112 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
113
114 while (*ptr != entry)
115 ptr = &(*ptr)->next;
116 *ptr = entry->next;
117 free (entry);
118 }
119
120 /* Call all node insertion hooks. */
121 void
122 symbol_table::call_varpool_insertion_hooks (varpool_node *node)
123 {
124 varpool_node_hook_list *entry = m_first_varpool_insertion_hook;
125 while (entry)
126 {
127 entry->hook (node, entry->data);
128 entry = entry->next;
129 }
130 }
131
132 /* Allocate new callgraph node and insert it into basic data structures. */
133
134 varpool_node *
135 varpool_node::create_empty (void)
136 {
137 varpool_node *node = ggc_cleared_alloc<varpool_node> ();
138 node->type = SYMTAB_VARIABLE;
139 return node;
140 }
141
142 /* Return varpool node assigned to DECL. Create new one when needed. */
143 varpool_node *
144 varpool_node::get_create (tree decl)
145 {
146 varpool_node *node = varpool_node::get (decl);
147 gcc_checking_assert (VAR_P (decl));
148 if (node)
149 return node;
150
151 node = varpool_node::create_empty ();
152 node->decl = decl;
153
154 if ((flag_openacc || flag_openmp)
155 && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
156 {
157 node->offloadable = 1;
158 if (ENABLE_OFFLOADING && !DECL_EXTERNAL (decl))
159 {
160 g->have_offload = true;
161 if (!in_lto_p)
162 vec_safe_push (offload_vars, decl);
163 }
164 }
165
166 node->register_symbol ();
167 return node;
168 }
169
170 /* Remove variable from symbol table. */
171
172 void
173 varpool_node::remove (void)
174 {
175 symtab->call_varpool_removal_hooks (this);
176 if (lto_file_data)
177 {
178 lto_free_function_in_decl_state_for_node (this);
179 lto_file_data = NULL;
180 }
181
182 /* When streaming we can have multiple nodes associated with decl. */
183 if (symtab->state == LTO_STREAMING)
184 ;
185 /* Keep constructor when it may be used for folding. We remove
186 references to external variables before final compilation. */
187 else if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node
188 && !ctor_useable_for_folding_p ())
189 remove_initializer ();
190
191 unregister ();
192 ggc_free (this);
193 }
194
195 /* Remove node initializer when it is no longer needed. */
196 void
197 varpool_node::remove_initializer (void)
198 {
199 if (DECL_INITIAL (decl)
200 && !DECL_IN_CONSTANT_POOL (decl)
201 /* Keep vtables for BINFO folding. */
202 && !DECL_VIRTUAL_P (decl)
203 /* FIXME: http://gcc.gnu.org/PR55395 */
204 && debug_info_level == DINFO_LEVEL_NONE
205 /* When doing declaration merging we have duplicate
206 entries for given decl. Do not attempt to remove
207 the bodies, or we will end up removing
208 wrong one. */
209 && symtab->state != LTO_STREAMING)
210 DECL_INITIAL (decl) = error_mark_node;
211 }
212
213 /* Dump given varpool node to F. */
214 void
215 varpool_node::dump (FILE *f)
216 {
217 dump_base (f);
218 fprintf (f, " Availability: %s\n",
219 symtab->function_flags_ready
220 ? cgraph_availability_names[get_availability ()]
221 : "not-ready");
222 fprintf (f, " Varpool flags:");
223 if (DECL_INITIAL (decl))
224 fprintf (f, " initialized");
225 if (output)
226 fprintf (f, " output");
227 if (used_by_single_function)
228 fprintf (f, " used-by-single-function");
229 if (TREE_READONLY (decl))
230 fprintf (f, " read-only");
231 if (ctor_useable_for_folding_p ())
232 fprintf (f, " const-value-known");
233 if (writeonly)
234 fprintf (f, " write-only");
235 if (tls_model)
236 fprintf (f, " tls-%s", tls_model_names [tls_model]);
237 fprintf (f, "\n");
238 }
239
240
241 /* Dump given varpool node to stderr. */
242 void varpool_node::debug (void)
243 {
244 varpool_node::dump (stderr);
245 }
246
247 /* Dump the variable pool to F. */
248 void
249 varpool_node::dump_varpool (FILE *f)
250 {
251 varpool_node *node;
252
253 fprintf (f, "variable pool:\n\n");
254 FOR_EACH_VARIABLE (node)
255 node->dump (f);
256 }
257
258 /* Dump the variable pool to stderr. */
259
260 DEBUG_FUNCTION void
261 varpool_node::debug_varpool (void)
262 {
263 dump_varpool (stderr);
264 }
265
266 /* Given an assembler name, lookup node. */
267 varpool_node *
268 varpool_node::get_for_asmname (tree asmname)
269 {
270 if (symtab_node *node = symtab_node::get_for_asmname (asmname))
271 return dyn_cast <varpool_node *> (node);
272 else
273 return NULL;
274 }
275
276 /* When doing LTO, read variable's constructor from disk if
277 it is not already present. */
278
279 tree
280 varpool_node::get_constructor (void)
281 {
282 lto_file_decl_data *file_data;
283 const char *data, *name;
284 size_t len;
285
286 if (DECL_INITIAL (decl) != error_mark_node
287 || !in_lto_p
288 || !lto_file_data)
289 return DECL_INITIAL (decl);
290
291 timevar_push (TV_IPA_LTO_CTORS_IN);
292
293 file_data = lto_file_data;
294 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
295
296 /* We may have renamed the declaration, e.g., a static function. */
297 name = lto_get_decl_name_mapping (file_data, name);
298 struct lto_in_decl_state *decl_state
299 = lto_get_function_in_decl_state (file_data, decl);
300
301 data = lto_get_section_data (file_data, LTO_section_function_body,
302 name, order - file_data->order_base,
303 &len, decl_state->compressed);
304 if (!data)
305 fatal_error (input_location, "%s: section %s.%d is missing",
306 file_data->file_name,
307 name, order - file_data->order_base);
308
309 if (!quiet_flag)
310 fprintf (stderr, " in:%s", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
311 lto_input_variable_constructor (file_data, this, data);
312 gcc_assert (DECL_INITIAL (decl) != error_mark_node);
313 lto_stats.num_function_bodies++;
314 lto_free_section_data (file_data, LTO_section_function_body, name,
315 data, len, decl_state->compressed);
316 lto_free_function_in_decl_state_for_node (this);
317 timevar_pop (TV_IPA_LTO_CTORS_IN);
318 return DECL_INITIAL (decl);
319 }
320
321 /* Return true if variable has constructor that can be used for folding. */
322
323 bool
324 varpool_node::ctor_useable_for_folding_p (void)
325 {
326 varpool_node *real_node = this;
327
328 if (real_node->alias && real_node->definition)
329 real_node = ultimate_alias_target ();
330
331 if (TREE_CODE (decl) == CONST_DECL
332 || DECL_IN_CONSTANT_POOL (decl))
333 return true;
334 if (TREE_THIS_VOLATILE (decl))
335 return false;
336
337 /* Avoid attempts to load constructors that was not streamed. */
338 if (in_lto_p && DECL_INITIAL (real_node->decl) == error_mark_node
339 && real_node->body_removed)
340 return false;
341
342 /* If we do not have a constructor, we can't use it. */
343 if (DECL_INITIAL (real_node->decl) == error_mark_node
344 && !real_node->lto_file_data)
345 return false;
346
347 /* Vtables are defined by their types and must match no matter of interposition
348 rules. */
349 if (DECL_VIRTUAL_P (decl))
350 {
351 /* The C++ front end creates VAR_DECLs for vtables of typeinfo
352 classes not defined in the current TU so that it can refer
353 to them from typeinfo objects. Avoid returning NULL_TREE. */
354 return DECL_INITIAL (real_node->decl) != NULL;
355 }
356
357 /* Alias of readonly variable is also readonly, since the variable is stored
358 in readonly memory. We also accept readonly aliases of non-readonly
359 locations assuming that user knows what he is asking for. */
360 if (!TREE_READONLY (decl) && !TREE_READONLY (real_node->decl))
361 return false;
362
363 /* Variables declared 'const' without an initializer
364 have zero as the initializer if they may not be
365 overridden at link or run time.
366
367 It is actually requirement for C++ compiler to optimize const variables
368 consistently. As a GNU extension, do not enforce this rule for user defined
369 weak variables, so we support interposition on:
370 static const int dummy = 0;
371 extern const int foo __attribute__((__weak__, __alias__("dummy")));
372 */
373 if ((!DECL_INITIAL (real_node->decl)
374 || (DECL_WEAK (decl) && !DECL_COMDAT (decl)))
375 && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
376 return false;
377
378 /* Variables declared `const' with an initializer are considered
379 to not be overwritable with different initializer by default.
380
381 ??? Previously we behaved so for scalar variables but not for array
382 accesses. */
383 return true;
384 }
385
386 /* If DECLARATION is constant variable and its initial value is known
387 (so we can do constant folding), return its constructor (DECL_INITIAL).
388 This may be an expression or NULL when DECL is initialized to 0.
389 Return ERROR_MARK_NODE otherwise.
390
391 In LTO this may actually trigger reading the constructor from disk.
392 For this reason varpool_ctor_useable_for_folding_p should be used when
393 the actual constructor value is not needed. */
394
395 tree
396 ctor_for_folding (tree decl)
397 {
398 varpool_node *node, *real_node;
399 tree real_decl;
400
401 if (!VAR_P (decl) && TREE_CODE (decl) != CONST_DECL)
402 return error_mark_node;
403
404 if (TREE_CODE (decl) == CONST_DECL
405 || DECL_IN_CONSTANT_POOL (decl))
406 return DECL_INITIAL (decl);
407
408 if (TREE_THIS_VOLATILE (decl))
409 return error_mark_node;
410
411 /* Do not care about automatic variables. Those are never initialized
412 anyway, because gimplifier expands the code. */
413 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
414 {
415 gcc_assert (!TREE_PUBLIC (decl));
416 return error_mark_node;
417 }
418
419 gcc_assert (VAR_P (decl));
420
421 real_node = node = varpool_node::get (decl);
422 if (node)
423 {
424 real_node = node->ultimate_alias_target ();
425 real_decl = real_node->decl;
426 }
427 else
428 real_decl = decl;
429
430 /* See if we are dealing with alias.
431 In most cases alias is just alternative symbol pointing to a given
432 constructor. This allows us to use interposition rules of DECL
433 constructor of REAL_NODE. However weakrefs are special by being just
434 alternative name of their target (if defined). */
435 if (decl != real_decl)
436 {
437 gcc_assert (!DECL_INITIAL (decl)
438 || (node->alias && node->get_alias_target () == real_node)
439 || DECL_INITIAL (decl) == error_mark_node);
440 while (node->transparent_alias && node->analyzed)
441 {
442 node = node->get_alias_target ();
443 decl = node->decl;
444 }
445 }
446
447 if ((!DECL_VIRTUAL_P (real_decl)
448 || DECL_INITIAL (real_decl) == error_mark_node
449 || !DECL_INITIAL (real_decl))
450 && (!node || !node->ctor_useable_for_folding_p ()))
451 return error_mark_node;
452
453 /* OK, we can return constructor. See if we need to fetch it from disk
454 in LTO mode. */
455 if (DECL_INITIAL (real_decl) != error_mark_node
456 || !in_lto_p)
457 return DECL_INITIAL (real_decl);
458 return real_node->get_constructor ();
459 }
460
461 /* Add the variable DECL to the varpool.
462 Unlike finalize_decl function is intended to be used
463 by middle end and allows insertion of new variable at arbitrary point
464 of compilation. */
465 void
466 varpool_node::add (tree decl)
467 {
468 varpool_node *node;
469 varpool_node::finalize_decl (decl);
470 node = varpool_node::get_create (decl);
471 symtab->call_varpool_insertion_hooks (node);
472 if (node->externally_visible_p ())
473 node->externally_visible = true;
474 if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl)))
475 node->no_reorder = 1;
476 }
477
478 /* Return variable availability. See cgraph.h for description of individual
479 return values. */
480 enum availability
481 varpool_node::get_availability (symtab_node *ref)
482 {
483 if (!definition)
484 return AVAIL_NOT_AVAILABLE;
485 if (!TREE_PUBLIC (decl))
486 return AVAIL_AVAILABLE;
487 if (DECL_IN_CONSTANT_POOL (decl)
488 || DECL_VIRTUAL_P (decl))
489 return AVAIL_AVAILABLE;
490 if (transparent_alias && definition)
491 {
492 enum availability avail;
493
494 ultimate_alias_target (&avail, ref);
495 return avail;
496 }
497 /* If this is a reference from symbol itself and there are no aliases, we
498 may be sure that the symbol was not interposed by something else because
499 the symbol itself would be unreachable otherwise. */
500 if ((this == ref && !has_aliases_p ())
501 || (ref && get_comdat_group ()
502 && get_comdat_group () == ref->get_comdat_group ()))
503 return AVAIL_AVAILABLE;
504 /* If the variable can be overwritten, return OVERWRITABLE. Takes
505 care of at least one notable extension - the COMDAT variables
506 used to share template instantiations in C++. */
507 if (decl_replaceable_p (decl)
508 || DECL_EXTERNAL (decl))
509 return AVAIL_INTERPOSABLE;
510 return AVAIL_AVAILABLE;
511 }
512
513 void
514 varpool_node::analyze (void)
515 {
516 /* When reading back varpool at LTO time, we re-construct the queue in order
517 to have "needed" list right by inserting all needed nodes into varpool.
518 We however don't want to re-analyze already analyzed nodes. */
519 if (!analyzed)
520 {
521 gcc_assert (!in_lto_p || symtab->function_flags_ready);
522 /* Compute the alignment early so function body expanders are
523 already informed about increased alignment. */
524 align_variable (decl, 0);
525 }
526 if (alias)
527 resolve_alias (varpool_node::get (alias_target));
528 else if (DECL_INITIAL (decl))
529 record_references_in_initializer (decl, analyzed);
530 analyzed = true;
531 }
532
533 /* Assemble thunks and aliases associated to varpool node. */
534
535 void
536 varpool_node::assemble_aliases (void)
537 {
538 ipa_ref *ref;
539
540 FOR_EACH_ALIAS (this, ref)
541 {
542 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
543 if (alias->symver)
544 do_assemble_symver (alias->decl,
545 DECL_ASSEMBLER_NAME (decl));
546 else if (!alias->transparent_alias)
547 do_assemble_alias (alias->decl,
548 DECL_ASSEMBLER_NAME (decl));
549 alias->assemble_aliases ();
550 }
551 }
552
553 /* Output one variable, if necessary. Return whether we output it. */
554
555 bool
556 varpool_node::assemble_decl (void)
557 {
558 /* Aliases are output when their target is produced or by
559 output_weakrefs. */
560 if (alias)
561 return false;
562
563 /* Constant pool is output from RTL land when the reference
564 survive till this level. */
565 if (DECL_IN_CONSTANT_POOL (decl) && TREE_ASM_WRITTEN (decl))
566 return false;
567
568 /* Decls with VALUE_EXPR should not be in the varpool at all. They
569 are not real variables, but just info for debugging and codegen.
570 Unfortunately at the moment emutls is not updating varpool correctly
571 after turning real vars into value_expr vars. */
572 if (DECL_HAS_VALUE_EXPR_P (decl)
573 && !targetm.have_tls)
574 return false;
575
576 /* Hard register vars do not need to be output. */
577 if (DECL_HARD_REGISTER (decl))
578 return false;
579
580 gcc_checking_assert (!TREE_ASM_WRITTEN (decl)
581 && VAR_P (decl)
582 && !DECL_HAS_VALUE_EXPR_P (decl));
583
584 if (!in_other_partition
585 && !DECL_EXTERNAL (decl))
586 {
587 get_constructor ();
588 assemble_variable (decl, 0, 1, 0);
589 gcc_assert (TREE_ASM_WRITTEN (decl));
590 gcc_assert (definition);
591 assemble_aliases ();
592 /* After the parser has generated debugging information, augment
593 this information with any new location/etc information that may
594 have become available after the compilation proper. */
595 debug_hooks->late_global_decl (decl);
596 return true;
597 }
598
599 return false;
600 }
601
602 /* Add NODE to queue starting at FIRST.
603 The queue is linked via AUX pointers and terminated by pointer to 1. */
604
605 static void
606 enqueue_node (varpool_node *node, varpool_node **first)
607 {
608 if (node->aux)
609 return;
610 gcc_checking_assert (*first);
611 node->aux = *first;
612 *first = node;
613 }
614
615 /* Optimization of function bodies might've rendered some variables as
616 unnecessary so we want to avoid these from being compiled. Re-do
617 reachability starting from variables that are either externally visible
618 or was referred from the asm output routines. */
619
620 void
621 symbol_table::remove_unreferenced_decls (void)
622 {
623 varpool_node *next, *node;
624 varpool_node *first = (varpool_node *)(void *)1;
625 int i;
626 ipa_ref *ref = NULL;
627 hash_set<varpool_node *> referenced;
628
629 if (seen_error ())
630 return;
631
632 if (dump_file)
633 fprintf (dump_file, "Trivially needed variables:");
634 FOR_EACH_DEFINED_VARIABLE (node)
635 {
636 if (node->analyzed
637 && (!node->can_remove_if_no_refs_p ()
638 /* We just expanded all function bodies. See if any of
639 them needed the variable. */
640 || DECL_RTL_SET_P (node->decl)))
641 {
642 enqueue_node (node, &first);
643 if (dump_file)
644 fprintf (dump_file, " %s", node->asm_name ());
645 }
646 }
647 while (first != (varpool_node *)(void *)1)
648 {
649 node = first;
650 first = (varpool_node *)first->aux;
651
652 if (node->same_comdat_group)
653 {
654 symtab_node *next;
655 for (next = node->same_comdat_group;
656 next != node;
657 next = next->same_comdat_group)
658 {
659 varpool_node *vnext = dyn_cast <varpool_node *> (next);
660 if (vnext && vnext->analyzed && !next->comdat_local_p ())
661 enqueue_node (vnext, &first);
662 }
663 }
664 for (i = 0; node->iterate_reference (i, ref); i++)
665 {
666 varpool_node *vnode = dyn_cast <varpool_node *> (ref->referred);
667 if (vnode
668 && !vnode->in_other_partition
669 && (!DECL_EXTERNAL (ref->referred->decl)
670 || vnode->alias)
671 && vnode->analyzed)
672 enqueue_node (vnode, &first);
673 else
674 {
675 referenced.add (vnode);
676 while (vnode && vnode->alias && vnode->definition)
677 {
678 vnode = vnode->get_alias_target ();
679 referenced.add (vnode);
680 }
681 }
682 }
683 }
684 if (dump_file)
685 fprintf (dump_file, "\nRemoving variables:");
686 for (node = first_defined_variable (); node; node = next)
687 {
688 next = next_defined_variable (node);
689 if (!node->aux && !node->no_reorder)
690 {
691 if (dump_file)
692 fprintf (dump_file, " %s", node->asm_name ());
693 if (referenced.contains(node))
694 node->remove_initializer ();
695 else
696 node->remove ();
697 }
698 }
699
700 if (dump_file)
701 fprintf (dump_file, "\n");
702 }
703
704 /* For variables in named sections make sure get_variable_section
705 is called before we switch to those sections. Then section
706 conflicts between read-only and read-only requiring relocations
707 sections can be resolved. */
708 void
709 varpool_node::finalize_named_section_flags (void)
710 {
711 if (!TREE_ASM_WRITTEN (decl)
712 && !alias
713 && !in_other_partition
714 && !DECL_EXTERNAL (decl)
715 && VAR_P (decl)
716 && !DECL_HAS_VALUE_EXPR_P (decl)
717 && get_section ())
718 get_variable_section (decl, false);
719 }
720
721 /* Output all variables enqueued to be assembled. */
722 bool
723 symbol_table::output_variables (void)
724 {
725 bool changed = false;
726 varpool_node *node;
727
728 if (seen_error ())
729 return false;
730
731 remove_unreferenced_decls ();
732
733 timevar_push (TV_VAROUT);
734
735 FOR_EACH_DEFINED_VARIABLE (node)
736 {
737 /* Handled in output_in_order. */
738 if (node->no_reorder)
739 continue;
740
741 node->finalize_named_section_flags ();
742 }
743
744 /* There is a similar loop in output_in_order. Please keep them in sync. */
745 FOR_EACH_VARIABLE (node)
746 {
747 /* Handled in output_in_order. */
748 if (node->no_reorder)
749 continue;
750 if (DECL_HARD_REGISTER (node->decl)
751 || DECL_HAS_VALUE_EXPR_P (node->decl))
752 continue;
753 if (node->definition)
754 changed |= node->assemble_decl ();
755 else
756 assemble_undefined_decl (node->decl);
757 }
758 timevar_pop (TV_VAROUT);
759 return changed;
760 }
761
762 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
763 Extra name aliases are output whenever DECL is output. */
764
765 varpool_node *
766 varpool_node::create_alias (tree alias, tree decl)
767 {
768 varpool_node *alias_node;
769
770 gcc_assert (VAR_P (decl));
771 gcc_assert (VAR_P (alias));
772 alias_node = varpool_node::get_create (alias);
773 alias_node->alias = true;
774 alias_node->definition = true;
775 alias_node->alias_target = decl;
776 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
777 alias_node->weakref = alias_node->transparent_alias = true;
778 return alias_node;
779 }
780
781 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
782 Extra name aliases are output whenever DECL is output. */
783
784 varpool_node *
785 varpool_node::create_extra_name_alias (tree alias, tree decl)
786 {
787 varpool_node *alias_node;
788
789 /* If aliases aren't supported by the assembler, fail. */
790 if (!TARGET_SUPPORTS_ALIASES)
791 return NULL;
792
793 alias_node = varpool_node::create_alias (alias, decl);
794 alias_node->cpp_implicit_alias = true;
795
796 /* Extra name alias mechanism creates aliases really late
797 via DECL_ASSEMBLER_NAME mechanism.
798 This is unfortunate because they are not going through the
799 standard channels. Ensure they get output. */
800 if (symtab->cpp_implicit_aliases_done)
801 alias_node->resolve_alias (varpool_node::get_create (decl));
802 return alias_node;
803 }
804
805 /* Worker for call_for_symbol_and_aliases. */
806
807 bool
808 varpool_node::call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *,
809 void *),
810 void *data,
811 bool include_overwritable)
812 {
813 ipa_ref *ref;
814
815 FOR_EACH_ALIAS (this, ref)
816 {
817 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
818 if (include_overwritable
819 || alias->get_availability () > AVAIL_INTERPOSABLE)
820 if (alias->call_for_symbol_and_aliases (callback, data,
821 include_overwritable))
822 return true;
823 }
824 return false;
825 }