On Tue, Nov 19, 2013 at 10:58 AM, Ilya Tocar <tocarip.in...@gmail.com> wrote:
> On 14 Nov 11:27, Richard Biener wrote:
>> > +  /* 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.
>
> I've changed it into:
> Set when symbol needs to be dumped into LTO bytecode for LTO,
> or in pragma omp target case, for separate compilation targeting
> a different architecture.
>
> Ok for gomp4 branch now?

Works for me.  I'll let branch maintainers decide if it follows whatever
is done there (I haven't found time to follow stuff here).

Richard.

> 2013-11-19 Ilya Tocar  <ilya.to...@intel.com>
>
>         * cgraph.h (symtab_node): Add need_dump.
>         * cgraphunit.c (ipa_passes): Run ipa_write_summaries for omp.
>         (compile): Intialize streamer for omp.
>         * ipa-inline-analysis.c (inline_generate_summary): Add flag_openmp.
>         * lto-cgraph.c (lto_set_symtab_encoder_in_partition): Respect
>         need_dump flag.
>         (select_what_to_dump): New.
>         * lto-streamer.c (section_name_prefix): New.
>         (lto_get_section_name): Use section_name_prefix.
>         (lto_streamer_init): Add flag_openmp.
>         * lto-streamer.h (OMP_SECTION_NAME_PREFIX): New.
>         (section_name_prefix): Ditto.
>         (select_what_to_dump): Ditto.
>         * lto/lto-partition.c (add_symbol_to_partition_1): Set need_dump.
>         (lto_promote_cross_file_statics): Dump everyhtinh.
>         * passes.c (ipa_write_summaries): Add parameter,
>         call select_what_to_dump.
>         * tree-pass.h (void ipa_write_summaries): Add parameter.
>
>
> ---
>  gcc/cgraph.h              |  5 +++++
>  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, 50 insertions(+), 8 deletions(-)
>
> diff --git a/gcc/cgraph.h b/gcc/cgraph.h
> index fb0fe93..9f799f4 100644
> --- a/gcc/cgraph.h
> +++ b/gcc/cgraph.h
> @@ -105,6 +105,11 @@ public:
>    /* Set when symbol has address taken. */
>    unsigned address_taken : 1;
>
> +  /* Set when symbol needs to be dumped into LTO bytecode for LTO,
> +     or in pragma omp target case, for separate compilation targeting
> +     a different architecture.  */
> +  unsigned need_dump : 1;
> +
>
>    /* 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
>

Reply via email to