aboutsummaryrefslogtreecommitdiff
path: root/gcc/cgraphunit.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cgraphunit.c')
-rw-r--r--gcc/cgraphunit.c186
1 files changed, 141 insertions, 45 deletions
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index dd247eb..b01f22b 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -167,6 +167,7 @@ cgraph_decide_is_function_needed (struct cgraph_node *node, tree decl)
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)
+ && (!node->thunk.thunk_p && !node->same_body_alias)
&& TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
return true;
@@ -391,6 +392,8 @@ cgraph_mark_if_needed (tree decl)
static bool
clone_of_p (struct cgraph_node *node, struct cgraph_node *node2)
{
+ node = cgraph_function_or_thunk_node (node, NULL);
+ node2 = cgraph_function_or_thunk_node (node2, NULL);
while (node != node2 && node2)
node2 = node2->clone_of;
return node2 != NULL;
@@ -619,6 +622,36 @@ verify_cgraph_node (struct cgraph_node *node)
while (n != node);
}
+ if (node->analyzed && node->alias)
+ {
+ bool ref_found = false;
+ int i;
+ struct ipa_ref *ref;
+
+ if (node->callees)
+ {
+ error ("Alias has call edges");
+ error_found = true;
+ }
+ for (i = 0; ipa_ref_list_reference_iterate (&node->ref_list, i, ref); i++)
+ if (ref->use != IPA_REF_ALIAS)
+ {
+ error ("Alias has non-alias refernece");
+ error_found = true;
+ }
+ else if (ref_found)
+ {
+ error ("Alias has more than one alias reference");
+ error_found = true;
+ }
+ else
+ ref_found = true;
+ if (!ref_found)
+ {
+ error ("Analyzed alias has no reference");
+ error_found = true;
+ }
+ }
if (node->analyzed && node->thunk.thunk_p)
{
if (!node->callees)
@@ -669,19 +702,17 @@ verify_cgraph_node (struct cgraph_node *node)
}
if (!e->indirect_unknown_callee)
{
- if (e->callee->same_body_alias)
- {
- error ("edge points to same body alias:");
- debug_tree (e->callee->decl);
- error_found = true;
- }
- else if (!e->callee->global.inlined_to
- && decl
- && cgraph_get_node (decl)
- && (e->callee->former_clone_of
- != cgraph_get_node (decl)->decl)
- && !clone_of_p (cgraph_get_node (decl),
- e->callee))
+ if (!e->callee->global.inlined_to
+ && decl
+ && cgraph_get_node (decl)
+ && (e->callee->former_clone_of
+ != cgraph_get_node (decl)->decl)
+ /* IPA-CP sometimes redirect edge to clone and then back to the former
+ function. This ping-pong has to go, eventaully. */
+ && (cgraph_function_or_thunk_node (cgraph_get_node (decl), NULL)
+ != cgraph_function_or_thunk_node (e->callee, NULL))
+ && !clone_of_p (cgraph_get_node (decl),
+ e->callee))
{
error ("edge points to wrong declaration:");
debug_tree (e->callee->decl);
@@ -781,7 +812,53 @@ cgraph_analyze_function (struct cgraph_node *node)
tree save = current_function_decl;
tree decl = node->decl;
- if (node->thunk.thunk_p)
+ if (node->alias && node->thunk.alias)
+ {
+ struct cgraph_node *tgt = cgraph_get_node (node->thunk.alias);
+ if (!VEC_length (ipa_ref_t, node->ref_list.references))
+ ipa_record_reference (node, NULL, tgt, NULL, IPA_REF_ALIAS, NULL);
+ if (node->same_body_alias)
+ {
+ DECL_VIRTUAL_P (node->decl) = DECL_VIRTUAL_P (node->thunk.alias);
+ DECL_DECLARED_INLINE_P (node->decl)
+ = DECL_DECLARED_INLINE_P (node->thunk.alias);
+ DECL_DISREGARD_INLINE_LIMITS (node->decl)
+ = DECL_DISREGARD_INLINE_LIMITS (node->thunk.alias);
+ }
+
+ /* Fixup visibility nonsences C++ frontend produce on same body aliases. */
+ if (TREE_PUBLIC (node->decl) && node->same_body_alias)
+ {
+ DECL_EXTERNAL (node->decl) = DECL_EXTERNAL (node->thunk.alias);
+ if (DECL_COMDAT (node->thunk.alias))
+ {
+ DECL_COMDAT (node->decl) = 1;
+ DECL_COMDAT_GROUP (node->decl) = DECL_COMDAT_GROUP (node->thunk.alias);
+ if (DECL_ONE_ONLY (node->thunk.alias) && !node->same_comdat_group)
+ {
+ struct cgraph_node *tgt = cgraph_get_node (node->thunk.alias);
+ node->same_comdat_group = tgt;
+ if (!tgt->same_comdat_group)
+ tgt->same_comdat_group = node;
+ else
+ {
+ struct cgraph_node *n;
+ for (n = tgt->same_comdat_group;
+ n->same_comdat_group != tgt;
+ n = n->same_comdat_group)
+ ;
+ n->same_comdat_group = node;
+ }
+ }
+ }
+ }
+ cgraph_mark_reachable_node (cgraph_alias_aliased_node (node));
+ if (node->address_taken)
+ cgraph_mark_address_taken_node (cgraph_alias_aliased_node (node));
+ if (cgraph_decide_is_function_needed (node, node->decl))
+ cgraph_mark_needed_node (node);
+ }
+ else if (node->thunk.thunk_p)
{
cgraph_create_edge (node, cgraph_get_node (node->thunk.alias),
NULL, 0, CGRAPH_FREQ_BASE);
@@ -809,6 +886,26 @@ cgraph_analyze_function (struct cgraph_node *node)
current_function_decl = save;
}
+/* C++ frontend produce same body aliases all over the place, even before PCH
+ gets streamed out. It relies on us linking the aliases with their function
+ in order to do the fixups, but ipa-ref is not PCH safe. Consequentely we
+ first produce aliases without links, but once C++ FE is sure he won't sream
+ PCH we build the links via this function. */
+
+void
+cgraph_process_same_body_aliases (void)
+{
+ struct cgraph_node *node;
+ for (node = cgraph_nodes; node; node = node->next)
+ if (node->same_body_alias
+ && !VEC_length (ipa_ref_t, node->ref_list.references))
+ {
+ struct cgraph_node *tgt = cgraph_get_node (node->thunk.alias);
+ ipa_record_reference (node, NULL, tgt, NULL, IPA_REF_ALIAS, NULL);
+ }
+ same_body_aliases_done = true;
+}
+
/* Process attributes common for vars and functions. */
static void
@@ -880,7 +977,7 @@ process_function_and_variable_attributes (struct cgraph_node *first,
cgraph_mark_needed_node (node);
}
if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
- && node->local.finalized)
+ && (node->local.finalized && !node->alias))
{
warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
"%<weakref%> attribute ignored"
@@ -979,6 +1076,7 @@ cgraph_analyze_functions (void)
weak alias attribute to kill its body. See
gcc.c-torture/compile/20011119-1.c */
if (!DECL_STRUCT_FUNCTION (decl)
+ && (!node->alias || !node->thunk.alias)
&& !node->thunk.thunk_p)
{
cgraph_reset_node (node);
@@ -1046,11 +1144,13 @@ cgraph_analyze_functions (void)
next = node->next;
if (node->local.finalized && !gimple_has_body_p (decl)
+ && (!node->alias || !node->thunk.alias)
&& !node->thunk.thunk_p)
cgraph_reset_node (node);
if (!node->reachable
- && (gimple_has_body_p (decl) || node->thunk.thunk_p))
+ && (gimple_has_body_p (decl) || node->thunk.thunk_p
+ || (node->alias && node->thunk.alias)))
{
if (cgraph_dump_file)
fprintf (cgraph_dump_file, " %s", cgraph_node_name (node));
@@ -1060,6 +1160,7 @@ cgraph_analyze_functions (void)
else
node->next_needed = NULL;
gcc_assert (!node->local.finalized || node->thunk.thunk_p
+ || node->alias
|| gimple_has_body_p (decl));
gcc_assert (node->analyzed == node->local.finalized);
}
@@ -1157,9 +1258,11 @@ cgraph_mark_functions_to_output (void)
outside the current compilation unit. */
if (node->analyzed
&& !node->thunk.thunk_p
+ && !node->alias
&& !node->global.inlined_to
&& (!cgraph_only_called_directly_p (node)
- || (e && node->reachable))
+ || ((e || ipa_ref_has_aliases_p (&node->ref_list))
+ && node->reachable))
&& !TREE_ASM_WRITTEN (decl)
&& !DECL_EXTERNAL (decl))
{
@@ -1170,7 +1273,7 @@ cgraph_mark_functions_to_output (void)
for (next = node->same_comdat_group;
next != node;
next = next->same_comdat_group)
- if (!next->thunk.thunk_p)
+ if (!next->thunk.thunk_p && !next->alias)
next->process = 1;
}
}
@@ -1190,6 +1293,7 @@ cgraph_mark_functions_to_output (void)
are inside partition, we can end up not removing the body since we no longer
have analyzed node pointing to it. */
&& !node->in_other_partition
+ && !node->alias
&& !DECL_EXTERNAL (decl))
{
dump_cgraph_node (stderr, node);
@@ -1219,7 +1323,7 @@ cgraph_mark_functions_to_output (void)
&& !DECL_EXTERNAL (decl))
{
dump_cgraph_node (stderr, node);
- internal_error ("failed to reclaim unneeded function");
+ internal_error ("failed to reclaim unneeded functionin same comdat group");
}
}
#endif
@@ -1569,23 +1673,35 @@ assemble_thunk (struct cgraph_node *node)
}
-/* Assemble thunks asociated to NODE. */
+
+/* Assemble thunks and aliases asociated to NODE. */
static void
-assemble_thunks (struct cgraph_node *node)
+assemble_thunks_and_aliases (struct cgraph_node *node)
{
struct cgraph_edge *e;
+ int i;
+ struct ipa_ref *ref;
+
for (e = node->callers; e;)
if (e->caller->thunk.thunk_p)
{
struct cgraph_node *thunk = e->caller;
e = e->next_caller;
- assemble_thunks (thunk);
+ assemble_thunks_and_aliases (thunk);
assemble_thunk (thunk);
}
else
e = e->next_caller;
+ for (i = 0; ipa_ref_list_refering_iterate (&node->ref_list, i, ref); i++)
+ if (ref->use == IPA_REF_ALIAS)
+ {
+ struct cgraph_node *alias = ipa_ref_refering_node (ref);
+ assemble_alias (alias->decl,
+ DECL_ASSEMBLER_NAME (alias->thunk.alias));
+ assemble_thunks_and_aliases (alias);
+ }
}
/* Expand function specified by NODE. */
@@ -1600,27 +1716,7 @@ cgraph_expand_function (struct cgraph_node *node)
announce_function (decl);
node->process = 0;
- if (node->same_body)
- {
- struct cgraph_node *alias, *next;
- bool saved_alias = node->alias;
- for (alias = node->same_body;
- alias && alias->next; alias = alias->next)
- ;
- /* Walk aliases in the order they were created; it is possible that
- thunks refers to the aliases made earlier. */
- for (; alias; alias = next)
- {
- next = alias->previous;
- if (!alias->thunk.thunk_p)
- assemble_alias (alias->decl,
- DECL_ASSEMBLER_NAME (alias->thunk.alias));
- }
- node->alias = saved_alias;
- cgraph_process_new_functions ();
- }
-
- assemble_thunks (node);
+ assemble_thunks_and_aliases (node);
gcc_assert (node->lowered);
/* Generate RTL for the body of DECL. */
@@ -1736,7 +1832,7 @@ cgraph_output_in_order (void)
for (pf = cgraph_nodes; pf; pf = pf->next)
{
- if (pf->process && !pf->thunk.thunk_p)
+ if (pf->process && !pf->thunk.thunk_p && !pf->alias)
{
i = pf->order;
gcc_assert (nodes[i].kind == ORDER_UNDEFINED);
@@ -1810,7 +1906,7 @@ bool
cgraph_preserve_function_body_p (struct cgraph_node *node)
{
gcc_assert (cgraph_global_info_ready);
- gcc_assert (!node->same_body_alias);
+ gcc_assert (!node->alias && !node->thunk.thunk_p);
/* Look if there is any clone around. */
if (node->clones)