diff options
author | Alon Zakai <alonzakai@gmail.com> | 2017-02-23 12:59:42 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 12:59:42 -0800 |
commit | db6f2bf0fa8cd1913bd498ca17641e2bda44a263 (patch) | |
tree | 24f725c2bfedd82fbd07d31204a9b5cafe9091bc | |
parent | 7c183a6ec06fa32098c9eb61993f857d821e0afe (diff) | |
download | binaryen-db6f2bf0fa8cd1913bd498ca17641e2bda44a263.tar.gz binaryen-db6f2bf0fa8cd1913bd498ca17641e2bda44a263.tar.bz2 binaryen-db6f2bf0fa8cd1913bd498ca17641e2bda44a263.zip |
fix BINARYEN_PASS_DEBUG option (#908)
* fix BINARYEN_PASS_DEBUG option
* Add isNested property to passRunner
-rw-r--r-- | src/pass.h | 10 | ||||
-rw-r--r-- | src/passes/DuplicateFunctionElimination.cpp | 2 | ||||
-rw-r--r-- | src/passes/Inlining.cpp | 2 | ||||
-rw-r--r-- | src/passes/LegalizeJSInterface.cpp | 1 | ||||
-rw-r--r-- | src/passes/pass.cpp | 14 | ||||
-rw-r--r-- | src/wasm-printing.h | 1 |
6 files changed, 25 insertions, 5 deletions
diff --git a/src/pass.h b/src/pass.h index 1fcd88e0c..faf674c49 100644 --- a/src/pass.h +++ b/src/pass.h @@ -123,6 +123,16 @@ struct PassRunner { ~PassRunner(); + // When running a pass runner within another pass runner, this + // flag should be set. This influences how pass debugging works, + // and may influence other things in the future too. + void setIsNested(bool nested) { + isNested = nested; + } + +protected: + bool isNested = false; + private: void doAdd(Pass* pass); diff --git a/src/passes/DuplicateFunctionElimination.cpp b/src/passes/DuplicateFunctionElimination.cpp index 05eaadfe5..5d55c7318 100644 --- a/src/passes/DuplicateFunctionElimination.cpp +++ b/src/passes/DuplicateFunctionElimination.cpp @@ -89,6 +89,7 @@ struct DuplicateFunctionElimination : public Pass { hashes[func.get()] = 0; // ensure an entry for each function - we must not modify the map shape in parallel, just the values } PassRunner hasherRunner(module); + hasherRunner.setIsNested(true); hasherRunner.add<FunctionHasher>(&hashes); hasherRunner.run(); // Find hash-equal groups @@ -131,6 +132,7 @@ struct DuplicateFunctionElimination : public Pass { module->updateMaps(); // replace direct calls PassRunner replacerRunner(module); + replacerRunner.setIsNested(true); replacerRunner.add<FunctionReplacer>(&replacements); replacerRunner.run(); // replace in table diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 943bbc500..c352a704a 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -145,6 +145,7 @@ struct Inlining : public Pass { } { PassRunner runner(module); + runner.setIsNested(true); runner.add<FunctionUseCounter>(&uses); runner.run(); } @@ -172,6 +173,7 @@ struct Inlining : public Pass { // find and plan inlinings { PassRunner runner(module); + runner.setIsNested(true); runner.add<Planner>(&state); runner.run(); } diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index f2ecb479f..4bb25361f 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -94,6 +94,7 @@ struct LegalizeJSInterface : public Pass { }; PassRunner passRunner(module); + passRunner.setIsNested(true); passRunner.add<FixImports>(&illegalToLegal); passRunner.run(); } diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index df98590c5..081164d90 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -142,7 +142,12 @@ void PassRunner::addDefaultGlobalOptimizationPasses() { } void PassRunner::run() { - if (options.debug) { + // BINARYEN_PASS_DEBUG is a convenient commandline way to log out the toplevel passes, their times, + // and validate between each pass. + // (we don't recurse pass debug into sub-passes, as it doesn't help anyhow and + // also is bad for e.g. printing which is a pass) + static const int passDebug = getenv("BINARYEN_PASS_DEBUG") ? atoi(getenv("BINARYEN_PASS_DEBUG")) : 0; + if (!isNested && (options.debug || passDebug)) { // for debug logging purposes, run each pass in full before running the other auto totalTime = std::chrono::duration<double>(0); size_t padding = 0; @@ -150,11 +155,10 @@ void PassRunner::run() { for (auto pass : passes) { padding = std::max(padding, pass->name.size()); } - bool passDebug = getenv("BINARYEN_PASS_DEBUG") && getenv("BINARYEN_PASS_DEBUG")[0] != '0'; for (auto* pass : passes) { // ignoring the time, save a printout of the module before, in case this pass breaks it, so we can print the before and after std::stringstream moduleBefore; - if (passDebug) { + if (passDebug == 2) { WasmPrinter::printModule(wasm, moduleBefore); } // prepare to run @@ -178,10 +182,10 @@ void PassRunner::run() { // validate, ignoring the time std::cerr << "[PassRunner] (validating)\n"; if (!WasmValidator().validate(*wasm, false, options.validateGlobally)) { - if (passDebug) { + if (passDebug >= 2) { std::cerr << "Last pass (" << pass->name << ") broke validation. Here is the module before: \n" << moduleBefore.str() << "\n"; } else { - std::cerr << "Last pass (" << pass->name << ") broke validation. Run with BINARYEN_PASS_DEBUG=1 in the env to see the earlier state\n"; + std::cerr << "Last pass (" << pass->name << ") broke validation. Run with BINARYEN_PASS_DEBUG=2 in the env to see the earlier state (FIXME: this is broken, need to prevent recursion of the print pass\n"; } abort(); } diff --git a/src/wasm-printing.h b/src/wasm-printing.h index 830f2dda2..a445866d8 100644 --- a/src/wasm-printing.h +++ b/src/wasm-printing.h @@ -27,6 +27,7 @@ namespace wasm { struct WasmPrinter { static std::ostream& printModule(Module* module, std::ostream& o) { PassRunner passRunner(module); + passRunner.setIsNested(true); passRunner.add<Printer>(&o); passRunner.run(); return o; |