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]

Re: [tree-ssa] Make sure operands and virtual operands don't mix[patch]


On Tue, 2003-09-09 at 19:20, Andrew MacLeod wrote:

> I suspect you'll still get most of them. If you wanna be really sure,
> create 2 vectors... one for real uses and one for virtual uses... At the
> end of creating the map, AND the 2 vectors together and it *ought* to
> result in a zero vector... Anything else flags something used as both...
> 
Here's the patch I've committed.  Thanks for the suggestion.


Diego.

	* tree-dfa.c (add_referenced_var): Handle cases when argument
	walk_state is NULL.
	(add_referenced_tmp_var): New function.
	* tree-flow.h (add_referenced_tmp_var): Declare it.
	* tree-ssa-pre.c (pre_expression): Call it.
	* tree-ssa-live.c (create_ssa_var_map): Add checking for variables
	being in real and virtual operands.

Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.156
diff -d -c -p -r1.1.4.156 tree-dfa.c
*** tree-dfa.c	6 Sep 2003 13:39:24 -0000	1.1.4.156
--- tree-dfa.c	9 Sep 2003 23:44:22 -0000
*************** static void
*** 2481,2487 ****
  add_referenced_var (tree var, struct walk_state *walk_state)
  {
    void **slot;
-   htab_t vars_found = walk_state->vars_found;
    var_ann_t v_ann;
  
    v_ann = get_var_ann (var);
--- 2491,2496 ----
*************** add_referenced_var (tree var, struct wal
*** 2491,2505 ****
    if (v_ann->has_hidden_use)
      return;
  
!   slot = htab_find_slot (vars_found, (void *) var, INSERT);
!   if (*slot == NULL)
      {
        bool is_addressable;
  
        /* This is the first time we find this variable, add it to the
           REFERENCED_VARS array and annotate it with attributes that are
  	 intrinsic to the variable.  */
!       *slot = (void *) var;
        v_ann->uid = num_referenced_vars;
        VARRAY_PUSH_TREE (referenced_vars, var);
  
--- 2500,2519 ----
    if (v_ann->has_hidden_use)
      return;
  
!   if (walk_state)
!     slot = htab_find_slot (walk_state->vars_found, (void *) var, INSERT);
!   else
!     slot = NULL;
! 
!   if (slot == NULL || *slot == NULL)
      {
        bool is_addressable;
  
        /* This is the first time we find this variable, add it to the
           REFERENCED_VARS array and annotate it with attributes that are
  	 intrinsic to the variable.  */
!       if (slot)
! 	*slot = (void *) var;
        v_ann->uid = num_referenced_vars;
        VARRAY_PUSH_TREE (referenced_vars, var);
  
*************** add_referenced_var (tree var, struct wal
*** 2546,2551 ****
--- 2560,2567 ----
      }
  
    /* Now, set attributes that depend on WALK_STATE.  */
+   if (walk_state == NULL)
+     return;
  
    /* Remember if the variable has been written to.  This is important for
       alias analysis.  If a variable and its aliases are never modified, it
*************** create_global_var (void)
*** 2787,2792 ****
--- 2803,2822 ----
    DECL_CONTEXT (global_var) = current_function_decl;
    TREE_THIS_VOLATILE (global_var) = 1;
    TREE_ADDRESSABLE (global_var) = 0;
+ }
+ 
+ 
+ /* Add a temporary variable to REFERENCED_VARS.  This is similar to
+    add_referenced_var, but is used by passes that need to add new temps to
+    the REFERENCED_VARS array after the program has been scanned for
+    variables.  In particular, none of the annotations that depend on struct
+    walk_state will be set.  The variable will just receive a new UID and be
+    added to the REFERENCED_VARS array without checking for duplicates.  */
+ 
+ void
+ add_referenced_tmp_var (tree var)
+ {
+   add_referenced_var (var, NULL);
  }
  
  #include "gt-tree-dfa.h"
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.110
diff -d -c -p -r1.1.4.110 tree-flow.h
*** tree-flow.h	9 Sep 2003 22:04:42 -0000	1.1.4.110
--- tree-flow.h	9 Sep 2003 23:44:23 -0000
*************** extern void debug_alias_info (void);
*** 468,473 ****
--- 468,474 ----
  extern tree get_virtual_var (tree);
  extern void add_vuse (tree, tree, voperands_t);
  extern void create_global_var (void);
+ extern void add_referenced_tmp_var (tree var);
  
  /* Flags used when computing reaching definitions and reached uses.  */
  #define TDFA_USE_OPS		1 << 0
Index: tree-ssa-live.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-live.c,v
retrieving revision 1.1.2.16
diff -d -c -p -r1.1.2.16 tree-ssa-live.c
*** tree-ssa-live.c	6 Sep 2003 13:39:24 -0000	1.1.2.16
--- tree-ssa-live.c	9 Sep 2003 23:44:27 -0000
*************** create_ssa_var_map (void)
*** 324,332 ****
--- 324,344 ----
    varray_type ops;
    unsigned x;
    var_map map;
+ #if defined ENABLE_CHECKING
+   sbitmap used_in_real_ops;
+   sbitmap used_in_virtual_ops;
+ #endif
  
    map = init_var_map (next_ssa_version + 1);
  
+ #if defined ENABLE_CHECKING
+   used_in_real_ops = sbitmap_alloc (num_referenced_vars);
+   sbitmap_zero (used_in_real_ops);
+ 
+   used_in_virtual_ops = sbitmap_alloc (num_referenced_vars);
+   sbitmap_zero (used_in_virtual_ops);
+ #endif
+ 
    FOR_EACH_BB (bb)
      {
        for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
*************** create_ssa_var_map (void)
*** 340,345 ****
--- 352,360 ----
  	    {
  	      use = VARRAY_TREE_PTR (ops, x);
  	      register_ssa_partition (map, *use);
+ #if defined ENABLE_CHECKING
+ 	      SET_BIT (used_in_real_ops, var_ann (SSA_NAME_VAR (*use))->uid);
+ #endif
  	    }
  
  	  ops = def_ops (stmt);
*************** create_ssa_var_map (void)
*** 347,352 ****
--- 362,370 ----
  	    {
  	      dest = VARRAY_TREE_PTR (ops, x);
  	      register_ssa_partition (map, *dest);
+ #if defined ENABLE_CHECKING
+ 	      SET_BIT (used_in_real_ops, var_ann (SSA_NAME_VAR (*dest))->uid);
+ #endif
  	    }
  
  	  /* While we do not care about virtual operands for
*************** create_ssa_var_map (void)
*** 354,366 ****
  	     we mark all the variables which are used.  */
  	  ops = vuse_ops (stmt);
  	  for (x = 0; ops && x < VARRAY_ACTIVE_SIZE (ops); x++)
! 	    set_is_used (VARRAY_TREE (ops, x));
  
  	  ops = vdef_ops (stmt);
  	  for (x = 0; ops && x < VARRAY_ACTIVE_SIZE (ops); x++)
! 	    set_is_used (VDEF_OP (VARRAY_TREE (ops, x)));
  	}
      }
  
    return map;
  }
--- 372,415 ----
  	     we mark all the variables which are used.  */
  	  ops = vuse_ops (stmt);
  	  for (x = 0; ops && x < VARRAY_ACTIVE_SIZE (ops); x++)
! 	    {
! 	      tree var = VARRAY_TREE (ops, x);
! 	      set_is_used (var);
! #if defined ENABLE_CHECKING
! 	      SET_BIT (used_in_virtual_ops, var_ann (SSA_NAME_VAR (var))->uid);
! #endif
! 	    }
  
  	  ops = vdef_ops (stmt);
  	  for (x = 0; ops && x < VARRAY_ACTIVE_SIZE (ops); x++)
! 	    {
! 	      tree var = VDEF_OP (VARRAY_TREE (ops, x));
! 	      set_is_used (var);
! #if defined ENABLE_CHECKING
! 	      SET_BIT (used_in_virtual_ops, var_ann (SSA_NAME_VAR (var))->uid);
! #endif
! 	    }
  	}
      }
+ 
+ #if defined ENABLE_CHECKING
+   {
+     unsigned i;
+     sbitmap both = sbitmap_alloc (num_referenced_vars);
+     sbitmap_a_and_b (both, used_in_real_ops, used_in_virtual_ops);
+     if (sbitmap_first_set_bit (both) >= 0)
+       {
+ 	EXECUTE_IF_SET_IN_SBITMAP (both, 0, i,
+ 	  fprintf (stderr, "Variable %s used in real and virtual operands\n",
+ 		   get_name (referenced_var (i))));
+ 	abort ();
+       }
+ 
+     sbitmap_free (used_in_real_ops);
+     sbitmap_free (used_in_virtual_ops);
+     sbitmap_free (both);
+   }
+ #endif
  
    return map;
  }
Index: tree-ssa-pre.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-pre.c,v
retrieving revision 1.1.4.78
diff -d -c -p -r1.1.4.78 tree-ssa-pre.c
*** tree-ssa-pre.c	6 Sep 2003 13:39:24 -0000	1.1.4.78
--- tree-ssa-pre.c	9 Sep 2003 23:44:30 -0000
*************** pre_expression (struct expr_info *slot, 
*** 2682,2688 ****
      return 0;
  
    ei->temp = create_tmp_var (TREE_TYPE (ei->expr), "pretmp");
!   create_var_ann (ei->temp);
    bitmap_clear (created_phi_preds);
    if (!expr_phi_insertion ((bitmap *)data, ei))
      goto cleanup;
--- 2682,2688 ----
      return 0;
  
    ei->temp = create_tmp_var (TREE_TYPE (ei->expr), "pretmp");
!   add_referenced_tmp_var (ei->temp);
    bitmap_clear (created_phi_preds);
    if (!expr_phi_insertion ((bitmap *)data, ei))
      goto cleanup;


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