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]

verify_flow_info improvements.


Hi
The notes are easy to damage with no obvious problems with the resulting
code, so it is good to check them.
This code adds some of the checking stuff to verify_flow_info.

Wed Oct 20 18:11:23 MET DST 1999  Jan Hubicka  <hubicka@freesoft.cz>Q

	* flow.c (note_inside_basic_block): New function
	(verify_flow_info): Do more checking for notes.

*** flow.c.old	Wed Oct 20 16:11:17 1999
--- flow.c	Wed Oct 20 18:09:44 1999
*************** set_block_num (insn, bb)
*** 5803,5808 ****
--- 5801,5843 ----
    set_block_for_insn (insn, BASIC_BLOCK (bb));
  }
  
+ /* Return 2 if note must be inside basic block,
+    1 if it can be and 0 if it can't be.  */
+ static int
+ note_inside_basic_block (x)
+     rtx x;
+ {
+   if (NOTE_LINE_NUMBER (x) > 0)
+     return 1;
+   switch (NOTE_LINE_NUMBER (x))
+     {
+        case NOTE_INSN_BASIC_BLOCK:
+ 	return 0;
+        /* We will probably want to make rules more strict for this insns,
+ 	  but for now all those insns appears both inside and outside of
+ 	  basic blocks.  */
+        case NOTE_INSN_DELETED_LABEL:
+        case NOTE_INSN_LOOP_BEG:
+        case NOTE_INSN_LOOP_END:
+        case NOTE_INSN_DELETED:
+        case NOTE_INSN_LOOP_CONT:
+        case NOTE_INSN_BLOCK_BEG:
+        case NOTE_INSN_BLOCK_END:
+        case NOTE_INSN_PROLOGUE_END:
+        case NOTE_INSN_EPILOGUE_BEG:
+        case NOTE_INSN_FUNCTION_BEG:
+        case NOTE_INSN_LOOP_VTOP:
+        case NOTE_INSN_FUNCTION_END:
+        case NOTE_INSN_EH_REGION_BEG:
+        case NOTE_INSN_EH_REGION_END:
+ 	return 1;
+        case NOTE_INSN_SETJMP:
+ 	return 2;
+        default:
+ 	error ("Unknown note number: %i.",NOTE_LINE_NUMBER (x));
+ 	abort();
+     }
+ }
  /* Verify the CFG consistency.  This function check some CFG invariants and
     aborts when something is wrong.  Hope that this function will help to
     convert many optimization passes to preserve CFG consistent.
*************** verify_flow_info ()
*** 5830,5835 ****
--- 5865,5873 ----
    basic_block *bb_info;
    rtx x;
    int i, err = 0;
+   int block_nest = 0;
+   int loop_nest = 0;
+   int eh_region_nest = 0;
  
    bb_info = (basic_block *) alloca (max_uid * sizeof (basic_block));
    memset (bb_info, 0, max_uid * sizeof (basic_block));
*************** verify_flow_info ()
*** 5969,5978 ****
  	  x = NEXT_INSN (x);
  	  while (x)
  	    {
! 	      if (GET_CODE (x) == NOTE
! 		  && NOTE_LINE_NUMBER (x) == NOTE_INSN_BASIC_BLOCK)
  		{
! 		  error ("NOTE_INSN_BASIC_BLOCK %d in the middle of basic block %d",
  			 INSN_UID (x), bb->index);
  		  err = 1;
  		}
--- 6007,6016 ----
  	  x = NEXT_INSN (x);
  	  while (x)
  	    {
! 	      if (GET_CODE (x) == NOTE 
! 		  && !note_inside_basic_block (x))
  		{
! 		  error ("Prohibited note %d in the middle of basic block %d",
  			 INSN_UID (x), bb->index);
  		  err = 1;
  		}
*************** verify_flow_info ()
*** 5996,6007 ****
--- 6034,6091 ----
    x = rtx_first;
    while (x)
      {
+       if (GET_CODE (x) == NOTE)
+ 	{
+ 	  switch (NOTE_LINE_NUMBER (x))
+ 	    {
+ 	      case NOTE_INSN_LOOP_BEG: 
+ 		loop_nest++;
+ 		break;
+ 	      case NOTE_INSN_LOOP_END:
+ 		loop_nest--;
+ 		if (loop_nest < 0)
+ 		  {
+ 		    error ("NOTE_INSN_LOOP_END %d is not paired:", INSN_UID (x));
+ 		    err = 1;
+ 		  }
+ 		break;
+ 	      case NOTE_INSN_BLOCK_BEG:
+ 		block_nest++;
+ 		break;
+ 	      case NOTE_INSN_BLOCK_END:
+ 		block_nest--;
+ 		if (block_nest < 0)
+ 		  {
+ 		    error ("NOTE_INSN_BLOCK_END %d is not paired:", INSN_UID (x));
+ 		    err = 1;
+ 		  }
+ 		break;
+ 	      case NOTE_INSN_EH_REGION_BEG:
+ 		eh_region_nest++;
+ 		break;
+ 	      case NOTE_INSN_EH_REGION_END:
+ 		eh_region_nest--;
+ 		if (eh_region_nest < 0)
+ 		  {
+ 		    error ("NOTE_INSN_EH_REGION_END %d is not paired:", INSN_UID (x));
+ 		    err = 1;
+ 		  }
+ 		break;
+ 	    }
+ 	}
        if (!bb_info[INSN_UID (x)])
  	{
  	  switch (GET_CODE (x))
  	    {
  	    case BARRIER:
+ 	      break;
  	    case NOTE:
+ 	      if (note_inside_basic_block (x) == 2)
+ 		{
+ 		  error ("Prohibited note %d outsite basic block.",
+ 			 INSN_UID (x));
+ 		  err = 1;
+ 		}
  	      break;
  
  	    case CODE_LABEL:
*************** verify_flow_info ()
*** 6023,6028 ****
--- 6107,6127 ----
  	}
  
        x = NEXT_INSN (x);
+     }
+   if (loop_nest)
+     {
+       error ("%i NOTE_INSN_LOOP_BEG not paired.", loop_nest);
+       err = 1;
+     }
+   if (block_nest)
+     {
+       error ("%i NOTE_INSN_BLOCK_END not paired.", block_nest);
+       err = 1;
+     }
+   if (eh_region_nest)
+     {
+       error ("%i NOTE_INSN_EH_REGION_END not paired.", eh_region_nest);
+       err = 1;
      }
  
    if (err)


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