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