public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Tom de Vries <Tom_deVries@mentor.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [libgomp, openacc, openmp, PR83046] Prune removed funcs from offload table
Date: Sat, 30 Dec 2017 09:54:00 -0000	[thread overview]
Message-ID: <20171230095417.GL1833@tucnak> (raw)
In-Reply-To: <76c90534-67c9-aadb-519d-172c3b42072c@mentor.com>

On Fri, Dec 29, 2017 at 02:07:49PM +0100, Tom de Vries wrote:
> --- a/gcc/lto-streamer-out.c
> +++ b/gcc/lto-streamer-out.c
> @@ -41,6 +41,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "builtins.h"
>  #include "gomp-constants.h"
>  #include "debug.h"
> +#include "omp-offload.h"
>  
>  
>  static void lto_write_tree (struct output_block*, tree, bool);
> @@ -2355,6 +2356,31 @@ lto_output (void)
>    int i, n_nodes;
>    lto_symtab_encoder_t encoder = lto_get_out_decl_state ()->symtab_node_encoder;
>  
> +  bool truncated_p = false;

I don't think you need this var.

> +  unsigned int write_index = 0;
> +  for (unsigned read_index = 0; read_index < vec_safe_length (offload_funcs);
> +       read_index++)
> +    {
> +      tree fn_decl = (*offload_funcs)[read_index];
> +      bool remove_p = cgraph_node::get (fn_decl) == NULL;
> +      if (remove_p)
> +	{
> +	  truncated_p = true;
> +	  continue;
> +	}
> +
> +      if (write_index != read_index)
> +	(*offload_funcs)[write_index] = (*offload_funcs)[read_index];
> +
> +      write_index++;
> +    }
> +  if (truncated_p)
> +    offload_funcs->truncate (write_index);

Either you truncate unconditionally, truncate is extremely cheap operation,
or if you really wanted to guard it, you could just do
  if (read_index != write_index)

> +
> +  if (!flag_lto)
> +    for (unsigned i = 0; i < vec_safe_length (offload_funcs); i++)
> +      DECL_PRESERVE_P ((*offload_funcs)[i]) = 1;

Can you please do this inside of the above loop, you have fn_decl already
there, just do it after the
      if (remove_p)
	continue;
And, I think you can do it unconditionally at that point, or, can you use
in_lto_p instead of flag_lto?  flag_lto is set even during the -flto
compilation of the sources before LTO is streamed, there is no need to
pessimize that code, we can still remove it, we just can't remove anything
after we've streamed LTO bytecode (for either the host or offloading
targets).

> @@ -7058,7 +7058,11 @@ expand_omp_target (struct omp_region *region)
>  
>        /* Add the new function to the offload table.  */
>        if (ENABLE_OFFLOADING)
> -	vec_safe_push (offload_funcs, child_fn);
> +	{
> +	  if (flag_lto)
> +	    DECL_PRESERVE_P (child_fn) = 1;

And use if (in_lto_p) here too.

Ok for trunk with those changes.

	Jakub

  reply	other threads:[~2017-12-30  9:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28 15:53 Tom de Vries
2017-12-28 16:07 ` Jakub Jelinek
2017-12-28 16:14   ` Jakub Jelinek
2017-12-29 13:08     ` Tom de Vries
2017-12-30  9:54       ` Jakub Jelinek [this message]
2017-12-30 11:51         ` Tom de Vries
2017-12-29 13:55   ` [RFC] Add vec::ordered_remove_if Tom de Vries
2018-01-02 14:09     ` Richard Biener
2018-01-05 21:06       ` [PATCH] Add VEC_ORDERED_REMOVE_IF Tom de Vries
     [not found]         ` <9ED0B8F9-66A4-40FF-AA22-59C22E6CAA7B@gmail.com>
2018-01-11 13:08           ` Tom de Vries
2018-05-01 18:25             ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171230095417.GL1833@tucnak \
    --to=jakub@redhat.com \
    --cc=Tom_deVries@mentor.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).