2005-10-22 03:00:04 +08: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"
|
2005-10-28 09:43:09 +08:00
|
|
|
#include <algorithm>
|
2005-10-22 03:00:04 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2005-10-22 15:59:56 +08:00
|
|
|
//
|
|
|
|
// Convenience types.
|
|
|
|
//
|
2005-10-22 03:00:04 +08:00
|
|
|
typedef std::vector<Record*> RecordList;
|
2005-10-28 03:47:21 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// RecordListIter - Simplify iterating through a std::vector of records.
|
|
|
|
//
|
|
|
|
class RecordListIter {
|
|
|
|
std::vector<Record*>::iterator RI; // Currect cursor
|
|
|
|
std::vector<Record*>::iterator E; // End point
|
|
|
|
|
|
|
|
public:
|
2005-10-28 03:47:21 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// Ctor.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordListIter(RecordList &RL)
|
|
|
|
: RI(RL.begin()), E(RL.end())
|
|
|
|
{}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
// isMore - Return true if more records are available.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
bool isMore() const { return RI != E; }
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// next - Return the next record or NULL if none.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
Record *next() { return isMore() ? *RI++ : NULL; }
|
|
|
|
};
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// DefListIter - Simplify iterating through a field which is a list of records.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
struct DefListIter {
|
2005-10-28 23:20:43 +08:00
|
|
|
ListInit *List; // List of DefInit
|
|
|
|
unsigned N; // Number of elements in list
|
|
|
|
unsigned i; // Current index in list
|
2005-10-28 03:47:21 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// Ctor - Lookup field and get list and length.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
DefListIter(Record *R, const std::string &Name)
|
|
|
|
: List(R->getValueAsListInit(Name)), N(List->getSize()), i(0)
|
|
|
|
{}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// isMore - Return true if more records are available.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
bool isMore() const { return i < N; }
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
//
|
|
|
|
// next - Return the next record or NULL if none.
|
|
|
|
//
|
2005-10-28 03:47:21 +08:00
|
|
|
Record *next() {
|
|
|
|
if (isMore()) {
|
|
|
|
if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i++))) {
|
|
|
|
return DI->getDef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
};
|
2005-10-22 03:00:04 +08:00
|
|
|
|
2005-10-22 15:59:56 +08:00
|
|
|
//
|
|
|
|
// Record sort by name function.
|
|
|
|
//
|
|
|
|
struct LessRecord {
|
|
|
|
bool operator()(const Record *Rec1, const Record *Rec2) const {
|
|
|
|
return Rec1->getName() < Rec2->getName();
|
|
|
|
}
|
|
|
|
};
|
2005-10-22 03:00:04 +08:00
|
|
|
|
2005-10-22 15:59:56 +08: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-22 03:00:04 +08:00
|
|
|
//
|
2005-10-27 01:30:34 +08:00
|
|
|
// Enumeration - Emit the specified class as an enumeration.
|
2005-10-25 23:16:36 +08:00
|
|
|
//
|
2005-10-27 01:30:34 +08:00
|
|
|
void SubtargetEmitter::Enumeration(std::ostream &OS,
|
|
|
|
const char *ClassName,
|
|
|
|
bool isBits) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get all records of class and sort
|
2005-10-27 01:30:34 +08:00
|
|
|
RecordList Defs = Records.getAllDerivedDefinitions(ClassName);
|
|
|
|
sort(Defs.begin(), Defs.end(), LessRecord());
|
2005-10-22 03:00:04 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Track position if isBits
|
2005-10-25 23:16:36 +08:00
|
|
|
int i = 0;
|
2005-10-22 03:00:04 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Open enumeration
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "enum {\n";
|
2005-10-22 03:00:04 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each record
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordListIter DI(Defs);
|
|
|
|
while (Record *R = DI.next()) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get and emit name
|
|
|
|
std::string Name = R->getName();
|
|
|
|
OS << " " << Name;
|
|
|
|
|
|
|
|
// If bit flags then emit expression (1 << i)
|
|
|
|
if (isBits) OS << " = " << " 1 << " << i++;
|
|
|
|
|
|
|
|
// Depending on if more in the list, emit comma and new line
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << (DI.isMore() ? ",\n" : "\n");
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Close enumeration
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FeatureKeyValues - Emit data of all the subtarget features. Used by command
|
|
|
|
// line.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::FeatureKeyValues(std::ostream &OS) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Gather and sort all the features
|
2005-10-25 23:16:36 +08:00
|
|
|
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
|
|
|
sort(Features.begin(), Features.end(), LessRecord());
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Begin feature table
|
2005-10-27 01:30:34 +08:00
|
|
|
OS << "// Sorted (by key) array of values for CPU features.\n"
|
2005-10-25 23:16:36 +08:00
|
|
|
<< "static llvm::SubtargetFeatureKV FeatureKV[] = {\n";
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// For each feature
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordListIter FI(Features);
|
|
|
|
while (Record *R = FI.next()) {
|
2005-10-25 23:16:36 +08:00
|
|
|
std::string Instance = R->getName();
|
|
|
|
std::string Name = R->getValueAsString("Name");
|
|
|
|
std::string Desc = R->getValueAsString("Desc");
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// Emit as { "feature", "decription", feactureEnum }
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
|
|
|
<< "\"" << Desc << "\", "
|
|
|
|
<< Instance
|
2005-10-28 03:47:21 +08:00
|
|
|
<< (FI.isMore() ? " },\n" : " }\n");
|
2005-10-25 23:16:36 +08:00
|
|
|
}
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// End feature table
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "};\n";
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit size of table
|
2005-10-25 23:16:36 +08:00
|
|
|
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) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Gather and sort processor information
|
2005-10-25 23:16:36 +08:00
|
|
|
RecordList Processors = Records.getAllDerivedDefinitions("Processor");
|
|
|
|
sort(Processors.begin(), Processors.end(), LessRecordFieldName());
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Begin processor table
|
2005-10-27 01:30:34 +08:00
|
|
|
OS << "// Sorted (by key) array of values for CPU subtype.\n"
|
2005-10-25 23:16:36 +08:00
|
|
|
<< "static const llvm::SubtargetFeatureKV SubTypeKV[] = {\n";
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// For each processor
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordListIter PI(Processors);
|
|
|
|
while (Record *R = PI.next()) {
|
2005-10-25 23:16:36 +08:00
|
|
|
std::string Name = R->getValueAsString("Name");
|
2005-10-28 03:47:21 +08:00
|
|
|
DefListIter FI(R, "Features");
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit as { "cpu", "description", f1 | f2 | ... fn },
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
|
|
|
<< "\"Select the " << Name << " processor\", ";
|
|
|
|
|
2005-10-28 03:47:21 +08:00
|
|
|
if (!FI.isMore()) {
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "0";
|
|
|
|
} else {
|
2005-10-28 03:47:21 +08:00
|
|
|
while (Record *Feature = FI.next()) {
|
|
|
|
std::string Name = Feature->getName();
|
|
|
|
OS << Name;
|
|
|
|
if (FI.isMore()) OS << " | ";
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
|
|
|
}
|
2005-10-25 23:16:36 +08:00
|
|
|
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << (PI.isMore() ? " },\n" : " }\n");
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// End processor table
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "};\n";
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit size of table
|
2005-10-24 06:33:08 +08:00
|
|
|
OS<<"\nenum {\n";
|
|
|
|
OS<<" SubTypeKVSize = sizeof(SubTypeKV)/sizeof(llvm::SubtargetFeatureKV)\n";
|
|
|
|
OS<<"};\n";
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
2005-10-25 23:16:36 +08:00
|
|
|
|
2005-10-28 03:47:21 +08:00
|
|
|
//
|
|
|
|
// CollectAllItinClasses - Gathers and enumerates all the itinerary classes.
|
2005-10-28 23:20:43 +08:00
|
|
|
// Returns itinerary class count.
|
2005-10-28 03:47:21 +08:00
|
|
|
//
|
|
|
|
unsigned SubtargetEmitter::CollectAllItinClasses(IntMap &ItinClassesMap) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Gather and sort all itinerary classes
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordList ICL = Records.getAllDerivedDefinitions("InstrItinClass");
|
|
|
|
sort(ICL.begin(), ICL.end(), LessRecord());
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// Track enumeration
|
|
|
|
unsigned Index = 0;
|
2005-10-28 03:47:21 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each class
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordListIter ICI(ICL);
|
|
|
|
while (Record *ItinClass = ICI.next()) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get name of itinerary class
|
2005-10-28 03:47:21 +08:00
|
|
|
std::string Name = ItinClass->getName();
|
2005-10-28 23:20:43 +08:00
|
|
|
// Assign itinerary class a unique number
|
2005-10-28 03:47:21 +08:00
|
|
|
ItinClassesMap[Name] = Index++;
|
|
|
|
}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Return itinerary class count
|
2005-10-28 03:47:21 +08:00
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// FormItineraryString - Compose a string containing the data initialization
|
|
|
|
// for the specified itinerary. N is the number of stages.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::FormItineraryString(Record *ItinData,
|
|
|
|
std::string &ItinString,
|
|
|
|
unsigned &N) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Set up stages iterator
|
2005-10-28 03:47:21 +08:00
|
|
|
DefListIter SLI(ItinData, "Stages");
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get stage count
|
2005-10-28 03:47:21 +08:00
|
|
|
N = SLI.N;
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// For each stage
|
2005-10-28 03:47:21 +08:00
|
|
|
while (Record *Stage = SLI.next()) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Form string as ,{ cycles, u1 | u2 | ... | un }
|
2005-10-28 03:47:21 +08:00
|
|
|
int Cycles = Stage->getValueAsInt("Cycles");
|
|
|
|
ItinString += " ,{ " + itostr(Cycles) + ", ";
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each unit
|
2005-10-28 03:47:21 +08:00
|
|
|
DefListIter ULI(Stage, "Units");
|
|
|
|
while (Record *Unit = ULI.next()) {
|
|
|
|
std::string Name = Unit->getName();
|
|
|
|
ItinString += Name;
|
|
|
|
if (ULI.isMore())ItinString += " | ";
|
|
|
|
}
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// Close off stage
|
|
|
|
ItinString += " }";
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// EmitStageData - Generate unique itinerary stages. Record itineraries for
|
|
|
|
// processors.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::EmitStageData(std::ostream &OS,
|
|
|
|
unsigned N,
|
|
|
|
IntMap &ItinClassesMap,
|
|
|
|
ProcessorList &ProcList) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Gather processor iteraries
|
|
|
|
RecordList Itins = Records.getAllDerivedDefinitions("ProcessorItineraries");
|
|
|
|
|
|
|
|
// If just no itinerary then don't bother
|
|
|
|
if (Itins.size() < 2) return;
|
|
|
|
|
|
|
|
// Begin stages table
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << "static llvm::InstrStage Stages[] = {\n"
|
|
|
|
" { 0, 0 } // No itinerary\n";
|
|
|
|
|
|
|
|
IntMap ItinMap;
|
|
|
|
unsigned Index = 1;
|
|
|
|
RecordListIter II(Itins);
|
|
|
|
while (Record *Itin = II.next()) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get processor itinerary name
|
2005-10-28 03:47:21 +08:00
|
|
|
std::string Name = Itin->getName();
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// Skip default
|
2005-10-28 03:47:21 +08:00
|
|
|
if (Name == "NoItineraries") continue;
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Create and expand processor itinerary to cover all itinerary classes
|
2005-10-28 03:47:21 +08:00
|
|
|
IntineraryList IL;
|
|
|
|
IL.resize(N);
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each itinerary
|
2005-10-28 03:47:21 +08:00
|
|
|
DefListIter IDLI(Itin, "IID");
|
|
|
|
while (Record *ItinData = IDLI.next()) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get string and stage count
|
2005-10-28 03:47:21 +08:00
|
|
|
std::string ItinString;
|
|
|
|
unsigned M;
|
|
|
|
FormItineraryString(ItinData, ItinString, M);
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Check to see if it already exists
|
2005-10-28 03:47:21 +08:00
|
|
|
unsigned Find = ItinMap[ItinString];
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// If new itinerary
|
2005-10-28 03:47:21 +08:00
|
|
|
if (Find == 0) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit as ,{ cycles, u1 | u2 | ... | un } // index
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << ItinString << " // " << Index << "\n";
|
|
|
|
ItinMap[ItinString] = Find = Index++;
|
|
|
|
}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Set up itinerary as location and location + stage count
|
2005-10-28 03:47:21 +08:00
|
|
|
InstrItinerary Intinerary = { Find, Find + M };
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Locate where to inject into processor itinerary table
|
2005-10-28 03:47:21 +08:00
|
|
|
std::string Name = ItinData->getValueAsDef("TheClass")->getName();
|
|
|
|
Find = ItinClassesMap[Name];
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// Inject - empty slots will be 0, 0
|
2005-10-28 03:47:21 +08:00
|
|
|
IL[Find] = Intinerary;
|
|
|
|
}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Add process itinerary to list
|
2005-10-28 03:47:21 +08:00
|
|
|
ProcList.push_back(IL);
|
|
|
|
}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// End stages table
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// EmitProcessData - Generate data for processor itineraries.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::EmitProcessData(std::ostream &OS,
|
|
|
|
ProcessorList &ProcList) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get an iterator for processor itinerary stages
|
2005-10-28 03:47:21 +08:00
|
|
|
ProcessorList::iterator PLI = ProcList.begin();
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// For each processor itinerary
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordList Itins = Records.getAllDerivedDefinitions("ProcessorItineraries");
|
|
|
|
RecordListIter II(Itins);
|
|
|
|
while (Record *Itin = II.next()) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get processor itinerary name
|
2005-10-28 03:47:21 +08:00
|
|
|
std::string Name = Itin->getName();
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// Skip default
|
2005-10-28 03:47:21 +08:00
|
|
|
if (Name == "NoItineraries") continue;
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Begin processor itinerary table
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << "\n";
|
|
|
|
OS << "static llvm::InstrItinerary " << Name << "[] = {\n";
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each itinerary class
|
2005-10-28 03:47:21 +08:00
|
|
|
IntineraryList &IL = *PLI++;
|
|
|
|
unsigned Index = 0;
|
|
|
|
for (IntineraryList::iterator ILI = IL.begin(), E = IL.end(); ILI != E;) {
|
|
|
|
InstrItinerary &Intinerary = *ILI++;
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit in the form of { first, last } // index
|
2005-10-28 03:47:21 +08:00
|
|
|
if (Intinerary.First == 0) {
|
|
|
|
OS << " { 0, 0 }";
|
|
|
|
} else {
|
|
|
|
OS << " { " << Intinerary.First << ", " << Intinerary.Last << " }";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ILI != E) OS << ",";
|
|
|
|
OS << " // " << Index++ << "\n";
|
|
|
|
}
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// End processor itinerary table
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// EmitData - Emits all stages and itineries, folding common patterns.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::EmitData(std::ostream &OS) {
|
|
|
|
IntMap ItinClassesMap;
|
|
|
|
ProcessorList ProcList;
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Enumerate all the itinerary classes
|
2005-10-28 03:47:21 +08:00
|
|
|
unsigned N = CollectAllItinClasses(ItinClassesMap);
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit the stage data
|
2005-10-28 03:47:21 +08:00
|
|
|
EmitStageData(OS, N, ItinClassesMap, ProcList);
|
2005-10-28 23:20:43 +08:00
|
|
|
// Emit the processor itinerary data
|
2005-10-28 03:47:21 +08:00
|
|
|
EmitProcessData(OS, ProcList);
|
|
|
|
}
|
|
|
|
|
2005-10-27 01:30:34 +08:00
|
|
|
//
|
|
|
|
// ParseFeaturesFunction - Produces a subtarget specific function for parsing
|
|
|
|
// the subtarget features string.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS) {
|
|
|
|
RecordList Features = Records.getAllDerivedDefinitions("SubtargetFeature");
|
|
|
|
sort(Features.begin(), Features.end(), LessRecord());
|
|
|
|
|
|
|
|
OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
|
|
|
|
"// subtarget options.\n"
|
|
|
|
"void llvm::";
|
|
|
|
OS << Target;
|
|
|
|
OS << "Subtarget::ParseSubtargetFeatures(const std::string &FS,\n"
|
|
|
|
" const std::string &CPU) {\n"
|
|
|
|
" SubtargetFeatures Features(FS);\n"
|
|
|
|
" Features.setCPUIfNone(CPU);\n"
|
|
|
|
" uint32_t Bits = Features.getBits(SubTypeKV, SubTypeKVSize,\n"
|
|
|
|
" FeatureKV, FeatureKVSize);\n";
|
|
|
|
|
2005-10-28 03:47:21 +08:00
|
|
|
RecordListIter FI(Features);
|
|
|
|
while (Record *R = FI.next()) {
|
2005-10-27 01:30:34 +08:00
|
|
|
std::string Instance = R->getName();
|
|
|
|
std::string Name = R->getValueAsString("Name");
|
|
|
|
std::string Type = R->getValueAsString("Type");
|
|
|
|
std::string Attribute = R->getValueAsString("Attribute");
|
|
|
|
|
|
|
|
OS << " " << Attribute << " = (Bits & " << Instance << ") != 0;\n";
|
|
|
|
}
|
|
|
|
OS << "}\n";
|
|
|
|
}
|
|
|
|
|
2005-10-25 23:16:36 +08:00
|
|
|
//
|
|
|
|
// SubtargetEmitter::run - Main subtarget enumeration emitter.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::run(std::ostream &OS) {
|
2005-10-27 01:49:21 +08:00
|
|
|
Target = CodeGenTarget().getName();
|
2005-10-27 01:30:34 +08:00
|
|
|
|
2005-10-25 23:16:36 +08:00
|
|
|
EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
|
|
|
|
|
2005-10-28 03:47:21 +08:00
|
|
|
OS << "#include \"llvm/Target/SubtargetFeature.h\"\n";
|
|
|
|
OS << "#include \"llvm/Target/TargetInstrItineraries.h\"\n\n";
|
2005-10-25 23:16:36 +08:00
|
|
|
|
2005-10-27 01:30:34 +08:00
|
|
|
Enumeration(OS, "FuncUnit", true);
|
|
|
|
OS<<"\n";
|
2005-10-28 23:20:43 +08:00
|
|
|
// Enumeration(OS, "InstrItinClass", false);
|
|
|
|
// OS<<"\n";
|
2005-10-27 01:30:34 +08:00
|
|
|
Enumeration(OS, "SubtargetFeature", true);
|
|
|
|
OS<<"\n";
|
2005-10-25 23:16:36 +08:00
|
|
|
FeatureKeyValues(OS);
|
2005-10-27 01:30:34 +08:00
|
|
|
OS<<"\n";
|
2005-10-25 23:16:36 +08:00
|
|
|
CPUKeyValues(OS);
|
2005-10-27 01:30:34 +08:00
|
|
|
OS<<"\n";
|
2005-10-28 03:47:21 +08:00
|
|
|
EmitData(OS);
|
|
|
|
OS<<"\n";
|
2005-10-27 01:30:34 +08:00
|
|
|
ParseFeaturesFunction(OS);
|
2005-10-25 23:16:36 +08:00
|
|
|
}
|