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/OnceReduction.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/OnceReduction.cpp')
-rw-r--r-- | src/passes/OnceReduction.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/passes/OnceReduction.cpp b/src/passes/OnceReduction.cpp index 1eb76c29e..c1500f185 100644 --- a/src/passes/OnceReduction.cpp +++ b/src/passes/OnceReduction.cpp @@ -88,7 +88,9 @@ struct Scanner : public WalkerPass<PostWalker<Scanner>> { Scanner(OptInfo& optInfo) : optInfo(optInfo) {} - Scanner* create() override { return new Scanner(optInfo); } + std::unique_ptr<Pass> create() override { + return std::make_unique<Scanner>(optInfo); + } // All the globals we read from. Any read of a global prevents us from // optimizing, unless it is the single read at the top of an "only" function @@ -219,7 +221,9 @@ struct Optimizer Optimizer(OptInfo& optInfo) : optInfo(optInfo) {} - Optimizer* create() override { return new Optimizer(optInfo); } + std::unique_ptr<Pass> create() override { + return std::make_unique<Optimizer>(optInfo); + } void visitGlobalSet(GlobalSet* curr) { if (currBasicBlock) { @@ -344,7 +348,7 @@ private: } // anonymous namespace struct OnceReduction : public Pass { - void run(PassRunner* runner, Module* module) override { + void run(Module* module) override { OptInfo optInfo; // Fill out the initial data. @@ -374,7 +378,7 @@ struct OnceReduction : public Pass { } // Scan the module to find out which globals and functions are "once". - Scanner(optInfo).run(runner, module); + Scanner(optInfo).run(getPassRunner(), module); // Combine the information. We found which globals appear to be "once", but // other information may have proven they are not so, in fact. Specifically, @@ -419,7 +423,7 @@ struct OnceReduction : public Pass { optInfo.newOnceGlobalsSetInFuncs[func->name]; } - Optimizer(optInfo).run(runner, module); + Optimizer(optInfo).run(getPassRunner(), module); optInfo.onceGlobalsSetInFuncs = std::move(optInfo.newOnceGlobalsSetInFuncs); |