#include <algorithm>
using namespace llvm;
-//
-// Record sort by name function.
-//
-struct LessRecord {
- bool operator()(const Record *Rec1, const Record *Rec2) const {
- return Rec1->getName() < Rec2->getName();
- }
-};
-
-//
-// Record sort by field "Name" function.
-//
-struct LessRecordFieldName {
- bool operator()(const Record *Rec1, const Record *Rec2) const {
- return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
- }
-};
-
//
// Enumeration - Emit the specified class as an enumeration.
//
// Gather and sort all the features
std::vector<Record*> FeatureList =
Records.getAllDerivedDefinitions("SubtargetFeature");
- std::sort(FeatureList.begin(), FeatureList.end(), LessRecord());
+ std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
// Begin feature table
OS << "// Sorted (by key) array of values for CPU features.\n"
- << "static llvm::SubtargetFeatureKV FeatureKV[] = {\n";
+ << "static const llvm::SubtargetFeatureKV FeatureKV[] = {\n";
// For each feature
for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
if (ProcItinList.size() < 2) return;
// Begin stages table
- OS << "static llvm::InstrStage Stages[] = {\n"
+ OS << "static const llvm::InstrStage Stages[] = {\n"
" { 0, 0 }, // No itinerary\n";
+ unsigned StageCount = 1;
unsigned ItinEnum = 1;
std::map<std::string, unsigned> ItinMap;
for (unsigned i = 0, N = ProcItinList.size(); i < N; i++) {
if (Find == 0) {
// Emit as { cycles, u1 | u2 | ... | un }, // index
OS << ItinString << ", // " << ItinEnum << "\n";
- // Record Itin class number
- ItinMap[ItinString] = Find = ItinEnum++;
+ // Record Itin class number.
+ ItinMap[ItinString] = Find = StageCount;
+ StageCount += NStages;
+ ItinEnum++;
}
// Set up itinerary as location and location + stage count
// Begin processor itinerary table
OS << "\n";
- OS << "static llvm::InstrItinerary " << Name << "[] = {\n";
+ OS << "static const llvm::InstrItinerary " << Name << "[] = {\n";
// For each itinerary class
std::vector<InstrItinerary> &ItinList = *ProcListIter++;