diff options
author | JF Bastien <jfb@google.com> | 2016-04-18 18:01:43 +0000 |
---|---|---|
committer | JF Bastien <jfb@google.com> | 2016-04-18 18:01:43 +0000 |
commit | bbb0aee66ea6a6175d6143975969ebd5048e4fa7 (patch) | |
tree | 2cc8fd995b2df98effe13af7a76e343ab6796ebf /llvm/lib/CodeGen/AtomicExpandPass.cpp | |
parent | b7fd9fa5e27a48da2806537fa8236cf81e2da54b (diff) | |
download | bcm5719-llvm-bbb0aee66ea6a6175d6143975969ebd5048e4fa7.tar.gz bcm5719-llvm-bbb0aee66ea6a6175d6143975969ebd5048e4fa7.zip |
NFC: unify clang / LLVM atomic ordering
This makes the C11 / C++11 *ABI* atomic ordering accessible from LLVM,
as discussed in http://reviews.llvm.org/D18200#inline-151433
This re-applies r266573 which I had reverted in r266576.
Original review: http://reviews.llvm.org/D18875
llvm-svn: 266640
Diffstat (limited to 'llvm/lib/CodeGen/AtomicExpandPass.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AtomicExpandPass.cpp | 46 |
1 files changed, 8 insertions, 38 deletions
diff --git a/llvm/lib/CodeGen/AtomicExpandPass.cpp b/llvm/lib/CodeGen/AtomicExpandPass.cpp index e0c7fd6f883..47e69d8ac25 100644 --- a/llvm/lib/CodeGen/AtomicExpandPass.cpp +++ b/llvm/lib/CodeGen/AtomicExpandPass.cpp @@ -937,39 +937,6 @@ bool llvm::expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, return true; } -// This converts from LLVM's internal AtomicOrdering enum to the -// memory_order_* value required by the __atomic_* libcalls. -static int libcallAtomicModel(AtomicOrdering AO) { - enum { - AO_ABI_memory_order_relaxed = 0, - AO_ABI_memory_order_consume = 1, - AO_ABI_memory_order_acquire = 2, - AO_ABI_memory_order_release = 3, - AO_ABI_memory_order_acq_rel = 4, - AO_ABI_memory_order_seq_cst = 5 - }; - - switch (AO) { - case AtomicOrdering::NotAtomic: - llvm_unreachable("Expected atomic memory order."); - case AtomicOrdering::Unordered: - case AtomicOrdering::Monotonic: - return AO_ABI_memory_order_relaxed; - // Not implemented yet in llvm: - // case AtomicOrdering::Consume: - // return AO_ABI_memory_order_consume; - case AtomicOrdering::Acquire: - return AO_ABI_memory_order_acquire; - case AtomicOrdering::Release: - return AO_ABI_memory_order_release; - case AtomicOrdering::AcquireRelease: - return AO_ABI_memory_order_acq_rel; - case AtomicOrdering::SequentiallyConsistent: - return AO_ABI_memory_order_seq_cst; - } - llvm_unreachable("Unknown atomic memory order."); -} - // In order to use one of the sized library calls such as // __atomic_fetch_add_4, the alignment must be sufficient, the size // must be one of the potentially-specialized sizes, and the value @@ -1151,12 +1118,15 @@ bool AtomicExpand::expandAtomicOpToLibcall( // TODO: the "order" argument type is "int", not int32. So // getInt32Ty may be wrong if the arch uses e.g. 16-bit ints. ConstantInt *SizeVal64 = ConstantInt::get(Type::getInt64Ty(Ctx), Size); + assert(Ordering != AtomicOrdering::NotAtomic && "expect atomic MO"); Constant *OrderingVal = - ConstantInt::get(Type::getInt32Ty(Ctx), libcallAtomicModel(Ordering)); - Constant *Ordering2Val = CASExpected - ? ConstantInt::get(Type::getInt32Ty(Ctx), - libcallAtomicModel(Ordering2)) - : nullptr; + ConstantInt::get(Type::getInt32Ty(Ctx), (int)toCABI(Ordering)); + Constant *Ordering2Val = nullptr; + if (CASExpected) { + assert(Ordering2 != AtomicOrdering::NotAtomic && "expect atomic MO"); + Ordering2Val = + ConstantInt::get(Type::getInt32Ty(Ctx), (int)toCABI(Ordering2)); + } bool HasResult = I->getType() != Type::getVoidTy(Ctx); RTLIB::Libcall RTLibType; |