Small improvements to coverage info (3/n)

Message ID 7409263.WKbt3tlcc9@polaris
State New
Headers show
Series
  • Small improvements to coverage info (3/n)
Related show

Commit Message

Eric Botcazou July 8, 2019, 9:32 a.m.
Hi,

a couple of fixes for the RTL middle-end this time, with the same goal of 
preventing instructions from inheriting random source location information 
in the debug info generated by the compiler.

Tested on x86_64-suse-linux, both GCC and GDB, OK for mainline?


2019-07-08  Eric Botcazou  <ebotcazou@adacore.com>

	* emit-rtl.c (set_insn_locations): New function moved from...
	* function.c (set_insn_locations): ...here.
	* ira-emit.c (emit_moves): Propagate location of the first instruction
	to the inserted move instructions.
	* reg-stack.c (compensate_edge): Set the location if the sequence is
	inserted on the edge.
	* rtl.h (set_insn_locations): Declare.

-- 
Eric Botcazou

Comments

Jeff Law July 8, 2019, 6:38 p.m. | #1
On 7/8/19 3:32 AM, Eric Botcazou wrote:
> Hi,

> 

> a couple of fixes for the RTL middle-end this time, with the same goal of 

> preventing instructions from inheriting random source location information 

> in the debug info generated by the compiler.

> 

> Tested on x86_64-suse-linux, both GCC and GDB, OK for mainline?

> 

> 

> 2019-07-08  Eric Botcazou  <ebotcazou@adacore.com>

> 

> 	* emit-rtl.c (set_insn_locations): New function moved from...

> 	* function.c (set_insn_locations): ...here.

> 	* ira-emit.c (emit_moves): Propagate location of the first instruction

> 	to the inserted move instructions.

> 	* reg-stack.c (compensate_edge): Set the location if the sequence is

> 	inserted on the edge.

> 	* rtl.h (set_insn_locations): Declare.

OK
jeff
Eric Botcazou July 9, 2019, 9:58 a.m. | #2
> 2019-07-08  Eric Botcazou  <ebotcazou@adacore.com>

> 

> 	* emit-rtl.c (set_insn_locations): New function moved from...

> 	* function.c (set_insn_locations): ...here.

> 	* ira-emit.c (emit_moves): Propagate location of the first instruction

> 	to the inserted move instructions.

> 	* reg-stack.c (compensate_edge): Set the location if the sequence is

> 	inserted on the edge.

> 	* rtl.h (set_insn_locations): Declare.


Jeff privately pointed out that the emit_moves change is not stable wrt debug 
insns so I have tested and installed the following fix, modelled on what was 
done for emit_to_new_bb_before.


	* ira-emit.c (emit_moves): Skip DEBUG_INSNs when setting the location.

-- 
Eric Botcazou
Index: ira-emit.c
===================================================================
--- ira-emit.c	(revision 273247)
+++ ira-emit.c	(working copy)
@@ -997,27 +997,30 @@ emit_moves (void)
   basic_block bb;
   edge_iterator ei;
   edge e;
-  rtx_insn *insns, *tmp;
+  rtx_insn *insns, *tmp, *next;
 
   FOR_EACH_BB_FN (bb, cfun)
     {
       if (at_bb_start[bb->index] != NULL)
 	{
 	  at_bb_start[bb->index] = modify_move_list (at_bb_start[bb->index]);
-	  insns = emit_move_list (at_bb_start[bb->index],
-				  REG_FREQ_FROM_BB (bb));
+	  insns
+	    = emit_move_list (at_bb_start[bb->index], REG_FREQ_FROM_BB (bb));
 	  tmp = BB_HEAD (bb);
 	  if (LABEL_P (tmp))
 	    tmp = NEXT_INSN (tmp);
 	  if (NOTE_INSN_BASIC_BLOCK_P (tmp))
 	    tmp = NEXT_INSN (tmp);
-	  /* Propagate the location of the current first instruction to the
-	     moves so that they don't inherit a random location.  */
-	  if (tmp != NULL_RTX && INSN_P (tmp))
-	    set_insn_locations (insns, INSN_LOCATION (tmp));
+	  /* Make sure to put the location of TMP or a subsequent instruction
+	     to avoid inheriting the location of the previous instruction.  */
+	  next = tmp;
+	  while (next && !NONDEBUG_INSN_P (next))
+	    next = NEXT_INSN (next);
+	  if (next)
+	    set_insn_locations (insns, INSN_LOCATION (next));
 	  if (tmp == BB_HEAD (bb))
 	    emit_insn_before (insns, tmp);
-	  else if (tmp != NULL_RTX)
+	  else if (tmp)
 	    emit_insn_after (insns, PREV_INSN (tmp));
 	  else
 	    emit_insn_after (insns, get_last_insn ());

Patch

Index: emit-rtl.c
===================================================================
--- emit-rtl.c	(revision 273133)
+++ emit-rtl.c	(working copy)
@@ -6582,6 +6582,18 @@  curr_insn_location (void)
   return curr_location;
 }
 
+/* Set the location of the insn chain starting at INSN to LOC.  */
+void
+set_insn_locations (rtx_insn *insn, location_t loc)
+{
+  while (insn)
+    {
+      if (INSN_P (insn))
+	INSN_LOCATION (insn) = loc;
+      insn = NEXT_INSN (insn);
+    }
+}
+
 /* Return lexical scope block insn belongs to.  */
 tree
 insn_scope (const rtx_insn *insn)
Index: function.c
===================================================================
--- function.c	(revision 273133)
+++ function.c	(working copy)
@@ -5244,19 +5244,6 @@  use_return_register (void)
   diddle_return_value (do_use_return_reg, NULL);
 }
 
-/* Set the location of the insn chain starting at INSN to LOC.  */
-
-static void
-set_insn_locations (rtx_insn *insn, int loc)
-{
-  while (insn != NULL)
-    {
-      if (INSN_P (insn))
-	INSN_LOCATION (insn) = loc;
-      insn = NEXT_INSN (insn);
-    }
-}
-
 /* Generate RTL for the end of the current function.  */
 
 void
Index: ira-emit.c
===================================================================
--- ira-emit.c	(revision 273133)
+++ ira-emit.c	(working copy)
@@ -1011,6 +1011,10 @@  emit_moves (void)
 	    tmp = NEXT_INSN (tmp);
 	  if (NOTE_INSN_BASIC_BLOCK_P (tmp))
 	    tmp = NEXT_INSN (tmp);
+	  /* Propagate the location of the current first instruction to the
+	     moves so that they don't inherit a random location.  */
+	  if (tmp != NULL_RTX && INSN_P (tmp))
+	    set_insn_locations (insns, INSN_LOCATION (tmp));
 	  if (tmp == BB_HEAD (bb))
 	    emit_insn_before (insns, tmp);
 	  else if (tmp != NULL_RTX)
Index: reg-stack.c
===================================================================
--- reg-stack.c	(revision 273133)
+++ reg-stack.c	(working copy)
@@ -2929,6 +2929,7 @@  compensate_edge (edge e)
       seq = get_insns ();
       end_sequence ();
 
+      set_insn_locations (seq, e->goto_locus);
       insert_insn_on_edge (seq, e);
       return true;
     }
Index: rtl.h
===================================================================
--- rtl.h	(revision 273133)
+++ rtl.h	(working copy)
@@ -4338,6 +4338,7 @@  extern void insn_locations_init (void);
 extern void insn_locations_finalize (void);
 extern void set_curr_insn_location (location_t);
 extern location_t curr_insn_location (void);
+extern void set_insn_locations (rtx_insn *, location_t);
 
 /* rtl-error.c */
 extern void _fatal_insn_not_found (const_rtx, const char *, int, const char *)