Add __atomic_* lowering to AtomicExpandPass.
authorJames Y Knight <jyknight@google.com>
Tue, 12 Apr 2016 20:18:48 +0000 (20:18 +0000)
committerJames Y Knight <jyknight@google.com>
Tue, 12 Apr 2016 20:18:48 +0000 (20:18 +0000)
commit19f6cce4e34d94e3aab0f6f8de3122dee3b9a0ed
tree8b8ce8d363279d0d010d4ac6ba4c2fd72ee01490
parentb861ec87348ec9ee0d5e346fa7dab889bc0ec32f
Add __atomic_* lowering to AtomicExpandPass.

(Recommit of r266002, with r266011, r266016, and not accidentally
including an extra unused/uninitialized element in LibcallRoutineNames)

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. There, unsupported atomic instructions would turn into __sync_*
library calls. Because of that behavior, Clang currently avoids emitting
llvm IR atomic instructions when this would happen, and emits __atomic_*
library functions itself, in the frontend.

This change makes LLVM able to emit __atomic_* libcalls, and thus will
eventually allow clang to depend on LLVM to do the right thing.

It is advantageous to do the new lowering to atomic libcalls in
AtomicExpandPass, before ISel time, because it's important that all
atomic operations for a given size either lower to __atomic_*
libcalls (which may use locks), or native instructions which won't. No
mixing and matching.

At the moment, this code is enabled only for SPARC, as a
demonstration. The next commit will expand support to all of the other
targets.

Differential Revision: http://reviews.llvm.org/D18200

llvm-svn: 266115
llvm/docs/Atomics.rst
llvm/include/llvm/CodeGen/RuntimeLibcalls.h
llvm/include/llvm/Target/TargetLowering.h
llvm/lib/CodeGen/AtomicExpandPass.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/Target/Sparc/SparcISelLowering.cpp
llvm/test/Transforms/AtomicExpand/SPARC/libcalls.ll [new file with mode: 0644]
llvm/test/Transforms/AtomicExpand/SPARC/lit.local.cfg [new file with mode: 0644]