[llvm] [NFC][TableGen] Minor cleanup in SequenceToOffsetTable (PR #178564)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 30 07:54:02 PST 2026


https://github.com/jurahul updated https://github.com/llvm/llvm-project/pull/178564

>From d3e5d9630fdf941afa969c028e8230a4beed3691 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Wed, 28 Jan 2026 18:17:51 -0800
Subject: [PATCH 1/2] [NFC][TableGen] Minor cleanup in SequenceToOffsetTable

Use `auto` for iterators, range for loop in `layout` and rename
`Entries` to a more canonical `Size`.
---
 .../TableGen/Basic/SequenceToOffsetTable.h    | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h b/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
index 1cd18b7184a57..aca4682d820e5 100644
--- a/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
+++ b/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
@@ -69,8 +69,8 @@ class SequenceToOffsetTable {
   // True if `layout` method was called.
   bool IsLaidOut = false;
 
-  // Entries in the final table, or 0 before layout was called.
-  unsigned Entries = 0;
+  // Size of the final table, or 0 before layout was called.
+  unsigned Size = 0;
 
   // isSuffix - Returns true if A is a suffix of B.
   static bool isSuffix(const SeqT &A, const SeqT &B) {
@@ -85,7 +85,7 @@ class SequenceToOffsetTable {
   /// This must be called before layout().
   void add(const SeqT &Seq) {
     assert(!IsLaidOut && "Cannot call add() after layout()");
-    typename SeqMap::iterator I = Seqs.lower_bound(Seq);
+    auto I = Seqs.lower_bound(Seq);
 
     // If SeqMap contains a sequence that has Seq as a suffix, I will be
     // pointing to it.
@@ -103,7 +103,7 @@ class SequenceToOffsetTable {
 
   unsigned size() const {
     assert(IsLaidOut && "Call layout() before size()");
-    return Entries;
+    return Size;
   }
 
   /// layout - Computes the final table layout.
@@ -112,18 +112,17 @@ class SequenceToOffsetTable {
     IsLaidOut = true;
 
     // Lay out the table in Seqs iteration order.
-    for (typename SeqMap::iterator I = Seqs.begin(), E = Seqs.end(); I != E;
-         ++I) {
-      I->second = Entries;
+    for (auto &Entry : Seqs) {
+      Entry.second = Size;
       // Include space for a terminator.
-      Entries += I->first.size() + Terminator.has_value();
+      Size += Entry.first.size() + Terminator.has_value();
     }
   }
 
   /// get - Returns the offset of Seq in the final table.
   unsigned get(const SeqT &Seq) const {
     assert(IsLaidOut && "Call layout() before get()");
-    typename SeqMap::const_iterator I = Seqs.lower_bound(Seq);
+    auto I = Seqs.lower_bound(Seq);
     assert(I != Seqs.end() && isSuffix(Seq, I->first) &&
            "get() called with sequence that wasn't added first");
     return I->second + (I->first.size() - Seq.size());
@@ -179,7 +178,7 @@ class SequenceToOffsetTable {
     }
 
     // Print a dummy element if the array would be empty otherwise.
-    if (!Entries) {
+    if (Size == 0) {
       OS << "  /* dummy */ ";
       Print(OS, ElemT());
       OS << '\n';

>From 7ae7fd456656e63078281039ee6f07d5323f5449 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Fri, 30 Jan 2026 07:53:24 -0800
Subject: [PATCH 2/2] Review feedback

---
 llvm/utils/TableGen/Basic/SequenceToOffsetTable.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h b/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
index aca4682d820e5..e1740ca10d88a 100644
--- a/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
+++ b/llvm/utils/TableGen/Basic/SequenceToOffsetTable.h
@@ -112,10 +112,10 @@ class SequenceToOffsetTable {
     IsLaidOut = true;
 
     // Lay out the table in Seqs iteration order.
-    for (auto &Entry : Seqs) {
-      Entry.second = Size;
+    for (auto &[Seq, Offset] : Seqs) {
+      Offset = Size;
       // Include space for a terminator.
-      Size += Entry.first.size() + Terminator.has_value();
+      Size += Seq.size() + Terminator.has_value();
     }
   }
 



More information about the llvm-commits mailing list