[cxx-mem-model] Change library call for __atomic_op_fetch routines
Andrew MacLeod
amacleod@redhat.com
Wed Oct 26 08:49:00 GMT 2011
The external library only provides the
__atomic_fetch_{add,sub,and,or,xor,nand} routines, which fetch the value
in memory before the operation is performed. It does not provide the
alternate operation which fetches the value after the operation (it is
trivial to calculate).
If the __atomic_{op}_fetch routine (which returns the value after the
operation) cannot be inlined, it needs to be transformed into the
fetch-before form, and have the appropriate calculation done to return
the correct value.
ie, if
c = __atomic_add_fetch (&b, a, __ATOMIC_RELAXED)
requires an external library call, it needs to be transformed into
c = __atomic_fetch_add (&b, a, __ATOMIC_RELAXED) + a;
This patch takes care of that. It seems to work when I hacked up some
test cases, but until I implement a flag to disable inlining all
atomics, its pretty hard to test thoroughly.
I find the bit in expand_builtin_atomic_fetch_op which changes the
function decl for the call a bit hacky maybe, but it seems to work. It
looks like that is exactly the way a builtin is built up. (ie, I don't
think the gcc_assert I added can fail, or previous calls to
get_callee_fndecl() wouldn't have returned a value which got us to this
hunk of code in the first place. Ie, the code there is reverse
engineered from get_callee_fndecl() to find the function decl and
change it. we know the built-in variations that are being changed are
identical in parameters and everything else.
thoughts?
Anyway, it bootstraps and passes all tests on x86_64-unknown-linux-gnu.
Andrew
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: op_func.diff
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20111026/796e5ed6/attachment.ksh>
More information about the Gcc-patches
mailing list