Skip to content

[NFC][TableGen] Use ArrayRef instead of const vector reference #145323

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 2 commits into from
Jun 24, 2025

Conversation

jurahul
Copy link
Contributor

@jurahul jurahul commented Jun 23, 2025

  • Use ArrayRef instead of SmallVector reference in a few places.
  • Drop redundant llvm:: in a few places.

@jurahul jurahul force-pushed the tablegen_use_arrayref branch from 185701b to f545eea Compare June 23, 2025 12:59
@jurahul jurahul force-pushed the tablegen_use_arrayref branch from f545eea to 6dfce04 Compare June 23, 2025 15:26
@jurahul jurahul marked this pull request as ready for review June 23, 2025 19:07
@llvmbot llvmbot added tablegen llvm:SelectionDAG SelectionDAGISel as well labels Jun 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 23, 2025

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-tablegen

Author: Rahul Joshi (jurahul)

Changes
  • Use ArrayRef instead of SmallVector reference in a few places.
  • Drop redundant llvm:: in a few places.

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

7 Files Affected:

  • (modified) llvm/include/llvm/CodeGen/SelectionDAGISel.h (+3-3)
  • (modified) llvm/lib/TableGen/StringMatcher.cpp (+5-4)
  • (modified) llvm/lib/TableGen/StringToOffsetTable.cpp (+3-3)
  • (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+1-1)
  • (modified) llvm/utils/TableGen/Common/CodeGenSchedule.cpp (+5-5)
  • (modified) llvm/utils/TableGen/DAGISelMatcherEmitter.cpp (+1-1)
  • (modified) llvm/utils/TableGen/DAGISelMatcherOpt.cpp (+2-2)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGISel.h b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
index 375d2f31e2835..5241a51dd8cd8 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGISel.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGISel.h
@@ -435,9 +435,9 @@ class SelectionDAGISel {
   /// It runs node predicate number PredNo and returns true if it succeeds or
   /// false if it fails.  The number is a private implementation detail to the
   /// code tblgen produces.
-  virtual bool CheckNodePredicateWithOperands(
-      SDValue Op, unsigned PredNo,
-      const SmallVectorImpl<SDValue> &Operands) const {
+  virtual bool
+  CheckNodePredicateWithOperands(SDValue Op, unsigned PredNo,
+                                 ArrayRef<SDValue> Operands) const {
     llvm_unreachable("Tblgen should generate the implementation of this!");
   }
 
diff --git a/llvm/lib/TableGen/StringMatcher.cpp b/llvm/lib/TableGen/StringMatcher.cpp
index b85849e40bb5e..eb9036625796e 100644
--- a/llvm/lib/TableGen/StringMatcher.cpp
+++ b/llvm/lib/TableGen/StringMatcher.cpp
@@ -11,7 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/TableGen/StringMatcher.h"
-#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cassert>
@@ -23,14 +23,15 @@
 using namespace llvm;
 
 /// FindFirstNonCommonLetter - Find the first character in the keys of the
-/// string pairs that is not shared across the whole set of strings.  All
+/// string pairs that is not shared across the whole set of strings. All
 /// strings are assumed to have the same length.
 static unsigned
 FindFirstNonCommonLetter(ArrayRef<const StringMatcher::StringPair *> Matches) {
   assert(!Matches.empty());
   for (auto [Idx, Letter] : enumerate(Matches[0]->first)) {
-    // Check to see if `Letter` is the same across the set.
-    for (const StringMatcher::StringPair *Match : Matches)
+    // Check to see if `Letter` is the same across the set. Since the letter is
+    // from `Matches[0]`, we can skip `Matches[0]` in the loop below.
+    for (const StringMatcher::StringPair *Match : Matches.drop_front())
       if (Match->first[Idx] != Letter)
         return Idx;
   }
diff --git a/llvm/lib/TableGen/StringToOffsetTable.cpp b/llvm/lib/TableGen/StringToOffsetTable.cpp
index d73b5749ad7d5..0db3f35f1c4b3 100644
--- a/llvm/lib/TableGen/StringToOffsetTable.cpp
+++ b/llvm/lib/TableGen/StringToOffsetTable.cpp
@@ -44,8 +44,8 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS, const Twine &Name,
   bool UseChars = !EmitLongStrLiterals && AggregateString.size() > (64 * 1024);
   OS << (UseChars ? "{\n" : "\n");
 
-  llvm::ListSeparator LineSep(UseChars ? ",\n" : "\n");
-  llvm::SmallVector<StringRef> Strings(split(AggregateString, '\0'));
+  ListSeparator LineSep(UseChars ? ",\n" : "\n");
+  SmallVector<StringRef> Strings(split(AggregateString, '\0'));
   // We should always have an empty string at the start, and because these are
   // null terminators rather than separators, we'll have one at the end as
   // well. Skip the end one.
@@ -63,7 +63,7 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS, const Twine &Name,
       continue;
     }
 
-    llvm::ListSeparator CharSep(", ");
+    ListSeparator CharSep(", ");
     for (char C : Str) {
       OS << CharSep << "'";
       OS.write_escaped(StringRef(&C, 1));
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 3a4ca1b451567..86be0d12d7b8a 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -3187,7 +3187,7 @@ bool TreePattern::InferAllTypes(
           return true;
         }
 
-        const SmallVectorImpl<TreePatternNode *> &InNodes = InIter->second;
+        ArrayRef<TreePatternNode *> InNodes = InIter->second;
 
         // The input types should be fully resolved by now.
         for (TreePatternNode *Node : Nodes) {
diff --git a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
index af7e43929bcf0..a93b5be01754f 100644
--- a/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenSchedule.cpp
@@ -1292,8 +1292,8 @@ class PredTransitions {
 
   PredTransitions(CodeGenSchedModels &sm) : SchedModels(sm) {}
 
-  bool substituteVariantOperand(const SmallVectorImpl<unsigned> &RWSeq,
-                                bool IsRead, unsigned StartIdx);
+  bool substituteVariantOperand(ArrayRef<unsigned> RWSeq, bool IsRead,
+                                unsigned StartIdx);
 
   bool substituteVariants(const PredTransition &Trans);
 
@@ -1526,8 +1526,8 @@ void PredTransitions::pushVariant(const TransVariant &VInfo, bool IsRead) {
 // operand. StartIdx is an index into TransVec where partial results
 // starts. RWSeq must be applied to all transitions between StartIdx and the end
 // of TransVec.
-bool PredTransitions::substituteVariantOperand(
-    const SmallVectorImpl<unsigned> &RWSeq, bool IsRead, unsigned StartIdx) {
+bool PredTransitions::substituteVariantOperand(ArrayRef<unsigned> RWSeq,
+                                               bool IsRead, unsigned StartIdx) {
   bool Subst = false;
   // Visit each original RW within the current sequence.
   for (unsigned int RWI : RWSeq) {
@@ -1591,7 +1591,7 @@ bool PredTransitions::substituteVariants(const PredTransition &Trans) {
 }
 
 static void addSequences(CodeGenSchedModels &SchedModels,
-                         const SmallVectorImpl<SmallVector<unsigned, 4>> &Seqs,
+                         ArrayRef<SmallVector<unsigned, 4>> Seqs,
                          IdxVec &Result, bool IsRead) {
   for (const auto &S : Seqs)
     if (!S.empty())
diff --git a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
index 49c33dc5ca149..d3fba6a92357a 100644
--- a/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherEmitter.cpp
@@ -1158,7 +1158,7 @@ void MatcherTableEmitter::EmitPredicateFunctions(raw_ostream &OS) {
   EmitNodePredicatesFunction(
       NodePredicatesWithOperands,
       "CheckNodePredicateWithOperands(SDValue Op, unsigned PredNo, "
-      "const SmallVectorImpl<SDValue> &Operands) const",
+      "ArrayRef<SDValue> Operands) const",
       OS);
 
   // Emit CompletePattern matchers.
diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
index 05bca75bcd4ef..8d8189983270e 100644
--- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp
@@ -282,8 +282,8 @@ static void ContractNodes(std::unique_ptr<Matcher> &InputMatcherPtr,
 #endif
 
         if (ResultsMatch) {
-          const SmallVectorImpl<MVT::SimpleValueType> &VTs = EN->getVTList();
-          const SmallVectorImpl<unsigned> &Operands = EN->getOperandList();
+          ArrayRef<MVT::SimpleValueType> VTs = EN->getVTList();
+          ArrayRef<unsigned> Operands = EN->getOperandList();
           MatcherPtr->reset(new MorphNodeToMatcher(
               EN->getInstruction(), VTs, Operands, EN->hasChain(),
               EN->hasInGlue(), EN->hasOutGlue(), EN->hasMemRefs(),

@jurahul jurahul merged commit fba63e3 into llvm:main Jun 24, 2025
11 checks passed
@jurahul jurahul deleted the tablegen_use_arrayref branch June 24, 2025 14:30
DrSergei pushed a commit to DrSergei/llvm-project that referenced this pull request Jun 24, 2025
…145323)

- Use `ArrayRef` instead of `SmallVector` reference in a few places.
- Drop redundant `llvm::` in a few places.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well tablegen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants