[llvm] [NFC][TableGen] Drop OperandInfo::addField/fields() wrappers and use OperandInfo::Fields instead (PR #195489)

Prerona Chaudhuri via llvm-commits llvm-commits at lists.llvm.org
Sat May 2 15:53:27 PDT 2026


https://github.com/pchaudhuri-nv created https://github.com/llvm/llvm-project/pull/195489

Fields is already a public member; the wrappers added no semantic value beyond a thin storage indirection (and ArrayRef-typed reads). Use Fields directly at all call sites for consistency with the rest of the struct's plain-data style.

>From e774b719aa66c242bde7cc39a28c20d19eecc0e6 Mon Sep 17 00:00:00 2001
From: pchaudhuri-nv <pchaudhuri at nvidia.com>
Date: Sat, 2 May 2026 22:48:14 +0000
Subject: [PATCH] [NFC][TableGen] Drop OperandInfo::addField/fields() wrappers

Fields is already a public member; the wrappers added no semantic value
beyond a thin storage indirection (and ArrayRef-typed reads). Use Fields
directly at all call sites for consistency with the rest of the struct's
plain-data style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply at anthropic.com>
---
 llvm/utils/TableGen/Common/InstructionEncoding.cpp | 10 ++++++----
 llvm/utils/TableGen/Common/InstructionEncoding.h   |  6 ------
 llvm/utils/TableGen/DecoderEmitter.cpp             |  8 ++++----
 3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/llvm/utils/TableGen/Common/InstructionEncoding.cpp b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
index e9c2d93244155..1d36bd6d9f95c 100644
--- a/llvm/utils/TableGen/Common/InstructionEncoding.cpp
+++ b/llvm/utils/TableGen/Common/InstructionEncoding.cpp
@@ -205,7 +205,8 @@ void InstructionEncoding::parseVarLenOperands(const VarLenInst &VLI) {
     if (!OpName.empty()) {
       auto OpSubOpPair = Inst->Operands.parseOperandName(OpName);
       unsigned OpIdx = Inst->Operands.getFlattenedOperandNumber(OpSubOpPair);
-      Operands[OpIdx].addField(CurrBitPos, EncodingSegment.BitWidth, Offset);
+      Operands[OpIdx].Fields.emplace_back(CurrBitPos, EncodingSegment.BitWidth,
+                                          Offset);
       if (!EncodingSegment.CustomDecoder.empty())
         Operands[OpIdx].Decoder = EncodingSegment.CustomDecoder.str();
 
@@ -213,7 +214,8 @@ void InstructionEncoding::parseVarLenOperands(const VarLenInst &VLI) {
       if (TiedReg != -1) {
         unsigned OpIdx = Inst->Operands.getFlattenedOperandNumber(
             {TiedReg, OpSubOpPair.second});
-        Operands[OpIdx].addField(CurrBitPos, EncodingSegment.BitWidth, Offset);
+        Operands[OpIdx].Fields.emplace_back(CurrBitPos,
+                                            EncodingSegment.BitWidth, Offset);
       }
     }
 
@@ -311,10 +313,10 @@ static void addOneOperandFields(const Record *EncodingDef,
     if (I == J)
       ++J;
     else
-      OpInfo.addField(I, J - I, Offset);
+      OpInfo.Fields.emplace_back(I, J - I, Offset);
   }
 
-  if (!OpInfo.InitValue && OpInfo.fields().empty()) {
+  if (!OpInfo.InitValue && OpInfo.Fields.empty()) {
     // We found a field in InstructionEncoding record that corresponds to the
     // named operand, but that field has no constant bits and doesn't contribute
     // to the Inst field. For now, treat that field as if it didn't exist.
diff --git a/llvm/utils/TableGen/Common/InstructionEncoding.h b/llvm/utils/TableGen/Common/InstructionEncoding.h
index d9e70edb0b04e..44b45137b8f8c 100644
--- a/llvm/utils/TableGen/Common/InstructionEncoding.h
+++ b/llvm/utils/TableGen/Common/InstructionEncoding.h
@@ -49,12 +49,6 @@ struct OperandInfo {
   std::optional<uint64_t> InitValue;
 
   OperandInfo(std::string D, bool HCD) : Decoder(D), HasCompleteDecoder(HCD) {}
-
-  void addField(unsigned Base, unsigned Width, unsigned Offset) {
-    Fields.emplace_back(Base, Width, Offset);
-  }
-
-  ArrayRef<EncodingField> fields() const { return Fields; }
 };
 
 /// Represents a parsed InstructionEncoding record or a record derived from it.
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 664c3009ff504..f8ebdfccda46f 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -707,16 +707,16 @@ static void emitBinaryParser(raw_ostream &OS, indent Indent,
     return;
   }
 
-  if (OpInfo.fields().empty()) {
+  if (OpInfo.Fields.empty()) {
     // Only a constant part. The old behavior is to not decode this operand.
     if (IgnoreFullyDefinedOperands)
       return;
     // Initialize `tmp` with the constant part.
     OS << Indent << "tmp = " << format_hex(*OpInfo.InitValue, 0) << ";\n";
-  } else if (OpInfo.fields().size() == 1 && !OpInfo.InitValue.value_or(0)) {
+  } else if (OpInfo.Fields.size() == 1 && !OpInfo.InitValue.value_or(0)) {
     // One variable part and no/zero constant part. Initialize `tmp` with the
     // variable part.
-    auto [Base, Width, Offset] = OpInfo.fields().front();
+    auto [Base, Width, Offset] = OpInfo.Fields.front();
     OS << Indent << "tmp = fieldFromInstruction(insn, " << Base << ", " << Width
        << ')';
     if (Offset)
@@ -727,7 +727,7 @@ static void emitBinaryParser(raw_ostream &OS, indent Indent,
     // insert the variable parts into it.
     OS << Indent << "tmp = " << format_hex(OpInfo.InitValue.value_or(0), 0)
        << ";\n";
-    for (auto [Base, Width, Offset] : OpInfo.fields()) {
+    for (auto [Base, Width, Offset] : OpInfo.Fields) {
       OS << Indent << "tmp |= fieldFromInstruction(insn, " << Base << ", "
          << Width << ')';
       if (Offset)



More information about the llvm-commits mailing list