-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[llvm] Use std::tie to implement comparison functors (NFC) #146197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm] Use std::tie to implement comparison functors (NFC) #146197
Conversation
std::tie clearly expresses the intent while slightly shortening the code.
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) Changesstd::tie clearly expresses the intent while slightly shortening the Full diff: https://github.com/llvm/llvm-project/pull/146197.diff 3 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 09dc7a2944159..4e1f1131b710f 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -289,8 +289,8 @@ struct LineLocation {
LLVM_ABI void serialize(raw_ostream &OS);
bool operator<(const LineLocation &O) const {
- return LineOffset < O.LineOffset ||
- (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
+ return std::tie(LineOffset, Discriminator) <
+ std::tie(O.LineOffset, O.Discriminator);
}
bool operator==(const LineLocation &O) const {
diff --git a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
index 5a3b6433fba78..e152dbf764c97 100644
--- a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
+++ b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
@@ -37,7 +37,7 @@ struct HexagonBlockRanges {
unsigned Sub;
bool operator<(RegisterRef R) const {
- return Reg < R.Reg || (Reg == R.Reg && Sub < R.Sub);
+ return std::tie(Reg, Sub) < std::tie(R.Reg, R.Sub);
}
};
using RegisterSet = std::set<RegisterRef>;
diff --git a/llvm/lib/Target/X86/X86PreTileConfig.cpp b/llvm/lib/Target/X86/X86PreTileConfig.cpp
index f3800d360fdd9..3b4e531f25388 100644
--- a/llvm/lib/Target/X86/X86PreTileConfig.cpp
+++ b/llvm/lib/Target/X86/X86PreTileConfig.cpp
@@ -80,12 +80,12 @@ struct MIRef {
bool operator<(const MIRef &RHS) const {
// Comparison between different BBs happens when inserting a MIRef into set.
// So we compare MBB first to make the insertion happy.
- return MBB < RHS.MBB || (MBB == RHS.MBB && Pos < RHS.Pos);
+ return std::tie(MBB, Pos) < std::tie(RHS.MBB, RHS.Pos);
}
bool operator>(const MIRef &RHS) const {
// Comparison between different BBs happens when inserting a MIRef into set.
// So we compare MBB first to make the insertion happy.
- return MBB > RHS.MBB || (MBB == RHS.MBB && Pos > RHS.Pos);
+ return std::tie(MBB, Pos) > std::tie(RHS.MBB, RHS.Pos);
}
};
|
@llvm/pr-subscribers-backend-hexagon Author: Kazu Hirata (kazutakahirata) Changesstd::tie clearly expresses the intent while slightly shortening the Full diff: https://github.com/llvm/llvm-project/pull/146197.diff 3 Files Affected:
diff --git a/llvm/include/llvm/ProfileData/SampleProf.h b/llvm/include/llvm/ProfileData/SampleProf.h
index 09dc7a2944159..4e1f1131b710f 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -289,8 +289,8 @@ struct LineLocation {
LLVM_ABI void serialize(raw_ostream &OS);
bool operator<(const LineLocation &O) const {
- return LineOffset < O.LineOffset ||
- (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
+ return std::tie(LineOffset, Discriminator) <
+ std::tie(O.LineOffset, O.Discriminator);
}
bool operator==(const LineLocation &O) const {
diff --git a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
index 5a3b6433fba78..e152dbf764c97 100644
--- a/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
+++ b/llvm/lib/Target/Hexagon/HexagonBlockRanges.h
@@ -37,7 +37,7 @@ struct HexagonBlockRanges {
unsigned Sub;
bool operator<(RegisterRef R) const {
- return Reg < R.Reg || (Reg == R.Reg && Sub < R.Sub);
+ return std::tie(Reg, Sub) < std::tie(R.Reg, R.Sub);
}
};
using RegisterSet = std::set<RegisterRef>;
diff --git a/llvm/lib/Target/X86/X86PreTileConfig.cpp b/llvm/lib/Target/X86/X86PreTileConfig.cpp
index f3800d360fdd9..3b4e531f25388 100644
--- a/llvm/lib/Target/X86/X86PreTileConfig.cpp
+++ b/llvm/lib/Target/X86/X86PreTileConfig.cpp
@@ -80,12 +80,12 @@ struct MIRef {
bool operator<(const MIRef &RHS) const {
// Comparison between different BBs happens when inserting a MIRef into set.
// So we compare MBB first to make the insertion happy.
- return MBB < RHS.MBB || (MBB == RHS.MBB && Pos < RHS.Pos);
+ return std::tie(MBB, Pos) < std::tie(RHS.MBB, RHS.Pos);
}
bool operator>(const MIRef &RHS) const {
// Comparison between different BBs happens when inserting a MIRef into set.
// So we compare MBB first to make the insertion happy.
- return MBB > RHS.MBB || (MBB == RHS.MBB && Pos > RHS.Pos);
+ return std::tie(MBB, Pos) > std::tie(RHS.MBB, RHS.Pos);
}
};
|
std::tie clearly expresses the intent while slightly shortening the code.
std::tie clearly expresses the intent while slightly shortening the code.
std::tie clearly expresses the intent while slightly shortening the
code.