diff mbox series

Use CONSTEXPR in machmode.h

Message ID mptsgo8k10t.fsf@arm.com
State New
Headers show
Series Use CONSTEXPR in machmode.h | expand

Commit Message

Richard Sandiford Oct. 4, 2019, 3:01 p.m. UTC
I'd like to use CONSTEXPR to get static initialisation of some
aarch64-specific variables.  This obviously means that cross toolchains
built with old compilers won't benefit, but I hope toolchains built with
newer compilers are faster for other reasons too. :-)

The variables in question have scalar_int_mode fields, so I first
needed to make the machine_mode stuff more constexpr-friendly.
This patch therefore adds CONSTEXPR to constructors and operators in
machmode.h, excluding the controversial constexpr-resistant "() {}"
constructors, which would become "= default" if we required C++11.

Some of the other routines could potentially be constexpr too,
but that can be done on an as-needed basis.

Tested on aarch64-linux-gnu, with and without the follow-on changes.
OK to install?

Richard


2019-10-04  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	* machmode.h (opt_mode): Mark constructors with CONSTEXPR.
	(pod_mode): Mark operators likewise.
	(scalar_int_mode): Mark non-default constructors and
	operators with CONSTEXPR.
	(scalar_float_mode, scalar_mode, complex_mode): Likewise.
	(fixed_size_mode): Likewise.

Comments

Jeff Law Oct. 4, 2019, 3:53 p.m. UTC | #1
On 10/4/19 9:01 AM, Richard Sandiford wrote:
> I'd like to use CONSTEXPR to get static initialisation of some
> aarch64-specific variables.  This obviously means that cross toolchains
> built with old compilers won't benefit, but I hope toolchains built with
> newer compilers are faster for other reasons too. :-)
> 
> The variables in question have scalar_int_mode fields, so I first
> needed to make the machine_mode stuff more constexpr-friendly.
> This patch therefore adds CONSTEXPR to constructors and operators in
> machmode.h, excluding the controversial constexpr-resistant "() {}"
> constructors, which would become "= default" if we required C++11.
> 
> Some of the other routines could potentially be constexpr too,
> but that can be done on an as-needed basis.
> 
> Tested on aarch64-linux-gnu, with and without the follow-on changes.
> OK to install?
> 
> Richard
> 
> 
> 2019-10-04  Richard Sandiford  <richard.sandiford@arm.com>
> 
> gcc/
> 	* machmode.h (opt_mode): Mark constructors with CONSTEXPR.
> 	(pod_mode): Mark operators likewise.
> 	(scalar_int_mode): Mark non-default constructors and
> 	operators with CONSTEXPR.
> 	(scalar_float_mode, scalar_mode, complex_mode): Likewise.
> 	(fixed_size_mode): Likewise.
Given that we've got the necessary magic in ansidecl.h and have already
started using constexpr elsewhere (bitmap, vec) I think this has to be
considered OK regardless of any policies we have WRT C++11 features.

So OK as would be the introduction of CONSTEXPR elsewhere.

Jeff
diff mbox series

Patch

Index: gcc/machmode.h
===================================================================
--- gcc/machmode.h	2019-08-13 11:39:54.753376024 +0100
+++ gcc/machmode.h	2019-10-04 15:59:12.166948822 +0100
@@ -244,11 +244,11 @@  #define CLASS_HAS_WIDER_MODES_P(CLASS)
 public:
   enum from_int { dummy = MAX_MACHINE_MODE };
 
-  ALWAYS_INLINE opt_mode () : m_mode (E_VOIDmode) {}
-  ALWAYS_INLINE opt_mode (const T &m) : m_mode (m) {}
+  ALWAYS_INLINE CONSTEXPR opt_mode () : m_mode (E_VOIDmode) {}
+  ALWAYS_INLINE CONSTEXPR opt_mode (const T &m) : m_mode (m) {}
   template<typename U>
-  ALWAYS_INLINE opt_mode (const U &m) : m_mode (T (m)) {}
-  ALWAYS_INLINE opt_mode (from_int m) : m_mode (machine_mode (m)) {}
+  ALWAYS_INLINE CONSTEXPR opt_mode (const U &m) : m_mode (T (m)) {}
+  ALWAYS_INLINE CONSTEXPR opt_mode (from_int m) : m_mode (machine_mode (m)) {}
 
   machine_mode else_void () const;
   machine_mode else_blk () const { return else_mode (BLKmode); }
@@ -324,8 +324,12 @@  struct pod_mode
   typedef typename T::measurement_type measurement_type;
 
   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 CONSTEXPR
+  operator machine_mode () const { return m_mode; }
+
+  ALWAYS_INLINE CONSTEXPR
+  operator T () const { return from_int (m_mode); }
+
   ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
 };
 
@@ -403,8 +407,11 @@  is_a (machine_mode m, U *result)
   typedef unsigned short measurement_type;
 
   ALWAYS_INLINE scalar_int_mode () {}
-  ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
-  ALWAYS_INLINE operator machine_mode () const { return m_mode; }
+
+  ALWAYS_INLINE CONSTEXPR
+  scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
+
+  ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
 
   static bool includes_p (machine_mode);
 
@@ -428,8 +435,11 @@  scalar_int_mode::includes_p (machine_mod
   typedef unsigned short measurement_type;
 
   ALWAYS_INLINE scalar_float_mode () {}
-  ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
-  ALWAYS_INLINE operator machine_mode () const { return m_mode; }
+
+  ALWAYS_INLINE CONSTEXPR
+  scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
+
+  ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
 
   static bool includes_p (machine_mode);
 
@@ -453,11 +463,20 @@  scalar_float_mode::includes_p (machine_m
   typedef unsigned short measurement_type;
 
   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; }
+
+  ALWAYS_INLINE CONSTEXPR
+  scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
 
   static bool includes_p (machine_mode);
 
@@ -494,8 +513,11 @@  scalar_mode::includes_p (machine_mode m)
   typedef unsigned short measurement_type;
 
   ALWAYS_INLINE complex_mode () {}
-  ALWAYS_INLINE complex_mode (from_int m) : m_mode (machine_mode (m)) {}
-  ALWAYS_INLINE operator machine_mode () const { return m_mode; }
+
+  ALWAYS_INLINE CONSTEXPR
+  complex_mode (from_int m) : m_mode (machine_mode (m)) {}
+
+  ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
 
   static bool includes_p (machine_mode);
 
@@ -764,14 +786,29 @@  #define GET_MODE_COMPLEX_MODE(MODE) ((ma
   typedef unsigned short measurement_type;
 
   ALWAYS_INLINE fixed_size_mode () {}
-  ALWAYS_INLINE fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
-  ALWAYS_INLINE fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
-  ALWAYS_INLINE fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
-  ALWAYS_INLINE fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
-  ALWAYS_INLINE fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
-  ALWAYS_INLINE fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
-  ALWAYS_INLINE fixed_size_mode (const complex_mode &m) : m_mode (m) {}
-  ALWAYS_INLINE operator machine_mode () const { return m_mode; }
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR
+  fixed_size_mode (const complex_mode &m) : m_mode (m) {}
+
+  ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
 
   static bool includes_p (machine_mode);