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]

[tuples] Change nlabels in a gs_switch to include the default


This patch changes gs_switch's nlabels to store the total number of
labels including the default instead of excluding the default.
Adjustments through out to compensate. Also I beefed up the switch
tests to check the cases that are stored in the gs_switch instead of
just in the bodies.

2007-07-16 Chris Matthews <chrismatthews@google.com>

   * gimple.c (gs_build_switch): Changed nlabels to represent total number of
   labels including the default.
   (gs_build_switch_1): Same.
   (walk_tuple_ops): Same.
   * gimple-pretty-print.c (dump_gs_switch): Same.
   * gs_switch.c: Improved test case to look at the gs_switch case list instead
   of just the body.
   * gs_switch2.c: Same.
   * gs_switch3.c: Same.
Index: gcc/testsuite/gcc.dg/gimple/gs_switch.c
===================================================================
--- gcc/testsuite/gcc.dg/gimple/gs_switch.c	(revision 126677)
+++ gcc/testsuite/gcc.dg/gimple/gs_switch.c	(working copy)
@@ -16,7 +16,7 @@ foo (int a)
       }
 
 }
-/* { dg-final { scan-tree-dump-times "gimpleir: switch \\(a\\)" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: switch \\(a\\) <default:, case 0:, case 1:>" 1 "gimple"} } */
 /* { dg-final { scan-tree-dump-times "gimpleir: default:" 1 "gimple"} } */
 /* { dg-final { scan-tree-dump-times "gimpleir: case 0:" 1 "gimple"} } */
 /* { dg-final { scan-tree-dump-times "gimpleir: case 1:" 1 "gimple"} } */
Index: gcc/testsuite/gcc.dg/gimple/gs_switch2.c
===================================================================
--- gcc/testsuite/gcc.dg/gimple/gs_switch2.c	(revision 126677)
+++ gcc/testsuite/gcc.dg/gimple/gs_switch2.c	(working copy)
@@ -14,5 +14,8 @@ foo2 (int a, int b)
           return 1;
       }
 }
-/* { dg-final { scan-tree-dump-times "gimpleir: switch \\(D.*\\)" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: switch \\(D.*\\) <default:, case 0:, case 1:>" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: case 0:" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: case 1:" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: default:" 1 "gimple"} } */
 /* { dg-final { cleanup-tree-dump "gimple" } } */
Index: gcc/testsuite/gcc.dg/gimple/gs_switch3.c
===================================================================
--- gcc/testsuite/gcc.dg/gimple/gs_switch3.c	(revision 126677)
+++ gcc/testsuite/gcc.dg/gimple/gs_switch3.c	(working copy)
@@ -1,7 +1,7 @@
 /* { dg-do compile } */
 /* Test generation of default label.  */
 int 
-foo2 (int a)
+foo3 (int a)
 {
     switch (a)
       {
@@ -11,6 +11,9 @@ foo2 (int a)
           return a;
       }
 }
+/* { dg-final { scan-tree-dump-times "gimpleir: switch \\(a\\) <default:, case 0:, case 1:>" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: case 0:" 1 "gimple"} } */
+/* { dg-final { scan-tree-dump-times "gimpleir: case 1:" 1 "gimple"} } */
 /* { dg-final { scan-tree-dump-times "gimpleir: default:" 1 "gimple"} } */
 /* { dg-final { cleanup-tree-dump "gimple" } } */
 
Index: gcc/gimple-pretty-print.c
===================================================================
--- gcc/gimple-pretty-print.c	(revision 126677)
+++ gcc/gimple-pretty-print.c	(working copy)
@@ -245,9 +245,6 @@ dump_gs_switch (pretty_printer *buffer, 
       if (i < gs_switch_nlabels (gs) - 1)
         pp_string (buffer, ", ");
     }
-      dump_generic_node (buffer, gs_switch_default_label (gs), spc, flags,
-                        false);
-
   pp_string (buffer, ">");
 }
 
Index: gcc/ChangeLog.tuples
===================================================================
--- gcc/ChangeLog.tuples	(revision 126677)
+++ gcc/ChangeLog.tuples	(working copy)
@@ -1,3 +1,15 @@
+2007-07-16  Chris Matthews  <chrismatthews@google.com>
+
+	* gimple.c (gs_build_switch): Changed nlabels to represent total number of
+	labels including the default.
+	(gs_build_switch_1): Same.
+	(walk_tuple_ops): Same.
+	* gimple-pretty-print.c (dump_gs_switch): Same.
+	* gs_switch.c: Improved test case to look at the gs_switch case list instead
+	of just the body.
+	* gs_switch2.c: Same.
+	* gs_switch3.c: Same.
+
 2007-07-16  Aldy Hernandez  <aldyh@redhat.com> 
 
 	* gimplify.c (gimplify_ctx): Rename current_bind_expr_seq to
Index: gcc/gimple.c
===================================================================
--- gcc/gimple.c	(revision 126677)
+++ gcc/gimple.c	(working copy)
@@ -442,13 +442,15 @@ static inline gimple 
 gs_build_switch_1 (unsigned int nlabels, tree index, tree default_label)
 {
   gimple p;
-  
-  /* nlabels + 1 default label - 1 extra from struct.  */
+  unsigned int n_all_labels;
+  /*  We count the default in the number of labels.  */
+  n_all_labels = nlabels + 1;
+  /* total labels - 1 extra from struct.  */
   p = ggc_alloc_cleared (sizeof (struct gimple_statement_switch)
-                         + sizeof (tree) * nlabels);
+                         + sizeof (tree) * (n_all_labels - 1));
   GS_CODE (p) = GS_SWITCH;
 
-  gs_switch_set_nlabels (p, nlabels);
+  gs_switch_set_nlabels (p, n_all_labels);
   gs_switch_set_index (p, index);
   gs_switch_set_default_label (p, default_label);
   
@@ -469,6 +471,8 @@ gs_build_switch (unsigned int nlabels, t
   unsigned int i;
 
   gimple p = gs_build_switch_1 (nlabels, index, default_label);
+  /*  Put labels in labels[1 - (nlables + 1)].
+     Default label is in labels[0].  */
   va_start (al, default_label);
   for (i = 1; i <= nlabels; i++)
     gs_switch_set_label (p, i, va_arg (al, tree));
@@ -491,8 +495,10 @@ gs_build_switch_vec (tree index, tree de
   size_t nlabels = VEC_length (tree, args);
   gimple p = gs_build_switch_1 (nlabels, index, default_label);
 
-  for (i = 0; i < nlabels; i++)
-    gs_switch_set_label (p, i + 1, VEC_index (tree, args, i));
+  /*  Put labels in labels[1 - (nlables + 1)].
+     Default label is in labels[0].  */
+  for (i = 1; i <= nlabels; i++)
+    gs_switch_set_label (p, i, VEC_index (tree, args, i - 1));
 
   return p;
 }
@@ -889,7 +895,7 @@ walk_tuple_ops (gimple gs, walk_tree_fn 
 
     case GS_SWITCH:
       WALKIT (gs_switch_index (gs));
-      for (i = 0; i <= gs_switch_nlabels (gs); ++i)
+      for (i = 0; i < gs_switch_nlabels (gs); ++i)
 	WALKIT (gs_switch_label (gs, i));
       break;
 

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