AtomicExpandPass can now lower atomic load, atomic store, atomicrmw, and
cmpxchg instructions to __atomic_* library calls, when the target
doesn't support atomics of a given size.
This is the first step towards moving all atomic lowering from clang
into llvm. When all is done, the behavior of sync_* builtins,
atomic_* builtins, and C11 atomics will be unified.
Previously LLVM would pass everything through to the ISelLowering code,
where unsupported atomic instructions would turn into sync_* library
functions. Because of that, Clang avoids emitting atomic instructions
when this will happen, and emits atomic_* library functions itself in
It is advantageous to do the lowering to atomic libcalls before ISel
time, because it's important that all atomic instructions for a given
size either lower to __atomic_* libcalls, or don't. No mixing and
At the moment, this code is enabled only for SPARC, as a
demonstration. The next commit will expand support to all of the other
There's also a few minor other changes:
- getInsertFencesForAtomic() is replaced with shouldInsertFencesForAtomic(), so that the decision can be made per-instruction. (This will be used in the next patch)
- emitLeadingFence/emitTrailingFence are no longer called when shouldInsertFencesForAtomic is false, so don't need to check that condition themselves.