This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[ast-optimizer-branch]: Allow temp variables to have differentprefixes
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: gcc-patches at gcc dot gnu dot org, <dnovillo at redhat dot com>
- Date: Thu, 30 May 2002 13:35:34 -0400 (EDT)
- Subject: [ast-optimizer-branch]: Allow temp variables to have differentprefixes
Ugly, but I couldn't think of a better way to do it, since the prefix
passed in could be some VAR_DECL's identifier, and thus, can't be modified
directly. We could use alloca if you want to add another parameter to
create_tmp_var.
I have left out the changes to simple-break-elim.c, simple-goto-elim.c,
and tree-ssa-pre.c, because I can't extricate it from some other changes i've
made.
There are two uses of create_tmp_var in simple-break-elim.c to be updated,
one in simple-goto-elim.c, and one in tree-ssa-pre.c
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.2.19
diff -u -3 -p -w -B -b -r1.1.2.19 c-simplify.c
--- c-simplify.c 28 May 2002 01:29:55 -0000 1.1.2.19
+++ c-simplify.c 30 May 2002 17:33:02 -0000
@@ -84,6 +84,7 @@ static tree convert_to_stmt_chain PAR
static int stmt_has_effect PARAMS ((tree));
static int expr_has_effect PARAMS ((tree));
static tree mostly_copy_tree_r PARAMS ((tree *, int *, void *));
+static inline void strip_off_ending PARAMS ((char *, int));
/* Local variables. */
static FILE *dump_file;
@@ -98,6 +99,26 @@ static int stmt_expr_level;
/* }}} */
+/* 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 < 8 && len > i; i++)
+ {
+ if (name[len - i] == '.')
+ {
+ name[len - i] = '\0';
+ break;
+ }
+ }
+}
/* Simplification of statement trees. */
/** {{{ simplify_tree ()
@@ -894,7 +915,7 @@ simplify_return_stmt (stmt, pre_p)
return;
/* Create the assignment 'T = ret_expr'. */
- tmp = create_tmp_var (TREE_TYPE (ret_expr));
+ tmp = create_tmp_var (TREE_TYPE (ret_expr), "return");
expr = build_modify_expr (tmp, NOP_EXPR, ret_expr);
/* Simplify it. */
@@ -949,6 +970,8 @@ simplify_expr (expr_p, pre_p, post_p, si
int (*simple_test_f) PARAMS ((tree));
tree stmt;
{
+ const char *prefix = NULL;
+ tree stripped_decl;
if (simple_test_f == NULL)
abort ();
@@ -1132,11 +1155,15 @@ simplify_expr (expr_p, pre_p, post_p, si
abort ();
}
+ stripped_decl = *expr_p;
+ STRIP_NOPS (stripped_decl);
+ if (DECL_P (stripped_decl))
+ prefix = IDENTIFIER_POINTER (DECL_NAME (stripped_decl));
/* If the simplified expression can be assigned into a new temporary TMP,
do so and replace the original expression with TMP. */
if (!VOID_TYPE_P (TREE_TYPE (*expr_p)))
{
- tree tmp = create_tmp_var (TREE_TYPE (*expr_p));
+ tree tmp = create_tmp_var (TREE_TYPE (*expr_p), prefix);
add_tree (build_modify_expr (tmp, NOP_EXPR, *expr_p), pre_p);
*expr_p = tmp;
}
@@ -1410,7 +1437,7 @@ simplify_cond_expr (expr_p, pre_p, stmt)
expr_type = TREE_TYPE (*expr_p);
if (!VOID_TYPE_P (expr_type))
- tmp = create_tmp_var (TREE_TYPE (*expr_p));
+ tmp = create_tmp_var (TREE_TYPE (*expr_p), "iftmp");
else
tmp = void_zero_node;
@@ -1526,7 +1553,7 @@ simplify_boolean_expr (expr_p, pre_p, st
rhs = TREE_OPERAND (*expr_p, 1);
/* Build 'T = a' */
- t = create_tmp_var (TREE_TYPE (*expr_p));
+ t = create_tmp_var (TREE_TYPE (*expr_p), "booltmp");
mod_expr = build_modify_expr (t, NOP_EXPR, lhs);
/* Build the body for the if() statement that conditionally evaluates the
@@ -1765,7 +1792,7 @@ simplify_lvalue_expr (expr_p, pre_p, pos
base = TREE_OPERAND (*expr_p, 0);
lvalue = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (base)), base);
- tmp = create_tmp_var (TREE_TYPE (lvalue));
+ tmp = create_tmp_var (TREE_TYPE (lvalue), "compref");
add_tree (build_modify_expr (tmp, NOP_EXPR, lvalue), pre_p);
/* Re-write the base of the structure with a reference to the new
@@ -2038,14 +2065,23 @@ insert_before_first (t, body)
newly created decl and pushes it into the current binding. */
tree
-create_tmp_var (type)
+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;
- ASM_FORMAT_PRIVATE_NAME (tmp_name, "T", id_num++);
+ /* prefix[0] != 0 to avoid an allocated string that happens to only contain a NULL */
+ if (prefix)
+ {
+ preftmp = xstrdup (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. */
@@ -2069,6 +2105,8 @@ create_tmp_var (type)
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 -u -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 30 May 2002 17:33:02 -0000
@@ -25,7 +25,7 @@ Boston, MA 02111-1307, USA. */
/* 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 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));