https://gcc.gnu.org/g:0b52da2198141ce07c075259d544de2f1c7928dc
commit 0b52da2198141ce07c075259d544de2f1c7928dc Author: Josef Melcr <melcr...@fit.cvut.cz> Date: Wed Nov 20 12:02:30 2024 +0100 omp-cp: Add callback redirection, not working yet gcc/ChangeLog: * cgraph.cc (cgraph_edge::get_callback_parent_edge): New function (cgraph_edge::redirect_call_stmt_to_callee): Add callback edge redirection * cgraph.h (cgraph_edge::get_callback_parent_edge): Declare * ipa-prop.cc (ipa_compute_jump_functions_for_bb): Comment out if statement Signed-off-by: Josef Melcr <melcr...@fit.cvut.cz> Diff: --- gcc/cgraph.cc | 34 +++++++++++++++++++++++++++++++++- gcc/cgraph.h | 3 +++ gcc/ipa-prop.cc | 6 +++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 78c56dd43ccd..0ce75f9b4674 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -1160,6 +1160,22 @@ cgraph_edge::make_callback (cgraph_node *n2) return e2; } +cgraph_edge * +cgraph_edge::get_callback_parent_edge () +{ + gcc_checking_assert (callback); + cgraph_edge *e; + fprintf (stderr, "get parent: %s -> %s\n", caller->name (), callee->name ()); + for (e = caller->callees; e; e = e->next_callee) + { + fprintf (stderr, "get parent for loop: %s -> %s\n", caller->name (), + callee->name ()); + if (e->has_callback && e->call_stmt == call_stmt) + return e; + } + gcc_unreachable (); +} + /* Speculative call consists of an indirect edge and one or more direct edge+ref pairs. @@ -1514,9 +1530,25 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e, } } - if (e->indirect_unknown_callee || decl == e->callee->decl || e->callback) + if (e->has_callback) + { + debug_gimple_stmt (e->call_stmt); + fprintf (stderr, "gimple pointer: %p\n", (void *) e->call_stmt); + } + + if (e->indirect_unknown_callee || decl == e->callee->decl) return e->call_stmt; + if (e->callback) + { + fprintf (stderr, "redirecting to %s\n", e->callee->name ()); + fprintf (stderr, "gimple pointer before: %p\n", (void *) e->call_stmt); + gimple_call_set_arg (e->call_stmt, 0, e->callee->decl); + debug_gimple_stmt (e->call_stmt); + fprintf (stderr, "gimple pointer after: %p\n", (void *) e->call_stmt); + return e->call_stmt; + } + if (decl && ipa_saved_clone_sources) { tree *p = ipa_saved_clone_sources->get (e->callee); diff --git a/gcc/cgraph.h b/gcc/cgraph.h index 5f1faa4c56ad..31205df2ffa8 100644 --- a/gcc/cgraph.h +++ b/gcc/cgraph.h @@ -1738,6 +1738,9 @@ public: /* TODO DOCS */ cgraph_edge *make_callback (cgraph_node *n2); + /* TODO DOCS */ + cgraph_edge *get_callback_parent_edge(); + /* Speculative call consists of an indirect edge and one or more direct edge+ref pairs. Speculative will expand to the following sequence: diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc index bc5b7933a75c..285cd734b3de 100644 --- a/gcc/ipa-prop.cc +++ b/gcc/ipa-prop.cc @@ -2544,9 +2544,9 @@ ipa_compute_jump_functions_for_bb (struct ipa_func_body_info *fbi, basic_block b callee = callee->ultimate_alias_target (); /* We do not need to bother analyzing calls to unknown functions unless they may become known during lto/whopr. */ - if (!callee->definition && !flag_lto - && !gimple_call_fnspec (cs->call_stmt).known_p ()) - continue; + // if (!callee->definition && !flag_lto + // && !gimple_call_fnspec (cs->call_stmt).known_p ()) + // continue; } ipa_compute_jump_functions_for_edge (fbi, cs); }