diff mbox

Correctly fill up cgraph_node::local.versionable flag.

Message ID 56256395.2010908@suse.cz
State New
Headers show

Commit Message

Martin Liška Oct. 19, 2015, 9:41 p.m. UTC
On 10/17/2015 09:49 PM, Jan Hubicka wrote:
>> Hello.
>>
>> I've been working on HSA branch, where we have a cloning pass running with all
>> optimization levels. The patch makes computation of cgraph_node::local.versionability
>> independent on IPA CP and uses the flag to verify that a function can be cloned.
>>
>> The patch can bootstrap on x86_64-linux-pc and survives test suite.
>>
>> Ready for trunk?
>> Thanks,
>> Martin
>
>> >From d17b51257d5e01ab6bd9a018b08f8ed6fd39c029 Mon Sep 17 00:00:00 2001
>> From: marxin <mliska@suse.cz>
>> Date: Thu, 8 Oct 2015 17:57:30 +0200
>> Subject: [PATCH 1/3] Correctly fill up cgraph_node::local.versionable flag.
>>
>> gcc/ChangeLog:
>>
>> 2015-10-15  Martin Liska  <mliska@suse.cz>
>>
>> 	* cgraphclones.c (cgraph_node::create_virtual_clone):
>> 	Verify cgraph_node.local.versionable instead of calling
>> 	tree_versionable_function_p.
>> 	* ipa-cp.c (determine_versionability): Save the information
>> 	to ipa_node_params summary.
>> 	(ipcp_versionable_function_p): Use it.
>> 	(ipcp_propagate_stage): Pass IPA_NODE_REF to a called function.
>> 	(ipcp_generate_summary): Do not compute cgraph_node
>> 	versionability.
>
> If you want to use the flag at WPA time, you need to stream it for LTO.
> I suppose this only passed testing because we have no testcases checking that
> ipa-cp happens with LTO.

Hi.

The flag is already streamed.

>
>> 	* ipa-inline-analysis.c (inline_generate_summary): Compute
>> 	visibility for all cgraph nodes.
>> 	* ipa-prop.c (ipa_node_params_t::duplicate): Duplicate
>> 	ipa_node_params::versionability.
>> 	* ipa-prop.h (struct ipa_node_params): Declare it.
>> ---
>>   gcc/cgraphclones.c        |  2 +-
>>   gcc/ipa-cp.c              | 15 ++++++---------
>>   gcc/ipa-inline-analysis.c |  4 ++++
>>   gcc/ipa-prop.c            |  1 +
>>   gcc/ipa-prop.h            |  2 ++
>>   5 files changed, 14 insertions(+), 10 deletions(-)
>>
>> diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
>> index e51431c..5c04dc4 100644
>> --- a/gcc/cgraphclones.c
>> +++ b/gcc/cgraphclones.c
>> @@ -570,7 +570,7 @@ cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
>>     char *name;
>>
>>     if (!in_lto_p)
>> -    gcc_checking_assert (tree_versionable_function_p (old_decl));
>> +    gcc_checking_assert (local.versionable);
>
> Then you should be able to drop in_lto_p here.

Yes, it works.

I'm sending final version of the patch which I'm going to install to trunk.

Thanks for the review,
Martin

>
> OK with that change.
>
> Honza
>
diff mbox

Patch

From 83a16ac2716baf7418d581398769e78bbde6abd0 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Thu, 8 Oct 2015 17:57:30 +0200
Subject: [PATCH] Correctly fill up cgraph_node::local.versionable flag.

gcc/ChangeLog:

2015-10-15  Martin Liska  <mliska@suse.cz>

	* cgraphclones.c (cgraph_node::create_virtual_clone):
	Verify cgraph_node.local.versionable instead of calling
	tree_versionable_function_p.
	* ipa-cp.c (determine_versionability): Save the information
	to ipa_node_params summary.
	(ipcp_versionable_function_p): Use it.
	(ipcp_propagate_stage): Pass IPA_NODE_REF to a called function.
	(ipcp_generate_summary): Do not compute cgraph_node
	versionability.
	* ipa-inline-analysis.c (inline_generate_summary): Compute
	visibility for all cgraph nodes.
	* ipa-prop.c (ipa_node_params_t::duplicate): Duplicate
	ipa_node_params::versionability.
	* ipa-prop.h (struct ipa_node_params): Declare it.
---
 gcc/cgraphclones.c        |  4 +---
 gcc/ipa-cp.c              | 15 ++++++---------
 gcc/ipa-inline-analysis.c |  4 ++++
 gcc/ipa-prop.c            |  1 +
 gcc/ipa-prop.h            |  2 ++
 5 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/gcc/cgraphclones.c b/gcc/cgraphclones.c
index e51431c..f243f6f 100644
--- a/gcc/cgraphclones.c
+++ b/gcc/cgraphclones.c
@@ -569,9 +569,7 @@  cgraph_node::create_virtual_clone (vec<cgraph_edge *> redirect_callers,
   ipa_replace_map *map;
   char *name;
 
-  if (!in_lto_p)
-    gcc_checking_assert (tree_versionable_function_p (old_decl));
-
+  gcc_checking_assert (local.versionable);
   gcc_assert (local.can_change_signature || !args_to_skip);
 
   /* Make a new FUNCTION_DECL tree node */
diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c
index d9d81f1..ef93b20 100644
--- a/gcc/ipa-cp.c
+++ b/gcc/ipa-cp.c
@@ -514,7 +514,8 @@  print_all_lattices (FILE * f, bool dump_sources, bool dump_benefits)
    with NODE.  */
 
 static void
-determine_versionability (struct cgraph_node *node)
+determine_versionability (struct cgraph_node *node,
+			  struct ipa_node_params *info)
 {
   const char *reason = NULL;
 
@@ -546,7 +547,7 @@  determine_versionability (struct cgraph_node *node)
     fprintf (dump_file, "Function %s/%i is not versionable, reason: %s.\n",
 	     node->name (), node->order, reason);
 
-  node->local.versionable = (reason == NULL);
+  info->versionable = (reason == NULL);
 }
 
 /* Return true if it is at all technically possible to create clones of a
@@ -555,7 +556,7 @@  determine_versionability (struct cgraph_node *node)
 static bool
 ipcp_versionable_function_p (struct cgraph_node *node)
 {
-  return node->local.versionable;
+  return IPA_NODE_REF (node)->versionable;
 }
 
 /* Structure holding accumulated information about callers of a node.  */
@@ -2896,7 +2897,7 @@  ipcp_propagate_stage (struct ipa_topo_info *topo)
   {
     struct ipa_node_params *info = IPA_NODE_REF (node);
 
-    determine_versionability (node);
+    determine_versionability (node, info);
     if (node->has_gimple_body_p ())
       {
 	info->lattices = XCNEWVEC (struct ipcp_param_lattices,
@@ -4609,11 +4610,7 @@  ipcp_generate_summary (void)
   ipa_register_cgraph_hooks ();
 
   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
-      {
-	node->local.versionable
-	  = tree_versionable_function_p (node->decl);
-	ipa_analyze_node (node);
-      }
+    ipa_analyze_node (node);
 }
 
 /* Write ipcp summary for nodes in SET.  */
diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index 38e1ec0..35322cc 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -4112,6 +4112,10 @@  inline_generate_summary (void)
 {
   struct cgraph_node *node;
 
+  FOR_EACH_DEFINED_FUNCTION (node)
+    if (DECL_STRUCT_FUNCTION (node->decl))
+      node->local.versionable = tree_versionable_function_p (node->decl);
+
   /* When not optimizing, do not bother to analyze.  Inlining is still done
      because edge redirection needs to happen there.  */
   if (!optimize && !flag_generate_lto && !flag_generate_offload && !flag_wpa)
diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 8dd9479..19846a8 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -3507,6 +3507,7 @@  ipa_node_params_t::duplicate(cgraph_node *src, cgraph_node *dst,
 
   new_info->analysis_done = old_info->analysis_done;
   new_info->node_enqueued = old_info->node_enqueued;
+  new_info->versionable = old_info->versionable;
 
   old_av = ipa_get_agg_replacements_for_node (src);
   if (old_av)
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index b9868bb..35952dc 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -334,6 +334,8 @@  struct ipa_node_params
   unsigned node_within_scc : 1;
   /* Node is calling a private function called only once.  */
   unsigned node_calling_single_call : 1;
+  /* False when there is something makes versioning impossible.  */
+  unsigned versionable : 1;
 };
 
 /* Intermediate information that we get from alias analysis about a particular
-- 
2.6.0