This is the mail archive of the gcc@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: number of spills and reloads


Qiong Cai wrote:
I'd like to know the number of spills and reloads generated by
register allocator in GCC.

You need to define exactly what you mean by "spills" and "reloads" before those questions can be answered. And you may not be able to define those terms exactly if you don't know how reload works.


So I add the counter "num_spills" in function "find_reload_regs" and the counter
"num_reloads" in "find_reg" in "reload1.c" just after the instructions
printing out the above information.  Is this correct?  Because the
reload phase is complicated, I'm quite suspicious what I did.

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.


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.

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.

Etc.

Maybe what you really want is the number of reloads that require use of a spill register, which I think you could get by putting a counter at the top of find_reg.
--
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



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