指令“atomic.fence”如何在通过 LLVM“stackify pass”生成的代码上工作?

How does the instruction "atomic.fence" work on the code generated through LLVM "stackify pass"?

提问人:Jason Yu 提问时间:11/10/2023 更新时间:11/10/2023 访问量:10

问:

我正在尝试找到一些关于 WebAssembly 指令 atomic.fence 的示例案例,但我只在互联网上找到的是该指令的 LLVM 实现中的测试用例,我的问题是“stackify pass”将如何影响指令顺序,以及下面测试代码的等效 WAT 代码是什么?

https://github.com/llvm/llvm-project/blob/fdbff88196b54cea12deb1fae978277066dffd1e/llvm/test/CodeGen/WebAssembly/atomic-fence.mir#L44C1-L66C4

# In the two tests below, without compiler_fence or atomic.fence in between,
# memory.atomic.notify and i32.add will be reordered by register stackify pass
# to meet 'call @foo''s requirements. But because we have fences between
# memory.atomic.notify and i32.add, they cannot be reordered, and local.set and
# local.get are inserted to save and load memory.atomic.notify's return value.

...


---
# CHECK-LABEL: name: atomic_fence_test
name: atomic_fence_test
liveins:
  - { reg: '$arguments' }
tracksRegLiveness: true
body: |
  bb.0:
    ; CHECK: %[[REG:[0-9]+]]:i32 = MEMORY_ATOMIC_NOTIFY_A32
    ; CHECK: LOCAL_SET_I32 [[LOCAL:[0-9]+]], %[[REG]]
    ; CHECK: ATOMIC_FENCE
    ; CHECK: ADD_I32
    ; CHECK: LOCAL_GET_I32 [[LOCAL]]
    ; CHECK: CALL @foo

    liveins: $arguments
    %0:i32 = CONST_I32 0, implicit-def $arguments
    %1:i32 = MEMORY_ATOMIC_NOTIFY_A32 2, 0, %0:i32, %0:i32, implicit-def $arguments
    ATOMIC_FENCE 0, implicit-def $arguments
    %2:i32 = ADD_I32 %0:i32, %0:i32, implicit-def $arguments
    CALL @foo, %2:i32, %1:i32, implicit-def $arguments
    RETURN implicit-def $arguments
...
LLVM WebAssembly(LLVM 网络汇编)

评论


答: 暂无答案