Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/ir/module-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ template<typename T> inline void iterDefinedEvents(Module& wasm, T visitor) {
}
}

template<typename T> inline void iterImports(Module& wasm, T visitor) {
iterImportedMemories(wasm, visitor);
iterImportedTables(wasm, visitor);
iterImportedGlobals(wasm, visitor);
iterImportedFunctions(wasm, visitor);
iterImportedEvents(wasm, visitor);
}

// Helper class for performing an operation on all the functions in the module,
// in parallel, with an Info object for each one that can contain results of
// some computation that the operation performs.
Expand Down
20 changes: 4 additions & 16 deletions src/passes/MinifyImportsAndExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ struct MinifyImportsAndExports : public Pass {
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) {

This comment was marked as outdated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the special stack pointer import is relevant only for dynamic linking, but as mentioned earlier, we don't run this pass in that case anyhow.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see

return;
}
auto iter = oldToNew.find(name);
if (iter == oldToNew.end()) {
auto newName = names.getName(soFar++);
Expand All @@ -162,7 +158,7 @@ struct MinifyImportsAndExports : public Pass {
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
Expand All @@ -171,10 +167,7 @@ struct MinifyImportsAndExports : public Pass {
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.
Expand All @@ -201,18 +194,13 @@ struct MinifyImportsAndExports : public Pass {
#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);
});
}
};

Expand Down
22 changes: 12 additions & 10 deletions test/passes/minify-imports-and-exports-and-modules.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
longname1 => a
longname2 => b
longname3 => c
longname4 => d
memory => a
table => b
longname1 => c
longname2 => d
longname3 => e
longname4 => f
(module
(type $none_=>_none (func))
(import "a" "memory" (memory $0 256 256))
(import "a" "table" (table $0 4 funcref))
(import "a" "a" (func $internal1))
(import "a" "b" (func $internal2))
(import "a" "c" (func $internal3))
(import "a" "d" (func $internal4))
(import "a" "a" (memory $0 256 256))
(import "a" "b" (table $0 4 funcref))
(import "a" "c" (func $internal1))
(import "a" "d" (func $internal2))
(import "a" "e" (func $internal3))
(import "a" "f" (func $internal4))
)
Loading