GCC Middle and Back End API Reference
|
#include <vector-builder.h>
Public Member Functions | |
vector_builder () | |
poly_uint64 | full_nelts () const |
unsigned int | npatterns () const |
unsigned int | nelts_per_pattern () const |
unsigned int | encoded_nelts () const |
bool | encoded_full_vector_p () const |
T | elt (unsigned int) const |
unsigned int | count_dups (int, int, int) const |
bool | operator== (const Derived &) const |
bool | operator!= (const Derived &x) const |
bool | new_unary_operation (Shape, T, bool) |
bool | new_binary_operation (Shape, T, T, bool) |
void | finalize () |
vec< T, va_heap > | to_vec_legacy () |
Static Public Member Functions | |
static unsigned int | binary_encoded_nelts (T, T) |
Protected Member Functions | |
void | new_vector (poly_uint64, unsigned int, unsigned int) |
void | reshape (unsigned int, unsigned int) |
bool | repeating_sequence_p (unsigned int, unsigned int, unsigned int) |
bool | stepped_sequence_p (unsigned int, unsigned int, unsigned int) |
bool | try_npatterns (unsigned int) |
Private Member Functions | |
vector_builder (const vector_builder &) | |
vector_builder & | operator= (const vector_builder &) |
Derived * | derived () |
const Derived * | derived () const |
Private Attributes | |
poly_uint64 | m_full_nelts |
unsigned int | m_npatterns |
unsigned int | m_nelts_per_pattern |
vec< T, va_heap, vl_embed > | m_auto |
unsigned char | m_data [sizeof(T) *N] |
A class for building vector constant patterns. Copyright (C) 2017-2025 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/>.
This class is a wrapper around auto_vec<T> for building vectors of T. It aims to encode each vector as npatterns interleaved patterns, where each pattern represents a sequence: { BASE0, BASE1, BASE1 + STEP, BASE1 + STEP*2, BASE1 + STEP*3, ... } The first three elements in each pattern provide enough information to derive the other elements. If all patterns have a STEP of zero, we only need to encode the first two elements in each pattern. If BASE1 is also equal to BASE0 for all patterns, we only need to encode the first element in each pattern. The number of encoded elements per pattern is given by nelts_per_pattern. The class can be used in two ways: 1. It can be used to build a full image of the vector, which is then canonicalized by finalize (). In this case npatterns is initially the number of elements in the vector and nelts_per_pattern is initially 1. 2. It can be used to build a vector that already has a known encoding. This is preferred since it is more efficient and copes with variable-length vectors. finalize () then canonicalizes the encoding to a simpler form if possible. Shape is the type that specifies the number of elements in the vector and (where relevant) the type of each element. The derived class Derived provides the functionality of this class for specific Ts. Derived needs to provide the following interface: bool equal_p (T elt1, T elt2) const; Return true if elements ELT1 and ELT2 are equal. bool allow_steps_p () const; Return true if a stepped representation is OK. We don't allow linear series for anything other than integers, to avoid problems with rounding. bool integral_p (T elt) const; Return true if element ELT can be interpreted as an integer. StepType step (T elt1, T elt2) const; Return the value of element ELT2 minus the value of element ELT1, given integral_p (ELT1) && integral_p (ELT2). There is no fixed choice of StepType. T apply_step (T base, unsigned int factor, StepType step) const; Return a vector element with the value BASE + FACTOR * STEP. bool can_elide_p (T elt) const; Return true if we can drop element ELT, even if the retained elements are different. This is provided for TREE_OVERFLOW handling. void note_representative (T *elt1_ptr, T elt2); Record that ELT2 is being elided, given that ELT1_PTR points to the last encoded element for the containing pattern. This is again provided for TREE_OVERFLOW handling. static poly_uint64 shape_nelts (Shape shape); Return the number of elements in SHAPE. The class provides additional functionality for the case in which T can describe a vector constant as well as an individual element. This functionality requires: static poly_uint64 nelts_of (T x); Return the number of elements in vector constant X. static unsigned int npatterns_of (T x); Return the number of patterns used to encode vector constant X. static unsigned int nelts_per_pattern_of (T x); Return the number of elements used to encode each pattern in vector constant X.
|
inline |
References m_full_nelts, m_nelts_per_pattern, and m_npatterns.
|
private |
|
static |
Return the number of elements that the caller needs to operate on in order to handle a binary operation on vector constants VEC1 and VEC2. This static function is used instead of new_binary_operation if the result of the operation is not a constant vector.
References gcc_assert, poly_int< N, C >::is_constant(), known_eq, least_common_multiple(), MAX, MIN, nelts_per_pattern(), npatterns(), and T.
unsigned int vector_builder< T, Shape, Derived >::count_dups | ( | int | start, |
int | end, | ||
int | step ) const |
Return the number of leading duplicate elements in the range [START:END:STEP]. The value is always at least 1.
References derived(), elt(), end(), gcc_assert, and i.
|
inlineprivate |
Referenced by count_dups(), elt(), new_binary_operation(), new_unary_operation(), operator==(), repeating_sequence_p(), reshape(), and stepped_sequence_p().
|
inlineprivate |
T vector_builder< T, Shape, Derived >::elt | ( | unsigned int | i | ) | const |
Return the value of vector element I, which might or might not be encoded explicitly.
References count, derived(), encoded_nelts(), gcc_checking_assert, i, m_nelts_per_pattern, m_npatterns, and T.
Referenced by count_dups(), and gimple_build_vector().
|
inline |
Return true if every element of the vector is explicitly encoded.
References known_eq, m_full_nelts, m_nelts_per_pattern, and m_npatterns.
Referenced by try_npatterns().
|
inline |
Return the number of elements that are explicitly encoded. The vec starts with these explicitly-encoded elements and may contain additional elided elements.
References m_nelts_per_pattern, and m_npatterns.
Referenced by const_unop(), const_vector_from_tree(), const_vector_mask_from_tree(), drop_tree_overflow(), elt(), exact_inverse(), expand_vector_divmod(), finalize(), fold_const_vec_convert(), fold_convert_const(), fold_negate_expr_1(), fold_relational_const(), gimple_build_vector(), make_tree(), native_decode_vector_rtx(), native_interpret_vector_part(), new_vector(), operator==(), reshape(), simplify_const_binary_operation(), simplify_const_unary_operation(), try_npatterns(), vec_perm_indices_to_rtx(), vec_perm_indices_to_tree(), and vector_const_binop().
void vector_builder< T, Shape, Derived >::finalize | ( | ) |
Replace the current encoding with the canonical form.
References encoded_nelts(), gcc_assert, i, m_full_nelts, m_nelts_per_pattern, m_npatterns, pow2p_hwi(), repeating_sequence_p(), reshape(), stepped_sequence_p(), and try_npatterns().
|
inline |
Referenced by new_binary_operation(), new_unary_operation(), and new_vector().
|
inline |
Referenced by binary_encoded_nelts(), gimple_build_vector(), new_binary_operation(), new_unary_operation(), new_vector(), and reshape().
bool vector_builder< T, Shape, Derived >::new_binary_operation | ( | Shape | shape, |
T | vec1, | ||
T | vec2, | ||
bool | allow_stepped_p ) |
Try to start building a new vector of shape SHAPE that holds the result of a binary operation on vector constants VEC1 and VEC2. ALLOW_STEPPED_P is true if the operation can handle stepped encodings directly, without having to expand the full sequence. Return true if the operation is possible. Leave the builder unchanged otherwise.
References derived(), full_nelts(), gcc_assert, known_eq, least_common_multiple(), MAX, nelts_per_pattern(), npatterns(), and T.
Referenced by fold_relational_const(), simplify_const_binary_operation(), and vector_const_binop().
bool vector_builder< T, Shape, Derived >::new_unary_operation | ( | Shape | shape, |
T | vec, | ||
bool | allow_stepped_p ) |
Try to start building a new vector of shape SHAPE that holds the result of a unary operation on vector constant VEC. ALLOW_STEPPED_P is true if the operation can handle stepped encodings directly, without having to expand the full sequence. Return true if the operation is possible, which it always is when ALLOW_STEPPED_P is true. Leave the builder unchanged otherwise.
References derived(), full_nelts(), gcc_assert, known_eq, nelts_per_pattern(), npatterns(), and T.
Referenced by const_unop(), drop_tree_overflow(), exact_inverse(), expand_vector_divmod(), fold_const_vec_convert(), fold_convert_const(), fold_negate_expr_1(), simplify_const_unary_operation(), and vector_const_binop().
|
protected |
Start building a vector that has FULL_NELTS elements. Initially encode it using NPATTERNS patterns with NELTS_PER_PATTERN each.
References encoded_nelts(), full_nelts(), m_full_nelts, m_nelts_per_pattern, m_npatterns, nelts_per_pattern(), and npatterns().
Referenced by int_vector_builder< T >::int_vector_builder(), and int_vector_builder< poly_int64 >::int_vector_builder().
|
inline |
Referenced by binary_encoded_nelts(), new_binary_operation(), new_unary_operation(), new_vector(), reshape(), and try_npatterns().
|
inline |
|
private |
bool vector_builder< T, Shape, Derived >::operator== | ( | const Derived & | other | ) | const |
Return true if this vector and OTHER have the same elements and are encoded in the same way.
References derived(), encoded_nelts(), i, m_full_nelts, m_nelts_per_pattern, and m_npatterns.
Referenced by vector_builder< T, poly_uint64, int_vector_builder >::operator!=().
|
protected |
Return true if elements [START, END) contain a repeating sequence of STEP elements.
References derived(), end(), and i.
Referenced by finalize(), and try_npatterns().
|
protected |
Change the encoding to NPATTERNS patterns of NELTS_PER_PATTERN each, but without changing the underlying vector.
References derived(), encoded_nelts(), gcc_checking_assert, i, m_nelts_per_pattern, m_npatterns, nelts_per_pattern(), and npatterns().
Referenced by finalize(), and try_npatterns().
|
protected |
Return true if elements [START, END) contain STEP interleaved linear series.
References derived(), end(), i, and T.
Referenced by finalize(), and try_npatterns().
|
protected |
Try to change the number of encoded patterns to NPATTERNS, returning true on success.
References encoded_full_vector_p(), encoded_nelts(), gcc_unreachable, m_nelts_per_pattern, npatterns(), repeating_sequence_p(), reshape(), and stepped_sequence_p().
Referenced by finalize().
|
private |
Referenced by encoded_full_vector_p(), finalize(), new_vector(), operator==(), and vector_builder().
|
private |
Referenced by elt(), encoded_full_vector_p(), encoded_nelts(), finalize(), new_vector(), operator==(), reshape(), try_npatterns(), and vector_builder().
|
private |
Referenced by elt(), encoded_full_vector_p(), encoded_nelts(), finalize(), new_vector(), operator==(), reshape(), and vector_builder().