summaryrefslogtreecommitdiff
path: root/src/passes/Heap2Local.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2024-09-10 13:24:20 -0700
committerGitHub <noreply@github.com>2024-09-10 13:24:20 -0700
commit34ee8342f8148e4c25bd1990e518cd8a9a502f80 (patch)
treefe9fe00a77ac5c7e7c355aeb55ea1e33eddc16a5 /src/passes/Heap2Local.cpp
parent10216e8fdc841f53408bc10caac2709f16b80030 (diff)
downloadbinaryen-34ee8342f8148e4c25bd1990e518cd8a9a502f80.tar.gz
binaryen-34ee8342f8148e4c25bd1990e518cd8a9a502f80.tar.bz2
binaryen-34ee8342f8148e4c25bd1990e518cd8a9a502f80.zip
[NFC] Use a lazy LocalGraph in Heap2Local (#6925)
That pass only cares about reference locals, and even among them, only ones that we see a struct.new/array.new that flows through locals. This makes the pass 40% faster.
Diffstat (limited to 'src/passes/Heap2Local.cpp')
-rw-r--r--src/passes/Heap2Local.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/passes/Heap2Local.cpp b/src/passes/Heap2Local.cpp
index 82a5e90bb..09a50eea8 100644
--- a/src/passes/Heap2Local.cpp
+++ b/src/passes/Heap2Local.cpp
@@ -198,15 +198,17 @@ enum class ParentChildInteraction : int8_t {
struct EscapeAnalyzer {
// To find what escapes, we need to follow where values flow, both up to
// parents, and via branches, and through locals.
- // TODO: for efficiency, only scan reference types in LocalGraph
- const LocalGraph& localGraph;
+ //
+ // We use a lazy graph here because we only need this for reference locals,
+ // and even among them, only ones we see an allocation is stored to.
+ const LazyLocalGraph& localGraph;
const Parents& parents;
const BranchUtils::BranchTargets& branchTargets;
const PassOptions& passOptions;
Module& wasm;
- EscapeAnalyzer(const LocalGraph& localGraph,
+ EscapeAnalyzer(const LazyLocalGraph& localGraph,
const Parents& parents,
const BranchUtils::BranchTargets& branchTargets,
const PassOptions& passOptions,
@@ -1139,17 +1141,13 @@ struct Heap2Local {
Module& wasm;
const PassOptions& passOptions;
- // TODO: construct this LocalGraph on demand
- LocalGraph localGraph;
+ LazyLocalGraph localGraph;
Parents parents;
BranchUtils::BranchTargets branchTargets;
Heap2Local(Function* func, Module& wasm, const PassOptions& passOptions)
: func(func), wasm(wasm), passOptions(passOptions), localGraph(func, &wasm),
parents(func->body), branchTargets(func->body) {
- // We need to track what each set influences, to see where its value can
- // flow to.
- localGraph.computeSetInfluences();
// Find all the relevant allocations in the function: StructNew, ArrayNew,
// ArrayNewFixed.