diff options
-rw-r--r-- | src/tools/wasm-opt.cpp | 39 | ||||
-rw-r--r-- | test/lit/help/wasm-opt.test | 9 | ||||
-rw-r--r-- | test/lit/passes/experimental-new_eh.wast | 28 |
3 files changed, 74 insertions, 2 deletions
diff --git a/src/tools/wasm-opt.cpp b/src/tools/wasm-opt.cpp index 5bbca1ea6..0b0ea2cd4 100644 --- a/src/tools/wasm-opt.cpp +++ b/src/tools/wasm-opt.cpp @@ -92,6 +92,7 @@ int main(int argc, const char* argv[]) { std::string inputSourceMapFilename; std::string outputSourceMapFilename; std::string outputSourceMapUrl; + bool experimentalNewEH = false; const std::string WasmOptOption = "wasm-opt options"; @@ -240,7 +241,18 @@ int main(int argc, const char* argv[]) { Options::Arguments::One, [](Options* o, const std::string& argument) { o->extra["infile"] = argument; - }); + }) + .add("--experimental-new-eh", + "", + "After running all requested transformations / optimizations, " + "translate the instruction to use the new EH instructions at the end. " + "Depending on the optimization level specified, this may do some more " + "post-translation optimizations.", + WasmOptOption, + Options::Arguments::Zero, + [&experimentalNewEH](Options*, const std::string&) { + experimentalNewEH = true; + }); options.parse(argc, argv); Module wasm; @@ -360,8 +372,11 @@ int main(int argc, const char* argv[]) { std::cout << "[extra-fuzz-command first output:]\n" << firstOutput << '\n'; } + bool translateToNewEH = + wasm.features.hasExceptionHandling() && experimentalNewEH; + if (!options.runningPasses()) { - if (!options.quiet) { + if (!options.quiet && !translateToNewEH) { std::cerr << "warning: no passes specified, not doing any work\n"; } } else { @@ -398,6 +413,26 @@ int main(int argc, const char* argv[]) { } } + if (translateToNewEH) { + BYN_TRACE("translating to new EH instructions...\n"); + PassRunner runner(&wasm, options.passOptions); + runner.add("translate-to-new-eh"); + // Perform Stack IR optimizations here, at the very end of the + // optimization pipeline. + if (options.passOptions.optimizeLevel >= 2 || + options.passOptions.shrinkLevel >= 1) { + runner.addIfNoDWARFIssues("generate-stack-ir"); + runner.addIfNoDWARFIssues("optimize-stack-ir"); + } + runner.run(); + if (options.passOptions.validate) { + bool valid = WasmValidator().validate(wasm, options.passOptions); + if (!valid) { + exitOnInvalidWasm("error after opts"); + } + } + } + if (fuzzExecAfter) { results.check(wasm); } diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index 5a207a1b0..88fc2448a 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -79,6 +79,15 @@ ;; CHECK-NEXT: --new-wat-parser Use the experimental new WAT ;; CHECK-NEXT: parser ;; CHECK-NEXT: +;; CHECK-NEXT: --experimental-new-eh After running all requested +;; CHECK-NEXT: transformations / optimizations, +;; CHECK-NEXT: translate the instruction to use +;; CHECK-NEXT: the new EH instructions at the +;; CHECK-NEXT: end. Depending on the +;; CHECK-NEXT: optimization level specified, +;; CHECK-NEXT: this may do some more +;; CHECK-NEXT: post-translation optimizations. +;; CHECK-NEXT: ;; CHECK-NEXT: ;; CHECK-NEXT: Optimization passes: ;; CHECK-NEXT: -------------------- diff --git a/test/lit/passes/experimental-new_eh.wast b/test/lit/passes/experimental-new_eh.wast new file mode 100644 index 000000000..ee6624676 --- /dev/null +++ b/test/lit/passes/experimental-new_eh.wast @@ -0,0 +1,28 @@ +;; When given alone, --experimental-new-eh just runs --translate-to-new-eh +;; RUN: wasm-opt %s -all --translate-to-new-eh -S -o %a.wasm +;; RUN: wasm-opt %s -all --experimental-new-eh -S -o %b.wasm +;; RUN: diff %a.wasm %b.wasm + +;; When given with other flags, --experimental-new-eh runs the translator after +;; running other passes. If --optimize-level >=3, --experimenal-new-eh also runs +;; StackIR (+ local2stack) optimization. So running '-O --experimental-new-eh' +;; should be the same as running all these passes separately. +;; RUN: wasm-opt %s -all -O --translate-to-new-eh --optimize-level=3 --generate-stack-ir --optimize-stack-ir -o %a.wasm +;; RUN: wasm-opt %s -all -O --experimental-new-eh -o %b.wasm +;; RUN: diff %a.wasm %b.wasm + +(module + (import "env" "foo" (func $foo)) + (start $test) + (func $test + (try $l + (do + (call $foo) + ) + (catch_all + (call $foo) + (rethrow $l) + ) + ) + ) +) |