diff options
author | Dan Gohman <dan433584@gmail.com> | 2018-01-23 17:02:02 +0000 |
---|---|---|
committer | Dan Gohman <dan433584@gmail.com> | 2018-01-23 17:02:02 +0000 |
commit | 5464941a6a5ad85f8d041bf95181980b9eb45498 (patch) | |
tree | 9bd9bf12919e32b39b06c060fc8776a273bda47a | |
parent | 8e2fc4f3f836a082b0599a6bd74ada26e6c44b7a (diff) | |
download | bcm5719-llvm-5464941a6a5ad85f8d041bf95181980b9eb45498.tar.gz bcm5719-llvm-5464941a6a5ad85f8d041bf95181980b9eb45498.zip |
[WebAssembly] Add mem.* intrinsics.
The grow_memory and current_memory instructions are expected to be
officially renamed to mem.grow and mem.size. Introduce new intrinsics
with the new names. These new names aren't yet official, so for now,
use them at your own risk.
Also, take this opportunity to add arguments for the currently unused
immediate field in those instructions.
llvm-svn: 323222
-rw-r--r-- | llvm/include/llvm/IR/IntrinsicsWebAssembly.td | 16 | ||||
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td | 9 | ||||
-rw-r--r-- | llvm/test/CodeGen/WebAssembly/memory-addr32.ll | 21 |
3 files changed, 44 insertions, 2 deletions
diff --git a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td index 640ef627bc4..5c33e5e6706 100644 --- a/llvm/include/llvm/IR/IntrinsicsWebAssembly.td +++ b/llvm/include/llvm/IR/IntrinsicsWebAssembly.td @@ -14,8 +14,20 @@ let TargetPrefix = "wasm" in { // All intrinsics start with "llvm.wasm.". -// Note that current_memory is not IntrNoMem because it must be sequenced with -// respect to grow_memory calls. +// Query the current memory size, and increase the current memory size. +// Note that mem.size is not IntrNoMem because it must be sequenced with +// respect to mem.grow calls. +// These are the new proposed names, which aren't yet official. Use at your own +// risk. +def int_wasm_mem_size : Intrinsic<[llvm_anyint_ty], + [llvm_i32_ty], + [IntrReadMem]>; +def int_wasm_mem_grow : Intrinsic<[llvm_anyint_ty], + [llvm_i32_ty, LLVMMatchType<0>], + []>; + +// These are the existing names, which are currently official, but expected +// to be deprecated in the future. They also lack the immediate field. def int_wasm_current_memory : Intrinsic<[llvm_anyint_ty], [], [IntrReadMem]>; def int_wasm_grow_memory : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], []>; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td index 9d58895ca5a..660f0abfcab 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td @@ -523,12 +523,21 @@ def : Pat<(truncstorei32 I64:$val, (WebAssemblywrapper texternalsym:$off)), let Defs = [ARGUMENTS] in { // Current memory size. +def MEM_SIZE_I32 : I<(outs I32:$dst), (ins i32imm:$flags), + [(set I32:$dst, (int_wasm_mem_size (i32 imm:$flags)))], + "mem.size\t$dst, $flags", 0x3f>, + Requires<[HasAddr32]>; def CURRENT_MEMORY_I32 : I<(outs I32:$dst), (ins i32imm:$flags), [], "current_memory\t$dst", 0x3f>, Requires<[HasAddr32]>; // Grow memory. +def MEM_GROW_I32 : I<(outs I32:$dst), (ins i32imm:$flags, I32:$delta), + [(set I32:$dst, + (int_wasm_mem_grow (i32 imm:$flags), I32:$delta))], + "mem.grow\t$dst, $flags, $delta", 0x3f>, + Requires<[HasAddr32]>; def GROW_MEMORY_I32 : I<(outs I32:$dst), (ins i32imm:$flags, I32:$delta), [], "grow_memory\t$dst, $delta", 0x40>, diff --git a/llvm/test/CodeGen/WebAssembly/memory-addr32.ll b/llvm/test/CodeGen/WebAssembly/memory-addr32.ll index ad599b1b3f1..2d1f0f5ddc5 100644 --- a/llvm/test/CodeGen/WebAssembly/memory-addr32.ll +++ b/llvm/test/CodeGen/WebAssembly/memory-addr32.ll @@ -5,9 +5,30 @@ target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-unknown-wasm" +declare i32 @llvm.wasm.mem.size.i32(i32) nounwind readonly +declare i32 @llvm.wasm.mem.grow.i32(i32, i32) nounwind declare i32 @llvm.wasm.current.memory.i32() nounwind readonly declare i32 @llvm.wasm.grow.memory.i32(i32) nounwind +; CHECK-LABEL: mem_size: +; CHECK-NEXT: .result i32{{$}} +; CHECK-NEXT: mem.size $push0=, 0{{$}} +; CHECK-NEXT: return $pop0{{$}} +define i32 @mem_size() { + %a = call i32 @llvm.wasm.mem.size.i32(i32 0) + ret i32 %a +} + +; CHECK-LABEL: mem_grow: +; CHECK-NEXT: .param i32{{$}} +; CHECK-NEXT: .result i32{{$}} +; CHECK: mem.grow $push0=, 0, $0{{$}} +; CHECK-NEXT: return $pop0{{$}} +define i32 @mem_grow(i32 %n) { + %a = call i32 @llvm.wasm.mem.grow.i32(i32 0, i32 %n) + ret i32 %a +} + ; CHECK-LABEL: current_memory: ; CHECK-NEXT: .result i32{{$}} ; CHECK-NEXT: current_memory $push0={{$}} |