diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2021-05-18 20:33:09 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2021-05-19 16:22:13 -0400 |
commit | dc6758f03effbf7d6946d8c314576c7a6c0003af (patch) | |
tree | 5d56151f75df24c220ad5f0908dd195781553f9b /gcc/gimple-range.h | |
parent | cd67343703ef4fa61de837f4690eba70d2760825 (diff) | |
download | gcc-dc6758f03effbf7d6946d8c314576c7a6c0003af.zip gcc-dc6758f03effbf7d6946d8c314576c7a6c0003af.tar.gz gcc-dc6758f03effbf7d6946d8c314576c7a6c0003af.tar.bz2 |
Split gimple range folding with ranges into a stand alone class.
Introduces fold_using_range which folds any kind of gimple statement by
querying argument ranges thru a generic range_query.
This pulls all the statement processing into a client neutral location.
* gimple-range.cc (fur_source::get_operand): New.
(gimple_range_fold): Delete.
(fold_using_range::fold_stmt): Move from gimple_ranger::calc_stmt.
(fold_using_range::range_of_range_op): Move from gimple_ranger.
(fold_using_range::range_of_address): Ditto.
(fold_using_range::range_of_phi): Ditto.
(fold_using_range::range_of_call): Ditto.
(fold_using_range::range_of_builtin_ubsan_call): Move from
range_of_builtin_ubsan_call.
(fold_using_range::range_of_builtin_call): Move from
range_of_builtin_call.
(gimple_ranger::range_of_builtin_call): Delete.
(fold_using_range::range_of_cond_expr): Move from gimple_ranger.
(gimple_ranger::fold_range_internal): New.
(gimple_ranger::range_of_stmt): Use new fold_using_range API.
(fold_using_range::range_of_ssa_name_with_loop_info): Move from
gimple_ranger. Improve ranges of SSA_NAMES when possible.
* gimple-range.h (gimple_ranger): Remove various range_of routines.
(class fur_source): New.
(class fold_using_range): New.
(fur_source::fur_source): New.
(fold_range): New.
* vr-values.c (vr_values::extract_range_basic): Use fold_using_range
instead of range_of_builtin_call.
Diffstat (limited to 'gcc/gimple-range.h')
-rw-r--r-- | gcc/gimple-range.h | 135 |
1 files changed, 114 insertions, 21 deletions
diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index f331561..5320506 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -30,6 +30,18 @@ along with GCC; see the file COPYING3. If not see #include "gimple-range-cache.h" #include "value-query.h" +// This file is the main include point for gimple ranges. +// There are two fold_range routines of interest: +// bool fold_range (irange &r, gimple *s, range_query *q) +// bool fold_range (irange &r, gimple *s, edge on_edge, range_query *q) +// These routines will fold stmt S into the result irange R. +// Any ssa_names on the stmt will be calculated using the range_query +// parameter via a call to range_of_expr. +// If no range_query is provided, current global range info will be used. +// The second variation specifies an edge, and stmt S is recalculated as if +// it appeared on that edge. + + // This is the basic range generator interface. // // This base class provides all the API entry points, but only provides @@ -55,32 +67,116 @@ public: void export_global_ranges (); void dump (FILE *f); protected: - bool calc_stmt (irange &r, gimple *s, tree name = NULL_TREE); - bool range_of_range_op (irange &r, gimple *s); - bool range_of_call (irange &r, gcall *call); - bool range_of_cond_expr (irange &r, gassign* cond); + bool fold_range_internal (irange &r, gimple *s, tree name); ranger_cache m_cache; -private: - bool range_of_phi (irange &r, gphi *phi); - bool range_of_address (irange &r, gimple *s); - bool range_of_builtin_call (irange &r, gcall *call); - bool range_with_loop_info (irange &r, tree name); - void range_of_ssa_name_with_loop_info (irange &, tree, class loop *, - gphi *); }; -// Calculate a basic range for a tree expression. +// Source of an operand for fold_using_range. +// It can specify a stmt or and edge, or thru an internal API which uses +// the ranger cache. +// Its primary function is to retreive an operand from the source via a +// call thru the range_query object. + +class fur_source +{ + friend class fold_using_range; +public: + inline fur_source (range_query *q, edge e); + inline fur_source (range_query *q, gimple *s); + inline fur_source (range_query *q, class ranger_cache *g, edge e, gimple *s); + bool get_operand (irange &r, tree expr); +protected: + ranger_cache *m_cache; + range_query *m_query; + edge m_edge; + gimple *m_stmt; +}; + + +// This class uses ranges to fold a gimple statement producinf a range for +// the LHS. The source of all operands is supplied via the fur_source class +// which provides a range_query as well as a source location and any other +// required information. + +class fold_using_range +{ +public: + bool fold_stmt (irange &r, gimple *s, class fur_source &src, + tree name = NULL_TREE); +protected: + bool range_of_range_op (irange &r, gimple *s, fur_source &src); + bool range_of_call (irange &r, gcall *call, fur_source &src); + bool range_of_cond_expr (irange &r, gassign* cond, fur_source &src); + bool range_of_address (irange &r, gimple *s, fur_source &src); + bool range_of_builtin_call (irange &r, gcall *call, fur_source &src); + void range_of_builtin_ubsan_call (irange &r, gcall *call, tree_code code, + fur_source &src); + bool range_of_phi (irange &r, gphi *phi, fur_source &src); + void range_of_ssa_name_with_loop_info (irange &, tree, class loop *, gphi *, + fur_source &src); +}; + + +// Create a source for a query on an edge. + +inline +fur_source::fur_source (range_query *q, edge e) +{ + m_query = q; + m_cache = NULL; + m_edge = e; + m_stmt = NULL; +} + +// Create a source for a query at a statement. + +inline +fur_source::fur_source (range_query *q, gimple *s) +{ + m_query = q; + m_cache = NULL; + m_edge = NULL; + m_stmt = s; +} + +// Create a source for Ranger. THis can recalculate from a different location +// and can also set the dependency information as appropriate when invoked. + +inline +fur_source::fur_source (range_query *q, ranger_cache *g, edge e, gimple *s) +{ + m_query = q; + m_cache = g; + m_edge = e; + m_stmt = s; +} + +// Fold stmt S into range R using range query Q. + +inline bool +fold_range (irange &r, gimple *s, range_query *q = NULL) +{ + fold_using_range f; + fur_source src (q, s); + return f.fold_stmt (r, s, src); +} + +// Recalculate stmt S into R using range query Q as if it were on edge ON_EDGE. + +inline bool +fold_range (irange &r, gimple *s, edge on_edge, range_query *q = NULL) +{ + fold_using_range f; + fur_source src (q, on_edge); + return f.fold_stmt (r, s, src); +} + +// Calculate a basic range for a tree node expression. extern bool get_tree_range (irange &r, tree expr); // These routines provide a GIMPLE interface to the range-ops code. extern tree gimple_range_operand1 (const gimple *s); extern tree gimple_range_operand2 (const gimple *s); -extern tree gimple_range_base_of_assignment (const gimple *s); -extern bool gimple_range_fold (irange &res, const gimple *s, - const irange &r1); -extern bool gimple_range_fold (irange &res, const gimple *s, - const irange &r1, - const irange &r2); extern bool gimple_range_calc_op1 (irange &r, const gimple *s, const irange &lhs_range); extern bool gimple_range_calc_op1 (irange &r, const gimple *s, @@ -199,7 +295,4 @@ private: // Flag to enable debugging the various internal Caches. #define DEBUG_RANGE_CACHE (dump_file && (param_evrp_mode & EVRP_MODE_DEBUG)) -// Temporary external interface to share with vr_values. -bool range_of_builtin_call (range_query &query, irange &r, gcall *call); - #endif // GCC_GIMPLE_RANGE_STMT_H |