aboutsummaryrefslogtreecommitdiff
path: root/gcc/rtx-vector-builder.h
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/rtx-vector-builder.h
parent8eff75e0d2a3495c5bc182324644a080d47205ac (diff)
downloadgcc-3877c560656f4961cc50952c3bba3c40812c36c3.zip
gcc-3877c560656f4961cc50952c3bba3c40812c36c3.tar.gz
gcc-3877c560656f4961cc50952c3bba3c40812c36c3.tar.bz2
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/rtx-vector-builder.h')
-rw-r--r--gcc/rtx-vector-builder.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/gcc/rtx-vector-builder.h b/gcc/rtx-vector-builder.h
new file mode 100644
index 0000000..d4dbdba
--- /dev/null
+++ b/gcc/rtx-vector-builder.h
@@ -0,0 +1,115 @@
+/* A class for building vector rtx constants.
+ Copyright (C) 2017 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_RTX_VECTOR_BUILDER_H
+#define GCC_RTX_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 rtx_vector_builder : public vector_builder<rtx, rtx_vector_builder>
+{
+ typedef vector_builder<rtx, rtx_vector_builder> parent;
+ friend class vector_builder<rtx, rtx_vector_builder>;
+
+public:
+ rtx_vector_builder () : m_mode (VOIDmode) {}
+ rtx_vector_builder (machine_mode, unsigned int, unsigned int);
+ rtx build (rtvec);
+ rtx build ();
+
+ machine_mode mode () const { return m_mode; }
+
+ void new_vector (machine_mode, unsigned int, unsigned int);
+
+private:
+ bool equal_p (rtx, rtx) const;
+ bool allow_steps_p () const;
+ bool integral_p (rtx) const;
+ wide_int step (rtx, rtx) const;
+ rtx apply_step (rtx, unsigned int, const wide_int &) const;
+ bool can_elide_p (rtx) const { return true; }
+ void note_representative (rtx *, rtx) {}
+
+ rtx find_cached_value ();
+
+ machine_mode m_mode;
+};
+
+/* Create a new builder for a vector of mode MODE. Initially encode the
+ value as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements
+ each. */
+
+inline
+rtx_vector_builder::rtx_vector_builder (machine_mode mode,
+ unsigned int npatterns,
+ unsigned int nelts_per_pattern)
+{
+ new_vector (mode, npatterns, nelts_per_pattern);
+}
+
+/* Start building a new vector of mode MODE. Initially encode the value
+ as NPATTERNS interleaved patterns with NELTS_PER_PATTERN elements each. */
+
+inline void
+rtx_vector_builder::new_vector (machine_mode mode, unsigned int npatterns,
+ unsigned int nelts_per_pattern)
+{
+ m_mode = mode;
+ parent::new_vector (GET_MODE_NUNITS (mode), npatterns, nelts_per_pattern);
+}
+
+/* Return true if elements ELT1 and ELT2 are equal. */
+
+inline bool
+rtx_vector_builder::equal_p (rtx elt1, rtx elt2) const
+{
+ return rtx_equal_p (elt1, elt2);
+}
+
+/* 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
+rtx_vector_builder::allow_steps_p () const
+{
+ return is_a <scalar_int_mode> (GET_MODE_INNER (m_mode));
+}
+
+/* Return true if element ELT can be interpreted as an integer. */
+
+inline bool
+rtx_vector_builder::integral_p (rtx elt) const
+{
+ return CONST_SCALAR_INT_P (elt);
+}
+
+/* Return the value of element ELT2 minus the value of element ELT1.
+ Both elements are known to be CONST_SCALAR_INT_Ps. */
+
+inline wide_int
+rtx_vector_builder::step (rtx elt1, rtx elt2) const
+{
+ return wi::sub (rtx_mode_t (elt2, GET_MODE_INNER (m_mode)),
+ rtx_mode_t (elt1, GET_MODE_INNER (m_mode)));
+}
+
+#endif