summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-05-09 15:00:13 -0700
committerGitHub <noreply@github.com>2024-05-09 15:00:13 -0700
commit7b2e0190213487b5d2505fe86aa9bbbd30e80fcc (patch)
tree2ae614b27102d83452b0f075612c7558c4493aa6 /test/example
parent006181bb98118c70d36e84e6f1f72b5d60264817 (diff)
downloadbinaryen-7b2e0190213487b5d2505fe86aa9bbbd30e80fcc.tar.gz
binaryen-7b2e0190213487b5d2505fe86aa9bbbd30e80fcc.tar.bz2
binaryen-7b2e0190213487b5d2505fe86aa9bbbd30e80fcc.zip
[StackIR] Run StackIR during binary writing and not as a pass (#6568)
Previously we had passes --generate-stack-ir, --optimize-stack-ir, --print-stack-ir that could be run like any other passes. After generating StackIR it was stashed on the function and invalidated if we modified BinaryenIR. If it wasn't invalidated then it was used during binary writing. This PR switches things so that we optionally generate, optimize, and print StackIR only during binary writing. It also removes all traces of StackIR from wasm.h - after this, StackIR is a feature of binary writing (and printing) logic only. This is almost NFC, but there are some minor noticeable differences: 1. We no longer print has StackIR in the text format when we see it is there. It will not be there during normal printing, as it is only present during binary writing. (but --print-stack-ir still works as before; as mentioned above it runs during writing). 2. --generate/optimize/print-stack-ir change from being passes to being flags that control that behavior instead. As passes, their order on the commandline mattered, while now it does not, and they only "globally" affect things during writing. 3. The C API changes slightly, as there is no need to pass it an option "optimize" to the StackIR APIs. Whether we optimize is handled by --optimize-stack-ir which is set like other optimization flags on the PassOptions object, so we don't need the old option to those C APIs. The main benefit here is simplifying the code, so we don't need to think about StackIR in more places than just binary writing. That may also allow future improvements to our usage of StackIR.
Diffstat (limited to 'test/example')
-rw-r--r--test/example/c-api-kitchen-sink.c7
-rw-r--r--test/example/c-api-kitchen-sink.txt10
-rw-r--r--test/example/relooper-fuzz.txt4
-rw-r--r--test/example/relooper-fuzz1.txt4
4 files changed, 20 insertions, 5 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index e5b614bec..66cf43290 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -2008,12 +2008,17 @@ void test_binaries() {
BinaryenModuleWriteText(module, buffer, 1024);
printf("module s-expr printed (in memory):\n%s\n", buffer);
- // writ the s-expr representation to a pointer which is managed by the
+ // write the s-expr representation to a pointer which is managed by the
// caller
char* text = BinaryenModuleAllocateAndWriteText(module);
printf("module s-expr printed (in memory, caller-owned):\n%s\n", text);
free(text);
+ // write StackIR
+ text = BinaryenModuleAllocateAndWriteStackIR(module);
+ printf("module s-expr printed (StackIR):\n%s\n", text);
+ free(text);
+
BinaryenModuleDispose(module);
}
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 8bdf1ba52..fe784a453 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -3140,6 +3140,16 @@ module s-expr printed (in memory, caller-owned):
)
)
+module s-expr printed (StackIR):
+(module
+ (type $0 (func (param i32 i32) (result i32)))
+ (func $adder (param $0 i32) (param $1 i32) (result i32)
+ local.get $0
+ local.get $1
+ i32.add
+ )
+)
+
(module
(type $0 (func (param i32)))
(type $1 (func))
diff --git a/test/example/relooper-fuzz.txt b/test/example/relooper-fuzz.txt
index 1030fac32..e4c3f6db4 100644
--- a/test/example/relooper-fuzz.txt
+++ b/test/example/relooper-fuzz.txt
@@ -311,7 +311,7 @@
(memory $0 1 1)
(export "mem" (memory $0))
(start $main)
- (func $check (; has Stack IR ;) (result i32)
+ (func $check (result i32)
(if
(i32.eq
(i32.load
@@ -348,7 +348,7 @@
)
)
)
- (func $main (; has Stack IR ;)
+ (func $main
(local $0 i32)
(local $1 i32)
(i32.store
diff --git a/test/example/relooper-fuzz1.txt b/test/example/relooper-fuzz1.txt
index 3cdb12e69..675d51042 100644
--- a/test/example/relooper-fuzz1.txt
+++ b/test/example/relooper-fuzz1.txt
@@ -293,7 +293,7 @@
(memory $0 1 1)
(export "mem" (memory $0))
(start $main)
- (func $check (; has Stack IR ;) (result i32)
+ (func $check (result i32)
(if
(i32.eq
(i32.load
@@ -330,7 +330,7 @@
)
)
)
- (func $main (; has Stack IR ;)
+ (func $main
(local $0 i32)
(i32.store
(i32.const 8)