varpool alias reorg

Jan Hubicka hubicka@ucw.cz
Fri Jun 24 12:30:00 GMT 2011


Hi,
I also tested the attached variant that simply disable the builtins streaming.
It fixes the testcase, too, bootstraps/regtestes x86_64 with and without plugin
and builds mozilla. It also solves the decl sharing problems that leads to
debug info confussion.
However it breaks memops-asm.c testcase.  What testcase does is giving builtlins
asm name (i.e. my_memcpy instead of memcpy) and then it tests that the new calls
to the builtilns introduced via folding actually use these asm names.

The code this patch remove was probably invented specifically for this testcase:
instead of streaming builtin decl like we do all other streaming, we just stream
reference to the builtin + an asm name and the single builtin decl in the
LTO unit gets the name.

The problem is that this won't work when LTOing multiple such units each giving a
different asm name (i.e. one of units will win). We can't quite fix this because
we don't want to keep track from where the code we are folding is comming.

So I wonder, do we really need to preserve this behaviour?  
I do not think it is documented anywhere and it seems to me that both variants:
ignoring the asm names or honoring them are sane.

Honza

Index: testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c
===================================================================
*** testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c	(revision 175350)
--- testsuite/gcc.c-torture/execute/builtins/memops-asm-lib.c	(working copy)
*************** typedef __SIZE_TYPE__ size_t;
*** 6,12 ****
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
     actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void *
  my_memcpy (void *d, const void *s, size_t n)
  {
--- 6,11 ----
*************** my_memcpy (void *d, const void *s, size_
*** 19,25 ****
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
     actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void
  my_bcopy (const void *s, void *d, size_t n)
  {
--- 18,23 ----
*************** my_bcopy (const void *s, void *d, size_t
*** 39,45 ****
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
     actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void *
  my_memset (void *d, int c, size_t n)
  {
--- 37,42 ----
*************** my_memset (void *d, int c, size_t n)
*** 51,57 ****
  
  /* LTO code is at the present to able to track that asm alias my_bcopy on builtin
     actually refers to this function.  See PR47181. */
- __attribute__ ((used))
  void
  my_bzero (void *d, size_t n)
  {
--- 48,53 ----
Index: lto-streamer-out.c
===================================================================
*** lto-streamer-out.c	(revision 175350)
--- lto-streamer-out.c	(working copy)
*************** pack_ts_function_decl_value_fields (stru
*** 484,491 ****
  {
    /* For normal/md builtins we only write the class and code, so they
       should never be handled here.  */
-   gcc_assert (!lto_stream_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);
--- 484,489 ----
*************** lto_output_tree_header (struct output_bl
*** 1306,1346 ****
  }
  
  
- /* Write the code and class of builtin EXPR to output block OB.  IX is
-    the index into the streamer cache where EXPR is stored.*/
- 
- static void
- lto_output_builtin_tree (struct output_block *ob, tree expr)
- {
-   gcc_assert (lto_stream_as_builtin_p (expr));
- 
-   if (DECL_BUILT_IN_CLASS (expr) == BUILT_IN_MD
-       && !targetm.builtin_decl)
-     sorry ("gimple bytecode streams do not support machine specific builtin "
- 	   "functions on this target");
- 
-   output_record_start (ob, LTO_builtin_decl);
-   lto_output_enum (ob->main_stream, built_in_class, BUILT_IN_LAST,
- 		   DECL_BUILT_IN_CLASS (expr));
-   output_uleb128 (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] == '*')
- 	lto_output_string (ob, ob->main_stream, &str[1], true);
-       else
- 	lto_output_string (ob, ob->main_stream, NULL, true);
-     }
-   else
-     lto_output_string (ob, ob->main_stream, NULL, true);
- }
- 
- 
  /* Write a physical representation of tree node EXPR to output block
     OB.  If REF_P is true, the leaves of EXPR are emitted as references
     via lto_output_tree_ref.  IX is the index into the streamer cache
--- 1304,1309 ----
*************** lto_output_tree (struct output_block *ob
*** 1456,1470 ****
        lto_output_enum (ob->main_stream, LTO_tags, LTO_NUM_TAGS,
  		       lto_tree_code_to_tag (TREE_CODE (expr)));
      }
-   else if (lto_stream_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.  */
-       lto_output_builtin_tree (ob, expr);
-     }
    else
      {
        /* This is the first time we see EXPR, write its fields
--- 1419,1424 ----
Index: lto-streamer-in.c
===================================================================
*** lto-streamer-in.c	(revision 175350)
--- lto-streamer-in.c	(working copy)
*************** lto_get_pickled_tree (struct lto_input_b
*** 2434,2481 ****
  }
  
  
- /* Read a code and class from input block IB and return the
-    corresponding builtin.  DATA_IN is as in lto_input_tree.  */
- 
- static tree
- lto_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 = lto_input_enum (ib, built_in_class, BUILT_IN_LAST);
-   gcc_assert (fclass == BUILT_IN_NORMAL || fclass == BUILT_IN_MD);
- 
-   fcode = (enum built_in_function) lto_input_uleb128 (ib);
- 
-   if (fclass == BUILT_IN_NORMAL)
-     {
-       if (fcode >= END_BUILTINS)
- 	fatal_error ("machine independent builtin code out of range");
-       result = built_in_decls[fcode];
-       gcc_assert (result);
-     }
-   else if (fclass == BUILT_IN_MD)
-     {
-       result = targetm.builtin_decl (fcode, true);
-       if (!result || result == error_mark_node)
- 	fatal_error ("target specific builtin not available");
-     }
-   else
-     gcc_unreachable ();
- 
-   asmname = lto_input_string (data_in, ib);
-   if (asmname)
-     set_builtin_user_assembler_name (result, asmname);
- 
-   lto_streamer_cache_append (data_in->reader_cache, result);
- 
-   return result;
- }
- 
- 
  /* Read the physical representation of a tree node with tag TAG from
     input block IB using the per-file context in DATA_IN.  */
  
--- 2434,2439 ----
*************** lto_read_tree (struct lto_input_block *i
*** 2495,2504 ****
    if (streamer_hooks.read_tree)
      streamer_hooks.read_tree (ib, data_in, result);
  
-   /* We should never try to instantiate an MD or NORMAL builtin here.  */
-   if (TREE_CODE (result) == FUNCTION_DECL)
-     gcc_assert (!lto_stream_as_builtin_p (result));
- 
    /* end_marker = */ lto_input_1_unsigned (ib);
  
  #ifdef LTO_STREAMER_DEBUG
--- 2453,2458 ----
*************** lto_input_tree (struct lto_input_block *
*** 2582,2593 ****
  	 the reader cache.  */
        result = lto_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 = lto_get_builtin_tree (ib, data_in);
-     }
    else if (tag == lto_tree_code_to_tag (INTEGER_CST))
      {
        /* For integer constants we only need the type and its hi/low
--- 2536,2541 ----
Index: lto-streamer.h
===================================================================
*** lto-streamer.h	(revision 175350)
--- lto-streamer.h	(working copy)
*************** enum LTO_tags
*** 198,206 ****
    /* 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,
- 
    /* Function body.  */
    LTO_function,
  
--- 198,203 ----
*************** emit_label_in_global_context_p (tree lab
*** 1141,1157 ****
    return DECL_NONLOCAL (label) || FORCED_LABEL (label);
  }
  
- /* 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
- lto_stream_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));
- }
- 
  DEFINE_DECL_STREAM_FUNCS (TYPE, type)
  DEFINE_DECL_STREAM_FUNCS (FIELD_DECL, field_decl)
  DEFINE_DECL_STREAM_FUNCS (FN_DECL, fn_decl)
--- 1138,1143 ----



More information about the Gcc-patches mailing list