Hello, just trying one more time. Any direction or hint is appreciated. Just as a note, I looked at the ipa-devirt as an inspiration for these small functions I wrote, but for some reason I can't read what I assume have written to the summaries. (What I'm trying to do is simply use LTO using a real IPA_PASS as opposed to SIMPLE_IPA_PASS, and therefore I just want to write some simple summaries and read them).
I have wondered if the bitpack_d bp = bitpack_create (ob->main_stream); creates any difference, but when I tried it that didn't seem to be the case. Many thanks in advance! On Tue, 30 Mar 2021 at 10:18, Erick Ochoa <eoc...@gcc.gnu.org> wrote: > > Hello, > > just trying again to increase visibility of this question. Many thanks > in advance! > > > On Fri, 26 Mar 2021 at 13:49, Erick Ochoa <eoc...@gcc.gnu.org> wrote: > > > > Hello, > > > > I already have some experience developing SIMPLE_IPA_PASSes, but I am > > looking to understand IPA_PASSes better. I have made a hello world ipa > > pass that stores "hello world $FUNCTION_NAME" in the function > > summaries; however, I am having trouble reading this information back. > > Can someone help me understand how to use these interfaces correctly? > > > > At the moment, it **seems** to be writing information correctly. > > (I.e., it doesn't segfault when attempting to write data.) However, in > > my read summary function (ipa_hello_world_read_summary (void)) the > > function `lto_get_summary_section_data (file_data, > > LTO_section_ipa_hello_world, &len);` always returns NULL and > > `file_data_vec` is of size 1. This means that at run time, there is > > only one call to `lto_get_summary_section_data` and it returns NULL. > > > > I am copy-pasting the relevant code below. > > > > /* Map from cgraph_node* to "hello world $FUNCTION_NAME". */ > > static hash_map<cgraph_node*, char*> *hello_summaries; > > > > static void > > ipa_hello_world_write_summary (void) > > { > > gcc_assert(hello_summaries); > > struct output_block *ob = create_output_block > > (LTO_section_ipa_hello_world); > > gcc_assert(ob); > > if (dump_file) fprintf(dump_file, "hello world from write summary\n"); > > lto_symtab_encoder_t encoder = ob->decl_state->symtab_node_encoder; > > if (dump_file) fprintf(dump_file, "writing %d\n", > > hello_summaries->elements()); > > streamer_write_uhwi (ob, hello_summaries->elements()); > > > > for (auto i = hello_summaries->begin(), e = hello_summaries->end(); > > i != e; ++i) > > { > > if (dump_file) fprintf(dump_file, "writing %s\n", (*i).second); > > streamer_write_uhwi(ob, lto_symtab_encoder_encode(encoder, (*i).first)); > > streamer_write_string (ob, ob->main_stream, (*i).second, true); > > } > > produce_asm (ob, NULL); > > destroy_output_block (ob); > > delete hello_summaries; > > } > > > > static void > > ipa_hello_world_read_summary (void) > > { > > struct lto_file_decl_data **file_data_vec = lto_get_file_decl_data (); > > struct lto_file_decl_data *file_data; > > unsigned int j = 0; > > if (dump_file) fprintf(dump_file, "hello from read summary\n"); > > while ((file_data = file_data_vec[j++])) > > { > > if (dump_file) fprintf(dump_file, "iteration = %d\n", j); > > size_t len; > > const char *data = > > lto_get_summary_section_data (file_data, > > LTO_section_ipa_hello_world, &len); > > if (!data) continue; > > > > const struct lto_function_header *header = (const struct > > lto_function_header*) data; > > gcc_assert(header); > > gcc_assert(header->cfg_size); > > const int cfg_offset = sizeof (struct lto_function_header); > > const int main_offset = cfg_offset + header->cfg_size; > > const int string_offset = main_offset + header->main_size; > > class data_in *data_in; > > > > lto_input_block ib ((const char *) data + main_offset, > > header->main_size, > > file_data->mode_table); > > data_in > > = lto_data_in_create (file_data, (const char *) data + string_offset, > > header->string_size, vNULL); > > unsigned int n = streamer_read_uhwi (&ib); > > //hello_summaries = new hash_map<cgraph_node*, char*>; > > for (unsigned i = 0; i < n; i++) > > { > > unsigned int index = streamer_read_uhwi(&ib); > > lto_symtab_encoder_t encoder = file_data->symtab_node_encoder; > > struct cgraph_node *cnode = dyn_cast<cgraph_node *> > > (lto_symtab_encoder_deref(encoder, index)); > > gcc_assert(cnode); > > const char* string = streamer_read_string (data_in, &ib); > > if (dump_file) fprintf(dump_file, string); > > } > > } > > > > }