GCC Middle and Back End API Reference
tree-vector-builder.h
Go to the documentation of this file.
1/* A class for building vector tree constants.
2 Copyright (C) 2017-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_TREE_VECTOR_BUILDER_H
21#define GCC_TREE_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. */
27class tree_vector_builder : public vector_builder<tree, tree,
28 tree_vector_builder>
29{
32
33public:
35 tree_vector_builder (tree, unsigned int, unsigned int);
36 tree build ();
37
38 tree type () const { return m_type; }
39
40 void new_vector (tree, unsigned int, unsigned int);
41
42private:
43 bool equal_p (const_tree, const_tree) const;
44 bool allow_steps_p () const;
45 bool integral_p (const_tree) const;
47 tree apply_step (tree, unsigned int, const wide_int &) const;
48 bool can_elide_p (const_tree) const;
50
54 { return VECTOR_CST_NELTS (t); }
55 static unsigned int npatterns_of (const_tree t)
56 { return VECTOR_CST_NPATTERNS (t); }
57 static unsigned int nelts_per_pattern_of (const_tree t)
58 { return VECTOR_CST_NELTS_PER_PATTERN (t); }
59
61};
62
63/* Create a new builder for a vector of type TYPE. Initially encode the
64 value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
65 each. */
66
67inline
73
74/* Start building a new vector of type TYPE. Initially encode the value
75 as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each. */
76
77inline void
85
86/* Return true if elements I1 and I2 are equal. */
87
88inline bool
90{
91 return operand_equal_p (elt1, elt2, OEP_BITWISE);
92}
93
94/* Return true if a stepped representation is OK. We don't allow
95 linear series for anything other than integers, to avoid problems
96 with rounding. */
97
98inline bool
103
104/* Return true if ELT can be interpreted as an integer. */
105
106inline bool
108{
109 return TREE_CODE (elt) == INTEGER_CST;
110}
111
112/* Return the value of element ELT2 minus the value of element ELT1.
113 Both elements are known to be INTEGER_CSTs. */
114
115inline wide_int
117{
118 return wi::to_wide (elt2) - wi::to_wide (elt1);
119}
120
121/* Return true if we can drop element ELT, even if the retained elements
122 are different. Return false if this would mean losing overflow
123 information. */
124
125inline bool
130
131/* Record that ELT2 is being elided, given that ELT1_PTR points to the last
132 encoded element for the containing pattern. */
133
134inline void
136{
137 if (TREE_OVERFLOW_P (elt2))
138 {
139 gcc_assert (operand_equal_p (*elt1_ptr, elt2, 0));
140 if (!TREE_OVERFLOW (elt2))
141 *elt1_ptr = elt2;
142 }
143}
144
145#endif
Definition tree-vector-builder.h:29
static unsigned int npatterns_of(const_tree t)
Definition tree-vector-builder.h:55
wide_int step(const_tree, const_tree) const
Definition tree-vector-builder.h:116
void note_representative(tree *, tree)
Definition tree-vector-builder.h:135
void new_vector(tree, unsigned int, unsigned int)
Definition tree-vector-builder.h:78
tree type() const
Definition tree-vector-builder.h:38
tree apply_step(tree, unsigned int, const wide_int &) const
Definition tree-vector-builder.cc:30
tree build()
Definition tree-vector-builder.cc:40
tree_vector_builder()
Definition tree-vector-builder.h:34
bool equal_p(const_tree, const_tree) const
Definition tree-vector-builder.h:89
bool integral_p(const_tree) const
Definition tree-vector-builder.h:107
vector_builder< tree, tree, tree_vector_builder > parent
Definition tree-vector-builder.h:30
static poly_uint64 shape_nelts(const_tree t)
Definition tree-vector-builder.h:51
bool allow_steps_p() const
Definition tree-vector-builder.h:99
static poly_uint64 nelts_of(const_tree t)
Definition tree-vector-builder.h:53
static unsigned int nelts_per_pattern_of(const_tree t)
Definition tree-vector-builder.h:57
bool can_elide_p(const_tree) const
Definition tree-vector-builder.h:126
tree m_type
Definition tree-vector-builder.h:60
Definition vector-builder.h:113
void new_vector(poly_uint64, unsigned int, unsigned int)
Definition vector-builder.h:193
unsigned int nelts_per_pattern() const
Definition vector-builder.h:119
unsigned int npatterns() const
Definition vector-builder.h:118
T elt(unsigned int) const
Definition vector-builder.h:229
const union tree_node * const_tree
Definition coretypes.h:98
union tree_node * tree
Definition coretypes.h:97
bool operand_equal_p(const_tree arg0, const_tree arg1, unsigned int flags)
Definition fold-const.cc:4252
tree_to_wide_ref to_wide(const_tree)
Definition tree.h:6388
Definition gengtype.h:252
#define gcc_assert(EXPR)
Definition system.h:821
@ OEP_BITWISE
Definition tree-core.h:957
poly_uint64 TYPE_VECTOR_SUBPARTS(const_tree node)
Definition tree.h:4252
#define TREE_OVERFLOW(NODE)
Definition tree.h:845
#define VECTOR_CST_NELTS(NODE)
Definition tree.h:1173
#define TREE_OVERFLOW_P(EXPR)
Definition tree.h:849
#define TREE_CODE(NODE)
Definition tree.h:324
#define TREE_TYPE(NODE)
Definition tree.h:512
#define INTEGRAL_TYPE_P(TYPE)
Definition tree.h:613
#define CONSTANT_CLASS_P(NODE)
Definition tree.h:215
#define VECTOR_CST_NPATTERNS(NODE)
Definition tree.h:1178
#define VECTOR_CST_NELTS_PER_PATTERN(NODE)
Definition tree.h:1180