2005-10-21 19:00:04 +00:00
|
|
|
//===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by James M. Laskey and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits subtarget enumerations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SubtargetEmitter.h"
|
|
|
|
#include "CodeGenTarget.h"
|
|
|
|
#include "Record.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <set>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2005-10-22 07:59:56 +00:00
|
|
|
//
|
|
|
|
// Convenience types.
|
|
|
|
//
|
2005-10-21 19:00:04 +00:00
|
|
|
typedef std::vector<Record*> RecordList;
|
|
|
|
typedef std::vector<Record*>::iterator RecordListIter;
|
|
|
|
|
2005-10-22 07:59:56 +00:00
|
|
|
//
|
|
|
|
// Record sort by name function.
|
|
|
|
//
|
|
|
|
struct LessRecord {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
|
|
return Rec1->getName() < Rec2->getName();
|
|
|
|
}
|
|
|
|
};
|
2005-10-21 19:00:04 +00:00
|
|
|
|
2005-10-22 07:59:56 +00:00
|
|
|
//
|
|
|
|
// Record sort by field "Name" function.
|
|
|
|
//
|
|
|
|
struct LessRecordFieldName {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
|
|
return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2005-10-21 19:00:04 +00:00
|
|
|
//
|
2005-10-25 15:16:36 +00:00
|
|
|
// FeatureEnumeration - Emit an enumeration of all the subtarget features.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::FeatureEnumeration(std::ostream &OS) {
|
2005-10-21 19:00:04 +00:00
|
|
|
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
2005-10-22 07:59:56 +00:00
|
|
|
sort(Features.begin(), Features.end(), LessRecord());
|
2005-10-21 19:00:04 +00:00
|
|
|
|
2005-10-25 15:16:36 +00:00
|
|
|
int i = 0;
|
2005-10-21 19:00:04 +00:00
|
|
|
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "enum {\n";
|
2005-10-21 19:00:04 +00:00
|
|
|
|
2005-10-25 15:16:36 +00:00
|
|
|
for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;){
|
|
|
|
Record *R = *RI++;
|
|
|
|
std::string Instance = R->getName();
|
|
|
|
OS << " "
|
|
|
|
<< Instance
|
|
|
|
<< " = "
|
|
|
|
<< " 1 << " << i++
|
|
|
|
<< ((RI != E) ? ",\n" : "\n");
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FeatureKeyValues - Emit data of all the subtarget features. Used by command
|
|
|
|
// line.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::FeatureKeyValues(std::ostream &OS) {
|
|
|
|
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
|
|
|
sort(Features.begin(), Features.end(), LessRecord());
|
|
|
|
|
|
|
|
OS << "\n"
|
|
|
|
<< "// Sorted (by key) array of values for CPU features.\n"
|
|
|
|
<< "static llvm::SubtargetFeatureKV FeatureKV[] = {\n";
|
|
|
|
for (RecordListIter RI = Features.begin(), E = Features.end(); RI != E;) {
|
|
|
|
Record *R = *RI++;
|
|
|
|
std::string Instance = R->getName();
|
|
|
|
std::string Name = R->getValueAsString("Name");
|
|
|
|
std::string Desc = R->getValueAsString("Desc");
|
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
|
|
|
<< "\"" << Desc << "\", "
|
|
|
|
<< Instance
|
|
|
|
<< ((RI != E) ? " },\n" : " }\n");
|
|
|
|
}
|
|
|
|
OS << "};\n";
|
|
|
|
|
|
|
|
OS<<"\nenum {\n";
|
|
|
|
OS<<" FeatureKVSize = sizeof(FeatureKV)/sizeof(llvm::SubtargetFeatureKV)\n";
|
|
|
|
OS<<"};\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CPUKeyValues - Emit data of all the subtarget processors. Used by command
|
|
|
|
// line.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::CPUKeyValues(std::ostream &OS) {
|
|
|
|
RecordList Processors = Records.getAllDerivedDefinitions("Processor");
|
|
|
|
sort(Processors.begin(), Processors.end(), LessRecordFieldName());
|
|
|
|
|
|
|
|
OS << "\n"
|
|
|
|
<< "// Sorted (by key) array of values for CPU subtype.\n"
|
|
|
|
<< "static const llvm::SubtargetFeatureKV SubTypeKV[] = {\n";
|
|
|
|
for (RecordListIter RI = Processors.begin(), E = Processors.end();
|
|
|
|
RI != E;) {
|
|
|
|
Record *R = *RI++;
|
|
|
|
std::string Name = R->getValueAsString("Name");
|
|
|
|
Record *ProcItin = R->getValueAsDef("ProcItin");
|
|
|
|
ListInit *Features = R->getValueAsListInit("Features");
|
|
|
|
unsigned N = Features->getSize();
|
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
|
|
|
<< "\"Select the " << Name << " processor\", ";
|
|
|
|
|
|
|
|
|
|
|
|
if (N == 0) {
|
|
|
|
OS << "0";
|
|
|
|
} else {
|
|
|
|
for (unsigned i = 0; i < N; ) {
|
|
|
|
if (DefInit *DI = dynamic_cast<DefInit*>(Features->getElement(i++))) {
|
|
|
|
Record *Feature = DI->getDef();
|
|
|
|
std::string Name = Feature->getName();
|
|
|
|
OS << Name;
|
|
|
|
if (i != N) OS << " | ";
|
|
|
|
} else {
|
|
|
|
throw "Feature: " + Name +
|
|
|
|
" expected feature in processor feature list!";
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-25 15:16:36 +00:00
|
|
|
|
|
|
|
OS << ((RI != E) ? " },\n" : " }\n");
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "};\n";
|
|
|
|
|
2005-10-23 22:33:08 +00:00
|
|
|
OS<<"\nenum {\n";
|
|
|
|
OS<<" SubTypeKVSize = sizeof(SubTypeKV)/sizeof(llvm::SubtargetFeatureKV)\n";
|
|
|
|
OS<<"};\n";
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
2005-10-25 15:16:36 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// SubtargetEmitter::run - Main subtarget enumeration emitter.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::run(std::ostream &OS) {
|
|
|
|
EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
|
|
|
|
|
|
|
|
OS << "#include \"llvm/Target/SubtargetFeature.h\"\n\n";
|
|
|
|
|
|
|
|
FeatureEnumeration(OS);
|
|
|
|
FeatureKeyValues(OS);
|
|
|
|
CPUKeyValues(OS);
|
|
|
|
}
|