Skip to content

Commit 998230d

Browse files
kazutakahiratatomtor
authored andcommitted
[BOLT] Use std::tie to implement operator< (NFC) (llvm#143560)
std::tie facilitates lexicographical comparisons through std::tuple's built-in operator<.
1 parent acd4a0f commit 998230d

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

bolt/include/bolt/Core/BinaryBasicBlock.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ class BinaryBasicBlock {
5252
uint64_t MispredictedCount; /// number of branches mispredicted
5353

5454
bool operator<(const BinaryBranchInfo &Other) const {
55-
return (Count < Other.Count) ||
56-
(Count == Other.Count &&
57-
MispredictedCount < Other.MispredictedCount);
55+
return std::tie(Count, MispredictedCount) <
56+
std::tie(Other.Count, Other.MispredictedCount);
5857
}
5958
};
6059

bolt/include/bolt/Passes/PAuthGadgetScanner.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ struct MCInstInBFReference {
7777
return BF == RHS.BF && Offset == RHS.Offset;
7878
}
7979
bool operator<(const MCInstInBFReference &RHS) const {
80-
if (BF != RHS.BF)
81-
return BF < RHS.BF;
82-
return Offset < RHS.Offset;
80+
return std::tie(BF, Offset) < std::tie(RHS.BF, RHS.Offset);
8381
}
8482
operator MCInst &() const {
8583
assert(BF != nullptr);

bolt/lib/Profile/YAMLProfileWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ YAMLProfileWriter::convert(const BinaryFunction &BF, bool UseDFS,
303303
}
304304
// Sort targets in a similar way to getBranchData, see Location::operator<
305305
llvm::sort(CSTargets, [](const auto &RHS, const auto &LHS) {
306-
if (RHS.first != LHS.first)
307-
return RHS.first < LHS.first;
308-
return RHS.second.Offset < LHS.second.Offset;
306+
return std::tie(RHS.first, RHS.second.Offset) <
307+
std::tie(LHS.first, LHS.second.Offset);
309308
});
310309
for (auto &KV : CSTargets)
311310
YamlBB.CallSites.push_back(KV.second);

0 commit comments

Comments
 (0)