New VECTOR_CST layout
[official-gcc.git] / gcc / tree-vector-builder.h
blobb7b56259b8c70cfb61e6ad563caa70ad16aed8de
1 /* A class for building vector tree constants.
2 Copyright (C) 2017 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef GCC_TREE_VECTOR_BUILDER_H
21 #define GCC_TREE_VECTOR_BUILDER_H
23 #include "vector-builder.h"
25 /* This class is used to build VECTOR_CSTs from a sequence of elements.
26 See vector_builder for more details. */
27 class tree_vector_builder : public vector_builder<tree, tree_vector_builder>
29 typedef vector_builder<tree, tree_vector_builder> parent;
30 friend class vector_builder<tree, tree_vector_builder>;
32 public:
33 tree_vector_builder () : m_type (0) {}
34 tree_vector_builder (tree, unsigned int, unsigned int);
35 tree build ();
37 tree type () const { return m_type; }
39 void new_vector (tree, unsigned int, unsigned int);
40 bool new_unary_operation (tree, tree, bool);
42 private:
43 bool equal_p (const_tree, const_tree) const;
44 bool allow_steps_p () const;
45 bool integral_p (const_tree) const;
46 wide_int step (const_tree, const_tree) const;
47 bool can_elide_p (const_tree) const;
48 void note_representative (tree *, tree);
50 tree m_type;
53 /* Create a new builder for a vector of type TYPE. Initially encode the
54 value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
55 each. */
57 inline
58 tree_vector_builder::tree_vector_builder (tree type, unsigned int npatterns,
59 unsigned int nelts_per_pattern)
61 new_vector (type, npatterns, nelts_per_pattern);
64 /* Start building a new vector of type TYPE. Initially encode the value
65 as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each. */
67 inline void
68 tree_vector_builder::new_vector (tree type, unsigned int npatterns,
69 unsigned int nelts_per_pattern)
71 m_type = type;
72 parent::new_vector (TYPE_VECTOR_SUBPARTS (type), npatterns,
73 nelts_per_pattern);
76 /* Return true if elements I1 and I2 are equal. */
78 inline bool
79 tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const
81 return operand_equal_p (elt1, elt2, 0);
84 /* Return true if a stepped representation is OK. We don't allow
85 linear series for anything other than integers, to avoid problems
86 with rounding. */
88 inline bool
89 tree_vector_builder::allow_steps_p () const
91 return INTEGRAL_TYPE_P (TREE_TYPE (m_type));
94 /* Return true if ELT can be interpreted as an integer. */
96 inline bool
97 tree_vector_builder::integral_p (const_tree elt) const
99 return TREE_CODE (elt) == INTEGER_CST;
102 /* Return the value of element ELT2 minus the value of element ELT1.
103 Both elements are known to be INTEGER_CSTs. */
105 inline wide_int
106 tree_vector_builder::step (const_tree elt1, const_tree elt2) const
108 return wi::to_wide (elt2) - wi::to_wide (elt1);
111 /* Return true if we can drop element ELT, even if the retained elements
112 are different. Return false if this would mean losing overflow
113 information. */
115 inline bool
116 tree_vector_builder::can_elide_p (const_tree elt) const
118 return !CONSTANT_CLASS_P (elt) || !TREE_OVERFLOW (elt);
121 /* Record that ELT2 is being elided, given that ELT1_PTR points to the last
122 encoded element for the containing pattern. */
124 inline void
125 tree_vector_builder::note_representative (tree *elt1_ptr, tree elt2)
127 if (CONSTANT_CLASS_P (elt2) && TREE_OVERFLOW (elt2))
129 gcc_assert (operand_equal_p (*elt1_ptr, elt2, 0));
130 if (!TREE_OVERFLOW (elt2))
131 *elt1_ptr = elt2;
135 #endif