https://gcc.gnu.org/g:f927264935972145bb71f1cdb26263a5446671e1

commit r15-5240-gf927264935972145bb71f1cdb26263a5446671e1
Author: Martin Jambor <mjam...@suse.cz>
Date:   Thu Nov 14 14:42:27 2024 +0100

    ipa: Introduce a one jump function dumping function
    
    I plan to introduce a verifier that prints a single jump function when
    it fails with the function introduced in this one.  Because it is a
    verifier, the risk that it would need to e reverted are non-zero and
    because the function can be useful on its own, this is a special patch
    to introduce it.
    
    gcc/ChangeLog:
    
    2024-11-01  Martin Jambor  <mjam...@suse.cz>
    
            * ipa-prop.h (ipa_dump_jump_function): Declare.
            * ipa-prop.cc (ipa_dump_jump_function): New function.
            (ipa_print_node_jump_functions_for_edge): Move printing of
            individual jump functions to the new function.

Diff:
---
 gcc/ipa-prop.cc | 209 +++++++++++++++++++++++++++++---------------------------
 gcc/ipa-prop.h  |   2 +
 2 files changed, 110 insertions(+), 101 deletions(-)

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index fd18f847e460..2a0d4503f525 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -429,126 +429,133 @@ ipa_print_constant_value (FILE *f, tree val)
     }
 }
 
-/* Print the jump functions associated with call graph edge CS to file F.  */
+/* Print contents of JFUNC to F.  If CTX is non-NULL, dump it too.  */
 
-static void
-ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
+DEBUG_FUNCTION void
+ipa_dump_jump_function (FILE *f, ipa_jump_func *jump_func,
+                       class ipa_polymorphic_call_context *ctx)
 {
-  ipa_edge_args *args = ipa_edge_args_sum->get (cs);
-  int count = ipa_get_cs_argument_count (args);
+  enum jump_func_type type = jump_func->type;
 
-  for (int i = 0; i < count; i++)
+  if (type == IPA_JF_UNKNOWN)
+    fprintf (f, "UNKNOWN\n");
+  else if (type == IPA_JF_CONST)
     {
-      struct ipa_jump_func *jump_func;
-      enum jump_func_type type;
-
-      jump_func = ipa_get_ith_jump_func (args, i);
-      type = jump_func->type;
-
-      fprintf (f, "       param %d: ", i);
-      if (type == IPA_JF_UNKNOWN)
-       fprintf (f, "UNKNOWN\n");
-      else if (type == IPA_JF_CONST)
+      fprintf (f, "CONST: ");
+      ipa_print_constant_value (f, jump_func->value.constant.value);
+      fprintf (f, "\n");
+    }
+  else if (type == IPA_JF_PASS_THROUGH)
+    {
+      fprintf (f, "PASS THROUGH: ");
+      fprintf (f, "%d, op %s",
+              jump_func->value.pass_through.formal_id,
+              get_tree_code_name(jump_func->value.pass_through.operation));
+      if (jump_func->value.pass_through.operation != NOP_EXPR)
        {
-         fprintf (f, "CONST: ");
-         ipa_print_constant_value (f, jump_func->value.constant.value);
-         fprintf (f, "\n");
+         fprintf (f, " ");
+         print_generic_expr (f, jump_func->value.pass_through.operand);
        }
-      else if (type == IPA_JF_PASS_THROUGH)
+      if (jump_func->value.pass_through.agg_preserved)
+       fprintf (f, ", agg_preserved");
+      if (jump_func->value.pass_through.refdesc_decremented)
+       fprintf (f, ", refdesc_decremented");
+      fprintf (f, "\n");
+    }
+  else if (type == IPA_JF_ANCESTOR)
+    {
+      fprintf (f, "ANCESTOR: ");
+      fprintf (f, "%d, offset " HOST_WIDE_INT_PRINT_DEC,
+              jump_func->value.ancestor.formal_id,
+              jump_func->value.ancestor.offset);
+      if (jump_func->value.ancestor.agg_preserved)
+       fprintf (f, ", agg_preserved");
+      if (jump_func->value.ancestor.keep_null)
+       fprintf (f, ", keep_null");
+      fprintf (f, "\n");
+    }
+
+  if (jump_func->agg.items)
+    {
+      struct ipa_agg_jf_item *item;
+      int j;
+
+      fprintf (f, "         Aggregate passed by %s:\n",
+              jump_func->agg.by_ref ? "reference" : "value");
+      FOR_EACH_VEC_ELT (*jump_func->agg.items, j, item)
        {
-         fprintf (f, "PASS THROUGH: ");
-         fprintf (f, "%d, op %s",
-                  jump_func->value.pass_through.formal_id,
-                  get_tree_code_name(jump_func->value.pass_through.operation));
-         if (jump_func->value.pass_through.operation != NOP_EXPR)
+         fprintf (f, "           offset: " HOST_WIDE_INT_PRINT_DEC ", ",
+                  item->offset);
+         fprintf (f, "type: ");
+         print_generic_expr (f, item->type);
+         fprintf (f, ", ");
+         if (item->jftype == IPA_JF_PASS_THROUGH)
+           fprintf (f, "PASS THROUGH: %d,",
+                    item->value.pass_through.formal_id);
+         else if (item->jftype == IPA_JF_LOAD_AGG)
            {
-             fprintf (f, " ");
-             print_generic_expr (f, jump_func->value.pass_through.operand);
+             fprintf (f, "LOAD AGG: %d",
+                      item->value.pass_through.formal_id);
+             fprintf (f, " [offset: " HOST_WIDE_INT_PRINT_DEC ", by %s],",
+                      item->value.load_agg.offset,
+                      item->value.load_agg.by_ref ? "reference"
+                      : "value");
            }
-         if (jump_func->value.pass_through.agg_preserved)
-           fprintf (f, ", agg_preserved");
-         if (jump_func->value.pass_through.refdesc_decremented)
-           fprintf (f, ", refdesc_decremented");
-         fprintf (f, "\n");
-       }
-      else if (type == IPA_JF_ANCESTOR)
-       {
-         fprintf (f, "ANCESTOR: ");
-         fprintf (f, "%d, offset " HOST_WIDE_INT_PRINT_DEC,
-                  jump_func->value.ancestor.formal_id,
-                  jump_func->value.ancestor.offset);
-         if (jump_func->value.ancestor.agg_preserved)
-           fprintf (f, ", agg_preserved");
-         if (jump_func->value.ancestor.keep_null)
-           fprintf (f, ", keep_null");
-         fprintf (f, "\n");
-       }
 
-      if (jump_func->agg.items)
-       {
-         struct ipa_agg_jf_item *item;
-         int j;
-
-         fprintf (f, "         Aggregate passed by %s:\n",
-                  jump_func->agg.by_ref ? "reference" : "value");
-         FOR_EACH_VEC_ELT (*jump_func->agg.items, j, item)
+         if (item->jftype == IPA_JF_PASS_THROUGH
+             || item->jftype == IPA_JF_LOAD_AGG)
            {
-             fprintf (f, "           offset: " HOST_WIDE_INT_PRINT_DEC ", ",
-                      item->offset);
-             fprintf (f, "type: ");
-             print_generic_expr (f, item->type);
-             fprintf (f, ", ");
-             if (item->jftype == IPA_JF_PASS_THROUGH)
-               fprintf (f, "PASS THROUGH: %d,",
-                        item->value.pass_through.formal_id);
-             else if (item->jftype == IPA_JF_LOAD_AGG)
-               {
-                 fprintf (f, "LOAD AGG: %d",
-                          item->value.pass_through.formal_id);
-                 fprintf (f, " [offset: " HOST_WIDE_INT_PRINT_DEC ", by %s],",
-                          item->value.load_agg.offset,
-                          item->value.load_agg.by_ref ? "reference"
-                                                      : "value");
-               }
-
-             if (item->jftype == IPA_JF_PASS_THROUGH
-                 || item->jftype == IPA_JF_LOAD_AGG)
-               {
-                 fprintf (f, " op %s",
-                    get_tree_code_name (item->value.pass_through.operation));
-                 if (item->value.pass_through.operation != NOP_EXPR)
-                   {
-                     fprintf (f, " ");
-                     print_generic_expr (f, item->value.pass_through.operand);
-                   }
-               }
-             else if (item->jftype == IPA_JF_CONST)
+             fprintf (f, " op %s",
+                      get_tree_code_name (item->value.pass_through.operation));
+             if (item->value.pass_through.operation != NOP_EXPR)
                {
-                 fprintf (f, "CONST: ");
-                 ipa_print_constant_value (f, item->value.constant);
+                 fprintf (f, " ");
+                 print_generic_expr (f, item->value.pass_through.operand);
                }
-             else if (item->jftype == IPA_JF_UNKNOWN)
-               fprintf (f, "UNKNOWN: " HOST_WIDE_INT_PRINT_DEC " bits",
-                        tree_to_uhwi (TYPE_SIZE (item->type)));
-             fprintf (f, "\n");
            }
+         else if (item->jftype == IPA_JF_CONST)
+           {
+             fprintf (f, "CONST: ");
+             ipa_print_constant_value (f, item->value.constant);
+           }
+         else if (item->jftype == IPA_JF_UNKNOWN)
+           fprintf (f, "UNKNOWN: " HOST_WIDE_INT_PRINT_DEC " bits",
+                    tree_to_uhwi (TYPE_SIZE (item->type)));
+         fprintf (f, "\n");
        }
+    }
+
+  if (ctx && !ctx->useless_p ())
+    {
+      fprintf (f, "         Context: ");
+      ctx->dump (dump_file);
+    }
+
+  if (jump_func->m_vr)
+    {
+      jump_func->m_vr->dump (f);
+      fprintf (f, "\n");
+    }
+  else
+    fprintf (f, "         Unknown VR\n");
+}
 
+/* Print the jump functions associated with call graph edge CS to file F.  */
+
+static void
+ipa_print_node_jump_functions_for_edge (FILE *f, struct cgraph_edge *cs)
+{
+  ipa_edge_args *args = ipa_edge_args_sum->get (cs);
+  int count = ipa_get_cs_argument_count (args);
+
+  for (int i = 0; i < count; i++)
+    {
+      struct ipa_jump_func *jump_func = ipa_get_ith_jump_func (args, i);
       class ipa_polymorphic_call_context *ctx
        = ipa_get_ith_polymorhic_call_context (args, i);
-      if (ctx && !ctx->useless_p ())
-       {
-         fprintf (f, "         Context: ");
-         ctx->dump (dump_file);
-       }
 
-      if (jump_func->m_vr)
-       {
-         jump_func->m_vr->dump (f);
-         fprintf (f, "\n");
-       }
-      else
-       fprintf (f, "         Unknown VR\n");
+      fprintf (f, "       param %d: ", i);
+      ipa_dump_jump_function (f, jump_func, ctx);
     }
 }
 
diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h
index a9ef3fe3aa60..1ff71aba8304 100644
--- a/gcc/ipa-prop.h
+++ b/gcc/ipa-prop.h
@@ -1248,6 +1248,8 @@ void ipa_push_agg_values_from_jfunc (ipa_node_params 
*info, cgraph_node *node,
                                     unsigned dst_index,
                                     vec<ipa_argagg_value> *res);
 void ipa_dump_param (FILE *, class ipa_node_params *info, int i);
+void ipa_dump_jump_function (FILE *f, ipa_jump_func *jfunc,
+                            class ipa_polymorphic_call_context *ctx = NULL);
 void ipa_release_body_info (struct ipa_func_body_info *);
 tree ipa_get_callee_param_type (struct cgraph_edge *e, int i);
 bool ipcp_get_parm_bits (tree, tree *, widest_int *);

Reply via email to