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]

Re: [patch] Use bb->flags instead of bb->aux for flags in cfgcleanup.c


On Monday 27 June 2005 00:26, Steven Bosscher wrote:
> Hi,
>
> Just a mechanical cleanup, this one.  But the real motivation for this
> patch is that in a follow-up I want to add some sanity checking for the
> aux field.  If bb->aux is to be pass specific, then it would be nice if
> cleanup_cfg doesn't blindly clean bb->aux, so that verify_flow_info can
> check that bb->aux is properly cleaned by the passes that use it.
>
> Bootstrapped and tested on i686-unknown-linux-gnu.  OK?
>
> Gr.
> Steven

Ehm, eh.


	* basic-block.h: Give the BB flags enum a name, bb_flags.
	Add new flags BB_FORWARDER_BLOCK, and BB_NONTHREADABLE_BLOCK.
	* cfgcleanup.c (enum bb_flags): Remove here.
	(BB_FLAGS, BB_SET_FLAG, BB_CLEAR_FLAG, FORWARDER_BLOCK_P): Remove.
	(notice_new_block): Set/test bb->flags instead of aux via BB_FLAGS.
	(update_forwarder_flag): Likewise.
	(try_simplify_condjump): Likewise.
	(thread_jump): Likewise.
	(try_forward_edges): Likewise.
	(merge_blocks_move): Likewise.
	(outgoing_edges_match): Likewise.
	(try_crossjump_to_edge): Likewise.
	(try_optimize_cfg): Likewise.  Clear bb->flags before updating the
	forwarder flags.  Don't clear bb->aux for all basic blocks.  Only
	reset the BB_FORWARDER_BLOCK and BB_NONTHREADABLE_BLOCK flags.

Index: basic-block.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/basic-block.h,v
retrieving revision 1.266
diff -u -3 -p -r1.266 basic-block.h
--- basic-block.h	25 Jun 2005 01:59:09 -0000	1.266
+++ basic-block.h	26 Jun 2005 22:12:02 -0000
@@ -303,7 +303,7 @@ typedef struct reorder_block_def *reorde
    All other flags may be cleared by clear_bb_flags().  It is generally
    a bad idea to rely on any flags being up-to-date.  */
 
-enum
+enum bb_flags
 {
 
   /* Set if insns in BB have are modified.  Used for updating liveness info.  */
@@ -336,7 +336,15 @@ enum
   BB_DUPLICATED = 256,
 
   /* Set on blocks that are in RTL format.  */
-  BB_RTL = 1024
+  BB_RTL = 1024,
+
+  /* Set on blocks that are forwarder blocks.
+     Only used in cfgcleanup.c.  */
+  BB_FORWARDER_BLOCK = 2048,
+
+  /* Set on blocks that cannot be threaded through.
+     Only used in cfgcleanup.c.  */
+  BB_NONTHREADABLE_BLOCK = 4096
 };
 
 /* Dummy flag for convenience in the hot/cold partitioning code.  */
Index: cfgcleanup.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgcleanup.c,v
retrieving revision 1.148
diff -u -3 -p -r1.148 cfgcleanup.c
--- cfgcleanup.c	25 Jun 2005 01:59:28 -0000	1.148
+++ cfgcleanup.c	26 Jun 2005 22:12:03 -0000
@@ -51,24 +51,6 @@ Software Foundation, 51 Franklin Street,
 #include "cfglayout.h"
 #include "emit-rtl.h"
 
-/* cleanup_cfg maintains following flags for each basic block.  */
-
-enum bb_flags
-{
-    /* Set if BB is the forwarder block to avoid too many
-       forwarder_block_p calls.  */
-    BB_FORWARDER_BLOCK = 1,
-    BB_NONTHREADABLE_BLOCK = 2
-};
-
-#define BB_FLAGS(BB) (enum bb_flags) (BB)->aux
-#define BB_SET_FLAG(BB, FLAG) \
-  (BB)->aux = (void *) (long) ((enum bb_flags) (BB)->aux | (FLAG))
-#define BB_CLEAR_FLAG(BB, FLAG) \
-  (BB)->aux = (void *) (long) ((enum bb_flags) (BB)->aux & ~(FLAG))
-
-#define FORWARDER_BLOCK_P(BB) (BB_FLAGS (BB) & BB_FORWARDER_BLOCK)
-
 /* Set to true when we are running first pass of try_optimize_cfg loop.  */
 static bool first_pass;
 static bool try_crossjump_to_edge (int, edge, edge);
@@ -98,7 +80,7 @@ notice_new_block (basic_block bb)
     return;
 
   if (forwarder_block_p (bb))
-    BB_SET_FLAG (bb, BB_FORWARDER_BLOCK);
+    bb->flags |= BB_FORWARDER_BLOCK;
 }
 
 /* Recompute forwarder flag after block has been modified.  */
@@ -107,9 +89,9 @@ static void
 update_forwarder_flag (basic_block bb)
 {
   if (forwarder_block_p (bb))
-    BB_SET_FLAG (bb, BB_FORWARDER_BLOCK);
+    bb->flags |= BB_FORWARDER_BLOCK;
   else
-    BB_CLEAR_FLAG (bb, BB_FORWARDER_BLOCK);
+    bb->flags &= ~BB_FORWARDER_BLOCK;
 }
 
 /* Simplify a conditional jump around an unconditional jump.
@@ -141,7 +123,7 @@ try_simplify_condjump (basic_block cbran
   jump_block = cbranch_fallthru_edge->dest;
   if (!single_pred_p (jump_block)
       || jump_block->next_bb == EXIT_BLOCK_PTR
-      || !FORWARDER_BLOCK_P (jump_block))
+      || !(jump_block->flags & BB_FORWARDER_BLOCK))
     return false;
   jump_dest_block = single_succ (jump_block);
 
@@ -282,7 +264,7 @@ thread_jump (int mode, edge e, basic_blo
   bool failed = false;
   reg_set_iterator rsi;
 
-  if (BB_FLAGS (b) & BB_NONTHREADABLE_BLOCK)
+  if (b->flags & BB_NONTHREADABLE_BLOCK)
     return NULL;
 
   /* At the moment, we do handle only conditional jumps, but later we may
@@ -291,7 +273,7 @@ thread_jump (int mode, edge e, basic_blo
     return NULL;
   if (EDGE_COUNT (b->succs) != 2)
     {
-      BB_SET_FLAG (b, BB_NONTHREADABLE_BLOCK);
+      b->flags |= BB_NONTHREADABLE_BLOCK;
       return NULL;
     }
 
@@ -301,7 +283,7 @@ thread_jump (int mode, edge e, basic_blo
 
   if (!any_condjump_p (BB_END (b)) || !onlyjump_p (BB_END (b)))
     {
-      BB_SET_FLAG (b, BB_NONTHREADABLE_BLOCK);
+      b->flags |= BB_NONTHREADABLE_BLOCK;
       return NULL;
     }
 
@@ -339,7 +321,7 @@ thread_jump (int mode, edge e, basic_blo
        insn = NEXT_INSN (insn))
     if (INSN_P (insn) && side_effects_p (PATTERN (insn)))
       {
-	BB_SET_FLAG (b, BB_NONTHREADABLE_BLOCK);
+	b->flags |= BB_NONTHREADABLE_BLOCK;
 	return NULL;
       }
 
@@ -383,7 +365,7 @@ thread_jump (int mode, edge e, basic_blo
      have life information in cfg_cleanup.  */
   if (failed)
     {
-      BB_SET_FLAG (b, BB_NONTHREADABLE_BLOCK);
+      b->flags |= BB_NONTHREADABLE_BLOCK;
       goto failed_exit;
     }
 
@@ -479,7 +461,7 @@ try_forward_edges (int mode, basic_block
 	  bool new_target_threaded = false;
 	  may_thread |= target->flags & BB_DIRTY;
 
-	  if (FORWARDER_BLOCK_P (target)
+	  if ((target->flags & BB_FORWARDER_BLOCK)
   	      && !(single_succ_edge (target)->flags & EDGE_CROSSING)
 	      && single_succ (target) != EXIT_BLOCK_PTR)
 	    {
@@ -608,8 +590,8 @@ try_forward_edges (int mode, basic_block
 			     + REG_BR_PROB_BASE / 2)
 			    / REG_BR_PROB_BASE);
 
-	  if (!FORWARDER_BLOCK_P (b) && forwarder_block_p (b))
-	    BB_SET_FLAG (b, BB_FORWARDER_BLOCK);
+	  if (!(b->flags & BB_FORWARDER_BLOCK) && forwarder_block_p (b))
+	    b->flags |= BB_FORWARDER_BLOCK;
 
 	  do
 	    {
@@ -839,7 +821,7 @@ merge_blocks_move (edge e, basic_block b
          eliminated by edge redirection instead.  One exception might have
 	 been if B is a forwarder block and C has no fallthru edge, but
 	 that should be cleaned up by bb-reorder instead.  */
-      if (FORWARDER_BLOCK_P (b) || FORWARDER_BLOCK_P (c))
+      if ((b->flags & BB_FORWARDER_BLOCK) || (c->flags & BB_FORWARDER_BLOCK))
 	return NULL;
 
       /* We must make sure to not munge nesting of lexical blocks,
@@ -1254,19 +1236,19 @@ outgoing_edges_match (int mode, basic_bl
 
       /* Get around possible forwarders on fallthru edges.  Other cases
          should be optimized out already.  */
-      if (FORWARDER_BLOCK_P (f1->dest))
+      if (f1->dest->flags & BB_FORWARDER_BLOCK)
 	f1 = single_succ_edge (f1->dest);
 
-      if (FORWARDER_BLOCK_P (f2->dest))
+      if (f2->dest->flags & BB_FORWARDER_BLOCK)
 	f2 = single_succ_edge (f2->dest);
 
       /* To simplify use of this function, return false if there are
 	 unneeded forwarder blocks.  These will get eliminated later
 	 during cleanup_cfg.  */
-      if (FORWARDER_BLOCK_P (f1->dest)
-	  || FORWARDER_BLOCK_P (f2->dest)
-	  || FORWARDER_BLOCK_P (b1->dest)
-	  || FORWARDER_BLOCK_P (b2->dest))
+      if ((f1->dest->flags & BB_FORWARDER_BLOCK)
+	  || (f2->dest->flags & BB_FORWARDER_BLOCK)
+	  || (b1->dest->flags & BB_FORWARDER_BLOCK)
+	  || (b2->dest->flags & BB_FORWARDER_BLOCK))
 	return false;
 
       if (f1->dest == f2->dest && b1->dest == b2->dest)
@@ -1512,11 +1494,11 @@ try_crossjump_to_edge (int mode, edge e1
      away.  We do this to look past the unconditional jump following a
      conditional jump that is required due to the current CFG shape.  */
   if (single_pred_p (src1)
-      && FORWARDER_BLOCK_P (src1))
+      && (src1->flags & BB_FORWARDER_BLOCK))
     e1 = single_pred_edge (src1), src1 = e1->src;
 
   if (single_pred_p (src2)
-      && FORWARDER_BLOCK_P (src2))
+      && (src2->flags & BB_FORWARDER_BLOCK))
     e2 = single_pred_edge (src2), src2 = e2->src;
 
   /* Nothing to do if we reach ENTRY, or a common source block.  */
@@ -1526,12 +1508,12 @@ try_crossjump_to_edge (int mode, edge e1
     return false;
 
   /* Seeing more than 1 forwarder blocks would confuse us later...  */
-  if (FORWARDER_BLOCK_P (e1->dest)
-      && FORWARDER_BLOCK_P (single_succ (e1->dest)))
+  if ((e1->dest->flags & BB_FORWARDER_BLOCK)
+      && (single_succ (e1->dest)->flags & BB_FORWARDER_BLOCK))
     return false;
 
-  if (FORWARDER_BLOCK_P (e2->dest)
-      && FORWARDER_BLOCK_P (single_succ (e2->dest)))
+  if ((e2->dest->flags & BB_FORWARDER_BLOCK)
+      && (single_succ (e2->dest)->flags & BB_FORWARDER_BLOCK))
     return false;
 
   /* Likewise with dead code (possibly newly created by the other optimizations
@@ -1613,13 +1595,13 @@ try_crossjump_to_edge (int mode, edge e1
       edge_iterator ei;
       basic_block d = s->dest;
 
-      if (FORWARDER_BLOCK_P (d))
+      if (d->flags & BB_FORWARDER_BLOCK)
 	d = single_succ (d);
 
       FOR_EACH_EDGE (s2, ei, src1->succs)
 	{
 	  basic_block d2 = s2->dest;
-	  if (FORWARDER_BLOCK_P (d2))
+	  if (d2->flags & BB_FORWARDER_BLOCK)
 	    d2 = single_succ (d2);
 	  if (d == d2)
 	    break;
@@ -1630,14 +1612,14 @@ try_crossjump_to_edge (int mode, edge e1
       /* Take care to update possible forwarder blocks.  We verified
          that there is no more than one in the chain, so we can't run
          into infinite loop.  */
-      if (FORWARDER_BLOCK_P (s->dest))
+      if (s->dest->flags & BB_FORWARDER_BLOCK)
 	{
 	  single_succ_edge (s->dest)->count += s2->count;
 	  s->dest->count += s2->count;
 	  s->dest->frequency += EDGE_FREQUENCY (s);
 	}
 
-      if (FORWARDER_BLOCK_P (s2->dest))
+      if (s2->dest->flags & BB_FORWARDER_BLOCK)
 	{
 	  single_succ_edge (s2->dest)->count -= s2->count;
 	  if (single_succ_edge (s2->dest)->count < 0)
@@ -1834,12 +1816,12 @@ try_optimize_cfg (int mode)
   if (mode & CLEANUP_CROSSJUMP)
     add_noreturn_fake_exit_edges ();
 
-  FOR_EACH_BB (bb)
-    update_forwarder_flag (bb);
-
   if (mode & (CLEANUP_UPDATE_LIFE | CLEANUP_CROSSJUMP | CLEANUP_THREADING))
     clear_bb_flags ();
 
+  FOR_EACH_BB (bb)
+    update_forwarder_flag (bb);
+
   if (! targetm.cannot_modify_jumps_p ())
     {
       first_pass = true;
@@ -1914,7 +1896,7 @@ try_optimize_cfg (int mode)
 		  && single_pred_p (b)
 		  && (single_pred_edge (b)->flags & EDGE_FALLTHRU)
 		  && !LABEL_P (BB_HEAD (b))
-		  && FORWARDER_BLOCK_P (b)
+		  && (b->flags & BB_FORWARDER_BLOCK)
 		  /* Note that forwarder_block_p true ensures that
 		     there is a successor for this block.  */
 		  && (single_succ_edge (b)->flags & EDGE_FALLTHRU)
@@ -2026,7 +2008,8 @@ try_optimize_cfg (int mode)
   if (mode & CLEANUP_CROSSJUMP)
     remove_fake_exit_edges ();
 
-  clear_aux_for_blocks ();
+  FOR_ALL_BB (b)
+    b->flags &= ~(BB_FORWARDER_BLOCK | BB_NONTHREADABLE_BLOCK);
 
   return changed_overall;
 }


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