diff options
author | Alon Zakai <azakai@google.com> | 2024-10-16 11:08:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-16 11:08:53 -0700 |
commit | d13c262dc8dc2239e6ed267eb3c0567eac378568 (patch) | |
tree | f4eea8e77ea698f38ca8b434950daad17ffd4369 | |
parent | 33abf08976264700e6ab5815a73537a5fb6b7dcf (diff) | |
download | binaryen-d13c262dc8dc2239e6ed267eb3c0567eac378568.tar.gz binaryen-d13c262dc8dc2239e6ed267eb3c0567eac378568.tar.bz2 binaryen-d13c262dc8dc2239e6ed267eb3c0567eac378568.zip |
[NFC] Add validation checks in OptUtils::optimizeAfterInlining (#7009)
This can help find errors in the middle of passes like Inlining, that do
multiple cycles and include optimizations in the middle.
We do this in BINARYEN_PASS_DEBUG >= 2 to avoid slowing down the
timing reports in 1.
-rw-r--r-- | src/passes/opt-utils.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/passes/opt-utils.h b/src/passes/opt-utils.h index 69552f717..69f055fd3 100644 --- a/src/passes/opt-utils.h +++ b/src/passes/opt-utils.h @@ -20,11 +20,12 @@ #include <functional> #include <unordered_set> -#include <ir/element-utils.h> -#include <ir/module-utils.h> -#include <pass.h> -#include <passes/pass-utils.h> -#include <wasm.h> +#include "ir/element-utils.h" +#include "ir/module-utils.h" +#include "pass.h" +#include "passes/pass-utils.h" +#include "wasm-validator.h" +#include "wasm.h" namespace wasm::OptUtils { @@ -42,10 +43,24 @@ inline void addUsefulPassesAfterInlining(PassRunner& runner) { inline void optimizeAfterInlining(const PassUtils::FuncSet& funcs, Module* module, PassRunner* parentRunner) { + // In pass-debug mode, validate before and after these optimizations. This + // helps catch bugs in the middle of passes like inlining and dae. We do this + // at level 2+ and not 1 so that this extra validation is not added to the + // timings that level 1 reports. + if (PassRunner::getPassDebug() >= 2) { + if (!WasmValidator().validate(*module, parentRunner->options)) { + Fatal() << "invalid wasm before optimizeAfterInlining"; + } + } PassUtils::FilteredPassRunner runner(module, funcs, parentRunner->options); runner.setIsNested(true); addUsefulPassesAfterInlining(runner); runner.run(); + if (PassRunner::getPassDebug() >= 2) { + if (!WasmValidator().validate(*module, parentRunner->options)) { + Fatal() << "invalid wasm after optimizeAfterInlining"; + } + } } struct FunctionRefReplacer |