Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 0 additions & 1 deletion scripts/fuzz_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,6 @@ def write_commands(commands, filename):
("--abstract-type-refining",),
("--cfp",),
("--cfp-reftest",),
("--gsi",),
("--type-ssa",),
("--type-merging",)}

Expand Down
18 changes: 15 additions & 3 deletions src/passes/GlobalStructInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* limitations under the License.
*/

//
// GlobalStructInference: Analyze struct usage globally, in particular, structs
// created (perhaps only) in globals.
//
// Finds types which are only created in assignments to immutable globals. For
// such types we can replace a struct.get with a global.get when there is a
Expand Down Expand Up @@ -47,7 +50,7 @@
//
// This also optimizes some related things - reads from structs created in
// globals - that benefit from the infrastructure here (see unnesting, below),
// even without this type-based approach.
// even without this type-based approach, and even in open world.
//
// TODO: Only do the case with a select when shrinkLevel == 0?
//
Expand Down Expand Up @@ -81,17 +84,24 @@ struct GlobalStructInference : public Pass {
//
// We will remove unoptimizable types from here, so in practice, if a type is
// optimizable it will have an entry here, and not if not.
//
// This is filled in when in closed world. In open world, we cannot do such
// type-based inference, and this remains empty.
std::unordered_map<HeapType, std::vector<Name>> typeGlobals;

void run(Module* module) override {
if (!module->features.hasGC()) {
return;
}

if (!getPassOptions().closedWorld) {
Fatal() << "GSI requires --closed-world";
if (getPassOptions().closedWorld) {
analyzeClosedWorld(module);
}

optimize(module);
}

void analyzeClosedWorld(Module* module) {
// First, find all the information we need. We need to know which struct
// types are created in functions, because we will not be able to optimize
// those.
Expand Down Expand Up @@ -213,7 +223,9 @@ struct GlobalStructInference : public Pass {
for (auto& [type, globals] : typeGlobals) {
std::sort(globals.begin(), globals.end());
}
}

void optimize(Module* module) {
// We are looking for the case where we can pick between two values using a
// single comparison. More than two values, or more than a single
// comparison, lead to tradeoffs that may not be worth it.
Expand Down
Loading
Loading