Skip to content
Merged
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
13 changes: 13 additions & 0 deletions src/tools/wasm-reduce/wasm-reduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <memory>

#include "ir/branch-utils.h"
#include "ir/eh-utils.h"
#include "ir/iteration.h"
#include "ir/localize.h"
#include "ir/properties.h"
Expand Down Expand Up @@ -1089,9 +1090,13 @@ struct Reducer
struct FunctionReplacer
: public WalkerPass<PostWalker<FunctionReplacer>> {
bool isFunctionParallel() override { return true; }

std::unique_ptr<Pass> create() override {
return std::make_unique<FunctionReplacer>();
};

bool needEHFixups = false;

void visitCall(Call* curr) {
// Replace calls to functions we have removed.
if (getModule()->getFunctionOrNull(curr->target)) {
Expand All @@ -1112,6 +1117,9 @@ struct Reducer
block->list.push_back(replacement);
block->type = originalType;
replaceCurrent(block);
// We added a block around content here, possibly causing us to need
// EH fixups later.
needEHFixups = true;
}
void visitRefFunc(RefFunc* curr) {
// Replace references to functions we have removed.
Expand All @@ -1122,6 +1130,11 @@ struct Reducer
replaceCurrent(
builder.makeBlock({builder.makeUnreachable()}, curr->type));
}
void visitFunction(Function* curr) {
if (needEHFixups) {
EHUtils::handleBlockNestedPops(curr, *getModule());
}
}
};
PassRunner runner(module.get());
runner.add(std::make_unique<FunctionReplacer>());
Expand Down
Loading