https://gcc.gnu.org/g:af46b2ce0f302fcfe7143562d751987cb793a2d9
commit r17-5624-gaf46b2ce0f302fcfe7143562d751987cb793a2d9 Author: Josef Melcr <[email protected]> Date: Tue Sep 15 11:47:42 2026 +0200 cgraph: Replace callback redirection logic with a function 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]> Diff: --- gcc/attr-callback.cc | 14 ++++++++++++++ gcc/attr-callback.h | 5 +++++ gcc/cgraph.cc | 6 +----- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gcc/attr-callback.cc b/gcc/attr-callback.cc index 376a17e82b40..6496844738f5 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,16 @@ 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. Edge E must be a callback + edge. */ +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 baefa8701b9e..b969b713a20d 100644 --- a/gcc/attr-callback.h +++ b/gcc/attr-callback.h @@ -76,4 +76,9 @@ 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. Edge E must be a callback + edge. */ +void callback_redirect_edge (cgraph_edge *e); + #endif /* ATTR_CALLBACK_H */ diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index e87b7998e006..ba596966aea3 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; }
