You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
5.0KB

  1. /* Support routines for value ranges.
  2. Copyright (C) 2019-2020 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_VALUE_RANGE_H
  16. #define GCC_VALUE_RANGE_H
  17. /* Types of value ranges. */
  18. enum value_range_kind
  19. {
  20. /* Empty range. */
  21. VR_UNDEFINED,
  22. /* Range spans the entire domain. */
  23. VR_VARYING,
  24. /* Range is [MIN, MAX]. */
  25. VR_RANGE,
  26. /* Range is ~[MIN, MAX]. */
  27. VR_ANTI_RANGE,
  28. /* Range is a nice guy. */
  29. VR_LAST
  30. };
  31. // Range of values that can be associated with an SSA_NAME.
  32. class GTY((for_user)) value_range
  33. {
  34. public:
  35. value_range ();
  36. value_range (tree, tree, value_range_kind = VR_RANGE);
  37. value_range (tree type, const wide_int &, const wide_int &,
  38. value_range_kind = VR_RANGE);
  39. value_range (tree type);
  40. void set (tree, tree, value_range_kind = VR_RANGE);
  41. void set (tree);
  42. void set_nonzero (tree);
  43. void set_zero (tree);
  44. enum value_range_kind kind () const;
  45. tree min () const;
  46. tree max () const;
  47. /* Types of value ranges. */
  48. bool symbolic_p () const;
  49. bool constant_p () const;
  50. bool undefined_p () const;
  51. bool varying_p () const;
  52. void set_varying (tree type);
  53. void set_undefined ();
  54. void union_ (const value_range *);
  55. void intersect (const value_range *);
  56. void union_ (const value_range &);
  57. void intersect (const value_range &);
  58. bool operator== (const value_range &) const;
  59. bool operator!= (const value_range &) const /* = delete */;
  60. bool equal_p (const value_range &) const;
  61. /* Misc methods. */
  62. tree type () const;
  63. bool may_contain_p (tree) const;
  64. bool zero_p () const;
  65. bool nonzero_p () const;
  66. bool singleton_p (tree *result = NULL) const;
  67. void dump (FILE *) const;
  68. void dump () const;
  69. static bool supports_type_p (tree);
  70. void normalize_symbolics ();
  71. void normalize_addresses ();
  72. static const unsigned int m_max_pairs = 2;
  73. bool contains_p (tree) const;
  74. unsigned num_pairs () const;
  75. wide_int lower_bound (unsigned = 0) const;
  76. wide_int upper_bound (unsigned) const;
  77. wide_int upper_bound () const;
  78. void invert ();
  79. protected:
  80. void check ();
  81. static value_range union_helper (const value_range *, const value_range *);
  82. static value_range intersect_helper (const value_range *,
  83. const value_range *);
  84. friend void gt_ggc_mx_value_range (void *);
  85. friend void gt_pch_p_11value_range (void *, void *,
  86. gt_pointer_operator, void *);
  87. friend void gt_pch_nx_value_range (void *);
  88. friend void gt_ggc_mx (value_range &);
  89. friend void gt_ggc_mx (value_range *&);
  90. friend void gt_pch_nx (value_range &);
  91. friend void gt_pch_nx (value_range *, gt_pointer_operator, void *);
  92. enum value_range_kind m_kind;
  93. tree m_min;
  94. tree m_max;
  95. private:
  96. int value_inside_range (tree) const;
  97. };
  98. extern bool range_has_numeric_bounds_p (const value_range *);
  99. extern bool ranges_from_anti_range (const value_range *,
  100. value_range *, value_range *);
  101. extern void dump_value_range (FILE *, const value_range *);
  102. extern bool vrp_val_is_min (const_tree);
  103. extern bool vrp_val_is_max (const_tree);
  104. extern tree vrp_val_min (const_tree);
  105. extern tree vrp_val_max (const_tree);
  106. extern bool vrp_operand_equal_p (const_tree, const_tree);
  107. inline
  108. value_range::value_range ()
  109. {
  110. m_kind = VR_UNDEFINED;
  111. m_min = m_max = NULL;
  112. }
  113. inline value_range_kind
  114. value_range::kind () const
  115. {
  116. return m_kind;
  117. }
  118. inline tree
  119. value_range::type () const
  120. {
  121. return TREE_TYPE (min ());
  122. }
  123. inline tree
  124. value_range::min () const
  125. {
  126. return m_min;
  127. }
  128. inline tree
  129. value_range::max () const
  130. {
  131. return m_max;
  132. }
  133. inline bool
  134. value_range::varying_p () const
  135. {
  136. return m_kind == VR_VARYING;
  137. }
  138. inline bool
  139. value_range::undefined_p () const
  140. {
  141. return m_kind == VR_UNDEFINED;
  142. }
  143. inline bool
  144. value_range::zero_p () const
  145. {
  146. return (m_kind == VR_RANGE
  147. && integer_zerop (m_min)
  148. && integer_zerop (m_max));
  149. }
  150. inline bool
  151. value_range::nonzero_p () const
  152. {
  153. if (m_kind == VR_ANTI_RANGE
  154. && !TYPE_UNSIGNED (type ())
  155. && integer_zerop (m_min)
  156. && integer_zerop (m_max))
  157. return true;
  158. return (m_kind == VR_RANGE
  159. && TYPE_UNSIGNED (type ())
  160. && integer_onep (m_min)
  161. && vrp_val_is_max (m_max));
  162. }
  163. inline bool
  164. value_range::supports_type_p (tree type)
  165. {
  166. if (type && (INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type)))
  167. return type;
  168. return false;
  169. }
  170. inline bool
  171. range_includes_zero_p (const value_range *vr)
  172. {
  173. if (vr->undefined_p ())
  174. return false;
  175. if (vr->varying_p ())
  176. return true;
  177. return vr->may_contain_p (build_zero_cst (vr->type ()));
  178. }
  179. #endif // GCC_VALUE_RANGE_H