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: Better estimations of costs in outof-ssa


> On Fri, 2005-07-29 at 17:21, Jan Hubicka wrote:
> > > On Thu, Jul 28, 2005 at 09:22:27AM +0200, Jan Hubicka wrote:
> > > > ! 		{
> > > > ! 		  /* Base costs on BB frequencies bounded by 1.  */
> > > > ! 		  int cost = EDGE_FREQUENCY (PHI_ARG_EDGE (phi, x));
> > > > ! 
> > > > ! 		  if (!cost)
> > > > ! 		    cost = 1;
> > > > ! 		  if (optimize_size || !maybe_hot_bb_p (bb))
> > > > ! 		    cost = 1;
> > > > ! 		  /* Inserting copy on critical edge is more costy
> > > > ! 		     than inserting it elsewhere.  */
> > > > ! 		  if (EDGE_CRITICAL_P (PHI_ARG_EDGE (phi, x)))
> > > > ! 		    cost *= 2;
> > > > ! 		  add_coalesce (cl, p, p2, cost);
> > > 
> > > Please factor out this thrice duplicated code.
> > 
> > OK, this moves the cost computation into add_coalesce itself.
> > It seems dificult to merge this somewhat further with other places we
> > compute simlar costs (such as reg-alloc) because of stubble differences
> > in between these..
> 
> Ick.  Why should add_coalesce have to know or care about hot blocks and
> critical edges?  It is intended to just take a simple cost.   
> 
> I would prefer to see the costs calculated by another small function or
> macro.   If I want to use add_coalesce for another purpose now (and
> coalesce lists are generic), I will have to write another add_coalesce,
> or create dummy values for those parameters I don't care about, and have
> to figure out what the correct dummy values are.

Well, I have dificult to think of sane using of coalescing list where
the costs won't be based on the profile, but here is updated patch.
Bootstrapping/regtesting i686-pc-gnu-linux, OK?
Honza
2005-07-29  Jan Hubicka  <jh@suse.cz>
	* tree-outof-ssa.c (coalesce_ssa_name): Use coalesce_cost.
	(coalesce_vars): Likewise.
	* tree-ssa-live.c (coalesce_cost): New.
	(build_tree_conflict_graph): Use coalesce_cost.
	* tree-ssa-live.h (coalesce_cost): Declare.
Index: tree-outof-ssa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-outof-ssa.c,v
retrieving revision 2.64
diff -c -3 -p -r2.64 tree-outof-ssa.c
*** tree-outof-ssa.c	25 Jun 2005 02:01:28 -0000	2.64
--- tree-outof-ssa.c	30 Jul 2005 07:50:09 -0000
*************** coalesce_ssa_name (var_map map, int flag
*** 729,735 ****
  		continue;
  	      p2 = var_to_partition (map, PHI_ARG_DEF (phi, x));
  	      if (p2 != NO_PARTITION)
! 		add_coalesce (cl, p, p2, 1);
  	    }
  	}
      }
--- 728,740 ----
  		continue;
  	      p2 = var_to_partition (map, PHI_ARG_DEF (phi, x));
  	      if (p2 != NO_PARTITION)
! 		{
! 		  edge e = PHI_ARG_EDGE (phi, x);
! 		  add_coalesce (cl, p, p2,
! 				coalesce_cost (EDGE_FREQUENCY (e),
! 					       maybe_hot_bb_p (bb),
! 					       EDGE_CRITICAL_P (e)));
! 		}
  	    }
  	}
      }
*************** coalesce_ssa_name (var_map map, int flag
*** 748,754 ****
  	      i = x;
  	    }
  	  else
! 	    add_coalesce (cl, i, x, 1);
  	}
      }
  
--- 753,762 ----
  	      i = x;
  	    }
  	  else
! 	    add_coalesce (cl, i, x,
! 			  coalesce_cost (EXIT_BLOCK_PTR->frequency,
! 					 maybe_hot_bb_p (EXIT_BLOCK_PTR),
! 					 false));
  	}
      }
  
*************** coalesce_vars (var_map map, tree_live_in
*** 1097,1103 ****
  	      if (p2 == (unsigned)NO_PARTITION)
  		continue;
  	      if (p != p2)
! 	        add_coalesce (cl, p, p2, 1);
  	    }
  	}
     }
--- 1105,1118 ----
  	      if (p2 == (unsigned)NO_PARTITION)
  		continue;
  	      if (p != p2)
! 		{
! 		  edge e = PHI_ARG_EDGE (phi, x);
! 
! 		  add_coalesce (cl, p, p2, 
! 				coalesce_cost (EDGE_FREQUENCY (e),
! 					       maybe_hot_bb_p (bb),
! 					       EDGE_CRITICAL_P (e)));
! 		}
  	    }
  	}
     }
Index: tree-ssa-live.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-live.c,v
retrieving revision 2.41
diff -c -3 -p -r2.41 tree-ssa-live.c
*** tree-ssa-live.c	30 Jun 2005 22:18:33 -0000	2.41
--- tree-ssa-live.c	30 Jul 2005 07:50:09 -0000
*************** find_partition_pair (coalesce_list_p cl,
*** 1145,1155 ****
    return node;
  }
  
  
  /* Add a potential coalesce between P1 and P2 in CL with a cost of VALUE.  */
  
  void 
! add_coalesce (coalesce_list_p cl, int p1, int p2, int value)
  {
    partition_pair_p node;
  
--- 1145,1174 ----
    return node;
  }
  
+ /* Return cost of execution of copy instruction with FREQUENCY
+    possibly on CRITICAL edge and in HOT basic block.  */
+ int
+ coalesce_cost (int frequency, bool hot, bool critical)
+ {
+   /* Base costs on BB frequencies bounded by 1.  */
+   int cost = frequency;
+ 
+   if (!cost)
+     cost = 1;
+   if (optimize_size || hot)
+     cost = 1;
+   /* Inserting copy on critical edge costs more
+      than inserting it elsewhere.  */
+   if (critical)
+     cost *= 2;
+   return cost;
+ }
  
  /* Add a potential coalesce between P1 and P2 in CL with a cost of VALUE.  */
  
  void 
! add_coalesce (coalesce_list_p cl, int p1, int p2,
! 	      int value)
  {
    partition_pair_p node;
  
*************** build_tree_conflict_graph (tree_live_inf
*** 1383,1389 ****
  		  if (bit)
  		    bitmap_set_bit (live, p2);
  		  if (cl)
! 		    add_coalesce (cl, p1, p2, 1);
  		  set_if_valid (map, live, rhs);
  		}
  	    }
--- 1402,1410 ----
  		  if (bit)
  		    bitmap_set_bit (live, p2);
  		  if (cl)
! 		    add_coalesce (cl, p1, p2,
! 				  coalesce_cost (bb->frequency,
! 				                 maybe_hot_bb_p (bb), false));
  		  set_if_valid (map, live, rhs);
  		}
  	    }
Index: tree-ssa-live.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-live.h,v
retrieving revision 2.15
diff -c -3 -p -r2.15 tree-ssa-live.h
*** tree-ssa-live.h	25 Jun 2005 02:01:39 -0000	2.15
--- tree-ssa-live.h	30 Jul 2005 07:50:09 -0000
*************** typedef struct coalesce_list_d 
*** 700,705 ****
--- 700,706 ----
  
  extern coalesce_list_p create_coalesce_list (var_map);
  extern void add_coalesce (coalesce_list_p, int, int, int);
+ extern int coalesce_cost (int, bool, bool);
  extern void sort_coalesce_list (coalesce_list_p);
  extern void dump_coalesce_list (FILE *, coalesce_list_p);
  extern void delete_coalesce_list (coalesce_list_p);


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