This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Remove more subtle unreachable code


Hi,

There is so much code that's not actually ever executed.  This patch
removes some more:

1) We never have EH_REGION_BEG and EH_REGION_END insn notes until we
   build them in convert_to_eh_region_ranges(), called from passes.c.
2) We only have BLOCK_BEG and BLOCK_END notes in the `final' pass.
   I don't see any good reason for that, but then, I'm not familiar
   with that pass.  Anyway, we should never see them anywhere else.

This patch adds a few checks to make sure those notes don't show up
anywhere else.  Bootstrapped (all languages minus treelang) on amd64,
testing in progress.  OK when it has passed?

Gr.
Steven

	* cfgrtl.c (rtl_delete_block): Fix comment.
	* emit-rtl.c (remove_unnecessary_notes): Die if we see BLOCK_BEG
	or BLOCK_END insn notes.
	* jump.c (squeeze_notes): Likewise.
	* haifa-sched.c (reemit_notes): Don't "re-emit" EH_REGION_BEG and
	EH_REGION_END notes, we never have them to begin with.
	* sched-deps.c (sched_analyze_insn): When updating loop notes,
	verify that we have indeed only recorded loop notes.
	(sched_analyze): Die if we see EH_REGION_BEG or EH_REGION_END notes.
	Only record loop notes.


Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgrtl.c,v
retrieving revision 1.145
diff -u -3 -p -r1.145 cfgrtl.c
--- cfgrtl.c	14 Nov 2004 21:25:37 -0000	1.145
+++ cfgrtl.c	17 Nov 2004 01:29:59 -0000
@@ -368,14 +368,9 @@ rtl_delete_block (basic_block b)
   rtx insn, end, tmp;
 
   /* If the head of this block is a CODE_LABEL, then it might be the
-     label for an exception handler which can't be reached.
-
-     We need to remove the label from the exception_handler_label list
-     and remove the associated NOTE_INSN_EH_REGION_BEG and
-     NOTE_INSN_EH_REGION_END notes.  */
-
+     label for an exception handler which can't be reached.  We need
+     to remove the label from the exception_handler_label list.  */
   insn = BB_HEAD (b);
-
   if (LABEL_P (insn))
     maybe_remove_eh_handler (insn);
 
Index: emit-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/emit-rtl.c,v
retrieving revision 1.424
diff -u -3 -p -r1.424 emit-rtl.c
--- emit-rtl.c	14 Nov 2004 12:55:15 -0000	1.424
+++ emit-rtl.c	17 Nov 2004 01:30:00 -0000
@@ -3690,7 +3690,6 @@ find_line_note (rtx insn)
 void
 remove_unnecessary_notes (void)
 {
-  rtx block_stack = NULL_RTX;
   rtx eh_stack = NULL_RTX;
   rtx insn;
   rtx next;
@@ -3729,66 +3728,17 @@ remove_unnecessary_notes (void)
 	  break;
 
 	case NOTE_INSN_BLOCK_BEG:
-	  /* By now, all notes indicating lexical blocks should have
-	     NOTE_BLOCK filled in.  */
-	  gcc_assert (NOTE_BLOCK (insn));
-	  block_stack = alloc_INSN_LIST (insn, block_stack);
-	  break;
-
 	case NOTE_INSN_BLOCK_END:
-	  /* Too many end notes.  */
-	  gcc_assert (block_stack);
-	  /* Mismatched nesting.  */
-	  gcc_assert (NOTE_BLOCK (XEXP (block_stack, 0)) == NOTE_BLOCK (insn));
-	  tmp = block_stack;
-	  block_stack = XEXP (block_stack, 1);
-	  free_INSN_LIST_node (tmp);
+          /* BLOCK_END and BLOCK_BEG notes only exist in the `final' pass.  */
+          gcc_unreachable ();
 
-	  /* Scan back to see if there are any non-note instructions
-	     between INSN and the beginning of this block.  If not,
-	     then there is no PC range in the generated code that will
-	     actually be in this block, so there's no point in
-	     remembering the existence of the block.  */
-	  for (tmp = PREV_INSN (insn); tmp; tmp = PREV_INSN (tmp))
-	    {
-	      /* This block contains a real instruction.  Note that we
-		 don't include labels; if the only thing in the block
-		 is a label, then there are still no PC values that
-		 lie within the block.  */
-	      if (INSN_P (tmp))
-		break;
-
-	      /* We're only interested in NOTEs.  */
-	      if (!NOTE_P (tmp))
-		continue;
-
-	      if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_BEG)
-		{
-		  /* We just verified that this BLOCK matches us with
-		     the block_stack check above.  Never delete the
-		     BLOCK for the outermost scope of the function; we
-		     can refer to names from that scope even if the
-		     block notes are messed up.  */
-		  if (! is_body_block (NOTE_BLOCK (insn))
-		      && (*debug_hooks->ignore_block) (NOTE_BLOCK (insn)))
-		    {
-		      remove_insn (tmp);
-		      remove_insn (insn);
-		    }
-		  break;
-		}
-	      else if (NOTE_LINE_NUMBER (tmp) == NOTE_INSN_BLOCK_END)
-		/* There's a nested block.  We need to leave the
-		   current block in place since otherwise the debugger
-		   wouldn't be able to show symbols from our block in
-		   the nested block.  */
-		break;
-	    }
+	default:
+	  break;
 	}
     }
 
-  /* Too many begin notes.  */
-  gcc_assert (!block_stack && !eh_stack);
+  /* Too many EH_REGION_BEG notes.  */
+  gcc_assert (!eh_stack);
 }
 
 
Index: haifa-sched.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/haifa-sched.c,v
retrieving revision 1.249
diff -u -3 -p -r1.249 haifa-sched.c
--- haifa-sched.c	20 Jul 2004 07:26:47 -0000	1.249
+++ haifa-sched.c	17 Nov 2004 01:30:00 -0000
@@ -1649,11 +1649,6 @@ reemit_notes (rtx insn, rtx last)
 
 	  last = emit_note_before (note_type, last);
 	  remove_note (insn, note);
-	  note = XEXP (note, 1);
-	  if (note_type == NOTE_INSN_EH_REGION_BEG
-	      || note_type == NOTE_INSN_EH_REGION_END)
-	    NOTE_EH_HANDLER (last) = INTVAL (XEXP (note, 0));
-	  remove_note (insn, note);
 	}
     }
   return retval;
Index: jump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/jump.c,v
retrieving revision 1.251
diff -u -3 -p -r1.251 jump.c
--- jump.c	4 Nov 2004 23:24:45 -0000	1.251
+++ jump.c	17 Nov 2004 01:30:00 -0000
@@ -248,6 +248,10 @@ squeeze_notes (rtx* startp, rtx* endp)
 	      || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
 	      || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END))
 	{
+	  /* BLOCK_BEG or BLOCK_END notes only exist in the `final' pass.  */
+	  gcc_assert (NOTE_LINE_NUMBER (insn) != NOTE_INSN_BLOCK_BEG
+		      && NOTE_LINE_NUMBER (insn) != NOTE_INSN_BLOCK_END);
+
 	  if (insn == start)
 	    start = next;
 	  else
Index: sched-deps.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/sched-deps.c,v
retrieving revision 1.85
diff -u -3 -p -r1.85 sched-deps.c
--- sched-deps.c	15 Nov 2004 22:23:29 -0000	1.85
+++ sched-deps.c	17 Nov 2004 01:30:00 -0000
@@ -981,18 +981,14 @@ sched_analyze_insn (struct deps *deps, r
     {
       rtx link;
 
-      /* Update loop_notes with any notes from this insn.  Also determine
-	 if any of the notes on the list correspond to instruction scheduling
-	 barriers (loop, eh & setjmp notes, but not range notes).  */
+      /* Update loop_notes with any notes from this insn.  */
       link = loop_notes;
       while (XEXP (link, 1))
 	{
-	  if (INTVAL (XEXP (link, 0)) == NOTE_INSN_LOOP_BEG
-	      || INTVAL (XEXP (link, 0)) == NOTE_INSN_LOOP_END
-	      || INTVAL (XEXP (link, 0)) == NOTE_INSN_EH_REGION_BEG
-	      || INTVAL (XEXP (link, 0)) == NOTE_INSN_EH_REGION_END)
-	    reg_pending_barrier = MOVE_BARRIER;
+	  gcc_assert (INTVAL (XEXP (link, 0)) == NOTE_INSN_LOOP_BEG
+		      || INTVAL (XEXP (link, 0)) == NOTE_INSN_LOOP_END);
 
+	  reg_pending_barrier = MOVE_BARRIER;
 	  link = XEXP (link, 1);
 	}
       XEXP (link, 1) = REG_NOTES (insn);
@@ -1328,26 +1324,19 @@ sched_analyze (struct deps *deps, rtx he
 	    deps->in_post_call_group_p = post_call;
 	}
 
+      /* EH_REGION insn notes can not appear until well after we complete
+	 scheduling.  */
+      if (NOTE_P (insn))
+	gcc_assert (NOTE_LINE_NUMBER (insn) != NOTE_INSN_EH_REGION_BEG
+		    && NOTE_LINE_NUMBER (insn) != NOTE_INSN_EH_REGION_END);
+
       /* See comments on reemit_notes as to why we do this.
 	 ??? Actually, the reemit_notes just say what is done, not why.  */
 
       if (NOTE_P (insn)
-	       && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
-		   || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END
-		   || NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
-		   || NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END))
-	{
-	  rtx rtx_region;
-
-	  if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_BEG
-	      || NOTE_LINE_NUMBER (insn) == NOTE_INSN_EH_REGION_END)
-	    rtx_region = GEN_INT (NOTE_EH_HANDLER (insn));
-	  else
-	    rtx_region = const0_rtx;
-
-	  loop_notes = alloc_EXPR_LIST (REG_SAVE_NOTE,
-					rtx_region,
-					loop_notes);
+	  && (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG
+	      || NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END))
+	{
 	  loop_notes = alloc_EXPR_LIST (REG_SAVE_NOTE,
 					GEN_INT (NOTE_LINE_NUMBER (insn)),
 					loop_notes);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]