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]

Add language hook for respect READONLY in tree.


tested on alphaev56-dec-osf4.0c.

Fri Oct 19 15:24:39 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* langhooks.h (LANG_HOOKS_HONOR_READONLY): New macro.
	* toplev.h (struct lang_hooks): New field HONOR_READONLY.
	* emit-rtl.c (set_mem_attributes): Set RTX_UNCHANGING_P from
	TREE_READONLY and TYPE_READONLY if lang_hooks.honor_readonly.
	Set alignment from type if INDIRECT_REF.
	(adjust_address_1, offset_address): Simplify alignment compuitation.
	* expr.c (expand_expr, case INDIRECT_REF): Don't set RTX_UNCHANGING_P
	here; done by set_mem_attributes.

*** langhooks.h	2001/10/08 20:54:07	1.1
--- langhooks.h	2001/10/19 19:07:06
*************** Boston, MA 02111-1307, USA.  */
*** 40,43 ****
--- 40,46 ----
  #define LANG_HOOKS_POST_OPTIONS NULL
  #endif
+ #ifndef LANG_HOOKS_HONOR_READONLY
+ #define LANG_HOOKS_HONOR_READONLY 0
+ #endif
  
  /* Declarations of default tree inlining hooks.  */
*************** int tree_inlining_default_hook_anon_aggr
*** 109,112 ****
--- 112,116 ----
    LANG_HOOKS_DECODE_OPTION, \
    LANG_HOOKS_POST_OPTIONS, \
+   LANG_HOOKS_HONOR_READONLY, \
    LANG_HOOKS_TREE_INLINING_INITIALIZER \
  }
*** toplev.h	2001/10/08 20:54:07	1.74
--- toplev.h	2001/10/19 19:07:11
*************** struct lang_hooks
*** 167,170 ****
--- 167,173 ----
    void (*post_options) PARAMS ((void));
  
+   /* Nonzero if TYPE_READONLY and TREE_READONLY should always be honored.  */
+   int honor_readonly;
+ 
    struct lang_hooks_for_tree_inlining tree_inlining;
  
*** emit-rtl.c	2001/10/18 21:34:07	1.211
--- emit-rtl.c	2001/10/19 19:02:24
*************** set_mem_attributes (ref, t, objectp)
*** 1673,1683 ****
    set_mem_alias_set (ref, get_alias_set (t));
  
-   /* It is incorrect to set RTX_UNCHANGING_P from TREE_READONLY (type)
-      here, because, in C and C++, the fact that a location is accessed
-      through a const expression does not mean that the value there can
-      never change.  */
- 
    MEM_VOLATILE_P (ref) = TYPE_VOLATILE (type);
    MEM_IN_STRUCT_P (ref) = AGGREGATE_TYPE_P (type);
  
    /* If we are making an object of this type, we know that it is a scalar if
--- 1673,1681 ----
    set_mem_alias_set (ref, get_alias_set (t));
  
    MEM_VOLATILE_P (ref) = TYPE_VOLATILE (type);
    MEM_IN_STRUCT_P (ref) = AGGREGATE_TYPE_P (type);
+   RTX_UNCHANGING_P (ref)
+     |= (lang_hooks.honor_readonly
+ 	&& (TYPE_READONLY (type) || TREE_READONLY (t)));
  
    /* If we are making an object of this type, we know that it is a scalar if
*************** set_mem_attributes (ref, t, objectp)
*** 1718,1721 ****
--- 1716,1723 ----
  	 : 0, DECL_ALIGN (t) / BITS_PER_UNIT);
  
+   /* If this is an INDIRECT_REF, we know its alignment.  */
+   if (TREE_CODE (t) == INDIRECT_REF)
+     set_mem_align (ref, TYPE_ALIGN (type) / BITS_PER_UNIT);
+ 
    /* Now see if we can say more about whether it's an aggregate or
       scalar.  If we already know it's an aggregate, don't bother.  */
*************** adjust_address_1 (memref, mode, offset, 
*** 1860,1872 ****
    if (memoffset)
      memoffset = GEN_INT (offset + INTVAL (memoffset));
- 
-   /* If the offset is negative, don't try to update the alignment.  If it's
-      zero, the alignment hasn't changed.  Otherwise, the known alignment may
-      be less strict.  */
-   if (offset < 0)
-     memalign = 1;
  
!   while (offset > 0 && (offset % memalign) != 0)
!     memalign >>= 1;
  
    MEM_ATTRS (new)
--- 1862,1871 ----
    if (memoffset)
      memoffset = GEN_INT (offset + INTVAL (memoffset));
  
!   /* Compute the new alignment by taking the MIN of the alignment and the
!      lowest-order set bit in OFFSET, but don't change the alignment if OFFSET
!      if zero.  */
!   if (offset != 0)
!     memalign = MIN (memalign, offset & -offset);
  
    MEM_ATTRS (new)
*************** offset_address (memref, offset, pow2)
*** 1894,1906 ****
  			      gen_rtx_PLUS (Pmode, XEXP (memref, 0),
  					    force_reg (Pmode, offset)), 1);
-   unsigned int memalign = MEM_ALIGN (memref);
  
    /* Update the alignment to reflect the offset.  Reset the offset, which
       we don't know.  */
-   while (pow2 % memalign != 0)
-     memalign >>= 1;
- 
    MEM_ATTRS (new) = get_mem_attrs (MEM_ALIAS_SET (memref), MEM_DECL (memref),
! 				   0, 0, memalign);
    return new;
  }
--- 1893,1901 ----
  			      gen_rtx_PLUS (Pmode, XEXP (memref, 0),
  					    force_reg (Pmode, offset)), 1);
  
    /* Update the alignment to reflect the offset.  Reset the offset, which
       we don't know.  */
    MEM_ATTRS (new) = get_mem_attrs (MEM_ALIAS_SET (memref), MEM_DECL (memref),
! 				   0, 0, MIN (MEM_ALIGN (memref), pow2));
    return new;
  }
*** expr.c	2001/10/18 21:34:08	1.361
--- expr.c	2001/10/19 19:04:45
*************** expand_expr (exp, target, tmode, modifie
*** 6813,6823 ****
  	set_mem_attributes (temp, exp, 0);
  
- 	/* It is incorrect to set RTX_UNCHANGING_P from TREE_READONLY
- 	   here, because, in C and C++, the fact that a location is accessed
- 	   through a pointer to const does not mean that the value there can
- 	   never change.  Languages where it can never change should
- 	   also set TREE_STATIC.  */
- 	RTX_UNCHANGING_P (temp) = TREE_READONLY (exp) & TREE_STATIC (exp);
- 
  	/* If we are writing to this object and its type is a record with
  	   readonly fields, we must mark it as readonly so it will
--- 6813,6816 ----


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