Skip to content

[TableGen][NFC] Replace hardcoded opcode numbering. #81065

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2024

Conversation

nvjle
Copy link
Contributor

@nvjle nvjle commented Feb 8, 2024

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

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

llvmbot commented Feb 8, 2024

@llvm/pr-subscribers-llvm-globalisel

Author: Jason Eckhardt (nvjle)

Changes

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


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

2 Files Affected:

  • (modified) llvm/utils/TableGen/GlobalISelMatchTable.cpp (+1-2)
  • (modified) llvm/utils/TableGen/InstrInfoEmitter.cpp (+3-2)
diff --git a/llvm/utils/TableGen/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/GlobalISelMatchTable.cpp
index 051c536f113f7..f7166ead9adc3 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 b2250c0cf9897..dbc5c22f23879 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";

@nvjle
Copy link
Contributor Author

nvjle commented Feb 8, 2024

Hi @wangpc-pp (or anyone else interested)-- this NFC patch just updates a couple instances of the hardcoded enum value setting with CodeGenTarget::getInstrIntValue (introduced in PR #80486) to eliminate duplicate code. If someone would kindly commit on my behalf, thank you.

@wangpc-pp
Copy link
Contributor

LGTM.
@topperc Can you help landing this? I'm on holidays and away from my laptop now.

for (const CodeGenInstruction *I : Target.getInstructionsByEnumValue())
OpcodeValues[I] = OpcodeValue++;
OpcodeValues[I] = Target.getInstrIntValue(I->TheDef);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this map a candidate for deletion now? It looks like it might be redundant with the new map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this map a candidate for deletion now? It looks like it might be redundant with the new map?

At first glance it does appear so, but I'm not entirely sure-- I'll need to look more carefully as a follow-up task (i.e., on better sleep).

Copy link
Collaborator

@topperc topperc 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 567d304 into llvm:main Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants