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: 127857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp680651vqg; Fri, 28 Jul 2023 13:40:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEuSah0joZdCFSNQ/XeoX3DTc23jiYlCYWvBuBdGP9euMkTQOrH4yc69cUC6UYV0vORRy1 X-Received: by 2002:a17:906:8a45:b0:977:ecff:3367 with SMTP id gx5-20020a1709068a4500b00977ecff3367mr333732ejc.40.1690576813518; Fri, 28 Jul 2023 13:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690576813; cv=none; d=google.com; s=arc-20160816; b=YYThubhnJHrhOGpiTuhokdMQNLRVE1AEdjfEWpt5FP3KL+anZ/OUPrAD7DLZ/NxQUy uo3AeN8ehKQ4JymCqcWFTKHG2x4dO9aePxUXE2+wNOhYUnTfoPKuSevELDNVl7xQrQIT JyKUFQlIcUIS3ZowXCsJeK5lP6sgN0lfWW7+1xU9TZh11VvB1s5W6GyYwgr2mzvD14qw +ibm+BYSehigjvg/QAu621oVN1J5Ta9QzmG/O7wtW+dDw7YO4AiipKyusyeJOFONG5lY ukiONDrKFUfapgUAMUquVY+fDX/MQiCpC7UdoJ5h4+f/kvvXRaBnG5H883Na4V8acpuo 3Fiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:content-language :subject:cc:to:user-agent:mime-version:date:message-id:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=uIozzS+fmfMR+GhodAoA87U6C2RWrmy1QqKpwOlTZsU=; fh=gclC9oA2esmCBAay1qQbUaUwD9iqJFz6H0IpB4Uz3uA=; b=lEgGa3jqcJsb8deu0d36HSXhX1n8rCR0niw8SZTdGNecpAv+g9fNjShCVUF3h/iapu 4PT52e2lUUmhznmWryLIjKXJCniaUOgtKsDHGiuiK93+5iJFdfRJkbzoEYadrouYrTa1 KrXg9SFJKh7NCN5Pb+eUz74H4BbkdPOhuBl5bHhACCE/kIYxhkWfu0CuGdcPg/z1uBkw yMWZ1S/DiH+GanR7AUw6NjchC8nT4PCABdXmS9bsT+7Hb3w3Am/9zcAz6fC4UhH3eaDw rj9WGPTu3J4hkeZJLAvTzzkIMQxqVFVqv+bOnCev0+wBDYLaTX/EZoimKO9WVuF9FVlH 42xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mQprlbpv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qw9-20020a170906fca900b009784f00c5besi3109799ejb.263.2023.07.28.13.40.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 13:40:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=mQprlbpv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 36EB7385DC0E for ; Fri, 28 Jul 2023 20:39:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36EB7385DC0E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1690576788; 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=mQprlbpv0yiADYykMJrf2sXWM2hoCkaimK8usggpHh5UKwW+4TY0tGfeONjri8erw UVCZgwE/LUXL72zB/fnjjLYCpATj0jWLgvIbqcsT/ZljBBtAT1xwvQKmFCWlMBJsKM lH2/1EMns5h28pdOo76l4i0854RJWo1aFbwZ52To= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772698272805511543 X-GMAIL-MSGID: 1772698272805511543 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