]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[64/77] Add a scalar_mode class
authorRichard Sandiford <richard.sandiford@linaro.org>
Wed, 30 Aug 2017 11:19:17 +0000 (11:19 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Wed, 30 Aug 2017 11:19:17 +0000 (11:19 +0000)
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  <richard.sandiford@linaro.org>
    Alan Hayward  <alan.hayward@arm.com>
    David Sherwood  <david.sherwood@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.

Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>
From-SVN: r251515

13 files changed:
gcc/ChangeLog
gcc/cfgexpand.c
gcc/coretypes.h
gcc/expmed.c
gcc/expr.c
gcc/function.c
gcc/gdbhooks.py
gcc/genmodes.c
gcc/machmode.h
gcc/optabs.c
gcc/rtlanal.c
gcc/simplify-rtx.c
gcc/varasm.c

index 0ddf5d9f85169ebea053a8e95f9dc3e25f2ecc3a..d9895f36e9ef73f52950e1d29a2890dc036017bc 100644 (file)
@@ -1,3 +1,27 @@
+2017-08-30  Richard Sandiford  <richard.sandiford@linaro.org>
+           Alan Hayward  <alan.hayward@arm.com>
+           David Sherwood  <david.sherwood@arm.com>
+
+       * 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  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index a32f7648d41d034203e2e4368bb4407036b0243e..7f5c97bfc7c14da30ab5db904fded168202b020d 100644 (file)
@@ -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))
index 37c836d87fa245c359f54322aa7da5d2e07b1f67..a9f105ceeef8e0083659828988694f3476119321 100644 (file)
@@ -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<typename> 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;
 
index 10cf59c5c2e2cf64761a2c8233dfc0f13fb83e5f..f38fb3177709d5db02b56da64a050629309885fa 100644 (file)
@@ -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);
index fcad2e39445a4102fd12c0af9a1f571bd3f15de9..71a81ef1f3069bffb83209078c0b169dbe1a0a26 100644 (file)
@@ -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))
index 8e8291edc55d50d0a203115db35b4cdd4afad6e4..af5e050b8a6f50bc6ec0eb163b5e04aabbbec6ea 100644 (file)
@@ -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]);
index 678698df9c83e97b9b0cccdaa3f3ab00d185447b..8799e3fbfd9153436ca0d7d2cc973af533a44517 100644 (file)
@@ -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 3eb9b44c74b97f0ac218a6cb3bacb608ccdf12f0..ab3f999c9995e78a403f21a21064c69ca502c6a6 100644 (file)
@@ -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 5f3e031324ec4656aa1d4a30cf7abd0eff54093d..4586d62b81a29260042bd4c5ccda308b9de714cf 100644 (file)
@@ -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<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
@@ -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
 }
 
index 86b5926af2158457200647e39e2e84aedf132316..49f35b007bee4219783595b5c75667fecb151d29 100644 (file)
@@ -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 <scalar_int_mode> (GET_MODE (op1)))
                  > GET_MODE_BITSIZE (inner_mode)))
index 1765dbeb9043840ebe7935ef2ceb960dc6766ce8..e6483679903cda7049b9489918374d320259198b 100644 (file)
@@ -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
index e729bd8ff894e5afc248035be23d4256811e644f..109c01917ed27d0d8ae977fedf38caf2ff524b19 100644 (file)
@@ -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.  */
index 04f19e6c8ecc4dd493d3434759c786cbbabe7c98..f10f26eb0f144f56e295ceb2c010c50fea30c326 100644 (file)
@@ -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);