From 2cd0f408f39c78e3bb0f141ee4d1b9ce2a4f1c16 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 20 Apr 2023 15:13:46 -0700 Subject: [Wasm GC] ReFinalize when needed in SimplifyGlobals (#5682) --- src/passes/SimplifyGlobals.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/passes/SimplifyGlobals.cpp b/src/passes/SimplifyGlobals.cpp index f9bccab23..97e91bbab 100644 --- a/src/passes/SimplifyGlobals.cpp +++ b/src/passes/SimplifyGlobals.cpp @@ -328,6 +328,10 @@ struct ConstantGlobalApplier : public WalkerPass< LinearExecutionWalker>> { + using super = WalkerPass< + LinearExecutionWalker>>; + bool isFunctionParallel() override { return true; } ConstantGlobalApplier(NameSet* constantGlobals, bool optimize) @@ -337,6 +341,16 @@ struct ConstantGlobalApplier return std::make_unique(constantGlobals, optimize); } + bool refinalize = false; + + void replaceCurrent(Expression* rep) { + if (rep->type != getCurrent()->type) { + // This operation will change the type, so refinalize. + refinalize = true; + } + super::replaceCurrent(rep); + } + void visitExpression(Expression* curr) { if (auto* set = curr->dynCast()) { if (Properties::isConstantExpression(set->value)) { @@ -386,10 +400,15 @@ struct ConstantGlobalApplier } void visitFunction(Function* curr) { - if (replaced && optimize) { - PassRunner runner(getPassRunner()); - runner.addDefaultFunctionOptimizationPasses(); - runner.runOnFunction(curr); + if (replaced) { + if (refinalize) { + ReFinalize().walkFunctionInModule(curr, this->getModule()); + } + if (optimize) { + PassRunner runner(getPassRunner()); + runner.addDefaultFunctionOptimizationPasses(); + runner.runOnFunction(curr); + } } } -- cgit v1.2.3