Skip to content

[BOLT] Use std::tie to Implment operator< (NFC) #139404

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 10, 2025

@llvm/pr-subscribers-bolt

Author: Kazu Hirata (kazutakahirata)

Changes

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

3 Files Affected:

  • (modified) bolt/include/bolt/Passes/FrameAnalysis.h (+2-3)
  • (modified) bolt/include/bolt/Passes/PAuthGadgetScanner.h (+1-3)
  • (modified) bolt/include/bolt/Profile/DataReader.h (+1-7)
diff --git a/bolt/include/bolt/Passes/FrameAnalysis.h b/bolt/include/bolt/Passes/FrameAnalysis.h
index 44b54d4ed45d4..d71c338bdcc37 100644
--- a/bolt/include/bolt/Passes/FrameAnalysis.h
+++ b/bolt/include/bolt/Passes/FrameAnalysis.h
@@ -10,6 +10,7 @@
 #define BOLT_PASSES_FRAMEANALYSIS_H
 
 #include "bolt/Passes/StackPointerTracking.h"
+#include <tuple>
 
 namespace llvm {
 namespace bolt {
@@ -53,9 +54,7 @@ struct ArgInStackAccess {
   uint8_t Size;
 
   bool operator<(const ArgInStackAccess &RHS) const {
-    if (StackOffset != RHS.StackOffset)
-      return StackOffset < RHS.StackOffset;
-    return Size < RHS.Size;
+    return std::tie(StackOffset, Size) < std::tie(RHS.StackOffset, RHS.Size);
   }
 };
 
diff --git a/bolt/include/bolt/Passes/PAuthGadgetScanner.h b/bolt/include/bolt/Passes/PAuthGadgetScanner.h
index ee69337637da3..66251e195822c 100644
--- a/bolt/include/bolt/Passes/PAuthGadgetScanner.h
+++ b/bolt/include/bolt/Passes/PAuthGadgetScanner.h
@@ -43,9 +43,7 @@ struct MCInstInBBReference {
     return BB == RHS.BB && BBIndex == RHS.BBIndex;
   }
   bool operator<(const MCInstInBBReference &RHS) const {
-    if (BB != RHS.BB)
-      return BB < RHS.BB;
-    return BBIndex < RHS.BBIndex;
+    return std::tie(BB, BBIndex) < std::tie(RHS.BB, RHS.BBIndex);
   }
   operator MCInst &() const {
     assert(BB != nullptr);
diff --git a/bolt/include/bolt/Profile/DataReader.h b/bolt/include/bolt/Profile/DataReader.h
index 314dcc9115586..4765eb28d53ca 100644
--- a/bolt/include/bolt/Profile/DataReader.h
+++ b/bolt/include/bolt/Profile/DataReader.h
@@ -90,13 +90,7 @@ struct BranchInfo {
   }
 
   bool operator<(const BranchInfo &RHS) const {
-    if (From < RHS.From)
-      return true;
-
-    if (From == RHS.From)
-      return (To < RHS.To);
-
-    return false;
+    return std::tie(From, To) < std::tie(RHS.From, RHS.To);
   }
 
   /// Merges branch and misprediction counts of \p BI with those of this object.

Copy link
Contributor

@aaupov aaupov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@kazutakahirata kazutakahirata merged commit 94c0a0b into llvm:main May 10, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_operator_less_bolt branch May 10, 2025 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants