summaryrefslogtreecommitdiff
path: root/test/lit/wasm-split/instrument-in-secondary-memory.wast
diff options
context:
space:
mode:
Diffstat (limited to 'test/lit/wasm-split/instrument-in-secondary-memory.wast')
-rw-r--r--test/lit/wasm-split/instrument-in-secondary-memory.wast92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/lit/wasm-split/instrument-in-secondary-memory.wast b/test/lit/wasm-split/instrument-in-secondary-memory.wast
new file mode 100644
index 000000000..3e012293b
--- /dev/null
+++ b/test/lit/wasm-split/instrument-in-secondary-memory.wast
@@ -0,0 +1,92 @@
+;; RUN: wasm-split %s --instrument --in-secondary-memory -all -S -o - | filecheck %s
+
+;; Check that the output round trips and validates as well
+;; RUN: wasm-split %s --instrument --in-secondary-memory -all -g -o %t.wasm
+;; RUN: wasm-opt -all %t.wasm -S -o -
+
+(module
+ (import "env" "foo" (func $foo))
+ (export "bar" (func $bar))
+ (memory $0 1 1)
+ (func $bar
+ (call $foo)
+ )
+ (func $baz (param i32) (result i32)
+ (local.get 0)
+ )
+)
+
+;; Check that a memory import has been added for secondary memory
+;; CHECK: (import "env" "profile-data" (memory $profile-data (shared 1 1)))
+
+;; And the profiling function exported
+;; CHECK: (export "__write_profile" (func $__write_profile))
+
+;; And main memory has been exported
+;; CHECK: (export "profile-memory" (memory $0))
+
+;; Check that the function instrumentation is correct
+
+;; CHECK: (func $bar
+;; CHECK-NEXT: (i32.atomic.store8 $profile-data
+;; CHECK-NEXT: (i32.const 0)
+;; CHECK-NEXT: (i32.const 1)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (call $foo)
+;; CHECK-NEXT: )
+
+;; CHECK-NEXT: (func $baz (param $0 i32) (result i32)
+;; CHECK-NEXT: (i32.atomic.store8 $profile-data offset=1
+;; CHECK-NEXT: (i32.const 0)
+;; CHECK-NEXT: (i32.const 1)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (local.get $0)
+;; CHECK-NEXT: )
+
+;; Check that the profiling function is correct.
+
+;; CHECK: (func $__write_profile (param $addr i32) (param $size i32) (result i32)
+;; CHECK-NEXT: (local $funcIdx i32)
+;; CHECK-NEXT: (if
+;; CHECK-NEXT: (i32.ge_u
+;; CHECK-NEXT: (local.get $size)
+;; CHECK-NEXT: (i32.const 16)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (block
+;; CHECK-NEXT: (i64.store $0 align=1
+;; CHECK-NEXT: (local.get $addr)
+;; CHECK-NEXT: (i64.const {{.*}})
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (block $outer
+;; CHECK-NEXT: (loop $l
+;; CHECK-NEXT: (br_if $outer
+;; CHECK-NEXT: (i32.eq
+;; CHECK-NEXT: (local.get $funcIdx)
+;; CHECK-NEXT: (i32.const 2)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (i32.store $0 offset=8
+;; CHECK-NEXT: (i32.add
+;; CHECK-NEXT: (local.get $addr)
+;; CHECK-NEXT: (i32.mul
+;; CHECK-NEXT: (local.get $funcIdx)
+;; CHECK-NEXT: (i32.const 4)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (i32.atomic.load8_u $profile-data
+;; CHECK-NEXT: (local.get $funcIdx)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (local.set $funcIdx
+;; CHECK-NEXT: (i32.add
+;; CHECK-NEXT: (local.get $funcIdx)
+;; CHECK-NEXT: (i32.const 1)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (br $l)
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: )
+;; CHECK-NEXT: (i32.const 16)
+;; CHECK-NEXT: )