@@ -61,7 +61,8 @@ class InstrInfoEmitter {
61
61
void run (raw_ostream &OS);
62
62
63
63
private:
64
- void emitEnums (raw_ostream &OS);
64
+ void emitEnums (raw_ostream &OS,
65
+ ArrayRef<const CodeGenInstruction *> NumberedInstructions);
65
66
66
67
typedef std::vector<std::string> OperandInfoTy;
67
68
typedef std::vector<OperandInfoTy> OperandInfoListTy;
@@ -117,10 +118,9 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
117
118
// either case into a list of operands for this op.
118
119
std::vector<CGIOperandList::OperandInfo> OperandList;
119
120
120
- // This might be a multiple operand thing. Targets like X86 have
121
- // registers in their multi-operand operands. It may also be an anonymous
122
- // operand, which has a single operand, but no declared class for the
123
- // operand.
121
+ // This might be a multiple operand thing. Targets like X86 have registers
122
+ // in their multi-operand operands. It may also be an anonymous operand,
123
+ // which has a single operand, but no declared class for the operand.
124
124
const DagInit *MIOI = Op.MIOperandInfo ;
125
125
126
126
if (!MIOI || MIOI->getNumArgs () == 0 ) {
@@ -135,8 +135,9 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
135
135
}
136
136
}
137
137
138
- for (unsigned j = 0 , e = OperandList.size (); j != e; ++j) {
139
- const Record *OpR = OperandList[j].Rec ;
138
+ for (const auto &[OpInfo, Constraint] :
139
+ zip_equal (OperandList, Op.Constraints )) {
140
+ const Record *OpR = OpInfo.Rec ;
140
141
std::string Res;
141
142
142
143
if (OpR->isSubClassOf (" RegisterOperand" ))
@@ -179,12 +180,11 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
179
180
// Fill in constraint info.
180
181
Res += " , " ;
181
182
182
- const CGIOperandList::ConstraintInfo &Constraint = Op.Constraints [j];
183
- if (Constraint.isNone ())
183
+ if (Constraint.isNone ()) {
184
184
Res += " 0" ;
185
- else if (Constraint.isEarlyClobber ())
185
+ } else if (Constraint.isEarlyClobber ()) {
186
186
Res += " MCOI_EARLY_CLOBBER" ;
187
- else {
187
+ } else {
188
188
assert (Constraint.isTied ());
189
189
Res += " MCOI_TIED_TO(" + utostr (Constraint.getTiedOperand ()) + " )" ;
190
190
}
@@ -329,7 +329,7 @@ void InstrInfoEmitter::emitOperandNameMappings(
329
329
OS << " return -1;\n " ;
330
330
}
331
331
OS << " }\n " ;
332
- OS << " } // end namespace llvm::" << Namespace << " \n " ;
332
+ OS << " } // end namespace llvm::" << Namespace << ' \n ' ;
333
333
OS << " #endif //GET_INSTRINFO_NAMED_OPS\n\n " ;
334
334
}
335
335
@@ -445,7 +445,7 @@ void InstrInfoEmitter::emitOperandTypeMappings(
445
445
446
446
OS << " return OpcodeOperandTypes[Offsets[Opcode] + OpIdx];\n " ;
447
447
OS << " }\n " ;
448
- OS << " } // end namespace llvm::" << Namespace << " \n " ;
448
+ OS << " } // end namespace llvm::" << Namespace << ' \n ' ;
449
449
OS << " #endif // GET_INSTRINFO_OPERAND_TYPE\n\n " ;
450
450
451
451
OS << " #ifdef GET_INSTRINFO_MEM_OPERAND_SIZE\n " ;
@@ -468,7 +468,7 @@ void InstrInfoEmitter::emitOperandTypeMappings(
468
468
OS << " return " << Size << " ;\n\n " ;
469
469
}
470
470
OS << " }\n }\n " ;
471
- OS << " } // end namespace llvm::" << Namespace << " \n " ;
471
+ OS << " } // end namespace llvm::" << Namespace << ' \n ' ;
472
472
OS << " #endif // GET_INSTRINFO_MEM_OPERAND_SIZE\n\n " ;
473
473
}
474
474
@@ -527,8 +527,7 @@ void InstrInfoEmitter::emitLogicalOperandSizeMappings(
527
527
for (; i < static_cast <int >(LogicalOpListSize); ++i) {
528
528
OS << " 0, " ;
529
529
}
530
- OS << " }, " ;
531
- OS << " \n " ;
530
+ OS << " }, \n " ;
532
531
}
533
532
OS << " };\n " ;
534
533
@@ -556,7 +555,7 @@ void InstrInfoEmitter::emitLogicalOperandSizeMappings(
556
555
OS << " return S;\n " ;
557
556
OS << " }\n " ;
558
557
559
- OS << " } // end namespace llvm::" << Namespace << " \n " ;
558
+ OS << " } // end namespace llvm::" << Namespace << ' \n ' ;
560
559
OS << " #endif // GET_INSTRINFO_LOGICAL_OPERAND_SIZE_MAP\n\n " ;
561
560
}
562
561
@@ -705,7 +704,7 @@ void InstrInfoEmitter::emitFeatureVerifier(raw_ostream &OS,
705
704
}
706
705
if (!NumPredicates)
707
706
OS << " _None" ;
708
- OS << " , // " << Inst->TheDef ->getName () << " = " << InstIdx << " \n " ;
707
+ OS << " , // " << Inst->TheDef ->getName () << " = " << InstIdx << ' \n ' ;
709
708
InstIdx++;
710
709
}
711
710
OS << " };\n\n "
@@ -811,10 +810,14 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
811
810
Timer.startTimer (" Analyze DAG patterns" );
812
811
813
812
emitSourceFileHeader (" Target Instruction Enum Values and Descriptors" , OS);
814
- emitEnums (OS);
815
813
816
814
const CodeGenTarget &Target = CDP.getTargetInfo ();
817
- const std::string &TargetName = std::string (Target.getName ());
815
+ ArrayRef<const CodeGenInstruction *> NumberedInstructions =
816
+ Target.getInstructionsByEnumValue ();
817
+
818
+ emitEnums (OS, NumberedInstructions);
819
+
820
+ StringRef TargetName = Target.getName ();
818
821
const Record *InstrInfo = Target.getInstructionSet ();
819
822
820
823
// Collect all of the operand info records.
@@ -824,9 +827,6 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
824
827
unsigned OperandInfoSize =
825
828
CollectOperandInfo (OperandInfoList, OperandInfoMap);
826
829
827
- ArrayRef<const CodeGenInstruction *> NumberedInstructions =
828
- Target.getInstructionsByEnumValue ();
829
-
830
830
// Collect all of the instruction's implicit uses and defs.
831
831
// Also collect which features are enabled by instructions to control
832
832
// emission of various mappings.
@@ -882,11 +882,11 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
882
882
883
883
OS << " extern const " << TargetName << " InstrTable " << TargetName
884
884
<< " Descs = {\n {\n " ;
885
- SequenceToOffsetTable<std::string > InstrNames;
885
+ SequenceToOffsetTable<StringRef > InstrNames;
886
886
unsigned Num = NumberedInstructions.size ();
887
887
for (const CodeGenInstruction *Inst : reverse (NumberedInstructions)) {
888
888
// Keep a list of the instruction names.
889
- InstrNames.add (std::string ( Inst->TheDef ->getName () ));
889
+ InstrNames.add (Inst->TheDef ->getName ());
890
890
// Emit the record into the table.
891
891
emitRecord (*Inst, --Num, InstrInfo, EmittedLists, OperandInfoMap, OS);
892
892
}
@@ -922,7 +922,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
922
922
// Newline every eight entries.
923
923
if (Num % 8 == 0 )
924
924
OS << " \n " ;
925
- OS << InstrNames.get (std::string ( Inst->TheDef ->getName () )) << " U, " ;
925
+ OS << InstrNames.get (Inst->TheDef ->getName ()) << " U, " ;
926
926
++Num;
927
927
}
928
928
OS << " \n };\n\n " ;
@@ -995,7 +995,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
995
995
OS << " #ifdef GET_INSTRINFO_HEADER\n " ;
996
996
OS << " #undef GET_INSTRINFO_HEADER\n " ;
997
997
998
- std::string ClassName = TargetName + " GenInstrInfo" ;
998
+ Twine ClassName = TargetName + " GenInstrInfo" ;
999
999
OS << " namespace llvm {\n " ;
1000
1000
OS << " struct " << ClassName << " : public TargetInstrInfo {\n "
1001
1001
<< " explicit " << ClassName
@@ -1010,7 +1010,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
1010
1010
OS << " #ifdef GET_INSTRINFO_HELPER_DECLS\n " ;
1011
1011
OS << " #undef GET_INSTRINFO_HELPER_DECLS\n\n " ;
1012
1012
emitTIIHelperMethods (OS, TargetName, /* ExpandDefinition = */ false );
1013
- OS << " \n " ;
1013
+ OS << ' \n ' ;
1014
1014
OS << " #endif // GET_INSTRINFO_HELPER_DECLS\n\n " ;
1015
1015
1016
1016
OS << " #ifdef GET_INSTRINFO_HELPERS\n " ;
@@ -1209,11 +1209,13 @@ void InstrInfoEmitter::emitRecord(
1209
1209
OS.write_hex (Value);
1210
1210
OS << " ULL" ;
1211
1211
1212
- OS << " }, // Inst #" << Num << " = " << Inst.TheDef ->getName () << " \n " ;
1212
+ OS << " }, // Inst #" << Num << " = " << Inst.TheDef ->getName () << ' \n ' ;
1213
1213
}
1214
1214
1215
1215
// emitEnums - Print out enum values for all of the instructions.
1216
- void InstrInfoEmitter::emitEnums (raw_ostream &OS) {
1216
+ void InstrInfoEmitter::emitEnums (
1217
+ raw_ostream &OS,
1218
+ ArrayRef<const CodeGenInstruction *> NumberedInstructions) {
1217
1219
OS << " #ifdef GET_INSTRINFO_ENUM\n " ;
1218
1220
OS << " #undef GET_INSTRINFO_ENUM\n " ;
1219
1221
@@ -1226,23 +1228,22 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
1226
1228
OS << " namespace llvm::" << Namespace << " {\n " ;
1227
1229
1228
1230
OS << " enum {\n " ;
1229
- unsigned Num = 0 ;
1230
- for (const CodeGenInstruction *Inst : Target.getInstructionsByEnumValue ())
1231
+ for (const CodeGenInstruction *Inst : NumberedInstructions)
1231
1232
OS << " " << Inst->TheDef ->getName ()
1232
- << " \t = " << (Num = Target.getInstrIntValue (Inst->TheDef ) ) << " ,\n " ;
1233
- OS << " INSTRUCTION_LIST_END = " << Num + 1 << " \n " ;
1233
+ << " \t = " << Target.getInstrIntValue (Inst->TheDef ) << " ,\n " ;
1234
+ OS << " INSTRUCTION_LIST_END = " << NumberedInstructions. size () << ' \n ' ;
1234
1235
OS << " };\n\n " ;
1235
- OS << " } // end namespace llvm::" << Namespace << " \n " ;
1236
+ OS << " } // end namespace llvm::" << Namespace << ' \n ' ;
1236
1237
OS << " #endif // GET_INSTRINFO_ENUM\n\n " ;
1237
1238
1238
1239
OS << " #ifdef GET_INSTRINFO_SCHED_ENUM\n " ;
1239
1240
OS << " #undef GET_INSTRINFO_SCHED_ENUM\n " ;
1240
1241
OS << " namespace llvm::" << Namespace << " ::Sched {\n\n " ;
1241
1242
OS << " enum {\n " ;
1242
- Num = 0 ;
1243
- for (const auto &Class : SchedModels. explicit_classes ( ))
1244
- OS << " " << Class.Name << " \t = " << Num++ << " ,\n " ;
1245
- OS << " SCHED_LIST_END = " << Num << " \n " ;
1243
+ auto ExplictClasses = SchedModels. explicit_classes () ;
1244
+ for (const auto &[Idx, Class] : enumerate(ExplictClasses ))
1245
+ OS << " " << Class.Name << " \t = " << Idx << " ,\n " ;
1246
+ OS << " SCHED_LIST_END = " << ExplictClasses. size () << ' \n ' ;
1246
1247
OS << " };\n " ;
1247
1248
OS << " } // end namespace llvm::" << Namespace << " ::Sched\n " ;
1248
1249
0 commit comments