[PATCH] D127931: [TableGen] Emit instruction name in INSTRINFO_OPERAND_TYPE

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 19 11:48:23 PDT 2022


Amir updated this revision to Diff 438208.
Amir added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127931/new/

https://reviews.llvm.org/D127931

Files:
  llvm/test/TableGen/get-operand-type.td
  llvm/utils/TableGen/InstrInfoEmitter.cpp


Index: llvm/utils/TableGen/InstrInfoEmitter.cpp
===================================================================
--- llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -383,9 +383,11 @@
   if (!NumberedInstructions.empty()) {
     std::vector<int> OperandOffsets;
     std::vector<Record *> OperandRecords;
+    std::map<int, StringRef> OffsetToInst;
     int CurrentOffset = 0;
     for (const CodeGenInstruction *Inst : NumberedInstructions) {
       OperandOffsets.push_back(CurrentOffset);
+      OffsetToInst.insert({CurrentOffset, Inst->TheDef->getName()});
       for (const auto &Op : Inst->Operands) {
         const DagInit *MIOI = Op.MIOperandInfo;
         if (!MIOI || MIOI->getNumArgs() == 0) {
@@ -407,9 +409,12 @@
            "Too many operands for offset table");
     OS << ((OperandRecords.size() <= UINT16_MAX) ? "  const uint16_t"
                                                  : "  const uint32_t");
-    OS << " Offsets[] = {\n";
-    for (int I = 0, E = OperandOffsets.size(); I != E; ++I)
-      OS << "    " << OperandOffsets[I] << ",\n";
+    OS << " Offsets[] = {";
+    for (int I = 0, E = OperandOffsets.size(); I != E; ++I) {
+      if (OffsetToInst.find(I) != OffsetToInst.end())
+        OS << "\n    /* " << OffsetToInst[I] << " */\n   ";
+      OS << " " << OperandOffsets[I] << ",";
+    }
     OS << "  };\n";
 
     // Add an entry for the end so that we don't need to special case it below.
@@ -419,22 +424,24 @@
     // Size the signed integer operand type to save space.
     assert(EnumVal <= INT16_MAX &&
            "Too many operand types for operand types table");
+    OS << "\n  using namespace OpTypes;\n";
     OS << ((EnumVal <= INT8_MAX) ? "  const int8_t" : "  const int16_t");
-    OS << " OpcodeOperandTypes[] = {\n    ";
-    for (int I = 0, E = OperandRecords.size(), CurOffset = 1; I != E; ++I) {
+    OS << " OpcodeOperandTypes[] = {";
+    for (int I = 0, E = OperandRecords.size(), CurOffset = 0; I != E; ++I) {
       // We print each Opcode's operands in its own row.
       if (I == OperandOffsets[CurOffset]) {
         OS << "\n    ";
-        // If there are empty rows, mark them with an empty comment.
-        while (OperandOffsets[++CurOffset] == I)
-          OS << "/**/\n    ";
+        if (OffsetToInst.find(I) != OffsetToInst.end())
+          OS << "/* " << OffsetToInst[I] << " */\n    ";
+        // Skip over empty rows.
+        while (OperandOffsets[++CurOffset] == I);
       }
       Record *OpR = OperandRecords[I];
       if ((OpR->isSubClassOf("Operand") ||
            OpR->isSubClassOf("RegisterOperand") ||
            OpR->isSubClassOf("RegisterClass")) &&
           !OpR->isAnonymous())
-        OS << "OpTypes::" << OpR->getName();
+        OS << OpR->getName();
       else
         OS << -1;
       OS << ", ";
Index: llvm/test/TableGen/get-operand-type.td
===================================================================
--- llvm/test/TableGen/get-operand-type.td
+++ llvm/test/TableGen/get-operand-type.td
@@ -46,7 +46,10 @@
 }
 
 // CHECK: #ifdef GET_INSTRINFO_OPERAND_TYPE
-// CHECK:        OpTypes::OpA, OpTypes::OpB, OpTypes::i32imm,
-// CHECK-NEXT:   OpTypes::i32imm, -1,
-// CHECK-NEXT:   OpTypes::RegClass, OpTypes::RegOp,
+// CHECK:        /* InstA */
+// CHECK-NEXT:   OpA, OpB, i32imm,
+// CHECK-NEXT:   /* InstB */
+// CHECK-NEXT:   i32imm, -1,
+// CHECK-NEXT:   /* InstC */
+// CHECK-NEXT:   RegClass, RegOp,
 // CHECK: #endif // GET_INSTRINFO_OPERAND_TYPE


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127931.438208.patch
Type: text/x-patch
Size: 3514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220619/ac0a8958/attachment.bin>


More information about the llvm-commits mailing list