]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/varpool.c
alias.c: Reorder #include statements and remove duplicates.
[thirdparty/gcc.git] / gcc / varpool.c
1 /* Callgraph handling code.
2 Copyright (C) 2003-2015 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 "diagnostic-core.h"
32 #include "alias.h"
33 #include "fold-const.h"
34 #include "varasm.h"
35 #include "langhooks.h"
36 #include "debug.h"
37 #include "output.h"
38 #include "flags.h"
39 #include "context.h"
40 #include "omp-low.h"
41
42 const char * const tls_model_names[]={"none", "emulated",
43 "global-dynamic", "local-dynamic",
44 "initial-exec", "local-exec"};
45
46 /* List of hooks triggered on varpool_node events. */
47 struct varpool_node_hook_list {
48 varpool_node_hook hook;
49 void *data;
50 struct varpool_node_hook_list *next;
51 };
52
53 /* Register HOOK to be called with DATA on each removed node. */
54 varpool_node_hook_list *
55 symbol_table::add_varpool_removal_hook (varpool_node_hook hook, void *data)
56 {
57 varpool_node_hook_list *entry;
58 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
59
60 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
61 entry->hook = hook;
62 entry->data = data;
63 entry->next = NULL;
64 while (*ptr)
65 ptr = &(*ptr)->next;
66 *ptr = entry;
67 return entry;
68 }
69
70 /* Remove ENTRY from the list of hooks called on removing nodes. */
71 void
72 symbol_table::remove_varpool_removal_hook (varpool_node_hook_list *entry)
73 {
74 varpool_node_hook_list **ptr = &m_first_varpool_removal_hook;
75
76 while (*ptr != entry)
77 ptr = &(*ptr)->next;
78 *ptr = entry->next;
79 free (entry);
80 }
81
82 /* Call all node removal hooks. */
83 void
84 symbol_table::call_varpool_removal_hooks (varpool_node *node)
85 {
86 varpool_node_hook_list *entry = m_first_varpool_removal_hook;
87 while (entry)
88 {
89 entry->hook (node, entry->data);
90 entry = entry->next;
91 }
92 }
93
94 /* Register HOOK to be called with DATA on each inserted node. */
95 varpool_node_hook_list *
96 symbol_table::add_varpool_insertion_hook (varpool_node_hook hook, void *data)
97 {
98 varpool_node_hook_list *entry;
99 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
100
101 entry = (varpool_node_hook_list *) xmalloc (sizeof (*entry));
102 entry->hook = hook;
103 entry->data = data;
104 entry->next = NULL;
105 while (*ptr)
106 ptr = &(*ptr)->next;
107 *ptr = entry;
108 return entry;
109 }
110
111 /* Remove ENTRY from the list of hooks called on inserted nodes. */
112 void
113 symbol_table::remove_varpool_insertion_hook (varpool_node_hook_list *entry)
114 {
115 varpool_node_hook_list **ptr = &m_first_varpool_insertion_hook;
116
117 while (*ptr != entry)
118 ptr = &(*ptr)->next;
119 *ptr = entry->next;
120 free (entry);
121 }
122
123 /* Call all node insertion hooks. */
124 void
125 symbol_table::call_varpool_insertion_hooks (varpool_node *node)
126 {
127 varpool_node_hook_list *entry = m_first_varpool_insertion_hook;
128 while (entry)
129 {
130 entry->hook (node, entry->data);
131 entry = entry->next;
132 }
133 }
134
135 /* Allocate new callgraph node and insert it into basic data structures. */
136
137 varpool_node *
138 varpool_node::create_empty (void)
139 {
140 varpool_node *node = ggc_cleared_alloc<varpool_node> ();
141 node->type = SYMTAB_VARIABLE;
142 return node;
143 }
144
145 /* Return varpool node assigned to DECL. Create new one when needed. */
146 varpool_node *
147 varpool_node::get_create (tree decl)
148 {
149 varpool_node *node = varpool_node::get (decl);
150 gcc_checking_assert (TREE_CODE (decl) == VAR_DECL);
151 if (node)
152 return node;
153
154 node = varpool_node::create_empty ();
155 node->decl = decl;
156
157 if ((flag_openacc || flag_openmp) && !DECL_EXTERNAL (decl)
158 && lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)))
159 {
160 node->offloadable = 1;
161 #ifdef ENABLE_OFFLOADING
162 g->have_offload = true;
163 if (!in_lto_p)
164 vec_safe_push (offload_vars, decl);
165 node->force_output = 1;
166 #endif
167 }
168
169 node->register_symbol ();
170 return node;
171 }
172
173 /* Remove variable from symbol table. */
174
175 void
176 varpool_node::remove (void)
177 {
178 symtab->call_varpool_removal_hooks (this);
179 if (lto_file_data)
180 {
181 lto_free_function_in_decl_state_for_node (this);
182 lto_file_data = NULL;
183 }
184
185 /* When streaming we can have multiple nodes associated with decl. */
186 if (symtab->state == LTO_STREAMING)
187 ;
188 /* Keep constructor when it may be used for folding. We remove
189 references to external variables before final compilation. */
190 else if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node
191 && !ctor_useable_for_folding_p ())
192 remove_initializer ();
193
194 unregister ();
195 ggc_free (this);
196 }
197
198 /* Remove node initializer when it is no longer needed. */
199 void
200 varpool_node::remove_initializer (void)
201 {
202 if (DECL_INITIAL (decl)
203 && !DECL_IN_CONSTANT_POOL (decl)
204 /* Keep vtables for BINFO folding. */
205 && !DECL_VIRTUAL_P (decl)
206 /* FIXME: http://gcc.gnu.org/PR55395 */
207 && debug_info_level == DINFO_LEVEL_NONE
208 /* When doing declaration merging we have duplicate
209 entries for given decl. Do not attempt to remove
210 the boides, or we will end up remiving
211 wrong one. */
212 && symtab->state != LTO_STREAMING)
213 DECL_INITIAL (decl) = error_mark_node;
214 }
215
216 /* Dump given varpool node to F. */
217 void
218 varpool_node::dump (FILE *f)
219 {
220 dump_base (f);
221 fprintf (f, " Availability: %s\n",
222 symtab->function_flags_ready
223 ? cgraph_availability_names[get_availability ()]
224 : "not-ready");
225 fprintf (f, " Varpool flags:");
226 if (DECL_INITIAL (decl))
227 fprintf (f, " initialized");
228 if (output)
229 fprintf (f, " output");
230 if (used_by_single_function)
231 fprintf (f, " used-by-single-function");
232 if (need_bounds_init)
233 fprintf (f, " need-bounds-init");
234 if (TREE_READONLY (decl))
235 fprintf (f, " read-only");
236 if (ctor_useable_for_folding_p ())
237 fprintf (f, " const-value-known");
238 if (writeonly)
239 fprintf (f, " write-only");
240 if (tls_model)
241 fprintf (f, " tls-%s", tls_model_names [tls_model]);
242 fprintf (f, "\n");
243 }
244
245
246 /* Dump given varpool node to stderr. */
247 void varpool_node::debug (void)
248 {
249 varpool_node::dump (stderr);
250 }
251
252 /* Dump the variable pool to F. */
253 void
254 varpool_node::dump_varpool (FILE *f)
255 {
256 varpool_node *node;
257
258 fprintf (f, "variable pool:\n\n");
259 FOR_EACH_VARIABLE (node)
260 node->dump (f);
261 }
262
263 /* Dump the variable pool to stderr. */
264
265 DEBUG_FUNCTION void
266 varpool_node::debug_varpool (void)
267 {
268 dump_varpool (stderr);
269 }
270
271 /* Given an assembler name, lookup node. */
272 varpool_node *
273 varpool_node::get_for_asmname (tree asmname)
274 {
275 if (symtab_node *node = symtab_node::get_for_asmname (asmname))
276 return dyn_cast <varpool_node *> (node);
277 else
278 return NULL;
279 }
280
281 /* When doing LTO, read variable's constructor from disk if
282 it is not already present. */
283
284 tree
285 varpool_node::get_constructor (void)
286 {
287 lto_file_decl_data *file_data;
288 const char *data, *name;
289 size_t len;
290
291 if (DECL_INITIAL (decl) != error_mark_node
292 || !in_lto_p
293 || !lto_file_data)
294 return DECL_INITIAL (decl);
295
296 timevar_push (TV_IPA_LTO_CTORS_IN);
297
298 file_data = lto_file_data;
299 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
300
301 /* We may have renamed the declaration, e.g., a static function. */
302 name = lto_get_decl_name_mapping (file_data, name);
303
304 data = lto_get_section_data (file_data, LTO_section_function_body,
305 name, &len);
306 if (!data)
307 fatal_error (input_location, "%s: section %s is missing",
308 file_data->file_name,
309 name);
310
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);
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 /* If we do not have a constructor, we can't use it. */
338 if (DECL_INITIAL (real_node->decl) == error_mark_node
339 && !real_node->lto_file_data)
340 return false;
341
342 /* Avoid attempts to load constructors that was not streamed. */
343 if (flag_ltrans && DECL_INITIAL (real_node->decl) == error_mark_node
344 && real_node->body_removed)
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 enfore 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 (TREE_CODE (decl) != VAR_DECL
402 && TREE_CODE (decl) != CONST_DECL)
403 return error_mark_node;
404
405 /* Static constant bounds are created to be
406 used instead of constants and therefore
407 do not let folding it. */
408 if (POINTER_BOUNDS_P (decl))
409 return error_mark_node;
410
411 if (TREE_CODE (decl) == CONST_DECL
412 || DECL_IN_CONSTANT_POOL (decl))
413 return DECL_INITIAL (decl);
414
415 if (TREE_THIS_VOLATILE (decl))
416 return error_mark_node;
417
418 /* Do not care about automatic variables. Those are never initialized
419 anyway, because gimplifier exapnds the code. */
420 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
421 {
422 gcc_assert (!TREE_PUBLIC (decl));
423 return error_mark_node;
424 }
425
426 gcc_assert (TREE_CODE (decl) == VAR_DECL);
427
428 real_node = node = varpool_node::get (decl);
429 if (node)
430 {
431 real_node = node->ultimate_alias_target ();
432 real_decl = real_node->decl;
433 }
434 else
435 real_decl = decl;
436
437 /* See if we are dealing with alias.
438 In most cases alias is just alternative symbol pointing to a given
439 constructor. This allows us to use interposition rules of DECL
440 constructor of REAL_NODE. However weakrefs are special by being just
441 alternative name of their target (if defined). */
442 if (decl != real_decl)
443 {
444 gcc_assert (!DECL_INITIAL (decl)
445 || (node->alias && node->get_alias_target () == real_node)
446 || DECL_INITIAL (decl) == error_mark_node);
447 if (node->weakref)
448 {
449 node = node->get_alias_target ();
450 decl = node->decl;
451 }
452 }
453
454 if ((!DECL_VIRTUAL_P (real_decl)
455 || DECL_INITIAL (real_decl) == error_mark_node
456 || !DECL_INITIAL (real_decl))
457 && (!node || !node->ctor_useable_for_folding_p ()))
458 return error_mark_node;
459
460 /* OK, we can return constructor. See if we need to fetch it from disk
461 in LTO mode. */
462 if (DECL_INITIAL (real_decl) != error_mark_node
463 || !in_lto_p)
464 return DECL_INITIAL (real_decl);
465 return real_node->get_constructor ();
466 }
467
468 /* Add the variable DECL to the varpool.
469 Unlike finalize_decl function is intended to be used
470 by middle end and allows insertion of new variable at arbitrary point
471 of compilation. */
472 void
473 varpool_node::add (tree decl)
474 {
475 varpool_node *node;
476 varpool_node::finalize_decl (decl);
477 node = varpool_node::get_create (decl);
478 symtab->call_varpool_insertion_hooks (node);
479 if (node->externally_visible_p ())
480 node->externally_visible = true;
481 if (lookup_attribute ("no_reorder", DECL_ATTRIBUTES (decl)))
482 node->no_reorder = 1;
483 }
484
485 /* Return variable availability. See cgraph.h for description of individual
486 return values. */
487 enum availability
488 varpool_node::get_availability (void)
489 {
490 if (!definition)
491 return AVAIL_NOT_AVAILABLE;
492 if (!TREE_PUBLIC (decl))
493 return AVAIL_AVAILABLE;
494 if (DECL_IN_CONSTANT_POOL (decl)
495 || DECL_VIRTUAL_P (decl))
496 return AVAIL_AVAILABLE;
497 if (alias && weakref)
498 {
499 enum availability avail;
500
501 ultimate_alias_target (&avail)->get_availability ();
502 return avail;
503 }
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 do_assemble_alias (alias->decl,
544 DECL_ASSEMBLER_NAME (decl));
545 alias->assemble_aliases ();
546 }
547 }
548
549 /* Output one variable, if necessary. Return whether we output it. */
550
551 bool
552 varpool_node::assemble_decl (void)
553 {
554 /* Aliases are outout when their target is produced or by
555 output_weakrefs. */
556 if (alias)
557 return false;
558
559 /* Constant pool is output from RTL land when the reference
560 survive till this level. */
561 if (DECL_IN_CONSTANT_POOL (decl) && TREE_ASM_WRITTEN (decl))
562 return false;
563
564 /* Decls with VALUE_EXPR should not be in the varpool at all. They
565 are not real variables, but just info for debugging and codegen.
566 Unfortunately at the moment emutls is not updating varpool correctly
567 after turning real vars into value_expr vars. */
568 if (DECL_HAS_VALUE_EXPR_P (decl)
569 && !targetm.have_tls)
570 return false;
571
572 /* Hard register vars do not need to be output. */
573 if (DECL_HARD_REGISTER (decl))
574 return false;
575
576 gcc_checking_assert (!TREE_ASM_WRITTEN (decl)
577 && TREE_CODE (decl) == VAR_DECL
578 && !DECL_HAS_VALUE_EXPR_P (decl));
579
580 if (!in_other_partition
581 && !DECL_EXTERNAL (decl))
582 {
583 get_constructor ();
584 assemble_variable (decl, 0, 1, 0);
585 gcc_assert (TREE_ASM_WRITTEN (decl));
586 gcc_assert (definition);
587 assemble_aliases ();
588 /* After the parser has generated debugging information, augment
589 this information with any new location/etc information that may
590 have become available after the compilation proper. */
591 timevar_start (TV_PHASE_DBGINFO);
592 debug_hooks->late_global_decl (decl);
593 timevar_stop (TV_PHASE_DBGINFO);
594 return true;
595 }
596
597 return false;
598 }
599
600 /* Add NODE to queue starting at FIRST.
601 The queue is linked via AUX pointers and terminated by pointer to 1. */
602
603 static void
604 enqueue_node (varpool_node *node, varpool_node **first)
605 {
606 if (node->aux)
607 return;
608 gcc_checking_assert (*first);
609 node->aux = *first;
610 *first = node;
611 }
612
613 /* Optimization of function bodies might've rendered some variables as
614 unnecessary so we want to avoid these from being compiled. Re-do
615 reachability starting from variables that are either externally visible
616 or was referred from the asm output routines. */
617
618 void
619 symbol_table::remove_unreferenced_decls (void)
620 {
621 varpool_node *next, *node;
622 varpool_node *first = (varpool_node *)(void *)1;
623 int i;
624 ipa_ref *ref = NULL;
625 hash_set<varpool_node *> referenced;
626
627 if (seen_error ())
628 return;
629
630 if (dump_file)
631 fprintf (dump_file, "Trivially needed variables:");
632 FOR_EACH_DEFINED_VARIABLE (node)
633 {
634 if (node->analyzed
635 && (!node->can_remove_if_no_refs_p ()
636 /* We just expanded all function bodies. See if any of
637 them needed the variable. */
638 || DECL_RTL_SET_P (node->decl)))
639 {
640 enqueue_node (node, &first);
641 if (dump_file)
642 fprintf (dump_file, " %s", node->asm_name ());
643 }
644 }
645 while (first != (varpool_node *)(void *)1)
646 {
647 node = first;
648 first = (varpool_node *)first->aux;
649
650 if (node->same_comdat_group)
651 {
652 symtab_node *next;
653 for (next = node->same_comdat_group;
654 next != node;
655 next = next->same_comdat_group)
656 {
657 varpool_node *vnext = dyn_cast <varpool_node *> (next);
658 if (vnext && vnext->analyzed && !next->comdat_local_p ())
659 enqueue_node (vnext, &first);
660 }
661 }
662 for (i = 0; node->iterate_reference (i, ref); i++)
663 {
664 varpool_node *vnode = dyn_cast <varpool_node *> (ref->referred);
665 if (vnode
666 && !vnode->in_other_partition
667 && (!DECL_EXTERNAL (ref->referred->decl)
668 || vnode->alias)
669 && vnode->analyzed)
670 enqueue_node (vnode, &first);
671 else
672 referenced.add (node);
673 }
674 }
675 if (dump_file)
676 fprintf (dump_file, "\nRemoving variables:");
677 for (node = first_defined_variable (); node; node = next)
678 {
679 next = next_defined_variable (node);
680 if (!node->aux && !node->no_reorder)
681 {
682 if (dump_file)
683 fprintf (dump_file, " %s", node->asm_name ());
684 if (referenced.contains(node))
685 node->remove_initializer ();
686 else
687 node->remove ();
688 }
689 }
690
691 if (dump_file)
692 fprintf (dump_file, "\n");
693 }
694
695 /* For variables in named sections make sure get_variable_section
696 is called before we switch to those sections. Then section
697 conflicts between read-only and read-only requiring relocations
698 sections can be resolved. */
699 void
700 varpool_node::finalize_named_section_flags (void)
701 {
702 if (!TREE_ASM_WRITTEN (decl)
703 && !alias
704 && !in_other_partition
705 && !DECL_EXTERNAL (decl)
706 && TREE_CODE (decl) == VAR_DECL
707 && !DECL_HAS_VALUE_EXPR_P (decl)
708 && get_section ())
709 get_variable_section (decl, false);
710 }
711
712 /* Output all variables enqueued to be assembled. */
713 bool
714 symbol_table::output_variables (void)
715 {
716 bool changed = false;
717 varpool_node *node;
718
719 if (seen_error ())
720 return false;
721
722 remove_unreferenced_decls ();
723
724 timevar_push (TV_VAROUT);
725
726 FOR_EACH_VARIABLE (node)
727 if (!node->definition
728 && !DECL_HAS_VALUE_EXPR_P (node->decl)
729 && !DECL_HARD_REGISTER (node->decl))
730 assemble_undefined_decl (node->decl);
731 FOR_EACH_DEFINED_VARIABLE (node)
732 {
733 /* Handled in output_in_order. */
734 if (node->no_reorder)
735 continue;
736
737 node->finalize_named_section_flags ();
738 }
739
740 FOR_EACH_DEFINED_VARIABLE (node)
741 {
742 /* Handled in output_in_order. */
743 if (node->no_reorder)
744 continue;
745 if (node->assemble_decl ())
746 changed = true;
747 }
748 timevar_pop (TV_VAROUT);
749 return changed;
750 }
751
752 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
753 Extra name aliases are output whenever DECL is output. */
754
755 varpool_node *
756 varpool_node::create_alias (tree alias, tree decl)
757 {
758 varpool_node *alias_node;
759
760 gcc_assert (TREE_CODE (decl) == VAR_DECL);
761 gcc_assert (TREE_CODE (alias) == VAR_DECL);
762 alias_node = varpool_node::get_create (alias);
763 alias_node->alias = true;
764 alias_node->definition = true;
765 alias_node->alias_target = decl;
766 if (lookup_attribute ("weakref", DECL_ATTRIBUTES (alias)) != NULL)
767 alias_node->weakref = true;
768 return alias_node;
769 }
770
771 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
772 Extra name aliases are output whenever DECL is output. */
773
774 varpool_node *
775 varpool_node::create_extra_name_alias (tree alias, tree decl)
776 {
777 varpool_node *alias_node;
778
779 #ifndef ASM_OUTPUT_DEF
780 /* If aliases aren't supported by the assembler, fail. */
781 return NULL;
782 #endif
783 alias_node = varpool_node::create_alias (alias, decl);
784 alias_node->cpp_implicit_alias = true;
785
786 /* Extra name alias mechanizm creates aliases really late
787 via DECL_ASSEMBLER_NAME mechanizm.
788 This is unfortunate because they are not going through the
789 standard channels. Ensure they get output. */
790 if (symtab->cpp_implicit_aliases_done)
791 alias_node->resolve_alias (varpool_node::get_create (decl));
792 return alias_node;
793 }
794
795 /* Worker for call_for_symbol_and_aliases. */
796
797 bool
798 varpool_node::call_for_symbol_and_aliases_1 (bool (*callback) (varpool_node *,
799 void *),
800 void *data,
801 bool include_overwritable)
802 {
803 ipa_ref *ref;
804
805 FOR_EACH_ALIAS (this, ref)
806 {
807 varpool_node *alias = dyn_cast <varpool_node *> (ref->referring);
808 if (include_overwritable
809 || alias->get_availability () > AVAIL_INTERPOSABLE)
810 if (alias->call_for_symbol_and_aliases (callback, data,
811 include_overwritable))
812 return true;
813 }
814 return false;
815 }