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]

Annotations for SYMBOL_REF


Adds two fields to a SYMBOL_REF -- the associated DECL, and a set
of flags that cache interesting properties of the symbol.  This
later is both to avoid re-computing data vs the decl, and to cope
with the fact that middle and back-end creates symbol_refs out of
thin air, and these symbols need marking as well.  Perhaps ideally
we'd create DECLs for each of these, but not today.

By itself, this patch does nothing, but now we can update targets
one at a time to avoid the name frobbing that currently happens in
encode_section_info.  The most common sorts of frobbing are already
represented; target-specific widgetry can use bits starting at
SYMBOL_FLAG_MACH_DEP.

In addition, I believe we can avoid the problems with assemble_external
as seen in prs c/10201 and c++/10202.


r~


        * rtl.def (SYMBOL_REF): Add two 0 fields.
        * gengtype.c (adjust_field_rtx_def): Handle them.
        * print-rtl.c (print_rtx): Print them.
        * rtl.h (SYMBOL_REF_DECL, SYMBOL_REF_FLAGS): New.
        (SYMBOL_FLAG_FUNCTION, SYMBOL_REF_FUNCTION_P): New.
        (SYMBOL_FLAG_LOCAL, SYMBOL_REF_LOCAL_P): New.
        (SYMBOL_FLAG_SMALL, SYMBOL_REF_SMALL_P): New.
        (SYMBOL_FLAG_TLS_SHIFT, SYMBOL_REF_TLS_MODEL): New.
        (SYMBOL_FLAG_EXTERNAL, SYMBOL_REF_EXTERNAL_P): New.
        (SYMBOL_FLAG_MACH_DEP): New.
        * optabs.c (init_one_libfunc): Zap fake SYMBOL_REF_DECL.
        * varasm.c (make_decl_rtl): Set SYMBOL_REF_DECL.
        (assemble_static_space): Set SYMBOL_REF_FLAGS.
        (assemble_trampoline_template): Likewise.
        (output_constant_def, force_const_mem): Likewise.
        (default_encode_section_info): New.
        * output.h: Declare it.
        * target-def.h (TARGET_ENCODE_SECTION_INFO): Use it.

Index: gengtype.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gengtype.c,v
retrieving revision 1.28
diff -c -p -d -r1.28 gengtype.c
*** gengtype.c	18 Mar 2003 20:21:18 -0000	1.28
--- gengtype.c	11 Apr 2003 20:46:07 -0000
*************** adjust_field_rtx_def (t, opt)
*** 544,549 ****
--- 544,553 ----
  		t = reg_attrs_tp, subname = "rtreg";
  	      else if (i == SCRATCH && aindex == 0)
  		t = scalar_tp, subname = "rtint";
+ 	      else if (i == SYMBOL_REF && aindex == 1)
+ 		t = scalar_tp, subname = "rtint";
+ 	      else if (i == SYMBOL_REF && aindex == 2)
+ 		t = tree_tp, subname = "rttree";
  	      else if (i == BARRIER && aindex >= 3)
  		t = scalar_tp, subname = "rtint";
  	      else
Index: optabs.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optabs.c,v
retrieving revision 1.170
diff -c -p -d -r1.170 optabs.c
*** optabs.c	11 Apr 2003 19:45:32 -0000	1.170
--- optabs.c	11 Apr 2003 20:46:08 -0000
*************** rtx
*** 5381,5386 ****
--- 5381,5388 ----
  init_one_libfunc (name)
       const char *name;
  {
+   rtx symbol;
+ 
    /* Create a FUNCTION_DECL that can be passed to
       targetm.encode_section_info.  */
    /* ??? We don't have any type information except for this is
*************** init_one_libfunc (name)
*** 5391,5398 ****
    DECL_EXTERNAL (decl) = 1;
    TREE_PUBLIC (decl) = 1;
  
!   /* Return the symbol_ref from the mem rtx.  */
!   return XEXP (DECL_RTL (decl), 0);
  }
  
  /* Call this once to initialize the contents of the optabs
--- 5393,5405 ----
    DECL_EXTERNAL (decl) = 1;
    TREE_PUBLIC (decl) = 1;
  
!   symbol = XEXP (DECL_RTL (decl), 0);
! 
!   /* Zap the nonsensical SYMBOL_REF_DECL for this.  What we're left with
!      are the flags assigned by targetm.encode_section_info.  */
!   SYMBOL_REF_DECL (symbol) = 0;
! 
!   return symbol;
  }
  
  /* Call this once to initialize the contents of the optabs
Index: output.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/output.h,v
retrieving revision 1.119
diff -c -p -d -r1.119 output.h
*** output.h	28 Jan 2003 18:08:48 -0000	1.119
--- output.h	11 Apr 2003 20:46:08 -0000
*************** extern void default_select_rtx_section P
*** 519,524 ****
--- 519,525 ----
  						unsigned HOST_WIDE_INT));
  extern void default_elf_select_rtx_section PARAMS ((enum machine_mode, rtx,
  						    unsigned HOST_WIDE_INT));
+ extern void default_encode_section_info PARAMS ((tree, int));
  extern const char *default_strip_name_encoding PARAMS ((const char *));
  extern bool default_binds_local_p PARAMS ((tree));
  extern bool default_binds_local_p_1 PARAMS ((tree, int));
Index: print-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/print-rtl.c,v
retrieving revision 1.94
diff -c -p -d -r1.94 print-rtl.c
*** print-rtl.c	26 Jan 2003 08:59:54 -0000	1.94
--- print-rtl.c	11 Apr 2003 20:46:09 -0000
*************** print_rtx (in_rtx)
*** 239,247 ****
  	  {
  	    if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
  	      fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
- 	    break;
  	  }
! 	if (i == 4 && GET_CODE (in_rtx) == NOTE)
  	  {
  	    switch (NOTE_LINE_NUMBER (in_rtx))
  	      {
--- 239,260 ----
  	  {
  	    if (REGNO (in_rtx) != ORIGINAL_REGNO (in_rtx))
  	      fprintf (outfile, " [%d]", ORIGINAL_REGNO (in_rtx));
  	  }
! #ifndef GENERATOR_FILE
! 	else if (i == 1 && GET_CODE (in_rtx) == SYMBOL_REF)
! 	  {
! 	    int flags = SYMBOL_REF_FLAGS (in_rtx);
! 	    if (flags)
! 	      fprintf (outfile, " [flags 0x%x]", flags);
! 	  }
! 	else if (i == 2 && GET_CODE (in_rtx) == SYMBOL_REF)
! 	  {
! 	    tree decl = SYMBOL_REF_DECL (in_rtx);
! 	    if (decl)
! 	      print_node_brief (outfile, "", decl, 0);
! 	  }
! #endif
! 	else if (i == 4 && GET_CODE (in_rtx) == NOTE)
  	  {
  	    switch (NOTE_LINE_NUMBER (in_rtx))
  	      {
Index: rtl.def
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.def,v
retrieving revision 1.66
diff -c -p -d -r1.66 rtl.def
*** rtl.def	9 Feb 2003 12:35:27 -0000	1.66
--- rtl.def	11 Apr 2003 20:46:09 -0000
*************** DEF_RTL_EXPR(MEM, "mem", "e0", 'o')
*** 860,870 ****
     LABEL_NEXTREF and CONTAINING_INSN.  */
  DEF_RTL_EXPR(LABEL_REF, "label_ref", "u00", 'o')
  
! /* Reference to a named label: the string that is the first operand,
!    with `_' added implicitly in front.
!    Exception: if the first character explicitly given is `*',
!    to give it to the assembler, remove the `*' and do not add `_'.  */
! DEF_RTL_EXPR(SYMBOL_REF, "symbol_ref", "s", 'o')
  
  /* The condition code register is represented, in our imagination,
     as a register holding a value that can be compared to zero.
--- 860,870 ----
     LABEL_NEXTREF and CONTAINING_INSN.  */
  DEF_RTL_EXPR(LABEL_REF, "label_ref", "u00", 'o')
  
! /* Reference to a named label: 
!    Operand 0: label name
!    Operand 1: flags (see SYMBOL_FLAG_* in rtl.h)
!    Operand 2: tree decl from which this symbol is derived, or null.  */
! DEF_RTL_EXPR(SYMBOL_REF, "symbol_ref", "s00", 'o')
  
  /* The condition code register is represented, in our imagination,
     as a register holding a value that can be compared to zero.
Index: rtl.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/rtl.h,v
retrieving revision 1.393
diff -c -p -d -r1.393 rtl.h
*** rtl.h	6 Apr 2003 21:44:09 -0000	1.393
--- rtl.h	11 Apr 2003 20:46:09 -0000
*************** do {						\
*** 1245,1250 ****
--- 1245,1290 ----
  #define SYMBOL_REF_WEAK(RTX)						\
    (RTL_FLAG_CHECK1("SYMBOL_REF_WEAK", (RTX), SYMBOL_REF)->integrated)
  
+ /* The tree decl associated with the symbol, or null.  */
+ #define SYMBOL_REF_DECL(RTX)	X0TREE ((RTX), 2)
+ 
+ /* A set of flags on a symbol_ref that are, in some respects, redundant with
+    information derivable from the tree decl associated with this symbol.
+    Except that we build a *lot* of SYMBOL_REFs that aren't associated with a
+    decl.  In some cases this is a bug.  But beyond that, it's nice to cache
+    this information to avoid recomputing it.  Finally, this allows space for
+    the target to store more than one bit of information, as with
+    SYMBOL_REF_FLAG.  */
+ #define SYMBOL_REF_FLAGS(RTX)	X0INT ((RTX), 1)
+ 
+ /* These flags are common enough to be defined for all targets.  They
+    are computed by the default version of targetm.encode_section_info.  */
+ 
+ /* Set if this symbol is a function.  */
+ #define SYMBOL_FLAG_FUNCTION	(1 << 0)
+ #define SYMBOL_REF_FUNCTION_P(RTX) \
+   ((SYMBOL_REF_FLAGS (RTX) & SYMBOL_FLAG_FUNCTION) != 0)
+ /* Set if targetm.binds_local_p is true.  */
+ #define SYMBOL_FLAG_LOCAL	(1 << 1)
+ #define SYMBOL_REF_LOCAL_P(RTX) \
+   ((SYMBOL_REF_FLAGS (RTX) & SYMBOL_FLAG_LOCAL) != 0)
+ /* Set if targetm.in_small_data_p is true.  */
+ #define SYMBOL_FLAG_SMALL	(1 << 2)
+ #define SYMBOL_REF_SMALL_P(RTX) \
+   ((SYMBOL_REF_FLAGS (RTX) & SYMBOL_FLAG_SMALL) != 0)
+ /* The three-bit field at [5:3] is true for TLS variables; use
+    SYMBOL_REF_TLS_MODEL to extract the field as an enum tls_model.  */
+ #define SYMBOL_FLAG_TLS_SHIFT	3
+ #define SYMBOL_REF_TLS_MODEL(RTX) \
+   ((enum tls_model) ((SYMBOL_REF_FLAGS (RTX) >> SYMBOL_FLAG_TLS_SHIFT) & 3))
+ /* Set if this symbol is not defined in this translation unit.  */
+ #define SYMBOL_FLAG_EXTERNAL	(1 << 6)
+ #define SYMBOL_REF_EXTERNAL_P(RTX) \
+   ((SYMBOL_REF_FLAGS (RTX) & SYMBOL_FLAG_EXTERNAL) != 0)
+ 
+ /* Subsequent bits are available for the target to use.  */
+ #define SYMBOL_FLAG_MACH_DEP	(1 << 7)
+ 
  /* Define a macro to look for REG_INC notes,
     but save time on machines where they never exist.  */
  
Index: target-def.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/target-def.h,v
retrieving revision 1.47
diff -c -p -d -r1.47 target-def.h
*** target-def.h	5 Mar 2003 22:37:51 -0000	1.47
--- target-def.h	11 Apr 2003 20:46:10 -0000
*************** Foundation, 59 Temple Place - Suite 330,
*** 280,286 ****
  #endif
  
  #ifndef TARGET_ENCODE_SECTION_INFO
! #define TARGET_ENCODE_SECTION_INFO hook_void_tree_int
  #endif
  
  /* The whole shebang.  */
--- 280,286 ----
  #endif
  
  #ifndef TARGET_ENCODE_SECTION_INFO
! #define TARGET_ENCODE_SECTION_INFO default_encode_section_info
  #endif
  
  /* The whole shebang.  */
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/varasm.c,v
retrieving revision 1.337
diff -c -p -d -r1.337 varasm.c
*** varasm.c	1 Apr 2003 18:33:49 -0000	1.337
--- varasm.c	11 Apr 2003 20:46:11 -0000
*************** make_decl_rtl (decl, asmspec)
*** 920,927 ****
        name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
      }
  
!   x = gen_rtx_MEM (DECL_MODE (decl), gen_rtx_SYMBOL_REF (Pmode, name));
!   SYMBOL_REF_WEAK (XEXP (x, 0)) = DECL_WEAK (decl);
    if (TREE_CODE (decl) != FUNCTION_DECL)
      set_mem_attributes (x, decl, 1);
    SET_DECL_RTL (decl, x);
--- 920,930 ----
        name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
      }
  
!   x = gen_rtx_SYMBOL_REF (Pmode, name);
!   SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
!   SYMBOL_REF_DECL (x) = decl;
!   
!   x = gen_rtx_MEM (DECL_MODE (decl), x);
    if (TREE_CODE (decl) != FUNCTION_DECL)
      set_mem_attributes (x, decl, 1);
    SET_DECL_RTL (decl, x);
*************** assemble_static_space (size)
*** 1765,1770 ****
--- 1768,1774 ----
    namestring = ggc_strdup (name);
  
    x = gen_rtx_SYMBOL_REF (Pmode, namestring);
+   SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL;
  
  #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
    ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
*************** assemble_trampoline_template ()
*** 1799,1804 ****
--- 1803,1809 ----
    char label[256];
    const char *name;
    int align;
+   rtx symbol;
  
    /* By default, put trampoline templates in read-only data section.  */
  
*************** assemble_trampoline_template ()
*** 1821,1827 ****
    /* Record the rtl to refer to it.  */
    ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
    name = ggc_strdup (label);
!   return gen_rtx_SYMBOL_REF (Pmode, name);
  }
  #endif
  
--- 1826,1835 ----
    /* Record the rtl to refer to it.  */
    ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
    name = ggc_strdup (label);
!   symbol = gen_rtx_SYMBOL_REF (Pmode, name);
!   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
! 
!   return symbol;
  }
  #endif
  
*************** output_constant_def (exp, defer)
*** 2650,2655 ****
--- 2658,2665 ----
  
    if (desc == 0)
      {
+       rtx symbol;
+ 
        /* No constant equal to EXP is known to have been output.
  	 Make a constant descriptor to enter EXP in the hash table.
  	 Assign the label number and record it in the descriptor for
*************** output_constant_def (exp, defer)
*** 2666,2674 ****
        const_hash_table[hash] = desc;
  
        /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
!       rtl = desc->rtl
! 	= gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
! 		       gen_rtx_SYMBOL_REF (Pmode, desc->label));
  
        set_mem_attributes (rtl, exp, 1);
        set_mem_alias_set (rtl, 0);
--- 2676,2685 ----
        const_hash_table[hash] = desc;
  
        /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
!       symbol = gen_rtx_SYMBOL_REF (Pmode, desc->label);
!       SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
! 
!       rtl = desc->rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol);
  
        set_mem_attributes (rtl, exp, 1);
        set_mem_alias_set (rtl, 0);
*************** force_const_mem (mode, x)
*** 3173,3179 ****
    int hash;
    struct constant_descriptor_rtx *desc;
    char label[256];
!   rtx def;
    struct pool_constant *pool;
    unsigned int align;
  
--- 3184,3190 ----
    int hash;
    struct constant_descriptor_rtx *desc;
    char label[256];
!   rtx def, symbol;
    struct pool_constant *pool;
    unsigned int align;
  
*************** force_const_mem (mode, x)
*** 3234,3252 ****
  
    /* Construct the SYMBOL_REF and the MEM.  */
  
!   pool->desc->rtl = def
!     = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)));
!   set_mem_alias_set (def, const_alias_set);
    set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
    RTX_UNCHANGING_P (def) = 1;
  
    /* Add label to symbol hash table.  */
!   hash = SYMHASH (XSTR (XEXP (def, 0), 0));
    pool->next_sym = const_rtx_sym_hash_table[hash];
    const_rtx_sym_hash_table[hash] = pool;
  
    /* Mark the symbol_ref as belonging to this constants pool.  */
!   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
    current_function_uses_const_pool = 1;
  
    return def;
--- 3245,3265 ----
  
    /* Construct the SYMBOL_REF and the MEM.  */
  
!   symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
!   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
! 
!   pool->desc->rtl = def = gen_rtx_MEM (mode, symbol);
    set_mem_attributes (def, (*lang_hooks.types.type_for_mode) (mode, 0), 1);
    RTX_UNCHANGING_P (def) = 1;
  
    /* Add label to symbol hash table.  */
!   hash = SYMHASH (XSTR (symbol, 0));
    pool->next_sym = const_rtx_sym_hash_table[hash];
    const_rtx_sym_hash_table[hash] = pool;
  
    /* Mark the symbol_ref as belonging to this constants pool.  */
!   CONSTANT_POOL_ADDRESS_P (symbol) = 1;
!   SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL;
    current_function_uses_const_pool = 1;
  
    return def;
*************** default_elf_select_rtx_section (mode, x,
*** 5368,5373 ****
--- 5381,5420 ----
        }
  
    mergeable_constant_section (mode, align, 0);
+ }
+ 
+ /* Set the generally applicable flags on the SYMBOL_REF for EXP.  */
+ 
+ void
+ default_encode_section_info (decl, first)
+      tree decl;
+      int first ATTRIBUTE_UNUSED;
+ {
+   rtx rtl, symbol;
+   int flags;
+ 
+   rtl = DECL_P (decl) ? DECL_RTL (decl) : TREE_CST_RTL (decl);
+ 
+   /* Careful not to prod global register variables.  */
+   if (GET_CODE (rtl) != MEM)
+     return;
+   symbol = XEXP (rtl, 0);
+   if (GET_CODE (symbol) != SYMBOL_REF)
+     return;
+ 
+   flags = 0;
+   if (TREE_CODE (decl) == FUNCTION_DECL)
+     flags |= SYMBOL_FLAG_FUNCTION;
+   if ((*targetm.binds_local_p) (decl))
+     flags |= SYMBOL_FLAG_LOCAL;
+   if ((*targetm.in_small_data_p) (decl))
+     flags |= SYMBOL_FLAG_SMALL;
+   if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl))
+     flags |= decl_tls_model (decl) << SYMBOL_FLAG_TLS_SHIFT;
+   if (DECL_P (decl) && DECL_EXTERNAL (decl))
+     flags |= SYMBOL_FLAG_EXTERNAL;
+ 
+   SYMBOL_REF_FLAGS (symbol) = flags;
  }
  
  /* By default, we do nothing for encode_section_info, so we need not


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