[llvm] [TableGen][NFC] Replace hardcoded opcode numbering. (PR #81065)

Jason Eckhardt via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 7 16:44:46 PST 2024


https://github.com/nvjle created https://github.com/llvm/llvm-project/pull/81065

This patch uses the recently introduced CodeGenTarget::getInstrIntValue to replace hardcoded opcode enum value numbering in a few places.

>From 3608a7b9e169b30ce31731db81286cb6386b733a Mon Sep 17 00:00:00 2001
From: Jason Eckhardt <jeckhardt at nvidia.com>
Date: Wed, 7 Feb 2024 17:56:02 -0600
Subject: [PATCH] [TableGen][NFC] Replace hardcoded opcode numbering.

This patch uses the recently introduced CodeGenTarget::getInstrIntValue
to replace hardcoded opcode enum value numbering in a few places.
---
 llvm/utils/TableGen/GlobalISelMatchTable.cpp | 3 +--
 llvm/utils/TableGen/InstrInfoEmitter.cpp     | 5 +++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/utils/TableGen/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/GlobalISelMatchTable.cpp
index 051c536f113f7b..f7166ead9adc3d 100644
--- a/llvm/utils/TableGen/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/GlobalISelMatchTable.cpp
@@ -1399,9 +1399,8 @@ void InstructionOpcodeMatcher::initOpcodeValuesMap(
     const CodeGenTarget &Target) {
   OpcodeValues.clear();
 
-  unsigned OpcodeValue = 0;
   for (const CodeGenInstruction *I : Target.getInstructionsByEnumValue())
-    OpcodeValues[I] = OpcodeValue++;
+    OpcodeValues[I] = Target.getInstrIntValue(I->TheDef);
 }
 
 MatchTableRecord InstructionOpcodeMatcher::getValue() const {
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index b2250c0cf9897c..dbc5c22f238793 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -1284,8 +1284,9 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
   OS << "  enum {\n";
   unsigned Num = 0;
   for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue())
-    OS << "    " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n";
-  OS << "    INSTRUCTION_LIST_END = " << Num << "\n";
+    OS << "    " << Inst->TheDef->getName()
+       << "\t= " << (Num = Target.getInstrIntValue(Inst->TheDef)) << ",\n";
+  OS << "    INSTRUCTION_LIST_END = " << Num + 1 << "\n";
   OS << "  };\n\n";
   OS << "} // end namespace " << Namespace << "\n";
   OS << "} // end namespace llvm\n";



More information about the llvm-commits mailing list