So I needed to fix that builtins appearing in BLOCK_VARs and the solution
I came up with accidentially disabled streaming via the special path.
Thus the following patch removes the special-casing completely and makes
the BLOCK_VARs handling work the same way as for regular externs (by
streaming a local copy).  We stream each builtin decl once and then
refer to it via the decl index (which is cheaper than the special
casing).

I'm not 100% this solves for example the -fno-math-errno inlining
across TUs (it certainly doesn't if you use attribute optimize with
-fno-math-errno), but it eventually should by means of having two
different BUILT_IN_XXX if they have different behavior.  At least
if all relevant bits are set on the function _type_ rather than
the decl which I think we still lto-symtab replace with one
entity during WPA(?)

Well.

LTO bootstrapped and tested on x86_64-unknown-linux-gnu (c,c++,fortran),
bootstrapped on x86_64-unknown-linux-gnu (all), testing in progress.

I might have not catched all fndecl compares.

Will apply to trunk if testing completes.  As said, maybe followup
cleanups possible, at least to lto-opts.c / lto-wrapper.

Richard.

2016-07-25  Richard Biener  <rguent...@suse.de>

        * cgraph.c (cgraph_node::verify_node): Compare against builtin
        by using DECL_BUILT_IN_CLASS and DECL_FUNCTION_CODE.
        * tree-chkp.c (chkp_gimple_call_builtin_p): Likewise.
        * tree-streamer.h (streamer_handle_as_builtin_p): Remove.
        (streamer_get_builtin_tree): Likewise.
        (streamer_write_builtin): Likewise.
        * lto-streamer.h (LTO_builtin_decl): Remove.
        * lto-streamer-in.c (lto_read_tree_1): Remove assert.
        (lto_input_scc): Remove LTO_builtin_decl handling.
        (lto_input_tree_1): Liekwise.
        * lto-streamer-out.c (lto_output_tree_1): Remove special
        handling of builtins.
        (DFS::DFS): Likewise.
        * tree-streamer-in.c (streamer_get_builtin_tree): Remove.
        * tree-streamer-out.c (pack_ts_function_decl_value_fields): Remove
        assert.
        (streamer_write_builtin): Remove.

        lto/
        * lto.c (compare_tree_sccs_1): Remove streamer_handle_as_builtin_p uses.
        (unify_scc): Likewise.
        (lto_read_decls): Likewise.

Index: gcc/cgraph.c
===================================================================
--- gcc/cgraph.c        (revision 238590)
+++ gcc/cgraph.c        (working copy)
@@ -3136,8 +3136,9 @@ cgraph_node::verify_node (void)
          && !e->speculative
          /* Optimized out calls are redirected to __builtin_unreachable.  */
          && (e->frequency
-             || e->callee->decl
-                != builtin_decl_implicit (BUILT_IN_UNREACHABLE))
+             || ! e->callee->decl
+             || DECL_BUILT_IN_CLASS (e->callee->decl) != BUILT_IN_NORMAL
+             || DECL_FUNCTION_CODE (e->callee->decl) != BUILT_IN_UNREACHABLE)
          && (e->frequency
              != compute_call_stmt_bb_frequency (e->caller->decl,
                                                 gimple_bb (e->call_stmt))))
Index: gcc/lto/lto.c
===================================================================
--- gcc/lto/lto.c       (revision 238590)
+++ gcc/lto/lto.c       (working copy)
@@ -1061,12 +1061,6 @@ compare_tree_sccs_1 (tree t1, tree t2, t
                        TREE_FIXED_CST_PTR (t1), TREE_FIXED_CST_PTR (t2)))
       return false;
 
-
-  /* We want to compare locations up to the point where it makes
-     a difference for streaming - thus whether the decl is builtin or not.  */
-  if (CODE_CONTAINS_STRUCT (code, TS_DECL_MINIMAL))
-    compare_values (streamer_handle_as_builtin_p);
-
   if (CODE_CONTAINS_STRUCT (code, TS_DECL_COMMON))
     {
       compare_values (DECL_MODE);
@@ -1602,8 +1596,7 @@ unify_scc (struct data_in *data_in, unsi
                   streamer.  The others should be singletons, too, and we
                   should not merge them in any way.  */
                gcc_assert (code != TRANSLATION_UNIT_DECL
-                           && code != IDENTIFIER_NODE
-                           && !streamer_handle_as_builtin_p (t));
+                           && code != IDENTIFIER_NODE);
              }
 
          /* Fixup the streamer cache with the prevailing nodes according
@@ -1710,8 +1703,7 @@ lto_read_decls (struct lto_file_decl_dat
          if (len == 1
              && (TREE_CODE (first) == IDENTIFIER_NODE
                  || TREE_CODE (first) == INTEGER_CST
-                 || TREE_CODE (first) == TRANSLATION_UNIT_DECL
-                 || streamer_handle_as_builtin_p (first)))
+                 || TREE_CODE (first) == TRANSLATION_UNIT_DECL))
            continue;
 
          /* Try to unify the SCC with already existing ones.  */
Index: gcc/lto-streamer-in.c
===================================================================
--- gcc/lto-streamer-in.c       (revision 238590)
+++ gcc/lto-streamer-in.c       (working copy)
@@ -1302,10 +1302,6 @@ lto_read_tree_1 (struct lto_input_block
       && TREE_CODE (expr) != TRANSLATION_UNIT_DECL)
     DECL_INITIAL (expr) = stream_read_tree (ib, data_in);
 
-  /* We should never try to instantiate an MD or NORMAL builtin here.  */
-  if (TREE_CODE (expr) == FUNCTION_DECL)
-    gcc_assert (!streamer_handle_as_builtin_p (expr));
-
 #ifdef LTO_STREAMER_DEBUG
   /* Remove the mapping to RESULT's original address set by
      streamer_alloc_tree.  */
@@ -1368,7 +1364,6 @@ lto_input_scc (struct lto_input_block *i
          if (tag == LTO_null
              || (tag >= LTO_field_decl_ref && tag <= LTO_global_decl_ref)
              || tag == LTO_tree_pickle_reference
-             || tag == LTO_builtin_decl
              || tag == LTO_integer_cst
              || tag == LTO_tree_scc)
            gcc_unreachable ();
@@ -1420,12 +1415,6 @@ lto_input_tree_1 (struct lto_input_block
         the reader cache.  */
       result = streamer_get_pickled_tree (ib, data_in);
     }
-  else if (tag == LTO_builtin_decl)
-    {
-      /* If we are going to read a built-in function, all we need is
-        the code and class.  */
-      result = streamer_get_builtin_tree (ib, data_in);
-    }
   else if (tag == LTO_integer_cst)
     {
       /* For shared integer constants in singletons we can use the
Index: gcc/lto-streamer-out.c
===================================================================
--- gcc/lto-streamer-out.c      (revision 238590)
+++ gcc/lto-streamer-out.c      (working copy)
@@ -445,17 +445,8 @@ lto_output_tree_1 (struct output_block *
   bool exists_p = streamer_tree_cache_insert (ob->writer_cache,
                                              expr, hash, &ix);
   gcc_assert (!exists_p);
-  if (streamer_handle_as_builtin_p (expr))
-    {
-      /* MD and NORMAL builtins do not need to be written out
-        completely as they are always instantiated by the
-        compiler on startup.  The only builtins that need to
-        be written out are BUILT_IN_FRONTEND.  For all other
-        builtins, we simply write the class and code.  */
-      streamer_write_builtin (ob, expr);
-    }
-  else if (TREE_CODE (expr) == INTEGER_CST
-          && !TREE_OVERFLOW (expr))
+  if (TREE_CODE (expr) == INTEGER_CST
+      && !TREE_OVERFLOW (expr))
     {
       /* Shared INTEGER_CST nodes are special because they need their
         original type to be materialized by the reader (to implement
@@ -559,10 +550,8 @@ DFS::DFS (struct output_block *ob, tree
          cstate->low = cstate->dfsnum;
          w.cstate = cstate;
 
-         if (streamer_handle_as_builtin_p (expr))
-           ;
-         else if (TREE_CODE (expr) == INTEGER_CST
-                  && !TREE_OVERFLOW (expr))
+         if (TREE_CODE (expr) == INTEGER_CST
+             && !TREE_OVERFLOW (expr))
            DFS_write_tree (ob, cstate, TREE_TYPE (expr), ref_p, ref_p);
          else
            {
@@ -675,8 +664,6 @@ DFS::DFS (struct output_block *ob, tree
                                    "in LTO streams",
                                    get_tree_code_name (TREE_CODE (t)));
 
-                 gcc_checking_assert (!streamer_handle_as_builtin_p (t));
-
                  /* Write the header, containing everything needed to
                     materialize EXPR on the reading side.  */
                  streamer_write_tree_header (ob, t);
@@ -2074,7 +2061,9 @@ output_function (struct cgraph_node *nod
   streamer_write_chain (ob, DECL_ARGUMENTS (function), true);
 
   /* Output DECL_INITIAL for the function, which contains the tree of
-     lexical scopes.  */
+     lexical scopes.
+     ???  This only streams the outermost block because we do not
+     recurse into BLOCK_SUBBLOCKS but re-build those on stream-in.  */
   stream_write_tree (ob, DECL_INITIAL (function), true);
 
   /* We also stream abstract functions where we stream only stuff needed for
Index: gcc/lto-streamer.h
===================================================================
--- gcc/lto-streamer.h  (revision 238590)
+++ gcc/lto-streamer.h  (working copy)
@@ -162,9 +162,6 @@ enum LTO_tags
   /* EH region holding the previous statement.  */
   LTO_eh_region,
 
-  /* An MD or NORMAL builtin.  Only the code and class are streamed out.  */
-  LTO_builtin_decl,
-
   /* Shared INTEGER_CST node.  */
   LTO_integer_cst,
 
Index: gcc/tree-chkp.c
===================================================================
--- gcc/tree-chkp.c     (revision 238590)
+++ gcc/tree-chkp.c     (working copy)
@@ -431,9 +431,10 @@ chkp_gimple_call_builtin_p (gimple *call
                            enum built_in_function code)
 {
   tree fndecl;
-  if (is_gimple_call (call)
+  if (gimple_call_builtin_p (call, BUILT_IN_MD)
       && (fndecl = targetm.builtin_chkp_function (code))
-      && gimple_call_fndecl (call) == fndecl)
+      && (DECL_FUNCTION_CODE (gimple_call_fndecl (call))
+         == DECL_FUNCTION_CODE (fndecl)))
     return true;
   return false;
 }
Index: gcc/tree-streamer-in.c
===================================================================
--- gcc/tree-streamer-in.c      (revision 238590)
+++ gcc/tree-streamer-in.c      (working copy)
@@ -1113,62 +1113,3 @@ streamer_get_pickled_tree (struct lto_in
 
   return result;
 }
-
-
-/* Read a code and class from input block IB and return the
-   corresponding builtin.  DATA_IN is as in stream_read_tree.  */
-
-tree
-streamer_get_builtin_tree (struct lto_input_block *ib, struct data_in *data_in)
-{
-  enum built_in_class fclass;
-  enum built_in_function fcode;
-  const char *asmname;
-  tree result;
-
-  fclass = streamer_read_enum (ib, built_in_class, BUILT_IN_LAST);
-  gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
-
-  fcode = (enum built_in_function) streamer_read_uhwi (ib);
-
-  if (fclass == BUILT_IN_NORMAL)
-    {
-      if (fcode >= END_BUILTINS)
-       fatal_error (input_location,
-                    "machine independent builtin code out of range");
-      result = builtin_decl_explicit (fcode);
-      if (!result)
-       {
-         if (fcode > BEGIN_CHKP_BUILTINS && fcode < END_CHKP_BUILTINS)
-           {
-             fcode = (enum built_in_function)
-                     (fcode - BEGIN_CHKP_BUILTINS - 1);
-             result = builtin_decl_explicit (fcode);
-             result = chkp_maybe_clone_builtin_fndecl (result);
-           }
-         else if (fcode > BEGIN_SANITIZER_BUILTINS
-                  && fcode < END_SANITIZER_BUILTINS)
-           {
-             initialize_sanitizer_builtins ();
-             result = builtin_decl_explicit (fcode);
-           }
-       }
-      gcc_assert (result);
-    }
-  else if (fclass == BUILT_IN_MD)
-    {
-      result = targetm.builtin_decl (fcode, true);
-      if (!result || result == error_mark_node)
-       fatal_error (input_location, "target specific builtin not available");
-    }
-  else
-    gcc_unreachable ();
-
-  asmname = streamer_read_string (data_in, ib);
-  if (asmname)
-    set_builtin_user_assembler_name (result, asmname);
-
-  streamer_tree_cache_append (data_in->reader_cache, result, 0);
-
-  return result;
-}
Index: gcc/tree-streamer-out.c
===================================================================
--- gcc/tree-streamer-out.c     (revision 238590)
+++ gcc/tree-streamer-out.c     (working copy)
@@ -278,10 +278,6 @@ pack_ts_decl_with_vis_value_fields (stru
 static void
 pack_ts_function_decl_value_fields (struct bitpack_d *bp, tree expr)
 {
-  /* For normal/md builtins we only write the class and code, so they
-     should never be handled here.  */
-  gcc_assert (!streamer_handle_as_builtin_p (expr));
-
   bp_pack_enum (bp, built_in_class, BUILT_IN_LAST,
                DECL_BUILT_IN_CLASS (expr));
   bp_pack_value (bp, DECL_STATIC_CONSTRUCTOR (expr), 1);
@@ -487,41 +483,6 @@ streamer_write_tree_bitfields (struct ou
 }
 
 
-/* Write the code and class of builtin EXPR to output block OB.  IX is
-   the index into the streamer cache where EXPR is stored.*/
-
-void
-streamer_write_builtin (struct output_block *ob, tree expr)
-{
-  gcc_assert (streamer_handle_as_builtin_p (expr));
-
-  if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
-      && !targetm.builtin_decl)
-    sorry ("tree bytecode streams do not support machine specific builtin "
-          "functions on this target");
-
-  streamer_write_record_start (ob, LTO_builtin_decl);
-  streamer_write_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
-                      DECL_BUILT_IN_CLASS (expr));
-  streamer_write_uhwi (ob, DECL_FUNCTION_CODE (expr));
-
-  if (DECL_ASSEMBLER_NAME_SET_P (expr))
-    {
-      /* When the assembler name of a builtin gets a user name,
-        the new name is always prefixed with '*' by
-        set_builtin_user_assembler_name.  So, to prevent the
-        reader side from adding a second '*', we omit it here.  */
-      const char *str = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (expr));
-      if (strlen (str) > 1 && str[0] == '*')
-       streamer_write_string (ob, ob->main_stream, &str[1], true);
-      else
-       streamer_write_string (ob, ob->main_stream, NULL, true);
-    }
-  else
-    streamer_write_string (ob, ob->main_stream, NULL, true);
-}
-
-
 /* Emit the chain of tree nodes starting at T.  OB is the output block
    to write to.  REF_P is true if chain elements should be emitted
    as references.  */
Index: gcc/tree-streamer.h
===================================================================
--- gcc/tree-streamer.h (revision 238590)
+++ gcc/tree-streamer.h (working copy)
@@ -57,17 +57,6 @@ struct streamer_tree_cache_d
   unsigned next_idx;
 };
 
-/* Return true if tree node EXPR should be streamed as a builtin.  For
-   these nodes, we just emit the class and function code.  */
-static inline bool
-streamer_handle_as_builtin_p (tree expr)
-{
-  return (TREE_CODE (expr) == FUNCTION_DECL
-         && DECL_IS_BUILTIN (expr)
-         && (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_NORMAL
-             || DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD));
-}
-
 /* In tree-streamer-in.c.  */
 tree streamer_read_string_cst (struct data_in *, struct lto_input_block *);
 tree streamer_read_chain (struct lto_input_block *, struct data_in *);
@@ -75,7 +64,6 @@ tree streamer_alloc_tree (struct lto_inp
                          enum LTO_tags);
 void streamer_read_tree_body (struct lto_input_block *, struct data_in *, 
tree);
 tree streamer_get_pickled_tree (struct lto_input_block *, struct data_in *);
-tree streamer_get_builtin_tree (struct lto_input_block *, struct data_in *);
 void streamer_read_tree_bitfields (struct lto_input_block *,
                                   struct data_in *, tree);
 
@@ -87,7 +75,6 @@ void streamer_write_tree_header (struct
 void streamer_write_tree_bitfields (struct output_block *, tree);
 void streamer_write_tree_body (struct output_block *, tree, bool);
 void streamer_write_integer_cst (struct output_block *, tree, bool);
-void streamer_write_builtin (struct output_block *, tree);
 
 /* In tree-streamer.c.  */
 extern unsigned char streamer_mode_table[1 << 8];

Reply via email to