This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] Use fold_convert instead of convert in middle-end
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 2 Apr 2006 20:47:43 -0600 (MDT)
- Subject: [Committed] Use fold_convert instead of convert in middle-end
The following patch removes many (but not all) of the uses of convert
from libbackend.a, instead replacing them with calls to the language
independent fold_convert. Many thanks to RTH for his help with
GOMP_IF_CLAUSE which previously blocked this clean-up.
The following patch has been tested on i686-pc-linux-gnu, all default
languages including Ada, and regression tested with a top-level
"make -k check" with no new failures.
Committed to mainline as revision 112633.
2006-04-02 Roger Sayle <roger@eyesopen.com>
* builtins.c (dummy_object): Use build_int_cst instead of convert.
* tree-ssa-ccp.c (maybe_fold_stmt_addition): Use fold_convert
instead of convert.
* dojump.c (do_jump): Likewise.
* expr.h (ADD_PARM_SIZE, SUB_PARM_SIZE, ARGS_SIZE_TREE): Likewise.
* gimplify.c (gimple_boolify, gimplify_init_constructor,
gimplify_boolean_expr): Likewise.
* emit-rtl.c (set_mem_attributes_minus_bitpos): Likewise.
* varasm.c (array_size_for_constructor): Likewise.
* tree-object-size.c (compute_object_offset): Likewise.
Index: builtins.c
===================================================================
*** builtins.c (revision 112438)
--- builtins.c (working copy)
*************** build_va_arg_indirect_ref (tree addr)
*** 4295,4301 ****
static tree
dummy_object (tree type)
{
! tree t = convert (build_pointer_type (type), null_pointer_node);
return build1 (INDIRECT_REF, type, t);
}
--- 4295,4301 ----
static tree
dummy_object (tree type)
{
! tree t = build_int_cst (build_pointer_type (type), 0);
return build1 (INDIRECT_REF, type, t);
}
Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c (revision 112438)
--- tree-ssa-ccp.c (working copy)
*************** maybe_fold_stmt_addition (tree expr)
*** 1879,1885 ****
if (TREE_CODE (min_idx) != INTEGER_CST)
break;
! array_idx = convert (TREE_TYPE (min_idx), array_idx);
if (!integer_zerop (min_idx))
array_idx = int_const_binop (MINUS_EXPR, array_idx,
min_idx, 0);
--- 1879,1885 ----
if (TREE_CODE (min_idx) != INTEGER_CST)
break;
! array_idx = fold_convert (TREE_TYPE (min_idx), array_idx);
if (!integer_zerop (min_idx))
array_idx = int_const_binop (MINUS_EXPR, array_idx,
min_idx, 0);
*************** maybe_fold_stmt_addition (tree expr)
*** 1887,1893 ****
}
/* Convert the index to a byte offset. */
! array_idx = convert (sizetype, array_idx);
array_idx = int_const_binop (MULT_EXPR, array_idx, elt_size, 0);
/* Update the operands for the next round, or for folding. */
--- 1887,1893 ----
}
/* Convert the index to a byte offset. */
! array_idx = fold_convert (sizetype, array_idx);
array_idx = int_const_binop (MULT_EXPR, array_idx, elt_size, 0);
/* Update the operands for the next round, or for folding. */
Index: dojump.c
===================================================================
*** dojump.c (revision 112438)
--- dojump.c (working copy)
*************** do_jump (tree exp, rtx if_false_label, r
*** 277,283 ****
&& (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
!= CODE_FOR_nothing))
{
! do_jump (convert (type, exp), if_false_label, if_true_label);
break;
}
goto normal;
--- 277,283 ----
&& (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
!= CODE_FOR_nothing))
{
! do_jump (fold_convert (type, exp), if_false_label, if_true_label);
break;
}
goto normal;
*************** do_jump (tree exp, rtx if_false_label, r
*** 336,342 ****
&& (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
!= CODE_FOR_nothing))
{
! do_jump (convert (type, exp), if_false_label, if_true_label);
break;
}
goto normal;
--- 336,342 ----
&& (cmp_optab->handlers[(int) TYPE_MODE (type)].insn_code
!= CODE_FOR_nothing))
{
! do_jump (fold_convert (type, exp), if_false_label, if_true_label);
break;
}
goto normal;
Index: expr.h
===================================================================
*** expr.h (revision 112438)
--- expr.h (working copy)
*************** Software Foundation, 51 Franklin Street,
*** 29,36 ****
#include "rtl.h"
/* For optimize_size */
#include "flags.h"
! /* For host_integerp, tree_low_cst, convert, size_binop, ssize_int, TREE_CODE,
! TYPE_SIZE, int_size_in_bytes, */
#include "tree.h"
/* For GET_MODE_BITSIZE, word_mode */
#include "machmode.h"
--- 29,36 ----
#include "rtl.h"
/* For optimize_size */
#include "flags.h"
! /* For host_integerp, tree_low_cst, fold_convert, size_binop, ssize_int,
! TREE_CODE, TYPE_SIZE, int_size_in_bytes, */
#include "tree.h"
/* For GET_MODE_BITSIZE, word_mode */
#include "machmode.h"
*************** struct locate_and_pad_arg_data
*** 123,158 ****
/* Add the value of the tree INC to the `struct args_size' TO. */
! #define ADD_PARM_SIZE(TO, INC) \
! do { \
! tree inc = (INC); \
! if (host_integerp (inc, 0)) \
! (TO).constant += tree_low_cst (inc, 0); \
! else if ((TO).var == 0) \
! (TO).var = convert (ssizetype, inc); \
! else \
! (TO).var = size_binop (PLUS_EXPR, (TO).var, \
! convert (ssizetype, inc)); \
} while (0)
! #define SUB_PARM_SIZE(TO, DEC) \
! do { \
! tree dec = (DEC); \
! if (host_integerp (dec, 0)) \
! (TO).constant -= tree_low_cst (dec, 0); \
! else if ((TO).var == 0) \
! (TO).var = size_binop (MINUS_EXPR, ssize_int (0), \
! convert (ssizetype, dec)); \
! else \
! (TO).var = size_binop (MINUS_EXPR, (TO).var, \
! convert (ssizetype, dec)); \
} while (0)
/* Convert the implicit sum in a `struct args_size' into a tree
of type ssizetype. */
#define ARGS_SIZE_TREE(SIZE) \
((SIZE).var == 0 ? ssize_int ((SIZE).constant) \
! : size_binop (PLUS_EXPR, convert (ssizetype, (SIZE).var), \
ssize_int ((SIZE).constant)))
/* Convert the implicit sum in a `struct args_size' into an rtx. */
--- 123,158 ----
/* Add the value of the tree INC to the `struct args_size' TO. */
! #define ADD_PARM_SIZE(TO, INC) \
! do { \
! tree inc = (INC); \
! if (host_integerp (inc, 0)) \
! (TO).constant += tree_low_cst (inc, 0); \
! else if ((TO).var == 0) \
! (TO).var = fold_convert (ssizetype, inc); \
! else \
! (TO).var = size_binop (PLUS_EXPR, (TO).var, \
! fold_convert (ssizetype, inc)); \
} while (0)
! #define SUB_PARM_SIZE(TO, DEC) \
! do { \
! tree dec = (DEC); \
! if (host_integerp (dec, 0)) \
! (TO).constant -= tree_low_cst (dec, 0); \
! else if ((TO).var == 0) \
! (TO).var = size_binop (MINUS_EXPR, ssize_int (0), \
! fold_convert (ssizetype, dec)); \
! else \
! (TO).var = size_binop (MINUS_EXPR, (TO).var, \
! fold_convert (ssizetype, dec)); \
} while (0)
/* Convert the implicit sum in a `struct args_size' into a tree
of type ssizetype. */
#define ARGS_SIZE_TREE(SIZE) \
((SIZE).var == 0 ? ssize_int ((SIZE).constant) \
! : size_binop (PLUS_EXPR, fold_convert (ssizetype, (SIZE).var), \
ssize_int ((SIZE).constant)))
/* Convert the implicit sum in a `struct args_size' into an rtx. */
Index: gimplify.c
===================================================================
*** gimplify.c (revision 112438)
--- gimplify.c (working copy)
*************** gimple_boolify (tree expr)
*** 2340,2346 ****
default:
/* Other expressions that get here must have boolean values, but
might need to be converted to the appropriate mode. */
! return convert (boolean_type_node, expr);
}
}
--- 2340,2346 ----
default:
/* Other expressions that get here must have boolean values, but
might need to be converted to the appropriate mode. */
! return fold_convert (boolean_type_node, expr);
}
}
*************** gimplify_init_constructor (tree *expr_p,
*** 3042,3048 ****
i = VEC_index (constructor_elt, elts, 1)->value;
if (r == NULL || i == NULL)
{
! tree zero = convert (TREE_TYPE (type), integer_zero_node);
if (r == NULL)
r = zero;
if (i == NULL)
--- 3042,3048 ----
i = VEC_index (constructor_elt, elts, 1)->value;
if (r == NULL || i == NULL)
{
! tree zero = fold_convert (TREE_TYPE (type), integer_zero_node);
if (r == NULL)
r = zero;
if (i == NULL)
*************** gimplify_boolean_expr (tree *expr_p)
*** 3545,3552 ****
tree type = TREE_TYPE (*expr_p);
*expr_p = build3 (COND_EXPR, type, *expr_p,
! convert (type, boolean_true_node),
! convert (type, boolean_false_node));
return GS_OK;
}
--- 3545,3552 ----
tree type = TREE_TYPE (*expr_p);
*expr_p = build3 (COND_EXPR, type, *expr_p,
! fold_convert (type, boolean_true_node),
! fold_convert (type, boolean_false_node));
return GS_OK;
}
Index: emit-rtl.c
===================================================================
*** emit-rtl.c (revision 112438)
--- emit-rtl.c (working copy)
*************** set_mem_attributes_minus_bitpos (rtx ref
*** 1596,1603 ****
index, low_bound);
off_tree = size_binop (PLUS_EXPR,
! size_binop (MULT_EXPR, convert (sizetype,
! index),
unit_size),
off_tree);
t2 = TREE_OPERAND (t2, 0);
--- 1596,1604 ----
index, low_bound);
off_tree = size_binop (PLUS_EXPR,
! size_binop (MULT_EXPR,
! fold_convert (sizetype,
! index),
unit_size),
off_tree);
t2 = TREE_OPERAND (t2, 0);
Index: varasm.c
===================================================================
*** varasm.c (revision 112438)
--- varasm.c (working copy)
*************** array_size_for_constructor (tree val)
*** 4137,4143 ****
{
tree max_index, i;
unsigned HOST_WIDE_INT cnt;
! tree index, value;
/* This code used to attempt to handle string constants that are not
arrays of single-bytes, but nothing else does, so there's no point in
--- 4137,4143 ----
{
tree max_index, i;
unsigned HOST_WIDE_INT cnt;
! tree index, value, tmp;
/* This code used to attempt to handle string constants that are not
arrays of single-bytes, but nothing else does, so there's no point in
*************** array_size_for_constructor (tree val)
*** 4158,4166 ****
return 0;
/* Compute the total number of array elements. */
! i = size_binop (MINUS_EXPR, convert (sizetype, max_index),
! convert (sizetype,
! TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)))));
i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
/* Multiply by the array element unit size to find number of bytes. */
--- 4158,4166 ----
return 0;
/* Compute the total number of array elements. */
! tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
! i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index),
! fold_convert (sizetype, tmp));
i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1));
/* Multiply by the array element unit size to find number of bytes. */
Index: tree-object-size.c
===================================================================
*** tree-object-size.c (revision 112438)
--- tree-object-size.c (working copy)
*************** compute_object_offset (tree expr, tree v
*** 134,140 ****
code = MINUS_EXPR;
t = fold_build1 (NEGATE_EXPR, TREE_TYPE (t), t);
}
! t = convert (sizetype, t);
off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
break;
--- 134,140 ----
code = MINUS_EXPR;
t = fold_build1 (NEGATE_EXPR, TREE_TYPE (t), t);
}
! t = fold_convert (sizetype, t);
off = size_binop (MULT_EXPR, TYPE_SIZE_UNIT (TREE_TYPE (expr)), t);
break;
Roger
--