[llvm] [TableGen] Extend direct lookup to instruction values in generic tables. (PR #80486)
Jason Eckhardt via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 4 13:45:49 PST 2024
================
@@ -646,11 +671,23 @@ void SearchableTableEmitter::collectTableEntries(
if (auto RecordTy = dyn_cast<RecordRecTy>(Field.RecType)) {
if (IntrinsicClass && RecordTy->isSubClassOf(IntrinsicClass))
Field.IsIntrinsic = true;
- else if (InstructionClass && RecordTy->isSubClassOf(InstructionClass))
+ else if (InstructionClass && RecordTy->isSubClassOf(InstructionClass)) {
Field.IsInstruction = true;
+ SawInstructionField = true;
+ }
}
}
+ // Build instruction-to-int map to check for contiguous instruction values.
+ // These are the same values emitted by InstrInfoEmitter. Do this on demand
+ // only after it is known that there are definitely instruction fields.
+ if (SawInstructionField && InstrEnumValueMap.empty()) {
+ CodeGenTarget Target(Records);
+ unsigned Num = 0;
+ for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue())
----------------
nvjle wrote:
As you suggested, I have moved this map into `CodeGenTarget::InstrToIntMap` and added a lookup method `CodeGenTarget::getInstrIntValue`. The map is now populated in `CodeGenTarget::computeInstrsByEnum` right after the sort that creates the order in the first place.
Overall this is cleaner and simplified the patch as well. Thanks again for the suggestions.
In a follow-up patch, as you alluded to, I could use the new query in `InstrInfoEmitter::emitEnums` (and elsewhere if applicable) to reuse/sync the logic.
https://github.com/llvm/llvm-project/pull/80486
More information about the llvm-commits
mailing list