rtx-vector-builder.h 3.3 KB

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