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>
This commit is contained in:
Andrew Pinski 2024-10-13 15:57:41 -07:00
parent 7f65f94917
commit 061a4e35c8
3 changed files with 20 additions and 17 deletions

View File

@ -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"
}

View File

@ -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"

View File

@ -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"