[llvm] [llvm] Use std::tie to implement operator< (NFC) (PR #143728)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 11 08:26:48 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/143728
std::tie facilitates lexicographical comparisons through std::tuple's
built-in operator<.
>From 7ef40e8724cb24fa06b340be19b3fc3ae78a4612 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 10 Jun 2025 20:25:21 -0700
Subject: [PATCH] [llvm] Use std::tie to implement operator< (NFC)
std::tie facilitates lexicographical comparisons through std::tuple's
built-in operator<.
---
.../ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h | 12 +++---------
llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp | 8 ++------
2 files changed, 5 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
index 24b03a058981a..89b20978c40e6 100644
--- a/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
+++ b/llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
@@ -202,15 +202,9 @@ class RelocationValueRef {
IsStubThumb == Other.IsStubThumb;
}
inline bool operator<(const RelocationValueRef &Other) const {
- if (SectionID != Other.SectionID)
- return SectionID < Other.SectionID;
- if (Offset != Other.Offset)
- return Offset < Other.Offset;
- if (Addend != Other.Addend)
- return Addend < Other.Addend;
- if (IsStubThumb != Other.IsStubThumb)
- return IsStubThumb < Other.IsStubThumb;
- return SymbolName < Other.SymbolName;
+ return std::tie(SectionID, Offset, Addend, IsStubThumb, SymbolName) <
+ std::tie(Other.SectionID, Other.Offset, Other.Addend,
+ Other.IsStubThumb, Other.SymbolName);
}
};
diff --git a/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp b/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
index f38e7b879e5f0..5dde47ab3de57 100644
--- a/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonConstExtenders.cpp
@@ -253,7 +253,7 @@ namespace {
bool operator!=(Register R) const { return !operator==(R); }
bool operator<(Register R) const {
// For std::map.
- return Reg < R.Reg || (Reg == R.Reg && Sub < R.Sub);
+ return std::tie(Reg, Sub) < std::tie(R.Reg, R.Sub);
}
llvm::Register Reg;
unsigned Sub = 0;
@@ -298,11 +298,7 @@ namespace {
return !operator==(Ex);
}
bool operator<(const ExtExpr &Ex) const {
- if (Rs != Ex.Rs)
- return Rs < Ex.Rs;
- if (S != Ex.S)
- return S < Ex.S;
- return !Neg && Ex.Neg;
+ return std::tie(Rs, S, Neg) < std::tie(Ex.Rs, Ex.S, Ex.Neg);
}
};
More information about the llvm-commits
mailing list