llvm.org GIT mirror llvm / ecb7ca8
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323222 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 2 years ago
3 changed file(s) with 44 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
1313
1414 let TargetPrefix = "wasm" in { // All intrinsics start with "llvm.wasm.".
1515
16 // Note that current_memory is not IntrNoMem because it must be sequenced with
17 // respect to grow_memory calls.
16 // Query the current memory size, and increase the current memory size.
17 // Note that mem.size is not IntrNoMem because it must be sequenced with
18 // respect to mem.grow calls.
19 // These are the new proposed names, which aren't yet official. Use at your own
20 // risk.
21 def int_wasm_mem_size : Intrinsic<[llvm_anyint_ty],
22 [llvm_i32_ty],
23 [IntrReadMem]>;
24 def int_wasm_mem_grow : Intrinsic<[llvm_anyint_ty],
25 [llvm_i32_ty, LLVMMatchType<0>],
26 []>;
27
28 // These are the existing names, which are currently official, but expected
29 // to be deprecated in the future. They also lack the immediate field.
1830 def int_wasm_current_memory : Intrinsic<[llvm_anyint_ty], [], [IntrReadMem]>;
1931 def int_wasm_grow_memory : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>], []>;
2032
522522 let Defs = [ARGUMENTS] in {
523523
524524 // Current memory size.
525 def MEM_SIZE_I32 : I<(outs I32:$dst), (ins i32imm:$flags),
526 [(set I32:$dst, (int_wasm_mem_size (i32 imm:$flags)))],
527 "mem.size\t$dst, $flags", 0x3f>,
528 Requires<[HasAddr32]>;
525529 def CURRENT_MEMORY_I32 : I<(outs I32:$dst), (ins i32imm:$flags),
526530 [],
527531 "current_memory\t$dst", 0x3f>,
528532 Requires<[HasAddr32]>;
529533
530534 // Grow memory.
535 def MEM_GROW_I32 : I<(outs I32:$dst), (ins i32imm:$flags, I32:$delta),
536 [(set I32:$dst,
537 (int_wasm_mem_grow (i32 imm:$flags), I32:$delta))],
538 "mem.grow\t$dst, $flags, $delta", 0x3f>,
539 Requires<[HasAddr32]>;
531540 def GROW_MEMORY_I32 : I<(outs I32:$dst), (ins i32imm:$flags, I32:$delta),
532541 [],
533542 "grow_memory\t$dst, $delta", 0x40>,
44 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
55 target triple = "wasm32-unknown-unknown-wasm"
66
7 declare i32 @llvm.wasm.mem.size.i32(i32) nounwind readonly
8 declare i32 @llvm.wasm.mem.grow.i32(i32, i32) nounwind
79 declare i32 @llvm.wasm.current.memory.i32() nounwind readonly
810 declare i32 @llvm.wasm.grow.memory.i32(i32) nounwind
11
12 ; CHECK-LABEL: mem_size:
13 ; CHECK-NEXT: .result i32{{$}}
14 ; CHECK-NEXT: mem.size $push0=, 0{{$}}
15 ; CHECK-NEXT: return $pop0{{$}}
16 define i32 @mem_size() {
17 %a = call i32 @llvm.wasm.mem.size.i32(i32 0)
18 ret i32 %a
19 }
20
21 ; CHECK-LABEL: mem_grow:
22 ; CHECK-NEXT: .param i32{{$}}
23 ; CHECK-NEXT: .result i32{{$}}
24 ; CHECK: mem.grow $push0=, 0, $0{{$}}
25 ; CHECK-NEXT: return $pop0{{$}}
26 define i32 @mem_grow(i32 %n) {
27 %a = call i32 @llvm.wasm.mem.grow.i32(i32 0, i32 %n)
28 ret i32 %a
29 }
930
1031 ; CHECK-LABEL: current_memory:
1132 ; CHECK-NEXT: .result i32{{$}}