[llvm] [TableGen] Implement getOperandIdxName (PR #154944)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 22 19:03:48 PDT 2025


================
@@ -223,17 +223,104 @@ void InstrInfoEmitter::EmitOperandInfo(raw_ostream &OS,
   }
 }
 
+static void emitGetInstructionIndexForOpLookup(
+    raw_ostream &OS, const MapVector<SmallVector<int>, unsigned> &OperandMap,
+    ArrayRef<unsigned> InstructionIndex) {
+  StringRef Type = OperandMap.size() <= UINT8_MAX + 1 ? "uint8_t" : "uint16_t";
+  OS << "LLVM_READONLY\n";
+  OS << "static " << Type
+     << " getInstructionIndexForOpLookup(uint16_t Opcode) {\n";
+  OS << "  static constexpr " << Type << " InstructionIndex[] = {";
+  for (auto [TableIndex, Entry] : enumerate(InstructionIndex))
+    OS << (TableIndex % 16 == 0 ? "\n    " : " ") << Entry << ',';
+  OS << "\n  };\n";
+  OS << "  return InstructionIndex[Opcode];\n";
+  OS << "}\n";
----------------
arsenm wrote:

```suggestion
  OS << "\n  };\n"
              "  return InstructionIndex[Opcode];\n"
              "}\n";
```

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


More information about the llvm-commits mailing list