aboutsummaryrefslogtreecommitdiff
path: root/gcc/cgraphunit.c
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-11 13:01:53 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2011-06-11 13:01:53 +0000
commitc70f46b057cd12973d33c01c8fa0da5c14ba3944 (patch)
treec6e4afcefa6681889da1ab377bb53466f789c2ff /gcc/cgraphunit.c
parente696a4cb377cdd9f8cf5c4066b8cf8e18891c923 (diff)
* lto-symtab.c (lto_cgraph_replace_node): Kill same body alias code.
(lto_symtab_resolve_can_prevail_p): Likewise. (lto_symtab_merge_cgraph_nodes): Update merging of aliases. * cgraph.c (same_body_aliases_done): New global var. (cgraph_same_body_alias_1): Rename to ... (cgraph_create_function_alias): ... this one; reorg to new representation. (cgraph_same_body_alias): Use cgraph_create_function_alias; record references when asked to. (cgraph_add_thunk): Fix formating. (cgraph_get_node): Kill same body alias code. (cgraph_node_for_asm): Likewise. (cgraph_remove_same_body_alias): Remove. (cgraph_remove_node): Kill same body alias code. (cgraph_mark_address_taken_node): Mark also the aliased function as having address taken. (dump_cgraph_node): Dump same body aliases. (cgraph_for_node_thunks_and_aliases): Update for new alias representation. (cgraph_for_node_and_aliases): Likewise. * cgraph.h (same_body): Kll pointer. (same_body_alias): Update comment. (same_body_aliases_done): Declare. (cgraph_remove_same_body_alias): Remove declaration. (cgraph_create_function_alias): Declare. (cgraph_process_same_body_aliases): Declare. (cgraph_function_with_gimple_body_p): Check for alias. (cgraph_can_remove_if_no_direct_calls_p): Look for aliases. (cgraph_alias_aliased_node): New function. (cgraph_function_node): Update for new aliases. (cgraph_function_or_thunk_node): Likewise. * ipa-inline-transform.c (can_remove_node_now_p): Look for aliases. (inline_call): Remove dead aliases. * cgraphunit.c (cgraph_decide_is_function_needed): Disable assembler name hack for same body aliases. (clone_of_p): Look through aliases. (verify_cgraph_node): Verify aliases. (cgraph_analyze_function): Analyze aliases; fixup C++ bugs. (cgraph_process_same_body_aliases): New function. (process_function_and_variable_attributes): Disable weakref warning on alias. (cgraph_analyze_functions): Handle aliases. (cgraph_mark_functions_to_output): Handle aliases same way as thunks. (assemble_thunks): Rename to ... (assemble_thunks_and_aliases): ... this one; handle aliases, too. (cgraph_expand_function): Remove alias output code. (cgraph_output_in_order): Skip aliases. (cgraph_preserve_function_body_p): Aliases don't need preserving. * ipa-ref.c (ipa_ref_use_name): Add alias reference. (ipa_record_reference): Do not assert on alias references. (ipa_ref_has_aliases_p): New function. * ipa-ref.h (enum ipa_ref_use): Add IPA_REF_ALIAS. (ipa_ref_has_aliases_p): Declare. * lto-cgraph.c (lto_output_node): Handle aliases. (input_node): Likewise. * lto-streamer-out.c (lto_output): Skip aliases. (produce_symtab): Kill same_body_alias code. * ipa-utils.c (ipa_reverse_postorder): Add FIXME. (ipa_reverse_postorder): Use cgraph_only_called_directly_or_aliased_p. * ipa-inline.c (update_caller_keys): Walk aliases. (inline_small_functions): Fix thinko in previous patch. * ipa.c (cgraph_externally_visible_p): Do not walk aliases. (function_and_variable_visibility): Do not walk same body aliases. * tree-ssa-structalias.c (associate_varinfo_to_alias): New function. (ipa_pta_execute): Use it. * lto.c (add_cgraph_node_to_partition_1): Break out from ... (add_cgraph_node_to_partition) ... here; walk aliases. (lto_1_to_1_map): Remove same body alias code. (promote_fn): Likewise. (lto_promote_cross_file_statics): Update comment. * decl2.c (cp_write_global_declarations): Process aliases; look trhough same body aliases. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@174952 138bc75d-0d04-0410-961f-82ee72b054a4
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 dd247eb231d..b01f22b2b23 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)