summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-10-16 12:35:27 -0700
committerGitHub <noreply@github.com>2020-10-16 12:35:27 -0700
commit8cdb2eaa7cb3f4c693239e32fe4d4c7f3d75e005 (patch)
tree630bac16f5cbd01a9c8ccbade245ca5671042fd5 /src
parent98dcde79d27eb1df2db47120e0102497bf385320 (diff)
downloadbinaryen-8cdb2eaa7cb3f4c693239e32fe4d4c7f3d75e005.tar.gz
binaryen-8cdb2eaa7cb3f4c693239e32fe4d4c7f3d75e005.tar.bz2
binaryen-8cdb2eaa7cb3f4c693239e32fe4d4c7f3d75e005.zip
Add unmodifiedImportedMemory pass option (#3246)
When set, we can assume an imported memory was not modified before us. That lets us assume it is all zeros and so we can optimize out zeros from memory segments. This does not actually do anything with the flag, just adds it. This is to avoid a rolling problem. Next emscripten can emit it without erroring, and then we can start to use it.
Diffstat (limited to 'src')
-rw-r--r--src/pass.h9
-rw-r--r--src/tools/optimization-options.h9
2 files changed, 17 insertions, 1 deletions
diff --git a/src/pass.h b/src/pass.h
index 4f9cd1b68..45dd549d1 100644
--- a/src/pass.h
+++ b/src/pass.h
@@ -107,6 +107,15 @@ struct PassOptions {
// forth (which IEEE floats do not, strictly speaking). This is inspired by
// gcc/clang's -ffast-math flag.
bool fastMath = false;
+ // Whether to assume that an imported memory has not been modified. Without
+ // this, we can do fewer optimizations on memory segments, because if memory
+ // *was* modified then the wasm's segments may trample those previous
+ // modifications. If memory was not modified, we can assume it starts as zero,
+ // which allows us to remove zeros from wasm's segments.
+ // (This is not a problem if the memory is *not* imported, since then wasm
+ // creates it and we know it is all zeros right before the active segments are
+ // applied.)
+ bool unmodifiedImportedMemory = false;
// Whether to try to preserve debug info through, which are special calls.
bool debugInfo = false;
// Arbitrary string arguments from the commandline, which we forward to
diff --git a/src/tools/optimization-options.h b/src/tools/optimization-options.h
index 5b6a643e6..f89dab347 100644
--- a/src/tools/optimization-options.h
+++ b/src/tools/optimization-options.h
@@ -193,7 +193,14 @@ struct OptimizationOptions : public ToolOptions {
"-ffm",
"Optimize floats without handling corner cases of NaNs and rounding",
Options::Arguments::Zero,
- [this](Options*, const std::string&) { passOptions.fastMath = true; });
+ [this](Options*, const std::string&) { passOptions.fastMath = true; })
+ .add("--unmodified-imported-mem",
+ "-uim",
+ "Assume that an imported memory will not have been modified",
+ Options::Arguments::Zero,
+ [this](Options*, const std::string&) {
+ passOptions.unmodifiedImportedMemory = true;
+ });
// add passes in registry
for (const auto& p : PassRegistry::get()->getRegisteredNames()) {
(*this).add(