diff options
author | Richard Sandiford <richard.sandiford@linaro.org> | 2017-09-14 15:46:08 +0000 |
---|---|---|
committer | Richard Sandiford <rsandifo@gcc.gnu.org> | 2017-09-14 15:46:08 +0000 |
commit | 794e31808f1554d51f0f0357c3a74a6365f0a274 (patch) | |
tree | d491aa520d3a8de4b35dbdde63439716c15b6f8d /gcc/tree.c | |
parent | 9e822269364f5268b2bdc82530fd6c871f47b1bc (diff) | |
download | gcc-794e31808f1554d51f0f0357c3a74a6365f0a274.zip gcc-794e31808f1554d51f0f0357c3a74a6365f0a274.tar.gz gcc-794e31808f1554d51f0f0357c3a74a6365f0a274.tar.bz2 |
Use vec<> in build_vector
This patch makes build_vector take the elements as a vec<> rather
than a tree *. This is useful for SVE because it bundles the number
of elements with the elements themselves, and enforces the fact that
the number is constant. Also, I think things like the folds can be used
with any generic GNU vector, not just those that match machine vectors,
so the arguments to XALLOCAVEC had no clear limit.
2017-09-14 Richard Sandiford <richard.sandiford@linaro.org>
Alan Hayward <alan.hayward@arm.com>
David Sherwood <david.sherwood@arm.com>
gcc/
* tree.h (build_vector): Take a vec<tree> instead of a tree *.
* tree.c (build_vector): Likewise.
(build_vector_from_ctor): Update accordingly.
(build_vector_from_val): Likewise.
* gimple-fold.c (gimple_fold_stmt_to_constant_1): Likewise.
* tree-ssa-forwprop.c (simplify_vector_constructor): Likewise.
* tree-vect-generic.c (add_rshift): Likewise.
(expand_vector_divmod): Likewise.
(optimize_vector_constructor): Likewise.
* tree-vect-slp.c (vect_get_constant_vectors): Likewise.
(vect_transform_slp_perm_load): Likewise.
(vect_schedule_slp_instance): Likewise.
* tree-vect-stmts.c (vectorizable_bswap): Likewise.
(vectorizable_call): Likewise.
(vect_gen_perm_mask_any): Likewise. Add elements in order.
* expmed.c (make_tree): Likewise.
* fold-const.c (fold_negate_expr_1): Use auto_vec<tree> when building
a vector passed to build_vector.
(fold_convert_const): Likewise.
(exact_inverse): Likewise.
(fold_ternary_loc): Likewise.
(fold_relational_const): Likewise.
(const_binop): Likewise. Use VECTOR_CST_ELT directly when operating
on VECTOR_CSTs, rather than going through vec_cst_ctor_to_array.
(const_unop): Likewise. Store the reduction accumulator in a
variable rather than an array.
(vec_cst_ctor_to_array): Take the number of elements as a parameter.
(fold_vec_perm): Update calls accordingly. Use auto_vec<tree> for
the new vector, rather than constructing it after the input arrays.
(native_interpret_vector): Use auto_vec<tree> when building
a vector passed to build_vector. Add elements in order.
* tree-vect-loop.c (get_initial_defs_for_reduction): Use
auto_vec<tree> when building a vector passed to build_vector.
(vect_create_epilog_for_reduction): Likewise.
(vectorizable_induction): Likewise.
(get_initial_def_for_reduction): Likewise. Fix indentation of
case statements.
* config/sparc/sparc.c (sparc_handle_vis_mul8x16): Change n_elts
to a vec<tree> *.
(sparc_fold_builtin): Use auto_vec<tree> when building a vector
passed to build_vector.
Co-Authored-By: Alan Hayward <alan.hayward@arm.com>
Co-Authored-By: David Sherwood <david.sherwood@arm.com>
From-SVN: r252760
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -1702,18 +1702,20 @@ make_vector (unsigned len MEM_STAT_DECL) } /* Return a new VECTOR_CST node whose type is TYPE and whose values - are in a list pointed to by VALS. */ + are given by VALS. */ tree -build_vector (tree type, tree *vals MEM_STAT_DECL) +build_vector (tree type, vec<tree> vals MEM_STAT_DECL) { + unsigned int nelts = vals.length (); + gcc_assert (nelts == TYPE_VECTOR_SUBPARTS (type)); int over = 0; unsigned cnt = 0; - tree v = make_vector (TYPE_VECTOR_SUBPARTS (type)); + tree v = make_vector (nelts); TREE_TYPE (v) = type; /* Iterate through elements and check for overflow. */ - for (cnt = 0; cnt < TYPE_VECTOR_SUBPARTS (type); ++cnt) + for (cnt = 0; cnt < nelts; ++cnt) { tree value = vals[cnt]; @@ -1736,20 +1738,21 @@ build_vector (tree type, tree *vals MEM_STAT_DECL) tree build_vector_from_ctor (tree type, vec<constructor_elt, va_gc> *v) { - tree *vec = XALLOCAVEC (tree, TYPE_VECTOR_SUBPARTS (type)); - unsigned HOST_WIDE_INT idx, pos = 0; + unsigned int nelts = TYPE_VECTOR_SUBPARTS (type); + unsigned HOST_WIDE_INT idx; tree value; + auto_vec<tree, 32> vec (nelts); FOR_EACH_CONSTRUCTOR_VALUE (v, idx, value) { if (TREE_CODE (value) == VECTOR_CST) for (unsigned i = 0; i < VECTOR_CST_NELTS (value); ++i) - vec[pos++] = VECTOR_CST_ELT (value, i); + vec.quick_push (VECTOR_CST_ELT (value, i)); else - vec[pos++] = value; + vec.quick_push (value); } - while (pos < TYPE_VECTOR_SUBPARTS (type)) - vec[pos++] = build_zero_cst (TREE_TYPE (type)); + while (vec.length () < nelts) + vec.quick_push (build_zero_cst (TREE_TYPE (type))); return build_vector (type, vec); } @@ -1774,9 +1777,9 @@ build_vector_from_val (tree vectype, tree sc) if (CONSTANT_CLASS_P (sc)) { - tree *v = XALLOCAVEC (tree, nunits); + auto_vec<tree, 32> v (nunits); for (i = 0; i < nunits; ++i) - v[i] = sc; + v.quick_push (sc); return build_vector (vectype, v); } else |