From f6b5c1e5c1c0de26fd078d336782508dd0186820 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 3 Jun 2016 14:55:29 -0700 Subject: move function parallelism to pass and pass runner, which allows more efficient parallel execution (#564) --- src/passes/DuplicateFunctionElimination.cpp | 40 ++++++++++++----------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/passes/DuplicateFunctionElimination.cpp') diff --git a/src/passes/DuplicateFunctionElimination.cpp b/src/passes/DuplicateFunctionElimination.cpp index c33baedd4..715df0815 100644 --- a/src/passes/DuplicateFunctionElimination.cpp +++ b/src/passes/DuplicateFunctionElimination.cpp @@ -26,17 +26,13 @@ namespace wasm { -struct FunctionHasher : public PostWalker> { - bool isFunctionParallel() { return true; } +struct FunctionHasher : public WalkerPass>> { + bool isFunctionParallel() override { return true; } - FunctionHasher* create() override { - auto* ret = new FunctionHasher; - ret->setOutput(output); - return ret; - } + FunctionHasher(std::map* output) : output(output) {} - void setOutput(std::map* output_) { - output = output_; + FunctionHasher* create() override { + return new FunctionHasher(output); } void doWalkFunction(Function* func) { @@ -63,17 +59,13 @@ private: }; }; -struct FunctionReplacer : public PostWalker> { - bool isFunctionParallel() { return true; } +struct FunctionReplacer : public WalkerPass>> { + bool isFunctionParallel() override { return true; } - FunctionReplacer* create() override { - auto* ret = new FunctionReplacer; - ret->setReplacements(replacements); - return ret; - } + FunctionReplacer(std::map* replacements) : replacements(replacements) {} - void setReplacements(std::map* replacements_) { - replacements = replacements_; + FunctionReplacer* create() override { + return new FunctionReplacer(replacements); } void visitCall(Call* curr) { @@ -95,9 +87,9 @@ struct DuplicateFunctionElimination : public Pass { for (auto& func : module->functions) { hashes[func.get()] = 0; // ensure an entry for each function - we must not modify the map shape in parallel, just the values } - FunctionHasher hasher; - hasher.setOutput(&hashes); - hasher.walkModule(module); + PassRunner hasherRunner(module); + hasherRunner.add(&hashes); + hasherRunner.run(); // Find hash-equal groups std::map> hashGroups; for (auto& func : module->functions) { @@ -127,9 +119,9 @@ struct DuplicateFunctionElimination : public Pass { }), v.end()); module->updateFunctionsMap(); // replace direct calls - FunctionReplacer replacer; - replacer.setReplacements(&replacements); - replacer.walkModule(module); + PassRunner replacerRunner(module); + replacerRunner.add(&replacements); + replacerRunner.run(); // replace in table for (auto& name : module->table.names) { auto iter = replacements.find(name); -- cgit v1.2.3