[llvm] [NFC][InstrInfoEmitter] Include location of inst definition in comment (PR #156927)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 4 13:52:54 PDT 2025


================
@@ -1302,18 +1305,29 @@ void InstrInfoEmitter::emitEnums(
 
   OS << "namespace llvm::" << Namespace << " {\n";
 
+  auto II = llvm::max_element(
+      NumberedInstructions,
+      [](const CodeGenInstruction *InstA, const CodeGenInstruction *InstB) {
+        return InstA->getName().size() < InstB->getName().size();
+      });
+  size_t MaxNameSize = (*II)->getName().size();
+
   OS << "  enum {\n";
-  for (const CodeGenInstruction *Inst : NumberedInstructions)
-    OS << "    " << Inst->TheDef->getName()
-       << "\t= " << Target.getInstrIntValue(Inst->TheDef) << ",\n";
+  for (const CodeGenInstruction *Inst : NumberedInstructions) {
+    OS << "    " << Inst->TheDef->getName();
+    OS.PadToColumn(MaxNameSize + 5);
----------------
s-barannikov wrote:

(nit) Since you know max name size beforehand, this could be simplified to

```suggestion
    OS << "    " << left_justify(Inst->getName(), MaxNameSize) << " = " ...
```

without the need to use `formatted_raw_ostream`.
I never tried it myself.


https://github.com/llvm/llvm-project/pull/156927


More information about the llvm-commits mailing list