public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Jakub Jelinek <jakub@redhat.com>
Cc: Jan Hubicka <hubicka@ucw.cz>,
	Maxim Ostapenko <m.ostapenko@partner.samsung.com>,
	Yury Gribov <y.gribov@samsung.com>,
	Marek Polacek <polacek@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>,
	Konstantin Serebryany <konstantin.s.serebryany@gmail.com>,
	Maxim Ostapenko <chefmax7@gmail.com>
Subject: Re: [PATCH] Propagate nonfreeing_call_p using ipa-pure-const
Date: Wed, 12 Nov 2014 23:11:00 -0000	[thread overview]
Message-ID: <20141112231108.GC11013@kam.mff.cuni.cz> (raw)
In-Reply-To: <20141112224131.GX5026@tucnak.redhat.com>

> On Wed, Nov 12, 2014 at 02:49:30PM +0400, Maxim Ostapenko wrote:
> > We used this code for IPA propagation of nonfreeing_call_p. It implemented
> > with a separate pass, but it probably could be propagated in some existing
> > one. This analysis doesn't seem to be costly thought, we didn't see any
> > significant slowdown compiling big files.
> 
> Here it is rewritten using ipa-pure-const which is where Richard/Honza
> suggested it should be done in.
> 
> I wonder if the nonfreeing_call_p function shouldn't be moved elsewhere
> though (suggestion where), so that gimple.c doesn't need the cgraph
> includes.
> 
> In any case, bootstrapped/regtested on x86_64-linux and i686-linux.
> 
> 2014-11-12  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* ipa-pure-const.c (struct funct_state_d): Add can_free field.
> 	(varying_state): Add true for can_free.
> 	(check_call): For builtin or internal !nonfreeing_call_p set
> 	local->can_free.
> 	(check_stmt): For asm volatile and asm with "memory" set
> 	local->can_free.
> 	(analyze_function): Clear local->can_free initially, continue
> 	calling check_stmt until all flags are computed, dump can_free
> 	flag.
> 	(pure_const_write_summary): Write can_free flag.
> 	(pure_const_read_summary): Read it back.
> 	(propagate_can_free): New function.
> 	(pass_ipa_pure_const::execute): Call it.
> 	* cgraph.h (cgraph_node): Add nonfreeing_fn member.
> 	* gimple.c: Include ipa-ref.h, lto-streamer.h and cgraph.h.
> 	(nonfreeing_call_p): Return cgraph nonfreeing_fn flag if set.
> 	* cgraph.c (cgraph_node::dump): Dump nonfreeing_fn flag.
> 	* lto-cgraph.c (lto_output_node): Write nonfreeing_fn flag.
> 	(input_overwrite_node): Read it back.
> 
> --- gcc/ipa-pure-const.c.jj	2014-11-12 18:32:56.351139726 +0100
> +++ gcc/ipa-pure-const.c	2014-11-12 21:11:08.574354600 +0100
> @@ -112,11 +112,15 @@ struct funct_state_d
>    bool looping;
>  
>    bool can_throw;
> +
> +  /* If function can call free, munmap or otherwise make previously
> +     non-trapping memory accesses trapping.  */
> +  bool can_free;
>  };
>  
>  /* State used when we know nothing about function.  */
>  static struct funct_state_d varying_state
> -   = { IPA_NEITHER, IPA_NEITHER, true, true, true };
> +   = { IPA_NEITHER, IPA_NEITHER, true, true, true, true };
>  
>  
>  typedef struct funct_state_d * funct_state;
> @@ -559,6 +563,10 @@ check_call (funct_state local, gimple ca
>        enum pure_const_state_e call_state;
>        bool call_looping;
>  
> +      if (gimple_call_builtin_p (call, BUILT_IN_NORMAL)
> +	  && !nonfreeing_call_p (call))
> +	local->can_free = true;
> +
>        if (special_builtin_state (&call_state, &call_looping, callee_t))
>  	{
>  	  worse_state (&local->pure_const_state, &local->looping,
> @@ -589,6 +597,8 @@ check_call (funct_state local, gimple ca
>  	    break;
>  	  }
>      }
> +  else if (gimple_call_internal_p (call) && !nonfreeing_call_p (call))
> +    local->can_free = true;

Actually I think you want to do this for can_throw, too.
We probably do not have throwing internal calls, but it is better to be safe.
> +/* Produce transitive closure over the callgraph and compute can_free
> +   attributes.  */
> +
> +static void
> +propagate_can_free (void)
> +{
> +  struct cgraph_node *node;
> +  struct cgraph_node *w;
> +  struct cgraph_node **order
> +    = XCNEWVEC (struct cgraph_node *, symtab->cgraph_count);
> +  int order_pos;
> +  int i;
> +  struct ipa_dfs_info *w_info;
> +
> +  order_pos = ipa_reduced_postorder (order, true, false, NULL);
> +  if (dump_file)
> +    {
> +      cgraph_node::dump_cgraph (dump_file);
> +      ipa_print_order (dump_file, "reduced", order, order_pos);
> +    }

The propagation seems fine, but I wonder if we won't get better memory locality doing this
during the propagation of pure/const?

nothrow flag goes in separate loop because knowledge of nothrow helps pure/const to work better.
Also one can ignore call edges that are !can_thros_externally to get fewer cycles, but apparently
this got never implemented.
>  	   && gimple_call_flags (call) & ECF_LEAF)
>      return true;
>  
> -  return false;
> +  tree fndecl = gimple_call_fndecl (call);
> +  if (!fndecl)
> +    return false;
> +  struct cgraph_node *n = cgraph_node::get (fndecl);

You want to walk aliases,

  cgraph_node::get (fndecl)->function_symbol (&availability)

> +  if (!n || n->get_availability () <= AVAIL_INTERPOSABLE)

and use availability here.

OK with this change.

Honza

  reply	other threads:[~2014-11-12 23:11 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-03 14:28 [PATCH] Optimize UBSAN_NULL checks, add sanopt.c Marek Polacek
2014-11-03 15:35 ` Jakub Jelinek
2014-11-04 18:36   ` Marek Polacek
2014-11-04 19:18     ` Jakub Jelinek
2014-11-05  9:19 ` Yury Gribov
2014-11-05  9:33   ` Jakub Jelinek
2014-11-05  9:54     ` Yury Gribov
2014-11-05 10:29       ` Marek Polacek
2014-11-05 10:50         ` Jakub Jelinek
2014-11-05 11:23           ` Marek Polacek
2014-11-05 12:16             ` Yury Gribov
2014-11-05 12:22               ` Jakub Jelinek
2014-11-05 12:34                 ` Yury Gribov
2014-11-05 13:13                   ` Yury Gribov
2014-11-05 13:23                     ` Jakub Jelinek
2014-11-05 13:48                       ` Yury Gribov
2014-11-12  9:52                         ` Maxim Ostapenko
2014-11-12 10:11                           ` Jakub Jelinek
2014-11-12 11:54                             ` Maxim Ostapenko
2014-11-12 22:53                               ` [PATCH] Propagate nonfreeing_call_p using ipa-pure-const Jakub Jelinek
2014-11-12 23:11                                 ` Jan Hubicka [this message]
2014-11-13  7:45                                   ` Jakub Jelinek
2014-11-13  8:44                                   ` [PATCH] Propagate nonfreeing_call_p using ipa-pure-const (take 2) Jakub Jelinek
2014-11-13 11:08                                     ` Richard Biener
2014-11-13 12:05                                     ` Jakub Jelinek
2014-11-14 17:44                                       ` Jakub Jelinek
2014-11-14 17:51                                         ` Jan Hubicka
2014-11-11 17:49           ` [RFC PATCH] Optimize ASAN_CHECK checks Jakub Jelinek
2014-11-12  9:26             ` Yury Gribov
2014-11-12 10:35               ` Jakub Jelinek
2014-11-12 11:12                 ` Yury Gribov
2014-11-12 22:41                   ` [PATCH] " Jakub Jelinek
2014-11-14 11:31                     ` Dodji Seketeli
2014-11-14 12:02                       ` Jakub Jelinek
2014-11-14 12:16                         ` Dodji Seketeli
2014-11-14 12:18                           ` Jakub Jelinek
2014-11-14 12:28                             ` Richard Biener
2014-11-14 13:06                               ` Jakub Jelinek
2014-11-14 17:30                           ` Jakub Jelinek
2014-11-25 17:26                 ` [PATCH] Enhance ASAN_CHECK optimization Yury Gribov
2014-11-26  9:59                   ` Jakub Jelinek
2014-11-26 18:43                     ` ygribov
2014-11-26 18:50                       ` Jakub Jelinek
2014-11-26 18:54                         ` ygribov
2014-11-26 19:00                           ` Jakub Jelinek
2014-12-03  8:09                   ` [PATCHv2] " Yury Gribov
2014-12-03  8:36                     ` Jakub Jelinek
2014-12-03  9:04                       ` Yury Gribov
2014-12-03  9:07                         ` Jakub Jelinek

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=20141112231108.GC11013@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=chefmax7@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=konstantin.s.serebryany@gmail.com \
    --cc=m.ostapenko@partner.samsung.com \
    --cc=polacek@redhat.com \
    --cc=y.gribov@samsung.com \
    /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).