diff --git a/src/ir/LocalGraph.cpp b/src/ir/LocalGraph.cpp index 11965040c96..af13707314e 100644 --- a/src/ir/LocalGraph.cpp +++ b/src/ir/LocalGraph.cpp @@ -552,7 +552,14 @@ bool LocalGraph::isSSA(Index x) { return SSAIndexes.count(x); } // LazyLocalGraph LazyLocalGraph::LazyLocalGraph(Function* func, Module* module) - : LocalGraphBase(func, module) { + : LocalGraphBase(func, module) {} + +void LazyLocalGraph::makeFlower() const { + // Lazy graphs do not provide |locations| publicly. TODO: perhaps refactor to + // avoid filling in this dummy data structure, but we may want to add a lazy + // version of it too, so see which makes sense first. + LocalGraph::Locations locations; + flower = std::make_unique(getSetsMap, locations, func, module); @@ -578,10 +585,16 @@ LazyLocalGraph::~LazyLocalGraph() { } void LazyLocalGraph::computeGetSets(LocalGet* get) const { + if (!flower) { + makeFlower(); + } flower->computeGetSets(get); } void LazyLocalGraph::computeSetInfluences(LocalSet* set) const { + if (!flower) { + makeFlower(); + } flower->computeSetInfluences(set, setInfluences); } diff --git a/src/ir/local-graph.h b/src/ir/local-graph.h index 7fe9adedc24..46bc135e0bd 100644 --- a/src/ir/local-graph.h +++ b/src/ir/local-graph.h @@ -58,11 +58,8 @@ struct LocalGraphBase { // get. Typically only one or two apply there, so this is a small set. using Sets = SmallSet; - // Where each get and set is. We compute this while doing the main computation - // and make it accessible for users, for easy replacing of things without - // extra work. + // Where each get and set is. using Locations = std::map; - Locations locations; // A map of each get to the sets relevant to it (i.e., that it can read from). using GetSetsMap = std::unordered_map; @@ -104,6 +101,11 @@ struct LocalGraph : public LocalGraphBase { return iter->second; } + // We compute the locations of gets and sets while doing the main computation + // and make it accessible for users, for easy replacing of things without + // extra work. + Locations locations; + // Checks if two gets are equivalent, that is, definitely have the same // value. bool equivalent(LocalGet* a, LocalGet* b); @@ -213,7 +215,12 @@ struct LazyLocalGraph : public LocalGraphBase { void computeSetInfluences(LocalSet* set) const; // This remains alive as long as we are, so that we can compute things lazily. - std::unique_ptr flower; + // It is mutable as when we construct this is an internal detail, that does + // not cause observable differences in API calls. + mutable std::unique_ptr flower; + + // We create |flower| lazily. + void makeFlower() const; }; } // namespace wasm