Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ir/possible-contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -2766,6 +2773,9 @@ void Flower::dump(Location location) {
} else if (auto* loc = std::get_if<ParamLocation>(&location)) {
std::cout << " paramloc " << loc->func->name << " : " << loc->index
<< '\n';
} else if (auto* loc = std::get_if<LocalLocation>(&location)) {
std::cout << " localloc " << loc->func->name << " : " << loc->index
<< '\n';
} else if (auto* loc = std::get_if<ResultLocation>(&location)) {
std::cout << " resultloc $" << loc->func->name << " : " << loc->index
<< '\n';
Expand Down
17 changes: 17 additions & 0 deletions src/ir/possible-contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -494,6 +503,7 @@ struct ConeReadLocation {
// have.
using Location = std::variant<ExpressionLocation,
ParamLocation,
LocalLocation,
ResultLocation,
BreakTargetLocation,
GlobalLocation,
Expand Down Expand Up @@ -534,6 +544,13 @@ template<> struct hash<wasm::ParamLocation> {
}
};

template<> struct hash<wasm::LocalLocation> {
size_t operator()(const wasm::LocalLocation& loc) const {
return std::hash<std::pair<size_t, wasm::Index>>{}(
{size_t(loc.func), loc.index});
}
};

template<> struct hash<wasm::ResultLocation> {
size_t operator()(const wasm::ResultLocation& loc) const {
return std::hash<std::pair<size_t, wasm::Index>>{}(
Expand Down
Loading