return edge in make_eh_edges

Message ID oredhrdowb.fsf@lxoliva.fsfla.org
State Accepted
Headers
Series return edge in make_eh_edges |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Alexandre Oliva Oct. 19, 2023, 7:58 a.m. UTC
  The need to initialize edge probabilities has made make_eh_edges
undesirably hard to use.  I suppose we don't want make_eh_edges to
initialize the probability of the newly-added edge itself, so that the
caller takes care of it, but identifying the added edge in need of
adjustments is inefficient and cumbersome.  Change make_eh_edges so
that it returns the added edge.

Regstrapped on x86_64-linux-gnu, and (along with various hardening
patches) on ppc64el-linux-gnu.  Also tested on multiple other targets,
on older versions of GCC.  The returned value is unused in code already
in the compiler.  This is a preparatory patch for uses to be introduced
along with stack scrubbing and control flow redundancy.  Ok to install?


for  gcc/ChangeLog

	* tree-eh.cc (make_eh_edges): Return the new edge.
	* tree-eh.h (make_eh_edges): Likewise.
---
 gcc/tree-eh.cc |    6 +++---
 gcc/tree-eh.h  |    2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
  

Comments

Richard Biener Oct. 19, 2023, 9:09 a.m. UTC | #1
On Thu, Oct 19, 2023 at 9:59 AM Alexandre Oliva <oliva@adacore.com> wrote:
>
>
> The need to initialize edge probabilities has made make_eh_edges
> undesirably hard to use.  I suppose we don't want make_eh_edges to
> initialize the probability of the newly-added edge itself, so that the
> caller takes care of it, but identifying the added edge in need of
> adjustments is inefficient and cumbersome.  Change make_eh_edges so
> that it returns the added edge.
>
> Regstrapped on x86_64-linux-gnu, and (along with various hardening
> patches) on ppc64el-linux-gnu.  Also tested on multiple other targets,
> on older versions of GCC.  The returned value is unused in code already
> in the compiler.  This is a preparatory patch for uses to be introduced
> along with stack scrubbing and control flow redundancy.  Ok to install?

OK.  Maybe time to do s/make_eh_edges/make_eh_edge/ though.

Richard.

>
> for  gcc/ChangeLog
>
>         * tree-eh.cc (make_eh_edges): Return the new edge.
>         * tree-eh.h (make_eh_edges): Likewise.
> ---
>  gcc/tree-eh.cc |    6 +++---
>  gcc/tree-eh.h  |    2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
> index e8ceff36cc6e7..1cb8e08652909 100644
> --- a/gcc/tree-eh.cc
> +++ b/gcc/tree-eh.cc
> @@ -2274,7 +2274,7 @@ make_eh_dispatch_edges (geh_dispatch *stmt)
>  /* Create the single EH edge from STMT to its nearest landing pad,
>     if there is such a landing pad within the current function.  */
>
> -void
> +edge
>  make_eh_edges (gimple *stmt)
>  {
>    basic_block src, dst;
> @@ -2283,14 +2283,14 @@ make_eh_edges (gimple *stmt)
>
>    lp_nr = lookup_stmt_eh_lp (stmt);
>    if (lp_nr <= 0)
> -    return;
> +    return NULL;
>
>    lp = get_eh_landing_pad_from_number (lp_nr);
>    gcc_assert (lp != NULL);
>
>    src = gimple_bb (stmt);
>    dst = label_to_block (cfun, lp->post_landing_pad);
> -  make_edge (src, dst, EDGE_EH);
> +  return make_edge (src, dst, EDGE_EH);
>  }
>
>  /* Do the work in redirecting EDGE_IN to NEW_BB within the EH region tree;
> diff --git a/gcc/tree-eh.h b/gcc/tree-eh.h
> index 771be50fe9a1d..1382568b7c919 100644
> --- a/gcc/tree-eh.h
> +++ b/gcc/tree-eh.h
> @@ -30,7 +30,7 @@ extern bool remove_stmt_from_eh_lp (gimple *);
>  extern int lookup_stmt_eh_lp_fn (struct function *, const gimple *);
>  extern int lookup_stmt_eh_lp (const gimple *);
>  extern bool make_eh_dispatch_edges (geh_dispatch *);
> -extern void make_eh_edges (gimple *);
> +extern edge make_eh_edges (gimple *);
>  extern edge redirect_eh_edge (edge, basic_block);
>  extern void redirect_eh_dispatch_edge (geh_dispatch *, edge, basic_block);
>  extern bool operation_could_trap_helper_p (enum tree_code, bool, bool, bool,
>
>
> --
> Alexandre Oliva, happy hacker            https://FSFLA.org/blogs/lxo/
>    Free Software Activist                   GNU Toolchain Engineer
> More tolerance and less prejudice are key for inclusion and diversity
> Excluding neuro-others for not behaving ""normal"" is *not* inclusive
  
Alexandre Oliva Oct. 20, 2023, 3:34 a.m. UTC | #2
On Oct 19, 2023, Richard Biener <richard.guenther@gmail.com> wrote:

> OK.  Maybe time to do s/make_eh_edges/make_eh_edge/ though.

Thanks, will do, ideally on top of the already-tested refreshed patches
that I'm going to post shortly.
  

Patch

diff --git a/gcc/tree-eh.cc b/gcc/tree-eh.cc
index e8ceff36cc6e7..1cb8e08652909 100644
--- a/gcc/tree-eh.cc
+++ b/gcc/tree-eh.cc
@@ -2274,7 +2274,7 @@  make_eh_dispatch_edges (geh_dispatch *stmt)
 /* Create the single EH edge from STMT to its nearest landing pad,
    if there is such a landing pad within the current function.  */
 
-void
+edge
 make_eh_edges (gimple *stmt)
 {
   basic_block src, dst;
@@ -2283,14 +2283,14 @@  make_eh_edges (gimple *stmt)
 
   lp_nr = lookup_stmt_eh_lp (stmt);
   if (lp_nr <= 0)
-    return;
+    return NULL;
 
   lp = get_eh_landing_pad_from_number (lp_nr);
   gcc_assert (lp != NULL);
 
   src = gimple_bb (stmt);
   dst = label_to_block (cfun, lp->post_landing_pad);
-  make_edge (src, dst, EDGE_EH);
+  return make_edge (src, dst, EDGE_EH);
 }
 
 /* Do the work in redirecting EDGE_IN to NEW_BB within the EH region tree;
diff --git a/gcc/tree-eh.h b/gcc/tree-eh.h
index 771be50fe9a1d..1382568b7c919 100644
--- a/gcc/tree-eh.h
+++ b/gcc/tree-eh.h
@@ -30,7 +30,7 @@  extern bool remove_stmt_from_eh_lp (gimple *);
 extern int lookup_stmt_eh_lp_fn (struct function *, const gimple *);
 extern int lookup_stmt_eh_lp (const gimple *);
 extern bool make_eh_dispatch_edges (geh_dispatch *);
-extern void make_eh_edges (gimple *);
+extern edge make_eh_edges (gimple *);
 extern edge redirect_eh_edge (edge, basic_block);
 extern void redirect_eh_dispatch_edge (geh_dispatch *, edge, basic_block);
 extern bool operation_could_trap_helper_p (enum tree_code, bool, bool, bool,