2011-12-09 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / varpool.c
blob74fc1ba712b6dd321ed2f47083c853e6a35ccafc
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
11 version.
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
16 for more details.
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/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "tree.h"
27 #include "cgraph.h"
28 #include "langhooks.h"
29 #include "diagnostic-core.h"
30 #include "hashtab.h"
31 #include "ggc.h"
32 #include "timevar.h"
33 #include "debug.h"
34 #include "target.h"
35 #include "output.h"
36 #include "gimple.h"
37 #include "tree-flow.h"
38 #include "flags.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
44 going to be compiled.
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 (struct varpool_node))) htab_t varpool_hash;
54 /* The linked list of cgraph varpool nodes.
55 Linked via node->next pointer. */
56 struct varpool_node *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
60 pointer.
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
64 PCH.
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 struct varpool_node *varpool_nodes_queue;
76 static GTY(()) struct varpool_node *varpool_last_needed_node;
77 static GTY(()) struct varpool_node *varpool_first_unanalyzed_node;
79 /* Lists all assembled variables to be sent to debugger output later on. */
80 static GTY(()) struct varpool_node *varpool_assembled_nodes_queue;
82 /* Return name of the node used in debug output. */
83 const char *
84 varpool_node_name (struct varpool_node *node)
86 return lang_hooks.decl_printable_name (node->decl, 2);
89 /* Returns a hash code for P. */
90 static hashval_t
91 hash_varpool_node (const void *p)
93 const struct varpool_node *n = (const struct varpool_node *) p;
94 return (hashval_t) DECL_UID (n->decl);
97 /* Returns nonzero if P1 and P2 are equal. */
98 static int
99 eq_varpool_node (const void *p1, const void *p2)
101 const struct varpool_node *n1 =
102 (const struct varpool_node *) p1;
103 const struct varpool_node *n2 =
104 (const struct varpool_node *) p2;
105 return DECL_UID (n1->decl) == DECL_UID (n2->decl);
108 /* Return varpool node assigned to DECL without creating new one. */
109 struct varpool_node *
110 varpool_get_node (const_tree decl)
112 struct varpool_node key, **slot;
114 gcc_assert (TREE_CODE (decl) == VAR_DECL
115 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)));
117 if (!varpool_hash)
118 return NULL;
119 key.decl = CONST_CAST2 (tree, const_tree, decl);
120 slot = (struct varpool_node **)
121 htab_find_slot (varpool_hash, &key, NO_INSERT);
122 if (!slot)
123 return NULL;
124 return *slot;
127 /* Return varpool node assigned to DECL. Create new one when needed. */
128 struct varpool_node *
129 varpool_node (tree decl)
131 struct varpool_node key, *node, **slot;
133 gcc_assert (TREE_CODE (decl) == VAR_DECL
134 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl) || in_lto_p));
136 if (!varpool_hash)
137 varpool_hash = htab_create_ggc (10, hash_varpool_node,
138 eq_varpool_node, NULL);
139 key.decl = decl;
140 slot = (struct varpool_node **)
141 htab_find_slot (varpool_hash, &key, INSERT);
142 if (*slot)
143 return *slot;
144 node = ggc_alloc_cleared_varpool_node ();
145 node->decl = decl;
146 node->order = cgraph_order++;
147 node->next = varpool_nodes;
148 ipa_empty_ref_list (&node->ref_list);
149 if (varpool_nodes)
150 varpool_nodes->prev = node;
151 varpool_nodes = node;
152 *slot = node;
153 return node;
156 /* Remove node from the varpool. */
157 void
158 varpool_remove_node (struct varpool_node *node)
160 void **slot;
161 slot = htab_find_slot (varpool_hash, node, NO_INSERT);
162 gcc_assert (*slot == node);
163 htab_clear_slot (varpool_hash, slot);
164 gcc_assert (!varpool_assembled_nodes_queue);
165 if (node->next)
166 node->next->prev = node->prev;
167 if (node->prev)
168 node->prev->next = node->next;
169 else
171 gcc_assert (varpool_nodes == node);
172 varpool_nodes = node->next;
174 if (varpool_first_unanalyzed_node == node)
175 varpool_first_unanalyzed_node = node->next_needed;
176 if (node->next_needed)
177 node->next_needed->prev_needed = node->prev_needed;
178 else if (node->prev_needed)
180 gcc_assert (varpool_last_needed_node);
181 varpool_last_needed_node = node->prev_needed;
183 if (node->prev_needed)
184 node->prev_needed->next_needed = node->next_needed;
185 else if (node->next_needed)
187 gcc_assert (varpool_nodes_queue == node);
188 varpool_nodes_queue = node->next_needed;
190 if (node->same_comdat_group)
192 struct varpool_node *prev;
193 for (prev = node->same_comdat_group;
194 prev->same_comdat_group != node;
195 prev = prev->same_comdat_group)
197 if (node->same_comdat_group == prev)
198 prev->same_comdat_group = NULL;
199 else
200 prev->same_comdat_group = node->same_comdat_group;
201 node->same_comdat_group = NULL;
203 ipa_remove_all_references (&node->ref_list);
204 ipa_remove_all_refering (&node->ref_list);
205 ggc_free (node);
208 /* Dump given cgraph node. */
209 void
210 dump_varpool_node (FILE *f, struct varpool_node *node)
212 fprintf (f, "%s:", varpool_node_name (node));
213 fprintf (f, " availability:%s",
214 cgraph_function_flags_ready
215 ? cgraph_availability_names[cgraph_variable_initializer_availability (node)]
216 : "not-ready");
217 if (DECL_ASSEMBLER_NAME_SET_P (node->decl))
218 fprintf (f, " (asm: %s)", IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)));
219 if (DECL_INITIAL (node->decl))
220 fprintf (f, " initialized");
221 if (TREE_ASM_WRITTEN (node->decl))
222 fprintf (f, " (asm written)");
223 if (node->needed)
224 fprintf (f, " needed");
225 if (node->analyzed)
226 fprintf (f, " analyzed");
227 if (node->finalized)
228 fprintf (f, " finalized");
229 if (node->output)
230 fprintf (f, " output");
231 if (node->externally_visible)
232 fprintf (f, " externally_visible");
233 if (node->resolution != LDPR_UNKNOWN)
234 fprintf (f, " %s",
235 ld_plugin_symbol_resolution_names[(int)node->resolution]);
236 if (node->in_other_partition)
237 fprintf (f, " in_other_partition");
238 else if (node->used_from_other_partition)
239 fprintf (f, " used_from_other_partition");
240 fprintf (f, "\n");
241 fprintf (f, " References: ");
242 ipa_dump_references (f, &node->ref_list);
243 fprintf (f, " Refering this var: ");
244 ipa_dump_refering (f, &node->ref_list);
247 /* Dump the variable pool. */
248 void
249 dump_varpool (FILE *f)
251 struct varpool_node *node;
253 fprintf (f, "variable pool:\n\n");
254 for (node = varpool_nodes; node; node = node->next)
255 dump_varpool_node (f, node);
258 /* Dump the variable pool to stderr. */
260 DEBUG_FUNCTION void
261 debug_varpool (void)
263 dump_varpool (stderr);
266 /* Given an assembler name, lookup node. */
267 struct varpool_node *
268 varpool_node_for_asm (tree asmname)
270 struct varpool_node *node;
272 for (node = varpool_nodes; node ; node = node->next)
273 if (decl_assembler_name_equal (node->decl, asmname))
274 return node;
276 return NULL;
279 /* Helper function for finalization code - add node into lists so it will
280 be analyzed and compiled. */
281 static void
282 varpool_enqueue_needed_node (struct varpool_node *node)
284 if (varpool_last_needed_node)
286 varpool_last_needed_node->next_needed = node;
287 node->prev_needed = varpool_last_needed_node;
289 varpool_last_needed_node = node;
290 node->next_needed = NULL;
291 if (!varpool_nodes_queue)
292 varpool_nodes_queue = node;
293 if (!varpool_first_unanalyzed_node)
294 varpool_first_unanalyzed_node = node;
295 notice_global_symbol (node->decl);
298 /* Notify finalize_compilation_unit that given node is reachable
299 or needed. */
300 void
301 varpool_mark_needed_node (struct varpool_node *node)
303 if (!node->needed && node->finalized
304 && !TREE_ASM_WRITTEN (node->decl))
305 varpool_enqueue_needed_node (node);
306 node->needed = 1;
309 /* Reset the queue of needed nodes. */
310 void
311 varpool_reset_queue (void)
313 varpool_last_needed_node = NULL;
314 varpool_nodes_queue = NULL;
315 varpool_first_unanalyzed_node = NULL;
318 /* Determine if variable DECL is needed. That is, visible to something
319 either outside this translation unit, something magic in the system
320 configury */
321 bool
322 decide_is_variable_needed (struct varpool_node *node, tree decl)
324 /* If the user told us it is used, then it must be so. */
325 if (node->force_output)
326 return true;
328 gcc_assert (!DECL_EXTERNAL (decl));
330 /* Externally visible variables must be output. The exception is
331 COMDAT variables that must be output only when they are needed. */
332 if (TREE_PUBLIC (decl)
333 && !DECL_COMDAT (decl)
334 && !DECL_EXTERNAL (decl))
335 return true;
337 /* When not reordering top level variables, we have to assume that
338 we are going to keep everything. */
339 if (!flag_toplevel_reorder)
340 return true;
341 return false;
344 /* Return if DECL is constant and its initial value is known (so we can do
345 constant folding using DECL_INITIAL (decl)). */
347 bool
348 const_value_known_p (tree decl)
350 if (TREE_CODE (decl) != VAR_DECL
351 &&TREE_CODE (decl) != CONST_DECL)
352 return false;
354 if (TREE_CODE (decl) == CONST_DECL
355 || DECL_IN_CONSTANT_POOL (decl))
356 return true;
358 gcc_assert (TREE_CODE (decl) == VAR_DECL);
360 if (!TREE_READONLY (decl) || TREE_THIS_VOLATILE (decl))
361 return false;
363 /* Gimplifier takes away constructors of local vars */
364 if (!TREE_STATIC (decl) && !DECL_EXTERNAL (decl))
365 return DECL_INITIAL (decl) != NULL;
367 gcc_assert (TREE_STATIC (decl) || DECL_EXTERNAL (decl));
369 /* Variables declared 'const' without an initializer
370 have zero as the initializer if they may not be
371 overridden at link or run time. */
372 if (!DECL_INITIAL (decl)
373 && (DECL_EXTERNAL (decl)
374 || decl_replaceable_p (decl)))
375 return false;
377 /* Variables declared `const' with an initializer are considered
378 to not be overwritable with different initializer by default.
380 ??? Previously we behaved so for scalar variables but not for array
381 accesses. */
382 return true;
385 /* Mark DECL as finalized. By finalizing the declaration, frontend instruct the
386 middle end to output the variable to asm file, if needed or externally
387 visible. */
388 void
389 varpool_finalize_decl (tree decl)
391 struct varpool_node *node = varpool_node (decl);
393 gcc_assert (TREE_STATIC (decl));
395 /* The first declaration of a variable that comes through this function
396 decides whether it is global (in C, has external linkage)
397 or local (in C, has internal linkage). So do nothing more
398 if this function has already run. */
399 if (node->finalized)
401 if (cgraph_global_info_ready)
402 varpool_assemble_pending_decls ();
403 return;
405 if (node->needed)
406 varpool_enqueue_needed_node (node);
407 node->finalized = true;
408 if (TREE_THIS_VOLATILE (decl) || DECL_PRESERVE_P (decl))
409 node->force_output = true;
411 if (decide_is_variable_needed (node, decl))
412 varpool_mark_needed_node (node);
413 if (cgraph_global_info_ready)
414 varpool_assemble_pending_decls ();
417 /* Add the variable DECL to the varpool.
418 Unlike varpool_finalize_decl function is intended to be used
419 by middle end and allows insertion of new variable at arbitrary point
420 of compilation. */
421 void
422 varpool_add_new_variable (tree decl)
424 struct varpool_node *node;
425 varpool_finalize_decl (decl);
426 node = varpool_node (decl);
427 if (varpool_externally_visible_p (node, false))
428 node->externally_visible = true;
431 /* Return variable availability. See cgraph.h for description of individual
432 return values. */
433 enum availability
434 cgraph_variable_initializer_availability (struct varpool_node *node)
436 gcc_assert (cgraph_function_flags_ready);
437 if (!node->finalized)
438 return AVAIL_NOT_AVAILABLE;
439 if (!TREE_PUBLIC (node->decl))
440 return AVAIL_AVAILABLE;
441 /* If the variable can be overwritten, return OVERWRITABLE. Takes
442 care of at least two notable extensions - the COMDAT variables
443 used to share template instantiations in C++. */
444 if (!decl_replaceable_p (node->decl))
445 return AVAIL_OVERWRITABLE;
446 return AVAIL_AVAILABLE;
449 /* Walk the decls we marked as necessary and see if they reference new
450 variables or functions and add them into the worklists. */
451 bool
452 varpool_analyze_pending_decls (void)
454 bool changed = false;
456 timevar_push (TV_VARPOOL);
457 while (varpool_first_unanalyzed_node)
459 struct varpool_node *node = varpool_first_unanalyzed_node, *next;
460 tree decl = node->decl;
461 bool analyzed = node->analyzed;
463 varpool_first_unanalyzed_node->analyzed = true;
465 varpool_first_unanalyzed_node = varpool_first_unanalyzed_node->next_needed;
467 /* When reading back varpool at LTO time, we re-construct the queue in order
468 to have "needed" list right by inserting all needed nodes into varpool.
469 We however don't want to re-analyze already analyzed nodes. */
470 if (!analyzed)
472 gcc_assert (!in_lto_p || cgraph_function_flags_ready);
473 /* Compute the alignment early so function body expanders are
474 already informed about increased alignment. */
475 align_variable (decl, 0);
477 if (node->alias && node->alias_of)
479 struct varpool_node *tgt = varpool_node (node->alias_of);
480 if (!VEC_length (ipa_ref_t, node->ref_list.references))
481 ipa_record_reference (NULL, node, NULL, tgt, IPA_REF_ALIAS, NULL);
482 /* C++ FE sometimes change linkage flags after producing same body aliases. */
483 if (node->extra_name_alias)
485 DECL_WEAK (node->decl) = DECL_WEAK (node->alias_of);
486 TREE_PUBLIC (node->decl) = TREE_PUBLIC (node->alias_of);
487 DECL_VISIBILITY (node->decl) = DECL_VISIBILITY (node->alias_of);
488 if (TREE_PUBLIC (node->decl))
490 DECL_COMDAT (node->decl) = DECL_COMDAT (node->alias_of);
491 DECL_COMDAT_GROUP (node->decl) = DECL_COMDAT_GROUP (node->alias_of);
492 if (DECL_ONE_ONLY (node->alias_of) && !node->same_comdat_group)
494 node->same_comdat_group = tgt;
495 if (!tgt->same_comdat_group)
496 tgt->same_comdat_group = node;
497 else
499 struct varpool_node *n;
500 for (n = tgt->same_comdat_group;
501 n->same_comdat_group != tgt;
502 n = n->same_comdat_group)
504 n->same_comdat_group = node;
510 else if (DECL_INITIAL (decl))
511 record_references_in_initializer (decl, analyzed);
512 if (node->same_comdat_group)
514 for (next = node->same_comdat_group;
515 next != node;
516 next = next->same_comdat_group)
517 varpool_mark_needed_node (next);
519 changed = true;
521 timevar_pop (TV_VARPOOL);
522 return changed;
525 /* Assemble thunks and aliases asociated to NODE. */
527 static void
528 assemble_aliases (struct varpool_node *node)
530 int i;
531 struct ipa_ref *ref;
532 for (i = 0; ipa_ref_list_refering_iterate (&node->ref_list, i, ref); i++)
533 if (ref->use == IPA_REF_ALIAS)
535 struct varpool_node *alias = ipa_ref_refering_varpool_node (ref);
536 assemble_alias (alias->decl,
537 DECL_ASSEMBLER_NAME (alias->alias_of));
538 assemble_aliases (alias);
542 /* Output one variable, if necessary. Return whether we output it. */
543 bool
544 varpool_assemble_decl (struct varpool_node *node)
546 tree decl = node->decl;
548 if (!TREE_ASM_WRITTEN (decl)
549 && !node->alias
550 && !node->in_other_partition
551 && !DECL_EXTERNAL (decl)
552 && (TREE_CODE (decl) != VAR_DECL || !DECL_HAS_VALUE_EXPR_P (decl)))
554 assemble_variable (decl, 0, 1, 0);
555 if (TREE_ASM_WRITTEN (decl))
557 node->next_needed = varpool_assembled_nodes_queue;
558 node->prev_needed = NULL;
559 if (varpool_assembled_nodes_queue)
560 varpool_assembled_nodes_queue->prev_needed = node;
561 varpool_assembled_nodes_queue = node;
562 node->finalized = 1;
563 assemble_aliases (node);
564 return true;
568 return false;
571 /* Optimization of function bodies might've rendered some variables as
572 unnecessary so we want to avoid these from being compiled.
574 This is done by pruning the queue and keeping only the variables that
575 really appear needed (ie they are either externally visible or referenced
576 by compiled function). Re-doing the reachability analysis on variables
577 brings back the remaining variables referenced by these. */
578 void
579 varpool_remove_unreferenced_decls (void)
581 struct varpool_node *next, *node = varpool_nodes_queue;
583 varpool_reset_queue ();
585 if (seen_error ())
586 return;
588 while (node)
590 next = node->next_needed;
591 node->needed = 0;
593 if (node->analyzed
594 && (!varpool_can_remove_if_no_refs (node)
595 /* We just expanded all function bodies. See if any of
596 them needed the variable. */
597 || DECL_RTL_SET_P (node->decl)))
598 varpool_mark_needed_node (node);
600 node = next;
602 /* Make sure we mark alias targets as used targets. */
603 finish_aliases_1 ();
604 varpool_analyze_pending_decls ();
607 /* For variables in named sections make sure get_variable_section
608 is called before we switch to those sections. Then section
609 conflicts between read-only and read-only requiring relocations
610 sections can be resolved. */
611 void
612 varpool_finalize_named_section_flags (struct varpool_node *node)
614 if (!TREE_ASM_WRITTEN (node->decl)
615 && !node->alias
616 && !node->in_other_partition
617 && !DECL_EXTERNAL (node->decl)
618 && TREE_CODE (node->decl) == VAR_DECL
619 && !DECL_HAS_VALUE_EXPR_P (node->decl)
620 && DECL_SECTION_NAME (node->decl))
621 get_variable_section (node->decl, false);
624 /* Output all variables enqueued to be assembled. */
625 bool
626 varpool_assemble_pending_decls (void)
628 bool changed = false;
629 struct varpool_node *node;
631 if (seen_error ())
632 return false;
634 timevar_push (TV_VAROUT);
635 /* EH might mark decls as needed during expansion. This should be safe since
636 we don't create references to new function, but it should not be used
637 elsewhere. */
638 varpool_analyze_pending_decls ();
640 for (node = varpool_nodes_queue; node; node = node->next_needed)
641 varpool_finalize_named_section_flags (node);
643 while (varpool_nodes_queue)
645 struct varpool_node *node = varpool_nodes_queue;
647 varpool_nodes_queue = varpool_nodes_queue->next_needed;
648 if (varpool_assemble_decl (node))
649 changed = true;
650 else
652 node->prev_needed = NULL;
653 node->next_needed = NULL;
656 /* varpool_nodes_queue is now empty, clear the pointer to the last element
657 in the queue. */
658 varpool_last_needed_node = NULL;
659 timevar_pop (TV_VAROUT);
660 return changed;
663 /* Remove all elements from the queue so we can re-use it for debug output. */
664 void
665 varpool_empty_needed_queue (void)
667 /* EH might mark decls as needed during expansion. This should be safe since
668 we don't create references to new function, but it should not be used
669 elsewhere. */
670 varpool_analyze_pending_decls ();
672 while (varpool_nodes_queue)
674 struct varpool_node *node = varpool_nodes_queue;
675 varpool_nodes_queue = varpool_nodes_queue->next_needed;
676 node->next_needed = NULL;
677 node->prev_needed = NULL;
679 /* varpool_nodes_queue is now empty, clear the pointer to the last element
680 in the queue. */
681 varpool_last_needed_node = NULL;
684 /* Create a new global variable of type TYPE. */
685 tree
686 add_new_static_var (tree type)
688 tree new_decl;
689 struct varpool_node *new_node;
691 new_decl = create_tmp_var (type, NULL);
692 DECL_NAME (new_decl) = create_tmp_var_name (NULL);
693 TREE_READONLY (new_decl) = 0;
694 TREE_STATIC (new_decl) = 1;
695 TREE_USED (new_decl) = 1;
696 DECL_CONTEXT (new_decl) = NULL_TREE;
697 DECL_ABSTRACT (new_decl) = 0;
698 lang_hooks.dup_lang_specific_decl (new_decl);
699 create_var_ann (new_decl);
700 new_node = varpool_node (new_decl);
701 varpool_mark_needed_node (new_node);
702 add_referenced_var (new_decl);
703 varpool_finalize_decl (new_decl);
705 return new_node->decl;
708 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
709 Extra name aliases are output whenever DECL is output. */
711 struct varpool_node *
712 varpool_create_variable_alias (tree alias, tree decl)
714 struct varpool_node *alias_node;
716 gcc_assert (TREE_CODE (decl) == VAR_DECL);
717 gcc_assert (TREE_CODE (alias) == VAR_DECL);
718 alias_node = varpool_node (alias);
719 alias_node->alias = 1;
720 if (!DECL_EXTERNAL (alias))
721 alias_node->finalized = 1;
722 alias_node->alias_of = decl;
723 if ((!DECL_EXTERNAL (alias)
724 && decide_is_variable_needed (alias_node, alias))
725 || alias_node->needed)
726 varpool_mark_needed_node (alias_node);
727 return alias_node;
730 /* Attempt to mark ALIAS as an alias to DECL. Return TRUE if successful.
731 Extra name aliases are output whenever DECL is output. */
733 struct varpool_node *
734 varpool_extra_name_alias (tree alias, tree decl)
736 struct varpool_node *alias_node;
738 #ifndef ASM_OUTPUT_DEF
739 /* If aliases aren't supported by the assembler, fail. */
740 return NULL;
741 #endif
742 alias_node = varpool_create_variable_alias (alias, decl);
743 alias_node->extra_name_alias = true;
744 return alias_node;
747 /* Return true when NODE is known to be used from other (non-LTO) object file.
748 Known only when doing LTO via linker plugin. */
750 bool
751 varpool_used_from_object_file_p (struct varpool_node *node)
753 if (!TREE_PUBLIC (node->decl))
754 return false;
755 if (resolution_used_from_other_file_p (node->resolution))
756 return true;
757 return false;
760 /* Call calback on NODE and aliases asociated to NODE.
761 When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
762 skipped. */
764 bool
765 varpool_for_node_and_aliases (struct varpool_node *node,
766 bool (*callback) (struct varpool_node *, void *),
767 void *data,
768 bool include_overwritable)
770 int i;
771 struct ipa_ref *ref;
773 if (callback (node, data))
774 return true;
775 for (i = 0; ipa_ref_list_refering_iterate (&node->ref_list, i, ref); i++)
776 if (ref->use == IPA_REF_ALIAS)
778 struct varpool_node *alias = ipa_ref_refering_varpool_node (ref);
779 if (include_overwritable
780 || cgraph_variable_initializer_availability (alias) > AVAIL_OVERWRITABLE)
781 if (varpool_for_node_and_aliases (alias, callback, data,
782 include_overwritable))
783 return true;
785 return false;
787 #include "gt-varpool.h"