diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-06-03 14:55:29 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-06-03 14:55:29 -0700 |
commit | f6b5c1e5c1c0de26fd078d336782508dd0186820 (patch) | |
tree | 8711b60b41ef1d9e5ded89486073df526a99ada7 /src/passes/DuplicateFunctionElimination.cpp | |
parent | b76818e23eab75876f1981800ef12d55ce2f579b (diff) | |
download | binaryen-f6b5c1e5c1c0de26fd078d336782508dd0186820.tar.gz binaryen-f6b5c1e5c1c0de26fd078d336782508dd0186820.tar.bz2 binaryen-f6b5c1e5c1c0de26fd078d336782508dd0186820.zip |
move function parallelism to pass and pass runner, which allows more efficient parallel execution (#564)
Diffstat (limited to 'src/passes/DuplicateFunctionElimination.cpp')
-rw-r--r-- | src/passes/DuplicateFunctionElimination.cpp | 40 |
1 files changed, 16 insertions, 24 deletions
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<FunctionHasher, Visitor<FunctionHasher>> { - bool isFunctionParallel() { return true; } +struct FunctionHasher : public WalkerPass<PostWalker<FunctionHasher, Visitor<FunctionHasher>>> { + bool isFunctionParallel() override { return true; } - FunctionHasher* create() override { - auto* ret = new FunctionHasher; - ret->setOutput(output); - return ret; - } + FunctionHasher(std::map<Function*, uint32_t>* output) : output(output) {} - void setOutput(std::map<Function*, uint32_t>* output_) { - output = output_; + FunctionHasher* create() override { + return new FunctionHasher(output); } void doWalkFunction(Function* func) { @@ -63,17 +59,13 @@ private: }; }; -struct FunctionReplacer : public PostWalker<FunctionReplacer, Visitor<FunctionReplacer>> { - bool isFunctionParallel() { return true; } +struct FunctionReplacer : public WalkerPass<PostWalker<FunctionReplacer, Visitor<FunctionReplacer>>> { + bool isFunctionParallel() override { return true; } - FunctionReplacer* create() override { - auto* ret = new FunctionReplacer; - ret->setReplacements(replacements); - return ret; - } + FunctionReplacer(std::map<Name, Name>* replacements) : replacements(replacements) {} - void setReplacements(std::map<Name, Name>* 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<FunctionHasher>(&hashes); + hasherRunner.run(); // Find hash-equal groups std::map<uint32_t, std::vector<Function*>> 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<FunctionReplacer>(&replacements); + replacerRunner.run(); // replace in table for (auto& name : module->table.names) { auto iter = replacements.find(name); |