New VECTOR_CST layout
[official-gcc.git] / gcc / tree-vector-builder.c
blob708bf0e1a059aec7dd27df24497026666db5bd15
1 /* A class for building vector tree constants.
2 Copyright (C) 2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tree.h"
24 #include "fold-const.h"
25 #include "tree-vector-builder.h"
27 /* Try to start building a new vector of type TYPE that holds the result of
28 a unary operation on VECTOR_CST T. ALLOW_STEPPED_P is true if the
29 operation can handle stepped encodings directly, without having to
30 expand the full sequence.
32 Return true if the operation is possible, which it always is when
33 ALLOW_STEPPED_P is true. Leave the builder unchanged otherwise. */
35 bool
36 tree_vector_builder::new_unary_operation (tree type, tree t,
37 bool allow_stepped_p)
39 unsigned int full_nelts = TYPE_VECTOR_SUBPARTS (type);
40 gcc_assert (full_nelts == TYPE_VECTOR_SUBPARTS (TREE_TYPE (t)));
41 unsigned int npatterns = VECTOR_CST_NPATTERNS (t);
42 unsigned int nelts_per_pattern = VECTOR_CST_NELTS_PER_PATTERN (t);
43 if (!allow_stepped_p && nelts_per_pattern > 2)
45 npatterns = full_nelts;
46 nelts_per_pattern = 1;
48 new_vector (type, npatterns, nelts_per_pattern);
49 return true;
52 /* Return a VECTOR_CST for the current constant. */
54 tree
55 tree_vector_builder::build ()
57 finalize ();
58 gcc_assert (pow2p_hwi (npatterns ()));
59 tree v = make_vector (exact_log2 (npatterns ()), nelts_per_pattern ());
60 TREE_TYPE (v) = m_type;
61 memcpy (VECTOR_CST_ENCODED_ELTS (v), address (),
62 encoded_nelts () * sizeof (tree));
63 return v;