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