From patchwork Thu May 23 20:52:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938582 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FJah+DKW; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgPM1rmGz20Q0 for ; Fri, 24 May 2024 06:53:27 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 20C5A386C591 for ; Thu, 23 May 2024 20:53:25 +0000 (GMT) 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 ESMTPS id 3CF773865C29 for ; Thu, 23 May 2024 20:52:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CF773865C29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3CF773865C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497580; cv=none; b=S6lBfoSjbalxkj1bW8er8IIP7jJxaGR3HhqRhBHdXFf6mHduoUu9ZYmj0Vk3dnAH3tZYvHM7ugTdPX3atFQHpP8BCaybAueBtZZu0vUmT1VW/hTSF9js8ca0ZK5t8ZhjCoEguA0Aa12qGgaJGB/YyiiNt4PXf1RHLJO68xIrbWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497580; c=relaxed/simple; bh=aPAjDsrKMX5ZpJDbRpgkykFx3lwyQPo0AfIyPSAk+uY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=WHLTnMqRFmN90ZAez2FbbCo2uVr53sBe9RF1KmtpCSRLOag203to8fJprO5HkQWkqeFJ3stcRA84YX9KPQEYuH2QFtcV2/an+cJx1eb/0gQGeoxK4Sl/vLp+Z+cMuqaq2CDfZLxxuRSxTWOCHgw0M1AXj9d88L2/eet1JRc/n7Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=2W6yZsRVLho9mrERrnGhgX3pNseexNvYji7f19apE88=; b=FJah+DKWClyu78w0DQLYbbkDvyfOwQ7dzAns1d5491Ht6fGCxrxRoBywllMkiHgO/Il6jD VeIIZ+mAVO3zD/voI2HCNeeaelTQbhu1nRj03shYIdgSTVKLExe68cfv3okiood0WUfs8c abd+cfdgr1eSV44yE2Jy9RroyVpgRLU= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-B16riJ4pM2e6_vgmFVn2FA-1; Thu, 23 May 2024 16:52:52 -0400 X-MC-Unique: B16riJ4pM2e6_vgmFVn2FA-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-794a0a73d75so71852185a.0 for ; Thu, 23 May 2024 13:52:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497571; x=1717102371; 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=O+oi0Pv8kpZngD/e6kob5MNXo0n8R0iBSYOvdveOK0E=; b=KpLGvJIFydEDXSO9pI76TMUDBuEBqTdWTic6WvGwFdiyFmyTDwKkXokR2RR2sp9W/i bFJSIfDlDLlDM5UPuALocySJltM4lBFhKI0w9//uxAQ2WZJkBFfvczG2hBKXF2yhmftl 9RWGjF5Hdk4jFwna7rDUcZJKpPT379lA/ZNrQKvmz/yf5PtxIJx9aqhpGr5oIYCt0Zg2 ES9UBVA3ZFuEgpXWRo3TtKCcC4C1iY73OQb9xHiV+3V4ZnEEvf49gZfcnOGkclFY3vMy 6A2m7Cq0JXgAv+SEu302l7MC3EtriYx/lTq5yHPMjkCWpVNeQu6G60R/aLzMfER4Emnk 0xCA== X-Gm-Message-State: AOJu0YzwPjG2im4hUZfkDNLwSZ52deg+H/UOTDZpAXaaTX7qh6zNKrF5 Cy1JODKpRL6Kqp6y/+Ah3zWCDmBScG7wEUUQDebt12ryRKuCm2WJcXqG5JKXDaRlbRwSl1UVdjP RtVcMurRdCLRB52SGt4/SJzlnwvHGrgQfBAmgWLaVM8MssE6kh9f29aKKivfLWVatQBTVluy+3O REqdxGMoWNkpzicyvN4wW4Cisi9wR+yqo1p5TLNws= X-Received: by 2002:a05:620a:31a7:b0:792:ba4e:b811 with SMTP id af79cd13be357-794a09fcb28mr634684685a.30.1716497571292; Thu, 23 May 2024 13:52:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8q1nfTvXi192qNA6U/vXHxa62DY7I3qG2FA4/UaeG0VdMr9/UiYgxIlxDLVJ3c+um1/vE1g== X-Received: by 2002:a05:620a:31a7:b0:792:ba4e:b811 with SMTP id af79cd13be357-794a09fcb28mr634681485a.30.1716497570853; Thu, 23 May 2024 13:52:50 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.52.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:52:50 -0700 (PDT) Message-ID: Date: Thu, 23 May 2024 16:52:49 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 01/12] - Move all relation queries into relation_oracle. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.7 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org A range-query currently provides a couple of relation query routines, plus it also provides direct access to an oracle.   This patch moves those queries into the oracle where they should be, and ands the ability to create and destroy the basic dominance oracle ranger uses.  This is the usual oracle most passes would want, and this provides full access to it if ranger has been enabled.  It also allows passes which do not use ranger to turn on an oracle and work with it. Full documentation  for relations and the oracle can be found at:   https://gcc.gnu.org/wiki/AndrewMacLeod/Relations Moving the queries into the oracle removes the need to check for a NULL pointer on every query, and results in speeding up VRP by about 0.7% Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From b0cbffd5655b9fc108691c6b15e8eaed4ab9746a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 29 Apr 2024 13:32:00 -0400 Subject: [PATCH 01/12] Move all relation queries into relation_oracle. Move relation queries from range_query object into the relation oracle. * gimple-range-cache.cc (ranger_cache::ranger_cache): Call create_relation_oracle. (ranger_cache::~ranger_cache): Call destroy_relation_oracle. * gimple-range-fold.cc (fur_stmt::get_phi_operand): Check for relation oracle bnefore calling query_relation. (fold_using_range::range_of_phi): Likewise. * gimple-range-path.cc (path_range_query::path_range_query): Set relation oracle pointer to NULL after deleting it. * value-query.cc (range_query::~range_query): Ensure any relation oracle is destroyed. (range_query::query_relation): relocate to relation_oracle object. * value-query.h (class range_query): Adjust method proototypes. (range_query::create_relation_oracle): New. (range_query::destroy_relation_oracle): New. * value-relation.cc (relation_oracle::query_relation): Relocate from range query class. * value-relation.h (Call relation_oracle): New prototypes. --- gcc/gimple-range-cache.cc | 9 +++---- gcc/gimple-range-fold.cc | 9 +++++-- gcc/gimple-range-path.cc | 1 + gcc/gimple-range.cc | 1 + gcc/value-query.cc | 52 ++------------------------------------- gcc/value-query.h | 32 +++++++++++++++++++----- gcc/value-relation.cc | 33 +++++++++++++++++++++++++ gcc/value-relation.h | 4 ++- 8 files changed, 76 insertions(+), 65 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index bdd2832873a..cf17a6af9db 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -957,11 +957,9 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun)); m_workback.truncate (0); m_temporal = new temporal_cache; + // If DOM info is available, spawn an oracle as well. - if (dom_info_available_p (CDI_DOMINATORS)) - m_oracle = new dom_oracle (); - else - m_oracle = NULL; + create_relation_oracle (); unsigned x, lim = last_basic_block_for_fn (cfun); // Calculate outgoing range info upfront. This will fully populate the @@ -979,8 +977,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) ranger_cache::~ranger_cache () { delete m_update; - if (m_oracle) - delete m_oracle; + destroy_relation_oracle (); delete m_temporal; m_workback.release (); } diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index a9c8c4d03e6..41b6d350c40 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -178,7 +178,10 @@ fur_stmt::get_phi_operand (vrange &r, tree expr, edge e) relation_kind fur_stmt::query_relation (tree op1, tree op2) { - return m_query->query_relation (m_stmt, op1, op2); + relation_oracle *oracle = m_query->oracle (); + if (!oracle) + return VREL_VARYING; + return oracle->query_relation (m_stmt, op1, op2); } // Instantiate a stmt based fur_source with a GORI object. @@ -860,6 +863,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) tree single_arg = NULL_TREE; bool seen_arg = false; + relation_oracle *oracle = src.query()->oracle (); // Start with an empty range, unioning in each argument's range. r.set_undefined (); for (x = 0; x < gimple_phi_num_args (phi); x++) @@ -880,7 +884,8 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) // Likewise, if the incoming PHI argument is equivalent to this // PHI definition, it provides no new info. Accumulate these ranges // in case all arguments are equivalences. - if (src.query ()->query_relation (e, arg, phi_def, false) == VREL_EQ) + if (oracle + && oracle->query_relation (e, arg, phi_def) == VREL_EQ) equiv_range.union_(arg_range); else r.union_ (arg_range); diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index f1a12f76144..ef3db10470e 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -60,6 +60,7 @@ path_range_query::path_range_query (gimple_ranger &ranger, bool resolve) path_range_query::~path_range_query () { delete m_oracle; + m_oracle = NULL; } // Return TRUE if NAME is an exit dependency for the path. diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index e75e2e17dc3..22e8add5de1 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -67,6 +67,7 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : gimple_ranger::~gimple_ranger () { + m_oracle = NULL; m_stmt_list.release (); } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index c2ab745a466..b275a43b679 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -185,6 +185,8 @@ range_query::range_query () range_query::~range_query () { + if (m_oracle) + destroy_relation_oracle (); } // This routine will invoke the equivalent of range_of_expr on @@ -437,53 +439,3 @@ global_range_query::range_of_expr (vrange &r, tree expr, gimple *stmt) return true; } - -// Return any known relation between SSA1 and SSA2 before stmt S is executed. -// If GET_RANGE is true, query the range of both operands first to ensure -// the definitions have been processed and any relations have be created. - -relation_kind -range_query::query_relation (gimple *s, tree ssa1, tree ssa2, bool get_range) -{ - if (!m_oracle || TREE_CODE (ssa1) != SSA_NAME || TREE_CODE (ssa2) != SSA_NAME) - return VREL_VARYING; - - // Ensure ssa1 and ssa2 have both been evaluated. - if (get_range) - { - Value_Range tmp1 (TREE_TYPE (ssa1)); - Value_Range tmp2 (TREE_TYPE (ssa2)); - range_of_expr (tmp1, ssa1, s); - range_of_expr (tmp2, ssa2, s); - } - return m_oracle->query_relation (gimple_bb (s), ssa1, ssa2); -} - -// Return any known relation between SSA1 and SSA2 on edge E. -// If GET_RANGE is true, query the range of both operands first to ensure -// the definitions have been processed and any relations have be created. - -relation_kind -range_query::query_relation (edge e, tree ssa1, tree ssa2, bool get_range) -{ - basic_block bb; - if (!m_oracle || TREE_CODE (ssa1) != SSA_NAME || TREE_CODE (ssa2) != SSA_NAME) - return VREL_VARYING; - - // Use destination block if it has a single predecessor, and this picks - // up any relation on the edge. - // Otherwise choose the src edge and the result is the same as on-exit. - if (!single_pred_p (e->dest)) - bb = e->src; - else - bb = e->dest; - - // Ensure ssa1 and ssa2 have both been evaluated. - if (get_range) - { - Value_Range tmp (TREE_TYPE (ssa1)); - range_on_edge (tmp, e, ssa1); - range_on_edge (tmp, e, ssa2); - } - return m_oracle->query_relation (bb, ssa1, ssa2); -} diff --git a/gcc/value-query.h b/gcc/value-query.h index 4d2a7bce485..9df89905ace 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -75,16 +75,12 @@ public: virtual bool range_on_entry (vrange &r, basic_block bb, tree expr); virtual bool range_on_exit (vrange &r, basic_block bb, tree expr); - // Query if there is any relation between SSA1 and SSA2. - relation_kind query_relation (gimple *s, tree ssa1, tree ssa2, - bool get_range = true); - relation_kind query_relation (edge e, tree ssa1, tree ssa2, - bool get_range = true); - // If present, Access relation oracle for more advanced uses. inline relation_oracle *oracle () const { return m_oracle; } virtual void dump (FILE *); + void create_relation_oracle (); + void destroy_relation_oracle (); protected: bool get_tree_range (vrange &v, tree expr, gimple *stmt, basic_block bbentry = NULL, basic_block bbexit = NULL); @@ -123,4 +119,28 @@ get_range_query (const struct function *fun) extern void gimple_range_global (vrange &v, tree name, struct function *f = cfun); +// Create dominance based range oracle for the current query if dom info is +// available. + +inline void +range_query::create_relation_oracle () +{ + if (!dom_info_available_p (CDI_DOMINATORS)) + return; + gcc_checking_assert (m_oracle == NULL); + m_oracle = new dom_oracle (); +} + +// Destroy any relation oracle that was created. + +inline void +range_query::destroy_relation_oracle () +{ + if (m_oracle != NULL) + { + delete m_oracle; + m_oracle = NULL; + } +} + #endif // GCC_QUERY_H diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index 619ee5f0867..d1081b3b3f5 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -288,6 +288,39 @@ relation_oracle::valid_equivs (bitmap b, const_bitmap equivs, basic_block bb) } } +// Return any known relation between SSA1 and SSA2 before stmt S is executed. +// If GET_RANGE is true, query the range of both operands first to ensure +// the definitions have been processed and any relations have be created. + +relation_kind +relation_oracle::query_relation (gimple *s, tree ssa1, tree ssa2) +{ + if (TREE_CODE (ssa1) != SSA_NAME || TREE_CODE (ssa2) != SSA_NAME) + return VREL_VARYING; + return query_relation (gimple_bb (s), ssa1, ssa2); +} + +// Return any known relation between SSA1 and SSA2 on edge E. +// If GET_RANGE is true, query the range of both operands first to ensure +// the definitions have been processed and any relations have be created. + +relation_kind +relation_oracle::query_relation (edge e, tree ssa1, tree ssa2) +{ + basic_block bb; + if (TREE_CODE (ssa1) != SSA_NAME || TREE_CODE (ssa2) != SSA_NAME) + return VREL_VARYING; + + // Use destination block if it has a single predecessor, and this picks + // up any relation on the edge. + // Otherwise choose the src edge and the result is the same as on-exit. + if (!single_pred_p (e->dest)) + bb = e->src; + else + bb = e->dest; + + return query_relation (bb, ssa1, ssa2); +} // ------------------------------------------------------------------------- // The very first element in the m_equiv chain is actually just a summary diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 61d2497743c..5adf736cf41 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -105,8 +105,10 @@ public: // register a relation between 2 ssa names in a basic block. virtual void register_relation (basic_block, relation_kind, tree, tree) = 0; - // Query for a relation between two ssa names in a basic block. + // Query if there is any relation between SSA1 and SSA2. virtual relation_kind query_relation (basic_block, tree, tree) = 0; + relation_kind query_relation (gimple *s, tree ssa1, tree ssa2); + relation_kind query_relation (edge e, tree ssa1, tree ssa2); relation_kind validate_relation (relation_kind, tree, tree); relation_kind validate_relation (relation_kind, vrange &, vrange &); -- 2.41.0 From patchwork Thu May 23 20:52:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938583 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TP2f+Do/; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgPP2s89z20Q0 for ; Fri, 24 May 2024 06:53:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2163386C598 for ; Thu, 23 May 2024 20:53:27 +0000 (GMT) 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 ESMTPS id C2B5A3849AC4 for ; Thu, 23 May 2024 20:53:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C2B5A3849AC4 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C2B5A3849AC4 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497587; cv=none; b=cXM3h1lGCR4bRFGmn+i+l5Iw6pJU84Ehl0bhgtODs2D+dgCnU2hP4ycYTnrWmgFsJNdhb2u4PlftztsBatsxB7ym7klR7X26E9/1dWYmma0VU5Mskpy3+xwb+SclvOIeRGqE16YhUH39szXh8ay/RV1fx57Ott36vTZ9UbF9Y8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497587; c=relaxed/simple; bh=ciOGMUeulq/Nftab2DR0wJGqsPU8ecPRRD/oH9+ue7A=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=HmF3gP6D9asQAWUzrxtovVGta10VhElJDR0qbbxz4zUR3IPWKpmceRrGsFwIh+eFE8ac/Heom7tlzx4aPmZGKK4uVFLgifHRhQE1JmgT/lX96fKLzxskShPwWdHQOVEw+WVMVY0lrYL6q3R9nllACwdI9DR6orRanyl4foT115M= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=yTVdFGv64T18FYgpou/33KYIqBxLzC3H7/OdmqxWCWY=; b=TP2f+Do/4sOsUCFVOOLlviky7LtZqXv5MJHtBL95VLnA9o6lLSPJzue45oQwKK3LwXJnLF yLWtP290Jo1GE/WI6v3vaTeHOPBEXyqUjF5YOwTWVI9JQE2kLP23ycoy7YbRNGB7LX/d7B w+Xu/xpU5zJVE+CjGZoBTYxDF+NAJvQ= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-pKsK50PNMHang97QDxZ2yw-1; Thu, 23 May 2024 16:52:59 -0400 X-MC-Unique: pKsK50PNMHang97QDxZ2yw-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-4df9b605458so164358e0c.3 for ; Thu, 23 May 2024 13:52:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497578; x=1717102378; 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=vEOyKc1eOECreRYtBncxOS189FnOZlmnLViiUuiLmB0=; b=kHp4cB3mq6uqUR1y0P8xaMWkSN8NqdikEEEvsj2prr9II+B5re1SuXve5n8QTMDxik ADBa6SAgRkxwNSskW1Sz3leq9EXCURcPcjEGmw+nV691ECJ0LIU+7fTZDHPHP/SXDfig IjHCQVjEGVW43wXnNuqAnRt6udkHs5sirnbjsVMaMQANNzMicVBRTxPLK18rvLwjl1uj MoHibk7LGTup7Bc/v48PSb5dxfmukTZd0Vp54KVdCv09BdqzH7sekUjR1lQVp+0orfZ3 vwdutPqC/ByKIgIyjY0QlAyLMQz4pE7NyTxP9Jr+XyorLgATyCsxXtDULDXHowCcB1lC 7Ghw== X-Gm-Message-State: AOJu0YxERMzeurxld3yDdOtGKn6HsVOOyqvahYjyKYc78vUHTqMw24bO CeQ+yu4Px9JOav3CIHhsOt29Q1CSoTG2AcL8X7tuFbwX0X3we6kHUFK5HA51Efl/eyHluU8CXh3 qzHRhT6tMVzjoz6Q+yvuveoh6S8mBa2TEbtpB/WVVur9FQ+td2trK5t/zBn6L6u9g1TkSp/O5eO UHYC2iROIPLJmA6wFV17aeH0FtDv3qRLLVmy2NhLA= X-Received: by 2002:a05:6122:2205:b0:4e4:ecd7:ad49 with SMTP id 71dfb90a1353d-4e4f021c840mr459620e0c.2.1716497578082; Thu, 23 May 2024 13:52:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFH1/m7epwTY34Pi2RNcEVpqtYDDFXwUqYdMc5YlK3TQUj1K6JQZvHXYJnTkKBekY7gYEb0sA== X-Received: by 2002:a05:6122:2205:b0:4e4:ecd7:ad49 with SMTP id 71dfb90a1353d-4e4f021c840mr459600e0c.2.1716497577485; Thu, 23 May 2024 13:52:57 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.52.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:52:56 -0700 (PDT) Message-ID: Date: Thu, 23 May 2024 16:52:56 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 02/12] - Move to an always available relation oracle. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch provides a basic oracle which doesn't do anything, but will still respond when queried.  This allows passes to avoid the NULL check for an oracle pointer before they do anything, and results in a slight speedup in VRP, and a slightly more significant 0.3% speedup in jump threading.. It also unifies the register and query names to nor specify what is already apparent in the parameters. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 2f80eb1feb3f92c7e9e57d4726ec52ca7d27ce92 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 30 Apr 2024 09:35:23 -0400 Subject: [PATCH 02/12] Move to an always available relation oracle. This eliminates the need to check if the relation oracle pointer is NULL before every call by providing a default oracle which does nothing. REmove unused routines, and Unify register_relation method names. * gimple-range-cache.cc (ranger_cache::dump_bb): Remove check for NULL oracle pointer. (ranger_cache::fill_block_cache): Likewise. * gimple-range-fold.cc (fur_stmt::get_phi_operand): Likewise. (fur_depend::fur_depend): Likewise. (fur_depend::register_relation): Likewise, use qury_relation. (fold_using_range::range_of_phi): Likewise. (fold_using_range::relation_fold_and_or): Likewise. * gimple-range-fold.h (fur_source::m_oracle): Delete. Oracle can be accessed dirctly via m_query now. * gimple-range-path.cc (path_range_query::path_range_query): Adjust for oracle reference pointer. (path_range_query::compute_ranges): Likewise. (jt_fur_source::jt_fur_source): Adjust for no m_oracle member. (jt_fur_source::register_relation): Do not check for NULL pointer. (jt_fur_source::query_relation): Likewise. * gimple-range.cc (gimple_ranger::gimple_ranger): Adjust for reference pointer. * value_query.cc (default_relation_oracle): New. (range_query::create_relation_oracle): Relocate from header. Ensure not being added to global query. (range_query::destroy_relation_oracle): Relocate from header. (range_query::range_query): Initailize to default oracle. (ange_query::~range_query): Call destroy_relation_oracle. * value-query.h (class range_query): Adjust prototypes. (range_query::create_relation_oracle): Move to source file. (range_query::destroy_relation_oracle): Move to source file. * value-relation.cc (relation_oracle::validate_relation): Delete. (relation_oracle::register_stmt): Rename to register_relation. (relation_oracle::register_edge): Likewise. * value-relation.h (register_stmt): Rename to register_relation and provide default function in base class. (register_edge): Likewise. (relation_oracle::query_relation): Provide default in base class. (relation_oracle::dump): Likewise. (relation_oracle::equiv_set): Likewise. (default_relation_oracle): New extenal reference. (partial_equiv_set, add_partial_equiv): Move to protected. * value-relation.h (relation_oracle::validate_relation): Delete. --- gcc/gimple-range-cache.cc | 98 +++++++++++++++++++-------------------- gcc/gimple-range-fold.cc | 22 +++------ gcc/gimple-range-fold.h | 2 - gcc/gimple-range-path.cc | 22 +++------ gcc/gimple-range.cc | 5 +- gcc/value-query.cc | 38 +++++++++++++-- gcc/value-query.h | 31 ++----------- gcc/value-relation.cc | 66 ++------------------------ gcc/value-relation.h | 32 ++++++------- 9 files changed, 119 insertions(+), 197 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index cf17a6af9db..020069fd635 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1001,8 +1001,7 @@ ranger_cache::dump_bb (FILE *f, basic_block bb) { m_gori.gori_map::dump (f, bb, false); m_on_entry.dump (f, bb); - if (m_oracle) - m_oracle->dump (f, bb); + m_oracle->dump (f, bb); } // Get the global range for NAME, and return in R. Return false if the @@ -1437,62 +1436,59 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) // See if any equivalences can refine it. // PR 109462, like 108139 below, a one way equivalence introduced // by a PHI node can also be through the definition side. Disallow it. - if (m_oracle) + tree equiv_name; + relation_kind rel; + int prec = TYPE_PRECISION (type); + FOR_EACH_PARTIAL_AND_FULL_EQUIV (m_oracle, bb, name, equiv_name, rel) { - tree equiv_name; - relation_kind rel; - int prec = TYPE_PRECISION (type); - FOR_EACH_PARTIAL_AND_FULL_EQUIV (m_oracle, bb, name, equiv_name, rel) - { - basic_block equiv_bb = gimple_bb (SSA_NAME_DEF_STMT (equiv_name)); + basic_block equiv_bb = gimple_bb (SSA_NAME_DEF_STMT (equiv_name)); - // Ignore partial equivs that are smaller than this object. - if (rel != VREL_EQ && prec > pe_to_bits (rel)) - continue; + // Ignore partial equivs that are smaller than this object. + if (rel != VREL_EQ && prec > pe_to_bits (rel)) + continue; - // Check if the equiv has any ranges calculated. - if (!m_gori.has_edge_range_p (equiv_name)) - continue; + // Check if the equiv has any ranges calculated. + if (!m_gori.has_edge_range_p (equiv_name)) + continue; - // Check if the equiv definition dominates this block - if (equiv_bb == bb || - (equiv_bb && !dominated_by_p (CDI_DOMINATORS, bb, equiv_bb))) - continue; + // Check if the equiv definition dominates this block + if (equiv_bb == bb || + (equiv_bb && !dominated_by_p (CDI_DOMINATORS, bb, equiv_bb))) + continue; - if (DEBUG_RANGE_CACHE) - { - if (rel == VREL_EQ) - fprintf (dump_file, "Checking Equivalence ("); - else - fprintf (dump_file, "Checking Partial equiv ("); - print_relation (dump_file, rel); - fprintf (dump_file, ") "); - print_generic_expr (dump_file, equiv_name, TDF_SLIM); - fprintf (dump_file, "\n"); - } - Value_Range equiv_range (TREE_TYPE (equiv_name)); - if (range_from_dom (equiv_range, equiv_name, bb, RFD_READ_ONLY)) - { - if (rel != VREL_EQ) - range_cast (equiv_range, type); - else - adjust_equivalence_range (equiv_range); + if (DEBUG_RANGE_CACHE) + { + if (rel == VREL_EQ) + fprintf (dump_file, "Checking Equivalence ("); + else + fprintf (dump_file, "Checking Partial equiv ("); + print_relation (dump_file, rel); + fprintf (dump_file, ") "); + print_generic_expr (dump_file, equiv_name, TDF_SLIM); + fprintf (dump_file, "\n"); + } + Value_Range equiv_range (TREE_TYPE (equiv_name)); + if (range_from_dom (equiv_range, equiv_name, bb, RFD_READ_ONLY)) + { + if (rel != VREL_EQ) + range_cast (equiv_range, type); + else + adjust_equivalence_range (equiv_range); - if (block_result.intersect (equiv_range)) + if (block_result.intersect (equiv_range)) + { + if (DEBUG_RANGE_CACHE) { - if (DEBUG_RANGE_CACHE) - { - if (rel == VREL_EQ) - fprintf (dump_file, "Equivalence update! : "); - else - fprintf (dump_file, "Partial equiv update! : "); - print_generic_expr (dump_file, equiv_name, TDF_SLIM); - fprintf (dump_file, " has range : "); - equiv_range.dump (dump_file); - fprintf (dump_file, " refining range to :"); - block_result.dump (dump_file); - fprintf (dump_file, "\n"); - } + if (rel == VREL_EQ) + fprintf (dump_file, "Equivalence update! : "); + else + fprintf (dump_file, "Partial equiv update! : "); + print_generic_expr (dump_file, equiv_name, TDF_SLIM); + fprintf (dump_file, " has range : "); + equiv_range.dump (dump_file); + fprintf (dump_file, " refining range to :"); + block_result.dump (dump_file); + fprintf (dump_file, "\n"); } } } diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 41b6d350c40..eeffdce0b97 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -178,10 +178,7 @@ fur_stmt::get_phi_operand (vrange &r, tree expr, edge e) relation_kind fur_stmt::query_relation (tree op1, tree op2) { - relation_oracle *oracle = m_query->oracle (); - if (!oracle) - return VREL_VARYING; - return oracle->query_relation (m_stmt, op1, op2); + return m_query->oracle ().query_relation (m_stmt, op1, op2); } // Instantiate a stmt based fur_source with a GORI object. @@ -192,10 +189,6 @@ fur_depend::fur_depend (gimple *s, gori_compute *gori, range_query *q) { gcc_checking_assert (gori); m_gori = gori; - // Set relations if there is an oracle in the range_query. - // This will enable registering of relationships as they are discovered. - m_oracle = q->oracle (); - } // Register a relation on a stmt if there is an oracle. @@ -203,8 +196,7 @@ fur_depend::fur_depend (gimple *s, gori_compute *gori, range_query *q) void fur_depend::register_relation (gimple *s, relation_kind k, tree op1, tree op2) { - if (m_oracle) - m_oracle->register_stmt (s, k, op1, op2); + m_query->oracle ().register_relation (s, k, op1, op2); } // Register a relation on an edge if there is an oracle. @@ -212,8 +204,7 @@ fur_depend::register_relation (gimple *s, relation_kind k, tree op1, tree op2) void fur_depend::register_relation (edge e, relation_kind k, tree op1, tree op2) { - if (m_oracle) - m_oracle->register_edge (e, k, op1, op2); + m_query->oracle ().register_relation (e, k, op1, op2); } // This version of fur_source will pick a range up from a list of ranges @@ -863,7 +854,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) tree single_arg = NULL_TREE; bool seen_arg = false; - relation_oracle *oracle = src.query()->oracle (); + relation_oracle *oracle = &(src.query()->oracle ()); // Start with an empty range, unioning in each argument's range. r.set_undefined (); for (x = 0; x < gimple_phi_num_args (phi); x++) @@ -884,8 +875,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) // Likewise, if the incoming PHI argument is equivalent to this // PHI definition, it provides no new info. Accumulate these ranges // in case all arguments are equivalences. - if (oracle - && oracle->query_relation (e, arg, phi_def) == VREL_EQ) + if (oracle->query_relation (e, arg, phi_def) == VREL_EQ) equiv_range.union_(arg_range); else r.union_ (arg_range); @@ -1135,7 +1125,7 @@ fold_using_range::relation_fold_and_or (irange& lhs_range, gimple *s, vrange &op2) { // No queries or already folded. - if (!src.gori () || !src.query ()->oracle () || lhs_range.singleton_p ()) + if (!src.gori () || lhs_range.singleton_p ()) return; // Only care about AND and OR expressions. diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index c7c599bfc93..1925fb899e3 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -138,8 +138,6 @@ public: tree op2) override; virtual void register_relation (edge e, relation_kind k, tree op1, tree op2) override; -protected: - relation_oracle *m_oracle; }; // This class uses ranges to fold a gimple statement producing a range for diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index ef3db10470e..cf7e0409098 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -44,7 +44,7 @@ path_range_query::path_range_query (gimple_ranger &ranger, m_ranger (ranger), m_resolve (resolve) { - m_oracle = new path_oracle (m_ranger.oracle ()); + m_oracle = new path_oracle (&(m_ranger.oracle ())); reset_path (path, dependencies); } @@ -54,7 +54,7 @@ path_range_query::path_range_query (gimple_ranger &ranger, bool resolve) m_ranger (ranger), m_resolve (resolve) { - m_oracle = new path_oracle (m_ranger.oracle ()); + m_oracle = new path_oracle (&(m_ranger.oracle ())); } path_range_query::~path_range_query () @@ -563,7 +563,7 @@ path_range_query::compute_ranges (const bitmap_head *dependencies) if (m_resolve) { path_oracle *p = get_path_oracle (); - p->reset_path (m_ranger.oracle ()); + p->reset_path (&(m_ranger.oracle ())); } if (DEBUG_SOLVER) @@ -629,11 +629,6 @@ jt_fur_source::jt_fur_source (gimple *s, gcc_checking_assert (!path.is_empty ()); m_entry = path[path.length () - 1]; - - if (dom_info_available_p (CDI_DOMINATORS)) - m_oracle = query->oracle (); - else - m_oracle = NULL; } // Ignore statement and register relation on entry to path. @@ -641,8 +636,7 @@ jt_fur_source::jt_fur_source (gimple *s, void jt_fur_source::register_relation (gimple *, relation_kind k, tree op1, tree op2) { - if (m_oracle) - m_oracle->register_relation (m_entry, k, op1, op2); + m_query->oracle ().register_relation (m_entry, k, op1, op2); } // Ignore edge and register relation on entry to path. @@ -650,20 +644,16 @@ jt_fur_source::register_relation (gimple *, relation_kind k, tree op1, tree op2) void jt_fur_source::register_relation (edge, relation_kind k, tree op1, tree op2) { - if (m_oracle) - m_oracle->register_relation (m_entry, k, op1, op2); + m_query->oracle ().register_relation (m_entry, k, op1, op2); } relation_kind jt_fur_source::query_relation (tree op1, tree op2) { - if (!m_oracle) - return VREL_VARYING; - if (TREE_CODE (op1) != SSA_NAME || TREE_CODE (op2) != SSA_NAME) return VREL_VARYING; - return m_oracle->query_relation (m_entry, op1, op2); + return m_query->oracle().query_relation (m_entry, op1, op2); } // Return the range of STMT at the end of the path being analyzed. diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 22e8add5de1..24ffd63c89b 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -43,8 +43,8 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : tracer (""), current_bb (NULL) { - // If the cache has a relation oracle, use it. - m_oracle = m_cache.oracle (); + // Share the oracle from the cache. + m_oracle = &m_cache.oracle (); if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE)) tracer.enable_trace (); m_stmt_list.create (0); @@ -67,6 +67,7 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : gimple_ranger::~gimple_ranger () { + // Restore the original oracle. m_oracle = NULL; m_stmt_list.release (); } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index b275a43b679..03ce574bcb5 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -178,15 +178,47 @@ range_query::dump (FILE *) { } +// Default oracle for all range queries. This contains no storage and thus +// can be used anywhere. +relation_oracle default_relation_oracle; + +// Create dominance based range oracle for the current query if dom info is +// available. + +void +range_query::create_relation_oracle () +{ + gcc_checking_assert (this != &global_ranges); + gcc_checking_assert (m_oracle == &default_relation_oracle); + + if (!dom_info_available_p (CDI_DOMINATORS)) + return; + m_oracle = new dom_oracle (); + gcc_checking_assert (m_oracle); +} + +// Destroy any relation oracle that was created. + +void +range_query::destroy_relation_oracle () +{ + // m_oracle can be NULL if a derived range_query class took care of + // disposing its own oracle. + if (m_oracle && m_oracle != &default_relation_oracle) + { + delete m_oracle; + m_oracle = &default_relation_oracle; + } +} + range_query::range_query () { - m_oracle = NULL; + m_oracle = &default_relation_oracle; } range_query::~range_query () { - if (m_oracle) - destroy_relation_oracle (); + destroy_relation_oracle (); } // This routine will invoke the equivalent of range_of_expr on diff --git a/gcc/value-query.h b/gcc/value-query.h index 9df89905ace..ed355bedfa8 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -75,12 +75,12 @@ public: virtual bool range_on_entry (vrange &r, basic_block bb, tree expr); virtual bool range_on_exit (vrange &r, basic_block bb, tree expr); - inline relation_oracle *oracle () const { return m_oracle; } + inline class relation_oracle &oracle () const { return *m_oracle; } + void create_relation_oracle (); + void destroy_relation_oracle (); virtual void dump (FILE *); - void create_relation_oracle (); - void destroy_relation_oracle (); protected: bool get_tree_range (vrange &v, tree expr, gimple *stmt, basic_block bbentry = NULL, basic_block bbexit = NULL); @@ -118,29 +118,4 @@ get_range_query (const struct function *fun) // Query the global range of NAME in function F. Default to cfun. extern void gimple_range_global (vrange &v, tree name, struct function *f = cfun); - -// Create dominance based range oracle for the current query if dom info is -// available. - -inline void -range_query::create_relation_oracle () -{ - if (!dom_info_available_p (CDI_DOMINATORS)) - return; - gcc_checking_assert (m_oracle == NULL); - m_oracle = new dom_oracle (); -} - -// Destroy any relation oracle that was created. - -inline void -range_query::destroy_relation_oracle () -{ - if (m_oracle != NULL) - { - delete m_oracle; - m_oracle = NULL; - } -} - #endif // GCC_QUERY_H diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index d1081b3b3f5..fac15613945 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -208,66 +208,6 @@ static const tree_code relation_to_code [VREL_LAST] = { ERROR_MARK, ERROR_MARK, LT_EXPR, LE_EXPR, GT_EXPR, GE_EXPR, EQ_EXPR, NE_EXPR }; -// This routine validates that a relation can be applied to a specific set of -// ranges. In particular, floating point x == x may not be true if the NaN bit -// is set in the range. Symbolically the oracle will determine x == x, -// but specific range instances may override this. -// To verify, attempt to fold the relation using the supplied ranges. -// One would expect [1,1] to be returned, anything else means there is something -// in the range preventing the relation from applying. -// If there is no mechanism to verify, assume the relation is acceptable. - -relation_kind -relation_oracle::validate_relation (relation_kind rel, vrange &op1, vrange &op2) -{ - // If there is no mapping to a tree code, leave the relation as is. - tree_code code = relation_to_code [rel]; - if (code == ERROR_MARK) - return rel; - - // Undefined ranges cannot be checked either. - if (op1.undefined_p () || op2.undefined_p ()) - return rel; - - tree t1 = op1.type (); - tree t2 = op2.type (); - - // If the range types are not compatible, no relation can exist. - if (!range_compatible_p (t1, t2)) - return VREL_VARYING; - - // If there is no handler, leave the relation as is. - range_op_handler handler (code); - if (!handler) - return rel; - - // If the relation cannot be folded for any reason, leave as is. - Value_Range result (boolean_type_node); - if (!handler.fold_range (result, boolean_type_node, op1, op2, - relation_trio::op1_op2 (rel))) - return rel; - - // The expression op1 REL op2 using REL should fold to [1,1]. - // Any other result means the relation is not verified to be true. - if (result.varying_p () || result.zero_p ()) - return VREL_VARYING; - - return rel; -} - -// If no range is available, create a varying range for each SSA name and -// verify. - -relation_kind -relation_oracle::validate_relation (relation_kind rel, tree ssa1, tree ssa2) -{ - Value_Range op1, op2; - op1.set_varying (TREE_TYPE (ssa1)); - op2.set_varying (TREE_TYPE (ssa2)); - - return validate_relation (rel, op1, op2); -} - // Given an equivalence set EQUIV, set all the bits in B that are still valid // members of EQUIV in basic block BB. @@ -1058,8 +998,8 @@ dom_oracle::~dom_oracle () // Register relation K between ssa_name OP1 and OP2 on STMT. void -relation_oracle::register_stmt (gimple *stmt, relation_kind k, tree op1, - tree op2) +relation_oracle::register_relation (gimple *stmt, relation_kind k, tree op1, + tree op2) { gcc_checking_assert (TREE_CODE (op1) == SSA_NAME); gcc_checking_assert (TREE_CODE (op2) == SSA_NAME); @@ -1106,7 +1046,7 @@ relation_oracle::register_stmt (gimple *stmt, relation_kind k, tree op1, // Register relation K between ssa_name OP1 and OP2 on edge E. void -relation_oracle::register_edge (edge e, relation_kind k, tree op1, tree op2) +relation_oracle::register_relation (edge e, relation_kind k, tree op1, tree op2) { gcc_checking_assert (TREE_CODE (op1) == SSA_NAME); gcc_checking_assert (TREE_CODE (op2) == SSA_NAME); diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 5adf736cf41..528f00aecbb 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -98,37 +98,37 @@ class relation_oracle { public: virtual ~relation_oracle () { } - // register a relation between 2 ssa names at a stmt. - void register_stmt (gimple *, relation_kind, tree, tree); - // register a relation between 2 ssa names on an edge. - void register_edge (edge, relation_kind, tree, tree); - // register a relation between 2 ssa names in a basic block. - virtual void register_relation (basic_block, relation_kind, tree, tree) = 0; + // register a relation between 2 ssa names. + void register_relation (gimple *, relation_kind, tree, tree); + void register_relation (edge, relation_kind, tree, tree); + virtual void register_relation (basic_block, relation_kind, tree, tree) { } + // Query if there is any relation between SSA1 and SSA2. - virtual relation_kind query_relation (basic_block, tree, tree) = 0; relation_kind query_relation (gimple *s, tree ssa1, tree ssa2); relation_kind query_relation (edge e, tree ssa1, tree ssa2); + virtual relation_kind query_relation (basic_block, tree, tree) + { return VREL_VARYING; } - relation_kind validate_relation (relation_kind, tree, tree); - relation_kind validate_relation (relation_kind, vrange &, vrange &); - - virtual void dump (FILE *, basic_block) const = 0; - virtual void dump (FILE *) const = 0; + virtual void dump (FILE *, basic_block) const { } + virtual void dump (FILE *) const { } void debug () const; protected: friend class equiv_relation_iterator; // Return equivalency set for an SSA name in a basic block. - virtual const_bitmap equiv_set (tree, basic_block) = 0; + virtual const_bitmap equiv_set (tree, basic_block) { return NULL; } // Return partial equivalency record for an SSA name. virtual const class pe_slice *partial_equiv_set (tree) { return NULL; } void valid_equivs (bitmap b, const_bitmap equivs, basic_block bb); // Query for a relation between two equivalency sets in a basic block. virtual relation_kind query_relation (basic_block, const_bitmap, - const_bitmap) = 0; + const_bitmap) { return VREL_VARYING; } friend class path_oracle; }; +// Instance with no storage used for default queries with no active oracle. +extern relation_oracle default_relation_oracle; + // This class represents an equivalency set, and contains a link to the next // one in the list to be searched. @@ -162,11 +162,9 @@ public: ~equiv_oracle (); const_bitmap equiv_set (tree ssa, basic_block bb) final override; - const pe_slice *partial_equiv_set (tree name) final override; void register_relation (basic_block bb, relation_kind k, tree ssa1, tree ssa2) override; - void add_partial_equiv (relation_kind, tree, tree); relation_kind partial_equiv (tree ssa1, tree ssa2, tree *base = NULL) const; relation_kind query_relation (basic_block, tree, tree) override; relation_kind query_relation (basic_block, const_bitmap, const_bitmap) @@ -175,6 +173,8 @@ public: void dump (FILE *f) const override; protected: + void add_partial_equiv (relation_kind, tree, tree); + const pe_slice *partial_equiv_set (tree name) final override; inline bool has_equiv_p (unsigned v) { return bitmap_bit_p (m_equiv_set, v); } bitmap_obstack m_bitmaps; struct obstack m_chain_obstack; -- 2.41.0 From patchwork Thu May 23 20:53:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938589 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=F0KukrOw; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgRY2sM2z20KL for ; Fri, 24 May 2024 06:55:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A33573846459 for ; Thu, 23 May 2024 20:55:19 +0000 (GMT) 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 EC6573865C2B for ; Thu, 23 May 2024 20:53:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC6573865C2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EC6573865C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497595; cv=none; b=CIZn14+wJlAz0GEX/3AcUJYLNfRYbXJlPShMhtXHrdoAAoLCJMwNRsKHlZdAZpW8HFUjHOI+EgDjJtqI/BiO4DXV7AooE4jMoXCuVmoTrZnCFIFJ1onJoK2K2U6fEmCyOL0DA5tNWFa0fFeV3jfiCNfODvxa/UbA/bi80YprFIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497595; c=relaxed/simple; bh=aOuNtZkojhUqP/NpZyDFUvfAJTmrMbNqEIJoazz4KLs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=QIbrHfNzLXSXysc2t3kvyFHhs1r0KNmKl+qDNVvAxmmxHK2RD2oYB/NaHGHZm49UFxeSjgPXUkpF+Wq6hErgGzJfLlcMBu7ew5weg01t4goPb2LDzmSnfIvsH2x0E0PEz8J4Weqw8dwh5vOh07Mt64vrVcti76fZ/KL/yQNEypA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=u5nm1eW+Vhy97En9o+LNMx/EN/emw+ZTPMv3ansEHbg=; b=F0KukrOw8NZXOcRm3NhJzP/1nI5wHv3nGyVmsUWkf+6Vc3wPeMTKlRqLXnnhCApBAJTLs2 lcfd8YVIS+v2/rW2uXYDPVXqxJM3vPZRXvSrP8JL4Bm0gZ6uJXQHza3GDbCWfcNzMFCIRP rkP99PVCHKetqLVVLVcYtxZfwyRaHz8= Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-299-4bJMoGmHOdCoWD1hN-VUqQ-1; Thu, 23 May 2024 16:53:09 -0400 X-MC-Unique: 4bJMoGmHOdCoWD1hN-VUqQ-1 Received: by mail-ot1-f72.google.com with SMTP id 46e09a7af769-6f1190504b8so1971488a34.1 for ; Thu, 23 May 2024 13:53:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497588; x=1717102388; 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=IWMQoT2dSkKvjHdRoQNjpkTr/qPRmkBBl3axOiTORu0=; b=Vb7Mo25Op1812VVSh56Fw2mZrQjCeA6gX3ZaH8v5OWSuahMPgYw3gWvjTxwFWD3aGK A3sMDWJ1lUAx83pvfN7Md7qeQ/shFW2os7gOSt5OHYIYQlUk7W0XA1tLXYezA+d2xxoB d7n2fk9wvFRpFVLXHq073BcNEbKGtFXNPund6anO4LTvyEKroTNm2MCAI/oYecZ0/M7I QbKCE1x1sR8SaAPpZc2k6oUNfqm0YxcYGKssvUUntGhDRBmOzWBI0cEWWap06W8/SclD 6VoDMTxVl5VIsgb5HSU78LYSFoVC2XUYrxMn+P17mAWYjd/bP+7Ep8Qs3UnhEluPv1LY JipQ== X-Gm-Message-State: AOJu0YzUJY///kKcIUMonFrxRzphtSL4InRs1GKwVL2yF+bntiMAKUjH Je5LI8xUZxJ3TqQtZCwSdYHAJLkQ8pU31mZwWQ4Dr1aCuhqw3EwsCwty2tSLwSV9ovCWYoIHFmY TKk3bEzfz4hMtKX7tau/sxkYLbJzTUwPvZqTAhaMU6A4wuLRWSGTRHV1vJvmF+A9t4jNMkloy33 MGVT6C2FB4i+Y2QB+QMjBQYqZnbo5lCSUOmL9dqLs= X-Received: by 2002:a05:6808:6043:b0:3c9:9294:8d8a with SMTP id 5614622812f47-3d1a7648051mr463571b6e.36.1716497588428; Thu, 23 May 2024 13:53:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHoZNkOSUdCHfJHWq3a+lcBJXgi7mgXv7EJzDKgHkri/cmes1Ij8vVLNEDN4B5LlONYbSxcng== X-Received: by 2002:a05:6808:6043:b0:3c9:9294:8d8a with SMTP id 5614622812f47-3d1a7648051mr463544b6e.36.1716497587788; Thu, 23 May 2024 13:53:07 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:07 -0700 (PDT) Message-ID: <40e73fc3-3171-4ca8-9c78-b09d73c75473@redhat.com> Date: Thu, 23 May 2024 16:53:06 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 03/12] - Rename relation oracle and API. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-10.9 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Could have been combined with the previous patch, but eh.... This changes the relation oracle accessed via a range_query to the name 'relation', as there are more oracles coming, and this is more description.  it also renames the registering and querying routines to have less redundant rext. relation->register_relation and relation->query_relation seem a bit texty.  they are now  relation.record () and relation.query () Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 3a5b702c4082950d614fe12a066609da23363246 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 17 May 2024 10:18:39 -0400 Subject: [PATCH 03/12] Rename relation oracle and API. With more oracles incoming, rename the range_query oracle () method to relation (), and remove the redundant 'relation' text from register and query methods, resulting in calls that look like: relation ()->record (...) and relation ()->query (...) * gimple-range-cache.cc (ranger_cache::dump_bb): Use m_relation. (ranger_cache::fill_block_cache): Likewise * gimple-range-fold.cc (fur_stmt::get_phi_operand): Use new names. (fur_depend::register_relation): Likewise. (fold_using_range::range_of_phi): Likewise. * gimple-range-path.cc (path_range_query::path_range_query): Likewise. (path_range_query::~path_range_query): Likewise. (ath_range_query::compute_ranges): Likewise. (jt_fur_source::register_relation): Likewise. (jt_fur_source::query_relation): Likewise. (path_range_query::maybe_register_phi_relation): Likewise. * gimple-range-path.h (get_path_oracle): Likewise. * value-query.cc (range_query::create_relation_oracle): Likewise. (range_query::destroy_relation_oracle): Likewise. (range_query::share_oracles): Likewise. (range_query::range_query): Likewise. * value-query.h (value_query::relation): Rename from oracle. (m_relation): Rename from m_oracle. * value-relation.cc (relation_oracle::query): Rename from query_relation. (equiv_oracle::query): Likewise. (equiv_oracle::record): Rename from register_relation. (relation_oracle::record): Likewise. (dom_oracle::record): Likewise. (dom_oracle::query): Rename from query_relation. (path_oracle::record): Rename from register_relation. (path_oracle::query): Rename from query_relation. * value-relation.h (*::record): Rename from register_relation. (*::query): Rename from query_relation. --- gcc/gimple-range-cache.cc | 4 +-- gcc/gimple-range-fold.cc | 10 ++++---- gcc/gimple-range-path.cc | 18 +++++++------- gcc/gimple-range-path.h | 2 +- gcc/gimple-range.cc | 4 +-- gcc/value-query.cc | 16 ++++++------ gcc/value-query.h | 4 +-- gcc/value-relation.cc | 51 ++++++++++++++++++--------------------- gcc/value-relation.h | 39 +++++++++++++----------------- 9 files changed, 69 insertions(+), 79 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 020069fd635..55277ea8af1 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -1001,7 +1001,7 @@ ranger_cache::dump_bb (FILE *f, basic_block bb) { m_gori.gori_map::dump (f, bb, false); m_on_entry.dump (f, bb); - m_oracle->dump (f, bb); + m_relation->dump (f, bb); } // Get the global range for NAME, and return in R. Return false if the @@ -1439,7 +1439,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) tree equiv_name; relation_kind rel; int prec = TYPE_PRECISION (type); - FOR_EACH_PARTIAL_AND_FULL_EQUIV (m_oracle, bb, name, equiv_name, rel) + FOR_EACH_PARTIAL_AND_FULL_EQUIV (m_relation, bb, name, equiv_name, rel) { basic_block equiv_bb = gimple_bb (SSA_NAME_DEF_STMT (equiv_name)); diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index eeffdce0b97..357a1beabd1 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -178,7 +178,7 @@ fur_stmt::get_phi_operand (vrange &r, tree expr, edge e) relation_kind fur_stmt::query_relation (tree op1, tree op2) { - return m_query->oracle ().query_relation (m_stmt, op1, op2); + return m_query->relation ().query (m_stmt, op1, op2); } // Instantiate a stmt based fur_source with a GORI object. @@ -196,7 +196,7 @@ fur_depend::fur_depend (gimple *s, gori_compute *gori, range_query *q) void fur_depend::register_relation (gimple *s, relation_kind k, tree op1, tree op2) { - m_query->oracle ().register_relation (s, k, op1, op2); + m_query->relation ().record (s, k, op1, op2); } // Register a relation on an edge if there is an oracle. @@ -204,7 +204,7 @@ fur_depend::register_relation (gimple *s, relation_kind k, tree op1, tree op2) void fur_depend::register_relation (edge e, relation_kind k, tree op1, tree op2) { - m_query->oracle ().register_relation (e, k, op1, op2); + m_query->relation ().record (e, k, op1, op2); } // This version of fur_source will pick a range up from a list of ranges @@ -854,7 +854,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) tree single_arg = NULL_TREE; bool seen_arg = false; - relation_oracle *oracle = &(src.query()->oracle ()); + relation_oracle *oracle = &(src.query()->relation ()); // Start with an empty range, unioning in each argument's range. r.set_undefined (); for (x = 0; x < gimple_phi_num_args (phi); x++) @@ -875,7 +875,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) // Likewise, if the incoming PHI argument is equivalent to this // PHI definition, it provides no new info. Accumulate these ranges // in case all arguments are equivalences. - if (oracle->query_relation (e, arg, phi_def) == VREL_EQ) + if (oracle->query (e, arg, phi_def) == VREL_EQ) equiv_range.union_(arg_range); else r.union_ (arg_range); diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index cf7e0409098..e35bec0e50d 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -44,7 +44,7 @@ path_range_query::path_range_query (gimple_ranger &ranger, m_ranger (ranger), m_resolve (resolve) { - m_oracle = new path_oracle (&(m_ranger.oracle ())); + m_relation = new path_oracle (&(m_ranger.relation ())); reset_path (path, dependencies); } @@ -54,13 +54,13 @@ path_range_query::path_range_query (gimple_ranger &ranger, bool resolve) m_ranger (ranger), m_resolve (resolve) { - m_oracle = new path_oracle (&(m_ranger.oracle ())); + m_relation = new path_oracle (&(m_ranger.relation ())); } path_range_query::~path_range_query () { - delete m_oracle; - m_oracle = NULL; + delete m_relation; + m_relation = NULL; } // Return TRUE if NAME is an exit dependency for the path. @@ -563,7 +563,7 @@ path_range_query::compute_ranges (const bitmap_head *dependencies) if (m_resolve) { path_oracle *p = get_path_oracle (); - p->reset_path (&(m_ranger.oracle ())); + p->reset_path (&(m_ranger.relation ())); } if (DEBUG_SOLVER) @@ -636,7 +636,7 @@ jt_fur_source::jt_fur_source (gimple *s, void jt_fur_source::register_relation (gimple *, relation_kind k, tree op1, tree op2) { - m_query->oracle ().register_relation (m_entry, k, op1, op2); + m_query->relation ().record (m_entry, k, op1, op2); } // Ignore edge and register relation on entry to path. @@ -644,7 +644,7 @@ jt_fur_source::register_relation (gimple *, relation_kind k, tree op1, tree op2) void jt_fur_source::register_relation (edge, relation_kind k, tree op1, tree op2) { - m_query->oracle ().register_relation (m_entry, k, op1, op2); + m_query->relation ().record (m_entry, k, op1, op2); } relation_kind @@ -653,7 +653,7 @@ jt_fur_source::query_relation (tree op1, tree op2) if (TREE_CODE (op1) != SSA_NAME || TREE_CODE (op2) != SSA_NAME) return VREL_VARYING; - return m_query->oracle().query_relation (m_entry, op1, op2); + return m_query->relation ().query (m_entry, op1, op2); } // Return the range of STMT at the end of the path being analyzed. @@ -707,7 +707,7 @@ path_range_query::maybe_register_phi_relation (gphi *phi, edge e) fprintf (dump_file, "maybe_register_phi_relation in bb%d:", bb->index); get_path_oracle ()->killing_def (result); - m_oracle->register_relation (entry_bb (), VREL_EQ, arg, result); + m_relation->record (entry_bb (), VREL_EQ, arg, result); } // Compute relations for each PHI in BB. For example: diff --git a/gcc/gimple-range-path.h b/gcc/gimple-range-path.h index f9aba179949..f36a10eb824 100644 --- a/gcc/gimple-range-path.h +++ b/gcc/gimple-range-path.h @@ -51,7 +51,7 @@ private: void compute_exit_dependencies (bitmap_head *dependencies); bool defined_outside_path (tree name); void range_on_path_entry (vrange &r, tree name); - path_oracle *get_path_oracle () { return (path_oracle *)m_oracle; } + path_oracle *get_path_oracle () { return (path_oracle *)m_relation; } // Cache manipulation. bool get_cache (vrange &r, tree name); diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 24ffd63c89b..9664300a80b 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -44,7 +44,7 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : current_bb (NULL) { // Share the oracle from the cache. - m_oracle = &m_cache.oracle (); + m_relation = &m_cache.relation (); if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE)) tracer.enable_trace (); m_stmt_list.create (0); @@ -68,7 +68,7 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : gimple_ranger::~gimple_ranger () { // Restore the original oracle. - m_oracle = NULL; + m_relation = NULL; m_stmt_list.release (); } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index 03ce574bcb5..db64a95a284 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -189,12 +189,12 @@ void range_query::create_relation_oracle () { gcc_checking_assert (this != &global_ranges); - gcc_checking_assert (m_oracle == &default_relation_oracle); + gcc_checking_assert (m_relation == &default_relation_oracle); if (!dom_info_available_p (CDI_DOMINATORS)) return; - m_oracle = new dom_oracle (); - gcc_checking_assert (m_oracle); + m_relation = new dom_oracle (); + gcc_checking_assert (m_relation); } // Destroy any relation oracle that was created. @@ -202,18 +202,18 @@ range_query::create_relation_oracle () void range_query::destroy_relation_oracle () { - // m_oracle can be NULL if a derived range_query class took care of + // m_relation can be NULL if a derived range_query class took care of // disposing its own oracle. - if (m_oracle && m_oracle != &default_relation_oracle) + if (m_relation && m_relation != &default_relation_oracle) { - delete m_oracle; - m_oracle = &default_relation_oracle; + delete m_relation; + m_relation = &default_relation_oracle; } } range_query::range_query () { - m_oracle = &default_relation_oracle; + m_relation = &default_relation_oracle; } range_query::~range_query () diff --git a/gcc/value-query.h b/gcc/value-query.h index ed355bedfa8..a8688a099fa 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -75,7 +75,7 @@ public: virtual bool range_on_entry (vrange &r, basic_block bb, tree expr); virtual bool range_on_exit (vrange &r, basic_block bb, tree expr); - inline class relation_oracle &oracle () const { return *m_oracle; } + inline class relation_oracle &relation () const { return *m_relation; } void create_relation_oracle (); void destroy_relation_oracle (); @@ -87,7 +87,7 @@ protected: bool invoke_range_of_expr (vrange &v, tree expr, gimple *stmt, basic_block bbentry, basic_block bbexit); bool get_arith_expr_range (vrange &r, tree expr, gimple *stmt); - relation_oracle *m_oracle; + relation_oracle *m_relation; }; // Global ranges for SSA names using SSA_NAME_RANGE_INFO. diff --git a/gcc/value-relation.cc b/gcc/value-relation.cc index fac15613945..d7bc1b72558 100644 --- a/gcc/value-relation.cc +++ b/gcc/value-relation.cc @@ -233,11 +233,11 @@ relation_oracle::valid_equivs (bitmap b, const_bitmap equivs, basic_block bb) // the definitions have been processed and any relations have be created. relation_kind -relation_oracle::query_relation (gimple *s, tree ssa1, tree ssa2) +relation_oracle::query (gimple *s, tree ssa1, tree ssa2) { if (TREE_CODE (ssa1) != SSA_NAME || TREE_CODE (ssa2) != SSA_NAME) return VREL_VARYING; - return query_relation (gimple_bb (s), ssa1, ssa2); + return query (gimple_bb (s), ssa1, ssa2); } // Return any known relation between SSA1 and SSA2 on edge E. @@ -245,7 +245,7 @@ relation_oracle::query_relation (gimple *s, tree ssa1, tree ssa2) // the definitions have been processed and any relations have be created. relation_kind -relation_oracle::query_relation (edge e, tree ssa1, tree ssa2) +relation_oracle::query (edge e, tree ssa1, tree ssa2) { basic_block bb; if (TREE_CODE (ssa1) != SSA_NAME || TREE_CODE (ssa2) != SSA_NAME) @@ -259,7 +259,7 @@ relation_oracle::query_relation (edge e, tree ssa1, tree ssa2) else bb = e->dest; - return query_relation (bb, ssa1, ssa2); + return query (bb, ssa1, ssa2); } // ------------------------------------------------------------------------- @@ -478,7 +478,7 @@ equiv_oracle::equiv_set (tree ssa, basic_block bb) // Query if there is a relation (equivalence) between 2 SSA_NAMEs. relation_kind -equiv_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) +equiv_oracle::query (basic_block bb, tree ssa1, tree ssa2) { // If the 2 ssa names share the same equiv set, they are equal. if (equiv_set (ssa1, bb) == equiv_set (ssa2, bb)) @@ -491,8 +491,8 @@ equiv_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) // Query if there is a relation (equivalence) between 2 SSA_NAMEs. relation_kind -equiv_oracle::query_relation (basic_block bb ATTRIBUTE_UNUSED, const_bitmap e1, - const_bitmap e2) +equiv_oracle::query (basic_block bb ATTRIBUTE_UNUSED, const_bitmap e1, + const_bitmap e2) { // If the 2 ssa names share the same equiv set, they are equal. if (bitmap_equal_p (e1, e2)) @@ -624,8 +624,7 @@ equiv_oracle::register_initial_def (tree ssa) // containing all the ssa_names in this basic block. void -equiv_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, - tree ssa2) +equiv_oracle::record (basic_block bb, relation_kind k, tree ssa1, tree ssa2) { // Process partial equivalencies. if (relation_partial_equiv_p (k)) @@ -998,8 +997,7 @@ dom_oracle::~dom_oracle () // Register relation K between ssa_name OP1 and OP2 on STMT. void -relation_oracle::register_relation (gimple *stmt, relation_kind k, tree op1, - tree op2) +relation_oracle::record (gimple *stmt, relation_kind k, tree op1, tree op2) { gcc_checking_assert (TREE_CODE (op1) == SSA_NAME); gcc_checking_assert (TREE_CODE (op2) == SSA_NAME); @@ -1040,13 +1038,13 @@ relation_oracle::register_relation (gimple *stmt, relation_kind k, tree op1, return; } } - register_relation (gimple_bb (stmt), k, op1, op2); + record (gimple_bb (stmt), k, op1, op2); } // Register relation K between ssa_name OP1 and OP2 on edge E. void -relation_oracle::register_relation (edge e, relation_kind k, tree op1, tree op2) +relation_oracle::record (edge e, relation_kind k, tree op1, tree op2) { gcc_checking_assert (TREE_CODE (op1) == SSA_NAME); gcc_checking_assert (TREE_CODE (op2) == SSA_NAME); @@ -1064,7 +1062,7 @@ relation_oracle::register_relation (edge e, relation_kind k, tree op1, tree op2) fprintf (dump_file, " on (%d->%d)\n", e->src->index, e->dest->index); } - register_relation (e->dest, k, op1, op2); + record (e->dest, k, op1, op2); } // Register relation K between OP! and OP2 in block BB. @@ -1072,8 +1070,7 @@ relation_oracle::register_relation (edge e, relation_kind k, tree op1, tree op2) // tree to merge with. void -dom_oracle::register_relation (basic_block bb, relation_kind k, tree op1, - tree op2) +dom_oracle::record (basic_block bb, relation_kind k, tree op1, tree op2) { // If the 2 ssa_names are the same, do nothing. An equivalence is implied, // and no other relation makes sense. @@ -1082,7 +1079,7 @@ dom_oracle::register_relation (basic_block bb, relation_kind k, tree op1, // Equivalencies are handled by the equivalence oracle. if (relation_equiv_p (k)) - equiv_oracle::register_relation (bb, k, op1, op2); + equiv_oracle::record (bb, k, op1, op2); else { // if neither op1 nor op2 are in a relation before this is registered, @@ -1283,8 +1280,7 @@ dom_oracle::find_relation_block (unsigned bb, const_bitmap b1, // and B2, starting with block BB. relation_kind -dom_oracle::query_relation (basic_block bb, const_bitmap b1, - const_bitmap b2) +dom_oracle::query (basic_block bb, const_bitmap b1, const_bitmap b2) { relation_kind r; if (bitmap_equal_p (b1, b2)) @@ -1371,7 +1367,7 @@ dom_oracle::find_relation_dom (basic_block bb, unsigned v1, unsigned v2) const // dominator of BB relation_kind -dom_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) +dom_oracle::query (basic_block bb, tree ssa1, tree ssa2) { relation_kind kind; unsigned v1 = SSA_NAME_VERSION (ssa1); @@ -1401,7 +1397,7 @@ dom_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) return kind; // Query using the equivalence sets. - kind = query_relation (bb, equiv1, equiv2); + kind = query (bb, equiv1, equiv2); return kind; } @@ -1565,8 +1561,7 @@ path_oracle::killing_def (tree ssa) // querying from BB. void -path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, - tree ssa2) +path_oracle::record (basic_block bb, relation_kind k, tree ssa1, tree ssa2) { // If the 2 ssa_names are the same, do nothing. An equivalence is implied, // and no other relation makes sense. @@ -1581,7 +1576,7 @@ path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, fprintf (dump_file, " (root: bb%d)\n", bb->index); } - relation_kind curr = query_relation (bb, ssa1, ssa2); + relation_kind curr = query (bb, ssa1, ssa2); if (curr != VREL_VARYING) k = relation_intersect (curr, k); @@ -1604,7 +1599,7 @@ path_oracle::register_relation (basic_block bb, relation_kind k, tree ssa1, // starting at block BB. relation_kind -path_oracle::query_relation (basic_block bb, const_bitmap b1, const_bitmap b2) +path_oracle::query (basic_block bb, const_bitmap b1, const_bitmap b2) { if (bitmap_equal_p (b1, b2)) return VREL_EQ; @@ -1618,7 +1613,7 @@ path_oracle::query_relation (basic_block bb, const_bitmap b1, const_bitmap b2) return k; if (k == VREL_VARYING && m_root) - k = m_root->query_relation (bb, b1, b2); + k = m_root->query (bb, b1, b2); return k; } @@ -1627,7 +1622,7 @@ path_oracle::query_relation (basic_block bb, const_bitmap b1, const_bitmap b2) // starting at block BB. relation_kind -path_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) +path_oracle::query (basic_block bb, tree ssa1, tree ssa2) { unsigned v1 = SSA_NAME_VERSION (ssa1); unsigned v2 = SSA_NAME_VERSION (ssa2); @@ -1640,7 +1635,7 @@ path_oracle::query_relation (basic_block bb, tree ssa1, tree ssa2) if (bitmap_bit_p (equiv_1, v2) && bitmap_bit_p (equiv_2, v1)) return VREL_EQ; - return query_relation (bb, equiv_1, equiv_2); + return query (bb, equiv_1, equiv_2); } // Reset any relations registered on this path. ORACLE is the root diff --git a/gcc/value-relation.h b/gcc/value-relation.h index 528f00aecbb..cf009e6aa19 100644 --- a/gcc/value-relation.h +++ b/gcc/value-relation.h @@ -100,15 +100,14 @@ public: virtual ~relation_oracle () { } // register a relation between 2 ssa names. - void register_relation (gimple *, relation_kind, tree, tree); - void register_relation (edge, relation_kind, tree, tree); - virtual void register_relation (basic_block, relation_kind, tree, tree) { } + void record (gimple *, relation_kind, tree, tree); + void record (edge, relation_kind, tree, tree); + virtual void record (basic_block, relation_kind, tree, tree) { } // Query if there is any relation between SSA1 and SSA2. - relation_kind query_relation (gimple *s, tree ssa1, tree ssa2); - relation_kind query_relation (edge e, tree ssa1, tree ssa2); - virtual relation_kind query_relation (basic_block, tree, tree) - { return VREL_VARYING; } + relation_kind query (gimple *s, tree ssa1, tree ssa2); + relation_kind query (edge e, tree ssa1, tree ssa2); + virtual relation_kind query (basic_block, tree, tree) { return VREL_VARYING; } virtual void dump (FILE *, basic_block) const { } virtual void dump (FILE *) const { } @@ -121,8 +120,8 @@ protected: virtual const class pe_slice *partial_equiv_set (tree) { return NULL; } void valid_equivs (bitmap b, const_bitmap equivs, basic_block bb); // Query for a relation between two equivalency sets in a basic block. - virtual relation_kind query_relation (basic_block, const_bitmap, - const_bitmap) { return VREL_VARYING; } + virtual relation_kind query (basic_block, const_bitmap, const_bitmap) + { return VREL_VARYING; } friend class path_oracle; }; @@ -162,13 +161,11 @@ public: ~equiv_oracle (); const_bitmap equiv_set (tree ssa, basic_block bb) final override; - void register_relation (basic_block bb, relation_kind k, tree ssa1, - tree ssa2) override; + void record (basic_block bb, relation_kind k, tree ssa1, tree ssa2) override; relation_kind partial_equiv (tree ssa1, tree ssa2, tree *base = NULL) const; - relation_kind query_relation (basic_block, tree, tree) override; - relation_kind query_relation (basic_block, const_bitmap, const_bitmap) - override; + relation_kind query (basic_block, tree, tree) override; + relation_kind query (basic_block, const_bitmap, const_bitmap) override; void dump (FILE *f, basic_block bb) const override; void dump (FILE *f) const override; @@ -222,13 +219,12 @@ public: dom_oracle (); ~dom_oracle (); - void register_relation (basic_block bb, relation_kind k, tree op1, tree op2) + void record (basic_block bb, relation_kind k, tree op1, tree op2) final override; - relation_kind query_relation (basic_block bb, tree ssa1, tree ssa2) + relation_kind query (basic_block bb, tree ssa1, tree ssa2) final override; + relation_kind query (basic_block bb, const_bitmap b1, const_bitmap b2) final override; - relation_kind query_relation (basic_block bb, const_bitmap b1, - const_bitmap b2) final override; void dump (FILE *f, basic_block bb) const final override; void dump (FILE *f) const final override; @@ -269,11 +265,10 @@ public: path_oracle (relation_oracle *oracle = NULL); ~path_oracle (); const_bitmap equiv_set (tree, basic_block) final override; - void register_relation (basic_block, relation_kind, tree, tree) final override; + void record (basic_block, relation_kind, tree, tree) final override; void killing_def (tree); - relation_kind query_relation (basic_block, tree, tree) final override; - relation_kind query_relation (basic_block, const_bitmap, const_bitmap) - final override; + relation_kind query (basic_block, tree, tree) final override; + relation_kind query (basic_block, const_bitmap, const_bitmap) final override; void reset_path (relation_oracle *oracle = NULL); void set_root_oracle (relation_oracle *oracle) { m_root = oracle; } void dump (FILE *, basic_block) const final override; -- 2.41.0 From patchwork Thu May 23 20:53:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938588 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HdFJ64lP; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgRW1Yfcz20KL for ; Fri, 24 May 2024 06:55:19 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 516F93846459 for ; Thu, 23 May 2024 20:55:17 +0000 (GMT) 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 ESMTPS id 6A7AA3849783 for ; Thu, 23 May 2024 20:53:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6A7AA3849783 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6A7AA3849783 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497597; cv=none; b=p5joabIvoUjM9OmVeWYQa/NZHdzUyfbzz/kils8WjrISZBnu12TdyhP+2ktKLSFShevQnefkvh8q1TLtwg/AR3RsTVhQigiy86TctfUi0vyrj41cG9Yw4Dgl5N+a1nDR+IvQD9OMuk8+mWoltJzcBtlSsZ3+J8oicsw8ZN7zcB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497597; c=relaxed/simple; bh=0n6cI3n1VwJhxG5XAhMKBrugtKd/FsXD06OE5qMGeMU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=mgPdxzcA4rxHjEtR0+b+41ODSDRPlhA8mLgiD+D4fcepvP+P1dqUhFaxy5N9HPoC9BP/2g/ea0iSoZwtmT6vaj7nM4CwXz3HL32O8yWq8Ty3SrFAJsaV9dviVdlvaR/ipW5tXP33RkCKdn1b3EdqwFeqrqo8hMuxzWnDSyvNFYY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=25iQwKLg+aQ9orJqzFRZCEBsqZL+wR1Sgnk31K0KkC8=; b=HdFJ64lPlkNglAJzFw0uAfQq6KKHhU7fsDeQvI0tiwMpB0OHqSDiqGUasAs+8kCTdNazgP KwybHGqcbZCF254iFGb01V1DRU4t8P8W2w1xJVrvjrddliSJwf7FZHWQAgtHhOj++F4OiO AW/bf01p+93l2YXs/nwCqWkVS4ATkiI= Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-592-eoQ83FYeP0qa2Bcv_FIrdg-1; Thu, 23 May 2024 16:53:13 -0400 X-MC-Unique: eoQ83FYeP0qa2Bcv_FIrdg-1 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-3c9a403d9f4so1518803b6e.1 for ; Thu, 23 May 2024 13:53:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497592; x=1717102392; 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=Q/b+wv/LfUkRbFX3zJuWmr730zI3qcEqcjHzqiiYAcU=; b=K/LwnClIVWwYRwjFabERZZ9gmeIHTjBY6EHLoN3b4IzV8eIFP0mpKYLGz0yoAm+4Qw s5iBUOAesy5+RBmyaWFoe8ZotgPPO8ardCZl0c7h1PtiuzkVFHzSihbcsJmx/K+vBk1I x4BFmODqnU/Mq8cuEPfpgYh6kw2VFhBPyePaZ4j2jecsbj6dG/O0NNIEgtUENCZDu3xO gN/Qk7CS5MDP3UK5nG97m0R8cc1mcPlnnxJVVhQqAsTXXtl47GhgzmKzyDOR5SQv0p8Q O5gqkpg18SEyphUUU8B87PoWDww4vb/54kcx+UtQQCL6nIEAXsin/zctFKssD0dtC/w+ YcMg== X-Gm-Message-State: AOJu0Yy57e1vfPUtonI4uZIAjydU11HNF77YMQwQEIa2GyjGUCW3o2Tv vceXgTtiGI46Ka2kLuOJgmS35xzvYyOKA2OvIz9a0+cNFit5mbfmeBo8ougvCMk3P9Y04mSJoI2 WBH6CwenItO30JGuBuIXBRpsLNHATZtUmaqeJm3j3eIwom7y3+6ukhoNjnckEYcE+qaT7GGXMuR i0yfE7P0uYHHwYpBYcY1yzXXeYz25MQo+acOj8dQ4= X-Received: by 2002:a05:6808:1597:b0:3cf:e9d5:7078 with SMTP id 5614622812f47-3d1a5f247afmr714845b6e.33.1716497592485; Thu, 23 May 2024 13:53:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7SoF6y7x02j0jI+stg9WWAxzf+Eih4XdwkWAaNmgqnn+1/DZD+Lm6EZ+rjsl8KQoKJE75EA== X-Received: by 2002:a05:6808:1597:b0:3cf:e9d5:7078 with SMTP id 5614622812f47-3d1a5f247afmr714812b6e.33.1716497591884; Thu, 23 May 2024 13:53:11 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:11 -0700 (PDT) Message-ID: <593a9ac1-ecdc-42b9-ac63-88e31dc1ff2a@redhat.com> Date: Thu, 23 May 2024 16:53:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 04/12] - Allow components to be shared among range-queries. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.3 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, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Ranger and ranger's cache are both range_query based, but they need to share some common components. The path ranger also needs to share the GORI component.   Up until now, they have simple copied pointers to share, but this patch provides a protected API to allow them to share without knowing what all components are involved. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From ef99d19569a1c5fafa5784c2c2f7855b6e62ffd8 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 17 May 2024 10:44:27 -0400 Subject: [PATCH 04/12] Allow components to be shared among range-queries. Ranger and the ranger cache need to share components, this provides a blessed way to do so. * gimple-range.cc (gimple_ranger::gimple_ranger): Share the components from ranger_cache. (gimple_ranger::~gimple_ranger): Don't clear pointer. * value-query.cc (range_query::share_query): New. (range_query::range_query): Clear shared component flag. (range_query::~range_query): Don't free shared component copies. * value-query.h (share_query): New prototype. (m_shared_copy_p): New member. --- gcc/gimple-range.cc | 4 +--- gcc/value-query.cc | 11 +++++++++++ gcc/value-query.h | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 9664300a80b..4326976fc2a 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -44,7 +44,7 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : current_bb (NULL) { // Share the oracle from the cache. - m_relation = &m_cache.relation (); + share_query (m_cache); if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE)) tracer.enable_trace (); m_stmt_list.create (0); @@ -67,8 +67,6 @@ gimple_ranger::gimple_ranger (bool use_imm_uses) : gimple_ranger::~gimple_ranger () { - // Restore the original oracle. - m_relation = NULL; m_stmt_list.release (); } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index db64a95a284..adcc59cadbf 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -211,13 +211,24 @@ range_query::destroy_relation_oracle () } } +void +range_query::share_query (range_query &q) +{ + m_relation = q.m_relation; + m_shared_copy_p = true; +} + range_query::range_query () { m_relation = &default_relation_oracle; + m_shared_copy_p = false; } range_query::~range_query () { + // Do not destroy anything if this is a shared copy. + if (m_shared_copy_p) + return; destroy_relation_oracle (); } diff --git a/gcc/value-query.h b/gcc/value-query.h index a8688a099fa..a5735902af0 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -88,6 +88,11 @@ protected: basic_block bbentry, basic_block bbexit); bool get_arith_expr_range (vrange &r, tree expr, gimple *stmt); relation_oracle *m_relation; + // When multiple related range queries wish to share oracles. + // This is an internal interface + void share_query (range_query &q); + bool m_shared_copy_p; + }; // Global ranges for SSA names using SSA_NAME_RANGE_INFO. -- 2.41.0 From patchwork Thu May 23 20:53:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938592 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RIKJDgcp; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgSs38Lsz20KL for ; Fri, 24 May 2024 06:56:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B4496386D61A for ; Thu, 23 May 2024 20:56:27 +0000 (GMT) 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 ESMTPS id 12CBF386C59E for ; Thu, 23 May 2024 20:53:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 12CBF386C59E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 12CBF386C59E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497604; cv=none; b=PxYSxoPhAadDM4gAzoGQBNHQa02nVwZjUfOy7HtOIUcCXHiTyxSJCFpRukIJcW/RXSTJwkdfZXrumLqv4VwoKTBiTU2Z9zBkKpwH3erndhr/HJW7Ys1Gu4HyNY2CW/vmf+4L/iF5Csab0o5N/EGlD3K7pdRikXy+5UCFS8PwwME= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497604; c=relaxed/simple; bh=zQabLYsHRIfbnK507rsfT5x1hFckHIwTaC6yBN7ji2o=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=BxuoLixnZpDT/51KoqCc8wEWIz7FCMq9MDc2rn+iM1LEE9bcezHxct4jGG2E1k+Ys1PdXvWqn7H9CW1bpuIF4j/xGqHMu6n+v+1/GhdcogE6wT9gHqpxuSQa4qNCeFMuMJ8i1sPZrrEbSyIhjgA7tQCWXCy4yy0Hn7TeswphFQQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497599; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=WpdV7lfg93BORrY/pZWT/s/5Xcz4stQd3p753UUS2CI=; b=RIKJDgcprfAjYoSDUsgV5I2JXWQk4neiWr7zk5wnxcNmfeFGVqUIOk5d9FzwN+UwZ1DJNN r9QK1JgfuUBx+2PTvcUlZ3UqiugxrDxnoivii58hG3muL0fv8hOZ+t02cjwDro64j+vDsK qg8WsJohglEWlHEugzymZcqVi+hcKeU= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-650-uvFgC28yNTal0o8AiMuKGw-1; Thu, 23 May 2024 16:53:18 -0400 X-MC-Unique: uvFgC28yNTal0o8AiMuKGw-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3c9a9094719so1308603b6e.0 for ; Thu, 23 May 2024 13:53:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497597; x=1717102397; 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=JuZWq/mcgmg7rsmRnb4g5Xaj28YTAUGHUkKfu2uYf5U=; b=TQPfDd17cLRS3uEVN0H/iXZSgwyvYPHCxZzHzf5TMuYv+IHRzMLl/5RrjswymbtvsG LrmhWVrcyXnES25b7peXAHyCpfPahs/97zPi8sroLC48k33tMkCu0OH0UBvO+J4sFwB9 o+x96wWsHIFp91deg1DhexPj+DAI4QCgHj8rf6FAUrmCBbNBatfquwI/csQmcnkMGT9x rkYDqFPmR9MCS4DO0GcljznAykzW7UFpXdCNRpnQus2G0KuuH9JlHZKjpNYY2PBYp+8Y 1htIJYYdte2Gp7T/qWi6Hy8MFPudIUcqDs/xwcx367QwmLY3XTNickAuBkGHgUvxx3IO /qFg== X-Gm-Message-State: AOJu0Yw6d5MxK1yQop++OYEN5X1dT7UjKilbZYz7k+IEdJTBv2fh6/Bk MLRZcGcMPTbrnLPVcj1NLRxSSxH5Hpbtp7/jXID+ghn8VPAtjNKbYNNCGxpF+2IvsK5QsE1AGNv h4/5NGge9cl9ZiqyNCdMd2CHMVH0vi+rQAgDH0jJAQxPvQlkV2QLLae/wmz78rH/OrY1QiXS27A fRLLmkj67W7dYJkmU2Ca7T4AFwUjYZigHItu/uHLg= X-Received: by 2002:a05:6808:219d:b0:3c9:6a5b:51cf with SMTP id 5614622812f47-3d1a538c770mr665041b6e.9.1716497597191; Thu, 23 May 2024 13:53:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpn/TtJFfdpn+SelYxpF4t20RJholHAOKLn8sI8ouyKVP9Zg3mXnQAAQAYQqjoSnCp0qd+4Q== X-Received: by 2002:a05:6808:219d:b0:3c9:6a5b:51cf with SMTP id 5614622812f47-3d1a538c770mr665025b6e.9.1716497596813; Thu, 23 May 2024 13:53:16 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:16 -0700 (PDT) Message-ID: <2293adc5-4dcd-45a6-a173-ca610f1e5e77@redhat.com> Date: Thu, 23 May 2024 16:53:15 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 05/12] - Move infer_manager to a range_query oracle. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.7 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Turn the infer_manager class into an always available oracle accessible via a range_query object.   This will make it easier to share and query inferred range info between objects and also makes the information easily accessible to any pass that is interested. This again removes the need to check for a non-null object, and again makes for a slight performance improvement. Documentation on the inferred range manager can be found at : https://gcc.gnu.org/wiki/AndrewMacLeod/InferredRanges It also associates each inferred range with it's originating stmt which was missing before (we only knew what block it came from). Future functionality will make use of the more specific information. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 837ce8a2d75231b68f13da00d9be8d2fd404804e Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 17 May 2024 10:50:24 -0400 Subject: [PATCH 05/12] Move infer_manager to a range_query oracle. Turn the infer_manager class into an always available oracle accessible via a range_query object. Also assocaite each inferrred range with it's originating stmt. * gimple-range-cache.cc (ranger_cache::ranger_cache): Create an infer oracle instead of a local member. (ranger_cache::~ranger_cache): Destroy the oracle. (ranger_cache::edge_range): Use oracle. (ranger_cache::fill_block_cache): Likewise. (ranger_cache::range_from_dom): Likewise. (ranger_cache::apply_inferred_ranges): Likewise. * gimple-range-cache.h (ranger_cache::m_exit): Delete. * gimple-range-infer.cc (infer_oracle): New static object; (class infer_oracle): New. (non_null_wrapper::non_null_wrapper): New. (non_null_wrapper::add_nonzero): New. (non_null_wrapper::add_range): New. (non_null_loadstore): Use nonnull_wrapper. (gimple_infer_range::gimple_infer_range): New alternate constructor. (exit_range::stmt): New. (infer_range_manager::has_range_p): Combine seperate methods. (infer_range_manager::maybe_adjust_range): Adjust has_range_p call. (infer_range_manager::add_ranges): New. (infer_range_manager::add_range): Take stmt rather than BB. (infer_range_manager::add_nonzero): Adjust from BB to stmt. * gimple-range-infer.h (class gimple_infer_range): Adjust methods. (infer_range_oracle): New. (class infer_range_manager): Inherit from infer_range_oracle. Adjust methods. * gimple-range-path.cc (path_range_query::range_defined_in_block): Use oracle. (path_range_query::adjust_for_non_null_uses): Likewise. * gimple-range.cc (gimple_ranger::range_on_edge): Likewise (gimple_ranger::register_transitive_inferred_ranges): Likewise. * value-query.cc (default_infer_oracle): New. (range_query::create_infer_oracle): New. (range_query::destroy_infer_oracle): New. (range_query::share_query): Copy infer pointer. (range_query::range_query): Initialize infer pointer. (range_query::~range_query): destroy infer object. * value-query.h (range_query::infer_oracle): New. (range_query::create_infer_oracle): New prototype. (range_query::destroy_infer_oracle): New prototype. (range_query::m_infer): New. --- gcc/gimple-range-cache.cc | 24 +++++------ gcc/gimple-range-cache.h | 1 - gcc/gimple-range-infer.cc | 90 +++++++++++++++++++++++++++------------ gcc/gimple-range-infer.h | 31 ++++++++++---- gcc/gimple-range-path.cc | 4 +- gcc/gimple-range.cc | 14 +++--- gcc/value-query.cc | 20 +++++++++ gcc/value-query.h | 5 +++ 8 files changed, 131 insertions(+), 58 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 55277ea8af1..34dc9c4a3ec 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -950,8 +950,7 @@ update_list::pop () // -------------------------------------------------------------------------- ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) - : m_gori (not_executable_flag), - m_exit (use_imm_uses) + : m_gori (not_executable_flag) { m_workback.create (0); m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun)); @@ -960,6 +959,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) // If DOM info is available, spawn an oracle as well. create_relation_oracle (); + create_infer_oracle (use_imm_uses); unsigned x, lim = last_basic_block_for_fn (cfun); // Calculate outgoing range info upfront. This will fully populate the @@ -977,6 +977,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) ranger_cache::~ranger_cache () { delete m_update; + destroy_infer_oracle (); destroy_relation_oracle (); delete m_temporal; m_workback.release (); @@ -1175,7 +1176,7 @@ ranger_cache::edge_range (vrange &r, edge e, tree name, enum rfd_mode mode) exit_range (r, name, e->src, mode); // If this is not an abnormal edge, check for inferred ranges on exit. if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0) - m_exit.maybe_adjust_range (r, name, e->src); + infer_oracle ().maybe_adjust_range (r, name, e->src); Value_Range er (TREE_TYPE (name)); if (m_gori.outgoing_edge_range_p (er, e, name, *this)) r.intersect (er); @@ -1544,7 +1545,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) // Regardless of whether we have visited pred or not, if the // pred has inferred ranges, revisit this block. // Don't search the DOM tree. - if (m_exit.has_range_p (name, pred)) + if (infer_oracle ().has_range_p (pred, name)) { if (DEBUG_RANGE_CACHE) fprintf (dump_file, "Inferred range: update "); @@ -1667,7 +1668,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, for ( ; bb; prev_bb = bb, bb = get_immediate_dominator (CDI_DOMINATORS, bb)) { // Accumulate any block exit inferred ranges. - m_exit.maybe_adjust_range (infer, name, bb); + infer_oracle ().maybe_adjust_range (infer, name, bb); // This block has an outgoing range. if (m_gori.has_edge_range_p (name, bb)) @@ -1742,7 +1743,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, r.intersect (er); // If this is a normal edge, apply any inferred ranges. if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0) - m_exit.maybe_adjust_range (r, name, bb); + infer_oracle ().maybe_adjust_range (r, name, bb); if (DEBUG_RANGE_CACHE) { @@ -1811,11 +1812,8 @@ ranger_cache::apply_inferred_ranges (gimple *s) update = false; } - for (unsigned x = 0; x < infer.num (); x++) - { - tree name = infer.name (x); - m_exit.add_range (name, bb, infer.range (x)); - if (update) - register_inferred_value (infer.range (x), name, bb); - } + infer_oracle ().add_ranges (s, infer); + if (update) + for (unsigned x = 0; x < infer.num (); x++) + register_inferred_value (infer.range (x), infer.name (x), bb); } diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index bdf07cd007c..e3ab89de02e 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -115,7 +115,6 @@ public: void register_inferred_value (const vrange &r, tree name, basic_block bb); void apply_inferred_ranges (gimple *s); gori_compute m_gori; - infer_range_manager m_exit; void dump_bb (FILE *f, basic_block bb); virtual void dump (FILE *f) override; diff --git a/gcc/gimple-range-infer.cc b/gcc/gimple-range-infer.cc index d5e1aa14275..757a2013c58 100644 --- a/gcc/gimple-range-infer.cc +++ b/gcc/gimple-range-infer.cc @@ -37,6 +37,25 @@ along with GCC; see the file COPYING3. If not see #include "cfganal.h" #include "tree-dfa.h" +// Create the global oracle. + +infer_range_oracle infer_oracle; + +// This class is merely an accessor which is granted internals to +// gimple_infer_range such that non_null_loadstore as a static callback can +// call the protected add_nonzero (). +// Static functions ccannot be friends, so we do it through a class wrapper. + +class non_null_wrapper +{ +public: + inline non_null_wrapper (gimple_infer_range *infer) : m_infer (infer) { } + inline void add_nonzero (tree name) { m_infer->add_nonzero (name); } + inline void add_range (tree t, vrange &r) { m_infer->add_range (t, r); } +private: + gimple_infer_range *m_infer; +}; + // Adapted from infer_nonnull_range_by_dereference and check_loadstore // to process nonnull ssa_name OP in S. DATA contains a pointer to a // stmt range inference instance. @@ -50,8 +69,8 @@ non_null_loadstore (gimple *, tree op, tree, void *data) addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (op)); if (!targetm.addr_space.zero_address_valid (as)) { - tree ssa = TREE_OPERAND (op, 0); - ((gimple_infer_range *)data)->add_nonzero (ssa); + non_null_wrapper wrapper ((gimple_infer_range *)data); + wrapper.add_nonzero (TREE_OPERAND (op, 0)); } } return false; @@ -173,6 +192,14 @@ gimple_infer_range::gimple_infer_range (gimple *s) } +// Create an single inferred range for NAMe using range R. + +gimple_infer_range::gimple_infer_range (tree name, vrange &r) +{ + num_args = 0; + add_range (name, r); +} + // ------------------------------------------------------------------------- // This class is an element in the list of inferred ranges. @@ -181,10 +208,12 @@ class exit_range { public: tree name; + gimple *stmt; vrange_storage *range; exit_range *next; }; + // If there is an element which matches SSA, return a pointer to the element. // Otherwise return NULL. @@ -253,33 +282,26 @@ infer_range_manager::get_nonzero (tree name) return *(m_nonzero[v]); } -// Return TRUE if there are any range inferences in block BB. - -bool -infer_range_manager::has_range_p (basic_block bb) -{ - if (bb->index >= (int)m_on_exit.length ()) - return false; - bitmap b = m_on_exit[bb->index].m_names; - return b && !bitmap_empty_p (b); -} - -// Return TRUE if NAME has a range inference in block BB. +// Return TRUE if NAME has a range inference in block BB. If NAME is NULL, +// return TRUE if there are any name sin BB. bool -infer_range_manager::has_range_p (tree name, basic_block bb) +infer_range_manager::has_range_p (basic_block bb, tree name) { // Check if this is an immediate use search model. - if (m_seen && !bitmap_bit_p (m_seen, SSA_NAME_VERSION (name))) + if (name && m_seen && !bitmap_bit_p (m_seen, SSA_NAME_VERSION (name))) register_all_uses (name); if (bb->index >= (int)m_on_exit.length ()) return false; - if (!m_on_exit[bb->index].m_names) - return false; - if (!bitmap_bit_p (m_on_exit[bb->index].m_names, SSA_NAME_VERSION (name))) + + bitmap b = m_on_exit[bb->index].m_names; + if (!b) return false; - return true; + + if (name) + return bitmap_bit_p (m_on_exit[bb->index].m_names, SSA_NAME_VERSION (name)); + return !bitmap_empty_p (b); } // Return TRUE if NAME has a range inference in block BB, and adjust range R @@ -288,7 +310,7 @@ infer_range_manager::has_range_p (tree name, basic_block bb) bool infer_range_manager::maybe_adjust_range (vrange &r, tree name, basic_block bb) { - if (!has_range_p (name, bb)) + if (!has_range_p (bb, name)) return false; exit_range *ptr = m_on_exit[bb->index].find_ptr (name); gcc_checking_assert (ptr); @@ -299,11 +321,23 @@ infer_range_manager::maybe_adjust_range (vrange &r, tree name, basic_block bb) return r.intersect (tmp); } -// Add range R as an inferred range for NAME in block BB. +// Add all inferred ranges in INFER at stmt S. + +void +infer_range_manager::add_ranges (gimple *s, gimple_infer_range &infer) +{ + for (unsigned x = 0; x < infer.num (); x++) + add_range (infer.name (x), s, infer.range (x)); +} + +// Add range R as an inferred range for NAME on stmt S. void -infer_range_manager::add_range (tree name, basic_block bb, const vrange &r) +infer_range_manager::add_range (tree name, gimple *s, const vrange &r) { + basic_block bb = gimple_bb (s); + if (!bb) + return; if (bb->index >= (int)m_on_exit.length ()) m_on_exit.safe_grow_cleared (last_basic_block_for_fn (cfun) + 1); @@ -334,6 +368,7 @@ infer_range_manager::add_range (tree name, basic_block bb, const vrange &r) ptr->range->set_vrange (cur); else ptr->range = m_range_allocator->clone (cur); + ptr->stmt = s; return; } @@ -342,16 +377,17 @@ infer_range_manager::add_range (tree name, basic_block bb, const vrange &r) ptr = (exit_range *)obstack_alloc (&m_list_obstack, sizeof (exit_range)); ptr->range = m_range_allocator->clone (r); ptr->name = name; + ptr->stmt = s; ptr->next = m_on_exit[bb->index].head; m_on_exit[bb->index].head = ptr; } -// Add a non-zero inferred range for NAME in block BB. +// Add a non-zero inferred range for NAME at stmt S. void -infer_range_manager::add_nonzero (tree name, basic_block bb) +infer_range_manager::add_nonzero (tree name, gimple *s) { - add_range (name, bb, get_nonzero (name)); + add_range (name, s, get_nonzero (name)); } // Follow immediate use chains and find all inferred ranges for NAME. @@ -378,7 +414,7 @@ infer_range_manager::register_all_uses (tree name) for (unsigned x = 0; x < infer.num (); x++) { if (name == infer.name (x)) - add_range (name, gimple_bb (s), infer.range (x)); + add_range (name, s, infer.range (x)); } } } diff --git a/gcc/gimple-range-infer.h b/gcc/gimple-range-infer.h index 384d8b2765e..fd5b2ad8dde 100644 --- a/gcc/gimple-range-infer.h +++ b/gcc/gimple-range-infer.h @@ -32,20 +32,35 @@ class gimple_infer_range { public: gimple_infer_range (gimple *s); + gimple_infer_range (tree name, vrange &r); inline unsigned num () const { return num_args; } inline tree name (unsigned index) const { gcc_checking_assert (index < num_args); return m_names[index]; } inline const vrange& range (unsigned index) const { gcc_checking_assert (index < num_args); return m_ranges[index]; } +private: void add_range (tree name, vrange &range); void add_nonzero (tree name); -private: void check_assume_func (gcall *call); unsigned num_args; static const int size_limit = 10; tree m_names[size_limit]; Value_Range m_ranges[size_limit]; inline void bump_index () { if (num_args < size_limit - 1) num_args++; } + friend class non_null_wrapper; +}; + +// This is the basic infer oracle API. Default functionaility does nothing. + +class infer_range_oracle +{ +public: + infer_range_oracle () { } + virtual ~infer_range_oracle () { } + virtual void add_ranges (gimple *, gimple_infer_range &) { } + virtual bool has_range_p (basic_block, tree = NULL_TREE) { return false; } + virtual bool maybe_adjust_range (vrange &, tree, basic_block) + { return false; } }; // This class manages a list of inferred ranges for each basic block. @@ -54,17 +69,17 @@ private: // followed the first time a name is referenced and block populated if // there are any inferred ranges. -class infer_range_manager +class infer_range_manager : public infer_range_oracle { public: infer_range_manager (bool do_search); - ~infer_range_manager (); - void add_range (tree name, basic_block bb, const vrange &r); - void add_nonzero (tree name, basic_block bb); - bool has_range_p (tree name, basic_block bb); - bool has_range_p (basic_block bb); - bool maybe_adjust_range (vrange &r, tree name, basic_block bb); + virtual ~infer_range_manager (); + virtual void add_ranges (gimple *s, gimple_infer_range &ir); + virtual bool has_range_p (basic_block bb, tree name = NULL_TREE); + virtual bool maybe_adjust_range (vrange &r, tree name, basic_block bb); private: + void add_range (tree name, gimple *s, const vrange &r); + void add_nonzero (tree name, gimple *s); class exit_range_head { public: diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index e35bec0e50d..b35ab43524b 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -303,7 +303,7 @@ path_range_query::range_defined_in_block (vrange &r, tree name, basic_block bb) } if (bb && POINTER_TYPE_P (TREE_TYPE (name))) - m_ranger.m_cache.m_exit.maybe_adjust_range (r, name, bb); + m_ranger.infer_oracle ().maybe_adjust_range (r, name, bb); if (DEBUG_SOLVER && (bb || !r.varying_p ())) { @@ -463,7 +463,7 @@ path_range_query::adjust_for_non_null_uses (basic_block bb) else r.set_varying (TREE_TYPE (name)); - if (m_ranger.m_cache.m_exit.maybe_adjust_range (r, name, bb)) + if (m_ranger.infer_oracle ().maybe_adjust_range (r, name, bb)) m_cache.set_range (name, r); } } diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 4326976fc2a..efc84dc3b44 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -253,7 +253,7 @@ gimple_ranger::range_on_edge (vrange &r, edge e, tree name) range_on_exit (r, e->src, name); // If this is not an abnormal edge, check for a non-null exit . if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0) - m_cache.m_exit.maybe_adjust_range (r, name, e->src); + infer_oracle ().maybe_adjust_range (r, name, e->src); gcc_checking_assert (r.undefined_p () || range_compatible_p (r.type(), TREE_TYPE (name))); @@ -516,8 +516,7 @@ void gimple_ranger::register_transitive_inferred_ranges (basic_block bb) { // Return if there are no inferred ranges in BB. - infer_range_manager &infer = m_cache.m_exit; - if (!infer.has_range_p (bb)) + if (!infer_oracle ().has_range_p (bb)) return; if (dump_file && (dump_flags & TDF_DETAILS)) @@ -530,7 +529,7 @@ gimple_ranger::register_transitive_inferred_ranges (basic_block bb) gimple *s = gsi_stmt (si); tree lhs = gimple_get_lhs (s); // If the LHS already has an inferred effect, leave it be. - if (!gimple_range_ssa_p (lhs) || infer.has_range_p (lhs, bb)) + if (!gimple_range_ssa_p (lhs) || infer_oracle ().has_range_p (bb, lhs)) continue; // Pick up global value. Value_Range g (TREE_TYPE (lhs)); @@ -543,13 +542,14 @@ gimple_ranger::register_transitive_inferred_ranges (basic_block bb) r.set_undefined (); tree name1 = gori ().depend1 (lhs); tree name2 = gori ().depend2 (lhs); - if ((name1 && infer.has_range_p (name1, bb)) - || (name2 && infer.has_range_p (name2, bb))) + if ((name1 && infer_oracle ().has_range_p (bb, name1)) + || (name2 && infer_oracle ().has_range_p (bb, name2))) { // Check if folding S produces a different result. if (fold_range (r, s, this) && g != r) { - infer.add_range (lhs, bb, r); + gimple_infer_range ir (lhs, r); + infer_oracle ().add_ranges (s, ir); m_cache.register_inferred_value (r, lhs, bb); } } diff --git a/gcc/value-query.cc b/gcc/value-query.cc index adcc59cadbf..41b581b20be 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -181,6 +181,23 @@ range_query::dump (FILE *) // Default oracle for all range queries. This contains no storage and thus // can be used anywhere. relation_oracle default_relation_oracle; +infer_range_oracle default_infer_oracle; + +void +range_query::create_infer_oracle (bool do_search) +{ + gcc_checking_assert (m_infer == &default_infer_oracle); + m_infer = new infer_range_manager (do_search); + gcc_checking_assert (m_infer); +} + +void +range_query::destroy_infer_oracle () +{ + if (m_infer && m_infer != &default_infer_oracle) + delete m_infer; + m_infer = &default_infer_oracle; +} // Create dominance based range oracle for the current query if dom info is // available. @@ -215,12 +232,14 @@ void range_query::share_query (range_query &q) { m_relation = q.m_relation; + m_infer = q.m_infer; m_shared_copy_p = true; } range_query::range_query () { m_relation = &default_relation_oracle; + m_infer = &default_infer_oracle; m_shared_copy_p = false; } @@ -229,6 +248,7 @@ range_query::~range_query () // Do not destroy anything if this is a shared copy. if (m_shared_copy_p) return; + destroy_infer_oracle (); destroy_relation_oracle (); } diff --git a/gcc/value-query.h b/gcc/value-query.h index a5735902af0..2f65d95bc9b 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -79,6 +79,10 @@ public: void create_relation_oracle (); void destroy_relation_oracle (); + inline class infer_range_oracle &infer_oracle () const { return *m_infer; } + void create_infer_oracle (bool do_search = TRUE); + void destroy_infer_oracle (); + virtual void dump (FILE *); protected: @@ -88,6 +92,7 @@ protected: basic_block bbentry, basic_block bbexit); bool get_arith_expr_range (vrange &r, tree expr, gimple *stmt); relation_oracle *m_relation; + infer_range_oracle *m_infer; // When multiple related range queries wish to share oracles. // This is an internal interface void share_query (range_query &q); -- 2.41.0 From patchwork Thu May 23 20:53:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hi9VxSaf; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgVJ37P7z20KL for ; Fri, 24 May 2024 06:57:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A9201384AB51 for ; Thu, 23 May 2024 20:57:42 +0000 (GMT) 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 ESMTPS id AA877386545E for ; Thu, 23 May 2024 20:53:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA877386545E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AA877386545E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497607; cv=none; b=IHPPQefFjvZodCjxc69dG3jIuCnCc/A5ylhHFMCjVWID1wBCBi7tVW+lA9QkyqvV4kJS5TLu1v5SbDR3hHmCAKFMIfMUQXm6TQO6zybmcnnLUMWfkz/cL2ZdV6KKRFzBpbicBKCwpwB2cz7P3G8WJY3Ts6ODGRtZGtyUM0gBU+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497607; c=relaxed/simple; bh=yiC88Aw7JWv+LbE8ryqc04nLM6+M4YWhs74tdhjm4yQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=ptYnmMMG/lISud2egcVmEnPBqCiBma+PCTHMdDQunPx6xA/tdNkcUAW3mCaS7mYXOGlM7DPBXtGBqqk0GYYwZaCq75qPv3PF+yh0pT02CHwyWLttMP10dBmQhlYLgrs7KJw8e5ual60wssc0wsel1KqZmII5/9Au22fhsJeJFw8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=B+Jo1CF4liNljBZo7Oo+g6PcsWOJyeQnxAWKd4OjR5k=; b=hi9VxSafEPq6rFxd0wp1eMUkMNx4Lm3NmDXZDaJr1BScSfurtbVe9DIRlbtgj/jJil0Lt5 wz4Wi8MfTPWHpWR5sjI4jXD6Av7s/m99F8ZSIbj1eoz5QUFVArT4wx4NPWRcXgm/Y+nWWf l0/G0Us+2WpuFvlgMd4R6aWNmxvIZ7g= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-86-m2DZ6MN2NmqRZuC0koLX0A-1; Thu, 23 May 2024 16:53:23 -0400 X-MC-Unique: m2DZ6MN2NmqRZuC0koLX0A-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-794aaf740c9so18368485a.0 for ; Thu, 23 May 2024 13:53:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497602; x=1717102402; 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=QmitR3J9H+j8uWDq4Dwk8ndiks3rL5pJpRDBog+culc=; b=Xd2zLnlEO6s2+NJH7D/rKUoixB/sylqmppn626FbizYMG8k3QymwfKaJI80iGHumHg JDmtAHYX4u9wEzIBXDYnYrFGoqz7dMutdrZMcofuwv5pFukU10Qy23fGdvieqcbTr/Lv kYc8MccJ8XrApmQqCk6L/ERD0lCAIQlMxuYS+k7NzZ5ogZgg5PNaJmePuNegZF7F+Yp8 K0xJB3ikL/Zu2Znf5NLfOw0smc1RG2aB/0y4047xGvPTizFpVVGdzzX6d290SQZJcZvT +x+W15u1nfoTGUDmWjLaMxKm91jH6Yw4JOZX3z7w7X0SEtnsX1tGk1HXoGQLPZvptGOF OjUw== X-Gm-Message-State: AOJu0Yw+Hm6NyiPmT2/ynAd4lgA7y8lPY+C5eB108EQ9qfy9F5syTUfr 4K4fQ6kEra3Vq8Dp4kSEaCHGbAQEUHshS7XiUP4rC4DH9UMnnlB64BcnvHzbOavDqYkoIjOPNRU kTyXEdb2woJfX6Hefhd5kmZclbXskbBVq0VjjkPtpsAIyFhUJ5LLsFBJL2+nZSXcQK6Si4PV+fa 6VedKXz2FYLMXvnL/ZwBiJGNGcax6z/RjBB/mflvY= X-Received: by 2002:a05:620a:6212:b0:792:c42b:edc1 with SMTP id af79cd13be357-794ab0ad1a3mr30859685a.39.1716497602139; Thu, 23 May 2024 13:53:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFd5K1DhnqpvzukHEO6Je2DqjjOmf+dLAaxWb4bQ1ABEJRbtPDLuNWp3hBUIqCiuU4zQSVWHg== X-Received: by 2002:a05:620a:6212:b0:792:c42b:edc1 with SMTP id af79cd13be357-794ab0ad1a3mr30857685a.39.1716497601576; Thu, 23 May 2024 13:53:21 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:21 -0700 (PDT) Message-ID: <1531cb9e-a373-4186-8d4a-eb190ad7616e@redhat.com> Date: Thu, 23 May 2024 16:53:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 06/12] tree-optimization/113879 - Add inferred ranges for range-ops based statements. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US 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, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org gimple_range_fold contains some shorthand fold_range routines for easy user consumption of the range-ops interface, but there is no equivalent routines for op1_range and op2_range.  This patch provides basic versions. I have started range-op documentation, but its very early days so not that useful yet: https://gcc.gnu.org/wiki/AndrewMacLeod/RangeOperator Any range-op entry which has an op1_range or op2_range implemented can potentially also provide inferred ranges.  This is a step towards PR 113879.  Default is currently OFF for performance reasons as it dramatically increases the number of inferred ranges past where the current engine is comfortable with, but the functionality will now be there to move towards fixing the PR.  It might be appropriate for -O3, but I'll hold of for the moment. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 985581b05f32b62df15b60833a8a57544dbbd739 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 2 May 2024 12:23:18 -0400 Subject: [PATCH 06/12] Add inferred ranges for range-ops based statements. Gimple_range_fold contains some shorthand fold_range routines for easy user consumption of that range-ops interface, but there is no equivalent routines for op1_range and op2_range. This patch provides basic versions. Any range-op entry which has an op1_range or op2_range implemented can potentially also provide inferred ranges. This is a step towards PR 113879. Default is currently OFF for performance reasons as it dramtically increases the number of inferred ranges. PR tree-optimization/113879 * gimple-range-fold.cc (op1_range): New. (op2_range): New. * gimple-range-fold.h (op1_range): New prototypes. (op2_range): New prototypes. * gimple-range-infer.cc (gimple_infer_range::add_range): Do not add an inferred range if it is VARYING. (gimple_infer_range::gimple_infer_range): Add inferred ranges for any range-op statements if requested. * gimple-range-infer.h (gimple_infer_range): Add parameter. --- gcc/gimple-range-fold.cc | 71 +++++++++++++++++++++++++++++++++++++++ gcc/gimple-range-fold.h | 7 ++++ gcc/gimple-range-infer.cc | 41 +++++++++++++++++++++- gcc/gimple-range-infer.h | 2 +- 4 files changed, 119 insertions(+), 2 deletions(-) diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 357a1beabd1..9e9c5960972 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -328,6 +328,77 @@ fold_range (vrange &r, gimple *s, edge on_edge, range_query *q) return f.fold_stmt (r, s, src); } +// Calculate op1 on statetemt S with LHS into range R using range query Q +// to resolve any other operands. + +bool +op1_range (vrange &r, gimple *s, const vrange &lhs, range_query *q) +{ + gimple_range_op_handler handler (s); + if (!handler) + return false; + + fur_stmt src (s, q); + + tree op2_expr = handler.operand2 (); + if (!op2_expr) + return handler.calc_op1 (r, lhs); + + Value_Range op2 (TREE_TYPE (op2_expr)); + if (!src.get_operand (op2, op2_expr)) + return false; + + return handler.calc_op1 (r, lhs, op2); +} + +// Calculate op1 on statetemt S into range R using range query Q. +// LHS is set to VARYING in this case. + +bool +op1_range (vrange &r, gimple *s, range_query *q) +{ + tree lhs_type = gimple_range_type (s); + if (!lhs_type) + return false; + Value_Range lhs_range; + lhs_range.set_varying (lhs_type); + return op1_range (r, s, lhs_range, q); +} + +// Calculate op2 on statetemt S with LHS into range R using range query Q +// to resolve any other operands. + +bool +op2_range (vrange &r, gimple *s, const vrange &lhs, range_query *q) +{ + + gimple_range_op_handler handler (s); + if (!handler) + return false; + + fur_stmt src (s, q); + + Value_Range op1 (TREE_TYPE (handler.operand1 ())); + if (!src.get_operand (op1, handler.operand1 ())) + return false; + + return handler.calc_op2 (r, lhs, op1); +} + +// Calculate op2 on statetemt S into range R using range query Q. +// LHS is set to VARYING in this case. + +bool +op2_range (vrange &r, gimple *s, range_query *q) +{ + tree lhs_type = gimple_range_type (s); + if (!lhs_type) + return false; + Value_Range lhs_range; + lhs_range.set_varying (lhs_type); + return op2_range (r, s, lhs_range, q); +} + // Provide a fur_source which can be used to determine any relations on // a statement. It manages the callback from fold_using_ranges to determine // a relation_trio for a statement. diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index 1925fb899e3..d974b0192c8 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -43,6 +43,13 @@ bool fold_range (vrange &r, gimple *s, vrange &r1, vrange &r2, bool fold_range (vrange &r, gimple *s, unsigned num_elements, vrange **vector, range_query *q = NULL); +// Calculate op1 on stmt S. +bool op1_range (vrange &, gimple *s, range_query *q = NULL); +bool op1_range (vrange &, gimple *s, const vrange &lhs, range_query *q = NULL); +// Calculate op2 on stmt S. +bool op2_range (vrange &, gimple *s, range_query *q = NULL); +bool op2_range (vrange &, gimple *s, const vrange &lhs, range_query *q = NULL); + // This routine will return a relation trio for stmt S. relation_trio fold_relations (gimple *s, range_query *q = NULL); diff --git a/gcc/gimple-range-infer.cc b/gcc/gimple-range-infer.cc index 757a2013c58..2571a4d127f 100644 --- a/gcc/gimple-range-infer.cc +++ b/gcc/gimple-range-infer.cc @@ -129,6 +129,9 @@ gimple_infer_range::check_assume_func (gcall *call) void gimple_infer_range::add_range (tree name, vrange &range) { + // Do not add an inferred range if it is VARYING. + if (range.varying_p ()) + return; m_names[num_args] = name; m_ranges[num_args] = range; if (num_args < size_limit - 1) @@ -149,8 +152,12 @@ gimple_infer_range::add_nonzero (tree name) // Process S for range inference and fill in the summary list. // This is the routine where new inferred ranges should be added. +// If USE_RANGEOPS is true, invoke range-ops on stmts with a single +// ssa-name aa constant to reflect an inferred range. ie +// x_2 = y_3 + 1 will provide an inferred range for y_3 of [-INF, +INF - 1]. +// This defaults to FALSE as it can be expensive., -gimple_infer_range::gimple_infer_range (gimple *s) +gimple_infer_range::gimple_infer_range (gimple *s, bool use_rangeops) { num_args = 0; @@ -190,6 +197,38 @@ gimple_infer_range::gimple_infer_range (gimple *s) walk_stmt_load_store_ops (s, (void *)this, non_null_loadstore, non_null_loadstore); + // Gated by flag. + if (!use_rangeops) + return; + + // Check if there are any inferred ranges from range-ops. + gimple_range_op_handler handler (s); + if (!handler) + return; + + // Only proceed if ONE operand is an SSA_NAME, This may provide an + // inferred range for 'y + 3' , but will bypass expressions like + // 'y + z' as it depends on symbolic values. + tree ssa1 = gimple_range_ssa_p (handler.operand1 ()); + tree ssa2 = gimple_range_ssa_p (handler.operand2 ()); + if ((ssa1 != NULL) == (ssa2 != NULL)) + return; + + // The other operand should be a constant, so just use the global range + // query to pick up any other values. + if (ssa1) + { + Value_Range op1 (TREE_TYPE (ssa1)); + if (op1_range (op1, s, get_global_range_query ()) && !op1.varying_p ()) + add_range (ssa1, op1); + } + else + { + gcc_checking_assert (ssa2); + Value_Range op2 (TREE_TYPE (ssa2)); + if (op2_range (op2, s, get_global_range_query ()) && !op2.varying_p ()) + add_range (ssa2, op2); + } } // Create an single inferred range for NAMe using range R. diff --git a/gcc/gimple-range-infer.h b/gcc/gimple-range-infer.h index fd5b2ad8dde..d2c151c4b9d 100644 --- a/gcc/gimple-range-infer.h +++ b/gcc/gimple-range-infer.h @@ -31,7 +31,7 @@ along with GCC; see the file COPYING3. If not see class gimple_infer_range { public: - gimple_infer_range (gimple *s); + gimple_infer_range (gimple *s, bool use_rangeops = false); gimple_infer_range (tree name, vrange &r); inline unsigned num () const { return num_args; } inline tree name (unsigned index) const -- 2.41.0 From patchwork Thu May 23 20:53:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=W2wXXQ6z; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgRM1bRdz1ynR for ; Fri, 24 May 2024 06:55:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 67B6B384404C for ; Thu, 23 May 2024 20:55:09 +0000 (GMT) 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 8D6DB384646D for ; Thu, 23 May 2024 20:53:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D6DB384646D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8D6DB384646D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497618; cv=none; b=CFKc7/5B6TUAtTCIkB6FbwDxD9BH4LEB8fPl2v4R6ayQWiOFLD1lHd57ATG9CPwEpB9WdxH6Cjk326IE+W6KmB9DcbFbmc3VflPLfakyUKVl6UOPqwZEyHD1jN++5fIbQHgv4/5F2rfA5yZNF9Fq/LRTpaZyUMtQBhyRrIXA1/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497618; c=relaxed/simple; bh=lsH09OsulREpyHTpp4oUVfw1jNytxOtJJwvKogZeh9I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=qJ8xx1W9O2GQkN0ApNmCiPcHnnryk6D8Zo2FTW6nMEqtKP3DawJ5TyQr+EaxQJX9HbOz3ToRhs5gDsEjqy8y9IBia4el6yeeNiIu/My3Ydc+RSB+I5o9ceg2pcqS9Dqh2LqBuVchXJANUPx1Dv+K37Z4lJJk/NA3i58JEkOQun8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=zP55i4XtMr6uuagOogrwSRAEisn+GbOoVTt50lQfx8Q=; b=W2wXXQ6zcQj03rZtO87YendxFN5jtW/UmfU3/X5LM+UYsJ5EU6PKi37Ds9lc8/B3hpO+pz rFuhfhrD6AlOvnNa2jYRb9PophaSbrZATrK60HvmgERTkEeygA9DtC2FXiYISFeSV36L0t L7foZ4bI77S8S4pYlxm+dW5LKiyte8Q= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-253-dMgT5JxlMi-FjL1DEp-k9g-1; Thu, 23 May 2024 16:53:26 -0400 X-MC-Unique: dMgT5JxlMi-FjL1DEp-k9g-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3d19e57ce65so157676b6e.1 for ; Thu, 23 May 2024 13:53:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497605; x=1717102405; 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=Ruiw2cy/jI5+hCvhI0snRZbuUsUFHujeHHQZbJnbvqY=; b=ker515NUypRtLE5iSkBvR9t8ME4PcfVr1yw+cVLmj5D0S6w8LDbovgwrQAuRXBLezy cVAL2+9bvUsO3iX9DQuD4XlxTxUoz0lKDH+Ybb/tIQTefo/Pe4awHpeljHN4rGDeJixY uItKURvkaqw5ewKRaXh76Db4U2u46560FyzxoBQWZlLbSGcpB9q/Pevf9G3mIKvcwkfn UQFa6RrB0eerHNeNATSbvhnzTHdbV+WBnEWk3VuPx9fa8ZwjCnoI1zi2Xv97E/ICSGBK PiSftMFvDNODluKuyZz//48P3aGNMo6FEzCmXce/ALhj0r0ID8o+rA56RIpcu+nTcTTz IzDw== X-Gm-Message-State: AOJu0YwBvNNWo4Bpmsb8xoYr9718XopfZ/EZvsHQKY4FpgdroVZGnMMF S1+agKLKFdb5yNulubkyibFbVbIrt11E3twQD3NSAol2fR+FwBzwtbVBLePiRq5jVI8Fc6QX4dT lvA4Gb9/8ujQqUAJHzk4aK1d/rSMNi012VKvNJ6TAWyEcTPH2DpQARf8jiRrRmoVNiX+GZ6iPzP IUU+kCYeG/HZc4etjsYltCPUrUWkujpMT49auLvBk= X-Received: by 2002:a54:4787:0:b0:3c9:d0e6:fed7 with SMTP id 5614622812f47-3d1a7a2e833mr409641b6e.58.1716497605586; Thu, 23 May 2024 13:53:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbKW+uKwml7GQT1VqvCA9KW71vkhEhHEvfyTyRmkZZk4WIPNuJ4frwGwD9xPCH1HEvmlMLRg== X-Received: by 2002:a54:4787:0:b0:3c9:d0e6:fed7 with SMTP id 5614622812f47-3d1a7a2e833mr409627b6e.58.1716497605119; Thu, 23 May 2024 13:53:25 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:24 -0700 (PDT) Message-ID: <40aae0c8-e7b1-48e8-bf1d-d6d55df87a76@redhat.com> Date: Thu, 23 May 2024 16:53:24 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 07/12] - Default gimple_outgoing_range to not process switches. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch adjusts the way gimple_outgoing_range works.  This is the static edge calculator that provide ranges on edges for TRUE/FALSE edges, as well as calculated the ranges on switch edges.   It was a component of ranger before or something that could be included if a pass wanted it. this adjusts the way it works in preparation for being more tightly integrated into GORI.  It now works by always working for TRUE/FALSE edges, and uses a set_sw_limit routine to enable or disable switch processing.   Functionally there is little difference, but it will allow it to be the base for a GORI object now. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 1ec8e2027a99a5ddca933a37b3cf5ef322208c5a Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Mon, 6 May 2024 12:04:24 -0400 Subject: [PATCH 07/12] Default gimple_outgoing_range to not process switches. Change the default constructor to not process switches, add method to enable/disable switch processing. * gimple-range-edge.cc (gimple_outgoing_range::gimple_outgoing_range): Do not allocate a range allocator at construction time. (gimple_outgoing_range::~gimple_outgoing_range): Delete allocator if one was allocated. (gimple_outgoing_range::set_switch_limit): New. (gimple_outgoing_range::switch_edge_range): Create an allocator if one does not exist. (gimple_outgoing_range::edge_range_p): Check for zero edges. * gimple-range-edge.h (class gimple_outgoing_range): Adjust prototypes. --- gcc/gimple-range-edge.cc | 23 +++++++++++++++++------ gcc/gimple-range-edge.h | 12 +++++++++++- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/gcc/gimple-range-edge.cc b/gcc/gimple-range-edge.cc index 3811a0995aa..0c75ad0519c 100644 --- a/gcc/gimple-range-edge.cc +++ b/gcc/gimple-range-edge.cc @@ -51,7 +51,6 @@ gimple_outgoing_range_stmt_p (basic_block bb) return NULL; } - // Return a TRUE or FALSE range representing the edge value of a GCOND. void @@ -64,22 +63,32 @@ gcond_edge_range (irange &r, edge e) r = range_false (); } +// Construct a gimple_outgoing_range object. No memory is allocated. gimple_outgoing_range::gimple_outgoing_range (int max_sw_edges) { m_edge_table = NULL; + m_range_allocator = NULL; m_max_edges = max_sw_edges; - m_range_allocator = new vrange_allocator; } +// Destruct an edge object, disposing of any memory allocated. gimple_outgoing_range::~gimple_outgoing_range () { if (m_edge_table) delete m_edge_table; - delete m_range_allocator; + if (m_range_allocator) + delete m_range_allocator; } +// Set a new switch limit. + +void +gimple_outgoing_range::set_switch_limit (int max_sw_edges) +{ + m_max_edges = max_sw_edges; +} // Get a range for a switch edge E from statement S and return it in R. // Use a cached value if it exists, or calculate it if not. @@ -96,8 +105,10 @@ gimple_outgoing_range::switch_edge_range (irange &r, gswitch *sw, edge e) TYPE_PRECISION (TREE_TYPE (gimple_switch_index (sw)))) return false; - if (!m_edge_table) - m_edge_table = new hash_map (n_edges_for_fn (cfun)); + if (!m_edge_table) + m_edge_table = new hash_map (n_edges_for_fn (cfun)); + if (!m_range_allocator) + m_range_allocator = new vrange_allocator; vrange_storage **val = m_edge_table->get (e); if (!val) @@ -202,7 +213,7 @@ gimple_outgoing_range::edge_range_p (irange &r, edge e) } // Only process switches if it within the size limit. - if (EDGE_COUNT (e->src->succs) > (unsigned)m_max_edges) + if (m_max_edges == 0 || (EDGE_COUNT (e->src->succs) > (unsigned)m_max_edges)) return NULL; gcc_checking_assert (is_a (s)); diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h index 9ac0617f970..ce8b04f6bad 100644 --- a/gcc/gimple-range-edge.h +++ b/gcc/gimple-range-edge.h @@ -34,13 +34,23 @@ along with GCC; see the file COPYING3. If not see // The API is simple, just ask for the range on the edge. // The return value is NULL for no range, or the branch statement which the // edge gets the range from, along with the range. +// +// THe switch_limit is the number of switch edges beyond which the switch +// is ignored (ie, edge_range_p () will return NULL as if the sitch was not +// there. THis value can be adjusted any time via set_switch_limit (). +// THe default is 0, no switches are precoessed until set_switch_limit () is +// called, and then the default is INT_MAX. +// +// No memory is allocated until an edge for a switch is processed which also +// falls under the edge limit criteria. class gimple_outgoing_range { public: - gimple_outgoing_range (int max_sw_edges = INT_MAX); + gimple_outgoing_range (int max_sw_edges = 0); ~gimple_outgoing_range (); gimple *edge_range_p (irange &r, edge e); + void set_switch_limit (int max_sw_edges = INT_MAX); private: void calc_switch_ranges (gswitch *sw); bool switch_edge_range (irange &r, gswitch *sw, edge e); -- 2.41.0 From patchwork Thu May 23 20:53:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938585 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TDzBNZhd; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgQZ5lxRz20Q0 for ; Fri, 24 May 2024 06:54:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 148ED3865C29 for ; Thu, 23 May 2024 20:54:29 +0000 (GMT) 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 017FE3858CD1 for ; Thu, 23 May 2024 20:53:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 017FE3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 017FE3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497622; cv=none; b=m50ObaoDbhFtChnNHAKd4aEVnTFPHf7TwA8+16ZOc7iWqixnOy+ml59cyK0p3qXYhQN6gsDCjotOum3SNQVvyZKtc78EPqIP7rd4ZJzJ7FYVD0DfOmh3g10XsW2VqSvJK2UjPsuPYBANgTG8dUZzoV6geLmHxOAUfyBi7HkBIFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497622; c=relaxed/simple; bh=SBovPFEpcedf8o08+vBzvDfmKjwY9zZBxEuKU8GmIGU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=nh3h8M7V/Y4jVLPfRQFBqQr6qnsth1DZi+hFe/6FTpPMtsENLyrIMqUp5qVNawiyiQvrIvawIu4Y2dBvbrByLeaaNbsNgmwRi0iF76AGWwqkKugIpa0RV42MVMFHtslDKgavo6/aXiqXyF3w35AoBO4YR+gu1JWoJU53kFG81zo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497615; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=PinOpLP9D+/f+qlEV6EQjiZtf+vHW7UaFCYUZy35djE=; b=TDzBNZhdWxd64WaQqPCj6LhXpOH6zmWlc2KHmi2u59xJ0SnVQYSBXd5idZrycUEIgifaR1 5oq/pLoA0km18IURl2fkFF+NvL/ZPmwM1WDmefXg+JnXgZQhJP7k/ZzJtomRHjmkSjw3Tq UdkZ6v4RBzFCSMKvAYaJ6TGr1bHPFTw= 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-101-4gkiYuyENEOVxQLjg40gdw-1; Thu, 23 May 2024 16:53:32 -0400 X-MC-Unique: 4gkiYuyENEOVxQLjg40gdw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-792c2650197so76396085a.0 for ; Thu, 23 May 2024 13:53:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497611; x=1717102411; 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=745UX0RJywIiTQapxoRA3aAUHhEvAYbPuYrCgRhujqo=; b=gseBMKzThr+pxXBaVOE0qnUxJIHlVJ3CwecFCXBZyVBiiibBcXw9YFy8ZxQEgYqL66 av33Qg4fYM8+qTYnV6c46WvIEdTbCCK/XwoI81xNGQRn5UtHG308OvahJZ6c+/MK6o+a aoDuQidZDTxJLAS493g4VuA29JeuI42i2ay2lqeDrw3AO/iNYiXccAzVZO+r7cLQlfUp IWgXYiO4OPmj6mg0kf21vN6/IkNL6ttrvMZjuKUnuHer/5D4uJUua7o2ag3v6F9AjoXS ZyKh59mjOpBLXm6XFQAFwL5FIumehAAEGSeVvcmEKmTFh5WQv5RC33F0opzualuUgjI2 hyAQ== X-Gm-Message-State: AOJu0YwK7/qJ/NYaxYuZWvg/VhXIVUofynnAtRWCAAMCjsUqfK7HNqT1 Ms1F5xABJgmNDJe264F9a+eEv0nEQepm/RipIdnnjQvKinc5UqHynwllhAr27Lgpey+qieDUGBU j3TItCdmcGL+1H+8l06dje1M6UwVdxI/h66vQOSmtZ9C3MQY6nr7yIN4UZqacU/G71nHv2LiALi /QK5bhOKEP9uMygfeJjk2n0PdExIfwAzQr9efey+I= X-Received: by 2002:a05:620a:3604:b0:792:ea76:27d3 with SMTP id af79cd13be357-794ab13dd9dmr37296785a.63.1716497611379; Thu, 23 May 2024 13:53:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGiHAYF/z/rpgwIe+1L7rAA8jViMtF/GNAL+UO+jlAAgwvQXKAKmZgLSb+h+Y1C0FisZk+3Uw== X-Received: by 2002:a05:620a:3604:b0:792:ea76:27d3 with SMTP id af79cd13be357-794ab13dd9dmr37294185a.63.1716497610765; Thu, 23 May 2024 13:53:30 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:30 -0700 (PDT) Message-ID: <336edc4c-d589-49e4-a879-3de7f533c65d@redhat.com> Date: Thu, 23 May 2024 16:53:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 08/12] - Gori_compute no longer inherits from gori_map. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.2 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch moves the gori_compute object away from inheriting a gori_map object and instead it as a local member.  Export it via map (). The gori_map object contains all the SSA name dependencies and import/export name lists for blocks.  GORI was inheriting from this originally as a convenient way to share the data, but it doesn't really belong there.  it is really a component that is used by GORI rather than part of what it is.  This more accurately reflects the relationship. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 9b42fafa0ec385bbc86be1d9f1a86c140e1045c3 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 9 May 2024 14:14:31 -0400 Subject: [PATCH 08/12] Gori_compute no longer inherits from gori_map. This patch moves the gori_compute object away from inheriting a gori_map object and instead it as a local member. Export it via map (). * gimple-range-cache.cc (ranger_cache::ranger_cache): Access gori_map via member call. (ranger_cache::dump_bb): Likewise. (ranger_cache::get_global_range): Likewise. (ranger_cache::set_global_range): Likewise. (ranger_cache::register_inferred_value): Likewise. * gimple-range-fold.cc (fold_using_range::range_of_range_op): Likewise. (fold_using_range::range_of_address): Likewise. (fold_using_range::range_of_phi): Likewise. * gimple-range-gori.cc (gori_compute::compute_operand_range_switch): likewise. (gori_compute::compute_operand_range): Likewise. (gori_compute::compute_logical_operands): Likewise. (gori_compute::refine_using_relation): Likewise. (gori_compute::compute_operand1_and_operand2_range): Likewise. (gori_compute::may_recompute_p): Likewise. (gori_compute::has_edge_range_p): Likewise. (gori_compute::outgoing_edge_range_p): Likewise. (gori_compute::condexpr_adjust): Likewise. * gimple-range-gori.h (class gori_compute): Do not inherit from gori_map. (gori_compute::m_map): New. * gimple-range-path.cc (gimple-range-path.cc): Use gori_map member. (path_range_query::compute_exit_dependencies): Likewise. * gimple-range.cc (gimple_ranger::range_of_stmt): Likewise. (gimple_ranger::register_transitive_inferred_ranges): Likewise. * tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): Likewise. * tree-ssa-threadedge.cc (hybrid_jt_simplifier::compute_exit_dependencies): Likewise. * tree-vrp.cc (remove_unreachable::handle_early): Likewise. (remove_unreachable::remove_and_update_globals): Likewise. --- gcc/gimple-range-cache.cc | 16 ++++++------- gcc/gimple-range-fold.cc | 12 +++++----- gcc/gimple-range-gori.cc | 47 +++++++++++++++++++------------------- gcc/gimple-range-gori.h | 4 +++- gcc/gimple-range-path.cc | 6 ++--- gcc/gimple-range.cc | 6 ++--- gcc/tree-ssa-dom.cc | 2 +- gcc/tree-ssa-threadedge.cc | 2 +- gcc/tree-vrp.cc | 9 ++++---- 9 files changed, 54 insertions(+), 50 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 34dc9c4a3ec..c52475852a9 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -969,7 +969,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) { basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); if (bb) - m_gori.exports (bb); + m_gori.map ()->exports (bb); } m_update = new update_list (); } @@ -1000,7 +1000,7 @@ ranger_cache::dump (FILE *f) void ranger_cache::dump_bb (FILE *f, basic_block bb) { - m_gori.gori_map::dump (f, bb, false); + m_gori.map ()->dump (f, bb, false); m_on_entry.dump (f, bb); m_relation->dump (f, bb); } @@ -1033,8 +1033,8 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) current_p = false; if (had_global) current_p = r.singleton_p () - || m_temporal->current_p (name, m_gori.depend1 (name), - m_gori.depend2 (name)); + || m_temporal->current_p (name, m_gori.map ()->depend1 (name), + m_gori.map ()->depend2 (name)); else { // If no global value has been set and value is VARYING, fold the stmt @@ -1071,8 +1071,8 @@ ranger_cache::set_global_range (tree name, const vrange &r, bool changed) if (!changed) { // If there are dependencies, make sure this is not out of date. - if (!m_temporal->current_p (name, m_gori.depend1 (name), - m_gori.depend2 (name))) + if (!m_temporal->current_p (name, m_gori.map ()->depend1 (name), + m_gori.map ()->depend2 (name))) m_temporal->set_timestamp (name); return; } @@ -1097,7 +1097,7 @@ ranger_cache::set_global_range (tree name, const vrange &r, bool changed) if (r.singleton_p () || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ())) - m_gori.set_range_invariant (name); + m_gori.map ()->set_range_invariant (name); m_temporal->set_timestamp (name); } @@ -1783,7 +1783,7 @@ ranger_cache::register_inferred_value (const vrange &ir, tree name, m_on_entry.set_bb_range (name, bb, r); // If this range was invariant before, remove invariant. if (!m_gori.has_edge_range_p (name)) - m_gori.set_range_invariant (name, false); + m_gori.map ()->set_range_invariant (name, false); } } diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 9e9c5960972..b626855c51a 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -747,7 +747,7 @@ fold_using_range::range_of_range_op (vrange &r, if (lhs && gimple_range_ssa_p (op1)) { if (src.gori ()) - src.gori ()->register_dependency (lhs, op1); + src.gori ()->map ()->register_dependency (lhs, op1); relation_kind rel; rel = handler.lhs_op1_relation (r, range1, range1); if (rel != VREL_VARYING) @@ -775,8 +775,8 @@ fold_using_range::range_of_range_op (vrange &r, { if (src.gori ()) { - src.gori ()->register_dependency (lhs, op1); - src.gori ()->register_dependency (lhs, op2); + src.gori ()->map ()->register_dependency (lhs, op1); + src.gori ()->map ()->register_dependency (lhs, op2); } if (gimple_range_ssa_p (op1)) { @@ -845,7 +845,7 @@ fold_using_range::range_of_address (prange &r, gimple *stmt, fur_source &src) tree ssa = TREE_OPERAND (base, 0); tree lhs = gimple_get_lhs (stmt); if (lhs && gimple_range_ssa_p (ssa) && src.gori ()) - src.gori ()->register_dependency (lhs, ssa); + src.gori ()->map ()->register_dependency (lhs, ssa); src.get_operand (r, ssa); range_cast (r, TREE_TYPE (gimple_assign_rhs1 (stmt))); @@ -952,7 +952,7 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) r.union_ (arg_range); if (gimple_range_ssa_p (arg) && src.gori ()) - src.gori ()->register_dependency (phi_def, arg); + src.gori ()->map ()->register_dependency (phi_def, arg); } // Track if all arguments are the same. @@ -1353,7 +1353,7 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, // leading to the condition such as: // c_2 = a_4 < b_7 // if (c_2) - FOR_EACH_GORI_EXPORT_NAME (*(gori ()), bb, name) + FOR_EACH_GORI_EXPORT_NAME (*(gori ()->map ()), bb, name) { if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE) continue; diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index 9afc7c1c19c..fa4a235f08b 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -589,7 +589,7 @@ gori_compute::compute_operand_range_switch (vrange &r, gswitch *s, } // If op1 is in the definition chain, pass lhs back. - if (gimple_range_ssa_p (op1) && in_chain_p (name, op1)) + if (gimple_range_ssa_p (op1) && m_map.in_chain_p (name, op1)) return compute_operand_range (r, SSA_NAME_DEF_STMT (op1), lhs, name, src); return false; @@ -646,8 +646,8 @@ gori_compute::compute_operand_range (vrange &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 && in_chain_p (name, op1); - bool op2_in_chain = op2 && in_chain_p (name, op2); + bool op1_in_chain = op1 && m_map.in_chain_p (name, op1); + bool op2_in_chain = op2 && m_map.in_chain_p (name, op2); // If neither operand is derived, then this stmt tells us nothing. if (!op1_in_chain && !op2_in_chain) @@ -658,9 +658,9 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, // Instead just evaluate the one operand. if (op1_in_chain && op2_in_chain) { - if (in_chain_p (op1, op2) || op1 == op2) + if (m_map.in_chain_p (op1, op2) || op1 == op2) op1_in_chain = false; - else if (in_chain_p (op2, op1)) + else if (m_map.in_chain_p (op2, op1)) op2_in_chain = false; } @@ -675,11 +675,11 @@ gori_compute::compute_operand_range (vrange &r, gimple *stmt, // a) both elements are in the defchain // c = x > y // (x and y are in c's defchain) if (op1_in_chain) - res = in_chain_p (vrel_ptr->op1 (), op1) - && in_chain_p (vrel_ptr->op2 (), op1); + res = m_map.in_chain_p (vrel_ptr->op1 (), op1) + && m_map.in_chain_p (vrel_ptr->op2 (), op1); if (!res && op2_in_chain) - res = in_chain_p (vrel_ptr->op1 (), op2) - || in_chain_p (vrel_ptr->op2 (), op2); + res = m_map.in_chain_p (vrel_ptr->op1 (), op2) + || m_map.in_chain_p (vrel_ptr->op2 (), op2); if (!res) { // or b) one relation element is in the defchain of the other and the @@ -955,7 +955,7 @@ gori_compute::compute_logical_operands (vrange &true_range, vrange &false_range, { gimple *stmt = handler.stmt (); gimple *src_stmt = gimple_range_ssa_p (op) ? SSA_NAME_DEF_STMT (op) : NULL; - if (!op_in_chain || !src_stmt || chain_import_p (handler.lhs (), op)) + if (!op_in_chain || !src_stmt || m_map.chain_import_p (handler.lhs (), op)) { // If op is not in the def chain, or defined in this block, // use its known value on entry to the block. @@ -1018,9 +1018,9 @@ gori_compute::refine_using_relation (tree op1, vrange &op1_range, return false; bool change = false; - bool op1_def_p = in_chain_p (op2, op1); + bool op1_def_p = m_map.in_chain_p (op2, op1); if (!op1_def_p) - if (!in_chain_p (op1, op2)) + if (!m_map.in_chain_p (op1, op2)) return false; tree def_op = op1_def_p ? op1 : op2; @@ -1304,8 +1304,8 @@ gori_compute::compute_operand1_and_operand2_range (vrange &r, bool gori_compute::may_recompute_p (tree name, basic_block bb, int depth) { - tree dep1 = depend1 (name); - tree dep2 = depend2 (name); + tree dep1 = m_map.depend1 (name); + tree dep2 = m_map.depend2 (name); // If the first dependency is not set, there is no recomputation. // Dependencies reflect original IL, not current state. Check if the @@ -1327,7 +1327,8 @@ gori_compute::may_recompute_p (tree name, basic_block bb, int depth) gcc_checking_assert (depth >= 1); } - bool res = (bb ? is_export_p (dep1, bb) : is_export_p (dep1)); + bool res = (bb ? m_map.is_export_p (dep1, bb) + : m_map.is_export_p (dep1)); if (res || depth <= 1) return res; // Check another level of recomputation. @@ -1335,9 +1336,9 @@ gori_compute::may_recompute_p (tree name, basic_block bb, int depth) } // Two dependencies terminate the depth of the search. if (bb) - return is_export_p (dep1, bb) || is_export_p (dep2, bb); + return m_map.is_export_p (dep1, bb) || m_map.is_export_p (dep2, bb); else - return is_export_p (dep1) || is_export_p (dep2); + return m_map.is_export_p (dep1) || m_map.is_export_p (dep2); } // Return TRUE if NAME can be recomputed on edge E. If any direct dependent @@ -1359,10 +1360,10 @@ gori_compute::has_edge_range_p (tree name, basic_block bb) { // Check if NAME is an export or can be recomputed. if (bb) - return is_export_p (name, bb) || may_recompute_p (name, bb); + return m_map.is_export_p (name, bb) || may_recompute_p (name, bb); // If no block is specified, check for anywhere in the IL. - return is_export_p (name) || may_recompute_p (name); + return m_map.is_export_p (name) || may_recompute_p (name); } // Return TRUE if a range can be calculated or recomputed for NAME on edge E. @@ -1402,7 +1403,7 @@ gori_compute::outgoing_edge_range_p (vrange &r, edge e, tree name, fur_stmt src (stmt, &q); // If NAME can be calculated on the edge, use that. - if (is_export_p (name, e->src)) + if (m_map.is_export_p (name, e->src)) { bool res; if ((idx = tracer.header ("outgoing_edge"))) @@ -1526,13 +1527,13 @@ gori_compute::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond, } // Now solve for SSA1 or SSA2 if they are in the dependency chain. - if (ssa1 && in_chain_p (ssa1, cond_name)) + if (ssa1 && m_map.in_chain_p (ssa1, cond_name)) { Value_Range tmp1 (TREE_TYPE (ssa1)); if (compute_operand_range (tmp1, def_stmt, cond_true, ssa1, src)) r1.intersect (tmp1); } - if (ssa2 && in_chain_p (ssa2, cond_name)) + if (ssa2 && m_map.in_chain_p (ssa2, cond_name)) { Value_Range tmp2 (TREE_TYPE (ssa2)); if (compute_operand_range (tmp2, def_stmt, cond_false, ssa2, src)) @@ -1555,7 +1556,7 @@ gori_compute::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond, void gori_compute::dump (FILE *f) { - gori_map::dump (f); + m_map.gori_map::dump (f); } // ------------------------------------------------------------------------ diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index 8f08e9a088a..ae857ecb2b5 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -161,7 +161,7 @@ private: class value_relation; -class gori_compute : public gori_map +class gori_compute { public: gori_compute (int not_executable_flag = 0); @@ -174,7 +174,9 @@ public: bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs, tree name, class fur_source &src, value_relation *rel = NULL); + gori_map *map () { return &m_map; } private: + gori_map m_map; bool refine_using_relation (tree op1, vrange &op1_range, tree op2, vrange &op2_range, fur_source &src, relation_kind k); diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index b35ab43524b..5043c00d482 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -410,7 +410,7 @@ path_range_query::compute_ranges_in_block (basic_block bb) } gori_compute &g = m_ranger.gori (); - bitmap exports = g.exports (bb); + bitmap exports = g.map()->exports (bb); EXECUTE_IF_AND_IN_BITMAP (m_exit_dependencies, exports, 0, i, bi) { tree name = ssa_name (i); @@ -488,7 +488,7 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) // Start with the imports from the exit block... basic_block exit = m_path[0]; gori_compute &gori = m_ranger.gori (); - bitmap_copy (dependencies, gori.imports (exit)); + bitmap_copy (dependencies, gori.map()->imports (exit)); auto_vec worklist (bitmap_count_bits (dependencies)); bitmap_iterator bi; @@ -536,7 +536,7 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) { basic_block bb = m_path[i]; tree name; - FOR_EACH_GORI_EXPORT_NAME (gori, bb, name) + FOR_EACH_GORI_EXPORT_NAME (*(gori.map ()), bb, name) if (TREE_CODE (TREE_TYPE (name)) == BOOLEAN_TYPE) bitmap_set_bit (dependencies, SSA_NAME_VERSION (name)); } diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index efc84dc3b44..e7e6fd86581 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -310,7 +310,7 @@ gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name) // Update any exports in the cache if this is a gimple cond statement. tree exp; basic_block bb = gimple_bb (s); - FOR_EACH_GORI_EXPORT_NAME (m_cache.m_gori, bb, exp) + FOR_EACH_GORI_EXPORT_NAME (*(m_cache.m_gori.map ()), bb, exp) m_cache.propagate_updated_value (exp, bb); } } @@ -540,8 +540,8 @@ gimple_ranger::register_transitive_inferred_ranges (basic_block bb) // an inferred range as well. Value_Range r (TREE_TYPE (lhs)); r.set_undefined (); - tree name1 = gori ().depend1 (lhs); - tree name2 = gori ().depend2 (lhs); + tree name1 = gori ().map () ->depend1 (lhs); + tree name2 = gori ().map ()->depend2 (lhs); if ((name1 && infer_oracle ().has_range_p (bb, name1)) || (name2 && infer_oracle ().has_range_p (bb, name2))) { diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 73264852ebd..81c8b16fd12 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -1431,7 +1431,7 @@ dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb) tree name; gori_compute &gori = m_ranger->gori (); - FOR_EACH_GORI_EXPORT_NAME (gori, pred_e->src, name) + FOR_EACH_GORI_EXPORT_NAME (*(gori.map()), pred_e->src, name) if (all_uses_feed_or_dominated_by_stmt (name, stmt) // The condition must post-dominate the definition point. && (SSA_NAME_IS_DEFAULT_DEF (name) diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc index 2bae82a074b..f5268d45516 100644 --- a/gcc/tree-ssa-threadedge.cc +++ b/gcc/tree-ssa-threadedge.cc @@ -1449,7 +1449,7 @@ hybrid_jt_simplifier::compute_exit_dependencies (bitmap dependencies, gori_compute &gori = m_ranger->gori (); // Start with the imports to the final conditional. - bitmap_copy (dependencies, gori.imports (path[0])); + bitmap_copy (dependencies, gori.map ()->imports (path[0])); // Add any other interesting operands we may have missed. if (gimple_bb (stmt) != path[0]) diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index a36c08f469a..be9df39f680 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -210,14 +210,14 @@ remove_unreachable::handle_early (gimple *s, edge e) // Check if every export use is dominated by this branch. tree name; - FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) + FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name) { if (!fully_replaceable (name, e->src)) return; } // Set the global value for each. - FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) + FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name) { Value_Range r (TREE_TYPE (name)); m_ranger.range_on_entry (r, e->dest, name); @@ -287,7 +287,7 @@ remove_unreachable::remove_and_update_globals () gcc_checking_assert (gimple_code (s) == GIMPLE_COND); bool dominate_exit_p = true; - FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) + FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name) { // Ensure the cache is set for NAME in the succ block. Value_Range r(TREE_TYPE (name)); @@ -304,7 +304,8 @@ remove_unreachable::remove_and_update_globals () // If the exit is dominated, add to the export list. Otherwise if this // isn't the final VRP pass, leave the call in the IL. if (dominate_exit_p) - bitmap_ior_into (all_exports, m_ranger.gori ().exports (e->src)); + bitmap_ior_into (all_exports, + m_ranger.gori ().map ()->exports (e->src)); else if (!final_p) continue; -- 2.41.0 From patchwork Thu May 23 20:53:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938593 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D/OiQnxy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgSv70B5z20KL for ; Fri, 24 May 2024 06:56:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4A81A386C5A9 for ; Thu, 23 May 2024 20:56:30 +0000 (GMT) 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 098CE386C596 for ; Thu, 23 May 2024 20:53:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 098CE386C596 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 098CE386C596 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497624; cv=none; b=lRUWP58n0BTq1wyfZ0CfVHxeNkVMHy1zJKmncKNOYrVaK+720cDft7GVG4zAPt5XeM3dc8y/Qi9CgRWjg7aGWGr7PtX7ayIGYf5DDjddIlxyGib3tDP7cYfgIUTiL2MLXECBgbqgm2T78RL2V1iHkK+LMxWmWkmH614ybWGT61Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497624; c=relaxed/simple; bh=4O3NyqIq8uEx1HZVnzYEud0W6LL/cBJKTPnSzvMCx8I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=BPHmRXIk+lhlu9o5ZNVUyWiVVMjA/3orcs0amTZ2gQhf/10P3a+w4KhxCTYUQ2Ln+iGhHCqpteF2ZKYzdZ2802qumLjt9BGHxwE1nOmoPLi9h0QgQWMx8JREZmI7k/nvYYQrhseVDOy0rnL1Nq1w66lDWPiZyR6/Jpcds/HitYs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497620; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=beBdJrd1lVRIxP5nhk/XqUbJxEMhNVjTnVYnpvmXh68=; b=D/OiQnxy3gbeYUD8E8NfsjST6newz5WbIO/R1GnSxUqFHLnrpw6UlwtLsboonn81cTO1P5 L9xkOU31sTEXiODSl/hhlVkm662myGhMUt3amX6TXxKFNRMc1xE5/muShqdOcSbhdxem05 PXXgCyq/OCvosy7Fw8r9xrIAP7veOmU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-wW_quzpWMz6oq25tnx-WFA-1; Thu, 23 May 2024 16:53:37 -0400 X-MC-Unique: wW_quzpWMz6oq25tnx-WFA-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-792e037511eso46375585a.2 for ; Thu, 23 May 2024 13:53:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497616; x=1717102416; 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=t0A8UrNirV07donMkBPcHZZfSbeG5W2sGhtqmO54ZGA=; b=d8AtgL2vVNsRjHVS+hlUVfJvsjMXA/Ni7IcaJ4TJkb50F7QsYKzkQBpR8Ccik3RIGo z4lG/e8/YncTgc37Rvld9Efv3EOI5+fCn3fN7KcdCNXwvq3aYrTnrV9L3ZnOIQJ/iF4/ +Pr6LnkWi3y7aXX8APXkcJSzkEj1i5oLMhmDAnqA42fjcfvaeqbpkosRr9FV77UwCHW5 pxbprAABae6ENW8cUqix77Mi04p7pg7iCyt4QyitK43Muk0+EwYkwSrkTzGf0Cm/NGnj TTTmU/vjWwiDat6R20lfeUmjCzoz9tmR5Q1BKv+7kvxLVUiZf+HsBjJ7llZrXPei4qOu hJng== X-Gm-Message-State: AOJu0YzfBzrLhIeZhkGU2JVghRJNy9L962i6uCMd0PP0c6gBCEPXX2BS LtCvKnpCuvbtYygdVmoYlINEbxYNNeIbzXiLvpR4/gsJn732mDVEYH+GLfch4HOY6YU+fETKsz5 bdQ89TMfsfjMRHBeGAlY3wgdi9IL8wWXmmMrCTcpVcx/xG0jnc8ZDVGnpo/IT57z/MeR5NrrHOv UgKV7s6dee3efb6SwrslDpqfWLZW0mpitJICsJvxo= X-Received: by 2002:a05:620a:a0c:b0:790:ef5d:25ae with SMTP id af79cd13be357-794ab12122bmr41385085a.56.1716497616297; Thu, 23 May 2024 13:53:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHvhJA3P0XGVQRk2SUaBZdbGQF1oB97r2twclGJG2DxSK3a/U8p46/ESevkJ3fyjAtD5DyBjA== X-Received: by 2002:a05:620a:a0c:b0:790:ef5d:25ae with SMTP id af79cd13be357-794ab12122bmr41382585a.56.1716497615773; Thu, 23 May 2024 13:53:35 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:35 -0700 (PDT) Message-ID: Date: Thu, 23 May 2024 16:53:34 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 09/12] - Gori_compute inherits from gimple_outgoing_range. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch makes gimple_outgoing_range a base class for the GORI API, and provides basic routines for the SSA-NAME versions returning false.   gori_compute now inherits from gimple_outgoing_range and no longer needs it as a private member. This makes far more sense as GORI is adding the ability to calculate SSA_NAMEs on edges in addition to the basic static edge ranges.  It also renames outgoing_edge_range_p to edge_range_p for consistency with the static edge range routine. The basic API for static edges (including switch ranges) is documented here. https://gcc.gnu.org/wiki/AndrewMacLeod/GimpleOutgoingRange The more advanced GORI ssa-name processing engine has not been written yet.  its on the to-do list :-) Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 8feb69600dd696fb8a6e3b88b7d159ced5cb0eb9 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 9 May 2024 16:34:12 -0400 Subject: [PATCH 09/12] Gori_compute inherits from gimple_outgoing_range. Make gimple_outgoing_range a base class for the GORI API, and provide base routines returning false. gori_compute inherits from gimple_outgoing_range and no longer needs it as a private member. Rename outgoing_edge_range_p to edge_range_p. * gimple-range-cache.cc (ranger_cache::ranger_cache): Adjust m_gori constructor. (ranger_cache::edge_range): Use renamed edge_range_p name. (ranger_cache::range_from_dom): Likewise. * gimple-range-edge.h (gimple_outgoing_range::condexpr_adjust): New. (gimple_outgoing_range::has_edge_range_p): New. (gimple_outgoing_range::dump): New. (gimple_outgoing_range::compute_operand_range): New. (gimple_outgoing_range::map): New. * gimple-range-fold.cc (fur_source::register_outgoing_edges ): Use renamed edge_range_p routine * gimple-range-gori.cc (gori_compute::gori_compute): Adjust constructor. (gori_compute::~gori_compute): New. (gori_compute::edge_range_p): Rename from outgoing_edge_range_p and use inherited routine instead of member method. * gimple-range-gori.h (class gori_compute): Inherit from gimple_outgoing_range, adjust protoypes. (gori_compute::outgpoing): Delete. * gimple-range-path.cc (path_range_query::compute_ranges_in_block): Use renamed edge_range_p routine. * tree-ssa-loop-unswitch.cc (evaluate_control_stmt_using_entry_checks): Likewise. --- gcc/gimple-range-cache.cc | 6 +++--- gcc/gimple-range-edge.h | 15 ++++++++++++++- gcc/gimple-range-fold.cc | 4 ++-- gcc/gimple-range-gori.cc | 13 ++++++++----- gcc/gimple-range-gori.h | 10 +++++----- gcc/gimple-range-path.cc | 4 ++-- gcc/tree-ssa-loop-unswitch.cc | 4 ++-- 7 files changed, 36 insertions(+), 20 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index c52475852a9..40e4baa6289 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -950,7 +950,7 @@ update_list::pop () // -------------------------------------------------------------------------- ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) - : m_gori (not_executable_flag) + : m_gori (not_executable_flag, param_vrp_switch_limit) { m_workback.create (0); m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun)); @@ -1178,7 +1178,7 @@ ranger_cache::edge_range (vrange &r, edge e, tree name, enum rfd_mode mode) if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0) infer_oracle ().maybe_adjust_range (r, name, e->src); Value_Range er (TREE_TYPE (name)); - if (m_gori.outgoing_edge_range_p (er, e, name, *this)) + if (m_gori.edge_range_p (er, e, name, *this)) r.intersect (er); return true; } @@ -1738,7 +1738,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, edge e = single_pred_edge (prev_bb); bb = e->src; - if (m_gori.outgoing_edge_range_p (er, e, name, *this)) + if (m_gori.edge_range_p (er, e, name, *this)) { r.intersect (er); // If this is a normal edge, apply any inferred ranges. diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h index ce8b04f6bad..be1f0c2cc15 100644 --- a/gcc/gimple-range-edge.h +++ b/gcc/gimple-range-edge.h @@ -48,9 +48,22 @@ class gimple_outgoing_range { public: gimple_outgoing_range (int max_sw_edges = 0); - ~gimple_outgoing_range (); + virtual ~gimple_outgoing_range (); gimple *edge_range_p (irange &r, edge e); void set_switch_limit (int max_sw_edges = INT_MAX); + + virtual bool edge_range_p (vrange &, edge, tree, range_query &) + { return false; } + virtual bool condexpr_adjust (vrange &, vrange &, gimple *, tree, tree, tree, + class fur_source &) { return false; } + virtual bool has_edge_range_p (tree, basic_block = NULL) { return false; } + virtual bool has_edge_range_p (tree, edge ) { return false; } + virtual void dump (FILE *) { } + virtual bool compute_operand_range (vrange &, gimple *, const vrange &, tree, + fur_source &, + class value_relation * = NULL) + { return false; } + virtual class gori_map *map () { return NULL; } private: void calc_switch_ranges (gswitch *sw); bool switch_edge_range (irange &r, gswitch *sw, edge e); diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index b626855c51a..37c16761ba6 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -1368,14 +1368,14 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, { r1.set_varying (TREE_TYPE (ssa1)); r2.set_varying (TREE_TYPE (ssa2)); - if (e0 && gori ()->outgoing_edge_range_p (r, e0, name, *m_query) + if (e0 && gori ()->edge_range_p (r, e0, name, *m_query) && r.singleton_p ()) { relation_kind relation = handler.op1_op2_relation (r, r1, r2); if (relation != VREL_VARYING) register_relation (e0, relation, ssa1, ssa2); } - if (e1 && gori ()->outgoing_edge_range_p (r, e1, name, *m_query) + if (e1 && gori ()->edge_range_p (r, e1, name, *m_query) && r.singleton_p ()) { relation_kind relation = handler.op1_op2_relation (r, r1, r2); diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index fa4a235f08b..a7543064258 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -557,8 +557,8 @@ debug (gori_map &g) // Construct a gori_compute object. -gori_compute::gori_compute (int not_executable_flag) - : outgoing (param_vrp_switch_limit), tracer ("GORI ") +gori_compute::gori_compute (int not_executable_flag, int sw_max_edges) + : gimple_outgoing_range (sw_max_edges), tracer ("GORI ") { m_not_executable_flag = not_executable_flag; // Create a boolean_type true and false range. @@ -568,6 +568,10 @@ gori_compute::gori_compute (int not_executable_flag) tracer.enable_trace (); } +gori_compute::~gori_compute () +{ +} + // Given the switch S, return an evaluation in R for NAME when the lhs // evaluates to LHS. Returning false means the name being looked for // was not resolvable. @@ -1380,8 +1384,7 @@ gori_compute::has_edge_range_p (tree name, edge e) // control edge or NAME is not defined by this edge. bool -gori_compute::outgoing_edge_range_p (vrange &r, edge e, tree name, - range_query &q) +gori_compute::edge_range_p (vrange &r, edge e, tree name, range_query &q) { unsigned idx; @@ -1397,7 +1400,7 @@ gori_compute::outgoing_edge_range_p (vrange &r, edge e, tree name, gcc_checking_assert (gimple_range_ssa_p (name)); int_range_max lhs; // Determine if there is an outgoing edge. - gimple *stmt = outgoing.edge_range_p (lhs, e); + gimple *stmt = gimple_outgoing_range::edge_range_p (lhs, e); if (!stmt) return false; diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index ae857ecb2b5..c7a707ee724 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -127,7 +127,7 @@ private: // on *ANY* edge that has been seen. FALSE indicates that the global value // is applicable everywhere that has been processed. // -// outgoing_edge_range_p (vrange &range, edge e, tree name) +// edge_range_p (vrange &range, edge e, tree name) // Actually does the calculation of RANGE for name on E // This represents application of whatever static range effect edge E // may have on NAME, not any cumulative effect. @@ -161,11 +161,12 @@ private: class value_relation; -class gori_compute +class gori_compute : public gimple_outgoing_range { public: - gori_compute (int not_executable_flag = 0); - bool outgoing_edge_range_p (vrange &r, edge e, tree name, range_query &q); + gori_compute (int not_executable_flag = 0, int max_sw_edges = 0); + virtual ~gori_compute (); + bool edge_range_p (vrange &r, edge e, tree name, range_query &q); bool condexpr_adjust (vrange &r1, vrange &r2, gimple *s, tree cond, tree op1, tree op2, fur_source &src); bool has_edge_range_p (tree name, basic_block bb = NULL); @@ -205,7 +206,6 @@ private: int_range<2> m_bool_zero; // Boolean false cached. int_range<2> m_bool_one; // Boolean true cached. - gimple_outgoing_range outgoing; // Edge values for COND_EXPR & SWITCH_EXPR. range_tracer tracer; int m_not_executable_flag; }; diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 5043c00d482..03f73218a57 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -415,7 +415,7 @@ path_range_query::compute_ranges_in_block (basic_block bb) { tree name = ssa_name (i); Value_Range r (TREE_TYPE (name)); - if (g.outgoing_edge_range_p (r, e, name, *this)) + if (g.edge_range_p (r, e, name, *this)) { Value_Range cached_range (TREE_TYPE (name)); if (get_cache (cached_range, name)) @@ -424,7 +424,7 @@ path_range_query::compute_ranges_in_block (basic_block bb) m_cache.set_range (name, r); if (DEBUG_SOLVER) { - fprintf (dump_file, "outgoing_edge_range_p for "); + fprintf (dump_file, "edge_range_p for "); print_generic_expr (dump_file, name, TDF_SLIM); fprintf (dump_file, " on edge %d->%d ", e->src->index, e->dest->index); diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc index 9c284ce26ae..14b0df1aefe 100644 --- a/gcc/tree-ssa-loop-unswitch.cc +++ b/gcc/tree-ssa-loop-unswitch.cc @@ -763,8 +763,8 @@ evaluate_control_stmt_using_entry_checks (gimple *stmt, continue; int_range_max r; - if (!ranger->gori ().outgoing_edge_range_p (r, e, idx, - *get_global_range_query ())) + if (!ranger->gori ().edge_range_p (r, e, idx, + *get_global_range_query ())) continue; r.intersect (path_range); if (r.undefined_p ()) -- 2.41.0 From patchwork Thu May 23 20:53:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=gFiHmnE5; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgSJ2WYHz20KL for ; Fri, 24 May 2024 06:56:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 86DBE386C5B7 for ; Thu, 23 May 2024 20:55:58 +0000 (GMT) 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 ESMTPS id 2B4143865C3C for ; Thu, 23 May 2024 20:53:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B4143865C3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2B4143865C3C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497629; cv=none; b=Pc9rr933X7h/9YZ+G7He2vnBv0MeTN2s7Ar0FPnAxfG1WnCP9dNTOsi1mb7m8OLdBB8amjaggg8CR81ies8Cmc6lRK0C+euWB2KpVUDRjFl/InpBRMJ0pe7fsWzJ6tDNGKI68egVTvop4aB1Rpn/NHtRu8kXQlkMCOXaX9ZU8JM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497629; c=relaxed/simple; bh=O9vZxu7X5QQ9u/YNYy96bsijzT3oQPNkptn9WQYEkX0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=pPL+VQ5hbm3ALNaXXj4v0QwZrjd2wPXCgIyL/U2csr1gO5tlAs8/yfBzQhVeXR+/EKoFvHcxsjRIMj1wzGu2XSoPdlOglRqFbk2jiAB1go5W3eibPK4O2swfSok8hGoTkgZQ1uyN6ijZbrpn2dAnPEFdu0Sy11w15fvAE4xhhGw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497623; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=ly43zfkSDhlCv06ag/9eWqwljNeKM8x7fwa20aZd0Og=; b=gFiHmnE51gyNyUXYoGSVR5hnztQ9MMCChn9TKdj1FKUq5qyqoZx4tDl2Td0RbX4ePsqysb iNI47vDB0VmiaDpSubkS3g9S2VwQi7U3jkhvf2SLwYaOU/HIyb/5jC3llUSH1C4ZTtm/Cz +FVIdIHgB5Ra1vRLq5NRK5iBaFRmbiQ= Received: from mail-vk1-f197.google.com (mail-vk1-f197.google.com [209.85.221.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-SmaSArc9PMmL4fP5V_JE8g-1; Thu, 23 May 2024 16:53:42 -0400 X-MC-Unique: SmaSArc9PMmL4fP5V_JE8g-1 Received: by mail-vk1-f197.google.com with SMTP id 71dfb90a1353d-4e4efcc3b79so79104e0c.0 for ; Thu, 23 May 2024 13:53:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497621; x=1717102421; 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=uq32/Kl5q9KihsVqqgEfjktdh/Ce/YOY1/eYwxjtTmc=; b=qZlmZHwr3mBGBq7l97ADVmVhbz+p8ktBaqK/qwZ2r/3mptw+SfK08WHxwy3BuvIGup HiGiSTDxpvlGzv2tquCAXBVZ2ZV+qeIM6IYB0jG/m6ovofdt76lVzN+k+FUWDtkxiaPg 1JiT3Y0QSzARimq6ZEDD58sPL3fMWfBKko4UOL3khncG07aCf6MXeBjc8eLRO/AwqN/N c/keZygSt+9n3Z5/CyFPDcjjyM+/19y4/U9W1IQAmTdbv5uMVtkuR4n9OLMVcls7DIas R9HxlPszCxj9G9rRJ9DIxxGNQ5MPxB0+ORRh9tsElWH6EpySeGJrISXhg2Ph0l4RlfFj 4JAA== X-Gm-Message-State: AOJu0YzuTJ7G7GgJU9vog/bo1FVKlQIoMGAs1GoLOFMCKzal82i5jMZj hYH1XjlgFdx0bJJYtLJhVANKCWpul/ot/mvdJLID892y0n0HH1Es0jgqHkD5WVjoQa5E8k/2+y7 HG9jzdUEpMU9oB40JrBBp22uF9GSwwCQsJiWDosCzW0pBPUVsw8LRGo0zXmNvT3ZcjUEgZMN5sz VAEtw9EX3vu8yL5hoGQdc8muFFugbhm175zEYiLQk= X-Received: by 2002:a05:6122:3195:b0:4e4:edf0:b71b with SMTP id 71dfb90a1353d-4e4f0230803mr476487e0c.4.1716497621329; Thu, 23 May 2024 13:53:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF5ujK57t4UqmWAAcbt6ml8qSV8V+Z+bAmTqIMgXa70bwA2uTd/XujZelZgbVfGwcraNgAqEw== X-Received: by 2002:a05:6122:3195:b0:4e4:edf0:b71b with SMTP id 71dfb90a1353d-4e4f0230803mr476466e0c.4.1716497620875; Thu, 23 May 2024 13:53:40 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:40 -0700 (PDT) Message-ID: Date: Thu, 23 May 2024 16:53:39 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 10/12] - Make GORI a range_query component. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.2 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch moves the GORI component into the range_query object, and makes it generally available.  This makes it much easier to share between ranger, other range_queries, and the passes using them. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From 59a3a0ad763bc03ad5ab630a62fbc78ae50b486f Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Fri, 17 May 2024 14:27:12 -0400 Subject: [PATCH 10/12] Make GORI a range_query component. This patch moves the GORI component into the range_query object, and makes it generally available. This makes it much easier to share between ranger and the passes. * gimple-range-cache.cc (ranger_cache::ranger_cache): Create GORi via the range_query instead of a local member. (ranger_cache::dump_bb): Use gori via from the range_query parent. (ranger_cache::get_global_range): Likewise. (ranger_cache::set_global_range): Likewise. (ranger_cache::edge_range): Likewise. (anger_cache::block_range): Likewise. (ranger_cache::fill_block_cache): Likewise. (ranger_cache::range_from_dom): Likewise. (ranger_cache::register_inferred_value): Likewise. * gimple-range-cache.h (ranger_cache::m_gori): Delete. * gimple-range-fold.cc (fur_source::fur_source): Set m_depend_p. (fur_depend::fur_depend): Remove gori parameter. * gimple-range-fold.h (fur_source::gori): Adjust. (fur_source::m_gori): Delete. (fur_source::m_depend): New. (fur_depend::fur_depend): Adjust prototype. * gimple-range-path.cc (path_range_query::path_range_query): Share ranger oracles. (path_range_query::range_defined_in_block): Use oracle directly. (path_range_query::compute_ranges_in_block): Use new gori() method. (path_range_query::adjust_for_non_null_uses): Use oracle directly. (path_range_query::compute_exit_dependencies): Likewise. (jt_fur_source::jt_fur_source): No gori in the parameters. (path_range_query::range_of_stmt): Likewise. (path_range_query::compute_outgoing_relations): Likewise. * gimple-range.cc (gimple_ranger::fold_range_internal): Likewise. (gimple_ranger::range_of_stmt): Access gori via gori () method. (assume_query::range_of_expr): Create a gori object. (assume_query::~assume_query): Destroy a gori object. (assume_query::calculate_op): Remove old gori() accessor. * gimple-range.h (gimple_ranger::gori): Delete. (assume_query::~assume_query): New. (assume_query::m_gori): Delete. * tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): use gori () method. * tree-ssa-threadedge.cc (compute_exit_dependencies): Likewise. * value-query.cc (default_gori): New. (range_query::create_gori): New. (range_query::destroy_gori): New. (range_query::share_oracles): Set m_gori. (range_query::range_query): Set m_gori to default. (range_query::~range_query): call destroy gori. * value-query.h (range_query): Adjust prototypes (range_query::m_gori): New. --- gcc/gimple-range-cache.cc | 34 +++++++++++++++++----------------- gcc/gimple-range-cache.h | 1 - gcc/gimple-range-fold.cc | 7 +++---- gcc/gimple-range-fold.h | 7 ++++--- gcc/gimple-range-path.cc | 28 ++++++++++++++-------------- gcc/gimple-range.cc | 12 +++++++++--- gcc/gimple-range.h | 3 +-- gcc/tree-ssa-dom.cc | 3 +-- gcc/tree-ssa-threadedge.cc | 4 +--- gcc/value-query.cc | 20 ++++++++++++++++++++ gcc/value-query.h | 5 +++++ 11 files changed, 75 insertions(+), 49 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index 40e4baa6289..e75cac66902 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -950,7 +950,6 @@ update_list::pop () // -------------------------------------------------------------------------- ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) - : m_gori (not_executable_flag, param_vrp_switch_limit) { m_workback.create (0); m_workback.safe_grow_cleared (last_basic_block_for_fn (cfun)); @@ -960,6 +959,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) // If DOM info is available, spawn an oracle as well. create_relation_oracle (); create_infer_oracle (use_imm_uses); + create_gori (not_executable_flag, param_vrp_switch_limit); unsigned x, lim = last_basic_block_for_fn (cfun); // Calculate outgoing range info upfront. This will fully populate the @@ -969,7 +969,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) { basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); if (bb) - m_gori.map ()->exports (bb); + gori ().map ()->exports (bb); } m_update = new update_list (); } @@ -1000,7 +1000,7 @@ ranger_cache::dump (FILE *f) void ranger_cache::dump_bb (FILE *f, basic_block bb) { - m_gori.map ()->dump (f, bb, false); + gori ().map ()->dump (f, bb, false); m_on_entry.dump (f, bb); m_relation->dump (f, bb); } @@ -1033,8 +1033,8 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) current_p = false; if (had_global) current_p = r.singleton_p () - || m_temporal->current_p (name, m_gori.map ()->depend1 (name), - m_gori.map ()->depend2 (name)); + || m_temporal->current_p (name, gori ().map ()->depend1 (name), + gori ().map ()->depend2 (name)); else { // If no global value has been set and value is VARYING, fold the stmt @@ -1071,8 +1071,8 @@ ranger_cache::set_global_range (tree name, const vrange &r, bool changed) if (!changed) { // If there are dependencies, make sure this is not out of date. - if (!m_temporal->current_p (name, m_gori.map ()->depend1 (name), - m_gori.map ()->depend2 (name))) + if (!m_temporal->current_p (name, gori ().map ()->depend1 (name), + gori ().map ()->depend2 (name))) m_temporal->set_timestamp (name); return; } @@ -1097,7 +1097,7 @@ ranger_cache::set_global_range (tree name, const vrange &r, bool changed) if (r.singleton_p () || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ())) - m_gori.map ()->set_range_invariant (name); + gori ().map ()->set_range_invariant (name); m_temporal->set_timestamp (name); } @@ -1178,7 +1178,7 @@ ranger_cache::edge_range (vrange &r, edge e, tree name, enum rfd_mode mode) if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0) infer_oracle ().maybe_adjust_range (r, name, e->src); Value_Range er (TREE_TYPE (name)); - if (m_gori.edge_range_p (er, e, name, *this)) + if (gori ().edge_range_p (er, e, name, *this)) r.intersect (er); return true; } @@ -1230,7 +1230,7 @@ ranger_cache::block_range (vrange &r, basic_block bb, tree name, bool calc) // If there are no range calculations anywhere in the IL, global range // applies everywhere, so don't bother caching it. - if (!m_gori.has_edge_range_p (name)) + if (!gori ().has_edge_range_p (name)) return false; if (calc) @@ -1449,7 +1449,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) continue; // Check if the equiv has any ranges calculated. - if (!m_gori.has_edge_range_p (equiv_name)) + if (!gori ().has_edge_range_p (equiv_name)) continue; // Check if the equiv definition dominates this block @@ -1562,7 +1562,7 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) r.dump (dump_file); fprintf (dump_file, ", "); } - if (!r.undefined_p () || m_gori.has_edge_range_p (name, e)) + if (!r.undefined_p () || gori ().has_edge_range_p (name, e)) { m_update->add (node); if (DEBUG_RANGE_CACHE) @@ -1671,7 +1671,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, infer_oracle ().maybe_adjust_range (infer, name, bb); // This block has an outgoing range. - if (m_gori.has_edge_range_p (name, bb)) + if (gori ().has_edge_range_p (name, bb)) m_workback.quick_push (prev_bb); else { @@ -1683,7 +1683,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, // If the first pred does not generate a range, then we will be // using the dominator range anyway, so that's all the check needed. if (EDGE_COUNT (prev_bb->preds) > 1 - && m_gori.has_edge_range_p (name, EDGE_PRED (prev_bb, 0)->src)) + && gori ().has_edge_range_p (name, EDGE_PRED (prev_bb, 0)->src)) { edge e; edge_iterator ei; @@ -1738,7 +1738,7 @@ ranger_cache::range_from_dom (vrange &r, tree name, basic_block start_bb, edge e = single_pred_edge (prev_bb); bb = e->src; - if (m_gori.edge_range_p (er, e, name, *this)) + if (gori ().edge_range_p (er, e, name, *this)) { r.intersect (er); // If this is a normal edge, apply any inferred ranges. @@ -1782,8 +1782,8 @@ ranger_cache::register_inferred_value (const vrange &ir, tree name, { m_on_entry.set_bb_range (name, bb, r); // If this range was invariant before, remove invariant. - if (!m_gori.has_edge_range_p (name)) - m_gori.map ()->set_range_invariant (name, false); + if (!gori ().has_edge_range_p (name)) + gori ().map ()->set_range_invariant (name, false); } } diff --git a/gcc/gimple-range-cache.h b/gcc/gimple-range-cache.h index e3ab89de02e..c7499f928a9 100644 --- a/gcc/gimple-range-cache.h +++ b/gcc/gimple-range-cache.h @@ -114,7 +114,6 @@ public: void register_inferred_value (const vrange &r, tree name, basic_block bb); void apply_inferred_ranges (gimple *s); - gori_compute m_gori; void dump_bb (FILE *f, basic_block bb); virtual void dump (FILE *f) override; diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index 37c16761ba6..e9e387c7d59 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -59,7 +59,7 @@ fur_source::fur_source (range_query *q) m_query = q; else m_query = get_range_query (cfun); - m_gori = NULL; + m_depend_p = false; } // Invoke range_of_expr on EXPR. @@ -184,11 +184,10 @@ fur_stmt::query_relation (tree op1, tree op2) // Instantiate a stmt based fur_source with a GORI object. -fur_depend::fur_depend (gimple *s, gori_compute *gori, range_query *q) +fur_depend::fur_depend (gimple *s, range_query *q) : fur_stmt (s, q) { - gcc_checking_assert (gori); - m_gori = gori; + m_depend_p = true; } // Register a relation on a stmt if there is an oracle. diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index d974b0192c8..9ae6cf56d2a 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -106,7 +106,8 @@ class fur_source public: fur_source (range_query *q = NULL); inline range_query *query () { return m_query; } - inline class gori_compute *gori () { return m_gori; }; + inline class gimple_outgoing_range *gori () + { return m_depend_p ? &(m_query->gori ()) : NULL; } virtual bool get_operand (vrange &r, tree expr); virtual bool get_phi_operand (vrange &r, tree expr, edge e); virtual relation_kind query_relation (tree op1, tree op2); @@ -117,7 +118,7 @@ public: void register_outgoing_edges (gcond *, irange &lhs_range, edge e0, edge e1); protected: range_query *m_query; - gori_compute *m_gori; + bool m_depend_p; }; // fur_stmt is the specification for drawing an operand from range_query Q @@ -140,7 +141,7 @@ private: class fur_depend : public fur_stmt { public: - fur_depend (gimple *s, gori_compute *gori, range_query *q = NULL); + fur_depend (gimple *s, range_query *q = NULL); virtual void register_relation (gimple *stmt, relation_kind k, tree op1, tree op2) override; virtual void register_relation (edge e, relation_kind k, tree op1, diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 03f73218a57..707bd0ebd94 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -44,6 +44,8 @@ path_range_query::path_range_query (gimple_ranger &ranger, m_ranger (ranger), m_resolve (resolve) { + share_query (ranger); + // Override the relation oracle with a local path relation oracle. m_relation = new path_oracle (&(m_ranger.relation ())); reset_path (path, dependencies); @@ -54,6 +56,8 @@ path_range_query::path_range_query (gimple_ranger &ranger, bool resolve) m_ranger (ranger), m_resolve (resolve) { + share_query (ranger); + // Override the relation oracle with a local path relation oracle. m_relation = new path_oracle (&(m_ranger.relation ())); } @@ -303,7 +307,7 @@ path_range_query::range_defined_in_block (vrange &r, tree name, basic_block bb) } if (bb && POINTER_TYPE_P (TREE_TYPE (name))) - m_ranger.infer_oracle ().maybe_adjust_range (r, name, bb); + infer_oracle ().maybe_adjust_range (r, name, bb); if (DEBUG_SOLVER && (bb || !r.varying_p ())) { @@ -409,13 +413,12 @@ path_range_query::compute_ranges_in_block (basic_block bb) p->reset_path (); } - gori_compute &g = m_ranger.gori (); - bitmap exports = g.map()->exports (bb); + bitmap exports = gori ().map ()->exports (bb); EXECUTE_IF_AND_IN_BITMAP (m_exit_dependencies, exports, 0, i, bi) { tree name = ssa_name (i); Value_Range r (TREE_TYPE (name)); - if (g.edge_range_p (r, e, name, *this)) + if (gori ().edge_range_p (r, e, name, *this)) { Value_Range cached_range (TREE_TYPE (name)); if (get_cache (cached_range, name)) @@ -463,7 +466,7 @@ path_range_query::adjust_for_non_null_uses (basic_block bb) else r.set_varying (TREE_TYPE (name)); - if (m_ranger.infer_oracle ().maybe_adjust_range (r, name, bb)) + if (infer_oracle ().maybe_adjust_range (r, name, bb)) m_cache.set_range (name, r); } } @@ -487,8 +490,7 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) { // Start with the imports from the exit block... basic_block exit = m_path[0]; - gori_compute &gori = m_ranger.gori (); - bitmap_copy (dependencies, gori.map()->imports (exit)); + bitmap_copy (dependencies, gori ().map()->imports (exit)); auto_vec worklist (bitmap_count_bits (dependencies)); bitmap_iterator bi; @@ -536,7 +538,7 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) { basic_block bb = m_path[i]; tree name; - FOR_EACH_GORI_EXPORT_NAME (*(gori.map ()), bb, name) + FOR_EACH_GORI_EXPORT_NAME (*(gori ().map ()), bb, name) if (TREE_CODE (TREE_TYPE (name)) == BOOLEAN_TYPE) bitmap_set_bit (dependencies, SSA_NAME_VERSION (name)); } @@ -611,8 +613,7 @@ path_range_query::compute_ranges (const bitmap_head *dependencies) class jt_fur_source : public fur_depend { public: - jt_fur_source (gimple *s, path_range_query *, gori_compute *, - const vec &); + jt_fur_source (gimple *s, path_range_query *, const vec &); relation_kind query_relation (tree op1, tree op2) override; void register_relation (gimple *, relation_kind, tree op1, tree op2) override; void register_relation (edge, relation_kind, tree op1, tree op2) override; @@ -622,9 +623,8 @@ private: jt_fur_source::jt_fur_source (gimple *s, path_range_query *query, - gori_compute *gori, const vec &path) - : fur_depend (s, gori, query) + : fur_depend (s, query) { gcc_checking_assert (!path.is_empty ()); @@ -671,7 +671,7 @@ path_range_query::range_of_stmt (vrange &r, gimple *stmt, tree) if (m_resolve) { fold_using_range f; - jt_fur_source src (stmt, this, &m_ranger.gori (), m_path); + jt_fur_source src (stmt, this, m_path); if (!f.fold_stmt (r, stmt, src)) r.set_varying (type); } @@ -761,7 +761,7 @@ path_range_query::compute_outgoing_relations (basic_block bb, basic_block next) else gcc_unreachable (); - jt_fur_source src (NULL, this, &m_ranger.gori (), m_path); + jt_fur_source src (NULL, this, m_path); src.register_outgoing_edges (cond, r, e0, e1); } } diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index e7e6fd86581..20294612185 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -273,7 +273,7 @@ bool gimple_ranger::fold_range_internal (vrange &r, gimple *s, tree name) { fold_using_range f; - fur_depend src (s, &(gori ()), this); + fur_depend src (s, this); return f.fold_stmt (r, s, src, name); } @@ -310,7 +310,7 @@ gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name) // Update any exports in the cache if this is a gimple cond statement. tree exp; basic_block bb = gimple_bb (s); - FOR_EACH_GORI_EXPORT_NAME (*(m_cache.m_gori.map ()), bb, exp) + FOR_EACH_GORI_EXPORT_NAME (*(gori ().map ()), bb, exp) m_cache.propagate_updated_value (exp, bb); } } @@ -755,6 +755,7 @@ assume_query::range_of_expr (vrange &r, tree expr, gimple *stmt) assume_query::assume_query () { + create_gori (0, param_vrp_switch_limit); basic_block exit_bb = EXIT_BLOCK_PTR_FOR_FN (cfun); if (single_pred_p (exit_bb)) { @@ -785,6 +786,11 @@ assume_query::assume_query () } } +assume_query::~assume_query () +{ + destroy_gori (); +} + // Evaluate operand OP on statement S, using the provided LHS range. // If successful, set the range in the global table, then visit OP's def stmt. @@ -792,7 +798,7 @@ void assume_query::calculate_op (tree op, gimple *s, vrange &lhs, fur_source &src) { Value_Range op_range (TREE_TYPE (op)); - if (m_gori.compute_operand_range (op_range, s, lhs, op, src) + if (gori ().compute_operand_range (op_range, s, lhs, op, src) && !op_range.varying_p ()) { // Set the global range, merging if there is already a range. diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 167b54b2a37..1532951a449 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -55,7 +55,6 @@ public: virtual bool range_on_entry (vrange &r, basic_block bb, tree name) override; virtual bool range_on_exit (vrange &r, basic_block bb, tree name) override; void export_global_ranges (); - inline gori_compute &gori () { return m_cache.m_gori; } virtual void dump (FILE *f) override; void debug (); void dump_bb (FILE *f, basic_block bb); @@ -87,6 +86,7 @@ class assume_query : public range_query { public: assume_query (); + ~assume_query (); bool assume_range_p (vrange &r, tree name); virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL); void dump (FILE *f); @@ -97,7 +97,6 @@ protected: void check_taken_edge (edge e, fur_source &src); ssa_lazy_cache global; - gori_compute m_gori; }; // DOM based ranger for fast VRP. diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 81c8b16fd12..67c87bbd19e 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -1430,8 +1430,7 @@ dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb) return; tree name; - gori_compute &gori = m_ranger->gori (); - FOR_EACH_GORI_EXPORT_NAME (*(gori.map()), pred_e->src, name) + FOR_EACH_GORI_EXPORT_NAME (*(m_ranger->gori ().map()), pred_e->src, name) if (all_uses_feed_or_dominated_by_stmt (name, stmt) // The condition must post-dominate the definition point. && (SSA_NAME_IS_DEFAULT_DEF (name) diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc index f5268d45516..766b68a007b 100644 --- a/gcc/tree-ssa-threadedge.cc +++ b/gcc/tree-ssa-threadedge.cc @@ -1446,10 +1446,8 @@ hybrid_jt_simplifier::compute_exit_dependencies (bitmap dependencies, const vec &path, gimple *stmt) { - gori_compute &gori = m_ranger->gori (); - // Start with the imports to the final conditional. - bitmap_copy (dependencies, gori.map ()->imports (path[0])); + bitmap_copy (dependencies, m_ranger->gori ().map ()->imports (path[0])); // Add any other interesting operands we may have missed. if (gimple_bb (stmt) != path[0]) diff --git a/gcc/value-query.cc b/gcc/value-query.cc index 41b581b20be..db813ad3094 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -182,6 +182,23 @@ range_query::dump (FILE *) // can be used anywhere. relation_oracle default_relation_oracle; infer_range_oracle default_infer_oracle; +gimple_outgoing_range default_gori; + +void +range_query::create_gori (int not_executable_flag, int sw_max_edges) +{ + gcc_checking_assert (m_gori == &default_gori); + m_gori = new gori_compute (not_executable_flag, sw_max_edges); + gcc_checking_assert (m_gori); +} + +void +range_query::destroy_gori () +{ + if (m_gori && m_gori != &default_gori) + delete m_gori; + m_gori= &default_gori; +} void range_query::create_infer_oracle (bool do_search) @@ -233,6 +250,7 @@ range_query::share_query (range_query &q) { m_relation = q.m_relation; m_infer = q.m_infer; + m_gori = q.m_gori; m_shared_copy_p = true; } @@ -240,6 +258,7 @@ range_query::range_query () { m_relation = &default_relation_oracle; m_infer = &default_infer_oracle; + m_gori = &default_gori; m_shared_copy_p = false; } @@ -248,6 +267,7 @@ range_query::~range_query () // Do not destroy anything if this is a shared copy. if (m_shared_copy_p) return; + destroy_gori (); destroy_infer_oracle (); destroy_relation_oracle (); } diff --git a/gcc/value-query.h b/gcc/value-query.h index 2f65d95bc9b..1481f532d60 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -83,6 +83,10 @@ public: void create_infer_oracle (bool do_search = TRUE); void destroy_infer_oracle (); + inline class gimple_outgoing_range &gori () const { return *m_gori; } + void create_gori (int not_executable_flag = 0, int sw_max_edges = INT_MAX); + void destroy_gori (); + virtual void dump (FILE *); protected: @@ -93,6 +97,7 @@ protected: bool get_arith_expr_range (vrange &r, tree expr, gimple *stmt); relation_oracle *m_relation; infer_range_oracle *m_infer; + gimple_outgoing_range *m_gori; // When multiple related range queries wish to share oracles. // This is an internal interface void share_query (range_query &q); -- 2.41.0 From patchwork Thu May 23 20:53:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bUmehoWz; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgWc1fmpz20KL for ; Fri, 24 May 2024 06:58:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 753EF384AB43 for ; Thu, 23 May 2024 20:58:49 +0000 (GMT) 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 ESMTPS id 56A823865C2D for ; Thu, 23 May 2024 20:53:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56A823865C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 56A823865C2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497632; cv=none; b=Eyauo0pJqN7ag7MgrL7Msq6P9gVhweIZbX3QdcMP9KM6q2pH9s+nnNo4qlfvnedRjYFAAkdAZ8njRD5lBI60knsgzZZ5tzI0b6xewm9KqJsOH4+Yu4afuPTLecvSuLcWPGnyo52bCera9r/pUhA9u++6jZKA/s+dlXPfdvpJ8QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497632; c=relaxed/simple; bh=KEZa7DzHTK5kaU5sMaqG2KL6edyFxDeQ8YippbIylhU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=TzlBS6gyyMbimQbCgFX8MKoGzSGtCWwHsyQN4Dwl89rLCoJFygDhkp41NvT6x3FvDYMeesWzbg2GSu5MshgOywXdwmAZ8QZYA4LTpPPbKrtm/oX9/IHNTUsCGXsOuiZXO+b8L2QIuHFUUy/9CcChCM+ihmlIni9MYLTaUkZjzhA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497629; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=UvWGQfZOIv8Of+thDnQYBvMAo8zxTQiOKwu4/VFUAB8=; b=bUmehoWzBp4MNDHxgdymX40FXEPHPJxxXYZHO/TRfUcwplct7QudGJL1CukQx4rbVeX3Uz teZ1kxU+9evfbBoUJC1zBEBVLIJn5CUyePzr1kakwTkdP8Izcvl0nD8zrae529VDZ60C6P r3kN9Wojt3nawNFxPw8QVSTaS525gnc= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-U1DnZi-YO16h25pyOPubiQ-1; Thu, 23 May 2024 16:53:47 -0400 X-MC-Unique: U1DnZi-YO16h25pyOPubiQ-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-792c365cb16so59138485a.3 for ; Thu, 23 May 2024 13:53:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497626; x=1717102426; 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=5XQ99VImpBjcfLagILOt3gJEWWtsujhf7CetzGdRyA4=; b=c+es6Tn+DiWWDFJavqX6t6OkE5HtTu+fvpByqXgCUNwoogKGAjJDlXuik7DwfnQ85/ UKqZnDrFXCRlkcDW7uN3/DgDsAcviUwqrEn/FzAQOForjVRFFcHovopDfR7injJmnpJY oen/JlH1iAGQvo5x0CLr2wNaUryuWzddvkcpmYJoZkYx0t0wJcf0mu+rTArN+jxBq4Kw Iz217v+JvnE6JWbH/qljq5i0azUcv9z1TxYptOItuFp+jUzchOQs534m3UKF00lbPfop KYAa/n8J2WTURlBx0Q+37bSRG+xeNcRiZd59Bb6vlfxTSmnMUuhfWm0qRlqueVVOLkIp N0tQ== X-Gm-Message-State: AOJu0YxOJdSFMRaT16lIp3dYplxM3dYHWbUqsfN/FsSmRku1IA2XBGk8 eSFsSjxtefCXsNpDnAQ/5QzTGaY23ahJgqF0YfsalAmLWGBA6JmPlRNs5BOh++OVA0RYVQ4fgXC Dv2JSvMiuK/hFwtLT5Gun2J1TZYcoYG47Q62JHKnaE6epb4Et6ysm+KJqSetcliLoTj4VuU2eZf Q2dH6Lpgro0KnaRcGvLzGtMlbtyW2AWhgMBJ+yOQM= X-Received: by 2002:a05:620a:2886:b0:792:9482:a9a7 with SMTP id af79cd13be357-794ab09b909mr45342985a.44.1716497626399; Thu, 23 May 2024 13:53:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFLvGr2aIvH41fRbqvI6tBuFoQ2a05VxIzjF9pP2tG37yU3UnhFCIbV0Po3jEpvj5vD7TRGNg== X-Received: by 2002:a05:620a:2886:b0:792:9482:a9a7 with SMTP id af79cd13be357-794ab09b909mr45340885a.44.1716497625906; Thu, 23 May 2024 13:53:45 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:45 -0700 (PDT) Message-ID: <22156eab-ed26-4f81-870d-336b4d2b970b@redhat.com> Date: Thu, 23 May 2024 16:53:44 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches Cc: "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 11/12] - Make gori_map a shared component. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.2 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org This patch moves the gori_map object out of the gori object, and into the range query.   it is required by gori, and will be created simultaneously with gori. The dependency data it manages has uses outside of GORI, and this makes it easier to access by the fold_using_range routines, and others. Documentation is coming :-P, Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From e81eafd81d76cf4e8b03089a94857b4b52a66bc7 Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 21 May 2024 14:20:52 -0400 Subject: [PATCH 11/12] Make gori_map a shared component. Move gori_map dependency and import/export object into a range query and construct it simultaneously with a gori object. * gimple-range-cache.cc (ranger_cache::ranger_cache): Use gori_ssa. (ranger_cache::dump): Likewise. (ranger_cache::get_global_range): Likewise. (ranger_cache::set_global_range): Likewise. (ranger_cache::register_inferred_value): Likewise. * gimple-range-edge.h (gimple_outgoing_range::map): Remove. * gimple-range-fold.cc (fold_using_range::range_of_range_op): Use gori_ssa. (fold_using_range::range_of_address): Likewise. (fold_using_range::range_of_phi): Likewise. (fur_source::register_outgoing_edges): Likewise. * gimple-range-fold.h (fur_source::query): Make const. (gori_ssa): New. * gimple-range-gori.cc (gori_map::dump): Use 'this' pointer. (gori_compute::gori_compute): Construct with a gori_map. * gimple-range-gori.h (gori_compute:gori_compute): Change prototype. (gori_compute::map): Delete. (gori_compute::m_map): Change to a reference. (FOR_EACH_GORI_IMPORT_NAME): Change parameter gori to gorimap. (FOR_EACH_GORI_EXPORT_NAME): Likewise. * gimple-range-path.cc (path_range_query::compute_ranges_in_block): Use gori_ssa method. (path_range_query::compute_exit_dependencies): Likewise. * gimple-range.cc (gimple_ranger::range_of_stmt): Likewise. (gimple_ranger::register_transitive_inferred_ranges): Likewise. * tree-ssa-dom.cc (set_global_ranges_from_unreachable_edges): Likewise. * tree-ssa-threadedge.cc (compute_exit_dependencies): Likewise. * tree-vrp.cc (remove_unreachable::handle_early): Likewise. (remove_unreachable::remove_and_update_globals): Likewise. * value-query.cc (range_query::create_gori): Create gori map. (range_query::share_query): Copy gori map member. (range_query::range_query): Initiialize gori_map member. * value-query.h (range_query::gori_ssa): New. (range_query::m_map): New. --- gcc/gimple-range-cache.cc | 16 ++++++++-------- gcc/gimple-range-edge.h | 1 - gcc/gimple-range-fold.cc | 22 +++++++++++----------- gcc/gimple-range-fold.h | 4 +++- gcc/gimple-range-gori.cc | 9 +++++---- gcc/gimple-range-gori.h | 14 +++++++------- gcc/gimple-range-path.cc | 6 +++--- gcc/gimple-range.cc | 6 +++--- gcc/tree-ssa-dom.cc | 2 +- gcc/tree-ssa-threadedge.cc | 2 +- gcc/tree-vrp.cc | 8 ++++---- gcc/value-query.cc | 6 +++++- gcc/value-query.h | 2 ++ 13 files changed, 53 insertions(+), 45 deletions(-) diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index e75cac66902..a511a2c3a4c 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -969,7 +969,7 @@ ranger_cache::ranger_cache (int not_executable_flag, bool use_imm_uses) { basic_block bb = BASIC_BLOCK_FOR_FN (cfun, x); if (bb) - gori ().map ()->exports (bb); + gori_ssa ()->exports (bb); } m_update = new update_list (); } @@ -1000,7 +1000,7 @@ ranger_cache::dump (FILE *f) void ranger_cache::dump_bb (FILE *f, basic_block bb) { - gori ().map ()->dump (f, bb, false); + gori_ssa ()->dump (f, bb, false); m_on_entry.dump (f, bb); m_relation->dump (f, bb); } @@ -1033,8 +1033,8 @@ ranger_cache::get_global_range (vrange &r, tree name, bool ¤t_p) current_p = false; if (had_global) current_p = r.singleton_p () - || m_temporal->current_p (name, gori ().map ()->depend1 (name), - gori ().map ()->depend2 (name)); + || m_temporal->current_p (name, gori_ssa ()->depend1 (name), + gori_ssa ()->depend2 (name)); else { // If no global value has been set and value is VARYING, fold the stmt @@ -1071,8 +1071,8 @@ ranger_cache::set_global_range (tree name, const vrange &r, bool changed) if (!changed) { // If there are dependencies, make sure this is not out of date. - if (!m_temporal->current_p (name, gori ().map ()->depend1 (name), - gori ().map ()->depend2 (name))) + if (!m_temporal->current_p (name, gori_ssa ()->depend1 (name), + gori_ssa ()->depend2 (name))) m_temporal->set_timestamp (name); return; } @@ -1097,7 +1097,7 @@ ranger_cache::set_global_range (tree name, const vrange &r, bool changed) if (r.singleton_p () || (POINTER_TYPE_P (TREE_TYPE (name)) && r.nonzero_p ())) - gori ().map ()->set_range_invariant (name); + gori_ssa ()->set_range_invariant (name); m_temporal->set_timestamp (name); } @@ -1783,7 +1783,7 @@ ranger_cache::register_inferred_value (const vrange &ir, tree name, m_on_entry.set_bb_range (name, bb, r); // If this range was invariant before, remove invariant. if (!gori ().has_edge_range_p (name)) - gori ().map ()->set_range_invariant (name, false); + gori_ssa ()->set_range_invariant (name, false); } } diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h index be1f0c2cc15..0096c02faf4 100644 --- a/gcc/gimple-range-edge.h +++ b/gcc/gimple-range-edge.h @@ -63,7 +63,6 @@ public: fur_source &, class value_relation * = NULL) { return false; } - virtual class gori_map *map () { return NULL; } private: void calc_switch_ranges (gswitch *sw); bool switch_edge_range (irange &r, gswitch *sw, edge e); diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index e9e387c7d59..a0ff7f2b98b 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -745,8 +745,8 @@ fold_using_range::range_of_range_op (vrange &r, r.set_varying (type); if (lhs && gimple_range_ssa_p (op1)) { - if (src.gori ()) - src.gori ()->map ()->register_dependency (lhs, op1); + if (src.gori_bb ()) + src.gori_bb ()->register_dependency (lhs, op1); relation_kind rel; rel = handler.lhs_op1_relation (r, range1, range1); if (rel != VREL_VARYING) @@ -772,10 +772,10 @@ fold_using_range::range_of_range_op (vrange &r, relation_fold_and_or (as_a (r), s, src, range1, range2); if (lhs) { - if (src.gori ()) + if (src.gori_bb ()) { - src.gori ()->map ()->register_dependency (lhs, op1); - src.gori ()->map ()->register_dependency (lhs, op2); + src.gori_bb ()->register_dependency (lhs, op1); + src.gori_bb ()->register_dependency (lhs, op2); } if (gimple_range_ssa_p (op1)) { @@ -843,8 +843,8 @@ fold_using_range::range_of_address (prange &r, gimple *stmt, fur_source &src) { tree ssa = TREE_OPERAND (base, 0); tree lhs = gimple_get_lhs (stmt); - if (lhs && gimple_range_ssa_p (ssa) && src.gori ()) - src.gori ()->map ()->register_dependency (lhs, ssa); + if (lhs && gimple_range_ssa_p (ssa) && src.gori_bb ()) + src.gori_bb ()->register_dependency (lhs, ssa); src.get_operand (r, ssa); range_cast (r, TREE_TYPE (gimple_assign_rhs1 (stmt))); @@ -950,8 +950,8 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) else r.union_ (arg_range); - if (gimple_range_ssa_p (arg) && src.gori ()) - src.gori ()->map ()->register_dependency (phi_def, arg); + if (gimple_range_ssa_p (arg) && src.gori_bb ()) + src.gori_bb ()->register_dependency (phi_def, arg); } // Track if all arguments are the same. @@ -1345,14 +1345,14 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, } // Outgoing relations of GORI exports require a gori engine. - if (!gori ()) + if (!gori_bb ()) return; // Now look for other relations in the exports. This will find stmts // leading to the condition such as: // c_2 = a_4 < b_7 // if (c_2) - FOR_EACH_GORI_EXPORT_NAME (*(gori ()->map ()), bb, name) + FOR_EACH_GORI_EXPORT_NAME (gori_bb (), bb, name) { if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE) continue; diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index 9ae6cf56d2a..b240a6e4c61 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -105,7 +105,9 @@ class fur_source { public: fur_source (range_query *q = NULL); - inline range_query *query () { return m_query; } + inline range_query *query () const { return m_query; } + inline gori_map *gori_bb () const + { return (m_depend_p && m_query) ? m_query->gori_ssa () : NULL; } inline class gimple_outgoing_range *gori () { return m_depend_p ? &(m_query->gori ()) : NULL; } virtual bool get_operand (vrange &r, tree expr); diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index a7543064258..a3fe67ede4e 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -514,7 +514,7 @@ gori_map::dump (FILE *f, basic_block bb, bool verbose) fprintf (f, "bb<%u> Imports: ",bb->index); else fprintf (f, "Imports: "); - FOR_EACH_GORI_IMPORT_NAME (*this, bb, name) + FOR_EACH_GORI_IMPORT_NAME (this, bb, name) { print_generic_expr (f, name, TDF_SLIM); fprintf (f, " "); @@ -527,7 +527,7 @@ gori_map::dump (FILE *f, basic_block bb, bool verbose) else fprintf (f, "Exports: "); // Dump the export vector. - FOR_EACH_GORI_EXPORT_NAME (*this, bb, name) + FOR_EACH_GORI_EXPORT_NAME (this, bb, name) { print_generic_expr (f, name, TDF_SLIM); fprintf (f, " "); @@ -557,8 +557,9 @@ debug (gori_map &g) // Construct a gori_compute object. -gori_compute::gori_compute (int not_executable_flag, int sw_max_edges) - : gimple_outgoing_range (sw_max_edges), tracer ("GORI ") +gori_compute::gori_compute (gori_map &map, int not_executable_flag, + int sw_max_edges) + : gimple_outgoing_range (sw_max_edges), m_map (map), tracer ("GORI ") { m_not_executable_flag = not_executable_flag; // Create a boolean_type true and false range. diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index c7a707ee724..aa8369a6823 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -164,7 +164,8 @@ class value_relation; class gori_compute : public gimple_outgoing_range { public: - gori_compute (int not_executable_flag = 0, int max_sw_edges = 0); + gori_compute (gori_map &map, int not_executable_flag = 0, + int max_sw_edges = 0); virtual ~gori_compute (); bool edge_range_p (vrange &r, edge e, tree name, range_query &q); bool condexpr_adjust (vrange &r1, vrange &r2, gimple *s, tree cond, tree op1, @@ -175,9 +176,8 @@ public: bool compute_operand_range (vrange &r, gimple *stmt, const vrange &lhs, tree name, class fur_source &src, value_relation *rel = NULL); - gori_map *map () { return &m_map; } private: - gori_map m_map; + gori_map &m_map; bool refine_using_relation (tree op1, vrange &op1_range, tree op2, vrange &op2_range, fur_source &src, relation_kind k); @@ -226,14 +226,14 @@ bool gori_on_edge (class ssa_cache &r, edge e, bool gori_name_on_edge (vrange &r, tree name, edge e, range_query *q = NULL); // 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))); \ +#define FOR_EACH_GORI_IMPORT_NAME(gorimap, bb, name) \ + for (gori_export_iterator iter ((gorimap)->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))); \ +#define FOR_EACH_GORI_EXPORT_NAME(gorimap, bb, name) \ + for (gori_export_iterator iter ((gorimap)->exports ((bb))); \ ((name) = iter.get_name ()); \ iter.next ()) diff --git a/gcc/gimple-range-path.cc b/gcc/gimple-range-path.cc index 707bd0ebd94..ef125a90882 100644 --- a/gcc/gimple-range-path.cc +++ b/gcc/gimple-range-path.cc @@ -413,7 +413,7 @@ path_range_query::compute_ranges_in_block (basic_block bb) p->reset_path (); } - bitmap exports = gori ().map ()->exports (bb); + bitmap exports = gori_ssa ()->exports (bb); EXECUTE_IF_AND_IN_BITMAP (m_exit_dependencies, exports, 0, i, bi) { tree name = ssa_name (i); @@ -490,7 +490,7 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) { // Start with the imports from the exit block... basic_block exit = m_path[0]; - bitmap_copy (dependencies, gori ().map()->imports (exit)); + bitmap_copy (dependencies, gori_ssa ()->imports (exit)); auto_vec worklist (bitmap_count_bits (dependencies)); bitmap_iterator bi; @@ -538,7 +538,7 @@ path_range_query::compute_exit_dependencies (bitmap dependencies) { basic_block bb = m_path[i]; tree name; - FOR_EACH_GORI_EXPORT_NAME (*(gori ().map ()), bb, name) + FOR_EACH_GORI_EXPORT_NAME (gori_ssa (), bb, name) if (TREE_CODE (TREE_TYPE (name)) == BOOLEAN_TYPE) bitmap_set_bit (dependencies, SSA_NAME_VERSION (name)); } diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index 20294612185..0749c9fa215 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -310,7 +310,7 @@ gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name) // Update any exports in the cache if this is a gimple cond statement. tree exp; basic_block bb = gimple_bb (s); - FOR_EACH_GORI_EXPORT_NAME (*(gori ().map ()), bb, exp) + FOR_EACH_GORI_EXPORT_NAME (gori_ssa (), bb, exp) m_cache.propagate_updated_value (exp, bb); } } @@ -540,8 +540,8 @@ gimple_ranger::register_transitive_inferred_ranges (basic_block bb) // an inferred range as well. Value_Range r (TREE_TYPE (lhs)); r.set_undefined (); - tree name1 = gori ().map () ->depend1 (lhs); - tree name2 = gori ().map ()->depend2 (lhs); + tree name1 = gori_ssa ()->depend1 (lhs); + tree name2 = gori_ssa ()->depend2 (lhs); if ((name1 && infer_oracle ().has_range_p (bb, name1)) || (name2 && infer_oracle ().has_range_p (bb, name2))) { diff --git a/gcc/tree-ssa-dom.cc b/gcc/tree-ssa-dom.cc index 67c87bbd19e..800bc5a4117 100644 --- a/gcc/tree-ssa-dom.cc +++ b/gcc/tree-ssa-dom.cc @@ -1430,7 +1430,7 @@ dom_opt_dom_walker::set_global_ranges_from_unreachable_edges (basic_block bb) return; tree name; - FOR_EACH_GORI_EXPORT_NAME (*(m_ranger->gori ().map()), pred_e->src, name) + FOR_EACH_GORI_EXPORT_NAME (m_ranger->gori_ssa (), pred_e->src, name) if (all_uses_feed_or_dominated_by_stmt (name, stmt) // The condition must post-dominate the definition point. && (SSA_NAME_IS_DEFAULT_DEF (name) diff --git a/gcc/tree-ssa-threadedge.cc b/gcc/tree-ssa-threadedge.cc index 766b68a007b..70f269e29fb 100644 --- a/gcc/tree-ssa-threadedge.cc +++ b/gcc/tree-ssa-threadedge.cc @@ -1447,7 +1447,7 @@ hybrid_jt_simplifier::compute_exit_dependencies (bitmap dependencies, gimple *stmt) { // Start with the imports to the final conditional. - bitmap_copy (dependencies, m_ranger->gori ().map ()->imports (path[0])); + bitmap_copy (dependencies, m_ranger->gori_ssa ()->imports (path[0])); // Add any other interesting operands we may have missed. if (gimple_bb (stmt) != path[0]) diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index be9df39f680..7d7f9fe2932 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -210,14 +210,14 @@ remove_unreachable::handle_early (gimple *s, edge e) // Check if every export use is dominated by this branch. tree name; - FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name) + FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori_ssa (), e->src, name) { if (!fully_replaceable (name, e->src)) return; } // Set the global value for each. - FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name) + FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori_ssa (), e->src, name) { Value_Range r (TREE_TYPE (name)); m_ranger.range_on_entry (r, e->dest, name); @@ -287,7 +287,7 @@ remove_unreachable::remove_and_update_globals () gcc_checking_assert (gimple_code (s) == GIMPLE_COND); bool dominate_exit_p = true; - FOR_EACH_GORI_EXPORT_NAME (*(m_ranger.gori ().map ()), e->src, name) + FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori_ssa (), e->src, name) { // Ensure the cache is set for NAME in the succ block. Value_Range r(TREE_TYPE (name)); @@ -305,7 +305,7 @@ remove_unreachable::remove_and_update_globals () // isn't the final VRP pass, leave the call in the IL. if (dominate_exit_p) bitmap_ior_into (all_exports, - m_ranger.gori ().map ()->exports (e->src)); + m_ranger.gori_ssa ()->exports (e->src)); else if (!final_p) continue; diff --git a/gcc/value-query.cc b/gcc/value-query.cc index db813ad3094..0d0c0e8058e 100644 --- a/gcc/value-query.cc +++ b/gcc/value-query.cc @@ -188,7 +188,9 @@ void range_query::create_gori (int not_executable_flag, int sw_max_edges) { gcc_checking_assert (m_gori == &default_gori); - m_gori = new gori_compute (not_executable_flag, sw_max_edges); + m_map = new gori_map (); + gcc_checking_assert (m_map); + m_gori = new gori_compute (*m_map, not_executable_flag, sw_max_edges); gcc_checking_assert (m_gori); } @@ -251,6 +253,7 @@ range_query::share_query (range_query &q) m_relation = q.m_relation; m_infer = q.m_infer; m_gori = q.m_gori; + m_map = q.m_map; m_shared_copy_p = true; } @@ -259,6 +262,7 @@ range_query::range_query () m_relation = &default_relation_oracle; m_infer = &default_infer_oracle; m_gori = &default_gori; + m_map = NULL; m_shared_copy_p = false; } diff --git a/gcc/value-query.h b/gcc/value-query.h index 1481f532d60..2572a03095d 100644 --- a/gcc/value-query.h +++ b/gcc/value-query.h @@ -84,6 +84,7 @@ public: void destroy_infer_oracle (); inline class gimple_outgoing_range &gori () const { return *m_gori; } + inline class gori_map *gori_ssa () const { return m_map; } void create_gori (int not_executable_flag = 0, int sw_max_edges = INT_MAX); void destroy_gori (); @@ -98,6 +99,7 @@ protected: relation_oracle *m_relation; infer_range_oracle *m_infer; gimple_outgoing_range *m_gori; + gori_map *m_map; // When multiple related range queries wish to share oracles. // This is an internal interface void share_query (range_query &q); -- 2.41.0 From patchwork Thu May 23 20:53:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1938591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Prkj7+JV; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VlgSZ4Nl8z20KL for ; Fri, 24 May 2024 06:56:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D8A9B386D60B for ; Thu, 23 May 2024 20:56:12 +0000 (GMT) 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 ESMTPS id 9C8D538654AD for ; Thu, 23 May 2024 20:53:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C8D538654AD Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9C8D538654AD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497638; cv=none; b=ifszB3Rrs2vUUTvmuxHiFzIt4kUL7Yz/mq2yCluYqMi55anUh7H8IWOI4LMl9xKFJxkh8HbIMDGIXLcvH+iDcINoJR8WwzEsBYibQA3697e99RnU9fE0rYeoMjyTWrZL0I8LSsAJxGEGsbD6bI/wYpmVzm9A7bwXv+lPkQx9guY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716497638; c=relaxed/simple; bh=Eq549oprKSbvcPRRD67foiad7GNoIof2aqqG0QZH9Ag=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=PSUad2MjlDcprFIRwh91RI5IedDUHxj4nHu18H2+aL/X6cp165InoCXaoUNjO/0OIQf6S8x3wLpsBT/eXQ5vrU0Gt/JhY1ocnHa5j6I1x0ZB1ERsrSnEhs6+i/rroEiFYMMA0AipkXoYKkn/c/xrF/N+eHEupnni9rdwJqHCHJQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716497634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=aGssTkz7IFpF9P5PxLeVK+FNGm9Y3TD5yOAy4G8Tt94=; b=Prkj7+JVj1yahXcJlWE7CWnQiArJrNuhn9pOGdkIZ6DAyAVWAJi/9B9P9BNmAKwX0dEls9 tWSQw31k6tNjyVHy/D2rScKgSghbSIxbsk8JX9I3uYtQ2bDe4dePlD3akEp0F+ppUj72bT uTRbno39C8plimBB821jWmnSmQRE5Rs= 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-602-XlkhDGnPOSeyIECL6KkXrA-1; Thu, 23 May 2024 16:53:53 -0400 X-MC-Unique: XlkhDGnPOSeyIECL6KkXrA-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-79308bfe615so60722785a.3 for ; Thu, 23 May 2024 13:53:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716497632; x=1717102432; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=B/e+SMcnyUQMcKsse8N190HlkXIp3nR+U6a9rnzAURU=; b=rEk/N2tZZPbFRdHFUeVfX/TiuGz6PVI05G1SusO9FWvPGH09nh+R+kQs+iWr8uQ1Ae U8QcKjVVgaUjX6VnH613zg3UOp76tkcIZpN98OOvZBCjD66g1+1hU6vkNZ7+7f4wyD5X t4BEai8DYXpFV4Chb7sS2r5MWJwKq3vrQ2UUB55rkqJytXc7cOWks18d1//X08udtNrl PDkV8olvGVzXmPvXJYO31RwydASEfpS2+YPNyjZiY+3f/DrlYEWuQ1NY1wZM73tBdheo CAwvwRdkrmFmA8BN0JKTL7O/tMSry/OPFOQ+zkCVwJbwiVtIRmtKQHaioyiHC/GQFalf n6lQ== X-Gm-Message-State: AOJu0YyMBcQy9Uo7ay4ukyMusBuW8BGcEjFNbZ4vc+D6FWmGRuKmYZwL osIANXi4wlHxDQ6+mJL09gXCJmGtI9OVe7wAhar9ELPc6CSQgNoHVjacov+U/avWcyCdChwbWUy RxPQqXtjZr6hw72wrujve437It9kK4HuLCmwjolaojSBU6e24kX5CHNQx2Cc38BxRIMM3V4sSIE hEbOzO3rxsysvL9i7BCcDXxbfsVRJ+MmGGvyQwElU= X-Received: by 2002:a05:620a:5647:b0:792:ba26:741d with SMTP id af79cd13be357-794ab093f88mr38695885a.33.1716497631888; Thu, 23 May 2024 13:53:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOtQIqNdMRwVQ1bC7wFvoDf9IWKHixxDeQ3GBpbQorTdc5+IPct/utdr9d1wlNGnCrRuwx3g== X-Received: by 2002:a05:620a:5647:b0:792:ba26:741d with SMTP id af79cd13be357-794ab093f88mr38693085a.33.1716497631098; Thu, 23 May 2024 13:53:51 -0700 (PDT) Received: from [192.168.0.174] ([104.219.121.64]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794abd48978sm202985a.132.2024.05.23.13.53.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 May 2024 13:53:50 -0700 (PDT) Message-ID: <4ec525b9-3d54-47a5-8fbc-b9538f2bbf09@redhat.com> Date: Thu, 23 May 2024 16:53:49 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: gcc-patches , "hernandez, aldy" From: Andrew MacLeod Subject: [COMMITTED 12/12] - Move condexpr_adjust into gimple-range-fold X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.2 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 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Certain components of GORI were needed in order to process a COND_EXPR expression and calculate the 2 operands as if they were true and false edges based on the condition.   With GORI available from the range_query object now, this can be moved into the fold_using_range code where it really belongs. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. From eb66da78b896ad5e7f6a315413ed68273c83662f Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Tue, 21 May 2024 12:41:49 -0400 Subject: [PATCH 12/12] Move condexpr_adjust into gimple-range-fold Certain components of GORI were needed in order to process a COND_EXPR expression and calculate the 2 operands as if they were true and false edges based on the condition. With GORI available from the range_query objcet now, this can be moved into the fold_using_range code where it really belongs. * gimple-range-edge.h (range_query::condexpr_adjust): Delete. * gimpe-range-fold.cc (fold_using_range::range_of_range_op): Use gori_ssa routine. (fold_using_range::range_of_address): Likewise. (fold_using_range::range_of_phi): Likewise. (fold_using_range::condexpr_adjust): Relocated from gori_compute. (fold_using_range::range_of_cond_expr): Use local condexpr_adjust. (fur_source::register_outgoing_edges): Use gori_ssa routine. * gimple-range-fold.h (gori_ssa): Rename from gori_bb. (fold_using_range::condexpr_adjust): Add prototype. * gimple-range-gori.cc (gori_compute::condexpr_adjust): Relocate. * gimple-range-gori.h (gori_compute::condexpr_adjust): Delete. --- gcc/gimple-range-edge.h | 4 +- gcc/gimple-range-fold.cc | 130 ++++++++++++++++++++++++++++++++------- gcc/gimple-range-fold.h | 4 +- gcc/gimple-range-gori.cc | 103 ------------------------------- gcc/gimple-range-gori.h | 2 - 5 files changed, 113 insertions(+), 130 deletions(-) diff --git a/gcc/gimple-range-edge.h b/gcc/gimple-range-edge.h index 0096c02faf4..0de1cca4294 100644 --- a/gcc/gimple-range-edge.h +++ b/gcc/gimple-range-edge.h @@ -54,13 +54,11 @@ public: virtual bool edge_range_p (vrange &, edge, tree, range_query &) { return false; } - virtual bool condexpr_adjust (vrange &, vrange &, gimple *, tree, tree, tree, - class fur_source &) { return false; } virtual bool has_edge_range_p (tree, basic_block = NULL) { return false; } virtual bool has_edge_range_p (tree, edge ) { return false; } virtual void dump (FILE *) { } virtual bool compute_operand_range (vrange &, gimple *, const vrange &, tree, - fur_source &, + class fur_source &, class value_relation * = NULL) { return false; } private: diff --git a/gcc/gimple-range-fold.cc b/gcc/gimple-range-fold.cc index a0ff7f2b98b..b3965b5ee50 100644 --- a/gcc/gimple-range-fold.cc +++ b/gcc/gimple-range-fold.cc @@ -745,8 +745,8 @@ fold_using_range::range_of_range_op (vrange &r, r.set_varying (type); if (lhs && gimple_range_ssa_p (op1)) { - if (src.gori_bb ()) - src.gori_bb ()->register_dependency (lhs, op1); + if (src.gori_ssa ()) + src.gori_ssa ()->register_dependency (lhs, op1); relation_kind rel; rel = handler.lhs_op1_relation (r, range1, range1); if (rel != VREL_VARYING) @@ -772,10 +772,10 @@ fold_using_range::range_of_range_op (vrange &r, relation_fold_and_or (as_a (r), s, src, range1, range2); if (lhs) { - if (src.gori_bb ()) + if (src.gori_ssa ()) { - src.gori_bb ()->register_dependency (lhs, op1); - src.gori_bb ()->register_dependency (lhs, op2); + src.gori_ssa ()->register_dependency (lhs, op1); + src.gori_ssa ()->register_dependency (lhs, op2); } if (gimple_range_ssa_p (op1)) { @@ -843,8 +843,8 @@ fold_using_range::range_of_address (prange &r, gimple *stmt, fur_source &src) { tree ssa = TREE_OPERAND (base, 0); tree lhs = gimple_get_lhs (stmt); - if (lhs && gimple_range_ssa_p (ssa) && src.gori_bb ()) - src.gori_bb ()->register_dependency (lhs, ssa); + if (lhs && gimple_range_ssa_p (ssa) && src.gori_ssa ()) + src.gori_ssa ()->register_dependency (lhs, ssa); src.get_operand (r, ssa); range_cast (r, TREE_TYPE (gimple_assign_rhs1 (stmt))); @@ -950,8 +950,8 @@ fold_using_range::range_of_phi (vrange &r, gphi *phi, fur_source &src) else r.union_ (arg_range); - if (gimple_range_ssa_p (arg) && src.gori_bb ()) - src.gori_bb ()->register_dependency (phi_def, arg); + if (gimple_range_ssa_p (arg) && src.gori_ssa ()) + src.gori_ssa ()->register_dependency (phi_def, arg); } // Track if all arguments are the same. @@ -1114,6 +1114,95 @@ fold_using_range::range_of_call (vrange &r, gcall *call, fur_source &) return true; } +// Given COND ? OP1 : OP2 with ranges R1 for OP1 and R2 for OP2, Use gori +// to further resolve R1 and R2 if there are any dependencies between +// OP1 and COND or OP2 and COND. All values can are to be calculated using SRC +// as the origination source location for operands.. +// Effectively, use COND an the edge condition and solve for OP1 on the true +// edge and OP2 on the false edge. + +bool +fold_using_range::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond, + tree op1, tree op2, fur_source &src) +{ + if (!src.gori () || !src.gori_ssa ()) + return false; + + tree ssa1 = gimple_range_ssa_p (op1); + tree ssa2 = gimple_range_ssa_p (op2); + if (!ssa1 && !ssa2) + return false; + if (TREE_CODE (cond) != SSA_NAME) + return false; + gassign *cond_def = dyn_cast (SSA_NAME_DEF_STMT (cond)); + if (!cond_def + || TREE_CODE_CLASS (gimple_assign_rhs_code (cond_def)) != tcc_comparison) + return false; + tree type = TREE_TYPE (gimple_assign_rhs1 (cond_def)); + if (!range_compatible_p (type, TREE_TYPE (gimple_assign_rhs2 (cond_def)))) + return false; + range_op_handler hand (gimple_assign_rhs_code (cond_def)); + if (!hand) + return false; + + tree c1 = gimple_range_ssa_p (gimple_assign_rhs1 (cond_def)); + tree c2 = gimple_range_ssa_p (gimple_assign_rhs2 (cond_def)); + + // Only solve if there is one SSA name in the condition. + if ((!c1 && !c2) || (c1 && c2)) + return false; + + // Pick up the current values of each part of the condition. + tree rhs1 = gimple_assign_rhs1 (cond_def); + tree rhs2 = gimple_assign_rhs2 (cond_def); + Value_Range cl (TREE_TYPE (rhs1)); + Value_Range cr (TREE_TYPE (rhs2)); + src.get_operand (cl, rhs1); + src.get_operand (cr, rhs2); + + tree cond_name = c1 ? c1 : c2; + gimple *def_stmt = SSA_NAME_DEF_STMT (cond_name); + + // Evaluate the value of COND_NAME on the true and false edges, using either + // the op1 or op2 routines based on its location. + Value_Range cond_true (type), cond_false (type); + if (c1) + { + if (!hand.op1_range (cond_false, type, range_false (), cr)) + return false; + if (!hand.op1_range (cond_true, type, range_true (), cr)) + return false; + cond_false.intersect (cl); + cond_true.intersect (cl); + } + else + { + if (!hand.op2_range (cond_false, type, range_false (), cl)) + return false; + if (!hand.op2_range (cond_true, type, range_true (), cl)) + return false; + cond_false.intersect (cr); + cond_true.intersect (cr); + } + + // Now solve for SSA1 or SSA2 if they are in the dependency chain. + if (ssa1 && src.gori_ssa()->in_chain_p (ssa1, cond_name)) + { + Value_Range tmp1 (TREE_TYPE (ssa1)); + if (src.gori ()->compute_operand_range (tmp1, def_stmt, cond_true, + ssa1, src)) + r1.intersect (tmp1); + } + if (ssa2 && src.gori_ssa ()->in_chain_p (ssa2, cond_name)) + { + Value_Range tmp2 (TREE_TYPE (ssa2)); + if (src.gori ()->compute_operand_range (tmp2, def_stmt, cond_false, + ssa2, src)) + r2.intersect (tmp2); + } + return true; +} + // Calculate a range for COND_EXPR statement S and return it in R. // If a range cannot be calculated, return false. @@ -1138,16 +1227,15 @@ fold_using_range::range_of_cond_expr (vrange &r, gassign *s, fur_source &src) src.get_operand (range2, op2); // Try to see if there is a dependence between the COND and either operand - if (src.gori ()) - if (src.gori ()->condexpr_adjust (range1, range2, s, cond, op1, op2, src)) - if (dump_file && (dump_flags & TDF_DETAILS)) - { - fprintf (dump_file, "Possible COND_EXPR adjustment. Range op1 : "); - range1.dump(dump_file); - fprintf (dump_file, " and Range op2: "); - range2.dump(dump_file); - fprintf (dump_file, "\n"); - } + if (condexpr_adjust (range1, range2, s, cond, op1, op2, src)) + if (dump_file && (dump_flags & TDF_DETAILS)) + { + fprintf (dump_file, "Possible COND_EXPR adjustment. Range op1 : "); + range1.dump(dump_file); + fprintf (dump_file, " and Range op2: "); + range2.dump(dump_file); + fprintf (dump_file, "\n"); + } // If the condition is known, choose the appropriate expression. if (cond_range.singleton_p ()) @@ -1345,14 +1433,14 @@ fur_source::register_outgoing_edges (gcond *s, irange &lhs_range, } // Outgoing relations of GORI exports require a gori engine. - if (!gori_bb ()) + if (!gori_ssa ()) return; // Now look for other relations in the exports. This will find stmts // leading to the condition such as: // c_2 = a_4 < b_7 // if (c_2) - FOR_EACH_GORI_EXPORT_NAME (gori_bb (), bb, name) + FOR_EACH_GORI_EXPORT_NAME (gori_ssa (), bb, name) { if (TREE_CODE (TREE_TYPE (name)) != BOOLEAN_TYPE) continue; diff --git a/gcc/gimple-range-fold.h b/gcc/gimple-range-fold.h index b240a6e4c61..491d57386f3 100644 --- a/gcc/gimple-range-fold.h +++ b/gcc/gimple-range-fold.h @@ -106,7 +106,7 @@ class fur_source public: fur_source (range_query *q = NULL); inline range_query *query () const { return m_query; } - inline gori_map *gori_bb () const + inline gori_map *gori_ssa () const { return (m_depend_p && m_query) ? m_query->gori_ssa () : NULL; } inline class gimple_outgoing_range *gori () { return m_depend_p ? &(m_query->gori ()) : NULL; } @@ -171,5 +171,7 @@ protected: fur_source &src); void relation_fold_and_or (irange& lhs_range, gimple *s, fur_source &src, vrange &op1, vrange &op2); + bool condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond, tree op1, + tree op2, fur_source &src); }; #endif // GCC_GIMPLE_RANGE_FOLD_H diff --git a/gcc/gimple-range-gori.cc b/gcc/gimple-range-gori.cc index a3fe67ede4e..0d471b46903 100644 --- a/gcc/gimple-range-gori.cc +++ b/gcc/gimple-range-gori.cc @@ -1452,109 +1452,6 @@ gori_compute::edge_range_p (vrange &r, edge e, tree name, range_query &q) return false; } -// Given COND ? OP1 : OP2 with ranges R1 for OP1 and R2 for OP2, Use gori -// to further resolve R1 and R2 if there are any dependencies between -// OP1 and COND or OP2 and COND. All values can are to be calculated using SRC -// as the origination source location for operands.. -// Effectively, use COND an the edge condition and solve for OP1 on the true -// edge and OP2 on the false edge. - -bool -gori_compute::condexpr_adjust (vrange &r1, vrange &r2, gimple *, tree cond, - tree op1, tree op2, fur_source &src) -{ - tree ssa1 = gimple_range_ssa_p (op1); - tree ssa2 = gimple_range_ssa_p (op2); - if (!ssa1 && !ssa2) - return false; - if (TREE_CODE (cond) != SSA_NAME) - return false; - gassign *cond_def = dyn_cast (SSA_NAME_DEF_STMT (cond)); - if (!cond_def - || TREE_CODE_CLASS (gimple_assign_rhs_code (cond_def)) != tcc_comparison) - return false; - tree type = TREE_TYPE (gimple_assign_rhs1 (cond_def)); - if (!range_compatible_p (type, TREE_TYPE (gimple_assign_rhs2 (cond_def)))) - return false; - range_op_handler hand (gimple_assign_rhs_code (cond_def)); - if (!hand) - return false; - - tree c1 = gimple_range_ssa_p (gimple_assign_rhs1 (cond_def)); - tree c2 = gimple_range_ssa_p (gimple_assign_rhs2 (cond_def)); - - // Only solve if there is one SSA name in the condition. - if ((!c1 && !c2) || (c1 && c2)) - return false; - - // Pick up the current values of each part of the condition. - tree rhs1 = gimple_assign_rhs1 (cond_def); - tree rhs2 = gimple_assign_rhs2 (cond_def); - Value_Range cl (TREE_TYPE (rhs1)); - Value_Range cr (TREE_TYPE (rhs2)); - src.get_operand (cl, rhs1); - src.get_operand (cr, rhs2); - - tree cond_name = c1 ? c1 : c2; - gimple *def_stmt = SSA_NAME_DEF_STMT (cond_name); - - // Evaluate the value of COND_NAME on the true and false edges, using either - // the op1 or op2 routines based on its location. - Value_Range cond_true (type), cond_false (type); - if (c1) - { - if (!hand.op1_range (cond_false, type, m_bool_zero, cr)) - return false; - if (!hand.op1_range (cond_true, type, m_bool_one, cr)) - return false; - cond_false.intersect (cl); - cond_true.intersect (cl); - } - else - { - if (!hand.op2_range (cond_false, type, m_bool_zero, cl)) - return false; - if (!hand.op2_range (cond_true, type, m_bool_one, cl)) - return false; - cond_false.intersect (cr); - cond_true.intersect (cr); - } - - unsigned idx; - if ((idx = tracer.header ("cond_expr evaluation : "))) - { - fprintf (dump_file, " range1 = "); - r1.dump (dump_file); - fprintf (dump_file, ", range2 = "); - r1.dump (dump_file); - fprintf (dump_file, "\n"); - } - - // Now solve for SSA1 or SSA2 if they are in the dependency chain. - if (ssa1 && m_map.in_chain_p (ssa1, cond_name)) - { - Value_Range tmp1 (TREE_TYPE (ssa1)); - if (compute_operand_range (tmp1, def_stmt, cond_true, ssa1, src)) - r1.intersect (tmp1); - } - if (ssa2 && m_map.in_chain_p (ssa2, cond_name)) - { - Value_Range tmp2 (TREE_TYPE (ssa2)); - if (compute_operand_range (tmp2, def_stmt, cond_false, ssa2, src)) - r2.intersect (tmp2); - } - if (idx) - { - tracer.print (idx, "outgoing: range1 = "); - r1.dump (dump_file); - fprintf (dump_file, ", range2 = "); - r1.dump (dump_file); - fprintf (dump_file, "\n"); - tracer.trailer (idx, "cond_expr", true, cond_name, cond_true); - } - return true; -} - // Dump what is known to GORI computes to listing file F. void diff --git a/gcc/gimple-range-gori.h b/gcc/gimple-range-gori.h index aa8369a6823..9b4bcd919f5 100644 --- a/gcc/gimple-range-gori.h +++ b/gcc/gimple-range-gori.h @@ -168,8 +168,6 @@ public: int max_sw_edges = 0); virtual ~gori_compute (); bool edge_range_p (vrange &r, edge e, tree name, range_query &q); - bool condexpr_adjust (vrange &r1, vrange &r2, gimple *s, tree cond, tree op1, - tree op2, fur_source &src); bool has_edge_range_p (tree name, basic_block bb = NULL); bool has_edge_range_p (tree name, edge e); void dump (FILE *f); -- 2.41.0