]> gcc.gnu.org Git - gcc.git/blame - gcc/vr-values.h
docs: fix: WARNING: Parsing of expression failed. Using fallback parser.
[gcc.git] / gcc / vr-values.h
CommitLineData
89759031 1/* Support routines for Value Range Propagation (VRP).
7adcbafe 2 Copyright (C) 2016-2022 Free Software Foundation, Inc.
89759031
JL
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_VR_VALUES_H
21#define GCC_VR_VALUES_H
22
4a5e9d00 23#include "value-range-equiv.h"
a889e06a 24#include "value-query.h"
4a5e9d00 25
ea95ba8d
AH
26// Abstract class to return a range for a given SSA.
27
fc36b97a 28// Class to simplify a statement using range information.
fc36b97a 29
a889e06a 30class simplify_using_ranges
fc36b97a
AH
31{
32public:
053e1d64
AM
33 simplify_using_ranges (range_query *query = NULL,
34 int not_executable_flag = 0);
fc36b97a 35 ~simplify_using_ranges ();
053e1d64
AM
36 void set_range_query (class range_query *q, int not_executable_flag = 0)
37 { query = q; m_not_executable_flag = not_executable_flag; }
a889e06a 38
fc36b97a
AH
39 bool simplify (gimple_stmt_iterator *);
40
41 // ?? These should be cleaned, merged, and made private.
42 tree vrp_evaluate_conditional (tree_code, tree, tree, gimple *);
43 void vrp_visit_cond_stmt (gcond *, edge *);
8c99e307 44 bool fold_cond (gcond *);
d8b8023c 45 tree vrp_evaluate_conditional_warnv_with_ops (gimple *stmt, enum tree_code,
fc36b97a
AH
46 tree, tree, bool,
47 bool *, bool *);
f5bacd9c 48 bool simplify_casted_cond (gcond *);
fc36b97a
AH
49
50private:
fc36b97a
AH
51 bool simplify_truth_ops_using_ranges (gimple_stmt_iterator *, gimple *);
52 bool simplify_div_or_mod_using_ranges (gimple_stmt_iterator *, gimple *);
53 bool simplify_abs_using_ranges (gimple_stmt_iterator *, gimple *);
54 bool simplify_bit_ops_using_ranges (gimple_stmt_iterator *, gimple *);
55 bool simplify_min_or_max_using_ranges (gimple_stmt_iterator *, gimple *);
56 bool simplify_cond_using_ranges_1 (gcond *);
fc36b97a
AH
57 bool simplify_switch_using_ranges (gswitch *);
58 bool simplify_float_conversion_using_ranges (gimple_stmt_iterator *,
59 gimple *);
60 bool simplify_internal_call_using_ranges (gimple_stmt_iterator *, gimple *);
61
a7e655ae
AM
62 bool two_valued_val_range_p (tree, tree *, tree *, gimple *);
63 bool op_with_boolean_value_range_p (tree, gimple *);
64 tree compare_name_with_value (enum tree_code, tree, tree, bool *, bool,
65 gimple *);
66 tree compare_names (enum tree_code, tree, tree, bool *, gimple *s);
67 const value_range_equiv *get_vr_for_comparison (int, value_range_equiv *,
68 gimple *s);
fc36b97a
AH
69 tree vrp_evaluate_conditional_warnv_with_ops_using_ranges (enum tree_code,
70 tree, tree,
a7e655ae 71 bool *, gimple *s);
73cf73af 72 void set_and_propagate_unexecutable (edge e);
fc36b97a
AH
73 void cleanup_edges_and_switches (void);
74
75 /* Vectors of edges that need removing and switch statements that
76 need updating. It is expected that a pass using the simplification
77 routines will, at the end of the pass, clean up the edges and
78 switch statements. The class dtor will try to detect cases
79 that do not follow that expectation. */
80 struct switch_update {
81 gswitch *stmt;
82 tree vec;
83 };
84
85 vec<edge> to_remove_edges;
86 vec<switch_update> to_update_switch_stmts;
a889e06a 87 class range_query *query;
053e1d64
AM
88 int m_not_executable_flag; // Non zero if not_executable flag exists.
89 vec<edge> m_flag_set_edges; // List of edges with flag to be cleared.
fc36b97a
AH
90};
91
89759031
JL
92/* The VR_VALUES class holds the current view of range information
93 for all the SSA_NAMEs in the IL.
94
95 It can be used to hold context sensitive range information during
96 a dominator walk or it may be used to hold range information in the
97 standard VRP pass as ranges are propagated through the lattice to a
98 steady state.
99
100 This information is independent of the range information that gets
101 attached to SSA_NAMEs. A pass such as VRP may choose to transfer
102 the global information it produces into global range information that
103 gets attached to an SSA_NAME. It's unclear how useful that global
104 information will be in a world where we can compute context sensitive
105 range information fast or perform on-demand queries. */
ea95ba8d 106class vr_values : public range_query
89759031
JL
107{
108 public:
109 vr_values (void);
110 ~vr_values (void);
111
45c8523d 112 virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt) override;
ff171cb1
DM
113 virtual tree value_of_expr (tree, gimple * = NULL) override;
114 virtual tree value_on_edge (edge, tree) override;
115 virtual tree value_of_stmt (gimple *, tree = NULL_TREE) override;
a889e06a 116 virtual const value_range_equiv *get_value_range (const_tree,
ff171cb1 117 gimple * = NULL) override;
028d81b1
AH
118 void set_vr_value (tree, value_range_equiv *);
119 value_range_equiv *swap_vr_value (tree, value_range_equiv *);
f86c2e71 120
0982acbe 121 void set_def_to_varying (const_tree);
a5de02e9 122 void set_defs_to_varying (gimple *);
028d81b1 123 bool update_value_range (const_tree, value_range_equiv *);
a5de02e9 124 tree op_with_constant_singleton_value_range (tree);
028d81b1
AH
125 void adjust_range_with_scev (value_range_equiv *, class loop *,
126 gimple *, tree);
ff171cb1 127 virtual void dump (FILE *) override;
a5de02e9
JL
128
129 void extract_range_for_var_from_comparison_expr (tree, enum tree_code,
028d81b1
AH
130 tree, tree,
131 value_range_equiv *);
132 void extract_range_from_phi_node (gphi *, value_range_equiv *);
133 void extract_range_basic (value_range_equiv *, gimple *);
134 void extract_range_from_stmt (gimple *, edge *, tree *, value_range_equiv *);
a5de02e9 135
3e406d33
JL
136 /* Indicate that propagation through the lattice is complete. */
137 void set_lattice_propagation_complete (void) { values_propagated = true; }
89759031 138
3e406d33 139 /* Allocate a new value_range object. */
028d81b1 140 value_range_equiv *allocate_value_range_equiv (void)
a889e06a 141 { return range_query::allocate_value_range_equiv (); }
028d81b1 142 void free_value_range (value_range_equiv *vr)
a889e06a 143 { free_value_range_equiv (vr); }
89759031 144
a5de02e9 145 private:
028d81b1 146 value_range_equiv *get_lattice_entry (const_tree);
89759031 147 bool vrp_stmt_computes_nonzero (gimple *);
028d81b1
AH
148 void extract_range_from_assignment (value_range_equiv *, gassign *);
149 void extract_range_from_assert (value_range_equiv *, tree);
150 void extract_range_from_ssa_name (value_range_equiv *, tree);
151 void extract_range_from_binary_expr (value_range_equiv *, enum tree_code,
89759031 152 tree, tree, tree);
028d81b1 153 void extract_range_from_unary_expr (value_range_equiv *, enum tree_code,
89759031 154 tree, tree);
028d81b1 155 void extract_range_from_cond_expr (value_range_equiv *, gassign *);
d8b8023c 156 void extract_range_from_comparison (value_range_equiv *, gimple *);
028d81b1 157 void vrp_visit_assignment_or_call (gimple*, tree *, value_range_equiv *);
89759031 158 void vrp_visit_switch_stmt (gswitch *, edge *);
82b6d25d 159 bool extract_range_from_ubsan_builtin (value_range_equiv *, gimple *);
a5de02e9 160
3e406d33
JL
161 /* This probably belongs in the lattice rather than in here. */
162 bool values_propagated;
163
164 /* Allocations for equivalences all come from this obstack. */
165 bitmap_obstack vrp_equiv_obstack;
166
a5de02e9
JL
167 /* Value range array. After propagation, VR_VALUE[I] holds the range
168 of values that SSA name N_I may take. */
169 unsigned int num_vr_values;
028d81b1 170 value_range_equiv **vr_value;
a5de02e9
JL
171
172 /* For a PHI node which sets SSA name N_I, VR_COUNTS[I] holds the
173 number of executable edges we saw the last time we visited the
174 node. */
175 int *vr_phi_edge_counts;
fc36b97a 176 simplify_using_ranges simplifier;
89759031
JL
177};
178
f432e4fc 179extern tree get_output_for_vrp (gimple *);
fc36b97a 180
bae73ca5
AH
181extern bool range_fits_type_p (const value_range *vr,
182 unsigned dest_precision, signop dest_sgn);
ea95ba8d
AH
183extern bool bounds_of_var_in_loop (tree *min, tree *max, range_query *,
184 class loop *loop, gimple *stmt, tree var);
185
89759031 186#endif /* GCC_VR_VALUES_H */
This page took 4.166552 seconds and 5 git commands to generate.