Re: Register optimizations

torbenm@diku.dk (Torben AEgidius Mogensen)
Thu, 9 Mar 1995 10:29:29 GMT

          From comp.compilers

Related articles
Register optimizations ArielMars@aol.com (1995-03-02)
Re: Register optimizations mercier@news.cinenet.net (1995-03-05)
Re: Register optimizations baynes@ukpsshp1.serigate.philips.nl (1995-03-08)
Re: Register optimizations torbenm@diku.dk (1995-03-09)
Re: Register optimizations preston@tera.com (1995-03-12)
Re: Register optimizations anton@mips.complang.tuwien.ac.at (1995-03-16)
Re: Register optimizations conway@munta.cs.mu.OZ.AU (1995-03-18)
| List of all articles for this month |

Newsgroups: comp.compilers
From: torbenm@diku.dk (Torben AEgidius Mogensen)
Keywords: registers, optimize, question
Organization: Department of Computer Science, U of Copenhagen
References: 95-03-025
Date: Thu, 9 Mar 1995 10:29:29 GMT

ArielMars@aol.com writes:


>Perhaps some of you with some experience could help me answer this one. As
>compared to a system in which all local variables are held on the stack,
>and where a single register is used to store the current value being
>operated on and intermediate expression results are pushed on the stack,
>is it more efficient to:


>1) remap commonly used variables into registers, just use the one register
>for expressions, and use stack space for intermediate values; or,


>2) leave the local variables on the stack, and use registers for all
>intermediate expression values?


The most commonly used approach is to keep both variables,
intermediate results and current values in registers if at all
possible. Variables will normally also have space allocated in a stack
frame. This is used when there are not enough registers available to
hold all values, in which case a variable is "spilled" to the stack
frame.


The frame is also used if a procedure call is made, in which case live
variables are stored in the frame prior to the call and restored
afterwards. Sometimes the procedure call standard specifies that some
registers are preserved across the call, in which case it is the
called procedure that will save the values on the stack, if the
register is used.


As for taking the address of a variable, the address given is that of
the stack frame location. Prior to any possible use of the address it
is ensured that the frame location contains the current value of the
variable, and if there is a possibility of assignment to through the
pointer, the register copy of the variable is considered invalid, and
must be reloaded for later use. A local analysis can easily find (or
approximate) the places where pointer access is done and make the
neccessary transfers before and after these. If the pointer is passed
to a procedure, it is normally assumed that that procedure can both
use and update the value at the end of the pointer (and any value this
points to etc.).


Most modern compilers will allocate registers on a per-procedure
basis, where earlier compilers used a per-basic-block approach. Some
compilers will allocate registers accross procedures (interprocedural
register allocation), but that is not common.


Torben Mogensen (torbenm@diku.dk)
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.