From: Richard Sandiford Date: Wed, 30 Aug 2017 11:19:17 +0000 (+0000) Subject: [64/77] Add a scalar_mode class X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d21cefc26f716395b03e3c0d379ecac04656f963;p=gcc.git [64/77] Add a scalar_mode class 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-08-30 Richard Sandiford Alan Hayward David Sherwood 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. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r251515 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0ddf5d9f851..d9895f36e9e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,27 @@ +2017-08-30 Richard Sandiford + Alan Hayward + David Sherwood + + * 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. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index a32f7648d41..7f5c97bfc7c 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -4823,7 +4823,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)) diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 37c836d87fa..a9f105ceeef 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -55,6 +55,7 @@ typedef const struct simple_bitmap_def *const_sbitmap; 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 class opt_mode; @@ -317,6 +318,7 @@ union _dont_use_tree_here_; #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; diff --git a/gcc/expmed.c b/gcc/expmed.c index 10cf59c5c2e..f38fb317770 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -761,16 +761,16 @@ store_bit_field_1 (rtx str_rtx, unsigned HOST_WIDE_INT bitsize, /* 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); @@ -1672,17 +1672,16 @@ extract_bit_field_1 (rtx str_rtx, unsigned HOST_WIDE_INT bitsize, /* 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) - && (convert_optab_handler (vec_extract_optab, GET_MODE (op0), - GET_MODE_INNER (GET_MODE (op0))) + && (convert_optab_handler (vec_extract_optab, outermode, innermode) != CODE_FOR_nothing) - && ((bitnum + bitsize - 1) / GET_MODE_UNIT_BITSIZE (GET_MODE (op0)) - == bitnum / GET_MODE_UNIT_BITSIZE (GET_MODE (op0)))) + && ((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 = convert_optab_handler (vec_extract_optab, outermode, innermode); unsigned HOST_WIDE_INT pos = bitnum / GET_MODE_BITSIZE (innermode); diff --git a/gcc/expr.c b/gcc/expr.c index fcad2e39445..71a81ef1f30 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -3115,7 +3115,7 @@ void 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) @@ -3176,7 +3176,8 @@ write_complex_part (rtx cplx, rtx val, bool imag_p) 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) @@ -3372,7 +3373,7 @@ emit_move_resolve_push (machine_mode mode, rtx x) 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 @@ -9335,7 +9336,7 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode, 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)) diff --git a/gcc/function.c b/gcc/function.c index 8e8291edc55..af5e050b8a6 100644 --- a/gcc/function.c +++ b/gcc/function.c @@ -3365,8 +3365,7 @@ assign_parm_setup_reg (struct assign_parm_data_all *all, tree parm, /* 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); @@ -3503,7 +3502,7 @@ assign_parms_unsplit_complex (struct assign_parm_data_all *all, && 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]); diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py index 678698df9c8..8799e3fbfd9 100644 --- a/gcc/gdbhooks.py +++ b/gcc/gdbhooks.py @@ -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 diff --git a/gcc/genmodes.c b/gcc/genmodes.c index 3eb9b44c74b..ab3f999c999 100644 --- a/gcc/genmodes.c +++ b/gcc/genmodes.c @@ -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"; diff --git a/gcc/machmode.h b/gcc/machmode.h index 5f3e031324e..4586d62b81a 100644 --- a/gcc/machmode.h +++ b/gcc/machmode.h @@ -409,6 +409,47 @@ scalar_float_mode::includes_p (machine_mode m) return SCALAR_FLOAT_MODE_P (m); } +/* Represents a machine mode that is known to be scalar. */ +class scalar_mode +{ +public: + typedef mode_traits::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 @@ -440,14 +481,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 } diff --git a/gcc/optabs.c b/gcc/optabs.c index 86b5926af21..49f35b007be 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -1230,7 +1230,7 @@ expand_binop (machine_mode mode, optab binoptab, rtx op0, rtx op1, { /* 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 (GET_MODE (op1))) > GET_MODE_BITSIZE (inner_mode))) diff --git a/gcc/rtlanal.c b/gcc/rtlanal.c index 1765dbeb904..e6483679903 100644 --- a/gcc/rtlanal.c +++ b/gcc/rtlanal.c @@ -3645,7 +3645,7 @@ subreg_get_info (unsigned int xregno, machine_mode xmode, { 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 diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index e729bd8ff89..109c01917ed 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -5728,7 +5728,7 @@ simplify_immed_subreg (machine_mode outermode, rtx op, 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. */ diff --git a/gcc/varasm.c b/gcc/varasm.c index 04f19e6c8ec..f10f26eb0f1 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -3900,7 +3900,7 @@ output_constant_pool_2 (machine_mode mode, rtx x, unsigned int align) 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);