diff mbox series

[16/77] Add scalar_int_mode_pod

Message ID 878tjslo9o.fsf@linaro.org
State New
Headers show
Series Add wrapper classes for machine_modes | expand

Commit Message

Richard Sandiford July 13, 2017, 8:44 a.m. UTC
This patch adds a POD class for scalar integers, as an instance
of a new pod_mode template.  Later patches will use pod_mode in
situations that really do need to be POD; this patch is simply
using PODs to remove load-time initialisation.

2017-07-13  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* coretypes.h (pod_mode): New type.
	(scalar_int_mode_pod): New typedef.
	* machmode.h (pod_mode): New class.
	(int_n_data_t::m): Change type to scalar_int_mode_pod.
	* genmodes.c (emit_mode_int_n): Update accordingly.
	* lower-subreg.h (target_lower_subreg): Change type to
	scalar_int_mode_pod.
	* gdbhooks.py (build_pretty_printer): Handle pod_mode and
	scalar_int_mode_pod.

Comments

Jeff Law Aug. 14, 2017, 6:23 p.m. UTC | #1
On 07/13/2017 02:44 AM, Richard Sandiford wrote:
> This patch adds a POD class for scalar integers, as an instance

> of a new pod_mode template.  Later patches will use pod_mode in

> situations that really do need to be POD; this patch is simply

> using PODs to remove load-time initialisation.

> 

> 2017-07-13  Richard Sandiford  <richard.sandiford@linaro.org>

> 	    Alan Hayward  <alan.hayward@arm.com>

> 	    David Sherwood  <david.sherwood@arm.com>

> 

> gcc/

> 	* coretypes.h (pod_mode): New type.

> 	(scalar_int_mode_pod): New typedef.

> 	* machmode.h (pod_mode): New class.

> 	(int_n_data_t::m): Change type to scalar_int_mode_pod.

> 	* genmodes.c (emit_mode_int_n): Update accordingly.

> 	* lower-subreg.h (target_lower_subreg): Change type to

> 	scalar_int_mode_pod.

> 	* gdbhooks.py (build_pretty_printer): Handle pod_mode and

> 	scalar_int_mode_pod.

OK.
jeff
diff mbox series

Patch

Index: gcc/coretypes.h
===================================================================
--- gcc/coretypes.h	2017-07-13 09:18:28.023771640 +0100
+++ gcc/coretypes.h	2017-07-13 09:18:28.587718194 +0100
@@ -60,6 +60,8 @@  typedef const struct rtx_def *const_rtx;
 template<typename> class opt_mode;
 typedef opt_mode<scalar_int_mode> opt_scalar_int_mode;
 typedef opt_mode<scalar_float_mode> opt_scalar_float_mode;
+template<typename> class pod_mode;
+typedef pod_mode<scalar_int_mode> scalar_int_mode_pod;
 
 /* Subclasses of rtx_def, using indentation to show the class
    hierarchy, along with the relevant invariant.
Index: gcc/machmode.h
===================================================================
--- gcc/machmode.h	2017-07-13 09:18:28.024771545 +0100
+++ gcc/machmode.h	2017-07-13 09:18:28.588718099 +0100
@@ -294,6 +294,19 @@  opt_mode<T>::exists (U *mode) const
   return false;
 }
 
+/* A POD version of mode class T.  */
+
+template<typename T>
+struct pod_mode
+{
+  typedef typename mode_traits<T>::from_int from_int;
+
+  machine_mode m_mode;
+  ALWAYS_INLINE operator machine_mode () const { return m_mode; }
+  ALWAYS_INLINE operator T () const { return from_int (m_mode); }
+  ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
+};
+
 /* Return true if mode M has type T.  */
 
 template<typename T>
@@ -648,7 +661,7 @@  #define HWI_COMPUTABLE_MODE_P(MODE) \
 struct int_n_data_t {
   /* These parts are initailized by genmodes output */
   unsigned int bitsize;
-  machine_mode m;
+  scalar_int_mode_pod m;
   /* RID_* is RID_INTN_BASE + index into this array */
 };
 
Index: gcc/genmodes.c
===================================================================
--- gcc/genmodes.c	2017-07-13 09:18:28.024771545 +0100
+++ gcc/genmodes.c	2017-07-13 09:18:28.587718194 +0100
@@ -1799,7 +1799,7 @@  emit_mode_int_n (void)
       m = mode_sort[i];
       printf(" {\n");
       tagged_printf ("%u", m->int_n, m->name);
-      printf ("E_%smode,", m->name);
+      printf ("{ E_%smode },", m->name);
       printf(" },\n");
     }
 
Index: gcc/lower-subreg.h
===================================================================
--- gcc/lower-subreg.h	2017-02-23 19:54:15.000000000 +0000
+++ gcc/lower-subreg.h	2017-07-13 09:18:28.588718099 +0100
@@ -43,7 +43,7 @@  struct lower_subreg_choices {
 /* Target-specific information for the subreg lowering pass.  */
 struct target_lower_subreg {
   /* An integer mode that is twice as wide as word_mode.  */
-  machine_mode x_twice_word_mode;
+  scalar_int_mode_pod x_twice_word_mode;
 
   /* What we have decided to do when optimizing for size (index 0)
      and speed (index 1).  */
Index: gcc/gdbhooks.py
===================================================================
--- gcc/gdbhooks.py	2017-07-13 09:18:28.024771545 +0100
+++ gcc/gdbhooks.py	2017-07-13 09:18:28.587718194 +0100
@@ -545,6 +545,10 @@  def build_pretty_printer():
     pp.add_printer_for_types(['opt_scalar_int_mode',
                               'opt_scalar_float_mode'],
                              'opt_mode', OptMachineModePrinter)
+    pp.add_printer_for_regex(r'pod_mode<(\S+)>',
+                             'pod_mode', MachineModePrinter)
+    pp.add_printer_for_types(['scalar_int_mode_pod'],
+                             'pod_mode', MachineModePrinter)
     for mode in 'scalar_int_mode', 'scalar_float_mode':
         pp.add_printer_for_types([mode], mode, MachineModePrinter)