r203560 - Update for IR: add a second AtomicOrdering to cmpxchg insts.

Tim Northover tnorthover at apple.com
Tue Mar 11 03:49:03 PDT 2014


Author: tnorthover
Date: Tue Mar 11 05:49:03 2014
New Revision: 203560

URL: http://llvm.org/viewvc/llvm-project?rev=203560&view=rev
Log:
Update for IR: add a second AtomicOrdering to cmpxchg insts.

rdar://problem/15996804

Modified:
    cfe/trunk/lib/CodeGen/CGAtomic.cpp
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/lib/CodeGen/CGExprScalar.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=203560&r1=203559&r2=203560&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Tue Mar 11 05:49:03 2014
@@ -201,13 +201,14 @@ EmitAtomicOp(CodeGenFunction &CGF, Atomi
   case AtomicExpr::AO__atomic_compare_exchange_n: {
     // Note that cmpxchg only supports specifying one ordering and
     // doesn't support weak cmpxchg, at least at the moment.
-
     llvm::LoadInst *Expected = CGF.Builder.CreateLoad(Val1);
     Expected->setAlignment(Align);
     llvm::LoadInst *Desired = CGF.Builder.CreateLoad(Val2);
     Desired->setAlignment(Align);
-    llvm::AtomicCmpXchgInst *Old =
-        CGF.Builder.CreateAtomicCmpXchg(Ptr, Expected, Desired, Order);
+    llvm::AtomicOrdering FailureOrder =
+        llvm::AtomicCmpXchgInst::getStrongestFailureOrdering(Order);
+    llvm::AtomicCmpXchgInst *Old = CGF.Builder.CreateAtomicCmpXchg(
+        Ptr, Expected, Desired, Order, FailureOrder);
     Old->setVolatile(E->isVolatile());
 
     // Cmp holds the result of the compare-exchange operation: true on success,

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=203560&r1=203559&r2=203560&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Mar 11 05:49:03 2014
@@ -964,6 +964,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
     Args[2] = EmitToInt(*this, EmitScalarExpr(E->getArg(2)), T, IntType);
 
     Value *Result = Builder.CreateAtomicCmpXchg(Args[0], Args[1], Args[2],
+                                                llvm::SequentiallyConsistent,
                                                 llvm::SequentiallyConsistent);
     Result = EmitFromInt(*this, Result, T, ValueType);
     return RValue::get(Result);
@@ -990,6 +991,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
     Value *OldVal = Args[1];
     Value *PrevVal = Builder.CreateAtomicCmpXchg(Args[0], Args[1], Args[2],
+                                                 llvm::SequentiallyConsistent,
                                                  llvm::SequentiallyConsistent);
     Value *Result = Builder.CreateICmpEQ(PrevVal, OldVal);
     // zext bool to int.
@@ -1504,6 +1506,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
         EmitScalarExpr(E->getArg(0)),
         EmitScalarExpr(E->getArg(2)),
         EmitScalarExpr(E->getArg(1)),
+        SequentiallyConsistent,
         SequentiallyConsistent);
       CXI->setVolatile(true);
       return RValue::get(CXI);

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=203560&r1=203559&r2=203560&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Tue Mar 11 05:49:03 2014
@@ -1735,8 +1735,9 @@ ScalarExprEmitter::EmitScalarPrePostIncD
   if (atomicPHI) {
     llvm::BasicBlock *opBB = Builder.GetInsertBlock();
     llvm::BasicBlock *contBB = CGF.createBasicBlock("atomic_cont", CGF.CurFn);
-    llvm::Value *old = Builder.CreateAtomicCmpXchg(LV.getAddress(), atomicPHI,
-        CGF.EmitToMemory(value, type), llvm::SequentiallyConsistent);
+    llvm::Value *old = Builder.CreateAtomicCmpXchg(
+        LV.getAddress(), atomicPHI, CGF.EmitToMemory(value, type),
+        llvm::SequentiallyConsistent, llvm::SequentiallyConsistent);
     atomicPHI->addIncoming(old, opBB);
     llvm::Value *success = Builder.CreateICmpEQ(old, atomicPHI);
     Builder.CreateCondBr(success, contBB, opBB);
@@ -2077,8 +2078,9 @@ LValue ScalarExprEmitter::EmitCompoundAs
   if (atomicPHI) {
     llvm::BasicBlock *opBB = Builder.GetInsertBlock();
     llvm::BasicBlock *contBB = CGF.createBasicBlock("atomic_cont", CGF.CurFn);
-    llvm::Value *old = Builder.CreateAtomicCmpXchg(LHSLV.getAddress(), atomicPHI,
-        CGF.EmitToMemory(Result, LHSTy), llvm::SequentiallyConsistent);
+    llvm::Value *old = Builder.CreateAtomicCmpXchg(
+        LHSLV.getAddress(), atomicPHI, CGF.EmitToMemory(Result, LHSTy),
+        llvm::SequentiallyConsistent, llvm::SequentiallyConsistent);
     atomicPHI->addIncoming(old, opBB);
     llvm::Value *success = Builder.CreateICmpEQ(old, atomicPHI);
     Builder.CreateCondBr(success, contBB, opBB);





More information about the cfe-commits mailing list