int stack_size = 0;
int order_pos = 0;
struct cgraph_edge *edge, last;
+ int pass;
struct cgraph_node **stack =
XCNEWVEC (struct cgraph_node *, cgraph_n_nodes);
right through inline functions. */
for (node = cgraph_nodes; node; node = node->next)
node->aux = NULL;
- for (node = cgraph_nodes; node; node = node->next)
- if (!node->aux)
- {
- node2 = node;
- if (!node->callers)
- node->aux = &last;
- else
- node->aux = node->callers;
- while (node2)
- {
- while (node2->aux != &last)
- {
- edge = (struct cgraph_edge *) node2->aux;
- if (edge->next_caller)
- node2->aux = edge->next_caller;
- else
- node2->aux = &last;
- if (!edge->caller->aux)
- {
- if (!edge->caller->callers)
- edge->caller->aux = &last;
- else
- edge->caller->aux = edge->caller->callers;
- stack[stack_size++] = node2;
- node2 = edge->caller;
- break;
- }
- }
- if (node2->aux == &last)
- {
- order[order_pos++] = node2;
- if (stack_size)
- node2 = stack[--stack_size];
- else
- node2 = NULL;
- }
- }
- }
+ for (pass = 0; pass < 2; pass++)
+ for (node = cgraph_nodes; node; node = node->next)
+ if (!node->aux
+ && (pass
+ || (!cgraph_only_called_directly_p (node)
+ && !node->address_taken)))
+ {
+ node2 = node;
+ if (!node->callers)
+ node->aux = &last;
+ else
+ node->aux = node->callers;
+ while (node2)
+ {
+ while (node2->aux != &last)
+ {
+ edge = (struct cgraph_edge *) node2->aux;
+ if (edge->next_caller)
+ node2->aux = edge->next_caller;
+ else
+ node2->aux = &last;
+ if (!edge->caller->aux)
+ {
+ if (!edge->caller->callers)
+ edge->caller->aux = &last;
+ else
+ edge->caller->aux = edge->caller->callers;
+ stack[stack_size++] = node2;
+ node2 = edge->caller;
+ break;
+ }
+ }
+ if (node2->aux == &last)
+ {
+ order[order_pos++] = node2;
+ if (stack_size)
+ node2 = stack[--stack_size];
+ else
+ node2 = NULL;
+ }
+ }
+ }
free (stack);
for (node = cgraph_nodes; node; node = node->next)
node->aux = NULL;
gcc_assert (!node->aux);
#endif
for (node = cgraph_nodes; node; node = node->next)
- if (node->needed && !node->global.inlined_to
+ if (!cgraph_can_remove_if_no_direct_calls_p (node)
&& ((!DECL_EXTERNAL (node->decl))
|| !node->analyzed
|| before_inlining_p))
{
+ gcc_assert (!node->global.inlined_to);
node->aux = first;
first = node;
}
#ifdef ENABLE_CHECKING
verify_cgraph ();
#endif
+
+ /* Reclaim alias pairs for functions that have disappeared from the
+ call graph. */
+ remove_unreachable_alias_pairs ();
+
return changed;
}
+static bool
+cgraph_externally_visible_p (struct cgraph_node *node, bool whole_program)
+{
+ if (!node->local.finalized)
+ return false;
+ if (!DECL_COMDAT (node->decl)
+ && (!TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl)))
+ return false;
+ if (!whole_program)
+ return true;
+ /* COMDAT functions must be shared only if they have address taken,
+ otherwise we can produce our own private implementation with
+ -fwhole-program. */
+ if (DECL_COMDAT (node->decl) && (node->address_taken || !node->analyzed))
+ return true;
+ if (MAIN_NAME_P (DECL_NAME (node->decl)))
+ return true;
+ if (lookup_attribute ("externally_visible", DECL_ATTRIBUTES (node->decl)))
+ return true;
+ return false;
+}
+
/* Mark visibility of all functions.
A local function is one whose calls can occur only in the current
via visibilities for the backend point of view. */
static unsigned int
-function_and_variable_visibility (void)
+function_and_variable_visibility (bool whole_program)
{
struct cgraph_node *node;
struct varpool_node *vnode;
for (node = cgraph_nodes; node; node = node->next)
{
- if (node->reachable
- && (DECL_COMDAT (node->decl)
- || (!flag_whole_program
- && TREE_PUBLIC (node->decl) && !DECL_EXTERNAL (node->decl))))
- node->local.externally_visible = true;
+ gcc_assert ((!DECL_WEAK (node->decl) && !DECL_COMDAT (node->decl))
+ || TREE_PUBLIC (node->decl) || DECL_EXTERNAL (node->decl));
+ if (cgraph_externally_visible_p (node, whole_program))
+ {
+ gcc_assert (!node->global.inlined_to);
+ node->local.externally_visible = true;
+ }
+ else
+ node->local.externally_visible = false;
if (!node->local.externally_visible && node->analyzed
&& !DECL_EXTERNAL (node->decl))
{
- gcc_assert (flag_whole_program || !TREE_PUBLIC (node->decl));
+ gcc_assert (whole_program || !TREE_PUBLIC (node->decl));
TREE_PUBLIC (node->decl) = 0;
+ DECL_COMDAT (node->decl) = 0;
+ DECL_WEAK (node->decl) = 0;
}
- node->local.local = (!node->needed
+ node->local.local = (cgraph_only_called_directly_p (node)
&& node->analyzed
&& !DECL_EXTERNAL (node->decl)
&& !node->local.externally_visible);
}
for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
{
+ if (!vnode->finalized)
+ continue;
+ gcc_assert ((!DECL_WEAK (vnode->decl) && !DECL_COMMON (vnode->decl) && !DECL_COMDAT (vnode->decl))
+ || TREE_PUBLIC (vnode->decl) || DECL_EXTERNAL (node->decl));
if (vnode->needed
- && !flag_whole_program
- && (DECL_COMDAT (vnode->decl) || TREE_PUBLIC (vnode->decl)))
- vnode->externally_visible = 1;
+ && (DECL_COMDAT (vnode->decl) || TREE_PUBLIC (vnode->decl))
+ && (!whole_program
+ /* We can privatize comdat readonly variables whose address is not taken,
+ but doing so is not going to bring us optimization oppurtunities until
+ we start reordering datastructures. */
+ || DECL_COMDAT (vnode->decl)
+ || DECL_WEAK (vnode->decl)
+ || lookup_attribute ("externally_visible",
+ DECL_ATTRIBUTES (vnode->decl))))
+ vnode->externally_visible = true;
+ else
+ vnode->externally_visible = false;
if (!vnode->externally_visible)
{
- gcc_assert (flag_whole_program || !TREE_PUBLIC (vnode->decl));
+ gcc_assert (whole_program || !TREE_PUBLIC (vnode->decl));
TREE_PUBLIC (vnode->decl) = 0;
}
gcc_assert (TREE_STATIC (vnode->decl));
if (node->local.externally_visible)
fprintf (dump_file, " %s", cgraph_node_name (node));
fprintf (dump_file, "\n\n");
+ fprintf (dump_file, "\nMarking externally visible variables:");
+ for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
+ if (vnode->externally_visible)
+ fprintf (dump_file, " %s", varpool_node_name (vnode));
+ fprintf (dump_file, "\n\n");
}
cgraph_function_flags_ready = true;
return 0;
}
+/* Local function pass handling visibilities. This happens before LTO streaming
+ so in particular -fwhole-program should be ignored at this level. */
+
+static unsigned int
+local_function_and_variable_visibility (void)
+{
+ return function_and_variable_visibility (flag_whole_program && !flag_lto && !flag_whopr);
+}
+
struct simple_ipa_opt_pass pass_ipa_function_and_variable_visibility =
{
{
SIMPLE_IPA_PASS,
"visibility", /* name */
NULL, /* gate */
- function_and_variable_visibility, /* execute */
+ local_function_and_variable_visibility,/* execute */
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
}
};
+/* Do not re-run on ltrans stage. */
+
+static bool
+gate_whole_program_function_and_variable_visibility (void)
+{
+ return !flag_ltrans;
+}
+
+/* Bring functionss local at LTO time whith -fwhole-program. */
+
+static unsigned int
+whole_program_function_and_variable_visibility (void)
+{
+ struct cgraph_node *node;
+ struct varpool_node *vnode;
+
+ function_and_variable_visibility (flag_whole_program);
+
+ for (node = cgraph_nodes; node; node = node->next)
+ if ((node->local.externally_visible && !DECL_COMDAT (node->decl))
+ && node->local.finalized)
+ cgraph_mark_needed_node (node);
+ for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
+ if (vnode->externally_visible && !DECL_COMDAT (vnode->decl))
+ varpool_mark_needed_node (vnode);
+ if (dump_file)
+ {
+ fprintf (dump_file, "\nNeeded variables:");
+ for (vnode = varpool_nodes_queue; vnode; vnode = vnode->next_needed)
+ if (vnode->needed)
+ fprintf (dump_file, " %s", varpool_node_name (vnode));
+ fprintf (dump_file, "\n\n");
+ }
+ return 0;
+}
+
+struct ipa_opt_pass_d pass_ipa_whole_program_visibility =
+{
+ {
+ IPA_PASS,
+ "whole-program", /* name */
+ gate_whole_program_function_and_variable_visibility,/* gate */
+ whole_program_function_and_variable_visibility,/* execute */
+ NULL, /* sub */
+ NULL, /* next */
+ 0, /* static_pass_number */
+ TV_CGRAPHOPT, /* tv_id */
+ 0, /* properties_required */
+ 0, /* properties_provided */
+ 0, /* properties_destroyed */
+ 0, /* todo_flags_start */
+ TODO_dump_cgraph | TODO_remove_functions/* todo_flags_finish */
+ },
+ NULL, /* generate_summary */
+ NULL, /* write_summary */
+ NULL, /* read_summary */
+ NULL, /* function_read_summary */
+ NULL, /* stmt_fixup */
+ 0, /* TODOs */
+ NULL, /* function_transform */
+ NULL, /* variable_transform */
+};
/* Hash a cgraph node set element. */