From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: "hernandez, aldy" <aldyh@redhat.com>
Subject: [PATCH 02/17] Adjust range_op_handler to store the handler directly.
Date: Thu, 22 Sep 2022 14:55:20 -0400 [thread overview]
Message-ID: <1c18ea06-495c-52f5-67ea-b116ef0df3bc@redhat.com> (raw)
In-Reply-To: <571782f9-72e6-5c30-da55-b8d62d3a153e@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 297 bytes --]
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
[-- Attachment #2: 0002-Adjust-range_op_handler-to-store-the-handler-directl.patch --]
[-- Type: text/x-patch, Size: 11445 bytes --]
From 24c473a14d3cbe6fc44997122b532cb9406497cb Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
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<const gassign *> (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<const gcond *> (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 <irange> (r), type,
- as_a <irange> (lh),
- as_a <irange> (rh), rel);
- }
- if (frange::supports_p (m_type))
- {
- range_operator_float *op = get_float_handler (m_code, m_type);
- if (is_a <irange> (r))
- return op->fold_range (as_a <irange> (r), type,
- as_a <frange> (lh),
- as_a <frange> (rh), rel);
- return op->fold_range (as_a <frange> (r), type,
- as_a <frange> (lh),
- as_a <frange> (rh), rel);
- }
- gcc_unreachable ();
- return false;
+ gcc_checking_assert (m_valid);
+ if (m_int)
+ return m_int->fold_range (as_a <irange> (r), type,
+ as_a <irange> (lh),
+ as_a <irange> (rh), rel);
+
+ if (is_a <irange> (r))
+ return m_float->fold_range (as_a <irange> (r), type,
+ as_a <frange> (lh),
+ as_a <frange> (rh), rel);
+ return m_float->fold_range (as_a <frange> (r), type,
+ as_a <frange> (lh),
+ as_a <frange> (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 <irange> (r), type,
- as_a <irange> (lhs),
- as_a <irange> (op2), rel);
- }
- if (frange::supports_p (m_type))
- {
- range_operator_float *op = get_float_handler (m_code, m_type);
- if (is_a <irange> (lhs))
- return op->op1_range (as_a <frange> (r), type,
- as_a <irange> (lhs),
- as_a <frange> (op2), rel);
- return op->op1_range (as_a <frange> (r), type,
- as_a <frange> (lhs),
- as_a <frange> (op2), rel);
- }
- gcc_unreachable ();
- return false;
+ gcc_checking_assert (m_valid);
+ if (m_int)
+ return m_int->op1_range (as_a <irange> (r), type,
+ as_a <irange> (lhs),
+ as_a <irange> (op2), rel);
+
+ if (is_a <irange> (lhs))
+ return m_float->op1_range (as_a <frange> (r), type,
+ as_a <irange> (lhs),
+ as_a <frange> (op2), rel);
+ return m_float->op1_range (as_a <frange> (r), type,
+ as_a <frange> (lhs),
+ as_a <frange> (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 <irange> (r), type,
- as_a <irange> (lhs),
- as_a <irange> (op1), rel);
- }
- if (frange::supports_p (m_type))
- {
- range_operator_float *op = get_float_handler (m_code, m_type);
- if (is_a <irange> (lhs))
- return op->op2_range (as_a <frange> (r), type,
- as_a <irange> (lhs),
- as_a <frange> (op1), rel);
- return op->op2_range (as_a <frange> (r), type,
- as_a <frange> (lhs),
- as_a <frange> (op1), rel);
- }
- gcc_unreachable ();
- return false;
+ gcc_checking_assert (m_valid);
+ if (m_int)
+ return m_int->op2_range (as_a <irange> (r), type,
+ as_a <irange> (lhs),
+ as_a <irange> (op1), rel);
+
+ if (is_a <irange> (lhs))
+ return m_float->op2_range (as_a <frange> (r), type,
+ as_a <irange> (lhs),
+ as_a <frange> (op1), rel);
+ return m_float->op2_range (as_a <frange> (r), type,
+ as_a <frange> (lhs),
+ as_a <frange> (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 <irange> (lhs),
- as_a <irange> (op1),
- as_a <irange> (op2), rel);
- }
- if (frange::supports_p (m_type))
- {
- range_operator_float *op = get_float_handler (m_code, m_type);
- if (is_a <irange> (lhs))
- return op->lhs_op1_relation (as_a <irange> (lhs),
- as_a <frange> (op1),
- as_a <frange> (op2), rel);
- return op->lhs_op1_relation (as_a <frange> (lhs),
- as_a <frange> (op1),
- as_a <frange> (op2), rel);
- }
- gcc_unreachable ();
- return VREL_VARYING;
+ gcc_checking_assert (m_valid);
+ if (m_int)
+ return m_int->lhs_op1_relation (as_a <irange> (lhs),
+ as_a <irange> (op1),
+ as_a <irange> (op2), rel);
+
+ if (is_a <irange> (lhs))
+ return m_float->lhs_op1_relation (as_a <irange> (lhs),
+ as_a <frange> (op1),
+ as_a <frange> (op2), rel);
+ return m_float->lhs_op1_relation (as_a <frange> (lhs),
+ as_a <frange> (op1),
+ as_a <frange> (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 <irange> (lhs),
- as_a <irange> (op1),
- as_a <irange> (op2), rel);
- }
- if (frange::supports_p (m_type))
- {
- range_operator_float *op = get_float_handler (m_code, m_type);
- if (is_a <irange> (lhs))
- return op->lhs_op2_relation (as_a <irange> (lhs),
- as_a <frange> (op1),
- as_a <frange> (op2), rel);
- return op->lhs_op2_relation (as_a <frange> (lhs),
- as_a <frange> (op1),
- as_a <frange> (op2), rel);
- }
- gcc_unreachable ();
- return VREL_VARYING;
+ gcc_checking_assert (m_valid);
+ if (m_int)
+ return m_int->lhs_op2_relation (as_a <irange> (lhs),
+ as_a <irange> (op1),
+ as_a <irange> (op2), rel);
+
+ if (is_a <irange> (lhs))
+ return m_float->lhs_op2_relation (as_a <irange> (lhs),
+ as_a <frange> (op1),
+ as_a <frange> (op2), rel);
+ return m_float->lhs_op2_relation (as_a <frange> (lhs),
+ as_a <frange> (op1),
+ as_a <frange> (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 <irange> (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 <irange> (lhs));
- }
- gcc_unreachable ();
- return VREL_VARYING;
+ gcc_checking_assert (m_valid);
+ if (m_int)
+ return m_int->op1_op2_relation (as_a <irange> (lhs));
+ return m_float->op1_op2_relation (as_a <irange> (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
next prev parent reply other threads:[~2022-09-22 18:55 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-22 18:49 [PATCH 00/17] Move builtin functions to range-ops Andrew MacLeod
2022-09-22 18:53 ` [PATCH 01/17] Replace another snippet with a call to, gimple_range_ssa_names Andrew MacLeod
2022-09-22 18:55 ` Andrew MacLeod [this message]
2022-09-22 18:56 ` [PATCH 03/17] Create gimple_range_op_handler in a new source file Andrew MacLeod
2022-09-22 18:58 ` [PATCH 04/17] Fix calc_op1 for undefined op2_range Andrew MacLeod
2022-09-22 18:59 ` [PATCH 05/17] Add missing float fold_range prototype for floats Andrew MacLeod
2022-09-22 19:00 ` [PATCH 06/17] Always check the return value of fold_range Andrew MacLeod
2022-09-22 19:01 ` [PATCH 07/17] Add range-ops support for builtin functions Andrew MacLeod
2022-09-22 19:02 ` [PATCH 08/17] Convert CFN_BUILT_IN_SIGNBIT to range-ops Andrew MacLeod
2022-09-22 19:05 ` [PATCH 09/17] Convert CFN_BUILT_IN_TOUPPER and TOLOWER " Andrew MacLeod
2022-09-22 19:05 ` [PATCH 10/17] Convert CFN_BUILT_FFS and CFN_POPCOUNT " Andrew MacLeod
2022-09-22 19:05 ` [PATCH 11/17] Convert CFN_CLZ builtins " Andrew MacLeod
2022-09-22 19:05 ` [PATCH 12/17] Convert CFN_CTZ " Andrew MacLeod
2022-09-22 19:06 ` [PATCH 13/17] Convert CFN_BUILT_IN_CLRSB " Andrew MacLeod
2022-09-22 19:06 ` [PATCH 14/17] Convert CFN_BUILT_IN_UBSAN_CHECK_* " Andrew MacLeod
2022-09-22 19:08 ` [PATCH 15/17] Convert CFN_BUILT_IN_STRLEN " Andrew MacLeod
2022-09-22 19:10 ` [PATCH 16/17] Convert CFN_BUILT_IN_GOACC_DIM_* " Andrew MacLeod
2022-09-22 19:10 ` [PATCH 17/17] Convert CFN_BUILT_IN_PARITY " Andrew MacLeod
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1c18ea06-495c-52f5-67ea-b116ef0df3bc@redhat.com \
--to=amacleod@redhat.com \
--cc=aldyh@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).