summaryrefslogtreecommitdiff
path: root/src/passes/SafeHeap.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2022-09-30 18:17:45 -0500
committerGitHub <noreply@github.com>2022-09-30 23:17:45 +0000
commit2055ea3fd0391c1abb92cdec54f32274dc7fd971 (patch)
tree2d9ccaae076b065373b1507d75bc3886232363ec /src/passes/SafeHeap.cpp
parent62d056f889d4b94562a104e2fcad318857550d5b (diff)
downloadbinaryen-2055ea3fd0391c1abb92cdec54f32274dc7fd971.tar.gz
binaryen-2055ea3fd0391c1abb92cdec54f32274dc7fd971.tar.bz2
binaryen-2055ea3fd0391c1abb92cdec54f32274dc7fd971.zip
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.
Diffstat (limited to 'src/passes/SafeHeap.cpp')
-rw-r--r--src/passes/SafeHeap.cpp17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/passes/SafeHeap.cpp b/src/passes/SafeHeap.cpp
index eccb521d2..0e9e8aeef 100644
--- a/src/passes/SafeHeap.cpp
+++ b/src/passes/SafeHeap.cpp
@@ -69,8 +69,8 @@ struct AccessInstrumenter : public WalkerPass<PostWalker<AccessInstrumenter>> {
bool isFunctionParallel() override { return true; }
- AccessInstrumenter* create() override {
- return new AccessInstrumenter(ignoreFunctions);
+ std::unique_ptr<Pass> create() override {
+ return std::make_unique<AccessInstrumenter>(ignoreFunctions);
}
AccessInstrumenter(std::set<Name> ignoreFunctions)
@@ -131,10 +131,8 @@ static std::set<Name> findCalledFunctions(Module* module, Name startFunc) {
}
struct SafeHeap : public Pass {
- PassOptions options;
- void run(PassRunner* runner, Module* module) override {
- options = runner->options;
+ void run(Module* module) override {
assert(!module->memories.empty());
// add imports
addImports(module);
@@ -147,7 +145,7 @@ struct SafeHeap : public Pass {
// not available until after it has run.
std::set<Name> ignoreFunctions = findCalledFunctions(module, module->start);
ignoreFunctions.insert(getSbrkPtr);
- AccessInstrumenter(ignoreFunctions).run(runner, module);
+ AccessInstrumenter(ignoreFunctions).run(getPassRunner(), module);
// add helper checking funcs and imports
addGlobals(module, module->features);
}
@@ -394,9 +392,10 @@ struct SafeHeap : public Pass {
Type indexType,
bool is64,
Name memory) {
- auto upperOp = is64 ? options.lowMemoryUnused ? LtUInt64 : EqInt64
- : options.lowMemoryUnused ? LtUInt32 : EqInt32;
- auto upperBound = options.lowMemoryUnused ? PassOptions::LowMemoryBound : 0;
+ bool lowMemUnused = getPassOptions().lowMemoryUnused;
+ auto upperOp = is64 ? lowMemUnused ? LtUInt64 : EqInt64
+ : lowMemUnused ? LtUInt32 : EqInt32;
+ auto upperBound = lowMemUnused ? PassOptions::LowMemoryBound : 0;
Expression* brkLocation;
if (sbrk.is()) {
brkLocation =