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: GCC's new register allocator


Hi,

On Sat, 24 Jul 2004, Rajkishore Barik wrote:

> void foo(int i, int *a, int *p) {
>         int x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14;
>         x1=a[i];
>         x2=a[i+1];
>         x3=a[i+2];
>         x4=a[i+3];
>         x5=a[i+4];
>         x6=a[i+5];
>         x7=a[i+6];
>         x8=a[i+7];
>         x9=a[i+8];
>         x10=a[i+9];
>         x11=a[i+10];
>         x12=a[i+11];
>         x13=a[i+12];
>         x14=a[i+13];
>         *p=99;

Uhh, these are 17 live variables (a, i, p and x1 to x14).  And only six 
registers (see below).

> This code after running on x86, allocates
> web 0    (pseudo 88 -- corresponding to x14)    to      color 1
> web 17  (pseudo 87 -- corresponding to x13)     to      color 5
> web 16   (pseudo 86 -- corresponding to x12)    to      color 2
> web 15   (pseudo 85 -- corresponding to x11)    to      color 3
> web 14   (pseudo 84 -- corresponding to x10)    to      color 4
> web 13 to web 4 (corresponding to x1-x9) all get a color 0  -- which I 
> assume have been spilled as they use the "an_usable_color" -- 

Yes, they are marked for spilling.  That they "get" color 0 is a bit 
misleading.  They get this color for the purpose of interference region 
spilling (in a sense they will be spilled under the assumption that all 
their spilled parts will get this color in the next round, which might or 
might not happen).

Note that this doesn't have to do with an_unusable_color.  The webs above 
really are simply marked for spilling.

> Why are the spilled webs get an_usable_color which happens to be the
> first free usable color in the FIXED_REGISTER set?

This "color" is used for webs used as spill-temporaries.  In order to not
commit too early to stack space for spilling I first spill to new pseudo 
registers (so they can be colored later).  If _those_ can't be colored we 
don't want to spill them again (they already represent stack slots).  The 
easiest way is to handle them as colored, but marked with a special color 
(which has the semantic of "this web itself represents a stack slot").

> Looking at the i386.h file, I find set of GENERAL_REGS class can use 
> %eax,%ebx,%ecx,%edx,%esi, %edi,%ebp,%esp and %r8-%r15.
> As per my understanding  %ebx, %ecx, %edx, %esi, and %edi are used for 
> register allocation

plus %eax (and %ebp when -fomit-frame-pointer).  And with -fPIC one 
register less.

> and others are used for special purpose stack and base pointers and
> %r8-15 are not usable due to the contraint in FIXED_REGISTERS.

Those registers are available only on the x86-64 architecture.

> Does this mean we can not use more than 5 registers for integer
> variables ?

On i386 basically yes.

> If not, then how can I modify the i386.h file to increase the number of
> usable regsiters for integer variables?

You need to compile for x86-64 to make use of %r8 to %r15.


Ciao,
Michael.


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