Commit 6c624f7f by Alexandre Oliva Committed by Alexandre Oliva

tree-inline.c (WALK_SUBTREE_TAIL): New macro.

* tree-inline.c (WALK_SUBTREE_TAIL): New macro.
(walk_tree): Use it for tail calls where appropriate.

From-SVN: r46556
parent 45c23566
2001-10-26 Alexandre Oliva <aoliva@redhat.com> 2001-10-26 Alexandre Oliva <aoliva@redhat.com>
* tree-inline.c (WALK_SUBTREE_TAIL): New macro.
(walk_tree): Use it for tail calls where appropriate.
2001-10-26 Alexandre Oliva <aoliva@redhat.com>
* cse.c (check_for_label_ref): Don't require REG_LABEL notes for * cse.c (check_for_label_ref): Don't require REG_LABEL notes for
non-local label_refs. non-local label_refs.
......
...@@ -1086,6 +1086,15 @@ walk_tree (tp, func, data, htab_) ...@@ -1086,6 +1086,15 @@ walk_tree (tp, func, data, htab_)
} \ } \
while (0) while (0)
#define WALK_SUBTREE_TAIL(NODE) \
do \
{ \
tp = & (NODE); \
goto tail_recurse; \
} \
while (0)
tail_recurse:
/* Skip empty subtrees. */ /* Skip empty subtrees. */
if (!*tp) if (!*tp)
return NULL_TREE; return NULL_TREE;
...@@ -1120,7 +1129,7 @@ walk_tree (tp, func, data, htab_) ...@@ -1120,7 +1129,7 @@ walk_tree (tp, func, data, htab_)
if (statement_code_p (code) || code == TREE_LIST if (statement_code_p (code) || code == TREE_LIST
|| (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp)) || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
/* But we still need to check our siblings. */ /* But we still need to check our siblings. */
return walk_tree (&TREE_CHAIN (*tp), func, data, htab); WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
else else
return NULL_TREE; return NULL_TREE;
} }
...@@ -1168,7 +1177,7 @@ walk_tree (tp, func, data, htab_) ...@@ -1168,7 +1177,7 @@ walk_tree (tp, func, data, htab_)
} }
/* This can be tail-recursion optimized if we write it this way. */ /* This can be tail-recursion optimized if we write it this way. */
return walk_tree (&TREE_CHAIN (*tp), func, data, htab); WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
} }
/* We didn't find what we were looking for. */ /* We didn't find what we were looking for. */
...@@ -1176,10 +1185,7 @@ walk_tree (tp, func, data, htab_) ...@@ -1176,10 +1185,7 @@ walk_tree (tp, func, data, htab_)
} }
else if (TREE_CODE_CLASS (code) == 'd') 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;
} }
result = (*lang_hooks.tree_inlining.walk_subtrees) (tp, &walk_subtrees, func, result = (*lang_hooks.tree_inlining.walk_subtrees) (tp, &walk_subtrees, func,
...@@ -1211,30 +1217,35 @@ walk_tree (tp, func, data, htab_) ...@@ -1211,30 +1217,35 @@ walk_tree (tp, func, data, htab_)
case POINTER_TYPE: case POINTER_TYPE:
case REFERENCE_TYPE: case REFERENCE_TYPE:
WALK_SUBTREE (TREE_TYPE (*tp)); WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
break; break;
case TREE_LIST: case TREE_LIST:
WALK_SUBTREE (TREE_VALUE (*tp)); WALK_SUBTREE (TREE_VALUE (*tp));
WALK_SUBTREE (TREE_CHAIN (*tp)); WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
break; break;
case TREE_VEC: case TREE_VEC:
{ {
int len = TREE_VEC_LENGTH (*tp); int len = TREE_VEC_LENGTH (*tp);
while (len--)
if (len == 0)
break;
/* Walk all elements but the first. */
while (--len)
WALK_SUBTREE (TREE_VEC_ELT (*tp, len)); WALK_SUBTREE (TREE_VEC_ELT (*tp, len));
/* Now walk the first one as a tail call. */
WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
} }
break;
case COMPLEX_CST: case COMPLEX_CST:
WALK_SUBTREE (TREE_REALPART (*tp)); WALK_SUBTREE (TREE_REALPART (*tp));
WALK_SUBTREE (TREE_IMAGPART (*tp)); WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
break;
case CONSTRUCTOR: case CONSTRUCTOR:
WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp)); WALK_SUBTREE_TAIL (CONSTRUCTOR_ELTS (*tp));
break;
case METHOD_TYPE: case METHOD_TYPE:
WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp)); WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp));
...@@ -1253,18 +1264,15 @@ walk_tree (tp, func, data, htab_) ...@@ -1253,18 +1264,15 @@ walk_tree (tp, func, data, htab_)
case ARRAY_TYPE: case ARRAY_TYPE:
WALK_SUBTREE (TREE_TYPE (*tp)); WALK_SUBTREE (TREE_TYPE (*tp));
WALK_SUBTREE (TYPE_DOMAIN (*tp)); WALK_SUBTREE_TAIL (TYPE_DOMAIN (*tp));
break;
case INTEGER_TYPE: case INTEGER_TYPE:
WALK_SUBTREE (TYPE_MIN_VALUE (*tp)); WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
WALK_SUBTREE (TYPE_MAX_VALUE (*tp)); WALK_SUBTREE_TAIL (TYPE_MAX_VALUE (*tp));
break;
case OFFSET_TYPE: case OFFSET_TYPE:
WALK_SUBTREE (TREE_TYPE (*tp)); WALK_SUBTREE (TREE_TYPE (*tp));
WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp)); WALK_SUBTREE_TAIL (TYPE_OFFSET_BASETYPE (*tp));
break;
default: default:
abort (); abort ();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment