From: Richard Sandiford Date: Tue, 5 Sep 2017 19:57:47 +0000 (+0000) Subject: Make targetm.get_mask_mode return an opt_mode X-Git-Tag: upstream/12.2.0~37250 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3981fbb65a43dff3a81ebc32c94d6f86bb4f9783;p=platform%2Fupstream%2Fgcc.git Make targetm.get_mask_mode return an opt_mode ...for consistency with mode_for_vector. 2017-09-05 Richard Sandiford 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. From-SVN: r251731 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 067040b..f521a27 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,17 @@ 2017-09-05 Richard Sandiford + * 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. + +2017-09-05 Richard Sandiford + * machmode.h (mode_for_vector): Return an opt_mode. * stor-layout.c (mode_for_vector): Likewise. (mode_for_int_vector): Update accordingly. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 8c17da2..4e93cc1 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -51714,7 +51714,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; @@ -51732,7 +51732,7 @@ ix86_get_mask_mode (unsigned nunits, unsigned vector_size) gcc_assert (elem_size * nunits == vector_size); - return mode_for_vector (elem_mode, nunits).else_blk (); + return mode_for_vector (elem_mode, nunits); } diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 2e22047..c29d249 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -5820,10 +5820,16 @@ mode returned by @code{TARGET_VECTORIZE_PREFERRED_SIMD_MODE}. 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}) diff --git a/gcc/optabs-query.c b/gcc/optabs-query.c index 9afdd1f..81b1bd9 100644 --- a/gcc/optabs-query.c +++ b/gcc/optabs-query.c @@ -531,12 +531,9 @@ can_vec_mask_load_store_p (machine_mode 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 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; } diff --git a/gcc/target.def b/gcc/target.def index a941757..110300c 100644 --- a/gcc/target.def +++ b/gcc/target.def @@ -1877,10 +1877,16 @@ The default is zero which means to not iterate over other vector sizes.", /* 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) diff --git a/gcc/targhooks.c b/gcc/targhooks.c index 078647c..cbc15ab 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -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, unsigned vector_size) 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, diff --git a/gcc/targhooks.h b/gcc/targhooks.h index a7fb83a2..5178086 100644 --- a/gcc/targhooks.h +++ b/gcc/targhooks.h @@ -102,7 +102,7 @@ default_builtin_support_vector_misalignment (machine_mode mode, 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, diff --git a/gcc/tree.c b/gcc/tree.c index 0420808..7a70eb7 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -10243,10 +10243,8 @@ build_vector_type (tree innertype, int nunits) 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)