diff options
author | Alon Zakai <alonzakai@gmail.com> | 2019-02-28 10:22:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-28 10:22:41 -0800 |
commit | 1a483a28bb7c58349d668ad3f54ef0e9f9607cad (patch) | |
tree | cfdedd92f9fa085656052ed9dfedcf99d6472ff0 /src | |
parent | 87a6512c5ba86bd6a7b7bafe778c89756de037f2 (diff) | |
download | binaryen-1a483a28bb7c58349d668ad3f54ef0e9f9607cad.tar.gz binaryen-1a483a28bb7c58349d668ad3f54ef0e9f9607cad.tar.bz2 binaryen-1a483a28bb7c58349d668ad3f54ef0e9f9607cad.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/pass.cpp | 18 | ||||
-rw-r--r-- | src/wasm-traversal.h | 13 |
2 files changed, 20 insertions, 11 deletions
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; } |