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]

New tree code: ARRAY_RANGE_REF


This is the same as ARRAY_REF except that the result's type is also an
array.  It represents a range ("slice") of array elements starting at
the one given by the index and whose length is determined by the type
of the ARRAY_RANGE_REF.

Tested on alphaev56.

Mon Jun  4 09:21:19 2001  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* tree.def (ARRAY_RANGE_REF): New code.
	* alias.c (handled_component_p, can_address_p): Handle it.
	* dwarf2out.c (loc_descriptor_from_tree): Likewise.
	* explow.c (set_mem_attributes): Likewise.
	* expr.c (expand_assignment, get_inner_reference): Likewise.
	(expand_expr, expand_expr_unaligned, do_jump): Likewise.
	* fold-const.c (operand_equal_p): Likewise.
	* tree.c (staticp, stabilize_reference): Likewise.
	* varasm.c (decode_addr_const): Likewise.

*** tree.def	2001/03/28 11:04:07	1.38
--- tree.def	2001/06/04 10:54:32
*************** DEFTREECODE (INDIRECT_REF, "indirect_ref
*** 370,376 ****
  DEFTREECODE (BUFFER_REF, "buffer_ref", 'r', 1)
  
! /* Array indexing in languages other than C.
     Operand 0 is the array; operand 1 is a (single) array index. */
  DEFTREECODE (ARRAY_REF, "array_ref", 'r', 2)
  
  /* Constructor: return an aggregate value made from specified components.
--- 371,382 ----
  DEFTREECODE (BUFFER_REF, "buffer_ref", 'r', 1)
  
! /* Array indexing.
     Operand 0 is the array; operand 1 is a (single) array index. */
  DEFTREECODE (ARRAY_REF, "array_ref", 'r', 2)
+ 
+ /* Likewise, except that the result is a range of the array.  The starting
+    index of the array is taken from operand 0 and the size of the range
+    is taken from the type of the expression.  */
+ DEFTREECODE (ARRAY_RANGE_REF, "array_range_ref", 'r', 2)
  
  /* Constructor: return an aggregate value made from specified components.
*** alias.c	2001/04/09 14:27:00	1.122
--- alias.c	2001/06/04 10:54:03
*************** handled_component_p (t)
*** 413,416 ****
--- 413,417 ----
      case COMPONENT_REF:
      case ARRAY_REF:
+     case ARRAY_RANGE_REF:
      case NON_LVALUE_EXPR:
        return 1;
*************** can_address_p (t)
*** 446,450 ****
      return 1;
  
!   else if (TREE_CODE (t) == ARRAY_REF
  	   && ! TYPE_NONALIASED_COMPONENT (TREE_TYPE (TREE_OPERAND (t, 0)))
  	   && can_address_p (TREE_OPERAND (t, 0)))
--- 447,451 ----
      return 1;
  
!   else if ((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
  	   && ! TYPE_NONALIASED_COMPONENT (TREE_TYPE (TREE_OPERAND (t, 0)))
  	   && can_address_p (TREE_OPERAND (t, 0)))
*** dwarf2out.c	2001/05/31 01:13:43	1.274
--- dwarf2out.c	2001/06/04 10:54:12
*************** loc_descriptor_from_tree (loc, addressp)
*** 7593,7596 ****
--- 7593,7597 ----
      case BIT_FIELD_REF:
      case ARRAY_REF:
+     case ARRAY_RANGE_REF:
        {
  	tree obj, offset;
*** explow.c	2001/05/01 12:11:31	1.61
--- explow.c	2001/06/04 10:54:13
*************** set_mem_attributes (ref, t, objectp)
*** 703,706 ****
--- 703,707 ----
      MEM_SCALAR_P (ref) = 1;
    else if (TREE_CODE (t) == COMPONENT_REF || TREE_CODE (t) == ARRAY_REF
+ 	   || TREE_CODE (t) == ARRAY_RANGE_REF
  	   || TREE_CODE (t) == BIT_FIELD_REF)
      MEM_IN_STRUCT_P (ref) = 1;
*** expr.c	2001/06/02 10:54:32	1.321
--- expr.c	2001/06/04 10:54:21
*************** expand_assignment (to, from, want_value,
*** 3676,3680 ****
  
    if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
!       || TREE_CODE (to) == ARRAY_REF)
      {
        enum machine_mode mode1;
--- 3676,3680 ----
  
    if (TREE_CODE (to) == COMPONENT_REF || TREE_CODE (to) == BIT_FIELD_REF
!       || TREE_CODE (to) == ARRAY_REF || TREE_CODE (to) == ARRAY_RANGE_REF)
      {
        enum machine_mode mode1;
*************** store_field (target, bitsize, bitpos, mo
*** 5334,5339 ****
  
  /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
!    or an ARRAY_REF, look for nested COMPONENT_REFs, BIT_FIELD_REFs, or
!    ARRAY_REFs and find the ultimate containing object, which we return.
  
     We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
--- 5334,5339 ----
  
  /* Given an expression EXP that may be a COMPONENT_REF, a BIT_FIELD_REF,
!    an ARRAY_REF, or an ARRAY_RANGE_REF, look for nested operations of these
!    codes and find the ultimate containing object, which we return.
  
     We set *PBITSIZE to the size in bits that we want, *PBITPOS to the
*************** get_inner_reference (exp, pbitsize, pbit
*** 5439,5448 ****
  	}
  
!       else if (TREE_CODE (exp) == ARRAY_REF)
  	{
  	  tree index = TREE_OPERAND (exp, 1);
! 	  tree domain = TYPE_DOMAIN (TREE_TYPE (TREE_OPERAND (exp, 0)));
  	  tree low_bound = (domain ? TYPE_MIN_VALUE (domain) : 0);
! 	  tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (exp));
  
  	  /* We assume all arrays have sizes that are a multiple of a byte.
--- 5439,5450 ----
  	}
  
!       else if (TREE_CODE (exp) == ARRAY_REF
! 	       || TREE_CODE (exp) == ARRAY_RANGE_REF)
  	{
  	  tree index = TREE_OPERAND (exp, 1);
! 	  tree array = TREE_OPERAND (exp, 0);
! 	  tree domain = TYPE_DOMAIN (TREE_TYPE (array));
  	  tree low_bound = (domain ? TYPE_MIN_VALUE (domain) : 0);
! 	  tree unit_size = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (array)));
  
  	  /* We assume all arrays have sizes that are a multiple of a byte.
*************** get_inner_reference (exp, pbitsize, pbit
*** 5462,5467 ****
  	  if (! TREE_CONSTANT (unit_size)
  	      && contains_placeholder_p (unit_size))
! 	    unit_size = build (WITH_RECORD_EXPR, sizetype, unit_size,
! 			       TREE_OPERAND (exp, 0));
  
  	  offset = size_binop (PLUS_EXPR, offset,
--- 5464,5468 ----
  	  if (! TREE_CONSTANT (unit_size)
  	      && contains_placeholder_p (unit_size))
! 	    unit_size = build (WITH_RECORD_EXPR, sizetype, unit_size, array);
  
  	  offset = size_binop (PLUS_EXPR, offset,
*************** expand_expr (exp, target, tmode, modifie
*** 6151,6154 ****
--- 6157,6161 ----
        && TREE_CODE (exp) != PARM_DECL
        && TREE_CODE (exp) != ARRAY_REF
+       && TREE_CODE (exp) != ARRAY_RANGE_REF
        && TREE_CODE (exp) != COMPONENT_REF
        && TREE_CODE (exp) != BIT_FIELD_REF
*************** expand_expr (exp, target, tmode, modifie
*** 6169,6172 ****
--- 6176,6180 ----
        && TREE_CODE (exp) != PARM_DECL
        && TREE_CODE (exp) != ARRAY_REF
+       && TREE_CODE (exp) != ARRAY_RANGE_REF
        && TREE_CODE (exp) != COMPONENT_REF
        && TREE_CODE (exp) != BIT_FIELD_REF
*************** expand_expr (exp, target, tmode, modifie
*** 6907,6915 ****
      case COMPONENT_REF:
      case BIT_FIELD_REF:
        /* If the operand is a CONSTRUCTOR, we can just extract the
  	 appropriate field if it is present.  Don't do this if we have
  	 already written the data since we want to refer to that copy
  	 and varasm.c assumes that's what we'll do.  */
!       if (code != ARRAY_REF
  	  && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
  	  && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
--- 6915,6924 ----
      case COMPONENT_REF:
      case BIT_FIELD_REF:
+     case ARRAY_RANGE_REF:
        /* If the operand is a CONSTRUCTOR, we can just extract the
  	 appropriate field if it is present.  Don't do this if we have
  	 already written the data since we want to refer to that copy
  	 and varasm.c assumes that's what we'll do.  */
!       if (code == COMPONENT_REF
  	  && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
  	  && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
*************** expand_expr_unaligned (exp, palign)
*** 8947,8955 ****
      case COMPONENT_REF:
      case BIT_FIELD_REF:
        /* If the operand is a CONSTRUCTOR, we can just extract the
  	 appropriate field if it is present.  Don't do this if we have
  	 already written the data since we want to refer to that copy
  	 and varasm.c assumes that's what we'll do.  */
!       if (TREE_CODE (exp) != ARRAY_REF
  	  && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
  	  && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
--- 8959,8968 ----
      case COMPONENT_REF:
      case BIT_FIELD_REF:
+     case ARRAY_RANGE_REF:
        /* If the operand is a CONSTRUCTOR, we can just extract the
  	 appropriate field if it is present.  Don't do this if we have
  	 already written the data since we want to refer to that copy
  	 and varasm.c assumes that's what we'll do.  */
!       if (TREE_CODE (exp) == COMPONENT_REF
  	  && TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR
  	  && TREE_CST_RTL (TREE_OPERAND (exp, 0)) == 0)
*************** do_jump (exp, if_false_label, if_true_la
*** 9523,9527 ****
        if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
  	  || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
! 	  || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF)
  	goto normal;
      case CONVERT_EXPR:
--- 9536,9541 ----
        if (TREE_CODE (TREE_OPERAND (exp, 0)) == COMPONENT_REF
  	  || TREE_CODE (TREE_OPERAND (exp, 0)) == BIT_FIELD_REF
! 	  || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_REF
! 	  || TREE_CODE (TREE_OPERAND (exp, 0)) == ARRAY_RANGE_REF)
  	goto normal;
      case CONVERT_EXPR:
*************** do_jump (exp, if_false_label, if_true_la
*** 9629,9632 ****
--- 9643,9647 ----
      case BIT_FIELD_REF:
      case ARRAY_REF:
+     case ARRAY_RANGE_REF:
        {
  	HOST_WIDE_INT bitsize, bitpos;
*** fold-const.c	2001/05/21 01:21:22	1.157
--- fold-const.c	2001/06/04 10:54:27
*************** operand_equal_p (arg0, arg1, only_const)
*** 2397,2400 ****
--- 2397,2401 ----
  	case COMPONENT_REF:
  	case ARRAY_REF:
+ 	case ARRAY_RANGE_REF:
  	  return (operand_equal_p (TREE_OPERAND (arg0, 0),
  				   TREE_OPERAND (arg1, 0), 0)
*** tree.c	2001/05/22 03:03:26	1.195
--- tree.c	2001/06/04 10:54:31
*************** staticp (arg)
*** 1519,1522 ****
--- 1519,1523 ----
  
      case ARRAY_REF:
+     case ARRAY_RANGE_REF:
        if (TREE_CODE (TYPE_SIZE (TREE_TYPE (arg))) == INTEGER_CST
  	  && TREE_CODE (TREE_OPERAND (arg, 1)) == INTEGER_CST)
*************** stabilize_reference (ref)
*** 2206,2209 ****
--- 2207,2216 ----
      case ARRAY_REF:
        result = build_nt (ARRAY_REF,
+ 			 stabilize_reference (TREE_OPERAND (ref, 0)),
+ 			 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
+       break;
+ 
+     case ARRAY_RANGE_REF:
+       result = build_nt (ARRAY_RANGE_REF,
  			 stabilize_reference (TREE_OPERAND (ref, 0)),
  			 stabilize_reference_1 (TREE_OPERAND (ref, 1)));
*** varasm.c	2001/05/17 18:12:27	1.175
--- varasm.c	2001/06/04 10:54:35
*************** decode_addr_const (exp, value)
*** 2181,2185 ****
  	  target = TREE_OPERAND (target, 0);
  	}
!       else if (TREE_CODE (target) == ARRAY_REF)
  	{
  	  offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
--- 2181,2186 ----
  	  target = TREE_OPERAND (target, 0);
  	}
!       else if (TREE_CODE (target) == ARRAY_REF
! 	       || TREE_CODE (target) == ARRAY_RANGE_REF)
  	{
  	  offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)


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