-/* Helper function for finalization code - add node into lists so it will
- be analyzed and compiled. */
-void
-cgraph_varpool_enqueue_needed_node (struct cgraph_varpool_node *node)
-{
- if (cgraph_varpool_last_needed_node)
- cgraph_varpool_last_needed_node->next_needed = node;
- cgraph_varpool_last_needed_node = node;
- node->next_needed = NULL;
- if (!cgraph_varpool_nodes_queue)
- cgraph_varpool_nodes_queue = node;
- if (!cgraph_varpool_first_unanalyzed_node)
- cgraph_varpool_first_unanalyzed_node = node;
- notice_global_symbol (node->decl);
-}
-
-/* Reset the queue of needed nodes. */
-void
-cgraph_varpool_reset_queue (void)
-{
- cgraph_varpool_last_needed_node = NULL;
- cgraph_varpool_nodes_queue = NULL;
- cgraph_varpool_first_unanalyzed_node = NULL;
-}
-
-/* Notify finalize_compilation_unit that given node is reachable
- or needed. */
-void
-cgraph_varpool_mark_needed_node (struct cgraph_varpool_node *node)
-{
- if (!node->needed && node->finalized)
- cgraph_varpool_enqueue_needed_node (node);
- node->needed = 1;
-}
-
-/* Determine if variable DECL is needed. That is, visible to something
- either outside this translation unit, something magic in the system
- configury, or (if not doing unit-at-a-time) to something we haven't
- seen yet. */
-
-bool
-decide_is_variable_needed (struct cgraph_varpool_node *node, tree decl)
-{
- /* If the user told us it is used, then it must be so. */
- if (node->externally_visible
- || lookup_attribute ("used", DECL_ATTRIBUTES (decl)))
- return true;
-
- /* ??? If the assembler name is set by hand, it is possible to assemble
- the name later after finalizing the function and the fact is noticed
- in assemble_name then. This is arguably a bug. */
- if (DECL_ASSEMBLER_NAME_SET_P (decl)
- && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
- return true;
-
- /* If we decided it was needed before, but at the time we didn't have
- the definition available, then it's still needed. */
- if (node->needed)
- return true;
-
- /* Externally visible variables must be output. The exception is
- COMDAT variables that must be output only when they are needed. */
- if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
- return true;
-
- /* When not reordering top level variables, we have to assume that
- we are going to keep everything. */
- if (flag_unit_at_a_time && flag_toplevel_reorder)
- return false;
-
- /* We want to emit COMDAT variables only when absolutely necessary. */
- if (DECL_COMDAT (decl))
- return false;
- return true;
-}
-
-void
-cgraph_varpool_finalize_decl (tree decl)
-{
- struct cgraph_varpool_node *node = cgraph_varpool_node (decl);
-
- /* The first declaration of a variable that comes through this function
- decides whether it is global (in C, has external linkage)
- or local (in C, has internal linkage). So do nothing more
- if this function has already run. */
- if (node->finalized)
- {
- if (cgraph_global_info_ready || (!flag_unit_at_a_time && !flag_openmp))
- cgraph_varpool_assemble_pending_decls ();
- return;
- }
- if (node->needed)
- cgraph_varpool_enqueue_needed_node (node);
- node->finalized = true;
-
- if (decide_is_variable_needed (node, decl))
- cgraph_varpool_mark_needed_node (node);
- /* Since we reclaim unreachable nodes at the end of every language
- level unit, we need to be conservative about possible entry points
- there. */
- else if (TREE_PUBLIC (decl) && !DECL_COMDAT (decl) && !DECL_EXTERNAL (decl))
- cgraph_varpool_mark_needed_node (node);
- if (cgraph_global_info_ready || (!flag_unit_at_a_time && !flag_openmp))
- cgraph_varpool_assemble_pending_decls ();
-}
-