public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Set discriminators for call stmts on the same line within the same basic block
@ 2022-10-03  6:08 Eugene Rozenfeld
  2022-10-04 22:21 ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Eugene Rozenfeld @ 2022-10-03  6:08 UTC (permalink / raw)
  To: gcc-patches, Jason Merrill

This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
by Dehao Chen in vendors/google/heads/gcc-4_8.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
        * tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
        on the same line within the same basic block.
---
 gcc/tree-cfg.cc | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index ade66c54499..8e2a3a5f6c6 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -1203,8 +1203,39 @@ assign_discriminators (void)
     {
       edge e;
       edge_iterator ei;
+      gimple_stmt_iterator gsi;
       gimple *last = last_stmt (bb);
       location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
+      location_t curr_locus = UNKNOWN_LOCATION;
+      int curr_discr = 0;
+
+      /* Traverse the basic block, if two function calls within a basic block
+       are mapped to the same line, assign a new discriminator because a call
+       stmt could be a split point of a basic block.  */
+      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+       {
+         gimple *stmt = gsi_stmt (gsi);
+         expanded_location curr_locus_e;
+         if (curr_locus == UNKNOWN_LOCATION)
+           {
+             curr_locus = gimple_location (stmt);
+             curr_locus_e = expand_location (curr_locus);
+           }
+         else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt)))
+           {
+             curr_locus = gimple_location (stmt);
+             curr_locus_e = expand_location (curr_locus);
+             curr_discr = 0;
+           }
+         else if (curr_discr != 0)
+           {
+             gimple_set_location (stmt, location_with_discriminator (
+                 gimple_location (stmt), curr_discr));
+           }
+         /* Allocate a new discriminator for CALL stmt.  */
+         if (gimple_code (stmt) == GIMPLE_CALL)
+           curr_discr = next_discriminator_for_locus (curr_locus);
+       }

       if (locus == UNKNOWN_LOCATION)
        continue;
--
2.25.1

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

* Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block
  2022-10-03  6:08 [PATCH] Set discriminators for call stmts on the same line within the same basic block Eugene Rozenfeld
@ 2022-10-04 22:21 ` Jason Merrill
  2022-10-07  3:50   ` Eugene Rozenfeld
  0 siblings, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2022-10-04 22:21 UTC (permalink / raw)
  To: Eugene Rozenfeld, gcc-patches

On 10/3/22 02:08, Eugene Rozenfeld wrote:
> This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
> by Dehao Chen in vendors/google/heads/gcc-4_8.
> 
> Tested on x86_64-pc-linux-gnu.

Brief rationale for the change?

> gcc/ChangeLog:
>          * tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
>          on the same line within the same basic block.
> ---
>   gcc/tree-cfg.cc | 31 +++++++++++++++++++++++++++++++
>   1 file changed, 31 insertions(+)
> 
> diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
> index ade66c54499..8e2a3a5f6c6 100644
> --- a/gcc/tree-cfg.cc
> +++ b/gcc/tree-cfg.cc
> @@ -1203,8 +1203,39 @@ assign_discriminators (void)
>       {
>         edge e;
>         edge_iterator ei;
> +      gimple_stmt_iterator gsi;
>         gimple *last = last_stmt (bb);
>         location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
> +      location_t curr_locus = UNKNOWN_LOCATION;
> +      int curr_discr = 0;
> +
> +      /* Traverse the basic block, if two function calls within a basic block
> +       are mapped to the same line, assign a new discriminator because a call
> +       stmt could be a split point of a basic block.  */
> +      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> +       {
> +         gimple *stmt = gsi_stmt (gsi);
> +         expanded_location curr_locus_e;
> +         if (curr_locus == UNKNOWN_LOCATION)
> +           {
> +             curr_locus = gimple_location (stmt);
> +             curr_locus_e = expand_location (curr_locus);
> +           }
> +         else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt)))
> +           {
> +             curr_locus = gimple_location (stmt);
> +             curr_locus_e = expand_location (curr_locus);
> +             curr_discr = 0;
> +           }
> +         else if (curr_discr != 0)
> +           {
> +             gimple_set_location (stmt, location_with_discriminator (
> +                 gimple_location (stmt), curr_discr));

This indentation is wonky, with an open paren at the end of the line; 
I'd suggest reformatting to

>              location_t dloc = (location_with_discriminator >                                 (gimple_location (stmt), 
curr_discr));>              gimple_set_location (stmt, dloc);

Jason


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

* Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block
  2022-10-04 22:21 ` Jason Merrill
@ 2022-10-07  3:50   ` Eugene Rozenfeld
  2022-10-07  4:08     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Eugene Rozenfeld @ 2022-10-07  3:50 UTC (permalink / raw)
  To: Jason Merrill, gcc-patches

Thank you for the review Jason.

I fixed formatting and updated the commit description:
----------------------------

Call statements are possible split points of a basic block so they may end up
in different basic blocks by the time pass_ipa_auto_profile executes.

This change will also simplify call site lookups since now location with discriminator
will uniquely identify the call site (no callee function name is needed).

This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
by Dehao Chen in vendors/google/heads/gcc-4_8.

Tested on x86_64-pc-linux-gnu.

gcc/ChangeLog:
	* tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
	on the same line within the same basic block.
---
 gcc/tree-cfg.cc | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
index ade66c54499..f6a465f4c91 100644
--- a/gcc/tree-cfg.cc
+++ b/gcc/tree-cfg.cc
@@ -1203,8 +1203,40 @@ assign_discriminators (void)
     {
       edge e;
       edge_iterator ei;
+      gimple_stmt_iterator gsi;
       gimple *last = last_stmt (bb);
       location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
+      location_t curr_locus = UNKNOWN_LOCATION;
+      int curr_discr = 0;
+
+      /* Traverse the basic block, if two function calls within a basic block
+	are mapped to the same line, assign a new discriminator because a call
+	stmt could be a split point of a basic block.  */
+      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+	{
+	  gimple *stmt = gsi_stmt (gsi);
+	  expanded_location curr_locus_e;
+	  if (curr_locus == UNKNOWN_LOCATION)
+	    {
+	      curr_locus = gimple_location (stmt);
+	      curr_locus_e = expand_location (curr_locus);
+	    }
+	  else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt)))
+	    {
+	      curr_locus = gimple_location (stmt);
+	      curr_locus_e = expand_location (curr_locus);
+	      curr_discr = 0;
+	    }
+	  else if (curr_discr != 0)
+	    {
+	      location_t loc = gimple_location (stmt);
+	      location_t dloc = location_with_discriminator (loc, curr_discr);
+	      gimple_set_location (stmt, dloc);
+	    }
+	  /* Allocate a new discriminator for CALL stmt.  */
+	  if (gimple_code (stmt) == GIMPLE_CALL)
+	    curr_discr = next_discriminator_for_locus (curr_locus);
+	}
 
       if (locus == UNKNOWN_LOCATION)
 	continue;
-- 
2.25.1

-----Original Message-----
From: Jason Merrill <jason@redhat.com> 
Sent: Tuesday, October 04, 2022 3:21 PM
To: Eugene Rozenfeld <Eugene.Rozenfeld@microsoft.com>; gcc-patches@gcc.gnu.org
Subject: [EXTERNAL] Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block

On 10/3/22 02:08, Eugene Rozenfeld wrote:
> This change is based on commit 
> 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
> by Dehao Chen in vendors/google/heads/gcc-4_8.
> 
> Tested on x86_64-pc-linux-gnu.

Brief rationale for the change?

> gcc/ChangeLog:
>          * tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
>          on the same line within the same basic block.
> ---
>   gcc/tree-cfg.cc | 31 +++++++++++++++++++++++++++++++
>   1 file changed, 31 insertions(+)
> 
> diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc index 
> ade66c54499..8e2a3a5f6c6 100644
> --- a/gcc/tree-cfg.cc
> +++ b/gcc/tree-cfg.cc
> @@ -1203,8 +1203,39 @@ assign_discriminators (void)
>       {
>         edge e;
>         edge_iterator ei;
> +      gimple_stmt_iterator gsi;
>         gimple *last = last_stmt (bb);
>         location_t locus = last ? gimple_location (last) : 
> UNKNOWN_LOCATION;
> +      location_t curr_locus = UNKNOWN_LOCATION;
> +      int curr_discr = 0;
> +
> +      /* Traverse the basic block, if two function calls within a basic block
> +       are mapped to the same line, assign a new discriminator because a call
> +       stmt could be a split point of a basic block.  */
> +      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> +       {
> +         gimple *stmt = gsi_stmt (gsi);
> +         expanded_location curr_locus_e;
> +         if (curr_locus == UNKNOWN_LOCATION)
> +           {
> +             curr_locus = gimple_location (stmt);
> +             curr_locus_e = expand_location (curr_locus);
> +           }
> +         else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt)))
> +           {
> +             curr_locus = gimple_location (stmt);
> +             curr_locus_e = expand_location (curr_locus);
> +             curr_discr = 0;
> +           }
> +         else if (curr_discr != 0)
> +           {
> +             gimple_set_location (stmt, location_with_discriminator (
> +                 gimple_location (stmt), curr_discr));

This indentation is wonky, with an open paren at the end of the line; I'd suggest reformatting to

>              location_t dloc = (location_with_discriminator >                                 (gimple_location (stmt), 
curr_discr));>              gimple_set_location (stmt, dloc);

Jason


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

* Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block
  2022-10-07  3:50   ` Eugene Rozenfeld
@ 2022-10-07  4:08     ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2022-10-07  4:08 UTC (permalink / raw)
  To: Eugene Rozenfeld, gcc-patches

On 10/6/22 23:50, Eugene Rozenfeld wrote:
> Thank you for the review Jason.
> 
> I fixed formatting and updated the commit description:

OK.

> ----------------------------
> 
> Call statements are possible split points of a basic block so they may end up
> in different basic blocks by the time pass_ipa_auto_profile executes.
> 
> This change will also simplify call site lookups since now location with discriminator
> will uniquely identify the call site (no callee function name is needed).
> 
> This change is based on commit 1e6c4a7a8fb8e20545bb9f9032d3854f3f794c18
> by Dehao Chen in vendors/google/heads/gcc-4_8.
> 
> Tested on x86_64-pc-linux-gnu.
> 
> gcc/ChangeLog:
> 	* tree-cfg.cc (assign_discriminators): Set discriminators for call stmts
> 	on the same line within the same basic block.
> ---
>   gcc/tree-cfg.cc | 32 ++++++++++++++++++++++++++++++++
>   1 file changed, 32 insertions(+)
> 
> diff --git a/gcc/tree-cfg.cc b/gcc/tree-cfg.cc
> index ade66c54499..f6a465f4c91 100644
> --- a/gcc/tree-cfg.cc
> +++ b/gcc/tree-cfg.cc
> @@ -1203,8 +1203,40 @@ assign_discriminators (void)
>       {
>         edge e;
>         edge_iterator ei;
> +      gimple_stmt_iterator gsi;
>         gimple *last = last_stmt (bb);
>         location_t locus = last ? gimple_location (last) : UNKNOWN_LOCATION;
> +      location_t curr_locus = UNKNOWN_LOCATION;
> +      int curr_discr = 0;
> +
> +      /* Traverse the basic block, if two function calls within a basic block
> +	are mapped to the same line, assign a new discriminator because a call
> +	stmt could be a split point of a basic block.  */
> +      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
> +	{
> +	  gimple *stmt = gsi_stmt (gsi);
> +	  expanded_location curr_locus_e;
> +	  if (curr_locus == UNKNOWN_LOCATION)
> +	    {
> +	      curr_locus = gimple_location (stmt);
> +	      curr_locus_e = expand_location (curr_locus);
> +	    }
> +	  else if (!same_line_p (curr_locus, &curr_locus_e, gimple_location (stmt)))
> +	    {
> +	      curr_locus = gimple_location (stmt);
> +	      curr_locus_e = expand_location (curr_locus);
> +	      curr_discr = 0;
> +	    }
> +	  else if (curr_discr != 0)
> +	    {
> +	      location_t loc = gimple_location (stmt);
> +	      location_t dloc = location_with_discriminator (loc, curr_discr);
> +	      gimple_set_location (stmt, dloc);
> +	    }
> +	  /* Allocate a new discriminator for CALL stmt.  */
> +	  if (gimple_code (stmt) == GIMPLE_CALL)
> +	    curr_discr = next_discriminator_for_locus (curr_locus);
> +	}
>   
>         if (locus == UNKNOWN_LOCATION)
>   	continue;


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

* Re: [PATCH] Set discriminators for call stmts on the same line within the same basic block
@ 2022-10-11  0:54 David Edelsohn
  0 siblings, 0 replies; 5+ messages in thread
From: David Edelsohn @ 2022-10-11  0:54 UTC (permalink / raw)
  To: Eugene Rozenfeld; +Cc: Jason Merrill, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 655 bytes --]

This patch causes a bootstrap comparison failure on AIX.  It apparently
does not cause a failure on PPC64BE Linux with the same ABI, so I suspect
that the failure may be related to the way that function aliases are
implemented on AIX, which doesn't have ELF symbol alias semantics.

"This change will also simplify call site lookups since now location with
discriminator will uniquely identify the call site (no callee function name
is needed)."

I will open a PR with more information about the comparison difference now
that I have a work-around to bring AIX back to a bootstrappable state.  Any
thoughts about what could be going wrong?

Thanks, David

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

end of thread, other threads:[~2022-10-11  0:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-03  6:08 [PATCH] Set discriminators for call stmts on the same line within the same basic block Eugene Rozenfeld
2022-10-04 22:21 ` Jason Merrill
2022-10-07  3:50   ` Eugene Rozenfeld
2022-10-07  4:08     ` Jason Merrill
2022-10-11  0:54 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).