diff --git a/gcc/data-streamer-in.cc b/gcc/data-streamer-in.cc index 7dce2928ef03420625410790a0c8965e98c22fd4..07dbc5e2bc367f7bf7a3a0bf999b24da23a52cb2 100644 --- a/gcc/data-streamer-in.cc +++ b/gcc/data-streamer-in.cc @@ -182,10 +182,8 @@ streamer_read_hwi (class lto_input_block *ib) poly_uint64 streamer_read_poly_uint64 (class lto_input_block *ib) { - poly_uint64 res; - for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) - res.coeffs[i] = streamer_read_uhwi (ib); - return res; + using coeff_type = poly_int_traits<poly_uint64>::coeff_type; + return poly_int_read_common<coeff_type> (streamer_read_uhwi, ib); } /* Read a poly_int64 from IB. */ @@ -193,10 +191,8 @@ streamer_read_poly_uint64 (class lto_input_block *ib) poly_int64 streamer_read_poly_int64 (class lto_input_block *ib) { - poly_int64 res; - for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) - res.coeffs[i] = streamer_read_hwi (ib); - return res; + using coeff_type = poly_int_traits<poly_int64>::coeff_type; + return poly_int_read_common<coeff_type> (streamer_read_hwi, ib); } /* Read gcov_type value from IB. */ diff --git a/gcc/data-streamer.cc b/gcc/data-streamer.cc index 346b294c72ac62398e00634bdea7fe8f4bd7afb2..896413e8d2b6857afaa32610d978fac433c078c0 100644 --- a/gcc/data-streamer.cc +++ b/gcc/data-streamer.cc @@ -28,6 +28,14 @@ along with GCC; see the file COPYING3. If not see #include "cgraph.h" #include "data-streamer.h" +/* For offloading -- While streaming-out, host NUM_POLY_INT_COEFFS is + stored at beginning of mode_table. While streaming-in, the value is read + in host_num_poly_int_coeffs. */ + +#ifdef ACCEL_COMPILER +unsigned host_num_poly_int_coeffs = 0; +#endif + /* Pack WORK into BP in a variant of uleb format. */ void diff --git a/gcc/data-streamer.h b/gcc/data-streamer.h index 6a2596134ceb3c824943cfa709c912ce105eb75e..b3dc4b9847671940bc626c18e9e65794d24a109f 100644 --- a/gcc/data-streamer.h +++ b/gcc/data-streamer.h @@ -50,6 +50,7 @@ void bp_pack_real_value (struct bitpack_d *, const REAL_VALUE_TYPE *); void bp_unpack_real_value (struct bitpack_d *, REAL_VALUE_TYPE *); unsigned HOST_WIDE_INT bp_unpack_var_len_unsigned (struct bitpack_d *); HOST_WIDE_INT bp_unpack_var_len_int (struct bitpack_d *); +extern unsigned host_num_poly_int_coeffs; /* In data-streamer-out.cc */ void streamer_write_zero (struct output_block *); @@ -194,15 +195,55 @@ bp_unpack_value (struct bitpack_d *bp, unsigned nbits) return val & mask; } +/* Common code for reading poly_int. */ + +template<typename C, typename F, typename ...Args> +poly_int<NUM_POLY_INT_COEFFS, C> +poly_int_read_common (F read_coeff, Args ...args) +{ + poly_int<NUM_POLY_INT_COEFFS, C> x; + unsigned i; + +#ifdef ACCEL_COMPILER + /* Ensure that we have streamed-in host_num_poly_int_coeffs. */ + const unsigned num_poly_int_coeffs = host_num_poly_int_coeffs; + gcc_assert (host_num_poly_int_coeffs > 0); +#else + const unsigned num_poly_int_coeffs = NUM_POLY_INT_COEFFS; +#endif + + if (num_poly_int_coeffs <= NUM_POLY_INT_COEFFS) + { + for (i = 0; i < num_poly_int_coeffs; i++) + x.coeffs[i] = read_coeff (args...); + for (; i < NUM_POLY_INT_COEFFS; i++) + x.coeffs[i] = 0; + } + else + { + for (i = 0; i < NUM_POLY_INT_COEFFS; i++) + x.coeffs[i] = read_coeff (args...); + + /* Ensure that degree of poly_int <= accel NUM_POLY_INT_COEFFS. */ + for (; i < num_poly_int_coeffs; i++) + { + C val = read_coeff (args...); + if (val != 0) + fatal_error (input_location, + "degree of %<poly_int%> exceeds " + "%<NUM_POLY_INT_COEFFS%> (%d)", + NUM_POLY_INT_COEFFS); + } + } + return x; +} + /* Unpacks a polynomial value from the bit-packing context BP in which each coefficient has NBITS bits. */ inline poly_int<NUM_POLY_INT_COEFFS, bitpack_word_t> bp_unpack_poly_value (struct bitpack_d *bp, unsigned nbits) { - poly_int<NUM_POLY_INT_COEFFS, bitpack_word_t> x; - for (int i = 0; i < NUM_POLY_INT_COEFFS; ++i) - x.coeffs[i] = bp_unpack_value (bp, nbits); - return x; + return poly_int_read_common<bitpack_word_t> (bp_unpack_value, bp, nbits); } diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc index 2e592be80823685b961a21fac2c5f23efbe06074..cbf6041fd685d072369d0afebd817f37a4149e49 100644 --- a/gcc/lto-streamer-in.cc +++ b/gcc/lto-streamer-in.cc @@ -2013,6 +2013,11 @@ lto_input_mode_table (struct lto_file_decl_data *file_data) header->string_size, vNULL); bitpack_d bp = streamer_read_bitpack (&ib); +#ifdef ACCEL_COMPILER + host_num_poly_int_coeffs + = bp_unpack_value (&bp, MAX_NUM_POLY_INT_COEFFS_BITS); +#endif + unsigned mode_bits = bp_unpack_value (&bp, 5); unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << mode_bits); diff --git a/gcc/lto-streamer-out.cc b/gcc/lto-streamer-out.cc index c329ac8af958dc89601cb6f589d6f708b808185f..523d6dad221e92d8c059f193cc8252a5d5314663 100644 --- a/gcc/lto-streamer-out.cc +++ b/gcc/lto-streamer-out.cc @@ -3192,6 +3192,9 @@ lto_write_mode_table (void) ob = create_output_block (LTO_section_mode_table); bitpack_d bp = bitpack_create (ob->main_stream); + if (lto_stream_offload_p) + bp_pack_value (&bp, NUM_POLY_INT_COEFFS, MAX_NUM_POLY_INT_COEFFS_BITS); + /* Ensure that for GET_MODE_INNER (m) != m we have also the inner mode marked. */ for (int i = 0; i < (int) MAX_MACHINE_MODE; i++) diff --git a/gcc/poly-int.h b/gcc/poly-int.h index e3f8d4df71646303f882b6dcac16b8b949e0ab60..94708165961625da64238c7ed66463802a344c71 100644 --- a/gcc/poly-int.h +++ b/gcc/poly-int.h @@ -354,6 +354,10 @@ struct poly_result<T1, T2, 2> ? (void) ((RES).coeffs[I] = VALUE) \ : (void) ((RES).coeffs[I].~C (), new (&(RES).coeffs[I]) C (VALUE))) +/* Number of bits needed to represent maximum value of + NUM_POLY_INT_COEFFS defined by any target. */ +#define MAX_NUM_POLY_INT_COEFFS_BITS 2 + /* poly_int_full and poly_int_hungry are used internally within poly_int for delegated initializers. poly_int_full indicates that a parameter pack has enough elements to initialize every coefficient. poly_int_hungry diff --git a/gcc/tree-streamer-in.cc b/gcc/tree-streamer-in.cc index c248a74f7a1a0b3ca6a37eb91a08123e8d9de13c..40029437199cc0a2c597388f0c444234e479f5fd 100644 --- a/gcc/tree-streamer-in.cc +++ b/gcc/tree-streamer-in.cc @@ -671,8 +671,37 @@ static void lto_input_ts_poly_tree_pointers (class lto_input_block *ib, class data_in *data_in, tree expr) { - for (unsigned int i = 0; i < NUM_POLY_INT_COEFFS; ++i) - POLY_INT_CST_COEFF (expr, i) = stream_read_tree_ref (ib, data_in); +#ifdef ACCEL_COMPILER + /* Ensure that we have streamed-in host_num_poly_int_coeffs. */ + const unsigned num_poly_int_coeffs = host_num_poly_int_coeffs; + gcc_assert (num_poly_int_coeffs > 0); +#else + const unsigned num_poly_int_coeffs = NUM_POLY_INT_COEFFS; +#endif + + unsigned i; + if (num_poly_int_coeffs <= NUM_POLY_INT_COEFFS) + { + for (i = 0; i < num_poly_int_coeffs; i++) + POLY_INT_CST_COEFF (expr, i) = stream_read_tree_ref (ib, data_in); + + tree coeff_type = TREE_TYPE (POLY_INT_CST_COEFF (expr, 0)); + for (; i < NUM_POLY_INT_COEFFS; i++) + POLY_INT_CST_COEFF (expr, i) = build_zero_cst (coeff_type); + } + else + { + for (i = 0; i < NUM_POLY_INT_COEFFS; i++) + POLY_INT_CST_COEFF (expr, i) = stream_read_tree_ref (ib, data_in); + for (; i < num_poly_int_coeffs; i++) + { + tree val = stream_read_tree_ref (ib, data_in); + if (!integer_zerop (val)) + fatal_error (input_location, + "degree of %<poly_int%> exceeds " + "%<NUM_POLY_INT_COEFFS%>"); + } + } }