summaryrefslogtreecommitdiff
path: root/gcc/tree-vector-builder.h
blob: a534164f7b838065908b4fd7eef79d763b00685f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* A class for building vector tree constants.
   Copyright (C) 2017-2020 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#ifndef GCC_TREE_VECTOR_BUILDER_H
#define GCC_TREE_VECTOR_BUILDER_H

#include "vector-builder.h"

/* This class is used to build VECTOR_CSTs from a sequence of elements.
   See vector_builder for more details.  */
class tree_vector_builder : public vector_builder<tree, tree,
						  tree_vector_builder>
{
  typedef vector_builder<tree, tree, tree_vector_builder> parent;
  friend class vector_builder<tree, tree, tree_vector_builder>;

public:
  tree_vector_builder () : m_type (0) {}
  tree_vector_builder (tree, unsigned int, unsigned int);
  tree build ();

  tree type () const { return m_type; }

  void new_vector (tree, unsigned int, unsigned int);

private:
  bool equal_p (const_tree, const_tree) const;
  bool allow_steps_p () const;
  bool integral_p (const_tree) const;
  wide_int step (const_tree, const_tree) const;
  tree apply_step (tree, unsigned int, const wide_int &) const;
  bool can_elide_p (const_tree) const;
  void note_representative (tree *, tree);

  static poly_uint64 shape_nelts (const_tree t)
    { return TYPE_VECTOR_SUBPARTS (t); }
  static poly_uint64 nelts_of (const_tree t)
    { return VECTOR_CST_NELTS (t); }
  static unsigned int npatterns_of (const_tree t)
    { return VECTOR_CST_NPATTERNS (t); }
  static unsigned int nelts_per_pattern_of (const_tree t)
    { return VECTOR_CST_NELTS_PER_PATTERN (t); }

  tree m_type;
};

/* Create a new builder for a vector of type TYPE.  Initially encode the
   value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
   each.  */

inline
tree_vector_builder::tree_vector_builder (tree type, unsigned int npatterns,
					  unsigned int nelts_per_pattern)
{
  new_vector (type, npatterns, nelts_per_pattern);
}

/* Start building a new vector of type TYPE.  Initially encode the value
   as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each.  */

inline void
tree_vector_builder::new_vector (tree type, unsigned int npatterns,
				 unsigned int nelts_per_pattern)
{
  m_type = type;
  parent::new_vector (TYPE_VECTOR_SUBPARTS (type), npatterns,
		      nelts_per_pattern);
}

/* Return true if elements I1 and I2 are equal.  */

inline bool
tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const
{
  return operand_equal_p (elt1, elt2, OEP_BITWISE);
}

/* Return true if a stepped representation is OK.  We don't allow
   linear series for anything other than integers, to avoid problems
   with rounding.  */

inline bool
tree_vector_builder::allow_steps_p () const
{
  return INTEGRAL_TYPE_P (TREE_TYPE (m_type));
}

/* Return true if ELT can be interpreted as an integer.  */

inline bool
tree_vector_builder::integral_p (const_tree elt) const
{
  return TREE_CODE (elt) == INTEGER_CST;
}

/* Return the value of element ELT2 minus the value of element ELT1.
   Both elements are known to be INTEGER_CSTs.  */

inline wide_int
tree_vector_builder::step (const_tree elt1, const_tree elt2) const
{
  return wi::to_wide (elt2) - wi::to_wide (elt1);
}

/* Return true if we can drop element ELT, even if the retained elements
   are different.  Return false if this would mean losing overflow
   information.  */

inline bool
tree_vector_builder::can_elide_p (const_tree elt) const
{
  return !CONSTANT_CLASS_P (elt) || !TREE_OVERFLOW (elt);
}

/* Record that ELT2 is being elided, given that ELT1_PTR points to the last
   encoded element for the containing pattern.  */

inline void
tree_vector_builder::note_representative (tree *elt1_ptr, tree elt2)
{
  if (CONSTANT_CLASS_P (elt2) && TREE_OVERFLOW (elt2))
    {
      gcc_assert (operand_equal_p (*elt1_ptr, elt2, 0));
      if (!TREE_OVERFLOW (elt2))
	*elt1_ptr = elt2;
    }
}

#endif