[Mlir-commits] [mlir] [NFC][MLIR][TableGen] Use ArrayRef instead of const vector reference (PR #162016)

Rahul Joshi llvmlistbot at llvm.org
Sun Oct 5 07:24:02 PDT 2025


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/162016

None

>From db91cbef3900a08a69480928dc6b99b8aa51390f Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sun, 5 Oct 2025 07:22:42 -0700
Subject: [PATCH] [NFC][MLIR][TableGen] Use ArrayRef instead of const vector
 reference

---
 mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp |  4 ++--
 mlir/tools/mlir-tblgen/EnumsGen.cpp         | 10 ++++------
 mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 13 +++++--------
 mlir/tools/mlir-tblgen/TosaUtilsGen.cpp     |  2 +-
 4 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
index 06ef396b9b21d..cd41e6d20d70e 100644
--- a/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
+++ b/mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
@@ -1166,7 +1166,7 @@ getAllCppAttrConstraints(const RecordKeeper &records) {
 
 /// Emit the declarations for the given constraints, of the form:
 /// `bool <constraintCppFunctionName>(<parameterTypeName> <parameterName>);`
-static void emitConstraintDecls(const std::vector<Constraint> &constraints,
+static void emitConstraintDecls(ArrayRef<Constraint> constraints,
                                 raw_ostream &os, StringRef parameterTypeName,
                                 StringRef parameterName) {
   static const char *const constraintDecl = "bool {0}({1} {2});\n";
@@ -1192,7 +1192,7 @@ static void emitAttrConstraintDecls(const RecordKeeper &records,
 ///   return (<condition>); }`
 /// where `<condition>` is the condition template with the `self` variable
 /// replaced with the `selfName` parameter.
-static void emitConstraintDefs(const std::vector<Constraint> &constraints,
+static void emitConstraintDefs(ArrayRef<Constraint> constraints,
                                raw_ostream &os, StringRef parameterTypeName,
                                StringRef selfName) {
   static const char *const constraintDef = R"(
diff --git a/mlir/tools/mlir-tblgen/EnumsGen.cpp b/mlir/tools/mlir-tblgen/EnumsGen.cpp
index d4d32f5885971..d55ad482f02c2 100644
--- a/mlir/tools/mlir-tblgen/EnumsGen.cpp
+++ b/mlir/tools/mlir-tblgen/EnumsGen.cpp
@@ -46,8 +46,7 @@ static std::string makeIdentifier(StringRef str) {
 
 static void emitEnumClass(const Record &enumDef, StringRef enumName,
                           StringRef underlyingType, StringRef description,
-                          const std::vector<EnumCase> &enumerants,
-                          raw_ostream &os) {
+                          ArrayRef<EnumCase> enumerants, raw_ostream &os) {
   os << "// " << description << "\n";
   os << "enum class " << enumName;
 
@@ -55,14 +54,13 @@ static void emitEnumClass(const Record &enumDef, StringRef enumName,
     os << " : " << underlyingType;
   os << " {\n";
 
-  for (const auto &enumerant : enumerants) {
+  for (const EnumCase &enumerant : enumerants) {
     auto symbol = makeIdentifier(enumerant.getSymbol());
     auto value = enumerant.getValue();
-    if (value >= 0) {
+    if (value >= 0)
       os << formatv("  {0} = {1},\n", symbol, value);
-    } else {
+    else
       os << formatv("  {0},\n", symbol);
-    }
   }
   os << "};\n\n";
 }
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index c3420d433523a..6895a04f85518 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -4801,11 +4801,9 @@ void OpOperandAdaptorEmitter::emitDef(
 }
 
 /// Emit the class declarations or definitions for the given op defs.
-static void
-emitOpClasses(const RecordKeeper &records,
-              const std::vector<const Record *> &defs, raw_ostream &os,
-              const StaticVerifierFunctionEmitter &staticVerifierEmitter,
-              bool emitDecl) {
+static void emitOpClasses(
+    const RecordKeeper &records, ArrayRef<const Record *> defs, raw_ostream &os,
+    const StaticVerifierFunctionEmitter &staticVerifierEmitter, bool emitDecl) {
   if (defs.empty())
     return;
 
@@ -4840,11 +4838,10 @@ emitOpClasses(const RecordKeeper &records,
 
 /// Emit the declarations for the provided op classes.
 static void emitOpClassDecls(const RecordKeeper &records,
-                             const std::vector<const Record *> &defs,
-                             raw_ostream &os) {
+                             ArrayRef<const Record *> defs, raw_ostream &os) {
   // First emit forward declaration for each class, this allows them to refer
   // to each others in traits for example.
-  for (auto *def : defs) {
+  for (const Record *def : defs) {
     Operator op(*def);
     NamespaceEmitter emitter(os, op.getCppNamespace());
     std::string comments = tblgen::emitSummaryAndDescComments(
diff --git a/mlir/tools/mlir-tblgen/TosaUtilsGen.cpp b/mlir/tools/mlir-tblgen/TosaUtilsGen.cpp
index c92954600f411..dc8cc58498230 100644
--- a/mlir/tools/mlir-tblgen/TosaUtilsGen.cpp
+++ b/mlir/tools/mlir-tblgen/TosaUtilsGen.cpp
@@ -1,4 +1,4 @@
-//===- TosaUtilsGen.cpp - Tosa utility generator -===//
+//===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.



More information about the Mlir-commits mailing list