From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id 2B77D385803D; Thu, 22 Sep 2022 18:49:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B77D385803D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663872542; bh=xMZ5rZAhNAA74cBBwbb7BM61Nz3ek4Ylf/Po30+50tI=; h=From:To:Subject:Date:From; b=lYxp5pGLKRz2iGAAOPLcQFBa135lfjZ1NVp8IPSSFVvJNvmOltlJZTJ+WTvkKdenp +6GbPA7aX6UuFZOy8fqphbXASSYMIJb4lrOfGa4htYbKTnOceC6/l/4LqkD+uH4PjX MuBrC0Ao2V+1W5hDpRSs5EXGxO3p8feIi8upeZcQ= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Macleod To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2784] Adjust range_op_handler to store the handler directly. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/master X-Git-Oldrev: 3cba5cd6e019182dbff756f621af048d55cdda98 X-Git-Newrev: 24c473a14d3cbe6fc44997122b532cb9406497cb Message-Id: <20220922184902.2B77D385803D@sourceware.org> Date: Thu, 22 Sep 2022 18:49:02 +0000 (GMT) List-Id: https://gcc.gnu.org/g:24c473a14d3cbe6fc44997122b532cb9406497cb commit r13-2784-g24c473a14d3cbe6fc44997122b532cb9406497cb Author: Andrew MacLeod Date: Wed Aug 31 14:07:13 2022 -0400 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. Diff: --- 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);