2005-10-21 19:00:04 +00:00
|
|
|
//===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-10-21 19:00:04 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-03-03 02:04:07 +00:00
|
|
|
// This tablegen backend emits subtarget enumerations.
|
2005-10-21 19:00:04 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SubtargetEmitter.h"
|
|
|
|
#include "CodeGenTarget.h"
|
|
|
|
#include "Record.h"
|
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2005-10-28 01:43:09 +00:00
|
|
|
#include <algorithm>
|
2005-10-21 19:00:04 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//
|
2005-10-26 17:30:34 +00:00
|
|
|
// Enumeration - Emit the specified class as an enumeration.
|
2005-10-25 15:16:36 +00:00
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::Enumeration(raw_ostream &OS,
|
2005-10-26 17:30:34 +00:00
|
|
|
const char *ClassName,
|
|
|
|
bool isBits) {
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get all records of class and sort
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName);
|
2005-12-30 14:56:37 +00:00
|
|
|
std::sort(DefList.begin(), DefList.end(), LessRecord());
|
2005-10-21 19:00:04 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Open enumeration
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "enum {\n";
|
2005-10-21 19:00:04 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// For each record
|
2005-10-28 21:47:29 +00:00
|
|
|
for (unsigned i = 0, N = DefList.size(); i < N;) {
|
|
|
|
// Next record
|
|
|
|
Record *Def = DefList[i];
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get and emit name
|
2007-05-04 20:38:40 +00:00
|
|
|
OS << " " << Def->getName();
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// If bit flags then emit expression (1 << i)
|
2005-10-28 21:47:29 +00:00
|
|
|
if (isBits) OS << " = " << " 1 << " << i;
|
2005-10-28 15:20:43 +00:00
|
|
|
|
2005-10-31 17:16:01 +00:00
|
|
|
// Depending on 'if more in the list' emit comma
|
2005-10-28 21:47:29 +00:00
|
|
|
if (++i < N) OS << ",";
|
|
|
|
|
|
|
|
OS << "\n";
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Close enumeration
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2007-05-04 20:38:40 +00:00
|
|
|
// FeatureKeyValues - Emit data of all the subtarget features. Used by the
|
|
|
|
// command line.
|
2005-10-25 15:16:36 +00:00
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
|
2005-10-28 15:20:43 +00:00
|
|
|
// Gather and sort all the features
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> FeatureList =
|
|
|
|
Records.getAllDerivedDefinitions("SubtargetFeature");
|
2008-09-11 17:05:32 +00:00
|
|
|
std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
|
2005-10-25 15:16:36 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Begin feature table
|
2005-10-26 17:30:34 +00:00
|
|
|
OS << "// Sorted (by key) array of values for CPU features.\n"
|
2008-03-25 21:45:14 +00:00
|
|
|
<< "static const llvm::SubtargetFeatureKV FeatureKV[] = {\n";
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// For each feature
|
2006-12-12 20:55:58 +00:00
|
|
|
for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
|
2005-10-28 21:47:29 +00:00
|
|
|
// Next feature
|
|
|
|
Record *Feature = FeatureList[i];
|
|
|
|
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Name = Feature->getName();
|
|
|
|
const std::string &CommandLineName = Feature->getValueAsString("Name");
|
|
|
|
const std::string &Desc = Feature->getValueAsString("Desc");
|
2005-10-28 15:20:43 +00:00
|
|
|
|
2006-12-12 20:55:58 +00:00
|
|
|
if (CommandLineName.empty()) continue;
|
|
|
|
|
2009-03-26 16:17:51 +00:00
|
|
|
// Emit as { "feature", "description", featureEnum, i1 | i2 | ... | in }
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << " { "
|
2005-10-28 21:47:29 +00:00
|
|
|
<< "\"" << CommandLineName << "\", "
|
2005-10-25 15:16:36 +00:00
|
|
|
<< "\"" << Desc << "\", "
|
2007-05-04 20:38:40 +00:00
|
|
|
<< Name << ", ";
|
|
|
|
|
|
|
|
const std::vector<Record*> &ImpliesList =
|
|
|
|
Feature->getValueAsListOfDefs("Implies");
|
|
|
|
|
|
|
|
if (ImpliesList.empty()) {
|
|
|
|
OS << "0";
|
|
|
|
} else {
|
|
|
|
for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
|
|
|
|
OS << ImpliesList[j]->getName();
|
|
|
|
if (++j < M) OS << " | ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << " }";
|
2005-10-28 21:47:29 +00:00
|
|
|
|
2005-10-31 17:16:01 +00:00
|
|
|
// Depending on 'if more in the list' emit comma
|
2006-12-12 20:55:58 +00:00
|
|
|
if ((i + 1) < N) OS << ",";
|
2005-10-28 21:47:29 +00:00
|
|
|
|
|
|
|
OS << "\n";
|
2005-10-25 15:16:36 +00:00
|
|
|
}
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// End feature table
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "};\n";
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Emit size of table
|
2005-10-25 15:16:36 +00: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.
|
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
|
2005-10-28 15:20:43 +00:00
|
|
|
// Gather and sort processor information
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> ProcessorList =
|
|
|
|
Records.getAllDerivedDefinitions("Processor");
|
2005-12-30 14:56:37 +00:00
|
|
|
std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
|
2005-10-25 15:16:36 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Begin processor table
|
2005-10-26 17:30:34 +00:00
|
|
|
OS << "// Sorted (by key) array of values for CPU subtype.\n"
|
2005-10-25 15:16:36 +00:00
|
|
|
<< "static const llvm::SubtargetFeatureKV SubTypeKV[] = {\n";
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// For each processor
|
2005-10-28 21:47:29 +00:00
|
|
|
for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
|
|
|
|
// Next processor
|
|
|
|
Record *Processor = ProcessorList[i];
|
|
|
|
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Name = Processor->getValueAsString("Name");
|
|
|
|
const std::vector<Record*> &FeatureList =
|
2005-10-28 22:49:02 +00:00
|
|
|
Processor->getValueAsListOfDefs("Features");
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Emit as { "cpu", "description", f1 | f2 | ... fn },
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
|
|
|
<< "\"Select the " << Name << " processor\", ";
|
|
|
|
|
2005-10-28 21:47:29 +00:00
|
|
|
if (FeatureList.empty()) {
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "0";
|
|
|
|
} else {
|
2005-10-28 21:47:29 +00:00
|
|
|
for (unsigned j = 0, M = FeatureList.size(); j < M;) {
|
2007-05-04 20:38:40 +00:00
|
|
|
OS << FeatureList[j]->getName();
|
2005-10-28 21:47:29 +00:00
|
|
|
if (++j < M) OS << " | ";
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-25 15:16:36 +00:00
|
|
|
|
2007-05-04 20:38:40 +00:00
|
|
|
// The "0" is for the "implies" section of this data structure.
|
|
|
|
OS << ", 0 }";
|
2005-10-28 21:47:29 +00:00
|
|
|
|
2005-10-31 17:16:01 +00:00
|
|
|
// Depending on 'if more in the list' emit comma
|
2005-10-28 21:47:29 +00:00
|
|
|
if (++i < N) OS << ",";
|
|
|
|
|
|
|
|
OS << "\n";
|
2005-10-21 19:00:04 +00:00
|
|
|
}
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// End processor table
|
2005-10-25 15:16:36 +00:00
|
|
|
OS << "};\n";
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Emit size of table
|
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
|
|
|
|
2005-10-27 19:47:21 +00:00
|
|
|
//
|
|
|
|
// CollectAllItinClasses - Gathers and enumerates all the itinerary classes.
|
2005-10-28 15:20:43 +00:00
|
|
|
// Returns itinerary class count.
|
2005-10-27 19:47:21 +00:00
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
unsigned SubtargetEmitter::CollectAllItinClasses(raw_ostream &OS,
|
2005-11-01 20:06:59 +00:00
|
|
|
std::map<std::string, unsigned> &ItinClassesMap) {
|
2005-10-28 15:20:43 +00:00
|
|
|
// Gather and sort all itinerary classes
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> ItinClassList =
|
|
|
|
Records.getAllDerivedDefinitions("InstrItinClass");
|
2005-12-30 14:56:37 +00:00
|
|
|
std::sort(ItinClassList.begin(), ItinClassList.end(), LessRecord());
|
2005-10-28 21:47:29 +00:00
|
|
|
|
|
|
|
// For each itinerary class
|
|
|
|
unsigned N = ItinClassList.size();
|
|
|
|
for (unsigned i = 0; i < N; i++) {
|
|
|
|
// Next itinerary class
|
2007-05-04 20:38:40 +00:00
|
|
|
const Record *ItinClass = ItinClassList[i];
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get name of itinerary class
|
|
|
|
// Assign itinerary class a unique number
|
2007-05-04 20:38:40 +00:00
|
|
|
ItinClassesMap[ItinClass->getName()] = i;
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
2005-11-01 20:06:59 +00:00
|
|
|
// Emit size of table
|
|
|
|
OS<<"\nenum {\n";
|
|
|
|
OS<<" ItinClassesSize = " << N << "\n";
|
|
|
|
OS<<"};\n";
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Return itinerary class count
|
2005-10-28 21:47:29 +00:00
|
|
|
return N;
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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,
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned &NStages) {
|
|
|
|
// Get states list
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::vector<Record*> &StageList =
|
|
|
|
ItinData->getValueAsListOfDefs("Stages");
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// For each stage
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned N = NStages = StageList.size();
|
2007-04-22 09:04:24 +00:00
|
|
|
for (unsigned i = 0; i < N;) {
|
2005-10-28 21:47:29 +00:00
|
|
|
// Next stage
|
2007-05-04 20:38:40 +00:00
|
|
|
const Record *Stage = StageList[i];
|
2005-10-28 21:47:29 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Form string as ,{ cycles, u1 | u2 | ... | un }
|
2005-10-27 19:47:21 +00:00
|
|
|
int Cycles = Stage->getValueAsInt("Cycles");
|
2005-11-03 22:47:41 +00:00
|
|
|
ItinString += " { " + itostr(Cycles) + ", ";
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 21:47:29 +00:00
|
|
|
// Get unit list
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::vector<Record*> &UnitList = Stage->getValueAsListOfDefs("Units");
|
2005-10-28 21:47:29 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// For each unit
|
2005-10-28 21:47:29 +00:00
|
|
|
for (unsigned j = 0, M = UnitList.size(); j < M;) {
|
|
|
|
// Add name and bitwise or
|
2007-05-04 20:38:40 +00:00
|
|
|
ItinString += UnitList[j]->getName();
|
2005-10-28 21:47:29 +00:00
|
|
|
if (++j < M) ItinString += " | ";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// Close off stage
|
|
|
|
ItinString += " }";
|
2007-04-22 09:04:24 +00:00
|
|
|
if (++i < N) ItinString += ", ";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// EmitStageData - Generate unique itinerary stages. Record itineraries for
|
|
|
|
// processors.
|
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::EmitStageData(raw_ostream &OS,
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned NItinClasses,
|
|
|
|
std::map<std::string, unsigned> &ItinClassesMap,
|
|
|
|
std::vector<std::vector<InstrItinerary> > &ProcList) {
|
2005-10-28 15:20:43 +00:00
|
|
|
// Gather processor iteraries
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> ProcItinList =
|
|
|
|
Records.getAllDerivedDefinitions("ProcessorItineraries");
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// If just no itinerary then don't bother
|
2005-10-28 21:47:29 +00:00
|
|
|
if (ProcItinList.size() < 2) return;
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// Begin stages table
|
2008-03-25 21:45:14 +00:00
|
|
|
OS << "static const llvm::InstrStage Stages[] = {\n"
|
2005-11-03 22:47:41 +00:00
|
|
|
" { 0, 0 }, // No itinerary\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2008-04-06 17:38:14 +00:00
|
|
|
unsigned StageCount = 1;
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned ItinEnum = 1;
|
|
|
|
std::map<std::string, unsigned> ItinMap;
|
|
|
|
for (unsigned i = 0, N = ProcItinList.size(); i < N; i++) {
|
|
|
|
// Next record
|
|
|
|
Record *Proc = ProcItinList[i];
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get processor itinerary name
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Name = Proc->getName();
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// Skip default
|
2005-10-27 19:47:21 +00:00
|
|
|
if (Name == "NoItineraries") continue;
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Create and expand processor itinerary to cover all itinerary classes
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<InstrItinerary> ItinList;
|
|
|
|
ItinList.resize(NItinClasses);
|
|
|
|
|
|
|
|
// Get itinerary data list
|
2005-10-28 22:49:02 +00:00
|
|
|
std::vector<Record*> ItinDataList = Proc->getValueAsListOfDefs("IID");
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 21:47:29 +00:00
|
|
|
// For each itinerary data
|
|
|
|
for (unsigned j = 0, M = ItinDataList.size(); j < M; j++) {
|
|
|
|
// Next itinerary data
|
|
|
|
Record *ItinData = ItinDataList[j];
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get string and stage count
|
2005-10-27 19:47:21 +00:00
|
|
|
std::string ItinString;
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned NStages;
|
|
|
|
FormItineraryString(ItinData, ItinString, NStages);
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Check to see if it already exists
|
2005-10-27 19:47:21 +00:00
|
|
|
unsigned Find = ItinMap[ItinString];
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// If new itinerary
|
2005-10-27 19:47:21 +00:00
|
|
|
if (Find == 0) {
|
2005-11-03 22:47:41 +00:00
|
|
|
// Emit as { cycles, u1 | u2 | ... | un }, // index
|
|
|
|
OS << ItinString << ", // " << ItinEnum << "\n";
|
2008-04-06 17:38:14 +00:00
|
|
|
// Record Itin class number.
|
|
|
|
ItinMap[ItinString] = Find = StageCount;
|
|
|
|
StageCount += NStages;
|
|
|
|
ItinEnum++;
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Set up itinerary as location and location + stage count
|
2005-10-28 21:47:29 +00:00
|
|
|
InstrItinerary Intinerary = { Find, Find + NStages };
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Locate where to inject into processor itinerary table
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Name = ItinData->getValueAsDef("TheClass")->getName();
|
2005-10-27 19:47:21 +00:00
|
|
|
Find = ItinClassesMap[Name];
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// Inject - empty slots will be 0, 0
|
2005-10-28 21:47:29 +00:00
|
|
|
ItinList[Find] = Intinerary;
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Add process itinerary to list
|
2005-10-28 21:47:29 +00:00
|
|
|
ProcList.push_back(ItinList);
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
2005-11-03 22:47:41 +00:00
|
|
|
// Closing stage
|
|
|
|
OS << " { 0, 0 } // End itinerary\n";
|
2005-10-28 15:20:43 +00:00
|
|
|
// End stages table
|
2005-10-27 19:47:21 +00:00
|
|
|
OS << "};\n";
|
2005-11-01 20:06:59 +00:00
|
|
|
|
|
|
|
// Emit size of table
|
|
|
|
OS<<"\nenum {\n";
|
|
|
|
OS<<" StagesSize = sizeof(Stages)/sizeof(llvm::InstrStage)\n";
|
|
|
|
OS<<"};\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2005-10-31 17:16:01 +00:00
|
|
|
// EmitProcessorData - Generate data for processor itineraries.
|
2005-10-27 19:47:21 +00:00
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::EmitProcessorData(raw_ostream &OS,
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<std::vector<InstrItinerary> > &ProcList) {
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get an iterator for processor itinerary stages
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<std::vector<InstrItinerary> >::iterator
|
|
|
|
ProcListIter = ProcList.begin();
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// For each processor itinerary
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> Itins =
|
|
|
|
Records.getAllDerivedDefinitions("ProcessorItineraries");
|
|
|
|
for (unsigned i = 0, N = Itins.size(); i < N; i++) {
|
|
|
|
// Next record
|
|
|
|
Record *Itin = Itins[i];
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Get processor itinerary name
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Name = Itin->getName();
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// Skip default
|
2005-10-27 19:47:21 +00:00
|
|
|
if (Name == "NoItineraries") continue;
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Begin processor itinerary table
|
2005-10-27 19:47:21 +00:00
|
|
|
OS << "\n";
|
2008-03-25 21:45:14 +00:00
|
|
|
OS << "static const llvm::InstrItinerary " << Name << "[] = {\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// For each itinerary class
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<InstrItinerary> &ItinList = *ProcListIter++;
|
|
|
|
for (unsigned j = 0, M = ItinList.size(); j < M;) {
|
|
|
|
InstrItinerary &Intinerary = ItinList[j];
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Emit in the form of { first, last } // index
|
2005-10-27 19:47:21 +00:00
|
|
|
if (Intinerary.First == 0) {
|
|
|
|
OS << " { 0, 0 }";
|
|
|
|
} else {
|
|
|
|
OS << " { " << Intinerary.First << ", " << Intinerary.Last << " }";
|
|
|
|
}
|
|
|
|
|
2005-10-28 21:47:29 +00:00
|
|
|
// If more in list add comma
|
|
|
|
if (++j < M) OS << ",";
|
|
|
|
|
|
|
|
OS << " // " << (j - 1) << "\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// End processor itinerary table
|
2005-10-27 19:47:21 +00:00
|
|
|
OS << "};\n";
|
|
|
|
}
|
2005-10-31 17:16:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// EmitProcessorLookup - generate cpu name to itinerary lookup table.
|
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
|
2005-10-31 17:16:01 +00:00
|
|
|
// Gather and sort processor information
|
|
|
|
std::vector<Record*> ProcessorList =
|
|
|
|
Records.getAllDerivedDefinitions("Processor");
|
2005-12-30 14:56:37 +00:00
|
|
|
std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
|
2005-10-31 17:16:01 +00:00
|
|
|
|
|
|
|
// Begin processor table
|
|
|
|
OS << "\n";
|
|
|
|
OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
|
2005-11-03 22:47:41 +00:00
|
|
|
<< "static const llvm::SubtargetInfoKV ProcItinKV[] = {\n";
|
2005-10-31 17:16:01 +00:00
|
|
|
|
|
|
|
// For each processor
|
|
|
|
for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
|
|
|
|
// Next processor
|
|
|
|
Record *Processor = ProcessorList[i];
|
|
|
|
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Name = Processor->getValueAsString("Name");
|
|
|
|
const std::string &ProcItin =
|
|
|
|
Processor->getValueAsDef("ProcItin")->getName();
|
2005-10-31 17:16:01 +00:00
|
|
|
|
|
|
|
// Emit as { "cpu", procinit },
|
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
|
|
|
<< "(void *)&" << ProcItin;
|
|
|
|
|
|
|
|
OS << " }";
|
|
|
|
|
|
|
|
// Depending on ''if more in the list'' emit comma
|
|
|
|
if (++i < N) OS << ",";
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// End processor table
|
|
|
|
OS << "};\n";
|
|
|
|
|
|
|
|
// Emit size of table
|
|
|
|
OS<<"\nenum {\n";
|
2005-11-03 22:47:41 +00:00
|
|
|
OS<<" ProcItinKVSize = sizeof(ProcItinKV)/"
|
2005-10-31 17:16:01 +00:00
|
|
|
"sizeof(llvm::SubtargetInfoKV)\n";
|
|
|
|
OS<<"};\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// EmitData - Emits all stages and itineries, folding common patterns.
|
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::EmitData(raw_ostream &OS) {
|
2005-10-28 21:47:29 +00:00
|
|
|
std::map<std::string, unsigned> ItinClassesMap;
|
|
|
|
std::vector<std::vector<InstrItinerary> > ProcList;
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Enumerate all the itinerary classes
|
2005-11-01 20:06:59 +00:00
|
|
|
unsigned NItinClasses = CollectAllItinClasses(OS, ItinClassesMap);
|
|
|
|
// Make sure the rest is worth the effort
|
2006-01-27 01:41:55 +00:00
|
|
|
HasItineraries = NItinClasses != 1; // Ignore NoItinerary.
|
2005-11-01 20:06:59 +00:00
|
|
|
|
|
|
|
if (HasItineraries) {
|
|
|
|
// Emit the stage data
|
|
|
|
EmitStageData(OS, NItinClasses, ItinClassesMap, ProcList);
|
|
|
|
// Emit the processor itinerary data
|
|
|
|
EmitProcessorData(OS, ProcList);
|
|
|
|
// Emit the processor lookup data
|
|
|
|
EmitProcessorLookup(OS);
|
|
|
|
}
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
2005-10-26 17:30:34 +00:00
|
|
|
//
|
|
|
|
// ParseFeaturesFunction - Produces a subtarget specific function for parsing
|
|
|
|
// the subtarget features string.
|
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS) {
|
2005-10-28 21:47:29 +00:00
|
|
|
std::vector<Record*> Features =
|
|
|
|
Records.getAllDerivedDefinitions("SubtargetFeature");
|
2005-12-30 14:56:37 +00:00
|
|
|
std::sort(Features.begin(), Features.end(), LessRecord());
|
2005-10-26 17:30:34 +00:00
|
|
|
|
|
|
|
OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
|
2007-05-04 20:38:40 +00:00
|
|
|
<< "// subtarget options.\n"
|
2009-05-23 19:50:50 +00:00
|
|
|
<< "std::string llvm::";
|
2005-10-26 17:30:34 +00:00
|
|
|
OS << Target;
|
|
|
|
OS << "Subtarget::ParseSubtargetFeatures(const std::string &FS,\n"
|
2007-05-04 20:38:40 +00:00
|
|
|
<< " 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 21:47:29 +00:00
|
|
|
for (unsigned i = 0; i < Features.size(); i++) {
|
|
|
|
// Next record
|
|
|
|
Record *R = Features[i];
|
2007-05-04 20:38:40 +00:00
|
|
|
const std::string &Instance = R->getName();
|
|
|
|
const std::string &Value = R->getValueAsString("Value");
|
|
|
|
const std::string &Attribute = R->getValueAsString("Attribute");
|
2006-01-27 08:09:42 +00:00
|
|
|
|
2008-02-14 23:35:16 +00:00
|
|
|
if (Value=="true" || Value=="false")
|
|
|
|
OS << " if ((Bits & " << Instance << ") != 0) "
|
|
|
|
<< Attribute << " = " << Value << ";\n";
|
|
|
|
else
|
|
|
|
OS << " if ((Bits & " << Instance << ") != 0 && " << Attribute <<
|
|
|
|
" < " << Value << ") " << Attribute << " = " << Value << ";\n";
|
2005-10-26 17:30:34 +00:00
|
|
|
}
|
2007-05-04 20:38:40 +00:00
|
|
|
|
2005-11-01 20:06:59 +00:00
|
|
|
if (HasItineraries) {
|
|
|
|
OS << "\n"
|
|
|
|
<< " InstrItinerary *Itinerary = (InstrItinerary *)"
|
2007-05-04 20:38:40 +00:00
|
|
|
<< "Features.getInfo(ProcItinKV, ProcItinKVSize);\n"
|
|
|
|
<< " InstrItins = InstrItineraryData(Stages, Itinerary);\n";
|
2005-11-01 20:06:59 +00:00
|
|
|
}
|
2009-05-23 19:50:50 +00:00
|
|
|
|
|
|
|
OS << " return Features.getCPU();\n"
|
|
|
|
<< "}\n";
|
2005-10-26 17:30:34 +00:00
|
|
|
}
|
|
|
|
|
2009-05-23 19:50:50 +00:00
|
|
|
//
|
2005-10-25 15:16:36 +00:00
|
|
|
// SubtargetEmitter::run - Main subtarget enumeration emitter.
|
|
|
|
//
|
2009-07-03 00:10:29 +00:00
|
|
|
void SubtargetEmitter::run(raw_ostream &OS) {
|
2005-10-26 17:49:21 +00:00
|
|
|
Target = CodeGenTarget().getName();
|
2005-10-26 17:30:34 +00:00
|
|
|
|
2005-10-25 15:16:36 +00:00
|
|
|
EmitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
|
|
|
|
|
2005-10-27 19:47:21 +00:00
|
|
|
OS << "#include \"llvm/Target/SubtargetFeature.h\"\n";
|
|
|
|
OS << "#include \"llvm/Target/TargetInstrItineraries.h\"\n\n";
|
2005-10-25 15:16:36 +00:00
|
|
|
|
2005-10-26 17:30:34 +00:00
|
|
|
Enumeration(OS, "FuncUnit", true);
|
|
|
|
OS<<"\n";
|
2005-10-28 15:20:43 +00:00
|
|
|
// Enumeration(OS, "InstrItinClass", false);
|
|
|
|
// OS<<"\n";
|
2005-10-26 17:30:34 +00:00
|
|
|
Enumeration(OS, "SubtargetFeature", true);
|
|
|
|
OS<<"\n";
|
2005-10-25 15:16:36 +00:00
|
|
|
FeatureKeyValues(OS);
|
2005-10-26 17:30:34 +00:00
|
|
|
OS<<"\n";
|
2005-10-25 15:16:36 +00:00
|
|
|
CPUKeyValues(OS);
|
2005-10-26 17:30:34 +00:00
|
|
|
OS<<"\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
EmitData(OS);
|
|
|
|
OS<<"\n";
|
2005-10-26 17:30:34 +00:00
|
|
|
ParseFeaturesFunction(OS);
|
2005-10-25 15:16:36 +00:00
|
|
|
}
|