aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range-tests.cc
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-05-26 08:40:17 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-06-03 17:47:27 +0200
commitcaa60c12715dd9b0cbb550a45e5878214a10a2fe (patch)
tree54782e0a2bb50af3fc37acb46e787a0de7c9298f /gcc/gimple-range-tests.cc
parentbe54520ea0422f4b5468cbbcf139be7e3a6cdeea (diff)
downloadgcc-caa60c12715dd9b0cbb550a45e5878214a10a2fe.zip
gcc-caa60c12715dd9b0cbb550a45e5878214a10a2fe.tar.gz
gcc-caa60c12715dd9b0cbb550a45e5878214a10a2fe.tar.bz2
Implement generic expression evaluator for range_query.
Right now, range_of_expr only works with constants, SSA names, and pointers. Anything else gets returned as VARYING. This patch adds the capability to deal with arbitrary expressions, inasmuch as these tree codes are implemented in range-ops.cc. This will give us the ability to ask for the range of any tree expression, not just constants and SSA names, with range_of_expr(). This is a more generic implementation of determine_value_range in VRP. A follow-up patch will remove all uses of it in favor of the range_query API. gcc/ChangeLog: * function-tests.c (test_ranges): Call gimple_range_tests. * gimple-range-cache.cc (ranger_cache::range_of_expr): Pass stmt to get_tree_range. * gimple-range.cc (fur_source::get_operand): Do not call get_tree_range or gimple_range_global. get_tree_range. (get_tree_range): Move to value-query.cc. Call get_arith_expr_range. (gimple_ranger::range_of_expr): Add argument to get_tree_range. Include gimple-range-tests.cc. * gimple-range.h (fold_range): Add argument. (get_tree_range): Remove. * selftest.h (gimple_range_tests): New. * value-query.cc (global_range_query::range_of_expr): Add stmt argument. (range_query::get_tree_range): Move from gimple-range.cc. * value-query.h (class range_query): Add get_tree_range and get_arith_expr_range. Make fur_source a friend. * vr-values.c (vr_values::range_of_expr): Pass stmt to get_tree_range. * gimple-range-tests.cc: New file.
Diffstat (limited to 'gcc/gimple-range-tests.cc')
-rw-r--r--gcc/gimple-range-tests.cc72
1 files changed, 72 insertions, 0 deletions
diff --git a/gcc/gimple-range-tests.cc b/gcc/gimple-range-tests.cc
new file mode 100644
index 0000000..9ee4c5a
--- /dev/null
+++ b/gcc/gimple-range-tests.cc
@@ -0,0 +1,72 @@
+/* Unit tests for GIMPLE range related routines.
+ Copyright (C) 2021 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3. If not see
+<http://www.gnu.org/licenses/>. */
+
+#if CHECKING_P
+
+#include "selftest.h"
+
+namespace selftest {
+
+// Test ranges of tree expressions.
+class test_expr_eval : public gimple_ranger
+{
+public:
+ test_expr_eval ()
+ {
+ type = integer_type_node;
+ op0 = make_ssa_name (type);
+ op1 = make_ssa_name (type);
+
+ // [5,10] + [15,20] => [20, 30]
+ tree expr = fold_build2 (PLUS_EXPR, type, op0, op1);
+ int_range<2> expect (build_int_cst (type, 20), build_int_cst (type, 30));
+ int_range_max r;
+
+ ASSERT_TRUE (range_of_expr (r, expr));
+ ASSERT_TRUE (r == expect);
+ }
+
+ virtual bool range_of_expr (irange &r, tree expr, gimple * = NULL) OVERRIDE
+ {
+ if (expr == op0)
+ {
+ r.set (build_int_cst (type, 5), build_int_cst (type, 10));
+ return true;
+ }
+ if (expr == op1)
+ {
+ r.set (build_int_cst (type, 15), build_int_cst (type, 20));
+ return true;
+ }
+ return gimple_ranger::range_of_expr (r, expr);
+ }
+
+private:
+ tree op0, op1, type;
+};
+
+void
+gimple_range_tests ()
+{
+ test_expr_eval e;
+}
+
+} // namespace selftest
+
+#endif // CHECKING_P