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/ConstantFieldPropagation.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/passes/ConstantFieldPropagation.cpp') diff --git a/src/passes/ConstantFieldPropagation.cpp b/src/passes/ConstantFieldPropagation.cpp index 0ec889e36..0f66fe28b 100644 --- a/src/passes/ConstantFieldPropagation.cpp +++ b/src/passes/ConstantFieldPropagation.cpp @@ -55,7 +55,9 @@ struct FunctionOptimizer : public WalkerPass> { // Only modifies struct.get operations. bool requiresNonNullableLocalFixups() override { return false; } - Pass* create() override { return new FunctionOptimizer(infos); } + std::unique_ptr create() override { + return std::make_unique(infos); + } FunctionOptimizer(PCVStructValuesMap& infos) : infos(infos) {} @@ -126,8 +128,8 @@ private: struct PCVScanner : public StructUtils::StructScanner { - Pass* create() override { - return new PCVScanner(functionNewInfos, functionSetGetInfos); + std::unique_ptr create() override { + return std::make_unique(functionNewInfos, functionSetGetInfos); } PCVScanner(StructUtils::FunctionStructValuesMap& @@ -181,7 +183,7 @@ struct ConstantFieldPropagation : public Pass { // Only modifies struct.get operations. bool requiresNonNullableLocalFixups() override { return false; } - void run(PassRunner* runner, Module* module) override { + void run(Module* module) override { if (!module->features.hasGC()) { return; } @@ -193,6 +195,7 @@ struct ConstantFieldPropagation : public Pass { PCVFunctionStructValuesMap functionNewInfos(*module), functionSetInfos(*module); PCVScanner scanner(functionNewInfos, functionSetInfos); + auto* runner = getPassRunner(); scanner.run(runner, module); scanner.runOnModuleCode(runner, module); -- cgit v1.2.3