[PATCH] D12338: Add a boolean parameter to make the initial load atomic.

Richard Diamond via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 25 14:44:39 PDT 2015


DiamondLovesYou created this revision.
DiamondLovesYou added a reviewer: jfb.
DiamondLovesYou added a subscriber: llvm-commits.
Herald added subscribers: dschuff, jfb.

PNaCl needs this so optimization/targetmachine passes don't reorder the initial load upon translation to a native target.

http://reviews.llvm.org/D12338

Files:
  include/llvm/CodeGen/AtomicExpandUtils.h
  lib/CodeGen/AtomicExpandPass.cpp

Index: lib/CodeGen/AtomicExpandPass.cpp
===================================================================
--- lib/CodeGen/AtomicExpandPass.cpp
+++ lib/CodeGen/AtomicExpandPass.cpp
@@ -251,7 +251,7 @@
     return expandAtomicRMWToLLSC(AI);
   }
   case TargetLoweringBase::AtomicRMWExpansionKind::CmpXChg: {
-    return expandAtomicRMWToCmpXchg(AI, createCmpXchgInstFun);
+    return expandAtomicRMWToCmpXchg(AI, createCmpXchgInstFun, false);
   }
   }
   llvm_unreachable("Unhandled case in tryExpandAtomicRMW");
@@ -512,7 +512,8 @@
 }
 
 bool llvm::expandAtomicRMWToCmpXchg(AtomicRMWInst *AI,
-                                    CreateCmpXchgInstFun CreateCmpXchg) {
+                                    CreateCmpXchgInstFun CreateCmpXchg,
+                                    const bool IsRelaxed) {
   assert(AI);
 
   AtomicOrdering MemOpOrder =
@@ -551,6 +552,9 @@
   LoadInst *InitLoaded = Builder.CreateLoad(Addr);
   // Atomics require at least natural alignment.
   InitLoaded->setAlignment(AI->getType()->getPrimitiveSizeInBits() / 8);
+  if(IsRelaxed) {
+    InitLoaded->setOrdering(SequentiallyConsistent);
+  }
   Builder.CreateBr(LoopBB);
 
   // Start the main loop block now that we've taken care of the preliminaries.
Index: include/llvm/CodeGen/AtomicExpandUtils.h
===================================================================
--- include/llvm/CodeGen/AtomicExpandUtils.h
+++ include/llvm/CodeGen/AtomicExpandUtils.h
@@ -53,5 +53,6 @@
 ///
 /// Returns true if the containing function was modified.
 bool
-expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun Factory);
+expandAtomicRMWToCmpXchg(AtomicRMWInst *AI, CreateCmpXchgInstFun Factory,
+                         const bool IsRelaxed);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12338.33129.patch
Type: text/x-patch
Size: 1735 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150825/a712d241/attachment.bin>


More information about the llvm-commits mailing list