1 /* Callgraph handling code.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011
3 Free Software Foundation, Inc.
4 Contributed by Jan Hubicka
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
28 #include "langhooks.h"
29 #include "diagnostic-core.h"
37 #include "tree-flow.h"
40 /* This file contains basic routines manipulating variable pool.
42 Varpool acts as interface in between the front-end and middle-end
43 and drives the decision process on what variables and when are
46 The varpool nodes are allocated lazily for declarations
47 either by frontend or at callgraph construction time.
48 All variables supposed to be output into final file needs to be
49 explicitly marked by frontend via VARPOOL_FINALIZE_DECL function. */
51 /* Hash table used to convert declarations into nodes. */
52 static GTY((param_is (union symtab_node_def
))) htab_t varpool_hash
;
54 /* The linked list of cgraph varpool nodes.
55 Linked via node->next pointer. */
56 symtab_node x_varpool_nodes
;
58 /* Queue of cgraph nodes scheduled to be lowered and output.
59 The queue is maintained via mark_needed_node, linked via node->next_needed
62 LAST_NEEDED_NODE points to the end of queue, so it can be
63 maintained in forward order. GTY is needed to make it friendly to
66 During compilation we construct the queue of needed variables
67 twice: first time it is during cgraph construction, second time it is at the
68 end of compilation in VARPOOL_REMOVE_UNREFERENCED_DECLS so we can avoid
69 optimized out variables being output.
71 Each variable is thus first analyzed and then later possibly output.
72 FIRST_UNANALYZED_NODE points to first node in queue that was not analyzed
73 yet and is moved via VARPOOL_ANALYZE_PENDING_DECLS. */
75 symtab_node x_varpool_nodes_queue
;
76 static GTY(()) symtab_node x_varpool_last_needed_node
;
77 #define varpool_last_needed_node ((struct varpool_node *)x_varpool_last_needed_node)
78 static GTY(()) symtab_node x_varpool_first_unanalyzed_node
;
79 #define varpool_first_unanalyzed_node ((struct varpool_node *)x_varpool_first_unanalyzed_node)
81 /* Lists all assembled variables to be sent to debugger output later on. */
82 static GTY(()) struct varpool_node
*varpool_assembled_nodes_queue
;
84 /* Return name of the node used in debug output. */
86 varpool_node_name (struct varpool_node
*node
)
88 return lang_hooks
.decl_printable_name (node
->symbol
.decl
, 2);
91 /* Returns a hash code for P. */
93 hash_varpool_node (const void *p
)
95 const struct varpool_node
*n
= (const struct varpool_node
*) p
;
96 return (hashval_t
) DECL_UID (n
->symbol
.decl
);
99 /* Returns nonzero if P1 and P2 are equal. */
101 eq_varpool_node (const void *p1
, const void *p2
)
103 const struct varpool_node
*n1
=
104 (const struct varpool_node
*) p1
;
105 const struct varpool_node
*n2
=
106 (const struct varpool_node
*) p2
;
107 return DECL_UID (n1
->symbol
.decl
) == DECL_UID (n2
->symbol
.decl
);
110 /* Return varpool node assigned to DECL without creating new one. */
111 struct varpool_node
*
112 varpool_get_node (const_tree decl
)
114 struct varpool_node key
, **slot
;
116 gcc_assert (TREE_CODE (decl
) == VAR_DECL
117 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
)));
121 key
.symbol
.decl
= CONST_CAST2 (tree
, const_tree
, decl
);
122 slot
= (struct varpool_node
**)
123 htab_find_slot (varpool_hash
, &key
, NO_INSERT
);
129 /* Return varpool node assigned to DECL. Create new one when needed. */
130 struct varpool_node
*
131 varpool_node (tree decl
)
133 struct varpool_node key
, *node
, **slot
;
135 gcc_assert (TREE_CODE (decl
) == VAR_DECL
136 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
) || in_lto_p
));
139 varpool_hash
= htab_create_ggc (10, hash_varpool_node
,
140 eq_varpool_node
, NULL
);
141 key
.symbol
.decl
= decl
;
142 slot
= (struct varpool_node
**)
143 htab_find_slot (varpool_hash
, &key
, INSERT
);
146 node
= ggc_alloc_cleared_varpool_node ();
147 node
->symbol
.type
= SYMTAB_VARIABLE
;
148 node
->symbol
.decl
= decl
;
149 node
->symbol
.order
= cgraph_order
++;
150 node
->next
= varpool_nodes
;
151 ipa_empty_ref_list (&node
->symbol
.ref_list
);
153 varpool (x_varpool_nodes
)->prev
= node
;
154 x_varpool_nodes
= (symtab_node
)node
;
159 /* Remove node from the varpool. */
161 varpool_remove_node (struct varpool_node
*node
)
164 slot
= htab_find_slot (varpool_hash
, node
, NO_INSERT
);
165 gcc_assert (*slot
== node
);
166 htab_clear_slot (varpool_hash
, slot
);
167 gcc_assert (!varpool_assembled_nodes_queue
);
169 node
->next
->prev
= node
->prev
;
171 node
->prev
->next
= node
->next
;
174 gcc_assert (varpool_nodes
== node
);
175 x_varpool_nodes
= (symtab_node
)node
->next
;
177 if (varpool_first_unanalyzed_node
== node
)
178 x_varpool_first_unanalyzed_node
= (symtab_node
)node
->next_needed
;
179 if (node
->next_needed
)
180 node
->next_needed
->prev_needed
= node
->prev_needed
;
181 else if (node
->prev_needed
)
183 gcc_assert (varpool_last_needed_node
);
184 x_varpool_last_needed_node
= (symtab_node
)node
->prev_needed
;
186 if (node
->prev_needed
)
187 node
->prev_needed
->next_needed
= node
->next_needed
;
188 else if (node
->next_needed
)
190 gcc_assert (varpool_nodes_queue
== node
);
191 x_varpool_nodes_queue
= (symtab_node
)node
->next_needed
;
193 if (node
->symbol
.same_comdat_group
)
196 for (prev
= node
->symbol
.same_comdat_group
;
197 prev
->symbol
.same_comdat_group
!= (symtab_node
)node
;
198 prev
= prev
->symbol
.same_comdat_group
)
200 if (node
->symbol
.same_comdat_group
== prev
)
201 prev
->symbol
.same_comdat_group
= NULL
;
203 prev
->symbol
.same_comdat_group
= (symtab_node
)node
->symbol
.same_comdat_group
;
204 node
->symbol
.same_comdat_group
= NULL
;
206 ipa_remove_all_references (&node
->symbol
.ref_list
);
207 ipa_remove_all_refering (&node
->symbol
.ref_list
);
211 /* Dump given cgraph node. */
213 dump_varpool_node (FILE *f
, struct varpool_node
*node
)
215 fprintf (f
, "%s:", varpool_node_name (node
));
216 fprintf (f
, " availability:%s",
217 cgraph_function_flags_ready
218 ? cgraph_availability_names
[cgraph_variable_initializer_availability (node
)]
220 if (DECL_ASSEMBLER_NAME_SET_P (node
->symbol
.decl
))
221 fprintf (f
, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node
->symbol
.decl
)));
222 if (DECL_INITIAL (node
->symbol
.decl
))
223 fprintf (f
, " initialized");
224 if (TREE_ASM_WRITTEN (node
->symbol
.decl
))
225 fprintf (f
, " (asm written)");
227 fprintf (f
, " needed");
229 fprintf (f
, " analyzed");
231 fprintf (f
, " finalized");
233 fprintf (f
, " output");
234 if (node
->symbol
.externally_visible
)
235 fprintf (f
, " externally_visible");
236 if (node
->symbol
.resolution
!= LDPR_UNKNOWN
)
238 ld_plugin_symbol_resolution_names
[(int)node
->symbol
.resolution
]);
239 if (node
->symbol
.in_other_partition
)
240 fprintf (f
, " in_other_partition");
241 else if (node
->symbol
.used_from_other_partition
)
242 fprintf (f
, " used_from_other_partition");
244 fprintf (f
, " References: ");
245 ipa_dump_references (f
, &node
->symbol
.ref_list
);
246 fprintf (f
, " Refering this var: ");
247 ipa_dump_refering (f
, &node
->symbol
.ref_list
);
250 /* Dump the variable pool. */
252 dump_varpool (FILE *f
)
254 struct varpool_node
*node
;
256 fprintf (f
, "variable pool:\n\n");
257 for (node
= varpool_nodes
; node
; node
= node
->next
)
258 dump_varpool_node (f
, node
);
261 /* Dump the variable pool to stderr. */
266 dump_varpool (stderr
);
269 /* Given an assembler name, lookup node. */
270 struct varpool_node
*
271 varpool_node_for_asm (tree asmname
)
273 struct varpool_node
*node
;
275 for (node
= varpool_nodes
; node
; node
= node
->next
)
276 if (decl_assembler_name_equal (node
->symbol
.decl
, asmname
))
282 /* Helper function for finalization code - add node into lists so it will
283 be analyzed and compiled. */
285 varpool_enqueue_needed_node (struct varpool_node
*node
)
287 if (varpool_last_needed_node
)
289 varpool_last_needed_node
->next_needed
= node
;
290 node
->prev_needed
= varpool_last_needed_node
;
292 x_varpool_last_needed_node
= (symtab_node
)node
;
293 node
->next_needed
= NULL
;
294 if (!varpool_nodes_queue
)
295 x_varpool_nodes_queue
= (symtab_node
)node
;
296 if (!varpool_first_unanalyzed_node
)
297 x_varpool_first_unanalyzed_node
= (symtab_node
)node
;
298 notice_global_symbol (node
->symbol
.decl
);
301 /* Notify finalize_compilation_unit that given node is reachable
304 varpool_mark_needed_node (struct varpool_node
*node
)
306 if (!node
->needed
&& node
->finalized
307 && !TREE_ASM_WRITTEN (node
->symbol
.decl
))
308 varpool_enqueue_needed_node (node
);
312 /* Reset the queue of needed nodes. */
314 varpool_reset_queue (void)
316 x_varpool_last_needed_node
= NULL
;
317 x_varpool_nodes_queue
= NULL
;
318 x_varpool_first_unanalyzed_node
= NULL
;
321 /* Determine if variable DECL is needed. That is, visible to something
322 either outside this translation unit, something magic in the system
325 decide_is_variable_needed (struct varpool_node
*node
, tree decl
)
327 /* If the user told us it is used, then it must be so. */
328 if (node
->force_output
)
331 gcc_assert (!DECL_EXTERNAL (decl
));
333 /* Externally visible variables must be output. The exception is
334 COMDAT variables that must be output only when they are needed. */
335 if (TREE_PUBLIC (decl
)
336 && !DECL_COMDAT (decl
)
337 && !DECL_EXTERNAL (decl
))
343 /* Return if DECL is constant and its initial value is known (so we can do
344 constant folding using DECL_INITIAL (decl)). */
347 const_value_known_p (tree decl
)
349 if (TREE_CODE (decl
) != VAR_DECL
350 &&TREE_CODE (decl
) != CONST_DECL
)
353 if (TREE_CODE (decl
) == CONST_DECL
354 || DECL_IN_CONSTANT_POOL (decl
))
357 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
359 if (!TREE_READONLY (decl
) || TREE_THIS_VOLATILE (decl
))
362 /* Gimplifier takes away constructors of local vars */
363 if (!TREE_STATIC (decl
) && !DECL_EXTERNAL (decl
))
364 return DECL_INITIAL (decl
) != NULL
;
366 gcc_assert (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
));
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 if (!DECL_INITIAL (decl
)
372 && (DECL_EXTERNAL (decl
)
373 || decl_replaceable_p (decl
)))
376 /* Variables declared `const' with an initializer are considered
377 to not be overwritable with different initializer by default.
379 ??? Previously we behaved so for scalar variables but not for array
384 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct the
385 middle end to output the variable to asm file, if needed or externally
388 varpool_finalize_decl (tree decl
)
390 struct varpool_node
*node
= varpool_node (decl
);
392 gcc_assert (TREE_STATIC (decl
));
394 /* The first declaration of a variable that comes through this function
395 decides whether it is global (in C, has external linkage)
396 or local (in C, has internal linkage). So do nothing more
397 if this function has already run. */
400 if (cgraph_global_info_ready
)
401 varpool_assemble_pending_decls ();
405 varpool_enqueue_needed_node (node
);
406 node
->finalized
= true;
407 if (TREE_THIS_VOLATILE (decl
) || DECL_PRESERVE_P (decl
)
408 /* Traditionally we do not eliminate static variables when not
409 optimizing and when not doing toplevel reoder. */
410 || (!flag_toplevel_reorder
&& !DECL_COMDAT (node
->symbol
.decl
)
411 && !DECL_ARTIFICIAL (node
->symbol
.decl
)))
412 node
->force_output
= true;
414 if (decide_is_variable_needed (node
, decl
))
415 varpool_mark_needed_node (node
);
416 if (cgraph_global_info_ready
)
417 varpool_assemble_pending_decls ();
420 /* Add the variable DECL to the varpool.
421 Unlike varpool_finalize_decl function is intended to be used
422 by middle end and allows insertion of new variable at arbitrary point
425 varpool_add_new_variable (tree decl
)
427 struct varpool_node
*node
;
428 varpool_finalize_decl (decl
);
429 node
= varpool_node (decl
);
430 if (varpool_externally_visible_p (node
, false))
431 node
->symbol
.externally_visible
= true;
434 /* Return variable availability. See cgraph.h for description of individual
437 cgraph_variable_initializer_availability (struct varpool_node
*node
)
439 gcc_assert (cgraph_function_flags_ready
);
440 if (!node
->finalized
)
441 return AVAIL_NOT_AVAILABLE
;
442 if (!TREE_PUBLIC (node
->symbol
.decl
))
443 return AVAIL_AVAILABLE
;
444 /* If the variable can be overwritten, return OVERWRITABLE. Takes
445 care of at least two notable extensions - the COMDAT variables
446 used to share template instantiations in C++. */
447 if (!decl_replaceable_p (node
->symbol
.decl
))
448 return AVAIL_OVERWRITABLE
;
449 return AVAIL_AVAILABLE
;
452 /* Walk the decls we marked as necessary and see if they reference new
453 variables or functions and add them into the worklists. */
455 varpool_analyze_pending_decls (void)
457 bool changed
= false;
459 timevar_push (TV_VARPOOL
);
460 while (varpool_first_unanalyzed_node
)
462 struct varpool_node
*node
= varpool_first_unanalyzed_node
, *next
;
463 tree decl
= node
->symbol
.decl
;
464 bool analyzed
= node
->analyzed
;
466 varpool_first_unanalyzed_node
->analyzed
= true;
468 x_varpool_first_unanalyzed_node
= (symtab_node
)varpool_first_unanalyzed_node
->next_needed
;
470 /* When reading back varpool at LTO time, we re-construct the queue in order
471 to have "needed" list right by inserting all needed nodes into varpool.
472 We however don't want to re-analyze already analyzed nodes. */
475 gcc_assert (!in_lto_p
|| cgraph_function_flags_ready
);
476 /* Compute the alignment early so function body expanders are
477 already informed about increased alignment. */
478 align_variable (decl
, 0);
480 if (node
->alias
&& node
->alias_of
)
482 struct varpool_node
*tgt
= varpool_node (node
->alias_of
);
483 struct varpool_node
*n
;
485 for (n
= tgt
; n
&& n
->alias
;
486 n
= n
->analyzed
? varpool_alias_aliased_node (n
) : NULL
)
489 error ("variable %q+D part of alias cycle", node
->symbol
.decl
);
493 if (!VEC_length (ipa_ref_t
, node
->symbol
.ref_list
.references
))
494 ipa_record_reference (NULL
, node
, NULL
, tgt
, IPA_REF_ALIAS
, NULL
);
495 /* C++ FE sometimes change linkage flags after producing same body aliases. */
496 if (node
->extra_name_alias
)
498 DECL_WEAK (node
->symbol
.decl
) = DECL_WEAK (node
->alias_of
);
499 TREE_PUBLIC (node
->symbol
.decl
) = TREE_PUBLIC (node
->alias_of
);
500 DECL_EXTERNAL (node
->symbol
.decl
) = DECL_EXTERNAL (node
->alias_of
);
501 DECL_VISIBILITY (node
->symbol
.decl
) = DECL_VISIBILITY (node
->alias_of
);
502 if (TREE_PUBLIC (node
->symbol
.decl
))
504 DECL_COMDAT (node
->symbol
.decl
) = DECL_COMDAT (node
->alias_of
);
505 DECL_COMDAT_GROUP (node
->symbol
.decl
) = DECL_COMDAT_GROUP (node
->alias_of
);
506 if (DECL_ONE_ONLY (node
->alias_of
)
507 && !node
->symbol
.same_comdat_group
)
509 node
->symbol
.same_comdat_group
= (symtab_node
)tgt
;
510 if (!tgt
->symbol
.same_comdat_group
)
511 tgt
->symbol
.same_comdat_group
= (symtab_node
)node
;
515 for (n
= tgt
->symbol
.same_comdat_group
;
516 n
->symbol
.same_comdat_group
!= (symtab_node
)tgt
;
517 n
= n
->symbol
.same_comdat_group
)
519 n
->symbol
.same_comdat_group
= (symtab_node
)node
;
525 else if (DECL_INITIAL (decl
))
526 record_references_in_initializer (decl
, analyzed
);
527 if (node
->symbol
.same_comdat_group
)
529 for (next
= varpool (node
->symbol
.same_comdat_group
);
531 next
= varpool (next
->symbol
.same_comdat_group
))
532 varpool_mark_needed_node (next
);
536 timevar_pop (TV_VARPOOL
);
540 /* Assemble thunks and aliases asociated to NODE. */
543 assemble_aliases (struct varpool_node
*node
)
547 for (i
= 0; ipa_ref_list_refering_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
548 if (ref
->use
== IPA_REF_ALIAS
)
550 struct varpool_node
*alias
= ipa_ref_refering_varpool_node (ref
);
551 assemble_alias (alias
->symbol
.decl
,
552 DECL_ASSEMBLER_NAME (alias
->alias_of
));
553 assemble_aliases (alias
);
557 /* Output one variable, if necessary. Return whether we output it. */
559 varpool_assemble_decl (struct varpool_node
*node
)
561 tree decl
= node
->symbol
.decl
;
563 if (!TREE_ASM_WRITTEN (decl
)
565 && !node
->symbol
.in_other_partition
566 && !DECL_EXTERNAL (decl
)
567 && (TREE_CODE (decl
) != VAR_DECL
|| !DECL_HAS_VALUE_EXPR_P (decl
)))
569 assemble_variable (decl
, 0, 1, 0);
570 if (TREE_ASM_WRITTEN (decl
))
572 node
->next_needed
= varpool_assembled_nodes_queue
;
573 node
->prev_needed
= NULL
;
574 if (varpool_assembled_nodes_queue
)
575 varpool_assembled_nodes_queue
->prev_needed
= node
;
576 varpool_assembled_nodes_queue
= node
;
578 assemble_aliases (node
);
586 /* Optimization of function bodies might've rendered some variables as
587 unnecessary so we want to avoid these from being compiled.
589 This is done by pruning the queue and keeping only the variables that
590 really appear needed (ie they are either externally visible or referenced
591 by compiled function). Re-doing the reachability analysis on variables
592 brings back the remaining variables referenced by these. */
594 varpool_remove_unreferenced_decls (void)
596 struct varpool_node
*next
, *node
= varpool_nodes_queue
;
598 varpool_reset_queue ();
605 next
= node
->next_needed
;
609 && (!varpool_can_remove_if_no_refs (node
)
610 /* We just expanded all function bodies. See if any of
611 them needed the variable. */
612 || DECL_RTL_SET_P (node
->symbol
.decl
)))
613 varpool_mark_needed_node (node
);
617 /* Make sure we mark alias targets as used targets. */
619 varpool_analyze_pending_decls ();
622 /* For variables in named sections make sure get_variable_section
623 is called before we switch to those sections. Then section
624 conflicts between read-only and read-only requiring relocations
625 sections can be resolved. */
627 varpool_finalize_named_section_flags (struct varpool_node
*node
)
629 if (!TREE_ASM_WRITTEN (node
->symbol
.decl
)
631 && !node
->symbol
.in_other_partition
632 && !DECL_EXTERNAL (node
->symbol
.decl
)
633 && TREE_CODE (node
->symbol
.decl
) == VAR_DECL
634 && !DECL_HAS_VALUE_EXPR_P (node
->symbol
.decl
)
635 && DECL_SECTION_NAME (node
->symbol
.decl
))
636 get_variable_section (node
->symbol
.decl
, false);
639 /* Output all variables enqueued to be assembled. */
641 varpool_assemble_pending_decls (void)
643 bool changed
= false;
644 struct varpool_node
*node
;
649 timevar_push (TV_VAROUT
);
650 /* EH might mark decls as needed during expansion. This should be safe since
651 we don't create references to new function, but it should not be used
653 varpool_analyze_pending_decls ();
655 for (node
= varpool_nodes_queue
; node
; node
= node
->next_needed
)
656 varpool_finalize_named_section_flags (node
);
658 while (varpool_nodes_queue
)
660 struct varpool_node
*node
= varpool_nodes_queue
;
662 x_varpool_nodes_queue
= (symtab_node
)(varpool_nodes_queue
->next_needed
);
663 if (varpool_assemble_decl (node
))
667 node
->prev_needed
= NULL
;
668 node
->next_needed
= NULL
;
671 /* varpool_nodes_queue is now empty, clear the pointer to the last element
673 x_varpool_last_needed_node
= NULL
;
674 timevar_pop (TV_VAROUT
);
678 /* Remove all elements from the queue so we can re-use it for debug output. */
680 varpool_empty_needed_queue (void)
682 /* EH might mark decls as needed during expansion. This should be safe since
683 we don't create references to new function, but it should not be used
685 varpool_analyze_pending_decls ();
687 while (varpool_nodes_queue
)
689 struct varpool_node
*node
= varpool_nodes_queue
;
690 x_varpool_nodes_queue
= (symtab_node
)varpool_nodes_queue
->next_needed
;
691 node
->next_needed
= NULL
;
692 node
->prev_needed
= NULL
;
694 /* varpool_nodes_queue is now empty, clear the pointer to the last element
696 x_varpool_last_needed_node
= NULL
;
699 /* Create a new global variable of type TYPE. */
701 add_new_static_var (tree type
)
704 struct varpool_node
*new_node
;
706 new_decl
= create_tmp_var (type
, NULL
);
707 DECL_NAME (new_decl
) = create_tmp_var_name (NULL
);
708 TREE_READONLY (new_decl
) = 0;
709 TREE_STATIC (new_decl
) = 1;
710 TREE_USED (new_decl
) = 1;
711 DECL_CONTEXT (new_decl
) = NULL_TREE
;
712 DECL_ABSTRACT (new_decl
) = 0;
713 lang_hooks
.dup_lang_specific_decl (new_decl
);
714 create_var_ann (new_decl
);
715 new_node
= varpool_node (new_decl
);
716 varpool_mark_needed_node (new_node
);
717 add_referenced_var (new_decl
);
718 varpool_finalize_decl (new_decl
);
720 return new_node
->symbol
.decl
;
723 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
724 Extra name aliases are output whenever DECL is output. */
726 struct varpool_node
*
727 varpool_create_variable_alias (tree alias
, tree decl
)
729 struct varpool_node
*alias_node
;
731 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
732 gcc_assert (TREE_CODE (alias
) == VAR_DECL
);
733 alias_node
= varpool_node (alias
);
734 alias_node
->alias
= 1;
735 if (!DECL_EXTERNAL (alias
))
736 alias_node
->finalized
= 1;
737 alias_node
->alias_of
= decl
;
738 if ((!DECL_EXTERNAL (alias
)
739 && decide_is_variable_needed (alias_node
, alias
))
740 || alias_node
->needed
)
741 varpool_mark_needed_node (alias_node
);
745 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
746 Extra name aliases are output whenever DECL is output. */
748 struct varpool_node
*
749 varpool_extra_name_alias (tree alias
, tree decl
)
751 struct varpool_node
*alias_node
;
753 #ifndef ASM_OUTPUT_DEF
754 /* If aliases aren't supported by the assembler, fail. */
757 alias_node
= varpool_create_variable_alias (alias
, decl
);
758 alias_node
->extra_name_alias
= true;
762 /* Return true when NODE is known to be used from other (non-LTO) object file.
763 Known only when doing LTO via linker plugin. */
766 varpool_used_from_object_file_p (struct varpool_node
*node
)
768 if (!TREE_PUBLIC (node
->symbol
.decl
))
770 if (resolution_used_from_other_file_p (node
->symbol
.resolution
))
775 /* Call calback on NODE and aliases asociated to NODE.
776 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
780 varpool_for_node_and_aliases (struct varpool_node
*node
,
781 bool (*callback
) (struct varpool_node
*, void *),
783 bool include_overwritable
)
788 if (callback (node
, data
))
790 for (i
= 0; ipa_ref_list_refering_iterate (&node
->symbol
.ref_list
, i
, ref
); i
++)
791 if (ref
->use
== IPA_REF_ALIAS
)
793 struct varpool_node
*alias
= ipa_ref_refering_varpool_node (ref
);
794 if (include_overwritable
795 || cgraph_variable_initializer_availability (alias
) > AVAIL_OVERWRITABLE
)
796 if (varpool_for_node_and_aliases (alias
, callback
, data
,
797 include_overwritable
))
802 #include "gt-varpool.h"