xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/tree-vector-builder.c (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1cef8759bSmrg /* A class for building vector tree constants.
2*4c3eb207Smrg    Copyright (C) 2017-2020 Free Software Foundation, Inc.
3cef8759bSmrg 
4cef8759bSmrg This file is part of GCC.
5cef8759bSmrg 
6cef8759bSmrg GCC is free software; you can redistribute it and/or modify it under
7cef8759bSmrg the terms of the GNU General Public License as published by the Free
8cef8759bSmrg Software Foundation; either version 3, or (at your option) any later
9cef8759bSmrg version.
10cef8759bSmrg 
11cef8759bSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12cef8759bSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
13cef8759bSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14cef8759bSmrg for more details.
15cef8759bSmrg 
16cef8759bSmrg You should have received a copy of the GNU General Public License
17cef8759bSmrg along with GCC; see the file COPYING3.  If not see
18cef8759bSmrg <http://www.gnu.org/licenses/>.  */
19cef8759bSmrg 
20cef8759bSmrg #include "config.h"
21cef8759bSmrg #include "system.h"
22cef8759bSmrg #include "coretypes.h"
23cef8759bSmrg #include "tree.h"
24cef8759bSmrg #include "fold-const.h"
25cef8759bSmrg #include "tree-vector-builder.h"
26cef8759bSmrg 
27cef8759bSmrg /* Return a vector element with the value BASE + FACTOR * STEP.  */
28cef8759bSmrg 
29cef8759bSmrg tree
apply_step(tree base,unsigned int factor,const wide_int & step)30cef8759bSmrg tree_vector_builder::apply_step (tree base, unsigned int factor,
31cef8759bSmrg 				 const wide_int &step) const
32cef8759bSmrg {
33cef8759bSmrg   return wide_int_to_tree (TREE_TYPE (base),
34cef8759bSmrg 			   wi::to_wide (base) + factor * step);
35cef8759bSmrg }
36cef8759bSmrg 
37cef8759bSmrg /* Return a VECTOR_CST for the current constant.  */
38cef8759bSmrg 
39cef8759bSmrg tree
build()40cef8759bSmrg tree_vector_builder::build ()
41cef8759bSmrg {
42cef8759bSmrg   finalize ();
43cef8759bSmrg   gcc_assert (pow2p_hwi (npatterns ()));
44cef8759bSmrg   tree v = make_vector (exact_log2 (npatterns ()), nelts_per_pattern ());
45cef8759bSmrg   TREE_TYPE (v) = m_type;
46cef8759bSmrg   memcpy (VECTOR_CST_ENCODED_ELTS (v), address (),
47cef8759bSmrg 	  encoded_nelts () * sizeof (tree));
48cef8759bSmrg   return v;
49cef8759bSmrg }
50