On Thu, Nov 14, 2013 at 10:52 AM, Ilya Tocar <[email protected]> wrote:
> On 18 Oct 13:30, Richard Biener wrote:
>> Certainly better than the first version. Jakub should decide for the branch
>> and eventually Honza for the merge to trunk. It still looks somewhat
>> hackish,
>> but I suppose that's because we don't have a LTO-state object where we
>> can encapsulate all this.
>>
>> Also I still don't like the attribute lookup
>>
>> > + /* Ignore non omp target nodes for omp case. */
>> > + if (is_omp && !lookup_attribute ("omp declare target",
>> > + DECL_ATTRIBUTES (node->symbol.decl)))
>> > + return;
>>
>> can we instead please add a flag in cgraph_node?
>
> You mean symtab_node (we also need to dump marked variables)?
> Is patch bellow ok for gomp4 branch?
>
> ---
> gcc/cgraph.h | 3 +++
> gcc/cgraphunit.c | 15 +++++++++++++--
> gcc/ipa-inline-analysis.c | 2 +-
> gcc/lto-cgraph.c | 14 ++++++++++++++
> gcc/lto-streamer.c | 5 +++--
> gcc/lto-streamer.h | 6 ++++++
> gcc/lto/lto-partition.c | 3 +++
> gcc/passes.c | 6 ++++--
> gcc/tree-pass.h | 2 +-
> 9 files changed, 48 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/cgraph.h b/gcc/cgraph.h
> index fb0fe93..601094a 100644
> --- a/gcc/cgraph.h
> +++ b/gcc/cgraph.h
> @@ -105,6 +105,9 @@ public:
> /* Set when symbol has address taken. */
> unsigned address_taken : 1;
>
> + /* Set when symbol needs to be dumped for lto/offloading. */
> + unsigned need_dump : 1;
> +
That's very non-descriptive. What's "offloading"? But yes, something
like this is what I was asking for.
Richard.
> /* Ordering of all symtab entries. */
> int order;
> diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
> index c3a8967..53cd250 100644
> --- a/gcc/cgraphunit.c
> +++ b/gcc/cgraphunit.c
> @@ -2019,7 +2019,18 @@ ipa_passes (void)
> passes->all_lto_gen_passes);
>
> if (!in_lto_p)
> - ipa_write_summaries ();
> + {
> + if (flag_openmp)
> + {
> + section_name_prefix = OMP_SECTION_NAME_PREFIX;
> + ipa_write_summaries (true);
> + }
> + if (flag_lto)
> + {
> + section_name_prefix = LTO_SECTION_NAME_PREFIX;
> + ipa_write_summaries (false);
> + }
> + }
>
> if (flag_generate_lto)
> targetm.asm_out.lto_end ();
> @@ -2110,7 +2121,7 @@ compile (void)
> cgraph_state = CGRAPH_STATE_IPA;
>
> /* If LTO is enabled, initialize the streamer hooks needed by GIMPLE. */
> - if (flag_lto)
> + if (flag_lto || flag_openmp)
> lto_streamer_hooks_init ();
>
> /* Don't run the IPA passes if there was any error or sorry messages. */
> diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
> index 4458723..62faa52 100644
> --- a/gcc/ipa-inline-analysis.c
> +++ b/gcc/ipa-inline-analysis.c
> @@ -3813,7 +3813,7 @@ inline_generate_summary (void)
>
> /* When not optimizing, do not bother to analyze. Inlining is still done
> because edge redirection needs to happen there. */
> - if (!optimize && !flag_lto && !flag_wpa)
> + if (!optimize && !flag_lto && !flag_wpa && !flag_openmp)
> return;
>
> function_insertion_hook_holder =
> diff --git a/gcc/lto-cgraph.c b/gcc/lto-cgraph.c
> index 6a52da8..697c069 100644
> --- a/gcc/lto-cgraph.c
> +++ b/gcc/lto-cgraph.c
> @@ -238,6 +238,9 @@ void
> lto_set_symtab_encoder_in_partition (lto_symtab_encoder_t encoder,
> symtab_node *node)
> {
> + /* Ignore not needed nodes. */
> + if (!node->need_dump)
> + return;
> int index = lto_symtab_encoder_encode (encoder, node);
> encoder->nodes[index].in_partition = true;
> }
> @@ -751,6 +754,17 @@ add_references (lto_symtab_encoder_t encoder,
> lto_symtab_encoder_encode (encoder, ref->referred);
> }
>
> +/* Select what needs to be dumped. In lto case dump everything.
> + In omp target case only dump stuff makrked with attribute. */
> +void
> +select_what_to_dump (bool is_omp)
> +{
> + struct symtab_node *snode;
> + FOR_EACH_SYMBOL(snode)
> + snode->need_dump = !is_omp || lookup_attribute ("omp declare target",
> + DECL_ATTRIBUTES
> (snode->decl));
> +}
> +
> /* Find all symbols we want to stream into given partition and insert them
> to encoders.
>
> diff --git a/gcc/lto-streamer.c b/gcc/lto-streamer.c
> index 1540e4c..ffafb0e 100644
> --- a/gcc/lto-streamer.c
> +++ b/gcc/lto-streamer.c
> @@ -43,6 +43,7 @@ struct lto_stats_d lto_stats;
> static bitmap_obstack lto_obstack;
> static bool lto_obstack_initialized;
>
> +const char *section_name_prefix = LTO_SECTION_NAME_PREFIX;
>
> /* Return a string representing LTO tag TAG. */
>
> @@ -172,7 +173,7 @@ lto_get_section_name (int section_type, const char *name,
> struct lto_file_decl_d
> sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, f->id);
> else
> sprintf (post, "." HOST_WIDE_INT_PRINT_HEX_PURE, get_random_seed
> (false));
> - return concat (LTO_SECTION_NAME_PREFIX, sep, add, post, NULL);
> + return concat (section_name_prefix, sep, add, post, NULL);
> }
>
>
> @@ -310,7 +311,7 @@ lto_streamer_init (void)
> bool
> gate_lto_out (void)
> {
> - return ((flag_generate_lto || in_lto_p)
> + return ((flag_generate_lto || in_lto_p || flag_openmp)
> /* Don't bother doing anything if the program has errors. */
> && !seen_error ());
> }
> diff --git a/gcc/lto-streamer.h b/gcc/lto-streamer.h
> index 797e92e..f4c46db 100644
> --- a/gcc/lto-streamer.h
> +++ b/gcc/lto-streamer.h
> @@ -139,6 +139,11 @@ along with GCC; see the file COPYING3. If not see
> name for the functions and static_initializers. For other types of
> sections a '.' and the section type are appended. */
> #define LTO_SECTION_NAME_PREFIX ".gnu.lto_"
> +#define OMP_SECTION_NAME_PREFIX ".gnu.target_lto_"
> +
> +/* Can be either OMP_SECTION_NAME_PREFIX when we stream pragma omp target
> + stuff, or LTO_SECTION_NAME_PREFIX for lto case. */
> +extern const char *section_name_prefix;
>
> #define LTO_major_version 2
> #define LTO_minor_version 2
> @@ -895,6 +900,7 @@ bool referenced_from_this_partition_p (struct
> ipa_ref_list *,
> bool reachable_from_this_partition_p (struct cgraph_node *,
> lto_symtab_encoder_t);
> lto_symtab_encoder_t compute_ltrans_boundary (lto_symtab_encoder_t encoder);
> +void select_what_to_dump (bool);
>
>
> /* In lto-symtab.c. */
> diff --git a/gcc/lto/lto-partition.c b/gcc/lto/lto-partition.c
> index 6a3d881..2d2aa63 100644
> --- a/gcc/lto/lto-partition.c
> +++ b/gcc/lto/lto-partition.c
> @@ -190,6 +190,7 @@ add_symbol_to_partition_1 (ltrans_partition part,
> symtab_node *node)
> gcc_assert (c != SYMBOL_EXTERNAL
> && (c == SYMBOL_DUPLICATE || !symbol_partitioned_p (node)));
>
> + node->need_dump = true;
> lto_set_symtab_encoder_in_partition (part->encoder, node);
>
> if (symbol_partitioned_p (node))
> @@ -917,6 +918,8 @@ lto_promote_cross_file_statics (void)
>
> gcc_assert (flag_wpa);
>
> + select_what_to_dump (false);
> +
> /* First compute boundaries. */
> n_sets = ltrans_partitions.length ();
> for (i = 0; i < n_sets; i++)
> diff --git a/gcc/passes.c b/gcc/passes.c
> index 19e5869..88b1538 100644
> --- a/gcc/passes.c
> +++ b/gcc/passes.c
> @@ -2335,7 +2335,7 @@ ipa_write_summaries_1 (lto_symtab_encoder_t encoder)
> /* Write out summaries for all the nodes in the callgraph. */
>
> void
> -ipa_write_summaries (void)
> +ipa_write_summaries (bool is_omp)
> {
> lto_symtab_encoder_t encoder;
> int i, order_pos;
> @@ -2343,9 +2343,11 @@ ipa_write_summaries (void)
> struct cgraph_node *node;
> struct cgraph_node **order;
>
> - if (!flag_generate_lto || seen_error ())
> + if (!(flag_generate_lto || flag_openmp) || seen_error () )
> return;
>
> + select_what_to_dump (is_omp);
> +
> encoder = lto_symtab_encoder_new (false);
>
> /* Create the callgraph set in the same order used in
> diff --git a/gcc/tree-pass.h b/gcc/tree-pass.h
> index fa403c7..8d51d80 100644
> --- a/gcc/tree-pass.h
> +++ b/gcc/tree-pass.h
> @@ -595,7 +595,7 @@ extern void pass_fini_dump_file (struct opt_pass *);
> extern const char *get_current_pass_name (void);
> extern void print_current_pass (FILE *);
> extern void debug_pass (void);
> -extern void ipa_write_summaries (void);
> +extern void ipa_write_summaries (bool is_omp);
> extern void ipa_write_optimization_summaries (struct lto_symtab_encoder_d *);
> extern void ipa_read_summaries (void);
> extern void ipa_read_optimization_summaries (void);
> --
> 1.8.3.1
>