From 33bca828ac3c1c6c0ed71fb632b03fe173cce696 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 20 Dec 2013 18:26:43 -0500
Subject: [PATCH 81/88] Concretize gimple_call_set_tail and gimple_call_tail_p

gcc/
	* gimple.h (gimple_call_set_tail): Require a gimple_call.
	(gimple_call_tail_p): Likewise.

	* cfgexpand.c (expand_gimple_tailcall): Likewise.
	(expand_gimple_basic_block): Convert calls to is_gimple_call to a
	dyn_cast, introducing a new "call_stmt" local.

	* trans-mem.c (expand_block_edges): Likewise, for comparison against
	GIMPLE_CALL.

	* tree-inline.c (remap_gimple_stmt): Add checked casts to
	gimple_call in region guarded by is_gimple_call.

	* tree-tailcall.c (optimize_tail_call): Add checked cast to gimple_call
	for t->call_gsi.
---
 gcc/cfgexpand.c     | 13 +++++++------
 gcc/gimple.h        |  6 ++----
 gcc/trans-mem.c     | 20 ++++++++++++--------
 gcc/tree-inline.c   |  4 ++--
 gcc/tree-tailcall.c |  2 +-
 5 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 0715b83..65de5b2 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -3407,7 +3407,7 @@ expand_gimple_stmt (gimple stmt)
    tailcall) and the normal result happens via a sqrt instruction.  */
 
 static basic_block
-expand_gimple_tailcall (basic_block bb, gimple stmt, bool *can_fallthru)
+expand_gimple_tailcall (basic_block bb, gimple_call stmt, bool *can_fallthru)
 {
   rtx_insn *last2, *last;
   edge e;
@@ -5172,15 +5172,16 @@ expand_gimple_basic_block (basic_block bb, bool disable_tail_calls)
 	}
       else
 	{
-	  if (is_gimple_call (stmt)
-	      && gimple_call_tail_p (stmt)
+	  gimple_call call_stmt = dyn_cast <gimple_call> (stmt);
+	  if (call_stmt
+	      && gimple_call_tail_p (call_stmt)
 	      && disable_tail_calls)
-	    gimple_call_set_tail (stmt, false);
+	    gimple_call_set_tail (call_stmt, false);
 
-	  if (is_gimple_call (stmt) && gimple_call_tail_p (stmt))
+	  if (call_stmt && gimple_call_tail_p (call_stmt))
 	    {
 	      bool can_fallthru;
-	      new_bb = expand_gimple_tailcall (bb, stmt, &can_fallthru);
+	      new_bb = expand_gimple_tailcall (bb, call_stmt, &can_fallthru);
 	      if (new_bb)
 		{
 		  if (can_fallthru)
diff --git a/gcc/gimple.h b/gcc/gimple.h
index d37c441..9d09804 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -2808,9 +2808,8 @@ gimple_call_set_arg (gimple gs, unsigned index, tree arg)
    candidate for tail call optimization.  */
 
 static inline void
-gimple_call_set_tail (gimple s, bool tail_p)
+gimple_call_set_tail (gimple_call s, bool tail_p)
 {
-  GIMPLE_CHECK (s, GIMPLE_CALL);
   if (tail_p)
     s->subcode |= GF_CALL_TAILCALL;
   else
@@ -2821,9 +2820,8 @@ gimple_call_set_tail (gimple s, bool tail_p)
 /* Return true if GIMPLE_CALL S is marked as a tail call.  */
 
 static inline bool
-gimple_call_tail_p (gimple s)
+gimple_call_tail_p (gimple_call s)
 {
-  GIMPLE_CHECK (s, GIMPLE_CALL);
   return (s->subcode & GF_CALL_TAILCALL) != 0;
 }
 
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index bdd4a77..0912cc8 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -3111,23 +3111,26 @@ expand_block_edges (struct tm_region *const region, basic_block bb)
   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi = next_gsi)
     {
       gimple stmt = gsi_stmt (gsi);
+      gimple_call call_stmt;
 
       next_gsi = gsi;
       gsi_next (&next_gsi);
 
       // ??? Shouldn't we split for any non-pure, non-irrevocable function?
-      if (gimple_code (stmt) != GIMPLE_CALL
-	  || (gimple_call_flags (stmt) & ECF_TM_BUILTIN) == 0)
+      call_stmt = dyn_cast <gimple_call> (stmt);
+      if ((!call_stmt)
+	  || (gimple_call_flags (call_stmt) & ECF_TM_BUILTIN) == 0)
 	continue;
 
-      if (DECL_FUNCTION_CODE (gimple_call_fndecl (stmt)) == BUILT_IN_TM_ABORT)
+      if (DECL_FUNCTION_CODE (gimple_call_fndecl (call_stmt))
+	  == BUILT_IN_TM_ABORT)
 	{
 	  // If we have a ``_transaction_cancel [[outer]]'', there is only
 	  // one abnormal edge: to the transaction marked OUTER.
 	  // All compiler-generated instances of BUILT_IN_TM_ABORT have a
 	  // constant argument, which we can examine here.  Users invoking
 	  // TM_ABORT directly get what they deserve.
-	  tree arg = gimple_call_arg (stmt, 0);
+	  tree arg = gimple_call_arg (call_stmt, 0);
 	  if (TREE_CODE (arg) == INTEGER_CST
 	      && (TREE_INT_CST_LOW (arg) & AR_OUTERABORT) != 0
 	      && !decl_is_tm_clone (current_function_decl))
@@ -3136,7 +3139,7 @@ expand_block_edges (struct tm_region *const region, basic_block bb)
 	      for (struct tm_region *o = region; o; o = o->outer)
 		if (o->original_transaction_was_outer)
 		  {
-		    split_bb_make_tm_edge (stmt, o->restart_block,
+		    split_bb_make_tm_edge (call_stmt, o->restart_block,
 					   gsi, &next_gsi);
 		    break;
 		  }
@@ -3149,7 +3152,8 @@ expand_block_edges (struct tm_region *const region, basic_block bb)
 
 	  // Non-outer, TM aborts have an abnormal edge to the inner-most
 	  // transaction, the one being aborted;
-	  split_bb_make_tm_edge (stmt, region->restart_block, gsi, &next_gsi);
+	  split_bb_make_tm_edge (call_stmt, region->restart_block, gsi,
+				 &next_gsi);
 	}
 
       // All TM builtins have an abnormal edge to the outer-most transaction.
@@ -3167,14 +3171,14 @@ expand_block_edges (struct tm_region *const region, basic_block bb)
       for (struct tm_region *o = region; o; o = o->outer)
 	if (!o->outer)
 	  {
-            split_bb_make_tm_edge (stmt, o->restart_block, gsi, &next_gsi);
+            split_bb_make_tm_edge (call_stmt, o->restart_block, gsi, &next_gsi);
 	    break;
 	  }
 
       // Delete any tail-call annotation that may have been added.
       // The tail-call pass may have mis-identified the commit as being
       // a candidate because we had not yet added this restart edge.
-      gimple_call_set_tail (stmt, false);
+      gimple_call_set_tail (call_stmt, false);
     }
 }
 
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index 11446d7..84dfea8 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -1549,8 +1549,8 @@ remap_gimple_stmt (gimple stmt, copy_body_data *id)
 
       /* Clear flags that need revisiting.  */
       if (is_gimple_call (copy)
-	  && gimple_call_tail_p (copy))
-	gimple_call_set_tail (copy, false);
+	  && gimple_call_tail_p (as_a <gimple_call> (copy)))
+	gimple_call_set_tail (as_a <gimple_call> (copy), false);
 
       /* Remap the region numbers for __builtin_eh_{pointer,filter},
 	 RESX and EH_DISPATCH.  */
diff --git a/gcc/tree-tailcall.c b/gcc/tree-tailcall.c
index 9bf3c42..b941396 100644
--- a/gcc/tree-tailcall.c
+++ b/gcc/tree-tailcall.c
@@ -920,7 +920,7 @@ optimize_tail_call (struct tailcall *t, bool opt_tailcalls)
 
   if (opt_tailcalls)
     {
-      gimple stmt = gsi_stmt (t->call_gsi);
+      gimple_call stmt = as_a <gimple_call> (gsi_stmt (t->call_gsi));
 
       gimple_call_set_tail (stmt, true);
       cfun->tail_call_marked = true;
-- 
1.8.5.3

