public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, committed] Accessor functions for loops' state flags
@ 2007-08-04  0:58 Zdenek Dvorak
  0 siblings, 0 replies; only message in thread
From: Zdenek Dvorak @ 2007-08-04  0:58 UTC (permalink / raw)
  To: gcc-patches

Hello,

this patch adds functions to test and manipulate the flags describing
the properties of the loops, instead of accessing the flags directly.

Bootstrapped & regtested on i686, committed.

Zdenek

	* tree-ssa-threadupdate.c (thread_through_all_blocks): Use loops' state
	accessor functions.
	* cfgloopmanip.c (remove_path, create_preheaders,
	force_single_succ_latches, fix_loop_structure): Ditto.
	* tree-ssa-loop-manip.c (rewrite_into_loop_closed_ssa,
	tree_duplicate_loop_to_header_edge): Ditto.
	* cfgloopanal.c (mark_irreducible_loops): Ditto.
	* loop-init.c (loop_optimizer_init, loop_optimizer_finalize):
	Ditto.
	* tree-cfgcleanup.c (cleanup_tree_cfg_noloop, repair_loop_structures,
	cleanup_tree_cfg): Ditto.
	* tree-cfg.c (tree_merge_blocks): Ditto.
	* cfgloop.c (rescan_loop_exit, record_loop_exits,
	release_recorded_exits, get_loop_exit_edges, verify_loop_structure,
	loop_preheader_edge, single_exit): Ditto.
	(flow_loops_find): Do not clear loops->state.
	* cfgloop.h (loops_state_satisfies_p, loops_state_set,
	loops_state_clear): New functions.

Index: tree-ssa-threadupdate.c
===================================================================
*** tree-ssa-threadupdate.c	(revision 127118)
--- tree-ssa-threadupdate.c	(working copy)
*************** thread_through_all_blocks (bool may_peel
*** 1077,1083 ****
    threaded_edges = NULL;
  
    if (retval)
!     current_loops->state |= LOOPS_NEED_FIXUP;
  
    return retval;
  }
--- 1077,1083 ----
    threaded_edges = NULL;
  
    if (retval)
!     loops_state_set (LOOPS_NEED_FIXUP);
  
    return retval;
  }
Index: cfgloopmanip.c
===================================================================
*** cfgloopmanip.c	(revision 127116)
--- cfgloopmanip.c	(working copy)
*************** remove_path (edge e)
*** 385,391 ****
    fix_loop_placements (from->loop_father, &irred_invalidated);
  
    if (irred_invalidated
!       && (current_loops->state & LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS) != 0)
      mark_irreducible_loops ();
  
    return true;
--- 385,391 ----
    fix_loop_placements (from->loop_father, &irred_invalidated);
  
    if (irred_invalidated
!       && loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS))
      mark_irreducible_loops ();
  
    return true;
*************** create_preheaders (int flags)
*** 1190,1196 ****
  
    FOR_EACH_LOOP (li, loop, 0)
      create_preheader (loop, flags);
!   current_loops->state |= LOOPS_HAVE_PREHEADERS;
  }
  
  /* Forces all loop latches to have only single successor.  */
--- 1190,1196 ----
  
    FOR_EACH_LOOP (li, loop, 0)
      create_preheader (loop, flags);
!   loops_state_set (LOOPS_HAVE_PREHEADERS);
  }
  
  /* Forces all loop latches to have only single successor.  */
*************** force_single_succ_latches (void)
*** 1211,1217 ****
  
        split_edge (e);
      }
!   current_loops->state |= LOOPS_HAVE_SIMPLE_LATCHES;
  }
  
  /* This function is called from loop_version.  It splits the entry edge
--- 1211,1217 ----
  
        split_edge (e);
      }
!   loops_state_set (LOOPS_HAVE_SIMPLE_LATCHES);
  }
  
  /* This function is called from loop_version.  It splits the entry edge
*************** fix_loop_structure (bitmap changed_bbs)
*** 1390,1397 ****
    bool record_exits = false;
    struct loop **superloop = XNEWVEC (struct loop *, number_of_loops ());
  
-   gcc_assert (current_loops->state & LOOPS_HAVE_SIMPLE_LATCHES);
- 
    /* Remove the old bb -> loop mapping.  Remember the depth of the blocks in
       the loop hierarchy, so that we can recognize blocks whose loop nesting
       relationship has changed.  */
--- 1390,1395 ----
*************** fix_loop_structure (bitmap changed_bbs)
*** 1402,1408 ****
        bb->loop_father = current_loops->tree_root;
      }
  
!   if (current_loops->state & LOOPS_HAVE_RECORDED_EXITS)
      {
        release_recorded_exits ();
        record_exits = true;
--- 1400,1406 ----
        bb->loop_father = current_loops->tree_root;
      }
  
!   if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      {
        release_recorded_exits ();
        record_exits = true;
*************** fix_loop_structure (bitmap changed_bbs)
*** 1464,1476 ****
  	}
      }
  
!   if (current_loops->state & LOOPS_HAVE_PREHEADERS)
      create_preheaders (CP_SIMPLE_PREHEADERS);
  
!   if (current_loops->state & LOOPS_HAVE_SIMPLE_LATCHES)
      force_single_succ_latches ();
  
!   if (current_loops->state & LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)
      mark_irreducible_loops ();
  
    if (record_exits)
--- 1462,1474 ----
  	}
      }
  
!   if (loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS))
      create_preheaders (CP_SIMPLE_PREHEADERS);
  
!   if (loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES))
      force_single_succ_latches ();
  
!   if (loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS))
      mark_irreducible_loops ();
  
    if (record_exits)
Index: tree-ssa-loop-manip.c
===================================================================
*** tree-ssa-loop-manip.c	(revision 127116)
--- tree-ssa-loop-manip.c	(working copy)
*************** rewrite_into_loop_closed_ssa (bitmap cha
*** 365,371 ****
    unsigned i, old_num_ssa_names;
    bitmap names_to_rename;
  
!   current_loops->state |= LOOP_CLOSED_SSA;
    if (number_of_loops () <= 1)
      return;
  
--- 365,371 ----
    unsigned i, old_num_ssa_names;
    bitmap names_to_rename;
  
!   loops_state_set (LOOP_CLOSED_SSA);
    if (number_of_loops () <= 1)
      return;
  
*************** tree_duplicate_loop_to_header_edge (stru
*** 584,592 ****
  {
    unsigned first_new_block;
  
!   if (!(current_loops->state & LOOPS_HAVE_SIMPLE_LATCHES))
      return false;
!   if (!(current_loops->state & LOOPS_HAVE_PREHEADERS))
      return false;
  
  #ifdef ENABLE_CHECKING
--- 584,592 ----
  {
    unsigned first_new_block;
  
!   if (!loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES))
      return false;
!   if (!loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS))
      return false;
  
  #ifdef ENABLE_CHECKING
Index: cfgloopanal.c
===================================================================
*** cfgloopanal.c	(revision 127116)
--- cfgloopanal.c	(working copy)
*************** mark_irreducible_loops (void)
*** 156,162 ****
  
    free_graph (g);
  
!   current_loops->state |= LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS;
  }
  
  /* Counts number of insns inside LOOP.  */
--- 156,162 ----
  
    free_graph (g);
  
!   loops_state_set (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS);
  }
  
  /* Counts number of insns inside LOOP.  */
Index: loop-init.c
===================================================================
*** loop-init.c	(revision 127116)
--- loop-init.c	(working copy)
*************** loop_optimizer_init (unsigned flags)
*** 59,65 ****
  	 passes may want.  */
        gcc_assert ((flags & ~(LOOPS_MAY_HAVE_MULTIPLE_LATCHES
  			     | LOOPS_HAVE_RECORDED_EXITS)) == 0);
!       current_loops->state = LOOPS_MAY_HAVE_MULTIPLE_LATCHES;
      }
    else
      disambiguate_loops_with_multiple_latches ();
--- 59,65 ----
  	 passes may want.  */
        gcc_assert ((flags & ~(LOOPS_MAY_HAVE_MULTIPLE_LATCHES
  			     | LOOPS_HAVE_RECORDED_EXITS)) == 0);
!       loops_state_set (LOOPS_MAY_HAVE_MULTIPLE_LATCHES);
      }
    else
      disambiguate_loops_with_multiple_latches ();
*************** loop_optimizer_finalize (void)
*** 105,111 ****
      }
  
    /* Clean up.  */
!   if (current_loops->state & LOOPS_HAVE_RECORDED_EXITS)
      release_recorded_exits ();
    flow_loops_free (current_loops);
    ggc_free (current_loops);
--- 105,111 ----
      }
  
    /* Clean up.  */
!   if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      release_recorded_exits ();
    flow_loops_free (current_loops);
    ggc_free (current_loops);
Index: tree-cfgcleanup.c
===================================================================
*** tree-cfgcleanup.c	(revision 127121)
--- tree-cfgcleanup.c	(working copy)
*************** cleanup_tree_cfg_noloop (void)
*** 666,672 ****
    timevar_pop (TV_TREE_CLEANUP_CFG);
  
    if (changed && current_loops)
!     current_loops->state |= LOOPS_NEED_FIXUP;
  
    return changed;
  }
--- 666,672 ----
    timevar_pop (TV_TREE_CLEANUP_CFG);
  
    if (changed && current_loops)
!     loops_state_set (LOOPS_NEED_FIXUP);
  
    return changed;
  }
*************** repair_loop_structures (void)
*** 682,688 ****
    /* This usually does nothing.  But sometimes parts of cfg that originally
       were inside a loop get out of it due to edge removal (since they
       become unreachable by back edges from latch).  */
!   if ((current_loops->state & LOOP_CLOSED_SSA) != 0)
      rewrite_into_loop_closed_ssa (changed_bbs, TODO_update_ssa);
  
    BITMAP_FREE (changed_bbs);
--- 682,688 ----
    /* This usually does nothing.  But sometimes parts of cfg that originally
       were inside a loop get out of it due to edge removal (since they
       become unreachable by back edges from latch).  */
!   if (loops_state_satisfies_p (LOOP_CLOSED_SSA))
      rewrite_into_loop_closed_ssa (changed_bbs, TODO_update_ssa);
  
    BITMAP_FREE (changed_bbs);
*************** repair_loop_structures (void)
*** 692,698 ****
  #endif
    scev_reset ();
  
!   current_loops->state &= ~LOOPS_NEED_FIXUP;
  }
  
  /* Cleanup cfg and repair loop structures.  */
--- 692,698 ----
  #endif
    scev_reset ();
  
!   loops_state_clear (LOOPS_NEED_FIXUP);
  }
  
  /* Cleanup cfg and repair loop structures.  */
*************** cleanup_tree_cfg (void)
*** 703,709 ****
    bool changed = cleanup_tree_cfg_noloop ();
  
    if (current_loops != NULL
!       && (current_loops->state & LOOPS_NEED_FIXUP))
      repair_loop_structures ();
  
    return changed;
--- 703,709 ----
    bool changed = cleanup_tree_cfg_noloop ();
  
    if (current_loops != NULL
!       && loops_state_satisfies_p (LOOPS_NEED_FIXUP))
      repair_loop_structures ();
  
    return changed;
Index: cfgloop.c
===================================================================
*** cfgloop.c	(revision 127116)
--- cfgloop.c	(working copy)
*************** flow_loops_find (struct loops *loops)
*** 502,508 ****
    sbitmap_free (headers);
  
    loops->exits = NULL;
-   loops->state = 0;
    return VEC_length (loop_p, loops->larray);
  }
  
--- 502,507 ----
*************** rescan_loop_exit (edge e, bool new_edge,
*** 996,1002 ****
    struct loop_exit *exits = NULL, *exit;
    struct loop *aloop, *cloop;
  
!   if ((current_loops->state & LOOPS_HAVE_RECORDED_EXITS) == 0)
      return;
  
    if (!removed
--- 995,1001 ----
    struct loop_exit *exits = NULL, *exit;
    struct loop *aloop, *cloop;
  
!   if (!loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      return;
  
    if (!removed
*************** record_loop_exits (void)
*** 1054,1062 ****
    if (!current_loops)
      return;
  
!   if (current_loops->state & LOOPS_HAVE_RECORDED_EXITS)
      return;
!   current_loops->state |= LOOPS_HAVE_RECORDED_EXITS;
  
    gcc_assert (current_loops->exits == NULL);
    current_loops->exits = htab_create_alloc (2 * number_of_loops (),
--- 1053,1061 ----
    if (!current_loops)
      return;
  
!   if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      return;
!   loops_state_set (LOOPS_HAVE_RECORDED_EXITS);
  
    gcc_assert (current_loops->exits == NULL);
    current_loops->exits = htab_create_alloc (2 * number_of_loops (),
*************** dump_recorded_exits (FILE *file)
*** 1109,1118 ****
  void
  release_recorded_exits (void)
  {
!   gcc_assert (current_loops->state & LOOPS_HAVE_RECORDED_EXITS);
    htab_delete (current_loops->exits);
    current_loops->exits = NULL;
!   current_loops->state &= ~LOOPS_HAVE_RECORDED_EXITS;
  }
  
  /* Returns the list of the exit edges of a LOOP.  */
--- 1108,1117 ----
  void
  release_recorded_exits (void)
  {
!   gcc_assert (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS));
    htab_delete (current_loops->exits);
    current_loops->exits = NULL;
!   loops_state_clear (LOOPS_HAVE_RECORDED_EXITS);
  }
  
  /* Returns the list of the exit edges of a LOOP.  */
*************** get_loop_exit_edges (const struct loop *
*** 1131,1137 ****
  
    /* If we maintain the lists of exits, use them.  Otherwise we must
       scan the body of the loop.  */
!   if (current_loops->state & LOOPS_HAVE_RECORDED_EXITS)
      {
        for (exit = loop->exits->next; exit->e; exit = exit->next)
  	VEC_safe_push (edge, heap, edges, exit->e);
--- 1130,1136 ----
  
    /* If we maintain the lists of exits, use them.  Otherwise we must
       scan the body of the loop.  */
!   if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      {
        for (exit = loop->exits->next; exit->e; exit = exit->next)
  	VEC_safe_push (edge, heap, edges, exit->e);
*************** verify_loop_structure (void)
*** 1352,1364 ****
      {
        i = loop->num;
  
!       if ((current_loops->state & LOOPS_HAVE_PREHEADERS)
  	  && EDGE_COUNT (loop->header->preds) != 2)
  	{
  	  error ("loop %d's header does not have exactly 2 entries", i);
  	  err = 1;
  	}
!       if (current_loops->state & LOOPS_HAVE_SIMPLE_LATCHES)
  	{
  	  if (!single_succ_p (loop->latch))
  	    {
--- 1351,1363 ----
      {
        i = loop->num;
  
!       if (loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS)
  	  && EDGE_COUNT (loop->header->preds) != 2)
  	{
  	  error ("loop %d's header does not have exactly 2 entries", i);
  	  err = 1;
  	}
!       if (loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES))
  	{
  	  if (!single_succ_p (loop->latch))
  	    {
*************** verify_loop_structure (void)
*** 1381,1387 ****
  	  error ("loop %d's header does not belong directly to it", i);
  	  err = 1;
  	}
!       if ((current_loops->state & LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)
  	  && (loop_latch_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP))
  	{
  	  error ("loop %d's latch is marked as part of irreducible region", i);
--- 1380,1386 ----
  	  error ("loop %d's header does not belong directly to it", i);
  	  err = 1;
  	}
!       if (loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)
  	  && (loop_latch_edge (loop)->flags & EDGE_IRREDUCIBLE_LOOP))
  	{
  	  error ("loop %d's latch is marked as part of irreducible region", i);
*************** verify_loop_structure (void)
*** 1390,1396 ****
      }
  
    /* Check irreducible loops.  */
!   if (current_loops->state & LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS)
      {
        /* Record old info.  */
        irreds = sbitmap_alloc (last_basic_block);
--- 1389,1395 ----
      }
  
    /* Check irreducible loops.  */
!   if (loops_state_satisfies_p (LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS))
      {
        /* Record old info.  */
        irreds = sbitmap_alloc (last_basic_block);
*************** verify_loop_structure (void)
*** 1476,1482 ****
  	    }
  	}
  
!       if ((current_loops->state & LOOPS_HAVE_RECORDED_EXITS) == 0)
  	{
  	  if (loop->exits->next != loop->exits)
  	    {
--- 1475,1481 ----
  	    }
  	}
  
!       if (!loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
  	{
  	  if (loop->exits->next != loop->exits)
  	    {
*************** verify_loop_structure (void)
*** 1487,1493 ****
  	}
      }
  
!   if (current_loops->state & LOOPS_HAVE_RECORDED_EXITS)
      {
        unsigned n_exits = 0, eloops;
  
--- 1486,1492 ----
  	}
      }
  
!   if (loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      {
        unsigned n_exits = 0, eloops;
  
*************** loop_preheader_edge (const struct loop *
*** 1570,1576 ****
    edge e;
    edge_iterator ei;
  
!   gcc_assert ((current_loops->state & LOOPS_HAVE_PREHEADERS) != 0);
  
    FOR_EACH_EDGE (e, ei, loop->header->preds)
      if (e->src != loop->latch)
--- 1569,1575 ----
    edge e;
    edge_iterator ei;
  
!   gcc_assert (loops_state_satisfies_p (LOOPS_HAVE_PREHEADERS));
  
    FOR_EACH_EDGE (e, ei, loop->header->preds)
      if (e->src != loop->latch)
*************** single_exit (const struct loop *loop)
*** 1597,1603 ****
  {
    struct loop_exit *exit = loop->exits->next;
  
!   if ((current_loops->state & LOOPS_HAVE_RECORDED_EXITS) == 0)
      return NULL;
  
    if (exit->e && exit->next == loop->exits)
--- 1596,1602 ----
  {
    struct loop_exit *exit = loop->exits->next;
  
!   if (!loops_state_satisfies_p (LOOPS_HAVE_RECORDED_EXITS))
      return NULL;
  
    if (exit->e && exit->next == loop->exits)
Index: cfgloop.h
===================================================================
*** cfgloop.h	(revision 127118)
--- cfgloop.h	(working copy)
*************** number_of_loops (void)
*** 451,456 ****
--- 451,483 ----
    return VEC_length (loop_p, current_loops->larray);
  }
  
+ /* Returns true if state of the loops satisfies all properties
+    described by FLAGS.  */
+ 
+ static inline bool
+ loops_state_satisfies_p (unsigned flags)
+ {
+   return (current_loops->state & flags) == flags;
+ }
+ 
+ /* Sets FLAGS to the loops state.  */
+ 
+ static inline void
+ loops_state_set (unsigned flags)
+ {
+   current_loops->state |= flags;
+ }
+ 
+ /* Clears FLAGS from the loops state.  */
+ 
+ static inline void
+ loops_state_clear (unsigned flags)
+ {
+   if (!current_loops)
+     return;
+   current_loops->state &= ~flags;
+ }
+ 
  /* Loop iterators.  */
  
  /* Flags for loop iteration.  */
Index: tree-cfg.c
===================================================================
*** tree-cfg.c	(revision 127121)
--- tree-cfg.c	(working copy)
*************** tree_merge_blocks (basic_block a, basic_
*** 1292,1298 ****
        /* In case we maintain loop closed ssa form, do not propagate arguments
  	 of loop exit phi nodes.  */
        if (current_loops
! 	  && (current_loops->state & LOOP_CLOSED_SSA)
  	  && is_gimple_reg (def)
  	  && TREE_CODE (use) == SSA_NAME
  	  && a->loop_father != b->loop_father)
--- 1292,1298 ----
        /* In case we maintain loop closed ssa form, do not propagate arguments
  	 of loop exit phi nodes.  */
        if (current_loops
! 	  && loops_state_satisfies_p (LOOP_CLOSED_SSA)
  	  && is_gimple_reg (def)
  	  && TREE_CODE (use) == SSA_NAME
  	  && a->loop_father != b->loop_father)

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-08-04  0:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-04  0:58 [patch, committed] Accessor functions for loops' state flags Zdenek Dvorak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).