@@ -192,20 +192,22 @@ void CodeGenFormat::run(raw_ostream &o) {
192192 {
193193 ConstTable OpFields (" const MCFormatField *" , " OpFields" );
194194 ConstTable FieldRanges (" const MCFormatField * const *" , " FieldRanges" );
195+ ConstTable SlotsFields (" SlotFieldPair" , " SlotsFields" );
195196 ConstTable Formats (FormatClassEmitted, " Formats" );
196197 for (const TGInstrLayout &Inst : InstFormats) {
197- Inst.emitFormat (FieldsHierarchy, Formats, OpFields, FieldRanges);
198+ Inst.emitFormat (FieldsHierarchy, Formats, OpFields, FieldRanges,
199+ SlotsFields);
198200 Formats.next ();
199201 }
200202
201203 Formats.finish ();
202204 OpFields.finish ();
203- FieldRanges.mark (" Sentinel" );
204- FieldRanges << OpFields.refNext ();
205+ SlotsFields.finish ();
205206 FieldRanges.finish ();
206207
207208 o << OpFields;
208209 o << FieldRanges;
210+ o << SlotsFields;
209211 o << Formats;
210212 o << " #endif // GET_FORMATS_FORMATS_DEFS\n\n " ;
211213 }
@@ -672,8 +674,8 @@ void TGInstrLayout::emitOpcodeFormatIndex(raw_ostream &o) const {
672674}
673675
674676void TGInstrLayout::emitFormat (ConstTable &FieldsHierarchy, ConstTable &o,
675- ConstTable &OpFields,
676- ConstTable &FieldRanges ) const {
677+ ConstTable &OpFields, ConstTable &FieldRanges,
678+ ConstTable &SlotsFields ) const {
677679 o << " // " << Target << " ::" << InstrName
678680 << " - Index : " << std::to_string (InstrID) << " \n "
679681 << " {\n "
@@ -682,51 +684,49 @@ void TGInstrLayout::emitFormat(ConstTable &FieldsHierarchy, ConstTable &o,
682684 << " " << (IsComposite ? " true" : " false" ) << " /* isComposite */,\n "
683685 << " " << (IsMultipleSlotOptions ? " true" : " false" )
684686 << " /* hasMultipleSlotOptions */,\n "
685- << " " << " /* Slots - Fields mapper */\n "
686- << " {" ;
687+ << " /* Slots - Fields mapper */\n " ;
687688
688689 const std::string TargetClassName = Target + SlotsRegistry.GenSlotKindName ;
690+ SlotsFields.mark (InstrName.c_str ());
689691
690- bool firstIter = true ;
691692 for (const auto &SlotField : slots ()) {
692- if (!firstIter)
693- o << " , " ;
694- else
695- firstIter = false ;
696- o << " { " ;
697- o << TargetClassName << " ::" << SlotField->SlotClass ->getEnumerationString ()
698- << " , " ;
699- o << FieldsHierarchy.absRef (SlotField->EmissionID );
700- o << " }" ;
693+ SlotsFields << " { " ;
694+ SlotsFields << TargetClassName
695+ << " ::" << SlotField->SlotClass ->getEnumerationString () << " , " ;
696+ SlotsFields << FieldsHierarchy.absRef (SlotField->EmissionID );
697+ SlotsFields << " }" ;
698+ SlotsFields.next ();
701699 }
702- o << " } ,\n " ;
700+ o << " " << SlotsFields. arrayRef () << " ,\n " ;
703701
704702 // Group every field by their operand index (if they have one)
705703 // i.e. { 0 : {field0, field1}, 1 : {field2}}...
706704 std::map<unsigned , SmallVector<TGFieldLayout *>> FieldOpIndexMap;
707705 // Keep track of the maximum operand index
708- unsigned MaxIdx = 0 ;
706+ unsigned NumOperands = 0 ;
709707 for (auto *OperandField : operands ()) {
710- unsigned Idx = OperandField->getMCOperandIndex ();
711- FieldOpIndexMap[Idx ].push_back (OperandField);
712- MaxIdx = std::max (MaxIdx, Idx );
708+ unsigned OperandIdx = OperandField->getMCOperandIndex ();
709+ FieldOpIndexMap[OperandIdx ].push_back (OperandField);
710+ NumOperands = std::max (NumOperands, OperandIdx );
713711 }
714712
715713 o << " /* MCOperand - Slots mapper */\n " ;
716714 OpFields.mark (InstrName.c_str ());
717715 FieldRanges.mark (InstrName.c_str ());
718- for (unsigned Idx = 0 ; Idx <= MaxIdx; Idx++) {
719- FieldRanges << OpFields.ref (Idx);
716+ unsigned OpFieldIdx = 0 ;
717+ for (unsigned OperandIdx = 0 ; OperandIdx <= NumOperands; OperandIdx++) {
718+ FieldRanges << OpFields.ref (OpFieldIdx);
720719 FieldRanges.next ();
721- auto It = FieldOpIndexMap.find (Idx );
720+ auto It = FieldOpIndexMap.find (OperandIdx );
722721 if (It != FieldOpIndexMap.end ()) {
723722 for (auto &MO : It->second ) {
724723 OpFields << " " << FieldsHierarchy.absRef (MO ->EmissionID );
725724 OpFields.next ();
725+ OpFieldIdx++;
726726 }
727727 }
728728 }
729- o << " {" << FieldRanges.ref (0 ) << " , " << MaxIdx + 1 << " },\n " ;
729+ o << " {" << FieldRanges.ref (0 ) << " , " << NumOperands + 1 << " },\n " ;
730730
731731 auto *RootField = *fields ().begin ();
732732 o << " " << FieldsHierarchy.absRef (RootField->EmissionID ) << " \n "
0 commit comments