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][gfortran] unify creation of temp variables


I noticed while debugging fortran test cases that gfc_create_var_np
was failing to set DECL_IGNORED_P.  But beyond that, having three copies
of this routine is just silly.  Unified thus.

Bootstrapped and tested on i686-linux.


r~


        * gimplify.c (create_tmp_var_raw): Split out from create_tmp_var.
        (create_tmp_var): Use it.
        (create_tmp_alias_var): Remove.
        * tree-alias-common.c, tree-dfa.c: Use create_tmp_var_raw instead.
        * tree-simple.h: Update decls.
fortran/
        * trans.c (gfc_create_var_np): Use create_tmp_var_raw.

Index: gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/gimplify.c,v
retrieving revision 1.1.2.123
diff -u -p -r1.1.2.123 gimplify.c
--- gimplify.c	25 Nov 2003 07:21:12 -0000	1.1.2.123
+++ gimplify.c	28 Nov 2003 21:19:22 -0000
@@ -265,11 +265,11 @@ create_artificial_label (void)
   return lab;
 }
 
-/*  Create a new temporary variable declaration of type TYPE.  Returns the
-    newly created decl and pushes it into the current binding.  */
+/* Create a new temporary variable declaration of type TYPE.
+   Does NOT push it into the current binding.  */
 
 tree
-create_tmp_var (tree type, const char *prefix)
+create_tmp_var_raw (tree type, const char *prefix)
 {
   static unsigned int id_num = 1;
   char *tmp_name;
@@ -286,15 +286,6 @@ create_tmp_var (tree type, const char *p
 
   ASM_FORMAT_PRIVATE_NAME (tmp_name, (prefix ? prefix : "T"), id_num++);
 
-#if defined ENABLE_CHECKING
-  /* If the type is an array or a type which must be created by the
-     frontend, something is wrong.  */
-  if (TREE_CODE (type) == ARRAY_TYPE || TREE_ADDRESSABLE (type))
-    abort ();
-  if (!COMPLETE_TYPE_P (type))
-    abort ();
-#endif
-
   /* Make the type of the variable writable.  */
   new_type = build_type_variant (type, 0, 0);
   TYPE_ATTRIBUTES (new_type) = TYPE_ATTRIBUTES (type);
@@ -313,54 +304,30 @@ create_tmp_var (tree type, const char *p
   TREE_STATIC (tmp_var) = 0;
   TREE_USED (tmp_var) = 1;
 
-  gimple_add_tmp_var (tmp_var);
-
   return tmp_var;
 }
 
-/* Create a new temporary alias variable declaration of type TYPE.  Returns
-   the newly created decl.  Does NOT push it into the current binding.  */
+/* Create a new temporary variable declaration of type TYPE.  DOES push the
+   variable into the current binding.  Further, assume that this is called
+   only from gimplification or optimization, at which point the creation of
+   certain types are bugs.  */
 
 tree
-create_tmp_alias_var (tree type, const char *prefix)
+create_tmp_var (tree type, const char *prefix)
 {
-  static unsigned int id_num = 1;
-  char *tmp_name;
-  char *preftmp = NULL;
   tree tmp_var;
 
-  if (prefix)
-    {
-      preftmp = ASTRDUP (prefix);
-      remove_suffix (preftmp, strlen (preftmp));
-      prefix = preftmp;
-    }
-
-  ASM_FORMAT_PRIVATE_NAME (tmp_name, (prefix ? prefix : "T"), id_num++);
-
-#if 0
-  /* FIXME: build_decl tries to layout the decl again.  This is causing a
-     miscompilation of g++.dg/debug/debug5.C because at this point CFUN
-     doesn't exist anymore.  Besides, laying the decl again seems to be
-     unnecessary work.  */
-  tmp_var = build_decl (VAR_DECL, get_identifier (tmp_name), type);
+#if defined ENABLE_CHECKING
+  /* If the type is an array or a type which must be created by the
+     frontend, something is wrong.  */
+  if (TREE_CODE (type) == ARRAY_TYPE || TREE_ADDRESSABLE (type))
+    abort ();
+  if (!COMPLETE_TYPE_P (type))
+    abort ();
 #endif
-  tmp_var = make_node (VAR_DECL);
-  DECL_NAME (tmp_var) = get_identifier (tmp_name);
-  TREE_TYPE (tmp_var) = type;
-
-  /* The variable was declared by the compiler.  */
-  DECL_ARTIFICIAL (tmp_var) = 1;
-
-  /* Make the variable writable.  */
-  TREE_READONLY (tmp_var) = 0;
-
-  DECL_EXTERNAL (tmp_var) = 0;
-  DECL_CONTEXT (tmp_var) = current_function_decl;
-  TREE_STATIC (tmp_var) = 0;
-  TREE_USED (tmp_var) = 1;
-  TREE_THIS_VOLATILE (tmp_var) = TYPE_VOLATILE (type);
 
+  tmp_var = create_tmp_var_raw (type, prefix);
+  gimple_add_tmp_var (tmp_var);
   return tmp_var;
 }
 
Index: tree-alias-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-alias-common.c,v
retrieving revision 1.1.2.42
diff -u -p -r1.1.2.42 tree-alias-common.c
--- tree-alias-common.c	25 Nov 2003 02:09:54 -0000	1.1.2.42
+++ tree-alias-common.c	28 Nov 2003 21:19:25 -0000
@@ -273,7 +273,7 @@ get_alias_var (tree expr)
       {
 	/* Otherwise, we need a new temporary alias variable for this
 	   expression. */
-	tree temp = create_tmp_alias_var (void_type_node, "aliastmp");
+	tree temp = create_tmp_var_raw (void_type_node, "aliastmp");
 	alias_typevar tempvar;
 	tempvar = current_alias_ops->add_var (current_alias_ops,
 					      temp);
@@ -589,7 +589,7 @@ find_func_aliases (tree *tp, int *walk_s
 	    {
 	      /* This becomes temp = &y and *x = temp . */
 	      alias_typevar tempvar;
-	      tree temp = create_tmp_alias_var (void_type_node, "aliastmp");
+	      tree temp = create_tmp_var_raw (void_type_node, "aliastmp");
 	      tempvar = current_alias_ops->add_var (current_alias_ops, temp);
 	      current_alias_ops->addr_assign (current_alias_ops, tempvar,
 					      rhsAV);
@@ -607,7 +607,7 @@ find_func_aliases (tree *tp, int *walk_s
 	      /* This becomes temp = *y and *x = temp . */
 	      alias_typevar tempvar;
 	      tree temp;
-	      temp = create_tmp_alias_var (void_type_node, "aliastmp");
+	      temp = create_tmp_var_raw (void_type_node, "aliastmp");
 	      tempvar = current_alias_ops->add_var (current_alias_ops, temp);
 	      current_alias_ops->ptr_assign (current_alias_ops, tempvar,
 					     rhsAV);
@@ -626,7 +626,7 @@ find_func_aliases (tree *tp, int *walk_s
 		  /* This becomes temp = (cast) y and  *x = temp. */
 		  alias_typevar tempvar;
 		  tree temp;
-		  temp = create_tmp_alias_var (void_type_node, "aliastmp");
+		  temp = create_tmp_var_raw (void_type_node, "aliastmp");
 		  tempvar = current_alias_ops->add_var (current_alias_ops,
 							temp);
 		  current_alias_ops->simple_assign (current_alias_ops,
@@ -738,7 +738,7 @@ create_fun_alias_var (tree decl, int for
 	   arg && TREE_VALUE (arg) != void_type_node;
 	   arg = TREE_CHAIN (arg))
 	{
-	  tree fakedecl = create_tmp_alias_var (TREE_VALUE (arg), "normarg");
+	  tree fakedecl = create_tmp_var_raw (TREE_VALUE (arg), "normarg");
 	  alias_typevar tvar;
 	  tvar = get_alias_var (fakedecl);
 	  VARRAY_PUSH_GENERIC_PTR (params, tvar);
@@ -763,7 +763,7 @@ create_fun_alias_var (tree decl, int for
      passed to our function.  */
   else
     {
-      tree fakedecl = create_tmp_alias_var (void_type_node, "fakearg");
+      tree fakedecl = create_tmp_var_raw (void_type_node, "fakearg");
       alias_typevar fakevar;
       fakevar = get_alias_var (fakedecl);
       VARRAY_PUSH_GENERIC_PTR (params, fakevar);
@@ -771,7 +771,7 @@ create_fun_alias_var (tree decl, int for
 
   if (!DECL_RESULT (decl))
     {
-      rdecl = create_tmp_alias_var (TREE_TYPE (TREE_TYPE (decl)), "_rv_");
+      rdecl = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (decl)), "_rv_");
       retvar = current_alias_ops->add_var (current_alias_ops, rdecl);
     }
   else
@@ -820,7 +820,7 @@ create_fun_alias_var_ptf (tree decl, tre
 	   arg && TREE_VALUE (arg) != void_type_node;
 	   arg = TREE_CHAIN (arg))
 	{
-	  tree fakedecl = create_tmp_alias_var (TREE_VALUE (arg), "ptfarg");
+	  tree fakedecl = create_tmp_var_raw (TREE_VALUE (arg), "ptfarg");
 	  alias_typevar tvar;
 	  tvar = get_alias_var (fakedecl);
 	  VARRAY_PUSH_GENERIC_PTR (params, tvar);
@@ -832,13 +832,13 @@ create_fun_alias_var_ptf (tree decl, tre
      passed to our function.  */
   else
     {
-      tree fakedecl = create_tmp_alias_var (void_type_node, "fakearg");
+      tree fakedecl = create_tmp_var_raw (void_type_node, "fakearg");
       alias_typevar fakevar;
       fakevar = get_alias_var (fakedecl);
       VARRAY_PUSH_GENERIC_PTR (params, fakevar);
     }
 
-  rdecl = create_tmp_alias_var (TREE_TYPE (type), "_rv_");
+  rdecl = create_tmp_var_raw (TREE_TYPE (type), "_rv_");
   retvar = current_alias_ops->add_var (current_alias_ops, rdecl);
   VARRAY_PUSH_GENERIC_PTR (alias_vars, retvar);
 
Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.189
diff -u -p -r1.1.4.189 tree-dfa.c
--- tree-dfa.c	27 Nov 2003 04:01:02 -0000	1.1.4.189
+++ tree-dfa.c	28 Nov 2003 21:19:27 -0000
@@ -2714,7 +2714,7 @@ get_memory_tag_for (tree ptr)
 
       /* Create a new MT.* artificial variable representing the memory
 	 location pointed-to by PTR.  */
-      tag = create_tmp_alias_var (tag_type, "MT");
+      tag = create_tmp_var_raw (tag_type, "MT");
       tag_ann = get_var_ann (tag);
       tag_ann->is_mem_tag = 1;
       tag_ann->mem_tag = NULL_TREE;
Index: tree-simple.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.h,v
retrieving revision 1.1.4.42
diff -u -p -r1.1.4.42 tree-simple.h
--- tree-simple.h	17 Nov 2003 23:18:13 -0000	1.1.4.42
+++ tree-simple.h	28 Nov 2003 21:19:28 -0000
@@ -25,8 +25,8 @@ Boston, MA 02111-1307, USA.  */
 
 #include "tree-iterator.h"
 
+extern tree create_tmp_var_raw (tree, const char *);
 extern tree create_tmp_var (tree, const char *);
-extern tree create_tmp_alias_var (tree, const char *);
 extern bool is_gimple_tmp_var (tree);
 extern tree get_initialized_tmp_var (tree, tree *, tree *);
 extern tree get_formal_tmp_var (tree, tree *);
Index: fortran/trans.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/Attic/trans.c,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 trans.c
--- fortran/trans.c	27 Nov 2003 19:25:52 -0000	1.1.2.7
+++ fortran/trans.c	28 Nov 2003 21:19:34 -0000
@@ -100,39 +100,7 @@ remove_suffix (char *name, int len)
 tree
 gfc_create_var_np (tree type, const char *prefix)
 {
-  static unsigned int id_num = 1;
-  char *tmp_name;
-  char *preftmp = NULL;
-  tree tmp_var;
-
-  /* Figure out a name for the variable.  */
-  if (prefix)
-    {
-      preftmp = ASTRDUP (prefix);
-      remove_suffix (preftmp, strlen (preftmp));
-      prefix = preftmp;
-    }
-  ASM_FORMAT_PRIVATE_NAME (tmp_name, (prefix ? prefix : "V"), id_num++);
-
-  /* Make the type of the variable writable.  */
-  type = build_type_variant (type, 0, 0);
-
-  /* Build the VAR_DECL variable declaration node.  */
-  tmp_var = build_decl (VAR_DECL, get_identifier (tmp_name), type);
-
-  /* The variable was declared by the compiler.  */
-  DECL_ARTIFICIAL (tmp_var) = 1;
-
-  /* Make the variable writable.  */
-  TREE_READONLY (tmp_var) = 0;
-
-  /* The variable is local, and we assume that it was not
-     created without purpose.  */
-  DECL_EXTERNAL (tmp_var) = 0;
-  TREE_STATIC (tmp_var) = 0;
-  TREE_USED (tmp_var) = 1;
-
-  return tmp_var;
+  return create_tmp_var_raw (type, prefix);
 }
 
 


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