2005-10-22 03:00:04 +08:00
|
|
|
//===- SubtargetEmitter.cpp - Generate subtarget enumerations -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:37:13 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-10-22 03:00:04 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-03-03 10:04:07 +08:00
|
|
|
// This tablegen backend emits subtarget enumerations.
|
2005-10-22 03:00:04 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "CodeGenTarget.h"
|
2012-07-07 12:00:00 +08:00
|
|
|
#include "CodeGenSchedule.h"
|
2005-10-22 03:00:04 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2012-06-11 23:37:55 +08:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
2005-10-22 03:00:04 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2012-06-11 23:37:55 +08:00
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2005-10-28 09:43:09 +08:00
|
|
|
#include <algorithm>
|
2012-06-11 23:37:55 +08:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2005-10-22 03:00:04 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2012-06-11 23:37:55 +08:00
|
|
|
namespace {
|
|
|
|
class SubtargetEmitter {
|
|
|
|
|
|
|
|
RecordKeeper &Records;
|
2012-07-07 12:00:00 +08:00
|
|
|
CodeGenSchedModels &SchedModels;
|
2012-06-11 23:37:55 +08:00
|
|
|
std::string Target;
|
|
|
|
|
|
|
|
void Enumeration(raw_ostream &OS, const char *ClassName, bool isBits);
|
|
|
|
unsigned FeatureKeyValues(raw_ostream &OS);
|
|
|
|
unsigned CPUKeyValues(raw_ostream &OS);
|
|
|
|
void FormItineraryStageString(const std::string &Names,
|
|
|
|
Record *ItinData, std::string &ItinString,
|
|
|
|
unsigned &NStages);
|
|
|
|
void FormItineraryOperandCycleString(Record *ItinData, std::string &ItinString,
|
|
|
|
unsigned &NOperandCycles);
|
|
|
|
void FormItineraryBypassString(const std::string &Names,
|
|
|
|
Record *ItinData,
|
|
|
|
std::string &ItinString, unsigned NOperandCycles);
|
2012-07-07 12:00:00 +08:00
|
|
|
void EmitStageAndOperandCycleData(raw_ostream &OS,
|
|
|
|
std::vector<std::vector<InstrItinerary> >
|
|
|
|
&ProcItinLists);
|
|
|
|
void EmitItineraries(raw_ostream &OS,
|
|
|
|
std::vector<std::vector<InstrItinerary> >
|
|
|
|
&ProcItinLists);
|
|
|
|
void EmitProcessorProp(raw_ostream &OS, const Record *R, const char *Name,
|
2012-06-11 23:37:55 +08:00
|
|
|
char Separator);
|
2012-07-07 12:00:00 +08:00
|
|
|
void EmitProcessorModels(raw_ostream &OS);
|
2012-06-11 23:37:55 +08:00
|
|
|
void EmitProcessorLookup(raw_ostream &OS);
|
2012-07-07 12:00:00 +08:00
|
|
|
void EmitSchedModel(raw_ostream &OS);
|
2012-06-11 23:37:55 +08:00
|
|
|
void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures,
|
|
|
|
unsigned NumProcs);
|
|
|
|
|
|
|
|
public:
|
2012-07-07 12:00:00 +08:00
|
|
|
SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT):
|
|
|
|
Records(R), SchedModels(TGT.getSchedModels()), Target(TGT.getName()) {}
|
2012-06-11 23:37:55 +08:00
|
|
|
|
|
|
|
void run(raw_ostream &o);
|
|
|
|
|
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
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
|
|
|
//
|
2009-07-03 08:10:29 +08:00
|
|
|
void SubtargetEmitter::Enumeration(raw_ostream &OS,
|
2005-10-27 01:30:34 +08:00
|
|
|
const char *ClassName,
|
|
|
|
bool isBits) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get all records of class and sort
|
2005-10-29 05:47:29 +08:00
|
|
|
std::vector<Record*> DefList = Records.getAllDerivedDefinitions(ClassName);
|
2005-12-30 22:56:37 +08:00
|
|
|
std::sort(DefList.begin(), DefList.end(), LessRecord());
|
2005-10-22 03:00:04 +08:00
|
|
|
|
2011-04-16 03:35:46 +08:00
|
|
|
unsigned N = DefList.size();
|
2011-07-02 04:45:01 +08:00
|
|
|
if (N == 0)
|
|
|
|
return;
|
2011-04-16 03:35:46 +08:00
|
|
|
if (N > 64) {
|
|
|
|
errs() << "Too many (> 64) subtarget features!\n";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-07-02 04:45:01 +08:00
|
|
|
OS << "namespace " << Target << " {\n";
|
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// For bit flag enumerations with more than 32 items, emit constants.
|
|
|
|
// Emit an enum for everything else.
|
|
|
|
if (isBits && N > 32) {
|
|
|
|
// For each record
|
|
|
|
for (unsigned i = 0; i < N; i++) {
|
|
|
|
// Next record
|
|
|
|
Record *Def = DefList[i];
|
2011-07-02 04:45:01 +08:00
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// Get and emit name and expression (1 << i)
|
|
|
|
OS << " const uint64_t " << Def->getName() << " = 1ULL << " << i << ";\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Open enumeration
|
|
|
|
OS << "enum {\n";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// For each record
|
|
|
|
for (unsigned i = 0; i < N;) {
|
|
|
|
// Next record
|
|
|
|
Record *Def = DefList[i];
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// Get and emit name
|
|
|
|
OS << " " << Def->getName();
|
2005-10-28 23:20:43 +08:00
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// If bit flags then emit expression (1 << i)
|
|
|
|
if (isBits) OS << " = " << " 1ULL << " << i;
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// Depending on 'if more in the list' emit comma
|
|
|
|
if (++i < N) OS << ",";
|
|
|
|
|
|
|
|
OS << "\n";
|
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-01-04 07:04:28 +08:00
|
|
|
// Close enumeration
|
|
|
|
OS << "};\n";
|
|
|
|
}
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
OS << "}\n";
|
2005-10-25 23:16:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2007-05-05 04:38:40 +08:00
|
|
|
// FeatureKeyValues - Emit data of all the subtarget features. Used by the
|
|
|
|
// command line.
|
2005-10-25 23:16:36 +08:00
|
|
|
//
|
2011-07-02 04:45:01 +08:00
|
|
|
unsigned SubtargetEmitter::FeatureKeyValues(raw_ostream &OS) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Gather and sort all the features
|
2005-10-29 05:47:29 +08:00
|
|
|
std::vector<Record*> FeatureList =
|
|
|
|
Records.getAllDerivedDefinitions("SubtargetFeature");
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
if (FeatureList.empty())
|
|
|
|
return 0;
|
|
|
|
|
2008-09-12 01:05:32 +08:00
|
|
|
std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
|
2005-10-25 23:16:36 +08:00
|
|
|
|
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"
|
2011-10-23 00:50:00 +08:00
|
|
|
<< "extern const llvm::SubtargetFeatureKV " << Target
|
|
|
|
<< "FeatureKV[] = {\n";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each feature
|
2011-07-02 04:45:01 +08:00
|
|
|
unsigned NumFeatures = 0;
|
2006-12-13 04:55:58 +08:00
|
|
|
for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
|
2005-10-29 05:47:29 +08:00
|
|
|
// Next feature
|
|
|
|
Record *Feature = FeatureList[i];
|
|
|
|
|
2007-05-05 04:38:40 +08:00
|
|
|
const std::string &Name = Feature->getName();
|
|
|
|
const std::string &CommandLineName = Feature->getValueAsString("Name");
|
|
|
|
const std::string &Desc = Feature->getValueAsString("Desc");
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2006-12-13 04:55:58 +08:00
|
|
|
if (CommandLineName.empty()) continue;
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2009-03-27 00:17:51 +08:00
|
|
|
// Emit as { "feature", "description", featureEnum, i1 | i2 | ... | in }
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << " { "
|
2005-10-29 05:47:29 +08:00
|
|
|
<< "\"" << CommandLineName << "\", "
|
2005-10-25 23:16:36 +08:00
|
|
|
<< "\"" << Desc << "\", "
|
2011-07-02 04:45:01 +08:00
|
|
|
<< Target << "::" << Name << ", ";
|
2007-05-05 04:38:40 +08:00
|
|
|
|
2011-04-01 09:56:55 +08:00
|
|
|
const std::vector<Record*> &ImpliesList =
|
2007-05-05 04:38:40 +08:00
|
|
|
Feature->getValueAsListOfDefs("Implies");
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2007-05-05 04:38:40 +08:00
|
|
|
if (ImpliesList.empty()) {
|
2011-04-16 03:35:46 +08:00
|
|
|
OS << "0ULL";
|
2007-05-05 04:38:40 +08:00
|
|
|
} else {
|
|
|
|
for (unsigned j = 0, M = ImpliesList.size(); j < M;) {
|
2011-07-02 04:45:01 +08:00
|
|
|
OS << Target << "::" << ImpliesList[j]->getName();
|
2007-05-05 04:38:40 +08:00
|
|
|
if (++j < M) OS << " | ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << " }";
|
2011-07-02 04:45:01 +08:00
|
|
|
++NumFeatures;
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
// Depending on 'if more in the list' emit comma
|
2006-12-13 04:55:58 +08:00
|
|
|
if ((i + 1) < N) OS << ",";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
OS << "\n";
|
2005-10-25 23:16:36 +08:00
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// End feature table
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "};\n";
|
|
|
|
|
2011-07-02 04:45:01 +08:00
|
|
|
return NumFeatures;
|
2005-10-25 23:16:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// CPUKeyValues - Emit data of all the subtarget processors. Used by command
|
|
|
|
// line.
|
|
|
|
//
|
2011-07-02 04:45:01 +08:00
|
|
|
unsigned SubtargetEmitter::CPUKeyValues(raw_ostream &OS) {
|
2005-10-28 23:20:43 +08:00
|
|
|
// Gather and sort processor information
|
2005-10-29 05:47:29 +08:00
|
|
|
std::vector<Record*> ProcessorList =
|
|
|
|
Records.getAllDerivedDefinitions("Processor");
|
2005-12-30 22:56:37 +08:00
|
|
|
std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
|
2005-10-25 23:16:36 +08:00
|
|
|
|
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"
|
2011-10-23 00:50:00 +08:00
|
|
|
<< "extern const llvm::SubtargetFeatureKV " << Target
|
|
|
|
<< "SubTypeKV[] = {\n";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each processor
|
2005-10-29 05:47:29 +08:00
|
|
|
for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
|
|
|
|
// Next processor
|
|
|
|
Record *Processor = ProcessorList[i];
|
|
|
|
|
2007-05-05 04:38:40 +08:00
|
|
|
const std::string &Name = Processor->getValueAsString("Name");
|
2011-04-01 09:56:55 +08:00
|
|
|
const std::vector<Record*> &FeatureList =
|
2005-10-29 06:49:02 +08:00
|
|
|
Processor->getValueAsListOfDefs("Features");
|
2011-04-01 09:56:55 +08:00
|
|
|
|
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\", ";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
if (FeatureList.empty()) {
|
2011-04-16 03:35:46 +08:00
|
|
|
OS << "0ULL";
|
2005-10-25 23:16:36 +08:00
|
|
|
} else {
|
2005-10-29 05:47:29 +08:00
|
|
|
for (unsigned j = 0, M = FeatureList.size(); j < M;) {
|
2011-07-02 04:45:01 +08:00
|
|
|
OS << Target << "::" << FeatureList[j]->getName();
|
2005-10-29 05:47:29 +08:00
|
|
|
if (++j < M) OS << " | ";
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2007-05-05 04:38:40 +08:00
|
|
|
// The "0" is for the "implies" section of this data structure.
|
2011-04-16 03:35:46 +08:00
|
|
|
OS << ", 0ULL }";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
// Depending on 'if more in the list' emit comma
|
2005-10-29 05:47:29 +08:00
|
|
|
if (++i < N) OS << ",";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
OS << "\n";
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// End processor table
|
2005-10-25 23:16:36 +08:00
|
|
|
OS << "};\n";
|
|
|
|
|
2011-07-02 04:45:01 +08:00
|
|
|
return ProcessorList.size();
|
2005-10-22 03:00:04 +08:00
|
|
|
}
|
2005-10-25 23:16:36 +08:00
|
|
|
|
2005-10-28 03:47:21 +08:00
|
|
|
//
|
2009-08-18 00:02:57 +08:00
|
|
|
// FormItineraryStageString - Compose a string containing the stage
|
|
|
|
// data initialization for the specified itinerary. N is the number
|
|
|
|
// of stages.
|
2005-10-28 03:47:21 +08:00
|
|
|
//
|
2010-04-19 04:31:01 +08:00
|
|
|
void SubtargetEmitter::FormItineraryStageString(const std::string &Name,
|
|
|
|
Record *ItinData,
|
2009-08-18 00:02:57 +08:00
|
|
|
std::string &ItinString,
|
|
|
|
unsigned &NStages) {
|
2005-10-29 05:47:29 +08:00
|
|
|
// Get states list
|
2007-05-05 04:38:40 +08:00
|
|
|
const std::vector<Record*> &StageList =
|
|
|
|
ItinData->getValueAsListOfDefs("Stages");
|
2005-10-28 23:20:43 +08:00
|
|
|
|
|
|
|
// For each stage
|
2005-10-29 05:47:29 +08:00
|
|
|
unsigned N = NStages = StageList.size();
|
2007-04-22 17:04:24 +08:00
|
|
|
for (unsigned i = 0; i < N;) {
|
2005-10-29 05:47:29 +08:00
|
|
|
// Next stage
|
2007-05-05 04:38:40 +08:00
|
|
|
const Record *Stage = StageList[i];
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2010-04-08 02:19:32 +08:00
|
|
|
// Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind }
|
2005-10-28 03:47:21 +08:00
|
|
|
int Cycles = Stage->getValueAsInt("Cycles");
|
2005-11-04 06:47:41 +08:00
|
|
|
ItinString += " { " + itostr(Cycles) + ", ";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
// Get unit list
|
2007-05-05 04:38:40 +08:00
|
|
|
const std::vector<Record*> &UnitList = Stage->getValueAsListOfDefs("Units");
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// For each unit
|
2005-10-29 05:47:29 +08:00
|
|
|
for (unsigned j = 0, M = UnitList.size(); j < M;) {
|
|
|
|
// Add name and bitwise or
|
2010-04-19 04:31:01 +08:00
|
|
|
ItinString += Name + "FU::" + UnitList[j]->getName();
|
2005-10-29 05:47:29 +08:00
|
|
|
if (++j < M) ItinString += " | ";
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2009-08-13 02:31:53 +08:00
|
|
|
int TimeInc = Stage->getValueAsInt("TimeInc");
|
|
|
|
ItinString += ", " + itostr(TimeInc);
|
|
|
|
|
2010-04-08 02:19:32 +08:00
|
|
|
int Kind = Stage->getValueAsInt("Kind");
|
|
|
|
ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind);
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Close off stage
|
|
|
|
ItinString += " }";
|
2007-04-22 17:04:24 +08:00
|
|
|
if (++i < N) ItinString += ", ";
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2009-08-18 00:02:57 +08: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-28 03:47:21 +08:00
|
|
|
//
|
2009-08-18 00:02:57 +08: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];
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2009-08-18 00:02:57 +08:00
|
|
|
ItinString += " " + itostr(OCycle);
|
|
|
|
if (++i < N) ItinString += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-29 07:50:49 +08: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-30 06:42:35 +08:00
|
|
|
unsigned i = 0;
|
|
|
|
for (; i < N;) {
|
2010-09-29 07:50:49 +08:00
|
|
|
ItinString += Name + "Bypass::" + BypassList[i]->getName();
|
2010-09-30 06:42:35 +08:00
|
|
|
if (++i < NOperandCycles) ItinString += ", ";
|
2010-09-29 07:50:49 +08:00
|
|
|
}
|
2010-09-30 06:42:35 +08:00
|
|
|
for (; i < NOperandCycles;) {
|
2010-09-29 07:50:49 +08:00
|
|
|
ItinString += " 0";
|
2010-09-30 06:42:35 +08:00
|
|
|
if (++i < NOperandCycles) ItinString += ", ";
|
2010-09-29 07:50:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-18 00:02:57 +08:00
|
|
|
//
|
2012-07-07 12:00:00 +08:00
|
|
|
// EmitStageAndOperandCycleData - Generate unique itinerary stages and operand
|
|
|
|
// cycle tables. Create a list of InstrItinerary objects (ProcItinLists) indexed
|
|
|
|
// by CodeGenSchedClass::Index.
|
2009-08-18 00:02:57 +08:00
|
|
|
//
|
2012-07-07 12:00:00 +08:00
|
|
|
void SubtargetEmitter::
|
|
|
|
EmitStageAndOperandCycleData(raw_ostream &OS,
|
|
|
|
std::vector<std::vector<InstrItinerary> >
|
|
|
|
&ProcItinLists) {
|
2005-10-28 23:20:43 +08:00
|
|
|
|
2012-07-10 04:43:03 +08:00
|
|
|
// Multiple processor models may share an itinerary record. Emit it once.
|
|
|
|
SmallPtrSet<Record*, 8> ItinsDefSet;
|
|
|
|
|
2010-04-19 04:31:01 +08:00
|
|
|
// Emit functional units for all the itineraries.
|
2012-07-07 12:00:00 +08:00
|
|
|
for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
|
|
|
|
PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
|
2010-04-19 04:31:01 +08:00
|
|
|
|
2012-07-10 04:43:03 +08:00
|
|
|
if (!ItinsDefSet.insert(PI->ItinsDef))
|
|
|
|
continue;
|
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
std::vector<Record*> FUs = PI->ItinsDef->getValueAsListOfDefs("FU");
|
2010-04-19 04:31:01 +08:00
|
|
|
if (FUs.empty())
|
|
|
|
continue;
|
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
const std::string &Name = PI->ItinsDef->getName();
|
|
|
|
OS << "\n// Functional units for \"" << Name << "\"\n"
|
2010-04-19 04:31:01 +08:00
|
|
|
<< "namespace " << Name << "FU {\n";
|
|
|
|
|
|
|
|
for (unsigned j = 0, FUN = FUs.size(); j < FUN; ++j)
|
2012-06-23 04:27:13 +08:00
|
|
|
OS << " const unsigned " << FUs[j]->getName()
|
|
|
|
<< " = 1 << " << j << ";\n";
|
2010-04-19 04:31:01 +08:00
|
|
|
|
|
|
|
OS << "}\n";
|
2010-09-29 07:50:49 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
std::vector<Record*> BPs = PI->ItinsDef->getValueAsListOfDefs("BP");
|
2010-09-30 06:42:35 +08:00
|
|
|
if (BPs.size()) {
|
|
|
|
OS << "\n// Pipeline forwarding pathes for itineraries \"" << Name
|
|
|
|
<< "\"\n" << "namespace " << Name << "Bypass {\n";
|
2010-09-29 07:50:49 +08:00
|
|
|
|
2011-10-23 00:50:00 +08:00
|
|
|
OS << " const unsigned NoBypass = 0;\n";
|
2010-09-30 06:42:35 +08:00
|
|
|
for (unsigned j = 0, BPN = BPs.size(); j < BPN; ++j)
|
2011-10-23 00:50:00 +08:00
|
|
|
OS << " const unsigned " << BPs[j]->getName()
|
2010-09-30 06:42:35 +08:00
|
|
|
<< " = 1 << " << j << ";\n";
|
2010-09-29 07:50:49 +08:00
|
|
|
|
2010-09-30 06:42:35 +08:00
|
|
|
OS << "}\n";
|
|
|
|
}
|
2010-04-19 04:31:01 +08:00
|
|
|
}
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Begin stages table
|
2011-10-23 00:50:00 +08:00
|
|
|
std::string StageTable = "\nextern const llvm::InstrStage " + Target +
|
|
|
|
"Stages[] = {\n";
|
2010-04-08 02:19:32 +08:00
|
|
|
StageTable += " { 0, 0, 0, llvm::InstrStage::Required }, // No itinerary\n";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2009-08-18 00:02:57 +08:00
|
|
|
// Begin operand cycle table
|
2011-10-23 00:50:00 +08:00
|
|
|
std::string OperandCycleTable = "extern const unsigned " + Target +
|
2011-07-02 04:45:01 +08:00
|
|
|
"OperandCycles[] = {\n";
|
2009-08-18 00:02:57 +08:00
|
|
|
OperandCycleTable += " 0, // No itinerary\n";
|
2010-09-29 07:50:49 +08:00
|
|
|
|
|
|
|
// Begin pipeline bypass table
|
2011-10-23 00:50:00 +08:00
|
|
|
std::string BypassTable = "extern const unsigned " + Target +
|
2012-07-07 11:59:48 +08:00
|
|
|
"ForwardingPaths[] = {\n";
|
2012-07-07 12:00:00 +08:00
|
|
|
BypassTable += " 0, // No itinerary\n";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// For each Itinerary across all processors, add a unique entry to the stages,
|
|
|
|
// operand cycles, and pipepine bypess tables. Then add the new Itinerary
|
|
|
|
// object with computed offsets to the ProcItinLists result.
|
2009-08-18 00:02:57 +08:00
|
|
|
unsigned StageCount = 1, OperandCycleCount = 1;
|
2010-09-30 06:42:35 +08:00
|
|
|
std::map<std::string, unsigned> ItinStageMap, ItinOperandMap;
|
2012-07-07 12:00:00 +08:00
|
|
|
for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
|
|
|
|
PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
|
|
|
|
const CodeGenProcModel &ProcModel = *PI;
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// Add process itinerary to the list.
|
|
|
|
ProcItinLists.resize(ProcItinLists.size()+1);
|
2012-06-22 11:58:51 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// If this processor defines no itineraries, then leave the itinerary list
|
|
|
|
// empty.
|
|
|
|
std::vector<InstrItinerary> &ItinList = ProcItinLists.back();
|
|
|
|
if (ProcModel.ItinDefList.empty())
|
2012-06-22 11:58:51 +08:00
|
|
|
continue;
|
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// Reserve index==0 for NoItinerary.
|
|
|
|
ItinList.resize(SchedModels.numItineraryClasses()+1);
|
|
|
|
|
|
|
|
const std::string &Name = ProcModel.ItinsDef->getName();
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
// For each itinerary data
|
2012-07-07 12:00:00 +08:00
|
|
|
for (unsigned SchedClassIdx = 0,
|
|
|
|
SchedClassEnd = ProcModel.ItinDefList.size();
|
|
|
|
SchedClassIdx < SchedClassEnd; ++SchedClassIdx) {
|
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
// Next itinerary data
|
2012-07-07 12:00:00 +08:00
|
|
|
Record *ItinData = ProcModel.ItinDefList[SchedClassIdx];
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get string and stage count
|
2009-08-18 00:02:57 +08:00
|
|
|
std::string ItinStageString;
|
2012-07-07 12:00:00 +08:00
|
|
|
unsigned NStages = 0;
|
|
|
|
if (ItinData)
|
|
|
|
FormItineraryStageString(Name, ItinData, ItinStageString, NStages);
|
2009-08-18 00:02:57 +08:00
|
|
|
|
|
|
|
// Get string and operand cycle count
|
|
|
|
std::string ItinOperandCycleString;
|
2012-07-07 12:00:00 +08:00
|
|
|
unsigned NOperandCycles = 0;
|
2010-09-29 07:50:49 +08:00
|
|
|
std::string ItinBypassString;
|
2012-07-07 12:00:00 +08:00
|
|
|
if (ItinData) {
|
|
|
|
FormItineraryOperandCycleString(ItinData, ItinOperandCycleString,
|
|
|
|
NOperandCycles);
|
|
|
|
|
|
|
|
FormItineraryBypassString(Name, ItinData, ItinBypassString,
|
|
|
|
NOperandCycles);
|
|
|
|
}
|
2010-09-29 07:50:49 +08:00
|
|
|
|
2009-08-18 00:02:57 +08: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) {
|
2011-04-01 10:22:47 +08:00
|
|
|
// Emit as { cycles, u1 | u2 | ... | un, timeinc }, // indices
|
|
|
|
StageTable += ItinStageString + ", // " + itostr(StageCount);
|
|
|
|
if (NStages > 1)
|
|
|
|
StageTable += "-" + itostr(StageCount + NStages - 1);
|
|
|
|
StageTable += "\n";
|
2009-08-18 00:02:57 +08:00
|
|
|
// Record Itin class number.
|
|
|
|
ItinStageMap[ItinStageString] = FindStage = StageCount;
|
|
|
|
StageCount += NStages;
|
|
|
|
}
|
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2009-08-18 00:02:57 +08:00
|
|
|
// Check to see if operand cycle already exists and create if it doesn't
|
|
|
|
unsigned FindOperandCycle = 0;
|
|
|
|
if (NOperandCycles > 0) {
|
2010-09-30 06:42:35 +08:00
|
|
|
std::string ItinOperandString = ItinOperandCycleString+ItinBypassString;
|
|
|
|
FindOperandCycle = ItinOperandMap[ItinOperandString];
|
2009-08-18 00:02:57 +08:00
|
|
|
if (FindOperandCycle == 0) {
|
|
|
|
// Emit as cycle, // index
|
2011-04-01 10:22:47 +08:00
|
|
|
OperandCycleTable += ItinOperandCycleString + ", // ";
|
|
|
|
std::string OperandIdxComment = itostr(OperandCycleCount);
|
|
|
|
if (NOperandCycles > 1)
|
|
|
|
OperandIdxComment += "-"
|
|
|
|
+ itostr(OperandCycleCount + NOperandCycles - 1);
|
|
|
|
OperandCycleTable += OperandIdxComment + "\n";
|
2009-08-18 00:02:57 +08:00
|
|
|
// Record Itin class number.
|
2011-04-01 09:56:55 +08:00
|
|
|
ItinOperandMap[ItinOperandCycleString] =
|
2009-08-18 00:02:57 +08:00
|
|
|
FindOperandCycle = OperandCycleCount;
|
2010-09-29 07:50:49 +08:00
|
|
|
// Emit as bypass, // index
|
2011-04-01 10:22:47 +08:00
|
|
|
BypassTable += ItinBypassString + ", // " + OperandIdxComment + "\n";
|
2009-08-18 00:02:57 +08:00
|
|
|
OperandCycleCount += NOperandCycles;
|
|
|
|
}
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2010-09-10 02:18:55 +08:00
|
|
|
// Set up itinerary as location and location + stage count
|
2012-07-07 12:00:00 +08:00
|
|
|
int NumUOps = ItinData ? ItinData->getValueAsInt("NumMicroOps") : 0;
|
2010-09-10 02:18:55 +08:00
|
|
|
InstrItinerary Intinerary = { NumUOps, FindStage, FindStage + NStages,
|
|
|
|
FindOperandCycle,
|
|
|
|
FindOperandCycle + NOperandCycles};
|
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Inject - empty slots will be 0, 0
|
2012-07-07 12:00:00 +08:00
|
|
|
ItinList[SchedClassIdx] = Intinerary;
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
|
|
|
}
|
2010-09-29 07:50:49 +08:00
|
|
|
|
2005-11-04 06:47:41 +08:00
|
|
|
// Closing stage
|
2012-07-07 12:00:00 +08:00
|
|
|
StageTable += " { 0, 0, 0, llvm::InstrStage::Required } // End stages\n";
|
2009-08-18 00:02:57 +08:00
|
|
|
StageTable += "};\n";
|
|
|
|
|
|
|
|
// Closing operand cycles
|
2012-07-07 12:00:00 +08:00
|
|
|
OperandCycleTable += " 0 // End operand cycles\n";
|
2009-08-18 00:02:57 +08:00
|
|
|
OperandCycleTable += "};\n";
|
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
BypassTable += " 0 // End bypass tables\n";
|
2010-09-29 07:50:49 +08:00
|
|
|
BypassTable += "};\n";
|
|
|
|
|
2009-08-18 00:02:57 +08:00
|
|
|
// Emit tables.
|
|
|
|
OS << StageTable;
|
|
|
|
OS << OperandCycleTable;
|
2010-09-29 07:50:49 +08:00
|
|
|
OS << BypassTable;
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-07-07 12:00:00 +08:00
|
|
|
// EmitProcessorData - Generate data for processor itineraries that were
|
|
|
|
// computed during EmitStageAndOperandCycleData(). ProcItinLists lists all
|
|
|
|
// Itineraries for each processor. The Itinerary lists are indexed on
|
|
|
|
// CodeGenSchedClass::Index.
|
2005-10-28 03:47:21 +08:00
|
|
|
//
|
2011-04-01 10:22:47 +08:00
|
|
|
void SubtargetEmitter::
|
2012-07-07 12:00:00 +08:00
|
|
|
EmitItineraries(raw_ostream &OS,
|
|
|
|
std::vector<std::vector<InstrItinerary> > &ProcItinLists) {
|
2012-06-05 11:44:40 +08:00
|
|
|
|
2012-07-10 04:43:03 +08:00
|
|
|
// Multiple processor models may share an itinerary record. Emit it once.
|
|
|
|
SmallPtrSet<Record*, 8> ItinsDefSet;
|
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// For each processor's machine model
|
2005-10-29 05:47:29 +08:00
|
|
|
std::vector<std::vector<InstrItinerary> >::iterator
|
2012-07-07 12:00:00 +08:00
|
|
|
ProcItinListsIter = ProcItinLists.begin();
|
|
|
|
for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
|
2012-09-15 08:19:57 +08:00
|
|
|
PE = SchedModels.procModelEnd(); PI != PE; ++PI, ++ProcItinListsIter) {
|
2012-07-10 04:43:03 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
Record *ItinsDef = PI->ItinsDef;
|
2012-07-10 04:43:03 +08:00
|
|
|
if (!ItinsDefSet.insert(ItinsDef))
|
|
|
|
continue;
|
2005-10-29 05:47:29 +08:00
|
|
|
|
2005-10-28 23:20:43 +08:00
|
|
|
// Get processor itinerary name
|
2012-07-07 12:00:00 +08:00
|
|
|
const std::string &Name = ItinsDef->getName();
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// Get the itinerary list for the processor.
|
|
|
|
assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator");
|
2012-09-15 08:19:57 +08:00
|
|
|
std::vector<InstrItinerary> &ItinList = *ProcItinListsIter;
|
2012-06-05 11:44:40 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
OS << "\n";
|
|
|
|
OS << "static const llvm::InstrItinerary ";
|
|
|
|
if (ItinList.empty()) {
|
|
|
|
OS << '*' << Name << " = 0;\n";
|
|
|
|
continue;
|
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2012-07-07 12:00:00 +08:00
|
|
|
// Begin processor itinerary table
|
|
|
|
OS << Name << "[] = {\n";
|
|
|
|
|
|
|
|
// For each itinerary class in CodeGenSchedClass::Index order.
|
|
|
|
for (unsigned j = 0, M = ItinList.size(); j < M; ++j) {
|
|
|
|
InstrItinerary &Intinerary = ItinList[j];
|
|
|
|
|
|
|
|
// Emit Itinerary in the form of
|
|
|
|
// { firstStage, lastStage, firstCycle, lastCycle } // index
|
|
|
|
OS << " { " <<
|
|
|
|
Intinerary.NumMicroOps << ", " <<
|
|
|
|
Intinerary.FirstStage << ", " <<
|
|
|
|
Intinerary.LastStage << ", " <<
|
|
|
|
Intinerary.FirstOperandCycle << ", " <<
|
|
|
|
Intinerary.LastOperandCycle << " }" <<
|
|
|
|
", // " << j << " " << SchedModels.getSchedClass(j).Name << "\n";
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
2012-07-07 12:00:00 +08:00
|
|
|
// End processor itinerary table
|
|
|
|
OS << " { 0, ~0U, ~0U, ~0U, ~0U } // end marker\n";
|
2012-06-05 11:44:40 +08:00
|
|
|
OS << "};\n";
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
2005-11-01 01:16:01 +08:00
|
|
|
}
|
|
|
|
|
2012-07-23 16:51:15 +08:00
|
|
|
// Emit either the value defined in the TableGen Record, or the default
|
2012-07-07 12:00:00 +08:00
|
|
|
// value defined in the C++ header. The Record is null if the processor does not
|
|
|
|
// define a model.
|
|
|
|
void SubtargetEmitter::EmitProcessorProp(raw_ostream &OS, const Record *R,
|
|
|
|
const char *Name, char Separator) {
|
|
|
|
OS << " ";
|
|
|
|
int V = R ? R->getValueAsInt(Name) : -1;
|
|
|
|
if (V >= 0)
|
|
|
|
OS << V << Separator << " // " << Name;
|
|
|
|
else
|
|
|
|
OS << "MCSchedModel::Default" << Name << Separator;
|
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) {
|
|
|
|
// For each processor model.
|
|
|
|
for (CodeGenSchedModels::ProcIter PI = SchedModels.procModelBegin(),
|
|
|
|
PE = SchedModels.procModelEnd(); PI != PE; ++PI) {
|
|
|
|
// Skip default
|
|
|
|
// Begin processor itinerary properties
|
|
|
|
OS << "\n";
|
|
|
|
OS << "static const llvm::MCSchedModel " << PI->ModelName << "(\n";
|
|
|
|
EmitProcessorProp(OS, PI->ModelDef, "IssueWidth", ',');
|
|
|
|
EmitProcessorProp(OS, PI->ModelDef, "MinLatency", ',');
|
|
|
|
EmitProcessorProp(OS, PI->ModelDef, "LoadLatency", ',');
|
|
|
|
EmitProcessorProp(OS, PI->ModelDef, "HighLatency", ',');
|
2012-08-08 10:44:16 +08:00
|
|
|
EmitProcessorProp(OS, PI->ModelDef, "MispredictPenalty", ',');
|
2012-07-07 12:00:00 +08:00
|
|
|
if (SchedModels.hasItineraryClasses())
|
|
|
|
OS << " " << PI->ItinsDef->getName();
|
|
|
|
else
|
|
|
|
OS << " 0";
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
//
|
|
|
|
// EmitProcessorLookup - generate cpu name to itinerary lookup table.
|
|
|
|
//
|
2009-07-03 08:10:29 +08:00
|
|
|
void SubtargetEmitter::EmitProcessorLookup(raw_ostream &OS) {
|
2005-11-01 01:16:01 +08:00
|
|
|
// Gather and sort processor information
|
|
|
|
std::vector<Record*> ProcessorList =
|
|
|
|
Records.getAllDerivedDefinitions("Processor");
|
2005-12-30 22:56:37 +08:00
|
|
|
std::sort(ProcessorList.begin(), ProcessorList.end(), LessRecordFieldName());
|
2005-11-01 01:16:01 +08:00
|
|
|
|
|
|
|
// Begin processor table
|
|
|
|
OS << "\n";
|
|
|
|
OS << "// Sorted (by key) array of itineraries for CPU subtype.\n"
|
2011-10-23 00:50:00 +08:00
|
|
|
<< "extern const llvm::SubtargetInfoKV "
|
2012-07-07 12:00:00 +08:00
|
|
|
<< Target << "ProcSchedKV[] = {\n";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
// For each processor
|
|
|
|
for (unsigned i = 0, N = ProcessorList.size(); i < N;) {
|
|
|
|
// Next processor
|
|
|
|
Record *Processor = ProcessorList[i];
|
|
|
|
|
2007-05-05 04:38:40 +08:00
|
|
|
const std::string &Name = Processor->getValueAsString("Name");
|
2012-07-07 12:00:00 +08:00
|
|
|
const std::string &ProcModelName =
|
2012-09-15 08:19:57 +08:00
|
|
|
SchedModels.getModelForProc(Processor).ModelName;
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
// Emit as { "cpu", procinit },
|
|
|
|
OS << " { "
|
|
|
|
<< "\"" << Name << "\", "
|
2012-09-06 05:43:57 +08:00
|
|
|
<< "(const void *)&" << ProcModelName;
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
OS << " }";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
// Depending on ''if more in the list'' emit comma
|
|
|
|
if (++i < N) OS << ",";
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
OS << "\n";
|
|
|
|
}
|
2011-04-01 09:56:55 +08:00
|
|
|
|
2005-11-01 01:16:01 +08:00
|
|
|
// End processor table
|
|
|
|
OS << "};\n";
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-07-07 12:00:00 +08:00
|
|
|
// EmitSchedModel - Emits all scheduling model tables, folding common patterns.
|
2005-10-28 03:47:21 +08:00
|
|
|
//
|
2012-07-07 12:00:00 +08:00
|
|
|
void SubtargetEmitter::EmitSchedModel(raw_ostream &OS) {
|
|
|
|
if (SchedModels.hasItineraryClasses()) {
|
|
|
|
std::vector<std::vector<InstrItinerary> > ProcItinLists;
|
2005-11-02 04:06:59 +08:00
|
|
|
// Emit the stage data
|
2012-07-07 12:00:00 +08:00
|
|
|
EmitStageAndOperandCycleData(OS, ProcItinLists);
|
|
|
|
EmitItineraries(OS, ProcItinLists);
|
2005-11-02 04:06:59 +08:00
|
|
|
}
|
2012-07-07 12:00:00 +08:00
|
|
|
// Emit the processor machine model
|
|
|
|
EmitProcessorModels(OS);
|
|
|
|
// Emit the processor lookup data
|
|
|
|
EmitProcessorLookup(OS);
|
2005-10-28 03:47:21 +08:00
|
|
|
}
|
|
|
|
|
2005-10-27 01:30:34 +08:00
|
|
|
//
|
|
|
|
// ParseFeaturesFunction - Produces a subtarget specific function for parsing
|
|
|
|
// the subtarget features string.
|
|
|
|
//
|
2011-07-02 04:45:01 +08:00
|
|
|
void SubtargetEmitter::ParseFeaturesFunction(raw_ostream &OS,
|
|
|
|
unsigned NumFeatures,
|
|
|
|
unsigned NumProcs) {
|
2005-10-29 05:47:29 +08:00
|
|
|
std::vector<Record*> Features =
|
|
|
|
Records.getAllDerivedDefinitions("SubtargetFeature");
|
2005-12-30 22:56:37 +08:00
|
|
|
std::sort(Features.begin(), Features.end(), LessRecord());
|
2005-10-27 01:30:34 +08:00
|
|
|
|
2011-04-01 09:56:55 +08:00
|
|
|
OS << "// ParseSubtargetFeatures - Parses features string setting specified\n"
|
|
|
|
<< "// subtarget options.\n"
|
2011-06-30 09:53:36 +08:00
|
|
|
<< "void llvm::";
|
2005-10-27 01:30:34 +08:00
|
|
|
OS << Target;
|
2011-07-07 15:07:08 +08:00
|
|
|
OS << "Subtarget::ParseSubtargetFeatures(StringRef CPU, StringRef FS) {\n"
|
2010-01-06 01:47:41 +08:00
|
|
|
<< " DEBUG(dbgs() << \"\\nFeatures:\" << FS);\n"
|
2012-06-12 12:21:36 +08:00
|
|
|
<< " DEBUG(dbgs() << \"\\nCPU:\" << CPU << \"\\n\\n\");\n";
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
if (Features.empty()) {
|
|
|
|
OS << "}\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-07 15:07:08 +08:00
|
|
|
OS << " uint64_t Bits = ReInitMCSubtargetInfo(CPU, FS);\n";
|
2007-05-05 04:38:40 +08:00
|
|
|
|
2005-10-29 05:47:29 +08:00
|
|
|
for (unsigned i = 0; i < Features.size(); i++) {
|
|
|
|
// Next record
|
|
|
|
Record *R = Features[i];
|
2007-05-05 04:38:40 +08:00
|
|
|
const std::string &Instance = R->getName();
|
|
|
|
const std::string &Value = R->getValueAsString("Value");
|
|
|
|
const std::string &Attribute = R->getValueAsString("Attribute");
|
2006-01-27 16:09:42 +08:00
|
|
|
|
2008-02-15 07:35:16 +08:00
|
|
|
if (Value=="true" || Value=="false")
|
2011-07-07 15:07:08 +08:00
|
|
|
OS << " if ((Bits & " << Target << "::"
|
|
|
|
<< Instance << ") != 0) "
|
2008-02-15 07:35:16 +08:00
|
|
|
<< Attribute << " = " << Value << ";\n";
|
|
|
|
else
|
2011-07-07 15:07:08 +08:00
|
|
|
OS << " if ((Bits & " << Target << "::"
|
|
|
|
<< Instance << ") != 0 && "
|
2011-07-02 04:45:01 +08:00
|
|
|
<< Attribute << " < " << Value << ") "
|
|
|
|
<< Attribute << " = " << Value << ";\n";
|
2005-11-02 04:06:59 +08:00
|
|
|
}
|
2009-05-24 03:50:50 +08:00
|
|
|
|
2011-06-30 09:53:36 +08:00
|
|
|
OS << "}\n";
|
2005-10-27 01:30:34 +08:00
|
|
|
}
|
|
|
|
|
2009-05-24 03:50:50 +08:00
|
|
|
//
|
2005-10-25 23:16:36 +08:00
|
|
|
// SubtargetEmitter::run - Main subtarget enumeration emitter.
|
|
|
|
//
|
2009-07-03 08:10:29 +08:00
|
|
|
void SubtargetEmitter::run(raw_ostream &OS) {
|
2012-06-11 23:37:55 +08:00
|
|
|
emitSourceFileHeader("Subtarget Enumeration Source Fragment", OS);
|
2005-10-25 23:16:36 +08:00
|
|
|
|
2011-07-08 09:53:10 +08:00
|
|
|
OS << "\n#ifdef GET_SUBTARGETINFO_ENUM\n";
|
|
|
|
OS << "#undef GET_SUBTARGETINFO_ENUM\n";
|
|
|
|
|
|
|
|
OS << "namespace llvm {\n";
|
|
|
|
Enumeration(OS, "SubtargetFeature", true);
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
OS << "#endif // GET_SUBTARGETINFO_ENUM\n\n";
|
|
|
|
|
2011-07-02 04:45:01 +08:00
|
|
|
OS << "\n#ifdef GET_SUBTARGETINFO_MC_DESC\n";
|
|
|
|
OS << "#undef GET_SUBTARGETINFO_MC_DESC\n";
|
2010-04-19 04:31:01 +08:00
|
|
|
|
2011-07-02 04:45:01 +08:00
|
|
|
OS << "namespace llvm {\n";
|
2011-07-15 04:59:42 +08:00
|
|
|
#if 0
|
|
|
|
OS << "namespace {\n";
|
|
|
|
#endif
|
2011-07-02 04:45:01 +08:00
|
|
|
unsigned NumFeatures = FeatureKeyValues(OS);
|
2011-07-15 04:59:42 +08:00
|
|
|
OS << "\n";
|
2011-07-02 04:45:01 +08:00
|
|
|
unsigned NumProcs = CPUKeyValues(OS);
|
2011-07-15 04:59:42 +08:00
|
|
|
OS << "\n";
|
2012-07-07 12:00:00 +08:00
|
|
|
EmitSchedModel(OS);
|
2011-07-15 04:59:42 +08:00
|
|
|
OS << "\n";
|
|
|
|
#if 0
|
|
|
|
OS << "}\n";
|
|
|
|
#endif
|
2011-07-02 04:45:01 +08:00
|
|
|
|
|
|
|
// MCInstrInfo initialization routine.
|
|
|
|
OS << "static inline void Init" << Target
|
2011-07-11 11:57:24 +08:00
|
|
|
<< "MCSubtargetInfo(MCSubtargetInfo *II, "
|
|
|
|
<< "StringRef TT, StringRef CPU, StringRef FS) {\n";
|
|
|
|
OS << " II->InitMCSubtargetInfo(TT, CPU, FS, ";
|
2011-07-02 04:45:01 +08:00
|
|
|
if (NumFeatures)
|
|
|
|
OS << Target << "FeatureKV, ";
|
|
|
|
else
|
|
|
|
OS << "0, ";
|
|
|
|
if (NumProcs)
|
|
|
|
OS << Target << "SubTypeKV, ";
|
|
|
|
else
|
|
|
|
OS << "0, ";
|
2012-07-07 12:00:00 +08:00
|
|
|
if (SchedModels.hasItineraryClasses()) {
|
|
|
|
OS << Target << "ProcSchedKV, "
|
2011-07-02 04:45:01 +08:00
|
|
|
<< Target << "Stages, "
|
|
|
|
<< Target << "OperandCycles, "
|
2012-07-07 11:59:48 +08:00
|
|
|
<< Target << "ForwardingPaths, ";
|
2011-07-02 04:45:01 +08:00
|
|
|
} else
|
|
|
|
OS << "0, 0, 0, 0, ";
|
|
|
|
OS << NumFeatures << ", " << NumProcs << ");\n}\n\n";
|
|
|
|
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
|
|
|
|
OS << "#endif // GET_SUBTARGETINFO_MC_DESC\n\n";
|
|
|
|
|
|
|
|
OS << "\n#ifdef GET_SUBTARGETINFO_TARGET_DESC\n";
|
|
|
|
OS << "#undef GET_SUBTARGETINFO_TARGET_DESC\n";
|
|
|
|
|
|
|
|
OS << "#include \"llvm/Support/Debug.h\"\n";
|
|
|
|
OS << "#include \"llvm/Support/raw_ostream.h\"\n";
|
|
|
|
ParseFeaturesFunction(OS, NumFeatures, NumProcs);
|
|
|
|
|
|
|
|
OS << "#endif // GET_SUBTARGETINFO_TARGET_DESC\n\n";
|
|
|
|
|
2011-07-02 05:01:15 +08:00
|
|
|
// Create a TargetSubtargetInfo subclass to hide the MC layer initialization.
|
2011-07-02 04:45:01 +08:00
|
|
|
OS << "\n#ifdef GET_SUBTARGETINFO_HEADER\n";
|
|
|
|
OS << "#undef GET_SUBTARGETINFO_HEADER\n";
|
|
|
|
|
|
|
|
std::string ClassName = Target + "GenSubtargetInfo";
|
|
|
|
OS << "namespace llvm {\n";
|
2011-12-02 05:10:21 +08:00
|
|
|
OS << "class DFAPacketizer;\n";
|
2011-07-02 05:01:15 +08:00
|
|
|
OS << "struct " << ClassName << " : public TargetSubtargetInfo {\n"
|
2011-07-07 15:07:08 +08:00
|
|
|
<< " explicit " << ClassName << "(StringRef TT, StringRef CPU, "
|
|
|
|
<< "StringRef FS);\n"
|
2011-12-02 05:10:21 +08:00
|
|
|
<< "public:\n"
|
2011-12-07 01:34:16 +08:00
|
|
|
<< " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)"
|
2011-12-02 05:10:21 +08:00
|
|
|
<< " const;\n"
|
2011-07-02 04:45:01 +08:00
|
|
|
<< "};\n";
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
|
|
|
|
OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n";
|
|
|
|
|
|
|
|
OS << "\n#ifdef GET_SUBTARGETINFO_CTOR\n";
|
|
|
|
OS << "#undef GET_SUBTARGETINFO_CTOR\n";
|
|
|
|
|
|
|
|
OS << "namespace llvm {\n";
|
2011-10-23 00:50:00 +08:00
|
|
|
OS << "extern const llvm::SubtargetFeatureKV " << Target << "FeatureKV[];\n";
|
|
|
|
OS << "extern const llvm::SubtargetFeatureKV " << Target << "SubTypeKV[];\n";
|
2012-07-07 12:00:00 +08:00
|
|
|
if (SchedModels.hasItineraryClasses()) {
|
|
|
|
OS << "extern const llvm::SubtargetInfoKV " << Target << "ProcSchedKV[];\n";
|
2011-10-23 00:50:00 +08:00
|
|
|
OS << "extern const llvm::InstrStage " << Target << "Stages[];\n";
|
|
|
|
OS << "extern const unsigned " << Target << "OperandCycles[];\n";
|
2012-07-07 11:59:48 +08:00
|
|
|
OS << "extern const unsigned " << Target << "ForwardingPaths[];\n";
|
2011-07-15 04:59:42 +08:00
|
|
|
}
|
|
|
|
|
2011-07-07 15:07:08 +08:00
|
|
|
OS << ClassName << "::" << ClassName << "(StringRef TT, StringRef CPU, "
|
|
|
|
<< "StringRef FS)\n"
|
2011-07-02 05:01:15 +08:00
|
|
|
<< " : TargetSubtargetInfo() {\n"
|
2011-07-11 11:57:24 +08:00
|
|
|
<< " InitMCSubtargetInfo(TT, CPU, FS, ";
|
2011-07-02 04:45:01 +08:00
|
|
|
if (NumFeatures)
|
|
|
|
OS << Target << "FeatureKV, ";
|
|
|
|
else
|
|
|
|
OS << "0, ";
|
|
|
|
if (NumProcs)
|
|
|
|
OS << Target << "SubTypeKV, ";
|
|
|
|
else
|
|
|
|
OS << "0, ";
|
2012-07-07 12:00:00 +08:00
|
|
|
if (SchedModels.hasItineraryClasses()) {
|
|
|
|
OS << Target << "ProcSchedKV, "
|
2011-07-02 04:45:01 +08:00
|
|
|
<< Target << "Stages, "
|
|
|
|
<< Target << "OperandCycles, "
|
2012-07-07 11:59:48 +08:00
|
|
|
<< Target << "ForwardingPaths, ";
|
2011-07-02 04:45:01 +08:00
|
|
|
} else
|
|
|
|
OS << "0, 0, 0, 0, ";
|
|
|
|
OS << NumFeatures << ", " << NumProcs << ");\n}\n\n";
|
|
|
|
OS << "} // End llvm namespace \n";
|
|
|
|
|
|
|
|
OS << "#endif // GET_SUBTARGETINFO_CTOR\n\n";
|
2005-10-25 23:16:36 +08:00
|
|
|
}
|
2012-06-11 23:37:55 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
void EmitSubtarget(RecordKeeper &RK, raw_ostream &OS) {
|
2012-07-07 12:00:00 +08:00
|
|
|
CodeGenTarget CGTarget(RK);
|
|
|
|
SubtargetEmitter(RK, CGTarget).run(OS);
|
2012-06-11 23:37:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End llvm namespace
|