]> gcc.gnu.org Git - gcc.git/commitdiff
tree-inline.c (WALK_SUBTREE_TAIL): New macro.
authorAlexandre Oliva <aoliva@redhat.com>
Fri, 26 Oct 2001 18:27:13 +0000 (18:27 +0000)
committerAlexandre Oliva <aoliva@gcc.gnu.org>
Fri, 26 Oct 2001 18:27:13 +0000 (18:27 +0000)
* tree-inline.c (WALK_SUBTREE_TAIL): New macro.
(walk_tree): Use it for tail calls where appropriate.

From-SVN: r46556

gcc/ChangeLog
gcc/tree-inline.c

index fe907d06beadafef932f9dbe01e2710d7af5cdda..ac8eb1cf9806596feb21f5aa4e6ba26f179cb789 100644 (file)
@@ -1,3 +1,8 @@
+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
index 25d0964ec02f8d04a1749fadaecae07b1b25aaae..865ec234caa9fbb1a88a1d25ff1cab03c46e8663 100644 (file)
@@ -1086,6 +1086,15 @@ walk_tree (tp, func, data, htab_)
     }                                                  \
   while (0)
 
+#define WALK_SUBTREE_TAIL(NODE)                                \
+  do                                                   \
+    {                                                  \
+       tp = & (NODE);                                  \
+       goto tail_recurse;                              \
+    }                                                  \
+  while (0)
+
+ tail_recurse:
   /* Skip empty subtrees.  */
   if (!*tp)
     return NULL_TREE;
@@ -1120,7 +1129,7 @@ walk_tree (tp, func, data, htab_)
       if (statement_code_p (code) || code == TREE_LIST
          || (*lang_hooks.tree_inlining.tree_chain_matters_p) (*tp))
        /* But we still need to check our siblings.  */
-       return walk_tree (&TREE_CHAIN (*tp), func, data, htab);
+       WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
       else
        return NULL_TREE;
     }
@@ -1168,7 +1177,7 @@ walk_tree (tp, func, data, htab_)
            }
 
          /* 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.  */
@@ -1176,10 +1185,7 @@ walk_tree (tp, func, data, htab_)
     }
   else if (TREE_CODE_CLASS (code) == 'd')
     {
-      WALK_SUBTREE (TREE_TYPE (*tp));
-
-      /* We didn't find what we were looking for.  */
-      return NULL_TREE;
+      WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
     }
 
   result = (*lang_hooks.tree_inlining.walk_subtrees) (tp, &walk_subtrees, func,
@@ -1211,30 +1217,35 @@ walk_tree (tp, func, data, htab_)
 
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-      WALK_SUBTREE (TREE_TYPE (*tp));
+      WALK_SUBTREE_TAIL (TREE_TYPE (*tp));
       break;
 
     case TREE_LIST:
       WALK_SUBTREE (TREE_VALUE (*tp));
-      WALK_SUBTREE (TREE_CHAIN (*tp));
+      WALK_SUBTREE_TAIL (TREE_CHAIN (*tp));
       break;
 
     case TREE_VEC:
       {
        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));
+
+       /* Now walk the first one as a tail call.  */
+       WALK_SUBTREE_TAIL (TREE_VEC_ELT (*tp, 0));
       }
-      break;
 
     case COMPLEX_CST:
       WALK_SUBTREE (TREE_REALPART (*tp));
-      WALK_SUBTREE (TREE_IMAGPART (*tp));
-      break;
+      WALK_SUBTREE_TAIL (TREE_IMAGPART (*tp));
 
     case CONSTRUCTOR:
-      WALK_SUBTREE (CONSTRUCTOR_ELTS (*tp));
-      break;
+      WALK_SUBTREE_TAIL (CONSTRUCTOR_ELTS (*tp));
 
     case METHOD_TYPE:
       WALK_SUBTREE (TYPE_METHOD_BASETYPE (*tp));
@@ -1253,18 +1264,15 @@ walk_tree (tp, func, data, htab_)
 
     case ARRAY_TYPE:
       WALK_SUBTREE (TREE_TYPE (*tp));
-      WALK_SUBTREE (TYPE_DOMAIN (*tp));
-      break;
+      WALK_SUBTREE_TAIL (TYPE_DOMAIN (*tp));
 
     case INTEGER_TYPE:
       WALK_SUBTREE (TYPE_MIN_VALUE (*tp));
-      WALK_SUBTREE (TYPE_MAX_VALUE (*tp));
-      break;
+      WALK_SUBTREE_TAIL (TYPE_MAX_VALUE (*tp));
 
     case OFFSET_TYPE:
       WALK_SUBTREE (TREE_TYPE (*tp));
-      WALK_SUBTREE (TYPE_OFFSET_BASETYPE (*tp));
-      break;
+      WALK_SUBTREE_TAIL (TYPE_OFFSET_BASETYPE (*tp));
 
     default:
       abort ();
This page took 0.079249 seconds and 5 git commands to generate.