From 53e6e86d1e1d56dd39159fcfcefd9513c0f97079 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 13 Nov 2023 17:01:07 -0800 Subject: [NFC] Add LocalLocation for future use (#6105) This is not needed in GUFA as it tracks local values precisely (each set is connected to the gets that actually read from it), but in a future PR it will be useful to track local values per index (each set is connected to all gets for that index, i.e., each local index is a single "location"). --- src/ir/possible-contents.cpp | 10 ++++++++++ src/ir/possible-contents.h | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src') diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp index 7c9a4fc6b..e7e0cd4fd 100644 --- a/src/ir/possible-contents.cpp +++ b/src/ir/possible-contents.cpp @@ -1202,6 +1202,13 @@ struct InfoCollector assert(handledPops == totalPops); // Handle local.get/sets: each set must write to the proper gets. + // + // Note that we do not use LocalLocation because LocalGraph gives us more + // precise information: we generate direct links from sets to relevant gets + // rather than consider each local index a single location, which + // LocalLocation does. (LocalLocation is useful in cases where we do need a + // single location, such as when we consider what type to give the local; + // the type must be the same for all gets of that local.) LocalGraph localGraph(func, getModule()); for (auto& [get, setsForGet] : localGraph.getSetses) { @@ -2766,6 +2773,9 @@ void Flower::dump(Location location) { } else if (auto* loc = std::get_if(&location)) { std::cout << " paramloc " << loc->func->name << " : " << loc->index << '\n'; + } else if (auto* loc = std::get_if(&location)) { + std::cout << " localloc " << loc->func->name << " : " << loc->index + << '\n'; } else if (auto* loc = std::get_if(&location)) { std::cout << " resultloc $" << loc->func->name << " : " << loc->index << '\n'; diff --git a/src/ir/possible-contents.h b/src/ir/possible-contents.h index 2fd6c39c7..2773c1d31 100644 --- a/src/ir/possible-contents.h +++ b/src/ir/possible-contents.h @@ -380,6 +380,15 @@ struct ParamLocation { } }; +// The location of a value in a local. +struct LocalLocation { + Function* func; + Index index; + bool operator==(const LocalLocation& other) const { + return func == other.func && index == other.index; + } +}; + // The location of one of the results of a function. struct ResultLocation { Function* func; @@ -494,6 +503,7 @@ struct ConeReadLocation { // have. using Location = std::variant struct hash { } }; +template<> struct hash { + size_t operator()(const wasm::LocalLocation& loc) const { + return std::hash>{}( + {size_t(loc.func), loc.index}); + } +}; + template<> struct hash { size_t operator()(const wasm::ResultLocation& loc) const { return std::hash>{}( -- cgit v1.2.3