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