Richi has asked the we break the wide-int patch so that the individual port and 
front end maintainers can review their parts without have to go through the 
entire patch.    This patch covers the fortran front end.

Ok?

fortran:
        * target-memory.c: Include wide-int.h.
        (gfc_interpret_logical): Use wide-int interfaces.
        * trans-array.c: Include wide-int.h.
        (gfc_conv_array_initializer): Use wide-int interfaces.
        * trans-const.c: Include wide-int.h.
        (gfc_conv_string_init): Use wide-int interfaces.
        (gfc_conv_mpz_to_tree): Likewise.
        (gfc_conv_tree_to_mpz): Likewise.
        * trans-decl.c
        (gfc_can_put_var_on_stack): Use tree_fits_uhwi_p.
        * trans-expr.c: Include wide-int.h.
        (gfc_conv_cst_int_power): Use wide-int interfaces.
        (gfc_string_to_single_character): Likewise.
        (gfc_optimize_len_trim): Likewise.
        * trans-intrinsic.c: Include wide-int.h.
        (trans_this_image): Use wide-int interfaces.
        (gfc_conv_intrinsic_bound): Likewise.
        (conv_intrinsic_cobound): Likewise.
        * trans-types.c
        (gfc_init_types): Use wide-int interfaces.
        (gfc_get_array_type_bounds): Pass an integer of the correct type
        instead of using integer_one_node.


diff --git a/gcc/fortran/target-memory.c b/gcc/fortran/target-memory.c
index d0ee41a..8778d98 100644
--- a/gcc/fortran/target-memory.c
+++ b/gcc/fortran/target-memory.c
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "trans-const.h"
 #include "trans-types.h"
 #include "target-memory.h"
+#include "wide-int.h"
 
 /* --------------------------------------------------------------- */
 /* Calculate the size of an expression.  */
@@ -430,7 +431,7 @@ gfc_interpret_logical (int kind, unsigned char *buffer, 
size_t buffer_size,
 {
   tree t = native_interpret_expr (gfc_get_logical_type (kind), buffer,
                                  buffer_size);
-  *logical = tree_to_double_int (t).is_zero () ? 0 : 1;
+  *logical = wi::eq_p (t, 0) ? 0 : 1;
   return size_logical (kind);
 }
 
diff --git a/gcc/fortran/trans-array.c b/gcc/fortran/trans-array.c
index c2bbd0e..5b3cd1f 100644
--- a/gcc/fortran/trans-array.c
+++ b/gcc/fortran/trans-array.c
@@ -90,6 +90,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "trans-array.h"
 #include "trans-const.h"
 #include "dependency.h"
+#include "wide-int.h"
 
 static bool gfc_get_array_constructor_size (mpz_t *, gfc_constructor_base);
 
@@ -5361,9 +5362,8 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
 {
   gfc_constructor *c;
   tree tmp;
+  offset_int wtmp;
   gfc_se se;
-  HOST_WIDE_INT hi;
-  unsigned HOST_WIDE_INT lo;
   tree index, range;
   vec<constructor_elt, va_gc> *v = NULL;
 
@@ -5385,20 +5385,13 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr)
       else
        gfc_conv_structure (&se, expr, 1);
 
-      tmp = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
-      gcc_assert (tmp && INTEGER_CST_P (tmp));
-      hi = TREE_INT_CST_HIGH (tmp);
-      lo = TREE_INT_CST_LOW (tmp);
-      lo++;
-      if (lo == 0)
-       hi++;
+      wtmp = wi::to_offset (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1;
+      gcc_assert (wtmp != 0);
       /* This will probably eat buckets of memory for large arrays.  */
-      while (hi != 0 || lo != 0)
+      while (wtmp != 0)
         {
          CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, se.expr);
-          if (lo == 0)
-            hi--;
-          lo--;
+         wtmp -= 1;
         }
       break;
 
diff --git a/gcc/fortran/trans-const.c b/gcc/fortran/trans-const.c
index f5a2b18..334b5f5 100644
--- a/gcc/fortran/trans-const.c
+++ b/gcc/fortran/trans-const.c
@@ -33,6 +33,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "trans-const.h"
 #include "trans-types.h"
 #include "target-memory.h"
+#include "wide-int.h"
 
 tree gfc_rank_cst[GFC_MAX_DIMENSIONS + 1];
 
@@ -145,8 +146,7 @@ gfc_conv_string_init (tree length, gfc_expr * expr)
 
   gcc_assert (expr->expr_type == EXPR_CONSTANT);
   gcc_assert (expr->ts.type == BT_CHARACTER);
-  gcc_assert (INTEGER_CST_P (length));
-  gcc_assert (TREE_INT_CST_HIGH (length) == 0);
+  gcc_assert (tree_fits_uhwi_p (length));
 
   len = TREE_INT_CST_LOW (length);
   slen = expr->value.character.length;
@@ -201,8 +201,8 @@ gfc_init_constants (void)
 tree
 gfc_conv_mpz_to_tree (mpz_t i, int kind)
 {
-  double_int val = mpz_get_double_int (gfc_get_int_type (kind), i, true);
-  return double_int_to_tree (gfc_get_int_type (kind), val);
+  wide_int val = wi::from_mpz (gfc_get_int_type (kind), i, true);
+  return wide_int_to_tree (gfc_get_int_type (kind), val);
 }
 
 /* Converts a backend tree into a GMP integer.  */
@@ -210,8 +210,7 @@ gfc_conv_mpz_to_tree (mpz_t i, int kind)
 void
 gfc_conv_tree_to_mpz (mpz_t i, tree source)
 {
-  double_int val = tree_to_double_int (source);
-  mpz_set_double_int (i, val, TYPE_UNSIGNED (TREE_TYPE (source)));
+  wi::to_mpz (source, i, TYPE_SIGN (TREE_TYPE (source)));
 }
 
 /* Converts a real constant into backend form.  */
diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index f974c6e..6a29ba1 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -409,7 +409,7 @@ gfc_can_put_var_on_stack (tree size)
   if (gfc_option.flag_max_stack_var_size < 0)
     return 1;
 
-  if (TREE_INT_CST_HIGH (size) != 0)
+  if (!tree_fits_uhwi_p (size))
     return 0;
 
   low = TREE_INT_CST_LOW (size);
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c
index 41b2f94..bb5cfad 100644
--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -41,7 +41,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dependency.h"
 #include "gimple.h"
 #include "gimplify.h"
-
+#include "wide-int.h"
 
 /* Convert a scalar to an array descriptor. To be used for assumed-rank
    arrays.  */
@@ -2083,13 +2083,14 @@ gfc_conv_cst_int_power (gfc_se * se, tree lhs, tree rhs)
   HOST_WIDE_INT m;
   unsigned HOST_WIDE_INT n;
   int sgn;
+  wide_int wrhs = rhs;
 
   /* If exponent is too large, we won't expand it anyway, so don't bother
      with large integer values.  */
-  if (!TREE_INT_CST (rhs).fits_shwi ())
+  if (!wi::fits_shwi_p (wrhs))
     return 0;
 
-  m = TREE_INT_CST (rhs).to_shwi ();
+  m = wrhs.to_shwi ();
   /* There's no ABS for HOST_WIDE_INT, so here we go. It also takes care
      of the asymmetric range of the integer type.  */
   n = (unsigned HOST_WIDE_INT) (m < 0 ? -m : m);
@@ -2628,7 +2629,7 @@ gfc_string_to_single_character (tree len, tree str, int 
kind)
 {
 
   if (len == NULL
-      || !INTEGER_CST_P (len) || TREE_INT_CST_HIGH (len) != 0
+      || !tree_fits_uhwi_p (len)
       || !POINTER_TYPE_P (TREE_TYPE (str)))
     return NULL_TREE;
 
@@ -2742,8 +2743,9 @@ gfc_optimize_len_trim (tree len, tree str, int kind)
       && TREE_CODE (TREE_OPERAND (TREE_OPERAND (str, 0), 0)) == STRING_CST
       && array_ref_low_bound (TREE_OPERAND (str, 0))
         == TREE_OPERAND (TREE_OPERAND (str, 0), 1)
-      && TREE_INT_CST_LOW (len) >= 1
-      && TREE_INT_CST_LOW (len)
+      && tree_fits_uhwi_p (len)
+      && tree_to_uhwi (len) >= 1
+      && tree_to_uhwi (len)
         == (unsigned HOST_WIDE_INT)
            TREE_STRING_LENGTH (TREE_OPERAND (TREE_OPERAND (str, 0), 0)))
     {
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index 4acdc8d..7e5feab 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -43,6 +43,7 @@ along with GCC; see the file COPYING3.  If not see
 /* Only for gfc_trans_assign and gfc_trans_pointer_assign.  */
 #include "trans-stmt.h"
 #include "tree-nested.h"
+#include "wide-int.h"
 
 /* This maps Fortran intrinsic math functions to external library or GCC
    builtin functions.  */
@@ -987,12 +988,8 @@ trans_this_image (gfc_se * se, gfc_expr *expr)
 
       if (INTEGER_CST_P (dim_arg))
        {
-         int hi, co_dim;
-
-         hi = TREE_INT_CST_HIGH (dim_arg);
-         co_dim = TREE_INT_CST_LOW (dim_arg);
-         if (hi || co_dim < 1
-             || co_dim > GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc)))
+         if (wi::ltu_p (dim_arg, 1)
+             || wi::gtu_p (dim_arg, GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc))))
            gfc_error ("'dim' argument of %s intrinsic at %L is not a valid "
                       "dimension index", expr->value.function.isym->name,
                       &expr->where);
@@ -1349,14 +1346,9 @@ gfc_conv_intrinsic_bound (gfc_se * se, gfc_expr * expr, 
int upper)
 
   if (INTEGER_CST_P (bound))
     {
-      int hi, low;
-
-      hi = TREE_INT_CST_HIGH (bound);
-      low = TREE_INT_CST_LOW (bound);
-      if (hi || low < 0
-         || ((!as || as->type != AS_ASSUMED_RANK)
-             && low >= GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc)))
-         || low > GFC_MAX_DIMENSIONS)
+      if (((!as || as->type != AS_ASSUMED_RANK)
+          && wi::geu_p (bound, GFC_TYPE_ARRAY_RANK (TREE_TYPE (desc))))
+         || wi::gtu_p (bound, GFC_MAX_DIMENSIONS))
        gfc_error ("'dim' argument of %s intrinsic at %L is not a valid "
                   "dimension index", upper ? "UBOUND" : "LBOUND",
                   &expr->where);
@@ -1551,11 +1543,8 @@ conv_intrinsic_cobound (gfc_se * se, gfc_expr * expr)
 
       if (INTEGER_CST_P (bound))
        {
-         int hi, low;
-
-         hi = TREE_INT_CST_HIGH (bound);
-         low = TREE_INT_CST_LOW (bound);
-         if (hi || low < 1 || low > GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc)))
+         if (wi::ltu_p (bound, 1)
+             || wi::gtu_p (bound, GFC_TYPE_ARRAY_CORANK (TREE_TYPE (desc))))
            gfc_error ("'dim' argument of %s intrinsic at %L is not a valid "
                       "dimension index", expr->value.function.isym->name,
                       &expr->where);
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 21d9f28..f447155 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -863,8 +863,6 @@ gfc_init_types (void)
   int index;
   tree type;
   unsigned n;
-  unsigned HOST_WIDE_INT hi;
-  unsigned HOST_WIDE_INT lo;
 
   /* Create and name the types.  */
 #define PUSH_TYPE(name, node) \
@@ -956,13 +954,10 @@ gfc_init_types (void)
      descriptor.  */
 
   n = TYPE_PRECISION (gfc_array_index_type) - GFC_DTYPE_SIZE_SHIFT;
-  lo = ~ (unsigned HOST_WIDE_INT) 0;
-  if (n > HOST_BITS_PER_WIDE_INT)
-    hi = lo >> (2*HOST_BITS_PER_WIDE_INT - n);
-  else
-    hi = 0, lo >>= HOST_BITS_PER_WIDE_INT - n;
   gfc_max_array_element_size
-    = build_int_cst_wide (long_unsigned_type_node, lo, hi);
+    = wide_int_to_tree (long_unsigned_type_node,
+                       wi::mask (n, UNSIGNED,
+                                 TYPE_PRECISION (long_unsigned_type_node)));
 
   boolean_type_node = gfc_get_logical_type (gfc_default_logical_kind);
   boolean_true_node = build_int_cst (boolean_type_node, 1);
@@ -1895,7 +1890,7 @@ gfc_get_array_type_bounds (tree etype, int dimen, int 
codimen, tree * lbound,
   if (stride)
     rtype = build_range_type (gfc_array_index_type, gfc_index_zero_node,
                              int_const_binop (MINUS_EXPR, stride,
-                                              integer_one_node));
+                                              build_int_cst (TREE_TYPE 
(stride), 1)));
   else
     rtype = gfc_array_range_type;
   arraytype = build_array_type (etype, rtype);

Reply via email to