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>
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];
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])
{
}
END {
- max_number_args = 2;
for (i = 1; i < lineno; i++)
{
ret = parse_line(lines[i], "NEXT_PASS");
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";
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"
}
#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"
#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"
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"