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/tools | |
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/tools')
-rw-r--r-- | src/tools/wasm-metadce.cpp | 4 | ||||
-rw-r--r-- | src/tools/wasm-split/instrumenter.cpp | 3 | ||||
-rw-r--r-- | src/tools/wasm-split/instrumenter.h | 3 | ||||
-rw-r--r-- | src/tools/wasm-split/wasm-split.cpp | 6 | ||||
-rw-r--r-- | src/tools/wasm2js.cpp | 4 |
5 files changed, 12 insertions, 8 deletions
diff --git a/src/tools/wasm-metadce.cpp b/src/tools/wasm-metadce.cpp index 741afb22f..5699b40f2 100644 --- a/src/tools/wasm-metadce.cpp +++ b/src/tools/wasm-metadce.cpp @@ -244,7 +244,9 @@ struct MetaDCEGraph { Scanner(MetaDCEGraph* parent) : parent(parent) {} - Scanner* create() override { return new Scanner(parent); } + std::unique_ptr<Pass> create() override { + return std::make_unique<Scanner>(parent); + } void visitCall(Call* curr) { if (!getModule()->getFunction(curr->target)->imported()) { diff --git a/src/tools/wasm-split/instrumenter.cpp b/src/tools/wasm-split/instrumenter.cpp index 7f9ff9c75..86a52688e 100644 --- a/src/tools/wasm-split/instrumenter.cpp +++ b/src/tools/wasm-split/instrumenter.cpp @@ -26,8 +26,7 @@ Instrumenter::Instrumenter(const InstrumenterConfig& config, uint64_t moduleHash) : config(config), moduleHash(moduleHash) {} -void Instrumenter::run(PassRunner* runner, Module* wasm) { - this->runner = runner; +void Instrumenter::run(Module* wasm) { this->wasm = wasm; size_t numFuncs = 0; diff --git a/src/tools/wasm-split/instrumenter.h b/src/tools/wasm-split/instrumenter.h index f4f2f2119..135d2b74f 100644 --- a/src/tools/wasm-split/instrumenter.h +++ b/src/tools/wasm-split/instrumenter.h @@ -41,7 +41,6 @@ struct InstrumenterConfig { // at the beginning of each function to set its timestamp, and a new exported // function for dumping the profile data. struct Instrumenter : public Pass { - PassRunner* runner = nullptr; Module* wasm = nullptr; const InstrumenterConfig& config; @@ -54,7 +53,7 @@ struct Instrumenter : public Pass { Instrumenter(const InstrumenterConfig& config, uint64_t moduleHash); - void run(PassRunner* runner, Module* wasm) override; + void run(Module* wasm) override; private: void addGlobals(size_t numFuncs); diff --git a/src/tools/wasm-split/wasm-split.cpp b/src/tools/wasm-split/wasm-split.cpp index ec1f5555c..49a15e934 100644 --- a/src/tools/wasm-split/wasm-split.cpp +++ b/src/tools/wasm-split/wasm-split.cpp @@ -110,7 +110,6 @@ void instrumentModule(const WasmSplitOptions& options) { } uint64_t moduleHash = hashFile(options.inputFiles[0]); - PassRunner runner(&wasm, options.passOptions); InstrumenterConfig config; if (options.importNamespace.size()) { config.importNamespace = options.importNamespace; @@ -120,7 +119,10 @@ void instrumentModule(const WasmSplitOptions& options) { } config.storageKind = options.storageKind; config.profileExport = options.profileExport; - Instrumenter(config, moduleHash).run(&runner, &wasm); + + PassRunner runner(&wasm, options.passOptions); + runner.add(std::make_unique<Instrumenter>(config, moduleHash)); + runner.run(); adjustTableSize(wasm, options.initialTableSize); diff --git a/src/tools/wasm2js.cpp b/src/tools/wasm2js.cpp index 061cd386f..7cecb5f6d 100644 --- a/src/tools/wasm2js.cpp +++ b/src/tools/wasm2js.cpp @@ -39,7 +39,9 @@ static void optimizeWasm(Module& wasm, PassOptions options) { struct OptimizeForJS : public WalkerPass<PostWalker<OptimizeForJS>> { bool isFunctionParallel() override { return true; } - Pass* create() override { return new OptimizeForJS; } + std::unique_ptr<Pass> create() override { + return std::make_unique<OptimizeForJS>(); + } void visitBinary(Binary* curr) { // x - -c (where c is a constant) is larger than x + c, in js (but not |