genmatch: Avoid unused parameter warnings in generated code.
authorRoger Sayle <roger@nextmovesoftware.com>
Mon, 3 Aug 2020 12:10:45 +0000 (13:10 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Mon, 3 Aug 2020 12:11:55 +0000 (13:11 +0100)
This patch silences a number of unused parameter warnings whilst
compiling both generic-match.c and gimple-match.c.  The problem is
that multiple (polymorphic) functions are generated for generic_simplify
and gimple_simplify, each handling tree codes with a specific number
of children.  Currently, there are no simplifications for tree codes
with four or five children, leading to functions with "empty" bodies
and unused function arguments.  This patch detects those cases, and
generates stub functions (with anonymous arguments) to silence these
warnings.

2020-08-03  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* genmatch.c (decision_tree::gen): Emit stub functions for
tree code operand counts that have no simplifications.
(main): Correct comment typo.

gcc/genmatch.c

index 109dce2d4699030108c293f95944bccf83e78fac..4e13bc515796616f8cccfa8ad0b147134be90929 100644 (file)
@@ -3803,6 +3803,8 @@ decision_tree::gen (FILE *f, bool gimple)
 
   for (unsigned n = 1; n <= 5; ++n)
     {
+      bool has_kids_p = false;
+
       /* First generate split-out functions.  */
       for (unsigned j = 0; j < root->kids.length (); j++)
        {
@@ -3841,6 +3843,32 @@ decision_tree::gen (FILE *f, bool gimple)
          else
            fprintf (f, "  return NULL_TREE;\n");
          fprintf (f, "}\n");
+         has_kids_p = true;
+       }
+
+      /* If this main entry has no children, avoid generating code
+        with compiler warnings, by generating a simple stub.  */
+      if (! has_kids_p)
+       {
+         if (gimple)
+           fprintf (f, "\nstatic bool\n"
+                       "gimple_simplify (gimple_match_op*, gimple_seq*,\n"
+                       "                 tree (*)(tree), code_helper,\n"
+                       "                 const tree");
+         else
+           fprintf (f, "\ntree\n"
+                       "generic_simplify (location_t, enum tree_code,\n"
+                       "                  const tree");
+         for (unsigned i = 0; i < n; ++i)
+           fprintf (f, ", tree");
+         fprintf (f, ")\n");
+         fprintf (f, "{\n");
+         if (gimple)
+           fprintf (f, "  return false;\n");
+         else
+           fprintf (f, "  return NULL_TREE;\n");
+         fprintf (f, "}\n");
+         continue;
        }
 
       /* Then generate the main entry with the outermost switch and
@@ -5079,7 +5107,7 @@ round_alloc_size (size_t s)
 }
 
 
-/* The genmatch generator progam.  It reads from a pattern description
+/* The genmatch generator program.  It reads from a pattern description
    and outputs GIMPLE or GENERIC IL matching and simplification routines.  */
 
 int