summaryrefslogtreecommitdiff
path: root/src/passes/pass.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-09-30 18:17:45 -0500
committerGitHub <noreply@github.com>2022-09-30 23:17:45 +0000
commit2055ea3fd0391c1abb92cdec54f32274dc7fd971 (patch)
tree2d9ccaae076b065373b1507d75bc3886232363ec /src/passes/pass.cpp
parent62d056f889d4b94562a104e2fcad318857550d5b (diff)
downloadbinaryen-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/pass.cpp')
-rw-r--r--src/passes/pass.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp
index c548b66c5..4036b8f47 100644
--- a/src/passes/pass.cpp
+++ b/src/passes/pass.cpp
@@ -896,7 +896,11 @@ void PassRunner::runPass(Pass* pass) {
checker = std::unique_ptr<AfterEffectModuleChecker>(
new AfterEffectModuleChecker(wasm));
}
- pass->run(this, wasm);
+ // Passes can only be run once and we deliberately do not clear the pass
+ // runner after running the pass, so there must not already be a runner here.
+ assert(!pass->getPassRunner());
+ pass->setPassRunner(this);
+ pass->run(wasm);
handleAfterEffects(pass);
if (getPassDebug()) {
checker->check();
@@ -925,15 +929,17 @@ void PassRunner::runPassOnFunction(Pass* pass, Function* func) {
bodyBefore << *func->body << '\n';
}
- // function-parallel passes get a new instance per function
- auto instance = std::unique_ptr<Pass>(pass->create());
std::unique_ptr<AfterEffectFunctionChecker> checker;
if (passDebug) {
- checker = std::unique_ptr<AfterEffectFunctionChecker>(
- new AfterEffectFunctionChecker(func));
+ checker = std::make_unique<AfterEffectFunctionChecker>(func);
}
- instance->runOnFunction(this, wasm, func);
+
+ // Function-parallel passes get a new instance per function
+ auto instance = pass->create();
+ instance->setPassRunner(this);
+ instance->runOnFunction(wasm, func);
handleAfterEffects(pass, func);
+
if (passDebug) {
checker->check();
}