From patchwork Tue May 25 23:29:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483793 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Uc3wcEub; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVg515zJz9sTD for ; Wed, 26 May 2021 09:30:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2585385BF9B; Tue, 25 May 2021 23:30:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2585385BF9B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985402; bh=hu1KhhpckOvP4dsDNoK8br8YvfkIZ3L4LUtmFYLIV+A=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Uc3wcEubBYGDMA6r7bT0Lc0YpZVTXWFwhpYttQ5GIJzqGTLqAAUzwJqPmegLsA/Nh rzwvxdU0fh0sV0czU4TVIWYQ4r/1ikJytSunb52IoQYWPx2pouC8N1inqGY3372s++ xmMJa24uD0txdtphE4Czfxr1qZmzb1gVNTcONjOk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 5B2C2385803D for ; Tue, 25 May 2021 23:29:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B2C2385803D Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-n_-yo6IoMf2d8qIiCmCaWg-1; Tue, 25 May 2021 19:29:56 -0400 X-MC-Unique: n_-yo6IoMf2d8qIiCmCaWg-1 Received: by mail-qk1-f197.google.com with SMTP id a76-20020ae9e84f0000b02903a69ae4796aso2582448qkg.12 for ; Tue, 25 May 2021 16:29:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=hu1KhhpckOvP4dsDNoK8br8YvfkIZ3L4LUtmFYLIV+A=; b=pXdGJblw5bVPB9A71Xgag0Laa8OItw6o3Trrmw6+CqV4b7zhXfjP3CBAAKuST3mJF0 y9J33VklUI3tcr9cMBw26oe0QXA3HpgNFjaZio3qpmQkiyMFQ94Zf+TU0iEnFCrqgubm r1jjPOcbM4bomACmQZg/i8cLHyAL8xcNgqUJ9Amb+FiEPTN6lQw5YQL/Wh8/aYo4Ynuq 3ZfUt+ec1+eYwlJtYXZJy3/falrcP3yf8+tC6JdnNmHVdaF2CdI7kw4r87I3i/KrDTrn lhMaYpfQxQTY7Tc3y90l/XvgG/eviraTgSosdHgX713BKYpzZuqytWarwMU1/Z4UJj72 v0EQ== X-Gm-Message-State: AOAM530MUvUAcOGs/nPET2swxlyoQRrpwgFKCwa9T0LgIzGWgSsyJ4Ox zo7L8uTS/T3bTKLVmGbnTy7sgD/2azc+Xdm/sFgf4nWW4LgAo9lEo4wpOgApWIMp222OZPVXb1N TKwLrBs8xB2ilCpHmoQ== X-Received: by 2002:a05:622a:591:: with SMTP id c17mr34445401qtb.20.1621985396059; Tue, 25 May 2021 16:29:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy58f8a7OWUFg6Nin7zjQM1O/KewDmILtyCfIq8RHUQOabBEZ0cXgkbW1ZSaGop0bPza2ce8Q== X-Received: by 2002:a05:622a:591:: with SMTP id c17mr34445384qtb.20.1621985395838; Tue, 25 May 2021 16:29:55 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id y137sm454361qkb.136.2021.05.25.16.29.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:29:55 -0700 (PDT) To: gcc-patches Subject: [PATCH 1/8] Change gori_compute to inherit from gori_map instead of, having a gori-map. Message-ID: Date: Tue, 25 May 2021 19:29:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This is the first in a set of, well, many patches.  It ultimately changes the gori-compute model into a consumer of the range_query class, which allows for much simpler and consistent interaction with the fold_stmt class. I'm basically evolving all the code base to consistently interact with range_query. the gori_compute class currently contains a gori_map class for all the dependency analysis and exports.  This patch changes it to inherit from a gori_map instead, which then exposes all the dependency and exports code to any client using a gori_compute. The upcoming threader code makes extensive use of the dependency analysis, and exposing it also allows the temporal cache to not try to maintain its own (one of the follow on patches) The range_def and gori_map class definitions are moved from gimple-range-gori.cc into the header file, and most of the change is adjustments to calling from the base class instead of invoking a method of the gori_map member. Sometime in the next couple of weeks I'll write up exactly what range-def and gori_map provide, as the threader makes use of it, and I presume there are some other places i could be useful. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 28ceee1b91f48b5ab09cbd20ea6a9de6ea137af8 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 13:45:43 -0400 Subject: [PATCH 1/8] Change gori_compute to inherit from gori_map instead of having a gori-map. Move the classes to the header file and inherit instead of instantiating. * gimple-range-gori.cc (range_def_chain): Move to gimple-range-gori.h. (gori_map): Move to gimple-range-gori.h. (gori_compute::gori_compute): Adjust. (gori_compute::~gori_compute): Delete. (gori_compute::compute_operand_range_switch): Adjust. (gori_compute::compute_operand_range): Adjust. (gori_compute::compute_logical_operands): Adjust. (gori_compute::has_edge_range_p ): Adjust. (gori_compute::set_range_invariant): Delete. (gori_compute::dump): Adjust. (gori_compute::outgoing_edge_range_p): Adjust. * gimple-range-gori.h (class range_def_chain): Relocate here. (class gori_map): Relocate here. (class gori_compute): Inherit from gori_map, and adjust. --- gcc/gimple-range-gori.cc | 76 ++++++---------------------------------- gcc/gimple-range-gori.h | 48 ++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 69 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 420282deb2d..074c025be37 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -91,21 +91,6 @@ is_gimple_logical_p (const gimple *gs) engine implements operations for. */ -class range_def_chain -{ -public: - range_def_chain (); - ~range_def_chain (); - bool has_def_chain (tree name); - bitmap get_def_chain (tree name); - bool in_chain_p (tree name, tree def); -private: - vec m_def_chain; // SSA_NAME : def chain components. - void build_def_chain (tree name, bitmap result, basic_block bb); - int m_logical_depth; -}; - - // Construct a range_def_chain. range_def_chain::range_def_chain () @@ -264,27 +249,6 @@ range_def_chain::get_def_chain (tree name) entire def_chain of all SSA names used in the last statement of the block which generate ranges. */ -class gori_map : public range_def_chain -{ -public: - gori_map (); - ~gori_map (); - - bool is_export_p (tree name, basic_block bb = NULL); - bool def_chain_in_export_p (tree name, basic_block bb); - bitmap exports (basic_block bb); - void set_range_invariant (tree name); - - void dump (FILE *f); - void dump (FILE *f, basic_block bb); -private: - bitmap_obstack m_bitmaps; - vec m_outgoing; // BB: Outgoing ranges calculatable on edges - bitmap m_maybe_variant; // Names which might have outgoing ranges. - void maybe_add_gori (tree name, basic_block bb); - void calculate_gori (basic_block bb); -}; - // Initialize a gori-map structure. @@ -494,7 +458,6 @@ gori_compute::gori_compute () // Create a boolean_type true and false range. m_bool_zero = int_range<2> (boolean_false_node, boolean_false_node); m_bool_one = int_range<2> (boolean_true_node, boolean_true_node); - m_gori_map = new gori_map; unsigned x, lim = last_basic_block_for_fn (cfun); // Calculate outgoing range info upfront. This will fully populate the // m_maybe_variant bitmap which will help eliminate processing of names @@ -503,17 +466,10 @@ gori_compute::gori_compute () { basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); if (bb) - m_gori_map->exports (bb); + exports (bb); } } -// Destruct a gori_compute_object. - -gori_compute::~gori_compute () -{ - delete m_gori_map; -} - // Provide a default of VARYING for all incoming SSA names. void @@ -597,7 +553,7 @@ gori_compute::compute_operand_range_switch (irange &r, gswitch *s, } // If op1 is in the defintion chain, pass lhs back. - if (gimple_range_ssa_p (op1) && m_gori_map->in_chain_p (name, op1)) + if (gimple_range_ssa_p (op1) && in_chain_p (name, op1)) return compute_operand_range (r, SSA_NAME_DEF_STMT (op1), lhs, name); return false; @@ -635,8 +591,8 @@ gori_compute::compute_operand_range (irange &r, gimple *stmt, // NAME is not in this stmt, but one of the names in it ought to be // derived from it. - bool op1_in_chain = op1 && m_gori_map->in_chain_p (name, op1); - bool op2_in_chain = op2 && m_gori_map->in_chain_p (name, op2); + bool op1_in_chain = op1 && in_chain_p (name, op1); + bool op2_in_chain = op2 && in_chain_p (name, op2); if (op1_in_chain && op2_in_chain) return compute_operand1_and_operand2_range (r, stmt, lhs, name); if (op1_in_chain) @@ -881,10 +837,8 @@ gori_compute::compute_logical_operands (irange &r, gimple *stmt, tree op2 = gimple_range_operand2 (stmt); gcc_checking_assert (op1 != name && op2 != name); - bool op1_in_chain = (gimple_range_ssa_p (op1) - && m_gori_map->in_chain_p (name, op1)); - bool op2_in_chain = (gimple_range_ssa_p (op2) - && m_gori_map->in_chain_p (name, op2)); + bool op1_in_chain = (gimple_range_ssa_p (op1) && in_chain_p (name, op1)); + bool op2_in_chain = (gimple_range_ssa_p (op2) && in_chain_p (name, op2)); // If neither operand is derived, then this stmt tells us nothing. if (!op1_in_chain && !op2_in_chain) @@ -1014,18 +968,10 @@ gori_compute::has_edge_range_p (tree name, edge e) { // If no edge is specified, check if NAME is an export on any edge. if (!e) - return m_gori_map->is_export_p (name); + return is_export_p (name); - return (m_gori_map->is_export_p (name, e->src) - || m_gori_map->def_chain_in_export_p (name, e->src)); -} - -// Clear the m_maybe_variant bit so ranges will not be tracked for NAME. - -void -gori_compute::set_range_invariant (tree name) -{ - m_gori_map->set_range_invariant (name); + return (is_export_p (name, e->src) + || def_chain_in_export_p (name, e->src)); } // Dump what is known to GORI computes to listing file F. @@ -1033,7 +979,7 @@ gori_compute::set_range_invariant (tree name) void gori_compute::dump (FILE *f) { - m_gori_map->dump (f); + gori_map::dump (f); } // Calculate a range on edge E and return it in R. Try to evaluate a @@ -1052,7 +998,7 @@ gori_compute::outgoing_edge_range_p (irange &r, edge e, tree name) return false; // If NAME can be calculated on the edge, use that. - if (m_gori_map->is_export_p (name, e->src)) + if (is_export_p (name, e->src)) { if (compute_operand_range (r, stmt, lhs, name)) { diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 7bb18a9baf1..6208931a0d8 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -22,6 +22,49 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_GIMPLE_RANGE_GORI_H #define GCC_GIMPLE_RANGE_GORI_H +// RANGE_DEF_CHAIN is used to determine which SSA names in a block can +// have range information calculated for them, and what the +// dependencies on each other are. + +class range_def_chain +{ +public: + range_def_chain (); + ~range_def_chain (); + bool has_def_chain (tree name); + bitmap get_def_chain (tree name); + bool in_chain_p (tree name, tree def); +private: + vec m_def_chain; // SSA_NAME : def chain components. + void build_def_chain (tree name, bitmap result, basic_block bb); + int m_logical_depth; +}; + +// GORI_MAP is used to accumulate what SSA names in a block can +// generate range information, and provides tools for the block ranger +// to enable it to efficiently calculate these ranges. + +class gori_map : public range_def_chain +{ +public: + gori_map (); + ~gori_map (); + + bool is_export_p (tree name, basic_block bb = NULL); + bool def_chain_in_export_p (tree name, basic_block bb); + bitmap exports (basic_block bb); + void set_range_invariant (tree name); + + void dump (FILE *f); + void dump (FILE *f, basic_block bb); +private: + bitmap_obstack m_bitmaps; + vec m_outgoing; // BB: Outgoing ranges calculatable on edges + bitmap m_maybe_variant; // Names which might have outgoing ranges. + void maybe_add_gori (tree name, basic_block bb); + void calculate_gori (basic_block bb); +}; + // This class is used to determine which SSA_NAMES can have ranges // calculated for them on outgoing edges from basic blocks. This represents @@ -65,14 +108,12 @@ along with GCC; see the file COPYING3. If not see // // The remaining routines are internal use only. -class gori_compute +class gori_compute : public gori_map { public: gori_compute (); - ~gori_compute (); bool outgoing_edge_range_p (irange &r, edge e, tree name); bool has_edge_range_p (tree name, edge e = NULL); - void set_range_invariant (tree name); void dump (FILE *f); protected: virtual void ssa_range_in_bb (irange &r, tree name, basic_block bb); @@ -107,7 +148,6 @@ private: bool compute_operand1_and_operand2_range (irange &r, gimple *stmt, const irange &lhs, tree name); - class gori_map *m_gori_map; gimple_outgoing_range outgoing; // Edge values for COND_EXPR & SWITCH_EXPR. }; -- 2.17.2 From patchwork Tue May 25 23:30:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483794 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=HsYCJNmo; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVgL5Rmtz9sTD for ; Wed, 26 May 2021 09:30:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AFD513857413; Tue, 25 May 2021 23:30:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AFD513857413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985420; bh=d/kfL2eaOvtL9MyqDG6M+xiKh3mxQsLobyEI5nEFBgk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=HsYCJNmob+Qb+XsmkQRo764ykm3uTeJCGutMlasZbdcru8YCuukennvnQPibANK9Q JfYGUKDN7/i5tLeEyV99QKZ8hLurSPvuXYInZvS2KPdS4dUUAZUryg8cqyotHj1cET lfMUVbXsPRnYnRdTWE5ORWmz8ZHZ8X6rRvefCEdM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 29176385803D for ; Tue, 25 May 2021 23:30:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 29176385803D Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-SnOV4ICvNhyPFmfPAR5kZA-1; Tue, 25 May 2021 19:30:13 -0400 X-MC-Unique: SnOV4ICvNhyPFmfPAR5kZA-1 Received: by mail-qt1-f200.google.com with SMTP id b20-20020ac87fd40000b02901e1370c5e12so27509472qtk.17 for ; Tue, 25 May 2021 16:30:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=d/kfL2eaOvtL9MyqDG6M+xiKh3mxQsLobyEI5nEFBgk=; b=cHjlX3rW1D3UEVtSe8KFGvzVhXetS03HhM1d3sP54ykXoAobzFLxySFb/HXBoj4q98 9JcMGwB2i8r7XSyme6PgB76UqW26oP5XPblwiGhwfRvnEwbbmw2mHk/uL9EYDI20YJS0 jD1mk2YvdsnHJ0M/3ol6egh5EH/HmAnJcasW5y4pn2XJ06dUAAjD/UXFzTuosIjcuW3u 4bWYS6QnN8N4cguDmBR1QUJCSivz9nGjIDX97hJvEo44rn+eTZugnejFTmFUrGgE9gCZ XBV1lASoxvWIamjC8ftkYEv1m3bfH1bbeGz5fNFL59ZN6aCDEhLGmnLVCVpU1E1KMWLk SAmA== X-Gm-Message-State: AOAM530JFEdr5mn6kGV8j6Et052gFU+t2B6cp6egljvJ05uv8wpAn1fH owm+rH3qdG+75ew56ctdKx9RsD4EHFeY0bjMP6epRZFYmUL07+QjObrZal8oIT9UdpjKLMrrnTZ ezKJSHf5LlOviVpyhoQ== X-Received: by 2002:a37:7d06:: with SMTP id y6mr38620745qkc.472.1621985413281; Tue, 25 May 2021 16:30:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwD3zIIjdqRjCJ6BaEER+BCD09nT+xG9TrBtj5KVcXmvcYptuS7Frc0XQJLhm6tek7j9FTk6Q== X-Received: by 2002:a37:7d06:: with SMTP id y6mr38620737qkc.472.1621985413143; Tue, 25 May 2021 16:30:13 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id 42sm431857qtf.37.2021.05.25.16.30.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:30:12 -0700 (PDT) To: gcc-patches Subject: [PATCH 2/8] fully populate the export list from range_cache, not, gori_compute. Message-ID: <829cf0ed-c026-3731-bb75-6eca05c0ccdc@redhat.com> Date: Tue, 25 May 2021 19:30:11 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Ranger wants to prepopulate all the export blocks so that it has an initial invariant set of names. GORI consumers shouldn't be penalized for ranger requirements.  This way any gori client remains lightweight. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From cb33af1a62b09576b0782ac36e5f5cff049f1035 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 13:53:25 -0400 Subject: [PATCH 2/8] fully populate the export list from range_cache, not gori_compute. Ranger wants to prepopulate all the export blocks so that it has an initial invariant set of names. GORI consumers shouldn't be penalized for ranger requirements. This way any gori client remains lightweight. * gimple-range-cache.cc (ranger_cache::ranger_cache): Move initial export cache filling to here. * gimple-range-gori.cc (gori_compute::gori_compute) : From Here. --- gcc/gimple-range-cache.cc | 10 ++++++++++ gcc/gimple-range-gori.cc | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 2c922e32913..8ad76048272 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -618,6 +618,16 @@ ranger_cache::ranger_cache (gimple_ranger &q) : query (q) m_poor_value_list.safe_grow_cleared (20); m_poor_value_list.truncate (0); m_temporal = new temporal_cache; + unsigned x, lim = last_basic_block_for_fn (cfun); + // Calculate outgoing range info upfront. This will fully populate the + // m_maybe_variant bitmap which will help eliminate processing of names + // which never have their ranges adjusted. + for (x = 0; x < lim ; x++) + { + basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); + if (bb) + exports (bb); + } } ranger_cache::~ranger_cache () diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 074c025be37..e30049edfbd 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -458,16 +458,6 @@ gori_compute::gori_compute () // Create a boolean_type true and false range. m_bool_zero = int_range<2> (boolean_false_node, boolean_false_node); m_bool_one = int_range<2> (boolean_true_node, boolean_true_node); - unsigned x, lim = last_basic_block_for_fn (cfun); - // Calculate outgoing range info upfront. This will fully populate the - // m_maybe_variant bitmap which will help eliminate processing of names - // which never have their ranges adjusted. - for (x = 0; x < lim ; x++) - { - basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); - if (bb) - exports (bb); - } } // Provide a default of VARYING for all incoming SSA names. -- 2.17.2 From patchwork Tue May 25 23:30:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483795 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=oDhIy/Sj; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVgh5Mrpz9sCD for ; Wed, 26 May 2021 09:30:40 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 56F633857802; Tue, 25 May 2021 23:30:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56F633857802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985438; bh=AzzCBNnzDO3Nc62ymmkylGo/w2+ktgGFAgAv8AG3Stk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oDhIy/Sjm3NsVOokR4pCBZsrioPLnzz0mUTsh5Nzcpedf6ZQmDi7RWhK+vO4GptYE RH8h0zVmxUwGZZpKwaWmKcard5vnh3o8BFTvCKkK82nRJnppbJEBNxkLjmqOaThoz/ v837nEWF0Y1Sa4MpQlJaJLdz1M5ezeyf+b4y4vDk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id B14FC385803D for ; Tue, 25 May 2021 23:30:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B14FC385803D Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-505-uA_oqy0hNMeBY881OyVhSQ-1; Tue, 25 May 2021 19:30:31 -0400 X-MC-Unique: uA_oqy0hNMeBY881OyVhSQ-1 Received: by mail-qv1-f72.google.com with SMTP id b24-20020a0cb3d80000b02901e78b82d74aso31954113qvf.20 for ; Tue, 25 May 2021 16:30:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=TPYxgLMXdT7VUhqhRhARUWNHG/HKm0GiWw5jA4vIw4w=; b=ugxqyocWAmzfsDhe0loc7tiWQdaS89CObHfyDmW+QfLVkLWJnSYAq3T9YhTmtuH0xD /W4TLXu2OZfiNeAuOzd8i13dYoo2jkQja1Qnx3hSD+i3qJfIB9ZkxWNuSDUeTmoveFqb RxpBb4odbgXQofu64gDSYejavBfU9+0uvbf6VkQJbif26ZtPXSVQ6o4YZswS8rHUANlA BbULsG+dsAD2HMe+Y7g7PkpWkB4KSdCfacIz6OigIA05R9hmvxjJ5bmHGzoLpL1KPpMx cU4cGyXLlaF7VTqeL+gi25ZJcA9WyP7DgT7rP3hycGTJA2O+FWshdgc8PHBZ4NXwblRF Y0Gg== X-Gm-Message-State: AOAM5326jdENTFHTi2xMbVUUkfKBEF0UgoeF8EeWwzkL2lK4EFU4h9Mn Inocw3vzKR6GyVyqdlQzkjRucq9Dq8IqQ3nHx8voF/SlXBQYVb6IMDzHnixr95J6S9N27YsGIdN kDXIvNKFZLkJT7pY6Cg== X-Received: by 2002:a0c:e752:: with SMTP id g18mr7212897qvn.24.1621985431245; Tue, 25 May 2021 16:30:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDy4sIC4sWvTit9Zr4pn7rvjHScwWfhZhsvqCd0MAR9NBTfvB6/GFCxz5JG/ud3/FvME9RMg== X-Received: by 2002:a0c:e752:: with SMTP id g18mr7212886qvn.24.1621985431115; Tue, 25 May 2021 16:30:31 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id q21sm488503qke.32.2021.05.25.16.30.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:30:30 -0700 (PDT) To: gcc-patches Subject: [PATCH 3/8] Add imports and strengthen the export definition to range_def and gori_map. Message-ID: <725bf67f-d257-ede6-d215-ef140741f342@redhat.com> Date: Tue, 25 May 2021 19:30:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch introduced imports to range_def, and corrects some minor issues with export calculation. When gori-compute is evaluating sequences in a block:   - an "export" is defined as any ssa_name which may have a range calculated on an outgoing edge.  If the edge may CHANGE the value of ssa-name from its on-entry/exit value, then it is an export.  - an "import" is any ssa name which which may affect the outgoing value of an export.   This may be the ssa_anme itself, or and ssa_name used in the calculation of the ssa_name value. bb5: b_6 = a_4 + 5 c_5 = b_6 < z_9 if (c_5 != 0) in this small sample c_5, b_6, z_9 and a_4 are all exports, because we may be able to refine a range for any of them on one of the edges a_4 and z_9 are considered imports because those are the ssa_names which have definitions occurring outside the block which can affect the value of any an exports. This patch introduces imports to  both range_def and gori_map, as well as standardizes the dependency chain registration API so we can also cache up to 2 direct dependent names and eventually utilize that for re-computation and the temporal cache. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From c21644704160710a17d1ea6c1cd212e079cd5e36 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:15:50 -0400 Subject: [PATCH 3/8] Add imports and strengthen the export definition in range_def and gori_map. All add up to 2 direct dependencies for each ssa-name. Add gori import/export iterators. * gimple-range-gori.cc (range_def_chain::range_def_chain): init bitmap obstack. (range_def_chain::~range_def_chain): Dispose of obstack rather than each individual bitmap. (range_def_chain::set_import): New. (range_def_chain::get_imports): New. (range_def_chain::chain_import_p): New. (range_def_chain::register_dependency): Rename from build_def_chain and set imports. (range_def_chain::def_chain_in_bitmap_p): New. (range_def_chain::add_def_chain_to_bitmap): New. (range_def_chain::has_def_chain): Just check first depenedence. (range_def_chain::get_def_chain): Process imports, use generic register_dependency routine. (range_def_chain::dump): New. (gori_map::gori_map): Allocate import list. (gori_map::~gori_map): Release imports. (gori_map::exports): Check for past allocated block size. (gori_map::imports): New. (gori_map::def_chain_in_export_p): Delete. (gori_map::is_import_p): New. (gori_map::maybe_add_gori): Handle imports. (gori_map::dump): Adjust output, add imports. (gori_compute::has_edge_range_p): Remove def_chain_in_export call. (gori_export_iterator::gori_export_iterator): New. (gori_export_iterator::next): New. (gori_export_iterator::get_name): New. * gimple-range-gori.h (range_def_chain): Add imports and direct dependecies via struct rdc. (range_def_chain::depend1): New. (range_def_chain::depend2): New. (class gori_map): Adjust. (FOR_EACH_GORI_IMPORT_NAME): New. (FOR_EACH_GORI_EXPORT_NAME): New. (class gori_export_iterator): New. --- gcc/gimple-range-gori.cc | 356 ++++++++++++++++++++++++++++----------- gcc/gimple-range-gori.h | 77 ++++++++- 2 files changed, 327 insertions(+), 106 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index e30049edfbd..94640adc041 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -56,7 +56,7 @@ is_gimple_logical_p (const gimple *gs) return false; } -/* RANGE_DEF_CHAIN is used to determine what SSA names in a block can +/* RANGE_DEF_CHAIN is used to determine which SSA names in a block can have range information calculated for them, and what the dependencies on each other are. @@ -95,6 +95,7 @@ is_gimple_logical_p (const gimple *gs) range_def_chain::range_def_chain () { + bitmap_obstack_initialize (&m_bitmaps); m_def_chain.create (0); m_def_chain.safe_grow_cleared (num_ssa_names); m_logical_depth = 0; @@ -104,11 +105,8 @@ range_def_chain::range_def_chain () range_def_chain::~range_def_chain () { - unsigned x; - for (x = 0; x < m_def_chain.length (); ++x) - if (m_def_chain[x]) - BITMAP_FREE (m_def_chain[x]); m_def_chain.release (); + bitmap_obstack_release (&m_bitmaps); } // Return true if NAME is in the def chain of DEF. If BB is provided, @@ -128,26 +126,112 @@ range_def_chain::in_chain_p (tree name, tree def) return bitmap_bit_p (chain, SSA_NAME_VERSION (name)); } +// Add either IMP or the import list B to the import set of DATA. + +void +range_def_chain::set_import (struct rdc &data, tree imp, bitmap b) +{ + // If there are no imports, just return + if (imp == NULL_TREE && !b) + return; + if (!data.m_import) + data.m_import = BITMAP_ALLOC (&m_bitmaps); + if (imp != NULL_TREE) + bitmap_set_bit (data.m_import, SSA_NAME_VERSION (imp)); + else + bitmap_ior_into (data.m_import, b); +} + +// Return the import list for NAME. + +bitmap +range_def_chain::get_imports (tree name) +{ + if (!has_def_chain (name)) + get_def_chain (name); + bitmap i = m_def_chain[SSA_NAME_VERSION (name)].m_import; + // Either this is a default def, OR imports must be a subset of exports. + gcc_checking_assert (!get_def_chain (name) || !i + || !bitmap_intersect_compl_p (i, get_def_chain (name))); + return i; +} + +// Return true if IMPORT is an import to NAMEs def chain. + +bool +range_def_chain::chain_import_p (tree name, tree import) +{ + bitmap b = get_imports (name); + if (b) + return bitmap_bit_p (b, SSA_NAME_VERSION (import)); + return false; +} + // Build def_chains for NAME if it is in BB. Copy the def chain into RESULT. void -range_def_chain::build_def_chain (tree name, bitmap result, basic_block bb) +range_def_chain::register_dependency (tree name, tree dep, basic_block bb) { + if (!gimple_range_ssa_p (dep)) + return; + + unsigned v = SSA_NAME_VERSION (name); + struct rdc &src = m_def_chain[v]; + gimple *def_stmt = SSA_NAME_DEF_STMT (dep); + unsigned dep_v = SSA_NAME_VERSION (dep); bitmap b; - gimple *def_stmt = SSA_NAME_DEF_STMT (name); + + // Set the direct dependency cache entries. + if (!src.ssa1) + src.ssa1 = dep; + else if (!src.ssa2 && src.ssa1 != dep) + src.ssa2 = dep; + + // Don't calculate imports or export/dep chains if BB is not provided. + // This is usually the case for when the temporal cache wants the direct + // dependencies of a stmt. + if (!bb) + return; + + if (!src.bm) + src.bm = BITMAP_ALLOC (&m_bitmaps); + // Add this operand into the result. - bitmap_set_bit (result, SSA_NAME_VERSION (name)); + bitmap_set_bit (src.bm, dep_v); if (gimple_bb (def_stmt) == bb && !is_a(def_stmt)) { // Get the def chain for the operand. - b = get_def_chain (name); + b = get_def_chain (dep); // If there was one, copy it into result. if (b) - bitmap_ior_into (result, b); + bitmap_ior_into (src.bm, b); + // And copy the import list. + set_import (src, NULL_TREE, get_imports (dep)); } + else + // Originated outside the block, so it is an import. + set_import (src, dep, NULL); +} + +bool +range_def_chain::def_chain_in_bitmap_p (tree name, bitmap b) +{ + bitmap a = get_def_chain (name); + if (a && b) + return bitmap_intersect_p (a, b); + return false; } +void +range_def_chain::add_def_chain_to_bitmap (bitmap b, tree name) +{ + bitmap r = get_def_chain (name); + if (r) + bitmap_ior_into (b, r); +} + + // Return TRUE if NAME has been processed for a def_chain. inline bool @@ -157,9 +241,11 @@ range_def_chain::has_def_chain (tree name) unsigned v = SSA_NAME_VERSION (name); if (v >= m_def_chain.length ()) m_def_chain.safe_grow_cleared (num_ssa_names + 1); - return (m_def_chain[v] != NULL); + return (m_def_chain[v].ssa1 != 0); } + + // Calculate the def chain for NAME and all of its dependent // operands. Only using names in the same BB. Return the bitmap of // all names in the m_def_chain. This only works for supported range @@ -174,11 +260,15 @@ range_def_chain::get_def_chain (tree name) // If it has already been processed, just return the cached value. if (has_def_chain (name)) - return m_def_chain[v]; + return m_def_chain[v].bm; // No definition chain for default defs. if (SSA_NAME_IS_DEFAULT_DEF (name)) - return NULL; + { + // A Default def is always an import. + set_import (m_def_chain[v], name, NULL); + return NULL; + } gimple *stmt = SSA_NAME_DEF_STMT (name); if (gimple_range_handler (stmt)) @@ -205,30 +295,63 @@ range_def_chain::get_def_chain (tree name) ssa3 = gimple_range_ssa_p (gimple_assign_rhs3 (st)); } else - return NULL; - - basic_block bb = gimple_bb (stmt); - - m_def_chain[v] = BITMAP_ALLOC (NULL); + { + // Stmts not understood are always imports. + set_import (m_def_chain[v], name, NULL); + return NULL; + } - if (ssa1) - build_def_chain (ssa1, m_def_chain[v], bb); - if (ssa2) - build_def_chain (ssa2, m_def_chain[v], bb); - if (ssa3) - build_def_chain (ssa3, m_def_chain[v], bb); + register_dependency (name, ssa1, gimple_bb (stmt)); + register_dependency (name, ssa2, gimple_bb (stmt)); + register_dependency (name, ssa3, gimple_bb (stmt)); + // Stmts with no understandable operands are also imports. + if (!ssa1 && !ssa2 & !ssa3) + set_import (m_def_chain[v], name, NULL); if (is_logical) m_logical_depth--; - // If we run into pathological cases where the defintion chains are - // huge (ie huge basic block fully unrolled) we might be able to limit - // this by deciding here that if some criteria is satisfied, we change the - // def_chain back to be just the ssa-names. That will help prevent chains - // of a_2 = b_6 + a_8 from creating a pathological case. - return m_def_chain[v]; + return m_def_chain[v].bm; +} + +// Dump what we know for basic block BB to file F. + +void +range_def_chain::dump (FILE *f, basic_block bb, const char *prefix) +{ + unsigned x, y; + bitmap_iterator bi; + + // Dump the def chain for each SSA_NAME defined in BB. + for (x = 1; x < num_ssa_names; x++) + { + tree name = ssa_name (x); + if (!name) + continue; + gimple *stmt = SSA_NAME_DEF_STMT (name); + if (!stmt || (bb && gimple_bb (stmt) != bb)) + continue; + bitmap chain = (has_def_chain (name) ? get_def_chain (name) : NULL); + if (chain && !bitmap_empty_p (chain)) + { + fprintf (f, prefix); + print_generic_expr (f, name, TDF_SLIM); + fprintf (f, " : "); + + bitmap imports = get_imports (name); + EXECUTE_IF_SET_IN_BITMAP (chain, 0, y, bi) + { + print_generic_expr (f, ssa_name (y), TDF_SLIM); + if (imports && bitmap_bit_p (imports, y)) + fprintf (f, "(I)"); + fprintf (f, " "); + } + fprintf (f, "\n"); + } + } } + // ------------------------------------------------------------------- /* GORI_MAP is used to accumulate what SSA names in a block can @@ -256,7 +379,8 @@ gori_map::gori_map () { m_outgoing.create (0); m_outgoing.safe_grow_cleared (last_basic_block_for_fn (cfun)); - bitmap_obstack_initialize (&m_bitmaps); + m_incoming.create (0); + m_incoming.safe_grow_cleared (last_basic_block_for_fn (cfun)); m_maybe_variant = BITMAP_ALLOC (&m_bitmaps); } @@ -264,7 +388,7 @@ gori_map::gori_map () gori_map::~gori_map () { - bitmap_obstack_release (&m_bitmaps); + m_incoming.release (); m_outgoing.release (); } @@ -273,11 +397,21 @@ gori_map::~gori_map () bitmap gori_map::exports (basic_block bb) { - if (!m_outgoing[bb->index]) + if (bb->index >= (signed int)m_outgoing.length () || !m_outgoing[bb->index]) calculate_gori (bb); return m_outgoing[bb->index]; } +// Return the bitmap vector of all imports to BB. Calculate if necessary. + +bitmap +gori_map::imports (basic_block bb) +{ + if (bb->index >= (signed int)m_outgoing.length () || !m_outgoing[bb->index]) + calculate_gori (bb); + return m_incoming[bb->index]; +} + // Return true if NAME is can have ranges generated for it from basic // block BB. @@ -298,17 +432,13 @@ gori_map::set_range_invariant (tree name) bitmap_clear_bit (m_maybe_variant, SSA_NAME_VERSION (name)); } -// Return true if any element in the def chain of NAME is in the -// export list for BB. +// Return true if NAME is an import to block BB. bool -gori_map::def_chain_in_export_p (tree name, basic_block bb) +gori_map::is_import_p (tree name, basic_block bb) { - bitmap a = exports (bb); - bitmap b = get_def_chain (name); - if (a && b) - return bitmap_intersect_p (a, b); - return false; + // If no BB is specified, test if it is exported anywhere in the IL. + return bitmap_bit_p (imports (bb), SSA_NAME_VERSION (name)); } // If NAME is non-NULL and defined in block BB, calculate the def @@ -319,11 +449,17 @@ gori_map::maybe_add_gori (tree name, basic_block bb) { if (name) { - gimple *s = SSA_NAME_DEF_STMT (name); - bitmap r = get_def_chain (name); - // Check if there is a def chain, and it is in this block. - if (r && gimple_bb (s) == bb) - bitmap_copy (m_outgoing[bb->index], r); + // Check if there is a def chain, regardless of the block. + add_def_chain_to_bitmap (m_outgoing[bb->index], name); + // Check for any imports. + bitmap imp = get_imports (name); + // If there were imports, add them so we can recompute + if (imp) + bitmap_ior_into (m_incoming[bb->index], imp); + // This name is always an import. + if (gimple_bb (SSA_NAME_DEF_STMT (name)) != bb) + bitmap_set_bit (m_incoming[bb->index], SSA_NAME_VERSION (name)); + // Def chain doesn't include itself, and even if there isn't a // def chain, this name should be added to exports. bitmap_set_bit (m_outgoing[bb->index], SSA_NAME_VERSION (name)); @@ -337,9 +473,13 @@ gori_map::calculate_gori (basic_block bb) { tree name; if (bb->index >= (signed int)m_outgoing.length ()) - m_outgoing.safe_grow_cleared (last_basic_block_for_fn (cfun)); + { + m_outgoing.safe_grow_cleared (last_basic_block_for_fn (cfun)); + m_incoming.safe_grow_cleared (last_basic_block_for_fn (cfun)); + } gcc_checking_assert (m_outgoing[bb->index] == NULL); m_outgoing[bb->index] = BITMAP_ALLOC (&m_bitmaps); + m_incoming[bb->index] = BITMAP_ALLOC (&m_bitmaps); // If this block's last statement may generate range informaiton, go // calculate it. @@ -368,65 +508,42 @@ gori_map::calculate_gori (basic_block bb) // Dump the table information for BB to file F. void -gori_map::dump (FILE *f, basic_block bb) +gori_map::dump (FILE *f, basic_block bb, bool verbose) { - bool header = false; - const char *header_string = "bb%-4d "; - const char *header2 = " "; - bool printed_something = false;; - unsigned x, y; - bitmap_iterator bi; - // BB was not processed. - if (!m_outgoing[bb->index]) + if (!m_outgoing[bb->index] || bitmap_empty_p (m_outgoing[bb->index])) return; - // Dump the def chain for each SSA_NAME defined in BB. - for (x = 1; x < num_ssa_names; x++) + tree name; + + bitmap imp = imports (bb); + if (!bitmap_empty_p (imp)) { - tree name = ssa_name (x); - if (!name) - continue; - gimple *stmt = SSA_NAME_DEF_STMT (name); - bitmap chain = (has_def_chain (name) ? get_def_chain (name) : NULL); - if (stmt && gimple_bb (stmt) == bb && chain && !bitmap_empty_p (chain)) - { - fprintf (f, header_string, bb->index); - header_string = header2; - header = true; + if (verbose) + fprintf (f, "bb<%u> Imports: ",bb->index); + else + fprintf (f, "Imports: "); + FOR_EACH_GORI_IMPORT_NAME (*this, bb, name) + { print_generic_expr (f, name, TDF_SLIM); - fprintf (f, " : "); - EXECUTE_IF_SET_IN_BITMAP (chain, 0, y, bi) - { - print_generic_expr (f, ssa_name (y), TDF_SLIM); - fprintf (f, " "); - } - fprintf (f, "\n"); + fprintf (f, " "); } + fputc ('\n', f); } - printed_something |= header; - - // Now dump the export vector. - header = false; - EXECUTE_IF_SET_IN_BITMAP (m_outgoing[bb->index], 0, y, bi) + if (verbose) + fprintf (f, "bb<%u> Exports: ",bb->index); + else + fprintf (f, "Exports: "); + // Dump the export vector. + FOR_EACH_GORI_EXPORT_NAME (*this, bb, name) { - if (!header) - { - fprintf (f, header_string, bb->index); - fprintf (f, "exports: "); - header_string = header2; - header = true; - } - print_generic_expr (f, ssa_name (y), TDF_SLIM); + print_generic_expr (f, name, TDF_SLIM); fprintf (f, " "); } - if (header) - fputc ('\n', f); + fputc ('\n', f); - printed_something |= header; - if (printed_something) - fprintf (f, "\n"); + range_def_chain::dump (f, bb, " "); } // Dump the entire GORI map structure to file F. @@ -436,11 +553,7 @@ gori_map::dump (FILE *f) { basic_block bb; FOR_EACH_BB_FN (bb, cfun) - { - dump (f, bb); - if (m_outgoing[bb->index]) - fprintf (f, "\n"); - } + dump (f, bb); } DEBUG_FUNCTION void @@ -960,8 +1073,7 @@ gori_compute::has_edge_range_p (tree name, edge e) if (!e) return is_export_p (name); - return (is_export_p (name, e->src) - || def_chain_in_export_p (name, e->src)); + return is_export_p (name, e->src); } // Dump what is known to GORI computes to listing file F. @@ -1006,6 +1118,50 @@ gori_compute::outgoing_edge_range_p (irange &r, edge e, tree name) return false; } + +// ------------------------------------------------------------------------ +// GORI iterator. Although we have bitmap iterators, don't expose that it +// is currently a bitmap. Use an export iterator to hide future changes. + +// Construct a basic iterator over an export bitmap. + +gori_export_iterator::gori_export_iterator (bitmap b) +{ + bm = b; + if (b) + bmp_iter_set_init (&bi, b, 1, &y); +} + + +// Move to the next export bitmap spot. + +void +gori_export_iterator::next () +{ + bmp_iter_next (&bi, &y); +} + + +// Fetch the name of the next export in the export list. Return NULL if +// iteration is done. + +tree +gori_export_iterator::get_name () +{ + if (!bm) + return NULL_TREE; + + while (bmp_iter_set (&bi, &y)) + { + tree t = ssa_name (y); + if (t) + return t; + next (); + } + return NULL_TREE; +} + + // -------------------------------------------------------------------------- // Cache for SSAs that appear on the RHS of a boolean assignment. diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 6208931a0d8..8f44216cfcd 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -31,15 +31,55 @@ class range_def_chain public: range_def_chain (); ~range_def_chain (); + tree depend1 (tree name) const; + tree depend2 (tree name) const; + bool in_chain_p (tree name, tree def); + bool chain_import_p (tree name, tree import); + void register_dependency (tree name, tree ssa1, basic_block bb = NULL); + void dump (FILE *f, basic_block bb, const char *prefix = NULL); +protected: bool has_def_chain (tree name); + bool def_chain_in_bitmap_p (tree name, bitmap b); + void add_def_chain_to_bitmap (bitmap b, tree name); bitmap get_def_chain (tree name); - bool in_chain_p (tree name, tree def); + bitmap get_imports (tree name); + bitmap_obstack m_bitmaps; private: - vec m_def_chain; // SSA_NAME : def chain components. - void build_def_chain (tree name, bitmap result, basic_block bb); + struct rdc { + tree ssa1; // First direct dependency + tree ssa2; // Second direct dependency + bitmap bm; // All dependencies + bitmap m_import; + }; + vec m_def_chain; // SSA_NAME : def chain components. + void set_import (struct rdc &data, tree imp, bitmap b); int m_logical_depth; }; +// Return the first direct dependency for NAME, if there is one. +// Direct dependencies are those which occur on the defintion statement. +// Only the first 2 such names are cached. + +inline tree +range_def_chain::depend1 (tree name) const +{ + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_def_chain.length ()) + return NULL_TREE; + return m_def_chain[v].ssa1; +} + +// Return the second direct dependency for NAME, if there is one. + +inline tree +range_def_chain::depend2 (tree name) const +{ + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_def_chain.length ()) + return NULL_TREE; + return m_def_chain[v].ssa2; +} + // GORI_MAP is used to accumulate what SSA names in a block can // generate range information, and provides tools for the block ranger // to enable it to efficiently calculate these ranges. @@ -51,15 +91,16 @@ public: ~gori_map (); bool is_export_p (tree name, basic_block bb = NULL); - bool def_chain_in_export_p (tree name, basic_block bb); + bool is_import_p (tree name, basic_block bb); bitmap exports (basic_block bb); + bitmap imports (basic_block bb); void set_range_invariant (tree name); void dump (FILE *f); - void dump (FILE *f, basic_block bb); + void dump (FILE *f, basic_block bb, bool verbose = true); private: - bitmap_obstack m_bitmaps; vec m_outgoing; // BB: Outgoing ranges calculatable on edges + vec m_incoming; // BB: Incoming ranges which can affect exports. bitmap m_maybe_variant; // Names which might have outgoing ranges. void maybe_add_gori (tree name, basic_block bb); void calculate_gori (basic_block bb); @@ -152,6 +193,30 @@ private: }; +// For each name that is an import into BB's exports.. +#define FOR_EACH_GORI_IMPORT_NAME(gori, bb, name) \ + for (gori_export_iterator iter ((gori).imports ((bb))); \ + ((name) = iter.get_name ()); \ + iter.next ()) + +// For each name possibly exported from block BB. +#define FOR_EACH_GORI_EXPORT_NAME(gori, bb, name) \ + for (gori_export_iterator iter ((gori).exports ((bb))); \ + ((name) = iter.get_name ()); \ + iter.next ()) + +// Used to assist with iterating over the GORI export list in various ways +class gori_export_iterator { +public: + gori_export_iterator (bitmap b); + void next (); + tree get_name (); +protected: + bitmap bm; + bitmap_iterator bi; + unsigned y; +}; + // This class adds a cache to gori_computes for logical expressions. // bool result = x && y // requires calcuation of both X and Y for both true and false results. -- 2.17.2 From patchwork Tue May 25 23:30:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483796 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=jwH1JKC0; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVh23xRJz9sCD for ; Wed, 26 May 2021 09:30:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B49F6385743D; Tue, 25 May 2021 23:30:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B49F6385743D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985454; bh=YK4BLn3YwP0XMPYAchmdZ7ZCLHhTRFuuRTzif6jLAFg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jwH1JKC0wSsRgtLaXBYWmfT/to9Jkx6rrqaVaGZg8kVD4MGyUa0KpUOYlJrjPPwoj RF6vd9HE5j01RrXLMlErck02oMt6HaivXNxlakPzM3gBRHfVMMF5FHtgRefw7wOlqY ATzyaMAEaC4ANYZ2JDQdJ99X2yaXxGyMjhoYo3fk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 9E5333857419 for ; Tue, 25 May 2021 23:30:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9E5333857419 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-172-E4vCpn_SOOW1sTBVi5qU9w-1; Tue, 25 May 2021 19:30:47 -0400 X-MC-Unique: E4vCpn_SOOW1sTBVi5qU9w-1 Received: by mail-qv1-f71.google.com with SMTP id i14-20020a0cf10e0000b02901eeced6480dso30486205qvl.4 for ; Tue, 25 May 2021 16:30:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=YK4BLn3YwP0XMPYAchmdZ7ZCLHhTRFuuRTzif6jLAFg=; b=Qk0YRFsSUW/QjnZ51JqoLhgkmGgcJxBoO1lrTR0KXTe1lgkjXFGmuPR4zjWFrX5Qzt 9hpFNsAfDEToiJsjVkXXfwl2Hc2IWBbFXdslpbd65WQzYITwP4jfDt+8VmkHOSyTYmO4 94C06SRb5dyPYWK/POUtu9F4Sx/3IWrhVW/vWme76Ou574Ffa3MgOKfgyzvMHUDn37Bp Kjgbf7Q4Loqd49qJmY7SLOp39ldjVJ9P+lhGL5ftNxP3Xr9d85eRqKjN5DpYHAYaXOtW BsIFgKetMOcAc/iagfi2xnYEnmlfO3t2pDESHgzmXE3+UnLkDywZwRt34XINueU2ZGAo Wv9Q== X-Gm-Message-State: AOAM533/eIGdPN4piApTcSMhO7neZa4awT+TFjE6oXhHf4O5xw011tZO NudCS9jcfLUlHA5977hmGzk/4jVCEZB1LQpZBfusZk4sBHuBIFs4bB1o5vHY0t0oU7Vi3bhtoPx 5AYpRq7BOMjG2gw2FVQ== X-Received: by 2002:a05:6214:c2d:: with SMTP id a13mr40192493qvd.37.1621985446206; Tue, 25 May 2021 16:30:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyulcq/wxWqpSrTyHsBccM9mD6FzgjZizUyvt+meREL1XMnct+IfL4OfprmtQ3rpCuWaEVw6w== X-Received: by 2002:a05:6214:c2d:: with SMTP id a13mr40192484qvd.37.1621985446078; Tue, 25 May 2021 16:30:46 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id p17sm488369qkg.67.2021.05.25.16.30.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:30:45 -0700 (PDT) To: gcc-patches Subject: [PATCH 4/8] Unify temporal cache with gori dependencies. Message-ID: Date: Tue, 25 May 2021 19:30:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" The patch removes the custom temporal cache from GCC11 and replaces it with a simple timestamp vector and utilizes the direct dependants from gori_compute. This allows the registration of said dependencies to be handled generically by the simplified fold_stmt class thru the gori_compute class.  So All the dependency analysis is handled centrally in one place now. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 10b286ce335cca135a45a92581b28146f3e3209b Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:34:06 -0400 Subject: [PATCH 4/8] Unify temporal cache with gori dependencies. Move the temporal cache to strictly be a timestamp, and query GORI for the dependencies rather than trying to register and maintain them. * gimple-range-cache.cc (struct range_timestamp): Delete. (class temporal_cache): Adjust. (temporal_cache::get_timestamp): Delete. (temporal_cache::set_dependency): Delete. (temporal_cache::temporal_value): Adjust. (temporal_cache::current_p): Take dependencies as params. (temporal_cache::set_timestamp): Adjust. (temporal_cache::set_always_current): Adjust. (ranger_cache::get_non_stale_global_range): Adjust. (ranger_cache::register_dependency): Delete. * gimple-range-cache.h (class range_cache): Adjust. --- gcc/gimple-range-cache.cc | 116 +++++++++++--------------------------- gcc/gimple-range-cache.h | 1 - 2 files changed, 32 insertions(+), 85 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 8ad76048272..3969c4de220 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -474,43 +474,28 @@ ssa_global_cache::dump (FILE *f) // -------------------------------------------------------------------------- -// This struct provides a timestamp for a global range calculation. -// it contains the time counter, as well as a limited number of ssa-names -// that it is dependent upon. If the timestamp for any of the dependent names -// Are newer, then this range could need updating. - -struct range_timestamp -{ - unsigned time; - unsigned ssa1; - unsigned ssa2; -}; - // This class will manage the timestamps for each ssa_name. -// When a value is calcualted, its timestamp is set to the current time. -// The ssanames it is dependent on have already been calculated, so they will -// have older times. If one fo those values is ever calculated again, it -// will get a newer timestamp, and the "current_p" check will fail. +// When a value is calculated, the timestamp is set to the current time. +// Current time is then incremented. Any dependencies will already have +// been calculated, and will thus have older timestamps. +// If one of those values is ever calculated again, it will get a newer +// timestamp, and the "current_p" check will fail. class temporal_cache { public: temporal_cache (); ~temporal_cache (); - bool current_p (tree name) const; + bool current_p (tree name, tree dep1, tree dep2) const; void set_timestamp (tree name); - void set_dependency (tree name, tree dep); void set_always_current (tree name); private: unsigned temporal_value (unsigned ssa) const; - const range_timestamp *get_timestamp (unsigned ssa) const; - range_timestamp *get_timestamp (unsigned ssa); unsigned m_current_time; - vec m_timestamp; + vec m_timestamp; }; - inline temporal_cache::temporal_cache () { @@ -525,65 +510,35 @@ temporal_cache::~temporal_cache () m_timestamp.release (); } -// Return a pointer to the timetamp for ssa-name at index SSA, if there is -// one, otherwise return NULL. - -inline const range_timestamp * -temporal_cache::get_timestamp (unsigned ssa) const -{ - if (ssa >= m_timestamp.length ()) - return NULL; - return &(m_timestamp[ssa]); -} - -// Return a reference to the timetamp for ssa-name at index SSA. If the index -// is past the end of the vector, extend the vector. - -inline range_timestamp * -temporal_cache::get_timestamp (unsigned ssa) -{ - if (ssa >= m_timestamp.length ()) - m_timestamp.safe_grow_cleared (num_ssa_names + 20); - return &(m_timestamp[ssa]); -} - -// This routine will fill NAME's next operand slot with DEP if DEP is a valid -// SSA_NAME and there is a free slot. - -inline void -temporal_cache::set_dependency (tree name, tree dep) -{ - if (dep && TREE_CODE (dep) == SSA_NAME) - { - gcc_checking_assert (get_timestamp (SSA_NAME_VERSION (name))); - range_timestamp& ts = *(get_timestamp (SSA_NAME_VERSION (name))); - if (!ts.ssa1) - ts.ssa1 = SSA_NAME_VERSION (dep); - else if (!ts.ssa2 && ts.ssa1 != SSA_NAME_VERSION (name)) - ts.ssa2 = SSA_NAME_VERSION (dep); - } -} - // Return the timestamp value for SSA, or 0 if there isnt one. + inline unsigned temporal_cache::temporal_value (unsigned ssa) const { - const range_timestamp *ts = get_timestamp (ssa); - return ts ? ts->time : 0; + if (ssa >= m_timestamp.length ()) + return 0; + return m_timestamp[ssa]; } // Return TRUE if the timestampe for NAME is newer than any of its dependents. +// Up to 2 dependencies can be checked. bool -temporal_cache::current_p (tree name) const +temporal_cache::current_p (tree name, tree dep1, tree dep2) const { - const range_timestamp *ts = get_timestamp (SSA_NAME_VERSION (name)); - if (!ts || ts->time == 0) + unsigned ts = temporal_value (SSA_NAME_VERSION (name)); + if (ts == 0) return true; + // Any non-registered dependencies will have a value of 0 and thus be older. // Return true if time is newer than either dependent. - return ts->time > temporal_value (ts->ssa1) - && ts->time > temporal_value (ts->ssa2); + + if (dep1 && ts < temporal_value (SSA_NAME_VERSION (dep1))) + return false; + if (dep2 && ts < temporal_value (SSA_NAME_VERSION (dep2))) + return false; + + return true; } // This increments the global timer and sets the timestamp for NAME. @@ -591,8 +546,10 @@ temporal_cache::current_p (tree name) const inline void temporal_cache::set_timestamp (tree name) { - gcc_checking_assert (get_timestamp (SSA_NAME_VERSION (name))); - get_timestamp (SSA_NAME_VERSION (name))->time = ++m_current_time; + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_timestamp.length ()) + m_timestamp.safe_grow_cleared (num_ssa_names + 20); + m_timestamp[v] = ++m_current_time; } // Set the timestamp to 0, marking it as "always up to date". @@ -600,11 +557,12 @@ temporal_cache::set_timestamp (tree name) inline void temporal_cache::set_always_current (tree name) { - gcc_checking_assert (get_timestamp (SSA_NAME_VERSION (name))); - get_timestamp (SSA_NAME_VERSION (name))->time = 0; + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_timestamp.length ()) + m_timestamp.safe_grow_cleared (num_ssa_names + 20); + m_timestamp[v] = 0; } - // -------------------------------------------------------------------------- ranger_cache::ranger_cache (gimple_ranger &q) : query (q) @@ -682,7 +640,7 @@ ranger_cache::get_non_stale_global_range (irange &r, tree name) { if (m_globals.get_global_range (r, name)) { - if (m_temporal->current_p (name)) + if (m_temporal->current_p (name, depend1 (name), depend2 (name))) return true; } else @@ -728,16 +686,6 @@ ranger_cache::set_global_range (tree name, const irange &r) m_temporal->set_timestamp (name); } -// Register a dependency on DEP to name. If the timestamp for DEP is ever -// greateer than the timestamp for NAME, then it is newer and NAMEs value -// becomes stale. - -void -ranger_cache::register_dependency (tree name, tree dep) -{ - m_temporal->set_dependency (name, dep); -} - // Push a request for a new lookup in block BB of name. Return true if // the request is actually made (ie, isn't a duplicate). diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index 15e6d0c61c4..fe781e0ad1b 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -98,7 +98,6 @@ public: bool get_global_range (irange &r, tree name) const; bool get_non_stale_global_range (irange &r, tree name); void set_global_range (tree name, const irange &r); - void register_dependency (tree name, tree dep); non_null_ref m_non_null; -- 2.17.2 From patchwork Tue May 25 23:30:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483797 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Brxpgn5C; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVhF4wSzz9sCD for ; Wed, 26 May 2021 09:31:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 567613857413; Tue, 25 May 2021 23:31:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 567613857413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985466; bh=RK4ahGWIEBlunnJ2fY60/0nEFsnlVl2yTceDdiu/Mts=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Brxpgn5CpdmQf55i5cOluzSHam3cjT/Vpqhc+svxW2O2YlC0K+3tzMIAym2yDnFGr fv2vkPim1cowI1kf0BsDhaODcsF9szDM91a+gJufxL9SNO6z/EczJsyxDu1NsLsBHu FT0JirkBfikcmS0BSzTnBSwkZM5ktV1ThwkTrvu4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 58EF5385803D for ; Tue, 25 May 2021 23:31:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 58EF5385803D Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-554-bIRBhL7yO_-9yWczeD_DNg-1; Tue, 25 May 2021 19:31:02 -0400 X-MC-Unique: bIRBhL7yO_-9yWczeD_DNg-1 Received: by mail-qv1-f72.google.com with SMTP id l19-20020a0ce5130000b02901b6795e3304so31988294qvm.2 for ; Tue, 25 May 2021 16:31:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=RK4ahGWIEBlunnJ2fY60/0nEFsnlVl2yTceDdiu/Mts=; b=iAmAD+3Fy5lf6qRa4laj73V0b4O+8flVKW9hGp45m/3tkQ42TH/Xfzyc7yqIEdQc8i LQREJ+85Ibll+oNkZgoZeKLLnGELhNJsmlN46v9RYN8mRBBztagm2EhagZtnLY0WpcNW rex7OQFtliuMBGkLl21hAKdSrnGyOcnj5wgTQMCImoxmuAq2n3ZDuTD3zexpdNFc5kQF vWFtNUkC16NRGC7dOwI1XQYHHTGLAbokw6kGgGvQgv36kzTOsOaZIHVZ1uj1JZp1S2bk iFRzlKurYv0Xk3NDc0a7A/+uAeWGcWA+7fWcAwNygaVyCJuVtI0BB3/FYphUcTWxLD0U 2n9w== X-Gm-Message-State: AOAM532C59k2w9mdV/jh3lqls+6TRzyR+2VupuDZnPY46bcRlQ9zxW5L BYmYzkI7LBoerR40UE/bhJzKbhexnoO3rIPoH3HLd7j+Oi74T2Hz/df0KRfYUUiH+PXfj3ATU0A uiq3u+R+nNd5YtFycuA== X-Received: by 2002:a05:622a:446:: with SMTP id o6mr36001500qtx.246.1621985461474; Tue, 25 May 2021 16:31:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ6DflOZfmFxjqTjifrWmvENbN7HxB337XnrKo9c18UMmkvp8Rj5oq8Cod3grZ1trBnGhy7w== X-Received: by 2002:a05:622a:446:: with SMTP id o6mr36001494qtx.246.1621985461329; Tue, 25 May 2021 16:31:01 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id t6sm467498qkh.117.2021.05.25.16.31.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:31:00 -0700 (PDT) To: gcc-patches Subject: [PATCH 5/8] Tweak location of non-null calls. revamp ranger debug, output. Message-ID: <129c9d2a-db45-15d9-3188-ac470a785688@redhat.com> Date: Tue, 25 May 2021 19:30:59 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Just some minor tweaking of the location of calls to non_null_deref_p, as well as debug output. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 35c78c6fc54721e067ed3a30ddd9184b45c5981d Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:41:16 -0400 Subject: [PATCH 5/8] Tweak location of non-null calls. revamp ranger debug output. range_on_entry shouldnt be checking non-null, but we sometimes should after calling it. change the debug output a bit. * gimple-range.cc (gimple_ranger::range_of_expr): Non-null should be checked only after range_of_stmt, not range_on_entry. (gimple_ranger::range_on_entry): Check for non-null in any predecessor block, if it is not already non-null. (gimple_ranger::range_on_exit): DOnt check for non-null after range on entry call. (gimple_ranger::dump_bb): New. Split from dump. (gimple_ranger::dump): Adjust. * gimple-range.h (class gimple_ranger): Adjust. --- gcc/gimple-range.cc | 149 ++++++++++++++++++++++---------------------- gcc/gimple-range.h | 1 + 2 files changed, 74 insertions(+), 76 deletions(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 06e9804494b..593ddb1c3f8 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -976,23 +976,16 @@ gimple_ranger::range_of_expr (irange &r, tree expr, gimple *stmt) // If name is defined in this block, try to get an range from S. if (def_stmt && gimple_bb (def_stmt) == bb) - range_of_stmt (r, def_stmt, expr); + { + range_of_stmt (r, def_stmt, expr); + if (!cfun->can_throw_non_call_exceptions && r.varying_p () && + m_cache.m_non_null.non_null_deref_p (expr, bb)) + r = range_nonzero (TREE_TYPE (expr)); + } else // Otherwise OP comes from outside this block, use range on entry. range_on_entry (r, bb, expr); - // No range yet, see if there is a dereference in the block. - // We don't care if it's between the def and a use within a block - // because the entire block must be executed anyway. - // FIXME:?? For non-call exceptions we could have a statement throw - // which causes an early block exit. - // in which case we may need to walk from S back to the def/top of block - // to make sure the deref happens between S and there before claiming - // there is a deref. Punt for now. - if (!cfun->can_throw_non_call_exceptions && r.varying_p () && - m_cache.m_non_null.non_null_deref_p (expr, bb)) - r = range_nonzero (TREE_TYPE (expr)); - return true; } @@ -1010,6 +1003,10 @@ gimple_ranger::range_on_entry (irange &r, basic_block bb, tree name) // Now see if there is any on_entry value which may refine it. if (m_cache.block_range (entry_range, bb, name)) r.intersect (entry_range); + + if (!cfun->can_throw_non_call_exceptions && r.varying_p () && + m_cache.m_non_null.non_null_deref_p (name, bb)) + r = range_nonzero (TREE_TYPE (name)); } // Calculate the range for NAME at the end of block BB and return it in R. @@ -1032,13 +1029,7 @@ gimple_ranger::range_on_exit (irange &r, basic_block bb, tree name) if (s) range_of_expr (r, name, s); else - { - range_on_entry (r, bb, name); - // See if there was a deref in this block, if applicable - if (!cfun->can_throw_non_call_exceptions && r.varying_p () && - m_cache.m_non_null.non_null_deref_p (name, bb)) - r = range_nonzero (TREE_TYPE (name)); - } + range_on_entry (r, bb, name); gcc_checking_assert (r.undefined_p () || range_compatible_p (r.type (), TREE_TYPE (name))); } @@ -1166,80 +1157,86 @@ gimple_ranger::export_global_ranges () // Print the known table values to file F. void -gimple_ranger::dump (FILE *f) +gimple_ranger::dump_bb (FILE *f, basic_block bb) { - basic_block bb; - - FOR_EACH_BB_FN (bb, cfun) - { - unsigned x; - edge_iterator ei; - edge e; - int_range_max range; - fprintf (f, "\n=========== BB %d ============\n", bb->index); - m_cache.dump (f, bb); + unsigned x; + edge_iterator ei; + edge e; + int_range_max range; + fprintf (f, "\n=========== BB %d ============\n", bb->index); + m_cache.dump (f, bb); - dump_bb (f, bb, 4, TDF_NONE); + ::dump_bb (f, bb, 4, TDF_NONE); - // Now find any globals defined in this block. - for (x = 1; x < num_ssa_names; x++) + // Now find any globals defined in this block. + for (x = 1; x < num_ssa_names; x++) + { + tree name = ssa_name (x); + if (gimple_range_ssa_p (name) && SSA_NAME_DEF_STMT (name) && + gimple_bb (SSA_NAME_DEF_STMT (name)) == bb && + m_cache.get_global_range (range, name)) { - tree name = ssa_name (x); - if (gimple_range_ssa_p (name) && SSA_NAME_DEF_STMT (name) && - gimple_bb (SSA_NAME_DEF_STMT (name)) == bb && - m_cache.get_global_range (range, name)) + if (!range.varying_p ()) { - if (!range.varying_p ()) - { - print_generic_expr (f, name, TDF_SLIM); - fprintf (f, " : "); - range.dump (f); - fprintf (f, "\n"); - } - + print_generic_expr (f, name, TDF_SLIM); + fprintf (f, " : "); + range.dump (f); + fprintf (f, "\n"); } + } + } - // And now outgoing edges, if they define anything. - FOR_EACH_EDGE (e, ei, bb->succs) + // And now outgoing edges, if they define anything. + FOR_EACH_EDGE (e, ei, bb->succs) + { + for (x = 1; x < num_ssa_names; x++) { - for (x = 1; x < num_ssa_names; x++) + tree name = gimple_range_ssa_p (ssa_name (x)); + if (name && m_cache.outgoing_edge_range_p (range, e, name)) { - tree name = gimple_range_ssa_p (ssa_name (x)); - if (name && m_cache.outgoing_edge_range_p (range, e, name)) + gimple *s = SSA_NAME_DEF_STMT (name); + // Only print the range if this is the def block, or + // the on entry cache for either end of the edge is + // set. + if ((s && bb == gimple_bb (s)) || + m_cache.block_range (range, bb, name, false) || + m_cache.block_range (range, e->dest, name, false)) { - gimple *s = SSA_NAME_DEF_STMT (name); - // Only print the range if this is the def block, or - // the on entry cache for either end of the edge is - // set. - if ((s && bb == gimple_bb (s)) || - m_cache.block_range (range, bb, name, false) || - m_cache.block_range (range, e->dest, name, false)) + range_on_edge (range, e, name); + if (!range.varying_p ()) { - range_on_edge (range, e, name); - if (!range.varying_p ()) - { - fprintf (f, "%d->%d ", e->src->index, - e->dest->index); - char c = ' '; - if (e->flags & EDGE_TRUE_VALUE) - fprintf (f, " (T)%c", c); - else if (e->flags & EDGE_FALSE_VALUE) - fprintf (f, " (F)%c", c); - else - fprintf (f, " "); - print_generic_expr (f, name, TDF_SLIM); - fprintf(f, " : \t"); - range.dump(f); - fprintf (f, "\n"); - } + fprintf (f, "%d->%d ", e->src->index, + e->dest->index); + char c = ' '; + if (e->flags & EDGE_TRUE_VALUE) + fprintf (f, " (T)%c", c); + else if (e->flags & EDGE_FALSE_VALUE) + fprintf (f, " (F)%c", c); + else + fprintf (f, " "); + print_generic_expr (f, name, TDF_SLIM); + fprintf(f, " : \t"); + range.dump(f); + fprintf (f, "\n"); } } } } } +} + +// Print the known table values to file F. + +void +gimple_ranger::dump (FILE *f) +{ + basic_block bb; + + FOR_EACH_BB_FN (bb, cfun) + dump_bb (f, bb); - m_cache.dump (dump_file, (dump_flags & TDF_DETAILS) != 0); + m_cache.dump (f, false); } // If SCEV has any information about phi node NAME, return it as a range in R. diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 53205066ab4..08035a53238 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -66,6 +66,7 @@ public: virtual void range_on_exit (irange &r, basic_block bb, tree name); void export_global_ranges (); void dump (FILE *f); + void dump_bb (FILE *f, basic_block bb); protected: bool fold_range_internal (irange &r, gimple *s, tree name); ranger_cache m_cache; -- 2.17.2 From patchwork Tue May 25 23:31:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483798 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=AAKRGtCi; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVhX0HRGz9sW6 for ; Wed, 26 May 2021 09:31:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00F7D3857802; Tue, 25 May 2021 23:31:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00F7D3857802 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985482; bh=PXbav1Opc1C7OJvb51DQJS+eanuVhSgjvtPvhvWgmg8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AAKRGtCi25YXKZlV6+JvFP+tOVZmCnjgnK7S3KxC5bPmoHo9OyzGsG9dRiGkByTBv ullQizdlZ4UYg2xUHoDvwef6tC5vL5LYDbmFJVfuxFhvjNVFE2VtFGJcgDXwX7IJN8 nQr8MQbAINbCt7ZBSCOswekodNQ6vY8ZqdhUbGWg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 808F8385803D for ; Tue, 25 May 2021 23:31:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 808F8385803D Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-PUZTj5YmNrejQ5oOyEAjQA-1; Tue, 25 May 2021 19:31:17 -0400 X-MC-Unique: PUZTj5YmNrejQ5oOyEAjQA-1 Received: by mail-qv1-f72.google.com with SMTP id n12-20020a0cdc8c0000b02901efdf8d3bc7so29254344qvk.23 for ; Tue, 25 May 2021 16:31:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=PXbav1Opc1C7OJvb51DQJS+eanuVhSgjvtPvhvWgmg8=; b=Klb9fvlDc0oYkSeChV7DCVB2hI2//oM+xyi/WiA2Dz2iLDnqzmVUv+gYIZnXJprjRt j0gwK2L81QF+j/CMeOizeWEcMdaAjjy3VZ5bR2RmRctkXWyeEyIgxj7nlH1/okU9kfKI p8JOjD0kNZXB05cXBs9q7Tp2LFsN01jGyuopLxG7hYUoE285/KSGVX6epzmB0LrWKsj6 0LZ4sv5KUTx1PthxWtLxUShyJvDxP//iyyQgEiksrnKg/UPWowX/QeuK99seSENzwBVN fGIRU/HcNnZrwTG7Xqm8Y2ZYY8gS90hNAL+4Vxgmy/GM5tsTq4ZGARVwH7jrWhEGBDla Gy/Q== X-Gm-Message-State: AOAM530EOcxBgDFfULWGpi5nZc0K6jdXudL3pgWMskEOYoeGcjd4SyLP sMmMCpdCLPSfDVLWwRyg85DdS6eXshmR1RAwDxihjsNizk9B6BSHoKkXTblU4rBpt8iP2p44u4U DPn67LeGiN1mx7rqcWg== X-Received: by 2002:a37:b0a:: with SMTP id 10mr40609916qkl.67.1621985476650; Tue, 25 May 2021 16:31:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaGkCSH2GH2LgEM+j1baYfV9ePhkvfqa+pYpkdfr6a/nrMmPCthCKRO4il2fe44s3Z0Q1tkA== X-Received: by 2002:a37:b0a:: with SMTP id 10mr40609909qkl.67.1621985476459; Tue, 25 May 2021 16:31:16 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id 64sm415338qtc.95.2021.05.25.16.31.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:31:16 -0700 (PDT) To: gcc-patches Subject: [PATCH 6/8] Make expr_range_in_bb stmt based rather than block based. Message-ID: Date: Tue, 25 May 2021 19:31:15 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" First step in moving gori_compute to range_query is to standardize its queries to be stmt based rather than block based. gori_compute works from the bottom of the block back towards the top, so it always has a stmt available for a range_of_expr query, there is no need to use a non-standard entry range query. No functional changes. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 2bccd9154e127909a4cdff5c19904a6562fcd0ff Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:49:40 -0400 Subject: [PATCH 6/8] Make expr_range_in_bb stmt based rather than block based. prerequisite to moving to a range_query model, make it stmt based. * gimple-range-gori.cc (gori_compute::expr_range_at_stmt): Rename from expr_range_in_bb and adjust. (gori_compute::compute_name_range_op): Adjust. (gori_compute::optimize_logical_operands): Adjust. (gori_compute::compute_logical_operands_in_chain): Adjust. (gori_compute::compute_operand1_range): Adjust. (gori_compute::compute_operand2_range): Adjust. (ori_compute_cache::cache_stmt): Adjust. * gimple-range-gori.h (gori_compute): Rename prototype. --- gcc/gimple-range-gori.cc | 36 ++++++++++++++++++------------------ gcc/gimple-range-gori.h | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 94640adc041..1a4ae45c986 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -582,10 +582,10 @@ gori_compute::ssa_range_in_bb (irange &r, tree name, basic_block) } void -gori_compute::expr_range_in_bb (irange &r, tree expr, basic_block bb) +gori_compute::expr_range_at_stmt (irange &r, tree expr, gimple *s) { if (gimple_range_ssa_p (expr)) - ssa_range_in_bb (r, expr, bb); + ssa_range_in_bb (r, expr, gimple_bb (s)); else get_tree_range (r, expr); } @@ -606,7 +606,7 @@ gori_compute::compute_name_range_op (irange &r, gimple *stmt, // Operand 1 is the name being looked for, evaluate it. if (op1 == name) { - expr_range_in_bb (op1_range, op1, gimple_bb (stmt)); + expr_range_at_stmt (op1_range, op1, stmt); if (!op2) { // The second parameter to a unary operation is the range @@ -616,7 +616,7 @@ gori_compute::compute_name_range_op (irange &r, gimple *stmt, return gimple_range_calc_op1 (r, stmt, lhs, op1_range); } // If we need the second operand, get a value and evaluate. - expr_range_in_bb (op2_range, op2, gimple_bb (stmt)); + expr_range_at_stmt (op2_range, op2, stmt); if (gimple_range_calc_op1 (r, stmt, lhs, op2_range)) r.intersect (op1_range); else @@ -626,8 +626,8 @@ gori_compute::compute_name_range_op (irange &r, gimple *stmt, if (op2 == name) { - expr_range_in_bb (op1_range, op1, gimple_bb (stmt)); - expr_range_in_bb (r, op2, gimple_bb (stmt)); + expr_range_at_stmt (op1_range, op1, stmt); + expr_range_at_stmt (r, op2, stmt); if (gimple_range_calc_op2 (op2_range, stmt, lhs, op1_range)) r.intersect (op2_range); return true; @@ -877,7 +877,7 @@ gori_compute::optimize_logical_operands (tf_range &range, { if (!compute_operand_range (range.false_range, SSA_NAME_DEF_STMT (op), m_bool_zero, name)) - expr_range_in_bb (range.false_range, name, gimple_bb (stmt)); + expr_range_at_stmt (range.false_range, name, stmt); range.true_range = range.false_range; return true; } @@ -886,7 +886,7 @@ gori_compute::optimize_logical_operands (tf_range &range, { if (!compute_operand_range (range.true_range, SSA_NAME_DEF_STMT (op), m_bool_one, name)) - expr_range_in_bb (range.true_range, name, gimple_bb (stmt)); + expr_range_at_stmt (range.true_range, name, stmt); range.false_range = range.true_range; return true; } @@ -905,12 +905,12 @@ gori_compute::compute_logical_operands_in_chain (tf_range &range, tree op, bool op_in_chain) { gimple *src_stmt = gimple_range_ssa_p (op) ? SSA_NAME_DEF_STMT (op) : NULL; - basic_block bb = gimple_bb (stmt); - if (!op_in_chain || (src_stmt != NULL && bb != gimple_bb (src_stmt))) + if (!op_in_chain || (src_stmt != NULL + && gimple_bb (stmt) != gimple_bb (src_stmt))) { // If op is not in the def chain, or defined in this block, // use its known value on entry to the block. - expr_range_in_bb (range.true_range, name, gimple_bb (stmt)); + expr_range_at_stmt (range.true_range, name, stmt); range.false_range = range.true_range; return; } @@ -920,9 +920,9 @@ gori_compute::compute_logical_operands_in_chain (tf_range &range, // Calculate ranges for true and false on both sides, since the false // path is not always a simple inversion of the true side. if (!compute_operand_range (range.true_range, src_stmt, m_bool_one, name)) - expr_range_in_bb (range.true_range, name, bb); + expr_range_at_stmt (range.true_range, name, stmt); if (!compute_operand_range (range.false_range, src_stmt, m_bool_zero, name)) - expr_range_in_bb (range.false_range, name, bb); + expr_range_at_stmt (range.false_range, name, stmt); } // Given a logical STMT, calculate true and false for each potential @@ -968,12 +968,12 @@ gori_compute::compute_operand1_range (irange &r, gimple *stmt, tree op1 = gimple_range_operand1 (stmt); tree op2 = gimple_range_operand2 (stmt); - expr_range_in_bb (op1_range, op1, gimple_bb (stmt)); + expr_range_at_stmt (op1_range, op1, stmt); // Now calcuated the operand and put that result in r. if (op2) { - expr_range_in_bb (op2_range, op2, gimple_bb (stmt)); + expr_range_at_stmt (op2_range, op2, stmt); if (!gimple_range_calc_op1 (r, stmt, lhs, op2_range)) return false; } @@ -1015,8 +1015,8 @@ gori_compute::compute_operand2_range (irange &r, gimple *stmt, tree op1 = gimple_range_operand1 (stmt); tree op2 = gimple_range_operand2 (stmt); - expr_range_in_bb (op1_range, op1, gimple_bb (stmt)); - expr_range_in_bb (op2_range, op2, gimple_bb (stmt)); + expr_range_at_stmt (op1_range, op1, stmt); + expr_range_at_stmt (op2_range, op2, stmt); // Intersect with range for op2 based on lhs and op1. if (!gimple_range_calc_op2 (r, stmt, lhs, op1_range)) @@ -1449,7 +1449,7 @@ gori_compute_cache::cache_stmt (gimple *stmt) { range_operator *handler = range_op_handler (code, TREE_TYPE (lhs)); int_range_max op2_range; - expr_range_in_bb (op2_range, op2, gimple_bb (stmt)); + expr_range_at_stmt (op2_range, op2, stmt); tree type = TREE_TYPE (op1); handler->op1_range (r_true_side, type, m_bool_one, op2_range); handler->op1_range (r_false_side, type, m_bool_zero, op2_range); diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 8f44216cfcd..8a85d6a2b79 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -161,7 +161,7 @@ protected: virtual bool compute_operand_range (irange &r, gimple *stmt, const irange &lhs, tree name); - void expr_range_in_bb (irange &r, tree expr, basic_block bb); + void expr_range_at_stmt (irange &r, tree expr, gimple *s); bool compute_logical_operands (irange &r, gimple *stmt, const irange &lhs, tree name); -- 2.17.2 From patchwork Tue May 25 23:31:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=BxwOluql; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVhq1vRzz9sCD for ; Wed, 26 May 2021 09:31:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C6A2393C874; Tue, 25 May 2021 23:31:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C6A2393C874 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985497; bh=YEsTIUFBLmYNa3RHb80C+ojuwsIjNQf6JJsVO8I8U9k=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BxwOluqlK/3XAq5ts6JosENi4wjUGCahpsyPDT+0Su2fcHP+SSaLmqPnBJDoKV90L 0ES1wRPLNtOuhUMHgaTvyUIDehf9zS0qC5iriDXWLLqXT63nZMx6s34vldBZocYlNj YicF1XVfEda61FcKeGUpuC4zcEV3FYOrdrueRMaY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 20006393BC3C for ; Tue, 25 May 2021 23:31:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 20006393BC3C Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-285-kvl54Sw-MgmdzWou46GWHw-1; Tue, 25 May 2021 19:31:31 -0400 X-MC-Unique: kvl54Sw-MgmdzWou46GWHw-1 Received: by mail-qk1-f198.google.com with SMTP id d201-20020ae9efd20000b02902e9e9d8d9dcso31139059qkg.10 for ; Tue, 25 May 2021 16:31:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=YEsTIUFBLmYNa3RHb80C+ojuwsIjNQf6JJsVO8I8U9k=; b=QaPiuK4xRK9cBl1/kua/M1Sfu8+R3d54MKxZnoaVQm2aW9ZE07AHWQUzjQNYSmFR3b WXqPh2CtAX/G7Hvm3jnBRQofDday/C32v/n7ZdpsDFT+Nez9vu4EyO9YNxuCZZeZMegB /SlQcWtmLBnKnd9uApS1FLXLTd/moj1ANxB9Fkizq2Pjco15YqezA1K4xAYBhpCUu+bk CxFntmU07PpYJ4/FDx8tyoYEtKoyq4w7l4YSGVgXHW8DjtKv/REe+Hd17tAY1w6EIvur Q1CVxbtXSWHtSKo9fvw+lnp0hZ6WkQi40WzIAQr1x9MmO5bkaR1T2MGctalnm2AqndvV JbJw== X-Gm-Message-State: AOAM530iGUG5J9CTTScykD5uwUF34PdhWTPbR7w03LnDkO9J2bQqiTxj VmgkY/98FkKjsqBiMqtaspUy4z8RRVWByg81b76TYtgYM7+yrhM9BKNep1RQFL6YNo8X6UroLbC o3OgWkMT8v06B0w2sWA== X-Received: by 2002:a05:620a:118a:: with SMTP id b10mr37576748qkk.263.1621985490955; Tue, 25 May 2021 16:31:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnzjLxkncNGVYIThcCa7roT0lLOVaPAjUuRVFMa3DMrANxVbio9eQzMP+8fgiN/mweDp8ndA== X-Received: by 2002:a05:620a:118a:: with SMTP id b10mr37576740qkk.263.1621985490813; Tue, 25 May 2021 16:31:30 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id e20sm405430qto.93.2021.05.25.16.31.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:31:30 -0700 (PDT) To: gcc-patches Subject: [PATCH 7/8] Adjust fur_source internal api to use gori_compute not, ranger_cache. Message-ID: <96532e40-6aa1-4816-f4a6-661de2e31403@redhat.com> Date: Tue, 25 May 2021 19:31:29 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I introduced fur_source  a week ago or so to act as the source for operands of fold_stmt.. ie, it encapsulated a range_query source to get operands for the arguments of a stmt when fold_stmt was invoked. One of the API points was an internal ranger version which contains a reference to a ranger_cache for various dependency set-upo/query reasons.   That has been relocated to gori_compute now, so change that class to use a gori_compute class reference instead of a ranger_cache object. Again, no functional change.  Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From f630797a1ed2f82faf965a47b43b5f995bc6623a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:55:04 -0400 Subject: [PATCH 7/8] Adjust fur_source internal api to use gori_compute not ranger_cache. In order to access the dependencies, the FoldUsingRange source API class stored a range_cache.. THis is now contained in the base gori_compute class, so use that now. * gimple-range.cc (fold_using_range::range_of_range_op): Use m_gori intead of m_cache. (fold_using_range::range_of_address): Adjust. (fold_using_range::range_of_phi): Adjust. * gimple-range.h (class fur_source): Adjust. (fur_source::fur_source): Adjust. --- gcc/gimple-range.cc | 18 +++++++++--------- gcc/gimple-range.h | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 593ddb1c3f8..e2d24d6e451 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -435,17 +435,17 @@ fold_using_range::range_of_range_op (irange &r, gimple *s, fur_source &src) // Fold range, and register any dependency if available. int_range<2> r2 (type); handler->fold_range (r, type, range1, r2); - if (lhs && src.m_cache) - src.m_cache->register_dependency (lhs, op1); + if (lhs && src.m_gori) + src.m_gori->register_dependency (lhs, op1); } else if (src.get_operand (range2, op2)) { // Fold range, and register any dependency if available. handler->fold_range (r, type, range1, range2); - if (lhs && src.m_cache) + if (lhs && src.m_gori) { - src.m_cache->register_dependency (lhs, op1); - src.m_cache->register_dependency (lhs, op2); + src.m_gori->register_dependency (lhs, op1); + src.m_gori->register_dependency (lhs, op2); } } else @@ -485,8 +485,8 @@ fold_using_range::range_of_address (irange &r, gimple *stmt, fur_source &src) { tree ssa = TREE_OPERAND (base, 0); tree lhs = gimple_get_lhs (stmt); - if (src.m_cache && lhs && gimple_range_ssa_p (ssa)) - src.m_cache->register_dependency (lhs, ssa); + if (src.m_gori && lhs && gimple_range_ssa_p (ssa)) + src.m_gori->register_dependency (lhs, ssa); gcc_checking_assert (irange::supports_type_p (TREE_TYPE (ssa))); src.get_operand (r, ssa); range_cast (r, TREE_TYPE (gimple_assign_rhs1 (stmt))); @@ -563,8 +563,8 @@ fold_using_range::range_of_phi (irange &r, gphi *phi, fur_source &src) edge e = gimple_phi_arg_edge (phi, x); // Register potential dependencies for stale value tracking. - if (src.m_cache && gimple_range_ssa_p (arg)) - src.m_cache->register_dependency (phi_def, arg); + if (src.m_gori && gimple_range_ssa_p (arg)) + src.m_gori->register_dependency (phi_def, arg); // Get the range of the argument on its edge. fur_source e_src (src.m_query, e); diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 08035a53238..707dcfe027b 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -84,10 +84,10 @@ class fur_source public: inline fur_source (range_query *q, edge e); inline fur_source (range_query *q, gimple *s); - inline fur_source (range_query *q, class ranger_cache *g, edge e, gimple *s); + inline fur_source (range_query *q, gori_compute *g, edge e, gimple *s); bool get_operand (irange &r, tree expr); protected: - ranger_cache *m_cache; + gori_compute *m_gori; range_query *m_query; edge m_edge; gimple *m_stmt; @@ -124,7 +124,7 @@ inline fur_source::fur_source (range_query *q, edge e) { m_query = q; - m_cache = NULL; + m_gori = NULL; m_edge = e; m_stmt = NULL; } @@ -135,7 +135,7 @@ inline fur_source::fur_source (range_query *q, gimple *s) { m_query = q; - m_cache = NULL; + m_gori = NULL; m_edge = NULL; m_stmt = s; } @@ -144,10 +144,10 @@ fur_source::fur_source (range_query *q, gimple *s) // and can also set the dependency information as appropriate when invoked. inline -fur_source::fur_source (range_query *q, ranger_cache *g, edge e, gimple *s) +fur_source::fur_source (range_query *q, gori_compute *g, edge e, gimple *s) { m_query = q; - m_cache = g; + m_gori = g; m_edge = e; m_stmt = s; } -- 2.17.2 From patchwork Tue May 25 23:31:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1483800 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=f5hfRzvV; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FqVj36Nhxz9sCD for ; Wed, 26 May 2021 09:31:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D68A4393A430; Tue, 25 May 2021 23:31:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D68A4393A430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621985509; bh=9DBMqujEvJ0DafMHgPTIgriRu7O6TdGsIy+bkj86d5I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=f5hfRzvVqTk6NMcNOSOvL8vA242Img6gwwf/aglrfNqf7TfmPbmiNrSSi9TKqHQ8f FOXihib1Tq7+aeiWwzwEH9bIOjxWNZh75ixr9aGmgPPYZL9imts2JTnvoR2SkfH6Au TG2PTDl3nUiGCe8wCIR6gOUD9vm02l1uYTCv0AtE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 9ED1F385803D for ; Tue, 25 May 2021 23:31:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9ED1F385803D Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-0FDM7A4jO3ybxneDhe2pWg-1; Tue, 25 May 2021 19:31:44 -0400 X-MC-Unique: 0FDM7A4jO3ybxneDhe2pWg-1 Received: by mail-qk1-f200.google.com with SMTP id b203-20020a3767d40000b02903a6207bfef5so15378721qkc.1 for ; Tue, 25 May 2021 16:31:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=9DBMqujEvJ0DafMHgPTIgriRu7O6TdGsIy+bkj86d5I=; b=Q8OaRCVH8fNpSbz8DyfIF3gudrt5HiwWH4CNE05P0wxDTxjLxKypiZHgEZ4DAaDF4A sDnEE4bMovyOyAVSfOeeE9UtrhAKDgg8luWMVTDnVi5WVXniDl+S5A5LtETITnaq+uLp 7zj3IvdQmLWdvm13CY/x3pEtUjP7/EnSdUFxhYlw0STBBo5qYkGqHfS2uXkf3OcprCM3 EN7frL8zPrSj8bMMDeYpMYvXbEVhAUGE2uQ32/hjfrqUfdsZonYWn7ysulQKtgXhM+yN RLnp53IojXSzibwMWnvctbVjANNnAnBv+HgYjwNjrAQBU2I+GL474B1Vmwdqlr486Kt5 HTXQ== X-Gm-Message-State: AOAM5339Wq8Me+vTooDH5QaEQ9SpOxADuhBOTo3nsMJUt0joFuC3h5Qq RL4nXSHg4xTf0ycDfauZsEatCKymRsMdk0eMDopmLqRq54Knt2S1AflfHQivroDm5kRO6C/s3VS uXfb5qHoCG+5ZR8S+wQ== X-Received: by 2002:a05:622a:1489:: with SMTP id t9mr6770653qtx.191.1621985503763; Tue, 25 May 2021 16:31:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt5sid+5UGV+39Fw5CMVp7EXvLi+/OnuwGkp0FMdDj7owKA0dkOnoynAW7wOpgLWnQIeFEmA== X-Received: by 2002:a05:622a:1489:: with SMTP id t9mr6770646qtx.191.1621985503624; Tue, 25 May 2021 16:31:43 -0700 (PDT) Received: from ?IPv6:2607:fea8:a25d:e700::2b5? ([2607:fea8:a25d:e700::2b5]) by smtp.gmail.com with ESMTPSA id t21sm86376qkg.22.2021.05.25.16.31.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 May 2021 16:31:43 -0700 (PDT) To: gcc-patches Subject: [PATCH 8/8] Remove the logical stmt cache for now. Message-ID: <94f38552-f3ab-4694-714c-71a152de7098@redhat.com> Date: Tue, 25 May 2021 19:31:42 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" We added the logical stmt depth limit back in January I think, and the logical stmt cache is not currently in use.   This patch removes that code so it doesn't have too be maintained thru these changes. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From a6e94287d31525b3ad0963ad22a92e9f3dbcd3cf Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 25 May 2021 14:59:54 -0400 Subject: [PATCH 8/8] Remove the logical stmt cache for now. With the depth limiting, we are not currently using the logical stmt cache. * gimple-range-gori.cc (class logical_stmt_cache): Delete (logical_stmt_cache::logical_stmt_cache ): Delete. (logical_stmt_cache::~logical_stmt_cache): Delete. (logical_stmt_cache::cache_entry::dump): Delete. (logical_stmt_cache::get_range): Delete. (logical_stmt_cache::cached_name ): Delete. (logical_stmt_cache::same_cached_name): Delete. (logical_stmt_cache::cacheable_p): Delete. (logical_stmt_cache::slot_diagnostics ): Delete. (logical_stmt_cache::dump): Delete. (gori_compute_cache::gori_compute_cache): Delete. (gori_compute_cache::~gori_compute_cache): Delete. (gori_compute_cache::compute_operand_range): Delete. (gori_compute_cache::cache_stmt): Delete. * gimple-range-gori.h (gori_compute::compute_operand_range): Remove virtual. (class gori_compute_cache): Delete. --- gcc/gimple-range-gori.cc | 311 --------------------------------------- gcc/gimple-range-gori.h | 31 +--- 2 files changed, 2 insertions(+), 340 deletions(-) diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 1a4ae45c986..a4c4bf507ba 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -1160,314 +1160,3 @@ gori_export_iterator::get_name () } return NULL_TREE; } - - -// -------------------------------------------------------------------------- - -// Cache for SSAs that appear on the RHS of a boolean assignment. -// -// Boolean assignments of logical expressions (i.e. LHS = j_5 > 999) -// have SSA operands whose range depend on the LHS of the assigment. -// That is, the range of j_5 when LHS is true is different than when -// LHS is false. -// -// This class caches the TRUE/FALSE ranges of such SSAs to avoid -// recomputing. - -class logical_stmt_cache -{ -public: - logical_stmt_cache (); - ~logical_stmt_cache (); - void set_range (tree lhs, tree name, const tf_range &); - bool get_range (tf_range &r, tree lhs, tree name) const; - bool cacheable_p (gimple *, const irange *lhs_range = NULL) const; - void dump (FILE *, gimple *stmt) const; - tree same_cached_name (tree lhs1, tree lh2) const; -private: - tree cached_name (tree lhs) const; - void slot_diagnostics (tree lhs, const tf_range &range) const; - struct cache_entry - { - cache_entry (tree name, const irange &t_range, const irange &f_range); - void dump (FILE *out) const; - tree name; - tf_range range; - }; - vec m_ssa_cache; -}; - -logical_stmt_cache::cache_entry::cache_entry (tree name, - const irange &t_range, - const irange &f_range) - : name (name), range (t_range, f_range) -{ -} - -logical_stmt_cache::logical_stmt_cache () -{ - m_ssa_cache.create (num_ssa_names + num_ssa_names / 10); - m_ssa_cache.safe_grow_cleared (num_ssa_names); -} - -logical_stmt_cache::~logical_stmt_cache () -{ - for (unsigned i = 0; i < m_ssa_cache.length (); ++i) - if (m_ssa_cache[i]) - delete m_ssa_cache[i]; - m_ssa_cache.release (); -} - -// Dump cache_entry to OUT. - -void -logical_stmt_cache::cache_entry::dump (FILE *out) const -{ - fprintf (out, "name="); - print_generic_expr (out, name, TDF_SLIM); - fprintf (out, " "); - range.true_range.dump (out); - fprintf (out, ", "); - range.false_range.dump (out); - fprintf (out, "\n"); -} - -// Update range for cache entry of NAME as it appears in the defining -// statement of LHS. - -void -logical_stmt_cache::set_range (tree lhs, tree name, const tf_range &range) -{ - unsigned version = SSA_NAME_VERSION (lhs); - if (version >= m_ssa_cache.length ()) - m_ssa_cache.safe_grow_cleared (num_ssa_names + num_ssa_names / 10); - - cache_entry *slot = m_ssa_cache[version]; - slot_diagnostics (lhs, range); - if (slot) - { - // The IL must have changed. Update the carried SSA name for - // consistency. Testcase is libgomp.fortran/doacross1.f90. - if (slot->name != name) - slot->name = name; - return; - } - m_ssa_cache[version] - = new cache_entry (name, range.true_range, range.false_range); -} - -// If there is a cached entry of NAME, set it in R and return TRUE, -// otherwise return FALSE. LHS is the defining statement where NAME -// appeared. - -bool -logical_stmt_cache::get_range (tf_range &r, tree lhs, tree name) const -{ - gcc_checking_assert (cacheable_p (SSA_NAME_DEF_STMT (lhs))); - if (cached_name (lhs) == name) - { - unsigned version = SSA_NAME_VERSION (lhs); - if (m_ssa_cache[version]) - { - r = m_ssa_cache[version]->range; - return true; - } - } - return false; -} - -// If the defining statement of LHS is in the cache, return the SSA -// operand being cached. That is, return SSA for LHS = SSA .RELOP. OP2. - -tree -logical_stmt_cache::cached_name (tree lhs) const -{ - unsigned version = SSA_NAME_VERSION (lhs); - - if (version >= m_ssa_cache.length ()) - return NULL; - - if (m_ssa_cache[version]) - return m_ssa_cache[version]->name; - return NULL; -} - -// Return TRUE if the cached name for LHS1 is the same as the -// cached name for LHS2. - -tree -logical_stmt_cache::same_cached_name (tree lhs1, tree lhs2) const -{ - tree name = cached_name (lhs1); - if (name && name == cached_name (lhs2)) - return name; - return NULL; -} - -// Return TRUE if STMT is a statement we are interested in caching. -// LHS_RANGE is any known range for the LHS of STMT. - -bool -logical_stmt_cache::cacheable_p (gimple *stmt, const irange *lhs_range) const -{ - if (gimple_code (stmt) == GIMPLE_ASSIGN - && types_compatible_p (TREE_TYPE (gimple_assign_lhs (stmt)), - boolean_type_node) - && TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME) - { - switch (gimple_expr_code (stmt)) - { - case TRUTH_AND_EXPR: - case BIT_AND_EXPR: - case TRUTH_OR_EXPR: - case BIT_IOR_EXPR: - return !lhs_range || range_is_either_true_or_false (*lhs_range); - default: - return false; - } - } - return false; -} - -// Output debugging diagnostics for the cache entry for LHS. RANGE is -// the new range that is being cached. - -void -logical_stmt_cache::slot_diagnostics (tree lhs, const tf_range &range) const -{ - gimple *stmt = SSA_NAME_DEF_STMT (lhs); - unsigned version = SSA_NAME_VERSION (lhs); - cache_entry *slot = m_ssa_cache[version]; - - if (!slot) - { - if (DEBUG_RANGE_CACHE) - { - fprintf (dump_file ? dump_file : stderr, "registering range for: "); - dump (dump_file ? dump_file : stderr, stmt); - } - return; - } - if (DEBUG_RANGE_CACHE) - fprintf (dump_file ? dump_file : stderr, - "reusing range for SSA #%d\n", version); - if (CHECKING_P && (slot->range.true_range != range.true_range - || slot->range.false_range != range.false_range)) - { - fprintf (stderr, "FATAL: range altered for cached: "); - dump (stderr, stmt); - fprintf (stderr, "Attempt to change to:\n"); - fprintf (stderr, "TRUE="); - range.true_range.dump (stderr); - fprintf (stderr, ", FALSE="); - range.false_range.dump (stderr); - fprintf (stderr, "\n"); - gcc_unreachable (); - } -} - -// Dump the cache information for STMT. - -void -logical_stmt_cache::dump (FILE *out, gimple *stmt) const -{ - tree lhs = gimple_assign_lhs (stmt); - cache_entry *entry = m_ssa_cache[SSA_NAME_VERSION (lhs)]; - - print_gimple_stmt (out, stmt, 0, TDF_SLIM); - if (entry) - { - fprintf (out, "\tname = "); - print_generic_expr (out, entry->name); - fprintf (out, " lhs(%d)= ", SSA_NAME_VERSION (lhs)); - print_generic_expr (out, lhs); - fprintf (out, "\n\tTRUE="); - entry->range.true_range.dump (out); - fprintf (out, ", FALSE="); - entry->range.false_range.dump (out); - fprintf (out, "\n"); - } - else - fprintf (out, "[EMPTY]\n"); -} - -gori_compute_cache::gori_compute_cache () -{ - m_cache = new logical_stmt_cache; -} - -gori_compute_cache::~gori_compute_cache () -{ - delete m_cache; -} - -// Caching version of compute_operand_range. If NAME, as it appears -// in STMT, has already been cached return it from the cache, -// otherwise compute the operand range as normal and cache it. - -bool -gori_compute_cache::compute_operand_range (irange &r, gimple *stmt, - const irange &lhs_range, tree name) -{ - bool cacheable = m_cache->cacheable_p (stmt, &lhs_range); - if (cacheable) - { - tree lhs = gimple_assign_lhs (stmt); - tf_range range; - if (m_cache->get_range (range, lhs, name)) - { - if (lhs_range.zero_p ()) - r = range.false_range; - else - r = range.true_range; - return true; - } - } - if (super::compute_operand_range (r, stmt, lhs_range, name)) - { - if (cacheable) - cache_stmt (stmt); - return true; - } - return false; -} - -// Cache STMT if possible. - -void -gori_compute_cache::cache_stmt (gimple *stmt) -{ - gcc_checking_assert (m_cache->cacheable_p (stmt)); - enum tree_code code = gimple_expr_code (stmt); - tree lhs = gimple_assign_lhs (stmt); - tree op1 = gimple_range_operand1 (stmt); - tree op2 = gimple_range_operand2 (stmt); - int_range_max r_true_side, r_false_side; - - // LHS = s_5 && 999. - if (TREE_CODE (op2) == INTEGER_CST) - { - range_operator *handler = range_op_handler (code, TREE_TYPE (lhs)); - int_range_max op2_range; - expr_range_at_stmt (op2_range, op2, stmt); - tree type = TREE_TYPE (op1); - handler->op1_range (r_true_side, type, m_bool_one, op2_range); - handler->op1_range (r_false_side, type, m_bool_zero, op2_range); - m_cache->set_range (lhs, op1, tf_range (r_true_side, r_false_side)); - } - // LHS = s_5 && b_8. - else if (tree cached_name = m_cache->same_cached_name (op1, op2)) - { - tf_range op1_range, op2_range; - bool ok = m_cache->get_range (op1_range, op1, cached_name); - ok = ok && m_cache->get_range (op2_range, op2, cached_name); - ok = ok && logical_combine (r_true_side, code, m_bool_one, - op1_range, op2_range); - ok = ok && logical_combine (r_false_side, code, m_bool_zero, - op1_range, op2_range); - gcc_checking_assert (ok); - if (ok) - m_cache->set_range (lhs, cached_name, - tf_range (r_true_side, r_false_side)); - } -} diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 8a85d6a2b79..f41dee3d8e5 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -158,8 +158,8 @@ public: void dump (FILE *f); protected: virtual void ssa_range_in_bb (irange &r, tree name, basic_block bb); - virtual bool compute_operand_range (irange &r, gimple *stmt, - const irange &lhs, tree name); + bool compute_operand_range (irange &r, gimple *stmt, + const irange &lhs, tree name); void expr_range_at_stmt (irange &r, tree expr, gimple *s); bool compute_logical_operands (irange &r, gimple *stmt, @@ -217,31 +217,4 @@ protected: unsigned y; }; -// This class adds a cache to gori_computes for logical expressions. -// bool result = x && y -// requires calcuation of both X and Y for both true and false results. -// There are 4 combinations [0,0][0,0] [0,0][1,1] [1,1][0,0] and [1,1][1,1]. -// Note that each pair of possible results for X and Y are used twice, and -// the calcuation of those results are the same each time. -// -// The cache simply checks if a stmt is cachable, and if so, saves both the -// true and false results for the next time the query is made. -// -// This is used to speed up long chains of logical operations which -// quickly become exponential. - -class gori_compute_cache : public gori_compute -{ -public: - gori_compute_cache (); - ~gori_compute_cache (); -protected: - virtual bool compute_operand_range (irange &r, gimple *stmt, - const irange &lhs, tree name); -private: - void cache_stmt (gimple *); - typedef gori_compute super; - class logical_stmt_cache *m_cache; -}; - #endif // GCC_GIMPLE_RANGE_GORI_H -- 2.17.2