This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Functions that are CSEable but not pure


On 10/11/2012 11:14 AM, Alexandre Oliva wrote:
How about marking the singleton containing the call to the initializer
as always_inline, but not the initializer itself?

The compiler can then infer that initialized is set on the first inlined
call and optimize away subsequent tests and initializer calls
(call_some_function_that_may_modify_memory).

That would require exporting the initialized flag in addition to the initializer function; currently it is private to the translation unit with the initializer function. That is, the wrapper currently looks like


int& i_wrap()
{
  if (i_init) i_init();
  return i;
}

and your suggestion would change it to

int& i_wrap()
{
  if (i_init && !i_initialized) { i_initialized = true; i_init(); }
  return i;
}

In previous discussions, people thought this would be less efficient.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]