From patchwork Fri Jul 28 20:38:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1814440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=QvzPZHHe; dkim-atps=neutral Received: from server2.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RCKHf758kz1yYq for ; Sat, 29 Jul 2023 06:39:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F10AB385C6F7 for ; Fri, 28 Jul 2023 20:39:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F10AB385C6F7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690576765; bh=uIozzS+fmfMR+GhodAoA87U6C2RWrmy1QqKpwOlTZsU=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=QvzPZHHebM6ToYcMf/+67jGrbbFQZIgbIoulKpBUOyUJYr0auLDw77k6RV75Vb/2l EFvCM0XulckLOWi8o4+ics50U+Smf2+wyacRZOk8Zr/gR9JZ+rKhsueiw5XGNXQXJ7 FN+Du/7r+/HSRV8bISu7QSU/szL1TVteDrss8tmY= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 6FD2C3854C5C for ; Fri, 28 Jul 2023 20:38:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FD2C3854C5C Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-393-2BfeivzJM8KFXwQ13AG0wA-1; Fri, 28 Jul 2023 16:38:09 -0400 X-MC-Unique: 2BfeivzJM8KFXwQ13AG0wA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-76c562323fbso326948885a.0 for ; Fri, 28 Jul 2023 13:38:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690576688; x=1691181488; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=W74v9hYvjdmpd/F8mtvetrRsYZC1Gkmq5Wig/xPE2Kw=; b=fjGQcUWeIr3cmliscT624+vNNrisyF00AY5Ig0+TEJkEEbu/9ZDqpMgbU2rKwjr6lz QlP1xfIhS7HMzyarK6l2NtneG0F1CHSqcff6agy/vCVPFAy0ksLCaQjtTkcsv7lIjYmw D+nxGL7FDrnFj7ggiM0+t2eDrDz8r4qG+0p2Z87/NQ/8hXamEIrxvPsoQH9tV7SFKhAr CzPtq3eivB8NbNc3u6yvVgUWD09enYUfkwOZLGF9ixUPvyCvXvaUZfcMqMEReJph11YT HeNsRz4WLF6Ctx7jwiONL6EZqAn7GtqVzlsTbgGkTeZWgFE9dpc29H4xy0HcXtc/u/Qk u8Kg== X-Gm-Message-State: ABy/qLZtHCqBKmPTCBMWwSE0g6pYfurbYjQTjO/icS3V1SMV4YCJmMRG Tc1RKaV5lA+Dkd086GhDc+ugyubggcYAb7ZpVjvghz+6Z/n0RqUEbwIL1F4ZmI8O0UJQUr2ZP2R GbHldnzDH6OVOupdx3cVi1EfyfFzi+g96fXsXtnnAWwrwLokBIIjP76KmyVD3S+fFaJz7tHayHw KMNw== X-Received: by 2002:a05:620a:bd3:b0:767:276:3c9c with SMTP id s19-20020a05620a0bd300b0076702763c9cmr3974607qki.14.1690576688774; Fri, 28 Jul 2023 13:38:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlHqpC3dTsG9wW2qF+IEtmCXGK3uXB3jv5TJKLcOLfrwW5JyOq8ck9h96GBrg4AITUHb7afA6A== X-Received: by 2002:a05:620a:bd3:b0:767:276:3c9c with SMTP id s19-20020a05620a0bd300b0076702763c9cmr3974593qki.14.1690576688450; Fri, 28 Jul 2023 13:38:08 -0700 (PDT) Received: from ?IPV6:2607:fea8:51e0:8e00::8eb7? ([2607:fea8:51e0:8e00::8eb7]) by smtp.gmail.com with ESMTPSA id t26-20020a05620a035a00b00767cfe27dccsm1374444qkm.112.2023.07.28.13.38.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Jul 2023 13:38:07 -0700 (PDT) Message-ID: Date: Fri, 28 Jul 2023 16:38:06 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 To: gcc-patches Cc: "hernandez, aldy" Subject: [COMMITTED] Remove value_query, push into sub&fold class. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.4 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When we first introduced range_query, we provided a base class for constants rather than range queries.  Then inherioted from that and modified the value queries for a range-specific engine. .   At the time, we figured there would be other consumers of the value_query class. When all the dust settled, it turned out that subsitute_and_fold is the only consumer, and all the other places we perceived there to be value clients actually use substitute_and_fold. This patch simplifies everything by providing only a range-query class, and moving the old value_range functionality into substitute_and_fold, the only place that uses it. Bootstrapped on x86_64-pc-linux-gnu with no regressions. Pushed. Andrew From 619641397a558bf65c24b99a4c52878bd940fcbe Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Sun, 16 Jul 2023 12:46:00 -0400 Subject: [PATCH 2/3] Remove value_query, push into sub&fold class * tree-ssa-propagate.cc (substitute_and_fold_engine::value_on_edge): Move from value-query.cc. (substitute_and_fold_engine::value_of_stmt): Ditto. (substitute_and_fold_engine::range_of_expr): New. * tree-ssa-propagate.h (substitute_and_fold_engine): Inherit from range_query. New prototypes. * value-query.cc (value_query::value_on_edge): Relocate. (value_query::value_of_stmt): Ditto. * value-query.h (class value_query): Remove. (class range_query): Remove base class. Adjust prototypes. --- gcc/tree-ssa-propagate.cc | 28 ++++++++++++++++++++++++++++ gcc/tree-ssa-propagate.h | 8 +++++++- gcc/value-query.cc | 21 --------------------- gcc/value-query.h | 30 ++++-------------------------- 4 files changed, 39 insertions(+), 48 deletions(-) diff --git a/gcc/tree-ssa-propagate.cc b/gcc/tree-ssa-propagate.cc index 174d19890f9..cb68b419b8c 100644 --- a/gcc/tree-ssa-propagate.cc +++ b/gcc/tree-ssa-propagate.cc @@ -532,6 +532,34 @@ struct prop_stats_d static struct prop_stats_d prop_stats; +// range_query default methods to drive from a value_of_expr() ranther than +// range_of_expr. + +tree +substitute_and_fold_engine::value_on_edge (edge, tree expr) +{ + return value_of_expr (expr); +} + +tree +substitute_and_fold_engine::value_of_stmt (gimple *stmt, tree name) +{ + if (!name) + name = gimple_get_lhs (stmt); + + gcc_checking_assert (!name || name == gimple_get_lhs (stmt)); + + if (name) + return value_of_expr (name); + return NULL_TREE; +} + +bool +substitute_and_fold_engine::range_of_expr (vrange &, tree, gimple *) +{ + return false; +} + /* Replace USE references in statement STMT with the values stored in PROP_VALUE. Return true if at least one reference was replaced. */ diff --git a/gcc/tree-ssa-propagate.h b/gcc/tree-ssa-propagate.h index be4cb457873..29bde37add9 100644 --- a/gcc/tree-ssa-propagate.h +++ b/gcc/tree-ssa-propagate.h @@ -96,11 +96,17 @@ class ssa_propagation_engine void simulate_block (basic_block); }; -class substitute_and_fold_engine : public value_query +class substitute_and_fold_engine : public range_query { public: substitute_and_fold_engine (bool fold_all_stmts = false) : fold_all_stmts (fold_all_stmts) { } + + virtual tree value_of_expr (tree expr, gimple * = NULL) = 0; + virtual tree value_on_edge (edge, tree expr) override; + virtual tree value_of_stmt (gimple *, tree name = NULL) override; + virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL); + virtual ~substitute_and_fold_engine (void) { } virtual bool fold_stmt (gimple_stmt_iterator *) { return false; } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index adef93415b7..0870d6c60a6 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -33,27 +33,6 @@ along with GCC; see the file COPYING3. If not see #include "gimple-range.h" #include "value-range-storage.h" -// value_query default methods. - -tree -value_query::value_on_edge (edge, tree expr) -{ - return value_of_expr (expr); -} - -tree -value_query::value_of_stmt (gimple *stmt, tree name) -{ - if (!name) - name = gimple_get_lhs (stmt); - - gcc_checking_assert (!name || name == gimple_get_lhs (stmt)); - - if (name) - return value_of_expr (name); - return NULL_TREE; -} - // range_query default methods. bool diff --git a/gcc/value-query.h b/gcc/value-query.h index d10c3eac1e2..429446b32eb 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -37,28 +37,6 @@ along with GCC; see the file COPYING3. If not see // Proper usage of the correct query in passes will enable other // valuation mechanisms to produce more precise results. -class value_query -{ -public: - value_query () { } - // Return the singleton expression for EXPR at a gimple statement, - // or NULL if none found. - virtual tree value_of_expr (tree expr, gimple * = NULL) = 0; - // Return the singleton expression for EXPR at an edge, or NULL if - // none found. - virtual tree value_on_edge (edge, tree expr); - // Return the singleton expression for the LHS of a gimple - // statement, assuming an (optional) initial value of NAME. Returns - // NULL if none found. - // - // Note that this method calculates the range the LHS would have - // *after* the statement has executed. - virtual tree value_of_stmt (gimple *, tree name = NULL); - -private: - DISABLE_COPY_AND_ASSIGN (value_query); -}; - // The range_query class is used by optimization passes which are // range aware. // @@ -73,15 +51,15 @@ private: // The get_value_range method is currently provided for compatibility // with vr-values. It will be deprecated when possible. -class range_query : public value_query +class range_query { public: range_query (); virtual ~range_query (); - virtual tree value_of_expr (tree expr, gimple * = NULL) override; - virtual tree value_on_edge (edge, tree expr) override; - virtual tree value_of_stmt (gimple *, tree name = NULL) override; + virtual tree value_of_expr (tree expr, gimple * = NULL); + virtual tree value_on_edge (edge, tree expr); + virtual tree value_of_stmt (gimple *, tree name = NULL); // These are the range equivalents of the value_* methods. Instead // of returning a singleton, they calculate a range and return it in -- 2.40.1