[new-ra] spill colorization statistics patch

Denis Chertykov denisc@overta.ru
Mon Oct 27 20:05:00 GMT 2003


Patch, statistics...

I have executed `make restage1' and after that `make restage2'.
Output of `make restage2' have results. It's stupid lines of text and
I just counted line numbers.
I have counted the following regexp's:
1. "Allocation rounds" it's number of allocation rounds in stage2;
2. "Spill.*stack\." - number of stack slots generated by rewrite_program;
3. "Spill.*colored\." - number of colored spill slots;
4. "Spill.*remat\." - number of colored spill slots which can be
   rematerialized;

Number in parenthesis after "Allocation rounds" is a number of
allocation rounds for current function. I have used it for getting
maximal rounds of allocation.

All results only about spills generated by rewrite_program.

Denis.

2003-10-27  Denis Chertykov  <denisc@overta.ru>

	* pre-reload.c (collect_insn_info): Add #ifdef MICHAEL around
	code which bypass pre-reloads after first ra_pass.
	(pre_reload_collect): Add #ifdef DENIS around aborting after
	first ra_pass.

	* ra.c (init_ra): Initialize variables for spilling statistics. 
	(reg_alloc): Call to debug_colorized_spills(). Freeing
	variables for spilling statistics

	* ra-debug.c: Declare variables for spilling statistics.
	(debug_colorized_spills): New function.

	* ra.h: Declare variables for spilling statistics.

	* ra-rewrite.c (rewrite_program): Remember all generated spill
	slots in rewrite_spill_slots bitmap.
	(emit_loads): Likewise. Make MICHAEL usable: validate_change
	or ra_validate_change.
	(insert_stores): Make DENIS and MICHAEL usable.
	(actual_spill): Reorganize condition with `spill_p'.
        (assign_stack_slots_1): Remember all stack slots generater by
	rewrite_program for spill slots generated by rewrite_program too.
	Bugfix: don't generate store insn if ref clobbered.


Index: ra.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ra.c,v
retrieving revision 1.1.2.74
diff -c -3 -p -r1.1.2.74 ra.c
*** ra.c	13 Oct 2003 13:02:27 -0000	1.1.2.74
--- ra.c	27 Oct 2003 17:52:19 -0000
*************** init_ra (void)
*** 657,662 ****
--- 657,667 ----
    compute_bb_for_insn ();
    ra_reg_renumber = NULL;
    insns_with_deaths = NULL;
+ #ifdef SPILLING_STATISTICS
+   stack_spill_slots_num = 0;
+   rewrite_spill_slots = BITMAP_XMALLOC ();
+   rewrite_stack_slots = BITMAP_XMALLOC ();
+ #endif
    emitted_by_spill = BITMAP_XMALLOC ();
    spill_slot_regs = BITMAP_XMALLOC ();
    gcc_obstack_init (&ra_obstack);
*************** reg_alloc (void)
*** 1124,1129 ****
--- 1129,1137 ----
  	  delete_moves ();
  	  create_flow_barriers ();
  	  dump_constraints ();
+ #ifdef SPILLING_STATISTICS
+  	  debug_colorized_spills ();
+ #endif
  	}
        else
  	{
*************** reg_alloc (void)
*** 1325,1330 ****
--- 1333,1342 ----
    regclass (get_insns (), max_reg_num (), rtl_dump_file);
    BITMAP_XFREE (emitted_by_spill);
    BITMAP_XFREE (spill_slot_regs);
+ #ifdef SPILLING_STATISTICS
+   BITMAP_XFREE (rewrite_spill_slots);
+   BITMAP_XFREE (rewrite_stack_slots);
+ #endif
  }
  
  /*
Index: ra-debug.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ra-debug.c,v
retrieving revision 1.1.2.10
diff -c -3 -p -r1.1.2.10 ra-debug.c
*** ra-debug.c	10 Oct 2003 14:18:59 -0000	1.1.2.10
--- ra-debug.c	27 Oct 2003 17:52:39 -0000
*************** static void ra_print_rtx_object (FILE *,
*** 44,49 ****
--- 44,58 ----
  /* The hardregs as names, for debugging.  */
  static const char *const reg_class_names[] = REG_CLASS_NAMES;
  
+ #ifdef SPILLING_STATISTICS
+ /* Registers generated for spill slots by rewrite_program[2].  */
+ bitmap rewrite_spill_slots;
+ /* rewrite_program[2] spill registers which was placed to stack.  */
+ bitmap rewrite_stack_slots;
+ /* Number of generated stack slots for spilled webs.  */
+ int stack_spill_slots_num;
+ #endif
+ 
  /* Print a message to the dump file, if debug_new_regalloc and LEVEL
     have any bits in common.  */
  
*************** debug_hard_reg_set (HARD_REG_SET set)
*** 1111,1116 ****
--- 1120,1188 ----
    fprintf (stderr, "\n");
  }
  
+ #ifdef SPILLING_STATISTICS
+ /* Output statistics about colorized spill-webs.  */
+ 
+ void
+ debug_colorized_spills (void)
+ {
+   unsigned int i;
+   int n;
+   int rewrite_slots_num = 0;
+   int colored_spills = 0;
+   int coalesced_spills = 0;
+   int colored_remat = 0;
+   
+   EXECUTE_IF_SET_IN_BITMAP (rewrite_spill_slots, 0, i,
+   {
+     ++rewrite_slots_num;
+   });
+   if (rewrite_slots_num)
+     {
+       printf ("Spills generated by rewrite_program in %s:\n", cfun->name);
+       for (i = 0; i < num_webs - num_subwebs; i++)
+ 	{
+ 	  struct web *web = ID2WEB (i);
+ 	  if (!web->num_defs && !web->num_uses)
+ 	    continue;
+ 	  if (bitmap_bit_p (rewrite_spill_slots, web->regno)
+ 	      && SPILL_SLOT_P (web->regno))
+ 	    {
+ 	      if (web->type == COLORED && web->color != an_unusable_color)
+ 		{
+ 		  if (web->pattern)
+ 		    {
+ 		      printf ("\tSpill slot pseudo %d colored remat.\n",
+ 			      web->regno);
+ 		      ++colored_remat;
+ 		    }
+ 		  else
+ 		    {
+ 		      printf ("\tSpill slot pseudo %d colored.\n", web->regno);
+ 		      ++colored_spills;
+ 		    }
+ 		}
+ 	      if (web->type == COALESCED)
+ 		++coalesced_spills;
+ 	    }
+ 	}
+       for (n = 0; n <= max_reg_num (); ++n)
+ 	{
+ 	  if (bitmap_bit_p (rewrite_spill_slots, n)
+ 	      && bitmap_bit_p (rewrite_stack_slots, n))
+ 	    {
+ 	      printf ("\tSpill slot pseudo %d stack.\n", n);
+ 	    }
+ 	}
+       printf ("\tColorability. "
+ 	      "spills: %d stack: %d, colored: %d colored-remat: %d\n",
+ 	      rewrite_slots_num, stack_spill_slots_num,
+ 	      colored_spills, colored_remat);
+       for (n = 0; n < ra_pass; ++n)
+ 	printf ("\tAllocation rounds (%d).\n", ra_pass);
+     }
+ }
+ #endif
  /*
  vim:cinoptions={.5s,g0,p5,t0,(0,^-0.5s,n-0.5s:tw=78:cindent:sw=4:
  */
Index: ra.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ra.h,v
retrieving revision 1.1.2.12
diff -c -3 -p -r1.1.2.12 ra.h
*** ra.h	13 Oct 2003 13:02:27 -0000	1.1.2.12
--- ra.h	27 Oct 2003 17:52:54 -0000
*************** extern void web_class_spill_ref (struct 
*** 668,672 ****
--- 668,686 ----
  extern int subst_to_stack_p (void);
  extern int copy_insn_p (rtx ,rtx *,rtx *);
  extern int hard_regs_combinable_p (struct web *,struct web *);
+ extern void debug_colorized_spills (void);
  
  #define SPILL_SLOT_P(REGNO) bitmap_bit_p (spill_slot_regs, (REGNO))
+ 
+ /* #define SPILLING_STATISTICS */
+ #define DENIS
+ /* #define MICHAEL */
+ 
+ #ifdef SPILLING_STATISTICS
+ /* Registers generated for spill slots by rewrite_program[2].  */
+ extern bitmap rewrite_spill_slots;
+ /* rewrite_program[2] spill registers which was placed to stack.  */
+ extern bitmap rewrite_stack_slots;
+ /* Number of generated stack slots for spilled webs.  */
+ extern int stack_spill_slots_num;
+ #endif
Index: ra-rewrite.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ra-rewrite.c,v
retrieving revision 1.1.2.23
diff -c -3 -p -r1.1.2.23 ra-rewrite.c
*** ra-rewrite.c	25 Oct 2003 07:03:02 -0000	1.1.2.23
--- ra-rewrite.c	27 Oct 2003 17:53:29 -0000
*************** rewrite_program (bitmap new_deaths)
*** 461,466 ****
--- 461,470 ----
  	    bitmap_clear (b);
  	    allocate_spill_web (aweb);
  	    slot = aweb->stack_slot;
+ #ifdef SPILLING_STATISTICS
+ 	    if (REG_P (slot))
+ 	      bitmap_set_bit (rewrite_spill_slots, REGNO (slot));
+ #endif
  	    for (j = 0; j < web->num_uses; j++)
  	      {
  		rtx insns, target, source;
*************** insert_stores (bitmap new_deaths)
*** 779,799 ****
  		  int has_use;
  		  last_slot = slot;
  		  remember_slot (&slots, slot);
! #if DENIS
! 		  if ((web->pattern || copy_insn_p (insn, NULL, NULL)) 
! 		      && ra_validate_change (insn, DF_REF_LOC (info.defs[n]),
! 					     slot, 0))
  #else
  		  if ((DF_REF_FLAGS (info.defs[n]) & DF_REF_ALREADY_SPILLED)
  		      || (! (rdef && RA_REF_ADDRESS_P (rdef))
! 			  && validate_change (insn, DF_REF_LOC (info.defs[n]),
  					      slot, 0)))
  		    {
  		      df_insn_modify (df, bb, insn);
  		      bitmap_set_bit (last_changed_insns, uid);
  		      if (!flag_ra_test)
  			bitmap_set_bit (ra_modified_insns, uid);
- #endif
  		      if (!bitmap_bit_p (useless_defs,
  					 DF_REF_ID (info.defs[n])))
  			ra_emit_move_insn (source, slot);
--- 783,812 ----
  		  int has_use;
  		  last_slot = slot;
  		  remember_slot (&slots, slot);
! #ifdef DENIS
! 		  if ((web->pattern || copy_insn_p (insn, NULL, NULL))
! 		      && (! (rdef && RA_REF_ADDRESS_P (rdef))
! 			  && ra_validate_change (insn,
! 						 DF_REF_LOC (info.defs[n]),
! 						 slot, 0)))
  #else
  		  if ((DF_REF_FLAGS (info.defs[n]) & DF_REF_ALREADY_SPILLED)
  		      || (! (rdef && RA_REF_ADDRESS_P (rdef))
! #ifdef MICHAEL
! 			  && validate_change (insn,
! 					      DF_REF_LOC (info.defs[n]),
  					      slot, 0)))
+ #else
+ 			  && ra_validate_change (insn,
+ 						 DF_REF_LOC (info.defs[n]),
+ 						 slot, 0)))
+ #endif
+ #endif
  		    {
  		      df_insn_modify (df, bb, insn);
  		      bitmap_set_bit (last_changed_insns, uid);
  		      if (!flag_ra_test)
  			bitmap_set_bit (ra_modified_insns, uid);
  		      if (!bitmap_bit_p (useless_defs,
  					 DF_REF_ID (info.defs[n])))
  			ra_emit_move_insn (source, slot);
*************** emit_loads (struct rewrite_info *ri, int
*** 1076,1081 ****
--- 1089,1098 ----
        start_sequence ();
        allocate_spill_web (aweb);
        slot = aweb->stack_slot;
+ #ifdef SPILLING_STATISTICS
+       if (REG_P (slot))
+ 	bitmap_set_bit (rewrite_spill_slots, REGNO (slot));
+ #endif
        innermode = GET_MODE (slot);
        /* If we don't copy the RTL there might be some SUBREG
  	 rtx shared in the next iteration although being in
*************** emit_loads (struct rewrite_info *ri, int
*** 1122,1132 ****
--- 1139,1157 ----
  		  /* For an rmw web we want to try to change the use and the
  		     def inplace to the mem-ref.  If that doesn't work, only
  		     try to handle the use.  */
+ #ifdef MICHAEL
  		  validate_change (web->last_use_insn,
  				   DF_REF_LOC (web->last_use), slot, 1);
  		  validate_change (web->last_use_insn,
  				   DF_REF_LOC (info.defs[n]), slot, 1);
  		  if (apply_change_group ())
+ #else
+ 		  ra_validate_change (web->last_use_insn,
+ 				   DF_REF_LOC (web->last_use), slot, 1);
+ 		  ra_validate_change (web->last_use_insn,
+ 				   DF_REF_LOC (info.defs[n]), slot, 1);
+ 		  if (ra_apply_change_group ())
+ #endif		    
  		    {
  		      DF_REF_FLAGS (info.defs[n]) |= DF_REF_ALREADY_SPILLED;
  		      done = 1;
*************** emit_loads (struct rewrite_info *ri, int
*** 1136,1143 ****
--- 1161,1173 ----
  	  /* No rmw web or spilling the def too didn't work,
  	     so handle just the use here.  */
  	  if (!done && !(ruse && RA_REF_ADDRESS_P (ruse))
+ #ifdef MICHAEL
  	      && validate_change (web->last_use_insn,
  				  DF_REF_LOC (web->last_use), slot, 0))
+ #else
+ 	      && ra_validate_change (web->last_use_insn,
+ 				     DF_REF_LOC (web->last_use), slot, 0))
+ #endif
  	    done = 1;
  	  if (done)
  	    {
*************** actual_spill (int spill_p ATTRIBUTE_UNUS
*** 2130,2136 ****
  
    /* If we have a webs colored by an_unusable_color (ie we think that they are
       already in frame) we must put such webs to frame.  */
!   if (/* !spill_p && */ subst_to_stack_p ())
      /* If you uncomment the SPILL_P usage then you will have a calls to
         assign_stack_slots only at end of allocation process.
         See to the caller of actual_spill.  */
--- 2160,2166 ----
  
    /* If we have a webs colored by an_unusable_color (ie we think that they are
       already in frame) we must put such webs to frame.  */
!   if (!spill_p && subst_to_stack_p ())
      /* If you uncomment the SPILL_P usage then you will have a calls to
         assign_stack_slots only at end of allocation process.
         See to the caller of actual_spill.  */
*************** purge_reg_equiv_notes ()
*** 2279,2285 ****
     Replace all uses and defs to stack slots in all possible cases.  */
  
  static void
! assign_stack_slots (void)
  {
    int i;
    struct dlist *d, *d_next;
--- 2309,2315 ----
     Replace all uses and defs to stack slots in all possible cases.  */
  
  static void
! assign_stack_slots ()
  {
    int i;
    struct dlist *d, *d_next;
*************** assign_stack_slots_1 ()
*** 2495,2506 ****
  	  place = assign_stack_local (innermode,
  				      total_size,
  				      inherent_size == total_size ? 0: -1);
  	  RTX_UNCHANGING_P (place) =
  	    RTX_UNCHANGING_P (regno_reg_rtx[web->regno]);
  	  set_mem_alias_set (place, new_alias_set ());
  	}
!       ra_debug_msg (DUMP_COLORIZE, "\t%3d(%d) insns: ",
! 		    web->id, web->regno);
  	  
        web->stack_slot = place;
  
--- 2525,2546 ----
  	  place = assign_stack_local (innermode,
  				      total_size,
  				      inherent_size == total_size ? 0: -1);
+ #ifdef SPILLING_STATISTICS
+ 	  if (bitmap_bit_p (rewrite_spill_slots, web->regno))
+ 	    {
+ 	      ++stack_spill_slots_num;
+ 	      bitmap_set_bit (rewrite_stack_slots, web->regno);
+ 	    }
+ #endif
  	  RTX_UNCHANGING_P (place) =
  	    RTX_UNCHANGING_P (regno_reg_rtx[web->regno]);
  	  set_mem_alias_set (place, new_alias_set ());
  	}
!       if (web->pattern)
! 	ra_debug_msg (DUMP_COLORIZE, "\tremat %3d(%d) insns: ", web->id,
! 		      web->regno);
!       else
! 	ra_debug_msg (DUMP_COLORIZE, "\t%3d(%d) insns: ", web->id, web->regno);
  	  
        web->stack_slot = place;
  
*************** assign_stack_slots_1 ()
*** 2562,2568 ****
  	      {
  		if (i == 0) /* Insn for use.  */
  		  ra_emit_move_insn (copy_rtx (target), source);
! 		else
  		  ra_emit_move_insn (source, copy_rtx (target));
  	      }
  	    insns = get_insns ();
--- 2602,2608 ----
  	      {
  		if (i == 0) /* Insn for use.  */
  		  ra_emit_move_insn (copy_rtx (target), source);
! 		else if (DF_REF_TYPE (refs[j]) != DF_REF_REG_CLOBBER)
  		  ra_emit_move_insn (source, copy_rtx (target));
  	      }
  	    insns = get_insns ();
Index: pre-reload.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/pre-reload.c,v
retrieving revision 1.1.2.21
diff -c -3 -p -r1.1.2.21 pre-reload.c
*** pre-reload.c	17 Oct 2003 14:38:37 -0000	1.1.2.21
--- pre-reload.c	27 Oct 2003 17:54:15 -0000
*************** collect_insn_info (ra_info, insn, def_re
*** 3230,3241 ****
    for (i = 0; i < noperands; i++)
      goal_alt[i].win |= goal_alt[i].match_win;
  
    /* In the later passes we don't want to create new reload insns, but just
       record register classes.  */
    if (ra_pass > 1)
      for (i = 0; i < noperands; i++)
        goal_alt[i].win = 1;
! 
    /* If the best alternative is with operands 1 and 2 swapped,
       consider them swapped before reporting the reloads.  Update the
       operand numbers of any reloads already pushed.  */
--- 3230,3243 ----
    for (i = 0; i < noperands; i++)
      goal_alt[i].win |= goal_alt[i].match_win;
  
+ #ifdef MICHAEL
    /* In the later passes we don't want to create new reload insns, but just
       record register classes.  */
    if (ra_pass > 1)
      for (i = 0; i < noperands; i++)
        goal_alt[i].win = 1;
! #endif
!   
    /* If the best alternative is with operands 1 and 2 swapped,
       consider them swapped before reporting the reloads.  Update the
       operand numbers of any reloads already pushed.  */
*************** pre_reload_collect (ra_info, modified)
*** 4406,4412 ****
  		{
  		  rtx before = PREV_INSN (insn);
  		  rtx after = NEXT_INSN (insn);
! 
  		  if (rtl_dump_file)
  		    {
  		      fprintf (rtl_dump_file, "Reload for insn:\n");
--- 4408,4417 ----
  		{
  		  rtx before = PREV_INSN (insn);
  		  rtx after = NEXT_INSN (insn);
! #ifdef DENIS
! 		  if (ra_pass > 1)
! 		    abort ();
! #endif	  
  		  if (rtl_dump_file)
  		    {
  		      fprintf (rtl_dump_file, "Reload for insn:\n");



More information about the Gcc-patches mailing list