diff options
author | Thomas Lively <tlively@google.com> | 2022-09-30 18:17:45 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 23:17:45 +0000 |
commit | 2055ea3fd0391c1abb92cdec54f32274dc7fd971 (patch) | |
tree | 2d9ccaae076b065373b1507d75bc3886232363ec /src/passes/SimplifyGlobals.cpp | |
parent | 62d056f889d4b94562a104e2fcad318857550d5b (diff) | |
download | binaryen-2055ea3fd0391c1abb92cdec54f32274dc7fd971.tar.gz binaryen-2055ea3fd0391c1abb92cdec54f32274dc7fd971.tar.bz2 binaryen-2055ea3fd0391c1abb92cdec54f32274dc7fd971.zip |
Refactor interaction between Pass and PassRunner (#5093)
Previously only WalkerPasses had access to the `getPassRunner` and
`getPassOptions` methods. Move those methods to `Pass` so all passes can use
them. As a result, the `PassRunner` passed to `Pass::run` and
`Pass::runOnFunction` is no longer necessary, so remove it.
Also update `Pass::create` to return a unique_ptr, which is more efficient than
having it return a raw pointer only to have the `PassRunner` wrap that raw
pointer in a `unique_ptr`.
Delete the unused template `PassRunner::getLast()`, which looks like it was
intended to enable retrieving previous analyses and has been in the code base
since 2015 but is not implemented anywhere.
Diffstat (limited to 'src/passes/SimplifyGlobals.cpp')
-rw-r--r-- | src/passes/SimplifyGlobals.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp index daaa82447..463261d35 100644 --- a/src/passes/SimplifyGlobals.cpp +++ b/src/passes/SimplifyGlobals.cpp @@ -97,7 +97,9 @@ struct GlobalUseScanner : public WalkerPass<PostWalker<GlobalUseScanner>> { GlobalUseScanner(GlobalInfoMap* infos) : infos(infos) {} - GlobalUseScanner* create() override { return new GlobalUseScanner(infos); } + std::unique_ptr<Pass> create() override { + return std::make_unique<GlobalUseScanner>(infos); + } void visitGlobalSet(GlobalSet* curr) { (*infos)[curr->name].written++; @@ -307,8 +309,8 @@ struct GlobalUseModifier : public WalkerPass<PostWalker<GlobalUseModifier>> { GlobalUseModifier(NameNameMap* copiedParentMap) : copiedParentMap(copiedParentMap) {} - GlobalUseModifier* create() override { - return new GlobalUseModifier(copiedParentMap); + std::unique_ptr<Pass> create() override { + return std::make_unique<GlobalUseModifier>(copiedParentMap); } void visitGlobalGet(GlobalGet* curr) { @@ -331,8 +333,8 @@ struct ConstantGlobalApplier ConstantGlobalApplier(NameSet* constantGlobals, bool optimize) : constantGlobals(constantGlobals), optimize(optimize) {} - ConstantGlobalApplier* create() override { - return new ConstantGlobalApplier(constantGlobals, optimize); + std::unique_ptr<Pass> create() override { + return std::make_unique<ConstantGlobalApplier>(constantGlobals, optimize); } void visitExpression(Expression* curr) { @@ -377,8 +379,7 @@ struct ConstantGlobalApplier void visitFunction(Function* curr) { if (replaced && optimize) { - PassRunner runner(getModule(), getPassRunner()->options); - runner.setIsNested(true); + PassRunner runner(getPassRunner()); runner.addDefaultFunctionOptimizationPasses(); runner.runOnFunction(curr); } @@ -399,8 +400,8 @@ struct GlobalSetRemover : public WalkerPass<PostWalker<GlobalSetRemover>> { bool isFunctionParallel() override { return true; } - GlobalSetRemover* create() override { - return new GlobalSetRemover(toRemove, optimize); + std::unique_ptr<Pass> create() override { + return std::make_unique<GlobalSetRemover>(toRemove, optimize); } void visitGlobalSet(GlobalSet* curr) { @@ -412,8 +413,7 @@ struct GlobalSetRemover : public WalkerPass<PostWalker<GlobalSetRemover>> { void visitFunction(Function* curr) { if (removed && optimize) { - PassRunner runner(getModule(), getPassRunner()->options); - runner.setIsNested(true); + PassRunner runner(getPassRunner()); runner.addDefaultFunctionOptimizationPasses(); runner.runOnFunction(curr); } @@ -428,7 +428,6 @@ private: } // anonymous namespace struct SimplifyGlobals : public Pass { - PassRunner* runner; Module* module; GlobalInfoMap map; @@ -436,8 +435,7 @@ struct SimplifyGlobals : public Pass { SimplifyGlobals(bool optimize = false) : optimize(optimize) {} - void run(PassRunner* runner_, Module* module_) override { - runner = runner_; + void run(Module* module_) override { module = module_; while (iteration()) { @@ -475,7 +473,7 @@ struct SimplifyGlobals : public Pass { map[ex->value].exported = true; } } - GlobalUseScanner(&map).run(runner, module); + GlobalUseScanner(&map).run(getPassRunner(), module); // We now know which are immutable in practice. for (auto& global : module->globals) { auto& info = map[global->name]; @@ -564,7 +562,8 @@ struct SimplifyGlobals : public Pass { // then see that since the global has no writes, it is a constant, which // will lead to removal of gets, and after removing them, the global itself // will be removed as well. - GlobalSetRemover(&globalsNotNeedingSets, optimize).run(runner, module); + GlobalSetRemover(&globalsNotNeedingSets, optimize) + .run(getPassRunner(), module); return more; } @@ -595,7 +594,7 @@ struct SimplifyGlobals : public Pass { } } // Apply to the gets. - GlobalUseModifier(&copiedParentMap).run(runner, module); + GlobalUseModifier(&copiedParentMap).run(getPassRunner(), module); } } @@ -633,7 +632,8 @@ struct SimplifyGlobals : public Pass { constantGlobals.insert(global->name); } } - ConstantGlobalApplier(&constantGlobals, optimize).run(runner, module); + ConstantGlobalApplier(&constantGlobals, optimize) + .run(getPassRunner(), module); } }; |