[gcc r15-4302] MAINTAINERS: Add myself to write after approval

2024-10-13 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:2ef62aa1a3fb7ece56b0f7a8ba79ef7eac0991ec

commit r15-4302-g2ef62aa1a3fb7ece56b0f7a8ba79ef7eac0991ec
Author: Josef Melcr 
Date:   Sun Oct 13 19:14:13 2024 +0200

MAINTAINERS: Add myself to write after approval

ChangeLog:

* MAINTAINERS: Add myself to write after approval

Signed-off-by: Josef Melcr 

Diff:
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4a53521d8eb2..f94aa9aeb791 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -657,6 +657,7 @@ Bryce McKinlay  bryce   

 Adam Megacz -   
 Bingfeng Meimeibf   
 Michael Meissnermeissner
+Josef Melcr -   
 Jason Merrill   jason   
 Jim Meyering-   
 Martin Michlmayrtbm 


[gcc] Created branch 'jmelcr/heads/omp-cp' in namespace 'refs/users'

2024-10-15 Thread Josef Melcr via Gcc-cvs
The branch 'jmelcr/heads/omp-cp' was created in namespace 'refs/users' pointing 
to:

 0fa5017df917... testsuite/i386: Require AVX2 effective target in pr107432-9


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: add callback attribute, wip callback edges

2024-10-18 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:723b98f9c1f1aea96d2eb74f06578565f6f405d1

commit 723b98f9c1f1aea96d2eb74f06578565f6f405d1
Author: Josef Melcr 
Date:   Fri Oct 18 14:40:46 2024 +0200

omp-cp: add callback attribute, wip callback edges

gcc/c-family/ChangeLog:

* c-attribs.cc: add callback attribute

gcc/ChangeLog:

* cgraph.cc (symbol_table::create_edge): allow multiple stmts to
  edges for callback edges
(cgraph_edge::make_callback): add make_callback method
* cgraph.h: add make_callback signature
* gimple.h (GCC_GIMPLE_H):
(gimple_omp_parallel_set_child_fn): add callback attribute when
setting new child fn
* ipa-inline.cc (can_inline_edge_p): disable inlining of
  callback edges
* ipa-prop.cc (ipa_analyze_node): add callback edge creation

yeah it's segfaulting atm

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/c-family/c-attribs.cc |  3 ++-
 gcc/cgraph.cc | 26 +-
 gcc/cgraph.h  |  7 +++
 gcc/gimple.h  | 12 +++-
 gcc/ipa-inline.cc |  6 ++
 gcc/ipa-prop.cc   | 24 
 6 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 4dd2eecbea54..63906bd01246 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -635,7 +635,8 @@ const struct attribute_spec c_common_gnu_attributes[] =
   { "flag_enum", 0, 0, false, true, false, false,
  handle_flag_enum_attribute, NULL },
   { "null_terminated_string_arg", 1, 1, false, true, true, false,
- handle_null_terminated_string_arg_attribute, NULL}
+ handle_null_terminated_string_arg_attribute, 
NULL},
+  { "callback", 0, 0, true, false, false, false, NULL, NULL}
 };
 
 const struct scoped_attribute_specs c_common_gnu_attribute_table =
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 39a3adbc7c35..58813e8cc2d0 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -885,7 +885,7 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
 construction of call stmt hashtable.  */
   cgraph_edge *e;
   gcc_checking_assert (!(e = caller->get_edge (call_stmt))
-  || e->speculative);
+  || e->speculative || e->has_callback);
 
   gcc_assert (is_gimple_call (call_stmt));
 }
@@ -911,6 +911,8 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
   edge->indirect_info = NULL;
   edge->indirect_inlining_edge = 0;
   edge->speculative = false;
+  edge->has_callback = false;
+  edge->callback = false;
   edge->indirect_unknown_callee = indir_unknown_callee;
   if (call_stmt && caller->call_site_hash)
 cgraph_add_edge_to_call_site_hash (edge);
@@ -1136,6 +1138,28 @@ cgraph_edge::make_speculative (cgraph_node *n2, 
profile_count direct_count,
   return e2;
 }
 
+cgraph_edge *
+cgraph_edge::make_callback (cgraph_node *n2)
+{
+  cgraph_node *n = caller;
+  cgraph_edge *e2;
+
+  if (dump_file)
+fprintf (dump_file, "Indirect call -> callback call %s => %s\n",
+n->dump_name (), n2->dump_name ());
+  has_callback = true;
+  e2 = n->create_edge (n2, call_stmt, count);
+  initialize_inline_failed (e2);
+  e2->callback = true;
+  if (TREE_NOTHROW (n2->decl))
+e2->can_throw_external = false;
+  else
+e2->can_throw_external = can_throw_external;
+  e2->lto_stmt_uid = lto_stmt_uid;
+  n2->mark_address_taken ();
+  return e2;
+}
+
 /* Speculative call consists of an indirect edge and one or more
direct edge+ref pairs.
 
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index a8c3224802c1..bf0a22bcf365 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1735,6 +1735,9 @@ public:
   cgraph_edge *make_speculative (cgraph_node *n2, profile_count direct_count,
 unsigned int speculative_id = 0);
 
+  /* TODO DOCS */
+  cgraph_edge *make_callback (cgraph_node *n2);
+
   /* Speculative call consists of an indirect edge and one or more
  direct edge+ref pairs.  Speculative will expand to the following sequence:
 
@@ -1951,6 +1954,10 @@ public:
  Optimizers may later redirect direct call to clone, so 1) and 3)
  do not need to necessarily agree with destination.  */
   unsigned int speculative : 1;
+  /* TODO DOCS */
+  unsigned int callback : 1;
+  /* TODO DOCS */
+  unsigned int has_callback : 1;
   /* Set to true when caller is a constructor or destructor of polymorphic
  type.  */
   unsigned in_polymorphic_cdtor : 1;
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 4a6e0e97d1e7..56eb49802e6b 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -22,8 +22,11 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_GIMPLE_H
 #define GCC_GIMPLE_H
 
+#include "stringpool.h"
+#include "attribs.

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: add callback flag to some checks

2024-10-21 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:cf15a12be9efe68841746d0ab189e3846499498f

commit cf15a12be9efe68841746d0ab189e3846499498f
Author: Josef Melcr 
Date:   Mon Oct 21 18:04:21 2024 +0200

omp-cp: add callback flag to some checks

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): return
  if callback flag is set
(cgraph_node::verify_node): allow some weirdness if callback is
set

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index c62f5de807da..96d95a87c769 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1514,9 +1514,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
}
 }
 
-
-  if (e->indirect_unknown_callee
-  || decl == e->callee->decl)
+  if (e->indirect_unknown_callee || decl == e->callee->decl || e->callback)
 return e->call_stmt;
 
   if (decl && ipa_saved_clone_sources)
@@ -3682,6 +3680,7 @@ cgraph_node::verify_node (void)
   if (gimple_has_body_p (e->caller->decl)
  && !e->caller->inlined_to
  && !e->speculative
+ && !e->callback
  /* Optimized out calls are redirected to __builtin_unreachable.  */
  && (e->count.nonzero_p ()
  || ! e->callee->decl
@@ -3929,7 +3928,7 @@ cgraph_node::verify_node (void)
 
   for (e = callees; e; e = e->next_callee)
{
- if (!e->aux && !e->speculative)
+ if (!e->aux && !e->speculative && !e->callback)
{
  error ("edge %s->%s has no corresponding call_stmt",
 identifier_to_locale (e->caller->name ()),


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: resolve segfault through monkey stick debugging

2024-10-21 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:397b6d3ea75e4f16c7da848c55f7823480c662c8

commit 397b6d3ea75e4f16c7da848c55f7823480c662c8
Author: Josef Melcr 
Date:   Fri Oct 18 23:41:37 2024 +0200

omp-cp: resolve segfault through monkey stick debugging

gcc/ChangeLog:

* cgraph.h: modify functions regarding speculative call edges
* ipa-fnsummary.cc (analyze_function_body): integrate callback
  edges
(compute_fn_summary): integrate callback edges in similar
fashion to speculative edges

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.h | 24 +---
 gcc/ipa-fnsummary.cc |  9 -
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index bf0a22bcf365..5f1faa4c56ad 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1769,6 +1769,10 @@ public:
  target2.  */
   cgraph_edge *next_speculative_call_target ()
   {
+if (callback)
+  {
+   return NULL;
+  }
 cgraph_edge *e = this;
 gcc_checking_assert (speculative && callee);
 
@@ -1783,15 +1787,29 @@ public:
  indirect call edge in the speculative call sequence.  */
   cgraph_edge *speculative_call_indirect_edge ()
   {
-gcc_checking_assert (speculative);
+gcc_checking_assert (speculative || callback);
 if (!callee)
   return this;
-for (cgraph_edge *e2 = caller->indirect_calls;
-true; e2 = e2->next_callee)
+
+cgraph_edge * e2 = NULL;
+for (e2 = caller->indirect_calls;
+e2; e2 = e2->next_callee)
   if (e2->speculative
  && call_stmt == e2->call_stmt
  && lto_stmt_uid == e2->lto_stmt_uid)
return e2;
+
+if (!e2 && callback)
+  {
+   for (e2 = caller->callees; e2; e2 = e2->next_callee)
+ {
+   if (e2->has_callback && call_stmt == e2->call_stmt)
+ {
+   return e2;
+ }
+ }
+  }
+  gcc_unreachable();
   }
 
   /* When called on any edge in speculative call and when given any target
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index b38247834065..7858684aaa25 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -2900,7 +2900,7 @@ analyze_function_body (struct cgraph_node *node, bool 
early)
  es->call_stmt_time = this_time;
  es->loop_depth = bb_loop_depth (bb);
  edge_set_predicate (edge, &bb_predicate);
- if (edge->speculative)
+ if (edge->speculative || edge->callback)
{
  cgraph_edge *indirect
= edge->speculative_call_indirect_edge ();
@@ -3309,6 +3309,13 @@ compute_fn_summary (struct cgraph_node *node, bool early)
   for (e = node->indirect_calls; e; e = e->next_callee)
if (e->speculative)
 break;
+
+  if (!e)
+   {
+ for (e = node->callees; e; e = e->next_callee)
+   if (e->callback)
+ break;
+   }
   gcc_assert (e || size_info->size == size_info->self_size);
 }
 }


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: fix flags when cloning edges, add lto input and output

2024-10-21 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:f2c71e4d68dce5a51aedd0f71a18eec4ad76ff17

commit f2c71e4d68dce5a51aedd0f71a18eec4ad76ff17
Author: Josef Melcr 
Date:   Mon Oct 21 16:31:32 2024 +0200

omp-cp: fix flags when cloning edges, add lto input and output

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::dump_edge_flags): add callback and
  has_callback printing
* cgraphclones.cc (cgraph_edge::clone): copy over callback and
  has_callback flags
* ipa-inline.cc (can_inline_edge_p): move callback condition to
  the beginning
* lto-cgraph.cc (lto_output_edge): add outputting for callback flags
(input_edge): add inputting of callback flags

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc   |  4 
 gcc/cgraphclones.cc |  2 ++
 gcc/ipa-inline.cc   | 10 +-
 gcc/lto-cgraph.cc   |  4 
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 58813e8cc2d0..c62f5de807da 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -2113,6 +2113,10 @@ cgraph_edge::dump_edge_flags (FILE *f)
 {
   if (speculative)
 fprintf (f, "(speculative) ");
+  if (callback)
+fprintf (f, "(callback) ");
+  if (has_callback)
+fprintf (f, "(has_callback) ");
   if (!inline_failed)
 fprintf (f, "(inlined) ");
   if (call_stmt_cannot_inline_p)
diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc
index 4fff6873a369..d52b72364d4d 100644
--- a/gcc/cgraphclones.cc
+++ b/gcc/cgraphclones.cc
@@ -144,6 +144,8 @@ cgraph_edge::clone (cgraph_node *n, gcall *call_stmt, 
unsigned stmt_uid,
   new_edge->can_throw_external = can_throw_external;
   new_edge->call_stmt_cannot_inline_p = call_stmt_cannot_inline_p;
   new_edge->speculative = speculative;
+  new_edge->callback = callback;
+  new_edge->has_callback = has_callback;
   new_edge->in_polymorphic_cdtor = in_polymorphic_cdtor;
 
   /* Update IPA profile.  Local profiles need no updating in original.  */
diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index 0d77b89fa301..dacf1fd2691b 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -371,6 +371,11 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
 {
   gcc_checking_assert (e->inline_failed);
 
+  if(e->callback) {
+printf("skipping inline - callback\n");
+return false;
+  }
+
   if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
 {
   if (report)
@@ -453,11 +458,6 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
   if (!inlinable && report)
 report_inline_failed_reason (e);
 
-  if(e->callback) {
-printf("skipping inline - tried to inline: %d\n", inlinable);
-inlinable = false;
-  }
-
   return inlinable;
 }
 
diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index 1d4311a8832b..b7a7def31b79 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -272,6 +272,8 @@ lto_output_edge (struct lto_simple_output_block *ob, struct 
cgraph_edge *edge,
   bp_pack_value (&bp, edge->speculative_id, 16);
   bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
   bp_pack_value (&bp, edge->speculative, 1);
+  bp_pack_value (&bp, edge->callback, 1);
+  bp_pack_value (&bp, edge->has_callback, 1);
   bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
   gcc_assert (!edge->call_stmt_cannot_inline_p
  || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
@@ -1524,6 +1526,8 @@ input_edge (class lto_input_block *ib, vec 
nodes,
 
   edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
   edge->speculative = bp_unpack_value (&bp, 1);
+  edge->callback = bp_unpack_value(&bp, 1);
+  edge->has_callback = bp_unpack_value(&bp, 1);
   edge->lto_stmt_uid = stmt_id;
   edge->speculative_id = speculative_id;
   edge->inline_failed = inline_failed;


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: add analysis done check when recursing in ipa_analyze_node

2024-10-22 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:96b5b1e30b6520d94702c1d2f18d18f2a1a05ad6

commit 96b5b1e30b6520d94702c1d2f18d18f2a1a05ad6
Author: Josef Melcr 
Date:   Tue Oct 22 19:24:01 2024 +0200

omp-cp: add analysis done check when recursing in ipa_analyze_node

gcc/ChangeLog:

* ipa-prop.cc (ipa_analyze_node): add analysis done check when 
recursing

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/ipa-prop.cc | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 2089bb64cf0e..2cc72755eb56 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -3204,10 +3204,16 @@ ipa_analyze_node (struct cgraph_node *node)
  cgraph_node * reffering_node = dyn_cast(ref->referring);
  gcc_checking_assert(call_stmt);
  gcc_checking_assert(reffering_node);
-cgraph_edge * e = reffering_node->get_edge(ref->stmt);
-e->make_callback(node);
-ipa_analyze_node(e->caller);
-   }
+ cgraph_edge *e = reffering_node->get_edge (ref->stmt);
+ e->make_callback (node);
+ ipa_node_params *caller_info
+   = ipa_node_params_sum->get_create (e->caller);
+ if (caller_info->analysis_done)
+   {
+ caller_info->analysis_done = 0;
+ ipa_analyze_node (e->caller);
+   }
+ }
}
 }


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: change callback creation, add callback args to callsummary, integrate into ipa_compute_jump_

2024-10-28 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:54d33c2cd5d8ba581fdb5dfd45d0fbc506005242

commit 54d33c2cd5d8ba581fdb5dfd45d0fbc506005242
Author: Josef Melcr 
Date:   Mon Oct 28 22:35:16 2024 +0100

omp-cp: change callback creation, add callback args to callsummary, 
integrate into ipa_compute_jump_functions_for_edge

gcc/ChangeLog:

* ipa-inline.cc (can_inline_edge_p): replace printf with fprintf
* ipa-prop.cc (calc_callback_args_idx): new function
(ipa_compute_jump_functions_for_edge): integrate callback_args
info
(ipa_analyze_node): remove callback edge creation
* ipa-prop.h (struct cb_arg_info): new struct
(class ipa_edge_args): add vector of cb_arg_info

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/ipa-inline.cc |  2 +-
 gcc/ipa-prop.cc   | 90 +++
 gcc/ipa-prop.h| 11 ++-
 3 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index dacf1fd2691b..fb16290f2e33 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -372,7 +372,7 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
   gcc_checking_assert (e->inline_failed);
 
   if(e->callback) {
-printf("skipping inline - callback\n");
+fprintf(stderr, "skipping inline - callback\n");
 return false;
   }
 
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 2cc72755eb56..1d131f338004 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2311,6 +2311,17 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr)
information in the jump_functions array in the ipa_edge_args corresponding
to this callsite.  */
 
+static void calc_callback_args_idx(cgraph_edge * e) {
+  gcc_checking_assert(e->callback);
+  ipa_edge_args *args = ipa_edge_args_sum->get_create (e);
+  int argn = 1;
+  vec_safe_grow_cleared (args->callback_args, argn, true);
+  (*args->callback_args)[0] = {1, true};
+  for (int i = 1; i < argn; i++) {
+(*args->callback_args)[i] = {i, false};
+  }
+}
+
 static void
 ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 struct cgraph_edge *cs)
@@ -2319,6 +2330,9 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   ipa_edge_args *args = ipa_edge_args_sum->get_create (cs);
   gcall *call = cs->call_stmt;
   int n, arg_num = gimple_call_num_args (call);
+  if (cs->callback) {
+arg_num = args->callback_args->length();
+  }
   bool useful_context = false;
 
   if (arg_num == 0 || args->jump_functions)
@@ -2332,10 +2346,21 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   if (ipa_func_spec_opts_forbid_analysis_p (cs->caller))
 return;
 
-  for (n = 0; n < arg_num; n++)
+  int n_ = 0;
+  bool recurse = false;
+  cgraph_edge * callback_edge = NULL;
+  for (n = 0; n < arg_num && n_ < arg_num; n_++, n++)
 {
+  if (cs->callback)
+   {
+ n_ = (*args->callback_args)[n].idx;
+   }
+  else
+   {
+ n_ = n;
+   }
   struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, n);
-  tree arg = gimple_call_arg (call, n);
+  tree arg = gimple_call_arg (call, n_);
   tree param_type = ipa_get_callee_param_type (cs, n);
   if (flag_devirtualize && POINTER_TYPE_P (TREE_TYPE (arg)))
{
@@ -2412,10 +2437,24 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
}
 
   if (is_gimple_ip_invariant (arg)
- || (VAR_P (arg)
- && is_global_var (arg)
- && TREE_READONLY (arg)))
-   ipa_set_jf_constant (jfunc, arg, cs);
+ || (VAR_P (arg) && is_global_var (arg) && TREE_READONLY (arg)))
+   {
+ ipa_set_jf_constant (jfunc, arg, cs);
+ if (TREE_CODE (arg) == ADDR_EXPR)
+   {
+ tree pointee = TREE_OPERAND (arg, 0);
+ if (TREE_CODE (pointee) == FUNCTION_DECL
+ && lookup_attribute ("callback", DECL_ATTRIBUTES (pointee))
+ && !cs->callback)
+   {
+ cgraph_node *kernel_node = cgraph_node::get_create (pointee);
+ gcc_checking_assert (!recurse && !callback_edge);
+ callback_edge = cs->make_callback (kernel_node);
+ calc_callback_args_idx (callback_edge);
+ recurse = true;
+   }
+   }
+   }
   else if (!is_gimple_reg_type (TREE_TYPE (arg))
   && TREE_CODE (arg) == PARM_DECL)
{
@@ -2456,6 +2495,14 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
}
}
 
+  if (cs->callback && (*args->callback_args)[n].is_data_arg)
+   {
+ ipa_set_jf_simple_pass_through (jfunc, 0, true);
+   }
+  if (cs->has_callback && n == 1)
+   {
+ ipa_set_jf_simple_pass_through (jfunc, 1, true);
+   }
   /* If ARG is pointer, we cannot use its type to dete

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Add jump function copying, omp constants now appear in lattices

2024-11-04 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:151e86109841b2aa7464f4132d2fda9d037190e2

commit 151e86109841b2aa7464f4132d2fda9d037190e2
Author: Josef Melcr 
Date:   Mon Nov 4 22:35:05 2024 +0100

omp-cp: Add jump function copying, omp constants now appear in lattices

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::maybe_hot_p): Add temporary hardcode
  for callback edges
(cgraph_node::verify_node): Fix some failing cases when not
using lto
* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Remove
  recursion, add jump function copying
(ipa_copy_ith_jump_func): New function
* ipa-prop.h (ipa_copy_ith_jump_func): New function declaration

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc   |   5 +-
 gcc/ipa-prop.cc | 158 ++--
 gcc/ipa-prop.h  |   4 ++
 3 files changed, 137 insertions(+), 30 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 96d95a87c769..78c56dd43ccd 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -3013,6 +3013,7 @@ cgraph_edge::cannot_lead_to_return_p (void)
 bool
 cgraph_edge::maybe_hot_p (void)
 {
+  if (callback) return true;
   if (!maybe_hot_count_p (NULL, count.ipa ()))
 return false;
   if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
@@ -3886,7 +3887,7 @@ cgraph_node::verify_node (void)
}
  if (!e->indirect_unknown_callee)
{
- if (e->verify_corresponds_to_fndecl (decl))
+ if (!e->callback && 
e->verify_corresponds_to_fndecl (decl))
{
  error ("edge points to wrong declaration:");
  debug_tree (e->callee->decl);
@@ -3928,7 +3929,7 @@ cgraph_node::verify_node (void)
 
   for (e = callees; e; e = e->next_callee)
{
- if (!e->aux && !e->speculative && !e->callback)
+ if (!e->aux && !e->speculative && !e->callback && !e->has_callback)
{
  error ("edge %s->%s has no corresponding call_stmt",
 identifier_to_locale (e->caller->name ()),
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 1d131f338004..bc5b7933a75c 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2330,9 +2330,6 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   ipa_edge_args *args = ipa_edge_args_sum->get_create (cs);
   gcall *call = cs->call_stmt;
   int n, arg_num = gimple_call_num_args (call);
-  if (cs->callback) {
-arg_num = args->callback_args->length();
-  }
   bool useful_context = false;
 
   if (arg_num == 0 || args->jump_functions)
@@ -2346,21 +2343,11 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   if (ipa_func_spec_opts_forbid_analysis_p (cs->caller))
 return;
 
-  int n_ = 0;
-  bool recurse = false;
   cgraph_edge * callback_edge = NULL;
-  for (n = 0; n < arg_num && n_ < arg_num; n_++, n++)
+  for (n = 0; n < arg_num; n++)
 {
-  if (cs->callback)
-   {
- n_ = (*args->callback_args)[n].idx;
-   }
-  else
-   {
- n_ = n;
-   }
   struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, n);
-  tree arg = gimple_call_arg (call, n_);
+  tree arg = gimple_call_arg (call, n);
   tree param_type = ipa_get_callee_param_type (cs, n);
   if (flag_devirtualize && POINTER_TYPE_P (TREE_TYPE (arg)))
{
@@ -2448,10 +2435,9 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
  && !cs->callback)
{
  cgraph_node *kernel_node = cgraph_node::get_create (pointee);
- gcc_checking_assert (!recurse && !callback_edge);
+ gcc_checking_assert (!callback_edge);
  callback_edge = cs->make_callback (kernel_node);
  calc_callback_args_idx (callback_edge);
- recurse = true;
}
}
}
@@ -2495,14 +2481,6 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
}
}
 
-  if (cs->callback && (*args->callback_args)[n].is_data_arg)
-   {
- ipa_set_jf_simple_pass_through (jfunc, 0, true);
-   }
-  if (cs->has_callback && n == 1)
-   {
- ipa_set_jf_simple_pass_through (jfunc, 1, true);
-   }
   /* If ARG is pointer, we cannot use its type to determine the type of 
aggregate
 passed (because type conversions are ignored in gimple).  Usually we 
can
 safely get type from function declaration, but in case of K&R 
prototypes or
@@ -2521,9 +2499,28 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
determine_known_aggregate_parts (fbi, call, arg, param_type, jfunc);
 }
 
-  if (recurse) {
-ipa_compute_jump_functions_for_edge (fbi, callb

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Add callback redirection, not working yet

2024-11-20 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:0b52da2198141ce07c075259d544de2f1c7928dc

commit 0b52da2198141ce07c075259d544de2f1c7928dc
Author: Josef Melcr 
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 

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);
 }


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Add call stmt copying to callback edges

2024-11-21 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:4a81b5e11e31e923aeca5eaaa7ab2e458382ef16

commit 4a81b5e11e31e923aeca5eaaa7ab2e458382ef16
Author: Josef Melcr 
Date:   Wed Nov 20 17:45:00 2024 +0100

omp-cp: Add call stmt copying to callback edges

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::set_call_stmt): Integrate callback
edges
(cgraph_edge::redirect_call_stmt_to_callee): Add addr expr
creation

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 0ce75f9b4674..8c6e38fedd60 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -804,7 +804,8 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
 
   /* Speculative edges has three component, update all of them
  when asked to.  */
-  if (update_speculative && e->speculative
+  if (update_speculative
+  && e->speculative
   /* If we are about to resolve the speculation by calling make_direct
 below, do not bother going over all the speculative edges now.  */
   && !new_direct_callee)
@@ -837,8 +838,30 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall 
*new_stmt,
   return e_indirect ? indirect : direct;
 }
 
-  if (new_direct_callee)
-e = make_direct (e, new_direct_callee);
+  if (update_speculative && (e->callback || e->has_callback)
+  /* If we are about to resolve the speculation by calling make_direct
+below, do not bother going over all the speculative edges now.  */
+  )
+{
+  fprintf (stderr, "set_call_stmt callback\n");
+  cgraph_edge *direct, *next;
+
+  direct = e;
+
+  gcall *old_stmt = direct->call_stmt;
+  for (cgraph_edge *d = direct; d; d = next)
+   {
+ next = d->next_callee;
+ for (; next; next = next->next_callee)
+   {
+ if ((next->callback || next->has_callback)
+ && old_stmt == next->call_stmt)
+   break;
+   }
+ cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
+ gcc_assert (d2 == d);
+   }
+}
 
   /* Only direct speculative edges go to call_site_hash.  */
   if (e->caller->call_site_hash
@@ -1543,7 +1566,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
 {
   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);
+  gimple_call_set_arg (e->call_stmt, 0, build_addr(e->callee->decl));
   debug_gimple_stmt (e->call_stmt);
   fprintf (stderr, "gimple pointer after: %p\n", (void *) e->call_stmt);
   return e->call_stmt;


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Resolve merge conflict, keep both copying functions

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:5c79cf980c5cd4bc4d3fdd2af92b486e6fba8c8a

commit 5c79cf980c5cd4bc4d3fdd2af92b486e6fba8c8a
Author: Josef Melcr 
Date:   Mon Nov 4 22:35:05 2024 +0100

omp-cp: Resolve merge conflict, keep both copying functions

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::maybe_hot_p): Add temporary hardcode
for callback edges
(cgraph_node::verify_node): Fix some failing cases when not
using lto
* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Remove
recursion, add jump function copying
(ipa_copy_ith_jump_func): New function
* ipa-prop.h (ipa_copy_ith_jump_func): New function declaration

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc   |   5 +-
 gcc/ipa-prop.cc | 161 +---
 gcc/ipa-prop.h  |   4 ++
 3 files changed, 138 insertions(+), 32 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 0465538cab9f..2fb6950ee4a7 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -3014,6 +3014,7 @@ cgraph_edge::cannot_lead_to_return_p (void)
 bool
 cgraph_edge::maybe_hot_p (void)
 {
+  if (callback) return true;
   if (!maybe_hot_count_p (NULL, count.ipa ()))
 return false;
   if (caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
@@ -3887,7 +3888,7 @@ cgraph_node::verify_node (void)
}
  if (!e->indirect_unknown_callee)
{
- if (e->verify_corresponds_to_fndecl (decl))
+ if (!e->callback && 
e->verify_corresponds_to_fndecl (decl))
{
  error ("edge points to wrong declaration:");
  debug_tree (e->callee->decl);
@@ -3929,7 +3930,7 @@ cgraph_node::verify_node (void)
 
   for (e = callees; e; e = e->next_callee)
{
- if (!e->aux && !e->speculative && !e->callback)
+ if (!e->aux && !e->speculative && !e->callback && !e->has_callback)
{
  error ("edge %s->%s has no corresponding call_stmt",
 identifier_to_locale (e->caller->name ()),
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 8d33780b6d35..70609f0d7b19 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2337,9 +2337,6 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   ipa_edge_args *args = ipa_edge_args_sum->get_create (cs);
   gcall *call = cs->call_stmt;
   int n, arg_num = gimple_call_num_args (call);
-  if (cs->callback) {
-arg_num = args->callback_args->length();
-  }
   bool useful_context = false;
 
   if (arg_num == 0 || args->jump_functions)
@@ -2353,21 +2350,11 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   if (ipa_func_spec_opts_forbid_analysis_p (cs->caller))
 return;
 
-  int n_ = 0;
-  bool recurse = false;
   cgraph_edge * callback_edge = NULL;
-  for (n = 0; n < arg_num && n_ < arg_num; n_++, n++)
+  for (n = 0; n < arg_num; n++)
 {
-  if (cs->callback)
-   {
- n_ = (*args->callback_args)[n].idx;
-   }
-  else
-   {
- n_ = n;
-   }
   struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, n);
-  tree arg = gimple_call_arg (call, n_);
+  tree arg = gimple_call_arg (call, n);
   tree param_type = ipa_get_callee_param_type (cs, n);
   if (flag_devirtualize && POINTER_TYPE_P (TREE_TYPE (arg)))
{
@@ -2455,10 +2442,9 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
  && !cs->callback)
{
  cgraph_node *kernel_node = cgraph_node::get_create (pointee);
- gcc_checking_assert (!recurse && !callback_edge);
+ gcc_checking_assert (!callback_edge);
  callback_edge = cs->make_callback (kernel_node);
  calc_callback_args_idx (callback_edge);
- recurse = true;
}
}
}
@@ -2502,14 +2488,6 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
}
}
 
-  if (cs->callback && (*args->callback_args)[n].is_data_arg)
-   {
- ipa_set_jf_simple_pass_through (jfunc, 0, true);
-   }
-  if (cs->has_callback && n == 1)
-   {
- ipa_set_jf_simple_pass_through (jfunc, 1, true);
-   }
   /* If ARG is pointer, we cannot use its type to determine the type of 
aggregate
 passed (because type conversions are ignored in gimple).  Usually we 
can
 safely get type from function declaration, but in case of K&R 
prototypes or
@@ -2528,9 +2506,28 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
determine_known_aggregate_parts (fbi, call, arg, param_type, jfunc);
 }
 
-  if (recurse) {
-ipa_compute_jump_functions_for_edge (fbi, callback_edge);
-  }

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: add callback attribute, wip callback edges

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:4af59432346b30541ac3142b6df968e34b8f2a5b

commit 4af59432346b30541ac3142b6df968e34b8f2a5b
Author: Josef Melcr 
Date:   Fri Oct 18 14:40:46 2024 +0200

omp-cp: add callback attribute, wip callback edges

gcc/c-family/ChangeLog:

* c-attribs.cc: add callback attribute

gcc/ChangeLog:

* cgraph.cc (symbol_table::create_edge): allow multiple stmts to
  edges for callback edges
(cgraph_edge::make_callback): add make_callback method
* cgraph.h: add make_callback signature
* gimple.h (GCC_GIMPLE_H):
(gimple_omp_parallel_set_child_fn): add callback attribute when
setting new child fn
* ipa-inline.cc (can_inline_edge_p): disable inlining of
  callback edges
* ipa-prop.cc (ipa_analyze_node): add callback edge creation

yeah it's segfaulting atm

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/c-family/c-attribs.cc |  3 ++-
 gcc/cgraph.cc | 26 +-
 gcc/cgraph.h  |  7 +++
 gcc/gimple.h  | 12 +++-
 gcc/ipa-inline.cc |  6 ++
 gcc/ipa-prop.cc   | 24 
 6 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 5b64805f97de..c342e7a1e55f 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -642,7 +642,8 @@ const struct attribute_spec c_common_gnu_attributes[] =
   { "flag_enum", 0, 0, false, true, false, false,
  handle_flag_enum_attribute, NULL },
   { "null_terminated_string_arg", 1, 1, false, true, true, false,
- handle_null_terminated_string_arg_attribute, NULL}
+ handle_null_terminated_string_arg_attribute, 
NULL},
+  { "callback", 0, 0, true, false, false, false, NULL, NULL}
 };
 
 const struct scoped_attribute_specs c_common_gnu_attribute_table =
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 3332ea41ce2d..9310f1b43c20 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -885,7 +885,7 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
 construction of call stmt hashtable.  */
   cgraph_edge *e;
   gcc_checking_assert (!(e = caller->get_edge (call_stmt))
-  || e->speculative);
+  || e->speculative || e->has_callback);
 
   gcc_assert (is_gimple_call (call_stmt));
 }
@@ -912,6 +912,8 @@ symbol_table::create_edge (cgraph_node *caller, cgraph_node 
*callee,
   edge->indirect_info = NULL;
   edge->indirect_inlining_edge = 0;
   edge->speculative = false;
+  edge->has_callback = false;
+  edge->callback = false;
   edge->indirect_unknown_callee = indir_unknown_callee;
   if (call_stmt && caller->call_site_hash)
 cgraph_add_edge_to_call_site_hash (edge);
@@ -1137,6 +1139,28 @@ cgraph_edge::make_speculative (cgraph_node *n2, 
profile_count direct_count,
   return e2;
 }
 
+cgraph_edge *
+cgraph_edge::make_callback (cgraph_node *n2)
+{
+  cgraph_node *n = caller;
+  cgraph_edge *e2;
+
+  if (dump_file)
+fprintf (dump_file, "Indirect call -> callback call %s => %s\n",
+n->dump_name (), n2->dump_name ());
+  has_callback = true;
+  e2 = n->create_edge (n2, call_stmt, count);
+  initialize_inline_failed (e2);
+  e2->callback = true;
+  if (TREE_NOTHROW (n2->decl))
+e2->can_throw_external = false;
+  else
+e2->can_throw_external = can_throw_external;
+  e2->lto_stmt_uid = lto_stmt_uid;
+  n2->mark_address_taken ();
+  return e2;
+}
+
 /* Speculative call consists of an indirect edge and one or more
direct edge+ref pairs.
 
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 50bae96de4cf..4d937b1cde24 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1735,6 +1735,9 @@ public:
   cgraph_edge *make_speculative (cgraph_node *n2, profile_count direct_count,
 unsigned int speculative_id = 0);
 
+  /* TODO DOCS */
+  cgraph_edge *make_callback (cgraph_node *n2);
+
   /* Speculative call consists of an indirect edge and one or more
  direct edge+ref pairs.  Speculative will expand to the following sequence:
 
@@ -1951,6 +1954,10 @@ public:
  Optimizers may later redirect direct call to clone, so 1) and 3)
  do not need to necessarily agree with destination.  */
   unsigned int speculative : 1;
+  /* TODO DOCS */
+  unsigned int callback : 1;
+  /* TODO DOCS */
+  unsigned int has_callback : 1;
   /* Set to true when caller is a constructor or destructor of polymorphic
  type.  */
   unsigned in_polymorphic_cdtor : 1;
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 039ed66eab5d..faae38491fea 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -22,8 +22,11 @@ along with GCC; see the file COPYING3.  If not see
 #ifndef GCC_GIMPLE_H
 #define GCC_GIMPLE_H
 
+#include "stringpool.h"
+#include "attribs.

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: fix flags when cloning edges, add lto input and output

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:f567d0df294dd1e5a820f07be91028c712965b6a

commit f567d0df294dd1e5a820f07be91028c712965b6a
Author: Josef Melcr 
Date:   Mon Oct 21 16:31:32 2024 +0200

omp-cp: fix flags when cloning edges, add lto input and output

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::dump_edge_flags): add callback and
  has_callback printing
* cgraphclones.cc (cgraph_edge::clone): copy over callback and
  has_callback flags
* ipa-inline.cc (can_inline_edge_p): move callback condition to
  the beginning
* lto-cgraph.cc (lto_output_edge): add outputting for callback flags
(input_edge): add inputting of callback flags

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc   |  4 
 gcc/cgraphclones.cc |  2 ++
 gcc/ipa-inline.cc   | 10 +-
 gcc/lto-cgraph.cc   |  4 
 4 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 9310f1b43c20..11002c884bb6 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -2114,6 +2114,10 @@ cgraph_edge::dump_edge_flags (FILE *f)
 {
   if (speculative)
 fprintf (f, "(speculative) ");
+  if (callback)
+fprintf (f, "(callback) ");
+  if (has_callback)
+fprintf (f, "(has_callback) ");
   if (!inline_failed)
 fprintf (f, "(inlined) ");
   if (call_stmt_cannot_inline_p)
diff --git a/gcc/cgraphclones.cc b/gcc/cgraphclones.cc
index 33cab4583348..de57c9bf9ab8 100644
--- a/gcc/cgraphclones.cc
+++ b/gcc/cgraphclones.cc
@@ -144,6 +144,8 @@ cgraph_edge::clone (cgraph_node *n, gcall *call_stmt, 
unsigned stmt_uid,
   new_edge->can_throw_external = can_throw_external;
   new_edge->call_stmt_cannot_inline_p = call_stmt_cannot_inline_p;
   new_edge->speculative = speculative;
+  new_edge->callback = callback;
+  new_edge->has_callback = has_callback;
   new_edge->in_polymorphic_cdtor = in_polymorphic_cdtor;
 
   /* Update IPA profile.  Local profiles need no updating in original.  */
diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index b31c028eca2b..a9ed734f8b89 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -371,6 +371,11 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
 {
   gcc_checking_assert (e->inline_failed);
 
+  if(e->callback) {
+printf("skipping inline - callback\n");
+return false;
+  }
+
   if (cgraph_inline_failed_type (e->inline_failed) == CIF_FINAL_ERROR)
 {
   if (report)
@@ -453,11 +458,6 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
   if (!inlinable && report)
 report_inline_failed_reason (e);
 
-  if(e->callback) {
-printf("skipping inline - tried to inline: %d\n", inlinable);
-inlinable = false;
-  }
-
   return inlinable;
 }
 
diff --git a/gcc/lto-cgraph.cc b/gcc/lto-cgraph.cc
index d1d63fd90ea5..72e6197f5872 100644
--- a/gcc/lto-cgraph.cc
+++ b/gcc/lto-cgraph.cc
@@ -271,6 +271,8 @@ lto_output_edge (struct lto_simple_output_block *ob, struct 
cgraph_edge *edge,
   bp_pack_value (&bp, edge->speculative_id, 16);
   bp_pack_value (&bp, edge->indirect_inlining_edge, 1);
   bp_pack_value (&bp, edge->speculative, 1);
+  bp_pack_value (&bp, edge->callback, 1);
+  bp_pack_value (&bp, edge->has_callback, 1);
   bp_pack_value (&bp, edge->call_stmt_cannot_inline_p, 1);
   gcc_assert (!edge->call_stmt_cannot_inline_p
  || edge->inline_failed != CIF_BODY_NOT_AVAILABLE);
@@ -1538,6 +1540,8 @@ input_edge (class lto_input_block *ib, vec 
nodes,
 
   edge->indirect_inlining_edge = bp_unpack_value (&bp, 1);
   edge->speculative = bp_unpack_value (&bp, 1);
+  edge->callback = bp_unpack_value(&bp, 1);
+  edge->has_callback = bp_unpack_value(&bp, 1);
   edge->lto_stmt_uid = stmt_id;
   edge->speculative_id = speculative_id;
   edge->inline_failed = inline_failed;


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: add analysis done check when recursing in ipa_analyze_node

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:e47df8123f9dcdabaa2164599438e03d987ef1b8

commit e47df8123f9dcdabaa2164599438e03d987ef1b8
Author: Josef Melcr 
Date:   Tue Oct 22 19:24:01 2024 +0200

omp-cp: add analysis done check when recursing in ipa_analyze_node

gcc/ChangeLog:

* ipa-prop.cc (ipa_analyze_node): add analysis done check when 
recursing

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/ipa-prop.cc | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index ffd6555d2e56..7834d494eac1 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -3211,10 +3211,16 @@ ipa_analyze_node (struct cgraph_node *node)
  cgraph_node * reffering_node = dyn_cast(ref->referring);
  gcc_checking_assert(call_stmt);
  gcc_checking_assert(reffering_node);
-cgraph_edge * e = reffering_node->get_edge(ref->stmt);
-e->make_callback(node);
-ipa_analyze_node(e->caller);
-   }
+ cgraph_edge *e = reffering_node->get_edge (ref->stmt);
+ e->make_callback (node);
+ ipa_node_params *caller_info
+   = ipa_node_params_sum->get_create (e->caller);
+ if (caller_info->analysis_done)
+   {
+ caller_info->analysis_done = 0;
+ ipa_analyze_node (e->caller);
+   }
+ }
}
 }


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: change callback creation, add callback args to callsummary, integrate into ipa_compute_jump_

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:716e2eb1f6910b79965215d9cc3b3b96cb0669d9

commit 716e2eb1f6910b79965215d9cc3b3b96cb0669d9
Author: Josef Melcr 
Date:   Mon Oct 28 22:35:16 2024 +0100

omp-cp: change callback creation, add callback args to callsummary, 
integrate into ipa_compute_jump_functions_for_edge

gcc/ChangeLog:

* ipa-inline.cc (can_inline_edge_p): replace printf with fprintf
* ipa-prop.cc (calc_callback_args_idx): new function
(ipa_compute_jump_functions_for_edge): integrate callback_args
info
(ipa_analyze_node): remove callback edge creation
* ipa-prop.h (struct cb_arg_info): new struct
(class ipa_edge_args): add vector of cb_arg_info

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/ipa-inline.cc |  2 +-
 gcc/ipa-prop.cc   | 90 +++
 gcc/ipa-prop.h| 11 ++-
 3 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index a9ed734f8b89..1cb5dc2d2d05 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -372,7 +372,7 @@ can_inline_edge_p (struct cgraph_edge *e, bool report,
   gcc_checking_assert (e->inline_failed);
 
   if(e->callback) {
-printf("skipping inline - callback\n");
+fprintf(stderr, "skipping inline - callback\n");
 return false;
   }
 
diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index 7834d494eac1..8d33780b6d35 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2318,6 +2318,17 @@ ipa_set_jfunc_vr (ipa_jump_func *jf, const ipa_vr &vr)
information in the jump_functions array in the ipa_edge_args corresponding
to this callsite.  */
 
+static void calc_callback_args_idx(cgraph_edge * e) {
+  gcc_checking_assert(e->callback);
+  ipa_edge_args *args = ipa_edge_args_sum->get_create (e);
+  int argn = 1;
+  vec_safe_grow_cleared (args->callback_args, argn, true);
+  (*args->callback_args)[0] = {1, true};
+  for (int i = 1; i < argn; i++) {
+(*args->callback_args)[i] = {i, false};
+  }
+}
+
 static void
 ipa_compute_jump_functions_for_edge (struct ipa_func_body_info *fbi,
 struct cgraph_edge *cs)
@@ -2326,6 +2337,9 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   ipa_edge_args *args = ipa_edge_args_sum->get_create (cs);
   gcall *call = cs->call_stmt;
   int n, arg_num = gimple_call_num_args (call);
+  if (cs->callback) {
+arg_num = args->callback_args->length();
+  }
   bool useful_context = false;
 
   if (arg_num == 0 || args->jump_functions)
@@ -2339,10 +2353,21 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
   if (ipa_func_spec_opts_forbid_analysis_p (cs->caller))
 return;
 
-  for (n = 0; n < arg_num; n++)
+  int n_ = 0;
+  bool recurse = false;
+  cgraph_edge * callback_edge = NULL;
+  for (n = 0; n < arg_num && n_ < arg_num; n_++, n++)
 {
+  if (cs->callback)
+   {
+ n_ = (*args->callback_args)[n].idx;
+   }
+  else
+   {
+ n_ = n;
+   }
   struct ipa_jump_func *jfunc = ipa_get_ith_jump_func (args, n);
-  tree arg = gimple_call_arg (call, n);
+  tree arg = gimple_call_arg (call, n_);
   tree param_type = ipa_get_callee_param_type (cs, n);
   if (flag_devirtualize && POINTER_TYPE_P (TREE_TYPE (arg)))
{
@@ -2419,10 +2444,24 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
}
 
   if (is_gimple_ip_invariant (arg)
- || (VAR_P (arg)
- && is_global_var (arg)
- && TREE_READONLY (arg)))
-   ipa_set_jf_constant (jfunc, arg, cs);
+ || (VAR_P (arg) && is_global_var (arg) && TREE_READONLY (arg)))
+   {
+ ipa_set_jf_constant (jfunc, arg, cs);
+ if (TREE_CODE (arg) == ADDR_EXPR)
+   {
+ tree pointee = TREE_OPERAND (arg, 0);
+ if (TREE_CODE (pointee) == FUNCTION_DECL
+ && lookup_attribute ("callback", DECL_ATTRIBUTES (pointee))
+ && !cs->callback)
+   {
+ cgraph_node *kernel_node = cgraph_node::get_create (pointee);
+ gcc_checking_assert (!recurse && !callback_edge);
+ callback_edge = cs->make_callback (kernel_node);
+ calc_callback_args_idx (callback_edge);
+ recurse = true;
+   }
+   }
+   }
   else if (!is_gimple_reg_type (TREE_TYPE (arg))
   && TREE_CODE (arg) == PARM_DECL)
{
@@ -2463,6 +2502,14 @@ ipa_compute_jump_functions_for_edge (struct 
ipa_func_body_info *fbi,
}
}
 
+  if (cs->callback && (*args->callback_args)[n].is_data_arg)
+   {
+ ipa_set_jf_simple_pass_through (jfunc, 0, true);
+   }
+  if (cs->has_callback && n == 1)
+   {
+ ipa_set_jf_simple_pass_through (jfunc, 1, true);
+   }
   /* If ARG is pointer, we cannot use its type to dete

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: resolve segfault through monkey stick debugging

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:216d94d970ea900e35ff41da7a52a31cc53cba49

commit 216d94d970ea900e35ff41da7a52a31cc53cba49
Author: Josef Melcr 
Date:   Fri Oct 18 23:41:37 2024 +0200

omp-cp: resolve segfault through monkey stick debugging

gcc/ChangeLog:

* cgraph.h: modify functions regarding speculative call edges
* ipa-fnsummary.cc (analyze_function_body): integrate callback
  edges
(compute_fn_summary): integrate callback edges in similar
fashion to speculative edges

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.h | 24 +---
 gcc/ipa-fnsummary.cc |  9 -
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 4d937b1cde24..84fe17a2a450 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1769,6 +1769,10 @@ public:
  target2.  */
   cgraph_edge *next_speculative_call_target ()
   {
+if (callback)
+  {
+   return NULL;
+  }
 cgraph_edge *e = this;
 gcc_checking_assert (speculative && callee);
 
@@ -1783,15 +1787,29 @@ public:
  indirect call edge in the speculative call sequence.  */
   cgraph_edge *speculative_call_indirect_edge ()
   {
-gcc_checking_assert (speculative);
+gcc_checking_assert (speculative || callback);
 if (!callee)
   return this;
-for (cgraph_edge *e2 = caller->indirect_calls;
-true; e2 = e2->next_callee)
+
+cgraph_edge * e2 = NULL;
+for (e2 = caller->indirect_calls;
+e2; e2 = e2->next_callee)
   if (e2->speculative
  && call_stmt == e2->call_stmt
  && lto_stmt_uid == e2->lto_stmt_uid)
return e2;
+
+if (!e2 && callback)
+  {
+   for (e2 = caller->callees; e2; e2 = e2->next_callee)
+ {
+   if (e2->has_callback && call_stmt == e2->call_stmt)
+ {
+   return e2;
+ }
+ }
+  }
+  gcc_unreachable();
   }
 
   /* When called on any edge in speculative call and when given any target
diff --git a/gcc/ipa-fnsummary.cc b/gcc/ipa-fnsummary.cc
index 3f5e09960ef8..348bf2c17724 100644
--- a/gcc/ipa-fnsummary.cc
+++ b/gcc/ipa-fnsummary.cc
@@ -3080,7 +3080,7 @@ analyze_function_body (struct cgraph_node *node, bool 
early)
  es->call_stmt_time = this_time;
  es->loop_depth = bb_loop_depth (bb);
  edge_set_predicate (edge, &bb_predicate);
- if (edge->speculative)
+ if (edge->speculative || edge->callback)
{
  cgraph_edge *indirect
= edge->speculative_call_indirect_edge ();
@@ -3489,6 +3489,13 @@ compute_fn_summary (struct cgraph_node *node, bool early)
   for (e = node->indirect_calls; e; e = e->next_callee)
if (e->speculative)
 break;
+
+  if (!e)
+   {
+ for (e = node->callees; e; e = e->next_callee)
+   if (e->callback)
+ break;
+   }
   gcc_assert (e || size_info->size == size_info->self_size);
 }
 }


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: add callback flag to some checks

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:f214fdbf4e4711b8fd334dea17d30384951ef3cd

commit f214fdbf4e4711b8fd334dea17d30384951ef3cd
Author: Josef Melcr 
Date:   Mon Oct 21 18:04:21 2024 +0200

omp-cp: add callback flag to some checks

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::redirect_call_stmt_to_callee): return
  if callback flag is set
(cgraph_node::verify_node): allow some weirdness if callback is
set

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 11002c884bb6..0465538cab9f 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1515,9 +1515,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
}
 }
 
-
-  if (e->indirect_unknown_callee
-  || decl == e->callee->decl)
+  if (e->indirect_unknown_callee || decl == e->callee->decl || e->callback)
 return e->call_stmt;
 
   if (decl && ipa_saved_clone_sources)
@@ -3683,6 +3681,7 @@ cgraph_node::verify_node (void)
   if (gimple_has_body_p (e->caller->decl)
  && !e->caller->inlined_to
  && !e->speculative
+ && !e->callback
  /* Optimized out calls are redirected to __builtin_unreachable.  */
  && (e->count.nonzero_p ()
  || ! e->callee->decl
@@ -3930,7 +3929,7 @@ cgraph_node::verify_node (void)
 
   for (e = callees; e; e = e->next_callee)
{
- if (!e->aux && !e->speculative)
+ if (!e->aux && !e->speculative && !e->callback)
{
  error ("edge %s->%s has no corresponding call_stmt",
 identifier_to_locale (e->caller->name ()),


[gcc/jmelcr/heads/omp-cp] (1503 commits) omp-cp: Add call stmt copying to callback edges

2024-12-02 Thread Josef Melcr via Gcc-cvs
The branch 'jmelcr/heads/omp-cp' was updated to point to:

 5cc552e9450e... omp-cp: Add call stmt copying to callback edges

It previously pointed to:

 4a81b5e11e31... omp-cp: Add call stmt copying to callback edges

Diff:

!!! WARNING: THE FOLLOWING COMMITS ARE NO LONGER ACCESSIBLE (LOST):
---

  4a81b5e... omp-cp: Add call stmt copying to callback edges
  0b52da2... omp-cp: Add callback redirection, not working yet
  151e861... omp-cp: Add jump function copying, omp constants now appear
  54d33c2... omp-cp: change callback creation, add callback args to call
  96b5b1e... omp-cp: add analysis done check when recursing in ipa_analy
  cf15a12... omp-cp: add callback flag to some checks
  f2c71e4... omp-cp: fix flags when cloning edges, add lto input and out
  397b6d3... omp-cp: resolve segfault through monkey stick debugging
  723b98f... omp-cp: add callback attribute, wip callback edges


Summary of changes (added commits):
---

  5cc552e... omp-cp: Add call stmt copying to callback edges
  e836b2e... omp-cp: Add callback redirection, not working yet
  5c79cf9... omp-cp: Resolve merge conflict, keep both copying functions
  716e2eb... omp-cp: change callback creation, add callback args to call
  e47df81... omp-cp: add analysis done check when recursing in ipa_analy
  f214fdb... omp-cp: add callback flag to some checks
  f567d0d... omp-cp: fix flags when cloning edges, add lto input and out
  216d94d... omp-cp: resolve segfault through monkey stick debugging
  4af5943... omp-cp: add callback attribute, wip callback edges
  e4dd007... x86: Correct comments for pass_apx_nf_convert (*)
  12e30d8... RISC-V: Fix incorrect optimization options passing to widde (*)
  aedb306... RISC-V: Fix RVV strided load/store testcases failure (*)
  326d474... Daily bump. (*)
  90becd9... [contrib] validate_failures.py: fix python 3.12 escape sequ (*)
  721a38a... [PATCH] gcc: configure: Fix the optimization flags cleanup (*)
  999aad4... Thanks for the feedback on the first version of the patch.  (*)
  113e902... [PATCH v7 12/12] Add tests for CRC detection and generation (*)
  4d2b920... [PATCH v7 11/12] Replace the original CRC loops with a fast (*)
  dcc6101... [PATCH v7 10/12] Verify detected CRC loop with symbolic exe (*)
  148e204... [PATCH v6 09/12] Add symbolic execution support. (*)
  062ad20... [PATCH v7 08/12] Add a new pass for naive CRC loops detecti (*)
  75fe4e2... Write binary annotations for CodeView S_INLINESITE symbols (*)
  7151aa1... testsuite: Silence gcc.dg/pr117806.c for default_packed (*)
  e1009b3... VN: Don't recurse on for the same value of `a != 0` [PR1178 (*)
  24949e6... gimple-lim: Reuse boolean var when moving PHI (*)
  e0ffe66... testsuite: Fix aarch64/sve/acle/general-c/gnu_vectors_[12]. (*)
  8491723... testsuite: Fix aarch64/sve/acle/general-c++/gnu_vectors_[12 (*)
  b996304... testsuite: Fix sve-sizeless-[12].C for C++98 (*)
  86b0750... testsuite: Fix sve-sizeless-[12].C for aggregate change (*)
  99d1fcf... testsuite: Fix another issue with sve-sizeless-[12].C (*)
  cdcc938... testsuite: Fix part of sve-sizeless-2.c (*)
  e4c1b3d... [PATCH v3] zero_extend(not) -> xor optimization [PR112398] (*)
  ff5e235... Daily bump. (*)
  abed480... libstdc++: Improve new testcase for std::optional assignmen (*)
  c2c7d71... libstdc++: Fix constraints on std::optional converting assi (*)
  91f4550... libstdc++: Move std::monostate to  for C++26 (P047 (*)
  0598e2f... libstdc++: Improve test for  synopsis (*)
  2ae0566... Support for 64-bit location_t: Internal parts (*)
  8cc9d27... Support for 64-bit location_t: toplev parts (*)
  9bba906... Support for 64-bit location_t: Backend parts (*)
  abea0db... gimplify: Handle void expression as asm input [PR100501, PR (*)
  5297795... Write S_INLINESITE CodeView symbols (*)
  65b5c4a... Write S_INLINEELINES CodeView subsection (*)
  e908efb... Don't output CodeView line numbers for inlined functions (*)
  4ed1898... Add block parameter to begin_block debug hook (*)
  214985f... AVR: ad target/84211 - Split MOVW into MOVs in try_split_an (*)
  6bebb3b... strlen: Handle vector CONSTRUCTORs [PR117057] (*)
  f089ef8... openmp: Add crtoffloadtableS.o and use it [PR117851] (*)
  cd107c1... LoongArch: Mask shift offset when emit {xv, v}{srl, sll, sr (*)
  4ad1c87... LoongArch: testsuite: Fix l{a}sx-andn-iorn.c. (*)
  4f650ef... LoongArch: testsuite: Fix loongarch/vect-frint-scalar.c. (*)
  1539bcd... c: Set attributes for fields when forming a composite type  (*)
  1701efd... gimplefe: Error recovery for invalid declarations [PR117749 (*)
  eb9f1ba... ext-dce: Fix SIGN_EXTEND handling and cleanups [PR117360] (*)
  cc67d95... c++: Implement C++26 P3176R1 - The Oxford variadic comma (*)
  20dcb79... Daily bump. (*)
  bc35976... Rename "libdiagnostics" to "libgdiagnostics" (*)
  b02b9e8... AVR: Skip the gcc.c-torture/execute/memcpy-a*.c tests. (*)
  f8f5732... libbacktrac

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Add callback redirection, not working yet

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:e836b2ea54f5c799d8652cc23184d10fe5683ff9

commit e836b2ea54f5c799d8652cc23184d10fe5683ff9
Author: Josef Melcr 
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 

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 2fb6950ee4a7..6cb753bbd9cf 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1161,6 +1161,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.
 
@@ -1515,9 +1531,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 84fe17a2a450..089e12f6ec30 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 70609f0d7b19..11404bdd3aff 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -2551,9 +2551,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);
 }


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Add call stmt copying to callback edges

2024-12-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:5cc552e9450e859e7f9f26ed98ad1f57fed6f8c5

commit 5cc552e9450e859e7f9f26ed98ad1f57fed6f8c5
Author: Josef Melcr 
Date:   Wed Nov 20 17:45:00 2024 +0100

omp-cp: Add call stmt copying to callback edges

gcc/ChangeLog:

* cgraph.cc (cgraph_edge::set_call_stmt): Integrate callback
edges
(cgraph_edge::redirect_call_stmt_to_callee): Add addr expr
creation

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 6cb753bbd9cf..484f2e3b45ff 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -804,7 +804,8 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
 
   /* Speculative edges has three component, update all of them
  when asked to.  */
-  if (update_speculative && e->speculative
+  if (update_speculative
+  && e->speculative
   /* If we are about to resolve the speculation by calling make_direct
 below, do not bother going over all the speculative edges now.  */
   && !new_direct_callee)
@@ -837,8 +838,30 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall 
*new_stmt,
   return e_indirect ? indirect : direct;
 }
 
-  if (new_direct_callee)
-e = make_direct (e, new_direct_callee);
+  if (update_speculative && (e->callback || e->has_callback)
+  /* If we are about to resolve the speculation by calling make_direct
+below, do not bother going over all the speculative edges now.  */
+  )
+{
+  fprintf (stderr, "set_call_stmt callback\n");
+  cgraph_edge *direct, *next;
+
+  direct = e;
+
+  gcall *old_stmt = direct->call_stmt;
+  for (cgraph_edge *d = direct; d; d = next)
+   {
+ next = d->next_callee;
+ for (; next; next = next->next_callee)
+   {
+ if ((next->callback || next->has_callback)
+ && old_stmt == next->call_stmt)
+   break;
+   }
+ cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
+ gcc_assert (d2 == d);
+   }
+}
 
   /* Only direct speculative edges go to call_site_hash.  */
   if (e->caller->call_site_hash
@@ -1544,7 +1567,7 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge *e,
 {
   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);
+  gimple_call_set_arg (e->call_stmt, 0, build_addr(e->callee->decl));
   debug_gimple_stmt (e->call_stmt);
   fprintf (stderr, "gimple pointer after: %p\n", (void *) e->call_stmt);
   return e->call_stmt;


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Move callback attr from callee to caller, add it to builtins

2024-12-04 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:a0c4cba52a5dc7db28810b44b209982df8144c37

commit a0c4cba52a5dc7db28810b44b209982df8144c37
Author: Josef Melcr 
Date:   Wed Dec 4 19:27:44 2024 +0100

omp-cp: Move callback attr from callee to caller, add it to builtins

gcc/ChangeLog:

* builtin-attrs.def (ATTR_CALLBACK): Add attribute definition
(DEF_CALLBACK_ATTRIBUTE_NOTHROW): New macro for creating
callback attribute
(ATTR_NOTHROW_CALLBACK_GOMP_LIST): New attr list
* gimple.h (gimple_omp_parallel_set_child_fn): Remove callback
attribute addition
* ipa-prop.cc (ipa_duplicate_jump_function): Declare
(calc_callback_args_idx): Refactor
(ipa_compute_jump_functions_for_edge): Change
calc_callback_args_idx call
(ipa_copy_ith_jump_func): Remove function
* omp-builtins.def (BUILT_IN_GOMP_PARALLEL): Change attr list to
callback list

gcc/c-family/ChangeLog:

* c-attribs.cc (handle_callback_attribute): Add attribute
handler

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/builtin-attrs.def |  10 +++
 gcc/c-family/c-attribs.cc |  36 +-
 gcc/gimple.h  |  10 +--
 gcc/ipa-prop.cc   | 171 +-
 gcc/omp-builtins.def  |   2 +-
 5 files changed, 95 insertions(+), 134 deletions(-)

diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def
index 1b8885c933cf..8a0b3463adcb 100644
--- a/gcc/builtin-attrs.def
+++ b/gcc/builtin-attrs.def
@@ -121,6 +121,7 @@ DEF_ATTR_IDENT (ATTR_TM_TMPURE, "transaction_pure")
 DEF_ATTR_IDENT (ATTR_RETURNS_TWICE, "returns_twice")
 DEF_ATTR_IDENT (ATTR_RETURNS_NONNULL, "returns_nonnull")
 DEF_ATTR_IDENT (ATTR_WARN_UNUSED_RESULT, "warn_unused_result")
+DEF_ATTR_IDENT (ATTR_CALLBACK, "callback")
 
 DEF_ATTR_TREE_LIST (ATTR_NOVOPS_LIST, ATTR_NOVOPS, ATTR_NULL, ATTR_NULL)
 
@@ -387,6 +388,15 @@ DEF_FORMAT_ATTRIBUTE_NOTHROW(STRFMON,3,3_4)
 #undef DEF_FORMAT_ATTRIBUTE_NOTHROW
 #undef DEF_FORMAT_ATTRIBUTE_BOTH
 
+/* Callback attr */
+#define DEF_CALLBACK_ATTRIBUTE_NOTHROW(TYPE, CA, VALUES)   
 \
+  DEF_ATTR_TREE_LIST (ATTR_CALLBACK_##TYPE##_NOTHROW_##VALUES, ATTR_CALLBACK,\
+ ATTR_NOTHROW_NONNULL_##CA, ATTR_LIST_##VALUES)
+
+DEF_CALLBACK_ATTRIBUTE_NOTHROW(GOMP, 1, 2)
+DEF_ATTR_TREE_LIST(ATTR_NOTHROW_CALLBACK_GOMP_LIST, ATTR_CALLBACK, 
ATTR_CALLBACK_GOMP_NOTHROW_2, ATTR_NOTHROW_LIST)
+#undef DEF_CALLBACK_ATTRIBUTE_NOTHROW
+
 /* Transactional memory variants of the above.  */
 
 DEF_ATTR_TREE_LIST (ATTR_TM_NOTHROW_LIST,
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index c342e7a1e55f..6fb1f8d034d1 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -188,6 +188,7 @@ static tree handle_retain_attribute (tree *, tree, tree, 
int, bool *);
 static tree handle_fd_arg_attribute (tree *, tree, tree, int, bool *);
 static tree handle_flag_enum_attribute (tree *, tree, tree, int, bool *);
 static tree handle_null_terminated_string_arg_attribute (tree *, tree, tree, 
int, bool *);
+static tree handle_callback_attribute (tree *, tree, tree, int, bool *);
 
 /* Helper to define attribute exclusions.  */
 #define ATTR_EXCL(name, function, type, variable)  \
@@ -465,6 +466,7 @@ const struct attribute_spec c_common_gnu_attributes[] =
  handle_tm_attribute, NULL },
   { "transaction_may_cancel_outer", 0, 0, false, true, false, false,
  handle_tm_attribute, NULL },
+  { "callback", 1, -1, true, false, false, false, handle_callback_attribute, 
NULL},
   /* ??? These two attributes didn't make the transition from the
  Intel language document to the multi-vendor language document.  */
   { "transaction_pure",   0, 0, false, true,  false, false,
@@ -643,7 +645,6 @@ const struct attribute_spec c_common_gnu_attributes[] =
  handle_flag_enum_attribute, NULL },
   { "null_terminated_string_arg", 1, 1, false, true, true, false,
  handle_null_terminated_string_arg_attribute, 
NULL},
-  { "callback", 0, 0, true, false, false, false, NULL, NULL}
 };
 
 const struct scoped_attribute_specs c_common_gnu_attribute_table =
@@ -5192,6 +5193,39 @@ get_argument (tree fndecl, unsigned argno)
   return NULL_TREE;
 }
 
+static tree
+handle_callback_attribute (tree *node, tree name, tree args,
+  int ARG_UNUSED (flags),
+  bool ARG_UNUSED (*no_add_attrs))
+{
+  tree decl = *node;
+  if (TREE_CODE (decl) != FUNCTION_DECL)
+{
+  error_at (DECL_SOURCE_LOCATION (decl),
+   "%qE attribute can only be used on functions", name);
+}
+  tree callback_fn_idx_node = args;
+  for (int i = 0; i < 3;
+   i++, callback_fn_idx_node = TREE_VALUE (callback_fn_idx_node))
+;
+  int callback_fn_idx = TREE_INT_CST_LOW (callback

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Refactor code, improve callback handler, add multiple callbacks support

2025-02-04 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:28fbf4db2cb28be3df399d4eb2ac61ab5ea0d465

commit 28fbf4db2cb28be3df399d4eb2ac61ab5ea0d465
Author: Josef Melcr 
Date:   Tue Feb 4 19:33:02 2025 +0100

omp-cp: Refactor code, improve callback handler, add multiple callbacks 
support

gcc/ChangeLog:

* builtin-attrs.def (0): Add new list with 0.
(DEF_CALLBACK_ATTRIBUTE_NOTHROW): Remove macro.
(GOMP): Add callback for GOMP functions.
(ATTR_NOTHROW_CALLBACK_GOMP_LIST): Remove list.
(DEF_CALLBACK_ATTRIBUTE): New macro for callback attribute
creation.
(OACC): Callback attribute for OACC functions.
(ATTR_CALLBACK_GOMP_LIST): Add list for for GOMP functions with
callbacks as their first argument and data as their second
argument.
(ATTR_CALLBACK_GOMP_TASK_HELPER_LIST): Helper list for
GOMP_task, needed because it has 2 callbacks.
(ATTR_CALLBACK_GOMP_TASK_LIST): Attribute list for GOMP_task
(ATTR_CALLBACK_OACC_LIST): Attribute list for OACC functions
with callbacks.
* cgraph.cc (cgraph_edge::set_call_stmt): Refactor callback
section.
(symbol_table::create_edge): Add check for callback to creation
assert.
(cgraph_edge::get_callback_parent_edge): Refactor function.
(cgraph_edge::redirect_call_stmt_to_callee): Refactor callback
redirection.
(cgraph_edge::maybe_hot_p): Make callback edge hot when it's
parent is hot, not working for now.
(cgraph_node::verify_node): Add verifiers for callbacks.
* cgraph.h: Add docs for callback utils.
* doc/extend.texi: Add callback attr docs.
* ipa-fnsummary.cc (analyze_function_body): Refactor.
(compute_fn_summary): Refactor.
* ipa-inline.cc (can_inline_edge_p): Refactor.
* ipa-prop.cc (calc_callback_args_idx): Remove function.
(init_callback_edge_summary): New function.
(ipa_compute_jump_functions_for_edge): Refactor, add multiple
callback support.
* ipa-prop.h (struct cb_arg_info): Remove struct.
(class ipa_edge_args): Remove cb_arg_info uses.
* omp-builtins.def (BUILT_IN_GOACC_PARALLEL): Use new attr list.
(BUILT_IN_GOMP_PARALLEL_LOOP_STATIC): Likewise.
(BUILT_IN_GOMP_PARALLEL_LOOP_GUIDED): Likewise.
(BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_DYNAMIC): Likewise.
(BUILT_IN_GOMP_PARALLEL_LOOP_NONMONOTONIC_RUNTIME): Likewise.
(BUILT_IN_GOMP_PARALLEL): Likewise.
(BUILT_IN_GOMP_TASK): Likewise.
(BUILT_IN_GOMP_PARALLEL_SECTIONS): Likewise.
(BUILT_IN_GOMP_TEAMS_REG): Likewise.
* attr-callback.h: New file.

gcc/c-family/ChangeLog:

* c-attribs.cc (handle_callback_attribute): Move handler to
attr_callback.h, add more checks.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/attr-callback.h   | 273 ++
 gcc/builtin-attrs.def |  25 +++--
 gcc/c-family/c-attribs.cc |  35 +-
 gcc/cgraph.cc | 121 ++--
 gcc/cgraph.h  |  56 +-
 gcc/doc/extend.texi   |  37 +++
 gcc/ipa-fnsummary.cc  |  26 +++--
 gcc/ipa-inline.cc |   6 +-
 gcc/ipa-prop.cc   | 113 +--
 gcc/ipa-prop.h|  11 +-
 gcc/omp-builtins.def  |  28 ++---
 11 files changed, 535 insertions(+), 196 deletions(-)

diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
new file mode 100644
index ..ea9c9cbbc780
--- /dev/null
+++ b/gcc/attr-callback.h
@@ -0,0 +1,273 @@
+/* Callback attribute handling
+   Copyright (C) 2025 Free Software Foundation, Inc.
+   Contributed by Josef Melcr 
+
+   This file is part of GCC.
+
+   GCC is free software; you can redistribute it and/or modify
+   under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   GCC is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GCC; see the file COPYING3.  If not see
+   .  */
+
+#ifndef ATTR_CALLBACK_H
+#define ATTR_CALLBACK_H
+#include "attribs.h"
+#include "system.h"
+#include "tree.h"
+#include "function.h"
+#include "basic-block.h"
+#include "coretypes.h"
+#include "is-a.h"
+#include "predict.h"
+#include "internal-fn.h"
+#include "tree-ssa-alias.h"
+#include "gimple-expr.h"
+#include "gimple.h"
+#include "vec.h"
+
+enum callback_

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: multiple callbacks in progress

2025-03-30 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:660de7e0a3cd8f1ddf6719d3cfe0a6b452557f9c

commit 660de7e0a3cd8f1ddf6719d3cfe0a6b452557f9c
Author: Josef Melcr 
Date:   Sun Mar 30 19:37:22 2025 +0200

omp-cp: multiple callbacks in progress

gcc/ChangeLog:

* attr-callback.h (callback_edge_useful_p): New function.
* cgraph.cc (cgraph_edge::purge_callback_children): New
function.
(cgraph_edge::redirect_call_stmt_to_callee): Add redirection
skipping for callback edges.
* cgraph.h: Declarations.
* ipa-cp.cc (purge_useless_callback_edges): New function.
(ipcp_decision_stage): Integrate the above function.
* ipa-param-manipulation.cc 
(drop_decl_attribute_if_params_changed_p): New predicate.
(ipa_param_adjustments::build_new_function_type): Add output
parameter.
(ipa_param_adjustments::adjust_decl): Add attribute dropping.
* ipa-param-manipulation.h: Change signature.
* tree-core.h (ECF_CB_1_0): New constant for callback attribute.
(ECF_CB_1_2): Likewise.
(ECF_CB_2_4): Likewise.
(ECF_CB_3_0_2): Likewise.
* tree.cc (set_call_expr_flags): Integrate the above flags.

gcc/fortran/ChangeLog:

* f95-lang.cc (ATTR_CALLBACK_GOMP_LIST): Add constant for list,
see builtin-attrs.def.
(ATTR_CALLBACK_GOMP_TASK_LIST): Likewise.
(ATTR_CALLBACK_OACC_LIST): Likewise.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/attr-callback.h   | 11 ++
 gcc/cgraph.cc | 20 ++
 gcc/cgraph.h  |  3 +++
 gcc/fortran/f95-lang.cc   |  4 
 gcc/ipa-cp.cc | 47 ++-
 gcc/ipa-param-manipulation.cc | 28 --
 gcc/ipa-param-manipulation.h  |  2 +-
 gcc/tree-core.h   | 14 +
 gcc/tree.cc   | 43 +++
 9 files changed, 168 insertions(+), 4 deletions(-)

diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
index ea9c9cbbc780..b6a1a0c4106c 100644
--- a/gcc/attr-callback.h
+++ b/gcc/attr-callback.h
@@ -270,4 +270,15 @@ handle_callback_attribute (tree *node, tree name, tree 
args,
   return NULL_TREE;
 }
 
+inline bool
+callback_edge_useful_p (cgraph_edge *e)
+{
+  gcc_checking_assert (e->callback);
+  /* If the edge is not pointing towards a clone, it is no longer useful as its
+ entire purpose is to produce clones of callbacks. */
+  if (!e->callee->clone_of)
+return false;
+  return true;
+}
+
 #endif /* ATTR_CALLBACK_H  */
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index e032cc0b4864..3bcfe1f2da12 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1248,6 +1248,19 @@ cgraph_edge::next_callback_target ()
   return e;
 }
 
+void
+cgraph_edge::purge_callback_children ()
+{
+  gcc_checking_assert (has_callback);
+  cgraph_edge *e, *next;
+  for (e = first_callback_target (); e; e = next)
+{
+  next = e->next_callback_target ();
+  cgraph_edge::remove (e);
+}
+  has_callback = false;
+}
+
 /* Speculative call consists of an indirect edge and one or more
direct edge+ref pairs.
 
@@ -1610,6 +1623,13 @@ cgraph_edge::redirect_call_stmt_to_callee (cgraph_edge 
*e,
  redirecting to. */
   if (e->callback)
 {
+  cgraph_edge *parent = e->get_callback_parent_edge ();
+  if (!lookup_attribute ("callback",
+DECL_ATTRIBUTES (parent->callee->decl)))
+   /* Callback attribute is removed if the offloading function changes
+  signature, as the indices would be correct anymore. These edges will
+  get cleaned up later, ignore their redirection for now. */
+   return e->call_stmt;
   int fn_idx
= callback_fetch_fn_position (e->call_stmt, DECL_ATTRIBUTES (decl),
  e->callee->decl);
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 044639793486..18756cf9f4f8 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -1753,6 +1753,9 @@ public:
   /* TODO DOCS */
   cgraph_edge *next_callback_target ();
 
+  /* TODO DOCS */
+  void purge_callback_children ();
+
   /* 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/fortran/f95-lang.cc b/gcc/fortran/f95-lang.cc
index aed19a9822ee..1c4b4b0de3d8 100644
--- a/gcc/fortran/f95-lang.cc
+++ b/gcc/fortran/f95-lang.cc
@@ -574,6 +574,10 @@ gfc_builtin_function (tree decl)
 #define ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST \
(ECF_COLD | ECF_NORETURN | \
 ECF_NOTHROW | ECF_LEAF)
+#define ATTR_CALLBACK_GOMP_LIST (ECF_CB_1_2 | ATTR_NOTHROW_LIST)
+#define ATTR_CALLBACK_GOMP_TASK_LIST \
+  (ECF_CB_3_0_2 | ECF_CB_1_0 | ATTR_NOTHROW_LIST)
+#define ATTR_CALLB

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: fix info copying in fn-summary, fix callback edge inlining

2025-03-14 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:307ba5b392678330c44b9a43215856eef5befc60

commit 307ba5b392678330c44b9a43215856eef5befc60
Author: Josef Melcr 
Date:   Fri Mar 14 15:13:42 2025 +0100

omp-cp: fix info copying in fn-summary, fix callback edge inlining

gcc/ChangeLog:

* cgraph.cc (cgraph_add_edge_to_call_site_hash): Exclude
callback edges.
(cgraph_node::get_edge): Return parent edge if callback is found
first.
(cgraph_edge::set_call_stmt): Fix callback edges.
(cgraph_edge::first_callback_target): New function.
(cgraph_edge::next_callback_target): New function.
(cgraph_node::remove_callers): Remove callback edges when
removing their parent.
(cgraph_node::verify_node): Fix type.
* cgraph.h: Add declarations.
* ipa-fnsummary.cc (analyze_function_body): Fix summary copying
when dealing with callback edges.
* ipa-inline-transform.cc (inline_transform): Set child call
stmts when setting their parent.
* ipa-prop.cc (ipa_compute_jump_functions_for_edge): Fix
segfault when dealing with indirect edges.
* tree-inline.cc (copy_bb): Add callback edge copying.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/cgraph.cc   | 63 ++---
 gcc/cgraph.h|  6 +
 gcc/ipa-fnsummary.cc| 16 
 gcc/ipa-inline-transform.cc | 12 -
 gcc/ipa-prop.cc |  2 +-
 gcc/tree-inline.cc  | 13 ++
 6 files changed, 101 insertions(+), 11 deletions(-)

diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index eabba370aa1f..e032cc0b4864 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -721,6 +721,8 @@ cgraph_add_edge_to_call_site_hash (cgraph_edge *e)
  one indirect); always hash the direct one.  */
   if (e->speculative && e->indirect_unknown_callee)
 return;
+  if (e->callback)
+return;
   cgraph_edge **slot = e->caller->call_site_hash->find_slot_with_hash
   (e->call_stmt, cgraph_edge_hasher::hash (e->call_stmt), INSERT);
   if (*slot)
@@ -769,6 +771,9 @@ cgraph_node::get_edge (gimple *call_stmt)
n++;
   }
 
+  if (e && e->callback)
+e = e->get_callback_parent_edge ();
+
   if (n > 100)
 {
   call_site_hash = hash_table::create_ggc (120);
@@ -845,7 +850,7 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall *new_stmt,
 {
   cgraph_edge *current, *next;
 
-  current = e;
+  current = e->first_callback_target ();
   gcall *old_stmt = current->call_stmt;
   for (cgraph_edge *d = current; d; d = next)
{
@@ -1213,6 +1218,36 @@ cgraph_edge::get_callback_parent_edge ()
   return e;
 }
 
+cgraph_edge *
+cgraph_edge::first_callback_target ()
+{
+  gcc_checking_assert (has_callback || callback);
+  cgraph_edge *e = NULL;
+  for (e = caller->callees; e; e = e->next_callee)
+{
+  if (e->callback && e->call_stmt == call_stmt)
+   {
+ break;
+   }
+}
+  return e;
+}
+
+cgraph_edge *
+cgraph_edge::next_callback_target ()
+{
+  gcc_checking_assert (has_callback || callback);
+  cgraph_edge *e = NULL;
+  for (e = next_callee; e; e = e->next_callee)
+{
+  if (e->callback && e->call_stmt == call_stmt)
+   {
+ break;
+   }
+}
+  return e;
+}
+
 /* Speculative call consists of an indirect edge and one or more
direct edge+ref pairs.
 
@@ -1867,6 +1902,17 @@ cgraph_node::remove_callers (void)
   for (e = callers; e; e = f)
 {
   f = e->next_caller;
+  if (e->has_callback)
+   {
+ cgraph_edge *cbe, *next_cbe = NULL;
+ for (cbe = e->first_callback_target (); cbe; cbe = next_cbe)
+   {
+ next_cbe = cbe->next_callback_target ();
+ symtab->call_edge_removal_hooks (cbe);
+ cbe->remove_caller ();
+ symtab->free_edge (cbe);
+   }
+   }
   symtab->call_edge_removal_hooks (e);
   e->remove_caller ();
   symtab->free_edge (e);
@@ -4032,11 +4078,20 @@ cgraph_node::verify_node (void)
ncallbacks++)
;
  for (cgraph_edge *cbe = callees; cbe; cbe = cbe->next_callee)
-   if (cbe->callback && cbe->call_stmt == e->call_stmt)
- nfound_edges++;
+   {
+ if (cbe->callback && cbe->call_stmt == e->call_stmt) {
+
+   nfound_edges++;
+
+ }
+ else if (cbe->callback) {
+   fprintf (stderr, "sus verify %s -> %s\n",
+cbe->caller->name (), cbe->callee->name ());
+ }
+   }
  if (ncallbacks != nfound_edges)
{
- error ("callback edge %s->%s child edge count mismach, "
+ error ("callback edge %s->%s child edge count mismatch, "

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Fix one segfault, introduce a different one

2025-04-04 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:86ef6c04591ed9b8deda7f1c86ff7f88e1efd734

commit 86ef6c04591ed9b8deda7f1c86ff7f88e1efd734
Author: Josef Melcr 
Date:   Mon Mar 31 20:48:52 2025 +0200

omp-cp: Fix one segfault, introduce a different one

gcc/ChangeLog:

* attr-callback.h (callback_fetch_fn_position): Rewrite with the
new function below.
(callback_fetch_attr_by_decl): New function.
(callback_remove_callback_edge): New function.
* cgraph.cc (cgraph_edge::get_callback_parent_edge): Add
lto_stmt_uid check.
(cgraph_edge::first_callback_target): Likewise.
(cgraph_edge::next_callback_target): Likewise.
(cgraph_node::verify_node): Likewise.
* ipa-cp.cc (purge_useless_callback_edges): Reformat, use the
new remove function.
(ipcp_decision_stage): Add back purge function.
* ipa-fnsummary.cc (analyze_function_body): Set call stmt size
and time to 0 for callback edges.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/attr-callback.h  | 58 +++-
 gcc/cgraph.cc| 21 +++
 gcc/ipa-cp.cc| 34 +-
 gcc/ipa-fnsummary.cc |  2 ++
 4 files changed, 82 insertions(+), 33 deletions(-)

diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
index b6a1a0c4106c..622949c03ac3 100644
--- a/gcc/attr-callback.h
+++ b/gcc/attr-callback.h
@@ -86,18 +86,13 @@ callback_get_arg_mapping (tree decl)
   return res;
 }
 
-/* Given a call statement of the parent, it's attribute list and
-   a decl of the callback, returns a 0-based index of the callback
-   function in the parameters of it's caller function. Arguments
-   are extracted from the call statement. If kernel_decl is a decl
-   of a clone, it's parent decl will be considered as well. */
-inline int
-callback_fetch_fn_position (gcall *call, tree attr_list, tree kernel_decl)
+inline tree
+callback_fetch_attr_by_decl(gcall *call, tree attr_list, tree kernel_decl)
 {
   tree original_decl = DECL_ORIGIN (kernel_decl);
   tree cb_attr = lookup_attribute ("callback", attr_list);
   gcc_checking_assert (cb_attr);
-  int res = -1;
+  tree res = NULL_TREE;
   for (; cb_attr; cb_attr = lookup_attribute ("callback", TREE_CHAIN 
(cb_attr)))
 {
   int idx = callback_get_fn_index (cb_attr);
@@ -108,15 +103,27 @@ callback_fetch_fn_position (gcall *call, tree attr_list, 
tree kernel_decl)
  if (pointee != NULL_TREE
  && (pointee == kernel_decl || pointee == original_decl))
{
- res = idx;
+ res = cb_attr;
  break;
}
}
 }
-  gcc_checking_assert (res != -1);
+  gcc_checking_assert (res != NULL_TREE);
   return res;
 }
 
+/* Given a call statement of the parent, it's attribute list and
+   a decl of the callback, returns a 0-based index of the callback
+   function in the parameters of it's caller function. Arguments
+   are extracted from the call statement. If kernel_decl is a decl
+   of a clone, it's parent decl will be considered as well. */
+inline int
+callback_fetch_fn_position (gcall *call, tree attr_list, tree kernel_decl)
+{
+  tree attr = callback_fetch_attr_by_decl(call, attr_list, kernel_decl);
+  return callback_get_fn_index(attr);
+}
+
 /* Returns the element at index idx in the list or NULL_TREE if
the list isn't long enough. NULL_TREE is used as the endpoint. */
 static tree
@@ -281,4 +288,35 @@ callback_edge_useful_p (cgraph_edge *e)
   return true;
 }
 
+inline void
+callback_remove_callback_edge (cgraph_edge *e)
+{
+  gcc_checking_assert (e->callback);
+  cgraph_edge *parent = e->get_callback_parent_edge ();
+  tree offload_decl = parent->callee->decl;
+  if (parent->call_stmt)
+{
+  tree attr = callback_fetch_attr_by_decl (parent->call_stmt,
+  DECL_ATTRIBUTES (offload_decl),
+  e->callee->decl);
+
+  tree *p;
+  tree list = DECL_ATTRIBUTES (offload_decl);
+  for (p = &list; *p;)
+   {
+ tree l = *p;
+
+ if (l == attr)
+   {
+ *p = TREE_CHAIN (l);
+ continue;
+   }
+ p = &TREE_CHAIN (l);
+   }
+
+  DECL_ATTRIBUTES (offload_decl) = list;
+}
+  cgraph_edge::remove (e);
+}
+
 #endif /* ATTR_CALLBACK_H  */
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 3bcfe1f2da12..60a4f49014c3 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -1212,7 +1212,8 @@ cgraph_edge::get_callback_parent_edge ()
   cgraph_edge *e;
   for (e = caller->callees; e; e = e->next_callee)
 {
-  if (e->has_callback && e->call_stmt == call_stmt)
+  if (e->has_callback && e->call_stmt == call_stmt
+ && e->lto_stmt_uid == lto_stmt_uid)
break;
 }
   return e;
@@ -1225,7 +1226,8 @@ cgraph_edge::first_callback_target ()
   cgraph_edge 

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Fix redirections, callback edge deletion

2025-04-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:060374f2294e5df3bf1c96e2051a06b8f7051ba6

commit 060374f2294e5df3bf1c96e2051a06b8f7051ba6
Author: Josef Melcr 
Date:   Wed Apr 2 11:06:35 2025 +0200

omp-cp: Fix redirections, callback edge deletion

gcc/ChangeLog:

* attr-callback.h (callback_remove_callback_edge): Remove
function.
* cgraph.cc (cgraph_edge::set_call_stmt): Add null check.
(cgraph_node::verify_node): Change verifying logic to account
for CB edge deletion.
* ipa-cp.cc (purge_useless_callback_edges): Change deletion
function, more logging.
* ipa-fnsummary.cc (ipa_call_summary_t::duplicate): Exclude
callback edges when subtracting size and time.
* ipa-inline-analysis.cc (do_estimate_growth_1): Skip callback
edges when calculating inlining cost.
* ipa-inline-transform.cc (inline_transform): Add callback edge
redirection.
* tree-inline.cc (redirect_all_calls): Likewise.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/attr-callback.h | 31 ---
 gcc/cgraph.cc   | 32 
 gcc/ipa-cp.cc   | 10 +-
 gcc/ipa-fnsummary.cc|  3 ++-
 gcc/ipa-inline-analysis.cc  |  3 +++
 gcc/ipa-inline-transform.cc |  7 ++-
 gcc/tree-inline.cc  | 12 ++--
 7 files changed, 46 insertions(+), 52 deletions(-)

diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
index 622949c03ac3..cf22808c9b8b 100644
--- a/gcc/attr-callback.h
+++ b/gcc/attr-callback.h
@@ -288,35 +288,4 @@ callback_edge_useful_p (cgraph_edge *e)
   return true;
 }
 
-inline void
-callback_remove_callback_edge (cgraph_edge *e)
-{
-  gcc_checking_assert (e->callback);
-  cgraph_edge *parent = e->get_callback_parent_edge ();
-  tree offload_decl = parent->callee->decl;
-  if (parent->call_stmt)
-{
-  tree attr = callback_fetch_attr_by_decl (parent->call_stmt,
-  DECL_ATTRIBUTES (offload_decl),
-  e->callee->decl);
-
-  tree *p;
-  tree list = DECL_ATTRIBUTES (offload_decl);
-  for (p = &list; *p;)
-   {
- tree l = *p;
-
- if (l == attr)
-   {
- *p = TREE_CHAIN (l);
- continue;
-   }
- p = &TREE_CHAIN (l);
-   }
-
-  DECL_ATTRIBUTES (offload_decl) = list;
-}
-  cgraph_edge::remove (e);
-}
-
 #endif /* ATTR_CALLBACK_H  */
diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc
index 60a4f49014c3..a1bb366265e7 100644
--- a/gcc/cgraph.cc
+++ b/gcc/cgraph.cc
@@ -851,19 +851,22 @@ cgraph_edge::set_call_stmt (cgraph_edge *e, gcall 
*new_stmt,
   cgraph_edge *current, *next;
 
   current = e->first_callback_target ();
-  gcall *old_stmt = current->call_stmt;
-  for (cgraph_edge *d = current; d; d = next)
+  if (current)
{
- next = d->next_callee;
- for (; next; next = next->next_callee)
+ gcall *old_stmt = current->call_stmt;
+ for (cgraph_edge *d = current; d; d = next)
{
- /* has_callback doesn't need to checked, as their
-call statements wouldn't match */
- if (next->callback && old_stmt == next->call_stmt)
-   break;
+ next = d->next_callee;
+ for (; next; next = next->next_callee)
+   {
+ /* has_callback doesn't need to checked, as their
+call statements wouldn't match */
+ if (next->callback && old_stmt == next->call_stmt)
+   break;
+   }
+ cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
+ gcc_assert (d2 == d);
}
- cgraph_edge *d2 = set_call_stmt (d, new_stmt, false);
- gcc_assert (d2 == d);
}
 }
 
@@ -3824,6 +3827,7 @@ cgraph_node::verify_node (void)
  && !e->caller->inlined_to
  && !e->speculative
  && !e->callback
+ && !e->has_callback
  /* Optimized out calls are redirected to __builtin_unreachable.  */
  && (e->count.nonzero_p ()
  || ! e->callee->decl
@@ -4107,15 +4111,11 @@ cgraph_node::verify_node (void)
{
  nfound_edges++;
}
- else if (cbe->callback) {
-   fprintf (stderr, "sus verify %s -> %s\n",
-cbe->caller->name (), cbe->callee->name ());
- }
}
- if (ncallbacks != nfound_edges)
+ if (ncallbacks < nfound_edges)
{
  error ("callback edge %s->%s child edge count mismatch, "
-"expected %d, found %d",
+"expected at most %d, found %d",
 identifier_to_locale (e->c

[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Various bug fixes, mainly printing

2025-04-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:64b07469e7aa07f2534857ae44c2b6f03a311dba

commit 64b07469e7aa07f2534857ae44c2b6f03a311dba
Author: Josef Melcr 
Date:   Wed Apr 2 22:22:00 2025 +0200

omp-cp: Various bug fixes, mainly printing

gcc/ChangeLog:

* attr-callback.h (handle_callback_attribute): Minor bugfixes.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/attr-callback.h | 22 ++
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/gcc/attr-callback.h b/gcc/attr-callback.h
index cf22808c9b8b..63c54e753178 100644
--- a/gcc/attr-callback.h
+++ b/gcc/attr-callback.h
@@ -168,9 +168,24 @@ handle_callback_attribute (tree *node, tree name, tree 
args,
 }
   /* We have to use the function type for validation, as
  DECL_ARGUMENTS returns NULL at this point. */
-  unsigned callback_fn_idx = TREE_INT_CST_LOW (cb_fn_idx_node) - 1;
+  unsigned callback_fn_idx = TREE_INT_CST_LOW (cb_fn_idx_node);
   tree decl_type_args = TYPE_ARG_TYPES (TREE_TYPE (decl));
+  tree it;
   unsigned decl_nargs = list_length (decl_type_args);
+  for (it = decl_type_args; it != NULL_TREE; it = TREE_CHAIN (it))
+if (it == void_list_node)
+  {
+   --decl_nargs;
+   break;
+  }
+  if (callback_fn_idx == CB_UNKNOWN_POS)
+{
+  error_at (DECL_SOURCE_LOCATION (decl),
+   "callback function position cannot be marked as unknown");
+  *no_add_attrs = true;
+  return NULL_TREE;
+}
+  --callback_fn_idx;
   if (callback_fn_idx >= decl_nargs)
 {
   error_at (DECL_SOURCE_LOCATION (decl),
@@ -195,12 +210,11 @@ handle_callback_attribute (tree *node, tree name, tree 
args,
 {
   error_at (DECL_SOURCE_LOCATION (decl),
"argument no. %d is not an address of a function",
-   callback_fn_idx);
+   callback_fn_idx + 1);
   *no_add_attrs = true;
   return NULL_TREE;
 }
 
-  tree it;
   tree type_args = TYPE_ARG_TYPES (cfn_pointee_type);
   /* Compare the length of the list of argument indices
  and the real number of parameters the callback takes. */
@@ -268,7 +282,7 @@ handle_callback_attribute (tree *node, tree name, tree args,
  error_at (DECL_SOURCE_LOCATION (decl),
"argument type at index %d is not compatible with callback "
"argument type at index %d",
-   curr, arg_idx);
+   arg_idx + 1, curr + 1);
  *no_add_attrs = true;
  continue;
}


[gcc(refs/users/jmelcr/heads/omp-cp)] omp-cp: Add testcases for omp-cp and callback attribute.

2025-04-02 Thread Josef Melcr via Gcc-cvs
https://gcc.gnu.org/g:b1fabc31774a8917426c9bdae59da45417d3c052

commit b1fabc31774a8917426c9bdae59da45417d3c052
Author: Josef Melcr 
Date:   Wed Apr 2 22:23:10 2025 +0200

omp-cp: Add testcases for omp-cp and callback attribute.

gcc/testsuite/ChangeLog:

* gcc.dg/attr-callback.c: New test.
* gcc.dg/ipa/ipcp-cb1.c: New test.
* gcc.dg/ipa/ipcp-cb2.c: New test.

Signed-off-by: Josef Melcr 

Diff:
---
 gcc/testsuite/gcc.dg/attr-callback.c | 79 
 gcc/testsuite/gcc.dg/ipa/ipcp-cb1.c  | 25 
 gcc/testsuite/gcc.dg/ipa/ipcp-cb2.c  | 53 
 3 files changed, 157 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/attr-callback.c 
b/gcc/testsuite/gcc.dg/attr-callback.c
new file mode 100644
index ..def371193f59
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/attr-callback.c
@@ -0,0 +1,79 @@
+/* Test callback attribute error checking. */
+
+/* { dg-do compile } */
+
+void 
+__attribute__((callback(1, 2)))
+correct_1(void (*)(int*), int*);
+
+void 
+__attribute__((callback(1, 2, 3)))
+correct_2(void (*)(int*, double*), int*, double*);
+
+void 
+__attribute__((callback(1, 0)))
+unknown_1(void (*)(int*));
+
+void 
+__attribute__((callback(1, 2, 0)))
+unknown_2(void (*)(int*, double*), int*, double*, char*);
+
+void 
+__attribute__((callback(1, 0, 3, 3)))
+too_many(void (*)(int*, double*), int*, double*); /* { dg-error "argument 
number mismatch, 2 expected, got 3" }*/
+
+void 
+__attribute__((callback(1, 2)))
+too_few_1(void (*)(int*, double*), int*, double*); /* { dg-error "argument 
number mismatch, 2 expected, got 1" }*/
+
+void 
+__attribute__((callback(1)))
+too_few_2(void (*)(int*, double*), int*, double*); /* { dg-error "argument 
number mismatch, 2 expected, got 0" }*/
+
+void 
+__attribute__((callback(3, 1)))
+promotion(char*, float, int (*)(int*));
+
+void 
+__attribute__((callback(2, 3)))
+downcast(char*, void* (*)(float*), double*);
+
+void 
+__attribute__((callback(1, 2, 5)))
+out_of_range_1(char (*)(float*, double*), float*, double*, int*); /* { 
dg-error "callback argument index 5 is out of range" } */
+
+void 
+__attribute__((callback(1, -2, 3)))
+out_of_range_2(char (*)(float*, double*), float*, double*, int*); /* { 
dg-error "callback argument index -2 is out of range" } */
+
+void 
+__attribute__((callback(-1, 2, 3)))
+out_of_range_3(char (*)(float*, double*), float*, double*, int*); /* { 
dg-error "callback function position out of range" } */
+
+void 
+__attribute__((callback(0, 2, 3)))
+unknown_fn(char (*)(float*, double*), float*, double*, int*); /* { dg-error 
"callback function position cannot be marked as unknown" } */
+
+void
+__attribute__((callback(1, 2)))
+not_a_fn(int, int); /* { dg-error "argument no. 1 is not an address of a 
function" } */
+
+struct S{
+  int x;
+};
+
+void
+__attribute__((callback(1, 2)))
+incompatible_types_1(void (*)(struct S*), struct S); /* { dg-error "argument 
type at index 2 is not compatible with callback argument type at index 1" } */
+
+void
+__attribute__((callback(1, 3, 2)))
+incompatible_types_2(void (*)(struct S*, int*), int*, double); /* { dg-error 
"argument type at index 3 is not compatible with callback argument type at 
index 1" } */
+
+void
+__attribute__((callback(1, "2")))
+wrong_arg_type_1(void (*)(void*), void*); /* { dg-error "argument no. 1 is not 
an integer constant" } */
+
+void
+__attribute__((callback("not a number", 2, 2)))
+wrong_arg_type_2(void (*)(void*, void*), void*); /* { dg-error "argument 
specifying callback function position is not an integer constant" } */
diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-cb1.c 
b/gcc/testsuite/gcc.dg/ipa/ipcp-cb1.c
new file mode 100644
index ..5f672a506f46
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipcp-cb1.c
@@ -0,0 +1,25 @@
+/* Test that we can propagate constants into outlined OpenMP kernels. 
+   This tests the underlying callback attribute and its related edges. */
+
+/* { dg-do run } */
+/* { dg-options "-O3 -fopenmp -flto -std=gnu99 -fdump-ipa-cp-details" } */
+/* { dg-require-effective-target fopenmp } */
+/* { dg-require-effective-target lto } */
+
+int a[100];
+void test(int c) {
+#pragma omp parallel for
+  for (int i = 0; i < c; i++) {
+if (!__builtin_constant_p(c)) {
+  __builtin_abort();
+}
+a[i] = i;
+  }
+}
+int main() {
+  test(100);
+  return a[5] - 5;
+}
+
+/* { dg-final { scan-wpa-ipa-dump "Creating a specialized node of 
test._omp_fn" "cp" } } */
+/* { dg-final { scan-wpa-ipa-dump "Aggregate replacements: 
0\\\[0]=100\\(by_ref\\)" "cp" } } */
diff --git a/gcc/testsuite/gcc.dg/ipa/ipcp-cb2.c 
b/gcc/testsuite/gcc.dg/ipa/ipcp-cb2.c
new file mode 100644
index ..b42c2a09d8bf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/ipcp-cb2.c
@@ -0,0 +1,53 @@
+/* Test that we can handle multiple callback attributes and use them to
+   propagate into callbacks. 'cb1' body borrowed from a ipa-cp test to get the
+   pass to work. *