[llvm] [TableGen] Extend direct lookup to instruction values in generic tables. (PR #80486)

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 3 19:45:43 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())
----------------
wangpc-pp wrote:

I think we should add a `CodeGenTarget::getInstrToIntMap` (or other names?) to get this instr->int mapping, so that we can reuse these logics and sync with other emittters (like you said, `InstrInfoEmitter::emitEnums`).

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


More information about the llvm-commits mailing list