From 1a483a28bb7c58349d668ad3f54ef0e9f9607cad Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 28 Feb 2019 10:22:41 -0800 Subject: Optimize normally with debug info (#1927) * optimize normally with debug info - some of it may be removed, but that's the price of higher optimization levels, and by optimizing normally in profiling and -g2 etc. builds they are more comparable to normal ones, yielding better data * copy debug locations automatically in replaceCurrent in wasm-traversal, so optimization passes at least by default will preserve debuggability --- src/passes/pass.cpp | 18 +++++++----------- src/wasm-traversal.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 4b14186fb..58a5f2f0a 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -156,9 +156,7 @@ void PassRunner::addDefaultFunctionOptimizationPasses() { add("flatten"); add("local-cse"); } - if (!options.debugInfo) { // debug info must be preserved, do not dce it - add("dce"); - } + add("dce"); add("remove-unused-brs"); add("remove-unused-names"); add("optimize-instructions"); @@ -215,14 +213,12 @@ void PassRunner::addDefaultGlobalOptimizationPrePasses() { void PassRunner::addDefaultGlobalOptimizationPostPasses() { // inlining/dae+optimizing can remove debug annotations - if (!options.debugInfo) { - if (options.optimizeLevel >= 2 || options.shrinkLevel >= 1) { - add("dae-optimizing"); - } - // inline when working hard, and when not preserving debug info - if (options.optimizeLevel >= 2 || options.shrinkLevel >= 2) { - add("inlining-optimizing"); - } + if (options.optimizeLevel >= 2 || options.shrinkLevel >= 1) { + add("dae-optimizing"); + } + // inline when working hard, and when not preserving debug info + if (options.optimizeLevel >= 2 || options.shrinkLevel >= 2) { + add("inlining-optimizing"); } add("duplicate-function-elimination"); // optimizations show more functions as duplicate add("remove-unused-module-elements"); diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h index 5bd316d89..541490418 100644 --- a/src/wasm-traversal.h +++ b/src/wasm-traversal.h @@ -302,6 +302,19 @@ struct Walker : public VisitorType { // just one visit*() method is called by the traversal; if you replace a node, // and you want to process the output, you must do that explicitly). Expression* replaceCurrent(Expression* expression) { + // Copy debug info, if present. + if (currFunction) { + auto& debugLocations = currFunction->debugLocations; + if (!debugLocations.empty()) { + auto* curr = getCurrent(); + auto iter = debugLocations.find(curr); + if (iter != debugLocations.end()) { + auto location = iter->second; + debugLocations.erase(iter); + debugLocations[expression] = location; + } + } + } return *replacep = expression; } -- cgit v1.2.3