MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / BestEffortMatchFunctions

Method BestEffortMatchFunctions

source/diff/diff.cpp:1655–1720  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1653}
1654
1655void Differ::BestEffortMatchFunctions(const IdGroup& src_func_ids,
1656 const IdGroup& dst_func_ids,
1657 const FunctionInstMap& src_func_insts,
1658 const FunctionInstMap& dst_func_insts) {
1659 struct MatchResult {
1660 uint32_t src_id;
1661 uint32_t dst_id;
1662 DiffMatch src_match;
1663 DiffMatch dst_match;
1664 float match_rate;
1665 bool operator<(const MatchResult& other) const {
1666 return match_rate > other.match_rate;
1667 }
1668 };
1669 std::vector<MatchResult> all_match_results;
1670
1671 for (const uint32_t src_func_id : src_func_ids) {
1672 if (id_map_.IsSrcMapped(src_func_id)) {
1673 continue;
1674 }
1675 const std::string src_name = GetSanitizedName(src_id_to_, src_func_id);
1676
1677 for (const uint32_t dst_func_id : dst_func_ids) {
1678 if (id_map_.IsDstMapped(dst_func_id)) {
1679 continue;
1680 }
1681
1682 // Don't match functions that are named, but the names are different.
1683 const std::string dst_name = GetSanitizedName(dst_id_to_, dst_func_id);
1684 if (src_name != "" && dst_name != "" && src_name != dst_name) {
1685 continue;
1686 }
1687
1688 DiffMatch src_match_result, dst_match_result;
1689 float match_rate = MatchFunctionBodies(
1690 src_func_insts.at(src_func_id), dst_func_insts.at(dst_func_id),
1691 &src_match_result, &dst_match_result);
1692
1693 // Only consider the functions a match if there's at least 60% match.
1694 // This is an arbitrary limit that should be tuned.
1695 constexpr float pass_match_rate = 0.6f;
1696 if (match_rate >= pass_match_rate) {
1697 all_match_results.emplace_back(
1698 MatchResult{src_func_id, dst_func_id, std::move(src_match_result),
1699 std::move(dst_match_result), match_rate});
1700 }
1701 }
1702 }
1703
1704 std::sort(all_match_results.begin(), all_match_results.end());
1705
1706 for (const MatchResult& match_result : all_match_results) {
1707 if (id_map_.IsSrcMapped(match_result.src_id) ||
1708 id_map_.IsDstMapped(match_result.dst_id)) {
1709 continue;
1710 }
1711
1712 id_map_.MapIds(match_result.src_id, match_result.dst_id);

Callers

nothing calls this directly

Calls 6

IsSrcMappedMethod · 0.80
IsDstMappedMethod · 0.80
emplace_backMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
MapIdsMethod · 0.45

Tested by

no test coverage detected