From 44d683da8e2db900434d307a8dbcc26dedb6e5ac Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 13 May 2014 16:46:26 -0400
Subject: [PATCH 08/29] Introduce glabel and use it in a few places

This corresponds to:
  "[PATCH 06/89] Introduce gimple_label and use it in a few places"
    http://gcc.gnu.org/ml/gcc-patches/2014-04/msg01152.html
from v1 of the patch series.

gcc/
	* coretypes.h (glabel): Add forward declaration.

	* gimple.h (struct glabel): New subclass of gimple_with_ops,
	adding the invariant that stmt->code == GIMPLE_LABEL.
	(is_a_helper <glabel *>::test): New.

	* gdbhooks.py (build_pretty_printer): Add "glabel *" and
	"const glabel *", reusing the gimple printer.

	* gimple-pretty-print.c (dump_gimple_label): Require a glabel
	rather than just a gimple.
	* tree-cfg.c (verify_gimple_label): Likewise.

	* gimple.c (gimple_build_label): Return a glabel rather than
	just a gimple.
	* gimple.h (gimple_build_label): Likewise.

	* gimplify.c (gimplify_case_label_expr): Update local to be a
	glabel.
	* tree-switch-conversion.c (gen_inbound_check): Likewise.

	* gimple-pretty-print.c (pp_gimple_stmt_1): Add checked cast to
	glabel in regions where a stmt is known to have code
	GIMPLE_LABEL.
	* tree-cfg.c (verify_gimple_stmt): Likewise.

	* doc/gimple.texi: Update for above changes.
---
 gcc/coretypes.h              |  1 +
 gcc/doc/gimple.texi          |  8 +++++---
 gcc/gdbhooks.py              |  1 +
 gcc/gimple-pretty-print.c    |  4 ++--
 gcc/gimple.c                 |  5 +++--
 gcc/gimple.h                 | 20 +++++++++++++++++++-
 gcc/gimplify.c               |  6 +++---
 gcc/tree-cfg.c               |  4 ++--
 gcc/tree-switch-conversion.c |  2 +-
 9 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index 6eb5dcf..f7976c8 100644
--- a/gcc/coretypes.h
+++ b/gcc/coretypes.h
@@ -71,6 +71,7 @@ struct gimple_stmt_iterator;
 /* Forward declarations of gimple subclasses.
    Keep this in the same order as the corresponding codes in gimple.def.  */
 class gcond;
+class glabel;
 class gswitch;
 class gassign;
 class gbind;
diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi
index 7fc885c..56a42f1 100644
--- a/gcc/doc/gimple.texi
+++ b/gcc/doc/gimple.texi
@@ -312,13 +312,15 @@ kinds, along with their relationships to @code{GSS_} values (layouts) and
      |   |
      |   + gimple_with_ops
      |   |   |    layout: GSS_WITH_OPS
-     |   |   |    Used for 3 codes: GIMPLE_DEBUG
+     |   |   |    Used for 2 codes: GIMPLE_DEBUG
      |   |   |                      GIMPLE_GOTO
-     |   |   |                      GIMPLE_LABEL
      |   |   |
      |   |   + gcond
      |   |   |        code: GIMPLE_COND
      |   |   |
+     |   |   + glabel
+     |   |   |        code: GIMPLE_LABEL
+     |   |   |
      |   |   + gswitch
      |   |            code: GIMPLE_SWITCH
      |   |
@@ -1686,7 +1688,7 @@ Set the @code{EH_FILTER_MUST_NOT_THROW} flag.
 @subsection @code{GIMPLE_LABEL}
 @cindex @code{GIMPLE_LABEL}
 
-@deftypefn {GIMPLE function} gimple *gimple_build_label (tree label)
+@deftypefn {GIMPLE function} glabel *gimple_build_label (tree label)
 Build a @code{GIMPLE_LABEL} statement with corresponding to the tree
 label, @code{LABEL}.
 @end deftypefn
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index 2b689db..cf8beba 100644
--- a/gcc/gdbhooks.py
+++ b/gcc/gdbhooks.py
@@ -457,6 +457,7 @@ def build_pretty_printer():
     pp.add_printer_for_types(['gimple *',
                               # Keep this in the same order as gimple.def:
                               'gcond *', 'const gcond *',
+                              'glabel *', 'const glabel *',
                               'gswitch *', 'const gswitch *',
                               'gassign *', 'const gassign *',
                               'gbind *', 'const gbind *'],
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index f323391..41f4d12 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -852,7 +852,7 @@ dump_gimple_cond (pretty_printer *buffer, gcond *gs, int spc, int flags)
    TDF_* in dumpfils.h).  */
 
 static void
-dump_gimple_label (pretty_printer *buffer, gimple *gs, int spc, int flags)
+dump_gimple_label (pretty_printer *buffer, glabel *gs, int spc, int flags)
 {
   tree label = gimple_label_label (gs);
   if (flags & TDF_RAW)
@@ -2104,7 +2104,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, int flags)
       break;
 
     case GIMPLE_LABEL:
-      dump_gimple_label (buffer, gs, spc, flags);
+      dump_gimple_label (buffer, as_a <glabel *> (gs), spc, flags);
       break;
 
     case GIMPLE_GOTO:
diff --git a/gcc/gimple.c b/gcc/gimple.c
index e9a2024..22f5620 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -482,10 +482,11 @@ gimple_cond_set_condition_from_tree (gcond *stmt, tree cond)
 
 /* Build a GIMPLE_LABEL statement for LABEL.  */
 
-gimple *
+glabel *
 gimple_build_label (tree label)
 {
-  gimple *p = gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1);
+  glabel *p
+    = as_a <glabel *> (gimple_build_with_ops (GIMPLE_LABEL, ERROR_MARK, 1));
   gimple_label_set_label (p, label);
   return p;
 }
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 576abec..6dfdaca 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -775,6 +775,16 @@ struct GTY((tag("GSS_WITH_OPS")))
 };
 
 /* A statement with the invariant that
+      stmt->code == GIMPLE_LABEL
+   i.e. a label statement.  */
+
+struct GTY((tag("GSS_WITH_OPS")))
+  glabel : public gimple_with_ops
+{
+  /* no additional fields; this uses the layout for GSS_WITH_OPS. */
+};
+
+/* A statement with the invariant that
       stmt->code == GIMPLE_SWITCH
    i.e. a switch statement.  */
 
@@ -853,6 +863,14 @@ is_a_helper <gcond *>::test (gimple *gs)
 template <>
 template <>
 inline bool
+is_a_helper <glabel *>::test (gimple *gs)
+{
+  return gs->code == GIMPLE_LABEL;
+}
+
+template <>
+template <>
+inline bool
 is_a_helper <geh_dispatch *>::test (gimple *gs)
 {
   return gs->code == GIMPLE_EH_DISPATCH;
@@ -1240,7 +1258,7 @@ gassign *gimple_build_assign_with_ops (enum tree_code, tree,
 gcond *gimple_build_cond (enum tree_code, tree, tree, tree, tree);
 gcond *gimple_build_cond_from_tree (tree, tree, tree);
 void gimple_cond_set_condition_from_tree (gcond *, tree);
-gimple *gimple_build_label (tree label);
+glabel *gimple_build_label (tree label);
 gimple *gimple_build_goto (tree dest);
 gimple *gimple_build_nop (void);
 gbind *gimple_build_bind (tree, gimple_seq, tree);
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 0add35e..7ff07ae 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -1512,7 +1512,7 @@ static enum gimplify_status
 gimplify_case_label_expr (tree *expr_p, gimple_seq *pre_p)
 {
   struct gimplify_ctx *ctxp;
-  gimple *gimple_label;
+  glabel *label_stmt;
 
   /* Invalid OpenMP programs can play Duff's Device type games with
      #pragma omp parallel.  At least in the C front end, we don't
@@ -1521,9 +1521,9 @@ gimplify_case_label_expr (tree *expr_p, gimple_seq *pre_p)
     if (ctxp->case_labels.exists ())
       break;
 
-  gimple_label = gimple_build_label (CASE_LABEL (*expr_p));
+  label_stmt = gimple_build_label (CASE_LABEL (*expr_p));
   ctxp->case_labels.safe_push (*expr_p);
-  gimplify_seq_add_stmt (pre_p, gimple_label);
+  gimplify_seq_add_stmt (pre_p, label_stmt);
 
   return GS_ALL_DONE;
 }
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 4b8bc05..6a22f8e 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4367,7 +4367,7 @@ verify_gimple_debug (gimple *stmt ATTRIBUTE_UNUSED)
    Returns true if anything is wrong.  */
 
 static bool
-verify_gimple_label (gimple *stmt)
+verify_gimple_label (glabel *stmt)
 {
   tree decl = gimple_label_label (stmt);
   int uid;
@@ -4417,7 +4417,7 @@ verify_gimple_stmt (gimple *stmt)
       return verify_gimple_assign (as_a <gassign *> (stmt));
 
     case GIMPLE_LABEL:
-      return verify_gimple_label (stmt);
+      return verify_gimple_label (as_a <glabel *> (stmt));
 
     case GIMPLE_CALL:
       return verify_gimple_call (stmt);
diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c
index ece86e5..cb086c3 100644
--- a/gcc/tree-switch-conversion.c
+++ b/gcc/tree-switch-conversion.c
@@ -1222,7 +1222,7 @@ gen_inbound_check (gswitch *swtch, struct switch_conv_info *info)
   tree label_decl1 = create_artificial_label (UNKNOWN_LOCATION);
   tree label_decl2 = create_artificial_label (UNKNOWN_LOCATION);
   tree label_decl3 = create_artificial_label (UNKNOWN_LOCATION);
-  gimple *label1, *label2, *label3;
+  glabel *label1, *label2, *label3;
   tree utype, tidx;
   tree bound;
 
-- 
1.8.5.3

