[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Make LTO's implementation of LANG_HOOKS_TYPE_FOR_SIZE the default



On January 19, 2017 5:37:09 PM GMT+01:00, David Malcolm <dmalcolm@redhat.com> wrote:
>On Thu, 2017-01-19 at 10:36 +0100, Richard Biener wrote:
>> On Wed, Jan 18, 2017 at 10:45 PM, David Malcolm <dmalcolm@redhat.com>
>> wrote:
>> > The jit testcase test-nested-loops.c was crashing.
>> > 
>> > Root cause is that deep inside loop optimization we're now exposing
>> > this call within fold-const.c which wasn't being hit before:
>> > 
>> > 4082      /* Compute the mask to access the bitfield.  */
>> > 4083      unsigned_type = lang_hooks.types.type_for_size
>> > (*pbitsize, 1);
>> > 
>> > and the jit's implementation of LANG_HOOKS_TYPE_FOR_SIZE was a
>> > placeholder that asserted it wasn't called.
>> > 
>> > This patch implements a proper LANG_HOOKS_TYPE_FOR_SIZE for jit,
>> > by taking LTO's implementation.
>> > 
>> > Fixes test-nested-loops.c, along with the related failures in
>> > test-combination.c and test-threads.c due to reusing the test.
>> > 
>> > This fixes all known failures in jit.sum, putting it at 8609
>> > passes.
>> > 
>> > Committed to trunk as r244600.
>> 
>> I suppose we could instead make the lto hook the default (thus move
>> it
>> to langhooks.c as lhd_type_for_size).  Note similar issues may arise
>> from type_for_mode?  Ah, I see you have that one...
>
>The following patch does that.
>
>Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.
>
>OK for trunk? 

OK.

Richard.

>gcc/jit/ChangeLog:
>	* dummy-frontend.c (jit_langhook_type_for_size): Delete.
>	(LANG_HOOKS_TYPE_FOR_SIZE): Don't redefine.
>
>gcc/ChangeLog:
>	* langhooks-def.h (lhd_type_for_size): New decl.
>	(LANG_HOOKS_TYPE_FOR_SIZE): Define as lhd_type_for_size.
>	* langhooks.c (lhd_type_for_size): New function, taken from
>	lto_type_for_size.
>
>gcc/lto/ChangeLog:
>	* lto-lang.c (builtin_type_for_size): Convert call to
>	lto_type_for_size to one through the langhook.
>	(lto_type_for_size): move to langhooks.c and rename to
>	lhd_type_for_size.
>	(LANG_HOOKS_TYPE_FOR_SIZE): Don't redefine.
>---
>gcc/jit/dummy-frontend.c | 52
>--------------------------------------------
> gcc/langhooks-def.h      |  2 ++
>gcc/langhooks.c          | 50
>++++++++++++++++++++++++++++++++++++++++++
>gcc/lto/lto-lang.c       | 56
>+-----------------------------------------------
> 4 files changed, 53 insertions(+), 107 deletions(-)
>
>diff --git a/gcc/jit/dummy-frontend.c b/gcc/jit/dummy-frontend.c
>index 4c7932b..87f583f 100644
>--- a/gcc/jit/dummy-frontend.c
>+++ b/gcc/jit/dummy-frontend.c
>@@ -207,55 +207,6 @@ jit_langhook_type_for_mode (enum machine_mode
>mode, int unsignedp)
>   return NULL;
> }
> 
>-/* Return an integer type with PRECISION bits of precision,
>-   that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
>-
>-static tree
>-jit_langhook_type_for_size (unsigned precision, int unsignedp)
>-{
>-  int i;
>-
>-  if (precision == TYPE_PRECISION (integer_type_node))
>-    return unsignedp ? unsigned_type_node : integer_type_node;
>-
>-  if (precision == TYPE_PRECISION (signed_char_type_node))
>-    return unsignedp ? unsigned_char_type_node :
>signed_char_type_node;
>-
>-  if (precision == TYPE_PRECISION (short_integer_type_node))
>-    return unsignedp ? short_unsigned_type_node :
>short_integer_type_node;
>-
>-  if (precision == TYPE_PRECISION (long_integer_type_node))
>-    return unsignedp ? long_unsigned_type_node :
>long_integer_type_node;
>-
>-  if (precision == TYPE_PRECISION (long_long_integer_type_node))
>-    return unsignedp
>-	   ? long_long_unsigned_type_node
>-	   : long_long_integer_type_node;
>-
>-  for (i = 0; i < NUM_INT_N_ENTS; i ++)
>-    if (int_n_enabled_p[i]
>-	&& precision == int_n_data[i].bitsize)
>-      return (unsignedp ? int_n_trees[i].unsigned_type
>-	      : int_n_trees[i].signed_type);
>-
>-  if (precision <= TYPE_PRECISION (intQI_type_node))
>-    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intHI_type_node))
>-    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intSI_type_node))
>-    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intDI_type_node))
>-    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intTI_type_node))
>-    return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
>-
>-  return NULL_TREE;
>-}
>-
> /* Record a builtin function.  We just ignore builtin functions.  */
> 
> static tree
>@@ -295,9 +246,6 @@ jit_langhook_getdecls (void)
> #undef LANG_HOOKS_TYPE_FOR_MODE
> #define LANG_HOOKS_TYPE_FOR_MODE	jit_langhook_type_for_mode
> 
>-#undef LANG_HOOKS_TYPE_FOR_SIZE
>-#define LANG_HOOKS_TYPE_FOR_SIZE	jit_langhook_type_for_size
>-
> #undef LANG_HOOKS_BUILTIN_FUNCTION
> #define LANG_HOOKS_BUILTIN_FUNCTION	jit_langhook_builtin_function
> 
>diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
>index db7587b..eb68084 100644
>--- a/gcc/langhooks-def.h
>+++ b/gcc/langhooks-def.h
>@@ -52,6 +52,7 @@ extern void lhd_print_error_function
>(diagnostic_context *,
> 				      const char *, struct diagnostic_info *);
> extern void lhd_set_decl_assembler_name (tree);
> extern bool lhd_warn_unused_global_decl (const_tree);
>+extern tree lhd_type_for_size (unsigned precision, int unsignedp);
>extern void lhd_incomplete_type_error (location_t, const_tree,
>const_tree);
> extern tree lhd_type_promotes_to (tree);
> extern void lhd_register_builtin_type (tree, const char *);
>@@ -165,6 +166,7 @@ extern tree lhd_unit_size_without_reusable_padding
>(tree);
> 
> #define LANG_HOOKS_MAKE_TYPE lhd_make_node
> #define LANG_HOOKS_CLASSIFY_RECORD	NULL
>+#define LANG_HOOKS_TYPE_FOR_SIZE	lhd_type_for_size
> #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error
> #define LANG_HOOKS_GENERIC_TYPE_P	hook_bool_const_tree_false
>#define LANG_HOOKS_GET_INNERMOST_GENERIC_PARMS
>hook_tree_const_tree_null
>diff --git a/gcc/langhooks.c b/gcc/langhooks.c
>index 4b4ebd7..dc19db7 100644
>--- a/gcc/langhooks.c
>+++ b/gcc/langhooks.c
>@@ -469,6 +469,56 @@ lhd_make_node (enum tree_code code)
>   return make_node (code);
> }
> 
>+/* Default implementation of LANG_HOOKS_TYPE_FOR_SIZE.
>+   Return an integer type with PRECISION bits of precision,
>+   that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
>+
>+tree
>+lhd_type_for_size (unsigned precision, int unsignedp)
>+{
>+  int i;
>+
>+  if (precision == TYPE_PRECISION (integer_type_node))
>+    return unsignedp ? unsigned_type_node : integer_type_node;
>+
>+  if (precision == TYPE_PRECISION (signed_char_type_node))
>+    return unsignedp ? unsigned_char_type_node :
>signed_char_type_node;
>+
>+  if (precision == TYPE_PRECISION (short_integer_type_node))
>+    return unsignedp ? short_unsigned_type_node :
>short_integer_type_node;
>+
>+  if (precision == TYPE_PRECISION (long_integer_type_node))
>+    return unsignedp ? long_unsigned_type_node :
>long_integer_type_node;
>+
>+  if (precision == TYPE_PRECISION (long_long_integer_type_node))
>+    return unsignedp
>+	   ? long_long_unsigned_type_node
>+	   : long_long_integer_type_node;
>+
>+  for (i = 0; i < NUM_INT_N_ENTS; i ++)
>+    if (int_n_enabled_p[i]
>+	&& precision == int_n_data[i].bitsize)
>+      return (unsignedp ? int_n_trees[i].unsigned_type
>+	      : int_n_trees[i].signed_type);
>+
>+  if (precision <= TYPE_PRECISION (intQI_type_node))
>+    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
>+
>+  if (precision <= TYPE_PRECISION (intHI_type_node))
>+    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
>+
>+  if (precision <= TYPE_PRECISION (intSI_type_node))
>+    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
>+
>+  if (precision <= TYPE_PRECISION (intDI_type_node))
>+    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
>+
>+  if (precision <= TYPE_PRECISION (intTI_type_node))
>+    return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
>+
>+  return NULL_TREE;
>+}
>+
> HOST_WIDE_INT
> lhd_to_target_charset (HOST_WIDE_INT c)
> {
>diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
>index fccb8c6..ca8945e 100644
>--- a/gcc/lto/lto-lang.c
>+++ b/gcc/lto/lto-lang.c
>@@ -36,8 +36,6 @@ along with GCC; see the file COPYING3.  If not see
> #include "lto.h"
> #include "cilk.h"
> 
>-static tree lto_type_for_size (unsigned, int);
>-
>static tree handle_noreturn_attribute (tree *, tree, tree, int, bool
>*);
> static tree handle_leaf_attribute (tree *, tree, tree, int, bool *);
> static tree handle_const_attribute (tree *, tree, tree, int, bool *);
>@@ -570,7 +568,7 @@ def_fn_type (builtin_type def, builtin_type ret,
>bool var, int n, ...)
> static tree
> builtin_type_for_size (int size, bool unsignedp)
> {
>-  tree type = lto_type_for_size (size, unsignedp);
>+  tree type = lang_hooks.types.type_for_size (size, unsignedp);
>   return type ? type : error_mark_node;
> }
> 
>@@ -867,56 +865,6 @@ lto_post_options (const char **pfilename
>ATTRIBUTE_UNUSED)
>   return false;
> }
> 
>-/* Return an integer type with PRECISION bits of precision,
>-   that is unsigned if UNSIGNEDP is nonzero, otherwise signed.  */
>-
>-static tree
>-lto_type_for_size (unsigned precision, int unsignedp)
>-{
>-  int i;
>-
>-  if (precision == TYPE_PRECISION (integer_type_node))
>-    return unsignedp ? unsigned_type_node : integer_type_node;
>-
>-  if (precision == TYPE_PRECISION (signed_char_type_node))
>-    return unsignedp ? unsigned_char_type_node :
>signed_char_type_node;
>-
>-  if (precision == TYPE_PRECISION (short_integer_type_node))
>-    return unsignedp ? short_unsigned_type_node :
>short_integer_type_node;
>-
>-  if (precision == TYPE_PRECISION (long_integer_type_node))
>-    return unsignedp ? long_unsigned_type_node :
>long_integer_type_node;
>-
>-  if (precision == TYPE_PRECISION (long_long_integer_type_node))
>-    return unsignedp
>-	   ? long_long_unsigned_type_node
>-	   : long_long_integer_type_node;
>-
>-  for (i = 0; i < NUM_INT_N_ENTS; i ++)
>-    if (int_n_enabled_p[i]
>-	&& precision == int_n_data[i].bitsize)
>-      return (unsignedp ? int_n_trees[i].unsigned_type
>-	      : int_n_trees[i].signed_type);
>-
>-  if (precision <= TYPE_PRECISION (intQI_type_node))
>-    return unsignedp ? unsigned_intQI_type_node : intQI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intHI_type_node))
>-    return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intSI_type_node))
>-    return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intDI_type_node))
>-    return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
>-
>-  if (precision <= TYPE_PRECISION (intTI_type_node))
>-    return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
>-
>-  return NULL_TREE;
>-}
>-
>-
> /* Return a data type that has machine mode MODE.
>    If the mode is an integer,
>    then UNSIGNEDP selects between signed and unsigned types.
>@@ -1364,8 +1312,6 @@ static void lto_init_ts (void)
> #define LANG_HOOKS_GET_ALIAS_SET gimple_get_alias_set
> #undef LANG_HOOKS_TYPE_FOR_MODE
> #define LANG_HOOKS_TYPE_FOR_MODE lto_type_for_mode
>-#undef LANG_HOOKS_TYPE_FOR_SIZE
>-#define LANG_HOOKS_TYPE_FOR_SIZE lto_type_for_size
> #undef LANG_HOOKS_SET_DECL_ASSEMBLER_NAME
> #define LANG_HOOKS_SET_DECL_ASSEMBLER_NAME lto_set_decl_assembler_name
> #undef LANG_HOOKS_GLOBAL_BINDINGS_P