From patchwork Thu Sep 22 18:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 57924 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC9FE3858005 for ; Thu, 22 Sep 2022 18:56:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC9FE3858005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663873005; bh=uurvdmFJndByZoPIzm5jGG91F/2JgZsck2Zevdd4ivU=; h=Date:Subject:To:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=PujJyd6xSyYjVHLu+7NGyFpW9ogvoh1R9MMlFp8DD8rEQRZtx6GIjR2k5aCH2295B StzxBRo2UlQuEF709/xbAxqJLQXxCfey3KQUn37NRneZtYBvSqCNBkHEtFk40NOuww 44/R4kQicUyoq4uMzKzLTqQmDgzVnLHGpCVBi86k= 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 9D4B83858D38 for ; Thu, 22 Sep 2022 18:55:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9D4B83858D38 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-592-WJ7-eTngM_SGWg8SRxJEVw-1; Thu, 22 Sep 2022 14:55:24 -0400 X-MC-Unique: WJ7-eTngM_SGWg8SRxJEVw-1 Received: by mail-io1-f69.google.com with SMTP id x22-20020a6bda16000000b006a123cb02beso5269615iob.18 for ; Thu, 22 Sep 2022 11:55:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:references:cc:to:from:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date; bh=97NnmpUTJjO568PXvlnekEPyNeu3tD6AmprRIu4ZoHI=; b=A5Abc2x9c/uUQf5o3hadZ5EGdDxD1CGzPATpQmLGpYTHk/Ac5raNHdYwTt2ficwCHo Qpq1vIKC7ZHOH6Z/UVCKppDFsevViNPYG8kzOPKkzIqyfppIBmeHmHc4M4kmhfH09EH0 beoLebJZoxf8O6786cB6DjymUgAPmKjLTIQ/88mvayIYiVwkvitdg29Rwa1UaLITX/MA oSoNyMw5PzXGMDNO6lgHDY7pp7HKSOYFVVFbjuEi0bPTfFp+GkHt5NCfIOf8poYSN5lx hqFAUU2djn1fLCdQgG/ayWnzuzhUd43V4mY8q6o+5R8zEQGLp88JMBgmls2ezJnXtKVg ogKA== X-Gm-Message-State: ACrzQf2QQ4yS8tWw/WklHs0EidjeSa6y9hXJZWfyirtW6l54LxdbSQPw vqZ6wsMuxy0RWsOWBBPrKxwDGTE5cu5nEkNEpf/pGv3Eztv1Lcct4oyk3RUQkWhN6EOO6AAmxcN V+/BeNgBP5GAX2ERIYuzcBRk5lODSGdX4/Jg01mG4ds0SpFdA51xt1JbfmklX1dM0X5hmqQ== X-Received: by 2002:a05:6e02:1148:b0:2f6:8c53:acb8 with SMTP id o8-20020a056e02114800b002f68c53acb8mr2446460ill.207.1663872923038; Thu, 22 Sep 2022 11:55:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7SXTFRncyk98nudyprFKbK58cYt5Vi7aOLbqGmRpYllFkYD10CkKo3CeC2PonH9f9+2ldyUw== X-Received: by 2002:a05:6e02:1148:b0:2f6:8c53:acb8 with SMTP id o8-20020a056e02114800b002f68c53acb8mr2446442ill.207.1663872922657; Thu, 22 Sep 2022 11:55:22 -0700 (PDT) Received: from ?IPV6:2607:fea8:a263:f600::3dbe? ([2607:fea8:a263:f600::3dbe]) by smtp.gmail.com with ESMTPSA id z7-20020a92cb87000000b002f54ab12613sm2297698ilo.1.2022.09.22.11.55.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Sep 2022 11:55:21 -0700 (PDT) Message-ID: <1c18ea06-495c-52f5-67ea-b116ef0df3bc@redhat.com> Date: Thu, 22 Sep 2022 14:55:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: [PATCH 02/17] Adjust range_op_handler to store the handler directly. To: gcc-patches References: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.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_LOW, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Range_op_handler currently stores a tree code and a type.  It defers checking to see if there is a valid handler until asked. This change checks at constructor time and store a pointer to the handler if there is one. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 24c473a14d3cbe6fc44997122b532cb9406497cb Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Wed, 31 Aug 2022 14:07:13 -0400 Subject: [PATCH 02/17] Adjust range_op_handler to store the handler directly. Range_op_handler currently stores a tree code and a type. It defers checking to see if there is a valid handler until asked. This change checks at constuctor time and store a pointer to the handler if there is one. * range-op.cc (range_op_handler::set_op_handler): Set new fields. (ange_op_handler::range_op_handler): Likewise. (range_op_handler::operator bool): Remove. (range_op_handler::fold_range): Use appropriate handler. (range_op_handler::op1_range): Likewise. (range_op_handler::op2_range): Likewise. (range_op_handler::lhs_op1_relation): Likewise. (range_op_handler::lhs_op2_relation): Likewise. (range_op_handler::op1_op2_relation): Likewise. * range-op.h (class range_op_handler): Store handler pointers. (range_op_handler:: operator bool): Inline. --- gcc/range-op.cc | 246 +++++++++++++++++++++--------------------------- gcc/range-op.h | 8 +- 2 files changed, 114 insertions(+), 140 deletions(-) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index 806edf1012e..f642b3f26de 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -4159,48 +4159,63 @@ get_float_handler (enum tree_code code, tree) return (*floating_tree_table)[code]; } +void +range_op_handler::set_op_handler (tree_code code, tree type) +{ + if (irange::supports_p (type)) + { + m_float = NULL; + m_int = get_handler (code, type); + m_valid = m_int != NULL; + } + else if (frange::supports_p (type)) + { + m_int = NULL; + m_float = get_float_handler (code, type); + m_valid = m_float != NULL; + } + else + { + m_int = NULL; + m_float = NULL; + m_valid = false; + } +} + range_op_handler::range_op_handler (tree_code code, tree type) - : m_code (code), m_type (type) { + set_op_handler (code, type); } range_op_handler::range_op_handler (const gimple *s) { + tree_code code = NOP_EXPR; + tree type = NULL_TREE; + if (const gassign *ass = dyn_cast (s)) { - m_code = gimple_assign_rhs_code (ass); + code = gimple_assign_rhs_code (ass); // The LHS of a comparison is always an int, so we must look at // the operands. - if (TREE_CODE_CLASS (m_code) == tcc_comparison) - m_type = TREE_TYPE (gimple_assign_rhs1 (ass)); + if (TREE_CODE_CLASS (code) == tcc_comparison) + type = TREE_TYPE (gimple_assign_rhs1 (ass)); else - m_type = TREE_TYPE (gimple_assign_lhs (ass)); + type = TREE_TYPE (gimple_assign_lhs (ass)); } else if (const gcond *cond = dyn_cast (s)) { - m_code = gimple_cond_code (cond); - m_type = TREE_TYPE (gimple_cond_lhs (cond)); + code = gimple_cond_code (cond); + type = TREE_TYPE (gimple_cond_lhs (cond)); } - else + + if (!type) { - // A null type means there is no handler for this combination, - // but the decision whether there is one or not, is delayed - // until operator bool below is queried. - m_code = NOP_EXPR; - m_type = nullptr; + m_int = NULL; + m_float = NULL; + m_valid = false; } -} - -// Return TRUE if there is a handler available for the current -// combination of tree_code and type. - -range_op_handler::operator bool () const -{ - if (!m_type) - return false; - if (frange::supports_p (m_type)) - return get_float_handler (m_code, m_type); - return get_handler (m_code, m_type); + else + set_op_handler (code, type); } bool @@ -4209,26 +4224,19 @@ range_op_handler::fold_range (vrange &r, tree type, const vrange &rh, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (r)) - return op->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); - return op->fold_range (as_a (r), type, - as_a (lh), - as_a (rh), rel); - } - gcc_unreachable (); - return false; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + + if (is_a (r)) + return m_float->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); + return m_float->fold_range (as_a (r), type, + as_a (lh), + as_a (rh), rel); } bool @@ -4237,26 +4245,19 @@ range_op_handler::op1_range (vrange &r, tree type, const vrange &op2, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->op1_range (as_a (r), type, - as_a (lhs), - as_a (op2), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->op1_range (as_a (r), type, - as_a (lhs), - as_a (op2), rel); - return op->op1_range (as_a (r), type, - as_a (lhs), - as_a (op2), rel); - } - gcc_unreachable (); - return false; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + + if (is_a (lhs)) + return m_float->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); + return m_float->op1_range (as_a (r), type, + as_a (lhs), + as_a (op2), rel); } bool @@ -4265,26 +4266,19 @@ range_op_handler::op2_range (vrange &r, tree type, const vrange &op1, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->op2_range (as_a (r), type, - as_a (lhs), - as_a (op1), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->op2_range (as_a (r), type, - as_a (lhs), - as_a (op1), rel); - return op->op2_range (as_a (r), type, - as_a (lhs), - as_a (op1), rel); - } - gcc_unreachable (); - return false; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); + + if (is_a (lhs)) + return m_float->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); + return m_float->op2_range (as_a (r), type, + as_a (lhs), + as_a (op1), rel); } relation_kind @@ -4293,26 +4287,19 @@ range_op_handler::lhs_op1_relation (const vrange &lhs, const vrange &op2, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->lhs_op1_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->lhs_op1_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - return op->lhs_op1_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - gcc_unreachable (); - return VREL_VARYING; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + + if (is_a (lhs)) + return m_float->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + return m_float->lhs_op1_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); } relation_kind @@ -4321,43 +4308,28 @@ range_op_handler::lhs_op2_relation (const vrange &lhs, const vrange &op2, relation_kind rel) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->lhs_op2_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - if (is_a (lhs)) - return op->lhs_op2_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - return op->lhs_op2_relation (as_a (lhs), - as_a (op1), - as_a (op2), rel); - } - gcc_unreachable (); - return VREL_VARYING; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->lhs_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + + if (is_a (lhs)) + return m_float->lhs_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); + return m_float->lhs_op2_relation (as_a (lhs), + as_a (op1), + as_a (op2), rel); } relation_kind range_op_handler::op1_op2_relation (const vrange &lhs) const { - if (irange::supports_p (m_type)) - { - range_operator *op = get_handler (m_code, m_type); - return op->op1_op2_relation (as_a (lhs)); - } - if (frange::supports_p (m_type)) - { - range_operator_float *op = get_float_handler (m_code, m_type); - return op->op1_op2_relation (as_a (lhs)); - } - gcc_unreachable (); - return VREL_VARYING; + gcc_checking_assert (m_valid); + if (m_int) + return m_int->op1_op2_relation (as_a (lhs)); + return m_float->op1_op2_relation (as_a (lhs)); } // Cast the range in R to TYPE. diff --git a/gcc/range-op.h b/gcc/range-op.h index 37d9aa91c46..56c57c46a8e 100644 --- a/gcc/range-op.h +++ b/gcc/range-op.h @@ -162,7 +162,7 @@ class range_op_handler public: range_op_handler (enum tree_code code, tree type); range_op_handler (const gimple *s); - operator bool () const; + inline operator bool () const { return m_valid; } bool fold_range (vrange &r, tree type, const vrange &lh, @@ -186,8 +186,10 @@ public: relation_kind = VREL_VARYING) const; relation_kind op1_op2_relation (const vrange &lhs) const; private: - enum tree_code m_code; - tree m_type; + void set_op_handler (enum tree_code code, tree type); + bool m_valid; + range_operator *m_int; + range_operator_float *m_float; }; extern bool range_cast (vrange &, tree type); -- 2.37.3