vr-values.h 5.8 KB

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