From patchwork Fri Nov 12 09:44:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 47511 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1B73385840B for ; Fri, 12 Nov 2021 09:45:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1B73385840B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636710324; bh=O2Ig98ot9sh0zxFAb6ZepGuC5oO10drB9FqfVrCK8+s=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JTEivYsnzgywk60MYmCbLwPJW7zMgk5s/VObsEjOwtVHJonrsr7AEO6az/KHxoo6V o/XDF/hODtTA5Ey5Ihj1CDfLc3YJv3eweIusBqKeEzhSDpWBYqkIi1WHVfETxfxxyP JBOfOVy3skhReW9bXK5E2+YgUk4gBo7wYUH10eUQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 583273858D28 for ; Fri, 12 Nov 2021 09:44:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 583273858D28 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id BF0462809A9; Fri, 12 Nov 2021 10:44:51 +0100 (CET) Date: Fri, 12 Nov 2021 10:44:51 +0100 To: gcc-patches@gcc.gnu.org Subject: Introduce finalize method to modref_summary Message-ID: <20211112094451.GL17431@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch adds finalize method that is called once summary is computed before it is used by optimizers. It adds convenient place to compute various flags as one for DSE Richard asked for. Bootstrapped/regtested x86_64-linux, will commit it shortly. gcc/ChangeLog: * ipa-modref.c (modref_summary::global_memory_read_p): Remove. (modref_summary::global_memory_written_p): Remove. (modref_summary::dump): Dump new flags. (modref_summary::finalize): New member function. (analyze_function): Call it. (read_section): Call it. (update_signature): Call it. (pass_ipa_modref::execute): Call it. * ipa-modref.h (struct modref_summary): Remove global_memory_read_p and global_memory_written_p. Add global_memory_read, global_memory_written. * tree-ssa-structalias.c (determine_global_memory_access): Update. diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index 72006251f29..6cc282292df 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -339,26 +339,6 @@ modref_summary::useful_p (int ecf_flags, bool check_flags) return stores && !stores->every_base; } -/* Return true if global memory is read - (that is loads summary contains global memory access). */ -bool -modref_summary::global_memory_read_p () -{ - if (!loads) - return true; - return loads->global_access_p (); -} - -/* Return true if global memory is written. */ -bool -modref_summary::global_memory_written_p () -{ - if (!stores) - return true; - return stores->global_access_p (); -} - - /* Single function summary used for LTO. */ typedef modref_tree modref_records_lto; @@ -621,6 +601,10 @@ modref_summary::dump (FILE *out) fprintf (out, " Writes errno\n"); if (side_effects) fprintf (out, " Side effects\n"); + if (global_memory_read) + fprintf (out, " Global memory read\n"); + if (global_memory_written) + fprintf (out, " Global memory written\n"); if (arg_flags.length ()) { for (unsigned int i = 0; i < arg_flags.length (); i++) @@ -676,6 +660,15 @@ modref_summary_lto::dump (FILE *out) } } +/* Called after summary is produced and before it is used by local analysis. + Can be called multiple times in case summary needs to update signature. */ +void +modref_summary::finalize () +{ + global_memory_read = !loads || loads->global_access_p (); + global_memory_written = !stores || stores->global_access_p (); +} + /* Get function summary for FUNC if it exists, return NULL otherwise. */ modref_summary * @@ -2782,8 +2775,7 @@ analyze_function (function *f, bool ipa) first = false; } } - if (summary && !summary->global_memory_written_p () && !summary->side_effects - && !finite_function_p ()) + if (summary && !summary->side_effects && !finite_function_p ()) summary->side_effects = true; if (summary_lto && !summary_lto->side_effects && !finite_function_p ()) summary_lto->side_effects = true; @@ -2810,6 +2802,8 @@ analyze_function (function *f, bool ipa) summaries->remove (fnode); summary = NULL; } + else + summary->finalize (); if (summary_lto && !summary_lto->useful_p (ecf_flags)) { summaries_lto->remove (fnode); @@ -3529,6 +3523,8 @@ read_section (struct lto_file_decl_data *file_data, const char *data, modref_read_escape_summary (&bp, e); } } + if (flag_ltrans) + modref_sum->finalize (); if (dump_file) { fprintf (dump_file, "Read modref for %s\n", @@ -3685,6 +3681,8 @@ update_signature (struct cgraph_node *node) if (r_lto) r_lto->dump (dump_file); } + if (r) + r->finalize (); return; } @@ -4905,6 +4903,11 @@ pass_ipa_modref::execute (function *) pureconst |= modref_propagate_in_scc (component_node); modref_propagate_flags_in_scc (component_node); + if (optimization_summaries) + for (struct cgraph_node *cur = component_node; cur; + cur = ((struct ipa_dfs_info *) cur->aux)->next_cycle) + if (modref_summary *sum = optimization_summaries->get (cur)) + sum->finalize (); if (dump_file) modref_propagate_dump_scc (component_node); } diff --git a/gcc/ipa-modref.h b/gcc/ipa-modref.h index 49c99f263a7..9a8d565d770 100644 --- a/gcc/ipa-modref.h +++ b/gcc/ipa-modref.h @@ -33,15 +33,18 @@ struct GTY(()) modref_summary auto_vec GTY((skip)) arg_flags; eaf_flags_t retslot_flags; eaf_flags_t static_chain_flags; - bool writes_errno; - bool side_effects; + unsigned writes_errno : 1; + unsigned side_effects : 1; + /* Flags coputed by finalize method. */ + unsigned global_memory_read : 1; + unsigned global_memory_written : 1; + modref_summary (); ~modref_summary (); void dump (FILE *); bool useful_p (int ecf_flags, bool check_flags = true); - bool global_memory_read_p (); - bool global_memory_written_p (); + void finalize (); }; modref_summary *get_modref_function_summary (cgraph_node *func); diff --git a/gcc/tree-ssa-structalias.c b/gcc/tree-ssa-structalias.c index 153ddf57a61..5a46a7a64b5 100644 --- a/gcc/tree-ssa-structalias.c +++ b/gcc/tree-ssa-structalias.c @@ -4262,9 +4262,9 @@ determine_global_memory_access (gcall *stmt, && (summary = get_modref_function_summary (node))) { if (writes_global_memory && *writes_global_memory) - *writes_global_memory = summary->global_memory_written_p (); + *writes_global_memory = summary->global_memory_written; if (reads_global_memory && *reads_global_memory) - *reads_global_memory = summary->global_memory_read_p (); + *reads_global_memory = summary->global_memory_read; if (reads_global_memory && uses_global_memory && !*reads_global_memory && node->binds_to_current_def_p ()) *uses_global_memory = false;