diff options
author | Alon Zakai <azakai@google.com> | 2021-10-11 17:37:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-11 17:37:34 -0700 |
commit | c06b2925232b92fd379a3e8d513ab361b8434a15 (patch) | |
tree | 41adcc814063c9f4277bc339e16dacb8a2195cfc | |
parent | ecda340b791be6c0a31c7dd290a682244aff3e89 (diff) | |
download | binaryen-c06b2925232b92fd379a3e8d513ab361b8434a15.tar.gz binaryen-c06b2925232b92fd379a3e8d513ab361b8434a15.tar.bz2 binaryen-c06b2925232b92fd379a3e8d513ab361b8434a15.zip |
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.
-rw-r--r-- | src/pass.h | 8 | ||||
-rw-r--r-- | src/passes/ConstantFieldPropagation.cpp | 2 | ||||
-rw-r--r-- | src/passes/GlobalTypeOptimization.cpp | 2 | ||||
-rw-r--r-- | src/passes/LegalizeJSInterface.cpp | 2 | ||||
-rw-r--r-- | src/passes/opt-utils.h | 2 |
5 files changed, 11 insertions, 5 deletions
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<typename WalkerType> class WalkerPass : public Pass, public WalkerType { - PassRunner* runner; + PassRunner* runner = nullptr; protected: typedef WalkerPass<WalkerType> 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<FieldInfo> 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()) { |