Orphaned Response

mike mike at hpdcdb.UUCP
Fri Jun 28 06:03:00 AEST 1985


The chief reason pcc compilers cannot make intelligent register variable
selection automatically is that they are single-pass compilers. Some kind
of usage count is necessary to select candidates for register variables.
By the time the compiler can accumulate a usage count, however, a
single-pass compiler has already generated code.

Automatically derived usage counts are invariably counts of static
references.  Such counts are useful but for my money I'd prefer dynamic
usage counts. Consequently I've yet to see a compiler algorithm for
automatic register variable selection that can beat explicit programmer
selection. If anyone does have such an algorithm, please share it.

Given the gutsy nature of C that allows the programmer great freedom
to allocate registers as he sees fit, I would not be surprised at all
if an automatic register allocator was greeted with loud cries of anguish
from the programmer community.

Register variables do alter the behavior of certain programs because
the pcc compiler generates code sequences based on cost estimates. Since
the use of register variables reduces the cost of certain subtrees it
can change the order of evaluation in the generated code. The only
situations I've seen where this matters is in the case of ambiguous
source code constructs such as

	a[i] = a[i++];

I don't have a great deal of sympathy for anyone who gets different
results depending on whether or not "i" is a register variable. K & R
specifically warn about such constructs.

Mike McNelly
Hewlett-Packard Corp.
hplabs!hpfcla!mike



More information about the Comp.lang.c mailing list