This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PCH, and more generally C++ parser performance
- To: geoffk at cygnus dot com (Geoff Keating)
- Subject: Re: PCH, and more generally C++ parser performance
- From: Joe Buck <jbuck at racerx dot synopsys dot com>
- Date: Tue, 29 Aug 2000 19:33:25 -0700 (PDT)
- Cc: zack at wolery dot cumb dot org, shebs at apple dot com, gcc at gcc dot gnu dot org
I wrote:
> > There are a couple of things that you're of course already aware of, like
> > constructors and destructors that may have side effects, and the impact
> > that the existence of a declaration may have on name resolution.
Geoff Keating writes:
> I did indeed think of those.
>
> Constructors, destructors, variable definitions, non-inline procedure
> definitions all have to be handled specially, because they all produce
> assembler output. You can't lazily compile
>
> int x = 3;
>
> even in C because even if 'x' is never used in a particular
> compilation unit, some other unit might use it. The options I see for
> such code are:
>
> - don't allow these
> - don't precompile these
> - save a chunk of assembler input which gets stuck in when the PCH is
> used. This would have the disadvantage that you could have
> conflicts if any assembler was output before the PCH was included,
> so you would have to prohibit this.
> - be really clever, make sure the assembler has no conflicts
> by (say) renaming internal symbols. This would be hard.
>
> My instinct is to start by implementing the first or second, and then
> extend it later if that turns out to be too slow.
This may not suffice, because of a few C++ idioms that won't be supported.
In particular, you can't precompile the iostreams headers, and if you
can't do that, the C++ community isn't going to be that interested.
Look in libstdc++-v3/bits/std_iostream.h. You will find
namespace std {
....
static ios_base::Init __ioinit;
};
ios_base::Init is a hack to assure that cin/cout/cerr/clog get initialized
before any use even in constructors for file-scope objects. The idea is
that one ios_base::Init object will get built for each .o file that
includes <iostream>. A counter is maintained, incremented in the
constructor and decremented in the destructor. The constructor and
destructor handle initialization and finalization of the standard streams.
This is actually a kludge first invented by the cfront people, and
Stroustrup is inordinately proud of it. Since he's told people about
it in his books, you can expect to encounter it.
As a comment in ios_base.h says, we could avoid this kludge by relying
on -finit-priority to give the constructors for iostreams priority over
everything else, but that won't work on all GCC target platforms
(you need a new-enough version of the GNU linker).
So what to do instead? Something like "save a hunk of assembler"?
Do you intend for PCH's to be machine-independent or machine-dependent?
Perhaps a limited number of common forms, corresponding to constructors
and initializers could be supported in a machine independent way.
The two most obvious things to support are the equivalent of
int x = 3;
and
static some_class some_obj;
where a note saying "set x to 3" or "include constructor and destructor
for some_obj" could be represented in a machine-independent way.