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.
gcc/ 2016-11-24 Richard Sandiford <richard.sandif...@arm.com> Alan Hayward <alan.hayw...@arm.com> David Sherwood <david.sherw...@arm.com> * 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/ 2016-11-24 Richard Sandiford <richard.sandif...@arm.com> Alan Hayward <alan.hayw...@arm.com> David Sherwood <david.sherw...@arm.com> * gcc-interface/misc.c (fp_prec_to_size): Use opt_scalar_float_mode. (fp_size_to_prec): Likewise. gcc/c-family/ 2016-11-24 Richard Sandiford <richard.sandif...@arm.com> Alan Hayward <alan.hayw...@arm.com> David Sherwood <david.sherw...@arm.com> * c-cppbuiltin.c (c_cpp_builtins): Use opt_scalar_float_mode. gcc/fortran/ 2016-11-24 Richard Sandiford <richard.sandif...@arm.com> Alan Hayward <alan.hayw...@arm.com> David Sherwood <david.sherw...@arm.com> * trans-types.c (gfc_init_kinds): Use opt_scalar_float_mode and FOR_EACH_MODE_IN_CLASS. diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c index 4bb22ed..cef8d84 100644 --- a/gcc/ada/gcc-interface/misc.c +++ b/gcc/ada/gcc-interface/misc.c @@ -1278,11 +1278,11 @@ 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 mode; FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) - if (GET_MODE_PRECISION (mode) == prec) - return GET_MODE_BITSIZE (mode); + if (GET_MODE_PRECISION (*mode) == prec) + return GET_MODE_BITSIZE (*mode); gcc_unreachable (); } @@ -1292,11 +1292,11 @@ fp_prec_to_size (int prec) int fp_size_to_prec (int size) { - machine_mode mode; + opt_scalar_float_mode mode; FOR_EACH_MODE_IN_CLASS (mode, MODE_FLOAT) - if (GET_MODE_BITSIZE (mode) == size) - return GET_MODE_PRECISION (mode); + if (GET_MODE_BITSIZE (*mode) == size) + return GET_MODE_PRECISION (*mode); gcc_unreachable (); } diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c index 0d6f538..32a999a 100644 --- a/gcc/c-family/c-cppbuiltin.c +++ b/gcc/c-family/c-cppbuiltin.c @@ -1184,9 +1184,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; 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 a3a3e86..d277a88 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -110,7 +110,6 @@ void init_expr_target (void) { rtx pat; - machine_mode mode; int num_clobbers; rtx mem, mem1; rtx reg; @@ -129,7 +128,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_enum) ((int) mode + 1)) { int regno; @@ -175,9 +174,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; + scalar_float_mode srcmode; FOR_EACH_MODE_UNTIL (srcmode, mode) { enum insn_code ic; diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c index c0d1a17..4c69237 100644 --- a/gcc/fortran/trans-types.c +++ b/gcc/fortran/trans-types.c @@ -348,6 +348,7 @@ void gfc_init_kinds (void) { machine_mode_enum 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; @@ -403,9 +404,10 @@ 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_enum) ((int) mode + 1)) + r_index = 0; + FOR_EACH_MODE_IN_CLASS (float_mode_iter, MODE_FLOAT) { + scalar_float_mode mode = *float_mode_iter; const struct real_format *fmt = REAL_MODE_FORMAT (mode); int kind; diff --git a/gcc/machmode.h b/gcc/machmode.h index 41a3a00..2f4b076 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -628,6 +628,16 @@ namespace mode_iterator { /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */ + template<typename T> + inline void + start (opt_mode<T> *iter, enum mode_class mclass) + { + if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode) + *iter = opt_mode<T> (); + else + *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass)); + } + inline void start (machine_mode *iter, enum mode_class mclass) { @@ -636,6 +646,13 @@ namespace mode_iterator /* Return true if mode iterator *ITER has not reached the end. */ + template<typename T> + inline bool + iterate_p (opt_mode<T> *iter) + { + return iter->exists (); + } + inline bool iterate_p (machine_mode *iter) { @@ -645,6 +662,13 @@ namespace mode_iterator /* Set mode iterator *ITER to the next widest mode in the same class, if any. */ + template<typename T> + inline void + get_wider (opt_mode<T> *iter) + { + *iter = GET_MODE_WIDER_MODE (**iter); + } + inline void get_wider (machine_mode *iter) {