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]

[tree-ssa] remove get_base_var/get_base_decl


There was exactly one valid use of these functions, the one in set_is_used.
Even there, it might be better to use walk_tree, since we're not currently
marking the index of ARRAY_REFs.  Andrew, is that something we should be
concerned about in callers of this function?

In all other cases, we should have been handling offseting references
(COMPONENT_REF, ARRAY_REF, etc) and INDIRECT_REF differently.  Unsurprising
because their semantics are radically different.

In order to avoid further incorrect uses, I've removed the functions.

Tested on i686-linux.


r~


        * tree-simple.c (get_base_var, get_base_decl): Remove.
        * tree-simple.h: Likewise.
        * tree-dfa.c (discover_nonconstant_array_refs_r): Use get_base_address.
        * tree-ssa-alias.c (ptr_is_dereferenced_by): Likewise.
        (add_pointed_to_var, is_escape_site): Likewise.
        * tree-ssa-ccp.c (get_default_value): Expect only SSA_NAME and DECLs.
        * tree-ssa-operands.c (add_stmt_operand): Likewise.
        (note_addressable): Use get_base_address.
        * tree-ssa-dce.c (need_to_preserve_store): Expect only SSA_NAME.
        * tree-ssa.c (set_is_used): Inline get_base_decl.

Index: gcc/tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.218
diff -c -p -d -r1.1.4.218 tree-dfa.c
*** gcc/tree-dfa.c	16 Feb 2004 14:08:00 -0000	1.1.4.218
--- gcc/tree-dfa.c	11 Mar 2004 05:03:08 -0000
*************** discover_nonconstant_array_refs_r (tree 
*** 1295,1301 ****
  	t = TREE_OPERAND (t, 0);
        if (TREE_CODE (t) == ARRAY_REF)
  	{
! 	  t = get_base_decl (t);
  	  if (t && DECL_P (t))
  	    TREE_ADDRESSABLE (t) = 1;
  	}
--- 1295,1301 ----
  	t = TREE_OPERAND (t, 0);
        if (TREE_CODE (t) == ARRAY_REF)
  	{
! 	  t = get_base_address (t);
  	  if (t && DECL_P (t))
  	    TREE_ADDRESSABLE (t) = 1;
  	}
Index: gcc/tree-simple.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.c,v
retrieving revision 1.1.4.72
diff -c -p -d -r1.1.4.72 tree-simple.c
*** gcc/tree-simple.c	28 Feb 2004 01:06:20 -0000	1.1.4.72
--- gcc/tree-simple.c	11 Mar 2004 05:03:08 -0000
*************** rationalize_compound_expr (tree top)
*** 587,638 ****
    return top;
  }
  
- /* Given a GIMPLE variable or memory reference T (e.g., ID, an ARRAY_REF, an
-    INDIRECT_REF), return the base variable of T (either a _DECL or an
-    SSA_NAME).  If T is not a variable or a memory reference, NULL_TREE is
-    returned.  */
- 
- tree
- get_base_var (tree t)
- {
-   do
-     {
-       if (SSA_VAR_P (t))
- 	return t;
- 
-       switch (TREE_CODE (t))
- 	{
- 	case ARRAY_REF:
- 	case COMPONENT_REF:
- 	case REALPART_EXPR:
- 	case IMAGPART_EXPR:
- 	case INDIRECT_REF:
- 	  t = TREE_OPERAND (t, 0);
- 	  break;
- 
- 	default:
- 	  return NULL_TREE;
- 	}
-     }
-   while (t);
- 
-   return t;
- }
- 
- /* Given a GIMPLE variable or memory reference T, return the base _DECL
-    symbol.  If T is not a variable or memory reference, NULL_TREE is
-    returned.  */
- 
- tree
- get_base_decl (tree t)
- {
-   t = get_base_var (t);
-   if (t && TREE_CODE (t) == SSA_NAME)
-     return SSA_NAME_VAR (t);
- 
-   return t;
- }
- 
  /* Given a memory reference expression, return the base address.  Note that,
     in contrast with get_base_var, this will not recurse inside INDIRECT_REF
     expressions.  Therefore, given the reference PTR->FIELD, this function
--- 587,592 ----
Index: gcc/tree-simple.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.h,v
retrieving revision 1.1.4.49
diff -c -p -d -r1.1.4.49 tree-simple.h
*** gcc/tree-simple.h	20 Feb 2004 18:57:02 -0000	1.1.4.49
--- gcc/tree-simple.h	11 Mar 2004 05:03:08 -0000
*************** void push_gimplify_context (void);
*** 108,115 ****
  void pop_gimplify_context (tree);
  
  /* Miscellaneous helpers.  */
- tree get_base_decl (tree);
- tree get_base_var (tree);
  tree get_base_address (tree t);
  void gimple_add_tmp_var (tree);
  tree gimple_current_bind_expr (void);
--- 108,113 ----
Index: gcc/tree-ssa-alias.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-alias.c,v
retrieving revision 1.1.2.9
diff -c -p -d -r1.1.2.9 tree-ssa-alias.c
*** gcc/tree-ssa-alias.c	5 Mar 2004 00:18:01 -0000	1.1.2.9
--- gcc/tree-ssa-alias.c	11 Mar 2004 05:03:08 -0000
*************** ptr_is_dereferenced_by (tree ptr, tree s
*** 449,458 ****
        lhs = TREE_OPERAND (e, 0);
        rhs = TREE_OPERAND (e, 1);
  
!       return ((TREE_CODE_CLASS (TREE_CODE (lhs)) == 'r'
! 	       && get_base_var (lhs) == ptr)
! 	      || (TREE_CODE_CLASS (TREE_CODE (rhs)) == 'r'
! 	   	  && get_base_var (rhs) == ptr));
      }
  
    return false;
--- 449,468 ----
        lhs = TREE_OPERAND (e, 0);
        rhs = TREE_OPERAND (e, 1);
  
!       if (TREE_CODE_CLASS (TREE_CODE (lhs)) == 'r')
! 	{
! 	  lhs = get_base_address (lhs);
! 	  if (lhs && TREE_CODE (lhs) == INDIRECT_REF
! 	      && TREE_OPERAND (lhs, 0) == ptr)
! 	    return true;
! 	}
!       if (TREE_CODE_CLASS (TREE_CODE (rhs)) == 'r')
! 	{
! 	  rhs = get_base_address (rhs);
! 	  if (rhs && TREE_CODE (rhs) == INDIRECT_REF
! 	      && TREE_OPERAND (rhs, 0) == ptr)
! 	    return true;
! 	}
      }
  
    return false;
*************** add_pointed_to_var (struct alias_info *a
*** 1405,1411 ****
  
        pt_var = TREE_OPERAND (value, 0);
        if (TREE_CODE_CLASS (TREE_CODE (pt_var)) == 'r')
! 	pt_var = get_base_decl (pt_var);
  
        if (pt_var && SSA_VAR_P (pt_var))
  	{
--- 1415,1421 ----
  
        pt_var = TREE_OPERAND (value, 0);
        if (TREE_CODE_CLASS (TREE_CODE (pt_var)) == 'r')
! 	pt_var = get_base_address (pt_var);
  
        if (pt_var && SSA_VAR_P (pt_var))
  	{
*************** is_escape_site (tree stmt, size_t *num_c
*** 1550,1556 ****
  
        /* Get to the base of _REF nodes.  */
        if (TREE_CODE (lhs) != SSA_NAME)
! 	lhs = get_base_var (lhs);
  
        /* If we couldn't recognize the LHS of the assignment, assume that it
  	 is a non-local store.  */
--- 1560,1566 ----
  
        /* Get to the base of _REF nodes.  */
        if (TREE_CODE (lhs) != SSA_NAME)
! 	lhs = get_base_address (lhs);
  
        /* If we couldn't recognize the LHS of the assignment, assume that it
  	 is a non-local store.  */
*************** is_escape_site (tree stmt, size_t *num_c
*** 1561,1569 ****
  	 memory store.  */
        if (TREE_CODE (lhs) == SSA_NAME)
  	return false;
- 
-       if (!DECL_P (lhs))
- 	abort ();
  
        /* FIXME: LHS is not an SSA_NAME.  Even if it's an assignment to a
  	 local variables we cannot be sure if it will escape, because we
--- 1571,1576 ----
Index: gcc/tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-ccp.c,v
retrieving revision 1.1.2.145
diff -c -p -d -r1.1.2.145 tree-ssa-ccp.c
*** gcc/tree-ssa-ccp.c	28 Feb 2004 01:06:20 -0000	1.1.2.145
--- gcc/tree-ssa-ccp.c	11 Mar 2004 05:03:08 -0000
*************** get_default_value (tree var)
*** 1987,1993 ****
    value val;
    tree sym;
  
!   sym = (!DECL_P (var)) ? get_base_decl (var) : var;
  
    val.lattice_val = UNDEFINED;
    val.const_val = NULL_TREE;
--- 1987,2002 ----
    value val;
    tree sym;
  
!   if (TREE_CODE (var) == SSA_NAME)
!     sym = SSA_NAME_VAR (var);
!   else
!     {
! #ifdef ENABLE_CHECKING
!       if (!DECL_P (var))
! 	abort ();
! #endif
!       sym = var;
!     }
  
    val.lattice_val = UNDEFINED;
    val.const_val = NULL_TREE;
Index: gcc/tree-ssa-dce.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dce.c,v
retrieving revision 1.1.2.82
diff -c -p -d -r1.1.2.82 tree-ssa-dce.c
*** gcc/tree-ssa-dce.c	5 Mar 2004 20:54:47 -0000	1.1.2.82
--- gcc/tree-ssa-dce.c	11 Mar 2004 05:03:08 -0000
*************** mark_operand_necessary (tree op)
*** 270,278 ****
  /* Return true if a store to a variable needs to be preserved.  */
  
  static inline bool
! need_to_preserve_store (tree var)
  {
!   return (needs_to_live_in_memory (get_base_decl (var)));
  }
  
  
--- 270,278 ----
  /* Return true if a store to a variable needs to be preserved.  */
  
  static inline bool
! need_to_preserve_store (tree ssa_name)
  {
!   return (needs_to_live_in_memory (SSA_NAME_VAR (ssa_name)));
  }
  
  
Index: gcc/tree-ssa-operands.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-operands.c,v
retrieving revision 1.1.2.14
diff -c -p -d -r1.1.2.14 tree-ssa-operands.c
*** gcc/tree-ssa-operands.c	3 Mar 2004 00:59:48 -0000	1.1.2.14
--- gcc/tree-ssa-operands.c	11 Mar 2004 05:03:08 -0000
*************** add_stmt_operand (tree *var_p, tree stmt
*** 1156,1162 ****
    if (var == NULL_TREE || !SSA_VAR_P (var))
      return;
  
!   sym = get_base_decl (var);
    v_ann = var_ann (sym);
  
    /* FIXME: We currently refuse to optimize variables that have hidden uses
--- 1156,1162 ----
    if (var == NULL_TREE || !SSA_VAR_P (var))
      return;
  
!   sym = (TREE_CODE (var) == SSA_NAME ? SSA_NAME_VAR (var) : var);
    v_ann = var_ann (sym);
  
    /* FIXME: We currently refuse to optimize variables that have hidden uses
*************** add_stmt_operand (tree *var_p, tree stmt
*** 1268,1274 ****
  static void
  note_addressable (tree var, stmt_ann_t s_ann)
  {
!   var = get_base_decl (var);
    if (var && SSA_VAR_P (var))
      {
        if (s_ann->addresses_taken == NULL)
--- 1268,1274 ----
  static void
  note_addressable (tree var, stmt_ann_t s_ann)
  {
!   var = get_base_address (var);
    if (var && SSA_VAR_P (var))
      {
        if (s_ann->addresses_taken == NULL)
Index: gcc/tree-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa.c,v
retrieving revision 1.1.4.208
diff -c -p -d -r1.1.4.208 tree-ssa.c
*** gcc/tree-ssa.c	3 Mar 2004 13:11:54 -0000	1.1.4.208
--- gcc/tree-ssa.c	11 Mar 2004 05:03:08 -0000
*************** rewrite_stmt (struct dom_walk_data *walk
*** 3442,3448 ****
  void
  set_is_used (tree t)
  {
!   t = get_base_decl (t);
    var_ann (t)->used = 1;
  }
  
--- 3442,3470 ----
  void
  set_is_used (tree t)
  {
!   while (1)
!     {
!       if (SSA_VAR_P (t))
! 	break;
! 
!       switch (TREE_CODE (t))
! 	{
! 	case ARRAY_REF:
! 	case COMPONENT_REF:
! 	case REALPART_EXPR:
! 	case IMAGPART_EXPR:
! 	case INDIRECT_REF:
! 	  t = TREE_OPERAND (t, 0);
! 	  break;
! 
! 	default:
! 	  return;
! 	}
!     }
! 
!   if (TREE_CODE (t) == SSA_NAME)
!     t = SSA_NAME_VAR (t);
! 
    var_ann (t)->used = 1;
  }
  


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