xref: /dflybsd-src/contrib/gcc-8.0/gcc/tree-vector-builder.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* A class for building vector tree 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_TREE_VECTOR_BUILDER_H
21*38fd1498Szrj #define GCC_TREE_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 tree_vector_builder : public vector_builder<tree, tree_vector_builder>
28*38fd1498Szrj {
29*38fd1498Szrj   typedef vector_builder<tree, tree_vector_builder> parent;
30*38fd1498Szrj   friend class vector_builder<tree, tree_vector_builder>;
31*38fd1498Szrj 
32*38fd1498Szrj public:
tree_vector_builder()33*38fd1498Szrj   tree_vector_builder () : m_type (0) {}
34*38fd1498Szrj   tree_vector_builder (tree, unsigned int, unsigned int);
35*38fd1498Szrj   tree build ();
36*38fd1498Szrj 
type()37*38fd1498Szrj   tree type () const { return m_type; }
38*38fd1498Szrj 
39*38fd1498Szrj   void new_vector (tree, unsigned int, unsigned int);
40*38fd1498Szrj   bool new_unary_operation (tree, tree, bool);
41*38fd1498Szrj   bool new_binary_operation (tree, tree, tree, bool);
42*38fd1498Szrj 
43*38fd1498Szrj   static unsigned int binary_encoded_nelts (tree, tree);
44*38fd1498Szrj 
45*38fd1498Szrj private:
46*38fd1498Szrj   bool equal_p (const_tree, const_tree) const;
47*38fd1498Szrj   bool allow_steps_p () const;
48*38fd1498Szrj   bool integral_p (const_tree) const;
49*38fd1498Szrj   wide_int step (const_tree, const_tree) const;
50*38fd1498Szrj   tree apply_step (tree, unsigned int, const wide_int &) const;
51*38fd1498Szrj   bool can_elide_p (const_tree) const;
52*38fd1498Szrj   void note_representative (tree *, tree);
53*38fd1498Szrj 
54*38fd1498Szrj   tree m_type;
55*38fd1498Szrj };
56*38fd1498Szrj 
57*38fd1498Szrj /* Create a new builder for a vector of type TYPE.  Initially encode the
58*38fd1498Szrj    value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
59*38fd1498Szrj    each.  */
60*38fd1498Szrj 
61*38fd1498Szrj inline
tree_vector_builder(tree type,unsigned int npatterns,unsigned int nelts_per_pattern)62*38fd1498Szrj tree_vector_builder::tree_vector_builder (tree type, unsigned int npatterns,
63*38fd1498Szrj 					  unsigned int nelts_per_pattern)
64*38fd1498Szrj {
65*38fd1498Szrj   new_vector (type, npatterns, nelts_per_pattern);
66*38fd1498Szrj }
67*38fd1498Szrj 
68*38fd1498Szrj /* Start building a new vector of type TYPE.  Initially encode the value
69*38fd1498Szrj    as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each.  */
70*38fd1498Szrj 
71*38fd1498Szrj inline void
new_vector(tree type,unsigned int npatterns,unsigned int nelts_per_pattern)72*38fd1498Szrj tree_vector_builder::new_vector (tree type, unsigned int npatterns,
73*38fd1498Szrj 				 unsigned int nelts_per_pattern)
74*38fd1498Szrj {
75*38fd1498Szrj   m_type = type;
76*38fd1498Szrj   parent::new_vector (TYPE_VECTOR_SUBPARTS (type), npatterns,
77*38fd1498Szrj 		      nelts_per_pattern);
78*38fd1498Szrj }
79*38fd1498Szrj 
80*38fd1498Szrj /* Return true if elements I1 and I2 are equal.  */
81*38fd1498Szrj 
82*38fd1498Szrj inline bool
equal_p(const_tree elt1,const_tree elt2)83*38fd1498Szrj tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const
84*38fd1498Szrj {
85*38fd1498Szrj   return operand_equal_p (elt1, elt2, 0);
86*38fd1498Szrj }
87*38fd1498Szrj 
88*38fd1498Szrj /* Return true if a stepped representation is OK.  We don't allow
89*38fd1498Szrj    linear series for anything other than integers, to avoid problems
90*38fd1498Szrj    with rounding.  */
91*38fd1498Szrj 
92*38fd1498Szrj inline bool
allow_steps_p()93*38fd1498Szrj tree_vector_builder::allow_steps_p () const
94*38fd1498Szrj {
95*38fd1498Szrj   return INTEGRAL_TYPE_P (TREE_TYPE (m_type));
96*38fd1498Szrj }
97*38fd1498Szrj 
98*38fd1498Szrj /* Return true if ELT can be interpreted as an integer.  */
99*38fd1498Szrj 
100*38fd1498Szrj inline bool
integral_p(const_tree elt)101*38fd1498Szrj tree_vector_builder::integral_p (const_tree elt) const
102*38fd1498Szrj {
103*38fd1498Szrj   return TREE_CODE (elt) == INTEGER_CST;
104*38fd1498Szrj }
105*38fd1498Szrj 
106*38fd1498Szrj /* Return the value of element ELT2 minus the value of element ELT1.
107*38fd1498Szrj    Both elements are known to be INTEGER_CSTs.  */
108*38fd1498Szrj 
109*38fd1498Szrj inline wide_int
step(const_tree elt1,const_tree elt2)110*38fd1498Szrj tree_vector_builder::step (const_tree elt1, const_tree elt2) const
111*38fd1498Szrj {
112*38fd1498Szrj   return wi::to_wide (elt2) - wi::to_wide (elt1);
113*38fd1498Szrj }
114*38fd1498Szrj 
115*38fd1498Szrj /* Return true if we can drop element ELT, even if the retained elements
116*38fd1498Szrj    are different.  Return false if this would mean losing overflow
117*38fd1498Szrj    information.  */
118*38fd1498Szrj 
119*38fd1498Szrj inline bool
can_elide_p(const_tree elt)120*38fd1498Szrj tree_vector_builder::can_elide_p (const_tree elt) const
121*38fd1498Szrj {
122*38fd1498Szrj   return !CONSTANT_CLASS_P (elt) || !TREE_OVERFLOW (elt);
123*38fd1498Szrj }
124*38fd1498Szrj 
125*38fd1498Szrj /* Record that ELT2 is being elided, given that ELT1_PTR points to the last
126*38fd1498Szrj    encoded element for the containing pattern.  */
127*38fd1498Szrj 
128*38fd1498Szrj inline void
note_representative(tree * elt1_ptr,tree elt2)129*38fd1498Szrj tree_vector_builder::note_representative (tree *elt1_ptr, tree elt2)
130*38fd1498Szrj {
131*38fd1498Szrj   if (CONSTANT_CLASS_P (elt2) && TREE_OVERFLOW (elt2))
132*38fd1498Szrj     {
133*38fd1498Szrj       gcc_assert (operand_equal_p (*elt1_ptr, elt2, 0));
134*38fd1498Szrj       if (!TREE_OVERFLOW (elt2))
135*38fd1498Szrj 	*elt1_ptr = elt2;
136*38fd1498Szrj     }
137*38fd1498Szrj }
138*38fd1498Szrj 
139*38fd1498Szrj #endif
140