From c06b2925232b92fd379a3e8d513ab361b8434a15 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 11 Oct 2021 17:37:34 -0700 Subject: Add runOnModuleCode helper. NFC (#4234) This method is in parallel to runOnFunction above it. It sets the runner and then does the walk, like that method. Also set runner to nullptr by default. I noticed ubsan was warning on things here, which this should avoid, but otherwise I'm not aware of an actual bug, so this should be NFC. But it does provide a safer API that should avoid future bugs. --- src/pass.h | 8 +++++++- src/passes/ConstantFieldPropagation.cpp | 2 +- src/passes/GlobalTypeOptimization.cpp | 2 +- src/passes/LegalizeJSInterface.cpp | 2 +- src/passes/opt-utils.h | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/pass.h b/src/pass.h index 2bb34aeea..cc63971fe 100644 --- a/src/pass.h +++ b/src/pass.h @@ -391,7 +391,7 @@ protected: // template class WalkerPass : public Pass, public WalkerType { - PassRunner* runner; + PassRunner* runner = nullptr; protected: typedef WalkerPass super; @@ -421,6 +421,12 @@ public: WalkerType::walkFunction(func); } + void runOnModuleCode(PassRunner* runner, Module* module) { + setPassRunner(runner); + WalkerType::setModule(module); + WalkerType::walkModuleCode(module); + } + PassRunner* getPassRunner() { return runner; } PassOptions& getPassOptions() { return runner->options; } diff --git a/src/passes/ConstantFieldPropagation.cpp b/src/passes/ConstantFieldPropagation.cpp index 0894a822a..2fdd8333c 100644 --- a/src/passes/ConstantFieldPropagation.cpp +++ b/src/passes/ConstantFieldPropagation.cpp @@ -274,7 +274,7 @@ struct ConstantFieldPropagation : public Pass { functionSetInfos(*module); PCVScanner scanner(functionNewInfos, functionSetInfos); scanner.run(runner, module); - scanner.walkModuleCode(module); + scanner.runOnModuleCode(runner, module); // Combine the data from the functions. PCVStructValuesMap combinedNewInfos, combinedSetInfos; diff --git a/src/passes/GlobalTypeOptimization.cpp b/src/passes/GlobalTypeOptimization.cpp index 89d5b8c0a..35b10bfff 100644 --- a/src/passes/GlobalTypeOptimization.cpp +++ b/src/passes/GlobalTypeOptimization.cpp @@ -93,7 +93,7 @@ struct GlobalTypeOptimization : public Pass { functionSetInfos(*module); FieldInfoScanner scanner(functionNewInfos, functionSetInfos); scanner.run(runner, module); - scanner.walkModuleCode(module); + scanner.runOnModuleCode(runner, module); // Combine the data from the functions. StructValuesMap combinedNewInfos, combinedSetInfos; diff --git a/src/passes/LegalizeJSInterface.cpp b/src/passes/LegalizeJSInterface.cpp index e7a5f9220..e5a69beb1 100644 --- a/src/passes/LegalizeJSInterface.cpp +++ b/src/passes/LegalizeJSInterface.cpp @@ -143,7 +143,7 @@ struct LegalizeJSInterface : public Pass { Fixer fixer(&illegalImportsToLegal); fixer.run(runner, module); - fixer.walkModuleCode(module); + fixer.runOnModuleCode(runner, module); // Finally we can remove all the now-unused illegal imports for (const auto& pair : illegalImportsToLegal) { diff --git a/src/passes/opt-utils.h b/src/passes/opt-utils.h index 326f75f95..28ace047a 100644 --- a/src/passes/opt-utils.h +++ b/src/passes/opt-utils.h @@ -88,7 +88,7 @@ inline void replaceFunctions(PassRunner* runner, // replace direct calls in code both functions and module elements FunctionRefReplacer replacer(maybeReplace); replacer.run(runner, &module); - replacer.walkModuleCode(&module); + replacer.runOnModuleCode(runner, &module); // replace in start if (module.start.is()) { -- cgit v1.2.3