Skip to content

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Sep 4, 2025

The name is most interesting and if you really need the number you can use the name to find the entry in the enum or use the first field of the table row.

…s in GenInstrInfo.inc.

The name is most interesting and if you really need the number
you can use the name to find the entry in the enum or use the
first field of the table row.
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2025

@llvm/pr-subscribers-tablegen

Author: Craig Topper (topperc)

Changes

The name is most interesting and if you really need the number you can use the name to find the entry in the enum or use the first field of the table row.


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

2 Files Affected:

  • (modified) llvm/test/TableGen/def-multiple-operands.td (+1-1)
  • (modified) llvm/utils/TableGen/InstrInfoEmitter.cpp (+6-6)
diff --git a/llvm/test/TableGen/def-multiple-operands.td b/llvm/test/TableGen/def-multiple-operands.td
index b747c58907505..5d215056920e8 100644
--- a/llvm/test/TableGen/def-multiple-operands.td
+++ b/llvm/test/TableGen/def-multiple-operands.td
@@ -24,7 +24,7 @@ def Reg3Opnd : Operand<OtherVT> {
 // CHECK: archInstrTable {{.* = \{}}
 // CHECK: {{\{}}
 // CHECK: {{\{}} [[ID:[0-9]+]], 4, 3, 13, {{.+\}, \/\/}}
-// CHECK-SAME: Inst #[[ID]] = InstA
+// CHECK-SAME: InstA
 def InstA : Instruction {
   let Namespace = "MyNS";
   let Size = 13;
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 26d93fc13c9ba..193087ec38d0c 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -760,8 +760,9 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
   OS << "  };\n"
      << "  static constexpr " << getMinimalTypeForRange(FeatureBitsets.size())
      << " RequiredFeaturesRefs[] = {\n";
-  unsigned InstIdx = 0;
-  for (const CodeGenInstruction *Inst : Target.getInstructions()) {
+  ArrayRef<const CodeGenInstruction *> NumberedInstructions =
+      Target.getInstructions();
+  for (const CodeGenInstruction *Inst : NumberedInstructions) {
     OS << "    CEFBS";
     unsigned NumPredicates = 0;
     for (const Record *Predicate :
@@ -774,11 +775,10 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
     }
     if (!NumPredicates)
       OS << "_None";
-    OS << ", // " << Inst->TheDef->getName() << " = " << InstIdx << '\n';
-    InstIdx++;
+    OS << ", // " << Inst->TheDef->getName() << '\n';
   }
   OS << "  };\n\n"
-     << "  assert(Opcode < " << InstIdx << ");\n"
+     << "  assert(Opcode < " << NumberedInstructions.size() << ");\n"
      << "  return FeatureBitsets[RequiredFeaturesRefs[Opcode]];\n"
      << "}\n\n";
 
@@ -1284,7 +1284,7 @@ void InstrInfoEmitter::emitRecord(
   OS.write_hex(Value);
   OS << "ULL";
 
-  OS << " },  // Inst #" << Num << " = " << Inst.TheDef->getName() << '\n';
+  OS << " },  // " << Inst.TheDef->getName() << '\n';
 }
 
 // emitEnums - Print out enum values for all of the instructions.

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 9337344 into llvm:main Sep 4, 2025
11 checks passed
@topperc topperc deleted the pr/tablgen-comments branch September 4, 2025 20:27
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