From patchwork Tue Aug 9 18:13:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 657441 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s82TX59v4z9s9N for ; Wed, 10 Aug 2016 04:13:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=SO3SJhWa; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; q=dns; s=default; b=V73Q4Nzmp6SR478yE +znHWciKseU3sq+5E3TO9wSRptq9uIOW46S7TJ8E7DJ2l/BaTEgqU4loe7ErjIlM bFu458NP0JQG9Q1/c4YTKGjP9FAJ6SEge89SpajCPU6I2zsxEKeRc7OjvLjKN7qG o53v8vHB1P8ehFLI68U/cSz3zQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=default; bh=Q2qGsAfyxULXV9O6LEttYK6 fz7Y=; b=SO3SJhWaUQaI3bbPziE8q32UiMj4sHb/+ALPNIyJpclZrLA6Ew9KgsV j3GtpZPSpylCKhSTPEAi42E8skT23CVt8MvvtmZcWKXF44+A/6Ol2C7L+Jz2K+k8 IaMuGMO4g9WsXndEM8r4ymFe/2FgGrZy4nhoSUDmsPxmMjQAfAcM= Received: (qmail 42497 invoked by alias); 9 Aug 2016 18:13:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 42420 invoked by uid 89); 9 Aug 2016 18:13:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=callers, UD:length, crazy, PARM_DECLs X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Tue, 09 Aug 2016 18:13:13 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 44B75AAF2; Tue, 9 Aug 2016 18:13:10 +0000 (UTC) Date: Tue, 9 Aug 2016 20:13:10 +0200 From: Martin Jambor To: Prathamesh Kulkarni Cc: Richard Biener , Jan Hubicka , Kugan Vivekanandarajah , gcc Patches Subject: Re: [RFC] ipa bitwise constant propagation Message-ID: <20160809181309.erlp4yxnc5otdtxm@virgil.suse.cz> Mail-Followup-To: Prathamesh Kulkarni , Richard Biener , Jan Hubicka , Kugan Vivekanandarajah , gcc Patches References: <20160805123655.c3oai3ivvecx6zbh@virgil.suse.cz> <20160808140355.sbi7zufcjeieek2p@virgil.suse.cz> <20160809110933.2dpy7qdepugoknp2@virgil.suse.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.2-neo (2016-06-11) X-IsSubscribed: yes Hi, On Tue, Aug 09, 2016 at 05:17:31PM +0530, Prathamesh Kulkarni wrote: > On 9 August 2016 at 16:39, Martin Jambor wrote: > > ... > > >> Instead of storing arg's precision and sign, we should store > >> parameter's precision and sign in ipa_compute_jump_functions_for_edge (). > >> Diff with respect to previous patch: > >> > >> @@ -1688,9 +1690,9 @@ ipa_compute_jump_functions_for_edge (struct > >> ipa_func_body_info *fbi, > >> && (TREE_CODE (arg) == SSA_NAME || TREE_CODE (arg) == INTEGER_CST)) > >> { > >> jfunc->bits.known = true; > >> - jfunc->bits.sgn = TYPE_SIGN (TREE_TYPE (arg)); > >> - jfunc->bits.precision = TYPE_PRECISION (TREE_TYPE (arg)); > >> - > >> + jfunc->bits.sgn = TYPE_SIGN (param_type); > >> + jfunc->bits.precision = TYPE_PRECISION (param_type); > >> + > > > > If you want to use the precision of the formal parameter then you do > > not need to store it to jump functions. Parameter DECLs along with > > their types are readily accessible in IPA (even with LTO). It would > > also be much clearer what is going on, IMHO. > Could you please point out how to access parameter decl in wpa ? > The only reason I ended up putting this in jump function was because > I couldn't figure out how to access param decl during WPA. > I see there's ipa_get_param() in ipa-prop.h however it's gated on > gcc_checking_assert (!flag_wpa), so I suppose I can't use this > during WPA ? > > Alternatively I think I could access cs->callee->decl and get to the param decl > by walking DECL_ARGUMENTS ? Actually, we no longer have DECL_ARGUMENTS during LTO WPA. But in most cases, you can still get at the type with something like the following (only very lightly tested) patch, if Honza does not think it is too crazy. Note that= for old K&R C sources we do not have TYPE_ARG_TYPES and so ipa_get_type can return NULL(!) ...however I wonder whether for such programs the type assumptions made in callers when constructing jump functions can be trusted either. I have to run, we will continue the discussion later. Martin 2016-08-09 Martin Jambor * ipa-prop.h (ipa_param_descriptor): Renamed decl to decl_or_type. Update comment. (ipa_get_param): Updated comment, added assert that we have a PARM_DECL. (ipa_get_type): New function. * ipa-cp.c (ipcp_propagate_stage): Fill in argument types in LTO mode. * ipa-prop.c (ipa_get_param_decl_index_1): Use decl_or_type instead of decl; (ipa_populate_param_decls): Likewise. (ipa_dump_param): Likewise. diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 5b6cb9a..3465da5 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -1952,11 +1952,21 @@ propagate_constants_accross_call (struct cgraph_edge *cs) else i = 0; + /* !!! The following dump is of course only a demonstration that it works: */ + debug_generic_expr (callee->decl); + fprintf (stderr, "\n"); + for (; (i < args_count) && (i < parms_count); i++) { struct ipa_jump_func *jump_func = ipa_get_ith_jump_func (args, i); struct ipcp_param_lattices *dest_plats; + /* !!! The following dump is of course only a demonstration that it + works: */ + fprintf (stderr, " The type of parameter %i is: ", i); + debug_generic_expr (ipa_get_type (callee_info, i)); + fprintf (stderr, "\n"); + dest_plats = ipa_get_parm_lattices (callee_info, i); if (availability == AVAIL_INTERPOSABLE) ret |= set_all_contains_variable (dest_plats); @@ -2936,6 +2946,19 @@ ipcp_propagate_stage (struct ipa_topo_info *topo) { struct ipa_node_params *info = IPA_NODE_REF (node); + /* In LTO we do not have PARM_DECLs but we would still like to be able to + look at types of parameters. */ + if (in_lto_p) + { + tree t = TYPE_ARG_TYPES (TREE_TYPE (node->decl)); + for (int k = 0; k < ipa_get_param_count (info); k++) + { + gcc_assert (t != void_list_node); + info->descriptors[k].decl_or_type = TREE_VALUE (t); + t = t ? TREE_CHAIN (t) : NULL; + } + } + determine_versionability (node, info); if (node->has_gimple_body_p ()) { diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c index 132b622..1eaccdf 100644 --- a/gcc/ipa-prop.c +++ b/gcc/ipa-prop.c @@ -103,9 +103,10 @@ ipa_get_param_decl_index_1 (vec descriptors, tree ptree) { int i, count; + gcc_checking_assert (!flag_wpa); count = descriptors.length (); for (i = 0; i < count; i++) - if (descriptors[i].decl == ptree) + if (descriptors[i].decl_or_type == ptree) return i; return -1; @@ -138,7 +139,7 @@ ipa_populate_param_decls (struct cgraph_node *node, param_num = 0; for (parm = fnargs; parm; parm = DECL_CHAIN (parm)) { - descriptors[param_num].decl = parm; + descriptors[param_num].decl_or_type = parm; descriptors[param_num].move_cost = estimate_move_cost (TREE_TYPE (parm), true); param_num++; @@ -168,10 +169,10 @@ void ipa_dump_param (FILE *file, struct ipa_node_params *info, int i) { fprintf (file, "param #%i", i); - if (info->descriptors[i].decl) + if (info->descriptors[i].decl_or_type) { fprintf (file, " "); - print_generic_expr (file, info->descriptors[i].decl, 0); + print_generic_expr (file, info->descriptors[i].decl_or_type, 0); } } diff --git a/gcc/ipa-prop.h b/gcc/ipa-prop.h index e32d078..1d5ce0b 100644 --- a/gcc/ipa-prop.h +++ b/gcc/ipa-prop.h @@ -283,8 +283,11 @@ ipa_get_jf_ancestor_type_preserved (struct ipa_jump_func *jfunc) struct ipa_param_descriptor { - /* PARAM_DECL of this parameter. */ - tree decl; + /* In analysis and modification phase, this is the PARAM_DECL of this + parameter, in IPA LTO phase, this is the type of the the described + parameter or NULL if not known. Do not read this field directly but + through ipa_get_param and ipa_get_type as appropriate. */ + tree decl_or_type; /* If all uses of the parameter are described by ipa-prop structures, this says how many there are. If any use could not be described by means of ipa-prop structures, this is IPA_UNDESCRIBED_USE. */ @@ -402,13 +405,31 @@ ipa_get_param_count (struct ipa_node_params *info) /* Return the declaration of Ith formal parameter of the function corresponding to INFO. Note there is no setter function as this array is built just once - using ipa_initialize_node_params. */ + using ipa_initialize_node_params. This function should not be called in + WPA. */ static inline tree ipa_get_param (struct ipa_node_params *info, int i) { gcc_checking_assert (!flag_wpa); - return info->descriptors[i].decl; + tree t = info->descriptors[i].decl_or_type; + gcc_checking_assert (TREE_CODE (t) == PARM_DECL); + return t; +} + +/* Return the type of Ith formal parameter of the function corresponding + to INFO if it is known or NULL if not. */ + +static inline tree +ipa_get_type (struct ipa_node_params *info, int i) +{ + tree t = info->descriptors[i].decl_or_type; + if (!t) + return NULL; + if (TYPE_P (t)) + return t; + gcc_checking_assert (TREE_CODE (t) == PARM_DECL); + return TREE_TYPE (t); } /* Return the move cost of Ith formal parameter of the function corresponding