diff mbox series

[ftracer] Factor out can_duplicate_bb_p

Message ID 39c6a16f-0295-f850-aabe-3e604c959947@suse.de
State New
Headers show
Series [ftracer] Factor out can_duplicate_bb_p | expand

Commit Message

Tom de Vries Oct. 5, 2020, 7:07 a.m. UTC
[ was: Re: [PATCH][omp, ftracer] Don't duplicate blocks in SIMT region ]

On 10/5/20 9:05 AM, Tom de Vries wrote:
> Ack, updated the patch accordingly, and split it up in two bits, one
> that does refactoring, and one that adds the actual caching:
> - [ftracer] Factor out can_duplicate_bb_p
> - [ftracer] Add caching of can_duplicate_bb_p
> 
> I'll post these in reply to this email.
> 

OK?

Thanks,
- Tom

Comments

Richard Biener Oct. 6, 2020, 7:50 a.m. UTC | #1
On Mon, 5 Oct 2020, Tom de Vries wrote:

> [ was: Re: [PATCH][omp, ftracer] Don't duplicate blocks in SIMT region ]
> 
> On 10/5/20 9:05 AM, Tom de Vries wrote:
> > Ack, updated the patch accordingly, and split it up in two bits, one
> > that does refactoring, and one that adds the actual caching:
> > - [ftracer] Factor out can_duplicate_bb_p
> > - [ftracer] Add caching of can_duplicate_bb_p
> > 
> > I'll post these in reply to this email.
> > 
> 
> OK?

OK.

Richard.
diff mbox series

Patch

[ftracer] Factor out can_duplicate_bb_p

Factor out can_duplicate_bb_p out of ignore_bb_p.

Also factor out can_duplicate_insn_p and can_duplicate_bb_no_insn_iter_p to
expose the parts of can_duplicate_bb_p that are per-bb and per-insn.

Bootstrapped and reg-tested on x86_64-linux.

gcc/ChangeLog:

2020-10-05  Tom de Vries  <tdevries@suse.de>

	* tracer.c (can_duplicate_insn_p, can_duplicate_bb_no_insn_iter_p)
	(can_duplicate_bb_p): New function, factored out of ...
	(ignore_bb_p): ... here.

---
 gcc/tracer.c | 74 ++++++++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 50 insertions(+), 24 deletions(-)

diff --git a/gcc/tracer.c b/gcc/tracer.c
index 5e51752d89f..c0e888f6b03 100644
--- a/gcc/tracer.c
+++ b/gcc/tracer.c
@@ -84,49 +84,75 @@  bb_seen_p (basic_block bb)
   return bitmap_bit_p (bb_seen, bb->index);
 }
 
-/* Return true if we should ignore the basic block for purposes of tracing.  */
-bool
-ignore_bb_p (const_basic_block bb)
+/* Return true if gimple stmt G can be duplicated.  */
+static bool
+can_duplicate_insn_p (gimple *g)
+{
+  /* An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be
+     duplicated as part of its group, or not at all.
+     The IFN_GOMP_SIMT_VOTE_ANY is currently part of such a group,
+     so the same holds there, but it could be argued that the
+     IFN_GOMP_SIMT_VOTE_ANY could be generated after that group,
+     in which case it could be duplicated.  */
+  if (is_gimple_call (g)
+      && (gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC)
+	  || gimple_call_internal_p (g, IFN_GOMP_SIMT_EXIT)
+	  || gimple_call_internal_p (g, IFN_GOMP_SIMT_VOTE_ANY)))
+    return false;
+
+  return true;
+}
+
+/* Return true if BB can be duplicated.  Avoid iterating over the insns.  */
+static bool
+can_duplicate_bb_no_insn_iter_p (const_basic_block bb)
 {
   if (bb->index < NUM_FIXED_BLOCKS)
-    return true;
-  if (optimize_bb_for_size_p (bb))
-    return true;
+    return false;
 
   if (gimple *g = last_stmt (CONST_CAST_BB (bb)))
     {
       /* A transaction is a single entry multiple exit region.  It
 	 must be duplicated in its entirety or not at all.  */
       if (gimple_code (g) == GIMPLE_TRANSACTION)
-	return true;
+	return false;
 
       /* An IFN_UNIQUE call must be duplicated as part of its group,
 	 or not at all.  */
       if (is_gimple_call (g)
 	  && gimple_call_internal_p (g)
 	  && gimple_call_internal_unique_p (g))
-	return true;
+	return false;
     }
 
+  return true;
+}
+
+/* Return true if BB can be duplicated.  */
+static bool
+can_duplicate_bb_p (const_basic_block bb)
+{
+  if (!can_duplicate_bb_no_insn_iter_p (bb))
+    return false;
+
   for (gimple_stmt_iterator gsi = gsi_start_bb (CONST_CAST_BB (bb));
        !gsi_end_p (gsi); gsi_next (&gsi))
-    {
-      gimple *g = gsi_stmt (gsi);
-
-      /* An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be
-	 duplicated as part of its group, or not at all.
-	 The IFN_GOMP_SIMT_VOTE_ANY is currently part of such a group,
-	 so the same holds there, but it could be argued that the
-	 IFN_GOMP_SIMT_VOTE_ANY could be generated after that group,
-	 in which case it could be duplicated.  */
-      if (is_gimple_call (g)
-	  && (gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC)
-	      || gimple_call_internal_p (g, IFN_GOMP_SIMT_EXIT)
-	      || gimple_call_internal_p (g, IFN_GOMP_SIMT_VOTE_ANY)))
-	return true;
-    }
+    if (!can_duplicate_insn_p (gsi_stmt (gsi)))
+      return false;
+
+  return true;
+}
+
+/* Return true if we should ignore the basic block for purposes of tracing.  */
+bool
+ignore_bb_p (const_basic_block bb)
+{
+  if (bb->index < NUM_FIXED_BLOCKS)
+    return true;
+  if (optimize_bb_for_size_p (bb))
+    return true;
 
-  return false;
+  return !can_duplicate_bb_p (bb);
 }
 
 /* Return number of instructions in the block.  */