public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* ipa-visibility TLC 2/n
@ 2014-05-25  5:54 Jan Hubicka
  2014-05-25 20:45 ` Ramana Radhakrishnan
  2014-05-26 15:39 ` Martin Liška
  0 siblings, 2 replies; 44+ messages in thread
From: Jan Hubicka @ 2014-05-25  5:54 UTC (permalink / raw)
  To: gcc-patches

Hi,
this patch adds code to rerite references in vtable initializers to local aliases
when doing so is a win.

Bootstrapped/regtested x86_64-linux, comitted.

Honza

	* 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.
Index: varpool.c
===================================================================
--- varpool.c	(revision 210908)
+++ varpool.c	(working copy)
@@ -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))
Index: ipa-visibility.c
===================================================================
--- ipa-visibility.c	(revision 210908)
+++ ipa-visibility.c	(working copy)
@@ -343,6 +343,36 @@ can_replace_by_local_alias (symtab_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 w
 	  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)

^ permalink raw reply	[flat|nested] 44+ messages in thread
* Re: ipa-visibility TLC 2/n
@ 2014-05-28 21:44 David Edelsohn
  2014-05-28 22:31 ` Jan Hubicka
  0 siblings, 1 reply; 44+ messages in thread
From: David Edelsohn @ 2014-05-28 21:44 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: GCC Patches, Richard Henderson, ramrad01

Honza,

I'm glad that you're making progress.

> David, this looks like a bug in the AIX target output macros. I get:
>         .set _ZTCSt14basic_ifstreamIcSt11char_traitsIcEE0_Si.localalias.69,_ZTCSt14basic_ifstreamIcSt11char_traitsIcEE0_Si

> (this is correct since localalias is really an alias)

> _ZTCSt14basic_ifstreamIcSt11char_traitsIcEE0_Si.localalias.69:
>         .space 40
> _ZTCSt14basic_ifstreamIcSt11char_traitsIcEE0_Si:
...

> This is wrong, since we should not try to out the variable at least if I read AIX assembly correctly.

> varpool has explicit test to not output any aliases, so perhaps this is a bug in wrapup_globals
> and AIX output macros.  I will try to track more after my teaching tonight.

The AIX support handles AIX XCOFF assembler syntax and chooses
appropriate sections, but it would not choose to emit an extra
definition. If there are multiple definitions, then the varasm macros
are being invoked multiple times for the same symbol.


Thanks, David

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2014-06-13  3:22 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-25  5:54 ipa-visibility TLC 2/n Jan Hubicka
2014-05-25 20:45 ` Ramana Radhakrishnan
2014-05-25 22:23   ` Jan Hubicka
2014-05-26  1:04     ` Jan Hubicka
2014-05-26  5:29       ` Ramana Radhakrishnan
2014-05-27 20:06         ` Jan Hubicka
2014-05-27 22:20           ` Jan Hubicka
2014-05-28 17:39             ` Yufeng Zhang
2014-05-28 19:52               ` Jan Hubicka
2014-05-28 21:56               ` Jan Hubicka
2014-05-29 14:17                 ` Yufeng Zhang
2014-05-30 16:18                   ` Ramana Radhakrishnan
2014-05-26 15:39 ` Martin Liška
2014-05-28 21:44 David Edelsohn
2014-05-28 22:31 ` Jan Hubicka
2014-05-28 22:44   ` David Edelsohn
2014-05-28 23:17     ` Jan Hubicka
2014-05-29  8:08       ` Richard Sandiford
2014-05-29 17:12         ` Jan Hubicka
2014-05-30  7:20           ` Richard Sandiford
2014-05-30 15:50             ` David Edelsohn
2014-06-08 16:44               ` Jan Hubicka
2014-06-10  8:51                 ` Richard Biener
2014-06-08 16:49               ` Jan Hubicka
2014-06-08 16:54               ` Jan Hubicka
2014-06-08 16:58                 ` Jan Hubicka
2014-06-10 13:08                   ` David Edelsohn
2014-06-10 18:02                     ` Jan Hubicka
2014-06-10 22:23                       ` David Edelsohn
2014-06-10 22:55                         ` Jan Hubicka
2014-06-11 14:26                           ` Rainer Orth
2014-06-11 17:02                             ` Jan Hubicka
2014-06-12 10:43                               ` Rainer Orth
2014-06-12 13:33                                 ` Rainer Orth
2014-06-13  3:22                                 ` Jan Hubicka
2014-06-11  8:17                         ` Jan Hubicka
2014-05-30 17:24             ` David Edelsohn
2014-05-30 21:02               ` Jan Hubicka
2014-05-31  0:57                 ` David Edelsohn
2014-05-31  7:42                   ` Richard Sandiford
2014-05-31 14:43                     ` David Edelsohn
2014-06-03 13:53               ` David Edelsohn
2014-06-06  7:10                 ` Jan Hubicka
2014-06-06 15:53                   ` David Edelsohn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).