[7/9] Make targetm.get_mask_mode return an opt_mode
Richard Biener
richard.guenther@gmail.com
Tue Sep 5 11:37:00 GMT 2017
On Mon, Sep 4, 2017 at 1:41 PM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> ...for consistency with mode_for_vector.
Ok.
Richard.
> 2017-09-04 Richard Sandiford <richard.sandiford@linaro.org>
>
> gcc/
> * target.def (get_mask_mode): Change return type to opt_mode.
> Expand commentary.
> * doc/tm.texi: Regenerate.
> * targhooks.h (default_get_mask_mode): Return an opt_mode.
> * targhooks.c (default_get_mask_mode): Likewise.
> * config/i386/i386.c (ix86_get_mask_mode): Likewise.
> * optabs-query.c (can_vec_mask_load_store_p): Update use of
> targetm.get_mask_mode.
> * tree.c (build_truth_vector_type): Likewise.
>
> Index: gcc/target.def
> ===================================================================
> --- gcc/target.def 2017-09-04 11:50:24.568774867 +0100
> +++ gcc/target.def 2017-09-04 12:18:58.594757220 +0100
> @@ -1877,10 +1877,16 @@ The default is zero which means to not i
> /* Function to get a target mode for a vector mask. */
> DEFHOOK
> (get_mask_mode,
> - "This hook returns mode to be used for a mask to be used for a vector\n\
> -of specified @var{length} with @var{nunits} elements. By default an integer\n\
> -vector mode of a proper size is returned.",
> - machine_mode,
> + "A vector mask is a value that holds one boolean result for every element\n\
> +in a vector. This hook returns the machine mode that should be used to\n\
> +represent such a mask when the vector in question is @var{length} bytes\n\
> +long and contains @var{nunits} elements. The hook returns an empty\n\
> +@code{opt_machine_mode} if no such mode exists.\n\
> +\n\
> +The default implementation returns the mode of an integer vector that\n\
> +is @var{length} bytes long and that contains @var{nunits} elements,\n\
> +if such a mode exists.",
> + opt_machine_mode,
> (unsigned nunits, unsigned length),
> default_get_mask_mode)
>
> Index: gcc/doc/tm.texi
> ===================================================================
> --- gcc/doc/tm.texi 2017-09-04 11:50:24.566073698 +0100
> +++ gcc/doc/tm.texi 2017-09-04 12:18:58.593753447 +0100
> @@ -5820,10 +5820,16 @@ mode returned by @code{TARGET_VECTORIZE_
> The default is zero which means to not iterate over other vector sizes.
> @end deftypefn
>
> -@deftypefn {Target Hook} machine_mode TARGET_VECTORIZE_GET_MASK_MODE (unsigned @var{nunits}, unsigned @var{length})
> -This hook returns mode to be used for a mask to be used for a vector
> -of specified @var{length} with @var{nunits} elements. By default an integer
> -vector mode of a proper size is returned.
> +@deftypefn {Target Hook} opt_machine_mode TARGET_VECTORIZE_GET_MASK_MODE (unsigned @var{nunits}, unsigned @var{length})
> +A vector mask is a value that holds one boolean result for every element
> +in a vector. This hook returns the machine mode that should be used to
> +represent such a mask when the vector in question is @var{length} bytes
> +long and contains @var{nunits} elements. The hook returns an empty
> +@code{opt_machine_mode} if no such mode exists.
> +
> +The default implementation returns the mode of an integer vector that
> +is @var{length} bytes long and that contains @var{nunits} elements,
> +if such a mode exists.
> @end deftypefn
>
> @deftypefn {Target Hook} {void *} TARGET_VECTORIZE_INIT_COST (struct loop *@var{loop_info})
> Index: gcc/targhooks.h
> ===================================================================
> --- gcc/targhooks.h 2017-09-04 11:50:24.568774867 +0100
> +++ gcc/targhooks.h 2017-09-04 12:18:58.594757220 +0100
> @@ -102,7 +102,7 @@ default_builtin_support_vector_misalignm
> int, bool);
> extern machine_mode default_preferred_simd_mode (scalar_mode mode);
> extern unsigned int default_autovectorize_vector_sizes (void);
> -extern machine_mode default_get_mask_mode (unsigned, unsigned);
> +extern opt_machine_mode default_get_mask_mode (unsigned, unsigned);
> extern void *default_init_cost (struct loop *);
> extern unsigned default_add_stmt_cost (void *, int, enum vect_cost_for_stmt,
> struct _stmt_vec_info *, int,
> Index: gcc/targhooks.c
> ===================================================================
> --- gcc/targhooks.c 2017-09-04 12:18:55.825348732 +0100
> +++ gcc/targhooks.c 2017-09-04 12:18:58.594757220 +0100
> @@ -1200,7 +1200,7 @@ default_autovectorize_vector_sizes (void
>
> /* By defaults a vector of integers is used as a mask. */
>
> -machine_mode
> +opt_machine_mode
> default_get_mask_mode (unsigned nunits, unsigned vector_size)
> {
> unsigned elem_size = vector_size / nunits;
> @@ -1210,12 +1210,12 @@ default_get_mask_mode (unsigned nunits,
>
> gcc_assert (elem_size * nunits == vector_size);
>
> - if (!mode_for_vector (elem_mode, nunits).exists (&vector_mode)
> - || !VECTOR_MODE_P (vector_mode)
> - || !targetm.vector_mode_supported_p (vector_mode))
> - vector_mode = BLKmode;
> + if (mode_for_vector (elem_mode, nunits).exists (&vector_mode)
> + && VECTOR_MODE_P (vector_mode)
> + && targetm.vector_mode_supported_p (vector_mode))
> + return vector_mode;
>
> - return vector_mode;
> + return opt_machine_mode ();
> }
>
> /* By default, the cost model accumulates three separate costs (prologue,
> Index: gcc/config/i386/i386.c
> ===================================================================
> --- gcc/config/i386/i386.c 2017-09-04 12:18:55.808284598 +0100
> +++ gcc/config/i386/i386.c 2017-09-04 12:18:58.592749675 +0100
> @@ -51598,7 +51598,7 @@ ix86_autovectorize_vector_sizes (void)
>
> /* Implemenation of targetm.vectorize.get_mask_mode. */
>
> -static machine_mode
> +static opt_machine_mode
> ix86_get_mask_mode (unsigned nunits, unsigned vector_size)
> {
> unsigned elem_size = vector_size / nunits;
> @@ -51616,7 +51616,7 @@ ix86_get_mask_mode (unsigned nunits, uns
>
> gcc_assert (elem_size * nunits == vector_size);
>
> - return mode_for_vector (elem_mode, nunits).else_blk ();
> + return mode_for_vector (elem_mode, nunits);
> }
>
>
> Index: gcc/optabs-query.c
> ===================================================================
> --- gcc/optabs-query.c 2017-09-04 12:18:55.821333642 +0100
> +++ gcc/optabs-query.c 2017-09-04 12:18:58.593753447 +0100
> @@ -531,12 +531,9 @@ can_vec_mask_load_store_p (machine_mode
> if (!VECTOR_MODE_P (vmode))
> return false;
>
> - mask_mode = targetm.vectorize.get_mask_mode (GET_MODE_NUNITS (vmode),
> - GET_MODE_SIZE (vmode));
> - if (mask_mode == VOIDmode)
> - return false;
> -
> - if (convert_optab_handler (op, vmode, mask_mode) != CODE_FOR_nothing)
> + if ((targetm.vectorize.get_mask_mode
> + (GET_MODE_NUNITS (vmode), GET_MODE_SIZE (vmode)).exists (&mask_mode))
> + && convert_optab_handler (op, vmode, mask_mode) != CODE_FOR_nothing)
> return true;
>
> vector_sizes = targetm.vectorize.autovectorize_vector_sizes ();
> @@ -548,12 +545,10 @@ can_vec_mask_load_store_p (machine_mode
> continue;
> unsigned int nunits = cur / GET_MODE_SIZE (smode);
> if (mode_for_vector (smode, nunits).exists (&vmode)
> - && VECTOR_MODE_P (vmode))
> - {
> - mask_mode = targetm.vectorize.get_mask_mode (nunits, cur);
> - if (convert_optab_handler (op, vmode, mask_mode) != CODE_FOR_nothing)
> - return true;
> - }
> + && VECTOR_MODE_P (vmode)
> + && targetm.vectorize.get_mask_mode (nunits, cur).exists (&mask_mode)
> + && convert_optab_handler (op, vmode, mask_mode) != CODE_FOR_nothing)
> + return true;
> }
> return false;
> }
> Index: gcc/tree.c
> ===================================================================
> --- gcc/tree.c 2017-08-30 12:19:19.721220029 +0100
> +++ gcc/tree.c 2017-09-04 12:18:58.595760992 +0100
> @@ -10243,10 +10243,8 @@ build_vector_type (tree innertype, int n
> tree
> build_truth_vector_type (unsigned nunits, unsigned vector_size)
> {
> - machine_mode mask_mode = targetm.vectorize.get_mask_mode (nunits,
> - vector_size);
> -
> - gcc_assert (mask_mode != VOIDmode);
> + machine_mode mask_mode
> + = targetm.vectorize.get_mask_mode (nunits, vector_size).else_blk ();
>
> unsigned HOST_WIDE_INT vsize;
> if (mask_mode == BLKmode)
More information about the Gcc-patches
mailing list