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.

126 lines
3.7KB

  1. /* A class for building vector rtx 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_RTX_VECTOR_BUILDER_H
  16. #define GCC_RTX_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 rtx_vector_builder : public vector_builder<rtx, machine_mode,
  21. rtx_vector_builder>
  22. {
  23. typedef vector_builder<rtx, machine_mode, rtx_vector_builder> parent;
  24. friend class vector_builder<rtx, machine_mode, rtx_vector_builder>;
  25. public:
  26. rtx_vector_builder () : m_mode (VOIDmode) {}
  27. rtx_vector_builder (machine_mode, unsigned int, unsigned int);
  28. rtx build (rtvec);
  29. rtx build ();
  30. machine_mode mode () const { return m_mode; }
  31. void new_vector (machine_mode, unsigned int, unsigned int);
  32. private:
  33. bool equal_p (rtx, rtx) const;
  34. bool allow_steps_p () const;
  35. bool integral_p (rtx) const;
  36. wide_int step (rtx, rtx) const;
  37. rtx apply_step (rtx, unsigned int, const wide_int &) const;
  38. bool can_elide_p (rtx) const { return true; }
  39. void note_representative (rtx *, rtx) {}
  40. static poly_uint64 shape_nelts (machine_mode mode)
  41. { return GET_MODE_NUNITS (mode); }
  42. static poly_uint64 nelts_of (const_rtx x)
  43. { return CONST_VECTOR_NUNITS (x); }
  44. static unsigned int npatterns_of (const_rtx x)
  45. { return CONST_VECTOR_NPATTERNS (x); }
  46. static unsigned int nelts_per_pattern_of (const_rtx x)
  47. { return CONST_VECTOR_NELTS_PER_PATTERN (x); }
  48. rtx find_cached_value ();
  49. machine_mode m_mode;
  50. };
  51. /* Create a new builder for a vector of mode MODE. Initially encode the
  52. value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
  53. each. */
  54. inline
  55. rtx_vector_builder::rtx_vector_builder (machine_mode mode,
  56. unsigned int npatterns,
  57. unsigned int nelts_per_pattern)
  58. {
  59. new_vector (mode, npatterns, nelts_per_pattern);
  60. }
  61. /* Start building a new vector of mode MODE. Initially encode the value
  62. as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each. */
  63. inline void
  64. rtx_vector_builder::new_vector (machine_mode mode, unsigned int npatterns,
  65. unsigned int nelts_per_pattern)
  66. {
  67. m_mode = mode;
  68. parent::new_vector (GET_MODE_NUNITS (mode), npatterns, nelts_per_pattern);
  69. }
  70. /* Return true if elements ELT1 and ELT2 are equal. */
  71. inline bool
  72. rtx_vector_builder::equal_p (rtx elt1, rtx elt2) const
  73. {
  74. return rtx_equal_p (elt1, elt2);
  75. }
  76. /* Return true if a stepped representation is OK. We don't allow
  77. linear series for anything other than integers, to avoid problems
  78. with rounding. */
  79. inline bool
  80. rtx_vector_builder::allow_steps_p () const
  81. {
  82. return is_a <scalar_int_mode> (GET_MODE_INNER (m_mode));
  83. }
  84. /* Return true if element ELT can be interpreted as an integer. */
  85. inline bool
  86. rtx_vector_builder::integral_p (rtx elt) const
  87. {
  88. return CONST_SCALAR_INT_P (elt);
  89. }
  90. /* Return the value of element ELT2 minus the value of element ELT1.
  91. Both elements are known to be CONST_SCALAR_INT_Ps. */
  92. inline wide_int
  93. rtx_vector_builder::step (rtx elt1, rtx elt2) const
  94. {
  95. return wi::sub (rtx_mode_t (elt2, GET_MODE_INNER (m_mode)),
  96. rtx_mode_t (elt1, GET_MODE_INNER (m_mode)));
  97. }
  98. #endif