summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-metadce.cpp45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp
index e5e7d8706..d81054d32 100644
--- a/src/tools/wasm-metadce.cpp
+++ b/src/tools/wasm-metadce.cpp
@@ -165,12 +165,7 @@ struct MetaDCEGraph {
// we can also link the export to the thing being exported
auto& node = nodes[exportToDCENode[exp->name]];
if (exp->kind == ExternalKind::Function) {
- if (!wasm.getFunction(exp->value)->imported()) {
- node.reaches.push_back(functionToDCENode[exp->value]);
- } else {
- node.reaches.push_back(
- importIdToDCENode[getFunctionImportId(exp->value)]);
- }
+ node.reaches.push_back(getFunctionDCEName(exp->value));
} else if (exp->kind == ExternalKind::Global) {
if (!wasm.getGlobal(exp->value)->imported()) {
node.reaches.push_back(globalToDCENode[exp->value]);
@@ -196,15 +191,9 @@ struct MetaDCEGraph {
void visitGlobalGet(GlobalGet* curr) { handleGlobal(curr->name); }
void visitGlobalSet(GlobalSet* curr) { handleGlobal(curr->name); }
void visitRefFunc(RefFunc* curr) {
- Name dceName;
- if (!getModule()->getFunction(curr->func)->imported()) {
- dceName = parent->functionToDCENode[curr->func];
- } else {
- dceName =
- parent->importIdToDCENode[parent->getFunctionImportId(curr->func)];
- }
assert(!parentDceName.isNull());
- parent->nodes[parentDceName].reaches.push_back(dceName);
+ parent->nodes[parentDceName].reaches.push_back(
+ parent->getFunctionDCEName(curr->func));
}
private:
@@ -239,13 +228,8 @@ struct MetaDCEGraph {
// TODO: currently, all functions in the table are roots, but we
// should add an option to refine that
ElementUtils::iterElementSegmentFunctionNames(
- segment, [&](Name name, Index) {
- if (!wasm.getFunction(name)->imported()) {
- roots.insert(functionToDCENode[name]);
- } else {
- roots.insert(importIdToDCENode[getFunctionImportId(name)]);
- }
- });
+ segment,
+ [&](Name name, Index) { roots.insert(getFunctionDCEName(name)); });
rooter.walk(segment->offset);
});
ModuleUtils::iterActiveDataSegments(
@@ -276,15 +260,8 @@ struct MetaDCEGraph {
MetaDCEGraph* parent;
void handleFunction(Name name) {
- if (!getModule()->getFunction(name)->imported()) {
- parent->nodes[parent->functionToDCENode[getFunction()->name]]
- .reaches.push_back(parent->functionToDCENode[name]);
- } else {
- assert(parent->functionToDCENode.count(getFunction()->name) > 0);
- parent->nodes[parent->functionToDCENode[getFunction()->name]]
- .reaches.push_back(
- parent->importIdToDCENode[parent->getFunctionImportId(name)]);
- }
+ parent->nodes[parent->functionToDCENode[getFunction()->name]]
+ .reaches.push_back(parent->getFunctionDCEName(name));
}
void handleGlobal(Name name) {
@@ -319,6 +296,14 @@ struct MetaDCEGraph {
Scanner(this).run(&runner, &wasm);
}
+ Name getFunctionDCEName(Name name) {
+ if (!wasm.getFunction(name)->imported()) {
+ return functionToDCENode[name];
+ } else {
+ return importIdToDCENode[getFunctionImportId(name)];
+ }
+ }
+
private:
// gets a unique name for the graph
Name getName(std::string prefix1, std::string prefix2) {