Hi,

On Mon, Sep 21 2026, Josef Melcr wrote:
> This patch takes the current callback edge redirection logic and tucks
> it away into its separate function.  The logic will be reused in a later
> patch for the redirection of internal callback edges.  Without them, all
> this patch does is make the logic a little neater.
>
> gcc/ChangeLog:
>
>       * attr-callback.cc (callback_redirect_edge): Add implementation.
>       * attr-callback.h (callback_redirect_edge): New function,
>       redirects a callback edge.  Contains logic extracted from
>       redirect_call_stmt_to_callee.
>       * cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): Use
>       callback_redirect_edge.
>
> Signed-off-by: Josef Melcr <[email protected]>
> ---
>  gcc/attr-callback.cc | 13 +++++++++++++
>  gcc/attr-callback.h  |  4 ++++
>  gcc/cgraph.cc        |  6 +-----
>  3 files changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/gcc/attr-callback.cc b/gcc/attr-callback.cc
> index 376a17e82b4..9e6bf7884a8 100644
> --- a/gcc/attr-callback.cc
> +++ b/gcc/attr-callback.cc
> @@ -24,6 +24,7 @@
>  #include "backend.h"
>  #include "tree.h"
>  #include "gimple.h"
> +#include "fold-const.h"
>  #include "alloc-pool.h"
>  #include "cgraph.h"
>  #include "diagnostic.h"
> @@ -183,3 +184,15 @@ callback_num_args (tree attr)
>      ;
>    return res;
>  }
> +
> +/* Redirect call statement of E to the callee of E.  Used in
> +   cgraph_edge::redirect_call_stmt_to_callee.  */

I guess the comment should mention E must be a callback edge, even if it
is a bit superfluous in this file.

Otherwise OK.

Thanks,

Martin


> +void
> +callback_redirect_edge (cgraph_edge *e)
> +{
> +  callback_info *ci = callback_info_sum->get (e);
> +  tree previous_arg = gimple_call_arg (e->call_stmt, ci->fn_idx);
> +  location_t loc = EXPR_LOCATION (previous_arg);
> +  tree new_addr = build_fold_addr_expr_loc (loc, e->callee->decl);
> +  gimple_call_set_arg (e->call_stmt, ci->fn_idx, new_addr);
> +}
> diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
> index baefa8701b9..b8eab66d321 100644
> --- a/gcc/attr-callback.h
> +++ b/gcc/attr-callback.h
> @@ -76,4 +76,8 @@ bool callback_edge_useful_p (cgraph_edge *e);
>     takes.  */
>  size_t callback_num_args (tree attr);
>  
> +/* Redirect call statement of E to the callee of E.  Used in
> +   cgraph_edge::redirect_call_stmt_to_callee.  */
> +void callback_redirect_edge (cgraph_edge *e);
> +
>  #endif /* ATTR_CALLBACK_H  */
> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
> index e87b7998e00..ba596966aea 100644
> --- a/gcc/cgraph.cc
> +++ b/gcc/cgraph.cc
> @@ -1870,11 +1870,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge 
> *e,
>          signature, as the indices wouldn't be correct anymore.  These edges
>          will get cleaned up later, ignore their redirection for now.  */
>       return e->call_stmt;
> -      callback_info *ci = callback_info_sum->get (e);
> -      tree previous_arg = gimple_call_arg (e->call_stmt, ci->fn_idx);
> -      location_t loc = EXPR_LOCATION (previous_arg);
> -      tree new_addr = build_fold_addr_expr_loc (loc, e->callee->decl);
> -      gimple_call_set_arg (e->call_stmt, ci->fn_idx, new_addr);
> +      callback_redirect_edge (e);
>        return e->call_stmt;
>      }
>  
> -- 
> 2.55.0

Reply via email to