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]

[patch] Do not clobber bb->aux when computing reachability in the CFG.



When we compute reachability in find_unreachable_blocks(), we use
bb->aux to flag if a block is reachable or not.  

I would like to use this function in the tree CFG, but clobbering
bb->aux destroys important annotations that the tree CFG pass
stores in each block.

This patch adds a new flag 'reachable' to basic_block.  The
clearing of bb->aux has been moved to cleanup_cfg().  Also, the
static function expunge_block() can be re-used in the tree CFG
code.

Bootstrapped and regression tested on i686.



	* basic-block.h (basic_block): Add new field 'reachable'.
	(expunge_block): Declare.
	* flow.c (ENTRY_BLOCK_PTR): Initialize field 'reachable'.
	(EXIT_BLOCK_PTR): Ditto.
	(expunge_block): Remove static declaration.
	(cleanup_cfg): Clear bb->aux on every basic block.
	(find_unreachable_blocks): Use field 'reachable' when computing
	reachability.
	(delete_unreachable_blocks): Use field 'reachable'. 

Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/basic-block.h,v
retrieving revision 1.111
diff -d -p -d -c -p -r1.111 basic-block.h
*** basic-block.h	2001/08/06 06:39:20	1.111
--- basic-block.h	2001/08/09 13:14:11
*************** typedef struct basic_block_def {
*** 218,223 ****
--- 218,227 ----
  
    /* Expected frequency.  Normalized to be in range 0 to BB_FREQ_MAX.  */
    int frequency;
+ 
+   /* Reachability flag.  Set to non-zero if this block is reachable from
+      the flowgraph's entry node.  */
+   int reachable;
  } *basic_block;
  
  #define BB_FREQ_MAX 10000
*************** extern void debug_regset		PARAMS ((regse
*** 609,614 ****
--- 613,619 ----
  extern void allocate_reg_life_data      PARAMS ((void));
  extern void allocate_bb_life_data	PARAMS ((void));
  extern void find_unreachable_blocks	PARAMS ((void));
+ extern void expunge_block		PARAMS ((basic_block));
  extern void delete_noop_moves		PARAMS ((rtx));
  extern rtx last_loop_beg_note		PARAMS ((rtx));
  extern basic_block redirect_edge_and_branch_force PARAMS ((edge, basic_block));
Index: flow.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/flow.c,v
retrieving revision 1.461
diff -d -p -d -c -p -r1.461 flow.c
*** flow.c	2001/08/08 22:06:47	1.461
--- flow.c	2001/08/09 13:14:12
*************** struct basic_block_def entry_exit_blocks
*** 208,214 ****
      ENTRY_BLOCK,		/* index */
      0,				/* loop_depth */
      0,				/* count */
!     0				/* frequency */
    },
    {
      NULL,			/* head */
--- 208,215 ----
      ENTRY_BLOCK,		/* index */
      0,				/* loop_depth */
      0,				/* count */
!     0,				/* frequency */
!     0				/* reachability */
    },
    {
      NULL,			/* head */
*************** struct basic_block_def entry_exit_blocks
*** 225,231 ****
      EXIT_BLOCK,			/* index */
      0,				/* loop_depth */
      0,				/* count */
!     0				/* frequency */
    }
  };
  
--- 226,233 ----
      EXIT_BLOCK,			/* index */
      0,				/* loop_depth */
      0,				/* count */
!     0,				/* frequency */
!     0				/* reachability */
    }
  };
  
*************** static void commit_one_edge_insertion	PA
*** 383,389 ****
  
  static void delete_unreachable_blocks	PARAMS ((void));
  static int can_delete_note_p		PARAMS ((rtx));
- static void expunge_block		PARAMS ((basic_block));
  static int can_delete_label_p		PARAMS ((rtx));
  static int tail_recursion_label_p	PARAMS ((rtx));
  static int merge_blocks_move_predecessor_nojumps PARAMS ((basic_block,
--- 385,390 ----
*************** void
*** 1030,1035 ****
--- 1031,1038 ----
  cleanup_cfg (mode)
       int mode;
  {
+   int i;
+ 
    timevar_push (TV_CLEANUP_CFG);
    delete_unreachable_blocks ();
    if (try_optimize_cfg (mode))
*************** cleanup_cfg (mode)
*** 1040,1045 ****
--- 1043,1052 ----
    free_EXPR_LIST_list (&label_value_list);
    free_EXPR_LIST_list (&tail_recursion_label_list);
    timevar_pop (TV_CLEANUP_CFG);
+ 
+   /* Clear bb->aux on all basic blocks.  */
+   for (i = 0; i < n_basic_blocks; ++i)
+     BASIC_BLOCK (i)->aux = NULL;
  }
  
  /* Create a new basic block consisting of the instructions between
*************** flow_call_edges_add (blocks)
*** 2640,2647 ****
    return blocks_split;
  }
  
! /* Find unreachable blocks.  An unreachable block will have NULL in
!    block->aux, a non-NULL value indicates the block is reachable.  */
  
  void
  find_unreachable_blocks ()
--- 2647,2654 ----
    return blocks_split;
  }
  
! /* Find unreachable blocks.  An unreachable block will have 0 in
!    block->reachable, a non-zero value indicates the block is reachable.  */
  
  void
  find_unreachable_blocks ()
*************** find_unreachable_blocks ()
*** 2653,2662 ****
    n = n_basic_blocks;
    tos = worklist = (basic_block *) xmalloc (sizeof (basic_block) * n);
  
!   /* Use basic_block->aux as a marker.  Clear them all.  */
  
    for (i = 0; i < n; ++i)
!     BASIC_BLOCK (i)->aux = NULL;
  
    /* Add our starting points to the worklist.  Almost always there will
       be only one.  It isn't inconcievable that we might one day directly
--- 2660,2669 ----
    n = n_basic_blocks;
    tos = worklist = (basic_block *) xmalloc (sizeof (basic_block) * n);
  
!   /* Clear all the reachability flags.  */
  
    for (i = 0; i < n; ++i)
!     BASIC_BLOCK (i)->reachable = 0;
  
    /* Add our starting points to the worklist.  Almost always there will
       be only one.  It isn't inconcievable that we might one day directly
*************** find_unreachable_blocks ()
*** 2667,2673 ****
        *tos++ = e->dest;
  
        /* Mark the block with a handy non-null value.  */
!       e->dest->aux = e;
      }
  
    /* Iterate: find everything reachable from what we've already seen.  */
--- 2674,2680 ----
        *tos++ = e->dest;
  
        /* Mark the block with a handy non-null value.  */
!       e->dest->reachable = 1;
      }
  
    /* Iterate: find everything reachable from what we've already seen.  */
*************** find_unreachable_blocks ()
*** 2677,2686 ****
        basic_block b = *--tos;
  
        for (e = b->succ; e; e = e->succ_next)
! 	if (!e->dest->aux)
  	  {
  	    *tos++ = e->dest;
! 	    e->dest->aux = e;
  	  }
      }
  
--- 2684,2693 ----
        basic_block b = *--tos;
  
        for (e = b->succ; e; e = e->succ_next)
! 	if (!e->dest->reachable)
  	  {
  	    *tos++ = e->dest;
! 	    e->dest->reachable = 1;
  	  }
      }
  
*************** delete_unreachable_blocks ()
*** 2703,2712 ****
      {
        basic_block b = BASIC_BLOCK (i);
  
!       if (b->aux != NULL)
! 	/* This block was found.  Tidy up the mark.  */
! 	b->aux = NULL;
!       else
  	flow_delete_block (b);
      }
  
--- 2710,2716 ----
      {
        basic_block b = BASIC_BLOCK (i);
  
!       if (!b->reachable)
  	flow_delete_block (b);
      }
  
*************** flow_delete_block (b)
*** 2842,2848 ****
  
  /* Remove block B from the basic block array and compact behind it.  */
  
! static void
  expunge_block (b)
       basic_block b;
  {
--- 2846,2852 ----
  
  /* Remove block B from the basic block array and compact behind it.  */
  
! void
  expunge_block (b)
       basic_block b;
  {


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