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