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.

146 lines
4.3KB

  1. /* A class for building vector tree constants.
  2. Copyright (C) 2017-2020 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. 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_TREE_VECTOR_BUILDER_H
  16. #define GCC_TREE_VECTOR_BUILDER_H
  17. #include "vector-builder.h"
  18. /* This class is used to build VECTOR_CSTs from a sequence of elements.
  19. See vector_builder for more details. */
  20. class tree_vector_builder : public vector_builder<tree, tree,
  21. tree_vector_builder>
  22. {
  23. typedef vector_builder<tree, tree, tree_vector_builder> parent;
  24. friend class vector_builder<tree, tree, tree_vector_builder>;
  25. public:
  26. tree_vector_builder () : m_type (0) {}
  27. tree_vector_builder (tree, unsigned int, unsigned int);
  28. tree build ();
  29. tree type () const { return m_type; }
  30. void new_vector (tree, unsigned int, unsigned int);
  31. private:
  32. bool equal_p (const_tree, const_tree) const;
  33. bool allow_steps_p () const;
  34. bool integral_p (const_tree) const;
  35. wide_int step (const_tree, const_tree) const;
  36. tree apply_step (tree, unsigned int, const wide_int &) const;
  37. bool can_elide_p (const_tree) const;
  38. void note_representative (tree *, tree);
  39. static poly_uint64 shape_nelts (const_tree t)
  40. { return TYPE_VECTOR_SUBPARTS (t); }
  41. static poly_uint64 nelts_of (const_tree t)
  42. { return VECTOR_CST_NELTS (t); }
  43. static unsigned int npatterns_of (const_tree t)
  44. { return VECTOR_CST_NPATTERNS (t); }
  45. static unsigned int nelts_per_pattern_of (const_tree t)
  46. { return VECTOR_CST_NELTS_PER_PATTERN (t); }
  47. tree m_type;
  48. };
  49. /* Create a new builder for a vector of type TYPE. Initially encode the
  50. value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
  51. each. */
  52. inline
  53. tree_vector_builder::tree_vector_builder (tree type, unsigned int npatterns,
  54. unsigned int nelts_per_pattern)
  55. {
  56. new_vector (type, npatterns, nelts_per_pattern);
  57. }
  58. /* Start building a new vector of type TYPE. Initially encode the value
  59. as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each. */
  60. inline void
  61. tree_vector_builder::new_vector (tree type, unsigned int npatterns,
  62. unsigned int nelts_per_pattern)
  63. {
  64. m_type = type;
  65. parent::new_vector (TYPE_VECTOR_SUBPARTS (type), npatterns,
  66. nelts_per_pattern);
  67. }
  68. /* Return true if elements I1 and I2 are equal. */
  69. inline bool
  70. tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const
  71. {
  72. return operand_equal_p (elt1, elt2, OEP_BITWISE);
  73. }
  74. /* Return true if a stepped representation is OK. We don't allow
  75. linear series for anything other than integers, to avoid problems
  76. with rounding. */
  77. inline bool
  78. tree_vector_builder::allow_steps_p () const
  79. {
  80. return INTEGRAL_TYPE_P (TREE_TYPE (m_type));
  81. }
  82. /* Return true if ELT can be interpreted as an integer. */
  83. inline bool
  84. tree_vector_builder::integral_p (const_tree elt) const
  85. {
  86. return TREE_CODE (elt) == INTEGER_CST;
  87. }
  88. /* Return the value of element ELT2 minus the value of element ELT1.
  89. Both elements are known to be INTEGER_CSTs. */
  90. inline wide_int
  91. tree_vector_builder::step (const_tree elt1, const_tree elt2) const
  92. {
  93. return wi::to_wide (elt2) - wi::to_wide (elt1);
  94. }
  95. /* Return true if we can drop element ELT, even if the retained elements
  96. are different. Return false if this would mean losing overflow
  97. information. */
  98. inline bool
  99. tree_vector_builder::can_elide_p (const_tree elt) const
  100. {
  101. return !CONSTANT_CLASS_P (elt) || !TREE_OVERFLOW (elt);
  102. }
  103. /* Record that ELT2 is being elided, given that ELT1_PTR points to the last
  104. encoded element for the containing pattern. */
  105. inline void
  106. tree_vector_builder::note_representative (tree *elt1_ptr, tree elt2)
  107. {
  108. if (CONSTANT_CLASS_P (elt2) && TREE_OVERFLOW (elt2))
  109. {
  110. gcc_assert (operand_equal_p (*elt1_ptr, elt2, 0));
  111. if (!TREE_OVERFLOW (elt2))
  112. *elt1_ptr = elt2;
  113. }
  114. }
  115. #endif