[llvm-commits] patch: CXAGuardElimination pass.

Nick Lewycky nicholas at mxc.ca
Sun May 24 22:46:26 PDT 2009


Eli Friedman wrote:
> On Sun, May 24, 2009 at 9:34 PM, Nick Lewycky <nicholas at mxc.ca> wrote:
>> This pass eliminates dead calls to __cxa_guard_acquire and
>> __cxa_guard_release. Those two functions are defined by the Itanium ABI as
>> part of the thread-safe one-time construction ABI for static variables in
>> functions.
>>
>> For example, this program:
>>
>>  struct X {
>>    X(int) {}
>>  };
>>
>>  void foo() {
>>    static X x(10);
>>  }
>>
>> would have calls to cxa_guard_* in foo, and this pass detects that there is
>> no real work being done between the guards and therefore it is safe to
>> eliminate them.
> 
> This isn't completely a question about your patch, but why are we
> loading and storing an i8 from an i64 global?

Because the ABI says so.

1. "The size of the guard variable is 64 bits. The first byte (i.e. the 
byte at the address of the full variable) shall contain the value 0 
prior to initialization of the associated variable, and 1 after 
initialization is complete. Usage of the other bytes of the guard 
variable is implementation-defined."

  -- http://www.codesourcery.com/public/cxx-abi/abi.html#guards

2. "extern "C" void __cxa_guard_release ( __int64_t *guard_object );

      "Sets the first byte of the guard object to a non-zero value. ..."

  -- http://www.codesourcery.com/public/cxx-abi/abi.html#once-ctor

Nick



More information about the llvm-commits mailing list