Skip to content

Commit 0f58d24

Browse files
authored
[NFC] Refactor GUFA's NullLocation and CaughtExnRefLocation into RootLocation (#7822)
Both locations are just roots in the graph: sources of info that we will never learn any more about, and hence fixed.
1 parent cdda336 commit 0f58d24

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

src/ir/possible-contents.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,25 @@ struct InfoCollector
891891
handleIndirectCall(curr, curr->target->type);
892892
}
893893

894-
// Creates a location for a null of a particular type and adds a root for it.
895-
// Such roots are where the default value of an i32 local comes from, or the
896-
// value in a ref.null.
897-
Location getNullLocation(Type type) {
898-
auto location = NullLocation{type};
899-
addRoot(location, PossibleContents::literal(Literal::makeZero(type)));
894+
// Creates a location for a root of a particular type, creating a RootLocation
895+
// and marking it as a root.
896+
Location getRootLocation(Type type, PossibleContents rootValue) {
897+
auto location = RootLocation{type};
898+
addRoot(location, rootValue);
900899
return location;
901900
}
902901

902+
// Creates a root location, settings its value by the type.
903+
Location getRootLocation(Type type) {
904+
return getRootLocation(type, PossibleContents::fromType(type));
905+
}
906+
907+
// Makes a root location containing a null.
908+
Location getNullLocation(Type type) {
909+
return getRootLocation(type,
910+
PossibleContents::literal(Literal::makeZero(type)));
911+
}
912+
903913
// Iterates over a list of children and adds links from them. The target of
904914
// those link is created using a function that is passed in, which receives
905915
// the index of the child.
@@ -1220,9 +1230,7 @@ struct InfoCollector
12201230
}
12211231

12221232
if (curr->catchRefs[tagIndex]) {
1223-
auto location = CaughtExnRefLocation{};
1224-
addRoot(location,
1225-
PossibleContents::fromType(Type(HeapType::exn, NonNullable)));
1233+
auto location = getRootLocation(Type(HeapType::exn, NonNullable));
12261234
info.links.push_back(
12271235
{location, getBreakTargetLocation(target, exnrefIndex)});
12281236
}
@@ -3062,8 +3070,8 @@ void Flower::dump(Location location) {
30623070
std::cout << " sigparamloc " << '\n';
30633071
} else if (auto* loc = std::get_if<SignatureResultLocation>(&location)) {
30643072
std::cout << " sigresultloc " << loc->type << " : " << loc->index << '\n';
3065-
} else if (auto* loc = std::get_if<NullLocation>(&location)) {
3066-
std::cout << " Nullloc " << loc->type << '\n';
3073+
} else if (auto* loc = std::get_if<RootLocation>(&location)) {
3074+
std::cout << " rootloc " << loc->type << '\n';
30673075
} else {
30683076
std::cout << " (other)\n";
30693077
}

src/ir/possible-contents.h

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -500,20 +500,17 @@ struct TagLocation {
500500
}
501501
};
502502

503-
// The location of an exnref materialized by a catch_ref or catch_all_ref clause
504-
// of a try_table. No data is stored here. exnrefs contain a tag and a payload
505-
// at run-time, as well as potential metadata such as stack traces, but we don't
506-
// track that. So this is the same as NullLocation in a way: we just need *a*
507-
// source of contents for places that receive an exnref.
508-
struct CaughtExnRefLocation {
509-
bool operator==(const CaughtExnRefLocation& other) const { return true; }
510-
};
511-
512-
// A null value. This is used as the location of the default value of a var in a
513-
// function, a null written to a struct field in struct.new_with_default, etc.
514-
struct NullLocation {
503+
// A root value. This is used as the location of the default value of a var in a
504+
// function, a null written to a struct field in struct.new_with_default, an
505+
// exnref from a catch etc. - in all these cases, we know
506+
//
507+
// 1. The value (which might be a null, or "anything of this type").
508+
// 2. That the value will never change; we can learn nothing more here.
509+
// 3. That all roots of this type can share the same location.
510+
//
511+
struct RootLocation {
515512
Type type;
516-
bool operator==(const NullLocation& other) const {
513+
bool operator==(const RootLocation& other) const {
517514
return type == other.type;
518515
}
519516
};
@@ -555,8 +552,7 @@ using Location = std::variant<ExpressionLocation,
555552
SignatureResultLocation,
556553
DataLocation,
557554
TagLocation,
558-
CaughtExnRefLocation,
559-
NullLocation,
555+
RootLocation,
560556
ConeReadLocation>;
561557

562558
} // namespace wasm
@@ -637,14 +633,8 @@ template<> struct hash<wasm::TagLocation> {
637633
}
638634
};
639635

640-
template<> struct hash<wasm::CaughtExnRefLocation> {
641-
size_t operator()(const wasm::CaughtExnRefLocation& loc) const {
642-
return std::hash<const void*>()("caught-exnref-location");
643-
}
644-
};
645-
646-
template<> struct hash<wasm::NullLocation> {
647-
size_t operator()(const wasm::NullLocation& loc) const {
636+
template<> struct hash<wasm::RootLocation> {
637+
size_t operator()(const wasm::RootLocation& loc) const {
648638
return std::hash<wasm::Type>{}(loc.type);
649639
}
650640
};

0 commit comments

Comments
 (0)