aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Hubicka <hubicka@ucw.cz>2014-05-25 07:52:49 +0200
committerJan Hubicka <hubicka@gcc.gnu.org>2014-05-25 05:52:49 +0000
commit07990a5e8e43ec758cbdfb2116b3d069b72f9543 (patch)
tree41d085d6d68e68b01c59e827077157d76a679599
parent05fc16dde913ed47ab4352a34b15f71d24d58934 (diff)
downloadgcc-07990a5e8e43ec758cbdfb2116b3d069b72f9543.zip
gcc-07990a5e8e43ec758cbdfb2116b3d069b72f9543.tar.gz
gcc-07990a5e8e43ec758cbdfb2116b3d069b72f9543.tar.bz2
ipa-visibility.c (can_replace_by_local_alias_in_vtable): New function.
* ipa-visibility.c (can_replace_by_local_alias_in_vtable): New function. (update_vtable_references): New function. (function_and_variable_visibility): Rewrite also vtable initializers. * varpool.c (cgraph_variable_initializer_availability): Remove assert. From-SVN: r210910
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/ipa-visibility.c58
-rw-r--r--gcc/varpool.c1
3 files changed, 65 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 46aa41c..8a5ff8f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2014-05-23 Jan Hubicka <hubicka@ucw.cz>
+ * ipa-visibility.c (can_replace_by_local_alias_in_vtable): New function.
+ (update_vtable_references): New function.
+ (function_and_variable_visibility): Rewrite also vtable initializers.
+ * varpool.c (cgraph_variable_initializer_availability): Remove assert.
+
+2014-05-23 Jan Hubicka <hubicka@ucw.cz>
+
* ggc.h (ggc_grow): New function.
* ggc-none.c (ggc_grow): New function.
* ggc-page.c (ggc_grow): Likewise.
diff --git a/gcc/ipa-visibility.c b/gcc/ipa-visibility.c
index b091071..dc22b2e 100644
--- a/gcc/ipa-visibility.c
+++ b/gcc/ipa-visibility.c
@@ -343,6 +343,36 @@ can_replace_by_local_alias (symtab_node *node)
&& !symtab_can_be_discarded (node));
}
+/* Return true if we can replace refernece to NODE by local alias
+ within a virtual table. Generally we can replace function pointers
+ and virtual table pointers. */
+
+bool
+can_replace_by_local_alias_in_vtable (symtab_node *node)
+{
+ if (is_a <varpool_node *> (node)
+ && !DECL_VIRTUAL_P (node->decl))
+ return false;
+ return can_replace_by_local_alias (node);
+}
+
+/* walk_tree callback that rewrites initializer references. */
+
+static tree
+update_vtable_references (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED)
+{
+ if (TREE_CODE (*tp) == VAR_DECL
+ || TREE_CODE (*tp) == FUNCTION_DECL)
+ {
+ if (can_replace_by_local_alias_in_vtable (symtab_get_node (*tp)))
+ *tp = symtab_nonoverwritable_alias (symtab_get_node (*tp))->decl;
+ *walk_subtrees = 0;
+ }
+ else if (IS_TYPE_OR_DECL_P (*tp))
+ *walk_subtrees = 0;
+ return NULL;
+}
+
/* In LTO we can remove COMDAT groups and weak symbols.
Either turn them into normal symbols or external symbol depending on
resolution info. */
@@ -625,6 +655,34 @@ function_and_variable_visibility (bool whole_program)
vnode->resolution = LDPR_PREVAILING_DEF_IRONLY;
}
update_visibility_by_resolution_info (vnode);
+
+ /* Update virutal tables to point to local aliases where possible. */
+ if (DECL_VIRTUAL_P (vnode->decl)
+ && !DECL_EXTERNAL (vnode->decl))
+ {
+ int i;
+ struct ipa_ref *ref;
+ bool found = false;
+
+ /* See if there is something to update. */
+ for (i = 0; ipa_ref_list_referring_iterate (&vnode->ref_list,
+ i, ref); i++)
+ if (ref->use == IPA_REF_ADDR
+ && can_replace_by_local_alias_in_vtable (ref->referred))
+ {
+ found = true;
+ break;
+ }
+ if (found)
+ {
+ struct pointer_set_t *visited_nodes = pointer_set_create ();
+ walk_tree (&DECL_INITIAL (vnode->decl),
+ update_vtable_references, NULL, visited_nodes);
+ pointer_set_destroy (visited_nodes);
+ ipa_remove_all_references (&vnode->ref_list);
+ record_references_in_initializer (vnode->decl, false);
+ }
+ }
}
if (dump_file)
diff --git a/gcc/varpool.c b/gcc/varpool.c
index 4525579..1697bb4 100644
--- a/gcc/varpool.c
+++ b/gcc/varpool.c
@@ -355,7 +355,6 @@ varpool_add_new_variable (tree decl)
enum availability
cgraph_variable_initializer_availability (varpool_node *node)
{
- gcc_assert (cgraph_function_flags_ready);
if (!node->definition)
return AVAIL_NOT_AVAILABLE;
if (!TREE_PUBLIC (node->decl))