@@ -76,6 +76,8 @@ static std::vector<Record*> GetOperandInfo(const CodeGenInstruction &Inst) {
76
76
77
77
// run - Emit the main instruction description records for the target...
78
78
void InstrInfoEmitter::run (std::ostream &OS) {
79
+ GatherItinClasses ();
80
+
79
81
EmitSourceFileHeader (" Target Instruction Descriptors" , OS);
80
82
OS << " namespace llvm {\n\n " ;
81
83
@@ -168,7 +170,13 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
168
170
OS << Inst.TheDef ->getName ();
169
171
else
170
172
OS << Inst.Name ;
171
- OS << " \" ,\t " << NumOperands << " , -1, 0, false, 0, 0, 0, 0" ;
173
+
174
+ unsigned ItinClass = !IsItineraries ? 0 :
175
+ ItinClassNumber (Inst.TheDef ->getValueAsDef (" Itinerary" )->getName ());
176
+
177
+ OS << " \" ,\t " << NumOperands << " , -1, 0, false, 0, 0, "
178
+ << ItinClass
179
+ << " , 0" ;
172
180
173
181
// Emit all of the target indepedent flags...
174
182
if (Inst.isReturn ) OS << " |M_RET_FLAG" ;
@@ -222,6 +230,30 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
222
230
OS << " }, // Inst #" << Num << " = " << Inst.TheDef ->getName () << " \n " ;
223
231
}
224
232
233
+ struct LessRecord {
234
+ bool operator ()(const Record *Rec1, const Record *Rec2) const {
235
+ return Rec1->getName () < Rec2->getName ();
236
+ }
237
+ };
238
+ void InstrInfoEmitter::GatherItinClasses () {
239
+ std::vector<Record*> DefList =
240
+ Records.getAllDerivedDefinitions (" InstrItinClass" );
241
+ IsItineraries = !DefList.empty ();
242
+
243
+ if (!IsItineraries) return ;
244
+
245
+ sort (DefList.begin (), DefList.end (), LessRecord ());
246
+
247
+ for (unsigned i = 0 , N = DefList.size (); i < N; i++) {
248
+ Record *Def = DefList[i];
249
+ ItinClassMap[Def->getName ()] = i + 1 ;
250
+ }
251
+ }
252
+
253
+ unsigned InstrInfoEmitter::ItinClassNumber (std::string ItinName) {
254
+ return ItinClassMap[ItinName];
255
+ }
256
+
225
257
void InstrInfoEmitter::emitShiftedValue (Record *R, StringInit *Val,
226
258
IntInit *ShiftInt, std::ostream &OS) {
227
259
if (Val == 0 || ShiftInt == 0 )
0 commit comments