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