[pkg-d-commits] [ldc] 102/211: Implement single-thread fences via the LDC_fence pragma. (#1837)

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:36:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.1.0
in repository ldc.

commit eab33ea7263e51ee43bd646c60f7f4d36466e12d
Author: LemonBoy <LemonBoy at users.noreply.github.com>
Date:   Tue Oct 18 20:20:44 2016 +0200

    Implement single-thread fences via the LDC_fence pragma. (#1837)
    
    * Implement single-thread fences.
    
    * Add a test for PR#1837
---
 gen/tocall.cpp               | 13 ++++++++++---
 runtime/druntime             |  2 +-
 tests/codegen/fence_pragma.d | 10 ++++++++++
 3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/gen/tocall.cpp b/gen/tocall.cpp
index a7ee42f..2c22d4e 100644
--- a/gen/tocall.cpp
+++ b/gen/tocall.cpp
@@ -329,11 +329,18 @@ bool DtoLowerMagicIntrinsic(IRState *p, FuncDeclaration *fndecl, CallExp *e,
 
   // fence instruction
   if (fndecl->llvmInternal == LLVMfence) {
-    if (e->arguments->dim != 1) {
-      e->error("fence instruction expects 1 arguments");
+    if (e->arguments->dim < 1 || e->arguments->dim > 2) {
+      e->error("fence instruction expects 1 (or 2) arguments");
       fatal();
     }
-    p->ir->CreateFence(llvm::AtomicOrdering((*e->arguments)[0]->toInteger()));
+    auto atomicOrdering =
+        static_cast<llvm::AtomicOrdering>((*e->arguments)[0]->toInteger());
+    auto scope = llvm::SynchronizationScope::CrossThread;
+    if (e->arguments->dim == 2) {
+      scope = static_cast<llvm::SynchronizationScope>(
+          (*e->arguments)[1]->toInteger());
+    }
+    p->ir->CreateFence(atomicOrdering, scope);
     return true;
   }
 
diff --git a/runtime/druntime b/runtime/druntime
index cf95c49..049b8ef 160000
--- a/runtime/druntime
+++ b/runtime/druntime
@@ -1 +1 @@
-Subproject commit cf95c49d685b78c6ba6f811ca210d243faf0d4d7
+Subproject commit 049b8efdf0daebcc1cfe690c5cf7585125c1ff72
diff --git a/tests/codegen/fence_pragma.d b/tests/codegen/fence_pragma.d
new file mode 100644
index 0000000..c2915ef
--- /dev/null
+++ b/tests/codegen/fence_pragma.d
@@ -0,0 +1,10 @@
+// RUN: %ldc %s -c -output-ll -of=%t.ll && FileCheck %s < %t.ll
+
+import ldc.intrinsics;
+
+void fun0 () {
+  llvm_memory_fence(DefaultOrdering, SynchronizationScope.CrossThread);
+  // CHECK: fence seq_cst
+  llvm_memory_fence(DefaultOrdering, SynchronizationScope.SingleThread);
+  // CHECK: fence singlethread seq_cst
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list