[llvm] [BOLT] Use std::tie to implement operator< (NFC) (PR #143560)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 08:55:29 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/143560
std::tie facilitates lexicographical comparisons through std::tuple's
built-in operator<.
>From a1baacb4f2ff3f0f7326b7ab76bb27d957c23a2e Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 9 Jun 2025 13:03:15 -0700
Subject: [PATCH] [BOLT] Use std::tie to implement operator< (NFC)
std::tie facilitates lexicographical comparisons through std::tuple's
built-in operator<.
---
bolt/include/bolt/Core/BinaryBasicBlock.h | 5 ++---
bolt/include/bolt/Passes/PAuthGadgetScanner.h | 4 +---
bolt/lib/Profile/YAMLProfileWriter.cpp | 5 ++---
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/bolt/include/bolt/Core/BinaryBasicBlock.h b/bolt/include/bolt/Core/BinaryBasicBlock.h
index 25cccc4edecf6..629f0ce8314dc 100644
--- a/bolt/include/bolt/Core/BinaryBasicBlock.h
+++ b/bolt/include/bolt/Core/BinaryBasicBlock.h
@@ -52,9 +52,8 @@ class BinaryBasicBlock {
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);
}
};
diff --git a/bolt/include/bolt/Passes/PAuthGadgetScanner.h b/bolt/include/bolt/Passes/PAuthGadgetScanner.h
index 98a49df862ebd..c6b9cc2eb4b9c 100644
--- a/bolt/include/bolt/Passes/PAuthGadgetScanner.h
+++ b/bolt/include/bolt/Passes/PAuthGadgetScanner.h
@@ -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);
diff --git a/bolt/lib/Profile/YAMLProfileWriter.cpp b/bolt/lib/Profile/YAMLProfileWriter.cpp
index f1fe45f21a0f6..0ae67a4d35595 100644
--- a/bolt/lib/Profile/YAMLProfileWriter.cpp
+++ b/bolt/lib/Profile/YAMLProfileWriter.cpp
@@ -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);
More information about the llvm-commits
mailing list