[BOLT] Use std::tie to implement operator< (NFC) (#143560)

std::tie facilitates lexicographical comparisons through std::tuple's
built-in operator<.
This commit is contained in:
Kazu Hirata 2025-06-10 11:31:46 -07:00 committed by GitHub
parent 04cffaae8f
commit 8da9eb235d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 9 deletions

View File

@ -52,9 +52,8 @@ public:
uint64_t MispredictedCount; /// number of branches mispredicted
bool operator<(const BinaryBranchInfo &Other) const {
return (Count < Other.Count) ||
(Count == Other.Count &&
MispredictedCount < Other.MispredictedCount);
return std::tie(Count, MispredictedCount) <
std::tie(Other.Count, Other.MispredictedCount);
}
};

View File

@ -77,9 +77,7 @@ struct MCInstInBFReference {
return BF == RHS.BF && Offset == RHS.Offset;
}
bool operator<(const MCInstInBFReference &RHS) const {
if (BF != RHS.BF)
return BF < RHS.BF;
return Offset < RHS.Offset;
return std::tie(BF, Offset) < std::tie(RHS.BF, RHS.Offset);
}
operator MCInst &() const {
assert(BF != nullptr);

View File

@ -303,9 +303,8 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
}
// Sort targets in a similar way to getBranchData, see Location::operator<
llvm::sort(CSTargets, [](const auto &RHS, const auto &LHS) {
if (RHS.first != LHS.first)
return RHS.first < LHS.first;
return RHS.second.Offset < LHS.second.Offset;
return std::tie(RHS.first, RHS.second.Offset) <
std::tie(LHS.first, LHS.second.Offset);
});
for (auto &KV : CSTargets)
YamlBB.CallSites.push_back(KV.second);