[PATCH] Implement emitLeading/TrailingFence in the ARM backend

Robin Morisset morisset at google.com
Mon Aug 18 15:09:04 PDT 2014


Hi jfb,

Depends on D4959.

http://reviews.llvm.org/D4960

Files:
  lib/Target/ARM/ARMISelLowering.cpp
  lib/Target/ARM/ARMISelLowering.h

Index: lib/Target/ARM/ARMISelLowering.cpp
===================================================================
--- lib/Target/ARM/ARMISelLowering.cpp
+++ lib/Target/ARM/ARMISelLowering.cpp
@@ -10857,6 +10857,63 @@
   return true;
 }
 
+void MakeDMB(IRBuilder<> &Builder, unsigned Domain) {
+  Module *M = Builder.GetInsertBlock()->getParent()->getParent();
+  Function *DMB = llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_dmb);
+  Constant *CDomain = Builder.getInt32(Domain);
+  Builder.CreateCall(DMB, CDomain);
+}
+
+void ARMTargetLowering::emitLeadingFence(IRBuilder<> &Builder,
+                                    AtomicOrdering Ord,
+                                    bool IsStore, bool IsLoad) const {
+  if (!getInsertFencesForAtomic())
+    return;
+
+  switch (Ord) {
+    case NotAtomic:
+    case Unordered:
+      llvm_unreachable("An unordered/not-atomic fence makes no sense");
+    case Monotonic:
+    case Acquire:
+      return; // Nothing to do
+    case SequentiallyConsistent:
+      if (!IsStore)
+        return; // Nothing to do
+      MakeDMB(Builder, ARM_MB::ISH);
+      return;
+    case Release:
+    case AcquireRelease:
+      if (Subtarget->isSwift())
+        MakeDMB(Builder, ARM_MB::ISHST);
+      else
+        MakeDMB(Builder, ARM_MB::ISH);
+      return;
+  }
+}
+
+void ARMTargetLowering::emitTrailingFence(IRBuilder<> &Builder,
+                                    AtomicOrdering Ord,
+                                    bool IsStore, bool IsLoad) const {
+  if (!getInsertFencesForAtomic())
+    return;
+
+  switch (Ord) {
+    case NotAtomic:
+    case Unordered:
+      llvm_unreachable("An unordered/not-atomic fence makes no sense");
+    case Monotonic:
+    case Release:
+      return; // Nothing to do
+    case Acquire:
+    case AcquireRelease:
+      // FIXME: Too conservative, an isb after a dependent branch is enough
+    case SequentiallyConsistent:
+      MakeDMB(Builder, ARM_MB::ISH);
+      return;
+  }
+}
+
 bool ARMTargetLowering::shouldExpandAtomicInIR(Instruction *Inst) const {
   // Loads and stores less than 64-bits are already atomic; ones above that
   // are doomed anyway, so defer to the default libcall and blame the OS when
Index: lib/Target/ARM/ARMISelLowering.h
===================================================================
--- lib/Target/ARM/ARMISelLowering.h
+++ lib/Target/ARM/ARMISelLowering.h
@@ -397,6 +397,11 @@
     Value *emitStoreConditional(IRBuilder<> &Builder, Value *Val,
                                 Value *Addr, AtomicOrdering Ord) const override;
 
+    void emitLeadingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
+                            bool IsStore, bool IsLoad) const override;
+    void emitTrailingFence(IRBuilder<> &Builder, AtomicOrdering Ord,
+                            bool IsStore, bool IsLoad) const override;
+
     bool shouldExpandAtomicInIR(Instruction *Inst) const override;
 
     bool useLoadStackGuardNode() const override;
@@ -415,7 +420,6 @@
     const InstrItineraryData *Itins;
 
     /// ARMPCLabelIndex - Keep track of the number of ARM PC labels created.
-    ///
     unsigned ARMPCLabelIndex;
 
     void addTypeForNEON(MVT VT, MVT PromotedLdStVT, MVT PromotedBitwiseVT);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4960.12630.patch
Type: text/x-patch
Size: 3226 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140818/8b95e1da/attachment.bin>


More information about the llvm-commits mailing list