make regclass to use estimated basic block frequencies

Jan Hubicka jh@suse.cz
Wed Jun 20 08:33:00 GMT 2001


Hi
This patch makes regclass to use expected basic block frequencies instead of
using it's own heuristics guessing each loop to execute 3 times.

Overall it makes little difference and it is dificult to benchmark something,
but it is an test of design. I would like do same replacement on other passes
we guess cost according the placement in function.

Also this is the second pass in gcc now taking care for profile driven feedback
:)

Patches to register allocator are to come shortly.

Honza

Wed Jun 20 17:29:01 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* regclass.c (loop_cost): Kill.
	(frequency): New global variable.
	(record_operand_costs): Replace loop_cost by frequency.
	(scan_one_insn): Likewise.
	(regclass): Likewise; set frequency according to bb->frequency.

Index: regclass.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/regclass.c,v
retrieving revision 1.119
diff -c -3 -p -r1.119 regclass.c
*** regclass.c	2001/05/09 13:40:49	1.119
--- regclass.c	2001/06/20 15:27:34
*************** static struct reg_pref *reg_pref;
*** 794,803 ****
  
  static struct reg_pref *reg_pref_buffer;
  
! /* Account for the fact that insns within a loop are executed very commonly,
!    but don't keep doing this as loops go too deep.  */
  
! static int loop_cost;
  
  static rtx scan_one_insn	PARAMS ((rtx, int));
  static void record_operand_costs PARAMS ((rtx, struct costs *, struct reg_pref *));
--- 794,802 ----
  
  static struct reg_pref *reg_pref_buffer;
  
! /* Expected frequency of execution of given insn.  */
  
! static int frequency;
  
  static rtx scan_one_insn	PARAMS ((rtx, int));
  static void record_operand_costs PARAMS ((rtx, struct costs *, struct reg_pref *));
*************** record_operand_costs (insn, op_costs, re
*** 928,937 ****
  
        if (GET_CODE (recog_data.operand[i]) == MEM)
  	record_address_regs (XEXP (recog_data.operand[i], 0),
! 			     BASE_REG_CLASS, loop_cost * 2);
        else if (constraints[i][0] == 'p')
  	record_address_regs (recog_data.operand[i],
! 			     BASE_REG_CLASS, loop_cost * 2);
      }
  
    /* Check for commutative in a separate loop so everything will
--- 927,936 ----
  
        if (GET_CODE (recog_data.operand[i]) == MEM)
  	record_address_regs (XEXP (recog_data.operand[i], 0),
! 			     BASE_REG_CLASS, frequency * 2);
        else if (constraints[i][0] == 'p')
  	record_address_regs (recog_data.operand[i],
! 			     BASE_REG_CLASS, frequency * 2);
      }
  
    /* Check for commutative in a separate loop so everything will
*************** scan_one_insn (insn, pass)
*** 1007,1015 ****
        costs[REGNO (SET_DEST (set))].mem_cost
  	-= (MEMORY_MOVE_COST (GET_MODE (SET_DEST (set)),
  			      GENERAL_REGS, 1)
! 	    * loop_cost);
        record_address_regs (XEXP (SET_SRC (set), 0),
! 			   BASE_REG_CLASS, loop_cost * 2);
        return insn;
      }
  
--- 1006,1014 ----
        costs[REGNO (SET_DEST (set))].mem_cost
  	-= (MEMORY_MOVE_COST (GET_MODE (SET_DEST (set)),
  			      GENERAL_REGS, 1)
! 	    * frequency);
        record_address_regs (XEXP (SET_SRC (set), 0),
! 			   BASE_REG_CLASS, frequency * 2);
        return insn;
      }
  
*************** scan_one_insn (insn, pass)
*** 1084,1092 ****
  	int regno = REGNO (recog_data.operand[i]);
  	struct costs *p = &costs[regno], *q = &op_costs[i];
  
! 	p->mem_cost += q->mem_cost * loop_cost;
  	for (j = 0; j < N_REG_CLASSES; j++)
! 	  p->cost[j] += q->cost[j] * loop_cost;
        }
  
    return insn;
--- 1086,1094 ----
  	int regno = REGNO (recog_data.operand[i]);
  	struct costs *p = &costs[regno], *q = &op_costs[i];
  
! 	p->mem_cost += q->mem_cost * frequency;
  	for (j = 0; j < N_REG_CLASSES; j++)
! 	  p->cost[j] += q->cost[j] * frequency;
        }
  
    return insn;
*************** regclass (f, nregs, dump)
*** 1192,1198 ****
  
        if (!optimize)
  	{
! 	  loop_cost = 1;
  	  for (insn = f; insn; insn = NEXT_INSN (insn))
  	    insn = scan_one_insn (insn, pass);
  	}
--- 1194,1200 ----
  
        if (!optimize)
  	{
! 	  frequency = 1;
  	  for (insn = f; insn; insn = NEXT_INSN (insn))
  	    insn = scan_one_insn (insn, pass);
  	}
*************** regclass (f, nregs, dump)
*** 1206,1214 ****
  	       aggressive than the assumptions made elsewhere and is being
  	       tried as an experiment.  */
  	    if (optimize_size)
! 	      loop_cost = 1;
  	    else
! 	      loop_cost = 1 << (2 * MIN (bb->loop_depth, 5));
  	    for (insn = bb->head; ; insn = NEXT_INSN (insn))
  	      {
  		insn = scan_one_insn (insn, pass);
--- 1208,1218 ----
  	       aggressive than the assumptions made elsewhere and is being
  	       tried as an experiment.  */
  	    if (optimize_size)
! 	      frequency = 1;
  	    else
! 	      frequency = bb->frequency;
! 	    if (!frequency)
! 	      frequency = 1;
  	    for (insn = bb->head; ; insn = NEXT_INSN (insn))
  	      {
  		insn = scan_one_insn (insn, pass);



More information about the Gcc-patches mailing list