xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/tree-vector-builder.h (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1cef8759bSmrg /* A class for building vector tree constants.
2*4c3eb207Smrg    Copyright (C) 2017-2020 Free Software Foundation, Inc.
3cef8759bSmrg 
4cef8759bSmrg This file is part of GCC.
5cef8759bSmrg 
6cef8759bSmrg GCC is free software; you can redistribute it and/or modify it under
7cef8759bSmrg the terms of the GNU General Public License as published by the Free
8cef8759bSmrg Software Foundation; either version 3, or (at your option) any later
9cef8759bSmrg version.
10cef8759bSmrg 
11cef8759bSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12cef8759bSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
13cef8759bSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14cef8759bSmrg for more details.
15cef8759bSmrg 
16cef8759bSmrg You should have received a copy of the GNU General Public License
17cef8759bSmrg along with GCC; see the file COPYING3.  If not see
18cef8759bSmrg <http://www.gnu.org/licenses/>.  */
19cef8759bSmrg 
20cef8759bSmrg #ifndef GCC_TREE_VECTOR_BUILDER_H
21cef8759bSmrg #define GCC_TREE_VECTOR_BUILDER_H
22cef8759bSmrg 
23cef8759bSmrg #include "vector-builder.h"
24cef8759bSmrg 
25cef8759bSmrg /* This class is used to build VECTOR_CSTs from a sequence of elements.
26cef8759bSmrg    See vector_builder for more details.  */
27*4c3eb207Smrg class tree_vector_builder : public vector_builder<tree, tree,
28*4c3eb207Smrg 						  tree_vector_builder>
29cef8759bSmrg {
30*4c3eb207Smrg   typedef vector_builder<tree, tree, tree_vector_builder> parent;
31*4c3eb207Smrg   friend class vector_builder<tree, tree, tree_vector_builder>;
32cef8759bSmrg 
33cef8759bSmrg public:
tree_vector_builder()34cef8759bSmrg   tree_vector_builder () : m_type (0) {}
35cef8759bSmrg   tree_vector_builder (tree, unsigned int, unsigned int);
36cef8759bSmrg   tree build ();
37cef8759bSmrg 
type()38cef8759bSmrg   tree type () const { return m_type; }
39cef8759bSmrg 
40cef8759bSmrg   void new_vector (tree, unsigned int, unsigned int);
41cef8759bSmrg 
42cef8759bSmrg private:
43cef8759bSmrg   bool equal_p (const_tree, const_tree) const;
44cef8759bSmrg   bool allow_steps_p () const;
45cef8759bSmrg   bool integral_p (const_tree) const;
46cef8759bSmrg   wide_int step (const_tree, const_tree) const;
47cef8759bSmrg   tree apply_step (tree, unsigned int, const wide_int &) const;
48cef8759bSmrg   bool can_elide_p (const_tree) const;
49cef8759bSmrg   void note_representative (tree *, tree);
50cef8759bSmrg 
shape_nelts(const_tree t)51*4c3eb207Smrg   static poly_uint64 shape_nelts (const_tree t)
52*4c3eb207Smrg     { return TYPE_VECTOR_SUBPARTS (t); }
nelts_of(const_tree t)53*4c3eb207Smrg   static poly_uint64 nelts_of (const_tree t)
54*4c3eb207Smrg     { return VECTOR_CST_NELTS (t); }
npatterns_of(const_tree t)55*4c3eb207Smrg   static unsigned int npatterns_of (const_tree t)
56*4c3eb207Smrg     { return VECTOR_CST_NPATTERNS (t); }
nelts_per_pattern_of(const_tree t)57*4c3eb207Smrg   static unsigned int nelts_per_pattern_of (const_tree t)
58*4c3eb207Smrg     { return VECTOR_CST_NELTS_PER_PATTERN (t); }
59*4c3eb207Smrg 
60cef8759bSmrg   tree m_type;
61cef8759bSmrg };
62cef8759bSmrg 
63cef8759bSmrg /* Create a new builder for a vector of type TYPE.  Initially encode the
64cef8759bSmrg    value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
65cef8759bSmrg    each.  */
66cef8759bSmrg 
67cef8759bSmrg inline
tree_vector_builder(tree type,unsigned int npatterns,unsigned int nelts_per_pattern)68cef8759bSmrg tree_vector_builder::tree_vector_builder (tree type, unsigned int npatterns,
69cef8759bSmrg 					  unsigned int nelts_per_pattern)
70cef8759bSmrg {
71cef8759bSmrg   new_vector (type, npatterns, nelts_per_pattern);
72cef8759bSmrg }
73cef8759bSmrg 
74cef8759bSmrg /* Start building a new vector of type TYPE.  Initially encode the value
75cef8759bSmrg    as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each.  */
76cef8759bSmrg 
77cef8759bSmrg inline void
new_vector(tree type,unsigned int npatterns,unsigned int nelts_per_pattern)78cef8759bSmrg tree_vector_builder::new_vector (tree type, unsigned int npatterns,
79cef8759bSmrg 				 unsigned int nelts_per_pattern)
80cef8759bSmrg {
81cef8759bSmrg   m_type = type;
82cef8759bSmrg   parent::new_vector (TYPE_VECTOR_SUBPARTS (type), npatterns,
83cef8759bSmrg 		      nelts_per_pattern);
84cef8759bSmrg }
85cef8759bSmrg 
86cef8759bSmrg /* Return true if elements I1 and I2 are equal.  */
87cef8759bSmrg 
88cef8759bSmrg inline bool
equal_p(const_tree elt1,const_tree elt2)89cef8759bSmrg tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const
90cef8759bSmrg {
91cef8759bSmrg   return operand_equal_p (elt1, elt2, OEP_BITWISE);
92cef8759bSmrg }
93cef8759bSmrg 
94cef8759bSmrg /* Return true if a stepped representation is OK.  We don't allow
95cef8759bSmrg    linear series for anything other than integers, to avoid problems
96cef8759bSmrg    with rounding.  */
97cef8759bSmrg 
98cef8759bSmrg inline bool
allow_steps_p()99cef8759bSmrg tree_vector_builder::allow_steps_p () const
100cef8759bSmrg {
101cef8759bSmrg   return INTEGRAL_TYPE_P (TREE_TYPE (m_type));
102cef8759bSmrg }
103cef8759bSmrg 
104cef8759bSmrg /* Return true if ELT can be interpreted as an integer.  */
105cef8759bSmrg 
106cef8759bSmrg inline bool
integral_p(const_tree elt)107cef8759bSmrg tree_vector_builder::integral_p (const_tree elt) const
108cef8759bSmrg {
109cef8759bSmrg   return TREE_CODE (elt) == INTEGER_CST;
110cef8759bSmrg }
111cef8759bSmrg 
112cef8759bSmrg /* Return the value of element ELT2 minus the value of element ELT1.
113cef8759bSmrg    Both elements are known to be INTEGER_CSTs.  */
114cef8759bSmrg 
115cef8759bSmrg inline wide_int
step(const_tree elt1,const_tree elt2)116cef8759bSmrg tree_vector_builder::step (const_tree elt1, const_tree elt2) const
117cef8759bSmrg {
118cef8759bSmrg   return wi::to_wide (elt2) - wi::to_wide (elt1);
119cef8759bSmrg }
120cef8759bSmrg 
121cef8759bSmrg /* Return true if we can drop element ELT, even if the retained elements
122cef8759bSmrg    are different.  Return false if this would mean losing overflow
123cef8759bSmrg    information.  */
124cef8759bSmrg 
125cef8759bSmrg inline bool
can_elide_p(const_tree elt)126cef8759bSmrg tree_vector_builder::can_elide_p (const_tree elt) const
127cef8759bSmrg {
128cef8759bSmrg   return !CONSTANT_CLASS_P (elt) || !TREE_OVERFLOW (elt);
129cef8759bSmrg }
130cef8759bSmrg 
131cef8759bSmrg /* Record that ELT2 is being elided, given that ELT1_PTR points to the last
132cef8759bSmrg    encoded element for the containing pattern.  */
133cef8759bSmrg 
134cef8759bSmrg inline void
note_representative(tree * elt1_ptr,tree elt2)135cef8759bSmrg tree_vector_builder::note_representative (tree *elt1_ptr, tree elt2)
136cef8759bSmrg {
137cef8759bSmrg   if (CONSTANT_CLASS_P (elt2) && TREE_OVERFLOW (elt2))
138cef8759bSmrg     {
139cef8759bSmrg       gcc_assert (operand_equal_p (*elt1_ptr, elt2, 0));
140cef8759bSmrg       if (!TREE_OVERFLOW (elt2))
141cef8759bSmrg 	*elt1_ptr = elt2;
142cef8759bSmrg     }
143cef8759bSmrg }
144cef8759bSmrg 
145cef8759bSmrg #endif
146