low level optimization

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Fri Apr 19 18:31:01 AEST 1991


In article <21703 at lanl.gov> jlg at cochiti.lanl.gov (Jim Giles) writes:
> The only information available to the compiler about
> procedures that are separately compiled are the names of routines
> that the current procedure calls and the number and type of their
> arguments and results (if any).

This is incorrect. The standard makes no special allowance for ``the
names of routines that the current procedure calls and [etc.].'' Each
C source file has a *meaning* dependent solely upon the information in
that file and its inclusions. Nevertheless, optimizations do not change
that meaning and may depend upon other information.

> For a language which requires
> separate compilation, _NO_OTHER_INFORMATION_ is known about an
> external procedure.

This is incorrect. Again, the meaning of a source file depends solely
upon that source file, prototypes in #includes, etc., but lots of other
information may be known to the compiler.

> The reason is that _all_ other characteristics
> of an external procedure are allowed to _change_ without the need to
> recompile any uses of that procedure.

This is incorrect. Compilation consists of translation (like foo.c
becoming foo.o) and loading (like foo.o and bar.o becoming a.out).
The *translation* of one file is independent of other files, but the
*loading* depends on all the files together.

> The bottom line is that separate compilation implies that procedures
> may be used together for which the _source_ of the separate routines
> has never even existed in the same programming environment and only
> the object code has been distributed.

This is incorrect. The ANSI C standard requires separate compilation. It
does not define ``the same programming environment'' or ``distributed.''
(As I pointed out in my previous article, a conforming compiler may
produce object code that includes the entire source code, so Jim's
statement is obviously wrong.)

> Further, even the object code
> of each may not be available at the time each of the other procedures
> is compiled.

This is incorrect. Compilation includes loading, and loading requires
all object code for the program. It's true that the other objects may
not be available at *translation* time, but optimizations aren't
restricted to translation time.

> Hence, under separate compilation there may be no internal
> information about other procedures used when a given procedure is compiled
> because such information may not exist, may be speculative, or may 
> subsequently change without notice.

This is incorrect. The correct information may be carried along with
each object file.

---Dan



More information about the Comp.lang.c mailing list