From 2055ea3fd0391c1abb92cdec54f32274dc7fd971 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Fri, 30 Sep 2022 18:17:45 -0500 Subject: 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. --- src/passes/Print.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/passes/Print.cpp') diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 2a031ad01..01b004d97 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -3365,9 +3365,9 @@ public: bool modifiesBinaryenIR() override { return false; } - void run(PassRunner* runner, Module* module) override { + void run(Module* module) override { PrintSExpression print(o); - print.setDebugInfo(runner->options.debugInfo); + print.setDebugInfo(getPassOptions().debugInfo); print.visitModule(module); } }; @@ -3381,10 +3381,10 @@ public: MinifiedPrinter() = default; MinifiedPrinter(std::ostream* o) : Printer(o) {} - void run(PassRunner* runner, Module* module) override { + void run(Module* module) override { PrintSExpression print(o); print.setMinify(true); - print.setDebugInfo(runner->options.debugInfo); + print.setDebugInfo(getPassOptions().debugInfo); print.visitModule(module); } }; @@ -3398,10 +3398,10 @@ public: FullPrinter() = default; FullPrinter(std::ostream* o) : Printer(o) {} - void run(PassRunner* runner, Module* module) override { + void run(Module* module) override { PrintSExpression print(o); print.setFull(true); - print.setDebugInfo(runner->options.debugInfo); + print.setDebugInfo(getPassOptions().debugInfo); print.currModule = module; print.visitModule(module); } @@ -3416,9 +3416,9 @@ public: PrintStackIR() = default; PrintStackIR(std::ostream* o) : Printer(o) {} - void run(PassRunner* runner, Module* module) override { + void run(Module* module) override { PrintSExpression print(o); - print.setDebugInfo(runner->options.debugInfo); + print.setDebugInfo(getPassOptions().debugInfo); print.setStackIR(true); print.currModule = module; print.visitModule(module); @@ -3603,7 +3603,12 @@ namespace std { std::ostream& operator<<(std::ostream& o, wasm::Module& module) { wasm::PassRunner runner(&module); - wasm::Printer(&o).run(&runner, &module); + wasm::Printer printer(&o); + // Do not use runner.run(), since that will cause an infinite recursion in + // BINARYEN_PASS_DEBUG=3, which prints modules (using this function) as part + // of running passes. + printer.setPassRunner(&runner); + printer.run(&module); return o; } -- cgit v1.2.3