From f079167a3064f11a7d8c17ef78389559435bad9d Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Fri, 18 Nov 2016 10:04:53 +0000 Subject: [PATCH] Use rtx_mode_t instead of std::make_pair 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. gcc/ 2016-11-18 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. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r242586 --- gcc/ChangeLog | 18 ++++++++++++++++++ gcc/combine.c | 4 ++-- gcc/dwarf2out.c | 10 +++++----- gcc/explow.c | 3 +-- gcc/expmed.c | 4 ++-- gcc/expr.c | 2 +- gcc/loop-doloop.c | 2 +- gcc/postreload.c | 8 ++++---- gcc/simplify-rtx.c | 26 +++++++++++++------------- gcc/wide-int.h | 4 ++-- 10 files changed, 49 insertions(+), 32 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b4291641e67..a63c7952ce1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,21 @@ +2016-11-18 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. + 2016-11-18 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/combine.c b/gcc/combine.c index 5f920c4a55e..93621bd02fb 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 a7344ca0136..e468a4c3299 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 b65eee6e921..75af333c1c3 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 index 69109db0ebd..a21a632ab18 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -3276,7 +3276,7 @@ expand_mult (machine_mode mode, rtx op0, rtx op1, rtx target, else if (CONST_DOUBLE_AS_INT_P (scalar_op1)) #endif { - int shift = wi::exact_log2 (std::make_pair (scalar_op1, mode)); + int shift = wi::exact_log2 (rtx_mode_t (scalar_op1, mode)); /* Perfect power of 2 (other than 1, which is handled above). */ if (shift > 0) return expand_shift (LSHIFT_EXPR, mode, op0, @@ -5092,7 +5092,7 @@ make_tree (tree type, rtx x) { case CONST_INT: case CONST_WIDE_INT: - t = wide_int_to_tree (type, std::make_pair (x, TYPE_MODE (type))); + t = wide_int_to_tree (type, rtx_mode_t (x, TYPE_MODE (type))); return t; case CONST_DOUBLE: diff --git a/gcc/expr.c b/gcc/expr.c index 985c2b3285f..a51c16478d3 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -652,7 +652,7 @@ convert_modes (machine_mode mode, machine_mode oldmode, rtx x, int unsignedp) assume that all the bits are significant. */ if (GET_MODE_CLASS (oldmode) != MODE_INT) oldmode = MAX_MODE_INT; - wide_int w = wide_int::from (std::make_pair (x, oldmode), + wide_int w = wide_int::from (rtx_mode_t (x, oldmode), GET_MODE_PRECISION (mode), unsignedp ? UNSIGNED : SIGNED); return immed_wide_int_const (w, mode); diff --git a/gcc/loop-doloop.c b/gcc/loop-doloop.c index a8055196014..1dff2ff3f88 100644 --- a/gcc/loop-doloop.c +++ b/gcc/loop-doloop.c @@ -662,7 +662,7 @@ doloop_optimize (struct loop *loop) } if (desc->const_iter) - iterations = widest_int::from (std::make_pair (desc->niter_expr, mode), + iterations = widest_int::from (rtx_mode_t (desc->niter_expr, mode), UNSIGNED); else iterations = 0; diff --git a/gcc/postreload.c b/gcc/postreload.c index a11d2705dab..fcb6bc4bd50 100644 --- a/gcc/postreload.c +++ b/gcc/postreload.c @@ -290,13 +290,13 @@ reload_cse_simplify_set (rtx set, rtx_insn *insn) switch (extend_op) { case ZERO_EXTEND: - result = wide_int::from (std::make_pair (this_rtx, - GET_MODE (src)), + result = wide_int::from (rtx_mode_t (this_rtx, + GET_MODE (src)), BITS_PER_WORD, UNSIGNED); break; case SIGN_EXTEND: - result = wide_int::from (std::make_pair (this_rtx, - GET_MODE (src)), + result = wide_int::from (rtx_mode_t (this_rtx, + GET_MODE (src)), BITS_PER_WORD, SIGNED); break; default: diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 11a2e0267c7..fde24430248 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1716,7 +1716,7 @@ simplify_const_unary_operation (enum rtx_code code, machine_mode mode, op_mode = MAX_MODE_INT; } - real_from_integer (&d, mode, std::make_pair (op, op_mode), SIGNED); + real_from_integer (&d, mode, rtx_mode_t (op, op_mode), SIGNED); /* Avoid the folding if flag_signaling_nans is on and operand is a signaling NaN. */ @@ -1740,7 +1740,7 @@ simplify_const_unary_operation (enum rtx_code code, machine_mode mode, op_mode = MAX_MODE_INT; } - real_from_integer (&d, mode, std::make_pair (op, op_mode), UNSIGNED); + real_from_integer (&d, mode, rtx_mode_t (op, op_mode), UNSIGNED); /* Avoid the folding if flag_signaling_nans is on and operand is a signaling NaN. */ @@ -1755,7 +1755,7 @@ simplify_const_unary_operation (enum rtx_code code, machine_mode mode, { wide_int result; machine_mode imode = op_mode == VOIDmode ? mode : op_mode; - rtx_mode_t op0 = std::make_pair (op, imode); + rtx_mode_t op0 = rtx_mode_t (op, imode); int int_value; #if TARGET_SUPPORTS_WIDE_INT == 0 @@ -2150,7 +2150,7 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, else if (GET_CODE (lhs) == MULT && CONST_SCALAR_INT_P (XEXP (lhs, 1))) { - coeff0 = std::make_pair (XEXP (lhs, 1), mode); + coeff0 = rtx_mode_t (XEXP (lhs, 1), mode); lhs = XEXP (lhs, 0); } else if (GET_CODE (lhs) == ASHIFT @@ -2171,7 +2171,7 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, else if (GET_CODE (rhs) == MULT && CONST_INT_P (XEXP (rhs, 1))) { - coeff1 = std::make_pair (XEXP (rhs, 1), mode); + coeff1 = rtx_mode_t (XEXP (rhs, 1), mode); rhs = XEXP (rhs, 0); } else if (GET_CODE (rhs) == ASHIFT @@ -2327,7 +2327,7 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, else if (GET_CODE (lhs) == MULT && CONST_SCALAR_INT_P (XEXP (lhs, 1))) { - coeff0 = std::make_pair (XEXP (lhs, 1), mode); + coeff0 = rtx_mode_t (XEXP (lhs, 1), mode); lhs = XEXP (lhs, 0); } else if (GET_CODE (lhs) == ASHIFT @@ -2348,7 +2348,7 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, else if (GET_CODE (rhs) == MULT && CONST_INT_P (XEXP (rhs, 1))) { - negcoeff1 = wi::neg (std::make_pair (XEXP (rhs, 1), mode)); + negcoeff1 = wi::neg (rtx_mode_t (XEXP (rhs, 1), mode)); rhs = XEXP (rhs, 0); } else if (GET_CODE (rhs) == ASHIFT @@ -2523,7 +2523,7 @@ simplify_binary_operation_1 (enum rtx_code code, machine_mode mode, /* Convert multiply by constant power of two into shift. */ if (CONST_SCALAR_INT_P (trueop1)) { - val = wi::exact_log2 (std::make_pair (trueop1, mode)); + val = wi::exact_log2 (rtx_mode_t (trueop1, mode)); if (val >= 0) return simplify_gen_binary (ASHIFT, mode, op0, GEN_INT (val)); } @@ -4046,8 +4046,8 @@ simplify_const_binary_operation (enum rtx_code code, machine_mode mode, { wide_int result; bool overflow; - rtx_mode_t pop0 = std::make_pair (op0, mode); - rtx_mode_t pop1 = std::make_pair (op1, mode); + rtx_mode_t pop0 = rtx_mode_t (op0, mode); + rtx_mode_t pop1 = rtx_mode_t (op1, mode); #if TARGET_SUPPORTS_WIDE_INT == 0 /* This assert keeps the simplification from producing a result @@ -5081,8 +5081,8 @@ simplify_const_relational_operation (enum rtx_code code, largest int representable on the target is as good as infinite. */ machine_mode cmode = (mode == VOIDmode) ? MAX_MODE_INT : mode; - rtx_mode_t ptrueop0 = std::make_pair (trueop0, cmode); - rtx_mode_t ptrueop1 = std::make_pair (trueop1, cmode); + rtx_mode_t ptrueop0 = rtx_mode_t (trueop0, cmode); + rtx_mode_t ptrueop1 = rtx_mode_t (trueop1, cmode); if (wi::eq_p (ptrueop0, ptrueop1)) return comparison_result (code, CMP_EQ); @@ -5738,7 +5738,7 @@ simplify_immed_subreg (machine_mode outermode, rtx op, case CONST_WIDE_INT: { - rtx_mode_t val = std::make_pair (el, innermode); + rtx_mode_t val = rtx_mode_t (el, innermode); unsigned char extend = wi::sign_mask (val); for (i = 0; i < elem_bitsize; i += value_bit) diff --git a/gcc/wide-int.h b/gcc/wide-int.h index f172faecf87..72f74bed9ec 100644 --- a/gcc/wide-int.h +++ b/gcc/wide-int.h @@ -158,10 +158,10 @@ along with GCC; see the file COPYING3. If not see However, a little more syntax is required for rtl constants since they do not have an explicit precision. To make an rtl into a wide_int, you have to pair it with a mode. The canonical way to do - this is with std::make_pair as in: + this is with rtx_mode_t as in: rtx r = ... - wide_int x = std::make_pair (r, mode); + wide_int x = rtx_mode_t (r, mode); Similarly, a wide_int can only be constructed from a host value if the target precision is given explicitly, such as in: -- 2.30.2