This patch adds a scalar_mode class that can hold any scalar mode, specifically:
- scalar integers - scalar floating-point values - scalar fractional modes - scalar accumulator modes - pointer bounds modes To start with this patch uses this type for GET_MODE_INNER. Later patches add more uses. 2017-07-13 Richard Sandiford <richard.sandif...@linaro.org> Alan Hayward <alan.hayw...@arm.com> David Sherwood <david.sherw...@arm.com> gcc/ * coretypes.h (scalar_mode): New class. * machmode.h (scalar_mode): Likewise. (scalar_mode::includes_p): New function. (mode_to_inner): Return a scalar_mode rather than a machine_mode. * gdbhooks.py (build_pretty_printers): Handle scalar_mode. * genmodes.c (get_mode_class): Handle remaining scalar modes. * cfgexpand.c (expand_debug_expr): Use scalar_mode. * expmed.c (store_bit_field_1): Likewise. (extract_bit_field_1): Likewise. * expr.c (write_complex_part): Likewise. (read_complex_part): Likewise. (emit_move_complex_push): Likewise. (expand_expr_real_2): Likewise. * function.c (assign_parm_setup_reg): Likewise. (assign_parms_unsplit_complex): Likewise. * optabs.c (expand_binop): Likewise. * rtlanal.c (subreg_get_info): Likewise. * simplify-rtx.c (simplify_immed_subreg): Likewise. * varasm.c (output_constant_pool_2): Likewise. Index: gcc/coretypes.h =================================================================== --- gcc/coretypes.h 2017-07-13 09:18:28.587718194 +0100 +++ gcc/coretypes.h 2017-07-13 09:18:53.271650545 +0100 @@ -55,6 +55,7 @@ typedef const struct simple_bitmap_def * struct rtx_def; typedef struct rtx_def *rtx; typedef const struct rtx_def *const_rtx; +class scalar_mode; class scalar_int_mode; class scalar_float_mode; template<typename> class opt_mode; @@ -317,6 +318,7 @@ #define rtx_insn struct _dont_use_rtx_in #define tree union _dont_use_tree_here_ * #define const_tree union _dont_use_tree_here_ * +typedef struct scalar_mode scalar_mode; typedef struct scalar_int_mode scalar_int_mode; typedef struct scalar_float_mode scalar_float_mode; Index: gcc/machmode.h =================================================================== --- gcc/machmode.h 2017-07-13 09:18:41.680558844 +0100 +++ gcc/machmode.h 2017-07-13 09:18:53.274650323 +0100 @@ -410,6 +410,47 @@ scalar_float_mode::includes_p (machine_m return SCALAR_FLOAT_MODE_P (m); } +/* Represents a machine mode that is known to be scalar. */ +class scalar_mode +{ +public: + typedef mode_traits<scalar_mode>::from_int from_int; + + ALWAYS_INLINE scalar_mode () {} + ALWAYS_INLINE scalar_mode (from_int m) : m_mode (machine_mode (m)) {} + ALWAYS_INLINE scalar_mode (const scalar_int_mode &m) : m_mode (m) {} + ALWAYS_INLINE scalar_mode (const scalar_float_mode &m) : m_mode (m) {} + ALWAYS_INLINE scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {} + ALWAYS_INLINE operator machine_mode () const { return m_mode; } + + static bool includes_p (machine_mode); + +protected: + machine_mode m_mode; +}; + +/* Return true if M represents some kind of scalar value. */ + +inline bool +scalar_mode::includes_p (machine_mode m) +{ + switch (GET_MODE_CLASS (m)) + { + case MODE_INT: + case MODE_PARTIAL_INT: + case MODE_FRACT: + case MODE_UFRACT: + case MODE_ACCUM: + case MODE_UACCUM: + case MODE_FLOAT: + case MODE_DECIMAL_FLOAT: + case MODE_POINTER_BOUNDS: + return true; + default: + return false; + } +} + /* Return the base GET_MODE_SIZE value for MODE. */ ALWAYS_INLINE unsigned short @@ -441,14 +482,15 @@ mode_to_precision (machine_mode mode) /* Return the base GET_MODE_INNER value for MODE. */ -ALWAYS_INLINE machine_mode +ALWAYS_INLINE scalar_mode mode_to_inner (machine_mode mode) { #if GCC_VERSION >= 4001 - return (machine_mode) (__builtin_constant_p (mode) - ? mode_inner_inline (mode) : mode_inner[mode]); + return scalar_mode::from_int (__builtin_constant_p (mode) + ? mode_inner_inline (mode) + : mode_inner[mode]); #else - return (machine_mode) mode_inner[mode]; + return scalar_mode::from_int (mode_inner[mode]); #endif } Index: gcc/gdbhooks.py =================================================================== --- gcc/gdbhooks.py 2017-07-13 09:18:28.587718194 +0100 +++ gcc/gdbhooks.py 2017-07-13 09:18:53.273650396 +0100 @@ -549,7 +549,7 @@ def build_pretty_printer(): 'pod_mode', MachineModePrinter) pp.add_printer_for_types(['scalar_int_mode_pod'], 'pod_mode', MachineModePrinter) - for mode in 'scalar_int_mode', 'scalar_float_mode': + for mode in 'scalar_mode', 'scalar_int_mode', 'scalar_float_mode': pp.add_printer_for_types([mode], mode, MachineModePrinter) return pp Index: gcc/genmodes.c =================================================================== --- gcc/genmodes.c 2017-07-13 09:18:28.587718194 +0100 +++ gcc/genmodes.c 2017-07-13 09:18:53.274650323 +0100 @@ -1141,6 +1141,13 @@ get_mode_class (struct mode_data *mode) case MODE_PARTIAL_INT: return "scalar_int_mode"; + case MODE_FRACT: + case MODE_UFRACT: + case MODE_ACCUM: + case MODE_UACCUM: + case MODE_POINTER_BOUNDS: + return "scalar_mode"; + case MODE_FLOAT: case MODE_DECIMAL_FLOAT: return "scalar_float_mode"; Index: gcc/cfgexpand.c =================================================================== --- gcc/cfgexpand.c 2017-07-13 09:18:51.574777404 +0100 +++ gcc/cfgexpand.c 2017-07-13 09:18:53.271650545 +0100 @@ -4821,7 +4821,7 @@ expand_debug_expr (tree exp) GET_MODE_INNER (mode))); else { - machine_mode imode = GET_MODE_INNER (mode); + scalar_mode imode = GET_MODE_INNER (mode); rtx re, im; if (MEM_P (op0)) Index: gcc/expmed.c =================================================================== --- gcc/expmed.c 2017-07-13 09:18:52.815684419 +0100 +++ gcc/expmed.c 2017-07-13 09:18:53.272650471 +0100 @@ -758,16 +758,16 @@ store_bit_field_1 (rtx str_rtx, unsigned /* Use vec_set patterns for inserting parts of vectors whenever available. */ - if (VECTOR_MODE_P (GET_MODE (op0)) + machine_mode outermode = GET_MODE (op0); + scalar_mode innermode = GET_MODE_INNER (outermode); + if (VECTOR_MODE_P (outermode) && !MEM_P (op0) - && optab_handler (vec_set_optab, GET_MODE (op0)) != CODE_FOR_nothing - && fieldmode == GET_MODE_INNER (GET_MODE (op0)) - && bitsize == GET_MODE_UNIT_BITSIZE (GET_MODE (op0)) - && !(bitnum % GET_MODE_UNIT_BITSIZE (GET_MODE (op0)))) + && optab_handler (vec_set_optab, outermode) != CODE_FOR_nothing + && fieldmode == innermode + && bitsize == GET_MODE_BITSIZE (innermode) + && !(bitnum % GET_MODE_BITSIZE (innermode))) { struct expand_operand ops[3]; - machine_mode outermode = GET_MODE (op0); - machine_mode innermode = GET_MODE_INNER (outermode); enum insn_code icode = optab_handler (vec_set_optab, outermode); int pos = bitnum / GET_MODE_BITSIZE (innermode); @@ -1616,15 +1616,15 @@ extract_bit_field_1 (rtx str_rtx, unsign /* Use vec_extract patterns for extracting parts of vectors whenever available. */ - if (VECTOR_MODE_P (GET_MODE (op0)) + machine_mode outermode = GET_MODE (op0); + scalar_mode innermode = GET_MODE_INNER (outermode); + if (VECTOR_MODE_P (outermode) && !MEM_P (op0) - && optab_handler (vec_extract_optab, GET_MODE (op0)) != CODE_FOR_nothing - && ((bitnum + bitsize - 1) / GET_MODE_UNIT_BITSIZE (GET_MODE (op0)) - == bitnum / GET_MODE_UNIT_BITSIZE (GET_MODE (op0)))) + && optab_handler (vec_extract_optab, outermode) != CODE_FOR_nothing + && ((bitnum + bitsize - 1) / GET_MODE_BITSIZE (innermode) + == bitnum / GET_MODE_BITSIZE (innermode))) { struct expand_operand ops[3]; - machine_mode outermode = GET_MODE (op0); - machine_mode innermode = GET_MODE_INNER (outermode); enum insn_code icode = optab_handler (vec_extract_optab, outermode); unsigned HOST_WIDE_INT pos = bitnum / GET_MODE_BITSIZE (innermode); Index: gcc/expr.c =================================================================== --- gcc/expr.c 2017-07-13 09:18:51.653771449 +0100 +++ gcc/expr.c 2017-07-13 09:18:53.273650396 +0100 @@ -3114,7 +3114,7 @@ set_storage_via_setmem (rtx object, rtx write_complex_part (rtx cplx, rtx val, bool imag_p) { machine_mode cmode; - machine_mode imode; + scalar_mode imode; unsigned ibitsize; if (GET_CODE (cplx) == CONCAT) @@ -3175,7 +3175,8 @@ write_complex_part (rtx cplx, rtx val, b rtx read_complex_part (rtx cplx, bool imag_p) { - machine_mode cmode, imode; + machine_mode cmode; + scalar_mode imode; unsigned ibitsize; if (GET_CODE (cplx) == CONCAT) @@ -3371,7 +3372,7 @@ emit_move_resolve_push (machine_mode mod rtx_insn * emit_move_complex_push (machine_mode mode, rtx x, rtx y) { - machine_mode submode = GET_MODE_INNER (mode); + scalar_mode submode = GET_MODE_INNER (mode); bool imag_first; #ifdef PUSH_ROUNDING @@ -9328,7 +9329,7 @@ #define REDUCE_BIT_FIELD(expr) (reduce_b GET_MODE_INNER (GET_MODE (target)), 0); if (reg_overlap_mentioned_p (temp, op1)) { - machine_mode imode = GET_MODE_INNER (GET_MODE (target)); + scalar_mode imode = GET_MODE_INNER (GET_MODE (target)); temp = adjust_address_nv (target, imode, GET_MODE_SIZE (imode)); if (reg_overlap_mentioned_p (temp, op0)) Index: gcc/function.c =================================================================== --- gcc/function.c 2017-07-13 09:18:39.589733813 +0100 +++ gcc/function.c 2017-07-13 09:18:53.273650396 +0100 @@ -3372,8 +3372,7 @@ assign_parm_setup_reg (struct assign_par /* Mark complex types separately. */ if (GET_CODE (parmreg) == CONCAT) { - machine_mode submode - = GET_MODE_INNER (GET_MODE (parmreg)); + scalar_mode submode = GET_MODE_INNER (GET_MODE (parmreg)); int regnor = REGNO (XEXP (parmreg, 0)); int regnoi = REGNO (XEXP (parmreg, 1)); rtx stackr = adjust_address_nv (data->stack_parm, submode, 0); @@ -3510,7 +3509,7 @@ assign_parms_unsplit_complex (struct ass && targetm.calls.split_complex_arg (TREE_TYPE (parm))) { rtx tmp, real, imag; - machine_mode inner = GET_MODE_INNER (DECL_MODE (parm)); + scalar_mode inner = GET_MODE_INNER (DECL_MODE (parm)); real = DECL_RTL (fnargs[i]); imag = DECL_RTL (fnargs[i + 1]); Index: gcc/optabs.c =================================================================== --- gcc/optabs.c 2017-07-13 09:18:51.661770846 +0100 +++ gcc/optabs.c 2017-07-13 09:18:53.274650323 +0100 @@ -1229,7 +1229,7 @@ expand_binop (machine_mode mode, optab b { /* The scalar may have been extended to be too wide. Truncate it back to the proper size to fit in the broadcast vector. */ - machine_mode inner_mode = GET_MODE_INNER (mode); + scalar_mode inner_mode = GET_MODE_INNER (mode); if (!CONST_INT_P (op1) && (GET_MODE_BITSIZE (as_a <scalar_int_mode> (GET_MODE (op1))) > GET_MODE_BITSIZE (inner_mode))) Index: gcc/rtlanal.c =================================================================== --- gcc/rtlanal.c 2017-07-13 09:18:51.664770620 +0100 +++ gcc/rtlanal.c 2017-07-13 09:18:53.275650248 +0100 @@ -3645,7 +3645,7 @@ subreg_get_info (unsigned int xregno, ma { nregs_xmode = HARD_REGNO_NREGS_WITH_PADDING (xregno, xmode); unsigned int nunits = GET_MODE_NUNITS (xmode); - machine_mode xmode_unit = GET_MODE_INNER (xmode); + scalar_mode xmode_unit = GET_MODE_INNER (xmode); gcc_assert (HARD_REGNO_NREGS_HAS_PADDING (xregno, xmode_unit)); gcc_assert (nregs_xmode == (nunits Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2017-07-13 09:18:48.356023575 +0100 +++ gcc/simplify-rtx.c 2017-07-13 09:18:53.276650175 +0100 @@ -5719,7 +5719,7 @@ simplify_immed_subreg (machine_mode oute rtx result_s = NULL; rtvec result_v = NULL; enum mode_class outer_class; - machine_mode outer_submode; + scalar_mode outer_submode; int max_bitsize; /* Some ports misuse CCmode. */ Index: gcc/varasm.c =================================================================== --- gcc/varasm.c 2017-07-13 09:18:38.669811945 +0100 +++ gcc/varasm.c 2017-07-13 09:18:53.276650175 +0100 @@ -3852,7 +3852,7 @@ output_constant_pool_2 (machine_mode mod case MODE_VECTOR_UACCUM: { int i, units; - machine_mode submode = GET_MODE_INNER (mode); + scalar_mode submode = GET_MODE_INNER (mode); unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode)); gcc_assert (GET_CODE (x) == CONST_VECTOR);