-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
[TableGen][NFC] Replace hardcoded opcode numbering. #81065
Conversation
This patch uses the recently introduced CodeGenTarget::getInstrIntValue to replace hardcoded opcode enum value numbering in a few places.
@llvm/pr-subscribers-llvm-globalisel Author: Jason Eckhardt (nvjle) ChangesThis 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:
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";
|
Hi @wangpc-pp (or anyone else interested)-- this NFC patch just updates a couple instances of the hardcoded enum value setting with |
LGTM. |
for (const CodeGenInstruction *I : Target.getInstructionsByEnumValue()) | ||
OpcodeValues[I] = OpcodeValue++; | ||
OpcodeValues[I] = Target.getInstrIntValue(I->TheDef); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This patch uses the recently introduced CodeGenTarget::getInstrIntValue to replace hardcoded opcode enum value numbering in a few places.