On Thu, Aug 07, 2014 at 01:44:02PM +0200, Jan Hubicka wrote: > > 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. > > I see, that indeed makes sense (and I was thinking of that). > Disabling early inlining of static ctors seems OK, but we may > not even need to do that given that we process topologically - so > we will identify simple ctor before we inline it. > (assuming we do not want to do this at LTO that would also make > sense) > > > > 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 > > Yeah, I think annotating cgraph nodes with info "this is static > ctor of this variable" would be easy and we don't neven need to > mess with the rest of C++ FE finalization code (i.e. one unifying > it to static construction functions). > Early inliner can skip inlining these if desirable and the new > pass can easily identify them.
I'm not sure how you find the variable given a cgraph node, but if you do great. > Being able to turn stores into ctor is something that may be > shareable with Martin's ipa-prop analysis. that's handy, have a link? > He is basically doing that IMO. > > > > 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? > > Hehe, not a question for me :) I feel like the anser should be if you write to a global before its I feel like it should only be valid to write to a global variable after its initialized, but I really don't know what C++ says. Trev > > Honza > > > > Richard.