aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2024-10-13 15:57:41 -0700
committerAndrew Pinski <quic_apinski@quicinc.com>2024-10-15 07:45:01 -0700
commit061a4e35c81f24c6ec5e56214469d229f1808971 (patch)
tree677a6b5eefd8a25033769621e5a135740116295e /gcc
parent7f65f94917866c6b18d9698eec6451c1bf21e0f9 (diff)
downloadgcc-061a4e35c81f24c6ec5e56214469d229f1808971.zip
gcc-061a4e35c81f24c6ec5e56214469d229f1808971.tar.gz
gcc-061a4e35c81f24c6ec5e56214469d229f1808971.tar.bz2
passes: Remove limit on the number of params
Having a limit of 2 params for NEXT_PASS was just done because I didn't think there was a way to handle arbitrary number of params. But I found that we can handle this via a static const variable array (constexpr so we know it is true or false at compile time) and just loop over the array. Note I keep around NEXT_PASS_WITH_ARG and NEXT_PASS macros instead of always using NEXT_PASS_WITH_ARGS macro to make sure these cases get optimized for -O0 (stage1). Tested INSERT_PASS_AFTER/INSERT_PASS_BEFORE manually by changing config/i386/i386-passes.def's stv lines to have a 2nd argument and checked the resuling pass-instances.def to see the NEXT_PASS_WITH_ARGS was correctly done. changes from v1: * v2: Handle INSERT_PASS_AFTER/INSERT_PASS_BEFORE too. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * gen-pass-instances.awk: Remove the limit of the params. * pass_manager.h (NEXT_PASS_WITH_ARG2): Rename to ... (NEXT_PASS_WITH_ARGS): This. * passes.cc (NEXT_PASS_WITH_ARG2): Rename to ... (NEXT_PASS_WITH_ARGS): This and support more than 2 params by using a constexpr array. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gen-pass-instances.awk22
-rw-r--r--gcc/pass_manager.h2
-rw-r--r--gcc/passes.cc13
3 files changed, 20 insertions, 17 deletions
diff --git a/gcc/gen-pass-instances.awk b/gcc/gen-pass-instances.awk
index def0934..1e5b3f0 100644
--- a/gcc/gen-pass-instances.awk
+++ b/gcc/gen-pass-instances.awk
@@ -100,7 +100,7 @@ function adjust_linenos(above, increment, p, i)
lineno += increment;
}
-function insert_remove_pass(line, fnname, arg3)
+function insert_remove_pass(line, fnname, arg3, i)
{
parse_line($0, fnname);
pass_name = args[1];
@@ -110,8 +110,13 @@ function insert_remove_pass(line, fnname, arg3)
arg3 = args[3];
sub(/^[ \t]*/, "", arg3);
new_line = prefix "NEXT_PASS (" arg3;
- if (args[4])
- new_line = new_line "," args[4];
+ # Add the optional params back.
+ i = 4;
+ while (args[i])
+ {
+ new_line = new_line "," args[i];
+ i++;
+ }
new_line = new_line ")" postfix;
if (!pass_lines[pass_name, pass_num])
{
@@ -195,7 +200,6 @@ 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");
@@ -220,13 +224,8 @@ END {
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;
+ printf "S";
}
else
printf "NEXT_PASS";
@@ -266,8 +265,7 @@ 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 NEXT_PASS_WITH_ARGS"
print "#undef TERMINATE_PASS_LIST"
}
diff --git a/gcc/pass_manager.h b/gcc/pass_manager.h
index f18ae02..294cdd0 100644
--- a/gcc/pass_manager.h
+++ b/gcc/pass_manager.h
@@ -130,7 +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 NEXT_PASS_WITH_ARGS(PASS, NUM, ...) NEXT_PASS (PASS, NUM)
#define TERMINATE_PASS_LIST(PASS)
#include "pass-instances.def"
diff --git a/gcc/passes.cc b/gcc/passes.cc
index b5475fc..ae80f40 100644
--- a/gcc/passes.cc
+++ b/gcc/passes.cc
@@ -1589,7 +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 NEXT_PASS_WITH_ARGS(PASS, NUM, ...) NEXT_PASS (PASS, NUM)
#define TERMINATE_PASS_LIST(PASS)
#include "pass-instances.def"
@@ -1636,11 +1636,16 @@ pass_manager::pass_manager (context *ctxt)
PASS ## _ ## NUM->set_pass_param (0, ARG); \
} while (0)
-#define NEXT_PASS_WITH_ARG2(PASS, NUM, ARG0, ARG1) \
+#define NEXT_PASS_WITH_ARGS(PASS, NUM, ...) \
do { \
NEXT_PASS (PASS, NUM); \
- PASS ## _ ## NUM->set_pass_param (0, ARG0); \
- PASS ## _ ## NUM->set_pass_param (1, ARG1); \
+ static constexpr bool values[] = { __VA_ARGS__ }; \
+ unsigned i = 0; \
+ for (bool value : values) \
+ { \
+ PASS ## _ ## NUM->set_pass_param (i, value); \
+ i++; \
+ } \
} while (0)
#include "pass-instances.def"