aboutsummaryrefslogtreecommitdiff
path: root/gcc/lto-cgraph.c
diff options
context:
space:
mode:
authorIlya Verbin <ilya.verbin@intel.com>2014-11-13 13:44:04 +0000
committerKirill Yukhin <kyukhin@gcc.gnu.org>2014-11-13 13:44:04 +0000
commitec6fe917cd323dfe1f84aebe9f3c2eda2b5cbdd1 (patch)
treee5c2e1b47f7ea61d81e7314f0dab30406c0efc09 /gcc/lto-cgraph.c
parent3f341ee716b3e32238c5b57e3282a125e273d6f7 (diff)
downloadgcc-ec6fe917cd323dfe1f84aebe9f3c2eda2b5cbdd1.zip
gcc-ec6fe917cd323dfe1f84aebe9f3c2eda2b5cbdd1.tar.gz
gcc-ec6fe917cd323dfe1f84aebe9f3c2eda2b5cbdd1.tar.bz2
[PATCH 3/7] OpenMP 4.0 offloading infrastructure: Offload tables.
gcc/ * Makefile.in (GTFILES): Add omp-low.h to list of GC files. * cgraphunit.c: Include omp-low.h. * doc/tm.texi: Regenerate. * doc/tm.texi.in (TARGET_RECORD_OFFLOAD_SYMBOL): Document. * gengtype.c (open_base_files): Add omp-low.h to ifiles. * lto-cgraph.c (output_offload_tables): New function. (input_offload_tables): Likewise. * lto-section-in.c (lto_section_name): Add "offload_table". * lto-section-names.h (OFFLOAD_VAR_TABLE_SECTION_NAME): Define. (OFFLOAD_FUNC_TABLE_SECTION_NAME): Likewise. * lto-streamer-out.c (lto_output): Call output_offload_tables. * lto-streamer.h (lto_section_type): Add LTO_section_offload_table. (output_offload_tables, input_offload_tables): Declare. * omp-low.c: Include common/common-target.h and lto-section-names.h. (offload_funcs, offload_vars): New global <tree, va_gc> vectors. (expand_omp_target): Add child_fn into offload_funcs vector. (add_decls_addresses_to_decl_constructor): New function. (omp_finish_file): Likewise. * omp-low.h (omp_finish_file, offload_funcs, offload_vars): Declare. * target.def (record_offload_symbol): New DEFHOOK. * toplev.c: Include omp-low.h. (compile_file): Call omp_finish_file. * varpool.c: Include omp-low.h. (varpool_node::get_create): Add decl into offload_vars vector. gcc/lto/ * lto/lto.c (read_cgraph_and_symbols): Call input_offload_tables. Co-Authored-By: Andrey Turetskiy <andrey.turetskiy@intel.com> Co-Authored-By: Bernd Schmidt <bernds@codesourcery.com> Co-Authored-By: Ilya Tocar <ilya.tocar@intel.com> Co-Authored-By: Michael Zolotukhin <michael.v.zolotukhin@intel.com> From-SVN: r217489
Diffstat (limited to 'gcc/lto-cgraph.c')
-rw-r--r--gcc/lto-cgraph.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
index fc8410c..b29d1b5 100644
--- a/gcc/lto-cgraph.c
+++ b/gcc/lto-cgraph.c
@@ -61,6 +61,7 @@ along with GCC; see the file COPYING3. If not see
#include "context.h"
#include "pass_manager.h"
#include "ipa-utils.h"
+#include "omp-low.h"
/* True when asm nodes has been output. */
bool asm_nodes_output = false;
@@ -1068,6 +1069,50 @@ read_string (struct lto_input_block *ib)
return str;
}
+/* Output function/variable tables that will allow libgomp to look up offload
+ target code.
+ OFFLOAD_FUNCS is filled in expand_omp_target, OFFLOAD_VARS is filled in
+ varpool_node::get_create. In WHOPR (partitioned) mode during the WPA stage
+ both OFFLOAD_FUNCS and OFFLOAD_VARS are filled by input_offload_tables. */
+
+void
+output_offload_tables (void)
+{
+ if (vec_safe_is_empty (offload_funcs) && vec_safe_is_empty (offload_vars))
+ return;
+
+ struct lto_simple_output_block *ob
+ = lto_create_simple_output_block (LTO_section_offload_table);
+
+ for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
+ {
+ streamer_write_enum (ob->main_stream, LTO_symtab_tags,
+ LTO_symtab_last_tag, LTO_symtab_unavail_node);
+ lto_output_fn_decl_index (ob->decl_state, ob->main_stream,
+ (*offload_funcs)[i]);
+ }
+
+ for (unsigned i = 0; i < vec_safe_length (offload_vars); i++)
+ {
+ streamer_write_enum (ob->main_stream, LTO_symtab_tags,
+ LTO_symtab_last_tag, LTO_symtab_variable);
+ lto_output_var_decl_index (ob->decl_state, ob->main_stream,
+ (*offload_vars)[i]);
+ }
+
+ streamer_write_uhwi_stream (ob->main_stream, 0);
+ lto_destroy_simple_output_block (ob);
+
+ /* In WHOPR mode during the WPA stage the joint offload tables need to be
+ streamed to one partition only. That's why we free offload_funcs and
+ offload_vars after the first call of output_offload_tables. */
+ if (flag_wpa)
+ {
+ vec_free (offload_funcs);
+ vec_free (offload_vars);
+ }
+}
+
/* Overwrite the information in NODE based on FILE_DATA, TAG, FLAGS,
STACK_SIZE, SELF_TIME and SELF_SIZE. This is called either to initialize
NODE or to replace the values in it, for instance because the first
@@ -1794,6 +1839,55 @@ input_symtab (void)
}
}
+/* Input function/variable tables that will allow libgomp to look up offload
+ target code, and store them into OFFLOAD_FUNCS and OFFLOAD_VARS. */
+
+void
+input_offload_tables (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;
+
+ while ((file_data = file_data_vec[j++]))
+ {
+ const char *data;
+ size_t len;
+ struct lto_input_block *ib
+ = lto_create_simple_input_block (file_data, LTO_section_offload_table,
+ &data, &len);
+ if (!ib)
+ continue;
+
+ enum LTO_symtab_tags tag
+ = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
+ while (tag)
+ {
+ if (tag == LTO_symtab_unavail_node)
+ {
+ int decl_index = streamer_read_uhwi (ib);
+ tree fn_decl
+ = lto_file_decl_data_get_fn_decl (file_data, decl_index);
+ vec_safe_push (offload_funcs, fn_decl);
+ }
+ else if (tag == LTO_symtab_variable)
+ {
+ int decl_index = streamer_read_uhwi (ib);
+ tree var_decl
+ = lto_file_decl_data_get_var_decl (file_data, decl_index);
+ vec_safe_push (offload_vars, var_decl);
+ }
+ else
+ fatal_error ("invalid offload table in %s", file_data->file_name);
+
+ tag = streamer_read_enum (ib, LTO_symtab_tags, LTO_symtab_last_tag);
+ }
+
+ lto_destroy_simple_input_block (file_data, LTO_section_offload_table,
+ ib, data, len);
+ }
+}
+
/* True when we need optimization summary for NODE. */
static int