summaryrefslogtreecommitdiff
path: root/src/passes
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-09-02 11:54:54 -0700
committerGitHub <noreply@github.com>2020-09-02 11:54:54 -0700
commit7438b6cbcb9b194db59c0e5c497208ce57c964a9 (patch)
tree3a2fcff10e3cb8c4ff3738000c1adba25f42ba2a /src/passes
parent89020a0b4074d18c3fedd0aec2b2aa900c538a1d (diff)
downloadbinaryen-7438b6cbcb9b194db59c0e5c497208ce57c964a9.tar.gz
binaryen-7438b6cbcb9b194db59c0e5c497208ce57c964a9.tar.bz2
binaryen-7438b6cbcb9b194db59c0e5c497208ce57c964a9.zip
MinifyImportsAndExports: Minify the memory and table as well. (#3089)
We were careful not to minify those, as well as the stack pointer, which makes sense in dynamic linking. But we don't run this pass in dynamic linking anyhow - we need the proper names of symbols in that case. So this was not helping us, and was just a leftover from an early state. This both a useful optimization and also important for #3043, as the wasm backend exports the table as __indirect_function_table - a much longer name than emscripten's table. So just changing to that would regress code size on small projects. Once we land this, the name won't matter as it will be minified anyhow.
Diffstat (limited to 'src/passes')
-rw-r--r--src/passes/MinifyImportsAndExports.cpp20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/passes/MinifyImportsAndExports.cpp b/src/passes/MinifyImportsAndExports.cpp
index 3a4dd8f80..ca8426e8a 100644
--- a/src/passes/MinifyImportsAndExports.cpp
+++ b/src/passes/MinifyImportsAndExports.cpp
@@ -148,10 +148,6 @@ private:
std::map<Name, Name> oldToNew;
std::map<Name, Name> newToOld;
auto process = [&](Name& name) {
- // do not minifiy special imports, they must always exist
- if (name == MEMORY_BASE || name == TABLE_BASE || name == STACK_POINTER) {
- return;
- }
auto iter = oldToNew.find(name);
if (iter == oldToNew.end()) {
auto newName = names.getName(soFar++);
@@ -162,7 +158,7 @@ private:
name = iter->second;
}
};
- auto processImport = [&](Importable* curr) {
+ ModuleUtils::iterImports(*module, [&](Importable* curr) {
// Minify all import base names if we are importing modules (which means
// we will minify all modules names, so we are not being careful).
// Otherwise, assume we just want to minify "normal" imports like env
@@ -171,10 +167,7 @@ private:
curr->module.startsWith("wasi_")) {
process(curr->base);
}
- };
- ModuleUtils::iterImportedGlobals(*module, processImport);
- ModuleUtils::iterImportedFunctions(*module, processImport);
- ModuleUtils::iterImportedEvents(*module, processImport);
+ });
if (minifyExports) {
// Minify the exported names.
@@ -201,18 +194,13 @@ private:
#ifndef NDEBUG
std::set<Name> seenImports;
#endif
- auto processImport = [&](Importable* curr) {
+ ModuleUtils::iterImports(*module, [&](Importable* curr) {
curr->module = SINGLETON_MODULE_NAME;
#ifndef NDEBUG
assert(seenImports.count(curr->base) == 0);
seenImports.insert(curr->base);
#endif
- };
- ModuleUtils::iterImportedGlobals(*module, processImport);
- ModuleUtils::iterImportedFunctions(*module, processImport);
- ModuleUtils::iterImportedEvents(*module, processImport);
- ModuleUtils::iterImportedMemories(*module, processImport);
- ModuleUtils::iterImportedTables(*module, processImport);
+ });
}
};