Modifies AtomicExpandPass to transform relaxed loads/RMW/AtomicXchg to acquire
[oota-llvm.git] / lib / CodeGen / AtomicExpandPass.cpp
index d12fdb246984e9db8949340221ec2935d99883ba..b2134a7859afc1a0b3db484afafcd31661ddd57e 100644 (file)
@@ -86,8 +86,40 @@ bool AtomicExpand::runOnFunction(Function &F) {
   // Changing control-flow while iterating through it is a bad idea, so gather a
   // list of all atomic instructions before we start.
   for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
-    if (I->isAtomic())
+    // XXX-update: For relaxed loads, change them to acquire. This includes
+    // relaxed loads, relaxed atomic RMW & relaxed atomic compare exchange.
+    if (I->isAtomic()) {
+      switch (I->getOpcode()) {
+        case Instruction::AtomicCmpXchg: {
+          auto* CmpXchg = dyn_cast<AtomicCmpXchgInst>(&*I);
+          auto SuccOrdering = CmpXchg->getSuccessOrdering();
+          if (SuccOrdering == Monotonic) {
+            CmpXchg->setSuccessOrdering(Acquire);
+          } else if (SuccOrdering == Release) {
+            CmpXchg->setSuccessOrdering(AcquireRelease);
+          }
+          break;
+        }
+        case Instruction::AtomicRMW: {
+          auto* RMW = dyn_cast<AtomicRMWInst>(&*I);
+          if (RMW->getOrdering() == Monotonic) {
+            RMW->setOrdering(Acquire);
+          }
+          break;
+        }
+        case Instruction::Load: {
+          auto* LI = dyn_cast<LoadInst>(&*I);
+          if (LI->getOrdering() == Monotonic) {
+            LI->setOrdering(Acquire);
+          }
+          break;
+        }
+        default: {
+          break;
+        }
+      }
       AtomicInsts.push_back(&*I);
+    }
   }
 
   bool MadeChange = false;