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