On Thu, 7 Aug 2014, Jan Hubicka wrote:

> > > 
> > > Probably not ;)
> > > 
> > > But seriously it's a matter of a) keeping constructors for each
> > > variable separate and optimize them in GIMPLE, b) recognize
> > > resulting code that can be expressed with a initializer
> > > 
> > > a) can be done with delaying inlining to IPA time and hoping
> > > that early opts do enough to perform the necessary simplification,
> > > b) needs a new pass (but I guess it shouldn't be _that_ hard...)
> > 
> > I'm not sure totally skipping inlining in C++ is that great an idea
> > since most C++ ctors will end up calling things.  Isn't it enough to not
> > inline the initializer for a variable into the file level function that
> > calls all the initializers, which you could do by internally apply
> > attribute noinline I guess.
> > 
> > > I think we already have constructor functions marked specially,
> > > hopefully with a link to the initialized variable.
> > 
> > I'd expect that's what DECL_STATIC_CONSTRUCTOR does, but I'm not sure
> > there's a link or where we could put one if there isn't.
> 
> If you mean language level static constructors, then it doesn't. C++ FE
> produce them and then wrap thems in static_construction functions that
> are the only having DECL_STATIC_CONSTRUCTOR calling the actual ctors.
> 
> Should not be hard to add though. Need to read back why inlining would
> be undesriable here - not inliing ctors in general would indeed be problematic
> (preventing SRA and more stuff)

It's only important to not inline the static constructor into the
one function calling all of them.  And only not doing that during
early inlining (but still inline into those constructors).  That's
because we eventually want to eliminate the body of the static
constructor in favor of a DECL_INITIAL in that new pass.

So we need to be able to identify

struct X { int i; X() { i = 1; } } a;

_constructor_of_a ()
{
  a.i = 1;
}

and place 'a' into .data with the appropriate initialization.
And then remove a.i = 1

Of course similar thing would be possible from the function
with all those constructors inlined but I guess it's much
harder if you may end up seeing calls inside (stuff may get
overwritten...).

OTOH, I wonder if

struct X { int i; X() { i = 1; } } a;
struct X { int i; X() { i = 1; a.i = 2; } } b;

is well-defined (with proper constructor priority attribute
to init a last or without).  That is, may we write to 'a'
from the constructor of b before it has been constructed?

Richard.

Reply via email to