Re: What is the current situation regarding the C "register" decl?

Gary Merrill <sasghm@unx.sas.com>
Wed, 24 Jun 1992 13:13:55 GMT

          From comp.compilers

Related articles
What is the current situation regarding the C "register" decl? boles@cayman.asg.arlut.utexas.edu (David Boles) (1992-06-23)
Re: What is the current situation regarding the C "register" decl? sasghm@unx.sas.com (Gary Merrill) (1992-06-24)
Re: What is the current situation regarding the C "register" decl? moss@cs.umass.edu (1992-06-26)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Gary Merrill <sasghm@unx.sas.com>
Return-Path: <sasghm@theseus.unx.sas.com>
Organization: Compilers Central
Date: Wed, 24 Jun 1992 13:13:55 GMT
References: 92-06-118
Keywords: C, optimize, registers

> I have been told many times that modern C compilers on machines with lots
> of registers essentially ignore the programmer's "register" declaration.


Actually, the issue can be of more significance on register-poor machines.
If a compiler honors the user's register declarations it may have no
registers left over for its own use in optimization and the quality of
generated code can suffer dramatically. Such is the case, for example, on
several Intel architectures.


Generally, the compiler writer's attitude is that since the compiler knows
how it is generating code and the user does not, then the
compiler/optimizer is in a position to make an informed decision
concerning register use, while the user is not. Really, the 'register'
keyword is something of a vestige from the days prior to decent (or any)
global optimization in C compilers. I don't ever use it any more, relying
on the optimizer and code generator to decide how best to use the
registers.


There is some question, I suppose, of what should be done with register
declarations if an optimization step is not performed. One of our
compilers simply ignores the declarations even in this case (believing it
has superior knowledge for code generation). For Intel targets, our code
generators will (in the absence of the global optimization step) honor as
many register declarations as feasible (this usually means 2 or 3).


> [A compiler can also take a register declaration as an assertion that there
> are no references to the address of a variable; it really shouldn't ignore
> that aspect. -John]


There is something of a subtle issue here. One is tempted to say that a
standard-conforming C compiler *cannot* ignore that aspect since the
standard requires a diagnostic if the address of a register variable is
taken. However, the force of such a requirement is weaker than one might
suppose. Having issued the diagnostic (say as a warning) one could then
go on to generate (correct) code. I don't know of any C compiler that
does this.


Note also that in C++ things have changed:


A *register* declaration is an *auto* declaration, together
with a hint to the compiler that the variables declared will
be heavily used. The hint may be ignored and in most
implementations it will be ignored if the address of the
variable is taken.


[Working Paaper for Draft Proposed ANSI Systems -- Programming
Language C++ (ANSI DOC NO: X3J16/92-0023, Feb. 3. 1992, Section
7.1.1]


So in C++ you *can* take the address of a register variable, and thus the
keyword becomes even more of a vestige.
___
Gary H. Merrill [Principal Systems Developer, C Compiler Development]
SAS Institute Inc. / SAS Campus Dr. / Cary, NC 27513 / (919) 677-8000
sasghm@unx.sas.com ... !mcnc!sas!sasghm
--


Post a followup to this message

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