On Tue, Jun 20, 2023 at 02:08:07PM +0000, Li, Pan2 via Gcc-patches wrote: > Thanks Jakub for the explanation, I have a try like below patch but I am not > quite sure it is expected, and where should I put the assertion. > > > If yes, it needs to > > be unsigned short, if not, we should add an assertion (e.g. on streaming > > in the LTO table) that MAX_MACHINE_MODE <= 256. > > diff --git a/gcc/lto-streamer-in.cc b/gcc/lto-streamer-in.cc > index 2cb83406db5..93ef97ec5d3 100644 > --- a/gcc/lto-streamer-in.cc > +++ b/gcc/lto-streamer-in.cc > @@ -1985,8 +1985,6 @@ lto_input_mode_table (struct lto_file_decl_data > *file_data) > internal_error ("cannot read LTO mode table from %s", > file_data->file_name); > > - unsigned char *table = ggc_cleared_vec_alloc<unsigned char> (1 << 8); > - file_data->mode_table = table; > const struct lto_simple_header_with_strings *header > = (const struct lto_simple_header_with_strings *) data; > int string_offset; > @@ -1994,6 +1992,9 @@ lto_input_mode_table (struct lto_file_decl_data > *file_data) > string_offset = sizeof (*header) + header->main_size; > > lto_input_block ib (data + sizeof (*header), header->main_size, NULL); > + unsigned char *table = ggc_cleared_vec_alloc<unsigned char> ( > + 1 << ib.mode_bits); > + file_data->mode_table = table; > data_in = lto_data_in_create (file_data, data + string_offset, > header->string_size, vNULL); > bitpack_d bp = streamer_read_bitpack (&ib);
Your ib.mode_bits is again the same ceil_log2 (MAX_MACHINE_MODE) value. You need to stream that value out in lto-streamer-out.cc as perhaps the first thing in the bitpack and stream it back here, so some mode_bits = bp_unpack_value (&bp, 5); or so (perhaps 4 would be enough if we only support up to 15 bits for mode). I.e. tell the offloading compiler what value had the host compiler when streaming LTO out. Then move those 3 lines from the above after that. I'd put it next to mode_table, so file_data->mode_bits. The unsigned char *table = ggc_cleared_vec_alloc<unsigned char> ( 1 << ib.mode_bits); formatting is wrong, ( shouldn't if at all possible be the last character on a line. In this case, > --- a/gcc/lto-streamer.h > +++ b/gcc/lto-streamer.h > @@ -352,6 +352,8 @@ public: > > const char *data; > const unsigned char *mode_table; > + /* Indicates how many bits of one machine mode will have. */ > + const unsigned int mode_bits = ceil_log2 (MAX_MACHINE_MODE) ; As I said earlier, I'd put it elsewhere. The formatting is wrong (no space before semicolon) and please don't add NSDMIs in structures which don't have them already. > inline machine_mode > bp_unpack_machine_mode (struct bitpack_d *bp) > { > - return (machine_mode) > - ((class lto_input_block *) > - bp->stream)->mode_table[bp_unpack_enum (bp, machine_mode, 1 << 8)]; > + lto_input_block *input_block = (class lto_input_block *)bp->stream; Wrong formatting again, there shouldn't be two consecutive spaces in there. On the other hand, there should be a space between *) and bp. > + int index = bp_unpack_enum (bp, machine_mode, input_block->mode_bits); > + > + return (machine_mode)input_block->mode_table[index]; And here similarly. Jakub