public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] generate EH info for volatile asm statements (PR inline-asm/93981)
@ 2020-03-05 16:49 J.W. Jagersma
  2020-03-06  8:55 ` Richard Biener
  0 siblings, 1 reply; 44+ messages in thread
From: J.W. Jagersma @ 2020-03-05 16:49 UTC (permalink / raw)
  To: gcc-patches; +Cc: J.W. Jagersma

The following patch extends the generation of exception handling
information to cover volatile asms too.  This was already mostly
implemented, and only very minor changes are required in order to make
it work.

The change in rewrite_stmt is necessary because it inserts debug
statements after the asm, and this causes the gimple verification pass
to fail.  This code is copied from maybe_register_def which does the
same thing.  Alternatively the verification routines could be made to
ignore debug statements at the end of a block.

gcc/
2020-03-05  Jan W. Jagersma  <jwjagersma@gmail.com>

	PR inline-asm/93981
	* tree-cfg.c (make_edges_bb): Call make_eh_edges for case
	GIMPLE_ASM.
	* tree-eh.c (lower_eh_constructs_2): Add case for GIMPLE_ASM.
	* tree-into-ssa.c (rewrite_stmt): For bb-ending stmts, insert
	debug notes on the fallthrough edge.  Code and comments copied
	verbatim from maybe_register_def.
---
 gcc/tree-cfg.c      |  2 ++
 gcc/tree-eh.c       |  3 +++
 gcc/tree-into-ssa.c | 38 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index f7b817d94e6..c21a7978493 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -913,6 +913,8 @@ make_edges_bb (basic_block bb, struct omp_region **pcur_region, int *pomp_index)
       break;
 
     case GIMPLE_ASM:
+      if (stmt_can_throw_internal (cfun, last))
+	make_eh_edges (last);
       make_gimple_asm_edges (bb);
       fallthru = true;
       break;
diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c
index 2a409dcaffe..8314db00922 100644
--- a/gcc/tree-eh.c
+++ b/gcc/tree-eh.c
@@ -2077,6 +2077,9 @@ lower_eh_constructs_2 (struct leh_state *state, gimple_stmt_iterator *gsi)
 	    DECL_GIMPLE_REG_P (tmp) = 1;
 	  gsi_insert_after (gsi, s, GSI_SAME_STMT);
 	}
+      /* FALLTHRU */
+
+    case GIMPLE_ASM:
       /* Look for things that can throw exceptions, and record them.  */
       if (state->cur_region && stmt_could_throw_p (cfun, stmt))
 	{
diff --git a/gcc/tree-into-ssa.c b/gcc/tree-into-ssa.c
index 6528acac31a..03bc1d52cfa 100644
--- a/gcc/tree-into-ssa.c
+++ b/gcc/tree-into-ssa.c
@@ -1415,7 +1415,43 @@ rewrite_stmt (gimple_stmt_iterator *si)
 	if (tracked_var)
 	  {
 	    gimple *note = gimple_build_debug_bind (tracked_var, name, stmt);
-	    gsi_insert_after (si, note, GSI_SAME_STMT);
+	    /* If stmt ends the bb, insert the debug stmt on the single
+	       non-EH edge from the stmt.  */
+	    if (gsi_one_before_end_p (*si) && stmt_ends_bb_p (stmt))
+	      {
+		basic_block bb = gsi_bb (*si);
+		edge_iterator ei;
+		edge e, ef = NULL;
+		FOR_EACH_EDGE (e, ei, bb->succs)
+		  if (!(e->flags & EDGE_EH))
+		    {
+		      gcc_checking_assert (!ef);
+		      ef = e;
+		    }
+		/* If there are other predecessors to ef->dest, then
+		   there must be PHI nodes for the modified
+		   variable, and therefore there will be debug bind
+		   stmts after the PHI nodes.  The debug bind notes
+		   we'd insert would force the creation of a new
+		   block (diverging codegen) and be redundant with
+		   the post-PHI bind stmts, so don't add them.
+
+		   As for the exit edge, there wouldn't be redundant
+		   bind stmts, but there wouldn't be a PC to bind
+		   them to either, so avoid diverging the CFG.  */
+		if (ef && single_pred_p (ef->dest)
+		    && ef->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
+		  {
+		    /* If there were PHI nodes in the node, we'd
+		       have to make sure the value we're binding
+		       doesn't need rewriting.  But there shouldn't
+		       be PHI nodes in a single-predecessor block,
+		       so we just add the note.  */
+		    gsi_insert_on_edge_immediate (ef, note);
+		  }
+	      }
+	    else
+	      gsi_insert_after (si, note, GSI_SAME_STMT);
 	  }
       }
 }
-- 
2.25.1

^ permalink raw reply	[flat|nested] 44+ messages in thread

end of thread, other threads:[~2020-03-24 17:54 UTC | newest]

Thread overview: 44+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 16:49 [PATCH] generate EH info for volatile asm statements (PR inline-asm/93981) J.W. Jagersma
2020-03-06  8:55 ` Richard Biener
2020-03-06 16:13   ` J.W. Jagersma
2020-03-07 17:12   ` [PATCH v2] generate EH info for volatile asm statements (PR93981) J.W. Jagersma
2020-03-07 19:20     ` Segher Boessenkool
2020-03-07 20:43       ` J.W. Jagersma
2020-03-07 20:48         ` Marek Polacek
2020-03-07 21:06           ` J.W. Jagersma
2020-03-07 23:03             ` Segher Boessenkool
2020-03-08 16:18               ` J.W. Jagersma
2020-03-09 22:10                 ` Segher Boessenkool
2020-03-10  1:10                   ` J.W. Jagersma
2020-03-07 20:52         ` Gerald Pfeifer
2020-03-09 12:13         ` Richard Sandiford
2020-03-09 12:54           ` Richard Biener
2020-03-09 18:01             ` Segher Boessenkool
2020-03-09 18:42               ` J.W. Jagersma
2020-03-10  0:25                 ` Segher Boessenkool
2020-03-10  1:12                   ` J.W. Jagersma
2020-03-09 15:49           ` J.W. Jagersma
2020-03-12  9:59             ` Richard Sandiford
2020-03-12 13:08               ` Richard Biener
2020-03-12 15:32                 ` Segher Boessenkool
2020-03-12 18:42                   ` J.W. Jagersma
2020-03-12 19:26                     ` Segher Boessenkool
2020-03-13  1:06                       ` J.W. Jagersma
2020-03-13 15:55                         ` Segher Boessenkool
2020-03-12 22:06               ` J.W. Jagersma
2020-03-13 13:31                 ` Richard Sandiford
2020-03-13 14:58                   ` Segher Boessenkool
2020-03-16 17:47                     ` Richard Sandiford
2020-03-16 19:02                       ` Segher Boessenkool
2020-03-16 19:46                         ` Richard Sandiford
2020-03-16 20:19                           ` Segher Boessenkool
2020-03-17 15:32                           ` Michael Matz
2020-03-18 15:42                             ` J.W. Jagersma
2020-03-19 17:06                               ` Michael Matz
2020-03-20 19:09                                 ` J.W. Jagersma
2020-03-24 17:54                                 ` J.W. Jagersma
2020-03-18 23:56                             ` Segher Boessenkool
2020-03-19 16:42                               ` Michael Matz
2020-03-19 16:59                               ` J.W. Jagersma
2020-03-19 17:17                                 ` Michael Matz
2020-03-13 16:40                   ` J.W. Jagersma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).