aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc/rtl.texi
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@linaro.org>2018-01-02 18:27:50 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2018-01-02 18:27:50 +0000
commit3877c560656f4961cc50952c3bba3c40812c36c3 (patch)
tree6a597b75586e86b045125cf698b9b23ec15e2d4a /gcc/doc/rtl.texi
parent8eff75e0d2a3495c5bc182324644a080d47205ac (diff)
New CONST_VECTOR layout
This patch makes CONST_VECTOR use the same encoding as VECTOR_CST. One problem that occurs in RTL but not at the tree level is that a fair amount of code uses XVEC and XVECEXP directly on CONST_VECTORs (which is valid, just with looser checking). This is complicated by the fact that vectors are also represented as PARALLELs in some target interfaces, so using XVECEXP is a good polymorphic way of handling both forms. Rather than try to untangle all that, the best approach seemed to be to continue to encode every element in a fixed-length vector. That way only target-independent and AArch64 code need to be precise about using CONST_VECTOR_ELT over XVECEXP. After this change is no longer valid to modify CONST_VECTORs in-place. This needed some fix-up in the powerpc backends. 2018-01-02 Richard Sandiford <richard.sandiford@linaro.org> gcc/ * doc/rtl.texi (const_vector): Describe new encoding scheme. * Makefile.in (OBJS): Add rtx-vector-builder.o. * rtx-vector-builder.h: New file. * rtx-vector-builder.c: Likewise. * rtl.h (rtx_def::u2): Add a const_vector field. (CONST_VECTOR_NPATTERNS): New macro. (CONST_VECTOR_NELTS_PER_PATTERN): Likewise. (CONST_VECTOR_DUPLICATE_P): Likewise. (CONST_VECTOR_STEPPED_P): Likewise. (CONST_VECTOR_ENCODED_ELT): Likewise. (const_vec_duplicate_p): Check for a duplicated vector encoding. (unwrap_const_vec_duplicate): Likewise. (const_vec_series_p): Check for a non-duplicated vector encoding. Say that the function only returns true for integer vectors. * emit-rtl.c: Include rtx-vector-builder.h. (gen_const_vec_duplicate_1): Delete. (gen_const_vector): Call gen_const_vec_duplicate instead of gen_const_vec_duplicate_1. (const_vec_series_p_1): Operate directly on the CONST_VECTOR encoding. (gen_const_vec_duplicate): Use rtx_vector_builder. (gen_const_vec_series): Likewise. (gen_rtx_CONST_VECTOR): Likewise. * config/powerpcspe/powerpcspe.c: Include rtx-vector-builder.h. (swap_const_vector_halves): Take an rtx pointer rather than rtx. Build a new vector rather than modifying a CONST_VECTOR in-place. (handle_special_swappables): Update call accordingly. * config/rs6000/rs6000-p8swap.c: Include rtx-vector-builder.h. (swap_const_vector_halves): Take an rtx pointer rather than rtx. Build a new vector rather than modifying a CONST_VECTOR in-place. (handle_special_swappables): Update call accordingly. From-SVN: r256102
Diffstat (limited to 'gcc/doc/rtl.texi')
-rw-r--r--gcc/doc/rtl.texi98
1 files changed, 86 insertions, 12 deletions
diff --git a/gcc/doc/rtl.texi b/gcc/doc/rtl.texi
index badaae707e4..18935b0407c 100644
--- a/gcc/doc/rtl.texi
+++ b/gcc/doc/rtl.texi
@@ -1644,18 +1644,92 @@ low-level routines) and @code{const_poly_int_value} gives the full
@findex const_vector
@item (const_vector:@var{m} [@var{x0} @var{x1} @dots{}])
-Represents a vector constant. The square brackets stand for the vector
-containing the constant elements. @var{x0}, @var{x1} and so on are
-the @code{const_int}, @code{const_wide_int}, @code{const_double} or
-@code{const_fixed} elements.
-
-The number of units in a @code{const_vector} is obtained with the macro
-@code{CONST_VECTOR_NUNITS} as in @code{CONST_VECTOR_NUNITS (@var{v})}.
-
-Individual elements in a vector constant are accessed with the macro
-@code{CONST_VECTOR_ELT} as in @code{CONST_VECTOR_ELT (@var{v}, @var{n})}
-where @var{v} is the vector constant and @var{n} is the element
-desired.
+Represents a vector constant. The values in square brackets are
+elements of the vector, which are always @code{const_int},
+@code{const_wide_int}, @code{const_double} or @code{const_fixed}
+expressions.
+
+Each vector constant @var{v} is treated as a specific instance of an
+arbitrary-length sequence that itself contains
+@samp{CONST_VECTOR_NPATTERNS (@var{v})} interleaved patterns. Each
+pattern has the form:
+
+@smallexample
+@{ @var{base0}, @var{base1}, @var{base1} + @var{step}, @var{base1} + @var{step} * 2, @dots{} @}
+@end smallexample
+
+The first three elements in each pattern are enough to determine the
+values of the other elements. However, if all @var{step}s are zero,
+only the first two elements are needed. If in addition each @var{base1}
+is equal to the corresponding @var{base0}, only the first element in
+each pattern is needed. The number of determining elements per pattern
+is given by @samp{CONST_VECTOR_NELTS_PER_PATTERN (@var{v})}.
+
+For example, the constant:
+
+@smallexample
+@{ 0, 1, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8, 18 @}
+@end smallexample
+
+is interpreted as an interleaving of the sequences:
+
+@smallexample
+@{ 0, 2, 3, 4, 5, 6, 7, 8 @}
+@{ 1, 6, 8, 10, 12, 14, 16, 18 @}
+@end smallexample
+
+where the sequences are represented by the following patterns:
+
+@smallexample
+@var{base0} == 0, @var{base1} == 2, @var{step} == 1
+@var{base0} == 1, @var{base1} == 6, @var{step} == 2
+@end smallexample
+
+In this case:
+
+@smallexample
+CONST_VECTOR_NPATTERNS (@var{v}) == 2
+CONST_VECTOR_NELTS_PER_PATTERN (@var{v}) == 3
+@end smallexample
+
+Thus the first 6 elements (@samp{@{ 0, 1, 2, 6, 3, 8 @}}) are enough
+to determine the whole sequence; we refer to them as the ``encoded''
+elements. They are the only elements present in the square brackets
+for variable-length @code{const_vector}s (i.e. for
+@code{const_vector}s whose mode @var{m} has a variable number of
+elements). However, as a convenience to code that needs to handle
+both @code{const_vector}s and @code{parallel}s, all elements are
+present in the square brackets for fixed-length @code{const_vector}s;
+the encoding scheme simply reduces the amount of work involved in
+processing constants that follow a regular pattern.
+
+Sometimes this scheme can create two possible encodings of the same
+vector. For example @{ 0, 1 @} could be seen as two patterns with
+one element each or one pattern with two elements (@var{base0} and
+@var{base1}). The canonical encoding is always the one with the
+fewest patterns or (if both encodings have the same number of
+petterns) the one with the fewest encoded elements.
+
+@samp{const_vector_encoding_nelts (@var{v})} gives the total number of
+encoded elements in @var{v}, which is 6 in the example above.
+@code{CONST_VECTOR_ENCODED_ELT (@var{v}, @var{i})} accesses the value
+of encoded element @var{i}.
+
+@samp{CONST_VECTOR_DUPLICATE_P (@var{v})} is true if @var{v} simply contains
+repeated instances of @samp{CONST_VECTOR_NPATTERNS (@var{v})} values. This is
+a shorthand for testing @samp{CONST_VECTOR_NELTS_PER_PATTERN (@var{v}) == 1}.
+
+@samp{CONST_VECTOR_STEPPED_P (@var{v})} is true if at least one
+pattern in @var{v} has a nonzero step. This is a shorthand for
+testing @samp{CONST_VECTOR_NELTS_PER_PATTERN (@var{v}) == 3}.
+
+@code{CONST_VECTOR_NUNITS (@var{v})} gives the total number of elements
+in @var{v}; it is a shorthand for getting the number of units in
+@samp{GET_MODE (@var{v})}.
+
+The utility function @code{const_vector_elt} gives the value of an
+arbitrary element as an @code{rtx}. @code{const_vector_int_elt} gives
+the same value as a @code{wide_int}.
@findex const_string
@item (const_string @var{str})