diff options
Diffstat (limited to 'src/passes')
-rw-r--r-- | src/passes/GlobalTypeOptimization.cpp | 4 | ||||
-rw-r--r-- | src/passes/TypeMerging.cpp | 33 |
2 files changed, 16 insertions, 21 deletions
diff --git a/src/passes/GlobalTypeOptimization.cpp b/src/passes/GlobalTypeOptimization.cpp index eec8e206d..dac6fd7b6 100644 --- a/src/passes/GlobalTypeOptimization.cpp +++ b/src/passes/GlobalTypeOptimization.cpp @@ -171,8 +171,8 @@ struct GlobalTypeOptimization : public Pass { // fields in a supertype is a constraint on what subtypes can do. That is, // we decide for each supertype what the optimal order is, and consider that // fixed, and then subtypes can decide how to sort fields that they append. - HeapTypeOrdering::SupertypesFirst sorted; - for (auto type : sorted.sort(propagator.subTypes.types)) { + for (auto type : + HeapTypeOrdering::supertypesFirst(propagator.subTypes.types)) { if (!type.isStruct()) { continue; } diff --git a/src/passes/TypeMerging.cpp b/src/passes/TypeMerging.cpp index 1cac7732f..206addd2f 100644 --- a/src/passes/TypeMerging.cpp +++ b/src/passes/TypeMerging.cpp @@ -142,6 +142,17 @@ struct TypeMerging : public Pass { return type; } + std::vector<HeapType> + mergeableSupertypesFirst(const std::vector<HeapType>& types) { + return HeapTypeOrdering::supertypesFirst( + types, [&](HeapType type) -> std::optional<HeapType> { + if (auto super = type.getDeclaredSuperType()) { + return getMerged(*super); + } + return std::nullopt; + }); + } + void run(Module* module_) override; // We will do two different kinds of merging: First, we will merge types into @@ -163,20 +174,6 @@ struct TypeMerging : public Pass { void applyMerges(); }; -struct MergeableSupertypesFirst - : HeapTypeOrdering::SupertypesFirstBase<MergeableSupertypesFirst> { - TypeMerging& merging; - - MergeableSupertypesFirst(TypeMerging& merging) : merging(merging) {} - - std::optional<HeapType> getDeclaredSuperType(HeapType type) { - if (auto super = type.getDeclaredSuperType()) { - return merging.getMerged(*super); - } - return std::nullopt; - } -}; - // Hash and equality-compare HeapTypes based on their top-level structure (i.e. // "shape"), ignoring nontrivial heap type children that will not be // differentiated between until we run the DFA partition refinement. @@ -305,8 +302,7 @@ bool TypeMerging::merge(MergeKind kind) { // For each type, either create a new partition or add to its supertype's // partition. - MergeableSupertypesFirst sortedTypes(*this); - for (auto type : sortedTypes.sort(mergeable)) { + for (auto type : mergeableSupertypesFirst(mergeable)) { // We need partitions for any public children of this type since those // children will participate in the DFA we're creating. for (auto child : getPublicChildren(type)) { @@ -414,7 +410,7 @@ bool TypeMerging::merge(MergeKind kind) { std::vector<HeapType> newMergeable; bool merged = false; for (const auto& partition : refinedPartitions) { - auto target = *MergeableSupertypesFirst(*this).sort(partition).begin(); + auto target = mergeableSupertypesFirst(partition).front(); newMergeable.push_back(target); for (auto type : partition) { if (type != target) { @@ -452,8 +448,7 @@ TypeMerging::splitSupertypePartition(const std::vector<HeapType>& types) { std::unordered_set<HeapType> includedTypes(types.begin(), types.end()); std::vector<std::vector<HeapType>> partitions; std::unordered_map<HeapType, Index> partitionIndices; - MergeableSupertypesFirst sortedTypes(*this); - for (auto type : sortedTypes.sort(types)) { + for (auto type : mergeableSupertypesFirst(types)) { auto super = type.getDeclaredSuperType(); if (super && includedTypes.count(*super)) { // We must already have a partition for the supertype we can add to. |