summaryrefslogtreecommitdiff
path: root/src/ir/local-graph.h
diff options
context:
space:
mode:
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