Register classes

James E Wilson wilson@specifixinc.com
Fri Aug 20 02:07:00 GMT 2004


Daniel Berlin wrote:
> A whole lot of ports seem to have register classes that contain 
> registers that can't possibly be used together.
> They also have to seem weird groupings of registers that don't make 
> sense to be used by any single pseudo.

This is because of interactions between the register preferences 
computed by regclass and the register allocator.

The register preferencing works by looking at the instructions that use 
a pseudo, looking at the register classes preferred by these 
instructions, and then forming unions/intersections to determine the 
best class to allocate a register to.  If you don't have register 
classes to represent the union/intersection of other register classes, 
then you can end up with suboptimal results.  In some extreme cases, a 
port may fail in reload if a union/intersection class isn't there.  This 
is sometimes a problem for embedded targets with small register sets, 
and lots of registers with special purposes.  See the subunion and 
superunion stuff in regclass.c for some of the stuff that is done with 
register classes.

Suppose you have a pseudo that is used in only two instructions.  One 
instruction requires the pseudo to be in class A.  The other requires it 
to be in class B.  The two classes don't intersect.  Neither class is 
better.  The best class to use would be the union of class A and B, 
which then lets the register allocator choose a hard reg from either 
class, depending on other factors, such as which class has less register 
pressure.  If you don't have the union reg class, then regclass must 
arbitrarily pick one (I think it picks the lower numbered one?), and 
this may result in suboptimal code if this forces an otherwise 
unnecessary spill.

Also, in some cases, it is useful to have classes that represent the 
difference of two classes.  Suppose you have a couple of registers with 
special purposes that cause them to have high register pressure.  Then 
you may be able to improve results by creating register classes with 
those registers subtracted out, and then using hooks to force the 
difference class to be used when possible, to reduce register pressure 
on the special purpose registers.  Again, this is more likely to be 
useful for an embedded target with a small number of registers and a set 
of registers with special purposes.
-- 
Jim Wilson, GNU Tools Support, http://www.SpecifixInc.com



More information about the Gcc mailing list