From 5c20c4af29da29d2bb74b1fdf3c116f564431878 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 30 Aug 2017 11:09:48 +0000 Subject: [PATCH] [12/77] Use opt_scalar_float_mode when iterating over float modes This means that we know when accessing the modes that the size is a compile-time constant, even for SVE. It also enables stricter type safety in later patches. 2017-08-30 Richard Sandiford Alan Hayward David Sherwood gcc/ * machmode.h (mode_iterator::start): Provide overload for opt_modes. (mode_iterator::iterate_p): Likewise. (mode_iterator::get_wider): Likewise. * expr.c (init_expr_target): Use opt_scalar_float_mode. gcc/ada/ * gcc-interface/misc.c (fp_prec_to_size): Use opt_scalar_float_mode. (fp_size_to_prec): Likewise. gcc/c-family/ * c-cppbuiltin.c (c_cpp_builtins): Use opt_scalar_float_mode. gcc/fortran/ * trans-types.c (gfc_init_kinds): Use opt_scalar_float_mode and FOR_EACH_MODE_IN_CLASS. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r251464 --- gcc/ChangeLog | 9 +++++++++ gcc/ada/ChangeLog | 7 +++++++ gcc/ada/gcc-interface/misc.c | 22 ++++++++++++++-------- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-cppbuiltin.c | 5 +++-- gcc/expr.c | 9 +++++---- gcc/fortran/ChangeLog | 7 +++++++ gcc/fortran/trans-types.c | 12 ++++++------ gcc/machmode.h | 24 ++++++++++++++++++++++++ 9 files changed, 81 insertions(+), 20 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8b74bc783c9..f5fb5fc0f63 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-08-30 Richard Sandiford + Alan Hayward + David Sherwood + + * machmode.h (mode_iterator::start): Provide overload for opt_modes. + (mode_iterator::iterate_p): Likewise. + (mode_iterator::get_wider): Likewise. + * expr.c (init_expr_target): Use opt_scalar_float_mode. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 9aab1314575..80242114224 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2017-08-30 Richard Sandiford + Alan Hayward + David Sherwood + + * gcc-interface/misc.c (fp_prec_to_size): Use opt_scalar_float_mode. + (fp_size_to_prec): Likewise. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index eaacabd5dcf..081a63ab0d0 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -1311,11 +1311,14 @@ enumerate_modes (void (*f) (const char *, int, int, int, int, int, int, int)) int fp_prec_to_size (int prec) { - machine_mode mode; + opt_scalar_float_mode opt_mode; - FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) - if (GET_MODE_PRECISION (mode) == prec) - return GET_MODE_BITSIZE (mode); + FOR_EACH_MODE_IN_CLASS (opt_mode, MODE_FLOAT) + { + scalar_float_mode mode = opt_mode.require (); + if (GET_MODE_PRECISION (mode) == prec) + return GET_MODE_BITSIZE (mode); + } gcc_unreachable (); } @@ -1325,11 +1328,14 @@ fp_prec_to_size (int prec) int fp_size_to_prec (int size) { - machine_mode mode; + opt_scalar_float_mode opt_mode; - FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) - if (GET_MODE_BITSIZE (mode) == size) - return GET_MODE_PRECISION (mode); + FOR_EACH_MODE_IN_CLASS (opt_mode, MODE_FLOAT) + { + scalar_mode mode = opt_mode.require (); + if (GET_MODE_BITSIZE (mode) == size) + return GET_MODE_PRECISION (mode); + } gcc_unreachable (); } diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 44857d6197b..36413cfca74 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2017-08-30 Richard Sandiford + Alan Hayward + David Sherwood + + * c-cppbuiltin.c (c_cpp_builtins): Use opt_scalar_float_mode. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 4f397a18f45..8f377f698a6 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -1186,9 +1186,10 @@ c_cpp_builtins (cpp_reader *pfile) if (flag_building_libgcc) { /* Properties of floating-point modes for libgcc2.c. */ - machine_mode mode; - FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) + opt_scalar_float_mode mode_iter; + FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT) { + scalar_float_mode mode = mode_iter.require (); const char *name = GET_MODE_NAME (mode); char *macro_name = (char *) alloca (strlen (name) diff --git a/gcc/expr.c b/gcc/expr.c index 0219045f9ff..c5cc0cbc155 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -112,7 +112,6 @@ void init_expr_target (void) { rtx pat; - machine_mode mode; int num_clobbers; rtx mem, mem1; rtx reg; @@ -131,7 +130,7 @@ init_expr_target (void) pat = gen_rtx_SET (NULL_RTX, NULL_RTX); PATTERN (insn) = pat; - for (mode = VOIDmode; (int) mode < NUM_MACHINE_MODES; + for (machine_mode mode = VOIDmode; (int) mode < NUM_MACHINE_MODES; mode = (machine_mode) ((int) mode + 1)) { int regno; @@ -177,9 +176,11 @@ init_expr_target (void) mem = gen_rtx_MEM (VOIDmode, gen_raw_REG (Pmode, LAST_VIRTUAL_REGISTER + 1)); - FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) + opt_scalar_float_mode mode_iter; + FOR_EACH_MODE_IN_CLASS (mode_iter, MODE_FLOAT) { - machine_mode srcmode; + scalar_float_mode mode = mode_iter.require (); + scalar_float_mode srcmode; FOR_EACH_MODE_UNTIL (srcmode, mode) { enum insn_code ic; diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 6baf74f27bb..c7a75341d12 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,10 @@ +2017-08-30 Richard Sandiford + Alan Hayward + David Sherwood + + * trans-types.c (gfc_init_kinds): Use opt_scalar_float_mode + and FOR_EACH_MODE_IN_CLASS. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index 7d2d274d3ba..282218fd656 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -364,6 +364,7 @@ void gfc_init_kinds (void) { machine_mode mode; + opt_scalar_float_mode float_mode_iter; int i_index, r_index, kind; bool saw_i4 = false, saw_i8 = false; bool saw_r4 = false, saw_r8 = false, saw_r10 = false, saw_r16 = false; @@ -419,11 +420,11 @@ gfc_init_kinds (void) /* Set the maximum integer kind. Used with at least BOZ constants. */ gfc_max_integer_kind = gfc_integer_kinds[i_index - 1].kind; - for (r_index = 0, mode = MIN_MODE_FLOAT; mode <= MAX_MODE_FLOAT; - mode = (machine_mode) ((int) mode + 1)) + r_index = 0; + FOR_EACH_MODE_IN_CLASS (float_mode_iter, MODE_FLOAT) { - const struct real_format *fmt = - REAL_MODE_FORMAT (mode); + scalar_float_mode mode = float_mode_iter.require (); + const struct real_format *fmt = REAL_MODE_FORMAT (mode); int kind; if (fmt == NULL) @@ -434,8 +435,7 @@ gfc_init_kinds (void) /* Only let float, double, long double and __float128 go through. Runtime support for others is not provided, so they would be useless. */ - if (!targetm.libgcc_floating_mode_supported_p ((machine_mode) - mode)) + if (!targetm.libgcc_floating_mode_supported_p (mode)) continue; if (mode != TYPE_MODE (float_type_node) && (mode != TYPE_MODE (double_type_node)) diff --git a/gcc/machmode.h b/gcc/machmode.h index aa931f59c50..2603d838d93 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -651,6 +651,16 @@ namespace mode_iterator { /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */ + template + inline void + start (opt_mode *iter, enum mode_class mclass) + { + if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode) + *iter = opt_mode (); + else + *iter = as_a (GET_CLASS_NARROWEST_MODE (mclass)); + } + inline void start (machine_mode *iter, enum mode_class mclass) { @@ -659,6 +669,13 @@ namespace mode_iterator /* Return true if mode iterator *ITER has not reached the end. */ + template + inline bool + iterate_p (opt_mode *iter) + { + return iter->exists (); + } + inline bool iterate_p (machine_mode *iter) { @@ -668,6 +685,13 @@ namespace mode_iterator /* Set mode iterator *ITER to the next widest mode in the same class, if any. */ + template + inline void + get_wider (opt_mode *iter) + { + *iter = GET_MODE_WIDER_MODE (iter->require ()); + } + inline void get_wider (machine_mode *iter) { -- 2.30.2