Skip to content

Commit d13c262

Browse files
authored
[NFC] Add validation checks in OptUtils::optimizeAfterInlining (WebAssembly#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.
1 parent 33abf08 commit d13c262

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/passes/opt-utils.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
#include <functional>
2121
#include <unordered_set>
2222

23-
#include <ir/element-utils.h>
24-
#include <ir/module-utils.h>
25-
#include <pass.h>
26-
#include <passes/pass-utils.h>
27-
#include <wasm.h>
23+
#include "ir/element-utils.h"
24+
#include "ir/module-utils.h"
25+
#include "pass.h"
26+
#include "passes/pass-utils.h"
27+
#include "wasm-validator.h"
28+
#include "wasm.h"
2829

2930
namespace wasm::OptUtils {
3031

@@ -42,10 +43,24 @@ inline void addUsefulPassesAfterInlining(PassRunner& runner) {
4243
inline void optimizeAfterInlining(const PassUtils::FuncSet& funcs,
4344
Module* module,
4445
PassRunner* parentRunner) {
46+
// In pass-debug mode, validate before and after these optimizations. This
47+
// helps catch bugs in the middle of passes like inlining and dae. We do this
48+
// at level 2+ and not 1 so that this extra validation is not added to the
49+
// timings that level 1 reports.
50+
if (PassRunner::getPassDebug() >= 2) {
51+
if (!WasmValidator().validate(*module, parentRunner->options)) {
52+
Fatal() << "invalid wasm before optimizeAfterInlining";
53+
}
54+
}
4555
PassUtils::FilteredPassRunner runner(module, funcs, parentRunner->options);
4656
runner.setIsNested(true);
4757
addUsefulPassesAfterInlining(runner);
4858
runner.run();
59+
if (PassRunner::getPassDebug() >= 2) {
60+
if (!WasmValidator().validate(*module, parentRunner->options)) {
61+
Fatal() << "invalid wasm after optimizeAfterInlining";
62+
}
63+
}
4964
}
5065

5166
struct FunctionRefReplacer

0 commit comments

Comments
 (0)