diff options
Diffstat (limited to 'gcc/tree-affine.c')
-rw-r--r-- | gcc/tree-affine.c | 182 |
1 files changed, 91 insertions, 91 deletions
diff --git a/gcc/tree-affine.c b/gcc/tree-affine.c index 46a183a07b4..3da68137151 100644 --- a/gcc/tree-affine.c +++ b/gcc/tree-affine.c @@ -27,33 +27,37 @@ along with GCC; see the file COPYING3. If not see #include "gimple.h" #include "flags.h" #include "dumpfile.h" +#include "wide-int-print.h" + /* Extends CST as appropriate for the affine combinations COMB. */ -double_int -double_int_ext_for_comb (double_int cst, aff_tree *comb) +max_wide_int +wide_int_ext_for_comb (max_wide_int cst, aff_tree *comb) { return cst.sext (TYPE_PRECISION (comb->type)); } - /* Initializes affine combination COMB so that its value is zero in TYPE. */ static void aff_combination_zero (aff_tree *comb, tree type) { + int i; comb->type = type; - comb->offset = double_int_zero; + comb->offset = 0; comb->n = 0; + for (i = 0; i < MAX_AFF_ELTS; i++) + comb->elts[i].coef = 0; comb->rest = NULL_TREE; } /* Sets COMB to CST. */ void -aff_combination_const (aff_tree *comb, tree type, double_int cst) +aff_combination_const (aff_tree *comb, tree type, const max_wide_int &cst) { aff_combination_zero (comb, type); - comb->offset = double_int_ext_for_comb (cst, comb); + comb->offset = wide_int_ext_for_comb (cst, comb);; } /* Sets COMB to single element ELT. */ @@ -65,37 +69,35 @@ aff_combination_elt (aff_tree *comb, tree type, tree elt) comb->n = 1; comb->elts[0].val = elt; - comb->elts[0].coef = double_int_one; + comb->elts[0].coef = 1; } /* Scales COMB by SCALE. */ void -aff_combination_scale (aff_tree *comb, double_int scale) +aff_combination_scale (aff_tree *comb, max_wide_int scale) { unsigned i, j; - scale = double_int_ext_for_comb (scale, comb); - if (scale.is_one ()) + scale = wide_int_ext_for_comb (scale, comb); + if (scale.one_p ()) return; - if (scale.is_zero ()) + if (scale.zero_p ()) { aff_combination_zero (comb, comb->type); return; } - comb->offset - = double_int_ext_for_comb (scale * comb->offset, comb); + comb->offset = wide_int_ext_for_comb (scale * comb->offset, comb); for (i = 0, j = 0; i < comb->n; i++) { - double_int new_coef; + max_wide_int new_coef; - new_coef - = double_int_ext_for_comb (scale * comb->elts[i].coef, comb); + new_coef = wide_int_ext_for_comb (scale * comb->elts[i].coef, comb); /* A coefficient may become zero due to overflow. Remove the zero elements. */ - if (new_coef.is_zero ()) + if (new_coef.zero_p ()) continue; comb->elts[j].coef = new_coef; comb->elts[j].val = comb->elts[i].val; @@ -117,30 +119,29 @@ aff_combination_scale (aff_tree *comb, double_int scale) } else comb->rest = fold_build2 (MULT_EXPR, type, comb->rest, - double_int_to_tree (type, scale)); + wide_int_to_tree (type, scale)); } } /* Adds ELT * SCALE to COMB. */ void -aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale) +aff_combination_add_elt (aff_tree *comb, tree elt, max_wide_int scale) { unsigned i; tree type; - scale = double_int_ext_for_comb (scale, comb); - if (scale.is_zero ()) + scale = wide_int_ext_for_comb (scale, comb); + if (scale.zero_p ()) return; for (i = 0; i < comb->n; i++) if (operand_equal_p (comb->elts[i].val, elt, 0)) { - double_int new_coef; + max_wide_int new_coef; - new_coef = comb->elts[i].coef + scale; - new_coef = double_int_ext_for_comb (new_coef, comb); - if (!new_coef.is_zero ()) + new_coef = wide_int_ext_for_comb (comb->elts[i].coef + scale, comb); + if (!new_coef.zero_p ()) { comb->elts[i].coef = new_coef; return; @@ -152,7 +153,7 @@ aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale) if (comb->rest) { gcc_assert (comb->n == MAX_AFF_ELTS - 1); - comb->elts[comb->n].coef = double_int_one; + comb->elts[comb->n].coef = 1; comb->elts[comb->n].val = comb->rest; comb->rest = NULL_TREE; comb->n++; @@ -171,12 +172,12 @@ aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale) if (POINTER_TYPE_P (type)) type = sizetype; - if (scale.is_one ()) + if (scale.one_p ()) elt = fold_convert (type, elt); else elt = fold_build2 (MULT_EXPR, type, fold_convert (type, elt), - double_int_to_tree (type, scale)); + wide_int_to_tree (type, scale)); if (comb->rest) comb->rest = fold_build2 (PLUS_EXPR, type, comb->rest, @@ -188,9 +189,9 @@ aff_combination_add_elt (aff_tree *comb, tree elt, double_int scale) /* Adds CST to C. */ static void -aff_combination_add_cst (aff_tree *c, double_int cst) +aff_combination_add_cst (aff_tree *c, const max_wide_int &cst) { - c->offset = double_int_ext_for_comb (c->offset + cst, c); + c->offset = wide_int_ext_for_comb (c->offset + cst, c); } /* Adds COMB2 to COMB1. */ @@ -204,7 +205,7 @@ aff_combination_add (aff_tree *comb1, aff_tree *comb2) for (i = 0; i < comb2->n; i++) aff_combination_add_elt (comb1, comb2->elts[i].val, comb2->elts[i].coef); if (comb2->rest) - aff_combination_add_elt (comb1, comb2->rest, double_int_one); + aff_combination_add_elt (comb1, comb2->rest, 1); } /* Converts affine combination COMB to TYPE. */ @@ -229,11 +230,11 @@ aff_combination_convert (aff_tree *comb, tree type) if (TYPE_PRECISION (type) == TYPE_PRECISION (comb_type)) return; - comb->offset = double_int_ext_for_comb (comb->offset, comb); + comb->offset = wide_int_ext_for_comb (comb->offset, comb); for (i = j = 0; i < comb->n; i++) { - double_int new_coef = double_int_ext_for_comb (comb->elts[i].coef, comb); - if (new_coef.is_zero ()) + max_wide_int new_coef = comb->elts[i].coef; + if (new_coef.zero_p ()) continue; comb->elts[j].coef = new_coef; comb->elts[j].val = fold_convert (type, comb->elts[i].val); @@ -243,7 +244,7 @@ aff_combination_convert (aff_tree *comb, tree type) comb->n = j; if (comb->n < MAX_AFF_ELTS && comb->rest) { - comb->elts[comb->n].coef = double_int_one; + comb->elts[comb->n].coef = 1; comb->elts[comb->n].val = comb->rest; comb->rest = NULL_TREE; comb->n++; @@ -268,7 +269,7 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) switch (code) { case INTEGER_CST: - aff_combination_const (comb, type, tree_to_double_int (expr)); + aff_combination_const (comb, type, expr); return; case POINTER_PLUS_EXPR: @@ -282,7 +283,7 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb); tree_to_aff_combination (TREE_OPERAND (expr, 1), type, &tmp); if (code == MINUS_EXPR) - aff_combination_scale (&tmp, double_int_minus_one); + aff_combination_scale (&tmp, -1); aff_combination_add (comb, &tmp); return; @@ -291,19 +292,19 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) if (TREE_CODE (cst) != INTEGER_CST) break; tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb); - aff_combination_scale (comb, tree_to_double_int (cst)); + aff_combination_scale (comb, cst); return; case NEGATE_EXPR: tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb); - aff_combination_scale (comb, double_int_minus_one); + aff_combination_scale (comb, -1); return; case BIT_NOT_EXPR: /* ~x = -x - 1 */ tree_to_aff_combination (TREE_OPERAND (expr, 0), type, comb); - aff_combination_scale (comb, double_int_minus_one); - aff_combination_add_cst (comb, double_int_minus_one); + aff_combination_scale (comb, -1); + aff_combination_add_cst (comb, -1); return; case ADDR_EXPR: @@ -321,11 +322,10 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) false); if (bitpos % BITS_PER_UNIT != 0) break; - aff_combination_const (comb, type, - double_int::from_uhwi (bitpos / BITS_PER_UNIT)); + aff_combination_const (comb, type, bitpos / BITS_PER_UNIT); core = build_fold_addr_expr (core); if (TREE_CODE (core) == ADDR_EXPR) - aff_combination_add_elt (comb, core, double_int_one); + aff_combination_add_elt (comb, core, 1); else { tree_to_aff_combination (core, type, &tmp); @@ -368,18 +368,18 @@ tree_to_aff_combination (tree expr, tree type, aff_tree *comb) combination COMB. */ static tree -add_elt_to_tree (tree expr, tree type, tree elt, double_int scale, - aff_tree *comb) +add_elt_to_tree (tree expr, tree type, tree elt, max_wide_int scale, + aff_tree *comb ATTRIBUTE_UNUSED) { enum tree_code code; tree type1 = type; if (POINTER_TYPE_P (type)) type1 = sizetype; - scale = double_int_ext_for_comb (scale, comb); + scale = wide_int_ext_for_comb (scale, comb); elt = fold_convert (type1, elt); - if (scale.is_one ()) + if (scale.one_p ()) { if (!expr) return fold_convert (type, elt); @@ -389,7 +389,7 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale, return fold_build2 (PLUS_EXPR, type, expr, elt); } - if (scale.is_minus_one ()) + if (scale.minus_one_p ()) { if (!expr) return fold_convert (type, fold_build1 (NEGATE_EXPR, type1, elt)); @@ -405,9 +405,9 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale, if (!expr) return fold_convert (type, fold_build2 (MULT_EXPR, type1, elt, - double_int_to_tree (type1, scale))); + wide_int_to_tree (type1, scale))); - if (scale.is_negative ()) + if (scale.neg_p (SIGNED)) { code = MINUS_EXPR; scale = -scale; @@ -416,7 +416,7 @@ add_elt_to_tree (tree expr, tree type, tree elt, double_int scale, code = PLUS_EXPR; elt = fold_build2 (MULT_EXPR, type1, elt, - double_int_to_tree (type1, scale)); + wide_int_to_tree (type1, scale)); if (POINTER_TYPE_P (type)) { if (code == MINUS_EXPR) @@ -434,7 +434,7 @@ aff_combination_to_tree (aff_tree *comb) tree type = comb->type; tree expr = NULL_TREE; unsigned i; - double_int off, sgn; + max_wide_int off, sgn; tree type1 = type; if (POINTER_TYPE_P (type)) type1 = sizetype; @@ -446,21 +446,21 @@ aff_combination_to_tree (aff_tree *comb) comb); if (comb->rest) - expr = add_elt_to_tree (expr, type, comb->rest, double_int_one, comb); + expr = add_elt_to_tree (expr, type, comb->rest, 1, comb); /* Ensure that we get x - 1, not x + (-1) or x + 0xff..f if x is unsigned. */ - if (comb->offset.is_negative ()) + if (comb->offset.neg_p (SIGNED)) { off = -comb->offset; - sgn = double_int_minus_one; + sgn = -1; } else { off = comb->offset; - sgn = double_int_one; + sgn = 1; } - return add_elt_to_tree (expr, type, double_int_to_tree (type1, off), sgn, + return add_elt_to_tree (expr, type, wide_int_to_tree (type1, off), sgn, comb); } @@ -487,7 +487,7 @@ aff_combination_remove_elt (aff_tree *comb, unsigned m) comb->elts[m] = comb->elts[comb->n]; if (comb->rest) { - comb->elts[comb->n].coef = double_int_one; + comb->elts[comb->n].coef = 1; comb->elts[comb->n].val = comb->rest; comb->rest = NULL_TREE; comb->n++; @@ -499,7 +499,7 @@ aff_combination_remove_elt (aff_tree *comb, unsigned m) static void -aff_combination_add_product (aff_tree *c, double_int coef, tree val, +aff_combination_add_product (aff_tree *c, const max_wide_int &coef, tree val, aff_tree *r) { unsigned i; @@ -550,7 +550,7 @@ aff_combination_mult (aff_tree *c1, aff_tree *c2, aff_tree *r) for (i = 0; i < c2->n; i++) aff_combination_add_product (c1, c2->elts[i].coef, c2->elts[i].val, r); if (c2->rest) - aff_combination_add_product (c1, double_int_one, c2->rest, r); + aff_combination_add_product (c1, 1, c2->rest, r); aff_combination_add_product (c1, c2->offset, NULL, r); } @@ -597,7 +597,7 @@ aff_combination_expand (aff_tree *comb ATTRIBUTE_UNUSED, aff_tree to_add, current, curre; tree e, rhs; gimple def; - double_int scale; + max_wide_int scale; void **slot; struct name_expansion *exp; @@ -742,25 +742,25 @@ free_affine_expand_cache (struct pointer_map_t **cache) is set to true. */ static bool -double_int_constant_multiple_p (double_int val, double_int div, - bool *mult_set, double_int *mult) +wide_int_constant_multiple_p (max_wide_int val, max_wide_int div, + bool *mult_set, max_wide_int *mult) { - double_int rem, cst; + max_wide_int rem, cst; - if (val.is_zero ()) + if (val.zero_p ()) { - if (*mult_set && !mult->is_zero ()) + if (*mult_set && !mult->zero_p ()) return false; *mult_set = true; - *mult = double_int_zero; + *mult = 0; return true; } - if (div.is_zero ()) + if (div.zero_p ()) return false; - cst = val.sdivmod (div, FLOOR_DIV_EXPR, &rem); - if (!rem.is_zero ()) + cst = val.sdivmod_floor (div, &rem); + if (!rem.zero_p ()) return false; if (*mult_set && *mult != cst) @@ -776,14 +776,14 @@ double_int_constant_multiple_p (double_int val, double_int div, bool aff_combination_constant_multiple_p (aff_tree *val, aff_tree *div, - double_int *mult) + max_wide_int *mult) { bool mult_set = false; unsigned i; - if (val->n == 0 && val->offset.is_zero ()) + if (val->n == 0 && val->offset.zero_p ()) { - *mult = double_int_zero; + *mult = 0; return true; } if (val->n != div->n) @@ -792,8 +792,8 @@ aff_combination_constant_multiple_p (aff_tree *val, aff_tree *div, if (val->rest || div->rest) return false; - if (!double_int_constant_multiple_p (val->offset, div->offset, - &mult_set, mult)) + if (!wide_int_constant_multiple_p (val->offset, div->offset, + &mult_set, mult)) return false; for (i = 0; i < div->n; i++) @@ -802,8 +802,8 @@ aff_combination_constant_multiple_p (aff_tree *val, aff_tree *div, = aff_combination_find_elt (val, div->elts[i].val, NULL); if (!elt) return false; - if (!double_int_constant_multiple_p (elt->coef, div->elts[i].coef, - &mult_set, mult)) + if (!wide_int_constant_multiple_p (elt->coef, div->elts[i].coef, + &mult_set, mult)) return false; } @@ -817,13 +817,13 @@ static void print_aff (FILE *file, aff_tree *val) { unsigned i; - bool uns = TYPE_UNSIGNED (val->type); + signop sgn = TYPE_SIGN (val->type); if (POINTER_TYPE_P (val->type)) - uns = false; + sgn = SIGNED; fprintf (file, "{\n type = "); print_generic_expr (file, val->type, TDF_VOPS|TDF_MEMSYMS); fprintf (file, "\n offset = "); - dump_double_int (file, val->offset, uns); + print_dec (val->offset, file, sgn); if (val->n > 0) { fprintf (file, "\n elements = {\n"); @@ -833,7 +833,7 @@ print_aff (FILE *file, aff_tree *val) print_generic_expr (file, val->elts[i].val, TDF_VOPS|TDF_MEMSYMS); fprintf (file, " * "); - dump_double_int (file, val->elts[i].coef, uns); + print_dec (val->elts[i].coef, file, sgn); if (i != val->n - 1) fprintf (file, ", \n"); } @@ -860,7 +860,7 @@ debug_aff (aff_tree *val) location is stored to SIZE. */ void -get_inner_reference_aff (tree ref, aff_tree *addr, double_int *size) +get_inner_reference_aff (tree ref, aff_tree *addr, max_wide_int *size) { HOST_WIDE_INT bitsize, bitpos; tree toff; @@ -882,36 +882,36 @@ get_inner_reference_aff (tree ref, aff_tree *addr, double_int *size) } aff_combination_const (&tmp, sizetype, - double_int::from_shwi (bitpos / BITS_PER_UNIT)); + max_wide_int (bitpos / BITS_PER_UNIT)); aff_combination_add (addr, &tmp); - *size = double_int::from_shwi ((bitsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT); + *size = (bitsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT; } /* Returns true if a region of size SIZE1 at position 0 and a region of size SIZE2 at position DIFF cannot overlap. */ bool -aff_comb_cannot_overlap_p (aff_tree *diff, double_int size1, double_int size2) +aff_comb_cannot_overlap_p (aff_tree *diff, const max_wide_int &size1, const max_wide_int &size2) { - double_int d, bound; + max_wide_int d, bound; /* Unless the difference is a constant, we fail. */ if (diff->n != 0) return false; d = diff->offset; - if (d.is_negative ()) + if (d.neg_p (SIGNED)) { /* The second object is before the first one, we succeed if the last element of the second object is before the start of the first one. */ - bound = d + size2 + double_int_minus_one; - return bound.is_negative (); + bound = d + size2 - 1; + return bound.neg_p (SIGNED); } else { /* We succeed if the second object starts after the first one ends. */ - return size1.sle (d); + return size1.les_p (d); } } |