aboutsummaryrefslogtreecommitdiff
path: root/gcc/rtx-vector-builder.c
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.c
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.c')
-rw-r--r--gcc/rtx-vector-builder.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/gcc/rtx-vector-builder.c b/gcc/rtx-vector-builder.c
new file mode 100644
index 0000000..6c39a3d
--- /dev/null
+++ b/gcc/rtx-vector-builder.c
@@ -0,0 +1,100 @@
+/* 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/>. */
+
+#include "config.h"
+#include "system.h"
+#include "coretypes.h"
+#include "tm.h"
+#include "rtl.h"
+#include "rtx-vector-builder.h"
+
+/* Return a CONST_VECTOR for the current constant. V is an existing
+ rtvec that contains all the elements. */
+
+rtx
+rtx_vector_builder::build (rtvec v)
+{
+ finalize ();
+
+ rtx x = find_cached_value ();
+ if (x)
+ return x;
+
+ x = gen_rtx_raw_CONST_VECTOR (m_mode, v);
+ CONST_VECTOR_NPATTERNS (x) = npatterns ();
+ CONST_VECTOR_NELTS_PER_PATTERN (x) = nelts_per_pattern ();
+ return x;
+}
+
+/* Return a vector element with the value BASE + FACTOR * STEP. */
+
+rtx
+rtx_vector_builder::apply_step (rtx base, unsigned int factor,
+ const wide_int &step) const
+{
+ scalar_int_mode int_mode = as_a <scalar_int_mode> (GET_MODE_INNER (m_mode));
+ return immed_wide_int_const (wi::add (rtx_mode_t (base, int_mode),
+ factor * step),
+ int_mode);
+}
+
+/* Return a CONST_VECTOR for the current constant. */
+
+rtx
+rtx_vector_builder::build ()
+{
+ finalize ();
+
+ rtx x = find_cached_value ();
+ if (x)
+ return x;
+
+ unsigned int nelts = GET_MODE_NUNITS (m_mode);
+ rtvec v = rtvec_alloc (nelts);
+ for (unsigned int i = 0; i < nelts; ++i)
+ RTVEC_ELT (v, i) = elt (i);
+ x = gen_rtx_raw_CONST_VECTOR (m_mode, v);
+ CONST_VECTOR_NPATTERNS (x) = npatterns ();
+ CONST_VECTOR_NELTS_PER_PATTERN (x) = nelts_per_pattern ();
+ return x;
+}
+
+/* Check whether there is a global cached value for the vector.
+ Return it if so, otherwise return null. */
+
+rtx
+rtx_vector_builder::find_cached_value ()
+{
+ if (encoded_nelts () != 1)
+ return NULL_RTX;
+
+ rtx elt = (*this)[0];
+
+ /* We can be called before the global vector constants are set up,
+ but in that case we'll just return null. */
+ scalar_mode inner_mode = GET_MODE_INNER (m_mode);
+ if (elt == CONST0_RTX (inner_mode))
+ return CONST0_RTX (m_mode);
+ else if (elt == CONST1_RTX (inner_mode))
+ return CONST1_RTX (m_mode);
+ else if (elt == CONSTM1_RTX (inner_mode))
+ return CONSTM1_RTX (m_mode);
+
+ return NULL_RTX;
+}