Re: register variables in C.

moss@cs.umass.edu
Thu, 23 Apr 1992 01:10:56 GMT

          From comp.compilers

Related articles
register variables in C. eric@pencom.com (1992-04-22)
register variables in C. kennykb@dssv01.crd.ge.com (1992-04-22)
Re: register variables in C. moss@cs.umass.edu (1992-04-23)
Re: register variables in C. dd@mips.com (1992-04-23)
Re: register variables in C. dave.howell@ColumbiaSC.NCR.COM (Dave Howell) (1992-04-24)
Re: register variables in C. bart@cs.uoregon.edu (1992-04-29)
Re: register variables in C. jeff@dsp.sps.mot.com (1992-04-30)
Re: register variables in C. Brian.Scearce@Eng.Sun.COM (1992-04-30)
Re: register variables in C. pardo@cs.washington.edu (1992-05-01)
[8 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: moss@cs.umass.edu
Keywords: registers, optimize, C
Organization: Dept of Comp and Info Sci, Univ of Mass (Amherst)
References: 92-04-108
Date: Thu, 23 Apr 1992 01:10:56 GMT

>>>>> On 22 Apr 92 17:48:36 GMT, eric@pencom.com said:
> In general, can a good optimizing C compiler do a better job
> of assigning registers to variables better than the programmer?
> [My impression is that the compiler can do a much better job, particularly
> with a graph coloring register allocator, but I'd be interested in some
> real data. -John]


Well, I can give some "anecdotal evidence" as to the value of the register
declarations. The issue has to do with how a compiler will choose to put
variables into registers. Many compilers have no profiling information
available, so they apply some heuristics to come up with cost estimates to
drive the decision making process. These estimates can be horribly wrong.
A case in point is a large C function that implements the main interpreter
loop in a Smalltalk interpreter we built. The variables modeling the
program counter, stack pointer, etc., of the virtual machine are best kept
in machine registers if possible, since they are frequently used. However,
they are not necessarily mentioned most often statically -- some variables
have more references, but fall mostly in the rarer paths. Using Smalltalk
byte code and primitive frequency information collected by previous
researchers we can figure out the common cases and make better decision
(or at least come close, and then zero in by fiddling the declarations and
checking the performance on a benchmark suite).


However, this kind of program (a main interpreter loop) is very unusual.
You should generally let the compiler do it, especially if you can provide
profiling information to a compiler that will use it well.
--


J. Eliot B. Moss, Assistant Professor
Department of Computer Science
Lederle Graduate Research Center
University of Massachusetts
Amherst, MA 01003
(413) 545-4206, 545-1249 (fax); Moss@cs.umass.edu
--


Post a followup to this message

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