diff --git a/llvm/test/TableGen/get-operand-type.td b/llvm/test/TableGen/get-operand-type.td --- a/llvm/test/TableGen/get-operand-type.td +++ b/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 diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp --- a/llvm/utils/TableGen/InstrInfoEmitter.cpp +++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp @@ -383,9 +383,11 @@ if (!NumberedInstructions.empty()) { std::vector OperandOffsets; std::vector OperandRecords; + std::map 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 << ", ";