number of spills and reloads

Qiong Cai qiong.cai@gmail.com
Thu Aug 26 09:04:00 GMT 2004


Hi James,

Thanks for the reply.

> find_reload_regs gets called once for every instruction that needs a
> reload.  find_reg gets called once for every operand of every
> instruction that needs a spill register allocated to satisfy a reload.
> But we only reach the place where we emit the message if we choose to
> allocate a new spill register.

I'm a bit confused with "spill register". Consider the following example,
r0 <- [sp+4] + [sp + 8]
then operand 1 must be the register. so reload into register r1 first
r1 <- [sp+4]

Is the register r1 a "spill" register?

> 
> Counting the instructions that need a reload is a very poor measure of
> the number of spills.  There is n_spills which counts the number of hard
> registers allocated for use as spill registers which is one reasonable
> measure.  n_spills is probably very close to your num_reloads.  The
> different is probably eliminable registers like the frame pointer.
> Another measure might be the number of pseudos that get forced to stack
> slots in order to free up hard registers for use as spill registers.
> This can be computed by counting the number of registers in spilled_pseudos.
> 
I need the number of "stores" or "spills" to memory caused by register
allocation.
It seems that this is close to your second measure.  Also I'd like to know the 
dyanmic counts of "stores".  For example, 
x = a + b  [ dynamic count = 10000 from edge profiling]
If the pseduos "a" and "b" must be forced to stack:
[sp + 4] <- a
[sp + b] <- b
So the dyanmic count is  10000+10000 = 20000.
Is this the reasonable measure of dynamic counts of "stores" or "spills" 
introduced by register allocation?


> For the number of reloads, there is n_reloads computed by find_reloads.
>   This is a per instruction count.  You would have to sum it over all
> instructions to get a count for the entire function.  But there are a
> number of ambiguities here.
> 
> We sometimes create what is known as "optional" reloads.  These are
> things that don't need a reload, but might result in better code if they
> do get a reload.  Sometimes we perform them.  Sometimes we don't.  You
> may or not want to count them.
> 
> We also have secondary reloads.  Sometimes a single reload needs two
> registers, which we handle by creating two reloads, one of which is a
> secondary reload.  So is that 1 reload or 2?  Depends on how you want to
> count them.
> 
> Some reloads need a spill register, some don't.  If a reload can never
> result in a spill, do you still want to count it?
> 
> Some reloads involve multi-word values which may require multiple spill
> registers.

Where's the place in which the final reload is emitted?  If I know the place,
then I just count the number of reload there.



-- 
Qiong Cai
www.cse.unsw.edu.au/~qiongc



More information about the Gcc mailing list