Alfie Richards <[email protected]> writes:
> Use function to replace manual machine_mode parsing.
>
> gcc/ChangeLog:
>
> * machmode.h (parse_machine_mode): New function.
> * read-rtl.cc (find_mode): Use parse_machine_mode.
> * config/riscv/riscv-v.cc (autovectorize_vector_modes): Likewise.
>
> gcc/c-family/ChangeLog:
>
> * c-attribs.cc (handle_mode_attribute): Use parse_machine_mode.
>
> -- >8 --
>
> This abstracts out the parsing of a machine mode from its name as I needed
> that for my next patch and was surprised not to be able to find it
> .
> I found some manual parsings so switched those to use this new function.
>
> Regression tested and boostrapped on aarch64-linux-gnu,x86-linux-gnu,
> and armhf-linux-gnu.
> Built on riscv, trying to do a bootstrap and will report back if it fails.
>
> Okay for master?
> Alfie
>
> ---
> gcc/c-family/c-attribs.cc | 8 +-------
> gcc/config/riscv/riscv-v.cc | 10 ++++------
> gcc/machmode.h | 12 ++++++++++++
> gcc/read-rtl.cc | 10 ++++------
> 4 files changed, 21 insertions(+), 19 deletions(-)
>
> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
> index ae5c2743ce6..3c0e780669b 100644
> --- a/gcc/c-family/c-attribs.cc
> +++ b/gcc/c-family/c-attribs.cc
> @@ -2429,7 +2429,6 @@ handle_mode_attribute (tree *node, tree name, tree args,
> warning (OPT_Wattributes, "%qE attribute ignored", name);
> else
> {
> - int j;
> const char *p = IDENTIFIER_POINTER (ident);
> int len = strlen (p);
> machine_mode mode = VOIDmode;
> @@ -2461,12 +2460,7 @@ handle_mode_attribute (tree *node, tree name, tree
> args,
> else if (!strcmp (p, "unwind_word"))
> mode = targetm.unwind_word_mode ();
> else
> - for (j = 0; j < NUM_MACHINE_MODES; j++)
> - if (!strcmp (p, GET_MODE_NAME (j)))
> - {
> - mode = (machine_mode) j;
> - break;
> - }
> + parse_machine_mode (p, &mode);
>
> if (mode == VOIDmode)
> {
> diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
> index e50ebdee163..7329ce2c71b 100644
> --- a/gcc/config/riscv/riscv-v.cc
> +++ b/gcc/config/riscv/riscv-v.cc
> @@ -3068,13 +3068,11 @@ autovectorize_vector_modes (vector_modes *modes, bool)
> ms.safe_splice (*modes);
> modes->truncate (0);
>
> - for (machine_mode mode : ms)
> + machine_mode mode;
> + if (parse_machine_mode (riscv_autovec_mode, &mode))
> {
> - if (!strcmp (GET_MODE_NAME (mode), riscv_autovec_mode))
> - {
> - modes->safe_push (mode);
> - return 0;
> - }
> + modes->safe_push (mode);
> + return 0;
> }
>
> /* Nothing found, fall back to regular handling. */
> diff --git a/gcc/machmode.h b/gcc/machmode.h
> index b92b1572d8d..17d6428f9a5 100644
> --- a/gcc/machmode.h
> +++ b/gcc/machmode.h
> @@ -926,6 +926,18 @@ smallest_int_mode_for_size (poly_uint64 size)
> return dyn_cast <scalar_int_mode> (smallest_mode_for_size (size,
> MODE_INT));
> }
>
> +inline bool
> +parse_machine_mode (const char *name, machine_mode *result)
Missing function comment.
OK with that added, thanks (independently of patch 2).
Richard
> +{
> + for (unsigned i = 0; i < NUM_MACHINE_MODES; i++)
> + if (strcmp (GET_MODE_NAME (i), name) == 0)
> + {
> + *result = (machine_mode) i;
> + return true;
> + }
> + return false;
> +}
> +
> extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
> extern opt_machine_mode bitwise_mode_for_mode (machine_mode);
> extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64);
> diff --git a/gcc/read-rtl.cc b/gcc/read-rtl.cc
> index be9f2da37e1..de95d859f78 100644
> --- a/gcc/read-rtl.cc
> +++ b/gcc/read-rtl.cc
> @@ -197,13 +197,11 @@ atoll (const char *p)
> static HOST_WIDE_INT
> find_mode (const char *name)
> {
> - int i;
> -
> - for (i = 0; i < NUM_MACHINE_MODES; i++)
> - if (strcmp (GET_MODE_NAME (i), name) == 0)
> - return i;
> + machine_mode mode;
> + if (!parse_machine_mode (name, &mode))
> + fatal_with_file_and_line ("unknown mode `%s'", name);
>
> - fatal_with_file_and_line ("unknown mode `%s'", name);
> + return (HOST_WIDE_INT) mode;
> }
>
> static void