diff mbox

wide-int, lto

Message ID C4ACA006-9892-4CAD-B0B6-200FDF1F230E@comcast.net
State New
Headers show

Commit Message

Mike Stump Feb. 6, 2014, 6:56 p.m. UTC
On Nov 25, 2013, at 3:09 AM, Richard Biener <richard.guenther@gmail.com> wrote:
> please add streamer_read/write_wi () helpers to data-streamer*
> 
> replicating the above loop N times is too ugly.

Agreed.  Below is the patch to collapse the code.  Thanks.

Comments

Richard Biener Feb. 7, 2014, 9:09 a.m. UTC | #1
On Thu, Feb 6, 2014 at 7:56 PM, Mike Stump <mikestump@comcast.net> wrote:
> On Nov 25, 2013, at 3:09 AM, Richard Biener <richard.guenther@gmail.com> wrote:
>> please add streamer_read/write_wi () helpers to data-streamer*
>>
>> replicating the above loop N times is too ugly.
>
> Agreed.  Below is the patch to collapse the code.  Thanks.

Ok.

>
> diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
> index 08eba48..3e02840 100644
> --- a/gcc/lto-streamer-in.c
> +++ b/gcc/lto-streamer-in.c
> @@ -617,6 +617,21 @@ make_new_block (struct function *fn, unsigned int index)
>  }
>
>
> +/* Read a wide-int.  */
> +
> +static widest_int
> +streamer_read_wi (struct lto_input_block *ib)
> +{
> +  HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
> +  int i;
> +  int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
> +  int len = streamer_read_uhwi (ib);
> +  for (i = 0; i < len; i++)
> +    a[i] = streamer_read_hwi (ib);
> +  return widest_int::from_array (a, len);
> +}
> +
> +
>  /* Read the CFG for function FN from input block IB.  */
>
>  static void
> @@ -726,28 +741,10 @@ input_cfg (struct lto_input_block *ib, struct data_in *data_in,
>        loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
>        loop->any_upper_bound = streamer_read_hwi (ib);
>        if (loop->any_upper_bound)
> -       {
> -         HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
> -         int i;
> -         int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
> -         int len = streamer_read_uhwi (ib);
> -         for (i = 0; i < len; i++)
> -           a[i] = streamer_read_hwi (ib);
> -
> -         loop->nb_iterations_upper_bound = widest_int::from_array (a, len);
> -       }
> +       loop->nb_iterations_upper_bound = streamer_read_wi (ib);
>        loop->any_estimate = streamer_read_hwi (ib);
>        if (loop->any_estimate)
> -       {
> -         HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
> -         int i;
> -         int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
> -         int len = streamer_read_uhwi (ib);
> -         for (i = 0; i < len; i++)
> -           a[i] = streamer_read_hwi (ib);
> -
> -         loop->nb_iterations_estimate = widest_int::from_array (a, len);
> -       }
> +       loop->nb_iterations_estimate = streamer_read_wi (ib);
>
>        /* Read OMP SIMD related info.  */
>        loop->safelen = streamer_read_hwi (ib);
> diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
> index de19235..60acb42 100644
> --- a/gcc/lto-streamer-out.c
> +++ b/gcc/lto-streamer-out.c
> @@ -1622,6 +1622,21 @@ output_ssa_names (struct output_block *ob, struct function *fn)
>  }
>
>
> +/* Output a wide-int.  */
> +
> +static void
> +streamer_write_wi (struct output_block *ob,
> +                  const widest_int &w)
> +{
> +  int len = w.get_len ();
> +
> +  streamer_write_uhwi (ob, w.get_precision ());
> +  streamer_write_uhwi (ob, len);
> +  for (int i = 0; i < len; i++)
> +    streamer_write_hwi (ob, w.elt (i));
> +}
> +
> +
>  /* Output the cfg.  */
>
>  static void
> @@ -1694,26 +1709,10 @@ output_cfg (struct output_block *ob, struct function *fn)
>                            loop_estimation, EST_LAST, loop->estimate_state);
>        streamer_write_hwi (ob, loop->any_upper_bound);
>        if (loop->any_upper_bound)
> -       {
> -         int len = loop->nb_iterations_upper_bound.get_len ();
> -         int i;
> -
> -         streamer_write_uhwi (ob, loop->nb_iterations_upper_bound.get_precision ());
> -         streamer_write_uhwi (ob, len);
> -         for (i = 0; i < len; i++)
> -           streamer_write_hwi (ob, loop->nb_iterations_upper_bound.elt (i));
> -       }
> +       streamer_write_wi (ob, loop->nb_iterations_upper_bound);
>        streamer_write_hwi (ob, loop->any_estimate);
>        if (loop->any_estimate)
> -       {
> -         int len = loop->nb_iterations_estimate.get_len ();
> -         int i;
> -
> -         streamer_write_uhwi (ob, loop->nb_iterations_estimate.get_precision ());
> -         streamer_write_uhwi (ob, len);
> -         for (i = 0; i < len; i++)
> -           streamer_write_hwi (ob, loop->nb_iterations_estimate.elt (i));
> -       }
> +       streamer_write_wi (ob, loop->nb_iterations_estimate);
>
>        /* Write OMP SIMD related info.  */
>        streamer_write_hwi (ob, loop->safelen);
diff mbox

Patch

diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c
index 08eba48..3e02840 100644
--- a/gcc/lto-streamer-in.c
+++ b/gcc/lto-streamer-in.c
@@ -617,6 +617,21 @@  make_new_block (struct function *fn, unsigned int index)
 }
 
 
+/* Read a wide-int.  */
+
+static widest_int
+streamer_read_wi (struct lto_input_block *ib)
+{
+  HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
+  int i;
+  int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
+  int len = streamer_read_uhwi (ib);
+  for (i = 0; i < len; i++)
+    a[i] = streamer_read_hwi (ib);
+  return widest_int::from_array (a, len);
+}
+
+
 /* Read the CFG for function FN from input block IB.  */
 
 static void
@@ -726,28 +741,10 @@  input_cfg (struct lto_input_block *ib, struct data_in *data_in,
       loop->estimate_state = streamer_read_enum (ib, loop_estimation, EST_LAST);
       loop->any_upper_bound = streamer_read_hwi (ib);
       if (loop->any_upper_bound)
-	{
-	  HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
-	  int i;
-	  int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
-	  int len = streamer_read_uhwi (ib);
-	  for (i = 0; i < len; i++)
-	    a[i] = streamer_read_hwi (ib);
-
-	  loop->nb_iterations_upper_bound = widest_int::from_array (a, len);
-	}
+	loop->nb_iterations_upper_bound = streamer_read_wi (ib);
       loop->any_estimate = streamer_read_hwi (ib);
       if (loop->any_estimate)
-	{
-	  HOST_WIDE_INT a[WIDE_INT_MAX_ELTS];
-	  int i;
-	  int prec ATTRIBUTE_UNUSED = streamer_read_uhwi (ib);
-	  int len = streamer_read_uhwi (ib);
-	  for (i = 0; i < len; i++)
-	    a[i] = streamer_read_hwi (ib);
-
-	  loop->nb_iterations_estimate = widest_int::from_array (a, len);
-	}
+	loop->nb_iterations_estimate = streamer_read_wi (ib);
 
       /* Read OMP SIMD related info.  */
       loop->safelen = streamer_read_hwi (ib);
diff --git a/gcc/lto-streamer-out.c b/gcc/lto-streamer-out.c
index de19235..60acb42 100644
--- a/gcc/lto-streamer-out.c
+++ b/gcc/lto-streamer-out.c
@@ -1622,6 +1622,21 @@  output_ssa_names (struct output_block *ob, struct function *fn)
 }
 
 
+/* Output a wide-int.  */
+
+static void
+streamer_write_wi (struct output_block *ob,
+		   const widest_int &w)
+{
+  int len = w.get_len ();
+
+  streamer_write_uhwi (ob, w.get_precision ());
+  streamer_write_uhwi (ob, len);
+  for (int i = 0; i < len; i++)
+    streamer_write_hwi (ob, w.elt (i));
+}
+
+
 /* Output the cfg.  */
 
 static void
@@ -1694,26 +1709,10 @@  output_cfg (struct output_block *ob, struct function *fn)
 			   loop_estimation, EST_LAST, loop->estimate_state);
       streamer_write_hwi (ob, loop->any_upper_bound);
       if (loop->any_upper_bound)
-	{
-	  int len = loop->nb_iterations_upper_bound.get_len ();
-	  int i;
-
-	  streamer_write_uhwi (ob, loop->nb_iterations_upper_bound.get_precision ());
-	  streamer_write_uhwi (ob, len);
-	  for (i = 0; i < len; i++)
-	    streamer_write_hwi (ob, loop->nb_iterations_upper_bound.elt (i));
-	}
+	streamer_write_wi (ob, loop->nb_iterations_upper_bound);
       streamer_write_hwi (ob, loop->any_estimate);
       if (loop->any_estimate)
-	{
-	  int len = loop->nb_iterations_estimate.get_len ();
-	  int i;
-
-	  streamer_write_uhwi (ob, loop->nb_iterations_estimate.get_precision ());
-	  streamer_write_uhwi (ob, len);
-	  for (i = 0; i < len; i++)
-	    streamer_write_hwi (ob, loop->nb_iterations_estimate.elt (i));
-	}
+	streamer_write_wi (ob, loop->nb_iterations_estimate);
 
       /* Write OMP SIMD related info.  */
       streamer_write_hwi (ob, loop->safelen);