GCC Middle and Back End API Reference
vector_builder< T, Shape, Derived > Class Template Reference

#include <vector-builder.h>

Inheritance diagram for vector_builder< T, Shape, Derived >:
Collaboration diagram for vector_builder< T, Shape, Derived >:

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_heapto_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_builderoperator= (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_embedm_auto
 
unsigned char m_data [sizeof(T) *N]
 

Detailed Description

template<typename T, typename Shape, typename Derived>
class vector_builder< T, Shape, Derived >
A class for building vector constant patterns.
   Copyright (C) 2017-2024 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.   

Constructor & Destructor Documentation

◆ vector_builder() [1/2]

template<typename T , typename Shape , typename Derived >
vector_builder< T, Shape, Derived >::vector_builder ( )
inline

◆ vector_builder() [2/2]

template<typename T , typename Shape , typename Derived >
vector_builder< T, Shape, Derived >::vector_builder ( const vector_builder< T, Shape, Derived > & )
private

Member Function Documentation

◆ binary_encoded_nelts()

template<typename T , typename Shape , typename Derived >
unsigned int vector_builder< T, Shape, Derived >::binary_encoded_nelts ( T vec1,
T vec2 )
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, and MIN.

◆ count_dups()

template<typename T , typename Shape , typename Derived >
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 end(), gcc_assert, and i.

◆ derived() [1/2]

template<typename T , typename Shape , typename Derived >
Derived * vector_builder< T, Shape, Derived >::derived ( )
inlineprivate

◆ derived() [2/2]

template<typename T , typename Shape , typename Derived >
const Derived * vector_builder< T, Shape, Derived >::derived ( ) const
inlineprivate

◆ elt()

template<typename T , typename Shape , typename Derived >
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, gcc_checking_assert, and i.

Referenced by gimple_build_vector(), vec_perm_indices::new_vector(), vec_perm_indices::operator[](), and vec_perm_indices::series_p().

◆ encoded_full_vector_p()

template<typename T , typename Shape , typename Derived >
bool vector_builder< T, Shape, Derived >::encoded_full_vector_p ( ) const
inline
Return true if every element of the vector is explicitly encoded.   

References known_eq.

◆ encoded_nelts()

◆ finalize()

template<typename T , typename Shape , typename Derived >
void vector_builder< T, Shape, Derived >::finalize ( )
Replace the current encoding with the canonical form.   

References gcc_assert, i, and pow2p_hwi().

Referenced by vec_perm_indices::new_expanded_vector(), vec_perm_indices::new_shrunk_vector(), and vec_perm_indices::new_vector().

◆ full_nelts()

◆ nelts_per_pattern()

◆ new_binary_operation()

template<typename T , typename Shape , typename Derived >
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 gcc_assert, poly_int< N, C >::is_constant(), known_eq, least_common_multiple(), MAX, and poly_int< N, C >::to_constant().

Referenced by const_binop(), fold_relational_const(), and simplify_const_binary_operation().

◆ new_unary_operation()

template<typename T , typename Shape , typename Derived >
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 gcc_assert, poly_int< N, C >::is_constant(), known_eq, and poly_int< N, C >::to_constant().

Referenced by const_binop(), const_unop(), drop_tree_overflow(), exact_inverse(), expand_vector_divmod(), fold_const_vec_convert(), fold_convert_const(), fold_negate_expr_1(), and simplify_const_unary_operation().

◆ new_vector()

template<typename T , typename Shape , typename Derived >
void vector_builder< T, Shape, Derived >::new_vector ( poly_uint64 full_nelts,
unsigned int npatterns,
unsigned int nelts_per_pattern )
protected
Start building a vector that has FULL_NELTS elements.  Initially
encode it using NPATTERNS patterns with NELTS_PER_PATTERN each.   

Referenced by int_vector_builder< T >::int_vector_builder().

◆ npatterns()

◆ operator!=()

template<typename T , typename Shape , typename Derived >
bool vector_builder< T, Shape, Derived >::operator!= ( const Derived & x) const
inline

◆ operator=()

template<typename T , typename Shape , typename Derived >
vector_builder & vector_builder< T, Shape, Derived >::operator= ( const vector_builder< T, Shape, Derived > & )
private

◆ operator==()

template<typename T , typename Shape , typename Derived >
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 i.

Referenced by vector_builder< T, Shape, Derived >::operator!=().

◆ repeating_sequence_p()

template<typename T , typename Shape , typename Derived >
bool vector_builder< T, Shape, Derived >::repeating_sequence_p ( unsigned int start,
unsigned int end,
unsigned int step )
protected
Return true if elements [START, END) contain a repeating sequence of
STEP elements.   

References end(), and i.

◆ reshape()

template<typename T , typename Shape , typename Derived >
void vector_builder< T, Shape, Derived >::reshape ( unsigned int npatterns,
unsigned int nelts_per_pattern )
protected
Change the encoding to NPATTERNS patterns of NELTS_PER_PATTERN each,
but without changing the underlying vector.   

References gcc_checking_assert, and i.

◆ stepped_sequence_p()

template<typename T , typename Shape , typename Derived >
bool vector_builder< T, Shape, Derived >::stepped_sequence_p ( unsigned int start,
unsigned int end,
unsigned int step )
protected
Return true if elements [START, END) contain STEP interleaved linear
series.   

References end(), and i.

◆ to_vec_legacy()

vec< T, va_heap > auto_vec< T, N >::to_vec_legacy ( )
inlineinherited

◆ try_npatterns()

template<typename T , typename Shape , typename Derived >
bool vector_builder< T, Shape, Derived >::try_npatterns ( unsigned int npatterns)
protected
Try to change the number of encoded patterns to NPATTERNS, returning
true on success.   

References gcc_unreachable.

Field Documentation

◆ m_auto

vec<T, va_heap, vl_embed> auto_vec< T, N >::m_auto
privateinherited

◆ m_data

unsigned char auto_vec< T, N >::m_data[sizeof(T) *N]
privateinherited

◆ m_full_nelts

template<typename T , typename Shape , typename Derived >
poly_uint64 vector_builder< T, Shape, Derived >::m_full_nelts
private

◆ m_nelts_per_pattern

template<typename T , typename Shape , typename Derived >
unsigned int vector_builder< T, Shape, Derived >::m_nelts_per_pattern
private

◆ m_npatterns

template<typename T , typename Shape , typename Derived >
unsigned int vector_builder< T, Shape, Derived >::m_npatterns
private

The documentation for this class was generated from the following file: