range-op.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Header file for range operator class.
  2. Copyright (C) 2017-2020 Free Software Foundation, Inc.
  3. Contributed by Andrew MacLeod <amacleod@redhat.com>
  4. and Aldy Hernandez <aldyh@redhat.com>.
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License as published by the Free
  8. Software Foundation; either version 3, or (at your option) any later
  9. version.
  10. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with GCC; see the file COPYING3. If not see
  16. <http://www.gnu.org/licenses/>. */
  17. #ifndef GCC_RANGE_OP_H
  18. #define GCC_RANGE_OP_H
  19. // This class is implemented for each kind of operator supported by
  20. // the range generator. It serves various purposes.
  21. //
  22. // 1 - Generates range information for the specific operation between
  23. // two ranges. This provides the ability to fold ranges for an
  24. // expression.
  25. //
  26. // 2 - Performs range algebra on the expression such that a range can be
  27. // adjusted in terms of one of the operands:
  28. //
  29. // def = op1 + op2
  30. //
  31. // Given a range for def, we can adjust the range so that it is in
  32. // terms of either operand.
  33. //
  34. // op1_range (def_range, op2) will adjust the range in place so it
  35. // is in terms of op1. Since op1 = def - op2, it will subtract
  36. // op2 from each element of the range.
  37. //
  38. // 3 - Creates a range for an operand based on whether the result is 0 or
  39. // non-zero. This is mostly for logical true false, but can serve other
  40. // purposes.
  41. // ie 0 = op1 - op2 implies op2 has the same range as op1.
  42. class range_operator
  43. {
  44. public:
  45. // Perform an operation between 2 ranges and return it.
  46. virtual bool fold_range (value_range &r, tree type,
  47. const value_range &lh,
  48. const value_range &rh) const;
  49. // Return the range for op[12] in the general case. LHS is the range for
  50. // the LHS of the expression, OP[12]is the range for the other
  51. //
  52. // The operand and the result is returned in R.
  53. //
  54. // TYPE is the expected type of the range.
  55. //
  56. // Return TRUE if the operation is performed and a valid range is available.
  57. //
  58. // i.e. [LHS] = ??? + OP2
  59. // is re-formed as R = [LHS] - OP2.
  60. virtual bool op1_range (value_range &r, tree type,
  61. const value_range &lhs,
  62. const value_range &op2) const;
  63. virtual bool op2_range (value_range &r, tree type,
  64. const value_range &lhs,
  65. const value_range &op1) const;
  66. protected:
  67. // Perform an integral operation between 2 sub-ranges and return it.
  68. virtual void wi_fold (value_range &r, tree type,
  69. const wide_int &lh_lb,
  70. const wide_int &lh_ub,
  71. const wide_int &rh_lb,
  72. const wide_int &rh_ub) const;
  73. };
  74. extern range_operator *range_op_handler (enum tree_code code, tree type);
  75. extern void range_cast (value_range &, tree type);
  76. extern void wi_set_zero_nonzero_bits (tree type,
  77. const wide_int &, const wide_int &,
  78. wide_int &maybe_nonzero,
  79. wide_int &mustbe_nonzero);
  80. #endif // GCC_RANGE_OP_H