Skip to content

[TableGen] Inline a helper function that didn't seem necessary. NFC #123440

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
merged 1 commit into from
Jan 18, 2025

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Jan 18, 2025

The function just called find_if and converted the iterator to an index. The caller then had to check the index being non-zero to know if the find succeeded.

Seems better to just do the find and distance in the caller.

The function just called find_if and converted the iterator to
an index. The caller then had to check the index being non-zero to
know if the find succeeded.

Seems better to just do the find and distance in the caller.
@llvmbot
Copy link
Member

llvmbot commented Jan 18, 2025

@llvm/pr-subscribers-tablegen

Author: Craig Topper (topperc)

Changes

The function just called find_if and converted the iterator to an index. The caller then had to check the index being non-zero to know if the find succeeded.

Seems better to just do the find and distance in the caller.


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

2 Files Affected:

  • (modified) llvm/utils/TableGen/Common/CodeGenSchedule.cpp (+7-16)
  • (modified) llvm/utils/TableGen/Common/CodeGenSchedule.h (-1)
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index a5ca060533bcef..1d1de884990855 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -809,18 +809,6 @@ void CodeGenSchedModels::expandRWSeqForProc(
   }
 }
 
-// Find the existing SchedWrite that models this sequence of writes.
-unsigned CodeGenSchedModels::findRWForSequence(ArrayRef<unsigned> Seq,
-                                               bool IsRead) {
-  std::vector<CodeGenSchedRW> &RWVec = IsRead ? SchedReads : SchedWrites;
-
-  auto I = find_if(RWVec, [Seq](CodeGenSchedRW &RW) {
-    return ArrayRef(RW.Sequence) == Seq;
-  });
-  // Index zero reserved for invalid RW.
-  return I == RWVec.end() ? 0 : std::distance(RWVec.begin(), I);
-}
-
 /// Add this ReadWrite if it doesn't already exist.
 unsigned CodeGenSchedModels::findOrInsertRW(ArrayRef<unsigned> Seq,
                                             bool IsRead) {
@@ -828,11 +816,14 @@ unsigned CodeGenSchedModels::findOrInsertRW(ArrayRef<unsigned> Seq,
   if (Seq.size() == 1)
     return Seq.back();
 
-  unsigned Idx = findRWForSequence(Seq, IsRead);
-  if (Idx)
-    return Idx;
-
   std::vector<CodeGenSchedRW> &RWVec = IsRead ? SchedReads : SchedWrites;
+
+  auto I = find_if(RWVec, [Seq](CodeGenSchedRW &RW) {
+    return ArrayRef(RW.Sequence) == Seq;
+  });
+  if (I != RWVec.end())
+    return std::distance(RWVec.begin(), I);
+
   unsigned RWIdx = RWVec.size();
   CodeGenSchedRW SchedRW(RWIdx, IsRead, Seq, genRWName(Seq, IsRead));
   RWVec.push_back(SchedRW);
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.h b/llvm/utils/TableGen/Common/CodeGenSchedule.h
index f43c856b274ce8..d47c03514b155f 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.h
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.h
@@ -592,7 +592,6 @@ class CodeGenSchedModels {
   void collectSchedRW();
 
   std::string genRWName(ArrayRef<unsigned> Seq, bool IsRead);
-  unsigned findRWForSequence(ArrayRef<unsigned> Seq, bool IsRead);
 
   void collectSchedClasses();
 

Copy link
Contributor

@s-barannikov s-barannikov left a comment

Choose a reason for hiding this comment

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

LGTM

@topperc topperc merged commit 9cd12b5 into llvm:main Jan 18, 2025
10 checks passed
@topperc topperc deleted the pr/findRWForSequence branch January 18, 2025 05:41
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.

4 participants