Skip to content

Commit

Permalink
[WebAssembly] Add a memory_size intrinsic.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249171 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Dan Gohman committed Oct 2, 2015
1 parent 29467e7 commit 7eb00c4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/llvm/IR/IntrinsicsWebAssembly.td
Original file line number Diff line number Diff line change
Expand Up @@ -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]>;

}
8 changes: 8 additions & 0 deletions lib/Target/WebAssembly/WebAssemblyInstrMemory.td
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@ def page_size_I32 : I<(outs I32:$dst), (ins),
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]>;
10 changes: 10 additions & 0 deletions test/CodeGen/WebAssembly/memory-addr32.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target datalayout = "e-p:32:32-i64:64-n32:64-S128"
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)
Expand All @@ -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
}
10 changes: 10 additions & 0 deletions test/CodeGen/WebAssembly/memory-addr64.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target datalayout = "e-p:64:64-i64:64-n32:64-S128"
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)
Expand All @@ -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
}

0 comments on commit 7eb00c4

Please sign in to comment.