Message ID | 20241014022201.1011677-2-quic_apinski@quicinc.com |
---|---|
State | New |
Headers | show |
Series | [1/5] passes: Move #undef to pass-instances.def | expand |
On Mon, Oct 14, 2024 at 4:25 AM Andrew Pinski <quic_apinski@quicinc.com> wrote: > > 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. OK > 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 | 24 +++++++++++++++++++----- > gcc/pass_manager.h | 1 + > gcc/passes.cc | 8 ++++++++ > 3 files changed, 28 insertions(+), 5 deletions(-) > > diff --git a/gcc/gen-pass-instances.awk b/gcc/gen-pass-instances.awk > index f56b8072ed5..def09347765 100644 > --- a/gcc/gen-pass-instances.awk > +++ b/gcc/gen-pass-instances.awk > @@ -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" > } > > diff --git a/gcc/pass_manager.h b/gcc/pass_manager.h > index 5a78d3fe56b..f18ae026257 100644 > --- a/gcc/pass_manager.h > +++ b/gcc/pass_manager.h > @@ -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" > diff --git a/gcc/passes.cc b/gcc/passes.cc > index 3abae971ace..b5475fce522 100644 > --- a/gcc/passes.cc > +++ b/gcc/passes.cc > @@ -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. */ > -- > 2.43.0 >
diff --git a/gcc/gen-pass-instances.awk b/gcc/gen-pass-instances.awk index f56b8072ed5..def09347765 100644 --- a/gcc/gen-pass-instances.awk +++ b/gcc/gen-pass-instances.awk @@ -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" } diff --git a/gcc/pass_manager.h b/gcc/pass_manager.h index 5a78d3fe56b..f18ae026257 100644 --- a/gcc/pass_manager.h +++ b/gcc/pass_manager.h @@ -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" diff --git a/gcc/passes.cc b/gcc/passes.cc index 3abae971ace..b5475fce522 100644 --- a/gcc/passes.cc +++ b/gcc/passes.cc @@ -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. */
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 | 24 +++++++++++++++++++----- gcc/pass_manager.h | 1 + gcc/passes.cc | 8 ++++++++ 3 files changed, 28 insertions(+), 5 deletions(-)