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]

[patch] basic-block.h: Clean up FOR_EACH_EDGE.


Hi,

Attached is a patch to clean up FOR_EACH_EDGE.

After inlining, the terminating condition of the FOR_EACH_EDGE looks
like so

  if (i == EDGE_COUNT (bb->succs))
    break;
  e = EDGE_SUCC (bb, i);
  if (e == NULL)
    break;

Notice that we have two "if" statements.  The first one is necessary,
but the second one is not.  We know that every edge in any edge vector
is nonnull.  This patch removes the null check.

Unfortunately, this patch itself does not introduce a mesuarable
speed-up, but this is a basis for a subsequent patch to simplify the
first "if" statement above, which actually contains another "if"
statement hidden in it.

This patch does have a measurable size win of 0.099% on stripped
versions of cc1.

Tested on i686-pc-linux-gnu.  Committed as approved by Jeff a while
ago.

Kazu Hirata

2005-04-26  Kazu Hirata  <kazu@cs.umass.edu>

	* basic-block.h (ei_cond): New.
	(FOR_EACH_EDGE): Call ei_cond.

Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/basic-block.h,v
retrieving revision 1.253
diff -u -d -p -r1.253 basic-block.h
--- basic-block.h	21 Apr 2005 09:17:08 -0000	1.253
+++ basic-block.h	24 Apr 2005 02:40:19 -0000
@@ -736,6 +736,25 @@ ei_safe_edge (edge_iterator i)
   return !ei_end_p (i) ? ei_edge (i) : NULL;
 }
 
+/* Return 1 if we should continue to iterate.  Return 0 otherwise.
+   *Edge P is set to the next edge if we are to continue to iterate
+   and NULL otherwise.  */
+
+static inline bool
+ei_cond (edge_iterator ei, edge *p)
+{
+  if (!ei_end_p (ei))
+    {
+      *p = ei_edge (ei);
+      return 1;
+    }
+  else
+    {
+      *p = NULL;
+      return 0;
+    }
+}
+
 /* This macro serves as a convenient way to iterate each edge in a
    vector of predecessor or successor edges.  It must not be used when
    an element might be removed during the traversal, otherwise
@@ -751,9 +770,9 @@ ei_safe_edge (edge_iterator i)
      }
 */
 
-#define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC) \
-  for ((EDGE) = NULL, (ITER) = ei_start ((EDGE_VEC)); \
-       ((EDGE) = ei_safe_edge ((ITER))); \
+#define FOR_EACH_EDGE(EDGE,ITER,EDGE_VEC)	\
+  for ((ITER) = ei_start ((EDGE_VEC));		\
+       ei_cond ((ITER), &(EDGE));		\
        ei_next (&(ITER)))
 
 struct edge_list * create_edge_list (void);


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