1*38fd1498Szrj /* Support routines for Value Range Propagation (VRP). 2*38fd1498Szrj Copyright (C) 2016-2018 Free Software Foundation, Inc. 3*38fd1498Szrj 4*38fd1498Szrj This file is part of GCC. 5*38fd1498Szrj 6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify 7*38fd1498Szrj it under the terms of the GNU General Public License as published by 8*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj any later version. 10*38fd1498Szrj 11*38fd1498Szrj GCC is distributed in the hope that it will be useful, 12*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj You should have received a copy of the GNU General Public License 17*38fd1498Szrj along with GCC; see the file COPYING3. If not see 18*38fd1498Szrj <http://www.gnu.org/licenses/>. */ 19*38fd1498Szrj 20*38fd1498Szrj #ifndef GCC_VR_VALUES_H 21*38fd1498Szrj #define GCC_VR_VALUES_H 22*38fd1498Szrj 23*38fd1498Szrj /* The VR_VALUES class holds the current view of range information 24*38fd1498Szrj for all the SSA_NAMEs in the IL. 25*38fd1498Szrj 26*38fd1498Szrj It can be used to hold context sensitive range information during 27*38fd1498Szrj a dominator walk or it may be used to hold range information in the 28*38fd1498Szrj standard VRP pass as ranges are propagated through the lattice to a 29*38fd1498Szrj steady state. 30*38fd1498Szrj 31*38fd1498Szrj This information is independent of the range information that gets 32*38fd1498Szrj attached to SSA_NAMEs. A pass such as VRP may choose to transfer 33*38fd1498Szrj the global information it produces into global range information that 34*38fd1498Szrj gets attached to an SSA_NAME. It's unclear how useful that global 35*38fd1498Szrj information will be in a world where we can compute context sensitive 36*38fd1498Szrj range information fast or perform on-demand queries. */ 37*38fd1498Szrj class vr_values 38*38fd1498Szrj { 39*38fd1498Szrj public: 40*38fd1498Szrj vr_values (void); 41*38fd1498Szrj ~vr_values (void); 42*38fd1498Szrj 43*38fd1498Szrj value_range *get_value_range (const_tree); 44*38fd1498Szrj 45*38fd1498Szrj void set_vr_value (tree, value_range *); 46*38fd1498Szrj void set_defs_to_varying (gimple *); 47*38fd1498Szrj bool update_value_range (const_tree, value_range *); 48*38fd1498Szrj tree op_with_constant_singleton_value_range (tree); 49*38fd1498Szrj void adjust_range_with_scev (value_range *, struct loop *, gimple *, tree); 50*38fd1498Szrj tree vrp_evaluate_conditional (tree_code, tree, tree, gimple *); 51*38fd1498Szrj void dump_all_value_ranges (FILE *); 52*38fd1498Szrj 53*38fd1498Szrj void extract_range_for_var_from_comparison_expr (tree, enum tree_code, 54*38fd1498Szrj tree, tree, value_range *); 55*38fd1498Szrj void extract_range_from_phi_node (gphi *, value_range *); 56*38fd1498Szrj void extract_range_basic (value_range *, gimple *); 57*38fd1498Szrj void extract_range_from_stmt (gimple *, edge *, tree *, value_range *); 58*38fd1498Szrj 59*38fd1498Szrj void vrp_visit_cond_stmt (gcond *, edge *); 60*38fd1498Szrj 61*38fd1498Szrj void simplify_cond_using_ranges_2 (gcond *); 62*38fd1498Szrj bool simplify_stmt_using_ranges (gimple_stmt_iterator *); 63*38fd1498Szrj 64*38fd1498Szrj /* Indicate that propagation through the lattice is complete. */ set_lattice_propagation_complete(void)65*38fd1498Szrj void set_lattice_propagation_complete (void) { values_propagated = true; } 66*38fd1498Szrj 67*38fd1498Szrj /* Allocate a new value_range object. */ allocate_value_range(void)68*38fd1498Szrj value_range *allocate_value_range (void) 69*38fd1498Szrj { return vrp_value_range_pool.allocate (); } 70*38fd1498Szrj 71*38fd1498Szrj private: 72*38fd1498Szrj void add_equivalence (bitmap *, const_tree); 73*38fd1498Szrj bool vrp_stmt_computes_nonzero (gimple *); 74*38fd1498Szrj bool op_with_boolean_value_range_p (tree); 75*38fd1498Szrj bool check_for_binary_op_overflow (enum tree_code, tree, tree, tree, bool *); 76*38fd1498Szrj value_range get_vr_for_comparison (int); 77*38fd1498Szrj tree compare_name_with_value (enum tree_code, tree, tree, bool *, bool); 78*38fd1498Szrj tree compare_names (enum tree_code, tree, tree, bool *); 79*38fd1498Szrj bool two_valued_val_range_p (tree, tree *, tree *); 80*38fd1498Szrj tree vrp_evaluate_conditional_warnv_with_ops_using_ranges (enum tree_code, 81*38fd1498Szrj tree, tree, 82*38fd1498Szrj bool *); 83*38fd1498Szrj tree vrp_evaluate_conditional_warnv_with_ops (enum tree_code, 84*38fd1498Szrj tree, tree, bool, 85*38fd1498Szrj bool *, bool *); 86*38fd1498Szrj void extract_range_from_assignment (value_range *, gassign *); 87*38fd1498Szrj void extract_range_from_assert (value_range *, tree); 88*38fd1498Szrj void extract_range_from_ssa_name (value_range *, tree); 89*38fd1498Szrj void extract_range_from_binary_expr (value_range *, enum tree_code, 90*38fd1498Szrj tree, tree, tree); 91*38fd1498Szrj void extract_range_from_unary_expr (value_range *, enum tree_code, 92*38fd1498Szrj tree, tree); 93*38fd1498Szrj void extract_range_from_cond_expr (value_range *, gassign *); 94*38fd1498Szrj void extract_range_from_comparison (value_range *, enum tree_code, 95*38fd1498Szrj tree, tree, tree); 96*38fd1498Szrj void vrp_visit_assignment_or_call (gimple*, tree *, value_range *); 97*38fd1498Szrj void vrp_visit_switch_stmt (gswitch *, edge *); 98*38fd1498Szrj bool simplify_truth_ops_using_ranges (gimple_stmt_iterator *, gimple *); 99*38fd1498Szrj bool simplify_div_or_mod_using_ranges (gimple_stmt_iterator *, gimple *); 100*38fd1498Szrj bool simplify_abs_using_ranges (gimple_stmt_iterator *, gimple *); 101*38fd1498Szrj bool simplify_bit_ops_using_ranges (gimple_stmt_iterator *, gimple *); 102*38fd1498Szrj bool simplify_min_or_max_using_ranges (gimple_stmt_iterator *, gimple *); 103*38fd1498Szrj bool simplify_cond_using_ranges_1 (gcond *); 104*38fd1498Szrj bool simplify_switch_using_ranges (gswitch *); 105*38fd1498Szrj bool simplify_float_conversion_using_ranges (gimple_stmt_iterator *, 106*38fd1498Szrj gimple *); 107*38fd1498Szrj bool simplify_internal_call_using_ranges (gimple_stmt_iterator *, gimple *); 108*38fd1498Szrj 109*38fd1498Szrj /* Allocation pools for value_range objects. */ 110*38fd1498Szrj object_allocator<value_range> vrp_value_range_pool; 111*38fd1498Szrj 112*38fd1498Szrj /* This probably belongs in the lattice rather than in here. */ 113*38fd1498Szrj bool values_propagated; 114*38fd1498Szrj 115*38fd1498Szrj /* Allocations for equivalences all come from this obstack. */ 116*38fd1498Szrj bitmap_obstack vrp_equiv_obstack; 117*38fd1498Szrj 118*38fd1498Szrj /* Value range array. After propagation, VR_VALUE[I] holds the range 119*38fd1498Szrj of values that SSA name N_I may take. */ 120*38fd1498Szrj unsigned int num_vr_values; 121*38fd1498Szrj value_range **vr_value; 122*38fd1498Szrj 123*38fd1498Szrj /* For a PHI node which sets SSA name N_I, VR_COUNTS[I] holds the 124*38fd1498Szrj number of executable edges we saw the last time we visited the 125*38fd1498Szrj node. */ 126*38fd1498Szrj int *vr_phi_edge_counts; 127*38fd1498Szrj }; 128*38fd1498Szrj 129*38fd1498Szrj #define VR_INITIALIZER { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL } 130*38fd1498Szrj 131*38fd1498Szrj extern tree get_output_for_vrp (gimple *); 132*38fd1498Szrj #endif /* GCC_VR_VALUES_H */ 133