Commit 9645c3c5 by Roger Sayle Committed by Roger Sayle

cuintp.c (UI_To_gnu): Use fold_buildN calls instead of calling fold with the result of buildN.


	* cuintp.c (UI_To_gnu): Use fold_buildN calls instead of calling
	fold with the result of buildN.
	* decl.c (gnat_to_gnu_entity): Likewise.
	* trans.c (Attribute_to_gnu, gnat_to_gnu, emit_check): Likewise.
	* utils.c (finish_record_type, merge_sizes, max_size, convert):
	Likewise.
	* utils2.c (gnat_truthvalue_conversion, compare_arrays,
	nonbinary_modular_operation, build_binary_op, build_unary_op,
	build_cond_expr): Likewise.

	* utils.c (convert): Use fold_build1 when casting values to void.
	* utils2.c (gnat_truthvalue_conversion): Use build_int_cst and
	fold_convert instead of convert when appropriate.

From-SVN: r122752
parent 63a08740
2007-03-09 Roger Sayle <roger@eyesopen.com>
* cuintp.c (UI_To_gnu): Use fold_buildN calls instead of calling
fold with the result of buildN.
* decl.c (gnat_to_gnu_entity): Likewise.
* trans.c (Attribute_to_gnu, gnat_to_gnu, emit_check): Likewise.
* utils.c (finish_record_type, merge_sizes, max_size, convert):
Likewise.
* utils2.c (gnat_truthvalue_conversion, compare_arrays,
nonbinary_modular_operation, build_binary_op, build_unary_op,
build_cond_expr): Likewise.
* utils.c (convert): Use fold_build1 when casting values to void.
* utils2.c (gnat_truthvalue_conversion): Use build_int_cst and
fold_convert instead of convert when appropriate.
2007-03-01 Brooks Moses <brooks.moses@codesourcery.com> 2007-03-01 Brooks Moses <brooks.moses@codesourcery.com>
* Make-lang.in: Add install-pdf target as copied from * Make-lang.in: Add install-pdf target as copied from
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* * * *
* C Implementation File * * C Implementation File *
* * * *
* Copyright (C) 1992-2005 Free Software Foundation, Inc. * * Copyright (C) 1992-2007 Free Software Foundation, Inc. *
* * * *
* GNAT is free software; you can redistribute it and/or modify it under * * GNAT is free software; you can redistribute it and/or modify it under *
* terms of the GNU General Public License as published by the Free Soft- * * terms of the GNU General Public License as published by the Free Soft- *
...@@ -113,18 +113,18 @@ UI_To_gnu (Uint Input, tree type) ...@@ -113,18 +113,18 @@ UI_To_gnu (Uint Input, tree type)
gnu_ret = build_cst_from_int (comp_type, First); gnu_ret = build_cst_from_int (comp_type, First);
if (First < 0) if (First < 0)
for (Idx++, Length--; Length; Idx++, Length--) for (Idx++, Length--; Length; Idx++, Length--)
gnu_ret = fold (build2 (MINUS_EXPR, comp_type, gnu_ret = fold_build2 (MINUS_EXPR, comp_type,
fold (build2 (MULT_EXPR, comp_type, fold_build2 (MULT_EXPR, comp_type,
gnu_ret, gnu_base)), gnu_ret, gnu_base),
build_cst_from_int (comp_type, build_cst_from_int (comp_type,
Udigits_Ptr[Idx]))); Udigits_Ptr[Idx]));
else else
for (Idx++, Length--; Length; Idx++, Length--) for (Idx++, Length--; Length; Idx++, Length--)
gnu_ret = fold (build2 (PLUS_EXPR, comp_type, gnu_ret = fold_build2 (PLUS_EXPR, comp_type,
fold (build2 (MULT_EXPR, comp_type, fold_build2 (MULT_EXPR, comp_type,
gnu_ret, gnu_base)), gnu_ret, gnu_base),
build_cst_from_int (comp_type, build_cst_from_int (comp_type,
Udigits_Ptr[Idx]))); Udigits_Ptr[Idx]));
} }
gnu_ret = convert (type, gnu_ret); gnu_ret = convert (type, gnu_ret);
......
...@@ -1332,8 +1332,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1332,8 +1332,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
{ {
TYPE_MODULAR_P (gnu_type) = 1; TYPE_MODULAR_P (gnu_type) = 1;
SET_TYPE_MODULUS (gnu_type, gnu_modulus); SET_TYPE_MODULUS (gnu_type, gnu_modulus);
gnu_high = fold (build2 (MINUS_EXPR, gnu_type, gnu_modulus, gnu_high = fold_build2 (MINUS_EXPR, gnu_type, gnu_modulus,
convert (gnu_type, integer_one_node))); convert (gnu_type, integer_one_node));
} }
/* If we have to set TYPE_PRECISION different from its natural value, /* If we have to set TYPE_PRECISION different from its natural value,
...@@ -1909,10 +1909,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition) ...@@ -1909,10 +1909,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
&& TREE_CODE (gnu_max) == INTEGER_CST && TREE_CODE (gnu_max) == INTEGER_CST
&& TREE_OVERFLOW (gnu_min) && TREE_OVERFLOW (gnu_max) && TREE_OVERFLOW (gnu_min) && TREE_OVERFLOW (gnu_max)
&& (!TREE_OVERFLOW && (!TREE_OVERFLOW
(fold (build2 (MINUS_EXPR, gnu_index_subtype, (fold_build2 (MINUS_EXPR, gnu_index_subtype,
TYPE_MAX_VALUE (gnu_index_subtype), TYPE_MAX_VALUE (gnu_index_subtype),
TYPE_MIN_VALUE (gnu_index_subtype)))))) TYPE_MIN_VALUE (gnu_index_subtype)))))
TREE_OVERFLOW (gnu_min) = TREE_OVERFLOW (gnu_max) = 0; {
TREE_OVERFLOW (gnu_min) = 0;
TREE_OVERFLOW (gnu_max) = 0;
}
/* Similarly, if the range is null, use bounds of 1..0 for /* Similarly, if the range is null, use bounds of 1..0 for
the sizetype bounds. */ the sizetype bounds. */
......
...@@ -782,8 +782,8 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) ...@@ -782,8 +782,8 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
if (attribute == Attr_Max_Size_In_Storage_Elements) if (attribute == Attr_Max_Size_In_Storage_Elements)
gnu_result = convert (sizetype, gnu_result = convert (sizetype,
fold (build2 (CEIL_DIV_EXPR, bitsizetype, fold_build2 (CEIL_DIV_EXPR, bitsizetype,
gnu_result, bitsize_unit_node))); gnu_result, bitsize_unit_node));
break; break;
case Attr_Alignment: case Attr_Alignment:
...@@ -1100,8 +1100,8 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute) ...@@ -1100,8 +1100,8 @@ Attribute_to_gnu (Node_Id gnat_node, tree *gnu_result_type_p, int attribute)
example in AARM 11.6(5.e). */ example in AARM 11.6(5.e). */
if (prefix_unused && TREE_SIDE_EFFECTS (gnu_prefix) if (prefix_unused && TREE_SIDE_EFFECTS (gnu_prefix)
&& !Is_Entity_Name (Prefix (gnat_node))) && !Is_Entity_Name (Prefix (gnat_node)))
gnu_result = fold (build2 (COMPOUND_EXPR, TREE_TYPE (gnu_result), gnu_result = fold_build2 (COMPOUND_EXPR, TREE_TYPE (gnu_result),
gnu_prefix, gnu_result)); gnu_prefix, gnu_result);
*gnu_result_type_p = gnu_result_type; *gnu_result_type_p = gnu_result_type;
return gnu_result; return gnu_result;
...@@ -3079,13 +3079,13 @@ gnat_to_gnu (Node_Id gnat_node) ...@@ -3079,13 +3079,13 @@ gnat_to_gnu (Node_Id gnat_node)
expression if the slice range is not null (max >= min) or expression if the slice range is not null (max >= min) or
returns the min if the slice range is null */ returns the min if the slice range is null */
gnu_expr gnu_expr
= fold (build3 (COND_EXPR, gnu_expr_type, = fold_build3 (COND_EXPR, gnu_expr_type,
build_binary_op (GE_EXPR, gnu_expr_type, build_binary_op (GE_EXPR, gnu_expr_type,
convert (gnu_expr_type, convert (gnu_expr_type,
gnu_max_expr), gnu_max_expr),
convert (gnu_expr_type, convert (gnu_expr_type,
gnu_min_expr)), gnu_min_expr)),
gnu_expr, gnu_min_expr)); gnu_expr, gnu_min_expr);
} }
else else
gnu_expr = TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_result_type)); gnu_expr = TYPE_MIN_VALUE (TYPE_DOMAIN (gnu_result_type));
...@@ -5403,10 +5403,10 @@ emit_check (tree gnu_cond, tree gnu_expr, int reason) ...@@ -5403,10 +5403,10 @@ emit_check (tree gnu_cond, tree gnu_expr, int reason)
in front of the comparison in case it ends up being a SAVE_EXPR. Put the in front of the comparison in case it ends up being a SAVE_EXPR. Put the
whole thing inside its own SAVE_EXPR so the inner SAVE_EXPR doesn't leak whole thing inside its own SAVE_EXPR so the inner SAVE_EXPR doesn't leak
out. */ out. */
gnu_result = fold (build3 (COND_EXPR, TREE_TYPE (gnu_expr), gnu_cond, gnu_result = fold_build3 (COND_EXPR, TREE_TYPE (gnu_expr), gnu_cond,
build2 (COMPOUND_EXPR, TREE_TYPE (gnu_expr), build2 (COMPOUND_EXPR, TREE_TYPE (gnu_expr),
gnu_call, gnu_expr), gnu_call, gnu_expr),
gnu_expr)); gnu_expr);
/* If GNU_EXPR has side effects, make the outer COMPOUND_EXPR and /* If GNU_EXPR has side effects, make the outer COMPOUND_EXPR and
protect it. Otherwise, show GNU_RESULT has no side effects: we protect it. Otherwise, show GNU_RESULT has no side effects: we
......
...@@ -868,10 +868,10 @@ finish_record_type (tree record_type, tree fieldlist, bool has_rep, ...@@ -868,10 +868,10 @@ finish_record_type (tree record_type, tree fieldlist, bool has_rep,
case QUAL_UNION_TYPE: case QUAL_UNION_TYPE:
ada_size ada_size
= fold (build3 (COND_EXPR, bitsizetype, DECL_QUALIFIER (field), = fold_build3 (COND_EXPR, bitsizetype, DECL_QUALIFIER (field),
this_ada_size, ada_size)); this_ada_size, ada_size);
size = fold (build3 (COND_EXPR, bitsizetype, DECL_QUALIFIER (field), size = fold_build3 (COND_EXPR, bitsizetype, DECL_QUALIFIER (field),
this_size, size)); this_size, size);
break; break;
case RECORD_TYPE: case RECORD_TYPE:
...@@ -1133,15 +1133,15 @@ merge_sizes (tree last_size, tree first_bit, tree size, bool special, ...@@ -1133,15 +1133,15 @@ merge_sizes (tree last_size, tree first_bit, tree size, bool special,
} }
else else
new = fold (build3 (COND_EXPR, type, TREE_OPERAND (size, 0), new = fold_build3 (COND_EXPR, type, TREE_OPERAND (size, 0),
integer_zerop (TREE_OPERAND (size, 1)) integer_zerop (TREE_OPERAND (size, 1))
? last_size : merge_sizes (last_size, first_bit, ? last_size : merge_sizes (last_size, first_bit,
TREE_OPERAND (size, 1), TREE_OPERAND (size, 1),
1, has_rep), 1, has_rep),
integer_zerop (TREE_OPERAND (size, 2)) integer_zerop (TREE_OPERAND (size, 2))
? last_size : merge_sizes (last_size, first_bit, ? last_size : merge_sizes (last_size, first_bit,
TREE_OPERAND (size, 2), TREE_OPERAND (size, 2),
1, has_rep))); 1, has_rep));
/* We don't need any NON_VALUE_EXPRs and they can confuse us (especially /* We don't need any NON_VALUE_EXPRs and they can confuse us (especially
when fed through substitute_in_expr) into thinking that a constant when fed through substitute_in_expr) into thinking that a constant
...@@ -2372,9 +2372,9 @@ max_size (tree exp, bool max_p) ...@@ -2372,9 +2372,9 @@ max_size (tree exp, bool max_p)
return max_size (TREE_OPERAND (exp, 0), max_p); return max_size (TREE_OPERAND (exp, 0), max_p);
else else
return return
fold (build1 (code, type, fold_build1 (code, type,
max_size (TREE_OPERAND (exp, 0), max_size (TREE_OPERAND (exp, 0),
code == NEGATE_EXPR ? !max_p : max_p))); code == NEGATE_EXPR ? !max_p : max_p));
case 2: case 2:
if (code == COMPOUND_EXPR) if (code == COMPOUND_EXPR)
...@@ -2424,16 +2424,16 @@ max_size (tree exp, bool max_p) ...@@ -2424,16 +2424,16 @@ max_size (tree exp, bool max_p)
&& !TREE_CONSTANT (rhs)) && !TREE_CONSTANT (rhs))
return lhs; return lhs;
else else
return fold (build2 (code, type, lhs, rhs)); return fold_build2 (code, type, lhs, rhs);
} }
case 3: case 3:
if (code == SAVE_EXPR) if (code == SAVE_EXPR)
return exp; return exp;
else if (code == COND_EXPR) else if (code == COND_EXPR)
return fold (build2 (max_p ? MAX_EXPR : MIN_EXPR, type, return fold_build2 (max_p ? MAX_EXPR : MIN_EXPR, type,
max_size (TREE_OPERAND (exp, 1), max_p), max_size (TREE_OPERAND (exp, 1), max_p),
max_size (TREE_OPERAND (exp, 2), max_p))); max_size (TREE_OPERAND (exp, 2), max_p));
} }
/* Other tree classes cannot happen. */ /* Other tree classes cannot happen. */
...@@ -3167,10 +3167,10 @@ convert (tree type, tree expr) ...@@ -3167,10 +3167,10 @@ convert (tree type, tree expr)
/* If the input is a biased type, adjust first. */ /* If the input is a biased type, adjust first. */
if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)) if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype))
return convert (type, fold (build2 (PLUS_EXPR, TREE_TYPE (etype), return convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (etype),
fold_convert (TREE_TYPE (etype), fold_convert (TREE_TYPE (etype),
expr), expr),
TYPE_MIN_VALUE (etype)))); TYPE_MIN_VALUE (etype)));
/* If the input is a justified modular type, we need to extract the actual /* If the input is a justified modular type, we need to extract the actual
object before converting it to any other type with the exceptions of an object before converting it to any other type with the exceptions of an
...@@ -3321,7 +3321,7 @@ convert (tree type, tree expr) ...@@ -3321,7 +3321,7 @@ convert (tree type, tree expr)
switch (code) switch (code)
{ {
case VOID_TYPE: case VOID_TYPE:
return build1 (CONVERT_EXPR, type, expr); return fold_build1 (CONVERT_EXPR, type, expr);
case BOOLEAN_TYPE: case BOOLEAN_TYPE:
return fold_convert (type, gnat_truthvalue_conversion (expr)); return fold_convert (type, gnat_truthvalue_conversion (expr));
......
...@@ -87,23 +87,27 @@ gnat_truthvalue_conversion (tree expr) ...@@ -87,23 +87,27 @@ gnat_truthvalue_conversion (tree expr)
return expr; return expr;
case INTEGER_CST: case INTEGER_CST:
return (integer_zerop (expr) ? convert (type, integer_zero_node) return (integer_zerop (expr)
: convert (type, integer_one_node)); ? build_int_cst (type, 0)
: build_int_cst (type, 1));
case REAL_CST: case REAL_CST:
return (real_zerop (expr) ? convert (type, integer_zero_node) return (real_zerop (expr)
: convert (type, integer_one_node)); ? fold_convert (type, integer_zero_node)
: fold_convert (type, integer_one_node));
case COND_EXPR: case COND_EXPR:
/* Distribute the conversion into the arms of a COND_EXPR. */ /* Distribute the conversion into the arms of a COND_EXPR. */
return fold {
(build3 (COND_EXPR, type, TREE_OPERAND (expr, 0), tree arg1 = gnat_truthvalue_conversion (TREE_OPERAND (expr, 1));
gnat_truthvalue_conversion (TREE_OPERAND (expr, 1)), tree arg2 = gnat_truthvalue_conversion (TREE_OPERAND (expr, 2));
gnat_truthvalue_conversion (TREE_OPERAND (expr, 2)))); return fold_build3 (COND_EXPR, type, TREE_OPERAND (expr, 0),
arg1, arg2);
}
default: default:
return build_binary_op (NE_EXPR, type, expr, return build_binary_op (NE_EXPR, type, expr,
convert (type, integer_zero_node)); fold_convert (type, integer_zero_node));
} }
} }
...@@ -351,8 +355,8 @@ compare_arrays (tree result_type, tree a1, tree a2) ...@@ -351,8 +355,8 @@ compare_arrays (tree result_type, tree a1, tree a2)
tree lb2 = TYPE_MIN_VALUE (TYPE_DOMAIN (t2)); tree lb2 = TYPE_MIN_VALUE (TYPE_DOMAIN (t2));
tree ub2 = TYPE_MAX_VALUE (TYPE_DOMAIN (t2)); tree ub2 = TYPE_MAX_VALUE (TYPE_DOMAIN (t2));
tree bt = get_base_type (TREE_TYPE (lb1)); tree bt = get_base_type (TREE_TYPE (lb1));
tree length1 = fold (build2 (MINUS_EXPR, bt, ub1, lb1)); tree length1 = fold_build2 (MINUS_EXPR, bt, ub1, lb1);
tree length2 = fold (build2 (MINUS_EXPR, bt, ub2, lb2)); tree length2 = fold_build2 (MINUS_EXPR, bt, ub2, lb2);
tree nbt; tree nbt;
tree tem; tree tem;
tree comparison, this_a1_is_null, this_a2_is_null; tree comparison, this_a1_is_null, this_a2_is_null;
...@@ -361,8 +365,8 @@ compare_arrays (tree result_type, tree a1, tree a2) ...@@ -361,8 +365,8 @@ compare_arrays (tree result_type, tree a1, tree a2)
unless the length of the second array is the constant zero. unless the length of the second array is the constant zero.
Note that we have set the `length' values to the length - 1. */ Note that we have set the `length' values to the length - 1. */
if (TREE_CODE (length1) == INTEGER_CST if (TREE_CODE (length1) == INTEGER_CST
&& !integer_zerop (fold (build2 (PLUS_EXPR, bt, length2, && !integer_zerop (fold_build2 (PLUS_EXPR, bt, length2,
convert (bt, integer_one_node))))) convert (bt, integer_one_node))))
{ {
tem = a1, a1 = a2, a2 = tem; tem = a1, a1 = a2, a2 = tem;
tem = t1, t1 = t2, t2 = tem; tem = t1, t1 = t2, t2 = tem;
...@@ -375,8 +379,8 @@ compare_arrays (tree result_type, tree a1, tree a2) ...@@ -375,8 +379,8 @@ compare_arrays (tree result_type, tree a1, tree a2)
/* If the length of this dimension in the second array is the constant /* If the length of this dimension in the second array is the constant
zero, we can just go inside the original bounds for the first zero, we can just go inside the original bounds for the first
array and see if last < first. */ array and see if last < first. */
if (integer_zerop (fold (build2 (PLUS_EXPR, bt, length2, if (integer_zerop (fold_build2 (PLUS_EXPR, bt, length2,
convert (bt, integer_one_node))))) convert (bt, integer_one_node))))
{ {
tree ub = TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (t1))); tree ub = TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (t1)));
tree lb = TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (t1))); tree lb = TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (t1)));
...@@ -455,7 +459,7 @@ compare_arrays (tree result_type, tree a1, tree a2) ...@@ -455,7 +459,7 @@ compare_arrays (tree result_type, tree a1, tree a2)
a1 = convert (type, a1), a2 = convert (type, a2); a1 = convert (type, a1), a2 = convert (type, a2);
result = build_binary_op (TRUTH_ANDIF_EXPR, result_type, result, result = build_binary_op (TRUTH_ANDIF_EXPR, result_type, result,
fold (build2 (EQ_EXPR, result_type, a1, a2))); fold_build2 (EQ_EXPR, result_type, a1, a2));
} }
...@@ -496,7 +500,10 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs, ...@@ -496,7 +500,10 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs,
/* If this is an addition of a constant, convert it to a subtraction /* If this is an addition of a constant, convert it to a subtraction
of a constant since we can do that faster. */ of a constant since we can do that faster. */
if (op_code == PLUS_EXPR && TREE_CODE (rhs) == INTEGER_CST) if (op_code == PLUS_EXPR && TREE_CODE (rhs) == INTEGER_CST)
rhs = fold (build2 (MINUS_EXPR, type, modulus, rhs)), op_code = MINUS_EXPR; {
rhs = fold_build2 (MINUS_EXPR, type, modulus, rhs);
op_code = MINUS_EXPR;
}
/* For the logical operations, we only need PRECISION bits. For /* For the logical operations, we only need PRECISION bits. For
addition and subtraction, we need one more and for multiplication we addition and subtraction, we need one more and for multiplication we
...@@ -528,7 +535,7 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs, ...@@ -528,7 +535,7 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs,
} }
/* Do the operation, then we'll fix it up. */ /* Do the operation, then we'll fix it up. */
result = fold (build2 (op_code, op_type, lhs, rhs)); result = fold_build2 (op_code, op_type, lhs, rhs);
/* For multiplication, we have no choice but to do a full modulus /* For multiplication, we have no choice but to do a full modulus
operation. However, we want to do this in the narrowest operation. However, we want to do this in the narrowest
...@@ -540,32 +547,31 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs, ...@@ -540,32 +547,31 @@ nonbinary_modular_operation (enum tree_code op_code, tree type, tree lhs,
SET_TYPE_MODULUS (div_type, modulus); SET_TYPE_MODULUS (div_type, modulus);
TYPE_MODULAR_P (div_type) = 1; TYPE_MODULAR_P (div_type) = 1;
result = convert (op_type, result = convert (op_type,
fold (build2 (TRUNC_MOD_EXPR, div_type, fold_build2 (TRUNC_MOD_EXPR, div_type,
convert (div_type, result), modulus))); convert (div_type, result), modulus));
} }
/* For subtraction, add the modulus back if we are negative. */ /* For subtraction, add the modulus back if we are negative. */
else if (op_code == MINUS_EXPR) else if (op_code == MINUS_EXPR)
{ {
result = save_expr (result); result = save_expr (result);
result = fold (build3 (COND_EXPR, op_type, result = fold_build3 (COND_EXPR, op_type,
build2 (LT_EXPR, integer_type_node, result, fold_build2 (LT_EXPR, integer_type_node, result,
convert (op_type, integer_zero_node)), convert (op_type, integer_zero_node)),
fold (build2 (PLUS_EXPR, op_type, fold_build2 (PLUS_EXPR, op_type, result, modulus),
result, modulus)), result);
result));
} }
/* For the other operations, subtract the modulus if we are >= it. */ /* For the other operations, subtract the modulus if we are >= it. */
else else
{ {
result = save_expr (result); result = save_expr (result);
result = fold (build3 (COND_EXPR, op_type, result = fold_build3 (COND_EXPR, op_type,
build2 (GE_EXPR, integer_type_node, fold_build2 (GE_EXPR, integer_type_node,
result, modulus), result, modulus),
fold (build2 (MINUS_EXPR, op_type, fold_build2 (MINUS_EXPR, op_type,
result, modulus)), result, modulus),
result)); result);
} }
return convert (type, result); return convert (type, result);
...@@ -955,11 +961,11 @@ build_binary_op (enum tree_code op_code, tree result_type, ...@@ -955,11 +961,11 @@ build_binary_op (enum tree_code op_code, tree result_type,
else if (TREE_CODE (right_operand) == NULL_EXPR) else if (TREE_CODE (right_operand) == NULL_EXPR)
return build1 (NULL_EXPR, operation_type, TREE_OPERAND (right_operand, 0)); return build1 (NULL_EXPR, operation_type, TREE_OPERAND (right_operand, 0));
else if (op_code == ARRAY_REF || op_code == ARRAY_RANGE_REF) else if (op_code == ARRAY_REF || op_code == ARRAY_RANGE_REF)
result = fold (build4 (op_code, operation_type, left_operand, result = build4 (op_code, operation_type, left_operand,
right_operand, NULL_TREE, NULL_TREE)); right_operand, NULL_TREE, NULL_TREE);
else else
result result
= fold (build2 (op_code, operation_type, left_operand, right_operand)); = fold_build2 (op_code, operation_type, left_operand, right_operand);
TREE_SIDE_EFFECTS (result) |= has_side_effects; TREE_SIDE_EFFECTS (result) |= has_side_effects;
TREE_CONSTANT (result) TREE_CONSTANT (result)
...@@ -973,8 +979,8 @@ build_binary_op (enum tree_code op_code, tree result_type, ...@@ -973,8 +979,8 @@ build_binary_op (enum tree_code op_code, tree result_type,
/* If we are working with modular types, perform the MOD operation /* If we are working with modular types, perform the MOD operation
if something above hasn't eliminated the need for it. */ if something above hasn't eliminated the need for it. */
if (modulus) if (modulus)
result = fold (build2 (FLOOR_MOD_EXPR, operation_type, result, result = fold_build2 (FLOOR_MOD_EXPR, operation_type, result,
convert (operation_type, modulus))); convert (operation_type, modulus));
if (result_type && result_type != operation_type) if (result_type && result_type != operation_type)
result = convert (result_type, result); result = convert (result_type, result);
...@@ -1012,7 +1018,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1012,7 +1018,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
else else
gcc_assert (result_type == TREE_TYPE (type)); gcc_assert (result_type == TREE_TYPE (type));
result = fold (build1 (op_code, operation_type, operand)); result = fold_build1 (op_code, operation_type, operand);
break; break;
case TRUTH_NOT_EXPR: case TRUTH_NOT_EXPR:
...@@ -1160,7 +1166,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1160,7 +1166,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
operation_type = build_pointer_type (type); operation_type = build_pointer_type (type);
gnat_mark_addressable (operand); gnat_mark_addressable (operand);
result = fold (build1 (ADDR_EXPR, operation_type, operand)); result = fold_build1 (ADDR_EXPR, operation_type, operand);
} }
TREE_CONSTANT (result) = staticp (operand) || TREE_CONSTANT (operand); TREE_CONSTANT (result) = staticp (operand) || TREE_CONSTANT (operand);
...@@ -1192,7 +1198,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1192,7 +1198,7 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
else else
{ {
result = fold (build1 (op_code, TREE_TYPE (type), operand)); result = fold_build1 (op_code, TREE_TYPE (type), operand);
TREE_READONLY (result) = TYPE_READONLY (TREE_TYPE (type)); TREE_READONLY (result) = TYPE_READONLY (TREE_TYPE (type));
} }
...@@ -1222,10 +1228,10 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1222,10 +1228,10 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
the straightforward code; the TRUNC_MOD_EXPR below the straightforward code; the TRUNC_MOD_EXPR below
is an AND operation. */ is an AND operation. */
if (op_code == NEGATE_EXPR && mod_pow2) if (op_code == NEGATE_EXPR && mod_pow2)
result = fold (build2 (TRUNC_MOD_EXPR, operation_type, result = fold_build2 (TRUNC_MOD_EXPR, operation_type,
fold (build1 (NEGATE_EXPR, operation_type, fold_build1 (NEGATE_EXPR, operation_type,
operand)), operand),
modulus)); modulus);
/* For nonbinary negate case, return zero for zero operand, /* For nonbinary negate case, return zero for zero operand,
else return the modulus minus the operand. If the modulus else return the modulus minus the operand. If the modulus
...@@ -1233,24 +1239,24 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1233,24 +1239,24 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
as an XOR since it is equivalent and faster on most machines. */ as an XOR since it is equivalent and faster on most machines. */
else if (op_code == NEGATE_EXPR && !mod_pow2) else if (op_code == NEGATE_EXPR && !mod_pow2)
{ {
if (integer_pow2p (fold (build2 (PLUS_EXPR, operation_type, if (integer_pow2p (fold_build2 (PLUS_EXPR, operation_type,
modulus, modulus,
convert (operation_type, convert (operation_type,
integer_one_node))))) integer_one_node))))
result = fold (build2 (BIT_XOR_EXPR, operation_type, result = fold_build2 (BIT_XOR_EXPR, operation_type,
operand, modulus)); operand, modulus);
else else
result = fold (build2 (MINUS_EXPR, operation_type, result = fold_build2 (MINUS_EXPR, operation_type,
modulus, operand)); modulus, operand);
result = fold (build3 (COND_EXPR, operation_type, result = fold_build3 (COND_EXPR, operation_type,
fold (build2 (NE_EXPR, fold_build2 (NE_EXPR,
integer_type_node, integer_type_node,
operand, operand,
convert convert
(operation_type, (operation_type,
integer_zero_node))), integer_zero_node)),
result, operand)); result, operand);
} }
else else
{ {
...@@ -1259,16 +1265,16 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1259,16 +1265,16 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
XOR against the constant and subtract the operand from XOR against the constant and subtract the operand from
that constant for nonbinary modulus. */ that constant for nonbinary modulus. */
tree cnst = fold (build2 (MINUS_EXPR, operation_type, modulus, tree cnst = fold_build2 (MINUS_EXPR, operation_type, modulus,
convert (operation_type, convert (operation_type,
integer_one_node))); integer_one_node));
if (mod_pow2) if (mod_pow2)
result = fold (build2 (BIT_XOR_EXPR, operation_type, result = fold_build2 (BIT_XOR_EXPR, operation_type,
operand, cnst)); operand, cnst);
else else
result = fold (build2 (MINUS_EXPR, operation_type, result = fold_build2 (MINUS_EXPR, operation_type,
cnst, operand)); cnst, operand);
} }
break; break;
...@@ -1279,8 +1285,8 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand) ...@@ -1279,8 +1285,8 @@ build_unary_op (enum tree_code op_code, tree result_type, tree operand)
default: default:
gcc_assert (operation_type == base_type); gcc_assert (operation_type == base_type);
result = fold (build1 (op_code, operation_type, convert (operation_type, result = fold_build1 (op_code, operation_type,
operand))); convert (operation_type, operand));
} }
if (side_effects) if (side_effects)
...@@ -1322,8 +1328,8 @@ build_cond_expr (tree result_type, tree condition_operand, ...@@ -1322,8 +1328,8 @@ build_cond_expr (tree result_type, tree condition_operand,
false_operand = build_unary_op (ADDR_EXPR, result_type, false_operand); false_operand = build_unary_op (ADDR_EXPR, result_type, false_operand);
} }
result = fold (build3 (COND_EXPR, result_type, condition_operand, result = fold_build3 (COND_EXPR, result_type, condition_operand,
true_operand, false_operand)); true_operand, false_operand);
/* If either operand is a SAVE_EXPR (possibly surrounded by /* If either operand is a SAVE_EXPR (possibly surrounded by
arithmetic, make sure it gets done. */ arithmetic, make sure it gets done. */
......
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