[llvm] r249171 - [WebAssembly] Add a memory_size intrinsic.

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 12:21:16 PDT 2015


Author: djg
Date: Fri Oct  2 14:21:15 2015
New Revision: 249171

URL: http://llvm.org/viewvc/llvm-project?rev=249171&view=rev
Log:
[WebAssembly] Add a memory_size intrinsic.

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

Modified: llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td?rev=249171&r1=249170&r2=249171&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td (original)
+++ llvm/trunk/include/llvm/IR/IntrinsicsWebAssembly.td Fri Oct  2 14:21:15 2015
@@ -15,5 +15,6 @@
 let TargetPrefix = "wasm" in {  // All intrinsics start with "llvm.wasm.".
 
 def int_wasm_page_size : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
+def int_wasm_memory_size : Intrinsic<[llvm_anyint_ty], [], [IntrNoMem]>;
 
 }

Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td?rev=249171&r1=249170&r2=249171&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrMemory.td Fri Oct  2 14:21:15 2015
@@ -98,3 +98,11 @@ def page_size_I32 : I<(outs I32:$dst), (
 def page_size_I64 : I<(outs I64:$dst), (ins),
                       [(set I64:$dst, (int_wasm_page_size))]>,
                     Requires<[HasAddr64]>;
+
+// Memory size.
+def memory_size_I32 : I<(outs I32:$dst), (ins),
+                        [(set I32:$dst, (int_wasm_memory_size))]>,
+                      Requires<[HasAddr32]>;
+def memory_size_I64 : I<(outs I64:$dst), (ins),
+                        [(set I64:$dst, (int_wasm_memory_size))]>,
+                      Requires<[HasAddr64]>;

Modified: llvm/trunk/test/CodeGen/WebAssembly/memory-addr32.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/memory-addr32.ll?rev=249171&r1=249170&r2=249171&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/memory-addr32.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/memory-addr32.ll Fri Oct  2 14:21:15 2015
@@ -6,6 +6,7 @@ target datalayout = "e-p:32:32-i64:64-n3
 target triple = "wasm32-unknown-unknown"
 
 declare i32 @llvm.wasm.page.size.i32() nounwind readnone
+declare i32 @llvm.wasm.memory.size.i32() nounwind readnone
 
 ; CHECK-LABEL: (func $page_size
 ; CHECK-NEXT: (result i32)
@@ -15,3 +16,12 @@ define i32 @page_size() {
   %a = call i32 @llvm.wasm.page.size.i32()
   ret i32 %a
 }
+
+; CHECK-LABEL: (func $memory_size
+; CHECK-NEXT: (result i32)
+; CHECK-NEXT: (setlocal @0 (memory_size))
+; CHECK-NEXT: (return @0)
+define i32 @memory_size() {
+  %a = call i32 @llvm.wasm.memory.size.i32()
+  ret i32 %a
+}

Modified: llvm/trunk/test/CodeGen/WebAssembly/memory-addr64.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/WebAssembly/memory-addr64.ll?rev=249171&r1=249170&r2=249171&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/WebAssembly/memory-addr64.ll (original)
+++ llvm/trunk/test/CodeGen/WebAssembly/memory-addr64.ll Fri Oct  2 14:21:15 2015
@@ -6,6 +6,7 @@ target datalayout = "e-p:64:64-i64:64-n3
 target triple = "wasm64-unknown-unknown"
 
 declare i64 @llvm.wasm.page.size.i64() nounwind readnone
+declare i64 @llvm.wasm.memory.size.i64() nounwind readnone
 
 ; CHECK-LABEL: (func $page_size
 ; CHECK-NEXT: (result i64)
@@ -15,3 +16,12 @@ define i64 @page_size() {
   %a = call i64 @llvm.wasm.page.size.i64()
   ret i64 %a
 }
+
+; CHECK-LABEL: (func $memory_size
+; CHECK-NEXT: (result i64)
+; CHECK-NEXT: (setlocal @0 (memory_size))
+; CHECK-NEXT: (return @0)
+define i64 @memory_size() {
+  %a = call i64 @llvm.wasm.memory.size.i64()
+  ret i64 %a
+}




More information about the llvm-commits mailing list