[llvm-commits] cxa_guard elimination
Nick Lewycky
nicholas at mxc.ca
Sat Jan 7 18:48:25 PST 2012
This patch implements some really basic elimination of calls to
__cxa_guard. More advanced cases can be added on request. Patch
attached, please review!
There's one thing I need to draw to a reviewer's attention. I make the
assumption that the code in the 'not-yet-initialized' path is indeed
initializing. That is to say that I assume that this pseudo-code:
*global = x;
if (expr) {
if (cxa_guard_acquire(global_guard)) {
*global = 0;
cxa_guard_release(global_guard);
}
}
use(global);
represents undefined behavior because global is initialized before the
call to __cxa_guard_acquire, and the guard is protecting a normal store,
not the first store.
The Itanium C++ ABI never states that guard_acquire/release must be used
for *initializing*, so this patch arguably can miscompile. However, it's
generally understood that this is for initialization (indeed, the
section heading is "Once-time initialization API") so I'm hoping we can
agree that this assumption is valid and ask users doing other things
with cxa_guard_acquire/release to pass -fno-builtins.
Otherwise, we'll have to prove that the cxa_guard_acquire dominates all
other uses of the global. Which sounds simple enough, except that it
actually never does; instead, we peel off part of the work that
cxa_guard_acquire does into the caller, and use that to bypass the cost
of the call when it's unnecessary. So we'd have to detect that test, and
show that the CFG works out in such a way that all uses of the global
are dominated by that initialization check.
Nick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cxa-guard-1.patch
Type: text/x-diff
Size: 10883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120107/609d1eb0/attachment.patch>
More information about the llvm-commits
mailing list