From eefdec482d3b01c97ab6d360dbee968b9ca9c252 Mon Sep 17 00:00:00 2001 From: hubicka Date: Mon, 30 Jul 2001 20:03:37 +0000 Subject: [PATCH] * flow.c (mark_set_1): Use REG_FREQ_FROM_BB. (attempt_auto_inc): LIkewise. (mark_used_reg): Likewise. (try_pre_increment_1): Likewise. * regclass.c (regclass): Likewise. * global.c (allocno_compare): Update comment; change scaling factor. * local-alloc.c (QTY_CMP_PRI): Likewise. * regs.h (REG_FREQ_FROM_BB): New. (REG_FREQ_MAX): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@44483 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 12 ++++++++++++ gcc/flow.c | 12 ++++-------- gcc/global.c | 9 +++++---- gcc/local-alloc.c | 7 ++++--- gcc/regclass.c | 7 ++----- gcc/regs.h | 18 ++++++++++++++++++ 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 429347c6fcc..67acc96c41a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +Mon Jul 30 21:54:53 CEST 2001 Jan Hubicka + + * flow.c (mark_set_1): Use REG_FREQ_FROM_BB. + (attempt_auto_inc): LIkewise. + (mark_used_reg): Likewise. + (try_pre_increment_1): Likewise. + * regclass.c (regclass): Likewise. + * global.c (allocno_compare): Update comment; change scaling factor. + * local-alloc.c (QTY_CMP_PRI): Likewise. + * regs.h (REG_FREQ_FROM_BB): New. + (REG_FREQ_MAX): Likewise. + 2001-07-30 H.J. Lu * config/mips/linux.h (CPLUSPLUS_CPP_SPEC): Add diff --git a/gcc/flow.c b/gcc/flow.c index 992cac6584b..69e7747502d 100644 --- a/gcc/flow.c +++ b/gcc/flow.c @@ -6220,8 +6220,7 @@ mark_set_1 (pbi, code, reg, cond, insn, flags) register twice if it is modified, but that is correct. */ REG_N_SETS (i) += 1; REG_N_REFS (i) += 1; - REG_FREQ (i) += (optimize_size || !pbi->bb->frequency - ? 1 : pbi->bb->frequency); + REG_FREQ (i) += REG_FREQ_FROM_BB (pbi->bb); /* The insns where a reg is live are normally counted elsewhere, but we want the count to include the insn @@ -6888,8 +6887,7 @@ attempt_auto_inc (pbi, inc, insn, mem, incr, incr_reg) /* Count an extra reference to the reg. When a reg is incremented, spilling it is worse, so we want to make that less likely. */ - REG_FREQ (regno) += (optimize_size || !pbi->bb->frequency - ? 1 : pbi->bb->frequency); + REG_FREQ (regno) += REG_FREQ_FROM_BB (pbi->bb); /* Count the increment as a setting of the register, even though it isn't a SET in rtl. */ @@ -7054,8 +7052,7 @@ mark_used_reg (pbi, reg, cond, insn) REG_BASIC_BLOCK (regno_first) = REG_BLOCK_GLOBAL; /* Count (weighted) number of uses of each reg. */ - REG_FREQ (regno_first) - += (optimize_size || !pbi->bb->frequency ? 1 : pbi->bb->frequency); + REG_FREQ (regno_first) += REG_FREQ_FROM_BB (pbi->bb); REG_N_REFS (regno_first)++; } } @@ -7477,8 +7474,7 @@ try_pre_increment_1 (pbi, insn) so we want to make that less likely. */ if (regno >= FIRST_PSEUDO_REGISTER) { - REG_FREQ (regno) += (optimize_size || !pbi->bb->frequency - ? 1 : pbi->bb->frequency); + REG_FREQ (regno) += REG_FREQ_FROM_BB (pbi->bb); REG_N_SETS (regno)++; } diff --git a/gcc/global.c b/gcc/global.c index f03de63c2c7..6558fac8b89 100644 --- a/gcc/global.c +++ b/gcc/global.c @@ -611,16 +611,17 @@ allocno_compare (v1p, v2p) int v1 = *(const int *)v1p, v2 = *(const int *)v2p; /* Note that the quotient will never be bigger than the value of floor_log2 times the maximum number of - times a register can occur in one insn (surely less than 100). - Multiplying this by 10000 can't overflow. */ + times a register can occur in one insn (surely less than 100) + weighted by the frequency (maximally REG_FREQ_MAX). + Multiplying this by 10000/REG_FREQ_MAX can't overflow. */ register int pri1 = (((double) (floor_log2 (allocno[v1].n_refs) * allocno[v1].freq) / allocno[v1].live_length) - * 10000 * allocno[v1].size); + * (10000 / REG_FREQ_MAX) * allocno[v1].size); register int pri2 = (((double) (floor_log2 (allocno[v2].n_refs) * allocno[v2].freq) / allocno[v2].live_length) - * 10000 * allocno[v2].size); + * (10000 / REG_FREQ_MAX) * allocno[v2].size); if (pri2 - pri1) return pri2 - pri1; diff --git a/gcc/local-alloc.c b/gcc/local-alloc.c index 4424074b653..a068db8385d 100644 --- a/gcc/local-alloc.c +++ b/gcc/local-alloc.c @@ -1698,13 +1698,14 @@ block_alloc (b) /* Note that the quotient will never be bigger than the value of floor_log2 times the maximum number of - times a register can occur in one insn (surely less than 100). - Multiplying this by 10000 can't overflow. + times a register can occur in one insn (surely less than 100) + weighted by frequency (max REG_FREQ_MAX). + Multiplying this by 10000/REG_FREQ_MAX can't overflow. QTY_CMP_PRI is also used by qty_sugg_compare. */ #define QTY_CMP_PRI(q) \ ((int) (((double) (floor_log2 (qty[q].n_refs) * qty[q].freq * qty[q].size) \ - / (qty[q].death - qty[q].birth)) * 10000)) + / (qty[q].death - qty[q].birth)) * (10000 / REG_FREQ_MAX))) static int qty_compare (q1, q2) diff --git a/gcc/regclass.c b/gcc/regclass.c index 2d80e7eb84a..b16a677d805 100644 --- a/gcc/regclass.c +++ b/gcc/regclass.c @@ -1233,7 +1233,7 @@ regclass (f, nregs, dump) if (!optimize) { - frequency = 1; + frequency = REG_FREQ_MAX; for (insn = f; insn; insn = NEXT_INSN (insn)) insn = scan_one_insn (insn, pass); } @@ -1246,10 +1246,7 @@ regclass (f, nregs, dump) times more than insns outside a loop. This is much more aggressive than the assumptions made elsewhere and is being tried as an experiment. */ - if (optimize_size) - frequency = 1; - else - frequency = bb->frequency ? bb->frequency : 1; + frequency = REG_FREQ_FROM_BB (bb); for (insn = bb->head; ; insn = NEXT_INSN (insn)) { insn = scan_one_insn (insn, pass); diff --git a/gcc/regs.h b/gcc/regs.h index 3857c829dc1..e852d6d3212 100644 --- a/gcc/regs.h +++ b/gcc/regs.h @@ -86,6 +86,24 @@ extern varray_type reg_n_info; #define REG_FREQ(N) (VARRAY_REG (reg_n_info, N)->freq) +/* The weights for each insn varries from 0 to REG_FREQ_BASE. + This constant does not need to be high, as in infrequently executed + regions we want to count instructions equivalently to optimize for + size instead of speed. */ +#define REG_FREQ_MAX 1000 + +/* Compute register frequency from the BB frequency. When optimizing for size, + or profile driven feedback is available and the function is never executed, + frequency is always equivalent. Otherwise rescale the basic block + frequency. */ +#define REG_FREQ_FROM_BB(bb) (optimize_size \ + || (flag_branch_probabilities \ + && !ENTRY_BLOCK_PTR->count) \ + ? REG_FREQ_MAX \ + : ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\ + ? ((bb)->frequency * REG_FREQ_MAX / BB_FREQ_MAX)\ + : 1) + /* Indexed by n, gives number of times (REG n) is set. ??? both regscan and flow allocate space for this. We should settle on just copy. */ -- 2.11.4.GIT