aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range.h
diff options
context:
space:
mode:
authorAldy Hernandez <aldyh@redhat.com>2021-05-19 18:27:05 +0200
committerAldy Hernandez <aldyh@redhat.com>2021-05-26 21:26:54 +0200
commit586d6f7aee0ba9faf3d9b7afd6ff89d57763a775 (patch)
tree42a7e51305d494dc2209159686571148982a0be7 /gcc/gimple-range.h
parent28484d00c45b7bf094a22a4fddf9ffdc7482c7e1 (diff)
downloadgcc-586d6f7aee0ba9faf3d9b7afd6ff89d57763a775.zip
gcc-586d6f7aee0ba9faf3d9b7afd6ff89d57763a775.tar.gz
gcc-586d6f7aee0ba9faf3d9b7afd6ff89d57763a775.tar.bz2
Common API for accessing global and on-demand ranges.
This patch provides a generic API for accessing global ranges. It is meant to replace get_range_info() and get_ptr_nonnull() with one common interface. It uses the same API as the ranger (class range_query), so there will now be one API for accessing local and global ranges alike. Follow-up patches will convert all users of get_range_info and get_ptr_nonnull to this API. For get_range_info, instead of: if (!POINTER_TYPE_P (TREE_TYPE (name)) && SSA_NAME_RANGE_INFO (name)) get_range_info (name, vr); You can now do: get_range_query (cfun)->range_of_expr (vr, name, [stmt]); ...as well as any other of the range_query methods (range_on_edge, range_of_stmt, value_of_expr, value_on_edge, value_on_stmt, etc). As per the API, range_of_expr will work on constants, SSA names, and anything we support in irange::supports_type_p(). For pointers, the interface is the same, so instead of: else if (POINTER_TYPE_P (TREE_TYPE (name)) && SSA_NAME_PTR_INFO (name)) { if (get_ptr_nonnull (name)) stuff(); } One can do: get_range_query (cfun)->range_of_expr (vr, name, [stmt]); if (vr.nonzero_p ()) stuff (); Along with this interface, we are providing a mechanism by which a pass can use an on-demand ranger transparently, without having to change its code. Of course, this assumes all get_range_info() and get_ptr_nonnull() users have been converted to the new API, which follow-up patches will do. If a pass would prefer to use an on-demand ranger with finer grained and context aware ranges, all it would have to do is call enable_ranger() at the beginning of the pass, and disable_ranger() at the end of the pass. Note, that to use context aware ranges, any user of range_of_expr() would need to pass additional context. For example, the optional gimple statement (or perhaps use range_on_edge or range_of_stmt). The observant reader will note that get_range_query is tied to a struct function, which may not be available in certain contexts, such as at RTL time, gimple-fold, or some other places where we may or may not have cfun set. For cases where we are sure there is no function, you can use get_global_range_query() instead of get_range_query(fun). The API is the same. For cases where a function may be called with or without a function, you could use the following idiom: range_query *query = cfun ? get_range_query (cfun) : get_global_range_query (); query->range_of_expr (range, expr, [stmt]); The default range query obtained by get_range_query() is the global range query, unless the user has enabled an on-demand ranger with enable_ranger(), in which case it will use the currently active ranger. That is, until disable_ranger() is called, at which point, we revert back to global ranges. We think this provides a generic way of accessing ranges, both globally and locally, without having to keep track of types, SSA_NAME_RANGE_INFO, and SSA_NAME_PTR_INFO. We also hope this can be used to transition passes from global to on-demand ranges when appropriate. gcc/ChangeLog: * function.c (allocate_struct_function): Set cfun->x_range_query. * function.h (struct function): Declare x_range_query. (get_range_query): New. (get_global_range_query): New. * gimple-range-cache.cc (ssa_global_cache::ssa_global_cache): Remove call to safe_grow_cleared. * gimple-range.cc (get_range_global): New. (gimple_range_global): Move from gimple-range.h. (get_global_range_query): New. (global_range_query::range_of_expr): New. (enable_ranger): New. (disable_ranger): New. * gimple-range.h (gimple_range_global): Move to gimple-range.cc. (class global_range_query): New. (enable_ranger): New. (disable_ranger): New. * gimple-ssa-evrp.c (evrp_folder::~evrp_folder): Rename dump_all_value_ranges to dump. * tree-vrp.c (vrp_prop::finalize): Same. * value-query.cc (range_query::dump): New. * value-query.h (range_query::dump): New. * vr-values.c (vr_values::dump_all_value_ranges): Rename to... (vr_values::dump): ...this. * vr-values.h (class vr_values): Rename dump_all_value_ranges to dump and make virtual.
Diffstat (limited to 'gcc/gimple-range.h')
-rw-r--r--gcc/gimple-range.h60
1 files changed, 15 insertions, 45 deletions
diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h
index 707dcfe..23734c6 100644
--- a/gcc/gimple-range.h
+++ b/gcc/gimple-range.h
@@ -65,7 +65,7 @@ public:
virtual void range_on_entry (irange &r, basic_block bb, tree name);
virtual void range_on_exit (irange &r, basic_block bb, tree name);
void export_global_ranges ();
- void dump (FILE *f);
+ virtual void dump (FILE *f) OVERRIDE;
void dump_bb (FILE *f, basic_block bb);
protected:
bool fold_range_internal (irange &r, gimple *s, tree name);
@@ -227,50 +227,6 @@ range_compatible_p (tree type1, tree type2)
&& TYPE_SIGN (type1) == TYPE_SIGN (type2));
}
-// Return the legacy GCC global range for NAME if it has one, otherwise
-// return VARYING.
-
-static inline value_range
-gimple_range_global (tree name)
-{
- gcc_checking_assert (gimple_range_ssa_p (name));
- tree type = TREE_TYPE (name);
-
- if (SSA_NAME_IS_DEFAULT_DEF (name))
- {
- tree sym = SSA_NAME_VAR (name);
- // Adapted from vr_values::get_lattice_entry().
- // Use a range from an SSA_NAME's available range.
- if (TREE_CODE (sym) == PARM_DECL)
- {
- // Try to use the "nonnull" attribute to create ~[0, 0]
- // anti-ranges for pointers. Note that this is only valid with
- // default definitions of PARM_DECLs.
- if (POINTER_TYPE_P (type)
- && (nonnull_arg_p (sym) || get_ptr_nonnull (name)))
- {
- value_range r;
- r.set_nonzero (type);
- return r;
- }
- else if (INTEGRAL_TYPE_P (type))
- {
- value_range r;
- get_range_info (name, r);
- if (r.undefined_p ())
- r.set_varying (type);
- return r;
- }
- }
- // If this is a local automatic with no definition, use undefined.
- else if (TREE_CODE (sym) != RESULT_DECL)
- return value_range ();
- }
- // Otherwise return range for the type.
- return value_range (type);
-}
-
-
// This class overloads the ranger routines to provide tracing facilties
// Entry and exit values to each of the APIs is placed in the dumpfile.
@@ -296,4 +252,18 @@ private:
// Flag to enable debugging the various internal Caches.
#define DEBUG_RANGE_CACHE (dump_file && (param_evrp_mode & EVRP_MODE_DEBUG))
+// Global ranges for SSA names using SSA_NAME_RANGE_INFO.
+
+class global_range_query : public range_query
+{
+public:
+ bool range_of_expr (irange &r, tree expr, gimple * = NULL) OVERRIDE;
+};
+
+extern global_range_query global_ranges;
+extern value_range gimple_range_global (tree name);
+
+extern gimple_ranger *enable_ranger (struct function *);
+extern void disable_ranger (struct function *);
+
#endif // GCC_GIMPLE_RANGE_STMT_H