Re: Use rtx_mode_t instead of std::make_pair

2016-11-16 Thread Bernd Schmidt

On 11/16/2016 05:52 PM, Richard Sandiford wrote:


Using rtx_mode_t also abstracts away the representation.  The fact that
it's a std::pair rather than a custom class isn't important to users of
the interface.


Looks borderline obvious to me. OK.


Bernd



Use rtx_mode_t instead of std::make_pair

2016-11-16 Thread Richard Sandiford
This change makes the code less sensitive to the exact type of the mode,
i.e. it forces a conversion where necessary.  This becomes important
when wrappers like scalar_int_mode and scalar_mode can also be used
instead of machine_mode.

Using rtx_mode_t also abstracts away the representation.  The fact that
it's a std::pair rather than a custom class isn't important to users of
the interface.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Thanks,
Richard


[ This patch is part of the SVE series posted here:
  https://gcc.gnu.org/ml/gcc/2016-11/msg00030.html ]

gcc/
2016-11-16  Richard Sandiford  
Alan Hayward  
David Sherwood  

* combine.c (try_combine): Use rtx_mode_t instead of std::make_pair.
* dwarf2out.c (mem_loc_descriptor, loc_descriptor): Likewise.
(add_const_value_attribute): Likewise.
* explow.c (plus_constant): Likewise.
* expmed.c (expand_mult, make_tree): Likewise.
* expr.c (convert_modes): Likewise.
* loop-doloop.c (doloop_optimize): Likewise.
* postreload.c (reload_cse_simplify_set): Likewise.
* simplify-rtx.c (simplify_const_unary_operation): Likewise.
(simplify_binary_operation_1, simplify_const_binary_operation):
(simplify_const_relational_operation, simplify_immed_subreg): Likewise.
* wide-int.h: Update documentation to recommend rtx_mode_t
instead of std::make_pair.

diff --git a/gcc/combine.c b/gcc/combine.c
index ca5ddae..0f3b292 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -2870,8 +2870,8 @@ try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, 
rtx_insn *i0,
  rtx outer = SET_SRC (temp_expr);
 
  wide_int o
-   = wi::insert (std::make_pair (outer, GET_MODE (SET_DEST 
(temp_expr))),
- std::make_pair (inner, GET_MODE (dest)),
+   = wi::insert (rtx_mode_t (outer, GET_MODE (SET_DEST (temp_expr))),
+ rtx_mode_t (inner, GET_MODE (dest)),
  offset, width);
 
  combine_merges++;
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index a7344ca..e468a4c 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -15127,7 +15127,7 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
  mem_loc_result->dw_loc_oprnd2.val_class
= dw_val_class_wide_int;
  mem_loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc ();
- *mem_loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, 
mode);
+ *mem_loc_result->dw_loc_oprnd2.v.val_wide = rtx_mode_t (rtl, mode);
}
   break;
 
@@ -15670,7 +15670,7 @@ loc_descriptor (rtx rtl, machine_mode mode,
  GET_MODE_SIZE (mode), 0);
  loc_result->dw_loc_oprnd2.val_class = dw_val_class_wide_int;
  loc_result->dw_loc_oprnd2.v.val_wide = ggc_alloc ();
- *loc_result->dw_loc_oprnd2.v.val_wide = std::make_pair (rtl, mode);
+ *loc_result->dw_loc_oprnd2.v.val_wide = rtx_mode_t (rtl, mode);
}
   break;
 
@@ -15695,7 +15695,7 @@ loc_descriptor (rtx rtl, machine_mode mode,
  for (i = 0, p = array; i < length; i++, p += elt_size)
{
  rtx elt = CONST_VECTOR_ELT (rtl, i);
- insert_wide_int (std::make_pair (elt, imode), p, elt_size);
+ insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
}
  break;
 
@@ -18357,7 +18357,7 @@ add_const_value_attribute (dw_die_ref die, rtx rtl)
 
 case CONST_WIDE_INT:
   {
-   wide_int w1 = std::make_pair (rtl, MAX_MODE_INT);
+   wide_int w1 = rtx_mode_t (rtl, MAX_MODE_INT);
unsigned int prec = MIN (wi::min_precision (w1, UNSIGNED),
 (unsigned int)CONST_WIDE_INT_NUNITS (rtl) * 
HOST_BITS_PER_WIDE_INT);
wide_int w = wi::zext (w1, prec);
@@ -18404,7 +18404,7 @@ add_const_value_attribute (dw_die_ref die, rtx rtl)
for (i = 0, p = array; i < length; i++, p += elt_size)
  {
rtx elt = CONST_VECTOR_ELT (rtl, i);
-   insert_wide_int (std::make_pair (elt, imode), p, elt_size);
+   insert_wide_int (rtx_mode_t (elt, imode), p, elt_size);
  }
break;
 
diff --git a/gcc/explow.c b/gcc/explow.c
index b65eee6..75af333 100644
--- a/gcc/explow.c
+++ b/gcc/explow.c
@@ -98,8 +98,7 @@ plus_constant (machine_mode mode, rtx x, HOST_WIDE_INT c,
   switch (code)
 {
 CASE_CONST_SCALAR_INT:
-  return immed_wide_int_const (wi::add (std::make_pair (x, mode), c),
-  mode);
+  return immed_wide_int_const (wi::add (rtx_mode_t (x, mode), c), mode);
 case MEM:
   /* If this is a reference to the constant pool, try replacing it with
 a reference to a new constant.  If the resulting address isn't
diff --git a/gcc/expmed.c b/gcc/expmed.c
ind