summaryrefslogtreecommitdiff
path: root/src/ir/local-graph.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-09-04 14:47:19 -0700
committerGitHub <noreply@github.com>2024-09-04 14:47:19 -0700
commit0812ad3564ab802db5c2df7f0fe9fdb22709a535 (patch)
tree6ad2dabc342652f2fcc48bb7bc92ffba211ed021 /src/ir/local-graph.h
parent9671b985aca3ce8ee18e7886229ba03c02e73fac (diff)
downloadbinaryen-0812ad3564ab802db5c2df7f0fe9fdb22709a535.tar.gz
binaryen-0812ad3564ab802db5c2df7f0fe9fdb22709a535.tar.bz2
binaryen-0812ad3564ab802db5c2df7f0fe9fdb22709a535.zip
[NFC] Convert LocalGraph influences accesses to function calls (#6899)
This replaces direct access of the data structure graph.*influences[foo] with a call graph.get*influences(foo). This will allow a later PR to make those calls optionally lazy.
Diffstat (limited to 'src/ir/local-graph.h')
-rw-r--r--src/ir/local-graph.h30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/ir/local-graph.h b/src/ir/local-graph.h
index 8ff4ee3be..17cc6ff31 100644
--- a/src/ir/local-graph.h
+++ b/src/ir/local-graph.h
@@ -74,7 +74,8 @@ struct LocalGraph {
bool equivalent(LocalGet* a, LocalGet* b);
// Optional: compute the influence graphs between sets and gets (useful for
- // algorithms that propagate changes).
+ // algorithms that propagate changes). Set influences are the gets that can
+ // read from it; get influences are the sets that can (directly) read from it.
void computeSetInfluences();
void computeGetInfluences();
@@ -83,11 +84,27 @@ struct LocalGraph {
computeGetInfluences();
}
- // for each get, the sets whose values are influenced by that get
- using GetInfluences = std::unordered_set<LocalSet*>;
- std::unordered_map<LocalGet*, GetInfluences> getInfluences;
using SetInfluences = std::unordered_set<LocalGet*>;
- std::unordered_map<LocalSet*, SetInfluences> setInfluences;
+ using GetInfluences = std::unordered_set<LocalSet*>;
+
+ const SetInfluences& getSetInfluences(LocalSet* set) const {
+ auto iter = setInfluences.find(set);
+ if (iter == setInfluences.end()) {
+ // Use a canonical constant empty set to avoid allocation.
+ static const SetInfluences empty;
+ return empty;
+ }
+ return iter->second;
+ }
+ const GetInfluences& getGetInfluences(LocalGet* get) const {
+ auto iter = getInfluences.find(get);
+ if (iter == getInfluences.end()) {
+ // Use a canonical constant empty set to avoid allocation.
+ static const GetInfluences empty;
+ return empty;
+ }
+ return iter->second;
+ }
// Optional: Compute the local indexes that are SSA, in the sense of
// * a single set for all the gets for that local index
@@ -132,6 +149,9 @@ private:
// with that. It could alternatively be a shared_ptr, but that runs into what
// seems to be a false positive of clang's (but not gcc's) UBSan.
std::unique_ptr<LocalGraphFlower> flower;
+
+ std::unordered_map<LocalSet*, SetInfluences> setInfluences;
+ std::unordered_map<LocalGet*, GetInfluences> getInfluences;
};
} // namespace wasm