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] Fix variables getting out of their scope


Hello,

> >>Not really -- not every BIND_EXPR has a BIND_EXPR_BLOCK.
> >>
> >Ah, yes.  In that case the patch is OK.
> >
> 
> Actually, Zdenek, if it's not too much trouble, could you update 
> bsi_move_* to make it reset the scope on the moved statement to the 
> proper new scope?
> That way when you move a statement, you can just call fixup_var_scopes 
> on the defined variable with the old scope, and it'll do the right 
> thing.

this (untested) should make what you want.  On the other hand, I
consider all of this a temporary hack before some better solution
what to do with BIND_EXPRs is devised.

Some ideas what to do with them?  It would be nice if we could shomehow
get rid of them before more radical changes from tree-ssa-cfg are
merged, as they bring nothing but problems.

Zdenek

Index: tree-ssa-copyprop.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-copyprop.c,v
retrieving revision 1.1.2.12
diff -c -3 -p -r1.1.2.12 tree-ssa-copyprop.c
*** tree-ssa-copyprop.c	19 Aug 2003 19:03:24 -0000	1.1.2.12
--- tree-ssa-copyprop.c	20 Aug 2003 19:44:34 -0000
*************** fixup_var_scope (tree var, tree scope)
*** 256,261 ****
--- 256,285 ----
      }
  }
  
+ /* Fixes scopes of all variables in statement STMT.  */
+ void
+ fixup_var_scopes (tree stmt)
+ {
+   varray_type refs[2];
+   tree *ref_p;
+   tree scope = stmt_ann (stmt)->scope;
+   int i, j;
+ 
+   get_stmt_operands (stmt);
+ 
+   refs[0] = use_ops (stmt);
+   refs[1] = def_ops (stmt);
+ 
+   for (j = 0; j < 2; j++)
+     for (i = 0; refs[j] && i < VARRAY_ACTIVE_SIZE (refs[j]); i++)
+       {
+ 	ref_p = (tree *) VARRAY_GENERIC_PTR (refs[j], i);
+ 
+ 	if (TREE_CODE (*ref_p) == SSA_NAME)
+ 	  fixup_var_scope (*ref_p, scope);
+       }
+ }
+ 
  /* Moves variable VAR from OLD_SCOPE to SCOPE.  */
  static void
  move_var_to_scope (tree var, tree old_scope, tree scope)
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.105
diff -c -3 -p -r1.1.4.105 tree-flow.h
*** tree-flow.h	19 Aug 2003 19:03:24 -0000	1.1.4.105
--- tree-flow.h	20 Aug 2003 19:44:36 -0000
*************** void tree_ssa_dce (tree);
*** 505,510 ****
--- 506,512 ----
  void tree_ssa_copyprop (tree);
  void propagate_copy (tree *, tree, tree);
  void fixup_var_scope (tree, tree);
+ void fixup_var_scopes (tree);
  
  /* In tree-flow-inline.h  */
  static inline int phi_arg_from_edge (tree, edge);
Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-cfg.c,v
retrieving revision 1.1.4.152
diff -c -3 -p -r1.1.4.152 tree-cfg.c
*** tree-cfg.c	19 Aug 2003 19:03:24 -0000	1.1.4.152
--- tree-cfg.c	20 Aug 2003 19:44:40 -0000
*************** bsi_replace (block_stmt_iterator bsi, tr
*** 2190,2199 ****
  
    replace_stmt (bsi.tp, &stmt);
    modify_stmt (bsi_stmt (bsi));
  }
  
- 
- 
  /* Remove statement *STMT_P.
  
     Update all references associated with it.  Note that this function will
--- 2086,2094 ----
  
    replace_stmt (bsi.tp, &stmt);
    modify_stmt (bsi_stmt (bsi));
+   fixup_var_scopes (bsi_stmt (bsi));
  }
  
  /* Remove statement *STMT_P.
  
     Update all references associated with it.  Note that this function will
*************** bsi_insert_after (block_stmt_iterator *c
*** 3904,3909 ****
--- 3690,3696 ----
  
    /* Now update the required SSA bits.  */
    modify_stmt (inserted_stmt);
+   fixup_var_scopes (inserted_stmt);
  
    return;
  }
*************** bsi_insert_before (block_stmt_iterator *
*** 3988,3993 ****
--- 3767,3773 ----
  
    /* Now update the required SSA bits.  */
    modify_stmt (inserted_stmt);
+   fixup_var_scopes (inserted_stmt);
  
    return;
  }


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