Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly] Support for atomic fences
Summary: This adds support for translation of LLVM IR fence instruction. We convert a singlethread fence to a pseudo compiler barrier which becomes 0 instructions in final binary, and a thread fence to an idempotent atomicrmw instruction to a memory address. Reviewers: dschuff, jfb, sunfish, tlively Subscribers: sbc100, jgravelle-google, llvm-commits Differential Revision: https://reviews.llvm.org/D50277 llvm-svn: 361884
- Loading branch information
Showing
4 changed files
with
154 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
; RUN: llc < %s | FileCheck %s --check-prefix NOATOMIC | ||
; RUN: not llc < %s -mtriple=wasm32-unknown-unknown -mattr=+atomics,+sign-ext 2>&1 | FileCheck %s --check-prefixes NOEMSCRIPTEN | ||
; RUN: not llc < %s -mtriple=wasm32-unknown-wasi -mattr=+atomics,+sign-ext 2>&1 | FileCheck %s --check-prefixes NOEMSCRIPTEN | ||
; RUN: llc < %s -mtriple=wasm32-unknown-emscripten -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics,+sign-ext | FileCheck %s | ||
|
||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" | ||
target triple = "wasm32-unknown-unknown" | ||
|
||
; NOEMSCRIPTEN: LLVM ERROR: ATOMIC_FENCE is not yet supported in non-emscripten OSes | ||
|
||
; A multithread fence turns into 'global.get $__stack_pointer' followed by an | ||
; idempotent atomicrmw instruction. | ||
; CHECK-LABEL: multithread_fence: | ||
; CHECK: global.get $push[[SP:[0-9]+]]=, __stack_pointer | ||
; CHECK-NEXT: i32.const $push[[ZERO:[0-9]+]]=, 0 | ||
; CHECK-NEXT: i32.atomic.rmw.or $drop=, 0($pop[[SP]]), $pop[[ZERO]] | ||
; NOATOMIC-NOT: i32.atomic.rmw.or | ||
define void @multithread_fence() { | ||
fence seq_cst | ||
ret void | ||
} | ||
|
||
; Fences with weaker memory orderings than seq_cst should be treated the same | ||
; because atomic memory access in wasm are sequentially consistent. | ||
; CHECK-LABEL: multithread_weak_fence: | ||
; CHECK: global.get $push{{.+}}=, __stack_pointer | ||
; CHECK: i32.atomic.rmw.or | ||
; CHECK: i32.atomic.rmw.or | ||
; CHECK: i32.atomic.rmw.or | ||
define void @multithread_weak_fence() { | ||
fence acquire | ||
fence release | ||
fence acq_rel | ||
ret void | ||
} | ||
|
||
; A singlethread fence becomes compiler_fence instruction, a pseudo instruction | ||
; that acts as a compiler barrier. The barrier should not be emitted to .s file. | ||
; CHECK-LABEL: singlethread_fence: | ||
; CHECK-NOT: compiler_fence | ||
define void @singlethread_fence() { | ||
fence syncscope("singlethread") seq_cst | ||
fence syncscope("singlethread") acquire | ||
fence syncscope("singlethread") release | ||
fence syncscope("singlethread") acq_rel | ||
ret void | ||
} |