This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Optimization for walk_tree
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Optimization for walk_tree
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Wed, 21 Jun 2000 15:23:15 +0200
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
Hi!
gcc does not recognize
int foo(void)
{
int r;
do {
r = foo(void);
if (r) return r;
} while (0);
return 0;
}
sequence as tail call recursion, and I guess it will take quite some time
till it will. So I think we should help it a little bit in walk_tree to
speed things up a little bit.
The possibilities I see is either the one below, or
#define WALK_SUBTREE_TAIL(NODE) \
do \
{ \
tp = &(NODE); \
goto tail_recursion; \
} \
while (0)
tail_recursion:
instead.
2000-06-21 Jakub Jelinek <jakub@redhat.com>
* tree.c (WALK_SUBTREE_TAIL): New macro.
(walk_tree): Use it if the only action after WALK_SUBTREE is
return NULL_TREE.
--- gcc/cp/tree.c.jj Wed Jun 7 08:41:15 2000
+++ gcc/cp/tree.c Wed Jun 21 14:50:19 2000
@@ -1219,6 +1219,9 @@ walk_tree (tp, func, data)
} \
while (0)
+#define WALK_SUBTREE_TAIL(NODE) \
+ return walk_tree (&(NODE), func, data)
+
/* Skip empty subtrees. */
if (!*tp)
return NULL_TREE;
@@ -1280,7 +1283,7 @@ walk_tree (tp, func, data)
WALK_SUBTREE (DECL_SIZE_UNIT (DECL_STMT_DECL (*tp)));
}
- WALK_SUBTREE (TREE_CHAIN (*tp));
+ WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
}
/* We didn't find what we were looking for. */
@@ -1288,7 +1291,7 @@ walk_tree (tp, func, data)
}
else if (TREE_CODE_CLASS (code) == 'd')
{
- WALK_SUBTREE (TREE_TYPE (*tp));
+ WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
/* We didn't find what we were looking for. */
return NULL_TREE;
@@ -1321,23 +1324,23 @@ walk_tree (tp, func, data)
break;
case PTRMEM_CST:
- WALK_SUBTREE (TREE_TYPE (*tp));
+ WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
break;
case POINTER_TYPE:
case REFERENCE_TYPE:
- WALK_SUBTREE (TREE_TYPE (*tp));
+ WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
break;
case TREE_LIST:
WALK_SUBTREE (TREE_PURPOSE (*tp));
WALK_SUBTREE (TREE_VALUE (*tp));
- WALK_SUBTREE (TREE_CHAIN (*tp));
+ WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
break;
case OVERLOAD:
WALK_SUBTREE (OVL_FUNCTION (*tp));
- WALK_SUBTREE (OVL_CHAIN (*tp));
+ WALK_SUBTREE_TAIL (OVL_CHAIN (*tp));
break;
case TREE_VEC:
@@ -1350,11 +1353,11 @@ walk_tree (tp, func, data)
case COMPLEX_CST:
WALK_SUBTREE (TREE_REALPART (*tp));
- WALK_SUBTREE (TREE_IMAGPART (*tp));
+ WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
break;
case CONSTRUCTOR:
- WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp));
+ WALK_SUBTREE_TAIL (CONSTRUCTOR_ELTS (*tp));
break;
case METHOD_TYPE:
@@ -1363,27 +1366,27 @@ walk_tree (tp, func, data)
case FUNCTION_TYPE:
WALK_SUBTREE (TREE_TYPE (*tp));
- WALK_SUBTREE (TYPE_ARG_TYPES (*tp));
+ WALK_SUBTREE_TAIL (TYPE_ARG_TYPES (*tp));
break;
case ARRAY_TYPE:
WALK_SUBTREE (TREE_TYPE (*tp));
- WALK_SUBTREE (TYPE_DOMAIN (*tp));
+ WALK_SUBTREE_TAIL (TYPE_DOMAIN (*tp));
break;
case INTEGER_TYPE:
WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
- WALK_SUBTREE (TYPE_MAX_VALUE (*tp));
+ WALK_SUBTREE_TAIL (TYPE_MAX_VALUE (*tp));
break;
case OFFSET_TYPE:
WALK_SUBTREE (TREE_TYPE (*tp));
- WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp));
+ WALK_SUBTREE_TAIL (TYPE_OFFSET_BASETYPE (*tp));
break;
case RECORD_TYPE:
if (TYPE_PTRMEMFUNC_P (*tp))
- WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
+ WALK_SUBTREE_TAIL (TYPE_PTRMEMFUNC_FN_TYPE (*tp));
break;
default:
@@ -1394,6 +1397,7 @@ walk_tree (tp, func, data)
return NULL_TREE;
#undef WALK_SUBTREE
+#undef WALK_SUBTREE_TAIL
}
/* Passed to walk_tree. Checks for the use of types with no linkage. */
Jakub