On 05/23/2013 12:06 PM, Richard Henderson wrote: > Another thing I should mention while you're doing all of these static function > to class member conversions is that as written we're losing target-specific > optimizations that can be done on purely local functions. This is trivially > fixed by placing these new classes in an anonymous namespace.
At which point it occurs to me that we don't need to distinguish between static and normal member methods, nor play with sub-state structures. All we need to require is that IPA constant propagation sees that the initial "this" argument is passed a constant value, and let it propagate and eliminate. E.g. namespace { class pass_state { private: int x, y, z; public: constexpr pass_state() : x(0), y(0), z(0) { } void doit(); private: void a(); void b(); void c(); }; // ... } // anon namespace #ifdef GLOBAL_STATE static pass_state ps; #endif void toplev() { #ifndef GLOBAL_STATE pass_state ps; #endif ps.doit(); } With an example that's probably too small, I verified that gcc will eliminate all of the this parameters with GLOBAL_STATE defined. It's certainly something worth investigating further, as this scheme has the least amount of boilerplate of any so far advanced. r~