1*38fd1498Szrj /* A class for building vector rtx constants.
2*38fd1498Szrj Copyright (C) 2017-2018 Free Software Foundation, Inc.
3*38fd1498Szrj
4*38fd1498Szrj This file is part of GCC.
5*38fd1498Szrj
6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
7*38fd1498Szrj the terms of the GNU General Public License as published by the Free
8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj version.
10*38fd1498Szrj
11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14*38fd1498Szrj for more details.
15*38fd1498Szrj
16*38fd1498Szrj You should have received a copy of the GNU General Public License
17*38fd1498Szrj along with GCC; see the file COPYING3. If not see
18*38fd1498Szrj <http://www.gnu.org/licenses/>. */
19*38fd1498Szrj
20*38fd1498Szrj #ifndef GCC_RTX_VECTOR_BUILDER_H
21*38fd1498Szrj #define GCC_RTX_VECTOR_BUILDER_H
22*38fd1498Szrj
23*38fd1498Szrj #include "vector-builder.h"
24*38fd1498Szrj
25*38fd1498Szrj /* This class is used to build VECTOR_CSTs from a sequence of elements.
26*38fd1498Szrj See vector_builder for more details. */
27*38fd1498Szrj class rtx_vector_builder : public vector_builder<rtx, rtx_vector_builder>
28*38fd1498Szrj {
29*38fd1498Szrj typedef vector_builder<rtx, rtx_vector_builder> parent;
30*38fd1498Szrj friend class vector_builder<rtx, rtx_vector_builder>;
31*38fd1498Szrj
32*38fd1498Szrj public:
rtx_vector_builder()33*38fd1498Szrj rtx_vector_builder () : m_mode (VOIDmode) {}
34*38fd1498Szrj rtx_vector_builder (machine_mode, unsigned int, unsigned int);
35*38fd1498Szrj rtx build (rtvec);
36*38fd1498Szrj rtx build ();
37*38fd1498Szrj
mode()38*38fd1498Szrj machine_mode mode () const { return m_mode; }
39*38fd1498Szrj
40*38fd1498Szrj void new_vector (machine_mode, unsigned int, unsigned int);
41*38fd1498Szrj
42*38fd1498Szrj private:
43*38fd1498Szrj bool equal_p (rtx, rtx) const;
44*38fd1498Szrj bool allow_steps_p () const;
45*38fd1498Szrj bool integral_p (rtx) const;
46*38fd1498Szrj wide_int step (rtx, rtx) const;
47*38fd1498Szrj rtx apply_step (rtx, unsigned int, const wide_int &) const;
can_elide_p(rtx)48*38fd1498Szrj bool can_elide_p (rtx) const { return true; }
note_representative(rtx *,rtx)49*38fd1498Szrj void note_representative (rtx *, rtx) {}
50*38fd1498Szrj
51*38fd1498Szrj rtx find_cached_value ();
52*38fd1498Szrj
53*38fd1498Szrj machine_mode m_mode;
54*38fd1498Szrj };
55*38fd1498Szrj
56*38fd1498Szrj /* Create a new builder for a vector of mode MODE. Initially encode the
57*38fd1498Szrj value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
58*38fd1498Szrj each. */
59*38fd1498Szrj
60*38fd1498Szrj inline
rtx_vector_builder(machine_mode mode,unsigned int npatterns,unsigned int nelts_per_pattern)61*38fd1498Szrj rtx_vector_builder::rtx_vector_builder (machine_mode mode,
62*38fd1498Szrj unsigned int npatterns,
63*38fd1498Szrj unsigned int nelts_per_pattern)
64*38fd1498Szrj {
65*38fd1498Szrj new_vector (mode, npatterns, nelts_per_pattern);
66*38fd1498Szrj }
67*38fd1498Szrj
68*38fd1498Szrj /* Start building a new vector of mode MODE. Initially encode the value
69*38fd1498Szrj as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each. */
70*38fd1498Szrj
71*38fd1498Szrj inline void
new_vector(machine_mode mode,unsigned int npatterns,unsigned int nelts_per_pattern)72*38fd1498Szrj rtx_vector_builder::new_vector (machine_mode mode, unsigned int npatterns,
73*38fd1498Szrj unsigned int nelts_per_pattern)
74*38fd1498Szrj {
75*38fd1498Szrj m_mode = mode;
76*38fd1498Szrj parent::new_vector (GET_MODE_NUNITS (mode), npatterns, nelts_per_pattern);
77*38fd1498Szrj }
78*38fd1498Szrj
79*38fd1498Szrj /* Return true if elements ELT1 and ELT2 are equal. */
80*38fd1498Szrj
81*38fd1498Szrj inline bool
equal_p(rtx elt1,rtx elt2)82*38fd1498Szrj rtx_vector_builder::equal_p (rtx elt1, rtx elt2) const
83*38fd1498Szrj {
84*38fd1498Szrj return rtx_equal_p (elt1, elt2);
85*38fd1498Szrj }
86*38fd1498Szrj
87*38fd1498Szrj /* Return true if a stepped representation is OK. We don't allow
88*38fd1498Szrj linear series for anything other than integers, to avoid problems
89*38fd1498Szrj with rounding. */
90*38fd1498Szrj
91*38fd1498Szrj inline bool
allow_steps_p()92*38fd1498Szrj rtx_vector_builder::allow_steps_p () const
93*38fd1498Szrj {
94*38fd1498Szrj return is_a <scalar_int_mode> (GET_MODE_INNER (m_mode));
95*38fd1498Szrj }
96*38fd1498Szrj
97*38fd1498Szrj /* Return true if element ELT can be interpreted as an integer. */
98*38fd1498Szrj
99*38fd1498Szrj inline bool
integral_p(rtx elt)100*38fd1498Szrj rtx_vector_builder::integral_p (rtx elt) const
101*38fd1498Szrj {
102*38fd1498Szrj return CONST_SCALAR_INT_P (elt);
103*38fd1498Szrj }
104*38fd1498Szrj
105*38fd1498Szrj /* Return the value of element ELT2 minus the value of element ELT1.
106*38fd1498Szrj Both elements are known to be CONST_SCALAR_INT_Ps. */
107*38fd1498Szrj
108*38fd1498Szrj inline wide_int
step(rtx elt1,rtx elt2)109*38fd1498Szrj rtx_vector_builder::step (rtx elt1, rtx elt2) const
110*38fd1498Szrj {
111*38fd1498Szrj return wi::sub (rtx_mode_t (elt2, GET_MODE_INNER (m_mode)),
112*38fd1498Szrj rtx_mode_t (elt1, GET_MODE_INNER (m_mode)));
113*38fd1498Szrj }
114*38fd1498Szrj
115*38fd1498Szrj #endif
116