Skip to content

Commit 0433df1

Browse files
committed
Emit itinerary class in instruction info.
llvm-svn: 24122
1 parent 3763a50 commit 0433df1

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

llvm/utils/TableGen/InstrInfoEmitter.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ static std::vector<Record*> GetOperandInfo(const CodeGenInstruction &Inst) {
7676

7777
// run - Emit the main instruction description records for the target...
7878
void InstrInfoEmitter::run(std::ostream &OS) {
79+
GatherItinClasses();
80+
7981
EmitSourceFileHeader("Target Instruction Descriptors", OS);
8082
OS << "namespace llvm {\n\n";
8183

@@ -168,7 +170,13 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
168170
OS << Inst.TheDef->getName();
169171
else
170172
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";
172180

173181
// Emit all of the target indepedent flags...
174182
if (Inst.isReturn) OS << "|M_RET_FLAG";
@@ -222,6 +230,30 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
222230
OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
223231
}
224232

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+
225257
void InstrInfoEmitter::emitShiftedValue(Record *R, StringInit *Val,
226258
IntInit *ShiftInt, std::ostream &OS) {
227259
if (Val == 0 || ShiftInt == 0)

llvm/utils/TableGen/InstrInfoEmitter.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ struct CodeGenInstruction;
2828

2929
class InstrInfoEmitter : public TableGenBackend {
3030
RecordKeeper &Records;
31+
bool IsItineraries;
32+
std::map<std::string, unsigned> ItinClassMap;
33+
3134
public:
32-
InstrInfoEmitter(RecordKeeper &R) : Records(R) {}
35+
InstrInfoEmitter(RecordKeeper &R) : Records(R), IsItineraries(false) {}
3336

3437
// run - Output the instruction set description, returning true on failure.
3538
void run(std::ostream &OS);
@@ -44,6 +47,8 @@ class InstrInfoEmitter : public TableGenBackend {
4447
std::map<std::vector<Record*>, unsigned> &EL,
4548
std::map<std::vector<Record*>, unsigned> &OpInfo,
4649
std::ostream &OS);
50+
void GatherItinClasses();
51+
unsigned ItinClassNumber(std::string ItinName);
4752
void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
4853
std::ostream &OS);
4954
};

0 commit comments

Comments
 (0)