[PATCH] D18200: Add __atomic_* lowering to AtomicExpandPass.

James Y Knight via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 15 15:38:14 PDT 2016


jyknight created this revision.
jyknight added subscribers: theraven, rnk, hfinkel, jfb, reames, joerg, llvm-commits.
Herald added subscribers: dsanders, jyknight.

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
the frontend.

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
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.

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.

http://reviews.llvm.org/D18200

Files:
  docs/Atomics.rst
  include/llvm/CodeGen/RuntimeLibcalls.h
  include/llvm/Target/TargetLowering.h
  lib/CodeGen/AtomicExpandPass.cpp
  lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  lib/CodeGen/TargetLoweringBase.cpp
  lib/Target/ARM/ARMISelLowering.cpp
  lib/Target/ARM/ARMISelLowering.h
  lib/Target/Hexagon/HexagonISelLowering.cpp
  lib/Target/Mips/MipsISelLowering.cpp
  lib/Target/Mips/MipsISelLowering.h
  lib/Target/PowerPC/PPCISelLowering.cpp
  lib/Target/PowerPC/PPCISelLowering.h
  lib/Target/Sparc/SparcISelLowering.cpp
  lib/Target/Sparc/SparcISelLowering.h
  lib/Target/XCore/XCoreISelLowering.cpp
  lib/Target/XCore/XCoreISelLowering.h
  test/Transforms/AtomicExpand/SPARC/libcalls.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18200.50779.patch
Type: text/x-patch
Size: 64728 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160315/c98113ab/attachment.bin>


More information about the llvm-commits mailing list