Skip to content

Commit

Permalink
[NFC] Refactor Heap2Local logic (#6473)
Browse files Browse the repository at this point in the history
Separate out an EscapeAnalyzer class that does the escape analysis,
and a Struct2Local one that does the optimization.

Also make a few things const here to be safer.
  • Loading branch information
kripken authored Apr 6, 2024
1 parent e862d5c commit 98f08ef
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 357 deletions.
8 changes: 6 additions & 2 deletions src/ir/branch-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,14 @@ struct BranchTargets {

// Gets the expression that defines this branch target, i.e., where we branch
// to if we branch to that name.
Expression* getTarget(Name name) { return inner.targets[name]; }
Expression* getTarget(Name name) const {
auto iter = inner.targets.find(name);
assert(iter != inner.targets.end());
return iter->second;
}

// Gets the expressions branching to a target.
std::unordered_set<Expression*> getBranches(Name name) {
std::unordered_set<Expression*> getBranches(Name name) const {
auto iter = inner.branches.find(name);
if (iter != inner.branches.end()) {
return iter->second;
Expand Down
8 changes: 7 additions & 1 deletion src/ir/parents.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ namespace wasm {
struct Parents {
Parents(Expression* expr) { inner.walk(expr); }

Expression* getParent(Expression* curr) { return inner.parentMap[curr]; }
Expression* getParent(Expression* curr) const {
auto iter = inner.parentMap.find(curr);
if (iter != inner.parentMap.end()) {
return iter->second;
}
return nullptr;
}

private:
struct Inner
Expand Down
Loading

0 comments on commit 98f08ef

Please # to comment.