Commit 857c7b46 by Richard Sandiford Committed by Richard Sandiford

[11/77] Add a float_mode_for_size helper function

This provides a type-safe way to ask for a float mode and get it as a
scalar_float_mode.

2017-08-30  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.

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

From-SVN: r251463
parent d16c828e
...@@ -2,6 +2,17 @@ ...@@ -2,6 +2,17 @@
Alan Hayward <alan.hayward@arm.com> Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com> David Sherwood <david.sherwood@arm.com>
* 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.
2017-08-30 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
* output.h (assemble_real): Take a scalar_float_mode. * output.h (assemble_real): Take a scalar_float_mode.
* config/arm/arm.c (arm_assemble_integer): Update accordingly. * config/arm/arm.c (arm_assemble_integer): Update accordingly.
* config/arm/arm.md (consttable_4): Likewise. * config/arm/arm.md (consttable_4): Likewise.
......
...@@ -57,6 +57,7 @@ typedef struct rtx_def *rtx; ...@@ -57,6 +57,7 @@ typedef struct rtx_def *rtx;
typedef const struct rtx_def *const_rtx; typedef const struct rtx_def *const_rtx;
class scalar_float_mode; class scalar_float_mode;
template<typename> class opt_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 /* Subclasses of rtx_def, using indentation to show the class
hierarchy, along with the relevant invariant. hierarchy, along with the relevant invariant.
......
...@@ -72,7 +72,6 @@ struct target_rtl *this_target_rtl = &default_target_rtl; ...@@ -72,7 +72,6 @@ struct target_rtl *this_target_rtl = &default_target_rtl;
machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */ machine_mode byte_mode; /* Mode whose width is BITS_PER_UNIT. */
machine_mode word_mode; /* Mode whose width is BITS_PER_WORD. */ 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. */ machine_mode ptr_mode; /* Mode whose width is POINTER_SIZE. */
/* Datastructures maintained for currently processed function in RTL form. */ /* Datastructures maintained for currently processed function in RTL form. */
...@@ -5889,7 +5888,7 @@ init_emit_once (void) ...@@ -5889,7 +5888,7 @@ init_emit_once (void)
{ {
int i; int i;
machine_mode mode; machine_mode mode;
machine_mode double_mode; scalar_float_mode double_mode;
/* Initialize the CONST_INT, CONST_WIDE_INT, CONST_DOUBLE, /* Initialize the CONST_INT, CONST_WIDE_INT, CONST_DOUBLE,
CONST_FIXED, and memory attribute hash tables. */ CONST_FIXED, and memory attribute hash tables. */
...@@ -5933,7 +5932,7 @@ init_emit_once (void) ...@@ -5933,7 +5932,7 @@ init_emit_once (void)
else else
const_true_rtx = gen_rtx_CONST_INT (VOIDmode, STORE_FLAG_VALUE); 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).require ();
real_from_integer (&dconst0, double_mode, 0, SIGNED); real_from_integer (&dconst0, double_mode, 0, SIGNED);
real_from_integer (&dconst1, double_mode, 1, SIGNED); real_from_integer (&dconst1, double_mode, 1, SIGNED);
......
...@@ -542,6 +542,8 @@ def build_pretty_printer(): ...@@ -542,6 +542,8 @@ def build_pretty_printer():
pp.add_printer_for_regex(r'opt_mode<(\S+)>', pp.add_printer_for_regex(r'opt_mode<(\S+)>',
'opt_mode', OptMachineModePrinter) 'opt_mode', OptMachineModePrinter)
pp.add_printer_for_types(['opt_scalar_float_mode'],
'opt_mode', OptMachineModePrinter)
pp.add_printer_for_types(['scalar_float_mode'], pp.add_printer_for_types(['scalar_float_mode'],
'scalar_float_mode', MachineModePrinter) 'scalar_float_mode', MachineModePrinter)
......
...@@ -520,7 +520,16 @@ extern const unsigned char mode_complex[NUM_MACHINE_MODES]; ...@@ -520,7 +520,16 @@ extern const unsigned char mode_complex[NUM_MACHINE_MODES];
extern machine_mode mode_for_size (unsigned int, enum mode_class, int); 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, extern machine_mode smallest_mode_for_size (unsigned int,
enum mode_class); enum mode_class);
......
...@@ -2205,14 +2205,17 @@ layout_type (tree type) ...@@ -2205,14 +2205,17 @@ layout_type (tree type)
break; break;
case REAL_TYPE: case REAL_TYPE:
/* Allow the caller to choose the type mode, which is how decimal {
floats are distinguished from binary ones. */ /* Allow the caller to choose the type mode, which is how decimal
if (TYPE_MODE (type) == VOIDmode) floats are distinguished from binary ones. */
SET_TYPE_MODE (type, if (TYPE_MODE (type) == VOIDmode)
mode_for_size (TYPE_PRECISION (type), MODE_FLOAT, 0)); SET_TYPE_MODE
TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (TYPE_MODE (type))); (type, float_mode_for_size (TYPE_PRECISION (type)).require ());
TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (TYPE_MODE (type))); scalar_float_mode mode = as_a <scalar_float_mode> (TYPE_MODE (type));
break; TYPE_SIZE (type) = bitsize_int (GET_MODE_BITSIZE (mode));
TYPE_SIZE_UNIT (type) = size_int (GET_MODE_SIZE (mode));
break;
}
case FIXED_POINT_TYPE: case FIXED_POINT_TYPE:
/* TYPE_MODE (type) has been set already. */ /* TYPE_MODE (type) has been set already. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment