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]

[ast-optimizer-branch]: Make simplified variable names have descriptiveprefix


With this patch, when we can easily figure it out, we prefix the temporary 
variable with the name of what it's going to store, or where it came from.


I.E.

Rather than

int T.238;
int _va;

T.238 = _va;
<..... enough that you forget what the heck T.238 was for>
T.238.blah.blah  = 5;

it'll say

int _va.238;
int _va;

_va.238 = _va;
<.......>
_va.238.blah.blah = 5;


To make debugging a little easier, we also prefix temporaries created 
during if condition simplification with "iftmp", and temporaries created 
during boolean expression simplification with "booltmp".


This only really matters for simplifications that end up getting pretty 
large, and you have to keep jumping around from page to page to see 
what/where something came from.

I stole strip_off_ending from toplev.c and made it static rather than use 
it externally, since callers use it on filenames, and i don't want to 
cause problems with *our* use (which is for variable names) if it's 
changed somehow.

Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.2.15
diff -c -3 -p -w -B -b -r1.1.2.15 c-simplify.c
*** c-simplify.c	2 May 2002 19:42:00 -0000	1.1.2.15
--- c-simplify.c	4 May 2002 02:31:28 -0000
*************** static tree simplify_cond_expr       PAR
*** 71,76 ****
--- 71,77 ----
  static tree simplify_modify_expr     PARAMS ((const tree, tree *, tree *));
  static tree simplify_boolean_expr    PARAMS ((const tree, tree *, tree *));
  static tree simplify_compound_expr   PARAMS ((const tree, tree *, tree *));
+ static tree simplify_stmt_expr       PARAMS ((const tree, tree *, tree *));
  static tree simplify_save_expr       PARAMS ((const tree, tree *, tree *,
                                                int (*) PARAMS ((tree)), int));
  static tree simplify_expr_wfl        PARAMS ((const tree, tree *, tree *,
*************** static tree tree_last_decl           PAR
*** 83,92 ****
--- 84,115 ----
  static tree convert_to_stmt_chain    PARAMS ((tree, tree));
  static int  stmt_has_effect          PARAMS ((tree));
  static int  expr_has_effect          PARAMS ((tree));
+ static inline void strip_off_ending  PARAMS ((char *, int));
  
  /* }}} */
  
  
+ /* Strip off a legitimate source ending from the input string NAME of
+    length LEN.  Rather than having to know the names used by all of
+    our front ends, we strip off an ending of a period followed by
+    up to five characters.  (Java uses ".class".)  */
+ 
+ static inline void
+ strip_off_ending (name, len)
+      char *name;
+      int len;
+ {
+   int i;
+   for (i = 2;  i < 6 && len > i;  i++)
+     {
+       if (name[len - i] == '.')
+ 	{
+ 	  name[len - i] = '\0';
+ 	  break;
+ 	}
+     }
+ }
+ 
  /* Simplification of statement trees.  */
  
  /** {{{ simplify_tree ()
*************** simplify_expr (expr, pre_p, post_p, simp
*** 933,938 ****
--- 955,962 ----
  {
    enum tree_code code;
    tree expr_s, tmp, type;
+   const char *prefix = NULL;
+   tree stripped_decl;
  
    if (expr == NULL_TREE)
      abort ();
*************** simplify_expr (expr, pre_p, post_p, simp
*** 1147,1158 ****
        abort ();
      }
  
    if (!needs_lvalue)
      {
        /* The original expression is not an lvalue, create a new temporary
  	 variable T, emit 'T = EXPR_S' and return T.  */
        type = TREE_TYPE (expr_s);
!       tmp = create_tmp_var (type);
        add_tree (build_modify_expr (tmp, NOP_EXPR, expr_s), pre_p);
        expr_s = tmp;
      }
--- 1172,1187 ----
        abort ();
      }
  
+   stripped_decl = expr_s;
+   STRIP_NOPS (stripped_decl);
+   if (DECL_P (stripped_decl))
+     prefix = IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
    if (!needs_lvalue)
      {
        /* The original expression is not an lvalue, create a new temporary
  	 variable T, emit 'T = EXPR_S' and return T.  */
        type = TREE_TYPE (expr_s);
!       tmp = create_tmp_var (type, prefix);
        add_tree (build_modify_expr (tmp, NOP_EXPR, expr_s), pre_p);
        expr_s = tmp;
      }
*************** simplify_expr (expr, pre_p, post_p, simp
*** 1166,1172 ****
  	{
  	  /* If the expression is a pointer already, there is no need to
  	     take the address of the expression.  */
! 	  tmp = create_tmp_var (type);
  	  add_tree (build_modify_expr (tmp, NOP_EXPR, expr_s), pre_p);
  	  expr_s = tmp;
  	}
--- 1195,1201 ----
  	{
  	  /* If the expression is a pointer already, there is no need to
  	     take the address of the expression.  */
! 	  tmp = create_tmp_var (type, prefix);
  	  add_tree (build_modify_expr (tmp, NOP_EXPR, expr_s), pre_p);
  	  expr_s = tmp;
  	}
*************** simplify_expr (expr, pre_p, post_p, simp
*** 1174,1183 ****
  	{
  	  /* If the expression is an indirect reference, the address we
  	     need is the actual reference.  */
! 	  type = TREE_TYPE (TREE_OPERAND (expr_s, 0));
! 	  tmp = create_tmp_var (type);
! 	  add_tree (build_modify_expr (tmp, NOP_EXPR, TREE_OPERAND (expr_s, 0)),
! 	            pre_p);
  	  TREE_OPERAND (expr_s, 0) = tmp;
  	}
        else
--- 1203,1216 ----
  	{
  	  /* If the expression is an indirect reference, the address we
  	     need is the actual reference.  */
! 	  tree op0 = TREE_OPERAND (expr_s, 0);
! 	  stripped_decl = op0;
! 	  STRIP_NOPS (stripped_decl);
! 	  if (DECL_P (stripped_decl))
! 	    prefix = IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
! 	  type = TREE_TYPE (op0);
! 	  tmp = create_tmp_var (type, prefix);
! 	  add_tree (build_modify_expr (tmp, NOP_EXPR, op0), pre_p);
  	  TREE_OPERAND (expr_s, 0) = tmp;
  	}
        else
*************** simplify_expr (expr, pre_p, post_p, simp
*** 1185,1191 ****
  	  /* Take the address of the simplified expression and return a
  	     reference to it.  */
  	  type = build_pointer_type (type);
! 	  tmp = create_tmp_var (type);
  	  add_tree (build_modify_expr (tmp, NOP_EXPR,
  		                       build1 (ADDR_EXPR, type, expr_s)),
                      pre_p);
--- 1218,1224 ----
  	  /* Take the address of the simplified expression and return a
  	     reference to it.  */
  	  type = build_pointer_type (type);
! 	  tmp = create_tmp_var (type, prefix);
  	  add_tree (build_modify_expr (tmp, NOP_EXPR,
  		                       build1 (ADDR_EXPR, type, expr_s)),
                      pre_p);
*************** simplify_cond_expr (expr, pre_p, post_p)
*** 1487,1493 ****
    expr_type = TREE_TYPE (expr);
  
    if (!VOID_TYPE_P (expr_type))
!     tmp = create_tmp_var (TREE_TYPE (expr));
    else
      tmp = void_zero_node;
  
--- 1520,1526 ----
    expr_type = TREE_TYPE (expr);
  
    if (!VOID_TYPE_P (expr_type))
!     tmp = create_tmp_var (TREE_TYPE (expr), "iftmp");
    else
      tmp = void_zero_node;
  
*************** simplify_boolean_expr (expr, pre_p, post
*** 1621,1627 ****
       temporary.  */
    lhs = simplify_expr (TREE_OPERAND (expr, 0), pre_p, post_p, 
                         is_simple_condexpr, 0);
!   t = create_tmp_var (TREE_TYPE (expr));
    add_tree (build_modify_expr (t, NOP_EXPR, lhs), pre_p);
  
    /* Build the body for the if() statement that conditionally evaluates the
--- 1654,1660 ----
       temporary.  */
    lhs = simplify_expr (TREE_OPERAND (expr, 0), pre_p, post_p, 
                         is_simple_condexpr, 0);
!   t = create_tmp_var (TREE_TYPE (expr), "booltmp");
    add_tree (build_modify_expr (t, NOP_EXPR, lhs), pre_p);
  
    /* Build the body for the if() statement that conditionally evaluates the
*************** insert_before_first (t, body)
*** 2112,2129 ****
  
  /** {{{ create_tmp_var ()
  
!    Create a new temporary variable declaration of type TYPE.  Returns the
     newly created decl and pushes it into the current binding.  */
  
  tree
! create_tmp_var (type)
       tree type;
  {
    static unsigned int id_num = 1;
    char *tmp_name;
    tree tmp_var;
! 
!   ASM_FORMAT_PRIVATE_NAME (tmp_name, "T", id_num++);
  
    /* If the type is an array, use TYPE_POINTER_TO to create a valid pointer
       that can be used in the LHS of an assignment.  */
--- 2231,2257 ----
  
  /** {{{ create_tmp_var ()
  
!    Create a new temporary variable declaration of type TYPE, 
!    prefixing the name with PREFIX, if it's not NULL..  Returns the
     newly created decl and pushes it into the current binding.  */
  
  tree
! create_tmp_var (type, prefix)
       tree type;
+      const char *prefix;
  {
    static unsigned int id_num = 1;
    char *tmp_name;
+   char *preftmp = NULL;
    tree tmp_var;
!   /* prefix[0] != 0 to avoid an allocated string that happens to only contain a  NULL */
!   if (prefix)
!     {
!       preftmp = strdup (prefix); 
!       strip_off_ending (preftmp, strlen (preftmp));
!       prefix = preftmp;
!     }
!   ASM_FORMAT_PRIVATE_NAME (tmp_name, (prefix ? prefix : "T"), id_num++);
  
    /* If the type is an array, use TYPE_POINTER_TO to create a valid pointer
       that can be used in the LHS of an assignment.  */
*************** create_tmp_var (type)
*** 2146,2152 ****
    TREE_USED (tmp_var) = 1;
  
    pushdecl (tmp_var);
! 
    return tmp_var;
  }
  
--- 2274,2281 ----
    TREE_USED (tmp_var) = 1;
  
    pushdecl (tmp_var);
!   if (preftmp)
!     free (preftmp);
    return tmp_var;
  }
  
Index: tree-simple.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.h,v
retrieving revision 1.1.2.7
diff -c -3 -p -w -B -b -r1.1.2.7 tree-simple.h
*** tree-simple.h	27 Apr 2002 22:54:22 -0000	1.1.2.7
--- tree-simple.h	4 May 2002 02:31:28 -0000
*************** Boston, MA 02111-1307, USA.  */
*** 25,31 ****
  /* Interface used in [break/goto]-elimination: to be declared in a .h file. */
  extern void insert_before_continue_end PARAMS ((tree, tree, int));
  extern void tree_build_scope           PARAMS ((tree *));
! extern tree create_tmp_var             PARAMS ((tree));
  extern tree declare_tmp_vars           PARAMS ((tree, tree));
  extern tree deep_copy_list             PARAMS ((tree));
  extern tree deep_copy_node             PARAMS ((tree));
--- 25,31 ----
  /* Interface used in [break/goto]-elimination: to be declared in a .h file. */
  extern void insert_before_continue_end PARAMS ((tree, tree, int));
  extern void tree_build_scope           PARAMS ((tree *));
! extern tree create_tmp_var             PARAMS ((tree, const char *));
  extern tree declare_tmp_vars           PARAMS ((tree, tree));
  extern tree deep_copy_list             PARAMS ((tree));
  extern tree deep_copy_node             PARAMS ((tree));

--Dan




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