[WebAssembly] Update to the new names for the memory intrinsics.
authorDan Gohman <dan433584@gmail.com>
Thu, 31 May 2018 22:35:25 +0000 (22:35 +0000)
committerDan Gohman <dan433584@gmail.com>
Thu, 31 May 2018 22:35:25 +0000 (22:35 +0000)
The WebAssembly committee has decided on the names `memory.size` and
`memory.grow` for the memory intrinsics, so update the LLVM intrinsics to
follow those names, keeping both sets of old names in place for
compatibility.

llvm-svn: 333708

llvm/include/llvm/IR/IntrinsicsWebAssembly.td
llvm/lib/Target/WebAssembly/WebAssemblyInstrMemory.td
llvm/test/CodeGen/WebAssembly/memory-addr32.ll

index 70531f6..7afc755 100644 (file)
 let TargetPrefix = "wasm" in {  // All intrinsics start with "llvm.wasm.".
 
 // 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.
+// Note that memory.size is not IntrNoMem because it must be sequenced with
+// respect to memory.grow calls.
+def int_wasm_memory_size : Intrinsic<[llvm_anyint_ty],
+                                     [llvm_i32_ty],
+                                     [IntrReadMem]>;
+def int_wasm_memory_grow : Intrinsic<[llvm_anyint_ty],
+                                     [llvm_i32_ty, LLVMMatchType<0>],
+                                     []>;
+
+// These are the old names.
 def int_wasm_mem_size : Intrinsic<[llvm_anyint_ty],
                                   [llvm_i32_ty],
                                   [IntrReadMem]>;
@@ -26,8 +32,7 @@ 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.
+// These are the old old names. 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>], []>;
 
index 9ef4083..70abc05 100644 (file)
@@ -444,6 +444,10 @@ def : StorePatExternSymOffOnly<i64, truncstorei32, STORE32_I64>;
 let Defs = [ARGUMENTS] in {
 
 // Current memory size.
+def MEMORY_SIZE_I32 : I<(outs I32:$dst), (ins i32imm:$flags),
+                        [(set I32:$dst, (int_wasm_memory_size (i32 imm:$flags)))],
+                        "memory.size\t$dst, $flags", 0x3f>,
+                      Requires<[HasAddr32]>;
 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>,
@@ -454,6 +458,11 @@ def CURRENT_MEMORY_I32 : I<(outs I32:$dst), (ins i32imm:$flags),
                          Requires<[HasAddr32]>;
 
 // Grow memory.
+def MEMORY_GROW_I32 : I<(outs I32:$dst), (ins i32imm:$flags, I32:$delta),
+                        [(set I32:$dst,
+                              (int_wasm_memory_grow (i32 imm:$flags), I32:$delta))],
+                        "memory.grow\t$dst, $flags, $delta", 0x3f>,
+                      Requires<[HasAddr32]>;
 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))],
index c8efa90..ca8c282 100644 (file)
@@ -5,11 +5,32 @@
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"
 
+declare i32 @llvm.wasm.memory.size.i32(i32) nounwind readonly
+declare i32 @llvm.wasm.memory.grow.i32(i32, i32) nounwind
 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: memory_size:
+; CHECK-NEXT: .result i32{{$}}
+; CHECK-NEXT: memory.size $push0=, 0{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i32 @memory_size() {
+  %a = call i32 @llvm.wasm.memory.size.i32(i32 0)
+  ret i32 %a
+}
+
+; CHECK-LABEL: memory_grow:
+; CHECK-NEXT: .param i32{{$}}
+; CHECK-NEXT: .result i32{{$}}
+; CHECK: memory.grow $push0=, 0, $0{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i32 @memory_grow(i32 %n) {
+  %a = call i32 @llvm.wasm.memory.grow.i32(i32 0, i32 %n)
+  ret i32 %a
+}
+
 ; CHECK-LABEL: mem_size:
 ; CHECK-NEXT: .result i32{{$}}
 ; CHECK-NEXT: mem.size $push0=, 0{{$}}