From 5c458816605f2c8bf7e2e65bfff7cd627a19d11d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Tue, 13 May 2014 17:04:38 -0400
Subject: [PATCH 09/29] Introduce gdebug and use it in a few places

This is an updated version of:
 "[PATCH 07/89] Introduce gimple_debug and use it in a few places"
    http://gcc.gnu.org/ml/gcc-patches/2014-04/msg01192.html
for v4 of the patch series.

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

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

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

	* gimple-pretty-print.c (dump_gimple_debug): Require a gdebug
	rather than just a gimple.
	* tree-inline.c (copy_debug_stmt): Likewise.

	* tree-inline.h (struct copy_body_data): Strengthen field
	"debug_stmts" from a vec<gimple *> to a vec<gdebug *>.

	* gimple.c (gimple_build_debug_bind_stat): Return a gdebug
	rather than just a gimple.
	(gimple_build_debug_source_bind_stat): Likewise.
	* gimple.h (gimple_build_debug_bind_stat): Likewise.
	(gimple_build_debug_source_bind_stat): Likewise.

	* tree-inline.c (remap_gimple_stmt): Update locals to be a
	gdebug.
	(maybe_move_debug_stmts_to_successors): Likewise.
	(copy_debug_stmts): Likewise.

	* gimple-pretty-print.c (pp_gimple_stmt_1): Add checked cast to
	gdebug in regions where a stmt is known to have code
	GIMPLE_DEBUG.

	* 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              | 18 ++++++++++--------
 gcc/gimple.h              | 22 ++++++++++++++++++++--
 gcc/tree-inline.c         | 16 +++++++++-------
 gcc/tree-inline.h         |  2 +-
 8 files changed, 49 insertions(+), 23 deletions(-)

diff --git a/gcc/coretypes.h b/gcc/coretypes.h
index f7976c8..26fae44 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 gdebug;
 class glabel;
 class gswitch;
 class gassign;
diff --git a/gcc/doc/gimple.texi b/gcc/doc/gimple.texi
index 56a42f1..679772a 100644
--- a/gcc/doc/gimple.texi
+++ b/gcc/doc/gimple.texi
@@ -312,12 +312,14 @@ kinds, along with their relationships to @code{GSS_} values (layouts) and
      |   |
      |   + gimple_with_ops
      |   |   |    layout: GSS_WITH_OPS
-     |   |   |    Used for 2 codes: GIMPLE_DEBUG
-     |   |   |                      GIMPLE_GOTO
+     |   |   |    Used for code: GIMPLE_GOTO
      |   |   |
      |   |   + gcond
      |   |   |        code: GIMPLE_COND
      |   |   |
+     |   |   + gdebug
+     |   |   |        code: GIMPLE_DEBUG
+     |   |   |
      |   |   + glabel
      |   |   |        code: GIMPLE_LABEL
      |   |   |
@@ -1557,7 +1559,7 @@ Set the conditional @code{COND_STMT} to be of the form 'if (1 == 1)'.
 @cindex @code{GIMPLE_DEBUG}
 @cindex @code{GIMPLE_DEBUG_BIND}
 
-@deftypefn {GIMPLE function} gimple *gimple_build_debug_bind (tree var, @
+@deftypefn {GIMPLE function} gdebug *gimple_build_debug_bind (tree var, @
 tree value, gimple *stmt)
 Build a @code{GIMPLE_DEBUG} statement with @code{GIMPLE_DEBUG_BIND} of
 @code{subcode}.  The effect of this statement is to tell debug
diff --git a/gcc/gdbhooks.py b/gcc/gdbhooks.py
index cf8beba..f3a3d97 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 *',
+                              'gdebug *', 'const gdebug *',
                               'glabel *', 'const glabel *',
                               'gswitch *', 'const gswitch *',
                               'gassign *', 'const gassign *',
diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c
index 41f4d12..5183ea1 100644
--- a/gcc/gimple-pretty-print.c
+++ b/gcc/gimple-pretty-print.c
@@ -1071,7 +1071,7 @@ dump_gimple_eh_dispatch (pretty_printer *buffer, gimple *gs, int spc, int flags)
    in dumpfile.h).  */
 
 static void
-dump_gimple_debug (pretty_printer *buffer, gimple *gs, int spc, int flags)
+dump_gimple_debug (pretty_printer *buffer, gdebug *gs, int spc, int flags)
 {
   switch (gs->subcode)
     {
@@ -2216,7 +2216,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple *gs, int spc, int flags)
       break;
 
     case GIMPLE_DEBUG:
-      dump_gimple_debug (buffer, gs, spc, flags);
+      dump_gimple_debug (buffer, as_a <gdebug *> (gs), spc, flags);
       break;
 
     case GIMPLE_PREDICT:
diff --git a/gcc/gimple.c b/gcc/gimple.c
index 22f5620..b002bcf 100644
--- a/gcc/gimple.c
+++ b/gcc/gimple.c
@@ -765,12 +765,13 @@ gimple_build_eh_dispatch (int region)
 
    VAR is bound to VALUE; block and location are taken from STMT.  */
 
-gimple *
+gdebug *
 gimple_build_debug_bind_stat (tree var, tree value, gimple *stmt MEM_STAT_DECL)
 {
-  gimple *p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
-					 (unsigned)GIMPLE_DEBUG_BIND, 2
-					 PASS_MEM_STAT);
+  gdebug *p = as_a <gdebug *> (gimple_build_with_ops_stat (
+				 GIMPLE_DEBUG,
+				 (unsigned)GIMPLE_DEBUG_BIND, 2
+				 PASS_MEM_STAT));
 
   gimple_debug_bind_set_var (p, var);
   gimple_debug_bind_set_value (p, value);
@@ -785,13 +786,14 @@ gimple_build_debug_bind_stat (tree var, tree value, gimple *stmt MEM_STAT_DECL)
 
    VAR is bound to VALUE; block and location are taken from STMT.  */
 
-gimple *
+gdebug *
 gimple_build_debug_source_bind_stat (tree var, tree value,
 				     gimple *stmt MEM_STAT_DECL)
 {
-  gimple *p = gimple_build_with_ops_stat (GIMPLE_DEBUG,
-					 (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
-					 PASS_MEM_STAT);
+  gdebug *p = as_a <gdebug *> (gimple_build_with_ops_stat (
+				 GIMPLE_DEBUG,
+				 (unsigned)GIMPLE_DEBUG_SOURCE_BIND, 2
+				 PASS_MEM_STAT));
 
   gimple_debug_source_bind_set_var (p, var);
   gimple_debug_source_bind_set_value (p, value);
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 6dfdaca..5fd2cd9 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_DEBUG
+   i.e. a debug statement.  */
+
+struct GTY((tag("GSS_WITH_OPS")))
+  gdebug : public gimple_with_ops
+{
+  /* no additional fields; this uses the layout for GSS_WITH_OPS. */
+};
+
+/* A statement with the invariant that
       stmt->code == GIMPLE_LABEL
    i.e. a label statement.  */
 
@@ -863,6 +873,14 @@ is_a_helper <gcond *>::test (gimple *gs)
 template <>
 template <>
 inline bool
+is_a_helper <gdebug *>::test (gimple *gs)
+{
+  return gs->code == GIMPLE_DEBUG;
+}
+
+template <>
+template <>
+inline bool
 is_a_helper <glabel *>::test (gimple *gs)
 {
   return gs->code == GIMPLE_LABEL;
@@ -1276,10 +1294,10 @@ gimple *gimple_build_resx (int);
 gswitch *gimple_build_switch_nlabels (unsigned, tree, tree);
 gswitch *gimple_build_switch (tree, tree, vec<tree> );
 gimple *gimple_build_eh_dispatch (int);
-gimple *gimple_build_debug_bind_stat (tree, tree, gimple *MEM_STAT_DECL);
+gdebug *gimple_build_debug_bind_stat (tree, tree, gimple *MEM_STAT_DECL);
 #define gimple_build_debug_bind(var,val,stmt)			\
   gimple_build_debug_bind_stat ((var), (val), (stmt) MEM_STAT_INFO)
-gimple *gimple_build_debug_source_bind_stat (tree, tree, gimple *MEM_STAT_DECL);
+gdebug *gimple_build_debug_source_bind_stat (tree, tree, gimple *MEM_STAT_DECL);
 #define gimple_build_debug_source_bind(var,val,stmt)			\
   gimple_build_debug_source_bind_stat ((var), (val), (stmt) MEM_STAT_INFO)
 gimple *gimple_build_omp_critical (gimple_seq, tree);
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index b425748..9f1901e 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1465,15 +1465,16 @@ remap_gimple_stmt (gimple *stmt, copy_body_data *id)
 
       if (gimple_debug_bind_p (stmt))
 	{
-	  copy = gimple_build_debug_bind (gimple_debug_bind_get_var (stmt),
-					  gimple_debug_bind_get_value (stmt),
-					  stmt);
+	  gdebug *copy =
+	    gimple_build_debug_bind (gimple_debug_bind_get_var (stmt),
+				     gimple_debug_bind_get_value (stmt),
+				     stmt);
 	  id->debug_stmts.safe_push (copy);
 	  return copy;
 	}
       if (gimple_debug_source_bind_p (stmt))
 	{
-	  copy = gimple_build_debug_source_bind
+	  gdebug *copy = gimple_build_debug_source_bind
 		   (gimple_debug_source_bind_get_var (stmt),
 		    gimple_debug_source_bind_get_value (stmt), stmt);
 	  id->debug_stmts.safe_push (copy);
@@ -2273,7 +2274,8 @@ maybe_move_debug_stmts_to_successors (copy_body_data *id, basic_block new_bb)
       gimple_stmt_iterator dsi = gsi_after_labels (e->dest);
       while (is_gimple_debug (gsi_stmt (ssi)))
 	{
-	  gimple *stmt = gsi_stmt (ssi), *new_stmt;
+	  gimple *stmt = gsi_stmt (ssi);
+	  gdebug *new_stmt;
 	  tree var;
 	  tree value;
 
@@ -2604,7 +2606,7 @@ copy_cfg_body (copy_body_data * id, gcov_type count, int frequency_scale,
    this arises, we drop the VALUE expression altogether.  */
 
 static void
-copy_debug_stmt (gimple *stmt, copy_body_data *id)
+copy_debug_stmt (gdebug *stmt, copy_body_data *id)
 {
   tree t, *n;
   struct walk_stmt_info wi;
@@ -2696,7 +2698,7 @@ static void
 copy_debug_stmts (copy_body_data *id)
 {
   size_t i;
-  gimple *stmt;
+  gdebug *stmt;
 
   if (!id->debug_stmts.exists ())
     return;
diff --git a/gcc/tree-inline.h b/gcc/tree-inline.h
index 595c0fb..61dea6a 100644
--- a/gcc/tree-inline.h
+++ b/gcc/tree-inline.h
@@ -124,7 +124,7 @@ struct copy_body_data
   bitmap blocks_to_copy;
 
   /* Debug statements that need processing.  */
-  vec<gimple *> debug_stmts;
+  vec<gdebug *> debug_stmts;
 
   /* A map from local declarations in the inlined function to
      equivalents in the function into which it is being inlined, where
-- 
1.8.5.3

