Skip to content

Commit 3763a50

Browse files
committed
Generate cpu to itinerary map.
llvm-svn: 24121
1 parent 14ada0f commit 3763a50

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

llvm/utils/TableGen/SubtargetEmitter.cpp

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// This tablegen backend emits subtarget enumerations.
10+
// This tablegen backend emits subtarget enumerations. The format is in a state
11+
// flux and will be tightened up when integration to scheduling is complete.
1112
//
1213
//===----------------------------------------------------------------------===//
1314

@@ -62,7 +63,7 @@ void SubtargetEmitter::Enumeration(std::ostream &OS,
6263
// If bit flags then emit expression (1 << i)
6364
if (isBits) OS << " = " << " 1 << " << i;
6465

65-
// Depending on if more in the list emit comma
66+
// Depending on 'if more in the list' emit comma
6667
if (++i < N) OS << ",";
6768

6869
OS << "\n";
@@ -102,7 +103,7 @@ void SubtargetEmitter::FeatureKeyValues(std::ostream &OS) {
102103
<< Name
103104
<< " }";
104105

105-
// Depending on if more in the list emit comma
106+
// Depending on 'if more in the list' emit comma
106107
if (++i < N) OS << ",";
107108

108109
OS << "\n";
@@ -158,7 +159,7 @@ void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
158159

159160
OS << " }";
160161

161-
// Depending on if more in the list emit comma
162+
// Depending on 'if more in the list' emit comma
162163
if (++i < N) OS << ",";
163164

164165
OS << "\n";
@@ -315,9 +316,9 @@ void SubtargetEmitter::EmitStageData(std::ostream &OS,
315316
}
316317

317318
//
318-
// EmitProcessData - Generate data for processor itineraries.
319+
// EmitProcessorData - Generate data for processor itineraries.
319320
//
320-
void SubtargetEmitter::EmitProcessData(std::ostream &OS,
321+
void SubtargetEmitter::EmitProcessorData(std::ostream &OS,
321322
std::vector<std::vector<InstrItinerary> > &ProcList) {
322323
// Get an iterator for processor itinerary stages
323324
std::vector<std::vector<InstrItinerary> >::iterator
@@ -362,6 +363,54 @@ void SubtargetEmitter::EmitProcessData(std::ostream &OS,
362363
// End processor itinerary table
363364
OS << "};\n";
364365
}
366+
367+
OS << "\n";
368+
OS << "static llvm::InstrItinerary NoItineraries[] = {};\n";
369+
}
370+
371+
//
372+
// EmitProcessorLookup - generate cpu name to itinerary lookup table.
373+
//
374+
void SubtargetEmitter::EmitProcessorLookup(std::ostream &OS) {
375+
// Gather and sort processor information
376+
std::vector<Record*> ProcessorList =
377+
Records.getAllDerivedDefinitions("Processor");
378+
sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
379+
380+
// Begin processor table
381+
OS << "\n";
382+
OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
383+
<< "static const llvm::SubtargetInfoKV SubTypeInfoKV[] = {\n";
384+
385+
// For each processor
386+
for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
387+
// Next processor
388+
Record *Processor = ProcessorList[i];
389+
390+
std::string Name = Processor->getValueAsString("Name");
391+
std::string ProcItin = Processor->getValueAsDef("ProcItin")->getName();
392+
393+
// Emit as { "cpu", procinit },
394+
OS << " { "
395+
<< "\"" << Name << "\", "
396+
<< "(void *)&" << ProcItin;
397+
398+
OS << " }";
399+
400+
// Depending on ''if more in the list'' emit comma
401+
if (++i < N) OS << ",";
402+
403+
OS << "\n";
404+
}
405+
406+
// End processor table
407+
OS << "};\n";
408+
409+
// Emit size of table
410+
OS<<"\nenum {\n";
411+
OS<<" SubTypeInfoKVSize = sizeof(SubTypeInfoKV)/"
412+
"sizeof(llvm::SubtargetInfoKV)\n";
413+
OS<<"};\n";
365414
}
366415

367416
//
@@ -376,7 +425,9 @@ void SubtargetEmitter::EmitData(std::ostream &OS) {
376425
// Emit the stage data
377426
EmitStageData(OS, NItinClasses, ItinClassesMap, ProcList);
378427
// Emit the processor itinerary data
379-
EmitProcessData(OS, ProcList);
428+
EmitProcessorData(OS, ProcList);
429+
// Emit the processor lookup data
430+
EmitProcessorLookup(OS);
380431
}
381432

382433
//
@@ -409,6 +460,9 @@ void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS) {
409460

410461
OS << " " << Attribute << " = (Bits & " << Instance << ") != 0;\n";
411462
}
463+
OS << "\n"
464+
<< " InstrItinerary *Itin = (InstrItinerary *)"
465+
"Features.getInfo(SubTypeInfoKV, SubTypeInfoKVSize);\n";
412466
OS << "}\n";
413467
}
414468

llvm/utils/TableGen/SubtargetEmitter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class SubtargetEmitter : public TableGenBackend {
3838
void EmitStageData(std::ostream &OS, unsigned NItinClasses,
3939
std::map<std::string, unsigned> &ItinClassesMap,
4040
std::vector<std::vector<InstrItinerary> > &ProcList);
41-
void EmitProcessData(std::ostream &OS,
41+
void EmitProcessorData(std::ostream &OS,
4242
std::vector<std::vector<InstrItinerary> > &ProcList);
43+
void EmitProcessorLookup(std::ostream &OS);
4344
void EmitData(std::ostream &OS);
4445
void ParseFeaturesFunction(std::ostream &OS);
4546

0 commit comments

Comments
 (0)