2015-03-02 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / gcc / varpool.c
blob707f62f0d848d04a30ddcd50ee2212ab4dcf9d82
1 /* Callgraph handling code.
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 Contributed by Jan Hubicka
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
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.
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/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "hash-set.h"
26 #include "machmode.h"
27 #include "vec.h"
28 #include "double-int.h"
29 #include "input.h"
30 #include "alias.h"
31 #include "symtab.h"
32 #include "wide-int.h"
33 #include "inchash.h"
34 #include "tree.h"
35 #include "fold-const.h"
36 #include "varasm.h"
37 #include "predict.h"
38 #include "basic-block.h"
39 #include "hash-map.h"
40 #include "is-a.h"
41 #include "plugin-api.h"
42 #include "hard-reg-set.h"
43 #include "input.h"
44 #include "function.h"
45 #include "ipa-ref.h"
46 #include "cgraph.h"
47 #include "langhooks.h"
48 #include "diagnostic-core.h"
49 #include "timevar.h"
50 #include "debug.h"
51 #include "target.h"
52 #include "output.h"
53 #include "gimple-expr.h"
54 #include "flags.h"
55 #include "tree-ssa-alias.h"
56 #include "gimple.h"
57 #include "lto-streamer.h"
58 #include "context.h"
59 #include "omp-low.h"
61 const char * const tls_model_names[]={"none", "emulated",
62 "global-dynamic", "local-dynamic",
63 "initial-exec", "local-exec"};
65 /* List of hooks triggered on varpool_node events. */
66 struct varpool_node_hook_list {
67 varpool_node_hook hook;
68 void *data;
69 struct varpool_node_hook_list *next;
72 /* Register HOOK to be called with DATA on each removed node. */
73 varpool_node_hook_list *
74 symbol_table::add_varpool_removal_hook (varpool_node_hook hook, void *data)
76 varpool_node_hook_list *entry;
77 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
79 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
80 entry->hook = hook;
81 entry->data = data;
82 entry->next = NULL;
83 while (*ptr)
84 ptr = &(*ptr)->next;
85 *ptr = entry;
86 return entry;
89 /* Remove ENTRY from the list of hooks called on removing nodes. */
90 void
91 symbol_table::remove_varpool_removal_hook (varpool_node_hook_list *entry)
93 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
95 while (*ptr != entry)
96 ptr = &(*ptr)->next;
97 *ptr = entry->next;
98 free (entry);
101 /* Call all node removal hooks. */
102 void
103 symbol_table::call_varpool_removal_hooks (varpool_node *node)
105 varpool_node_hook_list *entry = m_first_varpool_removal_hook;
106 while (entry)
108 entry->hook (node, entry->data);
109 entry = entry->next;
113 /* Register HOOK to be called with DATA on each inserted node. */
114 varpool_node_hook_list *
115 symbol_table::add_varpool_insertion_hook (varpool_node_hook hook, void *data)
117 varpool_node_hook_list *entry;
118 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
120 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
121 entry->hook = hook;
122 entry->data = data;
123 entry->next = NULL;
124 while (*ptr)
125 ptr = &(*ptr)->next;
126 *ptr = entry;
127 return entry;
130 /* Remove ENTRY from the list of hooks called on inserted nodes. */
131 void
132 symbol_table::remove_varpool_insertion_hook (varpool_node_hook_list *entry)
134 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
136 while (*ptr != entry)
137 ptr = &(*ptr)->next;
138 *ptr = entry->next;
139 free (entry);
142 /* Call all node insertion hooks. */
143 void
144 symbol_table::call_varpool_insertion_hooks (varpool_node *node)
146 varpool_node_hook_list *entry = m_first_varpool_insertion_hook;
147 while (entry)
149 entry->hook (node, entry->data);
150 entry = entry->next;
154 /* Allocate new callgraph node and insert it into basic data structures. */
156 varpool_node *
157 varpool_node::create_empty (void)
159 varpool_node *node = ggc_cleared_alloc<varpool_node> ();
160 node->type = SYMTAB_VARIABLE;
161 return node;
164 /* Return varpool node assigned to DECL. Create new one when needed. */
165 varpool_node *
166 varpool_node::get_create (tree decl)
168 varpool_node *node = varpool_node::get (decl);
169 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
170 if (node)
171 return node;
173 node = varpool_node::create_empty ();
174 node->decl = decl;
176 if ((flag_openacc || flag_openmp)
177 && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
179 node->offloadable = 1;
180 #ifdef ENABLE_OFFLOADING
181 g->have_offload = true;
182 if (!in_lto_p)
183 vec_safe_push (offload_vars, decl);
184 node->force_output = 1;
185 #endif
188 node->register_symbol ();
189 return node;
192 /* Remove variable from symbol table. */
194 void
195 varpool_node::remove (void)
197 symtab->call_varpool_removal_hooks (this);
199 /* When streaming we can have multiple nodes associated with decl. */
200 if (symtab->state == LTO_STREAMING)
202 /* Keep constructor when it may be used for folding. We remove
203 references to external variables before final compilation. */
204 else if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node
205 && !ctor_useable_for_folding_p ())
206 remove_initializer ();
208 unregister ();
209 ggc_free (this);
212 /* Remove node initializer when it is no longer needed. */
213 void
214 varpool_node::remove_initializer (void)
216 if (DECL_INITIAL (decl)
217 && !DECL_IN_CONSTANT_POOL (decl)
218 /* Keep vtables for BINFO folding. */
219 && !DECL_VIRTUAL_P (decl)
220 /* FIXME: http://gcc.gnu.org/PR55395 */
221 && debug_info_level == DINFO_LEVEL_NONE
222 /* When doing declaration merging we have duplicate
223 entries for given decl. Do not attempt to remove
224 the boides, or we will end up remiving
225 wrong one. */
226 && symtab->state != LTO_STREAMING)
227 DECL_INITIAL (decl) = error_mark_node;
230 /* Dump given varpool node to F. */
231 void
232 varpool_node::dump (FILE *f)
234 dump_base (f);
235 fprintf (f, " Availability: %s\n",
236 symtab->function_flags_ready
237 ? cgraph_availability_names[get_availability ()]
238 : "not-ready");
239 fprintf (f, " Varpool flags:");
240 if (DECL_INITIAL (decl))
241 fprintf (f, " initialized");
242 if (output)
243 fprintf (f, " output");
244 if (used_by_single_function)
245 fprintf (f, " used-by-single-function");
246 if (need_bounds_init)
247 fprintf (f, " need-bounds-init");
248 if (TREE_READONLY (decl))
249 fprintf (f, " read-only");
250 if (ctor_useable_for_folding_p ())
251 fprintf (f, " const-value-known");
252 if (writeonly)
253 fprintf (f, " write-only");
254 if (tls_model)
255 fprintf (f, " tls-%s", tls_model_names [tls_model]);
256 fprintf (f, "\n");
260 /* Dump given varpool node to stderr. */
261 void varpool_node::debug (void)
263 varpool_node::dump (stderr);
266 /* Dump the variable pool to F. */
267 void
268 varpool_node::dump_varpool (FILE *f)
270 varpool_node *node;
272 fprintf (f, "variable pool:\n\n");
273 FOR_EACH_VARIABLE (node)
274 node->dump (f);
277 /* Dump the variable pool to stderr. */
279 DEBUG_FUNCTION void
280 varpool_node::debug_varpool (void)
282 dump_varpool (stderr);
285 /* Given an assembler name, lookup node. */
286 varpool_node *
287 varpool_node::get_for_asmname (tree asmname)
289 if (symtab_node *node = symtab_node::get_for_asmname (asmname))
290 return dyn_cast <varpool_node *> (node);
291 else
292 return NULL;
295 /* When doing LTO, read variable's constructor from disk if
296 it is not already present. */
298 tree
299 varpool_node::get_constructor (void)
301 lto_file_decl_data *file_data;
302 const char *data, *name;
303 size_t len;
305 if (DECL_INITIAL (decl) != error_mark_node
306 || !in_lto_p
307 || !lto_file_data)
308 return DECL_INITIAL (decl);
310 timevar_push (TV_IPA_LTO_CTORS_IN);
312 file_data = lto_file_data;
313 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
315 /* We may have renamed the declaration, e.g., a static function. */
316 name = lto_get_decl_name_mapping (file_data, name);
318 data = lto_get_section_data (file_data, LTO_section_function_body,
319 name, &len);
320 if (!data)
321 fatal_error (input_location, "%s: section %s is missing",
322 file_data->file_name,
323 name);
325 lto_input_variable_constructor (file_data, this, data);
326 lto_stats.num_function_bodies++;
327 lto_free_section_data (file_data, LTO_section_function_body, name,
328 data, len);
329 lto_free_function_in_decl_state_for_node (this);
330 timevar_pop (TV_IPA_LTO_CTORS_IN);
331 return DECL_INITIAL (decl);
334 /* Return true if variable has constructor that can be used for folding. */
336 bool
337 varpool_node::ctor_useable_for_folding_p (void)
339 varpool_node *real_node = this;
341 if (real_node->alias && real_node->definition)
342 real_node = ultimate_alias_target ();
344 if (TREE_CODE (decl) == CONST_DECL
345 || DECL_IN_CONSTANT_POOL (decl))
346 return true;
347 if (TREE_THIS_VOLATILE (decl))
348 return false;
350 /* If we do not have a constructor, we can't use it. */
351 if (DECL_INITIAL (real_node->decl) == error_mark_node
352 && !real_node->lto_file_data)
353 return false;
355 /* Avoid attempts to load constructors that was not streamed. */
356 if (flag_ltrans && DECL_INITIAL (real_node->decl) == error_mark_node
357 && real_node->body_removed)
358 return false;
360 /* Vtables are defined by their types and must match no matter of interposition
361 rules. */
362 if (DECL_VIRTUAL_P (decl))
364 /* The C++ front end creates VAR_DECLs for vtables of typeinfo
365 classes not defined in the current TU so that it can refer
366 to them from typeinfo objects. Avoid returning NULL_TREE. */
367 return DECL_INITIAL (real_node->decl) != NULL;
370 /* Alias of readonly variable is also readonly, since the variable is stored
371 in readonly memory. We also accept readonly aliases of non-readonly
372 locations assuming that user knows what he is asking for. */
373 if (!TREE_READONLY (decl) && !TREE_READONLY (real_node->decl))
374 return false;
376 /* Variables declared 'const' without an initializer
377 have zero as the initializer if they may not be
378 overridden at link or run time.
380 It is actually requirement for C++ compiler to optimize const variables
381 consistently. As a GNU extension, do not enfore this rule for user defined
382 weak variables, so we support interposition on:
383 static const int dummy = 0;
384 extern const int foo __attribute__((__weak__, __alias__("dummy")));
386 if ((!DECL_INITIAL (real_node->decl)
387 || (DECL_WEAK (decl) && !DECL_COMDAT (decl)))
388 && (DECL_EXTERNAL (decl) || decl_replaceable_p (decl)))
389 return false;
391 /* Variables declared `const' with an initializer are considered
392 to not be overwritable with different initializer by default.
394 ??? Previously we behaved so for scalar variables but not for array
395 accesses. */
396 return true;
399 /* If DECLARATION is constant variable and its initial value is known
400 (so we can do constant folding), return its constructor (DECL_INITIAL).
401 This may be an expression or NULL when DECL is initialized to 0.
402 Return ERROR_MARK_NODE otherwise.
404 In LTO this may actually trigger reading the constructor from disk.
405 For this reason varpool_ctor_useable_for_folding_p should be used when
406 the actual constructor value is not needed. */
408 tree
409 ctor_for_folding (tree decl)
411 varpool_node *node, *real_node;
412 tree real_decl;
414 if (TREE_CODE (decl) != VAR_DECL
415 && TREE_CODE (decl) != CONST_DECL)
416 return error_mark_node;
418 /* Static constant bounds are created to be
419 used instead of constants and therefore
420 do not let folding it. */
421 if (POINTER_BOUNDS_P (decl))
422 return error_mark_node;
424 if (TREE_CODE (decl) == CONST_DECL
425 || DECL_IN_CONSTANT_POOL (decl))
426 return DECL_INITIAL (decl);
428 if (TREE_THIS_VOLATILE (decl))
429 return error_mark_node;
431 /* Do not care about automatic variables. Those are never initialized
432 anyway, because gimplifier exapnds the code. */
433 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
435 gcc_assert (!TREE_PUBLIC (decl));
436 return error_mark_node;
439 gcc_assert (TREE_CODE (decl) == VAR_DECL);
441 real_node = node = varpool_node::get (decl);
442 if (node)
444 real_node = node->ultimate_alias_target ();
445 real_decl = real_node->decl;
447 else
448 real_decl = decl;
450 /* See if we are dealing with alias.
451 In most cases alias is just alternative symbol pointing to a given
452 constructor. This allows us to use interposition rules of DECL
453 constructor of REAL_NODE. However weakrefs are special by being just
454 alternative name of their target (if defined). */
455 if (decl != real_decl)
457 gcc_assert (!DECL_INITIAL (decl)
458 || (node->alias && node->get_alias_target () == real_node)
459 || DECL_INITIAL (decl) == error_mark_node);
460 if (node->weakref)
462 node = node->get_alias_target ();
463 decl = node->decl;
467 if ((!DECL_VIRTUAL_P (real_decl)
468 || DECL_INITIAL (real_decl) == error_mark_node
469 || !DECL_INITIAL (real_decl))
470 && (!node || !node->ctor_useable_for_folding_p ()))
471 return error_mark_node;
473 /* OK, we can return constructor. See if we need to fetch it from disk
474 in LTO mode. */
475 if (DECL_INITIAL (real_decl) != error_mark_node
476 || !in_lto_p)
477 return DECL_INITIAL (real_decl);
478 return real_node->get_constructor ();
481 /* Add the variable DECL to the varpool.
482 Unlike finalize_decl function is intended to be used
483 by middle end and allows insertion of new variable at arbitrary point
484 of compilation. */
485 void
486 varpool_node::add (tree decl)
488 varpool_node *node;
489 varpool_node::finalize_decl (decl);
490 node = varpool_node::get_create (decl);
491 symtab->call_varpool_insertion_hooks (node);
492 if (node->externally_visible_p ())
493 node->externally_visible = true;
494 if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl)))
495 node->no_reorder = 1;
498 /* Return variable availability. See cgraph.h for description of individual
499 return values. */
500 enum availability
501 varpool_node::get_availability (void)
503 if (!definition)
504 return AVAIL_NOT_AVAILABLE;
505 if (!TREE_PUBLIC (decl))
506 return AVAIL_AVAILABLE;
507 if (DECL_IN_CONSTANT_POOL (decl)
508 || DECL_VIRTUAL_P (decl))
509 return AVAIL_AVAILABLE;
510 if (alias && weakref)
512 enum availability avail;
514 ultimate_alias_target (&avail)->get_availability ();
515 return avail;
517 /* If the variable can be overwritten, return OVERWRITABLE. Takes
518 care of at least one notable extension - the COMDAT variables
519 used to share template instantiations in C++. */
520 if (decl_replaceable_p (decl)
521 || DECL_EXTERNAL (decl))
522 return AVAIL_INTERPOSABLE;
523 return AVAIL_AVAILABLE;
526 void
527 varpool_node::analyze (void)
529 /* When reading back varpool at LTO time, we re-construct the queue in order
530 to have "needed" list right by inserting all needed nodes into varpool.
531 We however don't want to re-analyze already analyzed nodes. */
532 if (!analyzed)
534 gcc_assert (!in_lto_p || symtab->function_flags_ready);
535 /* Compute the alignment early so function body expanders are
536 already informed about increased alignment. */
537 align_variable (decl, 0);
539 if (alias)
540 resolve_alias (varpool_node::get (alias_target));
541 else if (DECL_INITIAL (decl))
542 record_references_in_initializer (decl, analyzed);
543 analyzed = true;
546 /* Assemble thunks and aliases associated to varpool node. */
548 void
549 varpool_node::assemble_aliases (void)
551 ipa_ref *ref;
553 FOR_EACH_ALIAS (this, ref)
555 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
556 do_assemble_alias (alias->decl,
557 DECL_ASSEMBLER_NAME (decl));
558 alias->assemble_aliases ();
562 /* Output one variable, if necessary. Return whether we output it. */
564 bool
565 varpool_node::assemble_decl (void)
567 /* Aliases are outout when their target is produced or by
568 output_weakrefs. */
569 if (alias)
570 return false;
572 /* Constant pool is output from RTL land when the reference
573 survive till this level. */
574 if (DECL_IN_CONSTANT_POOL (decl) && TREE_ASM_WRITTEN (decl))
575 return false;
577 /* Decls with VALUE_EXPR should not be in the varpool at all. They
578 are not real variables, but just info for debugging and codegen.
579 Unfortunately at the moment emutls is not updating varpool correctly
580 after turning real vars into value_expr vars. */
581 if (DECL_HAS_VALUE_EXPR_P (decl)
582 && !targetm.have_tls)
583 return false;
585 /* Hard register vars do not need to be output. */
586 if (DECL_HARD_REGISTER (decl))
587 return false;
589 gcc_checking_assert (!TREE_ASM_WRITTEN (decl)
590 && TREE_CODE (decl) == VAR_DECL
591 && !DECL_HAS_VALUE_EXPR_P (decl));
593 if (!in_other_partition
594 && !DECL_EXTERNAL (decl))
596 get_constructor ();
597 assemble_variable (decl, 0, 1, 0);
598 gcc_assert (TREE_ASM_WRITTEN (decl));
599 gcc_assert (definition);
600 assemble_aliases ();
601 return true;
604 return false;
607 /* Add NODE to queue starting at FIRST.
608 The queue is linked via AUX pointers and terminated by pointer to 1. */
610 static void
611 enqueue_node (varpool_node *node, varpool_node **first)
613 if (node->aux)
614 return;
615 gcc_checking_assert (*first);
616 node->aux = *first;
617 *first = node;
620 /* Optimization of function bodies might've rendered some variables as
621 unnecessary so we want to avoid these from being compiled. Re-do
622 reachability starting from variables that are either externally visible
623 or was referred from the asm output routines. */
625 void
626 symbol_table::remove_unreferenced_decls (void)
628 varpool_node *next, *node;
629 varpool_node *first = (varpool_node *)(void *)1;
630 int i;
631 ipa_ref *ref = NULL;
632 hash_set<varpool_node *> referenced;
634 if (seen_error ())
635 return;
637 if (dump_file)
638 fprintf (dump_file, "Trivially needed variables:");
639 FOR_EACH_DEFINED_VARIABLE (node)
641 if (node->analyzed
642 && (!node->can_remove_if_no_refs_p ()
643 /* We just expanded all function bodies. See if any of
644 them needed the variable. */
645 || DECL_RTL_SET_P (node->decl)))
647 enqueue_node (node, &first);
648 if (dump_file)
649 fprintf (dump_file, " %s", node->asm_name ());
652 while (first != (varpool_node *)(void *)1)
654 node = first;
655 first = (varpool_node *)first->aux;
657 if (node->same_comdat_group)
659 symtab_node *next;
660 for (next = node->same_comdat_group;
661 next != node;
662 next = next->same_comdat_group)
664 varpool_node *vnext = dyn_cast <varpool_node *> (next);
665 if (vnext && vnext->analyzed && !next->comdat_local_p ())
666 enqueue_node (vnext, &first);
669 for (i = 0; node->iterate_reference (i, ref); i++)
671 varpool_node *vnode = dyn_cast <varpool_node *> (ref->referred);
672 if (vnode
673 && !vnode->in_other_partition
674 && (!DECL_EXTERNAL (ref->referred->decl)
675 || vnode->alias)
676 && vnode->analyzed)
677 enqueue_node (vnode, &first);
678 else
679 referenced.add (node);
682 if (dump_file)
683 fprintf (dump_file, "\nRemoving variables:");
684 for (node = first_defined_variable (); node; node = next)
686 next = next_defined_variable (node);
687 if (!node->aux && !node->no_reorder)
689 if (dump_file)
690 fprintf (dump_file, " %s", node->asm_name ());
691 if (referenced.contains(node))
692 node->remove_initializer ();
693 else
694 node->remove ();
698 if (dump_file)
699 fprintf (dump_file, "\n");
702 /* For variables in named sections make sure get_variable_section
703 is called before we switch to those sections. Then section
704 conflicts between read-only and read-only requiring relocations
705 sections can be resolved. */
706 void
707 varpool_node::finalize_named_section_flags (void)
709 if (!TREE_ASM_WRITTEN (decl)
710 && !alias
711 && !in_other_partition
712 && !DECL_EXTERNAL (decl)
713 && TREE_CODE (decl) == VAR_DECL
714 && !DECL_HAS_VALUE_EXPR_P (decl)
715 && get_section ())
716 get_variable_section (decl, false);
719 /* Output all variables enqueued to be assembled. */
720 bool
721 symbol_table::output_variables (void)
723 bool changed = false;
724 varpool_node *node;
726 if (seen_error ())
727 return false;
729 remove_unreferenced_decls ();
731 timevar_push (TV_VAROUT);
733 FOR_EACH_VARIABLE (node)
734 if (!node->definition)
735 assemble_undefined_decl (node->decl);
736 FOR_EACH_DEFINED_VARIABLE (node)
738 /* Handled in output_in_order. */
739 if (node->no_reorder)
740 continue;
742 node->finalize_named_section_flags ();
745 FOR_EACH_DEFINED_VARIABLE (node)
747 /* Handled in output_in_order. */
748 if (node->no_reorder)
749 continue;
750 if (node->assemble_decl ())
751 changed = true;
753 timevar_pop (TV_VAROUT);
754 return changed;
757 /* Create a new global variable of type TYPE. */
758 tree
759 add_new_static_var (tree type)
761 tree new_decl;
762 varpool_node *new_node;
764 new_decl = create_tmp_var_raw (type);
765 DECL_NAME (new_decl) = create_tmp_var_name (NULL);
766 TREE_READONLY (new_decl) = 0;
767 TREE_STATIC (new_decl) = 1;
768 TREE_USED (new_decl) = 1;
769 DECL_CONTEXT (new_decl) = NULL_TREE;
770 DECL_ABSTRACT_P (new_decl) = false;
771 lang_hooks.dup_lang_specific_decl (new_decl);
772 new_node = varpool_node::get_create (new_decl);
773 varpool_node::finalize_decl (new_decl);
775 return new_node->decl;
778 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
779 Extra name aliases are output whenever DECL is output. */
781 varpool_node *
782 varpool_node::create_alias (tree alias, tree decl)
784 varpool_node *alias_node;
786 gcc_assert (TREE_CODE (decl) == VAR_DECL);
787 gcc_assert (TREE_CODE (alias) == VAR_DECL);
788 alias_node = varpool_node::get_create (alias);
789 alias_node->alias = true;
790 alias_node->definition = true;
791 alias_node->alias_target = decl;
792 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
793 alias_node->weakref = true;
794 return alias_node;
797 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
798 Extra name aliases are output whenever DECL is output. */
800 varpool_node *
801 varpool_node::create_extra_name_alias (tree alias, tree decl)
803 varpool_node *alias_node;
805 #ifndef ASM_OUTPUT_DEF
806 /* If aliases aren't supported by the assembler, fail. */
807 return NULL;
808 #endif
809 alias_node = varpool_node::create_alias (alias, decl);
810 alias_node->cpp_implicit_alias = true;
812 /* Extra name alias mechanizm creates aliases really late
813 via DECL_ASSEMBLER_NAME mechanizm.
814 This is unfortunate because they are not going through the
815 standard channels. Ensure they get output. */
816 if (symtab->cpp_implicit_aliases_done)
817 alias_node->resolve_alias (varpool_node::get_create (decl));
818 return alias_node;
821 /* Worker for call_for_symbol_and_aliases. */
823 bool
824 varpool_node::call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *,
825 void *),
826 void *data,
827 bool include_overwritable)
829 ipa_ref *ref;
831 FOR_EACH_ALIAS (this, ref)
833 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
834 if (include_overwritable
835 || alias->get_availability () > AVAIL_INTERPOSABLE)
836 if (alias->call_for_symbol_and_aliases (callback, data,
837 include_overwritable))
838 return true;
840 return false;