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
|
|
|
//
|
2010-09-09 18:18:55 +00:00
|
|
|
unsigned SubtargetEmitter::
|
|
|
|
CollectAllItinClasses(raw_ostream &OS,
|
|
|
|
std::map<std::string, unsigned> &ItinClassesMap,
|
|
|
|
std::vector<Record*> &ItinClassList) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2009-08-17 16:02:57 +00:00
|
|
|
// FormItineraryStageString - Compose a string containing the stage
|
|
|
|
// data initialization for the specified itinerary. N is the number
|
|
|
|
// of stages.
|
2005-10-27 19:47:21 +00:00
|
|
|
//
|
2010-04-18 20:31:01 +00:00
|
|
|
void SubtargetEmitter::FormItineraryStageString(const std::string &Name,
|
|
|
|
Record *ItinData,
|
2009-08-17 16:02:57 +00:00
|
|
|
std::string &ItinString,
|
|
|
|
unsigned &NStages) {
|
2005-10-28 21:47:29 +00:00
|
|
|
// 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
|
|
|
|
2010-04-07 18:19:32 +00:00
|
|
|
// Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind }
|
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
|
2010-04-18 20:31:01 +00:00
|
|
|
ItinString += Name + "FU::" + 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
|
|
|
|
2009-08-12 18:31:53 +00:00
|
|
|
int TimeInc = Stage->getValueAsInt("TimeInc");
|
|
|
|
ItinString += ", " + itostr(TimeInc);
|
|
|
|
|
2010-04-07 18:19:32 +00:00
|
|
|
int Kind = Stage->getValueAsInt("Kind");
|
|
|
|
ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind);
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2009-08-17 16:02:57 +00:00
|
|
|
// FormItineraryOperandCycleString - Compose a string containing the
|
|
|
|
// operand cycle initialization for the specified itinerary. N is the
|
|
|
|
// number of operands that has cycles specified.
|
2005-10-27 19:47:21 +00:00
|
|
|
//
|
2009-08-17 16:02:57 +00:00
|
|
|
void SubtargetEmitter::FormItineraryOperandCycleString(Record *ItinData,
|
|
|
|
std::string &ItinString, unsigned &NOperandCycles) {
|
|
|
|
// Get operand cycle list
|
|
|
|
const std::vector<int64_t> &OperandCycleList =
|
|
|
|
ItinData->getValueAsListOfInts("OperandCycles");
|
|
|
|
|
|
|
|
// For each operand cycle
|
|
|
|
unsigned N = NOperandCycles = OperandCycleList.size();
|
|
|
|
for (unsigned i = 0; i < N;) {
|
|
|
|
// Next operand cycle
|
|
|
|
const int OCycle = OperandCycleList[i];
|
|
|
|
|
|
|
|
ItinString += " " + itostr(OCycle);
|
|
|
|
if (++i < N) ItinString += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-28 23:50:49 +00:00
|
|
|
void SubtargetEmitter::FormItineraryBypassString(const std::string &Name,
|
|
|
|
Record *ItinData,
|
|
|
|
std::string &ItinString,
|
|
|
|
unsigned NOperandCycles) {
|
|
|
|
const std::vector<Record*> &BypassList =
|
|
|
|
ItinData->getValueAsListOfDefs("Bypasses");
|
|
|
|
unsigned N = BypassList.size();
|
2010-09-29 22:42:35 +00:00
|
|
|
unsigned i = 0;
|
|
|
|
for (; i < N;) {
|
2010-09-28 23:50:49 +00:00
|
|
|
ItinString += Name + "Bypass::" + BypassList[i]->getName();
|
2010-09-29 22:42:35 +00:00
|
|
|
if (++i < NOperandCycles) ItinString += ", ";
|
2010-09-28 23:50:49 +00:00
|
|
|
}
|
2010-09-29 22:42:35 +00:00
|
|
|
for (; i < NOperandCycles;) {
|
2010-09-28 23:50:49 +00:00
|
|
|
ItinString += " 0";
|
2010-09-29 22:42:35 +00:00
|
|
|
if (++i < NOperandCycles) ItinString += ", ";
|
2010-09-28 23:50:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
//
|
|
|
|
// EmitStageAndOperandCycleData - Generate unique itinerary stages and
|
|
|
|
// operand cycle tables. Record itineraries for processors.
|
|
|
|
//
|
|
|
|
void SubtargetEmitter::EmitStageAndOperandCycleData(raw_ostream &OS,
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned NItinClasses,
|
2010-09-09 18:18:55 +00:00
|
|
|
std::map<std::string, unsigned> &ItinClassesMap,
|
|
|
|
std::vector<Record*> &ItinClassList,
|
2005-10-28 21:47:29 +00:00
|
|
|
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
|
|
|
|
2010-04-18 20:31:01 +00:00
|
|
|
// Emit functional units for all the itineraries.
|
|
|
|
for (unsigned i = 0, N = ProcItinList.size(); i < N; ++i) {
|
|
|
|
// Next record
|
|
|
|
Record *Proc = ProcItinList[i];
|
|
|
|
|
|
|
|
std::vector<Record*> FUs = Proc->getValueAsListOfDefs("FU");
|
|
|
|
if (FUs.empty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const std::string &Name = Proc->getName();
|
|
|
|
OS << "\n// Functional units for itineraries \"" << Name << "\"\n"
|
|
|
|
<< "namespace " << Name << "FU {\n";
|
|
|
|
|
|
|
|
for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j)
|
|
|
|
OS << " const unsigned " << FUs[j]->getName()
|
|
|
|
<< " = 1 << " << j << ";\n";
|
|
|
|
|
|
|
|
OS << "}\n";
|
2010-09-28 23:50:49 +00:00
|
|
|
|
|
|
|
std::vector<Record*> BPs = Proc->getValueAsListOfDefs("BP");
|
2010-09-29 22:42:35 +00:00
|
|
|
if (BPs.size()) {
|
|
|
|
OS << "\n// Pipeline forwarding pathes for itineraries \"" << Name
|
|
|
|
<< "\"\n" << "namespace " << Name << "Bypass {\n";
|
2010-09-28 23:50:49 +00:00
|
|
|
|
2010-09-29 22:42:35 +00:00
|
|
|
OS << " const unsigned NoBypass = 0;\n";
|
|
|
|
for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j)
|
|
|
|
OS << " const unsigned " << BPs[j]->getName()
|
|
|
|
<< " = 1 << " << j << ";\n";
|
2010-09-28 23:50:49 +00:00
|
|
|
|
2010-09-29 22:42:35 +00:00
|
|
|
OS << "}\n";
|
|
|
|
}
|
2010-04-18 20:31:01 +00:00
|
|
|
}
|
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Begin stages table
|
2010-04-18 20:31:01 +00:00
|
|
|
std::string StageTable = "\nstatic const llvm::InstrStage Stages[] = {\n";
|
2010-04-07 18:19:32 +00:00
|
|
|
StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
// Begin operand cycle table
|
|
|
|
std::string OperandCycleTable = "static const unsigned OperandCycles[] = {\n";
|
|
|
|
OperandCycleTable += " 0, // No itinerary\n";
|
2010-09-28 23:50:49 +00:00
|
|
|
|
|
|
|
// Begin pipeline bypass table
|
2010-09-29 22:42:35 +00:00
|
|
|
std::string BypassTable = "static const unsigned ForwardingPathes[] = {\n";
|
2010-09-28 23:50:49 +00:00
|
|
|
BypassTable += " 0, // No itinerary\n";
|
2009-08-17 16:02:57 +00:00
|
|
|
|
|
|
|
unsigned StageCount = 1, OperandCycleCount = 1;
|
|
|
|
unsigned ItinStageEnum = 1, ItinOperandCycleEnum = 1;
|
2010-09-29 22:42:35 +00:00
|
|
|
std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
|
2005-10-28 21:47:29 +00:00
|
|
|
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
|
2009-08-17 16:02:57 +00:00
|
|
|
std::string ItinStageString;
|
2005-10-28 21:47:29 +00:00
|
|
|
unsigned NStages;
|
2010-04-18 20:31:01 +00:00
|
|
|
FormItineraryStageString(Name, ItinData, ItinStageString, NStages);
|
2009-08-17 16:02:57 +00:00
|
|
|
|
|
|
|
// Get string and operand cycle count
|
|
|
|
std::string ItinOperandCycleString;
|
|
|
|
unsigned NOperandCycles;
|
|
|
|
FormItineraryOperandCycleString(ItinData, ItinOperandCycleString,
|
|
|
|
NOperandCycles);
|
|
|
|
|
2010-09-28 23:50:49 +00:00
|
|
|
std::string ItinBypassString;
|
|
|
|
FormItineraryBypassString(Name, ItinData, ItinBypassString,
|
|
|
|
NOperandCycles);
|
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
// Check to see if stage already exists and create if it doesn't
|
|
|
|
unsigned FindStage = 0;
|
|
|
|
if (NStages > 0) {
|
|
|
|
FindStage = ItinStageMap[ItinStageString];
|
|
|
|
if (FindStage == 0) {
|
|
|
|
// Emit as { cycles, u1 | u2 | ... | un, timeinc }, // index
|
|
|
|
StageTable += ItinStageString + ", // " + itostr(ItinStageEnum) + "\n";
|
|
|
|
// Record Itin class number.
|
|
|
|
ItinStageMap[ItinStageString] = FindStage = StageCount;
|
|
|
|
StageCount += NStages;
|
|
|
|
ItinStageEnum++;
|
|
|
|
}
|
|
|
|
}
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
// Check to see if operand cycle already exists and create if it doesn't
|
|
|
|
unsigned FindOperandCycle = 0;
|
|
|
|
if (NOperandCycles > 0) {
|
2010-09-29 22:42:35 +00:00
|
|
|
std::string ItinOperandString = ItinOperandCycleString+ItinBypassString;
|
|
|
|
FindOperandCycle = ItinOperandMap[ItinOperandString];
|
2009-08-17 16:02:57 +00:00
|
|
|
if (FindOperandCycle == 0) {
|
|
|
|
// Emit as cycle, // index
|
|
|
|
OperandCycleTable += ItinOperandCycleString + ", // " +
|
|
|
|
itostr(ItinOperandCycleEnum) + "\n";
|
|
|
|
// Record Itin class number.
|
2010-09-29 22:42:35 +00:00
|
|
|
ItinOperandMap[ItinOperandCycleString] =
|
2009-08-17 16:02:57 +00:00
|
|
|
FindOperandCycle = OperandCycleCount;
|
2010-09-28 23:50:49 +00:00
|
|
|
|
|
|
|
// Emit as bypass, // index
|
|
|
|
BypassTable += ItinBypassString + ", // " +
|
|
|
|
itostr(ItinOperandCycleEnum) + "\n";
|
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
OperandCycleCount += NOperandCycles;
|
|
|
|
ItinOperandCycleEnum++;
|
|
|
|
}
|
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();
|
2009-08-17 16:02:57 +00:00
|
|
|
unsigned Find = ItinClassesMap[Name];
|
2005-10-28 15:20:43 +00:00
|
|
|
|
2010-09-09 18:18:55 +00:00
|
|
|
// Set up itinerary as location and location + stage count
|
|
|
|
unsigned NumUOps = ItinClassList[Find]->getValueAsInt("NumMicroOps");
|
|
|
|
InstrItinerary Intinerary = { NumUOps, FindStage, FindStage + NStages,
|
|
|
|
FindOperandCycle,
|
|
|
|
FindOperandCycle + NOperandCycles};
|
|
|
|
|
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
|
|
|
}
|
2010-09-28 23:50:49 +00:00
|
|
|
|
2005-11-03 22:47:41 +00:00
|
|
|
// Closing stage
|
2010-04-07 18:19:32 +00:00
|
|
|
StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End itinerary\n";
|
2009-08-17 16:02:57 +00:00
|
|
|
StageTable += "};\n";
|
|
|
|
|
|
|
|
// Closing operand cycles
|
|
|
|
OperandCycleTable += " 0 // End itinerary\n";
|
|
|
|
OperandCycleTable += "};\n";
|
|
|
|
|
2010-09-28 23:50:49 +00:00
|
|
|
BypassTable += " 0 // End itinerary\n";
|
|
|
|
BypassTable += "};\n";
|
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
// Emit tables.
|
|
|
|
OS << StageTable;
|
|
|
|
OS << OperandCycleTable;
|
2010-09-28 23:50:49 +00:00
|
|
|
OS << BypassTable;
|
2005-11-01 20:06:59 +00:00
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
// Emit size of tables
|
2005-11-01 20:06:59 +00:00
|
|
|
OS<<"\nenum {\n";
|
2009-08-17 16:02:57 +00:00
|
|
|
OS<<" StagesSize = sizeof(Stages)/sizeof(llvm::InstrStage),\n";
|
|
|
|
OS<<" OperandCyclesSize = sizeof(OperandCycles)/sizeof(unsigned)\n";
|
2005-11-01 20:06:59 +00:00
|
|
|
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++;
|
2009-09-24 20:22:50 +00:00
|
|
|
for (unsigned j = 0, M = ItinList.size(); j < M; ++j) {
|
2005-10-28 21:47:29 +00:00
|
|
|
InstrItinerary &Intinerary = ItinList[j];
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2009-08-17 16:02:57 +00:00
|
|
|
// Emit in the form of
|
|
|
|
// { firstStage, lastStage, firstCycle, lastCycle } // index
|
|
|
|
if (Intinerary.FirstStage == 0) {
|
2010-09-09 18:18:55 +00:00
|
|
|
OS << " { 1, 0, 0, 0, 0 }";
|
2005-10-27 19:47:21 +00:00
|
|
|
} else {
|
2010-09-09 18:18:55 +00:00
|
|
|
OS << " { " <<
|
|
|
|
Intinerary.NumMicroOps << ", " <<
|
|
|
|
Intinerary.FirstStage << ", " <<
|
2009-08-17 16:02:57 +00:00
|
|
|
Intinerary.LastStage << ", " <<
|
|
|
|
Intinerary.FirstOperandCycle << ", " <<
|
|
|
|
Intinerary.LastOperandCycle << " }";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
|
|
|
|
2009-09-24 20:22:50 +00:00
|
|
|
OS << ", // " << j << "\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
}
|
2005-10-28 15:20:43 +00:00
|
|
|
|
|
|
|
// End processor itinerary table
|
2010-09-09 18:18:55 +00:00
|
|
|
OS << " { 1, ~0U, ~0U, ~0U, ~0U } // end marker\n";
|
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;
|
2010-09-09 18:18:55 +00:00
|
|
|
// Gather and sort all itinerary classes
|
|
|
|
std::vector<Record*> ItinClassList =
|
|
|
|
Records.getAllDerivedDefinitions("InstrItinClass");
|
|
|
|
std::sort(ItinClassList.begin(), ItinClassList.end(), LessRecord());
|
2005-10-27 19:47:21 +00:00
|
|
|
|
2005-10-28 15:20:43 +00:00
|
|
|
// Enumerate all the itinerary classes
|
2010-09-09 18:18:55 +00:00
|
|
|
unsigned NItinClasses = CollectAllItinClasses(OS, ItinClassesMap,
|
|
|
|
ItinClassList);
|
2005-11-01 20:06:59 +00:00
|
|
|
// 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) {
|
2010-09-09 18:18:55 +00:00
|
|
|
std::vector<std::vector<InstrItinerary> > ProcList;
|
2005-11-01 20:06:59 +00:00
|
|
|
// Emit the stage data
|
2010-09-09 18:18:55 +00:00
|
|
|
EmitStageAndOperandCycleData(OS, NItinClasses, ItinClassesMap,
|
|
|
|
ItinClassList, ProcList);
|
2005-11-01 20:06:59 +00:00
|
|
|
// 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"
|
2010-01-05 17:47:41 +00:00
|
|
|
<< " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n"
|
|
|
|
<< " DEBUG(dbgs() << \"\\nCPU:\" << CPU);\n"
|
2007-05-04 20:38:40 +00:00
|
|
|
<< " 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"
|
2010-09-29 22:42:35 +00:00
|
|
|
<< " InstrItins = InstrItineraryData(Stages, OperandCycles, "
|
|
|
|
<< "ForwardingPathes, 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);
|
|
|
|
|
2009-11-11 03:23:46 +00:00
|
|
|
OS << "#include \"llvm/Support/Debug.h\"\n";
|
|
|
|
OS << "#include \"llvm/Support/raw_ostream.h\"\n";
|
2005-10-27 19:47:21 +00:00
|
|
|
OS << "#include \"llvm/Target/SubtargetFeature.h\"\n";
|
|
|
|
OS << "#include \"llvm/Target/TargetInstrItineraries.h\"\n\n";
|
2010-04-18 20:31:01 +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
|
|
|
}
|