Skip to content

[llvm] Use std::tie to implement operator< (NFC) #139487

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

Merged

Conversation

kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented May 12, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-debuginfo

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/139487.diff

3 Files Affected:

  • (modified) llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h (+2-5)
  • (modified) llvm/include/llvm/MC/MCContext.h (+5-12)
  • (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+1-3)
diff --git a/llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h b/llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
index 187642257cc52..19ec35c947c19 100644
--- a/llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
+++ b/llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
@@ -234,11 +234,8 @@ inline bool operator!=(const FunctionInfo &LHS, const FunctionInfo &RHS) {
 /// the GSYM file.
 inline bool operator<(const FunctionInfo &LHS, const FunctionInfo &RHS) {
   // First sort by address range
-  if (LHS.Range != RHS.Range)
-    return LHS.Range < RHS.Range;
-  if (LHS.Inline == RHS.Inline)
-    return LHS.OptLineTable < RHS.OptLineTable;
-  return LHS.Inline < RHS.Inline;
+  return std::tie(LHS.Range, LHS.Inline, LHS.OptLineTable) <
+         std::tie(RHS.Range, RHS.Inline, RHS.OptLineTable);
 }
 
 raw_ostream &operator<<(raw_ostream &OS, const FunctionInfo &R);
diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h
index e97c890ce9135..73c6d57f107f7 100644
--- a/llvm/include/llvm/MC/MCContext.h
+++ b/llvm/include/llvm/MC/MCContext.h
@@ -259,13 +259,9 @@ class MCContext {
           SelectionKey(SelectionKey), UniqueID(UniqueID) {}
 
     bool operator<(const COFFSectionKey &Other) const {
-      if (SectionName != Other.SectionName)
-        return SectionName < Other.SectionName;
-      if (GroupName != Other.GroupName)
-        return GroupName < Other.GroupName;
-      if (SelectionKey != Other.SelectionKey)
-        return SelectionKey < Other.SelectionKey;
-      return UniqueID < Other.UniqueID;
+      return std::tie(SectionName, GroupName, SelectionKey, UniqueID) <
+             std::tie(Other.SectionName, Other.GroupName, Other.SelectionKey,
+                      Other.UniqueID);
     }
   };
 
@@ -279,11 +275,8 @@ class MCContext {
         : SectionName(SectionName), GroupName(GroupName), UniqueID(UniqueID) {}
 
     bool operator<(const WasmSectionKey &Other) const {
-      if (SectionName != Other.SectionName)
-        return SectionName < Other.SectionName;
-      if (GroupName != Other.GroupName)
-        return GroupName < Other.GroupName;
-      return UniqueID < Other.UniqueID;
+      return std::tie(SectionName, GroupName, UniqueID) <
+             std::tie(Other.SectionName, Other.GroupName, Other.UniqueID);
     }
   };
 
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index a72c1d329e199..8b843634600be 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -10909,9 +10909,7 @@ struct AAPotentialValuesImpl : AAPotentialValues {
       return II.I == I && II.S == S;
     };
     bool operator<(const ItemInfo &II) const {
-      if (I == II.I)
-        return S < II.S;
-      return I < II.I;
+      return std::tie(I, S) < std::tie(II.I, II.S);
     };
   };
 

@kazutakahirata kazutakahirata merged commit 1ecba5b into llvm:main May 12, 2025
14 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_operator_less_llvm branch May 12, 2025 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants