This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH][LTO] Fix PR41638, wrong streaming of MD builtins


This should fix the PPC vmx ICEs in the testsuite and generally fix
streaming of target builtin decls.  I added a target hook to query
the backends for builtins in a way that also allows for on-demand
initialization (for example to support mixed -mX flags in TUs that
enable/disable certain builtins).  I need the special -1 return
to allow iterating over all MD builtins for type fixup purposes.

Bootstrap and regtest running on x86_64-unknown-linux-gnu, I have
built a cross-ppc cc1 as well.

Ok if it passes?  It might seem only fixing i386 and rs6000 might
cause some other targets to regress, but we only go from wrong
streaming to an error.  I tried to fixup arm, but that doesn't
even have an array of builtin decls available.  I guess leaving
this to the target maintainers is most reasonable.

Thanks,
Richard.

2009-10-09  Richard Guenther  <rguenther@suse.de>

	PR lto/41638
	* target-def.h (TARGET_BUILTIN_DECL): Define.
	(TARGET_INITIALIZER): Add TARGET_BUILTIN_DECL.
	* target.h (struct gcc_target): Add builtin_decl target hook.
	* doc/tm.texi (TARGET_BUILTIN_DECL): Document.

	* lto-streamer-in.c (lto_get_builtin_tree): Fix handling of
	target builtins.
	* lto-streamer-out.c (lto_output_tree_pointers): Use sorry,
	not gcc_unreachable.
	(lto_output_builtin_tree): Sorry if the target does not support
	streaming target builtins.

	* config/rs6000/rs6000.c (TARGET_BUILTIN_DECL): Define.
	(rs6000_builtin_decl): New function.
	* config/i386/i386.c (TARGET_BUILTIN_DECL): Define.
	(ix86_builtin_decl): New function.

Index: trunk/gcc/config/rs6000/rs6000.c
===================================================================
*** trunk.orig/gcc/config/rs6000/rs6000.c	2009-10-09 15:20:12.000000000 +0200
--- trunk/gcc/config/rs6000/rs6000.c	2009-10-09 15:45:40.000000000 +0200
*************** static const struct attribute_spec rs600
*** 1332,1337 ****
--- 1332,1339 ----
  
  #undef TARGET_INIT_BUILTINS
  #define TARGET_INIT_BUILTINS rs6000_init_builtins
+ #undef TARGET_BUILTIN_DECL
+ #define TARGET_BUILTIN_DECL rs6000_builtin_decl
  
  #undef TARGET_EXPAND_BUILTIN
  #define TARGET_EXPAND_BUILTIN rs6000_expand_builtin
*************** rs6000_init_builtins (void)
*** 11144,11149 ****
--- 11146,11162 ----
  #endif
  }
  
+ /* Returns the rs6000 builtin decl for CODE.  */
+ 
+ static tree
+ rs6000_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED)
+ {
+   if (code >= RS6000_BUILTIN_COUNT)
+     return (tree) (void *)-1;
+ 
+   return rs6000_builtin_decls[code];
+ }
+ 
  /* Search through a set of builtins and enable the mask bits.
     DESC is an array of builtins.
     SIZE is the total number of builtins.
Index: trunk/gcc/lto-streamer-in.c
===================================================================
*** trunk.orig/gcc/lto-streamer-in.c	2009-10-09 15:20:12.000000000 +0200
--- trunk/gcc/lto-streamer-in.c	2009-10-09 15:45:54.000000000 +0200
*************** lto_get_builtin_tree (struct lto_input_b
*** 2377,2389 ****
    gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
  
    fcode = (enum built_in_function) lto_input_uleb128 (ib);
-   gcc_assert (fcode < END_BUILTINS);
  
    ix = lto_input_sleb128 (ib);
    gcc_assert (ix == (int) ix);
  
!   result = built_in_decls[fcode];
!   gcc_assert (result);
  
    asmname = input_string (data_in, ib);
    if (asmname)
--- 2377,2398 ----
    gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
  
    fcode = (enum built_in_function) lto_input_uleb128 (ib);
  
    ix = lto_input_sleb128 (ib);
    gcc_assert (ix == (int) ix);
  
!   if (fclass == BUILT_IN_NORMAL)
!     {
!       gcc_assert (fcode < END_BUILTINS);
!       result = built_in_decls[fcode];
!       gcc_assert (result);
!     }
!   else if (fclass == BUILT_IN_MD)
!     {
!       result = targetm.builtin_decl (fcode, true);
!       if (!result || result == (tree) (void *)-1)
! 	fatal_error ("target specific builtin not available");
!     }
  
    asmname = input_string (data_in, ib);
    if (asmname)
Index: trunk/gcc/target-def.h
===================================================================
*** trunk.orig/gcc/target-def.h	2009-10-09 15:20:12.000000000 +0200
--- trunk/gcc/target-def.h	2009-10-09 15:26:09.000000000 +0200
***************
*** 437,442 ****
--- 437,443 ----
  #define TARGET_EXPAND_BUILTIN default_expand_builtin
  #define TARGET_RESOLVE_OVERLOADED_BUILTIN NULL
  #define TARGET_FOLD_BUILTIN hook_tree_tree_tree_bool_null
+ #define TARGET_BUILTIN_DECL NULL
  
  /* In tree-ssa-math-opts.c  */
  #define TARGET_BUILTIN_RECIPROCAL default_builtin_reciprocal
***************
*** 880,885 ****
--- 881,887 ----
    TARGET_ALIGN_ANON_BITFIELD,			\
    TARGET_NARROW_VOLATILE_BITFIELD,		\
    TARGET_INIT_BUILTINS,				\
+   TARGET_BUILTIN_DECL,				\
    TARGET_EXPAND_BUILTIN,			\
    TARGET_RESOLVE_OVERLOADED_BUILTIN,		\
    TARGET_FOLD_BUILTIN,				\
Index: trunk/gcc/target.h
===================================================================
*** trunk.orig/gcc/target.h	2009-10-09 15:20:12.000000000 +0200
--- trunk/gcc/target.h	2009-10-09 15:44:03.000000000 +0200
*************** struct gcc_target
*** 562,567 ****
--- 562,573 ----
    /* Set up target-specific built-in functions.  */
    void (* init_builtins) (void);
  
+   /* Initialize (if INITIALIZE_P is true) and return the target-specific
+      built-in function decl for CODE.
+      Return NULL if that is not possible.  Return (void *)-1 if CODE is
+      outside of the range of valid target builtin function codes.  */
+   tree (* builtin_decl) (unsigned code, bool initialize_p);
+ 
    /* Expand a target-specific builtin.  */
    rtx (* expand_builtin) (tree exp, rtx target, rtx subtarget,
  			  enum machine_mode mode, int ignore);
Index: trunk/gcc/lto-streamer-out.c
===================================================================
*** trunk.orig/gcc/lto-streamer-out.c	2009-10-09 15:20:12.000000000 +0200
--- trunk/gcc/lto-streamer-out.c	2009-10-09 15:27:21.000000000 +0200
*************** lto_output_tree_pointers (struct output_
*** 1165,1180 ****
      }
  
    if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
!     {
!       /* FIXME lto.  Not handled yet.  */
!       gcc_unreachable ();
!     }
  
    if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
!     {
!       /* FIXME lto.  Not handled yet.  */
!       gcc_unreachable ();
!     }
  }
  
  
--- 1165,1174 ----
      }
  
    if (CODE_CONTAINS_STRUCT (code, TS_OPTIMIZATION))
!     sorry ("LTO does not handle the optimization attribute");
  
    if (CODE_CONTAINS_STRUCT (code, TS_TARGET_OPTION))
!     sorry ("LTO does not handle the target attribute");
  }
  
  
*************** lto_output_builtin_tree (struct output_b
*** 1234,1239 ****
--- 1228,1237 ----
  {
    gcc_assert (lto_stream_as_builtin_p (expr));
  
+   if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
+       && !targetm.builtin_decl)
+     sorry ("LTO of builtin functions not supported on this target");
+ 
    output_record_start (ob, LTO_builtin_decl);
    output_uleb128 (ob, DECL_BUILT_IN_CLASS (expr));
    output_uleb128 (ob, DECL_FUNCTION_CODE (expr));
Index: trunk/gcc/config/i386/i386.c
===================================================================
*** trunk.orig/gcc/config/i386/i386.c	2009-10-09 15:20:12.000000000 +0200
--- trunk/gcc/config/i386/i386.c	2009-10-09 15:45:22.000000000 +0200
*************** ix86_init_builtins (void)
*** 23443,23448 ****
--- 23443,23459 ----
      ix86_init_builtins_va_builtins_abi ();
  }
  
+ /* Return the ix86 builtin for CODE.  */
+ 
+ static tree
+ ix86_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED)
+ {
+   if (code >= IX86_BUILTIN_MAX)
+     return (tree) (void *)-1;
+ 
+   return ix86_builtins[code];
+ }
+ 
  /* Errors in the source file can cause expand_expr to return const0_rtx
     where we expect a vector.  To avoid crashing, use one of the vector
     clear instructions.  */
*************** ix86_enum_va_list (int idx, const char *
*** 29666,29671 ****
--- 29677,29684 ----
  
  #undef TARGET_INIT_BUILTINS
  #define TARGET_INIT_BUILTINS ix86_init_builtins
+ #undef TARGET_BUILTIN_DECL
+ #define TARGET_BUILTIN_DECL ix86_builtin_decl
  #undef TARGET_EXPAND_BUILTIN
  #define TARGET_EXPAND_BUILTIN ix86_expand_builtin
  
Index: trunk/gcc/doc/tm.texi
===================================================================
*** trunk.orig/gcc/doc/tm.texi	2009-10-09 15:31:58.000000000 +0200
--- trunk/gcc/doc/tm.texi	2009-10-09 15:44:48.000000000 +0200
*************** only language front ends that use those 
*** 10532,10537 ****
--- 10532,10546 ----
  @samp{TARGET_INIT_BUILTINS}.
  @end deftypefn
  
+ @deftypefn {Target Hook} tree TARGET_BUILTIN_FUNCTION (unsigned @var{code}, bool @var{initialize_p})
+ Define this hook if you have any machine-specific built-in functions
+ that need to be defined.  It should be a function that returns the
+ builtin function declaration for the builtin function code @var{code}.
+ If there is no such builtin and it cannot be initialized at this time
+ if @var{initialize_p} is true the function should return @code{NULL_TREE}.
+ If @var{code} is out of range the function should return @code{-1}.
+ @end deftypefn
+ 
  @deftypefn {Target Hook} rtx TARGET_EXPAND_BUILTIN (tree @var{exp}, rtx @var{target}, rtx @var{subtarget}, enum machine_mode @var{mode}, int @var{ignore})
  
  Expand a call to a machine specific built-in function that was set up by


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]