]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
passes: Allow for second param for NEXT_PASS
authorAndrew Pinski <quic_apinski@quicinc.com>
Sun, 13 Oct 2024 18:09:14 +0000 (11:09 -0700)
committerAndrew Pinski <quic_apinski@quicinc.com>
Mon, 14 Oct 2024 14:32:34 +0000 (07:32 -0700)
Right now we currently only support 1 parameter for each pass in NEXT_PASS.
We also don't error out if someone tries to use more than 1.
This adds support for more than one but only to a max of max_number_args
(which is currently 2).
In the next patch, this will be used for DCE, adding a new parameter.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* gen-pass-instances.awk (END): Handle processing
of multiple arguments to NEXT_PASS. Also error out
if using more than max_number_args (2).
* pass_manager.h (NEXT_PASS_WITH_ARG2): New define.
* passes.cc (NEXT_PASS_WITH_ARG2): New define.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
gcc/gen-pass-instances.awk
gcc/pass_manager.h
gcc/passes.cc

index f56b8072ed5c1c78d6ef1e1d856e728f8f432760..def09347765821f550ec3148f16f8ef19f84d635 100644 (file)
@@ -195,6 +195,7 @@ function replace_pass(line, fnname,                 num, i)
 }
 
 END {
+  max_number_args = 2;
   for (i = 1; i < lineno; i++)
     {
       ret = parse_line(lines[i], "NEXT_PASS");
@@ -202,7 +203,9 @@ END {
        {
          # Set pass_name argument, an optional with_arg argument
          pass_name = args[1];
-         with_arg = args[2];
+         num_args = 0;
+         while (args[num_args + 2])
+           num_args++;
 
          # Set pass_final_counts
          if (pass_name in pass_final_counts)
@@ -214,13 +217,22 @@ END {
 
          # Print call expression with extra pass_num argument
          printf "%s", prefix;
-         if (with_arg)
-           printf "NEXT_PASS_WITH_ARG";
+         if (num_args > 0)
+           {
+             printf "NEXT_PASS_WITH_ARG";
+             if (num_args > max_number_args)
+               {
+                 print "ERROR: Only supports up to " max_number_args " args to NEXT_PASS";
+                 exit 1;
+               }
+             if (num_args != 1)
+               printf num_args;
+           }
          else
            printf "NEXT_PASS";
          printf " (%s, %s", pass_name, pass_num;
-         if (with_arg)
-           printf ",%s", with_arg;
+         for (j = 0; j < num_args; j++)
+           printf ",%s", args[j+2];
          printf ")%s\n", postfix;
 
          continue;
@@ -254,6 +266,8 @@ END {
   print "#undef POP_INSERT_PASSES"
   print "#undef NEXT_PASS"
   print "#undef NEXT_PASS_WITH_ARG"
+  for (i = 2; i <= max_number_args; i++)
+    print "#undef NEXT_PASS_WITH_ARG" i
   print "#undef TERMINATE_PASS_LIST"
 }
 
index 5a78d3fe56b061f14bb6a9574069a732cb6d43e2..f18ae026257a26350b871d76a4ff4dee58cee2af 100644 (file)
@@ -130,6 +130,7 @@ private:
 #define POP_INSERT_PASSES()
 #define NEXT_PASS(PASS, NUM) opt_pass *PASS ## _ ## NUM
 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
+#define NEXT_PASS_WITH_ARG2(PASS, NUM, ARG0, ARG1) NEXT_PASS (PASS, NUM)
 #define TERMINATE_PASS_LIST(PASS)
 
 #include "pass-instances.def"
index 3abae971aceb9fa450b7aca3edd48f6c2ee1fe4e..b5475fce5228f364274361c520c6d89c77eaeeff 100644 (file)
@@ -1589,6 +1589,7 @@ pass_manager::pass_manager (context *ctxt)
 #define POP_INSERT_PASSES()
 #define NEXT_PASS(PASS, NUM) PASS ## _ ## NUM = NULL
 #define NEXT_PASS_WITH_ARG(PASS, NUM, ARG) NEXT_PASS (PASS, NUM)
+#define NEXT_PASS_WITH_ARG2(PASS, NUM, ARG0, ARG1) NEXT_PASS (PASS, NUM)
 #define TERMINATE_PASS_LIST(PASS)
 #include "pass-instances.def"
 
@@ -1635,6 +1636,13 @@ pass_manager::pass_manager (context *ctxt)
       PASS ## _ ## NUM->set_pass_param (0, ARG);       \
     } while (0)
 
+#define NEXT_PASS_WITH_ARG2(PASS, NUM, ARG0, ARG1)     \
+    do {                                               \
+      NEXT_PASS (PASS, NUM);                           \
+      PASS ## _ ## NUM->set_pass_param (0, ARG0);      \
+      PASS ## _ ## NUM->set_pass_param (1, ARG1);      \
+    } while (0)
+
 #include "pass-instances.def"
 
   /* Register the passes with the tree dump code.  */