diff mbox series

[11/77] Add a float_mode_for_size helper function

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

Commit Message

Richard Sandiford July 13, 2017, 8:42 a.m. UTC
This provides a type-safe way to ask for a float mode and get it as a
scalar_float_mode.

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

gcc/
	* coretypes.h (opt_scalar_float_mode): New typedef.
	* machmode.h (float_mode_for_size): New function.
	* emit-rtl.c (double_mode): Delete.
	(init_emit_once): Use float_mode_for_size.
	* stor-layout.c (layout_type): Likewise.
	* gdbhooks.py (build_pretty_printer): Handle opt_scalar_float_mode.

Comments

Jeff Law Aug. 11, 2017, 6:13 p.m. UTC | #1
On 07/13/2017 02:42 AM, Richard Sandiford wrote:
> This provides a type-safe way to ask for a float mode and get it as a

> scalar_float_mode.

> 

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

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

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

> 

> gcc/

> 	* coretypes.h (opt_scalar_float_mode): New typedef.

> 	* machmode.h (float_mode_for_size): New function.

> 	* emit-rtl.c (double_mode): Delete.

> 	(init_emit_once): Use float_mode_for_size.

> 	* stor-layout.c (layout_type): Likewise.

> 	* gdbhooks.py (build_pretty_printer): Handle opt_scalar_float_mode.

OK.
jeff
diff mbox series

Patch

Index: gcc/coretypes.h
===================================================================
--- gcc/coretypes.h	2017-07-13 09:18:23.795186280 +0100
+++ gcc/coretypes.h	2017-07-13 09:18:25.915974717 +0100
@@ -57,6 +57,7 @@  typedef struct rtx_def *rtx;
 typedef const struct rtx_def *const_rtx;
 class scalar_float_mode;
 template<typename> class opt_mode;
+typedef opt_mode<scalar_float_mode> opt_scalar_float_mode;
 
 /* 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:23.798185961 +0100
+++ gcc/machmode.h	2017-07-13 09:18:25.916974620 +0100
@@ -521,7 +521,16 @@  #define GET_MODE_COMPLEX_MODE(MODE) ((ma
 
 extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
 
-/* Similar, but find the smallest mode for a given width.  */
+/* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
+   exists.  */
+
+inline opt_scalar_float_mode
+float_mode_for_size (unsigned int size)
+{
+  return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
+}
+
+/* Similar to mode_for_size, but find the smallest mode for a given width.  */
 
 extern machine_mode smallest_mode_for_size (unsigned int,
 						 enum mode_class);
Index: gcc/emit-rtl.c
===================================================================
--- gcc/emit-rtl.c	2017-07-13 09:18:21.530429366 +0100
+++ gcc/emit-rtl.c	2017-07-13 09:18:25.916974620 +0100
@@ -71,7 +71,6 @@  #define initial_regno_reg_rtx (this_targ
 
 machine_mode byte_mode;	/* Mode whose width is BITS_PER_UNIT.  */
 machine_mode word_mode;	/* Mode whose width is BITS_PER_WORD.  */
-machine_mode double_mode;	/* Mode whose width is DOUBLE_TYPE_SIZE.  */
 machine_mode ptr_mode;	/* Mode whose width is POINTER_SIZE.  */
 
 /* Datastructures maintained for currently processed function in RTL form.  */
@@ -5895,7 +5894,7 @@  init_emit_once (void)
 {
   int i;
   machine_mode mode;
-  machine_mode double_mode;
+  scalar_float_mode double_mode;
 
   /* Initialize the CONST_INT, CONST_WIDE_INT, CONST_DOUBLE,
      CONST_FIXED, and memory attribute hash tables.  */
@@ -5939,7 +5938,7 @@  init_emit_once (void)
   else
     const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE);
 
-  double_mode = mode_for_size (DOUBLE_TYPE_SIZE, MODE_FLOAT, 0);
+  double_mode = *float_mode_for_size (DOUBLE_TYPE_SIZE);
 
   real_from_integer (&dconst0, double_mode, 0, SIGNED);
   real_from_integer (&dconst1, double_mode, 1, SIGNED);
Index: gcc/stor-layout.c
===================================================================
--- gcc/stor-layout.c	2017-07-13 09:18:22.938277517 +0100
+++ gcc/stor-layout.c	2017-07-13 09:18:25.916974620 +0100
@@ -2142,14 +2142,16 @@  layout_type (tree type)
       break;
 
     case REAL_TYPE:
-      /* Allow the caller to choose the type mode, which is how decimal
-	 floats are distinguished from binary ones.  */
-      if (TYPE_MODE (type) == VOIDmode)
-	SET_TYPE_MODE (type,
-		       mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0));
-      TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type)));
-      TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type)));
-      break;
+      {
+	/* Allow the caller to choose the type mode, which is how decimal
+	   floats are distinguished from binary ones.  */
+	if (TYPE_MODE (type) == VOIDmode)
+	  SET_TYPE_MODE (type, *float_mode_for_size (TYPE_PRECISION (type)));
+	scalar_float_mode mode = as_a <scalar_float_mode> (TYPE_MODE (type));
+	TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode));
+	TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (mode));
+	break;
+      }
 
    case FIXED_POINT_TYPE:
      /* TYPE_MODE (type) has been set already.  */
Index: gcc/gdbhooks.py
===================================================================
--- gcc/gdbhooks.py	2017-07-13 09:18:23.798185961 +0100
+++ gcc/gdbhooks.py	2017-07-13 09:18:25.916974620 +0100
@@ -542,6 +542,8 @@  def build_pretty_printer():
 
     pp.add_printer_for_regex(r'opt_mode<(\S+)>',
                              'opt_mode', OptMachineModePrinter)
+    pp.add_printer_for_types(['opt_scalar_float_mode'],
+                             'opt_mode', OptMachineModePrinter)
     pp.add_printer_for_types(['scalar_float_mode'],
                              'scalar_float_mode', MachineModePrinter)